sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:databasesKEGG; 3, parameters; 3, 4; 3, 5; 4, identifier:organism; 5, identifier:ens_ids; 6, block; 6, 7; 6, 20; 6, 29; 6, 33; 6, 171; 6, 182; 6, 193; 6, 210; 6, 219; 6, 281; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:all_genes; 10, call; 10, 11; 10, 19; 11, attribute; 11, 12; 11, 18; 12, call; 12, 13; 12, 14; 13, identifier:urlopen; 14, argument_list; 14, 15; 15, binary_operator:+; 15, 16; 15, 17; 16, string:"http://rest.kegg.jp/list/"; 17, identifier:organism; 18, identifier:read; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:all_genes; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:all_genes; 26, identifier:split; 27, argument_list; 27, 28; 28, string:"\n"; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:dbs; 32, list:[]; 33, while_statement; 33, 34; 33, 40; 34, comparison_operator:==; 34, 35; 34, 39; 35, call; 35, 36; 35, 37; 36, identifier:len; 37, argument_list; 37, 38; 38, identifier:dbs; 39, integer:0; 40, block; 40, 41; 41, for_statement; 41, 42; 41, 43; 41, 44; 42, identifier:g; 43, identifier:all_genes; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 52; 45, 168; 46, comparison_operator:==; 46, 47; 46, 51; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, identifier:dbs; 51, integer:0; 52, block; 52, 53; 52, 64; 52, 77; 52, 86; 52, 98; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:kid; 56, subscript; 56, 57; 56, 63; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:g; 60, identifier:split; 61, argument_list; 61, 62; 62, string:"\t"; 63, integer:0; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:gene; 67, call; 67, 68; 67, 76; 68, attribute; 68, 69; 68, 75; 69, call; 69, 70; 69, 71; 70, identifier:urlopen; 71, argument_list; 71, 72; 72, binary_operator:+; 72, 73; 72, 74; 73, string:"http://rest.kegg.jp/get/"; 74, identifier:kid; 75, identifier:read; 76, argument_list; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:DBLINKS; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:gene; 83, identifier:split; 84, argument_list; 84, 85; 85, string:"\n"; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:DBLINKS; 89, list_comprehension; 89, 90; 89, 91; 89, 94; 90, identifier:s; 91, for_in_clause; 91, 92; 91, 93; 92, identifier:s; 93, identifier:DBLINKS; 94, if_clause; 94, 95; 95, comparison_operator:in; 95, 96; 95, 97; 96, string:":"; 97, identifier:s; 98, for_statement; 98, 99; 98, 100; 98, 101; 99, identifier:d; 100, identifier:DBLINKS; 101, block; 101, 102; 101, 111; 101, 122; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:test; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:d; 108, identifier:split; 109, argument_list; 109, 110; 110, string:" "; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:test; 114, subscript; 114, 115; 114, 116; 115, identifier:test; 116, binary_operator:-; 116, 117; 116, 121; 117, call; 117, 118; 117, 119; 118, identifier:len; 119, argument_list; 119, 120; 120, identifier:test; 121, integer:1; 122, if_statement; 122, 123; 122, 126; 123, comparison_operator:in; 123, 124; 123, 125; 124, identifier:test; 125, identifier:ens_ids; 126, block; 126, 127; 126, 139; 126, 150; 126, 161; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:DBLINK; 130, list_comprehension; 130, 131; 130, 132; 130, 135; 131, identifier:s; 132, for_in_clause; 132, 133; 132, 134; 133, identifier:s; 134, identifier:DBLINKS; 135, if_clause; 135, 136; 136, comparison_operator:in; 136, 137; 136, 138; 137, identifier:test; 138, identifier:s; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:DBLINK; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:DBLINK; 146, integer:0; 147, identifier:split; 148, argument_list; 148, 149; 149, string:":"; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:DBLINK; 153, subscript; 153, 154; 153, 155; 154, identifier:DBLINK; 155, binary_operator:-; 155, 156; 155, 160; 156, call; 156, 157; 156, 158; 157, identifier:len; 158, argument_list; 158, 159; 159, identifier:DBLINK; 160, integer:2; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:dbs; 165, identifier:append; 166, argument_list; 166, 167; 167, identifier:DBLINK; 168, else_clause; 168, 169; 169, block; 169, 170; 170, break_statement; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:ens_db; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:dbs; 178, integer:0; 179, identifier:split; 180, argument_list; 180, 181; 181, string:" "; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:ens_db; 185, subscript; 185, 186; 185, 187; 186, identifier:ens_db; 187, binary_operator:-; 187, 188; 187, 192; 188, call; 188, 189; 188, 190; 189, identifier:len; 190, argument_list; 190, 191; 191, identifier:ens_db; 192, integer:1; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:test_db; 196, call; 196, 197; 196, 209; 197, attribute; 197, 198; 197, 208; 198, call; 198, 199; 198, 200; 199, identifier:urlopen; 200, argument_list; 200, 201; 201, binary_operator:+; 201, 202; 201, 207; 202, binary_operator:+; 202, 203; 202, 206; 203, binary_operator:+; 203, 204; 203, 205; 204, string:"http://rest.genome.jp/link/"; 205, identifier:ens_db; 206, string:"/"; 207, identifier:organism; 208, identifier:read; 209, argument_list; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:test_db; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:test_db; 216, identifier:split; 217, argument_list; 217, 218; 218, string:"\n"; 219, if_statement; 219, 220; 219, 226; 219, 260; 220, comparison_operator:==; 220, 221; 220, 225; 221, call; 221, 222; 221, 223; 222, identifier:len; 223, argument_list; 223, 224; 224, identifier:test_db; 225, integer:1; 226, block; 226, 227; 226, 238; 226, 243; 226, 248; 226, 256; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 230; 229, identifier:print; 230, argument_list; 230, 231; 231, binary_operator:+; 231, 232; 231, 237; 232, binary_operator:+; 232, 233; 232, 236; 233, binary_operator:+; 233, 234; 233, 235; 234, string:"For "; 235, identifier:organism; 236, string:" the following db was found: "; 237, identifier:ens_db; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 241; 240, identifier:print; 241, argument_list; 241, 242; 242, string:"This database does not seem to be valid KEGG-linked database identifier"; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 246; 245, identifier:print; 246, argument_list; 246, 247; 247, string:"For \n'hsa' use 'ensembl-hsa'\n'mmu' use 'ensembl-mmu'\n'cel' use 'EnsemblGenomes-Gn'\n'dme' use 'FlyBase'"; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 255; 250, attribute; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:sys; 253, identifier:stdout; 254, identifier:flush; 255, argument_list; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:ens_db; 259, None; 260, else_clause; 260, 261; 261, block; 261, 262; 261, 273; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 265; 264, identifier:print; 265, argument_list; 265, 266; 266, binary_operator:+; 266, 267; 266, 272; 267, binary_operator:+; 267, 268; 267, 271; 268, binary_operator:+; 268, 269; 268, 270; 269, string:"For "; 270, identifier:organism; 271, string:" the following db was found: "; 272, identifier:ens_db; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 280; 275, attribute; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:sys; 278, identifier:stdout; 279, identifier:flush; 280, argument_list; 281, return_statement; 281, 282; 282, identifier:ens_db | def databasesKEGG(organism,ens_ids):
all_genes=urlopen("http://rest.kegg.jp/list/"+organism).read()
all_genes=all_genes.split("\n")
dbs=[]
while len(dbs) == 0:
for g in all_genes:
if len(dbs) == 0:
kid = g.split("\t")[0]
gene=urlopen("http://rest.kegg.jp/get/"+kid).read()
DBLINKS=gene.split("\n")
DBLINKS=[ s for s in DBLINKS if ":" in s ]
for d in DBLINKS:
test=d.split(" ")
test=test[len(test)-1]
if test in ens_ids:
DBLINK=[ s for s in DBLINKS if test in s ]
DBLINK=DBLINK[0].split(":")
DBLINK=DBLINK[len(DBLINK)-2]
dbs.append(DBLINK)
else:
break
ens_db=dbs[0].split(" ")
ens_db=ens_db[len(ens_db)-1]
test_db=urlopen("http://rest.genome.jp/link/"+ens_db+"/"+organism).read()
test_db=test_db.split("\n")
if len(test_db) == 1:
print("For "+organism+" the following db was found: "+ens_db)
print("This database does not seem to be valid KEGG-linked database identifier")
print("For \n'hsa' use 'ensembl-hsa'\n'mmu' use 'ensembl-mmu'\n'cel' use 'EnsemblGenomes-Gn'\n'dme' use 'FlyBase'")
sys.stdout.flush()
ens_db = None
else:
print("For "+organism+" the following db was found: "+ens_db)
sys.stdout.flush()
return ens_db |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:process; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:form; 6, identifier:post; 7, block; 7, 8; 7, 21; 7, 30; 7, 36; 7, 416; 7, 436; 8, if_statement; 8, 9; 8, 15; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:isinstance; 12, argument_list; 12, 13; 12, 14; 13, identifier:form; 14, identifier:FormMeta; 15, block; 15, 16; 16, raise_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:TypeError; 19, argument_list; 19, 20; 20, string:'Given form is not a valid WTForm.'; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:re_field_name; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:re; 27, identifier:compile; 28, argument_list; 28, 29; 29, string:r'\%([a-zA-Z0-9_]*)\%'; 30, class_definition; 30, 31; 30, 32; 30, 34; 31, identifier:F; 32, argument_list; 32, 33; 33, identifier:form; 34, block; 34, 35; 35, pass_statement; 36, for_statement; 36, 37; 36, 40; 36, 45; 37, pattern_list; 37, 38; 37, 39; 38, identifier:field; 39, identifier:data; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:post; 43, identifier:iteritems; 44, argument_list; 45, block; 45, 46; 45, 157; 45, 161; 45, 359; 45, 369; 45, 379; 45, 389; 45, 399; 46, if_statement; 46, 47; 46, 52; 46, 54; 47, comparison_operator:in; 47, 48; 47, 49; 48, identifier:field; 49, call; 49, 50; 49, 51; 50, identifier:F; 51, argument_list; 52, block; 52, 53; 53, continue_statement; 54, else_clause; 54, 55; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 62; 56, 71; 56, 154; 57, comparison_operator:in; 57, 58; 57, 59; 58, identifier:field; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:_dyn_fields; 62, block; 62, 63; 62, 67; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:field_cname; 66, identifier:field; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:current_set_number; 70, None; 71, elif_clause; 71, 72; 71, 115; 72, parenthesized_expression; 72, 73; 73, boolean_operator:and; 73, 74; 73, 87; 74, call; 74, 75; 74, 86; 75, attribute; 75, 76; 75, 85; 76, subscript; 76, 77; 76, 83; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:field; 80, identifier:split; 81, argument_list; 81, 82; 82, string:'_'; 83, unary_operator:-; 83, 84; 84, integer:1; 85, identifier:isdigit; 86, argument_list; 87, comparison_operator:in; 87, 88; 87, 108; 88, subscript; 88, 89; 88, 90; 89, identifier:field; 90, slice; 90, 91; 90, 92; 91, colon; 92, binary_operator:-; 92, 93; 92, 107; 93, unary_operator:-; 93, 94; 94, parenthesized_expression; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:len; 97, argument_list; 97, 98; 98, subscript; 98, 99; 98, 105; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:field; 102, identifier:split; 103, argument_list; 103, 104; 104, string:'_'; 105, unary_operator:-; 105, 106; 106, integer:1; 107, integer:1; 108, call; 108, 109; 108, 114; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:_dyn_fields; 113, identifier:keys; 114, argument_list; 115, block; 115, 116; 115, 139; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:field_cname; 119, subscript; 119, 120; 119, 121; 120, identifier:field; 121, slice; 121, 122; 121, 123; 122, colon; 123, binary_operator:-; 123, 124; 123, 138; 124, unary_operator:-; 124, 125; 125, parenthesized_expression; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:len; 128, argument_list; 128, 129; 129, subscript; 129, 130; 129, 136; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:field; 133, identifier:split; 134, argument_list; 134, 135; 135, string:'_'; 136, unary_operator:-; 136, 137; 137, integer:1; 138, integer:1; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:current_set_number; 142, call; 142, 143; 142, 144; 143, identifier:str; 144, argument_list; 144, 145; 145, subscript; 145, 146; 145, 152; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:field; 149, identifier:split; 150, argument_list; 150, 151; 151, string:'_'; 152, unary_operator:-; 152, 153; 153, integer:1; 154, else_clause; 154, 155; 155, block; 155, 156; 156, continue_statement; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:validators; 160, list:[]; 161, if_statement; 161, 162; 161, 169; 162, comparison_operator:in; 162, 163; 162, 164; 163, string:'validators'; 164, subscript; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:_dyn_fields; 168, identifier:field_cname; 169, block; 169, 170; 170, for_statement; 170, 171; 170, 172; 170, 179; 171, identifier:validator; 172, subscript; 172, 173; 172, 178; 173, subscript; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:_dyn_fields; 177, identifier:field_cname; 178, string:'validators'; 179, block; 179, 180; 179, 184; 179, 188; 179, 264; 179, 346; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:args; 183, list:[]; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:kwargs; 187, dictionary; 188, if_statement; 188, 189; 188, 201; 189, comparison_operator:in; 189, 190; 189, 191; 190, string:'args'; 191, subscript; 191, 192; 191, 197; 191, 198; 192, subscript; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:_dyn_fields; 196, identifier:field_cname; 197, line_continuation:\; 198, attribute; 198, 199; 198, 200; 199, identifier:validator; 200, identifier:__name__; 201, block; 201, 202; 202, if_statement; 202, 203; 202, 205; 202, 221; 203, not_operator; 203, 204; 204, identifier:current_set_number; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:args; 209, subscript; 209, 210; 209, 220; 210, subscript; 210, 211; 210, 216; 210, 217; 211, subscript; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:_dyn_fields; 215, identifier:field_cname; 216, line_continuation:\; 217, attribute; 217, 218; 217, 219; 218, identifier:validator; 219, identifier:__name__; 220, string:'args'; 221, else_clause; 221, 222; 222, block; 222, 223; 223, for_statement; 223, 224; 223, 225; 223, 237; 224, identifier:arg; 225, subscript; 225, 226; 225, 236; 226, subscript; 226, 227; 226, 232; 226, 233; 227, subscript; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:_dyn_fields; 231, identifier:field_cname; 232, line_continuation:\; 233, attribute; 233, 234; 233, 235; 234, identifier:validator; 235, identifier:__name__; 236, string:'args'; 237, block; 237, 238; 237, 257; 238, try_statement; 238, 239; 238, 254; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:arg; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:re_field_name; 246, identifier:sub; 247, argument_list; 247, 248; 247, 253; 248, binary_operator:+; 248, 249; 248, 252; 249, binary_operator:+; 249, 250; 249, 251; 250, string:r'\1'; 251, string:'_'; 252, identifier:current_set_number; 253, identifier:arg; 254, except_clause; 254, 255; 255, block; 255, 256; 256, pass_statement; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:args; 261, identifier:append; 262, argument_list; 262, 263; 263, identifier:arg; 264, if_statement; 264, 265; 264, 277; 265, comparison_operator:in; 265, 266; 265, 267; 266, string:'kwargs'; 267, subscript; 267, 268; 267, 273; 267, 274; 268, subscript; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:_dyn_fields; 272, identifier:field_cname; 273, line_continuation:\; 274, attribute; 274, 275; 274, 276; 275, identifier:validator; 276, identifier:__name__; 277, block; 277, 278; 278, if_statement; 278, 279; 278, 281; 278, 297; 279, not_operator; 279, 280; 280, identifier:current_set_number; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:kwargs; 285, subscript; 285, 286; 285, 296; 286, subscript; 286, 287; 286, 292; 286, 293; 287, subscript; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:self; 290, identifier:_dyn_fields; 291, identifier:field_cname; 292, line_continuation:\; 293, attribute; 293, 294; 293, 295; 294, identifier:validator; 295, identifier:__name__; 296, string:'kwargs'; 297, else_clause; 297, 298; 298, block; 298, 299; 299, for_statement; 299, 300; 299, 303; 299, 320; 300, pattern_list; 300, 301; 300, 302; 301, identifier:key; 302, identifier:arg; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:iteritems; 307, argument_list; 307, 308; 308, subscript; 308, 309; 308, 319; 309, subscript; 309, 310; 309, 315; 309, 316; 310, subscript; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:_dyn_fields; 314, identifier:field_cname; 315, line_continuation:\; 316, attribute; 316, 317; 316, 318; 317, identifier:validator; 318, identifier:__name__; 319, string:'kwargs'; 320, block; 320, 321; 320, 340; 321, try_statement; 321, 322; 321, 337; 322, block; 322, 323; 323, expression_statement; 323, 324; 324, assignment; 324, 325; 324, 326; 325, identifier:arg; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:re_field_name; 329, identifier:sub; 330, argument_list; 330, 331; 330, 336; 331, binary_operator:+; 331, 332; 331, 335; 332, binary_operator:+; 332, 333; 332, 334; 333, string:r'\1'; 334, string:'_'; 335, identifier:current_set_number; 336, identifier:arg; 337, except_clause; 337, 338; 338, block; 338, 339; 339, pass_statement; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 345; 342, subscript; 342, 343; 342, 344; 343, identifier:kwargs; 344, identifier:key; 345, identifier:arg; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:validators; 350, identifier:append; 351, argument_list; 351, 352; 352, call; 352, 353; 352, 354; 353, identifier:validator; 354, argument_list; 354, 355; 354, 357; 355, list_splat; 355, 356; 356, identifier:args; 357, dictionary_splat; 357, 358; 358, identifier:kwargs; 359, expression_statement; 359, 360; 360, assignment; 360, 361; 360, 362; 361, identifier:field_type; 362, subscript; 362, 363; 362, 368; 363, subscript; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:self; 366, identifier:_dyn_fields; 367, identifier:field_cname; 368, string:'type'; 369, expression_statement; 369, 370; 370, assignment; 370, 371; 370, 372; 371, identifier:field_label; 372, subscript; 372, 373; 372, 378; 373, subscript; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, identifier:self; 376, identifier:_dyn_fields; 377, identifier:field_cname; 378, string:'label'; 379, expression_statement; 379, 380; 380, assignment; 380, 381; 380, 382; 381, identifier:field_args; 382, subscript; 382, 383; 382, 388; 383, subscript; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:self; 386, identifier:_dyn_fields; 387, identifier:field_cname; 388, string:'args'; 389, expression_statement; 389, 390; 390, assignment; 390, 391; 390, 392; 391, identifier:field_kwargs; 392, subscript; 392, 393; 392, 398; 393, subscript; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:self; 396, identifier:_dyn_fields; 397, identifier:field_cname; 398, string:'kwargs'; 399, expression_statement; 399, 400; 400, call; 400, 401; 400, 402; 401, identifier:setattr; 402, argument_list; 402, 403; 402, 404; 402, 405; 403, identifier:F; 404, identifier:field; 405, call; 405, 406; 405, 407; 406, identifier:field_type; 407, argument_list; 407, 408; 407, 409; 407, 412; 407, 414; 408, identifier:field_label; 409, keyword_argument; 409, 410; 409, 411; 410, identifier:validators; 411, identifier:validators; 412, list_splat; 412, 413; 413, identifier:field_args; 414, dictionary_splat; 414, 415; 415, identifier:field_kwargs; 416, if_statement; 416, 417; 416, 420; 416, 427; 417, attribute; 417, 418; 417, 419; 418, identifier:self; 419, identifier:flask_wtf; 420, block; 420, 421; 421, expression_statement; 421, 422; 422, assignment; 422, 423; 422, 424; 423, identifier:form; 424, call; 424, 425; 424, 426; 425, identifier:F; 426, argument_list; 427, else_clause; 427, 428; 428, block; 428, 429; 429, expression_statement; 429, 430; 430, assignment; 430, 431; 430, 432; 431, identifier:form; 432, call; 432, 433; 432, 434; 433, identifier:F; 434, argument_list; 434, 435; 435, identifier:post; 436, return_statement; 436, 437; 437, identifier:form | def process(self, form, post):
if not isinstance(form, FormMeta):
raise TypeError('Given form is not a valid WTForm.')
re_field_name = re.compile(r'\%([a-zA-Z0-9_]*)\%')
class F(form):
pass
for field, data in post.iteritems():
if field in F():
continue
else:
if field in self._dyn_fields:
field_cname = field
current_set_number = None
elif (field.split('_')[-1].isdigit()
and field[:-(len(field.split('_')[-1]))-1] in self._dyn_fields.keys()):
field_cname = field[:-(len(field.split('_')[-1]))-1]
current_set_number = str(field.split('_')[-1])
else:
continue
validators = []
if 'validators' in self._dyn_fields[field_cname]:
for validator in self._dyn_fields[field_cname]['validators']:
args = []
kwargs = {}
if 'args' in self._dyn_fields[field_cname]\
[validator.__name__]:
if not current_set_number:
args = self._dyn_fields[field_cname]\
[validator.__name__]['args']
else:
for arg in self._dyn_fields[field_cname]\
[validator.__name__]['args']:
try:
arg = re_field_name.sub(r'\1'+'_'+current_set_number,
arg)
except:
pass
args.append(arg)
if 'kwargs' in self._dyn_fields[field_cname]\
[validator.__name__]:
if not current_set_number:
kwargs = self._dyn_fields[field_cname]\
[validator.__name__]['kwargs']
else:
for key, arg in self.iteritems(self._dyn_fields[field_cname]\
[validator.__name__]['kwargs']):
try:
arg = re_field_name.sub(r'\1'+'_'+current_set_number,
arg)
except:
pass
kwargs[key] = arg
validators.append(validator(*args, **kwargs))
field_type = self._dyn_fields[field_cname]['type']
field_label = self._dyn_fields[field_cname]['label']
field_args = self._dyn_fields[field_cname]['args']
field_kwargs = self._dyn_fields[field_cname]['kwargs']
setattr(F, field, field_type(field_label,
validators=validators,
*field_args,
**field_kwargs))
if self.flask_wtf:
form = F()
else:
form = F(post)
return form |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:distinct_values; 3, parameters; 3, 4; 3, 5; 4, identifier:t_old; 5, identifier:t_new; 6, block; 6, 7; 6, 11; 6, 19; 6, 118; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:res; 10, list:[]; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:res; 15, identifier:append; 16, argument_list; 16, 17; 17, list:[' -- NOT IN check -- ']; 17, 18; 18, string:' -- NOT IN check -- '; 19, for_statement; 19, 20; 19, 21; 19, 24; 20, identifier:new_col; 21, attribute; 21, 22; 21, 23; 22, identifier:t_new; 23, identifier:header; 24, block; 24, 25; 24, 35; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:dist_new; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:t_new; 31, identifier:get_distinct_values_from_cols; 32, argument_list; 32, 33; 33, list:[new_col]; 33, 34; 34, identifier:new_col; 35, for_statement; 35, 36; 35, 37; 35, 40; 36, identifier:old_col; 37, attribute; 37, 38; 37, 39; 38, identifier:t_old; 39, identifier:header; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 45; 42, comparison_operator:==; 42, 43; 42, 44; 43, identifier:old_col; 44, identifier:new_col; 45, block; 45, 46; 45, 56; 45, 72; 45, 87; 45, 103; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:dist_old; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:t_old; 52, identifier:get_distinct_values_from_cols; 53, argument_list; 53, 54; 54, list:[old_col]; 54, 55; 55, identifier:old_col; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:not_in_new; 59, list_comprehension; 59, 60; 59, 61; 59, 66; 60, identifier:x; 61, for_in_clause; 61, 62; 61, 63; 62, identifier:x; 63, subscript; 63, 64; 63, 65; 64, identifier:dist_old; 65, integer:0; 66, if_clause; 66, 67; 67, comparison_operator:not; 67, 68; 67, 69; 68, identifier:x; 69, subscript; 69, 70; 69, 71; 70, identifier:dist_new; 71, integer:0; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:!=; 73, 74; 73, 75; 74, identifier:not_in_new; 75, list:[]; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:res; 81, identifier:append; 82, argument_list; 82, 83; 83, list:['Not in New', old_col, not_in_new]; 83, 84; 83, 85; 83, 86; 84, string:'Not in New'; 85, identifier:old_col; 86, identifier:not_in_new; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:not_in_old; 90, list_comprehension; 90, 91; 90, 92; 90, 97; 91, identifier:x; 92, for_in_clause; 92, 93; 92, 94; 93, identifier:x; 94, subscript; 94, 95; 94, 96; 95, identifier:dist_new; 96, integer:0; 97, if_clause; 97, 98; 98, comparison_operator:not; 98, 99; 98, 100; 99, identifier:x; 100, subscript; 100, 101; 100, 102; 101, identifier:dist_old; 102, integer:0; 103, if_statement; 103, 104; 103, 107; 104, comparison_operator:!=; 104, 105; 104, 106; 105, identifier:not_in_old; 106, list:[]; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:res; 112, identifier:append; 113, argument_list; 113, 114; 114, list:['Not in Old', new_col, not_in_old]; 114, 115; 114, 116; 114, 117; 115, string:'Not in Old'; 116, identifier:new_col; 117, identifier:not_in_old; 118, return_statement; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:sorted; 121, argument_list; 121, 122; 122, identifier:res | def distinct_values(t_old, t_new):
res = []
res.append([' -- NOT IN check -- '])
for new_col in t_new.header:
dist_new = t_new.get_distinct_values_from_cols([new_col])
for old_col in t_old.header:
if old_col == new_col:
dist_old = t_old.get_distinct_values_from_cols([old_col])
not_in_new = [x for x in dist_old[0] if x not in dist_new[0]]
if not_in_new != []:
res.append(['Not in New', old_col, not_in_new])
not_in_old = [x for x in dist_new[0] if x not in dist_old[0]]
if not_in_old != []:
res.append(['Not in Old', new_col, not_in_old])
return sorted(res) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:most_similar_catchments; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:subject_catchment; 6, identifier:similarity_dist_function; 7, default_parameter; 7, 8; 7, 9; 8, identifier:records_limit; 9, integer:500; 10, default_parameter; 10, 11; 10, 12; 11, identifier:include_subject_catchment; 12, string:'auto'; 13, block; 13, 14; 13, 34; 13, 111; 13, 119; 13, 185; 13, 199; 13, 211; 13, 215; 13, 219; 13, 242; 14, if_statement; 14, 15; 14, 21; 15, comparison_operator:not; 15, 16; 15, 17; 16, identifier:include_subject_catchment; 17, list:['auto', 'force', 'exclude']; 17, 18; 17, 19; 17, 20; 18, string:'auto'; 19, string:'force'; 20, string:'exclude'; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:ValueError; 25, argument_list; 25, 26; 26, binary_operator:+; 26, 27; 26, 33; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, string:"Parameter `include_subject_catchment={}` invalid."; 30, identifier:format; 31, argument_list; 31, 32; 32, identifier:include_subject_catchment; 33, string:"Must be one of `auto`, `force` or `exclude`."; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:query; 37, parenthesized_expression; 37, 38; 38, call; 38, 39; 38, 100; 39, attribute; 39, 40; 39, 99; 40, call; 40, 41; 40, 97; 41, attribute; 41, 42; 41, 96; 42, call; 42, 43; 42, 67; 43, attribute; 43, 44; 43, 66; 44, call; 44, 45; 44, 62; 45, attribute; 45, 46; 45, 61; 46, call; 46, 47; 46, 57; 47, attribute; 47, 48; 47, 56; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:db_session; 53, identifier:query; 54, argument_list; 54, 55; 55, identifier:Catchment; 56, identifier:join; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:Catchment; 60, identifier:descriptors; 61, identifier:join; 62, argument_list; 62, 63; 63, attribute; 63, 64; 63, 65; 64, identifier:Catchment; 65, identifier:amax_records; 66, identifier:filter; 67, argument_list; 67, 68; 67, 75; 67, 78; 67, 91; 68, comparison_operator:!=; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:Catchment; 71, identifier:id; 72, attribute; 72, 73; 72, 74; 73, identifier:subject_catchment; 74, identifier:id; 75, attribute; 75, 76; 75, 77; 76, identifier:Catchment; 77, identifier:is_suitable_for_pooling; 78, call; 78, 79; 78, 80; 79, identifier:or_; 80, argument_list; 80, 81; 80, 86; 81, comparison_operator:<; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:Descriptors; 84, identifier:urbext2000; 85, float:0.03; 86, comparison_operator:==; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:Descriptors; 89, identifier:urbext2000; 90, None; 91, comparison_operator:==; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:AmaxRecord; 94, identifier:flag; 95, integer:0; 96, identifier:group_by; 97, argument_list; 97, 98; 98, identifier:Catchment; 99, identifier:having; 100, argument_list; 100, 101; 101, comparison_operator:>=; 101, 102; 101, 110; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:func; 105, identifier:count; 106, argument_list; 106, 107; 107, attribute; 107, 108; 107, 109; 108, identifier:AmaxRecord; 109, identifier:catchment_id; 110, integer:10; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:catchments; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:query; 117, identifier:all; 118, argument_list; 119, if_statement; 119, 120; 119, 123; 119, 141; 120, comparison_operator:==; 120, 121; 120, 122; 121, identifier:include_subject_catchment; 122, string:'force'; 123, block; 123, 124; 124, if_statement; 124, 125; 124, 133; 125, comparison_operator:>=; 125, 126; 125, 132; 126, call; 126, 127; 126, 128; 127, identifier:len; 128, argument_list; 128, 129; 129, attribute; 129, 130; 129, 131; 130, identifier:subject_catchment; 131, identifier:amax_records; 132, integer:10; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:catchments; 138, identifier:append; 139, argument_list; 139, 140; 140, identifier:subject_catchment; 141, elif_clause; 141, 142; 141, 145; 142, comparison_operator:==; 142, 143; 142, 144; 143, identifier:include_subject_catchment; 144, string:'auto'; 145, block; 145, 146; 146, if_statement; 146, 147; 146, 177; 147, boolean_operator:and; 147, 148; 147, 160; 147, 161; 148, boolean_operator:and; 148, 149; 148, 157; 149, comparison_operator:>=; 149, 150; 149, 156; 150, call; 150, 151; 150, 152; 151, identifier:len; 152, argument_list; 152, 153; 153, attribute; 153, 154; 153, 155; 154, identifier:subject_catchment; 155, identifier:amax_records; 156, integer:10; 157, attribute; 157, 158; 157, 159; 158, identifier:subject_catchment; 159, identifier:is_suitable_for_pooling; 160, line_continuation:\; 161, parenthesized_expression; 161, 162; 162, boolean_operator:or; 162, 163; 162, 170; 163, comparison_operator:<; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:subject_catchment; 167, identifier:descriptors; 168, identifier:urbext2000; 169, float:0.03; 170, comparison_operator:is; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:subject_catchment; 174, identifier:descriptors; 175, identifier:urbext2000; 176, None; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:catchments; 182, identifier:append; 183, argument_list; 183, 184; 184, identifier:subject_catchment; 185, for_statement; 185, 186; 185, 187; 185, 188; 186, identifier:catchment; 187, identifier:catchments; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:catchment; 193, identifier:similarity_dist; 194, call; 194, 195; 194, 196; 195, identifier:similarity_dist_function; 196, argument_list; 196, 197; 196, 198; 197, identifier:subject_catchment; 198, identifier:catchment; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:catchments; 203, identifier:sort; 204, argument_list; 204, 205; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:key; 207, call; 207, 208; 207, 209; 208, identifier:attrgetter; 209, argument_list; 209, 210; 210, string:'similarity_dist'; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:amax_records_count; 214, integer:0; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:catchments_limited; 218, list:[]; 219, for_statement; 219, 220; 219, 221; 219, 222; 220, identifier:catchment; 221, identifier:catchments; 222, block; 222, 223; 222, 230; 222, 236; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:catchments_limited; 227, identifier:append; 228, argument_list; 228, 229; 229, identifier:catchment; 230, expression_statement; 230, 231; 231, augmented_assignment:+=; 231, 232; 231, 233; 232, identifier:amax_records_count; 233, attribute; 233, 234; 233, 235; 234, identifier:catchment; 235, identifier:record_length; 236, if_statement; 236, 237; 236, 240; 237, comparison_operator:>=; 237, 238; 237, 239; 238, identifier:amax_records_count; 239, identifier:records_limit; 240, block; 240, 241; 241, break_statement; 242, return_statement; 242, 243; 243, identifier:catchments_limited | def most_similar_catchments(self, subject_catchment, similarity_dist_function, records_limit=500,
include_subject_catchment='auto'):
if include_subject_catchment not in ['auto', 'force', 'exclude']:
raise ValueError("Parameter `include_subject_catchment={}` invalid.".format(include_subject_catchment) +
"Must be one of `auto`, `force` or `exclude`.")
query = (self.db_session.query(Catchment).
join(Catchment.descriptors).
join(Catchment.amax_records).
filter(Catchment.id != subject_catchment.id,
Catchment.is_suitable_for_pooling,
or_(Descriptors.urbext2000 < 0.03, Descriptors.urbext2000 == None),
AmaxRecord.flag == 0).
group_by(Catchment).
having(func.count(AmaxRecord.catchment_id) >= 10))
catchments = query.all()
if include_subject_catchment == 'force':
if len(subject_catchment.amax_records) >= 10:
catchments.append(subject_catchment)
elif include_subject_catchment == 'auto':
if len(subject_catchment.amax_records) >= 10 and subject_catchment.is_suitable_for_pooling and \
(subject_catchment.descriptors.urbext2000 < 0.03 or subject_catchment.descriptors.urbext2000 is None):
catchments.append(subject_catchment)
for catchment in catchments:
catchment.similarity_dist = similarity_dist_function(subject_catchment, catchment)
catchments.sort(key=attrgetter('similarity_dist'))
amax_records_count = 0
catchments_limited = []
for catchment in catchments:
catchments_limited.append(catchment)
amax_records_count += catchment.record_length
if amax_records_count >= records_limit:
break
return catchments_limited |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:readSAM; 3, parameters; 3, 4; 3, 5; 4, identifier:SAMfile; 5, default_parameter; 5, 6; 5, 7; 6, identifier:header; 7, False; 8, block; 8, 9; 8, 57; 8, 75; 8, 97; 8, 111; 8, 117; 8, 127; 8, 139; 8, 149; 8, 205; 8, 222; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:==; 10, 11; 10, 12; 11, identifier:header; 12, True; 13, block; 13, 14; 13, 22; 13, 26; 13, 51; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:f; 17, call; 17, 18; 17, 19; 18, identifier:open; 19, argument_list; 19, 20; 19, 21; 20, identifier:SAMfile; 21, string:"r+"; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:head; 25, list:[]; 26, for_statement; 26, 27; 26, 28; 26, 33; 27, identifier:line; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:f; 31, identifier:readlines; 32, argument_list; 33, block; 33, 34; 34, if_statement; 34, 35; 34, 40; 34, 48; 35, comparison_operator:==; 35, 36; 35, 39; 36, subscript; 36, 37; 36, 38; 37, identifier:line; 38, integer:0; 39, string:"@"; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:head; 45, identifier:append; 46, argument_list; 46, 47; 47, identifier:line; 48, else_clause; 48, 49; 49, block; 49, 50; 50, continue_statement; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:f; 55, identifier:close; 56, argument_list; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:sam; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:pd; 63, identifier:read_table; 64, argument_list; 64, 65; 64, 66; 64, 69; 64, 72; 65, identifier:SAMfile; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:sep; 68, string:"this_gives_one_column"; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:comment; 71, string:"@"; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:header; 74, None; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:sam; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:pd; 81, identifier:DataFrame; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 96; 84, attribute; 84, 85; 84, 95; 85, call; 85, 86; 85, 93; 86, attribute; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:sam; 90, integer:0; 91, identifier:str; 92, identifier:split; 93, argument_list; 93, 94; 94, string:"\t"; 95, identifier:tolist; 96, argument_list; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:acols; 100, list:[0,1,2,3,4,5,6,7,8,9]; 100, 101; 100, 102; 100, 103; 100, 104; 100, 105; 100, 106; 100, 107; 100, 108; 100, 109; 100, 110; 101, integer:0; 102, integer:1; 103, integer:2; 104, integer:3; 105, integer:4; 106, integer:5; 107, integer:6; 108, integer:7; 109, integer:8; 110, integer:9; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:sam_; 114, subscript; 114, 115; 114, 116; 115, identifier:sam; 116, identifier:acols; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:samcols; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:sam; 124, identifier:columns; 125, identifier:tolist; 126, argument_list; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:bcols; 130, list_comprehension; 130, 131; 130, 132; 130, 135; 131, identifier:s; 132, for_in_clause; 132, 133; 132, 134; 133, identifier:s; 134, identifier:samcols; 135, if_clause; 135, 136; 136, comparison_operator:not; 136, 137; 136, 138; 137, identifier:s; 138, identifier:acols; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:sam_; 143, integer:10; 144, subscript; 144, 145; 144, 146; 145, identifier:sam; 146, subscript; 146, 147; 146, 148; 147, identifier:bcols; 148, integer:0; 149, if_statement; 149, 150; 149, 156; 150, comparison_operator:>; 150, 151; 150, 155; 151, call; 151, 152; 151, 153; 152, identifier:len; 153, argument_list; 153, 154; 154, identifier:bcols; 155, integer:1; 156, block; 156, 157; 157, for_statement; 157, 158; 157, 159; 157, 164; 158, identifier:c; 159, subscript; 159, 160; 159, 161; 160, identifier:bcols; 161, slice; 161, 162; 161, 163; 162, integer:1; 163, colon; 164, block; 164, 165; 164, 178; 164, 191; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:sam_; 169, integer:10; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:sam_; 174, integer:10; 175, identifier:astype; 176, argument_list; 176, 177; 177, identifier:str; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:sam; 182, identifier:c; 183, call; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:sam; 187, identifier:c; 188, identifier:astype; 189, argument_list; 189, 190; 190, identifier:str; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 196; 193, subscript; 193, 194; 193, 195; 194, identifier:sam_; 195, integer:10; 196, binary_operator:+; 196, 197; 196, 202; 197, binary_operator:+; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:sam_; 200, integer:10; 201, string:"\t"; 202, subscript; 202, 203; 202, 204; 203, identifier:sam; 204, identifier:c; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:sam_; 209, identifier:columns; 210, list:['QNAME','FLAG','RNAME','POS','MAPQ','CIGAR','RNEXT','PNEXT','TLEN','SEQ','QUAL']; 210, 211; 210, 212; 210, 213; 210, 214; 210, 215; 210, 216; 210, 217; 210, 218; 210, 219; 210, 220; 210, 221; 211, string:'QNAME'; 212, string:'FLAG'; 213, string:'RNAME'; 214, string:'POS'; 215, string:'MAPQ'; 216, string:'CIGAR'; 217, string:'RNEXT'; 218, string:'PNEXT'; 219, string:'TLEN'; 220, string:'SEQ'; 221, string:'QUAL'; 222, if_statement; 222, 223; 222, 226; 222, 231; 223, comparison_operator:==; 223, 224; 223, 225; 224, identifier:header; 225, True; 226, block; 226, 227; 227, return_statement; 227, 228; 228, expression_list; 228, 229; 228, 230; 229, identifier:sam_; 230, identifier:head; 231, else_clause; 231, 232; 232, block; 232, 233; 233, return_statement; 233, 234; 234, identifier:sam_ | def readSAM(SAMfile,header=False):
if header==True:
f=open(SAMfile,"r+")
head=[]
for line in f.readlines():
if line[0]=="@":
head.append(line)
else:
continue
f.close()
sam=pd.read_table(SAMfile,sep="this_gives_one_column",comment="@",header=None)
sam=pd.DataFrame(sam[0].str.split("\t").tolist())
acols=[0,1,2,3,4,5,6,7,8,9]
sam_=sam[acols]
samcols=sam.columns.tolist()
bcols=[ s for s in samcols if s not in acols ]
sam_[10]=sam[bcols[0]]
if len(bcols) > 1:
for c in bcols[1:]:
sam_[10]=sam_[10].astype(str)
sam[c]=sam[c].astype(str)
sam_[10]=sam_[10]+"\t"+sam[c]
sam_.columns=['QNAME','FLAG','RNAME','POS','MAPQ','CIGAR','RNEXT','PNEXT','TLEN','SEQ','QUAL']
if header==True:
return sam_, head
else:
return sam_ |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:SAMflags; 3, parameters; 3, 4; 4, identifier:x; 5, block; 5, 6; 5, 10; 5, 25; 5, 32; 5, 47; 5, 54; 5, 69; 5, 76; 5, 91; 5, 98; 5, 113; 5, 120; 5, 135; 5, 142; 5, 157; 5, 164; 5, 179; 5, 186; 5, 201; 5, 208; 5, 223; 5, 230; 5, 245; 5, 252; 5, 267; 5, 274; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:flags; 9, list:[]; 10, if_statement; 10, 11; 10, 14; 10, 19; 11, binary_operator:&; 11, 12; 11, 13; 12, identifier:x; 13, integer:1; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:l; 18, string:"1: Read paired"; 19, else_clause; 19, 20; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:l; 24, string:"0: Read unpaired"; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:flags; 29, identifier:append; 30, argument_list; 30, 31; 31, identifier:l; 32, if_statement; 32, 33; 32, 36; 32, 41; 33, binary_operator:&; 33, 34; 33, 35; 34, identifier:x; 35, integer:2; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:l; 40, string:"1: Read mapped in proper pair"; 41, else_clause; 41, 42; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:l; 46, string:"0: Read not mapped in proper pair"; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:flags; 51, identifier:append; 52, argument_list; 52, 53; 53, identifier:l; 54, if_statement; 54, 55; 54, 58; 54, 63; 55, binary_operator:&; 55, 56; 55, 57; 56, identifier:x; 57, integer:4; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:l; 62, string:"1: Read unmapped"; 63, else_clause; 63, 64; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:l; 68, string:"0: Read mapped"; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:flags; 73, identifier:append; 74, argument_list; 74, 75; 75, identifier:l; 76, if_statement; 76, 77; 76, 80; 76, 85; 77, binary_operator:&; 77, 78; 77, 79; 78, identifier:x; 79, integer:8; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:l; 84, string:"1: Mate unmapped"; 85, else_clause; 85, 86; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:l; 90, string:"0: Mate mapped"; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:flags; 95, identifier:append; 96, argument_list; 96, 97; 97, identifier:l; 98, if_statement; 98, 99; 98, 102; 98, 107; 99, binary_operator:&; 99, 100; 99, 101; 100, identifier:x; 101, integer:16; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:l; 106, string:"1: Read reverse strand"; 107, else_clause; 107, 108; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:l; 112, string:"0: Read direct strand"; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:flags; 117, identifier:append; 118, argument_list; 118, 119; 119, identifier:l; 120, if_statement; 120, 121; 120, 124; 120, 129; 121, binary_operator:&; 121, 122; 121, 123; 122, identifier:x; 123, integer:32; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:l; 128, string:"1: Mate reverse strand"; 129, else_clause; 129, 130; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:l; 134, string:"0: Mate direct strand"; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:flags; 139, identifier:append; 140, argument_list; 140, 141; 141, identifier:l; 142, if_statement; 142, 143; 142, 146; 142, 151; 143, binary_operator:&; 143, 144; 143, 145; 144, identifier:x; 145, integer:64; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:l; 150, string:"1: First in pair"; 151, else_clause; 151, 152; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:l; 156, string:"0: Second in pair"; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:flags; 161, identifier:append; 162, argument_list; 162, 163; 163, identifier:l; 164, if_statement; 164, 165; 164, 168; 164, 173; 165, binary_operator:&; 165, 166; 165, 167; 166, identifier:x; 167, integer:128; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:l; 172, string:"1: Second in pair"; 173, else_clause; 173, 174; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:l; 178, string:"0: First in pair"; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:flags; 183, identifier:append; 184, argument_list; 184, 185; 185, identifier:l; 186, if_statement; 186, 187; 186, 190; 186, 195; 187, binary_operator:&; 187, 188; 187, 189; 188, identifier:x; 189, integer:256; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:l; 194, string:"1: Not primary alignment"; 195, else_clause; 195, 196; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:l; 200, string:"0: Primary alignment"; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:flags; 205, identifier:append; 206, argument_list; 206, 207; 207, identifier:l; 208, if_statement; 208, 209; 208, 212; 208, 217; 209, binary_operator:&; 209, 210; 209, 211; 210, identifier:x; 211, integer:512; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:l; 216, string:"1: Read fails platform/vendor quality checks"; 217, else_clause; 217, 218; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:l; 222, string:"0: Read passes platform/vendor quality checks"; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:flags; 227, identifier:append; 228, argument_list; 228, 229; 229, identifier:l; 230, if_statement; 230, 231; 230, 234; 230, 239; 231, binary_operator:&; 231, 232; 231, 233; 232, identifier:x; 233, integer:1024; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:l; 238, string:"1: Read is PCR or optical duplicate"; 239, else_clause; 239, 240; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:l; 244, string:"0: Read is not PCR or optical duplicate"; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:flags; 249, identifier:append; 250, argument_list; 250, 251; 251, identifier:l; 252, if_statement; 252, 253; 252, 256; 252, 261; 253, binary_operator:&; 253, 254; 253, 255; 254, identifier:x; 255, integer:2048; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:l; 260, string:"1: Supplementary alignment"; 261, else_clause; 261, 262; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:l; 266, string:"0: Not supplementary alignment"; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:flags; 271, identifier:append; 272, argument_list; 272, 273; 273, identifier:l; 274, return_statement; 274, 275; 275, identifier:flags | def SAMflags(x):
flags=[]
if x & 1:
l="1: Read paired"
else:
l="0: Read unpaired"
flags.append(l)
if x & 2 :
l="1: Read mapped in proper pair"
else:
l="0: Read not mapped in proper pair"
flags.append(l)
if x & 4 :
l="1: Read unmapped"
else:
l="0: Read mapped"
flags.append(l)
if x & 8 :
l="1: Mate unmapped"
else:
l="0: Mate mapped"
flags.append(l)
if x & 16 :
l="1: Read reverse strand"
else:
l="0: Read direct strand"
flags.append(l)
if x & 32 :
l="1: Mate reverse strand"
else:
l="0: Mate direct strand"
flags.append(l)
if x & 64 :
l="1: First in pair"
else:
l="0: Second in pair"
flags.append(l)
if x & 128 :
l="1: Second in pair"
else:
l="0: First in pair"
flags.append(l)
if x & 256 :
l="1: Not primary alignment"
else:
l="0: Primary alignment"
flags.append(l)
if x & 512 :
l="1: Read fails platform/vendor quality checks"
else:
l="0: Read passes platform/vendor quality checks"
flags.append(l)
if x & 1024 :
l="1: Read is PCR or optical duplicate"
else:
l="0: Read is not PCR or optical duplicate"
flags.append(l)
if x & 2048 :
l="1: Supplementary alignment"
else:
l="0: Not supplementary alignment"
flags.append(l)
return flags |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 74; 2, function_name:BLASTquery; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 11; 3, 14; 3, 17; 3, 18; 3, 21; 3, 24; 3, 25; 3, 28; 3, 31; 3, 32; 3, 35; 3, 38; 3, 39; 3, 42; 3, 43; 3, 46; 3, 49; 3, 50; 3, 53; 3, 56; 3, 57; 3, 60; 3, 63; 3, 64; 3, 67; 3, 70; 3, 71; 4, identifier:query; 5, identifier:database; 6, identifier:program; 7, default_parameter; 7, 8; 7, 9; 8, identifier:filter; 9, None; 10, line_continuation:\; 11, default_parameter; 11, 12; 11, 13; 12, identifier:format_type; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:expect; 16, None; 17, line_continuation:\; 18, default_parameter; 18, 19; 18, 20; 19, identifier:nucl_reward; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:nucl_penalty; 23, None; 24, line_continuation:\; 25, default_parameter; 25, 26; 25, 27; 26, identifier:gapcosts; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:matrix; 30, None; 31, line_continuation:\; 32, default_parameter; 32, 33; 32, 34; 33, identifier:hitlist_size; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:descriptions; 37, None; 38, line_continuation:\; 39, default_parameter; 39, 40; 39, 41; 40, identifier:alignments; 41, None; 42, line_continuation:\; 43, default_parameter; 43, 44; 43, 45; 44, identifier:ncbi_gi; 45, None; 46, default_parameter; 46, 47; 46, 48; 47, identifier:threshold; 48, None; 49, line_continuation:\; 50, default_parameter; 50, 51; 50, 52; 51, identifier:word_size; 52, None; 53, default_parameter; 53, 54; 53, 55; 54, identifier:composition_based_statistics; 55, None; 56, line_continuation:\; 57, default_parameter; 57, 58; 57, 59; 58, identifier:organism; 59, None; 60, default_parameter; 60, 61; 60, 62; 61, identifier:others; 62, None; 63, line_continuation:\; 64, default_parameter; 64, 65; 64, 66; 65, identifier:num_threads; 66, None; 67, default_parameter; 67, 68; 67, 69; 68, identifier:baseURL; 69, string:"http://blast.ncbi.nlm.nih.gov"; 70, line_continuation:\; 71, default_parameter; 71, 72; 71, 73; 72, identifier:verbose; 73, False; 74, block; 74, 75; 74, 116; 74, 122; 74, 147; 74, 211; 74, 222; 74, 228; 74, 244; 74, 255; 74, 266; 74, 278; 74, 311; 75, if_statement; 75, 76; 75, 77; 75, 110; 76, identifier:organism; 77, block; 77, 78; 77, 106; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:organism; 81, call; 81, 82; 81, 103; 82, attribute; 82, 83; 82, 102; 83, call; 83, 84; 83, 99; 84, attribute; 84, 85; 84, 98; 85, call; 85, 86; 85, 95; 86, attribute; 86, 87; 86, 94; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:organism; 90, identifier:replace; 91, argument_list; 91, 92; 91, 93; 92, string:" "; 93, string:"%20"; 94, identifier:replace; 95, argument_list; 95, 96; 95, 97; 96, string:"("; 97, string:"%28"; 98, identifier:replace; 99, argument_list; 99, 100; 99, 101; 100, string:")"; 101, string:"%29"; 102, identifier:replace; 103, argument_list; 103, 104; 103, 105; 104, string:":"; 105, string:"%3A"; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:EQ_MENU; 109, identifier:organism; 110, else_clause; 110, 111; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:EQ_MENU; 115, None; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:URL; 119, binary_operator:+; 119, 120; 119, 121; 120, identifier:baseURL; 121, string:"/Blast.cgi?"; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:URL; 125, binary_operator:+; 125, 126; 125, 143; 126, binary_operator:+; 126, 127; 126, 142; 127, binary_operator:+; 127, 128; 127, 138; 128, binary_operator:+; 128, 129; 128, 137; 129, binary_operator:+; 129, 130; 129, 133; 130, binary_operator:+; 130, 131; 130, 132; 131, identifier:URL; 132, string:"QUERY="; 133, call; 133, 134; 133, 135; 134, identifier:str; 135, argument_list; 135, 136; 136, identifier:query; 137, string:"&DATABASE="; 138, call; 138, 139; 138, 140; 139, identifier:str; 140, argument_list; 140, 141; 141, identifier:database; 142, string:"&PROGRAM="; 143, call; 143, 144; 143, 145; 144, identifier:str; 145, argument_list; 145, 146; 146, identifier:program; 147, for_statement; 147, 148; 147, 151; 147, 192; 148, pattern_list; 148, 149; 148, 150; 149, identifier:o; 150, identifier:varname; 151, call; 151, 152; 151, 153; 152, identifier:zip; 153, argument_list; 153, 154; 153, 174; 153, 175; 154, list:[filter, format_type, expect, nucl_reward, nucl_penalty,\
gapcosts, matrix, hitlist_size, descriptions, alignments,\
ncbi_gi, threshold, word_size, composition_based_statistics,\
EQ_MENU, num_threads]; 154, 155; 154, 156; 154, 157; 154, 158; 154, 159; 154, 160; 154, 161; 154, 162; 154, 163; 154, 164; 154, 165; 154, 166; 154, 167; 154, 168; 154, 169; 154, 170; 154, 171; 154, 172; 154, 173; 155, identifier:filter; 156, identifier:format_type; 157, identifier:expect; 158, identifier:nucl_reward; 159, identifier:nucl_penalty; 160, line_continuation:\; 161, identifier:gapcosts; 162, identifier:matrix; 163, identifier:hitlist_size; 164, identifier:descriptions; 165, identifier:alignments; 166, line_continuation:\; 167, identifier:ncbi_gi; 168, identifier:threshold; 169, identifier:word_size; 170, identifier:composition_based_statistics; 171, line_continuation:\; 172, identifier:EQ_MENU; 173, identifier:num_threads; 174, line_continuation:\; 175, list:['FILTER' , 'FORMAT_TYPE', 'EXPECT', 'NUCL_REWARD', 'NUCL_PENALTY',\
'GAPCOSTS', 'MATRIX', 'HITLIST_SIZE', 'DESCRIPTIONS', 'ALIGNMENTS',\
'NCBI_GI', 'THRESHOLD', 'WORD_SIZE', 'COMPOSITION_BASED_STATISTICS',\
'EQ_MENU', 'NUM_THREADS']; 175, 176; 175, 177; 175, 178; 175, 179; 175, 180; 175, 181; 175, 182; 175, 183; 175, 184; 175, 185; 175, 186; 175, 187; 175, 188; 175, 189; 175, 190; 175, 191; 176, string:'FILTER'; 177, string:'FORMAT_TYPE'; 178, string:'EXPECT'; 179, string:'NUCL_REWARD'; 180, string:'NUCL_PENALTY'; 181, string:'GAPCOSTS'; 182, string:'MATRIX'; 183, string:'HITLIST_SIZE'; 184, string:'DESCRIPTIONS'; 185, string:'ALIGNMENTS'; 186, string:'NCBI_GI'; 187, string:'THRESHOLD'; 188, string:'WORD_SIZE'; 189, string:'COMPOSITION_BASED_STATISTICS'; 190, string:'EQ_MENU'; 191, string:'NUM_THREADS'; 192, block; 192, 193; 193, if_statement; 193, 194; 193, 195; 194, identifier:o; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:URL; 199, binary_operator:+; 199, 200; 199, 207; 200, binary_operator:+; 200, 201; 200, 206; 201, binary_operator:+; 201, 202; 201, 205; 202, binary_operator:+; 202, 203; 202, 204; 203, identifier:URL; 204, string:"&"; 205, identifier:varname; 206, string:"="; 207, call; 207, 208; 207, 209; 208, identifier:str; 209, argument_list; 209, 210; 210, identifier:o; 211, if_statement; 211, 212; 211, 213; 212, identifier:others; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:URL; 217, binary_operator:+; 217, 218; 217, 221; 218, binary_operator:+; 218, 219; 218, 220; 219, identifier:URL; 220, string:"&"; 221, identifier:others; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:URL; 225, binary_operator:+; 225, 226; 225, 227; 226, identifier:URL; 227, string:"&CMD=Put"; 228, if_statement; 228, 229; 228, 230; 229, identifier:verbose; 230, block; 230, 231; 230, 236; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:print; 234, argument_list; 234, 235; 235, identifier:URL; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 243; 238, attribute; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:sys; 241, identifier:stdout; 242, identifier:flush; 243, argument_list; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:response; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:requests; 250, identifier:get; 251, argument_list; 251, 252; 252, keyword_argument; 252, 253; 252, 254; 253, identifier:url; 254, identifier:URL; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:r; 258, call; 258, 259; 258, 264; 259, attribute; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:response; 262, identifier:content; 263, identifier:split; 264, argument_list; 264, 265; 265, string:"\n"; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:RID; 269, list_comprehension; 269, 270; 269, 271; 269, 274; 270, identifier:s; 271, for_in_clause; 271, 272; 271, 273; 272, identifier:s; 273, identifier:r; 274, if_clause; 274, 275; 275, comparison_operator:in; 275, 276; 275, 277; 276, string:"RID = "; 277, identifier:s; 278, if_statement; 278, 279; 278, 285; 278, 300; 279, comparison_operator:>; 279, 280; 279, 284; 280, call; 280, 281; 280, 282; 281, identifier:len; 282, argument_list; 282, 283; 283, identifier:RID; 284, integer:0; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:RID; 289, subscript; 289, 290; 289, 298; 290, call; 290, 291; 290, 296; 291, attribute; 291, 292; 291, 295; 292, subscript; 292, 293; 292, 294; 293, identifier:RID; 294, integer:0; 295, identifier:split; 296, argument_list; 296, 297; 297, string:" "; 298, unary_operator:-; 298, 299; 299, integer:1; 300, else_clause; 300, 301; 301, block; 301, 302; 301, 307; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:print; 305, argument_list; 305, 306; 306, string:"Could not return an RID for this query."; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:RID; 310, None; 311, return_statement; 311, 312; 312, identifier:RID | def BLASTquery(query,database,program,filter=None,\
format_type=None, expect=None,\
nucl_reward=None, nucl_penalty=None,\
gapcosts=None, matrix=None,\
hitlist_size=None, descriptions=None,\
alignments=None,\
ncbi_gi=None, threshold=None,\
word_size=None, composition_based_statistics=None,\
organism=None, others=None,\
num_threads=None, baseURL="http://blast.ncbi.nlm.nih.gov",\
verbose=False):
if organism:
organism=organism.replace(" ", "%20").replace("(", "%28").replace(")", "%29").replace(":", "%3A")
EQ_MENU=organism
else:
EQ_MENU=None
URL=baseURL+"/Blast.cgi?"
URL=URL+"QUERY="+str(query)+"&DATABASE="+str(database)+"&PROGRAM="+str(program)
for o,varname in zip([filter, format_type, expect, nucl_reward, nucl_penalty,\
gapcosts, matrix, hitlist_size, descriptions, alignments,\
ncbi_gi, threshold, word_size, composition_based_statistics,\
EQ_MENU, num_threads],\
['FILTER' , 'FORMAT_TYPE', 'EXPECT', 'NUCL_REWARD', 'NUCL_PENALTY',\
'GAPCOSTS', 'MATRIX', 'HITLIST_SIZE', 'DESCRIPTIONS', 'ALIGNMENTS',\
'NCBI_GI', 'THRESHOLD', 'WORD_SIZE', 'COMPOSITION_BASED_STATISTICS',\
'EQ_MENU', 'NUM_THREADS']):
if o:
URL=URL+"&"+ varname +"="+str(o)
if others:
URL=URL+"&"+others
URL=URL+"&CMD=Put"
if verbose:
print(URL)
sys.stdout.flush()
response=requests.get(url = URL)
r=response.content.split("\n")
RID=[ s for s in r if "RID = " in s ]
if len(RID) > 0:
RID=RID[0].split(" ")[-1]
else:
print("Could not return an RID for this query.")
RID=None
return RID |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:run_star; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:job; 5, identifier:fastqs; 6, identifier:univ_options; 7, identifier:star_options; 8, block; 8, 9; 8, 17; 8, 25; 8, 44; 8, 56; 8, 68; 8, 99; 8, 111; 8, 125; 8, 141; 8, 163; 8, 224; 8, 236; 8, 291; 8, 297; 8, 324; 8, 337; 8, 350; 8, 363; 9, assert_statement; 9, 10; 10, comparison_operator:in; 10, 11; 10, 14; 11, subscript; 11, 12; 11, 13; 12, identifier:star_options; 13, string:'type'; 14, tuple; 14, 15; 14, 16; 15, string:'star'; 16, string:'starlong'; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:work_dir; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:os; 23, identifier:getcwd; 24, argument_list; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:input_files; 28, dictionary; 28, 29; 28, 34; 28, 39; 29, pair; 29, 30; 29, 31; 30, string:'rna_cutadapt_1.fastq'; 31, subscript; 31, 32; 31, 33; 32, identifier:fastqs; 33, integer:0; 34, pair; 34, 35; 34, 36; 35, string:'rna_cutadapt_2.fastq'; 36, subscript; 36, 37; 36, 38; 37, identifier:fastqs; 38, integer:1; 39, pair; 39, 40; 39, 41; 40, string:'star_index.tar.gz'; 41, subscript; 41, 42; 41, 43; 42, identifier:star_options; 43, string:'index'; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:input_files; 47, call; 47, 48; 47, 49; 48, identifier:get_files_from_filestore; 49, argument_list; 49, 50; 49, 51; 49, 52; 49, 53; 50, identifier:job; 51, identifier:input_files; 52, identifier:work_dir; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:docker; 55, False; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:gz; 59, conditional_expression:if; 59, 60; 59, 61; 59, 67; 60, string:'.gz'; 61, call; 61, 62; 61, 63; 62, identifier:is_gzipfile; 63, argument_list; 63, 64; 64, subscript; 64, 65; 64, 66; 65, identifier:input_files; 66, string:'rna_cutadapt_1.fastq'; 67, string:''; 68, if_statement; 68, 69; 68, 70; 69, identifier:gz; 70, block; 70, 71; 71, for_statement; 71, 72; 71, 73; 71, 76; 72, identifier:read_file; 73, expression_list; 73, 74; 73, 75; 74, string:'rna_cutadapt_1.fastq'; 75, string:'rna_cutadapt_2.fastq'; 76, block; 76, 77; 76, 87; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:os; 81, identifier:symlink; 82, argument_list; 82, 83; 82, 84; 83, identifier:read_file; 84, binary_operator:+; 84, 85; 84, 86; 85, identifier:read_file; 86, identifier:gz; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 94; 89, subscript; 89, 90; 89, 91; 90, identifier:input_files; 91, binary_operator:+; 91, 92; 91, 93; 92, identifier:read_file; 93, identifier:gz; 94, binary_operator:+; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:input_files; 97, identifier:read_file; 98, identifier:gz; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:input_files; 103, string:'star_index'; 104, call; 104, 105; 104, 106; 105, identifier:untargz; 106, argument_list; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:input_files; 109, string:'star_index.tar.gz'; 110, identifier:work_dir; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:star_fusion_idx; 114, call; 114, 115; 114, 120; 115, attribute; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:os; 118, identifier:path; 119, identifier:join; 120, argument_list; 120, 121; 120, 124; 121, subscript; 121, 122; 121, 123; 122, identifier:input_files; 123, string:'star_index'; 124, string:'ref_genome.fa.star.idx'; 125, if_statement; 125, 126; 125, 134; 126, call; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:os; 130, identifier:path; 131, identifier:exists; 132, argument_list; 132, 133; 133, identifier:star_fusion_idx; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:input_files; 139, string:'star_index'; 140, identifier:star_fusion_idx; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:input_files; 144, dictionary_comprehension; 144, 145; 144, 154; 145, pair; 145, 146; 145, 147; 146, identifier:key; 147, call; 147, 148; 147, 149; 148, identifier:docker_path; 149, argument_list; 149, 150; 149, 151; 150, identifier:path; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:work_dir; 153, identifier:work_dir; 154, for_in_clause; 154, 155; 154, 158; 155, pattern_list; 155, 156; 155, 157; 156, identifier:key; 157, identifier:path; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:input_files; 161, identifier:items; 162, argument_list; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:parameters; 166, list:['--runThreadN', str(star_options['n']),
'--genomeDir', input_files['star_index'],
'--twopassMode', 'Basic',
'--outReadsUnmapped', 'None',
'--chimSegmentMin', '12',
'--chimJunctionOverhangMin', '12',
'--alignSJDBoverhangMin', '10',
'--alignMatesGapMax', '200000',
'--alignIntronMax', '200000',
'--chimSegmentReadGapMax', 'parameter', '3',
'--alignSJstitchMismatchNmax', '5', '-1', '5', '5',
'--outFileNamePrefix', 'rna',
'--readFilesIn',
input_files['rna_cutadapt_1.fastq' + gz],
input_files['rna_cutadapt_2.fastq' + gz],
'--outSAMattributes', 'NH', 'HI', 'AS', 'NM', 'MD',
'--outSAMtype', 'BAM', 'Unsorted',
'--quantMode', 'TranscriptomeSAM']; 166, 167; 166, 168; 166, 174; 166, 175; 166, 178; 166, 179; 166, 180; 166, 181; 166, 182; 166, 183; 166, 184; 166, 185; 166, 186; 166, 187; 166, 188; 166, 189; 166, 190; 166, 191; 166, 192; 166, 193; 166, 194; 166, 195; 166, 196; 166, 197; 166, 198; 166, 199; 166, 200; 166, 201; 166, 202; 166, 203; 166, 208; 166, 213; 166, 214; 166, 215; 166, 216; 166, 217; 166, 218; 166, 219; 166, 220; 166, 221; 166, 222; 166, 223; 167, string:'--runThreadN'; 168, call; 168, 169; 168, 170; 169, identifier:str; 170, argument_list; 170, 171; 171, subscript; 171, 172; 171, 173; 172, identifier:star_options; 173, string:'n'; 174, string:'--genomeDir'; 175, subscript; 175, 176; 175, 177; 176, identifier:input_files; 177, string:'star_index'; 178, string:'--twopassMode'; 179, string:'Basic'; 180, string:'--outReadsUnmapped'; 181, string:'None'; 182, string:'--chimSegmentMin'; 183, string:'12'; 184, string:'--chimJunctionOverhangMin'; 185, string:'12'; 186, string:'--alignSJDBoverhangMin'; 187, string:'10'; 188, string:'--alignMatesGapMax'; 189, string:'200000'; 190, string:'--alignIntronMax'; 191, string:'200000'; 192, string:'--chimSegmentReadGapMax'; 193, string:'parameter'; 194, string:'3'; 195, string:'--alignSJstitchMismatchNmax'; 196, string:'5'; 197, string:'-1'; 198, string:'5'; 199, string:'5'; 200, string:'--outFileNamePrefix'; 201, string:'rna'; 202, string:'--readFilesIn'; 203, subscript; 203, 204; 203, 205; 204, identifier:input_files; 205, binary_operator:+; 205, 206; 205, 207; 206, string:'rna_cutadapt_1.fastq'; 207, identifier:gz; 208, subscript; 208, 209; 208, 210; 209, identifier:input_files; 210, binary_operator:+; 210, 211; 210, 212; 211, string:'rna_cutadapt_2.fastq'; 212, identifier:gz; 213, string:'--outSAMattributes'; 214, string:'NH'; 215, string:'HI'; 216, string:'AS'; 217, string:'NM'; 218, string:'MD'; 219, string:'--outSAMtype'; 220, string:'BAM'; 221, string:'Unsorted'; 222, string:'--quantMode'; 223, string:'TranscriptomeSAM'; 224, if_statement; 224, 225; 224, 226; 225, identifier:gz; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:parameters; 231, identifier:extend; 232, argument_list; 232, 233; 233, list:['--readFilesCommand', 'zcat']; 233, 234; 233, 235; 234, string:'--readFilesCommand'; 235, string:'zcat'; 236, if_statement; 236, 237; 236, 242; 236, 266; 237, comparison_operator:==; 237, 238; 237, 241; 238, subscript; 238, 239; 238, 240; 239, identifier:star_options; 240, string:'type'; 241, string:'star'; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 246; 245, identifier:docker_call; 246, argument_list; 246, 247; 246, 250; 246, 253; 246, 256; 246, 261; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:tool; 249, string:'star'; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:tool_parameters; 252, identifier:parameters; 253, keyword_argument; 253, 254; 253, 255; 254, identifier:work_dir; 255, identifier:work_dir; 256, keyword_argument; 256, 257; 256, 258; 257, identifier:dockerhub; 258, subscript; 258, 259; 258, 260; 259, identifier:univ_options; 260, string:'dockerhub'; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:tool_version; 263, subscript; 263, 264; 263, 265; 264, identifier:star_options; 265, string:'version'; 266, else_clause; 266, 267; 267, block; 267, 268; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 271; 270, identifier:docker_call; 271, argument_list; 271, 272; 271, 275; 271, 278; 271, 281; 271, 286; 272, keyword_argument; 272, 273; 272, 274; 273, identifier:tool; 274, string:'starlong'; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:tool_parameters; 277, identifier:parameters; 278, keyword_argument; 278, 279; 278, 280; 279, identifier:work_dir; 280, identifier:work_dir; 281, keyword_argument; 281, 282; 281, 283; 282, identifier:dockerhub; 283, subscript; 283, 284; 283, 285; 284, identifier:univ_options; 285, string:'dockerhub'; 286, keyword_argument; 286, 287; 286, 288; 287, identifier:tool_version; 288, subscript; 288, 289; 288, 290; 289, identifier:star_options; 290, string:'version'; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:output_files; 294, call; 294, 295; 294, 296; 295, identifier:defaultdict; 296, argument_list; 297, for_statement; 297, 298; 297, 299; 297, 303; 298, identifier:output_file; 299, list:['rnaAligned.toTranscriptome.out.bam',
'rnaAligned.out.bam',
'rnaChimeric.out.junction']; 299, 300; 299, 301; 299, 302; 300, string:'rnaAligned.toTranscriptome.out.bam'; 301, string:'rnaAligned.out.bam'; 302, string:'rnaChimeric.out.junction'; 303, block; 303, 304; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 309; 306, subscript; 306, 307; 306, 308; 307, identifier:output_files; 308, identifier:output_file; 309, call; 309, 310; 309, 315; 310, attribute; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:job; 313, identifier:fileStore; 314, identifier:writeGlobalFile; 315, argument_list; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, string:'/'; 319, identifier:join; 320, argument_list; 320, 321; 321, list:[work_dir, output_file]; 321, 322; 321, 323; 322, identifier:work_dir; 323, identifier:output_file; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 327; 326, identifier:export_results; 327, argument_list; 327, 328; 327, 329; 327, 332; 327, 333; 327, 334; 328, identifier:job; 329, subscript; 329, 330; 329, 331; 330, identifier:output_files; 331, string:'rnaAligned.toTranscriptome.out.bam'; 332, string:'rna_transcriptome.bam'; 333, identifier:univ_options; 334, keyword_argument; 334, 335; 334, 336; 335, identifier:subfolder; 336, string:'alignments'; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 340; 339, identifier:export_results; 340, argument_list; 340, 341; 340, 342; 340, 345; 340, 346; 340, 347; 341, identifier:job; 342, subscript; 342, 343; 342, 344; 343, identifier:output_files; 344, string:'rnaChimeric.out.junction'; 345, string:'rna_chimeric.junction'; 346, identifier:univ_options; 347, keyword_argument; 347, 348; 347, 349; 348, identifier:subfolder; 349, string:'mutations/fusions'; 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:job; 355, identifier:fileStore; 356, identifier:logToMaster; 357, argument_list; 357, 358; 358, binary_operator:%; 358, 359; 358, 360; 359, string:'Ran STAR on %s successfully'; 360, subscript; 360, 361; 360, 362; 361, identifier:univ_options; 362, string:'patient'; 363, return_statement; 363, 364; 364, identifier:output_files | def run_star(job, fastqs, univ_options, star_options):
assert star_options['type'] in ('star', 'starlong')
work_dir = os.getcwd()
input_files = {
'rna_cutadapt_1.fastq': fastqs[0],
'rna_cutadapt_2.fastq': fastqs[1],
'star_index.tar.gz': star_options['index']}
input_files = get_files_from_filestore(job, input_files, work_dir,
docker=False)
gz = '.gz' if is_gzipfile(input_files['rna_cutadapt_1.fastq']) else ''
if gz:
for read_file in 'rna_cutadapt_1.fastq', 'rna_cutadapt_2.fastq':
os.symlink(read_file, read_file + gz)
input_files[read_file + gz] = input_files[read_file] + gz
input_files['star_index'] = untargz(input_files['star_index.tar.gz'], work_dir)
star_fusion_idx = os.path.join(input_files['star_index'], 'ref_genome.fa.star.idx')
if os.path.exists(star_fusion_idx):
input_files['star_index'] = star_fusion_idx
input_files = {key: docker_path(path, work_dir=work_dir) for key, path in input_files.items()}
parameters = ['--runThreadN', str(star_options['n']),
'--genomeDir', input_files['star_index'],
'--twopassMode', 'Basic',
'--outReadsUnmapped', 'None',
'--chimSegmentMin', '12',
'--chimJunctionOverhangMin', '12',
'--alignSJDBoverhangMin', '10',
'--alignMatesGapMax', '200000',
'--alignIntronMax', '200000',
'--chimSegmentReadGapMax', 'parameter', '3',
'--alignSJstitchMismatchNmax', '5', '-1', '5', '5',
'--outFileNamePrefix', 'rna',
'--readFilesIn',
input_files['rna_cutadapt_1.fastq' + gz],
input_files['rna_cutadapt_2.fastq' + gz],
'--outSAMattributes', 'NH', 'HI', 'AS', 'NM', 'MD',
'--outSAMtype', 'BAM', 'Unsorted',
'--quantMode', 'TranscriptomeSAM']
if gz:
parameters.extend(['--readFilesCommand', 'zcat'])
if star_options['type'] == 'star':
docker_call(tool='star', tool_parameters=parameters, work_dir=work_dir,
dockerhub=univ_options['dockerhub'], tool_version=star_options['version'])
else:
docker_call(tool='starlong', tool_parameters=parameters, work_dir=work_dir,
dockerhub=univ_options['dockerhub'], tool_version=star_options['version'])
output_files = defaultdict()
for output_file in ['rnaAligned.toTranscriptome.out.bam',
'rnaAligned.out.bam',
'rnaChimeric.out.junction']:
output_files[output_file] = job.fileStore.writeGlobalFile('/'.join([work_dir, output_file]))
export_results(job, output_files['rnaAligned.toTranscriptome.out.bam'], 'rna_transcriptome.bam',
univ_options, subfolder='alignments')
export_results(job, output_files['rnaChimeric.out.junction'], 'rna_chimeric.junction',
univ_options, subfolder='mutations/fusions')
job.fileStore.logToMaster('Ran STAR on %s successfully' % univ_options['patient'])
return output_files |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_and_index_star; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:job; 5, identifier:star_bams; 6, identifier:univ_options; 7, identifier:star_options; 8, block; 8, 9; 8, 19; 8, 47; 8, 82; 8, 89; 8, 96; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 16; 11, subscript; 11, 12; 11, 15; 12, subscript; 12, 13; 12, 14; 13, identifier:star_options; 14, string:'samtools'; 15, string:'n'; 16, subscript; 16, 17; 16, 18; 17, identifier:star_options; 18, string:'n'; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:sort; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:job; 25, identifier:wrapJobFn; 26, argument_list; 26, 27; 26, 28; 26, 31; 26, 32; 26, 33; 26, 38; 27, identifier:sort_bamfile; 28, subscript; 28, 29; 28, 30; 29, identifier:star_bams; 30, string:'rnaAligned.out.bam'; 31, string:'rna'; 32, identifier:univ_options; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:samtools_options; 35, subscript; 35, 36; 35, 37; 36, identifier:star_options; 37, string:'samtools'; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:disk; 40, call; 40, 41; 40, 42; 41, identifier:PromisedRequirement; 42, argument_list; 42, 43; 42, 44; 43, identifier:sort_disk; 44, subscript; 44, 45; 44, 46; 45, identifier:star_bams; 46, string:'rnaAligned.out.bam'; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:index; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:job; 53, identifier:wrapJobFn; 54, argument_list; 54, 55; 54, 56; 54, 61; 54, 62; 54, 63; 54, 68; 54, 71; 55, identifier:index_bamfile; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:sort; 59, identifier:rv; 60, argument_list; 61, string:'rna'; 62, identifier:univ_options; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:samtools_options; 65, subscript; 65, 66; 65, 67; 66, identifier:star_options; 67, string:'samtools'; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:sample_info; 70, string:'genome_sorted'; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:disk; 73, call; 73, 74; 73, 75; 74, identifier:PromisedRequirement; 75, argument_list; 75, 76; 75, 77; 76, identifier:index_disk; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:sort; 80, identifier:rv; 81, argument_list; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:job; 86, identifier:addChild; 87, argument_list; 87, 88; 88, identifier:sort; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:sort; 93, identifier:addChild; 94, argument_list; 94, 95; 95, identifier:index; 96, return_statement; 96, 97; 97, dictionary; 97, 98; 97, 105; 97, 110; 98, pair; 98, 99; 98, 100; 99, string:'rna_genome'; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:index; 103, identifier:rv; 104, argument_list; 105, pair; 105, 106; 105, 107; 106, string:'rna_transcriptome.bam'; 107, subscript; 107, 108; 107, 109; 108, identifier:star_bams; 109, string:'rnaAligned.toTranscriptome.out.bam'; 110, pair; 110, 111; 110, 112; 111, string:'rnaChimeric.out.junction'; 112, subscript; 112, 113; 112, 114; 113, identifier:star_bams; 114, string:'rnaChimeric.out.junction' | def sort_and_index_star(job, star_bams, univ_options, star_options):
star_options['samtools']['n'] = star_options['n']
sort = job.wrapJobFn(sort_bamfile, star_bams['rnaAligned.out.bam'], 'rna', univ_options,
samtools_options=star_options['samtools'],
disk=PromisedRequirement(sort_disk, star_bams['rnaAligned.out.bam']))
index = job.wrapJobFn(index_bamfile, sort.rv(), 'rna', univ_options,
samtools_options=star_options['samtools'], sample_info='genome_sorted',
disk=PromisedRequirement(index_disk, sort.rv()))
job.addChild(sort)
sort.addChild(index)
return {'rna_genome': index.rv(),
'rna_transcriptome.bam': star_bams['rnaAligned.toTranscriptome.out.bam'],
'rnaChimeric.out.junction': star_bams['rnaChimeric.out.junction']} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:evaluate; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 14; 5, 67; 5, 84; 5, 88; 5, 191; 5, 204; 5, 212; 5, 229; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:ops; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:rpn; 13, list:[]; 14, for_statement; 14, 15; 14, 16; 14, 19; 15, identifier:token; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:expr; 19, block; 19, 20; 20, if_statement; 20, 21; 20, 26; 20, 58; 21, call; 21, 22; 21, 23; 22, identifier:isinstance; 23, argument_list; 23, 24; 23, 25; 24, identifier:token; 25, identifier:int; 26, block; 26, 27; 26, 51; 27, while_statement; 27, 28; 27, 39; 28, boolean_operator:and; 28, 29; 28, 33; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, identifier:ops; 33, comparison_operator:<=; 33, 34; 33, 35; 34, identifier:token; 35, subscript; 35, 36; 35, 37; 36, identifier:ops; 37, unary_operator:-; 37, 38; 38, integer:1; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:rpn; 44, identifier:append; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:ops; 49, identifier:pop; 50, argument_list; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:ops; 55, identifier:append; 56, argument_list; 56, 57; 57, identifier:token; 58, else_clause; 58, 59; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:rpn; 64, identifier:append; 65, argument_list; 65, 66; 66, identifier:token; 67, while_statement; 67, 68; 67, 72; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:ops; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:rpn; 77, identifier:append; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:ops; 82, identifier:pop; 83, argument_list; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:stack; 87, list:[]; 88, for_statement; 88, 89; 88, 90; 88, 91; 89, identifier:token; 90, identifier:rpn; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 98; 92, 182; 93, call; 93, 94; 93, 95; 94, identifier:isinstance; 95, argument_list; 95, 96; 95, 97; 96, identifier:token; 97, identifier:int; 98, block; 98, 99; 98, 120; 98, 133; 98, 172; 99, if_statement; 99, 100; 99, 105; 100, comparison_operator:==; 100, 101; 100, 102; 101, identifier:token; 102, attribute; 102, 103; 102, 104; 103, identifier:OPERATOR; 104, identifier:NOT; 105, block; 105, 106; 105, 119; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 112; 108, subscript; 108, 109; 108, 110; 109, identifier:stack; 110, unary_operator:-; 110, 111; 111, integer:1; 112, call; 112, 113; 112, 114; 113, identifier:IsNot; 114, argument_list; 114, 115; 115, subscript; 115, 116; 115, 117; 116, identifier:stack; 117, unary_operator:-; 117, 118; 118, integer:1; 119, continue_statement; 120, if_statement; 120, 121; 120, 127; 121, comparison_operator:<; 121, 122; 121, 126; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:stack; 126, integer:2; 127, block; 127, 128; 128, raise_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:RuntimeError; 131, argument_list; 131, 132; 132, string:'Unable to build a valid expression. Not enough operands available.'; 133, if_statement; 133, 134; 133, 139; 133, 155; 134, comparison_operator:==; 134, 135; 134, 136; 135, identifier:token; 136, attribute; 136, 137; 136, 138; 137, identifier:OPERATOR; 138, identifier:OR; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:matcher; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:hc; 146, identifier:any_of; 147, argument_list; 147, 148; 148, list_splat; 148, 149; 149, subscript; 149, 150; 149, 151; 150, identifier:stack; 151, slice; 151, 152; 151, 154; 152, unary_operator:-; 152, 153; 153, integer:2; 154, colon; 155, else_clause; 155, 156; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:matcher; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:hc; 163, identifier:all_of; 164, argument_list; 164, 165; 165, list_splat; 165, 166; 166, subscript; 166, 167; 166, 168; 167, identifier:stack; 168, slice; 168, 169; 168, 171; 169, unary_operator:-; 169, 170; 170, integer:2; 171, colon; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 180; 174, subscript; 174, 175; 174, 176; 175, identifier:stack; 176, slice; 176, 177; 176, 179; 177, unary_operator:-; 177, 178; 178, integer:2; 179, colon; 180, list:[matcher]; 180, 181; 181, identifier:matcher; 182, else_clause; 182, 183; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:stack; 188, identifier:append; 189, argument_list; 189, 190; 190, identifier:token; 191, if_statement; 191, 192; 191, 198; 192, comparison_operator:!=; 192, 193; 192, 197; 193, call; 193, 194; 193, 195; 194, identifier:len; 195, argument_list; 195, 196; 196, identifier:stack; 197, integer:1; 198, block; 198, 199; 199, raise_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:RuntimeError; 202, argument_list; 202, 203; 203, string:'Unable to build a valid expression. The RPN stack should have just one item.'; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:matcher; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:stack; 210, identifier:pop; 211, argument_list; 212, if_statement; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:description; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:matcher; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:hc; 223, identifier:described_as; 224, argument_list; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:description; 228, identifier:matcher; 229, return_statement; 229, 230; 230, identifier:matcher | def evaluate(self):
ops = []
rpn = []
for token in self.expr:
if isinstance(token, int):
while len(ops) and token <= ops[-1]:
rpn.append(ops.pop())
ops.append(token)
else:
rpn.append(token)
while len(ops):
rpn.append(ops.pop())
stack = []
for token in rpn:
if isinstance(token, int):
if token == OPERATOR.NOT:
stack[-1] = IsNot(stack[-1])
continue
if len(stack) < 2:
raise RuntimeError('Unable to build a valid expression. Not enough operands available.')
if token == OPERATOR.OR:
matcher = hc.any_of(*stack[-2:])
else:
matcher = hc.all_of(*stack[-2:])
stack[-2:] = [matcher]
else:
stack.append(token)
if len(stack) != 1:
raise RuntimeError('Unable to build a valid expression. The RPN stack should have just one item.')
matcher = stack.pop()
if self.description:
matcher = hc.described_as(self.description, matcher)
return matcher |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_ensure_patient_group_is_ok; 3, parameters; 3, 4; 3, 5; 4, identifier:patient_object; 5, default_parameter; 5, 6; 5, 7; 6, identifier:patient_name; 7, None; 8, block; 8, 9; 8, 16; 8, 29; 8, 36; 8, 70; 9, import_from_statement; 9, 10; 9, 14; 10, dotted_name; 10, 11; 10, 12; 10, 13; 11, identifier:protect; 12, identifier:addons; 13, identifier:common; 14, dotted_name; 14, 15; 15, identifier:TCGAToGTEx; 16, assert_statement; 16, 17; 16, 24; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:patient_object; 21, tuple; 21, 22; 21, 23; 22, identifier:set; 23, identifier:dict; 24, binary_operator:%; 24, 25; 24, 26; 25, string:'%s,%s'; 26, tuple; 26, 27; 26, 28; 27, identifier:patient_object; 28, identifier:patient_name; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:test_set; 32, call; 32, 33; 32, 34; 33, identifier:set; 34, argument_list; 34, 35; 35, identifier:patient_object; 36, if_statement; 36, 37; 36, 40; 36, 51; 37, comparison_operator:not; 37, 38; 37, 39; 38, string:'tumor_type'; 39, identifier:patient_object; 40, block; 40, 41; 41, raise_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:ParameterError; 44, argument_list; 44, 45; 45, binary_operator:+; 45, 46; 45, 50; 46, parenthesized_expression; 46, 47; 47, binary_operator:%; 47, 48; 47, 49; 48, string:'The patient entry for sample %s '; 49, identifier:patient_name; 50, string:'does not contain a Tumor type.'; 51, elif_clause; 51, 52; 51, 57; 52, comparison_operator:not; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:patient_object; 55, string:'tumor_type'; 56, identifier:TCGAToGTEx; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:ParameterError; 61, argument_list; 61, 62; 62, binary_operator:+; 62, 63; 62, 67; 63, parenthesized_expression; 63, 64; 64, binary_operator:%; 64, 65; 64, 66; 65, string:'The patient entry for sample %s '; 66, identifier:patient_name; 67, concatenated_string; 67, 68; 67, 69; 68, string:'does contains an invalid Tumor type. Please use one of the '; 69, string:'valid TCGA tumor types.'; 70, if_statement; 70, 71; 70, 80; 70, 82; 71, call; 71, 72; 71, 78; 72, attribute; 72, 73; 72, 77; 73, set; 73, 74; 73, 75; 73, 76; 74, string:'tumor_dna_fastq_1'; 75, string:'normal_dna_fastq_1'; 76, string:'tumor_rna_fastq_1'; 77, identifier:issubset; 78, argument_list; 78, 79; 79, identifier:test_set; 80, block; 80, 81; 81, pass_statement; 82, else_clause; 82, 83; 83, block; 83, 84; 83, 101; 83, 156; 83, 196; 84, if_statement; 84, 85; 84, 88; 85, comparison_operator:not; 85, 86; 85, 87; 86, string:'hla_haplotype_files'; 87, identifier:test_set; 88, block; 88, 89; 89, raise_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:ParameterError; 92, argument_list; 92, 93; 93, binary_operator:+; 93, 94; 93, 98; 94, parenthesized_expression; 94, 95; 95, binary_operator:%; 95, 96; 95, 97; 96, string:'The patient entry for sample %s '; 97, identifier:patient_name; 98, concatenated_string; 98, 99; 98, 100; 99, string:'does not contain a hla_haplotype_files entry.\nCannot haplotype '; 100, string:'patient if all the input sequence files are not fastqs.'; 101, if_statement; 101, 102; 101, 142; 102, parenthesized_expression; 102, 103; 103, boolean_operator:and; 103, 104; 103, 134; 104, parenthesized_expression; 104, 105; 105, boolean_operator:or; 105, 106; 105, 120; 106, comparison_operator:==; 106, 107; 106, 118; 107, set_comprehension; 107, 108; 107, 115; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:re; 111, identifier:search; 112, argument_list; 112, 113; 112, 114; 113, string:'tumor_dna_((bam)|(fastq_1)).*'; 114, identifier:x; 115, for_in_clause; 115, 116; 115, 117; 116, identifier:x; 117, identifier:test_set; 118, set; 118, 119; 119, None; 120, comparison_operator:==; 120, 121; 120, 132; 121, set_comprehension; 121, 122; 121, 129; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:re; 125, identifier:search; 126, argument_list; 126, 127; 126, 128; 127, string:'normal_dna_((bam)|(fastq_1)).*'; 128, identifier:x; 129, for_in_clause; 129, 130; 129, 131; 130, identifier:x; 131, identifier:test_set; 132, set; 132, 133; 133, None; 134, parenthesized_expression; 134, 135; 135, boolean_operator:and; 135, 136; 135, 139; 136, comparison_operator:not; 136, 137; 136, 138; 137, string:'mutation_vcf'; 138, identifier:test_set; 139, comparison_operator:not; 139, 140; 139, 141; 140, string:'fusion_bedpe'; 141, identifier:test_set; 142, block; 142, 143; 143, raise_statement; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:ParameterError; 146, argument_list; 146, 147; 147, binary_operator:+; 147, 148; 147, 152; 148, parenthesized_expression; 148, 149; 149, binary_operator:%; 149, 150; 149, 151; 150, string:'The patient entry for sample %s '; 151, identifier:patient_name; 152, concatenated_string; 152, 153; 152, 154; 152, 155; 153, string:'does not contain a mutation_vcf or fusion_bedpe entry. If both '; 154, string:'tumor and normal DNA sequences (fastqs or bam) are not provided, '; 155, string:'a pre-computed vcf and/or bedpe must be provided.'; 156, if_statement; 156, 157; 156, 171; 157, comparison_operator:==; 157, 158; 157, 169; 158, set_comprehension; 158, 159; 158, 166; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:re; 162, identifier:search; 163, argument_list; 163, 164; 163, 165; 164, string:'tumor_rna_((bam)|(fastq_1)).*'; 165, identifier:x; 166, for_in_clause; 166, 167; 166, 168; 167, identifier:x; 168, identifier:test_set; 169, set; 169, 170; 170, None; 171, block; 171, 172; 172, if_statement; 172, 173; 172, 180; 172, 182; 173, boolean_operator:and; 173, 174; 173, 177; 174, comparison_operator:not; 174, 175; 174, 176; 175, string:'mutation_vcf'; 176, identifier:test_set; 177, comparison_operator:in; 177, 178; 177, 179; 178, string:'fusion_bedpe'; 179, identifier:test_set; 180, block; 180, 181; 181, pass_statement; 182, else_clause; 182, 183; 183, block; 183, 184; 184, raise_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:ParameterError; 187, argument_list; 187, 188; 188, binary_operator:+; 188, 189; 188, 193; 189, parenthesized_expression; 189, 190; 190, binary_operator:%; 190, 191; 190, 192; 191, string:'The patient entry for sample %s '; 192, identifier:patient_name; 193, concatenated_string; 193, 194; 193, 195; 194, string:'does not contain a tumor rna sequence data entry. We require '; 195, string:'either tumor_rna_fastq_1 or tumor_rna_bam.'; 196, if_statement; 196, 197; 196, 204; 197, boolean_operator:and; 197, 198; 197, 201; 198, comparison_operator:in; 198, 199; 198, 200; 199, string:'tumor_rna_bam'; 200, identifier:test_set; 201, comparison_operator:not; 201, 202; 201, 203; 202, string:'tumor_rna_transcriptome_bam'; 203, identifier:test_set; 204, block; 204, 205; 205, if_statement; 205, 206; 205, 209; 206, comparison_operator:not; 206, 207; 206, 208; 207, string:'expression_files'; 208, identifier:test_set; 209, block; 209, 210; 210, raise_statement; 210, 211; 211, call; 211, 212; 211, 213; 212, identifier:ParameterError; 213, argument_list; 213, 214; 214, parenthesized_expression; 214, 215; 215, binary_operator:+; 215, 216; 215, 219; 216, binary_operator:%; 216, 217; 216, 218; 217, string:'The patient entry for sample %s '; 218, identifier:patient_name; 219, concatenated_string; 219, 220; 219, 221; 219, 222; 219, 223; 219, 224; 220, string:'was provided a tumor rna bam with sequences mapped to the '; 221, string:'genome but was not provided a matching rna bam for the '; 222, string:'transcriptome or a tar containing expression values. '; 223, string:'We require either a matching transcriptome bam to estimate'; 224, string:'expression, or the precomputed expression values.' | def _ensure_patient_group_is_ok(patient_object, patient_name=None):
from protect.addons.common import TCGAToGTEx
assert isinstance(patient_object, (set, dict)), '%s,%s' % (patient_object, patient_name)
test_set = set(patient_object)
if 'tumor_type' not in patient_object:
raise ParameterError(('The patient entry for sample %s ' % patient_name) +
'does not contain a Tumor type.')
elif patient_object['tumor_type'] not in TCGAToGTEx:
raise ParameterError(('The patient entry for sample %s ' % patient_name) +
'does contains an invalid Tumor type. Please use one of the '
'valid TCGA tumor types.')
if {'tumor_dna_fastq_1', 'normal_dna_fastq_1', 'tumor_rna_fastq_1'}.issubset(test_set):
pass
else:
if 'hla_haplotype_files' not in test_set:
raise ParameterError(('The patient entry for sample %s ' % patient_name) +
'does not contain a hla_haplotype_files entry.\nCannot haplotype '
'patient if all the input sequence files are not fastqs.')
if (({re.search('tumor_dna_((bam)|(fastq_1)).*', x) for x in test_set} == {None} or
{re.search('normal_dna_((bam)|(fastq_1)).*', x) for x in test_set} == {None}) and
('mutation_vcf' not in test_set and 'fusion_bedpe' not in test_set)):
raise ParameterError(('The patient entry for sample %s ' % patient_name) +
'does not contain a mutation_vcf or fusion_bedpe entry. If both '
'tumor and normal DNA sequences (fastqs or bam) are not provided, '
'a pre-computed vcf and/or bedpe must be provided.')
if {re.search('tumor_rna_((bam)|(fastq_1)).*', x) for x in test_set} == {None}:
if 'mutation_vcf' not in test_set and 'fusion_bedpe' in test_set:
pass
else:
raise ParameterError(('The patient entry for sample %s ' % patient_name) +
'does not contain a tumor rna sequence data entry. We require '
'either tumor_rna_fastq_1 or tumor_rna_bam.')
if 'tumor_rna_bam' in test_set and 'tumor_rna_transcriptome_bam' not in test_set:
if 'expression_files' not in test_set:
raise ParameterError(('The patient entry for sample %s ' % patient_name +
'was provided a tumor rna bam with sequences mapped to the '
'genome but was not provided a matching rna bam for the '
'transcriptome or a tar containing expression values. '
'We require either a matching transcriptome bam to estimate'
'expression, or the precomputed expression values.')) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_add_default_entries; 3, parameters; 3, 4; 3, 5; 4, identifier:input_dict; 5, identifier:defaults_dict; 6, block; 6, 7; 6, 93; 7, for_statement; 7, 8; 7, 11; 7, 16; 8, pattern_list; 8, 9; 8, 10; 9, identifier:key; 10, identifier:value; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:defaults_dict; 14, identifier:iteritems; 15, argument_list; 16, block; 16, 17; 16, 28; 17, if_statement; 17, 18; 17, 21; 18, comparison_operator:==; 18, 19; 18, 20; 19, identifier:key; 20, string:'patients'; 21, block; 21, 22; 21, 27; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:print; 25, argument_list; 25, 26; 26, string:'Cannot default `patients`.'; 27, continue_statement; 28, if_statement; 28, 29; 28, 34; 28, 74; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 33; 32, identifier:value; 33, identifier:dict; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 45; 35, 52; 36, boolean_operator:or; 36, 37; 36, 40; 37, comparison_operator:not; 37, 38; 37, 39; 38, identifier:key; 39, identifier:input_dict; 40, comparison_operator:is; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:input_dict; 43, identifier:key; 44, None; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:input_dict; 50, identifier:key; 51, identifier:value; 52, else_clause; 52, 53; 53, block; 53, 54; 53, 68; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:r; 57, call; 57, 58; 57, 59; 58, identifier:_add_default_entries; 59, argument_list; 59, 60; 59, 67; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:input_dict; 63, identifier:get; 64, argument_list; 64, 65; 64, 66; 65, identifier:key; 66, dictionary; 67, identifier:value; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:input_dict; 72, identifier:key; 73, identifier:r; 74, else_clause; 74, 75; 75, block; 75, 76; 76, if_statement; 76, 77; 76, 86; 77, boolean_operator:or; 77, 78; 77, 81; 78, comparison_operator:not; 78, 79; 78, 80; 79, identifier:key; 80, identifier:input_dict; 81, comparison_operator:is; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:input_dict; 84, identifier:key; 85, None; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:input_dict; 91, identifier:key; 92, identifier:value; 93, return_statement; 93, 94; 94, identifier:input_dict | def _add_default_entries(input_dict, defaults_dict):
for key, value in defaults_dict.iteritems():
if key == 'patients':
print('Cannot default `patients`.')
continue
if isinstance(value, dict):
if key not in input_dict or input_dict[key] is None:
input_dict[key] = value
else:
r = _add_default_entries(input_dict.get(key, {}), value)
input_dict[key] = r
else:
if key not in input_dict or input_dict[key] is None:
input_dict[key] = value
return input_dict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:main; 3, parameters; 4, block; 4, 5; 4, 24; 4, 35; 4, 56; 4, 78; 4, 105; 4, 115; 4, 250; 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; 12, 13; 12, 16; 12, 19; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:prog; 15, string:'ProTECT'; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:description; 18, string:'Prediction of T-Cell Epitopes for Cancer Therapy'; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:epilog; 21, concatenated_string; 21, 22; 21, 23; 22, string:'Contact Arjun Rao (aarao@ucsc.edu) if you encounter '; 23, string:'any problems while running ProTECT'; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:inputs; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:parser; 30, identifier:add_mutually_exclusive_group; 31, argument_list; 31, 32; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:required; 34, True; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:inputs; 39, identifier:add_argument; 40, argument_list; 40, 41; 40, 42; 40, 45; 40, 50; 40, 53; 41, string:'--config_file'; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:dest; 44, string:'config_file'; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:help; 47, concatenated_string; 47, 48; 47, 49; 48, string:'Config file to be used in the '; 49, string:'run.'; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:type; 52, identifier:str; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:default; 55, None; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:inputs; 60, identifier:add_argument; 61, argument_list; 61, 62; 61, 63; 61, 66; 61, 72; 61, 75; 62, string:'--generate_config'; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:dest; 65, string:'generate_config'; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:help; 68, concatenated_string; 68, 69; 68, 70; 68, 71; 69, string:'Generate a config file '; 70, string:'in the current directory that is pre-filled with references and flags for '; 71, string:'an hg19 run.'; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:action; 74, string:'store_true'; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:default; 77, False; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:parser; 82, identifier:add_argument; 83, argument_list; 83, 84; 83, 85; 83, 88; 83, 96; 83, 99; 83, 102; 84, string:'--max-cores-per-job'; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:dest; 87, string:'max_cores'; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:help; 90, concatenated_string; 90, 91; 90, 92; 90, 93; 90, 94; 90, 95; 91, string:'Maximum cores to use per '; 92, string:'job. Aligners and Haplotypers ask for cores dependent on the machine that '; 93, string:'the launchpad gets assigned to -- In a heterogeneous cluster, this can '; 94, string:'lead to problems. This value should be set to the number of cpus on the '; 95, string:'smallest node in a cluster.'; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:type; 98, identifier:int; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:required; 101, False; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:default; 104, None; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, pattern_list; 107, 108; 107, 109; 108, identifier:params; 109, identifier:others; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:parser; 113, identifier:parse_known_args; 114, argument_list; 115, if_statement; 115, 116; 115, 119; 115, 124; 116, attribute; 116, 117; 116, 118; 117, identifier:params; 118, identifier:generate_config; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:generate_config_file; 123, argument_list; 124, else_clause; 124, 125; 125, block; 125, 126; 125, 135; 125, 143; 125, 158; 125, 225; 125, 240; 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:Job; 131, identifier:Runner; 132, identifier:addToilOptions; 133, argument_list; 133, 134; 134, identifier:parser; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:params; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:parser; 141, identifier:parse_args; 142, argument_list; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:params; 147, identifier:config_file; 148, call; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:os; 152, identifier:path; 153, identifier:abspath; 154, argument_list; 154, 155; 155, attribute; 155, 156; 155, 157; 156, identifier:params; 157, identifier:config_file; 158, if_statement; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:params; 161, identifier:maxCores; 162, block; 162, 163; 163, if_statement; 163, 164; 163, 168; 163, 180; 164, not_operator; 164, 165; 165, attribute; 165, 166; 165, 167; 166, identifier:params; 167, identifier:max_cores; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:params; 173, identifier:max_cores; 174, call; 174, 175; 174, 176; 175, identifier:int; 176, argument_list; 176, 177; 177, attribute; 177, 178; 177, 179; 178, identifier:params; 179, identifier:maxCores; 180, else_clause; 180, 181; 181, block; 181, 182; 182, if_statement; 182, 183; 182, 193; 183, comparison_operator:>; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:params; 186, identifier:max_cores; 187, call; 187, 188; 187, 189; 188, identifier:int; 189, argument_list; 189, 190; 190, attribute; 190, 191; 190, 192; 191, identifier:params; 192, identifier:maxCores; 193, block; 193, 194; 193, 214; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:print; 197, argument_list; 197, 198; 197, 209; 198, binary_operator:%; 198, 199; 198, 202; 199, concatenated_string; 199, 200; 199, 201; 200, string:"The value provided to max-cores-per-job (%s) was greater than that "; 201, string:"provided to maxCores (%s). Setting max-cores-per-job = maxCores."; 202, tuple; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:params; 205, identifier:max_cores; 206, attribute; 206, 207; 206, 208; 207, identifier:params; 208, identifier:maxCores; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:file; 211, attribute; 211, 212; 211, 213; 212, identifier:sys; 213, identifier:stderr; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:params; 218, identifier:max_cores; 219, call; 219, 220; 219, 221; 220, identifier:int; 221, argument_list; 221, 222; 222, attribute; 222, 223; 222, 224; 223, identifier:params; 224, identifier:maxCores; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:start; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:Job; 231, identifier:wrapJobFn; 232, argument_list; 232, 233; 232, 234; 232, 237; 233, identifier:parse_config_file; 234, attribute; 234, 235; 234, 236; 235, identifier:params; 236, identifier:config_file; 237, attribute; 237, 238; 237, 239; 238, identifier:params; 239, identifier:max_cores; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:Job; 245, identifier:Runner; 246, identifier:startToil; 247, argument_list; 247, 248; 247, 249; 248, identifier:start; 249, identifier:params; 250, return_statement; 250, 251; 251, None | def main():
parser = argparse.ArgumentParser(prog='ProTECT',
description='Prediction of T-Cell Epitopes for Cancer Therapy',
epilog='Contact Arjun Rao (aarao@ucsc.edu) if you encounter '
'any problems while running ProTECT')
inputs = parser.add_mutually_exclusive_group(required=True)
inputs.add_argument('--config_file', dest='config_file', help='Config file to be used in the '
'run.', type=str, default=None)
inputs.add_argument('--generate_config', dest='generate_config', help='Generate a config file '
'in the current directory that is pre-filled with references and flags for '
'an hg19 run.', action='store_true', default=False)
parser.add_argument('--max-cores-per-job', dest='max_cores', help='Maximum cores to use per '
'job. Aligners and Haplotypers ask for cores dependent on the machine that '
'the launchpad gets assigned to -- In a heterogeneous cluster, this can '
'lead to problems. This value should be set to the number of cpus on the '
'smallest node in a cluster.',
type=int, required=False, default=None)
params, others = parser.parse_known_args()
if params.generate_config:
generate_config_file()
else:
Job.Runner.addToilOptions(parser)
params = parser.parse_args()
params.config_file = os.path.abspath(params.config_file)
if params.maxCores:
if not params.max_cores:
params.max_cores = int(params.maxCores)
else:
if params.max_cores > int(params.maxCores):
print("The value provided to max-cores-per-job (%s) was greater than that "
"provided to maxCores (%s). Setting max-cores-per-job = maxCores." %
(params.max_cores, params.maxCores), file=sys.stderr)
params.max_cores = int(params.maxCores)
start = Job.wrapJobFn(parse_config_file, params.config_file, params.max_cores)
Job.Runner.startToil(start, params)
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:align_dna; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:job; 5, identifier:fastqs; 6, identifier:sample_type; 7, identifier:univ_options; 8, identifier:bwa_options; 9, block; 9, 10; 9, 43; 9, 78; 9, 113; 9, 148; 9, 183; 9, 221; 9, 228; 9, 235; 9, 242; 9, 249; 9, 256; 9, 263; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:bwa; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:job; 16, identifier:wrapJobFn; 17, argument_list; 17, 18; 17, 19; 17, 20; 17, 21; 17, 22; 17, 23; 17, 33; 17, 38; 18, identifier:run_bwa; 19, identifier:fastqs; 20, identifier:sample_type; 21, identifier:univ_options; 22, identifier:bwa_options; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:disk; 25, call; 25, 26; 25, 27; 26, identifier:PromisedRequirement; 27, argument_list; 27, 28; 27, 29; 27, 30; 28, identifier:bwa_disk; 29, identifier:fastqs; 30, subscript; 30, 31; 30, 32; 31, identifier:bwa_options; 32, string:'index'; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:memory; 35, subscript; 35, 36; 35, 37; 36, identifier:univ_options; 37, string:'java_Xmx'; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:cores; 40, subscript; 40, 41; 40, 42; 41, identifier:bwa_options; 42, string:'n'; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:sam2bam; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:job; 49, identifier:wrapJobFn; 50, argument_list; 50, 51; 50, 52; 50, 57; 50, 58; 50, 59; 50, 62; 50, 73; 51, identifier:bam_conversion; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:bwa; 55, identifier:rv; 56, argument_list; 57, identifier:sample_type; 58, identifier:univ_options; 59, subscript; 59, 60; 59, 61; 60, identifier:bwa_options; 61, string:'samtools'; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:disk; 64, call; 64, 65; 64, 66; 65, identifier:PromisedRequirement; 66, argument_list; 66, 67; 66, 68; 67, identifier:sam2bam_disk; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:bwa; 71, identifier:rv; 72, argument_list; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:memory; 75, subscript; 75, 76; 75, 77; 76, identifier:univ_options; 77, string:'java_Xmx'; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:reheader; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:job; 84, identifier:wrapJobFn; 85, argument_list; 85, 86; 85, 87; 85, 92; 85, 93; 85, 94; 85, 97; 85, 108; 86, identifier:fix_bam_header; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:sam2bam; 90, identifier:rv; 91, argument_list; 92, identifier:sample_type; 93, identifier:univ_options; 94, subscript; 94, 95; 94, 96; 95, identifier:bwa_options; 96, string:'samtools'; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:disk; 99, call; 99, 100; 99, 101; 100, identifier:PromisedRequirement; 101, argument_list; 101, 102; 101, 103; 102, identifier:sam2bam_disk; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:bwa; 106, identifier:rv; 107, argument_list; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:memory; 110, subscript; 110, 111; 110, 112; 111, identifier:univ_options; 112, string:'java_Xmx'; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:regroup; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:job; 119, identifier:wrapJobFn; 120, argument_list; 120, 121; 120, 122; 120, 127; 120, 128; 120, 129; 120, 132; 120, 143; 121, identifier:add_readgroups; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:reheader; 125, identifier:rv; 126, argument_list; 127, identifier:sample_type; 128, identifier:univ_options; 129, subscript; 129, 130; 129, 131; 130, identifier:bwa_options; 131, string:'picard'; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:disk; 134, call; 134, 135; 134, 136; 135, identifier:PromisedRequirement; 136, argument_list; 136, 137; 136, 138; 137, identifier:regroup_disk; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:reheader; 141, identifier:rv; 142, argument_list; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:memory; 145, subscript; 145, 146; 145, 147; 146, identifier:univ_options; 147, string:'java_Xmx'; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:mkdup; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:job; 154, identifier:wrapJobFn; 155, argument_list; 155, 156; 155, 157; 155, 162; 155, 163; 155, 164; 155, 167; 155, 178; 156, identifier:mark_duplicates; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:regroup; 160, identifier:rv; 161, argument_list; 162, identifier:sample_type; 163, identifier:univ_options; 164, subscript; 164, 165; 164, 166; 165, identifier:bwa_options; 166, string:'picard'; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:disk; 169, call; 169, 170; 169, 171; 170, identifier:PromisedRequirement; 171, argument_list; 171, 172; 171, 173; 172, identifier:mkdup_disk; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:regroup; 176, identifier:rv; 177, argument_list; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:memory; 180, subscript; 180, 181; 180, 182; 181, identifier:univ_options; 182, string:'java_Xmx'; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:index; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:job; 189, identifier:wrapJobFn; 190, argument_list; 190, 191; 190, 192; 190, 197; 190, 198; 190, 199; 190, 202; 190, 205; 190, 216; 191, identifier:index_bamfile; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:mkdup; 195, identifier:rv; 196, argument_list; 197, identifier:sample_type; 198, identifier:univ_options; 199, subscript; 199, 200; 199, 201; 200, identifier:bwa_options; 201, string:'samtools'; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:sample_info; 204, string:'fix_pg_sorted'; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:disk; 207, call; 207, 208; 207, 209; 208, identifier:PromisedRequirement; 209, argument_list; 209, 210; 209, 211; 210, identifier:index_disk; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:mkdup; 214, identifier:rv; 215, argument_list; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:memory; 218, subscript; 218, 219; 218, 220; 219, identifier:univ_options; 220, string:'java_Xmx'; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:job; 225, identifier:addChild; 226, argument_list; 226, 227; 227, identifier:bwa; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:bwa; 232, identifier:addChild; 233, argument_list; 233, 234; 234, identifier:sam2bam; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:sam2bam; 239, identifier:addChild; 240, argument_list; 240, 241; 241, identifier:reheader; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:reheader; 246, identifier:addChild; 247, argument_list; 247, 248; 248, identifier:regroup; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:regroup; 253, identifier:addChild; 254, argument_list; 254, 255; 255, identifier:mkdup; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:mkdup; 260, identifier:addChild; 261, argument_list; 261, 262; 262, identifier:index; 263, return_statement; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:index; 267, identifier:rv; 268, argument_list | def align_dna(job, fastqs, sample_type, univ_options, bwa_options):
bwa = job.wrapJobFn(run_bwa, fastqs, sample_type, univ_options, bwa_options,
disk=PromisedRequirement(bwa_disk, fastqs, bwa_options['index']),
memory=univ_options['java_Xmx'],
cores=bwa_options['n'])
sam2bam = job.wrapJobFn(bam_conversion, bwa.rv(), sample_type, univ_options,
bwa_options['samtools'],
disk=PromisedRequirement(sam2bam_disk, bwa.rv()),
memory=univ_options['java_Xmx'])
reheader = job.wrapJobFn(fix_bam_header, sam2bam.rv(), sample_type, univ_options,
bwa_options['samtools'],
disk=PromisedRequirement(sam2bam_disk, bwa.rv()),
memory=univ_options['java_Xmx'])
regroup = job.wrapJobFn(add_readgroups, reheader.rv(), sample_type, univ_options,
bwa_options['picard'],
disk=PromisedRequirement(regroup_disk, reheader.rv()),
memory=univ_options['java_Xmx'])
mkdup = job.wrapJobFn(mark_duplicates, regroup.rv(), sample_type, univ_options,
bwa_options['picard'],
disk=PromisedRequirement(mkdup_disk, regroup.rv()),
memory=univ_options['java_Xmx'])
index = job.wrapJobFn(index_bamfile, mkdup.rv(), sample_type, univ_options,
bwa_options['samtools'], sample_info='fix_pg_sorted',
disk=PromisedRequirement(index_disk, mkdup.rv()),
memory=univ_options['java_Xmx'])
job.addChild(bwa)
bwa.addChild(sam2bam)
sam2bam.addChild(reheader)
reheader.addChild(regroup)
regroup.addChild(mkdup)
mkdup.addChild(index)
return index.rv() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:create; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:entry; 6, block; 6, 7; 6, 73; 6, 80; 6, 104; 6, 119; 7, try_statement; 7, 8; 7, 16; 7, 40; 8, block; 8, 9; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:module; 12, call; 12, 13; 12, 14; 13, identifier:import_module; 14, argument_list; 14, 15; 15, identifier:entry; 16, except_clause; 16, 17; 16, 18; 17, identifier:ImportError; 18, block; 18, 19; 18, 23; 18, 35; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:module; 22, None; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 29; 25, pattern_list; 25, 26; 25, 27; 25, 28; 26, identifier:mod_path; 27, identifier:_; 28, identifier:cls_name; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:entry; 32, identifier:rpartition; 33, argument_list; 33, 34; 34, string:'.'; 35, if_statement; 35, 36; 35, 38; 36, not_operator; 36, 37; 37, identifier:mod_path; 38, block; 38, 39; 39, raise_statement; 40, else_clause; 40, 41; 41, block; 41, 42; 42, try_statement; 42, 43; 42, 50; 42, 59; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:entry; 47, attribute; 47, 48; 47, 49; 48, identifier:module; 49, identifier:default_bot; 50, except_clause; 50, 51; 50, 52; 51, identifier:AttributeError; 52, block; 52, 53; 53, return_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:cls; 56, argument_list; 56, 57; 56, 58; 57, string:f'{entry}.Bot'; 58, identifier:module; 59, else_clause; 59, 60; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 67; 63, pattern_list; 63, 64; 63, 65; 63, 66; 64, identifier:mod_path; 65, identifier:_; 66, identifier:cls_name; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:entry; 70, identifier:rpartition; 71, argument_list; 71, 72; 72, string:'.'; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:mod; 76, call; 76, 77; 76, 78; 77, identifier:import_module; 78, argument_list; 78, 79; 79, identifier:mod_path; 80, try_statement; 80, 81; 80, 90; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:bot_cls; 85, call; 85, 86; 85, 87; 86, identifier:getattr; 87, argument_list; 87, 88; 87, 89; 88, identifier:mod; 89, identifier:cls_name; 90, except_clause; 90, 91; 90, 92; 91, identifier:AttributeError; 92, block; 92, 93; 92, 103; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:module; 96, None; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:import_module; 101, argument_list; 101, 102; 102, identifier:entry; 103, raise_statement; 104, if_statement; 104, 105; 104, 111; 105, not_operator; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:issubclass; 108, argument_list; 108, 109; 108, 110; 109, identifier:bot_cls; 110, identifier:Bot; 111, block; 111, 112; 112, raise_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:ImproperlyConfigured; 115, argument_list; 115, 116; 116, binary_operator:%; 116, 117; 116, 118; 117, string:"'%s' isn't a subclass of Bot."; 118, identifier:entry; 119, return_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:cls; 122, argument_list; 122, 123; 122, 124; 122, 125; 123, identifier:entry; 124, identifier:mod; 125, attribute; 125, 126; 125, 127; 126, identifier:bot_cls; 127, identifier:label | def create(cls, entry):
try:
module = import_module(entry)
except ImportError:
module = None
mod_path, _, cls_name = entry.rpartition('.')
if not mod_path:
raise
else:
try:
entry = module.default_bot
except AttributeError:
return cls(f'{entry}.Bot', module)
else:
mod_path, _, cls_name = entry.rpartition('.')
mod = import_module(mod_path)
try:
bot_cls = getattr(mod, cls_name)
except AttributeError:
if module is None:
import_module(entry)
raise
if not issubclass(bot_cls, Bot):
raise ImproperlyConfigured(
"'%s' isn't a subclass of Bot." % entry)
return cls(entry, mod, bot_cls.label) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:populate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:installed_bots; 7, None; 8, block; 8, 9; 8, 15; 9, if_statement; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:ready; 13, block; 13, 14; 14, return_statement; 15, with_statement; 15, 16; 15, 21; 16, with_clause; 16, 17; 17, with_item; 17, 18; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_lock; 21, block; 21, 22; 21, 28; 21, 38; 21, 44; 21, 121; 21, 139; 21, 157; 21, 174; 21, 180; 21, 196; 21, 202; 22, if_statement; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:ready; 26, block; 26, 27; 27, return_statement; 28, if_statement; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:loading; 32, block; 32, 33; 33, raise_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:RuntimeError; 36, argument_list; 36, 37; 37, string:"populate() isn't re-entrant"; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:loading; 43, True; 44, for_statement; 44, 45; 44, 46; 44, 49; 45, identifier:entry; 46, boolean_operator:or; 46, 47; 46, 48; 47, identifier:installed_bots; 48, dictionary; 49, block; 49, 50; 49, 76; 49, 85; 49, 105; 49, 115; 50, if_statement; 50, 51; 50, 56; 51, call; 51, 52; 51, 53; 52, identifier:isinstance; 53, argument_list; 53, 54; 53, 55; 54, identifier:entry; 55, identifier:Bot; 56, block; 56, 57; 56, 61; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:cls; 60, identifier:entry; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:entry; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, string:'.'; 67, identifier:join; 68, argument_list; 68, 69; 69, list:[cls.__module__, cls.__name__]; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:cls; 72, identifier:__module__; 73, attribute; 73, 74; 73, 75; 74, identifier:cls; 75, identifier:__name__; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:bot_reg; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:BotRegistry; 82, identifier:create; 83, argument_list; 83, 84; 84, identifier:entry; 85, if_statement; 85, 86; 85, 93; 86, comparison_operator:in; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:bot_reg; 89, identifier:label; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:bots; 93, block; 93, 94; 94, raise_statement; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:ImproperlyConfigured; 97, argument_list; 97, 98; 98, binary_operator:%; 98, 99; 98, 102; 99, concatenated_string; 99, 100; 99, 101; 100, string:"Bot labels aren't unique, "; 101, string:"duplicates: %s"; 102, attribute; 102, 103; 102, 104; 103, identifier:bot_reg; 104, identifier:label; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 114; 107, subscript; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:bots; 111, attribute; 111, 112; 111, 113; 112, identifier:bot_reg; 113, identifier:label; 114, identifier:bot_reg; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:bot_reg; 119, identifier:bots; 120, identifier:self; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:counts; 124, call; 124, 125; 124, 126; 125, identifier:Counter; 126, generator_expression; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:bot_reg; 129, identifier:name; 130, for_in_clause; 130, 131; 130, 132; 131, identifier:bot_reg; 132, call; 132, 133; 132, 138; 133, attribute; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:bots; 137, identifier:values; 138, argument_list; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:duplicates; 142, list_comprehension; 142, 143; 142, 144; 142, 153; 143, identifier:name; 144, for_in_clause; 144, 145; 144, 148; 145, pattern_list; 145, 146; 145, 147; 146, identifier:name; 147, identifier:count; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:counts; 151, identifier:most_common; 152, argument_list; 153, if_clause; 153, 154; 154, comparison_operator:>; 154, 155; 154, 156; 155, identifier:count; 156, integer:1; 157, if_statement; 157, 158; 157, 159; 158, identifier:duplicates; 159, block; 159, 160; 160, raise_statement; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:ImproperlyConfigured; 163, argument_list; 163, 164; 164, binary_operator:%; 164, 165; 164, 168; 165, concatenated_string; 165, 166; 165, 167; 166, string:"Bot names aren't unique, "; 167, string:"duplicates: %s"; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, string:", "; 171, identifier:join; 172, argument_list; 172, 173; 173, identifier:duplicates; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:bots_ready; 179, True; 180, for_statement; 180, 181; 180, 182; 180, 189; 181, identifier:bot; 182, call; 182, 183; 182, 188; 183, attribute; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:bots; 187, identifier:values; 188, argument_list; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:bot; 194, identifier:import_configs; 195, argument_list; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:configs_ready; 201, True; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:ready; 207, True | def populate(self, installed_bots=None):
if self.ready:
return
with self._lock:
if self.ready:
return
if self.loading:
raise RuntimeError("populate() isn't re-entrant")
self.loading = True
for entry in installed_bots or {}:
if isinstance(entry, Bot):
cls = entry
entry = '.'.join([cls.__module__, cls.__name__])
bot_reg = BotRegistry.create(entry)
if bot_reg.label in self.bots:
raise ImproperlyConfigured(
"Bot labels aren't unique, "
"duplicates: %s" % bot_reg.label)
self.bots[bot_reg.label] = bot_reg
bot_reg.bots = self
counts = Counter(
bot_reg.name for bot_reg in self.bots.values())
duplicates = [
name for name, count in counts.most_common() if count > 1]
if duplicates:
raise ImproperlyConfigured(
"Bot names aren't unique, "
"duplicates: %s" % ", ".join(duplicates))
self.bots_ready = True
for bot in self.bots.values():
bot.import_configs()
self.configs_ready = True
self.ready = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:get_initkwargs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 17; 4, identifier:cls; 5, identifier:form_list; 6, default_parameter; 6, 7; 6, 8; 7, identifier:initial_dict; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:instance_dict; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:condition_dict; 14, None; 15, list_splat_pattern; 15, 16; 16, identifier:args; 17, dictionary_splat_pattern; 17, 18; 18, identifier:kwargs; 19, block; 19, 20; 19, 42; 19, 48; 19, 56; 19, 98; 19, 150; 19, 156; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:kwargs; 24, identifier:update; 25, argument_list; 25, 26; 26, dictionary; 26, 27; 26, 32; 26, 37; 27, pair; 27, 28; 27, 29; 28, string:'initial_dict'; 29, boolean_operator:or; 29, 30; 29, 31; 30, identifier:initial_dict; 31, dictionary; 32, pair; 32, 33; 32, 34; 33, string:'instance_dict'; 34, boolean_operator:or; 34, 35; 34, 36; 35, identifier:instance_dict; 36, dictionary; 37, pair; 37, 38; 37, 39; 38, string:'condition_dict'; 39, boolean_operator:or; 39, 40; 39, 41; 40, identifier:condition_dict; 41, dictionary; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:init_form_list; 45, call; 45, 46; 45, 47; 46, identifier:SortedDict; 47, argument_list; 48, assert_statement; 48, 49; 48, 55; 49, comparison_operator:>; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:form_list; 54, integer:0; 55, string:'at least one form is needed'; 56, for_statement; 56, 57; 56, 60; 56, 64; 57, pattern_list; 57, 58; 57, 59; 58, identifier:i; 59, identifier:form; 60, call; 60, 61; 60, 62; 61, identifier:enumerate; 62, argument_list; 62, 63; 63, identifier:form_list; 64, block; 64, 65; 65, if_statement; 65, 66; 65, 73; 65, 87; 66, call; 66, 67; 66, 68; 67, identifier:isinstance; 68, argument_list; 68, 69; 68, 70; 69, identifier:form; 70, tuple; 70, 71; 70, 72; 71, identifier:list; 72, identifier:tuple; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 84; 76, subscript; 76, 77; 76, 78; 77, identifier:init_form_list; 78, call; 78, 79; 78, 80; 79, identifier:unicode; 80, argument_list; 80, 81; 81, subscript; 81, 82; 81, 83; 82, identifier:form; 83, integer:0; 84, subscript; 84, 85; 84, 86; 85, identifier:form; 86, integer:1; 87, else_clause; 87, 88; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 97; 91, subscript; 91, 92; 91, 93; 92, identifier:init_form_list; 93, call; 93, 94; 93, 95; 94, identifier:unicode; 95, argument_list; 95, 96; 96, identifier:i; 97, identifier:form; 98, for_statement; 98, 99; 98, 100; 98, 105; 99, identifier:form; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:init_form_list; 103, identifier:itervalues; 104, argument_list; 105, block; 105, 106; 105, 121; 106, if_statement; 106, 107; 106, 114; 107, call; 107, 108; 107, 109; 108, identifier:issubclass; 109, argument_list; 109, 110; 109, 111; 110, identifier:form; 111, attribute; 111, 112; 111, 113; 112, identifier:formsets; 113, identifier:BaseFormSet; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:form; 118, attribute; 118, 119; 118, 120; 119, identifier:form; 120, identifier:form; 121, for_statement; 121, 122; 121, 123; 121, 130; 122, identifier:field; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:form; 127, identifier:base_fields; 128, identifier:itervalues; 129, argument_list; 130, block; 130, 131; 131, if_statement; 131, 132; 131, 147; 132, parenthesized_expression; 132, 133; 133, boolean_operator:and; 133, 134; 133, 141; 134, call; 134, 135; 134, 136; 135, identifier:isinstance; 136, argument_list; 136, 137; 136, 138; 137, identifier:field; 138, attribute; 138, 139; 138, 140; 139, identifier:forms; 140, identifier:FileField; 141, not_operator; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:hasattr; 144, argument_list; 144, 145; 144, 146; 145, identifier:cls; 146, string:'file_storage'; 147, block; 147, 148; 148, raise_statement; 148, 149; 149, identifier:NoFileStorageConfigured; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:kwargs; 154, string:'form_list'; 155, identifier:init_form_list; 156, return_statement; 156, 157; 157, identifier:kwargs | def get_initkwargs(cls, form_list, initial_dict=None,
instance_dict=None, condition_dict=None, *args, **kwargs):
kwargs.update({
'initial_dict': initial_dict or {},
'instance_dict': instance_dict or {},
'condition_dict': condition_dict or {},
})
init_form_list = SortedDict()
assert len(form_list) > 0, 'at least one form is needed'
for i, form in enumerate(form_list):
if isinstance(form, (list, tuple)):
init_form_list[unicode(form[0])] = form[1]
else:
init_form_list[unicode(i)] = form
for form in init_form_list.itervalues():
if issubclass(form, formsets.BaseFormSet):
form = form.form
for field in form.base_fields.itervalues():
if (isinstance(field, forms.FileField) and
not hasattr(cls, 'file_storage')):
raise NoFileStorageConfigured
kwargs['form_list'] = init_form_list
return kwargs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:post; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 24; 9, 86; 9, 102; 9, 115; 9, 123; 9, 149; 9, 171; 9, 247; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:wizard_prev_step; 13, call; 13, 14; 13, 21; 14, attribute; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:request; 19, identifier:POST; 20, identifier:get; 21, argument_list; 21, 22; 21, 23; 22, string:'wizard_prev_step'; 23, None; 24, if_statement; 24, 25; 24, 34; 25, boolean_operator:and; 25, 26; 25, 27; 26, identifier:wizard_prev_step; 27, comparison_operator:in; 27, 28; 27, 29; 28, identifier:wizard_prev_step; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:get_form_list; 33, argument_list; 34, block; 34, 35; 34, 43; 34, 79; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:storage; 41, identifier:current_step; 42, identifier:wizard_prev_step; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:form; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:get_form; 50, argument_list; 50, 51; 50, 65; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:data; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:storage; 58, identifier:get_step_data; 59, argument_list; 59, 60; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:steps; 64, identifier:current; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:files; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:storage; 72, identifier:get_step_files; 73, argument_list; 73, 74; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:steps; 78, identifier:current; 79, return_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:render; 84, argument_list; 84, 85; 85, identifier:form; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:management_form; 89, call; 89, 90; 89, 91; 90, identifier:ManagementForm; 91, argument_list; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:request; 96, identifier:POST; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:prefix; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:prefix; 102, if_statement; 102, 103; 102, 109; 103, not_operator; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:management_form; 107, identifier:is_valid; 108, argument_list; 109, block; 109, 110; 110, raise_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:ValidationError; 113, argument_list; 113, 114; 114, string:'ManagementForm data is missing or has been tampered.'; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:form_current_step; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:management_form; 121, identifier:cleaned_data; 122, string:'current_step'; 123, if_statement; 123, 124; 123, 140; 124, parenthesized_expression; 124, 125; 125, boolean_operator:and; 125, 126; 125, 133; 126, comparison_operator:!=; 126, 127; 126, 128; 127, identifier:form_current_step; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:steps; 132, identifier:current; 133, comparison_operator:is; 133, 134; 133, 139; 134, attribute; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:storage; 138, identifier:current_step; 139, None; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:storage; 147, identifier:current_step; 148, identifier:form_current_step; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:form; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:get_form; 156, argument_list; 156, 157; 156, 164; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:data; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:request; 163, identifier:POST; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:files; 166, attribute; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:request; 170, identifier:FILES; 171, if_statement; 171, 172; 171, 177; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:form; 175, identifier:is_valid; 176, argument_list; 177, block; 177, 178; 177, 197; 177, 216; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:storage; 184, identifier:set_step_data; 185, argument_list; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:steps; 190, identifier:current; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:process_step; 195, argument_list; 195, 196; 196, identifier:form; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 204; 199, attribute; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:storage; 203, identifier:set_step_files; 204, argument_list; 204, 205; 204, 210; 205, attribute; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:steps; 209, identifier:current; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:process_step_files; 214, argument_list; 214, 215; 215, identifier:form; 216, if_statement; 216, 217; 216, 228; 216, 238; 217, comparison_operator:==; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:steps; 222, identifier:current; 223, attribute; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:steps; 227, identifier:last; 228, block; 228, 229; 229, return_statement; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:render_done; 234, argument_list; 234, 235; 234, 236; 235, identifier:form; 236, dictionary_splat; 236, 237; 237, identifier:kwargs; 238, else_clause; 238, 239; 239, block; 239, 240; 240, return_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:render_next_step; 245, argument_list; 245, 246; 246, identifier:form; 247, return_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:render; 252, argument_list; 252, 253; 253, identifier:form | def post(self, *args, **kwargs):
wizard_prev_step = self.request.POST.get('wizard_prev_step', None)
if wizard_prev_step and wizard_prev_step in self.get_form_list():
self.storage.current_step = wizard_prev_step
form = self.get_form(
data=self.storage.get_step_data(self.steps.current),
files=self.storage.get_step_files(self.steps.current))
return self.render(form)
management_form = ManagementForm(self.request.POST, prefix=self.prefix)
if not management_form.is_valid():
raise ValidationError(
'ManagementForm data is missing or has been tampered.')
form_current_step = management_form.cleaned_data['current_step']
if (form_current_step != self.steps.current and
self.storage.current_step is not None):
self.storage.current_step = form_current_step
form = self.get_form(data=self.request.POST, files=self.request.FILES)
if form.is_valid():
self.storage.set_step_data(self.steps.current, self.process_step(form))
self.storage.set_step_files(self.steps.current, self.process_step_files(form))
if self.steps.current == self.steps.last:
return self.render_done(form, **kwargs)
else:
return self.render_next_step(form)
return self.render(form) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parse_config_file; 3, parameters; 3, 4; 3, 5; 4, identifier:job; 5, identifier:config_file; 6, block; 6, 7; 6, 16; 6, 27; 6, 45; 6, 51; 6, 57; 6, 63; 6, 229; 6, 244; 6, 260; 6, 280; 6, 300; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 14; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:job; 12, identifier:fileStore; 13, identifier:logToMaster; 14, argument_list; 14, 15; 15, string:'Parsing config file'; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:config_file; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:os; 23, identifier:path; 24, identifier:abspath; 25, argument_list; 25, 26; 26, identifier:config_file; 27, if_statement; 27, 28; 27, 37; 28, not_operator; 28, 29; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:os; 33, identifier:path; 34, identifier:exists; 35, argument_list; 35, 36; 36, identifier:config_file; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:ParameterError; 41, argument_list; 41, 42; 42, binary_operator:+; 42, 43; 42, 44; 43, string:'The config file was not found at specified location. Please verify '; 44, string:'and retry.'; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:sample_set; 48, call; 48, 49; 48, 50; 49, identifier:defaultdict; 50, argument_list; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:univ_options; 54, call; 54, 55; 54, 56; 55, identifier:defaultdict; 56, argument_list; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:tool_options; 60, call; 60, 61; 60, 62; 61, identifier:defaultdict; 62, argument_list; 63, with_statement; 63, 64; 63, 74; 64, with_clause; 64, 65; 65, with_item; 65, 66; 66, as_pattern; 66, 67; 66, 72; 67, call; 67, 68; 67, 69; 68, identifier:open; 69, argument_list; 69, 70; 69, 71; 70, identifier:config_file; 71, string:'r'; 72, as_pattern_target; 72, 73; 73, identifier:conf; 74, block; 74, 75; 74, 102; 75, for_statement; 75, 76; 75, 77; 75, 78; 76, identifier:line; 77, identifier:conf; 78, block; 78, 79; 78, 87; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:line; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:line; 85, identifier:strip; 86, argument_list; 87, if_statement; 87, 88; 87, 91; 87, 100; 88, attribute; 88, 89; 88, 90; 89, identifier:line; 90, identifier:startswith; 91, ERROR; 91, 92; 91, 93; 91, 94; 92, ERROR; 93, identifier:continue; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:line; 97, identifier:startswith; 98, argument_list; 98, 99; 99, string:'BEGIN'; 100, block; 100, 101; 101, break_statement; 102, for_statement; 102, 103; 102, 106; 102, 111; 103, pattern_list; 103, 104; 103, 105; 104, identifier:groupname; 105, identifier:group_params; 106, call; 106, 107; 106, 108; 107, identifier:tool_specific_param_generator; 108, argument_list; 108, 109; 108, 110; 109, identifier:job; 110, identifier:conf; 111, block; 111, 112; 112, if_statement; 112, 113; 112, 116; 112, 139; 112, 221; 113, comparison_operator:==; 113, 114; 113, 115; 114, identifier:groupname; 115, string:'patient'; 116, block; 116, 117; 116, 131; 117, if_statement; 117, 118; 117, 125; 118, comparison_operator:not; 118, 119; 118, 120; 119, string:'patient_id'; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:group_params; 123, identifier:keys; 124, argument_list; 125, block; 125, 126; 126, raise_statement; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:ParameterError; 129, argument_list; 129, 130; 130, string:'A patient group is missing the patient_id flag.'; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 138; 133, subscript; 133, 134; 133, 135; 134, identifier:sample_set; 135, subscript; 135, 136; 135, 137; 136, identifier:group_params; 137, string:'patient_id'; 138, identifier:group_params; 139, elif_clause; 139, 140; 139, 143; 140, comparison_operator:==; 140, 141; 140, 142; 141, identifier:groupname; 142, string:'Universal_Options'; 143, block; 143, 144; 143, 148; 143, 155; 143, 171; 143, 193; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:univ_options; 147, identifier:group_params; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:required_options; 151, set; 151, 152; 151, 153; 151, 154; 152, string:'java_Xmx'; 153, string:'output_folder'; 154, string:'storage_location'; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:missing_opts; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:required_options; 161, identifier:difference; 162, argument_list; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:set; 165, argument_list; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:univ_options; 169, identifier:keys; 170, argument_list; 171, if_statement; 171, 172; 171, 178; 172, comparison_operator:>; 172, 173; 172, 177; 173, call; 173, 174; 173, 175; 174, identifier:len; 175, argument_list; 175, 176; 176, identifier:missing_opts; 177, integer:0; 178, block; 178, 179; 179, raise_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:ParameterError; 182, argument_list; 182, 183; 183, binary_operator:+; 183, 184; 183, 187; 184, concatenated_string; 184, 185; 184, 186; 185, string:' The following options have no arguments in the config '; 186, string:'file :\n'; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, string:'\n'; 190, identifier:join; 191, argument_list; 191, 192; 192, identifier:missing_opts; 193, if_statement; 193, 194; 193, 197; 194, subscript; 194, 195; 194, 196; 195, identifier:univ_options; 196, string:'sse_key_is_master'; 197, block; 197, 198; 197, 208; 198, assert_statement; 198, 199; 199, comparison_operator:in; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:univ_options; 202, string:'sse_key_is_master'; 203, tuple; 203, 204; 203, 205; 203, 206; 203, 207; 204, string:'True'; 205, string:'true'; 206, string:'False'; 207, string:'false'; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 209, 214; 210, subscript; 210, 211; 210, 212; 211, identifier:univ_options; 212, string:'sse_key_is_master'; 213, line_continuation:\; 214, comparison_operator:in; 214, 215; 214, 218; 215, subscript; 215, 216; 215, 217; 216, identifier:univ_options; 217, string:'sse_key_is_master'; 218, tuple; 218, 219; 218, 220; 219, string:'True'; 220, string:'true'; 221, else_clause; 221, 222; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, subscript; 225, 226; 225, 227; 226, identifier:tool_options; 227, identifier:groupname; 228, identifier:group_params; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:required_tools; 232, set; 232, 233; 232, 234; 232, 235; 232, 236; 232, 237; 232, 238; 232, 239; 232, 240; 232, 241; 232, 242; 232, 243; 233, string:'cutadapt'; 234, string:'bwa'; 235, string:'star'; 236, string:'phlat'; 237, string:'transgene'; 238, string:'mut_callers'; 239, string:'rsem'; 240, string:'mhci'; 241, string:'mhcii'; 242, string:'snpeff'; 243, string:'rank_boost'; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:missing_tools; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:required_tools; 250, identifier:difference; 251, argument_list; 251, 252; 252, call; 252, 253; 252, 254; 253, identifier:set; 254, argument_list; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:tool_options; 258, identifier:keys; 259, argument_list; 260, if_statement; 260, 261; 260, 267; 261, comparison_operator:>; 261, 262; 261, 266; 262, call; 262, 263; 262, 264; 263, identifier:len; 264, argument_list; 264, 265; 265, identifier:missing_tools; 266, integer:0; 267, block; 267, 268; 268, raise_statement; 268, 269; 269, call; 269, 270; 269, 271; 270, identifier:ParameterError; 271, argument_list; 271, 272; 272, binary_operator:+; 272, 273; 272, 274; 273, string:' The following tools have no arguments in the config file : \n'; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, string:'\n'; 277, identifier:join; 278, argument_list; 278, 279; 279, identifier:missing_tools; 280, for_statement; 280, 281; 280, 282; 280, 287; 281, identifier:patient_id; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:sample_set; 285, identifier:keys; 286, argument_list; 287, block; 287, 288; 288, expression_statement; 288, 289; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:job; 292, identifier:addFollowOnJobFn; 293, argument_list; 293, 294; 293, 295; 293, 298; 293, 299; 294, identifier:pipeline_launchpad; 295, subscript; 295, 296; 295, 297; 296, identifier:sample_set; 297, identifier:patient_id; 298, identifier:univ_options; 299, identifier:tool_options; 300, return_statement; 300, 301; 301, None | def parse_config_file(job, config_file):
job.fileStore.logToMaster('Parsing config file')
config_file = os.path.abspath(config_file)
if not os.path.exists(config_file):
raise ParameterError('The config file was not found at specified location. Please verify ' +
'and retry.')
sample_set = defaultdict()
univ_options = defaultdict()
tool_options = defaultdict()
with open(config_file, 'r') as conf:
for line in conf:
line = line.strip()
if line.startswith('
continue
if line.startswith('BEGIN'):
break
for groupname, group_params in tool_specific_param_generator(job, conf):
if groupname == 'patient':
if 'patient_id' not in group_params.keys():
raise ParameterError('A patient group is missing the patient_id flag.')
sample_set[group_params['patient_id']] = group_params
elif groupname == 'Universal_Options':
univ_options = group_params
required_options = {'java_Xmx', 'output_folder', 'storage_location'}
missing_opts = required_options.difference(set(univ_options.keys()))
if len(missing_opts) > 0:
raise ParameterError(' The following options have no arguments in the config '
'file :\n' + '\n'.join(missing_opts))
if univ_options['sse_key_is_master']:
assert univ_options['sse_key_is_master'] in ('True', 'true', 'False', 'false')
univ_options['sse_key_is_master'] = \
univ_options['sse_key_is_master'] in ('True', 'true')
else:
tool_options[groupname] = group_params
required_tools = {'cutadapt', 'bwa', 'star', 'phlat', 'transgene', 'mut_callers', 'rsem',
'mhci', 'mhcii', 'snpeff', 'rank_boost'}
missing_tools = required_tools.difference(set(tool_options.keys()))
if len(missing_tools) > 0:
raise ParameterError(' The following tools have no arguments in the config file : \n' +
'\n'.join(missing_tools))
for patient_id in sample_set.keys():
job.addFollowOnJobFn(pipeline_launchpad, sample_set[patient_id], univ_options, tool_options)
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:run_star; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:job; 5, identifier:fastqs; 6, identifier:univ_options; 7, identifier:star_options; 8, block; 8, 9; 8, 17; 8, 30; 8, 40; 8, 59; 8, 71; 8, 108; 8, 153; 8, 159; 8, 185; 8, 196; 8, 207; 8, 224; 8, 231; 8, 241; 9, assert_statement; 9, 10; 10, comparison_operator:in; 10, 11; 10, 14; 11, subscript; 11, 12; 11, 13; 12, identifier:star_options; 13, string:'type'; 14, tuple; 14, 15; 14, 16; 15, string:'star'; 16, string:'starlong'; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:job; 22, identifier:fileStore; 23, identifier:logToMaster; 24, argument_list; 24, 25; 25, binary_operator:%; 25, 26; 25, 27; 26, string:'Running STAR on %s'; 27, subscript; 27, 28; 27, 29; 28, identifier:univ_options; 29, string:'patient'; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:work_dir; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:job; 37, identifier:fileStore; 38, identifier:getLocalTempDir; 39, argument_list; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:input_files; 43, dictionary; 43, 44; 43, 49; 43, 54; 44, pair; 44, 45; 44, 46; 45, string:'rna_cutadapt_1.fastq'; 46, subscript; 46, 47; 46, 48; 47, identifier:fastqs; 48, string:'rna_cutadapt_1.fastq'; 49, pair; 49, 50; 49, 51; 50, string:'rna_cutadapt_2.fastq'; 51, subscript; 51, 52; 51, 53; 52, identifier:fastqs; 53, string:'rna_cutadapt_2.fastq'; 54, pair; 54, 55; 54, 56; 55, string:'star_index.tar.gz'; 56, subscript; 56, 57; 56, 58; 57, identifier:star_options; 58, string:'index_tar'; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:input_files; 62, call; 62, 63; 62, 64; 63, identifier:get_files_from_filestore; 64, argument_list; 64, 65; 64, 66; 64, 67; 64, 68; 65, identifier:job; 66, identifier:input_files; 67, identifier:work_dir; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:docker; 70, True; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:parameters; 74, list:['--runThreadN', str(star_options['n']),
'--genomeDir', input_files['star_index'],
'--outFileNamePrefix', 'rna',
'--readFilesIn',
input_files['rna_cutadapt_1.fastq'],
input_files['rna_cutadapt_2.fastq'],
'--outSAMattributes', 'NH', 'HI', 'AS', 'NM', 'MD',
'--outSAMtype', 'BAM', 'SortedByCoordinate',
'--quantMode', 'TranscriptomeSAM',
'--outSAMunmapped', 'Within']; 74, 75; 74, 76; 74, 82; 74, 83; 74, 86; 74, 87; 74, 88; 74, 89; 74, 92; 74, 95; 74, 96; 74, 97; 74, 98; 74, 99; 74, 100; 74, 101; 74, 102; 74, 103; 74, 104; 74, 105; 74, 106; 74, 107; 75, string:'--runThreadN'; 76, call; 76, 77; 76, 78; 77, identifier:str; 78, argument_list; 78, 79; 79, subscript; 79, 80; 79, 81; 80, identifier:star_options; 81, string:'n'; 82, string:'--genomeDir'; 83, subscript; 83, 84; 83, 85; 84, identifier:input_files; 85, string:'star_index'; 86, string:'--outFileNamePrefix'; 87, string:'rna'; 88, string:'--readFilesIn'; 89, subscript; 89, 90; 89, 91; 90, identifier:input_files; 91, string:'rna_cutadapt_1.fastq'; 92, subscript; 92, 93; 92, 94; 93, identifier:input_files; 94, string:'rna_cutadapt_2.fastq'; 95, string:'--outSAMattributes'; 96, string:'NH'; 97, string:'HI'; 98, string:'AS'; 99, string:'NM'; 100, string:'MD'; 101, string:'--outSAMtype'; 102, string:'BAM'; 103, string:'SortedByCoordinate'; 104, string:'--quantMode'; 105, string:'TranscriptomeSAM'; 106, string:'--outSAMunmapped'; 107, string:'Within'; 108, if_statement; 108, 109; 108, 114; 108, 133; 109, comparison_operator:==; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:star_options; 112, string:'type'; 113, string:'star'; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:docker_call; 118, argument_list; 118, 119; 118, 122; 118, 125; 118, 128; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:tool; 121, string:'star'; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:tool_parameters; 124, identifier:parameters; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:work_dir; 127, identifier:work_dir; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:dockerhub; 130, subscript; 130, 131; 130, 132; 131, identifier:univ_options; 132, string:'dockerhub'; 133, else_clause; 133, 134; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:docker_call; 138, argument_list; 138, 139; 138, 142; 138, 145; 138, 148; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:tool; 141, string:'starlong'; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:tool_parameters; 144, identifier:parameters; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:work_dir; 147, identifier:work_dir; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:dockerhub; 150, subscript; 150, 151; 150, 152; 151, identifier:univ_options; 152, string:'dockerhub'; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:output_files; 156, call; 156, 157; 156, 158; 157, identifier:defaultdict; 158, argument_list; 159, for_statement; 159, 160; 159, 161; 159, 164; 160, identifier:bam_file; 161, list:['rnaAligned.toTranscriptome.out.bam',
'rnaAligned.sortedByCoord.out.bam']; 161, 162; 161, 163; 162, string:'rnaAligned.toTranscriptome.out.bam'; 163, string:'rnaAligned.sortedByCoord.out.bam'; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:output_files; 169, identifier:bam_file; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:job; 174, identifier:fileStore; 175, identifier:writeGlobalFile; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, string:'/'; 180, identifier:join; 181, argument_list; 181, 182; 182, list:[
work_dir, bam_file]; 182, 183; 182, 184; 183, identifier:work_dir; 184, identifier:bam_file; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 192; 187, attribute; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:job; 190, identifier:fileStore; 191, identifier:deleteGlobalFile; 192, argument_list; 192, 193; 193, subscript; 193, 194; 193, 195; 194, identifier:fastqs; 195, string:'rna_cutadapt_1.fastq'; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 203; 198, attribute; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:job; 201, identifier:fileStore; 202, identifier:deleteGlobalFile; 203, argument_list; 203, 204; 204, subscript; 204, 205; 204, 206; 205, identifier:fastqs; 206, string:'rna_cutadapt_2.fastq'; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:index_star; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:job; 213, identifier:wrapJobFn; 214, argument_list; 214, 215; 214, 216; 214, 219; 214, 220; 214, 221; 215, identifier:index_bamfile; 216, subscript; 216, 217; 216, 218; 217, identifier:output_files; 218, string:'rnaAligned.sortedByCoord.out.bam'; 219, string:'rna'; 220, identifier:univ_options; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:disk; 223, string:'120G'; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:job; 228, identifier:addChild; 229, argument_list; 229, 230; 230, identifier:index_star; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:output_files; 235, string:'rnaAligned.sortedByCoord.out.bam'; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:index_star; 239, identifier:rv; 240, argument_list; 241, return_statement; 241, 242; 242, identifier:output_files | def run_star(job, fastqs, univ_options, star_options):
assert star_options['type'] in ('star', 'starlong')
job.fileStore.logToMaster('Running STAR on %s' %univ_options['patient'])
work_dir = job.fileStore.getLocalTempDir()
input_files = {
'rna_cutadapt_1.fastq': fastqs['rna_cutadapt_1.fastq'],
'rna_cutadapt_2.fastq': fastqs['rna_cutadapt_2.fastq'],
'star_index.tar.gz': star_options['index_tar']}
input_files = get_files_from_filestore(job, input_files, work_dir,
docker=True)
parameters = ['--runThreadN', str(star_options['n']),
'--genomeDir', input_files['star_index'],
'--outFileNamePrefix', 'rna',
'--readFilesIn',
input_files['rna_cutadapt_1.fastq'],
input_files['rna_cutadapt_2.fastq'],
'--outSAMattributes', 'NH', 'HI', 'AS', 'NM', 'MD',
'--outSAMtype', 'BAM', 'SortedByCoordinate',
'--quantMode', 'TranscriptomeSAM',
'--outSAMunmapped', 'Within']
if star_options['type'] == 'star':
docker_call(tool='star', tool_parameters=parameters, work_dir=work_dir,
dockerhub=univ_options['dockerhub'])
else:
docker_call(tool='starlong', tool_parameters=parameters, work_dir=work_dir,
dockerhub=univ_options['dockerhub'])
output_files = defaultdict()
for bam_file in ['rnaAligned.toTranscriptome.out.bam',
'rnaAligned.sortedByCoord.out.bam']:
output_files[bam_file] = job.fileStore.writeGlobalFile('/'.join([
work_dir, bam_file]))
job.fileStore.deleteGlobalFile(fastqs['rna_cutadapt_1.fastq'])
job.fileStore.deleteGlobalFile(fastqs['rna_cutadapt_2.fastq'])
index_star = job.wrapJobFn(index_bamfile,
output_files['rnaAligned.sortedByCoord.out.bam'],
'rna', univ_options, disk='120G')
job.addChild(index_star)
output_files['rnaAligned.sortedByCoord.out.bam'] = index_star.rv()
return output_files |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:run_bwa; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:job; 5, identifier:fastqs; 6, identifier:sample_type; 7, identifier:univ_options; 8, identifier:bwa_options; 9, block; 9, 10; 9, 25; 9, 35; 9, 44; 9, 71; 9, 83; 9, 113; 9, 155; 9, 168; 9, 183; 9, 190; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:job; 15, identifier:fileStore; 16, identifier:logToMaster; 17, argument_list; 17, 18; 18, binary_operator:%; 18, 19; 18, 20; 19, string:'Running bwa on %s:%s'; 20, tuple; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:univ_options; 23, string:'patient'; 24, identifier:sample_type; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:work_dir; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:job; 32, identifier:fileStore; 33, identifier:getLocalTempDir; 34, argument_list; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:fq_extn; 38, conditional_expression:if; 38, 39; 38, 40; 38, 43; 39, string:'.gz'; 40, subscript; 40, 41; 40, 42; 41, identifier:fastqs; 42, string:'gzipped'; 43, string:''; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:input_files; 47, dictionary; 47, 48; 47, 57; 47, 66; 48, pair; 48, 49; 48, 52; 49, binary_operator:+; 49, 50; 49, 51; 50, string:'dna_1.fastq'; 51, identifier:fq_extn; 52, subscript; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:fastqs; 55, identifier:sample_type; 56, integer:0; 57, pair; 57, 58; 57, 61; 58, binary_operator:+; 58, 59; 58, 60; 59, string:'dna_2.fastq'; 60, identifier:fq_extn; 61, subscript; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:fastqs; 64, identifier:sample_type; 65, integer:1; 66, pair; 66, 67; 66, 68; 67, string:'bwa_index.tar.gz'; 68, subscript; 68, 69; 68, 70; 69, identifier:bwa_options; 70, string:'index_tar'; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:input_files; 74, call; 74, 75; 74, 76; 75, identifier:get_files_from_filestore; 76, argument_list; 76, 77; 76, 78; 76, 79; 76, 80; 77, identifier:job; 78, identifier:input_files; 79, identifier:work_dir; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:docker; 82, True; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:parameters; 86, list:['mem',
'-t', str(bwa_options['n']),
'-v', '1',
'/'.join([input_files['bwa_index'], 'hg19.fa']),
input_files['dna_1.fastq'],
input_files['dna_2.fastq']]; 86, 87; 86, 88; 86, 89; 86, 95; 86, 96; 86, 97; 86, 107; 86, 110; 87, string:'mem'; 88, string:'-t'; 89, call; 89, 90; 89, 91; 90, identifier:str; 91, argument_list; 91, 92; 92, subscript; 92, 93; 92, 94; 93, identifier:bwa_options; 94, string:'n'; 95, string:'-v'; 96, string:'1'; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, string:'/'; 100, identifier:join; 101, argument_list; 101, 102; 102, list:[input_files['bwa_index'], 'hg19.fa']; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:input_files; 105, string:'bwa_index'; 106, string:'hg19.fa'; 107, subscript; 107, 108; 107, 109; 108, identifier:input_files; 109, string:'dna_1.fastq'; 110, subscript; 110, 111; 110, 112; 111, identifier:input_files; 112, string:'dna_2.fastq'; 113, with_statement; 113, 114; 113, 133; 114, with_clause; 114, 115; 115, with_item; 115, 116; 116, as_pattern; 116, 117; 116, 131; 117, call; 117, 118; 117, 119; 118, identifier:open; 119, argument_list; 119, 120; 119, 130; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, string:''; 123, identifier:join; 124, argument_list; 124, 125; 125, list:[work_dir, '/', sample_type, '_aligned.sam']; 125, 126; 125, 127; 125, 128; 125, 129; 126, identifier:work_dir; 127, string:'/'; 128, identifier:sample_type; 129, string:'_aligned.sam'; 130, string:'w'; 131, as_pattern_target; 131, 132; 132, identifier:samfile; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:docker_call; 137, argument_list; 137, 138; 137, 141; 137, 144; 137, 147; 137, 152; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:tool; 140, string:'bwa'; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:tool_parameters; 143, identifier:parameters; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:work_dir; 146, identifier:work_dir; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:dockerhub; 149, subscript; 149, 150; 149, 151; 150, identifier:univ_options; 151, string:'dockerhub'; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:outfile; 154, identifier:samfile; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:output_file; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:job; 162, identifier:fileStore; 163, identifier:writeGlobalFile; 164, argument_list; 164, 165; 165, attribute; 165, 166; 165, 167; 166, identifier:samfile; 167, identifier:name; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:samfile_processing; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:job; 174, identifier:wrapJobFn; 175, argument_list; 175, 176; 175, 177; 175, 178; 175, 179; 175, 180; 176, identifier:bam_conversion; 177, identifier:output_file; 178, identifier:sample_type; 179, identifier:univ_options; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:disk; 182, string:'60G'; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:job; 187, identifier:addChild; 188, argument_list; 188, 189; 189, identifier:samfile_processing; 190, return_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:samfile_processing; 194, identifier:rv; 195, argument_list | def run_bwa(job, fastqs, sample_type, univ_options, bwa_options):
job.fileStore.logToMaster('Running bwa on %s:%s' % (univ_options['patient'], sample_type))
work_dir = job.fileStore.getLocalTempDir()
fq_extn = '.gz' if fastqs['gzipped'] else ''
input_files = {
'dna_1.fastq' + fq_extn: fastqs[sample_type][0],
'dna_2.fastq' + fq_extn: fastqs[sample_type][1],
'bwa_index.tar.gz': bwa_options['index_tar']}
input_files = get_files_from_filestore(job, input_files, work_dir, docker=True)
parameters = ['mem',
'-t', str(bwa_options['n']),
'-v', '1',
'/'.join([input_files['bwa_index'], 'hg19.fa']),
input_files['dna_1.fastq'],
input_files['dna_2.fastq']]
with open(''.join([work_dir, '/', sample_type, '_aligned.sam']), 'w') as samfile:
docker_call(tool='bwa', tool_parameters=parameters, work_dir=work_dir,
dockerhub=univ_options['dockerhub'], outfile=samfile)
output_file = job.fileStore.writeGlobalFile(samfile.name)
samfile_processing = job.wrapJobFn(bam_conversion, output_file, sample_type, univ_options,
disk='60G')
job.addChild(samfile_processing)
return samfile_processing.rv() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:merge_radia; 3, parameters; 3, 4; 3, 5; 4, identifier:job; 5, identifier:perchrom_rvs; 6, block; 6, 7; 6, 16; 6, 26; 6, 49; 6, 61; 6, 87; 6, 233; 6, 270; 6, 276; 6, 306; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 14; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:job; 12, identifier:fileStore; 13, identifier:logToMaster; 14, argument_list; 14, 15; 15, string:'Running merge_radia'; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:work_dir; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:job; 23, identifier:fileStore; 24, identifier:getLocalTempDir; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:input_files; 29, dictionary_comprehension; 29, 30; 29, 33; 29, 40; 30, pair; 30, 31; 30, 32; 31, identifier:filename; 32, identifier:jsid; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:perchrom_files; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:perchrom_rvs; 38, identifier:values; 39, argument_list; 40, for_in_clause; 40, 41; 40, 44; 41, pattern_list; 41, 42; 41, 43; 42, identifier:filename; 43, identifier:jsid; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:perchrom_files; 47, identifier:items; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:input_files; 52, call; 52, 53; 52, 54; 53, identifier:get_files_from_filestore; 54, argument_list; 54, 55; 54, 56; 54, 57; 54, 58; 55, identifier:job; 56, identifier:input_files; 57, identifier:work_dir; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:docker; 60, False; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:chromosomes; 64, list_comprehension; 64, 65; 64, 76; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, string:''; 68, identifier:join; 69, argument_list; 69, 70; 70, list:['chr', str(x)]; 70, 71; 70, 72; 71, string:'chr'; 72, call; 72, 73; 72, 74; 73, identifier:str; 74, argument_list; 74, 75; 75, identifier:x; 76, for_in_clause; 76, 77; 76, 78; 77, identifier:x; 78, binary_operator:+; 78, 79; 78, 84; 79, call; 79, 80; 79, 81; 80, identifier:range; 81, argument_list; 81, 82; 81, 83; 82, integer:1; 83, integer:23; 84, list:['X', 'Y']; 84, 85; 84, 86; 85, string:'X'; 86, string:'Y'; 87, with_statement; 87, 88; 87, 122; 88, with_clause; 88, 89; 88, 105; 88, 106; 89, with_item; 89, 90; 90, as_pattern; 90, 91; 90, 103; 91, call; 91, 92; 91, 93; 92, identifier:open; 93, argument_list; 93, 94; 93, 102; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, string:'/'; 97, identifier:join; 98, argument_list; 98, 99; 99, list:[work_dir, 'radia_calls.vcf']; 99, 100; 99, 101; 100, identifier:work_dir; 101, string:'radia_calls.vcf'; 102, string:'w'; 103, as_pattern_target; 103, 104; 104, identifier:radfile; 105, line_continuation:\; 106, with_item; 106, 107; 107, as_pattern; 107, 108; 107, 120; 108, call; 108, 109; 108, 110; 109, identifier:open; 110, argument_list; 110, 111; 110, 119; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, string:'/'; 114, identifier:join; 115, argument_list; 115, 116; 116, list:[work_dir, 'radia_filter_passing_calls.vcf']; 116, 117; 116, 118; 117, identifier:work_dir; 118, string:'radia_filter_passing_calls.vcf'; 119, string:'w'; 120, as_pattern_target; 120, 121; 121, identifier:radpassfile; 122, block; 122, 123; 123, for_statement; 123, 124; 123, 125; 123, 126; 124, identifier:chrom; 125, identifier:chromosomes; 126, block; 126, 127; 127, with_statement; 127, 128; 127, 148; 128, with_clause; 128, 129; 129, with_item; 129, 130; 130, as_pattern; 130, 131; 130, 146; 131, call; 131, 132; 131, 133; 132, identifier:open; 133, argument_list; 133, 134; 133, 145; 134, subscript; 134, 135; 134, 136; 135, identifier:input_files; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, string:''; 139, identifier:join; 140, argument_list; 140, 141; 141, list:['radia_filtered_', chrom, '.vcf']; 141, 142; 141, 143; 141, 144; 142, string:'radia_filtered_'; 143, identifier:chrom; 144, string:'.vcf'; 145, string:'r'; 146, as_pattern_target; 146, 147; 147, identifier:filtradfile; 148, block; 148, 149; 149, for_statement; 149, 150; 149, 151; 149, 152; 150, identifier:line; 151, identifier:filtradfile; 152, block; 152, 153; 152, 161; 152, 186; 152, 187; 152, 198; 152, 207; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:line; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:line; 159, identifier:strip; 160, argument_list; 161, if_statement; 161, 162; 161, 165; 161, 169; 162, attribute; 162, 163; 162, 164; 163, identifier:line; 164, identifier:startswith; 165, ERROR; 165, 166; 165, 167; 166, string:'
if chrom == '; 167, ERROR; 167, 168; 168, identifier:chr1; 169, block; 169, 170; 169, 178; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:print; 173, argument_list; 173, 174; 173, 175; 174, identifier:line; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:file; 177, identifier:radfile; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:print; 181, argument_list; 181, 182; 181, 183; 182, identifier:line; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:file; 185, identifier:radpassfile; 186, continue_statement; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:else; 190, type; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:print; 193, argument_list; 193, 194; 193, 195; 194, identifier:line; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:file; 197, identifier:radfile; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:line; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:line; 204, identifier:split; 205, argument_list; 205, 206; 206, string:'\t'; 207, if_statement; 207, 208; 207, 219; 208, boolean_operator:and; 208, 209; 208, 214; 209, comparison_operator:==; 209, 210; 209, 213; 210, subscript; 210, 211; 210, 212; 211, identifier:line; 212, integer:6; 213, string:'PASS'; 214, comparison_operator:not; 214, 215; 214, 216; 215, string:'MT=GERM'; 216, subscript; 216, 217; 216, 218; 217, identifier:line; 218, integer:7; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:print; 223, argument_list; 223, 224; 223, 230; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, string:'\t'; 227, identifier:join; 228, argument_list; 228, 229; 229, identifier:line; 230, keyword_argument; 230, 231; 230, 232; 231, identifier:file; 232, identifier:radpassfile; 233, with_statement; 233, 234; 233, 263; 234, with_clause; 234, 235; 234, 246; 234, 247; 235, with_item; 235, 236; 236, as_pattern; 236, 237; 236, 244; 237, call; 237, 238; 237, 239; 238, identifier:open; 239, argument_list; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:radpassfile; 242, identifier:name; 243, string:'r'; 244, as_pattern_target; 244, 245; 245, identifier:radpassfile; 246, line_continuation:\; 247, with_item; 247, 248; 248, as_pattern; 248, 249; 248, 261; 249, call; 249, 250; 249, 251; 250, identifier:open; 251, argument_list; 251, 252; 251, 260; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, string:'/'; 255, identifier:join; 256, argument_list; 256, 257; 257, list:[work_dir, 'radia_parsed_filter_passing_calls.vcf']; 257, 258; 257, 259; 258, identifier:work_dir; 259, string:'radia_parsed_filter_passing_calls.vcf'; 260, string:'w'; 261, as_pattern_target; 261, 262; 262, identifier:parsedradfile; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:parse_radia_multi_alt; 267, argument_list; 267, 268; 267, 269; 268, identifier:radpassfile; 269, identifier:parsedradfile; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:output_files; 273, call; 273, 274; 273, 275; 274, identifier:defaultdict; 275, argument_list; 276, for_statement; 276, 277; 276, 278; 276, 285; 277, identifier:radia_file; 278, list:[radfile.name, parsedradfile.name]; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:radfile; 281, identifier:name; 282, attribute; 282, 283; 282, 284; 283, identifier:parsedradfile; 284, identifier:name; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 298; 288, subscript; 288, 289; 288, 290; 289, identifier:output_files; 290, call; 290, 291; 290, 296; 291, attribute; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:os; 294, identifier:path; 295, identifier:basename; 296, argument_list; 296, 297; 297, identifier:radia_file; 298, call; 298, 299; 298, 304; 299, attribute; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:job; 302, identifier:fileStore; 303, identifier:writeGlobalFile; 304, argument_list; 304, 305; 305, identifier:radia_file; 306, return_statement; 306, 307; 307, identifier:output_files | def merge_radia(job, perchrom_rvs):
job.fileStore.logToMaster('Running merge_radia')
work_dir = job.fileStore.getLocalTempDir()
input_files = {filename: jsid for perchrom_files in perchrom_rvs.values()
for filename, jsid in perchrom_files.items()}
input_files = get_files_from_filestore(job, input_files, work_dir,
docker=False)
chromosomes = [''.join(['chr', str(x)]) for x in range(1, 23) + ['X', 'Y']]
with open('/'.join([work_dir, 'radia_calls.vcf']), 'w') as radfile, \
open('/'.join([work_dir, 'radia_filter_passing_calls.vcf']), 'w') as radpassfile:
for chrom in chromosomes:
with open(input_files[''.join(['radia_filtered_', chrom, '.vcf'])], 'r') as filtradfile:
for line in filtradfile:
line = line.strip()
if line.startswith('
if chrom == 'chr1':
print(line, file=radfile)
print(line, file=radpassfile)
continue
else:
print(line, file=radfile)
line = line.split('\t')
if line[6] == 'PASS' and 'MT=GERM' not in line[7]:
print('\t'.join(line), file=radpassfile)
with open(radpassfile.name, 'r') as radpassfile, \
open('/'.join([work_dir, 'radia_parsed_filter_passing_calls.vcf']),
'w') as parsedradfile:
parse_radia_multi_alt(radpassfile, parsedradfile)
output_files = defaultdict()
for radia_file in [radfile.name, parsedradfile.name]:
output_files[os.path.basename(radia_file)] = job.fileStore.writeGlobalFile(radia_file)
return output_files |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:merge_mutect; 3, parameters; 3, 4; 3, 5; 4, identifier:job; 5, identifier:perchrom_rvs; 6, block; 6, 7; 6, 16; 6, 26; 6, 49; 6, 61; 6, 87; 6, 328; 6, 341; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 14; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:job; 12, identifier:fileStore; 13, identifier:logToMaster; 14, argument_list; 14, 15; 15, string:'Running merge_mutect'; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:work_dir; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:job; 23, identifier:fileStore; 24, identifier:getLocalTempDir; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:input_files; 29, dictionary_comprehension; 29, 30; 29, 33; 29, 40; 30, pair; 30, 31; 30, 32; 31, identifier:filename; 32, identifier:jsid; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:perchrom_files; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:perchrom_rvs; 38, identifier:values; 39, argument_list; 40, for_in_clause; 40, 41; 40, 44; 41, pattern_list; 41, 42; 41, 43; 42, identifier:filename; 43, identifier:jsid; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:perchrom_files; 47, identifier:items; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:input_files; 52, call; 52, 53; 52, 54; 53, identifier:get_files_from_filestore; 54, argument_list; 54, 55; 54, 56; 54, 57; 54, 58; 55, identifier:job; 56, identifier:input_files; 57, identifier:work_dir; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:docker; 60, False; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:chromosomes; 64, list_comprehension; 64, 65; 64, 76; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, string:''; 68, identifier:join; 69, argument_list; 69, 70; 70, list:['chr', str(x)]; 70, 71; 70, 72; 71, string:'chr'; 72, call; 72, 73; 72, 74; 73, identifier:str; 74, argument_list; 74, 75; 75, identifier:x; 76, for_in_clause; 76, 77; 76, 78; 77, identifier:x; 78, binary_operator:+; 78, 79; 78, 84; 79, call; 79, 80; 79, 81; 80, identifier:range; 81, argument_list; 81, 82; 81, 83; 82, integer:1; 83, integer:23; 84, list:['X', 'Y']; 84, 85; 84, 86; 85, string:'X'; 86, string:'Y'; 87, with_statement; 87, 88; 87, 139; 88, with_clause; 88, 89; 88, 105; 88, 106; 88, 122; 88, 123; 89, with_item; 89, 90; 90, as_pattern; 90, 91; 90, 103; 91, call; 91, 92; 91, 93; 92, identifier:open; 93, argument_list; 93, 94; 93, 102; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, string:'/'; 97, identifier:join; 98, argument_list; 98, 99; 99, list:[work_dir, 'mutect_calls.vcf']; 99, 100; 99, 101; 100, identifier:work_dir; 101, string:'mutect_calls.vcf'; 102, string:'w'; 103, as_pattern_target; 103, 104; 104, identifier:mutvcf; 105, line_continuation:\; 106, with_item; 106, 107; 107, as_pattern; 107, 108; 107, 120; 108, call; 108, 109; 108, 110; 109, identifier:open; 110, argument_list; 110, 111; 110, 119; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, string:'/'; 114, identifier:join; 115, argument_list; 115, 116; 116, list:[work_dir, 'mutect_calls.out']; 116, 117; 116, 118; 117, identifier:work_dir; 118, string:'mutect_calls.out'; 119, string:'w'; 120, as_pattern_target; 120, 121; 121, identifier:mutout; 122, line_continuation:\; 123, with_item; 123, 124; 124, as_pattern; 124, 125; 124, 137; 125, call; 125, 126; 125, 127; 126, identifier:open; 127, argument_list; 127, 128; 127, 136; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, string:'/'; 131, identifier:join; 132, argument_list; 132, 133; 133, list:[work_dir, 'mutect_passing_calls.vcf']; 133, 134; 133, 135; 134, identifier:work_dir; 135, string:'mutect_passing_calls.vcf'; 136, string:'w'; 137, as_pattern_target; 137, 138; 138, identifier:mutpassvcf; 139, block; 139, 140; 139, 144; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:out_header_not_printed; 143, True; 144, for_statement; 144, 145; 144, 146; 144, 147; 145, identifier:chrom; 146, identifier:chromosomes; 147, block; 147, 148; 147, 248; 148, with_statement; 148, 149; 148, 169; 149, with_clause; 149, 150; 150, with_item; 150, 151; 151, as_pattern; 151, 152; 151, 167; 152, call; 152, 153; 152, 154; 153, identifier:open; 154, argument_list; 154, 155; 154, 166; 155, subscript; 155, 156; 155, 157; 156, identifier:input_files; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, string:''; 160, identifier:join; 161, argument_list; 161, 162; 162, list:['mutect_', chrom, '.vcf']; 162, 163; 162, 164; 162, 165; 163, string:'mutect_'; 164, identifier:chrom; 165, string:'.vcf'; 166, string:'r'; 167, as_pattern_target; 167, 168; 168, identifier:mutfile; 169, block; 169, 170; 170, for_statement; 170, 171; 170, 172; 170, 173; 171, identifier:line; 172, identifier:mutfile; 173, block; 173, 174; 173, 182; 173, 207; 173, 208; 173, 219; 173, 228; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:line; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:line; 180, identifier:strip; 181, argument_list; 182, if_statement; 182, 183; 182, 186; 182, 190; 183, attribute; 183, 184; 183, 185; 184, identifier:line; 185, identifier:startswith; 186, ERROR; 186, 187; 186, 188; 187, string:'
if chrom == '; 188, ERROR; 188, 189; 189, identifier:chr1; 190, block; 190, 191; 190, 199; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 194; 193, identifier:print; 194, argument_list; 194, 195; 194, 196; 195, identifier:line; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:file; 198, identifier:mutvcf; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:print; 202, argument_list; 202, 203; 202, 204; 203, identifier:line; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:file; 206, identifier:mutpassvcf; 207, continue_statement; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:else; 211, type; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:print; 214, argument_list; 214, 215; 214, 216; 215, identifier:line; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:file; 218, identifier:mutvcf; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:line; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:line; 225, identifier:split; 226, argument_list; 226, 227; 227, string:'\t'; 228, if_statement; 228, 229; 228, 234; 229, comparison_operator:!=; 229, 230; 229, 233; 230, subscript; 230, 231; 230, 232; 231, identifier:line; 232, integer:6; 233, string:'REJECT'; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 238; 237, identifier:print; 238, argument_list; 238, 239; 238, 245; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, string:'\t'; 242, identifier:join; 243, argument_list; 243, 244; 244, identifier:line; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:file; 247, identifier:mutpassvcf; 248, with_statement; 248, 249; 248, 269; 249, with_clause; 249, 250; 250, with_item; 250, 251; 251, as_pattern; 251, 252; 251, 267; 252, call; 252, 253; 252, 254; 253, identifier:open; 254, argument_list; 254, 255; 254, 266; 255, subscript; 255, 256; 255, 257; 256, identifier:input_files; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, string:''; 260, identifier:join; 261, argument_list; 261, 262; 262, list:['mutect_', chrom,
'.out']; 262, 263; 262, 264; 262, 265; 263, string:'mutect_'; 264, identifier:chrom; 265, string:'.out'; 266, string:'r'; 267, as_pattern_target; 267, 268; 268, identifier:mutfile; 269, block; 269, 270; 270, for_statement; 270, 271; 270, 272; 270, 273; 271, identifier:line; 272, identifier:mutfile; 273, block; 273, 274; 273, 282; 273, 299; 273, 300; 273, 302; 273, 313; 273, 317; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:line; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:line; 280, identifier:strip; 281, argument_list; 282, if_statement; 282, 283; 282, 286; 282, 290; 283, attribute; 283, 284; 283, 285; 284, identifier:line; 285, identifier:startswith; 286, ERROR; 286, 287; 286, 288; 287, string:'
if chrom == '; 288, ERROR; 288, 289; 289, identifier:chr1; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:print; 294, argument_list; 294, 295; 294, 296; 295, identifier:line; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:file; 298, identifier:mutout; 299, continue_statement; 300, ERROR; 300, 301; 301, identifier:elif; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:out_header_not_printed; 305, type; 305, 306; 306, call; 306, 307; 306, 308; 307, identifier:print; 308, argument_list; 308, 309; 308, 310; 309, identifier:line; 310, keyword_argument; 310, 311; 310, 312; 311, identifier:file; 312, identifier:mutout; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:out_header_not_printed; 316, False; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:else; 320, type; 320, 321; 321, call; 321, 322; 321, 323; 322, identifier:print; 323, argument_list; 323, 324; 323, 325; 324, identifier:line; 325, keyword_argument; 325, 326; 325, 327; 326, identifier:file; 327, identifier:mutout; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:output_file; 331, call; 331, 332; 331, 337; 332, attribute; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:job; 335, identifier:fileStore; 336, identifier:writeGlobalFile; 337, argument_list; 337, 338; 338, attribute; 338, 339; 338, 340; 339, identifier:mutpassvcf; 340, identifier:name; 341, return_statement; 341, 342; 342, identifier:output_file | def merge_mutect(job, perchrom_rvs):
job.fileStore.logToMaster('Running merge_mutect')
work_dir = job.fileStore.getLocalTempDir()
input_files = {filename: jsid for perchrom_files in perchrom_rvs.values()
for filename, jsid in perchrom_files.items()}
input_files = get_files_from_filestore(job, input_files, work_dir, docker=False)
chromosomes = [''.join(['chr', str(x)]) for x in range(1, 23) + ['X', 'Y']]
with open('/'.join([work_dir, 'mutect_calls.vcf']), 'w') as mutvcf, \
open('/'.join([work_dir, 'mutect_calls.out']), 'w') as mutout, \
open('/'.join([work_dir, 'mutect_passing_calls.vcf']), 'w') as mutpassvcf:
out_header_not_printed = True
for chrom in chromosomes:
with open(input_files[''.join(['mutect_', chrom, '.vcf'])], 'r') as mutfile:
for line in mutfile:
line = line.strip()
if line.startswith('
if chrom == 'chr1':
print(line, file=mutvcf)
print(line, file=mutpassvcf)
continue
else:
print(line, file=mutvcf)
line = line.split('\t')
if line[6] != 'REJECT':
print('\t'.join(line), file=mutpassvcf)
with open(input_files[''.join(['mutect_', chrom,
'.out'])], 'r') as mutfile:
for line in mutfile:
line = line.strip()
if line.startswith('
if chrom == 'chr1':
print(line, file=mutout)
continue
elif out_header_not_printed:
print(line, file=mutout)
out_header_not_printed = False
else:
print(line, file=mutout)
output_file = job.fileStore.writeGlobalFile(mutpassvcf.name)
return output_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:run_mutation_aggregator; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:job; 5, identifier:fusion_output; 6, identifier:radia_output; 7, identifier:mutect_output; 8, identifier:indel_output; 9, identifier:univ_options; 10, block; 10, 11; 10, 24; 10, 34; 10, 52; 10, 64; 10, 71; 10, 78; 10, 84; 10, 92; 10, 208; 10, 216; 10, 224; 10, 237; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:job; 16, identifier:fileStore; 17, identifier:logToMaster; 18, argument_list; 18, 19; 19, binary_operator:%; 19, 20; 19, 21; 20, string:'Aggregating mutations for %s'; 21, subscript; 21, 22; 21, 23; 22, identifier:univ_options; 23, string:'patient'; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:work_dir; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:job; 31, identifier:fileStore; 32, identifier:getLocalTempDir; 33, argument_list; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:input_files; 37, dictionary; 37, 38; 37, 41; 37, 46; 37, 49; 38, pair; 38, 39; 38, 40; 39, string:'mutect.vcf'; 40, identifier:mutect_output; 41, pair; 41, 42; 41, 43; 42, string:'radia.vcf'; 43, subscript; 43, 44; 43, 45; 44, identifier:radia_output; 45, string:'radia_parsed_filter_passing_calls.vcf'; 46, pair; 46, 47; 46, 48; 47, string:'indel.vcf'; 48, identifier:indel_output; 49, pair; 49, 50; 49, 51; 50, string:'fusion.vcf'; 51, identifier:fusion_output; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:input_files; 55, call; 55, 56; 55, 57; 56, identifier:get_files_from_filestore; 57, argument_list; 57, 58; 57, 59; 57, 60; 57, 61; 58, identifier:job; 59, identifier:input_files; 60, identifier:work_dir; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:docker; 63, False; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:input_files; 68, identifier:pop; 69, argument_list; 69, 70; 70, string:'indel.vcf'; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:input_files; 75, identifier:pop; 76, argument_list; 76, 77; 77, string:'fusion.vcf'; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:vcf_file; 81, call; 81, 82; 81, 83; 82, identifier:defaultdict; 83, argument_list; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:mutcallers; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:input_files; 90, identifier:keys; 91, argument_list; 92, with_statement; 92, 93; 92, 114; 93, with_clause; 93, 94; 94, with_item; 94, 95; 95, as_pattern; 95, 96; 95, 112; 96, call; 96, 97; 96, 98; 97, identifier:open; 98, argument_list; 98, 99; 98, 111; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, string:''; 102, identifier:join; 103, argument_list; 103, 104; 104, list:[work_dir, '/', univ_options['patient'], '_merged_mutations.vcf']; 104, 105; 104, 106; 104, 107; 104, 110; 105, identifier:work_dir; 106, string:'/'; 107, subscript; 107, 108; 107, 109; 108, identifier:univ_options; 109, string:'patient'; 110, string:'_merged_mutations.vcf'; 111, string:'w'; 112, as_pattern_target; 112, 113; 113, identifier:merged_mut_file; 114, block; 114, 115; 115, for_statement; 115, 116; 115, 117; 115, 118; 116, identifier:mut_caller; 117, identifier:mutcallers; 118, block; 118, 119; 118, 128; 118, 136; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:caller; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:mut_caller; 125, identifier:rstrip; 126, argument_list; 126, 127; 127, string:'.vcf'; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 133; 130, subscript; 130, 131; 130, 132; 131, identifier:vcf_file; 132, identifier:caller; 133, call; 133, 134; 133, 135; 134, identifier:defaultdict; 135, argument_list; 136, with_statement; 136, 137; 136, 149; 137, with_clause; 137, 138; 138, with_item; 138, 139; 139, as_pattern; 139, 140; 139, 147; 140, call; 140, 141; 140, 142; 141, identifier:open; 142, argument_list; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:input_files; 145, identifier:mut_caller; 146, string:'r'; 147, as_pattern_target; 147, 148; 148, identifier:mutfile; 149, block; 149, 150; 150, for_statement; 150, 151; 150, 152; 150, 153; 151, identifier:line; 152, identifier:mutfile; 153, block; 153, 154; 153, 175; 153, 176; 153, 188; 154, if_statement; 154, 155; 154, 158; 154, 162; 155, attribute; 155, 156; 155, 157; 156, identifier:line; 157, identifier:startswith; 158, ERROR; 158, 159; 158, 160; 159, string:'
if caller == '; 160, ERROR; 160, 161; 161, identifier:radia; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:print; 166, argument_list; 166, 167; 166, 172; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:line; 170, identifier:strip; 171, argument_list; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:file; 174, identifier:merged_mut_file; 175, continue_statement; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:line; 179, call; 179, 180; 179, 187; 180, attribute; 180, 181; 180, 186; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:line; 184, identifier:strip; 185, argument_list; 186, identifier:split; 187, argument_list; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 207; 190, subscript; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:vcf_file; 193, identifier:caller; 194, tuple; 194, 195; 194, 198; 194, 201; 194, 204; 195, subscript; 195, 196; 195, 197; 196, identifier:line; 197, integer:0; 198, subscript; 198, 199; 198, 200; 199, identifier:line; 200, integer:1; 201, subscript; 201, 202; 201, 203; 202, identifier:line; 203, integer:3; 204, subscript; 204, 205; 204, 206; 205, identifier:line; 206, integer:4; 207, identifier:line; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:merge_vcfs; 211, argument_list; 211, 212; 211, 213; 212, identifier:vcf_file; 213, attribute; 213, 214; 213, 215; 214, identifier:merged_mut_file; 215, identifier:name; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 219; 218, identifier:export_results; 219, argument_list; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:merged_mut_file; 222, identifier:name; 223, identifier:univ_options; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:output_file; 227, call; 227, 228; 227, 233; 228, attribute; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:job; 231, identifier:fileStore; 232, identifier:writeGlobalFile; 233, argument_list; 233, 234; 234, attribute; 234, 235; 234, 236; 235, identifier:merged_mut_file; 236, identifier:name; 237, return_statement; 237, 238; 238, identifier:output_file | def run_mutation_aggregator(job, fusion_output, radia_output, mutect_output, indel_output,
univ_options):
job.fileStore.logToMaster('Aggregating mutations for %s' % univ_options['patient'])
work_dir = job.fileStore.getLocalTempDir()
input_files = {
'mutect.vcf': mutect_output,
'radia.vcf': radia_output['radia_parsed_filter_passing_calls.vcf'],
'indel.vcf': indel_output,
'fusion.vcf': fusion_output}
input_files = get_files_from_filestore(job, input_files, work_dir, docker=False)
input_files.pop('indel.vcf')
input_files.pop('fusion.vcf')
vcf_file = defaultdict()
mutcallers = input_files.keys()
with open(''.join([work_dir, '/', univ_options['patient'], '_merged_mutations.vcf']),
'w') as merged_mut_file:
for mut_caller in mutcallers:
caller = mut_caller.rstrip('.vcf')
vcf_file[caller] = defaultdict()
with open(input_files[mut_caller], 'r') as mutfile:
for line in mutfile:
if line.startswith('
if caller == 'radia':
print(line.strip(), file=merged_mut_file)
continue
line = line.strip().split()
vcf_file[caller][(line[0], line[1], line[3], line[4])] = line
merge_vcfs(vcf_file, merged_mut_file.name)
export_results(merged_mut_file.name, univ_options)
output_file = job.fileStore.writeGlobalFile(merged_mut_file.name)
return output_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:merge_phlat_calls; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:job; 5, identifier:tumor_phlat; 6, identifier:normal_phlat; 7, identifier:rna_phlat; 8, block; 8, 9; 8, 18; 8, 28; 8, 41; 8, 50; 8, 131; 8, 285; 8, 291; 8, 318; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:job; 14, identifier:fileStore; 15, identifier:logToMaster; 16, argument_list; 16, 17; 17, string:'Merging Phlat calls'; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:work_dir; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:job; 25, identifier:fileStore; 26, identifier:getLocalTempDir; 27, argument_list; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:input_files; 31, dictionary; 31, 32; 31, 35; 31, 38; 32, pair; 32, 33; 32, 34; 33, string:'tumor_dna'; 34, identifier:tumor_phlat; 35, pair; 35, 36; 35, 37; 36, string:'normal_dna'; 37, identifier:normal_phlat; 38, pair; 38, 39; 38, 40; 39, string:'tumor_rna'; 40, identifier:rna_phlat; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:input_files; 44, call; 44, 45; 44, 46; 45, identifier:get_files_from_filestore; 46, argument_list; 46, 47; 46, 48; 46, 49; 47, identifier:job; 48, identifier:input_files; 49, identifier:work_dir; 50, with_statement; 50, 51; 50, 87; 51, with_clause; 51, 52; 51, 63; 51, 64; 51, 75; 51, 76; 52, with_item; 52, 53; 53, as_pattern; 53, 54; 53, 61; 54, call; 54, 55; 54, 56; 55, identifier:open; 56, argument_list; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:input_files; 59, string:'tumor_dna'; 60, string:'r'; 61, as_pattern_target; 61, 62; 62, identifier:td_file; 63, line_continuation:\; 64, with_item; 64, 65; 65, as_pattern; 65, 66; 65, 73; 66, call; 66, 67; 66, 68; 67, identifier:open; 68, argument_list; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:input_files; 71, string:'normal_dna'; 72, string:'r'; 73, as_pattern_target; 73, 74; 74, identifier:nd_file; 75, line_continuation:\; 76, with_item; 76, 77; 77, as_pattern; 77, 78; 77, 85; 78, call; 78, 79; 78, 80; 79, identifier:open; 80, argument_list; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:input_files; 83, string:'tumor_rna'; 84, string:'r'; 85, as_pattern_target; 85, 86; 86, identifier:tr_file; 87, block; 87, 88; 87, 116; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:mhc_alleles; 91, dictionary; 91, 92; 91, 95; 91, 98; 91, 101; 91, 104; 91, 107; 91, 110; 91, 113; 92, pair; 92, 93; 92, 94; 93, string:'HLA_A'; 94, list:[]; 95, pair; 95, 96; 95, 97; 96, string:'HLA_B'; 97, list:[]; 98, pair; 98, 99; 98, 100; 99, string:'HLA_C'; 100, list:[]; 101, pair; 101, 102; 101, 103; 102, string:'HLA_DPA'; 103, list:[]; 104, pair; 104, 105; 104, 106; 105, string:'HLA_DQA'; 106, list:[]; 107, pair; 107, 108; 107, 109; 108, string:'HLA_DPB'; 109, list:[]; 110, pair; 110, 111; 110, 112; 111, string:'HLA_DQB'; 112, list:[]; 113, pair; 113, 114; 113, 115; 114, string:'HLA_DRB'; 115, list:[]; 116, for_statement; 116, 117; 116, 118; 116, 122; 117, identifier:phlatfile; 118, expression_list; 118, 119; 118, 120; 118, 121; 119, identifier:td_file; 120, identifier:nd_file; 121, identifier:tr_file; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:mhc_alleles; 126, call; 126, 127; 126, 128; 127, identifier:parse_phlat_file; 128, argument_list; 128, 129; 128, 130; 129, identifier:phlatfile; 130, identifier:mhc_alleles; 131, with_statement; 131, 132; 131, 168; 132, with_clause; 132, 133; 132, 150; 132, 151; 133, with_item; 133, 134; 134, as_pattern; 134, 135; 134, 148; 135, call; 135, 136; 135, 137; 136, identifier:open; 137, argument_list; 137, 138; 137, 147; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:os; 142, identifier:path; 143, identifier:join; 144, argument_list; 144, 145; 144, 146; 145, identifier:work_dir; 146, string:'mhci_alleles.list'; 147, string:'w'; 148, as_pattern_target; 148, 149; 149, identifier:mhci_file; 150, line_continuation:\; 151, with_item; 151, 152; 152, as_pattern; 152, 153; 152, 166; 153, call; 153, 154; 153, 155; 154, identifier:open; 155, argument_list; 155, 156; 155, 165; 156, call; 156, 157; 156, 162; 157, attribute; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:os; 160, identifier:path; 161, identifier:join; 162, argument_list; 162, 163; 162, 164; 163, identifier:work_dir; 164, string:'mhcii_alleles.list'; 165, string:'w'; 166, as_pattern_target; 166, 167; 167, identifier:mhcii_file; 168, block; 168, 169; 168, 209; 168, 218; 168, 242; 168, 251; 168, 260; 169, for_statement; 169, 170; 169, 171; 169, 175; 170, identifier:mhci_group; 171, list:['HLA_A', 'HLA_B', 'HLA_C']; 171, 172; 171, 173; 171, 174; 172, string:'HLA_A'; 173, string:'HLA_B'; 174, string:'HLA_C'; 175, block; 175, 176; 175, 185; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:mpa; 179, call; 179, 180; 179, 181; 180, identifier:most_probable_alleles; 181, argument_list; 181, 182; 182, subscript; 182, 183; 182, 184; 183, identifier:mhc_alleles; 184, identifier:mhci_group; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:print; 188, argument_list; 188, 189; 188, 206; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, string:'\n'; 192, identifier:join; 193, argument_list; 193, 194; 194, list_comprehension; 194, 195; 194, 203; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, string:''; 198, identifier:join; 199, argument_list; 199, 200; 200, list:['HLA-', x]; 200, 201; 200, 202; 201, string:'HLA-'; 202, identifier:x; 203, for_in_clause; 203, 204; 203, 205; 204, identifier:x; 205, identifier:mpa; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:file; 208, identifier:mhci_file; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:drb_mpa; 212, call; 212, 213; 212, 214; 213, identifier:most_probable_alleles; 214, argument_list; 214, 215; 215, subscript; 215, 216; 215, 217; 216, identifier:mhc_alleles; 217, string:'HLA_DRB'; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 221; 220, identifier:print; 221, argument_list; 221, 222; 221, 239; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, string:'\n'; 225, identifier:join; 226, argument_list; 226, 227; 227, list_comprehension; 227, 228; 227, 236; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, string:''; 231, identifier:join; 232, argument_list; 232, 233; 233, list:['HLA-', x]; 233, 234; 233, 235; 234, string:'HLA-'; 235, identifier:x; 236, for_in_clause; 236, 237; 236, 238; 237, identifier:x; 238, identifier:drb_mpa; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:file; 241, identifier:mhcii_file; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:dqa_mpa; 245, call; 245, 246; 245, 247; 246, identifier:most_probable_alleles; 247, argument_list; 247, 248; 248, subscript; 248, 249; 248, 250; 249, identifier:mhc_alleles; 250, string:'HLA_DQA'; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:dqb_mpa; 254, call; 254, 255; 254, 256; 255, identifier:most_probable_alleles; 256, argument_list; 256, 257; 257, subscript; 257, 258; 257, 259; 258, identifier:mhc_alleles; 259, string:'HLA_DQB'; 260, for_statement; 260, 261; 260, 262; 260, 263; 261, identifier:dqa_allele; 262, identifier:dqa_mpa; 263, block; 263, 264; 264, for_statement; 264, 265; 264, 266; 264, 267; 265, identifier:dqb_allele; 266, identifier:dqb_mpa; 267, block; 267, 268; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 271; 270, identifier:print; 271, argument_list; 271, 272; 271, 282; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, string:''; 275, identifier:join; 276, argument_list; 276, 277; 277, list:['HLA-', dqa_allele, '/', dqb_allele]; 277, 278; 277, 279; 277, 280; 277, 281; 278, string:'HLA-'; 279, identifier:dqa_allele; 280, string:'/'; 281, identifier:dqb_allele; 282, keyword_argument; 282, 283; 282, 284; 283, identifier:file; 284, identifier:mhcii_file; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:output_files; 288, call; 288, 289; 288, 290; 289, identifier:defaultdict; 290, argument_list; 291, for_statement; 291, 292; 291, 293; 291, 296; 292, identifier:allele_file; 293, list:['mhci_alleles.list', 'mhcii_alleles.list']; 293, 294; 293, 295; 294, string:'mhci_alleles.list'; 295, string:'mhcii_alleles.list'; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 302; 299, subscript; 299, 300; 299, 301; 300, identifier:output_files; 301, identifier:allele_file; 302, call; 302, 303; 302, 308; 303, attribute; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:job; 306, identifier:fileStore; 307, identifier:writeGlobalFile; 308, argument_list; 308, 309; 309, call; 309, 310; 309, 315; 310, attribute; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:os; 313, identifier:path; 314, identifier:join; 315, argument_list; 315, 316; 315, 317; 316, identifier:work_dir; 317, identifier:allele_file; 318, return_statement; 318, 319; 319, identifier:output_files | def merge_phlat_calls(job, tumor_phlat, normal_phlat, rna_phlat):
job.fileStore.logToMaster('Merging Phlat calls')
work_dir = job.fileStore.getLocalTempDir()
input_files = {
'tumor_dna': tumor_phlat,
'normal_dna': normal_phlat,
'tumor_rna': rna_phlat}
input_files = get_files_from_filestore(job, input_files, work_dir)
with open(input_files['tumor_dna'], 'r') as td_file, \
open(input_files['normal_dna'], 'r') as nd_file, \
open(input_files['tumor_rna'], 'r') as tr_file:
mhc_alleles = {'HLA_A': [], 'HLA_B': [], 'HLA_C': [], 'HLA_DPA': [], 'HLA_DQA': [],
'HLA_DPB': [], 'HLA_DQB': [], 'HLA_DRB': []}
for phlatfile in td_file, nd_file, tr_file:
mhc_alleles = parse_phlat_file(phlatfile, mhc_alleles)
with open(os.path.join(work_dir, 'mhci_alleles.list'), 'w') as mhci_file, \
open(os.path.join(work_dir, 'mhcii_alleles.list'), 'w') as mhcii_file:
for mhci_group in ['HLA_A', 'HLA_B', 'HLA_C']:
mpa = most_probable_alleles(mhc_alleles[mhci_group])
print('\n'.join([''.join(['HLA-', x]) for x in mpa]), file=mhci_file)
drb_mpa = most_probable_alleles(mhc_alleles['HLA_DRB'])
print('\n'.join([''.join(['HLA-', x]) for x in drb_mpa]), file=mhcii_file)
dqa_mpa = most_probable_alleles(mhc_alleles['HLA_DQA'])
dqb_mpa = most_probable_alleles(mhc_alleles['HLA_DQB'])
for dqa_allele in dqa_mpa:
for dqb_allele in dqb_mpa:
print(''.join(['HLA-', dqa_allele, '/', dqb_allele]), file=mhcii_file)
output_files = defaultdict()
for allele_file in ['mhci_alleles.list', 'mhcii_alleles.list']:
output_files[allele_file] = job.fileStore.writeGlobalFile(os.path.join(work_dir,
allele_file))
return output_files |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:docker_call; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:tool; 5, identifier:tool_parameters; 6, identifier:work_dir; 7, default_parameter; 7, 8; 7, 9; 8, identifier:java_opts; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:outfile; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:dockerhub; 15, string:'aarjunrao'; 16, default_parameter; 16, 17; 16, 18; 17, identifier:interactive; 18, False; 19, block; 19, 20; 19, 47; 19, 60; 19, 91; 19, 97; 19, 106; 19, 139; 19, 207; 19, 245; 19, 258; 20, if_statement; 20, 21; 20, 22; 21, identifier:outfile; 22, block; 22, 23; 22, 30; 22, 41; 23, assert_statement; 23, 24; 23, 29; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 28; 27, identifier:outfile; 28, identifier:file; 29, string:'outfile was not passsed a file'; 30, assert_statement; 30, 31; 30, 40; 31, comparison_operator:in; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:outfile; 34, identifier:mode; 35, list:['w', 'a', 'wb', 'ab']; 35, 36; 35, 37; 35, 38; 35, 39; 36, string:'w'; 37, string:'a'; 38, string:'wb'; 39, string:'ab'; 40, string:'outfile not writeable'; 41, assert_statement; 41, 42; 41, 46; 42, not_operator; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:outfile; 45, identifier:closed; 46, string:'outfile is closed'; 47, if_statement; 47, 48; 47, 49; 47, 54; 48, identifier:interactive; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:interactive; 53, string:'-i'; 54, else_clause; 54, 55; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:interactive; 59, string:''; 60, if_statement; 60, 61; 60, 64; 60, 76; 61, comparison_operator:in; 61, 62; 61, 63; 62, string:':'; 63, identifier:tool; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:docker_tool; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, string:'/'; 71, identifier:join; 72, argument_list; 72, 73; 73, list:[dockerhub, tool]; 73, 74; 73, 75; 74, identifier:dockerhub; 75, identifier:tool; 76, else_clause; 76, 77; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:docker_tool; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, string:''; 84, identifier:join; 85, argument_list; 85, 86; 86, list:[dockerhub, '/', tool, ':latest']; 86, 87; 86, 88; 86, 89; 86, 90; 87, identifier:dockerhub; 88, string:'/'; 89, identifier:tool; 90, string:':latest'; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:call; 94, list:['docker', 'images']; 94, 95; 94, 96; 95, string:'docker'; 96, string:'images'; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:dimg_rv; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:subprocess; 103, identifier:check_output; 104, argument_list; 104, 105; 105, identifier:call; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:existing_images; 109, list_comprehension; 109, 110; 109, 125; 109, 132; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, string:':'; 113, identifier:join; 114, argument_list; 114, 115; 115, subscript; 115, 116; 115, 121; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:x; 119, identifier:split; 120, argument_list; 121, slice; 121, 122; 121, 123; 121, 124; 122, integer:0; 123, colon; 124, integer:2; 125, for_in_clause; 125, 126; 125, 127; 126, identifier:x; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:dimg_rv; 130, identifier:splitlines; 131, argument_list; 132, if_clause; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:x; 136, identifier:startswith; 137, argument_list; 137, 138; 138, identifier:dockerhub; 139, if_statement; 139, 140; 139, 143; 140, comparison_operator:not; 140, 141; 140, 142; 141, identifier:docker_tool; 142, identifier:existing_images; 143, block; 143, 144; 144, try_statement; 144, 145; 144, 169; 144, 197; 145, block; 145, 146; 145, 162; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:call; 149, call; 149, 150; 149, 161; 150, attribute; 150, 151; 150, 160; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, string:' '; 154, identifier:join; 155, argument_list; 155, 156; 156, list:['docker', 'pull', docker_tool]; 156, 157; 156, 158; 156, 159; 157, string:'docker'; 158, string:'pull'; 159, identifier:docker_tool; 160, identifier:split; 161, argument_list; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:subprocess; 166, identifier:check_call; 167, argument_list; 167, 168; 168, identifier:call; 169, except_clause; 169, 170; 169, 176; 170, as_pattern; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:subprocess; 173, identifier:CalledProcessError; 174, as_pattern_target; 174, 175; 175, identifier:err; 176, block; 176, 177; 177, raise_statement; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:RuntimeError; 180, argument_list; 180, 181; 181, binary_operator:+; 181, 182; 181, 189; 182, binary_operator:+; 182, 183; 182, 184; 183, string:'docker command returned a non-zero exit status '; 184, binary_operator:%; 184, 185; 184, 186; 185, string:'(%s)'; 186, attribute; 186, 187; 186, 188; 187, identifier:err; 188, identifier:returncode; 189, binary_operator:%; 189, 190; 189, 191; 190, string:'for command \"%s\"'; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, string:' '; 194, identifier:join; 195, argument_list; 195, 196; 196, identifier:call; 197, except_clause; 197, 198; 197, 199; 198, identifier:OSError; 199, block; 199, 200; 200, raise_statement; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:RuntimeError; 203, argument_list; 203, 204; 204, binary_operator:+; 204, 205; 204, 206; 205, string:'docker not found on system. Install on all'; 206, string:' nodes.'; 207, if_statement; 207, 208; 207, 209; 207, 230; 208, identifier:java_opts; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:base_docker_call; 213, binary_operator:+; 213, 214; 213, 229; 214, binary_operator:+; 214, 215; 214, 223; 215, binary_operator:+; 215, 216; 215, 222; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, string:' docker run -e JAVA_OPTS=-Xmx{} '; 219, identifier:format; 220, argument_list; 220, 221; 221, identifier:java_opts; 222, string:'--rm=true '; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, string:'-v {}:/data --log-driver=none '; 226, identifier:format; 227, argument_list; 227, 228; 228, identifier:work_dir; 229, identifier:interactive; 230, else_clause; 230, 231; 231, block; 231, 232; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:base_docker_call; 235, binary_operator:+; 235, 236; 235, 244; 236, binary_operator:+; 236, 237; 236, 243; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, string:' docker run --rm=true -v {}:/data '; 240, identifier:format; 241, argument_list; 241, 242; 242, identifier:work_dir; 243, string:'--log-driver=none '; 244, identifier:interactive; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:call; 248, binary_operator:+; 248, 249; 248, 257; 249, binary_operator:+; 249, 250; 249, 255; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:base_docker_call; 253, identifier:split; 254, argument_list; 255, list:[docker_tool]; 255, 256; 256, identifier:docker_tool; 257, identifier:tool_parameters; 258, try_statement; 258, 259; 258, 270; 258, 296; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:subprocess; 264, identifier:check_call; 265, argument_list; 265, 266; 265, 267; 266, identifier:call; 267, keyword_argument; 267, 268; 267, 269; 268, identifier:stdout; 269, identifier:outfile; 270, except_clause; 270, 271; 270, 277; 271, as_pattern; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:subprocess; 274, identifier:CalledProcessError; 275, as_pattern_target; 275, 276; 276, identifier:err; 277, block; 277, 278; 278, raise_statement; 278, 279; 279, call; 279, 280; 279, 281; 280, identifier:RuntimeError; 281, argument_list; 281, 282; 282, binary_operator:+; 282, 283; 282, 288; 283, binary_operator:%; 283, 284; 283, 285; 284, string:'docker command returned a non-zero exit status (%s)'; 285, attribute; 285, 286; 285, 287; 286, identifier:err; 287, identifier:returncode; 288, binary_operator:%; 288, 289; 288, 290; 289, string:'for command \"%s\"'; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, string:' '; 293, identifier:join; 294, argument_list; 294, 295; 295, identifier:call; 296, except_clause; 296, 297; 296, 298; 297, identifier:OSError; 298, block; 298, 299; 299, raise_statement; 299, 300; 300, call; 300, 301; 300, 302; 301, identifier:RuntimeError; 302, argument_list; 302, 303; 303, string:'docker not found on system. Install on all nodes.' | def docker_call(tool, tool_parameters, work_dir, java_opts=None, outfile=None,
dockerhub='aarjunrao', interactive=False):
if outfile:
assert isinstance(outfile, file), 'outfile was not passsed a file'
assert outfile.mode in ['w', 'a', 'wb', 'ab'], 'outfile not writeable'
assert not outfile.closed, 'outfile is closed'
if interactive:
interactive = '-i'
else:
interactive = ''
if ':' in tool:
docker_tool = '/'.join([dockerhub, tool])
else:
docker_tool = ''.join([dockerhub, '/', tool, ':latest'])
call = ['docker', 'images']
dimg_rv = subprocess.check_output(call)
existing_images = [':'.join(x.split()[0:2]) for x in dimg_rv.splitlines()
if x.startswith(dockerhub)]
if docker_tool not in existing_images:
try:
call = ' '.join(['docker', 'pull', docker_tool]).split()
subprocess.check_call(call)
except subprocess.CalledProcessError as err:
raise RuntimeError('docker command returned a non-zero exit status ' +
'(%s)' % err.returncode + 'for command \"%s\"' % ' '.join(call),)
except OSError:
raise RuntimeError('docker not found on system. Install on all' +
' nodes.')
if java_opts:
base_docker_call = ' docker run -e JAVA_OPTS=-Xmx{} '.format(java_opts) + '--rm=true ' + \
'-v {}:/data --log-driver=none '.format(work_dir) + interactive
else:
base_docker_call = ' docker run --rm=true -v {}:/data '.format(work_dir) + \
'--log-driver=none ' + interactive
call = base_docker_call.split() + [docker_tool] + tool_parameters
try:
subprocess.check_call(call, stdout=outfile)
except subprocess.CalledProcessError as err:
raise RuntimeError('docker command returned a non-zero exit status (%s)' % err.returncode +
'for command \"%s\"' % ' '.join(call),)
except OSError:
raise RuntimeError('docker not found on system. Install on all nodes.') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_file_from_gdc; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:job; 5, identifier:gdc_url; 6, identifier:gdc_download_token; 7, default_parameter; 7, 8; 7, 9; 8, identifier:write_to_jobstore; 9, True; 10, block; 10, 11; 10, 21; 10, 28; 10, 37; 10, 50; 10, 58; 10, 65; 10, 94; 10, 103; 10, 132; 10, 219; 10, 237; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:work_dir; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:job; 18, identifier:fileStore; 19, identifier:getLocalTempDir; 20, argument_list; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:parsed_url; 24, call; 24, 25; 24, 26; 25, identifier:urlparse; 26, argument_list; 26, 27; 27, identifier:gdc_url; 28, assert_statement; 28, 29; 28, 34; 29, comparison_operator:==; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:parsed_url; 32, identifier:scheme; 33, string:'gdc'; 34, binary_operator:%; 34, 35; 34, 36; 35, string:'Unexpected url scheme: %s'; 36, identifier:gdc_url; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:file_dir; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, string:'/'; 43, identifier:join; 44, argument_list; 44, 45; 45, list:[work_dir, parsed_url.netloc]; 45, 46; 45, 47; 46, identifier:work_dir; 47, attribute; 47, 48; 47, 49; 48, identifier:parsed_url; 49, identifier:netloc; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:currwd; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:os; 56, identifier:getcwd; 57, argument_list; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:os; 62, identifier:chdir; 63, argument_list; 63, 64; 64, identifier:work_dir; 65, try_statement; 65, 66; 65, 85; 66, block; 66, 67; 66, 78; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:download_call; 70, list:['gdc-client', 'download', '-t', gdc_download_token, parsed_url.netloc]; 70, 71; 70, 72; 70, 73; 70, 74; 70, 75; 71, string:'gdc-client'; 72, string:'download'; 73, string:'-t'; 74, identifier:gdc_download_token; 75, attribute; 75, 76; 75, 77; 76, identifier:parsed_url; 77, identifier:netloc; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:subprocess; 82, identifier:check_call; 83, argument_list; 83, 84; 84, identifier:download_call; 85, finally_clause; 85, 86; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:os; 91, identifier:chdir; 92, argument_list; 92, 93; 93, identifier:currwd; 94, assert_statement; 94, 95; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:os; 99, identifier:path; 100, identifier:exists; 101, argument_list; 101, 102; 102, identifier:file_dir; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:output_files; 106, list_comprehension; 106, 107; 106, 116; 106, 124; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:os; 111, identifier:path; 112, identifier:join; 113, argument_list; 113, 114; 113, 115; 114, identifier:file_dir; 115, identifier:x; 116, for_in_clause; 116, 117; 116, 118; 117, identifier:x; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:os; 121, identifier:listdir; 122, argument_list; 122, 123; 123, identifier:file_dir; 124, if_clause; 124, 125; 125, not_operator; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:x; 129, identifier:endswith; 130, argument_list; 130, 131; 131, string:'logs'; 132, if_statement; 132, 133; 132, 139; 132, 149; 133, comparison_operator:==; 133, 134; 133, 138; 134, call; 134, 135; 134, 136; 135, identifier:len; 136, argument_list; 136, 137; 137, identifier:output_files; 138, integer:1; 139, block; 139, 140; 140, assert_statement; 140, 141; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:output_files; 145, integer:0; 146, identifier:endswith; 147, argument_list; 147, 148; 148, string:'vcf'; 149, else_clause; 149, 150; 150, block; 150, 151; 150, 177; 150, 194; 151, if_statement; 151, 152; 151, 171; 152, not_operator; 152, 153; 153, comparison_operator:>=; 153, 154; 153, 168; 154, set_comprehension; 154, 155; 154, 165; 155, subscript; 155, 156; 155, 164; 156, call; 156, 157; 156, 162; 157, attribute; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:os; 160, identifier:path; 161, identifier:splitext; 162, argument_list; 162, 163; 163, identifier:x; 164, integer:1; 165, for_in_clause; 165, 166; 165, 167; 166, identifier:x; 167, identifier:output_files; 168, set; 168, 169; 168, 170; 169, string:'.bam'; 170, string:'.bai'; 171, block; 171, 172; 172, raise_statement; 172, 173; 173, call; 173, 174; 173, 175; 174, identifier:ParameterError; 175, argument_list; 175, 176; 176, string:'Can currently only handle pre-indexed GDC bams.'; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:output_files; 180, list_comprehension; 180, 181; 180, 182; 180, 185; 181, identifier:x; 182, for_in_clause; 182, 183; 182, 184; 183, identifier:x; 184, identifier:output_files; 185, if_clause; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:x; 189, identifier:endswith; 190, argument_list; 190, 191; 191, tuple; 191, 192; 191, 193; 192, string:'bam'; 193, string:'bai'; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:output_files; 197, call; 197, 198; 197, 199; 198, identifier:sorted; 199, argument_list; 199, 200; 199, 201; 199, 216; 200, identifier:output_files; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:key; 203, lambda; 203, 204; 203, 206; 204, lambda_parameters; 204, 205; 205, identifier:x; 206, subscript; 206, 207; 206, 215; 207, call; 207, 208; 207, 213; 208, attribute; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:os; 211, identifier:path; 212, identifier:splitext; 213, argument_list; 213, 214; 214, identifier:x; 215, integer:1; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:reverse; 218, True; 219, if_statement; 219, 220; 219, 221; 220, identifier:write_to_jobstore; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:output_files; 225, list_comprehension; 225, 226; 225, 234; 226, call; 226, 227; 226, 232; 227, attribute; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:job; 230, identifier:fileStore; 231, identifier:writeGlobalFile; 232, argument_list; 232, 233; 233, identifier:f; 234, for_in_clause; 234, 235; 234, 236; 235, identifier:f; 236, identifier:output_files; 237, return_statement; 237, 238; 238, identifier:output_files | def get_file_from_gdc(job, gdc_url, gdc_download_token, write_to_jobstore=True):
work_dir = job.fileStore.getLocalTempDir()
parsed_url = urlparse(gdc_url)
assert parsed_url.scheme == 'gdc', 'Unexpected url scheme: %s' % gdc_url
file_dir = '/'.join([work_dir, parsed_url.netloc])
currwd = os.getcwd()
os.chdir(work_dir)
try:
download_call = ['gdc-client', 'download', '-t', gdc_download_token, parsed_url.netloc]
subprocess.check_call(download_call)
finally:
os.chdir(currwd)
assert os.path.exists(file_dir)
output_files = [os.path.join(file_dir, x) for x in os.listdir(file_dir)
if not x.endswith('logs')]
if len(output_files) == 1:
assert output_files[0].endswith('vcf')
else:
if not {os.path.splitext(x)[1] for x in output_files} >= {'.bam', '.bai'}:
raise ParameterError('Can currently only handle pre-indexed GDC bams.')
output_files = [x for x in output_files if x.endswith(('bam', 'bai'))]
output_files = sorted(output_files, key=lambda x: os.path.splitext(x)[1], reverse=True)
if write_to_jobstore:
output_files = [job.fileStore.writeGlobalFile(f) for f in output_files]
return output_files |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:make_key_hippie; 3, parameters; 3, 4; 3, 5; 4, identifier:obj; 5, default_parameter; 5, 6; 5, 7; 6, identifier:typed; 7, True; 8, block; 8, 9; 8, 19; 8, 32; 8, 46; 8, 67; 8, 102; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:ftype; 12, conditional_expression:if; 12, 13; 12, 14; 12, 15; 13, identifier:type; 14, identifier:typed; 15, lambda; 15, 16; 15, 18; 16, lambda_parameters; 16, 17; 17, identifier:o; 18, None; 19, if_statement; 19, 20; 19, 24; 20, call; 20, 21; 20, 22; 21, identifier:is_hashable; 22, argument_list; 22, 23; 23, identifier:obj; 24, block; 24, 25; 25, return_statement; 25, 26; 26, expression_list; 26, 27; 26, 28; 27, identifier:obj; 28, call; 28, 29; 28, 30; 29, identifier:ftype; 30, argument_list; 30, 31; 31, identifier:obj; 32, if_statement; 32, 33; 32, 38; 33, call; 33, 34; 33, 35; 34, identifier:isinstance; 35, argument_list; 35, 36; 35, 37; 36, identifier:obj; 37, identifier:set; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:obj; 42, call; 42, 43; 42, 44; 43, identifier:sorted; 44, argument_list; 44, 45; 45, identifier:obj; 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:obj; 51, tuple; 51, 52; 51, 53; 52, identifier:list; 53, identifier:tuple; 54, block; 54, 55; 55, return_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:tuple; 58, generator_expression; 58, 59; 58, 64; 59, call; 59, 60; 59, 61; 60, identifier:make_key_hippie; 61, argument_list; 61, 62; 61, 63; 62, identifier:e; 63, identifier:typed; 64, for_in_clause; 64, 65; 64, 66; 65, identifier:e; 66, identifier:obj; 67, if_statement; 67, 68; 67, 73; 68, call; 68, 69; 68, 70; 69, identifier:isinstance; 70, argument_list; 70, 71; 70, 72; 71, identifier:obj; 72, identifier:dict; 73, block; 73, 74; 74, return_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:tuple; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:sorted; 80, argument_list; 80, 81; 81, generator_expression; 81, 82; 81, 93; 82, tuple; 82, 83; 82, 88; 83, call; 83, 84; 83, 85; 84, identifier:make_key_hippie; 85, argument_list; 85, 86; 85, 87; 86, identifier:k; 87, identifier:typed; 88, call; 88, 89; 88, 90; 89, identifier:make_key_hippie; 90, argument_list; 90, 91; 90, 92; 91, identifier:v; 92, identifier:typed; 93, for_in_clause; 93, 94; 93, 97; 94, pattern_list; 94, 95; 94, 96; 95, identifier:k; 96, identifier:v; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:obj; 100, identifier:items; 101, argument_list; 102, raise_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:ValueError; 105, argument_list; 105, 106; 106, binary_operator:%; 106, 107; 106, 108; 107, string:"%r can not be hashed. Try providing a custom key function."; 108, identifier:obj | def make_key_hippie(obj, typed=True):
ftype = type if typed else lambda o: None
if is_hashable(obj):
return obj, ftype(obj)
if isinstance(obj, set):
obj = sorted(obj)
if isinstance(obj, (list, tuple)):
return tuple(make_key_hippie(e, typed) for e in obj)
if isinstance(obj, dict):
return tuple(sorted(((make_key_hippie(k, typed),
make_key_hippie(v, typed))
for k, v in obj.items())))
raise ValueError(
"%r can not be hashed. Try providing a custom key function."
% obj) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:run_radia; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:job; 5, identifier:rna_bam; 6, identifier:tumor_bam; 7, identifier:normal_bam; 8, identifier:univ_options; 9, identifier:radia_options; 10, block; 10, 11; 10, 48; 10, 82; 10, 105; 10, 111; 10, 198; 10, 211; 11, if_statement; 11, 12; 11, 19; 11, 26; 11, 41; 12, comparison_operator:in; 12, 13; 12, 14; 13, string:'rna_genome'; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:rna_bam; 17, identifier:keys; 18, argument_list; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:rna_bam; 23, subscript; 23, 24; 23, 25; 24, identifier:rna_bam; 25, string:'rna_genome'; 26, elif_clause; 26, 27; 26, 39; 27, comparison_operator:==; 27, 28; 27, 36; 28, call; 28, 29; 28, 30; 29, identifier:set; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:rna_bam; 34, identifier:keys; 35, argument_list; 36, set; 36, 37; 36, 38; 37, string:'rna_genome_sorted.bam'; 38, string:'rna_genome_sorted.bam.bai'; 39, block; 39, 40; 40, pass_statement; 41, else_clause; 41, 42; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:RuntimeError; 46, argument_list; 46, 47; 47, string:'An improperly formatted dict was passed to rna_bam.'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:bams; 51, dictionary; 51, 52; 51, 57; 51, 62; 51, 67; 51, 72; 51, 77; 52, pair; 52, 53; 52, 54; 53, string:'tumor_rna'; 54, subscript; 54, 55; 54, 56; 55, identifier:rna_bam; 56, string:'rna_genome_sorted.bam'; 57, pair; 57, 58; 57, 59; 58, string:'tumor_rnai'; 59, subscript; 59, 60; 59, 61; 60, identifier:rna_bam; 61, string:'rna_genome_sorted.bam.bai'; 62, pair; 62, 63; 62, 64; 63, string:'tumor_dna'; 64, subscript; 64, 65; 64, 66; 65, identifier:tumor_bam; 66, string:'tumor_dna_fix_pg_sorted.bam'; 67, pair; 67, 68; 67, 69; 68, string:'tumor_dnai'; 69, subscript; 69, 70; 69, 71; 70, identifier:tumor_bam; 71, string:'tumor_dna_fix_pg_sorted.bam.bai'; 72, pair; 72, 73; 72, 74; 73, string:'normal_dna'; 74, subscript; 74, 75; 74, 76; 75, identifier:normal_bam; 76, string:'normal_dna_fix_pg_sorted.bam'; 77, pair; 77, 78; 77, 79; 78, string:'normal_dnai'; 79, subscript; 79, 80; 79, 81; 80, identifier:normal_bam; 81, string:'normal_dna_fix_pg_sorted.bam.bai'; 82, if_statement; 82, 83; 82, 86; 82, 93; 83, subscript; 83, 84; 83, 85; 84, identifier:radia_options; 85, string:'chromosomes'; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:chromosomes; 90, subscript; 90, 91; 90, 92; 91, identifier:radia_options; 92, string:'chromosomes'; 93, else_clause; 93, 94; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:chromosomes; 98, call; 98, 99; 98, 100; 99, identifier:sample_chromosomes; 100, argument_list; 100, 101; 100, 102; 101, identifier:job; 102, subscript; 102, 103; 102, 104; 103, identifier:radia_options; 104, string:'genome_fai'; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:perchrom_radia; 108, call; 108, 109; 108, 110; 109, identifier:defaultdict; 110, argument_list; 111, for_statement; 111, 112; 111, 113; 111, 114; 112, identifier:chrom; 113, identifier:chromosomes; 114, block; 114, 115; 114, 149; 114, 188; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:radia; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:job; 121, identifier:addChildJobFn; 122, argument_list; 122, 123; 122, 124; 122, 125; 122, 126; 122, 127; 122, 128; 122, 131; 123, identifier:run_radia_perchrom; 124, identifier:bams; 125, identifier:univ_options; 126, identifier:radia_options; 127, identifier:chrom; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:memory; 130, string:'6G'; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:disk; 133, call; 133, 134; 133, 135; 134, identifier:PromisedRequirement; 135, argument_list; 135, 136; 135, 137; 135, 140; 135, 143; 135, 146; 136, identifier:radia_disk; 137, subscript; 137, 138; 137, 139; 138, identifier:tumor_bam; 139, string:'tumor_dna_fix_pg_sorted.bam'; 140, subscript; 140, 141; 140, 142; 141, identifier:normal_bam; 142, string:'normal_dna_fix_pg_sorted.bam'; 143, subscript; 143, 144; 143, 145; 144, identifier:rna_bam; 145, string:'rna_genome_sorted.bam'; 146, subscript; 146, 147; 146, 148; 147, identifier:radia_options; 148, string:'genome_fasta'; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:filter_radia; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:radia; 155, identifier:addChildJobFn; 156, argument_list; 156, 157; 156, 158; 156, 159; 156, 164; 156, 165; 156, 166; 156, 167; 156, 170; 157, identifier:run_filter_radia; 158, identifier:bams; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:radia; 162, identifier:rv; 163, argument_list; 164, identifier:univ_options; 165, identifier:radia_options; 166, identifier:chrom; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:memory; 169, string:'6G'; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:disk; 172, call; 172, 173; 172, 174; 173, identifier:PromisedRequirement; 174, argument_list; 174, 175; 174, 176; 174, 179; 174, 182; 174, 185; 175, identifier:radia_disk; 176, subscript; 176, 177; 176, 178; 177, identifier:tumor_bam; 178, string:'tumor_dna_fix_pg_sorted.bam'; 179, subscript; 179, 180; 179, 181; 180, identifier:normal_bam; 181, string:'normal_dna_fix_pg_sorted.bam'; 182, subscript; 182, 183; 182, 184; 183, identifier:rna_bam; 184, string:'rna_genome_sorted.bam'; 185, subscript; 185, 186; 185, 187; 186, identifier:radia_options; 187, string:'genome_fasta'; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, subscript; 190, 191; 190, 192; 191, identifier:perchrom_radia; 192, identifier:chrom; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:filter_radia; 196, identifier:rv; 197, argument_list; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 205; 200, attribute; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:job; 203, identifier:fileStore; 204, identifier:logToMaster; 205, argument_list; 205, 206; 206, binary_operator:%; 206, 207; 206, 208; 207, string:'Ran spawn_radia on %s successfully'; 208, subscript; 208, 209; 208, 210; 209, identifier:univ_options; 210, string:'patient'; 211, return_statement; 211, 212; 212, identifier:perchrom_radia | def run_radia(job, rna_bam, tumor_bam, normal_bam, univ_options, radia_options):
if 'rna_genome' in rna_bam.keys():
rna_bam = rna_bam['rna_genome']
elif set(rna_bam.keys()) == {'rna_genome_sorted.bam', 'rna_genome_sorted.bam.bai'}:
pass
else:
raise RuntimeError('An improperly formatted dict was passed to rna_bam.')
bams = {'tumor_rna': rna_bam['rna_genome_sorted.bam'],
'tumor_rnai': rna_bam['rna_genome_sorted.bam.bai'],
'tumor_dna': tumor_bam['tumor_dna_fix_pg_sorted.bam'],
'tumor_dnai': tumor_bam['tumor_dna_fix_pg_sorted.bam.bai'],
'normal_dna': normal_bam['normal_dna_fix_pg_sorted.bam'],
'normal_dnai': normal_bam['normal_dna_fix_pg_sorted.bam.bai']}
if radia_options['chromosomes']:
chromosomes = radia_options['chromosomes']
else:
chromosomes = sample_chromosomes(job, radia_options['genome_fai'])
perchrom_radia = defaultdict()
for chrom in chromosomes:
radia = job.addChildJobFn(run_radia_perchrom, bams, univ_options, radia_options, chrom,
memory='6G',
disk=PromisedRequirement(
radia_disk, tumor_bam['tumor_dna_fix_pg_sorted.bam'],
normal_bam['normal_dna_fix_pg_sorted.bam'],
rna_bam['rna_genome_sorted.bam'],
radia_options['genome_fasta']))
filter_radia = radia.addChildJobFn(run_filter_radia, bams, radia.rv(), univ_options,
radia_options, chrom, memory='6G',
disk=PromisedRequirement(
radia_disk, tumor_bam['tumor_dna_fix_pg_sorted.bam'],
normal_bam['normal_dna_fix_pg_sorted.bam'],
rna_bam['rna_genome_sorted.bam'],
radia_options['genome_fasta']))
perchrom_radia[chrom] = filter_radia.rv()
job.fileStore.logToMaster('Ran spawn_radia on %s successfully' % univ_options['patient'])
return perchrom_radia |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_bamfile; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:job; 5, identifier:bamfile; 6, identifier:sample_type; 7, identifier:univ_options; 8, identifier:samtools_options; 9, block; 9, 10; 9, 18; 9, 29; 9, 40; 9, 47; 9, 59; 9, 83; 9, 106; 9, 115; 9, 130; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:work_dir; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:os; 16, identifier:getcwd; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:in_bamfile; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, string:''; 24, identifier:join; 25, argument_list; 25, 26; 26, list:[sample_type, '.bam']; 26, 27; 26, 28; 27, identifier:sample_type; 28, string:'.bam'; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:out_bamfile; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, string:'_'; 35, identifier:join; 36, argument_list; 36, 37; 37, list:[sample_type, 'sorted.bam']; 37, 38; 37, 39; 38, identifier:sample_type; 39, string:'sorted.bam'; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:input_files; 43, dictionary; 43, 44; 44, pair; 44, 45; 44, 46; 45, identifier:in_bamfile; 46, identifier:bamfile; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:input_files; 50, call; 50, 51; 50, 52; 51, identifier:get_files_from_filestore; 52, argument_list; 52, 53; 52, 54; 52, 55; 52, 56; 53, identifier:job; 54, identifier:input_files; 55, identifier:work_dir; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:docker; 58, True; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:parameters; 62, list:['sort',
'-o', docker_path(out_bamfile),
'-O', 'bam',
'-T', 'temp_sorted',
'-@', str(samtools_options['n']),
input_files[in_bamfile]]; 62, 63; 62, 64; 62, 65; 62, 69; 62, 70; 62, 71; 62, 72; 62, 73; 62, 74; 62, 80; 63, string:'sort'; 64, string:'-o'; 65, call; 65, 66; 65, 67; 66, identifier:docker_path; 67, argument_list; 67, 68; 68, identifier:out_bamfile; 69, string:'-O'; 70, string:'bam'; 71, string:'-T'; 72, string:'temp_sorted'; 73, string:'-@'; 74, call; 74, 75; 74, 76; 75, identifier:str; 76, argument_list; 76, 77; 77, subscript; 77, 78; 77, 79; 78, identifier:samtools_options; 79, string:'n'; 80, subscript; 80, 81; 80, 82; 81, identifier:input_files; 82, identifier:in_bamfile; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:docker_call; 86, argument_list; 86, 87; 86, 90; 86, 93; 86, 96; 86, 101; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:tool; 89, string:'samtools'; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:tool_parameters; 92, identifier:parameters; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:work_dir; 95, identifier:work_dir; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:dockerhub; 98, subscript; 98, 99; 98, 100; 99, identifier:univ_options; 100, string:'dockerhub'; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:tool_version; 103, subscript; 103, 104; 103, 105; 104, identifier:samtools_options; 105, string:'version'; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:job; 111, identifier:fileStore; 112, identifier:deleteGlobalFile; 113, argument_list; 113, 114; 114, identifier:bamfile; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:job; 120, identifier:fileStore; 121, identifier:logToMaster; 122, argument_list; 122, 123; 123, binary_operator:%; 123, 124; 123, 125; 124, string:'Ran samtools-sort on %s:%s successfully'; 125, tuple; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:univ_options; 128, string:'patient'; 129, identifier:sample_type; 130, return_statement; 130, 131; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:job; 135, identifier:fileStore; 136, identifier:writeGlobalFile; 137, argument_list; 137, 138; 138, identifier:out_bamfile | def sort_bamfile(job, bamfile, sample_type, univ_options, samtools_options):
work_dir = os.getcwd()
in_bamfile = ''.join([sample_type, '.bam'])
out_bamfile = '_'.join([sample_type, 'sorted.bam'])
input_files = {
in_bamfile: bamfile}
input_files = get_files_from_filestore(job, input_files, work_dir, docker=True)
parameters = ['sort',
'-o', docker_path(out_bamfile),
'-O', 'bam',
'-T', 'temp_sorted',
'-@', str(samtools_options['n']),
input_files[in_bamfile]]
docker_call(tool='samtools', tool_parameters=parameters, work_dir=work_dir,
dockerhub=univ_options['dockerhub'], tool_version=samtools_options['version'])
job.fileStore.deleteGlobalFile(bamfile)
job.fileStore.logToMaster('Ran samtools-sort on %s:%s successfully'
% (univ_options['patient'], sample_type))
return job.fileStore.writeGlobalFile(out_bamfile) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:recursive_sort; 3, parameters; 3, 4; 4, identifier:data_structure; 5, block; 5, 6; 5, 175; 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:data_structure; 12, identifier:_primitive_types; 13, block; 13, 14; 13, 22; 13, 30; 13, 77; 13, 82; 13, 94; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:is_meta; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:data_structure; 21, identifier:Meta; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:was_dict; 25, call; 25, 26; 25, 27; 26, identifier:isinstance; 27, argument_list; 27, 28; 27, 29; 28, identifier:data_structure; 29, identifier:WasDict; 30, if_statement; 30, 31; 30, 36; 31, not_operator; 31, 32; 32, parenthesized_expression; 32, 33; 33, boolean_operator:or; 33, 34; 33, 35; 34, identifier:is_meta; 35, identifier:was_dict; 36, block; 36, 37; 36, 45; 36, 64; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:was_dict; 40, call; 40, 41; 40, 42; 41, identifier:isinstance; 42, argument_list; 42, 43; 42, 44; 43, identifier:data_structure; 44, identifier:dict; 45, if_statement; 45, 46; 45, 48; 46, not_operator; 46, 47; 47, identifier:was_dict; 48, block; 48, 49; 49, try_statement; 49, 50; 49, 61; 50, block; 50, 51; 50, 57; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:data_structure; 54, attribute; 54, 55; 54, 56; 55, identifier:data_structure; 56, identifier:__dict__; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:was_dict; 60, True; 61, except_clause; 61, 62; 62, block; 62, 63; 63, pass_statement; 64, try_statement; 64, 65; 64, 74; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:data_structure; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:data_structure; 72, identifier:items; 73, argument_list; 74, except_clause; 74, 75; 75, block; 75, 76; 76, pass_statement; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:tlen; 80, unary_operator:-; 80, 81; 81, integer:1; 82, try_statement; 82, 83; 82, 91; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:tlen; 87, call; 87, 88; 87, 89; 88, identifier:len; 89, argument_list; 89, 90; 90, identifier:data_structure; 91, except_clause; 91, 92; 92, block; 92, 93; 93, pass_statement; 94, if_statement; 94, 95; 94, 99; 95, comparison_operator:!=; 95, 96; 95, 97; 96, identifier:tlen; 97, unary_operator:-; 97, 98; 98, integer:1; 99, block; 99, 100; 100, try_statement; 100, 101; 100, 172; 101, block; 101, 102; 102, if_statement; 102, 103; 102, 104; 102, 132; 102, 152; 103, identifier:was_dict; 104, block; 104, 105; 105, return_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:tuple; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:sorted; 111, argument_list; 111, 112; 111, 129; 112, list_comprehension; 112, 113; 112, 126; 113, tuple; 113, 114; 113, 120; 114, call; 114, 115; 114, 116; 115, identifier:recursive_sort; 116, argument_list; 116, 117; 117, subscript; 117, 118; 117, 119; 118, identifier:x; 119, integer:0; 120, call; 120, 121; 120, 122; 121, identifier:recursive_sort; 122, argument_list; 122, 123; 123, subscript; 123, 124; 123, 125; 124, identifier:x; 125, integer:1; 126, for_in_clause; 126, 127; 126, 128; 127, identifier:x; 128, identifier:data_structure; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:key; 131, identifier:TraversalBasedReprCompare; 132, elif_clause; 132, 133; 132, 134; 133, identifier:is_meta; 134, block; 134, 135; 135, return_statement; 135, 136; 136, binary_operator:+; 136, 137; 136, 144; 137, subscript; 137, 138; 137, 139; 138, identifier:data_structure; 139, slice; 139, 140; 139, 141; 139, 142; 140, integer:0; 141, colon; 142, unary_operator:-; 142, 143; 143, integer:1; 144, list:[
recursive_sort(
data_structure[-1]
)
]; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:recursive_sort; 147, argument_list; 147, 148; 148, subscript; 148, 149; 148, 150; 149, identifier:data_structure; 150, unary_operator:-; 150, 151; 151, integer:1; 152, else_clause; 152, 153; 153, block; 153, 154; 154, return_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:tuple; 157, argument_list; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:sorted; 160, argument_list; 160, 161; 160, 169; 161, list_comprehension; 161, 162; 161, 166; 162, call; 162, 163; 162, 164; 163, identifier:recursive_sort; 164, argument_list; 164, 165; 165, identifier:x; 166, for_in_clause; 166, 167; 166, 168; 167, identifier:x; 168, identifier:data_structure; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:key; 171, identifier:TraversalBasedReprCompare; 172, except_clause; 172, 173; 173, block; 173, 174; 174, pass_statement; 175, return_statement; 175, 176; 176, identifier:data_structure | def recursive_sort(data_structure):
if not isinstance(data_structure, _primitive_types):
is_meta = isinstance(data_structure, Meta)
was_dict = isinstance(data_structure, WasDict)
if not (is_meta or was_dict):
was_dict = isinstance(data_structure, dict)
if not was_dict:
try:
data_structure = data_structure.__dict__
was_dict = True
except:
pass
try:
data_structure = data_structure.items()
except:
pass
tlen = -1
try:
tlen = len(data_structure)
except:
pass
if tlen != -1:
try:
if was_dict:
return tuple(sorted(
[
(
recursive_sort(x[0]),
recursive_sort(x[1]),
)
for x in data_structure
],
key=TraversalBasedReprCompare
))
elif is_meta:
return data_structure[0:-1] + [
recursive_sort(
data_structure[-1]
)
]
else:
return tuple(sorted(
[recursive_sort(
x,
) for x in data_structure],
key=TraversalBasedReprCompare,
))
except:
pass
return data_structure |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:tree_diff; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:a; 5, identifier:b; 6, default_parameter; 6, 7; 6, 8; 7, identifier:n; 8, integer:5; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, False; 12, block; 12, 13; 12, 20; 12, 27; 12, 87; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:a; 16, call; 16, 17; 16, 18; 17, identifier:dump; 18, argument_list; 18, 19; 19, identifier:a; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:b; 23, call; 23, 24; 23, 25; 24, identifier:dump; 25, argument_list; 25, 26; 26, identifier:b; 27, if_statement; 27, 28; 27, 30; 27, 55; 28, not_operator; 28, 29; 29, identifier:sort; 30, block; 30, 31; 30, 43; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:a; 34, call; 34, 35; 34, 41; 35, attribute; 35, 36; 35, 40; 36, call; 36, 37; 36, 38; 37, identifier:vformat; 38, argument_list; 38, 39; 39, identifier:a; 40, identifier:split; 41, argument_list; 41, 42; 42, string:"\n"; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:b; 46, call; 46, 47; 46, 53; 47, attribute; 47, 48; 47, 52; 48, call; 48, 49; 48, 50; 49, identifier:vformat; 50, argument_list; 50, 51; 51, identifier:b; 52, identifier:split; 53, argument_list; 53, 54; 54, string:"\n"; 55, else_clause; 55, 56; 56, block; 56, 57; 56, 72; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:a; 60, call; 60, 61; 60, 70; 61, attribute; 61, 62; 61, 69; 62, call; 62, 63; 62, 64; 63, identifier:vformat; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:recursive_sort; 67, argument_list; 67, 68; 68, identifier:a; 69, identifier:split; 70, argument_list; 70, 71; 71, string:"\n"; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:b; 75, call; 75, 76; 75, 85; 76, attribute; 76, 77; 76, 84; 77, call; 77, 78; 77, 79; 78, identifier:vformat; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:recursive_sort; 82, argument_list; 82, 83; 83, identifier:b; 84, identifier:split; 85, argument_list; 85, 86; 86, string:"\n"; 87, return_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, string:"\n"; 91, identifier:join; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:difflib; 96, identifier:unified_diff; 97, argument_list; 97, 98; 97, 99; 97, 100; 97, 103; 98, identifier:a; 99, identifier:b; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:n; 102, identifier:n; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:lineterm; 105, string:"" | def tree_diff(a, b, n=5, sort=False):
a = dump(a)
b = dump(b)
if not sort:
a = vformat(a).split("\n")
b = vformat(b).split("\n")
else:
a = vformat(recursive_sort(a)).split("\n")
b = vformat(recursive_sort(b)).split("\n")
return "\n".join(difflib.unified_diff(a, b, n=n, lineterm="")) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:merge_perchrom_mutations; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:job; 5, identifier:chrom; 6, identifier:mutations; 7, identifier:univ_options; 8, block; 8, 9; 8, 17; 8, 24; 8, 31; 8, 38; 8, 45; 8, 52; 8, 59; 8, 69; 8, 79; 8, 107; 8, 117; 8, 124; 8, 305; 8, 401; 8, 414; 8, 427; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:work_dir; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:os; 15, identifier:getcwd; 16, argument_list; 17, import_from_statement; 17, 18; 17, 22; 18, dotted_name; 18, 19; 18, 20; 18, 21; 19, identifier:protect; 20, identifier:mutation_calling; 21, identifier:muse; 22, dotted_name; 22, 23; 23, identifier:process_muse_vcf; 24, import_from_statement; 24, 25; 24, 29; 25, dotted_name; 25, 26; 25, 27; 25, 28; 26, identifier:protect; 27, identifier:mutation_calling; 28, identifier:mutect; 29, dotted_name; 29, 30; 30, identifier:process_mutect_vcf; 31, import_from_statement; 31, 32; 31, 36; 32, dotted_name; 32, 33; 32, 34; 32, 35; 33, identifier:protect; 34, identifier:mutation_calling; 35, identifier:radia; 36, dotted_name; 36, 37; 37, identifier:process_radia_vcf; 38, import_from_statement; 38, 39; 38, 43; 39, dotted_name; 39, 40; 39, 41; 39, 42; 40, identifier:protect; 41, identifier:mutation_calling; 42, identifier:somaticsniper; 43, dotted_name; 43, 44; 44, identifier:process_somaticsniper_vcf; 45, import_from_statement; 45, 46; 45, 50; 46, dotted_name; 46, 47; 46, 48; 46, 49; 47, identifier:protect; 48, identifier:mutation_calling; 49, identifier:strelka; 50, dotted_name; 50, 51; 51, identifier:process_strelka_vcf; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:mutations; 56, identifier:pop; 57, argument_list; 57, 58; 58, string:'indels'; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:mutations; 63, string:'strelka_indels'; 64, subscript; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:mutations; 67, string:'strelka'; 68, string:'indels'; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:mutations; 73, string:'strelka_snvs'; 74, subscript; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:mutations; 77, string:'strelka'; 78, string:'snvs'; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:vcf_processor; 82, dictionary; 82, 83; 82, 101; 83, pair; 83, 84; 83, 85; 84, string:'snvs'; 85, dictionary; 85, 86; 85, 89; 85, 92; 85, 95; 85, 98; 86, pair; 86, 87; 86, 88; 87, string:'mutect'; 88, identifier:process_mutect_vcf; 89, pair; 89, 90; 89, 91; 90, string:'muse'; 91, identifier:process_muse_vcf; 92, pair; 92, 93; 92, 94; 93, string:'radia'; 94, identifier:process_radia_vcf; 95, pair; 95, 96; 95, 97; 96, string:'somaticsniper'; 97, identifier:process_somaticsniper_vcf; 98, pair; 98, 99; 98, 100; 99, string:'strelka_snvs'; 100, identifier:process_strelka_vcf; 101, pair; 101, 102; 101, 103; 102, string:'indels'; 103, dictionary; 103, 104; 104, pair; 104, 105; 104, 106; 105, string:'strelka_indels'; 106, identifier:process_strelka_vcf; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:majority; 110, dictionary; 110, 111; 110, 114; 111, pair; 111, 112; 111, 113; 112, string:'snvs'; 113, integer:2; 114, pair; 114, 115; 114, 116; 115, string:'indels'; 116, integer:1; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:accepted_hits; 120, call; 120, 121; 120, 122; 121, identifier:defaultdict; 122, argument_list; 122, 123; 123, identifier:dict; 124, for_statement; 124, 125; 124, 126; 124, 131; 125, identifier:mut_type; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:vcf_processor; 129, identifier:keys; 130, argument_list; 131, block; 131, 132; 131, 158; 131, 168; 131, 177; 131, 196; 131, 216; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:perchrom_mutations; 135, dictionary_comprehension; 135, 136; 135, 153; 136, pair; 136, 137; 136, 138; 137, identifier:caller; 138, call; 138, 139; 138, 144; 139, subscript; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:vcf_processor; 142, identifier:mut_type; 143, identifier:caller; 144, argument_list; 144, 145; 144, 146; 144, 151; 144, 152; 145, identifier:job; 146, subscript; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:mutations; 149, identifier:caller; 150, identifier:chrom; 151, identifier:work_dir; 152, identifier:univ_options; 153, for_in_clause; 153, 154; 153, 155; 154, identifier:caller; 155, subscript; 155, 156; 155, 157; 156, identifier:vcf_processor; 157, identifier:mut_type; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:perchrom_mutations; 162, string:'strelka'; 163, subscript; 163, 164; 163, 165; 164, identifier:perchrom_mutations; 165, binary_operator:+; 165, 166; 165, 167; 166, string:'strelka_'; 167, identifier:mut_type; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:perchrom_mutations; 172, identifier:pop; 173, argument_list; 173, 174; 174, binary_operator:+; 174, 175; 174, 176; 175, string:'strelka_'; 176, identifier:mut_type; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:vcf_lists; 180, dictionary_comprehension; 180, 181; 180, 187; 181, pair; 181, 182; 181, 183; 182, identifier:caller; 183, call; 183, 184; 183, 185; 184, identifier:read_vcf; 185, argument_list; 185, 186; 186, identifier:vcf_file; 187, for_in_clause; 187, 188; 187, 191; 188, pattern_list; 188, 189; 188, 190; 189, identifier:caller; 190, identifier:vcf_file; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:perchrom_mutations; 194, identifier:items; 195, argument_list; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:all_positions; 199, call; 199, 200; 199, 201; 200, identifier:list; 201, argument_list; 201, 202; 202, call; 202, 203; 202, 204; 203, identifier:set; 204, argument_list; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:itertools; 208, identifier:chain; 209, argument_list; 209, 210; 210, list_splat; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:vcf_lists; 214, identifier:values; 215, argument_list; 216, for_statement; 216, 217; 216, 218; 216, 222; 217, identifier:position; 218, call; 218, 219; 218, 220; 219, identifier:sorted; 220, argument_list; 220, 221; 221, identifier:all_positions; 222, block; 222, 223; 222, 241; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:hits; 226, dictionary_comprehension; 226, 227; 226, 234; 227, pair; 227, 228; 227, 229; 228, identifier:caller; 229, comparison_operator:in; 229, 230; 229, 231; 230, identifier:position; 231, subscript; 231, 232; 231, 233; 232, identifier:vcf_lists; 233, identifier:caller; 234, for_in_clause; 234, 235; 234, 236; 235, identifier:caller; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:perchrom_mutations; 239, identifier:keys; 240, argument_list; 241, if_statement; 241, 242; 241, 254; 242, comparison_operator:>=; 242, 243; 242, 251; 243, call; 243, 244; 243, 245; 244, identifier:sum; 245, argument_list; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:hits; 249, identifier:values; 250, argument_list; 251, subscript; 251, 252; 251, 253; 252, identifier:majority; 253, identifier:mut_type; 254, block; 254, 255; 254, 276; 254, 286; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:callers; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, string:','; 261, identifier:join; 262, argument_list; 262, 263; 263, list_comprehension; 263, 264; 263, 265; 263, 274; 264, identifier:caller; 265, for_in_clause; 265, 266; 265, 269; 266, pattern_list; 266, 267; 266, 268; 267, identifier:caller; 268, identifier:hit; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:hits; 272, identifier:items; 273, argument_list; 274, if_clause; 274, 275; 275, identifier:hit; 276, assert_statement; 276, 277; 277, comparison_operator:not; 277, 278; 277, 281; 278, subscript; 278, 279; 278, 280; 279, identifier:position; 280, integer:1; 281, subscript; 281, 282; 281, 283; 282, identifier:accepted_hits; 283, subscript; 283, 284; 283, 285; 284, identifier:position; 285, integer:0; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 297; 288, subscript; 288, 289; 288, 294; 289, subscript; 289, 290; 289, 291; 290, identifier:accepted_hits; 291, subscript; 291, 292; 291, 293; 292, identifier:position; 293, integer:0; 294, subscript; 294, 295; 294, 296; 295, identifier:position; 296, integer:1; 297, tuple; 297, 298; 297, 301; 297, 304; 298, subscript; 298, 299; 298, 300; 299, identifier:position; 300, integer:2; 301, subscript; 301, 302; 301, 303; 302, identifier:position; 303, integer:3; 304, identifier:callers; 305, with_statement; 305, 306; 305, 325; 306, with_clause; 306, 307; 307, with_item; 307, 308; 308, as_pattern; 308, 309; 308, 323; 309, call; 309, 310; 309, 311; 310, identifier:open; 311, argument_list; 311, 312; 311, 322; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, string:''; 315, identifier:join; 316, argument_list; 316, 317; 317, list:[work_dir, '/', chrom, '.vcf']; 317, 318; 317, 319; 317, 320; 317, 321; 318, identifier:work_dir; 319, string:'/'; 320, identifier:chrom; 321, string:'.vcf'; 322, string:'w'; 323, as_pattern_target; 323, 324; 324, identifier:outfile; 325, block; 325, 326; 325, 334; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 329; 328, identifier:print; 329, argument_list; 329, 330; 329, 331; 330, string:'
print('; 331, ERROR; 331, 332; 331, 333; 332, identifier:file; 333, identifier:outfile; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 337; 335, 350; 335, 352; 336, identifier:print; 337, ERROR; 337, 338; 337, 340; 338, ERROR; 338, 339; 339, identifier:for; 340, comparison_operator:in; 340, 341; 340, 342; 341, identifier:chrom; 342, call; 342, 343; 342, 344; 343, identifier:chrom_sorted; 344, argument_list; 344, 345; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:accepted_hits; 348, identifier:keys; 349, argument_list; 350, ERROR; 350, 351; 351, identifier:for; 352, type; 352, 353; 353, constrained_type; 353, 354; 353, 363; 354, type; 354, 355; 355, comparison_operator:in; 355, 356; 355, 357; 356, identifier:position; 357, call; 357, 358; 357, 359; 358, identifier:sorted; 359, argument_list; 359, 360; 360, subscript; 360, 361; 360, 362; 361, identifier:accepted_hits; 362, identifier:chrom; 363, type; 363, 364; 364, call; 364, 365; 364, 366; 365, identifier:print; 366, argument_list; 366, 367; 366, 368; 366, 369; 366, 370; 366, 377; 366, 384; 366, 385; 366, 386; 366, 395; 366, 398; 367, identifier:chrom; 368, identifier:position; 369, string:'.'; 370, subscript; 370, 371; 370, 376; 371, subscript; 371, 372; 371, 375; 372, subscript; 372, 373; 372, 374; 373, identifier:accepted_hits; 374, identifier:chrom; 375, identifier:position; 376, integer:0; 377, subscript; 377, 378; 377, 383; 378, subscript; 378, 379; 378, 382; 379, subscript; 379, 380; 379, 381; 380, identifier:accepted_hits; 381, identifier:chrom; 382, identifier:position; 383, integer:1; 384, string:'.'; 385, string:'PASS'; 386, binary_operator:+; 386, 387; 386, 388; 387, string:'callers='; 388, subscript; 388, 389; 388, 394; 389, subscript; 389, 390; 389, 393; 390, subscript; 390, 391; 390, 392; 391, identifier:accepted_hits; 392, identifier:chrom; 393, identifier:position; 394, integer:2; 395, keyword_argument; 395, 396; 395, 397; 396, identifier:sep; 397, string:'\t'; 398, keyword_argument; 398, 399; 398, 400; 399, identifier:file; 400, identifier:outfile; 401, expression_statement; 401, 402; 402, assignment; 402, 403; 402, 404; 403, identifier:fsid; 404, call; 404, 405; 404, 410; 405, attribute; 405, 406; 405, 409; 406, attribute; 406, 407; 406, 408; 407, identifier:job; 408, identifier:fileStore; 409, identifier:writeGlobalFile; 410, argument_list; 410, 411; 411, attribute; 411, 412; 411, 413; 412, identifier:outfile; 413, identifier:name; 414, expression_statement; 414, 415; 415, call; 415, 416; 415, 417; 416, identifier:export_results; 417, argument_list; 417, 418; 417, 419; 417, 420; 417, 423; 417, 424; 418, identifier:job; 419, identifier:fsid; 420, attribute; 420, 421; 420, 422; 421, identifier:outfile; 422, identifier:name; 423, identifier:univ_options; 424, keyword_argument; 424, 425; 424, 426; 425, identifier:subfolder; 426, string:'mutations/merged'; 427, return_statement; 427, 428; 428, identifier:fsid | def merge_perchrom_mutations(job, chrom, mutations, univ_options):
work_dir = os.getcwd()
from protect.mutation_calling.muse import process_muse_vcf
from protect.mutation_calling.mutect import process_mutect_vcf
from protect.mutation_calling.radia import process_radia_vcf
from protect.mutation_calling.somaticsniper import process_somaticsniper_vcf
from protect.mutation_calling.strelka import process_strelka_vcf
mutations.pop('indels')
mutations['strelka_indels'] = mutations['strelka']['indels']
mutations['strelka_snvs'] = mutations['strelka']['snvs']
vcf_processor = {'snvs': {'mutect': process_mutect_vcf,
'muse': process_muse_vcf,
'radia': process_radia_vcf,
'somaticsniper': process_somaticsniper_vcf,
'strelka_snvs': process_strelka_vcf
},
'indels': {'strelka_indels': process_strelka_vcf
}
}
majority = {'snvs': 2,
'indels': 1}
accepted_hits = defaultdict(dict)
for mut_type in vcf_processor.keys():
perchrom_mutations = {caller: vcf_processor[mut_type][caller](job, mutations[caller][chrom],
work_dir, univ_options)
for caller in vcf_processor[mut_type]}
perchrom_mutations['strelka'] = perchrom_mutations['strelka_' + mut_type]
perchrom_mutations.pop('strelka_' + mut_type)
vcf_lists = {caller: read_vcf(vcf_file) for caller, vcf_file in perchrom_mutations.items()}
all_positions = list(set(itertools.chain(*vcf_lists.values())))
for position in sorted(all_positions):
hits = {caller: position in vcf_lists[caller] for caller in perchrom_mutations.keys()}
if sum(hits.values()) >= majority[mut_type]:
callers = ','.join([caller for caller, hit in hits.items() if hit])
assert position[1] not in accepted_hits[position[0]]
accepted_hits[position[0]][position[1]] = (position[2], position[3], callers)
with open(''.join([work_dir, '/', chrom, '.vcf']), 'w') as outfile:
print('
print('
file=outfile)
print('
for chrom in chrom_sorted(accepted_hits.keys()):
for position in sorted(accepted_hits[chrom]):
print(chrom, position, '.', accepted_hits[chrom][position][0],
accepted_hits[chrom][position][1], '.', 'PASS',
'callers=' + accepted_hits[chrom][position][2], sep='\t', file=outfile)
fsid = job.fileStore.writeGlobalFile(outfile.name)
export_results(job, fsid, outfile.name, univ_options, subfolder='mutations/merged')
return fsid |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:check; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:domain; 5, identifier:prefix; 6, identifier:code; 7, default_parameter; 7, 8; 7, 9; 8, identifier:strategies; 9, string:'*'; 10, block; 10, 11; 10, 30; 10, 49; 10, 68; 10, 87; 11, if_statement; 11, 12; 11, 19; 12, boolean_operator:or; 12, 13; 12, 16; 13, comparison_operator:==; 13, 14; 13, 15; 14, identifier:strategies; 15, string:'*'; 16, comparison_operator:in; 16, 17; 16, 18; 17, string:'dns_txt'; 18, identifier:strategies; 19, block; 19, 20; 20, if_statement; 20, 21; 20, 27; 21, call; 21, 22; 21, 23; 22, identifier:check_dns_txt; 23, argument_list; 23, 24; 23, 25; 23, 26; 24, identifier:domain; 25, identifier:prefix; 26, identifier:code; 27, block; 27, 28; 28, return_statement; 28, 29; 29, True; 30, if_statement; 30, 31; 30, 38; 31, boolean_operator:or; 31, 32; 31, 35; 32, comparison_operator:==; 32, 33; 32, 34; 33, identifier:strategies; 34, string:'*'; 35, comparison_operator:in; 35, 36; 35, 37; 36, string:'dns_cname'; 37, identifier:strategies; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 46; 40, call; 40, 41; 40, 42; 41, identifier:check_dns_cname; 42, argument_list; 42, 43; 42, 44; 42, 45; 43, identifier:domain; 44, identifier:prefix; 45, identifier:code; 46, block; 46, 47; 47, return_statement; 47, 48; 48, True; 49, if_statement; 49, 50; 49, 57; 50, boolean_operator:or; 50, 51; 50, 54; 51, comparison_operator:==; 51, 52; 51, 53; 52, identifier:strategies; 53, string:'*'; 54, comparison_operator:in; 54, 55; 54, 56; 55, string:'meta_tag'; 56, identifier:strategies; 57, block; 57, 58; 58, if_statement; 58, 59; 58, 65; 59, call; 59, 60; 59, 61; 60, identifier:check_meta_tag; 61, argument_list; 61, 62; 61, 63; 61, 64; 62, identifier:domain; 63, identifier:prefix; 64, identifier:code; 65, block; 65, 66; 66, return_statement; 66, 67; 67, True; 68, if_statement; 68, 69; 68, 76; 69, boolean_operator:or; 69, 70; 69, 73; 70, comparison_operator:==; 70, 71; 70, 72; 71, identifier:strategies; 72, string:'*'; 73, comparison_operator:in; 73, 74; 73, 75; 74, string:'html_file'; 75, identifier:strategies; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 84; 78, call; 78, 79; 78, 80; 79, identifier:check_html_file; 80, argument_list; 80, 81; 80, 82; 80, 83; 81, identifier:domain; 82, identifier:prefix; 83, identifier:code; 84, block; 84, 85; 85, return_statement; 85, 86; 86, True; 87, return_statement; 87, 88; 88, False | def check(domain, prefix, code, strategies='*'):
if strategies == '*' or 'dns_txt' in strategies:
if check_dns_txt(domain, prefix, code):
return True
if strategies == '*' or 'dns_cname' in strategies:
if check_dns_cname(domain, prefix, code):
return True
if strategies == '*' or 'meta_tag' in strategies:
if check_meta_tag(domain, prefix, code):
return True
if strategies == '*' or 'html_file' in strategies:
if check_html_file(domain, prefix, code):
return True
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:register_cache_buster; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:app; 6, default_parameter; 6, 7; 6, 8; 7, identifier:config; 8, None; 9, block; 9, 10; 9, 28; 9, 32; 9, 36; 9, 45; 9, 159; 9, 168; 9, 181; 9, 194; 9, 221; 9, 251; 9, 259; 10, if_statement; 10, 11; 10, 22; 11, not_operator; 11, 12; 12, parenthesized_expression; 12, 13; 13, boolean_operator:or; 13, 14; 13, 17; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:config; 16, None; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:config; 21, identifier:dict; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:ValueError; 26, argument_list; 26, 27; 27, string:"`config` must be an instance of dict or None"; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:bust_map; 31, dictionary; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:unbust_map; 35, dictionary; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:app; 41, identifier:logger; 42, identifier:debug; 43, argument_list; 43, 44; 44, string:'Starting computing hashes for static assets'; 45, for_statement; 45, 46; 45, 50; 45, 58; 46, pattern_list; 46, 47; 46, 48; 46, 49; 47, identifier:dirpath; 48, identifier:dirnames; 49, identifier:filenames; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:os; 53, identifier:walk; 54, argument_list; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:app; 57, identifier:static_folder; 58, block; 58, 59; 59, for_statement; 59, 60; 59, 61; 59, 62; 60, identifier:filename; 61, identifier:filenames; 62, block; 62, 63; 62, 75; 62, 85; 62, 94; 62, 129; 62, 143; 62, 147; 62, 153; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:rooted_filename; 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:join; 72, argument_list; 72, 73; 72, 74; 73, identifier:dirpath; 74, identifier:filename; 75, if_statement; 75, 76; 75, 83; 76, not_operator; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:__is_file_to_be_busted; 81, argument_list; 81, 82; 82, identifier:rooted_filename; 83, block; 83, 84; 84, continue_statement; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:app; 90, identifier:logger; 91, identifier:debug; 92, argument_list; 92, 93; 93, string:f'Computing hashes for {rooted_filename}'; 94, with_statement; 94, 95; 94, 105; 95, with_clause; 95, 96; 96, with_item; 96, 97; 97, as_pattern; 97, 98; 97, 103; 98, call; 98, 99; 98, 100; 99, identifier:open; 100, argument_list; 100, 101; 100, 102; 101, identifier:rooted_filename; 102, string:'rb'; 103, as_pattern_target; 103, 104; 104, identifier:f; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:version; 109, subscript; 109, 110; 109, 124; 110, call; 110, 111; 110, 123; 111, attribute; 111, 112; 111, 122; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:hashlib; 115, identifier:md5; 116, argument_list; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:f; 120, identifier:read; 121, argument_list; 122, identifier:hexdigest; 123, argument_list; 124, slice; 124, 125; 124, 126; 125, colon; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:hash_size; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:unbusted; 132, call; 132, 133; 132, 138; 133, attribute; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:os; 136, identifier:path; 137, identifier:relpath; 138, argument_list; 138, 139; 138, 140; 139, identifier:rooted_filename; 140, attribute; 140, 141; 140, 142; 141, identifier:app; 142, identifier:static_folder; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:busted; 146, string:f"{unbusted}?q={version}"; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:bust_map; 151, identifier:unbusted; 152, identifier:busted; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:unbust_map; 157, identifier:busted; 158, identifier:unbusted; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:app; 164, identifier:logger; 165, identifier:debug; 166, argument_list; 166, 167; 167, string:'Finished Starting computing hashes for static assets'; 168, function_definition; 168, 169; 168, 170; 168, 172; 169, function_name:bust_filename; 170, parameters; 170, 171; 171, identifier:file; 172, block; 172, 173; 173, return_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:bust_map; 177, identifier:get; 178, argument_list; 178, 179; 178, 180; 179, identifier:file; 180, identifier:file; 181, function_definition; 181, 182; 181, 183; 181, 185; 182, function_name:unbust_filename; 183, parameters; 183, 184; 184, identifier:file; 185, block; 185, 186; 186, return_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:unbust_map; 190, identifier:get; 191, argument_list; 191, 192; 191, 193; 192, identifier:file; 193, identifier:file; 194, decorated_definition; 194, 195; 194, 199; 195, decorator; 195, 196; 196, attribute; 196, 197; 196, 198; 197, identifier:app; 198, identifier:url_defaults; 199, function_definition; 199, 200; 199, 201; 199, 204; 200, function_name:reverse_to_cache_busted_url; 201, parameters; 201, 202; 201, 203; 202, identifier:endpoint; 203, identifier:values; 204, block; 204, 205; 205, if_statement; 205, 206; 205, 209; 206, comparison_operator:==; 206, 207; 206, 208; 207, identifier:endpoint; 208, string:'static'; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 215; 212, subscript; 212, 213; 212, 214; 213, identifier:values; 214, string:'filename'; 215, call; 215, 216; 215, 217; 216, identifier:bust_filename; 217, argument_list; 217, 218; 218, subscript; 218, 219; 218, 220; 219, identifier:values; 220, string:'filename'; 221, function_definition; 221, 222; 221, 223; 221, 228; 222, function_name:debusting_static_view; 223, parameters; 223, 224; 223, 226; 224, list_splat_pattern; 224, 225; 225, identifier:args; 226, dictionary_splat_pattern; 226, 227; 227, identifier:kwargs; 228, block; 228, 229; 228, 243; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 234; 231, subscript; 231, 232; 231, 233; 232, identifier:kwargs; 233, string:'filename'; 234, call; 234, 235; 234, 236; 235, identifier:unbust_filename; 236, argument_list; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:kwargs; 240, identifier:get; 241, argument_list; 241, 242; 242, string:'filename'; 243, return_statement; 243, 244; 244, call; 244, 245; 244, 246; 245, identifier:original_static_view; 246, argument_list; 246, 247; 246, 249; 247, list_splat; 247, 248; 248, identifier:args; 249, dictionary_splat; 249, 250; 250, identifier:kwargs; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:original_static_view; 254, subscript; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:app; 257, identifier:view_functions; 258, string:'static'; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 266; 261, subscript; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:app; 264, identifier:view_functions; 265, string:'static'; 266, identifier:debusting_static_view | def register_cache_buster(self, app, config=None):
if not (config is None or isinstance(config, dict)):
raise ValueError("`config` must be an instance of dict or None")
bust_map = {}
unbust_map = {}
app.logger.debug('Starting computing hashes for static assets')
for dirpath, dirnames, filenames in os.walk(app.static_folder):
for filename in filenames:
rooted_filename = os.path.join(dirpath, filename)
if not self.__is_file_to_be_busted(rooted_filename):
continue
app.logger.debug(f'Computing hashes for {rooted_filename}')
with open(rooted_filename, 'rb') as f:
version = hashlib.md5(
f.read()
).hexdigest()[:self.hash_size]
unbusted = os.path.relpath(rooted_filename, app.static_folder)
busted = f"{unbusted}?q={version}"
bust_map[unbusted] = busted
unbust_map[busted] = unbusted
app.logger.debug('Finished Starting computing hashes for static assets')
def bust_filename(file):
return bust_map.get(file, file)
def unbust_filename(file):
return unbust_map.get(file, file)
@app.url_defaults
def reverse_to_cache_busted_url(endpoint, values):
if endpoint == 'static':
values['filename'] = bust_filename(values['filename'])
def debusting_static_view(*args, **kwargs):
kwargs['filename'] = unbust_filename(kwargs.get('filename'))
return original_static_view(*args, **kwargs)
original_static_view = app.view_functions['static']
app.view_functions['static'] = debusting_static_view |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:parse_inventory; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:inventory_output; 6, None; 7, block; 7, 8; 7, 27; 7, 34; 7, 38; 7, 42; 7, 100; 7, 113; 7, 132; 7, 145; 7, 164; 7, 177; 7, 191; 7, 204; 7, 218; 7, 231; 7, 249; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:udi; 11, dictionary; 11, 12; 11, 15; 11, 18; 11, 21; 11, 24; 12, pair; 12, 13; 12, 14; 13, string:"name"; 14, string:""; 15, pair; 15, 16; 15, 17; 16, string:"description"; 17, string:""; 18, pair; 18, 19; 18, 20; 19, string:"pid"; 20, string:""; 21, pair; 21, 22; 21, 23; 22, string:"vid"; 23, string:""; 24, pair; 24, 25; 24, 26; 25, string:"sn"; 26, string:""; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:inventory_output; 30, None; 31, block; 31, 32; 32, return_statement; 32, 33; 33, identifier:udi; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:capture_next; 37, False; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:chassis_udi_text; 41, None; 42, for_statement; 42, 43; 42, 44; 42, 50; 43, identifier:line; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:inventory_output; 47, identifier:split; 48, argument_list; 48, 49; 49, string:'\n'; 50, block; 50, 51; 50, 59; 50, 88; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:lc_line; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:line; 57, identifier:lower; 58, argument_list; 59, if_statement; 59, 60; 59, 78; 60, boolean_operator:and; 60, 61; 60, 77; 61, boolean_operator:and; 61, 62; 61, 74; 62, parenthesized_expression; 62, 63; 63, boolean_operator:or; 63, 64; 63, 71; 64, boolean_operator:or; 64, 65; 64, 68; 65, comparison_operator:in; 65, 66; 65, 67; 66, string:'chassis'; 67, identifier:lc_line; 68, comparison_operator:in; 68, 69; 68, 70; 69, string:'switch system'; 70, identifier:lc_line; 71, comparison_operator:in; 71, 72; 71, 73; 72, string:'rack'; 73, identifier:lc_line; 74, comparison_operator:in; 74, 75; 74, 76; 75, string:'name'; 76, identifier:lc_line; 77, string:'descr'; 78, block; 78, 79; 78, 83; 78, 87; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:capture_next; 82, True; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:chassis_udi_text; 86, identifier:line; 87, continue_statement; 88, if_statement; 88, 89; 88, 90; 89, identifier:capture_next; 90, block; 90, 91; 90, 99; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:inventory_output; 94, binary_operator:+; 94, 95; 94, 98; 95, binary_operator:+; 95, 96; 95, 97; 96, identifier:chassis_udi_text; 97, string:"\n"; 98, identifier:line; 99, break_statement; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:match; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:re; 106, identifier:search; 107, argument_list; 107, 108; 107, 109; 107, 110; 108, string:r"(?i)NAME: (?P<name>.*?),? (?i)DESCR"; 109, identifier:inventory_output; 110, attribute; 110, 111; 110, 112; 111, identifier:re; 112, identifier:MULTILINE; 113, if_statement; 113, 114; 113, 115; 114, identifier:match; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:udi; 120, string:'name'; 121, call; 121, 122; 121, 130; 122, attribute; 122, 123; 122, 129; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:match; 126, identifier:group; 127, argument_list; 127, 128; 128, string:'name'; 129, identifier:strip; 130, argument_list; 130, 131; 131, string:'" ,'; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:match; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:re; 138, identifier:search; 139, argument_list; 139, 140; 139, 141; 139, 142; 140, string:r"(?i)DESCR: (?P<description>.*)"; 141, identifier:inventory_output; 142, attribute; 142, 143; 142, 144; 143, identifier:re; 144, identifier:MULTILINE; 145, if_statement; 145, 146; 145, 147; 146, identifier:match; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:udi; 152, string:'description'; 153, call; 153, 154; 153, 162; 154, attribute; 154, 155; 154, 161; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:match; 158, identifier:group; 159, argument_list; 159, 160; 160, string:'description'; 161, identifier:strip; 162, argument_list; 162, 163; 163, string:'" '; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:match; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:re; 170, identifier:search; 171, argument_list; 171, 172; 171, 173; 171, 174; 172, string:r"(?i)PID: (?P<pid>.*?),? "; 173, identifier:inventory_output; 174, attribute; 174, 175; 174, 176; 175, identifier:re; 176, identifier:MULTILINE; 177, if_statement; 177, 178; 177, 179; 178, identifier:match; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:udi; 184, string:'pid'; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:match; 188, identifier:group; 189, argument_list; 189, 190; 190, string:'pid'; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:match; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:re; 197, identifier:search; 198, argument_list; 198, 199; 198, 200; 198, 201; 199, string:r"(?i)VID: (?P<vid>.*?),? "; 200, identifier:inventory_output; 201, attribute; 201, 202; 201, 203; 202, identifier:re; 203, identifier:MULTILINE; 204, if_statement; 204, 205; 204, 206; 205, identifier:match; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:udi; 211, string:'vid'; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:match; 215, identifier:group; 216, argument_list; 216, 217; 217, string:'vid'; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:match; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:re; 224, identifier:search; 225, argument_list; 225, 226; 225, 227; 225, 228; 226, string:r"(?i)SN: (?P<sn>.*)"; 227, identifier:inventory_output; 228, attribute; 228, 229; 228, 230; 229, identifier:re; 230, identifier:MULTILINE; 231, if_statement; 231, 232; 231, 233; 232, identifier:match; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:udi; 238, string:'sn'; 239, call; 239, 240; 239, 248; 240, attribute; 240, 241; 240, 247; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:match; 244, identifier:group; 245, argument_list; 245, 246; 246, string:'sn'; 247, identifier:strip; 248, argument_list; 249, return_statement; 249, 250; 250, identifier:udi | def parse_inventory(inventory_output=None):
udi = {
"name": "",
"description": "",
"pid": "",
"vid": "",
"sn": ""
}
if inventory_output is None:
return udi
capture_next = False
chassis_udi_text = None
for line in inventory_output.split('\n'):
lc_line = line.lower()
if ('chassis' in lc_line or 'switch system' in lc_line or 'rack' in lc_line) and 'name' in lc_line and 'descr':
capture_next = True
chassis_udi_text = line
continue
if capture_next:
inventory_output = chassis_udi_text + "\n" + line
break
match = re.search(r"(?i)NAME: (?P<name>.*?),? (?i)DESCR", inventory_output, re.MULTILINE)
if match:
udi['name'] = match.group('name').strip('" ,')
match = re.search(r"(?i)DESCR: (?P<description>.*)", inventory_output, re.MULTILINE)
if match:
udi['description'] = match.group('description').strip('" ')
match = re.search(r"(?i)PID: (?P<pid>.*?),? ", inventory_output, re.MULTILINE)
if match:
udi['pid'] = match.group('pid')
match = re.search(r"(?i)VID: (?P<vid>.*?),? ", inventory_output, re.MULTILINE)
if match:
udi['vid'] = match.group('vid')
match = re.search(r"(?i)SN: (?P<sn>.*)", inventory_output, re.MULTILINE)
if match:
udi['sn'] = match.group('sn').strip()
return udi |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:yaml_file_to_dict; 3, parameters; 3, 4; 3, 5; 4, identifier:script_name; 5, default_parameter; 5, 6; 5, 7; 6, identifier:path; 7, None; 8, block; 8, 9; 8, 46; 8, 102; 8, 118; 8, 132; 8, 153; 8, 160; 8, 189; 8, 212; 8, 240; 9, function_definition; 9, 10; 9, 11; 9, 13; 10, function_name:load_yaml; 11, parameters; 11, 12; 12, identifier:file_path; 13, block; 13, 14; 13, 44; 14, with_statement; 14, 15; 14, 25; 15, with_clause; 15, 16; 16, with_item; 16, 17; 17, as_pattern; 17, 18; 17, 23; 18, call; 18, 19; 18, 20; 19, identifier:open; 20, argument_list; 20, 21; 20, 22; 21, identifier:file_path; 22, string:'r'; 23, as_pattern_target; 23, 24; 24, identifier:yamlfile; 25, block; 25, 26; 26, try_statement; 26, 27; 26, 37; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:dictionary; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:yaml; 34, identifier:load; 35, argument_list; 35, 36; 36, identifier:yamlfile; 37, except_clause; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:yaml; 40, identifier:YAMLError; 41, block; 41, 42; 42, return_statement; 42, 43; 43, dictionary; 44, return_statement; 44, 45; 45, identifier:dictionary; 46, function_definition; 46, 47; 46, 48; 46, 51; 47, function_name:merge; 48, parameters; 48, 49; 48, 50; 49, identifier:user; 50, identifier:default; 51, block; 51, 52; 51, 100; 52, if_statement; 52, 53; 52, 64; 53, boolean_operator:and; 53, 54; 53, 59; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:user; 58, identifier:dict; 59, call; 59, 60; 59, 61; 60, identifier:isinstance; 61, argument_list; 61, 62; 61, 63; 62, identifier:default; 63, identifier:dict; 64, block; 64, 65; 65, for_statement; 65, 66; 65, 69; 65, 74; 66, pattern_list; 66, 67; 66, 68; 67, identifier:k; 68, identifier:v; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:default; 72, identifier:iteritems; 73, argument_list; 74, block; 74, 75; 75, if_statement; 75, 76; 75, 79; 75, 86; 76, comparison_operator:not; 76, 77; 76, 78; 77, identifier:k; 78, identifier:user; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:user; 84, identifier:k; 85, identifier:v; 86, else_clause; 86, 87; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:user; 92, identifier:k; 93, call; 93, 94; 93, 95; 94, identifier:merge; 95, argument_list; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:user; 98, identifier:k; 99, identifier:v; 100, return_statement; 100, 101; 101, identifier:user; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:path; 105, None; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:path; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:os; 114, identifier:path; 115, identifier:abspath; 116, argument_list; 116, 117; 117, string:'.'; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:config_file_path; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:os; 125, identifier:path; 126, identifier:join; 127, argument_list; 127, 128; 127, 129; 128, identifier:path; 129, binary_operator:+; 129, 130; 129, 131; 130, identifier:script_name; 131, string:'.yaml'; 132, if_statement; 132, 133; 132, 142; 133, not_operator; 133, 134; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:os; 138, identifier:path; 139, identifier:exists; 140, argument_list; 140, 141; 141, identifier:config_file_path; 142, block; 142, 143; 143, raise_statement; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:RuntimeError; 146, argument_list; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, string:'Config file does not exist: {}'; 150, identifier:format; 151, argument_list; 151, 152; 152, identifier:config_file_path; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:default_dict; 156, call; 156, 157; 156, 158; 157, identifier:load_yaml; 158, argument_list; 158, 159; 159, identifier:config_file_path; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:user_config_file_path; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:os; 167, identifier:path; 168, identifier:join; 169, argument_list; 169, 170; 169, 178; 169, 179; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:os; 174, identifier:path; 175, identifier:expanduser; 176, argument_list; 176, 177; 177, string:'~'; 178, string:'.condoor'; 179, binary_operator:+; 179, 180; 179, 188; 180, call; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:os; 184, identifier:path; 185, identifier:basename; 186, argument_list; 186, 187; 187, identifier:script_name; 188, string:'.yaml'; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:user_config_file_path; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:os; 195, identifier:getenv; 196, argument_list; 196, 197; 196, 211; 197, binary_operator:+; 197, 198; 197, 199; 198, string:'CONDOOR_'; 199, call; 199, 200; 199, 210; 200, attribute; 200, 201; 200, 209; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:os; 205, identifier:path; 206, identifier:basename; 207, argument_list; 207, 208; 208, identifier:script_name; 209, identifier:upper; 210, argument_list; 211, identifier:user_config_file_path; 212, if_statement; 212, 213; 212, 221; 213, call; 213, 214; 213, 219; 214, attribute; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:os; 217, identifier:path; 218, identifier:exists; 219, argument_list; 219, 220; 220, identifier:user_config_file_path; 221, block; 221, 222; 221, 229; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:user_dict; 225, call; 225, 226; 225, 227; 226, identifier:load_yaml; 227, argument_list; 227, 228; 228, identifier:user_config_file_path; 229, if_statement; 229, 230; 229, 231; 230, identifier:user_dict; 231, block; 231, 232; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:default_dict; 235, call; 235, 236; 235, 237; 236, identifier:merge; 237, argument_list; 237, 238; 237, 239; 238, identifier:user_dict; 239, identifier:default_dict; 240, return_statement; 240, 241; 241, identifier:default_dict | def yaml_file_to_dict(script_name, path=None):
def load_yaml(file_path):
with open(file_path, 'r') as yamlfile:
try:
dictionary = yaml.load(yamlfile)
except yaml.YAMLError:
return {}
return dictionary
def merge(user, default):
if isinstance(user, dict) and isinstance(default, dict):
for k, v in default.iteritems():
if k not in user:
user[k] = v
else:
user[k] = merge(user[k], v)
return user
if path is None:
path = os.path.abspath('.')
config_file_path = os.path.join(path, script_name + '.yaml')
if not os.path.exists(config_file_path):
raise RuntimeError('Config file does not exist: {}'.format(config_file_path))
default_dict = load_yaml(config_file_path)
user_config_file_path = os.path.join(os.path.expanduser('~'), '.condoor', os.path.basename(script_name) + '.yaml')
user_config_file_path = os.getenv('CONDOOR_' + os.path.basename(script_name).upper(), user_config_file_path)
if os.path.exists(user_config_file_path):
user_dict = load_yaml(user_config_file_path)
if user_dict:
default_dict = merge(user_dict, default_dict)
return default_dict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:make_hop_info_from_url; 3, parameters; 3, 4; 3, 5; 4, identifier:url; 5, default_parameter; 5, 6; 5, 7; 6, identifier:verify_reachability; 7, None; 8, block; 8, 9; 8, 16; 8, 32; 8, 48; 8, 70; 8, 91; 8, 100; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:parsed; 12, call; 12, 13; 12, 14; 13, identifier:urlparse; 14, argument_list; 14, 15; 15, identifier:url; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:username; 19, conditional_expression:if; 19, 20; 19, 21; 19, 26; 20, None; 21, comparison_operator:is; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:parsed; 24, identifier:username; 25, None; 26, call; 26, 27; 26, 28; 27, identifier:unquote; 28, argument_list; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:parsed; 31, identifier:username; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:password; 35, conditional_expression:if; 35, 36; 35, 37; 35, 42; 36, None; 37, comparison_operator:is; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:parsed; 40, identifier:password; 41, None; 42, call; 42, 43; 42, 44; 43, identifier:unquote; 44, argument_list; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:parsed; 47, identifier:password; 48, try_statement; 48, 49; 48, 63; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:enable_password; 53, subscript; 53, 54; 53, 62; 54, subscript; 54, 55; 54, 61; 55, call; 55, 56; 55, 57; 56, identifier:parse_qs; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:parsed; 60, identifier:query; 61, string:"enable_password"; 62, integer:0; 63, except_clause; 63, 64; 63, 65; 64, identifier:KeyError; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:enable_password; 69, None; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:hop_info; 73, call; 73, 74; 73, 75; 74, identifier:HopInfo; 75, argument_list; 75, 76; 75, 79; 75, 82; 75, 83; 75, 84; 75, 87; 75, 88; 76, attribute; 76, 77; 76, 78; 77, identifier:parsed; 78, identifier:scheme; 79, attribute; 79, 80; 79, 81; 80, identifier:parsed; 81, identifier:hostname; 82, identifier:username; 83, identifier:password; 84, attribute; 84, 85; 84, 86; 85, identifier:parsed; 86, identifier:port; 87, identifier:enable_password; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:verify_reachability; 90, identifier:verify_reachability; 91, if_statement; 91, 92; 91, 97; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:hop_info; 95, identifier:is_valid; 96, argument_list; 97, block; 97, 98; 98, return_statement; 98, 99; 99, identifier:hop_info; 100, raise_statement; 100, 101; 101, identifier:InvalidHopInfoError | def make_hop_info_from_url(url, verify_reachability=None):
parsed = urlparse(url)
username = None if parsed.username is None else unquote(parsed.username)
password = None if parsed.password is None else unquote(parsed.password)
try:
enable_password = parse_qs(parsed.query)["enable_password"][0]
except KeyError:
enable_password = None
hop_info = HopInfo(
parsed.scheme,
parsed.hostname,
username,
password,
parsed.port,
enable_password,
verify_reachability=verify_reachability
)
if hop_info.is_valid():
return hop_info
raise InvalidHopInfoError |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sendmail; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:self; 5, identifier:sender; 6, identifier:recipients; 7, identifier:message; 8, default_parameter; 8, 9; 8, 10; 9, identifier:mail_options; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:rcpt_options; 13, None; 14, block; 14, 15; 14, 27; 14, 36; 14, 45; 14, 52; 14, 79; 14, 88; 14, 92; 14, 120; 14, 136; 14, 144; 15, if_statement; 15, 16; 15, 21; 16, call; 16, 17; 16, 18; 17, identifier:isinstance; 18, argument_list; 18, 19; 18, 20; 19, identifier:recipients; 20, identifier:str; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:recipients; 25, list:[recipients]; 25, 26; 26, identifier:recipients; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:mail_options; 30, None; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:mail_options; 35, list:[]; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:rcpt_options; 39, None; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:rcpt_options; 44, list:[]; 45, expression_statement; 45, 46; 46, await; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:ehlo_or_helo_if_needed; 51, argument_list; 52, if_statement; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:supports_esmtp; 56, block; 56, 57; 57, if_statement; 57, 58; 57, 63; 58, comparison_operator:in; 58, 59; 58, 60; 59, string:"size"; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:esmtp_extensions; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:mail_options; 68, identifier:append; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:"size={}"; 73, identifier:format; 74, argument_list; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:len; 77, argument_list; 77, 78; 78, identifier:message; 79, expression_statement; 79, 80; 80, await; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:mail; 85, argument_list; 85, 86; 85, 87; 86, identifier:sender; 87, identifier:mail_options; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:errors; 91, list:[]; 92, for_statement; 92, 93; 92, 94; 92, 95; 93, identifier:recipient; 94, identifier:recipients; 95, block; 95, 96; 96, try_statement; 96, 97; 96, 107; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, await; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:rcpt; 104, argument_list; 104, 105; 104, 106; 105, identifier:recipient; 106, identifier:rcpt_options; 107, except_clause; 107, 108; 107, 112; 108, as_pattern; 108, 109; 108, 110; 109, identifier:SMTPCommandFailedError; 110, as_pattern_target; 110, 111; 111, identifier:e; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:errors; 117, identifier:append; 118, argument_list; 118, 119; 119, identifier:e; 120, if_statement; 120, 121; 120, 130; 121, comparison_operator:==; 121, 122; 121, 126; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:recipients; 126, call; 126, 127; 126, 128; 127, identifier:len; 128, argument_list; 128, 129; 129, identifier:errors; 130, block; 130, 131; 131, raise_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:SMTPNoRecipientError; 134, argument_list; 134, 135; 135, identifier:errors; 136, expression_statement; 136, 137; 137, await; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:data; 142, argument_list; 142, 143; 143, identifier:message; 144, return_statement; 144, 145; 145, identifier:errors | async def sendmail(
self, sender, recipients, message, mail_options=None, rcpt_options=None
):
if isinstance(recipients, str):
recipients = [recipients]
if mail_options is None:
mail_options = []
if rcpt_options is None:
rcpt_options = []
await self.ehlo_or_helo_if_needed()
if self.supports_esmtp:
if "size" in self.esmtp_extensions:
mail_options.append("size={}".format(len(message)))
await self.mail(sender, mail_options)
errors = []
for recipient in recipients:
try:
await self.rcpt(recipient, rcpt_options)
except SMTPCommandFailedError as e:
errors.append(e)
if len(recipients) == len(errors):
raise SMTPNoRecipientError(errors)
await self.data(message)
return errors |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:run_fsm; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:self; 5, identifier:name; 6, identifier:command; 7, identifier:events; 8, identifier:transitions; 9, identifier:timeout; 10, default_parameter; 10, 11; 10, 12; 11, identifier:max_transitions; 12, integer:20; 13, block; 13, 14; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 23; 16, attribute; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_chain; 21, identifier:target_device; 22, identifier:run_fsm; 23, argument_list; 23, 24; 23, 25; 23, 26; 23, 27; 23, 28; 23, 29; 24, identifier:name; 25, identifier:command; 26, identifier:events; 27, identifier:transitions; 28, identifier:timeout; 29, identifier:max_transitions | def run_fsm(self, name, command, events, transitions, timeout, max_transitions=20):
return self._chain.target_device.run_fsm(name, command, events, transitions, timeout, max_transitions) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_get_view_details; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:urlpatterns; 6, default_parameter; 6, 7; 6, 8; 7, identifier:parent; 8, string:''; 9, block; 9, 10; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:pattern; 12, identifier:urlpatterns; 13, block; 13, 14; 14, if_statement; 14, 15; 14, 22; 14, 218; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:pattern; 19, tuple; 19, 20; 19, 21; 20, identifier:URLPattern; 21, identifier:RegexURLPattern; 22, block; 22, 23; 23, try_statement; 23, 24; 23, 214; 24, block; 24, 25; 24, 32; 24, 40; 24, 44; 24, 48; 24, 52; 24, 79; 24, 90; 24, 109; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:d; 28, call; 28, 29; 28, 30; 29, identifier:describe_pattern; 30, argument_list; 30, 31; 31, identifier:pattern; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:docstr; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:pattern; 38, identifier:callback; 39, identifier:__doc__; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:method; 43, None; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:expected_json_response; 47, string:''; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:expected_url; 51, string:''; 52, if_statement; 52, 53; 52, 54; 53, identifier:docstr; 54, block; 54, 55; 54, 70; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:u; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:re; 61, identifier:findall; 62, argument_list; 62, 63; 62, 64; 62, 65; 63, string:r'URL: (.*)'; 64, identifier:docstr; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:flags; 67, attribute; 67, 68; 67, 69; 68, identifier:re; 69, identifier:DOTALL; 70, if_statement; 70, 71; 70, 72; 71, identifier:u; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:expected_url; 76, subscript; 76, 77; 76, 78; 77, identifier:u; 78, integer:0; 79, if_statement; 79, 80; 79, 88; 80, comparison_operator:not; 80, 81; 80, 82; 81, string:'view_class'; 82, call; 82, 83; 82, 84; 83, identifier:dir; 84, argument_list; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:pattern; 87, identifier:callback; 88, block; 88, 89; 89, continue_statement; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:possible_methods; 93, list_comprehension; 93, 94; 93, 95; 93, 105; 94, identifier:m; 95, for_in_clause; 95, 96; 95, 97; 96, identifier:m; 97, call; 97, 98; 97, 99; 98, identifier:dir; 99, argument_list; 99, 100; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:pattern; 103, identifier:callback; 104, identifier:view_class; 105, if_clause; 105, 106; 106, comparison_operator:in; 106, 107; 106, 108; 107, identifier:m; 108, identifier:METHODS; 109, for_statement; 109, 110; 109, 111; 109, 112; 110, identifier:method; 111, identifier:possible_methods; 112, block; 112, 113; 112, 127; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:view_method_docstr; 116, attribute; 116, 117; 116, 126; 117, call; 117, 118; 117, 119; 118, identifier:getattr; 119, argument_list; 119, 120; 119, 125; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:pattern; 123, identifier:callback; 124, identifier:view_class; 125, identifier:method; 126, identifier:__doc__; 127, if_statement; 127, 128; 127, 129; 128, identifier:view_method_docstr; 129, block; 129, 130; 129, 154; 129, 169; 130, if_statement; 130, 131; 130, 137; 131, comparison_operator:in; 131, 132; 131, 133; 132, identifier:method; 133, list:['put', 'patch', 'delete']; 133, 134; 133, 135; 133, 136; 134, string:'put'; 135, string:'patch'; 136, string:'delete'; 137, block; 137, 138; 137, 153; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:url_details; 144, identifier:append; 145, argument_list; 145, 146; 146, dictionary; 146, 147; 146, 150; 147, pair; 147, 148; 147, 149; 148, string:'url'; 149, identifier:expected_url; 150, pair; 150, 151; 150, 152; 151, string:'method'; 152, identifier:method; 153, continue_statement; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:j; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:re; 160, identifier:findall; 161, argument_list; 161, 162; 161, 163; 161, 164; 162, string:r'```(.*)```'; 163, identifier:view_method_docstr; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:flags; 166, attribute; 166, 167; 166, 168; 167, identifier:re; 168, identifier:DOTALL; 169, if_statement; 169, 170; 169, 173; 170, comparison_operator:is; 170, 171; 170, 172; 171, identifier:j; 172, None; 173, block; 173, 174; 174, for_statement; 174, 175; 174, 176; 174, 177; 175, identifier:match; 176, identifier:j; 177, block; 177, 178; 177, 186; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:expected_json_response; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:match; 184, identifier:strip; 185, argument_list; 186, if_statement; 186, 187; 186, 194; 187, boolean_operator:and; 187, 188; 187, 193; 188, boolean_operator:and; 188, 189; 188, 192; 189, comparison_operator:is; 189, 190; 189, 191; 190, identifier:method; 191, None; 192, identifier:expected_json_response; 193, identifier:expected_url; 194, block; 194, 195; 194, 213; 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:url_details; 201, identifier:append; 202, argument_list; 202, 203; 203, dictionary; 203, 204; 203, 207; 203, 210; 204, pair; 204, 205; 204, 206; 205, string:'url'; 206, identifier:expected_url; 207, pair; 207, 208; 207, 209; 208, string:'method'; 209, identifier:method; 210, pair; 210, 211; 210, 212; 211, string:'response'; 212, identifier:expected_json_response; 213, continue_statement; 214, except_clause; 214, 215; 214, 216; 215, identifier:ViewDoesNotExist; 216, block; 216, 217; 217, pass_statement; 218, elif_clause; 218, 219; 218, 226; 219, call; 219, 220; 219, 221; 220, identifier:isinstance; 221, argument_list; 221, 222; 221, 223; 222, identifier:pattern; 223, tuple; 223, 224; 223, 225; 224, identifier:URLResolver; 225, identifier:RegexURLResolver; 226, block; 226, 227; 226, 239; 226, 246; 226, 252; 227, try_statement; 227, 228; 227, 235; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:patterns; 232, attribute; 232, 233; 232, 234; 233, identifier:pattern; 234, identifier:url_patterns; 235, except_clause; 235, 236; 235, 237; 236, identifier:ImportError; 237, block; 237, 238; 238, continue_statement; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:d; 242, call; 242, 243; 242, 244; 243, identifier:describe_pattern; 244, argument_list; 244, 245; 245, identifier:pattern; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:current_full_url; 249, binary_operator:+; 249, 250; 249, 251; 250, identifier:parent; 251, identifier:d; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:_get_view_details; 257, argument_list; 257, 258; 257, 259; 258, identifier:patterns; 259, identifier:current_full_url | def _get_view_details(self, urlpatterns, parent=''):
for pattern in urlpatterns:
if isinstance(pattern, (URLPattern, RegexURLPattern)):
try:
d = describe_pattern(pattern)
docstr = pattern.callback.__doc__
method = None
expected_json_response = ''
expected_url = ''
if docstr:
u = re.findall(r'URL: (.*)', docstr, flags=re.DOTALL)
if u:
expected_url = u[0]
if 'view_class' not in dir(pattern.callback):
continue
possible_methods = [m for m in dir(pattern.callback.view_class) if m in METHODS]
for method in possible_methods:
view_method_docstr = getattr(pattern.callback.view_class, method).__doc__
if view_method_docstr:
if method in ['put', 'patch', 'delete']:
self.url_details.append({
'url': expected_url,
'method': method
})
continue
j = re.findall(r'```(.*)```', view_method_docstr, flags=re.DOTALL)
if j is not None:
for match in j:
expected_json_response = match.strip()
if method is not None and expected_json_response and expected_url:
self.url_details.append({
'url': expected_url,
'method': method,
'response': expected_json_response
})
continue
except ViewDoesNotExist:
pass
elif isinstance(pattern, (URLResolver, RegexURLResolver)):
try:
patterns = pattern.url_patterns
except ImportError:
continue
d = describe_pattern(pattern)
current_full_url = parent + d
self._get_view_details(patterns, current_full_url) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:scan_module; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:modpath; 6, identifier:node; 7, block; 7, 8; 7, 22; 7, 89; 7, 184; 7, 230; 7, 261; 7, 267; 7, 273; 7, 313; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:used_origins; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:map; 16, identifier:setdefault; 17, argument_list; 17, 18; 17, 19; 18, identifier:modpath; 19, call; 19, 20; 19, 21; 20, identifier:set; 21, argument_list; 22, function_definition; 22, 23; 22, 24; 22, 27; 23, function_name:get_origins; 24, parameters; 24, 25; 24, 26; 25, identifier:modpath; 26, identifier:name; 27, block; 27, 28; 27, 34; 27, 81; 27, 87; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:origins; 31, call; 31, 32; 31, 33; 32, identifier:set; 33, argument_list; 34, function_definition; 34, 35; 34, 36; 34, 39; 35, function_name:walk_origins; 36, parameters; 36, 37; 36, 38; 37, identifier:modpath; 38, identifier:name; 39, block; 39, 40; 40, for_statement; 40, 41; 40, 42; 40, 51; 41, identifier:origin; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:import_map; 47, identifier:get_origins; 48, argument_list; 48, 49; 48, 50; 49, identifier:modpath; 50, identifier:name; 51, block; 51, 52; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:not; 53, 54; 53, 55; 54, identifier:origin; 55, identifier:origins; 56, block; 56, 57; 56, 64; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:origins; 61, identifier:add; 62, argument_list; 62, 63; 63, identifier:origin; 64, if_statement; 64, 65; 64, 68; 65, comparison_operator:in; 65, 66; 65, 67; 66, string:'.'; 67, identifier:origin; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:walk_origins; 72, argument_list; 72, 73; 73, list_splat; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:origin; 77, identifier:rsplit; 78, argument_list; 78, 79; 78, 80; 79, string:'.'; 80, integer:1; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:walk_origins; 84, argument_list; 84, 85; 84, 86; 85, identifier:modpath; 86, identifier:name; 87, return_statement; 87, 88; 88, identifier:origins; 89, function_definition; 89, 90; 89, 91; 89, 93; 90, function_name:get_origins_for_node; 91, parameters; 91, 92; 92, identifier:node; 93, block; 93, 94; 93, 128; 93, 180; 94, if_statement; 94, 95; 94, 110; 95, boolean_operator:and; 95, 96; 95, 102; 96, comparison_operator:==; 96, 97; 96, 101; 97, call; 97, 98; 97, 99; 98, identifier:node_type; 99, argument_list; 99, 100; 100, identifier:node; 101, string:'Name'; 102, comparison_operator:==; 102, 103; 102, 109; 103, call; 103, 104; 103, 105; 104, identifier:node_type; 105, argument_list; 105, 106; 106, attribute; 106, 107; 106, 108; 107, identifier:node; 108, identifier:ctx; 109, string:'Load'; 110, block; 110, 111; 111, return_statement; 111, 112; 112, binary_operator:|; 112, 113; 112, 121; 113, set; 113, 114; 114, binary_operator:+; 114, 115; 114, 118; 115, binary_operator:+; 115, 116; 115, 117; 116, identifier:modpath; 117, string:'.'; 118, attribute; 118, 119; 118, 120; 119, identifier:node; 120, identifier:id; 121, call; 121, 122; 121, 123; 122, identifier:get_origins; 123, argument_list; 123, 124; 123, 125; 124, identifier:modpath; 125, attribute; 125, 126; 125, 127; 126, identifier:node; 127, identifier:id; 128, if_statement; 128, 129; 128, 144; 129, boolean_operator:and; 129, 130; 129, 136; 130, comparison_operator:==; 130, 131; 130, 135; 131, call; 131, 132; 131, 133; 132, identifier:node_type; 133, argument_list; 133, 134; 134, identifier:node; 135, string:'Attribute'; 136, comparison_operator:==; 136, 137; 136, 143; 137, call; 137, 138; 137, 139; 138, identifier:node_type; 139, argument_list; 139, 140; 140, attribute; 140, 141; 140, 142; 141, identifier:node; 142, identifier:ctx; 143, string:'Load'; 144, block; 144, 145; 145, return_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:set; 149, identifier:union; 150, argument_list; 150, 151; 150, 154; 151, call; 151, 152; 151, 153; 152, identifier:set; 153, argument_list; 154, list_splat; 154, 155; 155, list_comprehension; 155, 156; 155, 172; 156, binary_operator:|; 156, 157; 156, 165; 157, set; 157, 158; 158, binary_operator:+; 158, 159; 158, 162; 159, binary_operator:+; 159, 160; 159, 161; 160, identifier:parent; 161, string:'.'; 162, attribute; 162, 163; 162, 164; 163, identifier:node; 164, identifier:attr; 165, call; 165, 166; 165, 167; 166, identifier:get_origins; 167, argument_list; 167, 168; 167, 169; 168, identifier:parent; 169, attribute; 169, 170; 169, 171; 170, identifier:node; 171, identifier:attr; 172, for_in_clause; 172, 173; 172, 174; 173, identifier:parent; 174, call; 174, 175; 174, 176; 175, identifier:get_origins_for_node; 176, argument_list; 176, 177; 177, attribute; 177, 178; 177, 179; 178, identifier:node; 179, identifier:value; 180, return_statement; 180, 181; 181, call; 181, 182; 181, 183; 182, identifier:set; 183, argument_list; 184, function_definition; 184, 185; 184, 186; 184, 188; 185, function_name:get_origins_used_by_node; 186, parameters; 186, 187; 187, identifier:node; 188, block; 188, 189; 188, 202; 188, 226; 189, if_statement; 189, 190; 189, 196; 190, comparison_operator:==; 190, 191; 190, 195; 191, call; 191, 192; 191, 193; 192, identifier:node_type; 193, argument_list; 193, 194; 194, identifier:node; 195, string:'Name'; 196, block; 196, 197; 197, return_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:get_origins_for_node; 200, argument_list; 200, 201; 201, identifier:node; 202, if_statement; 202, 203; 202, 209; 203, comparison_operator:==; 203, 204; 203, 208; 204, call; 204, 205; 204, 206; 205, identifier:node_type; 206, argument_list; 206, 207; 207, identifier:node; 208, string:'Attribute'; 209, block; 209, 210; 210, return_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:set; 214, identifier:union; 215, argument_list; 215, 216; 215, 222; 216, call; 216, 217; 216, 218; 217, identifier:get_origins_used_by_node; 218, argument_list; 218, 219; 219, attribute; 219, 220; 219, 221; 220, identifier:node; 221, identifier:value; 222, call; 222, 223; 222, 224; 223, identifier:get_origins_for_node; 224, argument_list; 224, 225; 225, identifier:node; 226, return_statement; 226, 227; 227, call; 227, 228; 227, 229; 228, identifier:set; 229, argument_list; 230, function_definition; 230, 231; 230, 232; 230, 234; 231, function_name:scan_loads; 232, parameters; 232, 233; 233, identifier:node; 234, block; 234, 235; 234, 255; 235, if_statement; 235, 236; 235, 244; 236, comparison_operator:in; 236, 237; 236, 241; 237, call; 237, 238; 237, 239; 238, identifier:node_type; 239, argument_list; 239, 240; 240, identifier:node; 241, list:['Name', 'Attribute']; 241, 242; 241, 243; 242, string:'Name'; 243, string:'Attribute'; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:used_origins; 249, identifier:update; 250, argument_list; 250, 251; 251, call; 251, 252; 251, 253; 252, identifier:get_origins_used_by_node; 253, argument_list; 253, 254; 254, identifier:node; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:for_each_child; 258, argument_list; 258, 259; 258, 260; 259, identifier:node; 260, identifier:scan_loads; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 264; 263, identifier:for_each_child; 264, argument_list; 264, 265; 264, 266; 265, identifier:node; 266, identifier:scan_loads; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:intermediate_origins; 270, call; 270, 271; 270, 272; 271, identifier:set; 272, argument_list; 273, for_statement; 273, 274; 273, 275; 273, 276; 274, identifier:origin; 275, identifier:used_origins; 276, block; 276, 277; 276, 286; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:parts; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:origin; 283, identifier:split; 284, argument_list; 284, 285; 285, string:'.'; 286, for_statement; 286, 287; 286, 288; 286, 296; 287, identifier:i; 288, call; 288, 289; 288, 290; 289, identifier:range; 290, argument_list; 290, 291; 290, 292; 291, integer:1; 292, call; 292, 293; 292, 294; 293, identifier:len; 294, argument_list; 294, 295; 295, identifier:parts; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:intermediate_origins; 301, identifier:add; 302, argument_list; 302, 303; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, string:'.'; 306, identifier:join; 307, argument_list; 307, 308; 308, subscript; 308, 309; 308, 310; 309, identifier:parts; 310, slice; 310, 311; 310, 312; 311, colon; 312, identifier:i; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:used_origins; 317, identifier:update; 318, argument_list; 318, 319; 319, identifier:intermediate_origins | def scan_module(self, modpath, node):
used_origins = self.map.setdefault(modpath, set())
def get_origins(modpath, name):
origins = set()
def walk_origins(modpath, name):
for origin in self.import_map.get_origins(modpath, name):
if origin not in origins:
origins.add(origin)
if '.' in origin:
walk_origins(*origin.rsplit('.', 1))
walk_origins(modpath, name)
return origins
def get_origins_for_node(node):
if node_type(node) == 'Name' and node_type(node.ctx) == 'Load':
return {modpath + '.' + node.id} | get_origins(modpath, node.id)
if node_type(node) == 'Attribute' and node_type(node.ctx) == 'Load':
return set.union(set(), *[
{parent + '.' + node.attr} | get_origins(parent, node.attr)
for parent in get_origins_for_node(node.value)])
return set()
def get_origins_used_by_node(node):
if node_type(node) == 'Name':
return get_origins_for_node(node)
if node_type(node) == 'Attribute':
return set.union(get_origins_used_by_node(node.value),
get_origins_for_node(node))
return set()
def scan_loads(node):
if node_type(node) in ['Name', 'Attribute']:
used_origins.update(get_origins_used_by_node(node))
for_each_child(node, scan_loads)
for_each_child(node, scan_loads)
intermediate_origins = set()
for origin in used_origins:
parts = origin.split('.')
for i in range(1, len(parts)):
intermediate_origins.add('.'.join(parts[:i]))
used_origins.update(intermediate_origins) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:operations; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:op_types; 7, None; 8, block; 8, 9; 8, 22; 9, if_statement; 9, 10; 9, 12; 10, not_operator; 10, 11; 11, identifier:op_types; 12, block; 12, 13; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:op_types; 16, list:['message', 'action', 'sync', 'viewlock', 'savedchapter']; 16, 17; 16, 18; 16, 19; 16, 20; 16, 21; 17, string:'message'; 18, string:'action'; 19, string:'sync'; 20, string:'viewlock'; 21, string:'savedchapter'; 22, while_statement; 22, 23; 22, 34; 23, comparison_operator:<; 23, 24; 23, 31; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_handle; 29, identifier:tell; 30, argument_list; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_eof; 34, block; 34, 35; 34, 50; 34, 77; 34, 133; 34, 157; 34, 172; 34, 193; 34, 216; 34, 236; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:current_time; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:mgz; 42, identifier:util; 43, identifier:convert_to_timestamp; 44, argument_list; 44, 45; 45, binary_operator:/; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_time; 49, integer:1000; 50, try_statement; 50, 51; 50, 67; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:operation; 55, call; 55, 56; 55, 63; 56, attribute; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:mgz; 60, identifier:body; 61, identifier:operation; 62, identifier:parse_stream; 63, argument_list; 63, 64; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_handle; 67, except_clause; 67, 68; 67, 71; 68, tuple; 68, 69; 68, 70; 69, identifier:ConstructError; 70, identifier:ValueError; 71, block; 71, 72; 72, raise_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:MgzError; 75, argument_list; 75, 76; 76, string:'failed to parse body operation'; 77, if_statement; 77, 78; 77, 83; 78, comparison_operator:==; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:operation; 81, identifier:type; 82, string:'action'; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 92; 84, 117; 85, comparison_operator:in; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:operation; 89, identifier:action; 90, identifier:type; 91, identifier:ACTIONS_WITH_PLAYER_ID; 92, block; 92, 93; 92, 105; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:counter; 96, subscript; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_actions_by_player; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:operation; 103, identifier:action; 104, identifier:player_id; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:counter; 109, identifier:update; 110, argument_list; 110, 111; 111, list:[operation.action.type]; 111, 112; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:operation; 115, identifier:action; 116, identifier:type; 117, else_clause; 117, 118; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_actions_without_player; 125, identifier:update; 126, argument_list; 126, 127; 127, list:[operation.action.type]; 127, 128; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:operation; 131, identifier:action; 132, identifier:type; 133, if_statement; 133, 134; 133, 149; 134, boolean_operator:and; 134, 135; 134, 140; 135, comparison_operator:==; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:operation; 138, identifier:type; 139, string:'action'; 140, call; 140, 141; 140, 142; 141, identifier:isinstance; 142, argument_list; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:operation; 146, identifier:action; 147, identifier:type; 148, identifier:int; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 153; 152, identifier:print; 153, argument_list; 153, 154; 154, attribute; 154, 155; 154, 156; 155, identifier:operation; 156, identifier:action; 157, if_statement; 157, 158; 157, 163; 158, comparison_operator:==; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:operation; 161, identifier:type; 162, string:'sync'; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, augmented_assignment:+=; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:_time; 169, attribute; 169, 170; 169, 171; 170, identifier:operation; 171, identifier:time_increment; 172, if_statement; 172, 173; 172, 186; 173, boolean_operator:and; 173, 174; 173, 179; 174, comparison_operator:==; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:operation; 177, identifier:type; 178, string:'action'; 179, comparison_operator:==; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:operation; 183, identifier:action; 184, identifier:type; 185, string:'postgame'; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:_postgame; 192, identifier:operation; 193, if_statement; 193, 194; 193, 199; 194, comparison_operator:==; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:operation; 197, identifier:type; 198, string:'action'; 199, block; 199, 200; 199, 208; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:action; 203, call; 203, 204; 203, 205; 204, identifier:Action; 205, argument_list; 205, 206; 205, 207; 206, identifier:operation; 207, identifier:current_time; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:_parse_action; 213, argument_list; 213, 214; 213, 215; 214, identifier:action; 215, identifier:current_time; 216, if_statement; 216, 217; 216, 222; 217, comparison_operator:==; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:operation; 220, identifier:type; 221, string:'savedchapter'; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:_parse_lobby_chat; 228, argument_list; 228, 229; 228, 234; 228, 235; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:operation; 232, identifier:lobby; 233, identifier:messages; 234, string:'save'; 235, identifier:current_time; 236, if_statement; 236, 237; 236, 242; 236, 256; 236, 285; 237, comparison_operator:==; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:operation; 240, identifier:type; 241, string:'viewlock'; 242, block; 242, 243; 243, if_statement; 243, 244; 243, 249; 244, comparison_operator:in; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:operation; 247, identifier:type; 248, identifier:op_types; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, yield; 251, 252; 252, call; 252, 253; 252, 254; 253, identifier:Viewlock; 254, argument_list; 254, 255; 255, identifier:operation; 256, elif_clause; 256, 257; 256, 270; 257, boolean_operator:and; 257, 258; 257, 263; 258, comparison_operator:==; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:operation; 261, identifier:type; 262, string:'action'; 263, comparison_operator:!=; 263, 264; 263, 269; 264, attribute; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:operation; 267, identifier:action; 268, identifier:type; 269, string:'postgame'; 270, block; 270, 271; 271, if_statement; 271, 272; 271, 277; 272, comparison_operator:in; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:operation; 275, identifier:type; 276, identifier:op_types; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, yield; 279, 280; 280, call; 280, 281; 280, 282; 281, identifier:Action; 282, argument_list; 282, 283; 282, 284; 283, identifier:operation; 284, identifier:current_time; 285, elif_clause; 285, 286; 285, 305; 286, parenthesized_expression; 286, 287; 287, boolean_operator:and; 287, 288; 287, 300; 288, parenthesized_expression; 288, 289; 289, boolean_operator:or; 289, 290; 289, 295; 290, comparison_operator:==; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:operation; 293, identifier:type; 294, string:'message'; 295, comparison_operator:==; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:operation; 298, identifier:type; 299, string:'embedded'; 300, comparison_operator:==; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:operation; 303, identifier:subtype; 304, string:'chat'; 305, block; 305, 306; 305, 329; 305, 336; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:chat; 309, call; 309, 310; 309, 311; 310, identifier:ChatMessage; 311, argument_list; 311, 312; 311, 317; 311, 318; 311, 323; 311, 328; 312, attribute; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:operation; 315, identifier:data; 316, identifier:text; 317, identifier:current_time; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:self; 321, identifier:_players; 322, argument_list; 323, subscript; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:self; 326, identifier:_diplomacy; 327, string:'type'; 328, string:'game'; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:_parse_chat; 334, argument_list; 334, 335; 335, identifier:chat; 336, if_statement; 336, 337; 336, 342; 337, comparison_operator:in; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:operation; 340, identifier:type; 341, identifier:op_types; 342, block; 342, 343; 343, expression_statement; 343, 344; 344, yield; 344, 345; 345, identifier:chat | def operations(self, op_types=None):
if not op_types:
op_types = ['message', 'action', 'sync', 'viewlock', 'savedchapter']
while self._handle.tell() < self._eof:
current_time = mgz.util.convert_to_timestamp(self._time / 1000)
try:
operation = mgz.body.operation.parse_stream(self._handle)
except (ConstructError, ValueError):
raise MgzError('failed to parse body operation')
if operation.type == 'action':
if operation.action.type in ACTIONS_WITH_PLAYER_ID:
counter = self._actions_by_player[operation.action.player_id]
counter.update([operation.action.type])
else:
self._actions_without_player.update([operation.action.type])
if operation.type == 'action' and isinstance(operation.action.type, int):
print(operation.action)
if operation.type == 'sync':
self._time += operation.time_increment
if operation.type == 'action' and operation.action.type == 'postgame':
self._postgame = operation
if operation.type == 'action':
action = Action(operation, current_time)
self._parse_action(action, current_time)
if operation.type == 'savedchapter':
self._parse_lobby_chat(operation.lobby.messages, 'save', current_time)
if operation.type == 'viewlock':
if operation.type in op_types:
yield Viewlock(operation)
elif operation.type == 'action' and operation.action.type != 'postgame':
if operation.type in op_types:
yield Action(operation, current_time)
elif ((operation.type == 'message' or operation.type == 'embedded')
and operation.subtype == 'chat'):
chat = ChatMessage(operation.data.text, current_time,
self._players(), self._diplomacy['type'], 'game')
self._parse_chat(chat)
if operation.type in op_types:
yield chat |
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, 20; 5, 24; 5, 30; 5, 44; 5, 402; 5, 409; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:ctx; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:FSM; 12, identifier:Context; 13, argument_list; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:name; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:device; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:transition_counter; 23, integer:0; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:timeout; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:timeout; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:log; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, string:"{} Start"; 39, identifier:format; 40, argument_list; 40, 41; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:name; 44, while_statement; 44, 45; 44, 50; 45, comparison_operator:<; 45, 46; 45, 47; 46, identifier:transition_counter; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:max_transitions; 50, block; 50, 51; 50, 55; 50, 370; 51, expression_statement; 51, 52; 52, augmented_assignment:+=; 52, 53; 52, 54; 53, identifier:transition_counter; 54, integer:1; 55, try_statement; 55, 56; 55, 357; 56, block; 56, 57; 56, 63; 56, 148; 56, 156; 56, 166; 56, 178; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:start_time; 60, call; 60, 61; 60, 62; 61, identifier:time; 62, argument_list; 63, if_statement; 63, 64; 63, 69; 63, 93; 64, comparison_operator:is; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:init_pattern; 68, None; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:ctx; 74, identifier:event; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:ctrl; 80, identifier:expect; 81, argument_list; 81, 82; 81, 85; 81, 90; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:events; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:searchwindowsize; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:searchwindowsize; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:timeout; 92, identifier:timeout; 93, else_clause; 93, 94; 94, block; 94, 95; 94, 112; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:log; 100, argument_list; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, string:"INIT_PATTERN={}"; 104, identifier:format; 105, argument_list; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:pattern_to_str; 108, argument_list; 108, 109; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:init_pattern; 112, try_statement; 112, 113; 112, 129; 112, 140; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:ctx; 118, identifier:event; 119, call; 119, 120; 119, 125; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:events; 124, identifier:index; 125, argument_list; 125, 126; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:init_pattern; 129, except_clause; 129, 130; 129, 131; 130, identifier:ValueError; 131, block; 131, 132; 131, 139; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:log; 137, argument_list; 137, 138; 138, string:"INIT_PATTERN unknown."; 139, continue_statement; 140, finally_clause; 140, 141; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:init_pattern; 147, None; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:finish_time; 151, binary_operator:-; 151, 152; 151, 155; 152, call; 152, 153; 152, 154; 153, identifier:time; 154, argument_list; 155, identifier:start_time; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:key; 159, tuple; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:ctx; 162, identifier:event; 163, attribute; 163, 164; 163, 165; 164, identifier:ctx; 165, identifier:state; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:ctx; 170, identifier:pattern; 171, subscript; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:events; 175, attribute; 175, 176; 175, 177; 176, identifier:ctx; 177, identifier:event; 178, if_statement; 178, 179; 178, 184; 178, 337; 179, comparison_operator:in; 179, 180; 179, 181; 180, identifier:key; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:transition_table; 184, block; 184, 185; 184, 193; 184, 200; 184, 219; 184, 309; 184, 318; 184, 324; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:transition; 188, subscript; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:transition_table; 192, identifier:key; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 199; 195, pattern_list; 195, 196; 195, 197; 195, 198; 196, identifier:next_state; 197, identifier:action_instance; 198, identifier:next_timeout; 199, identifier:transition; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:log; 205, argument_list; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, string:"E={},S={},T={},RT={:.2f}"; 209, identifier:format; 210, argument_list; 210, 211; 210, 214; 210, 217; 210, 218; 211, attribute; 211, 212; 211, 213; 212, identifier:ctx; 213, identifier:event; 214, attribute; 214, 215; 214, 216; 215, identifier:ctx; 216, identifier:state; 217, identifier:timeout; 218, identifier:finish_time; 219, if_statement; 219, 220; 219, 230; 219, 254; 219, 275; 219, 287; 220, boolean_operator:and; 220, 221; 220, 225; 221, call; 221, 222; 221, 223; 222, identifier:callable; 223, argument_list; 223, 224; 224, identifier:action_instance; 225, not_operator; 225, 226; 226, call; 226, 227; 226, 228; 227, identifier:isclass; 228, argument_list; 228, 229; 229, identifier:action_instance; 230, block; 230, 231; 231, if_statement; 231, 232; 231, 237; 232, not_operator; 232, 233; 233, call; 233, 234; 233, 235; 234, identifier:action_instance; 235, argument_list; 235, 236; 236, identifier:ctx; 237, block; 237, 238; 237, 252; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:log; 243, argument_list; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, string:"Error: {}"; 247, identifier:format; 248, argument_list; 248, 249; 249, attribute; 249, 250; 249, 251; 250, identifier:ctx; 251, identifier:msg; 252, return_statement; 252, 253; 253, False; 254, elif_clause; 254, 255; 254, 260; 255, call; 255, 256; 255, 257; 256, identifier:isinstance; 257, argument_list; 257, 258; 257, 259; 258, identifier:action_instance; 259, identifier:Exception; 260, block; 260, 261; 260, 273; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:log; 266, argument_list; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, string:"A=Exception {}"; 270, identifier:format; 271, argument_list; 271, 272; 272, identifier:action_instance; 273, raise_statement; 273, 274; 274, identifier:action_instance; 275, elif_clause; 275, 276; 275, 279; 276, comparison_operator:is; 276, 277; 276, 278; 277, identifier:action_instance; 278, None; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:log; 285, argument_list; 285, 286; 286, string:"A=None"; 287, else_clause; 287, 288; 288, block; 288, 289; 288, 304; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:self; 293, identifier:log; 294, argument_list; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, string:"FSM Action is not callable: {}"; 298, identifier:format; 299, argument_list; 299, 300; 300, call; 300, 301; 300, 302; 301, identifier:str; 302, argument_list; 302, 303; 303, identifier:action_instance; 304, raise_statement; 304, 305; 305, call; 305, 306; 305, 307; 306, identifier:RuntimeWarning; 307, argument_list; 307, 308; 308, string:"FSM Action is not callable"; 309, if_statement; 309, 310; 309, 313; 310, comparison_operator:!=; 310, 311; 310, 312; 311, identifier:next_timeout; 312, integer:0; 313, block; 313, 314; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:timeout; 317, identifier:next_timeout; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:ctx; 322, identifier:state; 323, identifier:next_state; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:self; 328, identifier:log; 329, argument_list; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, string:"NS={},NT={}"; 333, identifier:format; 334, argument_list; 334, 335; 334, 336; 335, identifier:next_state; 336, identifier:timeout; 337, else_clause; 337, 338; 338, block; 338, 339; 338, 356; 339, expression_statement; 339, 340; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:self; 343, identifier:log; 344, argument_list; 344, 345; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, string:"Unknown transition: EVENT={},STATE={}"; 348, identifier:format; 349, argument_list; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:ctx; 352, identifier:event; 353, attribute; 353, 354; 353, 355; 354, identifier:ctx; 355, identifier:state; 356, continue_statement; 357, except_clause; 357, 358; 357, 359; 358, identifier:EOF; 359, block; 359, 360; 360, raise_statement; 360, 361; 361, call; 361, 362; 361, 363; 362, identifier:ConnectionError; 363, argument_list; 363, 364; 363, 365; 364, string:"Session closed unexpectedly"; 365, attribute; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:self; 368, identifier:ctrl; 369, identifier:hostname; 370, if_statement; 370, 371; 370, 379; 371, boolean_operator:or; 371, 372; 371, 375; 372, attribute; 372, 373; 372, 374; 373, identifier:ctx; 374, identifier:finished; 375, comparison_operator:==; 375, 376; 375, 377; 376, identifier:next_state; 377, unary_operator:-; 377, 378; 378, integer:1; 379, block; 379, 380; 379, 400; 380, expression_statement; 380, 381; 381, call; 381, 382; 381, 385; 382, attribute; 382, 383; 382, 384; 383, identifier:self; 384, identifier:log; 385, argument_list; 385, 386; 386, call; 386, 387; 386, 390; 387, attribute; 387, 388; 387, 389; 388, string:"{} Stop at E={},S={}"; 389, identifier:format; 390, argument_list; 390, 391; 390, 394; 390, 397; 391, attribute; 391, 392; 391, 393; 392, identifier:self; 393, identifier:name; 394, attribute; 394, 395; 394, 396; 395, identifier:ctx; 396, identifier:event; 397, attribute; 397, 398; 397, 399; 398, identifier:ctx; 399, identifier:state; 400, return_statement; 400, 401; 401, True; 402, expression_statement; 402, 403; 403, call; 403, 404; 403, 407; 404, attribute; 404, 405; 404, 406; 405, identifier:self; 406, identifier:log; 407, argument_list; 407, 408; 408, string:"FSM looped. Exiting"; 409, return_statement; 409, 410; 410, False | def run(self):
ctx = FSM.Context(self.name, self.device)
transition_counter = 0
timeout = self.timeout
self.log("{} Start".format(self.name))
while transition_counter < self.max_transitions:
transition_counter += 1
try:
start_time = time()
if self.init_pattern is None:
ctx.event = self.ctrl.expect(self.events, searchwindowsize=self.searchwindowsize, timeout=timeout)
else:
self.log("INIT_PATTERN={}".format(pattern_to_str(self.init_pattern)))
try:
ctx.event = self.events.index(self.init_pattern)
except ValueError:
self.log("INIT_PATTERN unknown.")
continue
finally:
self.init_pattern = None
finish_time = time() - start_time
key = (ctx.event, ctx.state)
ctx.pattern = self.events[ctx.event]
if key in self.transition_table:
transition = self.transition_table[key]
next_state, action_instance, next_timeout = transition
self.log("E={},S={},T={},RT={:.2f}".format(ctx.event, ctx.state, timeout, finish_time))
if callable(action_instance) and not isclass(action_instance):
if not action_instance(ctx):
self.log("Error: {}".format(ctx.msg))
return False
elif isinstance(action_instance, Exception):
self.log("A=Exception {}".format(action_instance))
raise action_instance
elif action_instance is None:
self.log("A=None")
else:
self.log("FSM Action is not callable: {}".format(str(action_instance)))
raise RuntimeWarning("FSM Action is not callable")
if next_timeout != 0:
timeout = next_timeout
ctx.state = next_state
self.log("NS={},NT={}".format(next_state, timeout))
else:
self.log("Unknown transition: EVENT={},STATE={}".format(ctx.event, ctx.state))
continue
except EOF:
raise ConnectionError("Session closed unexpectedly", self.ctrl.hostname)
if ctx.finished or next_state == -1:
self.log("{} Stop at E={},S={}".format(self.name, ctx.event, ctx.state))
return True
self.log("FSM looped. Exiting")
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:build; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:port; 6, integer:8000; 7, default_parameter; 7, 8; 7, 9; 8, identifier:fixtures; 9, None; 10, block; 10, 11; 10, 17; 10, 27; 10, 33; 10, 39; 10, 46; 10, 55; 10, 67; 10, 77; 10, 81; 10, 85; 10, 447; 10, 456; 10, 462; 10, 472; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:extractor; 14, call; 14, 15; 14, 16; 15, identifier:Extractor; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:parser; 20, call; 20, 21; 20, 22; 21, identifier:Parser; 22, argument_list; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:extractor; 25, identifier:url_details; 26, identifier:fixtures; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:parser; 31, identifier:parse; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:url_details; 36, attribute; 36, 37; 36, 38; 37, identifier:parser; 38, identifier:results; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:_store; 42, call; 42, 43; 42, 44; 43, identifier:get_store; 44, argument_list; 44, 45; 45, identifier:url_details; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:store; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:json; 52, identifier:dumps; 53, argument_list; 53, 54; 54, identifier:_store; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:variables; 58, call; 58, 59; 58, 60; 59, identifier:str; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:Variable; 63, argument_list; 63, 64; 63, 65; 63, 66; 64, string:'let'; 65, string:'store'; 66, identifier:store; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:functions; 70, binary_operator:+; 70, 71; 70, 76; 71, binary_operator:+; 71, 72; 71, 75; 72, binary_operator:+; 72, 73; 72, 74; 73, identifier:DATA_FINDER; 74, identifier:GET_HANDLER; 75, identifier:MODIFY_HANDLER; 76, identifier:POST_HANDLER; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:endpoints; 80, list:[]; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:endpoint_uris; 84, list:[]; 85, for_statement; 85, 86; 85, 87; 85, 90; 86, identifier:u; 87, attribute; 87, 88; 87, 89; 88, identifier:parser; 89, identifier:results; 90, block; 90, 91; 90, 97; 90, 126; 90, 136; 90, 157; 90, 221; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:endpoint; 94, call; 94, 95; 94, 96; 95, identifier:Endpoint; 96, argument_list; 97, if_statement; 97, 98; 97, 109; 97, 120; 98, comparison_operator:in; 98, 99; 98, 106; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:u; 103, string:'method'; 104, identifier:lower; 105, argument_list; 106, list:['get', 'post']; 106, 107; 106, 108; 107, string:'get'; 108, string:'post'; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:method; 113, call; 113, 114; 113, 119; 114, attribute; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:u; 117, string:'method'; 118, identifier:lower; 119, argument_list; 120, else_clause; 120, 121; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:method; 125, string:'modify'; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:response; 129, call; 129, 130; 129, 131; 130, identifier:str; 131, argument_list; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:ResponseBody; 134, argument_list; 134, 135; 135, identifier:method; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 143; 138, pattern_list; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:u; 141, string:'url'; 142, identifier:list_url; 143, call; 143, 144; 143, 145; 144, identifier:clean_url; 145, argument_list; 145, 146; 145, 149; 145, 150; 146, subscript; 146, 147; 146, 148; 147, identifier:u; 148, string:'full_url'; 149, identifier:_store; 150, call; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:u; 154, string:'method'; 155, identifier:lower; 156, argument_list; 157, if_statement; 157, 158; 157, 171; 158, boolean_operator:and; 158, 159; 158, 162; 159, comparison_operator:is; 159, 160; 159, 161; 160, identifier:list_url; 161, None; 162, comparison_operator:==; 162, 163; 162, 170; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:u; 167, string:'method'; 168, identifier:lower; 169, argument_list; 170, string:'get'; 171, block; 171, 172; 171, 178; 171, 187; 171, 205; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:list_endpoint; 175, call; 175, 176; 175, 177; 176, identifier:Endpoint; 177, argument_list; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:list_endpoint; 182, identifier:construct; 183, argument_list; 183, 184; 183, 185; 183, 186; 184, string:'get'; 185, identifier:list_url; 186, identifier:response; 187, if_statement; 187, 188; 187, 194; 188, comparison_operator:not; 188, 189; 188, 193; 189, call; 189, 190; 189, 191; 190, identifier:str; 191, argument_list; 191, 192; 192, identifier:list_endpoint; 193, identifier:endpoints; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:endpoints; 199, identifier:append; 200, argument_list; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:str; 203, argument_list; 203, 204; 204, identifier:list_endpoint; 205, if_statement; 205, 206; 205, 211; 206, comparison_operator:not; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:list_endpoint; 209, identifier:uri; 210, identifier:endpoint_uris; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:endpoint_uris; 216, identifier:append; 217, argument_list; 217, 218; 218, attribute; 218, 219; 218, 220; 219, identifier:list_endpoint; 220, identifier:uri; 221, if_statement; 221, 222; 221, 225; 221, 398; 222, comparison_operator:==; 222, 223; 222, 224; 223, identifier:method; 224, string:'modify'; 225, block; 225, 226; 225, 239; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:without_prefix; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:re; 232, identifier:sub; 233, argument_list; 233, 234; 233, 235; 233, 236; 234, string:r'\/(\w+)\_\_'; 235, string:''; 236, subscript; 236, 237; 236, 238; 237, identifier:u; 238, string:'url'; 239, for_statement; 239, 240; 239, 243; 239, 248; 240, pattern_list; 240, 241; 240, 242; 241, identifier:k; 242, identifier:v; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:_store; 246, identifier:items; 247, argument_list; 248, block; 248, 249; 249, if_statement; 249, 250; 249, 253; 250, comparison_operator:in; 250, 251; 250, 252; 251, identifier:without_prefix; 252, identifier:k; 253, block; 253, 254; 253, 264; 253, 273; 253, 277; 253, 292; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:options; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:v; 260, identifier:get; 261, argument_list; 261, 262; 261, 263; 262, string:'options'; 263, string:'{}'; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:options; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:ast; 270, identifier:literal_eval; 271, argument_list; 271, 272; 272, identifier:options; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:modifiers; 276, list:[]; 277, if_statement; 277, 278; 277, 281; 278, comparison_operator:is; 278, 279; 278, 280; 279, identifier:options; 280, None; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:modifiers; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:options; 288, identifier:get; 289, argument_list; 289, 290; 289, 291; 290, string:'modifiers'; 291, list:[]; 292, if_statement; 292, 293; 292, 294; 293, identifier:modifiers; 294, block; 294, 295; 295, for_statement; 295, 296; 295, 297; 295, 298; 296, identifier:mod; 297, identifier:modifiers; 298, block; 298, 299; 299, if_statement; 299, 300; 299, 309; 300, comparison_operator:==; 300, 301; 300, 308; 301, call; 301, 302; 301, 307; 302, attribute; 302, 303; 302, 306; 303, subscript; 303, 304; 303, 305; 304, identifier:u; 305, string:'method'; 306, identifier:lower; 307, argument_list; 308, identifier:mod; 309, block; 309, 310; 309, 316; 309, 320; 309, 349; 309, 364; 309, 382; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:mod_endpoint; 313, call; 313, 314; 313, 315; 314, identifier:Endpoint; 315, argument_list; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:uri; 319, identifier:without_prefix; 320, if_statement; 320, 321; 320, 335; 321, boolean_operator:and; 321, 322; 321, 330; 322, comparison_operator:is; 322, 323; 322, 329; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:v; 326, identifier:get; 327, argument_list; 327, 328; 328, string:'position'; 329, None; 330, comparison_operator:==; 330, 331; 330, 334; 331, subscript; 331, 332; 331, 333; 332, identifier:v; 333, string:'position'; 334, string:'url'; 335, block; 335, 336; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:uri; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:re; 342, identifier:sub; 343, argument_list; 343, 344; 343, 345; 343, 346; 344, string:r'\/?\_\_key'; 345, string:'/:id'; 346, subscript; 346, 347; 346, 348; 347, identifier:u; 348, string:'full_url'; 349, expression_statement; 349, 350; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:mod_endpoint; 353, identifier:construct; 354, argument_list; 354, 355; 354, 362; 354, 363; 355, call; 355, 356; 355, 361; 356, attribute; 356, 357; 356, 360; 357, subscript; 357, 358; 357, 359; 358, identifier:u; 359, string:'method'; 360, identifier:lower; 361, argument_list; 362, identifier:uri; 363, identifier:response; 364, if_statement; 364, 365; 364, 371; 365, comparison_operator:not; 365, 366; 365, 370; 366, call; 366, 367; 366, 368; 367, identifier:str; 368, argument_list; 368, 369; 369, identifier:mod_endpoint; 370, identifier:endpoints; 371, block; 371, 372; 372, expression_statement; 372, 373; 373, call; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, identifier:endpoints; 376, identifier:append; 377, argument_list; 377, 378; 378, call; 378, 379; 378, 380; 379, identifier:str; 380, argument_list; 380, 381; 381, identifier:mod_endpoint; 382, if_statement; 382, 383; 382, 388; 383, comparison_operator:not; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:mod_endpoint; 386, identifier:uri; 387, identifier:endpoint_uris; 388, block; 388, 389; 389, expression_statement; 389, 390; 390, call; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:endpoint_uris; 393, identifier:append; 394, argument_list; 394, 395; 395, attribute; 395, 396; 395, 397; 396, identifier:mod_endpoint; 397, identifier:uri; 398, else_clause; 398, 399; 399, block; 399, 400; 399, 413; 399, 431; 400, expression_statement; 400, 401; 401, call; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:endpoint; 404, identifier:construct; 405, argument_list; 405, 406; 405, 409; 405, 412; 406, subscript; 406, 407; 406, 408; 407, identifier:u; 408, string:'method'; 409, subscript; 409, 410; 409, 411; 410, identifier:u; 411, string:'url'; 412, identifier:response; 413, if_statement; 413, 414; 413, 420; 414, comparison_operator:not; 414, 415; 414, 419; 415, call; 415, 416; 415, 417; 416, identifier:str; 417, argument_list; 417, 418; 418, identifier:endpoint; 419, identifier:endpoints; 420, block; 420, 421; 421, expression_statement; 421, 422; 422, call; 422, 423; 422, 426; 423, attribute; 423, 424; 423, 425; 424, identifier:endpoints; 425, identifier:append; 426, argument_list; 426, 427; 427, call; 427, 428; 427, 429; 428, identifier:str; 429, argument_list; 429, 430; 430, identifier:endpoint; 431, if_statement; 431, 432; 431, 437; 432, comparison_operator:not; 432, 433; 432, 436; 433, attribute; 433, 434; 433, 435; 434, identifier:endpoint; 435, identifier:uri; 436, identifier:endpoint_uris; 437, block; 437, 438; 438, expression_statement; 438, 439; 439, call; 439, 440; 439, 443; 440, attribute; 440, 441; 440, 442; 441, identifier:endpoint_uris; 442, identifier:append; 443, argument_list; 443, 444; 444, attribute; 444, 445; 444, 446; 445, identifier:endpoint; 446, identifier:uri; 447, expression_statement; 447, 448; 448, assignment; 448, 449; 448, 450; 449, identifier:endpoints; 450, call; 450, 451; 450, 454; 451, attribute; 451, 452; 451, 453; 452, string:''; 453, identifier:join; 454, argument_list; 454, 455; 455, identifier:endpoints; 456, expression_statement; 456, 457; 457, assignment; 457, 458; 457, 459; 458, identifier:express; 459, call; 459, 460; 459, 461; 460, identifier:ExpressServer; 461, argument_list; 462, expression_statement; 462, 463; 463, call; 463, 464; 463, 467; 464, attribute; 464, 465; 464, 466; 465, identifier:express; 466, identifier:construct; 467, argument_list; 467, 468; 467, 469; 467, 470; 467, 471; 468, identifier:variables; 469, identifier:functions; 470, identifier:endpoints; 471, identifier:port; 472, return_statement; 472, 473; 473, identifier:express | def build(port=8000, fixtures=None):
extractor = Extractor()
parser = Parser(extractor.url_details, fixtures)
parser.parse()
url_details = parser.results
_store = get_store(url_details)
store = json.dumps(_store)
variables = str(Variable('let', 'store', store))
functions = DATA_FINDER + GET_HANDLER + MODIFY_HANDLER + POST_HANDLER
endpoints = []
endpoint_uris = []
for u in parser.results:
endpoint = Endpoint()
if u['method'].lower() in ['get', 'post']:
method = u['method'].lower()
else:
method = 'modify'
response = str(ResponseBody(method))
u['url'], list_url = clean_url(u['full_url'], _store, u['method'].lower())
if list_url is not None and u['method'].lower() == 'get':
list_endpoint = Endpoint()
list_endpoint.construct('get', list_url, response)
if str(list_endpoint) not in endpoints:
endpoints.append(str(list_endpoint))
if list_endpoint.uri not in endpoint_uris:
endpoint_uris.append(list_endpoint.uri)
if method == 'modify':
without_prefix = re.sub(r'\/(\w+)\_\_', '', u['url'])
for k, v in _store.items():
if without_prefix in k:
options = v.get('options', '{}')
options = ast.literal_eval(options)
modifiers = []
if options is not None:
modifiers = options.get('modifiers', [])
if modifiers:
for mod in modifiers:
if u['method'].lower() == mod:
mod_endpoint = Endpoint()
uri = without_prefix
if v.get('position') is not None and v['position'] == 'url':
uri = re.sub(r'\/?\_\_key', '/:id', u['full_url'])
mod_endpoint.construct(u['method'].lower(), uri, response)
if str(mod_endpoint) not in endpoints:
endpoints.append(str(mod_endpoint))
if mod_endpoint.uri not in endpoint_uris:
endpoint_uris.append(mod_endpoint.uri)
else:
endpoint.construct(u['method'], u['url'], response)
if str(endpoint) not in endpoints:
endpoints.append(str(endpoint))
if endpoint.uri not in endpoint_uris:
endpoint_uris.append(endpoint.uri)
endpoints = ''.join(endpoints)
express = ExpressServer()
express.construct(variables, functions, endpoints, port)
return express |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:gpg_decrypt; 3, parameters; 3, 4; 3, 5; 4, identifier:cfg; 5, default_parameter; 5, 6; 5, 7; 6, identifier:gpg_config; 7, None; 8, block; 8, 9; 8, 217; 8, 304; 9, function_definition; 9, 10; 9, 11; 9, 13; 10, function_name:decrypt; 11, parameters; 11, 12; 12, identifier:obj; 13, block; 13, 14; 13, 215; 14, if_statement; 14, 15; 14, 20; 14, 41; 14, 136; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:obj; 19, identifier:list; 20, block; 20, 21; 20, 25; 20, 39; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:res_v; 24, list:[]; 25, for_statement; 25, 26; 25, 27; 25, 28; 26, identifier:item; 27, identifier:obj; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:res_v; 33, identifier:append; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:decrypt; 37, argument_list; 37, 38; 38, identifier:item; 39, return_statement; 39, 40; 40, identifier:res_v; 41, elif_clause; 41, 42; 41, 47; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 46; 45, identifier:obj; 46, identifier:dict; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 52; 48, 115; 49, comparison_operator:in; 49, 50; 49, 51; 50, string:'_gpg'; 51, identifier:obj; 52, block; 52, 53; 53, try_statement; 53, 54; 53, 101; 54, block; 54, 55; 54, 66; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:decrypted; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:gpg; 61, identifier:decrypt; 62, argument_list; 62, 63; 63, subscript; 63, 64; 63, 65; 64, identifier:obj; 65, string:'_gpg'; 66, if_statement; 66, 67; 66, 70; 66, 89; 67, attribute; 67, 68; 67, 69; 68, identifier:decrypted; 69, identifier:ok; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:obj; 74, call; 74, 75; 74, 76; 75, identifier:n; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 88; 78, attribute; 78, 79; 78, 87; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:decrypted; 83, identifier:data; 84, identifier:decode; 85, argument_list; 85, 86; 86, string:'utf-8'; 87, identifier:encode; 88, argument_list; 89, else_clause; 89, 90; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:log; 95, identifier:error; 96, argument_list; 96, 97; 96, 98; 97, string:"gpg error unpacking secrets %s"; 98, attribute; 98, 99; 98, 100; 99, identifier:decrypted; 100, identifier:stderr; 101, except_clause; 101, 102; 101, 106; 102, as_pattern; 102, 103; 102, 104; 103, identifier:Exception; 104, as_pattern_target; 104, 105; 105, identifier:err; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:log; 111, identifier:error; 112, argument_list; 112, 113; 112, 114; 113, string:"error unpacking secrets %s"; 114, identifier:err; 115, else_clause; 115, 116; 116, block; 116, 117; 117, for_statement; 117, 118; 117, 121; 117, 126; 118, pattern_list; 118, 119; 118, 120; 119, identifier:k; 120, identifier:v; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:obj; 124, identifier:items; 125, argument_list; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:obj; 131, identifier:k; 132, call; 132, 133; 132, 134; 133, identifier:decrypt; 134, argument_list; 134, 135; 135, identifier:v; 136, else_clause; 136, 137; 137, block; 137, 138; 138, try_statement; 138, 139; 138, 205; 139, block; 139, 140; 140, if_statement; 140, 141; 140, 144; 141, comparison_operator:in; 141, 142; 141, 143; 142, string:'BEGIN PGP'; 143, identifier:obj; 144, block; 144, 145; 145, try_statement; 145, 146; 145, 191; 146, block; 146, 147; 146, 156; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:decrypted; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:gpg; 153, identifier:decrypt; 154, argument_list; 154, 155; 155, identifier:obj; 156, if_statement; 156, 157; 156, 160; 156, 179; 157, attribute; 157, 158; 157, 159; 158, identifier:decrypted; 159, identifier:ok; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:obj; 164, call; 164, 165; 164, 166; 165, identifier:n; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 178; 168, attribute; 168, 169; 168, 177; 169, call; 169, 170; 169, 175; 170, attribute; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:decrypted; 173, identifier:data; 174, identifier:decode; 175, argument_list; 175, 176; 176, string:'utf-8'; 177, identifier:encode; 178, argument_list; 179, else_clause; 179, 180; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:log; 185, identifier:error; 186, argument_list; 186, 187; 186, 188; 187, string:"gpg error unpacking secrets %s"; 188, attribute; 188, 189; 188, 190; 189, identifier:decrypted; 190, identifier:stderr; 191, except_clause; 191, 192; 191, 196; 192, as_pattern; 192, 193; 192, 194; 193, identifier:Exception; 194, as_pattern_target; 194, 195; 195, identifier:err; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:log; 201, identifier:error; 202, argument_list; 202, 203; 202, 204; 203, string:"error unpacking secrets %s"; 204, identifier:err; 205, except_clause; 205, 206; 205, 207; 206, identifier:TypeError; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:log; 212, identifier:debug; 213, argument_list; 213, 214; 214, string:'Pass on decryption. Only decrypt strings'; 215, return_statement; 215, 216; 216, identifier:obj; 217, if_statement; 217, 218; 217, 219; 218, identifier:GPG_IMPORTED; 219, block; 219, 220; 219, 275; 219, 299; 220, if_statement; 220, 221; 220, 223; 221, not_operator; 221, 222; 222, identifier:gpg_config; 223, block; 223, 224; 223, 228; 223, 235; 223, 248; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:gpg_config; 227, dictionary; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:defaults; 231, dictionary; 231, 232; 232, pair; 232, 233; 232, 234; 233, string:'homedir'; 234, string:'~/.gnupg/'; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:env_fields; 238, dictionary; 238, 239; 238, 242; 238, 245; 239, pair; 239, 240; 239, 241; 240, string:'homedir'; 241, string:'FIGGYPY_GPG_HOMEDIR'; 242, pair; 242, 243; 242, 244; 243, string:'binary'; 244, string:'FIGGYPY_GPG_BINARY'; 245, pair; 245, 246; 245, 247; 246, string:'keyring'; 247, string:'FIGGYPY_GPG_KEYRING'; 248, for_statement; 248, 249; 248, 252; 248, 257; 249, pattern_list; 249, 250; 249, 251; 250, identifier:k; 251, identifier:v; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:env_fields; 255, identifier:items; 256, argument_list; 257, block; 257, 258; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 263; 260, subscript; 260, 261; 260, 262; 261, identifier:gpg_config; 262, identifier:k; 263, call; 263, 264; 263, 265; 264, identifier:env_or_default; 265, argument_list; 265, 266; 265, 267; 266, identifier:v; 267, conditional_expression:if; 267, 268; 267, 271; 267, 274; 268, subscript; 268, 269; 268, 270; 269, identifier:defaults; 270, identifier:k; 271, comparison_operator:in; 271, 272; 271, 273; 272, identifier:k; 273, identifier:defaults; 274, None; 275, try_statement; 275, 276; 275, 287; 276, block; 276, 277; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:gpg; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:gnupg; 283, identifier:GPG; 284, argument_list; 284, 285; 285, dictionary_splat; 285, 286; 286, identifier:gpg_config; 287, except_clause; 287, 288; 287, 291; 288, tuple; 288, 289; 288, 290; 289, identifier:OSError; 290, identifier:RuntimeError; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:log; 296, identifier:exception; 297, argument_list; 297, 298; 298, string:'Failed to configure gpg. Will be unable to decrypt secrets.'; 299, return_statement; 299, 300; 300, call; 300, 301; 300, 302; 301, identifier:decrypt; 302, argument_list; 302, 303; 303, identifier:cfg; 304, return_statement; 304, 305; 305, identifier:cfg | def gpg_decrypt(cfg, gpg_config=None):
def decrypt(obj):
if isinstance(obj, list):
res_v = []
for item in obj:
res_v.append(decrypt(item))
return res_v
elif isinstance(obj, dict):
if '_gpg' in obj:
try:
decrypted = gpg.decrypt(obj['_gpg'])
if decrypted.ok:
obj = n(decrypted.data.decode('utf-8').encode())
else:
log.error("gpg error unpacking secrets %s", decrypted.stderr)
except Exception as err:
log.error("error unpacking secrets %s", err)
else:
for k, v in obj.items():
obj[k] = decrypt(v)
else:
try:
if 'BEGIN PGP' in obj:
try:
decrypted = gpg.decrypt(obj)
if decrypted.ok:
obj = n(decrypted.data.decode('utf-8').encode())
else:
log.error("gpg error unpacking secrets %s", decrypted.stderr)
except Exception as err:
log.error("error unpacking secrets %s", err)
except TypeError:
log.debug('Pass on decryption. Only decrypt strings')
return obj
if GPG_IMPORTED:
if not gpg_config:
gpg_config = {}
defaults = {'homedir': '~/.gnupg/'}
env_fields = {'homedir': 'FIGGYPY_GPG_HOMEDIR',
'binary': 'FIGGYPY_GPG_BINARY',
'keyring': 'FIGGYPY_GPG_KEYRING'}
for k, v in env_fields.items():
gpg_config[k] = env_or_default(v, defaults[k] if k in defaults else None)
try:
gpg = gnupg.GPG(**gpg_config)
except (OSError, RuntimeError):
log.exception('Failed to configure gpg. Will be unable to decrypt secrets.')
return decrypt(cfg)
return cfg |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_teams; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 19; 5, 23; 5, 192; 5, 200; 6, if_statement; 6, 7; 6, 12; 7, subscript; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_cache; 11, string:'teams'; 12, block; 12, 13; 13, return_statement; 13, 14; 14, subscript; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_cache; 18, string:'teams'; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:teams; 22, list:[]; 23, for_statement; 23, 24; 23, 27; 23, 37; 24, pattern_list; 24, 25; 24, 26; 25, identifier:j; 26, identifier:player; 27, call; 27, 28; 27, 29; 28, identifier:enumerate; 29, argument_list; 29, 30; 30, attribute; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_header; 35, identifier:initial; 36, identifier:players; 37, block; 37, 38; 37, 42; 37, 176; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:added; 41, False; 42, for_statement; 42, 43; 42, 44; 42, 58; 43, identifier:i; 44, call; 44, 45; 44, 46; 45, identifier:range; 46, argument_list; 46, 47; 46, 48; 47, integer:0; 48, call; 48, 49; 48, 50; 49, identifier:len; 50, argument_list; 50, 51; 51, attribute; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_header; 56, identifier:initial; 57, identifier:players; 58, block; 58, 59; 59, if_statement; 59, 60; 59, 69; 60, comparison_operator:==; 60, 61; 60, 68; 61, subscript; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:player; 65, identifier:attributes; 66, identifier:my_diplomacy; 67, identifier:i; 68, string:'ally'; 69, block; 69, 70; 69, 74; 69, 78; 69, 82; 69, 132; 69, 144; 69, 158; 69, 172; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:inner_team; 73, False; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:outer_team; 77, False; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:new_team; 81, True; 82, for_statement; 82, 83; 82, 86; 82, 90; 83, pattern_list; 83, 84; 83, 85; 84, identifier:t; 85, identifier:tl; 86, call; 86, 87; 86, 88; 87, identifier:enumerate; 88, argument_list; 88, 89; 89, identifier:teams; 90, block; 90, 91; 90, 104; 90, 118; 91, if_statement; 91, 92; 91, 99; 92, boolean_operator:or; 92, 93; 92, 96; 93, comparison_operator:in; 93, 94; 93, 95; 94, identifier:j; 95, identifier:tl; 96, comparison_operator:in; 96, 97; 96, 98; 97, identifier:i; 98, identifier:tl; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:new_team; 103, False; 104, if_statement; 104, 105; 104, 112; 105, boolean_operator:and; 105, 106; 105, 109; 106, comparison_operator:in; 106, 107; 106, 108; 107, identifier:j; 108, identifier:tl; 109, comparison_operator:not; 109, 110; 109, 111; 110, identifier:i; 111, identifier:tl; 112, block; 112, 113; 112, 117; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:inner_team; 116, identifier:t; 117, break_statement; 118, if_statement; 118, 119; 118, 126; 119, boolean_operator:and; 119, 120; 119, 123; 120, comparison_operator:not; 120, 121; 120, 122; 121, identifier:j; 122, identifier:tl; 123, comparison_operator:in; 123, 124; 123, 125; 124, identifier:i; 125, identifier:tl; 126, block; 126, 127; 126, 131; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:outer_team; 130, identifier:t; 131, break_statement; 132, if_statement; 132, 133; 132, 134; 133, identifier:new_team; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:teams; 139, identifier:append; 140, argument_list; 140, 141; 141, list:[i, j]; 141, 142; 141, 143; 142, identifier:i; 143, identifier:j; 144, if_statement; 144, 145; 144, 148; 145, comparison_operator:is; 145, 146; 145, 147; 146, identifier:inner_team; 147, False; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:teams; 154, identifier:inner_team; 155, identifier:append; 156, argument_list; 156, 157; 157, identifier:i; 158, if_statement; 158, 159; 158, 162; 159, comparison_operator:is; 159, 160; 159, 161; 160, identifier:outer_team; 161, False; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 170; 165, attribute; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:teams; 168, identifier:outer_team; 169, identifier:append; 170, argument_list; 170, 171; 171, identifier:j; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:added; 175, True; 176, if_statement; 176, 177; 176, 183; 177, boolean_operator:and; 177, 178; 177, 180; 178, not_operator; 178, 179; 179, identifier:added; 180, comparison_operator:!=; 180, 181; 180, 182; 181, identifier:j; 182, integer:0; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:teams; 188, identifier:append; 189, argument_list; 189, 190; 190, list:[j]; 190, 191; 191, identifier:j; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 199; 194, subscript; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:_cache; 198, string:'teams'; 199, identifier:teams; 200, return_statement; 200, 201; 201, identifier:teams | def get_teams(self):
if self._cache['teams']:
return self._cache['teams']
teams = []
for j, player in enumerate(self._header.initial.players):
added = False
for i in range(0, len(self._header.initial.players)):
if player.attributes.my_diplomacy[i] == 'ally':
inner_team = False
outer_team = False
new_team = True
for t, tl in enumerate(teams):
if j in tl or i in tl:
new_team = False
if j in tl and i not in tl:
inner_team = t
break
if j not in tl and i in tl:
outer_team = t
break
if new_team:
teams.append([i, j])
if inner_team is not False:
teams[inner_team].append(i)
if outer_team is not False:
teams[outer_team].append(j)
added = True
if not added and j != 0:
teams.append([j])
self._cache['teams'] = teams
return teams |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_settings; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:postgame; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:get_postgame; 13, argument_list; 14, return_statement; 14, 15; 15, dictionary; 15, 16; 15, 33; 15, 54; 15, 65; 15, 82; 15, 108; 15, 117; 15, 126; 15, 141; 15, 156; 15, 171; 15, 180; 15, 188; 15, 196; 16, pair; 16, 17; 16, 18; 17, string:'type'; 18, tuple; 18, 19; 18, 26; 19, attribute; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_header; 24, identifier:lobby; 25, identifier:game_type_id; 26, attribute; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_header; 31, identifier:lobby; 32, identifier:game_type; 33, pair; 33, 34; 33, 35; 34, string:'difficulty'; 35, tuple; 35, 36; 35, 45; 36, attribute; 36, 37; 36, 44; 37, attribute; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_header; 42, identifier:scenario; 43, identifier:game_settings; 44, identifier:difficulty_id; 45, attribute; 45, 46; 45, 53; 46, attribute; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_header; 51, identifier:scenario; 52, identifier:game_settings; 53, identifier:difficulty; 54, pair; 54, 55; 54, 56; 55, string:'population_limit'; 56, binary_operator:*; 56, 57; 56, 64; 57, attribute; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:_header; 62, identifier:lobby; 63, identifier:population_limit; 64, integer:25; 65, pair; 65, 66; 65, 67; 66, string:'map_reveal_choice'; 67, tuple; 67, 68; 67, 75; 68, attribute; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:_header; 73, identifier:lobby; 74, identifier:reveal_map_id; 75, attribute; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:_header; 80, identifier:lobby; 81, identifier:reveal_map; 82, pair; 82, 83; 82, 84; 83, string:'speed'; 84, tuple; 84, 85; 84, 92; 85, attribute; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_header; 90, identifier:replay; 91, identifier:game_speed_id; 92, call; 92, 93; 92, 100; 93, attribute; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:mgz; 97, identifier:const; 98, identifier:SPEEDS; 99, identifier:get; 100, argument_list; 100, 101; 101, attribute; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_header; 106, identifier:replay; 107, identifier:game_speed_id; 108, pair; 108, 109; 108, 110; 109, string:'cheats'; 110, attribute; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:_header; 115, identifier:replay; 116, identifier:cheats_enabled; 117, pair; 117, 118; 117, 119; 118, string:'lock_teams'; 119, attribute; 119, 120; 119, 125; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:_header; 124, identifier:lobby; 125, identifier:lock_teams; 126, pair; 126, 127; 126, 128; 127, string:'starting_resources'; 128, tuple; 128, 129; 128, 135; 129, conditional_expression:if; 129, 130; 129, 133; 129, 134; 130, attribute; 130, 131; 130, 132; 131, identifier:postgame; 132, identifier:resource_level_id; 133, identifier:postgame; 134, None; 135, conditional_expression:if; 135, 136; 135, 139; 135, 140; 136, attribute; 136, 137; 136, 138; 137, identifier:postgame; 138, identifier:resource_level; 139, identifier:postgame; 140, None; 141, pair; 141, 142; 141, 143; 142, string:'starting_age'; 143, tuple; 143, 144; 143, 150; 144, conditional_expression:if; 144, 145; 144, 148; 144, 149; 145, attribute; 145, 146; 145, 147; 146, identifier:postgame; 147, identifier:starting_age_id; 148, identifier:postgame; 149, None; 150, conditional_expression:if; 150, 151; 150, 154; 150, 155; 151, attribute; 151, 152; 151, 153; 152, identifier:postgame; 153, identifier:starting_age; 154, identifier:postgame; 155, None; 156, pair; 156, 157; 156, 158; 157, string:'victory_condition'; 158, tuple; 158, 159; 158, 165; 159, conditional_expression:if; 159, 160; 159, 163; 159, 164; 160, attribute; 160, 161; 160, 162; 161, identifier:postgame; 162, identifier:victory_type_id; 163, identifier:postgame; 164, None; 165, conditional_expression:if; 165, 166; 165, 169; 165, 170; 166, attribute; 166, 167; 166, 168; 167, identifier:postgame; 168, identifier:victory_type; 169, identifier:postgame; 170, None; 171, pair; 171, 172; 171, 173; 172, string:'team_together'; 173, conditional_expression:if; 173, 174; 173, 178; 173, 179; 174, not_operator; 174, 175; 175, attribute; 175, 176; 175, 177; 176, identifier:postgame; 177, identifier:team_together; 178, identifier:postgame; 179, None; 180, pair; 180, 181; 180, 182; 181, string:'all_technologies'; 182, conditional_expression:if; 182, 183; 182, 186; 182, 187; 183, attribute; 183, 184; 183, 185; 184, identifier:postgame; 185, identifier:all_techs; 186, identifier:postgame; 187, None; 188, pair; 188, 189; 188, 190; 189, string:'lock_speed'; 190, conditional_expression:if; 190, 191; 190, 194; 190, 195; 191, attribute; 191, 192; 191, 193; 192, identifier:postgame; 193, identifier:lock_speed; 194, identifier:postgame; 195, None; 196, pair; 196, 197; 196, 198; 197, string:'multiqueue'; 198, None | def get_settings(self):
postgame = self.get_postgame()
return {
'type': (
self._header.lobby.game_type_id,
self._header.lobby.game_type
),
'difficulty': (
self._header.scenario.game_settings.difficulty_id,
self._header.scenario.game_settings.difficulty
),
'population_limit': self._header.lobby.population_limit * 25,
'map_reveal_choice': (
self._header.lobby.reveal_map_id,
self._header.lobby.reveal_map
),
'speed': (
self._header.replay.game_speed_id,
mgz.const.SPEEDS.get(self._header.replay.game_speed_id)
),
'cheats': self._header.replay.cheats_enabled,
'lock_teams': self._header.lobby.lock_teams,
'starting_resources': (
postgame.resource_level_id if postgame else None,
postgame.resource_level if postgame else None,
),
'starting_age': (
postgame.starting_age_id if postgame else None,
postgame.starting_age if postgame else None
),
'victory_condition': (
postgame.victory_type_id if postgame else None,
postgame.victory_type if postgame else None
),
'team_together': not postgame.team_together if postgame else None,
'all_technologies': postgame.all_techs if postgame else None,
'lock_speed': postgame.lock_speed if postgame else None,
'multiqueue': None
} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_map; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 19; 5, 31; 5, 43; 5, 62; 5, 72; 5, 76; 5, 80; 5, 84; 5, 88; 5, 166; 5, 205; 5, 213; 5, 221; 5, 254; 5, 264; 5, 268; 5, 283; 5, 292; 5, 296; 5, 320; 5, 344; 5, 389; 6, if_statement; 6, 7; 6, 12; 7, subscript; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_cache; 11, string:'map'; 12, block; 12, 13; 13, return_statement; 13, 14; 14, subscript; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_cache; 18, string:'map'; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:map_id; 22, attribute; 22, 23; 22, 30; 23, attribute; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_header; 28, identifier:scenario; 29, identifier:game_settings; 30, identifier:map_id; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:instructions; 34, attribute; 34, 35; 34, 42; 35, attribute; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_header; 40, identifier:scenario; 41, identifier:messages; 42, identifier:instructions; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:size; 46, call; 46, 47; 46, 54; 47, attribute; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:mgz; 51, identifier:const; 52, identifier:MAP_SIZES; 53, identifier:get; 54, argument_list; 54, 55; 55, attribute; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_header; 60, identifier:map_info; 61, identifier:size_x; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:dimension; 65, attribute; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_header; 70, identifier:map_info; 71, identifier:size_x; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:custom; 75, True; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:name; 79, string:'Unknown'; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:language; 83, None; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:encoding; 87, string:'unknown'; 88, for_statement; 88, 89; 88, 90; 88, 91; 89, identifier:pair; 90, identifier:ENCODING_MARKERS; 91, block; 91, 92; 91, 98; 91, 104; 91, 113; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:marker; 95, subscript; 95, 96; 95, 97; 96, identifier:pair; 97, integer:0; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:test_encoding; 101, subscript; 101, 102; 101, 103; 102, identifier:pair; 103, integer:1; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:e_m; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:marker; 110, identifier:encode; 111, argument_list; 111, 112; 112, identifier:test_encoding; 113, for_statement; 113, 114; 113, 115; 113, 121; 114, identifier:line; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:instructions; 118, identifier:split; 119, argument_list; 119, 120; 120, string:b'\n'; 121, block; 121, 122; 121, 131; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:pos; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:line; 128, identifier:find; 129, argument_list; 129, 130; 130, identifier:e_m; 131, if_statement; 131, 132; 131, 136; 132, comparison_operator:>; 132, 133; 132, 134; 133, identifier:pos; 134, unary_operator:-; 134, 135; 135, integer:1; 136, block; 136, 137; 136, 141; 136, 159; 136, 165; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:encoding; 140, identifier:test_encoding; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:name; 144, call; 144, 145; 144, 157; 145, attribute; 145, 146; 145, 156; 146, subscript; 146, 147; 146, 148; 147, identifier:line; 148, slice; 148, 149; 148, 155; 149, binary_operator:+; 149, 150; 149, 151; 150, identifier:pos; 151, call; 151, 152; 151, 153; 152, identifier:len; 153, argument_list; 153, 154; 154, identifier:e_m; 155, colon; 156, identifier:decode; 157, argument_list; 157, 158; 158, identifier:encoding; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:language; 162, subscript; 162, 163; 162, 164; 163, identifier:pair; 164, integer:2; 165, break_statement; 166, if_statement; 166, 167; 166, 169; 167, not_operator; 167, 168; 168, identifier:language; 169, block; 169, 170; 169, 174; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:language; 173, string:'unknown'; 174, for_statement; 174, 175; 174, 176; 174, 177; 175, identifier:pair; 176, identifier:LANGUAGE_MARKERS; 177, block; 177, 178; 178, if_statement; 178, 179; 178, 197; 179, comparison_operator:>; 179, 180; 179, 195; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:instructions; 183, identifier:find; 184, argument_list; 184, 185; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:pair; 189, integer:0; 190, identifier:encode; 191, argument_list; 191, 192; 192, subscript; 192, 193; 192, 194; 193, identifier:pair; 194, integer:1; 195, unary_operator:-; 195, 196; 196, integer:1; 197, block; 197, 198; 197, 204; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:language; 201, subscript; 201, 202; 201, 203; 202, identifier:pair; 203, integer:2; 204, break_statement; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 212; 207, subscript; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:_cache; 211, string:'encoding'; 212, identifier:encoding; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 220; 215, subscript; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:_cache; 219, string:'language'; 220, identifier:language; 221, if_statement; 221, 222; 221, 225; 222, comparison_operator:!=; 222, 223; 222, 224; 223, identifier:map_id; 224, integer:44; 225, block; 225, 226; 225, 240; 225, 250; 226, if_statement; 226, 227; 226, 234; 227, comparison_operator:not; 227, 228; 227, 229; 228, identifier:map_id; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:mgz; 232, identifier:const; 233, identifier:MAP_NAMES; 234, block; 234, 235; 235, raise_statement; 235, 236; 236, call; 236, 237; 236, 238; 237, identifier:ValueError; 238, argument_list; 238, 239; 239, string:'unspecified builtin map'; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:name; 243, subscript; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:mgz; 247, identifier:const; 248, identifier:MAP_NAMES; 249, identifier:map_id; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:custom; 253, False; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:match; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:re; 260, identifier:search; 261, argument_list; 261, 262; 261, 263; 262, string:b'\x00.*? (\-?[0-9]+)\x00.*?\.rms'; 263, identifier:instructions; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:seed; 267, None; 268, if_statement; 268, 269; 268, 270; 269, identifier:match; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:seed; 274, call; 274, 275; 274, 276; 275, identifier:int; 276, argument_list; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:match; 280, identifier:group; 281, argument_list; 281, 282; 282, integer:1; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:has_modes; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:name; 289, identifier:find; 290, argument_list; 290, 291; 291, string:': !'; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:mode_string; 295, string:''; 296, if_statement; 296, 297; 296, 301; 297, comparison_operator:>; 297, 298; 297, 299; 298, identifier:has_modes; 299, unary_operator:-; 299, 300; 300, integer:1; 301, block; 301, 302; 301, 312; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:mode_string; 305, subscript; 305, 306; 305, 307; 306, identifier:name; 307, slice; 307, 308; 307, 311; 308, binary_operator:+; 308, 309; 308, 310; 309, identifier:has_modes; 310, integer:3; 311, colon; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:name; 315, subscript; 315, 316; 315, 317; 316, identifier:name; 317, slice; 317, 318; 317, 319; 318, colon; 319, identifier:has_modes; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:modes; 323, dictionary; 323, 324; 323, 329; 323, 334; 323, 339; 324, pair; 324, 325; 324, 326; 325, string:'direct_placement'; 326, comparison_operator:in; 326, 327; 326, 328; 327, string:'P'; 328, identifier:mode_string; 329, pair; 329, 330; 329, 331; 330, string:'effect_quantity'; 331, comparison_operator:in; 331, 332; 331, 333; 332, string:'C'; 333, identifier:mode_string; 334, pair; 334, 335; 334, 336; 335, string:'guard_state'; 336, comparison_operator:in; 336, 337; 336, 338; 337, string:'G'; 338, identifier:mode_string; 339, pair; 339, 340; 339, 341; 340, string:'fixed_positions'; 341, comparison_operator:in; 341, 342; 341, 343; 342, string:'F'; 343, identifier:mode_string; 344, expression_statement; 344, 345; 345, assignment; 345, 346; 345, 351; 346, subscript; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:self; 349, identifier:_cache; 350, string:'map'; 351, dictionary; 351, 352; 351, 359; 351, 366; 351, 369; 351, 372; 351, 375; 351, 378; 351, 381; 352, pair; 352, 353; 352, 354; 353, string:'id'; 354, conditional_expression:if; 354, 355; 354, 356; 354, 358; 355, identifier:map_id; 356, not_operator; 356, 357; 357, identifier:custom; 358, None; 359, pair; 359, 360; 359, 361; 360, string:'name'; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:name; 364, identifier:strip; 365, argument_list; 366, pair; 366, 367; 366, 368; 367, string:'size'; 368, identifier:size; 369, pair; 369, 370; 369, 371; 370, string:'dimension'; 371, identifier:dimension; 372, pair; 372, 373; 372, 374; 373, string:'seed'; 374, identifier:seed; 375, pair; 375, 376; 375, 377; 376, string:'modes'; 377, identifier:modes; 378, pair; 378, 379; 378, 380; 379, string:'custom'; 380, identifier:custom; 381, pair; 381, 382; 381, 383; 382, string:'zr'; 383, call; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:name; 386, identifier:startswith; 387, argument_list; 387, 388; 388, string:'ZR@'; 389, return_statement; 389, 390; 390, subscript; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:self; 393, identifier:_cache; 394, string:'map' | def get_map(self):
if self._cache['map']:
return self._cache['map']
map_id = self._header.scenario.game_settings.map_id
instructions = self._header.scenario.messages.instructions
size = mgz.const.MAP_SIZES.get(self._header.map_info.size_x)
dimension = self._header.map_info.size_x
custom = True
name = 'Unknown'
language = None
encoding = 'unknown'
for pair in ENCODING_MARKERS:
marker = pair[0]
test_encoding = pair[1]
e_m = marker.encode(test_encoding)
for line in instructions.split(b'\n'):
pos = line.find(e_m)
if pos > -1:
encoding = test_encoding
name = line[pos+len(e_m):].decode(encoding)
language = pair[2]
break
if not language:
language = 'unknown'
for pair in LANGUAGE_MARKERS:
if instructions.find(pair[0].encode(pair[1])) > -1:
language = pair[2]
break
self._cache['encoding'] = encoding
self._cache['language'] = language
if map_id != 44:
if map_id not in mgz.const.MAP_NAMES:
raise ValueError('unspecified builtin map')
name = mgz.const.MAP_NAMES[map_id]
custom = False
match = re.search(b'\x00.*? (\-?[0-9]+)\x00.*?\.rms', instructions)
seed = None
if match:
seed = int(match.group(1))
has_modes = name.find(': !')
mode_string = ''
if has_modes > -1:
mode_string = name[has_modes + 3:]
name = name[:has_modes]
modes = {
'direct_placement': 'P' in mode_string,
'effect_quantity': 'C' in mode_string,
'guard_state': 'G' in mode_string,
'fixed_positions': 'F' in mode_string
}
self._cache['map'] = {
'id': map_id if not custom else None,
'name': name.strip(),
'size': size,
'dimension': dimension,
'seed': seed,
'modes': modes,
'custom': custom,
'zr': name.startswith('ZR@')
}
return self._cache['map'] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:update; 3, parameters; 3, 4; 3, 5; 3, 7; 3, 12; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:sources; 7, typed_default_parameter; 7, 8; 7, 9; 7, 11; 8, identifier:follow_symlinks; 9, type; 9, 10; 10, identifier:bool; 11, False; 12, typed_default_parameter; 12, 13; 12, 14; 12, 16; 13, identifier:maximum_depth; 14, type; 14, 15; 15, identifier:int; 16, integer:20; 17, block; 17, 18; 18, for_statement; 18, 19; 18, 20; 18, 21; 19, identifier:source; 20, identifier:sources; 21, block; 21, 22; 21, 60; 21, 67; 22, if_statement; 22, 23; 22, 30; 23, call; 23, 24; 23, 25; 24, identifier:isinstance; 25, argument_list; 25, 26; 25, 27; 26, identifier:source; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:klass; 30, block; 30, 31; 30, 45; 30, 59; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 44; 33, subscript; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:path_map; 37, attribute; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:source; 41, identifier:this; 42, identifier:name; 43, identifier:value; 44, identifier:source; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 58; 47, subscript; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:class_cache; 51, attribute; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:source; 55, identifier:this; 56, identifier:name; 57, identifier:value; 58, identifier:source; 59, continue_statement; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:source; 63, call; 63, 64; 63, 65; 64, identifier:str; 65, argument_list; 65, 66; 66, identifier:source; 67, if_statement; 67, 68; 67, 80; 67, 109; 68, call; 68, 69; 68, 76; 69, attribute; 69, 70; 69, 75; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:source; 73, identifier:lower; 74, argument_list; 75, identifier:endswith; 76, argument_list; 76, 77; 77, tuple; 77, 78; 77, 79; 78, string:'.zip'; 79, string:'.jar'; 80, block; 80, 81; 80, 89; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:zf; 84, call; 84, 85; 84, 86; 85, identifier:ZipFile; 86, argument_list; 86, 87; 86, 88; 87, identifier:source; 88, string:'r'; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:path_map; 95, identifier:update; 96, argument_list; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:zip; 99, argument_list; 99, 100; 99, 105; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:zf; 103, identifier:namelist; 104, argument_list; 105, call; 105, 106; 105, 107; 106, identifier:repeat; 107, argument_list; 107, 108; 108, identifier:zf; 109, elif_clause; 109, 110; 109, 118; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:os; 114, identifier:path; 115, identifier:isdir; 116, argument_list; 116, 117; 117, identifier:source; 118, block; 118, 119; 118, 132; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:walker; 122, call; 122, 123; 122, 124; 123, identifier:_walk; 124, argument_list; 124, 125; 124, 126; 124, 129; 125, identifier:source; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:follow_links; 128, identifier:follow_symlinks; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:maximum_depth; 131, identifier:maximum_depth; 132, for_statement; 132, 133; 132, 137; 132, 138; 133, pattern_list; 133, 134; 133, 135; 133, 136; 134, identifier:root; 135, identifier:dirs; 136, identifier:files; 137, identifier:walker; 138, block; 138, 139; 139, for_statement; 139, 140; 139, 141; 139, 142; 140, identifier:file_; 141, identifier:files; 142, block; 142, 143; 142, 155; 142, 167; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:path_full; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:os; 150, identifier:path; 151, identifier:join; 152, argument_list; 152, 153; 152, 154; 153, identifier:root; 154, identifier:file_; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:path_suffix; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:os; 162, identifier:path; 163, identifier:relpath; 164, argument_list; 164, 165; 164, 166; 165, identifier:path_full; 166, identifier:source; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 174; 169, subscript; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:path_map; 173, identifier:path_suffix; 174, identifier:path_full | def update(self, *sources, follow_symlinks: bool=False,
maximum_depth: int=20):
for source in sources:
if isinstance(source, self.klass):
self.path_map[source.this.name.value] = source
self.class_cache[source.this.name.value] = source
continue
source = str(source)
if source.lower().endswith(('.zip', '.jar')):
zf = ZipFile(source, 'r')
self.path_map.update(zip(zf.namelist(), repeat(zf)))
elif os.path.isdir(source):
walker = _walk(
source,
follow_links=follow_symlinks,
maximum_depth=maximum_depth
)
for root, dirs, files in walker:
for file_ in files:
path_full = os.path.join(root, file_)
path_suffix = os.path.relpath(path_full, source)
self.path_map[path_suffix] = path_full |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:error_view; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:template_dir; 6, None; 7, block; 7, 8; 7, 16; 7, 22; 7, 212; 8, if_statement; 8, 9; 8, 11; 9, not_operator; 9, 10; 10, identifier:template_dir; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:template_dir; 15, string:"Pylot/Error"; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:template_page; 19, binary_operator:%; 19, 20; 19, 21; 20, string:"%s/index.html"; 21, identifier:template_dir; 22, class_definition; 22, 23; 22, 24; 22, 26; 23, identifier:Error; 24, argument_list; 24, 25; 25, identifier:Pylot; 26, block; 26, 27; 26, 177; 27, decorated_definition; 27, 28; 27, 30; 28, decorator; 28, 29; 29, identifier:classmethod; 30, function_definition; 30, 31; 30, 32; 30, 37; 31, function_name:register; 32, parameters; 32, 33; 32, 34; 32, 35; 33, identifier:cls; 34, identifier:app; 35, dictionary_splat_pattern; 35, 36; 36, identifier:kwargs; 37, block; 37, 38; 37, 51; 37, 72; 37, 93; 37, 114; 37, 135; 37, 156; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 47; 40, attribute; 40, 41; 40, 46; 41, call; 41, 42; 41, 43; 42, identifier:super; 43, argument_list; 43, 44; 43, 45; 44, identifier:cls; 45, identifier:cls; 46, identifier:register; 47, argument_list; 47, 48; 47, 49; 48, identifier:app; 49, dictionary_splat; 49, 50; 50, identifier:kwargs; 51, decorated_definition; 51, 52; 51, 59; 52, decorator; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:app; 56, identifier:errorhandler; 57, argument_list; 57, 58; 58, integer:400; 59, function_definition; 59, 60; 59, 61; 59, 63; 60, function_name:error_400; 61, parameters; 61, 62; 62, identifier:error; 63, block; 63, 64; 64, return_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:cls; 68, identifier:index; 69, argument_list; 69, 70; 69, 71; 70, identifier:error; 71, integer:400; 72, decorated_definition; 72, 73; 72, 80; 73, decorator; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:app; 77, identifier:errorhandler; 78, argument_list; 78, 79; 79, integer:401; 80, function_definition; 80, 81; 80, 82; 80, 84; 81, function_name:error_401; 82, parameters; 82, 83; 83, identifier:error; 84, block; 84, 85; 85, return_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:cls; 89, identifier:index; 90, argument_list; 90, 91; 90, 92; 91, identifier:error; 92, integer:401; 93, decorated_definition; 93, 94; 93, 101; 94, decorator; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:app; 98, identifier:errorhandler; 99, argument_list; 99, 100; 100, integer:403; 101, function_definition; 101, 102; 101, 103; 101, 105; 102, function_name:error_403; 103, parameters; 103, 104; 104, identifier:error; 105, block; 105, 106; 106, return_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:cls; 110, identifier:index; 111, argument_list; 111, 112; 111, 113; 112, identifier:error; 113, integer:403; 114, decorated_definition; 114, 115; 114, 122; 115, decorator; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:app; 119, identifier:errorhandler; 120, argument_list; 120, 121; 121, integer:404; 122, function_definition; 122, 123; 122, 124; 122, 126; 123, function_name:error_404; 124, parameters; 124, 125; 125, identifier:error; 126, block; 126, 127; 127, return_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:cls; 131, identifier:index; 132, argument_list; 132, 133; 132, 134; 133, identifier:error; 134, integer:404; 135, decorated_definition; 135, 136; 135, 143; 136, decorator; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:app; 140, identifier:errorhandler; 141, argument_list; 141, 142; 142, integer:500; 143, function_definition; 143, 144; 143, 145; 143, 147; 144, function_name:error_500; 145, parameters; 145, 146; 146, identifier:error; 147, block; 147, 148; 148, return_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:cls; 152, identifier:index; 153, argument_list; 153, 154; 153, 155; 154, identifier:error; 155, integer:500; 156, decorated_definition; 156, 157; 156, 164; 157, decorator; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:app; 161, identifier:errorhandler; 162, argument_list; 162, 163; 163, integer:503; 164, function_definition; 164, 165; 164, 166; 164, 168; 165, function_name:error_503; 166, parameters; 166, 167; 167, identifier:error; 168, block; 168, 169; 169, return_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:cls; 173, identifier:index; 174, argument_list; 174, 175; 174, 176; 175, identifier:error; 176, integer:503; 177, decorated_definition; 177, 178; 177, 180; 178, decorator; 178, 179; 179, identifier:classmethod; 180, function_definition; 180, 181; 180, 182; 180, 186; 181, function_name:index; 182, parameters; 182, 183; 182, 184; 182, 185; 183, identifier:cls; 184, identifier:error; 185, identifier:code; 186, block; 186, 187; 186, 198; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:cls; 191, identifier:meta_; 192, argument_list; 192, 193; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:title; 195, binary_operator:%; 195, 196; 195, 197; 196, string:"Error %s"; 197, identifier:code; 198, return_statement; 198, 199; 199, expression_list; 199, 200; 199, 211; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:cls; 203, identifier:render; 204, argument_list; 204, 205; 204, 208; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:error; 207, identifier:error; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:view_template; 210, identifier:template_page; 211, identifier:code; 212, return_statement; 212, 213; 213, identifier:Error | def error_view(template_dir=None):
if not template_dir:
template_dir = "Pylot/Error"
template_page = "%s/index.html" % template_dir
class Error(Pylot):
@classmethod
def register(cls, app, **kwargs):
super(cls, cls).register(app, **kwargs)
@app.errorhandler(400)
def error_400(error):
return cls.index(error, 400)
@app.errorhandler(401)
def error_401(error):
return cls.index(error, 401)
@app.errorhandler(403)
def error_403(error):
return cls.index(error, 403)
@app.errorhandler(404)
def error_404(error):
return cls.index(error, 404)
@app.errorhandler(500)
def error_500(error):
return cls.index(error, 500)
@app.errorhandler(503)
def error_503(error):
return cls.index(error, 503)
@classmethod
def index(cls, error, code):
cls.meta_(title="Error %s" % code)
return cls.render(error=error, view_template=template_page), code
return Error |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:update_device_list; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:sessions; 6, block; 6, 7; 6, 20; 6, 24; 6, 28; 6, 32; 6, 217; 6, 262; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:is; 8, 9; 8, 10; 9, identifier:sessions; 10, None; 11, block; 11, 12; 11, 19; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:_LOGGER; 16, identifier:error; 17, argument_list; 17, 18; 18, string:'Error updating Emby devices.'; 19, return_statement; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:new_devices; 23, list:[]; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:active_devices; 27, list:[]; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:dev_update; 31, False; 32, for_statement; 32, 33; 32, 34; 32, 35; 33, identifier:device; 34, identifier:sessions; 35, block; 35, 36; 35, 50; 35, 74; 35, 81; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:dev_name; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, string:'{}.{}'; 42, identifier:format; 43, argument_list; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:device; 46, string:'DeviceId'; 47, subscript; 47, 48; 47, 49; 48, identifier:device; 49, string:'Client'; 50, try_statement; 50, 51; 50, 70; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:_LOGGER; 56, identifier:debug; 57, argument_list; 57, 58; 57, 59; 57, 60; 57, 65; 58, string:'Session msg on %s of type: %s, themeflag: %s'; 59, identifier:dev_name; 60, subscript; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:device; 63, string:'NowPlayingItem'; 64, string:'Type'; 65, subscript; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:device; 68, string:'NowPlayingItem'; 69, string:'IsThemeMedia'; 70, except_clause; 70, 71; 70, 72; 71, identifier:KeyError; 72, block; 72, 73; 73, pass_statement; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:active_devices; 78, identifier:append; 79, argument_list; 79, 80; 80, identifier:dev_name; 81, if_statement; 81, 82; 81, 99; 81, 131; 82, boolean_operator:and; 82, 83; 82, 88; 82, 89; 83, comparison_operator:not; 83, 84; 83, 85; 84, identifier:dev_name; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:_devices; 88, line_continuation:\; 89, comparison_operator:!=; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:device; 92, string:'DeviceId'; 93, call; 93, 94; 93, 95; 94, identifier:str; 95, argument_list; 95, 96; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_api_id; 99, block; 99, 100; 99, 108; 99, 116; 99, 124; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:_LOGGER; 104, identifier:debug; 105, argument_list; 105, 106; 105, 107; 106, string:'New Emby DeviceID: %s. Adding to device list.'; 107, identifier:dev_name; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:new; 111, call; 111, 112; 111, 113; 112, identifier:EmbyDevice; 113, argument_list; 113, 114; 113, 115; 114, identifier:device; 115, identifier:self; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 123; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:_devices; 122, identifier:dev_name; 123, identifier:new; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:new_devices; 128, identifier:append; 129, argument_list; 129, 130; 130, identifier:new; 131, elif_clause; 131, 132; 131, 142; 132, comparison_operator:!=; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:device; 135, string:'DeviceId'; 136, call; 136, 137; 136, 138; 137, identifier:str; 138, argument_list; 138, 139; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:_api_id; 142, block; 142, 143; 142, 157; 142, 171; 142, 182; 142, 193; 142, 207; 143, if_statement; 143, 144; 143, 152; 144, not_operator; 144, 145; 145, attribute; 145, 146; 145, 151; 146, subscript; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:_devices; 150, identifier:dev_name; 151, identifier:is_active; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:dev_update; 156, True; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:do_update; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:update_check; 164, argument_list; 164, 165; 164, 170; 165, subscript; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:_devices; 169, identifier:dev_name; 170, identifier:device; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 180; 173, attribute; 173, 174; 173, 179; 174, subscript; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:_devices; 178, identifier:dev_name; 179, identifier:update_data; 180, argument_list; 180, 181; 181, identifier:device; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 191; 184, attribute; 184, 185; 184, 190; 185, subscript; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:_devices; 189, identifier:dev_name; 190, identifier:set_active; 191, argument_list; 191, 192; 192, True; 193, if_statement; 193, 194; 193, 195; 194, identifier:dev_update; 195, block; 195, 196; 195, 203; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:_do_new_devices_callback; 201, argument_list; 201, 202; 202, integer:0; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:dev_update; 206, False; 207, if_statement; 207, 208; 207, 209; 208, identifier:do_update; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:_do_update_callback; 215, argument_list; 215, 216; 216, identifier:dev_name; 217, for_statement; 217, 218; 217, 219; 217, 222; 218, identifier:dev_id; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:_devices; 222, block; 222, 223; 223, if_statement; 223, 224; 223, 227; 224, comparison_operator:not; 224, 225; 224, 226; 225, identifier:dev_id; 226, identifier:active_devices; 227, block; 227, 228; 228, if_statement; 228, 229; 228, 236; 229, attribute; 229, 230; 229, 235; 230, subscript; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:_devices; 234, identifier:dev_id; 235, identifier:is_active; 236, block; 236, 237; 236, 248; 236, 255; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 246; 239, attribute; 239, 240; 239, 245; 240, subscript; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:_devices; 244, identifier:dev_id; 245, identifier:set_active; 246, argument_list; 246, 247; 247, False; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:_do_update_callback; 253, argument_list; 253, 254; 254, identifier:dev_id; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:self; 259, identifier:_do_stale_devices_callback; 260, argument_list; 260, 261; 261, identifier:dev_id; 262, if_statement; 262, 263; 262, 264; 263, identifier:new_devices; 264, block; 264, 265; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:_do_new_devices_callback; 270, argument_list; 270, 271; 271, integer:0 | def update_device_list(self, sessions):
if sessions is None:
_LOGGER.error('Error updating Emby devices.')
return
new_devices = []
active_devices = []
dev_update = False
for device in sessions:
dev_name = '{}.{}'.format(device['DeviceId'], device['Client'])
try:
_LOGGER.debug('Session msg on %s of type: %s, themeflag: %s',
dev_name, device['NowPlayingItem']['Type'],
device['NowPlayingItem']['IsThemeMedia'])
except KeyError:
pass
active_devices.append(dev_name)
if dev_name not in self._devices and \
device['DeviceId'] != str(self._api_id):
_LOGGER.debug('New Emby DeviceID: %s. Adding to device list.',
dev_name)
new = EmbyDevice(device, self)
self._devices[dev_name] = new
new_devices.append(new)
elif device['DeviceId'] != str(self._api_id):
if not self._devices[dev_name].is_active:
dev_update = True
do_update = self.update_check(
self._devices[dev_name], device)
self._devices[dev_name].update_data(device)
self._devices[dev_name].set_active(True)
if dev_update:
self._do_new_devices_callback(0)
dev_update = False
if do_update:
self._do_update_callback(dev_name)
for dev_id in self._devices:
if dev_id not in active_devices:
if self._devices[dev_id].is_active:
self._devices[dev_id].set_active(False)
self._do_update_callback(dev_id)
self._do_stale_devices_callback(dev_id)
if new_devices:
self._do_new_devices_callback(0) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:main; 3, parameters; 4, block; 4, 5; 4, 11; 4, 19; 4, 25; 4, 33; 4, 43; 4, 53; 4, 140; 4, 181; 4, 194; 4, 200; 4, 296; 4, 327; 4, 338; 4, 353; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:parser; 8, call; 8, 9; 8, 10; 9, identifier:get_parser; 10, argument_list; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:args; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:parser; 17, identifier:parse_args; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:ARCHIVE; 22, attribute; 22, 23; 22, 24; 23, identifier:args; 24, identifier:archive_path; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:archive; 28, parenthesized_expression; 28, 29; 29, not_operator; 29, 30; 30, attribute; 30, 31; 30, 32; 31, identifier:args; 32, identifier:no_archive; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 40; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:os; 38, identifier:environ; 39, string:'F2FORMAT_VERSION'; 40, attribute; 40, 41; 40, 42; 41, identifier:args; 42, identifier:python; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 50; 45, subscript; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:os; 48, identifier:environ; 49, string:'F2FORMAT_ENCODING'; 50, attribute; 50, 51; 50, 52; 51, identifier:args; 52, identifier:encoding; 53, function_definition; 53, 54; 53, 55; 53, 57; 54, function_name:find; 55, parameters; 55, 56; 56, identifier:root; 57, block; 57, 58; 57, 64; 57, 73; 57, 137; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:flst; 61, call; 61, 62; 61, 63; 62, identifier:list; 63, argument_list; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:temp; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:os; 70, identifier:listdir; 71, argument_list; 71, 72; 72, identifier:root; 73, for_statement; 73, 74; 73, 75; 73, 76; 74, identifier:file; 75, identifier:temp; 76, block; 76, 77; 76, 89; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:path; 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:root; 88, identifier:file; 89, if_statement; 89, 90; 89, 98; 89, 109; 89, 126; 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:isdir; 96, argument_list; 96, 97; 97, identifier:path; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:flst; 103, identifier:extend; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:find; 107, argument_list; 107, 108; 108, identifier:path; 109, elif_clause; 109, 110; 109, 118; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:os; 114, identifier:path; 115, identifier:isfile; 116, argument_list; 116, 117; 117, identifier:path; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:flst; 123, identifier:append; 124, argument_list; 124, 125; 125, identifier:path; 126, elif_clause; 126, 127; 126, 135; 127, call; 127, 128; 127, 133; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:os; 131, identifier:path; 132, identifier:islink; 133, argument_list; 133, 134; 134, identifier:path; 135, block; 135, 136; 136, continue_statement; 137, expression_statement; 137, 138; 138, yield; 138, 139; 139, identifier:flst; 140, function_definition; 140, 141; 140, 142; 140, 144; 141, function_name:rename; 142, parameters; 142, 143; 143, identifier:path; 144, block; 144, 145; 144, 158; 144, 171; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 150; 147, pattern_list; 147, 148; 147, 149; 148, identifier:stem; 149, identifier:ext; 150, call; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:os; 154, identifier:path; 155, identifier:splitext; 156, argument_list; 156, 157; 157, identifier:path; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:name; 161, binary_operator:%; 161, 162; 161, 163; 162, string:'%s-%s%s'; 163, tuple; 163, 164; 163, 165; 163, 170; 164, identifier:stem; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:uuid; 168, identifier:uuid4; 169, argument_list; 170, identifier:ext; 171, return_statement; 171, 172; 172, call; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:os; 176, identifier:path; 177, identifier:join; 178, argument_list; 178, 179; 178, 180; 179, identifier:ARCHIVE; 180, identifier:name; 181, if_statement; 181, 182; 181, 183; 182, identifier:archive; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:os; 188, identifier:makedirs; 189, argument_list; 189, 190; 189, 191; 190, identifier:ARCHIVE; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:exist_ok; 193, True; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:filelist; 197, call; 197, 198; 197, 199; 198, identifier:list; 199, argument_list; 200, for_statement; 200, 201; 200, 202; 200, 209; 201, identifier:path; 202, subscript; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:sys; 205, identifier:argv; 206, slice; 206, 207; 206, 208; 207, integer:1; 208, colon; 209, block; 209, 210; 209, 262; 210, if_statement; 210, 211; 210, 219; 211, call; 211, 212; 211, 217; 212, attribute; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:os; 215, identifier:path; 216, identifier:isfile; 217, argument_list; 217, 218; 218, identifier:path; 219, block; 219, 220; 219, 255; 220, if_statement; 220, 221; 220, 222; 221, identifier:archive; 222, block; 222, 223; 222, 230; 222, 247; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:dest; 226, call; 226, 227; 226, 228; 227, identifier:rename; 228, argument_list; 228, 229; 229, identifier:path; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:os; 234, identifier:makedirs; 235, argument_list; 235, 236; 235, 244; 236, call; 236, 237; 236, 242; 237, attribute; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:os; 240, identifier:path; 241, identifier:dirname; 242, argument_list; 242, 243; 243, identifier:dest; 244, keyword_argument; 244, 245; 244, 246; 245, identifier:exist_ok; 246, True; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:shutil; 251, identifier:copy; 252, argument_list; 252, 253; 252, 254; 253, identifier:path; 254, identifier:dest; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:filelist; 259, identifier:append; 260, argument_list; 260, 261; 261, identifier:path; 262, if_statement; 262, 263; 262, 271; 263, call; 263, 264; 263, 269; 264, attribute; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:os; 267, identifier:path; 268, identifier:isdir; 269, argument_list; 269, 270; 270, identifier:path; 271, block; 271, 272; 271, 286; 272, if_statement; 272, 273; 272, 274; 273, identifier:archive; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:shutil; 279, identifier:copytree; 280, argument_list; 280, 281; 280, 282; 281, identifier:path; 282, call; 282, 283; 282, 284; 283, identifier:rename; 284, argument_list; 284, 285; 285, identifier:path; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:filelist; 290, identifier:extend; 291, argument_list; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:find; 294, argument_list; 294, 295; 295, identifier:path; 296, function_definition; 296, 297; 296, 298; 296, 300; 297, function_name:ispy; 298, parameters; 298, 299; 299, identifier:file; 300, block; 300, 301; 301, return_statement; 301, 302; 302, parenthesized_expression; 302, 303; 303, boolean_operator:and; 303, 304; 303, 312; 304, call; 304, 305; 304, 310; 305, attribute; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:os; 308, identifier:path; 309, identifier:isfile; 310, argument_list; 310, 311; 311, identifier:file; 312, parenthesized_expression; 312, 313; 313, comparison_operator:in; 313, 314; 313, 324; 314, subscript; 314, 315; 314, 323; 315, call; 315, 316; 315, 321; 316, attribute; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:os; 319, identifier:path; 320, identifier:splitext; 321, argument_list; 321, 322; 322, identifier:file; 323, integer:1; 324, tuple; 324, 325; 324, 326; 325, string:'.py'; 326, string:'.pyw'; 327, expression_statement; 327, 328; 328, assignment; 328, 329; 328, 330; 329, identifier:filelist; 330, call; 330, 331; 330, 332; 331, identifier:sorted; 332, argument_list; 332, 333; 333, call; 333, 334; 333, 335; 334, identifier:filter; 335, argument_list; 335, 336; 335, 337; 336, identifier:ispy; 337, identifier:filelist; 338, if_statement; 338, 339; 338, 345; 339, comparison_operator:==; 339, 340; 339, 344; 340, call; 340, 341; 340, 342; 341, identifier:len; 342, argument_list; 342, 343; 343, identifier:filelist; 344, integer:0; 345, block; 345, 346; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:parser; 350, identifier:error; 351, argument_list; 351, 352; 352, string:'argument PATH: no valid source file found'; 353, if_statement; 353, 354; 353, 361; 353, 371; 354, boolean_operator:or; 354, 355; 354, 358; 355, comparison_operator:is; 355, 356; 355, 357; 356, identifier:mp; 357, None; 358, comparison_operator:<=; 358, 359; 358, 360; 359, identifier:CPU_CNT; 360, integer:1; 361, block; 361, 362; 362, expression_statement; 362, 363; 363, list_comprehension; 363, 364; 363, 368; 364, call; 364, 365; 364, 366; 365, identifier:f2format; 366, argument_list; 366, 367; 367, identifier:filename; 368, for_in_clause; 368, 369; 368, 370; 369, identifier:filename; 370, identifier:filelist; 371, else_clause; 371, 372; 372, block; 372, 373; 373, expression_statement; 373, 374; 374, call; 374, 375; 374, 385; 375, attribute; 375, 376; 375, 384; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:mp; 379, identifier:Pool; 380, argument_list; 380, 381; 381, keyword_argument; 381, 382; 381, 383; 382, identifier:processes; 383, identifier:CPU_CNT; 384, identifier:map; 385, argument_list; 385, 386; 385, 387; 386, identifier:f2format; 387, identifier:filelist | def main():
parser = get_parser()
args = parser.parse_args()
ARCHIVE = args.archive_path
archive = (not args.no_archive)
os.environ['F2FORMAT_VERSION'] = args.python
os.environ['F2FORMAT_ENCODING'] = args.encoding
def find(root):
flst = list()
temp = os.listdir(root)
for file in temp:
path = os.path.join(root, file)
if os.path.isdir(path):
flst.extend(find(path))
elif os.path.isfile(path):
flst.append(path)
elif os.path.islink(path):
continue
yield from flst
def rename(path):
stem, ext = os.path.splitext(path)
name = '%s-%s%s' % (stem, uuid.uuid4(), ext)
return os.path.join(ARCHIVE, name)
if archive:
os.makedirs(ARCHIVE, exist_ok=True)
filelist = list()
for path in sys.argv[1:]:
if os.path.isfile(path):
if archive:
dest = rename(path)
os.makedirs(os.path.dirname(dest), exist_ok=True)
shutil.copy(path, dest)
filelist.append(path)
if os.path.isdir(path):
if archive:
shutil.copytree(path, rename(path))
filelist.extend(find(path))
def ispy(file): return (os.path.isfile(file) and (os.path.splitext(file)[1] in ('.py', '.pyw')))
filelist = sorted(filter(ispy, filelist))
if len(filelist) == 0:
parser.error('argument PATH: no valid source file found')
if mp is None or CPU_CNT <= 1:
[f2format(filename) for filename in filelist]
else:
mp.Pool(processes=CPU_CNT).map(f2format, filelist) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:random_useragent; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:filename; 6, True; 7, block; 7, 8; 7, 11; 7, 17; 7, 35; 7, 47; 7, 90; 7, 205; 8, import_statement; 8, 9; 9, dotted_name; 9, 10; 10, identifier:random; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:default_ua; 14, binary_operator:%; 14, 15; 14, 16; 15, string:'urlfetch/%s'; 16, identifier:__version__; 17, if_statement; 17, 18; 17, 23; 17, 29; 18, call; 18, 19; 18, 20; 19, identifier:isinstance; 20, argument_list; 20, 21; 20, 22; 21, identifier:filename; 22, identifier:basestring; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:filenames; 27, list:[filename]; 27, 28; 28, identifier:filename; 29, else_clause; 29, 30; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:filenames; 34, list:[]; 35, if_statement; 35, 36; 35, 39; 36, boolean_operator:and; 36, 37; 36, 38; 37, identifier:filename; 38, identifier:UAFILE; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:filenames; 44, identifier:append; 45, argument_list; 45, 46; 46, identifier:UAFILE; 47, for_statement; 47, 48; 47, 49; 47, 50; 47, 86; 48, identifier:filename; 49, identifier:filenames; 50, block; 50, 51; 51, try_statement; 51, 52; 51, 83; 52, block; 52, 53; 52, 62; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:st; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:os; 59, identifier:stat; 60, argument_list; 60, 61; 61, identifier:filename; 62, if_statement; 62, 63; 62, 81; 63, boolean_operator:and; 63, 64; 63, 72; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:stat; 67, identifier:S_ISREG; 68, argument_list; 68, 69; 69, attribute; 69, 70; 69, 71; 70, identifier:st; 71, identifier:st_mode; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:os; 75, identifier:access; 76, argument_list; 76, 77; 76, 78; 77, identifier:filename; 78, attribute; 78, 79; 78, 80; 79, identifier:os; 80, identifier:R_OK; 81, block; 81, 82; 82, break_statement; 83, except_clause; 83, 84; 84, block; 84, 85; 85, pass_statement; 86, else_clause; 86, 87; 87, block; 87, 88; 88, return_statement; 88, 89; 89, identifier:default_ua; 90, with_statement; 90, 91; 90, 101; 91, with_clause; 91, 92; 92, with_item; 92, 93; 93, as_pattern; 93, 94; 93, 99; 94, call; 94, 95; 94, 96; 95, identifier:open; 96, argument_list; 96, 97; 96, 98; 97, identifier:filename; 98, string:'rb'; 99, as_pattern_target; 99, 100; 100, identifier:f; 101, block; 101, 102; 101, 108; 101, 112; 101, 120; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:filesize; 105, attribute; 105, 106; 105, 107; 106, identifier:st; 107, identifier:st_size; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:pos; 111, integer:0; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:r; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:random; 118, identifier:Random; 119, argument_list; 120, for_statement; 120, 121; 120, 122; 120, 126; 121, identifier:i; 122, call; 122, 123; 122, 124; 123, identifier:range; 124, argument_list; 124, 125; 125, integer:3; 126, block; 126, 127; 126, 137; 126, 141; 126, 148; 126, 154; 126, 162; 126, 190; 126, 198; 127, expression_statement; 127, 128; 128, augmented_assignment:+=; 128, 129; 128, 130; 129, identifier:pos; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:r; 133, identifier:randint; 134, argument_list; 134, 135; 134, 136; 135, integer:0; 136, identifier:filesize; 137, expression_statement; 137, 138; 138, augmented_assignment:%=; 138, 139; 138, 140; 139, identifier:pos; 140, identifier:filesize; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:f; 145, identifier:seek; 146, argument_list; 146, 147; 147, identifier:pos; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:f; 152, identifier:readline; 153, argument_list; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:line; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:f; 160, identifier:readline; 161, argument_list; 162, if_statement; 162, 163; 162, 165; 163, not_operator; 163, 164; 164, identifier:line; 165, block; 165, 166; 166, if_statement; 166, 167; 166, 174; 167, comparison_operator:==; 167, 168; 167, 173; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:f; 171, identifier:tell; 172, argument_list; 173, identifier:filesize; 174, block; 174, 175; 174, 182; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:f; 179, identifier:seek; 180, argument_list; 180, 181; 181, integer:0; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:line; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:f; 188, identifier:readline; 189, argument_list; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:line; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:line; 196, identifier:strip; 197, argument_list; 198, ERROR; 198, 199; 198, 200; 198, 203; 198, 204; 199, identifier:line; 200, subscript; 200, 201; 200, 202; 201, identifier:line; 202, integer:0; 203, identifier:return; 204, identifier:line; 205, return_statement; 205, 206; 206, identifier:default_ua | def random_useragent(filename=True):
import random
default_ua = 'urlfetch/%s' % __version__
if isinstance(filename, basestring):
filenames = [filename]
else:
filenames = []
if filename and UAFILE:
filenames.append(UAFILE)
for filename in filenames:
try:
st = os.stat(filename)
if stat.S_ISREG(st.st_mode) and os.access(filename, os.R_OK):
break
except:
pass
else:
return default_ua
with open(filename, 'rb') as f:
filesize = st.st_size
pos = 0
r = random.Random()
for i in range(3):
pos += r.randint(0, filesize)
pos %= filesize
f.seek(pos)
f.readline()
line = f.readline()
if not line:
if f.tell() == filesize:
f.seek(0)
line = f.readline()
line = line.strip()
if line and line[0] != '
return line
return default_ua |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:encode_multipart; 3, parameters; 3, 4; 3, 5; 4, identifier:data; 5, identifier:files; 6, block; 6, 7; 6, 13; 6, 19; 6, 28; 6, 39; 6, 153; 6, 329; 6, 343; 6, 349; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:body; 10, call; 10, 11; 10, 12; 11, identifier:BytesIO; 12, argument_list; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:boundary; 16, call; 16, 17; 16, 18; 17, identifier:choose_boundary; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:part_boundary; 22, call; 22, 23; 22, 24; 23, identifier:b; 24, argument_list; 24, 25; 25, binary_operator:%; 25, 26; 25, 27; 26, string:'--%s\r\n'; 27, identifier:boundary; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:writer; 31, subscript; 31, 32; 31, 38; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:codecs; 35, identifier:lookup; 36, argument_list; 36, 37; 37, string:'utf-8'; 38, integer:3; 39, if_statement; 39, 40; 39, 45; 40, call; 40, 41; 40, 42; 41, identifier:isinstance; 42, argument_list; 42, 43; 42, 44; 43, identifier:data; 44, identifier:dict; 45, block; 45, 46; 46, for_statement; 46, 47; 46, 50; 46, 55; 47, pattern_list; 47, 48; 47, 49; 48, identifier:name; 49, identifier:values; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:data; 53, identifier:items; 54, argument_list; 55, block; 55, 56; 55, 72; 56, if_statement; 56, 57; 56, 66; 57, not_operator; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:isinstance; 60, argument_list; 60, 61; 60, 62; 61, identifier:values; 62, tuple; 62, 63; 62, 64; 62, 65; 63, identifier:list; 64, identifier:tuple; 65, identifier:set; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:values; 70, tuple; 70, 71; 71, identifier:values; 72, for_statement; 72, 73; 72, 74; 72, 75; 73, identifier:value; 74, identifier:values; 75, block; 75, 76; 75, 83; 75, 97; 75, 104; 75, 118; 75, 146; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:body; 80, identifier:write; 81, argument_list; 81, 82; 82, identifier:part_boundary; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 91; 85, attribute; 85, 86; 85, 90; 86, call; 86, 87; 86, 88; 87, identifier:writer; 88, argument_list; 88, 89; 89, identifier:body; 90, identifier:write; 91, argument_list; 91, 92; 92, binary_operator:%; 92, 93; 92, 96; 93, concatenated_string; 93, 94; 93, 95; 94, string:'Content-Disposition: form-data; '; 95, string:'name="%s"\r\n'; 96, identifier:name; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:body; 101, identifier:write; 102, argument_list; 102, 103; 103, string:b'Content-Type: text/plain\r\n\r\n'; 104, if_statement; 104, 105; 104, 110; 105, call; 105, 106; 105, 107; 106, identifier:isinstance; 107, argument_list; 107, 108; 107, 109; 108, identifier:value; 109, identifier:int; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:value; 114, call; 114, 115; 114, 116; 115, identifier:str; 116, argument_list; 116, 117; 117, identifier:value; 118, if_statement; 118, 119; 118, 126; 118, 137; 119, boolean_operator:and; 119, 120; 119, 121; 120, identifier:py3k; 121, call; 121, 122; 121, 123; 122, identifier:isinstance; 123, argument_list; 123, 124; 123, 125; 124, identifier:value; 125, identifier:str; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 135; 129, attribute; 129, 130; 129, 134; 130, call; 130, 131; 130, 132; 131, identifier:writer; 132, argument_list; 132, 133; 133, identifier:body; 134, identifier:write; 135, argument_list; 135, 136; 136, identifier:value; 137, else_clause; 137, 138; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:body; 143, identifier:write; 144, argument_list; 144, 145; 145, identifier:value; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:body; 150, identifier:write; 151, argument_list; 151, 152; 152, string:b'\r\n'; 153, for_statement; 153, 154; 153, 157; 153, 162; 154, pattern_list; 154, 155; 154, 156; 155, identifier:fieldname; 156, identifier:f; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:files; 160, identifier:items; 161, argument_list; 162, block; 162, 163; 162, 203; 162, 238; 162, 245; 162, 294; 162, 322; 163, if_statement; 163, 164; 163, 169; 163, 176; 163, 192; 164, call; 164, 165; 164, 166; 165, identifier:isinstance; 166, argument_list; 166, 167; 166, 168; 167, identifier:f; 168, identifier:tuple; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 175; 172, pattern_list; 172, 173; 172, 174; 173, identifier:filename; 174, identifier:f; 175, identifier:f; 176, elif_clause; 176, 177; 176, 182; 177, call; 177, 178; 177, 179; 178, identifier:hasattr; 179, argument_list; 179, 180; 179, 181; 180, identifier:f; 181, string:'name'; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:filename; 186, call; 186, 187; 186, 188; 187, identifier:basename; 188, argument_list; 188, 189; 189, attribute; 189, 190; 189, 191; 190, identifier:f; 191, identifier:name; 192, else_clause; 192, 193; 193, block; 193, 194; 193, 198; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:filename; 197, None; 198, raise_statement; 198, 199; 199, call; 199, 200; 199, 201; 200, identifier:UrlfetchException; 201, argument_list; 201, 202; 202, string:"file must has filename"; 203, if_statement; 203, 204; 203, 209; 203, 218; 203, 229; 204, call; 204, 205; 204, 206; 205, identifier:hasattr; 206, argument_list; 206, 207; 206, 208; 207, identifier:f; 208, string:'read'; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:value; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:f; 216, identifier:read; 217, argument_list; 218, elif_clause; 218, 219; 218, 224; 219, call; 219, 220; 219, 221; 220, identifier:isinstance; 221, argument_list; 221, 222; 221, 223; 222, identifier:f; 223, identifier:basestring; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:value; 228, identifier:f; 229, else_clause; 229, 230; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:value; 234, call; 234, 235; 234, 236; 235, identifier:str; 236, argument_list; 236, 237; 237, identifier:f; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:body; 242, identifier:write; 243, argument_list; 243, 244; 244, identifier:part_boundary; 245, if_statement; 245, 246; 245, 247; 245, 271; 246, identifier:filename; 247, block; 247, 248; 247, 264; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 256; 250, attribute; 250, 251; 250, 255; 251, call; 251, 252; 251, 253; 252, identifier:writer; 253, argument_list; 253, 254; 254, identifier:body; 255, identifier:write; 256, argument_list; 256, 257; 257, binary_operator:%; 257, 258; 257, 261; 258, concatenated_string; 258, 259; 258, 260; 259, string:'Content-Disposition: form-data; name="%s"; '; 260, string:'filename="%s"\r\n'; 261, tuple; 261, 262; 261, 263; 262, identifier:fieldname; 263, identifier:filename; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:body; 268, identifier:write; 269, argument_list; 269, 270; 270, string:b'Content-Type: application/octet-stream\r\n\r\n'; 271, else_clause; 271, 272; 272, block; 272, 273; 272, 287; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 281; 275, attribute; 275, 276; 275, 280; 276, call; 276, 277; 276, 278; 277, identifier:writer; 278, argument_list; 278, 279; 279, identifier:body; 280, identifier:write; 281, argument_list; 281, 282; 282, binary_operator:%; 282, 283; 282, 286; 283, concatenated_string; 283, 284; 283, 285; 284, string:'Content-Disposition: form-data; name="%s"'; 285, string:'\r\n'; 286, identifier:name; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:body; 291, identifier:write; 292, argument_list; 292, 293; 293, string:b'Content-Type: text/plain\r\n\r\n'; 294, if_statement; 294, 295; 294, 302; 294, 313; 295, boolean_operator:and; 295, 296; 295, 297; 296, identifier:py3k; 297, call; 297, 298; 297, 299; 298, identifier:isinstance; 299, argument_list; 299, 300; 299, 301; 300, identifier:value; 301, identifier:str; 302, block; 302, 303; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 311; 305, attribute; 305, 306; 305, 310; 306, call; 306, 307; 306, 308; 307, identifier:writer; 308, argument_list; 308, 309; 309, identifier:body; 310, identifier:write; 311, argument_list; 311, 312; 312, identifier:value; 313, else_clause; 313, 314; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:body; 319, identifier:write; 320, argument_list; 320, 321; 321, identifier:value; 322, expression_statement; 322, 323; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:body; 326, identifier:write; 327, argument_list; 327, 328; 328, string:b'\r\n'; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:body; 333, identifier:write; 334, argument_list; 334, 335; 335, call; 335, 336; 335, 337; 336, identifier:b; 337, argument_list; 337, 338; 338, binary_operator:+; 338, 339; 338, 342; 339, binary_operator:+; 339, 340; 339, 341; 340, string:'--'; 341, identifier:boundary; 342, string:'--\r\n'; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 346; 345, identifier:content_type; 346, binary_operator:%; 346, 347; 346, 348; 347, string:'multipart/form-data; boundary=%s'; 348, identifier:boundary; 349, return_statement; 349, 350; 350, expression_list; 350, 351; 350, 352; 351, identifier:content_type; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:body; 355, identifier:getvalue; 356, argument_list | def encode_multipart(data, files):
body = BytesIO()
boundary = choose_boundary()
part_boundary = b('--%s\r\n' % boundary)
writer = codecs.lookup('utf-8')[3]
if isinstance(data, dict):
for name, values in data.items():
if not isinstance(values, (list, tuple, set)):
values = (values, )
for value in values:
body.write(part_boundary)
writer(body).write('Content-Disposition: form-data; '
'name="%s"\r\n' % name)
body.write(b'Content-Type: text/plain\r\n\r\n')
if isinstance(value, int):
value = str(value)
if py3k and isinstance(value, str):
writer(body).write(value)
else:
body.write(value)
body.write(b'\r\n')
for fieldname, f in files.items():
if isinstance(f, tuple):
filename, f = f
elif hasattr(f, 'name'):
filename = basename(f.name)
else:
filename = None
raise UrlfetchException("file must has filename")
if hasattr(f, 'read'):
value = f.read()
elif isinstance(f, basestring):
value = f
else:
value = str(f)
body.write(part_boundary)
if filename:
writer(body).write('Content-Disposition: form-data; name="%s"; '
'filename="%s"\r\n' % (fieldname, filename))
body.write(b'Content-Type: application/octet-stream\r\n\r\n')
else:
writer(body).write('Content-Disposition: form-data; name="%s"'
'\r\n' % name)
body.write(b'Content-Type: text/plain\r\n\r\n')
if py3k and isinstance(value, str):
writer(body).write(value)
else:
body.write(value)
body.write(b'\r\n')
body.write(b('--' + boundary + '--\r\n'))
content_type = 'multipart/form-data; boundary=%s' % boundary
return content_type, body.getvalue() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:assemble; 3, parameters; 3, 4; 4, identifier:code; 5, block; 5, 6; 5, 10; 5, 158; 5, 162; 5, 166; 5, 195; 5, 199; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:final; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:line; 12, identifier:code; 13, block; 13, 14; 13, 29; 13, 43; 13, 51; 13, 55; 13, 145; 14, if_statement; 14, 15; 14, 20; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:line; 19, identifier:Label; 20, block; 20, 21; 20, 28; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:final; 25, identifier:append; 26, argument_list; 26, 27; 27, identifier:line; 28, continue_statement; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, pattern_list; 31, 32; 31, 33; 32, identifier:mnemonic; 33, identifier:operands; 34, expression_list; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:line; 37, integer:0; 38, subscript; 38, 39; 38, 40; 39, identifier:line; 40, slice; 40, 41; 40, 42; 41, integer:1; 42, colon; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:operand_fmts; 46, subscript; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:opcode_table; 49, identifier:mnemonic; 50, string:'operands'; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:final_operands; 54, list:[]; 55, for_statement; 55, 56; 55, 59; 55, 63; 56, pattern_list; 56, 57; 56, 58; 57, identifier:i; 58, identifier:operand; 59, call; 59, 60; 59, 61; 60, identifier:enumerate; 61, argument_list; 61, 62; 62, identifier:operands; 63, block; 63, 64; 64, if_statement; 64, 65; 64, 70; 64, 78; 64, 100; 64, 114; 64, 128; 65, call; 65, 66; 65, 67; 66, identifier:isinstance; 67, argument_list; 67, 68; 67, 69; 68, identifier:operand; 69, identifier:Operand; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:final_operands; 75, identifier:append; 76, argument_list; 76, 77; 77, identifier:operand; 78, elif_clause; 78, 79; 78, 84; 79, call; 79, 80; 79, 81; 80, identifier:isinstance; 81, argument_list; 81, 82; 81, 83; 82, identifier:operand; 83, identifier:Constant; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:final_operands; 89, identifier:append; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:Operand; 93, argument_list; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:OperandTypes; 96, identifier:CONSTANT_INDEX; 97, attribute; 97, 98; 97, 99; 98, identifier:operand; 99, identifier:index; 100, elif_clause; 100, 101; 100, 106; 101, call; 101, 102; 101, 103; 102, identifier:isinstance; 103, argument_list; 103, 104; 103, 105; 104, identifier:operand; 105, identifier:dict; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:final_operands; 111, identifier:append; 112, argument_list; 112, 113; 113, identifier:operand; 114, elif_clause; 114, 115; 114, 120; 115, call; 115, 116; 115, 117; 116, identifier:isinstance; 117, argument_list; 117, 118; 117, 119; 118, identifier:operand; 119, identifier:Label; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:final_operands; 125, identifier:append; 126, argument_list; 126, 127; 127, identifier:operand; 128, else_clause; 128, 129; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:final_operands; 134, identifier:append; 135, argument_list; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:Operand; 138, argument_list; 138, 139; 138, 144; 139, subscript; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:operand_fmts; 142, identifier:i; 143, integer:1; 144, identifier:operand; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:final; 149, identifier:append; 150, argument_list; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:Instruction; 154, identifier:create; 155, argument_list; 155, 156; 155, 157; 156, identifier:mnemonic; 157, identifier:final_operands; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:label_pcs; 161, dictionary; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:current_pc; 165, integer:0; 166, for_statement; 166, 167; 166, 168; 166, 169; 167, identifier:ins; 168, identifier:final; 169, block; 169, 170; 169, 186; 170, if_statement; 170, 171; 170, 176; 171, call; 171, 172; 171, 173; 172, identifier:isinstance; 173, argument_list; 173, 174; 173, 175; 174, identifier:ins; 175, identifier:Label; 176, block; 176, 177; 176, 185; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 184; 179, subscript; 179, 180; 179, 181; 180, identifier:label_pcs; 181, attribute; 181, 182; 181, 183; 182, identifier:ins; 183, identifier:name; 184, identifier:current_pc; 185, continue_statement; 186, expression_statement; 186, 187; 187, augmented_assignment:+=; 187, 188; 187, 189; 188, identifier:current_pc; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:ins; 192, identifier:size_on_disk; 193, argument_list; 193, 194; 194, identifier:current_pc; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:current_pc; 198, integer:0; 199, for_statement; 199, 200; 199, 201; 199, 202; 200, identifier:ins; 201, identifier:final; 202, block; 202, 203; 202, 211; 202, 287; 202, 296; 203, if_statement; 203, 204; 203, 209; 204, call; 204, 205; 204, 206; 205, identifier:isinstance; 206, argument_list; 206, 207; 206, 208; 207, identifier:ins; 208, identifier:Label; 209, block; 209, 210; 210, continue_statement; 211, for_statement; 211, 212; 211, 215; 211, 221; 212, pattern_list; 212, 213; 212, 214; 213, identifier:i; 214, identifier:operand; 215, call; 215, 216; 215, 217; 216, identifier:enumerate; 217, argument_list; 217, 218; 218, attribute; 218, 219; 218, 220; 219, identifier:ins; 220, identifier:operands; 221, block; 221, 222; 222, if_statement; 222, 223; 222, 228; 222, 262; 223, call; 223, 224; 223, 225; 224, identifier:isinstance; 225, argument_list; 225, 226; 225, 227; 226, identifier:operand; 227, identifier:dict; 228, block; 228, 229; 229, for_statement; 229, 230; 229, 233; 229, 238; 230, pattern_list; 230, 231; 230, 232; 231, identifier:k; 232, identifier:v; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:operand; 236, identifier:items; 237, argument_list; 238, block; 238, 239; 239, if_statement; 239, 240; 239, 245; 240, call; 240, 241; 240, 242; 241, identifier:isinstance; 242, argument_list; 242, 243; 242, 244; 243, identifier:v; 244, identifier:Label; 245, block; 245, 246; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:operand; 250, identifier:k; 251, call; 251, 252; 251, 253; 252, identifier:Operand; 253, argument_list; 253, 254; 253, 255; 254, integer:40; 255, binary_operator:-; 255, 256; 255, 261; 256, subscript; 256, 257; 256, 258; 257, identifier:label_pcs; 258, attribute; 258, 259; 258, 260; 259, identifier:v; 260, identifier:name; 261, identifier:current_pc; 262, elif_clause; 262, 263; 262, 268; 263, call; 263, 264; 263, 265; 264, identifier:isinstance; 265, argument_list; 265, 266; 265, 267; 266, identifier:operand; 267, identifier:Label; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 276; 271, subscript; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:ins; 274, identifier:operands; 275, identifier:i; 276, call; 276, 277; 276, 278; 277, identifier:Operand; 278, argument_list; 278, 279; 278, 280; 279, integer:40; 280, binary_operator:-; 280, 281; 280, 286; 281, subscript; 281, 282; 281, 283; 282, identifier:label_pcs; 283, attribute; 283, 284; 283, 285; 284, identifier:operand; 285, identifier:name; 286, identifier:current_pc; 287, expression_statement; 287, 288; 288, augmented_assignment:+=; 288, 289; 288, 290; 289, identifier:current_pc; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:ins; 293, identifier:size_on_disk; 294, argument_list; 294, 295; 295, identifier:current_pc; 296, expression_statement; 296, 297; 297, yield; 297, 298; 298, identifier:ins | def assemble(code):
final = []
for line in code:
if isinstance(line, Label):
final.append(line)
continue
mnemonic, operands = line[0], line[1:]
operand_fmts = opcode_table[mnemonic]['operands']
final_operands = []
for i, operand in enumerate(operands):
if isinstance(operand, Operand):
final_operands.append(operand)
elif isinstance(operand, Constant):
final_operands.append(Operand(
OperandTypes.CONSTANT_INDEX,
operand.index
))
elif isinstance(operand, dict):
final_operands.append(operand)
elif isinstance(operand, Label):
final_operands.append(operand)
else:
final_operands.append(Operand(
operand_fmts[i][1],
operand
))
final.append(Instruction.create(mnemonic, final_operands))
label_pcs = {}
current_pc = 0
for ins in final:
if isinstance(ins, Label):
label_pcs[ins.name] = current_pc
continue
current_pc += ins.size_on_disk(current_pc)
current_pc = 0
for ins in final:
if isinstance(ins, Label):
continue
for i, operand in enumerate(ins.operands):
if isinstance(operand, dict):
for k, v in operand.items():
if isinstance(v, Label):
operand[k] = Operand(40, label_pcs[v.name] - current_pc)
elif isinstance(operand, Label):
ins.operands[i] = Operand(
40,
label_pcs[operand.name] - current_pc
)
current_pc += ins.size_on_disk(current_pc)
yield ins |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_add_new; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:host_object; 6, block; 6, 7; 6, 16; 6, 43; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:i; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_get_insertion_point; 14, argument_list; 14, 15; 15, identifier:host_object; 16, for_statement; 16, 17; 16, 18; 16, 23; 17, identifier:listed; 18, subscript; 18, 19; 18, 20; 19, identifier:self; 20, slice; 20, 21; 20, 22; 21, identifier:i; 22, colon; 23, block; 23, 24; 23, 34; 24, if_statement; 24, 25; 24, 32; 25, not_operator; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:listed; 29, identifier:is_subdomain; 30, argument_list; 30, 31; 31, identifier:host_object; 32, block; 32, 33; 33, break_statement; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:hosts; 40, identifier:pop; 41, argument_list; 41, 42; 42, identifier:i; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:hosts; 49, identifier:insert; 50, argument_list; 50, 51; 50, 52; 51, identifier:i; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:host_object; 55, identifier:to_unicode; 56, argument_list | def _add_new(self, host_object):
i = self._get_insertion_point(host_object)
for listed in self[i:]:
if not listed.is_subdomain(host_object):
break
self.hosts.pop(i)
self.hosts.insert(i, host_object.to_unicode()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:write_instruction; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:fout; 5, identifier:start_pos; 6, identifier:ins; 7, block; 7, 8; 7, 20; 7, 28; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, pattern_list; 10, 11; 10, 12; 11, identifier:opcode; 12, identifier:operands; 13, expression_list; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:ins; 16, identifier:opcode; 17, attribute; 17, 18; 17, 19; 18, identifier:ins; 19, identifier:operands; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:fmt_operands; 23, subscript; 23, 24; 23, 27; 24, subscript; 24, 25; 24, 26; 25, identifier:opcode_table; 26, identifier:opcode; 27, string:'operands'; 28, if_statement; 28, 29; 28, 32; 28, 90; 28, 133; 28, 229; 28, 312; 29, attribute; 29, 30; 29, 31; 30, identifier:ins; 31, identifier:wide; 32, block; 32, 33; 32, 44; 32, 55; 32, 70; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:fout; 37, identifier:write; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:pack; 41, argument_list; 41, 42; 41, 43; 42, string:'>B'; 43, integer:0xC4; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:fout; 48, identifier:write; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:pack; 52, argument_list; 52, 53; 52, 54; 53, string:'>B'; 54, identifier:opcode; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:fout; 59, identifier:write; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:pack; 63, argument_list; 63, 64; 63, 65; 64, string:'>H'; 65, attribute; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:operands; 68, integer:0; 69, identifier:value; 70, if_statement; 70, 71; 70, 74; 71, comparison_operator:==; 71, 72; 71, 73; 72, identifier:opcode; 73, integer:0x84; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:fout; 79, identifier:write; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:pack; 83, argument_list; 83, 84; 83, 85; 84, string:'>h'; 85, attribute; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:operands; 88, integer:1; 89, identifier:value; 90, elif_clause; 90, 91; 90, 92; 91, identifier:fmt_operands; 92, block; 92, 93; 92, 104; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:fout; 97, identifier:write; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:pack; 101, argument_list; 101, 102; 101, 103; 102, string:'>B'; 103, identifier:opcode; 104, for_statement; 104, 105; 104, 110; 104, 114; 105, pattern_list; 105, 106; 105, 107; 106, identifier:i; 107, tuple_pattern; 107, 108; 107, 109; 108, identifier:fmt; 109, identifier:_; 110, call; 110, 111; 110, 112; 111, identifier:enumerate; 112, argument_list; 112, 113; 113, identifier:fmt_operands; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:fout; 119, identifier:write; 120, argument_list; 120, 121; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:fmt; 125, identifier:value; 126, identifier:pack; 127, argument_list; 127, 128; 128, attribute; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:operands; 131, identifier:i; 132, identifier:value; 133, elif_clause; 133, 134; 133, 137; 134, comparison_operator:==; 134, 135; 134, 136; 135, identifier:opcode; 136, integer:0xAB; 137, block; 137, 138; 137, 149; 137, 160; 137, 169; 137, 179; 137, 200; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:fout; 142, identifier:write; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:pack; 146, argument_list; 146, 147; 146, 148; 147, string:'>B'; 148, identifier:opcode; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:padding; 152, binary_operator:-; 152, 153; 152, 154; 153, integer:4; 154, binary_operator:%; 154, 155; 154, 159; 155, parenthesized_expression; 155, 156; 156, binary_operator:+; 156, 157; 156, 158; 157, identifier:start_pos; 158, integer:1; 159, integer:4; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:padding; 163, conditional_expression:if; 163, 164; 163, 165; 163, 168; 164, identifier:padding; 165, comparison_operator:!=; 165, 166; 165, 167; 166, identifier:padding; 167, integer:4; 168, integer:0; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:fout; 173, identifier:write; 174, argument_list; 174, 175; 175, call; 175, 176; 175, 177; 176, identifier:pack; 177, argument_list; 177, 178; 178, string:f'{padding}x'; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:fout; 183, identifier:write; 184, argument_list; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:pack; 187, argument_list; 187, 188; 187, 189; 187, 194; 188, string:'>ii'; 189, attribute; 189, 190; 189, 193; 190, subscript; 190, 191; 190, 192; 191, identifier:operands; 192, integer:1; 193, identifier:value; 194, call; 194, 195; 194, 196; 195, identifier:len; 196, argument_list; 196, 197; 197, subscript; 197, 198; 197, 199; 198, identifier:operands; 199, integer:0; 200, for_statement; 200, 201; 200, 202; 200, 212; 201, identifier:key; 202, call; 202, 203; 202, 204; 203, identifier:sorted; 204, argument_list; 204, 205; 205, call; 205, 206; 205, 211; 206, attribute; 206, 207; 206, 210; 207, subscript; 207, 208; 207, 209; 208, identifier:operands; 209, integer:0; 210, identifier:keys; 211, argument_list; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:fout; 217, identifier:write; 218, argument_list; 218, 219; 219, call; 219, 220; 219, 221; 220, identifier:pack; 221, argument_list; 221, 222; 221, 223; 221, 224; 222, string:'>ii'; 223, identifier:key; 224, subscript; 224, 225; 224, 228; 225, subscript; 225, 226; 225, 227; 226, identifier:operands; 227, integer:0; 228, identifier:key; 229, elif_clause; 229, 230; 229, 233; 230, comparison_operator:==; 230, 231; 230, 232; 231, identifier:opcode; 232, integer:0xAA; 233, block; 233, 234; 233, 245; 233, 256; 233, 265; 233, 275; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:fout; 238, identifier:write; 239, argument_list; 239, 240; 240, call; 240, 241; 240, 242; 241, identifier:pack; 242, argument_list; 242, 243; 242, 244; 243, string:'>B'; 244, identifier:opcode; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:padding; 248, binary_operator:-; 248, 249; 248, 250; 249, integer:4; 250, binary_operator:%; 250, 251; 250, 255; 251, parenthesized_expression; 251, 252; 252, binary_operator:+; 252, 253; 252, 254; 253, identifier:start_pos; 254, integer:1; 255, integer:4; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:padding; 259, conditional_expression:if; 259, 260; 259, 261; 259, 264; 260, identifier:padding; 261, comparison_operator:!=; 261, 262; 261, 263; 262, identifier:padding; 263, integer:4; 264, integer:0; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:fout; 269, identifier:write; 270, argument_list; 270, 271; 271, call; 271, 272; 271, 273; 272, identifier:pack; 273, argument_list; 273, 274; 274, string:f'{padding}x'; 275, expression_statement; 275, 276; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:fout; 279, identifier:write; 280, argument_list; 280, 281; 281, call; 281, 282; 281, 283; 282, identifier:pack; 283, argument_list; 283, 284; 283, 285; 283, 290; 283, 295; 283, 300; 284, string:f'>iii{len(operands) - 3}i'; 285, attribute; 285, 286; 285, 289; 286, subscript; 286, 287; 286, 288; 287, identifier:operands; 288, integer:0; 289, identifier:value; 290, attribute; 290, 291; 290, 294; 291, subscript; 291, 292; 291, 293; 292, identifier:operands; 293, integer:1; 294, identifier:value; 295, attribute; 295, 296; 295, 299; 296, subscript; 296, 297; 296, 298; 297, identifier:operands; 298, integer:2; 299, identifier:value; 300, list_splat; 300, 301; 301, generator_expression; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:o; 304, identifier:value; 305, for_in_clause; 305, 306; 305, 307; 306, identifier:o; 307, subscript; 307, 308; 307, 309; 308, identifier:operands; 309, slice; 309, 310; 309, 311; 310, integer:3; 311, colon; 312, else_clause; 312, 313; 313, block; 313, 314; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:fout; 318, identifier:write; 319, argument_list; 319, 320; 320, call; 320, 321; 320, 322; 321, identifier:pack; 322, argument_list; 322, 323; 322, 324; 323, string:'>B'; 324, identifier:opcode | def write_instruction(fout, start_pos, ins):
opcode, operands = ins.opcode, ins.operands
fmt_operands = opcode_table[opcode]['operands']
if ins.wide:
fout.write(pack('>B', 0xC4))
fout.write(pack('>B', opcode))
fout.write(pack('>H', operands[0].value))
if opcode == 0x84:
fout.write(pack('>h', operands[1].value))
elif fmt_operands:
fout.write(pack('>B', opcode))
for i, (fmt, _) in enumerate(fmt_operands):
fout.write(fmt.value.pack(operands[i].value))
elif opcode == 0xAB:
fout.write(pack('>B', opcode))
padding = 4 - (start_pos + 1) % 4
padding = padding if padding != 4 else 0
fout.write(pack(f'{padding}x'))
fout.write(pack('>ii', operands[1].value, len(operands[0])))
for key in sorted(operands[0].keys()):
fout.write(pack('>ii', key, operands[0][key]))
elif opcode == 0xAA:
fout.write(pack('>B', opcode))
padding = 4 - (start_pos + 1) % 4
padding = padding if padding != 4 else 0
fout.write(pack(f'{padding}x'))
fout.write(pack(
f'>iii{len(operands) - 3}i',
operands[0].value,
operands[1].value,
operands[2].value,
*(o.value for o in operands[3:])
))
else:
fout.write(pack('>B', opcode)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:read_instruction; 3, parameters; 3, 4; 3, 5; 4, identifier:fio; 5, identifier:start_pos; 6, block; 6, 7; 6, 16; 6, 22; 6, 29; 6, 35; 6, 41; 6, 47; 6, 51; 6, 401; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:op; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:fio; 13, identifier:read; 14, argument_list; 14, 15; 15, integer:1; 16, if_statement; 16, 17; 16, 19; 17, not_operator; 17, 18; 18, identifier:op; 19, block; 19, 20; 20, return_statement; 20, 21; 21, None; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:op; 25, call; 25, 26; 25, 27; 26, identifier:ord; 27, argument_list; 27, 28; 28, identifier:op; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:ins; 32, subscript; 32, 33; 32, 34; 33, identifier:opcode_table; 34, identifier:op; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:operands; 38, subscript; 38, 39; 38, 40; 39, identifier:ins; 40, string:'operands'; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:name; 44, subscript; 44, 45; 44, 46; 45, identifier:ins; 46, string:'mnemonic'; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:final_operands; 50, list:[]; 51, if_statement; 51, 52; 51, 53; 51, 89; 51, 189; 51, 316; 52, identifier:operands; 53, block; 53, 54; 54, for_statement; 54, 55; 54, 58; 54, 59; 55, pattern_list; 55, 56; 55, 57; 56, identifier:fmt; 57, identifier:type_; 58, identifier:operands; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:final_operands; 64, identifier:append; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:Operand; 68, argument_list; 68, 69; 68, 70; 69, identifier:type_; 70, subscript; 70, 71; 70, 88; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:fmt; 75, identifier:value; 76, identifier:unpack; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:fio; 81, identifier:read; 82, argument_list; 82, 83; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:fmt; 86, identifier:value; 87, identifier:size; 88, integer:0; 89, elif_clause; 89, 90; 89, 93; 90, comparison_operator:==; 90, 91; 90, 92; 91, identifier:op; 92, integer:0xAB; 93, block; 93, 94; 93, 105; 93, 114; 93, 121; 93, 136; 93, 140; 93, 169; 93, 176; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:padding; 97, binary_operator:-; 97, 98; 97, 99; 98, integer:4; 99, binary_operator:%; 99, 100; 99, 104; 100, parenthesized_expression; 100, 101; 101, binary_operator:+; 101, 102; 101, 103; 102, identifier:start_pos; 103, integer:1; 104, integer:4; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:padding; 108, conditional_expression:if; 108, 109; 108, 110; 108, 113; 109, identifier:padding; 110, comparison_operator:!=; 110, 111; 110, 112; 111, identifier:padding; 112, integer:4; 113, integer:0; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:fio; 118, identifier:read; 119, argument_list; 119, 120; 120, identifier:padding; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 126; 123, pattern_list; 123, 124; 123, 125; 124, identifier:default; 125, identifier:npairs; 126, call; 126, 127; 126, 128; 127, identifier:unpack; 128, argument_list; 128, 129; 128, 130; 129, string:'>ii'; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:fio; 133, identifier:read; 134, argument_list; 134, 135; 135, integer:8; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:pairs; 139, dictionary; 140, for_statement; 140, 141; 140, 142; 140, 147; 141, identifier:_; 142, call; 142, 143; 142, 144; 143, identifier:repeat; 144, argument_list; 144, 145; 144, 146; 145, None; 146, identifier:npairs; 147, block; 147, 148; 147, 163; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, pattern_list; 150, 151; 150, 152; 151, identifier:match; 152, identifier:offset; 153, call; 153, 154; 153, 155; 154, identifier:unpack; 155, argument_list; 155, 156; 155, 157; 156, string:'>ii'; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:fio; 160, identifier:read; 161, argument_list; 161, 162; 162, integer:8; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:pairs; 167, identifier:match; 168, identifier:offset; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:final_operands; 173, identifier:append; 174, argument_list; 174, 175; 175, identifier:pairs; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:final_operands; 180, identifier:append; 181, argument_list; 181, 182; 182, call; 182, 183; 182, 184; 183, identifier:Operand; 184, argument_list; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:OperandTypes; 187, identifier:BRANCH; 188, identifier:default; 189, elif_clause; 189, 190; 189, 193; 190, comparison_operator:==; 190, 191; 190, 192; 191, identifier:op; 192, integer:0xAA; 193, block; 193, 194; 193, 205; 193, 214; 193, 221; 193, 237; 193, 250; 193, 263; 193, 276; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:padding; 197, binary_operator:-; 197, 198; 197, 199; 198, integer:4; 199, binary_operator:%; 199, 200; 199, 204; 200, parenthesized_expression; 200, 201; 201, binary_operator:+; 201, 202; 201, 203; 202, identifier:start_pos; 203, integer:1; 204, integer:4; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:padding; 208, conditional_expression:if; 208, 209; 208, 210; 208, 213; 209, identifier:padding; 210, comparison_operator:!=; 210, 211; 210, 212; 211, identifier:padding; 212, integer:4; 213, integer:0; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:fio; 218, identifier:read; 219, argument_list; 219, 220; 220, identifier:padding; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 227; 223, pattern_list; 223, 224; 223, 225; 223, 226; 224, identifier:default; 225, identifier:low; 226, identifier:high; 227, call; 227, 228; 227, 229; 228, identifier:unpack; 229, argument_list; 229, 230; 229, 231; 230, string:'>iii'; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:fio; 234, identifier:read; 235, argument_list; 235, 236; 236, integer:12; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:final_operands; 241, identifier:append; 242, argument_list; 242, 243; 243, call; 243, 244; 243, 245; 244, identifier:Operand; 245, argument_list; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:OperandTypes; 248, identifier:BRANCH; 249, identifier:default; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:final_operands; 254, identifier:append; 255, argument_list; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:Operand; 258, argument_list; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:OperandTypes; 261, identifier:LITERAL; 262, identifier:low; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:final_operands; 267, identifier:append; 268, argument_list; 268, 269; 269, call; 269, 270; 269, 271; 270, identifier:Operand; 271, argument_list; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:OperandTypes; 274, identifier:LITERAL; 275, identifier:high; 276, for_statement; 276, 277; 276, 278; 276, 287; 277, identifier:_; 278, call; 278, 279; 278, 280; 279, identifier:repeat; 280, argument_list; 280, 281; 280, 282; 281, None; 282, binary_operator:+; 282, 283; 282, 286; 283, binary_operator:-; 283, 284; 283, 285; 284, identifier:high; 285, identifier:low; 286, integer:1; 287, block; 287, 288; 287, 303; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:offset; 291, subscript; 291, 292; 291, 302; 292, call; 292, 293; 292, 294; 293, identifier:unpack; 294, argument_list; 294, 295; 294, 296; 295, string:'>i'; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:fio; 299, identifier:read; 300, argument_list; 300, 301; 301, integer:4; 302, integer:0; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:final_operands; 307, identifier:append; 308, argument_list; 308, 309; 309, call; 309, 310; 309, 311; 310, identifier:Operand; 311, argument_list; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:OperandTypes; 314, identifier:BRANCH; 315, identifier:offset; 316, elif_clause; 316, 317; 316, 320; 317, comparison_operator:==; 317, 318; 317, 319; 318, identifier:op; 319, integer:0xC4; 320, block; 320, 321; 320, 336; 320, 342; 320, 348; 320, 372; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:real_op; 324, subscript; 324, 325; 324, 335; 325, call; 325, 326; 325, 327; 326, identifier:unpack; 327, argument_list; 327, 328; 327, 329; 328, string:'>B'; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:fio; 332, identifier:read; 333, argument_list; 333, 334; 334, integer:1; 335, integer:0; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:ins; 339, subscript; 339, 340; 339, 341; 340, identifier:opcode_table; 341, identifier:real_op; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 345; 344, identifier:name; 345, subscript; 345, 346; 345, 347; 346, identifier:ins; 347, string:'mnemonic'; 348, expression_statement; 348, 349; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:final_operands; 352, identifier:append; 353, argument_list; 353, 354; 354, call; 354, 355; 354, 356; 355, identifier:Operand; 356, argument_list; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:OperandTypes; 359, identifier:LOCAL_INDEX; 360, subscript; 360, 361; 360, 371; 361, call; 361, 362; 361, 363; 362, identifier:unpack; 363, argument_list; 363, 364; 363, 365; 364, string:'>H'; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:fio; 368, identifier:read; 369, argument_list; 369, 370; 370, integer:2; 371, integer:0; 372, if_statement; 372, 373; 372, 376; 373, comparison_operator:==; 373, 374; 373, 375; 374, identifier:real_op; 375, integer:0x84; 376, block; 376, 377; 377, expression_statement; 377, 378; 378, call; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:final_operands; 381, identifier:append; 382, argument_list; 382, 383; 383, call; 383, 384; 383, 385; 384, identifier:Operand; 385, argument_list; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:OperandTypes; 388, identifier:LITERAL; 389, subscript; 389, 390; 389, 400; 390, call; 390, 391; 390, 392; 391, identifier:unpack; 392, argument_list; 392, 393; 392, 394; 393, string:'>H'; 394, call; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:fio; 397, identifier:read; 398, argument_list; 398, 399; 399, integer:2; 400, integer:0; 401, return_statement; 401, 402; 402, call; 402, 403; 402, 404; 403, identifier:Instruction; 404, argument_list; 404, 405; 404, 406; 404, 407; 404, 408; 405, identifier:name; 406, identifier:op; 407, identifier:final_operands; 408, identifier:start_pos | def read_instruction(fio, start_pos):
op = fio.read(1)
if not op:
return None
op = ord(op)
ins = opcode_table[op]
operands = ins['operands']
name = ins['mnemonic']
final_operands = []
if operands:
for fmt, type_ in operands:
final_operands.append(
Operand(
type_,
fmt.value.unpack(fio.read(fmt.value.size))[0]
)
)
elif op == 0xAB:
padding = 4 - (start_pos + 1) % 4
padding = padding if padding != 4 else 0
fio.read(padding)
default, npairs = unpack('>ii', fio.read(8))
pairs = {}
for _ in repeat(None, npairs):
match, offset = unpack('>ii', fio.read(8))
pairs[match] = offset
final_operands.append(pairs)
final_operands.append(Operand(OperandTypes.BRANCH, default))
elif op == 0xAA:
padding = 4 - (start_pos + 1) % 4
padding = padding if padding != 4 else 0
fio.read(padding)
default, low, high = unpack('>iii', fio.read(12))
final_operands.append(Operand(OperandTypes.BRANCH, default))
final_operands.append(Operand(OperandTypes.LITERAL, low))
final_operands.append(Operand(OperandTypes.LITERAL, high))
for _ in repeat(None, high - low + 1):
offset = unpack('>i', fio.read(4))[0]
final_operands.append(Operand(OperandTypes.BRANCH, offset))
elif op == 0xC4:
real_op = unpack('>B', fio.read(1))[0]
ins = opcode_table[real_op]
name = ins['mnemonic']
final_operands.append(Operand(
OperandTypes.LOCAL_INDEX,
unpack('>H', fio.read(2))[0]
))
if real_op == 0x84:
final_operands.append(Operand(
OperandTypes.LITERAL,
unpack('>H', fio.read(2))[0]
))
return Instruction(name, op, final_operands, start_pos) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_by_type; 3, parameters; 3, 4; 4, identifier:file_list; 5, block; 5, 6; 5, 13; 5, 45; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:ret_dict; 9, call; 9, 10; 9, 11; 10, identifier:defaultdict; 11, argument_list; 11, 12; 12, identifier:list; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:filepath; 15, identifier:file_list; 16, block; 16, 17; 16, 30; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, pattern_list; 19, 20; 19, 21; 20, identifier:_; 21, identifier:ext; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:os; 26, identifier:path; 27, identifier:splitext; 28, argument_list; 28, 29; 29, identifier:filepath; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 43; 32, attribute; 32, 33; 32, 42; 33, subscript; 33, 34; 33, 35; 34, identifier:ret_dict; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:ext; 38, identifier:replace; 39, argument_list; 39, 40; 39, 41; 40, string:'.'; 41, string:''; 42, identifier:append; 43, argument_list; 43, 44; 44, identifier:filepath; 45, return_statement; 45, 46; 46, identifier:ret_dict | def sort_by_type(file_list):
ret_dict = defaultdict(list)
for filepath in file_list:
_, ext = os.path.splitext(filepath)
ret_dict[ext.replace('.', '')].append(filepath)
return ret_dict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_check_triple; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:triple; 6, block; 6, 7; 6, 14; 6, 40; 6, 44; 6, 53; 6, 62; 6, 83; 6, 95; 6, 114; 6, 146; 6, 155; 6, 169; 6, 181; 6, 188; 6, 199; 6, 211; 6, 223; 6, 235; 6, 246; 6, 253; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 13; 9, pattern_list; 9, 10; 9, 11; 9, 12; 10, identifier:subj; 11, identifier:pred; 12, identifier:obj; 13, identifier:triple; 14, if_statement; 14, 15; 14, 21; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_should_ignore_predicate; 19, argument_list; 19, 20; 20, identifier:pred; 21, block; 21, 22; 21, 39; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:log; 26, identifier:info; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, string:"Ignoring triple with predicate '{}'"; 31, identifier:format; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_field_name_from_uri; 37, argument_list; 37, 38; 38, identifier:pred; 39, return_statement; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:classes; 43, list:[]; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:log; 48, identifier:warning; 49, argument_list; 49, 50; 50, binary_operator:%; 50, 51; 50, 52; 51, string:"Possible member %s found"; 52, identifier:pred; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:pred; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_expand_qname; 60, argument_list; 60, 61; 61, identifier:pred; 62, if_statement; 62, 63; 62, 73; 63, comparison_operator:not; 63, 64; 63, 70; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:_namespace_from_uri; 68, argument_list; 68, 69; 69, identifier:pred; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:allowed_namespaces; 73, block; 73, 74; 73, 82; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:log; 78, identifier:info; 79, argument_list; 79, 80; 79, 81; 80, string:"Member %s does not use an allowed namespace"; 81, identifier:pred; 82, return_statement; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:instanceof; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_is_instance; 90, argument_list; 90, 91; 91, tuple; 91, 92; 91, 93; 91, 94; 92, identifier:subj; 93, identifier:pred; 94, identifier:obj; 95, if_statement; 95, 96; 95, 104; 96, comparison_operator:==; 96, 97; 96, 101; 97, call; 97, 98; 97, 99; 98, identifier:type; 99, argument_list; 99, 100; 100, identifier:instanceof; 101, attribute; 101, 102; 101, 103; 102, identifier:rt; 103, identifier:URIRef; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:instanceof; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:_expand_qname; 112, argument_list; 112, 113; 113, identifier:instanceof; 114, if_statement; 114, 115; 114, 130; 115, boolean_operator:and; 115, 116; 115, 123; 115, 124; 116, call; 116, 117; 116, 118; 117, identifier:hasattr; 118, argument_list; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:schema_def; 122, string:"attributes_by_class"; 123, line_continuation:\; 124, not_operator; 124, 125; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:schema_def; 129, identifier:attributes_by_class; 130, block; 130, 131; 130, 138; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:log; 135, identifier:info; 136, argument_list; 136, 137; 137, string:"Parsed ontology not found. Parsing..."; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:schema_def; 144, identifier:parse_ontology; 145, argument_list; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:class_invalid; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:_validate_class; 153, argument_list; 153, 154; 154, identifier:instanceof; 155, if_statement; 155, 156; 155, 157; 156, identifier:class_invalid; 157, block; 157, 158; 157, 167; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:log; 162, identifier:warning; 163, argument_list; 163, 164; 164, binary_operator:%; 164, 165; 164, 166; 165, string:"Invalid class %s"; 166, identifier:instanceof; 167, return_statement; 167, 168; 168, identifier:class_invalid; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:classes; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:_superclasses_for_subject; 176, argument_list; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:graph; 180, identifier:instanceof; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:classes; 185, identifier:append; 186, argument_list; 186, 187; 187, identifier:instanceof; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:member_invalid; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:_validate_member; 195, argument_list; 195, 196; 195, 197; 195, 198; 196, identifier:pred; 197, identifier:classes; 198, identifier:instanceof; 199, if_statement; 199, 200; 199, 201; 200, identifier:member_invalid; 201, block; 201, 202; 201, 209; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:log; 206, identifier:warning; 207, argument_list; 207, 208; 208, string:"Invalid member of class"; 209, return_statement; 209, 210; 210, identifier:member_invalid; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:dupe_invalid; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:_validate_duplication; 218, argument_list; 218, 219; 218, 222; 219, tuple; 219, 220; 219, 221; 220, identifier:subj; 221, identifier:pred; 222, identifier:instanceof; 223, if_statement; 223, 224; 223, 225; 224, identifier:dupe_invalid; 225, block; 225, 226; 225, 233; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:log; 230, identifier:warning; 231, argument_list; 231, 232; 232, string:"Duplication found"; 233, return_statement; 233, 234; 234, identifier:dupe_invalid; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 242; 237, attribute; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:checked_attributes; 241, identifier:append; 242, argument_list; 242, 243; 243, tuple; 243, 244; 243, 245; 244, identifier:subj; 245, identifier:pred; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:log; 250, identifier:warning; 251, argument_list; 251, 252; 252, string:"successfully validated triple, no errors"; 253, return_statement | def _check_triple(self, triple):
subj, pred, obj = triple
if self._should_ignore_predicate(pred):
log.info("Ignoring triple with predicate '{}'"
.format(self._field_name_from_uri(pred)))
return
classes = []
log.warning("Possible member %s found" % pred)
pred = self._expand_qname(pred)
if self._namespace_from_uri(pred) not in self.allowed_namespaces:
log.info("Member %s does not use an allowed namespace", pred)
return
instanceof = self._is_instance((subj, pred, obj))
if type(instanceof) == rt.URIRef:
instanceof = self._expand_qname(instanceof)
if hasattr(self.schema_def, "attributes_by_class") and \
not self.schema_def.attributes_by_class:
log.info("Parsed ontology not found. Parsing...")
self.schema_def.parse_ontology()
class_invalid = self._validate_class(instanceof)
if class_invalid:
log.warning("Invalid class %s" % instanceof)
return class_invalid
classes = self._superclasses_for_subject(self.graph, instanceof)
classes.append(instanceof)
member_invalid = self._validate_member(pred, classes, instanceof)
if member_invalid:
log.warning("Invalid member of class")
return member_invalid
dupe_invalid = self._validate_duplication((subj, pred), instanceof)
if dupe_invalid:
log.warning("Duplication found")
return dupe_invalid
self.checked_attributes.append((subj, pred))
log.warning("successfully validated triple, no errors")
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_ontology; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 5, 27; 5, 159; 5, 172; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:start; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:time; 12, identifier:clock; 13, argument_list; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:log; 18, identifier:info; 19, argument_list; 19, 20; 20, binary_operator:%; 20, 21; 20, 22; 21, string:"Parsing ontology file for %s"; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:__class__; 26, identifier:__name__; 27, for_statement; 27, 28; 27, 32; 27, 37; 28, pattern_list; 28, 29; 28, 30; 28, 31; 29, identifier:subj; 30, identifier:pred; 31, identifier:obj; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_schema_nodes; 36, argument_list; 37, block; 37, 38; 37, 81; 37, 89; 37, 112; 38, if_statement; 38, 39; 38, 44; 39, comparison_operator:not; 39, 40; 39, 41; 40, identifier:subj; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:attributes_by_class; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 72; 46, boolean_operator:and; 46, 47; 46, 59; 46, 60; 47, comparison_operator:==; 47, 48; 47, 49; 48, identifier:obj; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:rt; 52, identifier:URIRef; 53, argument_list; 53, 54; 54, subscript; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:lexicon; 58, string:'class'; 59, line_continuation:\; 60, comparison_operator:==; 60, 61; 60, 62; 61, identifier:pred; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:rt; 65, identifier:URIRef; 66, argument_list; 66, 67; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:lexicon; 71, string:'type'; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 80; 75, subscript; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:attributes_by_class; 79, identifier:subj; 80, list:[]; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:leaves; 84, list:[(subj, pred, obj)]; 84, 85; 85, tuple; 85, 86; 85, 87; 85, 88; 86, identifier:subj; 87, identifier:pred; 88, identifier:obj; 89, if_statement; 89, 90; 89, 98; 90, comparison_operator:==; 90, 91; 90, 95; 91, call; 91, 92; 91, 93; 92, identifier:type; 93, argument_list; 93, 94; 94, identifier:obj; 95, attribute; 95, 96; 95, 97; 96, identifier:rt; 97, identifier:BNode; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:leaves; 102, call; 102, 103; 102, 104; 103, identifier:deepest_node; 104, argument_list; 104, 105; 104, 109; 105, tuple; 105, 106; 105, 107; 105, 108; 106, identifier:subj; 107, identifier:pred; 108, identifier:obj; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:graph; 112, for_statement; 112, 113; 112, 117; 112, 118; 113, pattern_list; 113, 114; 113, 115; 113, 116; 114, identifier:s; 115, identifier:p; 116, identifier:o; 117, identifier:leaves; 118, block; 118, 119; 118, 134; 119, if_statement; 119, 120; 119, 125; 120, comparison_operator:not; 120, 121; 120, 122; 121, identifier:o; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:attributes_by_class; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 133; 128, subscript; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:attributes_by_class; 132, identifier:o; 133, list:[]; 134, if_statement; 134, 135; 134, 147; 135, comparison_operator:==; 135, 136; 135, 137; 136, identifier:pred; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:rt; 140, identifier:URIRef; 141, argument_list; 141, 142; 142, subscript; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:lexicon; 146, string:'domain'; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 157; 150, attribute; 150, 151; 150, 156; 151, subscript; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:attributes_by_class; 155, identifier:o; 156, identifier:append; 157, argument_list; 157, 158; 158, identifier:subj; 159, if_statement; 159, 160; 159, 164; 160, not_operator; 160, 161; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:attributes_by_class; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:log; 169, identifier:info; 170, argument_list; 170, 171; 171, string:"No nodes found in ontology"; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:log; 176, identifier:info; 177, argument_list; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, string:"Ontology parsing complete in {}"; 181, identifier:format; 182, argument_list; 182, 183; 183, binary_operator:*; 183, 184; 183, 192; 184, parenthesized_expression; 184, 185; 185, binary_operator:-; 185, 186; 185, 191; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:time; 189, identifier:clock; 190, argument_list; 191, identifier:start; 192, integer:1000 | def parse_ontology(self):
start = time.clock()
log.info("Parsing ontology file for %s" % self.__class__.__name__)
for subj, pred, obj in self._schema_nodes():
if subj not in self.attributes_by_class:
if obj == rt.URIRef(self.lexicon['class']) and \
pred == rt.URIRef(self.lexicon['type']):
self.attributes_by_class[subj] = []
leaves = [(subj, pred, obj)]
if type(obj) == rt.BNode:
leaves = deepest_node((subj, pred, obj), self.graph)
for s, p, o in leaves:
if o not in self.attributes_by_class:
self.attributes_by_class[o] = []
if pred == rt.URIRef(self.lexicon['domain']):
self.attributes_by_class[o].append(subj)
if not self.attributes_by_class:
log.info("No nodes found in ontology")
log.info("Ontology parsing complete in {}".format(
(time.clock() - start) * 1000)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:new_frame_event; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 25; 5, 29; 5, 106; 5, 195; 6, for_statement; 6, 7; 6, 8; 6, 15; 7, identifier:out_pool; 8, call; 8, 9; 8, 14; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:outframe_pool; 13, identifier:values; 14, argument_list; 15, block; 15, 16; 16, if_statement; 16, 17; 16, 23; 17, not_operator; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:out_pool; 21, identifier:available; 22, argument_list; 23, block; 23, 24; 24, return_statement; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:frame_nos; 28, dictionary; 29, for_statement; 29, 30; 29, 31; 29, 38; 30, identifier:in_buff; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:input_buffer; 36, identifier:values; 37, argument_list; 38, block; 38, 39; 38, 48; 38, 56; 38, 65; 39, if_statement; 39, 40; 39, 46; 40, not_operator; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:in_buff; 44, identifier:available; 45, argument_list; 46, block; 46, 47; 47, return_statement; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:in_frame; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:in_buff; 54, identifier:peek; 55, argument_list; 56, if_statement; 56, 57; 56, 60; 57, comparison_operator:is; 57, 58; 57, 59; 58, identifier:in_frame; 59, None; 60, block; 60, 61; 61, raise_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:StopIteration; 64, argument_list; 65, if_statement; 65, 66; 65, 71; 65, 80; 66, comparison_operator:>=; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:in_frame; 69, identifier:frame_no; 70, integer:0; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:frame_nos; 76, identifier:in_buff; 77, attribute; 77, 78; 77, 79; 78, identifier:in_frame; 79, identifier:frame_no; 80, else_clause; 80, 81; 81, block; 81, 82; 82, while_statement; 82, 83; 82, 99; 83, boolean_operator:and; 83, 84; 83, 91; 84, comparison_operator:>; 84, 85; 84, 90; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:in_buff; 88, identifier:available; 89, argument_list; 90, integer:1; 91, comparison_operator:is; 91, 92; 91, 98; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:in_buff; 95, identifier:peek; 96, argument_list; 96, 97; 97, integer:1; 98, None; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:in_buff; 104, identifier:get; 105, argument_list; 106, if_statement; 106, 107; 106, 113; 107, comparison_operator:>; 107, 108; 107, 112; 108, call; 108, 109; 108, 110; 109, identifier:len; 110, argument_list; 110, 111; 111, identifier:frame_nos; 112, integer:1; 113, block; 113, 114; 113, 125; 113, 175; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:frame_no; 117, call; 117, 118; 117, 119; 118, identifier:max; 119, argument_list; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:frame_nos; 123, identifier:values; 124, argument_list; 125, for_statement; 125, 126; 125, 127; 125, 128; 126, identifier:in_buff; 127, identifier:frame_nos; 128, block; 128, 129; 129, while_statement; 129, 130; 129, 143; 130, boolean_operator:and; 130, 131; 130, 136; 131, comparison_operator:<; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:frame_nos; 134, identifier:in_buff; 135, identifier:frame_no; 136, comparison_operator:>; 136, 137; 136, 142; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:in_buff; 140, identifier:available; 141, argument_list; 142, integer:1; 143, block; 143, 144; 143, 150; 143, 158; 143, 167; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:in_buff; 148, identifier:get; 149, argument_list; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:in_frame; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:in_buff; 156, identifier:peek; 157, argument_list; 158, if_statement; 158, 159; 158, 162; 159, comparison_operator:is; 159, 160; 159, 161; 160, identifier:in_frame; 161, None; 162, block; 162, 163; 163, raise_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:StopIteration; 166, argument_list; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, subscript; 169, 170; 169, 171; 170, identifier:frame_nos; 171, identifier:in_buff; 172, attribute; 172, 173; 172, 174; 173, identifier:in_frame; 174, identifier:frame_no; 175, if_statement; 175, 176; 175, 193; 176, comparison_operator:!=; 176, 177; 176, 185; 177, call; 177, 178; 177, 179; 178, identifier:min; 179, argument_list; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:frame_nos; 183, identifier:values; 184, argument_list; 185, call; 185, 186; 185, 187; 186, identifier:max; 187, argument_list; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:frame_nos; 191, identifier:values; 192, argument_list; 193, block; 193, 194; 194, return_statement; 195, try_statement; 195, 196; 195, 203; 195, 207; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:process_frame; 202, argument_list; 203, except_clause; 203, 204; 203, 205; 204, identifier:StopIteration; 205, block; 205, 206; 206, raise_statement; 207, except_clause; 207, 208; 207, 212; 208, as_pattern; 208, 209; 208, 210; 209, identifier:Exception; 210, as_pattern_target; 210, 211; 211, identifier:ex; 212, block; 212, 213; 212, 222; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 220; 215, attribute; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:logger; 219, identifier:exception; 220, argument_list; 220, 221; 221, identifier:ex; 222, raise_statement; 222, 223; 223, call; 223, 224; 223, 225; 224, identifier:StopIteration; 225, argument_list | def new_frame_event(self):
for out_pool in self.outframe_pool.values():
if not out_pool.available():
return
frame_nos = {}
for in_buff in self.input_buffer.values():
if not in_buff.available():
return
in_frame = in_buff.peek()
if in_frame is None:
raise StopIteration()
if in_frame.frame_no >= 0:
frame_nos[in_buff] = in_frame.frame_no
else:
while in_buff.available() > 1 and in_buff.peek(1) is not None:
in_buff.get()
if len(frame_nos) > 1:
frame_no = max(frame_nos.values())
for in_buff in frame_nos:
while frame_nos[in_buff] < frame_no and in_buff.available() > 1:
in_buff.get()
in_frame = in_buff.peek()
if in_frame is None:
raise StopIteration()
frame_nos[in_buff] = in_frame.frame_no
if min(frame_nos.values()) != max(frame_nos.values()):
return
try:
self.process_frame()
except StopIteration:
raise
except Exception as ex:
self.logger.exception(ex)
raise StopIteration() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:GaussianFilterCore; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:x_sigma; 6, float:0.0; 7, default_parameter; 7, 8; 7, 9; 8, identifier:y_sigma; 9, float:0.0; 10, block; 10, 11; 10, 137; 10, 145; 10, 153; 10, 160; 10, 167; 10, 192; 10, 228; 10, 234; 10, 240; 10, 246; 10, 257; 10, 261; 10, 273; 10, 285; 10, 295; 11, function_definition; 11, 12; 11, 13; 11, 15; 12, function_name:filter_1D; 13, parameters; 13, 14; 14, identifier:sigma; 15, block; 15, 16; 15, 32; 15, 36; 15, 40; 15, 74; 15, 83; 15, 102; 15, 127; 15, 135; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:alpha; 19, binary_operator:/; 19, 20; 19, 21; 20, float:1.0; 21, parenthesized_expression; 21, 22; 22, binary_operator:*; 22, 23; 22, 24; 23, float:2.0; 24, parenthesized_expression; 24, 25; 25, binary_operator:**; 25, 26; 25, 31; 26, call; 26, 27; 26, 28; 27, identifier:max; 28, argument_list; 28, 29; 28, 30; 29, identifier:sigma; 30, float:0.0001; 31, float:2.0; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:coefs; 35, list:[]; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:coef; 39, float:1.0; 40, while_statement; 40, 41; 40, 44; 41, comparison_operator:>; 41, 42; 41, 43; 42, identifier:coef; 43, float:0.0001; 44, block; 44, 45; 44, 52; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:coefs; 49, identifier:append; 50, argument_list; 50, 51; 51, identifier:coef; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:coef; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:math; 58, identifier:exp; 59, argument_list; 59, 60; 60, unary_operator:-; 60, 61; 61, parenthesized_expression; 61, 62; 62, binary_operator:*; 62, 63; 62, 64; 63, identifier:alpha; 64, parenthesized_expression; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:float; 67, argument_list; 67, 68; 68, binary_operator:**; 68, 69; 68, 73; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, identifier:coefs; 73, integer:2; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:fil_dim; 77, binary_operator:-; 77, 78; 77, 82; 78, call; 78, 79; 78, 80; 79, identifier:len; 80, argument_list; 80, 81; 81, identifier:coefs; 82, integer:1; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:result; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:numpy; 89, identifier:zeros; 90, argument_list; 90, 91; 90, 97; 91, binary_operator:+; 91, 92; 91, 93; 92, integer:1; 93, parenthesized_expression; 93, 94; 94, binary_operator:*; 94, 95; 94, 96; 95, identifier:fil_dim; 96, integer:2; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:dtype; 99, attribute; 99, 100; 99, 101; 100, identifier:numpy; 101, identifier:float32; 102, for_statement; 102, 103; 102, 106; 102, 110; 103, pattern_list; 103, 104; 103, 105; 104, identifier:n; 105, identifier:coef; 106, call; 106, 107; 106, 108; 107, identifier:enumerate; 108, argument_list; 108, 109; 109, identifier:coefs; 110, block; 110, 111; 110, 119; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 118; 113, subscript; 113, 114; 113, 115; 114, identifier:result; 115, binary_operator:-; 115, 116; 115, 117; 116, identifier:fil_dim; 117, identifier:n; 118, identifier:coef; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 126; 121, subscript; 121, 122; 121, 123; 122, identifier:result; 123, binary_operator:+; 123, 124; 123, 125; 124, identifier:fil_dim; 125, identifier:n; 126, identifier:coef; 127, expression_statement; 127, 128; 128, augmented_assignment:/=; 128, 129; 128, 130; 129, identifier:result; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:result; 133, identifier:sum; 134, argument_list; 135, return_statement; 135, 136; 136, identifier:result; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:x_sigma; 140, call; 140, 141; 140, 142; 141, identifier:max; 142, argument_list; 142, 143; 142, 144; 143, identifier:x_sigma; 144, float:0.0; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:y_sigma; 148, call; 148, 149; 148, 150; 149, identifier:max; 150, argument_list; 150, 151; 150, 152; 151, identifier:y_sigma; 152, float:0.0; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:x_fil; 156, call; 156, 157; 156, 158; 157, identifier:filter_1D; 158, argument_list; 158, 159; 159, identifier:x_sigma; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:y_fil; 163, call; 163, 164; 163, 165; 164, identifier:filter_1D; 165, argument_list; 165, 166; 166, identifier:y_sigma; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:result; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:numpy; 173, identifier:empty; 174, argument_list; 174, 175; 174, 187; 175, list:[y_fil.shape[0], x_fil.shape[0], 1]; 175, 176; 175, 181; 175, 186; 176, subscript; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:y_fil; 179, identifier:shape; 180, integer:0; 181, subscript; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:x_fil; 184, identifier:shape; 185, integer:0; 186, integer:1; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:dtype; 189, attribute; 189, 190; 189, 191; 190, identifier:numpy; 191, identifier:float32; 192, for_statement; 192, 193; 192, 194; 192, 202; 193, identifier:y; 194, call; 194, 195; 194, 196; 195, identifier:range; 196, argument_list; 196, 197; 197, subscript; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:y_fil; 200, identifier:shape; 201, integer:0; 202, block; 202, 203; 203, for_statement; 203, 204; 203, 205; 203, 213; 204, identifier:x; 205, call; 205, 206; 205, 207; 206, identifier:range; 207, argument_list; 207, 208; 208, subscript; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:x_fil; 211, identifier:shape; 212, integer:0; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 221; 216, subscript; 216, 217; 216, 218; 216, 219; 216, 220; 217, identifier:result; 218, identifier:y; 219, identifier:x; 220, integer:0; 221, binary_operator:*; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:x_fil; 224, identifier:x; 225, subscript; 225, 226; 225, 227; 226, identifier:y_fil; 227, identifier:y; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:out_frame; 231, call; 231, 232; 231, 233; 232, identifier:Frame; 233, argument_list; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:out_frame; 238, identifier:data; 239, identifier:result; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:out_frame; 244, identifier:type; 245, string:'fil'; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:audit; 249, call; 249, 250; 249, 255; 250, attribute; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:out_frame; 253, identifier:metadata; 254, identifier:get; 255, argument_list; 255, 256; 256, string:'audit'; 257, expression_statement; 257, 258; 258, augmented_assignment:+=; 258, 259; 258, 260; 259, identifier:audit; 260, string:'data = GaussianFilter()\n'; 261, if_statement; 261, 262; 261, 265; 262, comparison_operator:!=; 262, 263; 262, 264; 263, identifier:x_sigma; 264, float:0.0; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, augmented_assignment:+=; 267, 268; 267, 269; 268, identifier:audit; 269, binary_operator:%; 269, 270; 269, 271; 270, string:' x_sigma: %g\n'; 271, parenthesized_expression; 271, 272; 272, identifier:x_sigma; 273, if_statement; 273, 274; 273, 277; 274, comparison_operator:!=; 274, 275; 274, 276; 275, identifier:y_sigma; 276, float:0.0; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, augmented_assignment:+=; 279, 280; 279, 281; 280, identifier:audit; 281, binary_operator:%; 281, 282; 281, 283; 282, string:' y_sigma: %g\n'; 283, parenthesized_expression; 283, 284; 284, identifier:y_sigma; 285, expression_statement; 285, 286; 286, call; 286, 287; 286, 292; 287, attribute; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:out_frame; 290, identifier:metadata; 291, identifier:set; 292, argument_list; 292, 293; 292, 294; 293, string:'audit'; 294, identifier:audit; 295, return_statement; 295, 296; 296, identifier:out_frame | def GaussianFilterCore(x_sigma=0.0, y_sigma=0.0):
def filter_1D(sigma):
alpha = 1.0 / (2.0 * (max(sigma, 0.0001) ** 2.0))
coefs = []
coef = 1.0
while coef > 0.0001:
coefs.append(coef)
coef = math.exp(-(alpha * (float(len(coefs) ** 2))))
fil_dim = len(coefs) - 1
result = numpy.zeros(1 + (fil_dim * 2), dtype=numpy.float32)
for n, coef in enumerate(coefs):
result[fil_dim - n] = coef
result[fil_dim + n] = coef
result /= result.sum()
return result
x_sigma = max(x_sigma, 0.0)
y_sigma = max(y_sigma, 0.0)
x_fil = filter_1D(x_sigma)
y_fil = filter_1D(y_sigma)
result = numpy.empty(
[y_fil.shape[0], x_fil.shape[0], 1], dtype=numpy.float32)
for y in range(y_fil.shape[0]):
for x in range(x_fil.shape[0]):
result[y, x, 0] = x_fil[x] * y_fil[y]
out_frame = Frame()
out_frame.data = result
out_frame.type = 'fil'
audit = out_frame.metadata.get('audit')
audit += 'data = GaussianFilter()\n'
if x_sigma != 0.0:
audit += ' x_sigma: %g\n' % (x_sigma)
if y_sigma != 0.0:
audit += ' y_sigma: %g\n' % (y_sigma)
out_frame.metadata.set('audit', audit)
return out_frame |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:either; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, if_statement; 6, 7; 6, 13; 6, 22; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:hasattr; 10, argument_list; 10, 11; 10, 12; 11, identifier:self; 12, string:'children'; 13, block; 13, 14; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:Either; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:Required; 20, argument_list; 20, 21; 21, identifier:self; 22, else_clause; 22, 23; 23, block; 23, 24; 23, 28; 23, 34; 23, 262; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:ret; 27, list:[]; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:groups; 31, list:[[self]]; 31, 32; 32, list:[self]; 32, 33; 33, identifier:self; 34, while_statement; 34, 35; 34, 36; 35, identifier:groups; 36, block; 36, 37; 36, 46; 36, 57; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:children; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:groups; 43, identifier:pop; 44, argument_list; 44, 45; 45, integer:0; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:types; 49, list_comprehension; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:type; 52, argument_list; 52, 53; 53, identifier:c; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:c; 56, identifier:children; 57, if_statement; 57, 58; 57, 61; 57, 107; 57, 155; 57, 203; 57, 253; 58, comparison_operator:in; 58, 59; 58, 60; 59, identifier:Either; 60, identifier:types; 61, block; 61, 62; 61, 79; 61, 91; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:either; 65, subscript; 65, 66; 65, 78; 66, list_comprehension; 66, 67; 66, 68; 66, 71; 67, identifier:c; 68, for_in_clause; 68, 69; 68, 70; 69, identifier:c; 70, identifier:children; 71, if_clause; 71, 72; 72, comparison_operator:is; 72, 73; 72, 77; 73, call; 73, 74; 73, 75; 74, identifier:type; 75, argument_list; 75, 76; 76, identifier:c; 77, identifier:Either; 78, integer:0; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:children; 83, identifier:pop; 84, argument_list; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:children; 88, identifier:index; 89, argument_list; 89, 90; 90, identifier:either; 91, for_statement; 91, 92; 91, 93; 91, 96; 92, identifier:c; 93, attribute; 93, 94; 93, 95; 94, identifier:either; 95, identifier:children; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:groups; 101, identifier:append; 102, argument_list; 102, 103; 103, binary_operator:+; 103, 104; 103, 106; 104, list:[c]; 104, 105; 105, identifier:c; 106, identifier:children; 107, elif_clause; 107, 108; 107, 111; 108, comparison_operator:in; 108, 109; 108, 110; 109, identifier:Required; 110, identifier:types; 111, block; 111, 112; 111, 129; 111, 141; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:required; 115, subscript; 115, 116; 115, 128; 116, list_comprehension; 116, 117; 116, 118; 116, 121; 117, identifier:c; 118, for_in_clause; 118, 119; 118, 120; 119, identifier:c; 120, identifier:children; 121, if_clause; 121, 122; 122, comparison_operator:is; 122, 123; 122, 127; 123, call; 123, 124; 123, 125; 124, identifier:type; 125, argument_list; 125, 126; 126, identifier:c; 127, identifier:Required; 128, integer:0; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:children; 133, identifier:pop; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:children; 138, identifier:index; 139, argument_list; 139, 140; 140, identifier:required; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:groups; 145, identifier:append; 146, argument_list; 146, 147; 147, binary_operator:+; 147, 148; 147, 154; 148, call; 148, 149; 148, 150; 149, identifier:list; 150, argument_list; 150, 151; 151, attribute; 151, 152; 151, 153; 152, identifier:required; 153, identifier:children; 154, identifier:children; 155, elif_clause; 155, 156; 155, 159; 156, comparison_operator:in; 156, 157; 156, 158; 157, identifier:Optional; 158, identifier:types; 159, block; 159, 160; 159, 177; 159, 189; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:optional; 163, subscript; 163, 164; 163, 176; 164, list_comprehension; 164, 165; 164, 166; 164, 169; 165, identifier:c; 166, for_in_clause; 166, 167; 166, 168; 167, identifier:c; 168, identifier:children; 169, if_clause; 169, 170; 170, comparison_operator:is; 170, 171; 170, 175; 171, call; 171, 172; 171, 173; 172, identifier:type; 173, argument_list; 173, 174; 174, identifier:c; 175, identifier:Optional; 176, integer:0; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:children; 181, identifier:pop; 182, argument_list; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:children; 186, identifier:index; 187, argument_list; 187, 188; 188, identifier:optional; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:groups; 193, identifier:append; 194, argument_list; 194, 195; 195, binary_operator:+; 195, 196; 195, 202; 196, call; 196, 197; 196, 198; 197, identifier:list; 198, argument_list; 198, 199; 199, attribute; 199, 200; 199, 201; 200, identifier:optional; 201, identifier:children; 202, identifier:children; 203, elif_clause; 203, 204; 203, 207; 204, comparison_operator:in; 204, 205; 204, 206; 205, identifier:OneOrMore; 206, identifier:types; 207, block; 207, 208; 207, 225; 207, 237; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:oneormore; 211, subscript; 211, 212; 211, 224; 212, list_comprehension; 212, 213; 212, 214; 212, 217; 213, identifier:c; 214, for_in_clause; 214, 215; 214, 216; 215, identifier:c; 216, identifier:children; 217, if_clause; 217, 218; 218, comparison_operator:is; 218, 219; 218, 223; 219, call; 219, 220; 219, 221; 220, identifier:type; 221, argument_list; 221, 222; 222, identifier:c; 223, identifier:OneOrMore; 224, integer:0; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:children; 229, identifier:pop; 230, argument_list; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:children; 234, identifier:index; 235, argument_list; 235, 236; 236, identifier:oneormore; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:groups; 241, identifier:append; 242, argument_list; 242, 243; 243, binary_operator:+; 243, 244; 243, 252; 244, binary_operator:*; 244, 245; 244, 251; 245, call; 245, 246; 245, 247; 246, identifier:list; 247, argument_list; 247, 248; 248, attribute; 248, 249; 248, 250; 249, identifier:oneormore; 250, identifier:children; 251, integer:2; 252, identifier:children; 253, else_clause; 253, 254; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:ret; 259, identifier:append; 260, argument_list; 260, 261; 261, identifier:children; 262, return_statement; 262, 263; 263, call; 263, 264; 263, 265; 264, identifier:Either; 265, argument_list; 265, 266; 266, list_splat; 266, 267; 267, list_comprehension; 267, 268; 267, 273; 268, call; 268, 269; 268, 270; 269, identifier:Required; 270, argument_list; 270, 271; 271, list_splat; 271, 272; 272, identifier:e; 273, for_in_clause; 273, 274; 273, 275; 274, identifier:e; 275, identifier:ret | def either(self):
if not hasattr(self, 'children'):
return Either(Required(self))
else:
ret = []
groups = [[self]]
while groups:
children = groups.pop(0)
types = [type(c) for c in children]
if Either in types:
either = [c for c in children if type(c) is Either][0]
children.pop(children.index(either))
for c in either.children:
groups.append([c] + children)
elif Required in types:
required = [c for c in children if type(c) is Required][0]
children.pop(children.index(required))
groups.append(list(required.children) + children)
elif Optional in types:
optional = [c for c in children if type(c) is Optional][0]
children.pop(children.index(optional))
groups.append(list(optional.children) + children)
elif OneOrMore in types:
oneormore = [c for c in children if type(c) is OneOrMore][0]
children.pop(children.index(oneormore))
groups.append(list(oneormore.children) * 2 + children)
else:
ret.append(children)
return Either(*[Required(*e) for e in ret]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:TranslateManagedObject; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:mObj; 5, identifier:xlateOrg; 6, identifier:xlateMap; 7, block; 7, 8; 7, 15; 7, 20; 7, 28; 7, 39; 7, 198; 7, 352; 8, import_from_statement; 8, 9; 8, 11; 8, 13; 9, dotted_name; 9, 10; 10, identifier:UcsBase; 11, dotted_name; 11, 12; 12, identifier:UcsUtils; 13, dotted_name; 13, 14; 14, identifier:WriteUcsWarning; 15, import_from_statement; 15, 16; 15, 18; 16, dotted_name; 16, 17; 17, identifier:Mos; 18, dotted_name; 18, 19; 19, identifier:OrgOrg; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:xMO; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:mObj; 26, identifier:Clone; 27, argument_list; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:xMO; 32, identifier:SetHandle; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:mObj; 37, identifier:GetHandle; 38, argument_list; 39, if_statement; 39, 40; 39, 44; 40, parenthesized_expression; 40, 41; 41, comparison_operator:!=; 41, 42; 41, 43; 42, identifier:xlateOrg; 43, None; 44, block; 44, 45; 44, 57; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:matchObj; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:re; 51, identifier:match; 52, argument_list; 52, 53; 52, 54; 53, string:r'^(org-[\-\.:_a-zA-Z0-9]{1,16}/)*org-[\-\.:_a-zA-Z0-9]{1,16}'; 54, attribute; 54, 55; 54, 56; 55, identifier:xMO; 56, identifier:Dn; 57, if_statement; 57, 58; 57, 59; 58, identifier:matchObj; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 75; 60, 166; 61, comparison_operator:==; 61, 62; 61, 70; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:UcsUtils; 65, identifier:WordL; 66, argument_list; 66, 67; 67, attribute; 67, 68; 67, 69; 68, identifier:xMO; 69, identifier:classId; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:OrgOrg; 73, identifier:ClassId; 74, argument_list; 75, block; 75, 76; 75, 95; 75, 112; 75, 124; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:orgMoMeta; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:UcsUtils; 82, identifier:GetUcsPropertyMeta; 83, argument_list; 83, 84; 83, 94; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:UcsUtils; 87, identifier:WordU; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:OrgOrg; 92, identifier:ClassId; 93, argument_list; 94, string:"Meta"; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:==; 96, 97; 96, 98; 97, identifier:orgMoMeta; 98, None; 99, block; 99, 100; 99, 110; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:WriteUcsWarning; 103, argument_list; 103, 104; 104, binary_operator:%; 104, 105; 104, 106; 105, string:'[Warning]: Could not translate [%s]'; 106, parenthesized_expression; 106, 107; 107, attribute; 107, 108; 107, 109; 108, identifier:xMO; 109, identifier:Dn; 110, return_statement; 110, 111; 111, identifier:xMO; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:matchObj1; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:re; 118, identifier:findall; 119, argument_list; 119, 120; 119, 121; 120, string:r'(\[[^\]]+\])'; 121, attribute; 121, 122; 121, 123; 122, identifier:orgMoMeta; 123, identifier:rn; 124, if_statement; 124, 125; 124, 126; 124, 134; 125, identifier:matchObj1; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:UpdateMoDnAlongWithNamingProperties; 130, argument_list; 130, 131; 130, 132; 130, 133; 131, identifier:xMO; 132, identifier:orgMoMeta; 133, identifier:xlateOrg; 134, else_clause; 134, 135; 135, block; 135, 136; 135, 160; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:newDn; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:re; 142, identifier:sub; 143, argument_list; 143, 144; 143, 153; 143, 157; 144, binary_operator:%; 144, 145; 144, 146; 145, string:"%s"; 146, parenthesized_expression; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:matchObj; 150, identifier:group; 151, argument_list; 151, 152; 152, integer:0; 153, binary_operator:%; 153, 154; 153, 155; 154, string:"%s"; 155, parenthesized_expression; 155, 156; 156, identifier:xlateOrg; 157, attribute; 157, 158; 157, 159; 158, identifier:xMO; 159, identifier:Dn; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:xMO; 164, identifier:Dn; 165, identifier:newDn; 166, else_clause; 166, 167; 167, block; 167, 168; 167, 192; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:newDn; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:re; 174, identifier:sub; 175, argument_list; 175, 176; 175, 185; 175, 189; 176, binary_operator:%; 176, 177; 176, 178; 177, string:"^%s/"; 178, parenthesized_expression; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:matchObj; 182, identifier:group; 183, argument_list; 183, 184; 184, integer:0; 185, binary_operator:%; 185, 186; 185, 187; 186, string:"%s/"; 187, parenthesized_expression; 187, 188; 188, identifier:xlateOrg; 189, attribute; 189, 190; 189, 191; 190, identifier:xMO; 191, identifier:Dn; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:xMO; 196, identifier:Dn; 197, identifier:newDn; 198, if_statement; 198, 199; 198, 203; 199, parenthesized_expression; 199, 200; 200, comparison_operator:!=; 200, 201; 200, 202; 201, identifier:xlateMap; 202, None; 203, block; 203, 204; 203, 210; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:originalDn; 207, attribute; 207, 208; 207, 209; 208, identifier:xMO; 209, identifier:Dn; 210, if_statement; 210, 211; 210, 214; 210, 281; 211, comparison_operator:in; 211, 212; 211, 213; 212, identifier:originalDn; 213, identifier:xlateMap; 214, block; 214, 215; 214, 232; 214, 247; 214, 259; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:xMoMeta; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:UcsUtils; 221, identifier:GetUcsPropertyMeta; 222, argument_list; 222, 223; 222, 231; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:UcsUtils; 226, identifier:WordU; 227, argument_list; 227, 228; 228, attribute; 228, 229; 228, 230; 229, identifier:xMO; 230, identifier:classId; 231, string:"Meta"; 232, if_statement; 232, 233; 232, 236; 233, comparison_operator:==; 233, 234; 233, 235; 234, identifier:xMoMeta; 235, None; 236, block; 236, 237; 236, 245; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 240; 239, identifier:WriteUcsWarning; 240, argument_list; 240, 241; 241, binary_operator:%; 241, 242; 241, 243; 242, string:'[Warning]: Could not translate [%s]'; 243, parenthesized_expression; 243, 244; 244, identifier:originalDn; 245, return_statement; 245, 246; 246, identifier:xMO; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:matchObj; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:re; 253, identifier:findall; 254, argument_list; 254, 255; 254, 256; 255, string:r'(\[[^\]]+\])'; 256, attribute; 256, 257; 256, 258; 257, identifier:xMoMeta; 258, identifier:rn; 259, if_statement; 259, 260; 259, 261; 259, 271; 260, identifier:matchObj; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 265; 264, identifier:UpdateMoDnAlongWithNamingProperties; 265, argument_list; 265, 266; 265, 267; 265, 268; 266, identifier:xMO; 267, identifier:xMoMeta; 268, subscript; 268, 269; 268, 270; 269, identifier:xlateMap; 270, identifier:originalDn; 271, else_clause; 271, 272; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:xMO; 277, identifier:Dn; 278, subscript; 278, 279; 278, 280; 279, identifier:xlateMap; 280, identifier:originalDn; 281, else_clause; 281, 282; 282, block; 282, 283; 282, 294; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:originalDn; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:re; 289, identifier:sub; 290, argument_list; 290, 291; 290, 292; 290, 293; 291, string:r'[/]*[^/]+$'; 292, string:''; 293, identifier:originalDn; 294, while_statement; 294, 295; 294, 303; 295, parenthesized_expression; 295, 296; 296, boolean_operator:or; 296, 297; 296, 300; 297, comparison_operator:!=; 297, 298; 297, 299; 298, identifier:originalDn; 299, None; 300, comparison_operator:==; 300, 301; 300, 302; 301, identifier:originalDn; 302, string:""; 303, block; 303, 304; 303, 324; 303, 345; 303, 351; 304, if_statement; 304, 305; 304, 311; 305, parenthesized_expression; 305, 306; 306, not_operator; 306, 307; 307, parenthesized_expression; 307, 308; 308, comparison_operator:in; 308, 309; 308, 310; 309, identifier:originalDn; 310, identifier:xlateMap; 311, block; 311, 312; 311, 323; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:originalDn; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:re; 318, identifier:sub; 319, argument_list; 319, 320; 319, 321; 319, 322; 320, string:r'[/]*[^/]+$'; 321, string:''; 322, identifier:originalDn; 323, continue_statement; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:newDn; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:re; 330, identifier:sub; 331, argument_list; 331, 332; 331, 336; 331, 342; 332, binary_operator:%; 332, 333; 332, 334; 333, string:"^%s/"; 334, parenthesized_expression; 334, 335; 335, identifier:originalDn; 336, binary_operator:%; 336, 337; 336, 338; 337, string:"%s/"; 338, parenthesized_expression; 338, 339; 339, subscript; 339, 340; 339, 341; 340, identifier:xlateMap; 341, identifier:originalDn; 342, attribute; 342, 343; 342, 344; 343, identifier:xMO; 344, identifier:Dn; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:xMO; 349, identifier:Dn; 350, identifier:newDn; 351, break_statement; 352, return_statement; 352, 353; 353, identifier:xMO | def TranslateManagedObject(mObj, xlateOrg, xlateMap):
from UcsBase import UcsUtils, WriteUcsWarning
from Mos import OrgOrg
xMO = mObj.Clone()
xMO.SetHandle(mObj.GetHandle())
if (xlateOrg != None):
matchObj = re.match(r'^(org-[\-\.:_a-zA-Z0-9]{1,16}/)*org-[\-\.:_a-zA-Z0-9]{1,16}', xMO.Dn)
if matchObj:
if UcsUtils.WordL(xMO.classId) == OrgOrg.ClassId():
orgMoMeta = UcsUtils.GetUcsPropertyMeta(UcsUtils.WordU(OrgOrg.ClassId()), "Meta")
if orgMoMeta == None:
WriteUcsWarning('[Warning]: Could not translate [%s]' % (xMO.Dn))
return xMO
matchObj1 = re.findall(r'(\[[^\]]+\])', orgMoMeta.rn)
if matchObj1:
UpdateMoDnAlongWithNamingProperties(xMO, orgMoMeta, xlateOrg)
else:
newDn = re.sub("%s" % (matchObj.group(0)), "%s" % (xlateOrg), xMO.Dn)
xMO.Dn = newDn
else:
newDn = re.sub("^%s/" % (matchObj.group(0)), "%s/" % (xlateOrg), xMO.Dn)
xMO.Dn = newDn
if (xlateMap != None):
originalDn = xMO.Dn
if originalDn in xlateMap:
xMoMeta = UcsUtils.GetUcsPropertyMeta(UcsUtils.WordU(xMO.classId), "Meta")
if xMoMeta == None:
WriteUcsWarning('[Warning]: Could not translate [%s]' % (originalDn))
return xMO
matchObj = re.findall(r'(\[[^\]]+\])', xMoMeta.rn)
if matchObj:
UpdateMoDnAlongWithNamingProperties(xMO, xMoMeta, xlateMap[originalDn])
else:
xMO.Dn = xlateMap[originalDn]
else:
originalDn = re.sub(r'[/]*[^/]+$', '', originalDn)
while (originalDn != None or originalDn == ""):
if (not (originalDn in xlateMap)):
originalDn = re.sub(r'[/]*[^/]+$', '', originalDn)
continue
newDn = re.sub("^%s/" % (originalDn), "%s/" % (xlateMap[originalDn]), xMO.Dn)
xMO.Dn = newDn
break
return xMO |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:ImportUcsSession; 3, parameters; 3, 4; 3, 5; 4, identifier:filePath; 5, identifier:key; 6, block; 6, 7; 6, 16; 6, 26; 6, 36; 6, 65; 6, 78; 6, 84; 6, 99; 7, import_from_statement; 7, 8; 7, 10; 7, 12; 7, 14; 8, dotted_name; 8, 9; 9, identifier:UcsBase; 10, dotted_name; 10, 11; 11, identifier:UcsUtils; 12, dotted_name; 12, 13; 13, identifier:WriteUcsWarning; 14, dotted_name; 14, 15; 15, identifier:UcsValidationException; 16, if_statement; 16, 17; 16, 20; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:filePath; 19, None; 20, block; 20, 21; 21, raise_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:UcsValidationException; 24, argument_list; 24, 25; 25, string:"filePath parameter is not provided."; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:key; 29, None; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:UcsValidationException; 34, argument_list; 34, 35; 35, string:"key parameter is not provided."; 36, if_statement; 36, 37; 36, 56; 37, boolean_operator:or; 37, 38; 37, 47; 38, not_operator; 38, 39; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:os; 43, identifier:path; 44, identifier:isfile; 45, argument_list; 45, 46; 46, identifier:filePath; 47, not_operator; 47, 48; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:os; 52, identifier:path; 53, identifier:exists; 54, argument_list; 54, 55; 55, identifier:filePath; 56, block; 56, 57; 57, raise_statement; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:UcsValidationException; 60, argument_list; 60, 61; 61, binary_operator:%; 61, 62; 61, 63; 62, string:'[Error]: File <%s> does not exist '; 63, parenthesized_expression; 63, 64; 64, identifier:filePath; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:doc; 68, call; 68, 69; 68, 76; 69, attribute; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:xml; 73, identifier:dom; 74, identifier:minidom; 75, identifier:parse; 76, argument_list; 76, 77; 77, identifier:filePath; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:topNode; 81, attribute; 81, 82; 81, 83; 82, identifier:doc; 83, identifier:documentElement; 84, if_statement; 84, 85; 84, 96; 85, boolean_operator:or; 85, 86; 85, 89; 86, comparison_operator:is; 86, 87; 86, 88; 87, identifier:topNode; 88, None; 89, comparison_operator:!=; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:topNode; 92, identifier:localName; 93, attribute; 93, 94; 93, 95; 94, identifier:UcsLoginXml; 95, identifier:UCS_HANDLES; 96, block; 96, 97; 97, return_statement; 97, 98; 98, None; 99, if_statement; 99, 100; 99, 106; 100, parenthesized_expression; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:topNode; 104, identifier:hasChildNodes; 105, argument_list; 106, block; 106, 107; 106, 113; 106, 120; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:childList; 110, attribute; 110, 111; 110, 112; 111, identifier:topNode; 112, identifier:childNodes; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:childCount; 116, call; 116, 117; 116, 118; 117, identifier:len; 118, argument_list; 118, 119; 119, identifier:childList; 120, for_statement; 120, 121; 120, 122; 120, 126; 121, identifier:i; 122, call; 122, 123; 122, 124; 123, identifier:range; 124, argument_list; 124, 125; 125, identifier:childCount; 126, block; 126, 127; 126, 136; 126, 147; 126, 157; 126, 161; 126, 165; 126, 169; 126, 173; 126, 177; 126, 198; 126, 219; 126, 246; 126, 267; 126, 288; 126, 306; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:childNode; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:childList; 133, identifier:item; 134, argument_list; 134, 135; 135, identifier:i; 136, if_statement; 136, 137; 136, 145; 137, parenthesized_expression; 137, 138; 138, comparison_operator:!=; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:childNode; 141, identifier:nodeType; 142, attribute; 142, 143; 142, 144; 143, identifier:Node; 144, identifier:ELEMENT_NODE; 145, block; 145, 146; 146, continue_statement; 147, if_statement; 147, 148; 147, 155; 148, comparison_operator:!=; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:childNode; 151, identifier:localName; 152, attribute; 152, 153; 152, 154; 153, identifier:UcsLoginXml; 154, identifier:UCS; 155, block; 155, 156; 156, continue_statement; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:lName; 160, None; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:lUsername; 164, None; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:lPassword; 168, None; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:lNoSsl; 172, False; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:lPort; 176, None; 177, if_statement; 177, 178; 177, 186; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:childNode; 181, identifier:hasAttribute; 182, argument_list; 182, 183; 183, attribute; 183, 184; 183, 185; 184, identifier:UcsLoginXml; 185, identifier:NAME; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:lName; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:childNode; 193, identifier:getAttribute; 194, argument_list; 194, 195; 195, attribute; 195, 196; 195, 197; 196, identifier:UcsLoginXml; 197, identifier:NAME; 198, if_statement; 198, 199; 198, 207; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:childNode; 202, identifier:hasAttribute; 203, argument_list; 203, 204; 204, attribute; 204, 205; 204, 206; 205, identifier:UcsLoginXml; 206, identifier:USER_NAME; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:lUsername; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:childNode; 214, identifier:getAttribute; 215, argument_list; 215, 216; 216, attribute; 216, 217; 216, 218; 217, identifier:UcsLoginXml; 218, identifier:USER_NAME; 219, if_statement; 219, 220; 219, 228; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:childNode; 223, identifier:hasAttribute; 224, argument_list; 224, 225; 225, attribute; 225, 226; 225, 227; 226, identifier:UcsLoginXml; 227, identifier:PASSWORD; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:lPassword; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:UcsUtils; 235, identifier:DecryptPassword; 236, argument_list; 236, 237; 236, 245; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:childNode; 240, identifier:getAttribute; 241, argument_list; 241, 242; 242, attribute; 242, 243; 242, 244; 243, identifier:UcsLoginXml; 244, identifier:PASSWORD; 245, identifier:key; 246, if_statement; 246, 247; 246, 255; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:childNode; 250, identifier:hasAttribute; 251, argument_list; 251, 252; 252, attribute; 252, 253; 252, 254; 253, identifier:UcsLoginXml; 254, identifier:NO_SSL; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:lNoSsl; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:childNode; 262, identifier:getAttribute; 263, argument_list; 263, 264; 264, attribute; 264, 265; 264, 266; 265, identifier:UcsLoginXml; 266, identifier:NO_SSL; 267, if_statement; 267, 268; 267, 276; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:childNode; 271, identifier:hasAttribute; 272, argument_list; 272, 273; 273, attribute; 273, 274; 273, 275; 274, identifier:UcsLoginXml; 275, identifier:PORT; 276, block; 276, 277; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:lPort; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:childNode; 283, identifier:getAttribute; 284, argument_list; 284, 285; 285, attribute; 285, 286; 285, 287; 286, identifier:UcsLoginXml; 287, identifier:PORT; 288, if_statement; 288, 289; 288, 304; 289, parenthesized_expression; 289, 290; 290, boolean_operator:or; 290, 291; 290, 300; 291, boolean_operator:or; 291, 292; 291, 296; 292, parenthesized_expression; 292, 293; 293, comparison_operator:is; 293, 294; 293, 295; 294, identifier:lName; 295, None; 296, parenthesized_expression; 296, 297; 297, comparison_operator:==; 297, 298; 297, 299; 298, identifier:lUsername; 299, None; 300, parenthesized_expression; 300, 301; 301, comparison_operator:==; 301, 302; 301, 303; 302, identifier:lPassword; 303, None; 304, block; 304, 305; 305, continue_statement; 306, try_statement; 306, 307; 306, 335; 307, block; 307, 308; 307, 314; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:handle; 311, call; 311, 312; 311, 313; 312, identifier:UcsHandle; 313, argument_list; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:handle; 318, identifier:Login; 319, argument_list; 319, 320; 319, 323; 319, 326; 319, 329; 319, 332; 320, keyword_argument; 320, 321; 320, 322; 321, identifier:name; 322, identifier:lName; 323, keyword_argument; 323, 324; 323, 325; 324, identifier:username; 325, identifier:lUsername; 326, keyword_argument; 326, 327; 326, 328; 327, identifier:password; 328, identifier:lPassword; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:noSsl; 331, identifier:lNoSsl; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:port; 334, identifier:lPort; 335, except_clause; 335, 336; 335, 337; 335, 338; 336, identifier:Exception; 337, identifier:err; 338, block; 338, 339; 339, expression_statement; 339, 340; 340, call; 340, 341; 340, 342; 341, identifier:WriteUcsWarning; 342, argument_list; 342, 343; 343, binary_operator:%; 343, 344; 343, 345; 344, string:"[Connection Error<%s>] %s"; 345, tuple; 345, 346; 345, 347; 346, identifier:lName; 347, call; 347, 348; 347, 349; 348, identifier:str; 349, argument_list; 349, 350; 350, identifier:err | def ImportUcsSession(filePath, key):
from UcsBase import UcsUtils, WriteUcsWarning, UcsValidationException
if filePath is None:
raise UcsValidationException("filePath parameter is not provided.")
if key is None:
raise UcsValidationException("key parameter is not provided.")
if not os.path.isfile(filePath) or not os.path.exists(filePath):
raise UcsValidationException('[Error]: File <%s> does not exist ' % (filePath))
doc = xml.dom.minidom.parse(filePath)
topNode = doc.documentElement
if topNode is None or topNode.localName != UcsLoginXml.UCS_HANDLES:
return None
if (topNode.hasChildNodes()):
childList = topNode.childNodes
childCount = len(childList)
for i in range(childCount):
childNode = childList.item(i)
if (childNode.nodeType != Node.ELEMENT_NODE):
continue
if childNode.localName != UcsLoginXml.UCS:
continue
lName = None
lUsername = None
lPassword = None
lNoSsl = False
lPort = None
if childNode.hasAttribute(UcsLoginXml.NAME):
lName = childNode.getAttribute(UcsLoginXml.NAME)
if childNode.hasAttribute(UcsLoginXml.USER_NAME):
lUsername = childNode.getAttribute(UcsLoginXml.USER_NAME)
if childNode.hasAttribute(UcsLoginXml.PASSWORD):
lPassword = UcsUtils.DecryptPassword(childNode.getAttribute(UcsLoginXml.PASSWORD), key)
if childNode.hasAttribute(UcsLoginXml.NO_SSL):
lNoSsl = childNode.getAttribute(UcsLoginXml.NO_SSL)
if childNode.hasAttribute(UcsLoginXml.PORT):
lPort = childNode.getAttribute(UcsLoginXml.PORT)
if ((lName is None) or (lUsername == None) or (lPassword == None)):
continue
try:
handle = UcsHandle()
handle.Login(name=lName, username=lUsername, password=lPassword, noSsl=lNoSsl, port=lPort)
except Exception, err:
WriteUcsWarning("[Connection Error<%s>] %s" % (lName, str(err))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:ImportUcsBackup; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:path; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:merge; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:dumpXml; 13, False; 14, block; 14, 15; 14, 33; 14, 38; 14, 43; 14, 48; 14, 59; 14, 68; 14, 87; 14, 91; 14, 95; 14, 106; 14, 115; 14, 124; 14, 149; 14, 168; 14, 174; 14, 182; 14, 188; 14, 196; 14, 204; 14, 225; 14, 231; 14, 238; 14, 250; 14, 295; 14, 304; 14, 317; 14, 324; 14, 337; 14, 346; 14, 368; 14, 386; 15, import_from_statement; 15, 16; 15, 18; 15, 20; 15, 22; 15, 24; 15, 26; 15, 28; 15, 30; 15, 31; 16, dotted_name; 16, 17; 17, identifier:UcsBase; 18, dotted_name; 18, 19; 19, identifier:WriteUcsWarning; 20, dotted_name; 20, 21; 21, identifier:UcsUtils; 22, dotted_name; 22, 23; 23, identifier:ManagedObject; 24, dotted_name; 24, 25; 25, identifier:WriteObject; 26, dotted_name; 26, 27; 27, identifier:UcsUtils; 28, dotted_name; 28, 29; 29, identifier:UcsException; 30, line_continuation:\; 31, dotted_name; 31, 32; 32, identifier:UcsValidationException; 33, import_from_statement; 33, 34; 33, 36; 34, dotted_name; 34, 35; 35, identifier:Ucs; 36, dotted_name; 36, 37; 37, identifier:ConfigConfig; 38, import_from_statement; 38, 39; 38, 41; 39, dotted_name; 39, 40; 40, identifier:Mos; 41, dotted_name; 41, 42; 42, identifier:MgmtImporter; 43, import_from_statement; 43, 44; 43, 46; 44, dotted_name; 44, 45; 45, identifier:datetime; 46, dotted_name; 46, 47; 47, identifier:datetime; 48, if_statement; 48, 49; 48, 53; 49, parenthesized_expression; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_transactionInProgress; 53, block; 53, 54; 54, raise_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:UcsValidationException; 57, argument_list; 57, 58; 58, string:"UCS transaction in progress. Cannot execute ImportUcsBackup. Complete or Undo UCS transaction."; 59, if_statement; 59, 60; 59, 62; 60, not_operator; 60, 61; 61, identifier:path; 62, block; 62, 63; 63, raise_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:UcsValidationException; 66, argument_list; 66, 67; 67, string:"path parameter is not provided."; 68, if_statement; 68, 69; 68, 78; 69, not_operator; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:os; 74, identifier:path; 75, identifier:exists; 76, argument_list; 76, 77; 77, identifier:path; 78, block; 78, 79; 79, raise_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:UcsValidationException; 82, argument_list; 82, 83; 83, binary_operator:%; 83, 84; 83, 85; 84, string:"Backup File not found <%s>"; 85, parenthesized_expression; 85, 86; 86, identifier:path; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:dn; 90, None; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:filePath; 94, identifier:path; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:localFile; 98, call; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:os; 102, identifier:path; 103, identifier:basename; 104, argument_list; 104, 105; 105, identifier:filePath; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:topSystem; 109, call; 109, 110; 109, 111; 110, identifier:ManagedObject; 111, argument_list; 111, 112; 112, attribute; 112, 113; 112, 114; 113, identifier:NamingId; 114, identifier:TOP_SYSTEM; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:mgmtImporter; 118, call; 118, 119; 118, 120; 119, identifier:ManagedObject; 120, argument_list; 120, 121; 121, attribute; 121, 122; 121, 123; 122, identifier:NamingId; 123, identifier:MGMT_IMPORTER; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:mgmtImporter; 128, identifier:Hostname; 129, binary_operator:+; 129, 130; 129, 139; 130, call; 130, 131; 130, 138; 131, attribute; 131, 132; 131, 137; 132, subscript; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:os; 135, identifier:environ; 136, string:'COMPUTERNAME'; 137, identifier:lower; 138, argument_list; 139, call; 139, 140; 139, 147; 140, attribute; 140, 141; 140, 146; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:datetime; 144, identifier:now; 145, argument_list; 146, identifier:strftime; 147, argument_list; 147, 148; 148, string:'%Y%m%d%H%M'; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:dn; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:UcsUtils; 155, identifier:MakeDn; 156, argument_list; 156, 157; 157, list:[topSystem.MakeRn(), mgmtImporter.MakeRn()]; 157, 158; 157, 163; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:topSystem; 161, identifier:MakeRn; 162, argument_list; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:mgmtImporter; 166, identifier:MakeRn; 167, argument_list; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:mgmtImporter; 172, identifier:Dn; 173, identifier:dn; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:mgmtImporter; 178, identifier:Status; 179, attribute; 179, 180; 179, 181; 180, identifier:Status; 181, identifier:CREATED; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:mgmtImporter; 186, identifier:RemoteFile; 187, identifier:filePath; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:mgmtImporter; 192, identifier:Proto; 193, attribute; 193, 194; 193, 195; 194, identifier:MgmtImporter; 195, identifier:CONST_PROTO_HTTP; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:mgmtImporter; 200, identifier:AdminState; 201, attribute; 201, 202; 201, 203; 202, identifier:MgmtImporter; 203, identifier:CONST_ADMIN_STATE_ENABLED; 204, if_statement; 204, 205; 204, 206; 204, 215; 205, identifier:merge; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:mgmtImporter; 211, identifier:Action; 212, attribute; 212, 213; 212, 214; 213, identifier:MgmtImporter; 214, identifier:CONST_ACTION_MERGE; 215, else_clause; 215, 216; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:mgmtImporter; 221, identifier:Action; 222, attribute; 222, 223; 222, 224; 223, identifier:MgmtImporter; 224, identifier:CONST_ACTION_REPLACE; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:inConfig; 228, call; 228, 229; 228, 230; 229, identifier:ConfigConfig; 230, argument_list; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:inConfig; 235, identifier:AddChild; 236, argument_list; 236, 237; 237, identifier:mgmtImporter; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:uri; 241, binary_operator:%; 241, 242; 241, 243; 242, string:"%s/operations/file-%s/importconfig.txt"; 243, tuple; 243, 244; 243, 249; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:Uri; 248, argument_list; 249, identifier:localFile; 250, if_statement; 250, 251; 250, 258; 250, 275; 251, comparison_operator:<; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:sys; 254, identifier:version_info; 255, tuple; 255, 256; 255, 257; 256, integer:2; 257, integer:6; 258, block; 258, 259; 258, 267; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:uploadFileHandle; 262, call; 262, 263; 262, 264; 263, identifier:open; 264, argument_list; 264, 265; 264, 266; 265, identifier:filePath; 266, string:'rb'; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:stream; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:uploadFileHandle; 273, identifier:read; 274, argument_list; 275, else_clause; 275, 276; 276, block; 276, 277; 276, 283; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:progress; 280, call; 280, 281; 280, 282; 281, identifier:Progress; 282, argument_list; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:stream; 286, call; 286, 287; 286, 288; 287, identifier:file_with_callback; 288, argument_list; 288, 289; 288, 290; 288, 291; 288, 294; 289, identifier:filePath; 290, string:'rb'; 291, attribute; 291, 292; 291, 293; 292, identifier:progress; 293, identifier:update; 294, identifier:filePath; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 298; 297, identifier:request; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:urllib2; 301, identifier:Request; 302, argument_list; 302, 303; 303, identifier:uri; 304, expression_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:request; 308, identifier:add_header; 309, argument_list; 309, 310; 309, 311; 310, string:'Cookie'; 311, binary_operator:%; 311, 312; 311, 313; 312, string:'ucsm-cookie=%s'; 313, parenthesized_expression; 313, 314; 314, attribute; 314, 315; 314, 316; 315, identifier:self; 316, identifier:_cookie; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:request; 321, identifier:add_data; 322, argument_list; 322, 323; 323, identifier:stream; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:response; 327, call; 327, 328; 327, 336; 328, attribute; 328, 329; 328, 335; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:urllib2; 332, identifier:urlopen; 333, argument_list; 333, 334; 334, identifier:request; 335, identifier:read; 336, argument_list; 337, if_statement; 337, 338; 337, 340; 338, not_operator; 338, 339; 339, identifier:response; 340, block; 340, 341; 341, raise_statement; 341, 342; 342, call; 342, 343; 342, 344; 343, identifier:UcsValidationException; 344, argument_list; 344, 345; 345, string:"Unable to upload properly."; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 349; 348, identifier:ccm; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:self; 352, identifier:ConfigConfMo; 353, argument_list; 353, 354; 353, 357; 353, 360; 353, 365; 354, keyword_argument; 354, 355; 354, 356; 355, identifier:dn; 356, identifier:dn; 357, keyword_argument; 357, 358; 357, 359; 358, identifier:inConfig; 359, identifier:inConfig; 360, keyword_argument; 360, 361; 360, 362; 361, identifier:inHierarchical; 362, attribute; 362, 363; 362, 364; 363, identifier:YesOrNo; 364, identifier:FALSE; 365, keyword_argument; 365, 366; 365, 367; 366, identifier:dumpXml; 367, identifier:dumpXml; 368, if_statement; 368, 369; 368, 375; 369, parenthesized_expression; 369, 370; 370, comparison_operator:!=; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:ccm; 373, identifier:errorCode; 374, integer:0; 375, block; 375, 376; 376, raise_statement; 376, 377; 377, call; 377, 378; 377, 379; 378, identifier:UcsException; 379, argument_list; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:ccm; 382, identifier:errorCode; 383, attribute; 383, 384; 383, 385; 384, identifier:ccm; 385, identifier:errorDescr; 386, return_statement; 386, 387; 387, call; 387, 388; 387, 393; 388, attribute; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:ccm; 391, identifier:OutConfig; 392, identifier:GetChild; 393, argument_list | def ImportUcsBackup(self, path=None, merge=False, dumpXml=False):
from UcsBase import WriteUcsWarning, UcsUtils, ManagedObject, WriteObject, UcsUtils, UcsException, \
UcsValidationException
from Ucs import ConfigConfig
from Mos import MgmtImporter
from datetime import datetime
if (self._transactionInProgress):
raise UcsValidationException(
"UCS transaction in progress. Cannot execute ImportUcsBackup. Complete or Undo UCS transaction.")
if not path:
raise UcsValidationException("path parameter is not provided.")
if not os.path.exists(path):
raise UcsValidationException("Backup File not found <%s>" % (path))
dn = None
filePath = path
localFile = os.path.basename(filePath)
topSystem = ManagedObject(NamingId.TOP_SYSTEM)
mgmtImporter = ManagedObject(NamingId.MGMT_IMPORTER)
mgmtImporter.Hostname = os.environ['COMPUTERNAME'].lower() + datetime.now().strftime('%Y%m%d%H%M')
dn = UcsUtils.MakeDn([topSystem.MakeRn(), mgmtImporter.MakeRn()])
mgmtImporter.Dn = dn
mgmtImporter.Status = Status.CREATED
mgmtImporter.RemoteFile = filePath
mgmtImporter.Proto = MgmtImporter.CONST_PROTO_HTTP
mgmtImporter.AdminState = MgmtImporter.CONST_ADMIN_STATE_ENABLED
if merge:
mgmtImporter.Action = MgmtImporter.CONST_ACTION_MERGE
else:
mgmtImporter.Action = MgmtImporter.CONST_ACTION_REPLACE
inConfig = ConfigConfig()
inConfig.AddChild(mgmtImporter)
uri = "%s/operations/file-%s/importconfig.txt" % (self.Uri(), localFile)
if sys.version_info < (2, 6):
uploadFileHandle = open(filePath, 'rb')
stream = uploadFileHandle.read()
else:
progress = Progress()
stream = file_with_callback(filePath, 'rb', progress.update, filePath)
request = urllib2.Request(uri)
request.add_header('Cookie', 'ucsm-cookie=%s' % (self._cookie))
request.add_data(stream)
response = urllib2.urlopen(request).read()
if not response:
raise UcsValidationException("Unable to upload properly.")
ccm = self.ConfigConfMo(dn=dn, inConfig=inConfig, inHierarchical=YesOrNo.FALSE, dumpXml=dumpXml)
if (ccm.errorCode != 0):
raise UcsException(ccm.errorCode, ccm.errorDescr)
return ccm.OutConfig.GetChild() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_set_suffix_links; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 6, expression_statement; 6, 7; 7, string:'''
Sets all suffix links in all nodes in this trie.
'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_suffix_links_set; 13, True; 14, for_statement; 14, 15; 14, 18; 14, 23; 15, pattern_list; 15, 16; 15, 17; 16, identifier:current; 17, identifier:parent; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:bfs; 22, argument_list; 23, block; 23, 24; 23, 30; 23, 38; 23, 49; 23, 55; 23, 59; 23, 103; 23, 109; 23, 125; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:parent; 27, None; 28, block; 28, 29; 29, continue_statement; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:current; 34, identifier:longest_prefix; 35, attribute; 35, 36; 35, 37; 36, identifier:parent; 37, identifier:longest_prefix; 38, if_statement; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:parent; 41, identifier:has_value; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:current; 47, identifier:longest_prefix; 48, identifier:parent; 49, if_statement; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:current; 52, identifier:has_suffix; 53, block; 53, 54; 54, continue_statement; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:suffix; 58, identifier:parent; 59, while_statement; 59, 60; 59, 61; 60, True; 61, block; 61, 62; 61, 85; 62, if_statement; 62, 63; 62, 67; 62, 77; 63, not_operator; 63, 64; 64, attribute; 64, 65; 64, 66; 65, identifier:suffix; 66, identifier:has_suffix; 67, block; 67, 68; 67, 76; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:current; 72, identifier:suffix; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:root; 76, break_statement; 77, else_clause; 77, 78; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:suffix; 82, attribute; 82, 83; 82, 84; 83, identifier:suffix; 84, identifier:suffix; 85, if_statement; 85, 86; 85, 91; 86, comparison_operator:in; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:current; 89, identifier:uplink; 90, identifier:suffix; 91, block; 91, 92; 91, 102; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:current; 96, identifier:suffix; 97, subscript; 97, 98; 97, 99; 98, identifier:suffix; 99, attribute; 99, 100; 99, 101; 100, identifier:current; 101, identifier:uplink; 102, break_statement; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:suffix; 106, attribute; 106, 107; 106, 108; 107, identifier:current; 108, identifier:suffix; 109, while_statement; 109, 110; 109, 118; 110, boolean_operator:and; 110, 111; 110, 115; 111, not_operator; 111, 112; 112, attribute; 112, 113; 112, 114; 113, identifier:suffix; 114, identifier:has_value; 115, attribute; 115, 116; 115, 117; 116, identifier:suffix; 117, identifier:has_suffix; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:suffix; 122, attribute; 122, 123; 122, 124; 123, identifier:suffix; 124, identifier:suffix; 125, if_statement; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:suffix; 128, identifier:has_value; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:current; 134, identifier:dict_suffix; 135, identifier:suffix | def _set_suffix_links(self):
'''
Sets all suffix links in all nodes in this trie.
'''
self._suffix_links_set = True
for current, parent in self.bfs():
if parent is None:
continue
current.longest_prefix = parent.longest_prefix
if parent.has_value:
current.longest_prefix = parent
if current.has_suffix:
continue
suffix = parent
while True:
if not suffix.has_suffix:
current.suffix = self.root
break
else:
suffix = suffix.suffix
if current.uplink in suffix:
current.suffix = suffix[current.uplink]
break
suffix = current.suffix
while not suffix.has_value and suffix.has_suffix:
suffix = suffix.suffix
if suffix.has_value:
current.dict_suffix = suffix |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_write_mo; 3, parameters; 3, 4; 4, identifier:mo; 5, block; 5, 6; 5, 10; 5, 27; 5, 31; 5, 35; 5, 73; 5, 84; 5, 216; 5, 270; 5, 297; 5, 301; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:classNotFound; 9, False; 10, if_statement; 10, 11; 10, 22; 11, parenthesized_expression; 11, 12; 12, comparison_operator:==; 12, 13; 12, 21; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:UcsUtils; 16, identifier:FindClassIdInMoMetaIgnoreCase; 17, argument_list; 17, 18; 18, attribute; 18, 19; 18, 20; 19, identifier:mo; 20, identifier:classId; 21, None; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:classNotFound; 26, True; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:tabsize; 30, integer:8; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:outstr; 34, string:"\n"; 35, if_statement; 35, 36; 35, 37; 35, 56; 36, identifier:classNotFound; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, augmented_assignment:+=; 39, 40; 39, 41; 40, identifier:outstr; 41, binary_operator:+; 41, 42; 41, 55; 42, binary_operator:+; 42, 43; 42, 44; 43, string:"Managed Object\t\t\t:\t"; 44, call; 44, 45; 44, 46; 45, identifier:str; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:UcsUtils; 50, identifier:WordU; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:mo; 54, identifier:classId; 55, string:"\n"; 56, else_clause; 56, 57; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, augmented_assignment:+=; 59, 60; 59, 61; 60, identifier:outstr; 61, binary_operator:+; 61, 62; 61, 72; 62, binary_operator:+; 62, 63; 62, 64; 63, string:"Managed Object\t\t\t:\t"; 64, call; 64, 65; 64, 66; 65, identifier:str; 66, argument_list; 66, 67; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:mo; 70, identifier:propMoMeta; 71, identifier:name; 72, string:"\n"; 73, expression_statement; 73, 74; 74, augmented_assignment:+=; 74, 75; 74, 76; 75, identifier:outstr; 76, binary_operator:+; 76, 77; 76, 83; 77, binary_operator:*; 77, 78; 77, 79; 78, string:"-"; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, string:"Managed Object"; 83, string:"\n"; 84, if_statement; 84, 85; 84, 88; 84, 159; 85, parenthesized_expression; 85, 86; 86, not_operator; 86, 87; 87, identifier:classNotFound; 88, block; 88, 89; 89, for_statement; 89, 90; 89, 91; 89, 101; 90, identifier:prop; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:UcsUtils; 94, identifier:GetUcsPropertyMetaAttributeList; 95, argument_list; 95, 96; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:mo; 99, identifier:propMoMeta; 100, identifier:name; 101, block; 101, 102; 101, 116; 101, 127; 101, 136; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:propMeta; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:UcsUtils; 108, identifier:GetUcsPropertyMeta; 109, argument_list; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:mo; 113, identifier:propMoMeta; 114, identifier:name; 115, identifier:prop; 116, if_statement; 116, 117; 116, 125; 117, parenthesized_expression; 117, 118; 118, comparison_operator:==; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:propMeta; 121, identifier:access; 122, attribute; 122, 123; 122, 124; 123, identifier:UcsPropertyMeta; 124, identifier:Internal; 125, block; 125, 126; 126, continue_statement; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:val; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:mo; 133, identifier:getattr; 134, argument_list; 134, 135; 135, identifier:prop; 136, expression_statement; 136, 137; 137, augmented_assignment:+=; 137, 138; 137, 139; 138, identifier:outstr; 139, binary_operator:+; 139, 140; 139, 158; 140, binary_operator:+; 140, 141; 140, 154; 141, binary_operator:+; 141, 142; 141, 153; 142, call; 142, 143; 142, 149; 143, attribute; 143, 144; 143, 148; 144, call; 144, 145; 144, 146; 145, identifier:str; 146, argument_list; 146, 147; 147, identifier:prop; 148, identifier:ljust; 149, argument_list; 149, 150; 150, binary_operator:*; 150, 151; 150, 152; 151, identifier:tabsize; 152, integer:4; 153, string:':'; 154, call; 154, 155; 154, 156; 155, identifier:str; 156, argument_list; 156, 157; 157, identifier:val; 158, string:"\n"; 159, else_clause; 159, 160; 160, block; 160, 161; 161, for_statement; 161, 162; 161, 163; 161, 166; 162, identifier:prop; 163, attribute; 163, 164; 163, 165; 164, identifier:mo; 165, identifier:__dict__; 166, block; 166, 167; 166, 180; 166, 188; 167, if_statement; 167, 168; 167, 178; 168, parenthesized_expression; 168, 169; 169, comparison_operator:in; 169, 170; 169, 171; 170, identifier:prop; 171, list:['classId', 'XtraProperty', 'handle', 'propMoMeta', 'dirtyMask', 'child']; 171, 172; 171, 173; 171, 174; 171, 175; 171, 176; 171, 177; 172, string:'classId'; 173, string:'XtraProperty'; 174, string:'handle'; 175, string:'propMoMeta'; 176, string:'dirtyMask'; 177, string:'child'; 178, block; 178, 179; 179, continue_statement; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:val; 183, subscript; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:mo; 186, identifier:__dict__; 187, identifier:prop; 188, expression_statement; 188, 189; 189, augmented_assignment:+=; 189, 190; 189, 191; 190, identifier:outstr; 191, binary_operator:+; 191, 192; 191, 215; 192, binary_operator:+; 192, 193; 192, 211; 193, binary_operator:+; 193, 194; 193, 210; 194, call; 194, 195; 194, 206; 195, attribute; 195, 196; 195, 205; 196, call; 196, 197; 196, 198; 197, identifier:str; 198, argument_list; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:UcsUtils; 202, identifier:WordU; 203, argument_list; 203, 204; 204, identifier:prop; 205, identifier:ljust; 206, argument_list; 206, 207; 207, binary_operator:*; 207, 208; 207, 209; 208, identifier:tabsize; 209, integer:4; 210, string:':'; 211, call; 211, 212; 211, 213; 212, identifier:str; 213, argument_list; 213, 214; 214, identifier:val; 215, string:"\n"; 216, if_statement; 216, 217; 216, 225; 217, call; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:mo; 221, identifier:__dict__; 222, identifier:has_key; 223, argument_list; 223, 224; 224, string:'XtraProperty'; 225, block; 225, 226; 226, for_statement; 226, 227; 226, 228; 226, 233; 227, identifier:xtraProp; 228, subscript; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:mo; 231, identifier:__dict__; 232, string:'XtraProperty'; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, augmented_assignment:+=; 235, 236; 235, 237; 236, identifier:outstr; 237, binary_operator:+; 237, 238; 237, 269; 238, binary_operator:+; 238, 239; 238, 259; 239, binary_operator:+; 239, 240; 239, 258; 240, binary_operator:+; 240, 241; 240, 242; 241, string:'[X]'; 242, call; 242, 243; 242, 254; 243, attribute; 243, 244; 243, 253; 244, call; 244, 245; 244, 246; 245, identifier:str; 246, argument_list; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:UcsUtils; 250, identifier:WordU; 251, argument_list; 251, 252; 252, identifier:xtraProp; 253, identifier:ljust; 254, argument_list; 254, 255; 255, binary_operator:*; 255, 256; 255, 257; 256, identifier:tabsize; 257, integer:4; 258, string:':'; 259, call; 259, 260; 259, 261; 260, identifier:str; 261, argument_list; 261, 262; 262, subscript; 262, 263; 262, 268; 263, subscript; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:mo; 266, identifier:__dict__; 267, string:'XtraProperty'; 268, identifier:xtraProp; 269, string:"\n"; 270, expression_statement; 270, 271; 271, augmented_assignment:+=; 271, 272; 271, 273; 272, identifier:outstr; 273, binary_operator:+; 273, 274; 273, 296; 274, binary_operator:+; 274, 275; 274, 288; 275, binary_operator:+; 275, 276; 275, 287; 276, call; 276, 277; 276, 283; 277, attribute; 277, 278; 277, 282; 278, call; 278, 279; 278, 280; 279, identifier:str; 280, argument_list; 280, 281; 281, string:"Ucs"; 282, identifier:ljust; 283, argument_list; 283, 284; 284, binary_operator:*; 284, 285; 284, 286; 285, identifier:tabsize; 286, integer:4; 287, string:':'; 288, call; 288, 289; 288, 290; 289, identifier:str; 290, argument_list; 290, 291; 291, attribute; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:mo; 294, identifier:handle; 295, identifier:_ucs; 296, string:"\n"; 297, expression_statement; 297, 298; 298, augmented_assignment:+=; 298, 299; 298, 300; 299, identifier:outstr; 300, string:"\n"; 301, return_statement; 301, 302; 302, identifier:outstr | def _write_mo(mo):
classNotFound = False
if (UcsUtils.FindClassIdInMoMetaIgnoreCase(mo.classId) == None):
classNotFound = True
tabsize = 8
outstr = "\n"
if classNotFound:
outstr += "Managed Object\t\t\t:\t" + str(UcsUtils.WordU(mo.classId)) + "\n"
else:
outstr += "Managed Object\t\t\t:\t" + str(mo.propMoMeta.name) + "\n"
outstr += "-" * len("Managed Object") + "\n"
if (not classNotFound):
for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo.propMoMeta.name):
propMeta = UcsUtils.GetUcsPropertyMeta(mo.propMoMeta.name, prop)
if (propMeta.access == UcsPropertyMeta.Internal):
continue
val = mo.getattr(prop)
outstr += str(prop).ljust(tabsize * 4) + ':' + str(val) + "\n"
else:
for prop in mo.__dict__:
if (prop in ['classId', 'XtraProperty', 'handle', 'propMoMeta', 'dirtyMask', 'child']):
continue
val = mo.__dict__[prop]
outstr += str(UcsUtils.WordU(prop)).ljust(tabsize * 4) + ':' + str(val) + "\n"
if mo.__dict__.has_key('XtraProperty'):
for xtraProp in mo.__dict__['XtraProperty']:
outstr += '[X]' + str(UcsUtils.WordU(xtraProp)).ljust(tabsize * 4) + ':' + str(
mo.__dict__['XtraProperty'][xtraProp]) + "\n"
outstr += str("Ucs").ljust(tabsize * 4) + ':' + str(mo.handle._ucs) + "\n"
outstr += "\n"
return outstr |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:LoadFromXml; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:node; 6, identifier:handle; 7, block; 7, 8; 7, 15; 7, 183; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:SetHandle; 13, argument_list; 13, 14; 14, identifier:handle; 15, if_statement; 15, 16; 15, 21; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:node; 19, identifier:hasAttributes; 20, argument_list; 21, block; 21, 22; 21, 28; 21, 35; 21, 141; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:attributes; 25, attribute; 25, 26; 25, 27; 26, identifier:node; 27, identifier:attributes; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:attCount; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, identifier:attributes; 35, for_statement; 35, 36; 35, 37; 35, 41; 36, identifier:i; 37, call; 37, 38; 37, 39; 38, identifier:range; 39, argument_list; 39, 40; 40, identifier:attCount; 41, block; 41, 42; 41, 51; 41, 62; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:attNode; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:attributes; 48, identifier:item; 49, argument_list; 49, 50; 50, identifier:i; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:attr; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:UcsUtils; 57, identifier:WordU; 58, argument_list; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:attNode; 61, identifier:localName; 62, if_statement; 62, 63; 62, 74; 62, 121; 63, parenthesized_expression; 63, 64; 64, comparison_operator:!=; 64, 65; 64, 73; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:UcsUtils; 68, identifier:FindClassIdInMoMetaIgnoreCase; 69, argument_list; 69, 70; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:classId; 73, None; 74, block; 74, 75; 75, if_statement; 75, 76; 75, 87; 75, 101; 76, parenthesized_expression; 76, 77; 77, comparison_operator:in; 77, 78; 77, 79; 78, identifier:attr; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:UcsUtils; 82, identifier:GetUcsPropertyMetaAttributeList; 83, argument_list; 83, 84; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:classId; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:setattr; 93, argument_list; 93, 94; 93, 95; 94, identifier:attr; 95, call; 95, 96; 95, 97; 96, identifier:str; 97, argument_list; 97, 98; 98, attribute; 98, 99; 98, 100; 99, identifier:attNode; 100, identifier:value; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:setattr; 108, argument_list; 108, 109; 108, 115; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:UcsUtils; 112, identifier:WordU; 113, argument_list; 113, 114; 114, identifier:attr; 115, call; 115, 116; 115, 117; 116, identifier:str; 117, argument_list; 117, 118; 118, attribute; 118, 119; 118, 120; 119, identifier:attNode; 120, identifier:value; 121, else_clause; 121, 122; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:setattr; 128, argument_list; 128, 129; 128, 135; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:UcsUtils; 132, identifier:WordU; 133, argument_list; 133, 134; 134, identifier:attr; 135, call; 135, 136; 135, 137; 136, identifier:str; 137, argument_list; 137, 138; 138, attribute; 138, 139; 138, 140; 139, identifier:attNode; 140, identifier:value; 141, if_statement; 141, 142; 141, 159; 142, boolean_operator:and; 142, 143; 142, 151; 143, comparison_operator:==; 143, 144; 143, 150; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:getattr; 148, argument_list; 148, 149; 149, string:"Rn"; 150, None; 151, comparison_operator:!=; 151, 152; 151, 158; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:getattr; 156, argument_list; 156, 157; 157, string:"Dn"; 158, None; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:setattr; 165, argument_list; 165, 166; 165, 167; 166, string:"Rn"; 167, call; 167, 168; 167, 169; 168, identifier:str; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:re; 173, identifier:sub; 174, argument_list; 174, 175; 174, 176; 174, 177; 175, string:r'^.*/'; 176, string:''; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:getattr; 181, argument_list; 181, 182; 182, string:"Dn"; 183, if_statement; 183, 184; 183, 190; 184, parenthesized_expression; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:node; 188, identifier:hasChildNodes; 189, argument_list; 190, block; 190, 191; 190, 197; 190, 204; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:childList; 194, attribute; 194, 195; 194, 196; 195, identifier:node; 196, identifier:childNodes; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:childCount; 200, call; 200, 201; 200, 202; 201, identifier:len; 202, argument_list; 202, 203; 203, identifier:childList; 204, for_statement; 204, 205; 204, 206; 204, 210; 205, identifier:i; 206, call; 206, 207; 206, 208; 207, identifier:range; 208, argument_list; 208, 209; 209, identifier:childCount; 210, block; 210, 211; 210, 220; 210, 231; 210, 243; 210, 257; 210, 266; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:childNode; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:childList; 217, identifier:item; 218, argument_list; 218, 219; 219, identifier:i; 220, if_statement; 220, 221; 220, 229; 221, parenthesized_expression; 221, 222; 222, comparison_operator:!=; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:childNode; 225, identifier:nodeType; 226, attribute; 226, 227; 226, 228; 227, identifier:Node; 228, identifier:ELEMENT_NODE; 229, block; 229, 230; 230, continue_statement; 231, if_statement; 231, 232; 231, 241; 232, comparison_operator:in; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:childNode; 235, identifier:localName; 236, attribute; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:propMoMeta; 240, identifier:fieldNames; 241, block; 241, 242; 242, pass_statement; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:c; 246, call; 246, 247; 246, 248; 247, identifier:ManagedObject; 248, argument_list; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:UcsUtils; 252, identifier:WordU; 253, argument_list; 253, 254; 254, attribute; 254, 255; 254, 256; 255, identifier:childNode; 256, identifier:localName; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 264; 259, attribute; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:child; 263, identifier:append; 264, argument_list; 264, 265; 265, identifier:c; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:c; 270, identifier:LoadFromXml; 271, argument_list; 271, 272; 271, 273; 272, identifier:childNode; 273, identifier:handle | def LoadFromXml(self, node, handle):
self.SetHandle(handle)
if node.hasAttributes():
attributes = node.attributes
attCount = len(attributes)
for i in range(attCount):
attNode = attributes.item(i)
attr = UcsUtils.WordU(attNode.localName)
if (UcsUtils.FindClassIdInMoMetaIgnoreCase(self.classId) != None):
if (attr in UcsUtils.GetUcsPropertyMetaAttributeList(self.classId)):
self.setattr(attr, str(attNode.value))
else:
self.setattr(UcsUtils.WordU(attr), str(attNode.value))
else:
self.setattr(UcsUtils.WordU(attr), str(attNode.value))
if self.getattr("Rn") == None and self.getattr("Dn") != None:
self.setattr("Rn", str(re.sub(r'^.*/', '', self.getattr("Dn"))))
if (node.hasChildNodes()):
childList = node.childNodes
childCount = len(childList)
for i in range(childCount):
childNode = childList.item(i)
if (childNode.nodeType != Node.ELEMENT_NODE):
continue
if childNode.localName in self.propMoMeta.fieldNames:
pass
c = ManagedObject(UcsUtils.WordU(childNode.localName))
self.child.append(c)
c.LoadFromXml(childNode, handle) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:GetJavaInstallationPath; 3, parameters; 4, block; 4, 5; 4, 10; 5, import_statement; 5, 6; 5, 8; 6, dotted_name; 6, 7; 7, identifier:os; 8, dotted_name; 8, 9; 9, identifier:platform; 10, if_statement; 10, 11; 10, 18; 10, 85; 11, comparison_operator:==; 11, 12; 11, 17; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:platform; 15, identifier:system; 16, argument_list; 17, string:"Linux"; 18, block; 18, 19; 18, 30; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:path; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:os; 26, identifier:environ; 27, identifier:get; 28, argument_list; 28, 29; 29, string:'JAVA_HOME'; 30, if_statement; 30, 31; 30, 33; 30, 39; 31, not_operator; 31, 32; 32, identifier:path; 33, block; 33, 34; 34, raise_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:UcsValidationException; 37, argument_list; 37, 38; 38, string:"Please make sure JAVA is installed and variable JAVA_HOME is set properly."; 39, else_clause; 39, 40; 40, block; 40, 41; 40, 53; 40, 65; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:path; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:os; 48, identifier:path; 49, identifier:join; 50, argument_list; 50, 51; 50, 52; 51, identifier:path; 52, string:'bin'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:path; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:os; 60, identifier:path; 61, identifier:join; 62, argument_list; 62, 63; 62, 64; 63, identifier:path; 64, string:'javaws'; 65, if_statement; 65, 66; 65, 75; 65, 81; 66, not_operator; 66, 67; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:os; 71, identifier:path; 72, identifier:exists; 73, argument_list; 73, 74; 74, identifier:path; 75, block; 75, 76; 76, raise_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:UcsValidationException; 79, argument_list; 79, 80; 80, string:"javaws is not installed on System."; 81, else_clause; 81, 82; 82, block; 82, 83; 83, return_statement; 83, 84; 84, identifier:path; 85, elif_clause; 85, 86; 85, 101; 86, boolean_operator:or; 86, 87; 86, 94; 87, comparison_operator:==; 87, 88; 87, 93; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:platform; 91, identifier:system; 92, argument_list; 93, string:"Windows"; 94, comparison_operator:==; 94, 95; 94, 100; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:platform; 98, identifier:system; 99, argument_list; 100, string:"Microsoft"; 101, block; 101, 102; 101, 113; 101, 127; 101, 141; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:path; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:os; 109, identifier:environ; 110, identifier:get; 111, argument_list; 111, 112; 112, string:'JAVA_HOME'; 113, if_statement; 113, 114; 113, 117; 114, comparison_operator:==; 114, 115; 114, 116; 115, identifier:path; 116, None; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:path; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:UcsUtils; 124, identifier:CheckRegistryKey; 125, argument_list; 125, 126; 126, string:r"SOFTWARE\\JavaSoft\\Java Runtime Environment\\"; 127, if_statement; 127, 128; 127, 131; 128, comparison_operator:==; 128, 129; 128, 130; 129, identifier:path; 130, None; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:path; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:UcsUtils; 138, identifier:CheckRegistryKey; 139, argument_list; 139, 140; 140, string:r"SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment"; 141, if_statement; 141, 142; 141, 144; 141, 150; 142, not_operator; 142, 143; 143, identifier:path; 144, block; 144, 145; 145, raise_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:UcsValidationException; 148, argument_list; 148, 149; 149, string:"Please make sure JAVA is installed."; 150, else_clause; 150, 151; 151, block; 151, 152; 151, 164; 151, 176; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:path; 155, call; 155, 156; 155, 161; 156, attribute; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:os; 159, identifier:path; 160, identifier:join; 161, argument_list; 161, 162; 161, 163; 162, identifier:path; 163, string:'bin'; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:path; 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:join; 173, argument_list; 173, 174; 173, 175; 174, identifier:path; 175, string:'javaws.exe'; 176, if_statement; 176, 177; 176, 186; 176, 192; 177, not_operator; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:os; 182, identifier:path; 183, identifier:exists; 184, argument_list; 184, 185; 185, identifier:path; 186, block; 186, 187; 187, raise_statement; 187, 188; 188, call; 188, 189; 188, 190; 189, identifier:UcsValidationException; 190, argument_list; 190, 191; 191, string:"javaws.exe is not installed on System."; 192, else_clause; 192, 193; 193, block; 193, 194; 194, return_statement; 194, 195; 195, identifier:path | def GetJavaInstallationPath():
import os, platform
if platform.system() == "Linux":
path = os.environ.get('JAVA_HOME')
if not path:
raise UcsValidationException(
"Please make sure JAVA is installed and variable JAVA_HOME is set properly.")
else:
path = os.path.join(path, 'bin')
path = os.path.join(path, 'javaws')
if not os.path.exists(path):
raise UcsValidationException("javaws is not installed on System.")
else:
return path
elif platform.system() == "Windows" or platform.system() == "Microsoft":
path = os.environ.get('JAVA_HOME')
if path == None:
path = UcsUtils.CheckRegistryKey(r"SOFTWARE\\JavaSoft\\Java Runtime Environment\\")
if path == None:
path = UcsUtils.CheckRegistryKey(r"SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment")
if not path:
raise UcsValidationException("Please make sure JAVA is installed.")
else:
path = os.path.join(path, 'bin')
path = os.path.join(path, 'javaws.exe')
if not os.path.exists(path):
raise UcsValidationException("javaws.exe is not installed on System.")
else:
return path |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:GetSyncMoConfig; 3, parameters; 3, 4; 4, identifier:ConfigDoc; 5, block; 5, 6; 5, 10; 5, 19; 5, 245; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:moConfigMap; 9, dictionary; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:configList; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:ConfigDoc; 16, identifier:getElementsByTagName; 17, argument_list; 17, 18; 18, string:"mo"; 19, for_statement; 19, 20; 19, 21; 19, 22; 20, identifier:moConfigNode; 21, identifier:configList; 22, block; 22, 23; 22, 27; 22, 31; 22, 35; 22, 39; 22, 43; 22, 47; 22, 51; 22, 55; 22, 72; 22, 89; 22, 106; 22, 123; 22, 140; 22, 157; 22, 174; 22, 191; 22, 195; 22, 212; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:classId; 26, None; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:noun; 30, None; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:version; 34, None; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:actionVersion; 38, None; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:action; 42, None; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:ignoreReason; 46, None; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:status; 50, None; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:excludeList; 54, None; 55, if_statement; 55, 56; 55, 62; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:moConfigNode; 59, identifier:hasAttribute; 60, argument_list; 60, 61; 61, string:"classid"; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:classId; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:moConfigNode; 69, identifier:getAttribute; 70, argument_list; 70, 71; 71, string:"classid"; 72, if_statement; 72, 73; 72, 79; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:moConfigNode; 76, identifier:hasAttribute; 77, argument_list; 77, 78; 78, string:"noun"; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:noun; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:moConfigNode; 86, identifier:getAttribute; 87, argument_list; 87, 88; 88, string:"noun"; 89, if_statement; 89, 90; 89, 96; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:moConfigNode; 93, identifier:hasAttribute; 94, argument_list; 94, 95; 95, string:"version"; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:version; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:moConfigNode; 103, identifier:getAttribute; 104, argument_list; 104, 105; 105, string:"version"; 106, if_statement; 106, 107; 106, 113; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:moConfigNode; 110, identifier:hasAttribute; 111, argument_list; 111, 112; 112, string:"actionVersion"; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:actionVersion; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:moConfigNode; 120, identifier:getAttribute; 121, argument_list; 121, 122; 122, string:"actionVersion"; 123, if_statement; 123, 124; 123, 130; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:moConfigNode; 127, identifier:hasAttribute; 128, argument_list; 128, 129; 129, string:"action"; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:action; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:moConfigNode; 137, identifier:getAttribute; 138, argument_list; 138, 139; 139, string:"action"; 140, if_statement; 140, 141; 140, 147; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:moConfigNode; 144, identifier:hasAttribute; 145, argument_list; 145, 146; 146, string:"ignoreReason"; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:ignoreReason; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:moConfigNode; 154, identifier:getAttribute; 155, argument_list; 155, 156; 156, string:"ignoreReason"; 157, if_statement; 157, 158; 157, 164; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:moConfigNode; 161, identifier:hasAttribute; 162, argument_list; 162, 163; 163, string:"status"; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:status; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:moConfigNode; 171, identifier:getAttribute; 172, argument_list; 172, 173; 173, string:"status"; 174, if_statement; 174, 175; 174, 181; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:moConfigNode; 178, identifier:hasAttribute; 179, argument_list; 179, 180; 180, string:"excludeList"; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:excludeList; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:moConfigNode; 188, identifier:getAttribute; 189, argument_list; 189, 190; 190, string:"excludeList"; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:moConfig; 194, None; 195, if_statement; 195, 196; 195, 197; 196, identifier:classId; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:moConfig; 201, call; 201, 202; 201, 203; 202, identifier:SyncMoConfig; 203, argument_list; 203, 204; 203, 205; 203, 206; 203, 207; 203, 208; 203, 209; 203, 210; 203, 211; 204, identifier:classId; 205, identifier:noun; 206, identifier:version; 207, identifier:actionVersion; 208, identifier:action; 209, identifier:ignoreReason; 210, identifier:status; 211, identifier:excludeList; 212, if_statement; 212, 213; 212, 214; 213, identifier:moConfig; 214, block; 214, 215; 215, if_statement; 215, 216; 215, 219; 215, 226; 216, comparison_operator:in; 216, 217; 216, 218; 217, identifier:classId; 218, identifier:moConfigMap; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:moConfigMap; 224, identifier:classId; 225, identifier:moConfig; 226, else_clause; 226, 227; 227, block; 227, 228; 227, 232; 227, 239; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:moConfigList; 231, list:[]; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:moConfigList; 236, identifier:append; 237, argument_list; 237, 238; 238, identifier:moConfig; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 244; 241, subscript; 241, 242; 241, 243; 242, identifier:moConfigMap; 243, identifier:classId; 244, identifier:moConfigList; 245, return_statement; 245, 246; 246, identifier:moConfigMap | def GetSyncMoConfig(ConfigDoc):
moConfigMap = {}
configList = ConfigDoc.getElementsByTagName("mo")
for moConfigNode in configList:
classId = None
noun = None
version = None
actionVersion = None
action = None
ignoreReason = None
status = None
excludeList = None
if moConfigNode.hasAttribute("classid"):
classId = moConfigNode.getAttribute("classid")
if moConfigNode.hasAttribute("noun"):
noun = moConfigNode.getAttribute("noun")
if moConfigNode.hasAttribute("version"):
version = moConfigNode.getAttribute("version")
if moConfigNode.hasAttribute("actionVersion"):
actionVersion = moConfigNode.getAttribute("actionVersion")
if moConfigNode.hasAttribute("action"):
action = moConfigNode.getAttribute("action")
if moConfigNode.hasAttribute("ignoreReason"):
ignoreReason = moConfigNode.getAttribute("ignoreReason")
if moConfigNode.hasAttribute("status"):
status = moConfigNode.getAttribute("status")
if moConfigNode.hasAttribute("excludeList"):
excludeList = moConfigNode.getAttribute("excludeList")
moConfig = None
if classId:
moConfig = SyncMoConfig(classId, noun, version, actionVersion, action, ignoreReason, status,
excludeList)
if moConfig:
if classId in moConfigMap:
moConfigMap[classId] = moConfig
else:
moConfigList = []
moConfigList.append(moConfig)
moConfigMap[classId] = moConfigList
return moConfigMap |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:duration; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:t; 5, default_parameter; 5, 6; 5, 7; 6, identifier:now; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:precision; 10, integer:1; 11, default_parameter; 11, 12; 11, 13; 12, identifier:pad; 13, string:', '; 14, default_parameter; 14, 15; 14, 16; 15, identifier:words; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:justnow; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:datetime; 22, identifier:timedelta; 23, argument_list; 23, 24; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:seconds; 26, integer:10; 27, block; 27, 28; 27, 30; 27, 41; 27, 48; 27, 63; 27, 84; 27, 100; 28, expression_statement; 28, 29; 29, string:'''
Time delta compared to ``t``. You can override ``now`` to specify what time
to compare to.
:param t: timestamp, :class:`datetime.date` or :class:`datetime.datetime`
object
:param now: default ``None``, optionally a :class:`datetime.datetime`
object
:param precision: default ``1``, number of fragments to return
:param words: default ``None``, allow words like "yesterday", if set to
``None`` this will be enabled if ``precision`` is set to
``1``
:param justnow: default ``datetime.timedelta(seconds=10)``,
:class:`datetime.timedelta` object passed to :func:`delta`
representing tolerance for considering argument ``t`` as
meaning 'just now'
>>> import time
>>> from datetime import datetime
>>> print(duration(time.time() + 1))
just now
>>> print(duration(time.time() + 11))
11 seconds from now
>>> print(duration(time.time() - 1))
just now
>>> print(duration(time.time() - 11))
11 seconds ago
>>> print(duration(time.time() - 3601))
an hour ago
>>> print(duration(time.time() - 7201))
2 hours ago
>>> print(duration(time.time() - 1234567))
2 weeks ago
>>> print(duration(time.time() + 7200, precision=1))
2 hours from now
>>> print(duration(time.time() - 1234567, precision=3))
2 weeks, 6 hours, 56 minutes ago
>>> print(duration(datetime(2014, 9, 8), now=datetime(2014, 9, 9)))
yesterday
>>> print(duration(datetime(2014, 9, 7, 23), now=datetime(2014, 9, 9)))
1 day ago
>>> print(duration(datetime(2014, 9, 10), now=datetime(2014, 9, 9)))
tomorrow
>>> print(duration(datetime(2014, 9, 11, 1), now=datetime(2014, 9, 9, 23)))
1 day from now
'''; 30, if_statement; 30, 31; 30, 34; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:words; 33, None; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:words; 38, comparison_operator:==; 38, 39; 38, 40; 39, identifier:precision; 40, integer:1; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:t1; 44, call; 44, 45; 44, 46; 45, identifier:_to_datetime; 46, argument_list; 46, 47; 47, identifier:t; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:t2; 51, call; 51, 52; 51, 53; 52, identifier:_to_datetime; 53, argument_list; 53, 54; 54, boolean_operator:or; 54, 55; 54, 56; 55, identifier:now; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:datetime; 60, identifier:datetime; 61, identifier:now; 62, argument_list; 63, if_statement; 63, 64; 63, 67; 63, 75; 64, comparison_operator:<; 64, 65; 64, 66; 65, identifier:t1; 66, identifier:t2; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:format; 71, call; 71, 72; 71, 73; 72, identifier:_; 73, argument_list; 73, 74; 74, string:'%s ago'; 75, else_clause; 75, 76; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:format; 80, call; 80, 81; 80, 82; 81, identifier:_; 82, argument_list; 82, 83; 83, string:'%s from now'; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, pattern_list; 86, 87; 86, 88; 87, identifier:result; 88, identifier:remains; 89, call; 89, 90; 89, 91; 90, identifier:delta; 91, argument_list; 91, 92; 91, 93; 91, 94; 91, 97; 92, identifier:t1; 93, identifier:t2; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:words; 96, identifier:words; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:justnow; 99, identifier:justnow; 100, if_statement; 100, 101; 100, 124; 100, 127; 100, 167; 101, comparison_operator:in; 101, 102; 101, 103; 102, identifier:result; 103, tuple; 103, 104; 103, 108; 103, 112; 103, 116; 103, 120; 104, call; 104, 105; 104, 106; 105, identifier:_; 106, argument_list; 106, 107; 107, string:'just now'; 108, call; 108, 109; 108, 110; 109, identifier:_; 110, argument_list; 110, 111; 111, string:'yesterday'; 112, call; 112, 113; 112, 114; 113, identifier:_; 114, argument_list; 114, 115; 115, string:'tomorrow'; 116, call; 116, 117; 116, 118; 117, identifier:_; 118, argument_list; 118, 119; 119, string:'last week'; 120, call; 120, 121; 120, 122; 121, identifier:_; 122, argument_list; 122, 123; 123, string:'next week'; 124, block; 124, 125; 125, return_statement; 125, 126; 126, identifier:result; 127, elif_clause; 127, 128; 127, 133; 128, boolean_operator:and; 128, 129; 128, 132; 129, comparison_operator:>; 129, 130; 129, 131; 130, identifier:precision; 131, integer:1; 132, identifier:remains; 133, block; 133, 134; 133, 147; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:t3; 137, binary_operator:-; 137, 138; 137, 139; 138, identifier:t2; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:datetime; 142, identifier:timedelta; 143, argument_list; 143, 144; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:seconds; 146, identifier:remains; 147, return_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:pad; 151, identifier:join; 152, argument_list; 152, 153; 153, list:[
result,
duration(t2, t3, precision - 1, pad, words=False),
]; 153, 154; 153, 155; 154, identifier:result; 155, call; 155, 156; 155, 157; 156, identifier:duration; 157, argument_list; 157, 158; 157, 159; 157, 160; 157, 163; 157, 164; 158, identifier:t2; 159, identifier:t3; 160, binary_operator:-; 160, 161; 160, 162; 161, identifier:precision; 162, integer:1; 163, identifier:pad; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:words; 166, False; 167, else_clause; 167, 168; 168, block; 168, 169; 169, return_statement; 169, 170; 170, binary_operator:%; 170, 171; 170, 172; 171, identifier:format; 172, tuple; 172, 173; 173, identifier:result | def duration(t, now=None, precision=1, pad=', ', words=None,
justnow=datetime.timedelta(seconds=10)):
'''
Time delta compared to ``t``. You can override ``now`` to specify what time
to compare to.
:param t: timestamp, :class:`datetime.date` or :class:`datetime.datetime`
object
:param now: default ``None``, optionally a :class:`datetime.datetime`
object
:param precision: default ``1``, number of fragments to return
:param words: default ``None``, allow words like "yesterday", if set to
``None`` this will be enabled if ``precision`` is set to
``1``
:param justnow: default ``datetime.timedelta(seconds=10)``,
:class:`datetime.timedelta` object passed to :func:`delta`
representing tolerance for considering argument ``t`` as
meaning 'just now'
>>> import time
>>> from datetime import datetime
>>> print(duration(time.time() + 1))
just now
>>> print(duration(time.time() + 11))
11 seconds from now
>>> print(duration(time.time() - 1))
just now
>>> print(duration(time.time() - 11))
11 seconds ago
>>> print(duration(time.time() - 3601))
an hour ago
>>> print(duration(time.time() - 7201))
2 hours ago
>>> print(duration(time.time() - 1234567))
2 weeks ago
>>> print(duration(time.time() + 7200, precision=1))
2 hours from now
>>> print(duration(time.time() - 1234567, precision=3))
2 weeks, 6 hours, 56 minutes ago
>>> print(duration(datetime(2014, 9, 8), now=datetime(2014, 9, 9)))
yesterday
>>> print(duration(datetime(2014, 9, 7, 23), now=datetime(2014, 9, 9)))
1 day ago
>>> print(duration(datetime(2014, 9, 10), now=datetime(2014, 9, 9)))
tomorrow
>>> print(duration(datetime(2014, 9, 11, 1), now=datetime(2014, 9, 9, 23)))
1 day from now
'''
if words is None:
words = precision == 1
t1 = _to_datetime(t)
t2 = _to_datetime(now or datetime.datetime.now())
if t1 < t2:
format = _('%s ago')
else:
format = _('%s from now')
result, remains = delta(t1, t2, words=words, justnow=justnow)
if result in (
_('just now'),
_('yesterday'),
_('tomorrow'),
_('last week'),
_('next week'),
):
return result
elif precision > 1 and remains:
t3 = t2 - datetime.timedelta(seconds=remains)
return pad.join([
result,
duration(t2, t3, precision - 1, pad, words=False),
])
else:
return format % (result,) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:query_string; 6, block; 6, 7; 6, 15; 6, 23; 6, 29; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:query; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:create_query; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:parser; 18, call; 18, 19; 18, 20; 19, identifier:QueryParser; 20, argument_list; 20, 21; 20, 22; 21, identifier:query_string; 22, identifier:query; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:parser; 27, identifier:parse; 28, argument_list; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:query; 34, argument_list; 34, 35; 35, identifier:query | def search(self, query_string):
query = self.create_query()
parser = QueryParser(query_string, query)
parser.parse()
return self.query(query) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:wrap_error; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:data; 6, identifier:renderer_context; 7, identifier:keys_are_fields; 8, identifier:issue_is_title; 9, block; 9, 10; 9, 20; 9, 31; 9, 35; 9, 127; 9, 135; 9, 141; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:response; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:renderer_context; 16, identifier:get; 17, argument_list; 17, 18; 17, 19; 18, string:"response"; 19, None; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:status_code; 23, call; 23, 24; 23, 25; 24, identifier:str; 25, argument_list; 25, 26; 26, boolean_operator:and; 26, 27; 26, 28; 27, identifier:response; 28, attribute; 28, 29; 28, 30; 29, identifier:response; 30, identifier:status_code; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:errors; 34, list:[]; 35, for_statement; 35, 36; 35, 39; 35, 44; 36, pattern_list; 36, 37; 36, 38; 37, identifier:field; 38, identifier:issues; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:data; 42, identifier:items; 43, argument_list; 44, block; 44, 45; 44, 59; 45, if_statement; 45, 46; 45, 53; 46, call; 46, 47; 46, 48; 47, identifier:isinstance; 48, argument_list; 48, 49; 48, 50; 49, identifier:issues; 50, attribute; 50, 51; 50, 52; 51, identifier:six; 52, identifier:string_types; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:issues; 57, list:[issues]; 57, 58; 58, identifier:issues; 59, for_statement; 59, 60; 59, 61; 59, 62; 60, identifier:issue; 61, identifier:issues; 62, block; 62, 63; 62, 71; 62, 77; 62, 94; 62, 120; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:error; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:dict_class; 70, argument_list; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:error; 75, string:"status"; 76, identifier:status_code; 77, if_statement; 77, 78; 77, 79; 77, 86; 78, identifier:issue_is_title; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:error; 84, string:"title"; 85, identifier:issue; 86, else_clause; 86, 87; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:error; 92, string:"detail"; 93, identifier:issue; 94, if_statement; 94, 95; 94, 96; 95, identifier:keys_are_fields; 96, block; 96, 97; 97, if_statement; 97, 98; 97, 103; 97, 110; 98, comparison_operator:in; 98, 99; 98, 100; 99, identifier:field; 100, tuple; 100, 101; 100, 102; 101, string:'non_field_errors'; 102, identifier:NON_FIELD_ERRORS; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:error; 108, string:"path"; 109, string:'/-'; 110, else_clause; 110, 111; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:error; 116, string:"path"; 117, binary_operator:+; 117, 118; 117, 119; 118, string:'/'; 119, identifier:field; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:errors; 124, identifier:append; 125, argument_list; 125, 126; 126, identifier:error; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:wrapper; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:dict_class; 134, argument_list; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:wrapper; 139, string:"errors"; 140, identifier:errors; 141, return_statement; 141, 142; 142, identifier:wrapper | def wrap_error(
self, data, renderer_context, keys_are_fields, issue_is_title):
response = renderer_context.get("response", None)
status_code = str(response and response.status_code)
errors = []
for field, issues in data.items():
if isinstance(issues, six.string_types):
issues = [issues]
for issue in issues:
error = self.dict_class()
error["status"] = status_code
if issue_is_title:
error["title"] = issue
else:
error["detail"] = issue
if keys_are_fields:
if field in ('non_field_errors', NON_FIELD_ERRORS):
error["path"] = '/-'
else:
error["path"] = '/' + field
errors.append(error)
wrapper = self.dict_class()
wrapper["errors"] = errors
return wrapper |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:lunr; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:ref; 5, identifier:fields; 6, identifier:documents; 7, default_parameter; 7, 8; 7, 9; 8, identifier:languages; 9, None; 10, block; 10, 11; 10, 115; 10, 122; 10, 150; 10, 186; 11, if_statement; 11, 12; 11, 19; 11, 87; 12, boolean_operator:and; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:languages; 15, None; 16, attribute; 16, 17; 16, 18; 17, identifier:lang; 18, identifier:LANGUAGE_SUPPORT; 19, block; 19, 20; 19, 32; 19, 46; 19, 78; 20, if_statement; 20, 21; 20, 26; 21, call; 21, 22; 21, 23; 22, identifier:isinstance; 23, argument_list; 23, 24; 23, 25; 24, identifier:languages; 25, identifier:basestring; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:languages; 30, list:[languages]; 30, 31; 31, identifier:languages; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:unsupported_languages; 35, binary_operator:-; 35, 36; 35, 40; 36, call; 36, 37; 36, 38; 37, identifier:set; 38, argument_list; 38, 39; 39, identifier:languages; 40, call; 40, 41; 40, 42; 41, identifier:set; 42, argument_list; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:lang; 45, identifier:SUPPORTED_LANGUAGES; 46, if_statement; 46, 47; 46, 48; 47, identifier:unsupported_languages; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:RuntimeError; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, concatenated_string; 55, 56; 55, 57; 56, string:"The specified languages {} are not supported, "; 57, string:"please choose one of {}"; 58, identifier:format; 59, argument_list; 59, 60; 59, 66; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, string:", "; 63, identifier:join; 64, argument_list; 64, 65; 65, identifier:unsupported_languages; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, string:", "; 69, identifier:join; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:lang; 75, identifier:SUPPORTED_LANGUAGES; 76, identifier:keys; 77, argument_list; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:builder; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:lang; 84, identifier:get_nltk_builder; 85, argument_list; 85, 86; 86, identifier:languages; 87, else_clause; 87, 88; 88, block; 88, 89; 88, 95; 88, 106; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:builder; 92, call; 92, 93; 92, 94; 93, identifier:Builder; 94, argument_list; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:builder; 100, identifier:pipeline; 101, identifier:add; 102, argument_list; 102, 103; 102, 104; 102, 105; 103, identifier:trimmer; 104, identifier:stop_word_filter; 105, identifier:stemmer; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:builder; 111, identifier:search_pipeline; 112, identifier:add; 113, argument_list; 113, 114; 114, identifier:stemmer; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:builder; 119, identifier:ref; 120, argument_list; 120, 121; 121, identifier:ref; 122, for_statement; 122, 123; 122, 124; 122, 125; 123, identifier:field; 124, identifier:fields; 125, block; 125, 126; 126, if_statement; 126, 127; 126, 132; 126, 141; 127, call; 127, 128; 127, 129; 128, identifier:isinstance; 129, argument_list; 129, 130; 129, 131; 130, identifier:field; 131, identifier:dict; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:builder; 137, identifier:field; 138, argument_list; 138, 139; 139, dictionary_splat; 139, 140; 140, identifier:field; 141, else_clause; 141, 142; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:builder; 147, identifier:field; 148, argument_list; 148, 149; 149, identifier:field; 150, for_statement; 150, 151; 150, 152; 150, 153; 151, identifier:document; 152, identifier:documents; 153, block; 153, 154; 154, if_statement; 154, 155; 154, 162; 154, 177; 155, call; 155, 156; 155, 157; 156, identifier:isinstance; 157, argument_list; 157, 158; 157, 159; 158, identifier:document; 159, tuple; 159, 160; 159, 161; 160, identifier:tuple; 161, identifier:list; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:builder; 167, identifier:add; 168, argument_list; 168, 169; 168, 172; 169, subscript; 169, 170; 169, 171; 170, identifier:document; 171, integer:0; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:attributes; 174, subscript; 174, 175; 174, 176; 175, identifier:document; 176, integer:1; 177, else_clause; 177, 178; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:builder; 183, identifier:add; 184, argument_list; 184, 185; 185, identifier:document; 186, return_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:builder; 190, identifier:build; 191, argument_list | def lunr(ref, fields, documents, languages=None):
if languages is not None and lang.LANGUAGE_SUPPORT:
if isinstance(languages, basestring):
languages = [languages]
unsupported_languages = set(languages) - set(lang.SUPPORTED_LANGUAGES)
if unsupported_languages:
raise RuntimeError(
"The specified languages {} are not supported, "
"please choose one of {}".format(
", ".join(unsupported_languages),
", ".join(lang.SUPPORTED_LANGUAGES.keys()),
)
)
builder = lang.get_nltk_builder(languages)
else:
builder = Builder()
builder.pipeline.add(trimmer, stop_word_filter, stemmer)
builder.search_pipeline.add(stemmer)
builder.ref(ref)
for field in fields:
if isinstance(field, dict):
builder.field(**field)
else:
builder.field(field)
for document in documents:
if isinstance(document, (tuple, list)):
builder.add(document[0], attributes=document[1])
else:
builder.add(document)
return builder.build() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:build_trie; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:pattern_filename; 5, identifier:pattern_format; 6, identifier:encoding; 7, identifier:on_word_boundaries; 8, block; 8, 9; 8, 11; 8, 15; 8, 34; 8, 52; 8, 62; 8, 66; 8, 357; 8, 370; 9, expression_statement; 9, 10; 10, string:'''
Constructs a finite state machine for performing string rewriting.
Arguments:
- `pattern_filename`:
- `pattern_format`:
- `encoding`:
- `on_word_boundaries`:
'''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:boundaries; 14, identifier:on_word_boundaries; 15, if_statement; 15, 16; 15, 22; 16, boolean_operator:or; 16, 17; 16, 20; 17, comparison_operator:==; 17, 18; 17, 19; 18, identifier:pattern_format; 19, string:'auto'; 20, not_operator; 20, 21; 21, identifier:on_word_boundaries; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, pattern_list; 25, 26; 25, 27; 26, identifier:tsv; 27, identifier:boundaries; 28, call; 28, 29; 28, 30; 29, identifier:detect_pattern_format; 30, argument_list; 30, 31; 30, 32; 30, 33; 31, identifier:pattern_filename; 32, identifier:encoding; 33, identifier:on_word_boundaries; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:==; 35, 36; 35, 37; 36, identifier:pattern_format; 37, string:'auto'; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 41; 39, 46; 40, identifier:tsv; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:pattern_format; 45, string:'tsv'; 46, else_clause; 46, 47; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:pattern_format; 51, string:'sed'; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:trie; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:fsed; 59, identifier:ahocorasick; 60, identifier:AhoCorasickTrie; 61, argument_list; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:num_candidates; 65, integer:0; 66, with_statement; 66, 67; 66, 76; 67, with_clause; 67, 68; 68, with_item; 68, 69; 69, as_pattern; 69, 70; 69, 74; 70, call; 70, 71; 70, 72; 71, identifier:open_file; 72, argument_list; 72, 73; 73, identifier:pattern_filename; 74, as_pattern_target; 74, 75; 75, identifier:pattern_file; 76, block; 76, 77; 77, for_statement; 77, 78; 77, 81; 77, 85; 78, pattern_list; 78, 79; 78, 80; 79, identifier:lineno; 80, identifier:line; 81, call; 81, 82; 81, 83; 82, identifier:enumerate; 83, argument_list; 83, 84; 84, identifier:pattern_file; 85, block; 85, 86; 85, 100; 85, 109; 85, 290; 85, 294; 85, 322; 85, 329; 85, 336; 85, 351; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:line; 89, call; 89, 90; 89, 98; 90, attribute; 90, 91; 90, 97; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:line; 94, identifier:decode; 95, argument_list; 95, 96; 96, identifier:encoding; 97, identifier:rstrip; 98, argument_list; 98, 99; 99, string:'\n'; 100, if_statement; 100, 101; 100, 107; 101, not_operator; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:line; 105, identifier:strip; 106, argument_list; 107, block; 107, 108; 108, continue_statement; 109, if_statement; 109, 110; 109, 113; 109, 154; 110, comparison_operator:==; 110, 111; 110, 112; 111, identifier:pattern_format; 112, string:'tsv'; 113, block; 113, 114; 113, 123; 113, 148; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:fields; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:line; 120, identifier:split; 121, argument_list; 121, 122; 122, string:'\t'; 123, if_statement; 123, 124; 123, 130; 124, comparison_operator:!=; 124, 125; 124, 129; 125, call; 125, 126; 125, 127; 126, identifier:len; 127, argument_list; 127, 128; 128, identifier:fields; 129, integer:2; 130, block; 130, 131; 130, 147; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:LOGGER; 135, identifier:warning; 136, argument_list; 136, 137; 137, call; 137, 138; 137, 144; 138, attribute; 138, 139; 138, 143; 139, parenthesized_expression; 139, 140; 140, concatenated_string; 140, 141; 140, 142; 141, string:'skipping line {} of pattern file (not '; 142, string:'in tab-separated format): {}'; 143, identifier:format; 144, argument_list; 144, 145; 144, 146; 145, identifier:lineno; 146, identifier:line; 147, continue_statement; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, pattern_list; 150, 151; 150, 152; 151, identifier:before; 152, identifier:after; 153, identifier:fields; 154, elif_clause; 154, 155; 154, 158; 155, comparison_operator:==; 155, 156; 155, 157; 156, identifier:pattern_format; 157, string:'sed'; 158, block; 158, 159; 158, 165; 158, 173; 158, 264; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:before; 162, assignment; 162, 163; 162, 164; 163, identifier:after; 164, None; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:line; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:line; 171, identifier:lstrip; 172, argument_list; 173, if_statement; 173, 174; 173, 179; 174, comparison_operator:==; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:line; 177, integer:0; 178, string:'s'; 179, block; 179, 180; 179, 186; 179, 197; 179, 212; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:delim; 183, subscript; 183, 184; 183, 185; 184, identifier:line; 185, integer:1; 186, if_statement; 186, 187; 186, 190; 187, comparison_operator:in; 187, 188; 187, 189; 188, identifier:delim; 189, string:'.^$*+?[](){}|\\'; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:delim; 194, binary_operator:+; 194, 195; 194, 196; 195, string:'\\'; 196, identifier:delim; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:fields; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:re; 203, identifier:split; 204, argument_list; 204, 205; 204, 211; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, string:r'(?<!\\){}'; 208, identifier:format; 209, argument_list; 209, 210; 210, identifier:delim; 211, identifier:line; 212, if_statement; 212, 213; 212, 219; 213, comparison_operator:==; 213, 214; 213, 218; 214, call; 214, 215; 214, 216; 215, identifier:len; 216, argument_list; 216, 217; 217, identifier:fields; 218, integer:4; 219, block; 219, 220; 219, 232; 219, 248; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, pattern_list; 222, 223; 222, 224; 223, identifier:before; 224, identifier:after; 225, expression_list; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:fields; 228, integer:1; 229, subscript; 229, 230; 229, 231; 230, identifier:fields; 231, integer:2; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:before; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:re; 238, identifier:sub; 239, argument_list; 239, 240; 239, 246; 239, 247; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, string:r'(?<!\\)\\{}'; 243, identifier:format; 244, argument_list; 244, 245; 245, identifier:delim; 246, identifier:delim; 247, identifier:before; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:after; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:re; 254, identifier:sub; 255, argument_list; 255, 256; 255, 262; 255, 263; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, string:r'(?<!\\)\\{}'; 259, identifier:format; 260, argument_list; 260, 261; 261, identifier:delim; 262, identifier:delim; 263, identifier:after; 264, if_statement; 264, 265; 264, 272; 265, boolean_operator:or; 265, 266; 265, 269; 266, comparison_operator:is; 266, 267; 266, 268; 267, identifier:before; 268, None; 269, comparison_operator:is; 269, 270; 269, 271; 270, identifier:after; 271, None; 272, block; 272, 273; 272, 289; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:LOGGER; 277, identifier:warning; 278, argument_list; 278, 279; 279, call; 279, 280; 279, 286; 280, attribute; 280, 281; 280, 285; 281, parenthesized_expression; 281, 282; 282, concatenated_string; 282, 283; 282, 284; 283, string:'skipping line {} of pattern file (not '; 284, string:'in sed format): {}'; 285, identifier:format; 286, argument_list; 286, 287; 286, 288; 287, identifier:lineno; 288, identifier:line; 289, continue_statement; 290, expression_statement; 290, 291; 291, augmented_assignment:+=; 291, 292; 291, 293; 292, identifier:num_candidates; 293, integer:1; 294, if_statement; 294, 295; 294, 304; 295, boolean_operator:and; 295, 296; 295, 297; 296, identifier:on_word_boundaries; 297, comparison_operator:!=; 297, 298; 297, 299; 298, identifier:before; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:before; 302, identifier:strip; 303, argument_list; 304, block; 304, 305; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:LOGGER; 309, identifier:warning; 310, argument_list; 310, 311; 311, call; 311, 312; 311, 319; 312, attribute; 312, 313; 312, 318; 313, parenthesized_expression; 313, 314; 314, concatenated_string; 314, 315; 314, 316; 314, 317; 315, string:'before pattern on line {} padded whitespace; '; 316, string:'this may interact strangely with the --words '; 317, string:'option: {}'; 318, identifier:format; 319, argument_list; 319, 320; 319, 321; 320, identifier:lineno; 321, identifier:line; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:before; 325, call; 325, 326; 325, 327; 326, identifier:sub_escapes; 327, argument_list; 327, 328; 328, identifier:before; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 332; 331, identifier:after; 332, call; 332, 333; 332, 334; 333, identifier:sub_escapes; 334, argument_list; 334, 335; 335, identifier:after; 336, if_statement; 336, 337; 336, 338; 337, identifier:boundaries; 338, block; 338, 339; 339, expression_statement; 339, 340; 340, assignment; 340, 341; 340, 342; 341, identifier:before; 342, call; 342, 343; 342, 348; 343, attribute; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:fsed; 346, identifier:ahocorasick; 347, identifier:boundary_transform; 348, argument_list; 348, 349; 348, 350; 349, identifier:before; 350, identifier:on_word_boundaries; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 356; 353, subscript; 353, 354; 353, 355; 354, identifier:trie; 355, identifier:before; 356, identifier:after; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:LOGGER; 361, identifier:info; 362, argument_list; 362, 363; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, string:'{} patterns loaded from {}'; 366, identifier:format; 367, argument_list; 367, 368; 367, 369; 368, identifier:num_candidates; 369, identifier:pattern_filename; 370, return_statement; 370, 371; 371, expression_list; 371, 372; 371, 373; 372, identifier:trie; 373, identifier:boundaries | def build_trie(pattern_filename, pattern_format, encoding, on_word_boundaries):
'''
Constructs a finite state machine for performing string rewriting.
Arguments:
- `pattern_filename`:
- `pattern_format`:
- `encoding`:
- `on_word_boundaries`:
'''
boundaries = on_word_boundaries
if pattern_format == 'auto' or not on_word_boundaries:
tsv, boundaries = detect_pattern_format(pattern_filename, encoding,
on_word_boundaries)
if pattern_format == 'auto':
if tsv:
pattern_format = 'tsv'
else:
pattern_format = 'sed'
trie = fsed.ahocorasick.AhoCorasickTrie()
num_candidates = 0
with open_file(pattern_filename) as pattern_file:
for lineno, line in enumerate(pattern_file):
line = line.decode(encoding).rstrip('\n')
if not line.strip():
continue
if pattern_format == 'tsv':
fields = line.split('\t')
if len(fields) != 2:
LOGGER.warning(('skipping line {} of pattern file (not '
'in tab-separated format): {}').format(lineno, line))
continue
before, after = fields
elif pattern_format == 'sed':
before = after = None
line = line.lstrip()
if line[0] == 's':
delim = line[1]
if delim in '.^$*+?[](){}|\\':
delim = '\\' + delim
fields = re.split(r'(?<!\\){}'.format(delim), line)
if len(fields) == 4:
before, after = fields[1], fields[2]
before = re.sub(r'(?<!\\)\\{}'.format(delim), delim, before)
after = re.sub(r'(?<!\\)\\{}'.format(delim), delim, after)
if before is None or after is None:
LOGGER.warning(('skipping line {} of pattern file (not '
'in sed format): {}').format(lineno, line))
continue
num_candidates += 1
if on_word_boundaries and before != before.strip():
LOGGER.warning(('before pattern on line {} padded whitespace; '
'this may interact strangely with the --words '
'option: {}').format(lineno, line))
before = sub_escapes(before)
after = sub_escapes(after)
if boundaries:
before = fsed.ahocorasick.boundary_transform(before, on_word_boundaries)
trie[before] = after
LOGGER.info('{} patterns loaded from {}'.format(num_candidates,
pattern_filename))
return trie, boundaries |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:make_parser; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:add_help; 6, True; 7, default_parameter; 7, 8; 7, 9; 8, identifier:exclude_args; 9, None; 10, block; 10, 11; 10, 20; 10, 31; 10, 40; 10, 58; 10, 83; 10, 105; 10, 123; 10, 138; 10, 156; 10, 174; 10, 192; 10, 210; 10, 232; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:exclude_args; 14, None; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:exclude_args; 19, list:[]; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:parser; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:argparse; 26, identifier:ArgumentParser; 27, argument_list; 27, 28; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:add_help; 30, identifier:add_help; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:parser; 35, identifier:description; 36, parenthesized_expression; 36, 37; 37, concatenated_string; 37, 38; 37, 39; 38, string:"Filter, transform and export a list of JSON "; 39, string:"objects on stdin to JSON or CSV on stdout"; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:not; 41, 42; 41, 43; 42, string:"--columns"; 43, identifier:exclude_args; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:parser; 49, identifier:add_argument; 50, argument_list; 50, 51; 50, 52; 50, 55; 51, string:"--columns"; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:dest; 54, string:"columns_file"; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:help; 57, string:"the JSON file specifying the columns to be output"; 58, if_statement; 58, 59; 58, 68; 59, boolean_operator:and; 59, 60; 59, 64; 60, parenthesized_expression; 60, 61; 61, comparison_operator:not; 61, 62; 61, 63; 62, string:"-i"; 63, identifier:exclude_args; 64, parenthesized_expression; 64, 65; 65, comparison_operator:not; 65, 66; 65, 67; 66, string:"--input"; 67, identifier:exclude_args; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:parser; 73, identifier:add_argument; 74, argument_list; 74, 75; 74, 76; 74, 77; 74, 80; 75, string:"-i"; 76, string:"--input"; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:help; 79, string:"read input from the given file instead of from stdin"; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:dest; 82, string:'input_data'; 83, if_statement; 83, 84; 83, 93; 84, boolean_operator:and; 84, 85; 84, 89; 85, parenthesized_expression; 85, 86; 86, comparison_operator:not; 86, 87; 86, 88; 87, string:"-c"; 88, identifier:exclude_args; 89, parenthesized_expression; 89, 90; 90, comparison_operator:not; 90, 91; 90, 92; 91, string:"--column"; 92, identifier:exclude_args; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:parser; 98, identifier:add_argument; 99, argument_list; 99, 100; 99, 101; 99, 102; 100, string:"-c"; 101, string:"--column"; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:action; 104, identifier:ColumnsAction; 105, if_statement; 105, 106; 105, 109; 106, comparison_operator:not; 106, 107; 106, 108; 107, string:"--pattern"; 108, identifier:exclude_args; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:parser; 114, identifier:add_argument; 115, argument_list; 115, 116; 115, 117; 115, 120; 116, string:"--pattern"; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:action; 119, identifier:ColumnsAction; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:nargs; 122, string:'+'; 123, if_statement; 123, 124; 123, 127; 124, comparison_operator:not; 124, 125; 124, 126; 125, string:"--max-length"; 126, identifier:exclude_args; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:parser; 132, identifier:add_argument; 133, argument_list; 133, 134; 133, 135; 134, string:"--max-length"; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:action; 137, identifier:ColumnsAction; 138, if_statement; 138, 139; 138, 142; 139, comparison_operator:not; 139, 140; 139, 141; 140, string:"--strip"; 141, identifier:exclude_args; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:parser; 147, identifier:add_argument; 148, argument_list; 148, 149; 148, 150; 148, 153; 149, string:"--strip"; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:nargs; 152, string:"?"; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:action; 155, identifier:ColumnsAction; 156, if_statement; 156, 157; 156, 160; 157, comparison_operator:not; 157, 158; 157, 159; 158, string:"--deduplicate"; 159, identifier:exclude_args; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:parser; 165, identifier:add_argument; 166, argument_list; 166, 167; 166, 168; 166, 171; 167, string:"--deduplicate"; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:nargs; 170, string:'?'; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:action; 173, identifier:ColumnsAction; 174, if_statement; 174, 175; 174, 178; 175, comparison_operator:not; 175, 176; 175, 177; 176, string:"--case-sensitive"; 177, identifier:exclude_args; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:parser; 183, identifier:add_argument; 184, argument_list; 184, 185; 184, 186; 184, 189; 185, string:"--case-sensitive"; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:nargs; 188, string:'?'; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:action; 191, identifier:ColumnsAction; 192, if_statement; 192, 193; 192, 196; 193, comparison_operator:not; 193, 194; 193, 195; 194, string:"--unique"; 195, identifier:exclude_args; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:parser; 201, identifier:add_argument; 202, argument_list; 202, 203; 202, 204; 202, 207; 203, string:"--unique"; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:nargs; 206, string:"?"; 207, keyword_argument; 207, 208; 207, 209; 208, identifier:action; 209, identifier:ColumnsAction; 210, if_statement; 210, 211; 210, 220; 211, boolean_operator:and; 211, 212; 211, 216; 212, parenthesized_expression; 212, 213; 213, comparison_operator:not; 213, 214; 213, 215; 214, string:"-p"; 215, identifier:exclude_args; 216, parenthesized_expression; 216, 217; 217, comparison_operator:not; 217, 218; 217, 219; 218, string:"--pretty"; 219, identifier:exclude_args; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:parser; 225, identifier:add_argument; 226, argument_list; 226, 227; 226, 228; 226, 229; 227, string:"-p"; 228, string:"--pretty"; 229, keyword_argument; 229, 230; 229, 231; 230, identifier:action; 231, string:"store_true"; 232, return_statement; 232, 233; 233, identifier:parser | def make_parser(add_help=True, exclude_args=None):
if exclude_args is None:
exclude_args = []
parser = argparse.ArgumentParser(add_help=add_help)
parser.description = ("Filter, transform and export a list of JSON "
"objects on stdin to JSON or CSV on stdout")
if "--columns" not in exclude_args:
parser.add_argument(
"--columns", dest="columns_file",
help="the JSON file specifying the columns to be output",
)
if ("-i" not in exclude_args) and ("--input" not in exclude_args):
parser.add_argument(
"-i", "--input",
help="read input from the given file instead of from stdin",
dest='input_data',
)
if ("-c" not in exclude_args) and ("--column" not in exclude_args):
parser.add_argument("-c", "--column", action=ColumnsAction)
if "--pattern" not in exclude_args:
parser.add_argument("--pattern", action=ColumnsAction, nargs='+')
if "--max-length" not in exclude_args:
parser.add_argument("--max-length", action=ColumnsAction)
if "--strip" not in exclude_args:
parser.add_argument("--strip", nargs="?", action=ColumnsAction)
if "--deduplicate" not in exclude_args:
parser.add_argument("--deduplicate", nargs='?', action=ColumnsAction)
if "--case-sensitive" not in exclude_args:
parser.add_argument(
"--case-sensitive", nargs='?', action=ColumnsAction)
if "--unique" not in exclude_args:
parser.add_argument("--unique", nargs="?", action=ColumnsAction)
if ("-p" not in exclude_args) and ("--pretty" not in exclude_args):
parser.add_argument("-p", "--pretty", action="store_true")
return parser |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:parse; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:parser; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:args; 9, None; 10, block; 10, 11; 10, 21; 10, 45; 10, 70; 10, 115; 10, 165; 11, if_statement; 11, 12; 11, 14; 12, not_operator; 12, 13; 13, identifier:parser; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:parser; 18, call; 18, 19; 18, 20; 19, identifier:make_parser; 20, argument_list; 21, try_statement; 21, 22; 21, 32; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:parsed_args; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:parser; 29, identifier:parse_args; 30, argument_list; 30, 31; 31, identifier:args; 32, except_clause; 32, 33; 32, 37; 33, as_pattern; 33, 34; 33, 35; 34, identifier:SystemExit; 35, as_pattern_target; 35, 36; 36, identifier:err; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:CommandLineExit; 41, argument_list; 41, 42; 42, attribute; 42, 43; 42, 44; 43, identifier:err; 44, identifier:code; 45, try_statement; 45, 46; 45, 53; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:columns; 50, attribute; 50, 51; 50, 52; 51, identifier:parsed_args; 52, identifier:columns; 53, except_clause; 53, 54; 53, 55; 54, identifier:AttributeError; 55, block; 55, 56; 55, 64; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:columns; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:collections; 62, identifier:OrderedDict; 63, argument_list; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:parsed_args; 68, identifier:columns; 69, identifier:columns; 70, for_statement; 70, 71; 70, 74; 70, 79; 71, pattern_list; 71, 72; 71, 73; 72, identifier:title; 73, identifier:spec; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:columns; 77, identifier:items; 78, argument_list; 79, block; 79, 80; 79, 95; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:not; 81, 82; 81, 83; 82, string:"pattern"; 83, identifier:spec; 84, block; 84, 85; 85, raise_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:ColumnWithoutPatternError; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, string:'Column "{0}" needs a pattern'; 92, identifier:format; 93, argument_list; 93, 94; 94, identifier:title; 95, if_statement; 95, 96; 95, 104; 96, comparison_operator:==; 96, 97; 96, 103; 97, call; 97, 98; 97, 99; 98, identifier:len; 99, argument_list; 99, 100; 100, subscript; 100, 101; 100, 102; 101, identifier:spec; 102, string:"pattern"; 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:spec; 109, string:"pattern"; 110, subscript; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:spec; 113, string:"pattern"; 114, integer:0; 115, if_statement; 115, 116; 115, 121; 115, 127; 115, 143; 115, 161; 116, boolean_operator:and; 116, 117; 116, 118; 117, identifier:columns; 118, attribute; 118, 119; 118, 120; 119, identifier:parsed_args; 120, identifier:columns_file; 121, block; 121, 122; 122, raise_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:ColumnsAndColumnsFileError; 125, argument_list; 125, 126; 126, string:"You can't use the --column and --columns options together (yet)"; 127, elif_clause; 127, 128; 127, 134; 128, boolean_operator:and; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:parsed_args; 131, identifier:columns_file; 132, not_operator; 132, 133; 133, identifier:columns; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:parsed_args; 139, identifier:columns; 140, attribute; 140, 141; 140, 142; 141, identifier:parsed_args; 142, identifier:columns_file; 143, elif_clause; 143, 144; 143, 153; 144, boolean_operator:and; 144, 145; 144, 148; 145, parenthesized_expression; 145, 146; 146, not_operator; 146, 147; 147, identifier:columns; 148, parenthesized_expression; 148, 149; 149, not_operator; 149, 150; 150, attribute; 150, 151; 150, 152; 151, identifier:parsed_args; 152, identifier:columns_file; 153, block; 153, 154; 154, raise_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:NoColumnsError; 157, argument_list; 157, 158; 158, concatenated_string; 158, 159; 158, 160; 159, string:"You must give either a --columns or at least one -c/--column "; 160, string:"argument"; 161, else_clause; 161, 162; 162, block; 162, 163; 163, assert_statement; 163, 164; 164, identifier:columns; 165, return_statement; 165, 166; 166, identifier:parsed_args | def parse(parser=None, args=None):
if not parser:
parser = make_parser()
try:
parsed_args = parser.parse_args(args)
except SystemExit as err:
raise CommandLineExit(err.code)
try:
columns = parsed_args.columns
except AttributeError:
columns = collections.OrderedDict()
parsed_args.columns = columns
for title, spec in columns.items():
if "pattern" not in spec:
raise ColumnWithoutPatternError(
'Column "{0}" needs a pattern'.format(title))
if len(spec["pattern"]) == 1:
spec["pattern"] = spec["pattern"][0]
if columns and parsed_args.columns_file:
raise ColumnsAndColumnsFileError(
"You can't use the --column and --columns options together (yet)")
elif parsed_args.columns_file and not columns:
parsed_args.columns = parsed_args.columns_file
elif (not columns) and (not parsed_args.columns_file):
raise NoColumnsError(
"You must give either a --columns or at least one -c/--column "
"argument")
else:
assert columns
return parsed_args |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:read_value; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:ftype; 5, identifier:prompt; 6, default_parameter; 6, 7; 6, 8; 7, identifier:default; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:minval; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:maxval; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:allowed_single_chars; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:question_mark; 20, True; 21, block; 21, 22; 21, 26; 21, 39; 21, 76; 21, 113; 21, 178; 21, 182; 21, 391; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:result; 25, None; 26, if_statement; 26, 27; 26, 28; 26, 33; 27, identifier:question_mark; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:cquestion_mark; 32, string:' ? '; 33, else_clause; 33, 34; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:cquestion_mark; 38, string:''; 39, if_statement; 39, 40; 39, 43; 39, 70; 40, comparison_operator:is; 40, 41; 40, 42; 41, identifier:minval; 42, None; 43, block; 43, 44; 44, try_statement; 44, 45; 44, 53; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:iminval; 49, call; 49, 50; 49, 51; 50, identifier:ftype; 51, argument_list; 51, 52; 52, identifier:minval; 53, except_clause; 53, 54; 53, 55; 54, identifier:ValueError; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:ValueError; 59, argument_list; 59, 60; 60, binary_operator:+; 60, 61; 60, 69; 61, binary_operator:+; 61, 62; 61, 68; 62, binary_operator:+; 62, 63; 62, 64; 63, string:"'"; 64, call; 64, 65; 64, 66; 65, identifier:str; 66, argument_list; 66, 67; 67, identifier:minval; 68, string:"' cannot "; 69, string:"be used as an minval in readi()"; 70, else_clause; 70, 71; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:iminval; 75, None; 76, if_statement; 76, 77; 76, 80; 76, 107; 77, comparison_operator:is; 77, 78; 77, 79; 78, identifier:maxval; 79, None; 80, block; 80, 81; 81, try_statement; 81, 82; 81, 90; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:imaxval; 86, call; 86, 87; 86, 88; 87, identifier:ftype; 88, argument_list; 88, 89; 89, identifier:maxval; 90, except_clause; 90, 91; 90, 92; 91, identifier:ValueError; 92, block; 92, 93; 93, raise_statement; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:ValueError; 96, argument_list; 96, 97; 97, binary_operator:+; 97, 98; 97, 106; 98, binary_operator:+; 98, 99; 98, 105; 99, binary_operator:+; 99, 100; 99, 101; 100, string:"'"; 101, call; 101, 102; 101, 103; 102, identifier:str; 103, argument_list; 103, 104; 104, identifier:maxval; 105, string:"' cannot "; 106, string:"be used as an maxval in readi()"; 107, else_clause; 107, 108; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:imaxval; 112, None; 113, if_statement; 113, 114; 113, 121; 113, 126; 113, 142; 113, 158; 114, boolean_operator:and; 114, 115; 114, 118; 115, comparison_operator:is; 115, 116; 115, 117; 116, identifier:minval; 117, None; 118, comparison_operator:is; 118, 119; 118, 120; 119, identifier:maxval; 120, None; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:cminmax; 125, string:''; 126, elif_clause; 126, 127; 126, 130; 127, comparison_operator:is; 127, 128; 127, 129; 128, identifier:minval; 129, None; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:cminmax; 134, binary_operator:+; 134, 135; 134, 141; 135, binary_operator:+; 135, 136; 135, 137; 136, string:' (number <= '; 137, call; 137, 138; 137, 139; 138, identifier:str; 139, argument_list; 139, 140; 140, identifier:imaxval; 141, string:')'; 142, elif_clause; 142, 143; 142, 146; 143, comparison_operator:is; 143, 144; 143, 145; 144, identifier:maxval; 145, None; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:cminmax; 150, binary_operator:+; 150, 151; 150, 157; 151, binary_operator:+; 151, 152; 151, 153; 152, string:' (number >= '; 153, call; 153, 154; 153, 155; 154, identifier:str; 155, argument_list; 155, 156; 156, identifier:iminval; 157, string:')'; 158, else_clause; 158, 159; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:cminmax; 163, binary_operator:+; 163, 164; 163, 177; 164, binary_operator:+; 164, 165; 164, 173; 165, binary_operator:+; 165, 166; 165, 172; 166, binary_operator:+; 166, 167; 166, 168; 167, string:' ('; 168, call; 168, 169; 168, 170; 169, identifier:str; 170, argument_list; 170, 171; 171, identifier:minval; 172, string:' <= number <= '; 173, call; 173, 174; 173, 175; 174, identifier:str; 175, argument_list; 175, 176; 176, identifier:maxval; 177, string:')'; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:loop; 181, True; 182, while_statement; 182, 183; 182, 184; 183, identifier:loop; 184, block; 184, 185; 184, 241; 184, 255; 184, 271; 184, 291; 185, if_statement; 185, 186; 185, 189; 185, 210; 186, comparison_operator:is; 186, 187; 186, 188; 187, identifier:default; 188, None; 189, block; 189, 190; 189, 202; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:print; 193, argument_list; 193, 194; 193, 199; 194, binary_operator:+; 194, 195; 194, 198; 195, binary_operator:+; 195, 196; 195, 197; 196, identifier:prompt; 197, identifier:cminmax; 198, identifier:cquestion_mark; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:end; 201, string:''; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:sys; 207, identifier:stdout; 208, identifier:flush; 209, argument_list; 210, else_clause; 210, 211; 211, block; 211, 212; 211, 233; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:print; 215, argument_list; 215, 216; 215, 230; 216, binary_operator:+; 216, 217; 216, 229; 217, binary_operator:+; 217, 218; 217, 228; 218, binary_operator:+; 218, 219; 218, 224; 219, binary_operator:+; 219, 220; 219, 223; 220, binary_operator:+; 220, 221; 220, 222; 221, identifier:prompt; 222, identifier:cminmax; 223, string:' ['; 224, call; 224, 225; 224, 226; 225, identifier:str; 226, argument_list; 226, 227; 227, identifier:default; 228, string:']'; 229, identifier:cquestion_mark; 230, keyword_argument; 230, 231; 230, 232; 231, identifier:end; 232, string:''; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 240; 235, attribute; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:sys; 238, identifier:stdout; 239, identifier:flush; 240, argument_list; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:cresult; 244, call; 244, 245; 244, 254; 245, attribute; 245, 246; 245, 253; 246, call; 246, 247; 246, 252; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:sys; 250, identifier:stdin; 251, identifier:readline; 252, argument_list; 253, identifier:strip; 254, argument_list; 255, if_statement; 255, 256; 255, 263; 256, boolean_operator:and; 256, 257; 256, 260; 257, comparison_operator:==; 257, 258; 257, 259; 258, identifier:cresult; 259, string:''; 260, comparison_operator:is; 260, 261; 260, 262; 261, identifier:default; 262, None; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:cresult; 267, call; 267, 268; 267, 269; 268, identifier:str; 269, argument_list; 269, 270; 270, identifier:default; 271, if_statement; 271, 272; 271, 278; 272, comparison_operator:==; 272, 273; 272, 277; 273, call; 273, 274; 273, 275; 274, identifier:len; 275, argument_list; 275, 276; 276, identifier:cresult; 277, integer:1; 278, block; 278, 279; 279, if_statement; 279, 280; 279, 283; 280, comparison_operator:is; 280, 281; 280, 282; 281, identifier:allowed_single_chars; 282, None; 283, block; 283, 284; 284, if_statement; 284, 285; 284, 288; 285, comparison_operator:in; 285, 286; 285, 287; 286, identifier:cresult; 287, identifier:allowed_single_chars; 288, block; 288, 289; 289, return_statement; 289, 290; 290, identifier:cresult; 291, try_statement; 291, 292; 291, 300; 291, 315; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:result; 296, call; 296, 297; 296, 298; 297, identifier:ftype; 298, argument_list; 298, 299; 299, identifier:cresult; 300, except_clause; 300, 301; 300, 302; 301, identifier:ValueError; 302, block; 302, 303; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:print; 306, argument_list; 306, 307; 307, binary_operator:+; 307, 308; 307, 314; 308, binary_operator:+; 308, 309; 308, 310; 309, string:"*** Error: invalid "; 310, call; 310, 311; 310, 312; 311, identifier:str; 312, argument_list; 312, 313; 313, identifier:ftype; 314, string:" value. Try again!"; 315, else_clause; 315, 316; 316, block; 316, 317; 317, if_statement; 317, 318; 317, 325; 317, 330; 317, 351; 317, 372; 318, boolean_operator:and; 318, 319; 318, 322; 319, comparison_operator:is; 319, 320; 319, 321; 320, identifier:minval; 321, None; 322, comparison_operator:is; 322, 323; 322, 324; 323, identifier:maxval; 324, None; 325, block; 325, 326; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 329; 328, identifier:loop; 329, False; 330, elif_clause; 330, 331; 330, 334; 331, comparison_operator:is; 331, 332; 331, 333; 332, identifier:minval; 333, None; 334, block; 334, 335; 335, if_statement; 335, 336; 335, 339; 335, 344; 336, comparison_operator:<=; 336, 337; 336, 338; 337, identifier:result; 338, identifier:imaxval; 339, block; 339, 340; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:loop; 343, False; 344, else_clause; 344, 345; 345, block; 345, 346; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 349; 348, identifier:print; 349, argument_list; 349, 350; 350, string:"*** Error: number out of range. Try again!"; 351, elif_clause; 351, 352; 351, 355; 352, comparison_operator:is; 352, 353; 352, 354; 353, identifier:maxval; 354, None; 355, block; 355, 356; 356, if_statement; 356, 357; 356, 360; 356, 365; 357, comparison_operator:>=; 357, 358; 357, 359; 358, identifier:result; 359, identifier:iminval; 360, block; 360, 361; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 364; 363, identifier:loop; 364, False; 365, else_clause; 365, 366; 366, block; 366, 367; 367, expression_statement; 367, 368; 368, call; 368, 369; 368, 370; 369, identifier:print; 370, argument_list; 370, 371; 371, string:"*** Error: number out of range. Try again!"; 372, else_clause; 372, 373; 373, block; 373, 374; 374, if_statement; 374, 375; 374, 379; 374, 384; 375, comparison_operator:<=; 375, 376; 375, 377; 375, 378; 376, identifier:iminval; 377, identifier:result; 378, identifier:imaxval; 379, block; 379, 380; 380, expression_statement; 380, 381; 381, assignment; 381, 382; 381, 383; 382, identifier:loop; 383, False; 384, else_clause; 384, 385; 385, block; 385, 386; 386, expression_statement; 386, 387; 387, call; 387, 388; 387, 389; 388, identifier:print; 389, argument_list; 389, 390; 390, string:"*** Error: number out of range. Try again!"; 391, return_statement; 391, 392; 392, identifier:result | def read_value(ftype, prompt, default=None, minval=None, maxval=None,
allowed_single_chars=None, question_mark=True):
result = None
if question_mark:
cquestion_mark = ' ? '
else:
cquestion_mark = ''
if minval is not None:
try:
iminval = ftype(minval)
except ValueError:
raise ValueError("'" + str(minval) + "' cannot " +
"be used as an minval in readi()")
else:
iminval = None
if maxval is not None:
try:
imaxval = ftype(maxval)
except ValueError:
raise ValueError("'" + str(maxval) + "' cannot " +
"be used as an maxval in readi()")
else:
imaxval = None
if minval is None and maxval is None:
cminmax = ''
elif minval is None:
cminmax = ' (number <= ' + str(imaxval) + ')'
elif maxval is None:
cminmax = ' (number >= ' + str(iminval) + ')'
else:
cminmax = ' (' + str(minval) + ' <= number <= ' + str(maxval) + ')'
loop = True
while loop:
if default is None:
print(prompt + cminmax + cquestion_mark, end='')
sys.stdout.flush()
else:
print(prompt + cminmax + ' [' + str(default) + ']' +
cquestion_mark, end='')
sys.stdout.flush()
cresult = sys.stdin.readline().strip()
if cresult == '' and default is not None:
cresult = str(default)
if len(cresult) == 1:
if allowed_single_chars is not None:
if cresult in allowed_single_chars:
return cresult
try:
result = ftype(cresult)
except ValueError:
print("*** Error: invalid " + str(ftype) + " value. Try again!")
else:
if minval is None and maxval is None:
loop = False
elif minval is None:
if result <= imaxval:
loop = False
else:
print("*** Error: number out of range. Try again!")
elif maxval is None:
if result >= iminval:
loop = False
else:
print("*** Error: number out of range. Try again!")
else:
if iminval <= result <= imaxval:
loop = False
else:
print("*** Error: number out of range. Try again!")
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:select_configuration; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:obresult; 6, block; 6, 7; 6, 16; 6, 23; 6, 31; 6, 41; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:logger; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:logging; 13, identifier:getLogger; 14, argument_list; 14, 15; 15, identifier:__name__; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:logger; 20, identifier:debug; 21, argument_list; 21, 22; 22, string:'calling default configuration selector'; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:ref; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:obresult; 29, identifier:get_sample_frame; 30, argument_list; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:extr; 34, subscript; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:datamodel; 39, identifier:extractor_map; 40, string:'fits'; 41, if_statement; 41, 42; 41, 43; 41, 180; 42, identifier:ref; 43, block; 43, 44; 43, 54; 43, 111; 43, 121; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:result; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:extr; 50, identifier:extract; 51, argument_list; 51, 52; 51, 53; 52, string:'insconf'; 53, identifier:ref; 54, if_statement; 54, 55; 54, 56; 55, identifier:result; 56, block; 56, 57; 56, 65; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:logger; 61, identifier:debug; 62, argument_list; 62, 63; 62, 64; 63, string:'found insconf config uuid=%s'; 64, identifier:result; 65, if_statement; 65, 66; 65, 71; 65, 78; 66, comparison_operator:in; 66, 67; 66, 68; 67, identifier:result; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:configurations; 71, block; 71, 72; 72, return_statement; 72, 73; 73, subscript; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:configurations; 77, identifier:result; 78, else_clause; 78, 79; 79, block; 79, 80; 80, for_statement; 80, 81; 80, 82; 80, 89; 80, 99; 81, identifier:conf; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:configurations; 87, identifier:values; 88, argument_list; 89, block; 89, 90; 90, if_statement; 90, 91; 90, 96; 91, comparison_operator:==; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:conf; 94, identifier:name; 95, identifier:result; 96, block; 96, 97; 97, return_statement; 97, 98; 98, identifier:conf; 99, else_clause; 99, 100; 100, block; 100, 101; 101, raise_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:KeyError; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, string:'insconf {} does not match any config'; 108, identifier:format; 109, argument_list; 109, 110; 110, identifier:result; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:date_obs; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:extr; 117, identifier:extract; 118, argument_list; 118, 119; 118, 120; 119, string:'observation_date'; 120, identifier:ref; 121, for_statement; 121, 122; 121, 125; 121, 132; 122, pattern_list; 122, 123; 122, 124; 123, identifier:key; 124, identifier:conf; 125, call; 125, 126; 125, 131; 126, attribute; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:configurations; 130, identifier:items; 131, argument_list; 132, block; 132, 133; 132, 139; 132, 160; 133, if_statement; 133, 134; 133, 137; 134, comparison_operator:==; 134, 135; 134, 136; 135, identifier:key; 136, string:'default'; 137, block; 137, 138; 138, continue_statement; 139, if_statement; 139, 140; 139, 145; 139, 154; 140, comparison_operator:is; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:conf; 143, identifier:date_end; 144, None; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:upper_t; 149, comparison_operator:<; 149, 150; 149, 151; 150, identifier:date_obs; 151, attribute; 151, 152; 151, 153; 152, identifier:conf; 153, identifier:date_end; 154, else_clause; 154, 155; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:upper_t; 159, True; 160, if_statement; 160, 161; 160, 169; 161, boolean_operator:and; 161, 162; 161, 163; 162, identifier:upper_t; 163, parenthesized_expression; 163, 164; 164, comparison_operator:>=; 164, 165; 164, 166; 165, identifier:date_obs; 166, attribute; 166, 167; 166, 168; 167, identifier:conf; 168, identifier:date_start; 169, block; 169, 170; 169, 178; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:logger; 174, identifier:debug; 175, argument_list; 175, 176; 175, 177; 176, string:'found date match, config uuid=%s'; 177, identifier:key; 178, return_statement; 178, 179; 179, identifier:conf; 180, else_clause; 180, 181; 181, block; 181, 182; 181, 189; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:logger; 186, identifier:debug; 187, argument_list; 187, 188; 188, string:'no match, using default configuration'; 189, return_statement; 189, 190; 190, subscript; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:configurations; 194, string:'default' | def select_configuration(self, obresult):
logger = logging.getLogger(__name__)
logger.debug('calling default configuration selector')
ref = obresult.get_sample_frame()
extr = self.datamodel.extractor_map['fits']
if ref:
result = extr.extract('insconf', ref)
if result:
logger.debug('found insconf config uuid=%s', result)
if result in self.configurations:
return self.configurations[result]
else:
for conf in self.configurations.values():
if conf.name == result:
return conf
else:
raise KeyError('insconf {} does not match any config'.format(result))
date_obs = extr.extract('observation_date', ref)
for key, conf in self.configurations.items():
if key == 'default':
continue
if conf.date_end is not None:
upper_t = date_obs < conf.date_end
else:
upper_t = True
if upper_t and (date_obs >= conf.date_start):
logger.debug('found date match, config uuid=%s', key)
return conf
else:
logger.debug('no match, using default configuration')
return self.configurations['default'] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:pause_debugplot; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:debugplot; 5, default_parameter; 5, 6; 5, 7; 6, identifier:optional_prompt; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:pltshow; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:tight_layout; 13, True; 14, block; 14, 15; 14, 26; 14, 50; 14, 187; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:not; 16, 17; 16, 18; 17, identifier:debugplot; 18, identifier:DEBUGPLOT_CODES; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:ValueError; 23, argument_list; 23, 24; 23, 25; 24, string:'Invalid debugplot value:'; 25, identifier:debugplot; 26, if_statement; 26, 27; 26, 30; 26, 40; 27, comparison_operator:<; 27, 28; 27, 29; 28, identifier:debugplot; 29, integer:0; 30, block; 30, 31; 30, 36; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:debugplot_; 34, unary_operator:-; 34, 35; 35, identifier:debugplot; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:pltclose; 39, True; 40, else_clause; 40, 41; 41, block; 41, 42; 41, 46; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:debugplot_; 45, identifier:debugplot; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:pltclose; 49, False; 50, if_statement; 50, 51; 50, 52; 50, 132; 51, identifier:pltshow; 52, block; 52, 53; 53, if_statement; 53, 54; 53, 63; 54, comparison_operator:in; 54, 55; 54, 56; 55, identifier:debugplot_; 56, list:[1, 2, 11, 12, 21, 22]; 56, 57; 56, 58; 56, 59; 56, 60; 56, 61; 56, 62; 57, integer:1; 58, integer:2; 59, integer:11; 60, integer:12; 61, integer:21; 62, integer:22; 63, block; 63, 64; 63, 73; 64, if_statement; 64, 65; 64, 66; 65, identifier:tight_layout; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:plt; 71, identifier:tight_layout; 72, argument_list; 73, if_statement; 73, 74; 73, 80; 73, 97; 74, comparison_operator:in; 74, 75; 74, 76; 75, identifier:debugplot_; 76, list:[1, 11, 21]; 76, 77; 76, 78; 76, 79; 77, integer:1; 78, integer:11; 79, integer:21; 80, block; 80, 81; 80, 90; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:plt; 85, identifier:show; 86, argument_list; 86, 87; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:block; 89, False; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:plt; 94, identifier:pause; 95, argument_list; 95, 96; 96, float:0.2; 97, elif_clause; 97, 98; 97, 104; 98, comparison_operator:in; 98, 99; 98, 100; 99, identifier:debugplot_; 100, list:[2, 12, 22]; 100, 101; 100, 102; 100, 103; 101, integer:2; 102, integer:12; 103, integer:22; 104, block; 104, 105; 104, 113; 104, 121; 104, 127; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:print; 108, argument_list; 108, 109; 108, 110; 109, string:'Press "q" to continue...'; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:end; 112, string:''; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 120; 115, attribute; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:sys; 118, identifier:stdout; 119, identifier:flush; 120, argument_list; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:plt; 125, identifier:show; 126, argument_list; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:print; 130, argument_list; 130, 131; 131, string:''; 132, else_clause; 132, 133; 133, block; 133, 134; 134, if_statement; 134, 135; 134, 141; 135, comparison_operator:in; 135, 136; 135, 137; 136, identifier:debugplot_; 137, list:[2, 12, 22]; 137, 138; 137, 139; 137, 140; 138, integer:2; 139, integer:12; 140, integer:22; 141, block; 141, 142; 141, 165; 141, 173; 142, if_statement; 142, 143; 142, 146; 142, 155; 143, comparison_operator:is; 143, 144; 143, 145; 144, identifier:optional_prompt; 145, None; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 150; 149, identifier:print; 150, argument_list; 150, 151; 150, 152; 151, string:'Press <RETURN> to continue...'; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:end; 154, string:''; 155, else_clause; 155, 156; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:print; 160, argument_list; 160, 161; 160, 162; 161, identifier:optional_prompt; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:end; 164, string:''; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:sys; 170, identifier:stdout; 171, identifier:flush; 172, argument_list; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:cdummy; 176, call; 176, 177; 176, 186; 177, attribute; 177, 178; 177, 185; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:sys; 182, identifier:stdin; 183, identifier:readline; 184, argument_list; 185, identifier:strip; 186, argument_list; 187, if_statement; 187, 188; 187, 199; 188, boolean_operator:and; 188, 189; 188, 198; 189, comparison_operator:in; 189, 190; 189, 191; 190, identifier:debugplot_; 191, list:[1, 2, 11, 12, 21, 22]; 191, 192; 191, 193; 191, 194; 191, 195; 191, 196; 191, 197; 192, integer:1; 193, integer:2; 194, integer:11; 195, integer:12; 196, integer:21; 197, integer:22; 198, identifier:pltclose; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:plt; 204, identifier:close; 205, argument_list | def pause_debugplot(debugplot, optional_prompt=None, pltshow=False,
tight_layout=True):
if debugplot not in DEBUGPLOT_CODES:
raise ValueError('Invalid debugplot value:', debugplot)
if debugplot < 0:
debugplot_ = -debugplot
pltclose = True
else:
debugplot_ = debugplot
pltclose = False
if pltshow:
if debugplot_ in [1, 2, 11, 12, 21, 22]:
if tight_layout:
plt.tight_layout()
if debugplot_ in [1, 11, 21]:
plt.show(block=False)
plt.pause(0.2)
elif debugplot_ in [2, 12, 22]:
print('Press "q" to continue...', end='')
sys.stdout.flush()
plt.show()
print('')
else:
if debugplot_ in [2, 12, 22]:
if optional_prompt is None:
print('Press <RETURN> to continue...', end='')
else:
print(optional_prompt, end='')
sys.stdout.flush()
cdummy = sys.stdin.readline().strip()
if debugplot_ in [1, 2, 11, 12, 21, 22] and pltclose:
plt.close() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:mode_half_sample; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, default_parameter; 5, 6; 5, 7; 6, identifier:is_sorted; 7, False; 8, block; 8, 9; 8, 11; 8, 20; 8, 39; 8, 46; 9, expression_statement; 9, 10; 10, string:'''
Estimate the mode using the Half Sample mode.
A method to estimate the mode, as described in
D. R. Bickel and R. Frühwirth (contributed equally),
"On a fast, robust estimator of the mode: Comparisons to other
robust estimators with applications,"
Computational Statistics and Data Analysis 50, 3500-3530 (2006).
Example
=======
>> import numpy as np
>> np.random.seed(1392838)
>> a = np.random.normal(1000, 200, size=1000)
>> a[:100] = np.random.normal(2000, 300, size=100)
>> b = np.sort(a)
>> mode_half_sample(b, is_sorted=True)
1041.9327885039545
'''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:a; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:np; 17, identifier:asanyarray; 18, argument_list; 18, 19; 19, identifier:a; 20, if_statement; 20, 21; 20, 23; 20, 33; 21, not_operator; 21, 22; 22, identifier:is_sorted; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:sdata; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:np; 30, identifier:sort; 31, argument_list; 31, 32; 32, identifier:a; 33, else_clause; 33, 34; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:sdata; 38, identifier:a; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:n; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:sdata; 46, if_statement; 46, 47; 46, 50; 46, 55; 46, 71; 46, 131; 47, comparison_operator:==; 47, 48; 47, 49; 48, identifier:n; 49, integer:1; 50, block; 50, 51; 51, return_statement; 51, 52; 52, subscript; 52, 53; 52, 54; 53, identifier:sdata; 54, integer:0; 55, elif_clause; 55, 56; 55, 59; 56, comparison_operator:==; 56, 57; 56, 58; 57, identifier:n; 58, integer:2; 59, block; 59, 60; 60, return_statement; 60, 61; 61, binary_operator:*; 61, 62; 61, 63; 62, float:0.5; 63, parenthesized_expression; 63, 64; 64, binary_operator:+; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:sdata; 67, integer:0; 68, subscript; 68, 69; 68, 70; 69, identifier:sdata; 70, integer:1; 71, elif_clause; 71, 72; 71, 75; 72, comparison_operator:==; 72, 73; 72, 74; 73, identifier:n; 74, integer:3; 75, block; 75, 76; 75, 93; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:ind; 79, binary_operator:-; 79, 80; 79, 90; 80, binary_operator:+; 80, 81; 80, 85; 81, unary_operator:-; 81, 82; 82, subscript; 82, 83; 82, 84; 83, identifier:sdata; 84, integer:0; 85, binary_operator:*; 85, 86; 85, 87; 86, integer:2; 87, subscript; 87, 88; 87, 89; 88, identifier:sdata; 89, integer:1; 90, subscript; 90, 91; 90, 92; 91, identifier:sdata; 92, integer:2; 93, if_statement; 93, 94; 93, 97; 93, 109; 93, 125; 94, comparison_operator:<; 94, 95; 94, 96; 95, identifier:ind; 96, integer:0; 97, block; 97, 98; 98, return_statement; 98, 99; 99, binary_operator:*; 99, 100; 99, 101; 100, float:0.5; 101, parenthesized_expression; 101, 102; 102, binary_operator:+; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:sdata; 105, integer:0; 106, subscript; 106, 107; 106, 108; 107, identifier:sdata; 108, integer:1; 109, elif_clause; 109, 110; 109, 113; 110, comparison_operator:>; 110, 111; 110, 112; 111, identifier:ind; 112, integer:0; 113, block; 113, 114; 114, return_statement; 114, 115; 115, binary_operator:*; 115, 116; 115, 117; 116, float:0.5; 117, parenthesized_expression; 117, 118; 118, binary_operator:+; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:sdata; 121, integer:1; 122, subscript; 122, 123; 122, 124; 123, identifier:sdata; 124, integer:2; 125, else_clause; 125, 126; 126, block; 126, 127; 127, return_statement; 127, 128; 128, subscript; 128, 129; 128, 130; 129, identifier:sdata; 130, integer:1; 131, else_clause; 131, 132; 132, block; 132, 133; 132, 147; 132, 169; 132, 177; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:N; 136, call; 136, 137; 136, 138; 137, identifier:int; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:math; 142, identifier:ceil; 143, argument_list; 143, 144; 144, binary_operator:/; 144, 145; 144, 146; 145, identifier:n; 146, float:2.0; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:w; 150, binary_operator:-; 150, 151; 150, 159; 151, subscript; 151, 152; 151, 153; 152, identifier:sdata; 153, slice; 153, 154; 153, 158; 154, parenthesized_expression; 154, 155; 155, binary_operator:-; 155, 156; 155, 157; 156, identifier:N; 157, integer:1; 158, colon; 159, subscript; 159, 160; 159, 161; 160, identifier:sdata; 161, slice; 161, 162; 161, 163; 162, colon; 163, parenthesized_expression; 163, 164; 164, binary_operator:+; 164, 165; 164, 168; 165, binary_operator:-; 165, 166; 165, 167; 166, identifier:n; 167, identifier:N; 168, integer:1; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:ar; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:w; 175, identifier:argmin; 176, argument_list; 177, return_statement; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:mode_half_sample; 180, argument_list; 180, 181; 180, 189; 181, subscript; 181, 182; 181, 183; 182, identifier:sdata; 183, slice; 183, 184; 183, 185; 183, 186; 184, identifier:ar; 185, colon; 186, binary_operator:+; 186, 187; 186, 188; 187, identifier:ar; 188, identifier:N; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:is_sorted; 191, True | def mode_half_sample(a, is_sorted=False):
'''
Estimate the mode using the Half Sample mode.
A method to estimate the mode, as described in
D. R. Bickel and R. Frühwirth (contributed equally),
"On a fast, robust estimator of the mode: Comparisons to other
robust estimators with applications,"
Computational Statistics and Data Analysis 50, 3500-3530 (2006).
Example
=======
>> import numpy as np
>> np.random.seed(1392838)
>> a = np.random.normal(1000, 200, size=1000)
>> a[:100] = np.random.normal(2000, 300, size=100)
>> b = np.sort(a)
>> mode_half_sample(b, is_sorted=True)
1041.9327885039545
'''
a = np.asanyarray(a)
if not is_sorted:
sdata = np.sort(a)
else:
sdata = a
n = len(sdata)
if n == 1:
return sdata[0]
elif n == 2:
return 0.5 * (sdata[0] + sdata[1])
elif n == 3:
ind = -sdata[0] + 2 * sdata[1] - sdata[2]
if ind < 0:
return 0.5 * (sdata[0] + sdata[1])
elif ind > 0:
return 0.5 * (sdata[1] + sdata[2])
else:
return sdata[1]
else:
N = int(math.ceil(n / 2.0))
w = sdata[(N-1):] - sdata[:(n-N+1)]
ar = w.argmin()
return mode_half_sample(sdata[ar:ar+N], is_sorted=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:author_id_normalize_and_schema; 3, parameters; 3, 4; 3, 5; 4, identifier:uid; 5, default_parameter; 5, 6; 5, 7; 6, identifier:schema; 7, None; 8, block; 8, 9; 8, 47; 8, 70; 8, 82; 8, 108; 8, 116; 8, 147; 8, 154; 9, function_definition; 9, 10; 9, 11; 9, 14; 10, function_name:_get_uid_normalized_in_schema; 11, parameters; 11, 12; 11, 13; 12, identifier:_uid; 13, identifier:_schema; 14, block; 14, 15; 14, 23; 14, 32; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:regex; 19, identifier:template; 20, subscript; 20, 21; 20, 22; 21, identifier:_RE_AUTHORS_UID; 22, identifier:_schema; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:match; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:regex; 29, identifier:match; 30, argument_list; 30, 31; 31, identifier:_uid; 32, if_statement; 32, 33; 32, 34; 33, identifier:match; 34, block; 34, 35; 35, return_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:template; 39, identifier:format; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:match; 44, identifier:group; 45, argument_list; 45, 46; 46, string:'uid'; 47, if_statement; 47, 48; 47, 60; 48, boolean_operator:and; 48, 49; 48, 55; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:idutils; 52, identifier:is_orcid; 53, argument_list; 53, 54; 54, identifier:uid; 55, comparison_operator:in; 55, 56; 55, 57; 56, identifier:schema; 57, tuple; 57, 58; 57, 59; 58, None; 59, string:'ORCID'; 60, block; 60, 61; 61, return_statement; 61, 62; 62, expression_list; 62, 63; 62, 69; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:idutils; 66, identifier:normalize_orcid; 67, argument_list; 67, 68; 68, identifier:uid; 69, string:'ORCID'; 70, if_statement; 70, 71; 70, 76; 71, boolean_operator:and; 71, 72; 71, 73; 72, identifier:schema; 73, comparison_operator:not; 73, 74; 73, 75; 74, identifier:schema; 75, identifier:_RE_AUTHORS_UID; 76, block; 76, 77; 77, raise_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:UnknownUIDSchema; 80, argument_list; 80, 81; 81, identifier:uid; 82, if_statement; 82, 83; 82, 84; 83, identifier:schema; 84, block; 84, 85; 84, 93; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:normalized_uid; 88, call; 88, 89; 88, 90; 89, identifier:_get_uid_normalized_in_schema; 90, argument_list; 90, 91; 90, 92; 91, identifier:uid; 92, identifier:schema; 93, if_statement; 93, 94; 93, 95; 93, 100; 94, identifier:normalized_uid; 95, block; 95, 96; 96, return_statement; 96, 97; 97, expression_list; 97, 98; 97, 99; 98, identifier:normalized_uid; 99, identifier:schema; 100, else_clause; 100, 101; 101, block; 101, 102; 102, raise_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:SchemaUIDConflict; 105, argument_list; 105, 106; 105, 107; 106, identifier:schema; 107, identifier:uid; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, pattern_list; 110, 111; 110, 112; 111, identifier:match_schema; 112, identifier:normalized_uid; 113, expression_list; 113, 114; 113, 115; 114, None; 115, None; 116, for_statement; 116, 117; 116, 118; 116, 119; 117, identifier:candidate_schema; 118, identifier:_RE_AUTHORS_UID; 119, block; 119, 120; 119, 128; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:candidate_uid; 123, call; 123, 124; 123, 125; 124, identifier:_get_uid_normalized_in_schema; 125, argument_list; 125, 126; 125, 127; 126, identifier:uid; 127, identifier:candidate_schema; 128, if_statement; 128, 129; 128, 130; 129, identifier:candidate_uid; 130, block; 130, 131; 130, 139; 130, 143; 131, if_statement; 131, 132; 131, 133; 132, identifier:match_schema; 133, block; 133, 134; 134, raise_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:UnknownUIDSchema; 137, argument_list; 137, 138; 138, identifier:uid; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:match_schema; 142, identifier:candidate_schema; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:normalized_uid; 146, identifier:candidate_uid; 147, if_statement; 147, 148; 147, 149; 148, identifier:match_schema; 149, block; 149, 150; 150, return_statement; 150, 151; 151, expression_list; 151, 152; 151, 153; 152, identifier:normalized_uid; 153, identifier:match_schema; 154, raise_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:UnknownUIDSchema; 157, argument_list; 157, 158; 158, identifier:uid | def author_id_normalize_and_schema(uid, schema=None):
def _get_uid_normalized_in_schema(_uid, _schema):
regex, template = _RE_AUTHORS_UID[_schema]
match = regex.match(_uid)
if match:
return template.format(match.group('uid'))
if idutils.is_orcid(uid) and schema in (None, 'ORCID'):
return idutils.normalize_orcid(uid), 'ORCID'
if schema and schema not in _RE_AUTHORS_UID:
raise UnknownUIDSchema(uid)
if schema:
normalized_uid = _get_uid_normalized_in_schema(uid, schema)
if normalized_uid:
return normalized_uid, schema
else:
raise SchemaUIDConflict(schema, uid)
match_schema, normalized_uid = None, None
for candidate_schema in _RE_AUTHORS_UID:
candidate_uid = _get_uid_normalized_in_schema(uid, candidate_schema)
if candidate_uid:
if match_schema:
raise UnknownUIDSchema(uid)
match_schema = candidate_schema
normalized_uid = candidate_uid
if match_schema:
return normalized_uid, match_schema
raise UnknownUIDSchema(uid) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_schema_path; 3, parameters; 3, 4; 3, 5; 4, identifier:schema; 5, default_parameter; 5, 6; 5, 7; 6, identifier:resolved; 7, False; 8, block; 8, 9; 8, 39; 8, 101; 8, 108; 8, 180; 9, function_definition; 9, 10; 9, 11; 9, 13; 10, function_name:_strip_first_path_elem; 11, parameters; 11, 12; 12, identifier:path; 13, block; 13, 14; 13, 32; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:stripped_path; 17, subscript; 17, 18; 17, 29; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:path; 21, identifier:split; 22, argument_list; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:os; 26, identifier:path; 27, identifier:sep; 28, integer:1; 29, slice; 29, 30; 29, 31; 30, integer:1; 31, colon; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, string:''; 36, identifier:join; 37, argument_list; 37, 38; 38, identifier:stripped_path; 39, function_definition; 39, 40; 39, 41; 39, 43; 40, function_name:_schema_to_normalized_path; 41, parameters; 41, 42; 42, identifier:schema; 43, block; 43, 44; 43, 66; 43, 86; 43, 99; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:path; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:os; 51, identifier:path; 52, identifier:normpath; 53, argument_list; 53, 54; 54, binary_operator:+; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:os; 58, identifier:path; 59, identifier:sep; 60, attribute; 60, 61; 60, 65; 61, call; 61, 62; 61, 63; 62, identifier:urlsplit; 63, argument_list; 63, 64; 64, identifier:schema; 65, identifier:path; 66, if_statement; 66, 67; 66, 77; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:path; 70, identifier:startswith; 71, argument_list; 71, 72; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:os; 75, identifier:path; 76, identifier:sep; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:path; 81, subscript; 81, 82; 81, 83; 82, identifier:path; 83, slice; 83, 84; 83, 85; 84, integer:1; 85, colon; 86, if_statement; 86, 87; 86, 94; 87, not_operator; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:path; 91, identifier:endswith; 92, argument_list; 92, 93; 93, string:'.json'; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, augmented_assignment:+=; 96, 97; 96, 98; 97, identifier:path; 98, string:'.json'; 99, return_statement; 99, 100; 100, identifier:path; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:path; 104, call; 104, 105; 104, 106; 105, identifier:_schema_to_normalized_path; 106, argument_list; 106, 107; 107, identifier:schema; 108, while_statement; 108, 109; 108, 110; 109, identifier:path; 110, block; 110, 111; 110, 154; 110, 173; 111, if_statement; 111, 112; 111, 113; 111, 133; 112, identifier:resolved; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:schema_path; 117, call; 117, 118; 117, 123; 118, attribute; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:os; 121, identifier:path; 122, identifier:abspath; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:os; 128, identifier:path; 129, identifier:join; 130, argument_list; 130, 131; 130, 132; 131, identifier:_resolved_schema_root_path; 132, identifier:path; 133, else_clause; 133, 134; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:schema_path; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:os; 142, identifier:path; 143, identifier:abspath; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 151; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:os; 149, identifier:path; 150, identifier:join; 151, argument_list; 151, 152; 151, 153; 152, identifier:_schema_root_path; 153, identifier:path; 154, if_statement; 154, 155; 154, 163; 155, call; 155, 156; 155, 161; 156, attribute; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:os; 159, identifier:path; 160, identifier:exists; 161, argument_list; 161, 162; 162, identifier:schema_path; 163, block; 163, 164; 164, return_statement; 164, 165; 165, call; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:os; 169, identifier:path; 170, identifier:abspath; 171, argument_list; 171, 172; 172, identifier:schema_path; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:path; 176, call; 176, 177; 176, 178; 177, identifier:_strip_first_path_elem; 178, argument_list; 178, 179; 179, identifier:path; 180, raise_statement; 180, 181; 181, call; 181, 182; 181, 183; 182, identifier:SchemaNotFound; 183, argument_list; 183, 184; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:schema; 186, identifier:schema | def get_schema_path(schema, resolved=False):
def _strip_first_path_elem(path):
stripped_path = path.split(os.path.sep, 1)[1:]
return ''.join(stripped_path)
def _schema_to_normalized_path(schema):
path = os.path.normpath(os.path.sep + urlsplit(schema).path)
if path.startswith(os.path.sep):
path = path[1:]
if not path.endswith('.json'):
path += '.json'
return path
path = _schema_to_normalized_path(schema)
while path:
if resolved:
schema_path = os.path.abspath(os.path.join(_resolved_schema_root_path, path))
else:
schema_path = os.path.abspath(os.path.join(_schema_root_path, path))
if os.path.exists(schema_path):
return os.path.abspath(schema_path)
path = _strip_first_path_elem(path)
raise SchemaNotFound(schema=schema) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_license_from_url; 3, parameters; 3, 4; 4, identifier:url; 5, block; 5, 6; 5, 11; 5, 21; 5, 167; 6, if_statement; 6, 7; 6, 9; 7, not_operator; 7, 8; 8, identifier:url; 9, block; 9, 10; 10, return_statement; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:split_url; 14, call; 14, 15; 14, 16; 15, identifier:urlsplit; 16, argument_list; 16, 17; 16, 18; 17, identifier:url; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:scheme; 20, string:'http'; 21, if_statement; 21, 22; 21, 31; 21, 121; 21, 160; 22, comparison_operator:==; 22, 23; 22, 30; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:split_url; 27, identifier:netloc; 28, identifier:lower; 29, argument_list; 30, string:'creativecommons.org'; 31, block; 31, 32; 32, if_statement; 32, 33; 32, 38; 32, 83; 33, comparison_operator:in; 33, 34; 33, 35; 34, string:'publicdomain'; 35, attribute; 35, 36; 35, 37; 36, identifier:split_url; 37, identifier:path; 38, block; 38, 39; 38, 50; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:match; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:_RE_PUBLIC_DOMAIN_URL; 45, identifier:match; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:split_url; 49, identifier:path; 50, if_statement; 50, 51; 50, 54; 50, 60; 51, comparison_operator:is; 51, 52; 51, 53; 52, identifier:match; 53, None; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:license; 58, list:['public domain']; 58, 59; 59, string:'public domain'; 60, else_clause; 60, 61; 61, block; 61, 62; 61, 67; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:license; 65, list:['CC0']; 65, 66; 66, string:'CC0'; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:license; 71, identifier:extend; 72, generator_expression; 72, 73; 72, 74; 72, 81; 73, identifier:part; 74, for_in_clause; 74, 75; 74, 76; 75, identifier:part; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:match; 79, identifier:groups; 80, argument_list; 81, if_clause; 81, 82; 82, identifier:part; 83, else_clause; 83, 84; 84, block; 84, 85; 84, 90; 84, 101; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:license; 88, list:['CC']; 88, 89; 89, string:'CC'; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:match; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:_RE_LICENSE_URL; 96, identifier:match; 97, argument_list; 97, 98; 98, attribute; 98, 99; 98, 100; 99, identifier:split_url; 100, identifier:path; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:license; 105, identifier:extend; 106, generator_expression; 106, 107; 106, 112; 106, 119; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:part; 110, identifier:upper; 111, argument_list; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:part; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:match; 117, identifier:groups; 118, argument_list; 119, if_clause; 119, 120; 120, identifier:part; 121, elif_clause; 121, 122; 121, 127; 122, comparison_operator:==; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:split_url; 125, identifier:netloc; 126, string:'arxiv.org'; 127, block; 127, 128; 127, 133; 127, 144; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:license; 131, list:['arXiv']; 131, 132; 132, string:'arXiv'; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:match; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:_RE_LICENSE_URL; 139, identifier:match; 140, argument_list; 140, 141; 141, attribute; 141, 142; 141, 143; 142, identifier:split_url; 143, identifier:path; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:license; 148, identifier:extend; 149, generator_expression; 149, 150; 149, 151; 149, 158; 150, identifier:part; 151, for_in_clause; 151, 152; 151, 153; 152, identifier:part; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:match; 156, identifier:groups; 157, argument_list; 158, if_clause; 158, 159; 159, identifier:part; 160, else_clause; 160, 161; 161, block; 161, 162; 162, raise_statement; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:ValueError; 165, argument_list; 165, 166; 166, string:'Unknown license URL'; 167, return_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, string:u' '; 171, identifier:join; 172, argument_list; 172, 173; 173, identifier:license | def get_license_from_url(url):
if not url:
return
split_url = urlsplit(url, scheme='http')
if split_url.netloc.lower() == 'creativecommons.org':
if 'publicdomain' in split_url.path:
match = _RE_PUBLIC_DOMAIN_URL.match(split_url.path)
if match is None:
license = ['public domain']
else:
license = ['CC0']
license.extend(part for part in match.groups() if part)
else:
license = ['CC']
match = _RE_LICENSE_URL.match(split_url.path)
license.extend(part.upper() for part in match.groups() if part)
elif split_url.netloc == 'arxiv.org':
license = ['arXiv']
match = _RE_LICENSE_URL.match(split_url.path)
license.extend(part for part in match.groups() if part)
else:
raise ValueError('Unknown license URL')
return u' '.join(license) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:convert_old_publication_info_to_new; 3, parameters; 3, 4; 4, identifier:publication_infos; 5, block; 5, 6; 5, 10; 5, 14; 5, 280; 5, 302; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:result; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:hidden_publication_infos; 13, list:[]; 14, for_statement; 14, 15; 14, 16; 14, 17; 15, identifier:publication_info; 16, identifier:publication_infos; 17, block; 17, 18; 17, 27; 17, 36; 17, 62; 17, 71; 17, 148; 17, 251; 17, 261; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:_publication_info; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:copy; 24, identifier:deepcopy; 25, argument_list; 25, 26; 26, identifier:publication_info; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:journal_title; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:_publication_info; 33, identifier:get; 34, argument_list; 34, 35; 35, string:'journal_title'; 36, try_statement; 36, 37; 36, 58; 37, block; 37, 38; 37, 44; 37, 50; 37, 57; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:journal_title; 41, subscript; 41, 42; 41, 43; 42, identifier:_JOURNALS_RENAMED_OLD_TO_NEW; 43, identifier:journal_title; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:_publication_info; 48, string:'journal_title'; 49, identifier:journal_title; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:result; 54, identifier:append; 55, argument_list; 55, 56; 56, identifier:_publication_info; 57, continue_statement; 58, except_clause; 58, 59; 58, 60; 59, identifier:KeyError; 60, block; 60, 61; 61, pass_statement; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:journal_volume; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:_publication_info; 68, identifier:get; 69, argument_list; 69, 70; 70, string:'journal_volume'; 71, if_statement; 71, 72; 71, 84; 72, boolean_operator:and; 72, 73; 72, 78; 73, boolean_operator:and; 73, 74; 73, 77; 74, comparison_operator:in; 74, 75; 74, 76; 75, identifier:journal_title; 76, identifier:_JOURNALS_WITH_YEAR_ADDED_TO_VOLUME; 77, identifier:journal_volume; 78, comparison_operator:==; 78, 79; 78, 83; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, identifier:journal_volume; 83, integer:4; 84, block; 84, 85; 84, 140; 84, 147; 85, try_statement; 85, 86; 85, 100; 85, 104; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:was_last_century; 90, comparison_operator:>; 90, 91; 90, 99; 91, call; 91, 92; 91, 93; 92, identifier:int; 93, argument_list; 93, 94; 94, subscript; 94, 95; 94, 96; 95, identifier:journal_volume; 96, slice; 96, 97; 96, 98; 97, colon; 98, integer:2; 99, integer:50; 100, except_clause; 100, 101; 100, 102; 101, identifier:ValueError; 102, block; 102, 103; 103, pass_statement; 104, else_clause; 104, 105; 105, block; 105, 106; 105, 130; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:_publication_info; 110, string:'year'; 111, call; 111, 112; 111, 113; 112, identifier:int; 113, argument_list; 113, 114; 114, conditional_expression:if; 114, 115; 114, 122; 114, 123; 115, binary_operator:+; 115, 116; 115, 117; 116, string:'19'; 117, subscript; 117, 118; 117, 119; 118, identifier:journal_volume; 119, slice; 119, 120; 119, 121; 120, colon; 121, integer:2; 122, identifier:was_last_century; 123, binary_operator:+; 123, 124; 123, 125; 124, string:'20'; 125, subscript; 125, 126; 125, 127; 126, identifier:journal_volume; 127, slice; 127, 128; 127, 129; 128, colon; 129, integer:2; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:_publication_info; 134, string:'journal_volume'; 135, subscript; 135, 136; 135, 137; 136, identifier:journal_volume; 137, slice; 137, 138; 137, 139; 138, integer:2; 139, colon; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:result; 144, identifier:append; 145, argument_list; 145, 146; 146, identifier:_publication_info; 147, continue_statement; 148, if_statement; 148, 149; 148, 160; 149, boolean_operator:and; 149, 150; 149, 153; 150, boolean_operator:and; 150, 151; 150, 152; 151, identifier:journal_title; 152, identifier:journal_volume; 153, comparison_operator:not; 153, 154; 153, 159; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:journal_title; 157, identifier:lower; 158, argument_list; 159, identifier:JOURNALS_IGNORED_IN_OLD_TO_NEW; 160, block; 160, 161; 160, 170; 160, 179; 160, 185; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:volume_starts_with_a_letter; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:_RE_VOLUME_STARTS_WITH_A_LETTER; 167, identifier:match; 168, argument_list; 168, 169; 169, identifier:journal_volume; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:volume_ends_with_a_letter; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:_RE_VOLUME_ENDS_WITH_A_LETTER; 176, identifier:match; 177, argument_list; 177, 178; 178, identifier:journal_volume; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:match; 182, boolean_operator:or; 182, 183; 182, 184; 183, identifier:volume_starts_with_a_letter; 184, identifier:volume_ends_with_a_letter; 185, if_statement; 185, 186; 185, 187; 186, identifier:match; 187, block; 187, 188; 187, 196; 187, 240; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:_publication_info; 192, identifier:pop; 193, argument_list; 193, 194; 193, 195; 194, string:'journal_record'; 195, None; 196, if_statement; 196, 197; 196, 204; 196, 211; 197, comparison_operator:in; 197, 198; 197, 199; 198, identifier:journal_title; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:_JOURNALS_RENAMED_OLD_TO_NEW; 202, identifier:values; 203, argument_list; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 210; 207, subscript; 207, 208; 207, 209; 208, identifier:_publication_info; 209, string:'journal_title'; 210, identifier:journal_title; 211, else_clause; 211, 212; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 218; 215, subscript; 215, 216; 215, 217; 216, identifier:_publication_info; 217, string:'journal_title'; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, string:''; 221, identifier:join; 222, argument_list; 222, 223; 223, list:[
journal_title,
'' if journal_title.endswith('.') else ' ',
match.group('letter'),
]; 223, 224; 223, 225; 223, 234; 224, identifier:journal_title; 225, conditional_expression:if; 225, 226; 225, 227; 225, 233; 226, string:''; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:journal_title; 230, identifier:endswith; 231, argument_list; 231, 232; 232, string:'.'; 233, string:' '; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:match; 237, identifier:group; 238, argument_list; 238, 239; 239, string:'letter'; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 245; 242, subscript; 242, 243; 242, 244; 243, identifier:_publication_info; 244, string:'journal_volume'; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:match; 248, identifier:group; 249, argument_list; 249, 250; 250, string:'volume'; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:hidden; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:_publication_info; 257, identifier:pop; 258, argument_list; 258, 259; 258, 260; 259, string:'hidden'; 260, None; 261, if_statement; 261, 262; 261, 263; 261, 271; 262, identifier:hidden; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:hidden_publication_infos; 268, identifier:append; 269, argument_list; 269, 270; 270, identifier:_publication_info; 271, else_clause; 271, 272; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:result; 277, identifier:append; 278, argument_list; 278, 279; 279, identifier:_publication_info; 280, for_statement; 280, 281; 280, 282; 280, 283; 281, identifier:publication_info; 282, identifier:hidden_publication_infos; 283, block; 283, 284; 284, if_statement; 284, 285; 284, 288; 285, comparison_operator:not; 285, 286; 285, 287; 286, identifier:publication_info; 287, identifier:result; 288, block; 288, 289; 288, 295; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 294; 291, subscript; 291, 292; 291, 293; 292, identifier:publication_info; 293, string:'hidden'; 294, True; 295, expression_statement; 295, 296; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:result; 299, identifier:append; 300, argument_list; 300, 301; 301, identifier:publication_info; 302, return_statement; 302, 303; 303, identifier:result | def convert_old_publication_info_to_new(publication_infos):
result = []
hidden_publication_infos = []
for publication_info in publication_infos:
_publication_info = copy.deepcopy(publication_info)
journal_title = _publication_info.get('journal_title')
try:
journal_title = _JOURNALS_RENAMED_OLD_TO_NEW[journal_title]
_publication_info['journal_title'] = journal_title
result.append(_publication_info)
continue
except KeyError:
pass
journal_volume = _publication_info.get('journal_volume')
if journal_title in _JOURNALS_WITH_YEAR_ADDED_TO_VOLUME and journal_volume and len(journal_volume) == 4:
try:
was_last_century = int(journal_volume[:2]) > 50
except ValueError:
pass
else:
_publication_info['year'] = int('19' + journal_volume[:2] if was_last_century else '20' + journal_volume[:2])
_publication_info['journal_volume'] = journal_volume[2:]
result.append(_publication_info)
continue
if journal_title and journal_volume and journal_title.lower() not in JOURNALS_IGNORED_IN_OLD_TO_NEW:
volume_starts_with_a_letter = _RE_VOLUME_STARTS_WITH_A_LETTER.match(journal_volume)
volume_ends_with_a_letter = _RE_VOLUME_ENDS_WITH_A_LETTER.match(journal_volume)
match = volume_starts_with_a_letter or volume_ends_with_a_letter
if match:
_publication_info.pop('journal_record', None)
if journal_title in _JOURNALS_RENAMED_OLD_TO_NEW.values():
_publication_info['journal_title'] = journal_title
else:
_publication_info['journal_title'] = ''.join([
journal_title,
'' if journal_title.endswith('.') else ' ',
match.group('letter'),
])
_publication_info['journal_volume'] = match.group('volume')
hidden = _publication_info.pop('hidden', None)
if hidden:
hidden_publication_infos.append(_publication_info)
else:
result.append(_publication_info)
for publication_info in hidden_publication_infos:
if publication_info not in result:
publication_info['hidden'] = True
result.append(publication_info)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:construct_reference_system; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:symbols; 5, default_parameter; 5, 6; 5, 7; 6, identifier:candidates; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:options; 10, None; 11, block; 11, 12; 11, 33; 11, 37; 11, 50; 11, 88; 11, 92; 11, 213; 11, 217; 11, 228; 12, if_statement; 12, 13; 12, 22; 12, 27; 13, boolean_operator:and; 13, 14; 13, 19; 14, call; 14, 15; 14, 16; 15, identifier:hasattr; 16, argument_list; 16, 17; 16, 18; 17, identifier:options; 18, string:'no_hydrogen'; 19, attribute; 19, 20; 19, 21; 20, identifier:options; 21, identifier:no_hydrogen; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:add_hydrogen; 26, False; 27, else_clause; 27, 28; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:add_hydrogen; 32, True; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:references; 36, dictionary; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:sorted_candidates; 40, list:[
'H2',
'H2O',
'NH3',
'N2',
'CH4',
'CO',
'H2S',
'HCl',
'O2']; 40, 41; 40, 42; 40, 43; 40, 44; 40, 45; 40, 46; 40, 47; 40, 48; 40, 49; 41, string:'H2'; 42, string:'H2O'; 43, string:'NH3'; 44, string:'N2'; 45, string:'CH4'; 46, string:'CO'; 47, string:'H2S'; 48, string:'HCl'; 49, string:'O2'; 50, if_statement; 50, 51; 50, 54; 50, 59; 51, comparison_operator:is; 51, 52; 51, 53; 52, identifier:candidates; 53, None; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:candidates; 58, identifier:sorted_candidates; 59, else_clause; 59, 60; 60, block; 60, 61; 60, 73; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:odd_candidates; 64, list_comprehension; 64, 65; 64, 66; 64, 69; 65, identifier:c; 66, for_in_clause; 66, 67; 66, 68; 67, identifier:c; 68, identifier:candidates; 69, if_clause; 69, 70; 70, comparison_operator:not; 70, 71; 70, 72; 71, identifier:c; 72, identifier:sorted_candidates; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:candidates; 76, binary_operator:+; 76, 77; 76, 86; 76, 87; 77, list_comprehension; 77, 78; 77, 79; 77, 82; 78, identifier:c; 79, for_in_clause; 79, 80; 79, 81; 80, identifier:c; 81, identifier:sorted_candidates; 82, if_clause; 82, 83; 83, comparison_operator:in; 83, 84; 83, 85; 84, identifier:c; 85, identifier:candidates; 86, line_continuation:\; 87, identifier:odd_candidates; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:added_symbols; 91, list:[]; 92, for_statement; 92, 93; 92, 94; 92, 95; 93, identifier:symbol; 94, identifier:symbols; 95, block; 95, 96; 95, 103; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:added_symbols; 100, identifier:append; 101, argument_list; 101, 102; 102, identifier:symbol; 103, for_statement; 103, 104; 103, 105; 103, 106; 103, 174; 104, identifier:candidate; 105, identifier:candidates; 106, block; 106, 107; 106, 118; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:_symbols; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:ase; 114, identifier:symbols; 115, identifier:string2symbols; 116, argument_list; 116, 117; 117, identifier:candidate; 118, if_statement; 118, 119; 118, 166; 119, boolean_operator:and; 119, 120; 119, 158; 119, 159; 120, boolean_operator:and; 120, 121; 120, 139; 120, 140; 121, comparison_operator:<=; 121, 122; 121, 126; 122, call; 122, 123; 122, 124; 123, identifier:set; 124, argument_list; 124, 125; 125, identifier:added_symbols; 126, call; 126, 127; 126, 128; 127, identifier:set; 128, argument_list; 128, 129; 129, binary_operator:+; 129, 130; 129, 138; 130, call; 130, 131; 130, 132; 131, identifier:list; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:references; 136, identifier:keys; 137, argument_list; 138, identifier:_symbols; 139, line_continuation:\; 140, comparison_operator:<=; 140, 141; 140, 154; 141, call; 141, 142; 141, 143; 142, identifier:set; 143, argument_list; 143, 144; 144, binary_operator:+; 144, 145; 144, 153; 145, call; 145, 146; 145, 147; 146, identifier:list; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:references; 151, identifier:keys; 152, argument_list; 153, identifier:_symbols; 154, call; 154, 155; 154, 156; 155, identifier:set; 156, argument_list; 156, 157; 157, identifier:symbols; 158, line_continuation:\; 159, comparison_operator:not; 159, 160; 159, 161; 160, identifier:candidate; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:references; 164, identifier:values; 165, argument_list; 166, block; 166, 167; 166, 173; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, subscript; 169, 170; 169, 171; 170, identifier:references; 171, identifier:symbol; 172, identifier:candidate; 173, break_statement; 174, else_clause; 174, 175; 175, block; 175, 176; 176, raise_statement; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:UserWarning; 179, argument_list; 179, 180; 180, call; 180, 181; 180, 190; 181, attribute; 181, 182; 181, 189; 182, parenthesized_expression; 182, 183; 183, concatenated_string; 183, 184; 183, 185; 183, 186; 183, 187; 183, 188; 184, string:"No candidate satisfied {symbol}. Add more candidates\n"; 185, string:" Symbols {symbols}\n"; 186, string:" _Symbols {_symbols}\n"; 187, string:" References {references}\n"; 188, string:" Candidates {candidates}\n"; 189, identifier:format; 190, argument_list; 190, 191; 190, 194; 190, 197; 190, 200; 190, 203; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:symbol; 193, identifier:symbol; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:symbols; 196, identifier:symbols; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:_symbols; 199, identifier:_symbols; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:candidates; 202, identifier:candidates; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:references; 205, call; 205, 206; 205, 207; 206, identifier:list; 207, argument_list; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:references; 211, identifier:keys; 212, argument_list; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:sorted_references; 216, list:[]; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:references; 220, call; 220, 221; 220, 222; 221, identifier:list; 222, argument_list; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:references; 226, identifier:items; 227, argument_list; 228, return_statement; 228, 229; 229, identifier:references | def construct_reference_system(
symbols,
candidates=None,
options=None,
):
if hasattr(options, 'no_hydrogen') and options.no_hydrogen:
add_hydrogen = False
else:
add_hydrogen = True
references = {}
sorted_candidates = [
'H2',
'H2O',
'NH3',
'N2',
'CH4',
'CO',
'H2S',
'HCl',
'O2']
if candidates is None:
candidates = sorted_candidates
else:
odd_candidates = [c for c in candidates if c not in sorted_candidates]
candidates = [c for c in sorted_candidates if c in candidates] \
+ odd_candidates
added_symbols = []
for symbol in symbols:
added_symbols.append(symbol)
for candidate in candidates:
_symbols = ase.symbols.string2symbols(candidate)
if set(added_symbols) <= set(list(references.keys()) + _symbols) \
and set(list(references.keys()) + _symbols) <= set(symbols) \
and candidate not in references.values():
references[symbol] = candidate
break
else:
raise UserWarning((
"No candidate satisfied {symbol}. Add more candidates\n"
" Symbols {symbols}\n"
" _Symbols {_symbols}\n"
" References {references}\n"
" Candidates {candidates}\n"
).format(
symbol=symbol,
symbols=symbols,
_symbols=_symbols,
candidates=candidates,
references=list(references.keys()),
))
sorted_references = []
references = list(references.items())
return references |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:gen_triplets_master; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:wv_master; 5, default_parameter; 5, 6; 5, 7; 6, identifier:geometry; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:debugplot; 10, integer:0; 11, block; 11, 12; 11, 18; 11, 24; 11, 66; 11, 79; 11, 87; 11, 94; 11, 133; 11, 142; 11, 186; 11, 195; 11, 201; 11, 211; 11, 365; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:nlines_master; 15, attribute; 15, 16; 15, 17; 16, identifier:wv_master; 17, identifier:size; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:wv_previous; 21, subscript; 21, 22; 21, 23; 22, identifier:wv_master; 23, integer:0; 24, for_statement; 24, 25; 24, 26; 24, 31; 25, identifier:i; 26, call; 26, 27; 26, 28; 27, identifier:range; 28, argument_list; 28, 29; 28, 30; 29, integer:1; 30, identifier:nlines_master; 31, block; 31, 32; 31, 60; 32, if_statement; 32, 33; 32, 38; 33, comparison_operator:>=; 33, 34; 33, 35; 34, identifier:wv_previous; 35, subscript; 35, 36; 35, 37; 36, identifier:wv_master; 37, identifier:i; 38, block; 38, 39; 39, raise_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:ValueError; 42, argument_list; 42, 43; 43, binary_operator:+; 43, 44; 43, 59; 44, binary_operator:+; 44, 45; 44, 53; 45, binary_operator:+; 45, 46; 45, 52; 46, binary_operator:+; 46, 47; 46, 48; 47, string:'Wavelengths:\n--> '; 48, call; 48, 49; 48, 50; 49, identifier:str; 50, argument_list; 50, 51; 51, identifier:wv_previous; 52, string:'\n--> '; 53, call; 53, 54; 53, 55; 54, identifier:str; 55, argument_list; 55, 56; 56, subscript; 56, 57; 56, 58; 57, identifier:wv_master; 58, identifier:i; 59, string:'\nin master table are duplicated or not sorted'; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:wv_previous; 63, subscript; 63, 64; 63, 65; 64, identifier:wv_master; 65, identifier:i; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:iter_comb_triplets; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:itertools; 72, identifier:combinations; 73, argument_list; 73, 74; 73, 78; 74, call; 74, 75; 74, 76; 75, identifier:range; 76, argument_list; 76, 77; 77, identifier:nlines_master; 78, integer:3; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:triplets_master_list; 82, list_comprehension; 82, 83; 82, 84; 83, identifier:val; 84, for_in_clause; 84, 85; 84, 86; 85, identifier:val; 86, identifier:iter_comb_triplets; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:ntriplets_master; 90, call; 90, 91; 90, 92; 91, identifier:len; 92, argument_list; 92, 93; 93, identifier:triplets_master_list; 94, if_statement; 94, 95; 94, 105; 94, 126; 95, comparison_operator:==; 95, 96; 95, 97; 96, identifier:ntriplets_master; 97, call; 97, 98; 97, 99; 98, identifier:comb; 99, argument_list; 99, 100; 99, 101; 99, 102; 100, identifier:nlines_master; 101, integer:3; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:exact; 104, True; 105, block; 105, 106; 106, if_statement; 106, 107; 106, 113; 107, comparison_operator:>=; 107, 108; 107, 112; 108, call; 108, 109; 108, 110; 109, identifier:abs; 110, argument_list; 110, 111; 111, identifier:debugplot; 112, integer:10; 113, block; 113, 114; 113, 120; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:print; 117, argument_list; 117, 118; 117, 119; 118, string:'>>> Total number of lines in master table:'; 119, identifier:nlines_master; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:print; 123, argument_list; 123, 124; 123, 125; 124, string:'>>> Number of triplets in master table...:'; 125, identifier:ntriplets_master; 126, else_clause; 126, 127; 127, block; 127, 128; 128, raise_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:ValueError; 131, argument_list; 131, 132; 132, string:'Invalid number of combinations'; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:ratios_master; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:np; 139, identifier:zeros; 140, argument_list; 140, 141; 141, identifier:ntriplets_master; 142, for_statement; 142, 143; 142, 146; 142, 150; 143, pattern_list; 143, 144; 143, 145; 144, identifier:index; 145, identifier:value; 146, call; 146, 147; 146, 148; 147, identifier:enumerate; 148, argument_list; 148, 149; 149, identifier:triplets_master_list; 150, block; 150, 151; 150, 158; 150, 168; 150, 178; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 157; 153, pattern_list; 153, 154; 153, 155; 153, 156; 154, identifier:i1; 155, identifier:i2; 156, identifier:i3; 157, identifier:value; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:delta1; 161, binary_operator:-; 161, 162; 161, 165; 162, subscript; 162, 163; 162, 164; 163, identifier:wv_master; 164, identifier:i2; 165, subscript; 165, 166; 165, 167; 166, identifier:wv_master; 167, identifier:i1; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:delta2; 171, binary_operator:-; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:wv_master; 174, identifier:i3; 175, subscript; 175, 176; 175, 177; 176, identifier:wv_master; 177, identifier:i1; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:ratios_master; 182, identifier:index; 183, binary_operator:/; 183, 184; 183, 185; 184, identifier:delta1; 185, identifier:delta2; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:isort_ratios_master; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:np; 192, identifier:argsort; 193, argument_list; 193, 194; 194, identifier:ratios_master; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:ratios_master_sorted; 198, subscript; 198, 199; 198, 200; 199, identifier:ratios_master; 200, identifier:isort_ratios_master; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:triplets_master_sorted_list; 204, list_comprehension; 204, 205; 204, 208; 205, subscript; 205, 206; 205, 207; 206, identifier:triplets_master_list; 207, identifier:i; 208, for_in_clause; 208, 209; 208, 210; 209, identifier:i; 210, identifier:isort_ratios_master; 211, if_statement; 211, 212; 211, 220; 212, comparison_operator:in; 212, 213; 212, 217; 213, call; 213, 214; 213, 215; 214, identifier:abs; 215, argument_list; 215, 216; 216, identifier:debugplot; 217, list:[21, 22]; 217, 218; 217, 219; 218, integer:21; 219, integer:22; 220, block; 220, 221; 220, 232; 220, 246; 220, 254; 220, 262; 220, 271; 220, 284; 220, 302; 220, 316; 220, 323; 220, 330; 220, 349; 220, 354; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:bins_in; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:np; 227, identifier:linspace; 228, argument_list; 228, 229; 228, 230; 228, 231; 229, float:0.0; 230, float:1.0; 231, integer:41; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 237; 234, pattern_list; 234, 235; 234, 236; 235, identifier:hist; 236, identifier:bins_out; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:np; 240, identifier:histogram; 241, argument_list; 241, 242; 241, 243; 242, identifier:ratios_master; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:bins; 245, identifier:bins_in; 246, import_from_statement; 246, 247; 246, 252; 247, dotted_name; 247, 248; 247, 249; 247, 250; 247, 251; 248, identifier:numina; 249, identifier:array; 250, identifier:display; 251, identifier:matplotlib_qt; 252, dotted_name; 252, 253; 253, identifier:plt; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:fig; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:plt; 260, identifier:figure; 261, argument_list; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:ax; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:fig; 268, identifier:add_subplot; 269, argument_list; 269, 270; 270, integer:111; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:width_hist; 274, binary_operator:*; 274, 275; 274, 276; 275, float:0.8; 276, parenthesized_expression; 276, 277; 277, binary_operator:-; 277, 278; 277, 281; 278, subscript; 278, 279; 278, 280; 279, identifier:bins_out; 280, integer:1; 281, subscript; 281, 282; 281, 283; 282, identifier:bins_out; 283, integer:0; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:center; 287, binary_operator:/; 287, 288; 287, 301; 288, parenthesized_expression; 288, 289; 289, binary_operator:+; 289, 290; 289, 296; 290, subscript; 290, 291; 290, 292; 291, identifier:bins_out; 292, slice; 292, 293; 292, 294; 293, colon; 294, unary_operator:-; 294, 295; 295, integer:1; 296, subscript; 296, 297; 296, 298; 297, identifier:bins_out; 298, slice; 298, 299; 298, 300; 299, integer:1; 300, colon; 301, integer:2; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:ax; 306, identifier:bar; 307, argument_list; 307, 308; 307, 309; 307, 310; 307, 313; 308, identifier:center; 309, identifier:hist; 310, keyword_argument; 310, 311; 310, 312; 311, identifier:align; 312, string:'center'; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:width; 315, identifier:width_hist; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:ax; 320, identifier:set_xlabel; 321, argument_list; 321, 322; 322, string:'distance ratio in each triplet'; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:ax; 327, identifier:set_ylabel; 328, argument_list; 328, 329; 329, string:'Number of triplets'; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:ax; 334, identifier:set_title; 335, argument_list; 335, 336; 336, binary_operator:+; 336, 337; 336, 345; 337, binary_operator:+; 337, 338; 337, 344; 338, binary_operator:+; 338, 339; 338, 340; 339, string:"Number of lines/triplets: "; 340, call; 340, 341; 340, 342; 341, identifier:str; 342, argument_list; 342, 343; 343, identifier:nlines_master; 344, string:"/"; 345, call; 345, 346; 345, 347; 346, identifier:str; 347, argument_list; 347, 348; 348, identifier:ntriplets_master; 349, expression_statement; 349, 350; 350, call; 350, 351; 350, 352; 351, identifier:set_window_geometry; 352, argument_list; 352, 353; 353, identifier:geometry; 354, expression_statement; 354, 355; 355, call; 355, 356; 355, 357; 356, identifier:pause_debugplot; 357, argument_list; 357, 358; 357, 359; 357, 362; 358, identifier:debugplot; 359, keyword_argument; 359, 360; 359, 361; 360, identifier:pltshow; 361, True; 362, keyword_argument; 362, 363; 362, 364; 363, identifier:tight_layout; 364, True; 365, return_statement; 365, 366; 366, expression_list; 366, 367; 366, 368; 366, 369; 367, identifier:ntriplets_master; 368, identifier:ratios_master_sorted; 369, identifier:triplets_master_sorted_list | def gen_triplets_master(wv_master, geometry=None, debugplot=0):
nlines_master = wv_master.size
wv_previous = wv_master[0]
for i in range(1, nlines_master):
if wv_previous >= wv_master[i]:
raise ValueError('Wavelengths:\n--> ' +
str(wv_previous) + '\n--> ' + str(wv_master[i]) +
'\nin master table are duplicated or not sorted')
wv_previous = wv_master[i]
iter_comb_triplets = itertools.combinations(range(nlines_master), 3)
triplets_master_list = [val for val in iter_comb_triplets]
ntriplets_master = len(triplets_master_list)
if ntriplets_master == comb(nlines_master, 3, exact=True):
if abs(debugplot) >= 10:
print('>>> Total number of lines in master table:',
nlines_master)
print('>>> Number of triplets in master table...:',
ntriplets_master)
else:
raise ValueError('Invalid number of combinations')
ratios_master = np.zeros(ntriplets_master)
for index, value in enumerate(triplets_master_list):
i1, i2, i3 = value
delta1 = wv_master[i2] - wv_master[i1]
delta2 = wv_master[i3] - wv_master[i1]
ratios_master[index] = delta1 / delta2
isort_ratios_master = np.argsort(ratios_master)
ratios_master_sorted = ratios_master[isort_ratios_master]
triplets_master_sorted_list = [triplets_master_list[i]
for i in isort_ratios_master]
if abs(debugplot) in [21, 22]:
bins_in = np.linspace(0.0, 1.0, 41)
hist, bins_out = np.histogram(ratios_master, bins=bins_in)
from numina.array.display.matplotlib_qt import plt
fig = plt.figure()
ax = fig.add_subplot(111)
width_hist = 0.8*(bins_out[1]-bins_out[0])
center = (bins_out[:-1]+bins_out[1:])/2
ax.bar(center, hist, align='center', width=width_hist)
ax.set_xlabel('distance ratio in each triplet')
ax.set_ylabel('Number of triplets')
ax.set_title("Number of lines/triplets: " +
str(nlines_master) + "/" + str(ntriplets_master))
set_window_geometry(geometry)
pause_debugplot(debugplot, pltshow=True, tight_layout=True)
return ntriplets_master, ratios_master_sorted, triplets_master_sorted_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:match_wv_arrays; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:wv_master; 5, identifier:wv_expected_all_peaks; 6, identifier:delta_wv_max; 7, block; 7, 8; 7, 17; 7, 29; 7, 41; 7, 47; 7, 343; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:wv_verified_all_peaks; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:np; 14, identifier:zeros_like; 15, argument_list; 15, 16; 16, identifier:wv_expected_all_peaks; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:wv_unused; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:np; 23, identifier:ones_like; 24, argument_list; 24, 25; 24, 26; 25, identifier:wv_expected_all_peaks; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:dtype; 28, identifier:bool; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:minimum_delta_wv; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:np; 35, identifier:ones_like; 36, argument_list; 36, 37; 36, 38; 37, identifier:wv_expected_all_peaks; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:dtype; 40, identifier:float; 41, expression_statement; 41, 42; 42, augmented_assignment:*=; 42, 43; 42, 44; 43, identifier:minimum_delta_wv; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:infty; 47, for_statement; 47, 48; 47, 49; 47, 56; 48, identifier:i; 49, call; 49, 50; 49, 51; 50, identifier:range; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, identifier:wv_master; 56, block; 56, 57; 56, 69; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:j; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:np; 63, identifier:searchsorted; 64, argument_list; 64, 65; 64, 66; 65, identifier:wv_expected_all_peaks; 66, subscript; 66, 67; 66, 68; 67, identifier:wv_master; 68, identifier:i; 69, if_statement; 69, 70; 69, 73; 69, 140; 69, 214; 70, comparison_operator:==; 70, 71; 70, 72; 71, identifier:j; 72, integer:0; 73, block; 73, 74; 73, 87; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:delta_wv; 77, call; 77, 78; 77, 79; 78, identifier:abs; 79, argument_list; 79, 80; 80, binary_operator:-; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:wv_master; 83, identifier:i; 84, subscript; 84, 85; 84, 86; 85, identifier:wv_expected_all_peaks; 86, identifier:j; 87, if_statement; 87, 88; 87, 91; 88, comparison_operator:<; 88, 89; 88, 90; 89, identifier:delta_wv; 90, identifier:delta_wv_max; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 96; 92, 117; 93, subscript; 93, 94; 93, 95; 94, identifier:wv_unused; 95, identifier:j; 96, block; 96, 97; 96, 105; 96, 111; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:wv_verified_all_peaks; 101, identifier:j; 102, subscript; 102, 103; 102, 104; 103, identifier:wv_master; 104, identifier:i; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:wv_unused; 109, identifier:j; 110, False; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:minimum_delta_wv; 115, identifier:j; 116, identifier:delta_wv; 117, else_clause; 117, 118; 118, block; 118, 119; 119, if_statement; 119, 120; 119, 125; 120, comparison_operator:<; 120, 121; 120, 122; 121, identifier:delta_wv; 122, subscript; 122, 123; 122, 124; 123, identifier:minimum_delta_wv; 124, identifier:j; 125, block; 125, 126; 125, 134; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:wv_verified_all_peaks; 130, identifier:j; 131, subscript; 131, 132; 131, 133; 132, identifier:wv_master; 133, identifier:i; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, subscript; 136, 137; 136, 138; 137, identifier:minimum_delta_wv; 138, identifier:j; 139, identifier:delta_wv; 140, elif_clause; 140, 141; 140, 147; 141, comparison_operator:==; 141, 142; 141, 143; 142, identifier:j; 143, call; 143, 144; 143, 145; 144, identifier:len; 145, argument_list; 145, 146; 146, identifier:wv_expected_all_peaks; 147, block; 147, 148; 147, 163; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:delta_wv; 151, call; 151, 152; 151, 153; 152, identifier:abs; 153, argument_list; 153, 154; 154, binary_operator:-; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:wv_master; 157, identifier:i; 158, subscript; 158, 159; 158, 160; 159, identifier:wv_expected_all_peaks; 160, binary_operator:-; 160, 161; 160, 162; 161, identifier:j; 162, integer:1; 163, if_statement; 163, 164; 163, 167; 164, comparison_operator:<; 164, 165; 164, 166; 165, identifier:delta_wv; 166, identifier:delta_wv_max; 167, block; 167, 168; 168, if_statement; 168, 169; 168, 174; 168, 193; 169, subscript; 169, 170; 169, 171; 170, identifier:wv_unused; 171, binary_operator:-; 171, 172; 171, 173; 172, identifier:j; 173, integer:1; 174, block; 174, 175; 174, 185; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 182; 177, subscript; 177, 178; 177, 179; 178, identifier:wv_verified_all_peaks; 179, binary_operator:-; 179, 180; 179, 181; 180, identifier:j; 181, integer:1; 182, subscript; 182, 183; 182, 184; 183, identifier:wv_master; 184, identifier:i; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 192; 187, subscript; 187, 188; 187, 189; 188, identifier:wv_unused; 189, binary_operator:-; 189, 190; 189, 191; 190, identifier:j; 191, integer:1; 192, False; 193, else_clause; 193, 194; 194, block; 194, 195; 195, if_statement; 195, 196; 195, 203; 196, comparison_operator:<; 196, 197; 196, 198; 197, identifier:delta_wv; 198, subscript; 198, 199; 198, 200; 199, identifier:minimum_delta_wv; 200, binary_operator:-; 200, 201; 200, 202; 201, identifier:j; 202, integer:1; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 211; 206, subscript; 206, 207; 206, 208; 207, identifier:wv_verified_all_peaks; 208, binary_operator:-; 208, 209; 208, 210; 209, identifier:j; 210, integer:1; 211, subscript; 211, 212; 211, 213; 212, identifier:wv_master; 213, identifier:i; 214, else_clause; 214, 215; 215, block; 215, 216; 215, 231; 215, 244; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:delta_wv1; 219, call; 219, 220; 219, 221; 220, identifier:abs; 221, argument_list; 221, 222; 222, binary_operator:-; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:wv_master; 225, identifier:i; 226, subscript; 226, 227; 226, 228; 227, identifier:wv_expected_all_peaks; 228, binary_operator:-; 228, 229; 228, 230; 229, identifier:j; 230, integer:1; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:delta_wv2; 234, call; 234, 235; 234, 236; 235, identifier:abs; 236, argument_list; 236, 237; 237, binary_operator:-; 237, 238; 237, 241; 238, subscript; 238, 239; 238, 240; 239, identifier:wv_master; 240, identifier:i; 241, subscript; 241, 242; 241, 243; 242, identifier:wv_expected_all_peaks; 243, identifier:j; 244, if_statement; 244, 245; 244, 248; 244, 300; 245, comparison_operator:<; 245, 246; 245, 247; 246, identifier:delta_wv1; 247, identifier:delta_wv2; 248, block; 248, 249; 249, if_statement; 249, 250; 249, 253; 250, comparison_operator:<; 250, 251; 250, 252; 251, identifier:delta_wv1; 252, identifier:delta_wv_max; 253, block; 253, 254; 254, if_statement; 254, 255; 254, 260; 254, 279; 255, subscript; 255, 256; 255, 257; 256, identifier:wv_unused; 257, binary_operator:-; 257, 258; 257, 259; 258, identifier:j; 259, integer:1; 260, block; 260, 261; 260, 271; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 268; 263, subscript; 263, 264; 263, 265; 264, identifier:wv_verified_all_peaks; 265, binary_operator:-; 265, 266; 265, 267; 266, identifier:j; 267, integer:1; 268, subscript; 268, 269; 268, 270; 269, identifier:wv_master; 270, identifier:i; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 278; 273, subscript; 273, 274; 273, 275; 274, identifier:wv_unused; 275, binary_operator:-; 275, 276; 275, 277; 276, identifier:j; 277, integer:1; 278, False; 279, else_clause; 279, 280; 280, block; 280, 281; 281, if_statement; 281, 282; 281, 289; 282, comparison_operator:<; 282, 283; 282, 284; 283, identifier:delta_wv1; 284, subscript; 284, 285; 284, 286; 285, identifier:minimum_delta_wv; 286, binary_operator:-; 286, 287; 286, 288; 287, identifier:j; 288, integer:1; 289, block; 289, 290; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 297; 292, subscript; 292, 293; 292, 294; 293, identifier:wv_verified_all_peaks; 294, binary_operator:-; 294, 295; 294, 296; 295, identifier:j; 296, integer:1; 297, subscript; 297, 298; 297, 299; 298, identifier:wv_master; 299, identifier:i; 300, else_clause; 300, 301; 301, block; 301, 302; 302, if_statement; 302, 303; 302, 306; 303, comparison_operator:<; 303, 304; 303, 305; 304, identifier:delta_wv2; 305, identifier:delta_wv_max; 306, block; 306, 307; 307, if_statement; 307, 308; 307, 311; 307, 326; 308, subscript; 308, 309; 308, 310; 309, identifier:wv_unused; 310, identifier:j; 311, block; 311, 312; 311, 320; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 317; 314, subscript; 314, 315; 314, 316; 315, identifier:wv_verified_all_peaks; 316, identifier:j; 317, subscript; 317, 318; 317, 319; 318, identifier:wv_master; 319, identifier:i; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 325; 322, subscript; 322, 323; 322, 324; 323, identifier:wv_unused; 324, identifier:j; 325, False; 326, else_clause; 326, 327; 327, block; 327, 328; 328, if_statement; 328, 329; 328, 334; 329, comparison_operator:<; 329, 330; 329, 331; 330, identifier:delta_wv2; 331, subscript; 331, 332; 331, 333; 332, identifier:minimum_delta_wv; 333, identifier:j; 334, block; 334, 335; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 340; 337, subscript; 337, 338; 337, 339; 338, identifier:wv_verified_all_peaks; 339, identifier:j; 340, subscript; 340, 341; 340, 342; 341, identifier:wv_master; 342, identifier:i; 343, return_statement; 343, 344; 344, identifier:wv_verified_all_peaks | def match_wv_arrays(wv_master, wv_expected_all_peaks, delta_wv_max):
wv_verified_all_peaks = np.zeros_like(wv_expected_all_peaks)
wv_unused = np.ones_like(wv_expected_all_peaks, dtype=bool)
minimum_delta_wv = np.ones_like(wv_expected_all_peaks, dtype=float)
minimum_delta_wv *= np.infty
for i in range(len(wv_master)):
j = np.searchsorted(wv_expected_all_peaks, wv_master[i])
if j == 0:
delta_wv = abs(wv_master[i] - wv_expected_all_peaks[j])
if delta_wv < delta_wv_max:
if wv_unused[j]:
wv_verified_all_peaks[j] = wv_master[i]
wv_unused[j] = False
minimum_delta_wv[j] = delta_wv
else:
if delta_wv < minimum_delta_wv[j]:
wv_verified_all_peaks[j] = wv_master[i]
minimum_delta_wv[j] = delta_wv
elif j == len(wv_expected_all_peaks):
delta_wv = abs(wv_master[i] - wv_expected_all_peaks[j-1])
if delta_wv < delta_wv_max:
if wv_unused[j-1]:
wv_verified_all_peaks[j-1] = wv_master[i]
wv_unused[j-1] = False
else:
if delta_wv < minimum_delta_wv[j-1]:
wv_verified_all_peaks[j-1] = wv_master[i]
else:
delta_wv1 = abs(wv_master[i] - wv_expected_all_peaks[j-1])
delta_wv2 = abs(wv_master[i] - wv_expected_all_peaks[j])
if delta_wv1 < delta_wv2:
if delta_wv1 < delta_wv_max:
if wv_unused[j-1]:
wv_verified_all_peaks[j-1] = wv_master[i]
wv_unused[j-1] = False
else:
if delta_wv1 < minimum_delta_wv[j-1]:
wv_verified_all_peaks[j-1] = wv_master[i]
else:
if delta_wv2 < delta_wv_max:
if wv_unused[j]:
wv_verified_all_peaks[j] = wv_master[i]
wv_unused[j] = False
else:
if delta_wv2 < minimum_delta_wv[j]:
wv_verified_all_peaks[j] = wv_master[i]
return wv_verified_all_peaks |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 41; 2, function_name:add_publication_info; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:year; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:cnum; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:artid; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:page_end; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:page_start; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:journal_issue; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:journal_title; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:journal_volume; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:pubinfo_freetext; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:material; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:parent_record; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:parent_isbn; 40, None; 41, block; 41, 42; 41, 73; 41, 77; 41, 110; 41, 128; 41, 142; 41, 172; 41, 180; 42, if_statement; 42, 43; 42, 59; 43, boolean_operator:and; 43, 44; 43, 45; 44, identifier:journal_title; 45, call; 45, 46; 45, 47; 46, identifier:all; 47, generator_expression; 47, 48; 47, 50; 48, not_operator; 48, 49; 49, identifier:field; 50, for_in_clause; 50, 51; 50, 52; 51, identifier:field; 52, tuple; 52, 53; 52, 54; 52, 55; 52, 56; 52, 57; 52, 58; 53, identifier:cnum; 54, identifier:artid; 55, identifier:journal_issue; 56, identifier:journal_volume; 57, identifier:page_start; 58, identifier:page_end; 59, block; 59, 60; 59, 72; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:add_public_note; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, string:'Submitted to {}'; 69, identifier:format; 70, argument_list; 70, 71; 71, identifier:journal_title; 72, return_statement; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:publication_item; 76, dictionary; 77, for_statement; 77, 78; 77, 79; 77, 90; 78, identifier:key; 79, tuple; 79, 80; 79, 81; 79, 82; 79, 83; 79, 84; 79, 85; 79, 86; 79, 87; 79, 88; 79, 89; 80, string:'cnum'; 81, string:'artid'; 82, string:'page_end'; 83, string:'page_start'; 84, string:'journal_issue'; 85, string:'journal_title'; 86, string:'journal_volume'; 87, string:'year'; 88, string:'pubinfo_freetext'; 89, string:'material'; 90, block; 90, 91; 91, if_statement; 91, 92; 91, 99; 92, comparison_operator:is; 92, 93; 92, 98; 93, subscript; 93, 94; 93, 97; 94, call; 94, 95; 94, 96; 95, identifier:locals; 96, argument_list; 97, identifier:key; 98, None; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:publication_item; 104, identifier:key; 105, subscript; 105, 106; 105, 109; 106, call; 106, 107; 106, 108; 107, identifier:locals; 108, argument_list; 109, identifier:key; 110, if_statement; 110, 111; 110, 114; 111, comparison_operator:is; 111, 112; 111, 113; 112, identifier:parent_record; 113, None; 114, block; 114, 115; 114, 122; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:parent_item; 118, dictionary; 118, 119; 119, pair; 119, 120; 119, 121; 120, string:'$ref'; 121, identifier:parent_record; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:publication_item; 126, string:'parent_record'; 127, identifier:parent_item; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:is; 129, 130; 129, 131; 130, identifier:parent_isbn; 131, None; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:publication_item; 137, string:'parent_isbn'; 138, call; 138, 139; 138, 140; 139, identifier:normalize_isbn; 140, argument_list; 140, 141; 141, identifier:parent_isbn; 142, if_statement; 142, 143; 142, 146; 143, boolean_operator:and; 143, 144; 143, 145; 144, identifier:page_start; 145, identifier:page_end; 146, block; 146, 147; 147, try_statement; 147, 148; 147, 166; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:add_number_of_pages; 154, argument_list; 154, 155; 155, binary_operator:+; 155, 156; 155, 165; 156, binary_operator:-; 156, 157; 156, 161; 157, call; 157, 158; 157, 159; 158, identifier:int; 159, argument_list; 159, 160; 160, identifier:page_end; 161, call; 161, 162; 161, 163; 162, identifier:int; 163, argument_list; 163, 164; 164, identifier:page_start; 165, integer:1; 166, except_clause; 166, 167; 166, 170; 167, tuple; 167, 168; 167, 169; 168, identifier:TypeError; 169, identifier:ValueError; 170, block; 170, 171; 171, pass_statement; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:_append_to; 177, argument_list; 177, 178; 177, 179; 178, string:'publication_info'; 179, identifier:publication_item; 180, if_statement; 180, 181; 180, 189; 181, call; 181, 182; 181, 183; 182, identifier:is_citeable; 183, argument_list; 183, 184; 184, subscript; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:record; 188, string:'publication_info'; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:set_citeable; 195, argument_list; 195, 196; 196, True | def add_publication_info(
self,
year=None,
cnum=None,
artid=None,
page_end=None,
page_start=None,
journal_issue=None,
journal_title=None,
journal_volume=None,
pubinfo_freetext=None,
material=None,
parent_record=None,
parent_isbn=None,
):
if journal_title and all(
not field for field in (cnum, artid, journal_issue,
journal_volume, page_start, page_end)):
self.add_public_note('Submitted to {}'.format(journal_title))
return
publication_item = {}
for key in ('cnum', 'artid', 'page_end', 'page_start',
'journal_issue', 'journal_title',
'journal_volume', 'year', 'pubinfo_freetext', 'material'):
if locals()[key] is not None:
publication_item[key] = locals()[key]
if parent_record is not None:
parent_item = {'$ref': parent_record}
publication_item['parent_record'] = parent_item
if parent_isbn is not None:
publication_item['parent_isbn'] = normalize_isbn(parent_isbn)
if page_start and page_end:
try:
self.add_number_of_pages(
int(page_end) - int(page_start) + 1
)
except (TypeError, ValueError):
pass
self._append_to('publication_info', publication_item)
if is_citeable(self.record['publication_info']):
self.set_citeable(True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:compute_operation; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 4, identifier:file1; 5, identifier:file2; 6, identifier:operation; 7, identifier:output; 8, identifier:display; 9, identifier:args_z1z2; 10, identifier:args_bbox; 11, identifier:args_keystitle; 12, identifier:args_geometry; 13, block; 13, 14; 13, 50; 13, 56; 13, 62; 13, 89; 13, 125; 13, 131; 13, 137; 13, 164; 13, 174; 13, 184; 13, 240; 13, 257; 13, 267; 14, with_statement; 14, 15; 14, 26; 15, with_clause; 15, 16; 16, with_item; 16, 17; 17, as_pattern; 17, 18; 17, 24; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:fits; 21, identifier:open; 22, argument_list; 22, 23; 23, identifier:file1; 24, as_pattern_target; 24, 25; 25, identifier:hdulist; 26, block; 26, 27; 26, 35; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:image_header1; 30, attribute; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:hdulist; 33, integer:0; 34, identifier:header; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:image1; 38, call; 38, 39; 38, 46; 39, attribute; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:hdulist; 43, integer:0; 44, identifier:data; 45, identifier:astype; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:np; 49, identifier:float; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:naxis1; 53, subscript; 53, 54; 53, 55; 54, identifier:image_header1; 55, string:'naxis1'; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:naxis2; 59, subscript; 59, 60; 59, 61; 60, identifier:image_header1; 61, string:'naxis2'; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:==; 63, 64; 63, 65; 64, identifier:display; 65, string:'all'; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:ximshow_file; 70, argument_list; 70, 71; 70, 74; 70, 77; 70, 80; 70, 83; 70, 86; 71, attribute; 71, 72; 71, 73; 72, identifier:file1; 73, identifier:name; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:args_z1z2; 76, identifier:args_z1z2; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:args_bbox; 79, identifier:args_bbox; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:args_keystitle; 82, identifier:args_keystitle; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:args_geometry; 85, identifier:args_geometry; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:debugplot; 88, integer:12; 89, with_statement; 89, 90; 89, 101; 90, with_clause; 90, 91; 91, with_item; 91, 92; 92, as_pattern; 92, 93; 92, 99; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:fits; 96, identifier:open; 97, argument_list; 97, 98; 98, identifier:file2; 99, as_pattern_target; 99, 100; 100, identifier:hdulist; 101, block; 101, 102; 101, 110; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:image_header2; 105, attribute; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:hdulist; 108, integer:0; 109, identifier:header; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:image2; 113, call; 113, 114; 113, 121; 114, attribute; 114, 115; 114, 120; 115, attribute; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:hdulist; 118, integer:0; 119, identifier:data; 120, identifier:astype; 121, argument_list; 121, 122; 122, attribute; 122, 123; 122, 124; 123, identifier:np; 124, identifier:float; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:naxis1_; 128, subscript; 128, 129; 128, 130; 129, identifier:image_header2; 130, string:'naxis1'; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:naxis2_; 134, subscript; 134, 135; 134, 136; 135, identifier:image_header2; 136, string:'naxis2'; 137, if_statement; 137, 138; 137, 141; 138, comparison_operator:==; 138, 139; 138, 140; 139, identifier:display; 140, string:'all'; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:ximshow_file; 145, argument_list; 145, 146; 145, 149; 145, 152; 145, 155; 145, 158; 145, 161; 146, attribute; 146, 147; 146, 148; 147, identifier:file2; 148, identifier:name; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:args_z1z2; 151, identifier:args_z1z2; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:args_bbox; 154, identifier:args_bbox; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:args_keystitle; 157, identifier:args_keystitle; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:args_geometry; 160, identifier:args_geometry; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:debugplot; 163, integer:12; 164, if_statement; 164, 165; 164, 168; 165, comparison_operator:!=; 165, 166; 165, 167; 166, identifier:naxis1; 167, identifier:naxis1_; 168, block; 168, 169; 169, raise_statement; 169, 170; 170, call; 170, 171; 170, 172; 171, identifier:ValueError; 172, argument_list; 172, 173; 173, string:"NAXIS1 values are different."; 174, if_statement; 174, 175; 174, 178; 175, comparison_operator:!=; 175, 176; 175, 177; 176, identifier:naxis2; 177, identifier:naxis2_; 178, block; 178, 179; 179, raise_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:ValueError; 182, argument_list; 182, 183; 183, string:"NAXIS2 values are different."; 184, if_statement; 184, 185; 184, 188; 184, 195; 184, 206; 184, 217; 184, 228; 185, comparison_operator:==; 185, 186; 185, 187; 186, identifier:operation; 187, string:"+"; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:solution; 192, binary_operator:+; 192, 193; 192, 194; 193, identifier:image1; 194, identifier:image2; 195, elif_clause; 195, 196; 195, 199; 196, comparison_operator:==; 196, 197; 196, 198; 197, identifier:operation; 198, string:"-"; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:solution; 203, binary_operator:-; 203, 204; 203, 205; 204, identifier:image1; 205, identifier:image2; 206, elif_clause; 206, 207; 206, 210; 207, comparison_operator:==; 207, 208; 207, 209; 208, identifier:operation; 209, string:"*"; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:solution; 214, binary_operator:*; 214, 215; 214, 216; 215, identifier:image1; 216, identifier:image2; 217, elif_clause; 217, 218; 217, 221; 218, comparison_operator:==; 218, 219; 218, 220; 219, identifier:operation; 220, string:"/"; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:solution; 225, binary_operator:/; 225, 226; 225, 227; 226, identifier:image1; 227, identifier:image2; 228, else_clause; 228, 229; 229, block; 229, 230; 230, raise_statement; 230, 231; 231, call; 231, 232; 231, 233; 232, identifier:ValueError; 233, argument_list; 233, 234; 234, binary_operator:+; 234, 235; 234, 236; 235, string:"Unexpected operation="; 236, call; 236, 237; 236, 238; 237, identifier:str; 238, argument_list; 238, 239; 239, identifier:operation; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:hdu; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:fits; 246, identifier:PrimaryHDU; 247, argument_list; 247, 248; 247, 256; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:solution; 251, identifier:astype; 252, argument_list; 252, 253; 253, attribute; 253, 254; 253, 255; 254, identifier:np; 255, identifier:float; 256, identifier:image_header1; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:hdu; 261, identifier:writeto; 262, argument_list; 262, 263; 262, 264; 263, identifier:output; 264, keyword_argument; 264, 265; 264, 266; 265, identifier:overwrite; 266, True; 267, if_statement; 267, 268; 267, 273; 268, comparison_operator:in; 268, 269; 268, 270; 269, identifier:display; 270, list:['all', 'result']; 270, 271; 270, 272; 271, string:'all'; 272, string:'result'; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 277; 276, identifier:ximshow_file; 277, argument_list; 277, 278; 277, 281; 277, 284; 277, 287; 277, 290; 277, 293; 278, attribute; 278, 279; 278, 280; 279, identifier:output; 280, identifier:name; 281, keyword_argument; 281, 282; 281, 283; 282, identifier:args_z1z2; 283, identifier:args_z1z2; 284, keyword_argument; 284, 285; 284, 286; 285, identifier:args_bbox; 286, identifier:args_bbox; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:args_keystitle; 289, identifier:args_keystitle; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:args_geometry; 292, identifier:args_geometry; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:debugplot; 295, integer:12 | def compute_operation(file1, file2, operation, output, display,
args_z1z2, args_bbox, args_keystitle, args_geometry):
with fits.open(file1) as hdulist:
image_header1 = hdulist[0].header
image1 = hdulist[0].data.astype(np.float)
naxis1 = image_header1['naxis1']
naxis2 = image_header1['naxis2']
if display == 'all':
ximshow_file(file1.name,
args_z1z2=args_z1z2, args_bbox=args_bbox,
args_keystitle=args_keystitle,
args_geometry=args_geometry,
debugplot=12)
with fits.open(file2) as hdulist:
image_header2 = hdulist[0].header
image2 = hdulist[0].data.astype(np.float)
naxis1_ = image_header2['naxis1']
naxis2_ = image_header2['naxis2']
if display == 'all':
ximshow_file(file2.name,
args_z1z2=args_z1z2, args_bbox=args_bbox,
args_keystitle=args_keystitle,
args_geometry=args_geometry,
debugplot=12)
if naxis1 != naxis1_:
raise ValueError("NAXIS1 values are different.")
if naxis2 != naxis2_:
raise ValueError("NAXIS2 values are different.")
if operation == "+":
solution = image1 + image2
elif operation == "-":
solution = image1 - image2
elif operation == "*":
solution = image1 * image2
elif operation == "/":
solution = image1 / image2
else:
raise ValueError("Unexpected operation=" + str(operation))
hdu = fits.PrimaryHDU(solution.astype(np.float), image_header1)
hdu.writeto(output, overwrite=True)
if display in ['all', 'result']:
ximshow_file(output.name,
args_z1z2=args_z1z2, args_bbox=args_bbox,
args_keystitle=args_keystitle,
args_geometry=args_geometry,
debugplot=12) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:summary; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:x; 5, default_parameter; 5, 6; 5, 7; 6, identifier:rm_nan; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:debug; 10, False; 11, block; 11, 12; 11, 64; 11, 85; 11, 104; 11, 111; 11, 117; 11, 237; 11, 353; 12, if_statement; 12, 13; 12, 21; 12, 31; 13, comparison_operator:is; 13, 14; 13, 18; 14, call; 14, 15; 14, 16; 15, identifier:type; 16, argument_list; 16, 17; 17, identifier:x; 18, attribute; 18, 19; 18, 20; 19, identifier:np; 20, identifier:ndarray; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:xx; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:np; 28, identifier:copy; 29, argument_list; 29, 30; 30, identifier:x; 31, else_clause; 31, 32; 32, block; 32, 33; 33, if_statement; 33, 34; 33, 40; 33, 50; 34, comparison_operator:is; 34, 35; 34, 39; 35, call; 35, 36; 35, 37; 36, identifier:type; 37, argument_list; 37, 38; 38, identifier:x; 39, identifier:list; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:xx; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:np; 47, identifier:array; 48, argument_list; 48, 49; 49, identifier:x; 50, else_clause; 50, 51; 51, block; 51, 52; 52, raise_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:ValueError; 55, argument_list; 55, 56; 56, binary_operator:+; 56, 57; 56, 63; 57, binary_operator:+; 57, 58; 57, 59; 58, string:'x='; 59, call; 59, 60; 59, 61; 60, identifier:str; 61, argument_list; 61, 62; 62, identifier:x; 63, string:' must be a numpy.ndarray'; 64, if_statement; 64, 65; 64, 70; 65, comparison_operator:is; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:xx; 68, identifier:ndim; 69, integer:1; 70, block; 70, 71; 71, raise_statement; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:ValueError; 74, argument_list; 74, 75; 75, binary_operator:+; 75, 76; 75, 84; 76, binary_operator:+; 76, 77; 76, 78; 77, string:'xx.dim='; 78, call; 78, 79; 78, 80; 79, identifier:str; 80, argument_list; 80, 81; 81, attribute; 81, 82; 81, 83; 82, identifier:xx; 83, identifier:ndim; 84, string:' must be 1'; 85, if_statement; 85, 86; 85, 87; 86, identifier:rm_nan; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:xx; 91, subscript; 91, 92; 91, 93; 92, identifier:xx; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:np; 96, identifier:logical_not; 97, argument_list; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:np; 101, identifier:isnan; 102, argument_list; 102, 103; 103, identifier:xx; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:npoints; 107, call; 107, 108; 107, 109; 108, identifier:len; 109, argument_list; 109, 110; 110, identifier:xx; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:ok; 114, comparison_operator:>; 114, 115; 114, 116; 115, identifier:npoints; 116, integer:0; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:result; 120, dictionary; 120, 121; 120, 124; 120, 135; 120, 147; 120, 159; 120, 170; 120, 182; 120, 193; 120, 204; 120, 213; 120, 225; 121, pair; 121, 122; 121, 123; 122, string:'npoints'; 123, identifier:npoints; 124, pair; 124, 125; 124, 126; 125, string:'minimum'; 126, conditional_expression:if; 126, 127; 126, 133; 126, 134; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:np; 130, identifier:min; 131, argument_list; 131, 132; 132, identifier:xx; 133, identifier:ok; 134, integer:0; 135, pair; 135, 136; 135, 137; 136, string:'percentile25'; 137, conditional_expression:if; 137, 138; 137, 145; 137, 146; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:np; 141, identifier:percentile; 142, argument_list; 142, 143; 142, 144; 143, identifier:xx; 144, integer:25; 145, identifier:ok; 146, integer:0; 147, pair; 147, 148; 147, 149; 148, string:'median'; 149, conditional_expression:if; 149, 150; 149, 157; 149, 158; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:np; 153, identifier:percentile; 154, argument_list; 154, 155; 154, 156; 155, identifier:xx; 156, integer:50; 157, identifier:ok; 158, integer:0; 159, pair; 159, 160; 159, 161; 160, string:'mean'; 161, conditional_expression:if; 161, 162; 161, 168; 161, 169; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:np; 165, identifier:mean; 166, argument_list; 166, 167; 167, identifier:xx; 168, identifier:ok; 169, integer:0; 170, pair; 170, 171; 170, 172; 171, string:'percentile75'; 172, conditional_expression:if; 172, 173; 172, 180; 172, 181; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:np; 176, identifier:percentile; 177, argument_list; 177, 178; 177, 179; 178, identifier:xx; 179, integer:75; 180, identifier:ok; 181, integer:0; 182, pair; 182, 183; 182, 184; 183, string:'maximum'; 184, conditional_expression:if; 184, 185; 184, 191; 184, 192; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:np; 188, identifier:max; 189, argument_list; 189, 190; 190, identifier:xx; 191, identifier:ok; 192, integer:0; 193, pair; 193, 194; 193, 195; 194, string:'std'; 195, conditional_expression:if; 195, 196; 195, 202; 195, 203; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:np; 199, identifier:std; 200, argument_list; 200, 201; 201, identifier:xx; 202, identifier:ok; 203, integer:0; 204, pair; 204, 205; 204, 206; 205, string:'robust_std'; 206, conditional_expression:if; 206, 207; 206, 211; 206, 212; 207, call; 207, 208; 207, 209; 208, identifier:robust_std; 209, argument_list; 209, 210; 210, identifier:xx; 211, identifier:ok; 212, integer:0; 213, pair; 213, 214; 213, 215; 214, string:'percentile15'; 215, conditional_expression:if; 215, 216; 215, 223; 215, 224; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:np; 219, identifier:percentile; 220, argument_list; 220, 221; 220, 222; 221, identifier:xx; 222, float:15.86553; 223, identifier:ok; 224, integer:0; 225, pair; 225, 226; 225, 227; 226, string:'percentile84'; 227, conditional_expression:if; 227, 228; 227, 235; 227, 236; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:np; 231, identifier:percentile; 232, argument_list; 232, 233; 232, 234; 233, identifier:xx; 234, float:84.13447; 235, identifier:ok; 236, integer:0; 237, if_statement; 237, 238; 237, 239; 238, identifier:debug; 239, block; 239, 240; 239, 245; 239, 250; 239, 255; 239, 263; 239, 271; 239, 279; 239, 287; 239, 295; 239, 303; 239, 311; 239, 316; 239, 324; 239, 332; 239, 340; 239, 348; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 243; 242, identifier:print; 243, argument_list; 243, 244; 244, string:'>>> ========================================'; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:print; 248, argument_list; 248, 249; 249, string:'>>> STATISTICAL SUMMARY:'; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 253; 252, identifier:print; 253, argument_list; 253, 254; 254, string:'>>> ----------------------------------------'; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:print; 258, argument_list; 258, 259; 258, 260; 259, string:'>>> Number of points.........:'; 260, subscript; 260, 261; 260, 262; 261, identifier:result; 262, string:'npoints'; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 266; 265, identifier:print; 266, argument_list; 266, 267; 266, 268; 267, string:'>>> Minimum..................:'; 268, subscript; 268, 269; 268, 270; 269, identifier:result; 270, string:'minimum'; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 274; 273, identifier:print; 274, argument_list; 274, 275; 274, 276; 275, string:'>>> 1st Quartile.............:'; 276, subscript; 276, 277; 276, 278; 277, identifier:result; 278, string:'percentile25'; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 282; 281, identifier:print; 282, argument_list; 282, 283; 282, 284; 283, string:'>>> Median...................:'; 284, subscript; 284, 285; 284, 286; 285, identifier:result; 286, string:'median'; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 290; 289, identifier:print; 290, argument_list; 290, 291; 290, 292; 291, string:'>>> Mean.....................:'; 292, subscript; 292, 293; 292, 294; 293, identifier:result; 294, string:'mean'; 295, expression_statement; 295, 296; 296, call; 296, 297; 296, 298; 297, identifier:print; 298, argument_list; 298, 299; 298, 300; 299, string:'>>> 3rd Quartile.............:'; 300, subscript; 300, 301; 300, 302; 301, identifier:result; 302, string:'percentile75'; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:print; 306, argument_list; 306, 307; 306, 308; 307, string:'>>> Maximum..................:'; 308, subscript; 308, 309; 308, 310; 309, identifier:result; 310, string:'maximum'; 311, expression_statement; 311, 312; 312, call; 312, 313; 312, 314; 313, identifier:print; 314, argument_list; 314, 315; 315, string:'>>> ----------------------------------------'; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 319; 318, identifier:print; 319, argument_list; 319, 320; 319, 321; 320, string:'>>> Standard deviation.......:'; 321, subscript; 321, 322; 321, 323; 322, identifier:result; 323, string:'std'; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 327; 326, identifier:print; 327, argument_list; 327, 328; 327, 329; 328, string:'>>> Robust standard deviation:'; 329, subscript; 329, 330; 329, 331; 330, identifier:result; 331, string:'robust_std'; 332, expression_statement; 332, 333; 333, call; 333, 334; 333, 335; 334, identifier:print; 335, argument_list; 335, 336; 335, 337; 336, string:'>>> 0.1586553 percentile.....:'; 337, subscript; 337, 338; 337, 339; 338, identifier:result; 339, string:'percentile15'; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 343; 342, identifier:print; 343, argument_list; 343, 344; 343, 345; 344, string:'>>> 0.8413447 percentile.....:'; 345, subscript; 345, 346; 345, 347; 346, identifier:result; 347, string:'percentile84'; 348, expression_statement; 348, 349; 349, call; 349, 350; 349, 351; 350, identifier:print; 351, argument_list; 351, 352; 352, string:'>>> ========================================'; 353, return_statement; 353, 354; 354, identifier:result | def summary(x, rm_nan=False, debug=False):
if type(x) is np.ndarray:
xx = np.copy(x)
else:
if type(x) is list:
xx = np.array(x)
else:
raise ValueError('x=' + str(x) + ' must be a numpy.ndarray')
if xx.ndim is not 1:
raise ValueError('xx.dim=' + str(xx.ndim) + ' must be 1')
if rm_nan:
xx = xx[np.logical_not(np.isnan(xx))]
npoints = len(xx)
ok = npoints > 0
result = {
'npoints' : npoints,
'minimum' : np.min(xx) if ok else 0,
'percentile25' : np.percentile(xx, 25) if ok else 0,
'median' : np.percentile(xx, 50) if ok else 0,
'mean' : np.mean(xx) if ok else 0,
'percentile75': np.percentile(xx, 75) if ok else 0,
'maximum' : np.max(xx) if ok else 0,
'std': np.std(xx) if ok else 0,
'robust_std' : robust_std(xx) if ok else 0,
'percentile15': np.percentile(xx, 15.86553) if ok else 0,
'percentile84': np.percentile(xx, 84.13447) if ok else 0
}
if debug:
print('>>> ========================================')
print('>>> STATISTICAL SUMMARY:')
print('>>> ----------------------------------------')
print('>>> Number of points.........:', result['npoints'])
print('>>> Minimum..................:', result['minimum'])
print('>>> 1st Quartile.............:', result['percentile25'])
print('>>> Median...................:', result['median'])
print('>>> Mean.....................:', result['mean'])
print('>>> 3rd Quartile.............:', result['percentile75'])
print('>>> Maximum..................:', result['maximum'])
print('>>> ----------------------------------------')
print('>>> Standard deviation.......:', result['std'])
print('>>> Robust standard deviation:', result['robust_std'])
print('>>> 0.1586553 percentile.....:', result['percentile15'])
print('>>> 0.8413447 percentile.....:', result['percentile84'])
print('>>> ========================================')
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:find_peaks_spectrum; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:sx; 5, identifier:nwinwidth; 6, default_parameter; 6, 7; 6, 8; 7, identifier:threshold; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:debugplot; 11, integer:0; 12, block; 12, 13; 12, 56; 12, 62; 12, 68; 12, 104; 12, 108; 12, 132; 12, 136; 12, 283; 12, 292; 12, 311; 13, if_statement; 13, 14; 13, 22; 13, 35; 14, comparison_operator:is; 14, 15; 14, 19; 15, call; 15, 16; 15, 17; 16, identifier:type; 17, argument_list; 17, 18; 18, identifier:sx; 19, attribute; 19, 20; 19, 21; 20, identifier:np; 21, identifier:ndarray; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:ValueError; 26, argument_list; 26, 27; 27, binary_operator:+; 27, 28; 27, 34; 28, binary_operator:+; 28, 29; 28, 30; 29, string:"sx="; 30, call; 30, 31; 30, 32; 31, identifier:str; 32, argument_list; 32, 33; 33, identifier:sx; 34, string:" must be a numpy.ndarray"; 35, elif_clause; 35, 36; 35, 41; 36, comparison_operator:is; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:sx; 39, identifier:ndim; 40, integer:1; 41, block; 41, 42; 42, raise_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:ValueError; 45, argument_list; 45, 46; 46, binary_operator:+; 46, 47; 46, 55; 47, binary_operator:+; 47, 48; 47, 49; 48, string:"sx.ndim="; 49, call; 49, 50; 49, 51; 50, identifier:str; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:sx; 54, identifier:ndim; 55, string:" must be 1"; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:sx_shape; 59, attribute; 59, 60; 59, 61; 60, identifier:sx; 61, identifier:shape; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:nmed; 65, binary_operator://; 65, 66; 65, 67; 66, identifier:nwinwidth; 67, integer:2; 68, if_statement; 68, 69; 68, 72; 69, comparison_operator:>=; 69, 70; 69, 71; 70, identifier:debugplot; 71, integer:10; 72, block; 72, 73; 72, 79; 72, 85; 72, 91; 72, 97; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:print; 76, argument_list; 76, 77; 76, 78; 77, string:'find_peaks_spectrum> sx shape......:'; 78, identifier:sx_shape; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:print; 82, argument_list; 82, 83; 82, 84; 83, string:'find_peaks_spectrum> nwinwidth.....:'; 84, identifier:nwinwidth; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:print; 88, argument_list; 88, 89; 88, 90; 89, string:'find_peaks_spectrum> nmed..........:'; 90, identifier:nmed; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:print; 94, argument_list; 94, 95; 94, 96; 95, string:'find_peaks_spectrum> data_threshold:'; 96, identifier:threshold; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:print; 100, argument_list; 100, 101; 100, 102; 100, 103; 101, string:'find_peaks_spectrum> the first and last'; 102, identifier:nmed; 103, string:'pixels will be ignored'; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:xpeaks; 107, list:[]; 108, if_statement; 108, 109; 108, 114; 109, comparison_operator:<; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:sx_shape; 112, integer:0; 113, identifier:nwinwidth; 114, block; 114, 115; 114, 121; 114, 127; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:print; 118, argument_list; 118, 119; 118, 120; 119, string:'find_peaks_spectrum> sx shape......:'; 120, identifier:sx_shape; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:print; 124, argument_list; 124, 125; 124, 126; 125, string:'find_peaks_spectrum> nwinwidth.....:'; 126, identifier:nwinwidth; 127, raise_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:ValueError; 130, argument_list; 130, 131; 131, string:'sx.shape < nwinwidth'; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:i; 135, identifier:nmed; 136, while_statement; 136, 137; 136, 144; 137, comparison_operator:<; 137, 138; 137, 139; 138, identifier:i; 139, binary_operator:-; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:sx_shape; 142, integer:0; 143, identifier:nmed; 144, block; 144, 145; 145, if_statement; 145, 146; 145, 151; 145, 277; 146, comparison_operator:>; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:sx; 149, identifier:i; 150, identifier:threshold; 151, block; 151, 152; 151, 156; 151, 160; 151, 164; 151, 203; 151, 255; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:peak_ok; 155, True; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:j; 159, integer:0; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:loop; 163, True; 164, while_statement; 164, 165; 164, 166; 165, identifier:loop; 166, block; 166, 167; 166, 190; 166, 194; 167, if_statement; 167, 168; 167, 185; 168, comparison_operator:>; 168, 169; 168, 176; 169, subscript; 169, 170; 169, 171; 170, identifier:sx; 171, binary_operator:+; 171, 172; 171, 175; 172, binary_operator:-; 172, 173; 172, 174; 173, identifier:i; 174, identifier:nmed; 175, identifier:j; 176, subscript; 176, 177; 176, 178; 177, identifier:sx; 178, binary_operator:+; 178, 179; 178, 184; 179, binary_operator:+; 179, 180; 179, 183; 180, binary_operator:-; 180, 181; 180, 182; 181, identifier:i; 182, identifier:nmed; 183, identifier:j; 184, integer:1; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:peak_ok; 189, False; 190, expression_statement; 190, 191; 191, augmented_assignment:+=; 191, 192; 191, 193; 192, identifier:j; 193, integer:1; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:loop; 197, boolean_operator:and; 197, 198; 197, 202; 198, parenthesized_expression; 198, 199; 199, comparison_operator:<; 199, 200; 199, 201; 200, identifier:j; 201, identifier:nmed; 202, identifier:peak_ok; 203, if_statement; 203, 204; 203, 205; 204, identifier:peak_ok; 205, block; 205, 206; 205, 212; 205, 216; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:j; 209, binary_operator:+; 209, 210; 209, 211; 210, identifier:nmed; 211, integer:1; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:loop; 215, True; 216, while_statement; 216, 217; 216, 218; 217, identifier:loop; 218, block; 218, 219; 218, 242; 218, 246; 219, if_statement; 219, 220; 219, 237; 220, comparison_operator:<; 220, 221; 220, 230; 221, subscript; 221, 222; 221, 223; 222, identifier:sx; 223, binary_operator:-; 223, 224; 223, 229; 224, binary_operator:+; 224, 225; 224, 228; 225, binary_operator:-; 225, 226; 225, 227; 226, identifier:i; 227, identifier:nmed; 228, identifier:j; 229, integer:1; 230, subscript; 230, 231; 230, 232; 231, identifier:sx; 232, binary_operator:+; 232, 233; 232, 236; 233, binary_operator:-; 233, 234; 233, 235; 234, identifier:i; 235, identifier:nmed; 236, identifier:j; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:peak_ok; 241, False; 242, expression_statement; 242, 243; 243, augmented_assignment:+=; 243, 244; 243, 245; 244, identifier:j; 245, integer:1; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:loop; 249, boolean_operator:and; 249, 250; 249, 254; 250, parenthesized_expression; 250, 251; 251, comparison_operator:<; 251, 252; 251, 253; 252, identifier:j; 253, identifier:nwinwidth; 254, identifier:peak_ok; 255, if_statement; 255, 256; 255, 257; 255, 271; 256, identifier:peak_ok; 257, block; 257, 258; 257, 265; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:xpeaks; 262, identifier:append; 263, argument_list; 263, 264; 264, identifier:i; 265, expression_statement; 265, 266; 266, augmented_assignment:+=; 266, 267; 266, 268; 267, identifier:i; 268, binary_operator:-; 268, 269; 268, 270; 269, identifier:nwinwidth; 270, integer:1; 271, else_clause; 271, 272; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, augmented_assignment:+=; 274, 275; 274, 276; 275, identifier:i; 276, integer:1; 277, else_clause; 277, 278; 278, block; 278, 279; 279, expression_statement; 279, 280; 280, augmented_assignment:+=; 280, 281; 280, 282; 281, identifier:i; 282, integer:1; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:ixpeaks; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:np; 289, identifier:array; 290, argument_list; 290, 291; 291, identifier:xpeaks; 292, if_statement; 292, 293; 292, 296; 293, comparison_operator:>=; 293, 294; 293, 295; 294, identifier:debugplot; 295, integer:10; 296, block; 296, 297; 296, 306; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 300; 299, identifier:print; 300, argument_list; 300, 301; 300, 302; 301, string:'find_peaks_spectrum> number of peaks found:'; 302, call; 302, 303; 302, 304; 303, identifier:len; 304, argument_list; 304, 305; 305, identifier:ixpeaks; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 309; 308, identifier:print; 309, argument_list; 309, 310; 310, identifier:ixpeaks; 311, return_statement; 311, 312; 312, identifier:ixpeaks | def find_peaks_spectrum(sx, nwinwidth, threshold=0, debugplot=0):
if type(sx) is not np.ndarray:
raise ValueError("sx=" + str(sx) + " must be a numpy.ndarray")
elif sx.ndim is not 1:
raise ValueError("sx.ndim=" + str(sx.ndim) + " must be 1")
sx_shape = sx.shape
nmed = nwinwidth//2
if debugplot >= 10:
print('find_peaks_spectrum> sx shape......:', sx_shape)
print('find_peaks_spectrum> nwinwidth.....:', nwinwidth)
print('find_peaks_spectrum> nmed..........:', nmed)
print('find_peaks_spectrum> data_threshold:', threshold)
print('find_peaks_spectrum> the first and last', nmed,
'pixels will be ignored')
xpeaks = []
if sx_shape[0] < nwinwidth:
print('find_peaks_spectrum> sx shape......:', sx_shape)
print('find_peaks_spectrum> nwinwidth.....:', nwinwidth)
raise ValueError('sx.shape < nwinwidth')
i = nmed
while i < sx_shape[0] - nmed:
if sx[i] > threshold:
peak_ok = True
j = 0
loop = True
while loop:
if sx[i - nmed + j] > sx[i - nmed + j + 1]:
peak_ok = False
j += 1
loop = (j < nmed) and peak_ok
if peak_ok:
j = nmed + 1
loop = True
while loop:
if sx[i - nmed + j - 1] < sx[i - nmed + j]:
peak_ok = False
j += 1
loop = (j < nwinwidth) and peak_ok
if peak_ok:
xpeaks.append(i)
i += nwinwidth - 1
else:
i += 1
else:
i += 1
ixpeaks = np.array(xpeaks)
if debugplot >= 10:
print('find_peaks_spectrum> number of peaks found:', len(ixpeaks))
print(ixpeaks)
return ixpeaks |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:shortlex; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:start; 5, identifier:other; 6, default_parameter; 6, 7; 6, 8; 7, identifier:excludestart; 8, False; 9, block; 9, 10; 9, 17; 9, 29; 10, if_statement; 10, 11; 10, 13; 11, not_operator; 11, 12; 12, identifier:excludestart; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, yield; 15, 16; 16, identifier:start; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:queue; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:collections; 23, identifier:deque; 24, argument_list; 24, 25; 25, list:[(start, other)]; 25, 26; 26, tuple; 26, 27; 26, 28; 27, identifier:start; 28, identifier:other; 29, while_statement; 29, 30; 29, 31; 30, identifier:queue; 31, block; 31, 32; 31, 42; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, pattern_list; 34, 35; 34, 36; 35, identifier:current; 36, identifier:other; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:queue; 40, identifier:popleft; 41, argument_list; 42, while_statement; 42, 43; 42, 44; 43, identifier:other; 44, block; 44, 45; 44, 59; 44, 65; 44, 68; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, pattern_list; 47, 48; 47, 49; 48, identifier:first; 49, identifier:other; 50, expression_list; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:other; 53, integer:0; 54, subscript; 54, 55; 54, 56; 55, identifier:other; 56, slice; 56, 57; 56, 58; 57, integer:1; 58, colon; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:result; 62, binary_operator:|; 62, 63; 62, 64; 63, identifier:current; 64, identifier:first; 65, expression_statement; 65, 66; 66, yield; 66, 67; 67, identifier:result; 68, if_statement; 68, 69; 68, 70; 69, identifier:other; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:queue; 75, identifier:append; 76, argument_list; 76, 77; 77, tuple; 77, 78; 77, 79; 78, identifier:result; 79, identifier:other | def shortlex(start, other, excludestart=False):
if not excludestart:
yield start
queue = collections.deque([(start, other)])
while queue:
current, other = queue.popleft()
while other:
first, other = other[0], other[1:]
result = current | first
yield result
if other:
queue.append((result, other)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:reverse_shortlex; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:end; 5, identifier:other; 6, default_parameter; 6, 7; 6, 8; 7, identifier:excludeend; 8, False; 9, block; 9, 10; 9, 17; 9, 29; 10, if_statement; 10, 11; 10, 13; 11, not_operator; 11, 12; 12, identifier:excludeend; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, yield; 15, 16; 16, identifier:end; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:queue; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:collections; 23, identifier:deque; 24, argument_list; 24, 25; 25, list:[(end, other)]; 25, 26; 26, tuple; 26, 27; 26, 28; 27, identifier:end; 28, identifier:other; 29, while_statement; 29, 30; 29, 31; 30, identifier:queue; 31, block; 31, 32; 31, 42; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, pattern_list; 34, 35; 34, 36; 35, identifier:current; 36, identifier:other; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:queue; 40, identifier:popleft; 41, argument_list; 42, while_statement; 42, 43; 42, 44; 43, identifier:other; 44, block; 44, 45; 44, 59; 44, 65; 44, 68; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, pattern_list; 47, 48; 47, 49; 48, identifier:first; 49, identifier:other; 50, expression_list; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:other; 53, integer:0; 54, subscript; 54, 55; 54, 56; 55, identifier:other; 56, slice; 56, 57; 56, 58; 57, integer:1; 58, colon; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:result; 62, binary_operator:&; 62, 63; 62, 64; 63, identifier:current; 64, identifier:first; 65, expression_statement; 65, 66; 66, yield; 66, 67; 67, identifier:result; 68, if_statement; 68, 69; 68, 70; 69, identifier:other; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:queue; 75, identifier:append; 76, argument_list; 76, 77; 77, tuple; 77, 78; 77, 79; 78, identifier:result; 79, identifier:other | def reverse_shortlex(end, other, excludeend=False):
if not excludeend:
yield end
queue = collections.deque([(end, other)])
while queue:
current, other = queue.popleft()
while other:
first, other = other[0], other[1:]
result = current & first
yield result
if other:
queue.append((result, other)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:gnuplot; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:script_name; 5, default_parameter; 5, 6; 5, 7; 6, identifier:args_dict; 7, dictionary; 8, default_parameter; 8, 9; 8, 10; 9, identifier:data; 10, list:[]; 11, default_parameter; 11, 12; 11, 13; 12, identifier:silent; 13, True; 14, block; 14, 15; 14, 17; 14, 21; 14, 45; 14, 172; 14, 178; 14, 185; 14, 192; 15, expression_statement; 15, 16; 16, string:'''
Call a Gnuplot script, passing it arguments and
datasets.
Args:
scipt_name(str): The name of the Gnuplot script.
args_dict(dict): A dictionary of parameters to pass
to the script. The `key` is the name of the variable
that the `item` will be passed to the Gnuplot script
with.
data(list): A list of lists containing lists to be plotted.
The lists can be accessed by plotting the variable
`data` in the Gnuplot script. The first list in the
list of lists corresponds to the first column in data,
and so on.
silent (bool): `True` if Gnuplot stdout should be silenced,
`False` if not.
Returns:
str: The Gnuplot command used to call the script.
'''; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:gnuplot_command; 20, string:'gnuplot'; 21, if_statement; 21, 22; 21, 23; 22, identifier:data; 23, block; 23, 24; 23, 29; 23, 37; 24, assert_statement; 24, 25; 24, 28; 25, comparison_operator:not; 25, 26; 25, 27; 26, string:'data'; 27, identifier:args_dict; 28, string:'Can\'t use \'data\' variable twice.'; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:data_temp; 32, call; 32, 33; 32, 34; 33, identifier:_GnuplotDataTemp; 34, argument_list; 34, 35; 35, list_splat; 35, 36; 36, identifier:data; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:args_dict; 41, string:'data'; 42, attribute; 42, 43; 42, 44; 43, identifier:data_temp; 44, identifier:name; 45, if_statement; 45, 46; 45, 47; 46, identifier:args_dict; 47, block; 47, 48; 47, 52; 47, 159; 47, 168; 48, expression_statement; 48, 49; 49, augmented_assignment:+=; 49, 50; 49, 51; 50, identifier:gnuplot_command; 51, string:' -e "'; 52, for_statement; 52, 53; 52, 54; 52, 59; 53, identifier:arg; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:args_dict; 57, identifier:items; 58, argument_list; 59, block; 59, 60; 59, 68; 59, 155; 60, expression_statement; 60, 61; 61, augmented_assignment:+=; 61, 62; 61, 63; 62, identifier:gnuplot_command; 63, binary_operator:+; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:arg; 66, integer:0; 67, string:'='; 68, if_statement; 68, 69; 68, 76; 68, 87; 68, 113; 68, 144; 69, call; 69, 70; 69, 71; 70, identifier:isinstance; 71, argument_list; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:arg; 74, integer:1; 75, identifier:str; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, augmented_assignment:+=; 78, 79; 78, 80; 79, identifier:gnuplot_command; 80, binary_operator:+; 80, 81; 80, 86; 81, binary_operator:+; 81, 82; 81, 83; 82, string:'\''; 83, subscript; 83, 84; 83, 85; 84, identifier:arg; 85, integer:1; 86, string:'\''; 87, elif_clause; 87, 88; 87, 95; 88, call; 88, 89; 88, 90; 89, identifier:isinstance; 90, argument_list; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:arg; 93, integer:1; 94, identifier:bool; 95, block; 95, 96; 96, if_statement; 96, 97; 96, 102; 96, 107; 97, comparison_operator:is; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:arg; 100, integer:1; 101, True; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, augmented_assignment:+=; 104, 105; 104, 106; 105, identifier:gnuplot_command; 106, string:'1'; 107, else_clause; 107, 108; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, augmented_assignment:+=; 110, 111; 110, 112; 111, identifier:gnuplot_command; 112, string:'0'; 113, elif_clause; 113, 114; 113, 121; 114, call; 114, 115; 114, 116; 115, identifier:hasattr; 116, argument_list; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:arg; 119, integer:1; 120, string:'__iter__'; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, augmented_assignment:+=; 123, 124; 123, 125; 124, identifier:gnuplot_command; 125, binary_operator:+; 125, 126; 125, 143; 126, binary_operator:+; 126, 127; 126, 128; 127, string:'\''; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, string:' '; 131, identifier:join; 132, argument_list; 132, 133; 133, list_comprehension; 133, 134; 133, 138; 134, call; 134, 135; 134, 136; 135, identifier:str; 136, argument_list; 136, 137; 137, identifier:v; 138, for_in_clause; 138, 139; 138, 140; 139, identifier:v; 140, subscript; 140, 141; 140, 142; 141, identifier:arg; 142, integer:1; 143, string:'\''; 144, else_clause; 144, 145; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, augmented_assignment:+=; 147, 148; 147, 149; 148, identifier:gnuplot_command; 149, call; 149, 150; 149, 151; 150, identifier:str; 151, argument_list; 151, 152; 152, subscript; 152, 153; 152, 154; 153, identifier:arg; 154, integer:1; 155, expression_statement; 155, 156; 156, augmented_assignment:+=; 156, 157; 156, 158; 157, identifier:gnuplot_command; 158, string:'; '; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:gnuplot_command; 162, subscript; 162, 163; 162, 164; 163, identifier:gnuplot_command; 164, slice; 164, 165; 164, 166; 165, colon; 166, unary_operator:-; 166, 167; 167, integer:1; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:gnuplot_command; 171, string:'"'; 172, expression_statement; 172, 173; 173, augmented_assignment:+=; 173, 174; 173, 175; 174, identifier:gnuplot_command; 175, binary_operator:+; 175, 176; 175, 177; 176, string:' '; 177, identifier:script_name; 178, if_statement; 178, 179; 178, 180; 179, identifier:silent; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, augmented_assignment:+=; 182, 183; 182, 184; 183, identifier:gnuplot_command; 184, string:' > /dev/null 2>&1'; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:os; 189, identifier:system; 190, argument_list; 190, 191; 191, identifier:gnuplot_command; 192, return_statement; 192, 193; 193, identifier:gnuplot_command | def gnuplot(script_name, args_dict={}, data=[], silent=True):
'''
Call a Gnuplot script, passing it arguments and
datasets.
Args:
scipt_name(str): The name of the Gnuplot script.
args_dict(dict): A dictionary of parameters to pass
to the script. The `key` is the name of the variable
that the `item` will be passed to the Gnuplot script
with.
data(list): A list of lists containing lists to be plotted.
The lists can be accessed by plotting the variable
`data` in the Gnuplot script. The first list in the
list of lists corresponds to the first column in data,
and so on.
silent (bool): `True` if Gnuplot stdout should be silenced,
`False` if not.
Returns:
str: The Gnuplot command used to call the script.
'''
gnuplot_command = 'gnuplot'
if data:
assert 'data' not in args_dict, \
'Can\'t use \'data\' variable twice.'
data_temp = _GnuplotDataTemp(*data)
args_dict['data'] = data_temp.name
if args_dict:
gnuplot_command += ' -e "'
for arg in args_dict.items():
gnuplot_command += arg[0] + '='
if isinstance(arg[1], str):
gnuplot_command += '\'' + arg[1] + '\''
elif isinstance(arg[1], bool):
if arg[1] is True:
gnuplot_command += '1'
else:
gnuplot_command += '0'
elif hasattr(arg[1], '__iter__'):
gnuplot_command += '\'' + ' '.join([str(v) for v in arg[1]]) + '\''
else:
gnuplot_command += str(arg[1])
gnuplot_command += '; '
gnuplot_command = gnuplot_command[:-1]
gnuplot_command += '"'
gnuplot_command += ' ' + script_name
if silent:
gnuplot_command += ' > /dev/null 2>&1'
os.system(gnuplot_command)
return gnuplot_command |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:read; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:skip; 7, list:[]; 8, default_parameter; 8, 9; 8, 10; 9, identifier:goto_metal; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:goto_reaction; 13, None; 14, block; 14, 15; 14, 36; 14, 56; 14, 65; 14, 74; 14, 83; 14, 87; 15, if_statement; 15, 16; 15, 22; 16, comparison_operator:>; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:skip; 21, integer:0; 22, block; 22, 23; 23, for_statement; 23, 24; 23, 25; 23, 26; 24, identifier:skip_f; 25, identifier:skip; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:omit_folders; 33, identifier:append; 34, argument_list; 34, 35; 35, identifier:skip_f; 36, if_statement; 36, 37; 36, 49; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:os; 41, identifier:path; 42, identifier:isfile; 43, argument_list; 43, 44; 44, binary_operator:+; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:data_base; 48, string:'/publication.txt'; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, augmented_assignment:-=; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:user_base_level; 55, integer:1; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:stdout; 62, identifier:write; 63, argument_list; 63, 64; 64, string:'---------------------- \n'; 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:stdout; 71, identifier:write; 72, argument_list; 72, 73; 73, string:'Starting folderreader! \n'; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:stdout; 80, identifier:write; 81, argument_list; 81, 82; 82, string:'---------------------- \n'; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:found_reaction; 86, False; 87, for_statement; 87, 88; 87, 92; 87, 100; 88, pattern_list; 88, 89; 88, 90; 88, 91; 89, identifier:root; 90, identifier:dirs; 91, identifier:files; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:os; 95, identifier:walk; 96, argument_list; 96, 97; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:user_base; 100, block; 100, 101; 100, 119; 100, 135; 100, 149; 100, 169; 100, 203; 100, 261; 100, 275; 100, 320; 101, for_statement; 101, 102; 101, 103; 101, 106; 102, identifier:omit_folder; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:omit_folders; 106, block; 106, 107; 107, if_statement; 107, 108; 107, 111; 108, comparison_operator:in; 108, 109; 108, 110; 109, identifier:omit_folder; 110, identifier:dirs; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:dirs; 116, identifier:remove; 117, argument_list; 117, 118; 118, identifier:omit_folder; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:level; 122, binary_operator:-; 122, 123; 122, 132; 123, call; 123, 124; 123, 125; 124, identifier:len; 125, argument_list; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:root; 129, identifier:split; 130, argument_list; 130, 131; 131, string:"/"; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:user_base_level; 135, if_statement; 135, 136; 135, 141; 136, comparison_operator:==; 136, 137; 136, 138; 137, identifier:level; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:pub_level; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:read_pub; 147, argument_list; 147, 148; 148, identifier:root; 149, if_statement; 149, 150; 149, 155; 150, comparison_operator:==; 150, 151; 150, 152; 151, identifier:level; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:DFT_level; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:DFT_code; 161, call; 161, 162; 161, 167; 162, attribute; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:os; 165, identifier:path; 166, identifier:basename; 167, argument_list; 167, 168; 168, identifier:root; 169, if_statement; 169, 170; 169, 175; 170, comparison_operator:==; 170, 171; 170, 172; 171, identifier:level; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:XC_level; 175, block; 175, 176; 175, 189; 175, 197; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:DFT_functional; 181, call; 181, 182; 181, 187; 182, attribute; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:os; 185, identifier:path; 186, identifier:basename; 187, argument_list; 187, 188; 188, identifier:root; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:gas_folder; 194, binary_operator:+; 194, 195; 194, 196; 195, identifier:root; 196, string:'/gas/'; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:read_gas; 202, argument_list; 203, if_statement; 203, 204; 203, 209; 204, comparison_operator:==; 204, 205; 204, 206; 205, identifier:level; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:reference_level; 209, block; 209, 210; 209, 223; 209, 254; 210, if_statement; 210, 211; 210, 221; 211, comparison_operator:in; 211, 212; 211, 213; 212, string:'gas'; 213, call; 213, 214; 213, 219; 214, attribute; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:os; 217, identifier:path; 218, identifier:basename; 219, argument_list; 219, 220; 220, identifier:root; 221, block; 221, 222; 222, continue_statement; 223, if_statement; 223, 224; 223, 227; 224, comparison_operator:is; 224, 225; 224, 226; 225, identifier:goto_metal; 226, None; 227, block; 227, 228; 228, if_statement; 228, 229; 228, 239; 228, 244; 229, comparison_operator:==; 229, 230; 229, 238; 230, call; 230, 231; 230, 236; 231, attribute; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:os; 234, identifier:path; 235, identifier:basename; 236, argument_list; 236, 237; 237, identifier:root; 238, identifier:goto_metal; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:goto_metal; 243, None; 244, else_clause; 244, 245; 245, block; 245, 246; 245, 253; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 252; 248, subscript; 248, 249; 248, 250; 249, identifier:dirs; 250, slice; 250, 251; 251, colon; 252, list:[]; 253, continue_statement; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:read_bulk; 259, argument_list; 259, 260; 260, identifier:root; 261, if_statement; 261, 262; 261, 267; 262, comparison_operator:==; 262, 263; 262, 264; 263, identifier:level; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:slab_level; 267, block; 267, 268; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:self; 272, identifier:read_slab; 273, argument_list; 273, 274; 274, identifier:root; 275, if_statement; 275, 276; 275, 281; 276, comparison_operator:==; 276, 277; 276, 278; 277, identifier:level; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:reaction_level; 281, block; 281, 282; 281, 313; 282, if_statement; 282, 283; 282, 286; 283, comparison_operator:is; 283, 284; 283, 285; 284, identifier:goto_reaction; 285, None; 286, block; 286, 287; 287, if_statement; 287, 288; 287, 298; 287, 303; 288, comparison_operator:==; 288, 289; 288, 297; 289, call; 289, 290; 289, 295; 290, attribute; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:os; 293, identifier:path; 294, identifier:basename; 295, argument_list; 295, 296; 296, identifier:root; 297, identifier:goto_reaction; 298, block; 298, 299; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:goto_reaction; 302, None; 303, else_clause; 303, 304; 304, block; 304, 305; 304, 312; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 311; 307, subscript; 307, 308; 307, 309; 308, identifier:dirs; 309, slice; 309, 310; 310, colon; 311, list:[]; 312, continue_statement; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:self; 317, identifier:read_reaction; 318, argument_list; 318, 319; 319, identifier:root; 320, if_statement; 320, 321; 320, 326; 321, comparison_operator:==; 321, 322; 321, 323; 322, identifier:level; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:final_level; 326, block; 326, 327; 326, 333; 326, 340; 327, expression_statement; 327, 328; 328, assignment; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:self; 331, identifier:root; 332, identifier:root; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:self; 337, identifier:read_energies; 338, argument_list; 338, 339; 339, identifier:root; 340, if_statement; 340, 341; 340, 346; 341, comparison_operator:is; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:self; 344, identifier:key_value_pairs_reaction; 345, None; 346, block; 346, 347; 347, expression_statement; 347, 348; 348, yield; 348, 349; 349, attribute; 349, 350; 349, 351; 350, identifier:self; 351, identifier:key_value_pairs_reaction | def read(self, skip=[], goto_metal=None, goto_reaction=None):
if len(skip) > 0:
for skip_f in skip:
self.omit_folders.append(skip_f)
if os.path.isfile(self.data_base + '/publication.txt'):
self.user_base_level -= 1
self.stdout.write('---------------------- \n')
self.stdout.write('Starting folderreader! \n')
self.stdout.write('---------------------- \n')
found_reaction = False
for root, dirs, files in os.walk(self.user_base):
for omit_folder in self.omit_folders:
if omit_folder in dirs:
dirs.remove(omit_folder)
level = len(root.split("/")) - self.user_base_level
if level == self.pub_level:
self.read_pub(root)
if level == self.DFT_level:
self.DFT_code = os.path.basename(root)
if level == self.XC_level:
self.DFT_functional = os.path.basename(root)
self.gas_folder = root + '/gas/'
self.read_gas()
if level == self.reference_level:
if 'gas' in os.path.basename(root):
continue
if goto_metal is not None:
if os.path.basename(root) == goto_metal:
goto_metal = None
else:
dirs[:] = []
continue
self.read_bulk(root)
if level == self.slab_level:
self.read_slab(root)
if level == self.reaction_level:
if goto_reaction is not None:
if os.path.basename(root) == goto_reaction:
goto_reaction = None
else:
dirs[:] = []
continue
self.read_reaction(root)
if level == self.final_level:
self.root = root
self.read_energies(root)
if self.key_value_pairs_reaction is not None:
yield self.key_value_pairs_reaction |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:location; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:wave_field; 6, default_parameter; 6, 7; 6, 8; 7, identifier:depth; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:index; 11, None; 12, block; 12, 13; 12, 27; 12, 123; 13, if_statement; 13, 14; 13, 20; 14, not_operator; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:wave_field; 19, identifier:WaveField; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:wave_field; 24, subscript; 24, 25; 24, 26; 25, identifier:WaveField; 26, identifier:wave_field; 27, if_statement; 27, 28; 27, 35; 27, 91; 27, 119; 28, boolean_operator:and; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:index; 31, None; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:depth; 34, None; 35, block; 35, 36; 36, for_statement; 36, 37; 36, 40; 36, 49; 36, 69; 37, pattern_list; 37, 38; 37, 39; 38, identifier:i; 39, identifier:layer; 40, call; 40, 41; 40, 42; 41, identifier:enumerate; 42, argument_list; 42, 43; 43, subscript; 43, 44; 43, 45; 44, identifier:self; 45, slice; 45, 46; 45, 47; 46, colon; 47, unary_operator:-; 47, 48; 48, integer:1; 49, block; 49, 50; 50, if_statement; 50, 51; 50, 59; 51, comparison_operator:<=; 51, 52; 51, 55; 51, 56; 52, attribute; 52, 53; 52, 54; 53, identifier:layer; 54, identifier:depth; 55, identifier:depth; 56, attribute; 56, 57; 56, 58; 57, identifier:layer; 58, identifier:depth_base; 59, block; 59, 60; 59, 68; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:depth_within; 63, binary_operator:-; 63, 64; 63, 65; 64, identifier:depth; 65, attribute; 65, 66; 65, 67; 66, identifier:layer; 67, identifier:depth; 68, break_statement; 69, else_clause; 69, 70; 70, block; 70, 71; 70, 80; 70, 87; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:i; 74, binary_operator:-; 74, 75; 74, 79; 75, call; 75, 76; 75, 77; 76, identifier:len; 77, argument_list; 77, 78; 78, identifier:self; 79, integer:1; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:layer; 83, subscript; 83, 84; 83, 85; 84, identifier:self; 85, unary_operator:-; 85, 86; 86, integer:1; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:depth_within; 90, integer:0; 91, elif_clause; 91, 92; 91, 99; 92, boolean_operator:and; 92, 93; 92, 96; 93, comparison_operator:is; 93, 94; 93, 95; 94, identifier:index; 95, None; 96, comparison_operator:is; 96, 97; 96, 98; 97, identifier:depth; 98, None; 99, block; 99, 100; 99, 106; 99, 115; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:layer; 103, subscript; 103, 104; 103, 105; 104, identifier:self; 105, identifier:index; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:i; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:index; 113, argument_list; 113, 114; 114, identifier:layer; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:depth_within; 118, integer:0; 119, else_clause; 119, 120; 120, block; 120, 121; 121, raise_statement; 121, 122; 122, identifier:NotImplementedError; 123, return_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:Location; 126, argument_list; 126, 127; 126, 128; 126, 129; 126, 130; 127, identifier:i; 128, identifier:layer; 129, identifier:wave_field; 130, identifier:depth_within | def location(self, wave_field, depth=None, index=None):
if not isinstance(wave_field, WaveField):
wave_field = WaveField[wave_field]
if index is None and depth is not None:
for i, layer in enumerate(self[:-1]):
if layer.depth <= depth < layer.depth_base:
depth_within = depth - layer.depth
break
else:
i = len(self) - 1
layer = self[-1]
depth_within = 0
elif index is not None and depth is None:
layer = self[index]
i = self.index(layer)
depth_within = 0
else:
raise NotImplementedError
return Location(i, layer, wave_field, depth_within) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.