sequence
stringlengths
492
15.9k
code
stringlengths
75
8.58k
0, module; 0, 1; 1, ERROR; 1, 2; 1, 321; 2, function_definition; 2, 3; 2, 4; 2, 14; 2, 211; 3, function_name:_scan_xgettext_from_files; 4, parameters; 4, 5; 4, 6; 4, 7; 4, 8; 4, 11; 5, identifier:target; 6, identifier:source; 7, identifier:env; 8, default_parameter; 8, 9; 8, 10; 9, identifier:files; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:path; 13, None; 14, ERROR; 14, 15; 14, 18; 14, 22; 14, 27; 14, 34; 14, 50; 14, 72; 14, 88; 14, 99; 14, 103; 14, 167; 14, 182; 14, 183; 14, 186; 14, 187; 15, import_statement; 15, 16; 16, dotted_name; 16, 17; 17, identifier:re; 18, import_statement; 18, 19; 19, dotted_name; 19, 20; 19, 21; 20, identifier:SCons; 21, identifier:Util; 22, import_statement; 22, 23; 23, dotted_name; 23, 24; 23, 25; 23, 26; 24, identifier:SCons; 25, identifier:Node; 26, identifier:FS; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:files; 30, None; 31, block; 31, 32; 32, return_statement; 32, 33; 33, integer:0; 34, if_statement; 34, 35; 34, 44; 35, not_operator; 35, 36; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:SCons; 40, identifier:Util; 41, identifier:is_List; 42, argument_list; 42, 43; 43, identifier:files; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:files; 48, list:[files]; 48, 49; 49, identifier:files; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:is; 51, 52; 51, 53; 52, identifier:path; 53, None; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 59; 55, 66; 56, comparison_operator:in; 56, 57; 56, 58; 57, string:'XGETTEXTPATH'; 58, identifier:env; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:path; 63, subscript; 63, 64; 63, 65; 64, identifier:env; 65, string:'XGETTEXTPATH'; 66, else_clause; 66, 67; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:path; 71, list:[]; 72, if_statement; 72, 73; 72, 82; 73, not_operator; 73, 74; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:SCons; 78, identifier:Util; 79, identifier:is_List; 80, argument_list; 80, 81; 81, identifier:path; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:path; 86, list:[path]; 86, 87; 87, identifier:path; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:path; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:SCons; 95, identifier:Util; 96, identifier:flatten; 97, argument_list; 97, 98; 98, identifier:path; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:dirs; 102, tuple; 103, for_statement; 103, 104; 103, 105; 103, 106; 104, identifier:p; 105, identifier:path; 106, block; 106, 107; 106, 160; 107, if_statement; 107, 108; 107, 120; 108, not_operator; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:isinstance; 111, argument_list; 111, 112; 111, 113; 112, identifier:p; 113, attribute; 113, 114; 113, 119; 114, attribute; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:SCons; 117, identifier:Node; 118, identifier:FS; 119, identifier:Base; 120, block; 120, 121; 120, 146; 121, if_statement; 121, 122; 121, 130; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:SCons; 126, identifier:Util; 127, identifier:is_String; 128, argument_list; 128, 129; 129, identifier:p; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:p; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:env; 137, identifier:subst; 138, argument_list; 138, 139; 138, 140; 138, 143; 139, identifier:p; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:source; 142, identifier:source; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:target; 145, identifier:target; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:p; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:env; 152, identifier:arg2nodes; 153, argument_list; 153, 154; 153, 155; 154, identifier:p; 155, attribute; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:env; 158, identifier:fs; 159, identifier:Dir; 160, expression_statement; 160, 161; 161, augmented_assignment:+=; 161, 162; 161, 163; 162, identifier:dirs; 163, call; 163, 164; 163, 165; 164, identifier:tuple; 165, argument_list; 165, 166; 166, identifier:p; 167, if_statement; 167, 168; 167, 170; 168, not_operator; 168, 169; 169, identifier:dirs; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:dirs; 174, tuple; 174, 175; 175, call; 175, 176; 175, 181; 176, attribute; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:env; 179, identifier:fs; 180, identifier:getcwd; 181, argument_list; 182, identifier:re_comment; 183, attribute; 183, 184; 183, 185; 184, identifier:re; 185, identifier:compile; 186, ERROR; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:re_emptyln; 189, comparison_operator:in; 189, 190; 189, 207; 189, 210; 190, call; 190, 191; 190, 205; 191, attribute; 191, 192; 191, 201; 191, 204; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:re; 195, identifier:compile; 196, argument_list; 196, 197; 196, 198; 197, string:r'^[ \t\r]*$\r?\n?'; 198, attribute; 198, 199; 198, 200; 199, identifier:re; 200, identifier:M; 201, ERROR; 201, 202; 201, 203; 202, identifier:re_trailws; 203, identifier:re; 204, identifier:compile; 205, argument_list; 205, 206; 206, string:r'[ \t\r]+$'; 207, ERROR; 207, 208; 207, 209; 208, identifier:for; 209, identifier:f; 210, identifier:files; 211, block; 211, 212; 212, if_statement; 212, 213; 212, 230; 213, boolean_operator:and; 213, 214; 213, 225; 214, call; 214, 215; 214, 216; 215, identifier:isinstance; 216, argument_list; 216, 217; 216, 218; 217, identifier:f; 218, attribute; 218, 219; 218, 224; 219, attribute; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:SCons; 222, identifier:Node; 223, identifier:FS; 224, identifier:Base; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:f; 228, identifier:rexists; 229, argument_list; 230, block; 230, 231; 230, 239; 230, 249; 230, 259; 230, 269; 230, 277; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:contents; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:f; 237, identifier:get_text_contents; 238, argument_list; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:contents; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:re_comment; 245, identifier:sub; 246, argument_list; 246, 247; 246, 248; 247, string:""; 248, identifier:contents; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:contents; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:re_emptyln; 255, identifier:sub; 256, argument_list; 256, 257; 256, 258; 257, string:""; 258, identifier:contents; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:contents; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:re_trailws; 265, identifier:sub; 266, argument_list; 266, 267; 266, 268; 267, string:""; 268, identifier:contents; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:depnames; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:contents; 275, identifier:splitlines; 276, argument_list; 277, for_statement; 277, 278; 277, 279; 277, 280; 278, identifier:depname; 279, identifier:depnames; 280, block; 280, 281; 280, 295; 280, 313; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:depfile; 284, call; 284, 285; 284, 292; 285, attribute; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:SCons; 289, identifier:Node; 290, identifier:FS; 291, identifier:find_file; 292, argument_list; 292, 293; 292, 294; 293, identifier:depname; 294, identifier:dirs; 295, if_statement; 295, 296; 295, 298; 296, not_operator; 296, 297; 297, identifier:depfile; 298, block; 298, 299; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:depfile; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:env; 305, identifier:arg2nodes; 306, argument_list; 306, 307; 306, 308; 307, identifier:depname; 308, attribute; 308, 309; 308, 312; 309, subscript; 309, 310; 309, 311; 310, identifier:dirs; 311, integer:0; 312, identifier:File; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:env; 317, identifier:Depends; 318, argument_list; 318, 319; 318, 320; 319, identifier:target; 320, identifier:depfile; 321, return_statement; 321, 322; 322, integer:0
def _scan_xgettext_from_files(target, source, env, files=None, path=None): import re import SCons.Util import SCons.Node.FS if files is None: return 0 if not SCons.Util.is_List(files): files = [files] if path is None: if 'XGETTEXTPATH' in env: path = env['XGETTEXTPATH'] else: path = [] if not SCons.Util.is_List(path): path = [path] path = SCons.Util.flatten(path) dirs = () for p in path: if not isinstance(p, SCons.Node.FS.Base): if SCons.Util.is_String(p): p = env.subst(p, source=source, target=target) p = env.arg2nodes(p, env.fs.Dir) dirs += tuple(p) if not dirs: dirs = (env.fs.getcwd(),) re_comment = re.compile(r'^ re_emptyln = re.compile(r'^[ \t\r]*$\r?\n?', re.M) re_trailws = re.compile(r'[ \t\r]+$') for f in files: if isinstance(f, SCons.Node.FS.Base) and f.rexists(): contents = f.get_text_contents() contents = re_comment.sub("", contents) contents = re_emptyln.sub("", contents) contents = re_trailws.sub("", contents) depnames = contents.splitlines() for depname in depnames: depfile = SCons.Node.FS.find_file(depname, dirs) if not depfile: depfile = env.arg2nodes(depname, dirs[0].File) env.Depends(target, depfile) return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:build_wxsfile_file_section; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:root; 5, identifier:files; 6, identifier:NAME; 7, identifier:VERSION; 8, identifier:VENDOR; 9, identifier:filename_set; 10, identifier:id_set; 11, block; 11, 12; 11, 23; 11, 30; 11, 36; 11, 216; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:root; 15, call; 15, 16; 15, 17; 16, identifier:create_default_directory_layout; 17, argument_list; 17, 18; 17, 19; 17, 20; 17, 21; 17, 22; 18, identifier:root; 19, identifier:NAME; 20, identifier:VERSION; 21, identifier:VENDOR; 22, identifier:filename_set; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:components; 26, call; 26, 27; 26, 28; 27, identifier:create_feature_dict; 28, argument_list; 28, 29; 29, identifier:files; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:factory; 33, call; 33, 34; 33, 35; 34, identifier:Document; 35, argument_list; 36, function_definition; 36, 37; 36, 38; 36, 41; 37, function_name:get_directory; 38, parameters; 38, 39; 38, 40; 39, identifier:node; 40, identifier:dir; 41, block; 41, 42; 41, 52; 41, 56; 41, 69; 41, 73; 41, 85; 41, 146; 41, 214; 42, if_statement; 42, 43; 42, 49; 43, boolean_operator:or; 43, 44; 43, 47; 44, comparison_operator:==; 44, 45; 44, 46; 45, identifier:dir; 46, string:''; 47, not_operator; 47, 48; 48, identifier:dir; 49, block; 49, 50; 50, return_statement; 50, 51; 51, identifier:node; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:Directory; 55, identifier:node; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:dir_parts; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:dir; 62, identifier:split; 63, argument_list; 63, 64; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:os; 67, identifier:path; 68, identifier:sep; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:upper_dir; 72, string:''; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:dir_parts; 76, list_comprehension; 76, 77; 76, 78; 76, 81; 77, identifier:d; 78, for_in_clause; 78, 79; 78, 80; 79, identifier:d; 80, identifier:dir_parts; 81, if_clause; 81, 82; 82, comparison_operator:!=; 82, 83; 82, 84; 83, identifier:d; 84, string:''; 85, for_statement; 85, 86; 85, 87; 85, 91; 86, identifier:d; 87, subscript; 87, 88; 87, 89; 88, identifier:dir_parts; 89, slice; 89, 90; 90, colon; 91, block; 91, 92; 91, 121; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:already_created; 95, list_comprehension; 95, 96; 95, 97; 95, 102; 96, identifier:c; 97, for_in_clause; 97, 98; 97, 99; 98, identifier:c; 99, attribute; 99, 100; 99, 101; 100, identifier:Directory; 101, identifier:childNodes; 102, if_clause; 102, 103; 103, boolean_operator:and; 103, 104; 103, 109; 104, comparison_operator:==; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:c; 107, identifier:nodeName; 108, string:'Directory'; 109, comparison_operator:==; 109, 110; 109, 117; 110, attribute; 110, 111; 110, 116; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:c; 114, identifier:attributes; 115, string:'LongName'; 116, identifier:value; 117, call; 117, 118; 117, 119; 118, identifier:escape; 119, argument_list; 119, 120; 120, identifier:d; 121, if_statement; 121, 122; 121, 125; 121, 143; 122, comparison_operator:!=; 122, 123; 122, 124; 123, identifier:already_created; 124, list:[]; 125, block; 125, 126; 125, 132; 125, 139; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:Directory; 129, subscript; 129, 130; 129, 131; 130, identifier:already_created; 131, integer:0; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:dir_parts; 136, identifier:remove; 137, argument_list; 137, 138; 138, identifier:d; 139, expression_statement; 139, 140; 140, augmented_assignment:+=; 140, 141; 140, 142; 141, identifier:upper_dir; 142, identifier:d; 143, else_clause; 143, 144; 144, block; 144, 145; 145, break_statement; 146, for_statement; 146, 147; 146, 148; 146, 149; 147, identifier:d; 148, identifier:dir_parts; 149, block; 149, 150; 149, 159; 149, 170; 149, 185; 149, 189; 149, 201; 149, 210; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:nDirectory; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:factory; 156, identifier:createElement; 157, argument_list; 157, 158; 158, string:'Directory'; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 166; 161, subscript; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:nDirectory; 164, identifier:attributes; 165, string:'LongName'; 166, call; 166, 167; 166, 168; 167, identifier:escape; 168, argument_list; 168, 169; 169, identifier:d; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 177; 172, subscript; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:nDirectory; 175, identifier:attributes; 176, string:'Name'; 177, call; 177, 178; 177, 179; 178, identifier:escape; 179, argument_list; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:gen_dos_short_file_name; 182, argument_list; 182, 183; 182, 184; 183, identifier:d; 184, identifier:filename_set; 185, expression_statement; 185, 186; 186, augmented_assignment:+=; 186, 187; 186, 188; 187, identifier:upper_dir; 188, identifier:d; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 196; 191, subscript; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:nDirectory; 194, identifier:attributes; 195, string:'Id'; 196, call; 196, 197; 196, 198; 197, identifier:convert_to_id; 198, argument_list; 198, 199; 198, 200; 199, identifier:upper_dir; 200, identifier:id_set; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:Directory; 206, identifier:childNodes; 207, identifier:append; 208, argument_list; 208, 209; 209, identifier:nDirectory; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:Directory; 213, identifier:nDirectory; 214, return_statement; 214, 215; 215, identifier:Directory; 216, for_statement; 216, 217; 216, 218; 216, 219; 217, identifier:file; 218, identifier:files; 219, block; 219, 220; 219, 235; 219, 246; 219, 257; 219, 288; 219, 320; 219, 329; 219, 342; 219, 355; 219, 368; 219, 381; 219, 394; 219, 403; 219, 411; 219, 423; 219, 431; 219, 440; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, pattern_list; 222, 223; 222, 224; 223, identifier:drive; 224, identifier:path; 225, call; 225, 226; 225, 231; 226, attribute; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:os; 229, identifier:path; 230, identifier:splitdrive; 231, argument_list; 231, 232; 232, attribute; 232, 233; 232, 234; 233, identifier:file; 234, identifier:PACKAGING_INSTALL_LOCATION; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:filename; 238, call; 238, 239; 238, 244; 239, attribute; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:os; 242, identifier:path; 243, identifier:basename; 244, argument_list; 244, 245; 245, identifier:path; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:dirname; 249, call; 249, 250; 249, 255; 250, attribute; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:os; 253, identifier:path; 254, identifier:dirname; 255, argument_list; 255, 256; 256, identifier:path; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:h; 260, dictionary; 260, 261; 260, 264; 260, 271; 260, 274; 260, 281; 261, pair; 261, 262; 261, 263; 262, string:'PACKAGING_X_MSI_VITAL'; 263, string:'yes'; 264, pair; 264, 265; 264, 266; 265, string:'PACKAGING_X_MSI_FILEID'; 266, call; 266, 267; 266, 268; 267, identifier:convert_to_id; 268, argument_list; 268, 269; 268, 270; 269, identifier:filename; 270, identifier:id_set; 271, pair; 271, 272; 271, 273; 272, string:'PACKAGING_X_MSI_LONGNAME'; 273, identifier:filename; 274, pair; 274, 275; 274, 276; 275, string:'PACKAGING_X_MSI_SHORTNAME'; 276, call; 276, 277; 276, 278; 277, identifier:gen_dos_short_file_name; 278, argument_list; 278, 279; 278, 280; 279, identifier:filename; 280, identifier:filename_set; 281, pair; 281, 282; 281, 283; 282, string:'PACKAGING_X_MSI_SOURCE'; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:file; 286, identifier:get_path; 287, argument_list; 288, for_statement; 288, 289; 288, 292; 288, 312; 289, pattern_list; 289, 290; 289, 291; 290, identifier:k; 291, identifier:v; 292, list_comprehension; 292, 293; 292, 296; 292, 305; 293, tuple; 293, 294; 293, 295; 294, identifier:k; 295, identifier:v; 296, for_in_clause; 296, 297; 296, 300; 297, tuple_pattern; 297, 298; 297, 299; 298, identifier:k; 299, identifier:v; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:h; 303, identifier:items; 304, argument_list; 305, if_clause; 305, 306; 306, not_operator; 306, 307; 307, call; 307, 308; 307, 309; 308, identifier:hasattr; 309, argument_list; 309, 310; 309, 311; 310, identifier:file; 311, identifier:k; 312, block; 312, 313; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 316; 315, identifier:setattr; 316, argument_list; 316, 317; 316, 318; 316, 319; 317, identifier:file; 318, identifier:k; 319, identifier:v; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:File; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:factory; 326, identifier:createElement; 327, argument_list; 327, 328; 328, string:'File'; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 336; 331, subscript; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:File; 334, identifier:attributes; 335, string:'LongName'; 336, call; 336, 337; 336, 338; 337, identifier:escape; 338, argument_list; 338, 339; 339, attribute; 339, 340; 339, 341; 340, identifier:file; 341, identifier:PACKAGING_X_MSI_LONGNAME; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 349; 344, subscript; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:File; 347, identifier:attributes; 348, string:'Name'; 349, call; 349, 350; 349, 351; 350, identifier:escape; 351, argument_list; 351, 352; 352, attribute; 352, 353; 352, 354; 353, identifier:file; 354, identifier:PACKAGING_X_MSI_SHORTNAME; 355, expression_statement; 355, 356; 356, assignment; 356, 357; 356, 362; 357, subscript; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:File; 360, identifier:attributes; 361, string:'Source'; 362, call; 362, 363; 362, 364; 363, identifier:escape; 364, argument_list; 364, 365; 365, attribute; 365, 366; 365, 367; 366, identifier:file; 367, identifier:PACKAGING_X_MSI_SOURCE; 368, expression_statement; 368, 369; 369, assignment; 369, 370; 369, 375; 370, subscript; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:File; 373, identifier:attributes; 374, string:'Id'; 375, call; 375, 376; 375, 377; 376, identifier:escape; 377, argument_list; 377, 378; 378, attribute; 378, 379; 378, 380; 379, identifier:file; 380, identifier:PACKAGING_X_MSI_FILEID; 381, expression_statement; 381, 382; 382, assignment; 382, 383; 382, 388; 383, subscript; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:File; 386, identifier:attributes; 387, string:'Vital'; 388, call; 388, 389; 388, 390; 389, identifier:escape; 390, argument_list; 390, 391; 391, attribute; 391, 392; 391, 393; 392, identifier:file; 393, identifier:PACKAGING_X_MSI_VITAL; 394, expression_statement; 394, 395; 395, assignment; 395, 396; 395, 397; 396, identifier:Component; 397, call; 397, 398; 397, 401; 398, attribute; 398, 399; 398, 400; 399, identifier:factory; 400, identifier:createElement; 401, argument_list; 401, 402; 402, string:'Component'; 403, expression_statement; 403, 404; 404, assignment; 404, 405; 404, 410; 405, subscript; 405, 406; 405, 409; 406, attribute; 406, 407; 406, 408; 407, identifier:Component; 408, identifier:attributes; 409, string:'DiskId'; 410, string:'1'; 411, expression_statement; 411, 412; 412, assignment; 412, 413; 412, 418; 413, subscript; 413, 414; 413, 417; 414, attribute; 414, 415; 414, 416; 415, identifier:Component; 416, identifier:attributes; 417, string:'Id'; 418, call; 418, 419; 418, 420; 419, identifier:convert_to_id; 420, argument_list; 420, 421; 420, 422; 421, identifier:filename; 422, identifier:id_set; 423, expression_statement; 423, 424; 424, assignment; 424, 425; 424, 426; 425, identifier:Directory; 426, call; 426, 427; 426, 428; 427, identifier:get_directory; 428, argument_list; 428, 429; 428, 430; 429, identifier:root; 430, identifier:dirname; 431, expression_statement; 431, 432; 432, call; 432, 433; 432, 438; 433, attribute; 433, 434; 433, 437; 434, attribute; 434, 435; 434, 436; 435, identifier:Directory; 436, identifier:childNodes; 437, identifier:append; 438, argument_list; 438, 439; 439, identifier:Component; 440, expression_statement; 440, 441; 441, call; 441, 442; 441, 447; 442, attribute; 442, 443; 442, 446; 443, attribute; 443, 444; 443, 445; 444, identifier:Component; 445, identifier:childNodes; 446, identifier:append; 447, argument_list; 447, 448; 448, identifier:File
def build_wxsfile_file_section(root, files, NAME, VERSION, VENDOR, filename_set, id_set): root = create_default_directory_layout( root, NAME, VERSION, VENDOR, filename_set ) components = create_feature_dict( files ) factory = Document() def get_directory( node, dir ): if dir == '' or not dir: return node Directory = node dir_parts = dir.split(os.path.sep) upper_dir = '' dir_parts = [d for d in dir_parts if d != ''] for d in dir_parts[:]: already_created = [c for c in Directory.childNodes if c.nodeName == 'Directory' and c.attributes['LongName'].value == escape(d)] if already_created != []: Directory = already_created[0] dir_parts.remove(d) upper_dir += d else: break for d in dir_parts: nDirectory = factory.createElement( 'Directory' ) nDirectory.attributes['LongName'] = escape( d ) nDirectory.attributes['Name'] = escape( gen_dos_short_file_name( d, filename_set ) ) upper_dir += d nDirectory.attributes['Id'] = convert_to_id( upper_dir, id_set ) Directory.childNodes.append( nDirectory ) Directory = nDirectory return Directory for file in files: drive, path = os.path.splitdrive( file.PACKAGING_INSTALL_LOCATION ) filename = os.path.basename( path ) dirname = os.path.dirname( path ) h = { 'PACKAGING_X_MSI_VITAL' : 'yes', 'PACKAGING_X_MSI_FILEID' : convert_to_id(filename, id_set), 'PACKAGING_X_MSI_LONGNAME' : filename, 'PACKAGING_X_MSI_SHORTNAME' : gen_dos_short_file_name(filename, filename_set), 'PACKAGING_X_MSI_SOURCE' : file.get_path(), } for k,v in [ (k, v) for (k,v) in h.items() if not hasattr(file, k) ]: setattr( file, k, v ) File = factory.createElement( 'File' ) File.attributes['LongName'] = escape( file.PACKAGING_X_MSI_LONGNAME ) File.attributes['Name'] = escape( file.PACKAGING_X_MSI_SHORTNAME ) File.attributes['Source'] = escape( file.PACKAGING_X_MSI_SOURCE ) File.attributes['Id'] = escape( file.PACKAGING_X_MSI_FILEID ) File.attributes['Vital'] = escape( file.PACKAGING_X_MSI_VITAL ) Component = factory.createElement('Component') Component.attributes['DiskId'] = '1' Component.attributes['Id'] = convert_to_id( filename, id_set ) Directory = get_directory( root, dirname ) Directory.childNodes.append( Component ) Component.childNodes.append( File )
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:FromReadings; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 13; 3, 16; 3, 19; 3, 22; 4, identifier:cls; 5, identifier:uuid; 6, identifier:readings; 7, identifier:events; 8, default_parameter; 8, 9; 8, 10; 9, identifier:report_id; 10, attribute; 10, 11; 10, 12; 11, identifier:IOTileReading; 12, identifier:InvalidReadingID; 13, default_parameter; 13, 14; 13, 15; 14, identifier:selector; 15, integer:0xFFFF; 16, default_parameter; 16, 17; 16, 18; 17, identifier:streamer; 18, integer:0x100; 19, default_parameter; 19, 20; 19, 21; 20, identifier:sent_timestamp; 21, integer:0; 22, default_parameter; 22, 23; 22, 24; 23, identifier:received_time; 24, None; 25, block; 25, 26; 25, 32; 25, 38; 25, 102; 25, 114; 25, 126; 25, 162; 25, 177; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:lowest_id; 29, attribute; 29, 30; 29, 31; 30, identifier:IOTileReading; 31, identifier:InvalidReadingID; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:highest_id; 35, attribute; 35, 36; 35, 37; 36, identifier:IOTileReading; 37, identifier:InvalidReadingID; 38, for_statement; 38, 39; 38, 40; 38, 53; 39, identifier:item; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:itertools; 43, identifier:chain; 44, argument_list; 44, 45; 44, 49; 45, call; 45, 46; 45, 47; 46, identifier:iter; 47, argument_list; 47, 48; 48, identifier:readings; 49, call; 49, 50; 49, 51; 50, identifier:iter; 51, argument_list; 51, 52; 52, identifier:events; 53, block; 53, 54; 53, 64; 53, 83; 54, if_statement; 54, 55; 54, 62; 55, comparison_operator:==; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:item; 58, identifier:reading_id; 59, attribute; 59, 60; 59, 61; 60, identifier:IOTileReading; 61, identifier:InvalidReadingID; 62, block; 62, 63; 63, continue_statement; 64, if_statement; 64, 65; 64, 76; 65, boolean_operator:or; 65, 66; 65, 71; 66, comparison_operator:==; 66, 67; 66, 68; 67, identifier:lowest_id; 68, attribute; 68, 69; 68, 70; 69, identifier:IOTileReading; 70, identifier:InvalidReadingID; 71, comparison_operator:<; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:item; 74, identifier:reading_id; 75, identifier:lowest_id; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:lowest_id; 80, attribute; 80, 81; 80, 82; 81, identifier:item; 82, identifier:reading_id; 83, if_statement; 83, 84; 83, 95; 84, boolean_operator:or; 84, 85; 84, 90; 85, comparison_operator:==; 85, 86; 85, 87; 86, identifier:highest_id; 87, attribute; 87, 88; 87, 89; 88, identifier:IOTileReading; 89, identifier:InvalidReadingID; 90, comparison_operator:>; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:item; 93, identifier:reading_id; 94, identifier:highest_id; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:highest_id; 99, attribute; 99, 100; 99, 101; 100, identifier:item; 101, identifier:reading_id; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:reading_list; 105, list_comprehension; 105, 106; 105, 111; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:x; 109, identifier:asdict; 110, argument_list; 111, for_in_clause; 111, 112; 111, 113; 112, identifier:x; 113, identifier:readings; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:event_list; 117, list_comprehension; 117, 118; 117, 123; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:x; 121, identifier:asdict; 122, argument_list; 123, for_in_clause; 123, 124; 123, 125; 124, identifier:x; 125, identifier:events; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:report_dict; 129, dictionary; 129, 130; 129, 135; 129, 138; 129, 141; 129, 144; 129, 147; 129, 150; 129, 153; 129, 156; 129, 159; 130, pair; 130, 131; 130, 132; 131, string:"format"; 132, attribute; 132, 133; 132, 134; 133, identifier:cls; 134, identifier:FORMAT_TAG; 135, pair; 135, 136; 135, 137; 136, string:"device"; 137, identifier:uuid; 138, pair; 138, 139; 138, 140; 139, string:"streamer_index"; 140, identifier:streamer; 141, pair; 141, 142; 141, 143; 142, string:"streamer_selector"; 143, identifier:selector; 144, pair; 144, 145; 144, 146; 145, string:"incremental_id"; 146, identifier:report_id; 147, pair; 147, 148; 147, 149; 148, string:"lowest_id"; 149, identifier:lowest_id; 150, pair; 150, 151; 150, 152; 151, string:"highest_id"; 152, identifier:highest_id; 153, pair; 153, 154; 153, 155; 154, string:"device_sent_timestamp"; 155, identifier:sent_timestamp; 156, pair; 156, 157; 156, 158; 157, string:"events"; 158, identifier:event_list; 159, pair; 159, 160; 159, 161; 160, string:"data"; 161, identifier:reading_list; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:encoded; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:msgpack; 168, identifier:packb; 169, argument_list; 169, 170; 169, 171; 169, 174; 170, identifier:report_dict; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:default; 173, identifier:_encode_datetime; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:use_bin_type; 176, True; 177, return_statement; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:FlexibleDictionaryReport; 180, argument_list; 180, 181; 180, 182; 180, 185; 180, 188; 181, identifier:encoded; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:signed; 184, False; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:encrypted; 187, False; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:received_time; 190, identifier:received_time
def FromReadings(cls, uuid, readings, events, report_id=IOTileReading.InvalidReadingID, selector=0xFFFF, streamer=0x100, sent_timestamp=0, received_time=None): lowest_id = IOTileReading.InvalidReadingID highest_id = IOTileReading.InvalidReadingID for item in itertools.chain(iter(readings), iter(events)): if item.reading_id == IOTileReading.InvalidReadingID: continue if lowest_id == IOTileReading.InvalidReadingID or item.reading_id < lowest_id: lowest_id = item.reading_id if highest_id == IOTileReading.InvalidReadingID or item.reading_id > highest_id: highest_id = item.reading_id reading_list = [x.asdict() for x in readings] event_list = [x.asdict() for x in events] report_dict = { "format": cls.FORMAT_TAG, "device": uuid, "streamer_index": streamer, "streamer_selector": selector, "incremental_id": report_id, "lowest_id": lowest_id, "highest_id": highest_id, "device_sent_timestamp": sent_timestamp, "events": event_list, "data": reading_list } encoded = msgpack.packb(report_dict, default=_encode_datetime, use_bin_type=True) return FlexibleDictionaryReport(encoded, signed=False, encrypted=False, received_time=received_time)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_object_instance_content; 3, parameters; 3, 4; 4, identifier:obj; 5, block; 5, 6; 5, 12; 5, 19; 5, 39; 5, 45; 5, 57; 5, 69; 5, 88; 5, 138; 5, 144; 5, 165; 5, 173; 5, 195; 5, 201; 5, 205; 5, 227; 5, 234; 5, 241; 5, 248; 5, 255; 5, 262; 5, 269; 5, 276; 5, 291; 5, 298; 5, 305; 5, 312; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:retval; 9, call; 9, 10; 9, 11; 10, identifier:bytearray; 11, argument_list; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:obj; 15, None; 16, block; 16, 17; 17, return_statement; 17, 18; 18, string:b'N.'; 19, if_statement; 19, 20; 19, 29; 20, call; 20, 21; 20, 22; 21, identifier:isinstance; 22, argument_list; 22, 23; 22, 24; 23, identifier:obj; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:SCons; 27, identifier:Util; 28, identifier:BaseStringTypes; 29, block; 29, 30; 30, return_statement; 30, 31; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:SCons; 35, identifier:Util; 36, identifier:to_bytes; 37, argument_list; 37, 38; 38, identifier:obj; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:inst_class; 42, attribute; 42, 43; 42, 44; 43, identifier:obj; 44, identifier:__class__; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:inst_class_name; 48, call; 48, 49; 48, 50; 49, identifier:bytearray; 50, argument_list; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:obj; 54, identifier:__class__; 55, identifier:__name__; 56, string:'utf-8'; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:inst_class_module; 60, call; 60, 61; 60, 62; 61, identifier:bytearray; 62, argument_list; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:obj; 66, identifier:__class__; 67, identifier:__module__; 68, string:'utf-8'; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:inst_class_hierarchy; 72, call; 72, 73; 72, 74; 73, identifier:bytearray; 74, argument_list; 74, 75; 74, 87; 75, call; 75, 76; 75, 77; 76, identifier:repr; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:inspect; 81, identifier:getclasstree; 82, argument_list; 82, 83; 83, list:[obj.__class__,]; 83, 84; 84, attribute; 84, 85; 84, 86; 85, identifier:obj; 86, identifier:__class__; 87, string:'utf-8'; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:properties; 91, list_comprehension; 91, 92; 91, 100; 91, 106; 92, tuple; 92, 93; 92, 94; 93, identifier:p; 94, call; 94, 95; 94, 96; 95, identifier:getattr; 96, argument_list; 96, 97; 96, 98; 96, 99; 97, identifier:obj; 98, identifier:p; 99, string:"None"; 100, for_in_clause; 100, 101; 100, 102; 101, identifier:p; 102, call; 102, 103; 102, 104; 103, identifier:dir; 104, argument_list; 104, 105; 105, identifier:obj; 106, if_clause; 106, 107; 107, not_operator; 107, 108; 108, parenthesized_expression; 108, 109; 109, boolean_operator:or; 109, 110; 109, 128; 110, boolean_operator:or; 110, 111; 110, 118; 111, comparison_operator:==; 111, 112; 111, 117; 112, subscript; 112, 113; 112, 114; 113, identifier:p; 114, slice; 114, 115; 114, 116; 115, colon; 116, integer:2; 117, string:'__'; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:inspect; 121, identifier:ismethod; 122, argument_list; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:getattr; 125, argument_list; 125, 126; 125, 127; 126, identifier:obj; 127, identifier:p; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:inspect; 131, identifier:isbuiltin; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:getattr; 135, argument_list; 135, 136; 135, 137; 136, identifier:obj; 137, identifier:p; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:properties; 142, identifier:sort; 143, argument_list; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:properties_str; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, string:','; 150, identifier:join; 151, argument_list; 151, 152; 152, list_comprehension; 152, 153; 152, 162; 153, binary_operator:%; 153, 154; 153, 155; 154, string:"%s=%s"; 155, tuple; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:p; 158, integer:0; 159, subscript; 159, 160; 159, 161; 160, identifier:p; 161, integer:1; 162, for_in_clause; 162, 163; 162, 164; 163, identifier:p; 164, identifier:properties; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:properties_bytes; 168, call; 168, 169; 168, 170; 169, identifier:bytearray; 170, argument_list; 170, 171; 170, 172; 171, identifier:properties_str; 172, string:'utf-8'; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:methods; 176, list_comprehension; 176, 177; 176, 178; 176, 184; 177, identifier:p; 178, for_in_clause; 178, 179; 178, 180; 179, identifier:p; 180, call; 180, 181; 180, 182; 181, identifier:dir; 182, argument_list; 182, 183; 183, identifier:obj; 184, if_clause; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:inspect; 188, identifier:ismethod; 189, argument_list; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:getattr; 192, argument_list; 192, 193; 192, 194; 193, identifier:obj; 194, identifier:p; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:methods; 199, identifier:sort; 200, argument_list; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:method_contents; 204, list:[]; 205, for_statement; 205, 206; 205, 207; 205, 208; 206, identifier:m; 207, identifier:methods; 208, block; 208, 209; 208, 220; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:v; 212, call; 212, 213; 212, 214; 213, identifier:_function_contents; 214, argument_list; 214, 215; 215, call; 215, 216; 215, 217; 216, identifier:getattr; 217, argument_list; 217, 218; 217, 219; 218, identifier:obj; 219, identifier:m; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:method_contents; 224, identifier:append; 225, argument_list; 225, 226; 226, identifier:v; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:retval; 230, call; 230, 231; 230, 232; 231, identifier:bytearray; 232, argument_list; 232, 233; 233, string:b'{'; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:retval; 238, identifier:extend; 239, argument_list; 239, 240; 240, identifier:inst_class_name; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:retval; 245, identifier:extend; 246, argument_list; 246, 247; 247, string:b":"; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:retval; 252, identifier:extend; 253, argument_list; 253, 254; 254, identifier:inst_class_module; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:retval; 259, identifier:extend; 260, argument_list; 260, 261; 261, string:b'}[['; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:retval; 266, identifier:extend; 267, argument_list; 267, 268; 268, identifier:inst_class_hierarchy; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:retval; 273, identifier:extend; 274, argument_list; 274, 275; 275, string:b']]{{'; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:retval; 280, identifier:extend; 281, argument_list; 281, 282; 282, call; 282, 283; 282, 289; 283, attribute; 283, 284; 283, 288; 284, call; 284, 285; 284, 286; 285, identifier:bytearray; 286, argument_list; 286, 287; 287, string:b","; 288, identifier:join; 289, argument_list; 289, 290; 290, identifier:method_contents; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:retval; 295, identifier:extend; 296, argument_list; 296, 297; 297, string:b"}}{{{"; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:retval; 302, identifier:extend; 303, argument_list; 303, 304; 304, identifier:properties_bytes; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:retval; 309, identifier:extend; 310, argument_list; 310, 311; 311, string:b'}}}'; 312, return_statement; 312, 313; 313, identifier:retval
def _object_instance_content(obj): retval = bytearray() if obj is None: return b'N.' if isinstance(obj, SCons.Util.BaseStringTypes): return SCons.Util.to_bytes(obj) inst_class = obj.__class__ inst_class_name = bytearray(obj.__class__.__name__,'utf-8') inst_class_module = bytearray(obj.__class__.__module__,'utf-8') inst_class_hierarchy = bytearray(repr(inspect.getclasstree([obj.__class__,])),'utf-8') properties = [(p, getattr(obj, p, "None")) for p in dir(obj) if not (p[:2] == '__' or inspect.ismethod(getattr(obj, p)) or inspect.isbuiltin(getattr(obj,p))) ] properties.sort() properties_str = ','.join(["%s=%s"%(p[0],p[1]) for p in properties]) properties_bytes = bytearray(properties_str,'utf-8') methods = [p for p in dir(obj) if inspect.ismethod(getattr(obj, p))] methods.sort() method_contents = [] for m in methods: v = _function_contents(getattr(obj, m)) method_contents.append(v) retval = bytearray(b'{') retval.extend(inst_class_name) retval.extend(b":") retval.extend(inst_class_module) retval.extend(b'}[[') retval.extend(inst_class_hierarchy) retval.extend(b']]{{') retval.extend(bytearray(b",").join(method_contents)) retval.extend(b"}}{{{") retval.extend(properties_bytes) retval.extend(b'}}}') return retval
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:execute; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:target; 6, identifier:source; 7, identifier:env; 8, default_parameter; 8, 9; 8, 10; 9, identifier:executor; 10, None; 11, block; 11, 12; 11, 20; 11, 28; 11, 48; 11, 94; 11, 107; 11, 114; 11, 172; 11, 191; 11, 213; 11, 274; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:escape_list; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:SCons; 18, identifier:Subst; 19, identifier:escape_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:flatten_sequence; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:SCons; 26, identifier:Util; 27, identifier:flatten_sequence; 28, try_statement; 28, 29; 28, 36; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:shell; 33, subscript; 33, 34; 33, 35; 34, identifier:env; 35, string:'SHELL'; 36, except_clause; 36, 37; 36, 38; 37, identifier:KeyError; 38, block; 38, 39; 39, raise_statement; 39, 40; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:SCons; 44, identifier:Errors; 45, identifier:UserError; 46, argument_list; 46, 47; 47, string:'Missing SHELL construction variable.'; 48, try_statement; 48, 49; 48, 56; 48, 68; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:spawn; 53, subscript; 53, 54; 53, 55; 54, identifier:env; 55, string:'SPAWN'; 56, except_clause; 56, 57; 56, 58; 57, identifier:KeyError; 58, block; 58, 59; 59, raise_statement; 59, 60; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:SCons; 64, identifier:Errors; 65, identifier:UserError; 66, argument_list; 66, 67; 67, string:'Missing SPAWN construction variable.'; 68, else_clause; 68, 69; 69, block; 69, 70; 70, if_statement; 70, 71; 70, 75; 71, call; 71, 72; 71, 73; 72, identifier:is_String; 73, argument_list; 73, 74; 74, identifier:spawn; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:spawn; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:env; 82, identifier:subst; 83, argument_list; 83, 84; 83, 85; 83, 88; 84, identifier:spawn; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:raw; 87, integer:1; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:conv; 90, lambda; 90, 91; 90, 93; 91, lambda_parameters; 91, 92; 92, identifier:x; 93, identifier:x; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:escape; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:env; 100, identifier:get; 101, argument_list; 101, 102; 101, 103; 102, string:'ESCAPE'; 103, lambda; 103, 104; 103, 106; 104, lambda_parameters; 104, 105; 105, identifier:x; 106, identifier:x; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:ENV; 110, call; 110, 111; 110, 112; 111, identifier:get_default_ENV; 112, argument_list; 112, 113; 113, identifier:env; 114, for_statement; 114, 115; 114, 118; 114, 123; 115, pattern_list; 115, 116; 115, 117; 116, identifier:key; 117, identifier:value; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:ENV; 121, identifier:items; 122, argument_list; 123, block; 123, 124; 124, if_statement; 124, 125; 124, 130; 125, not_operator; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:is_String; 128, argument_list; 128, 129; 129, identifier:value; 130, block; 130, 131; 131, if_statement; 131, 132; 131, 136; 131, 161; 132, call; 132, 133; 132, 134; 133, identifier:is_List; 134, argument_list; 134, 135; 135, identifier:value; 136, block; 136, 137; 136, 144; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:value; 140, call; 140, 141; 140, 142; 141, identifier:flatten_sequence; 142, argument_list; 142, 143; 143, identifier:value; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:ENV; 148, identifier:key; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:os; 153, identifier:pathsep; 154, identifier:join; 155, argument_list; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:map; 158, argument_list; 158, 159; 158, 160; 159, identifier:str; 160, identifier:value; 161, else_clause; 161, 162; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:ENV; 167, identifier:key; 168, call; 168, 169; 168, 170; 169, identifier:str; 170, argument_list; 170, 171; 171, identifier:value; 172, if_statement; 172, 173; 172, 174; 173, identifier:executor; 174, block; 174, 175; 174, 183; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:target; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:executor; 181, identifier:get_all_targets; 182, argument_list; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:source; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:executor; 189, identifier:get_all_sources; 190, argument_list; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 197; 193, pattern_list; 193, 194; 193, 195; 193, 196; 194, identifier:cmd_list; 195, identifier:ignore; 196, identifier:silent; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:process; 201, argument_list; 201, 202; 201, 203; 201, 211; 201, 212; 202, identifier:target; 203, call; 203, 204; 203, 205; 204, identifier:list; 205, argument_list; 205, 206; 206, call; 206, 207; 206, 208; 207, identifier:map; 208, argument_list; 208, 209; 208, 210; 209, identifier:rfile; 210, identifier:source; 211, identifier:env; 212, identifier:executor; 213, for_statement; 213, 214; 213, 215; 213, 220; 214, identifier:cmd_line; 215, call; 215, 216; 215, 217; 216, identifier:filter; 217, argument_list; 217, 218; 217, 219; 218, identifier:len; 219, identifier:cmd_list; 220, block; 220, 221; 220, 229; 220, 242; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:cmd_line; 224, call; 224, 225; 224, 226; 225, identifier:escape_list; 226, argument_list; 226, 227; 226, 228; 227, identifier:cmd_line; 228, identifier:escape; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:result; 232, call; 232, 233; 232, 234; 233, identifier:spawn; 234, argument_list; 234, 235; 234, 236; 234, 237; 234, 240; 234, 241; 235, identifier:shell; 236, identifier:escape; 237, subscript; 237, 238; 237, 239; 238, identifier:cmd_line; 239, integer:0; 240, identifier:cmd_line; 241, identifier:ENV; 242, if_statement; 242, 243; 242, 247; 243, boolean_operator:and; 243, 244; 243, 246; 244, not_operator; 244, 245; 245, identifier:ignore; 246, identifier:result; 247, block; 247, 248; 247, 254; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:msg; 251, binary_operator:%; 251, 252; 251, 253; 252, string:"Error %s"; 253, identifier:result; 254, return_statement; 254, 255; 255, call; 255, 256; 255, 261; 256, attribute; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:SCons; 259, identifier:Errors; 260, identifier:BuildError; 261, argument_list; 261, 262; 261, 265; 261, 268; 261, 271; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:errstr; 264, identifier:msg; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:status; 267, identifier:result; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:action; 270, identifier:self; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:command; 273, identifier:cmd_line; 274, return_statement; 274, 275; 275, integer:0
def execute(self, target, source, env, executor=None): escape_list = SCons.Subst.escape_list flatten_sequence = SCons.Util.flatten_sequence try: shell = env['SHELL'] except KeyError: raise SCons.Errors.UserError('Missing SHELL construction variable.') try: spawn = env['SPAWN'] except KeyError: raise SCons.Errors.UserError('Missing SPAWN construction variable.') else: if is_String(spawn): spawn = env.subst(spawn, raw=1, conv=lambda x: x) escape = env.get('ESCAPE', lambda x: x) ENV = get_default_ENV(env) for key, value in ENV.items(): if not is_String(value): if is_List(value): value = flatten_sequence(value) ENV[key] = os.pathsep.join(map(str, value)) else: ENV[key] = str(value) if executor: target = executor.get_all_targets() source = executor.get_all_sources() cmd_list, ignore, silent = self.process(target, list(map(rfile, source)), env, executor) for cmd_line in filter(len, cmd_list): cmd_line = escape_list(cmd_line, escape) result = spawn(shell, escape, cmd_line[0], cmd_line, ENV) if not ignore and result: msg = "Error %s" % result return SCons.Errors.BuildError(errstr=msg, status=result, action=self, command=cmd_line) return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_try_load_module; 3, parameters; 3, 4; 3, 5; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:import_name; 7, None; 8, block; 8, 9; 8, 18; 8, 22; 8, 50; 8, 63; 8, 72; 8, 95; 8, 108; 8, 124; 8, 143; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:logger; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logging; 15, identifier:getLogger; 16, argument_list; 16, 17; 17, identifier:__name__; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:obj_name; 21, None; 22, if_statement; 22, 23; 22, 37; 23, boolean_operator:and; 23, 24; 23, 30; 24, comparison_operator:>; 24, 25; 24, 29; 25, call; 25, 26; 25, 27; 26, identifier:len; 27, argument_list; 27, 28; 28, identifier:path; 29, integer:2; 30, comparison_operator:in; 30, 31; 30, 32; 31, string:':'; 32, subscript; 32, 33; 32, 34; 33, identifier:path; 34, slice; 34, 35; 34, 36; 35, integer:2; 36, colon; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 44; 40, pattern_list; 40, 41; 40, 42; 40, 43; 41, identifier:path; 42, identifier:_; 43, identifier:obj_name; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:path; 47, identifier:rpartition; 48, argument_list; 48, 49; 49, string:":"; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, pattern_list; 52, 53; 52, 54; 53, identifier:folder; 54, identifier:basename; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:os; 59, identifier:path; 60, identifier:split; 61, argument_list; 61, 62; 62, identifier:path; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:==; 64, 65; 64, 66; 65, identifier:folder; 66, string:''; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:folder; 71, string:'./'; 72, if_statement; 72, 73; 72, 86; 73, boolean_operator:or; 73, 74; 73, 77; 74, comparison_operator:==; 74, 75; 74, 76; 75, identifier:basename; 76, string:''; 77, not_operator; 77, 78; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:os; 82, identifier:path; 83, identifier:exists; 84, argument_list; 84, 85; 85, identifier:path; 86, block; 86, 87; 87, raise_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:ArgumentError; 90, argument_list; 90, 91; 90, 92; 91, string:"Could not find python module to load extension"; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:path; 94, identifier:path; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, pattern_list; 97, 98; 97, 99; 98, identifier:basename; 99, identifier:ext; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:os; 104, identifier:path; 105, identifier:splitext; 106, argument_list; 106, 107; 107, identifier:basename; 108, if_statement; 108, 109; 108, 115; 109, comparison_operator:not; 109, 110; 109, 111; 110, identifier:ext; 111, tuple; 111, 112; 111, 113; 111, 114; 112, string:".py"; 113, string:".pyc"; 114, string:""; 115, block; 115, 116; 116, raise_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:ArgumentError; 119, argument_list; 119, 120; 119, 121; 120, string:"Attempted to load module is not a python package or module (.py or .pyc)"; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:path; 123, identifier:path; 124, if_statement; 124, 125; 124, 128; 124, 133; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:import_name; 127, None; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:import_name; 132, identifier:basename; 133, else_clause; 133, 134; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:logger; 139, identifier:debug; 140, argument_list; 140, 141; 140, 142; 141, string:"Importing module as subpackage: %s"; 142, identifier:import_name; 143, try_statement; 143, 144; 143, 228; 144, block; 144, 145; 144, 149; 144, 163; 144, 192; 144, 224; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:fileobj; 148, None; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 155; 151, pattern_list; 151, 152; 151, 153; 151, 154; 152, identifier:fileobj; 153, identifier:pathname; 154, identifier:description; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:imp; 158, identifier:find_module; 159, argument_list; 159, 160; 159, 161; 160, identifier:basename; 161, list:[folder]; 161, 162; 162, identifier:folder; 163, if_statement; 163, 164; 163, 169; 163, 178; 164, comparison_operator:in; 164, 165; 164, 166; 165, identifier:basename; 166, attribute; 166, 167; 166, 168; 167, identifier:sys; 168, identifier:modules; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:mod; 173, subscript; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:sys; 176, identifier:modules; 177, identifier:basename; 178, else_clause; 178, 179; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:mod; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:imp; 186, identifier:load_module; 187, argument_list; 187, 188; 187, 189; 187, 190; 187, 191; 188, identifier:import_name; 189, identifier:fileobj; 190, identifier:pathname; 191, identifier:description; 192, if_statement; 192, 193; 192, 196; 193, comparison_operator:is; 193, 194; 193, 195; 194, identifier:obj_name; 195, None; 196, block; 196, 197; 196, 216; 197, if_statement; 197, 198; 197, 203; 198, comparison_operator:not; 198, 199; 198, 200; 199, identifier:obj_name; 200, attribute; 200, 201; 200, 202; 201, identifier:mod; 202, identifier:__dict__; 203, block; 203, 204; 204, raise_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:ArgumentError; 207, argument_list; 207, 208; 207, 213; 208, binary_operator:%; 208, 209; 208, 210; 209, string:"Cannot find named object '%s' inside module '%s'"; 210, tuple; 210, 211; 210, 212; 211, identifier:obj_name; 212, identifier:basename; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:path; 215, identifier:path; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:mod; 219, subscript; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:mod; 222, identifier:__dict__; 223, identifier:obj_name; 224, return_statement; 224, 225; 225, expression_list; 225, 226; 225, 227; 226, identifier:basename; 227, identifier:mod; 228, finally_clause; 228, 229; 229, block; 229, 230; 230, if_statement; 230, 231; 230, 234; 231, comparison_operator:is; 231, 232; 231, 233; 232, identifier:fileobj; 233, None; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:fileobj; 239, identifier:close; 240, argument_list
def _try_load_module(path, import_name=None): logger = logging.getLogger(__name__) obj_name = None if len(path) > 2 and ':' in path[2:]: path, _, obj_name = path.rpartition(":") folder, basename = os.path.split(path) if folder == '': folder = './' if basename == '' or not os.path.exists(path): raise ArgumentError("Could not find python module to load extension", path=path) basename, ext = os.path.splitext(basename) if ext not in (".py", ".pyc", ""): raise ArgumentError("Attempted to load module is not a python package or module (.py or .pyc)", path=path) if import_name is None: import_name = basename else: logger.debug("Importing module as subpackage: %s", import_name) try: fileobj = None fileobj, pathname, description = imp.find_module(basename, [folder]) if basename in sys.modules: mod = sys.modules[basename] else: mod = imp.load_module(import_name, fileobj, pathname, description) if obj_name is not None: if obj_name not in mod.__dict__: raise ArgumentError("Cannot find named object '%s' inside module '%s'" % (obj_name, basename), path=path) mod = mod.__dict__[obj_name] return basename, mod finally: if fileobj is not None: fileobj.close()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:load_extensions; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:group; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name_filter; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:comp_filter; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:class_filter; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:product_name; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:unique; 20, False; 21, block; 21, 22; 21, 26; 21, 131; 21, 205; 21, 247; 21, 266; 21, 320; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:found_extensions; 25, list:[]; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:product_name; 29, None; 30, block; 30, 31; 31, for_statement; 31, 32; 31, 33; 31, 38; 32, identifier:comp; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:iter_components; 37, argument_list; 38, block; 38, 39; 38, 51; 38, 60; 39, if_statement; 39, 40; 39, 49; 40, boolean_operator:and; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:comp_filter; 43, None; 44, comparison_operator:!=; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:comp; 47, identifier:name; 48, identifier:comp_filter; 49, block; 49, 50; 50, continue_statement; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:products; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:comp; 57, identifier:find_products; 58, argument_list; 58, 59; 59, identifier:product_name; 60, for_statement; 60, 61; 60, 62; 60, 63; 61, identifier:product; 62, identifier:products; 63, block; 63, 64; 64, try_statement; 64, 65; 64, 117; 65, block; 65, 66; 65, 84; 65, 110; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:entries; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:load_extension; 73, argument_list; 73, 74; 73, 75; 73, 78; 73, 81; 74, identifier:product; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:name_filter; 77, identifier:name_filter; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:class_filter; 80, identifier:class_filter; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:component; 83, identifier:comp; 84, if_statement; 84, 85; 84, 95; 85, boolean_operator:and; 85, 86; 85, 92; 86, comparison_operator:==; 86, 87; 86, 91; 87, call; 87, 88; 87, 89; 88, identifier:len; 89, argument_list; 89, 90; 90, identifier:entries; 91, integer:0; 92, comparison_operator:is; 92, 93; 92, 94; 93, identifier:name_filter; 94, None; 95, block; 95, 96; 95, 109; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:_logger; 102, identifier:warn; 103, argument_list; 103, 104; 103, 105; 103, 106; 104, string:"Found no valid extensions in product %s of component %s"; 105, identifier:product; 106, attribute; 106, 107; 106, 108; 107, identifier:comp; 108, identifier:path; 109, continue_statement; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:found_extensions; 114, identifier:extend; 115, argument_list; 115, 116; 116, identifier:entries; 117, except_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:_logger; 125, identifier:exception; 126, argument_list; 126, 127; 126, 128; 126, 129; 126, 130; 127, string:"Unable to load extension %s from local component %s at path %s"; 128, identifier:product_name; 129, identifier:comp; 130, identifier:product; 131, for_statement; 131, 132; 131, 133; 131, 139; 132, identifier:entry; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:_iter_entrypoint_group; 137, argument_list; 137, 138; 138, identifier:group; 139, block; 139, 140; 139, 146; 139, 156; 139, 187; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:name; 143, attribute; 143, 144; 143, 145; 144, identifier:entry; 145, identifier:name; 146, if_statement; 146, 147; 146, 154; 147, boolean_operator:and; 147, 148; 147, 151; 148, comparison_operator:is; 148, 149; 148, 150; 149, identifier:name_filter; 150, None; 151, comparison_operator:!=; 151, 152; 151, 153; 152, identifier:name; 153, identifier:name_filter; 154, block; 154, 155; 155, continue_statement; 156, try_statement; 156, 157; 156, 166; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:ext; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:entry; 164, identifier:load; 165, argument_list; 166, except_clause; 166, 167; 167, block; 167, 168; 167, 186; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 175; 170, attribute; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:_logger; 174, identifier:warn; 175, argument_list; 175, 176; 175, 177; 175, 180; 175, 183; 176, string:"Unable to load %s from %s"; 177, attribute; 177, 178; 177, 179; 178, identifier:entry; 179, identifier:name; 180, attribute; 180, 181; 180, 182; 181, identifier:entry; 182, identifier:distro; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:exc_info; 185, True; 186, continue_statement; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:found_extensions; 191, identifier:extend; 192, generator_expression; 192, 193; 192, 196; 193, tuple; 193, 194; 193, 195; 194, identifier:name; 195, identifier:x; 196, for_in_clause; 196, 197; 196, 198; 197, identifier:x; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:_filter_subclasses; 202, argument_list; 202, 203; 202, 204; 203, identifier:ext; 204, identifier:class_filter; 205, for_statement; 205, 206; 205, 209; 205, 218; 206, tuple_pattern; 206, 207; 206, 208; 207, identifier:name; 208, identifier:ext; 209, call; 209, 210; 209, 215; 210, attribute; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:_registered_extensions; 214, identifier:get; 215, argument_list; 215, 216; 215, 217; 216, identifier:group; 217, list:[]; 218, block; 218, 219; 218, 229; 219, if_statement; 219, 220; 219, 227; 220, boolean_operator:and; 220, 221; 220, 224; 221, comparison_operator:is; 221, 222; 221, 223; 222, identifier:name_filter; 223, None; 224, comparison_operator:!=; 224, 225; 224, 226; 225, identifier:name; 226, identifier:name_filter; 227, block; 227, 228; 228, continue_statement; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:found_extensions; 233, identifier:extend; 234, generator_expression; 234, 235; 234, 238; 235, tuple; 235, 236; 235, 237; 236, identifier:name; 237, identifier:x; 238, for_in_clause; 238, 239; 238, 240; 239, identifier:x; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:_filter_subclasses; 244, argument_list; 244, 245; 244, 246; 245, identifier:ext; 246, identifier:class_filter; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:found_extensions; 250, list_comprehension; 250, 251; 250, 254; 250, 259; 251, tuple; 251, 252; 251, 253; 252, identifier:name; 253, identifier:x; 254, for_in_clause; 254, 255; 254, 258; 255, pattern_list; 255, 256; 255, 257; 256, identifier:name; 257, identifier:x; 258, identifier:found_extensions; 259, if_clause; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:self; 263, identifier:_filter_nonextensions; 264, argument_list; 264, 265; 265, identifier:x; 266, if_statement; 266, 267; 266, 270; 267, comparison_operator:is; 267, 268; 267, 269; 268, identifier:unique; 269, True; 270, block; 270, 271; 270, 316; 271, if_statement; 271, 272; 271, 278; 271, 297; 272, comparison_operator:>; 272, 273; 272, 277; 273, call; 273, 274; 273, 275; 274, identifier:len; 275, argument_list; 275, 276; 276, identifier:found_extensions; 277, integer:1; 278, block; 278, 279; 279, raise_statement; 279, 280; 280, call; 280, 281; 280, 282; 281, identifier:ArgumentError; 282, argument_list; 282, 283; 282, 294; 283, binary_operator:%; 283, 284; 283, 285; 284, string:"Extension %s should have had exactly one instance of class %s, found %d"; 285, tuple; 285, 286; 285, 287; 285, 290; 286, identifier:group; 287, attribute; 287, 288; 287, 289; 288, identifier:class_filter; 289, identifier:__name__; 290, call; 290, 291; 290, 292; 291, identifier:len; 292, argument_list; 292, 293; 293, identifier:found_extensions; 294, keyword_argument; 294, 295; 294, 296; 295, identifier:classes; 296, identifier:found_extensions; 297, elif_clause; 297, 298; 297, 304; 298, comparison_operator:==; 298, 299; 298, 303; 299, call; 299, 300; 299, 301; 300, identifier:len; 301, argument_list; 301, 302; 302, identifier:found_extensions; 303, integer:0; 304, block; 304, 305; 305, raise_statement; 305, 306; 306, call; 306, 307; 306, 308; 307, identifier:ArgumentError; 308, argument_list; 308, 309; 309, binary_operator:%; 309, 310; 309, 311; 310, string:"Extension %s had no instances of class %s"; 311, tuple; 311, 312; 311, 313; 312, identifier:group; 313, attribute; 313, 314; 313, 315; 314, identifier:class_filter; 315, identifier:__name__; 316, return_statement; 316, 317; 317, subscript; 317, 318; 317, 319; 318, identifier:found_extensions; 319, integer:0; 320, return_statement; 320, 321; 321, identifier:found_extensions
def load_extensions(self, group, name_filter=None, comp_filter=None, class_filter=None, product_name=None, unique=False): found_extensions = [] if product_name is not None: for comp in self.iter_components(): if comp_filter is not None and comp.name != comp_filter: continue products = comp.find_products(product_name) for product in products: try: entries = self.load_extension(product, name_filter=name_filter, class_filter=class_filter, component=comp) if len(entries) == 0 and name_filter is None: self._logger.warn("Found no valid extensions in product %s of component %s", product, comp.path) continue found_extensions.extend(entries) except: self._logger.exception("Unable to load extension %s from local component %s at path %s", product_name, comp, product) for entry in self._iter_entrypoint_group(group): name = entry.name if name_filter is not None and name != name_filter: continue try: ext = entry.load() except: self._logger.warn("Unable to load %s from %s", entry.name, entry.distro, exc_info=True) continue found_extensions.extend((name, x) for x in self._filter_subclasses(ext, class_filter)) for (name, ext) in self._registered_extensions.get(group, []): if name_filter is not None and name != name_filter: continue found_extensions.extend((name, x) for x in self._filter_subclasses(ext, class_filter)) found_extensions = [(name, x) for name, x in found_extensions if self._filter_nonextensions(x)] if unique is True: if len(found_extensions) > 1: raise ArgumentError("Extension %s should have had exactly one instance of class %s, found %d" % (group, class_filter.__name__, len(found_extensions)), classes=found_extensions) elif len(found_extensions) == 0: raise ArgumentError("Extension %s had no instances of class %s" % (group, class_filter.__name__)) return found_extensions[0] return found_extensions
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:load_extension; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name_filter; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:class_filter; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:unique; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:component; 17, None; 18, block; 18, 19; 18, 23; 18, 36; 18, 48; 18, 59; 18, 75; 18, 94; 18, 100; 18, 145; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:import_name; 22, None; 23, if_statement; 23, 24; 23, 27; 24, comparison_operator:is; 24, 25; 24, 26; 25, identifier:component; 26, None; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:import_name; 31, call; 31, 32; 31, 33; 32, identifier:_ensure_package_loaded; 33, argument_list; 33, 34; 33, 35; 34, identifier:path; 35, identifier:component; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 41; 38, pattern_list; 38, 39; 38, 40; 39, identifier:name; 40, identifier:ext; 41, call; 41, 42; 41, 43; 42, identifier:_try_load_module; 43, argument_list; 43, 44; 43, 45; 44, identifier:path; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:import_name; 47, identifier:import_name; 48, if_statement; 48, 49; 48, 56; 49, boolean_operator:and; 49, 50; 49, 53; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:name_filter; 52, None; 53, comparison_operator:!=; 53, 54; 53, 55; 54, identifier:name; 55, identifier:name_filter; 56, block; 56, 57; 57, return_statement; 57, 58; 58, list:[]; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:found; 62, list_comprehension; 62, 63; 62, 66; 63, tuple; 63, 64; 63, 65; 64, identifier:name; 65, identifier:x; 66, for_in_clause; 66, 67; 66, 68; 67, identifier:x; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:_filter_subclasses; 72, argument_list; 72, 73; 72, 74; 73, identifier:ext; 74, identifier:class_filter; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:found; 78, list_comprehension; 78, 79; 78, 82; 78, 87; 79, tuple; 79, 80; 79, 81; 80, identifier:name; 81, identifier:x; 82, for_in_clause; 82, 83; 82, 86; 83, pattern_list; 83, 84; 83, 85; 84, identifier:name; 85, identifier:x; 86, identifier:found; 87, if_clause; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:_filter_nonextensions; 92, argument_list; 92, 93; 93, identifier:x; 94, if_statement; 94, 95; 94, 97; 95, not_operator; 95, 96; 96, identifier:unique; 97, block; 97, 98; 98, return_statement; 98, 99; 99, identifier:found; 100, if_statement; 100, 101; 100, 107; 100, 126; 101, comparison_operator:>; 101, 102; 101, 106; 102, call; 102, 103; 102, 104; 103, identifier:len; 104, argument_list; 104, 105; 105, identifier:found; 106, integer:1; 107, block; 107, 108; 108, raise_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:ArgumentError; 111, argument_list; 111, 112; 111, 123; 112, binary_operator:%; 112, 113; 112, 114; 113, string:"Extension %s should have had exactly one instance of class %s, found %d"; 114, tuple; 114, 115; 114, 116; 114, 119; 115, identifier:path; 116, attribute; 116, 117; 116, 118; 117, identifier:class_filter; 118, identifier:__name__; 119, call; 119, 120; 119, 121; 120, identifier:len; 121, argument_list; 121, 122; 122, identifier:found; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:classes; 125, identifier:found; 126, elif_clause; 126, 127; 126, 133; 127, comparison_operator:==; 127, 128; 127, 132; 128, call; 128, 129; 128, 130; 129, identifier:len; 130, argument_list; 130, 131; 131, identifier:found; 132, integer:0; 133, block; 133, 134; 134, raise_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:ArgumentError; 137, argument_list; 137, 138; 138, binary_operator:%; 138, 139; 138, 140; 139, string:"Extension %s had no instances of class %s"; 140, tuple; 140, 141; 140, 142; 141, identifier:path; 142, attribute; 142, 143; 142, 144; 143, identifier:class_filter; 144, identifier:__name__; 145, return_statement; 145, 146; 146, subscript; 146, 147; 146, 148; 147, identifier:found; 148, integer:0
def load_extension(self, path, name_filter=None, class_filter=None, unique=False, component=None): import_name = None if component is not None: import_name = _ensure_package_loaded(path, component) name, ext = _try_load_module(path, import_name=import_name) if name_filter is not None and name != name_filter: return [] found = [(name, x) for x in self._filter_subclasses(ext, class_filter)] found = [(name, x) for name, x in found if self._filter_nonextensions(x)] if not unique: return found if len(found) > 1: raise ArgumentError("Extension %s should have had exactly one instance of class %s, found %d" % (path, class_filter.__name__, len(found)), classes=found) elif len(found) == 0: raise ArgumentError("Extension %s had no instances of class %s" % (path, class_filter.__name__)) return found[0]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:solutionEmitter; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:target; 5, identifier:source; 6, identifier:env; 7, block; 7, 8; 7, 21; 7, 39; 7, 48; 7, 56; 7, 326; 8, if_statement; 8, 9; 8, 16; 9, comparison_operator:==; 9, 10; 9, 13; 10, subscript; 10, 11; 10, 12; 11, identifier:source; 12, integer:0; 13, subscript; 13, 14; 13, 15; 14, identifier:target; 15, integer:0; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:source; 20, list:[]; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 26; 23, tuple_pattern; 23, 24; 23, 25; 24, identifier:base; 25, identifier:suff; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:SCons; 30, identifier:Util; 31, identifier:splitext; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:str; 35, argument_list; 35, 36; 36, subscript; 36, 37; 36, 38; 37, identifier:target; 38, integer:0; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:suff; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:env; 45, identifier:subst; 46, argument_list; 46, 47; 47, string:'$MSVSSOLUTIONSUFFIX'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:target; 52, integer:0; 53, binary_operator:+; 53, 54; 53, 55; 54, identifier:base; 55, identifier:suff; 56, if_statement; 56, 57; 56, 59; 57, not_operator; 57, 58; 58, identifier:source; 59, block; 59, 60; 59, 64; 59, 102; 59, 198; 59, 236; 59, 299; 59, 312; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:source; 63, string:'sln_inputs:'; 64, if_statement; 64, 65; 64, 68; 65, comparison_operator:in; 65, 66; 65, 67; 66, string:'name'; 67, identifier:env; 68, block; 68, 69; 69, if_statement; 69, 70; 69, 80; 69, 91; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:SCons; 74, identifier:Util; 75, identifier:is_String; 76, argument_list; 76, 77; 77, subscript; 77, 78; 77, 79; 78, identifier:env; 79, string:'name'; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:source; 84, binary_operator:+; 84, 85; 84, 86; 85, identifier:source; 86, binary_operator:%; 86, 87; 86, 88; 87, string:' "%s"'; 88, subscript; 88, 89; 88, 90; 89, identifier:env; 90, string:'name'; 91, else_clause; 91, 92; 92, block; 92, 93; 93, raise_statement; 93, 94; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:SCons; 98, identifier:Errors; 99, identifier:InternalError; 100, argument_list; 100, 101; 101, string:"name must be a string"; 102, if_statement; 102, 103; 102, 106; 102, 187; 103, comparison_operator:in; 103, 104; 103, 105; 104, string:'variant'; 105, identifier:env; 106, block; 106, 107; 107, if_statement; 107, 108; 107, 118; 107, 129; 107, 176; 108, call; 108, 109; 108, 114; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:SCons; 112, identifier:Util; 113, identifier:is_String; 114, argument_list; 114, 115; 115, subscript; 115, 116; 115, 117; 116, identifier:env; 117, string:'variant'; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:source; 122, binary_operator:+; 122, 123; 122, 124; 123, identifier:source; 124, binary_operator:%; 124, 125; 124, 126; 125, string:' "%s"'; 126, subscript; 126, 127; 126, 128; 127, identifier:env; 128, string:'variant'; 129, elif_clause; 129, 130; 129, 140; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:SCons; 134, identifier:Util; 135, identifier:is_List; 136, argument_list; 136, 137; 137, subscript; 137, 138; 137, 139; 138, identifier:env; 139, string:'variant'; 140, block; 140, 141; 141, for_statement; 141, 142; 141, 143; 141, 146; 142, identifier:variant; 143, subscript; 143, 144; 143, 145; 144, identifier:env; 145, string:'variant'; 146, block; 146, 147; 147, if_statement; 147, 148; 147, 156; 147, 165; 148, call; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:SCons; 152, identifier:Util; 153, identifier:is_String; 154, argument_list; 154, 155; 155, identifier:variant; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:source; 160, binary_operator:+; 160, 161; 160, 162; 161, identifier:source; 162, binary_operator:%; 162, 163; 162, 164; 163, string:' "%s"'; 164, identifier:variant; 165, else_clause; 165, 166; 166, block; 166, 167; 167, raise_statement; 167, 168; 168, call; 168, 169; 168, 174; 169, attribute; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:SCons; 172, identifier:Errors; 173, identifier:InternalError; 174, argument_list; 174, 175; 175, string:"name must be a string or a list of strings"; 176, else_clause; 176, 177; 177, block; 177, 178; 178, raise_statement; 178, 179; 179, call; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:SCons; 183, identifier:Errors; 184, identifier:InternalError; 185, argument_list; 185, 186; 186, string:"variant must be a string or a list of strings"; 187, else_clause; 187, 188; 188, block; 188, 189; 189, raise_statement; 189, 190; 190, call; 190, 191; 190, 196; 191, attribute; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:SCons; 194, identifier:Errors; 195, identifier:InternalError; 196, argument_list; 196, 197; 197, string:"variant must be specified"; 198, if_statement; 198, 199; 198, 202; 199, comparison_operator:in; 199, 200; 199, 201; 200, string:'slnguid'; 201, identifier:env; 202, block; 202, 203; 203, if_statement; 203, 204; 203, 214; 203, 225; 204, call; 204, 205; 204, 210; 205, attribute; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:SCons; 208, identifier:Util; 209, identifier:is_String; 210, argument_list; 210, 211; 211, subscript; 211, 212; 211, 213; 212, identifier:env; 213, string:'slnguid'; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:source; 218, binary_operator:+; 218, 219; 218, 220; 219, identifier:source; 220, binary_operator:%; 220, 221; 220, 222; 221, string:' "%s"'; 222, subscript; 222, 223; 222, 224; 223, identifier:env; 224, string:'slnguid'; 225, else_clause; 225, 226; 226, block; 226, 227; 227, raise_statement; 227, 228; 228, call; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:SCons; 232, identifier:Errors; 233, identifier:InternalError; 234, argument_list; 234, 235; 235, string:"slnguid must be a string"; 236, if_statement; 236, 237; 236, 240; 237, comparison_operator:in; 237, 238; 237, 239; 238, string:'projects'; 239, identifier:env; 240, block; 240, 241; 241, if_statement; 241, 242; 241, 252; 241, 263; 242, call; 242, 243; 242, 248; 243, attribute; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:SCons; 246, identifier:Util; 247, identifier:is_String; 248, argument_list; 248, 249; 249, subscript; 249, 250; 249, 251; 250, identifier:env; 251, string:'projects'; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:source; 256, binary_operator:+; 256, 257; 256, 258; 257, identifier:source; 258, binary_operator:%; 258, 259; 258, 260; 259, string:' "%s"'; 260, subscript; 260, 261; 260, 262; 261, identifier:env; 262, string:'projects'; 263, elif_clause; 263, 264; 263, 274; 264, call; 264, 265; 264, 270; 265, attribute; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:SCons; 268, identifier:Util; 269, identifier:is_List; 270, argument_list; 270, 271; 271, subscript; 271, 272; 271, 273; 272, identifier:env; 273, string:'projects'; 274, block; 274, 275; 275, for_statement; 275, 276; 275, 277; 275, 280; 276, identifier:t; 277, subscript; 277, 278; 277, 279; 278, identifier:env; 279, string:'projects'; 280, block; 280, 281; 281, if_statement; 281, 282; 281, 290; 282, call; 282, 283; 282, 288; 283, attribute; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:SCons; 286, identifier:Util; 287, identifier:is_String; 288, argument_list; 288, 289; 289, identifier:t; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:source; 294, binary_operator:+; 294, 295; 294, 296; 295, identifier:source; 296, binary_operator:%; 296, 297; 296, 298; 297, string:' "%s"'; 298, identifier:t; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:source; 302, binary_operator:+; 302, 303; 302, 304; 303, identifier:source; 304, binary_operator:%; 304, 305; 304, 306; 305, string:' "%s"'; 306, call; 306, 307; 306, 308; 307, identifier:str; 308, argument_list; 308, 309; 309, subscript; 309, 310; 309, 311; 310, identifier:target; 311, integer:0; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:source; 315, list:[SCons.Node.Python.Value(source)]; 315, 316; 316, call; 316, 317; 316, 324; 317, attribute; 317, 318; 317, 323; 318, attribute; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:SCons; 321, identifier:Node; 322, identifier:Python; 323, identifier:Value; 324, argument_list; 324, 325; 325, identifier:source; 326, return_statement; 326, 327; 327, tuple; 327, 328; 327, 332; 328, list:[target[0]]; 328, 329; 329, subscript; 329, 330; 329, 331; 330, identifier:target; 331, integer:0; 332, identifier:source
def solutionEmitter(target, source, env): if source[0] == target[0]: source = [] (base, suff) = SCons.Util.splitext(str(target[0])) suff = env.subst('$MSVSSOLUTIONSUFFIX') target[0] = base + suff if not source: source = 'sln_inputs:' if 'name' in env: if SCons.Util.is_String(env['name']): source = source + ' "%s"' % env['name'] else: raise SCons.Errors.InternalError("name must be a string") if 'variant' in env: if SCons.Util.is_String(env['variant']): source = source + ' "%s"' % env['variant'] elif SCons.Util.is_List(env['variant']): for variant in env['variant']: if SCons.Util.is_String(variant): source = source + ' "%s"' % variant else: raise SCons.Errors.InternalError("name must be a string or a list of strings") else: raise SCons.Errors.InternalError("variant must be a string or a list of strings") else: raise SCons.Errors.InternalError("variant must be specified") if 'slnguid' in env: if SCons.Util.is_String(env['slnguid']): source = source + ' "%s"' % env['slnguid'] else: raise SCons.Errors.InternalError("slnguid must be a string") if 'projects' in env: if SCons.Util.is_String(env['projects']): source = source + ' "%s"' % env['projects'] elif SCons.Util.is_List(env['projects']): for t in env['projects']: if SCons.Util.is_String(t): source = source + ' "%s"' % t source = source + ' "%s"' % str(target[0]) source = [SCons.Node.Python.Value(source)] return ([target[0]], source)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:process_message; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:message; 6, default_parameter; 6, 7; 6, 8; 7, identifier:wait; 8, True; 9, block; 9, 10; 9, 20; 9, 24; 9, 153; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:to_check; 13, call; 13, 14; 13, 15; 14, identifier:deque; 15, argument_list; 15, 16; 16, list:[self._waiters]; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_waiters; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:ignored; 23, True; 24, while_statement; 24, 25; 24, 31; 25, comparison_operator:>; 25, 26; 25, 30; 26, call; 26, 27; 26, 28; 27, identifier:len; 28, argument_list; 28, 29; 29, identifier:to_check; 30, integer:0; 31, block; 31, 32; 31, 40; 31, 52; 31, 107; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:context; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:to_check; 38, identifier:popleft; 39, argument_list; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:waiters; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:context; 46, identifier:get; 47, argument_list; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:OperationManager; 50, identifier:_LEAF; 51, list:[]; 52, for_statement; 52, 53; 52, 54; 52, 55; 53, identifier:waiter; 54, identifier:waiters; 55, block; 55, 56; 55, 103; 56, if_statement; 56, 57; 56, 64; 56, 72; 57, call; 57, 58; 57, 59; 58, identifier:isinstance; 59, argument_list; 59, 60; 59, 61; 60, identifier:waiter; 61, attribute; 61, 62; 61, 63; 62, identifier:asyncio; 63, identifier:Future; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:waiter; 69, identifier:set_result; 70, argument_list; 70, 71; 71, identifier:message; 72, else_clause; 72, 73; 73, block; 73, 74; 74, try_statement; 74, 75; 74, 87; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, await; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:_wait_or_launch; 80, argument_list; 80, 81; 80, 84; 80, 85; 80, 86; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:_loop; 84, identifier:waiter; 85, identifier:message; 86, identifier:wait; 87, except_clause; 87, 88; 88, block; 88, 89; 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:_logger; 95, identifier:warning; 96, argument_list; 96, 97; 96, 98; 96, 99; 96, 100; 97, string:"Error calling every_match callback, callback=%s, message=%s"; 98, identifier:waiter; 99, identifier:message; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:exc_info; 102, True; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:ignored; 106, False; 107, for_statement; 107, 108; 107, 109; 107, 110; 108, identifier:key; 109, identifier:context; 110, block; 110, 111; 110, 119; 110, 127; 110, 133; 110, 139; 111, if_statement; 111, 112; 111, 117; 112, comparison_operator:is; 112, 113; 112, 114; 113, identifier:key; 114, attribute; 114, 115; 114, 116; 115, identifier:OperationManager; 116, identifier:_LEAF; 117, block; 117, 118; 118, continue_statement; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:message_val; 122, call; 122, 123; 122, 124; 123, identifier:_get_key; 124, argument_list; 124, 125; 124, 126; 125, identifier:message; 126, identifier:key; 127, if_statement; 127, 128; 127, 131; 128, comparison_operator:is; 128, 129; 128, 130; 129, identifier:message_val; 130, identifier:_MISSING; 131, block; 131, 132; 132, continue_statement; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:next_level; 136, subscript; 136, 137; 136, 138; 137, identifier:context; 138, identifier:key; 139, if_statement; 139, 140; 139, 143; 140, comparison_operator:in; 140, 141; 140, 142; 141, identifier:message_val; 142, identifier:next_level; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:to_check; 148, identifier:append; 149, argument_list; 149, 150; 150, subscript; 150, 151; 150, 152; 151, identifier:next_level; 152, identifier:message_val; 153, return_statement; 153, 154; 154, not_operator; 154, 155; 155, identifier:ignored
async def process_message(self, message, wait=True): to_check = deque([self._waiters]) ignored = True while len(to_check) > 0: context = to_check.popleft() waiters = context.get(OperationManager._LEAF, []) for waiter in waiters: if isinstance(waiter, asyncio.Future): waiter.set_result(message) else: try: await _wait_or_launch(self._loop, waiter, message, wait) except: self._logger.warning("Error calling every_match callback, callback=%s, message=%s", waiter, message, exc_info=True) ignored = False for key in context: if key is OperationManager._LEAF: continue message_val = _get_key(message, key) if message_val is _MISSING: continue next_level = context[key] if message_val in next_level: to_check.append(next_level[message_val]) return not ignored
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:compile; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:values; 6, block; 6, 7; 6, 19; 6, 31; 6, 43; 6, 56; 6, 60; 6, 76; 6, 107; 6, 122; 6, 193; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:is_international; 9, parameters; 9, 10; 10, identifier:tag; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:tag; 16, identifier:endswith; 17, argument_list; 17, 18; 18, string:'_'; 19, function_definition; 19, 20; 19, 21; 19, 23; 20, function_name:get_country_code; 21, parameters; 21, 22; 22, identifier:tag; 23, block; 23, 24; 24, return_statement; 24, 25; 25, subscript; 25, 26; 25, 27; 26, identifier:tag; 27, slice; 27, 28; 27, 30; 28, unary_operator:-; 28, 29; 29, integer:2; 30, colon; 31, function_definition; 31, 32; 31, 33; 31, 35; 32, function_name:strip_country_code; 33, parameters; 33, 34; 34, identifier:tag; 35, block; 35, 36; 36, return_statement; 36, 37; 37, subscript; 37, 38; 37, 39; 38, identifier:tag; 39, slice; 39, 40; 39, 41; 40, colon; 41, unary_operator:-; 41, 42; 42, integer:2; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:replacements; 46, call; 46, 47; 46, 48; 47, identifier:list; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:tagset; 54, identifier:items; 55, argument_list; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:str; 59, string:""; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:domestic; 63, list_comprehension; 63, 64; 63, 65; 63, 68; 64, identifier:t; 65, for_in_clause; 65, 66; 65, 67; 66, identifier:t; 67, identifier:replacements; 68, if_clause; 68, 69; 69, not_operator; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:is_international; 72, argument_list; 72, 73; 73, subscript; 73, 74; 73, 75; 74, identifier:t; 75, integer:0; 76, for_statement; 76, 77; 76, 80; 76, 81; 77, pattern_list; 77, 78; 77, 79; 78, identifier:key; 79, identifier:replacement; 80, identifier:domestic; 81, block; 81, 82; 82, try_statement; 82, 83; 82, 94; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:str; 87, binary_operator:+; 87, 88; 87, 89; 88, identifier:str; 89, binary_operator:%; 89, 90; 89, 91; 90, identifier:replacement; 91, subscript; 91, 92; 91, 93; 92, identifier:values; 93, identifier:key; 94, except_clause; 94, 95; 94, 99; 95, as_pattern; 95, 96; 95, 97; 96, identifier:KeyError; 97, as_pattern_target; 97, 98; 98, identifier:e; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:mandatory; 104, block; 104, 105; 105, raise_statement; 105, 106; 106, identifier:e; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:international; 110, list_comprehension; 110, 111; 110, 112; 110, 115; 111, identifier:t; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:t; 114, identifier:replacements; 115, if_clause; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:is_international; 118, argument_list; 118, 119; 119, subscript; 119, 120; 119, 121; 120, identifier:t; 121, integer:0; 122, for_statement; 122, 123; 122, 126; 122, 127; 123, pattern_list; 123, 124; 123, 125; 124, identifier:key; 125, identifier:replacement; 126, identifier:international; 127, block; 127, 128; 128, try_statement; 128, 129; 128, 180; 129, block; 129, 130; 129, 151; 129, 168; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:x; 133, list_comprehension; 133, 134; 133, 135; 133, 142; 134, identifier:t; 135, for_in_clause; 135, 136; 135, 137; 136, identifier:t; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:values; 140, identifier:items; 141, argument_list; 142, if_clause; 142, 143; 143, comparison_operator:==; 143, 144; 143, 150; 144, call; 144, 145; 144, 146; 145, identifier:strip_country_code; 146, argument_list; 146, 147; 147, subscript; 147, 148; 147, 149; 148, identifier:t; 149, integer:0; 150, identifier:key; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:int_values_for_key; 154, list_comprehension; 154, 155; 154, 165; 155, tuple; 155, 156; 155, 162; 156, call; 156, 157; 156, 158; 157, identifier:get_country_code; 158, argument_list; 158, 159; 159, subscript; 159, 160; 159, 161; 160, identifier:t; 161, integer:0; 162, subscript; 162, 163; 162, 164; 163, identifier:t; 164, integer:1; 165, for_in_clause; 165, 166; 165, 167; 166, identifier:t; 167, identifier:x; 168, for_statement; 168, 169; 168, 170; 168, 171; 169, identifier:v; 170, identifier:int_values_for_key; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:str; 175, binary_operator:+; 175, 176; 175, 177; 176, identifier:str; 177, binary_operator:%; 177, 178; 177, 179; 178, identifier:replacement; 179, identifier:v; 180, except_clause; 180, 181; 180, 185; 181, as_pattern; 181, 182; 181, 183; 182, identifier:KeyError; 183, as_pattern_target; 183, 184; 184, identifier:e; 185, block; 185, 186; 186, if_statement; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:mandatory; 190, block; 190, 191; 191, raise_statement; 191, 192; 192, identifier:e; 193, return_statement; 193, 194; 194, identifier:str
def compile(self, values): def is_international(tag): return tag.endswith('_') def get_country_code(tag): return tag[-2:] def strip_country_code(tag): return tag[:-2] replacements = list(self.tagset.items()) str = "" domestic = [t for t in replacements if not is_international(t[0])] for key, replacement in domestic: try: str = str + replacement % values[key] except KeyError as e: if self.mandatory: raise e international = [t for t in replacements if is_international(t[0])] for key, replacement in international: try: x = [t for t in values.items() if strip_country_code(t[0]) == key] int_values_for_key = [(get_country_code(t[0]),t[1]) for t in x] for v in int_values_for_key: str = str + replacement % v except KeyError as e: if self.mandatory: raise e return str
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:FromReadings; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 12; 3, 15; 3, 20; 3, 23; 3, 26; 4, identifier:cls; 5, identifier:uuid; 6, identifier:readings; 7, default_parameter; 7, 8; 7, 9; 8, identifier:root_key; 9, attribute; 9, 10; 9, 11; 10, identifier:AuthProvider; 11, identifier:NoKey; 12, default_parameter; 12, 13; 12, 14; 13, identifier:signer; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:report_id; 17, attribute; 17, 18; 17, 19; 18, identifier:IOTileReading; 19, identifier:InvalidReadingID; 20, default_parameter; 20, 21; 20, 22; 21, identifier:selector; 22, integer:0xFFFF; 23, default_parameter; 23, 24; 23, 25; 24, identifier:streamer; 25, integer:0; 26, default_parameter; 26, 27; 26, 28; 27, identifier:sent_timestamp; 28, integer:0; 29, block; 29, 30; 29, 36; 29, 42; 29, 55; 29, 61; 29, 67; 29, 85; 29, 107; 29, 127; 29, 134; 29, 140; 29, 173; 29, 184; 29, 195; 29, 261; 29, 296; 29, 315; 29, 322; 29, 328; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:lowest_id; 33, attribute; 33, 34; 33, 35; 34, identifier:IOTileReading; 35, identifier:InvalidReadingID; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:highest_id; 39, attribute; 39, 40; 39, 41; 40, identifier:IOTileReading; 41, identifier:InvalidReadingID; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:report_len; 45, binary_operator:+; 45, 46; 45, 54; 46, binary_operator:+; 46, 47; 46, 48; 47, integer:20; 48, binary_operator:*; 48, 49; 48, 50; 49, integer:16; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:readings; 54, integer:24; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:len_low; 58, binary_operator:&; 58, 59; 58, 60; 59, identifier:report_len; 60, integer:0xFF; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:len_high; 64, binary_operator:>>; 64, 65; 64, 66; 65, identifier:report_len; 66, integer:8; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:unique_readings; 70, list_comprehension; 70, 71; 70, 74; 70, 77; 71, attribute; 71, 72; 71, 73; 72, identifier:x; 73, identifier:reading_id; 74, for_in_clause; 74, 75; 74, 76; 75, identifier:x; 76, identifier:readings; 77, if_clause; 77, 78; 78, comparison_operator:!=; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:x; 81, identifier:reading_id; 82, attribute; 82, 83; 82, 84; 83, identifier:IOTileReading; 84, identifier:InvalidReadingID; 85, if_statement; 85, 86; 85, 92; 86, comparison_operator:>; 86, 87; 86, 91; 87, call; 87, 88; 87, 89; 88, identifier:len; 89, argument_list; 89, 90; 90, identifier:unique_readings; 91, integer:0; 92, block; 92, 93; 92, 100; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:lowest_id; 96, call; 96, 97; 96, 98; 97, identifier:min; 98, argument_list; 98, 99; 99, identifier:unique_readings; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:highest_id; 103, call; 103, 104; 103, 105; 104, identifier:max; 105, argument_list; 105, 106; 106, identifier:unique_readings; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:header; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:struct; 113, identifier:pack; 114, argument_list; 114, 115; 114, 116; 114, 119; 114, 120; 114, 121; 114, 122; 114, 123; 114, 124; 114, 125; 114, 126; 115, string:"<BBHLLLBBH"; 116, attribute; 116, 117; 116, 118; 117, identifier:cls; 118, identifier:ReportType; 119, identifier:len_low; 120, identifier:len_high; 121, identifier:uuid; 122, identifier:report_id; 123, identifier:sent_timestamp; 124, identifier:root_key; 125, identifier:streamer; 126, identifier:selector; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:header; 130, call; 130, 131; 130, 132; 131, identifier:bytearray; 132, argument_list; 132, 133; 133, identifier:header; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:packed_readings; 137, call; 137, 138; 137, 139; 138, identifier:bytearray; 139, argument_list; 140, for_statement; 140, 141; 140, 142; 140, 143; 141, identifier:reading; 142, identifier:readings; 143, block; 143, 144; 143, 166; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:packed_reading; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:struct; 150, identifier:pack; 151, argument_list; 151, 152; 151, 153; 151, 156; 151, 157; 151, 160; 151, 163; 152, string:"<HHLLL"; 153, attribute; 153, 154; 153, 155; 154, identifier:reading; 155, identifier:stream; 156, integer:0; 157, attribute; 157, 158; 157, 159; 158, identifier:reading; 159, identifier:reading_id; 160, attribute; 160, 161; 160, 162; 161, identifier:reading; 162, identifier:raw_time; 163, attribute; 163, 164; 163, 165; 164, identifier:reading; 165, identifier:value; 166, expression_statement; 166, 167; 167, augmented_assignment:+=; 167, 168; 167, 169; 168, identifier:packed_readings; 169, call; 169, 170; 169, 171; 170, identifier:bytearray; 171, argument_list; 171, 172; 172, identifier:packed_reading; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:footer_stats; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:struct; 179, identifier:pack; 180, argument_list; 180, 181; 180, 182; 180, 183; 181, string:"<LL"; 182, identifier:lowest_id; 183, identifier:highest_id; 184, if_statement; 184, 185; 184, 188; 185, comparison_operator:is; 185, 186; 185, 187; 186, identifier:signer; 187, None; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:signer; 192, call; 192, 193; 192, 194; 193, identifier:ChainedAuthProvider; 194, argument_list; 195, if_statement; 195, 196; 195, 201; 195, 251; 196, comparison_operator:!=; 196, 197; 196, 198; 197, identifier:root_key; 198, attribute; 198, 199; 198, 200; 199, identifier:signer; 200, identifier:NoKey; 201, block; 201, 202; 201, 206; 201, 241; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:enc_data; 205, identifier:packed_readings; 206, try_statement; 206, 207; 206, 225; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:result; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:signer; 214, identifier:encrypt_report; 215, argument_list; 215, 216; 215, 217; 215, 218; 215, 219; 215, 222; 216, identifier:uuid; 217, identifier:root_key; 218, identifier:enc_data; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:report_id; 221, identifier:report_id; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:sent_timestamp; 224, identifier:sent_timestamp; 225, except_clause; 225, 226; 225, 227; 226, identifier:NotFoundError; 227, block; 227, 228; 228, raise_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:ExternalError; 231, argument_list; 231, 232; 231, 235; 231, 238; 232, concatenated_string; 232, 233; 232, 234; 233, string:"Could not encrypt report because no AuthProvider supported "; 234, string:"the requested encryption method for the requested device"; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:device_id; 237, identifier:uuid; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:root_key; 240, identifier:root_key; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:signed_data; 244, binary_operator:+; 244, 245; 244, 250; 245, binary_operator:+; 245, 246; 245, 247; 246, identifier:header; 247, subscript; 247, 248; 247, 249; 248, identifier:result; 249, string:'data'; 250, identifier:footer_stats; 251, else_clause; 251, 252; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:signed_data; 256, binary_operator:+; 256, 257; 256, 260; 257, binary_operator:+; 257, 258; 257, 259; 258, identifier:header; 259, identifier:packed_readings; 260, identifier:footer_stats; 261, try_statement; 261, 262; 261, 280; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:signature; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:signer; 269, identifier:sign_report; 270, argument_list; 270, 271; 270, 272; 270, 273; 270, 274; 270, 277; 271, identifier:uuid; 272, identifier:root_key; 273, identifier:signed_data; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:report_id; 276, identifier:report_id; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:sent_timestamp; 279, identifier:sent_timestamp; 280, except_clause; 280, 281; 280, 282; 281, identifier:NotFoundError; 282, block; 282, 283; 283, raise_statement; 283, 284; 284, call; 284, 285; 284, 286; 285, identifier:ExternalError; 286, argument_list; 286, 287; 286, 290; 286, 293; 287, concatenated_string; 287, 288; 287, 289; 288, string:"Could not sign report because no AuthProvider supported the requested "; 289, string:"signature method for the requested device"; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:device_id; 292, identifier:uuid; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:root_key; 295, identifier:root_key; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:footer; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:struct; 302, identifier:pack; 303, argument_list; 303, 304; 303, 305; 304, string:"16s"; 305, call; 305, 306; 305, 307; 306, identifier:bytes; 307, argument_list; 307, 308; 308, subscript; 308, 309; 308, 312; 309, subscript; 309, 310; 309, 311; 310, identifier:signature; 311, string:'signature'; 312, slice; 312, 313; 312, 314; 313, colon; 314, integer:16; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:footer; 318, call; 318, 319; 318, 320; 319, identifier:bytearray; 320, argument_list; 320, 321; 321, identifier:footer; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:data; 325, binary_operator:+; 325, 326; 325, 327; 326, identifier:signed_data; 327, identifier:footer; 328, return_statement; 328, 329; 329, call; 329, 330; 329, 331; 330, identifier:SignedListReport; 331, argument_list; 331, 332; 332, identifier:data
def FromReadings(cls, uuid, readings, root_key=AuthProvider.NoKey, signer=None, report_id=IOTileReading.InvalidReadingID, selector=0xFFFF, streamer=0, sent_timestamp=0): lowest_id = IOTileReading.InvalidReadingID highest_id = IOTileReading.InvalidReadingID report_len = 20 + 16*len(readings) + 24 len_low = report_len & 0xFF len_high = report_len >> 8 unique_readings = [x.reading_id for x in readings if x.reading_id != IOTileReading.InvalidReadingID] if len(unique_readings) > 0: lowest_id = min(unique_readings) highest_id = max(unique_readings) header = struct.pack("<BBHLLLBBH", cls.ReportType, len_low, len_high, uuid, report_id, sent_timestamp, root_key, streamer, selector) header = bytearray(header) packed_readings = bytearray() for reading in readings: packed_reading = struct.pack("<HHLLL", reading.stream, 0, reading.reading_id, reading.raw_time, reading.value) packed_readings += bytearray(packed_reading) footer_stats = struct.pack("<LL", lowest_id, highest_id) if signer is None: signer = ChainedAuthProvider() if root_key != signer.NoKey: enc_data = packed_readings try: result = signer.encrypt_report(uuid, root_key, enc_data, report_id=report_id, sent_timestamp=sent_timestamp) except NotFoundError: raise ExternalError("Could not encrypt report because no AuthProvider supported " "the requested encryption method for the requested device", device_id=uuid, root_key=root_key) signed_data = header + result['data'] + footer_stats else: signed_data = header + packed_readings + footer_stats try: signature = signer.sign_report(uuid, root_key, signed_data, report_id=report_id, sent_timestamp=sent_timestamp) except NotFoundError: raise ExternalError("Could not sign report because no AuthProvider supported the requested " "signature method for the requested device", device_id=uuid, root_key=root_key) footer = struct.pack("16s", bytes(signature['signature'][:16])) footer = bytearray(footer) data = signed_data + footer return SignedListReport(data)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:format_snippet; 3, parameters; 3, 4; 4, identifier:sensor_graph; 5, block; 5, 6; 5, 10; 5, 17; 5, 24; 5, 31; 5, 51; 5, 105; 5, 145; 5, 152; 5, 159; 5, 170; 5, 181; 5, 220; 5, 227; 5, 234; 5, 304; 5, 311; 5, 318; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:output; 9, list:[]; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:output; 14, identifier:append; 15, argument_list; 15, 16; 16, string:"disable"; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:output; 21, identifier:append; 22, argument_list; 22, 23; 23, string:"clear"; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:output; 28, identifier:append; 29, argument_list; 29, 30; 30, string:"reset"; 31, for_statement; 31, 32; 31, 33; 31, 38; 32, identifier:node; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:sensor_graph; 36, identifier:dump_nodes; 37, argument_list; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:output; 43, identifier:append; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, string:'add_node "{}"'; 48, identifier:format; 49, argument_list; 49, 50; 50, identifier:node; 51, for_statement; 51, 52; 51, 53; 51, 56; 52, identifier:streamer; 53, attribute; 53, 54; 53, 55; 54, identifier:sensor_graph; 55, identifier:streamers; 56, block; 56, 57; 56, 80; 56, 98; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:line; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, string:"add_streamer '{}' '{}' {} {} {}"; 63, identifier:format; 64, argument_list; 64, 65; 64, 68; 64, 71; 64, 74; 64, 77; 65, attribute; 65, 66; 65, 67; 66, identifier:streamer; 67, identifier:selector; 68, attribute; 68, 69; 68, 70; 69, identifier:streamer; 70, identifier:dest; 71, attribute; 71, 72; 71, 73; 72, identifier:streamer; 73, identifier:automatic; 74, attribute; 74, 75; 74, 76; 75, identifier:streamer; 76, identifier:format; 77, attribute; 77, 78; 77, 79; 78, identifier:streamer; 79, identifier:report_type; 80, if_statement; 80, 81; 80, 86; 81, comparison_operator:is; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:streamer; 84, identifier:with_other; 85, None; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, augmented_assignment:+=; 88, 89; 88, 90; 89, identifier:line; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, string:' --withother {}'; 93, identifier:format; 94, argument_list; 94, 95; 95, attribute; 95, 96; 95, 97; 96, identifier:streamer; 97, identifier:with_other; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:output; 102, identifier:append; 103, argument_list; 103, 104; 104, identifier:line; 105, for_statement; 105, 106; 105, 109; 105, 131; 106, pattern_list; 106, 107; 106, 108; 107, identifier:stream; 108, identifier:value; 109, call; 109, 110; 109, 111; 110, identifier:sorted; 111, argument_list; 111, 112; 111, 119; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:sensor_graph; 116, identifier:constant_database; 117, identifier:items; 118, argument_list; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:key; 121, lambda; 121, 122; 121, 124; 122, lambda_parameters; 122, 123; 123, identifier:x; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:x; 128, integer:0; 129, identifier:encode; 130, argument_list; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:output; 136, identifier:append; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, string:"set_constant '{}' {}"; 141, identifier:format; 142, argument_list; 142, 143; 142, 144; 143, identifier:stream; 144, identifier:value; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:output; 149, identifier:append; 150, argument_list; 150, 151; 151, string:"persist"; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:output; 156, identifier:append; 157, argument_list; 157, 158; 158, string:"back"; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:app_tag; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:sensor_graph; 166, identifier:metadata_database; 167, identifier:get; 168, argument_list; 168, 169; 169, string:'app_tag'; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:app_version; 173, call; 173, 174; 173, 179; 174, attribute; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:sensor_graph; 177, identifier:metadata_database; 178, identifier:get; 179, argument_list; 179, 180; 180, string:'app_version'; 181, if_statement; 181, 182; 181, 185; 182, comparison_operator:is; 182, 183; 182, 184; 183, identifier:app_tag; 184, None; 185, block; 185, 186; 185, 195; 185, 202; 185, 213; 186, if_statement; 186, 187; 186, 190; 187, comparison_operator:is; 187, 188; 187, 189; 188, identifier:app_version; 189, None; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:app_version; 194, string:"0.0"; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:output; 199, identifier:append; 200, argument_list; 200, 201; 201, string:"test_interface"; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:output; 206, identifier:append; 207, argument_list; 207, 208; 208, binary_operator:%; 208, 209; 208, 210; 209, string:"set_version app %d --version '%s'"; 210, tuple; 210, 211; 210, 212; 211, identifier:app_tag; 212, identifier:app_version; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:output; 217, identifier:append; 218, argument_list; 218, 219; 219, string:"back"; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:output; 224, identifier:append; 225, argument_list; 225, 226; 226, string:"config_database"; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:output; 231, identifier:append; 232, argument_list; 232, 233; 233, string:"clear_variables"; 234, for_statement; 234, 235; 234, 238; 234, 245; 235, pattern_list; 235, 236; 235, 237; 236, identifier:slot; 237, identifier:conf_vars; 238, call; 238, 239; 238, 244; 239, attribute; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:sensor_graph; 242, identifier:config_database; 243, identifier:items; 244, argument_list; 245, block; 245, 246; 246, for_statement; 246, 247; 246, 250; 246, 255; 247, pattern_list; 247, 248; 247, 249; 248, identifier:conf_var; 249, identifier:conf_def; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:conf_vars; 253, identifier:items; 254, argument_list; 255, block; 255, 256; 255, 262; 255, 289; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 261; 258, pattern_list; 258, 259; 258, 260; 259, identifier:conf_type; 260, identifier:conf_val; 261, identifier:conf_def; 262, if_statement; 262, 263; 262, 266; 262, 276; 263, comparison_operator:==; 263, 264; 263, 265; 264, identifier:conf_type; 265, string:'binary'; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:conf_val; 270, binary_operator:+; 270, 271; 270, 272; 271, string:'hex:'; 272, call; 272, 273; 272, 274; 273, identifier:hexlify; 274, argument_list; 274, 275; 275, identifier:conf_val; 276, elif_clause; 276, 277; 276, 282; 277, call; 277, 278; 277, 279; 278, identifier:isinstance; 279, argument_list; 279, 280; 279, 281; 280, identifier:conf_val; 281, identifier:str; 282, block; 282, 283; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:conf_val; 286, binary_operator:%; 286, 287; 286, 288; 287, string:'"%s"'; 288, identifier:conf_val; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:output; 293, identifier:append; 294, argument_list; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, string:"set_variable '{}' {} {} {}"; 298, identifier:format; 299, argument_list; 299, 300; 299, 301; 299, 302; 299, 303; 300, identifier:slot; 301, identifier:conf_var; 302, identifier:conf_type; 303, identifier:conf_val; 304, expression_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:output; 308, identifier:append; 309, argument_list; 309, 310; 310, string:"back"; 311, expression_statement; 311, 312; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:output; 315, identifier:append; 316, argument_list; 316, 317; 317, string:"reset"; 318, return_statement; 318, 319; 319, binary_operator:+; 319, 320; 319, 326; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, string:"\n"; 323, identifier:join; 324, argument_list; 324, 325; 325, identifier:output; 326, string:'\n'
def format_snippet(sensor_graph): output = [] output.append("disable") output.append("clear") output.append("reset") for node in sensor_graph.dump_nodes(): output.append('add_node "{}"'.format(node)) for streamer in sensor_graph.streamers: line = "add_streamer '{}' '{}' {} {} {}".format(streamer.selector, streamer.dest, streamer.automatic, streamer.format, streamer.report_type) if streamer.with_other is not None: line += ' --withother {}'.format(streamer.with_other) output.append(line) for stream, value in sorted(sensor_graph.constant_database.items(), key=lambda x: x[0].encode()): output.append("set_constant '{}' {}".format(stream, value)) output.append("persist") output.append("back") app_tag = sensor_graph.metadata_database.get('app_tag') app_version = sensor_graph.metadata_database.get('app_version') if app_tag is not None: if app_version is None: app_version = "0.0" output.append("test_interface") output.append("set_version app %d --version '%s'" % (app_tag, app_version)) output.append("back") output.append("config_database") output.append("clear_variables") for slot, conf_vars in sensor_graph.config_database.items(): for conf_var, conf_def in conf_vars.items(): conf_type, conf_val = conf_def if conf_type == 'binary': conf_val = 'hex:' + hexlify(conf_val) elif isinstance(conf_val, str): conf_val = '"%s"' % conf_val output.append("set_variable '{}' {} {} {}".format(slot, conf_var, conf_type, conf_val)) output.append("back") output.append("reset") return "\n".join(output) + '\n'
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_process_scan_event; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:response; 6, block; 6, 7; 6, 13; 6, 22; 6, 28; 6, 44; 6, 70; 6, 98; 6, 104; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:payload; 10, attribute; 10, 11; 10, 12; 11, identifier:response; 12, identifier:payload; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:length; 16, binary_operator:-; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:payload; 21, integer:10; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:<; 23, 24; 23, 25; 24, identifier:length; 25, integer:0; 26, block; 26, 27; 27, return_statement; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 37; 30, pattern_list; 30, 31; 30, 32; 30, 33; 30, 34; 30, 35; 30, 36; 31, identifier:rssi; 32, identifier:packet_type; 33, identifier:sender; 34, identifier:_addr_type; 35, identifier:_bond; 36, identifier:data; 37, call; 37, 38; 37, 39; 38, identifier:unpack; 39, argument_list; 39, 40; 39, 43; 40, binary_operator:%; 40, 41; 40, 42; 41, string:"<bB6sBB%ds"; 42, identifier:length; 43, identifier:payload; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:string_address; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, string:':'; 50, identifier:join; 51, argument_list; 51, 52; 52, list_comprehension; 52, 53; 52, 58; 53, call; 53, 54; 53, 55; 54, identifier:format; 55, argument_list; 55, 56; 55, 57; 56, identifier:x; 57, string:"02X"; 58, for_in_clause; 58, 59; 58, 60; 59, identifier:x; 60, call; 60, 61; 60, 62; 61, identifier:bytearray; 62, argument_list; 62, 63; 63, subscript; 63, 64; 63, 65; 64, identifier:sender; 65, slice; 65, 66; 65, 67; 65, 68; 66, colon; 67, colon; 68, unary_operator:-; 68, 69; 69, integer:1; 70, if_statement; 70, 71; 70, 77; 70, 89; 71, comparison_operator:>; 71, 72; 71, 76; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, identifier:data; 76, integer:0; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:data; 81, call; 81, 82; 81, 83; 82, identifier:bytearray; 83, argument_list; 83, 84; 84, subscript; 84, 85; 84, 86; 85, identifier:data; 86, slice; 86, 87; 86, 88; 87, integer:1; 88, colon; 89, else_clause; 89, 90; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:data; 94, call; 94, 95; 94, 96; 95, identifier:bytearray; 96, argument_list; 96, 97; 97, list:[]; 98, expression_statement; 98, 99; 99, augmented_assignment:+=; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:_scan_event_count; 103, integer:1; 104, if_statement; 104, 105; 104, 111; 104, 198; 105, comparison_operator:in; 105, 106; 105, 107; 106, identifier:packet_type; 107, tuple; 107, 108; 107, 109; 107, 110; 108, integer:0; 109, integer:2; 110, integer:6; 111, block; 111, 112; 111, 121; 112, if_statement; 112, 113; 112, 119; 113, comparison_operator:!=; 113, 114; 113, 118; 114, call; 114, 115; 114, 116; 115, identifier:len; 116, argument_list; 116, 117; 117, identifier:data; 118, integer:31; 119, block; 119, 120; 120, return_statement; 121, if_statement; 121, 122; 121, 139; 121, 155; 121, 195; 122, boolean_operator:and; 122, 123; 122, 134; 123, boolean_operator:and; 123, 124; 123, 129; 124, comparison_operator:==; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:data; 127, integer:22; 128, integer:0xFF; 129, comparison_operator:==; 129, 130; 129, 133; 130, subscript; 130, 131; 130, 132; 131, identifier:data; 132, integer:23; 133, integer:0xC0; 134, comparison_operator:==; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:data; 137, integer:24; 138, integer:0x3; 139, block; 139, 140; 139, 146; 140, expression_statement; 140, 141; 141, augmented_assignment:+=; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:_v1_scan_count; 145, integer:1; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:_parse_v1_advertisement; 151, argument_list; 151, 152; 151, 153; 151, 154; 152, identifier:rssi; 153, identifier:string_address; 154, identifier:data; 155, elif_clause; 155, 156; 155, 179; 156, boolean_operator:and; 156, 157; 156, 174; 157, boolean_operator:and; 157, 158; 157, 169; 158, boolean_operator:and; 158, 159; 158, 164; 159, comparison_operator:==; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:data; 162, integer:3; 163, integer:27; 164, comparison_operator:==; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:data; 167, integer:4; 168, integer:0x16; 169, comparison_operator:==; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:data; 172, integer:5; 173, integer:0xdd; 174, comparison_operator:==; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:data; 177, integer:6; 178, integer:0xfd; 179, block; 179, 180; 179, 186; 180, expression_statement; 180, 181; 181, augmented_assignment:+=; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:_v2_scan_count; 185, integer:1; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:_parse_v2_advertisement; 191, argument_list; 191, 192; 191, 193; 191, 194; 192, identifier:rssi; 193, identifier:string_address; 194, identifier:data; 195, else_clause; 195, 196; 196, block; 196, 197; 197, pass_statement; 198, elif_clause; 198, 199; 198, 202; 199, comparison_operator:==; 199, 200; 199, 201; 200, identifier:packet_type; 201, integer:4; 202, block; 202, 203; 202, 209; 203, expression_statement; 203, 204; 204, augmented_assignment:+=; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:_v1_scan_response_count; 208, integer:1; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:_parse_v1_scan_response; 214, argument_list; 214, 215; 214, 216; 215, identifier:string_address; 216, identifier:data
def _process_scan_event(self, response): payload = response.payload length = len(payload) - 10 if length < 0: return rssi, packet_type, sender, _addr_type, _bond, data = unpack("<bB6sBB%ds" % length, payload) string_address = ':'.join([format(x, "02X") for x in bytearray(sender[::-1])]) if len(data) > 0: data = bytearray(data[1:]) else: data = bytearray([]) self._scan_event_count += 1 if packet_type in (0, 2, 6): if len(data) != 31: return if data[22] == 0xFF and data[23] == 0xC0 and data[24] == 0x3: self._v1_scan_count += 1 self._parse_v1_advertisement(rssi, string_address, data) elif data[3] == 27 and data[4] == 0x16 and data[5] == 0xdd and data[6] == 0xfd: self._v2_scan_count += 1 self._parse_v2_advertisement(rssi, string_address, data) else: pass elif packet_type == 4: self._v1_scan_response_count += 1 self._parse_v1_scan_response(string_address, data)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_check_ver_range; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:version; 6, identifier:ver_range; 7, block; 7, 8; 7, 16; 7, 27; 7, 51; 7, 75; 7, 133; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 15; 10, pattern_list; 10, 11; 10, 12; 10, 13; 10, 14; 11, identifier:lower; 12, identifier:upper; 13, identifier:lower_inc; 14, identifier:upper_inc; 15, identifier:ver_range; 16, if_statement; 16, 17; 16, 24; 17, boolean_operator:and; 17, 18; 17, 21; 18, comparison_operator:is; 18, 19; 18, 20; 19, identifier:lower; 20, None; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:upper; 23, None; 24, block; 24, 25; 25, return_statement; 25, 26; 26, True; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:lower; 30, None; 31, block; 31, 32; 32, if_statement; 32, 33; 32, 38; 32, 41; 33, boolean_operator:and; 33, 34; 33, 35; 34, identifier:lower_inc; 35, comparison_operator:<; 35, 36; 35, 37; 36, identifier:version; 37, identifier:lower; 38, block; 38, 39; 39, return_statement; 39, 40; 40, False; 41, elif_clause; 41, 42; 41, 48; 42, boolean_operator:and; 42, 43; 42, 45; 43, not_operator; 43, 44; 44, identifier:lower_inc; 45, comparison_operator:<=; 45, 46; 45, 47; 46, identifier:version; 47, identifier:lower; 48, block; 48, 49; 49, return_statement; 49, 50; 50, False; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:upper; 54, None; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 62; 56, 65; 57, boolean_operator:and; 57, 58; 57, 59; 58, identifier:upper_inc; 59, comparison_operator:>; 59, 60; 59, 61; 60, identifier:version; 61, identifier:upper; 62, block; 62, 63; 63, return_statement; 63, 64; 64, False; 65, elif_clause; 65, 66; 65, 72; 66, boolean_operator:and; 66, 67; 66, 69; 67, not_operator; 67, 68; 68, identifier:upper_inc; 69, comparison_operator:>=; 69, 70; 69, 71; 70, identifier:version; 71, identifier:upper; 72, block; 72, 73; 73, return_statement; 73, 74; 74, False; 75, if_statement; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:version; 78, identifier:is_prerelease; 79, block; 79, 80; 79, 103; 80, if_statement; 80, 81; 80, 100; 81, boolean_operator:and; 81, 82; 81, 91; 82, parenthesized_expression; 82, 83; 83, boolean_operator:or; 83, 84; 83, 87; 84, comparison_operator:is; 84, 85; 84, 86; 85, identifier:lower; 86, None; 87, not_operator; 87, 88; 88, attribute; 88, 89; 88, 90; 89, identifier:lower; 90, identifier:is_prerelease; 91, parenthesized_expression; 91, 92; 92, boolean_operator:or; 92, 93; 92, 96; 93, comparison_operator:is; 93, 94; 93, 95; 94, identifier:upper; 95, None; 96, not_operator; 96, 97; 97, attribute; 97, 98; 97, 99; 98, identifier:upper; 99, identifier:is_prerelease; 100, block; 100, 101; 101, return_statement; 101, 102; 102, False; 103, if_statement; 103, 104; 103, 130; 104, boolean_operator:and; 104, 105; 104, 117; 104, 118; 105, parenthesized_expression; 105, 106; 106, boolean_operator:and; 106, 107; 106, 110; 107, comparison_operator:is; 107, 108; 107, 109; 108, identifier:lower; 109, None; 110, comparison_operator:!=; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:version; 113, identifier:release_tuple; 114, attribute; 114, 115; 114, 116; 115, identifier:lower; 116, identifier:release_tuple; 117, line_continuation:\; 118, parenthesized_expression; 118, 119; 119, boolean_operator:and; 119, 120; 119, 123; 120, comparison_operator:is; 120, 121; 120, 122; 121, identifier:upper; 122, None; 123, comparison_operator:!=; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:version; 126, identifier:release_tuple; 127, attribute; 127, 128; 127, 129; 128, identifier:upper; 129, identifier:release_tuple; 130, block; 130, 131; 131, return_statement; 131, 132; 132, False; 133, return_statement; 133, 134; 134, True
def _check_ver_range(self, version, ver_range): lower, upper, lower_inc, upper_inc = ver_range if lower is None and upper is None: return True if lower is not None: if lower_inc and version < lower: return False elif not lower_inc and version <= lower: return False if upper is not None: if upper_inc and version > upper: return False elif not upper_inc and version >= upper: return False if version.is_prerelease: if (lower is None or not lower.is_prerelease) and (upper is None or not upper.is_prerelease): return False if (lower is not None and version.release_tuple != lower.release_tuple) and \ (upper is not None and version.release_tuple != upper.release_tuple): return False return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:is_LaTeX; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:flist; 5, identifier:env; 6, identifier:abspath; 7, block; 7, 8; 7, 17; 7, 25; 7, 49; 7, 76; 7, 91; 7, 246; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:savedpath; 11, call; 11, 12; 11, 13; 12, identifier:modify_env_var; 13, argument_list; 13, 14; 13, 15; 13, 16; 14, identifier:env; 15, string:'TEXINPUTS'; 16, identifier:abspath; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:paths; 20, subscript; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:env; 23, string:'ENV'; 24, string:'TEXINPUTS'; 25, if_statement; 25, 26; 25, 34; 25, 36; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:SCons; 30, identifier:Util; 31, identifier:is_List; 32, argument_list; 32, 33; 33, identifier:paths; 34, block; 34, 35; 35, pass_statement; 36, else_clause; 36, 37; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:paths; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:paths; 44, identifier:split; 45, argument_list; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:os; 48, identifier:pathsep; 49, if_statement; 49, 50; 49, 53; 49, 66; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:savedpath; 52, identifier:_null; 53, block; 53, 54; 54, try_statement; 54, 55; 54, 62; 55, block; 55, 56; 56, delete_statement; 56, 57; 57, subscript; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:env; 60, string:'ENV'; 61, string:'TEXINPUTS'; 62, except_clause; 62, 63; 62, 64; 63, identifier:KeyError; 64, block; 64, 65; 65, pass_statement; 66, else_clause; 66, 67; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 75; 70, subscript; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:env; 73, string:'ENV'; 74, string:'TEXINPUTS'; 75, identifier:savedpath; 76, if_statement; 76, 77; 76, 78; 77, identifier:Verbose; 78, block; 78, 79; 78, 85; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:print; 82, argument_list; 82, 83; 82, 84; 83, string:"is_LaTeX search path "; 84, identifier:paths; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:print; 88, argument_list; 88, 89; 88, 90; 89, string:"files to search :"; 90, identifier:flist; 91, for_statement; 91, 92; 91, 93; 91, 94; 92, identifier:f; 93, identifier:flist; 94, block; 94, 95; 94, 107; 94, 115; 94, 138; 94, 151; 94, 155; 94, 167; 94, 181; 94, 234; 95, if_statement; 95, 96; 95, 97; 96, identifier:Verbose; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:print; 101, argument_list; 101, 102; 101, 103; 102, string:" checking for Latex source "; 103, call; 103, 104; 103, 105; 104, identifier:str; 105, argument_list; 105, 106; 106, identifier:f; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:content; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:f; 113, identifier:get_text_contents; 114, argument_list; 115, if_statement; 115, 116; 115, 122; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:LaTeX_re; 119, identifier:search; 120, argument_list; 120, 121; 121, identifier:content; 122, block; 122, 123; 122, 136; 123, if_statement; 123, 124; 123, 125; 124, identifier:Verbose; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:print; 129, argument_list; 129, 130; 130, binary_operator:%; 130, 131; 130, 132; 131, string:"file %s is a LaTeX file"; 132, call; 132, 133; 132, 134; 133, identifier:str; 134, argument_list; 134, 135; 135, identifier:f; 136, return_statement; 136, 137; 137, integer:1; 138, if_statement; 138, 139; 138, 140; 139, identifier:Verbose; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:print; 144, argument_list; 144, 145; 145, binary_operator:%; 145, 146; 145, 147; 146, string:"file %s is not a LaTeX file"; 147, call; 147, 148; 147, 149; 148, identifier:str; 149, argument_list; 149, 150; 150, identifier:f; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:inc_files; 154, list:[ ]; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:inc_files; 159, identifier:extend; 160, argument_list; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:include_re; 164, identifier:findall; 165, argument_list; 165, 166; 166, identifier:content; 167, if_statement; 167, 168; 167, 169; 168, identifier:Verbose; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:print; 173, argument_list; 173, 174; 173, 180; 174, binary_operator:%; 174, 175; 174, 176; 175, string:"files included by '%s': "; 176, call; 176, 177; 176, 178; 177, identifier:str; 178, argument_list; 178, 179; 179, identifier:f; 180, identifier:inc_files; 181, for_statement; 181, 182; 181, 183; 181, 184; 182, identifier:src; 183, identifier:inc_files; 184, block; 184, 185; 184, 201; 184, 206; 184, 215; 184, 229; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:srcNode; 188, call; 188, 189; 188, 190; 189, identifier:FindFile; 190, argument_list; 190, 191; 190, 192; 190, 196; 190, 197; 190, 198; 191, identifier:src; 192, list:['.tex','.ltx','.latex']; 192, 193; 192, 194; 192, 195; 193, string:'.tex'; 194, string:'.ltx'; 195, string:'.latex'; 196, identifier:paths; 197, identifier:env; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:requireExt; 200, False; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:fileList; 204, list:[srcNode,]; 204, 205; 205, identifier:srcNode; 206, if_statement; 206, 207; 206, 208; 207, identifier:Verbose; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 212; 211, identifier:print; 212, argument_list; 212, 213; 212, 214; 213, string:"FindFile found "; 214, identifier:srcNode; 215, if_statement; 215, 216; 215, 219; 216, comparison_operator:is; 216, 217; 216, 218; 217, identifier:srcNode; 218, None; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:file_test; 223, call; 223, 224; 223, 225; 224, identifier:is_LaTeX; 225, argument_list; 225, 226; 225, 227; 225, 228; 226, identifier:fileList; 227, identifier:env; 228, identifier:abspath; 229, if_statement; 229, 230; 229, 231; 230, identifier:file_test; 231, block; 231, 232; 232, return_statement; 232, 233; 233, identifier:file_test; 234, if_statement; 234, 235; 234, 236; 235, identifier:Verbose; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 240; 239, identifier:print; 240, argument_list; 240, 241; 240, 242; 241, string:" done scanning "; 242, call; 242, 243; 242, 244; 243, identifier:str; 244, argument_list; 244, 245; 245, identifier:f; 246, return_statement; 246, 247; 247, integer:0
def is_LaTeX(flist,env,abspath): savedpath = modify_env_var(env, 'TEXINPUTS', abspath) paths = env['ENV']['TEXINPUTS'] if SCons.Util.is_List(paths): pass else: paths = paths.split(os.pathsep) if savedpath is _null: try: del env['ENV']['TEXINPUTS'] except KeyError: pass else: env['ENV']['TEXINPUTS'] = savedpath if Verbose: print("is_LaTeX search path ",paths) print("files to search :",flist) for f in flist: if Verbose: print(" checking for Latex source ",str(f)) content = f.get_text_contents() if LaTeX_re.search(content): if Verbose: print("file %s is a LaTeX file" % str(f)) return 1 if Verbose: print("file %s is not a LaTeX file" % str(f)) inc_files = [ ] inc_files.extend( include_re.findall(content) ) if Verbose: print("files included by '%s': "%str(f),inc_files) for src in inc_files: srcNode = FindFile(src,['.tex','.ltx','.latex'],paths,env,requireExt=False) fileList = [srcNode,] if Verbose: print("FindFile found ",srcNode) if srcNode is not None: file_test = is_LaTeX(fileList, env, abspath) if file_test: return file_test if Verbose: print(" done scanning ",str(f)) return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:processDefines; 3, parameters; 3, 4; 4, identifier:defs; 5, block; 5, 6; 5, 250; 6, if_statement; 6, 7; 6, 15; 6, 179; 6, 240; 7, call; 7, 8; 7, 13; 8, attribute; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:SCons; 11, identifier:Util; 12, identifier:is_List; 13, argument_list; 13, 14; 14, identifier:defs; 15, block; 15, 16; 15, 20; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:l; 19, list:[]; 20, for_statement; 20, 21; 20, 22; 20, 23; 21, identifier:d; 22, identifier:defs; 23, block; 23, 24; 24, if_statement; 24, 25; 24, 28; 24, 30; 24, 89; 24, 143; 24, 163; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:d; 27, None; 28, block; 28, 29; 29, continue_statement; 30, elif_clause; 30, 31; 30, 45; 31, boolean_operator:or; 31, 32; 31, 40; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:SCons; 36, identifier:Util; 37, identifier:is_List; 38, argument_list; 38, 39; 39, identifier:d; 40, call; 40, 41; 40, 42; 41, identifier:isinstance; 42, argument_list; 42, 43; 42, 44; 43, identifier:d; 44, identifier:tuple; 45, block; 45, 46; 46, if_statement; 46, 47; 46, 53; 46, 75; 47, comparison_operator:>=; 47, 48; 47, 52; 48, call; 48, 49; 48, 50; 49, identifier:len; 50, argument_list; 50, 51; 51, identifier:d; 52, integer:2; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:l; 58, identifier:append; 59, argument_list; 59, 60; 60, binary_operator:+; 60, 61; 60, 69; 61, binary_operator:+; 61, 62; 61, 68; 62, call; 62, 63; 62, 64; 63, identifier:str; 64, argument_list; 64, 65; 65, subscript; 65, 66; 65, 67; 66, identifier:d; 67, integer:0; 68, string:'='; 69, call; 69, 70; 69, 71; 70, identifier:str; 71, argument_list; 71, 72; 72, subscript; 72, 73; 72, 74; 73, identifier:d; 74, integer:1; 75, else_clause; 75, 76; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:l; 81, identifier:append; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:str; 85, argument_list; 85, 86; 86, subscript; 86, 87; 86, 88; 87, identifier:d; 88, integer:0; 89, elif_clause; 89, 90; 89, 98; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:SCons; 94, identifier:Util; 95, identifier:is_Dict; 96, argument_list; 96, 97; 97, identifier:d; 98, block; 98, 99; 99, for_statement; 99, 100; 99, 103; 99, 108; 100, pattern_list; 100, 101; 100, 102; 101, identifier:macro; 102, identifier:value; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:d; 106, identifier:items; 107, argument_list; 108, block; 108, 109; 109, if_statement; 109, 110; 109, 113; 109, 131; 110, comparison_operator:is; 110, 111; 110, 112; 111, identifier:value; 112, None; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:l; 118, identifier:append; 119, argument_list; 119, 120; 120, binary_operator:+; 120, 121; 120, 127; 121, binary_operator:+; 121, 122; 121, 126; 122, call; 122, 123; 122, 124; 123, identifier:str; 124, argument_list; 124, 125; 125, identifier:macro; 126, string:'='; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:value; 131, else_clause; 131, 132; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:l; 137, identifier:append; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:str; 141, argument_list; 141, 142; 142, identifier:macro; 143, elif_clause; 143, 144; 143, 152; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:SCons; 148, identifier:Util; 149, identifier:is_String; 150, argument_list; 150, 151; 151, identifier:d; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:l; 157, identifier:append; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 161; 160, identifier:str; 161, argument_list; 161, 162; 162, identifier:d; 163, else_clause; 163, 164; 164, block; 164, 165; 165, raise_statement; 165, 166; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:SCons; 170, identifier:Errors; 171, identifier:UserError; 172, argument_list; 172, 173; 173, binary_operator:%; 173, 174; 173, 175; 174, string:"DEFINE %s is not a list, dict, string or None."; 175, call; 175, 176; 175, 177; 176, identifier:repr; 177, argument_list; 177, 178; 178, identifier:d; 179, elif_clause; 179, 180; 179, 188; 180, call; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:SCons; 184, identifier:Util; 185, identifier:is_Dict; 186, argument_list; 186, 187; 187, identifier:defs; 188, block; 188, 189; 188, 193; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:l; 192, list:[]; 193, for_statement; 193, 194; 193, 197; 193, 205; 194, pattern_list; 194, 195; 194, 196; 195, identifier:k; 196, identifier:v; 197, call; 197, 198; 197, 199; 198, identifier:sorted; 199, argument_list; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:defs; 203, identifier:items; 204, argument_list; 205, block; 205, 206; 206, if_statement; 206, 207; 206, 210; 206, 221; 207, comparison_operator:is; 207, 208; 207, 209; 208, identifier:v; 209, None; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:l; 215, identifier:append; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 219; 218, identifier:str; 219, argument_list; 219, 220; 220, identifier:k; 221, else_clause; 221, 222; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:l; 227, identifier:append; 228, argument_list; 228, 229; 229, binary_operator:+; 229, 230; 229, 236; 230, binary_operator:+; 230, 231; 230, 235; 231, call; 231, 232; 231, 233; 232, identifier:str; 233, argument_list; 233, 234; 234, identifier:k; 235, string:'='; 236, call; 236, 237; 236, 238; 237, identifier:str; 238, argument_list; 238, 239; 239, identifier:v; 240, else_clause; 240, 241; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:l; 245, list:[str(defs)]; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:str; 248, argument_list; 248, 249; 249, identifier:defs; 250, return_statement; 250, 251; 251, identifier:l
def processDefines(defs): if SCons.Util.is_List(defs): l = [] for d in defs: if d is None: continue elif SCons.Util.is_List(d) or isinstance(d, tuple): if len(d) >= 2: l.append(str(d[0]) + '=' + str(d[1])) else: l.append(str(d[0])) elif SCons.Util.is_Dict(d): for macro,value in d.items(): if value is not None: l.append(str(macro) + '=' + str(value)) else: l.append(str(macro)) elif SCons.Util.is_String(d): l.append(str(d)) else: raise SCons.Errors.UserError("DEFINE %s is not a list, dict, string or None."%repr(d)) elif SCons.Util.is_Dict(defs): l = [] for k,v in sorted(defs.items()): if v is None: l.append(str(k)) else: l.append(str(k) + '=' + str(v)) else: l = [str(defs)] return l
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:local_services; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 24; 6, if_statement; 6, 7; 6, 15; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 14; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_loop; 13, identifier:inside_loop; 14, argument_list; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_state_lock; 22, identifier:acquire; 23, argument_list; 24, try_statement; 24, 25; 24, 53; 25, block; 25, 26; 26, return_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:sorted; 29, argument_list; 29, 30; 29, 45; 30, list_comprehension; 30, 31; 30, 34; 31, tuple; 31, 32; 31, 33; 32, identifier:index; 33, identifier:name; 34, for_in_clause; 34, 35; 34, 38; 35, pattern_list; 35, 36; 35, 37; 36, identifier:index; 37, identifier:name; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_name_map; 43, identifier:items; 44, argument_list; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:key; 47, lambda; 47, 48; 47, 50; 48, lambda_parameters; 48, 49; 49, identifier:element; 50, subscript; 50, 51; 50, 52; 51, identifier:element; 52, integer:0; 53, finally_clause; 53, 54; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 64; 56, not_operator; 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:_loop; 62, identifier:inside_loop; 63, argument_list; 64, block; 64, 65; 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:_state_lock; 71, identifier:release; 72, argument_list
def local_services(self): if not self._loop.inside_loop(): self._state_lock.acquire() try: return sorted([(index, name) for index, name in self._name_map.items()], key=lambda element: element[0]) finally: if not self._loop.inside_loop(): self._state_lock.release()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:generate; 3, parameters; 3, 4; 4, identifier:env; 5, block; 5, 6; 5, 14; 5, 22; 5, 30; 5, 187; 5, 219; 5, 234; 5, 274; 5, 314; 5, 322; 5, 330; 5, 343; 5, 350; 5, 357; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:CLVar; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:SCons; 12, identifier:Util; 13, identifier:CLVar; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:Action; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:SCons; 20, identifier:Action; 21, identifier:Action; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:Builder; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:SCons; 28, identifier:Builder; 29, identifier:Builder; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:env; 34, identifier:SetDefault; 35, argument_list; 35, 36; 35, 42; 35, 53; 35, 64; 35, 75; 35, 86; 35, 97; 35, 100; 35, 103; 35, 109; 35, 115; 35, 121; 35, 127; 35, 130; 35, 133; 35, 136; 35, 139; 35, 142; 35, 145; 35, 148; 35, 151; 35, 154; 35, 171; 35, 175; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:QTDIR; 38, call; 38, 39; 38, 40; 39, identifier:_detect; 40, argument_list; 40, 41; 41, identifier:env; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:QT_BINPATH; 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, string:'$QTDIR'; 52, string:'bin'; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:QT_CPPPATH; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:os; 59, identifier:path; 60, identifier:join; 61, argument_list; 61, 62; 61, 63; 62, string:'$QTDIR'; 63, string:'include'; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:QT_LIBPATH; 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, string:'$QTDIR'; 74, string:'lib'; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:QT_MOC; 77, call; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:os; 81, identifier:path; 82, identifier:join; 83, argument_list; 83, 84; 83, 85; 84, string:'$QT_BINPATH'; 85, string:'moc'; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:QT_UIC; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:os; 92, identifier:path; 93, identifier:join; 94, argument_list; 94, 95; 94, 96; 95, string:'$QT_BINPATH'; 96, string:'uic'; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:QT_LIB; 99, string:'qt'; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:QT_AUTOSCAN; 102, integer:1; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:QT_UICIMPLFLAGS; 105, call; 105, 106; 105, 107; 106, identifier:CLVar; 107, argument_list; 107, 108; 108, string:''; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:QT_UICDECLFLAGS; 111, call; 111, 112; 111, 113; 112, identifier:CLVar; 113, argument_list; 113, 114; 114, string:''; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:QT_MOCFROMHFLAGS; 117, call; 117, 118; 117, 119; 118, identifier:CLVar; 119, argument_list; 119, 120; 120, string:''; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:QT_MOCFROMCXXFLAGS; 123, call; 123, 124; 123, 125; 124, identifier:CLVar; 125, argument_list; 125, 126; 126, string:'-i'; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:QT_UICDECLPREFIX; 129, string:''; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:QT_UICDECLSUFFIX; 132, string:'.h'; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:QT_UICIMPLPREFIX; 135, string:'uic_'; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:QT_UICIMPLSUFFIX; 138, string:'$CXXFILESUFFIX'; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:QT_MOCHPREFIX; 141, string:'moc_'; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:QT_MOCHSUFFIX; 144, string:'$CXXFILESUFFIX'; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:QT_MOCCXXPREFIX; 147, string:''; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:QT_MOCCXXSUFFIX; 150, string:'.moc'; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:QT_UISUFFIX; 153, string:'.ui'; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:QT_UICCOM; 156, list:[ CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'), CLVar('$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} ' '-o ${TARGETS[1]} $SOURCE'), CLVar('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}')]; 156, 157; 156, 161; 156, 167; 157, call; 157, 158; 157, 159; 158, identifier:CLVar; 159, argument_list; 159, 160; 160, string:'$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'; 161, call; 161, 162; 161, 163; 162, identifier:CLVar; 163, argument_list; 163, 164; 164, concatenated_string; 164, 165; 164, 166; 165, string:'$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} '; 166, string:'-o ${TARGETS[1]} $SOURCE'; 167, call; 167, 168; 167, 169; 168, identifier:CLVar; 169, argument_list; 169, 170; 170, string:'$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}'; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:QT_MOCFROMHCOM; 173, parenthesized_expression; 173, 174; 174, string:'$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:QT_MOCFROMCXXCOM; 177, list:[ CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'), Action(checkMocIncluded,None)]; 177, 178; 177, 182; 178, call; 178, 179; 178, 180; 179, identifier:CLVar; 180, argument_list; 180, 181; 181, string:'$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'; 182, call; 182, 183; 182, 184; 183, identifier:Action; 184, argument_list; 184, 185; 184, 186; 185, identifier:checkMocIncluded; 186, None; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:uicBld; 190, call; 190, 191; 190, 192; 191, identifier:Builder; 192, argument_list; 192, 193; 192, 204; 192, 207; 192, 210; 192, 213; 192, 216; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:action; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:SCons; 199, identifier:Action; 200, identifier:Action; 201, argument_list; 201, 202; 201, 203; 202, string:'$QT_UICCOM'; 203, string:'$QT_UICCOMSTR'; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:emitter; 206, identifier:uicEmitter; 207, keyword_argument; 207, 208; 207, 209; 208, identifier:src_suffix; 209, string:'$QT_UISUFFIX'; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:suffix; 212, string:'$QT_UICDECLSUFFIX'; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:prefix; 215, string:'$QT_UICDECLPREFIX'; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:source_scanner; 218, identifier:uicScanner; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:mocBld; 222, call; 222, 223; 222, 224; 223, identifier:Builder; 224, argument_list; 224, 225; 224, 228; 224, 231; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:action; 227, dictionary; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:prefix; 230, dictionary; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:suffix; 233, dictionary; 234, for_statement; 234, 235; 234, 236; 234, 237; 235, identifier:h; 236, identifier:header_extensions; 237, block; 237, 238; 237, 250; 237, 258; 237, 266; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:act; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:SCons; 245, identifier:Action; 246, identifier:Action; 247, argument_list; 247, 248; 247, 249; 248, string:'$QT_MOCFROMHCOM'; 249, string:'$QT_MOCFROMHCOMSTR'; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:mocBld; 254, identifier:add_action; 255, argument_list; 255, 256; 255, 257; 256, identifier:h; 257, identifier:act; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 265; 260, subscript; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:mocBld; 263, identifier:prefix; 264, identifier:h; 265, string:'$QT_MOCHPREFIX'; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 273; 268, subscript; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:mocBld; 271, identifier:suffix; 272, identifier:h; 273, string:'$QT_MOCHSUFFIX'; 274, for_statement; 274, 275; 274, 276; 274, 277; 275, identifier:cxx; 276, identifier:cxx_suffixes; 277, block; 277, 278; 277, 290; 277, 298; 277, 306; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:act; 281, call; 281, 282; 281, 287; 282, attribute; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:SCons; 285, identifier:Action; 286, identifier:Action; 287, argument_list; 287, 288; 287, 289; 288, string:'$QT_MOCFROMCXXCOM'; 289, string:'$QT_MOCFROMCXXCOMSTR'; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:mocBld; 294, identifier:add_action; 295, argument_list; 295, 296; 295, 297; 296, identifier:cxx; 297, identifier:act; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 305; 300, subscript; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:mocBld; 303, identifier:prefix; 304, identifier:cxx; 305, string:'$QT_MOCCXXPREFIX'; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 313; 308, subscript; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:mocBld; 311, identifier:suffix; 312, identifier:cxx; 313, string:'$QT_MOCCXXSUFFIX'; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 321; 316, subscript; 316, 317; 316, 320; 317, subscript; 317, 318; 317, 319; 318, identifier:env; 319, string:'BUILDERS'; 320, string:'Uic'; 321, identifier:uicBld; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 329; 324, subscript; 324, 325; 324, 328; 325, subscript; 325, 326; 325, 327; 326, identifier:env; 327, string:'BUILDERS'; 328, string:'Moc'; 329, identifier:mocBld; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 335; 332, pattern_list; 332, 333; 332, 334; 333, identifier:static_obj; 334, identifier:shared_obj; 335, call; 335, 336; 335, 341; 336, attribute; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:SCons; 339, identifier:Tool; 340, identifier:createObjBuilders; 341, argument_list; 341, 342; 342, identifier:env; 343, expression_statement; 343, 344; 344, call; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:static_obj; 347, identifier:add_src_builder; 348, argument_list; 348, 349; 349, string:'Uic'; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:shared_obj; 354, identifier:add_src_builder; 355, argument_list; 355, 356; 356, string:'Uic'; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:env; 361, identifier:AppendUnique; 362, argument_list; 362, 363; 362, 367; 362, 371; 362, 375; 362, 379; 362, 383; 362, 387; 363, keyword_argument; 363, 364; 363, 365; 364, identifier:PROGEMITTER; 365, list:[AutomocStatic]; 365, 366; 366, identifier:AutomocStatic; 367, keyword_argument; 367, 368; 367, 369; 368, identifier:SHLIBEMITTER; 369, list:[AutomocShared]; 369, 370; 370, identifier:AutomocShared; 371, keyword_argument; 371, 372; 371, 373; 372, identifier:LDMODULEEMITTER; 373, list:[AutomocShared]; 373, 374; 374, identifier:AutomocShared; 375, keyword_argument; 375, 376; 375, 377; 376, identifier:LIBEMITTER; 377, list:[AutomocStatic]; 377, 378; 378, identifier:AutomocStatic; 379, keyword_argument; 379, 380; 379, 381; 380, identifier:CPPPATH; 381, list:["$QT_CPPPATH"]; 381, 382; 382, string:"$QT_CPPPATH"; 383, keyword_argument; 383, 384; 383, 385; 384, identifier:LIBPATH; 385, list:["$QT_LIBPATH"]; 385, 386; 386, string:"$QT_LIBPATH"; 387, keyword_argument; 387, 388; 387, 389; 388, identifier:LIBS; 389, list:['$QT_LIB']; 389, 390; 390, string:'$QT_LIB'
def generate(env): CLVar = SCons.Util.CLVar Action = SCons.Action.Action Builder = SCons.Builder.Builder env.SetDefault(QTDIR = _detect(env), QT_BINPATH = os.path.join('$QTDIR', 'bin'), QT_CPPPATH = os.path.join('$QTDIR', 'include'), QT_LIBPATH = os.path.join('$QTDIR', 'lib'), QT_MOC = os.path.join('$QT_BINPATH','moc'), QT_UIC = os.path.join('$QT_BINPATH','uic'), QT_LIB = 'qt', QT_AUTOSCAN = 1, QT_UICIMPLFLAGS = CLVar(''), QT_UICDECLFLAGS = CLVar(''), QT_MOCFROMHFLAGS = CLVar(''), QT_MOCFROMCXXFLAGS = CLVar('-i'), QT_UICDECLPREFIX = '', QT_UICDECLSUFFIX = '.h', QT_UICIMPLPREFIX = 'uic_', QT_UICIMPLSUFFIX = '$CXXFILESUFFIX', QT_MOCHPREFIX = 'moc_', QT_MOCHSUFFIX = '$CXXFILESUFFIX', QT_MOCCXXPREFIX = '', QT_MOCCXXSUFFIX = '.moc', QT_UISUFFIX = '.ui', QT_UICCOM = [ CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'), CLVar('$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} ' '-o ${TARGETS[1]} $SOURCE'), CLVar('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}')], QT_MOCFROMHCOM = ( '$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'), QT_MOCFROMCXXCOM = [ CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'), Action(checkMocIncluded,None)]) uicBld = Builder(action=SCons.Action.Action('$QT_UICCOM', '$QT_UICCOMSTR'), emitter=uicEmitter, src_suffix='$QT_UISUFFIX', suffix='$QT_UICDECLSUFFIX', prefix='$QT_UICDECLPREFIX', source_scanner=uicScanner) mocBld = Builder(action={}, prefix={}, suffix={}) for h in header_extensions: act = SCons.Action.Action('$QT_MOCFROMHCOM', '$QT_MOCFROMHCOMSTR') mocBld.add_action(h, act) mocBld.prefix[h] = '$QT_MOCHPREFIX' mocBld.suffix[h] = '$QT_MOCHSUFFIX' for cxx in cxx_suffixes: act = SCons.Action.Action('$QT_MOCFROMCXXCOM', '$QT_MOCFROMCXXCOMSTR') mocBld.add_action(cxx, act) mocBld.prefix[cxx] = '$QT_MOCCXXPREFIX' mocBld.suffix[cxx] = '$QT_MOCCXXSUFFIX' env['BUILDERS']['Uic'] = uicBld env['BUILDERS']['Moc'] = mocBld static_obj, shared_obj = SCons.Tool.createObjBuilders(env) static_obj.add_src_builder('Uic') shared_obj.add_src_builder('Uic') env.AppendUnique(PROGEMITTER =[AutomocStatic], SHLIBEMITTER=[AutomocShared], LDMODULEEMITTER=[AutomocShared], LIBEMITTER =[AutomocStatic], CPPPATH=["$QT_CPPPATH"], LIBPATH=["$QT_LIBPATH"], LIBS=['$QT_LIB'])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:emit_rmic_classes; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:target; 5, identifier:source; 6, identifier:env; 7, block; 7, 8; 7, 18; 7, 27; 7, 65; 7, 78; 7, 103; 7, 107; 7, 214; 7, 219; 7, 236; 7, 240; 7, 297; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:class_suffix; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:env; 14, identifier:get; 15, argument_list; 15, 16; 15, 17; 16, string:'JAVACLASSSUFFIX'; 17, string:'.class'; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:classdir; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:env; 24, identifier:get; 25, argument_list; 25, 26; 26, string:'JAVACLASSDIR'; 27, if_statement; 27, 28; 27, 30; 28, not_operator; 28, 29; 29, identifier:classdir; 30, block; 30, 31; 31, try_statement; 31, 32; 31, 39; 31, 46; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:s; 36, subscript; 36, 37; 36, 38; 37, identifier:source; 38, integer:0; 39, except_clause; 39, 40; 39, 41; 40, identifier:IndexError; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:classdir; 45, string:'.'; 46, else_clause; 46, 47; 47, block; 47, 48; 48, try_statement; 48, 49; 48, 58; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:classdir; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:s; 56, identifier:attributes; 57, identifier:java_classdir; 58, except_clause; 58, 59; 58, 60; 59, identifier:AttributeError; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:classdir; 64, string:'.'; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:classdir; 68, call; 68, 69; 68, 77; 69, attribute; 69, 70; 69, 76; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:env; 73, identifier:Dir; 74, argument_list; 74, 75; 75, identifier:classdir; 76, identifier:rdir; 77, argument_list; 78, if_statement; 78, 79; 78, 85; 78, 90; 79, comparison_operator:==; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:str; 82, argument_list; 82, 83; 83, identifier:classdir; 84, string:'.'; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:c_; 89, None; 90, else_clause; 90, 91; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:c_; 95, binary_operator:+; 95, 96; 95, 100; 96, call; 96, 97; 96, 98; 97, identifier:str; 98, argument_list; 98, 99; 99, identifier:classdir; 100, attribute; 100, 101; 100, 102; 101, identifier:os; 102, identifier:sep; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:slist; 106, list:[]; 107, for_statement; 107, 108; 107, 109; 107, 110; 108, identifier:src; 109, identifier:source; 110, block; 110, 111; 110, 183; 110, 191; 110, 199; 110, 207; 111, try_statement; 111, 112; 111, 121; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:classname; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:src; 119, identifier:attributes; 120, identifier:java_classname; 121, except_clause; 121, 122; 121, 123; 122, identifier:AttributeError; 123, block; 123, 124; 123, 131; 123, 156; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:classname; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:src; 131, if_statement; 131, 132; 131, 144; 132, boolean_operator:and; 132, 133; 132, 134; 133, identifier:c_; 134, comparison_operator:==; 134, 135; 134, 143; 135, subscript; 135, 136; 135, 137; 136, identifier:classname; 137, slice; 137, 138; 137, 139; 138, colon; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, identifier:c_; 143, identifier:c_; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:classname; 148, subscript; 148, 149; 148, 150; 149, identifier:classname; 150, slice; 150, 151; 150, 155; 151, call; 151, 152; 151, 153; 152, identifier:len; 153, argument_list; 153, 154; 154, identifier:c_; 155, colon; 156, if_statement; 156, 157; 156, 170; 157, boolean_operator:and; 157, 158; 157, 159; 158, identifier:class_suffix; 159, comparison_operator:==; 159, 160; 159, 169; 160, subscript; 160, 161; 160, 162; 161, identifier:classname; 162, slice; 162, 163; 162, 164; 163, colon; 164, unary_operator:-; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:len; 167, argument_list; 167, 168; 168, identifier:class_suffix; 169, identifier:class_suffix; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:classname; 174, subscript; 174, 175; 174, 176; 175, identifier:classname; 176, slice; 176, 177; 176, 182; 177, unary_operator:-; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:len; 180, argument_list; 180, 181; 181, identifier:class_suffix; 182, colon; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:s; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:src; 189, identifier:rfile; 190, argument_list; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 198; 193, attribute; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:s; 196, identifier:attributes; 197, identifier:java_classdir; 198, identifier:classdir; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 206; 201, attribute; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:s; 204, identifier:attributes; 205, identifier:java_classname; 206, identifier:classname; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:slist; 211, identifier:append; 212, argument_list; 212, 213; 213, identifier:s; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:stub_suffixes; 217, list:['_Stub']; 217, 218; 218, string:'_Stub'; 219, if_statement; 219, 220; 219, 228; 220, comparison_operator:==; 220, 221; 220, 227; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:env; 224, identifier:get; 225, argument_list; 225, 226; 226, string:'JAVAVERSION'; 227, string:'1.4'; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:stub_suffixes; 233, identifier:append; 234, argument_list; 234, 235; 235, string:'_Skel'; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:tlist; 239, list:[]; 240, for_statement; 240, 241; 240, 242; 240, 243; 241, identifier:s; 242, identifier:source; 243, block; 243, 244; 244, for_statement; 244, 245; 244, 246; 244, 247; 245, identifier:suff; 246, identifier:stub_suffixes; 247, block; 247, 248; 247, 269; 247, 280; 247, 290; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:fname; 251, binary_operator:+; 251, 252; 251, 268; 252, binary_operator:+; 252, 253; 252, 266; 252, 267; 253, call; 253, 254; 253, 261; 254, attribute; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:s; 258, identifier:attributes; 259, identifier:java_classname; 260, identifier:replace; 261, argument_list; 261, 262; 261, 263; 262, string:'.'; 263, attribute; 263, 264; 263, 265; 264, identifier:os; 265, identifier:sep; 266, line_continuation:\; 267, identifier:suff; 268, identifier:class_suffix; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:t; 272, call; 272, 273; 272, 278; 273, attribute; 273, 274; 273, 277; 274, subscript; 274, 275; 274, 276; 275, identifier:target; 276, integer:0; 277, identifier:File; 278, argument_list; 278, 279; 279, identifier:fname; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 287; 282, attribute; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:t; 285, identifier:attributes; 286, identifier:java_lookupdir; 287, subscript; 287, 288; 287, 289; 288, identifier:target; 289, integer:0; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:tlist; 294, identifier:append; 295, argument_list; 295, 296; 296, identifier:t; 297, return_statement; 297, 298; 298, expression_list; 298, 299; 298, 300; 299, identifier:tlist; 300, identifier:source
def emit_rmic_classes(target, source, env): class_suffix = env.get('JAVACLASSSUFFIX', '.class') classdir = env.get('JAVACLASSDIR') if not classdir: try: s = source[0] except IndexError: classdir = '.' else: try: classdir = s.attributes.java_classdir except AttributeError: classdir = '.' classdir = env.Dir(classdir).rdir() if str(classdir) == '.': c_ = None else: c_ = str(classdir) + os.sep slist = [] for src in source: try: classname = src.attributes.java_classname except AttributeError: classname = str(src) if c_ and classname[:len(c_)] == c_: classname = classname[len(c_):] if class_suffix and classname[:-len(class_suffix)] == class_suffix: classname = classname[-len(class_suffix):] s = src.rfile() s.attributes.java_classdir = classdir s.attributes.java_classname = classname slist.append(s) stub_suffixes = ['_Stub'] if env.get('JAVAVERSION') == '1.4': stub_suffixes.append('_Skel') tlist = [] for s in source: for suff in stub_suffixes: fname = s.attributes.java_classname.replace('.', os.sep) + \ suff + class_suffix t = target[0].File(fname) t.attributes.java_lookupdir = target[0] tlist.append(t) return tlist, source
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_probe_services; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:handle; 6, block; 6, 7; 6, 11; 6, 52; 6, 93; 6, 107; 6, 130; 6, 142; 6, 151; 6, 162; 6, 175; 6, 188; 6, 200; 6, 206; 6, 219; 6, 241; 6, 245; 6, 255; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:code; 10, integer:0x2800; 11, function_definition; 11, 12; 11, 13; 11, 15; 12, function_name:event_filter_func; 13, parameters; 13, 14; 14, identifier:event; 15, block; 15, 16; 15, 50; 16, if_statement; 16, 17; 16, 29; 17, parenthesized_expression; 17, 18; 18, boolean_operator:and; 18, 19; 18, 24; 19, comparison_operator:==; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:event; 22, identifier:command_class; 23, integer:4; 24, comparison_operator:==; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:event; 27, identifier:command; 28, integer:2; 29, block; 29, 30; 29, 46; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 34; 32, pattern_list; 32, 33; 33, identifier:event_handle; 34, call; 34, 35; 34, 36; 35, identifier:unpack; 36, argument_list; 36, 37; 36, 38; 37, string:"B"; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:event; 41, identifier:payload; 42, slice; 42, 43; 42, 44; 42, 45; 43, integer:0; 44, colon; 45, integer:1; 46, return_statement; 46, 47; 47, comparison_operator:==; 47, 48; 47, 49; 48, identifier:event_handle; 49, identifier:handle; 50, return_statement; 50, 51; 51, False; 52, function_definition; 52, 53; 52, 54; 52, 56; 53, function_name:end_filter_func; 54, parameters; 54, 55; 55, identifier:event; 56, block; 56, 57; 56, 91; 57, if_statement; 57, 58; 57, 70; 58, parenthesized_expression; 58, 59; 59, boolean_operator:and; 59, 60; 59, 65; 60, comparison_operator:==; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:event; 63, identifier:command_class; 64, integer:4; 65, comparison_operator:==; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:event; 68, identifier:command; 69, integer:1; 70, block; 70, 71; 70, 87; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 75; 73, pattern_list; 73, 74; 74, identifier:event_handle; 75, call; 75, 76; 75, 77; 76, identifier:unpack; 77, argument_list; 77, 78; 77, 79; 78, string:"B"; 79, subscript; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:event; 82, identifier:payload; 83, slice; 83, 84; 83, 85; 83, 86; 84, integer:0; 85, colon; 86, integer:1; 87, return_statement; 87, 88; 88, comparison_operator:==; 88, 89; 88, 90; 89, identifier:event_handle; 90, identifier:handle; 91, return_statement; 91, 92; 92, False; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:payload; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:struct; 99, identifier:pack; 100, argument_list; 100, 101; 100, 102; 100, 103; 100, 104; 100, 105; 100, 106; 101, string:'<BHHBH'; 102, identifier:handle; 103, integer:1; 104, integer:0xFFFF; 105, integer:2; 106, identifier:code; 107, try_statement; 107, 108; 107, 120; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:response; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:_send_command; 116, argument_list; 116, 117; 116, 118; 116, 119; 117, integer:4; 118, integer:1; 119, identifier:payload; 120, except_clause; 120, 121; 120, 122; 121, identifier:InternalTimeoutError; 122, block; 122, 123; 123, return_statement; 123, 124; 124, expression_list; 124, 125; 124, 126; 125, False; 126, dictionary; 126, 127; 127, pair; 127, 128; 127, 129; 128, string:'reason'; 129, string:'Timeout waiting for command response'; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 135; 132, pattern_list; 132, 133; 132, 134; 133, identifier:handle; 134, identifier:result; 135, call; 135, 136; 135, 137; 136, identifier:unpack; 137, argument_list; 137, 138; 137, 139; 138, string:"<BH"; 139, attribute; 139, 140; 139, 141; 140, identifier:response; 141, identifier:payload; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:!=; 143, 144; 143, 145; 144, identifier:result; 145, integer:0; 146, block; 146, 147; 147, return_statement; 147, 148; 148, expression_list; 148, 149; 148, 150; 149, False; 150, None; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:events; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:_wait_process_events; 158, argument_list; 158, 159; 158, 160; 158, 161; 159, float:0.5; 160, identifier:event_filter_func; 161, identifier:end_filter_func; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:gatt_events; 165, list_comprehension; 165, 166; 165, 167; 165, 170; 166, identifier:x; 167, for_in_clause; 167, 168; 167, 169; 168, identifier:x; 169, identifier:events; 170, if_clause; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:event_filter_func; 173, argument_list; 173, 174; 174, identifier:x; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:end_events; 178, list_comprehension; 178, 179; 178, 180; 178, 183; 179, identifier:x; 180, for_in_clause; 180, 181; 180, 182; 181, identifier:x; 182, identifier:events; 183, if_clause; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:end_filter_func; 186, argument_list; 186, 187; 187, identifier:x; 188, if_statement; 188, 189; 188, 195; 189, comparison_operator:==; 189, 190; 189, 194; 190, call; 190, 191; 190, 192; 191, identifier:len; 192, argument_list; 192, 193; 193, identifier:end_events; 194, integer:0; 195, block; 195, 196; 196, return_statement; 196, 197; 197, expression_list; 197, 198; 197, 199; 198, False; 199, None; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:end_event; 203, subscript; 203, 204; 203, 205; 204, identifier:end_events; 205, integer:0; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 212; 208, pattern_list; 208, 209; 208, 210; 208, 211; 209, identifier:_; 210, identifier:result; 211, identifier:_; 212, call; 212, 213; 212, 214; 213, identifier:unpack; 214, argument_list; 214, 215; 214, 216; 215, string:"<BHH"; 216, attribute; 216, 217; 216, 218; 217, identifier:end_event; 218, identifier:payload; 219, if_statement; 219, 220; 219, 223; 220, comparison_operator:!=; 220, 221; 220, 222; 221, identifier:result; 222, integer:0; 223, block; 223, 224; 223, 237; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 231; 226, attribute; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:_logger; 230, identifier:warn; 231, argument_list; 231, 232; 232, binary_operator:%; 232, 233; 232, 234; 233, string:"Error enumerating GATT table, protocol error code = %d (0x%X)"; 234, tuple; 234, 235; 234, 236; 235, identifier:result; 236, identifier:result; 237, return_statement; 237, 238; 238, expression_list; 238, 239; 238, 240; 239, False; 240, None; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:services; 244, dictionary; 245, for_statement; 245, 246; 245, 247; 245, 248; 246, identifier:event; 247, identifier:gatt_events; 248, block; 248, 249; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 252; 251, identifier:process_gatt_service; 252, argument_list; 252, 253; 252, 254; 253, identifier:services; 254, identifier:event; 255, return_statement; 255, 256; 256, expression_list; 256, 257; 256, 258; 257, True; 258, dictionary; 258, 259; 259, pair; 259, 260; 259, 261; 260, string:'services'; 261, identifier:services
def _probe_services(self, handle): code = 0x2800 def event_filter_func(event): if (event.command_class == 4 and event.command == 2): event_handle, = unpack("B", event.payload[0:1]) return event_handle == handle return False def end_filter_func(event): if (event.command_class == 4 and event.command == 1): event_handle, = unpack("B", event.payload[0:1]) return event_handle == handle return False payload = struct.pack('<BHHBH', handle, 1, 0xFFFF, 2, code) try: response = self._send_command(4, 1, payload) except InternalTimeoutError: return False, {'reason': 'Timeout waiting for command response'} handle, result = unpack("<BH", response.payload) if result != 0: return False, None events = self._wait_process_events(0.5, event_filter_func, end_filter_func) gatt_events = [x for x in events if event_filter_func(x)] end_events = [x for x in events if end_filter_func(x)] if len(end_events) == 0: return False, None end_event = end_events[0] _, result, _ = unpack("<BHH", end_event.payload) if result != 0: self._logger.warn("Error enumerating GATT table, protocol error code = %d (0x%X)" % (result, result)) return False, None services = {} for event in gatt_events: process_gatt_service(services, event) return True, {'services': services}
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_write_handle; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:conn; 6, identifier:handle; 7, identifier:ack; 8, identifier:value; 9, default_parameter; 9, 10; 9, 11; 10, identifier:timeout; 11, float:1.0; 12, block; 12, 13; 12, 17; 12, 21; 12, 60; 12, 67; 12, 79; 12, 94; 12, 133; 12, 145; 12, 160; 12, 222; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:conn_handle; 16, identifier:conn; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:char_handle; 20, identifier:handle; 21, function_definition; 21, 22; 21, 23; 21, 25; 22, function_name:write_handle_acked; 23, parameters; 23, 24; 24, identifier:event; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 38; 27, boolean_operator:and; 27, 28; 27, 33; 28, comparison_operator:==; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:event; 31, identifier:command_class; 32, integer:4; 33, comparison_operator:==; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:event; 36, identifier:command; 37, integer:1; 38, block; 38, 39; 38, 52; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 45; 41, pattern_list; 41, 42; 41, 43; 41, 44; 42, identifier:conn; 43, identifier:_; 44, identifier:char; 45, call; 45, 46; 45, 47; 46, identifier:unpack; 47, argument_list; 47, 48; 47, 49; 48, string:"<BHH"; 49, attribute; 49, 50; 49, 51; 50, identifier:event; 51, identifier:payload; 52, return_statement; 52, 53; 53, boolean_operator:and; 53, 54; 53, 57; 54, comparison_operator:==; 54, 55; 54, 56; 55, identifier:conn_handle; 56, identifier:conn; 57, comparison_operator:==; 57, 58; 57, 59; 58, identifier:char_handle; 59, identifier:char; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:data_len; 63, call; 63, 64; 63, 65; 64, identifier:len; 65, argument_list; 65, 66; 66, identifier:value; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:>; 68, 69; 68, 70; 69, identifier:data_len; 70, integer:20; 71, block; 71, 72; 72, return_statement; 72, 73; 73, expression_list; 73, 74; 73, 75; 74, False; 75, dictionary; 75, 76; 76, pair; 76, 77; 76, 78; 77, string:'reason'; 78, string:'Data too long to write'; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:payload; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:struct; 85, identifier:pack; 86, argument_list; 86, 87; 86, 90; 86, 91; 86, 92; 86, 93; 87, binary_operator:%; 87, 88; 87, 89; 88, string:"<BHB%ds"; 89, identifier:data_len; 90, identifier:conn_handle; 91, identifier:char_handle; 92, identifier:data_len; 93, identifier:value; 94, try_statement; 94, 95; 94, 123; 95, block; 95, 96; 96, if_statement; 96, 97; 96, 98; 96, 110; 97, identifier:ack; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:response; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_send_command; 106, argument_list; 106, 107; 106, 108; 106, 109; 107, integer:4; 108, integer:5; 109, identifier:payload; 110, else_clause; 110, 111; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:response; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:_send_command; 119, argument_list; 119, 120; 119, 121; 119, 122; 120, integer:4; 121, integer:6; 122, identifier:payload; 123, except_clause; 123, 124; 123, 125; 124, identifier:InternalTimeoutError; 125, block; 125, 126; 126, return_statement; 126, 127; 127, expression_list; 127, 128; 127, 129; 128, False; 129, dictionary; 129, 130; 130, pair; 130, 131; 130, 132; 131, string:'reason'; 132, string:'Timeout waiting for response to command in _write_handle'; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, pattern_list; 135, 136; 135, 137; 136, identifier:_; 137, identifier:result; 138, call; 138, 139; 138, 140; 139, identifier:unpack; 140, argument_list; 140, 141; 140, 142; 141, string:"<BH"; 142, attribute; 142, 143; 142, 144; 143, identifier:response; 144, identifier:payload; 145, if_statement; 145, 146; 145, 149; 146, comparison_operator:!=; 146, 147; 146, 148; 147, identifier:result; 148, integer:0; 149, block; 149, 150; 150, return_statement; 150, 151; 151, expression_list; 151, 152; 151, 153; 152, False; 153, dictionary; 153, 154; 153, 157; 154, pair; 154, 155; 154, 156; 155, string:'reason'; 156, string:'Error writing to handle'; 157, pair; 157, 158; 157, 159; 158, string:'error_code'; 159, identifier:result; 160, if_statement; 160, 161; 160, 162; 161, identifier:ack; 162, block; 162, 163; 162, 177; 162, 192; 162, 207; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:events; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:_wait_process_events; 170, argument_list; 170, 171; 170, 172; 170, 176; 171, identifier:timeout; 172, lambda; 172, 173; 172, 175; 173, lambda_parameters; 173, 174; 174, identifier:x; 175, False; 176, identifier:write_handle_acked; 177, if_statement; 177, 178; 177, 184; 178, comparison_operator:==; 178, 179; 178, 183; 179, call; 179, 180; 179, 181; 180, identifier:len; 181, argument_list; 181, 182; 182, identifier:events; 183, integer:0; 184, block; 184, 185; 185, return_statement; 185, 186; 186, expression_list; 186, 187; 186, 188; 187, False; 188, dictionary; 188, 189; 189, pair; 189, 190; 189, 191; 190, string:'reason'; 191, string:'Timeout waiting for acknowledge on write'; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 198; 194, pattern_list; 194, 195; 194, 196; 194, 197; 195, identifier:_; 196, identifier:result; 197, identifier:_; 198, call; 198, 199; 198, 200; 199, identifier:unpack; 200, argument_list; 200, 201; 200, 202; 201, string:"<BHH"; 202, attribute; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:events; 205, integer:0; 206, identifier:payload; 207, if_statement; 207, 208; 207, 211; 208, comparison_operator:!=; 208, 209; 208, 210; 209, identifier:result; 210, integer:0; 211, block; 211, 212; 212, return_statement; 212, 213; 213, expression_list; 213, 214; 213, 215; 214, False; 215, dictionary; 215, 216; 215, 219; 216, pair; 216, 217; 216, 218; 217, string:'reason'; 218, string:'Error received during write to handle'; 219, pair; 219, 220; 219, 221; 220, string:'error_code'; 221, identifier:result; 222, return_statement; 222, 223; 223, expression_list; 223, 224; 223, 225; 224, True; 225, None
def _write_handle(self, conn, handle, ack, value, timeout=1.0): conn_handle = conn char_handle = handle def write_handle_acked(event): if event.command_class == 4 and event.command == 1: conn, _, char = unpack("<BHH", event.payload) return conn_handle == conn and char_handle == char data_len = len(value) if data_len > 20: return False, {'reason': 'Data too long to write'} payload = struct.pack("<BHB%ds" % data_len, conn_handle, char_handle, data_len, value) try: if ack: response = self._send_command(4, 5, payload) else: response = self._send_command(4, 6, payload) except InternalTimeoutError: return False, {'reason': 'Timeout waiting for response to command in _write_handle'} _, result = unpack("<BH", response.payload) if result != 0: return False, {'reason': 'Error writing to handle', 'error_code': result} if ack: events = self._wait_process_events(timeout, lambda x: False, write_handle_acked) if len(events) == 0: return False, {'reason': 'Timeout waiting for acknowledge on write'} _, result, _ = unpack("<BHH", events[0].payload) if result != 0: return False, {'reason': 'Error received during write to handle', 'error_code': result} return True, None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:build_specfiles; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:source; 5, identifier:target; 6, identifier:env; 7, block; 7, 8; 7, 12; 7, 70; 7, 78; 7, 103; 7, 117; 7, 155; 7, 200; 7, 217; 7, 231; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:opened_files; 11, dictionary; 12, function_definition; 12, 13; 12, 14; 12, 17; 13, function_name:open_file; 14, parameters; 14, 15; 14, 16; 15, identifier:needle; 16, identifier:haystack; 17, block; 17, 18; 18, try_statement; 18, 19; 18, 24; 19, block; 19, 20; 20, return_statement; 20, 21; 21, subscript; 21, 22; 21, 23; 22, identifier:opened_files; 23, identifier:needle; 24, except_clause; 24, 25; 24, 26; 25, identifier:KeyError; 26, block; 26, 27; 26, 52; 26, 66; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:file; 30, subscript; 30, 31; 30, 51; 31, call; 31, 32; 31, 33; 32, identifier:filter; 33, argument_list; 33, 34; 33, 50; 34, lambda; 34, 35; 34, 37; 35, lambda_parameters; 35, 36; 36, identifier:x; 37, comparison_operator:!=; 37, 38; 37, 48; 38, call; 38, 39; 38, 46; 39, attribute; 39, 40; 39, 45; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:x; 43, identifier:get_path; 44, argument_list; 45, identifier:rfind; 46, argument_list; 46, 47; 47, identifier:needle; 48, unary_operator:-; 48, 49; 49, integer:1; 50, identifier:haystack; 51, integer:0; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:opened_files; 56, identifier:needle; 57, call; 57, 58; 57, 59; 58, identifier:open; 59, argument_list; 59, 60; 59, 65; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:file; 63, identifier:get_abspath; 64, argument_list; 65, string:'w'; 66, return_statement; 66, 67; 67, subscript; 67, 68; 67, 69; 68, identifier:opened_files; 69, identifier:needle; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:control_file; 73, call; 73, 74; 73, 75; 74, identifier:open_file; 75, argument_list; 75, 76; 75, 77; 76, string:'control'; 77, identifier:target; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:not; 79, 80; 79, 81; 80, string:'X_IPK_DESCRIPTION'; 81, identifier:env; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:env; 87, string:'X_IPK_DESCRIPTION'; 88, binary_operator:%; 88, 89; 88, 90; 89, string:"%s\n %s"; 90, tuple; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:env; 93, string:'SUMMARY'; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:env; 98, string:'DESCRIPTION'; 99, identifier:replace; 100, argument_list; 100, 101; 100, 102; 101, string:'\n'; 102, string:'\n '; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:content; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:control_file; 109, identifier:write; 110, argument_list; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:env; 114, identifier:subst; 115, argument_list; 115, 116; 116, identifier:content; 117, for_statement; 117, 118; 117, 119; 117, 131; 118, identifier:f; 119, list_comprehension; 119, 120; 119, 121; 119, 124; 120, identifier:x; 121, for_in_clause; 121, 122; 121, 123; 122, identifier:x; 123, identifier:source; 124, if_clause; 124, 125; 125, comparison_operator:in; 125, 126; 125, 127; 126, string:'PACKAGING_CONFIG'; 127, call; 127, 128; 127, 129; 128, identifier:dir; 129, argument_list; 129, 130; 130, identifier:x; 131, block; 131, 132; 131, 139; 131, 148; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:config; 135, call; 135, 136; 135, 137; 136, identifier:open_file; 137, argument_list; 137, 138; 138, string:'conffiles'; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:config; 143, identifier:write; 144, argument_list; 144, 145; 145, attribute; 145, 146; 145, 147; 146, identifier:f; 147, identifier:PACKAGING_INSTALL_LOCATION; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:config; 152, identifier:write; 153, argument_list; 153, 154; 154, string:'\n'; 155, for_statement; 155, 156; 155, 157; 155, 162; 156, identifier:str; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, string:'POSTRM PRERM POSTINST PREINST'; 160, identifier:split; 161, argument_list; 162, block; 162, 163; 162, 169; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:name; 166, binary_operator:%; 166, 167; 166, 168; 167, string:"PACKAGING_X_IPK_%s"; 168, identifier:str; 169, for_statement; 169, 170; 169, 171; 169, 183; 170, identifier:f; 171, list_comprehension; 171, 172; 171, 173; 171, 176; 172, identifier:x; 173, for_in_clause; 173, 174; 173, 175; 174, identifier:x; 175, identifier:source; 176, if_clause; 176, 177; 177, comparison_operator:in; 177, 178; 177, 179; 178, identifier:name; 179, call; 179, 180; 179, 181; 180, identifier:dir; 181, argument_list; 181, 182; 182, identifier:x; 183, block; 183, 184; 183, 191; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:file; 187, call; 187, 188; 187, 189; 188, identifier:open_file; 189, argument_list; 189, 190; 190, identifier:name; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:file; 195, identifier:write; 196, argument_list; 196, 197; 197, subscript; 197, 198; 197, 199; 198, identifier:env; 199, identifier:str; 200, for_statement; 200, 201; 200, 202; 200, 210; 201, identifier:f; 202, call; 202, 203; 202, 204; 203, identifier:list; 204, argument_list; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:opened_files; 208, identifier:values; 209, argument_list; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:f; 215, identifier:close; 216, argument_list; 217, if_statement; 217, 218; 217, 221; 218, comparison_operator:in; 218, 219; 218, 220; 219, string:'CHANGE_SPECFILE'; 220, identifier:env; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, augmented_assignment:+=; 223, 224; 223, 225; 224, identifier:content; 225, call; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:env; 228, string:'CHANGE_SPECFILE'; 229, argument_list; 229, 230; 230, identifier:target; 231, return_statement; 231, 232; 232, integer:0
def build_specfiles(source, target, env): opened_files={} def open_file(needle, haystack): try: return opened_files[needle] except KeyError: file=filter(lambda x: x.get_path().rfind(needle)!=-1, haystack)[0] opened_files[needle]=open(file.get_abspath(), 'w') return opened_files[needle] control_file=open_file('control', target) if 'X_IPK_DESCRIPTION' not in env: env['X_IPK_DESCRIPTION']="%s\n %s"%(env['SUMMARY'], env['DESCRIPTION'].replace('\n', '\n ')) content = control_file.write(env.subst(content)) for f in [x for x in source if 'PACKAGING_CONFIG' in dir(x)]: config=open_file('conffiles') config.write(f.PACKAGING_INSTALL_LOCATION) config.write('\n') for str in 'POSTRM PRERM POSTINST PREINST'.split(): name="PACKAGING_X_IPK_%s"%str for f in [x for x in source if name in dir(x)]: file=open_file(name) file.write(env[str]) for f in list(opened_files.values()): f.close() if 'CHANGE_SPECFILE' in env: content += env['CHANGE_SPECFILE'](target) return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:emit_java_headers; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:target; 5, identifier:source; 6, identifier:env; 7, block; 7, 8; 7, 18; 7, 27; 7, 65; 7, 78; 7, 103; 7, 107; 7, 219; 7, 229; 7, 247; 7, 358; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:class_suffix; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:env; 14, identifier:get; 15, argument_list; 15, 16; 15, 17; 16, string:'JAVACLASSSUFFIX'; 17, string:'.class'; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:classdir; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:env; 24, identifier:get; 25, argument_list; 25, 26; 26, string:'JAVACLASSDIR'; 27, if_statement; 27, 28; 27, 30; 28, not_operator; 28, 29; 29, identifier:classdir; 30, block; 30, 31; 31, try_statement; 31, 32; 31, 39; 31, 46; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:s; 36, subscript; 36, 37; 36, 38; 37, identifier:source; 38, integer:0; 39, except_clause; 39, 40; 39, 41; 40, identifier:IndexError; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:classdir; 45, string:'.'; 46, else_clause; 46, 47; 47, block; 47, 48; 48, try_statement; 48, 49; 48, 58; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:classdir; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:s; 56, identifier:attributes; 57, identifier:java_classdir; 58, except_clause; 58, 59; 58, 60; 59, identifier:AttributeError; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:classdir; 64, string:'.'; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:classdir; 68, call; 68, 69; 68, 77; 69, attribute; 69, 70; 69, 76; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:env; 73, identifier:Dir; 74, argument_list; 74, 75; 75, identifier:classdir; 76, identifier:rdir; 77, argument_list; 78, if_statement; 78, 79; 78, 85; 78, 90; 79, comparison_operator:==; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:str; 82, argument_list; 82, 83; 83, identifier:classdir; 84, string:'.'; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:c_; 89, None; 90, else_clause; 90, 91; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:c_; 95, binary_operator:+; 95, 96; 95, 100; 96, call; 96, 97; 96, 98; 97, identifier:str; 98, argument_list; 98, 99; 99, identifier:classdir; 100, attribute; 100, 101; 100, 102; 101, identifier:os; 102, identifier:sep; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:slist; 106, list:[]; 107, for_statement; 107, 108; 107, 109; 107, 110; 108, identifier:src; 109, identifier:source; 110, block; 110, 111; 110, 196; 110, 204; 110, 212; 111, try_statement; 111, 112; 111, 121; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:classname; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:src; 119, identifier:attributes; 120, identifier:java_classname; 121, except_clause; 121, 122; 121, 123; 122, identifier:AttributeError; 123, block; 123, 124; 123, 131; 123, 156; 123, 183; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:classname; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:src; 131, if_statement; 131, 132; 131, 144; 132, boolean_operator:and; 132, 133; 132, 134; 133, identifier:c_; 134, comparison_operator:==; 134, 135; 134, 143; 135, subscript; 135, 136; 135, 137; 136, identifier:classname; 137, slice; 137, 138; 137, 139; 138, colon; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, identifier:c_; 143, identifier:c_; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:classname; 148, subscript; 148, 149; 148, 150; 149, identifier:classname; 150, slice; 150, 151; 150, 155; 151, call; 151, 152; 151, 153; 152, identifier:len; 153, argument_list; 153, 154; 154, identifier:c_; 155, colon; 156, if_statement; 156, 157; 156, 170; 157, boolean_operator:and; 157, 158; 157, 159; 158, identifier:class_suffix; 159, comparison_operator:==; 159, 160; 159, 169; 160, subscript; 160, 161; 160, 162; 161, identifier:classname; 162, slice; 162, 163; 162, 168; 163, unary_operator:-; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:len; 166, argument_list; 166, 167; 167, identifier:class_suffix; 168, colon; 169, identifier:class_suffix; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:classname; 174, subscript; 174, 175; 174, 176; 175, identifier:classname; 176, slice; 176, 177; 176, 178; 177, colon; 178, unary_operator:-; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:len; 181, argument_list; 181, 182; 182, identifier:class_suffix; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:classname; 186, call; 186, 187; 186, 194; 187, attribute; 187, 188; 187, 193; 188, attribute; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:SCons; 191, identifier:Tool; 192, identifier:javac; 193, identifier:classname; 194, argument_list; 194, 195; 195, identifier:classname; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:s; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:src; 202, identifier:rfile; 203, argument_list; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 211; 206, attribute; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:s; 209, identifier:attributes; 210, identifier:java_classname; 211, identifier:classname; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:slist; 216, identifier:append; 217, argument_list; 217, 218; 218, identifier:s; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:s; 222, call; 222, 223; 222, 228; 223, attribute; 223, 224; 223, 227; 224, subscript; 224, 225; 224, 226; 225, identifier:source; 226, integer:0; 227, identifier:rfile; 228, argument_list; 229, if_statement; 229, 230; 229, 238; 230, not_operator; 230, 231; 231, call; 231, 232; 231, 233; 232, identifier:hasattr; 233, argument_list; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:s; 236, identifier:attributes; 237, string:'java_classdir'; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:s; 244, identifier:attributes; 245, identifier:java_classdir; 246, identifier:classdir; 247, if_statement; 247, 248; 247, 261; 247, 266; 248, comparison_operator:is; 248, 249; 248, 254; 249, attribute; 249, 250; 249, 253; 250, subscript; 250, 251; 250, 252; 251, identifier:target; 252, integer:0; 253, identifier:__class__; 254, attribute; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:SCons; 258, identifier:Node; 259, identifier:FS; 260, identifier:File; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:tlist; 265, identifier:target; 266, else_clause; 266, 267; 267, block; 267, 268; 267, 306; 267, 310; 268, if_statement; 268, 269; 268, 283; 269, not_operator; 269, 270; 270, call; 270, 271; 270, 272; 271, identifier:isinstance; 272, argument_list; 272, 273; 272, 276; 273, subscript; 273, 274; 273, 275; 274, identifier:target; 275, integer:0; 276, attribute; 276, 277; 276, 282; 277, attribute; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:SCons; 280, identifier:Node; 281, identifier:FS; 282, identifier:Dir; 283, block; 283, 284; 283, 298; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, subscript; 287, 288; 287, 289; 288, identifier:target; 289, integer:0; 290, identifier:__class__; 291, attribute; 291, 292; 291, 297; 292, attribute; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:SCons; 295, identifier:Node; 296, identifier:FS; 297, identifier:Dir; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 305; 300, attribute; 300, 301; 300, 304; 301, subscript; 301, 302; 301, 303; 302, identifier:target; 303, integer:0; 304, identifier:_morph; 305, argument_list; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:tlist; 309, list:[]; 310, for_statement; 310, 311; 310, 312; 310, 313; 311, identifier:s; 312, identifier:source; 313, block; 313, 314; 313, 330; 313, 341; 313, 351; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:fname; 317, binary_operator:+; 317, 318; 317, 329; 318, call; 318, 319; 318, 326; 319, attribute; 319, 320; 319, 325; 320, attribute; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:s; 323, identifier:attributes; 324, identifier:java_classname; 325, identifier:replace; 326, argument_list; 326, 327; 326, 328; 327, string:'.'; 328, string:'_'; 329, string:'.h'; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 333; 332, identifier:t; 333, call; 333, 334; 333, 339; 334, attribute; 334, 335; 334, 338; 335, subscript; 335, 336; 335, 337; 336, identifier:target; 337, integer:0; 338, identifier:File; 339, argument_list; 339, 340; 340, identifier:fname; 341, expression_statement; 341, 342; 342, assignment; 342, 343; 342, 348; 343, attribute; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:t; 346, identifier:attributes; 347, identifier:java_lookupdir; 348, subscript; 348, 349; 348, 350; 349, identifier:target; 350, integer:0; 351, expression_statement; 351, 352; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:tlist; 355, identifier:append; 356, argument_list; 356, 357; 357, identifier:t; 358, return_statement; 358, 359; 359, expression_list; 359, 360; 359, 361; 360, identifier:tlist; 361, identifier:source
def emit_java_headers(target, source, env): class_suffix = env.get('JAVACLASSSUFFIX', '.class') classdir = env.get('JAVACLASSDIR') if not classdir: try: s = source[0] except IndexError: classdir = '.' else: try: classdir = s.attributes.java_classdir except AttributeError: classdir = '.' classdir = env.Dir(classdir).rdir() if str(classdir) == '.': c_ = None else: c_ = str(classdir) + os.sep slist = [] for src in source: try: classname = src.attributes.java_classname except AttributeError: classname = str(src) if c_ and classname[:len(c_)] == c_: classname = classname[len(c_):] if class_suffix and classname[-len(class_suffix):] == class_suffix: classname = classname[:-len(class_suffix)] classname = SCons.Tool.javac.classname(classname) s = src.rfile() s.attributes.java_classname = classname slist.append(s) s = source[0].rfile() if not hasattr(s.attributes, 'java_classdir'): s.attributes.java_classdir = classdir if target[0].__class__ is SCons.Node.FS.File: tlist = target else: if not isinstance(target[0], SCons.Node.FS.Dir): target[0].__class__ = SCons.Node.FS.Dir target[0]._morph() tlist = [] for s in source: fname = s.attributes.java_classname.replace('.', '_') + '.h' t = target[0].File(fname) t.attributes.java_lookupdir = target[0] tlist.append(t) return tlist, source
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_parse_resource_usage; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:action_dict; 6, identifier:declarations; 7, block; 7, 8; 7, 18; 7, 36; 7, 54; 7, 58; 7, 163; 7, 187; 7, 207; 7, 227; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:raw_used; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:action_dict; 14, identifier:pop; 15, argument_list; 15, 16; 15, 17; 16, string:'use'; 17, list:[]; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:opened; 21, list_comprehension; 21, 22; 21, 27; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:x; 25, identifier:strip; 26, argument_list; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:x; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:action_dict; 32, identifier:pop; 33, argument_list; 33, 34; 33, 35; 34, string:'open_before'; 35, list:[]; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:closed; 39, list_comprehension; 39, 40; 39, 45; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:x; 43, identifier:strip; 44, argument_list; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:x; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:action_dict; 50, identifier:pop; 51, argument_list; 51, 52; 51, 53; 52, string:'close_after'; 53, list:[]; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:used; 57, dictionary; 58, for_statement; 58, 59; 58, 60; 58, 61; 59, identifier:resource; 60, identifier:raw_used; 61, block; 61, 62; 61, 138; 61, 157; 62, if_statement; 62, 63; 62, 66; 62, 124; 63, comparison_operator:in; 63, 64; 63, 65; 64, string:'as'; 65, identifier:resource; 66, block; 66, 67; 66, 79; 66, 87; 66, 95; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 73; 69, pattern_list; 69, 70; 69, 71; 69, 72; 70, identifier:global_name; 71, identifier:_; 72, identifier:local_name; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:resource; 76, identifier:partition; 77, argument_list; 77, 78; 78, string:'as'; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:global_name; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:global_name; 85, identifier:strip; 86, argument_list; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:local_name; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:local_name; 93, identifier:strip; 94, argument_list; 95, if_statement; 95, 96; 95, 109; 96, boolean_operator:or; 96, 97; 96, 103; 97, comparison_operator:==; 97, 98; 97, 102; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, identifier:global_name; 102, integer:0; 103, comparison_operator:==; 103, 104; 103, 108; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, identifier:local_name; 108, integer:0; 109, block; 109, 110; 110, raise_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:RecipeFileInvalid; 113, argument_list; 113, 114; 113, 115; 113, 118; 113, 121; 114, string:"Resource usage specified in action with invalid name using 'as' statement"; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:global_name; 117, identifier:global_name; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:local_name; 120, identifier:local_name; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:statement; 123, identifier:resource; 124, else_clause; 124, 125; 125, block; 125, 126; 125, 134; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:global_name; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:resource; 132, identifier:strip; 133, argument_list; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:local_name; 137, identifier:global_name; 138, if_statement; 138, 139; 138, 142; 139, comparison_operator:in; 139, 140; 139, 141; 140, identifier:local_name; 141, identifier:used; 142, block; 142, 143; 143, raise_statement; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:RecipeFileInvalid; 146, argument_list; 146, 147; 146, 148; 146, 151; 146, 154; 147, string:"Resource specified twice for action"; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:args; 150, identifier:action_dict; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:resource; 153, identifier:local_name; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:used_resources; 156, identifier:used; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 162; 159, subscript; 159, 160; 159, 161; 160, identifier:used; 161, identifier:local_name; 162, identifier:global_name; 163, for_statement; 163, 164; 163, 165; 163, 178; 164, identifier:name; 165, generator_expression; 165, 166; 165, 167; 165, 174; 166, identifier:x; 167, for_in_clause; 167, 168; 167, 169; 168, identifier:x; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:used; 172, identifier:values; 173, argument_list; 174, if_clause; 174, 175; 175, comparison_operator:not; 175, 176; 175, 177; 176, identifier:x; 177, identifier:declarations; 178, block; 178, 179; 179, raise_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:RecipeFileInvalid; 182, argument_list; 182, 183; 182, 184; 183, string:"Action makes use of non-declared shared resource"; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:name; 186, identifier:name; 187, for_statement; 187, 188; 187, 189; 187, 198; 188, identifier:name; 189, generator_expression; 189, 190; 189, 191; 189, 194; 190, identifier:x; 191, for_in_clause; 191, 192; 191, 193; 192, identifier:x; 193, identifier:opened; 194, if_clause; 194, 195; 195, comparison_operator:not; 195, 196; 195, 197; 196, identifier:x; 197, identifier:declarations; 198, block; 198, 199; 199, raise_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:RecipeFileInvalid; 202, argument_list; 202, 203; 202, 204; 203, string:"Action specified a non-declared shared resource in open_before"; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:name; 206, identifier:name; 207, for_statement; 207, 208; 207, 209; 207, 218; 208, identifier:name; 209, generator_expression; 209, 210; 209, 211; 209, 214; 210, identifier:x; 211, for_in_clause; 211, 212; 211, 213; 212, identifier:x; 213, identifier:closed; 214, if_clause; 214, 215; 215, comparison_operator:not; 215, 216; 215, 217; 216, identifier:x; 217, identifier:declarations; 218, block; 218, 219; 219, raise_statement; 219, 220; 220, call; 220, 221; 220, 222; 221, identifier:RecipeFileInvalid; 222, argument_list; 222, 223; 222, 224; 223, string:"Action specified a non-declared shared resource in close_after"; 224, keyword_argument; 224, 225; 224, 226; 225, identifier:name; 226, identifier:name; 227, return_statement; 227, 228; 228, call; 228, 229; 228, 230; 229, identifier:ResourceUsage; 230, argument_list; 230, 231; 230, 232; 230, 233; 231, identifier:used; 232, identifier:opened; 233, identifier:closed
def _parse_resource_usage(cls, action_dict, declarations): raw_used = action_dict.pop('use', []) opened = [x.strip() for x in action_dict.pop('open_before', [])] closed = [x.strip() for x in action_dict.pop('close_after', [])] used = {} for resource in raw_used: if 'as' in resource: global_name, _, local_name = resource.partition('as') global_name = global_name.strip() local_name = local_name.strip() if len(global_name) == 0 or len(local_name) == 0: raise RecipeFileInvalid("Resource usage specified in action with invalid name using 'as' statement", global_name=global_name, local_name=local_name, statement=resource) else: global_name = resource.strip() local_name = global_name if local_name in used: raise RecipeFileInvalid("Resource specified twice for action", args=action_dict, resource=local_name, used_resources=used) used[local_name] = global_name for name in (x for x in used.values() if x not in declarations): raise RecipeFileInvalid("Action makes use of non-declared shared resource", name=name) for name in (x for x in opened if x not in declarations): raise RecipeFileInvalid("Action specified a non-declared shared resource in open_before", name=name) for name in (x for x in closed if x not in declarations): raise RecipeFileInvalid("Action specified a non-declared shared resource in close_after", name=name) return ResourceUsage(used, opened, closed)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:format_script; 3, parameters; 3, 4; 4, identifier:sensor_graph; 5, block; 5, 6; 5, 10; 5, 23; 5, 35; 5, 47; 5, 69; 5, 88; 5, 129; 5, 141; 5, 150; 5, 212; 5, 223; 5, 234; 5, 254; 5, 261; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:records; 9, list:[]; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:records; 14, identifier:append; 15, argument_list; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:SetGraphOnlineRecord; 18, argument_list; 18, 19; 18, 20; 19, False; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:address; 22, integer:8; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:records; 27, identifier:append; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:ClearDataRecord; 31, argument_list; 31, 32; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:address; 34, integer:8; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:records; 39, identifier:append; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:ResetGraphRecord; 43, argument_list; 43, 44; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:address; 46, integer:8; 47, for_statement; 47, 48; 47, 49; 47, 52; 48, identifier:node; 49, attribute; 49, 50; 49, 51; 50, identifier:sensor_graph; 51, identifier:nodes; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:records; 57, identifier:append; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:AddNodeRecord; 61, argument_list; 61, 62; 61, 66; 62, call; 62, 63; 62, 64; 63, identifier:str; 64, argument_list; 64, 65; 65, identifier:node; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:address; 68, integer:8; 69, for_statement; 69, 70; 69, 71; 69, 74; 70, identifier:streamer; 71, attribute; 71, 72; 71, 73; 72, identifier:sensor_graph; 73, identifier:streamers; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:records; 79, identifier:append; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:AddStreamerRecord; 83, argument_list; 83, 84; 83, 85; 84, identifier:streamer; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:address; 87, integer:8; 88, for_statement; 88, 89; 88, 92; 88, 114; 89, pattern_list; 89, 90; 89, 91; 90, identifier:stream; 91, identifier:value; 92, call; 92, 93; 92, 94; 93, identifier:sorted; 94, argument_list; 94, 95; 94, 102; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:sensor_graph; 99, identifier:constant_database; 100, identifier:items; 101, argument_list; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:key; 104, lambda; 104, 105; 104, 107; 105, lambda_parameters; 105, 106; 106, identifier:x; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:x; 111, integer:0; 112, identifier:encode; 113, argument_list; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:records; 119, identifier:append; 120, argument_list; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:SetConstantRecord; 123, argument_list; 123, 124; 123, 125; 123, 126; 124, identifier:stream; 125, identifier:value; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:address; 128, integer:8; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:records; 133, identifier:append; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:PersistGraphRecord; 137, argument_list; 137, 138; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:address; 140, integer:8; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:records; 145, identifier:append; 146, argument_list; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:ClearConfigVariablesRecord; 149, argument_list; 150, for_statement; 150, 151; 150, 152; 150, 168; 151, identifier:slot; 152, call; 152, 153; 152, 154; 153, identifier:sorted; 154, argument_list; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:sensor_graph; 157, identifier:config_database; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:key; 160, lambda; 160, 161; 160, 163; 161, lambda_parameters; 161, 162; 162, identifier:x; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:x; 166, identifier:encode; 167, argument_list; 168, block; 168, 169; 169, for_statement; 169, 170; 169, 171; 169, 179; 170, identifier:config_id; 171, call; 171, 172; 171, 173; 172, identifier:sorted; 173, argument_list; 173, 174; 174, subscript; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:sensor_graph; 177, identifier:config_database; 178, identifier:slot; 179, block; 179, 180; 179, 192; 179, 200; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 185; 182, pattern_list; 182, 183; 182, 184; 183, identifier:config_type; 184, identifier:value; 185, subscript; 185, 186; 185, 191; 186, subscript; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:sensor_graph; 189, identifier:config_database; 190, identifier:slot; 191, identifier:config_id; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:byte_value; 195, call; 195, 196; 195, 197; 196, identifier:_convert_to_bytes; 197, argument_list; 197, 198; 197, 199; 198, identifier:config_type; 199, identifier:value; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:records; 204, identifier:append; 205, argument_list; 205, 206; 206, call; 206, 207; 206, 208; 207, identifier:SetConfigRecord; 208, argument_list; 208, 209; 208, 210; 208, 211; 209, identifier:slot; 210, identifier:config_id; 211, identifier:byte_value; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:app_tag; 215, call; 215, 216; 215, 221; 216, attribute; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:sensor_graph; 219, identifier:metadata_database; 220, identifier:get; 221, argument_list; 221, 222; 222, string:'app_tag'; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:app_version; 226, call; 226, 227; 226, 232; 227, attribute; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:sensor_graph; 230, identifier:metadata_database; 231, identifier:get; 232, argument_list; 232, 233; 233, string:'app_version'; 234, if_statement; 234, 235; 234, 238; 235, comparison_operator:is; 235, 236; 235, 237; 236, identifier:app_tag; 237, None; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:records; 243, identifier:append; 244, argument_list; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:SetDeviceTagRecord; 247, argument_list; 247, 248; 247, 251; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:app_tag; 250, identifier:app_tag; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:app_version; 253, identifier:app_version; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:script; 257, call; 257, 258; 257, 259; 258, identifier:UpdateScript; 259, argument_list; 259, 260; 260, identifier:records; 261, return_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:script; 265, identifier:encode; 266, argument_list
def format_script(sensor_graph): records = [] records.append(SetGraphOnlineRecord(False, address=8)) records.append(ClearDataRecord(address=8)) records.append(ResetGraphRecord(address=8)) for node in sensor_graph.nodes: records.append(AddNodeRecord(str(node), address=8)) for streamer in sensor_graph.streamers: records.append(AddStreamerRecord(streamer, address=8)) for stream, value in sorted(sensor_graph.constant_database.items(), key=lambda x: x[0].encode()): records.append(SetConstantRecord(stream, value, address=8)) records.append(PersistGraphRecord(address=8)) records.append(ClearConfigVariablesRecord()) for slot in sorted(sensor_graph.config_database, key=lambda x: x.encode()): for config_id in sorted(sensor_graph.config_database[slot]): config_type, value = sensor_graph.config_database[slot][config_id] byte_value = _convert_to_bytes(config_type, value) records.append(SetConfigRecord(slot, config_id, byte_value)) app_tag = sensor_graph.metadata_database.get('app_tag') app_version = sensor_graph.metadata_database.get('app_version') if app_tag is not None: records.append(SetDeviceTagRecord(app_tag=app_tag, app_version=app_version)) script = UpdateScript(records) return script.encode()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:push; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:stream; 6, identifier:reading; 7, block; 7, 8; 7, 17; 7, 27; 7, 134; 7, 166; 7, 188; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:reading; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:copy; 14, identifier:copy; 15, argument_list; 15, 16; 16, identifier:reading; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:reading; 21, identifier:stream; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:stream; 25, identifier:encode; 26, argument_list; 27, if_statement; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:stream; 30, identifier:buffered; 31, block; 31, 32; 31, 38; 31, 57; 31, 112; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:output_buffer; 35, attribute; 35, 36; 35, 37; 36, identifier:stream; 37, identifier:output; 38, if_statement; 38, 39; 38, 44; 39, comparison_operator:is; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:id_assigner; 43, None; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:reading; 49, identifier:reading_id; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:id_assigner; 54, argument_list; 54, 55; 54, 56; 55, identifier:stream; 56, identifier:reading; 57, try_statement; 57, 58; 57, 68; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:_engine; 65, identifier:push; 66, argument_list; 66, 67; 67, identifier:reading; 68, except_clause; 68, 69; 68, 70; 69, identifier:StorageFullError; 70, block; 70, 71; 70, 94; 70, 103; 71, if_statement; 71, 72; 71, 92; 72, boolean_operator:or; 72, 73; 72, 82; 73, parenthesized_expression; 73, 74; 74, boolean_operator:and; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:stream; 77, identifier:output; 78, not_operator; 78, 79; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:_rollover_streaming; 82, parenthesized_expression; 82, 83; 83, boolean_operator:and; 83, 84; 83, 88; 84, not_operator; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:stream; 87, identifier:output; 88, not_operator; 88, 89; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:_rollover_storage; 92, block; 92, 93; 93, raise_statement; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_erase_buffer; 99, argument_list; 99, 100; 100, attribute; 100, 101; 100, 102; 101, identifier:stream; 102, identifier:output; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 110; 105, attribute; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:_engine; 109, identifier:push; 110, argument_list; 110, 111; 111, identifier:reading; 112, for_statement; 112, 113; 112, 114; 112, 117; 113, identifier:walker; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:_queue_walkers; 117, block; 117, 118; 118, if_statement; 118, 119; 118, 126; 119, comparison_operator:==; 119, 120; 119, 125; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:walker; 123, identifier:selector; 124, identifier:output; 125, identifier:output_buffer; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:walker; 131, identifier:notify_added; 132, argument_list; 132, 133; 133, identifier:stream; 134, for_statement; 134, 135; 134, 136; 134, 139; 135, identifier:selector; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:_monitors; 139, block; 139, 140; 140, if_statement; 140, 141; 140, 151; 141, boolean_operator:or; 141, 142; 141, 145; 142, comparison_operator:is; 142, 143; 142, 144; 143, identifier:selector; 144, None; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:selector; 148, identifier:matches; 149, argument_list; 149, 150; 150, identifier:stream; 151, block; 151, 152; 152, for_statement; 152, 153; 152, 154; 152, 159; 153, identifier:callback; 154, subscript; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:_monitors; 158, identifier:selector; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:callback; 163, argument_list; 163, 164; 163, 165; 164, identifier:stream; 165, identifier:reading; 166, for_statement; 166, 167; 166, 168; 166, 171; 167, identifier:walker; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:_virtual_walkers; 171, block; 171, 172; 172, if_statement; 172, 173; 172, 179; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:walker; 176, identifier:matches; 177, argument_list; 177, 178; 178, identifier:stream; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:walker; 184, identifier:push; 185, argument_list; 185, 186; 185, 187; 186, identifier:stream; 187, identifier:reading; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 195; 190, subscript; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:_last_values; 194, identifier:stream; 195, identifier:reading
def push(self, stream, reading): reading = copy.copy(reading) reading.stream = stream.encode() if stream.buffered: output_buffer = stream.output if self.id_assigner is not None: reading.reading_id = self.id_assigner(stream, reading) try: self._engine.push(reading) except StorageFullError: if (stream.output and not self._rollover_streaming) or (not stream.output and not self._rollover_storage): raise self._erase_buffer(stream.output) self._engine.push(reading) for walker in self._queue_walkers: if walker.selector.output == output_buffer: walker.notify_added(stream) for selector in self._monitors: if selector is None or selector.matches(stream): for callback in self._monitors[selector]: callback(stream, reading) for walker in self._virtual_walkers: if walker.matches(stream): walker.push(stream, reading) self._last_values[stream] = reading
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:inspect_last; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:stream; 6, default_parameter; 6, 7; 6, 8; 7, identifier:only_allocated; 8, False; 9, block; 9, 10; 9, 48; 9, 61; 10, if_statement; 10, 11; 10, 12; 11, identifier:only_allocated; 12, block; 12, 13; 12, 17; 12, 36; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:found; 16, False; 17, for_statement; 17, 18; 17, 19; 17, 22; 18, identifier:walker; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_virtual_walkers; 22, block; 22, 23; 23, if_statement; 23, 24; 23, 30; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:walker; 27, identifier:matches; 28, argument_list; 28, 29; 29, identifier:stream; 30, block; 30, 31; 30, 35; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:found; 34, True; 35, break_statement; 36, if_statement; 36, 37; 36, 39; 37, not_operator; 37, 38; 38, identifier:found; 39, block; 39, 40; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:UnresolvedIdentifierError; 43, argument_list; 43, 44; 43, 45; 44, string:"inspect_last could not find an allocated virtual streamer for the desired stream"; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:stream; 47, identifier:stream; 48, if_statement; 48, 49; 48, 54; 49, comparison_operator:in; 49, 50; 49, 51; 50, identifier:stream; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_last_values; 54, block; 54, 55; 55, return_statement; 55, 56; 56, subscript; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_last_values; 60, identifier:stream; 61, raise_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:StreamEmptyError; 64, argument_list; 64, 65; 64, 66; 65, string:u"inspect_last called on stream that has never been written to"; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:stream; 68, identifier:stream
def inspect_last(self, stream, only_allocated=False): if only_allocated: found = False for walker in self._virtual_walkers: if walker.matches(stream): found = True break if not found: raise UnresolvedIdentifierError("inspect_last could not find an allocated virtual streamer for the desired stream", stream=stream) if stream in self._last_values: return self._last_values[stream] raise StreamEmptyError(u"inspect_last called on stream that has never been written to", stream=stream)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_dllEmitter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:target; 5, identifier:source; 6, identifier:env; 7, identifier:paramtp; 8, block; 8, 9; 8, 20; 8, 24; 8, 28; 8, 43; 8, 53; 8, 75; 8, 84; 8, 124; 8, 145; 8, 188; 8, 231; 8, 276; 8, 331; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 18; 11, attribute; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:SCons; 15, identifier:Tool; 16, identifier:msvc; 17, identifier:validate_vars; 18, argument_list; 18, 19; 19, identifier:env; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:extratargets; 23, list:[]; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:extrasources; 27, list:[]; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:dll; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:env; 34, identifier:FindIxes; 35, argument_list; 35, 36; 35, 37; 35, 40; 36, identifier:target; 37, binary_operator:%; 37, 38; 37, 39; 38, string:'%sPREFIX'; 39, identifier:paramtp; 40, binary_operator:%; 40, 41; 40, 42; 41, string:'%sSUFFIX'; 42, identifier:paramtp; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:no_import_lib; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:env; 49, identifier:get; 50, argument_list; 50, 51; 50, 52; 51, string:'no_import_lib'; 52, integer:0; 53, if_statement; 53, 54; 53, 56; 54, not_operator; 54, 55; 55, identifier:dll; 56, block; 56, 57; 57, raise_statement; 57, 58; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:SCons; 62, identifier:Errors; 63, identifier:UserError; 64, argument_list; 64, 65; 65, binary_operator:%; 65, 66; 65, 67; 66, string:'A shared library should have exactly one target with the suffix: %s'; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:env; 70, identifier:subst; 71, argument_list; 71, 72; 72, binary_operator:%; 72, 73; 72, 74; 73, string:'$%sSUFFIX'; 74, identifier:paramtp; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:insert_def; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:env; 81, identifier:subst; 82, argument_list; 82, 83; 83, string:"$WINDOWS_INSERT_DEF"; 84, if_statement; 84, 85; 84, 103; 85, boolean_operator:and; 85, 86; 85, 93; 85, 94; 86, not_operator; 86, 87; 87, comparison_operator:in; 87, 88; 87, 89; 88, identifier:insert_def; 89, list:['', '0', 0]; 89, 90; 89, 91; 89, 92; 90, string:''; 91, string:'0'; 92, integer:0; 93, line_continuation:\; 94, not_operator; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:env; 98, identifier:FindIxes; 99, argument_list; 99, 100; 99, 101; 99, 102; 100, identifier:source; 101, string:"WINDOWSDEFPREFIX"; 102, string:"WINDOWSDEFSUFFIX"; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:extrasources; 108, identifier:append; 109, argument_list; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:env; 113, identifier:ReplaceIxes; 114, argument_list; 114, 115; 114, 116; 114, 119; 114, 122; 114, 123; 115, identifier:dll; 116, binary_operator:%; 116, 117; 116, 118; 117, string:'%sPREFIX'; 118, identifier:paramtp; 119, binary_operator:%; 119, 120; 119, 121; 120, string:'%sSUFFIX'; 121, identifier:paramtp; 122, string:"WINDOWSDEFPREFIX"; 123, string:"WINDOWSDEFSUFFIX"; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 129; 126, pattern_list; 126, 127; 126, 128; 127, identifier:version_num; 128, identifier:suite; 129, call; 129, 130; 129, 137; 130, attribute; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:SCons; 134, identifier:Tool; 135, identifier:msvs; 136, identifier:msvs_parse_version; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:env; 141, identifier:get; 142, argument_list; 142, 143; 142, 144; 143, string:'MSVS_VERSION'; 144, string:'6.0'; 145, if_statement; 145, 146; 145, 167; 146, boolean_operator:and; 146, 147; 146, 150; 146, 151; 147, comparison_operator:>=; 147, 148; 147, 149; 148, identifier:version_num; 149, float:8.0; 150, line_continuation:\; 151, parenthesized_expression; 151, 152; 152, boolean_operator:or; 152, 153; 152, 160; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:env; 156, identifier:get; 157, argument_list; 157, 158; 157, 159; 158, string:'WINDOWS_INSERT_MANIFEST'; 159, integer:0; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:env; 163, identifier:get; 164, argument_list; 164, 165; 164, 166; 165, string:'WINDOWS_EMBED_MANIFEST'; 166, integer:0; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:extratargets; 172, identifier:append; 173, argument_list; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:env; 177, identifier:ReplaceIxes; 178, argument_list; 178, 179; 178, 180; 178, 183; 178, 186; 178, 187; 179, identifier:dll; 180, binary_operator:%; 180, 181; 180, 182; 181, string:'%sPREFIX'; 182, identifier:paramtp; 183, binary_operator:%; 183, 184; 183, 185; 184, string:'%sSUFFIX'; 185, identifier:paramtp; 186, string:"WINDOWSSHLIBMANIFESTPREFIX"; 187, string:"WINDOWSSHLIBMANIFESTSUFFIX"; 188, if_statement; 188, 189; 188, 196; 189, boolean_operator:and; 189, 190; 189, 193; 190, comparison_operator:in; 190, 191; 190, 192; 191, string:'PDB'; 192, identifier:env; 193, subscript; 193, 194; 193, 195; 194, identifier:env; 195, string:'PDB'; 196, block; 196, 197; 196, 214; 196, 221; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:pdb; 200, subscript; 200, 201; 200, 213; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:env; 204, identifier:arg2nodes; 205, argument_list; 205, 206; 205, 207; 205, 210; 206, string:'$PDB'; 207, keyword_argument; 207, 208; 207, 209; 208, identifier:target; 209, identifier:target; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:source; 212, identifier:source; 213, integer:0; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:extratargets; 218, identifier:append; 219, argument_list; 219, 220; 220, identifier:pdb; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 230; 223, attribute; 223, 224; 223, 229; 224, attribute; 224, 225; 224, 228; 225, subscript; 225, 226; 225, 227; 226, identifier:target; 227, integer:0; 228, identifier:attributes; 229, identifier:pdb; 230, identifier:pdb; 231, if_statement; 231, 232; 231, 243; 232, boolean_operator:and; 232, 233; 232, 236; 233, comparison_operator:>=; 233, 234; 233, 235; 234, identifier:version_num; 235, float:11.0; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:env; 239, identifier:get; 240, argument_list; 240, 241; 240, 242; 241, string:'PCH'; 242, integer:0; 243, block; 243, 244; 243, 264; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:pchobj; 247, binary_operator:+; 247, 248; 247, 263; 248, subscript; 248, 249; 248, 262; 249, call; 249, 250; 249, 255; 250, attribute; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:SCons; 253, identifier:Util; 254, identifier:splitext; 255, argument_list; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:str; 258, argument_list; 258, 259; 259, subscript; 259, 260; 259, 261; 260, identifier:env; 261, string:'PCH'; 262, integer:0; 263, string:'.obj'; 264, if_statement; 264, 265; 264, 268; 265, comparison_operator:not; 265, 266; 265, 267; 266, identifier:pchobj; 267, identifier:extrasources; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:extrasources; 273, identifier:append; 274, argument_list; 274, 275; 275, identifier:pchobj; 276, if_statement; 276, 277; 276, 290; 277, boolean_operator:and; 277, 278; 277, 280; 277, 281; 278, not_operator; 278, 279; 279, identifier:no_import_lib; 280, line_continuation:\; 281, not_operator; 281, 282; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:env; 285, identifier:FindIxes; 286, argument_list; 286, 287; 286, 288; 286, 289; 287, identifier:target; 288, string:"LIBPREFIX"; 289, string:"LIBSUFFIX"; 290, block; 290, 291; 290, 311; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:extratargets; 295, identifier:append; 296, argument_list; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:env; 300, identifier:ReplaceIxes; 301, argument_list; 301, 302; 301, 303; 301, 306; 301, 309; 301, 310; 302, identifier:dll; 303, binary_operator:%; 303, 304; 303, 305; 304, string:'%sPREFIX'; 305, identifier:paramtp; 306, binary_operator:%; 306, 307; 306, 308; 307, string:'%sSUFFIX'; 308, identifier:paramtp; 309, string:"LIBPREFIX"; 310, string:"LIBSUFFIX"; 311, expression_statement; 311, 312; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:extratargets; 315, identifier:append; 316, argument_list; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:env; 320, identifier:ReplaceIxes; 321, argument_list; 321, 322; 321, 323; 321, 326; 321, 329; 321, 330; 322, identifier:dll; 323, binary_operator:%; 323, 324; 323, 325; 324, string:'%sPREFIX'; 325, identifier:paramtp; 326, binary_operator:%; 326, 327; 326, 328; 327, string:'%sSUFFIX'; 328, identifier:paramtp; 329, string:"WINDOWSEXPPREFIX"; 330, string:"WINDOWSEXPSUFFIX"; 331, return_statement; 331, 332; 332, tuple; 332, 333; 332, 336; 333, binary_operator:+; 333, 334; 333, 335; 334, identifier:target; 335, identifier:extratargets; 336, binary_operator:+; 336, 337; 336, 338; 337, identifier:source; 338, identifier:extrasources
def _dllEmitter(target, source, env, paramtp): SCons.Tool.msvc.validate_vars(env) extratargets = [] extrasources = [] dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp) no_import_lib = env.get('no_import_lib', 0) if not dll: raise SCons.Errors.UserError('A shared library should have exactly one target with the suffix: %s' % env.subst('$%sSUFFIX' % paramtp)) insert_def = env.subst("$WINDOWS_INSERT_DEF") if not insert_def in ['', '0', 0] and \ not env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"): extrasources.append( env.ReplaceIxes(dll, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX")) version_num, suite = SCons.Tool.msvs.msvs_parse_version(env.get('MSVS_VERSION', '6.0')) if version_num >= 8.0 and \ (env.get('WINDOWS_INSERT_MANIFEST', 0) or env.get('WINDOWS_EMBED_MANIFEST', 0)): extratargets.append( env.ReplaceIxes(dll, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSSHLIBMANIFESTPREFIX", "WINDOWSSHLIBMANIFESTSUFFIX")) if 'PDB' in env and env['PDB']: pdb = env.arg2nodes('$PDB', target=target, source=source)[0] extratargets.append(pdb) target[0].attributes.pdb = pdb if version_num >= 11.0 and env.get('PCH', 0): pchobj = SCons.Util.splitext(str(env['PCH']))[0] + '.obj' if pchobj not in extrasources: extrasources.append(pchobj) if not no_import_lib and \ not env.FindIxes(target, "LIBPREFIX", "LIBSUFFIX"): extratargets.append( env.ReplaceIxes(dll, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "LIBPREFIX", "LIBSUFFIX")) extratargets.append( env.ReplaceIxes(dll, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSEXPPREFIX", "WINDOWSEXPSUFFIX")) return (target+extratargets, source+extrasources)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:setup_environment; 3, parameters; 3, 4; 3, 5; 4, identifier:chip; 5, default_parameter; 5, 6; 5, 7; 6, identifier:args_file; 7, None; 8, block; 8, 9; 8, 15; 8, 56; 8, 62; 8, 68; 8, 74; 8, 80; 8, 90; 8, 96; 8, 102; 8, 108; 8, 114; 8, 120; 8, 126; 8, 132; 8, 165; 8, 176; 8, 187; 8, 201; 8, 215; 8, 230; 8, 236; 8, 252; 8, 268; 8, 284; 8, 300; 8, 306; 8, 312; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:config; 12, call; 12, 13; 12, 14; 13, identifier:ConfigManager; 14, argument_list; 15, if_statement; 15, 16; 15, 23; 15, 39; 16, comparison_operator:==; 16, 17; 16, 22; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:platform; 20, identifier:system; 21, argument_list; 22, string:'Windows'; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:env; 27, call; 27, 28; 27, 29; 28, identifier:Environment; 29, argument_list; 29, 30; 29, 34; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:tools; 32, list:['mingw']; 32, 33; 33, string:'mingw'; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:ENV; 36, attribute; 36, 37; 36, 38; 37, identifier:os; 38, identifier:environ; 39, else_clause; 39, 40; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:env; 44, call; 44, 45; 44, 46; 45, identifier:Environment; 46, argument_list; 46, 47; 46, 51; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:tools; 49, list:['default']; 49, 50; 50, string:'default'; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:ENV; 53, attribute; 53, 54; 53, 55; 54, identifier:os; 55, identifier:environ; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:env; 60, string:'INCPREFIX'; 61, string:'-I"'; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:env; 66, string:'INCSUFFIX'; 67, string:'"'; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:env; 72, string:'CPPDEFPREFIX'; 73, string:''; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:env; 78, string:'CPPDEFSUFFIX'; 79, string:''; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:env; 84, string:'CPPPATH'; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:chip; 88, identifier:includes; 89, argument_list; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:env; 94, string:'ARCH'; 95, identifier:chip; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:env; 100, string:'CC'; 101, string:'arm-none-eabi-gcc'; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:env; 106, string:'AS'; 107, string:'arm-none-eabi-gcc'; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:env; 112, string:'LINK'; 113, string:'arm-none-eabi-gcc'; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:env; 118, string:'AR'; 119, string:'arm-none-eabi-ar'; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:env; 124, string:'RANLIB'; 125, string:'arm-none-eabi-ranlib'; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:env; 130, string:'ASCOM'; 131, string:"$AS $ASFLAGS -o $TARGET -c $SOURCES"; 132, if_statement; 132, 133; 132, 140; 133, not_operator; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:config; 137, identifier:get; 138, argument_list; 138, 139; 139, string:'build:show-commands'; 140, block; 140, 141; 140, 147; 140, 153; 140, 159; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:env; 145, string:'CCCOMSTR'; 146, string:"Compiling $TARGET"; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:env; 151, string:'ARCOMSTR'; 152, string:"Building static library $TARGET"; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:env; 157, string:'RANLIBCOMSTR'; 158, string:"Indexing static library $TARGET"; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:env; 163, string:'LINKCOMSTR'; 164, string:"Linking $TARGET"; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:env; 169, string:'CCFLAGS'; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:chip; 173, identifier:combined_properties; 174, argument_list; 174, 175; 175, string:'cflags'; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, subscript; 178, 179; 178, 180; 179, identifier:env; 180, string:'LINKFLAGS'; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:chip; 184, identifier:combined_properties; 185, argument_list; 185, 186; 186, string:'ldflags'; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 194; 189, attribute; 189, 190; 189, 193; 190, subscript; 190, 191; 190, 192; 191, identifier:env; 192, string:'ARFLAGS'; 193, identifier:append; 194, argument_list; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:chip; 198, identifier:combined_properties; 199, argument_list; 199, 200; 200, string:'arflags'; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, subscript; 204, 205; 204, 206; 205, identifier:env; 206, string:'ASFLAGS'; 207, identifier:append; 208, argument_list; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:chip; 212, identifier:combined_properties; 213, argument_list; 213, 214; 214, string:'asflags'; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:defines; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:utilities; 221, identifier:build_defines; 222, argument_list; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:chip; 226, identifier:property; 227, argument_list; 227, 228; 227, 229; 228, string:'defines'; 229, dictionary; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 235; 232, subscript; 232, 233; 232, 234; 233, identifier:env; 234, string:'CPPDEFINES'; 235, identifier:defines; 236, if_statement; 236, 237; 236, 240; 237, comparison_operator:is; 237, 238; 237, 239; 238, identifier:args_file; 239, None; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 246; 243, subscript; 243, 244; 243, 245; 244, identifier:env; 245, string:'CCCOM'; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, string:"$CC $CCFLAGS $CPPFLAGS @{} -c -o $TARGET $SOURCES"; 249, identifier:format; 250, argument_list; 250, 251; 251, identifier:args_file; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 259; 254, attribute; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:env; 257, string:'CCFLAGS'; 258, identifier:append; 259, argument_list; 259, 260; 260, binary_operator:%; 260, 261; 260, 262; 261, string:'-mcpu=%s'; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:chip; 265, identifier:property; 266, argument_list; 266, 267; 267, string:'cpu'; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 275; 270, attribute; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:env; 273, string:'ASFLAGS'; 274, identifier:append; 275, argument_list; 275, 276; 276, binary_operator:%; 276, 277; 276, 278; 277, string:'-mcpu=%s'; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:chip; 281, identifier:property; 282, argument_list; 282, 283; 283, string:'cpu'; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, subscript; 287, 288; 287, 289; 288, identifier:env; 289, string:'LINKFLAGS'; 290, identifier:append; 291, argument_list; 291, 292; 292, binary_operator:%; 292, 293; 292, 294; 293, string:'-mcpu=%s'; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:chip; 297, identifier:property; 298, argument_list; 298, 299; 299, string:'cpu'; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 305; 302, subscript; 302, 303; 302, 304; 303, identifier:env; 304, string:'LIBPATH'; 305, list:[]; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 311; 308, subscript; 308, 309; 308, 310; 309, identifier:env; 310, string:'LIBS'; 311, list:[]; 312, return_statement; 312, 313; 313, identifier:env
def setup_environment(chip, args_file=None): config = ConfigManager() if platform.system() == 'Windows': env = Environment(tools=['mingw'], ENV=os.environ) else: env = Environment(tools=['default'], ENV=os.environ) env['INCPREFIX'] = '-I"' env['INCSUFFIX'] = '"' env['CPPDEFPREFIX'] = '' env['CPPDEFSUFFIX'] = '' env['CPPPATH'] = chip.includes() env['ARCH'] = chip env['CC'] = 'arm-none-eabi-gcc' env['AS'] = 'arm-none-eabi-gcc' env['LINK'] = 'arm-none-eabi-gcc' env['AR'] = 'arm-none-eabi-ar' env['RANLIB'] = 'arm-none-eabi-ranlib' env['ASCOM'] = "$AS $ASFLAGS -o $TARGET -c $SOURCES" if not config.get('build:show-commands'): env['CCCOMSTR'] = "Compiling $TARGET" env['ARCOMSTR'] = "Building static library $TARGET" env['RANLIBCOMSTR'] = "Indexing static library $TARGET" env['LINKCOMSTR'] = "Linking $TARGET" env['CCFLAGS'] = chip.combined_properties('cflags') env['LINKFLAGS'] = chip.combined_properties('ldflags') env['ARFLAGS'].append(chip.combined_properties('arflags')) env['ASFLAGS'].append(chip.combined_properties('asflags')) defines = utilities.build_defines(chip.property('defines', {})) env['CPPDEFINES'] = defines if args_file is not None: env['CCCOM'] = "$CC $CCFLAGS $CPPFLAGS @{} -c -o $TARGET $SOURCES".format(args_file) env['CCFLAGS'].append('-mcpu=%s' % chip.property('cpu')) env['ASFLAGS'].append('-mcpu=%s' % chip.property('cpu')) env['LINKFLAGS'].append('-mcpu=%s' % chip.property('cpu')) env['LIBPATH'] = [] env['LIBS'] = [] return env
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:fastqRead; 3, parameters; 3, 4; 4, identifier:fileHandleOrFile; 5, block; 5, 6; 5, 13; 5, 21; 5, 208; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:fileHandle; 9, call; 9, 10; 9, 11; 10, identifier:_getFileHandle; 11, argument_list; 11, 12; 12, identifier:fileHandleOrFile; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:line; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:fileHandle; 19, identifier:readline; 20, argument_list; 21, while_statement; 21, 22; 21, 25; 22, comparison_operator:!=; 22, 23; 22, 24; 23, identifier:line; 24, string:''; 25, block; 25, 26; 25, 200; 26, if_statement; 26, 27; 26, 32; 27, comparison_operator:==; 27, 28; 27, 31; 28, subscript; 28, 29; 28, 30; 29, identifier:line; 30, integer:0; 31, string:'@'; 32, block; 32, 33; 32, 43; 32, 56; 32, 64; 32, 78; 32, 98; 32, 153; 32, 194; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:name; 36, subscript; 36, 37; 36, 38; 37, identifier:line; 38, slice; 38, 39; 38, 40; 38, 41; 39, integer:1; 40, colon; 41, unary_operator:-; 41, 42; 42, integer:1; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:seq; 46, subscript; 46, 47; 46, 52; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:fileHandle; 50, identifier:readline; 51, argument_list; 52, slice; 52, 53; 52, 54; 53, colon; 54, unary_operator:-; 54, 55; 55, integer:1; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:plus; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:fileHandle; 62, identifier:readline; 63, argument_list; 64, if_statement; 64, 65; 64, 70; 65, comparison_operator:!=; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:plus; 68, integer:0; 69, string:'+'; 70, block; 70, 71; 71, raise_statement; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:RuntimeError; 74, argument_list; 74, 75; 75, binary_operator:%; 75, 76; 75, 77; 76, string:"Got unexpected line: %s"; 77, identifier:plus; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:qualValues; 81, list_comprehension; 81, 82; 81, 86; 82, call; 82, 83; 82, 84; 83, identifier:ord; 84, argument_list; 84, 85; 85, identifier:i; 86, for_in_clause; 86, 87; 86, 88; 87, identifier:i; 88, subscript; 88, 89; 88, 94; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:fileHandle; 92, identifier:readline; 93, argument_list; 94, slice; 94, 95; 94, 96; 95, colon; 96, unary_operator:-; 96, 97; 97, integer:1; 98, if_statement; 98, 99; 98, 108; 98, 131; 99, comparison_operator:!=; 99, 100; 99, 104; 100, call; 100, 101; 100, 102; 101, identifier:len; 102, argument_list; 102, 103; 103, identifier:seq; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, identifier:qualValues; 108, block; 108, 109; 108, 127; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:logger; 113, identifier:critical; 114, argument_list; 114, 115; 115, binary_operator:%; 115, 116; 115, 117; 116, string:"Got a mismatch between the number of sequence characters (%s) and number of qual values (%s) for sequence: %s, ignoring returning None"; 117, tuple; 117, 118; 117, 122; 117, 126; 118, call; 118, 119; 118, 120; 119, identifier:len; 120, argument_list; 120, 121; 121, identifier:seq; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:qualValues; 126, identifier:name; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:qualValues; 130, None; 131, else_clause; 131, 132; 132, block; 132, 133; 133, for_statement; 133, 134; 133, 135; 133, 136; 134, identifier:i; 135, identifier:qualValues; 136, block; 136, 137; 137, if_statement; 137, 138; 137, 145; 138, boolean_operator:or; 138, 139; 138, 142; 139, comparison_operator:<; 139, 140; 139, 141; 140, identifier:i; 141, integer:33; 142, comparison_operator:>; 142, 143; 142, 144; 143, identifier:i; 144, integer:126; 145, block; 145, 146; 146, raise_statement; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:RuntimeError; 149, argument_list; 149, 150; 150, binary_operator:%; 150, 151; 150, 152; 151, string:"Got a qual value out of range %s (range is 33 to 126)"; 152, identifier:i; 153, for_statement; 153, 154; 153, 155; 153, 156; 154, identifier:i; 155, identifier:seq; 156, block; 156, 157; 157, if_statement; 157, 158; 157, 181; 158, not_operator; 158, 159; 159, parenthesized_expression; 159, 160; 160, boolean_operator:or; 160, 161; 160, 178; 161, boolean_operator:or; 161, 162; 161, 170; 162, parenthesized_expression; 162, 163; 163, boolean_operator:and; 163, 164; 163, 167; 164, comparison_operator:>=; 164, 165; 164, 166; 165, identifier:i; 166, string:'A'; 167, comparison_operator:<=; 167, 168; 167, 169; 168, identifier:i; 169, string:'Z'; 170, parenthesized_expression; 170, 171; 171, boolean_operator:and; 171, 172; 171, 175; 172, comparison_operator:>=; 172, 173; 172, 174; 173, identifier:i; 174, string:'a'; 175, comparison_operator:<=; 175, 176; 175, 177; 176, identifier:i; 177, string:'z'; 178, comparison_operator:==; 178, 179; 178, 180; 179, identifier:i; 180, string:'-'; 181, block; 181, 182; 182, raise_statement; 182, 183; 183, call; 183, 184; 183, 185; 184, identifier:RuntimeError; 185, argument_list; 185, 186; 186, binary_operator:%; 186, 187; 186, 188; 187, string:"Invalid FASTQ character, ASCII code = \'%d\', found in input sequence %s"; 188, tuple; 188, 189; 188, 193; 189, call; 189, 190; 189, 191; 190, identifier:ord; 191, argument_list; 191, 192; 192, identifier:i; 193, identifier:name; 194, expression_statement; 194, 195; 195, yield; 195, 196; 196, expression_list; 196, 197; 196, 198; 196, 199; 197, identifier:name; 198, identifier:seq; 199, identifier:qualValues; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:line; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:fileHandle; 206, identifier:readline; 207, argument_list; 208, if_statement; 208, 209; 208, 216; 209, call; 209, 210; 209, 211; 210, identifier:isinstance; 211, argument_list; 211, 212; 211, 213; 212, identifier:fileHandleOrFile; 213, attribute; 213, 214; 213, 215; 214, string:""; 215, identifier:__class__; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:fileHandle; 221, identifier:close; 222, argument_list
def fastqRead(fileHandleOrFile): fileHandle = _getFileHandle(fileHandleOrFile) line = fileHandle.readline() while line != '': if line[0] == '@': name = line[1:-1] seq = fileHandle.readline()[:-1] plus = fileHandle.readline() if plus[0] != '+': raise RuntimeError("Got unexpected line: %s" % plus) qualValues = [ ord(i) for i in fileHandle.readline()[:-1] ] if len(seq) != len(qualValues): logger.critical("Got a mismatch between the number of sequence characters (%s) and number of qual values (%s) for sequence: %s, ignoring returning None" % (len(seq), len(qualValues), name)) qualValues = None else: for i in qualValues: if i < 33 or i > 126: raise RuntimeError("Got a qual value out of range %s (range is 33 to 126)" % i) for i in seq: if not ((i >= 'A' and i <= 'Z') or (i >= 'a' and i <= 'z') or i == '-'): raise RuntimeError("Invalid FASTQ character, ASCII code = \'%d\', found in input sequence %s" % (ord(i), name)) yield name, seq, qualValues line = fileHandle.readline() if isinstance(fileHandleOrFile, "".__class__): fileHandle.close()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:newickTreeParser; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 9; 3, 12; 4, identifier:newickTree; 5, default_parameter; 5, 6; 5, 7; 6, identifier:defaultDistance; 7, identifier:DEFAULT_DISTANCE; 8, line_continuation:\; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sortNonBinaryNodes; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:reportUnaryNodes; 14, False; 15, block; 15, 16; 15, 26; 15, 36; 15, 46; 15, 56; 15, 66; 15, 80; 15, 92; 15, 140; 15, 187; 15, 426; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:newickTree; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:newickTree; 22, identifier:replace; 23, argument_list; 23, 24; 23, 25; 24, string:"("; 25, string:" ( "; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:newickTree; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:newickTree; 32, identifier:replace; 33, argument_list; 33, 34; 33, 35; 34, string:")"; 35, string:" ) "; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:newickTree; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:newickTree; 42, identifier:replace; 43, argument_list; 43, 44; 43, 45; 44, string:":"; 45, string:" : "; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:newickTree; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:newickTree; 52, identifier:replace; 53, argument_list; 53, 54; 53, 55; 54, string:";"; 55, string:""; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:newickTree; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:newickTree; 62, identifier:replace; 63, argument_list; 63, 64; 63, 65; 64, string:","; 65, string:" , "; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:newickTree; 69, call; 69, 70; 69, 78; 70, attribute; 70, 71; 70, 77; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:re; 74, identifier:compile; 75, argument_list; 75, 76; 76, string:"[\s]*"; 77, identifier:split; 78, argument_list; 78, 79; 79, identifier:newickTree; 80, while_statement; 80, 81; 80, 84; 81, comparison_operator:in; 81, 82; 81, 83; 82, string:""; 83, identifier:newickTree; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:newickTree; 89, identifier:remove; 90, argument_list; 90, 91; 91, string:""; 92, function_definition; 92, 93; 92, 94; 92, 97; 93, function_name:fn; 94, parameters; 94, 95; 94, 96; 95, identifier:newickTree; 96, identifier:i; 97, block; 97, 98; 97, 138; 98, if_statement; 98, 99; 98, 107; 99, comparison_operator:<; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:i; 102, integer:0; 103, call; 103, 104; 103, 105; 104, identifier:len; 105, argument_list; 105, 106; 106, identifier:newickTree; 107, block; 107, 108; 108, if_statement; 108, 109; 108, 116; 109, comparison_operator:==; 109, 110; 109, 115; 110, subscript; 110, 111; 110, 112; 111, identifier:newickTree; 112, subscript; 112, 113; 112, 114; 113, identifier:i; 114, integer:0; 115, string:':'; 116, block; 116, 117; 116, 130; 116, 136; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:d; 120, call; 120, 121; 120, 122; 121, identifier:float; 122, argument_list; 122, 123; 123, subscript; 123, 124; 123, 125; 124, identifier:newickTree; 125, binary_operator:+; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:i; 128, integer:0; 129, integer:1; 130, expression_statement; 130, 131; 131, augmented_assignment:+=; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:i; 134, integer:0; 135, integer:2; 136, return_statement; 136, 137; 137, identifier:d; 138, return_statement; 138, 139; 139, identifier:defaultDistance; 140, function_definition; 140, 141; 140, 142; 140, 145; 141, function_name:fn2; 142, parameters; 142, 143; 142, 144; 143, identifier:newickTree; 144, identifier:i; 145, block; 145, 146; 145, 185; 146, if_statement; 146, 147; 146, 155; 147, comparison_operator:<; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:i; 150, integer:0; 151, call; 151, 152; 151, 153; 152, identifier:len; 153, argument_list; 153, 154; 154, identifier:newickTree; 155, block; 155, 156; 155, 164; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:j; 159, subscript; 159, 160; 159, 161; 160, identifier:newickTree; 161, subscript; 161, 162; 161, 163; 162, identifier:i; 163, integer:0; 164, if_statement; 164, 165; 164, 176; 165, boolean_operator:and; 165, 166; 165, 173; 166, boolean_operator:and; 166, 167; 166, 170; 167, comparison_operator:!=; 167, 168; 167, 169; 168, identifier:j; 169, string:':'; 170, comparison_operator:!=; 170, 171; 170, 172; 171, identifier:j; 172, string:')'; 173, comparison_operator:!=; 173, 174; 173, 175; 174, identifier:j; 175, string:','; 176, block; 176, 177; 176, 183; 177, expression_statement; 177, 178; 178, augmented_assignment:+=; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:i; 181, integer:0; 182, integer:1; 183, return_statement; 183, 184; 184, identifier:j; 185, return_statement; 185, 186; 186, None; 187, function_definition; 187, 188; 187, 189; 187, 192; 188, function_name:fn3; 189, parameters; 189, 190; 189, 191; 190, identifier:newickTree; 191, identifier:i; 192, block; 192, 193; 192, 405; 192, 413; 193, if_statement; 193, 194; 193, 201; 194, comparison_operator:==; 194, 195; 194, 200; 195, subscript; 195, 196; 195, 197; 196, identifier:newickTree; 197, subscript; 197, 198; 197, 199; 198, identifier:i; 199, integer:0; 200, string:'('; 201, block; 201, 202; 201, 206; 201, 212; 201, 216; 201, 251; 201, 257; 201, 288; 201, 298; 201, 304; 201, 403; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:subTreeList; 205, list:[]; 206, expression_statement; 206, 207; 207, augmented_assignment:+=; 207, 208; 207, 211; 208, subscript; 208, 209; 208, 210; 209, identifier:i; 210, integer:0; 211, integer:1; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:k; 215, list:[]; 216, while_statement; 216, 217; 216, 224; 217, comparison_operator:!=; 217, 218; 217, 223; 218, subscript; 218, 219; 218, 220; 219, identifier:newickTree; 220, subscript; 220, 221; 220, 222; 221, identifier:i; 222, integer:0; 223, string:')'; 224, block; 224, 225; 224, 240; 225, if_statement; 225, 226; 225, 233; 226, comparison_operator:==; 226, 227; 226, 232; 227, subscript; 227, 228; 227, 229; 228, identifier:newickTree; 229, subscript; 229, 230; 229, 231; 230, identifier:i; 231, integer:0; 232, string:','; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, augmented_assignment:+=; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:i; 238, integer:0; 239, integer:1; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:subTreeList; 244, identifier:append; 245, argument_list; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:fn3; 248, argument_list; 248, 249; 248, 250; 249, identifier:newickTree; 250, identifier:i; 251, expression_statement; 251, 252; 252, augmented_assignment:+=; 252, 253; 252, 256; 253, subscript; 253, 254; 253, 255; 254, identifier:i; 255, integer:0; 256, integer:1; 257, function_definition; 257, 258; 257, 259; 257, 262; 258, function_name:cmp; 259, parameters; 259, 260; 259, 261; 260, identifier:i; 261, identifier:j; 262, block; 262, 263; 262, 275; 262, 286; 263, if_statement; 263, 264; 263, 271; 264, comparison_operator:<; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:i; 267, identifier:distance; 268, attribute; 268, 269; 268, 270; 269, identifier:j; 270, identifier:distance; 271, block; 271, 272; 272, return_statement; 272, 273; 273, unary_operator:-; 273, 274; 274, integer:1; 275, if_statement; 275, 276; 275, 283; 276, comparison_operator:>; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:i; 279, identifier:distance; 280, attribute; 280, 281; 280, 282; 281, identifier:j; 282, identifier:distance; 283, block; 283, 284; 284, return_statement; 284, 285; 285, integer:1; 286, return_statement; 286, 287; 287, integer:0; 288, if_statement; 288, 289; 288, 290; 289, identifier:sortNonBinaryNodes; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:subTreeList; 295, identifier:sort; 296, argument_list; 296, 297; 297, identifier:cmp; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:subTree1; 301, subscript; 301, 302; 301, 303; 302, identifier:subTreeList; 303, integer:0; 304, if_statement; 304, 305; 304, 311; 304, 351; 304, 385; 305, comparison_operator:>; 305, 306; 305, 310; 306, call; 306, 307; 306, 308; 307, identifier:len; 308, argument_list; 308, 309; 309, identifier:subTreeList; 310, integer:1; 311, block; 311, 312; 311, 331; 311, 341; 312, for_statement; 312, 313; 312, 314; 312, 319; 313, identifier:subTree2; 314, subscript; 314, 315; 314, 316; 315, identifier:subTreeList; 316, slice; 316, 317; 316, 318; 317, integer:1; 318, colon; 319, block; 319, 320; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:subTree1; 323, call; 323, 324; 323, 325; 324, identifier:BinaryTree; 325, argument_list; 325, 326; 325, 327; 325, 328; 325, 329; 325, 330; 326, float:0.0; 327, True; 328, identifier:subTree1; 329, identifier:subTree2; 330, None; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:subTree1; 335, identifier:iD; 336, call; 336, 337; 336, 338; 337, identifier:fn2; 338, argument_list; 338, 339; 338, 340; 339, identifier:newickTree; 340, identifier:i; 341, expression_statement; 341, 342; 342, augmented_assignment:+=; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:subTree1; 345, identifier:distance; 346, call; 346, 347; 346, 348; 347, identifier:fn; 348, argument_list; 348, 349; 348, 350; 349, identifier:newickTree; 350, identifier:i; 351, elif_clause; 351, 352; 351, 353; 352, identifier:reportUnaryNodes; 353, block; 353, 354; 353, 365; 353, 375; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 357; 356, identifier:subTree1; 357, call; 357, 358; 357, 359; 358, identifier:BinaryTree; 359, argument_list; 359, 360; 359, 361; 359, 362; 359, 363; 359, 364; 360, float:0.0; 361, True; 362, identifier:subTree1; 363, None; 364, None; 365, expression_statement; 365, 366; 366, assignment; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:subTree1; 369, identifier:iD; 370, call; 370, 371; 370, 372; 371, identifier:fn2; 372, argument_list; 372, 373; 372, 374; 373, identifier:newickTree; 374, identifier:i; 375, expression_statement; 375, 376; 376, augmented_assignment:+=; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:subTree1; 379, identifier:distance; 380, call; 380, 381; 380, 382; 381, identifier:fn; 382, argument_list; 382, 383; 382, 384; 383, identifier:newickTree; 384, identifier:i; 385, else_clause; 385, 386; 386, block; 386, 387; 386, 393; 387, expression_statement; 387, 388; 388, call; 388, 389; 388, 390; 389, identifier:fn2; 390, argument_list; 390, 391; 390, 392; 391, identifier:newickTree; 392, identifier:i; 393, expression_statement; 393, 394; 394, augmented_assignment:+=; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:subTree1; 397, identifier:distance; 398, call; 398, 399; 398, 400; 399, identifier:fn; 400, argument_list; 400, 401; 400, 402; 401, identifier:newickTree; 402, identifier:i; 403, return_statement; 403, 404; 404, identifier:subTree1; 405, expression_statement; 405, 406; 406, assignment; 406, 407; 406, 408; 407, identifier:leafID; 408, call; 408, 409; 408, 410; 409, identifier:fn2; 410, argument_list; 410, 411; 410, 412; 411, identifier:newickTree; 412, identifier:i; 413, return_statement; 413, 414; 414, call; 414, 415; 414, 416; 415, identifier:BinaryTree; 416, argument_list; 416, 417; 416, 422; 416, 423; 416, 424; 416, 425; 417, call; 417, 418; 417, 419; 418, identifier:fn; 419, argument_list; 419, 420; 419, 421; 420, identifier:newickTree; 421, identifier:i; 422, False; 423, None; 424, None; 425, identifier:leafID; 426, return_statement; 426, 427; 427, call; 427, 428; 427, 429; 428, identifier:fn3; 429, argument_list; 429, 430; 429, 431; 430, identifier:newickTree; 431, list:[0]; 431, 432; 432, integer:0
def newickTreeParser(newickTree, defaultDistance=DEFAULT_DISTANCE, \ sortNonBinaryNodes=False, reportUnaryNodes=False): newickTree = newickTree.replace("(", " ( ") newickTree = newickTree.replace(")", " ) ") newickTree = newickTree.replace(":", " : ") newickTree = newickTree.replace(";", "") newickTree = newickTree.replace(",", " , ") newickTree = re.compile("[\s]*").split(newickTree) while "" in newickTree: newickTree.remove("") def fn(newickTree, i): if i[0] < len(newickTree): if newickTree[i[0]] == ':': d = float(newickTree[i[0]+1]) i[0] += 2 return d return defaultDistance def fn2(newickTree, i): if i[0] < len(newickTree): j = newickTree[i[0]] if j != ':' and j != ')' and j != ',': i[0] += 1 return j return None def fn3(newickTree, i): if newickTree[i[0]] == '(': subTreeList = [] i[0] += 1 k = [] while newickTree[i[0]] != ')': if newickTree[i[0]] == ',': i[0] += 1 subTreeList.append(fn3(newickTree, i)) i[0] += 1 def cmp(i, j): if i.distance < j.distance: return -1 if i.distance > j.distance: return 1 return 0 if sortNonBinaryNodes: subTreeList.sort(cmp) subTree1 = subTreeList[0] if len(subTreeList) > 1: for subTree2 in subTreeList[1:]: subTree1 = BinaryTree(0.0, True, subTree1, subTree2, None) subTree1.iD = fn2(newickTree, i) subTree1.distance += fn(newickTree, i) elif reportUnaryNodes: subTree1 = BinaryTree(0.0, True, subTree1, None, None) subTree1.iD = fn2(newickTree, i) subTree1.distance += fn(newickTree, i) else: fn2(newickTree, i) subTree1.distance += fn(newickTree, i) return subTree1 leafID = fn2(newickTree, i) return BinaryTree(fn(newickTree, i), False, None, None, leafID) return fn3(newickTree, [0])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_iptables_rule; 3, parameters; 3, 4; 4, identifier:line; 5, block; 5, 6; 5, 8; 5, 16; 5, 20; 5, 24; 5, 28; 5, 32; 5, 90; 5, 154; 5, 161; 5, 177; 6, expression_statement; 6, 7; 7, string:''' Parse one iptables rule. Returns a dict where each iptables code argument is mapped to a name using IPTABLES_ARGS. '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:bits; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:line; 14, identifier:split; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:definition; 19, dictionary; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:key; 23, None; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:args; 27, list:[]; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:not_arg; 31, False; 32, function_definition; 32, 33; 32, 34; 32, 35; 33, function_name:add_args; 34, parameters; 35, block; 35, 36; 35, 45; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:arg_string; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, string:' '; 42, identifier:join; 43, argument_list; 43, 44; 44, identifier:args; 45, if_statement; 45, 46; 45, 49; 45, 73; 46, comparison_operator:in; 46, 47; 46, 48; 47, identifier:key; 48, identifier:IPTABLES_ARGS; 49, block; 49, 50; 49, 67; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:definition_key; 53, parenthesized_expression; 53, 54; 54, conditional_expression:if; 54, 55; 54, 63; 54, 64; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, string:'not_{0}'; 58, identifier:format; 59, argument_list; 59, 60; 60, subscript; 60, 61; 60, 62; 61, identifier:IPTABLES_ARGS; 62, identifier:key; 63, identifier:not_arg; 64, subscript; 64, 65; 64, 66; 65, identifier:IPTABLES_ARGS; 66, identifier:key; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:definition; 71, identifier:definition_key; 72, identifier:arg_string; 73, else_clause; 73, 74; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 86; 77, attribute; 77, 78; 77, 85; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:definition; 81, identifier:setdefault; 82, argument_list; 82, 83; 82, 84; 83, string:'extras'; 84, list:[]; 85, identifier:extend; 86, argument_list; 86, 87; 87, tuple; 87, 88; 87, 89; 88, identifier:key; 89, identifier:arg_string; 90, for_statement; 90, 91; 90, 92; 90, 93; 91, identifier:bit; 92, identifier:bits; 93, block; 93, 94; 94, if_statement; 94, 95; 94, 98; 94, 118; 94, 145; 95, comparison_operator:==; 95, 96; 95, 97; 96, identifier:bit; 97, string:'!'; 98, block; 98, 99; 98, 114; 99, if_statement; 99, 100; 99, 101; 100, identifier:key; 101, block; 101, 102; 101, 106; 101, 110; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:add_args; 105, argument_list; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:args; 109, list:[]; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:key; 113, None; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:not_arg; 117, True; 118, elif_clause; 118, 119; 118, 125; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:bit; 122, identifier:startswith; 123, argument_list; 123, 124; 124, string:'-'; 125, block; 125, 126; 125, 141; 126, if_statement; 126, 127; 126, 128; 127, identifier:key; 128, block; 128, 129; 128, 133; 128, 137; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:add_args; 132, argument_list; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:args; 136, list:[]; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:not_arg; 140, False; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:key; 144, identifier:bit; 145, else_clause; 145, 146; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:args; 151, identifier:append; 152, argument_list; 152, 153; 153, identifier:bit; 154, if_statement; 154, 155; 154, 156; 155, identifier:key; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:add_args; 160, argument_list; 161, if_statement; 161, 162; 161, 165; 162, comparison_operator:in; 162, 163; 162, 164; 163, string:'extras'; 164, identifier:definition; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:definition; 170, string:'extras'; 171, call; 171, 172; 171, 173; 172, identifier:set; 173, argument_list; 173, 174; 174, subscript; 174, 175; 174, 176; 175, identifier:definition; 176, string:'extras'; 177, return_statement; 177, 178; 178, identifier:definition
def parse_iptables_rule(line): ''' Parse one iptables rule. Returns a dict where each iptables code argument is mapped to a name using IPTABLES_ARGS. ''' bits = line.split() definition = {} key = None args = [] not_arg = False def add_args(): arg_string = ' '.join(args) if key in IPTABLES_ARGS: definition_key = ( 'not_{0}'.format(IPTABLES_ARGS[key]) if not_arg else IPTABLES_ARGS[key] ) definition[definition_key] = arg_string else: definition.setdefault('extras', []).extend((key, arg_string)) for bit in bits: if bit == '!': if key: add_args() args = [] key = None not_arg = True elif bit.startswith('-'): if key: add_args() args = [] not_arg = False key = bit else: args.append(bit) if key: add_args() if 'extras' in definition: definition['extras'] = set(definition['extras']) return definition
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:make_command; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:command; 5, default_parameter; 5, 6; 5, 7; 6, identifier:env; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:su_user; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sudo; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sudo_user; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:preserve_sudo_env; 19, False; 20, block; 20, 21; 20, 23; 20, 27; 20, 54; 20, 88; 20, 127; 20, 134; 20, 158; 20, 204; 21, expression_statement; 21, 22; 22, string:''' Builds a shell command with various kwargs. '''; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:debug_meta; 26, dictionary; 27, for_statement; 27, 28; 27, 31; 27, 44; 28, pattern_list; 28, 29; 28, 30; 29, identifier:key; 30, identifier:value; 31, tuple; 31, 32; 31, 35; 31, 38; 31, 41; 32, tuple; 32, 33; 32, 34; 33, string:'sudo'; 34, identifier:sudo; 35, tuple; 35, 36; 35, 37; 36, string:'sudo_user'; 37, identifier:sudo_user; 38, tuple; 38, 39; 38, 40; 39, string:'su_user'; 40, identifier:su_user; 41, tuple; 41, 42; 41, 43; 42, string:'env'; 43, identifier:env; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 47; 46, identifier:value; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:debug_meta; 52, identifier:key; 53, identifier:value; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:logger; 58, identifier:debug; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, string:'Building command ({0}): {1}'; 63, identifier:format; 64, argument_list; 64, 65; 64, 87; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, string:' '; 68, identifier:join; 69, generator_expression; 69, 70; 69, 77; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:'{0}: {1}'; 73, identifier:format; 74, argument_list; 74, 75; 74, 76; 75, identifier:key; 76, identifier:value; 77, for_in_clause; 77, 78; 77, 81; 78, pattern_list; 78, 79; 78, 80; 79, identifier:key; 80, identifier:value; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:six; 84, identifier:iteritems; 85, argument_list; 85, 86; 86, identifier:debug_meta; 87, identifier:command; 88, if_statement; 88, 89; 88, 90; 89, identifier:env; 90, block; 90, 91; 90, 117; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:env_string; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, string:' '; 97, identifier:join; 98, argument_list; 98, 99; 99, list_comprehension; 99, 100; 99, 107; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, string:'{0}={1}'; 103, identifier:format; 104, argument_list; 104, 105; 104, 106; 105, identifier:key; 106, identifier:value; 107, for_in_clause; 107, 108; 107, 111; 108, pattern_list; 108, 109; 108, 110; 109, identifier:key; 110, identifier:value; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:six; 114, identifier:iteritems; 115, argument_list; 115, 116; 116, identifier:env; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:command; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, string:'export {0}; {1}'; 123, identifier:format; 124, argument_list; 124, 125; 124, 126; 125, identifier:env_string; 126, identifier:command; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:command; 130, call; 130, 131; 130, 132; 131, identifier:shlex_quote; 132, argument_list; 132, 133; 133, identifier:command; 134, if_statement; 134, 135; 134, 136; 134, 147; 135, identifier:su_user; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:command; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, string:'su {0} -c {1}'; 143, identifier:format; 144, argument_list; 144, 145; 144, 146; 145, identifier:su_user; 146, identifier:command; 147, else_clause; 147, 148; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:command; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, string:'sh -c {0}'; 155, identifier:format; 156, argument_list; 156, 157; 157, identifier:command; 158, if_statement; 158, 159; 158, 160; 159, identifier:sudo; 160, block; 160, 161; 160, 167; 160, 177; 160, 189; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:sudo_bits; 164, list:['sudo', '-H']; 164, 165; 164, 166; 165, string:'sudo'; 166, string:'-H'; 167, if_statement; 167, 168; 167, 169; 168, identifier:preserve_sudo_env; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:sudo_bits; 174, identifier:append; 175, argument_list; 175, 176; 176, string:'-E'; 177, if_statement; 177, 178; 177, 179; 178, identifier:sudo_user; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:sudo_bits; 184, identifier:extend; 185, argument_list; 185, 186; 186, tuple; 186, 187; 186, 188; 187, string:'-u'; 188, identifier:sudo_user; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:command; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, string:'{0} {1}'; 195, identifier:format; 196, argument_list; 196, 197; 196, 203; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, string:' '; 200, identifier:join; 201, argument_list; 201, 202; 202, identifier:sudo_bits; 203, identifier:command; 204, return_statement; 204, 205; 205, identifier:command
def make_command( command, env=None, su_user=None, sudo=False, sudo_user=None, preserve_sudo_env=False, ): ''' Builds a shell command with various kwargs. ''' debug_meta = {} for key, value in ( ('sudo', sudo), ('sudo_user', sudo_user), ('su_user', su_user), ('env', env), ): if value: debug_meta[key] = value logger.debug('Building command ({0}): {1}'.format(' '.join( '{0}: {1}'.format(key, value) for key, value in six.iteritems(debug_meta) ), command)) if env: env_string = ' '.join([ '{0}={1}'.format(key, value) for key, value in six.iteritems(env) ]) command = 'export {0}; {1}'.format(env_string, command) command = shlex_quote(command) if su_user: command = 'su {0} -c {1}'.format(su_user, command) else: command = 'sh -c {0}'.format(command) if sudo: sudo_bits = ['sudo', '-H'] if preserve_sudo_env: sudo_bits.append('-E') if sudo_user: sudo_bits.extend(('-u', sudo_user)) command = '{0} {1}'.format(' '.join(sudo_bits), command) return command
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:read_buffer; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:io; 5, default_parameter; 5, 6; 5, 7; 6, identifier:print_output; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:print_func; 10, None; 11, block; 11, 12; 11, 14; 11, 55; 11, 59; 11, 102; 12, expression_statement; 12, 13; 13, string:''' Reads a file-like buffer object into lines and optionally prints the output. '''; 14, function_definition; 14, 15; 14, 16; 14, 18; 15, function_name:_print; 16, parameters; 16, 17; 17, identifier:line; 18, block; 18, 19; 19, if_statement; 19, 20; 19, 21; 20, identifier:print_output; 21, block; 21, 22; 21, 38; 21, 50; 22, if_statement; 22, 23; 22, 24; 22, 32; 23, identifier:print_func; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:formatted_line; 28, call; 28, 29; 28, 30; 29, identifier:print_func; 30, argument_list; 30, 31; 31, identifier:line; 32, else_clause; 32, 33; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:formatted_line; 37, identifier:line; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:encoded_line; 41, call; 41, 42; 41, 48; 42, attribute; 42, 43; 42, 47; 43, call; 43, 44; 43, 45; 44, identifier:unicode; 45, argument_list; 45, 46; 46, identifier:formatted_line; 47, identifier:encode; 48, argument_list; 48, 49; 49, string:'utf-8'; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:print; 53, argument_list; 53, 54; 54, identifier:encoded_line; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:out; 58, list:[]; 59, for_statement; 59, 60; 59, 61; 59, 62; 60, identifier:line; 61, identifier:io; 62, block; 62, 63; 62, 82; 62, 90; 62, 97; 63, if_statement; 63, 64; 63, 72; 64, not_operator; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:isinstance; 67, argument_list; 67, 68; 67, 69; 68, identifier:line; 69, attribute; 69, 70; 69, 71; 70, identifier:six; 71, identifier:text_type; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:line; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:line; 79, identifier:decode; 80, argument_list; 80, 81; 81, string:'utf-8'; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:line; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:line; 88, identifier:strip; 89, argument_list; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:out; 94, identifier:append; 95, argument_list; 95, 96; 96, identifier:line; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:_print; 100, argument_list; 100, 101; 101, identifier:line; 102, return_statement; 102, 103; 103, identifier:out
def read_buffer(io, print_output=False, print_func=None): ''' Reads a file-like buffer object into lines and optionally prints the output. ''' def _print(line): if print_output: if print_func: formatted_line = print_func(line) else: formatted_line = line encoded_line = unicode(formatted_line).encode('utf-8') print(encoded_line) out = [] for line in io: if not isinstance(line, six.text_type): line = line.decode('utf-8') line = line.strip() out.append(line) _print(line) return out
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:download; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:state; 5, identifier:host; 6, identifier:source_url; 7, identifier:destination; 8, default_parameter; 8, 9; 8, 10; 9, identifier:user; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:group; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:mode; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:cache_time; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:force; 22, False; 23, block; 23, 24; 23, 26; 23, 37; 23, 52; 23, 56; 23, 105; 24, expression_statement; 24, 25; 25, string:''' Download files from remote locations. + source_url: source URl of the file + destination: where to save the file + user: user to own the files + group: group to own the files + mode: permissions of the files + cache_time: if the file exists already, re-download after this time (in s) + force: always download the file, even if it already exists '''; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:info; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:host; 33, identifier:fact; 34, identifier:file; 35, argument_list; 35, 36; 36, identifier:destination; 37, if_statement; 37, 38; 37, 41; 38, comparison_operator:is; 38, 39; 38, 40; 39, identifier:info; 40, False; 41, block; 41, 42; 42, raise_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:OperationError; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, string:'Destination {0} already exists and is not a file'; 49, identifier:format; 50, argument_list; 50, 51; 51, identifier:destination; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:download; 55, identifier:force; 56, if_statement; 56, 57; 56, 60; 56, 65; 57, comparison_operator:is; 57, 58; 57, 59; 58, identifier:info; 59, None; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:download; 64, True; 65, elif_clause; 65, 66; 65, 67; 66, identifier:cache_time; 67, block; 67, 68; 67, 90; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:cache_time; 71, binary_operator:-; 71, 72; 71, 84; 72, call; 72, 73; 72, 80; 73, attribute; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:host; 77, identifier:fact; 78, identifier:date; 79, identifier:replace; 80, argument_list; 80, 81; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:tzinfo; 83, None; 84, call; 84, 85; 84, 86; 85, identifier:timedelta; 86, argument_list; 86, 87; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:seconds; 89, identifier:cache_time; 90, if_statement; 90, 91; 90, 100; 91, boolean_operator:and; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:info; 94, string:'mtime'; 95, comparison_operator:>; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:info; 98, string:'mtime'; 99, identifier:cache_time; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:download; 104, True; 105, if_statement; 105, 106; 105, 107; 106, identifier:download; 107, block; 107, 108; 107, 117; 107, 130; 108, expression_statement; 108, 109; 109, yield; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, string:'wget -q {0} -O {1}'; 113, identifier:format; 114, argument_list; 114, 115; 114, 116; 115, identifier:source_url; 116, identifier:destination; 117, if_statement; 117, 118; 117, 121; 118, boolean_operator:or; 118, 119; 118, 120; 119, identifier:user; 120, identifier:group; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, yield; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:chown; 126, argument_list; 126, 127; 126, 128; 126, 129; 127, identifier:destination; 128, identifier:user; 129, identifier:group; 130, if_statement; 130, 131; 130, 132; 131, identifier:mode; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, yield; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:chmod; 137, argument_list; 137, 138; 137, 139; 138, identifier:destination; 139, identifier:mode
def download( state, host, source_url, destination, user=None, group=None, mode=None, cache_time=None, force=False, ): ''' Download files from remote locations. + source_url: source URl of the file + destination: where to save the file + user: user to own the files + group: group to own the files + mode: permissions of the files + cache_time: if the file exists already, re-download after this time (in s) + force: always download the file, even if it already exists ''' info = host.fact.file(destination) if info is False: raise OperationError( 'Destination {0} already exists and is not a file'.format(destination), ) download = force if info is None: download = True elif cache_time: cache_time = host.fact.date.replace(tzinfo=None) - timedelta(seconds=cache_time) if info['mtime'] and info['mtime'] > cache_time: download = True if download: yield 'wget -q {0} -O {1}'.format(source_url, destination) if user or group: yield chown(destination, user, group) if mode: yield chmod(destination, mode)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:sync; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:state; 5, identifier:host; 6, identifier:source; 7, identifier:destination; 8, default_parameter; 8, 9; 8, 10; 9, identifier:user; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:group; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:mode; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:delete; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:exclude; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:exclude_dir; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:add_deploy_dir; 28, True; 29, block; 29, 30; 29, 32; 29, 55; 29, 74; 29, 93; 29, 113; 29, 133; 29, 137; 29, 141; 29, 239; 29, 253; 29, 278; 29, 305; 30, expression_statement; 30, 31; 31, string:''' Syncs a local directory with a remote one, with delete support. Note that delete will remove extra files on the remote side, but not extra directories. + source: local directory to sync + destination: remote directory to sync to + user: user to own the files and directories + group: group to own the files and directories + mode: permissions of the files + delete: delete remote files not present locally + exclude: string or list/tuple of strings to match & exclude files (eg *.pyc) + exclude_dir: string or list/tuple of strings to match & exclude directories (eg node_modules) '''; 32, if_statement; 32, 33; 32, 42; 33, not_operator; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:source; 37, identifier:endswith; 38, argument_list; 38, 39; 39, attribute; 39, 40; 39, 41; 40, identifier:path; 41, identifier:sep; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:source; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, string:'{0}{1}'; 49, identifier:format; 50, argument_list; 50, 51; 50, 52; 51, identifier:source; 52, attribute; 52, 53; 52, 54; 53, identifier:path; 54, identifier:sep; 55, if_statement; 55, 56; 55, 61; 56, boolean_operator:and; 56, 57; 56, 58; 57, identifier:add_deploy_dir; 58, attribute; 58, 59; 58, 60; 59, identifier:state; 60, identifier:deploy_dir; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:source; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:path; 68, identifier:join; 69, argument_list; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:state; 72, identifier:deploy_dir; 73, identifier:source; 74, if_statement; 74, 75; 74, 82; 75, not_operator; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:path; 79, identifier:isdir; 80, argument_list; 80, 81; 81, identifier:source; 82, block; 82, 83; 83, raise_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:IOError; 86, argument_list; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, string:'No such directory: {0}'; 90, identifier:format; 91, argument_list; 91, 92; 92, identifier:source; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:exclude; 96, None; 97, block; 97, 98; 98, if_statement; 98, 99; 98, 107; 99, not_operator; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:isinstance; 102, argument_list; 102, 103; 102, 104; 103, identifier:exclude; 104, tuple; 104, 105; 104, 106; 105, identifier:list; 106, identifier:tuple; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:exclude; 111, list:[exclude]; 111, 112; 112, identifier:exclude; 113, if_statement; 113, 114; 113, 117; 114, comparison_operator:is; 114, 115; 114, 116; 115, identifier:exclude_dir; 116, None; 117, block; 117, 118; 118, if_statement; 118, 119; 118, 127; 119, not_operator; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:isinstance; 122, argument_list; 122, 123; 122, 124; 123, identifier:exclude_dir; 124, tuple; 124, 125; 124, 126; 125, identifier:list; 126, identifier:tuple; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:exclude_dir; 131, list:[exclude_dir]; 131, 132; 132, identifier:exclude_dir; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:put_files; 136, list:[]; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:ensure_dirnames; 140, list:[]; 141, for_statement; 141, 142; 141, 146; 141, 150; 142, pattern_list; 142, 143; 142, 144; 142, 145; 143, identifier:dirname; 144, identifier:_; 145, identifier:filenames; 146, call; 146, 147; 146, 148; 147, identifier:walk; 148, argument_list; 148, 149; 149, identifier:source; 150, block; 150, 151; 150, 161; 150, 177; 150, 187; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:remote_dirname; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:dirname; 157, identifier:replace; 158, argument_list; 158, 159; 158, 160; 159, identifier:source; 160, string:''; 161, if_statement; 161, 162; 161, 175; 162, boolean_operator:and; 162, 163; 162, 164; 163, identifier:exclude_dir; 164, call; 164, 165; 164, 166; 165, identifier:any; 166, generator_expression; 166, 167; 166, 172; 167, call; 167, 168; 167, 169; 168, identifier:fnmatch; 169, argument_list; 169, 170; 169, 171; 170, identifier:remote_dirname; 171, identifier:match; 172, for_in_clause; 172, 173; 172, 174; 173, identifier:match; 174, identifier:exclude_dir; 175, block; 175, 176; 176, continue_statement; 177, if_statement; 177, 178; 177, 179; 178, identifier:remote_dirname; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:ensure_dirnames; 184, identifier:append; 185, argument_list; 185, 186; 186, identifier:remote_dirname; 187, for_statement; 187, 188; 187, 189; 187, 190; 188, identifier:filename; 189, identifier:filenames; 190, block; 190, 191; 190, 201; 190, 217; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:full_filename; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:path; 197, identifier:join; 198, argument_list; 198, 199; 198, 200; 199, identifier:dirname; 200, identifier:filename; 201, if_statement; 201, 202; 201, 215; 202, boolean_operator:and; 202, 203; 202, 204; 203, identifier:exclude; 204, call; 204, 205; 204, 206; 205, identifier:any; 206, generator_expression; 206, 207; 206, 212; 207, call; 207, 208; 207, 209; 208, identifier:fnmatch; 209, argument_list; 209, 210; 209, 211; 210, identifier:full_filename; 211, identifier:match; 212, for_in_clause; 212, 213; 212, 214; 213, identifier:match; 214, identifier:exclude; 215, block; 215, 216; 216, continue_statement; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:put_files; 221, identifier:append; 222, argument_list; 222, 223; 223, tuple; 223, 224; 223, 225; 224, identifier:full_filename; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, string:'/'; 228, identifier:join; 229, generator_expression; 229, 230; 229, 231; 229, 237; 230, identifier:item; 231, for_in_clause; 231, 232; 231, 233; 232, identifier:item; 233, tuple; 233, 234; 233, 235; 233, 236; 234, identifier:destination; 235, identifier:remote_dirname; 236, identifier:filename; 237, if_clause; 237, 238; 238, identifier:item; 239, expression_statement; 239, 240; 240, yield; 240, 241; 241, call; 241, 242; 241, 243; 242, identifier:directory; 243, argument_list; 243, 244; 243, 245; 243, 246; 243, 247; 243, 250; 244, identifier:state; 245, identifier:host; 246, identifier:destination; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:user; 249, identifier:user; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:group; 252, identifier:group; 253, for_statement; 253, 254; 253, 255; 253, 256; 254, identifier:dirname; 255, identifier:ensure_dirnames; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, yield; 258, 259; 259, call; 259, 260; 259, 261; 260, identifier:directory; 261, argument_list; 261, 262; 261, 263; 261, 264; 261, 272; 261, 275; 262, identifier:state; 263, identifier:host; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, string:'/'; 267, identifier:join; 268, argument_list; 268, 269; 269, tuple; 269, 270; 269, 271; 270, identifier:destination; 271, identifier:dirname; 272, keyword_argument; 272, 273; 272, 274; 273, identifier:user; 274, identifier:user; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:group; 277, identifier:group; 278, for_statement; 278, 279; 278, 282; 278, 283; 279, pattern_list; 279, 280; 279, 281; 280, identifier:local_filename; 281, identifier:remote_filename; 282, identifier:put_files; 283, block; 283, 284; 284, expression_statement; 284, 285; 285, yield; 285, 286; 286, call; 286, 287; 286, 288; 287, identifier:put; 288, argument_list; 288, 289; 288, 290; 288, 291; 288, 292; 288, 293; 288, 296; 288, 299; 288, 302; 289, identifier:state; 290, identifier:host; 291, identifier:local_filename; 292, identifier:remote_filename; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:user; 295, identifier:user; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:group; 298, identifier:group; 299, keyword_argument; 299, 300; 299, 301; 300, identifier:mode; 301, identifier:mode; 302, keyword_argument; 302, 303; 302, 304; 303, identifier:add_deploy_dir; 304, False; 305, if_statement; 305, 306; 305, 307; 306, identifier:delete; 307, block; 307, 308; 307, 324; 307, 337; 307, 343; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:remote_filenames; 311, call; 311, 312; 311, 313; 312, identifier:set; 313, argument_list; 313, 314; 314, boolean_operator:or; 314, 315; 314, 323; 315, call; 315, 316; 315, 321; 316, attribute; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:host; 319, identifier:fact; 320, identifier:find_files; 321, argument_list; 321, 322; 322, identifier:destination; 323, list:[]; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:wanted_filenames; 327, call; 327, 328; 327, 329; 328, identifier:set; 329, argument_list; 329, 330; 330, list_comprehension; 330, 331; 330, 332; 331, identifier:remote_filename; 332, for_in_clause; 332, 333; 332, 336; 333, pattern_list; 333, 334; 333, 335; 334, identifier:_; 335, identifier:remote_filename; 336, identifier:put_files; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 340; 339, identifier:files_to_delete; 340, binary_operator:-; 340, 341; 340, 342; 341, identifier:remote_filenames; 342, identifier:wanted_filenames; 343, for_statement; 343, 344; 343, 345; 343, 346; 344, identifier:filename; 345, identifier:files_to_delete; 346, block; 346, 347; 346, 363; 347, if_statement; 347, 348; 347, 361; 348, boolean_operator:and; 348, 349; 348, 350; 349, identifier:exclude; 350, call; 350, 351; 350, 352; 351, identifier:any; 352, generator_expression; 352, 353; 352, 358; 353, call; 353, 354; 353, 355; 354, identifier:fnmatch; 355, argument_list; 355, 356; 355, 357; 356, identifier:filename; 357, identifier:match; 358, for_in_clause; 358, 359; 358, 360; 359, identifier:match; 360, identifier:exclude; 361, block; 361, 362; 362, continue_statement; 363, expression_statement; 363, 364; 364, yield; 364, 365; 365, call; 365, 366; 365, 367; 366, identifier:file; 367, argument_list; 367, 368; 367, 369; 367, 370; 367, 371; 368, identifier:state; 369, identifier:host; 370, identifier:filename; 371, keyword_argument; 371, 372; 371, 373; 372, identifier:present; 373, False
def sync( state, host, source, destination, user=None, group=None, mode=None, delete=False, exclude=None, exclude_dir=None, add_deploy_dir=True, ): ''' Syncs a local directory with a remote one, with delete support. Note that delete will remove extra files on the remote side, but not extra directories. + source: local directory to sync + destination: remote directory to sync to + user: user to own the files and directories + group: group to own the files and directories + mode: permissions of the files + delete: delete remote files not present locally + exclude: string or list/tuple of strings to match & exclude files (eg *.pyc) + exclude_dir: string or list/tuple of strings to match & exclude directories (eg node_modules) ''' if not source.endswith(path.sep): source = '{0}{1}'.format(source, path.sep) if add_deploy_dir and state.deploy_dir: source = path.join(state.deploy_dir, source) if not path.isdir(source): raise IOError('No such directory: {0}'.format(source)) if exclude is not None: if not isinstance(exclude, (list, tuple)): exclude = [exclude] if exclude_dir is not None: if not isinstance(exclude_dir, (list, tuple)): exclude_dir = [exclude_dir] put_files = [] ensure_dirnames = [] for dirname, _, filenames in walk(source): remote_dirname = dirname.replace(source, '') if exclude_dir and any(fnmatch(remote_dirname, match) for match in exclude_dir): continue if remote_dirname: ensure_dirnames.append(remote_dirname) for filename in filenames: full_filename = path.join(dirname, filename) if exclude and any(fnmatch(full_filename, match) for match in exclude): continue put_files.append(( full_filename, '/'.join( item for item in (destination, remote_dirname, filename) if item ), )) yield directory( state, host, destination, user=user, group=group, ) for dirname in ensure_dirnames: yield directory( state, host, '/'.join((destination, dirname)), user=user, group=group, ) for local_filename, remote_filename in put_files: yield put( state, host, local_filename, remote_filename, user=user, group=group, mode=mode, add_deploy_dir=False, ) if delete: remote_filenames = set(host.fact.find_files(destination) or []) wanted_filenames = set([remote_filename for _, remote_filename in put_files]) files_to_delete = remote_filenames - wanted_filenames for filename in files_to_delete: if exclude and any(fnmatch(filename, match) for match in exclude): continue yield file(state, host, filename, present=False)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:put; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:state; 5, identifier:host; 6, identifier:local_filename; 7, identifier:remote_filename; 8, default_parameter; 8, 9; 8, 10; 9, identifier:user; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:group; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:mode; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:add_deploy_dir; 19, True; 20, block; 20, 21; 20, 23; 20, 78; 20, 85; 20, 96; 21, expression_statement; 21, 22; 22, string:''' Copy a local file to the remote system. + local_filename: local filename + remote_filename: remote filename + user: user to own the files + group: group to own the files + mode: permissions of the files '''; 23, if_statement; 23, 24; 23, 29; 23, 34; 24, call; 24, 25; 24, 26; 25, identifier:hasattr; 26, argument_list; 26, 27; 26, 28; 27, identifier:local_filename; 28, string:'read'; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:local_file; 33, identifier:local_filename; 34, else_clause; 34, 35; 35, block; 35, 36; 35, 55; 35, 59; 36, if_statement; 36, 37; 36, 42; 37, boolean_operator:and; 37, 38; 37, 39; 38, identifier:add_deploy_dir; 39, attribute; 39, 40; 39, 41; 40, identifier:state; 41, identifier:deploy_dir; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:local_filename; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:path; 49, identifier:join; 50, argument_list; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:state; 53, identifier:deploy_dir; 54, identifier:local_filename; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:local_file; 58, identifier:local_filename; 59, if_statement; 59, 60; 59, 67; 60, not_operator; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:path; 64, identifier:isfile; 65, argument_list; 65, 66; 66, identifier:local_file; 67, block; 67, 68; 68, raise_statement; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:IOError; 71, argument_list; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, string:'No such file: {0}'; 75, identifier:format; 76, argument_list; 76, 77; 77, identifier:local_file; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:mode; 81, call; 81, 82; 81, 83; 82, identifier:ensure_mode_int; 83, argument_list; 83, 84; 84, identifier:mode; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:remote_file; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:host; 92, identifier:fact; 93, identifier:file; 94, argument_list; 94, 95; 95, identifier:remote_filename; 96, if_statement; 96, 97; 96, 99; 96, 128; 97, not_operator; 97, 98; 98, identifier:remote_file; 99, block; 99, 100; 99, 105; 99, 118; 100, expression_statement; 100, 101; 101, yield; 101, 102; 102, tuple; 102, 103; 102, 104; 103, identifier:local_file; 104, identifier:remote_filename; 105, if_statement; 105, 106; 105, 109; 106, boolean_operator:or; 106, 107; 106, 108; 107, identifier:user; 108, identifier:group; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, yield; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:chown; 114, argument_list; 114, 115; 114, 116; 114, 117; 115, identifier:remote_filename; 116, identifier:user; 117, identifier:group; 118, if_statement; 118, 119; 118, 120; 119, identifier:mode; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, yield; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:chmod; 125, argument_list; 125, 126; 125, 127; 126, identifier:remote_filename; 127, identifier:mode; 128, else_clause; 128, 129; 129, block; 129, 130; 129, 137; 129, 148; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:local_sum; 133, call; 133, 134; 133, 135; 134, identifier:get_file_sha1; 135, argument_list; 135, 136; 136, identifier:local_filename; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:remote_sum; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:host; 144, identifier:fact; 145, identifier:sha1_file; 146, argument_list; 146, 147; 147, identifier:remote_filename; 148, if_statement; 148, 149; 148, 152; 148, 181; 149, comparison_operator:!=; 149, 150; 149, 151; 150, identifier:local_sum; 151, identifier:remote_sum; 152, block; 152, 153; 152, 158; 152, 171; 153, expression_statement; 153, 154; 154, yield; 154, 155; 155, tuple; 155, 156; 155, 157; 156, identifier:local_file; 157, identifier:remote_filename; 158, if_statement; 158, 159; 158, 162; 159, boolean_operator:or; 159, 160; 159, 161; 160, identifier:user; 161, identifier:group; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, yield; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:chown; 167, argument_list; 167, 168; 167, 169; 167, 170; 168, identifier:remote_filename; 169, identifier:user; 170, identifier:group; 171, if_statement; 171, 172; 171, 173; 172, identifier:mode; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, yield; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:chmod; 178, argument_list; 178, 179; 178, 180; 179, identifier:remote_filename; 180, identifier:mode; 181, else_clause; 181, 182; 182, block; 182, 183; 182, 199; 183, if_statement; 183, 184; 183, 191; 184, boolean_operator:and; 184, 185; 184, 186; 185, identifier:mode; 186, comparison_operator:!=; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:remote_file; 189, string:'mode'; 190, identifier:mode; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, yield; 193, 194; 194, call; 194, 195; 194, 196; 195, identifier:chmod; 196, argument_list; 196, 197; 196, 198; 197, identifier:remote_filename; 198, identifier:mode; 199, if_statement; 199, 200; 199, 218; 200, parenthesized_expression; 200, 201; 201, boolean_operator:or; 201, 202; 201, 210; 202, parenthesized_expression; 202, 203; 203, boolean_operator:and; 203, 204; 203, 205; 204, identifier:user; 205, comparison_operator:!=; 205, 206; 205, 209; 206, subscript; 206, 207; 206, 208; 207, identifier:remote_file; 208, string:'user'; 209, identifier:user; 210, parenthesized_expression; 210, 211; 211, boolean_operator:and; 211, 212; 211, 213; 212, identifier:group; 213, comparison_operator:!=; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:remote_file; 216, string:'group'; 217, identifier:group; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, yield; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:chown; 223, argument_list; 223, 224; 223, 225; 223, 226; 224, identifier:remote_filename; 225, identifier:user; 226, identifier:group
def put( state, host, local_filename, remote_filename, user=None, group=None, mode=None, add_deploy_dir=True, ): ''' Copy a local file to the remote system. + local_filename: local filename + remote_filename: remote filename + user: user to own the files + group: group to own the files + mode: permissions of the files ''' if hasattr(local_filename, 'read'): local_file = local_filename else: if add_deploy_dir and state.deploy_dir: local_filename = path.join(state.deploy_dir, local_filename) local_file = local_filename if not path.isfile(local_file): raise IOError('No such file: {0}'.format(local_file)) mode = ensure_mode_int(mode) remote_file = host.fact.file(remote_filename) if not remote_file: yield (local_file, remote_filename) if user or group: yield chown(remote_filename, user, group) if mode: yield chmod(remote_filename, mode) else: local_sum = get_file_sha1(local_filename) remote_sum = host.fact.sha1_file(remote_filename) if local_sum != remote_sum: yield (local_file, remote_filename) if user or group: yield chown(remote_filename, user, group) if mode: yield chmod(remote_filename, mode) else: if mode and remote_file['mode'] != mode: yield chmod(remote_filename, mode) if ( (user and remote_file['user'] != user) or (group and remote_file['group'] != group) ): yield chown(remote_filename, user, group)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_run_single_op; 3, parameters; 3, 4; 3, 5; 4, identifier:state; 5, identifier:op_hash; 6, block; 6, 7; 6, 9; 6, 17; 6, 21; 6, 33; 6, 45; 6, 108; 6, 114; 6, 300; 6, 313; 7, expression_statement; 7, 8; 8, string:''' Run a single operation for all servers. Can be configured to run in serial. '''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:op_meta; 12, subscript; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:state; 15, identifier:op_meta; 16, identifier:op_hash; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:op_types; 20, list:[]; 21, if_statement; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:op_meta; 24, string:'serial'; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:op_types; 30, identifier:append; 31, argument_list; 31, 32; 32, string:'serial'; 33, if_statement; 33, 34; 33, 37; 34, subscript; 34, 35; 34, 36; 35, identifier:op_meta; 36, string:'run_once'; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:op_types; 42, identifier:append; 43, argument_list; 43, 44; 44, string:'run once'; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:logger; 49, identifier:info; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, string:'{0} {1} {2}'; 54, identifier:format; 55, argument_list; 55, 56; 55, 81; 55, 97; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:click; 59, identifier:style; 60, argument_list; 60, 61; 60, 80; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, string:'--> Starting{0}operation:'; 64, identifier:format; 65, argument_list; 65, 66; 66, conditional_expression:if; 66, 67; 66, 78; 66, 79; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, string:' {0} '; 70, identifier:format; 71, argument_list; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, string:', '; 75, identifier:join; 76, argument_list; 76, 77; 77, identifier:op_types; 78, identifier:op_types; 79, string:' '; 80, string:'blue'; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:click; 84, identifier:style; 85, argument_list; 85, 86; 85, 94; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, string:', '; 89, identifier:join; 90, argument_list; 90, 91; 91, subscript; 91, 92; 91, 93; 92, identifier:op_meta; 93, string:'names'; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:bold; 96, True; 97, conditional_expression:if; 97, 98; 97, 104; 97, 107; 98, call; 98, 99; 98, 100; 99, identifier:tuple; 100, argument_list; 100, 101; 101, subscript; 101, 102; 101, 103; 102, identifier:op_meta; 103, string:'args'; 104, subscript; 104, 105; 104, 106; 105, identifier:op_meta; 106, string:'args'; 107, string:''; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:failed_hosts; 111, call; 111, 112; 111, 113; 112, identifier:set; 113, argument_list; 114, if_statement; 114, 115; 114, 118; 114, 163; 115, subscript; 115, 116; 115, 117; 116, identifier:op_meta; 117, string:'serial'; 118, block; 118, 119; 119, with_statement; 119, 120; 119, 131; 120, with_clause; 120, 121; 121, with_item; 121, 122; 122, as_pattern; 122, 123; 122, 129; 123, call; 123, 124; 123, 125; 124, identifier:progress_spinner; 125, argument_list; 125, 126; 126, attribute; 126, 127; 126, 128; 127, identifier:state; 128, identifier:inventory; 129, as_pattern_target; 129, 130; 130, identifier:progress; 131, block; 131, 132; 132, for_statement; 132, 133; 132, 134; 132, 137; 133, identifier:host; 134, attribute; 134, 135; 134, 136; 135, identifier:state; 136, identifier:inventory; 137, block; 137, 138; 137, 147; 137, 152; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:result; 141, call; 141, 142; 141, 143; 142, identifier:_run_server_op; 143, argument_list; 143, 144; 143, 145; 143, 146; 144, identifier:state; 145, identifier:host; 146, identifier:op_hash; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 150; 149, identifier:progress; 150, argument_list; 150, 151; 151, identifier:host; 152, if_statement; 152, 153; 152, 155; 153, not_operator; 153, 154; 154, identifier:result; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:failed_hosts; 160, identifier:add; 161, argument_list; 161, 162; 162, identifier:host; 163, else_clause; 163, 164; 164, block; 164, 165; 164, 172; 164, 215; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:batches; 168, list:[state.inventory]; 168, 169; 169, attribute; 169, 170; 169, 171; 170, identifier:state; 171, identifier:inventory; 172, if_statement; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:op_meta; 175, string:'parallel'; 176, block; 176, 177; 176, 183; 176, 192; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:parallel; 180, subscript; 180, 181; 180, 182; 181, identifier:op_meta; 182, string:'parallel'; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:hosts; 186, call; 186, 187; 186, 188; 187, identifier:list; 188, argument_list; 188, 189; 189, attribute; 189, 190; 189, 191; 190, identifier:state; 191, identifier:inventory; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:batches; 195, list_comprehension; 195, 196; 195, 204; 196, subscript; 196, 197; 196, 198; 197, identifier:hosts; 198, slice; 198, 199; 198, 200; 198, 201; 199, identifier:i; 200, colon; 201, binary_operator:+; 201, 202; 201, 203; 202, identifier:i; 203, identifier:parallel; 204, for_in_clause; 204, 205; 204, 206; 205, identifier:i; 206, call; 206, 207; 206, 208; 207, identifier:range; 208, argument_list; 208, 209; 208, 210; 208, 214; 209, integer:0; 210, call; 210, 211; 210, 212; 211, identifier:len; 212, argument_list; 212, 213; 213, identifier:hosts; 214, identifier:parallel; 215, for_statement; 215, 216; 215, 217; 215, 218; 216, identifier:batch; 217, identifier:batches; 218, block; 218, 219; 219, with_statement; 219, 220; 219, 229; 220, with_clause; 220, 221; 221, with_item; 221, 222; 222, as_pattern; 222, 223; 222, 227; 223, call; 223, 224; 223, 225; 224, identifier:progress_spinner; 225, argument_list; 225, 226; 226, identifier:batch; 227, as_pattern_target; 227, 228; 228, identifier:progress; 229, block; 229, 230; 229, 250; 229, 274; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:greenlet_to_host; 233, dictionary_comprehension; 233, 234; 233, 247; 234, pair; 234, 235; 234, 246; 235, call; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:state; 239, identifier:pool; 240, identifier:spawn; 241, argument_list; 241, 242; 241, 243; 241, 244; 241, 245; 242, identifier:_run_server_op; 243, identifier:state; 244, identifier:host; 245, identifier:op_hash; 246, identifier:host; 247, for_in_clause; 247, 248; 247, 249; 248, identifier:host; 249, identifier:batch; 250, for_statement; 250, 251; 250, 252; 250, 262; 251, identifier:greenlet; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:gevent; 255, identifier:iwait; 256, argument_list; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:greenlet_to_host; 260, identifier:keys; 261, argument_list; 262, block; 262, 263; 262, 269; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:host; 266, subscript; 266, 267; 266, 268; 267, identifier:greenlet_to_host; 268, identifier:greenlet; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 272; 271, identifier:progress; 272, argument_list; 272, 273; 273, identifier:host; 274, for_statement; 274, 275; 274, 278; 274, 284; 275, pattern_list; 275, 276; 275, 277; 276, identifier:greenlet; 277, identifier:host; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:six; 281, identifier:iteritems; 282, argument_list; 282, 283; 283, identifier:greenlet_to_host; 284, block; 284, 285; 285, if_statement; 285, 286; 285, 292; 286, not_operator; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:greenlet; 290, identifier:get; 291, argument_list; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:failed_hosts; 297, identifier:add; 298, argument_list; 298, 299; 299, identifier:host; 300, if_statement; 300, 301; 300, 305; 301, not_operator; 301, 302; 302, subscript; 302, 303; 302, 304; 303, identifier:op_meta; 304, string:'ignore_errors'; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:state; 310, identifier:fail_hosts; 311, argument_list; 311, 312; 312, identifier:failed_hosts; 313, if_statement; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:pyinfra; 316, identifier:is_cli; 317, block; 317, 318; 318, expression_statement; 318, 319; 319, call; 319, 320; 319, 321; 320, identifier:print; 321, argument_list
def _run_single_op(state, op_hash): ''' Run a single operation for all servers. Can be configured to run in serial. ''' op_meta = state.op_meta[op_hash] op_types = [] if op_meta['serial']: op_types.append('serial') if op_meta['run_once']: op_types.append('run once') logger.info('{0} {1} {2}'.format( click.style('--> Starting{0}operation:'.format( ' {0} '.format(', '.join(op_types)) if op_types else ' ', ), 'blue'), click.style(', '.join(op_meta['names']), bold=True), tuple(op_meta['args']) if op_meta['args'] else '', )) failed_hosts = set() if op_meta['serial']: with progress_spinner(state.inventory) as progress: for host in state.inventory: result = _run_server_op(state, host, op_hash) progress(host) if not result: failed_hosts.add(host) else: batches = [state.inventory] if op_meta['parallel']: parallel = op_meta['parallel'] hosts = list(state.inventory) batches = [ hosts[i:i + parallel] for i in range(0, len(hosts), parallel) ] for batch in batches: with progress_spinner(batch) as progress: greenlet_to_host = { state.pool.spawn(_run_server_op, state, host, op_hash): host for host in batch } for greenlet in gevent.iwait(greenlet_to_host.keys()): host = greenlet_to_host[greenlet] progress(host) for greenlet, host in six.iteritems(greenlet_to_host): if not greenlet.get(): failed_hosts.add(host) if not op_meta['ignore_errors']: state.fail_hosts(failed_hosts) if pyinfra.is_cli: print()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:send; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 45; 5, 67; 6, if_statement; 6, 7; 6, 11; 6, 18; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_receive_has_been_called; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:all_addrs; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_dest_addrs; 18, else_clause; 18, 19; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:all_addrs; 23, list_comprehension; 23, 24; 23, 25; 23, 39; 24, identifier:a; 25, for_in_clause; 25, 26; 25, 29; 26, tuple_pattern; 26, 27; 26, 28; 27, identifier:i; 28, identifier:a; 29, call; 29, 30; 29, 31; 30, identifier:list; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_id_to_addr; 37, identifier:items; 38, argument_list; 39, if_clause; 39, 40; 40, comparison_operator:in; 40, 41; 40, 42; 41, identifier:i; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:_remaining_ids; 45, if_statement; 45, 46; 45, 51; 46, comparison_operator:is; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_last_used_id; 50, None; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_last_used_id; 57, binary_operator:&; 57, 58; 57, 66; 58, call; 58, 59; 58, 60; 59, identifier:int; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:time; 64, identifier:time; 65, argument_list; 66, integer:0xffff; 67, for_statement; 67, 68; 67, 69; 67, 70; 68, identifier:addr; 69, identifier:all_addrs; 70, block; 70, 71; 70, 84; 70, 94; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:_last_used_id; 76, binary_operator:&; 76, 77; 76, 83; 77, parenthesized_expression; 77, 78; 78, binary_operator:+; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:_last_used_id; 82, integer:1; 83, integer:0xffff; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 93; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_id_to_addr; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:_last_used_id; 93, identifier:addr; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_send_ping; 99, argument_list; 99, 100; 99, 101; 100, identifier:addr; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:payload; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:struct; 106, identifier:pack; 107, argument_list; 107, 108; 107, 109; 108, string:"d"; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:time; 112, identifier:time; 113, argument_list
def send(self): if not self._receive_has_been_called: all_addrs = self._dest_addrs else: all_addrs = [a for (i, a) in list(self._id_to_addr.items()) if i in self._remaining_ids] if self._last_used_id is None: self._last_used_id = int(time.time()) & 0xffff for addr in all_addrs: self._last_used_id = (self._last_used_id + 1) & 0xffff self._id_to_addr[self._last_used_id] = addr self._send_ping(addr, payload=struct.pack("d", time.time()))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_parse; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:registers; 6, block; 6, 7; 6, 19; 6, 38; 6, 52; 6, 62; 6, 85; 6, 95; 6, 119; 6, 132; 6, 143; 6, 155; 6, 161; 6, 171; 6, 177; 6, 185; 6, 224; 6, 237; 6, 247; 6, 253; 6, 263; 6, 275; 6, 281; 6, 291; 6, 297; 6, 311; 6, 325; 6, 350; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:result; 10, dictionary; 10, 11; 10, 16; 11, pair; 11, 12; 11, 13; 12, string:'ip'; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:ip; 16, pair; 16, 17; 16, 18; 17, string:'connected'; 18, True; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:decoder; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:BinaryPayloadDecoder; 25, identifier:fromRegisters; 26, argument_list; 26, 27; 26, 28; 26, 33; 27, identifier:registers; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:byteorder; 30, attribute; 30, 31; 30, 32; 31, identifier:Endian; 32, identifier:Big; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:wordorder; 35, attribute; 35, 36; 35, 37; 36, identifier:Endian; 37, identifier:Little; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:b; 41, list:[decoder.decode_bits(), decoder.decode_bits()]; 41, 42; 41, 47; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:decoder; 45, identifier:decode_bits; 46, argument_list; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:decoder; 50, identifier:decode_bits; 51, argument_list; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:reg_40001; 55, binary_operator:+; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:b; 58, integer:1; 59, subscript; 59, 60; 59, 61; 60, identifier:b; 61, integer:0; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:monitor_integer; 65, call; 65, 66; 65, 67; 66, identifier:sum; 67, generator_expression; 67, 68; 67, 71; 67, 83; 68, binary_operator:<<; 68, 69; 68, 70; 69, integer:1; 70, identifier:i; 71, for_in_clause; 71, 72; 71, 75; 72, pattern_list; 72, 73; 72, 74; 73, identifier:i; 74, identifier:b; 75, call; 75, 76; 75, 77; 76, identifier:enumerate; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 80; 79, identifier:reg_40001; 80, slice; 80, 81; 80, 82; 81, colon; 82, integer:4; 83, if_clause; 83, 84; 84, identifier:b; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:result; 89, string:'state'; 90, subscript; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:options; 93, string:'monitor state'; 94, identifier:monitor_integer; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:fault_integer; 98, call; 98, 99; 98, 100; 99, identifier:sum; 100, generator_expression; 100, 101; 100, 104; 100, 117; 101, binary_operator:<<; 101, 102; 101, 103; 102, integer:1; 103, identifier:i; 104, for_in_clause; 104, 105; 104, 108; 105, pattern_list; 105, 106; 105, 107; 106, identifier:i; 107, identifier:b; 108, call; 108, 109; 108, 110; 109, identifier:enumerate; 110, argument_list; 110, 111; 111, subscript; 111, 112; 111, 113; 112, identifier:reg_40001; 113, slice; 113, 114; 113, 115; 113, 116; 114, integer:4; 115, colon; 116, integer:6; 117, if_clause; 117, 118; 118, identifier:b; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, subscript; 121, 122; 121, 123; 122, identifier:result; 123, string:'fault'; 124, dictionary; 124, 125; 125, pair; 125, 126; 125, 127; 126, string:'status'; 127, subscript; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:options; 130, string:'fault status'; 131, identifier:fault_integer; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 137; 134, pattern_list; 134, 135; 134, 136; 135, identifier:low; 136, identifier:high; 137, subscript; 137, 138; 137, 139; 138, identifier:reg_40001; 139, slice; 139, 140; 139, 141; 139, 142; 140, integer:6; 141, colon; 142, integer:8; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:result; 147, string:'alarm'; 148, subscript; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:options; 151, string:'alarm level'; 152, binary_operator:+; 152, 153; 152, 154; 153, identifier:low; 154, identifier:high; 155, expression_statement; 155, 156; 156, augmented_assignment:+=; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:decoder; 159, identifier:_pointer; 160, integer:2; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:result; 165, string:'concentration'; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:decoder; 169, identifier:decode_32bit_float; 170, argument_list; 171, expression_statement; 171, 172; 172, augmented_assignment:+=; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:decoder; 175, identifier:_pointer; 176, integer:2; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:fault_number; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:decoder; 183, identifier:decode_16bit_uint; 184, argument_list; 185, if_statement; 185, 186; 185, 189; 186, comparison_operator:!=; 186, 187; 186, 188; 187, identifier:fault_number; 188, integer:0; 189, block; 189, 190; 189, 205; 189, 213; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:code; 193, binary_operator:+; 193, 194; 193, 201; 194, parenthesized_expression; 194, 195; 195, conditional_expression:if; 195, 196; 195, 197; 195, 200; 196, string:'m'; 197, comparison_operator:<; 197, 198; 197, 199; 198, identifier:fault_number; 199, integer:30; 200, string:'F'; 201, call; 201, 202; 201, 203; 202, identifier:str; 203, argument_list; 203, 204; 204, identifier:fault_number; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 212; 207, subscript; 207, 208; 207, 211; 208, subscript; 208, 209; 208, 210; 209, identifier:result; 210, string:'fault'; 211, string:'code'; 212, identifier:code; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 220; 215, attribute; 215, 216; 215, 219; 216, subscript; 216, 217; 216, 218; 217, identifier:result; 218, string:'fault'; 219, identifier:update; 220, argument_list; 220, 221; 221, subscript; 221, 222; 221, 223; 222, identifier:faults; 223, identifier:code; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:unit_bit; 227, call; 227, 228; 227, 235; 228, attribute; 228, 229; 228, 234; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:decoder; 232, identifier:decode_bits; 233, argument_list; 234, identifier:index; 235, argument_list; 235, 236; 236, True; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 242; 239, subscript; 239, 240; 239, 241; 240, identifier:result; 241, string:'units'; 242, subscript; 242, 243; 242, 246; 243, subscript; 243, 244; 243, 245; 244, identifier:options; 245, string:'concentration unit'; 246, identifier:unit_bit; 247, expression_statement; 247, 248; 248, augmented_assignment:+=; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:decoder; 251, identifier:_pointer; 252, integer:1; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:result; 257, string:'temperature'; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:decoder; 261, identifier:decode_16bit_int; 262, argument_list; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:result; 267, string:'life'; 268, binary_operator:/; 268, 269; 268, 274; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:decoder; 272, identifier:decode_16bit_uint; 273, argument_list; 274, float:24.0; 275, expression_statement; 275, 276; 276, augmented_assignment:+=; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:decoder; 279, identifier:_pointer; 280, integer:2; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 286; 283, subscript; 283, 284; 283, 285; 284, identifier:result; 285, string:'flow'; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:decoder; 289, identifier:decode_16bit_uint; 290, argument_list; 291, expression_statement; 291, 292; 292, augmented_assignment:+=; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:decoder; 295, identifier:_pointer; 296, integer:2; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 302; 299, subscript; 299, 300; 299, 301; 300, identifier:result; 301, string:'low-alarm threshold'; 302, call; 302, 303; 302, 304; 303, identifier:round; 304, argument_list; 304, 305; 304, 310; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:decoder; 308, identifier:decode_32bit_float; 309, argument_list; 310, integer:6; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 316; 313, subscript; 313, 314; 313, 315; 314, identifier:result; 315, string:'high-alarm threshold'; 316, call; 316, 317; 316, 318; 317, identifier:round; 318, argument_list; 318, 319; 318, 324; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:decoder; 322, identifier:decode_32bit_float; 323, argument_list; 324, integer:6; 325, if_statement; 325, 326; 325, 331; 326, comparison_operator:==; 326, 327; 326, 330; 327, subscript; 327, 328; 327, 329; 328, identifier:result; 329, string:'units'; 330, string:'ppb'; 331, block; 331, 332; 331, 338; 331, 344; 332, expression_statement; 332, 333; 333, augmented_assignment:*=; 333, 334; 333, 337; 334, subscript; 334, 335; 334, 336; 335, identifier:result; 336, string:'concentration'; 337, integer:1000; 338, expression_statement; 338, 339; 339, augmented_assignment:*=; 339, 340; 339, 343; 340, subscript; 340, 341; 340, 342; 341, identifier:result; 342, string:'low-alarm threshold'; 343, integer:1000; 344, expression_statement; 344, 345; 345, augmented_assignment:*=; 345, 346; 345, 349; 346, subscript; 346, 347; 346, 348; 347, identifier:result; 348, string:'high-alarm threshold'; 349, integer:1000; 350, return_statement; 350, 351; 351, identifier:result
def _parse(self, registers): result = {'ip': self.ip, 'connected': True} decoder = BinaryPayloadDecoder.fromRegisters(registers, byteorder=Endian.Big, wordorder=Endian.Little) b = [decoder.decode_bits(), decoder.decode_bits()] reg_40001 = b[1] + b[0] monitor_integer = sum(1 << i for i, b in enumerate(reg_40001[:4]) if b) result['state'] = options['monitor state'][monitor_integer] fault_integer = sum(1 << i for i, b in enumerate(reg_40001[4:6]) if b) result['fault'] = {'status': options['fault status'][fault_integer]} low, high = reg_40001[6:8] result['alarm'] = options['alarm level'][low + high] decoder._pointer += 2 result['concentration'] = decoder.decode_32bit_float() decoder._pointer += 2 fault_number = decoder.decode_16bit_uint() if fault_number != 0: code = ('m' if fault_number < 30 else 'F') + str(fault_number) result['fault']['code'] = code result['fault'].update(faults[code]) unit_bit = decoder.decode_bits().index(True) result['units'] = options['concentration unit'][unit_bit] decoder._pointer += 1 result['temperature'] = decoder.decode_16bit_int() result['life'] = decoder.decode_16bit_uint() / 24.0 decoder._pointer += 2 result['flow'] = decoder.decode_16bit_uint() decoder._pointer += 2 result['low-alarm threshold'] = round(decoder.decode_32bit_float(), 6) result['high-alarm threshold'] = round(decoder.decode_32bit_float(), 6) if result['units'] == 'ppb': result['concentration'] *= 1000 result['low-alarm threshold'] *= 1000 result['high-alarm threshold'] *= 1000 return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:ParseCFlags; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:start_line; 7, integer:0; 8, block; 8, 9; 8, 13; 8, 17; 8, 21; 8, 217; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:modname; 12, None; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:modlist; 16, list:[]; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:flag; 20, None; 21, for_statement; 21, 22; 21, 23; 21, 33; 22, identifier:line_num; 23, call; 23, 24; 23, 25; 24, identifier:range; 25, argument_list; 25, 26; 25, 27; 26, identifier:start_line; 27, call; 27, 28; 27, 29; 28, identifier:len; 29, argument_list; 29, 30; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:output; 33, block; 33, 34; 33, 46; 33, 65; 33, 76; 33, 139; 33, 150; 33, 191; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:line; 37, call; 37, 38; 37, 45; 38, attribute; 38, 39; 38, 44; 39, subscript; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:output; 43, identifier:line_num; 44, identifier:rstrip; 45, argument_list; 46, if_statement; 46, 47; 46, 49; 47, not_operator; 47, 48; 48, identifier:line; 49, block; 49, 50; 49, 64; 50, if_statement; 50, 51; 50, 52; 51, identifier:flag; 52, block; 52, 53; 52, 60; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:modlist; 57, identifier:append; 58, argument_list; 58, 59; 59, identifier:flag; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:flag; 63, None; 64, continue_statement; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:mobj; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:module_c_re; 73, identifier:match; 74, argument_list; 74, 75; 75, identifier:line; 76, if_statement; 76, 77; 76, 78; 77, identifier:mobj; 78, block; 78, 79; 78, 88; 78, 97; 78, 107; 78, 116; 78, 126; 78, 134; 78, 138; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:modname; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:mobj; 85, identifier:group; 86, argument_list; 86, 87; 87, integer:1; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:logging; 92, identifier:debug; 93, argument_list; 93, 94; 94, binary_operator:%; 94, 95; 94, 96; 95, string:'Module: %s'; 96, identifier:line; 97, if_statement; 97, 98; 97, 99; 98, identifier:flag; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:modlist; 104, identifier:append; 105, argument_list; 105, 106; 106, identifier:flag; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 114; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:module_list; 113, identifier:append; 114, argument_list; 114, 115; 115, identifier:modname; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 123; 118, attribute; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:modules; 122, identifier:setdefault; 123, argument_list; 123, 124; 123, 125; 124, identifier:modname; 125, list:[]; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:modlist; 129, subscript; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:modules; 133, identifier:modname; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:flag; 137, None; 138, continue_statement; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:mobj; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:flag_c_re; 147, identifier:match; 148, argument_list; 148, 149; 149, identifier:line; 150, if_statement; 150, 151; 150, 152; 151, identifier:mobj; 152, block; 152, 153; 152, 163; 152, 172; 152, 190; 153, if_statement; 153, 154; 153, 155; 154, identifier:flag; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:modlist; 160, identifier:append; 161, argument_list; 161, 162; 162, identifier:flag; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:logging; 167, identifier:debug; 168, argument_list; 168, 169; 169, binary_operator:%; 169, 170; 169, 171; 170, string:'Flag: %s'; 171, identifier:line; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:flag; 175, call; 175, 176; 175, 177; 176, identifier:Flag; 177, argument_list; 177, 178; 177, 184; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:mobj; 181, identifier:group; 182, argument_list; 182, 183; 183, integer:1; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:mobj; 187, identifier:group; 188, argument_list; 188, 189; 189, integer:2; 190, continue_statement; 191, if_statement; 191, 192; 191, 193; 191, 206; 192, identifier:flag; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, augmented_assignment:+=; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:flag; 198, identifier:help; 199, binary_operator:+; 199, 200; 199, 201; 200, string:' '; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:line; 204, identifier:strip; 205, argument_list; 206, else_clause; 206, 207; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:logging; 212, identifier:info; 213, argument_list; 213, 214; 214, binary_operator:%; 214, 215; 214, 216; 215, string:'Extra: %s'; 216, identifier:line; 217, if_statement; 217, 218; 217, 219; 218, identifier:flag; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:modlist; 224, identifier:append; 225, argument_list; 225, 226; 226, identifier:flag
def ParseCFlags(self, start_line=0): modname = None modlist = [] flag = None for line_num in range(start_line, len(self.output)): line = self.output[line_num].rstrip() if not line: if flag: modlist.append(flag) flag = None continue mobj = self.module_c_re.match(line) if mobj: modname = mobj.group(1) logging.debug('Module: %s' % line) if flag: modlist.append(flag) self.module_list.append(modname) self.modules.setdefault(modname, []) modlist = self.modules[modname] flag = None continue mobj = self.flag_c_re.match(line) if mobj: if flag: modlist.append(flag) logging.debug('Flag: %s' % line) flag = Flag(mobj.group(1), mobj.group(2)) continue if flag: flag.help += ' ' + line.strip() else: logging.info('Extra: %s' % line) if flag: modlist.append(flag)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:DEFINE_alias; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:name; 5, identifier:original_name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:flag_values; 8, identifier:FLAGS; 9, default_parameter; 9, 10; 9, 11; 10, identifier:module_name; 11, None; 12, block; 12, 13; 12, 23; 12, 29; 12, 51; 12, 85; 12, 93; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:not; 14, 15; 14, 16; 15, identifier:original_name; 16, identifier:flag_values; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:UnrecognizedFlagError; 21, argument_list; 21, 22; 22, identifier:original_name; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:flag; 26, subscript; 26, 27; 26, 28; 27, identifier:flag_values; 28, identifier:original_name; 29, class_definition; 29, 30; 29, 31; 29, 33; 30, identifier:_Parser; 31, argument_list; 31, 32; 32, identifier:ArgumentParser; 33, block; 33, 34; 34, function_definition; 34, 35; 34, 36; 34, 39; 35, function_name:parse; 36, parameters; 36, 37; 36, 38; 37, identifier:self; 38, identifier:argument; 39, block; 39, 40; 39, 47; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:flag; 44, identifier:parse; 45, argument_list; 45, 46; 46, identifier:argument; 47, return_statement; 47, 48; 48, attribute; 48, 49; 48, 50; 49, identifier:flag; 50, identifier:value; 51, class_definition; 51, 52; 51, 53; 51, 55; 52, identifier:_FlagAlias; 53, argument_list; 53, 54; 54, identifier:Flag; 55, block; 55, 56; 55, 68; 56, decorated_definition; 56, 57; 56, 59; 57, decorator; 57, 58; 58, identifier:property; 59, function_definition; 59, 60; 59, 61; 59, 63; 60, function_name:value; 61, parameters; 61, 62; 62, identifier:self; 63, block; 63, 64; 64, return_statement; 64, 65; 65, attribute; 65, 66; 65, 67; 66, identifier:flag; 67, identifier:value; 68, decorated_definition; 68, 69; 68, 73; 69, decorator; 69, 70; 70, attribute; 70, 71; 70, 72; 71, identifier:value; 72, identifier:setter; 73, function_definition; 73, 74; 73, 75; 73, 78; 74, function_name:value; 75, parameters; 75, 76; 75, 77; 76, identifier:self; 77, identifier:value; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:flag; 83, identifier:value; 84, identifier:value; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:help_msg; 88, binary_operator:%; 88, 89; 88, 90; 89, string:'Alias for --%s.'; 90, attribute; 90, 91; 90, 92; 91, identifier:flag; 92, identifier:name; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:DEFINE_flag; 96, argument_list; 96, 97; 96, 116; 96, 117; 97, call; 97, 98; 97, 99; 98, identifier:_FlagAlias; 99, argument_list; 99, 100; 99, 103; 99, 106; 99, 107; 99, 110; 99, 111; 100, call; 100, 101; 100, 102; 101, identifier:_Parser; 102, argument_list; 103, attribute; 103, 104; 103, 105; 104, identifier:flag; 105, identifier:serializer; 106, identifier:name; 107, attribute; 107, 108; 107, 109; 108, identifier:flag; 109, identifier:default; 110, identifier:help_msg; 111, keyword_argument; 111, 112; 111, 113; 112, identifier:boolean; 113, attribute; 113, 114; 113, 115; 114, identifier:flag; 115, identifier:boolean; 116, identifier:flag_values; 117, identifier:module_name
def DEFINE_alias(name, original_name, flag_values=FLAGS, module_name=None): if original_name not in flag_values: raise UnrecognizedFlagError(original_name) flag = flag_values[original_name] class _Parser(ArgumentParser): def parse(self, argument): flag.parse(argument) return flag.value class _FlagAlias(Flag): @property def value(self): return flag.value @value.setter def value(self, value): flag.value = value help_msg = 'Alias for --%s.' % flag.name DEFINE_flag(_FlagAlias(_Parser(), flag.serializer, name, flag.default, help_msg, boolean=flag.boolean), flag_values, module_name)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:acquire; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:cls; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:lifetime; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:mechs; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:usage; 16, string:'both'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:store; 19, None; 20, block; 20, 21; 20, 73; 21, if_statement; 21, 22; 21, 25; 21, 38; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:store; 24, None; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:res; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:rcreds; 32, identifier:acquire_cred; 33, argument_list; 33, 34; 33, 35; 33, 36; 33, 37; 34, identifier:name; 35, identifier:lifetime; 36, identifier:mechs; 37, identifier:usage; 38, else_clause; 38, 39; 39, block; 39, 40; 39, 53; 39, 60; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:rcred_cred_store; 43, None; 44, block; 44, 45; 45, raise_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:NotImplementedError; 48, argument_list; 48, 49; 49, concatenated_string; 49, 50; 49, 51; 49, 52; 50, string:"Your GSSAPI implementation does "; 51, string:"not have support for manipulating "; 52, string:"credential stores"; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:store; 56, call; 56, 57; 56, 58; 57, identifier:_encode_dict; 58, argument_list; 58, 59; 59, identifier:store; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:res; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:rcred_cred_store; 66, identifier:acquire_cred_from; 67, argument_list; 67, 68; 67, 69; 67, 70; 67, 71; 67, 72; 68, identifier:store; 69, identifier:name; 70, identifier:lifetime; 71, identifier:mechs; 72, identifier:usage; 73, return_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:tuples; 77, identifier:AcquireCredResult; 78, argument_list; 78, 79; 78, 87; 78, 90; 79, call; 79, 80; 79, 81; 80, identifier:cls; 81, argument_list; 81, 82; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:base; 84, attribute; 84, 85; 84, 86; 85, identifier:res; 86, identifier:creds; 87, attribute; 87, 88; 87, 89; 88, identifier:res; 89, identifier:mechs; 90, attribute; 90, 91; 90, 92; 91, identifier:res; 92, identifier:lifetime
def acquire(cls, name=None, lifetime=None, mechs=None, usage='both', store=None): if store is None: res = rcreds.acquire_cred(name, lifetime, mechs, usage) else: if rcred_cred_store is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for manipulating " "credential stores") store = _encode_dict(store) res = rcred_cred_store.acquire_cred_from(store, name, lifetime, mechs, usage) return tuples.AcquireCredResult(cls(base=res.creds), res.mechs, res.lifetime)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:store; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:store; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:usage; 10, string:'both'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:mech; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:overwrite; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:set_default; 19, False; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 25; 21, 49; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:store; 24, None; 25, block; 25, 26; 25, 38; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:rcred_rfc5588; 29, None; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:NotImplementedError; 34, argument_list; 34, 35; 35, concatenated_string; 35, 36; 35, 37; 36, string:"Your GSSAPI implementation does "; 37, string:"not have support for RFC 5588"; 38, return_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:rcred_rfc5588; 42, identifier:store_cred; 43, argument_list; 43, 44; 43, 45; 43, 46; 43, 47; 43, 48; 44, identifier:self; 45, identifier:usage; 46, identifier:mech; 47, identifier:overwrite; 48, identifier:set_default; 49, else_clause; 49, 50; 50, block; 50, 51; 50, 64; 50, 71; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:rcred_cred_store; 54, None; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:NotImplementedError; 59, argument_list; 59, 60; 60, concatenated_string; 60, 61; 60, 62; 60, 63; 61, string:"Your GSSAPI implementation does "; 62, string:"not have support for manipulating "; 63, string:"credential stores directly"; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:store; 67, call; 67, 68; 67, 69; 68, identifier:_encode_dict; 69, argument_list; 69, 70; 70, identifier:store; 71, return_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:rcred_cred_store; 75, identifier:store_cred_into; 76, argument_list; 76, 77; 76, 78; 76, 79; 76, 80; 76, 81; 76, 82; 77, identifier:store; 78, identifier:self; 79, identifier:usage; 80, identifier:mech; 81, identifier:overwrite; 82, identifier:set_default
def store(self, store=None, usage='both', mech=None, overwrite=False, set_default=False): if store is None: if rcred_rfc5588 is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for RFC 5588") return rcred_rfc5588.store_cred(self, usage, mech, overwrite, set_default) else: if rcred_cred_store is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for manipulating " "credential stores directly") store = _encode_dict(store) return rcred_cred_store.store_cred_into(store, self, usage, mech, overwrite, set_default)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:add; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 4, identifier:self; 5, identifier:name; 6, identifier:mech; 7, default_parameter; 7, 8; 7, 9; 8, identifier:usage; 9, string:'both'; 10, default_parameter; 10, 11; 10, 12; 11, identifier:init_lifetime; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:accept_lifetime; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:impersonator; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:store; 21, None; 22, block; 22, 23; 22, 39; 22, 127; 23, if_statement; 23, 24; 23, 31; 24, boolean_operator:and; 24, 25; 24, 28; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:store; 27, None; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:impersonator; 30, None; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:ValueError; 35, argument_list; 35, 36; 36, concatenated_string; 36, 37; 36, 38; 37, string:'You cannot use both the `impersonator` and '; 38, string:'`store` arguments at the same time'; 39, if_statement; 39, 40; 39, 43; 39, 79; 39, 111; 40, comparison_operator:is; 40, 41; 40, 42; 41, identifier:store; 42, None; 43, block; 43, 44; 43, 57; 43, 64; 44, if_statement; 44, 45; 44, 48; 45, comparison_operator:is; 45, 46; 45, 47; 46, identifier:rcred_cred_store; 47, None; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:NotImplementedError; 52, argument_list; 52, 53; 53, concatenated_string; 53, 54; 53, 55; 53, 56; 54, string:"Your GSSAPI implementation does "; 55, string:"not have support for manipulating "; 56, string:"credential stores"; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:store; 60, call; 60, 61; 60, 62; 61, identifier:_encode_dict; 62, argument_list; 62, 63; 63, identifier:store; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:res; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:rcred_cred_store; 70, identifier:add_cred_from; 71, argument_list; 71, 72; 71, 73; 71, 74; 71, 75; 71, 76; 71, 77; 71, 78; 72, identifier:store; 73, identifier:self; 74, identifier:name; 75, identifier:mech; 76, identifier:usage; 77, identifier:init_lifetime; 78, identifier:accept_lifetime; 79, elif_clause; 79, 80; 79, 83; 80, comparison_operator:is; 80, 81; 80, 82; 81, identifier:impersonator; 82, None; 83, block; 83, 84; 83, 96; 84, if_statement; 84, 85; 84, 88; 85, comparison_operator:is; 85, 86; 85, 87; 86, identifier:rcred_s4u; 87, None; 88, block; 88, 89; 89, raise_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:NotImplementedError; 92, argument_list; 92, 93; 93, concatenated_string; 93, 94; 93, 95; 94, string:"Your GSSAPI implementation does "; 95, string:"not have support for S4U"; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:res; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:rcred_s4u; 102, identifier:add_cred_impersonate_name; 103, argument_list; 103, 104; 103, 105; 103, 106; 103, 107; 103, 108; 103, 109; 103, 110; 104, identifier:self; 105, identifier:impersonator; 106, identifier:name; 107, identifier:mech; 108, identifier:usage; 109, identifier:init_lifetime; 110, identifier:accept_lifetime; 111, else_clause; 111, 112; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:res; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:rcreds; 119, identifier:add_cred; 120, argument_list; 120, 121; 120, 122; 120, 123; 120, 124; 120, 125; 120, 126; 121, identifier:self; 122, identifier:name; 123, identifier:mech; 124, identifier:usage; 125, identifier:init_lifetime; 126, identifier:accept_lifetime; 127, return_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:Credentials; 130, argument_list; 130, 131; 131, attribute; 131, 132; 131, 133; 132, identifier:res; 133, identifier:creds
def add(self, name, mech, usage='both', init_lifetime=None, accept_lifetime=None, impersonator=None, store=None): if store is not None and impersonator is not None: raise ValueError('You cannot use both the `impersonator` and ' '`store` arguments at the same time') if store is not None: if rcred_cred_store is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for manipulating " "credential stores") store = _encode_dict(store) res = rcred_cred_store.add_cred_from(store, self, name, mech, usage, init_lifetime, accept_lifetime) elif impersonator is not None: if rcred_s4u is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for S4U") res = rcred_s4u.add_cred_impersonate_name(self, impersonator, name, mech, usage, init_lifetime, accept_lifetime) else: res = rcreds.add_cred(self, name, mech, usage, init_lifetime, accept_lifetime) return Credentials(res.creds)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 107; 2, function_name:velocity_graph; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 3, 41; 3, 44; 3, 47; 3, 50; 3, 53; 3, 56; 3, 59; 3, 62; 3, 65; 3, 68; 3, 71; 3, 74; 3, 77; 3, 80; 3, 83; 3, 86; 3, 89; 3, 92; 3, 95; 3, 98; 3, 101; 3, 104; 4, identifier:adata; 5, default_parameter; 5, 6; 5, 7; 6, identifier:basis; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:vkey; 10, string:'velocity'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:which_graph; 13, string:'velocity'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:n_neighbors; 16, integer:10; 17, default_parameter; 17, 18; 17, 19; 18, identifier:alpha; 19, float:.8; 20, default_parameter; 20, 21; 20, 22; 21, identifier:perc; 22, integer:90; 23, default_parameter; 23, 24; 23, 25; 24, identifier:edge_width; 25, float:.2; 26, default_parameter; 26, 27; 26, 28; 27, identifier:edge_color; 28, string:'grey'; 29, default_parameter; 29, 30; 29, 31; 30, identifier:color; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:use_raw; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:layer; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:color_map; 40, None; 41, default_parameter; 41, 42; 41, 43; 42, identifier:colorbar; 43, True; 44, default_parameter; 44, 45; 44, 46; 45, identifier:palette; 46, None; 47, default_parameter; 47, 48; 47, 49; 48, identifier:size; 49, None; 50, default_parameter; 50, 51; 50, 52; 51, identifier:sort_order; 52, True; 53, default_parameter; 53, 54; 53, 55; 54, identifier:groups; 55, None; 56, default_parameter; 56, 57; 56, 58; 57, identifier:components; 58, None; 59, default_parameter; 59, 60; 59, 61; 60, identifier:projection; 61, string:'2d'; 62, default_parameter; 62, 63; 62, 64; 63, identifier:legend_loc; 64, string:'on data'; 65, default_parameter; 65, 66; 65, 67; 66, identifier:legend_fontsize; 67, None; 68, default_parameter; 68, 69; 68, 70; 69, identifier:legend_fontweight; 70, None; 71, default_parameter; 71, 72; 71, 73; 72, identifier:right_margin; 73, None; 74, default_parameter; 74, 75; 74, 76; 75, identifier:left_margin; 76, None; 77, default_parameter; 77, 78; 77, 79; 78, identifier:xlabel; 79, None; 80, default_parameter; 80, 81; 80, 82; 81, identifier:ylabel; 82, None; 83, default_parameter; 83, 84; 83, 85; 84, identifier:title; 85, None; 86, default_parameter; 86, 87; 86, 88; 87, identifier:fontsize; 88, None; 89, default_parameter; 89, 90; 89, 91; 90, identifier:figsize; 91, None; 92, default_parameter; 92, 93; 92, 94; 93, identifier:dpi; 94, None; 95, default_parameter; 95, 96; 95, 97; 96, identifier:frameon; 97, None; 98, default_parameter; 98, 99; 98, 100; 99, identifier:show; 100, True; 101, default_parameter; 101, 102; 101, 103; 102, identifier:save; 103, None; 104, default_parameter; 104, 105; 104, 106; 105, identifier:ax; 106, None; 107, block; 107, 108; 107, 120; 107, 131; 107, 210; 107, 234; 107, 241; 107, 312; 107, 371; 107, 390; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:basis; 111, conditional_expression:if; 111, 112; 111, 116; 111, 119; 112, call; 112, 113; 112, 114; 113, identifier:default_basis; 114, argument_list; 114, 115; 115, identifier:adata; 116, comparison_operator:is; 116, 117; 116, 118; 117, identifier:basis; 118, None; 119, identifier:basis; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:title; 123, conditional_expression:if; 123, 124; 123, 127; 123, 130; 124, binary_operator:+; 124, 125; 124, 126; 125, identifier:which_graph; 126, string:' graph'; 127, comparison_operator:is; 127, 128; 127, 129; 128, identifier:title; 129, None; 130, identifier:title; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:scatter_kwargs; 134, dictionary; 134, 135; 134, 138; 134, 141; 134, 144; 134, 147; 134, 150; 134, 153; 134, 156; 134, 159; 134, 162; 134, 165; 134, 168; 134, 171; 134, 174; 134, 177; 134, 180; 134, 183; 134, 186; 134, 189; 134, 192; 134, 195; 134, 198; 134, 201; 134, 204; 134, 207; 135, pair; 135, 136; 135, 137; 136, string:"basis"; 137, identifier:basis; 138, pair; 138, 139; 138, 140; 139, string:"perc"; 140, identifier:perc; 141, pair; 141, 142; 141, 143; 142, string:"use_raw"; 143, identifier:use_raw; 144, pair; 144, 145; 144, 146; 145, string:"sort_order"; 146, identifier:sort_order; 147, pair; 147, 148; 147, 149; 148, string:"alpha"; 149, identifier:alpha; 150, pair; 150, 151; 150, 152; 151, string:"components"; 152, identifier:components; 153, pair; 153, 154; 153, 155; 154, string:"projection"; 155, identifier:projection; 156, pair; 156, 157; 156, 158; 157, string:"legend_loc"; 158, identifier:legend_loc; 159, pair; 159, 160; 159, 161; 160, string:"groups"; 161, identifier:groups; 162, pair; 162, 163; 162, 164; 163, string:"legend_fontsize"; 164, identifier:legend_fontsize; 165, pair; 165, 166; 165, 167; 166, string:"legend_fontweight"; 167, identifier:legend_fontweight; 168, pair; 168, 169; 168, 170; 169, string:"palette"; 170, identifier:palette; 171, pair; 171, 172; 171, 173; 172, string:"color_map"; 173, identifier:color_map; 174, pair; 174, 175; 174, 176; 175, string:"frameon"; 176, identifier:frameon; 177, pair; 177, 178; 177, 179; 178, string:"title"; 179, identifier:title; 180, pair; 180, 181; 180, 182; 181, string:"xlabel"; 182, identifier:xlabel; 183, pair; 183, 184; 183, 185; 184, string:"ylabel"; 185, identifier:ylabel; 186, pair; 186, 187; 186, 188; 187, string:"right_margin"; 188, identifier:right_margin; 189, pair; 189, 190; 189, 191; 190, string:"left_margin"; 191, identifier:left_margin; 192, pair; 192, 193; 192, 194; 193, string:"colorbar"; 194, identifier:colorbar; 195, pair; 195, 196; 195, 197; 196, string:"dpi"; 197, identifier:dpi; 198, pair; 198, 199; 198, 200; 199, string:"fontsize"; 200, identifier:fontsize; 201, pair; 201, 202; 201, 203; 202, string:"show"; 203, False; 204, pair; 204, 205; 204, 206; 205, string:"save"; 206, None; 207, pair; 207, 208; 207, 209; 208, string:"figsize"; 209, identifier:figsize; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:ax; 213, call; 213, 214; 213, 215; 214, identifier:scatter; 215, argument_list; 215, 216; 215, 217; 215, 220; 215, 223; 215, 226; 215, 229; 215, 232; 216, identifier:adata; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:layer; 219, identifier:layer; 220, keyword_argument; 220, 221; 220, 222; 221, identifier:color; 222, identifier:color; 223, keyword_argument; 223, 224; 223, 225; 224, identifier:size; 225, identifier:size; 226, keyword_argument; 226, 227; 226, 228; 227, identifier:ax; 228, identifier:ax; 229, keyword_argument; 229, 230; 229, 231; 230, identifier:zorder; 231, integer:0; 232, dictionary_splat; 232, 233; 233, identifier:scatter_kwargs; 234, import_from_statement; 234, 235; 234, 237; 234, 239; 235, dotted_name; 235, 236; 236, identifier:networkx; 237, dotted_name; 237, 238; 238, identifier:Graph; 239, dotted_name; 239, 240; 240, identifier:draw_networkx_edges; 241, if_statement; 241, 242; 241, 245; 241, 291; 242, comparison_operator:==; 242, 243; 242, 244; 243, identifier:which_graph; 244, string:'neighbors'; 245, block; 245, 246; 245, 256; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:T; 249, subscript; 249, 250; 249, 255; 250, subscript; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:adata; 253, identifier:uns; 254, string:'neighbors'; 255, string:'connectivities'; 256, if_statement; 256, 257; 256, 260; 257, comparison_operator:is; 257, 258; 257, 259; 258, identifier:perc; 259, None; 260, block; 260, 261; 260, 273; 260, 285; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:threshold; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:np; 267, identifier:percentile; 268, argument_list; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:T; 271, identifier:data; 272, identifier:perc; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 284; 275, subscript; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:T; 278, identifier:data; 279, comparison_operator:<; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:T; 282, identifier:data; 283, identifier:threshold; 284, integer:0; 285, expression_statement; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:T; 289, identifier:eliminate_zeros; 290, argument_list; 291, else_clause; 291, 292; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:T; 296, call; 296, 297; 296, 298; 297, identifier:transition_matrix; 298, argument_list; 298, 299; 298, 300; 298, 303; 298, 306; 298, 309; 299, identifier:adata; 300, keyword_argument; 300, 301; 300, 302; 301, identifier:vkey; 302, identifier:vkey; 303, keyword_argument; 303, 304; 303, 305; 304, identifier:weight_indirect_neighbors; 305, integer:0; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:n_neighbors; 308, identifier:n_neighbors; 309, keyword_argument; 309, 310; 309, 311; 310, identifier:perc; 311, identifier:perc; 312, with_statement; 312, 313; 312, 320; 313, with_clause; 313, 314; 314, with_item; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:warnings; 318, identifier:catch_warnings; 319, argument_list; 320, block; 320, 321; 320, 328; 320, 354; 320, 362; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:warnings; 325, identifier:simplefilter; 326, argument_list; 326, 327; 327, string:"ignore"; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:edges; 331, call; 331, 332; 331, 333; 332, identifier:draw_networkx_edges; 333, argument_list; 333, 334; 333, 338; 333, 345; 333, 348; 333, 351; 334, call; 334, 335; 334, 336; 335, identifier:Graph; 336, argument_list; 336, 337; 337, identifier:T; 338, subscript; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:adata; 341, identifier:obsm; 342, binary_operator:+; 342, 343; 342, 344; 343, string:'X_'; 344, identifier:basis; 345, keyword_argument; 345, 346; 345, 347; 346, identifier:width; 347, identifier:edge_width; 348, keyword_argument; 348, 349; 348, 350; 349, identifier:edge_color; 350, identifier:edge_color; 351, keyword_argument; 351, 352; 351, 353; 352, identifier:ax; 353, identifier:ax; 354, expression_statement; 354, 355; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:edges; 358, identifier:set_zorder; 359, argument_list; 359, 360; 360, unary_operator:-; 360, 361; 361, integer:2; 362, expression_statement; 362, 363; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:edges; 366, identifier:set_rasterized; 367, argument_list; 367, 368; 368, attribute; 368, 369; 368, 370; 369, identifier:settings; 370, identifier:_vector_friendly; 371, expression_statement; 371, 372; 372, call; 372, 373; 372, 374; 373, identifier:savefig_or_show; 374, argument_list; 374, 375; 374, 381; 374, 384; 374, 387; 375, conditional_expression:if; 375, 376; 375, 377; 375, 380; 376, string:''; 377, comparison_operator:is; 377, 378; 377, 379; 378, identifier:basis; 379, None; 380, identifier:basis; 381, keyword_argument; 381, 382; 381, 383; 382, identifier:dpi; 383, identifier:dpi; 384, keyword_argument; 384, 385; 384, 386; 385, identifier:save; 386, identifier:save; 387, keyword_argument; 387, 388; 387, 389; 388, identifier:show; 389, identifier:show; 390, if_statement; 390, 391; 390, 393; 391, not_operator; 391, 392; 392, identifier:show; 393, block; 393, 394; 394, return_statement; 394, 395; 395, identifier:ax
def velocity_graph(adata, basis=None, vkey='velocity', which_graph='velocity', n_neighbors=10, alpha=.8, perc=90, edge_width=.2, edge_color='grey', color=None, use_raw=None, layer=None, color_map=None, colorbar=True, palette=None, size=None, sort_order=True, groups=None, components=None, projection='2d', legend_loc='on data', legend_fontsize=None, legend_fontweight=None, right_margin=None, left_margin=None, xlabel=None, ylabel=None, title=None, fontsize=None, figsize=None, dpi=None, frameon=None, show=True, save=None, ax=None): basis = default_basis(adata) if basis is None else basis title = which_graph + ' graph' if title is None else title scatter_kwargs = {"basis": basis, "perc": perc, "use_raw": use_raw, "sort_order": sort_order, "alpha": alpha, "components": components, "projection": projection, "legend_loc": legend_loc, "groups": groups, "legend_fontsize": legend_fontsize, "legend_fontweight": legend_fontweight, "palette": palette, "color_map": color_map, "frameon": frameon, "title": title, "xlabel": xlabel, "ylabel": ylabel, "right_margin": right_margin, "left_margin": left_margin, "colorbar": colorbar, "dpi": dpi, "fontsize": fontsize, "show": False, "save": None, "figsize": figsize, } ax = scatter(adata, layer=layer, color=color, size=size, ax=ax, zorder=0, **scatter_kwargs) from networkx import Graph, draw_networkx_edges if which_graph == 'neighbors': T = adata.uns['neighbors']['connectivities'] if perc is not None: threshold = np.percentile(T.data, perc) T.data[T.data < threshold] = 0 T.eliminate_zeros() else: T = transition_matrix(adata, vkey=vkey, weight_indirect_neighbors=0, n_neighbors=n_neighbors, perc=perc) with warnings.catch_warnings(): warnings.simplefilter("ignore") edges = draw_networkx_edges(Graph(T), adata.obsm['X_' + basis], width=edge_width, edge_color=edge_color, ax=ax) edges.set_zorder(-2) edges.set_rasterized(settings._vector_friendly) savefig_or_show('' if basis is None else basis, dpi=dpi, save=save, show=show) if not show: return ax
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:cleanup; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:clean; 7, string:'layers'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:keep; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:copy; 13, False; 14, block; 14, 15; 14, 26; 14, 51; 14, 64; 14, 101; 14, 126; 14, 154; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:adata; 18, conditional_expression:if; 18, 19; 18, 24; 18, 25; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:data; 22, identifier:copy; 23, argument_list; 24, identifier:copy; 25, identifier:data; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:keep; 29, conditional_expression:if; 29, 30; 29, 35; 29, 40; 30, call; 30, 31; 30, 32; 31, identifier:list; 32, argument_list; 32, 33; 33, list:[keep]; 33, 34; 34, identifier:keep; 35, call; 35, 36; 35, 37; 36, identifier:isinstance; 37, argument_list; 37, 38; 37, 39; 38, identifier:keep; 39, identifier:str; 40, conditional_expression:if; 40, 41; 40, 44; 40, 47; 41, call; 41, 42; 41, 43; 42, identifier:list; 43, argument_list; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:keep; 46, None; 47, call; 47, 48; 47, 49; 48, identifier:list; 49, argument_list; 49, 50; 50, identifier:keep; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:keep; 55, identifier:extend; 56, argument_list; 56, 57; 57, list:['spliced', 'unspliced', 'Ms', 'Mu', 'clusters', 'neighbors']; 57, 58; 57, 59; 57, 60; 57, 61; 57, 62; 57, 63; 58, string:'spliced'; 59, string:'unspliced'; 60, string:'Ms'; 61, string:'Mu'; 62, string:'clusters'; 63, string:'neighbors'; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:ann_dict; 67, dictionary; 67, 68; 67, 75; 67, 82; 67, 89; 68, pair; 68, 69; 68, 70; 69, string:'obs'; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:adata; 73, identifier:obs_keys; 74, argument_list; 75, pair; 75, 76; 75, 77; 76, string:'var'; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:adata; 80, identifier:var_keys; 81, argument_list; 82, pair; 82, 83; 82, 84; 83, string:'uns'; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:adata; 87, identifier:uns_keys; 88, argument_list; 89, pair; 89, 90; 89, 91; 90, string:'layers'; 91, call; 91, 92; 91, 93; 92, identifier:list; 93, argument_list; 93, 94; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:adata; 98, identifier:layers; 99, identifier:keys; 100, argument_list; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:not; 102, 103; 102, 104; 103, string:'all'; 104, identifier:clean; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:ann_dict; 109, dictionary_comprehension; 109, 110; 109, 113; 109, 122; 110, pair; 110, 111; 110, 112; 111, identifier:ann; 112, identifier:values; 113, for_in_clause; 113, 114; 113, 117; 114, tuple_pattern; 114, 115; 114, 116; 115, identifier:ann; 116, identifier:values; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:ann_dict; 120, identifier:items; 121, argument_list; 122, if_clause; 122, 123; 123, comparison_operator:in; 123, 124; 123, 125; 124, identifier:ann; 125, identifier:clean; 126, for_statement; 126, 127; 126, 130; 126, 135; 127, tuple_pattern; 127, 128; 127, 129; 128, identifier:ann; 129, identifier:values; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:ann_dict; 133, identifier:items; 134, argument_list; 135, block; 135, 136; 136, for_statement; 136, 137; 136, 138; 136, 139; 137, identifier:value; 138, identifier:values; 139, block; 139, 140; 140, if_statement; 140, 141; 140, 144; 141, comparison_operator:not; 141, 142; 141, 143; 142, identifier:value; 143, identifier:keep; 144, block; 144, 145; 145, delete_statement; 145, 146; 146, parenthesized_expression; 146, 147; 147, subscript; 147, 148; 147, 153; 148, call; 148, 149; 148, 150; 149, identifier:getattr; 150, argument_list; 150, 151; 150, 152; 151, identifier:adata; 152, identifier:ann; 153, identifier:value; 154, return_statement; 154, 155; 155, conditional_expression:if; 155, 156; 155, 157; 155, 158; 156, identifier:adata; 157, identifier:copy; 158, None
def cleanup(data, clean='layers', keep=None, copy=False): adata = data.copy() if copy else data keep = list([keep]) if isinstance(keep, str) else list() if keep is None else list(keep) keep.extend(['spliced', 'unspliced', 'Ms', 'Mu', 'clusters', 'neighbors']) ann_dict = {'obs': adata.obs_keys(), 'var': adata.var_keys(), 'uns': adata.uns_keys(), 'layers': list(adata.layers.keys())} if 'all' not in clean: ann_dict = {ann: values for (ann, values) in ann_dict.items() if ann in clean} for (ann, values) in ann_dict.items(): for value in values: if value not in keep: del(getattr(adata, ann)[value]) return adata if copy else None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 38; 2, function_name:filter_genes; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:min_counts; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:min_cells; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:max_counts; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:max_cells; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:min_counts_u; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:min_cells_u; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:max_counts_u; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:max_cells_u; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:min_shared_counts; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:min_shared_cells; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:copy; 37, False; 38, block; 38, 39; 38, 50; 38, 55; 38, 75; 38, 92; 38, 440; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:adata; 42, conditional_expression:if; 42, 43; 42, 48; 42, 49; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:data; 46, identifier:copy; 47, argument_list; 48, identifier:copy; 49, identifier:data; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:set_initial_size; 53, argument_list; 53, 54; 54, identifier:adata; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:layers; 58, list_comprehension; 58, 59; 58, 60; 58, 65; 59, identifier:layer; 60, for_in_clause; 60, 61; 60, 62; 61, identifier:layer; 62, list:['spliced', 'unspliced']; 62, 63; 62, 64; 63, string:'spliced'; 64, string:'unspliced'; 65, if_clause; 65, 66; 66, comparison_operator:in; 66, 67; 66, 68; 67, identifier:layer; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:adata; 72, identifier:layers; 73, identifier:keys; 74, argument_list; 75, if_statement; 75, 76; 75, 83; 76, boolean_operator:or; 76, 77; 76, 80; 77, comparison_operator:is; 77, 78; 77, 79; 78, identifier:min_shared_counts; 79, None; 80, comparison_operator:is; 80, 81; 80, 82; 81, identifier:min_shared_cells; 82, None; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:layers; 88, identifier:extend; 89, argument_list; 89, 90; 90, list:['shared']; 90, 91; 91, string:'shared'; 92, for_statement; 92, 93; 92, 94; 92, 95; 93, identifier:layer; 94, identifier:layers; 95, block; 95, 96; 95, 144; 95, 236; 95, 250; 95, 281; 95, 312; 95, 322; 96, if_statement; 96, 97; 96, 100; 96, 113; 96, 130; 97, comparison_operator:is; 97, 98; 97, 99; 98, identifier:layer; 99, string:'spliced'; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 108; 103, pattern_list; 103, 104; 103, 105; 103, 106; 103, 107; 104, identifier:_min_counts; 105, identifier:_min_cells; 106, identifier:_max_counts; 107, identifier:_max_cells; 108, expression_list; 108, 109; 108, 110; 108, 111; 108, 112; 109, identifier:min_counts; 110, identifier:min_cells; 111, identifier:max_counts; 112, identifier:max_cells; 113, elif_clause; 113, 114; 113, 117; 114, comparison_operator:is; 114, 115; 114, 116; 115, identifier:layer; 116, string:'unspliced'; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 125; 120, pattern_list; 120, 121; 120, 122; 120, 123; 120, 124; 121, identifier:_min_counts; 122, identifier:_min_cells; 123, identifier:_max_counts; 124, identifier:_max_cells; 125, expression_list; 125, 126; 125, 127; 125, 128; 125, 129; 126, identifier:min_counts_u; 127, identifier:min_cells_u; 128, identifier:max_counts_u; 129, identifier:max_cells_u; 130, else_clause; 130, 131; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 139; 134, pattern_list; 134, 135; 134, 136; 134, 137; 134, 138; 135, identifier:_min_counts; 136, identifier:_min_cells; 137, identifier:_max_counts; 138, identifier:_max_cells; 139, expression_list; 139, 140; 139, 141; 139, 142; 139, 143; 140, identifier:min_shared_counts; 141, identifier:min_shared_cells; 142, None; 143, None; 144, if_statement; 144, 145; 144, 154; 144, 163; 145, comparison_operator:in; 145, 146; 145, 147; 146, identifier:layer; 147, call; 147, 148; 147, 153; 148, attribute; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:adata; 151, identifier:layers; 152, identifier:keys; 153, argument_list; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:X; 158, subscript; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:adata; 161, identifier:layers; 162, identifier:layer; 163, else_clause; 163, 164; 164, block; 164, 165; 164, 181; 164, 209; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, pattern_list; 167, 168; 167, 169; 168, identifier:Xs; 169, identifier:Xu; 170, expression_list; 170, 171; 170, 176; 171, subscript; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:adata; 174, identifier:layers; 175, string:'spliced'; 176, subscript; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:adata; 179, identifier:layers; 180, string:'unspliced'; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:nonzeros; 184, conditional_expression:if; 184, 185; 184, 196; 184, 200; 185, call; 185, 186; 185, 192; 186, attribute; 186, 187; 186, 191; 187, parenthesized_expression; 187, 188; 188, comparison_operator:>; 188, 189; 188, 190; 189, identifier:Xs; 190, integer:0; 191, identifier:multiply; 192, argument_list; 192, 193; 193, comparison_operator:>; 193, 194; 193, 195; 194, identifier:Xu; 195, integer:0; 196, call; 196, 197; 196, 198; 197, identifier:issparse; 198, argument_list; 198, 199; 199, identifier:Xs; 200, binary_operator:*; 200, 201; 200, 205; 201, parenthesized_expression; 201, 202; 202, comparison_operator:>; 202, 203; 202, 204; 203, identifier:Xs; 204, integer:0; 205, parenthesized_expression; 205, 206; 206, comparison_operator:>; 206, 207; 206, 208; 207, identifier:Xu; 208, integer:0; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:X; 212, conditional_expression:if; 212, 213; 212, 226; 212, 230; 213, binary_operator:+; 213, 214; 213, 220; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:nonzeros; 217, identifier:multiply; 218, argument_list; 218, 219; 219, identifier:Xs; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:nonzeros; 223, identifier:multiply; 224, argument_list; 224, 225; 225, identifier:Xu; 226, call; 226, 227; 226, 228; 227, identifier:issparse; 228, argument_list; 228, 229; 229, identifier:nonzeros; 230, binary_operator:*; 230, 231; 230, 232; 231, identifier:nonzeros; 232, parenthesized_expression; 232, 233; 233, binary_operator:+; 233, 234; 233, 235; 234, identifier:Xs; 235, identifier:Xu; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:gene_subset; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:np; 242, identifier:ones; 243, argument_list; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:adata; 246, identifier:n_vars; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:dtype; 249, identifier:bool; 250, if_statement; 250, 251; 250, 258; 251, boolean_operator:or; 251, 252; 251, 255; 252, comparison_operator:is; 252, 253; 252, 254; 253, identifier:_min_counts; 254, None; 255, comparison_operator:is; 255, 256; 255, 257; 256, identifier:_max_counts; 257, None; 258, block; 258, 259; 258, 274; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 264; 261, pattern_list; 261, 262; 261, 263; 262, identifier:gene_subset; 263, identifier:_; 264, call; 264, 265; 264, 266; 265, identifier:filter; 266, argument_list; 266, 267; 266, 268; 266, 271; 267, identifier:X; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:min_counts; 270, identifier:_min_counts; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:max_counts; 273, identifier:_max_counts; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:adata; 278, identifier:_inplace_subset_var; 279, argument_list; 279, 280; 280, identifier:gene_subset; 281, if_statement; 281, 282; 281, 289; 282, boolean_operator:or; 282, 283; 282, 286; 283, comparison_operator:is; 283, 284; 283, 285; 284, identifier:_min_cells; 285, None; 286, comparison_operator:is; 286, 287; 286, 288; 287, identifier:_max_cells; 288, None; 289, block; 289, 290; 289, 305; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 295; 292, pattern_list; 292, 293; 292, 294; 293, identifier:gene_subset; 294, identifier:_; 295, call; 295, 296; 295, 297; 296, identifier:filter; 297, argument_list; 297, 298; 297, 299; 297, 302; 298, identifier:X; 299, keyword_argument; 299, 300; 299, 301; 300, identifier:min_cells; 301, identifier:_min_cells; 302, keyword_argument; 302, 303; 302, 304; 303, identifier:max_cells; 304, identifier:_max_cells; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:adata; 309, identifier:_inplace_subset_var; 310, argument_list; 310, 311; 311, identifier:gene_subset; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:s; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:np; 318, identifier:sum; 319, argument_list; 319, 320; 320, unary_operator:~; 320, 321; 321, identifier:gene_subset; 322, if_statement; 322, 323; 322, 326; 323, comparison_operator:>; 323, 324; 323, 325; 324, identifier:s; 325, integer:0; 326, block; 326, 327; 326, 342; 326, 391; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:logg; 331, identifier:info; 332, argument_list; 332, 333; 332, 339; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, string:'Filtered out {} genes that are detected'; 336, identifier:format; 337, argument_list; 337, 338; 338, identifier:s; 339, keyword_argument; 339, 340; 339, 341; 340, identifier:end; 341, string:' '; 342, if_statement; 342, 343; 342, 350; 343, boolean_operator:or; 343, 344; 343, 347; 344, comparison_operator:is; 344, 345; 344, 346; 345, identifier:_min_cells; 346, None; 347, comparison_operator:is; 347, 348; 347, 349; 348, identifier:_min_counts; 349, None; 350, block; 350, 351; 351, expression_statement; 351, 352; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:logg; 355, identifier:info; 356, argument_list; 356, 357; 356, 358; 356, 388; 357, string:'in less than'; 358, conditional_expression:if; 358, 359; 358, 372; 358, 375; 359, binary_operator:+; 359, 360; 359, 371; 360, binary_operator:+; 360, 361; 360, 367; 361, binary_operator:+; 361, 362; 361, 366; 362, call; 362, 363; 362, 364; 363, identifier:str; 364, argument_list; 364, 365; 365, identifier:_min_cells; 366, string:' cells ('; 367, call; 367, 368; 367, 369; 368, identifier:str; 369, argument_list; 369, 370; 370, identifier:layer; 371, string:').'; 372, comparison_operator:is; 372, 373; 372, 374; 373, identifier:_min_counts; 374, None; 375, binary_operator:+; 375, 376; 375, 387; 376, binary_operator:+; 376, 377; 376, 383; 377, binary_operator:+; 377, 378; 377, 382; 378, call; 378, 379; 378, 380; 379, identifier:str; 380, argument_list; 380, 381; 381, identifier:_min_counts; 382, string:' counts ('; 383, call; 383, 384; 383, 385; 384, identifier:str; 385, argument_list; 385, 386; 386, identifier:layer; 387, string:').'; 388, keyword_argument; 388, 389; 388, 390; 389, identifier:no_indent; 390, True; 391, if_statement; 391, 392; 391, 399; 392, boolean_operator:or; 392, 393; 392, 396; 393, comparison_operator:is; 393, 394; 393, 395; 394, identifier:max_cells; 395, None; 396, comparison_operator:is; 396, 397; 396, 398; 397, identifier:max_counts; 398, None; 399, block; 399, 400; 400, expression_statement; 400, 401; 401, call; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:logg; 404, identifier:info; 405, argument_list; 405, 406; 405, 407; 405, 437; 406, string:'in more than '; 407, conditional_expression:if; 407, 408; 407, 421; 407, 424; 408, binary_operator:+; 408, 409; 408, 420; 409, binary_operator:+; 409, 410; 409, 416; 410, binary_operator:+; 410, 411; 410, 415; 411, call; 411, 412; 411, 413; 412, identifier:str; 413, argument_list; 413, 414; 414, identifier:_max_cells; 415, string:' cells('; 416, call; 416, 417; 416, 418; 417, identifier:str; 418, argument_list; 418, 419; 419, identifier:layer; 420, string:').'; 421, comparison_operator:is; 421, 422; 421, 423; 422, identifier:_max_counts; 423, None; 424, binary_operator:+; 424, 425; 424, 436; 425, binary_operator:+; 425, 426; 425, 432; 426, binary_operator:+; 426, 427; 426, 431; 427, call; 427, 428; 427, 429; 428, identifier:str; 429, argument_list; 429, 430; 430, identifier:_max_counts; 431, string:' counts ('; 432, call; 432, 433; 432, 434; 433, identifier:str; 434, argument_list; 434, 435; 435, identifier:layer; 436, string:').'; 437, keyword_argument; 437, 438; 437, 439; 438, identifier:no_indent; 439, True; 440, return_statement; 440, 441; 441, conditional_expression:if; 441, 442; 441, 443; 441, 444; 442, identifier:adata; 443, identifier:copy; 444, None
def filter_genes(data, min_counts=None, min_cells=None, max_counts=None, max_cells=None, min_counts_u=None, min_cells_u=None, max_counts_u=None, max_cells_u=None, min_shared_counts=None, min_shared_cells=None, copy=False): adata = data.copy() if copy else data set_initial_size(adata) layers = [layer for layer in ['spliced', 'unspliced'] if layer in adata.layers.keys()] if min_shared_counts is not None or min_shared_cells is not None: layers.extend(['shared']) for layer in layers: if layer is 'spliced': _min_counts, _min_cells, _max_counts, _max_cells = min_counts, min_cells, max_counts, max_cells elif layer is 'unspliced': _min_counts, _min_cells, _max_counts, _max_cells = min_counts_u, min_cells_u, max_counts_u, max_cells_u else: _min_counts, _min_cells, _max_counts, _max_cells = min_shared_counts, min_shared_cells, None, None if layer in adata.layers.keys(): X = adata.layers[layer] else: Xs, Xu = adata.layers['spliced'], adata.layers['unspliced'] nonzeros = (Xs > 0).multiply(Xu > 0) if issparse(Xs) else (Xs > 0) * (Xu > 0) X = nonzeros.multiply(Xs) + nonzeros.multiply(Xu) if issparse(nonzeros) else nonzeros * (Xs + Xu) gene_subset = np.ones(adata.n_vars, dtype=bool) if _min_counts is not None or _max_counts is not None: gene_subset, _ = filter(X, min_counts=_min_counts, max_counts=_max_counts) adata._inplace_subset_var(gene_subset) if _min_cells is not None or _max_cells is not None: gene_subset, _ = filter(X, min_cells=_min_cells, max_cells=_max_cells) adata._inplace_subset_var(gene_subset) s = np.sum(~gene_subset) if s > 0: logg.info('Filtered out {} genes that are detected'.format(s), end=' ') if _min_cells is not None or _min_counts is not None: logg.info('in less than', str(_min_cells) + ' cells (' + str(layer) + ').' if _min_counts is None else str(_min_counts) + ' counts (' + str(layer) + ').', no_indent=True) if max_cells is not None or max_counts is not None: logg.info('in more than ', str(_max_cells) + ' cells(' + str(layer) + ').' if _max_counts is None else str(_max_counts) + ' counts (' + str(layer) + ').', no_indent=True) return adata if copy else None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:filter_genes_dispersion; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:flavor; 7, string:'seurat'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:min_disp; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:max_disp; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:min_mean; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:max_mean; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:n_bins; 22, integer:20; 23, default_parameter; 23, 24; 23, 25; 24, identifier:n_top_genes; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:log; 28, True; 29, default_parameter; 29, 30; 29, 31; 30, identifier:copy; 31, False; 32, block; 32, 33; 32, 44; 32, 49; 32, 277; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:adata; 36, conditional_expression:if; 36, 37; 36, 42; 36, 43; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:data; 40, identifier:copy; 41, argument_list; 42, identifier:copy; 43, identifier:data; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:set_initial_size; 47, argument_list; 47, 48; 48, identifier:adata; 49, if_statement; 49, 50; 49, 59; 49, 67; 50, boolean_operator:and; 50, 51; 50, 54; 51, comparison_operator:is; 51, 52; 51, 53; 52, identifier:n_top_genes; 53, None; 54, comparison_operator:<; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:adata; 57, identifier:n_vars; 58, identifier:n_top_genes; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:logg; 64, identifier:info; 65, argument_list; 65, 66; 66, string:'Skip filtering by dispersion since number of variables are less than `n_top_genes`'; 67, else_clause; 67, 68; 68, block; 68, 69; 69, if_statement; 69, 70; 69, 73; 69, 239; 70, comparison_operator:is; 70, 71; 70, 72; 71, identifier:flavor; 72, string:'svr'; 73, block; 73, 74; 73, 102; 73, 146; 73, 155; 73, 166; 73, 172; 73, 186; 73, 198; 73, 213; 73, 230; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:mu; 77, conditional_expression:if; 77, 78; 77, 88; 77, 94; 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:adata; 83, identifier:X; 84, identifier:mean; 85, argument_list; 85, 86; 86, integer:0; 87, identifier:A1; 88, call; 88, 89; 88, 90; 89, identifier:issparse; 90, argument_list; 90, 91; 91, attribute; 91, 92; 91, 93; 92, identifier:adata; 93, identifier:X; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:adata; 98, identifier:X; 99, identifier:mean; 100, argument_list; 100, 101; 101, integer:0; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:sigma; 105, conditional_expression:if; 105, 106; 105, 132; 105, 138; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:np; 109, identifier:sqrt; 110, argument_list; 110, 111; 111, binary_operator:-; 111, 112; 111, 129; 112, attribute; 112, 113; 112, 128; 113, call; 113, 114; 113, 126; 114, attribute; 114, 115; 114, 125; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:adata; 119, identifier:X; 120, identifier:multiply; 121, argument_list; 121, 122; 122, attribute; 122, 123; 122, 124; 123, identifier:adata; 124, identifier:X; 125, identifier:mean; 126, argument_list; 126, 127; 127, integer:0; 128, identifier:A1; 129, binary_operator:**; 129, 130; 129, 131; 130, identifier:mu; 131, integer:2; 132, call; 132, 133; 132, 134; 133, identifier:issparse; 134, argument_list; 134, 135; 135, attribute; 135, 136; 135, 137; 136, identifier:adata; 137, identifier:X; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:adata; 142, identifier:X; 143, identifier:std; 144, argument_list; 144, 145; 145, integer:0; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:log_mu; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:np; 152, identifier:log2; 153, argument_list; 153, 154; 154, identifier:mu; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:log_cv; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:np; 161, identifier:log2; 162, argument_list; 162, 163; 163, binary_operator:/; 163, 164; 163, 165; 164, identifier:sigma; 165, identifier:mu; 166, import_from_statement; 166, 167; 166, 170; 167, dotted_name; 167, 168; 167, 169; 168, identifier:sklearn; 169, identifier:svm; 170, dotted_name; 170, 171; 171, identifier:SVR; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:clf; 175, call; 175, 176; 175, 177; 176, identifier:SVR; 177, argument_list; 177, 178; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:gamma; 180, binary_operator:/; 180, 181; 180, 182; 181, float:150.; 182, call; 182, 183; 182, 184; 183, identifier:len; 184, argument_list; 184, 185; 185, identifier:mu; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:clf; 190, identifier:fit; 191, argument_list; 191, 192; 191, 197; 192, subscript; 192, 193; 192, 194; 192, 196; 193, identifier:log_mu; 194, slice; 194, 195; 195, colon; 196, None; 197, identifier:log_cv; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:score; 201, binary_operator:-; 201, 202; 201, 203; 202, identifier:log_cv; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:clf; 206, identifier:predict; 207, argument_list; 207, 208; 208, subscript; 208, 209; 208, 210; 208, 212; 209, identifier:log_mu; 210, slice; 210, 211; 211, colon; 212, None; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:nth_score; 216, subscript; 216, 217; 216, 229; 217, subscript; 217, 218; 217, 224; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:np; 221, identifier:sort; 222, argument_list; 222, 223; 223, identifier:score; 224, slice; 224, 225; 224, 226; 224, 227; 225, colon; 226, colon; 227, unary_operator:-; 227, 228; 228, integer:1; 229, identifier:n_top_genes; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:adata; 234, identifier:_inplace_subset_var; 235, argument_list; 235, 236; 236, comparison_operator:>=; 236, 237; 236, 238; 237, identifier:score; 238, identifier:nth_score; 239, else_clause; 239, 240; 240, block; 240, 241; 240, 248; 241, import_from_statement; 241, 242; 241, 246; 242, dotted_name; 242, 243; 242, 244; 242, 245; 243, identifier:scanpy; 244, identifier:api; 245, identifier:pp; 246, dotted_name; 246, 247; 247, identifier:filter_genes_dispersion; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 251; 250, identifier:filter_genes_dispersion; 251, argument_list; 251, 252; 251, 253; 251, 256; 251, 259; 251, 262; 251, 265; 251, 268; 251, 271; 251, 274; 252, identifier:adata; 253, keyword_argument; 253, 254; 253, 255; 254, identifier:flavor; 255, identifier:flavor; 256, keyword_argument; 256, 257; 256, 258; 257, identifier:min_disp; 258, identifier:min_disp; 259, keyword_argument; 259, 260; 259, 261; 260, identifier:max_disp; 261, identifier:max_disp; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:min_mean; 264, identifier:min_mean; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:max_mean; 267, identifier:max_mean; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:n_bins; 270, identifier:n_bins; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:n_top_genes; 273, identifier:n_top_genes; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:log; 276, identifier:log; 277, return_statement; 277, 278; 278, conditional_expression:if; 278, 279; 278, 280; 278, 281; 279, identifier:adata; 280, identifier:copy; 281, None
def filter_genes_dispersion(data, flavor='seurat', min_disp=None, max_disp=None, min_mean=None, max_mean=None, n_bins=20, n_top_genes=None, log=True, copy=False): adata = data.copy() if copy else data set_initial_size(adata) if n_top_genes is not None and adata.n_vars < n_top_genes: logg.info('Skip filtering by dispersion since number of variables are less than `n_top_genes`') else: if flavor is 'svr': mu = adata.X.mean(0).A1 if issparse(adata.X) else adata.X.mean(0) sigma = np.sqrt(adata.X.multiply(adata.X).mean(0).A1 - mu ** 2) if issparse(adata.X) else adata.X.std(0) log_mu = np.log2(mu) log_cv = np.log2(sigma / mu) from sklearn.svm import SVR clf = SVR(gamma=150. / len(mu)) clf.fit(log_mu[:, None], log_cv) score = log_cv - clf.predict(log_mu[:, None]) nth_score = np.sort(score)[::-1][n_top_genes] adata._inplace_subset_var(score >= nth_score) else: from scanpy.api.pp import filter_genes_dispersion filter_genes_dispersion(adata, flavor=flavor, min_disp=min_disp, max_disp=max_disp, min_mean=min_mean, max_mean=max_mean, n_bins=n_bins, n_top_genes=n_top_genes, log=log) return adata if copy else None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 31; 2, function_name:normalize_per_cell; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 25; 3, 28; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:counts_per_cell_after; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:counts_per_cell; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:key_n_counts; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:max_proportion_per_cell; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:use_initial_size; 19, True; 20, default_parameter; 20, 21; 20, 22; 21, identifier:layers; 22, list:['spliced', 'unspliced']; 22, 23; 22, 24; 23, string:'spliced'; 24, string:'unspliced'; 25, default_parameter; 25, 26; 25, 27; 26, identifier:enforce; 27, False; 28, default_parameter; 28, 29; 28, 30; 29, identifier:copy; 30, False; 31, block; 31, 32; 31, 43; 31, 81; 31, 88; 31, 92; 31, 227; 31, 243; 31, 266; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:adata; 35, conditional_expression:if; 35, 36; 35, 41; 35, 42; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:data; 39, identifier:copy; 40, argument_list; 41, identifier:copy; 42, identifier:data; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:layers; 46, conditional_expression:if; 46, 47; 46, 54; 46, 57; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:adata; 51, identifier:layers; 52, identifier:keys; 53, argument_list; 54, comparison_operator:is; 54, 55; 54, 56; 55, identifier:layers; 56, string:'all'; 57, conditional_expression:if; 57, 58; 57, 60; 57, 65; 57, 66; 58, list:[layers]; 58, 59; 59, identifier:layers; 60, call; 60, 61; 60, 62; 61, identifier:isinstance; 62, argument_list; 62, 63; 62, 64; 63, identifier:layers; 64, identifier:str; 65, line_continuation:\; 66, list_comprehension; 66, 67; 66, 68; 66, 71; 67, identifier:layer; 68, for_in_clause; 68, 69; 68, 70; 69, identifier:layer; 70, identifier:layers; 71, if_clause; 71, 72; 72, comparison_operator:in; 72, 73; 72, 74; 73, identifier:layer; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:adata; 78, identifier:layers; 79, identifier:keys; 80, argument_list; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:layers; 84, binary_operator:+; 84, 85; 84, 87; 85, list:['X']; 85, 86; 86, string:'X'; 87, identifier:layers; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:modified_layers; 91, list:[]; 92, for_statement; 92, 93; 92, 94; 92, 95; 93, identifier:layer; 94, identifier:layers; 95, block; 95, 96; 95, 111; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:X; 99, conditional_expression:if; 99, 100; 99, 103; 99, 106; 100, attribute; 100, 101; 100, 102; 101, identifier:adata; 102, identifier:X; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:layer; 105, string:'X'; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:adata; 109, identifier:layers; 110, identifier:layer; 111, if_statement; 111, 112; 111, 118; 112, boolean_operator:or; 112, 113; 112, 117; 113, call; 113, 114; 113, 115; 114, identifier:not_yet_normalized; 115, argument_list; 115, 116; 116, identifier:X; 117, identifier:enforce; 118, block; 118, 119; 118, 140; 118, 160; 118, 174; 118, 183; 118, 189; 118, 220; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:counts; 122, conditional_expression:if; 122, 123; 122, 124; 122, 127; 122, 128; 123, identifier:counts_per_cell; 124, comparison_operator:is; 124, 125; 124, 126; 125, identifier:counts_per_cell; 126, None; 127, line_continuation:\; 128, conditional_expression:if; 128, 129; 128, 134; 128, 135; 129, call; 129, 130; 129, 131; 130, identifier:get_initial_size; 131, argument_list; 131, 132; 131, 133; 132, identifier:adata; 133, identifier:layer; 134, identifier:use_initial_size; 135, call; 135, 136; 135, 137; 136, identifier:get_size; 137, argument_list; 137, 138; 137, 139; 138, identifier:adata; 139, identifier:layer; 140, if_statement; 140, 141; 140, 150; 141, boolean_operator:and; 141, 142; 141, 145; 142, comparison_operator:is; 142, 143; 142, 144; 143, identifier:max_proportion_per_cell; 144, None; 145, parenthesized_expression; 145, 146; 146, comparison_operator:<; 146, 147; 146, 148; 146, 149; 147, integer:0; 148, identifier:max_proportion_per_cell; 149, integer:1; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:counts; 154, call; 154, 155; 154, 156; 155, identifier:counts_per_cell_quantile; 156, argument_list; 156, 157; 156, 158; 156, 159; 157, identifier:X; 158, identifier:max_proportion_per_cell; 159, identifier:counts; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:counts_after; 163, conditional_expression:if; 163, 164; 163, 170; 163, 173; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:np; 167, identifier:median; 168, argument_list; 168, 169; 169, identifier:counts; 170, comparison_operator:is; 170, 171; 170, 172; 171, identifier:counts_per_cell_after; 172, None; 173, identifier:counts_per_cell_after; 174, expression_statement; 174, 175; 175, augmented_assignment:/=; 175, 176; 175, 177; 176, identifier:counts; 177, binary_operator:+; 177, 178; 177, 179; 178, identifier:counts_after; 179, parenthesized_expression; 179, 180; 180, comparison_operator:==; 180, 181; 180, 182; 181, identifier:counts_after; 182, integer:0; 183, expression_statement; 183, 184; 184, augmented_assignment:+=; 184, 185; 184, 186; 185, identifier:counts; 186, comparison_operator:==; 186, 187; 186, 188; 187, identifier:counts; 188, integer:0; 189, if_statement; 189, 190; 189, 194; 189, 205; 190, call; 190, 191; 190, 192; 191, identifier:issparse; 192, argument_list; 192, 193; 193, identifier:X; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:sparsefuncs; 199, identifier:inplace_row_scale; 200, argument_list; 200, 201; 200, 202; 201, identifier:X; 202, binary_operator:/; 202, 203; 202, 204; 203, integer:1; 204, identifier:counts; 205, else_clause; 205, 206; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, augmented_assignment:/=; 208, 209; 208, 210; 209, identifier:X; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:np; 213, identifier:array; 214, argument_list; 214, 215; 215, subscript; 215, 216; 215, 217; 215, 219; 216, identifier:counts; 217, slice; 217, 218; 218, colon; 219, None; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:modified_layers; 224, identifier:append; 225, argument_list; 225, 226; 226, identifier:layer; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 239; 229, subscript; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:adata; 232, identifier:obs; 233, conditional_expression:if; 233, 234; 233, 235; 233, 238; 234, string:'n_counts'; 235, comparison_operator:is; 235, 236; 235, 237; 236, identifier:key_n_counts; 237, None; 238, identifier:key_n_counts; 239, call; 239, 240; 239, 241; 240, identifier:get_size; 241, argument_list; 241, 242; 242, identifier:adata; 243, if_statement; 243, 244; 243, 250; 244, comparison_operator:>; 244, 245; 244, 249; 245, call; 245, 246; 245, 247; 246, identifier:len; 247, argument_list; 247, 248; 248, identifier:modified_layers; 249, integer:0; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:logg; 255, identifier:info; 256, argument_list; 256, 257; 256, 258; 257, string:'Normalized count data:'; 258, binary_operator:+; 258, 259; 258, 265; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, string:', '; 262, identifier:join; 263, argument_list; 263, 264; 264, identifier:modified_layers; 265, string:'.'; 266, return_statement; 266, 267; 267, conditional_expression:if; 267, 268; 267, 269; 267, 270; 268, identifier:adata; 269, identifier:copy; 270, None
def normalize_per_cell(data, counts_per_cell_after=None, counts_per_cell=None, key_n_counts=None, max_proportion_per_cell=None, use_initial_size=True, layers=['spliced', 'unspliced'], enforce=False, copy=False): adata = data.copy() if copy else data layers = adata.layers.keys() if layers is 'all' else [layers] if isinstance(layers, str) \ else [layer for layer in layers if layer in adata.layers.keys()] layers = ['X'] + layers modified_layers = [] for layer in layers: X = adata.X if layer is 'X' else adata.layers[layer] if not_yet_normalized(X) or enforce: counts = counts_per_cell if counts_per_cell is not None \ else get_initial_size(adata, layer) if use_initial_size else get_size(adata, layer) if max_proportion_per_cell is not None and (0 < max_proportion_per_cell < 1): counts = counts_per_cell_quantile(X, max_proportion_per_cell, counts) counts_after = np.median(counts) if counts_per_cell_after is None else counts_per_cell_after counts /= counts_after + (counts_after == 0) counts += counts == 0 if issparse(X): sparsefuncs.inplace_row_scale(X, 1 / counts) else: X /= np.array(counts[:, None]) modified_layers.append(layer) adata.obs['n_counts' if key_n_counts is None else key_n_counts] = get_size(adata) if len(modified_layers) > 0: logg.info('Normalized count data:', ', '.join(modified_layers) + '.') return adata if copy else None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 35; 2, function_name:filter_and_normalize; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:min_counts; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:min_counts_u; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:min_cells; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:min_cells_u; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:min_shared_counts; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:min_shared_cells; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:n_top_genes; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:flavor; 28, string:'seurat'; 29, default_parameter; 29, 30; 29, 31; 30, identifier:log; 31, True; 32, default_parameter; 32, 33; 32, 34; 33, identifier:copy; 34, False; 35, block; 35, 36; 35, 47; 35, 73; 35, 96; 35, 101; 35, 117; 35, 149; 35, 159; 35, 177; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:adata; 39, conditional_expression:if; 39, 40; 39, 45; 39, 46; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:data; 43, identifier:copy; 44, argument_list; 45, identifier:copy; 46, identifier:data; 47, if_statement; 47, 48; 47, 67; 48, boolean_operator:or; 48, 49; 48, 58; 49, comparison_operator:not; 49, 50; 49, 51; 50, string:'spliced'; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:adata; 55, identifier:layers; 56, identifier:keys; 57, argument_list; 58, comparison_operator:not; 58, 59; 58, 60; 59, string:'unspliced'; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:adata; 64, identifier:layers; 65, identifier:keys; 66, argument_list; 67, block; 67, 68; 68, raise_statement; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:ValueError; 71, argument_list; 71, 72; 72, string:'Could not find spliced / unspliced counts.'; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:filter_genes; 76, argument_list; 76, 77; 76, 78; 76, 81; 76, 84; 76, 87; 76, 90; 76, 93; 77, identifier:adata; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:min_counts; 80, identifier:min_counts; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:min_counts_u; 83, identifier:min_counts_u; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:min_cells; 86, identifier:min_cells; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:min_cells_u; 89, identifier:min_cells_u; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:min_shared_counts; 92, identifier:min_shared_counts; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:min_shared_cells; 95, identifier:min_shared_cells; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:normalize_per_cell; 99, argument_list; 99, 100; 100, identifier:adata; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:is; 102, 103; 102, 104; 103, identifier:n_top_genes; 104, None; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:filter_genes_dispersion; 109, argument_list; 109, 110; 109, 111; 109, 114; 110, identifier:adata; 111, keyword_argument; 111, 112; 111, 113; 112, identifier:n_top_genes; 113, identifier:n_top_genes; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:flavor; 116, identifier:flavor; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:log_advised; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:np; 123, identifier:allclose; 124, argument_list; 124, 125; 124, 136; 125, call; 125, 126; 125, 135; 126, attribute; 126, 127; 126, 134; 127, subscript; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:adata; 130, identifier:X; 131, slice; 131, 132; 131, 133; 132, colon; 133, integer:10; 134, identifier:sum; 135, argument_list; 136, call; 136, 137; 136, 148; 137, attribute; 137, 138; 137, 147; 138, subscript; 138, 139; 138, 144; 139, subscript; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:adata; 142, identifier:layers; 143, string:'spliced'; 144, slice; 144, 145; 144, 146; 145, colon; 146, integer:10; 147, identifier:sum; 148, argument_list; 149, if_statement; 149, 150; 149, 153; 150, boolean_operator:and; 150, 151; 150, 152; 151, identifier:log; 152, identifier:log_advised; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:log1p; 157, argument_list; 157, 158; 158, identifier:adata; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:logg; 163, identifier:info; 164, argument_list; 164, 165; 165, conditional_expression:if; 165, 166; 165, 167; 165, 170; 166, string:'Logarithmized X.'; 167, boolean_operator:and; 167, 168; 167, 169; 168, identifier:log; 169, identifier:log_advised; 170, conditional_expression:if; 170, 171; 170, 172; 170, 173; 171, string:'Did not modify X as it looks preprocessed already.'; 172, identifier:log; 173, conditional_expression:if; 173, 174; 173, 175; 173, 176; 174, string:'Consider logarithmizing X with `scv.pp.log1p` for better results.'; 175, identifier:log_advised; 176, string:''; 177, return_statement; 177, 178; 178, conditional_expression:if; 178, 179; 178, 180; 178, 181; 179, identifier:adata; 180, identifier:copy; 181, None
def filter_and_normalize(data, min_counts=None, min_counts_u=None, min_cells=None, min_cells_u=None, min_shared_counts=None, min_shared_cells=None, n_top_genes=None, flavor='seurat', log=True, copy=False): adata = data.copy() if copy else data if 'spliced' not in adata.layers.keys() or 'unspliced' not in adata.layers.keys(): raise ValueError('Could not find spliced / unspliced counts.') filter_genes(adata, min_counts=min_counts, min_counts_u=min_counts_u, min_cells=min_cells, min_cells_u=min_cells_u, min_shared_counts=min_shared_counts, min_shared_cells=min_shared_cells,) normalize_per_cell(adata) if n_top_genes is not None: filter_genes_dispersion(adata, n_top_genes=n_top_genes, flavor=flavor) log_advised = np.allclose(adata.X[:10].sum(), adata.layers['spliced'][:10].sum()) if log and log_advised: log1p(adata) logg.info('Logarithmized X.' if log and log_advised else 'Did not modify X as it looks preprocessed already.' if log else 'Consider logarithmizing X with `scv.pp.log1p` for better results.' if log_advised else '') return adata if copy else None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:merge; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:adata; 5, identifier:ldata; 6, default_parameter; 6, 7; 6, 8; 7, identifier:copy; 8, True; 9, block; 9, 10; 9, 62; 9, 75; 9, 88; 9, 119; 9, 199; 9, 229; 9, 254; 9, 276; 9, 298; 9, 320; 9, 342; 9, 439; 10, if_statement; 10, 11; 10, 30; 10, 36; 11, boolean_operator:and; 11, 12; 11, 21; 12, comparison_operator:in; 12, 13; 12, 14; 13, string:'spliced'; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:ldata; 18, identifier:layers; 19, identifier:keys; 20, argument_list; 21, comparison_operator:not; 21, 22; 21, 23; 22, string:'initial_size_spliced'; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:ldata; 27, identifier:obs; 28, identifier:keys; 29, argument_list; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:set_initial_size; 34, argument_list; 34, 35; 35, identifier:ldata; 36, elif_clause; 36, 37; 36, 56; 37, boolean_operator:and; 37, 38; 37, 47; 38, comparison_operator:in; 38, 39; 38, 40; 39, string:'spliced'; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:adata; 44, identifier:layers; 45, identifier:keys; 46, argument_list; 47, comparison_operator:not; 47, 48; 47, 49; 48, string:'initial_size_spliced'; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:adata; 53, identifier:obs; 54, identifier:keys; 55, argument_list; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:set_initial_size; 60, argument_list; 60, 61; 61, identifier:adata; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:common_obs; 65, call; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:adata; 69, identifier:obs_names; 70, identifier:intersection; 71, argument_list; 71, 72; 72, attribute; 72, 73; 72, 74; 73, identifier:ldata; 74, identifier:obs_names; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:common_vars; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:adata; 82, identifier:var_names; 83, identifier:intersection; 84, argument_list; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:ldata; 87, identifier:var_names; 88, if_statement; 88, 89; 88, 95; 89, comparison_operator:==; 89, 90; 89, 94; 90, call; 90, 91; 90, 92; 91, identifier:len; 92, argument_list; 92, 93; 93, identifier:common_obs; 94, integer:0; 95, block; 95, 96; 95, 101; 95, 106; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:clean_obs_names; 99, argument_list; 99, 100; 100, identifier:adata; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:clean_obs_names; 104, argument_list; 104, 105; 105, identifier:ldata; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:common_obs; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:adata; 113, identifier:obs_names; 114, identifier:intersection; 115, argument_list; 115, 116; 116, attribute; 116, 117; 116, 118; 117, identifier:ldata; 118, identifier:obs_names; 119, if_statement; 119, 120; 119, 121; 119, 180; 120, identifier:copy; 121, block; 121, 122; 121, 151; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:_adata; 125, conditional_expression:if; 125, 126; 125, 133; 125, 144; 126, call; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:adata; 130, identifier:common_obs; 131, identifier:copy; 132, argument_list; 133, comparison_operator:>=; 133, 134; 133, 139; 134, subscript; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:adata; 137, identifier:shape; 138, integer:1; 139, subscript; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:ldata; 142, identifier:shape; 143, integer:1; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:ldata; 148, identifier:common_obs; 149, identifier:copy; 150, argument_list; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:_ldata; 154, conditional_expression:if; 154, 155; 154, 162; 154, 173; 155, call; 155, 156; 155, 161; 156, attribute; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:ldata; 159, identifier:common_obs; 160, identifier:copy; 161, argument_list; 162, comparison_operator:>=; 162, 163; 162, 168; 163, subscript; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:adata; 166, identifier:shape; 167, integer:1; 168, subscript; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:ldata; 171, identifier:shape; 172, integer:1; 173, call; 173, 174; 173, 179; 174, attribute; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:adata; 177, identifier:common_obs; 178, identifier:copy; 179, argument_list; 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:adata; 186, identifier:_inplace_subset_obs; 187, argument_list; 187, 188; 188, identifier:common_obs; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, pattern_list; 191, 192; 191, 193; 192, identifier:_adata; 193, identifier:_ldata; 194, expression_list; 194, 195; 194, 196; 195, identifier:adata; 196, subscript; 196, 197; 196, 198; 197, identifier:ldata; 198, identifier:common_obs; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:same_vars; 202, parenthesized_expression; 202, 203; 203, boolean_operator:and; 203, 204; 203, 217; 204, comparison_operator:==; 204, 205; 204, 211; 205, call; 205, 206; 205, 207; 206, identifier:len; 207, argument_list; 207, 208; 208, attribute; 208, 209; 208, 210; 209, identifier:_adata; 210, identifier:var_names; 211, call; 211, 212; 211, 213; 212, identifier:len; 213, argument_list; 213, 214; 214, attribute; 214, 215; 214, 216; 215, identifier:_ldata; 216, identifier:var_names; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:np; 220, identifier:all; 221, argument_list; 221, 222; 222, comparison_operator:==; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:_adata; 225, identifier:var_names; 226, attribute; 226, 227; 226, 228; 227, identifier:_ldata; 228, identifier:var_names; 229, if_statement; 229, 230; 229, 239; 230, boolean_operator:and; 230, 231; 230, 237; 231, comparison_operator:>; 231, 232; 231, 236; 232, call; 232, 233; 232, 234; 233, identifier:len; 234, argument_list; 234, 235; 235, identifier:common_vars; 236, integer:0; 237, not_operator; 237, 238; 238, identifier:same_vars; 239, block; 239, 240; 239, 247; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:_adata; 244, identifier:_inplace_subset_var; 245, argument_list; 245, 246; 246, identifier:common_vars; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:_ldata; 251, identifier:_inplace_subset_var; 252, argument_list; 252, 253; 253, identifier:common_vars; 254, for_statement; 254, 255; 254, 256; 254, 263; 255, identifier:attr; 256, call; 256, 257; 256, 262; 257, attribute; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:_ldata; 260, identifier:obs; 261, identifier:keys; 262, argument_list; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 271; 266, subscript; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:_adata; 269, identifier:obs; 270, identifier:attr; 271, subscript; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:_ldata; 274, identifier:obs; 275, identifier:attr; 276, for_statement; 276, 277; 276, 278; 276, 285; 277, identifier:attr; 278, call; 278, 279; 278, 284; 279, attribute; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:_ldata; 282, identifier:obsm; 283, identifier:keys; 284, argument_list; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 293; 288, subscript; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:_adata; 291, identifier:obsm; 292, identifier:attr; 293, subscript; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:_ldata; 296, identifier:obsm; 297, identifier:attr; 298, for_statement; 298, 299; 298, 300; 298, 307; 299, identifier:attr; 300, call; 300, 301; 300, 306; 301, attribute; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:_ldata; 304, identifier:uns; 305, identifier:keys; 306, argument_list; 307, block; 307, 308; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 315; 310, subscript; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:_adata; 313, identifier:uns; 314, identifier:attr; 315, subscript; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:_ldata; 318, identifier:uns; 319, identifier:attr; 320, for_statement; 320, 321; 320, 322; 320, 329; 321, identifier:attr; 322, call; 322, 323; 322, 328; 323, attribute; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:_ldata; 326, identifier:layers; 327, identifier:keys; 328, argument_list; 329, block; 329, 330; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 337; 332, subscript; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:_adata; 335, identifier:layers; 336, identifier:attr; 337, subscript; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:_ldata; 340, identifier:layers; 341, identifier:attr; 342, if_statement; 342, 343; 342, 354; 343, comparison_operator:==; 343, 344; 343, 349; 344, subscript; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:_adata; 347, identifier:shape; 348, integer:1; 349, subscript; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:_ldata; 352, identifier:shape; 353, integer:1; 354, block; 354, 355; 354, 385; 355, expression_statement; 355, 356; 356, assignment; 356, 357; 356, 358; 357, identifier:same_vars; 358, parenthesized_expression; 358, 359; 359, boolean_operator:and; 359, 360; 359, 373; 360, comparison_operator:==; 360, 361; 360, 367; 361, call; 361, 362; 361, 363; 362, identifier:len; 363, argument_list; 363, 364; 364, attribute; 364, 365; 364, 366; 365, identifier:_adata; 366, identifier:var_names; 367, call; 367, 368; 367, 369; 368, identifier:len; 369, argument_list; 369, 370; 370, attribute; 370, 371; 370, 372; 371, identifier:_ldata; 372, identifier:var_names; 373, call; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, identifier:np; 376, identifier:all; 377, argument_list; 377, 378; 378, comparison_operator:==; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:_adata; 381, identifier:var_names; 382, attribute; 382, 383; 382, 384; 383, identifier:_ldata; 384, identifier:var_names; 385, if_statement; 385, 386; 385, 387; 385, 432; 386, identifier:same_vars; 387, block; 387, 388; 387, 410; 388, for_statement; 388, 389; 388, 390; 388, 397; 389, identifier:attr; 390, call; 390, 391; 390, 396; 391, attribute; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:_ldata; 394, identifier:var; 395, identifier:keys; 396, argument_list; 397, block; 397, 398; 398, expression_statement; 398, 399; 399, assignment; 399, 400; 399, 405; 400, subscript; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:_adata; 403, identifier:var; 404, identifier:attr; 405, subscript; 405, 406; 405, 409; 406, attribute; 406, 407; 406, 408; 407, identifier:_ldata; 408, identifier:var; 409, identifier:attr; 410, for_statement; 410, 411; 410, 412; 410, 419; 411, identifier:attr; 412, call; 412, 413; 412, 418; 413, attribute; 413, 414; 413, 417; 414, attribute; 414, 415; 414, 416; 415, identifier:_ldata; 416, identifier:varm; 417, identifier:keys; 418, argument_list; 419, block; 419, 420; 420, expression_statement; 420, 421; 421, assignment; 421, 422; 421, 427; 422, subscript; 422, 423; 422, 426; 423, attribute; 423, 424; 423, 425; 424, identifier:_adata; 425, identifier:varm; 426, identifier:attr; 427, subscript; 427, 428; 427, 431; 428, attribute; 428, 429; 428, 430; 429, identifier:_ldata; 430, identifier:varm; 431, identifier:attr; 432, else_clause; 432, 433; 433, block; 433, 434; 434, raise_statement; 434, 435; 435, call; 435, 436; 435, 437; 436, identifier:ValueError; 437, argument_list; 437, 438; 438, string:'Variable names are not identical.'; 439, return_statement; 439, 440; 440, conditional_expression:if; 440, 441; 440, 442; 440, 443; 441, identifier:_adata; 442, identifier:copy; 443, None
def merge(adata, ldata, copy=True): if 'spliced' in ldata.layers.keys() and 'initial_size_spliced' not in ldata.obs.keys(): set_initial_size(ldata) elif 'spliced' in adata.layers.keys() and 'initial_size_spliced' not in adata.obs.keys(): set_initial_size(adata) common_obs = adata.obs_names.intersection(ldata.obs_names) common_vars = adata.var_names.intersection(ldata.var_names) if len(common_obs) == 0: clean_obs_names(adata) clean_obs_names(ldata) common_obs = adata.obs_names.intersection(ldata.obs_names) if copy: _adata = adata[common_obs].copy() if adata.shape[1] >= ldata.shape[1] else ldata[common_obs].copy() _ldata = ldata[common_obs].copy() if adata.shape[1] >= ldata.shape[1] else adata[common_obs].copy() else: adata._inplace_subset_obs(common_obs) _adata, _ldata = adata, ldata[common_obs] same_vars = (len(_adata.var_names) == len(_ldata.var_names) and np.all(_adata.var_names == _ldata.var_names)) if len(common_vars) > 0 and not same_vars: _adata._inplace_subset_var(common_vars) _ldata._inplace_subset_var(common_vars) for attr in _ldata.obs.keys(): _adata.obs[attr] = _ldata.obs[attr] for attr in _ldata.obsm.keys(): _adata.obsm[attr] = _ldata.obsm[attr] for attr in _ldata.uns.keys(): _adata.uns[attr] = _ldata.uns[attr] for attr in _ldata.layers.keys(): _adata.layers[attr] = _ldata.layers[attr] if _adata.shape[1] == _ldata.shape[1]: same_vars = (len(_adata.var_names) == len(_ldata.var_names) and np.all(_adata.var_names == _ldata.var_names)) if same_vars: for attr in _ldata.var.keys(): _adata.var[attr] = _ldata.var[attr] for attr in _ldata.varm.keys(): _adata.varm[attr] = _ldata.varm[attr] else: raise ValueError('Variable names are not identical.') return _adata if copy else None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:cell_fate; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:groupby; 7, string:'clusters'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:disconnected_groups; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:self_transitions; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:n_neighbors; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:copy; 19, False; 20, block; 20, 21; 20, 32; 20, 42; 20, 51; 20, 59; 20, 75; 20, 81; 20, 91; 20, 101; 20, 111; 20, 122; 20, 135; 20, 147; 20, 167; 20, 197; 20, 205; 20, 225; 20, 230; 20, 250; 20, 260; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:adata; 24, conditional_expression:if; 24, 25; 24, 30; 24, 31; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:data; 28, identifier:copy; 29, argument_list; 30, identifier:copy; 31, identifier:data; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:logg; 36, identifier:info; 37, argument_list; 37, 38; 37, 39; 38, string:'computing cell fates'; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:r; 41, True; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:n_neighbors; 45, conditional_expression:if; 45, 46; 45, 47; 45, 50; 46, integer:10; 47, comparison_operator:is; 47, 48; 47, 49; 48, identifier:n_neighbors; 49, None; 50, identifier:n_neighbors; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:_adata; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:adata; 57, identifier:copy; 58, argument_list; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:vgraph; 62, call; 62, 63; 62, 64; 63, identifier:VelocityGraph; 64, argument_list; 64, 65; 64, 66; 64, 69; 64, 72; 65, identifier:_adata; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:n_neighbors; 68, identifier:n_neighbors; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:approx; 71, True; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:n_recurse_neighbors; 74, integer:1; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:vgraph; 79, identifier:compute_cosines; 80, argument_list; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 88; 83, subscript; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:_adata; 86, identifier:uns; 87, string:'velocity_graph'; 88, attribute; 88, 89; 88, 90; 89, identifier:vgraph; 90, identifier:graph; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 98; 93, subscript; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:_adata; 96, identifier:uns; 97, string:'velocity_graph_neg'; 98, attribute; 98, 99; 98, 100; 99, identifier:vgraph; 100, identifier:graph_neg; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:T; 104, call; 104, 105; 104, 106; 105, identifier:transition_matrix; 106, argument_list; 106, 107; 106, 108; 107, identifier:_adata; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:self_transitions; 110, identifier:self_transitions; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:I; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:np; 117, identifier:eye; 118, argument_list; 118, 119; 119, attribute; 119, 120; 119, 121; 120, identifier:_adata; 121, identifier:n_obs; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:fate; 125, call; 125, 126; 125, 131; 126, attribute; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:np; 129, identifier:linalg; 130, identifier:inv; 131, argument_list; 131, 132; 132, binary_operator:-; 132, 133; 132, 134; 133, identifier:I; 134, identifier:T; 135, if_statement; 135, 136; 135, 140; 136, call; 136, 137; 136, 138; 137, identifier:issparse; 138, argument_list; 138, 139; 139, identifier:T; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:fate; 144, attribute; 144, 145; 144, 146; 145, identifier:fate; 146, identifier:A; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:cell_fates; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:np; 153, identifier:array; 154, argument_list; 154, 155; 155, subscript; 155, 156; 155, 161; 156, subscript; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:_adata; 159, identifier:obs; 160, identifier:groupby; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:fate; 164, identifier:argmax; 165, argument_list; 165, 166; 166, integer:1; 167, if_statement; 167, 168; 167, 171; 168, comparison_operator:is; 168, 169; 168, 170; 169, identifier:disconnected_groups; 170, None; 171, block; 171, 172; 171, 185; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:idx; 175, call; 175, 176; 175, 183; 176, attribute; 176, 177; 176, 182; 177, subscript; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:_adata; 180, identifier:obs; 181, identifier:groupby; 182, identifier:isin; 183, argument_list; 183, 184; 184, identifier:disconnected_groups; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:cell_fates; 189, identifier:idx; 190, subscript; 190, 191; 190, 196; 191, subscript; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:_adata; 194, identifier:obs; 195, identifier:groupby; 196, identifier:idx; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 204; 199, subscript; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:adata; 202, identifier:obs; 203, string:'cell_fate'; 204, identifier:cell_fates; 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:adata; 210, identifier:obs; 211, string:'cell_fate_confidence'; 212, binary_operator:/; 212, 213; 212, 219; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:fate; 216, identifier:max; 217, argument_list; 217, 218; 218, integer:1; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:fate; 222, identifier:sum; 223, argument_list; 223, 224; 224, integer:1; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 228; 227, identifier:strings_to_categoricals; 228, argument_list; 228, 229; 229, identifier:adata; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:logg; 234, identifier:info; 235, argument_list; 235, 236; 235, 237; 235, 240; 236, string:' finished'; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:time; 239, True; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:end; 242, conditional_expression:if; 242, 243; 242, 244; 242, 249; 243, string:' '; 244, comparison_operator:>; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:settings; 247, identifier:verbosity; 248, integer:2; 249, string:'\n'; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:logg; 254, identifier:hint; 255, argument_list; 255, 256; 256, concatenated_string; 256, 257; 256, 258; 256, 259; 257, string:'added\n'; 258, string:' \'cell_fate\', most likely cell fate (adata.obs)\n'; 259, string:' \'cell_fate_confidence\', confidence of transitioning to the assigned fate (adata.obs)'; 260, return_statement; 260, 261; 261, conditional_expression:if; 261, 262; 261, 263; 261, 264; 262, identifier:adata; 263, identifier:copy; 264, None
def cell_fate(data, groupby='clusters', disconnected_groups=None, self_transitions=False, n_neighbors=None, copy=False): adata = data.copy() if copy else data logg.info('computing cell fates', r=True) n_neighbors = 10 if n_neighbors is None else n_neighbors _adata = adata.copy() vgraph = VelocityGraph(_adata, n_neighbors=n_neighbors, approx=True, n_recurse_neighbors=1) vgraph.compute_cosines() _adata.uns['velocity_graph'] = vgraph.graph _adata.uns['velocity_graph_neg'] = vgraph.graph_neg T = transition_matrix(_adata, self_transitions=self_transitions) I = np.eye(_adata.n_obs) fate = np.linalg.inv(I - T) if issparse(T): fate = fate.A cell_fates = np.array(_adata.obs[groupby][fate.argmax(1)]) if disconnected_groups is not None: idx = _adata.obs[groupby].isin(disconnected_groups) cell_fates[idx] = _adata.obs[groupby][idx] adata.obs['cell_fate'] = cell_fates adata.obs['cell_fate_confidence'] = fate.max(1) / fate.sum(1) strings_to_categoricals(adata) logg.info(' finished', time=True, end=' ' if settings.verbosity > 2 else '\n') logg.hint( 'added\n' ' \'cell_fate\', most likely cell fate (adata.obs)\n' ' \'cell_fate_confidence\', confidence of transitioning to the assigned fate (adata.obs)') return adata if copy else None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:moments; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:n_neighbors; 7, integer:30; 8, default_parameter; 8, 9; 8, 10; 9, identifier:n_pcs; 10, integer:30; 11, default_parameter; 11, 12; 11, 13; 12, identifier:mode; 13, string:'connectivities'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:method; 16, string:'umap'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:metric; 19, string:'euclidean'; 20, default_parameter; 20, 21; 20, 22; 21, identifier:use_rep; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:recurse_neighbors; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:renormalize; 28, False; 29, default_parameter; 29, 30; 29, 31; 30, identifier:copy; 31, False; 32, block; 32, 33; 32, 44; 32, 70; 32, 94; 32, 142; 32, 156; 32, 171; 32, 185; 32, 215; 32, 245; 32, 261; 32, 281; 32, 290; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:adata; 36, conditional_expression:if; 36, 37; 36, 42; 36, 43; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:data; 40, identifier:copy; 41, argument_list; 42, identifier:copy; 43, identifier:data; 44, if_statement; 44, 45; 44, 64; 45, boolean_operator:or; 45, 46; 45, 55; 46, comparison_operator:not; 46, 47; 46, 48; 47, string:'spliced'; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:adata; 52, identifier:layers; 53, identifier:keys; 54, argument_list; 55, comparison_operator:not; 55, 56; 55, 57; 56, string:'unspliced'; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:adata; 61, identifier:layers; 62, identifier:keys; 63, argument_list; 64, block; 64, 65; 65, raise_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:ValueError; 68, argument_list; 68, 69; 69, string:'Could not find spliced / unspliced counts.'; 70, if_statement; 70, 71; 70, 88; 71, call; 71, 72; 71, 73; 72, identifier:any; 73, argument_list; 73, 74; 74, list_comprehension; 74, 75; 74, 83; 75, call; 75, 76; 75, 77; 76, identifier:not_yet_normalized; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:adata; 81, identifier:layers; 82, identifier:layer; 83, for_in_clause; 83, 84; 83, 85; 84, identifier:layer; 85, set; 85, 86; 85, 87; 86, string:'spliced'; 87, string:'unspliced'; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:normalize_per_cell; 92, argument_list; 92, 93; 93, identifier:adata; 94, if_statement; 94, 95; 94, 112; 95, boolean_operator:or; 95, 96; 95, 105; 96, comparison_operator:not; 96, 97; 96, 98; 97, string:'neighbors'; 98, call; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:adata; 102, identifier:uns; 103, identifier:keys; 104, argument_list; 105, call; 105, 106; 105, 107; 106, identifier:neighbors_to_be_recomputed; 107, argument_list; 107, 108; 107, 109; 108, identifier:adata; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:n_neighbors; 111, identifier:n_neighbors; 112, block; 112, 113; 112, 122; 113, if_statement; 113, 114; 113, 117; 114, comparison_operator:is; 114, 115; 114, 116; 115, identifier:use_rep; 116, None; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:use_rep; 121, string:'X_pca'; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:neighbors; 125, argument_list; 125, 126; 125, 127; 125, 130; 125, 133; 125, 136; 125, 139; 126, identifier:adata; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:n_neighbors; 129, identifier:n_neighbors; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:use_rep; 132, identifier:use_rep; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:n_pcs; 135, identifier:n_pcs; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:method; 138, identifier:method; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:metric; 141, identifier:metric; 142, if_statement; 142, 143; 142, 150; 143, comparison_operator:not; 143, 144; 143, 145; 144, identifier:mode; 145, subscript; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:adata; 148, identifier:uns; 149, string:'neighbors'; 150, block; 150, 151; 151, raise_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:ValueError; 154, argument_list; 154, 155; 155, string:'mode can only be \'connectivities\' or \'distances\''; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:logg; 160, identifier:info; 161, argument_list; 161, 162; 161, 168; 162, binary_operator:+; 162, 163; 162, 164; 163, string:'computing moments based on '; 164, call; 164, 165; 164, 166; 165, identifier:str; 166, argument_list; 166, 167; 167, identifier:mode; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:r; 170, True; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:connectivities; 174, call; 174, 175; 174, 176; 175, identifier:get_connectivities; 176, argument_list; 176, 177; 176, 178; 176, 179; 176, 182; 177, identifier:adata; 178, identifier:mode; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:n_neighbors; 181, identifier:n_neighbors; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:recurse_neighbors; 184, identifier:recurse_neighbors; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 192; 187, subscript; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:adata; 190, identifier:layers; 191, string:'Ms'; 192, attribute; 192, 193; 192, 214; 193, call; 193, 194; 193, 210; 194, attribute; 194, 195; 194, 209; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:csr_matrix; 198, identifier:dot; 199, argument_list; 199, 200; 199, 201; 200, identifier:connectivities; 201, call; 201, 202; 201, 203; 202, identifier:csr_matrix; 203, argument_list; 203, 204; 204, subscript; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:adata; 207, identifier:layers; 208, string:'spliced'; 209, identifier:astype; 210, argument_list; 210, 211; 211, attribute; 211, 212; 211, 213; 212, identifier:np; 213, identifier:float32; 214, identifier:A; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 222; 217, subscript; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:adata; 220, identifier:layers; 221, string:'Mu'; 222, attribute; 222, 223; 222, 244; 223, call; 223, 224; 223, 240; 224, attribute; 224, 225; 224, 239; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:csr_matrix; 228, identifier:dot; 229, argument_list; 229, 230; 229, 231; 230, identifier:connectivities; 231, call; 231, 232; 231, 233; 232, identifier:csr_matrix; 233, argument_list; 233, 234; 234, subscript; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:adata; 237, identifier:layers; 238, string:'unspliced'; 239, identifier:astype; 240, argument_list; 240, 241; 241, attribute; 241, 242; 241, 243; 242, identifier:np; 243, identifier:float32; 244, identifier:A; 245, if_statement; 245, 246; 245, 247; 246, identifier:renormalize; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 251; 250, identifier:normalize_per_cell; 251, argument_list; 251, 252; 251, 253; 251, 258; 252, identifier:adata; 253, keyword_argument; 253, 254; 253, 255; 254, identifier:layers; 255, set; 255, 256; 255, 257; 256, string:'Ms'; 257, string:'Mu'; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:enforce; 260, True; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:logg; 265, identifier:info; 266, argument_list; 266, 267; 266, 268; 266, 271; 267, string:' finished'; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:time; 270, True; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:end; 273, conditional_expression:if; 273, 274; 273, 275; 273, 280; 274, string:' '; 275, comparison_operator:>; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:settings; 278, identifier:verbosity; 279, integer:2; 280, string:'\n'; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:logg; 285, identifier:hint; 286, argument_list; 286, 287; 287, concatenated_string; 287, 288; 287, 289; 288, string:'added \n'; 289, string:' \'Ms\' and \'Mu\', moments of spliced/unspliced abundances (adata.layers)'; 290, return_statement; 290, 291; 291, conditional_expression:if; 291, 292; 291, 293; 291, 294; 292, identifier:adata; 293, identifier:copy; 294, None
def moments(data, n_neighbors=30, n_pcs=30, mode='connectivities', method='umap', metric='euclidean', use_rep=None, recurse_neighbors=False, renormalize=False, copy=False): adata = data.copy() if copy else data if 'spliced' not in adata.layers.keys() or 'unspliced' not in adata.layers.keys(): raise ValueError('Could not find spliced / unspliced counts.') if any([not_yet_normalized(adata.layers[layer]) for layer in {'spliced', 'unspliced'}]): normalize_per_cell(adata) if 'neighbors' not in adata.uns.keys() or neighbors_to_be_recomputed(adata, n_neighbors=n_neighbors): if use_rep is None: use_rep = 'X_pca' neighbors(adata, n_neighbors=n_neighbors, use_rep=use_rep, n_pcs=n_pcs, method=method, metric=metric) if mode not in adata.uns['neighbors']: raise ValueError('mode can only be \'connectivities\' or \'distances\'') logg.info('computing moments based on ' + str(mode), r=True) connectivities = get_connectivities(adata, mode, n_neighbors=n_neighbors, recurse_neighbors=recurse_neighbors) adata.layers['Ms'] = csr_matrix.dot(connectivities, csr_matrix(adata.layers['spliced'])).astype(np.float32).A adata.layers['Mu'] = csr_matrix.dot(connectivities, csr_matrix(adata.layers['unspliced'])).astype(np.float32).A if renormalize: normalize_per_cell(adata, layers={'Ms', 'Mu'}, enforce=True) logg.info(' finished', time=True, end=' ' if settings.verbosity > 2 else '\n') logg.hint( 'added \n' ' \'Ms\' and \'Mu\', moments of spliced/unspliced abundances (adata.layers)') return adata if copy else None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 41; 2, function_name:transition_matrix; 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:adata; 5, default_parameter; 5, 6; 5, 7; 6, identifier:vkey; 7, string:'velocity'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:basis; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:backward; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:self_transitions; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:scale; 19, integer:10; 20, default_parameter; 20, 21; 20, 22; 21, identifier:perc; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:use_negative_cosines; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:weight_diffusion; 28, integer:0; 29, default_parameter; 29, 30; 29, 31; 30, identifier:scale_diffusion; 31, integer:1; 32, default_parameter; 32, 33; 32, 34; 33, identifier:weight_indirect_neighbors; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:n_neighbors; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:vgraph; 40, None; 41, block; 41, 42; 41, 56; 41, 82; 41, 130; 41, 141; 41, 198; 41, 258; 41, 267; 41, 274; 41, 300; 41, 335; 41, 475; 42, if_statement; 42, 43; 42, 50; 43, comparison_operator:not; 43, 44; 43, 47; 44, binary_operator:+; 44, 45; 44, 46; 45, identifier:vkey; 46, string:'_graph'; 47, attribute; 47, 48; 47, 49; 48, identifier:adata; 49, identifier:uns; 50, block; 50, 51; 51, raise_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:ValueError; 54, argument_list; 54, 55; 55, string:'You need to run `tl.velocity_graph` first to compute cosine correlations.'; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:graph; 59, conditional_expression:if; 59, 60; 59, 74; 59, 77; 60, call; 60, 61; 60, 73; 61, attribute; 61, 62; 61, 72; 62, call; 62, 63; 62, 64; 63, identifier:csr_matrix; 64, argument_list; 64, 65; 65, subscript; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:adata; 68, identifier:uns; 69, binary_operator:+; 69, 70; 69, 71; 70, identifier:vkey; 71, string:'_graph'; 72, identifier:copy; 73, argument_list; 74, comparison_operator:is; 74, 75; 74, 76; 75, identifier:vgraph; 76, None; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:vgraph; 80, identifier:copy; 81, argument_list; 82, if_statement; 82, 83; 82, 84; 83, identifier:self_transitions; 84, block; 84, 85; 84, 100; 84, 110; 84, 123; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:confidence; 88, call; 88, 89; 88, 99; 89, attribute; 89, 90; 89, 98; 90, attribute; 90, 91; 90, 97; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:graph; 94, identifier:max; 95, argument_list; 95, 96; 96, integer:1; 97, identifier:A; 98, identifier:flatten; 99, argument_list; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:ub; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:np; 106, identifier:percentile; 107, argument_list; 107, 108; 107, 109; 108, identifier:confidence; 109, integer:98; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:self_prob; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:np; 116, identifier:clip; 117, argument_list; 117, 118; 117, 121; 117, 122; 118, binary_operator:-; 118, 119; 118, 120; 119, identifier:ub; 120, identifier:confidence; 121, integer:0; 122, integer:1; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:graph; 127, identifier:setdiag; 128, argument_list; 128, 129; 129, identifier:self_prob; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:T; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:np; 136, identifier:expm1; 137, argument_list; 137, 138; 138, binary_operator:*; 138, 139; 138, 140; 139, identifier:graph; 140, identifier:scale; 141, if_statement; 141, 142; 141, 153; 142, comparison_operator:in; 142, 143; 142, 146; 143, binary_operator:+; 143, 144; 143, 145; 144, identifier:vkey; 145, string:'_graph_neg'; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:adata; 150, identifier:uns; 151, identifier:keys; 152, argument_list; 153, block; 153, 154; 153, 164; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:graph_neg; 157, subscript; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:adata; 160, identifier:uns; 161, binary_operator:+; 161, 162; 161, 163; 162, identifier:vkey; 163, string:'_graph_neg'; 164, if_statement; 164, 165; 164, 166; 164, 179; 165, identifier:use_negative_cosines; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, augmented_assignment:-=; 168, 169; 168, 170; 169, identifier:T; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:np; 173, identifier:expm1; 174, argument_list; 174, 175; 175, binary_operator:*; 175, 176; 175, 178; 176, unary_operator:-; 176, 177; 177, identifier:graph_neg; 178, identifier:scale; 179, else_clause; 179, 180; 180, block; 180, 181; 180, 192; 181, expression_statement; 181, 182; 182, augmented_assignment:+=; 182, 183; 182, 184; 183, identifier:T; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:np; 187, identifier:expm1; 188, argument_list; 188, 189; 189, binary_operator:*; 189, 190; 189, 191; 190, identifier:graph_neg; 191, identifier:scale; 192, expression_statement; 192, 193; 193, augmented_assignment:+=; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:T; 196, identifier:data; 197, integer:1; 198, if_statement; 198, 199; 198, 216; 199, boolean_operator:and; 199, 200; 199, 213; 200, boolean_operator:and; 200, 201; 200, 210; 201, comparison_operator:in; 201, 202; 201, 203; 202, string:'neighbors'; 203, call; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:adata; 207, identifier:uns; 208, identifier:keys; 209, argument_list; 210, comparison_operator:is; 210, 211; 210, 212; 211, identifier:weight_indirect_neighbors; 212, None; 213, comparison_operator:<; 213, 214; 213, 215; 214, identifier:weight_indirect_neighbors; 215, integer:1; 216, block; 216, 217; 216, 229; 216, 236; 216, 240; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:direct_neighbors; 220, comparison_operator:>; 220, 221; 220, 228; 221, subscript; 221, 222; 221, 227; 222, subscript; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:adata; 225, identifier:uns; 226, string:'neighbors'; 227, string:'distances'; 228, integer:0; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:direct_neighbors; 233, identifier:setdiag; 234, argument_list; 234, 235; 235, integer:1; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:w; 239, identifier:weight_indirect_neighbors; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:T; 243, binary_operator:+; 243, 244; 243, 247; 244, binary_operator:*; 244, 245; 244, 246; 245, identifier:w; 246, identifier:T; 247, binary_operator:*; 247, 248; 247, 252; 248, parenthesized_expression; 248, 249; 249, binary_operator:-; 249, 250; 249, 251; 250, integer:1; 251, identifier:w; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:direct_neighbors; 255, identifier:multiply; 256, argument_list; 256, 257; 257, identifier:T; 258, if_statement; 258, 259; 258, 260; 259, identifier:backward; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:T; 264, attribute; 264, 265; 264, 266; 265, identifier:T; 266, identifier:T; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:T; 270, call; 270, 271; 270, 272; 271, identifier:normalize; 272, argument_list; 272, 273; 273, identifier:T; 274, if_statement; 274, 275; 274, 278; 275, comparison_operator:is; 275, 276; 275, 277; 276, identifier:n_neighbors; 277, None; 278, block; 278, 279; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:T; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:T; 285, identifier:multiply; 286, argument_list; 286, 287; 287, call; 287, 288; 287, 289; 288, identifier:get_connectivities; 289, argument_list; 289, 290; 289, 291; 289, 294; 289, 297; 290, identifier:adata; 291, keyword_argument; 291, 292; 291, 293; 292, identifier:mode; 293, string:'distances'; 294, keyword_argument; 294, 295; 294, 296; 295, identifier:n_neighbors; 296, identifier:n_neighbors; 297, keyword_argument; 297, 298; 297, 299; 298, identifier:recurse_neighbors; 299, True; 300, if_statement; 300, 301; 300, 304; 301, comparison_operator:is; 301, 302; 301, 303; 302, identifier:perc; 303, None; 304, block; 304, 305; 304, 317; 304, 329; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 308; 307, identifier:threshold; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:np; 311, identifier:percentile; 312, argument_list; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:T; 315, identifier:data; 316, identifier:perc; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 328; 319, subscript; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:T; 322, identifier:data; 323, comparison_operator:<; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:T; 326, identifier:data; 327, identifier:threshold; 328, integer:0; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:T; 333, identifier:eliminate_zeros; 334, argument_list; 335, if_statement; 335, 336; 335, 350; 336, comparison_operator:in; 336, 337; 336, 343; 337, binary_operator:+; 337, 338; 337, 339; 338, string:'X_'; 339, call; 339, 340; 339, 341; 340, identifier:str; 341, argument_list; 341, 342; 342, identifier:basis; 343, call; 343, 344; 343, 349; 344, attribute; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:adata; 347, identifier:obsm; 348, identifier:keys; 349, argument_list; 350, block; 350, 351; 350, 375; 350, 385; 350, 393; 350, 415; 350, 424; 350, 468; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 354; 353, identifier:dists_emb; 354, call; 354, 355; 354, 361; 355, attribute; 355, 356; 355, 360; 356, parenthesized_expression; 356, 357; 357, comparison_operator:>; 357, 358; 357, 359; 358, identifier:T; 359, integer:0; 360, identifier:multiply; 361, argument_list; 361, 362; 362, call; 362, 363; 362, 364; 363, identifier:squareform; 364, argument_list; 364, 365; 365, call; 365, 366; 365, 367; 366, identifier:pdist; 367, argument_list; 367, 368; 368, subscript; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:adata; 371, identifier:obsm; 372, binary_operator:+; 372, 373; 372, 374; 373, string:'X_'; 374, identifier:basis; 375, expression_statement; 375, 376; 376, augmented_assignment:*=; 376, 377; 376, 378; 377, identifier:scale_diffusion; 378, call; 378, 379; 378, 384; 379, attribute; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:dists_emb; 382, identifier:data; 383, identifier:mean; 384, argument_list; 385, expression_statement; 385, 386; 386, assignment; 386, 387; 386, 388; 387, identifier:diffusion_kernel; 388, call; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:dists_emb; 391, identifier:copy; 392, argument_list; 393, expression_statement; 393, 394; 394, assignment; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:diffusion_kernel; 397, identifier:data; 398, call; 398, 399; 398, 402; 399, attribute; 399, 400; 399, 401; 400, identifier:np; 401, identifier:exp; 402, argument_list; 402, 403; 403, binary_operator:/; 403, 404; 403, 412; 404, binary_operator:*; 404, 405; 404, 407; 405, unary_operator:-; 405, 406; 406, float:.5; 407, binary_operator:**; 407, 408; 407, 411; 408, attribute; 408, 409; 408, 410; 409, identifier:dists_emb; 410, identifier:data; 411, integer:2; 412, binary_operator:**; 412, 413; 412, 414; 413, identifier:scale_diffusion; 414, integer:2; 415, expression_statement; 415, 416; 416, assignment; 416, 417; 416, 418; 417, identifier:T; 418, call; 418, 419; 418, 422; 419, attribute; 419, 420; 419, 421; 420, identifier:T; 421, identifier:multiply; 422, argument_list; 422, 423; 423, identifier:diffusion_kernel; 424, if_statement; 424, 425; 424, 429; 425, comparison_operator:<; 425, 426; 425, 427; 425, 428; 426, integer:0; 427, identifier:weight_diffusion; 428, integer:1; 429, block; 429, 430; 429, 455; 430, expression_statement; 430, 431; 431, assignment; 431, 432; 431, 435; 432, attribute; 432, 433; 432, 434; 433, identifier:diffusion_kernel; 434, identifier:data; 435, call; 435, 436; 435, 439; 436, attribute; 436, 437; 436, 438; 437, identifier:np; 438, identifier:exp; 439, argument_list; 439, 440; 440, binary_operator:/; 440, 441; 440, 449; 441, binary_operator:*; 441, 442; 441, 444; 442, unary_operator:-; 442, 443; 443, float:.5; 444, binary_operator:**; 444, 445; 444, 448; 445, attribute; 445, 446; 445, 447; 446, identifier:dists_emb; 447, identifier:data; 448, integer:2; 449, binary_operator:**; 449, 450; 449, 454; 450, parenthesized_expression; 450, 451; 451, binary_operator:/; 451, 452; 451, 453; 452, identifier:scale_diffusion; 453, integer:2; 454, integer:2; 455, expression_statement; 455, 456; 456, assignment; 456, 457; 456, 458; 457, identifier:T; 458, binary_operator:+; 458, 459; 458, 465; 459, binary_operator:*; 459, 460; 459, 464; 460, parenthesized_expression; 460, 461; 461, binary_operator:-; 461, 462; 461, 463; 462, integer:1; 463, identifier:weight_diffusion; 464, identifier:T; 465, binary_operator:*; 465, 466; 465, 467; 466, identifier:weight_diffusion; 467, identifier:diffusion_kernel; 468, expression_statement; 468, 469; 469, assignment; 469, 470; 469, 471; 470, identifier:T; 471, call; 471, 472; 471, 473; 472, identifier:normalize; 473, argument_list; 473, 474; 474, identifier:T; 475, return_statement; 475, 476; 476, identifier:T
def transition_matrix(adata, vkey='velocity', basis=None, backward=False, self_transitions=True, scale=10, perc=None, use_negative_cosines=False, weight_diffusion=0, scale_diffusion=1, weight_indirect_neighbors=None, n_neighbors=None, vgraph=None): if vkey+'_graph' not in adata.uns: raise ValueError('You need to run `tl.velocity_graph` first to compute cosine correlations.') graph = csr_matrix(adata.uns[vkey + '_graph']).copy() if vgraph is None else vgraph.copy() if self_transitions: confidence = graph.max(1).A.flatten() ub = np.percentile(confidence, 98) self_prob = np.clip(ub - confidence, 0, 1) graph.setdiag(self_prob) T = np.expm1(graph * scale) if vkey + '_graph_neg' in adata.uns.keys(): graph_neg = adata.uns[vkey + '_graph_neg'] if use_negative_cosines: T -= np.expm1(-graph_neg * scale) else: T += np.expm1(graph_neg * scale) T.data += 1 if 'neighbors' in adata.uns.keys() and weight_indirect_neighbors is not None and weight_indirect_neighbors < 1: direct_neighbors = adata.uns['neighbors']['distances'] > 0 direct_neighbors.setdiag(1) w = weight_indirect_neighbors T = w * T + (1-w) * direct_neighbors.multiply(T) if backward: T = T.T T = normalize(T) if n_neighbors is not None: T = T.multiply(get_connectivities(adata, mode='distances', n_neighbors=n_neighbors, recurse_neighbors=True)) if perc is not None: threshold = np.percentile(T.data, perc) T.data[T.data < threshold] = 0 T.eliminate_zeros() if 'X_' + str(basis) in adata.obsm.keys(): dists_emb = (T > 0).multiply(squareform(pdist(adata.obsm['X_' + basis]))) scale_diffusion *= dists_emb.data.mean() diffusion_kernel = dists_emb.copy() diffusion_kernel.data = np.exp(-.5 * dists_emb.data ** 2 / scale_diffusion ** 2) T = T.multiply(diffusion_kernel) if 0 < weight_diffusion < 1: diffusion_kernel.data = np.exp(-.5 * dists_emb.data ** 2 / (scale_diffusion/2) ** 2) T = (1-weight_diffusion) * T + weight_diffusion * diffusion_kernel T = normalize(T) return T
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:update_holder; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:holder; 6, block; 6, 7; 6, 15; 6, 176; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:subject_symbol; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:subject; 14, identifier:symbol; 15, if_statement; 15, 16; 15, 21; 15, 152; 16, comparison_operator:in; 16, 17; 16, 18; 17, identifier:subject_symbol; 18, attribute; 18, 19; 18, 20; 19, identifier:holder; 20, identifier:state; 21, block; 21, 22; 21, 138; 22, if_statement; 22, 23; 22, 31; 22, 46; 22, 99; 23, not_operator; 23, 24; 24, subscript; 24, 25; 24, 30; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:holder; 28, identifier:state; 29, identifier:subject_symbol; 30, string:'quantity'; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 41; 34, subscript; 34, 35; 34, 40; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:holder; 38, identifier:state; 39, identifier:subject_symbol; 40, string:'value'; 41, subscript; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:details; 45, string:'value'; 46, elif_clause; 46, 47; 46, 62; 47, call; 47, 48; 47, 49; 48, identifier:same_sign; 49, argument_list; 49, 50; 49, 57; 50, subscript; 50, 51; 50, 56; 51, subscript; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:holder; 54, identifier:state; 55, identifier:subject_symbol; 56, string:'quantity'; 57, subscript; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:details; 61, string:'quantity'; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 72; 65, subscript; 65, 66; 65, 71; 66, subscript; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:holder; 69, identifier:state; 70, identifier:subject_symbol; 71, string:'value'; 72, call; 72, 73; 72, 74; 73, identifier:average_price; 74, argument_list; 74, 75; 74, 82; 74, 89; 74, 94; 75, subscript; 75, 76; 75, 81; 76, subscript; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:holder; 79, identifier:state; 80, identifier:subject_symbol; 81, string:'quantity'; 82, subscript; 82, 83; 82, 88; 83, subscript; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:holder; 86, identifier:state; 87, identifier:subject_symbol; 88, string:'value'; 89, subscript; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:details; 93, string:'quantity'; 94, subscript; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:details; 98, string:'value'; 99, else_clause; 99, 100; 100, block; 100, 101; 101, if_statement; 101, 102; 101, 123; 102, call; 102, 103; 102, 104; 103, identifier:same_sign; 104, argument_list; 104, 105; 104, 110; 105, subscript; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:details; 109, string:'quantity'; 110, binary_operator:+; 110, 111; 110, 118; 111, subscript; 111, 112; 111, 117; 112, subscript; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:holder; 115, identifier:state; 116, identifier:subject_symbol; 117, string:'quantity'; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:details; 122, string:'quantity'; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 133; 126, subscript; 126, 127; 126, 132; 127, subscript; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:holder; 130, identifier:state; 131, identifier:subject_symbol; 132, string:'value'; 133, subscript; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:details; 137, string:'value'; 138, expression_statement; 138, 139; 139, augmented_assignment:+=; 139, 140; 139, 147; 140, subscript; 140, 141; 140, 146; 141, subscript; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:holder; 144, identifier:state; 145, identifier:subject_symbol; 146, string:'quantity'; 147, subscript; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:details; 151, string:'quantity'; 152, else_clause; 152, 153; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 161; 156, subscript; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:holder; 159, identifier:state; 160, identifier:subject_symbol; 161, dictionary; 161, 162; 161, 169; 162, pair; 162, 163; 162, 164; 163, string:'quantity'; 164, subscript; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:details; 168, string:'quantity'; 169, pair; 169, 170; 169, 171; 170, string:'value'; 171, subscript; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:details; 175, string:'value'; 176, if_statement; 176, 177; 176, 185; 177, not_operator; 177, 178; 178, subscript; 178, 179; 178, 184; 179, subscript; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:holder; 182, identifier:state; 183, identifier:subject_symbol; 184, string:'quantity'; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 195; 188, subscript; 188, 189; 188, 194; 189, subscript; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:holder; 192, identifier:state; 193, identifier:subject_symbol; 194, string:'value'; 195, integer:0
def update_holder(self, holder): subject_symbol = self.subject.symbol if subject_symbol in holder.state: if not holder.state[subject_symbol]['quantity']: holder.state[subject_symbol]['value'] = self.details['value'] elif same_sign( holder.state[subject_symbol]['quantity'], self.details['quantity']): holder.state[subject_symbol]['value'] = average_price( holder.state[subject_symbol]['quantity'], holder.state[subject_symbol]['value'], self.details['quantity'], self.details['value'] ) else: if same_sign( self.details['quantity'], holder.state[subject_symbol]['quantity'] + self.details['quantity']): holder.state[subject_symbol]['value'] = self.details['value'] holder.state[subject_symbol]['quantity'] += self.details['quantity'] else: holder.state[subject_symbol] = { 'quantity': self.details['quantity'], 'value': self.details['value'] } if not holder.state[subject_symbol]['quantity']: holder.state[subject_symbol]['value'] = 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:addImagingColumns; 3, parameters; 3, 4; 3, 5; 4, identifier:msname; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ack; 7, True; 8, block; 8, 9; 8, 14; 8, 27; 8, 35; 8, 53; 8, 57; 8, 89; 8, 109; 8, 160; 8, 211; 8, 331; 8, 349; 8, 364; 8, 373; 8, 383; 8, 397; 8, 407; 9, import_statement; 9, 10; 10, aliased_import; 10, 11; 10, 13; 11, dotted_name; 11, 12; 12, identifier:numpy; 13, identifier:np; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:t; 17, call; 17, 18; 17, 19; 18, identifier:table; 19, argument_list; 19, 20; 19, 21; 19, 24; 20, identifier:msname; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:readonly; 23, False; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:ack; 26, False; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:cnames; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:t; 33, identifier:colnames; 34, argument_list; 35, try_statement; 35, 36; 35, 46; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:cdesc; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:t; 43, identifier:getcoldesc; 44, argument_list; 44, 45; 45, string:'DATA'; 46, except_clause; 46, 47; 47, block; 47, 48; 48, raise_statement; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:ValueError; 51, argument_list; 51, 52; 52, string:'Column DATA does not exist'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:hasTiled; 56, False; 57, try_statement; 57, 58; 57, 83; 58, block; 58, 59; 58, 68; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:dminfo; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:t; 65, identifier:getdminfo; 66, argument_list; 66, 67; 67, string:"DATA"; 68, if_statement; 68, 69; 68, 78; 69, comparison_operator:==; 69, 70; 69, 77; 70, subscript; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:dminfo; 73, string:'TYPE'; 74, slice; 74, 75; 74, 76; 75, colon; 76, integer:5; 77, string:'Tiled'; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:hasTiled; 82, True; 83, except_clause; 83, 84; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:hasTiled; 88, False; 89, if_statement; 89, 90; 89, 92; 90, not_operator; 90, 91; 91, identifier:hasTiled; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:dminfo; 96, dictionary; 96, 97; 96, 100; 97, pair; 97, 98; 97, 99; 98, string:'TYPE'; 99, string:'TiledShapeStMan'; 100, pair; 100, 101; 100, 102; 101, string:'SPEC'; 102, dictionary; 102, 103; 103, pair; 103, 104; 103, 105; 104, string:'DEFAULTTILESHAPE'; 105, list:[4, 32, 128]; 105, 106; 105, 107; 105, 108; 106, integer:4; 107, integer:32; 108, integer:128; 109, if_statement; 109, 110; 109, 113; 109, 121; 110, comparison_operator:in; 110, 111; 110, 112; 111, string:'MODEL_DATA'; 112, identifier:cnames; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:six; 118, identifier:print_; 119, argument_list; 119, 120; 120, string:"Column MODEL_DATA not added; it already exists"; 121, else_clause; 121, 122; 122, block; 122, 123; 122, 129; 122, 135; 122, 150; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:dminfo; 127, string:'NAME'; 128, string:'modeldata'; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:cdesc; 133, string:'comment'; 134, string:'The model data column'; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:t; 139, identifier:addcols; 140, argument_list; 140, 141; 140, 149; 141, call; 141, 142; 141, 143; 142, identifier:maketabdesc; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:makecoldesc; 146, argument_list; 146, 147; 146, 148; 147, string:'MODEL_DATA'; 148, identifier:cdesc; 149, identifier:dminfo; 150, if_statement; 150, 151; 150, 152; 151, identifier:ack; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:six; 157, identifier:print_; 158, argument_list; 158, 159; 159, string:"added column MODEL_DATA"; 160, if_statement; 160, 161; 160, 164; 160, 172; 161, comparison_operator:in; 161, 162; 161, 163; 162, string:'CORRECTED_DATA'; 163, identifier:cnames; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:six; 169, identifier:print_; 170, argument_list; 170, 171; 171, string:"Column CORRECTED_DATA not added; it already exists"; 172, else_clause; 172, 173; 173, block; 173, 174; 173, 180; 173, 186; 173, 201; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:dminfo; 178, string:'NAME'; 179, string:'correcteddata'; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:cdesc; 184, string:'comment'; 185, string:'The corrected data column'; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:t; 190, identifier:addcols; 191, argument_list; 191, 192; 191, 200; 192, call; 192, 193; 192, 194; 193, identifier:maketabdesc; 194, argument_list; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:makecoldesc; 197, argument_list; 197, 198; 197, 199; 198, string:'CORRECTED_DATA'; 199, identifier:cdesc; 200, identifier:dminfo; 201, if_statement; 201, 202; 201, 203; 202, identifier:ack; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:six; 208, identifier:print_; 209, argument_list; 209, 210; 210, string:"'added column CORRECTED_DATA"; 211, if_statement; 211, 212; 211, 215; 211, 223; 212, comparison_operator:in; 212, 213; 212, 214; 213, string:'IMAGING_WEIGHT'; 214, identifier:cnames; 215, block; 215, 216; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:six; 220, identifier:print_; 221, argument_list; 221, 222; 222, string:"Column IMAGING_WEIGHT not added; it already exists"; 223, else_clause; 223, 224; 224, block; 224, 225; 224, 229; 224, 240; 224, 272; 224, 289; 224, 304; 224, 310; 224, 321; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:shp; 228, list:[]; 229, if_statement; 229, 230; 229, 233; 230, comparison_operator:in; 230, 231; 230, 232; 231, string:'shape'; 232, identifier:cdesc; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:shp; 237, subscript; 237, 238; 237, 239; 238, identifier:cdesc; 239, string:'shape'; 240, if_statement; 240, 241; 240, 247; 240, 255; 241, comparison_operator:>; 241, 242; 241, 246; 242, call; 242, 243; 242, 244; 243, identifier:len; 244, argument_list; 244, 245; 245, identifier:shp; 246, integer:0; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:shp; 251, list:[shp[0]]; 251, 252; 252, subscript; 252, 253; 252, 254; 253, identifier:shp; 254, integer:0; 255, else_clause; 255, 256; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:shp; 260, list:[t.getcell('DATA', 0).shape[0]]; 260, 261; 261, subscript; 261, 262; 261, 271; 262, attribute; 262, 263; 262, 270; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:t; 266, identifier:getcell; 267, argument_list; 267, 268; 267, 269; 268, string:'DATA'; 269, integer:0; 270, identifier:shape; 271, integer:0; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:cd; 275, call; 275, 276; 275, 277; 276, identifier:makearrcoldesc; 277, argument_list; 277, 278; 277, 279; 277, 280; 277, 283; 277, 286; 278, string:'IMAGING_WEIGHT'; 279, integer:0; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:ndim; 282, integer:1; 283, keyword_argument; 283, 284; 283, 285; 284, identifier:shape; 285, identifier:shp; 286, keyword_argument; 286, 287; 286, 288; 287, identifier:valuetype; 288, string:'float'; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:dminfo; 292, dictionary; 292, 293; 292, 296; 293, pair; 293, 294; 293, 295; 294, string:'TYPE'; 295, string:'TiledShapeStMan'; 296, pair; 296, 297; 296, 298; 297, string:'SPEC'; 298, dictionary; 298, 299; 299, pair; 299, 300; 299, 301; 300, string:'DEFAULTTILESHAPE'; 301, list:[32, 128]; 301, 302; 301, 303; 302, integer:32; 303, integer:128; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 309; 306, subscript; 306, 307; 306, 308; 307, identifier:dminfo; 308, string:'NAME'; 309, string:'imagingweight'; 310, expression_statement; 310, 311; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:t; 314, identifier:addcols; 315, argument_list; 315, 316; 315, 320; 316, call; 316, 317; 316, 318; 317, identifier:maketabdesc; 318, argument_list; 318, 319; 319, identifier:cd; 320, identifier:dminfo; 321, if_statement; 321, 322; 321, 323; 322, identifier:ack; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:six; 328, identifier:print_; 329, argument_list; 329, 330; 330, string:"added column IMAGING_WEIGHT"; 331, if_statement; 331, 332; 331, 340; 332, comparison_operator:in; 332, 333; 332, 334; 333, string:'CHANNEL_SELECTION'; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:t; 337, identifier:colkeywordnames; 338, argument_list; 338, 339; 339, string:'MODEL_DATA'; 340, block; 340, 341; 341, expression_statement; 341, 342; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:t; 345, identifier:removecolkeyword; 346, argument_list; 346, 347; 346, 348; 347, string:'MODEL_DATA'; 348, string:'CHANNEL_SELECTION'; 349, expression_statement; 349, 350; 350, assignment; 350, 351; 350, 352; 351, identifier:tspw; 352, call; 352, 353; 352, 354; 353, identifier:table; 354, argument_list; 354, 355; 354, 361; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:t; 358, identifier:getkeyword; 359, argument_list; 359, 360; 360, string:'SPECTRAL_WINDOW'; 361, keyword_argument; 361, 362; 361, 363; 362, identifier:ack; 363, False; 364, expression_statement; 364, 365; 365, assignment; 365, 366; 365, 367; 366, identifier:nchans; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:tspw; 370, identifier:getcol; 371, argument_list; 371, 372; 372, string:'NUM_CHAN'; 373, expression_statement; 373, 374; 374, assignment; 374, 375; 374, 376; 375, identifier:chans; 376, list_comprehension; 376, 377; 376, 380; 377, list:[0, nch]; 377, 378; 377, 379; 378, integer:0; 379, identifier:nch; 380, for_in_clause; 380, 381; 380, 382; 381, identifier:nch; 382, identifier:nchans; 383, expression_statement; 383, 384; 384, call; 384, 385; 384, 388; 385, attribute; 385, 386; 385, 387; 386, identifier:t; 387, identifier:putcolkeyword; 388, argument_list; 388, 389; 388, 390; 388, 391; 389, string:'MODEL_DATA'; 390, string:'CHANNEL_SELECTION'; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:np; 394, identifier:int32; 395, argument_list; 395, 396; 396, identifier:chans; 397, if_statement; 397, 398; 397, 399; 398, identifier:ack; 399, block; 399, 400; 400, expression_statement; 400, 401; 401, call; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:six; 404, identifier:print_; 405, argument_list; 405, 406; 406, string:"defined keyword CHANNEL_SELECTION in column MODEL_DATA"; 407, expression_statement; 407, 408; 408, call; 408, 409; 408, 412; 409, attribute; 409, 410; 409, 411; 410, identifier:t; 411, identifier:flush; 412, argument_list
def addImagingColumns(msname, ack=True): import numpy as np t = table(msname, readonly=False, ack=False) cnames = t.colnames() try: cdesc = t.getcoldesc('DATA') except: raise ValueError('Column DATA does not exist') hasTiled = False try: dminfo = t.getdminfo("DATA") if dminfo['TYPE'][:5] == 'Tiled': hasTiled = True except: hasTiled = False if not hasTiled: dminfo = {'TYPE': 'TiledShapeStMan', 'SPEC': {'DEFAULTTILESHAPE': [4, 32, 128]}} if 'MODEL_DATA' in cnames: six.print_("Column MODEL_DATA not added; it already exists") else: dminfo['NAME'] = 'modeldata' cdesc['comment'] = 'The model data column' t.addcols(maketabdesc(makecoldesc('MODEL_DATA', cdesc)), dminfo) if ack: six.print_("added column MODEL_DATA") if 'CORRECTED_DATA' in cnames: six.print_("Column CORRECTED_DATA not added; it already exists") else: dminfo['NAME'] = 'correcteddata' cdesc['comment'] = 'The corrected data column' t.addcols(maketabdesc(makecoldesc('CORRECTED_DATA', cdesc)), dminfo) if ack: six.print_("'added column CORRECTED_DATA") if 'IMAGING_WEIGHT' in cnames: six.print_("Column IMAGING_WEIGHT not added; it already exists") else: shp = [] if 'shape' in cdesc: shp = cdesc['shape'] if len(shp) > 0: shp = [shp[0]] else: shp = [t.getcell('DATA', 0).shape[0]] cd = makearrcoldesc('IMAGING_WEIGHT', 0, ndim=1, shape=shp, valuetype='float') dminfo = {'TYPE': 'TiledShapeStMan', 'SPEC': {'DEFAULTTILESHAPE': [32, 128]}} dminfo['NAME'] = 'imagingweight' t.addcols(maketabdesc(cd), dminfo) if ack: six.print_("added column IMAGING_WEIGHT") if 'CHANNEL_SELECTION' in t.colkeywordnames('MODEL_DATA'): t.removecolkeyword('MODEL_DATA', 'CHANNEL_SELECTION') tspw = table(t.getkeyword('SPECTRAL_WINDOW'), ack=False) nchans = tspw.getcol('NUM_CHAN') chans = [[0, nch] for nch in nchans] t.putcolkeyword('MODEL_DATA', 'CHANNEL_SELECTION', np.int32(chans)) if ack: six.print_("defined keyword CHANNEL_SELECTION in column MODEL_DATA") t.flush()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:msregularize; 3, parameters; 3, 4; 3, 5; 4, identifier:msname; 5, identifier:newname; 6, block; 6, 7; 6, 14; 6, 23; 6, 27; 6, 252; 6, 307; 6, 314; 6, 322; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:t; 10, call; 10, 11; 10, 12; 11, identifier:table; 12, argument_list; 12, 13; 13, identifier:msname; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:t1; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:t; 20, identifier:sort; 21, argument_list; 21, 22; 22, string:'unique ANTENNA1,ANTENNA2'; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:nadded; 26, integer:0; 27, for_statement; 27, 28; 27, 29; 27, 37; 28, identifier:tsub; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:t; 32, identifier:iter; 33, argument_list; 33, 34; 34, list:['TIME', 'DATA_DESC_ID']; 34, 35; 34, 36; 35, string:'TIME'; 36, string:'DATA_DESC_ID'; 37, block; 37, 38; 37, 52; 37, 62; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:nmissing; 41, binary_operator:-; 41, 42; 41, 47; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:t1; 45, identifier:nrows; 46, argument_list; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:tsub; 50, identifier:nrows; 51, argument_list; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:<; 53, 54; 53, 55; 54, identifier:nmissing; 55, integer:0; 56, block; 56, 57; 57, raise_statement; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:ValueError; 60, argument_list; 60, 61; 61, string:"A time/band chunk has too many rows"; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:>; 63, 64; 63, 65; 64, identifier:nmissing; 65, integer:0; 66, block; 66, 67; 66, 85; 66, 103; 66, 112; 66, 121; 66, 130; 66, 152; 66, 166; 66, 206; 66, 227; 66, 248; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:ant1; 70, call; 70, 71; 70, 82; 71, attribute; 71, 72; 71, 81; 72, call; 72, 73; 72, 74; 73, identifier:str; 74, argument_list; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:t1; 78, identifier:getcol; 79, argument_list; 79, 80; 80, string:'ANTENNA1'; 81, identifier:replace; 82, argument_list; 82, 83; 82, 84; 83, string:' '; 84, string:','; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:ant2; 88, call; 88, 89; 88, 100; 89, attribute; 89, 90; 89, 99; 90, call; 90, 91; 90, 92; 91, identifier:str; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:t1; 96, identifier:getcol; 97, argument_list; 97, 98; 98, string:'ANTENNA2'; 99, identifier:replace; 100, argument_list; 100, 101; 100, 102; 101, string:' '; 102, string:','; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:ant1; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:tsub; 109, identifier:getcol; 110, argument_list; 110, 111; 111, string:'ANTENNA1'; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:ant2; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:tsub; 118, identifier:getcol; 119, argument_list; 119, 120; 120, string:'ANTENNA2'; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:t2; 124, call; 124, 125; 124, 126; 125, identifier:taql; 126, argument_list; 126, 127; 127, binary_operator:+; 127, 128; 127, 129; 128, string:'select from $t1 where !any(ANTENNA1 == $ant1 &&'; 129, string:' ANTENNA2 == $ant2)'; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:six; 134, identifier:print_; 135, argument_list; 135, 136; 135, 137; 135, 142; 135, 147; 136, identifier:nmissing; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:t1; 140, identifier:nrows; 141, argument_list; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:tsub; 145, identifier:nrows; 146, argument_list; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:t2; 150, identifier:nrows; 151, argument_list; 152, if_statement; 152, 153; 152, 160; 153, comparison_operator:!=; 153, 154; 153, 159; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:t2; 157, identifier:nrows; 158, argument_list; 159, identifier:nmissing; 160, block; 160, 161; 161, raise_statement; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:ValueError; 164, argument_list; 164, 165; 165, string:"A time/band chunk behaves strangely"; 166, if_statement; 166, 167; 166, 170; 166, 197; 167, comparison_operator:==; 167, 168; 167, 169; 168, identifier:nadded; 169, integer:0; 170, block; 170, 171; 170, 185; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:tnew; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:t2; 177, identifier:copy; 178, argument_list; 178, 179; 178, 182; 179, binary_operator:+; 179, 180; 179, 181; 180, identifier:newname; 181, string:"_add"; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:deep; 184, True; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:tnew; 188, call; 188, 189; 188, 190; 189, identifier:table; 190, argument_list; 190, 191; 190, 194; 191, binary_operator:+; 191, 192; 191, 193; 192, identifier:newname; 193, string:"_add"; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:readonly; 196, False; 197, else_clause; 197, 198; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:t2; 203, identifier:copyrows; 204, argument_list; 204, 205; 205, identifier:tnew; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:tnew; 210, identifier:putcell; 211, argument_list; 211, 212; 211, 213; 211, 220; 212, string:'TIME'; 213, call; 213, 214; 213, 215; 214, identifier:range; 215, argument_list; 215, 216; 215, 217; 216, identifier:nadded; 217, binary_operator:+; 217, 218; 217, 219; 218, identifier:nadded; 219, identifier:nmissing; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:tsub; 223, identifier:getcell; 224, argument_list; 224, 225; 224, 226; 225, string:'TIME'; 226, integer:0; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:tnew; 231, identifier:putcell; 232, argument_list; 232, 233; 232, 234; 232, 241; 233, string:'DATA_DESC_ID'; 234, call; 234, 235; 234, 236; 235, identifier:range; 236, argument_list; 236, 237; 236, 238; 237, identifier:nadded; 238, binary_operator:+; 238, 239; 238, 240; 239, identifier:nadded; 240, identifier:nmissing; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:tsub; 244, identifier:getcell; 245, argument_list; 245, 246; 245, 247; 246, string:'DATA_DESC_ID'; 247, integer:0; 248, expression_statement; 248, 249; 249, augmented_assignment:+=; 249, 250; 249, 251; 250, identifier:nadded; 251, identifier:nmissing; 252, if_statement; 252, 253; 252, 256; 252, 294; 253, comparison_operator:>; 253, 254; 253, 255; 254, identifier:nadded; 255, integer:0; 256, block; 256, 257; 256, 262; 256, 267; 256, 276; 256, 285; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 260; 259, identifier:taql; 260, argument_list; 260, 261; 261, string:'update $tnew set DATA=0+0i'; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 265; 264, identifier:taql; 265, argument_list; 265, 266; 266, string:'update $tnew set FLAG=True'; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:tcomb; 270, call; 270, 271; 270, 272; 271, identifier:table; 272, argument_list; 272, 273; 273, list:[t, tnew]; 273, 274; 273, 275; 274, identifier:t; 275, identifier:tnew; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:tcomb; 280, identifier:rename; 281, argument_list; 281, 282; 282, binary_operator:+; 282, 283; 282, 284; 283, identifier:newname; 284, string:'_adds'; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:tcombs; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:tcomb; 291, identifier:sort; 292, argument_list; 292, 293; 293, string:'TIME,DATA_DESC_ID,ANTENNA1,ANTENNA2'; 294, else_clause; 294, 295; 295, block; 295, 296; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:tcombs; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:t; 302, identifier:query; 303, argument_list; 303, 304; 304, keyword_argument; 304, 305; 304, 306; 305, identifier:offset; 306, integer:0; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:tcombs; 311, identifier:rename; 312, argument_list; 312, 313; 313, identifier:newname; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:six; 318, identifier:print_; 319, argument_list; 319, 320; 319, 321; 320, identifier:newname; 321, string:'has been created; it references the original MS'; 322, if_statement; 322, 323; 322, 326; 322, 340; 323, comparison_operator:>; 323, 324; 323, 325; 324, identifier:nadded; 325, integer:0; 326, block; 326, 327; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:six; 331, identifier:print_; 332, argument_list; 332, 333; 332, 334; 332, 337; 332, 338; 332, 339; 333, string:' and'; 334, binary_operator:+; 334, 335; 334, 336; 335, identifier:newname; 336, string:'_adds'; 337, string:'containing'; 338, identifier:nadded; 339, string:'new rows'; 340, else_clause; 340, 341; 341, block; 341, 342; 342, expression_statement; 342, 343; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:six; 346, identifier:print_; 347, argument_list; 347, 348; 348, string:' no rows needed to be added'
def msregularize(msname, newname): t = table(msname) t1 = t.sort('unique ANTENNA1,ANTENNA2') nadded = 0 for tsub in t.iter(['TIME', 'DATA_DESC_ID']): nmissing = t1.nrows() - tsub.nrows() if nmissing < 0: raise ValueError("A time/band chunk has too many rows") if nmissing > 0: ant1 = str(t1.getcol('ANTENNA1')).replace(' ', ',') ant2 = str(t1.getcol('ANTENNA2')).replace(' ', ',') ant1 = tsub.getcol('ANTENNA1') ant2 = tsub.getcol('ANTENNA2') t2 = taql('select from $t1 where !any(ANTENNA1 == $ant1 &&' + ' ANTENNA2 == $ant2)') six.print_(nmissing, t1.nrows(), tsub.nrows(), t2.nrows()) if t2.nrows() != nmissing: raise ValueError("A time/band chunk behaves strangely") if nadded == 0: tnew = t2.copy(newname + "_add", deep=True) tnew = table(newname + "_add", readonly=False) else: t2.copyrows(tnew) tnew.putcell('TIME', range(nadded, nadded + nmissing), tsub.getcell('TIME', 0)) tnew.putcell('DATA_DESC_ID', range(nadded, nadded + nmissing), tsub.getcell('DATA_DESC_ID', 0)) nadded += nmissing if nadded > 0: taql('update $tnew set DATA=0+0i') taql('update $tnew set FLAG=True') tcomb = table([t, tnew]) tcomb.rename(newname + '_adds') tcombs = tcomb.sort('TIME,DATA_DESC_ID,ANTENNA1,ANTENNA2') else: tcombs = t.query(offset=0) tcombs.rename(newname) six.print_(newname, 'has been created; it references the original MS') if nadded > 0: six.print_(' and', newname + '_adds', 'containing', nadded, 'new rows') else: six.print_(' no rows needed to be added')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 43; 2, function_name:tablefromascii; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 34; 3, 37; 3, 40; 4, identifier:tablename; 5, identifier:asciifile; 6, default_parameter; 6, 7; 6, 8; 7, identifier:headerfile; 8, string:''; 9, default_parameter; 9, 10; 9, 11; 10, identifier:autoheader; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:autoshape; 14, list:[]; 15, default_parameter; 15, 16; 15, 17; 16, identifier:columnnames; 17, list:[]; 18, default_parameter; 18, 19; 18, 20; 19, identifier:datatypes; 20, list:[]; 21, default_parameter; 21, 22; 21, 23; 22, identifier:sep; 23, string:' '; 24, default_parameter; 24, 25; 24, 26; 25, identifier:commentmarker; 26, string:''; 27, default_parameter; 27, 28; 27, 29; 28, identifier:firstline; 29, integer:1; 30, default_parameter; 30, 31; 30, 32; 31, identifier:lastline; 32, unary_operator:-; 32, 33; 33, integer:1; 34, default_parameter; 34, 35; 34, 36; 35, identifier:readonly; 36, True; 37, default_parameter; 37, 38; 37, 39; 38, identifier:lockoptions; 39, string:'default'; 40, default_parameter; 40, 41; 40, 42; 41, identifier:ack; 42, True; 43, block; 43, 44; 43, 48; 43, 59; 43, 70; 43, 93; 43, 143; 43, 167; 43, 182; 43, 186; 44, import_statement; 44, 45; 45, dotted_name; 45, 46; 45, 47; 46, identifier:os; 47, identifier:path; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:filename; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:os; 55, identifier:path; 56, identifier:expandvars; 57, argument_list; 57, 58; 58, identifier:asciifile; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:filename; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:os; 66, identifier:path; 67, identifier:expanduser; 68, argument_list; 68, 69; 69, identifier:filename; 70, if_statement; 70, 71; 70, 80; 71, not_operator; 71, 72; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:os; 76, identifier:path; 77, identifier:exists; 78, argument_list; 78, 79; 79, identifier:filename; 80, block; 80, 81; 80, 88; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:s; 84, binary_operator:%; 84, 85; 84, 86; 85, string:"File '%s' not found"; 86, parenthesized_expression; 86, 87; 87, identifier:filename; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:IOError; 91, argument_list; 91, 92; 92, identifier:s; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:!=; 94, 95; 94, 96; 95, identifier:headerfile; 96, string:''; 97, block; 97, 98; 97, 109; 97, 120; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:filename; 101, call; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:os; 105, identifier:path; 106, identifier:expandvars; 107, argument_list; 107, 108; 108, identifier:headerfile; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:filename; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:os; 116, identifier:path; 117, identifier:expanduser; 118, argument_list; 118, 119; 119, identifier:filename; 120, if_statement; 120, 121; 120, 130; 121, not_operator; 121, 122; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:os; 126, identifier:path; 127, identifier:exists; 128, argument_list; 128, 129; 129, identifier:filename; 130, block; 130, 131; 130, 138; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:s; 134, binary_operator:%; 134, 135; 134, 136; 135, string:"File '%s' not found"; 136, parenthesized_expression; 136, 137; 137, identifier:filename; 138, raise_statement; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:IOError; 141, argument_list; 141, 142; 142, identifier:s; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:tab; 146, call; 146, 147; 146, 148; 147, identifier:table; 148, argument_list; 148, 149; 148, 150; 148, 151; 148, 152; 148, 153; 148, 154; 148, 155; 148, 156; 148, 157; 148, 158; 148, 161; 148, 164; 149, identifier:asciifile; 150, identifier:headerfile; 151, identifier:tablename; 152, identifier:autoheader; 153, identifier:autoshape; 154, identifier:sep; 155, identifier:commentmarker; 156, identifier:firstline; 157, identifier:lastline; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:_columnnames; 160, identifier:columnnames; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:_datatypes; 163, identifier:datatypes; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:_oper; 166, integer:1; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:six; 171, identifier:print_; 172, argument_list; 172, 173; 173, binary_operator:+; 173, 174; 173, 181; 174, binary_operator:+; 174, 175; 174, 176; 175, string:'Input format: ['; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:tab; 179, identifier:_getasciiformat; 180, argument_list; 181, string:']'; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:tab; 185, integer:0; 186, return_statement; 186, 187; 187, call; 187, 188; 187, 189; 188, identifier:table; 189, argument_list; 189, 190; 189, 191; 189, 194; 189, 197; 190, identifier:tablename; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:readonly; 193, identifier:readonly; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:lockoptions; 196, identifier:lockoptions; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:ack; 199, identifier:ack
def tablefromascii(tablename, asciifile, headerfile='', autoheader=False, autoshape=[], columnnames=[], datatypes=[], sep=' ', commentmarker='', firstline=1, lastline=-1, readonly=True, lockoptions='default', ack=True): import os.path filename = os.path.expandvars(asciifile) filename = os.path.expanduser(filename) if not os.path.exists(filename): s = "File '%s' not found" % (filename) raise IOError(s) if headerfile != '': filename = os.path.expandvars(headerfile) filename = os.path.expanduser(filename) if not os.path.exists(filename): s = "File '%s' not found" % (filename) raise IOError(s) tab = table(asciifile, headerfile, tablename, autoheader, autoshape, sep, commentmarker, firstline, lastline, _columnnames=columnnames, _datatypes=datatypes, _oper=1) six.print_('Input format: [' + tab._getasciiformat() + ']') tab = 0 return table(tablename, readonly=readonly, lockoptions=lockoptions, ack=ack)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:makescacoldesc; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 4, identifier:columnname; 5, identifier:value; 6, default_parameter; 6, 7; 6, 8; 7, identifier:datamanagertype; 8, string:''; 9, default_parameter; 9, 10; 9, 11; 10, identifier:datamanagergroup; 11, string:''; 12, default_parameter; 12, 13; 12, 14; 13, identifier:options; 14, integer:0; 15, default_parameter; 15, 16; 15, 17; 16, identifier:maxlen; 17, integer:0; 18, default_parameter; 18, 19; 18, 20; 19, identifier:comment; 20, string:''; 21, default_parameter; 21, 22; 21, 23; 22, identifier:valuetype; 23, string:''; 24, default_parameter; 24, 25; 24, 26; 25, identifier:keywords; 26, dictionary; 27, block; 27, 28; 27, 32; 27, 44; 27, 69; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:vtype; 31, identifier:valuetype; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:==; 33, 34; 33, 35; 34, identifier:vtype; 35, string:''; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:vtype; 40, call; 40, 41; 40, 42; 41, identifier:_value_type_name; 42, argument_list; 42, 43; 43, identifier:value; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:rec2; 47, dictionary; 47, 48; 47, 51; 47, 54; 47, 57; 47, 60; 47, 63; 47, 66; 48, pair; 48, 49; 48, 50; 49, string:'valueType'; 50, identifier:vtype; 51, pair; 51, 52; 51, 53; 52, string:'dataManagerType'; 53, identifier:datamanagertype; 54, pair; 54, 55; 54, 56; 55, string:'dataManagerGroup'; 56, identifier:datamanagergroup; 57, pair; 57, 58; 57, 59; 58, string:'option'; 59, identifier:options; 60, pair; 60, 61; 60, 62; 61, string:'maxlen'; 62, identifier:maxlen; 63, pair; 63, 64; 63, 65; 64, string:'comment'; 65, identifier:comment; 66, pair; 66, 67; 66, 68; 67, string:'keywords'; 68, identifier:keywords; 69, return_statement; 69, 70; 70, dictionary; 70, 71; 70, 74; 71, pair; 71, 72; 71, 73; 72, string:'name'; 73, identifier:columnname; 74, pair; 74, 75; 74, 76; 75, string:'desc'; 76, identifier:rec2
def makescacoldesc(columnname, value, datamanagertype='', datamanagergroup='', options=0, maxlen=0, comment='', valuetype='', keywords={}): vtype = valuetype if vtype == '': vtype = _value_type_name(value) rec2 = {'valueType': vtype, 'dataManagerType': datamanagertype, 'dataManagerGroup': datamanagergroup, 'option': options, 'maxlen': maxlen, 'comment': comment, 'keywords': keywords} return {'name': columnname, 'desc': rec2}
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 33; 2, function_name:makearrcoldesc; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 4, identifier:columnname; 5, identifier:value; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ndim; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:shape; 11, list:[]; 12, default_parameter; 12, 13; 12, 14; 13, identifier:datamanagertype; 14, string:''; 15, default_parameter; 15, 16; 15, 17; 16, identifier:datamanagergroup; 17, string:''; 18, default_parameter; 18, 19; 18, 20; 19, identifier:options; 20, integer:0; 21, default_parameter; 21, 22; 21, 23; 22, identifier:maxlen; 23, integer:0; 24, default_parameter; 24, 25; 24, 26; 25, identifier:comment; 26, string:''; 27, default_parameter; 27, 28; 27, 29; 28, identifier:valuetype; 29, string:''; 30, default_parameter; 30, 31; 30, 32; 31, identifier:keywords; 32, dictionary; 33, block; 33, 34; 33, 38; 33, 50; 33, 70; 33, 104; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:vtype; 37, identifier:valuetype; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:==; 39, 40; 39, 41; 40, identifier:vtype; 41, string:''; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:vtype; 46, call; 46, 47; 46, 48; 47, identifier:_value_type_name; 48, argument_list; 48, 49; 49, identifier:value; 50, if_statement; 50, 51; 50, 57; 51, comparison_operator:>; 51, 52; 51, 56; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, identifier:shape; 56, integer:0; 57, block; 57, 58; 58, if_statement; 58, 59; 58, 62; 59, comparison_operator:<=; 59, 60; 59, 61; 60, identifier:ndim; 61, integer:0; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:ndim; 66, call; 66, 67; 66, 68; 67, identifier:len; 68, argument_list; 68, 69; 69, identifier:shape; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:rec2; 73, dictionary; 73, 74; 73, 77; 73, 80; 73, 83; 73, 86; 73, 89; 73, 92; 73, 95; 73, 98; 73, 101; 74, pair; 74, 75; 74, 76; 75, string:'valueType'; 76, identifier:vtype; 77, pair; 77, 78; 77, 79; 78, string:'dataManagerType'; 79, identifier:datamanagertype; 80, pair; 80, 81; 80, 82; 81, string:'dataManagerGroup'; 82, identifier:datamanagergroup; 83, pair; 83, 84; 83, 85; 84, string:'ndim'; 85, identifier:ndim; 86, pair; 86, 87; 86, 88; 87, string:'shape'; 88, identifier:shape; 89, pair; 89, 90; 89, 91; 90, string:'_c_order'; 91, True; 92, pair; 92, 93; 92, 94; 93, string:'option'; 94, identifier:options; 95, pair; 95, 96; 95, 97; 96, string:'maxlen'; 97, identifier:maxlen; 98, pair; 98, 99; 98, 100; 99, string:'comment'; 100, identifier:comment; 101, pair; 101, 102; 101, 103; 102, string:'keywords'; 103, identifier:keywords; 104, return_statement; 104, 105; 105, dictionary; 105, 106; 105, 109; 106, pair; 106, 107; 106, 108; 107, string:'name'; 108, identifier:columnname; 109, pair; 109, 110; 109, 111; 110, string:'desc'; 111, identifier:rec2
def makearrcoldesc(columnname, value, ndim=0, shape=[], datamanagertype='', datamanagergroup='', options=0, maxlen=0, comment='', valuetype='', keywords={}): vtype = valuetype if vtype == '': vtype = _value_type_name(value) if len(shape) > 0: if ndim <= 0: ndim = len(shape) rec2 = {'valueType': vtype, 'dataManagerType': datamanagertype, 'dataManagerGroup': datamanagergroup, 'ndim': ndim, 'shape': shape, '_c_order': True, 'option': options, 'maxlen': maxlen, 'comment': comment, 'keywords': keywords} return {'name': columnname, 'desc': rec2}
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:makedminfo; 3, parameters; 3, 4; 3, 5; 4, identifier:tabdesc; 5, default_parameter; 5, 6; 5, 7; 6, identifier:group_spec; 7, None; 8, block; 8, 9; 8, 18; 8, 46; 8, 53; 8, 179; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:group_spec; 12, None; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:group_spec; 17, dictionary; 18, class_definition; 18, 19; 18, 20; 18, 22; 19, identifier:DMGroup; 20, argument_list; 20, 21; 21, identifier:object; 22, block; 22, 23; 23, function_definition; 23, 24; 23, 25; 23, 27; 24, function_name:__init__; 25, parameters; 25, 26; 26, identifier:self; 27, block; 27, 28; 27, 34; 27, 40; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:columns; 33, list:[]; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:type; 39, None; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:spec; 45, None; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:dm_groups; 49, call; 49, 50; 49, 51; 50, identifier:defaultdict; 51, argument_list; 51, 52; 52, identifier:DMGroup; 53, for_statement; 53, 54; 53, 57; 53, 63; 54, pattern_list; 54, 55; 54, 56; 55, identifier:c; 56, identifier:d; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:six; 60, identifier:iteritems; 61, argument_list; 61, 62; 62, identifier:tabdesc; 63, block; 63, 64; 63, 73; 63, 83; 63, 93; 63, 101; 63, 109; 63, 115; 63, 124; 63, 143; 64, if_statement; 64, 65; 64, 71; 65, comparison_operator:in; 65, 66; 65, 67; 66, identifier:c; 67, tuple; 67, 68; 67, 69; 67, 70; 68, string:'_define_hypercolumn_'; 69, string:'_keywords_'; 70, string:'_private_keywords_'; 71, block; 71, 72; 72, continue_statement; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:group; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:d; 79, identifier:get; 80, argument_list; 80, 81; 80, 82; 81, string:"dataManagerGroup"; 82, string:"StandardStMan"; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:type_; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:d; 89, identifier:get; 90, argument_list; 90, 91; 90, 92; 91, string:"dataManagerType"; 92, string:"StandardStMan"; 93, if_statement; 93, 94; 93, 96; 94, not_operator; 94, 95; 95, identifier:group; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:group; 100, string:"StandardStMan"; 101, if_statement; 101, 102; 101, 104; 102, not_operator; 102, 103; 103, identifier:type_; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:type_; 108, string:"StandardStMan"; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:dm_group; 112, subscript; 112, 113; 112, 114; 113, identifier:dm_groups; 114, identifier:group; 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:dm_group; 120, identifier:columns; 121, identifier:append; 122, argument_list; 122, 123; 123, identifier:c; 124, if_statement; 124, 125; 124, 130; 125, comparison_operator:is; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:dm_group; 128, identifier:spec; 129, None; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:dm_group; 135, identifier:spec; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:group_spec; 139, identifier:get; 140, argument_list; 140, 141; 140, 142; 141, identifier:group; 142, dictionary; 143, if_statement; 143, 144; 143, 149; 143, 156; 144, comparison_operator:is; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:dm_group; 147, identifier:type; 148, None; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:dm_group; 154, identifier:type; 155, identifier:type_; 156, elif_clause; 156, 157; 156, 163; 157, not_operator; 157, 158; 158, comparison_operator:==; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:dm_group; 161, identifier:type; 162, identifier:type_; 163, block; 163, 164; 164, raise_statement; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:ValueError; 167, argument_list; 167, 168; 168, binary_operator:%; 168, 169; 168, 173; 169, concatenated_string; 169, 170; 169, 171; 169, 172; 170, string:"Mismatched dataManagerType '%s' "; 171, string:"for dataManagerGroup '%s' "; 172, string:"Previously, the type was '%s'"; 173, tuple; 173, 174; 173, 175; 173, 176; 174, identifier:type_; 175, identifier:group; 176, attribute; 176, 177; 176, 178; 177, identifier:dm_group; 178, identifier:type; 179, return_statement; 179, 180; 180, dictionary_comprehension; 180, 181; 180, 210; 181, pair; 181, 182; 181, 188; 182, binary_operator:%; 182, 183; 182, 184; 183, string:'*%d'; 184, parenthesized_expression; 184, 185; 185, binary_operator:+; 185, 186; 185, 187; 186, identifier:i; 187, integer:1; 188, dictionary; 188, 189; 188, 194; 188, 199; 188, 202; 188, 207; 189, pair; 189, 190; 189, 191; 190, string:'COLUMNS'; 191, attribute; 191, 192; 191, 193; 192, identifier:dm_group; 193, identifier:columns; 194, pair; 194, 195; 194, 196; 195, string:'TYPE'; 196, attribute; 196, 197; 196, 198; 197, identifier:dm_group; 198, identifier:type; 199, pair; 199, 200; 199, 201; 200, string:'NAME'; 201, identifier:group; 202, pair; 202, 203; 202, 204; 203, string:'SPEC'; 204, attribute; 204, 205; 204, 206; 205, identifier:dm_group; 206, identifier:spec; 207, pair; 207, 208; 207, 209; 208, string:'SEQNR'; 209, identifier:i; 210, for_in_clause; 210, 211; 210, 216; 211, pattern_list; 211, 212; 211, 213; 212, identifier:i; 213, tuple_pattern; 213, 214; 213, 215; 214, identifier:group; 215, identifier:dm_group; 216, call; 216, 217; 216, 218; 217, identifier:enumerate; 218, argument_list; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:six; 222, identifier:iteritems; 223, argument_list; 223, 224; 224, identifier:dm_groups
def makedminfo(tabdesc, group_spec=None): if group_spec is None: group_spec = {} class DMGroup(object): def __init__(self): self.columns = [] self.type = None self.spec = None dm_groups = defaultdict(DMGroup) for c, d in six.iteritems(tabdesc): if c in ('_define_hypercolumn_', '_keywords_', '_private_keywords_'): continue group = d.get("dataManagerGroup", "StandardStMan") type_ = d.get("dataManagerType", "StandardStMan") if not group: group = "StandardStMan" if not type_: type_ = "StandardStMan" dm_group = dm_groups[group] dm_group.columns.append(c) if dm_group.spec is None: dm_group.spec = group_spec.get(group, {}) if dm_group.type is None: dm_group.type = type_ elif not dm_group.type == type_: raise ValueError("Mismatched dataManagerType '%s' " "for dataManagerGroup '%s' " "Previously, the type was '%s'" % (type_, group, dm_group.type)) return { '*%d'%(i+1): { 'COLUMNS': dm_group.columns, 'TYPE': dm_group.type, 'NAME': group, 'SPEC' : dm_group.spec, 'SEQNR': i } for i, (group, dm_group) in enumerate(six.iteritems(dm_groups)) }
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:attrgetrow; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:groupname; 6, identifier:key; 7, default_parameter; 7, 8; 7, 9; 8, identifier:value; 9, None; 10, block; 10, 11; 10, 27; 10, 38; 10, 64; 10, 90; 11, if_statement; 11, 12; 11, 18; 12, not_operator; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:key; 17, identifier:str; 18, block; 18, 19; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_attrgetrow; 24, argument_list; 24, 25; 24, 26; 25, identifier:groupname; 26, identifier:key; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:rownrs; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:attrfindrows; 34, argument_list; 34, 35; 34, 36; 34, 37; 35, identifier:groupname; 36, identifier:key; 37, identifier:value; 38, if_statement; 38, 39; 38, 45; 39, comparison_operator:==; 39, 40; 39, 44; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, identifier:rownrs; 44, integer:0; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:IndexError; 49, argument_list; 49, 50; 50, binary_operator:+; 50, 51; 50, 60; 51, binary_operator:+; 51, 52; 51, 59; 52, binary_operator:+; 52, 53; 52, 58; 53, binary_operator:+; 53, 54; 53, 57; 54, binary_operator:+; 54, 55; 54, 56; 55, string:"Image attribute "; 56, identifier:key; 57, string:" in group "; 58, identifier:groupname; 59, string:" has no matches for value "; 60, call; 60, 61; 60, 62; 61, identifier:str; 62, argument_list; 62, 63; 63, identifier:value; 64, if_statement; 64, 65; 64, 71; 65, comparison_operator:>; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:len; 68, argument_list; 68, 69; 69, identifier:rownrs; 70, integer:1; 71, block; 71, 72; 72, raise_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:IndexError; 75, argument_list; 75, 76; 76, binary_operator:+; 76, 77; 76, 86; 77, binary_operator:+; 77, 78; 77, 85; 78, binary_operator:+; 78, 79; 78, 84; 79, binary_operator:+; 79, 80; 79, 83; 80, binary_operator:+; 80, 81; 80, 82; 81, string:"Image attribute "; 82, identifier:key; 83, string:" in group "; 84, identifier:groupname; 85, string:" has multiple matches for value "; 86, call; 86, 87; 86, 88; 87, identifier:str; 88, argument_list; 88, 89; 89, identifier:value; 90, return_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:_attrgetrow; 95, argument_list; 95, 96; 95, 97; 96, identifier:groupname; 97, subscript; 97, 98; 97, 99; 98, identifier:rownrs; 99, integer:0
def attrgetrow(self, groupname, key, value=None): if not isinstance(key, str): return self._attrgetrow(groupname, key) rownrs = self.attrfindrows(groupname, key, value) if len(rownrs) == 0: raise IndexError("Image attribute " + key + " in group " + groupname + " has no matches for value " + str(value)) if len(rownrs) > 1: raise IndexError("Image attribute " + key + " in group " + groupname + " has multiple matches for value " + str(value)) return self._attrgetrow(groupname, rownrs[0])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:substitute; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:s; 5, default_parameter; 5, 6; 5, 7; 6, identifier:objlist; 7, tuple; 8, default_parameter; 8, 9; 8, 10; 9, identifier:globals; 10, dictionary; 11, default_parameter; 11, 12; 11, 13; 12, identifier:locals; 13, dictionary; 14, block; 14, 15; 14, 26; 14, 30; 14, 34; 14, 38; 14, 42; 14, 46; 14, 50; 14, 54; 14, 58; 14, 267; 14, 293; 15, if_statement; 15, 16; 15, 18; 16, not_operator; 16, 17; 17, identifier:locals; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:locals; 22, call; 22, 23; 22, 24; 23, identifier:getlocals; 24, argument_list; 24, 25; 25, integer:3; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:backslash; 29, False; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:dollar; 33, False; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:nparen; 37, integer:0; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:name; 41, string:''; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:evalstr; 45, string:''; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:squote; 49, False; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:dquote; 53, False; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:out; 57, string:''; 58, for_statement; 58, 59; 58, 60; 58, 61; 59, identifier:tmp; 60, identifier:s; 61, block; 61, 62; 61, 74; 61, 150; 61, 176; 61, 243; 61, 258; 62, if_statement; 62, 63; 62, 64; 63, identifier:backslash; 64, block; 64, 65; 64, 69; 64, 73; 65, expression_statement; 65, 66; 66, augmented_assignment:+=; 66, 67; 66, 68; 67, identifier:out; 68, identifier:tmp; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:backslash; 72, False; 73, continue_statement; 74, if_statement; 74, 75; 74, 80; 75, boolean_operator:and; 75, 76; 75, 77; 76, identifier:dollar; 77, comparison_operator:==; 77, 78; 77, 79; 78, identifier:nparen; 79, integer:0; 80, block; 80, 81; 80, 103; 80, 118; 80, 136; 80, 146; 81, if_statement; 81, 82; 81, 97; 82, boolean_operator:or; 82, 83; 82, 92; 83, boolean_operator:or; 83, 84; 83, 87; 84, comparison_operator:==; 84, 85; 84, 86; 85, identifier:tmp; 86, string:'_'; 87, parenthesized_expression; 87, 88; 88, comparison_operator:<=; 88, 89; 88, 90; 88, 91; 89, string:'a'; 90, identifier:tmp; 91, string:'z'; 92, parenthesized_expression; 92, 93; 93, comparison_operator:<=; 93, 94; 93, 95; 93, 96; 94, string:'A'; 95, identifier:tmp; 96, string:'Z'; 97, block; 97, 98; 97, 102; 98, expression_statement; 98, 99; 99, augmented_assignment:+=; 99, 100; 99, 101; 100, identifier:name; 101, identifier:tmp; 102, continue_statement; 103, if_statement; 103, 104; 103, 112; 104, boolean_operator:and; 104, 105; 104, 109; 105, comparison_operator:<=; 105, 106; 105, 107; 105, 108; 106, string:'0'; 107, identifier:tmp; 108, string:'9'; 109, comparison_operator:!=; 109, 110; 109, 111; 110, identifier:name; 111, string:''; 112, block; 112, 113; 112, 117; 113, expression_statement; 113, 114; 114, augmented_assignment:+=; 114, 115; 114, 116; 115, identifier:name; 116, identifier:tmp; 117, continue_statement; 118, if_statement; 118, 119; 118, 126; 119, boolean_operator:and; 119, 120; 119, 123; 120, comparison_operator:==; 120, 121; 120, 122; 121, identifier:tmp; 122, string:'('; 123, comparison_operator:==; 123, 124; 123, 125; 124, identifier:name; 125, string:''; 126, block; 126, 127; 126, 131; 126, 135; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:nparen; 130, integer:1; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:evalstr; 134, string:''; 135, continue_statement; 136, expression_statement; 136, 137; 137, augmented_assignment:+=; 137, 138; 137, 139; 138, identifier:out; 139, call; 139, 140; 139, 141; 140, identifier:substitutename; 141, argument_list; 141, 142; 141, 143; 141, 144; 141, 145; 142, identifier:name; 143, identifier:objlist; 144, identifier:globals; 145, identifier:locals; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:dollar; 149, False; 150, if_statement; 150, 151; 150, 157; 150, 163; 151, boolean_operator:and; 151, 152; 151, 155; 152, comparison_operator:==; 152, 153; 152, 154; 153, identifier:tmp; 154, string:'"'; 155, not_operator; 155, 156; 156, identifier:squote; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:dquote; 161, not_operator; 161, 162; 162, identifier:dquote; 163, elif_clause; 163, 164; 163, 170; 164, boolean_operator:and; 164, 165; 164, 168; 165, comparison_operator:==; 165, 166; 165, 167; 166, identifier:tmp; 167, string:"'"; 168, not_operator; 168, 169; 169, identifier:dquote; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:squote; 174, not_operator; 174, 175; 175, identifier:squote; 176, if_statement; 176, 177; 176, 182; 177, boolean_operator:and; 177, 178; 177, 180; 178, not_operator; 178, 179; 179, identifier:dquote; 180, not_operator; 180, 181; 181, identifier:squote; 182, block; 182, 183; 182, 229; 183, if_statement; 183, 184; 183, 187; 184, comparison_operator:>; 184, 185; 184, 186; 185, identifier:nparen; 186, integer:0; 187, block; 187, 188; 187, 224; 187, 228; 188, if_statement; 188, 189; 188, 192; 188, 197; 189, comparison_operator:==; 189, 190; 189, 191; 190, identifier:tmp; 191, string:'('; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, augmented_assignment:+=; 194, 195; 194, 196; 195, identifier:nparen; 196, integer:1; 197, elif_clause; 197, 198; 197, 201; 198, comparison_operator:==; 198, 199; 198, 200; 199, identifier:tmp; 200, string:')'; 201, block; 201, 202; 201, 206; 202, expression_statement; 202, 203; 203, augmented_assignment:-=; 203, 204; 203, 205; 204, identifier:nparen; 205, integer:1; 206, if_statement; 206, 207; 206, 210; 207, comparison_operator:==; 207, 208; 207, 209; 208, identifier:nparen; 209, integer:0; 210, block; 210, 211; 210, 220; 211, expression_statement; 211, 212; 212, augmented_assignment:+=; 212, 213; 212, 214; 213, identifier:out; 214, call; 214, 215; 214, 216; 215, identifier:substituteexpr; 216, argument_list; 216, 217; 216, 218; 216, 219; 217, identifier:evalstr; 218, identifier:globals; 219, identifier:locals; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:dollar; 223, False; 224, expression_statement; 224, 225; 225, augmented_assignment:+=; 225, 226; 225, 227; 226, identifier:evalstr; 227, identifier:tmp; 228, continue_statement; 229, if_statement; 229, 230; 229, 233; 230, comparison_operator:==; 230, 231; 230, 232; 231, identifier:tmp; 232, string:'$'; 233, block; 233, 234; 233, 238; 233, 242; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:dollar; 237, True; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:name; 241, string:''; 242, continue_statement; 243, if_statement; 243, 244; 243, 247; 243, 252; 244, comparison_operator:==; 244, 245; 244, 246; 245, identifier:nparen; 246, integer:0; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, augmented_assignment:+=; 249, 250; 249, 251; 250, identifier:out; 251, identifier:tmp; 252, else_clause; 252, 253; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, augmented_assignment:+=; 255, 256; 255, 257; 256, identifier:evalstr; 257, identifier:tmp; 258, if_statement; 258, 259; 258, 262; 259, comparison_operator:==; 259, 260; 259, 261; 260, identifier:tmp; 261, string:'\\'; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:backslash; 266, True; 267, if_statement; 267, 268; 267, 269; 267, 280; 268, identifier:dollar; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, augmented_assignment:+=; 271, 272; 271, 273; 272, identifier:out; 273, call; 273, 274; 273, 275; 274, identifier:substitutename; 275, argument_list; 275, 276; 275, 277; 275, 278; 275, 279; 276, identifier:name; 277, identifier:objlist; 278, identifier:globals; 279, identifier:locals; 280, else_clause; 280, 281; 281, block; 281, 282; 282, if_statement; 282, 283; 282, 286; 283, comparison_operator:>; 283, 284; 283, 285; 284, identifier:nparen; 285, integer:0; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, augmented_assignment:+=; 288, 289; 288, 290; 289, identifier:out; 290, binary_operator:+; 290, 291; 290, 292; 291, string:'$('; 292, identifier:evalstr; 293, return_statement; 293, 294; 294, identifier:out
def substitute(s, objlist=(), globals={}, locals={}): if not locals: locals = getlocals(3) backslash = False dollar = False nparen = 0 name = '' evalstr = '' squote = False dquote = False out = '' for tmp in s: if backslash: out += tmp backslash = False continue if dollar and nparen == 0: if tmp == '_' or ('a' <= tmp <= 'z') or ('A' <= tmp <= 'Z'): name += tmp continue if '0' <= tmp <= '9' and name != '': name += tmp continue if tmp == '(' and name == '': nparen = 1 evalstr = '' continue out += substitutename(name, objlist, globals, locals) dollar = False if tmp == '"' and not squote: dquote = not dquote elif tmp == "'" and not dquote: squote = not squote if not dquote and not squote: if nparen > 0: if tmp == '(': nparen += 1 elif tmp == ')': nparen -= 1 if nparen == 0: out += substituteexpr(evalstr, globals, locals) dollar = False evalstr += tmp continue if tmp == '$': dollar = True name = '' continue if nparen == 0: out += tmp else: evalstr += tmp if tmp == '\\': backslash = True if dollar: out += substitutename(name, objlist, globals, locals) else: if nparen > 0: out += '$(' + evalstr return out
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:iter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:columnnames; 6, default_parameter; 6, 7; 6, 8; 7, identifier:order; 8, string:''; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, True; 12, block; 12, 13; 12, 20; 13, import_from_statement; 13, 14; 13, 18; 14, relative_import; 14, 15; 14, 16; 15, import_prefix; 16, dotted_name; 16, 17; 17, identifier:tableiter; 18, dotted_name; 18, 19; 19, identifier:tableiter; 20, return_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:tableiter; 23, argument_list; 23, 24; 23, 25; 23, 26; 23, 27; 24, identifier:self; 25, identifier:columnnames; 26, identifier:order; 27, identifier:sort
def iter(self, columnnames, order='', sort=True): from .tableiter import tableiter return tableiter(self, columnnames, order, sort)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:index; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:columnnames; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort; 8, True; 9, block; 9, 10; 9, 17; 10, import_from_statement; 10, 11; 10, 15; 11, relative_import; 11, 12; 11, 13; 12, import_prefix; 13, dotted_name; 13, 14; 14, identifier:tableindex; 15, dotted_name; 15, 16; 16, identifier:tableindex; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:tableindex; 20, argument_list; 20, 21; 20, 22; 20, 23; 21, identifier:self; 22, identifier:columnnames; 23, identifier:sort
def index(self, columnnames, sort=True): from .tableindex import tableindex return tableindex(self, columnnames, sort)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:rownumbers; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:table; 7, None; 8, block; 8, 9; 8, 23; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:table; 12, None; 13, block; 13, 14; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_rownumbers; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:Table; 22, argument_list; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_rownumbers; 28, argument_list; 28, 29; 29, identifier:table
def rownumbers(self, table=None): if table is None: return self._rownumbers(Table()) return self._rownumbers(table)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:showstructure; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:dataman; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:column; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:subtable; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort; 16, False; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_showstructure; 23, argument_list; 23, 24; 23, 25; 23, 26; 23, 27; 24, identifier:dataman; 25, identifier:column; 26, identifier:subtable; 27, identifier:sort
def showstructure(self, dataman=True, column=True, subtable=False, sort=False): return self._showstructure(dataman, column, subtable, sort)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:query; 7, string:''; 8, default_parameter; 8, 9; 8, 10; 9, identifier:name; 10, string:''; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sortlist; 13, string:''; 14, default_parameter; 14, 15; 14, 16; 15, identifier:columns; 16, string:''; 17, default_parameter; 17, 18; 17, 19; 18, identifier:limit; 19, integer:0; 20, default_parameter; 20, 21; 20, 22; 21, identifier:offset; 22, integer:0; 23, default_parameter; 23, 24; 23, 25; 24, identifier:style; 25, string:'Python'; 26, block; 26, 27; 26, 53; 26, 57; 26, 64; 26, 68; 26, 77; 26, 86; 26, 97; 26, 108; 26, 117; 27, if_statement; 27, 28; 27, 45; 28, boolean_operator:and; 28, 29; 28, 42; 29, boolean_operator:and; 29, 30; 29, 38; 29, 39; 30, boolean_operator:and; 30, 31; 30, 36; 31, boolean_operator:and; 31, 32; 31, 34; 32, not_operator; 32, 33; 33, identifier:query; 34, not_operator; 34, 35; 35, identifier:sortlist; 36, not_operator; 36, 37; 37, identifier:columns; 38, line_continuation:\; 39, comparison_operator:<=; 39, 40; 39, 41; 40, identifier:limit; 41, integer:0; 42, comparison_operator:<=; 42, 43; 42, 44; 43, identifier:offset; 44, integer:0; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:ValueError; 49, argument_list; 49, 50; 50, binary_operator:+; 50, 51; 50, 52; 51, string:'No selection done (arguments query, '; 52, string:'sortlist, columns, limit, and offset are empty)'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:command; 56, string:'select '; 57, if_statement; 57, 58; 57, 59; 58, identifier:columns; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, augmented_assignment:+=; 61, 62; 61, 63; 62, identifier:command; 63, identifier:columns; 64, expression_statement; 64, 65; 65, augmented_assignment:+=; 65, 66; 65, 67; 66, identifier:command; 67, string:' from $1'; 68, if_statement; 68, 69; 68, 70; 69, identifier:query; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, augmented_assignment:+=; 72, 73; 72, 74; 73, identifier:command; 74, binary_operator:+; 74, 75; 74, 76; 75, string:' where '; 76, identifier:query; 77, if_statement; 77, 78; 77, 79; 78, identifier:sortlist; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, augmented_assignment:+=; 81, 82; 81, 83; 82, identifier:command; 83, binary_operator:+; 83, 84; 83, 85; 84, string:' orderby '; 85, identifier:sortlist; 86, if_statement; 86, 87; 86, 90; 87, comparison_operator:>; 87, 88; 87, 89; 88, identifier:limit; 89, integer:0; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, augmented_assignment:+=; 92, 93; 92, 94; 93, identifier:command; 94, binary_operator:%; 94, 95; 94, 96; 95, string:' limit %d'; 96, identifier:limit; 97, if_statement; 97, 98; 97, 101; 98, comparison_operator:>; 98, 99; 98, 100; 99, identifier:offset; 100, integer:0; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, augmented_assignment:+=; 103, 104; 103, 105; 104, identifier:command; 105, binary_operator:%; 105, 106; 105, 107; 106, string:' offset %d'; 107, identifier:offset; 108, if_statement; 108, 109; 108, 110; 109, identifier:name; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, augmented_assignment:+=; 112, 113; 112, 114; 113, identifier:command; 114, binary_operator:+; 114, 115; 114, 116; 115, string:' giving '; 116, identifier:name; 117, return_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:tablecommand; 120, argument_list; 120, 121; 120, 122; 120, 123; 121, identifier:command; 122, identifier:style; 123, list:[self]; 123, 124; 124, identifier:self
def query(self, query='', name='', sortlist='', columns='', limit=0, offset=0, style='Python'): if not query and not sortlist and not columns and \ limit <= 0 and offset <= 0: raise ValueError('No selection done (arguments query, ' + 'sortlist, columns, limit, and offset are empty)') command = 'select ' if columns: command += columns command += ' from $1' if query: command += ' where ' + query if sortlist: command += ' orderby ' + sortlist if limit > 0: command += ' limit %d' % limit if offset > 0: command += ' offset %d' % offset if name: command += ' giving ' + name return tablecommand(command, style, [self])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:sortlist; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name; 8, string:''; 9, default_parameter; 9, 10; 9, 11; 10, identifier:limit; 11, integer:0; 12, default_parameter; 12, 13; 12, 14; 13, identifier:offset; 14, integer:0; 15, default_parameter; 15, 16; 15, 17; 16, identifier:style; 17, string:'Python'; 18, block; 18, 19; 18, 25; 18, 36; 18, 47; 18, 56; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:command; 22, binary_operator:+; 22, 23; 22, 24; 23, string:'select from $1 orderby '; 24, identifier:sortlist; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:>; 26, 27; 26, 28; 27, identifier:limit; 28, integer:0; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, augmented_assignment:+=; 31, 32; 31, 33; 32, identifier:command; 33, binary_operator:%; 33, 34; 33, 35; 34, string:' limit %d'; 35, identifier:limit; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:>; 37, 38; 37, 39; 38, identifier:offset; 39, integer:0; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, augmented_assignment:+=; 42, 43; 42, 44; 43, identifier:command; 44, binary_operator:%; 44, 45; 44, 46; 45, string:' offset %d'; 46, identifier:offset; 47, if_statement; 47, 48; 47, 49; 48, identifier:name; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, augmented_assignment:+=; 51, 52; 51, 53; 52, identifier:command; 53, binary_operator:+; 53, 54; 53, 55; 54, string:' giving '; 55, identifier:name; 56, return_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:tablecommand; 59, argument_list; 59, 60; 59, 61; 59, 62; 60, identifier:command; 61, identifier:style; 62, list:[self]; 62, 63; 63, identifier:self
def sort(self, sortlist, name='', limit=0, offset=0, style='Python'): command = 'select from $1 orderby ' + sortlist if limit > 0: command += ' limit %d' % limit if offset > 0: command += ' offset %d' % offset if name: command += ' giving ' + name return tablecommand(command, style, [self])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:browse; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:wait; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:tempname; 10, string:"/tmp/seltable"; 11, block; 11, 12; 11, 15; 12, import_statement; 12, 13; 13, dotted_name; 13, 14; 14, identifier:os; 15, if_statement; 15, 16; 15, 24; 15, 211; 16, comparison_operator:==; 16, 17; 16, 23; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:os; 20, identifier:system; 21, argument_list; 21, 22; 22, string:'test `which casabrowser`x != x'; 23, integer:0; 24, block; 24, 25; 24, 29; 24, 33; 24, 45; 24, 72; 24, 78; 24, 84; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:waitstr1; 28, string:""; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:waitstr2; 32, string:"foreground ..."; 33, if_statement; 33, 34; 33, 36; 34, not_operator; 34, 35; 35, identifier:wait; 36, block; 36, 37; 36, 41; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:waitstr1; 40, string:" &"; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:waitstr2; 44, string:"background ..."; 45, if_statement; 45, 46; 45, 51; 45, 61; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:iswritable; 50, argument_list; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:six; 56, identifier:print_; 57, argument_list; 57, 58; 58, binary_operator:+; 58, 59; 58, 60; 59, string:"Flushing data and starting casabrowser in the "; 60, identifier:waitstr2; 61, else_clause; 61, 62; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:six; 67, identifier:print_; 68, argument_list; 68, 69; 69, binary_operator:+; 69, 70; 69, 71; 70, string:"Starting casabrowser in the "; 71, identifier:waitstr2; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:flush; 77, argument_list; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:unlock; 83, argument_list; 84, if_statement; 84, 85; 84, 101; 84, 117; 84, 186; 85, comparison_operator:==; 85, 86; 85, 100; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:os; 89, identifier:system; 90, argument_list; 90, 91; 91, binary_operator:+; 91, 92; 91, 99; 92, binary_operator:+; 92, 93; 92, 94; 93, string:'test -e '; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:name; 98, argument_list; 99, string:'/table.dat'; 100, integer:0; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:os; 106, identifier:system; 107, argument_list; 107, 108; 108, binary_operator:+; 108, 109; 108, 116; 109, binary_operator:+; 109, 110; 109, 111; 110, string:'casabrowser '; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:name; 115, argument_list; 116, identifier:waitstr1; 117, elif_clause; 117, 118; 117, 124; 118, comparison_operator:>; 118, 119; 118, 123; 119, call; 119, 120; 119, 121; 120, identifier:len; 121, argument_list; 121, 122; 122, identifier:tempname; 123, integer:0; 124, block; 124, 125; 124, 134; 124, 141; 124, 152; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:six; 129, identifier:print_; 130, argument_list; 130, 131; 131, binary_operator:+; 131, 132; 131, 133; 132, string:" making a persistent copy in table "; 133, identifier:tempname; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:copy; 139, argument_list; 139, 140; 140, identifier:tempname; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:os; 145, identifier:system; 146, argument_list; 146, 147; 147, binary_operator:+; 147, 148; 147, 151; 148, binary_operator:+; 148, 149; 148, 150; 149, string:'casabrowser '; 150, identifier:tempname; 151, identifier:waitstr1; 152, if_statement; 152, 153; 152, 154; 152, 173; 153, identifier:wait; 154, block; 154, 155; 154, 161; 154, 168; 155, import_from_statement; 155, 156; 155, 159; 156, dotted_name; 156, 157; 156, 158; 157, identifier:casacore; 158, identifier:tables; 159, dotted_name; 159, 160; 160, identifier:tabledelete; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:six; 165, identifier:print_; 166, argument_list; 166, 167; 167, string:" finished browsing"; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:tabledelete; 171, argument_list; 171, 172; 172, identifier:tempname; 173, else_clause; 173, 174; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:six; 179, identifier:print_; 180, argument_list; 180, 181; 181, binary_operator:+; 181, 182; 181, 185; 182, binary_operator:+; 182, 183; 182, 184; 183, string:" after browsing use tabledelete('"; 184, identifier:tempname; 185, string:"') to delete the copy"; 186, else_clause; 186, 187; 187, block; 187, 188; 187, 195; 187, 204; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:six; 192, identifier:print_; 193, argument_list; 193, 194; 194, string:"Cannot browse because the table is in memory only"; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:six; 199, identifier:print_; 200, argument_list; 200, 201; 201, binary_operator:+; 201, 202; 201, 203; 202, string:"You can browse a (shallow) persistent copy "; 203, string:"of the table like: "; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:six; 208, identifier:print_; 209, argument_list; 209, 210; 210, string:" t.browse(True, '/tmp/tab1')"; 211, else_clause; 211, 212; 212, block; 212, 213; 212, 229; 212, 235; 212, 238; 212, 244; 212, 249; 212, 260; 212, 267; 213, try_statement; 213, 214; 213, 218; 214, block; 214, 215; 215, import_statement; 215, 216; 216, dotted_name; 216, 217; 217, identifier:wxPython; 218, except_clause; 218, 219; 218, 220; 219, identifier:ImportError; 220, block; 220, 221; 220, 228; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:six; 225, identifier:print_; 226, argument_list; 226, 227; 227, string:'casabrowser nor wxPython can be found'; 228, return_statement; 229, import_from_statement; 229, 230; 229, 233; 230, dotted_name; 230, 231; 230, 232; 231, identifier:wxPython; 232, identifier:wx; 233, dotted_name; 233, 234; 234, identifier:wxPySimpleApp; 235, import_statement; 235, 236; 236, dotted_name; 236, 237; 237, identifier:sys; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:app; 241, call; 241, 242; 241, 243; 242, identifier:wxPySimpleApp; 243, argument_list; 244, import_from_statement; 244, 245; 244, 247; 245, dotted_name; 245, 246; 246, identifier:wxtablebrowser; 247, dotted_name; 247, 248; 248, identifier:CasaTestFrame; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:frame; 252, call; 252, 253; 252, 254; 253, identifier:CasaTestFrame; 254, argument_list; 254, 255; 254, 256; 254, 259; 255, None; 256, attribute; 256, 257; 256, 258; 257, identifier:sys; 258, identifier:stdout; 259, identifier:self; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:frame; 264, identifier:Show; 265, argument_list; 265, 266; 266, True; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:app; 271, identifier:MainLoop; 272, argument_list
def browse(self, wait=True, tempname="/tmp/seltable"): import os if os.system('test `which casabrowser`x != x') == 0: waitstr1 = "" waitstr2 = "foreground ..." if not wait: waitstr1 = " &" waitstr2 = "background ..." if self.iswritable(): six.print_("Flushing data and starting casabrowser in the " + waitstr2) else: six.print_("Starting casabrowser in the " + waitstr2) self.flush() self.unlock() if os.system('test -e ' + self.name() + '/table.dat') == 0: os.system('casabrowser ' + self.name() + waitstr1) elif len(tempname) > 0: six.print_(" making a persistent copy in table " + tempname) self.copy(tempname) os.system('casabrowser ' + tempname + waitstr1) if wait: from casacore.tables import tabledelete six.print_(" finished browsing") tabledelete(tempname) else: six.print_(" after browsing use tabledelete('" + tempname + "') to delete the copy") else: six.print_("Cannot browse because the table is in memory only") six.print_("You can browse a (shallow) persistent copy " + "of the table like: ") six.print_(" t.browse(True, '/tmp/tab1')") else: try: import wxPython except ImportError: six.print_('casabrowser nor wxPython can be found') return from wxPython.wx import wxPySimpleApp import sys app = wxPySimpleApp() from wxtablebrowser import CasaTestFrame frame = CasaTestFrame(None, sys.stdout, self) frame.Show(True) app.MainLoop()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:view; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:wait; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:tempname; 10, string:"/tmp/seltable"; 11, block; 11, 12; 11, 15; 11, 19; 11, 29; 11, 246; 12, import_statement; 12, 13; 13, dotted_name; 13, 14; 14, identifier:os; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:viewed; 18, False; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:type; 22, subscript; 22, 23; 22, 28; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:info; 27, argument_list; 28, string:"type"; 29, if_statement; 29, 30; 29, 37; 30, boolean_operator:or; 30, 31; 30, 34; 31, comparison_operator:==; 31, 32; 31, 33; 32, identifier:type; 33, string:"Measurement Set"; 34, comparison_operator:==; 34, 35; 34, 36; 35, identifier:type; 36, string:"Image"; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 47; 39, comparison_operator:==; 39, 40; 39, 46; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:os; 43, identifier:system; 44, argument_list; 44, 45; 45, string:'test -x `which casaviewer` > /dev/null 2>&1'; 46, integer:0; 47, block; 47, 48; 47, 52; 47, 56; 47, 68; 47, 97; 47, 103; 47, 109; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:waitstr1; 51, string:""; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:waitstr2; 55, string:"foreground ..."; 56, if_statement; 56, 57; 56, 59; 57, not_operator; 57, 58; 58, identifier:wait; 59, block; 59, 60; 59, 64; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:waitstr1; 63, string:" &"; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:waitstr2; 67, string:"background ..."; 68, if_statement; 68, 69; 68, 74; 68, 86; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:iswritable; 73, argument_list; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:six; 79, identifier:print_; 80, argument_list; 80, 81; 81, binary_operator:+; 81, 82; 81, 85; 82, binary_operator:+; 82, 83; 82, 84; 83, string:"Flushing data and starting casaviewer "; 84, string:"in the "; 85, identifier:waitstr2; 86, else_clause; 86, 87; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:six; 92, identifier:print_; 93, argument_list; 93, 94; 94, binary_operator:+; 94, 95; 94, 96; 95, string:"Starting casaviewer in the "; 96, identifier:waitstr2; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:flush; 102, argument_list; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:unlock; 108, argument_list; 109, if_statement; 109, 110; 109, 126; 109, 146; 109, 219; 110, comparison_operator:==; 110, 111; 110, 125; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:os; 114, identifier:system; 115, argument_list; 115, 116; 116, binary_operator:+; 116, 117; 116, 124; 117, binary_operator:+; 117, 118; 117, 119; 118, string:'test -e '; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:name; 123, argument_list; 124, string:'/table.dat'; 125, integer:0; 126, block; 126, 127; 126, 142; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:os; 131, identifier:system; 132, argument_list; 132, 133; 133, binary_operator:+; 133, 134; 133, 141; 134, binary_operator:+; 134, 135; 134, 136; 135, string:'casaviewer '; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:name; 140, argument_list; 141, identifier:waitstr1; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:viewed; 145, True; 146, elif_clause; 146, 147; 146, 153; 147, comparison_operator:>; 147, 148; 147, 152; 148, call; 148, 149; 148, 150; 149, identifier:len; 150, argument_list; 150, 151; 151, identifier:tempname; 152, integer:0; 153, block; 153, 154; 153, 163; 153, 170; 153, 181; 153, 185; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:six; 158, identifier:print_; 159, argument_list; 159, 160; 160, binary_operator:+; 160, 161; 160, 162; 161, string:" making a persistent copy in table "; 162, identifier:tempname; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:copy; 168, argument_list; 168, 169; 169, identifier:tempname; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:os; 174, identifier:system; 175, argument_list; 175, 176; 176, binary_operator:+; 176, 177; 176, 180; 177, binary_operator:+; 177, 178; 177, 179; 178, string:'casaviewer '; 179, identifier:tempname; 180, identifier:waitstr1; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:viewed; 184, True; 185, if_statement; 185, 186; 185, 187; 185, 206; 186, identifier:wait; 187, block; 187, 188; 187, 194; 187, 201; 188, import_from_statement; 188, 189; 188, 192; 189, dotted_name; 189, 190; 189, 191; 190, identifier:casacore; 191, identifier:tables; 192, dotted_name; 192, 193; 193, identifier:tabledelete; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:six; 198, identifier:print_; 199, argument_list; 199, 200; 200, string:" finished viewing"; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 204; 203, identifier:tabledelete; 204, argument_list; 204, 205; 205, identifier:tempname; 206, else_clause; 206, 207; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:six; 212, identifier:print_; 213, argument_list; 213, 214; 214, binary_operator:+; 214, 215; 214, 218; 215, binary_operator:+; 215, 216; 215, 217; 216, string:" after viewing use tabledelete('"; 217, identifier:tempname; 218, string:"') to delete the copy"; 219, else_clause; 219, 220; 220, block; 220, 221; 220, 230; 220, 239; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:six; 225, identifier:print_; 226, argument_list; 226, 227; 227, binary_operator:+; 227, 228; 227, 229; 228, string:"Cannot browse because the table is "; 229, string:"in memory only."; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:six; 234, identifier:print_; 235, argument_list; 235, 236; 236, binary_operator:+; 236, 237; 236, 238; 237, string:"You can browse a (shallow) persistent "; 238, string:"copy of the table like:"; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:six; 243, identifier:print_; 244, argument_list; 244, 245; 245, string:" t.view(True, '/tmp/tab1')"; 246, if_statement; 246, 247; 246, 249; 247, not_operator; 247, 248; 248, identifier:viewed; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:browse; 255, argument_list; 255, 256; 255, 257; 256, identifier:wait; 257, identifier:tempname
def view(self, wait=True, tempname="/tmp/seltable"): import os viewed = False type = self.info()["type"] if type == "Measurement Set" or type == "Image": if os.system('test -x `which casaviewer` > /dev/null 2>&1') == 0: waitstr1 = "" waitstr2 = "foreground ..." if not wait: waitstr1 = " &" waitstr2 = "background ..." if self.iswritable(): six.print_("Flushing data and starting casaviewer " + "in the " + waitstr2) else: six.print_("Starting casaviewer in the " + waitstr2) self.flush() self.unlock() if os.system('test -e ' + self.name() + '/table.dat') == 0: os.system('casaviewer ' + self.name() + waitstr1) viewed = True elif len(tempname) > 0: six.print_(" making a persistent copy in table " + tempname) self.copy(tempname) os.system('casaviewer ' + tempname + waitstr1) viewed = True if wait: from casacore.tables import tabledelete six.print_(" finished viewing") tabledelete(tempname) else: six.print_(" after viewing use tabledelete('" + tempname + "') to delete the copy") else: six.print_("Cannot browse because the table is " + "in memory only.") six.print_("You can browse a (shallow) persistent " + "copy of the table like:") six.print_(" t.view(True, '/tmp/tab1')") if not viewed: self.browse(wait, tempname)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_repr_html_; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 56; 5, 60; 5, 64; 5, 112; 5, 131; 5, 135; 5, 156; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:out; 9, string:"<table class='taqltable' style='overflow-x:auto'>\n"; 10, if_statement; 10, 11; 10, 31; 11, not_operator; 11, 12; 12, parenthesized_expression; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:all; 15, argument_list; 15, 16; 16, list_comprehension; 16, 17; 16, 24; 17, comparison_operator:==; 17, 18; 17, 23; 18, subscript; 18, 19; 18, 20; 19, identifier:colname; 20, slice; 20, 21; 20, 22; 21, colon; 22, integer:4; 23, string:"Col_"; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:colname; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:colnames; 30, argument_list; 31, block; 31, 32; 31, 36; 31, 52; 32, expression_statement; 32, 33; 33, augmented_assignment:+=; 33, 34; 33, 35; 34, identifier:out; 35, string:"<tr>"; 36, for_statement; 36, 37; 36, 38; 36, 43; 37, identifier:colname; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:colnames; 42, argument_list; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, augmented_assignment:+=; 45, 46; 45, 47; 46, identifier:out; 47, binary_operator:+; 47, 48; 47, 51; 48, binary_operator:+; 48, 49; 48, 50; 49, string:"<th><b>"; 50, identifier:colname; 51, string:"</b></th>"; 52, expression_statement; 52, 53; 53, augmented_assignment:+=; 53, 54; 53, 55; 54, identifier:out; 55, string:"</tr>"; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:cropped; 59, False; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:rowcount; 63, integer:0; 64, for_statement; 64, 65; 64, 66; 64, 67; 65, identifier:row; 66, identifier:self; 67, block; 67, 68; 67, 81; 67, 85; 67, 89; 67, 98; 67, 102; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:rowout; 71, call; 71, 72; 71, 73; 72, identifier:_format_row; 73, argument_list; 73, 74; 73, 75; 73, 80; 74, identifier:row; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:colnames; 79, argument_list; 80, identifier:self; 81, expression_statement; 81, 82; 82, augmented_assignment:+=; 82, 83; 82, 84; 83, identifier:rowcount; 84, integer:1; 85, expression_statement; 85, 86; 86, augmented_assignment:+=; 86, 87; 86, 88; 87, identifier:out; 88, identifier:rowout; 89, if_statement; 89, 90; 89, 93; 90, comparison_operator:in; 90, 91; 90, 92; 91, string:"\n"; 92, identifier:rowout; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, augmented_assignment:+=; 95, 96; 95, 97; 96, identifier:out; 97, string:"\n"; 98, expression_statement; 98, 99; 99, augmented_assignment:+=; 99, 100; 99, 101; 100, identifier:out; 101, string:"\n"; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:>=; 103, 104; 103, 105; 104, identifier:rowcount; 105, integer:20; 106, block; 106, 107; 106, 111; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:cropped; 110, True; 111, break_statement; 112, if_statement; 112, 113; 112, 121; 113, comparison_operator:==; 113, 114; 113, 120; 114, subscript; 114, 115; 114, 116; 115, identifier:out; 116, slice; 116, 117; 116, 119; 117, unary_operator:-; 117, 118; 118, integer:2; 119, colon; 120, string:"\n\n"; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:out; 125, subscript; 125, 126; 125, 127; 126, identifier:out; 127, slice; 127, 128; 127, 129; 128, colon; 129, unary_operator:-; 129, 130; 130, integer:1; 131, expression_statement; 131, 132; 132, augmented_assignment:+=; 132, 133; 132, 134; 133, identifier:out; 134, string:"</table>"; 135, if_statement; 135, 136; 135, 137; 136, identifier:cropped; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, augmented_assignment:+=; 139, 140; 139, 141; 140, identifier:out; 141, parenthesized_expression; 141, 142; 142, binary_operator:+; 142, 143; 142, 155; 143, binary_operator:+; 143, 144; 143, 145; 144, string:"<p style='text-align:center'>("; 145, call; 145, 146; 145, 147; 146, identifier:str; 147, argument_list; 147, 148; 148, binary_operator:-; 148, 149; 148, 154; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:nrows; 153, argument_list; 154, integer:20; 155, string:" more rows)</p>\n"; 156, return_statement; 156, 157; 157, identifier:out
def _repr_html_(self): out = "<table class='taqltable' style='overflow-x:auto'>\n" if not(all([colname[:4] == "Col_" for colname in self.colnames()])): out += "<tr>" for colname in self.colnames(): out += "<th><b>"+colname+"</b></th>" out += "</tr>" cropped = False rowcount = 0 for row in self: rowout = _format_row(row, self.colnames(), self) rowcount += 1 out += rowout if "\n" in rowout: out += "\n" out += "\n" if rowcount >= 20: cropped = True break if out[-2:] == "\n\n": out = out[:-1] out += "</table>" if cropped: out += ("<p style='text-align:center'>(" + str(self.nrows()-20)+" more rows)</p>\n") return out
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:handle_import; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:compilation; 7, identifier:rule; 8, block; 8, 9; 8, 16; 8, 27; 8, 52; 8, 58; 8, 62; 8, 111; 8, 127; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:path; 12, call; 12, 13; 12, 14; 13, identifier:PurePosixPath; 14, argument_list; 14, 15; 15, identifier:name; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:search_exts; 19, call; 19, 20; 19, 21; 20, identifier:list; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:compilation; 25, identifier:compiler; 26, identifier:dynamic_extensions; 27, if_statement; 27, 28; 27, 37; 27, 44; 28, boolean_operator:and; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:path; 31, identifier:suffix; 32, comparison_operator:in; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:path; 35, identifier:suffix; 36, identifier:search_exts; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:basename; 41, attribute; 41, 42; 41, 43; 42, identifier:path; 43, identifier:stem; 44, else_clause; 44, 45; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:basename; 49, attribute; 49, 50; 49, 51; 50, identifier:path; 51, identifier:name; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:relative_to; 55, attribute; 55, 56; 55, 57; 56, identifier:path; 57, identifier:parent; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:search_path; 61, list:[]; 62, if_statement; 62, 63; 62, 68; 62, 83; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:relative_to; 66, identifier:is_absolute; 67, argument_list; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:relative_to; 72, call; 72, 73; 72, 74; 73, identifier:PurePosixPath; 74, argument_list; 74, 75; 75, list_splat; 75, 76; 76, subscript; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:relative_to; 79, identifier:parts; 80, slice; 80, 81; 80, 82; 81, integer:1; 82, colon; 83, elif_clause; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:rule; 87, identifier:source_file; 88, identifier:origin; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:search_path; 94, identifier:append; 95, argument_list; 95, 96; 96, tuple; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:rule; 100, identifier:source_file; 101, identifier:origin; 102, binary_operator:/; 102, 103; 102, 110; 103, attribute; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:rule; 107, identifier:source_file; 108, identifier:relpath; 109, identifier:parent; 110, identifier:relative_to; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:search_path; 115, identifier:extend; 116, generator_expression; 116, 117; 116, 120; 117, tuple; 117, 118; 117, 119; 118, identifier:origin; 119, identifier:relative_to; 120, for_in_clause; 120, 121; 120, 122; 121, identifier:origin; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:compilation; 125, identifier:compiler; 126, identifier:search_path; 127, for_statement; 127, 128; 127, 131; 127, 138; 128, pattern_list; 128, 129; 128, 130; 129, identifier:prefix; 130, identifier:suffix; 131, call; 131, 132; 131, 133; 132, identifier:product; 133, argument_list; 133, 134; 133, 137; 134, tuple; 134, 135; 134, 136; 135, string:'_'; 136, string:''; 137, identifier:search_exts; 138, block; 138, 139; 138, 147; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:filename; 142, binary_operator:+; 142, 143; 142, 146; 143, binary_operator:+; 143, 144; 143, 145; 144, identifier:prefix; 145, identifier:basename; 146, identifier:suffix; 147, for_statement; 147, 148; 147, 151; 147, 152; 148, pattern_list; 148, 149; 148, 150; 149, identifier:origin; 150, identifier:relative_to; 151, identifier:search_path; 152, block; 152, 153; 152, 159; 152, 176; 152, 188; 152, 194; 152, 203; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:relpath; 156, binary_operator:/; 156, 157; 156, 158; 157, identifier:relative_to; 158, identifier:filename; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:relpath; 162, call; 162, 163; 162, 164; 163, identifier:PurePosixPath; 164, argument_list; 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:normpath; 171, argument_list; 171, 172; 172, call; 172, 173; 172, 174; 173, identifier:str; 174, argument_list; 174, 175; 175, identifier:relpath; 176, if_statement; 176, 177; 176, 186; 177, comparison_operator:==; 177, 178; 177, 183; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:rule; 181, identifier:source_file; 182, identifier:key; 183, tuple; 183, 184; 183, 185; 184, identifier:origin; 185, identifier:relpath; 186, block; 186, 187; 187, continue_statement; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:path; 191, binary_operator:/; 191, 192; 191, 193; 192, identifier:origin; 193, identifier:relpath; 194, if_statement; 194, 195; 194, 201; 195, not_operator; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:path; 199, identifier:exists; 200, argument_list; 201, block; 201, 202; 202, continue_statement; 203, return_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:SourceFile; 207, identifier:read; 208, argument_list; 208, 209; 208, 210; 209, identifier:origin; 210, identifier:relpath
def handle_import(self, name, compilation, rule): path = PurePosixPath(name) search_exts = list(compilation.compiler.dynamic_extensions) if path.suffix and path.suffix in search_exts: basename = path.stem else: basename = path.name relative_to = path.parent search_path = [] if relative_to.is_absolute(): relative_to = PurePosixPath(*relative_to.parts[1:]) elif rule.source_file.origin: search_path.append(( rule.source_file.origin, rule.source_file.relpath.parent / relative_to, )) search_path.extend( (origin, relative_to) for origin in compilation.compiler.search_path ) for prefix, suffix in product(('_', ''), search_exts): filename = prefix + basename + suffix for origin, relative_to in search_path: relpath = relative_to / filename relpath = PurePosixPath(os.path.normpath(str(relpath))) if rule.source_file.key == (origin, relpath): continue path = origin / relpath if not path.exists(): continue return SourceFile.read(origin, relpath)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_get_properties; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:rule; 6, identifier:scope; 7, identifier:block; 8, block; 8, 9; 8, 31; 8, 44; 8, 67; 8, 76; 8, 87; 8, 95; 8, 104; 8, 109; 8, 118; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11, pattern_list; 11, 12; 11, 13; 12, identifier:prop; 13, identifier:raw_value; 14, subscript; 14, 15; 14, 28; 15, parenthesized_expression; 15, 16; 16, binary_operator:+; 16, 17; 16, 26; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:_prop_split_re; 20, identifier:split; 21, argument_list; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:block; 24, identifier:prop; 25, integer:1; 26, list:[None]; 26, 27; 27, None; 28, slice; 28, 29; 28, 30; 29, colon; 30, integer:2; 31, if_statement; 31, 32; 31, 35; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:raw_value; 34, None; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:raw_value; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:raw_value; 42, identifier:strip; 43, argument_list; 44, try_statement; 44, 45; 44, 60; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:is_var; 49, parenthesized_expression; 49, 50; 50, comparison_operator:==; 50, 51; 50, 59; 51, subscript; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:block; 54, identifier:prop; 55, call; 55, 56; 55, 57; 56, identifier:len; 57, argument_list; 57, 58; 58, identifier:prop; 59, string:'='; 60, except_clause; 60, 61; 60, 62; 61, identifier:IndexError; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:is_var; 66, False; 67, if_statement; 67, 68; 67, 69; 68, identifier:is_var; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:warn_deprecated; 73, argument_list; 73, 74; 73, 75; 74, identifier:rule; 75, string:"Assignment with = is deprecated; use : instead."; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:calculator; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:_make_calculator; 83, argument_list; 83, 84; 84, attribute; 84, 85; 84, 86; 85, identifier:rule; 86, identifier:namespace; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:prop; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:prop; 93, identifier:strip; 94, argument_list; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:prop; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:calculator; 101, identifier:do_glob_math; 102, argument_list; 102, 103; 103, identifier:prop; 104, if_statement; 104, 105; 104, 107; 105, not_operator; 105, 106; 106, identifier:prop; 107, block; 107, 108; 108, return_statement; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:_prop; 112, binary_operator:+; 112, 113; 112, 117; 113, parenthesized_expression; 113, 114; 114, boolean_operator:or; 114, 115; 114, 116; 115, identifier:scope; 116, string:''; 117, identifier:prop; 118, if_statement; 118, 119; 118, 131; 118, 306; 119, boolean_operator:or; 119, 120; 119, 121; 120, identifier:is_var; 121, boolean_operator:and; 121, 122; 121, 128; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:prop; 125, identifier:startswith; 126, argument_list; 126, 127; 127, string:'$'; 128, comparison_operator:is; 128, 129; 128, 130; 129, identifier:raw_value; 130, None; 131, block; 131, 132; 131, 136; 131, 140; 131, 208; 131, 215; 131, 235; 131, 246; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:is_default; 135, False; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:is_global; 139, True; 140, while_statement; 140, 141; 140, 142; 141, True; 142, block; 142, 143; 142, 153; 142, 172; 142, 178; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:splits; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:raw_value; 149, identifier:rsplit; 150, argument_list; 150, 151; 150, 152; 151, None; 152, integer:1; 153, if_statement; 153, 154; 153, 170; 154, boolean_operator:or; 154, 155; 154, 161; 155, comparison_operator:<; 155, 156; 155, 160; 156, call; 156, 157; 156, 158; 157, identifier:len; 158, argument_list; 158, 159; 159, identifier:splits; 160, integer:2; 161, not_operator; 161, 162; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:splits; 166, integer:1; 167, identifier:startswith; 168, argument_list; 168, 169; 169, string:'!'; 170, block; 170, 171; 171, break_statement; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 177; 174, pattern_list; 174, 175; 174, 176; 175, identifier:raw_value; 176, identifier:flag; 177, identifier:splits; 178, if_statement; 178, 179; 178, 182; 178, 187; 178, 196; 179, comparison_operator:==; 179, 180; 179, 181; 180, identifier:flag; 181, string:'!default'; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:is_default; 186, True; 187, elif_clause; 187, 188; 187, 191; 188, comparison_operator:==; 188, 189; 188, 190; 189, identifier:flag; 190, string:'!global'; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:is_global; 195, True; 196, else_clause; 196, 197; 197, block; 197, 198; 198, raise_statement; 198, 199; 199, call; 199, 200; 199, 201; 200, identifier:ValueError; 201, argument_list; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, string:"Unrecognized flag: {0}"; 205, identifier:format; 206, argument_list; 206, 207; 207, identifier:flag; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:_prop; 211, call; 211, 212; 211, 213; 212, identifier:normalize_var; 213, argument_list; 213, 214; 214, identifier:_prop; 215, try_statement; 215, 216; 215, 228; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:existing_value; 220, call; 220, 221; 220, 226; 221, attribute; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:rule; 224, identifier:namespace; 225, identifier:variable; 226, argument_list; 226, 227; 227, identifier:_prop; 228, except_clause; 228, 229; 228, 230; 229, identifier:KeyError; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:existing_value; 234, None; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:is_defined; 238, boolean_operator:and; 238, 239; 238, 242; 239, comparison_operator:is; 239, 240; 239, 241; 240, identifier:existing_value; 241, None; 242, not_operator; 242, 243; 243, attribute; 243, 244; 243, 245; 244, identifier:existing_value; 245, identifier:is_null; 246, if_statement; 246, 247; 246, 250; 246, 252; 247, boolean_operator:and; 247, 248; 247, 249; 248, identifier:is_default; 249, identifier:is_defined; 250, block; 250, 251; 251, pass_statement; 252, else_clause; 252, 253; 253, block; 253, 254; 253, 280; 253, 292; 254, if_statement; 254, 255; 254, 271; 255, boolean_operator:and; 255, 256; 255, 264; 256, boolean_operator:and; 256, 257; 256, 258; 257, identifier:is_defined; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:prop; 261, identifier:startswith; 262, argument_list; 262, 263; 263, string:'$'; 264, call; 264, 265; 264, 270; 265, attribute; 265, 266; 265, 269; 266, subscript; 266, 267; 266, 268; 267, identifier:prop; 268, integer:1; 269, identifier:isupper; 270, argument_list; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:log; 276, identifier:warn; 277, argument_list; 277, 278; 277, 279; 278, string:"Constant %r redefined"; 279, identifier:prop; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:value; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:calculator; 286, identifier:calculate; 287, argument_list; 287, 288; 287, 289; 288, identifier:raw_value; 289, keyword_argument; 289, 290; 289, 291; 290, identifier:divide; 291, True; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 299; 294, attribute; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:rule; 297, identifier:namespace; 298, identifier:set_variable; 299, argument_list; 299, 300; 299, 301; 299, 302; 300, identifier:_prop; 301, identifier:value; 302, keyword_argument; 302, 303; 302, 304; 303, identifier:local_only; 304, not_operator; 304, 305; 305, identifier:is_global; 306, else_clause; 306, 307; 307, block; 307, 308; 307, 317; 307, 337; 307, 394; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:_prop; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:calculator; 314, identifier:apply_vars; 315, argument_list; 315, 316; 316, identifier:_prop; 317, if_statement; 317, 318; 317, 321; 317, 326; 318, comparison_operator:is; 318, 319; 318, 320; 319, identifier:raw_value; 320, None; 321, block; 321, 322; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:value; 325, None; 326, else_clause; 326, 327; 327, block; 327, 328; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:value; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:calculator; 334, identifier:calculate; 335, argument_list; 335, 336; 336, identifier:raw_value; 337, if_statement; 337, 338; 337, 341; 337, 343; 337, 353; 338, comparison_operator:is; 338, 339; 338, 340; 339, identifier:value; 340, None; 341, block; 341, 342; 342, pass_statement; 343, elif_clause; 343, 344; 343, 351; 344, call; 344, 345; 344, 346; 345, identifier:isinstance; 346, argument_list; 346, 347; 346, 348; 347, identifier:value; 348, attribute; 348, 349; 348, 350; 349, identifier:six; 350, identifier:string_types; 351, block; 351, 352; 352, pass_statement; 353, else_clause; 353, 354; 354, block; 354, 355; 354, 361; 354, 377; 354, 383; 355, if_statement; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:value; 358, identifier:is_null; 359, block; 359, 360; 360, return_statement; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 364; 363, identifier:style; 364, call; 364, 365; 364, 370; 365, attribute; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:rule; 368, identifier:legacy_compiler_options; 369, identifier:get; 370, argument_list; 370, 371; 370, 372; 371, string:'style'; 372, attribute; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:self; 375, identifier:compiler; 376, identifier:output_style; 377, expression_statement; 377, 378; 378, assignment; 378, 379; 378, 380; 379, identifier:compress; 380, comparison_operator:==; 380, 381; 380, 382; 381, identifier:style; 382, string:'compressed'; 383, expression_statement; 383, 384; 384, assignment; 384, 385; 384, 386; 385, identifier:value; 386, call; 386, 387; 386, 390; 387, attribute; 387, 388; 387, 389; 388, identifier:value; 389, identifier:render; 390, argument_list; 390, 391; 391, keyword_argument; 391, 392; 391, 393; 392, identifier:compress; 393, identifier:compress; 394, expression_statement; 394, 395; 395, call; 395, 396; 395, 401; 396, attribute; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:rule; 399, identifier:properties; 400, identifier:append; 401, argument_list; 401, 402; 402, tuple; 402, 403; 402, 404; 403, identifier:_prop; 404, identifier:value
def _get_properties(self, rule, scope, block): prop, raw_value = (_prop_split_re.split(block.prop, 1) + [None])[:2] if raw_value is not None: raw_value = raw_value.strip() try: is_var = (block.prop[len(prop)] == '=') except IndexError: is_var = False if is_var: warn_deprecated(rule, "Assignment with = is deprecated; use : instead.") calculator = self._make_calculator(rule.namespace) prop = prop.strip() prop = calculator.do_glob_math(prop) if not prop: return _prop = (scope or '') + prop if is_var or prop.startswith('$') and raw_value is not None: is_default = False is_global = True while True: splits = raw_value.rsplit(None, 1) if len(splits) < 2 or not splits[1].startswith('!'): break raw_value, flag = splits if flag == '!default': is_default = True elif flag == '!global': is_global = True else: raise ValueError("Unrecognized flag: {0}".format(flag)) _prop = normalize_var(_prop) try: existing_value = rule.namespace.variable(_prop) except KeyError: existing_value = None is_defined = existing_value is not None and not existing_value.is_null if is_default and is_defined: pass else: if is_defined and prop.startswith('$') and prop[1].isupper(): log.warn("Constant %r redefined", prop) value = calculator.calculate(raw_value, divide=True) rule.namespace.set_variable( _prop, value, local_only=not is_global) else: _prop = calculator.apply_vars(_prop) if raw_value is None: value = None else: value = calculator.calculate(raw_value) if value is None: pass elif isinstance(value, six.string_types): pass else: if value.is_null: return style = rule.legacy_compiler_options.get( 'style', self.compiler.output_style) compress = style == 'compressed' value = value.render(compress=compress) rule.properties.append((_prop, value))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:longest_common_subsequence; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:a; 5, identifier:b; 6, default_parameter; 6, 7; 6, 8; 7, identifier:mergefunc; 8, None; 9, block; 9, 10; 9, 30; 9, 34; 9, 63; 9, 67; 9, 152; 9, 161; 9, 170; 9, 174; 9, 238; 9, 244; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:mergefunc; 13, None; 14, block; 14, 15; 15, function_definition; 15, 16; 15, 17; 15, 20; 16, function_name:mergefunc; 17, parameters; 17, 18; 17, 19; 18, identifier:a; 19, identifier:b; 20, block; 20, 21; 20, 28; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:==; 22, 23; 22, 24; 23, identifier:a; 24, identifier:b; 25, block; 25, 26; 26, return_statement; 26, 27; 27, identifier:a; 28, return_statement; 28, 29; 29, None; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:eq; 33, dictionary; 34, for_statement; 34, 35; 34, 38; 34, 42; 35, pattern_list; 35, 36; 35, 37; 36, identifier:ai; 37, identifier:aval; 38, call; 38, 39; 38, 40; 39, identifier:enumerate; 40, argument_list; 40, 41; 41, identifier:a; 42, block; 42, 43; 43, for_statement; 43, 44; 43, 47; 43, 51; 44, pattern_list; 44, 45; 44, 46; 45, identifier:bi; 46, identifier:bval; 47, call; 47, 48; 47, 49; 48, identifier:enumerate; 49, argument_list; 49, 50; 50, identifier:b; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 58; 54, subscript; 54, 55; 54, 56; 54, 57; 55, identifier:eq; 56, identifier:ai; 57, identifier:bi; 58, call; 58, 59; 58, 60; 59, identifier:mergefunc; 60, argument_list; 60, 61; 60, 62; 61, identifier:aval; 62, identifier:bval; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:prefix_lcs_length; 66, dictionary; 67, for_statement; 67, 68; 67, 69; 67, 78; 68, identifier:ai; 69, call; 69, 70; 69, 71; 70, identifier:range; 71, argument_list; 71, 72; 71, 74; 72, unary_operator:-; 72, 73; 73, integer:1; 74, call; 74, 75; 74, 76; 75, identifier:len; 76, argument_list; 76, 77; 77, identifier:a; 78, block; 78, 79; 79, for_statement; 79, 80; 79, 81; 79, 90; 80, identifier:bi; 81, call; 81, 82; 81, 83; 82, identifier:range; 83, argument_list; 83, 84; 83, 86; 84, unary_operator:-; 84, 85; 85, integer:1; 86, call; 86, 87; 86, 88; 87, identifier:len; 88, argument_list; 88, 89; 89, identifier:b; 90, block; 90, 91; 90, 145; 91, if_statement; 91, 92; 91, 101; 91, 106; 91, 125; 92, boolean_operator:or; 92, 93; 92, 97; 93, comparison_operator:==; 93, 94; 93, 95; 94, identifier:ai; 95, unary_operator:-; 95, 96; 96, integer:1; 97, comparison_operator:==; 97, 98; 97, 99; 98, identifier:bi; 99, unary_operator:-; 99, 100; 100, integer:1; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:l; 105, integer:0; 106, elif_clause; 106, 107; 106, 111; 107, subscript; 107, 108; 107, 109; 107, 110; 108, identifier:eq; 109, identifier:ai; 110, identifier:bi; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:l; 115, binary_operator:+; 115, 116; 115, 124; 116, subscript; 116, 117; 116, 118; 116, 121; 117, identifier:prefix_lcs_length; 118, binary_operator:-; 118, 119; 118, 120; 119, identifier:ai; 120, integer:1; 121, binary_operator:-; 121, 122; 121, 123; 122, identifier:bi; 123, integer:1; 124, integer:1; 125, else_clause; 125, 126; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:l; 130, call; 130, 131; 130, 132; 131, identifier:max; 132, argument_list; 132, 133; 132, 139; 133, subscript; 133, 134; 133, 135; 133, 136; 134, identifier:prefix_lcs_length; 135, identifier:ai; 136, binary_operator:-; 136, 137; 136, 138; 137, identifier:bi; 138, integer:1; 139, subscript; 139, 140; 139, 141; 139, 144; 140, identifier:prefix_lcs_length; 141, binary_operator:-; 141, 142; 141, 143; 142, identifier:ai; 143, integer:1; 144, identifier:bi; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 151; 147, subscript; 147, 148; 147, 149; 147, 150; 148, identifier:prefix_lcs_length; 149, identifier:ai; 150, identifier:bi; 151, identifier:l; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:ai; 155, binary_operator:-; 155, 156; 155, 160; 156, call; 156, 157; 156, 158; 157, identifier:len; 158, argument_list; 158, 159; 159, identifier:a; 160, integer:1; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:bi; 164, binary_operator:-; 164, 165; 164, 169; 165, call; 165, 166; 165, 167; 166, identifier:len; 167, argument_list; 167, 168; 168, identifier:b; 169, integer:1; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:ret; 173, list:[]; 174, while_statement; 174, 175; 174, 182; 175, boolean_operator:and; 175, 176; 175, 179; 176, comparison_operator:>=; 176, 177; 176, 178; 177, identifier:ai; 178, integer:0; 179, comparison_operator:>=; 179, 180; 179, 181; 180, identifier:bi; 181, integer:0; 182, block; 182, 183; 182, 190; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:merged; 186, subscript; 186, 187; 186, 188; 186, 189; 187, identifier:eq; 188, identifier:ai; 189, identifier:bi; 190, if_statement; 190, 191; 190, 194; 190, 213; 190, 232; 191, comparison_operator:is; 191, 192; 191, 193; 192, identifier:merged; 193, None; 194, block; 194, 195; 194, 205; 194, 209; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:ret; 199, identifier:append; 200, argument_list; 200, 201; 201, tuple; 201, 202; 201, 203; 201, 204; 202, identifier:ai; 203, identifier:bi; 204, identifier:merged; 205, expression_statement; 205, 206; 206, augmented_assignment:-=; 206, 207; 206, 208; 207, identifier:ai; 208, integer:1; 209, expression_statement; 209, 210; 210, augmented_assignment:-=; 210, 211; 210, 212; 211, identifier:bi; 212, integer:1; 213, elif_clause; 213, 214; 213, 227; 214, comparison_operator:>; 214, 215; 214, 221; 215, subscript; 215, 216; 215, 217; 215, 218; 216, identifier:prefix_lcs_length; 217, identifier:ai; 218, binary_operator:-; 218, 219; 218, 220; 219, identifier:bi; 220, integer:1; 221, subscript; 221, 222; 221, 223; 221, 226; 222, identifier:prefix_lcs_length; 223, binary_operator:-; 223, 224; 223, 225; 224, identifier:ai; 225, integer:1; 226, identifier:bi; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, augmented_assignment:-=; 229, 230; 229, 231; 230, identifier:bi; 231, integer:1; 232, else_clause; 232, 233; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, augmented_assignment:-=; 235, 236; 235, 237; 236, identifier:ai; 237, integer:1; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:ret; 242, identifier:reverse; 243, argument_list; 244, return_statement; 244, 245; 245, identifier:ret
def longest_common_subsequence(a, b, mergefunc=None): if mergefunc is None: def mergefunc(a, b): if a == b: return a return None eq = {} for ai, aval in enumerate(a): for bi, bval in enumerate(b): eq[ai, bi] = mergefunc(aval, bval) prefix_lcs_length = {} for ai in range(-1, len(a)): for bi in range(-1, len(b)): if ai == -1 or bi == -1: l = 0 elif eq[ai, bi]: l = prefix_lcs_length[ai - 1, bi - 1] + 1 else: l = max( prefix_lcs_length[ai, bi - 1], prefix_lcs_length[ai - 1, bi]) prefix_lcs_length[ai, bi] = l ai = len(a) - 1 bi = len(b) - 1 ret = [] while ai >= 0 and bi >= 0: merged = eq[ai, bi] if merged is not None: ret.append((ai, bi, merged)) ai -= 1 bi -= 1 elif prefix_lcs_length[ai, bi - 1] > prefix_lcs_length[ai - 1, bi]: bi -= 1 else: ai -= 1 ret.reverse() return ret
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:determine_encoding; 3, parameters; 3, 4; 4, identifier:buf; 5, block; 5, 6; 5, 10; 5, 16; 5, 84; 5, 105; 5, 147; 5, 217; 5, 226; 5, 235; 5, 324; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:bom_encoding; 9, string:'UTF-8'; 10, if_statement; 10, 11; 10, 13; 11, not_operator; 11, 12; 12, identifier:buf; 13, block; 13, 14; 14, return_statement; 14, 15; 15, identifier:bom_encoding; 16, if_statement; 16, 17; 16, 24; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:buf; 21, attribute; 21, 22; 21, 23; 22, identifier:six; 23, identifier:text_type; 24, block; 24, 25; 24, 40; 24, 44; 24, 48; 25, if_statement; 25, 26; 25, 31; 26, comparison_operator:==; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:buf; 29, integer:0; 30, string:'\ufeff'; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:buf; 35, subscript; 35, 36; 35, 37; 36, identifier:buf; 37, slice; 37, 38; 37, 39; 38, integer:0; 39, colon; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:charset_start; 43, string:'@charset "'; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:charset_end; 47, string:'";'; 48, if_statement; 48, 49; 48, 55; 48, 80; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:buf; 52, identifier:startswith; 53, argument_list; 53, 54; 54, identifier:charset_start; 55, block; 55, 56; 55, 63; 55, 73; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:start; 59, call; 59, 60; 59, 61; 60, identifier:len; 61, argument_list; 61, 62; 62, identifier:charset_start; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:end; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:buf; 69, identifier:index; 70, argument_list; 70, 71; 70, 72; 71, identifier:charset_end; 72, identifier:start; 73, return_statement; 73, 74; 74, subscript; 74, 75; 74, 76; 75, identifier:buf; 76, slice; 76, 77; 76, 78; 76, 79; 77, identifier:start; 78, colon; 79, identifier:end; 80, else_clause; 80, 81; 81, block; 81, 82; 82, return_statement; 82, 83; 83, identifier:bom_encoding; 84, if_statement; 84, 85; 84, 92; 85, comparison_operator:==; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 88; 87, identifier:buf; 88, slice; 88, 89; 88, 90; 89, colon; 90, integer:3; 91, string:b'\xef\xbb\xbf'; 92, block; 92, 93; 92, 97; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:bom_encoding; 96, string:'UTF-8'; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:buf; 100, subscript; 100, 101; 100, 102; 101, identifier:buf; 102, slice; 102, 103; 102, 104; 103, integer:3; 104, colon; 105, if_statement; 105, 106; 105, 113; 105, 126; 106, comparison_operator:==; 106, 107; 106, 112; 107, subscript; 107, 108; 107, 109; 108, identifier:buf; 109, slice; 109, 110; 109, 111; 110, colon; 111, integer:4; 112, string:b'\x00\x00\xfe\xff'; 113, block; 113, 114; 113, 118; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:bom_encoding; 117, string:'UTF-32BE'; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:buf; 121, subscript; 121, 122; 121, 123; 122, identifier:buf; 123, slice; 123, 124; 123, 125; 124, integer:4; 125, colon; 126, elif_clause; 126, 127; 126, 134; 127, comparison_operator:==; 127, 128; 127, 133; 128, subscript; 128, 129; 128, 130; 129, identifier:buf; 130, slice; 130, 131; 130, 132; 131, colon; 132, integer:4; 133, string:b'\xff\xfe\x00\x00'; 134, block; 134, 135; 134, 139; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:bom_encoding; 138, string:'UTF-32LE'; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:buf; 142, subscript; 142, 143; 142, 144; 143, identifier:buf; 144, slice; 144, 145; 144, 146; 145, integer:4; 146, colon; 147, if_statement; 147, 148; 147, 155; 147, 161; 147, 175; 147, 196; 148, comparison_operator:==; 148, 149; 148, 154; 149, subscript; 149, 150; 149, 151; 150, identifier:buf; 151, slice; 151, 152; 151, 153; 152, colon; 153, integer:4; 154, string:b'\x00\x00\xff\xfe'; 155, block; 155, 156; 156, raise_statement; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:UnicodeError; 159, argument_list; 159, 160; 160, string:"UTF-32-2143 is not supported"; 161, elif_clause; 161, 162; 161, 169; 162, comparison_operator:==; 162, 163; 162, 168; 163, subscript; 163, 164; 163, 165; 164, identifier:buf; 165, slice; 165, 166; 165, 167; 166, colon; 167, integer:4; 168, string:b'\xfe\xff\x00\x00'; 169, block; 169, 170; 170, raise_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:UnicodeError; 173, argument_list; 173, 174; 174, string:"UTF-32-2143 is not supported"; 175, elif_clause; 175, 176; 175, 183; 176, comparison_operator:==; 176, 177; 176, 182; 177, subscript; 177, 178; 177, 179; 178, identifier:buf; 179, slice; 179, 180; 179, 181; 180, colon; 181, integer:2; 182, string:b'\xfe\xff'; 183, block; 183, 184; 183, 188; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:bom_encoding; 187, string:'UTF-16BE'; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:buf; 191, subscript; 191, 192; 191, 193; 192, identifier:buf; 193, slice; 193, 194; 193, 195; 194, integer:2; 195, colon; 196, elif_clause; 196, 197; 196, 204; 197, comparison_operator:==; 197, 198; 197, 203; 198, subscript; 198, 199; 198, 200; 199, identifier:buf; 200, slice; 200, 201; 200, 202; 201, colon; 202, integer:2; 203, string:b'\xff\xfe'; 204, block; 204, 205; 204, 209; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:bom_encoding; 208, string:'UTF-16LE'; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:buf; 212, subscript; 212, 213; 212, 214; 213, identifier:buf; 214, slice; 214, 215; 214, 216; 215, integer:2; 216, colon; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:charset_start; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, string:'@charset "'; 223, identifier:encode; 224, argument_list; 224, 225; 225, identifier:bom_encoding; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:charset_end; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, string:'";'; 232, identifier:encode; 233, argument_list; 233, 234; 234, identifier:bom_encoding; 235, if_statement; 235, 236; 235, 242; 235, 318; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:buf; 239, identifier:startswith; 240, argument_list; 240, 241; 241, identifier:charset_start; 242, block; 242, 243; 242, 250; 242, 260; 242, 269; 242, 278; 242, 291; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:start; 246, call; 246, 247; 246, 248; 247, identifier:len; 248, argument_list; 248, 249; 249, identifier:charset_start; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:end; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:buf; 256, identifier:index; 257, argument_list; 257, 258; 257, 259; 258, identifier:charset_end; 259, identifier:start; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:encoded_encoding; 263, subscript; 263, 264; 263, 265; 264, identifier:buf; 265, slice; 265, 266; 265, 267; 265, 268; 266, identifier:start; 267, colon; 268, identifier:end; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:encoding; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:encoded_encoding; 275, identifier:decode; 276, argument_list; 276, 277; 277, identifier:bom_encoding; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:encoded_charset; 281, subscript; 281, 282; 281, 283; 282, identifier:buf; 283, slice; 283, 284; 283, 285; 284, colon; 285, binary_operator:+; 285, 286; 285, 287; 286, identifier:end; 287, call; 287, 288; 287, 289; 288, identifier:len; 289, argument_list; 289, 290; 290, identifier:charset_end; 291, if_statement; 291, 292; 291, 306; 292, parenthesized_expression; 292, 293; 293, comparison_operator:!=; 293, 294; 293, 300; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:encoded_charset; 297, identifier:decode; 298, argument_list; 298, 299; 299, identifier:encoding; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:encoded_charset; 303, identifier:decode; 304, argument_list; 304, 305; 305, identifier:bom_encoding; 306, block; 306, 307; 307, raise_statement; 307, 308; 308, call; 308, 309; 308, 310; 309, identifier:UnicodeError; 310, argument_list; 310, 311; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, string:"@charset {0} is incompatible with detected encoding {1}"; 314, identifier:format; 315, argument_list; 315, 316; 315, 317; 316, identifier:bom_encoding; 317, identifier:encoding; 318, else_clause; 318, 319; 319, block; 319, 320; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:encoding; 323, identifier:bom_encoding; 324, return_statement; 324, 325; 325, identifier:encoding
def determine_encoding(buf): bom_encoding = 'UTF-8' if not buf: return bom_encoding if isinstance(buf, six.text_type): if buf[0] == '\ufeff': buf = buf[0:] charset_start = '@charset "' charset_end = '";' if buf.startswith(charset_start): start = len(charset_start) end = buf.index(charset_end, start) return buf[start:end] else: return bom_encoding if buf[:3] == b'\xef\xbb\xbf': bom_encoding = 'UTF-8' buf = buf[3:] if buf[:4] == b'\x00\x00\xfe\xff': bom_encoding = 'UTF-32BE' buf = buf[4:] elif buf[:4] == b'\xff\xfe\x00\x00': bom_encoding = 'UTF-32LE' buf = buf[4:] if buf[:4] == b'\x00\x00\xff\xfe': raise UnicodeError("UTF-32-2143 is not supported") elif buf[:4] == b'\xfe\xff\x00\x00': raise UnicodeError("UTF-32-2143 is not supported") elif buf[:2] == b'\xfe\xff': bom_encoding = 'UTF-16BE' buf = buf[2:] elif buf[:2] == b'\xff\xfe': bom_encoding = 'UTF-16LE' buf = buf[2:] charset_start = '@charset "'.encode(bom_encoding) charset_end = '";'.encode(bom_encoding) if buf.startswith(charset_start): start = len(charset_start) end = buf.index(charset_end, start) encoded_encoding = buf[start:end] encoding = encoded_encoding.decode(bom_encoding) encoded_charset = buf[:end + len(charset_end)] if (encoded_charset.decode(encoding) != encoded_charset.decode(bom_encoding)): raise UnicodeError( "@charset {0} is incompatible with detected encoding {1}" .format(bom_encoding, encoding)) else: encoding = bom_encoding return encoding
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_draw_surfaces; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:surface; 6, identifier:offset; 7, identifier:surfaces; 8, block; 8, 9; 8, 15; 8, 21; 8, 31; 8, 39; 8, 47; 8, 58; 8, 64; 8, 70; 8, 93; 8, 102; 8, 109; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:surface_blit; 12, attribute; 12, 13; 12, 14; 13, identifier:surface; 14, identifier:blit; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:ox; 19, identifier:oy; 20, identifier:offset; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 26; 23, pattern_list; 23, 24; 23, 25; 24, identifier:left; 25, identifier:top; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_tile_view; 30, identifier:topleft; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:hit; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_layer_quadtree; 38, identifier:hit; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:get_tile; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:data; 46, identifier:get_tile_image; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:tile_layers; 50, call; 50, 51; 50, 52; 51, identifier:tuple; 52, argument_list; 52, 53; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:data; 57, identifier:visible_tile_layers; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:dirty; 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:dirty_append; 67, attribute; 67, 68; 67, 69; 68, identifier:dirty; 69, identifier:append; 70, function_definition; 70, 71; 70, 72; 70, 74; 71, function_name:sprite_sort; 72, parameters; 72, 73; 73, identifier:i; 74, block; 74, 75; 75, return_statement; 75, 76; 76, expression_list; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:i; 79, integer:2; 80, binary_operator:+; 80, 81; 80, 86; 81, subscript; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:i; 84, integer:1; 85, integer:1; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:i; 90, integer:0; 91, identifier:get_height; 92, argument_list; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:surfaces; 97, identifier:sort; 98, argument_list; 98, 99; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:key; 101, identifier:sprite_sort; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:layer_getter; 105, call; 105, 106; 105, 107; 106, identifier:itemgetter; 107, argument_list; 107, 108; 108, integer:2; 109, for_statement; 109, 110; 109, 113; 109, 118; 110, pattern_list; 110, 111; 110, 112; 111, identifier:layer; 112, identifier:group; 113, call; 113, 114; 113, 115; 114, identifier:groupby; 115, argument_list; 115, 116; 115, 117; 116, identifier:surfaces; 117, identifier:layer_getter; 118, block; 118, 119; 118, 124; 118, 169; 119, delete_statement; 119, 120; 120, subscript; 120, 121; 120, 122; 121, identifier:dirty; 122, slice; 122, 123; 123, colon; 124, for_statement; 124, 125; 124, 126; 124, 127; 125, identifier:i; 126, identifier:group; 127, block; 127, 128; 128, try_statement; 128, 129; 128, 136; 128, 152; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:flags; 133, subscript; 133, 134; 133, 135; 134, identifier:i; 135, integer:3; 136, except_clause; 136, 137; 136, 138; 137, identifier:IndexError; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:dirty_append; 142, argument_list; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:surface_blit; 145, argument_list; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:i; 148, integer:0; 149, subscript; 149, 150; 149, 151; 150, identifier:i; 151, integer:1; 152, else_clause; 152, 153; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:dirty_append; 157, argument_list; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:surface_blit; 160, argument_list; 160, 161; 160, 164; 160, 167; 160, 168; 161, subscript; 161, 162; 161, 163; 162, identifier:i; 163, integer:0; 164, subscript; 164, 165; 164, 166; 165, identifier:i; 166, integer:1; 167, None; 168, identifier:flags; 169, for_statement; 169, 170; 169, 171; 169, 172; 170, identifier:dirty_rect; 171, identifier:dirty; 172, block; 172, 173; 173, for_statement; 173, 174; 173, 175; 173, 185; 174, identifier:r; 175, call; 175, 176; 175, 177; 176, identifier:hit; 177, argument_list; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:dirty_rect; 181, identifier:move; 182, argument_list; 182, 183; 182, 184; 183, identifier:ox; 184, identifier:oy; 185, block; 185, 186; 185, 194; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 193; 188, pattern_list; 188, 189; 188, 190; 188, 191; 188, 192; 189, identifier:x; 190, identifier:y; 191, identifier:tw; 192, identifier:th; 193, identifier:r; 194, for_statement; 194, 195; 194, 196; 194, 207; 195, identifier:l; 196, list_comprehension; 196, 197; 196, 198; 196, 201; 197, identifier:i; 198, for_in_clause; 198, 199; 198, 200; 199, identifier:i; 200, identifier:tile_layers; 201, if_clause; 201, 202; 202, call; 202, 203; 202, 204; 203, identifier:gt; 204, argument_list; 204, 205; 204, 206; 205, identifier:i; 206, identifier:layer; 207, block; 207, 208; 207, 235; 207, 252; 208, if_statement; 208, 209; 208, 218; 209, boolean_operator:and; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:tall_sprites; 213, comparison_operator:==; 213, 214; 213, 215; 214, identifier:l; 215, binary_operator:+; 215, 216; 215, 217; 216, identifier:layer; 217, integer:1; 218, block; 218, 219; 219, if_statement; 219, 220; 219, 233; 220, comparison_operator:<=; 220, 221; 220, 226; 221, binary_operator:+; 221, 222; 221, 225; 222, binary_operator:-; 222, 223; 222, 224; 223, identifier:y; 224, identifier:oy; 225, identifier:th; 226, binary_operator:-; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:dirty_rect; 229, identifier:bottom; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:tall_sprites; 233, block; 233, 234; 234, continue_statement; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:tile; 238, call; 238, 239; 238, 240; 239, identifier:get_tile; 240, argument_list; 240, 241; 240, 246; 240, 251; 241, binary_operator:+; 241, 242; 241, 245; 242, binary_operator://; 242, 243; 242, 244; 243, identifier:x; 244, identifier:tw; 245, identifier:left; 246, binary_operator:+; 246, 247; 246, 250; 247, binary_operator://; 247, 248; 247, 249; 248, identifier:y; 249, identifier:th; 250, identifier:top; 251, identifier:l; 252, expression_statement; 252, 253; 253, boolean_operator:and; 253, 254; 253, 255; 254, identifier:tile; 255, call; 255, 256; 255, 257; 256, identifier:surface_blit; 257, argument_list; 257, 258; 257, 259; 258, identifier:tile; 259, tuple; 259, 260; 259, 263; 260, binary_operator:-; 260, 261; 260, 262; 261, identifier:x; 262, identifier:ox; 263, binary_operator:-; 263, 264; 263, 265; 264, identifier:y; 265, identifier:oy
def _draw_surfaces(self, surface, offset, surfaces): surface_blit = surface.blit ox, oy = offset left, top = self._tile_view.topleft hit = self._layer_quadtree.hit get_tile = self.data.get_tile_image tile_layers = tuple(self.data.visible_tile_layers) dirty = list() dirty_append = dirty.append def sprite_sort(i): return i[2], i[1][1] + i[0].get_height() surfaces.sort(key=sprite_sort) layer_getter = itemgetter(2) for layer, group in groupby(surfaces, layer_getter): del dirty[:] for i in group: try: flags = i[3] except IndexError: dirty_append(surface_blit(i[0], i[1])) else: dirty_append(surface_blit(i[0], i[1], None, flags)) for dirty_rect in dirty: for r in hit(dirty_rect.move(ox, oy)): x, y, tw, th = r for l in [i for i in tile_layers if gt(i, layer)]: if self.tall_sprites and l == layer + 1: if y - oy + th <= dirty_rect.bottom - self.tall_sprites: continue tile = get_tile(x // tw + left, y // th + top, l) tile and surface_blit(tile, (x - ox, y - oy))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_tile_images_by_rect; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:rect; 6, block; 6, 7; 6, 36; 6, 47; 6, 55; 6, 63; 6, 69; 6, 75; 6, 81; 6, 90; 7, function_definition; 7, 8; 7, 9; 7, 13; 8, function_name:rev; 9, parameters; 9, 10; 9, 11; 9, 12; 10, identifier:seq; 11, identifier:start; 12, identifier:stop; 13, block; 13, 14; 13, 23; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:<; 15, 16; 15, 17; 16, identifier:start; 17, integer:0; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:start; 22, integer:0; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:enumerate; 26, argument_list; 26, 27; 26, 35; 27, subscript; 27, 28; 27, 29; 28, identifier:seq; 29, slice; 29, 30; 29, 31; 29, 32; 30, identifier:start; 31, colon; 32, binary_operator:+; 32, 33; 32, 34; 33, identifier:stop; 34, integer:1; 35, identifier:start; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 43; 38, pattern_list; 38, 39; 38, 40; 38, 41; 38, 42; 39, identifier:x1; 40, identifier:y1; 41, identifier:x2; 42, identifier:y2; 43, call; 43, 44; 43, 45; 44, identifier:rect_to_bb; 45, argument_list; 45, 46; 46, identifier:rect; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:images; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:tmx; 54, identifier:images; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:layers; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:tmx; 62, identifier:layers; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:at; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:_animated_tile; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:tracked_gids; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:_tracked_gids; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:anim_map; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:_animation_map; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:track; 84, call; 84, 85; 84, 86; 85, identifier:bool; 86, argument_list; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_animation_queue; 90, for_statement; 90, 91; 90, 92; 90, 97; 91, identifier:l; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:tmx; 96, identifier:visible_tile_layers; 97, block; 97, 98; 98, for_statement; 98, 99; 98, 102; 98, 112; 99, pattern_list; 99, 100; 99, 101; 100, identifier:y; 101, identifier:row; 102, call; 102, 103; 102, 104; 103, identifier:rev; 104, argument_list; 104, 105; 104, 110; 104, 111; 105, attribute; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:layers; 108, identifier:l; 109, identifier:data; 110, identifier:y1; 111, identifier:y2; 112, block; 112, 113; 113, for_statement; 113, 114; 113, 117; 113, 131; 114, pattern_list; 114, 115; 114, 116; 115, identifier:x; 116, identifier:gid; 117, list_comprehension; 117, 118; 117, 119; 117, 127; 118, identifier:i; 119, for_in_clause; 119, 120; 119, 121; 120, identifier:i; 121, call; 121, 122; 121, 123; 122, identifier:rev; 123, argument_list; 123, 124; 123, 125; 123, 126; 124, identifier:row; 125, identifier:x1; 126, identifier:x2; 127, if_clause; 127, 128; 128, subscript; 128, 129; 128, 130; 129, identifier:i; 130, integer:1; 131, block; 131, 132; 131, 153; 132, if_statement; 132, 133; 132, 138; 133, boolean_operator:and; 133, 134; 133, 135; 134, identifier:track; 135, comparison_operator:in; 135, 136; 135, 137; 136, identifier:gid; 137, identifier:tracked_gids; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 148; 141, attribute; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:anim_map; 145, identifier:gid; 146, identifier:positions; 147, identifier:add; 148, argument_list; 148, 149; 149, tuple; 149, 150; 149, 151; 149, 152; 150, identifier:x; 151, identifier:y; 152, identifier:l; 153, try_statement; 153, 154; 153, 167; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, yield; 156, 157; 157, expression_list; 157, 158; 157, 159; 157, 160; 157, 161; 158, identifier:x; 159, identifier:y; 160, identifier:l; 161, subscript; 161, 162; 161, 163; 162, identifier:at; 163, tuple; 163, 164; 163, 165; 163, 166; 164, identifier:x; 165, identifier:y; 166, identifier:l; 167, except_clause; 167, 168; 167, 169; 168, identifier:KeyError; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, yield; 171, 172; 172, expression_list; 172, 173; 172, 174; 172, 175; 172, 176; 173, identifier:x; 174, identifier:y; 175, identifier:l; 176, subscript; 176, 177; 176, 178; 177, identifier:images; 178, identifier:gid
def get_tile_images_by_rect(self, rect): def rev(seq, start, stop): if start < 0: start = 0 return enumerate(seq[start:stop + 1], start) x1, y1, x2, y2 = rect_to_bb(rect) images = self.tmx.images layers = self.tmx.layers at = self._animated_tile tracked_gids = self._tracked_gids anim_map = self._animation_map track = bool(self._animation_queue) for l in self.tmx.visible_tile_layers: for y, row in rev(layers[l].data, y1, y2): for x, gid in [i for i in rev(row, x1, x2) if i[1]]: if track and gid in tracked_gids: anim_map[gid].positions.add((x, y, l)) try: yield x, y, l, at[(x, y, l)] except KeyError: yield x, y, l, images[gid]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:describe_pdb; 3, parameters; 3, 4; 4, identifier:pdb_id; 5, block; 5, 6; 5, 16; 5, 23; 5, 34; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:out; 9, call; 9, 10; 9, 11; 10, identifier:get_info; 11, argument_list; 11, 12; 11, 13; 12, identifier:pdb_id; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:url_root; 15, string:'http://www.rcsb.org/pdb/rest/describePDB?structureId='; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:out; 19, call; 19, 20; 19, 21; 20, identifier:to_dict; 21, argument_list; 21, 22; 22, identifier:out; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:out; 26, call; 26, 27; 26, 28; 27, identifier:remove_at_sign; 28, argument_list; 28, 29; 29, subscript; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:out; 32, string:'PDBdescription'; 33, string:'PDB'; 34, return_statement; 34, 35; 35, identifier:out
def describe_pdb(pdb_id): out = get_info(pdb_id, url_root = 'http://www.rcsb.org/pdb/rest/describePDB?structureId=') out = to_dict(out) out = remove_at_sign(out['PDBdescription']['PDB']) return out
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:download_file_from_google_drive; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:file_id; 5, identifier:dest_path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:overwrite; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:unzip; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:showsize; 14, False; 15, block; 15, 16; 15, 23; 15, 35; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:destination_directory; 19, call; 19, 20; 19, 21; 20, identifier:dirname; 21, argument_list; 21, 22; 22, identifier:dest_path; 23, if_statement; 23, 24; 23, 29; 24, not_operator; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:exists; 27, argument_list; 27, 28; 28, identifier:destination_directory; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:makedirs; 33, argument_list; 33, 34; 34, identifier:destination_directory; 35, if_statement; 35, 36; 35, 43; 36, boolean_operator:or; 36, 37; 36, 42; 37, not_operator; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:exists; 40, argument_list; 40, 41; 41, identifier:dest_path; 42, identifier:overwrite; 43, block; 43, 44; 43, 52; 43, 66; 43, 72; 43, 92; 43, 101; 43, 131; 43, 138; 43, 143; 43, 153; 43, 158; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:session; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:requests; 50, identifier:Session; 51, argument_list; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:print; 55, argument_list; 55, 56; 55, 63; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, string:'Downloading {} into {}... '; 59, identifier:format; 60, argument_list; 60, 61; 60, 62; 61, identifier:file_id; 62, identifier:dest_path; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:end; 65, string:''; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:stdout; 70, identifier:flush; 71, argument_list; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:response; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:session; 78, identifier:get; 79, argument_list; 79, 80; 79, 83; 79, 89; 80, attribute; 80, 81; 80, 82; 81, identifier:GoogleDriveDownloader; 82, identifier:DOWNLOAD_URL; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:params; 85, dictionary; 85, 86; 86, pair; 86, 87; 86, 88; 87, string:'id'; 88, identifier:file_id; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:stream; 91, True; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:token; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:GoogleDriveDownloader; 98, identifier:_get_confirm_token; 99, argument_list; 99, 100; 100, identifier:response; 101, if_statement; 101, 102; 101, 103; 102, identifier:token; 103, block; 103, 104; 103, 114; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:params; 107, dictionary; 107, 108; 107, 111; 108, pair; 108, 109; 108, 110; 109, string:'id'; 110, identifier:file_id; 111, pair; 111, 112; 111, 113; 112, string:'confirm'; 113, identifier:token; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:response; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:session; 120, identifier:get; 121, argument_list; 121, 122; 121, 125; 121, 128; 122, attribute; 122, 123; 122, 124; 123, identifier:GoogleDriveDownloader; 124, identifier:DOWNLOAD_URL; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:params; 127, identifier:params; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:stream; 130, True; 131, if_statement; 131, 132; 131, 133; 132, identifier:showsize; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:print; 137, argument_list; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:current_download_size; 141, list:[0]; 141, 142; 142, integer:0; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:GoogleDriveDownloader; 147, identifier:_save_response_content; 148, argument_list; 148, 149; 148, 150; 148, 151; 148, 152; 149, identifier:response; 150, identifier:dest_path; 151, identifier:showsize; 152, identifier:current_download_size; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:print; 156, argument_list; 156, 157; 157, string:'Done.'; 158, if_statement; 158, 159; 158, 160; 159, identifier:unzip; 160, block; 160, 161; 161, try_statement; 161, 162; 161, 203; 162, block; 162, 163; 162, 171; 162, 177; 162, 198; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:print; 166, argument_list; 166, 167; 166, 168; 167, string:'Unzipping...'; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:end; 170, string:''; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:stdout; 175, identifier:flush; 176, argument_list; 177, with_statement; 177, 178; 177, 190; 178, with_clause; 178, 179; 179, with_item; 179, 180; 180, as_pattern; 180, 181; 180, 188; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:zipfile; 184, identifier:ZipFile; 185, argument_list; 185, 186; 185, 187; 186, identifier:dest_path; 187, string:'r'; 188, as_pattern_target; 188, 189; 189, identifier:z; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:z; 195, identifier:extractall; 196, argument_list; 196, 197; 197, identifier:destination_directory; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 201; 200, identifier:print; 201, argument_list; 201, 202; 202, string:'Done.'; 203, except_clause; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:zipfile; 206, identifier:BadZipfile; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:warnings; 212, identifier:warn; 213, argument_list; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, string:'Ignoring `unzip` since "{}" does not look like a valid zip file'; 217, identifier:format; 218, argument_list; 218, 219; 219, identifier:file_id
def download_file_from_google_drive(file_id, dest_path, overwrite=False, unzip=False, showsize=False): destination_directory = dirname(dest_path) if not exists(destination_directory): makedirs(destination_directory) if not exists(dest_path) or overwrite: session = requests.Session() print('Downloading {} into {}... '.format(file_id, dest_path), end='') stdout.flush() response = session.get(GoogleDriveDownloader.DOWNLOAD_URL, params={'id': file_id}, stream=True) token = GoogleDriveDownloader._get_confirm_token(response) if token: params = {'id': file_id, 'confirm': token} response = session.get(GoogleDriveDownloader.DOWNLOAD_URL, params=params, stream=True) if showsize: print() current_download_size = [0] GoogleDriveDownloader._save_response_content(response, dest_path, showsize, current_download_size) print('Done.') if unzip: try: print('Unzipping...', end='') stdout.flush() with zipfile.ZipFile(dest_path, 'r') as z: z.extractall(destination_directory) print('Done.') except zipfile.BadZipfile: warnings.warn('Ignoring `unzip` since "{}" does not look like a valid zip file'.format(file_id))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:server_extensions_handshake; 3, parameters; 3, 4; 3, 5; 4, identifier:requested; 5, identifier:supported; 6, block; 6, 7; 6, 11; 6, 86; 6, 178; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:accepts; 10, dictionary; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:offer; 13, identifier:requested; 14, block; 14, 15; 14, 31; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:name; 18, call; 18, 19; 18, 30; 19, attribute; 19, 20; 19, 29; 20, subscript; 20, 21; 20, 28; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:offer; 24, identifier:split; 25, argument_list; 25, 26; 25, 27; 26, string:";"; 27, integer:1; 28, integer:0; 29, identifier:strip; 30, argument_list; 31, for_statement; 31, 32; 31, 33; 31, 34; 32, identifier:extension; 33, identifier:supported; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 41; 36, comparison_operator:==; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:extension; 39, identifier:name; 40, identifier:name; 41, block; 41, 42; 41, 51; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:accept; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:extension; 48, identifier:accept; 49, argument_list; 49, 50; 50, identifier:offer; 51, if_statement; 51, 52; 51, 55; 51, 64; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:accept; 54, True; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 63; 58, subscript; 58, 59; 58, 60; 59, identifier:accepts; 60, attribute; 60, 61; 60, 62; 61, identifier:extension; 62, identifier:name; 63, True; 64, elif_clause; 64, 65; 64, 72; 65, boolean_operator:and; 65, 66; 65, 69; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:accept; 68, False; 69, comparison_operator:is; 69, 70; 69, 71; 70, identifier:accept; 71, None; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 80; 75, subscript; 75, 76; 75, 77; 76, identifier:accepts; 77, attribute; 77, 78; 77, 79; 78, identifier:extension; 79, identifier:name; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:accept; 83, identifier:encode; 84, argument_list; 84, 85; 85, string:"ascii"; 86, if_statement; 86, 87; 86, 88; 87, identifier:accepts; 88, block; 88, 89; 88, 93; 88, 171; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:extensions; 92, list:[]; 93, for_statement; 93, 94; 93, 97; 93, 102; 94, pattern_list; 94, 95; 94, 96; 95, identifier:name; 96, identifier:params; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:accepts; 100, identifier:items; 101, argument_list; 102, block; 102, 103; 103, if_statement; 103, 104; 103, 107; 103, 120; 104, comparison_operator:is; 104, 105; 104, 106; 105, identifier:params; 106, True; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:extensions; 112, identifier:append; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:name; 117, identifier:encode; 118, argument_list; 118, 119; 119, string:"ascii"; 120, else_clause; 120, 121; 121, block; 121, 122; 121, 131; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:params; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:params; 128, identifier:decode; 129, argument_list; 129, 130; 130, string:"ascii"; 131, if_statement; 131, 132; 131, 135; 131, 152; 132, comparison_operator:==; 132, 133; 132, 134; 133, identifier:params; 134, string:""; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:extensions; 140, identifier:append; 141, argument_list; 141, 142; 142, call; 142, 143; 142, 150; 143, attribute; 143, 144; 143, 149; 144, parenthesized_expression; 144, 145; 145, binary_operator:%; 145, 146; 145, 147; 146, string:"%s"; 147, parenthesized_expression; 147, 148; 148, identifier:name; 149, identifier:encode; 150, argument_list; 150, 151; 151, string:"ascii"; 152, else_clause; 152, 153; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:extensions; 158, identifier:append; 159, argument_list; 159, 160; 160, call; 160, 161; 160, 169; 161, attribute; 161, 162; 161, 168; 162, parenthesized_expression; 162, 163; 163, binary_operator:%; 163, 164; 163, 165; 164, string:"%s; %s"; 165, tuple; 165, 166; 165, 167; 166, identifier:name; 167, identifier:params; 168, identifier:encode; 169, argument_list; 169, 170; 170, string:"ascii"; 171, return_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, string:b", "; 175, identifier:join; 176, argument_list; 176, 177; 177, identifier:extensions; 178, return_statement; 178, 179; 179, None
def server_extensions_handshake(requested, supported): accepts = {} for offer in requested: name = offer.split(";", 1)[0].strip() for extension in supported: if extension.name == name: accept = extension.accept(offer) if accept is True: accepts[extension.name] = True elif accept is not False and accept is not None: accepts[extension.name] = accept.encode("ascii") if accepts: extensions = [] for name, params in accepts.items(): if params is True: extensions.append(name.encode("ascii")) else: params = params.decode("ascii") if params == "": extensions.append(("%s" % (name)).encode("ascii")) else: extensions.append(("%s; %s" % (name, params)).encode("ascii")) return b", ".join(extensions) return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:listfiles; 3, parameters; 3, 4; 4, identifier:data_name; 5, block; 5, 6; 5, 16; 5, 38; 5, 43; 5, 47; 5, 189; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:data_source; 9, call; 9, 10; 9, 11; 10, identifier:get_data_object; 11, argument_list; 11, 12; 11, 13; 12, identifier:data_name; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:use_data_config; 15, False; 16, if_statement; 16, 17; 16, 19; 17, not_operator; 17, 18; 18, identifier:data_source; 19, block; 19, 20; 19, 32; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:in; 21, 22; 21, 23; 22, string:'output'; 23, identifier:data_name; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:floyd_logger; 29, identifier:info; 30, argument_list; 30, 31; 31, string:"Note: You cannot clone the output of a running job. You need to wait for it to finish."; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:sys; 36, identifier:exit; 37, argument_list; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:dirs; 41, list:['']; 41, 42; 42, string:''; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:paths; 46, list:[]; 47, while_statement; 47, 48; 47, 49; 48, identifier:dirs; 49, block; 49, 50; 49, 58; 49, 70; 49, 86; 49, 107; 49, 113; 49, 127; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:cur_dir; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:dirs; 56, identifier:pop; 57, argument_list; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:url; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, string:"/resources/{}/{}?content=true"; 64, identifier:format; 65, argument_list; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:data_source; 68, identifier:resource_id; 69, identifier:cur_dir; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:response; 73, call; 73, 74; 73, 85; 74, attribute; 74, 75; 74, 84; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, call; 77, 78; 77, 79; 78, identifier:DataClient; 79, argument_list; 80, identifier:request; 81, argument_list; 81, 82; 81, 83; 82, string:"GET"; 83, identifier:url; 84, identifier:json; 85, argument_list; 86, if_statement; 86, 87; 86, 92; 87, comparison_operator:>; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:response; 90, string:'skipped_files'; 91, integer:0; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:floyd_logger; 97, identifier:info; 98, argument_list; 98, 99; 98, 100; 98, 101; 98, 104; 99, string:"Warning: in directory '%s', %s/%s files skipped (too many files)"; 100, identifier:cur_dir; 101, subscript; 101, 102; 101, 103; 102, identifier:response; 103, string:'skipped_files'; 104, subscript; 104, 105; 104, 106; 105, identifier:response; 106, string:'total_files'; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:files; 110, subscript; 110, 111; 110, 112; 111, identifier:response; 112, string:'files'; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:files; 117, identifier:sort; 118, argument_list; 118, 119; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:key; 121, lambda; 121, 122; 121, 124; 122, lambda_parameters; 122, 123; 123, identifier:f; 124, subscript; 124, 125; 124, 126; 125, identifier:f; 126, string:'name'; 127, for_statement; 127, 128; 127, 129; 127, 130; 128, identifier:f; 129, identifier:files; 130, block; 130, 131; 130, 145; 130, 158; 130, 165; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:path; 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:join; 140, argument_list; 140, 141; 140, 142; 141, identifier:cur_dir; 142, subscript; 142, 143; 142, 144; 143, identifier:f; 144, string:'name'; 145, if_statement; 145, 146; 145, 151; 146, comparison_operator:==; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:f; 149, string:'type'; 150, string:'directory'; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, augmented_assignment:+=; 153, 154; 153, 155; 154, identifier:path; 155, attribute; 155, 156; 155, 157; 156, identifier:os; 157, identifier:sep; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:paths; 162, identifier:append; 163, argument_list; 163, 164; 164, identifier:path; 165, if_statement; 165, 166; 165, 171; 166, comparison_operator:==; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:f; 169, string:'type'; 170, string:'directory'; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:dirs; 176, identifier:append; 177, argument_list; 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:join; 184, argument_list; 184, 185; 184, 186; 185, identifier:cur_dir; 186, subscript; 186, 187; 186, 188; 187, identifier:f; 188, string:'name'; 189, for_statement; 189, 190; 189, 191; 189, 192; 190, identifier:path; 191, identifier:paths; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:floyd_logger; 197, identifier:info; 198, argument_list; 198, 199; 199, identifier:path
def listfiles(data_name): data_source = get_data_object(data_name, use_data_config=False) if not data_source: if 'output' in data_name: floyd_logger.info("Note: You cannot clone the output of a running job. You need to wait for it to finish.") sys.exit() dirs = [''] paths = [] while dirs: cur_dir = dirs.pop() url = "/resources/{}/{}?content=true".format(data_source.resource_id, cur_dir) response = DataClient().request("GET", url).json() if response['skipped_files'] > 0: floyd_logger.info("Warning: in directory '%s', %s/%s files skipped (too many files)", cur_dir, response['skipped_files'], response['total_files']) files = response['files'] files.sort(key=lambda f: f['name']) for f in files: path = os.path.join(cur_dir, f['name']) if f['type'] == 'directory': path += os.sep paths.append(path) if f['type'] == 'directory': dirs.append(os.path.join(cur_dir, f['name'])) for path in paths: floyd_logger.info(path)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:download; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 4, identifier:self; 5, identifier:url; 6, identifier:filename; 7, default_parameter; 7, 8; 7, 9; 8, identifier:relative; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:headers; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:timeout; 15, integer:5; 16, block; 16, 17; 16, 28; 16, 40; 16, 44; 16, 57; 16, 67; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:request_url; 20, conditional_expression:if; 20, 21; 20, 26; 20, 27; 21, binary_operator:+; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:base_url; 25, identifier:url; 26, identifier:relative; 27, identifier:url; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:floyd_logger; 32, identifier:debug; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, string:"Downloading file from url: {}"; 37, identifier:format; 38, argument_list; 38, 39; 39, identifier:request_url; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:request_headers; 43, dictionary; 44, if_statement; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:auth_header; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:request_headers; 53, string:"Authorization"; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:auth_header; 57, if_statement; 57, 58; 57, 59; 58, identifier:headers; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:request_headers; 64, identifier:update; 65, argument_list; 65, 66; 66, identifier:headers; 67, try_statement; 67, 68; 67, 197; 68, block; 68, 69; 68, 87; 68, 94; 68, 195; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:response; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:requests; 75, identifier:get; 76, argument_list; 76, 77; 76, 78; 76, 81; 76, 84; 77, identifier:request_url; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:headers; 80, identifier:request_headers; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:timeout; 83, identifier:timeout; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:stream; 86, True; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:check_response_status; 92, argument_list; 92, 93; 93, identifier:response; 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:filename; 102, string:'wb'; 103, as_pattern_target; 103, 104; 104, identifier:f; 105, block; 105, 106; 105, 117; 105, 132; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:content_length; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:response; 113, identifier:headers; 114, identifier:get; 115, argument_list; 115, 116; 116, string:'x-floydhub-content-length'; 117, if_statement; 117, 118; 117, 120; 118, not_operator; 118, 119; 119, identifier:content_length; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:content_length; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:response; 128, identifier:headers; 129, identifier:get; 130, argument_list; 130, 131; 131, string:'content-length'; 132, if_statement; 132, 133; 132, 134; 132, 172; 133, identifier:content_length; 134, block; 134, 135; 135, for_statement; 135, 136; 135, 137; 135, 161; 136, identifier:chunk; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:progress; 140, identifier:bar; 141, argument_list; 141, 142; 141, 150; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:response; 145, identifier:iter_content; 146, argument_list; 146, 147; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:chunk_size; 149, integer:1024; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:expected_size; 152, binary_operator:+; 152, 153; 152, 160; 153, parenthesized_expression; 153, 154; 154, binary_operator:/; 154, 155; 154, 159; 155, call; 155, 156; 155, 157; 156, identifier:int; 157, argument_list; 157, 158; 158, identifier:content_length; 159, integer:1024; 160, integer:1; 161, block; 161, 162; 162, if_statement; 162, 163; 162, 164; 163, identifier:chunk; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:f; 169, identifier:write; 170, argument_list; 170, 171; 171, identifier:chunk; 172, else_clause; 172, 173; 173, block; 173, 174; 174, for_statement; 174, 175; 174, 176; 174, 184; 175, identifier:chunk; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:response; 179, identifier:iter_content; 180, argument_list; 180, 181; 181, keyword_argument; 181, 182; 181, 183; 182, identifier:chunk_size; 183, integer:1024; 184, block; 184, 185; 185, if_statement; 185, 186; 185, 187; 186, identifier:chunk; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:f; 192, identifier:write; 193, argument_list; 193, 194; 194, identifier:chunk; 195, return_statement; 195, 196; 196, identifier:filename; 197, except_clause; 197, 198; 197, 206; 198, as_pattern; 198, 199; 198, 204; 199, attribute; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:requests; 202, identifier:exceptions; 203, identifier:ConnectionError; 204, as_pattern_target; 204, 205; 205, identifier:exception; 206, block; 206, 207; 206, 219; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:floyd_logger; 211, identifier:debug; 212, argument_list; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, string:"Exception: {}"; 216, identifier:format; 217, argument_list; 217, 218; 218, identifier:exception; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:sys; 223, identifier:exit; 224, argument_list; 224, 225; 225, string:"Cannot connect to the Floyd server. Check your internet connection."
def download(self, url, filename, relative=False, headers=None, timeout=5): request_url = self.base_url + url if relative else url floyd_logger.debug("Downloading file from url: {}".format(request_url)) request_headers = {} if self.auth_header: request_headers["Authorization"] = self.auth_header if headers: request_headers.update(headers) try: response = requests.get(request_url, headers=request_headers, timeout=timeout, stream=True) self.check_response_status(response) with open(filename, 'wb') as f: content_length = response.headers.get('x-floydhub-content-length') if not content_length: content_length = response.headers.get('content-length') if content_length: for chunk in progress.bar(response.iter_content(chunk_size=1024), expected_size=(int(content_length) / 1024) + 1): if chunk: f.write(chunk) else: for chunk in response.iter_content(chunk_size=1024): if chunk: f.write(chunk) return filename except requests.exceptions.ConnectionError as exception: floyd_logger.debug("Exception: {}".format(exception)) sys.exit("Cannot connect to the Floyd server. Check your internet connection.")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_command_line; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:instance_type; 5, identifier:env; 6, identifier:message; 7, identifier:data; 8, identifier:mode; 9, identifier:open_notebook; 10, identifier:command_str; 11, block; 11, 12; 11, 18; 11, 32; 11, 46; 11, 58; 11, 106; 11, 150; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:floyd_command; 15, list:["floyd", "run"]; 15, 16; 15, 17; 16, string:"floyd"; 17, string:"run"; 18, if_statement; 18, 19; 18, 20; 19, identifier:instance_type; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:floyd_command; 25, identifier:append; 26, argument_list; 26, 27; 27, binary_operator:+; 27, 28; 27, 29; 28, string:'--'; 29, subscript; 29, 30; 29, 31; 30, identifier:INSTANCE_NAME_MAP; 31, identifier:instance_type; 32, if_statement; 32, 33; 32, 39; 33, boolean_operator:and; 33, 34; 33, 35; 34, identifier:env; 35, not_operator; 35, 36; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:env; 38, identifier:DEFAULT_ENV; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, augmented_assignment:+=; 41, 42; 41, 43; 42, identifier:floyd_command; 43, list:["--env", env]; 43, 44; 43, 45; 44, string:"--env"; 45, identifier:env; 46, if_statement; 46, 47; 46, 48; 47, identifier:message; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, augmented_assignment:+=; 50, 51; 50, 52; 51, identifier:floyd_command; 52, list:["--message", shell_quote(message)]; 52, 53; 52, 54; 53, string:"--message"; 54, call; 54, 55; 54, 56; 55, identifier:shell_quote; 56, argument_list; 56, 57; 57, identifier:message; 58, if_statement; 58, 59; 58, 60; 59, identifier:data; 60, block; 60, 61; 61, for_statement; 61, 62; 61, 63; 61, 64; 62, identifier:data_item; 63, identifier:data; 64, block; 64, 65; 64, 74; 64, 100; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:parts; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:data_item; 71, identifier:split; 72, argument_list; 72, 73; 73, string:':'; 74, if_statement; 74, 75; 74, 81; 75, comparison_operator:>; 75, 76; 75, 80; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, identifier:parts; 80, integer:1; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:data_item; 85, binary_operator:+; 85, 86; 85, 97; 86, binary_operator:+; 86, 87; 86, 96; 87, call; 87, 88; 87, 89; 88, identifier:normalize_data_name; 89, argument_list; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:parts; 92, integer:0; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:use_data_config; 95, False; 96, string:':'; 97, subscript; 97, 98; 97, 99; 98, identifier:parts; 99, integer:1; 100, expression_statement; 100, 101; 101, augmented_assignment:+=; 101, 102; 101, 103; 102, identifier:floyd_command; 103, list:["--data", data_item]; 103, 104; 103, 105; 104, string:"--data"; 105, identifier:data_item; 106, if_statement; 106, 107; 106, 112; 106, 135; 107, boolean_operator:and; 107, 108; 107, 109; 108, identifier:mode; 109, comparison_operator:!=; 109, 110; 109, 111; 110, identifier:mode; 111, string:"job"; 112, block; 112, 113; 112, 119; 113, expression_statement; 113, 114; 114, augmented_assignment:+=; 114, 115; 114, 116; 115, identifier:floyd_command; 116, list:["--mode", mode]; 116, 117; 116, 118; 117, string:"--mode"; 118, identifier:mode; 119, if_statement; 119, 120; 119, 123; 120, comparison_operator:==; 120, 121; 120, 122; 121, identifier:mode; 122, string:'jupyter'; 123, block; 123, 124; 124, if_statement; 124, 125; 124, 127; 125, not_operator; 125, 126; 126, identifier:open_notebook; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:floyd_command; 132, identifier:append; 133, argument_list; 133, 134; 134, string:"--no-open"; 135, else_clause; 135, 136; 136, block; 136, 137; 137, if_statement; 137, 138; 137, 139; 138, identifier:command_str; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:floyd_command; 144, identifier:append; 145, argument_list; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:shell_quote; 148, argument_list; 148, 149; 149, identifier:command_str; 150, return_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, string:' '; 154, identifier:join; 155, argument_list; 155, 156; 156, identifier:floyd_command
def get_command_line(instance_type, env, message, data, mode, open_notebook, command_str): floyd_command = ["floyd", "run"] if instance_type: floyd_command.append('--' + INSTANCE_NAME_MAP[instance_type]) if env and not env == DEFAULT_ENV: floyd_command += ["--env", env] if message: floyd_command += ["--message", shell_quote(message)] if data: for data_item in data: parts = data_item.split(':') if len(parts) > 1: data_item = normalize_data_name(parts[0], use_data_config=False) + ':' + parts[1] floyd_command += ["--data", data_item] if mode and mode != "job": floyd_command += ["--mode", mode] if mode == 'jupyter': if not open_notebook: floyd_command.append("--no-open") else: if command_str: floyd_command.append(shell_quote(command_str)) return ' '.join(floyd_command)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:restart; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 4, identifier:ctx; 5, identifier:job_name; 6, identifier:data; 7, identifier:open_notebook; 8, identifier:env; 9, identifier:message; 10, identifier:gpu; 11, identifier:cpu; 12, identifier:gpup; 13, identifier:cpup; 14, identifier:command; 15, block; 15, 16; 15, 43; 15, 49; 15, 53; 15, 59; 15, 85; 15, 107; 15, 126; 15, 158; 15, 168; 15, 179; 15, 188; 15, 197; 15, 211; 15, 219; 15, 233; 15, 251; 16, if_statement; 16, 17; 16, 23; 17, comparison_operator:>; 17, 18; 17, 22; 18, call; 18, 19; 18, 20; 19, identifier:len; 20, argument_list; 20, 21; 21, identifier:env; 22, integer:1; 23, block; 23, 24; 23, 36; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:floyd_logger; 28, identifier:error; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, string:"You passed more than one environment: {}. Please specify a single environment."; 33, identifier:format; 34, argument_list; 34, 35; 35, identifier:env; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:sys; 40, identifier:exit; 41, argument_list; 41, 42; 42, integer:1; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:env; 46, subscript; 46, 47; 46, 48; 47, identifier:env; 48, integer:0; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:parameters; 52, dictionary; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:expt_client; 56, call; 56, 57; 56, 58; 57, identifier:ExperimentClient; 58, argument_list; 59, try_statement; 59, 60; 59, 73; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:job; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:expt_client; 67, identifier:get; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:normalize_job_name; 71, argument_list; 71, 72; 72, identifier:job_name; 73, except_clause; 73, 74; 73, 75; 74, identifier:FloydException; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:job; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:expt_client; 82, identifier:get; 83, argument_list; 83, 84; 84, identifier:job_name; 85, if_statement; 85, 86; 85, 87; 85, 92; 85, 99; 86, identifier:gpu; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:instance_type; 91, identifier:G1_INSTANCE_TYPE; 92, elif_clause; 92, 93; 92, 94; 93, identifier:cpu; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:instance_type; 98, identifier:C1_INSTANCE_TYPE; 99, else_clause; 99, 100; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:instance_type; 104, attribute; 104, 105; 104, 106; 105, identifier:job; 106, identifier:instance_type; 107, if_statement; 107, 108; 107, 111; 107, 118; 108, comparison_operator:is; 108, 109; 108, 110; 109, identifier:instance_type; 110, None; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:parameters; 116, string:'instance_type'; 117, identifier:instance_type; 118, else_clause; 118, 119; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:instance_type; 123, attribute; 123, 124; 123, 125; 124, identifier:job; 125, identifier:instance_type; 126, if_statement; 126, 127; 126, 130; 127, comparison_operator:is; 127, 128; 127, 129; 128, identifier:env; 129, None; 130, block; 130, 131; 130, 137; 130, 152; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:arch; 134, subscript; 134, 135; 134, 136; 135, identifier:INSTANCE_ARCH_MAP; 136, identifier:instance_type; 137, if_statement; 137, 138; 137, 144; 138, not_operator; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:validate_env; 141, argument_list; 141, 142; 141, 143; 142, identifier:env; 143, identifier:arch; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:sys; 149, identifier:exit; 150, argument_list; 150, 151; 151, integer:1; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:parameters; 156, string:'env'; 157, identifier:env; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 164; 160, pattern_list; 160, 161; 160, 162; 160, 163; 161, identifier:success; 162, identifier:data_ids; 163, identifier:show_data_info; 164, call; 164, 165; 164, 166; 165, identifier:process_data_ids; 166, argument_list; 166, 167; 167, identifier:data; 168, if_statement; 168, 169; 168, 171; 169, not_operator; 169, 170; 170, identifier:success; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:sys; 176, identifier:exit; 177, argument_list; 177, 178; 178, integer:1; 179, if_statement; 179, 180; 179, 181; 180, identifier:data_ids; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:parameters; 186, string:'data_ids'; 187, identifier:data_ids; 188, if_statement; 188, 189; 188, 190; 189, identifier:message; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 196; 193, subscript; 193, 194; 193, 195; 194, identifier:parameters; 195, string:'description'; 196, identifier:message; 197, if_statement; 197, 198; 197, 199; 198, identifier:command; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:parameters; 204, string:'command'; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, string:' '; 208, identifier:join; 209, argument_list; 209, 210; 210, identifier:command; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:floyd_logger; 215, identifier:info; 216, argument_list; 216, 217; 216, 218; 217, string:'Restarting job %s...'; 218, identifier:job_name; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:new_job_info; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:expt_client; 225, identifier:restart; 226, argument_list; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:job; 229, identifier:id; 230, keyword_argument; 230, 231; 230, 232; 231, identifier:parameters; 232, identifier:parameters; 233, if_statement; 233, 234; 233, 236; 234, not_operator; 234, 235; 235, identifier:new_job_info; 236, block; 236, 237; 236, 244; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:floyd_logger; 241, identifier:error; 242, argument_list; 242, 243; 243, string:"Failed to restart job"; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:sys; 248, identifier:exit; 249, argument_list; 249, 250; 250, integer:1; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 254; 253, identifier:show_new_job_info; 254, argument_list; 254, 255; 254, 256; 254, 259; 254, 260; 254, 263; 254, 264; 255, identifier:expt_client; 256, subscript; 256, 257; 256, 258; 257, identifier:new_job_info; 258, string:'name'; 259, identifier:new_job_info; 260, attribute; 260, 261; 260, 262; 261, identifier:job; 262, identifier:mode; 263, identifier:open_notebook; 264, identifier:show_data_info
def restart(ctx, job_name, data, open_notebook, env, message, gpu, cpu, gpup, cpup, command): if len(env) > 1: floyd_logger.error( "You passed more than one environment: {}. Please specify a single environment.".format(env) ) sys.exit(1) env = env[0] parameters = {} expt_client = ExperimentClient() try: job = expt_client.get(normalize_job_name(job_name)) except FloydException: job = expt_client.get(job_name) if gpu: instance_type = G1_INSTANCE_TYPE elif cpu: instance_type = C1_INSTANCE_TYPE else: instance_type = job.instance_type if instance_type is not None: parameters['instance_type'] = instance_type else: instance_type = job.instance_type if env is not None: arch = INSTANCE_ARCH_MAP[instance_type] if not validate_env(env, arch): sys.exit(1) parameters['env'] = env success, data_ids, show_data_info = process_data_ids(data) if not success: sys.exit(1) if data_ids: parameters['data_ids'] = data_ids if message: parameters['description'] = message if command: parameters['command'] = ' '.join(command) floyd_logger.info('Restarting job %s...', job_name) new_job_info = expt_client.restart(job.id, parameters=parameters) if not new_job_info: floyd_logger.error("Failed to restart job") sys.exit(1) show_new_job_info(expt_client, new_job_info['name'], new_job_info, job.mode, open_notebook, show_data_info)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:filter_user; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:user; 5, default_parameter; 5, 6; 5, 7; 6, identifier:using; 7, string:'records'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:interaction; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:part_of_week; 13, string:'allweek'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:part_of_day; 16, string:'allday'; 17, block; 17, 18; 17, 79; 17, 148; 17, 201; 17, 250; 18, if_statement; 18, 19; 18, 22; 18, 29; 19, comparison_operator:==; 19, 20; 19, 21; 20, identifier:using; 21, string:'recharges'; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:records; 26, attribute; 26, 27; 26, 28; 27, identifier:user; 28, identifier:recharges; 29, else_clause; 29, 30; 30, block; 30, 31; 30, 37; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:records; 34, attribute; 34, 35; 34, 36; 35, identifier:user; 36, identifier:records; 37, if_statement; 37, 38; 37, 41; 37, 59; 38, comparison_operator:==; 38, 39; 38, 40; 39, identifier:interaction; 40, string:'callandtext'; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:records; 45, call; 45, 46; 45, 47; 46, identifier:filter; 47, argument_list; 47, 48; 47, 58; 48, lambda; 48, 49; 48, 51; 49, lambda_parameters; 49, 50; 50, identifier:r; 51, comparison_operator:in; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:r; 54, identifier:interaction; 55, list:['call', 'text']; 55, 56; 55, 57; 56, string:'call'; 57, string:'text'; 58, identifier:records; 59, elif_clause; 59, 60; 59, 63; 60, comparison_operator:is; 60, 61; 60, 62; 61, identifier:interaction; 62, None; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:records; 67, call; 67, 68; 67, 69; 68, identifier:filter; 69, argument_list; 69, 70; 69, 78; 70, lambda; 70, 71; 70, 73; 71, lambda_parameters; 71, 72; 72, identifier:r; 73, comparison_operator:==; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:r; 76, identifier:interaction; 77, identifier:interaction; 78, identifier:records; 79, if_statement; 79, 80; 79, 83; 79, 105; 79, 131; 80, comparison_operator:==; 80, 81; 80, 82; 81, identifier:part_of_week; 82, string:'weekday'; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:records; 87, call; 87, 88; 87, 89; 88, identifier:filter; 89, argument_list; 89, 90; 89, 104; 90, lambda; 90, 91; 90, 93; 91, lambda_parameters; 91, 92; 92, identifier:r; 93, comparison_operator:not; 93, 94; 93, 101; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:r; 98, identifier:datetime; 99, identifier:isoweekday; 100, argument_list; 101, attribute; 101, 102; 101, 103; 102, identifier:user; 103, identifier:weekend; 104, identifier:records; 105, elif_clause; 105, 106; 105, 109; 106, comparison_operator:==; 106, 107; 106, 108; 107, identifier:part_of_week; 108, string:'weekend'; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:records; 113, call; 113, 114; 113, 115; 114, identifier:filter; 115, argument_list; 115, 116; 115, 130; 116, lambda; 116, 117; 116, 119; 117, lambda_parameters; 117, 118; 118, identifier:r; 119, comparison_operator:in; 119, 120; 119, 127; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:r; 124, identifier:datetime; 125, identifier:isoweekday; 126, argument_list; 127, attribute; 127, 128; 127, 129; 128, identifier:user; 129, identifier:weekend; 130, identifier:records; 131, elif_clause; 131, 132; 131, 135; 132, comparison_operator:!=; 132, 133; 132, 134; 133, identifier:part_of_week; 134, string:'allweek'; 135, block; 135, 136; 136, raise_statement; 136, 137; 137, call; 137, 138; 137, 139; 138, identifier:KeyError; 139, argument_list; 139, 140; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, concatenated_string; 142, 143; 142, 144; 143, string:"{} is not a valid value for part_of_week. it should be 'weekday', "; 144, string:"'weekend' or 'allweek'."; 145, identifier:format; 146, argument_list; 146, 147; 147, identifier:part_of_week; 148, if_statement; 148, 149; 148, 156; 148, 177; 149, comparison_operator:<; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:user; 152, identifier:night_start; 153, attribute; 153, 154; 153, 155; 154, identifier:user; 155, identifier:night_end; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:night_filter; 160, lambda; 160, 161; 160, 163; 161, lambda_parameters; 161, 162; 162, identifier:r; 163, comparison_operator:>; 163, 164; 163, 167; 163, 174; 164, attribute; 164, 165; 164, 166; 165, identifier:user; 166, identifier:night_end; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:r; 171, identifier:datetime; 172, identifier:time; 173, argument_list; 174, attribute; 174, 175; 174, 176; 175, identifier:user; 176, identifier:night_start; 177, else_clause; 177, 178; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:night_filter; 182, lambda; 182, 183; 182, 185; 183, lambda_parameters; 183, 184; 184, identifier:r; 185, not_operator; 185, 186; 186, parenthesized_expression; 186, 187; 187, comparison_operator:<; 187, 188; 187, 191; 187, 198; 188, attribute; 188, 189; 188, 190; 189, identifier:user; 190, identifier:night_end; 191, call; 191, 192; 191, 197; 192, attribute; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:r; 195, identifier:datetime; 196, identifier:time; 197, argument_list; 198, attribute; 198, 199; 198, 200; 199, identifier:user; 200, identifier:night_start; 201, if_statement; 201, 202; 201, 205; 201, 222; 201, 235; 202, comparison_operator:==; 202, 203; 202, 204; 203, identifier:part_of_day; 204, string:'day'; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:records; 209, call; 209, 210; 209, 211; 210, identifier:filter; 211, argument_list; 211, 212; 211, 221; 212, lambda; 212, 213; 212, 215; 213, lambda_parameters; 213, 214; 214, identifier:r; 215, not_operator; 215, 216; 216, parenthesized_expression; 216, 217; 217, call; 217, 218; 217, 219; 218, identifier:night_filter; 219, argument_list; 219, 220; 220, identifier:r; 221, identifier:records; 222, elif_clause; 222, 223; 222, 226; 223, comparison_operator:==; 223, 224; 223, 225; 224, identifier:part_of_day; 225, string:'night'; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:records; 230, call; 230, 231; 230, 232; 231, identifier:filter; 232, argument_list; 232, 233; 232, 234; 233, identifier:night_filter; 234, identifier:records; 235, elif_clause; 235, 236; 235, 239; 236, comparison_operator:!=; 236, 237; 236, 238; 237, identifier:part_of_day; 238, string:'allday'; 239, block; 239, 240; 240, raise_statement; 240, 241; 241, call; 241, 242; 241, 243; 242, identifier:KeyError; 243, argument_list; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, string:"{} is not a valid value for part_of_day. It should be 'day', 'night' or 'allday'."; 247, identifier:format; 248, argument_list; 248, 249; 249, identifier:part_of_day; 250, return_statement; 250, 251; 251, call; 251, 252; 251, 253; 252, identifier:list; 253, argument_list; 253, 254; 254, identifier:records
def filter_user(user, using='records', interaction=None, part_of_week='allweek', part_of_day='allday'): if using == 'recharges': records = user.recharges else: records = user.records if interaction == 'callandtext': records = filter( lambda r: r.interaction in ['call', 'text'], records) elif interaction is not None: records = filter(lambda r: r.interaction == interaction, records) if part_of_week == 'weekday': records = filter( lambda r: r.datetime.isoweekday() not in user.weekend, records) elif part_of_week == 'weekend': records = filter( lambda r: r.datetime.isoweekday() in user.weekend, records) elif part_of_week != 'allweek': raise KeyError( "{} is not a valid value for part_of_week. it should be 'weekday', " "'weekend' or 'allweek'.".format(part_of_week)) if user.night_start < user.night_end: night_filter = lambda r: user.night_end > r.datetime.time( ) > user.night_start else: night_filter = lambda r: not( user.night_end < r.datetime.time() < user.night_start) if part_of_day == 'day': records = filter(lambda r: not(night_filter(r)), records) elif part_of_day == 'night': records = filter(night_filter, records) elif part_of_day != 'allday': raise KeyError( "{} is not a valid value for part_of_day. It should be 'day', 'night' or 'allday'.".format(part_of_day)) return list(records)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:infer_type; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 22; 5, 31; 5, 95; 6, if_statement; 6, 7; 6, 19; 7, call; 7, 8; 7, 9; 8, identifier:isinstance; 9, argument_list; 9, 10; 9, 11; 10, identifier:data; 11, tuple; 11, 12; 11, 16; 12, call; 12, 13; 12, 14; 13, identifier:type; 14, argument_list; 14, 15; 15, None; 16, attribute; 16, 17; 16, 18; 17, identifier:numbers; 18, identifier:Number; 19, block; 19, 20; 20, return_statement; 20, 21; 21, string:'scalar'; 22, if_statement; 22, 23; 22, 28; 23, call; 23, 24; 23, 25; 24, identifier:isinstance; 25, argument_list; 25, 26; 25, 27; 26, identifier:data; 27, identifier:SummaryStats; 28, block; 28, 29; 29, return_statement; 29, 30; 30, string:'summarystats'; 31, if_statement; 31, 32; 31, 37; 32, call; 32, 33; 32, 34; 33, identifier:hasattr; 34, argument_list; 34, 35; 34, 36; 35, identifier:data; 36, string:"__len__"; 37, block; 37, 38; 37, 50; 37, 70; 37, 81; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:data; 41, list_comprehension; 41, 42; 41, 43; 41, 46; 42, identifier:x; 43, for_in_clause; 43, 44; 43, 45; 44, identifier:x; 45, identifier:data; 46, if_clause; 46, 47; 47, comparison_operator:is; 47, 48; 47, 49; 48, identifier:x; 49, None; 50, if_statement; 50, 51; 50, 67; 51, boolean_operator:or; 51, 52; 51, 58; 52, comparison_operator:==; 52, 53; 52, 57; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:data; 57, integer:0; 58, call; 58, 59; 58, 60; 59, identifier:isinstance; 60, argument_list; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:data; 63, integer:0; 64, attribute; 64, 65; 64, 66; 65, identifier:numbers; 66, identifier:Number; 67, block; 67, 68; 68, return_statement; 68, 69; 69, string:'distribution_scalar'; 70, if_statement; 70, 71; 70, 78; 71, call; 71, 72; 71, 73; 72, identifier:isinstance; 73, argument_list; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:data; 76, integer:0; 77, identifier:SummaryStats; 78, block; 78, 79; 79, return_statement; 79, 80; 80, string:'distribution_summarystats'; 81, raise_statement; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:TypeError; 84, argument_list; 84, 85; 85, call; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, concatenated_string; 87, 88; 87, 89; 88, string:"{} is not a valid input. It should be a number, a SummaryStats "; 89, string:"object, or None"; 90, identifier:format; 91, argument_list; 91, 92; 92, subscript; 92, 93; 92, 94; 93, identifier:data; 94, integer:0; 95, raise_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:TypeError; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, concatenated_string; 101, 102; 101, 103; 102, string:"{} is not a valid input. It should be a number, a SummaryStats "; 103, string:"object, or a list"; 104, identifier:format; 105, argument_list; 105, 106; 106, identifier:data
def infer_type(data): if isinstance(data, (type(None), numbers.Number)): return 'scalar' if isinstance(data, SummaryStats): return 'summarystats' if hasattr(data, "__len__"): data = [x for x in data if x is not None] if len(data) == 0 or isinstance(data[0], numbers.Number): return 'distribution_scalar' if isinstance(data[0], SummaryStats): return 'distribution_summarystats' raise TypeError( "{} is not a valid input. It should be a number, a SummaryStats " "object, or None".format(data[0])) raise TypeError( "{} is not a valid input. It should be a number, a SummaryStats " "object, or a list".format(data))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:churn_rate; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:user; 5, default_parameter; 5, 6; 5, 7; 6, identifier:summary; 7, string:'default'; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, block; 10, 11; 10, 29; 10, 59; 10, 67; 10, 75; 10, 91; 10, 95; 10, 99; 10, 144; 10, 154; 10, 228; 11, if_statement; 11, 12; 11, 20; 12, comparison_operator:==; 12, 13; 12, 19; 13, call; 13, 14; 13, 15; 14, identifier:len; 15, argument_list; 15, 16; 16, attribute; 16, 17; 16, 18; 17, identifier:user; 18, identifier:records; 19, integer:0; 20, block; 20, 21; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:statistics; 24, argument_list; 24, 25; 24, 26; 25, list:[]; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:summary; 28, identifier:summary; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:query; 32, dictionary; 32, 33; 32, 36; 32, 50; 32, 53; 32, 56; 33, pair; 33, 34; 33, 35; 34, string:'groupby'; 35, string:'week'; 36, pair; 36, 37; 36, 38; 37, string:'divide_by'; 38, call; 38, 39; 38, 40; 39, identifier:OrderedDict; 40, argument_list; 40, 41; 41, list:[ ('part_of_week', ['allweek']), ('part_of_day', ['allday']) ]; 41, 42; 41, 46; 42, tuple; 42, 43; 42, 44; 43, string:'part_of_week'; 44, list:['allweek']; 44, 45; 45, string:'allweek'; 46, tuple; 46, 47; 46, 48; 47, string:'part_of_day'; 48, list:['allday']; 48, 49; 49, string:'allday'; 50, pair; 50, 51; 50, 52; 51, string:'using'; 52, string:'records'; 53, pair; 53, 54; 53, 55; 54, string:'filter_empty'; 55, True; 56, pair; 56, 57; 56, 58; 57, string:'binning'; 58, True; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:rv; 62, call; 62, 63; 62, 64; 63, identifier:grouping_query; 64, argument_list; 64, 65; 64, 66; 65, identifier:user; 66, identifier:query; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:weekly_positions; 70, subscript; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:rv; 73, integer:0; 74, integer:1; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:all_positions; 78, call; 78, 79; 78, 80; 79, identifier:list; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:set; 83, generator_expression; 83, 84; 83, 85; 83, 88; 84, identifier:p; 85, for_in_clause; 85, 86; 85, 87; 86, identifier:l; 87, identifier:weekly_positions; 88, for_in_clause; 88, 89; 88, 90; 89, identifier:p; 90, identifier:l; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:frequencies; 94, dictionary; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:cos_dist; 98, list:[]; 99, for_statement; 99, 100; 99, 103; 99, 107; 100, pattern_list; 100, 101; 100, 102; 101, identifier:week; 102, identifier:week_positions; 103, call; 103, 104; 103, 105; 104, identifier:enumerate; 105, argument_list; 105, 106; 106, identifier:weekly_positions; 107, block; 107, 108; 107, 115; 107, 126; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:count; 111, call; 111, 112; 111, 113; 112, identifier:Counter; 113, argument_list; 113, 114; 114, identifier:week_positions; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:total; 118, call; 118, 119; 118, 120; 119, identifier:sum; 120, argument_list; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:count; 124, identifier:values; 125, argument_list; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:frequencies; 130, identifier:week; 131, list_comprehension; 131, 132; 131, 141; 132, binary_operator:/; 132, 133; 132, 140; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:count; 136, identifier:get; 137, argument_list; 137, 138; 137, 139; 138, identifier:p; 139, integer:0; 140, identifier:total; 141, for_in_clause; 141, 142; 141, 143; 142, identifier:p; 143, identifier:all_positions; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:all_indexes; 147, call; 147, 148; 147, 149; 148, identifier:range; 149, argument_list; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:len; 152, argument_list; 152, 153; 153, identifier:all_positions; 154, for_statement; 154, 155; 154, 158; 154, 169; 155, pattern_list; 155, 156; 155, 157; 156, identifier:f_1; 157, identifier:f_2; 158, call; 158, 159; 158, 160; 159, identifier:pairwise; 160, argument_list; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:list; 163, argument_list; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:frequencies; 167, identifier:values; 168, argument_list; 169, block; 169, 170; 169, 186; 169, 198; 169, 210; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:num; 173, call; 173, 174; 173, 175; 174, identifier:sum; 175, generator_expression; 175, 176; 175, 183; 176, binary_operator:*; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:f_1; 179, identifier:a; 180, subscript; 180, 181; 180, 182; 181, identifier:f_2; 182, identifier:a; 183, for_in_clause; 183, 184; 183, 185; 184, identifier:a; 185, identifier:all_indexes; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:denom_1; 189, call; 189, 190; 189, 191; 190, identifier:sum; 191, generator_expression; 191, 192; 191, 195; 192, binary_operator:**; 192, 193; 192, 194; 193, identifier:f; 194, integer:2; 195, for_in_clause; 195, 196; 195, 197; 196, identifier:f; 197, identifier:f_1; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:denom_2; 201, call; 201, 202; 201, 203; 202, identifier:sum; 203, generator_expression; 203, 204; 203, 207; 204, binary_operator:**; 204, 205; 204, 206; 205, identifier:f; 206, integer:2; 207, for_in_clause; 207, 208; 207, 209; 208, identifier:f; 209, identifier:f_2; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:cos_dist; 214, identifier:append; 215, argument_list; 215, 216; 216, binary_operator:-; 216, 217; 216, 218; 217, integer:1; 218, binary_operator:/; 218, 219; 218, 220; 219, identifier:num; 220, parenthesized_expression; 220, 221; 221, binary_operator:*; 221, 222; 221, 225; 222, binary_operator:**; 222, 223; 222, 224; 223, identifier:denom_1; 224, float:.5; 225, binary_operator:**; 225, 226; 225, 227; 226, identifier:denom_2; 227, float:.5; 228, return_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:statistics; 231, argument_list; 231, 232; 231, 233; 232, identifier:cos_dist; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:summary; 235, identifier:summary
def churn_rate(user, summary='default', **kwargs): if len(user.records) == 0: return statistics([], summary=summary) query = { 'groupby': 'week', 'divide_by': OrderedDict([ ('part_of_week', ['allweek']), ('part_of_day', ['allday']) ]), 'using': 'records', 'filter_empty': True, 'binning': True } rv = grouping_query(user, query) weekly_positions = rv[0][1] all_positions = list(set(p for l in weekly_positions for p in l)) frequencies = {} cos_dist = [] for week, week_positions in enumerate(weekly_positions): count = Counter(week_positions) total = sum(count.values()) frequencies[week] = [count.get(p, 0) / total for p in all_positions] all_indexes = range(len(all_positions)) for f_1, f_2 in pairwise(list(frequencies.values())): num = sum(f_1[a] * f_2[a] for a in all_indexes) denom_1 = sum(f ** 2 for f in f_1) denom_2 = sum(f ** 2 for f in f_2) cos_dist.append(1 - num / (denom_1 ** .5 * denom_2 ** .5)) return statistics(cos_dist, summary=summary)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:describe; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 40; 5, 54; 5, 68; 5, 111; 5, 128; 5, 138; 5, 161; 5, 191; 5, 226; 5, 256; 5, 277; 5, 298; 5, 319; 6, function_definition; 6, 7; 6, 8; 6, 11; 7, function_name:format_int; 8, parameters; 8, 9; 8, 10; 9, identifier:name; 10, identifier:n; 11, block; 11, 12; 12, if_statement; 12, 13; 12, 20; 12, 32; 13, boolean_operator:or; 13, 14; 13, 17; 14, comparison_operator:==; 14, 15; 14, 16; 15, identifier:n; 16, integer:0; 17, comparison_operator:==; 17, 18; 17, 19; 18, identifier:n; 19, integer:1; 20, block; 20, 21; 21, return_statement; 21, 22; 22, binary_operator:%; 22, 23; 22, 24; 23, string:"%i %s"; 24, tuple; 24, 25; 24, 26; 25, identifier:n; 26, subscript; 26, 27; 26, 28; 27, identifier:name; 28, slice; 28, 29; 28, 30; 29, colon; 30, unary_operator:-; 30, 31; 31, integer:1; 32, else_clause; 32, 33; 33, block; 33, 34; 34, return_statement; 34, 35; 35, binary_operator:%; 35, 36; 35, 37; 36, string:"%i %s"; 37, tuple; 37, 38; 37, 39; 38, identifier:n; 39, identifier:name; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:empty_box; 43, binary_operator:+; 43, 44; 43, 53; 44, binary_operator:+; 44, 45; 44, 50; 45, binary_operator:+; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:Colors; 48, identifier:OKGREEN; 49, string:'[ ]'; 50, attribute; 50, 51; 50, 52; 51, identifier:Colors; 52, identifier:ENDC; 53, string:' '; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:filled_box; 57, binary_operator:+; 57, 58; 57, 67; 58, binary_operator:+; 58, 59; 58, 64; 59, binary_operator:+; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:Colors; 62, identifier:OKGREEN; 63, string:'[x]'; 64, attribute; 64, 65; 64, 66; 65, identifier:Colors; 66, identifier:ENDC; 67, string:' '; 68, if_statement; 68, 69; 68, 74; 68, 82; 69, comparison_operator:is; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:start_time; 73, None; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:print; 78, argument_list; 78, 79; 79, binary_operator:+; 79, 80; 79, 81; 80, identifier:empty_box; 81, string:"No records stored"; 82, else_clause; 82, 83; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:print; 87, argument_list; 87, 88; 88, parenthesized_expression; 88, 89; 89, binary_operator:+; 89, 90; 89, 102; 90, binary_operator:+; 90, 91; 90, 92; 91, identifier:filled_box; 92, call; 92, 93; 92, 94; 93, identifier:format_int; 94, argument_list; 94, 95; 94, 96; 95, string:"records"; 96, call; 96, 97; 96, 98; 97, identifier:len; 98, argument_list; 98, 99; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:records; 102, binary_operator:%; 102, 103; 102, 104; 103, string:" from %s to %s"; 104, tuple; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:start_time; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:end_time; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:nb_contacts; 114, call; 114, 115; 114, 120; 115, attribute; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:bc; 118, identifier:individual; 119, identifier:number_of_contacts; 120, argument_list; 120, 121; 120, 122; 120, 125; 121, identifier:self; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:interaction; 124, string:'callandtext'; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:groupby; 127, None; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:nb_contacts; 131, subscript; 131, 132; 131, 137; 132, subscript; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:nb_contacts; 135, string:'allweek'; 136, string:'allday'; 137, string:'callandtext'; 138, if_statement; 138, 139; 138, 140; 138, 152; 139, identifier:nb_contacts; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:print; 144, argument_list; 144, 145; 145, binary_operator:+; 145, 146; 145, 147; 146, identifier:filled_box; 147, call; 147, 148; 147, 149; 148, identifier:format_int; 149, argument_list; 149, 150; 149, 151; 150, string:"contacts"; 151, identifier:nb_contacts; 152, else_clause; 152, 153; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:print; 157, argument_list; 157, 158; 158, binary_operator:+; 158, 159; 158, 160; 159, identifier:empty_box; 160, string:"No contacts"; 161, if_statement; 161, 162; 161, 165; 161, 182; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:has_attributes; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:print; 169, argument_list; 169, 170; 170, binary_operator:+; 170, 171; 170, 172; 171, identifier:filled_box; 172, call; 172, 173; 172, 174; 173, identifier:format_int; 174, argument_list; 174, 175; 174, 176; 175, string:"attributes"; 176, call; 176, 177; 176, 178; 177, identifier:len; 178, argument_list; 178, 179; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:attributes; 182, else_clause; 182, 183; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:print; 187, argument_list; 187, 188; 188, binary_operator:+; 188, 189; 188, 190; 189, identifier:empty_box; 190, string:"No attribute stored"; 191, if_statement; 191, 192; 191, 200; 191, 208; 192, comparison_operator:==; 192, 193; 192, 199; 193, call; 193, 194; 193, 195; 194, identifier:len; 195, argument_list; 195, 196; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:antennas; 199, integer:0; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 204; 203, identifier:print; 204, argument_list; 204, 205; 205, binary_operator:+; 205, 206; 205, 207; 206, identifier:empty_box; 207, string:"No antenna stored"; 208, else_clause; 208, 209; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 213; 212, identifier:print; 213, argument_list; 213, 214; 214, binary_operator:+; 214, 215; 214, 216; 215, identifier:filled_box; 216, call; 216, 217; 216, 218; 217, identifier:format_int; 218, argument_list; 218, 219; 218, 220; 219, string:"antennas"; 220, call; 220, 221; 220, 222; 221, identifier:len; 222, argument_list; 222, 223; 223, attribute; 223, 224; 223, 225; 224, identifier:self; 225, identifier:antennas; 226, if_statement; 226, 227; 226, 230; 226, 247; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:has_recharges; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:print; 234, argument_list; 234, 235; 235, binary_operator:+; 235, 236; 235, 237; 236, identifier:filled_box; 237, call; 237, 238; 237, 239; 238, identifier:format_int; 239, argument_list; 239, 240; 239, 241; 240, string:"recharges"; 241, call; 241, 242; 241, 243; 242, identifier:len; 243, argument_list; 243, 244; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:recharges; 247, else_clause; 247, 248; 248, block; 248, 249; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 252; 251, identifier:print; 252, argument_list; 252, 253; 253, binary_operator:+; 253, 254; 253, 255; 254, identifier:empty_box; 255, string:"No recharges"; 256, if_statement; 256, 257; 256, 260; 256, 268; 257, attribute; 257, 258; 257, 259; 258, identifier:self; 259, identifier:has_home; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 264; 263, identifier:print; 264, argument_list; 264, 265; 265, binary_operator:+; 265, 266; 265, 267; 266, identifier:filled_box; 267, string:"Has home"; 268, else_clause; 268, 269; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 273; 272, identifier:print; 273, argument_list; 273, 274; 274, binary_operator:+; 274, 275; 274, 276; 275, identifier:empty_box; 276, string:"No home"; 277, if_statement; 277, 278; 277, 281; 277, 289; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:has_text; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:print; 285, argument_list; 285, 286; 286, binary_operator:+; 286, 287; 286, 288; 287, identifier:filled_box; 288, string:"Has texts"; 289, else_clause; 289, 290; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:print; 294, argument_list; 294, 295; 295, binary_operator:+; 295, 296; 295, 297; 296, identifier:empty_box; 297, string:"No texts"; 298, if_statement; 298, 299; 298, 302; 298, 310; 299, attribute; 299, 300; 299, 301; 300, identifier:self; 301, identifier:has_call; 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, 309; 308, identifier:filled_box; 309, string:"Has calls"; 310, else_clause; 310, 311; 311, block; 311, 312; 312, expression_statement; 312, 313; 313, call; 313, 314; 313, 315; 314, identifier:print; 315, argument_list; 315, 316; 316, binary_operator:+; 316, 317; 316, 318; 317, identifier:empty_box; 318, string:"No calls"; 319, if_statement; 319, 320; 319, 323; 319, 331; 320, attribute; 320, 321; 320, 322; 321, identifier:self; 322, identifier:has_network; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 327; 326, identifier:print; 327, argument_list; 327, 328; 328, binary_operator:+; 328, 329; 328, 330; 329, identifier:filled_box; 330, string:"Has network"; 331, else_clause; 331, 332; 332, block; 332, 333; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 336; 335, identifier:print; 336, argument_list; 336, 337; 337, binary_operator:+; 337, 338; 337, 339; 338, identifier:empty_box; 339, string:"No network"
def describe(self): def format_int(name, n): if n == 0 or n == 1: return "%i %s" % (n, name[:-1]) else: return "%i %s" % (n, name) empty_box = Colors.OKGREEN + '[ ]' + Colors.ENDC + ' ' filled_box = Colors.OKGREEN + '[x]' + Colors.ENDC + ' ' if self.start_time is None: print(empty_box + "No records stored") else: print((filled_box + format_int("records", len(self.records)) + " from %s to %s" % (self.start_time, self.end_time))) nb_contacts = bc.individual.number_of_contacts( self, interaction='callandtext', groupby=None) nb_contacts = nb_contacts['allweek']['allday']['callandtext'] if nb_contacts: print(filled_box + format_int("contacts", nb_contacts)) else: print(empty_box + "No contacts") if self.has_attributes: print(filled_box + format_int("attributes", len(self.attributes))) else: print(empty_box + "No attribute stored") if len(self.antennas) == 0: print(empty_box + "No antenna stored") else: print(filled_box + format_int("antennas", len(self.antennas))) if self.has_recharges: print(filled_box + format_int("recharges", len(self.recharges))) else: print(empty_box + "No recharges") if self.has_home: print(filled_box + "Has home") else: print(empty_box + "No home") if self.has_text: print(filled_box + "Has texts") else: print(empty_box + "No texts") if self.has_call: print(filled_box + "Has calls") else: print(empty_box + "No calls") if self.has_network: print(filled_box + "Has network") else: print(empty_box + "No network")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:matrix_index; 3, parameters; 3, 4; 4, identifier:user; 5, block; 5, 6; 5, 29; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:other_keys; 9, call; 9, 10; 9, 11; 10, identifier:sorted; 11, argument_list; 11, 12; 12, list_comprehension; 12, 13; 12, 14; 12, 23; 13, identifier:k; 14, for_in_clause; 14, 15; 14, 16; 15, identifier:k; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:user; 20, identifier:network; 21, identifier:keys; 22, argument_list; 23, if_clause; 23, 24; 24, comparison_operator:!=; 24, 25; 24, 26; 25, identifier:k; 26, attribute; 26, 27; 26, 28; 27, identifier:user; 28, identifier:name; 29, return_statement; 29, 30; 30, binary_operator:+; 30, 31; 30, 35; 31, list:[user.name]; 31, 32; 32, attribute; 32, 33; 32, 34; 33, identifier:user; 34, identifier:name; 35, identifier:other_keys
def matrix_index(user): other_keys = sorted([k for k in user.network.keys() if k != user.name]) return [user.name] + other_keys
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:clustering_coefficient_weighted; 3, parameters; 3, 4; 3, 5; 4, identifier:user; 5, default_parameter; 5, 6; 5, 7; 6, identifier:interaction; 7, None; 8, block; 8, 9; 8, 19; 8, 34; 8, 44; 8, 51; 8, 55; 8, 130; 8, 146; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:matrix; 12, call; 12, 13; 12, 14; 13, identifier:matrix_undirected_weighted; 14, argument_list; 14, 15; 14, 16; 15, identifier:user; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:interaction; 18, identifier:interaction; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:weights; 22, list_comprehension; 22, 23; 22, 24; 22, 27; 22, 30; 23, identifier:weight; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:g; 26, identifier:matrix; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:weight; 29, identifier:g; 30, if_clause; 30, 31; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:weight; 33, None; 34, if_statement; 34, 35; 34, 41; 35, comparison_operator:==; 35, 36; 35, 40; 36, call; 36, 37; 36, 38; 37, identifier:len; 38, argument_list; 38, 39; 39, identifier:weights; 40, integer:0; 41, block; 41, 42; 42, return_statement; 42, 43; 43, None; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:max_weight; 47, call; 47, 48; 47, 49; 48, identifier:max; 49, argument_list; 49, 50; 50, identifier:weights; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:triplet_weight; 54, integer:0; 55, for_statement; 55, 56; 55, 59; 55, 70; 56, pattern_list; 56, 57; 56, 58; 57, identifier:a; 58, identifier:b; 59, call; 59, 60; 59, 61; 60, identifier:combinations; 61, argument_list; 61, 62; 61, 69; 62, call; 62, 63; 62, 64; 63, identifier:range; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:len; 67, argument_list; 67, 68; 68, identifier:matrix; 69, integer:2; 70, block; 70, 71; 70, 93; 70, 107; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 77; 73, pattern_list; 73, 74; 73, 75; 73, 76; 74, identifier:a_b; 75, identifier:a_c; 76, identifier:b_c; 77, expression_list; 77, 78; 77, 83; 77, 88; 78, subscript; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:matrix; 81, identifier:a; 82, identifier:b; 83, subscript; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:matrix; 86, identifier:a; 87, integer:0; 88, subscript; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:matrix; 91, identifier:b; 92, integer:0; 93, if_statement; 93, 94; 93, 105; 94, boolean_operator:or; 94, 95; 94, 102; 95, boolean_operator:or; 95, 96; 95, 99; 96, comparison_operator:is; 96, 97; 96, 98; 97, identifier:a_b; 98, None; 99, comparison_operator:is; 99, 100; 99, 101; 100, identifier:a_c; 101, None; 102, comparison_operator:is; 102, 103; 102, 104; 103, identifier:b_c; 104, None; 105, block; 105, 106; 106, continue_statement; 107, if_statement; 107, 108; 107, 113; 108, boolean_operator:and; 108, 109; 108, 112; 109, boolean_operator:and; 109, 110; 109, 111; 110, identifier:a_b; 111, identifier:a_c; 112, identifier:b_c; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, augmented_assignment:+=; 115, 116; 115, 117; 116, identifier:triplet_weight; 117, binary_operator:/; 117, 118; 117, 129; 118, binary_operator:**; 118, 119; 118, 125; 119, parenthesized_expression; 119, 120; 120, binary_operator:*; 120, 121; 120, 124; 121, binary_operator:*; 121, 122; 121, 123; 122, identifier:a_b; 123, identifier:a_c; 124, identifier:b_c; 125, parenthesized_expression; 125, 126; 126, binary_operator:/; 126, 127; 126, 128; 127, integer:1; 128, integer:3; 129, identifier:max_weight; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:d_ego; 133, call; 133, 134; 133, 135; 134, identifier:sum; 135, generator_expression; 135, 136; 135, 137; 135, 142; 136, integer:1; 137, for_in_clause; 137, 138; 137, 139; 138, identifier:i; 139, subscript; 139, 140; 139, 141; 140, identifier:matrix; 141, integer:0; 142, if_clause; 142, 143; 143, comparison_operator:>; 143, 144; 143, 145; 144, identifier:i; 145, integer:0; 146, return_statement; 146, 147; 147, conditional_expression:if; 147, 148; 147, 159; 147, 162; 148, binary_operator:/; 148, 149; 148, 152; 149, binary_operator:*; 149, 150; 149, 151; 150, integer:2; 151, identifier:triplet_weight; 152, parenthesized_expression; 152, 153; 153, binary_operator:*; 153, 154; 153, 155; 154, identifier:d_ego; 155, parenthesized_expression; 155, 156; 156, binary_operator:-; 156, 157; 156, 158; 157, identifier:d_ego; 158, integer:1; 159, comparison_operator:>; 159, 160; 159, 161; 160, identifier:d_ego; 161, integer:1; 162, integer:0
def clustering_coefficient_weighted(user, interaction=None): matrix = matrix_undirected_weighted(user, interaction=interaction) weights = [weight for g in matrix for weight in g if weight is not None] if len(weights) == 0: return None max_weight = max(weights) triplet_weight = 0 for a, b in combinations(range(len(matrix)), 2): a_b, a_c, b_c = matrix[a][b], matrix[a][0], matrix[b][0] if a_b is None or a_c is None or b_c is None: continue if a_b and a_c and b_c: triplet_weight += (a_b * a_c * b_c) ** (1 / 3) / max_weight d_ego = sum(1 for i in matrix[0] if i > 0) return 2 * triplet_weight / (d_ego * (d_ego - 1)) if d_ego > 1 else 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:assortativity_indicators; 3, parameters; 3, 4; 4, identifier:user; 5, block; 5, 6; 5, 13; 5, 20; 5, 27; 5, 37; 5, 73; 5, 165; 5, 169; 5, 185; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:matrix; 9, call; 9, 10; 9, 11; 10, identifier:matrix_undirected_unweighted; 11, argument_list; 11, 12; 12, identifier:user; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:count_indicator; 16, call; 16, 17; 16, 18; 17, identifier:defaultdict; 18, argument_list; 18, 19; 19, identifier:int; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:total_indicator; 23, call; 23, 24; 23, 25; 24, identifier:defaultdict; 25, argument_list; 25, 26; 26, identifier:int; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:ego_indics; 30, call; 30, 31; 30, 32; 31, identifier:all; 32, argument_list; 32, 33; 32, 34; 33, identifier:user; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:flatten; 36, True; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:ego_indics; 40, dictionary_comprehension; 40, 41; 40, 44; 40, 53; 41, pair; 41, 42; 41, 43; 42, identifier:a; 43, identifier:value; 44, for_in_clause; 44, 45; 44, 48; 45, pattern_list; 45, 46; 45, 47; 46, identifier:a; 47, identifier:value; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:ego_indics; 51, identifier:items; 52, argument_list; 53, if_clause; 53, 54; 54, boolean_operator:and; 54, 55; 54, 66; 55, boolean_operator:and; 55, 56; 55, 59; 56, comparison_operator:!=; 56, 57; 56, 58; 57, identifier:a; 58, string:"name"; 59, comparison_operator:!=; 59, 60; 59, 65; 60, subscript; 60, 61; 60, 62; 61, identifier:a; 62, slice; 62, 63; 62, 64; 63, colon; 64, integer:11; 65, string:"reporting__"; 66, comparison_operator:!=; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 69; 68, identifier:a; 69, slice; 69, 70; 69, 71; 70, colon; 71, integer:10; 72, string:"attributes"; 73, for_statement; 73, 74; 73, 77; 73, 84; 74, pattern_list; 74, 75; 74, 76; 75, identifier:i; 76, identifier:u_name; 77, call; 77, 78; 77, 79; 78, identifier:enumerate; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:matrix_index; 82, argument_list; 82, 83; 83, identifier:user; 84, block; 84, 85; 84, 97; 84, 117; 84, 127; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:correspondent; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:user; 92, identifier:network; 93, identifier:get; 94, argument_list; 94, 95; 94, 96; 95, identifier:u_name; 96, None; 97, if_statement; 97, 98; 97, 115; 98, boolean_operator:or; 98, 99; 98, 108; 99, boolean_operator:or; 99, 100; 99, 103; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:correspondent; 102, None; 103, comparison_operator:==; 103, 104; 103, 105; 104, identifier:u_name; 105, attribute; 105, 106; 105, 107; 106, identifier:user; 107, identifier:name; 108, comparison_operator:==; 108, 109; 108, 114; 109, subscript; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:matrix; 112, integer:0; 113, identifier:i; 114, integer:0; 115, block; 115, 116; 116, continue_statement; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:neighbor_indics; 120, call; 120, 121; 120, 122; 121, identifier:all; 122, argument_list; 122, 123; 122, 124; 123, identifier:correspondent; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:flatten; 126, True; 127, for_statement; 127, 128; 127, 129; 127, 130; 128, identifier:a; 129, identifier:ego_indics; 130, block; 130, 131; 131, if_statement; 131, 132; 131, 143; 132, boolean_operator:and; 132, 133; 132, 138; 133, comparison_operator:is; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:ego_indics; 136, identifier:a; 137, None; 138, comparison_operator:is; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:neighbor_indics; 141, identifier:a; 142, None; 143, block; 143, 144; 143, 150; 144, expression_statement; 144, 145; 145, augmented_assignment:+=; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:total_indicator; 148, identifier:a; 149, integer:1; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:count_indicator; 154, identifier:a; 155, binary_operator:**; 155, 156; 155, 164; 156, parenthesized_expression; 156, 157; 157, binary_operator:-; 157, 158; 157, 161; 158, subscript; 158, 159; 158, 160; 159, identifier:ego_indics; 160, identifier:a; 161, subscript; 161, 162; 161, 163; 162, identifier:neighbor_indics; 163, identifier:a; 164, integer:2; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:assortativity; 168, dictionary; 169, for_statement; 169, 170; 169, 171; 169, 172; 170, identifier:i; 171, identifier:count_indicator; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:assortativity; 177, identifier:i; 178, binary_operator:/; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:count_indicator; 181, identifier:i; 182, subscript; 182, 183; 182, 184; 183, identifier:total_indicator; 184, identifier:i; 185, return_statement; 185, 186; 186, identifier:assortativity
def assortativity_indicators(user): matrix = matrix_undirected_unweighted(user) count_indicator = defaultdict(int) total_indicator = defaultdict(int) ego_indics = all(user, flatten=True) ego_indics = {a: value for a, value in ego_indics.items() if a != "name" and a[:11] != "reporting__" and a[:10] != "attributes"} for i, u_name in enumerate(matrix_index(user)): correspondent = user.network.get(u_name, None) if correspondent is None or u_name == user.name or matrix[0][i] == 0: continue neighbor_indics = all(correspondent, flatten=True) for a in ego_indics: if ego_indics[a] is not None and neighbor_indics[a] is not None: total_indicator[a] += 1 count_indicator[a] += (ego_indics[a] - neighbor_indics[a]) ** 2 assortativity = {} for i in count_indicator: assortativity[i] = count_indicator[i] / total_indicator[i] return assortativity
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:assortativity_attributes; 3, parameters; 3, 4; 4, identifier:user; 5, block; 5, 6; 5, 13; 5, 33; 5, 37; 5, 96; 5, 100; 5, 159; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:matrix; 9, call; 9, 10; 9, 11; 10, identifier:matrix_undirected_unweighted; 11, argument_list; 11, 12; 12, identifier:user; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:neighbors; 16, list_comprehension; 16, 17; 16, 18; 16, 27; 17, identifier:k; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:k; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:user; 24, identifier:network; 25, identifier:keys; 26, argument_list; 27, if_clause; 27, 28; 28, comparison_operator:!=; 28, 29; 28, 30; 29, identifier:k; 30, attribute; 30, 31; 30, 32; 31, identifier:user; 32, identifier:name; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:neighbors_attrbs; 36, dictionary; 37, for_statement; 37, 38; 37, 41; 37, 48; 38, pattern_list; 38, 39; 38, 40; 39, identifier:i; 40, identifier:u_name; 41, call; 41, 42; 41, 43; 42, identifier:enumerate; 43, argument_list; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:matrix_index; 46, argument_list; 46, 47; 47, identifier:user; 48, block; 48, 49; 48, 61; 48, 81; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:correspondent; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:user; 56, identifier:network; 57, identifier:get; 58, argument_list; 58, 59; 58, 60; 59, identifier:u_name; 60, None; 61, if_statement; 61, 62; 61, 79; 62, boolean_operator:or; 62, 63; 62, 72; 63, boolean_operator:or; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:correspondent; 66, None; 67, comparison_operator:==; 67, 68; 67, 69; 68, identifier:u_name; 69, attribute; 69, 70; 69, 71; 70, identifier:user; 71, identifier:name; 72, comparison_operator:==; 72, 73; 72, 78; 73, subscript; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:matrix; 76, integer:0; 77, identifier:i; 78, integer:0; 79, block; 79, 80; 80, continue_statement; 81, if_statement; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:correspondent; 84, identifier:has_attributes; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 93; 88, subscript; 88, 89; 88, 90; 89, identifier:neighbors_attrbs; 90, attribute; 90, 91; 90, 92; 91, identifier:correspondent; 92, identifier:name; 93, attribute; 93, 94; 93, 95; 94, identifier:correspondent; 95, identifier:attributes; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:assortativity; 99, dictionary; 100, for_statement; 100, 101; 100, 102; 100, 105; 101, identifier:a; 102, attribute; 102, 103; 102, 104; 103, identifier:user; 104, identifier:attributes; 105, block; 105, 106; 105, 132; 105, 146; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:total; 109, call; 109, 110; 109, 111; 110, identifier:sum; 111, generator_expression; 111, 112; 111, 113; 111, 116; 112, integer:1; 113, for_in_clause; 113, 114; 113, 115; 114, identifier:n; 115, identifier:neighbors; 116, if_clause; 116, 117; 117, boolean_operator:and; 117, 118; 117, 121; 118, comparison_operator:in; 118, 119; 118, 120; 119, identifier:n; 120, identifier:neighbors_attrbs; 121, comparison_operator:==; 121, 122; 121, 127; 122, subscript; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:user; 125, identifier:attributes; 126, identifier:a; 127, subscript; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:neighbors_attrbs; 130, identifier:n; 131, identifier:a; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:den; 135, call; 135, 136; 135, 137; 136, identifier:sum; 137, generator_expression; 137, 138; 137, 139; 137, 142; 138, integer:1; 139, for_in_clause; 139, 140; 139, 141; 140, identifier:n; 141, identifier:neighbors; 142, if_clause; 142, 143; 143, comparison_operator:in; 143, 144; 143, 145; 144, identifier:n; 145, identifier:neighbors_attrbs; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:assortativity; 150, identifier:a; 151, conditional_expression:if; 151, 152; 151, 155; 151, 158; 152, binary_operator:/; 152, 153; 152, 154; 153, identifier:total; 154, identifier:den; 155, comparison_operator:!=; 155, 156; 155, 157; 156, identifier:den; 157, integer:0; 158, None; 159, return_statement; 159, 160; 160, identifier:assortativity
def assortativity_attributes(user): matrix = matrix_undirected_unweighted(user) neighbors = [k for k in user.network.keys() if k != user.name] neighbors_attrbs = {} for i, u_name in enumerate(matrix_index(user)): correspondent = user.network.get(u_name, None) if correspondent is None or u_name == user.name or matrix[0][i] == 0: continue if correspondent.has_attributes: neighbors_attrbs[correspondent.name] = correspondent.attributes assortativity = {} for a in user.attributes: total = sum(1 for n in neighbors if n in neighbors_attrbs and user.attributes[a] == neighbors_attrbs[n][a]) den = sum(1 for n in neighbors if n in neighbors_attrbs) assortativity[a] = total / den if den != 0 else None return assortativity
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:network_sampling; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:n; 5, identifier:filename; 6, default_parameter; 6, 7; 6, 8; 7, identifier:directory; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:snowball; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:user; 14, None; 15, block; 15, 16; 15, 205; 15, 226; 16, if_statement; 16, 17; 16, 18; 16, 129; 17, identifier:snowball; 18, block; 18, 19; 19, if_statement; 19, 20; 19, 23; 19, 29; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:user; 22, None; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:ValueError; 27, argument_list; 27, 28; 28, string:"Must specify a starting user from whom to initiate the snowball"; 29, else_clause; 29, 30; 30, block; 30, 31; 30, 41; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, pattern_list; 33, 34; 33, 35; 34, identifier:users; 35, identifier:agenda; 36, expression_list; 36, 37; 36, 39; 37, list:[user]; 37, 38; 38, identifier:user; 39, list:[user]; 39, 40; 40, identifier:user; 41, while_statement; 41, 42; 41, 48; 42, comparison_operator:>; 42, 43; 42, 47; 43, call; 43, 44; 43, 45; 44, identifier:len; 45, argument_list; 45, 46; 46, identifier:agenda; 47, integer:0; 48, block; 48, 49; 48, 57; 48, 80; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:parent; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:agenda; 55, identifier:pop; 56, argument_list; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:dealphebetized_network; 60, call; 60, 61; 60, 62; 61, identifier:sorted; 62, argument_list; 62, 63; 62, 70; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:parent; 67, identifier:network; 68, identifier:items; 69, argument_list; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:key; 72, lambda; 72, 73; 72, 75; 73, lambda_parameters; 73, 74; 74, identifier:k; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:random; 78, identifier:random; 79, argument_list; 80, for_statement; 80, 81; 80, 82; 80, 83; 81, identifier:neighbor; 82, identifier:dealphebetized_network; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 103; 85, boolean_operator:and; 85, 86; 85, 97; 86, boolean_operator:and; 86, 87; 86, 92; 87, comparison_operator:not; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:neighbor; 90, integer:1; 91, identifier:users; 92, comparison_operator:is; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:neighbor; 95, integer:1; 96, None; 97, comparison_operator:<; 97, 98; 97, 102; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, identifier:users; 102, identifier:n; 103, block; 103, 104; 103, 113; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:users; 108, identifier:append; 109, argument_list; 109, 110; 110, subscript; 110, 111; 110, 112; 111, identifier:neighbor; 112, integer:1; 113, if_statement; 113, 114; 113, 119; 114, attribute; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:neighbor; 117, integer:1; 118, identifier:network; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:agenda; 124, identifier:push; 125, argument_list; 125, 126; 126, subscript; 126, 127; 126, 128; 127, identifier:neighbor; 128, integer:1; 129, else_clause; 129, 130; 130, block; 130, 131; 130, 161; 130, 178; 130, 186; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:files; 134, list_comprehension; 134, 135; 134, 136; 134, 144; 135, identifier:x; 136, for_in_clause; 136, 137; 136, 138; 137, identifier:x; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:os; 141, identifier:listdir; 142, argument_list; 142, 143; 143, identifier:directory; 144, if_clause; 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:isfile; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:os; 156, identifier:path; 157, identifier:join; 158, argument_list; 158, 159; 158, 160; 159, identifier:directory; 160, identifier:x; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:shuffled_files; 164, call; 164, 165; 164, 166; 165, identifier:sorted; 166, argument_list; 166, 167; 166, 168; 167, identifier:files; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:key; 170, lambda; 170, 171; 170, 173; 171, lambda_parameters; 171, 172; 172, identifier:k; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:random; 176, identifier:random; 177, argument_list; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:user_names; 181, subscript; 181, 182; 181, 183; 182, identifier:shuffled_files; 183, slice; 183, 184; 183, 185; 184, colon; 185, identifier:n; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:users; 189, list_comprehension; 189, 190; 189, 202; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:bc; 193, identifier:read_csv; 194, argument_list; 194, 195; 194, 201; 195, subscript; 195, 196; 195, 197; 196, identifier:u; 197, slice; 197, 198; 197, 199; 198, colon; 199, unary_operator:-; 199, 200; 200, integer:4; 201, identifier:directory; 202, for_in_clause; 202, 203; 202, 204; 203, identifier:u; 204, identifier:user_names; 205, if_statement; 205, 206; 205, 212; 206, comparison_operator:<; 206, 207; 206, 211; 207, call; 207, 208; 207, 209; 208, identifier:len; 209, argument_list; 209, 210; 210, identifier:users; 211, identifier:n; 212, block; 212, 213; 213, raise_statement; 213, 214; 214, call; 214, 215; 214, 216; 215, identifier:ValueError; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, string:"Specified more users than records that exist, only {} records available"; 220, identifier:format; 221, argument_list; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:len; 224, argument_list; 224, 225; 225, identifier:users; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:bc; 230, identifier:to_csv; 231, argument_list; 231, 232; 231, 244; 232, list_comprehension; 232, 233; 232, 241; 233, call; 233, 234; 233, 239; 234, attribute; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:bc; 237, identifier:utils; 238, identifier:all; 239, argument_list; 239, 240; 240, identifier:u; 241, for_in_clause; 241, 242; 241, 243; 242, identifier:u; 243, identifier:users; 244, identifier:filename
def network_sampling(n, filename, directory=None, snowball=False, user=None): if snowball: if user is None: raise ValueError("Must specify a starting user from whom to initiate the snowball") else: users, agenda = [user], [user] while len(agenda) > 0: parent = agenda.pop() dealphebetized_network = sorted(parent.network.items(), key=lambda k: random.random()) for neighbor in dealphebetized_network: if neighbor[1] not in users and neighbor[1] is not None and len(users) < n: users.append(neighbor[1]) if neighbor[1].network: agenda.push(neighbor[1]) else: files = [x for x in os.listdir(directory) if os.path.isfile(os.path.join(directory, x))] shuffled_files = sorted(files, key=lambda k: random.random()) user_names = shuffled_files[:n] users = [bc.read_csv(u[:-4], directory) for u in user_names] if len(users) < n: raise ValueError("Specified more users than records that exist, only {} records available".format(len(users))) bc.to_csv([bc.utils.all(u) for u in users], filename)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:to_csv; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:objects; 5, identifier:filename; 6, default_parameter; 6, 7; 6, 8; 7, identifier:digits; 8, integer:5; 9, default_parameter; 9, 10; 9, 11; 10, identifier:warnings; 11, True; 12, block; 12, 13; 12, 26; 12, 37; 12, 52; 12, 73; 12, 181; 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:objects; 19, identifier:list; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:objects; 24, list:[objects]; 24, 25; 25, identifier:objects; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:data; 29, list_comprehension; 29, 30; 29, 34; 30, call; 30, 31; 30, 32; 31, identifier:flatten; 32, argument_list; 32, 33; 33, identifier:obj; 34, for_in_clause; 34, 35; 34, 36; 35, identifier:obj; 36, identifier:objects; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:all_keys; 40, list_comprehension; 40, 41; 40, 42; 40, 45; 41, identifier:d; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:datum; 44, identifier:data; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:d; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:datum; 50, identifier:keys; 51, argument_list; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:field_names; 55, call; 55, 56; 55, 57; 56, identifier:sorted; 57, argument_list; 57, 58; 57, 62; 58, call; 58, 59; 58, 60; 59, identifier:set; 60, argument_list; 60, 61; 61, identifier:all_keys; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:key; 64, lambda; 64, 65; 64, 67; 65, lambda_parameters; 65, 66; 66, identifier:x; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:all_keys; 70, identifier:index; 71, argument_list; 71, 72; 72, identifier:x; 73, with_statement; 73, 74; 73, 84; 74, with_clause; 74, 75; 75, with_item; 75, 76; 76, as_pattern; 76, 77; 76, 82; 77, call; 77, 78; 77, 79; 78, identifier:open; 79, argument_list; 79, 80; 79, 81; 80, identifier:filename; 81, string:'w'; 82, as_pattern_target; 82, 83; 83, identifier:f; 84, block; 84, 85; 84, 94; 84, 101; 84, 136; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:w; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:csv; 91, identifier:writer; 92, argument_list; 92, 93; 93, identifier:f; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:w; 98, identifier:writerow; 99, argument_list; 99, 100; 100, identifier:field_names; 101, function_definition; 101, 102; 101, 103; 101, 105; 102, function_name:make_repr; 103, parameters; 103, 104; 104, identifier:item; 105, block; 105, 106; 106, if_statement; 106, 107; 106, 110; 106, 113; 106, 129; 107, comparison_operator:is; 107, 108; 107, 109; 108, identifier:item; 109, None; 110, block; 110, 111; 111, return_statement; 111, 112; 112, None; 113, elif_clause; 113, 114; 113, 119; 114, call; 114, 115; 114, 116; 115, identifier:isinstance; 116, argument_list; 116, 117; 116, 118; 117, identifier:item; 118, identifier:float; 119, block; 119, 120; 120, return_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:repr; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:round; 126, argument_list; 126, 127; 126, 128; 127, identifier:item; 128, identifier:digits; 129, else_clause; 129, 130; 130, block; 130, 131; 131, return_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:str; 134, argument_list; 134, 135; 135, identifier:item; 136, for_statement; 136, 137; 136, 138; 136, 139; 137, identifier:row; 138, identifier:data; 139, block; 139, 140; 139, 161; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:row; 143, call; 143, 144; 143, 145; 144, identifier:dict; 145, generator_expression; 145, 146; 145, 152; 146, tuple; 146, 147; 146, 148; 147, identifier:k; 148, call; 148, 149; 148, 150; 149, identifier:make_repr; 150, argument_list; 150, 151; 151, identifier:v; 152, for_in_clause; 152, 153; 152, 156; 153, pattern_list; 153, 154; 153, 155; 154, identifier:k; 155, identifier:v; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:row; 159, identifier:items; 160, argument_list; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:w; 165, identifier:writerow; 166, argument_list; 166, 167; 167, list_comprehension; 167, 168; 167, 178; 168, call; 168, 169; 168, 170; 169, identifier:make_repr; 170, argument_list; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:row; 174, identifier:get; 175, argument_list; 175, 176; 175, 177; 176, identifier:k; 177, None; 178, for_in_clause; 178, 179; 178, 180; 179, identifier:k; 180, identifier:field_names; 181, if_statement; 181, 182; 181, 183; 182, identifier:warnings; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:print; 187, argument_list; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, string:"Successfully exported {} object(s) to {}"; 191, identifier:format; 192, argument_list; 192, 193; 192, 197; 193, call; 193, 194; 193, 195; 194, identifier:len; 195, argument_list; 195, 196; 196, identifier:objects; 197, identifier:filename
def to_csv(objects, filename, digits=5, warnings=True): if not isinstance(objects, list): objects = [objects] data = [flatten(obj) for obj in objects] all_keys = [d for datum in data for d in datum.keys()] field_names = sorted(set(all_keys), key=lambda x: all_keys.index(x)) with open(filename, 'w') as f: w = csv.writer(f) w.writerow(field_names) def make_repr(item): if item is None: return None elif isinstance(item, float): return repr(round(item, digits)) else: return str(item) for row in data: row = dict((k, make_repr(v)) for k, v in row.items()) w.writerow([make_repr(row.get(k, None)) for k in field_names]) if warnings: print("Successfully exported {} object(s) to {}".format(len(objects), filename))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 33; 2, function_name:read_csv; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 4, identifier:user_id; 5, identifier:records_path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:antennas_path; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:attributes_path; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:recharges_path; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:network; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:duration_format; 20, string:'seconds'; 21, default_parameter; 21, 22; 21, 23; 22, identifier:describe; 23, True; 24, default_parameter; 24, 25; 24, 26; 25, identifier:warnings; 26, True; 27, default_parameter; 27, 28; 27, 29; 28, identifier:errors; 29, False; 30, default_parameter; 30, 31; 30, 32; 31, identifier:drop_duplicates; 32, False; 33, block; 33, 34; 33, 38; 33, 96; 33, 110; 33, 143; 33, 147; 33, 173; 33, 177; 33, 203; 33, 228; 33, 256; 33, 265; 33, 272; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:antennas; 37, None; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:antennas_path; 41, None; 42, block; 42, 43; 43, try_statement; 43, 44; 43, 92; 44, block; 44, 45; 45, with_statement; 45, 46; 45, 56; 46, with_clause; 46, 47; 47, with_item; 47, 48; 48, as_pattern; 48, 49; 48, 54; 49, call; 49, 50; 49, 51; 50, identifier:open; 51, argument_list; 51, 52; 51, 53; 52, identifier:antennas_path; 53, string:'r'; 54, as_pattern_target; 54, 55; 55, identifier:csv_file; 56, block; 56, 57; 56, 66; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:reader; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:csv; 63, identifier:DictReader; 64, argument_list; 64, 65; 65, identifier:csv_file; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:antennas; 69, call; 69, 70; 69, 71; 70, identifier:dict; 71, generator_expression; 71, 72; 71, 89; 72, tuple; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:d; 75, string:'antenna_id'; 76, tuple; 76, 77; 76, 83; 77, call; 77, 78; 77, 79; 78, identifier:float; 79, argument_list; 79, 80; 80, subscript; 80, 81; 80, 82; 81, identifier:d; 82, string:'latitude'; 83, call; 83, 84; 83, 85; 84, identifier:float; 85, argument_list; 85, 86; 86, subscript; 86, 87; 86, 88; 87, identifier:d; 88, string:'longitude'; 89, for_in_clause; 89, 90; 89, 91; 90, identifier:d; 91, identifier:reader; 92, except_clause; 92, 93; 92, 94; 93, identifier:IOError; 94, block; 94, 95; 95, pass_statement; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:user_records; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:os; 103, identifier:path; 104, identifier:join; 105, argument_list; 105, 106; 105, 107; 106, identifier:records_path; 107, binary_operator:+; 107, 108; 107, 109; 108, identifier:user_id; 109, string:'.csv'; 110, with_statement; 110, 111; 110, 121; 111, with_clause; 111, 112; 112, with_item; 112, 113; 113, as_pattern; 113, 114; 113, 119; 114, call; 114, 115; 114, 116; 115, identifier:open; 116, argument_list; 116, 117; 116, 118; 117, identifier:user_records; 118, string:'r'; 119, as_pattern_target; 119, 120; 120, identifier:csv_file; 121, block; 121, 122; 121, 131; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:reader; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:csv; 128, identifier:DictReader; 129, argument_list; 129, 130; 130, identifier:csv_file; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:records; 134, list_comprehension; 134, 135; 134, 140; 135, call; 135, 136; 135, 137; 136, identifier:_parse_record; 137, argument_list; 137, 138; 137, 139; 138, identifier:r; 139, identifier:duration_format; 140, for_in_clause; 140, 141; 140, 142; 141, identifier:r; 142, identifier:reader; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:attributes; 146, None; 147, if_statement; 147, 148; 147, 151; 148, comparison_operator:is; 148, 149; 148, 150; 149, identifier:attributes_path; 150, None; 151, block; 151, 152; 151, 166; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:user_attributes; 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:attributes_path; 163, binary_operator:+; 163, 164; 163, 165; 164, identifier:user_id; 165, string:'.csv'; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:attributes; 169, call; 169, 170; 169, 171; 170, identifier:_load_attributes; 171, argument_list; 171, 172; 172, identifier:user_attributes; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:recharges; 176, None; 177, if_statement; 177, 178; 177, 181; 178, comparison_operator:is; 178, 179; 178, 180; 179, identifier:recharges_path; 180, None; 181, block; 181, 182; 181, 196; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:user_recharges; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:os; 189, identifier:path; 190, identifier:join; 191, argument_list; 191, 192; 191, 193; 192, identifier:recharges_path; 193, binary_operator:+; 193, 194; 193, 195; 194, identifier:user_id; 195, string:'.csv'; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:recharges; 199, call; 199, 200; 199, 201; 200, identifier:_load_recharges; 201, argument_list; 201, 202; 202, identifier:user_recharges; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, pattern_list; 205, 206; 205, 207; 206, identifier:user; 207, identifier:bad_records; 208, call; 208, 209; 208, 210; 209, identifier:load; 210, argument_list; 210, 211; 210, 212; 210, 213; 210, 214; 210, 215; 210, 216; 210, 217; 210, 218; 210, 219; 210, 222; 210, 225; 211, identifier:user_id; 212, identifier:records; 213, identifier:antennas; 214, identifier:attributes; 215, identifier:recharges; 216, identifier:antennas_path; 217, identifier:attributes_path; 218, identifier:recharges_path; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:describe; 221, False; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:warnings; 224, identifier:warnings; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:drop_duplicates; 227, identifier:drop_duplicates; 228, if_statement; 228, 229; 228, 232; 229, comparison_operator:is; 229, 230; 229, 231; 230, identifier:network; 231, True; 232, block; 232, 233; 232, 250; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:user; 237, identifier:network; 238, call; 238, 239; 238, 240; 239, identifier:_read_network; 240, argument_list; 240, 241; 240, 242; 240, 243; 240, 244; 240, 245; 240, 246; 240, 247; 241, identifier:user; 242, identifier:records_path; 243, identifier:attributes_path; 244, identifier:read_csv; 245, identifier:antennas_path; 246, identifier:warnings; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:drop_duplicates; 249, identifier:drop_duplicates; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:user; 254, identifier:recompute_missing_neighbors; 255, argument_list; 256, if_statement; 256, 257; 256, 258; 257, identifier:describe; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:user; 263, identifier:describe; 264, argument_list; 265, if_statement; 265, 266; 265, 267; 266, identifier:errors; 267, block; 267, 268; 268, return_statement; 268, 269; 269, expression_list; 269, 270; 269, 271; 270, identifier:user; 271, identifier:bad_records; 272, return_statement; 272, 273; 273, identifier:user
def read_csv(user_id, records_path, antennas_path=None, attributes_path=None, recharges_path=None, network=False, duration_format='seconds', describe=True, warnings=True, errors=False, drop_duplicates=False): antennas = None if antennas_path is not None: try: with open(antennas_path, 'r') as csv_file: reader = csv.DictReader(csv_file) antennas = dict((d['antenna_id'], (float(d['latitude']), float(d['longitude']))) for d in reader) except IOError: pass user_records = os.path.join(records_path, user_id + '.csv') with open(user_records, 'r') as csv_file: reader = csv.DictReader(csv_file) records = [_parse_record(r, duration_format) for r in reader] attributes = None if attributes_path is not None: user_attributes = os.path.join(attributes_path, user_id + '.csv') attributes = _load_attributes(user_attributes) recharges = None if recharges_path is not None: user_recharges = os.path.join(recharges_path, user_id + '.csv') recharges = _load_recharges(user_recharges) user, bad_records = load(user_id, records, antennas, attributes, recharges, antennas_path, attributes_path, recharges_path, describe=False, warnings=warnings, drop_duplicates=drop_duplicates) if network is True: user.network = _read_network(user, records_path, attributes_path, read_csv, antennas_path, warnings, drop_duplicates=drop_duplicates) user.recompute_missing_neighbors() if describe: user.describe() if errors: return user, bad_records return user
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:_conversations; 3, parameters; 3, 4; 3, 5; 4, identifier:group; 5, default_parameter; 5, 6; 5, 7; 6, identifier:delta; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:datetime; 10, identifier:timedelta; 11, argument_list; 11, 12; 12, keyword_argument; 12, 13; 12, 14; 13, identifier:hours; 14, integer:1; 15, block; 15, 16; 15, 20; 15, 24; 15, 109; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:last_time; 19, None; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:results; 23, list:[]; 24, for_statement; 24, 25; 24, 26; 24, 27; 25, identifier:g; 26, identifier:group; 27, block; 27, 28; 27, 103; 28, if_statement; 28, 29; 28, 40; 28, 72; 29, boolean_operator:or; 29, 30; 29, 33; 30, comparison_operator:is; 30, 31; 30, 32; 31, identifier:last_time; 32, None; 33, comparison_operator:<; 33, 34; 33, 39; 34, binary_operator:-; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:g; 37, identifier:datetime; 38, identifier:last_time; 39, identifier:delta; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 47; 41, 55; 42, comparison_operator:==; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:g; 45, identifier:interaction; 46, string:'text'; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:results; 52, identifier:append; 53, argument_list; 53, 54; 54, identifier:g; 55, else_clause; 55, 56; 56, block; 56, 57; 57, if_statement; 57, 58; 57, 64; 58, comparison_operator:!=; 58, 59; 58, 63; 59, call; 59, 60; 59, 61; 60, identifier:len; 61, argument_list; 61, 62; 62, identifier:results; 63, integer:0; 64, block; 64, 65; 64, 68; 65, expression_statement; 65, 66; 66, yield; 66, 67; 67, identifier:results; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:results; 71, list:[]; 72, else_clause; 72, 73; 73, block; 73, 74; 73, 85; 74, if_statement; 74, 75; 74, 81; 75, comparison_operator:!=; 75, 76; 75, 80; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, identifier:results; 80, integer:0; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, yield; 83, 84; 84, identifier:results; 85, if_statement; 85, 86; 85, 91; 85, 96; 86, comparison_operator:==; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:g; 89, identifier:interaction; 90, string:'call'; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:results; 95, list:[]; 96, else_clause; 96, 97; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:results; 101, list:[g]; 101, 102; 102, identifier:g; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:last_time; 106, attribute; 106, 107; 106, 108; 107, identifier:g; 108, identifier:datetime; 109, if_statement; 109, 110; 109, 116; 110, comparison_operator:!=; 110, 111; 110, 115; 111, call; 111, 112; 111, 113; 112, identifier:len; 113, argument_list; 113, 114; 114, identifier:results; 115, integer:0; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, yield; 118, 119; 119, identifier:results
def _conversations(group, delta=datetime.timedelta(hours=1)): last_time = None results = [] for g in group: if last_time is None or g.datetime - last_time < delta: if g.interaction == 'text': results.append(g) else: if len(results) != 0: yield results results = [] else: if len(results) != 0: yield results if g.interaction == 'call': results = [] else: results = [g] last_time = g.datetime if len(results) != 0: yield results
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:fetch; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:cert; 5, identifier:issuer; 6, default_parameter; 6, 7; 6, 8; 7, identifier:hash_algo; 8, string:'sha1'; 9, default_parameter; 9, 10; 9, 11; 10, identifier:nonce; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:user_agent; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:timeout; 17, integer:10; 18, block; 18, 19; 18, 39; 18, 59; 18, 79; 18, 97; 18, 126; 18, 169; 18, 181; 18, 199; 18, 251; 18, 263; 18, 267; 18, 379; 19, if_statement; 19, 20; 19, 28; 20, not_operator; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:isinstance; 23, argument_list; 23, 24; 23, 25; 24, identifier:cert; 25, attribute; 25, 26; 25, 27; 26, identifier:x509; 27, identifier:Certificate; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:TypeError; 32, argument_list; 32, 33; 33, binary_operator:%; 33, 34; 33, 35; 34, string:'cert must be an instance of asn1crypto.x509.Certificate, not %s'; 35, call; 35, 36; 35, 37; 36, identifier:type_name; 37, argument_list; 37, 38; 38, identifier:cert; 39, if_statement; 39, 40; 39, 48; 40, not_operator; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:isinstance; 43, argument_list; 43, 44; 43, 45; 44, identifier:issuer; 45, attribute; 45, 46; 45, 47; 46, identifier:x509; 47, identifier:Certificate; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:TypeError; 52, argument_list; 52, 53; 53, binary_operator:%; 53, 54; 53, 55; 54, string:'issuer must be an instance of asn1crypto.x509.Certificate, not %s'; 55, call; 55, 56; 55, 57; 56, identifier:type_name; 57, argument_list; 57, 58; 58, identifier:issuer; 59, if_statement; 59, 60; 59, 68; 60, comparison_operator:not; 60, 61; 60, 62; 61, identifier:hash_algo; 62, call; 62, 63; 62, 64; 63, identifier:set; 64, argument_list; 64, 65; 65, list:['sha1', 'sha256']; 65, 66; 65, 67; 66, string:'sha1'; 67, string:'sha256'; 68, block; 68, 69; 69, raise_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:ValueError; 72, argument_list; 72, 73; 73, binary_operator:%; 73, 74; 73, 75; 74, string:'hash_algo must be one of "sha1", "sha256", not %s'; 75, call; 75, 76; 75, 77; 76, identifier:repr; 77, argument_list; 77, 78; 78, identifier:hash_algo; 79, if_statement; 79, 80; 79, 86; 80, not_operator; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:isinstance; 83, argument_list; 83, 84; 83, 85; 84, identifier:nonce; 85, identifier:bool; 86, block; 86, 87; 87, raise_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:TypeError; 90, argument_list; 90, 91; 91, binary_operator:%; 91, 92; 91, 93; 92, string:'nonce must be a bool, not %s'; 93, call; 93, 94; 93, 95; 94, identifier:type_name; 95, argument_list; 95, 96; 96, identifier:nonce; 97, if_statement; 97, 98; 97, 101; 97, 108; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:user_agent; 100, None; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:user_agent; 105, binary_operator:%; 105, 106; 105, 107; 106, string:'certvalidator %s'; 107, identifier:__version__; 108, elif_clause; 108, 109; 108, 115; 109, not_operator; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:isinstance; 112, argument_list; 112, 113; 112, 114; 113, identifier:user_agent; 114, identifier:str_cls; 115, block; 115, 116; 116, raise_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:TypeError; 119, argument_list; 119, 120; 120, binary_operator:%; 120, 121; 120, 122; 121, string:'user_agent must be a unicode string, not %s'; 122, call; 122, 123; 122, 124; 123, identifier:type_name; 124, argument_list; 124, 125; 125, identifier:user_agent; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:cert_id; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:ocsp; 132, identifier:CertId; 133, argument_list; 133, 134; 134, dictionary; 134, 135; 134, 146; 134, 155; 134, 164; 135, pair; 135, 136; 135, 137; 136, string:'hash_algorithm'; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:algos; 140, identifier:DigestAlgorithm; 141, argument_list; 141, 142; 142, dictionary; 142, 143; 143, pair; 143, 144; 143, 145; 144, string:'algorithm'; 145, identifier:hash_algo; 146, pair; 146, 147; 146, 148; 147, string:'issuer_name_hash'; 148, call; 148, 149; 148, 150; 149, identifier:getattr; 150, argument_list; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:cert; 153, identifier:issuer; 154, identifier:hash_algo; 155, pair; 155, 156; 155, 157; 156, string:'issuer_key_hash'; 157, call; 157, 158; 157, 159; 158, identifier:getattr; 159, argument_list; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:issuer; 162, identifier:public_key; 163, identifier:hash_algo; 164, pair; 164, 165; 164, 166; 165, string:'serial_number'; 166, attribute; 166, 167; 166, 168; 167, identifier:cert; 168, identifier:serial_number; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:request; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:ocsp; 175, identifier:Request; 176, argument_list; 176, 177; 177, dictionary; 177, 178; 178, pair; 178, 179; 178, 180; 179, string:'req_cert'; 180, identifier:cert_id; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:tbs_request; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:ocsp; 187, identifier:TBSRequest; 188, argument_list; 188, 189; 189, dictionary; 189, 190; 190, pair; 190, 191; 190, 192; 191, string:'request_list'; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:ocsp; 195, identifier:Requests; 196, argument_list; 196, 197; 197, list:[request]; 197, 198; 198, identifier:request; 199, if_statement; 199, 200; 199, 201; 200, identifier:nonce; 201, block; 201, 202; 201, 239; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:nonce_extension; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:ocsp; 208, identifier:TBSRequestExtension; 209, argument_list; 209, 210; 210, dictionary; 210, 211; 210, 214; 210, 217; 211, pair; 211, 212; 211, 213; 212, string:'extn_id'; 213, string:'nonce'; 214, pair; 214, 215; 214, 216; 215, string:'critical'; 216, False; 217, pair; 217, 218; 217, 219; 218, string:'extn_value'; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:core; 222, identifier:OctetString; 223, argument_list; 223, 224; 224, call; 224, 225; 224, 238; 225, attribute; 225, 226; 225, 237; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:core; 229, identifier:OctetString; 230, argument_list; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:os; 234, identifier:urandom; 235, argument_list; 235, 236; 236, integer:16; 237, identifier:dump; 238, argument_list; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 244; 241, subscript; 241, 242; 241, 243; 242, identifier:tbs_request; 243, string:'request_extensions'; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:ocsp; 247, identifier:TBSRequestExtensions; 248, argument_list; 248, 249; 249, list:[nonce_extension]; 249, 250; 250, identifier:nonce_extension; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:ocsp_request; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:ocsp; 257, identifier:OCSPRequest; 258, argument_list; 258, 259; 259, dictionary; 259, 260; 260, pair; 260, 261; 260, 262; 261, string:'tbs_request'; 262, identifier:tbs_request; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:last_e; 266, None; 267, for_statement; 267, 268; 267, 269; 267, 272; 268, identifier:ocsp_url; 269, attribute; 269, 270; 269, 271; 270, identifier:cert; 271, identifier:ocsp_urls; 272, block; 272, 273; 273, try_statement; 273, 274; 273, 368; 274, block; 274, 275; 274, 282; 274, 290; 274, 298; 274, 306; 274, 319; 274, 334; 274, 340; 274, 346; 274, 366; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:request; 278, call; 278, 279; 278, 280; 279, identifier:Request; 280, argument_list; 280, 281; 281, identifier:ocsp_url; 282, expression_statement; 282, 283; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:request; 286, identifier:add_header; 287, argument_list; 287, 288; 287, 289; 288, string:'Accept'; 289, string:'application/ocsp-response'; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:request; 294, identifier:add_header; 295, argument_list; 295, 296; 295, 297; 296, string:'Content-Type'; 297, string:'application/ocsp-request'; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:request; 302, identifier:add_header; 303, argument_list; 303, 304; 303, 305; 304, string:'User-Agent'; 305, identifier:user_agent; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:response; 309, call; 309, 310; 309, 311; 310, identifier:urlopen; 311, argument_list; 311, 312; 311, 313; 311, 318; 312, identifier:request; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:ocsp_request; 316, identifier:dump; 317, argument_list; 318, identifier:timeout; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 322; 321, identifier:ocsp_response; 322, call; 322, 323; 322, 328; 323, attribute; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:ocsp; 326, identifier:OCSPResponse; 327, identifier:load; 328, argument_list; 328, 329; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:response; 332, identifier:read; 333, argument_list; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 337; 336, identifier:request_nonce; 337, attribute; 337, 338; 337, 339; 338, identifier:ocsp_request; 339, identifier:nonce_value; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:response_nonce; 343, attribute; 343, 344; 343, 345; 344, identifier:ocsp_response; 345, identifier:nonce_value; 346, if_statement; 346, 347; 346, 358; 347, boolean_operator:and; 347, 348; 347, 351; 348, boolean_operator:and; 348, 349; 348, 350; 349, identifier:request_nonce; 350, identifier:response_nonce; 351, comparison_operator:!=; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:request_nonce; 354, identifier:native; 355, attribute; 355, 356; 355, 357; 356, identifier:response_nonce; 357, identifier:native; 358, block; 358, 359; 359, raise_statement; 359, 360; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:errors; 363, identifier:OCSPValidationError; 364, argument_list; 364, 365; 365, string:'Unable to verify OCSP response since the request and response nonces do not match'; 366, return_statement; 366, 367; 367, identifier:ocsp_response; 368, except_clause; 368, 369; 368, 374; 369, as_pattern; 369, 370; 369, 372; 370, parenthesized_expression; 370, 371; 371, identifier:URLError; 372, as_pattern_target; 372, 373; 373, identifier:e; 374, block; 374, 375; 375, expression_statement; 375, 376; 376, assignment; 376, 377; 376, 378; 377, identifier:last_e; 378, identifier:e; 379, raise_statement; 379, 380; 380, identifier:last_e
def fetch(cert, issuer, hash_algo='sha1', nonce=True, user_agent=None, timeout=10): if not isinstance(cert, x509.Certificate): raise TypeError('cert must be an instance of asn1crypto.x509.Certificate, not %s' % type_name(cert)) if not isinstance(issuer, x509.Certificate): raise TypeError('issuer must be an instance of asn1crypto.x509.Certificate, not %s' % type_name(issuer)) if hash_algo not in set(['sha1', 'sha256']): raise ValueError('hash_algo must be one of "sha1", "sha256", not %s' % repr(hash_algo)) if not isinstance(nonce, bool): raise TypeError('nonce must be a bool, not %s' % type_name(nonce)) if user_agent is None: user_agent = 'certvalidator %s' % __version__ elif not isinstance(user_agent, str_cls): raise TypeError('user_agent must be a unicode string, not %s' % type_name(user_agent)) cert_id = ocsp.CertId({ 'hash_algorithm': algos.DigestAlgorithm({'algorithm': hash_algo}), 'issuer_name_hash': getattr(cert.issuer, hash_algo), 'issuer_key_hash': getattr(issuer.public_key, hash_algo), 'serial_number': cert.serial_number, }) request = ocsp.Request({ 'req_cert': cert_id, }) tbs_request = ocsp.TBSRequest({ 'request_list': ocsp.Requests([request]), }) if nonce: nonce_extension = ocsp.TBSRequestExtension({ 'extn_id': 'nonce', 'critical': False, 'extn_value': core.OctetString(core.OctetString(os.urandom(16)).dump()) }) tbs_request['request_extensions'] = ocsp.TBSRequestExtensions([nonce_extension]) ocsp_request = ocsp.OCSPRequest({ 'tbs_request': tbs_request, }) last_e = None for ocsp_url in cert.ocsp_urls: try: request = Request(ocsp_url) request.add_header('Accept', 'application/ocsp-response') request.add_header('Content-Type', 'application/ocsp-request') request.add_header('User-Agent', user_agent) response = urlopen(request, ocsp_request.dump(), timeout) ocsp_response = ocsp.OCSPResponse.load(response.read()) request_nonce = ocsp_request.nonce_value response_nonce = ocsp_response.nonce_value if request_nonce and response_nonce and request_nonce.native != response_nonce.native: raise errors.OCSPValidationError( 'Unable to verify OCSP response since the request and response nonces do not match' ) return ocsp_response except (URLError) as e: last_e = e raise last_e