sequence
stringlengths
492
15.9k
code
stringlengths
75
8.58k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:Debounce; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:threshold; 6, integer:100; 7, block; 7, 8; 7, 12; 7, 16; 7, 174; 8, expression_statement; 8, 9; 9, augmented_assignment:*=; 9, 10; 9, 11; 10, identifier:threshold; 11, integer:1000; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:max_tick; 15, integer:0xFFFFFFFF; 16, class_definition; 16, 17; 16, 18; 16, 20; 17, identifier:_decorated; 18, argument_list; 18, 19; 19, identifier:object; 20, block; 20, 21; 20, 45; 20, 151; 21, function_definition; 21, 22; 21, 23; 21, 26; 22, function_name:__init__; 23, parameters; 23, 24; 23, 25; 24, identifier:self; 25, identifier:pigpio_cb; 26, block; 26, 27; 26, 33; 26, 39; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:_fn; 32, identifier:pigpio_cb; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:last; 38, integer:0; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:is_method; 44, False; 45, function_definition; 45, 46; 45, 47; 45, 53; 46, function_name:__call__; 47, parameters; 47, 48; 47, 49; 47, 51; 48, identifier:self; 49, list_splat_pattern; 49, 50; 50, identifier:args; 51, dictionary_splat_pattern; 51, 52; 52, identifier:kwargs; 53, block; 53, 54; 53, 73; 53, 100; 54, if_statement; 54, 55; 54, 58; 54, 65; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:is_method; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:tick; 62, subscript; 62, 63; 62, 64; 63, identifier:args; 64, integer:3; 65, else_clause; 65, 66; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:tick; 70, subscript; 70, 71; 70, 72; 71, identifier:args; 72, integer:2; 73, if_statement; 73, 74; 73, 79; 73, 90; 74, comparison_operator:>; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:last; 78, identifier:tick; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:delay; 83, binary_operator:+; 83, 84; 83, 89; 84, binary_operator:-; 84, 85; 84, 86; 85, identifier:max_tick; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:last; 89, identifier:tick; 90, else_clause; 90, 91; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:delay; 95, binary_operator:-; 95, 96; 95, 97; 96, identifier:tick; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:last; 100, if_statement; 100, 101; 100, 104; 100, 135; 101, comparison_operator:>; 101, 102; 101, 103; 102, identifier:delay; 103, identifier:threshold; 104, block; 104, 105; 104, 115; 104, 129; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:_fn; 110, argument_list; 110, 111; 110, 113; 111, list_splat; 111, 112; 112, identifier:args; 113, dictionary_splat; 113, 114; 114, identifier:kwargs; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:print; 118, argument_list; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, string:'call passed by debouncer {} {} {}'; 122, identifier:format; 123, argument_list; 123, 124; 123, 125; 123, 128; 124, identifier:tick; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:last; 128, identifier:threshold; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:last; 134, identifier:tick; 135, else_clause; 135, 136; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:print; 140, argument_list; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, string:'call filtered out by debouncer {} {} {}'; 144, identifier:format; 145, argument_list; 145, 146; 145, 147; 145, 150; 146, identifier:tick; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:last; 150, identifier:threshold; 151, function_definition; 151, 152; 151, 153; 151, 159; 152, function_name:__get__; 153, parameters; 153, 154; 153, 155; 153, 156; 154, identifier:self; 155, identifier:instance; 156, default_parameter; 156, 157; 156, 158; 157, identifier:type; 158, None; 159, block; 159, 160; 159, 166; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:is_method; 165, True; 166, return_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:functools; 170, identifier:partial; 171, argument_list; 171, 172; 171, 173; 172, identifier:self; 173, identifier:instance; 174, return_statement; 174, 175; 175, identifier:_decorated
def Debounce(threshold=100): threshold *= 1000 max_tick = 0xFFFFFFFF class _decorated(object): def __init__(self, pigpio_cb): self._fn = pigpio_cb self.last = 0 self.is_method = False def __call__(self, *args, **kwargs): if self.is_method: tick = args[3] else: tick = args[2] if self.last > tick: delay = max_tick-self.last + tick else: delay = tick - self.last if delay > threshold: self._fn(*args, **kwargs) print('call passed by debouncer {} {} {}' .format(tick, self.last, threshold)) self.last = tick else: print('call filtered out by debouncer {} {} {}' .format(tick, self.last, threshold)) def __get__(self, instance, type=None): self.is_method = True return functools.partial(self, instance) return _decorated
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:fit; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 4, identifier:self; 5, identifier:target_type; 6, identifier:target; 7, default_parameter; 7, 8; 7, 9; 8, identifier:adjust_thickness; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:adjust_site_atten; 12, False; 13, default_parameter; 13, 14; 13, 15; 14, identifier:adjust_source_vel; 15, False; 16, block; 16, 17; 16, 25; 16, 32; 16, 40; 16, 48; 16, 54; 16, 58; 16, 74; 16, 93; 16, 124; 16, 150; 16, 171; 16, 284; 16, 298; 16, 309; 16, 326; 16, 361; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:density; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:profile; 24, identifier:density; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:nl; 28, call; 28, 29; 28, 30; 29, identifier:len; 30, argument_list; 30, 31; 31, identifier:density; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:slowness; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:profile; 39, identifier:slowness; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:thickness; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:profile; 47, identifier:thickness; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:site_atten; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_site_atten; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:initial; 57, identifier:slowness; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:bounds; 61, binary_operator:/; 61, 62; 61, 63; 62, integer:1; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:np; 66, identifier:tile; 67, argument_list; 67, 68; 67, 71; 68, tuple; 68, 69; 68, 70; 69, integer:4000; 70, integer:100; 71, tuple; 71, 72; 71, 73; 72, identifier:nl; 73, integer:1; 74, if_statement; 74, 75; 74, 77; 75, not_operator; 75, 76; 76, identifier:adjust_source_vel; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 84; 80, subscript; 80, 81; 80, 82; 81, identifier:bounds; 82, unary_operator:-; 82, 83; 83, integer:1; 84, tuple; 84, 85; 84, 89; 85, subscript; 85, 86; 85, 87; 86, identifier:initial; 87, unary_operator:-; 87, 88; 88, integer:1; 89, subscript; 89, 90; 89, 91; 90, identifier:initial; 91, unary_operator:-; 91, 92; 92, integer:1; 93, if_statement; 93, 94; 93, 95; 94, identifier:adjust_thickness; 95, block; 95, 96; 95, 115; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:bounds; 99, subscript; 99, 100; 99, 103; 99, 104; 100, attribute; 100, 101; 100, 102; 101, identifier:np; 102, identifier:r_; 103, identifier:bounds; 104, list_comprehension; 104, 105; 104, 112; 105, list:[t / 2, 2 * t]; 105, 106; 105, 109; 106, binary_operator:/; 106, 107; 106, 108; 107, identifier:t; 108, integer:2; 109, binary_operator:*; 109, 110; 109, 111; 110, integer:2; 111, identifier:t; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:t; 114, identifier:thickness; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:initial; 118, subscript; 118, 119; 118, 122; 118, 123; 119, attribute; 119, 120; 119, 121; 120, identifier:np; 121, identifier:r_; 122, identifier:initial; 123, identifier:thickness; 124, if_statement; 124, 125; 124, 126; 125, identifier:adjust_site_atten; 126, block; 126, 127; 126, 139; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:bounds; 130, subscript; 130, 131; 130, 134; 130, 135; 131, attribute; 131, 132; 131, 133; 132, identifier:np; 133, identifier:r_; 134, identifier:bounds; 135, list:[[0.0001, 0.200]]; 135, 136; 136, list:[0.0001, 0.200]; 136, 137; 136, 138; 137, float:0.0001; 138, float:0.200; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:initial; 142, subscript; 142, 143; 142, 146; 142, 147; 143, attribute; 143, 144; 143, 145; 144, identifier:np; 145, identifier:r_; 146, identifier:initial; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:site_atten; 150, function_definition; 150, 151; 150, 152; 150, 155; 151, function_name:calc_rmse; 152, parameters; 152, 153; 152, 154; 153, identifier:this; 154, identifier:that; 155, block; 155, 156; 156, return_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:np; 160, identifier:mean; 161, argument_list; 161, 162; 162, binary_operator:**; 162, 163; 162, 170; 163, parenthesized_expression; 163, 164; 164, binary_operator:/; 164, 165; 164, 169; 165, parenthesized_expression; 165, 166; 166, binary_operator:-; 166, 167; 166, 168; 167, identifier:this; 168, identifier:that; 169, identifier:that; 170, integer:2; 171, function_definition; 171, 172; 171, 173; 171, 175; 172, function_name:err; 173, parameters; 173, 174; 174, identifier:x; 175, block; 175, 176; 175, 185; 175, 206; 175, 218; 175, 231; 175, 240; 175, 250; 175, 258; 175, 269; 175, 282; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:_slowness; 179, subscript; 179, 180; 179, 181; 180, identifier:x; 181, slice; 181, 182; 181, 183; 181, 184; 182, integer:0; 183, colon; 184, identifier:nl; 185, if_statement; 185, 186; 185, 187; 185, 200; 186, identifier:adjust_thickness; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:_thickness; 191, subscript; 191, 192; 191, 193; 192, identifier:x; 193, slice; 193, 194; 193, 195; 193, 196; 194, identifier:nl; 195, colon; 196, parenthesized_expression; 196, 197; 197, binary_operator:*; 197, 198; 197, 199; 198, integer:2; 199, identifier:nl; 200, else_clause; 200, 201; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:_thickness; 205, identifier:thickness; 206, if_statement; 206, 207; 206, 208; 207, identifier:adjust_site_atten; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:_site_atten; 214, subscript; 214, 215; 214, 216; 215, identifier:x; 216, unary_operator:-; 216, 217; 217, integer:1; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 223; 220, pattern_list; 220, 221; 220, 222; 221, identifier:crustal_amp; 222, identifier:site_term; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:_calc_amp; 227, argument_list; 227, 228; 227, 229; 227, 230; 228, identifier:density; 229, identifier:_thickness; 230, identifier:_slowness; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:calc; 234, conditional_expression:if; 234, 235; 234, 236; 234, 239; 235, identifier:crustal_amp; 236, comparison_operator:==; 236, 237; 236, 238; 237, identifier:target_type; 238, string:'crustal_amp'; 239, identifier:site_term; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:err; 243, binary_operator:*; 243, 244; 243, 245; 244, integer:10; 245, call; 245, 246; 245, 247; 246, identifier:calc_rmse; 247, argument_list; 247, 248; 247, 249; 248, identifier:target; 249, identifier:calc; 250, expression_statement; 250, 251; 251, augmented_assignment:+=; 251, 252; 251, 253; 252, identifier:err; 253, call; 253, 254; 253, 255; 254, identifier:calc_rmse; 255, argument_list; 255, 256; 255, 257; 256, identifier:slowness; 257, identifier:_slowness; 258, if_statement; 258, 259; 258, 260; 259, identifier:adjust_thickness; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, augmented_assignment:+=; 262, 263; 262, 264; 263, identifier:err; 264, call; 264, 265; 264, 266; 265, identifier:calc_rmse; 266, argument_list; 266, 267; 266, 268; 267, identifier:thickness; 268, identifier:_thickness; 269, if_statement; 269, 270; 269, 271; 270, identifier:adjust_site_atten; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, augmented_assignment:+=; 273, 274; 273, 275; 274, identifier:err; 275, call; 275, 276; 275, 277; 276, identifier:calc_rmse; 277, argument_list; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:_site_atten; 281, identifier:site_atten; 282, return_statement; 282, 283; 283, identifier:err; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:res; 287, call; 287, 288; 287, 289; 288, identifier:minimize; 289, argument_list; 289, 290; 289, 291; 289, 292; 289, 295; 290, identifier:err; 291, identifier:initial; 292, keyword_argument; 292, 293; 292, 294; 293, identifier:method; 294, string:'L-BFGS-B'; 295, keyword_argument; 295, 296; 295, 297; 296, identifier:bounds; 297, identifier:bounds; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:slowness; 301, subscript; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:res; 304, identifier:x; 305, slice; 305, 306; 305, 307; 305, 308; 306, integer:0; 307, colon; 308, identifier:nl; 309, if_statement; 309, 310; 309, 311; 310, identifier:adjust_thickness; 311, block; 311, 312; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:thickness; 315, subscript; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:res; 318, identifier:x; 319, slice; 319, 320; 319, 321; 319, 322; 320, identifier:nl; 321, colon; 322, parenthesized_expression; 322, 323; 323, binary_operator:*; 323, 324; 323, 325; 324, integer:2; 325, identifier:nl; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 329; 328, identifier:profile; 329, call; 329, 330; 329, 331; 330, identifier:Profile; 331, argument_list; 331, 332; 331, 356; 332, list_comprehension; 332, 333; 332, 343; 333, call; 333, 334; 333, 335; 334, identifier:Layer; 335, argument_list; 335, 336; 335, 339; 335, 340; 336, attribute; 336, 337; 336, 338; 337, identifier:l; 338, identifier:soil_type; 339, identifier:t; 340, binary_operator:/; 340, 341; 340, 342; 341, integer:1; 342, identifier:s; 343, for_in_clause; 343, 344; 343, 348; 344, pattern_list; 344, 345; 344, 346; 344, 347; 345, identifier:l; 346, identifier:t; 347, identifier:s; 348, call; 348, 349; 348, 350; 349, identifier:zip; 350, argument_list; 350, 351; 350, 354; 350, 355; 351, attribute; 351, 352; 351, 353; 352, identifier:self; 353, identifier:profile; 354, identifier:thickness; 355, identifier:slowness; 356, attribute; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:self; 359, identifier:profile; 360, identifier:wt_depth; 361, return_statement; 361, 362; 362, tuple; 362, 363; 362, 366; 362, 367; 363, attribute; 363, 364; 363, 365; 364, identifier:self; 365, identifier:motion; 366, identifier:profile; 367, attribute; 367, 368; 367, 369; 368, identifier:self; 369, identifier:loc_input
def fit(self, target_type, target, adjust_thickness=False, adjust_site_atten=False, adjust_source_vel=False): density = self.profile.density nl = len(density) slowness = self.profile.slowness thickness = self.profile.thickness site_atten = self._site_atten initial = slowness bounds = 1 / np.tile((4000, 100), (nl, 1)) if not adjust_source_vel: bounds[-1] = (initial[-1], initial[-1]) if adjust_thickness: bounds = np.r_[bounds, [[t / 2, 2 * t] for t in thickness]] initial = np.r_[initial, thickness] if adjust_site_atten: bounds = np.r_[bounds, [[0.0001, 0.200]]] initial = np.r_[initial, self.site_atten] def calc_rmse(this, that): return np.mean(((this - that) / that) ** 2) def err(x): _slowness = x[0:nl] if adjust_thickness: _thickness = x[nl:(2 * nl)] else: _thickness = thickness if adjust_site_atten: self._site_atten = x[-1] crustal_amp, site_term = self._calc_amp(density, _thickness, _slowness) calc = crustal_amp if target_type == 'crustal_amp' else site_term err = 10 * calc_rmse(target, calc) err += calc_rmse(slowness, _slowness) if adjust_thickness: err += calc_rmse(thickness, _thickness) if adjust_site_atten: err += calc_rmse(self._site_atten, site_atten) return err res = minimize(err, initial, method='L-BFGS-B', bounds=bounds) slowness = res.x[0:nl] if adjust_thickness: thickness = res.x[nl:(2 * nl)] profile = Profile([ Layer(l.soil_type, t, 1 / s) for l, t, s in zip(self.profile, thickness, slowness) ], self.profile.wt_depth) return (self.motion, profile, self.loc_input)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:build_recipe_input; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:ob; 6, identifier:dal; 7, block; 7, 8; 7, 12; 7, 16; 7, 20; 7, 157; 7, 166; 7, 172; 7, 212; 7, 261; 7, 331; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:result; 11, dictionary; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:ob_query_skip; 15, False; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:ob_query_field; 19, string:'obresult'; 20, if_statement; 20, 21; 20, 26; 20, 151; 21, call; 21, 22; 21, 23; 22, identifier:isinstance; 23, argument_list; 23, 24; 23, 25; 24, identifier:ob; 25, identifier:ObservingBlock; 26, block; 26, 27; 26, 34; 27, import_statement; 27, 28; 28, aliased_import; 28, 29; 28, 33; 29, dotted_name; 29, 30; 29, 31; 29, 32; 30, identifier:numina; 31, identifier:types; 32, identifier:obsresult; 33, identifier:obtype; 34, for_statement; 34, 35; 34, 38; 34, 47; 34, 145; 35, pattern_list; 35, 36; 35, 37; 36, identifier:key; 37, identifier:req; 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:self; 43, identifier:requirements; 44, argument_list; 45, identifier:items; 46, argument_list; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 58; 49, call; 49, 50; 49, 51; 50, identifier:isinstance; 51, argument_list; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:req; 54, identifier:type; 55, attribute; 55, 56; 55, 57; 56, identifier:obtype; 57, identifier:ObservationResultType; 58, block; 58, 59; 58, 63; 58, 67; 58, 78; 58, 84; 58, 92; 58, 105; 58, 113; 58, 144; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:ob_query_field; 62, identifier:key; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:ob_query_skip; 66, True; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:query_option; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:query_options; 75, identifier:get; 76, argument_list; 76, 77; 77, identifier:key; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:new_or; 81, call; 81, 82; 81, 83; 82, identifier:ObservationResult; 83, argument_list; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:new_or; 88, identifier:__dict__; 89, attribute; 89, 90; 89, 91; 90, identifier:ob; 91, identifier:__dict__; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:obsres; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:req; 98, identifier:query; 99, argument_list; 99, 100; 99, 101; 99, 102; 100, identifier:dal; 101, identifier:new_or; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:options; 104, identifier:query_option; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:tagger; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:mode; 112, identifier:tagger; 113, if_statement; 113, 114; 113, 117; 113, 136; 114, comparison_operator:is; 114, 115; 114, 116; 115, identifier:tagger; 116, None; 117, block; 117, 118; 117, 127; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 125; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:logger; 124, identifier:debug; 125, argument_list; 125, 126; 126, string:'Use mode tagger to fill tags in OB'; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:obsres; 131, identifier:tags; 132, call; 132, 133; 132, 134; 133, identifier:tagger; 134, argument_list; 134, 135; 135, identifier:obsres; 136, else_clause; 136, 137; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:obsres; 142, identifier:tags; 143, None; 144, break_statement; 145, else_clause; 145, 146; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:obsres; 150, identifier:ob; 151, else_clause; 151, 152; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:obsres; 156, identifier:ob; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:logger; 163, identifier:debug; 164, argument_list; 164, 165; 165, string:'getting query fields per REQ'; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:qfields; 169, call; 169, 170; 169, 171; 170, identifier:set; 171, argument_list; 172, for_statement; 172, 173; 172, 176; 172, 185; 173, pattern_list; 173, 174; 173, 175; 174, identifier:key; 175, identifier:req; 176, call; 176, 177; 176, 184; 177, attribute; 177, 178; 177, 183; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:requirements; 182, argument_list; 183, identifier:items; 184, argument_list; 185, block; 185, 186; 185, 194; 185, 205; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:tag_n; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:req; 192, identifier:tag_names; 193, argument_list; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:logger; 200, identifier:debug; 201, argument_list; 201, 202; 201, 203; 201, 204; 202, string:"%s has these query fields %s"; 203, identifier:key; 204, identifier:tag_n; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:qfields; 209, identifier:update; 210, argument_list; 210, 211; 211, identifier:tag_n; 212, if_statement; 212, 213; 212, 218; 213, comparison_operator:is; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:obsres; 216, identifier:tags; 217, None; 218, block; 218, 219; 218, 228; 218, 238; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 226; 221, attribute; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:self; 224, identifier:logger; 225, identifier:debug; 226, argument_list; 226, 227; 227, string:'running recipe tagger'; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 235; 230, attribute; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:logger; 234, identifier:debug; 235, argument_list; 235, 236; 235, 237; 236, string:'with query fields %s'; 237, identifier:qfields; 238, if_statement; 238, 239; 238, 240; 238, 253; 239, identifier:qfields; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:obsres; 245, identifier:tags; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:self; 249, identifier:obsres_extractor; 250, argument_list; 250, 251; 250, 252; 251, identifier:obsres; 252, identifier:qfields; 253, else_clause; 253, 254; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:obsres; 259, identifier:tags; 260, dictionary; 261, for_statement; 261, 262; 261, 265; 261, 274; 262, pattern_list; 262, 263; 262, 264; 263, identifier:key; 264, identifier:req; 265, call; 265, 266; 265, 273; 266, attribute; 266, 267; 266, 272; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:requirements; 271, argument_list; 272, identifier:items; 273, argument_list; 274, block; 274, 275; 275, try_statement; 275, 276; 275, 318; 276, block; 276, 277; 276, 288; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:query_option; 280, call; 280, 281; 280, 286; 281, attribute; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:query_options; 285, identifier:get; 286, argument_list; 286, 287; 287, identifier:key; 288, if_statement; 288, 289; 288, 294; 288, 301; 289, boolean_operator:and; 289, 290; 289, 293; 290, comparison_operator:==; 290, 291; 290, 292; 291, identifier:key; 292, identifier:ob_query_field; 293, identifier:ob_query_skip; 294, block; 294, 295; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 300; 297, subscript; 297, 298; 297, 299; 298, identifier:result; 299, identifier:key; 300, identifier:obsres; 301, else_clause; 301, 302; 302, block; 302, 303; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 308; 305, subscript; 305, 306; 305, 307; 306, identifier:result; 307, identifier:key; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:req; 311, identifier:query; 312, argument_list; 312, 313; 312, 314; 312, 315; 313, identifier:dal; 314, identifier:obsres; 315, keyword_argument; 315, 316; 315, 317; 316, identifier:options; 317, identifier:query_option; 318, except_clause; 318, 319; 318, 323; 319, as_pattern; 319, 320; 319, 321; 320, identifier:NoResultFound; 321, as_pattern_target; 321, 322; 322, identifier:notfound; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:req; 328, identifier:on_query_not_found; 329, argument_list; 329, 330; 330, identifier:notfound; 331, return_statement; 331, 332; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:self; 335, identifier:create_input; 336, argument_list; 336, 337; 337, dictionary_splat; 337, 338; 338, identifier:result
def build_recipe_input(self, ob, dal): result = {} ob_query_skip = False ob_query_field = 'obresult' if isinstance(ob, ObservingBlock): import numina.types.obsresult as obtype for key, req in self.requirements().items(): if isinstance(req.type, obtype.ObservationResultType): ob_query_field = key ob_query_skip = True query_option = self.query_options.get(key) new_or = ObservationResult() new_or.__dict__ = ob.__dict__ obsres = req.query(dal, new_or, options=query_option) tagger = self.mode.tagger if tagger is not None: self.logger.debug('Use mode tagger to fill tags in OB') obsres.tags = tagger(obsres) else: obsres.tags = None break else: obsres = ob else: obsres = ob self.logger.debug('getting query fields per REQ') qfields = set() for key, req in self.requirements().items(): tag_n = req.tag_names() self.logger.debug("%s has these query fields %s", key, tag_n) qfields.update(tag_n) if obsres.tags is None: self.logger.debug('running recipe tagger') self.logger.debug('with query fields %s', qfields) if qfields: obsres.tags = self.obsres_extractor(obsres, qfields) else: obsres.tags = {} for key, req in self.requirements().items(): try: query_option = self.query_options.get(key) if key == ob_query_field and ob_query_skip: result[key] = obsres else: result[key] = req.query(dal, obsres, options=query_option) except NoResultFound as notfound: req.on_query_not_found(notfound) return self.create_input(**result)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:subsets_of_fileinfo_from_txt; 3, parameters; 3, 4; 4, identifier:filename; 5, block; 5, 6; 5, 26; 5, 49; 5, 53; 5, 57; 5, 61; 5, 65; 5, 69; 5, 73; 5, 77; 5, 290; 5, 299; 6, if_statement; 6, 7; 6, 16; 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:os; 12, identifier:path; 13, identifier:isfile; 14, argument_list; 14, 15; 15, identifier:filename; 16, block; 16, 17; 17, raise_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:ValueError; 20, argument_list; 20, 21; 21, binary_operator:+; 21, 22; 21, 25; 22, binary_operator:+; 22, 23; 22, 24; 23, string:"File "; 24, identifier:filename; 25, string:" not found!"; 26, with_statement; 26, 27; 26, 36; 27, with_clause; 27, 28; 28, with_item; 28, 29; 29, as_pattern; 29, 30; 29, 34; 30, call; 30, 31; 30, 32; 31, identifier:open; 32, argument_list; 32, 33; 33, identifier:filename; 34, as_pattern_target; 34, 35; 35, identifier:f; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:file_content; 40, call; 40, 41; 40, 48; 41, attribute; 41, 42; 41, 47; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:f; 45, identifier:read; 46, argument_list; 47, identifier:splitlines; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:dict_of_subsets_of_fileinfo; 52, dictionary; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:label; 56, None; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:sublist_of_fileinfo; 60, list:[]; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:idict; 64, integer:0; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:ifiles; 68, integer:0; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:nfiles; 72, integer:0; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:sublist_finished; 76, True; 77, for_statement; 77, 78; 77, 79; 77, 80; 78, identifier:line; 79, identifier:file_content; 80, block; 80, 81; 81, if_statement; 81, 82; 81, 88; 82, comparison_operator:>; 82, 83; 82, 87; 83, call; 83, 84; 83, 85; 84, identifier:len; 85, argument_list; 85, 86; 86, identifier:line; 87, integer:0; 88, block; 88, 89; 89, if_statement; 89, 90; 89, 98; 89, 156; 90, comparison_operator:!=; 90, 91; 90, 94; 90, 96; 90, 97; 91, subscript; 91, 92; 91, 93; 92, identifier:line; 93, integer:0; 94, ERROR; 94, 95; 95, identifier:if; 96, identifier:label; 97, None; 98, block; 98, 99; 99, if_statement; 99, 100; 99, 105; 99, 149; 100, comparison_operator:==; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:line; 103, integer:0; 104, string:"@"; 105, block; 105, 106; 105, 123; 105, 137; 105, 141; 105, 145; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:nfiles; 109, call; 109, 110; 109, 111; 110, identifier:int; 111, argument_list; 111, 112; 112, subscript; 112, 113; 112, 122; 113, call; 113, 114; 113, 121; 114, attribute; 114, 115; 114, 120; 115, subscript; 115, 116; 115, 117; 116, identifier:line; 117, slice; 117, 118; 117, 119; 118, integer:1; 119, colon; 120, identifier:split; 121, argument_list; 122, integer:0; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:label; 126, subscript; 126, 127; 126, 136; 127, call; 127, 128; 127, 135; 128, attribute; 128, 129; 128, 134; 129, subscript; 129, 130; 129, 131; 130, identifier:line; 131, slice; 131, 132; 131, 133; 132, integer:1; 133, colon; 134, identifier:split; 135, argument_list; 136, integer:1; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:sublist_of_fileinfo; 140, list:[]; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:ifiles; 144, integer:0; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:sublist_finished; 148, False; 149, else_clause; 149, 150; 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:"Expected @ symbol not found!"; 156, else_clause; 156, 157; 157, block; 157, 158; 157, 170; 157, 178; 157, 184; 157, 206; 157, 226; 157, 237; 157, 241; 158, if_statement; 158, 159; 158, 164; 159, comparison_operator:==; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:line; 162, integer:0; 163, string:"@"; 164, block; 164, 165; 165, raise_statement; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:ValueError; 168, argument_list; 168, 169; 169, string:"Unexpected @ symbol found!"; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:tmplist; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:line; 176, identifier:split; 177, argument_list; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:tmpfile; 181, subscript; 181, 182; 181, 183; 182, identifier:tmplist; 183, integer:0; 184, if_statement; 184, 185; 184, 191; 184, 200; 185, comparison_operator:>; 185, 186; 185, 190; 186, call; 186, 187; 186, 188; 187, identifier:len; 188, argument_list; 188, 189; 189, identifier:tmplist; 190, integer:1; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:tmpinfo; 195, subscript; 195, 196; 195, 197; 196, identifier:tmplist; 197, slice; 197, 198; 197, 199; 198, integer:1; 199, colon; 200, else_clause; 200, 201; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:tmpinfo; 205, None; 206, if_statement; 206, 207; 206, 216; 207, not_operator; 207, 208; 208, call; 208, 209; 208, 214; 209, attribute; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:os; 212, identifier:path; 213, identifier:isfile; 214, argument_list; 214, 215; 215, identifier:tmpfile; 216, block; 216, 217; 217, raise_statement; 217, 218; 218, call; 218, 219; 218, 220; 219, identifier:ValueError; 220, argument_list; 220, 221; 221, binary_operator:+; 221, 222; 221, 225; 222, binary_operator:+; 222, 223; 222, 224; 223, string:"File "; 224, identifier:tmpfile; 225, string:" not found!"; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:sublist_of_fileinfo; 230, identifier:append; 231, argument_list; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:FileInfo; 234, argument_list; 234, 235; 234, 236; 235, identifier:tmpfile; 236, identifier:tmpinfo; 237, expression_statement; 237, 238; 238, augmented_assignment:+=; 238, 239; 238, 240; 239, identifier:ifiles; 240, integer:1; 241, if_statement; 241, 242; 241, 245; 242, comparison_operator:==; 242, 243; 242, 244; 243, identifier:ifiles; 244, identifier:nfiles; 245, block; 245, 246; 245, 252; 245, 258; 245, 264; 245, 270; 245, 274; 245, 278; 245, 282; 245, 286; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:dict_of_subsets_of_fileinfo; 250, identifier:idict; 251, dictionary; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:tmpdict; 255, subscript; 255, 256; 255, 257; 256, identifier:dict_of_subsets_of_fileinfo; 257, identifier:idict; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 263; 260, subscript; 260, 261; 260, 262; 261, identifier:tmpdict; 262, string:'label'; 263, identifier:label; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 269; 266, subscript; 266, 267; 266, 268; 267, identifier:tmpdict; 268, string:'list_of_fileinfo'; 269, identifier:sublist_of_fileinfo; 270, expression_statement; 270, 271; 271, augmented_assignment:+=; 271, 272; 271, 273; 272, identifier:idict; 273, integer:1; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:label; 277, None; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:sublist_of_fileinfo; 281, list:[]; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:ifiles; 285, integer:0; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:sublist_finished; 289, True; 290, if_statement; 290, 291; 290, 293; 291, not_operator; 291, 292; 292, identifier:sublist_finished; 293, block; 293, 294; 294, raise_statement; 294, 295; 295, call; 295, 296; 295, 297; 296, identifier:ValueError; 297, argument_list; 297, 298; 298, string:"Unexpected end of sublist of files."; 299, return_statement; 299, 300; 300, identifier:dict_of_subsets_of_fileinfo
def subsets_of_fileinfo_from_txt(filename): if not os.path.isfile(filename): raise ValueError("File " + filename + " not found!") with open(filename) as f: file_content = f.read().splitlines() dict_of_subsets_of_fileinfo = {} label = None sublist_of_fileinfo = [] idict = 0 ifiles = 0 nfiles = 0 sublist_finished = True for line in file_content: if len(line) > 0: if line[0] != ' if label is None: if line[0] == "@": nfiles = int(line[1:].split()[0]) label = line[1:].split()[1] sublist_of_fileinfo = [] ifiles = 0 sublist_finished = False else: raise ValueError("Expected @ symbol not found!") else: if line[0] == "@": raise ValueError("Unexpected @ symbol found!") tmplist = line.split() tmpfile = tmplist[0] if len(tmplist) > 1: tmpinfo = tmplist[1:] else: tmpinfo = None if not os.path.isfile(tmpfile): raise ValueError("File " + tmpfile + " not found!") sublist_of_fileinfo.append(FileInfo(tmpfile, tmpinfo)) ifiles += 1 if ifiles == nfiles: dict_of_subsets_of_fileinfo[idict] = {} tmpdict = dict_of_subsets_of_fileinfo[idict] tmpdict['label'] = label tmpdict['list_of_fileinfo'] = sublist_of_fileinfo idict += 1 label = None sublist_of_fileinfo = [] ifiles = 0 sublist_finished = True if not sublist_finished: raise ValueError("Unexpected end of sublist of files.") return dict_of_subsets_of_fileinfo
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:verify_refresh; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:request; 6, block; 6, 7; 6, 18; 6, 27; 6, 37; 6, 67; 6, 76; 6, 88; 6, 123; 6, 179; 7, if_statement; 7, 8; 7, 12; 8, not_operator; 8, 9; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:allow_refresh; 12, block; 12, 13; 13, raise_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:InvalidTokenError; 16, argument_list; 16, 17; 17, string:'Token refresh is disabled'; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:token; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:get_jwt; 25, argument_list; 25, 26; 26, identifier:request; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:token; 30, None; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:InvalidTokenError; 35, argument_list; 35, 36; 36, string:'Token not found'; 37, try_statement; 37, 38; 37, 51; 37, 59; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:claims_set; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:decode_jwt; 46, argument_list; 46, 47; 46, 48; 47, identifier:token; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:verify_expiration_on_refresh; 51, except_clause; 51, 52; 51, 53; 52, identifier:DecodeError; 53, block; 53, 54; 54, raise_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:DecodeError; 57, argument_list; 57, 58; 58, string:'Token could not be decoded'; 59, except_clause; 59, 60; 59, 61; 60, identifier:ExpiredSignatureError; 61, block; 61, 62; 62, raise_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:ExpiredSignatureError; 65, argument_list; 65, 66; 66, string:'Token has expired'; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:userid; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:get_userid; 74, argument_list; 74, 75; 75, identifier:claims_set; 76, if_statement; 76, 77; 76, 80; 77, comparison_operator:is; 77, 78; 77, 79; 78, identifier:userid; 79, None; 80, block; 80, 81; 81, raise_statement; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:MissingRequiredClaimError; 84, argument_list; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:userid_claim; 88, if_statement; 88, 89; 88, 94; 89, comparison_operator:is; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:refresh_nonce_handler; 93, None; 94, block; 94, 95; 94, 105; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:not; 96, 97; 96, 98; 97, string:'nonce'; 98, identifier:claims_set; 99, block; 99, 100; 100, raise_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:MissingRequiredClaimError; 103, argument_list; 103, 104; 104, string:'nonce'; 105, if_statement; 105, 106; 105, 117; 106, comparison_operator:!=; 106, 107; 106, 114; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:refresh_nonce_handler; 111, argument_list; 111, 112; 111, 113; 112, identifier:request; 113, identifier:userid; 114, subscript; 114, 115; 114, 116; 115, identifier:claims_set; 116, string:'nonce'; 117, block; 117, 118; 118, raise_statement; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:InvalidTokenError; 121, argument_list; 121, 122; 122, string:'Refresh nonce is not valid'; 123, if_statement; 123, 124; 123, 129; 124, comparison_operator:is; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:refresh_delta; 128, None; 129, block; 129, 130; 129, 140; 129, 155; 129, 164; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:not; 131, 132; 131, 133; 132, string:'refresh_until'; 133, identifier:claims_set; 134, block; 134, 135; 135, raise_statement; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:MissingRequiredClaimError; 138, argument_list; 138, 139; 139, string:'refresh_until'; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:now; 143, call; 143, 144; 143, 145; 144, identifier:timegm; 145, argument_list; 145, 146; 146, call; 146, 147; 146, 154; 147, attribute; 147, 148; 147, 153; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:datetime; 151, identifier:utcnow; 152, argument_list; 153, identifier:utctimetuple; 154, argument_list; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:refresh_until; 158, call; 158, 159; 158, 160; 159, identifier:int; 160, argument_list; 160, 161; 161, subscript; 161, 162; 161, 163; 162, identifier:claims_set; 163, string:'refresh_until'; 164, if_statement; 164, 165; 164, 173; 165, comparison_operator:<; 165, 166; 165, 167; 166, identifier:refresh_until; 167, parenthesized_expression; 167, 168; 168, binary_operator:-; 168, 169; 168, 170; 169, identifier:now; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:leeway; 173, block; 173, 174; 174, raise_statement; 174, 175; 175, call; 175, 176; 175, 177; 176, identifier:ExpiredSignatureError; 177, argument_list; 177, 178; 178, string:'Refresh nonce has expired'; 179, return_statement; 179, 180; 180, identifier:userid
def verify_refresh(self, request): if not self.allow_refresh: raise InvalidTokenError('Token refresh is disabled') token = self.get_jwt(request) if token is None: raise InvalidTokenError('Token not found') try: claims_set = self.decode_jwt( token, self.verify_expiration_on_refresh ) except DecodeError: raise DecodeError('Token could not be decoded') except ExpiredSignatureError: raise ExpiredSignatureError('Token has expired') userid = self.get_userid(claims_set) if userid is None: raise MissingRequiredClaimError(self.userid_claim) if self.refresh_nonce_handler is not None: if 'nonce' not in claims_set: raise MissingRequiredClaimError('nonce') if self.refresh_nonce_handler(request, userid) != claims_set['nonce']: raise InvalidTokenError('Refresh nonce is not valid') if self.refresh_delta is not None: if 'refresh_until' not in claims_set: raise MissingRequiredClaimError('refresh_until') now = timegm(datetime.utcnow().utctimetuple()) refresh_until = int(claims_set['refresh_until']) if refresh_until < (now - self.leeway): raise ExpiredSignatureError('Refresh nonce has expired') return userid
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_default_terminal; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:environ; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:fallback; 9, identifier:_UNSPECIFIED; 10, block; 10, 11; 10, 22; 10, 31; 10, 35; 10, 44; 10, 77; 10, 90; 10, 96; 10, 103; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:environ; 14, None; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:environ; 19, attribute; 19, 20; 19, 21; 20, identifier:os; 21, identifier:environ; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:in; 23, 24; 23, 25; 24, string:"PIAS_OPT_TERMINAL"; 25, identifier:environ; 26, block; 26, 27; 27, return_statement; 27, 28; 28, subscript; 28, 29; 28, 30; 29, identifier:environ; 30, string:"PIAS_OPT_TERMINAL"; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:terminals; 34, list:[]; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:colorterm; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:environ; 41, identifier:get; 42, argument_list; 42, 43; 43, string:"COLORTERM"; 44, for_statement; 44, 45; 44, 46; 44, 51; 45, identifier:filename; 46, tuple; 46, 47; 46, 48; 46, 49; 46, 50; 47, identifier:colorterm; 48, string:"gnome-terminal"; 49, string:"konsole"; 50, string:"xterm"; 51, block; 51, 52; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:is; 53, 54; 53, 55; 54, identifier:filename; 55, None; 56, block; 56, 57; 56, 65; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:filepath; 60, call; 60, 61; 60, 62; 61, identifier:find_executable; 62, argument_list; 62, 63; 62, 64; 63, identifier:filename; 64, identifier:environ; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:filepath; 68, None; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:terminals; 74, identifier:append; 75, argument_list; 75, 76; 76, identifier:filepath; 77, for_statement; 77, 78; 77, 79; 77, 82; 78, identifier:ancestor; 79, call; 79, 80; 79, 81; 80, identifier:get_ancestor_processes; 81, argument_list; 82, block; 82, 83; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:in; 84, 85; 84, 86; 85, identifier:ancestor; 86, identifier:terminals; 87, block; 87, 88; 88, return_statement; 88, 89; 89, identifier:ancestor; 90, for_statement; 90, 91; 90, 92; 90, 93; 91, identifier:term; 92, identifier:terminals; 93, block; 93, 94; 94, return_statement; 94, 95; 95, identifier:term; 96, if_statement; 96, 97; 96, 100; 97, comparison_operator:is; 97, 98; 97, 99; 98, identifier:fallback; 99, identifier:_UNSPECIFIED; 100, block; 100, 101; 101, return_statement; 101, 102; 102, identifier:fallback; 103, raise_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:ValueError; 106, argument_list; 106, 107; 107, string:"Could not find a terminal"
def get_default_terminal(environ=None, fallback=_UNSPECIFIED): if environ is None: environ = os.environ if "PIAS_OPT_TERMINAL" in environ: return environ["PIAS_OPT_TERMINAL"] terminals = [] colorterm = environ.get("COLORTERM") for filename in (colorterm, "gnome-terminal", "konsole", "xterm"): if filename is not None: filepath = find_executable(filename, environ) if filepath is not None: terminals.append(filepath) for ancestor in get_ancestor_processes(): if ancestor in terminals: return ancestor for term in terminals: return term if fallback is not _UNSPECIFIED: return fallback raise ValueError("Could not find a terminal")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:bitset; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 11; 3, 14; 4, identifier:name; 5, identifier:members; 6, default_parameter; 6, 7; 6, 8; 7, identifier:base; 8, attribute; 8, 9; 8, 10; 9, identifier:bases; 10, identifier:BitSet; 11, default_parameter; 11, 12; 11, 13; 12, identifier:list; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:tuple; 16, False; 17, block; 17, 18; 17, 29; 17, 51; 17, 66; 17, 88; 17, 107; 17, 125; 17, 143; 18, if_statement; 18, 19; 18, 21; 19, not_operator; 19, 20; 20, identifier:name; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:ValueError; 25, argument_list; 25, 26; 26, binary_operator:%; 26, 27; 26, 28; 27, string:'empty bitset name: %r'; 28, identifier:name; 29, if_statement; 29, 30; 29, 43; 30, boolean_operator:or; 30, 31; 30, 37; 31, not_operator; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:hasattr; 34, argument_list; 34, 35; 34, 36; 35, identifier:members; 36, string:'__getitem__'; 37, not_operator; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:hasattr; 40, argument_list; 40, 41; 40, 42; 41, identifier:members; 42, string:'__len__'; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:ValueError; 47, argument_list; 47, 48; 48, binary_operator:%; 48, 49; 48, 50; 49, string:'non-sequence bitset members: %r'; 50, identifier:members; 51, if_statement; 51, 52; 51, 57; 52, not_operator; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:members; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:ValueError; 61, argument_list; 61, 62; 62, binary_operator:%; 62, 63; 62, 64; 63, string:'less than one bitset member: %r'; 64, tuple; 64, 65; 65, identifier:members; 66, if_statement; 66, 67; 66, 79; 67, comparison_operator:!=; 67, 68; 67, 75; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:set; 73, argument_list; 73, 74; 74, identifier:members; 75, call; 75, 76; 75, 77; 76, identifier:len; 77, argument_list; 77, 78; 78, identifier:members; 79, block; 79, 80; 80, raise_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:ValueError; 83, argument_list; 83, 84; 84, binary_operator:%; 84, 85; 84, 86; 85, string:'bitset members contains duplicates: %r'; 86, tuple; 86, 87; 87, identifier:members; 88, if_statement; 88, 89; 88, 99; 89, not_operator; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:issubclass; 92, argument_list; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:base; 95, identifier:__class__; 96, attribute; 96, 97; 96, 98; 97, identifier:meta; 98, identifier:MemberBitsMeta; 99, block; 99, 100; 100, raise_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:ValueError; 103, argument_list; 103, 104; 104, binary_operator:%; 104, 105; 104, 106; 105, string:'base does not subclass bitset.bases: %r'; 106, identifier:base; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:list; 110, call; 110, 111; 110, 122; 111, attribute; 111, 112; 111, 121; 112, dictionary; 112, 113; 112, 116; 113, pair; 113, 114; 113, 115; 114, False; 115, None; 116, pair; 116, 117; 116, 118; 117, True; 118, attribute; 118, 119; 118, 120; 119, identifier:series; 120, identifier:List; 121, identifier:get; 122, argument_list; 122, 123; 122, 124; 123, identifier:list; 124, identifier:list; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:tuple; 128, call; 128, 129; 128, 140; 129, attribute; 129, 130; 129, 139; 130, dictionary; 130, 131; 130, 134; 131, pair; 131, 132; 131, 133; 132, False; 133, None; 134, pair; 134, 135; 134, 136; 135, True; 136, attribute; 136, 137; 136, 138; 137, identifier:series; 138, identifier:Tuple; 139, identifier:get; 140, argument_list; 140, 141; 140, 142; 141, identifier:tuple; 142, identifier:tuple; 143, return_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:base; 147, identifier:_make_subclass; 148, argument_list; 148, 149; 148, 150; 148, 151; 148, 154; 149, identifier:name; 150, identifier:members; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:listcls; 153, identifier:list; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:tuplecls; 156, identifier:tuple
def bitset(name, members, base=bases.BitSet, list=False, tuple=False): if not name: raise ValueError('empty bitset name: %r' % name) if not hasattr(members, '__getitem__') or not hasattr(members, '__len__'): raise ValueError('non-sequence bitset members: %r' % members) if not len(members): raise ValueError('less than one bitset member: %r' % (members,)) if len(set(members)) != len(members): raise ValueError('bitset members contains duplicates: %r' % (members,)) if not issubclass(base.__class__, meta.MemberBitsMeta): raise ValueError('base does not subclass bitset.bases: %r' % base) list = {False: None, True: series.List}.get(list, list) tuple = {False: None, True: series.Tuple}.get(tuple, tuple) return base._make_subclass(name, members, listcls=list, tuplecls=tuple)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_split_refextract_authors_str; 3, parameters; 3, 4; 4, identifier:authors_str; 5, block; 5, 6; 5, 25; 5, 29; 5, 33; 5, 144; 5, 154; 5, 182; 5, 202; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:author_seq; 9, generator_expression; 9, 10; 9, 15; 9, 23; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:x; 13, identifier:strip; 14, argument_list; 15, for_in_clause; 15, 16; 15, 17; 16, identifier:x; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:RE_SPLIT_AUTH; 20, identifier:split; 21, argument_list; 21, 22; 22, identifier:authors_str; 23, if_clause; 23, 24; 24, identifier:x; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:res; 28, list:[]; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:current; 32, string:''; 33, for_statement; 33, 34; 33, 35; 33, 36; 34, identifier:author; 35, identifier:author_seq; 36, block; 36, 37; 36, 62; 36, 76; 36, 90; 36, 104; 37, if_statement; 37, 38; 37, 46; 38, not_operator; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:isinstance; 41, argument_list; 41, 42; 41, 43; 42, identifier:author; 43, attribute; 43, 44; 43, 45; 44, identifier:six; 45, identifier:text_type; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:author; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:six; 53, identifier:text_type; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:author; 58, identifier:decode; 59, argument_list; 59, 60; 59, 61; 60, string:'utf8'; 61, string:'ignore'; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:author; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:re; 68, identifier:sub; 69, argument_list; 69, 70; 69, 71; 69, 72; 69, 73; 70, string:r'\(|\)'; 71, string:''; 72, identifier:author; 73, attribute; 73, 74; 73, 75; 74, identifier:re; 75, identifier:U; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:author; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:re; 82, identifier:sub; 83, argument_list; 83, 84; 83, 85; 83, 86; 83, 87; 84, string:r'^[\W\d]+'; 85, string:''; 86, identifier:author; 87, attribute; 87, 88; 87, 89; 88, identifier:re; 89, identifier:U; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:author; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:re; 96, identifier:sub; 97, argument_list; 97, 98; 97, 99; 97, 100; 97, 101; 98, string:r'[^.\w]+$'; 99, string:''; 100, identifier:author; 101, attribute; 101, 102; 101, 103; 102, identifier:re; 103, identifier:U; 104, if_statement; 104, 105; 104, 111; 104, 128; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:RE_INITIALS_ONLY; 108, identifier:match; 109, argument_list; 109, 110; 110, identifier:author; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, augmented_assignment:+=; 113, 114; 113, 115; 114, identifier:current; 115, binary_operator:+; 115, 116; 115, 117; 116, string:', '; 117, call; 117, 118; 117, 125; 118, attribute; 118, 119; 118, 124; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:author; 122, identifier:strip; 123, argument_list; 124, identifier:replace; 125, argument_list; 125, 126; 125, 127; 126, string:'. '; 127, string:'.'; 128, else_clause; 128, 129; 129, block; 129, 130; 129, 140; 130, if_statement; 130, 131; 130, 132; 131, identifier:current; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:res; 137, identifier:append; 138, argument_list; 138, 139; 139, identifier:current; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:current; 143, identifier:author; 144, if_statement; 144, 145; 144, 146; 145, identifier:current; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:res; 151, identifier:append; 152, argument_list; 152, 153; 153, identifier:current; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:filters; 157, list:[ lambda a: a == 'ed', lambda a: a.startswith(','), lambda a: len(a) == 1 ]; 157, 158; 157, 164; 157, 173; 158, lambda; 158, 159; 158, 161; 159, lambda_parameters; 159, 160; 160, identifier:a; 161, comparison_operator:==; 161, 162; 161, 163; 162, identifier:a; 163, string:'ed'; 164, lambda; 164, 165; 164, 167; 165, lambda_parameters; 165, 166; 166, identifier:a; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:a; 170, identifier:startswith; 171, argument_list; 171, 172; 172, string:','; 173, lambda; 173, 174; 173, 176; 174, lambda_parameters; 174, 175; 175, identifier:a; 176, comparison_operator:==; 176, 177; 176, 181; 177, call; 177, 178; 177, 179; 178, identifier:len; 179, argument_list; 179, 180; 180, identifier:a; 181, integer:1; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:res; 185, list_comprehension; 185, 186; 185, 187; 185, 190; 186, identifier:r; 187, for_in_clause; 187, 188; 187, 189; 188, identifier:r; 189, identifier:res; 190, if_clause; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:all; 193, generator_expression; 193, 194; 193, 199; 194, not_operator; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:f; 197, argument_list; 197, 198; 198, identifier:r; 199, for_in_clause; 199, 200; 199, 201; 200, identifier:f; 201, identifier:filters; 202, return_statement; 202, 203; 203, identifier:res
def _split_refextract_authors_str(authors_str): author_seq = (x.strip() for x in RE_SPLIT_AUTH.split(authors_str) if x) res = [] current = '' for author in author_seq: if not isinstance(author, six.text_type): author = six.text_type(author.decode('utf8', 'ignore')) author = re.sub(r'\(|\)', '', author, re.U) author = re.sub(r'^[\W\d]+', '', author, re.U) author = re.sub(r'[^.\w]+$', '', author, re.U) if RE_INITIALS_ONLY.match(author): current += ', ' + author.strip().replace('. ', '.') else: if current: res.append(current) current = author if current: res.append(current) filters = [ lambda a: a == 'ed', lambda a: a.startswith(','), lambda a: len(a) == 1 ] res = [r for r in res if all(not f(r) for f in filters)] return res
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:pattern_path; 5, identifier:dict_; 6, default_parameter; 6, 7; 6, 8; 7, identifier:max_length; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:strip; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:case_sensitive; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:unique; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:deduplicate; 20, False; 21, default_parameter; 21, 22; 21, 23; 22, identifier:string_transformations; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:hyperlink; 26, False; 27, default_parameter; 27, 28; 27, 29; 28, identifier:return_multiple_columns; 29, False; 30, block; 30, 31; 30, 40; 30, 57; 30, 75; 30, 87; 30, 91; 30, 98; 30, 104; 30, 124; 31, if_statement; 31, 32; 31, 35; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:string_transformations; 34, None; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:string_transformations; 39, list:[]; 40, if_statement; 40, 41; 40, 42; 41, identifier:max_length; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:string_transformations; 47, identifier:append; 48, argument_list; 48, 49; 49, lambda; 49, 50; 49, 52; 50, lambda_parameters; 50, 51; 51, identifier:x; 52, subscript; 52, 53; 52, 54; 53, identifier:x; 54, slice; 54, 55; 54, 56; 55, colon; 56, identifier:max_length; 57, if_statement; 57, 58; 57, 59; 58, identifier:hyperlink; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:string_transformations; 64, identifier:append; 65, argument_list; 65, 66; 66, lambda; 66, 67; 66, 69; 67, lambda_parameters; 67, 68; 68, identifier:x; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:'=HYPERLINK("{0}")'; 72, identifier:format; 73, argument_list; 73, 74; 74, identifier:x; 75, if_statement; 75, 76; 75, 81; 76, call; 76, 77; 76, 78; 77, identifier:isinstance; 78, argument_list; 78, 79; 78, 80; 79, identifier:pattern_path; 80, identifier:basestring; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:pattern_path; 85, list:[pattern_path]; 85, 86; 86, identifier:pattern_path; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:original_pattern_path; 90, identifier:pattern_path; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:pattern_path; 94, subscript; 94, 95; 94, 96; 95, identifier:pattern_path; 96, slice; 96, 97; 97, colon; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:pattern_path; 102, identifier:reverse; 103, argument_list; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:result; 107, call; 107, 108; 107, 109; 108, identifier:_process_object; 109, argument_list; 109, 110; 109, 111; 109, 112; 109, 115; 109, 118; 109, 121; 110, identifier:pattern_path; 111, identifier:dict_; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:string_transformations; 114, identifier:string_transformations; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:strip; 117, identifier:strip; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:case_sensitive; 120, identifier:case_sensitive; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:return_multiple_columns; 123, identifier:return_multiple_columns; 124, if_statement; 124, 125; 124, 127; 124, 130; 124, 142; 124, 154; 125, not_operator; 125, 126; 126, identifier:result; 127, block; 127, 128; 128, return_statement; 128, 129; 129, None; 130, elif_clause; 130, 131; 130, 136; 131, call; 131, 132; 131, 133; 132, identifier:isinstance; 133, argument_list; 133, 134; 133, 135; 134, identifier:result; 135, identifier:dict; 136, block; 136, 137; 137, return_statement; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:_flatten; 140, argument_list; 140, 141; 141, identifier:result; 142, elif_clause; 142, 143; 142, 149; 143, comparison_operator:==; 143, 144; 143, 148; 144, call; 144, 145; 144, 146; 145, identifier:len; 146, argument_list; 146, 147; 147, identifier:result; 148, integer:1; 149, block; 149, 150; 150, return_statement; 150, 151; 151, subscript; 151, 152; 151, 153; 152, identifier:result; 153, integer:0; 154, else_clause; 154, 155; 155, block; 155, 156; 155, 184; 155, 211; 156, if_statement; 156, 157; 156, 158; 157, identifier:unique; 158, block; 158, 159; 158, 168; 158, 179; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:msg; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, string:"pattern_path: {0}\n\n"; 165, identifier:format; 166, argument_list; 166, 167; 167, identifier:original_pattern_path; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:msg; 171, binary_operator:+; 171, 172; 171, 173; 172, identifier:msg; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:pprint; 176, identifier:pformat; 177, argument_list; 177, 178; 178, identifier:dict_; 179, raise_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:UniqueError; 182, argument_list; 182, 183; 183, identifier:msg; 184, if_statement; 184, 185; 184, 186; 185, identifier:deduplicate; 186, block; 186, 187; 186, 191; 186, 207; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:new_result; 190, list:[]; 191, for_statement; 191, 192; 191, 193; 191, 194; 192, identifier:item; 193, identifier:result; 194, block; 194, 195; 195, if_statement; 195, 196; 195, 199; 196, comparison_operator:not; 196, 197; 196, 198; 197, identifier:item; 198, identifier:new_result; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:new_result; 204, identifier:append; 205, argument_list; 205, 206; 206, identifier:item; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:result; 210, identifier:new_result; 211, return_statement; 211, 212; 212, identifier:result
def query(pattern_path, dict_, max_length=None, strip=False, case_sensitive=False, unique=False, deduplicate=False, string_transformations=None, hyperlink=False, return_multiple_columns=False): if string_transformations is None: string_transformations = [] if max_length: string_transformations.append(lambda x: x[:max_length]) if hyperlink: string_transformations.append( lambda x: '=HYPERLINK("{0}")'.format(x)) if isinstance(pattern_path, basestring): pattern_path = [pattern_path] original_pattern_path = pattern_path pattern_path = pattern_path[:] pattern_path.reverse() result = _process_object(pattern_path, dict_, string_transformations=string_transformations, strip=strip, case_sensitive=case_sensitive, return_multiple_columns=return_multiple_columns) if not result: return None elif isinstance(result, dict): return _flatten(result) elif len(result) == 1: return result[0] else: if unique: msg = "pattern_path: {0}\n\n".format(original_pattern_path) msg = msg + pprint.pformat(dict_) raise UniqueError(msg) if deduplicate: new_result = [] for item in result: if item not in new_result: new_result.append(item) result = new_result return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:get_reactions; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:columns; 6, string:'all'; 7, default_parameter; 7, 8; 7, 9; 8, identifier:n_results; 9, integer:20; 10, default_parameter; 10, 11; 10, 12; 11, identifier:write_db; 12, False; 13, dictionary_splat_pattern; 13, 14; 14, identifier:kwargs; 15, block; 15, 16; 15, 29; 15, 33; 15, 114; 15, 118; 15, 133; 15, 154; 15, 160; 15, 165; 15, 169; 15, 382; 15, 477; 15, 482; 16, if_statement; 16, 17; 16, 22; 17, boolean_operator:or; 17, 18; 17, 19; 18, identifier:write_db; 19, comparison_operator:==; 19, 20; 19, 21; 20, identifier:columns; 21, string:'all'; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:columns; 26, subscript; 26, 27; 26, 28; 27, identifier:all_columns; 28, string:'reactions'; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:queries; 32, dictionary; 33, for_statement; 33, 34; 33, 37; 33, 42; 34, pattern_list; 34, 35; 34, 36; 35, identifier:key; 36, identifier:value; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:kwargs; 40, identifier:items; 41, argument_list; 42, block; 42, 43; 42, 50; 42, 74; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:key; 46, call; 46, 47; 46, 48; 47, identifier:map_column_names; 48, argument_list; 48, 49; 49, identifier:key; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:==; 51, 52; 51, 53; 52, identifier:key; 53, string:'distinct'; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 62; 56, comparison_operator:in; 56, 57; 56, 58; 57, identifier:value; 58, list:[True, 'True', 'true']; 58, 59; 58, 60; 58, 61; 59, True; 60, string:'True'; 61, string:'true'; 62, block; 62, 63; 62, 73; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:queries; 67, identifier:update; 68, argument_list; 68, 69; 69, dictionary; 69, 70; 70, pair; 70, 71; 70, 72; 71, identifier:key; 72, True; 73, continue_statement; 74, if_statement; 74, 75; 74, 86; 74, 97; 75, boolean_operator:or; 75, 76; 75, 81; 76, call; 76, 77; 76, 78; 77, identifier:isinstance; 78, argument_list; 78, 79; 78, 80; 79, identifier:value; 80, identifier:int; 81, call; 81, 82; 81, 83; 82, identifier:isinstance; 83, argument_list; 83, 84; 83, 85; 84, identifier:value; 85, identifier:float; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:queries; 91, identifier:update; 92, argument_list; 92, 93; 93, dictionary; 93, 94; 94, pair; 94, 95; 94, 96; 95, identifier:key; 96, identifier:value; 97, else_clause; 97, 98; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:queries; 103, identifier:update; 104, argument_list; 104, 105; 105, dictionary; 105, 106; 106, pair; 106, 107; 106, 108; 107, identifier:key; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, string:'{0}'; 111, identifier:format; 112, argument_list; 112, 113; 113, identifier:value; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:subtables; 117, list:[]; 118, if_statement; 118, 119; 118, 120; 118, 127; 119, identifier:write_db; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:subtables; 124, list:['reactionSystems', 'publication']; 124, 125; 124, 126; 125, string:'reactionSystems'; 126, string:'publication'; 127, else_clause; 127, 128; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:subtables; 132, list:[]; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:data; 136, call; 136, 137; 136, 138; 137, identifier:query; 138, argument_list; 138, 139; 138, 142; 138, 145; 138, 148; 138, 151; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:table; 141, string:'reactions'; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:subtables; 144, identifier:subtables; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:columns; 147, identifier:columns; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:n_results; 150, identifier:n_results; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:queries; 153, identifier:queries; 154, if_statement; 154, 155; 154, 157; 155, not_operator; 155, 156; 156, identifier:write_db; 157, block; 157, 158; 158, return_statement; 158, 159; 159, identifier:data; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:print; 163, argument_list; 163, 164; 164, string:'Writing result to Reactions.db'; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:unique_ids; 168, list:[]; 169, for_statement; 169, 170; 169, 171; 169, 176; 170, identifier:row; 171, subscript; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:data; 174, string:'reactions'; 175, string:'edges'; 176, block; 176, 177; 177, with_statement; 177, 178; 177, 187; 178, with_clause; 178, 179; 179, with_item; 179, 180; 180, as_pattern; 180, 181; 180, 185; 181, call; 181, 182; 181, 183; 182, identifier:CathubSQLite; 183, argument_list; 183, 184; 184, string:'Reactions.db'; 185, as_pattern_target; 185, 186; 186, identifier:db; 187, block; 187, 188; 187, 194; 187, 198; 187, 234; 187, 238; 187, 242; 187, 276; 187, 298; 187, 304; 187, 310; 187, 314; 187, 320; 187, 337; 187, 344; 187, 358; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:row; 191, subscript; 191, 192; 191, 193; 192, identifier:row; 193, string:'node'; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:key_values; 197, dictionary; 198, for_statement; 198, 199; 198, 200; 198, 203; 199, identifier:key; 200, subscript; 200, 201; 200, 202; 201, identifier:all_columns; 202, string:'reactions'; 203, block; 203, 204; 203, 210; 203, 225; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:v; 207, subscript; 207, 208; 207, 209; 208, identifier:row; 209, identifier:key; 210, try_statement; 210, 211; 210, 221; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:v; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:json; 218, identifier:loads; 219, argument_list; 219, 220; 220, identifier:v; 221, except_clause; 221, 222; 221, 223; 222, identifier:BaseException; 223, block; 223, 224; 224, pass_statement; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 233; 227, subscript; 227, 228; 227, 229; 228, identifier:key_values; 229, call; 229, 230; 229, 231; 230, identifier:convert; 231, argument_list; 231, 232; 232, identifier:key; 233, identifier:v; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:ase_ids; 237, dictionary; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:energy_corrections; 241, dictionary; 242, for_statement; 242, 243; 242, 244; 242, 247; 243, identifier:row_rs; 244, subscript; 244, 245; 244, 246; 245, identifier:row; 246, string:'reactionSystems'; 247, block; 247, 248; 247, 256; 247, 266; 248, if_statement; 248, 249; 248, 254; 249, comparison_operator:==; 249, 250; 249, 253; 250, subscript; 250, 251; 250, 252; 251, identifier:row_rs; 252, string:'name'; 253, string:'N/A'; 254, block; 254, 255; 255, continue_statement; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 263; 258, subscript; 258, 259; 258, 260; 259, identifier:ase_ids; 260, subscript; 260, 261; 260, 262; 261, identifier:row_rs; 262, string:'name'; 263, subscript; 263, 264; 263, 265; 264, identifier:row_rs; 265, string:'aseId'; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 273; 268, subscript; 268, 269; 268, 270; 269, identifier:energy_corrections; 270, subscript; 270, 271; 270, 272; 271, identifier:row_rs; 272, string:'name'; 273, subscript; 273, 274; 273, 275; 274, identifier:row_rs; 275, string:'energyCorrection'; 276, if_statement; 276, 277; 276, 279; 276, 288; 277, not_operator; 277, 278; 278, identifier:ase_ids; 279, block; 279, 280; 279, 284; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:ase_ids; 283, None; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:energy_corrections; 287, None; 288, else_clause; 288, 289; 289, block; 289, 290; 290, expression_statement; 290, 291; 291, augmented_assignment:+=; 291, 292; 291, 293; 292, identifier:unique_ids; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:ase_ids; 296, identifier:values; 297, argument_list; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 303; 300, subscript; 300, 301; 300, 302; 301, identifier:key_values; 302, string:'ase_ids'; 303, identifier:ase_ids; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 309; 306, subscript; 306, 307; 306, 308; 307, identifier:key_values; 308, string:'energy_corrections'; 309, identifier:ase_ids; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:pub_key_values; 313, dictionary; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:row_p; 317, subscript; 317, 318; 317, 319; 318, identifier:row; 319, string:'publication'; 320, for_statement; 320, 321; 320, 322; 320, 325; 321, identifier:key; 322, subscript; 322, 323; 322, 324; 323, identifier:all_columns; 324, string:'publications'; 325, block; 325, 326; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 334; 328, subscript; 328, 329; 328, 330; 329, identifier:pub_key_values; 330, call; 330, 331; 330, 332; 331, identifier:convert; 332, argument_list; 332, 333; 333, identifier:key; 334, subscript; 334, 335; 334, 336; 335, identifier:row_p; 336, identifier:key; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:db; 341, identifier:write_publication; 342, argument_list; 342, 343; 343, identifier:pub_key_values; 344, expression_statement; 344, 345; 345, assignment; 345, 346; 345, 347; 346, identifier:id; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:db; 350, identifier:check; 351, argument_list; 351, 352; 351, 355; 352, subscript; 352, 353; 352, 354; 353, identifier:key_values; 354, string:'chemical_composition'; 355, subscript; 355, 356; 355, 357; 356, identifier:key_values; 357, string:'reaction_energy'; 358, if_statement; 358, 359; 358, 362; 358, 372; 359, comparison_operator:is; 359, 360; 359, 361; 360, identifier:id; 361, None; 362, block; 362, 363; 363, expression_statement; 363, 364; 364, assignment; 364, 365; 364, 366; 365, identifier:id; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:db; 369, identifier:write; 370, argument_list; 370, 371; 371, identifier:key_values; 372, else_clause; 372, 373; 373, block; 373, 374; 374, expression_statement; 374, 375; 375, call; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:db; 378, identifier:update; 379, argument_list; 379, 380; 379, 381; 380, identifier:id; 381, identifier:key_values; 382, if_statement; 382, 383; 382, 386; 383, comparison_operator:is; 383, 384; 383, 385; 384, identifier:ase_ids; 385, None; 386, block; 386, 387; 387, with_statement; 387, 388; 387, 401; 388, with_clause; 388, 389; 389, with_item; 389, 390; 390, as_pattern; 390, 391; 390, 399; 391, call; 391, 392; 391, 397; 392, attribute; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:ase; 395, identifier:db; 396, identifier:connect; 397, argument_list; 397, 398; 398, string:'Reactions.db'; 399, as_pattern_target; 399, 400; 400, identifier:ase_db; 401, block; 401, 402; 401, 408; 401, 416; 401, 423; 401, 431; 401, 441; 401, 453; 402, expression_statement; 402, 403; 403, assignment; 403, 404; 403, 405; 404, identifier:con; 405, attribute; 405, 406; 405, 407; 406, identifier:ase_db; 407, identifier:connection; 408, expression_statement; 408, 409; 409, assignment; 409, 410; 409, 411; 410, identifier:cur; 411, call; 411, 412; 411, 415; 412, attribute; 412, 413; 412, 414; 413, identifier:con; 414, identifier:cursor; 415, argument_list; 416, expression_statement; 416, 417; 417, call; 417, 418; 417, 421; 418, attribute; 418, 419; 418, 420; 419, identifier:cur; 420, identifier:execute; 421, argument_list; 421, 422; 422, string:'SELECT unique_id from systems;'; 423, expression_statement; 423, 424; 424, assignment; 424, 425; 424, 426; 425, identifier:unique_ids0; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:cur; 429, identifier:fetchall; 430, argument_list; 431, expression_statement; 431, 432; 432, assignment; 432, 433; 432, 434; 433, identifier:unique_ids0; 434, list_comprehension; 434, 435; 434, 438; 435, subscript; 435, 436; 435, 437; 436, identifier:un; 437, integer:0; 438, for_in_clause; 438, 439; 438, 440; 439, identifier:un; 440, identifier:unique_ids0; 441, expression_statement; 441, 442; 442, assignment; 442, 443; 442, 444; 443, identifier:unique_ids; 444, list_comprehension; 444, 445; 444, 446; 444, 449; 445, identifier:un; 446, for_in_clause; 446, 447; 446, 448; 447, identifier:un; 448, identifier:unique_ids; 449, if_clause; 449, 450; 450, comparison_operator:not; 450, 451; 450, 452; 451, identifier:un; 452, identifier:unique_ids0; 453, for_statement; 453, 454; 453, 455; 453, 462; 454, identifier:unique_id; 455, call; 455, 456; 455, 457; 456, identifier:list; 457, argument_list; 457, 458; 458, call; 458, 459; 458, 460; 459, identifier:set; 460, argument_list; 460, 461; 461, identifier:unique_ids; 462, block; 462, 463; 462, 470; 463, expression_statement; 463, 464; 464, assignment; 464, 465; 464, 466; 465, identifier:atomsrow; 466, call; 466, 467; 466, 468; 467, identifier:get_atomsrow_by_id; 468, argument_list; 468, 469; 469, identifier:unique_id; 470, expression_statement; 470, 471; 471, call; 471, 472; 471, 475; 472, attribute; 472, 473; 472, 474; 473, identifier:ase_db; 474, identifier:write; 475, argument_list; 475, 476; 476, identifier:atomsrow; 477, expression_statement; 477, 478; 478, call; 478, 479; 478, 480; 479, identifier:print; 480, argument_list; 480, 481; 481, string:'Writing complete!'; 482, return_statement; 482, 483; 483, identifier:data
def get_reactions(columns='all', n_results=20, write_db=False, **kwargs): if write_db or columns == 'all': columns = all_columns['reactions'] queries = {} for key, value in kwargs.items(): key = map_column_names(key) if key == 'distinct': if value in [True, 'True', 'true']: queries.update({key: True}) continue if isinstance(value, int) or isinstance(value, float): queries.update({key: value}) else: queries.update({key: '{0}'.format(value)}) subtables = [] if write_db: subtables = ['reactionSystems', 'publication'] else: subtables = [] data = query(table='reactions', subtables=subtables, columns=columns, n_results=n_results, queries=queries) if not write_db: return data print('Writing result to Reactions.db') unique_ids = [] for row in data['reactions']['edges']: with CathubSQLite('Reactions.db') as db: row = row['node'] key_values = {} for key in all_columns['reactions']: v = row[key] try: v = json.loads(v) except BaseException: pass key_values[convert(key)] = v ase_ids = {} energy_corrections = {} for row_rs in row['reactionSystems']: if row_rs['name'] == 'N/A': continue ase_ids[row_rs['name']] = row_rs['aseId'] energy_corrections[row_rs['name']] = row_rs['energyCorrection'] if not ase_ids: ase_ids = None energy_corrections = None else: unique_ids += ase_ids.values() key_values['ase_ids'] = ase_ids key_values['energy_corrections'] = ase_ids pub_key_values = {} row_p = row['publication'] for key in all_columns['publications']: pub_key_values[convert(key)] = row_p[key] db.write_publication(pub_key_values) id = db.check(key_values['chemical_composition'], key_values['reaction_energy']) if id is None: id = db.write(key_values) else: db.update(id, key_values) if ase_ids is not None: with ase.db.connect('Reactions.db') as ase_db: con = ase_db.connection cur = con.cursor() cur.execute('SELECT unique_id from systems;') unique_ids0 = cur.fetchall() unique_ids0 = [un[0] for un in unique_ids0] unique_ids = [un for un in unique_ids if un not in unique_ids0] for unique_id in list(set(unique_ids)): atomsrow = get_atomsrow_by_id(unique_id) ase_db.write(atomsrow) print('Writing complete!') return data
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:extract_atoms; 3, parameters; 3, 4; 4, identifier:molecule; 5, block; 5, 6; 5, 13; 5, 24; 5, 28; 5, 107; 5, 156; 5, 233; 6, if_statement; 6, 7; 6, 10; 7, comparison_operator:==; 7, 8; 7, 9; 8, identifier:molecule; 9, string:''; 10, block; 10, 11; 11, return_statement; 11, 12; 12, identifier:molecule; 13, try_statement; 13, 14; 13, 20; 14, block; 14, 15; 15, return_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:float; 18, argument_list; 18, 19; 19, identifier:molecule; 20, except_clause; 20, 21; 20, 22; 21, identifier:BaseException; 22, block; 22, 23; 23, pass_statement; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:atoms; 27, string:''; 28, if_statement; 28, 29; 28, 37; 28, 97; 29, not_operator; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:molecule; 34, integer:0; 35, identifier:isalpha; 36, argument_list; 37, block; 37, 38; 37, 42; 37, 56; 37, 67; 37, 89; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:i; 41, integer:0; 42, while_statement; 42, 43; 42, 51; 43, not_operator; 43, 44; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:molecule; 48, identifier:i; 49, identifier:isalpha; 50, argument_list; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, augmented_assignment:+=; 53, 54; 53, 55; 54, identifier:i; 55, integer:1; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:prefactor; 59, call; 59, 60; 59, 61; 60, identifier:float; 61, argument_list; 61, 62; 62, subscript; 62, 63; 62, 64; 63, identifier:molecule; 64, slice; 64, 65; 64, 66; 65, colon; 66, identifier:i; 67, if_statement; 67, 68; 67, 71; 67, 83; 68, comparison_operator:<; 68, 69; 68, 70; 69, identifier:prefactor; 70, integer:0; 71, block; 71, 72; 71, 79; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:prefactor; 75, call; 75, 76; 75, 77; 76, identifier:abs; 77, argument_list; 77, 78; 78, identifier:prefactor; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:sign; 82, string:'-'; 83, else_clause; 83, 84; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:sign; 88, string:''; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:molecule; 92, subscript; 92, 93; 92, 94; 93, identifier:molecule; 94, slice; 94, 95; 94, 96; 95, identifier:i; 96, colon; 97, else_clause; 97, 98; 98, block; 98, 99; 98, 103; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:prefactor; 102, integer:1; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:sign; 106, string:''; 107, for_statement; 107, 108; 107, 109; 107, 116; 108, identifier:k; 109, call; 109, 110; 109, 111; 110, identifier:range; 111, argument_list; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:len; 114, argument_list; 114, 115; 115, identifier:molecule; 116, block; 116, 117; 117, if_statement; 117, 118; 117, 125; 117, 148; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:molecule; 122, identifier:k; 123, identifier:isdigit; 124, argument_list; 125, block; 125, 126; 126, for_statement; 126, 127; 126, 128; 126, 139; 127, identifier:j; 128, call; 128, 129; 128, 130; 129, identifier:range; 130, argument_list; 130, 131; 131, binary_operator:-; 131, 132; 131, 138; 132, call; 132, 133; 132, 134; 133, identifier:int; 134, argument_list; 134, 135; 135, subscript; 135, 136; 135, 137; 136, identifier:molecule; 137, identifier:k; 138, integer:1; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, augmented_assignment:+=; 141, 142; 141, 143; 142, identifier:atoms; 143, subscript; 143, 144; 143, 145; 144, identifier:molecule; 145, binary_operator:-; 145, 146; 145, 147; 146, identifier:k; 147, integer:1; 148, else_clause; 148, 149; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 153; 152, identifier:atoms; 153, subscript; 153, 154; 153, 155; 154, identifier:molecule; 155, identifier:k; 156, if_statement; 156, 157; 156, 162; 156, 170; 157, comparison_operator:==; 157, 158; 157, 161; 158, binary_operator:%; 158, 159; 158, 160; 159, identifier:prefactor; 160, integer:1; 161, integer:0; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, augmented_assignment:*=; 164, 165; 164, 166; 165, identifier:atoms; 166, call; 166, 167; 166, 168; 167, identifier:int; 168, argument_list; 168, 169; 169, identifier:prefactor; 170, elif_clause; 170, 171; 170, 176; 171, comparison_operator:==; 171, 172; 171, 175; 172, binary_operator:%; 172, 173; 172, 174; 173, identifier:prefactor; 174, integer:1; 175, float:0.5; 176, block; 176, 177; 176, 184; 176, 191; 176, 195; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:atoms_sort; 180, call; 180, 181; 180, 182; 181, identifier:sorted; 182, argument_list; 182, 183; 183, identifier:atoms; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:N; 187, call; 187, 188; 187, 189; 188, identifier:len; 189, argument_list; 189, 190; 190, identifier:atoms; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:atoms; 194, string:''; 195, for_statement; 195, 196; 195, 197; 195, 201; 196, identifier:n; 197, call; 197, 198; 197, 199; 198, identifier:range; 199, argument_list; 199, 200; 200, identifier:N; 201, block; 201, 202; 201, 220; 202, for_statement; 202, 203; 202, 204; 202, 213; 203, identifier:m; 204, call; 204, 205; 204, 206; 205, identifier:range; 206, argument_list; 206, 207; 207, call; 207, 208; 207, 209; 208, identifier:int; 209, argument_list; 209, 210; 210, binary_operator:-; 210, 211; 210, 212; 211, identifier:prefactor; 212, float:0.5; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, augmented_assignment:+=; 215, 216; 215, 217; 216, identifier:atoms; 217, subscript; 217, 218; 217, 219; 218, identifier:atoms_sort; 219, identifier:n; 220, if_statement; 220, 221; 220, 226; 221, comparison_operator:==; 221, 222; 221, 225; 222, binary_operator:%; 222, 223; 222, 224; 223, identifier:n; 224, integer:2; 225, integer:0; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, augmented_assignment:+=; 228, 229; 228, 230; 229, identifier:atoms; 230, subscript; 230, 231; 230, 232; 231, identifier:atoms_sort; 232, identifier:n; 233, return_statement; 233, 234; 234, binary_operator:+; 234, 235; 234, 236; 235, identifier:sign; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, string:''; 239, identifier:join; 240, argument_list; 240, 241; 241, call; 241, 242; 241, 243; 242, identifier:sorted; 243, argument_list; 243, 244; 244, identifier:atoms
def extract_atoms(molecule): if molecule == '': return molecule try: return float(molecule) except BaseException: pass atoms = '' if not molecule[0].isalpha(): i = 0 while not molecule[i].isalpha(): i += 1 prefactor = float(molecule[:i]) if prefactor < 0: prefactor = abs(prefactor) sign = '-' else: sign = '' molecule = molecule[i:] else: prefactor = 1 sign = '' for k in range(len(molecule)): if molecule[k].isdigit(): for j in range(int(molecule[k]) - 1): atoms += molecule[k - 1] else: atoms += molecule[k] if prefactor % 1 == 0: atoms *= int(prefactor) elif prefactor % 1 == 0.5: atoms_sort = sorted(atoms) N = len(atoms) atoms = '' for n in range(N): for m in range(int(prefactor - 0.5)): atoms += atoms_sort[n] if n % 2 == 0: atoms += atoms_sort[n] return sign + ''.join(sorted(atoms))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:check_reaction; 3, parameters; 3, 4; 3, 5; 4, identifier:reactants; 5, identifier:products; 6, block; 6, 7; 6, 32; 6, 57; 6, 68; 6, 79; 6, 86; 6, 93; 6, 97; 6, 101; 6, 136; 6, 160; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:reactant_list; 10, list_comprehension; 10, 11; 10, 29; 11, call; 11, 12; 11, 27; 12, attribute; 12, 13; 12, 26; 13, call; 13, 14; 13, 24; 14, attribute; 14, 15; 14, 23; 15, subscript; 15, 16; 15, 22; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:reactant; 19, identifier:split; 20, argument_list; 20, 21; 21, string:'@'; 22, integer:0; 23, identifier:strip; 24, argument_list; 24, 25; 25, string:'star'; 26, identifier:strip; 27, argument_list; 27, 28; 28, string:'gas'; 29, for_in_clause; 29, 30; 29, 31; 30, identifier:reactant; 31, identifier:reactants; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:product_list; 35, list_comprehension; 35, 36; 35, 54; 36, call; 36, 37; 36, 52; 37, attribute; 37, 38; 37, 51; 38, call; 38, 39; 38, 49; 39, attribute; 39, 40; 39, 48; 40, subscript; 40, 41; 40, 47; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:product; 44, identifier:split; 45, argument_list; 45, 46; 46, string:'@'; 47, integer:0; 48, identifier:strip; 49, argument_list; 49, 50; 50, string:'star'; 51, identifier:strip; 52, argument_list; 52, 53; 53, string:'gas'; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:product; 56, identifier:products; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:reactant_atoms; 60, list_comprehension; 60, 61; 60, 65; 61, call; 61, 62; 61, 63; 62, identifier:extract_atoms; 63, argument_list; 63, 64; 64, identifier:reactant; 65, for_in_clause; 65, 66; 65, 67; 66, identifier:reactant; 67, identifier:reactant_list; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:product_atoms; 71, list_comprehension; 71, 72; 71, 76; 72, call; 72, 73; 72, 74; 73, identifier:extract_atoms; 74, argument_list; 74, 75; 75, identifier:product; 76, for_in_clause; 76, 77; 76, 78; 77, identifier:product; 78, identifier:product_list; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:reactants; 82, call; 82, 83; 82, 84; 83, identifier:add_atoms; 84, argument_list; 84, 85; 85, identifier:reactant_atoms; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:products; 89, call; 89, 90; 89, 91; 90, identifier:add_atoms; 91, argument_list; 91, 92; 92, identifier:product_atoms; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:r_stars; 96, integer:0; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:p_stars; 100, integer:0; 101, for_statement; 101, 102; 101, 105; 101, 109; 102, pattern_list; 102, 103; 102, 104; 103, identifier:i; 104, identifier:a; 105, call; 105, 106; 105, 107; 106, identifier:enumerate; 107, argument_list; 107, 108; 108, identifier:reactant_atoms; 109, block; 109, 110; 110, if_statement; 110, 111; 110, 120; 110, 125; 111, boolean_operator:or; 111, 112; 111, 115; 112, comparison_operator:==; 112, 113; 112, 114; 113, identifier:a; 114, string:''; 115, comparison_operator:in; 115, 116; 115, 117; 116, string:'star'; 117, subscript; 117, 118; 117, 119; 118, identifier:reactant_list; 119, identifier:i; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, augmented_assignment:+=; 122, 123; 122, 124; 123, identifier:r_stars; 124, integer:1; 125, elif_clause; 125, 126; 125, 131; 126, call; 126, 127; 126, 128; 127, identifier:isinstance; 128, argument_list; 128, 129; 128, 130; 129, identifier:a; 130, identifier:float; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, augmented_assignment:+=; 133, 134; 133, 135; 134, identifier:r_stars; 135, identifier:a; 136, for_statement; 136, 137; 136, 138; 136, 139; 137, identifier:a; 138, identifier:product_atoms; 139, block; 139, 140; 140, if_statement; 140, 141; 140, 144; 140, 149; 141, comparison_operator:==; 141, 142; 141, 143; 142, identifier:a; 143, string:''; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, augmented_assignment:+=; 146, 147; 146, 148; 147, identifier:p_stars; 148, integer:1; 149, elif_clause; 149, 150; 149, 155; 150, call; 150, 151; 150, 152; 151, identifier:isinstance; 152, argument_list; 152, 153; 152, 154; 153, identifier:a; 154, identifier:float; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, augmented_assignment:+=; 157, 158; 157, 159; 158, identifier:p_stars; 159, identifier:a; 160, assert_statement; 160, 161; 161, comparison_operator:==; 161, 162; 161, 171; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, string:''; 165, identifier:join; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:sorted; 169, argument_list; 169, 170; 170, identifier:reactants; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, string:''; 174, identifier:join; 175, argument_list; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:sorted; 178, argument_list; 178, 179; 179, identifier:products
def check_reaction(reactants, products): reactant_list = [reactant.split('@')[0].strip( 'star').strip('gas') for reactant in reactants] product_list = [product.split('@')[0].strip( 'star').strip('gas') for product in products] reactant_atoms = [extract_atoms(reactant) for reactant in reactant_list] product_atoms = [extract_atoms(product) for product in product_list] reactants = add_atoms(reactant_atoms) products = add_atoms(product_atoms) r_stars = 0 p_stars = 0 for i, a in enumerate(reactant_atoms): if a == '' or 'star' in reactant_list[i]: r_stars += 1 elif isinstance(a, float): r_stars += a for a in product_atoms: if a == '': p_stars += 1 elif isinstance(a, float): p_stars += a assert ''.join(sorted(reactants)) == ''.join(sorted(products))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:fowler_array; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:fowlerdata; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ti; 7, float:0.0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ts; 10, float:0.0; 11, default_parameter; 11, 12; 11, 13; 12, identifier:gain; 13, float:1.0; 14, default_parameter; 14, 15; 14, 16; 15, identifier:ron; 16, float:1.0; 17, default_parameter; 17, 18; 17, 19; 18, identifier:badpixels; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:dtype; 22, string:'float64'; 23, default_parameter; 23, 24; 23, 25; 24, identifier:saturation; 25, integer:65631; 26, default_parameter; 26, 27; 26, 28; 27, identifier:blank; 28, integer:0; 29, default_parameter; 29, 30; 29, 31; 30, identifier:normalize; 31, False; 32, block; 32, 33; 32, 40; 32, 50; 32, 60; 32, 70; 32, 80; 32, 90; 32, 99; 32, 111; 32, 121; 32, 137; 32, 148; 32, 160; 32, 172; 32, 181; 32, 195; 32, 240; 32, 252; 32, 261; 32, 273; 32, 281; 32, 299; 33, import_statement; 33, 34; 34, aliased_import; 34, 35; 34, 39; 35, dotted_name; 35, 36; 35, 37; 35, 38; 36, identifier:numina; 37, identifier:array; 38, identifier:_nirproc; 39, identifier:_nirproc; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:<=; 41, 42; 41, 43; 42, identifier:gain; 43, integer:0; 44, block; 44, 45; 45, raise_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:ValueError; 48, argument_list; 48, 49; 49, string:"invalid parameter, gain <= 0.0"; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:<=; 51, 52; 51, 53; 52, identifier:ron; 53, integer:0; 54, block; 54, 55; 55, raise_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:ValueError; 58, argument_list; 58, 59; 59, string:"invalid parameter, ron < 0.0"; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:<; 61, 62; 61, 63; 62, identifier:ti; 63, integer:0; 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:"invalid parameter, ti < 0.0"; 70, if_statement; 70, 71; 70, 74; 71, comparison_operator:<; 71, 72; 71, 73; 72, identifier:ts; 73, integer:0; 74, block; 74, 75; 75, raise_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:ValueError; 78, argument_list; 78, 79; 79, string:"invalid parameter, ts < 0.0"; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:<=; 81, 82; 81, 83; 82, identifier:saturation; 83, integer:0; 84, block; 84, 85; 85, raise_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:ValueError; 88, argument_list; 88, 89; 89, string:"invalid parameter, saturation <= 0"; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:fowlerdata; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:numpy; 96, identifier:asarray; 97, argument_list; 97, 98; 98, identifier:fowlerdata; 99, if_statement; 99, 100; 99, 105; 100, comparison_operator:!=; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:fowlerdata; 103, identifier:ndim; 104, integer:3; 105, block; 105, 106; 106, raise_statement; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:ValueError; 109, argument_list; 109, 110; 110, string:'fowlerdata must be 3D'; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:npairs; 114, binary_operator://; 114, 115; 114, 120; 115, subscript; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:fowlerdata; 118, identifier:shape; 119, integer:0; 120, integer:2; 121, if_statement; 121, 122; 121, 131; 122, comparison_operator:!=; 122, 123; 122, 126; 123, binary_operator:*; 123, 124; 123, 125; 124, integer:2; 125, identifier:npairs; 126, subscript; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:fowlerdata; 129, identifier:shape; 130, integer:0; 131, block; 131, 132; 132, raise_statement; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:ValueError; 135, argument_list; 135, 136; 136, string:'axis-0 in fowlerdata must be even'; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:ndtype; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:fowlerdata; 144, identifier:dtype; 145, identifier:newbyteorder; 146, argument_list; 146, 147; 147, string:'='; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:fowlerdata; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:numpy; 154, identifier:asarray; 155, argument_list; 155, 156; 155, 157; 156, identifier:fowlerdata; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:dtype; 159, identifier:ndtype; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:fdtype; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:numpy; 166, identifier:result_type; 167, argument_list; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:fowlerdata; 170, identifier:dtype; 171, identifier:dtype; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:mdtype; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:numpy; 178, identifier:dtype; 179, argument_list; 179, 180; 180, string:'uint8'; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:fshape; 184, tuple; 184, 185; 184, 190; 185, subscript; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:fowlerdata; 188, identifier:shape; 189, integer:1; 190, subscript; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:fowlerdata; 193, identifier:shape; 194, integer:2; 195, if_statement; 195, 196; 195, 199; 195, 212; 196, comparison_operator:is; 196, 197; 196, 198; 197, identifier:badpixels; 198, None; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:badpixels; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:numpy; 206, identifier:zeros; 207, argument_list; 207, 208; 207, 209; 208, identifier:fshape; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:dtype; 211, identifier:mdtype; 212, else_clause; 212, 213; 213, block; 213, 214; 213, 228; 214, if_statement; 214, 215; 214, 220; 215, comparison_operator:!=; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:badpixels; 218, identifier:shape; 219, identifier:fshape; 220, block; 220, 221; 221, raise_statement; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:ValueError; 224, argument_list; 224, 225; 225, concatenated_string; 225, 226; 225, 227; 226, string:'shape of badpixels is not '; 227, string:'compatible with shape of fowlerdata'; 228, if_statement; 228, 229; 228, 234; 229, comparison_operator:!=; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:badpixels; 232, identifier:dtype; 233, identifier:mdtype; 234, block; 234, 235; 235, raise_statement; 235, 236; 236, call; 236, 237; 236, 238; 237, identifier:ValueError; 238, argument_list; 238, 239; 239, string:'dtype of badpixels must be uint8'; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:result; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:numpy; 246, identifier:empty; 247, argument_list; 247, 248; 247, 249; 248, identifier:fshape; 249, keyword_argument; 249, 250; 249, 251; 250, identifier:dtype; 251, identifier:fdtype; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:var; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:numpy; 258, identifier:empty_like; 259, argument_list; 259, 260; 260, identifier:result; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:npix; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:numpy; 267, identifier:empty; 268, argument_list; 268, 269; 268, 270; 269, identifier:fshape; 270, keyword_argument; 270, 271; 270, 272; 271, identifier:dtype; 272, identifier:mdtype; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:mask; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:badpixels; 279, identifier:copy; 280, argument_list; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:_nirproc; 285, identifier:_process_fowler_intl; 286, argument_list; 286, 287; 286, 288; 286, 289; 286, 290; 286, 291; 286, 292; 286, 293; 286, 294; 286, 295; 286, 296; 286, 297; 286, 298; 287, identifier:fowlerdata; 288, identifier:ti; 289, identifier:ts; 290, identifier:gain; 291, identifier:ron; 292, identifier:badpixels; 293, identifier:saturation; 294, identifier:blank; 295, identifier:result; 296, identifier:var; 297, identifier:npix; 298, identifier:mask; 299, return_statement; 299, 300; 300, expression_list; 300, 301; 300, 302; 300, 303; 300, 304; 301, identifier:result; 302, identifier:var; 303, identifier:npix; 304, identifier:mask
def fowler_array(fowlerdata, ti=0.0, ts=0.0, gain=1.0, ron=1.0, badpixels=None, dtype='float64', saturation=65631, blank=0, normalize=False): import numina.array._nirproc as _nirproc if gain <= 0: raise ValueError("invalid parameter, gain <= 0.0") if ron <= 0: raise ValueError("invalid parameter, ron < 0.0") if ti < 0: raise ValueError("invalid parameter, ti < 0.0") if ts < 0: raise ValueError("invalid parameter, ts < 0.0") if saturation <= 0: raise ValueError("invalid parameter, saturation <= 0") fowlerdata = numpy.asarray(fowlerdata) if fowlerdata.ndim != 3: raise ValueError('fowlerdata must be 3D') npairs = fowlerdata.shape[0] // 2 if 2 * npairs != fowlerdata.shape[0]: raise ValueError('axis-0 in fowlerdata must be even') ndtype = fowlerdata.dtype.newbyteorder('=') fowlerdata = numpy.asarray(fowlerdata, dtype=ndtype) fdtype = numpy.result_type(fowlerdata.dtype, dtype) mdtype = numpy.dtype('uint8') fshape = (fowlerdata.shape[1], fowlerdata.shape[2]) if badpixels is None: badpixels = numpy.zeros(fshape, dtype=mdtype) else: if badpixels.shape != fshape: raise ValueError('shape of badpixels is not ' 'compatible with shape of fowlerdata') if badpixels.dtype != mdtype: raise ValueError('dtype of badpixels must be uint8') result = numpy.empty(fshape, dtype=fdtype) var = numpy.empty_like(result) npix = numpy.empty(fshape, dtype=mdtype) mask = badpixels.copy() _nirproc._process_fowler_intl( fowlerdata, ti, ts, gain, ron, badpixels, saturation, blank, result, var, npix, mask ) return result, var, npix, mask
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:reactions; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:columns; 5, identifier:n_results; 6, identifier:write_db; 7, identifier:queries; 8, block; 8, 9; 8, 96; 8, 107; 8, 126; 8, 130; 8, 134; 8, 138; 8, 160; 8, 173; 9, if_statement; 9, 10; 9, 16; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:queries; 15, identifier:dict; 16, block; 16, 17; 16, 21; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:query_dict; 20, dictionary; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:q; 23, identifier:queries; 24, block; 24, 25; 24, 36; 24, 59; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, pattern_list; 27, 28; 27, 29; 28, identifier:key; 29, identifier:value; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:q; 33, identifier:split; 34, argument_list; 34, 35; 35, string:'='; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:==; 37, 38; 37, 39; 38, identifier:key; 39, string:'distinct'; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 47; 42, comparison_operator:in; 42, 43; 42, 44; 43, identifier:value; 44, list:['True', 'true']; 44, 45; 44, 46; 45, string:'True'; 46, string:'true'; 47, block; 47, 48; 47, 58; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:query_dict; 52, identifier:update; 53, argument_list; 53, 54; 54, dictionary; 54, 55; 55, pair; 55, 56; 55, 57; 56, identifier:key; 57, True; 58, continue_statement; 59, try_statement; 59, 60; 59, 78; 60, block; 60, 61; 60, 68; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:value; 64, call; 64, 65; 64, 66; 65, identifier:int; 66, argument_list; 66, 67; 67, identifier:value; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:query_dict; 72, identifier:update; 73, argument_list; 73, 74; 74, dictionary; 74, 75; 75, pair; 75, 76; 75, 77; 76, identifier:key; 77, identifier:value; 78, except_clause; 78, 79; 78, 80; 79, identifier:BaseException; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:query_dict; 85, identifier:update; 86, argument_list; 86, 87; 87, dictionary; 87, 88; 88, pair; 88, 89; 88, 90; 89, identifier:key; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, string:'{0}'; 93, identifier:format; 94, argument_list; 94, 95; 95, identifier:value; 96, if_statement; 96, 97; 96, 102; 97, boolean_operator:and; 97, 98; 97, 99; 98, identifier:write_db; 99, comparison_operator:>; 99, 100; 99, 101; 100, identifier:n_results; 101, integer:1000; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:print; 106, argument_list; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:data; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:query; 113, identifier:get_reactions; 114, argument_list; 114, 115; 114, 118; 114, 121; 114, 124; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:columns; 117, identifier:columns; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:n_results; 120, identifier:n_results; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:write_db; 123, identifier:write_db; 124, dictionary_splat; 124, 125; 125, identifier:query_dict; 126, if_statement; 126, 127; 126, 128; 127, identifier:write_db; 128, block; 128, 129; 129, return_statement; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:table; 133, list:[]; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:headers; 137, list:[]; 138, for_statement; 138, 139; 138, 140; 138, 145; 139, identifier:row; 140, subscript; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:data; 143, string:'reactions'; 144, string:'edges'; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, augmented_assignment:+=; 147, 148; 147, 149; 148, identifier:table; 149, list:[list(row['node'].values())]; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:list; 152, argument_list; 152, 153; 153, call; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:row; 157, string:'node'; 158, identifier:values; 159, argument_list; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:headers; 163, call; 163, 164; 163, 165; 164, identifier:list; 165, argument_list; 165, 166; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:row; 170, string:'node'; 171, identifier:keys; 172, argument_list; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:print; 176, argument_list; 176, 177; 177, binary_operator:+; 177, 178; 177, 183; 178, call; 178, 179; 178, 180; 179, identifier:tabulate; 180, argument_list; 180, 181; 180, 182; 181, identifier:table; 182, identifier:headers; 183, string:'\n'
def reactions(columns, n_results, write_db, queries): if not isinstance(queries, dict): query_dict = {} for q in queries: key, value = q.split('=') if key == 'distinct': if value in ['True', 'true']: query_dict.update({key: True}) continue try: value = int(value) query_dict.update({key: value}) except BaseException: query_dict.update({key: '{0}'.format(value)}) if write_db and n_results > 1000: print( ) data = query.get_reactions(columns=columns, n_results=n_results, write_db=write_db, **query_dict) if write_db: return table = [] headers = [] for row in data['reactions']['edges']: table += [list(row['node'].values())] headers = list(row['node'].keys()) print(tabulate(table, headers) + '\n')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:publications; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:columns; 5, identifier:n_results; 6, identifier:queries; 7, block; 7, 8; 7, 95; 7, 110; 7, 130; 7, 134; 7, 138; 7, 248; 7, 261; 8, if_statement; 8, 9; 8, 15; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:isinstance; 12, argument_list; 12, 13; 12, 14; 13, identifier:queries; 14, identifier:dict; 15, block; 15, 16; 15, 20; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:query_dict; 19, dictionary; 20, for_statement; 20, 21; 20, 22; 20, 23; 21, identifier:q; 22, identifier:queries; 23, block; 23, 24; 23, 35; 23, 58; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, pattern_list; 26, 27; 26, 28; 27, identifier:key; 28, identifier:value; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:q; 32, identifier:split; 33, argument_list; 33, 34; 34, string:'='; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:key; 38, string:'distinct'; 39, block; 39, 40; 40, if_statement; 40, 41; 40, 46; 41, comparison_operator:in; 41, 42; 41, 43; 42, identifier:value; 43, list:['True', 'true']; 43, 44; 43, 45; 44, string:'True'; 45, string:'true'; 46, block; 46, 47; 46, 57; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:query_dict; 51, identifier:update; 52, argument_list; 52, 53; 53, dictionary; 53, 54; 54, pair; 54, 55; 54, 56; 55, identifier:key; 56, True; 57, continue_statement; 58, try_statement; 58, 59; 58, 77; 59, block; 59, 60; 59, 67; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:value; 63, call; 63, 64; 63, 65; 64, identifier:int; 65, argument_list; 65, 66; 66, identifier:value; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:query_dict; 71, identifier:update; 72, argument_list; 72, 73; 73, dictionary; 73, 74; 74, pair; 74, 75; 74, 76; 75, identifier:key; 76, identifier:value; 77, except_clause; 77, 78; 77, 79; 78, identifier:BaseException; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:query_dict; 84, identifier:update; 85, argument_list; 85, 86; 86, dictionary; 86, 87; 87, pair; 87, 88; 87, 89; 88, identifier:key; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, string:'{0}'; 92, identifier:format; 93, argument_list; 93, 94; 94, identifier:value; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:not; 96, 97; 96, 98; 97, string:'sort'; 98, identifier:query_dict; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:query_dict; 104, identifier:update; 105, argument_list; 105, 106; 106, dictionary; 106, 107; 107, pair; 107, 108; 107, 109; 108, string:'order'; 109, string:'-year'; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:data; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:query; 116, identifier:query; 117, argument_list; 117, 118; 117, 121; 117, 124; 117, 127; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:table; 120, string:'publications'; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:columns; 123, identifier:columns; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:n_results; 126, identifier:n_results; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:queries; 129, identifier:query_dict; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:table; 133, list:[]; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:headers; 137, list:[]; 138, for_statement; 138, 139; 138, 140; 138, 145; 139, identifier:row; 140, subscript; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:data; 143, string:'publications'; 144, string:'edges'; 145, block; 145, 146; 145, 159; 145, 243; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:value; 149, call; 149, 150; 149, 151; 150, identifier:list; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:row; 156, string:'node'; 157, identifier:values; 158, argument_list; 159, for_statement; 159, 160; 159, 163; 159, 167; 160, pattern_list; 160, 161; 160, 162; 161, identifier:n; 162, identifier:v; 163, call; 163, 164; 163, 165; 164, identifier:enumerate; 165, argument_list; 165, 166; 166, identifier:value; 167, block; 167, 168; 168, if_statement; 168, 169; 168, 181; 169, boolean_operator:and; 169, 170; 169, 175; 170, call; 170, 171; 170, 172; 171, identifier:isinstance; 172, argument_list; 172, 173; 172, 174; 173, identifier:v; 174, identifier:str; 175, comparison_operator:>; 175, 176; 175, 180; 176, call; 176, 177; 176, 178; 177, identifier:len; 178, argument_list; 178, 179; 179, identifier:v; 180, integer:20; 181, block; 181, 182; 181, 191; 181, 195; 181, 199; 181, 233; 181, 237; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:splited; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:v; 188, identifier:split; 189, argument_list; 189, 190; 190, string:' '; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:size; 194, integer:0; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:sentence; 198, string:''; 199, for_statement; 199, 200; 199, 201; 199, 202; 200, identifier:word; 201, identifier:splited; 202, block; 202, 203; 203, if_statement; 203, 204; 203, 207; 203, 221; 204, comparison_operator:<; 204, 205; 204, 206; 205, identifier:size; 206, integer:20; 207, block; 207, 208; 207, 215; 208, expression_statement; 208, 209; 209, augmented_assignment:+=; 209, 210; 209, 211; 210, identifier:size; 211, call; 211, 212; 211, 213; 212, identifier:len; 213, argument_list; 213, 214; 214, identifier:word; 215, expression_statement; 215, 216; 216, augmented_assignment:+=; 216, 217; 216, 218; 217, identifier:sentence; 218, binary_operator:+; 218, 219; 218, 220; 219, string:' '; 220, identifier:word; 221, else_clause; 221, 222; 222, block; 222, 223; 222, 229; 223, expression_statement; 223, 224; 224, augmented_assignment:+=; 224, 225; 224, 226; 225, identifier:sentence; 226, binary_operator:+; 226, 227; 226, 228; 227, string:'\n'; 228, identifier:word; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:size; 232, integer:0; 233, expression_statement; 233, 234; 234, augmented_assignment:+=; 234, 235; 234, 236; 235, identifier:sentence; 236, string:'\n'; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 242; 239, subscript; 239, 240; 239, 241; 240, identifier:value; 241, identifier:n; 242, identifier:sentence; 243, expression_statement; 243, 244; 244, augmented_assignment:+=; 244, 245; 244, 246; 245, identifier:table; 246, list:[value]; 246, 247; 247, identifier:value; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:headers; 251, call; 251, 252; 251, 253; 252, identifier:list; 253, argument_list; 253, 254; 254, call; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, subscript; 256, 257; 256, 258; 257, identifier:row; 258, string:'node'; 259, identifier:keys; 260, argument_list; 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, 274; 266, call; 266, 267; 266, 268; 267, identifier:tabulate; 268, argument_list; 268, 269; 268, 270; 268, 271; 269, identifier:table; 270, identifier:headers; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:tablefmt; 273, string:"grid"; 274, string:'\n'
def publications(columns, n_results, queries): if not isinstance(queries, dict): query_dict = {} for q in queries: key, value = q.split('=') if key == 'distinct': if value in ['True', 'true']: query_dict.update({key: True}) continue try: value = int(value) query_dict.update({key: value}) except BaseException: query_dict.update({key: '{0}'.format(value)}) if 'sort' not in query_dict: query_dict.update({'order': '-year'}) data = query.query(table='publications', columns=columns, n_results=n_results, queries=query_dict) table = [] headers = [] for row in data['publications']['edges']: value = list(row['node'].values()) for n, v in enumerate(value): if isinstance(v, str) and len(v) > 20: splited = v.split(' ') size = 0 sentence = '' for word in splited: if size < 20: size += len(word) sentence += ' ' + word else: sentence += '\n' + word size = 0 sentence += '\n' value[n] = sentence table += [value] headers = list(row['node'].keys()) print(tabulate(table, headers, tablefmt="grid") + '\n')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:make_folders; 3, parameters; 3, 4; 3, 5; 4, identifier:template; 5, identifier:custom_base; 6, block; 6, 7; 6, 24; 6, 34; 6, 54; 6, 62; 6, 68; 6, 129; 6, 251; 6, 335; 6, 346; 7, function_definition; 7, 8; 7, 9; 7, 12; 8, function_name:dict_representer; 9, parameters; 9, 10; 9, 11; 10, identifier:dumper; 11, identifier:data; 12, block; 12, 13; 13, return_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:dumper; 17, identifier:represent_dict; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:data; 22, identifier:items; 23, argument_list; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:Dumper; 28, identifier:add_representer; 29, argument_list; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:collections; 32, identifier:OrderedDict; 33, identifier:dict_representer; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:custom_base; 37, None; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:custom_base; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:os; 46, identifier:path; 47, identifier:abspath; 48, argument_list; 48, 49; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:os; 52, identifier:path; 53, identifier:curdir; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:template; 57, binary_operator:+; 57, 58; 57, 61; 58, binary_operator:+; 58, 59; 58, 60; 59, identifier:custom_base; 60, string:'/'; 61, identifier:template; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:template_data; 65, attribute; 65, 66; 65, 67; 66, identifier:ase_tools; 67, identifier:REACTION_TEMPLATE; 68, if_statement; 68, 69; 68, 78; 69, not_operator; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:os; 74, identifier:path; 75, identifier:exists; 76, argument_list; 76, 77; 77, identifier:template; 78, block; 78, 79; 79, with_statement; 79, 80; 79, 90; 80, with_clause; 80, 81; 81, with_item; 81, 82; 82, as_pattern; 82, 83; 82, 88; 83, call; 83, 84; 83, 85; 84, identifier:open; 85, argument_list; 85, 86; 85, 87; 86, identifier:template; 87, string:'w'; 88, as_pattern_target; 88, 89; 89, identifier:outfile; 90, block; 90, 91; 90, 111; 90, 128; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:outfile; 95, identifier:write; 96, argument_list; 96, 97; 97, binary_operator:+; 97, 98; 97, 110; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:yaml; 101, identifier:dump; 102, argument_list; 102, 103; 102, 104; 102, 107; 103, identifier:template_data; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:indent; 106, integer:4; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:Dumper; 109, identifier:Dumper; 110, string:'\n'; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:print; 114, argument_list; 114, 115; 115, binary_operator:+; 115, 116; 115, 127; 116, binary_operator:+; 116, 117; 116, 126; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, string:"Created template file: {template}\n"; 120, identifier:format; 121, argument_list; 121, 122; 122, dictionary_splat; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:locals; 125, argument_list; 126, string:' Please edit it and run the script again to create your folderstructure.\n'; 127, string:' Run cathub make_folders --help for instructions'; 128, return_statement; 129, with_statement; 129, 130; 129, 139; 130, with_clause; 130, 131; 131, with_item; 131, 132; 132, as_pattern; 132, 133; 132, 137; 133, call; 133, 134; 133, 135; 134, identifier:open; 135, argument_list; 135, 136; 136, identifier:template; 137, as_pattern_target; 137, 138; 138, identifier:infile; 139, block; 139, 140; 139, 149; 139, 155; 139, 161; 139, 167; 139, 173; 139, 179; 139, 185; 139, 191; 139, 197; 139, 203; 139, 209; 139, 215; 139, 221; 139, 227; 139, 233; 139, 239; 139, 245; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:template_data; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:yaml; 146, identifier:load; 147, argument_list; 147, 148; 148, identifier:infile; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:title; 152, subscript; 152, 153; 152, 154; 153, identifier:template_data; 154, string:'title'; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:authors; 158, subscript; 158, 159; 158, 160; 159, identifier:template_data; 160, string:'authors'; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:journal; 164, subscript; 164, 165; 164, 166; 165, identifier:template_data; 166, string:'journal'; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:volume; 170, subscript; 170, 171; 170, 172; 171, identifier:template_data; 172, string:'volume'; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:number; 176, subscript; 176, 177; 176, 178; 177, identifier:template_data; 178, string:'number'; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:pages; 182, subscript; 182, 183; 182, 184; 183, identifier:template_data; 184, string:'pages'; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:year; 188, subscript; 188, 189; 188, 190; 189, identifier:template_data; 190, string:'year'; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:email; 194, subscript; 194, 195; 194, 196; 195, identifier:template_data; 196, string:'email'; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:publisher; 200, subscript; 200, 201; 200, 202; 201, identifier:template_data; 202, string:'publisher'; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:doi; 206, subscript; 206, 207; 206, 208; 207, identifier:template_data; 208, string:'doi'; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:dft_code; 212, subscript; 212, 213; 212, 214; 213, identifier:template_data; 214, string:'DFT_code'; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:dft_functionals; 218, subscript; 218, 219; 218, 220; 219, identifier:template_data; 220, string:'DFT_functionals'; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:reactions; 224, subscript; 224, 225; 224, 226; 225, identifier:template_data; 226, string:'reactions'; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:crystal_structures; 230, subscript; 230, 231; 230, 232; 231, identifier:template_data; 232, string:'crystal_structures'; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:bulk_compositions; 236, subscript; 236, 237; 236, 238; 237, identifier:template_data; 238, string:'bulk_compositions'; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:facets; 242, subscript; 242, 243; 242, 244; 243, identifier:template_data; 244, string:'facets'; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:energy_corrections; 248, subscript; 248, 249; 248, 250; 249, identifier:template_data; 250, string:'energy_corrections'; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:make_folders_template; 255, identifier:main; 256, argument_list; 256, 257; 256, 260; 256, 275; 256, 278; 256, 281; 256, 284; 256, 287; 256, 290; 256, 293; 256, 296; 256, 299; 256, 302; 256, 305; 256, 320; 256, 323; 256, 326; 256, 329; 256, 332; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:title; 259, identifier:title; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:authors; 262, conditional_expression:if; 262, 263; 262, 267; 262, 274; 263, call; 263, 264; 263, 265; 264, identifier:eval; 265, argument_list; 265, 266; 266, identifier:authors; 267, call; 267, 268; 267, 269; 268, identifier:isinstance; 269, argument_list; 269, 270; 269, 271; 270, identifier:authors; 271, attribute; 271, 272; 271, 273; 272, identifier:six; 273, identifier:string_types; 274, identifier:authors; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:journal; 277, identifier:journal; 278, keyword_argument; 278, 279; 278, 280; 279, identifier:volume; 280, identifier:volume; 281, keyword_argument; 281, 282; 281, 283; 282, identifier:number; 283, identifier:number; 284, keyword_argument; 284, 285; 284, 286; 285, identifier:pages; 286, identifier:pages; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:year; 289, identifier:year; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:email; 292, identifier:email; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:publisher; 295, identifier:publisher; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:doi; 298, identifier:doi; 299, keyword_argument; 299, 300; 299, 301; 300, identifier:DFT_code; 301, identifier:dft_code; 302, keyword_argument; 302, 303; 302, 304; 303, identifier:DFT_functionals; 304, identifier:dft_functionals; 305, keyword_argument; 305, 306; 305, 307; 306, identifier:reactions; 307, conditional_expression:if; 307, 308; 307, 312; 307, 319; 308, call; 308, 309; 308, 310; 309, identifier:eval; 310, argument_list; 310, 311; 311, identifier:reactions; 312, call; 312, 313; 312, 314; 313, identifier:isinstance; 314, argument_list; 314, 315; 314, 316; 315, identifier:reactions; 316, attribute; 316, 317; 316, 318; 317, identifier:six; 318, identifier:string_types; 319, identifier:reactions; 320, keyword_argument; 320, 321; 320, 322; 321, identifier:custom_base; 322, identifier:custom_base; 323, keyword_argument; 323, 324; 323, 325; 324, identifier:bulk_compositions; 325, identifier:bulk_compositions; 326, keyword_argument; 326, 327; 326, 328; 327, identifier:crystal_structures; 328, identifier:crystal_structures; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:facets; 331, identifier:facets; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:energy_corrections; 334, identifier:energy_corrections; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:pub_id; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:tools; 341, identifier:get_pub_id; 342, argument_list; 342, 343; 342, 344; 342, 345; 343, identifier:title; 344, identifier:authors; 345, identifier:year; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 349; 348, identifier:print; 349, argument_list; 349, 350; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, string:"Now dump your DFT output files into the folder, and run 'cathub folder2db {pub_id}'"; 353, identifier:format; 354, argument_list; 354, 355; 355, dictionary_splat; 355, 356; 356, call; 356, 357; 356, 358; 357, identifier:locals; 358, argument_list
def make_folders(template, custom_base): def dict_representer(dumper, data): return dumper.represent_dict(data.items()) Dumper.add_representer(collections.OrderedDict, dict_representer) if custom_base is None: custom_base = os.path.abspath(os.path.curdir) template = custom_base + '/' + template template_data = ase_tools.REACTION_TEMPLATE if not os.path.exists(template): with open(template, 'w') as outfile: outfile.write( yaml.dump( template_data, indent=4, Dumper=Dumper) + '\n') print("Created template file: {template}\n".format(**locals()) + ' Please edit it and run the script again to create your folderstructure.\n' + ' Run cathub make_folders --help for instructions') return with open(template) as infile: template_data = yaml.load(infile) title = template_data['title'] authors = template_data['authors'] journal = template_data['journal'] volume = template_data['volume'] number = template_data['number'] pages = template_data['pages'] year = template_data['year'] email = template_data['email'] publisher = template_data['publisher'] doi = template_data['doi'] dft_code = template_data['DFT_code'] dft_functionals = template_data['DFT_functionals'] reactions = template_data['reactions'] crystal_structures = template_data['crystal_structures'] bulk_compositions = template_data['bulk_compositions'] facets = template_data['facets'] energy_corrections = template_data['energy_corrections'] make_folders_template.main( title=title, authors=eval(authors) if isinstance( authors, six.string_types) else authors, journal=journal, volume=volume, number=number, pages=pages, year=year, email=email, publisher=publisher, doi=doi, DFT_code=dft_code, DFT_functionals=dft_functionals, reactions=eval(reactions) if isinstance( reactions, six.string_types) else reactions, custom_base=custom_base, bulk_compositions=bulk_compositions, crystal_structures=crystal_structures, facets=facets, energy_corrections=energy_corrections ) pub_id = tools.get_pub_id(title, authors, year) print( "Now dump your DFT output files into the folder, and run 'cathub folder2db {pub_id}'".format(**locals()))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:opensignals_hierarchy; 3, parameters; 3, 4; 3, 7; 3, 10; 4, default_parameter; 4, 5; 4, 6; 5, identifier:root; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:update; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:clone; 12, False; 13, block; 13, 14; 13, 27; 13, 38; 13, 44; 13, 62; 13, 156; 13, 162; 13, 180; 13, 210; 13, 430; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:is; 15, 16; 15, 17; 16, identifier:root; 17, None; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:root; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:os; 25, identifier:getcwd; 26, argument_list; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:categories; 30, call; 30, 31; 30, 32; 31, identifier:list; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:NOTEBOOK_KEYS; 36, identifier:keys; 37, argument_list; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:current_dir; 41, binary_operator:+; 41, 42; 41, 43; 42, identifier:root; 43, string:"\\opensignalstools_environment"; 44, if_statement; 44, 45; 44, 54; 45, not_operator; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:os; 50, identifier:path; 51, identifier:isdir; 52, argument_list; 52, 53; 53, identifier:current_dir; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:os; 59, identifier:makedirs; 60, argument_list; 60, 61; 61, identifier:current_dir; 62, for_statement; 62, 63; 62, 64; 62, 68; 63, identifier:var; 64, list:["images", "styles", "signal_samples"]; 64, 65; 64, 66; 64, 67; 65, string:"images"; 66, string:"styles"; 67, string:"signal_samples"; 68, block; 68, 69; 69, if_statement; 69, 70; 69, 83; 69, 112; 70, not_operator; 70, 71; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:os; 75, identifier:path; 76, identifier:isdir; 77, argument_list; 77, 78; 78, binary_operator:+; 78, 79; 78, 82; 79, binary_operator:+; 79, 80; 79, 81; 80, identifier:root; 81, string:"\\opensignalstools_environment\\"; 82, identifier:var; 83, block; 83, 84; 83, 96; 83, 104; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:src; 87, binary_operator:+; 87, 88; 87, 95; 88, binary_operator:+; 88, 89; 88, 94; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:os; 92, identifier:getcwd; 93, argument_list; 94, string:"\\"; 95, identifier:var; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:destination; 99, binary_operator:+; 99, 100; 99, 103; 100, binary_operator:+; 100, 101; 100, 102; 101, identifier:current_dir; 102, string:"\\"; 103, identifier:var; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:shutil; 108, identifier:copytree; 109, argument_list; 109, 110; 109, 111; 110, identifier:src; 111, identifier:destination; 112, elif_clause; 112, 113; 112, 116; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:update; 115, True; 116, block; 116, 117; 116, 128; 116, 140; 116, 148; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:shutil; 121, identifier:rmtree; 122, argument_list; 122, 123; 123, binary_operator:+; 123, 124; 123, 127; 124, binary_operator:+; 124, 125; 124, 126; 125, identifier:root; 126, string:"\\opensignalstools_environment\\"; 127, identifier:var; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:src; 131, binary_operator:+; 131, 132; 131, 139; 132, binary_operator:+; 132, 133; 132, 138; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:os; 136, identifier:getcwd; 137, argument_list; 138, string:"\\"; 139, identifier:var; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:destination; 143, binary_operator:+; 143, 144; 143, 147; 144, binary_operator:+; 144, 145; 144, 146; 145, identifier:current_dir; 146, string:"\\"; 147, identifier:var; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:shutil; 152, identifier:copytree; 153, argument_list; 153, 154; 153, 155; 154, identifier:src; 155, identifier:destination; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:current_dir; 159, binary_operator:+; 159, 160; 159, 161; 160, identifier:root; 161, string:"\\opensignalstools_environment\\Categories"; 162, if_statement; 162, 163; 162, 172; 163, not_operator; 163, 164; 164, call; 164, 165; 164, 170; 165, attribute; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:os; 168, identifier:path; 169, identifier:isdir; 170, argument_list; 170, 171; 171, identifier:current_dir; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:os; 177, identifier:makedirs; 178, argument_list; 178, 179; 179, identifier:current_dir; 180, for_statement; 180, 181; 180, 182; 180, 183; 181, identifier:category; 182, identifier:categories; 183, block; 183, 184; 184, if_statement; 184, 185; 184, 198; 185, not_operator; 185, 186; 186, call; 186, 187; 186, 192; 187, attribute; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:os; 190, identifier:path; 191, identifier:isdir; 192, argument_list; 192, 193; 193, binary_operator:+; 193, 194; 193, 197; 194, binary_operator:+; 194, 195; 194, 196; 195, identifier:current_dir; 196, string:"\\"; 197, identifier:category; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:os; 203, identifier:makedirs; 204, argument_list; 204, 205; 205, binary_operator:+; 205, 206; 205, 209; 206, binary_operator:+; 206, 207; 206, 208; 207, identifier:current_dir; 208, string:"\\"; 209, identifier:category; 210, if_statement; 210, 211; 210, 214; 211, comparison_operator:is; 211, 212; 211, 213; 212, identifier:clone; 213, True; 214, block; 214, 215; 214, 221; 214, 230; 214, 314; 214, 321; 214, 334; 214, 345; 214, 358; 214, 369; 214, 382; 214, 393; 214, 406; 214, 417; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:dir_path; 218, binary_operator:+; 218, 219; 218, 220; 219, identifier:root; 220, string:"\\notebook_code"; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:list_of_code_dirs; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:os; 227, identifier:listdir; 228, argument_list; 228, 229; 229, identifier:dir_path; 230, for_statement; 230, 231; 230, 232; 230, 233; 231, identifier:folder; 232, identifier:list_of_code_dirs; 233, block; 233, 234; 233, 242; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:folder_path; 237, binary_operator:+; 237, 238; 237, 241; 238, binary_operator:+; 238, 239; 238, 240; 239, identifier:root; 240, string:"\\notebook_code\\"; 241, identifier:folder; 242, if_statement; 242, 243; 242, 250; 243, boolean_operator:and; 243, 244; 243, 247; 244, comparison_operator:!=; 244, 245; 244, 246; 245, identifier:folder; 246, string:"MainFiles"; 247, comparison_operator:!=; 247, 248; 247, 249; 248, identifier:folder; 249, string:"__pycache__"; 250, block; 250, 251; 250, 260; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:list_of_code_files; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:os; 257, identifier:listdir; 258, argument_list; 258, 259; 259, identifier:folder_path; 260, for_statement; 260, 261; 260, 262; 260, 263; 261, identifier:file; 262, identifier:list_of_code_files; 263, block; 263, 264; 264, if_statement; 264, 265; 264, 268; 265, comparison_operator:!=; 265, 266; 265, 267; 266, identifier:file; 267, string:"__pycache__"; 268, block; 268, 269; 268, 285; 268, 296; 268, 305; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:spec; 272, call; 272, 273; 272, 278; 273, attribute; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:importlib; 276, identifier:util; 277, identifier:spec_from_file_location; 278, argument_list; 278, 279; 278, 280; 279, identifier:file; 280, binary_operator:+; 280, 281; 280, 284; 281, binary_operator:+; 281, 282; 281, 283; 282, identifier:folder_path; 283, string:"\\"; 284, identifier:file; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:foo; 288, call; 288, 289; 288, 294; 289, attribute; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:importlib; 292, identifier:util; 293, identifier:module_from_spec; 294, argument_list; 294, 295; 295, identifier:spec; 296, expression_statement; 296, 297; 297, call; 297, 298; 297, 303; 298, attribute; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:spec; 301, identifier:loader; 302, identifier:exec_module; 303, argument_list; 303, 304; 304, identifier:foo; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:foo; 309, identifier:run; 310, argument_list; 310, 311; 311, binary_operator:+; 311, 312; 311, 313; 312, identifier:root; 313, string:"\\opensignalstools_environment"; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:main_page; 317, call; 317, 318; 317, 319; 318, identifier:notebook; 319, argument_list; 319, 320; 320, string:"Main_Files_By_Category"; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:main_page; 325, identifier:write_to_file; 326, argument_list; 326, 327; 326, 330; 326, 331; 327, binary_operator:+; 327, 328; 327, 329; 328, identifier:root; 329, string:"\\opensignalstools_environment"; 330, string:"opensignalstools"; 331, keyword_argument; 331, 332; 331, 333; 332, identifier:footer; 333, False; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 337; 336, identifier:by_difficulty; 337, call; 337, 338; 337, 339; 338, identifier:notebook; 339, argument_list; 339, 340; 339, 341; 339, 342; 340, string:"Main_Files_By_Difficulty"; 341, string:"Notebooks Grouped by Difficulty"; 342, keyword_argument; 342, 343; 342, 344; 343, identifier:notebook_description; 344, identifier:DESCRIPTION_GROUP_BY; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:by_difficulty; 349, identifier:write_to_file; 350, argument_list; 350, 351; 350, 354; 350, 355; 351, binary_operator:+; 351, 352; 351, 353; 352, identifier:root; 353, string:"\\opensignalstools_environment"; 354, string:"by_diff"; 355, keyword_argument; 355, 356; 355, 357; 356, identifier:footer; 357, False; 358, expression_statement; 358, 359; 359, assignment; 359, 360; 359, 361; 360, identifier:by_tags; 361, call; 361, 362; 361, 363; 362, identifier:notebook; 363, argument_list; 363, 364; 363, 365; 363, 366; 364, string:"Main_Files_By_Tag"; 365, string:"Notebooks Grouped by Tag Values"; 366, keyword_argument; 366, 367; 366, 368; 367, identifier:notebook_description; 368, identifier:DESCRIPTION_GROUP_BY; 369, expression_statement; 369, 370; 370, call; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:by_tags; 373, identifier:write_to_file; 374, argument_list; 374, 375; 374, 378; 374, 379; 375, binary_operator:+; 375, 376; 375, 377; 376, identifier:root; 377, string:"\\opensignalstools_environment"; 378, string:"by_tag"; 379, keyword_argument; 379, 380; 379, 381; 380, identifier:footer; 381, False; 382, expression_statement; 382, 383; 383, assignment; 383, 384; 383, 385; 384, identifier:by_signal_type; 385, call; 385, 386; 385, 387; 386, identifier:notebook; 387, argument_list; 387, 388; 387, 389; 387, 390; 388, string:"Main_Files_By_Signal_Type"; 389, string:"Notebooks Grouped by Signal Type"; 390, keyword_argument; 390, 391; 390, 392; 391, identifier:notebook_description; 392, identifier:DESCRIPTION_GROUP_BY; 393, expression_statement; 393, 394; 394, call; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:by_signal_type; 397, identifier:write_to_file; 398, argument_list; 398, 399; 398, 402; 398, 403; 399, binary_operator:+; 399, 400; 399, 401; 400, identifier:root; 401, string:"\\opensignalstools_environment"; 402, string:"by_signal_type"; 403, keyword_argument; 403, 404; 403, 405; 404, identifier:footer; 405, False; 406, expression_statement; 406, 407; 407, assignment; 407, 408; 407, 409; 408, identifier:signal_samples; 409, call; 409, 410; 409, 411; 410, identifier:notebook; 411, argument_list; 411, 412; 411, 413; 411, 414; 412, string:"Main_Files_Signal_Samples"; 413, string:"Signal Samples Library"; 414, keyword_argument; 414, 415; 414, 416; 415, identifier:notebook_description; 416, identifier:DESCRIPTION_SIGNAL_SAMPLES; 417, expression_statement; 417, 418; 418, call; 418, 419; 418, 422; 419, attribute; 419, 420; 419, 421; 420, identifier:signal_samples; 421, identifier:write_to_file; 422, argument_list; 422, 423; 422, 426; 422, 427; 423, binary_operator:+; 423, 424; 423, 425; 424, identifier:root; 425, string:"\\opensignalstools_environment"; 426, string:"signal_samples"; 427, keyword_argument; 427, 428; 427, 429; 428, identifier:footer; 429, False; 430, return_statement; 430, 431; 431, binary_operator:+; 431, 432; 431, 433; 432, identifier:root; 433, string:"\\opensignalstools_environment"
def opensignals_hierarchy(root=None, update=False, clone=False): if root is None: root = os.getcwd() categories = list(NOTEBOOK_KEYS.keys()) current_dir = root + "\\opensignalstools_environment" if not os.path.isdir(current_dir): os.makedirs(current_dir) for var in ["images", "styles", "signal_samples"]: if not os.path.isdir(root + "\\opensignalstools_environment\\" + var): src = os.getcwd() + "\\" + var destination = current_dir + "\\" + var shutil.copytree(src, destination) elif update is True: shutil.rmtree(root + "\\opensignalstools_environment\\" + var) src = os.getcwd() + "\\" + var destination = current_dir + "\\" + var shutil.copytree(src, destination) current_dir = root + "\\opensignalstools_environment\\Categories" if not os.path.isdir(current_dir): os.makedirs(current_dir) for category in categories: if not os.path.isdir(current_dir + "\\" + category): os.makedirs(current_dir + "\\" + category) if clone is True: dir_path = root + "\\notebook_code" list_of_code_dirs = os.listdir(dir_path) for folder in list_of_code_dirs: folder_path = root + "\\notebook_code\\" + folder if folder != "MainFiles" and folder != "__pycache__": list_of_code_files = os.listdir(folder_path) for file in list_of_code_files: if file != "__pycache__": spec = importlib.util.spec_from_file_location(file, folder_path + "\\" + file) foo = importlib.util.module_from_spec(spec) spec.loader.exec_module(foo) foo.run(root + "\\opensignalstools_environment") main_page = notebook("Main_Files_By_Category") main_page.write_to_file(root + "\\opensignalstools_environment", "opensignalstools", footer=False) by_difficulty = notebook("Main_Files_By_Difficulty", "Notebooks Grouped by Difficulty", notebook_description=DESCRIPTION_GROUP_BY) by_difficulty.write_to_file(root + "\\opensignalstools_environment", "by_diff", footer=False) by_tags = notebook("Main_Files_By_Tag", "Notebooks Grouped by Tag Values", notebook_description=DESCRIPTION_GROUP_BY) by_tags.write_to_file(root + "\\opensignalstools_environment", "by_tag", footer=False) by_signal_type = notebook("Main_Files_By_Signal_Type", "Notebooks Grouped by Signal Type", notebook_description=DESCRIPTION_GROUP_BY) by_signal_type.write_to_file(root + "\\opensignalstools_environment", "by_signal_type", footer=False) signal_samples = notebook("Main_Files_Signal_Samples", "Signal Samples Library", notebook_description=DESCRIPTION_SIGNAL_SAMPLES) signal_samples.write_to_file(root + "\\opensignalstools_environment", "signal_samples", footer=False) return root + "\\opensignalstools_environment"
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_generate_notebook_by_tag_body; 3, parameters; 3, 4; 3, 5; 4, identifier:notebook_object; 5, identifier:dict_by_tag; 6, block; 6, 7; 6, 18; 6, 24; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:tag_keys; 10, call; 10, 11; 10, 12; 11, identifier:list; 12, argument_list; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:dict_by_tag; 16, identifier:keys; 17, argument_list; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:tag_keys; 22, identifier:sort; 23, argument_list; 24, for_statement; 24, 25; 24, 26; 24, 27; 25, identifier:tag; 26, identifier:tag_keys; 27, block; 27, 28; 28, if_statement; 28, 29; 28, 36; 29, comparison_operator:not; 29, 30; 29, 35; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:tag; 33, identifier:lower; 34, argument_list; 35, identifier:SIGNAL_TYPE_LIST; 36, block; 36, 37; 36, 43; 36, 53; 36, 154; 36, 158; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:markdown_cell; 40, attribute; 40, 41; 40, 42; 41, identifier:group_tag_code; 42, identifier:TAG_TABLE_HEADER; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:markdown_cell; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:markdown_cell; 49, identifier:replace; 50, argument_list; 50, 51; 50, 52; 51, string:"Tag i"; 52, identifier:tag; 53, for_statement; 53, 54; 53, 55; 53, 58; 54, identifier:notebook_file; 55, subscript; 55, 56; 55, 57; 56, identifier:dict_by_tag; 57, identifier:tag; 58, block; 58, 59; 58, 68; 58, 75; 58, 89; 58, 103; 58, 127; 58, 136; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:split_path; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:notebook_file; 65, identifier:split; 66, argument_list; 66, 67; 67, string:"\\"; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:notebook_type; 71, subscript; 71, 72; 71, 73; 72, identifier:split_path; 73, unary_operator:-; 73, 74; 74, integer:2; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:notebook_name; 78, subscript; 78, 79; 78, 88; 79, call; 79, 80; 79, 86; 80, attribute; 80, 81; 80, 85; 81, subscript; 81, 82; 81, 83; 82, identifier:split_path; 83, unary_operator:-; 83, 84; 84, integer:1; 85, identifier:split; 86, argument_list; 86, 87; 87, string:"&"; 88, integer:0; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:notebook_title; 92, subscript; 92, 93; 92, 102; 93, call; 93, 94; 93, 100; 94, attribute; 94, 95; 94, 99; 95, subscript; 95, 96; 95, 97; 96, identifier:split_path; 97, unary_operator:-; 97, 98; 98, integer:1; 99, identifier:split; 100, argument_list; 100, 101; 101, string:"&"; 102, integer:1; 103, expression_statement; 103, 104; 104, augmented_assignment:+=; 104, 105; 104, 106; 105, identifier:markdown_cell; 106, binary_operator:+; 106, 107; 106, 126; 107, binary_operator:+; 107, 108; 107, 121; 108, binary_operator:+; 108, 109; 108, 118; 109, binary_operator:+; 109, 110; 109, 111; 109, 112; 110, string:"\t<tr>\n\t\t<td width='20%' class='header_image_color_"; 111, line_continuation:\; 112, call; 112, 113; 112, 114; 113, identifier:str; 114, argument_list; 114, 115; 115, subscript; 115, 116; 115, 117; 116, identifier:NOTEBOOK_KEYS; 117, identifier:notebook_type; 118, concatenated_string; 118, 119; 118, 120; 119, string:"'><img "; 120, string:"src='../../images/icons/"; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:notebook_type; 124, identifier:title; 125, argument_list; 126, string:".png' width='15%'>\n\t\t</td>"; 127, expression_statement; 127, 128; 128, augmented_assignment:+=; 128, 129; 128, 130; 129, identifier:markdown_cell; 130, binary_operator:+; 130, 131; 130, 135; 131, binary_operator:+; 131, 132; 131, 133; 131, 134; 132, string:"\n\t\t<td width='60%' class='center_cell open_cell_light'>"; 133, line_continuation:\; 134, identifier:notebook_title; 135, string:"\n\t\t</td>"; 136, expression_statement; 136, 137; 137, augmented_assignment:+=; 137, 138; 137, 139; 138, identifier:markdown_cell; 139, binary_operator:+; 139, 140; 139, 153; 140, binary_operator:+; 140, 141; 140, 152; 141, binary_operator:+; 141, 142; 141, 151; 142, binary_operator:+; 142, 143; 142, 146; 143, concatenated_string; 143, 144; 143, 145; 144, string:"\n\t\t<td width='20%' class='center_cell'>\n\t\t\t<a href='"; 145, string:"../"; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:notebook_type; 149, identifier:title; 150, argument_list; 151, string:"/"; 152, identifier:notebook_name; 153, string:"'><div class='file_icon'></div></a>\n\t\t</td>\n\t</tr>"; 154, expression_statement; 154, 155; 155, augmented_assignment:+=; 155, 156; 155, 157; 156, identifier:markdown_cell; 157, string:"</table>"; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 165; 160, attribute; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:notebook_object; 163, string:"cells"; 164, identifier:append; 165, argument_list; 165, 166; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:nb; 170, identifier:v4; 171, identifier:new_markdown_cell; 172, argument_list; 172, 173; 173, identifier:markdown_cell
def _generate_notebook_by_tag_body(notebook_object, dict_by_tag): tag_keys = list(dict_by_tag.keys()) tag_keys.sort() for tag in tag_keys: if tag.lower() not in SIGNAL_TYPE_LIST: markdown_cell = group_tag_code.TAG_TABLE_HEADER markdown_cell = markdown_cell.replace("Tag i", tag) for notebook_file in dict_by_tag[tag]: split_path = notebook_file.split("\\") notebook_type = split_path[-2] notebook_name = split_path[-1].split("&")[0] notebook_title = split_path[-1].split("&")[1] markdown_cell += "\t<tr>\n\t\t<td width='20%' class='header_image_color_" + \ str(NOTEBOOK_KEYS[notebook_type]) + "'><img " \ "src='../../images/icons/" + notebook_type.title() +\ ".png' width='15%'>\n\t\t</td>" markdown_cell += "\n\t\t<td width='60%' class='center_cell open_cell_light'>" + \ notebook_title + "\n\t\t</td>" markdown_cell += "\n\t\t<td width='20%' class='center_cell'>\n\t\t\t<a href='" \ "../" + notebook_type.title() + "/" + notebook_name + \ "'><div class='file_icon'></div></a>\n\t\t</td>\n\t</tr>" markdown_cell += "</table>" notebook_object["cells"].append(nb.v4.new_markdown_cell(markdown_cell))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_preprocess_params; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:kwargs; 6, block; 6, 7; 6, 248; 7, for_statement; 7, 8; 7, 11; 7, 16; 8, pattern_list; 8, 9; 8, 10; 9, identifier:attr; 10, identifier:val; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:kwargs; 14, identifier:items; 15, argument_list; 16, block; 16, 17; 16, 34; 16, 46; 17, if_statement; 17, 18; 17, 28; 18, boolean_operator:and; 18, 19; 18, 25; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:cls; 22, identifier:is_the_primary_key; 23, argument_list; 23, 24; 24, identifier:attr; 25, attribute; 25, 26; 25, 27; 26, identifier:cls; 27, identifier:_prevent_primary_key_initialization_; 28, block; 28, 29; 28, 33; 29, delete_statement; 29, 30; 30, subscript; 30, 31; 30, 32; 31, identifier:kwargs; 32, identifier:attr; 33, continue_statement; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:==; 35, 36; 35, 37; 36, identifier:val; 37, string:""; 38, block; 38, 39; 38, 45; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:kwargs; 43, identifier:attr; 44, None; 45, continue_statement; 46, if_statement; 46, 47; 46, 61; 47, boolean_operator:and; 47, 48; 47, 56; 48, comparison_operator:in; 48, 49; 48, 50; 49, identifier:attr; 50, attribute; 50, 51; 50, 55; 51, call; 51, 52; 51, 53; 52, identifier:class_mapper; 53, argument_list; 53, 54; 54, identifier:cls; 55, identifier:relationships; 56, comparison_operator:not; 56, 57; 56, 58; 57, identifier:attr; 58, attribute; 58, 59; 58, 60; 59, identifier:cls; 60, identifier:_no_overwrite_; 61, block; 61, 62; 61, 73; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:rel; 65, subscript; 65, 66; 65, 72; 66, attribute; 66, 67; 66, 71; 67, call; 67, 68; 67, 69; 68, identifier:class_mapper; 69, argument_list; 69, 70; 70, identifier:cls; 71, identifier:relationships; 72, identifier:attr; 73, if_statement; 73, 74; 73, 77; 73, 208; 74, attribute; 74, 75; 74, 76; 75, identifier:rel; 76, identifier:uselist; 77, block; 77, 78; 78, if_statement; 78, 79; 78, 84; 78, 128; 79, call; 79, 80; 79, 81; 80, identifier:isinstance; 81, argument_list; 81, 82; 81, 83; 82, identifier:val; 83, identifier:list; 84, block; 84, 85; 85, if_statement; 85, 86; 85, 97; 86, call; 86, 87; 86, 88; 87, identifier:all; 88, generator_expression; 88, 89; 88, 94; 89, call; 89, 90; 89, 91; 90, identifier:isinstance; 91, argument_list; 91, 92; 91, 93; 92, identifier:v; 93, identifier:dict; 94, for_in_clause; 94, 95; 94, 96; 95, identifier:v; 96, identifier:val; 97, block; 97, 98; 97, 107; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:rel_cls; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:cls; 104, identifier:mapped_rel_class; 105, argument_list; 105, 106; 106, identifier:attr; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:kwargs; 111, identifier:attr; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:rel_cls; 115, identifier:update_or_new_all; 116, argument_list; 116, 117; 116, 120; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:list_of_kwargs; 119, identifier:val; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:keys; 122, list:[rel_cls.primary_key_name()]; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:rel_cls; 126, identifier:primary_key_name; 127, argument_list; 128, elif_clause; 128, 129; 128, 134; 129, call; 129, 130; 129, 131; 130, identifier:isinstance; 131, argument_list; 131, 132; 131, 133; 132, identifier:val; 133, identifier:dict; 134, block; 134, 135; 134, 144; 134, 156; 134, 177; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:rel_cls; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:cls; 141, identifier:mapped_rel_class; 142, argument_list; 142, 143; 143, identifier:attr; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:mapping_col; 147, attribute; 147, 148; 147, 155; 148, attribute; 148, 149; 148, 154; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:rel; 152, identifier:collection_class; 153, argument_list; 154, identifier:keyfunc; 155, identifier:name; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:list_of_kwargs; 159, list_comprehension; 159, 160; 159, 168; 160, call; 160, 161; 160, 162; 161, identifier:merge; 162, argument_list; 162, 163; 162, 164; 163, identifier:v; 164, dictionary; 164, 165; 165, pair; 165, 166; 165, 167; 166, identifier:mapping_col; 167, identifier:k; 168, for_in_clause; 168, 169; 168, 172; 169, pattern_list; 169, 170; 169, 171; 170, identifier:k; 171, identifier:v; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:val; 175, identifier:items; 176, argument_list; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:kwargs; 181, identifier:attr; 182, dictionary_comprehension; 182, 183; 182, 190; 183, pair; 183, 184; 183, 189; 184, call; 184, 185; 184, 186; 185, identifier:getattr; 186, argument_list; 186, 187; 186, 188; 187, identifier:obj; 188, identifier:mapping_col; 189, identifier:obj; 190, for_in_clause; 190, 191; 190, 192; 191, identifier:obj; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:rel_cls; 195, identifier:update_or_new_all; 196, argument_list; 196, 197; 196, 200; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:list_of_kwargs; 199, identifier:list_of_kwargs; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:keys; 202, list:[rel_cls.primary_key_name()]; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:rel_cls; 206, identifier:primary_key_name; 207, argument_list; 208, elif_clause; 208, 209; 208, 214; 209, call; 209, 210; 209, 211; 210, identifier:isinstance; 211, argument_list; 211, 212; 211, 213; 212, identifier:val; 213, identifier:dict; 214, block; 214, 215; 214, 224; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:rel_cls; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:cls; 221, identifier:mapped_rel_class; 222, argument_list; 222, 223; 223, identifier:attr; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:kwargs; 228, identifier:attr; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:rel_cls; 232, identifier:update_or_new; 233, argument_list; 233, 234; 234, dictionary_splat; 234, 235; 235, call; 235, 236; 235, 237; 236, identifier:merge; 237, argument_list; 237, 238; 237, 239; 238, identifier:val; 239, dictionary; 239, 240; 240, pair; 240, 241; 240, 242; 241, string:'keys'; 242, list:[rel_cls.primary_key_name()]; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:rel_cls; 246, identifier:primary_key_name; 247, argument_list; 248, return_statement; 248, 249; 249, identifier:kwargs
def _preprocess_params(cls, kwargs): for attr, val in kwargs.items(): if cls.is_the_primary_key(attr) and cls._prevent_primary_key_initialization_: del kwargs[attr] continue if val == "": kwargs[attr] = None continue if attr in class_mapper(cls).relationships and attr not in cls._no_overwrite_: rel = class_mapper(cls).relationships[attr] if rel.uselist: if isinstance(val, list): if all(isinstance(v, dict) for v in val): rel_cls = cls.mapped_rel_class(attr) kwargs[attr] = rel_cls.update_or_new_all( list_of_kwargs=val, keys=[rel_cls.primary_key_name()]) elif isinstance(val, dict): rel_cls = cls.mapped_rel_class(attr) mapping_col = rel.collection_class().keyfunc.name list_of_kwargs = [merge(v, {mapping_col: k}) for k, v in val.items()] kwargs[attr] = {getattr(obj, mapping_col): obj for obj in rel_cls.update_or_new_all( list_of_kwargs=list_of_kwargs, keys=[rel_cls.primary_key_name()])} elif isinstance(val, dict): rel_cls = cls.mapped_rel_class(attr) kwargs[attr] = rel_cls.update_or_new( **merge(val, {'keys': [rel_cls.primary_key_name()]})) return kwargs
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:add_all; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:cls; 5, identifier:models; 6, default_parameter; 6, 7; 6, 8; 7, identifier:commit; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:check_type; 11, False; 12, block; 12, 13; 12, 37; 12, 70; 13, if_statement; 13, 14; 13, 15; 14, identifier:check_type; 15, block; 15, 16; 16, for_statement; 16, 17; 16, 18; 16, 19; 17, identifier:model; 18, identifier:models; 19, block; 19, 20; 20, if_statement; 20, 21; 20, 27; 21, not_operator; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:isinstance; 24, argument_list; 24, 25; 24, 26; 25, identifier:model; 26, identifier:cls; 27, block; 27, 28; 28, raise_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:ValueError; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 34; 33, string:'%s is not of type %s'; 34, argument_list; 34, 35; 34, 36; 35, identifier:model; 36, identifier:cls; 37, if_statement; 37, 38; 37, 41; 37, 59; 38, comparison_operator:in; 38, 39; 38, 40; 39, None; 40, identifier:models; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:cls; 47, identifier:session; 48, identifier:add_all; 49, argument_list; 49, 50; 50, list_comprehension; 50, 51; 50, 52; 50, 55; 51, identifier:m; 52, for_in_clause; 52, 53; 52, 54; 53, identifier:m; 54, identifier:models; 55, if_clause; 55, 56; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:m; 58, None; 59, else_clause; 59, 60; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:cls; 66, identifier:session; 67, identifier:add_all; 68, argument_list; 68, 69; 69, identifier:models; 70, try_statement; 70, 71; 70, 85; 71, block; 71, 72; 71, 83; 72, if_statement; 72, 73; 72, 74; 73, identifier:commit; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:cls; 80, identifier:session; 81, identifier:commit; 82, argument_list; 83, return_statement; 83, 84; 84, identifier:models; 85, except_clause; 85, 86; 86, block; 86, 87; 86, 95; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:cls; 92, identifier:session; 93, identifier:rollback; 94, argument_list; 95, raise_statement
def add_all(cls, models, commit=True, check_type=False): if check_type: for model in models: if not isinstance(model, cls): raise ValueError('%s is not of type %s' (model, cls)) if None in models: cls.session.add_all([m for m in models if m is not None]) else: cls.session.add_all(models) try: if commit: cls.session.commit() return models except: cls.session.rollback() raise
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:peakdelta; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:v; 5, identifier:delta; 6, default_parameter; 6, 7; 6, 8; 7, identifier:x; 8, None; 9, block; 9, 10; 9, 14; 9, 18; 9, 33; 9, 40; 9, 58; 9, 72; 9, 84; 9, 93; 9, 101; 9, 105; 9, 216; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:maxtab; 13, list:[]; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:mintab; 17, list:[]; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:x; 21, None; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:x; 26, call; 26, 27; 26, 28; 27, identifier:arange; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, identifier:v; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:v; 36, call; 36, 37; 36, 38; 37, identifier:asarray; 38, argument_list; 38, 39; 39, identifier:v; 40, if_statement; 40, 41; 40, 50; 41, comparison_operator:!=; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:v; 46, call; 46, 47; 46, 48; 47, identifier:len; 48, argument_list; 48, 49; 49, identifier:x; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:sys; 55, identifier:exit; 56, argument_list; 56, 57; 57, string:'Input vectors v and x must have same length'; 58, if_statement; 58, 59; 58, 64; 59, not_operator; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:isscalar; 62, argument_list; 62, 63; 63, identifier:delta; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:sys; 69, identifier:exit; 70, argument_list; 70, 71; 71, string:'Input argument delta must be a scalar'; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:<=; 73, 74; 73, 75; 74, identifier:delta; 75, integer:0; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:sys; 81, identifier:exit; 82, argument_list; 82, 83; 83, string:'Input argument delta must be positive'; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, pattern_list; 86, 87; 86, 88; 87, identifier:mn; 88, identifier:mx; 89, expression_list; 89, 90; 89, 91; 90, identifier:Inf; 91, unary_operator:-; 91, 92; 92, identifier:Inf; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, pattern_list; 95, 96; 95, 97; 96, identifier:mnpos; 97, identifier:mxpos; 98, expression_list; 98, 99; 98, 100; 99, identifier:NaN; 100, identifier:NaN; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:lookformax; 104, True; 105, for_statement; 105, 106; 105, 107; 105, 114; 106, identifier:i; 107, call; 107, 108; 107, 109; 108, identifier:arange; 109, argument_list; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:len; 112, argument_list; 112, 113; 113, identifier:v; 114, block; 114, 115; 114, 121; 114, 136; 114, 151; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:this; 118, subscript; 118, 119; 118, 120; 119, identifier:v; 120, identifier:i; 121, if_statement; 121, 122; 121, 125; 122, comparison_operator:>; 122, 123; 122, 124; 123, identifier:this; 124, identifier:mx; 125, block; 125, 126; 125, 130; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:mx; 129, identifier:this; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:mxpos; 133, subscript; 133, 134; 133, 135; 134, identifier:x; 135, identifier:i; 136, if_statement; 136, 137; 136, 140; 137, comparison_operator:<; 137, 138; 137, 139; 138, identifier:this; 139, identifier:mn; 140, block; 140, 141; 140, 145; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:mn; 144, identifier:this; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:mnpos; 148, subscript; 148, 149; 148, 150; 149, identifier:x; 150, identifier:i; 151, if_statement; 151, 152; 151, 153; 151, 184; 152, identifier:lookformax; 153, block; 153, 154; 154, if_statement; 154, 155; 154, 160; 155, comparison_operator:<; 155, 156; 155, 157; 156, identifier:this; 157, binary_operator:-; 157, 158; 157, 159; 158, identifier:mx; 159, identifier:delta; 160, block; 160, 161; 160, 170; 160, 174; 160, 180; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:maxtab; 165, identifier:append; 166, argument_list; 166, 167; 167, tuple; 167, 168; 167, 169; 168, identifier:mxpos; 169, identifier:mx; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:mn; 173, identifier:this; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:mnpos; 177, subscript; 177, 178; 177, 179; 178, identifier:x; 179, identifier:i; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:lookformax; 183, False; 184, else_clause; 184, 185; 185, block; 185, 186; 186, if_statement; 186, 187; 186, 192; 187, comparison_operator:>; 187, 188; 187, 189; 188, identifier:this; 189, binary_operator:+; 189, 190; 189, 191; 190, identifier:mn; 191, identifier:delta; 192, block; 192, 193; 192, 202; 192, 206; 192, 212; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:mintab; 197, identifier:append; 198, argument_list; 198, 199; 199, tuple; 199, 200; 199, 201; 200, identifier:mnpos; 201, identifier:mn; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:mx; 205, identifier:this; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:mxpos; 209, subscript; 209, 210; 209, 211; 210, identifier:x; 211, identifier:i; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:lookformax; 215, True; 216, return_statement; 216, 217; 217, expression_list; 217, 218; 217, 222; 218, call; 218, 219; 218, 220; 219, identifier:array; 220, argument_list; 220, 221; 221, identifier:maxtab; 222, call; 222, 223; 222, 224; 223, identifier:array; 224, argument_list; 224, 225; 225, identifier:mintab
def peakdelta(v, delta, x=None): maxtab = [] mintab = [] if x is None: x = arange(len(v)) v = asarray(v) if len(v) != len(x): sys.exit('Input vectors v and x must have same length') if not isscalar(delta): sys.exit('Input argument delta must be a scalar') if delta <= 0: sys.exit('Input argument delta must be positive') mn, mx = Inf, -Inf mnpos, mxpos = NaN, NaN lookformax = True for i in arange(len(v)): this = v[i] if this > mx: mx = this mxpos = x[i] if this < mn: mn = this mnpos = x[i] if lookformax: if this < mx - delta: maxtab.append((mxpos, mx)) mn = this mnpos = x[i] lookformax = False else: if this > mn + delta: mintab.append((mnpos, mn)) mx = this mxpos = x[i] lookformax = True return array(maxtab), array(mintab)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_datetime; 3, parameters; 3, 4; 4, identifier:value; 5, block; 5, 6; 5, 13; 5, 69; 5, 82; 5, 91; 6, if_statement; 6, 7; 6, 10; 7, comparison_operator:is; 7, 8; 7, 9; 8, identifier:value; 9, None; 10, block; 10, 11; 11, return_statement; 11, 12; 12, None; 13, function_definition; 13, 14; 13, 15; 13, 17; 14, function_name:_get_fixed_timezone; 15, parameters; 15, 16; 16, identifier:offset; 17, block; 17, 18; 17, 33; 17, 42; 17, 55; 17, 61; 18, if_statement; 18, 19; 18, 24; 19, call; 19, 20; 19, 21; 20, identifier:isinstance; 21, argument_list; 21, 22; 21, 23; 22, identifier:offset; 23, identifier:timedelta; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:offset; 28, binary_operator://; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:offset; 31, identifier:seconds; 32, integer:60; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:sign; 36, conditional_expression:if; 36, 37; 36, 38; 36, 41; 37, string:'-'; 38, comparison_operator:<; 38, 39; 38, 40; 39, identifier:offset; 40, integer:0; 41, string:'+'; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:hhmm; 45, binary_operator:%; 45, 46; 45, 47; 46, string:'%02d%02d'; 47, call; 47, 48; 47, 49; 48, identifier:divmod; 49, argument_list; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:abs; 52, argument_list; 52, 53; 53, identifier:offset; 54, integer:60; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:name; 58, binary_operator:+; 58, 59; 58, 60; 59, identifier:sign; 60, identifier:hhmm; 61, return_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:pytz; 65, identifier:FixedOffset; 66, argument_list; 66, 67; 66, 68; 67, identifier:offset; 68, identifier:name; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:DATETIME_RE; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:re; 75, identifier:compile; 76, argument_list; 76, 77; 77, concatenated_string; 77, 78; 77, 79; 77, 80; 77, 81; 78, string:r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})'; 79, string:r'[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})'; 80, string:r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?'; 81, string:r'(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$'; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:match; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:DATETIME_RE; 88, identifier:match; 89, argument_list; 89, 90; 90, identifier:value; 91, if_statement; 91, 92; 91, 93; 92, identifier:match; 93, block; 93, 94; 93, 102; 93, 121; 93, 130; 93, 201; 93, 225; 93, 231; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:kw; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:match; 100, identifier:groupdict; 101, argument_list; 102, if_statement; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:kw; 105, string:'microsecond'; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:kw; 111, string:'microsecond'; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:kw; 116, string:'microsecond'; 117, identifier:ljust; 118, argument_list; 118, 119; 118, 120; 119, integer:6; 120, string:'0'; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:tzinfo; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:kw; 127, identifier:pop; 128, argument_list; 128, 129; 129, string:'tzinfo'; 130, if_statement; 130, 131; 130, 134; 130, 141; 131, comparison_operator:==; 131, 132; 131, 133; 132, identifier:tzinfo; 133, string:'Z'; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:tzinfo; 138, attribute; 138, 139; 138, 140; 139, identifier:pytz; 140, identifier:UTC; 141, elif_clause; 141, 142; 141, 145; 142, comparison_operator:is; 142, 143; 142, 144; 143, identifier:tzinfo; 144, None; 145, block; 145, 146; 145, 166; 145, 182; 145, 194; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:offset_mins; 149, conditional_expression:if; 149, 150; 149, 159; 149, 165; 150, call; 150, 151; 150, 152; 151, identifier:int; 152, argument_list; 152, 153; 153, subscript; 153, 154; 153, 155; 154, identifier:tzinfo; 155, slice; 155, 156; 155, 158; 156, unary_operator:-; 156, 157; 157, integer:2; 158, colon; 159, comparison_operator:>; 159, 160; 159, 164; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, identifier:tzinfo; 164, integer:3; 165, integer:0; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:offset; 169, binary_operator:+; 169, 170; 169, 181; 170, binary_operator:*; 170, 171; 170, 172; 171, integer:60; 172, call; 172, 173; 172, 174; 173, identifier:int; 174, argument_list; 174, 175; 175, subscript; 175, 176; 175, 177; 176, identifier:tzinfo; 177, slice; 177, 178; 177, 179; 177, 180; 178, integer:1; 179, colon; 180, integer:3; 181, identifier:offset_mins; 182, if_statement; 182, 183; 182, 188; 183, comparison_operator:==; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:tzinfo; 186, integer:0; 187, string:'-'; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:offset; 192, unary_operator:-; 192, 193; 193, identifier:offset; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:tzinfo; 197, call; 197, 198; 197, 199; 198, identifier:_get_fixed_timezone; 199, argument_list; 199, 200; 200, identifier:offset; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:kw; 204, dictionary_comprehension; 204, 205; 204, 211; 204, 221; 205, pair; 205, 206; 205, 207; 206, identifier:k; 207, call; 207, 208; 207, 209; 208, identifier:int; 209, argument_list; 209, 210; 210, identifier:v; 211, for_in_clause; 211, 212; 211, 215; 212, pattern_list; 212, 213; 212, 214; 213, identifier:k; 214, identifier:v; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:six; 218, identifier:iteritems; 219, argument_list; 219, 220; 220, identifier:kw; 221, if_clause; 221, 222; 222, comparison_operator:is; 222, 223; 222, 224; 223, identifier:v; 224, None; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 230; 227, subscript; 227, 228; 227, 229; 228, identifier:kw; 229, string:'tzinfo'; 230, identifier:tzinfo; 231, return_statement; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:datetime; 234, argument_list; 234, 235; 235, dictionary_splat; 235, 236; 236, identifier:kw
def parse_datetime(value): if value is None: return None def _get_fixed_timezone(offset): if isinstance(offset, timedelta): offset = offset.seconds // 60 sign = '-' if offset < 0 else '+' hhmm = '%02d%02d' % divmod(abs(offset), 60) name = sign + hhmm return pytz.FixedOffset(offset, name) DATETIME_RE = re.compile( r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})' r'[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})' r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?' r'(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$' ) match = DATETIME_RE.match(value) if match: kw = match.groupdict() if kw['microsecond']: kw['microsecond'] = kw['microsecond'].ljust(6, '0') tzinfo = kw.pop('tzinfo') if tzinfo == 'Z': tzinfo = pytz.UTC elif tzinfo is not None: offset_mins = int(tzinfo[-2:]) if len(tzinfo) > 3 else 0 offset = 60 * int(tzinfo[1:3]) + offset_mins if tzinfo[0] == '-': offset = -offset tzinfo = _get_fixed_timezone(offset) kw = {k: int(v) for k, v in six.iteritems(kw) if v is not None} kw['tzinfo'] = tzinfo return datetime(**kw)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:add_property_grid_widget; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:part_instance; 6, default_parameter; 6, 7; 6, 8; 7, identifier:max_height; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:custom_title; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:show_headers; 14, True; 15, default_parameter; 15, 16; 15, 17; 16, identifier:show_columns; 17, None; 18, block; 18, 19; 18, 23; 18, 82; 18, 92; 18, 102; 18, 108; 18, 131; 18, 174; 18, 183; 18, 226; 18, 232; 18, 238; 18, 279; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:height; 22, identifier:max_height; 23, if_statement; 23, 24; 23, 29; 23, 36; 23, 65; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 28; 27, identifier:part_instance; 28, identifier:Part; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:part_instance_id; 33, attribute; 33, 34; 33, 35; 34, identifier:part_instance; 35, identifier:id; 36, elif_clause; 36, 37; 36, 47; 37, boolean_operator:and; 37, 38; 37, 43; 38, call; 38, 39; 38, 40; 39, identifier:isinstance; 40, argument_list; 40, 41; 40, 42; 41, identifier:part_instance; 42, identifier:text_type; 43, call; 43, 44; 43, 45; 44, identifier:is_uuid; 45, argument_list; 45, 46; 46, identifier:part_instance; 47, block; 47, 48; 47, 52; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:part_instance_id; 51, identifier:part_instance; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:part_instance; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_client; 60, identifier:part; 61, argument_list; 61, 62; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:id; 64, identifier:part_instance_id; 65, else_clause; 65, 66; 66, block; 66, 67; 67, raise_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:IllegalArgumentError; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, concatenated_string; 73, 74; 73, 75; 74, string:"When using the add_property_grid_widget, part_instance must be a "; 75, string:"Part or Part id. Type is: {}"; 76, identifier:format; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:type; 80, argument_list; 80, 81; 81, identifier:part_instance; 82, if_statement; 82, 83; 82, 85; 83, not_operator; 83, 84; 84, identifier:show_columns; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:show_columns; 89, call; 89, 90; 89, 91; 90, identifier:list; 91, argument_list; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:possible_columns; 95, list:[ShowColumnTypes.DESCRIPTION, ShowColumnTypes.UNIT]; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:ShowColumnTypes; 98, identifier:DESCRIPTION; 99, attribute; 99, 100; 99, 101; 100, identifier:ShowColumnTypes; 101, identifier:UNIT; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:display_columns; 105, call; 105, 106; 105, 107; 106, identifier:dict; 107, argument_list; 108, for_statement; 108, 109; 108, 110; 108, 111; 109, identifier:possible_column; 110, identifier:possible_columns; 111, block; 111, 112; 112, if_statement; 112, 113; 112, 116; 112, 123; 113, comparison_operator:in; 113, 114; 113, 115; 114, identifier:possible_column; 115, identifier:show_columns; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:display_columns; 121, identifier:possible_column; 122, True; 123, else_clause; 123, 124; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:display_columns; 129, identifier:possible_column; 130, False; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:config; 134, dictionary; 134, 135; 134, 140; 134, 145; 134, 161; 134, 165; 135, pair; 135, 136; 135, 137; 136, string:"xtype"; 137, attribute; 137, 138; 137, 139; 138, identifier:ComponentXType; 139, identifier:PROPERTYGRID; 140, pair; 140, 141; 140, 142; 141, string:"category"; 142, attribute; 142, 143; 142, 144; 143, identifier:Category; 144, identifier:INSTANCE; 145, pair; 145, 146; 145, 147; 146, string:"filter"; 147, dictionary; 147, 148; 147, 158; 148, pair; 148, 149; 148, 150; 149, string:"activity_id"; 150, call; 150, 151; 150, 152; 151, identifier:str; 152, argument_list; 152, 153; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:activity; 157, identifier:id; 158, pair; 158, 159; 158, 160; 159, string:"part"; 160, identifier:part_instance_id; 161, pair; 161, 162; 161, 163; 162, string:"hideHeaders"; 163, not_operator; 163, 164; 164, identifier:show_headers; 165, pair; 165, 166; 165, 167; 166, string:"viewModel"; 167, dictionary; 167, 168; 168, pair; 168, 169; 168, 170; 169, string:"data"; 170, dictionary; 170, 171; 171, pair; 171, 172; 171, 173; 172, string:"displayColumns"; 173, identifier:display_columns; 174, if_statement; 174, 175; 174, 176; 175, identifier:height; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:config; 181, string:'height'; 182, identifier:height; 183, if_statement; 183, 184; 183, 187; 183, 198; 183, 213; 184, comparison_operator:is; 184, 185; 184, 186; 185, identifier:custom_title; 186, False; 187, block; 187, 188; 187, 192; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:show_title_value; 191, string:"Default"; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:title; 195, attribute; 195, 196; 195, 197; 196, identifier:part_instance; 197, identifier:name; 198, elif_clause; 198, 199; 198, 202; 199, comparison_operator:is; 199, 200; 199, 201; 200, identifier:custom_title; 201, None; 202, block; 202, 203; 202, 207; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:show_title_value; 206, string:"No title"; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:title; 210, call; 210, 211; 210, 212; 211, identifier:str; 212, argument_list; 213, else_clause; 213, 214; 214, block; 214, 215; 214, 219; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:show_title_value; 218, string:"Custom title"; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:title; 222, call; 222, 223; 222, 224; 223, identifier:str; 224, argument_list; 224, 225; 225, identifier:custom_title; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:config; 230, string:"title"; 231, identifier:title; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:config; 236, string:"showTitleValue"; 237, identifier:show_title_value; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:meta; 241, dictionary; 241, 242; 241, 252; 241, 258; 241, 261; 241, 264; 241, 267; 241, 270; 241, 276; 242, pair; 242, 243; 242, 244; 243, string:"activityId"; 244, call; 244, 245; 244, 246; 245, identifier:str; 246, argument_list; 246, 247; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:activity; 251, identifier:id; 252, pair; 252, 253; 252, 254; 253, string:"customHeight"; 254, conditional_expression:if; 254, 255; 254, 256; 254, 257; 255, identifier:height; 256, identifier:height; 257, None; 258, pair; 258, 259; 258, 260; 259, string:"customTitle"; 260, identifier:title; 261, pair; 261, 262; 261, 263; 262, string:"partInstanceId"; 263, identifier:part_instance_id; 264, pair; 264, 265; 264, 266; 265, string:"showColumns"; 266, identifier:show_columns; 267, pair; 267, 268; 267, 269; 268, string:"showHeaders"; 269, identifier:show_headers; 270, pair; 270, 271; 270, 272; 271, string:"showHeightValue"; 272, conditional_expression:if; 272, 273; 272, 274; 272, 275; 273, string:"Set height"; 274, identifier:height; 275, string:"Automatic height"; 276, pair; 276, 277; 276, 278; 277, string:"showTitleValue"; 278, identifier:show_title_value; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:self; 283, identifier:_add_widget; 284, argument_list; 284, 285; 285, call; 285, 286; 285, 287; 286, identifier:dict; 287, argument_list; 287, 288; 287, 291; 287, 294; 288, keyword_argument; 288, 289; 288, 290; 289, identifier:config; 290, identifier:config; 291, keyword_argument; 291, 292; 291, 293; 292, identifier:meta; 293, identifier:meta; 294, keyword_argument; 294, 295; 294, 296; 295, identifier:name; 296, attribute; 296, 297; 296, 298; 297, identifier:WidgetNames; 298, identifier:PROPERTYGRIDWIDGET
def add_property_grid_widget(self, part_instance, max_height=None, custom_title=False, show_headers=True, show_columns=None): height = max_height if isinstance(part_instance, Part): part_instance_id = part_instance.id elif isinstance(part_instance, text_type) and is_uuid(part_instance): part_instance_id = part_instance part_instance = self._client.part(id=part_instance_id) else: raise IllegalArgumentError("When using the add_property_grid_widget, part_instance must be a " "Part or Part id. Type is: {}".format(type(part_instance))) if not show_columns: show_columns = list() possible_columns = [ShowColumnTypes.DESCRIPTION, ShowColumnTypes.UNIT] display_columns = dict() for possible_column in possible_columns: if possible_column in show_columns: display_columns[possible_column] = True else: display_columns[possible_column] = False config = { "xtype": ComponentXType.PROPERTYGRID, "category": Category.INSTANCE, "filter": { "activity_id": str(self.activity.id), "part": part_instance_id }, "hideHeaders": not show_headers, "viewModel": { "data": { "displayColumns": display_columns } }, } if height: config['height'] = height if custom_title is False: show_title_value = "Default" title = part_instance.name elif custom_title is None: show_title_value = "No title" title = str() else: show_title_value = "Custom title" title = str(custom_title) config["title"] = title config["showTitleValue"] = show_title_value meta = { "activityId": str(self.activity.id), "customHeight": height if height else None, "customTitle": title, "partInstanceId": part_instance_id, "showColumns": show_columns, "showHeaders": show_headers, "showHeightValue": "Set height" if height else "Automatic height", "showTitleValue": show_title_value } self._add_widget(dict(config=config, meta=meta, name=WidgetNames.PROPERTYGRIDWIDGET))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_generate_data_for_format; 3, parameters; 3, 4; 4, identifier:fmt; 5, block; 5, 6; 5, 10; 5, 14; 5, 216; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:data; 9, dictionary; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:free_size_start; 13, False; 14, for_statement; 14, 15; 14, 20; 14, 26; 15, pattern_list; 15, 16; 15, 17; 15, 18; 15, 19; 16, identifier:literal_text; 17, identifier:field_name; 18, identifier:format_spec; 19, identifier:conversion; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:formatter; 23, identifier:parse; 24, argument_list; 24, 25; 25, identifier:fmt; 26, block; 26, 27; 26, 34; 26, 43; 26, 66; 27, if_statement; 27, 28; 27, 29; 28, identifier:literal_text; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:free_size_start; 33, False; 34, if_statement; 34, 35; 34, 37; 35, not_operator; 35, 36; 36, identifier:field_name; 37, block; 37, 38; 37, 42; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:free_size_start; 41, False; 42, continue_statement; 43, if_statement; 43, 44; 43, 54; 44, boolean_operator:or; 44, 45; 44, 51; 45, boolean_operator:or; 45, 46; 45, 48; 46, not_operator; 46, 47; 47, identifier:format_spec; 48, comparison_operator:==; 48, 49; 48, 50; 49, identifier:format_spec; 50, string:"s"; 51, comparison_operator:==; 51, 52; 51, 53; 52, identifier:format_spec; 53, string:"d"; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 57; 55, 60; 56, identifier:free_size_start; 57, block; 57, 58; 58, return_statement; 58, 59; 59, None; 60, else_clause; 60, 61; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:free_size_start; 65, True; 66, if_statement; 66, 67; 66, 72; 66, 114; 66, 157; 67, boolean_operator:and; 67, 68; 67, 69; 68, identifier:format_spec; 69, comparison_operator:in; 69, 70; 69, 71; 70, string:'%'; 71, identifier:format_spec; 72, block; 72, 73; 72, 83; 72, 108; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:t; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:dt; 80, identifier:datetime; 81, identifier:now; 82, argument_list; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:t; 86, subscript; 86, 87; 86, 107; 87, call; 87, 88; 87, 89; 88, identifier:parse; 89, argument_list; 89, 90; 89, 95; 90, binary_operator:+; 90, 91; 90, 94; 91, binary_operator:+; 91, 92; 91, 93; 92, string:"{t:"; 93, identifier:format_spec; 94, string:"}"; 95, call; 95, 96; 95, 97; 96, identifier:compose; 97, argument_list; 97, 98; 97, 103; 98, binary_operator:+; 98, 99; 98, 102; 99, binary_operator:+; 99, 100; 99, 101; 100, string:"{t:"; 101, identifier:format_spec; 102, string:"}"; 103, dictionary; 103, 104; 104, pair; 104, 105; 104, 106; 105, string:'t'; 106, identifier:t; 107, string:'t'; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:data; 112, identifier:field_name; 113, identifier:t; 114, elif_clause; 114, 115; 114, 120; 115, boolean_operator:and; 115, 116; 115, 117; 116, identifier:format_spec; 117, comparison_operator:in; 117, 118; 117, 119; 118, string:'d'; 119, identifier:format_spec; 120, block; 120, 121; 120, 140; 121, if_statement; 121, 122; 121, 128; 121, 136; 122, not_operator; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:format_spec; 126, identifier:isalpha; 127, argument_list; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:n; 132, call; 132, 133; 132, 134; 133, identifier:_get_number_from_fmt; 134, argument_list; 134, 135; 135, identifier:format_spec; 136, else_clause; 136, 137; 137, block; 137, 138; 138, return_statement; 138, 139; 139, None; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:data; 144, identifier:field_name; 145, binary_operator:%; 145, 146; 145, 153; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:random; 149, identifier:randint; 150, argument_list; 150, 151; 150, 152; 151, integer:0; 152, integer:99999999999999999; 153, parenthesized_expression; 153, 154; 154, binary_operator:**; 154, 155; 154, 156; 155, integer:10; 156, identifier:n; 157, else_clause; 157, 158; 158, block; 158, 159; 158, 188; 158, 192; 158, 210; 159, if_statement; 159, 160; 159, 163; 159, 168; 159, 182; 160, comparison_operator:is; 160, 161; 160, 162; 161, identifier:format_spec; 162, None; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:n; 167, integer:4; 168, elif_clause; 168, 169; 168, 174; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:format_spec; 172, identifier:isalnum; 173, argument_list; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:n; 178, call; 178, 179; 178, 180; 179, identifier:_get_number_from_fmt; 180, argument_list; 180, 181; 181, identifier:format_spec; 182, else_clause; 182, 183; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:n; 187, integer:4; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:randstri; 191, string:''; 192, for_statement; 192, 193; 192, 194; 192, 198; 193, identifier:x; 194, call; 194, 195; 194, 196; 195, identifier:range; 196, argument_list; 196, 197; 197, identifier:n; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, augmented_assignment:+=; 200, 201; 200, 202; 201, identifier:randstri; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:random; 205, identifier:choice; 206, argument_list; 206, 207; 207, attribute; 207, 208; 207, 209; 208, identifier:string; 209, identifier:ascii_letters; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 215; 212, subscript; 212, 213; 212, 214; 213, identifier:data; 214, identifier:field_name; 215, identifier:randstri; 216, return_statement; 216, 217; 217, identifier:data
def _generate_data_for_format(fmt): data = {} free_size_start = False for literal_text, field_name, format_spec, conversion in formatter.parse(fmt): if literal_text: free_size_start = False if not field_name: free_size_start = False continue if not format_spec or format_spec == "s" or format_spec == "d": if free_size_start: return None else: free_size_start = True if format_spec and '%' in format_spec: t = dt.datetime.now() t = parse( "{t:" + format_spec + "}", compose("{t:" + format_spec + "}", {'t': t}))['t'] data[field_name] = t elif format_spec and 'd' in format_spec: if not format_spec.isalpha(): n = _get_number_from_fmt(format_spec) else: return None data[field_name] = random.randint(0, 99999999999999999) % (10 ** n) else: if format_spec is None: n = 4 elif format_spec.isalnum(): n = _get_number_from_fmt(format_spec) else: n = 4 randstri = '' for x in range(n): randstri += random.choice(string.ascii_letters) data[field_name] = randstri return data
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:relocate_model; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:part; 5, identifier:target_parent; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:include_children; 11, True; 12, block; 12, 13; 12, 46; 12, 61; 12, 69; 12, 85; 12, 100; 12, 114; 12, 120; 12, 136; 12, 358; 12, 391; 13, if_statement; 13, 14; 13, 28; 14, comparison_operator:in; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:target_parent; 17, identifier:id; 18, call; 18, 19; 18, 20; 19, identifier:get_illegal_targets; 20, argument_list; 20, 21; 20, 22; 21, identifier:part; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:include; 24, set; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:part; 27, identifier:id; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:IllegalArgumentError; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, concatenated_string; 35, 36; 35, 37; 36, string:'cannot relocate part "{}" under target parent "{}", because the target is part of '; 37, string:'its descendants'; 38, identifier:format; 39, argument_list; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:part; 42, identifier:name; 43, attribute; 43, 44; 43, 45; 44, identifier:target_parent; 45, identifier:name; 46, if_statement; 46, 47; 46, 49; 47, not_operator; 47, 48; 48, identifier:name; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:name; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, string:"CLONE - {}"; 56, identifier:format; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:part; 60, identifier:name; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:part_desc; 64, subscript; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:part; 67, identifier:_json_data; 68, string:'description'; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:moved_part_model; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:target_parent; 75, identifier:add_model; 76, argument_list; 76, 77; 76, 80; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:name; 79, identifier:name; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:multiplicity; 82, attribute; 82, 83; 82, 84; 83, identifier:part; 84, identifier:multiplicity; 85, if_statement; 85, 86; 85, 87; 86, identifier:part_desc; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:moved_part_model; 92, identifier:edit; 93, argument_list; 93, 94; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:description; 96, call; 96, 97; 96, 98; 97, identifier:str; 98, argument_list; 98, 99; 99, identifier:part_desc; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, call; 103, 104; 103, 105; 104, identifier:get_mapping_dictionary; 105, argument_list; 106, identifier:update; 107, argument_list; 107, 108; 108, dictionary; 108, 109; 109, pair; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:part; 112, identifier:id; 113, identifier:moved_part_model; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:list_of_properties_sorted_by_order; 117, attribute; 117, 118; 117, 119; 118, identifier:part; 119, identifier:properties; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:list_of_properties_sorted_by_order; 124, identifier:sort; 125, argument_list; 125, 126; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:key; 128, lambda; 128, 129; 128, 131; 129, lambda_parameters; 129, 130; 130, identifier:x; 131, subscript; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:x; 134, identifier:_json_data; 135, string:'order'; 136, for_statement; 136, 137; 136, 138; 136, 139; 137, identifier:prop; 138, identifier:list_of_properties_sorted_by_order; 139, block; 139, 140; 139, 151; 139, 162; 139, 173; 139, 184; 139, 348; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:prop_type; 143, call; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:prop; 147, identifier:_json_data; 148, identifier:get; 149, argument_list; 149, 150; 150, string:'property_type'; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:desc; 154, call; 154, 155; 154, 160; 155, attribute; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:prop; 158, identifier:_json_data; 159, identifier:get; 160, argument_list; 160, 161; 161, string:'description'; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:unit; 165, call; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:prop; 169, identifier:_json_data; 170, identifier:get; 171, argument_list; 171, 172; 172, string:'unit'; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:options; 176, call; 176, 177; 176, 182; 177, attribute; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:prop; 180, identifier:_json_data; 181, identifier:get; 182, argument_list; 182, 183; 183, string:'options'; 184, if_statement; 184, 185; 184, 190; 184, 225; 184, 316; 185, comparison_operator:==; 185, 186; 185, 187; 186, identifier:prop_type; 187, attribute; 187, 188; 187, 189; 188, identifier:PropertyType; 189, identifier:REFERENCES_VALUE; 190, block; 190, 191; 190, 203; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:referenced_part_ids; 194, list_comprehension; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:referenced_part; 197, identifier:id; 198, for_in_clause; 198, 199; 198, 200; 199, identifier:referenced_part; 200, attribute; 200, 201; 200, 202; 201, identifier:prop; 202, identifier:value; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:moved_prop; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:moved_part_model; 209, identifier:add_property; 210, argument_list; 210, 211; 210, 216; 210, 219; 210, 222; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:name; 213, attribute; 213, 214; 213, 215; 214, identifier:prop; 215, identifier:name; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:description; 218, identifier:desc; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:property_type; 221, identifier:prop_type; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:default_value; 224, identifier:referenced_part_ids; 225, elif_clause; 225, 226; 225, 231; 226, comparison_operator:==; 226, 227; 226, 228; 227, identifier:prop_type; 228, attribute; 228, 229; 228, 230; 229, identifier:PropertyType; 230, identifier:ATTACHMENT_VALUE; 231, block; 231, 232; 231, 251; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:moved_prop; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:moved_part_model; 238, identifier:add_property; 239, argument_list; 239, 240; 239, 245; 239, 248; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:name; 242, attribute; 242, 243; 242, 244; 243, identifier:prop; 244, identifier:name; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:description; 247, identifier:desc; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:property_type; 250, identifier:prop_type; 251, if_statement; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:prop; 254, identifier:value; 255, block; 255, 256; 255, 272; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:attachment_name; 259, subscript; 259, 260; 259, 270; 260, call; 260, 261; 260, 268; 261, attribute; 261, 262; 261, 267; 262, subscript; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:prop; 265, identifier:_json_data; 266, string:'value'; 267, identifier:split; 268, argument_list; 268, 269; 269, string:'/'; 270, unary_operator:-; 270, 271; 271, integer:1; 272, with_statement; 272, 273; 272, 281; 273, with_clause; 273, 274; 274, with_item; 274, 275; 275, as_pattern; 275, 276; 275, 279; 276, call; 276, 277; 276, 278; 277, identifier:temp_chdir; 278, argument_list; 279, as_pattern_target; 279, 280; 280, identifier:target_dir; 281, block; 281, 282; 281, 300; 281, 309; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:full_path; 285, call; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:os; 289, identifier:path; 290, identifier:join; 291, argument_list; 291, 292; 291, 299; 292, boolean_operator:or; 292, 293; 292, 294; 293, identifier:target_dir; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:os; 297, identifier:getcwd; 298, argument_list; 299, identifier:attachment_name; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:prop; 304, identifier:save_as; 305, argument_list; 305, 306; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:filename; 308, identifier:full_path; 309, expression_statement; 309, 310; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:moved_prop; 313, identifier:upload; 314, argument_list; 314, 315; 315, identifier:full_path; 316, else_clause; 316, 317; 317, block; 317, 318; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:moved_prop; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:moved_part_model; 324, identifier:add_property; 325, argument_list; 325, 326; 325, 331; 325, 334; 325, 337; 325, 342; 325, 345; 326, keyword_argument; 326, 327; 326, 328; 327, identifier:name; 328, attribute; 328, 329; 328, 330; 329, identifier:prop; 330, identifier:name; 331, keyword_argument; 331, 332; 331, 333; 332, identifier:description; 333, identifier:desc; 334, keyword_argument; 334, 335; 334, 336; 335, identifier:property_type; 336, identifier:prop_type; 337, keyword_argument; 337, 338; 337, 339; 338, identifier:default_value; 339, attribute; 339, 340; 339, 341; 340, identifier:prop; 341, identifier:value; 342, keyword_argument; 342, 343; 342, 344; 343, identifier:unit; 344, identifier:unit; 345, keyword_argument; 345, 346; 345, 347; 346, identifier:options; 347, identifier:options; 348, expression_statement; 348, 349; 349, assignment; 349, 350; 349, 357; 350, subscript; 350, 351; 350, 354; 351, call; 351, 352; 351, 353; 352, identifier:get_mapping_dictionary; 353, argument_list; 354, attribute; 354, 355; 354, 356; 355, identifier:prop; 356, identifier:id; 357, identifier:moved_prop; 358, if_statement; 358, 359; 358, 360; 359, identifier:include_children; 360, block; 360, 361; 360, 367; 361, expression_statement; 361, 362; 362, call; 362, 363; 362, 366; 363, attribute; 363, 364; 363, 365; 364, identifier:part; 365, identifier:populate_descendants; 366, argument_list; 367, for_statement; 367, 368; 367, 369; 367, 372; 368, identifier:sub_part; 369, attribute; 369, 370; 369, 371; 370, identifier:part; 371, identifier:_cached_children; 372, block; 372, 373; 373, expression_statement; 373, 374; 374, call; 374, 375; 374, 376; 375, identifier:relocate_model; 376, argument_list; 376, 377; 376, 380; 376, 383; 376, 388; 377, keyword_argument; 377, 378; 377, 379; 378, identifier:part; 379, identifier:sub_part; 380, keyword_argument; 380, 381; 380, 382; 381, identifier:target_parent; 382, identifier:moved_part_model; 383, keyword_argument; 383, 384; 383, 385; 384, identifier:name; 385, attribute; 385, 386; 385, 387; 386, identifier:sub_part; 387, identifier:name; 388, keyword_argument; 388, 389; 388, 390; 389, identifier:include_children; 390, identifier:include_children; 391, return_statement; 391, 392; 392, identifier:moved_part_model
def relocate_model(part, target_parent, name=None, include_children=True): if target_parent.id in get_illegal_targets(part, include={part.id}): raise IllegalArgumentError('cannot relocate part "{}" under target parent "{}", because the target is part of ' 'its descendants'.format(part.name, target_parent.name)) if not name: name = "CLONE - {}".format(part.name) part_desc = part._json_data['description'] moved_part_model = target_parent.add_model(name=name, multiplicity=part.multiplicity) if part_desc: moved_part_model.edit(description=str(part_desc)) get_mapping_dictionary().update({part.id: moved_part_model}) list_of_properties_sorted_by_order = part.properties list_of_properties_sorted_by_order.sort(key=lambda x: x._json_data['order']) for prop in list_of_properties_sorted_by_order: prop_type = prop._json_data.get('property_type') desc = prop._json_data.get('description') unit = prop._json_data.get('unit') options = prop._json_data.get('options') if prop_type == PropertyType.REFERENCES_VALUE: referenced_part_ids = [referenced_part.id for referenced_part in prop.value] moved_prop = moved_part_model.add_property(name=prop.name, description=desc, property_type=prop_type, default_value=referenced_part_ids) elif prop_type == PropertyType.ATTACHMENT_VALUE: moved_prop = moved_part_model.add_property(name=prop.name, description=desc, property_type=prop_type) if prop.value: attachment_name = prop._json_data['value'].split('/')[-1] with temp_chdir() as target_dir: full_path = os.path.join(target_dir or os.getcwd(), attachment_name) prop.save_as(filename=full_path) moved_prop.upload(full_path) else: moved_prop = moved_part_model.add_property(name=prop.name, description=desc, property_type=prop_type, default_value=prop.value, unit=unit, options=options) get_mapping_dictionary()[prop.id] = moved_prop if include_children: part.populate_descendants() for sub_part in part._cached_children: relocate_model(part=sub_part, target_parent=moved_part_model, name=sub_part.name, include_children=include_children) return moved_part_model
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:relocate_instance; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:part; 5, identifier:target_parent; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:include_children; 11, True; 12, block; 12, 13; 12, 28; 12, 36; 12, 44; 12, 62; 12, 71; 12, 92; 13, if_statement; 13, 14; 13, 16; 14, not_operator; 14, 15; 15, identifier:name; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:name; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, string:"CLONE - {}"; 23, identifier:format; 24, argument_list; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:part; 27, identifier:name; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:part_model; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:part; 34, identifier:model; 35, argument_list; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:target_parent_model; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:target_parent; 42, identifier:model; 43, argument_list; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:relocate_model; 47, argument_list; 47, 48; 47, 51; 47, 54; 47, 59; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:part; 50, identifier:part_model; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:target_parent; 53, identifier:target_parent_model; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:name; 56, attribute; 56, 57; 56, 58; 57, identifier:part_model; 58, identifier:name; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:include_children; 61, identifier:include_children; 62, if_statement; 62, 63; 62, 64; 63, identifier:include_children; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:part; 69, identifier:populate_descendants; 70, argument_list; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:moved_instance; 74, call; 74, 75; 74, 76; 75, identifier:move_part_instance; 76, argument_list; 76, 77; 76, 80; 76, 83; 76, 86; 76, 89; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:part_instance; 79, identifier:part; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:target_parent; 82, identifier:target_parent; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:part_model; 85, identifier:part_model; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:name; 88, identifier:name; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:include_children; 91, identifier:include_children; 92, return_statement; 92, 93; 93, identifier:moved_instance
def relocate_instance(part, target_parent, name=None, include_children=True): if not name: name = "CLONE - {}".format(part.name) part_model = part.model() target_parent_model = target_parent.model() relocate_model(part=part_model, target_parent=target_parent_model, name=part_model.name, include_children=include_children) if include_children: part.populate_descendants() moved_instance = move_part_instance(part_instance=part, target_parent=target_parent, part_model=part_model, name=name, include_children=include_children) return moved_instance
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:move_part_instance; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:part_instance; 5, identifier:target_parent; 6, identifier:part_model; 7, default_parameter; 7, 8; 7, 9; 8, identifier:name; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:include_children; 12, True; 13, block; 13, 14; 13, 24; 13, 34; 13, 222; 13, 256; 14, if_statement; 14, 15; 14, 17; 15, not_operator; 15, 16; 16, identifier:name; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:name; 21, attribute; 21, 22; 21, 23; 22, identifier:part_instance; 23, identifier:name; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:moved_model; 27, subscript; 27, 28; 27, 31; 28, call; 28, 29; 28, 30; 29, identifier:get_mapping_dictionary; 30, argument_list; 31, attribute; 31, 32; 31, 33; 32, identifier:part_model; 33, identifier:id; 34, if_statement; 34, 35; 34, 42; 34, 78; 34, 183; 35, comparison_operator:==; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:moved_model; 38, identifier:multiplicity; 39, attribute; 39, 40; 39, 41; 40, identifier:Multiplicity; 41, identifier:ONE; 42, block; 42, 43; 42, 58; 42, 64; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:moved_instance; 46, subscript; 46, 47; 46, 57; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:moved_model; 50, identifier:instances; 51, argument_list; 51, 52; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:parent_id; 54, attribute; 54, 55; 54, 56; 55, identifier:target_parent; 56, identifier:id; 57, integer:0; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:map_property_instances; 61, argument_list; 61, 62; 61, 63; 62, identifier:part_instance; 63, identifier:moved_instance; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:moved_instance; 67, call; 67, 68; 67, 69; 68, identifier:update_part_with_properties; 69, argument_list; 69, 70; 69, 71; 69, 72; 70, identifier:part_instance; 71, identifier:moved_instance; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:name; 74, call; 74, 75; 74, 76; 75, identifier:str; 76, argument_list; 76, 77; 77, identifier:name; 78, elif_clause; 78, 79; 78, 86; 79, comparison_operator:==; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:moved_model; 82, identifier:multiplicity; 83, attribute; 83, 84; 83, 85; 84, identifier:Multiplicity; 85, identifier:ONE_MANY; 86, block; 86, 87; 87, if_statement; 87, 88; 87, 95; 87, 142; 88, comparison_operator:not; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:target_parent; 91, identifier:id; 92, call; 92, 93; 92, 94; 93, identifier:get_edited_one_many; 94, argument_list; 95, block; 95, 96; 95, 111; 95, 117; 95, 131; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:moved_instance; 99, subscript; 99, 100; 99, 110; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:moved_model; 103, identifier:instances; 104, argument_list; 104, 105; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:parent_id; 107, attribute; 107, 108; 107, 109; 108, identifier:target_parent; 109, identifier:id; 110, integer:0; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:map_property_instances; 114, argument_list; 114, 115; 114, 116; 115, identifier:part_instance; 116, identifier:moved_instance; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:moved_instance; 120, call; 120, 121; 120, 122; 121, identifier:update_part_with_properties; 122, argument_list; 122, 123; 122, 124; 122, 125; 123, identifier:part_instance; 124, identifier:moved_instance; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:name; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:name; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 138; 133, attribute; 133, 134; 133, 137; 134, call; 134, 135; 134, 136; 135, identifier:get_edited_one_many; 136, argument_list; 137, identifier:append; 138, argument_list; 138, 139; 139, attribute; 139, 140; 139, 141; 140, identifier:target_parent; 141, identifier:id; 142, else_clause; 142, 143; 143, block; 143, 144; 143, 163; 143, 169; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:moved_instance; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:target_parent; 150, identifier:add; 151, argument_list; 151, 152; 151, 157; 151, 160; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:name; 154, attribute; 154, 155; 154, 156; 155, identifier:part_instance; 156, identifier:name; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:model; 159, identifier:moved_model; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:suppress_kevents; 162, True; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:map_property_instances; 166, argument_list; 166, 167; 166, 168; 167, identifier:part_instance; 168, identifier:moved_instance; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:moved_instance; 172, call; 172, 173; 172, 174; 173, identifier:update_part_with_properties; 174, argument_list; 174, 175; 174, 176; 174, 177; 175, identifier:part_instance; 176, identifier:moved_instance; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:name; 179, call; 179, 180; 179, 181; 180, identifier:str; 181, argument_list; 181, 182; 182, identifier:name; 183, else_clause; 183, 184; 184, block; 184, 185; 184, 202; 184, 208; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:moved_instance; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:target_parent; 191, identifier:add; 192, argument_list; 192, 193; 192, 196; 192, 199; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:name; 195, identifier:name; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:model; 198, identifier:moved_model; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:suppress_kevents; 201, True; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:map_property_instances; 205, argument_list; 205, 206; 205, 207; 206, identifier:part_instance; 207, identifier:moved_instance; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:moved_instance; 211, call; 211, 212; 211, 213; 212, identifier:update_part_with_properties; 213, argument_list; 213, 214; 213, 215; 213, 216; 214, identifier:part_instance; 215, identifier:moved_instance; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:name; 218, call; 218, 219; 218, 220; 219, identifier:str; 220, argument_list; 220, 221; 221, identifier:name; 222, if_statement; 222, 223; 222, 224; 223, identifier:include_children; 224, block; 224, 225; 225, for_statement; 225, 226; 225, 227; 225, 230; 226, identifier:sub_instance; 227, attribute; 227, 228; 227, 229; 228, identifier:part_instance; 229, identifier:_cached_children; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:move_part_instance; 234, argument_list; 234, 235; 234, 238; 234, 241; 234, 248; 234, 253; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:part_instance; 237, identifier:sub_instance; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:target_parent; 240, identifier:moved_instance; 241, keyword_argument; 241, 242; 241, 243; 242, identifier:part_model; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:sub_instance; 246, identifier:model; 247, argument_list; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:name; 250, attribute; 250, 251; 250, 252; 251, identifier:sub_instance; 252, identifier:name; 253, keyword_argument; 253, 254; 253, 255; 254, identifier:include_children; 255, True; 256, return_statement; 256, 257; 257, identifier:moved_instance
def move_part_instance(part_instance, target_parent, part_model, name=None, include_children=True): if not name: name = part_instance.name moved_model = get_mapping_dictionary()[part_model.id] if moved_model.multiplicity == Multiplicity.ONE: moved_instance = moved_model.instances(parent_id=target_parent.id)[0] map_property_instances(part_instance, moved_instance) moved_instance = update_part_with_properties(part_instance, moved_instance, name=str(name)) elif moved_model.multiplicity == Multiplicity.ONE_MANY: if target_parent.id not in get_edited_one_many(): moved_instance = moved_model.instances(parent_id=target_parent.id)[0] map_property_instances(part_instance, moved_instance) moved_instance = update_part_with_properties(part_instance, moved_instance, name=str(name)) get_edited_one_many().append(target_parent.id) else: moved_instance = target_parent.add(name=part_instance.name, model=moved_model, suppress_kevents=True) map_property_instances(part_instance, moved_instance) moved_instance = update_part_with_properties(part_instance, moved_instance, name=str(name)) else: moved_instance = target_parent.add(name=name, model=moved_model, suppress_kevents=True) map_property_instances(part_instance, moved_instance) moved_instance = update_part_with_properties(part_instance, moved_instance, name=str(name)) if include_children: for sub_instance in part_instance._cached_children: move_part_instance(part_instance=sub_instance, target_parent=moved_instance, part_model=sub_instance.model(), name=sub_instance.name, include_children=True) return moved_instance
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:update_part_with_properties; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:part_instance; 5, identifier:moved_instance; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name; 8, None; 9, block; 9, 10; 9, 16; 9, 180; 9, 201; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:properties_id_dict; 13, call; 13, 14; 13, 15; 14, identifier:dict; 15, argument_list; 16, for_statement; 16, 17; 16, 18; 16, 21; 17, identifier:prop_instance; 18, attribute; 18, 19; 18, 20; 19, identifier:part_instance; 20, identifier:properties; 21, block; 21, 22; 22, if_statement; 22, 23; 22, 32; 22, 116; 22, 158; 23, comparison_operator:==; 23, 24; 23, 29; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:prop_instance; 27, identifier:_json_data; 28, string:'property_type'; 29, attribute; 29, 30; 29, 31; 30, identifier:PropertyType; 31, identifier:ATTACHMENT_VALUE; 32, block; 32, 33; 32, 43; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:moved_prop; 36, subscript; 36, 37; 36, 40; 37, call; 37, 38; 37, 39; 38, identifier:get_mapping_dictionary; 39, argument_list; 40, attribute; 40, 41; 40, 42; 41, identifier:prop_instance; 42, identifier:id; 43, if_statement; 43, 44; 43, 47; 43, 108; 44, attribute; 44, 45; 44, 46; 45, identifier:prop_instance; 46, identifier:value; 47, block; 47, 48; 47, 64; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:attachment_name; 51, subscript; 51, 52; 51, 62; 52, call; 52, 53; 52, 60; 53, attribute; 53, 54; 53, 59; 54, subscript; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:prop_instance; 57, identifier:_json_data; 58, string:'value'; 59, identifier:split; 60, argument_list; 60, 61; 61, string:'/'; 62, unary_operator:-; 62, 63; 63, integer:1; 64, with_statement; 64, 65; 64, 73; 65, with_clause; 65, 66; 66, with_item; 66, 67; 67, as_pattern; 67, 68; 67, 71; 68, call; 68, 69; 68, 70; 69, identifier:temp_chdir; 70, argument_list; 71, as_pattern_target; 71, 72; 72, identifier:target_dir; 73, block; 73, 74; 73, 92; 73, 101; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:full_path; 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, 91; 84, boolean_operator:or; 84, 85; 84, 86; 85, identifier:target_dir; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:os; 89, identifier:getcwd; 90, argument_list; 91, identifier:attachment_name; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:prop_instance; 96, identifier:save_as; 97, argument_list; 97, 98; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:filename; 100, identifier:full_path; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:moved_prop; 105, identifier:upload; 106, argument_list; 106, 107; 107, identifier:full_path; 108, else_clause; 108, 109; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:moved_prop; 114, identifier:clear; 115, argument_list; 116, elif_clause; 116, 117; 116, 126; 117, comparison_operator:==; 117, 118; 117, 123; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:prop_instance; 121, identifier:_json_data; 122, string:'property_type'; 123, attribute; 123, 124; 123, 125; 124, identifier:PropertyType; 125, identifier:REFERENCES_VALUE; 126, block; 126, 127; 127, if_statement; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:prop_instance; 130, identifier:value; 131, block; 131, 132; 131, 142; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:moved_prop_instance; 135, subscript; 135, 136; 135, 139; 136, call; 136, 137; 136, 138; 137, identifier:get_mapping_dictionary; 138, argument_list; 139, attribute; 139, 140; 139, 141; 140, identifier:prop_instance; 141, identifier:id; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 146; 145, identifier:properties_id_dict; 146, attribute; 146, 147; 146, 148; 147, identifier:moved_prop_instance; 148, identifier:id; 149, list_comprehension; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:ref_part; 152, identifier:id; 153, for_in_clause; 153, 154; 153, 155; 154, identifier:ref_part; 155, attribute; 155, 156; 155, 157; 156, identifier:prop_instance; 157, identifier:value; 158, else_clause; 158, 159; 159, block; 159, 160; 159, 170; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:moved_prop_instance; 163, subscript; 163, 164; 163, 167; 164, call; 164, 165; 164, 166; 165, identifier:get_mapping_dictionary; 166, argument_list; 167, attribute; 167, 168; 167, 169; 168, identifier:prop_instance; 169, identifier:id; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 177; 172, subscript; 172, 173; 172, 174; 173, identifier:properties_id_dict; 174, attribute; 174, 175; 174, 176; 175, identifier:moved_prop_instance; 176, identifier:id; 177, attribute; 177, 178; 177, 179; 178, identifier:prop_instance; 179, identifier:value; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:moved_instance; 184, identifier:update; 185, argument_list; 185, 186; 185, 192; 185, 195; 185, 198; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:name; 188, call; 188, 189; 188, 190; 189, identifier:str; 190, argument_list; 190, 191; 191, identifier:name; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:update_dict; 194, identifier:properties_id_dict; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:bulk; 197, True; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:suppress_kevents; 200, True; 201, return_statement; 201, 202; 202, identifier:moved_instance
def update_part_with_properties(part_instance, moved_instance, name=None): properties_id_dict = dict() for prop_instance in part_instance.properties: if prop_instance._json_data['property_type'] == PropertyType.ATTACHMENT_VALUE: moved_prop = get_mapping_dictionary()[prop_instance.id] if prop_instance.value: attachment_name = prop_instance._json_data['value'].split('/')[-1] with temp_chdir() as target_dir: full_path = os.path.join(target_dir or os.getcwd(), attachment_name) prop_instance.save_as(filename=full_path) moved_prop.upload(full_path) else: moved_prop.clear() elif prop_instance._json_data['property_type'] == PropertyType.REFERENCES_VALUE: if prop_instance.value: moved_prop_instance = get_mapping_dictionary()[prop_instance.id] properties_id_dict[moved_prop_instance.id] = [ref_part.id for ref_part in prop_instance.value] else: moved_prop_instance = get_mapping_dictionary()[prop_instance.id] properties_id_dict[moved_prop_instance.id] = prop_instance.value moved_instance.update(name=str(name), update_dict=properties_id_dict, bulk=True, suppress_kevents=True) return moved_instance
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_checkup; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:peaks; 5, identifier:ecg_integrated; 6, identifier:sample_rate; 7, identifier:rr_buffer; 8, identifier:spk1; 9, identifier:npk1; 10, identifier:threshold; 11, block; 11, 12; 11, 22; 11, 26; 11, 171; 11, 180; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:peaks_amp; 15, list_comprehension; 15, 16; 15, 19; 16, subscript; 16, 17; 16, 18; 17, identifier:ecg_integrated; 18, identifier:peak; 19, for_in_clause; 19, 20; 19, 21; 20, identifier:peak; 21, identifier:peaks; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:definitive_peaks; 25, list:[]; 26, for_statement; 26, 27; 26, 30; 26, 34; 27, pattern_list; 27, 28; 27, 29; 28, identifier:i; 29, identifier:peak; 30, call; 30, 31; 30, 32; 31, identifier:enumerate; 32, argument_list; 32, 33; 33, identifier:peaks; 34, block; 34, 35; 34, 41; 34, 163; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:amp; 38, subscript; 38, 39; 38, 40; 39, identifier:peaks_amp; 40, identifier:i; 41, if_statement; 41, 42; 41, 45; 41, 60; 41, 153; 42, comparison_operator:>; 42, 43; 42, 44; 43, identifier:amp; 44, identifier:threshold; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 52; 48, pattern_list; 48, 49; 48, 50; 48, 51; 49, identifier:definitive_peaks; 50, identifier:spk1; 51, identifier:rr_buffer; 52, call; 52, 53; 52, 54; 53, identifier:_acceptpeak; 54, argument_list; 54, 55; 54, 56; 54, 57; 54, 58; 54, 59; 55, identifier:peak; 56, identifier:amp; 57, identifier:definitive_peaks; 58, identifier:spk1; 59, identifier:rr_buffer; 60, elif_clause; 60, 61; 60, 80; 61, boolean_operator:and; 61, 62; 61, 72; 62, boolean_operator:and; 62, 63; 62, 68; 63, comparison_operator:>; 63, 64; 63, 65; 64, identifier:amp; 65, binary_operator:/; 65, 66; 65, 67; 66, identifier:threshold; 67, integer:2; 68, call; 68, 69; 68, 70; 69, identifier:list; 70, argument_list; 70, 71; 71, identifier:definitive_peaks; 72, comparison_operator:>; 72, 73; 72, 77; 73, call; 73, 74; 73, 75; 74, identifier:len; 75, argument_list; 75, 76; 76, identifier:peaks; 77, binary_operator:+; 77, 78; 77, 79; 78, identifier:i; 79, integer:1; 80, block; 80, 81; 80, 90; 80, 105; 80, 118; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:mean_rr; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:numpy; 87, identifier:mean; 88, argument_list; 88, 89; 89, identifier:rr_buffer; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:last_qrs_ms; 93, binary_operator:*; 93, 94; 93, 101; 94, parenthesized_expression; 94, 95; 95, binary_operator:-; 95, 96; 95, 97; 96, identifier:peak; 97, subscript; 97, 98; 97, 99; 98, identifier:definitive_peaks; 99, unary_operator:-; 99, 100; 100, integer:1; 101, parenthesized_expression; 101, 102; 102, binary_operator:/; 102, 103; 102, 104; 103, integer:1000; 104, identifier:sample_rate; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:last_qrs_to_next_peak; 108, binary_operator:-; 108, 109; 108, 114; 109, subscript; 109, 110; 109, 111; 110, identifier:peaks; 111, binary_operator:+; 111, 112; 111, 113; 112, identifier:i; 113, integer:1; 114, subscript; 114, 115; 114, 116; 115, identifier:definitive_peaks; 116, unary_operator:-; 116, 117; 117, integer:1; 118, if_statement; 118, 119; 118, 128; 118, 143; 119, boolean_operator:and; 119, 120; 119, 123; 120, comparison_operator:>; 120, 121; 120, 122; 121, identifier:last_qrs_ms; 122, integer:360; 123, comparison_operator:>; 123, 124; 123, 125; 124, identifier:last_qrs_to_next_peak; 125, binary_operator:*; 125, 126; 125, 127; 126, float:1.5; 127, identifier:mean_rr; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 135; 131, pattern_list; 131, 132; 131, 133; 131, 134; 132, identifier:definitive_peaks; 133, identifier:spk1; 134, identifier:rr_buffer; 135, call; 135, 136; 135, 137; 136, identifier:_acceptpeak; 137, argument_list; 137, 138; 137, 139; 137, 140; 137, 141; 137, 142; 138, identifier:peak; 139, identifier:amp; 140, identifier:definitive_peaks; 141, identifier:spk1; 142, identifier:rr_buffer; 143, else_clause; 143, 144; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:npk1; 148, call; 148, 149; 148, 150; 149, identifier:_noisepeak; 150, argument_list; 150, 151; 150, 152; 151, identifier:amp; 152, identifier:npk1; 153, else_clause; 153, 154; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:npk1; 158, call; 158, 159; 158, 160; 159, identifier:_noisepeak; 160, argument_list; 160, 161; 160, 162; 161, identifier:amp; 162, identifier:npk1; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:threshold; 166, call; 166, 167; 166, 168; 167, identifier:_buffer_update; 168, argument_list; 168, 169; 168, 170; 169, identifier:npk1; 170, identifier:spk1; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:definitive_peaks; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:numpy; 177, identifier:array; 178, argument_list; 178, 179; 179, identifier:definitive_peaks; 180, return_statement; 180, 181; 181, identifier:definitive_peaks
def _checkup(peaks, ecg_integrated, sample_rate, rr_buffer, spk1, npk1, threshold): peaks_amp = [ecg_integrated[peak] for peak in peaks] definitive_peaks = [] for i, peak in enumerate(peaks): amp = peaks_amp[i] if amp > threshold: definitive_peaks, spk1, rr_buffer = _acceptpeak(peak, amp, definitive_peaks, spk1, rr_buffer) elif amp > threshold / 2 and list(definitive_peaks) and len(peaks) > i + 1: mean_rr = numpy.mean(rr_buffer) last_qrs_ms = (peak - definitive_peaks[-1]) * (1000 / sample_rate) last_qrs_to_next_peak = peaks[i+1] - definitive_peaks[-1] if last_qrs_ms > 360 and last_qrs_to_next_peak > 1.5 * mean_rr: definitive_peaks, spk1, rr_buffer = _acceptpeak(peak, amp, definitive_peaks, spk1, rr_buffer) else: npk1 = _noisepeak(amp, npk1) else: npk1 = _noisepeak(amp, npk1) threshold = _buffer_update(npk1, spk1) definitive_peaks = numpy.array(definitive_peaks) return definitive_peaks
0, module; 0, 1; 0, 175; 0, 182; 0, 197; 0, 206; 0, 213; 0, 220; 0, 237; 0, 291; 0, 305; 0, 309; 0, 317; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:create_napp; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, default_parameter; 5, 6; 5, 7; 6, identifier:meta_package; 7, False; 8, block; 8, 9; 8, 15; 8, 27; 8, 31; 8, 35; 8, 40; 8, 45; 8, 50; 8, 55; 8, 60; 8, 65; 8, 70; 8, 75; 8, 80; 8, 85; 8, 101; 8, 117; 8, 126; 8, 145; 8, 155; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:templates_path; 12, binary_operator:/; 12, 13; 12, 14; 13, identifier:SKEL_PATH; 14, string:'napp-structure/username/napp'; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:ui_templates_path; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:os; 22, identifier:path; 23, identifier:join; 24, argument_list; 24, 25; 24, 26; 25, identifier:templates_path; 26, string:'ui'; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:username; 30, None; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:napp_name; 34, None; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:print; 38, argument_list; 38, 39; 39, string:'--------------------------------------------------------------'; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:print; 43, argument_list; 43, 44; 44, string:'Welcome to the bootstrap process of your NApp.'; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:print; 48, argument_list; 48, 49; 49, string:'--------------------------------------------------------------'; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:print; 53, argument_list; 53, 54; 54, string:'In order to answer both the username and the napp name,'; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:print; 58, argument_list; 58, 59; 59, string:'You must follow this naming rules:'; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:print; 63, argument_list; 63, 64; 64, string:' - name starts with a letter'; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:print; 68, argument_list; 68, 69; 69, string:' - name contains only letters, numbers or underscores'; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:print; 73, argument_list; 73, 74; 74, string:' - at least three characters'; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:print; 78, argument_list; 78, 79; 79, string:'--------------------------------------------------------------'; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:print; 83, argument_list; 83, 84; 84, string:''; 85, while_statement; 85, 86; 85, 93; 86, not_operator; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:cls; 90, identifier:valid_name; 91, argument_list; 91, 92; 92, identifier:username; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:username; 97, call; 97, 98; 97, 99; 98, identifier:input; 99, argument_list; 99, 100; 100, string:'Please, insert your NApps Server username: '; 101, while_statement; 101, 102; 101, 109; 102, not_operator; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:cls; 106, identifier:valid_name; 107, argument_list; 107, 108; 108, identifier:napp_name; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:napp_name; 113, call; 113, 114; 113, 115; 114, identifier:input; 115, argument_list; 115, 116; 116, string:'Please, insert your NApp name: '; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:description; 120, call; 120, 121; 120, 122; 121, identifier:input; 122, argument_list; 122, 123; 123, concatenated_string; 123, 124; 123, 125; 124, string:'Please, insert a brief description for your'; 125, string:'NApp [optional]: '; 126, if_statement; 126, 127; 126, 129; 127, not_operator; 127, 128; 128, identifier:description; 129, block; 129, 130; 129, 142; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:description; 133, expression_list; 133, 134; 133, 139; 134, concatenated_string; 134, 135; 134, 136; 134, 138; 135, string:' context = {'; 136, ERROR; 136, 137; 137, identifier:username; 138, string:': username, '; 139, ERROR; 139, 140; 139, 141; 140, identifier:napp; 141, identifier:napp_name; 142, ERROR; 142, 143; 142, 144; 143, string:'description'; 144, identifier:description; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:os; 149, identifier:makedirs; 150, argument_list; 150, 151; 150, 152; 151, identifier:username; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:exist_ok; 154, True; 155, with_statement; 155, 156; 155, 174; 156, with_clause; 156, 157; 157, with_item; 157, 158; 158, as_pattern; 158, 159; 158, 172; 159, call; 159, 160; 159, 161; 160, identifier:open; 161, argument_list; 161, 162; 161, 171; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:os; 166, identifier:path; 167, identifier:join; 168, argument_list; 168, 169; 168, 170; 169, identifier:username; 170, string:'__init__.py'; 171, string:'w'; 172, as_pattern_target; 172, 173; 173, identifier:init_file; 174, block:; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:init_file; 179, identifier:write; 180, argument_list; 180, 181; 181, string:f'"'; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:os; 186, identifier:makedirs; 187, argument_list; 187, 188; 188, call; 188, 189; 188, 194; 189, attribute; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:os; 192, identifier:path; 193, identifier:join; 194, argument_list; 194, 195; 194, 196; 195, identifier:username; 196, identifier:napp_name; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:templates; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:os; 203, identifier:listdir; 204, argument_list; 204, 205; 205, identifier:templates_path; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:templates; 210, identifier:remove; 211, argument_list; 211, 212; 212, string:'ui'; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:templates; 217, identifier:remove; 218, argument_list; 218, 219; 219, string:'openapi.yml.template'; 220, if_statement; 220, 221; 220, 222; 221, identifier:meta_package; 222, block; 222, 223; 222, 230; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:templates; 227, identifier:remove; 228, argument_list; 228, 229; 229, string:'main.py.template'; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:templates; 234, identifier:remove; 235, argument_list; 235, 236; 236, string:'settings.py.template'; 237, for_statement; 237, 238; 237, 239; 237, 240; 238, identifier:tmp; 239, identifier:templates; 240, block; 240, 241; 240, 261; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:fname; 244, call; 244, 245; 244, 250; 245, attribute; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:os; 248, identifier:path; 249, identifier:join; 250, argument_list; 250, 251; 250, 252; 250, 253; 251, identifier:username; 252, identifier:napp_name; 253, subscript; 253, 254; 253, 260; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:tmp; 257, identifier:rsplit; 258, argument_list; 258, 259; 259, string:'.template'; 260, integer:0; 261, with_statement; 261, 262; 261, 272; 262, with_clause; 262, 263; 263, with_item; 263, 264; 264, as_pattern; 264, 265; 264, 270; 265, call; 265, 266; 265, 267; 266, identifier:open; 267, argument_list; 267, 268; 267, 269; 268, identifier:fname; 269, string:'w'; 270, as_pattern_target; 270, 271; 271, identifier:file; 272, block; 272, 273; 272, 284; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:content; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:cls; 279, identifier:render_template; 280, argument_list; 280, 281; 280, 282; 280, 283; 281, identifier:templates_path; 282, identifier:tmp; 283, identifier:context; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:file; 288, identifier:write; 289, argument_list; 289, 290; 290, identifier:content; 291, if_statement; 291, 292; 291, 294; 292, not_operator; 292, 293; 293, identifier:meta_package; 294, block; 294, 295; 295, expression_statement; 295, 296; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:NAppsManager; 299, identifier:create_ui_structure; 300, argument_list; 300, 301; 300, 302; 300, 303; 300, 304; 301, identifier:username; 302, identifier:napp_name; 303, identifier:ui_templates_path; 304, identifier:context; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 308; 307, identifier:print; 308, argument_list; 309, expression_statement; 309, 310; 310, call; 310, 311; 310, 312; 311, identifier:print; 312, argument_list; 312, 313; 313, concatenated_string; 313, 314; 313, 315; 313, 316; 314, string:f'Congratulations! Your NApp has been bootstrapped!\nNow you '; 315, string:'can go to the directory {username}/{napp_name} and begin to '; 316, string:'code your NApp.'; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 320; 319, identifier:print; 320, argument_list; 320, 321; 321, string:'Have fun!'
def create_napp(cls, meta_package=False): templates_path = SKEL_PATH / 'napp-structure/username/napp' ui_templates_path = os.path.join(templates_path, 'ui') username = None napp_name = None print('--------------------------------------------------------------') print('Welcome to the bootstrap process of your NApp.') print('--------------------------------------------------------------') print('In order to answer both the username and the napp name,') print('You must follow this naming rules:') print(' - name starts with a letter') print(' - name contains only letters, numbers or underscores') print(' - at least three characters') print('--------------------------------------------------------------') print('') while not cls.valid_name(username): username = input('Please, insert your NApps Server username: ') while not cls.valid_name(napp_name): napp_name = input('Please, insert your NApp name: ') description = input('Please, insert a brief description for your' 'NApp [optional]: ') if not description: description = ' context = {'username': username, 'napp': napp_name, 'description': description} os.makedirs(username, exist_ok=True) with open(os.path.join(username, '__init__.py'), 'w') as init_file: init_file.write(f'"') os.makedirs(os.path.join(username, napp_name)) templates = os.listdir(templates_path) templates.remove('ui') templates.remove('openapi.yml.template') if meta_package: templates.remove('main.py.template') templates.remove('settings.py.template') for tmp in templates: fname = os.path.join(username, napp_name, tmp.rsplit('.template')[0]) with open(fname, 'w') as file: content = cls.render_template(templates_path, tmp, context) file.write(content) if not meta_package: NAppsManager.create_ui_structure(username, napp_name, ui_templates_path, context) print() print(f'Congratulations! Your NApp has been bootstrapped!\nNow you ' 'can go to the directory {username}/{napp_name} and begin to ' 'code your NApp.') print('Have fun!')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:match_app_version; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:app; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:label; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:version; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:default; 16, False; 17, block; 17, 18; 17, 94; 17, 103; 17, 114; 18, if_statement; 18, 19; 18, 30; 18, 87; 19, boolean_operator:or; 19, 20; 19, 22; 20, not_operator; 20, 21; 21, identifier:app; 22, boolean_operator:and; 22, 23; 22, 25; 23, not_operator; 23, 24; 24, identifier:label; 25, not_operator; 25, 26; 26, parenthesized_expression; 26, 27; 27, boolean_operator:and; 27, 28; 27, 29; 28, identifier:app; 29, identifier:label; 30, block; 30, 31; 30, 59; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:target_app; 34, list_comprehension; 34, 35; 34, 36; 34, 41; 35, identifier:a; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:a; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:app_versions; 41, if_clause; 41, 42; 42, boolean_operator:or; 42, 43; 42, 51; 43, comparison_operator:==; 43, 44; 43, 50; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:a; 47, identifier:get; 48, argument_list; 48, 49; 49, string:'app'; 50, identifier:app; 51, comparison_operator:==; 51, 52; 51, 58; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:a; 55, identifier:get; 56, argument_list; 56, 57; 57, string:'label'; 58, identifier:label; 59, if_statement; 59, 60; 59, 69; 59, 75; 60, boolean_operator:and; 60, 61; 60, 63; 61, not_operator; 61, 62; 62, identifier:target_app; 63, not_operator; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:isinstance; 66, argument_list; 66, 67; 66, 68; 67, identifier:default; 68, identifier:bool; 69, block; 69, 70; 70, raise_statement; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:NotFoundError; 73, argument_list; 73, 74; 74, string:"Could not find the app or label provided"; 75, elif_clause; 75, 76; 75, 84; 76, boolean_operator:and; 76, 77; 76, 79; 77, not_operator; 77, 78; 78, identifier:target_app; 79, call; 79, 80; 79, 81; 80, identifier:isinstance; 81, argument_list; 81, 82; 81, 83; 82, identifier:default; 83, identifier:bool; 84, block; 84, 85; 85, return_statement; 85, 86; 86, identifier:default; 87, else_clause; 87, 88; 88, block; 88, 89; 89, raise_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:IllegalArgumentError; 92, argument_list; 92, 93; 93, string:"Please provide either app or label"; 94, if_statement; 94, 95; 94, 97; 95, not_operator; 95, 96; 96, identifier:version; 97, block; 97, 98; 98, raise_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:IllegalArgumentError; 101, argument_list; 101, 102; 102, string:"Please provide semantic version string including operand eg: `>=1.0.0`"; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:app_version; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:target_app; 110, integer:0; 111, identifier:get; 112, argument_list; 112, 113; 113, string:'version'; 114, if_statement; 114, 115; 114, 120; 114, 132; 115, boolean_operator:and; 115, 116; 115, 119; 116, boolean_operator:and; 116, 117; 116, 118; 117, identifier:target_app; 118, identifier:app_version; 119, identifier:version; 120, block; 120, 121; 120, 124; 121, import_statement; 121, 122; 122, dotted_name; 122, 123; 123, identifier:semver; 124, return_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:semver; 128, identifier:match; 129, argument_list; 129, 130; 129, 131; 130, identifier:app_version; 131, identifier:version; 132, elif_clause; 132, 133; 132, 135; 133, not_operator; 133, 134; 134, identifier:app_version; 135, block; 135, 136; 136, if_statement; 136, 137; 136, 142; 136, 145; 137, call; 137, 138; 137, 139; 138, identifier:isinstance; 139, argument_list; 139, 140; 139, 141; 140, identifier:default; 141, identifier:bool; 142, block; 142, 143; 143, return_statement; 143, 144; 144, identifier:default; 145, else_clause; 145, 146; 146, block; 146, 147; 147, raise_statement; 147, 148; 148, call; 148, 149; 148, 150; 149, identifier:NotFoundError; 150, argument_list; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, string:"No version found on the app '{}'"; 154, identifier:format; 155, argument_list; 155, 156; 156, call; 156, 157; 156, 162; 157, attribute; 157, 158; 157, 161; 158, subscript; 158, 159; 158, 160; 159, identifier:target_app; 160, integer:0; 161, identifier:get; 162, argument_list; 162, 163; 163, string:'app'
def match_app_version(self, app=None, label=None, version=None, default=False): if not app or not label and not (app and label): target_app = [a for a in self.app_versions if a.get('app') == app or a.get('label') == label] if not target_app and not isinstance(default, bool): raise NotFoundError("Could not find the app or label provided") elif not target_app and isinstance(default, bool): return default else: raise IllegalArgumentError("Please provide either app or label") if not version: raise IllegalArgumentError("Please provide semantic version string including operand eg: `>=1.0.0`") app_version = target_app[0].get('version') if target_app and app_version and version: import semver return semver.match(app_version, version) elif not app_version: if isinstance(default, bool): return default else: raise NotFoundError("No version found on the app '{}'".format(target_app[0].get('app')))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:activities; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:pk; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:scope; 13, None; 14, dictionary_splat_pattern; 14, 15; 15, identifier:kwargs; 16, block; 16, 17; 16, 30; 16, 55; 16, 66; 16, 84; 16, 108; 16, 116; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:request_params; 20, dictionary; 20, 21; 20, 24; 20, 27; 21, pair; 21, 22; 21, 23; 22, string:'id'; 23, identifier:pk; 24, pair; 24, 25; 24, 26; 25, string:'name'; 26, identifier:name; 27, pair; 27, 28; 27, 29; 28, string:'scope'; 29, identifier:scope; 30, if_statement; 30, 31; 30, 45; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:match_app_version; 35, argument_list; 35, 36; 35, 39; 35, 42; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:label; 38, string:'wim'; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:version; 41, string:'>=2.0.0'; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:default; 44, False; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:request_params; 50, identifier:update; 51, argument_list; 51, 52; 52, subscript; 52, 53; 52, 54; 53, identifier:API_EXTRA_PARAMS; 54, string:'activity'; 55, if_statement; 55, 56; 55, 57; 56, identifier:kwargs; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:request_params; 62, identifier:update; 63, argument_list; 63, 64; 64, dictionary_splat; 64, 65; 65, identifier:kwargs; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:response; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:_request; 73, argument_list; 73, 74; 73, 75; 73, 81; 74, string:'GET'; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:_build_url; 79, argument_list; 79, 80; 80, string:'activities'; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:params; 83, identifier:request_params; 84, if_statement; 84, 85; 84, 94; 85, comparison_operator:!=; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:response; 88, identifier:status_code; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:requests; 92, identifier:codes; 93, identifier:ok; 94, block; 94, 95; 95, raise_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:NotFoundError; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, string:"Could not retrieve activities. Server responded with {}"; 102, identifier:format; 103, argument_list; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:str; 106, argument_list; 106, 107; 107, identifier:response; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:data; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:response; 114, identifier:json; 115, argument_list; 116, if_statement; 116, 117; 116, 131; 116, 146; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:match_app_version; 121, argument_list; 121, 122; 121, 125; 121, 128; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:label; 124, string:'wim'; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:version; 127, string:'<2.0.0'; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:default; 130, True; 131, block; 131, 132; 132, return_statement; 132, 133; 133, list_comprehension; 133, 134; 133, 141; 134, call; 134, 135; 134, 136; 135, identifier:Activity; 136, argument_list; 136, 137; 136, 138; 137, identifier:a; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:client; 140, identifier:self; 141, for_in_clause; 141, 142; 141, 143; 142, identifier:a; 143, subscript; 143, 144; 143, 145; 144, identifier:data; 145, string:'results'; 146, else_clause; 146, 147; 147, block; 147, 148; 148, return_statement; 148, 149; 149, list_comprehension; 149, 150; 149, 157; 150, call; 150, 151; 150, 152; 151, identifier:Activity2; 152, argument_list; 152, 153; 152, 154; 153, identifier:a; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:client; 156, identifier:self; 157, for_in_clause; 157, 158; 157, 159; 158, identifier:a; 159, subscript; 159, 160; 159, 161; 160, identifier:data; 161, string:'results'
def activities(self, name=None, pk=None, scope=None, **kwargs): request_params = { 'id': pk, 'name': name, 'scope': scope } if self.match_app_version(label='wim', version='>=2.0.0', default=False): request_params.update(API_EXTRA_PARAMS['activity']) if kwargs: request_params.update(**kwargs) response = self._request('GET', self._build_url('activities'), params=request_params) if response.status_code != requests.codes.ok: raise NotFoundError("Could not retrieve activities. Server responded with {}".format(str(response))) data = response.json() if self.match_app_version(label='wim', version='<2.0.0', default=True): return [Activity(a, client=self) for a in data['results']] else: return [Activity2(a, client=self) for a in data['results']]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 36; 2, function_name:parts; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:pk; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:model; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:category; 16, attribute; 16, 17; 16, 18; 17, identifier:Category; 18, identifier:INSTANCE; 19, default_parameter; 19, 20; 19, 21; 20, identifier:bucket; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:parent; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:activity; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:limit; 30, None; 31, default_parameter; 31, 32; 31, 33; 32, identifier:batch; 33, integer:100; 34, dictionary_splat_pattern; 34, 35; 35, identifier:kwargs; 36, block; 36, 37; 36, 48; 36, 81; 36, 92; 36, 110; 36, 126; 36, 134; 36, 140; 36, 195; 37, if_statement; 37, 38; 37, 43; 38, boolean_operator:and; 38, 39; 38, 40; 39, identifier:limit; 40, comparison_operator:<; 40, 41; 40, 42; 41, identifier:limit; 42, identifier:batch; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:batch; 47, identifier:limit; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:request_params; 51, dictionary; 51, 52; 51, 55; 51, 58; 51, 66; 51, 69; 51, 72; 51, 75; 51, 78; 52, pair; 52, 53; 52, 54; 53, string:'id'; 54, identifier:pk; 55, pair; 55, 56; 55, 57; 56, string:'name'; 57, identifier:name; 58, pair; 58, 59; 58, 60; 59, string:'model'; 60, conditional_expression:if; 60, 61; 60, 64; 60, 65; 61, attribute; 61, 62; 61, 63; 62, identifier:model; 63, identifier:id; 64, identifier:model; 65, None; 66, pair; 66, 67; 66, 68; 67, string:'category'; 68, identifier:category; 69, pair; 69, 70; 69, 71; 70, string:'bucket'; 71, identifier:bucket; 72, pair; 72, 73; 72, 74; 73, string:'parent'; 74, identifier:parent; 75, pair; 75, 76; 75, 77; 76, string:'activity_id'; 77, identifier:activity; 78, pair; 78, 79; 78, 80; 79, string:'limit'; 80, identifier:batch; 81, if_statement; 81, 82; 81, 83; 82, identifier:kwargs; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:request_params; 88, identifier:update; 89, argument_list; 89, 90; 90, dictionary_splat; 90, 91; 91, identifier:kwargs; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:response; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_request; 99, argument_list; 99, 100; 99, 101; 99, 107; 100, string:'GET'; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:_build_url; 105, argument_list; 105, 106; 106, string:'parts'; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:params; 109, identifier:request_params; 110, if_statement; 110, 111; 110, 120; 111, comparison_operator:!=; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:response; 114, identifier:status_code; 115, attribute; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:requests; 118, identifier:codes; 119, identifier:ok; 120, block; 120, 121; 121, raise_statement; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:NotFoundError; 124, argument_list; 124, 125; 125, string:"Could not retrieve parts"; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:data; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:response; 132, identifier:json; 133, argument_list; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:part_results; 137, subscript; 137, 138; 137, 139; 138, identifier:data; 139, string:'results'; 140, if_statement; 140, 141; 140, 149; 141, boolean_operator:and; 141, 142; 141, 143; 142, identifier:batch; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:data; 146, identifier:get; 147, argument_list; 147, 148; 148, string:'next'; 149, block; 149, 150; 150, while_statement; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:data; 153, string:'next'; 154, block; 154, 155; 154, 166; 154, 178; 154, 186; 155, if_statement; 155, 156; 155, 164; 156, boolean_operator:and; 156, 157; 156, 158; 157, identifier:limit; 158, comparison_operator:>=; 158, 159; 158, 163; 159, call; 159, 160; 159, 161; 160, identifier:len; 161, argument_list; 161, 162; 162, identifier:part_results; 163, identifier:limit; 164, block; 164, 165; 165, break_statement; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:response; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:_request; 173, argument_list; 173, 174; 173, 175; 174, string:'GET'; 175, subscript; 175, 176; 175, 177; 176, identifier:data; 177, string:'next'; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:data; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:response; 184, identifier:json; 185, argument_list; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:part_results; 190, identifier:extend; 191, argument_list; 191, 192; 192, subscript; 192, 193; 192, 194; 193, identifier:data; 194, string:'results'; 195, return_statement; 195, 196; 196, call; 196, 197; 196, 198; 197, identifier:PartSet; 198, argument_list; 198, 199; 199, generator_expression; 199, 200; 199, 207; 200, call; 200, 201; 200, 202; 201, identifier:Part; 202, argument_list; 202, 203; 202, 204; 203, identifier:p; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:client; 206, identifier:self; 207, for_in_clause; 207, 208; 207, 209; 208, identifier:p; 209, identifier:part_results
def parts(self, name=None, pk=None, model=None, category=Category.INSTANCE, bucket=None, parent=None, activity=None, limit=None, batch=100, **kwargs): if limit and limit < batch: batch = limit request_params = { 'id': pk, 'name': name, 'model': model.id if model else None, 'category': category, 'bucket': bucket, 'parent': parent, 'activity_id': activity, 'limit': batch } if kwargs: request_params.update(**kwargs) response = self._request('GET', self._build_url('parts'), params=request_params) if response.status_code != requests.codes.ok: raise NotFoundError("Could not retrieve parts") data = response.json() part_results = data['results'] if batch and data.get('next'): while data['next']: if limit and len(part_results) >= limit: break response = self._request('GET', data['next']) data = response.json() part_results.extend(data['results']) return PartSet((Part(p, client=self) for p in part_results))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:create_property; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 15; 3, 18; 3, 21; 4, identifier:self; 5, identifier:model; 6, identifier:name; 7, default_parameter; 7, 8; 7, 9; 8, identifier:description; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:property_type; 12, attribute; 12, 13; 12, 14; 13, identifier:PropertyType; 14, identifier:CHAR_VALUE; 15, default_parameter; 15, 16; 15, 17; 16, identifier:default_value; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:unit; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:options; 23, None; 24, block; 24, 25; 24, 39; 24, 71; 24, 92; 24, 120; 24, 157; 24, 175; 24, 191; 24, 211; 24, 220; 25, if_statement; 25, 26; 25, 33; 26, comparison_operator:!=; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:model; 29, identifier:category; 30, attribute; 30, 31; 30, 32; 31, identifier:Category; 32, identifier:MODEL; 33, block; 33, 34; 34, raise_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:IllegalArgumentError; 37, argument_list; 37, 38; 38, string:"The model should be of category MODEL"; 39, if_statement; 39, 40; 39, 47; 40, not_operator; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:property_type; 44, identifier:endswith; 45, argument_list; 45, 46; 46, string:'_VALUE'; 47, block; 47, 48; 47, 58; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:warnings; 52, identifier:warn; 53, argument_list; 53, 54; 53, 57; 54, concatenated_string; 54, 55; 54, 56; 55, string:"Please use the `PropertyType` enumeration to ensure providing correct "; 56, string:"values to the backend."; 57, identifier:UserWarning; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:property_type; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, string:'{}_VALUE'; 64, identifier:format; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:property_type; 69, identifier:upper; 70, argument_list; 71, if_statement; 71, 72; 71, 79; 72, comparison_operator:not; 72, 73; 72, 74; 73, identifier:property_type; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:PropertyType; 77, identifier:values; 78, argument_list; 79, block; 79, 80; 80, raise_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:IllegalArgumentError; 83, argument_list; 83, 84; 84, call; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, concatenated_string; 86, 87; 86, 88; 87, string:"Please provide a valid propertytype, please use one of `enums.PropertyType`. "; 88, string:"Got: '{}'"; 89, identifier:format; 90, argument_list; 90, 91; 91, identifier:property_type; 92, if_statement; 92, 93; 92, 113; 93, boolean_operator:and; 93, 94; 93, 112; 94, boolean_operator:and; 94, 95; 94, 104; 94, 105; 95, comparison_operator:in; 95, 96; 95, 97; 96, identifier:property_type; 97, tuple; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:PropertyType; 100, identifier:REFERENCE_VALUE; 101, attribute; 101, 102; 101, 103; 102, identifier:PropertyType; 103, identifier:REFERENCES_VALUE; 104, line_continuation:\; 105, call; 105, 106; 105, 107; 106, identifier:isinstance; 107, argument_list; 107, 108; 107, 109; 108, identifier:default_value; 109, tuple; 109, 110; 109, 111; 110, identifier:list; 111, identifier:tuple; 112, identifier:default_value; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:default_value; 117, subscript; 117, 118; 117, 119; 118, identifier:default_value; 119, integer:0; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:data; 123, dictionary; 123, 124; 123, 127; 123, 132; 123, 137; 123, 144; 123, 147; 123, 152; 124, pair; 124, 125; 124, 126; 125, string:"name"; 126, identifier:name; 127, pair; 127, 128; 127, 129; 128, string:"part"; 129, attribute; 129, 130; 129, 131; 130, identifier:model; 131, identifier:id; 132, pair; 132, 133; 132, 134; 133, string:"description"; 134, boolean_operator:or; 134, 135; 134, 136; 135, identifier:description; 136, string:''; 137, pair; 137, 138; 137, 139; 138, string:"property_type"; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:property_type; 142, identifier:upper; 143, argument_list; 144, pair; 144, 145; 144, 146; 145, string:"value"; 146, identifier:default_value; 147, pair; 147, 148; 147, 149; 148, string:"unit"; 149, boolean_operator:or; 149, 150; 149, 151; 150, identifier:unit; 151, string:''; 152, pair; 152, 153; 152, 154; 153, string:"options"; 154, boolean_operator:or; 154, 155; 154, 156; 155, identifier:options; 156, dictionary; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:response; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:_request; 164, argument_list; 164, 165; 164, 166; 164, 172; 165, string:'POST'; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:_build_url; 170, argument_list; 170, 171; 171, string:'properties'; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:json; 174, identifier:data; 175, if_statement; 175, 176; 175, 185; 176, comparison_operator:!=; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:response; 179, identifier:status_code; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:requests; 183, identifier:codes; 184, identifier:created; 185, block; 185, 186; 186, raise_statement; 186, 187; 187, call; 187, 188; 187, 189; 188, identifier:APIError; 189, argument_list; 189, 190; 190, string:"Could not create property"; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:prop; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:Property; 197, identifier:create; 198, argument_list; 198, 199; 198, 208; 199, subscript; 199, 200; 199, 207; 200, subscript; 200, 201; 200, 206; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:response; 204, identifier:json; 205, argument_list; 206, string:'results'; 207, integer:0; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:client; 210, identifier:self; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:model; 216, identifier:properties; 217, identifier:append; 218, argument_list; 218, 219; 219, identifier:prop; 220, return_statement; 220, 221; 221, identifier:prop
def create_property(self, model, name, description=None, property_type=PropertyType.CHAR_VALUE, default_value=None, unit=None, options=None): if model.category != Category.MODEL: raise IllegalArgumentError("The model should be of category MODEL") if not property_type.endswith('_VALUE'): warnings.warn("Please use the `PropertyType` enumeration to ensure providing correct " "values to the backend.", UserWarning) property_type = '{}_VALUE'.format(property_type.upper()) if property_type not in PropertyType.values(): raise IllegalArgumentError("Please provide a valid propertytype, please use one of `enums.PropertyType`. " "Got: '{}'".format(property_type)) if property_type in (PropertyType.REFERENCE_VALUE, PropertyType.REFERENCES_VALUE) and \ isinstance(default_value, (list, tuple)) and default_value: default_value = default_value[0] data = { "name": name, "part": model.id, "description": description or '', "property_type": property_type.upper(), "value": default_value, "unit": unit or '', "options": options or {} } response = self._request('POST', self._build_url('properties'), json=data) if response.status_code != requests.codes.created: raise APIError("Could not create property") prop = Property.create(response.json()['results'][0], client=self) model.properties.append(prop) return prop
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:set_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:request; 6, block; 6, 7; 6, 23; 6, 56; 6, 76; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:sort_request; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:request; 14, identifier:GET; 15, identifier:get; 16, argument_list; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:sort_parameter; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:default_sort; 23, if_statement; 23, 24; 23, 30; 23, 46; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:sort_request; 27, identifier:startswith; 28, argument_list; 28, 29; 29, string:'-'; 30, block; 30, 31; 30, 35; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:sort_order; 34, string:'-'; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:sort_field; 38, subscript; 38, 39; 38, 45; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:sort_request; 42, identifier:split; 43, argument_list; 43, 44; 44, string:'-'; 45, integer:1; 46, else_clause; 46, 47; 47, block; 47, 48; 47, 52; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:sort_order; 51, string:''; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:sort_field; 55, identifier:sort_request; 56, if_statement; 56, 57; 56, 63; 57, not_operator; 57, 58; 58, comparison_operator:in; 58, 59; 58, 60; 59, identifier:sort_field; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_allowed_sort_fields; 63, block; 63, 64; 63, 70; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:sort_order; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:default_sort_order; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:sort_field; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:default_sort_field; 76, return_statement; 76, 77; 77, tuple; 77, 78; 77, 79; 78, identifier:sort_order; 79, identifier:sort_field
def set_sort(self, request): sort_request = request.GET.get(self.sort_parameter, self.default_sort) if sort_request.startswith('-'): sort_order = '-' sort_field = sort_request.split('-')[1] else: sort_order = '' sort_field = sort_request if not sort_field in self._allowed_sort_fields: sort_order = self.default_sort_order sort_field = self.default_sort_field return (sort_order, sort_field)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_next_sort_string; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:field; 6, block; 6, 7; 6, 43; 7, if_statement; 7, 8; 7, 13; 7, 24; 8, comparison_operator:==; 8, 9; 8, 10; 9, identifier:field; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:sort_field; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:next_sort; 17, binary_operator:+; 17, 18; 17, 23; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:toggle_sort_order; 22, argument_list; 23, identifier:field; 24, else_clause; 24, 25; 25, block; 25, 26; 25, 37; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 27, 30; 28, identifier:default_order_for_field; 29, line_continuation:\; 30, subscript; 30, 31; 30, 36; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_allowed_sort_fields; 35, identifier:field; 36, string:'default_direction'; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:next_sort; 40, binary_operator:+; 40, 41; 40, 42; 41, identifier:default_order_for_field; 42, identifier:field; 43, return_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:get_sort_string; 48, argument_list; 48, 49; 49, identifier:next_sort
def get_next_sort_string(self, field): if field == self.sort_field: next_sort = self.toggle_sort_order() + field else: default_order_for_field = \ self._allowed_sort_fields[field]['default_direction'] next_sort = default_order_for_field + field return self.get_sort_string(next_sort)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_sort_indicator; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:field; 6, block; 6, 7; 6, 11; 6, 33; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:indicator; 10, string:''; 11, if_statement; 11, 12; 11, 17; 12, comparison_operator:==; 12, 13; 12, 14; 13, identifier:field; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:sort_field; 17, block; 17, 18; 17, 22; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:indicator; 21, string:'sort-asc'; 22, if_statement; 22, 23; 22, 28; 23, comparison_operator:==; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:sort_order; 27, string:'-'; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:indicator; 32, string:'sort-desc'; 33, return_statement; 33, 34; 34, identifier:indicator
def get_sort_indicator(self, field): indicator = '' if field == self.sort_field: indicator = 'sort-asc' if self.sort_order == '-': indicator = 'sort-desc' return indicator
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_basic_sort_link; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:request; 6, identifier:field; 7, block; 7, 8; 7, 16; 7, 25; 7, 64; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:query_string; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:get_querystring; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:sort_string; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:get_next_sort_string; 23, argument_list; 23, 24; 24, identifier:field; 25, if_statement; 25, 26; 25, 27; 25, 47; 26, identifier:sort_string; 27, block; 27, 28; 27, 38; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:sort_link; 31, binary_operator:+; 31, 32; 31, 37; 32, binary_operator:+; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:request; 35, identifier:path; 36, string:'?'; 37, identifier:sort_string; 38, if_statement; 38, 39; 38, 40; 39, identifier:query_string; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, augmented_assignment:+=; 42, 43; 42, 44; 43, identifier:sort_link; 44, binary_operator:+; 44, 45; 44, 46; 45, string:'&'; 46, identifier:query_string; 47, else_clause; 47, 48; 48, block; 48, 49; 48, 55; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:sort_link; 52, attribute; 52, 53; 52, 54; 53, identifier:request; 54, identifier:path; 55, if_statement; 55, 56; 55, 57; 56, identifier:query_string; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, augmented_assignment:+=; 59, 60; 59, 61; 60, identifier:sort_link; 61, binary_operator:+; 61, 62; 61, 63; 62, string:'?'; 63, identifier:query_string; 64, return_statement; 64, 65; 65, identifier:sort_link
def get_basic_sort_link(self, request, field): query_string = self.get_querystring() sort_string = self.get_next_sort_string(field) if sort_string: sort_link = request.path + '?' + sort_string if query_string: sort_link += '&' + query_string else: sort_link = request.path if query_string: sort_link += '?' + query_string return sort_link
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:download_as_pdf; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 16; 3, 21; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:target_dir; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:pdf_filename; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:paper_size; 13, attribute; 13, 14; 13, 15; 14, identifier:PaperSize; 15, identifier:A4; 16, default_parameter; 16, 17; 16, 18; 17, identifier:paper_orientation; 18, attribute; 18, 19; 18, 20; 19, identifier:PaperOrientation; 20, identifier:PORTRAIT; 21, default_parameter; 21, 22; 21, 23; 22, identifier:include_appendices; 23, False; 24, block; 24, 25; 24, 37; 24, 50; 24, 68; 24, 81; 24, 97; 24, 112; 24, 135; 24, 249; 25, if_statement; 25, 26; 25, 28; 26, not_operator; 26, 27; 27, identifier:pdf_filename; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:pdf_filename; 32, binary_operator:+; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:name; 36, string:'.pdf'; 37, if_statement; 37, 38; 37, 45; 38, not_operator; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:pdf_filename; 42, identifier:endswith; 43, argument_list; 43, 44; 44, string:'.pdf'; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, augmented_assignment:+=; 47, 48; 47, 49; 48, identifier:pdf_filename; 49, string:'.pdf'; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:full_path; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:os; 57, identifier:path; 58, identifier:join; 59, argument_list; 59, 60; 59, 67; 60, boolean_operator:or; 60, 61; 60, 62; 61, identifier:target_dir; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:os; 65, identifier:getcwd; 66, argument_list; 67, identifier:pdf_filename; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:request_params; 71, dictionary; 71, 72; 71, 75; 71, 78; 72, pair; 72, 73; 72, 74; 73, string:'papersize'; 74, identifier:paper_size; 75, pair; 75, 76; 75, 77; 76, string:'orientation'; 77, identifier:paper_orientation; 78, pair; 78, 79; 78, 80; 79, string:'appendices'; 80, identifier:include_appendices; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:url; 84, call; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:_client; 89, identifier:_build_url; 90, argument_list; 90, 91; 90, 92; 91, string:'activity_export'; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:activity_id; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:id; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:response; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:_client; 105, identifier:_request; 106, argument_list; 106, 107; 106, 108; 106, 109; 107, string:'GET'; 108, identifier:url; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:params; 111, identifier:request_params; 112, if_statement; 112, 113; 112, 122; 113, comparison_operator:!=; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:response; 116, identifier:status_code; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:requests; 120, identifier:codes; 121, identifier:ok; 122, block; 122, 123; 123, raise_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:APIError; 126, argument_list; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, string:"Could not download PDF of activity {}"; 130, identifier:format; 131, argument_list; 131, 132; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:name; 135, if_statement; 135, 136; 135, 137; 136, identifier:include_appendices; 137, block; 137, 138; 137, 146; 137, 160; 137, 164; 137, 234; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:data; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:response; 144, identifier:json; 145, argument_list; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:url; 149, call; 149, 150; 149, 151; 150, identifier:urljoin; 151, argument_list; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:_client; 156, identifier:api_root; 157, subscript; 157, 158; 157, 159; 158, identifier:data; 159, string:'download_url'; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:count; 163, integer:0; 164, while_statement; 164, 165; 164, 168; 165, comparison_operator:<=; 165, 166; 165, 167; 166, identifier:count; 167, identifier:ASYNC_TIMEOUT_LIMIT; 168, block; 168, 169; 168, 183; 168, 223; 168, 227; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:response; 172, call; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:_client; 177, identifier:_request; 178, argument_list; 178, 179; 178, 180; 179, string:'GET'; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:url; 182, identifier:url; 183, if_statement; 183, 184; 183, 193; 184, comparison_operator:==; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:response; 187, identifier:status_code; 188, attribute; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:requests; 191, identifier:codes; 192, identifier:ok; 193, block; 193, 194; 193, 222; 194, with_statement; 194, 195; 194, 205; 195, with_clause; 195, 196; 196, with_item; 196, 197; 197, as_pattern; 197, 198; 197, 203; 198, call; 198, 199; 198, 200; 199, identifier:open; 200, argument_list; 200, 201; 200, 202; 201, identifier:full_path; 202, string:'wb'; 203, as_pattern_target; 203, 204; 204, identifier:f; 205, block; 205, 206; 206, for_statement; 206, 207; 206, 208; 206, 214; 207, identifier:chunk; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:response; 211, identifier:iter_content; 212, argument_list; 212, 213; 213, integer:1024; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:f; 219, identifier:write; 220, argument_list; 220, 221; 221, identifier:chunk; 222, return_statement; 223, expression_statement; 223, 224; 224, augmented_assignment:+=; 224, 225; 224, 226; 225, identifier:count; 226, identifier:ASYNC_REFRESH_INTERVAL; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:time; 231, identifier:sleep; 232, argument_list; 232, 233; 233, identifier:ASYNC_REFRESH_INTERVAL; 234, raise_statement; 234, 235; 235, call; 235, 236; 235, 237; 236, identifier:APIError; 237, argument_list; 237, 238; 238, call; 238, 239; 238, 244; 239, attribute; 239, 240; 239, 243; 240, concatenated_string; 240, 241; 240, 242; 241, string:"Could not download PDF of activity {} within the time-out limit of {} "; 242, string:"seconds"; 243, identifier:format; 244, argument_list; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:name; 248, identifier:ASYNC_TIMEOUT_LIMIT; 249, with_statement; 249, 250; 249, 260; 250, with_clause; 250, 251; 251, with_item; 251, 252; 252, as_pattern; 252, 253; 252, 258; 253, call; 253, 254; 253, 255; 254, identifier:open; 255, argument_list; 255, 256; 255, 257; 256, identifier:full_path; 257, string:'wb'; 258, as_pattern_target; 258, 259; 259, identifier:f; 260, block; 260, 261; 261, for_statement; 261, 262; 261, 263; 261, 269; 262, identifier:chunk; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:response; 266, identifier:iter_content; 267, argument_list; 267, 268; 268, integer:1024; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:f; 274, identifier:write; 275, argument_list; 275, 276; 276, identifier:chunk
def download_as_pdf(self, target_dir=None, pdf_filename=None, paper_size=PaperSize.A4, paper_orientation=PaperOrientation.PORTRAIT, include_appendices=False): if not pdf_filename: pdf_filename = self.name + '.pdf' if not pdf_filename.endswith('.pdf'): pdf_filename += '.pdf' full_path = os.path.join(target_dir or os.getcwd(), pdf_filename) request_params = { 'papersize': paper_size, 'orientation': paper_orientation, 'appendices': include_appendices } url = self._client._build_url('activity_export', activity_id=self.id) response = self._client._request('GET', url, params=request_params) if response.status_code != requests.codes.ok: raise APIError("Could not download PDF of activity {}".format(self.name)) if include_appendices: data = response.json() url = urljoin(self._client.api_root, data['download_url']) count = 0 while count <= ASYNC_TIMEOUT_LIMIT: response = self._client._request('GET', url=url) if response.status_code == requests.codes.ok: with open(full_path, 'wb') as f: for chunk in response.iter_content(1024): f.write(chunk) return count += ASYNC_REFRESH_INTERVAL time.sleep(ASYNC_REFRESH_INTERVAL) raise APIError("Could not download PDF of activity {} within the time-out limit of {} " "seconds".format(self.name, ASYNC_TIMEOUT_LIMIT)) with open(full_path, 'wb') as f: for chunk in response.iter_content(1024): f.write(chunk)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:get_project; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 4, default_parameter; 4, 5; 4, 6; 5, identifier:url; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:username; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:password; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:token; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:scope; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:scope_id; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:env_filename; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:status; 27, attribute; 27, 28; 27, 29; 28, identifier:ScopeStatus; 29, identifier:ACTIVE; 30, block; 30, 31; 30, 126; 30, 264; 31, if_statement; 31, 32; 31, 43; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:env; 35, identifier:bool; 36, argument_list; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:kecenv; 39, identifier:KECHAIN_FORCE_ENV_USE; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:default; 42, False; 43, block; 43, 44; 43, 60; 43, 98; 44, if_statement; 44, 45; 44, 54; 45, not_operator; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:os; 49, identifier:getenv; 50, argument_list; 50, 51; 51, attribute; 51, 52; 51, 53; 52, identifier:kecenv; 53, identifier:KECHAIN_URL; 54, block; 54, 55; 55, raise_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:ClientError; 58, argument_list; 58, 59; 59, string:"Error: KECHAIN_URL should be provided as environment variable (use of env vars is enforced)"; 60, if_statement; 60, 61; 60, 90; 61, not_operator; 61, 62; 62, parenthesized_expression; 62, 63; 63, boolean_operator:or; 63, 64; 63, 72; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:os; 67, identifier:getenv; 68, argument_list; 68, 69; 69, attribute; 69, 70; 69, 71; 70, identifier:kecenv; 71, identifier:KECHAIN_TOKEN; 72, parenthesized_expression; 72, 73; 73, boolean_operator:and; 73, 74; 73, 82; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:os; 77, identifier:getenv; 78, argument_list; 78, 79; 79, attribute; 79, 80; 79, 81; 80, identifier:kecenv; 81, identifier:KECHAIN_PASSWORD; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:os; 85, identifier:getenv; 86, argument_list; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:kecenv; 89, identifier:KECHAIN_PASSWORD; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:ClientError; 94, argument_list; 94, 95; 95, concatenated_string; 95, 96; 95, 97; 96, string:"Error: KECHAIN_TOKEN or KECHAIN_USERNAME and KECHAIN_PASSWORD should be provided as "; 97, string:"environment variable(s) (use of env vars is enforced)"; 98, if_statement; 98, 99; 98, 118; 99, not_operator; 99, 100; 100, parenthesized_expression; 100, 101; 101, boolean_operator:or; 101, 102; 101, 110; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:os; 105, identifier:getenv; 106, argument_list; 106, 107; 107, attribute; 107, 108; 107, 109; 108, identifier:kecenv; 109, identifier:KECHAIN_SCOPE; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:os; 113, identifier:getenv; 114, argument_list; 114, 115; 115, attribute; 115, 116; 115, 117; 116, identifier:kecenv; 117, identifier:KECHAIN_SCOPE_ID; 118, block; 118, 119; 119, raise_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:ClientError; 122, argument_list; 122, 123; 123, concatenated_string; 123, 124; 123, 125; 124, string:"Error: KECHAIN_SCOPE or KECHAIN_SCOPE_ID should be provided as environment variable "; 125, string:"(use of env vars is enforced)"; 126, if_statement; 126, 127; 126, 151; 126, 199; 126, 255; 127, boolean_operator:or; 127, 128; 127, 139; 127, 140; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:env; 131, identifier:bool; 132, argument_list; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:kecenv; 135, identifier:KECHAIN_FORCE_ENV_USE; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:default; 138, False; 139, line_continuation:\; 140, not_operator; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:any; 143, argument_list; 143, 144; 144, tuple; 144, 145; 144, 146; 144, 147; 144, 148; 144, 149; 144, 150; 145, identifier:url; 146, identifier:username; 147, identifier:password; 148, identifier:token; 149, identifier:scope; 150, identifier:scope_id; 151, block; 151, 152; 151, 163; 151, 175; 151, 187; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:client; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:Client; 158, identifier:from_env; 159, argument_list; 159, 160; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:env_filename; 162, identifier:env_filename; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:scope_id; 166, call; 166, 167; 166, 168; 167, identifier:env; 168, argument_list; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:kecenv; 171, identifier:KECHAIN_SCOPE_ID; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:default; 174, None; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:scope; 178, call; 178, 179; 178, 180; 179, identifier:env; 180, argument_list; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:kecenv; 183, identifier:KECHAIN_SCOPE; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:default; 186, None; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:status; 190, call; 190, 191; 190, 192; 191, identifier:env; 192, argument_list; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:kecenv; 195, identifier:KECHAIN_SCOPE_STATUS; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:default; 198, None; 199, elif_clause; 199, 200; 199, 230; 200, boolean_operator:and; 200, 201; 200, 217; 200, 218; 201, parenthesized_expression; 201, 202; 202, boolean_operator:and; 202, 203; 202, 213; 203, boolean_operator:and; 203, 204; 203, 205; 204, identifier:url; 205, parenthesized_expression; 205, 206; 206, boolean_operator:or; 206, 207; 206, 211; 207, parenthesized_expression; 207, 208; 208, boolean_operator:and; 208, 209; 208, 210; 209, identifier:username; 210, identifier:password; 211, parenthesized_expression; 211, 212; 212, identifier:token; 213, parenthesized_expression; 213, 214; 214, boolean_operator:or; 214, 215; 214, 216; 215, identifier:scope; 216, identifier:scope_id; 217, line_continuation:\; 218, not_operator; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:env; 222, identifier:bool; 223, argument_list; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:kecenv; 226, identifier:KECHAIN_FORCE_ENV_USE; 227, keyword_argument; 227, 228; 227, 229; 228, identifier:default; 229, False; 230, block; 230, 231; 230, 240; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:client; 234, call; 234, 235; 234, 236; 235, identifier:Client; 236, argument_list; 236, 237; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:url; 239, identifier:url; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:client; 244, identifier:login; 245, argument_list; 245, 246; 245, 249; 245, 252; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:username; 248, identifier:username; 249, keyword_argument; 249, 250; 249, 251; 250, identifier:password; 251, identifier:password; 252, keyword_argument; 252, 253; 252, 254; 253, identifier:token; 254, identifier:token; 255, else_clause; 255, 256; 256, block; 256, 257; 257, raise_statement; 257, 258; 258, call; 258, 259; 258, 260; 259, identifier:ClientError; 260, argument_list; 260, 261; 261, concatenated_string; 261, 262; 261, 263; 262, string:"Error: insufficient arguments to connect to KE-chain. "; 263, string:"See documentation of `pykechain.get_project()`"; 264, if_statement; 264, 265; 264, 266; 264, 279; 265, identifier:scope_id; 266, block; 266, 267; 267, return_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:client; 271, identifier:scope; 272, argument_list; 272, 273; 272, 276; 273, keyword_argument; 273, 274; 273, 275; 274, identifier:pk; 275, identifier:scope_id; 276, keyword_argument; 276, 277; 276, 278; 277, identifier:status; 278, identifier:status; 279, else_clause; 279, 280; 280, block; 280, 281; 281, return_statement; 281, 282; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:client; 285, identifier:scope; 286, argument_list; 286, 287; 286, 290; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:name; 289, identifier:scope; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:status; 292, identifier:status
def get_project(url=None, username=None, password=None, token=None, scope=None, scope_id=None, env_filename=None, status=ScopeStatus.ACTIVE): if env.bool(kecenv.KECHAIN_FORCE_ENV_USE, default=False): if not os.getenv(kecenv.KECHAIN_URL): raise ClientError( "Error: KECHAIN_URL should be provided as environment variable (use of env vars is enforced)") if not (os.getenv(kecenv.KECHAIN_TOKEN) or (os.getenv(kecenv.KECHAIN_PASSWORD) and os.getenv(kecenv.KECHAIN_PASSWORD))): raise ClientError("Error: KECHAIN_TOKEN or KECHAIN_USERNAME and KECHAIN_PASSWORD should be provided as " "environment variable(s) (use of env vars is enforced)") if not (os.getenv(kecenv.KECHAIN_SCOPE) or os.getenv(kecenv.KECHAIN_SCOPE_ID)): raise ClientError("Error: KECHAIN_SCOPE or KECHAIN_SCOPE_ID should be provided as environment variable " "(use of env vars is enforced)") if env.bool(kecenv.KECHAIN_FORCE_ENV_USE, default=False) or \ not any((url, username, password, token, scope, scope_id)): client = Client.from_env(env_filename=env_filename) scope_id = env(kecenv.KECHAIN_SCOPE_ID, default=None) scope = env(kecenv.KECHAIN_SCOPE, default=None) status = env(kecenv.KECHAIN_SCOPE_STATUS, default=None) elif (url and ((username and password) or (token)) and (scope or scope_id)) and \ not env.bool(kecenv.KECHAIN_FORCE_ENV_USE, default=False): client = Client(url=url) client.login(username=username, password=password, token=token) else: raise ClientError("Error: insufficient arguments to connect to KE-chain. " "See documentation of `pykechain.get_project()`") if scope_id: return client.scope(pk=scope_id, status=status) else: return client.scope(name=scope, status=status)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:options; 3, parameters; 3, 4; 4, identifier:cls; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:sorted; 9, generator_expression; 9, 10; 9, 13; 9, 24; 10, tuple; 10, 11; 10, 12; 11, identifier:value; 12, identifier:name; 13, for_in_clause; 13, 14; 13, 17; 14, tuple_pattern; 14, 15; 14, 16; 15, identifier:name; 16, identifier:value; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:cls; 21, identifier:__dict__; 22, identifier:items; 23, argument_list; 24, if_clause; 24, 25; 25, not_operator; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:name; 29, identifier:startswith; 30, argument_list; 30, 31; 31, string:'__'
def options(cls): return sorted((value, name) for (name, value) in cls.__dict__.items() if not name.startswith('__'))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:edit; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:description; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:version; 13, None; 14, dictionary_splat_pattern; 14, 15; 15, identifier:kwargs; 16, block; 16, 17; 16, 26; 16, 52; 16, 78; 16, 104; 16, 115; 16, 142; 16, 163; 16, 172; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:update_dict; 20, dictionary; 20, 21; 21, pair; 21, 22; 21, 23; 22, string:'id'; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:id; 26, if_statement; 26, 27; 26, 28; 27, identifier:name; 28, block; 28, 29; 28, 42; 29, if_statement; 29, 30; 29, 36; 30, not_operator; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:isinstance; 33, argument_list; 33, 34; 33, 35; 34, identifier:name; 35, identifier:str; 36, block; 36, 37; 37, raise_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:IllegalArgumentError; 40, argument_list; 40, 41; 41, string:"name should be provided as a string"; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:update_dict; 46, identifier:update; 47, argument_list; 47, 48; 48, dictionary; 48, 49; 49, pair; 49, 50; 49, 51; 50, string:'name'; 51, identifier:name; 52, if_statement; 52, 53; 52, 54; 53, identifier:description; 54, block; 54, 55; 54, 68; 55, if_statement; 55, 56; 55, 62; 56, not_operator; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:isinstance; 59, argument_list; 59, 60; 59, 61; 60, identifier:description; 61, identifier:str; 62, block; 62, 63; 63, raise_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:IllegalArgumentError; 66, argument_list; 66, 67; 67, string:"description should be provided as a string"; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:update_dict; 72, identifier:update; 73, argument_list; 73, 74; 74, dictionary; 74, 75; 75, pair; 75, 76; 75, 77; 76, string:'description'; 77, identifier:description; 78, if_statement; 78, 79; 78, 80; 79, identifier:version; 80, block; 80, 81; 80, 94; 81, if_statement; 81, 82; 81, 88; 82, not_operator; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:isinstance; 85, argument_list; 85, 86; 85, 87; 86, identifier:version; 87, identifier:str; 88, block; 88, 89; 89, raise_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:IllegalArgumentError; 92, argument_list; 92, 93; 93, string:"description should be provided as a string"; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:update_dict; 98, identifier:update; 99, argument_list; 99, 100; 100, dictionary; 100, 101; 101, pair; 101, 102; 101, 103; 102, string:'script_version'; 103, identifier:version; 104, if_statement; 104, 105; 104, 106; 105, identifier:kwargs; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:update_dict; 111, identifier:update; 112, argument_list; 112, 113; 113, dictionary_splat; 113, 114; 114, identifier:kwargs; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:response; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:_client; 123, identifier:_request; 124, argument_list; 124, 125; 124, 126; 124, 139; 125, string:'PUT'; 126, call; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:_client; 131, identifier:_build_url; 132, argument_list; 132, 133; 132, 134; 133, string:'service'; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:service_id; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:id; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:json; 141, identifier:update_dict; 142, if_statement; 142, 143; 142, 152; 143, comparison_operator:!=; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:response; 146, identifier:status_code; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:requests; 150, identifier:codes; 151, identifier:ok; 152, block; 152, 153; 153, raise_statement; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:APIError; 156, argument_list; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, string:"Could not update Service ({})"; 160, identifier:format; 161, argument_list; 161, 162; 162, identifier:response; 163, if_statement; 163, 164; 163, 165; 164, identifier:name; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:name; 171, identifier:name; 172, if_statement; 172, 173; 172, 174; 173, identifier:version; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:version; 180, identifier:version
def edit(self, name=None, description=None, version=None, **kwargs): update_dict = {'id': self.id} if name: if not isinstance(name, str): raise IllegalArgumentError("name should be provided as a string") update_dict.update({'name': name}) if description: if not isinstance(description, str): raise IllegalArgumentError("description should be provided as a string") update_dict.update({'description': description}) if version: if not isinstance(version, str): raise IllegalArgumentError("description should be provided as a string") update_dict.update({'script_version': version}) if kwargs: update_dict.update(**kwargs) response = self._client._request('PUT', self._client._build_url('service', service_id=self.id), json=update_dict) if response.status_code != requests.codes.ok: raise APIError("Could not update Service ({})".format(response)) if name: self.name = name if version: self.version = version
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:children; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 8, if_statement; 8, 9; 8, 11; 8, 47; 9, not_operator; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 43; 12, if_statement; 12, 13; 12, 17; 13, not_operator; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_cached_children; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_cached_children; 23, call; 23, 24; 23, 25; 24, identifier:list; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_client; 31, identifier:parts; 32, argument_list; 32, 33; 32, 38; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:parent; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:id; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:category; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:category; 43, return_statement; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_cached_children; 47, else_clause; 47, 48; 48, block; 48, 49; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_client; 55, identifier:parts; 56, argument_list; 56, 57; 56, 62; 56, 67; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:parent; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:id; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:category; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:category; 67, dictionary_splat; 67, 68; 68, identifier:kwargs
def children(self, **kwargs): if not kwargs: if not self._cached_children: self._cached_children = list(self._client.parts(parent=self.id, category=self.category)) return self._cached_children else: return self._client.parts(parent=self.id, category=self.category, **kwargs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:update; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:update_dict; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:bulk; 13, True; 14, dictionary_splat_pattern; 14, 15; 15, identifier:kwargs; 16, block; 16, 17; 16, 21; 16, 27; 16, 64; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:action; 20, string:'bulk_update_properties'; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:request_body; 24, call; 24, 25; 24, 26; 25, identifier:dict; 26, argument_list; 27, for_statement; 27, 28; 27, 31; 27, 36; 28, pattern_list; 28, 29; 28, 30; 29, identifier:prop_name_or_id; 30, identifier:property_value; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:update_dict; 34, identifier:items; 35, argument_list; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 42; 37, 49; 38, call; 38, 39; 38, 40; 39, identifier:is_uuid; 40, argument_list; 40, 41; 41, identifier:prop_name_or_id; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:request_body; 47, identifier:prop_name_or_id; 48, identifier:property_value; 49, else_clause; 49, 50; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 63; 53, subscript; 53, 54; 53, 55; 54, identifier:request_body; 55, attribute; 55, 56; 55, 62; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:property; 60, argument_list; 60, 61; 61, identifier:prop_name_or_id; 62, identifier:id; 63, identifier:property_value; 64, if_statement; 64, 65; 64, 77; 64, 171; 65, boolean_operator:and; 65, 66; 65, 67; 66, identifier:bulk; 67, comparison_operator:>; 67, 68; 67, 76; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:update_dict; 74, identifier:keys; 75, argument_list; 76, integer:1; 77, block; 77, 78; 77, 94; 77, 144; 78, if_statement; 78, 79; 78, 80; 79, identifier:name; 80, block; 80, 81; 81, if_statement; 81, 82; 81, 88; 82, not_operator; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:isinstance; 85, argument_list; 85, 86; 85, 87; 86, identifier:name; 87, identifier:str; 88, block; 88, 89; 89, raise_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:IllegalArgumentError; 92, argument_list; 92, 93; 93, string:"Name of the part should be provided as a string"; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:r; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:_client; 102, identifier:_request; 103, argument_list; 103, 104; 103, 105; 103, 118; 103, 136; 104, string:'PUT'; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:_client; 110, identifier:_build_url; 111, argument_list; 111, 112; 111, 113; 112, string:'part'; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:part_id; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:id; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:data; 120, call; 120, 121; 120, 122; 121, identifier:dict; 122, argument_list; 122, 123; 122, 126; 122, 134; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:name; 125, identifier:name; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:properties; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:json; 131, identifier:dumps; 132, argument_list; 132, 133; 133, identifier:request_body; 134, dictionary_splat; 134, 135; 135, identifier:kwargs; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:params; 138, call; 138, 139; 138, 140; 139, identifier:dict; 140, argument_list; 140, 141; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:select_action; 143, identifier:action; 144, if_statement; 144, 145; 144, 154; 145, comparison_operator:!=; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:r; 148, identifier:status_code; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:requests; 152, identifier:codes; 153, identifier:ok; 154, block; 154, 155; 155, raise_statement; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:APIError; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, string:'{}: {}'; 162, identifier:format; 163, argument_list; 163, 164; 163, 168; 164, call; 164, 165; 164, 166; 165, identifier:str; 166, argument_list; 166, 167; 167, identifier:r; 168, attribute; 168, 169; 168, 170; 169, identifier:r; 170, identifier:content; 171, else_clause; 171, 172; 172, block; 172, 173; 173, for_statement; 173, 174; 173, 177; 173, 182; 174, pattern_list; 174, 175; 174, 176; 175, identifier:property_name; 176, identifier:property_value; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:update_dict; 180, identifier:items; 181, argument_list; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 193; 185, attribute; 185, 186; 185, 192; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:property; 190, argument_list; 190, 191; 191, identifier:property_name; 192, identifier:value; 193, identifier:property_value
def update(self, name=None, update_dict=None, bulk=True, **kwargs): action = 'bulk_update_properties' request_body = dict() for prop_name_or_id, property_value in update_dict.items(): if is_uuid(prop_name_or_id): request_body[prop_name_or_id] = property_value else: request_body[self.property(prop_name_or_id).id] = property_value if bulk and len(update_dict.keys()) > 1: if name: if not isinstance(name, str): raise IllegalArgumentError("Name of the part should be provided as a string") r = self._client._request('PUT', self._client._build_url('part', part_id=self.id), data=dict(name=name, properties=json.dumps(request_body), **kwargs), params=dict(select_action=action)) if r.status_code != requests.codes.ok: raise APIError('{}: {}'.format(str(r), r.content)) else: for property_name, property_value in update_dict.items(): self.property(property_name).value = property_value
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:add_with_properties; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:model; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:update_dict; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:bulk; 14, True; 15, dictionary_splat_pattern; 15, 16; 16, identifier:kwargs; 17, block; 17, 18; 17, 32; 17, 40; 17, 44; 17, 50; 17, 87; 18, if_statement; 18, 19; 18, 26; 19, comparison_operator:!=; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:category; 23, attribute; 23, 24; 23, 25; 24, identifier:Category; 25, identifier:INSTANCE; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:APIError; 30, argument_list; 30, 31; 31, string:"Part should be of category INSTANCE"; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:name; 35, boolean_operator:or; 35, 36; 35, 37; 36, identifier:name; 37, attribute; 37, 38; 37, 39; 38, identifier:model; 39, identifier:name; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:action; 43, string:'new_instance_with_properties'; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:properties_update_dict; 47, call; 47, 48; 47, 49; 48, identifier:dict; 49, argument_list; 50, for_statement; 50, 51; 50, 54; 50, 59; 51, pattern_list; 51, 52; 51, 53; 52, identifier:prop_name_or_id; 53, identifier:property_value; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:update_dict; 57, identifier:items; 58, argument_list; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 65; 60, 72; 61, call; 61, 62; 61, 63; 62, identifier:is_uuid; 63, argument_list; 63, 64; 64, identifier:prop_name_or_id; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:properties_update_dict; 70, identifier:prop_name_or_id; 71, identifier:property_value; 72, else_clause; 72, 73; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 86; 76, subscript; 76, 77; 76, 78; 77, identifier:properties_update_dict; 78, attribute; 78, 79; 78, 85; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:model; 82, identifier:property; 83, argument_list; 83, 84; 84, identifier:prop_name_or_id; 85, identifier:id; 86, identifier:property_value; 87, if_statement; 87, 88; 87, 89; 87, 190; 88, identifier:bulk; 89, block; 89, 90; 89, 145; 89, 172; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:r; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:_client; 98, identifier:_request; 99, argument_list; 99, 100; 99, 101; 99, 109; 99, 137; 100, string:'POST'; 101, call; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_client; 106, identifier:_build_url; 107, argument_list; 107, 108; 108, string:'parts'; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:data; 111, call; 111, 112; 111, 113; 112, identifier:dict; 113, argument_list; 113, 114; 113, 117; 113, 122; 113, 127; 113, 135; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:name; 116, identifier:name; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:model; 119, attribute; 119, 120; 119, 121; 120, identifier:model; 121, identifier:id; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:parent; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:id; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:properties; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:json; 132, identifier:dumps; 133, argument_list; 133, 134; 134, identifier:properties_update_dict; 135, dictionary_splat; 135, 136; 136, identifier:kwargs; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:params; 139, call; 139, 140; 139, 141; 140, identifier:dict; 141, argument_list; 141, 142; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:select_action; 144, identifier:action; 145, if_statement; 145, 146; 145, 155; 146, comparison_operator:!=; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:r; 149, identifier:status_code; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:requests; 153, identifier:codes; 154, identifier:created; 155, block; 155, 156; 156, raise_statement; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:APIError; 159, argument_list; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, string:'{}: {}'; 163, identifier:format; 164, argument_list; 164, 165; 164, 169; 165, call; 165, 166; 165, 167; 166, identifier:str; 167, argument_list; 167, 168; 168, identifier:r; 169, attribute; 169, 170; 169, 171; 170, identifier:r; 171, identifier:content; 172, return_statement; 172, 173; 173, call; 173, 174; 173, 175; 174, identifier:Part; 175, argument_list; 175, 176; 175, 185; 176, subscript; 176, 177; 176, 184; 177, subscript; 177, 178; 177, 183; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:r; 181, identifier:json; 182, argument_list; 183, string:'results'; 184, integer:0; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:client; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:_client; 190, else_clause; 190, 191; 191, block; 191, 192; 191, 204; 191, 216; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:new_part; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:add; 199, argument_list; 199, 200; 199, 201; 200, identifier:model; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:name; 203, identifier:name; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:new_part; 208, identifier:update; 209, argument_list; 209, 210; 209, 213; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:update_dict; 212, identifier:update_dict; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:bulk; 215, identifier:bulk; 216, return_statement; 216, 217; 217, identifier:new_part
def add_with_properties(self, model, name=None, update_dict=None, bulk=True, **kwargs): if self.category != Category.INSTANCE: raise APIError("Part should be of category INSTANCE") name = name or model.name action = 'new_instance_with_properties' properties_update_dict = dict() for prop_name_or_id, property_value in update_dict.items(): if is_uuid(prop_name_or_id): properties_update_dict[prop_name_or_id] = property_value else: properties_update_dict[model.property(prop_name_or_id).id] = property_value if bulk: r = self._client._request('POST', self._client._build_url('parts'), data=dict( name=name, model=model.id, parent=self.id, properties=json.dumps(properties_update_dict), **kwargs ), params=dict(select_action=action)) if r.status_code != requests.codes.created: raise APIError('{}: {}'.format(str(r), r.content)) return Part(r.json()['results'][0], client=self._client) else: new_part = self.add(model, name=name) new_part.update(update_dict=update_dict, bulk=bulk) return new_part
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:move; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:target_parent; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:include_children; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:include_instances; 14, True; 15, block; 15, 16; 15, 26; 16, if_statement; 16, 17; 16, 19; 17, not_operator; 17, 18; 18, identifier:name; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:name; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:name; 26, if_statement; 26, 27; 26, 42; 26, 129; 26, 191; 27, boolean_operator:and; 27, 28; 27, 35; 28, comparison_operator:==; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:category; 32, attribute; 32, 33; 32, 34; 33, identifier:Category; 34, identifier:MODEL; 35, comparison_operator:==; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:target_parent; 38, identifier:category; 39, attribute; 39, 40; 39, 41; 40, identifier:Category; 41, identifier:MODEL; 42, block; 42, 43; 42, 61; 42, 121; 42, 127; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:moved_model; 46, call; 46, 47; 46, 48; 47, identifier:relocate_model; 48, argument_list; 48, 49; 48, 52; 48, 55; 48, 58; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:part; 51, identifier:self; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:target_parent; 54, identifier:target_parent; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:name; 57, identifier:name; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:include_children; 60, identifier:include_children; 61, if_statement; 61, 62; 61, 63; 62, identifier:include_instances; 63, block; 63, 64; 63, 75; 63, 86; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:retrieve_instances_to_copied; 67, call; 67, 68; 67, 69; 68, identifier:list; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:instances; 74, argument_list; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:retrieve_parent_instances; 78, call; 78, 79; 78, 80; 79, identifier:list; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:target_parent; 84, identifier:instances; 85, argument_list; 86, for_statement; 86, 87; 86, 88; 86, 89; 87, identifier:parent_instance; 88, identifier:retrieve_parent_instances; 89, block; 89, 90; 90, for_statement; 90, 91; 90, 92; 90, 93; 91, identifier:instance; 92, identifier:retrieve_instances_to_copied; 93, block; 93, 94; 93, 100; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:instance; 98, identifier:populate_descendants; 99, argument_list; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:move_part_instance; 103, argument_list; 103, 104; 103, 107; 103, 110; 103, 113; 103, 118; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:part_instance; 106, identifier:instance; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:target_parent; 109, identifier:parent_instance; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:part_model; 112, identifier:self; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:name; 115, attribute; 115, 116; 115, 117; 116, identifier:instance; 117, identifier:name; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:include_children; 120, identifier:include_children; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:delete; 126, argument_list; 127, return_statement; 127, 128; 128, identifier:moved_model; 129, elif_clause; 129, 130; 129, 145; 130, boolean_operator:and; 130, 131; 130, 138; 131, comparison_operator:==; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:category; 135, attribute; 135, 136; 135, 137; 136, identifier:Category; 137, identifier:INSTANCE; 138, comparison_operator:==; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:target_parent; 141, identifier:category; 142, attribute; 142, 143; 142, 144; 143, identifier:Category; 144, identifier:INSTANCE; 145, block; 145, 146; 145, 164; 145, 189; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:moved_instance; 149, call; 149, 150; 149, 151; 150, identifier:relocate_instance; 151, argument_list; 151, 152; 151, 155; 151, 158; 151, 161; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:part; 154, identifier:self; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:target_parent; 157, identifier:target_parent; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:name; 160, identifier:name; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:include_children; 163, identifier:include_children; 164, try_statement; 164, 165; 164, 172; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:delete; 171, argument_list; 172, except_clause; 172, 173; 172, 174; 173, identifier:APIError; 174, block; 174, 175; 174, 183; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:model_of_instance; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:model; 182, argument_list; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:model_of_instance; 187, identifier:delete; 188, argument_list; 189, return_statement; 189, 190; 190, identifier:moved_instance; 191, else_clause; 191, 192; 192, block; 192, 193; 193, raise_statement; 193, 194; 194, call; 194, 195; 194, 196; 195, identifier:IllegalArgumentError; 196, argument_list; 196, 197; 197, string:'part "{}" and target parent "{}" must have the same category'
def move(self, target_parent, name=None, include_children=True, include_instances=True): if not name: name = self.name if self.category == Category.MODEL and target_parent.category == Category.MODEL: moved_model = relocate_model(part=self, target_parent=target_parent, name=name, include_children=include_children) if include_instances: retrieve_instances_to_copied = list(self.instances()) retrieve_parent_instances = list(target_parent.instances()) for parent_instance in retrieve_parent_instances: for instance in retrieve_instances_to_copied: instance.populate_descendants() move_part_instance(part_instance=instance, target_parent=parent_instance, part_model=self, name=instance.name, include_children=include_children) self.delete() return moved_model elif self.category == Category.INSTANCE and target_parent.category == Category.INSTANCE: moved_instance = relocate_instance(part=self, target_parent=target_parent, name=name, include_children=include_children) try: self.delete() except APIError: model_of_instance = self.model() model_of_instance.delete() return moved_instance else: raise IllegalArgumentError('part "{}" and target parent "{}" must have the same category')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 69; 2, function_name:plot; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 3, 39; 3, 42; 3, 45; 3, 48; 3, 51; 3, 54; 3, 57; 3, 60; 3, 63; 3, 66; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:workflow; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:view; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:depth; 13, unary_operator:-; 13, 14; 14, integer:1; 15, default_parameter; 15, 16; 15, 17; 16, identifier:name; 17, identifier:NONE; 18, default_parameter; 18, 19; 18, 20; 19, identifier:comment; 20, identifier:NONE; 21, default_parameter; 21, 22; 21, 23; 22, identifier:format; 23, identifier:NONE; 24, default_parameter; 24, 25; 24, 26; 25, identifier:engine; 26, identifier:NONE; 27, default_parameter; 27, 28; 27, 29; 28, identifier:encoding; 29, identifier:NONE; 30, default_parameter; 30, 31; 30, 32; 31, identifier:graph_attr; 32, identifier:NONE; 33, default_parameter; 33, 34; 33, 35; 34, identifier:node_attr; 35, identifier:NONE; 36, default_parameter; 36, 37; 36, 38; 37, identifier:edge_attr; 38, identifier:NONE; 39, default_parameter; 39, 40; 39, 41; 40, identifier:body; 41, identifier:NONE; 42, default_parameter; 42, 43; 42, 44; 43, identifier:node_styles; 44, identifier:NONE; 45, default_parameter; 45, 46; 45, 47; 46, identifier:node_data; 47, identifier:NONE; 48, default_parameter; 48, 49; 48, 50; 49, identifier:node_function; 50, identifier:NONE; 51, default_parameter; 51, 52; 51, 53; 52, identifier:edge_data; 53, identifier:NONE; 54, default_parameter; 54, 55; 54, 56; 55, identifier:max_lines; 56, identifier:NONE; 57, default_parameter; 57, 58; 57, 59; 58, identifier:max_width; 59, identifier:NONE; 60, default_parameter; 60, 61; 60, 62; 61, identifier:directory; 62, None; 63, default_parameter; 63, 64; 63, 65; 64, identifier:sites; 65, None; 66, default_parameter; 66, 67; 66, 68; 67, identifier:index; 68, False; 69, block; 69, 70; 69, 101; 69, 144; 69, 164; 69, 171; 69, 178; 69, 201; 69, 207; 69, 222; 69, 278; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:d; 73, dictionary; 73, 74; 73, 77; 73, 80; 73, 83; 73, 86; 73, 89; 73, 92; 73, 95; 73, 98; 74, pair; 74, 75; 74, 76; 75, string:'name'; 76, identifier:name; 77, pair; 77, 78; 77, 79; 78, string:'comment'; 79, identifier:comment; 80, pair; 80, 81; 80, 82; 81, string:'format'; 82, identifier:format; 83, pair; 83, 84; 83, 85; 84, string:'engine'; 85, identifier:engine; 86, pair; 86, 87; 86, 88; 87, string:'encoding'; 88, identifier:encoding; 89, pair; 89, 90; 89, 91; 90, string:'graph_attr'; 91, identifier:graph_attr; 92, pair; 92, 93; 92, 94; 93, string:'node_attr'; 94, identifier:node_attr; 95, pair; 95, 96; 95, 97; 96, string:'edge_attr'; 97, identifier:edge_attr; 98, pair; 98, 99; 98, 100; 99, string:'body'; 100, identifier:body; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:options; 104, dictionary; 104, 105; 104, 126; 104, 129; 104, 132; 104, 135; 104, 138; 104, 141; 105, pair; 105, 106; 105, 107; 106, string:'digraph'; 107, boolean_operator:or; 107, 108; 107, 125; 108, dictionary_comprehension; 108, 109; 108, 112; 108, 121; 109, pair; 109, 110; 109, 111; 110, identifier:k; 111, identifier:v; 112, for_in_clause; 112, 113; 112, 116; 113, pattern_list; 113, 114; 113, 115; 114, identifier:k; 115, identifier:v; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:d; 119, identifier:items; 120, argument_list; 121, if_clause; 121, 122; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:v; 124, identifier:NONE; 125, identifier:NONE; 126, pair; 126, 127; 126, 128; 127, string:'node_styles'; 128, identifier:node_styles; 129, pair; 129, 130; 129, 131; 130, string:'node_data'; 131, identifier:node_data; 132, pair; 132, 133; 132, 134; 133, string:'node_function'; 134, identifier:node_function; 135, pair; 135, 136; 135, 137; 136, string:'edge_data'; 137, identifier:edge_data; 138, pair; 138, 139; 138, 140; 139, string:'max_lines'; 140, identifier:max_lines; 141, pair; 141, 142; 141, 143; 142, string:'max_width'; 143, identifier:max_width; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:options; 147, dictionary_comprehension; 147, 148; 147, 151; 147, 160; 148, pair; 148, 149; 148, 150; 149, identifier:k; 150, identifier:v; 151, for_in_clause; 151, 152; 151, 155; 152, pattern_list; 152, 153; 152, 154; 153, identifier:k; 154, identifier:v; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:options; 158, identifier:items; 159, argument_list; 160, if_clause; 160, 161; 161, comparison_operator:is; 161, 162; 161, 163; 162, identifier:v; 163, identifier:NONE; 164, import_from_statement; 164, 165; 164, 169; 165, relative_import; 165, 166; 165, 167; 166, import_prefix; 167, dotted_name; 167, 168; 168, identifier:drw; 169, dotted_name; 169, 170; 170, identifier:SiteMap; 171, import_from_statement; 171, 172; 171, 176; 172, relative_import; 172, 173; 172, 174; 173, import_prefix; 174, dotted_name; 174, 175; 175, identifier:sol; 176, dotted_name; 176, 177; 177, identifier:Solution; 178, if_statement; 178, 179; 178, 188; 178, 193; 179, boolean_operator:and; 179, 180; 179, 183; 180, comparison_operator:is; 180, 181; 180, 182; 181, identifier:workflow; 182, None; 183, call; 183, 184; 183, 185; 184, identifier:isinstance; 185, argument_list; 185, 186; 185, 187; 186, identifier:self; 187, identifier:Solution; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:workflow; 192, True; 193, else_clause; 193, 194; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:workflow; 198, boolean_operator:or; 198, 199; 198, 200; 199, identifier:workflow; 200, False; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:sitemap; 204, call; 204, 205; 204, 206; 205, identifier:SiteMap; 206, argument_list; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:sitemap; 211, identifier:add_items; 212, argument_list; 212, 213; 212, 214; 212, 217; 212, 220; 213, identifier:self; 214, keyword_argument; 214, 215; 214, 216; 215, identifier:workflow; 216, identifier:workflow; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:depth; 219, identifier:depth; 220, dictionary_splat; 220, 221; 221, identifier:options; 222, if_statement; 222, 223; 222, 224; 223, identifier:view; 224, block; 224, 225; 224, 228; 224, 238; 225, import_statement; 225, 226; 226, dotted_name; 226, 227; 227, identifier:tempfile; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:directory; 231, boolean_operator:or; 231, 232; 231, 233; 232, identifier:directory; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:tempfile; 236, identifier:mkdtemp; 237, argument_list; 238, if_statement; 238, 239; 238, 242; 238, 258; 239, comparison_operator:is; 239, 240; 239, 241; 240, identifier:sites; 241, None; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:sitemap; 247, identifier:render; 248, argument_list; 248, 249; 248, 252; 248, 255; 249, keyword_argument; 249, 250; 249, 251; 250, identifier:directory; 251, identifier:directory; 252, keyword_argument; 252, 253; 252, 254; 253, identifier:view; 254, True; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:index; 257, identifier:index; 258, else_clause; 258, 259; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:sites; 264, identifier:add; 265, argument_list; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:sitemap; 269, identifier:site; 270, argument_list; 270, 271; 270, 272; 270, 275; 271, identifier:directory; 272, keyword_argument; 272, 273; 272, 274; 273, identifier:view; 274, True; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:index; 277, identifier:index; 278, return_statement; 278, 279; 279, identifier:sitemap
def plot(self, workflow=None, view=True, depth=-1, name=NONE, comment=NONE, format=NONE, engine=NONE, encoding=NONE, graph_attr=NONE, node_attr=NONE, edge_attr=NONE, body=NONE, node_styles=NONE, node_data=NONE, node_function=NONE, edge_data=NONE, max_lines=NONE, max_width=NONE, directory=None, sites=None, index=False): d = { 'name': name, 'comment': comment, 'format': format, 'engine': engine, 'encoding': encoding, 'graph_attr': graph_attr, 'node_attr': node_attr, 'edge_attr': edge_attr, 'body': body, } options = { 'digraph': {k: v for k, v in d.items() if v is not NONE} or NONE, 'node_styles': node_styles, 'node_data': node_data, 'node_function': node_function, 'edge_data': edge_data, 'max_lines': max_lines, 'max_width': max_width, } options = {k: v for k, v in options.items() if v is not NONE} from .drw import SiteMap from .sol import Solution if workflow is None and isinstance(self, Solution): workflow = True else: workflow = workflow or False sitemap = SiteMap() sitemap.add_items(self, workflow=workflow, depth=depth, **options) if view: import tempfile directory = directory or tempfile.mkdtemp() if sites is None: sitemap.render(directory=directory, view=True, index=index) else: sites.add(sitemap.site(directory, view=True, index=index)) return sitemap
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:lookup_url; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:url; 6, identifier:klass; 7, default_parameter; 7, 8; 7, 9; 8, identifier:module; 9, None; 10, block; 10, 11; 10, 13; 10, 23; 10, 30; 11, expression_statement; 11, 12; 12, string:''' Gets a proxy reference to the actor indicated by the URL in the parameters. It can be a local reference or a remote direction to another host. This method can be called remotely synchronously. :param srt. url: address that identifies an actor. :param class klass: the class of the actor. :param srt. module: if the actor class is not in the calling module, you need to specify the module where it is here. Also, the *klass* parameter change to be a string. :return: :class:`~.Proxy` of the actor requested. :raises: :class:`NotFoundError`, if the URL specified do not correspond to any actor in the host. :raises: :class:`HostDownError` if the host is down. :raises: :class:`HostError` if there is an error looking for the actor in another server. '''; 13, if_statement; 13, 14; 13, 18; 14, not_operator; 14, 15; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:alive; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:HostDownError; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:aurl; 26, call; 26, 27; 26, 28; 27, identifier:urlparse; 28, argument_list; 28, 29; 29, identifier:url; 30, if_statement; 30, 31; 30, 37; 30, 65; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:is_local; 35, argument_list; 35, 36; 36, identifier:aurl; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 48; 38, 54; 39, comparison_operator:not; 39, 40; 39, 41; 40, identifier:url; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:actors; 46, identifier:keys; 47, argument_list; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:NotFoundError; 52, argument_list; 52, 53; 53, identifier:url; 54, else_clause; 54, 55; 55, block; 55, 56; 56, return_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:Proxy; 59, argument_list; 59, 60; 60, subscript; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:actors; 64, identifier:url; 65, else_clause; 65, 66; 66, block; 66, 67; 67, try_statement; 67, 68; 67, 181; 67, 185; 68, block; 68, 69; 68, 79; 68, 163; 68, 176; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:dispatcher; 72, subscript; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:actors; 76, attribute; 76, 77; 76, 78; 77, identifier:aurl; 78, identifier:scheme; 79, if_statement; 79, 80; 79, 83; 79, 137; 79, 154; 80, comparison_operator:is; 80, 81; 80, 82; 81, identifier:module; 82, None; 83, block; 83, 84; 84, try_statement; 84, 85; 84, 111; 85, block; 85, 86; 85, 103; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:module_; 89, call; 89, 90; 89, 91; 90, identifier:__import__; 91, argument_list; 91, 92; 91, 93; 91, 96; 91, 99; 91, 101; 92, identifier:module; 93, call; 93, 94; 93, 95; 94, identifier:globals; 95, argument_list; 96, call; 96, 97; 96, 98; 97, identifier:locals; 98, argument_list; 99, list:[klass]; 99, 100; 100, identifier:klass; 101, unary_operator:-; 101, 102; 102, integer:1; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:klass_; 106, call; 106, 107; 106, 108; 107, identifier:getattr; 108, argument_list; 108, 109; 108, 110; 109, identifier:module_; 110, identifier:klass; 111, except_clause; 111, 112; 111, 113; 111, 114; 112, identifier:Exception; 113, identifier:e; 114, block; 114, 115; 115, raise_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:HostError; 118, argument_list; 118, 119; 119, binary_operator:+; 119, 120; 119, 133; 120, binary_operator:+; 120, 121; 120, 132; 121, binary_operator:+; 121, 122; 121, 131; 122, binary_operator:+; 122, 123; 122, 130; 123, binary_operator:+; 123, 124; 123, 129; 124, binary_operator:+; 124, 125; 124, 128; 125, binary_operator:+; 125, 126; 125, 127; 126, string:"At lookup_url: "; 127, string:"Import failed for module "; 128, identifier:module; 129, string:", class "; 130, identifier:klass; 131, string:". Check this values for the lookup."; 132, string:" ERROR: "; 133, call; 133, 134; 133, 135; 134, identifier:str; 135, argument_list; 135, 136; 136, identifier:e; 137, elif_clause; 137, 138; 137, 149; 138, call; 138, 139; 138, 140; 139, identifier:isinstance; 140, argument_list; 140, 141; 140, 142; 141, identifier:klass; 142, tuple; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:types; 145, identifier:TypeType; 146, attribute; 146, 147; 146, 148; 147, identifier:types; 148, identifier:ClassType; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:klass_; 153, identifier:klass; 154, else_clause; 154, 155; 155, block; 155, 156; 156, raise_statement; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:HostError; 159, argument_list; 159, 160; 160, binary_operator:+; 160, 161; 160, 162; 161, string:"The class specified to look up is"; 162, string:" not a class."; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:remote_actor; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:actor; 169, identifier:ActorRef; 170, argument_list; 170, 171; 170, 172; 170, 173; 171, identifier:url; 172, identifier:klass_; 173, attribute; 173, 174; 173, 175; 174, identifier:dispatcher; 175, identifier:channel; 176, return_statement; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:Proxy; 179, argument_list; 179, 180; 180, identifier:remote_actor; 181, except_clause; 181, 182; 181, 183; 182, identifier:HostError; 183, block; 183, 184; 184, raise_statement; 185, except_clause; 185, 186; 185, 187; 185, 188; 186, identifier:Exception; 187, identifier:e; 188, block; 188, 189; 189, raise_statement; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:HostError; 192, argument_list; 192, 193; 193, binary_operator:+; 193, 194; 193, 199; 194, binary_operator:+; 194, 195; 194, 198; 195, binary_operator:+; 195, 196; 195, 197; 196, string:"ERROR looking for the actor on another "; 197, string:"server. Hosts must "; 198, string:"be in http to work properly. "; 199, call; 199, 200; 199, 201; 200, identifier:str; 201, argument_list; 201, 202; 202, identifier:e
def lookup_url(self, url, klass, module=None): ''' Gets a proxy reference to the actor indicated by the URL in the parameters. It can be a local reference or a remote direction to another host. This method can be called remotely synchronously. :param srt. url: address that identifies an actor. :param class klass: the class of the actor. :param srt. module: if the actor class is not in the calling module, you need to specify the module where it is here. Also, the *klass* parameter change to be a string. :return: :class:`~.Proxy` of the actor requested. :raises: :class:`NotFoundError`, if the URL specified do not correspond to any actor in the host. :raises: :class:`HostDownError` if the host is down. :raises: :class:`HostError` if there is an error looking for the actor in another server. ''' if not self.alive: raise HostDownError() aurl = urlparse(url) if self.is_local(aurl): if url not in self.actors.keys(): raise NotFoundError(url) else: return Proxy(self.actors[url]) else: try: dispatcher = self.actors[aurl.scheme] if module is not None: try: module_ = __import__(module, globals(), locals(), [klass], -1) klass_ = getattr(module_, klass) except Exception, e: raise HostError("At lookup_url: " + "Import failed for module " + module + ", class " + klass + ". Check this values for the lookup." + " ERROR: " + str(e)) elif isinstance(klass, (types.TypeType, types.ClassType)): klass_ = klass else: raise HostError("The class specified to look up is" + " not a class.") remote_actor = actor.ActorRef(url, klass_, dispatcher.channel) return Proxy(remote_actor) except HostError: raise except Exception, e: raise HostError("ERROR looking for the actor on another " + "server. Hosts must " + "be in http to work properly. " + str(e))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:prepare_rapid_streamflow; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:path_to_rapid_qout; 6, identifier:connection_list_file; 7, block; 7, 8; 7, 21; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:ihg_filename; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, string:'{0}.ihg'; 14, identifier:format; 15, argument_list; 15, 16; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:project_manager; 20, identifier:name; 21, with_statement; 21, 22; 21, 32; 22, with_clause; 22, 23; 23, with_item; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:tmp_chdir; 26, argument_list; 26, 27; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:project_manager; 31, identifier:project_directory; 32, block; 32, 33; 32, 37; 32, 203; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:time_index_range; 36, list:[]; 37, with_statement; 37, 38; 37, 52; 38, with_clause; 38, 39; 39, with_item; 39, 40; 40, as_pattern; 40, 41; 40, 50; 41, call; 41, 42; 41, 43; 42, identifier:RAPIDDataset; 43, argument_list; 43, 44; 43, 45; 44, identifier:path_to_rapid_qout; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:out_tzinfo; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:tz; 50, as_pattern_target; 50, 51; 51, identifier:qout_nc; 52, block; 52, 53; 52, 71; 52, 134; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:time_index_range; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:qout_nc; 59, identifier:get_time_index_range; 60, argument_list; 60, 61; 60, 66; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:date_search_start; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:simulation_start; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:date_search_end; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:simulation_end; 71, if_statement; 71, 72; 71, 78; 72, comparison_operator:>; 72, 73; 72, 77; 73, call; 73, 74; 73, 75; 74, identifier:len; 75, argument_list; 75, 76; 76, identifier:time_index_range; 77, integer:0; 78, block; 78, 79; 78, 93; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:time_array; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:qout_nc; 85, identifier:get_time_array; 86, argument_list; 86, 87; 86, 90; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:return_datetime; 89, True; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:time_index_array; 92, identifier:time_index_range; 93, if_statement; 93, 94; 93, 99; 94, comparison_operator:is; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:simulation_start; 98, None; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 108; 101, comparison_operator:==; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:simulation_start; 105, subscript; 105, 106; 105, 107; 106, identifier:time_array; 107, integer:0; 108, block; 108, 109; 108, 118; 108, 126; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:log; 113, identifier:warning; 114, argument_list; 114, 115; 115, concatenated_string; 115, 116; 115, 117; 116, string:"First timestep of streamflow skipped "; 117, string:"in order for GSSHA to capture the streamflow."; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:time_index_range; 121, subscript; 121, 122; 121, 123; 122, identifier:time_index_range; 123, slice; 123, 124; 123, 125; 124, integer:1; 125, colon; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:time_array; 129, subscript; 129, 130; 129, 131; 130, identifier:time_array; 131, slice; 131, 132; 131, 133; 132, integer:1; 133, colon; 134, if_statement; 134, 135; 134, 141; 134, 194; 135, comparison_operator:>; 135, 136; 135, 140; 136, call; 136, 137; 136, 138; 137, identifier:len; 138, argument_list; 138, 139; 139, identifier:time_index_range; 140, integer:0; 141, block; 141, 142; 141, 148; 141, 162; 141, 178; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:start_datetime; 145, subscript; 145, 146; 145, 147; 146, identifier:time_array; 147, integer:0; 148, if_statement; 148, 149; 148, 154; 149, comparison_operator:is; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:simulation_start; 153, None; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:_update_simulation_start; 160, argument_list; 160, 161; 161, identifier:start_datetime; 162, if_statement; 162, 163; 162, 168; 163, comparison_operator:is; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:simulation_end; 167, None; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:simulation_end; 174, subscript; 174, 175; 174, 176; 175, identifier:time_array; 176, unary_operator:-; 176, 177; 177, integer:1; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:qout_nc; 182, identifier:write_flows_to_gssha_time_series_ihg; 183, argument_list; 183, 184; 183, 185; 183, 186; 183, 189; 184, identifier:ihg_filename; 185, identifier:connection_list_file; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:date_search_start; 188, identifier:start_datetime; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:date_search_end; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:simulation_end; 194, else_clause; 194, 195; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:log; 200, identifier:warning; 201, argument_list; 201, 202; 202, string:"No streamflow values found in time range ..."; 203, if_statement; 203, 204; 203, 210; 203, 260; 204, comparison_operator:>; 204, 205; 204, 209; 205, call; 205, 206; 205, 207; 206, identifier:len; 207, argument_list; 207, 208; 208, identifier:time_index_range; 209, integer:0; 210, block; 210, 211; 210, 217; 210, 232; 210, 241; 210, 254; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:_update_simulation_start_cards; 216, argument_list; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:_update_card; 222, argument_list; 222, 223; 222, 224; 223, string:"END_TIME"; 224, call; 224, 225; 224, 230; 225, attribute; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:simulation_end; 229, identifier:strftime; 230, argument_list; 230, 231; 231, string:"%Y %m %d %H %M"; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:_update_card; 237, argument_list; 237, 238; 237, 239; 237, 240; 238, string:"CHAN_POINT_INPUT"; 239, identifier:ihg_filename; 240, True; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:set_simulation_duration; 246, argument_list; 246, 247; 247, binary_operator:-; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:simulation_end; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:simulation_start; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:_update_gmt; 259, argument_list; 260, else_clause; 260, 261; 261, block; 261, 262; 261, 269; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:os; 266, identifier:remove; 267, argument_list; 267, 268; 268, identifier:ihg_filename; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 276; 271, attribute; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:project_manager; 275, identifier:deleteCard; 276, argument_list; 276, 277; 276, 278; 277, string:'CHAN_POINT_INPUT'; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:db_session
def prepare_rapid_streamflow(self, path_to_rapid_qout, connection_list_file): ihg_filename = '{0}.ihg'.format(self.project_manager.name) with tmp_chdir(self.project_manager.project_directory): time_index_range = [] with RAPIDDataset(path_to_rapid_qout, out_tzinfo=self.tz) as qout_nc: time_index_range = qout_nc.get_time_index_range(date_search_start=self.simulation_start, date_search_end=self.simulation_end) if len(time_index_range) > 0: time_array = qout_nc.get_time_array(return_datetime=True, time_index_array=time_index_range) if self.simulation_start is not None: if self.simulation_start == time_array[0]: log.warning("First timestep of streamflow skipped " "in order for GSSHA to capture the streamflow.") time_index_range = time_index_range[1:] time_array = time_array[1:] if len(time_index_range) > 0: start_datetime = time_array[0] if self.simulation_start is None: self._update_simulation_start(start_datetime) if self.simulation_end is None: self.simulation_end = time_array[-1] qout_nc.write_flows_to_gssha_time_series_ihg(ihg_filename, connection_list_file, date_search_start=start_datetime, date_search_end=self.simulation_end, ) else: log.warning("No streamflow values found in time range ...") if len(time_index_range) > 0: self._update_simulation_start_cards() self._update_card("END_TIME", self.simulation_end.strftime("%Y %m %d %H %M")) self._update_card("CHAN_POINT_INPUT", ihg_filename, True) self.set_simulation_duration(self.simulation_end-self.simulation_start) self._update_gmt() else: os.remove(ihg_filename) self.project_manager.deleteCard('CHAN_POINT_INPUT', self.db_session)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:stencil; 3, parameters; 3, 4; 4, dictionary_splat_pattern; 4, 5; 5, identifier:kwargs; 6, block; 6, 7; 6, 16; 6, 25; 6, 34; 6, 73; 6, 87; 6, 107; 6, 130; 6, 145; 6, 156; 6, 344; 6, 354; 6, 373; 6, 382; 6, 400; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:alnfile; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:kwargs; 13, identifier:get; 14, argument_list; 14, 15; 15, string:'alnfile'; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:gtypefile; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:kwargs; 22, identifier:get; 23, argument_list; 23, 24; 24, string:'gtypefile'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:grpfile; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:kwargs; 31, identifier:get; 32, argument_list; 32, 33; 33, string:'grpfile'; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:grpfile; 37, None; 38, block; 38, 39; 38, 51; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:grpfile2chk; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:os; 46, identifier:path; 47, identifier:join; 48, argument_list; 48, 49; 48, 50; 49, identifier:DATA_DIR; 50, string:'ref.gene2transcripts.tsv'; 51, if_statement; 51, 52; 51, 60; 51, 65; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:os; 56, identifier:path; 57, identifier:exists; 58, argument_list; 58, 59; 59, identifier:grpfile2chk; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:grpfile; 64, identifier:grpfile2chk; 65, else_clause; 65, 66; 66, block; 66, 67; 67, print_statement; 67, 68; 67, 72; 68, chevron; 68, 69; 69, attribute; 69, 70; 69, 71; 70, identifier:sys; 71, identifier:stderr; 72, string:'[gbrs::stencil] A group file is *not* given. Genotype will be stenciled as is.'; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:alnmat; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:emase; 79, identifier:AlignmentPropertyMatrix; 80, argument_list; 80, 81; 80, 84; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:h5file; 83, identifier:alnfile; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:grpfile; 86, identifier:grpfile; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:hid; 90, call; 90, 91; 90, 92; 91, identifier:dict; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:zip; 95, argument_list; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:alnmat; 98, identifier:hname; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:np; 102, identifier:arange; 103, argument_list; 103, 104; 104, attribute; 104, 105; 104, 106; 105, identifier:alnmat; 106, identifier:num_haplotypes; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:gid; 110, call; 110, 111; 110, 112; 111, identifier:dict; 112, argument_list; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:zip; 115, argument_list; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:alnmat; 118, identifier:gname; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:np; 122, identifier:arange; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:len; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 129; 128, identifier:alnmat; 129, identifier:gname; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:gtmask; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:np; 136, identifier:zeros; 137, argument_list; 137, 138; 138, tuple; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:alnmat; 141, identifier:num_haplotypes; 142, attribute; 142, 143; 142, 144; 143, identifier:alnmat; 144, identifier:num_loci; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:gtcall_g; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:dict; 151, identifier:fromkeys; 152, argument_list; 152, 153; 153, attribute; 153, 154; 153, 155; 154, identifier:alnmat; 155, identifier:gname; 156, with_statement; 156, 157; 156, 166; 157, with_clause; 157, 158; 158, with_item; 158, 159; 159, as_pattern; 159, 160; 159, 164; 160, call; 160, 161; 160, 162; 161, identifier:open; 162, argument_list; 162, 163; 163, identifier:gtypefile; 164, as_pattern_target; 164, 165; 165, identifier:fh; 166, block; 166, 167; 167, if_statement; 167, 168; 167, 171; 167, 276; 168, comparison_operator:is; 168, 169; 168, 170; 169, identifier:grpfile; 170, None; 171, block; 171, 172; 171, 183; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:gtcall_t; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:dict; 178, identifier:fromkeys; 179, argument_list; 179, 180; 180, attribute; 180, 181; 180, 182; 181, identifier:alnmat; 182, identifier:lname; 183, for_statement; 183, 184; 183, 185; 183, 190; 184, identifier:curline; 185, call; 185, 186; 185, 187; 186, identifier:dropwhile; 187, argument_list; 187, 188; 187, 189; 188, identifier:is_comment; 189, identifier:fh; 190, block; 190, 191; 190, 204; 190, 214; 190, 220; 190, 235; 190, 250; 190, 262; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:item; 194, call; 194, 195; 194, 202; 195, attribute; 195, 196; 195, 201; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:curline; 199, identifier:rstrip; 200, argument_list; 201, identifier:split; 202, argument_list; 202, 203; 203, string:"\t"; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 209; 206, pattern_list; 206, 207; 206, 208; 207, identifier:g; 208, identifier:gt; 209, subscript; 209, 210; 209, 211; 210, identifier:item; 211, slice; 211, 212; 211, 213; 212, colon; 213, integer:2; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 219; 216, subscript; 216, 217; 216, 218; 217, identifier:gtcall_g; 218, identifier:g; 219, identifier:gt; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:hid2set; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:np; 226, identifier:array; 227, argument_list; 227, 228; 228, list_comprehension; 228, 229; 228, 232; 229, subscript; 229, 230; 229, 231; 230, identifier:hid; 231, identifier:c; 232, for_in_clause; 232, 233; 232, 234; 233, identifier:c; 234, identifier:gt; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:tid2set; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:np; 241, identifier:array; 242, argument_list; 242, 243; 243, subscript; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:alnmat; 246, identifier:groups; 247, subscript; 247, 248; 247, 249; 248, identifier:gid; 249, identifier:g; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 261; 252, subscript; 252, 253; 252, 254; 253, identifier:gtmask; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:np; 257, identifier:meshgrid; 258, argument_list; 258, 259; 258, 260; 259, identifier:hid2set; 260, identifier:tid2set; 261, float:1.0; 262, for_statement; 262, 263; 262, 264; 262, 265; 263, identifier:t; 264, identifier:tid2set; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 275; 268, subscript; 268, 269; 268, 270; 269, identifier:gtcall_t; 270, subscript; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:alnmat; 273, identifier:lname; 274, identifier:t; 275, identifier:gt; 276, else_clause; 276, 277; 277, block; 277, 278; 278, for_statement; 278, 279; 278, 280; 278, 285; 279, identifier:curline; 280, call; 280, 281; 280, 282; 281, identifier:dropwhile; 282, argument_list; 282, 283; 282, 284; 283, identifier:is_comment; 284, identifier:fh; 285, block; 285, 286; 285, 299; 285, 309; 285, 315; 285, 330; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:item; 289, call; 289, 290; 289, 297; 290, attribute; 290, 291; 290, 296; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:curline; 294, identifier:rstrip; 295, argument_list; 296, identifier:split; 297, argument_list; 297, 298; 298, string:"\t"; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 304; 301, pattern_list; 301, 302; 301, 303; 302, identifier:g; 303, identifier:gt; 304, subscript; 304, 305; 304, 306; 305, identifier:item; 306, slice; 306, 307; 306, 308; 307, colon; 308, integer:2; 309, expression_statement; 309, 310; 310, assignment; 310, 311; 310, 314; 311, subscript; 311, 312; 311, 313; 312, identifier:gtcall_g; 313, identifier:g; 314, identifier:gt; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:hid2set; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:np; 321, identifier:array; 322, argument_list; 322, 323; 323, list_comprehension; 323, 324; 323, 327; 324, subscript; 324, 325; 324, 326; 325, identifier:hid; 326, identifier:c; 327, for_in_clause; 327, 328; 327, 329; 328, identifier:c; 329, identifier:gt; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 343; 332, subscript; 332, 333; 332, 334; 333, identifier:gtmask; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:np; 337, identifier:meshgrid; 338, argument_list; 338, 339; 338, 340; 339, identifier:hid2set; 340, subscript; 340, 341; 340, 342; 341, identifier:gid; 342, identifier:g; 343, float:1.0; 344, expression_statement; 344, 345; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:alnmat; 348, identifier:multiply; 349, argument_list; 349, 350; 349, 351; 350, identifier:gtmask; 351, keyword_argument; 351, 352; 351, 353; 352, identifier:axis; 353, integer:2; 354, for_statement; 354, 355; 354, 356; 354, 362; 355, identifier:h; 356, call; 356, 357; 356, 358; 357, identifier:xrange; 358, argument_list; 358, 359; 359, attribute; 359, 360; 359, 361; 360, identifier:alnmat; 361, identifier:num_haplotypes; 362, block; 362, 363; 363, expression_statement; 363, 364; 364, call; 364, 365; 364, 372; 365, attribute; 365, 366; 365, 371; 366, subscript; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:alnmat; 369, identifier:data; 370, identifier:h; 371, identifier:eliminate_zeros; 372, argument_list; 373, expression_statement; 373, 374; 374, assignment; 374, 375; 374, 376; 375, identifier:outfile; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:kwargs; 379, identifier:get; 380, argument_list; 380, 381; 381, string:'outfile'; 382, if_statement; 382, 383; 382, 386; 383, comparison_operator:is; 383, 384; 383, 385; 384, identifier:outfile; 385, None; 386, block; 386, 387; 387, expression_statement; 387, 388; 388, assignment; 388, 389; 388, 390; 389, identifier:outfile; 390, binary_operator:+; 390, 391; 390, 392; 391, string:'gbrs.stenciled.'; 392, call; 392, 393; 392, 398; 393, attribute; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:os; 396, identifier:path; 397, identifier:basename; 398, argument_list; 398, 399; 399, identifier:alnfile; 400, expression_statement; 400, 401; 401, call; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:alnmat; 404, identifier:save; 405, argument_list; 405, 406; 406, keyword_argument; 406, 407; 406, 408; 407, identifier:h5file; 408, identifier:outfile
def stencil(**kwargs): alnfile = kwargs.get('alnfile') gtypefile = kwargs.get('gtypefile') grpfile = kwargs.get('grpfile') if grpfile is None: grpfile2chk = os.path.join(DATA_DIR, 'ref.gene2transcripts.tsv') if os.path.exists(grpfile2chk): grpfile = grpfile2chk else: print >> sys.stderr, '[gbrs::stencil] A group file is *not* given. Genotype will be stenciled as is.' alnmat = emase.AlignmentPropertyMatrix(h5file=alnfile, grpfile=grpfile) hid = dict(zip(alnmat.hname, np.arange(alnmat.num_haplotypes))) gid = dict(zip(alnmat.gname, np.arange(len(alnmat.gname)))) gtmask = np.zeros((alnmat.num_haplotypes, alnmat.num_loci)) gtcall_g = dict.fromkeys(alnmat.gname) with open(gtypefile) as fh: if grpfile is not None: gtcall_t = dict.fromkeys(alnmat.lname) for curline in dropwhile(is_comment, fh): item = curline.rstrip().split("\t") g, gt = item[:2] gtcall_g[g] = gt hid2set = np.array([hid[c] for c in gt]) tid2set = np.array(alnmat.groups[gid[g]]) gtmask[np.meshgrid(hid2set, tid2set)] = 1.0 for t in tid2set: gtcall_t[alnmat.lname[t]] = gt else: for curline in dropwhile(is_comment, fh): item = curline.rstrip().split("\t") g, gt = item[:2] gtcall_g[g] = gt hid2set = np.array([hid[c] for c in gt]) gtmask[np.meshgrid(hid2set, gid[g])] = 1.0 alnmat.multiply(gtmask, axis=2) for h in xrange(alnmat.num_haplotypes): alnmat.data[h].eliminate_zeros() outfile = kwargs.get('outfile') if outfile is None: outfile = 'gbrs.stenciled.' + os.path.basename(alnfile) alnmat.save(h5file=outfile)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:split_tracks; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:lat; 5, identifier:lon; 6, list_splat_pattern; 6, 7; 7, identifier:args; 8, block; 8, 9; 8, 11; 8, 15; 8, 29; 8, 40; 8, 316; 8, 353; 9, expression_statement; 9, 10; 10, string:'''assumes eastward motion'''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:tracks; 14, list:[]; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:lt; 19, identifier:ln; 20, expression_list; 20, 21; 20, 25; 21, list:[lat[0]]; 21, 22; 22, subscript; 22, 23; 22, 24; 23, identifier:lat; 24, integer:0; 25, list:[lon[0]]; 25, 26; 26, subscript; 26, 27; 26, 28; 27, identifier:lon; 28, integer:0; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:zz; 32, list_comprehension; 32, 33; 32, 37; 33, list:[z[0]]; 33, 34; 34, subscript; 34, 35; 34, 36; 35, identifier:z; 36, integer:0; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:z; 39, identifier:args; 40, for_statement; 40, 41; 40, 42; 40, 50; 41, identifier:i; 42, call; 42, 43; 42, 44; 43, identifier:range; 44, argument_list; 44, 45; 44, 46; 45, integer:1; 46, call; 46, 47; 46, 48; 47, identifier:len; 48, argument_list; 48, 49; 49, identifier:lon; 50, block; 50, 51; 50, 60; 50, 79; 50, 94; 50, 112; 50, 130; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:lt; 55, identifier:append; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:lat; 59, identifier:i; 60, for_statement; 60, 61; 60, 64; 60, 69; 61, pattern_list; 61, 62; 61, 63; 62, identifier:z; 63, identifier:a; 64, call; 64, 65; 64, 66; 65, identifier:zip; 66, argument_list; 66, 67; 66, 68; 67, identifier:zz; 68, identifier:args; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:z; 74, identifier:append; 75, argument_list; 75, 76; 76, subscript; 76, 77; 76, 78; 77, identifier:a; 78, identifier:i; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:d1; 82, call; 82, 83; 82, 84; 83, identifier:abs; 84, argument_list; 84, 85; 85, binary_operator:-; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:lon; 88, identifier:i; 89, subscript; 89, 90; 89, 91; 90, identifier:lon; 91, binary_operator:-; 91, 92; 91, 93; 92, identifier:i; 93, integer:1; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:d2; 97, call; 97, 98; 97, 99; 98, identifier:abs; 99, argument_list; 99, 100; 100, binary_operator:-; 100, 101; 100, 109; 101, parenthesized_expression; 101, 102; 102, binary_operator:+; 102, 103; 102, 108; 103, subscript; 103, 104; 103, 105; 104, identifier:lon; 105, binary_operator:-; 105, 106; 105, 107; 106, identifier:i; 107, integer:1; 108, integer:360; 109, subscript; 109, 110; 109, 111; 110, identifier:lon; 111, identifier:i; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:d3; 115, call; 115, 116; 115, 117; 116, identifier:abs; 117, argument_list; 117, 118; 118, binary_operator:-; 118, 119; 118, 124; 119, subscript; 119, 120; 119, 121; 120, identifier:lon; 121, binary_operator:-; 121, 122; 121, 123; 122, identifier:i; 123, integer:1; 124, parenthesized_expression; 124, 125; 125, binary_operator:+; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:lon; 128, identifier:i; 129, integer:360; 130, if_statement; 130, 131; 130, 134; 130, 216; 130, 305; 131, comparison_operator:<; 131, 132; 131, 133; 132, identifier:d2; 133, identifier:d1; 134, block; 134, 135; 134, 146; 134, 177; 134, 189; 134, 203; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:ln; 139, identifier:append; 140, argument_list; 140, 141; 141, binary_operator:-; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:lon; 144, identifier:i; 145, integer:360; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:tracks; 150, identifier:append; 151, argument_list; 151, 152; 152, binary_operator:+; 152, 153; 152, 166; 152, 167; 153, list:[np.array(lt),np.array(ln)]; 153, 154; 153, 160; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:np; 157, identifier:array; 158, argument_list; 158, 159; 159, identifier:lt; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:np; 163, identifier:array; 164, argument_list; 164, 165; 165, identifier:ln; 166, line_continuation:\; 167, list_comprehension; 167, 168; 167, 174; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:np; 171, identifier:array; 172, argument_list; 172, 173; 173, identifier:z; 174, for_in_clause; 174, 175; 174, 176; 175, identifier:z; 176, identifier:zz; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:lt; 180, list:[lat[i-1],lat[i]]; 180, 181; 180, 186; 181, subscript; 181, 182; 181, 183; 182, identifier:lat; 183, binary_operator:-; 183, 184; 183, 185; 184, identifier:i; 185, integer:1; 186, subscript; 186, 187; 186, 188; 187, identifier:lat; 188, identifier:i; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:ln; 192, list:[lon[i-1]+360,lon[i]]; 192, 193; 192, 200; 193, binary_operator:+; 193, 194; 193, 199; 194, subscript; 194, 195; 194, 196; 195, identifier:lon; 196, binary_operator:-; 196, 197; 196, 198; 197, identifier:i; 198, integer:1; 199, integer:360; 200, subscript; 200, 201; 200, 202; 201, identifier:lon; 202, identifier:i; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:zz; 206, list_comprehension; 206, 207; 206, 213; 207, list:[z[i-1]]; 207, 208; 208, subscript; 208, 209; 208, 210; 209, identifier:z; 210, binary_operator:-; 210, 211; 210, 212; 211, identifier:i; 212, integer:1; 213, for_in_clause; 213, 214; 213, 215; 214, identifier:z; 215, identifier:args; 216, elif_clause; 216, 217; 216, 220; 217, comparison_operator:<; 217, 218; 217, 219; 218, identifier:d3; 219, identifier:d1; 220, block; 220, 221; 220, 232; 220, 263; 220, 275; 220, 289; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:ln; 225, identifier:append; 226, argument_list; 226, 227; 227, binary_operator:+; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:lon; 230, identifier:i; 231, integer:360; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:tracks; 236, identifier:append; 237, argument_list; 237, 238; 238, binary_operator:+; 238, 239; 238, 252; 238, 253; 239, list:[np.array(lt),np.array(ln)]; 239, 240; 239, 246; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:np; 243, identifier:array; 244, argument_list; 244, 245; 245, identifier:lt; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:np; 249, identifier:array; 250, argument_list; 250, 251; 251, identifier:ln; 252, line_continuation:\; 253, list_comprehension; 253, 254; 253, 260; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:np; 257, identifier:array; 258, argument_list; 258, 259; 259, identifier:z; 260, for_in_clause; 260, 261; 260, 262; 261, identifier:z; 262, identifier:zz; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:lt; 266, list:[lat[i-1],lat[i]]; 266, 267; 266, 272; 267, subscript; 267, 268; 267, 269; 268, identifier:lat; 269, binary_operator:-; 269, 270; 269, 271; 270, identifier:i; 271, integer:1; 272, subscript; 272, 273; 272, 274; 273, identifier:lat; 274, identifier:i; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:ln; 278, list:[lon[i-1]-360,lon[i]]; 278, 279; 278, 286; 279, binary_operator:-; 279, 280; 279, 285; 280, subscript; 280, 281; 280, 282; 281, identifier:lon; 282, binary_operator:-; 282, 283; 282, 284; 283, identifier:i; 284, integer:1; 285, integer:360; 286, subscript; 286, 287; 286, 288; 287, identifier:lon; 288, identifier:i; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:zz; 292, list_comprehension; 292, 293; 292, 302; 293, list:[z[i-1],z[i]]; 293, 294; 293, 299; 294, subscript; 294, 295; 294, 296; 295, identifier:z; 296, binary_operator:-; 296, 297; 296, 298; 297, identifier:i; 298, integer:1; 299, subscript; 299, 300; 299, 301; 300, identifier:z; 301, identifier:i; 302, for_in_clause; 302, 303; 302, 304; 303, identifier:z; 304, identifier:args; 305, else_clause; 305, 306; 306, block; 306, 307; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:ln; 311, identifier:append; 312, argument_list; 312, 313; 313, subscript; 313, 314; 313, 315; 314, identifier:lon; 315, identifier:i; 316, if_statement; 316, 317; 316, 321; 317, call; 317, 318; 317, 319; 318, identifier:len; 319, argument_list; 319, 320; 320, identifier:lt; 321, block; 321, 322; 322, expression_statement; 322, 323; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:tracks; 326, identifier:append; 327, argument_list; 327, 328; 328, binary_operator:+; 328, 329; 328, 342; 328, 343; 329, list:[np.array(lt),np.array(ln)]; 329, 330; 329, 336; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:np; 333, identifier:array; 334, argument_list; 334, 335; 335, identifier:lt; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:np; 339, identifier:array; 340, argument_list; 340, 341; 341, identifier:ln; 342, line_continuation:\; 343, list_comprehension; 343, 344; 343, 350; 344, call; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:np; 347, identifier:array; 348, argument_list; 348, 349; 349, identifier:z; 350, for_in_clause; 350, 351; 350, 352; 351, identifier:z; 352, identifier:zz; 353, return_statement; 353, 354; 354, identifier:tracks
def split_tracks(lat,lon,*args): '''assumes eastward motion''' tracks = [] lt,ln = [lat[0]],[lon[0]] zz = [[z[0]] for z in args] for i in range(1,len(lon)): lt.append(lat[i]) for z,a in zip(zz,args): z.append(a[i]) d1 = abs(lon[i] - lon[i-1]) d2 = abs((lon[i-1] + 360) - lon[i]) d3 = abs(lon[i-1] - (lon[i] + 360)) if d2 < d1: ln.append(lon[i]-360) tracks.append([np.array(lt),np.array(ln)] \ + [np.array(z) for z in zz]) lt = [lat[i-1],lat[i]] ln = [lon[i-1]+360,lon[i]] zz = [[z[i-1]] for z in args] elif d3 < d1: ln.append(lon[i]+360) tracks.append([np.array(lt),np.array(ln)] \ + [np.array(z) for z in zz]) lt = [lat[i-1],lat[i]] ln = [lon[i-1]-360,lon[i]] zz = [[z[i-1],z[i]] for z in args] else: ln.append(lon[i]) if len(lt): tracks.append([np.array(lt),np.array(ln)] \ + [np.array(z) for z in zz]) return tracks
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:find_loaders; 3, parameters; 3, 4; 3, 5; 4, identifier:scheme; 5, default_parameter; 5, 6; 5, 7; 6, identifier:protocols; 7, None; 8, block; 8, 9; 8, 14; 8, 30; 8, 38; 8, 48; 8, 98; 8, 125; 8, 135; 8, 155; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:matching_groups; 12, list:['plaster.loader_factory']; 12, 13; 13, string:'plaster.loader_factory'; 14, if_statement; 14, 15; 14, 16; 15, identifier:protocols; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, augmented_assignment:+=; 18, 19; 18, 20; 19, identifier:matching_groups; 20, list_comprehension; 20, 21; 20, 27; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, string:'plaster.{0}_loader_factory'; 24, identifier:format; 25, argument_list; 25, 26; 26, identifier:proto; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:proto; 29, identifier:protocols; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:scheme; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:scheme; 36, identifier:lower; 37, argument_list; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:parts; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:scheme; 44, identifier:split; 45, argument_list; 45, 46; 45, 47; 46, string:'+'; 47, integer:1; 48, if_statement; 48, 49; 48, 55; 49, comparison_operator:==; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:parts; 54, integer:2; 55, block; 55, 56; 56, try_statement; 56, 57; 56, 69; 56, 75; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:distro; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:pkg_resources; 64, identifier:get_distribution; 65, argument_list; 65, 66; 66, subscript; 66, 67; 66, 68; 67, identifier:parts; 68, integer:0; 69, except_clause; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:pkg_resources; 72, identifier:DistributionNotFound; 73, block; 73, 74; 74, pass_statement; 75, else_clause; 75, 76; 76, block; 76, 77; 76, 88; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:ep; 80, call; 80, 81; 80, 82; 81, identifier:_find_ep_in_dist; 82, argument_list; 82, 83; 82, 84; 82, 87; 83, identifier:distro; 84, subscript; 84, 85; 84, 86; 85, identifier:parts; 86, integer:1; 87, identifier:matching_groups; 88, if_statement; 88, 89; 88, 90; 89, identifier:ep; 90, block; 90, 91; 91, return_statement; 91, 92; 92, list:[EntryPointLoaderInfo(ep, protocols)]; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:EntryPointLoaderInfo; 95, argument_list; 95, 96; 95, 97; 96, identifier:ep; 97, identifier:protocols; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:possible_entry_points; 101, list_comprehension; 101, 102; 101, 103; 101, 111; 102, identifier:ep; 103, for_in_clause; 103, 104; 103, 105; 104, identifier:ep; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:pkg_resources; 108, identifier:iter_entry_points; 109, argument_list; 109, 110; 110, string:'plaster.loader_factory'; 111, if_clause; 111, 112; 112, boolean_operator:or; 112, 113; 112, 116; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:scheme; 115, None; 116, comparison_operator:==; 116, 117; 116, 118; 117, identifier:scheme; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:ep; 122, identifier:name; 123, identifier:lower; 124, argument_list; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:distros; 128, set_comprehension; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:ep; 131, identifier:dist; 132, for_in_clause; 132, 133; 132, 134; 133, identifier:ep; 134, identifier:possible_entry_points; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:matched_entry_points; 138, call; 138, 139; 138, 140; 139, identifier:list; 140, argument_list; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:filter; 143, argument_list; 143, 144; 143, 145; 144, None; 145, list_comprehension; 145, 146; 145, 152; 146, call; 146, 147; 146, 148; 147, identifier:_find_ep_in_dist; 148, argument_list; 148, 149; 148, 150; 148, 151; 149, identifier:distro; 150, identifier:scheme; 151, identifier:matching_groups; 152, for_in_clause; 152, 153; 152, 154; 153, identifier:distro; 154, identifier:distros; 155, return_statement; 155, 156; 156, list_comprehension; 156, 157; 156, 164; 157, call; 157, 158; 157, 159; 158, identifier:EntryPointLoaderInfo; 159, argument_list; 159, 160; 159, 161; 160, identifier:ep; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:protocols; 163, identifier:protocols; 164, for_in_clause; 164, 165; 164, 166; 165, identifier:ep; 166, identifier:matched_entry_points
def find_loaders(scheme, protocols=None): matching_groups = ['plaster.loader_factory'] if protocols: matching_groups += [ 'plaster.{0}_loader_factory'.format(proto) for proto in protocols ] scheme = scheme.lower() parts = scheme.split('+', 1) if len(parts) == 2: try: distro = pkg_resources.get_distribution(parts[0]) except pkg_resources.DistributionNotFound: pass else: ep = _find_ep_in_dist(distro, parts[1], matching_groups) if ep: return [EntryPointLoaderInfo(ep, protocols)] possible_entry_points = [ ep for ep in pkg_resources.iter_entry_points('plaster.loader_factory') if scheme is None or scheme == ep.name.lower() ] distros = {ep.dist for ep in possible_entry_points} matched_entry_points = list(filter(None, [ _find_ep_in_dist(distro, scheme, matching_groups) for distro in distros ])) return [ EntryPointLoaderInfo(ep, protocols=protocols) for ep in matched_entry_points ]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:combine_dicts; 3, parameters; 3, 4; 3, 6; 3, 9; 4, list_splat_pattern; 4, 5; 5, identifier:dicts; 6, default_parameter; 6, 7; 6, 8; 7, identifier:copy; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:base; 11, None; 12, block; 12, 13; 12, 60; 13, if_statement; 13, 14; 13, 24; 13, 35; 14, boolean_operator:and; 14, 15; 14, 21; 15, comparison_operator:==; 15, 16; 15, 20; 16, call; 16, 17; 16, 18; 17, identifier:len; 18, argument_list; 18, 19; 19, identifier:dicts; 20, integer:1; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:base; 23, None; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:cd; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:dicts; 32, integer:0; 33, identifier:copy; 34, argument_list; 35, else_clause; 35, 36; 36, block; 36, 37; 36, 46; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:cd; 40, conditional_expression:if; 40, 41; 40, 42; 40, 45; 41, dictionary; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:base; 44, None; 45, identifier:base; 46, for_statement; 46, 47; 46, 48; 46, 49; 47, identifier:d; 48, identifier:dicts; 49, block; 49, 50; 50, if_statement; 50, 51; 50, 52; 51, identifier:d; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:cd; 57, identifier:update; 58, argument_list; 58, 59; 59, identifier:d; 60, return_statement; 60, 61; 61, conditional_expression:if; 61, 62; 61, 80; 61, 81; 62, dictionary_comprehension; 62, 63; 62, 71; 63, pair; 63, 64; 63, 65; 64, identifier:k; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:_copy; 68, identifier:deepcopy; 69, argument_list; 69, 70; 70, identifier:v; 71, for_in_clause; 71, 72; 71, 75; 72, pattern_list; 72, 73; 72, 74; 73, identifier:k; 74, identifier:v; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:cd; 78, identifier:items; 79, argument_list; 80, identifier:copy; 81, identifier:cd
def combine_dicts(*dicts, copy=False, base=None): if len(dicts) == 1 and base is None: cd = dicts[0].copy() else: cd = {} if base is None else base for d in dicts: if d: cd.update(d) return {k: _copy.deepcopy(v) for k, v in cd.items()} if copy else cd
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:kk_dict; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:kk; 6, dictionary_splat_pattern; 6, 7; 7, identifier:adict; 8, block; 8, 9; 8, 62; 9, for_statement; 9, 10; 9, 11; 9, 12; 10, identifier:k; 11, identifier:kk; 12, block; 12, 13; 13, if_statement; 13, 14; 13, 19; 13, 44; 13, 54; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:k; 18, identifier:dict; 19, block; 19, 20; 19, 37; 20, if_statement; 20, 21; 20, 31; 21, not_operator; 21, 22; 22, call; 22, 23; 22, 29; 23, attribute; 23, 24; 23, 28; 24, call; 24, 25; 24, 26; 25, identifier:set; 26, argument_list; 26, 27; 27, identifier:k; 28, identifier:isdisjoint; 29, argument_list; 29, 30; 30, identifier:adict; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:ValueError; 35, argument_list; 35, 36; 36, string:'keyword argument repeated'; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:adict; 41, identifier:update; 42, argument_list; 42, 43; 43, identifier:k; 44, elif_clause; 44, 45; 44, 48; 45, comparison_operator:in; 45, 46; 45, 47; 46, identifier:k; 47, identifier:adict; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:ValueError; 52, argument_list; 52, 53; 53, string:'keyword argument repeated'; 54, else_clause; 54, 55; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:adict; 60, identifier:k; 61, identifier:k; 62, return_statement; 62, 63; 63, identifier:adict
def kk_dict(*kk, **adict): for k in kk: if isinstance(k, dict): if not set(k).isdisjoint(adict): raise ValueError('keyword argument repeated') adict.update(k) elif k in adict: raise ValueError('keyword argument repeated') else: adict[k] = k return adict
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:map_dict; 3, parameters; 3, 4; 3, 5; 3, 7; 3, 10; 4, identifier:key_map; 5, list_splat_pattern; 5, 6; 6, identifier:dicts; 7, default_parameter; 7, 8; 7, 9; 8, identifier:copy; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:base; 12, None; 13, block; 13, 14; 13, 26; 13, 32; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:it; 17, call; 17, 18; 17, 25; 18, attribute; 18, 19; 18, 24; 19, call; 19, 20; 19, 21; 20, identifier:combine_dicts; 21, argument_list; 21, 22; 22, list_splat; 22, 23; 23, identifier:dicts; 24, identifier:items; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:get; 29, attribute; 29, 30; 29, 31; 30, identifier:key_map; 31, identifier:get; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:combine_dicts; 35, argument_list; 35, 36; 35, 49; 35, 52; 36, dictionary_comprehension; 36, 37; 36, 44; 37, pair; 37, 38; 37, 43; 38, call; 38, 39; 38, 40; 39, identifier:get; 40, argument_list; 40, 41; 40, 42; 41, identifier:k; 42, identifier:k; 43, identifier:v; 44, for_in_clause; 44, 45; 44, 48; 45, pattern_list; 45, 46; 45, 47; 46, identifier:k; 47, identifier:v; 48, identifier:it; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:copy; 51, identifier:copy; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:base; 54, identifier:base
def map_dict(key_map, *dicts, copy=False, base=None): it = combine_dicts(*dicts).items() get = key_map.get return combine_dicts({get(k, k): v for k, v in it}, copy=copy, base=base)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:map_list; 3, parameters; 3, 4; 3, 5; 3, 7; 3, 10; 4, identifier:key_map; 5, list_splat_pattern; 5, 6; 6, identifier:inputs; 7, default_parameter; 7, 8; 7, 9; 8, identifier:copy; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:base; 12, None; 13, block; 13, 14; 13, 23; 13, 74; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:d; 17, conditional_expression:if; 17, 18; 17, 19; 17, 22; 18, dictionary; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:base; 21, None; 22, identifier:base; 23, for_statement; 23, 24; 23, 27; 23, 32; 24, pattern_list; 24, 25; 24, 26; 25, identifier:m; 26, identifier:v; 27, call; 27, 28; 27, 29; 28, identifier:zip; 29, argument_list; 29, 30; 29, 31; 30, identifier:key_map; 31, identifier:inputs; 32, block; 32, 33; 33, if_statement; 33, 34; 33, 39; 33, 49; 33, 66; 34, call; 34, 35; 34, 36; 35, identifier:isinstance; 36, argument_list; 36, 37; 36, 38; 37, identifier:m; 38, identifier:dict; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:map_dict; 43, argument_list; 43, 44; 43, 45; 43, 46; 44, identifier:m; 45, identifier:v; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:base; 48, identifier:d; 49, elif_clause; 49, 50; 49, 55; 50, call; 50, 51; 50, 52; 51, identifier:isinstance; 52, argument_list; 52, 53; 52, 54; 53, identifier:m; 54, identifier:list; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:map_list; 59, argument_list; 59, 60; 59, 61; 59, 63; 60, identifier:m; 61, list_splat; 61, 62; 62, identifier:v; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:base; 65, identifier:d; 66, else_clause; 66, 67; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:d; 72, identifier:m; 73, identifier:v; 74, return_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:combine_dicts; 77, argument_list; 77, 78; 77, 81; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:copy; 80, identifier:copy; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:base; 83, identifier:d
def map_list(key_map, *inputs, copy=False, base=None): d = {} if base is None else base for m, v in zip(key_map, inputs): if isinstance(m, dict): map_dict(m, v, base=d) elif isinstance(m, list): map_list(m, *v, base=d) else: d[m] = v return combine_dicts(copy=copy, base=d)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:selector; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:keys; 5, identifier:dictionary; 6, default_parameter; 6, 7; 6, 8; 7, identifier:copy; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:output_type; 11, string:'dict'; 12, default_parameter; 12, 13; 12, 14; 13, identifier:allow_miss; 14, False; 15, block; 15, 16; 15, 38; 15, 93; 16, if_statement; 16, 17; 16, 19; 16, 27; 17, not_operator; 17, 18; 18, identifier:allow_miss; 19, block; 19, 20; 20, function_definition; 20, 21; 20, 22; 20, 24; 21, function_name:check; 22, parameters; 22, 23; 23, identifier:key; 24, block; 24, 25; 25, return_statement; 25, 26; 26, True; 27, else_clause; 27, 28; 28, block; 28, 29; 29, function_definition; 29, 30; 29, 31; 29, 33; 30, function_name:check; 31, parameters; 31, 32; 32, identifier:key; 33, block; 33, 34; 34, return_statement; 34, 35; 35, comparison_operator:in; 35, 36; 35, 37; 36, identifier:key; 37, identifier:dictionary; 38, if_statement; 38, 39; 38, 42; 38, 68; 39, comparison_operator:==; 39, 40; 39, 41; 40, identifier:output_type; 41, string:'list'; 42, block; 42, 43; 42, 58; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:res; 46, list_comprehension; 46, 47; 46, 50; 46, 53; 47, subscript; 47, 48; 47, 49; 48, identifier:dictionary; 49, identifier:k; 50, for_in_clause; 50, 51; 50, 52; 51, identifier:k; 52, identifier:keys; 53, if_clause; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:check; 56, argument_list; 56, 57; 57, identifier:k; 58, return_statement; 58, 59; 59, conditional_expression:if; 59, 60; 59, 66; 59, 67; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:_copy; 63, identifier:deepcopy; 64, argument_list; 64, 65; 65, identifier:res; 66, identifier:copy; 67, identifier:res; 68, elif_clause; 68, 69; 68, 72; 69, comparison_operator:==; 69, 70; 69, 71; 70, identifier:output_type; 71, string:'values'; 72, block; 72, 73; 73, return_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:bypass; 76, argument_list; 76, 77; 76, 90; 77, list_splat; 77, 78; 78, list_comprehension; 78, 79; 78, 82; 78, 85; 79, subscript; 79, 80; 79, 81; 80, identifier:dictionary; 81, identifier:k; 82, for_in_clause; 82, 83; 82, 84; 83, identifier:k; 84, identifier:keys; 85, if_clause; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:check; 88, argument_list; 88, 89; 89, identifier:k; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:copy; 92, identifier:copy; 93, return_statement; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:bypass; 96, argument_list; 96, 97; 96, 111; 97, dictionary_comprehension; 97, 98; 97, 103; 97, 106; 98, pair; 98, 99; 98, 100; 99, identifier:k; 100, subscript; 100, 101; 100, 102; 101, identifier:dictionary; 102, identifier:k; 103, for_in_clause; 103, 104; 103, 105; 104, identifier:k; 105, identifier:keys; 106, if_clause; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:check; 109, argument_list; 109, 110; 110, identifier:k; 111, keyword_argument; 111, 112; 111, 113; 112, identifier:copy; 113, identifier:copy
def selector(keys, dictionary, copy=False, output_type='dict', allow_miss=False): if not allow_miss: def check(key): return True else: def check(key): return key in dictionary if output_type == 'list': res = [dictionary[k] for k in keys if check(k)] return _copy.deepcopy(res) if copy else res elif output_type == 'values': return bypass(*[dictionary[k] for k in keys if check(k)], copy=copy) return bypass({k: dictionary[k] for k in keys if check(k)}, copy=copy)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:difference; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:others; 7, block; 7, 8; 7, 10; 7, 18; 7, 24; 7, 30; 7, 92; 7, 98; 8, expression_statement; 8, 9; 9, identifier:r; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:result; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:__copy__; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:_elements; 21, attribute; 21, 22; 21, 23; 22, identifier:result; 23, identifier:_elements; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:_total; 27, attribute; 27, 28; 27, 29; 28, identifier:result; 29, identifier:_total; 30, for_statement; 30, 31; 30, 32; 30, 39; 31, identifier:other; 32, call; 32, 33; 32, 34; 33, identifier:map; 34, argument_list; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_as_multiset; 38, identifier:others; 39, block; 39, 40; 40, for_statement; 40, 41; 40, 44; 40, 49; 41, pattern_list; 41, 42; 41, 43; 42, identifier:element; 43, identifier:multiplicity; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:other; 47, identifier:items; 48, argument_list; 49, block; 49, 50; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:in; 51, 52; 51, 53; 52, identifier:element; 53, identifier:_elements; 54, block; 54, 55; 54, 61; 54, 67; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:old_multiplicity; 58, subscript; 58, 59; 58, 60; 59, identifier:_elements; 60, identifier:element; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:new_multiplicity; 64, binary_operator:-; 64, 65; 64, 66; 65, identifier:old_multiplicity; 66, identifier:multiplicity; 67, if_statement; 67, 68; 67, 71; 67, 82; 68, comparison_operator:>; 68, 69; 68, 70; 69, identifier:new_multiplicity; 70, integer:0; 71, block; 71, 72; 71, 78; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:_elements; 76, identifier:element; 77, identifier:new_multiplicity; 78, expression_statement; 78, 79; 79, augmented_assignment:-=; 79, 80; 79, 81; 80, identifier:_total; 81, identifier:multiplicity; 82, else_clause; 82, 83; 83, block; 83, 84; 83, 88; 84, delete_statement; 84, 85; 85, subscript; 85, 86; 85, 87; 86, identifier:_elements; 87, identifier:element; 88, expression_statement; 88, 89; 89, augmented_assignment:-=; 89, 90; 89, 91; 90, identifier:_total; 91, identifier:old_multiplicity; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:result; 96, identifier:_total; 97, identifier:_total; 98, return_statement; 98, 99; 99, identifier:result
def difference(self, *others): r result = self.__copy__() _elements = result._elements _total = result._total for other in map(self._as_multiset, others): for element, multiplicity in other.items(): if element in _elements: old_multiplicity = _elements[element] new_multiplicity = old_multiplicity - multiplicity if new_multiplicity > 0: _elements[element] = new_multiplicity _total -= multiplicity else: del _elements[element] _total -= old_multiplicity result._total = _total return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:union; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:others; 7, block; 7, 8; 7, 10; 7, 18; 7, 24; 7, 30; 7, 77; 7, 83; 8, expression_statement; 8, 9; 9, identifier:r; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:result; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:__copy__; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:_elements; 21, attribute; 21, 22; 21, 23; 22, identifier:result; 23, identifier:_elements; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:_total; 27, attribute; 27, 28; 27, 29; 28, identifier:result; 29, identifier:_total; 30, for_statement; 30, 31; 30, 32; 30, 39; 31, identifier:other; 32, call; 32, 33; 32, 34; 33, identifier:map; 34, argument_list; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_as_mapping; 38, identifier:others; 39, block; 39, 40; 40, for_statement; 40, 41; 40, 44; 40, 49; 41, pattern_list; 41, 42; 41, 43; 42, identifier:element; 43, identifier:multiplicity; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:other; 47, identifier:items; 48, argument_list; 49, block; 49, 50; 49, 60; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:old_multiplicity; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:_elements; 56, identifier:get; 57, argument_list; 57, 58; 57, 59; 58, identifier:element; 59, integer:0; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:>; 61, 62; 61, 63; 62, identifier:multiplicity; 63, identifier:old_multiplicity; 64, block; 64, 65; 64, 71; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:_elements; 69, identifier:element; 70, identifier:multiplicity; 71, expression_statement; 71, 72; 72, augmented_assignment:+=; 72, 73; 72, 74; 73, identifier:_total; 74, binary_operator:-; 74, 75; 74, 76; 75, identifier:multiplicity; 76, identifier:old_multiplicity; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:result; 81, identifier:_total; 82, identifier:_total; 83, return_statement; 83, 84; 84, identifier:result
def union(self, *others): r result = self.__copy__() _elements = result._elements _total = result._total for other in map(self._as_mapping, others): for element, multiplicity in other.items(): old_multiplicity = _elements.get(element, 0) if multiplicity > old_multiplicity: _elements[element] = multiplicity _total += multiplicity - old_multiplicity result._total = _total return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:intersection; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:others; 7, block; 7, 8; 7, 10; 7, 18; 7, 24; 7, 30; 7, 95; 7, 101; 8, expression_statement; 8, 9; 9, identifier:r; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:result; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:__copy__; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:_elements; 21, attribute; 21, 22; 21, 23; 22, identifier:result; 23, identifier:_elements; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:_total; 27, attribute; 27, 28; 27, 29; 28, identifier:result; 29, identifier:_total; 30, for_statement; 30, 31; 30, 32; 30, 39; 31, identifier:other; 32, call; 32, 33; 32, 34; 33, identifier:map; 34, argument_list; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_as_mapping; 38, identifier:others; 39, block; 39, 40; 40, for_statement; 40, 41; 40, 44; 40, 52; 41, pattern_list; 41, 42; 41, 43; 42, identifier:element; 43, identifier:multiplicity; 44, call; 44, 45; 44, 46; 45, identifier:list; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:_elements; 50, identifier:items; 51, argument_list; 52, block; 52, 53; 52, 63; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:new_multiplicity; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:other; 59, identifier:get; 60, argument_list; 60, 61; 60, 62; 61, identifier:element; 62, integer:0; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:<; 64, 65; 64, 66; 65, identifier:new_multiplicity; 66, identifier:multiplicity; 67, block; 67, 68; 68, if_statement; 68, 69; 68, 72; 68, 85; 69, comparison_operator:>; 69, 70; 69, 71; 70, identifier:new_multiplicity; 71, integer:0; 72, block; 72, 73; 72, 79; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:_elements; 77, identifier:element; 78, identifier:new_multiplicity; 79, expression_statement; 79, 80; 80, augmented_assignment:-=; 80, 81; 80, 82; 81, identifier:_total; 82, binary_operator:-; 82, 83; 82, 84; 83, identifier:multiplicity; 84, identifier:new_multiplicity; 85, else_clause; 85, 86; 86, block; 86, 87; 86, 91; 87, delete_statement; 87, 88; 88, subscript; 88, 89; 88, 90; 89, identifier:_elements; 90, identifier:element; 91, expression_statement; 91, 92; 92, augmented_assignment:-=; 92, 93; 92, 94; 93, identifier:_total; 94, identifier:multiplicity; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:result; 99, identifier:_total; 100, identifier:_total; 101, return_statement; 101, 102; 102, identifier:result
def intersection(self, *others): r result = self.__copy__() _elements = result._elements _total = result._total for other in map(self._as_mapping, others): for element, multiplicity in list(_elements.items()): new_multiplicity = other.get(element, 0) if new_multiplicity < multiplicity: if new_multiplicity > 0: _elements[element] = new_multiplicity _total -= multiplicity - new_multiplicity else: del _elements[element] _total -= multiplicity result._total = _total return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:symmetric_difference; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:other; 6, block; 6, 7; 6, 9; 6, 18; 6, 26; 6, 30; 6, 36; 6, 42; 6, 48; 6, 68; 6, 121; 6, 127; 7, expression_statement; 7, 8; 8, identifier:r; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:other; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_as_multiset; 16, argument_list; 16, 17; 17, identifier:other; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:result; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:__class__; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:_total; 29, integer:0; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:_elements; 33, attribute; 33, 34; 33, 35; 34, identifier:result; 35, identifier:_elements; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:self_elements; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_elements; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:other_elements; 45, attribute; 45, 46; 45, 47; 46, identifier:other; 47, identifier:_elements; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:dist_elements; 51, binary_operator:|; 51, 52; 51, 60; 52, call; 52, 53; 52, 54; 53, identifier:set; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self_elements; 58, identifier:keys; 59, argument_list; 60, call; 60, 61; 60, 62; 61, identifier:set; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:other_elements; 66, identifier:keys; 67, argument_list; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:element; 70, identifier:dist_elements; 71, block; 71, 72; 71, 82; 71, 92; 71, 106; 71, 110; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:multiplicity; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self_elements; 78, identifier:get; 79, argument_list; 79, 80; 79, 81; 80, identifier:element; 81, integer:0; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:other_multiplicity; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:other_elements; 88, identifier:get; 89, argument_list; 89, 90; 89, 91; 90, identifier:element; 91, integer:0; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:new_multiplicity; 95, parenthesized_expression; 95, 96; 96, conditional_expression:if; 96, 97; 96, 100; 96, 103; 97, binary_operator:-; 97, 98; 97, 99; 98, identifier:multiplicity; 99, identifier:other_multiplicity; 100, comparison_operator:>; 100, 101; 100, 102; 101, identifier:multiplicity; 102, identifier:other_multiplicity; 103, binary_operator:-; 103, 104; 103, 105; 104, identifier:other_multiplicity; 105, identifier:multiplicity; 106, expression_statement; 106, 107; 107, augmented_assignment:+=; 107, 108; 107, 109; 108, identifier:_total; 109, identifier:new_multiplicity; 110, if_statement; 110, 111; 110, 114; 111, comparison_operator:>; 111, 112; 111, 113; 112, identifier:new_multiplicity; 113, integer:0; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:_elements; 119, identifier:element; 120, identifier:new_multiplicity; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:result; 125, identifier:_total; 126, identifier:_total; 127, return_statement; 127, 128; 128, identifier:result
def symmetric_difference(self, other): r other = self._as_multiset(other) result = self.__class__() _total = 0 _elements = result._elements self_elements = self._elements other_elements = other._elements dist_elements = set(self_elements.keys()) | set(other_elements.keys()) for element in dist_elements: multiplicity = self_elements.get(element, 0) other_multiplicity = other_elements.get(element, 0) new_multiplicity = (multiplicity - other_multiplicity if multiplicity > other_multiplicity else other_multiplicity - multiplicity) _total += new_multiplicity if new_multiplicity > 0: _elements[element] = new_multiplicity result._total = _total return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:times; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:factor; 6, block; 6, 7; 6, 18; 6, 28; 6, 36; 6, 42; 6, 52; 6, 58; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:==; 8, 9; 8, 10; 9, identifier:factor; 10, integer:0; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:__class__; 17, argument_list; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:<; 19, 20; 19, 21; 20, identifier:factor; 21, integer:0; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:ValueError; 26, argument_list; 26, 27; 27, string:'The factor must no be negative.'; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:result; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:__copy__; 35, argument_list; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:_elements; 39, attribute; 39, 40; 39, 41; 40, identifier:result; 41, identifier:_elements; 42, for_statement; 42, 43; 42, 44; 42, 45; 43, identifier:element; 44, identifier:_elements; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, augmented_assignment:*=; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:_elements; 50, identifier:element; 51, identifier:factor; 52, expression_statement; 52, 53; 53, augmented_assignment:*=; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:result; 56, identifier:_total; 57, identifier:factor; 58, return_statement; 58, 59; 59, identifier:result
def times(self, factor): if factor == 0: return self.__class__() if factor < 0: raise ValueError('The factor must no be negative.') result = self.__copy__() _elements = result._elements for element in _elements: _elements[element] *= factor result._total *= factor return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:union_update; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:others; 7, block; 7, 8; 7, 10; 7, 16; 7, 22; 7, 69; 8, expression_statement; 8, 9; 9, identifier:r; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:_elements; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_elements; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:_total; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_total; 22, for_statement; 22, 23; 22, 24; 22, 31; 23, identifier:other; 24, call; 24, 25; 24, 26; 25, identifier:map; 26, argument_list; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_as_mapping; 30, identifier:others; 31, block; 31, 32; 32, for_statement; 32, 33; 32, 36; 32, 41; 33, pattern_list; 33, 34; 33, 35; 34, identifier:element; 35, identifier:multiplicity; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:other; 39, identifier:items; 40, argument_list; 41, block; 41, 42; 41, 52; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:old_multiplicity; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:_elements; 48, identifier:get; 49, argument_list; 49, 50; 49, 51; 50, identifier:element; 51, integer:0; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:>; 53, 54; 53, 55; 54, identifier:multiplicity; 55, identifier:old_multiplicity; 56, block; 56, 57; 56, 63; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, subscript; 59, 60; 59, 61; 60, identifier:_elements; 61, identifier:element; 62, identifier:multiplicity; 63, expression_statement; 63, 64; 64, augmented_assignment:+=; 64, 65; 64, 66; 65, identifier:_total; 66, binary_operator:-; 66, 67; 66, 68; 67, identifier:multiplicity; 68, identifier:old_multiplicity; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_total; 74, identifier:_total
def union_update(self, *others): r _elements = self._elements _total = self._total for other in map(self._as_mapping, others): for element, multiplicity in other.items(): old_multiplicity = _elements.get(element, 0) if multiplicity > old_multiplicity: _elements[element] = multiplicity _total += multiplicity - old_multiplicity self._total = _total
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:intersection_update; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:others; 7, block; 7, 8; 7, 10; 8, expression_statement; 8, 9; 9, identifier:r; 10, for_statement; 10, 11; 10, 12; 10, 19; 11, identifier:other; 12, call; 12, 13; 12, 14; 13, identifier:map; 14, argument_list; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_as_mapping; 18, identifier:others; 19, block; 19, 20; 20, for_statement; 20, 21; 20, 24; 20, 32; 21, pattern_list; 21, 22; 21, 23; 22, identifier:element; 23, identifier:current_count; 24, call; 24, 25; 24, 26; 25, identifier:list; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:items; 31, argument_list; 32, block; 32, 33; 32, 43; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:multiplicity; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:other; 39, identifier:get; 40, argument_list; 40, 41; 40, 42; 41, identifier:element; 42, integer:0; 43, if_statement; 43, 44; 43, 47; 44, comparison_operator:<; 44, 45; 44, 46; 45, identifier:multiplicity; 46, identifier:current_count; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:self; 52, identifier:element; 53, identifier:multiplicity
def intersection_update(self, *others): r for other in map(self._as_mapping, others): for element, current_count in list(self.items()): multiplicity = other.get(element, 0) if multiplicity < current_count: self[element] = multiplicity
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:difference_update; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:others; 7, block; 7, 8; 7, 10; 8, expression_statement; 8, 9; 9, identifier:r; 10, for_statement; 10, 11; 10, 12; 10, 19; 11, identifier:other; 12, call; 12, 13; 12, 14; 13, identifier:map; 14, argument_list; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_as_multiset; 18, identifier:others; 19, block; 19, 20; 20, for_statement; 20, 21; 20, 24; 20, 29; 21, pattern_list; 21, 22; 21, 23; 22, identifier:element; 23, identifier:multiplicity; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:other; 27, identifier:items; 28, argument_list; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:discard; 35, argument_list; 35, 36; 35, 37; 36, identifier:element; 37, identifier:multiplicity
def difference_update(self, *others): r for other in map(self._as_multiset, others): for element, multiplicity in other.items(): self.discard(element, multiplicity)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:symmetric_difference_update; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:other; 6, block; 6, 7; 6, 9; 6, 18; 6, 38; 7, expression_statement; 7, 8; 8, identifier:r; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:other; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_as_multiset; 16, argument_list; 16, 17; 17, identifier:other; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:elements; 21, binary_operator:|; 21, 22; 21, 30; 22, call; 22, 23; 22, 24; 23, identifier:set; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:distinct_elements; 29, argument_list; 30, call; 30, 31; 30, 32; 31, identifier:set; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:other; 36, identifier:distinct_elements; 37, argument_list; 38, for_statement; 38, 39; 38, 40; 38, 41; 39, identifier:element; 40, identifier:elements; 41, block; 41, 42; 41, 48; 41, 54; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:multiplicity; 45, subscript; 45, 46; 45, 47; 46, identifier:self; 47, identifier:element; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:other_count; 51, subscript; 51, 52; 51, 53; 52, identifier:other; 53, identifier:element; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:self; 58, identifier:element; 59, parenthesized_expression; 59, 60; 60, conditional_expression:if; 60, 61; 60, 64; 60, 67; 61, binary_operator:-; 61, 62; 61, 63; 62, identifier:multiplicity; 63, identifier:other_count; 64, comparison_operator:>; 64, 65; 64, 66; 65, identifier:multiplicity; 66, identifier:other_count; 67, binary_operator:-; 67, 68; 67, 69; 68, identifier:other_count; 69, identifier:multiplicity
def symmetric_difference_update(self, other): r other = self._as_multiset(other) elements = set(self.distinct_elements()) | set(other.distinct_elements()) for element in elements: multiplicity = self[element] other_count = other[element] self[element] = (multiplicity - other_count if multiplicity > other_count else other_count - multiplicity)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:times_update; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:factor; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 11; 7, 17; 7, 28; 8, comparison_operator:<; 8, 9; 8, 10; 9, identifier:factor; 10, integer:0; 11, block; 11, 12; 12, raise_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:ValueError; 15, argument_list; 15, 16; 16, string:"The factor must not be negative."; 17, elif_clause; 17, 18; 17, 21; 18, comparison_operator:==; 18, 19; 18, 20; 19, identifier:factor; 20, integer:0; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:clear; 27, argument_list; 28, else_clause; 28, 29; 29, block; 29, 30; 29, 36; 29, 46; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:_elements; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_elements; 36, for_statement; 36, 37; 36, 38; 36, 39; 37, identifier:element; 38, identifier:_elements; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, augmented_assignment:*=; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:_elements; 44, identifier:element; 45, identifier:factor; 46, expression_statement; 46, 47; 47, augmented_assignment:*=; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_total; 51, identifier:factor
def times_update(self, factor): if factor < 0: raise ValueError("The factor must not be negative.") elif factor == 0: self.clear() else: _elements = self._elements for element in _elements: _elements[element] *= factor self._total *= factor
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:add; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:element; 6, default_parameter; 6, 7; 6, 8; 7, identifier:multiplicity; 8, integer:1; 9, block; 9, 10; 9, 20; 9, 28; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:<; 11, 12; 11, 13; 12, identifier:multiplicity; 13, integer:1; 14, block; 14, 15; 15, raise_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:ValueError; 18, argument_list; 18, 19; 19, string:"Multiplicity must be positive"; 20, expression_statement; 20, 21; 21, augmented_assignment:+=; 21, 22; 21, 27; 22, subscript; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:_elements; 26, identifier:element; 27, identifier:multiplicity; 28, expression_statement; 28, 29; 29, augmented_assignment:+=; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_total; 33, identifier:multiplicity
def add(self, element, multiplicity=1): if multiplicity < 1: raise ValueError("Multiplicity must be positive") self._elements[element] += multiplicity self._total += multiplicity
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:remove; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:element; 6, default_parameter; 6, 7; 6, 8; 7, identifier:multiplicity; 8, None; 9, block; 9, 10; 9, 16; 9, 23; 9, 33; 9, 79; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:_elements; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_elements; 16, if_statement; 16, 17; 16, 20; 17, comparison_operator:not; 17, 18; 17, 19; 18, identifier:element; 19, identifier:_elements; 20, block; 20, 21; 21, raise_statement; 21, 22; 22, identifier:KeyError; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:old_multiplicity; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:_elements; 29, identifier:get; 30, argument_list; 30, 31; 30, 32; 31, identifier:element; 32, integer:0; 33, if_statement; 33, 34; 33, 41; 33, 52; 33, 62; 34, boolean_operator:or; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:multiplicity; 37, None; 38, comparison_operator:>=; 38, 39; 38, 40; 39, identifier:multiplicity; 40, identifier:old_multiplicity; 41, block; 41, 42; 41, 46; 42, delete_statement; 42, 43; 43, subscript; 43, 44; 43, 45; 44, identifier:_elements; 45, identifier:element; 46, expression_statement; 46, 47; 47, augmented_assignment:-=; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_total; 51, identifier:old_multiplicity; 52, elif_clause; 52, 53; 52, 56; 53, comparison_operator:<; 53, 54; 53, 55; 54, identifier:multiplicity; 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:"Multiplicity must be not be negative"; 62, elif_clause; 62, 63; 62, 66; 63, comparison_operator:>; 63, 64; 63, 65; 64, identifier:multiplicity; 65, integer:0; 66, block; 66, 67; 66, 73; 67, expression_statement; 67, 68; 68, augmented_assignment:-=; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:_elements; 71, identifier:element; 72, identifier:multiplicity; 73, expression_statement; 73, 74; 74, augmented_assignment:-=; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:_total; 78, identifier:multiplicity; 79, return_statement; 79, 80; 80, identifier:old_multiplicity
def remove(self, element, multiplicity=None): _elements = self._elements if element not in _elements: raise KeyError old_multiplicity = _elements.get(element, 0) if multiplicity is None or multiplicity >= old_multiplicity: del _elements[element] self._total -= old_multiplicity elif multiplicity < 0: raise ValueError("Multiplicity must be not be negative") elif multiplicity > 0: _elements[element] -= multiplicity self._total -= multiplicity return old_multiplicity
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:discard; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:element; 6, default_parameter; 6, 7; 6, 8; 7, identifier:multiplicity; 8, None; 9, block; 9, 10; 9, 16; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:_elements; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_elements; 16, if_statement; 16, 17; 16, 20; 16, 75; 17, comparison_operator:in; 17, 18; 17, 19; 18, identifier:element; 19, identifier:_elements; 20, block; 20, 21; 20, 27; 20, 73; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:old_multiplicity; 24, subscript; 24, 25; 24, 26; 25, identifier:_elements; 26, identifier:element; 27, if_statement; 27, 28; 27, 35; 27, 46; 27, 56; 28, boolean_operator:or; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:multiplicity; 31, None; 32, comparison_operator:>=; 32, 33; 32, 34; 33, identifier:multiplicity; 34, identifier:old_multiplicity; 35, block; 35, 36; 35, 40; 36, delete_statement; 36, 37; 37, subscript; 37, 38; 37, 39; 38, identifier:_elements; 39, identifier:element; 40, expression_statement; 40, 41; 41, augmented_assignment:-=; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:_total; 45, identifier:old_multiplicity; 46, elif_clause; 46, 47; 46, 50; 47, comparison_operator:<; 47, 48; 47, 49; 48, identifier:multiplicity; 49, integer:0; 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:"Multiplicity must not be negative"; 56, elif_clause; 56, 57; 56, 60; 57, comparison_operator:>; 57, 58; 57, 59; 58, identifier:multiplicity; 59, integer:0; 60, block; 60, 61; 60, 67; 61, expression_statement; 61, 62; 62, augmented_assignment:-=; 62, 63; 62, 66; 63, subscript; 63, 64; 63, 65; 64, identifier:_elements; 65, identifier:element; 66, identifier:multiplicity; 67, expression_statement; 67, 68; 68, augmented_assignment:-=; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:_total; 72, identifier:multiplicity; 73, return_statement; 73, 74; 74, identifier:old_multiplicity; 75, else_clause; 75, 76; 76, block; 76, 77; 77, return_statement; 77, 78; 78, integer:0
def discard(self, element, multiplicity=None): _elements = self._elements if element in _elements: old_multiplicity = _elements[element] if multiplicity is None or multiplicity >= old_multiplicity: del _elements[element] self._total -= old_multiplicity elif multiplicity < 0: raise ValueError("Multiplicity must not be negative") elif multiplicity > 0: _elements[element] -= multiplicity self._total -= multiplicity return old_multiplicity else: return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:async_thread; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 10; 4, identifier:sol; 5, identifier:args; 6, identifier:node_attr; 7, identifier:node_id; 8, list_splat_pattern; 8, 9; 9, identifier:a; 10, dictionary_splat_pattern; 10, 11; 11, identifier:kw; 12, block; 12, 13; 12, 32; 12, 49; 12, 53; 12, 79; 12, 85; 12, 99; 12, 118; 12, 206; 12, 216; 12, 229; 12, 242; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:executor; 16, call; 16, 17; 16, 18; 17, identifier:_get_executor; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:_executor_name; 21, argument_list; 21, 22; 21, 29; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:kw; 25, identifier:get; 26, argument_list; 26, 27; 26, 28; 27, string:'executor'; 28, False; 29, attribute; 29, 30; 29, 31; 30, identifier:sol; 31, identifier:dsp; 32, if_statement; 32, 33; 32, 35; 33, not_operator; 33, 34; 34, identifier:executor; 35, block; 35, 36; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:sol; 40, identifier:_evaluate_node; 41, argument_list; 41, 42; 41, 43; 41, 44; 41, 45; 41, 47; 42, identifier:args; 43, identifier:node_attr; 44, identifier:node_id; 45, list_splat; 45, 46; 46, identifier:a; 47, dictionary_splat; 47, 48; 48, identifier:kw; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:futures; 52, identifier:args; 53, if_statement; 53, 54; 53, 68; 54, boolean_operator:and; 54, 55; 54, 60; 55, comparison_operator:==; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:node_attr; 58, string:'type'; 59, string:'data'; 60, parenthesized_expression; 60, 61; 61, boolean_operator:or; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:node_attr; 64, string:'wait_inputs'; 65, comparison_operator:in; 65, 66; 65, 67; 66, string:'function'; 67, identifier:node_attr; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:futures; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:args; 76, integer:0; 77, identifier:values; 78, argument_list; 79, import_from_statement; 79, 80; 79, 83; 80, dotted_name; 80, 81; 80, 82; 81, identifier:concurrent; 82, identifier:futures; 83, dotted_name; 83, 84; 84, identifier:Future; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:futures; 88, set_comprehension; 88, 89; 88, 90; 88, 93; 89, identifier:v; 90, for_in_clause; 90, 91; 90, 92; 91, identifier:v; 92, identifier:futures; 93, if_clause; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:isinstance; 96, argument_list; 96, 97; 96, 98; 97, identifier:v; 98, identifier:Future; 99, function_definition; 99, 100; 99, 101; 99, 102; 100, function_name:_submit; 101, parameters; 102, block; 102, 103; 103, return_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:executor; 107, identifier:thread; 108, argument_list; 108, 109; 108, 110; 108, 111; 108, 112; 108, 113; 108, 114; 108, 116; 109, identifier:_async_eval; 110, identifier:sol; 111, identifier:args; 112, identifier:node_attr; 113, identifier:node_id; 114, list_splat; 114, 115; 115, identifier:a; 116, dictionary_splat; 116, 117; 117, identifier:kw; 118, if_statement; 118, 119; 118, 120; 118, 198; 119, identifier:futures; 120, block; 120, 121; 120, 127; 120, 158; 120, 184; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:result; 124, call; 124, 125; 124, 126; 125, identifier:Future; 126, argument_list; 127, function_definition; 127, 128; 127, 129; 127, 131; 128, function_name:_set_res; 129, parameters; 129, 130; 130, identifier:fut; 131, block; 131, 132; 132, try_statement; 132, 133; 132, 145; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:result; 138, identifier:set_result; 139, argument_list; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:fut; 143, identifier:result; 144, argument_list; 145, except_clause; 145, 146; 145, 150; 146, as_pattern; 146, 147; 146, 148; 147, identifier:BaseException; 148, as_pattern_target; 148, 149; 149, identifier:ex; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:result; 155, identifier:set_exception; 156, argument_list; 156, 157; 157, identifier:ex; 158, function_definition; 158, 159; 158, 160; 158, 164; 159, function_name:_submit_task; 160, parameters; 160, 161; 161, default_parameter; 161, 162; 161, 163; 162, identifier:fut; 163, None; 164, block; 164, 165; 164, 172; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:futures; 169, identifier:discard; 170, argument_list; 170, 171; 171, identifier:fut; 172, expression_statement; 172, 173; 173, boolean_operator:and; 173, 174; 173, 176; 174, not_operator; 174, 175; 175, identifier:futures; 176, call; 176, 177; 176, 182; 177, attribute; 177, 178; 177, 181; 178, call; 178, 179; 178, 180; 179, identifier:_submit; 180, argument_list; 181, identifier:add_done_callback; 182, argument_list; 182, 183; 183, identifier:_set_res; 184, for_statement; 184, 185; 184, 186; 184, 190; 185, identifier:f; 186, call; 186, 187; 186, 188; 187, identifier:list; 188, argument_list; 188, 189; 189, identifier:futures; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:f; 195, identifier:add_done_callback; 196, argument_list; 196, 197; 197, identifier:_submit_task; 198, else_clause; 198, 199; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:result; 203, call; 203, 204; 203, 205; 204, identifier:_submit; 205, argument_list; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:timeout; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:node_attr; 212, identifier:get; 213, argument_list; 213, 214; 213, 215; 214, string:'await_result'; 215, False; 216, if_statement; 216, 217; 216, 220; 217, comparison_operator:is; 217, 218; 217, 219; 218, identifier:timeout; 219, False; 220, block; 220, 221; 221, return_statement; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:_await_result; 224, argument_list; 224, 225; 224, 226; 224, 227; 224, 228; 225, identifier:result; 226, identifier:timeout; 227, identifier:sol; 228, identifier:node_id; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:n; 232, call; 232, 233; 232, 234; 233, identifier:len; 234, argument_list; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:node_attr; 238, identifier:get; 239, argument_list; 239, 240; 239, 241; 240, string:'outputs'; 241, list:[]; 242, return_statement; 242, 243; 243, conditional_expression:if; 243, 244; 243, 253; 243, 256; 244, call; 244, 245; 244, 246; 245, identifier:AsyncList; 246, argument_list; 246, 247; 246, 250; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:future; 249, identifier:result; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:n; 252, identifier:n; 253, comparison_operator:>; 253, 254; 253, 255; 254, identifier:n; 255, integer:1; 256, identifier:result
def async_thread(sol, args, node_attr, node_id, *a, **kw): executor = _get_executor(_executor_name(kw.get('executor', False), sol.dsp)) if not executor: return sol._evaluate_node(args, node_attr, node_id, *a, **kw) futures = args if node_attr['type'] == 'data' and ( node_attr['wait_inputs'] or 'function' in node_attr): futures = args[0].values() from concurrent.futures import Future futures = {v for v in futures if isinstance(v, Future)} def _submit(): return executor.thread( _async_eval, sol, args, node_attr, node_id, *a, **kw ) if futures: result = Future() def _set_res(fut): try: result.set_result(fut.result()) except BaseException as ex: result.set_exception(ex) def _submit_task(fut=None): futures.discard(fut) not futures and _submit().add_done_callback(_set_res) for f in list(futures): f.add_done_callback(_submit_task) else: result = _submit() timeout = node_attr.get('await_result', False) if timeout is not False: return _await_result(result, timeout, sol, node_id) n = len(node_attr.get('outputs', [])) return AsyncList(future=result, n=n) if n > 1 else result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:pivot; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:table; 5, identifier:left; 6, identifier:top; 7, identifier:value; 8, block; 8, 9; 8, 13; 8, 17; 8, 21; 8, 115; 8, 155; 8, 162; 8, 169; 8, 173; 8, 230; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:rs; 12, dictionary; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:ysort; 16, list:[]; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:xsort; 20, list:[]; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:row; 23, identifier:table; 24, block; 24, 25; 24, 38; 24, 50; 24, 63; 24, 75; 24, 90; 24, 105; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:yaxis; 28, call; 28, 29; 28, 30; 29, identifier:tuple; 30, argument_list; 30, 31; 31, list_comprehension; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:row; 34, identifier:c; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:c; 37, identifier:left; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:not; 39, 40; 39, 41; 40, identifier:yaxis; 41, identifier:ysort; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:ysort; 47, identifier:append; 48, argument_list; 48, 49; 49, identifier:yaxis; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:xaxis; 53, call; 53, 54; 53, 55; 54, identifier:tuple; 55, argument_list; 55, 56; 56, list_comprehension; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:row; 59, identifier:c; 60, for_in_clause; 60, 61; 60, 62; 61, identifier:c; 62, identifier:top; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:not; 64, 65; 64, 66; 65, identifier:xaxis; 66, identifier:xsort; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:xsort; 72, identifier:append; 73, argument_list; 73, 74; 74, identifier:xaxis; 75, try_statement; 75, 76; 75, 81; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, subscript; 78, 79; 78, 80; 79, identifier:rs; 80, identifier:yaxis; 81, except_clause; 81, 82; 81, 83; 82, identifier:KeyError; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:rs; 88, identifier:yaxis; 89, dictionary; 90, if_statement; 90, 91; 90, 96; 91, comparison_operator:not; 91, 92; 91, 93; 92, identifier:xaxis; 93, subscript; 93, 94; 93, 95; 94, identifier:rs; 95, identifier:yaxis; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 104; 99, subscript; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:rs; 102, identifier:yaxis; 103, identifier:xaxis; 104, integer:0; 105, expression_statement; 105, 106; 106, augmented_assignment:+=; 106, 107; 106, 112; 107, subscript; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:rs; 110, identifier:yaxis; 111, identifier:xaxis; 112, subscript; 112, 113; 112, 114; 113, identifier:row; 114, identifier:value; 115, for_statement; 115, 116; 115, 117; 115, 118; 116, identifier:key; 117, identifier:rs; 118, block; 118, 119; 119, if_statement; 119, 120; 119, 131; 120, binary_operator:-; 120, 121; 120, 127; 121, call; 121, 122; 121, 123; 122, identifier:len; 123, argument_list; 123, 124; 124, subscript; 124, 125; 124, 126; 125, identifier:rs; 126, identifier:key; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, identifier:xsort; 131, block; 131, 132; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:var; 134, identifier:xsort; 135, block; 135, 136; 136, if_statement; 136, 137; 136, 146; 137, comparison_operator:not; 137, 138; 137, 139; 138, identifier:var; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:rs; 143, identifier:key; 144, identifier:keys; 145, argument_list; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 154; 149, subscript; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:rs; 152, identifier:key; 153, identifier:var; 154, string:''; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:headings; 158, call; 158, 159; 158, 160; 159, identifier:list; 160, argument_list; 160, 161; 161, identifier:left; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:headings; 166, identifier:extend; 167, argument_list; 167, 168; 168, identifier:xsort; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:t; 172, list:[]; 173, for_statement; 173, 174; 173, 175; 173, 176; 174, identifier:left; 175, identifier:ysort; 176, block; 176, 177; 176, 184; 176, 197; 176, 209; 176, 216; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:row; 180, call; 180, 181; 180, 182; 181, identifier:list; 182, argument_list; 182, 183; 183, identifier:left; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:sortedkeys; 187, call; 187, 188; 187, 189; 188, identifier:sorted; 189, argument_list; 189, 190; 190, call; 190, 191; 190, 196; 191, attribute; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:rs; 194, identifier:left; 195, identifier:keys; 196, argument_list; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:sortedvalues; 200, call; 200, 201; 200, 202; 201, identifier:map; 202, argument_list; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, subscript; 204, 205; 204, 206; 205, identifier:rs; 206, identifier:left; 207, identifier:get; 208, identifier:sortedkeys; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:row; 213, identifier:extend; 214, argument_list; 214, 215; 215, identifier:sortedvalues; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:t; 220, identifier:append; 221, argument_list; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:dict; 224, argument_list; 224, 225; 225, call; 225, 226; 225, 227; 226, identifier:zip; 227, argument_list; 227, 228; 227, 229; 228, identifier:headings; 229, identifier:row; 230, return_statement; 230, 231; 231, identifier:t
def pivot(table, left, top, value): rs = {} ysort = [] xsort = [] for row in table: yaxis = tuple([row[c] for c in left]) if yaxis not in ysort: ysort.append(yaxis) xaxis = tuple([row[c] for c in top]) if xaxis not in xsort: xsort.append(xaxis) try: rs[yaxis] except KeyError: rs[yaxis] = {} if xaxis not in rs[yaxis]: rs[yaxis][xaxis] = 0 rs[yaxis][xaxis] += row[value] for key in rs: if len(rs[key]) - len(xsort): for var in xsort: if var not in rs[key].keys(): rs[key][var] = '' headings = list(left) headings.extend(xsort) t = [] for left in ysort: row = list(left) sortedkeys = sorted(rs[left].keys()) sortedvalues = map(rs[left].get, sortedkeys) row.extend(sortedvalues) t.append(dict(zip(headings,row))) return t
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:download_hrrr_for_gssha; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 11; 3, 14; 3, 17; 4, identifier:main_directory; 5, identifier:forecast_start_date_string; 6, identifier:forecast_start_hour_string; 7, default_parameter; 7, 8; 7, 9; 8, identifier:leftlon; 9, unary_operator:-; 9, 10; 10, integer:180; 11, default_parameter; 11, 12; 11, 13; 12, identifier:rightlon; 13, integer:180; 14, default_parameter; 14, 15; 14, 16; 15, identifier:toplat; 16, integer:90; 17, default_parameter; 17, 18; 17, 19; 18, identifier:bottomlat; 19, unary_operator:-; 19, 20; 20, integer:90; 21, block; 21, 22; 21, 32; 21, 43; 21, 66; 21, 70; 21, 269; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:out_directory; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:path; 28, identifier:join; 29, argument_list; 29, 30; 29, 31; 30, identifier:main_directory; 31, identifier:forecast_start_date_string; 32, try_statement; 32, 33; 32, 39; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:mkdir; 37, argument_list; 37, 38; 38, identifier:out_directory; 39, except_clause; 39, 40; 39, 41; 40, identifier:OSError; 41, block; 41, 42; 42, pass_statement; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:forecast_timestep_hour_string_array; 46, list:['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18']; 46, 47; 46, 48; 46, 49; 46, 50; 46, 51; 46, 52; 46, 53; 46, 54; 46, 55; 46, 56; 46, 57; 46, 58; 46, 59; 46, 60; 46, 61; 46, 62; 46, 63; 46, 64; 46, 65; 47, string:'00'; 48, string:'01'; 49, string:'02'; 50, string:'03'; 51, string:'04'; 52, string:'05'; 53, string:'06'; 54, string:'07'; 55, string:'08'; 56, string:'09'; 57, string:'10'; 58, string:'11'; 59, string:'12'; 60, string:'13'; 61, string:'14'; 62, string:'15'; 63, string:'16'; 64, string:'17'; 65, string:'18'; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:downloaded_file_list; 69, list:[]; 70, for_statement; 70, 71; 70, 72; 70, 73; 71, identifier:forecast_timestep_hour_string; 72, identifier:forecast_timestep_hour_string_array; 73, block; 73, 74; 73, 84; 73, 162; 73, 177; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:file_name; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, string:'hrrr.t{0}z.wrfsfcf{1}.grib2'; 80, identifier:format; 81, argument_list; 81, 82; 81, 83; 82, identifier:forecast_start_hour_string; 83, identifier:forecast_timestep_hour_string; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:payload; 87, dictionary; 87, 88; 87, 91; 87, 94; 87, 97; 87, 100; 87, 103; 87, 106; 87, 109; 87, 112; 87, 115; 87, 118; 87, 121; 87, 124; 87, 127; 87, 130; 87, 136; 87, 142; 87, 148; 87, 154; 88, pair; 88, 89; 88, 90; 89, string:'file'; 90, identifier:file_name; 91, pair; 91, 92; 91, 93; 92, string:'lev_10_m_above_ground'; 93, string:'on'; 94, pair; 94, 95; 94, 96; 95, string:'lev_2_m_above_ground'; 96, string:'on'; 97, pair; 97, 98; 97, 99; 98, string:'lev_entire_atmosphere'; 99, string:'on'; 100, pair; 100, 101; 100, 102; 101, string:'lev_surface'; 102, string:'on'; 103, pair; 103, 104; 103, 105; 104, string:'var_DSWRF'; 105, string:'on'; 106, pair; 106, 107; 106, 108; 107, string:'var_PRATE'; 108, string:'on'; 109, pair; 109, 110; 109, 111; 110, string:'var_PRES'; 111, string:'on'; 112, pair; 112, 113; 112, 114; 113, string:'var_RH'; 114, string:'on'; 115, pair; 115, 116; 115, 117; 116, string:'var_TMP'; 117, string:'on'; 118, pair; 118, 119; 118, 120; 119, string:'var_UGRD'; 120, string:'on'; 121, pair; 121, 122; 121, 123; 122, string:'var_VGRD'; 123, string:'on'; 124, pair; 124, 125; 124, 126; 125, string:'var_TCDC'; 126, string:'on'; 127, pair; 127, 128; 127, 129; 128, string:'subregion'; 129, string:''; 130, pair; 130, 131; 130, 132; 131, string:'leftlon'; 132, call; 132, 133; 132, 134; 133, identifier:str; 134, argument_list; 134, 135; 135, identifier:leftlon; 136, pair; 136, 137; 136, 138; 137, string:'rightlon'; 138, call; 138, 139; 138, 140; 139, identifier:str; 140, argument_list; 140, 141; 141, identifier:rightlon; 142, pair; 142, 143; 142, 144; 143, string:'toplat'; 144, call; 144, 145; 144, 146; 145, identifier:str; 146, argument_list; 146, 147; 147, identifier:toplat; 148, pair; 148, 149; 148, 150; 149, string:'bottomlat'; 150, call; 150, 151; 150, 152; 151, identifier:str; 152, argument_list; 152, 153; 153, identifier:bottomlat; 154, pair; 154, 155; 154, 156; 155, string:'dir'; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, string:'/hrrr.{0}'; 159, identifier:format; 160, argument_list; 160, 161; 161, identifier:forecast_start_date_string; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:r; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:requests; 168, identifier:get; 169, argument_list; 169, 170; 169, 171; 169, 174; 170, string:'http://nomads.ncep.noaa.gov/cgi-bin/filter_hrrr_2d.pl'; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:params; 173, identifier:payload; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:stream; 176, True; 177, if_statement; 177, 178; 177, 187; 177, 235; 178, comparison_operator:==; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:r; 181, identifier:status_code; 182, attribute; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:requests; 185, identifier:codes; 186, identifier:ok; 187, block; 187, 188; 187, 198; 187, 205; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:out_file; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:path; 194, identifier:join; 195, argument_list; 195, 196; 195, 197; 196, identifier:out_directory; 197, identifier:file_name; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:downloaded_file_list; 202, identifier:append; 203, argument_list; 203, 204; 204, identifier:out_file; 205, with_statement; 205, 206; 205, 216; 206, with_clause; 206, 207; 207, with_item; 207, 208; 208, as_pattern; 208, 209; 208, 214; 209, call; 209, 210; 209, 211; 210, identifier:open; 211, argument_list; 211, 212; 211, 213; 212, identifier:out_file; 213, string:'wb'; 214, as_pattern_target; 214, 215; 215, identifier:fd; 216, block; 216, 217; 217, for_statement; 217, 218; 217, 219; 217, 227; 218, identifier:chunk; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:r; 222, identifier:iter_content; 223, argument_list; 223, 224; 224, keyword_argument; 224, 225; 224, 226; 225, identifier:chunk_size; 226, integer:1024; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:fd; 232, identifier:write; 233, argument_list; 233, 234; 234, identifier:chunk; 235, else_clause; 235, 236; 236, block; 236, 237; 236, 249; 236, 264; 236, 268; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:log; 241, identifier:error; 242, argument_list; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, string:"Problem downloading {0}"; 246, identifier:format; 247, argument_list; 247, 248; 248, identifier:file_name; 249, for_statement; 249, 250; 249, 251; 249, 252; 250, identifier:filename; 251, identifier:downloaded_file_list; 252, block; 252, 253; 253, try_statement; 253, 254; 253, 260; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:remove; 258, argument_list; 258, 259; 259, identifier:filename; 260, except_clause; 260, 261; 260, 262; 261, identifier:OSError; 262, block; 262, 263; 263, pass_statement; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:downloaded_file_list; 267, list:[]; 268, break_statement; 269, return_statement; 269, 270; 270, identifier:downloaded_file_list
def download_hrrr_for_gssha(main_directory, forecast_start_date_string, forecast_start_hour_string, leftlon=-180, rightlon=180, toplat=90,bottomlat=-90): out_directory = path.join(main_directory, forecast_start_date_string) try: mkdir(out_directory) except OSError: pass forecast_timestep_hour_string_array = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18'] downloaded_file_list = [] for forecast_timestep_hour_string in forecast_timestep_hour_string_array: file_name = 'hrrr.t{0}z.wrfsfcf{1}.grib2'.format(forecast_start_hour_string, forecast_timestep_hour_string) payload = { 'file': file_name, 'lev_10_m_above_ground': 'on', 'lev_2_m_above_ground': 'on', 'lev_entire_atmosphere': 'on', 'lev_surface': 'on', 'var_DSWRF': 'on', 'var_PRATE': 'on', 'var_PRES': 'on', 'var_RH': 'on', 'var_TMP': 'on', 'var_UGRD': 'on', 'var_VGRD': 'on', 'var_TCDC': 'on', 'subregion': '', 'leftlon': str(leftlon), 'rightlon': str(rightlon), 'toplat': str(toplat), 'bottomlat': str(bottomlat), 'dir': '/hrrr.{0}'.format(forecast_start_date_string), } r = requests.get('http://nomads.ncep.noaa.gov/cgi-bin/filter_hrrr_2d.pl', params=payload, stream=True) if r.status_code == requests.codes.ok: out_file = path.join(out_directory, file_name) downloaded_file_list.append(out_file) with open(out_file, 'wb') as fd: for chunk in r.iter_content(chunk_size=1024): fd.write(chunk) else: log.error("Problem downloading {0}".format(file_name)) for filename in downloaded_file_list: try: remove(filename) except OSError: pass downloaded_file_list = [] break return downloaded_file_list
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_convert_data_to_hourly; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:gssha_data_var; 6, block; 6, 7; 6, 30; 6, 39; 6, 43; 6, 392; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:time_step_hours; 10, binary_operator:/; 10, 11; 10, 23; 11, subscript; 11, 12; 11, 22; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:np; 15, identifier:diff; 16, argument_list; 16, 17; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:data; 21, identifier:time; 22, integer:0; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:np; 26, identifier:timedelta64; 27, argument_list; 27, 28; 27, 29; 28, integer:1; 29, string:'h'; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:calc_function; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_get_calc_function; 37, argument_list; 37, 38; 38, identifier:gssha_data_var; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:resampled_data; 42, None; 43, if_statement; 43, 44; 43, 47; 43, 68; 44, comparison_operator:<; 44, 45; 44, 46; 45, identifier:time_step_hours; 46, integer:1; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:resampled_data; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:data; 56, identifier:resample; 57, argument_list; 57, 58; 57, 59; 57, 62; 57, 65; 58, string:'1H'; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:dim; 61, string:'time'; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:how; 64, identifier:calc_function; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:keep_attrs; 67, True; 68, elif_clause; 68, 69; 68, 72; 69, comparison_operator:>; 69, 70; 69, 71; 70, identifier:time_step_hours; 71, integer:1; 72, block; 72, 73; 72, 90; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:resampled_data; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:data; 81, identifier:resample; 82, argument_list; 82, 83; 82, 84; 82, 87; 83, string:'1H'; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:dim; 86, string:'time'; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:keep_attrs; 89, True; 90, for_statement; 90, 91; 90, 92; 90, 102; 91, identifier:time_idx; 92, call; 92, 93; 92, 94; 93, identifier:range; 94, argument_list; 94, 95; 95, subscript; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:data; 100, identifier:dims; 101, string:'time'; 102, block; 102, 103; 103, if_statement; 103, 104; 103, 115; 103, 280; 104, comparison_operator:<; 104, 105; 104, 108; 105, binary_operator:+; 105, 106; 105, 107; 106, identifier:time_idx; 107, integer:1; 108, subscript; 108, 109; 108, 114; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:data; 113, identifier:dims; 114, string:'time'; 115, block; 115, 116; 115, 128; 115, 142; 115, 156; 115, 173; 115, 189; 115, 213; 115, 243; 115, 254; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:start_time; 119, attribute; 119, 120; 119, 127; 120, subscript; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:data; 125, identifier:time; 126, identifier:time_idx; 127, identifier:values; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:end_time; 131, attribute; 131, 132; 131, 141; 132, subscript; 132, 133; 132, 138; 133, attribute; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:data; 137, identifier:time; 138, binary_operator:+; 138, 139; 138, 140; 139, identifier:time_idx; 140, integer:1; 141, identifier:values; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:slope_timeslice; 145, call; 145, 146; 145, 147; 146, identifier:slice; 147, argument_list; 147, 148; 147, 152; 148, call; 148, 149; 148, 150; 149, identifier:str; 150, argument_list; 150, 151; 151, identifier:start_time; 152, call; 152, 153; 152, 154; 153, identifier:str; 154, argument_list; 154, 155; 155, identifier:end_time; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:slice_size; 159, binary_operator:-; 159, 160; 159, 172; 160, subscript; 160, 161; 160, 171; 161, attribute; 161, 162; 161, 170; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:resampled_data; 165, identifier:sel; 166, argument_list; 166, 167; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:time; 169, identifier:slope_timeslice; 170, identifier:dims; 171, string:'time'; 172, integer:1; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:first_timestep; 176, subscript; 176, 177; 176, 188; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:resampled_data; 180, identifier:sel; 181, argument_list; 181, 182; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:time; 184, call; 184, 185; 184, 186; 185, identifier:str; 186, argument_list; 186, 187; 187, identifier:start_time; 188, identifier:gssha_data_var; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:slope; 192, binary_operator:/; 192, 193; 192, 209; 193, parenthesized_expression; 193, 194; 194, binary_operator:-; 194, 195; 194, 208; 195, subscript; 195, 196; 195, 207; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:resampled_data; 199, identifier:sel; 200, argument_list; 200, 201; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:time; 203, call; 203, 204; 203, 205; 204, identifier:str; 205, argument_list; 205, 206; 206, identifier:end_time; 207, identifier:gssha_data_var; 208, identifier:first_timestep; 209, call; 209, 210; 209, 211; 210, identifier:float; 211, argument_list; 211, 212; 212, identifier:slice_size; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:data_timeslice; 216, call; 216, 217; 216, 218; 217, identifier:slice; 218, argument_list; 218, 219; 218, 231; 219, call; 219, 220; 219, 221; 220, identifier:str; 221, argument_list; 221, 222; 222, binary_operator:+; 222, 223; 222, 224; 223, identifier:start_time; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:np; 227, identifier:timedelta64; 228, argument_list; 228, 229; 228, 230; 229, integer:1; 230, string:'m'; 231, call; 231, 232; 231, 233; 232, identifier:str; 233, argument_list; 233, 234; 234, binary_operator:-; 234, 235; 234, 236; 235, identifier:end_time; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:np; 239, identifier:timedelta64; 240, argument_list; 240, 241; 240, 242; 241, integer:1; 242, string:'m'; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:data_subset; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:resampled_data; 249, identifier:sel; 250, argument_list; 250, 251; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:time; 253, identifier:data_timeslice; 254, for_statement; 254, 255; 254, 256; 254, 264; 255, identifier:xidx; 256, call; 256, 257; 256, 258; 257, identifier:range; 258, argument_list; 258, 259; 259, subscript; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:data_subset; 262, identifier:dims; 263, string:'time'; 264, block; 264, 265; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 272; 267, subscript; 267, 268; 267, 271; 268, subscript; 268, 269; 268, 270; 269, identifier:data_subset; 270, identifier:gssha_data_var; 271, identifier:xidx; 272, binary_operator:+; 272, 273; 272, 274; 273, identifier:first_timestep; 274, binary_operator:*; 274, 275; 274, 276; 275, identifier:slope; 276, parenthesized_expression; 276, 277; 277, binary_operator:+; 277, 278; 277, 279; 278, identifier:xidx; 279, integer:1; 280, else_clause; 280, 281; 281, block; 281, 282; 281, 294; 281, 305; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:start_time; 285, attribute; 285, 286; 285, 293; 286, subscript; 286, 287; 286, 292; 287, attribute; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:self; 290, identifier:data; 291, identifier:time; 292, identifier:time_idx; 293, identifier:values; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:end_time; 297, attribute; 297, 298; 297, 304; 298, subscript; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:resampled_data; 301, identifier:time; 302, unary_operator:-; 302, 303; 303, integer:1; 304, identifier:values; 305, if_statement; 305, 306; 305, 309; 306, comparison_operator:>; 306, 307; 306, 308; 307, identifier:end_time; 308, identifier:start_time; 309, block; 309, 310; 309, 326; 309, 340; 309, 351; 309, 355; 309, 368; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:first_timestep; 313, subscript; 313, 314; 313, 325; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:resampled_data; 317, identifier:sel; 318, argument_list; 318, 319; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:time; 321, call; 321, 322; 321, 323; 322, identifier:str; 323, argument_list; 323, 324; 324, identifier:start_time; 325, identifier:gssha_data_var; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 329; 328, identifier:data_timeslice; 329, call; 329, 330; 329, 331; 330, identifier:slice; 331, argument_list; 331, 332; 331, 336; 332, call; 332, 333; 332, 334; 333, identifier:str; 334, argument_list; 334, 335; 335, identifier:start_time; 336, call; 336, 337; 336, 338; 337, identifier:str; 338, argument_list; 338, 339; 339, identifier:end_time; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:data_subset; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:resampled_data; 346, identifier:sel; 347, argument_list; 347, 348; 348, keyword_argument; 348, 349; 348, 350; 349, identifier:time; 350, identifier:data_timeslice; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 354; 353, identifier:slice_size; 354, integer:1; 355, if_statement; 355, 356; 355, 359; 356, comparison_operator:==; 356, 357; 356, 358; 357, identifier:calc_function; 358, string:"mean"; 359, block; 359, 360; 360, expression_statement; 360, 361; 361, assignment; 361, 362; 361, 363; 362, identifier:slice_size; 363, subscript; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:data_subset; 366, identifier:dims; 367, string:'time'; 368, for_statement; 368, 369; 368, 370; 368, 378; 369, identifier:xidx; 370, call; 370, 371; 370, 372; 371, identifier:range; 372, argument_list; 372, 373; 373, subscript; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, identifier:data_subset; 376, identifier:dims; 377, string:'time'; 378, block; 378, 379; 379, expression_statement; 379, 380; 380, assignment; 380, 381; 380, 386; 381, subscript; 381, 382; 381, 385; 382, subscript; 382, 383; 382, 384; 383, identifier:data_subset; 384, identifier:gssha_data_var; 385, identifier:xidx; 386, binary_operator:/; 386, 387; 386, 388; 387, identifier:first_timestep; 388, call; 388, 389; 388, 390; 389, identifier:float; 390, argument_list; 390, 391; 391, identifier:slice_size; 392, if_statement; 392, 393; 392, 396; 393, comparison_operator:is; 393, 394; 393, 395; 394, identifier:resampled_data; 395, None; 396, block; 396, 397; 396, 436; 396, 475; 397, if_statement; 397, 398; 397, 409; 398, comparison_operator:not; 398, 399; 398, 406; 399, attribute; 399, 400; 399, 405; 400, attribute; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:self; 403, identifier:data; 404, identifier:lsm; 405, identifier:x_var; 406, attribute; 406, 407; 406, 408; 407, identifier:resampled_data; 408, identifier:coords; 409, block; 409, 410; 410, expression_statement; 410, 411; 411, assignment; 411, 412; 411, 423; 412, subscript; 412, 413; 412, 416; 413, attribute; 413, 414; 413, 415; 414, identifier:resampled_data; 415, identifier:coords; 416, attribute; 416, 417; 416, 422; 417, attribute; 417, 418; 417, 421; 418, attribute; 418, 419; 418, 420; 419, identifier:self; 420, identifier:data; 421, identifier:lsm; 422, identifier:x_var; 423, subscript; 423, 424; 423, 429; 424, attribute; 424, 425; 424, 428; 425, attribute; 425, 426; 425, 427; 426, identifier:self; 427, identifier:data; 428, identifier:coords; 429, attribute; 429, 430; 429, 435; 430, attribute; 430, 431; 430, 434; 431, attribute; 431, 432; 431, 433; 432, identifier:self; 433, identifier:data; 434, identifier:lsm; 435, identifier:x_var; 436, if_statement; 436, 437; 436, 448; 437, comparison_operator:not; 437, 438; 437, 445; 438, attribute; 438, 439; 438, 444; 439, attribute; 439, 440; 439, 443; 440, attribute; 440, 441; 440, 442; 441, identifier:self; 442, identifier:data; 443, identifier:lsm; 444, identifier:y_var; 445, attribute; 445, 446; 445, 447; 446, identifier:resampled_data; 447, identifier:coords; 448, block; 448, 449; 449, expression_statement; 449, 450; 450, assignment; 450, 451; 450, 462; 451, subscript; 451, 452; 451, 455; 452, attribute; 452, 453; 452, 454; 453, identifier:resampled_data; 454, identifier:coords; 455, attribute; 455, 456; 455, 461; 456, attribute; 456, 457; 456, 460; 457, attribute; 457, 458; 457, 459; 458, identifier:self; 459, identifier:data; 460, identifier:lsm; 461, identifier:y_var; 462, subscript; 462, 463; 462, 468; 463, attribute; 463, 464; 463, 467; 464, attribute; 464, 465; 464, 466; 465, identifier:self; 466, identifier:data; 467, identifier:coords; 468, attribute; 468, 469; 468, 474; 469, attribute; 469, 470; 469, 473; 470, attribute; 470, 471; 470, 472; 471, identifier:self; 472, identifier:data; 473, identifier:lsm; 474, identifier:y_var; 475, expression_statement; 475, 476; 476, assignment; 476, 477; 476, 480; 477, attribute; 477, 478; 477, 479; 478, identifier:self; 479, identifier:data; 480, identifier:resampled_data
def _convert_data_to_hourly(self, gssha_data_var): time_step_hours = np.diff(self.data.time)[0]/np.timedelta64(1, 'h') calc_function = self._get_calc_function(gssha_data_var) resampled_data = None if time_step_hours < 1: resampled_data = self.data.resample('1H', dim='time', how=calc_function, keep_attrs=True) elif time_step_hours > 1: resampled_data = self.data.resample('1H', dim='time', keep_attrs=True) for time_idx in range(self.data.dims['time']): if time_idx+1 < self.data.dims['time']: start_time = self.data.time[time_idx].values end_time = self.data.time[time_idx+1].values slope_timeslice = slice(str(start_time), str(end_time)) slice_size = resampled_data.sel(time=slope_timeslice).dims['time'] - 1 first_timestep = resampled_data.sel(time=str(start_time))[gssha_data_var] slope = (resampled_data.sel(time=str(end_time))[gssha_data_var] - first_timestep)/float(slice_size) data_timeslice = slice(str(start_time+np.timedelta64(1, 'm')), str(end_time-np.timedelta64(1, 'm'))) data_subset = resampled_data.sel(time=data_timeslice) for xidx in range(data_subset.dims['time']): data_subset[gssha_data_var][xidx] = first_timestep + slope * (xidx+1) else: start_time = self.data.time[time_idx].values end_time = resampled_data.time[-1].values if end_time > start_time: first_timestep = resampled_data.sel(time=str(start_time))[gssha_data_var] data_timeslice = slice(str(start_time), str(end_time)) data_subset = resampled_data.sel(time=data_timeslice) slice_size = 1 if calc_function == "mean": slice_size = data_subset.dims['time'] for xidx in range(data_subset.dims['time']): data_subset[gssha_data_var][xidx] = first_timestep/float(slice_size) if resampled_data is not None: if self.data.lsm.x_var not in resampled_data.coords: resampled_data.coords[self.data.lsm.x_var] = self.data.coords[self.data.lsm.x_var] if self.data.lsm.y_var not in resampled_data.coords: resampled_data.coords[self.data.lsm.y_var] = self.data.coords[self.data.lsm.y_var] self.data = resampled_data
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_sub_dsp; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:nodes_bunch; 6, default_parameter; 6, 7; 6, 8; 7, identifier:edges_bunch; 8, None; 9, block; 9, 10; 9, 27; 9, 49; 9, 63; 9, 77; 9, 85; 9, 122; 9, 137; 9, 173; 9, 178; 9, 195; 9, 213; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:nodes_bunch; 13, list_comprehension; 13, 14; 13, 24; 14, subscript; 14, 15; 14, 23; 15, subscript; 15, 16; 15, 22; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:get_node; 20, argument_list; 20, 21; 21, identifier:u; 22, integer:1; 23, integer:0; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:u; 26, identifier:nodes_bunch; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:sub_dsp; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:copy_structure; 34, argument_list; 34, 35; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:dmap; 37, call; 37, 38; 37, 48; 38, attribute; 38, 39; 38, 47; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:dmap; 44, identifier:subgraph; 45, argument_list; 45, 46; 46, identifier:nodes_bunch; 47, identifier:copy; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, pattern_list; 51, 52; 51, 53; 52, identifier:nodes; 53, identifier:dmap_out_degree; 54, expression_list; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:sub_dsp; 57, identifier:nodes; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:sub_dsp; 61, identifier:dmap; 62, identifier:out_degree; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, pattern_list; 65, 66; 65, 67; 66, identifier:dmap_dv; 67, identifier:dmap_rm_edge; 68, expression_list; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:default_values; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:sub_dsp; 75, identifier:dmap; 76, identifier:remove_edge; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:dmap_rm_node; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:sub_dsp; 83, identifier:dmap; 84, identifier:remove_node; 85, for_statement; 85, 86; 85, 87; 85, 88; 86, identifier:u; 87, identifier:nodes_bunch; 88, block; 88, 89; 88, 101; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:n; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, subscript; 94, 95; 94, 96; 95, identifier:nodes; 96, identifier:u; 97, identifier:get; 98, argument_list; 98, 99; 98, 100; 99, string:'inputs'; 100, None; 101, if_statement; 101, 102; 101, 116; 102, boolean_operator:and; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:n; 105, None; 106, not_operator; 106, 107; 107, call; 107, 108; 107, 114; 108, attribute; 108, 109; 108, 113; 109, call; 109, 110; 109, 111; 110, identifier:set; 111, argument_list; 111, 112; 112, identifier:n; 113, identifier:issubset; 114, argument_list; 114, 115; 115, identifier:nodes_bunch; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:dmap_rm_node; 120, argument_list; 120, 121; 121, identifier:u; 122, if_statement; 122, 123; 122, 126; 123, comparison_operator:is; 123, 124; 123, 125; 124, identifier:edges_bunch; 125, None; 126, block; 126, 127; 127, for_statement; 127, 128; 127, 129; 127, 130; 128, identifier:e; 129, identifier:edges_bunch; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:dmap_rm_edge; 134, argument_list; 134, 135; 135, list_splat; 135, 136; 136, identifier:e; 137, for_statement; 137, 138; 137, 139; 137, 160; 138, identifier:u; 139, list_comprehension; 139, 140; 139, 141; 139, 154; 140, identifier:u; 141, for_in_clause; 141, 142; 141, 145; 142, pattern_list; 142, 143; 142, 144; 143, identifier:u; 144, identifier:n; 145, call; 145, 146; 145, 153; 146, attribute; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:sub_dsp; 150, identifier:dmap; 151, identifier:nodes; 152, identifier:items; 153, argument_list; 154, if_clause; 154, 155; 155, comparison_operator:==; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:n; 158, string:'type'; 159, string:'function'; 160, block; 160, 161; 161, if_statement; 161, 162; 161, 167; 162, not_operator; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:dmap_out_degree; 165, argument_list; 165, 166; 166, identifier:u; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:dmap_rm_node; 171, argument_list; 171, 172; 172, identifier:u; 173, import_from_statement; 173, 174; 173, 176; 174, dotted_name; 174, 175; 175, identifier:networkx; 176, dotted_name; 176, 177; 177, identifier:isolates; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:sub_dsp; 183, identifier:dmap; 184, identifier:remove_nodes_from; 185, argument_list; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:list; 188, argument_list; 188, 189; 189, call; 189, 190; 189, 191; 190, identifier:isolates; 191, argument_list; 191, 192; 192, attribute; 192, 193; 192, 194; 193, identifier:sub_dsp; 194, identifier:dmap; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:sub_dsp; 199, identifier:default_values; 200, dictionary_comprehension; 200, 201; 200, 206; 200, 209; 201, pair; 201, 202; 201, 203; 202, identifier:k; 203, subscript; 203, 204; 203, 205; 204, identifier:dmap_dv; 205, identifier:k; 206, for_in_clause; 206, 207; 206, 208; 207, identifier:k; 208, identifier:dmap_dv; 209, if_clause; 209, 210; 210, comparison_operator:in; 210, 211; 210, 212; 211, identifier:k; 212, identifier:nodes; 213, return_statement; 213, 214; 214, identifier:sub_dsp
def get_sub_dsp(self, nodes_bunch, edges_bunch=None): nodes_bunch = [self.get_node(u)[1][0] for u in nodes_bunch] sub_dsp = self.copy_structure( dmap=self.dmap.subgraph(nodes_bunch).copy() ) nodes, dmap_out_degree = sub_dsp.nodes, sub_dsp.dmap.out_degree dmap_dv, dmap_rm_edge = self.default_values, sub_dsp.dmap.remove_edge dmap_rm_node = sub_dsp.dmap.remove_node for u in nodes_bunch: n = nodes[u].get('inputs', None) if n is not None and not set(n).issubset(nodes_bunch): dmap_rm_node(u) if edges_bunch is not None: for e in edges_bunch: dmap_rm_edge(*e) for u in [u for u, n in sub_dsp.dmap.nodes.items() if n['type'] == 'function']: if not dmap_out_degree(u): dmap_rm_node(u) from networkx import isolates sub_dsp.dmap.remove_nodes_from(list(isolates(sub_dsp.dmap))) sub_dsp.default_values = {k: dmap_dv[k] for k in dmap_dv if k in nodes} return sub_dsp
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:blue; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:memo; 7, None; 8, block; 8, 9; 8, 18; 8, 27; 8, 35; 8, 45; 8, 75; 8, 81; 8, 90; 8, 106; 8, 144; 8, 301; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:memo; 12, conditional_expression:if; 12, 13; 12, 14; 12, 17; 13, dictionary; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:memo; 16, None; 17, identifier:memo; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:in; 19, 20; 19, 21; 20, identifier:self; 21, identifier:memo; 22, block; 22, 23; 23, return_statement; 23, 24; 24, subscript; 24, 25; 24, 26; 25, identifier:memo; 26, identifier:self; 27, import_from_statement; 27, 28; 27, 33; 28, relative_import; 28, 29; 28, 30; 29, import_prefix; 30, dotted_name; 30, 31; 30, 32; 31, identifier:utils; 32, identifier:dsp; 33, dotted_name; 33, 34; 34, identifier:map_list; 35, import_from_statement; 35, 36; 35, 41; 35, 43; 36, relative_import; 36, 37; 36, 38; 37, import_prefix; 38, dotted_name; 38, 39; 38, 40; 39, identifier:utils; 40, identifier:blue; 41, dotted_name; 41, 42; 42, identifier:BlueDispatcher; 43, dotted_name; 43, 44; 44, identifier:_parent_blue; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:memo; 49, identifier:self; 50, assignment; 50, 51; 50, 52; 51, identifier:blue; 52, call; 52, 53; 52, 54; 53, identifier:BlueDispatcher; 54, argument_list; 54, 55; 54, 60; 54, 65; 54, 70; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:executor; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:executor; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:name; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:name; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:raises; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:raises; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:description; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:__doc__; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:dfl; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:default_values; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:key_map_data; 84, list:['data_id', {'value': 'default_value'}]; 84, 85; 84, 86; 85, string:'data_id'; 86, dictionary; 86, 87; 87, pair; 87, 88; 87, 89; 88, string:'value'; 89, string:'default_value'; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, pattern_list; 92, 93; 92, 94; 93, identifier:pred; 94, identifier:succ; 95, expression_list; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:dmap; 100, identifier:pred; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:dmap; 105, identifier:succ; 106, function_definition; 106, 107; 106, 108; 106, 112; 107, function_name:_set_weight; 108, parameters; 108, 109; 108, 110; 108, 111; 109, identifier:n; 110, identifier:r; 111, identifier:d; 112, block; 112, 113; 112, 135; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:d; 116, dictionary_comprehension; 116, 117; 116, 122; 116, 131; 117, pair; 117, 118; 117, 119; 118, identifier:i; 119, subscript; 119, 120; 119, 121; 120, identifier:j; 121, string:'weight'; 122, for_in_clause; 122, 123; 122, 126; 123, pattern_list; 123, 124; 123, 125; 124, identifier:i; 125, identifier:j; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:d; 129, identifier:items; 130, argument_list; 131, if_clause; 131, 132; 132, comparison_operator:in; 132, 133; 132, 134; 133, string:'weight'; 134, identifier:j; 135, if_statement; 135, 136; 135, 137; 136, identifier:d; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:r; 142, identifier:n; 143, identifier:d; 144, for_statement; 144, 145; 144, 148; 144, 168; 145, pattern_list; 145, 146; 145, 147; 146, identifier:k; 147, identifier:v; 148, call; 148, 149; 148, 150; 149, identifier:sorted; 150, argument_list; 150, 151; 150, 158; 151, call; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:nodes; 156, identifier:items; 157, argument_list; 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, subscript; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:x; 166, integer:1; 167, string:'index'; 168, block; 168, 169; 168, 177; 168, 186; 168, 190; 168, 290; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:v; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:v; 175, identifier:copy; 176, argument_list; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:t; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:v; 183, identifier:pop; 184, argument_list; 184, 185; 185, string:'type'; 186, delete_statement; 186, 187; 187, subscript; 187, 188; 187, 189; 188, identifier:v; 189, string:'index'; 190, if_statement; 190, 191; 190, 194; 190, 218; 191, comparison_operator:==; 191, 192; 191, 193; 192, identifier:t; 193, string:'data'; 194, block; 194, 195; 194, 199; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:method; 198, string:'add_data'; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:combine_dicts; 202, argument_list; 202, 203; 202, 215; 203, call; 203, 204; 203, 205; 204, identifier:map_list; 205, argument_list; 205, 206; 205, 207; 205, 208; 206, identifier:key_map_data; 207, identifier:k; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:dfl; 211, identifier:get; 212, argument_list; 212, 213; 212, 214; 213, identifier:k; 214, dictionary; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:base; 217, identifier:v; 218, elif_clause; 218, 219; 218, 224; 219, comparison_operator:in; 219, 220; 219, 221; 220, identifier:t; 221, tuple; 221, 222; 221, 223; 222, string:'function'; 223, string:'dispatcher'; 224, block; 224, 225; 224, 231; 224, 240; 224, 248; 224, 252; 224, 261; 224, 270; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:method; 228, binary_operator:%; 228, 229; 228, 230; 229, string:'add_%s'; 230, identifier:t; 231, if_statement; 231, 232; 231, 235; 232, comparison_operator:==; 232, 233; 232, 234; 233, identifier:t; 234, string:'dispatcher'; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:t; 239, string:'dsp'; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 247; 242, subscript; 242, 243; 242, 244; 243, identifier:v; 244, binary_operator:%; 244, 245; 244, 246; 245, string:'%s_id'; 246, identifier:t; 247, identifier:k; 248, delete_statement; 248, 249; 249, subscript; 249, 250; 249, 251; 250, identifier:v; 251, string:'wait_inputs'; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 255; 254, identifier:_set_weight; 255, argument_list; 255, 256; 255, 257; 255, 258; 256, string:'inp_weight'; 257, identifier:v; 258, subscript; 258, 259; 258, 260; 259, identifier:pred; 260, identifier:k; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 264; 263, identifier:_set_weight; 264, argument_list; 264, 265; 264, 266; 264, 267; 265, string:'out_weight'; 266, identifier:v; 267, subscript; 267, 268; 267, 269; 268, identifier:succ; 269, identifier:k; 270, if_statement; 270, 271; 270, 274; 271, comparison_operator:in; 271, 272; 271, 273; 272, string:'function'; 273, identifier:v; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 280; 277, subscript; 277, 278; 277, 279; 278, identifier:v; 279, identifier:t; 280, call; 280, 281; 280, 282; 281, identifier:_parent_blue; 282, argument_list; 282, 283; 282, 289; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:v; 286, identifier:pop; 287, argument_list; 287, 288; 288, string:'function'; 289, identifier:memo; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 297; 292, attribute; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:blue; 295, identifier:deferred; 296, identifier:append; 297, argument_list; 297, 298; 298, tuple; 298, 299; 298, 300; 299, identifier:method; 300, identifier:v; 301, return_statement; 301, 302; 302, identifier:blue
def blue(self, memo=None): memo = {} if memo is None else memo if self in memo: return memo[self] from .utils.dsp import map_list from .utils.blue import BlueDispatcher, _parent_blue memo[self] = blue = BlueDispatcher( executor=self.executor, name=self.name, raises=self.raises, description=self.__doc__ ) dfl = self.default_values key_map_data = ['data_id', {'value': 'default_value'}] pred, succ = self.dmap.pred, self.dmap.succ def _set_weight(n, r, d): d = {i: j['weight'] for i, j in d.items() if 'weight' in j} if d: r[n] = d for k, v in sorted(self.nodes.items(), key=lambda x: x[1]['index']): v = v.copy() t = v.pop('type') del v['index'] if t == 'data': method = 'add_data' combine_dicts(map_list(key_map_data, k, dfl.get(k, {})), base=v) elif t in ('function', 'dispatcher'): method = 'add_%s' % t if t == 'dispatcher': t = 'dsp' v['%s_id' % t] = k del v['wait_inputs'] _set_weight('inp_weight', v, pred[k]) _set_weight('out_weight', v, succ[k]) if 'function' in v: v[t] = _parent_blue(v.pop('function'), memo) blue.deferred.append((method, v)) return blue
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:findOutlet; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:shapefile_path; 6, block; 6, 7; 6, 12; 6, 21; 6, 30; 6, 38; 6, 46; 6, 53; 6, 63; 6, 72; 6, 80; 6, 87; 6, 98; 6, 106; 6, 117; 6, 125; 6, 145; 6, 151; 6, 155; 6, 351; 6, 361; 6, 367; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:check_watershed_boundary_geometry; 10, argument_list; 10, 11; 11, identifier:shapefile_path; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:shapefile; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:ogr; 18, identifier:Open; 19, argument_list; 19, 20; 20, identifier:shapefile_path; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:source_layer; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:shapefile; 27, identifier:GetLayer; 28, argument_list; 28, 29; 29, integer:0; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:source_lyr_proj; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:source_layer; 36, identifier:GetSpatialRef; 37, argument_list; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:osr_geographic_proj; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:osr; 44, identifier:SpatialReference; 45, argument_list; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:osr_geographic_proj; 50, identifier:ImportFromEPSG; 51, argument_list; 51, 52; 52, integer:4326; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:proj_transform; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:osr; 59, identifier:CoordinateTransformation; 60, argument_list; 60, 61; 60, 62; 61, identifier:source_lyr_proj; 62, identifier:osr_geographic_proj; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:boundary_feature; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:source_layer; 69, identifier:GetFeature; 70, argument_list; 70, 71; 71, integer:0; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:feat_geom; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:boundary_feature; 78, identifier:GetGeometryRef; 79, argument_list; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:feat_geom; 84, identifier:Transform; 85, argument_list; 85, 86; 86, identifier:proj_transform; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:polygon; 90, call; 90, 91; 90, 92; 91, identifier:shapely_loads; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:feat_geom; 96, identifier:ExportToWkb; 97, argument_list; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:mask_grid; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:getGrid; 105, argument_list; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:elevation_grid; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:getGrid; 113, argument_list; 113, 114; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:use_mask; 116, False; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:elevation_array; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:elevation_grid; 123, identifier:np_array; 124, argument_list; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:ma_elevation_array; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:np; 132, identifier:ma; 133, identifier:array; 134, argument_list; 134, 135; 134, 136; 135, identifier:elevation_array; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:mask; 138, comparison_operator:==; 138, 139; 138, 144; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:mask_grid; 142, identifier:np_array; 143, argument_list; 144, integer:0; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:min_elevation; 148, attribute; 148, 149; 148, 150; 149, identifier:sys; 150, identifier:maxsize; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:outlet_pt; 154, None; 155, for_statement; 155, 156; 155, 157; 155, 165; 156, identifier:coord; 157, call; 157, 158; 157, 159; 158, identifier:list; 159, argument_list; 159, 160; 160, attribute; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:polygon; 163, identifier:exterior; 164, identifier:coords; 165, block; 165, 166; 165, 184; 165, 191; 165, 336; 166, try_statement; 166, 167; 166, 180; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 173; 170, pattern_list; 170, 171; 170, 172; 171, identifier:col; 172, identifier:row; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:mask_grid; 176, identifier:lonlat2pixel; 177, argument_list; 177, 178; 178, list_splat; 178, 179; 179, identifier:coord; 180, except_clause; 180, 181; 180, 182; 181, identifier:IndexError; 182, block; 182, 183; 183, continue_statement; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:elevation_value; 187, subscript; 187, 188; 187, 189; 187, 190; 188, identifier:ma_elevation_array; 189, identifier:row; 190, identifier:col; 191, if_statement; 191, 192; 191, 199; 192, comparison_operator:is; 192, 193; 192, 194; 193, identifier:elevation_value; 194, attribute; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:np; 197, identifier:ma; 198, identifier:masked; 199, block; 199, 200; 199, 207; 199, 213; 199, 217; 199, 221; 199, 225; 199, 316; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:actual_value; 203, subscript; 203, 204; 203, 205; 203, 206; 204, identifier:elevation_array; 205, identifier:row; 206, identifier:col; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:max_diff; 210, attribute; 210, 211; 210, 212; 211, identifier:sys; 212, identifier:maxsize; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:nrow; 216, None; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:ncol; 220, None; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:nval; 224, None; 225, for_statement; 225, 226; 225, 227; 225, 246; 226, identifier:row_ix; 227, call; 227, 228; 227, 229; 228, identifier:range; 229, argument_list; 229, 230; 229, 237; 230, call; 230, 231; 230, 232; 231, identifier:max; 232, argument_list; 232, 233; 232, 236; 233, binary_operator:-; 233, 234; 233, 235; 234, identifier:row; 235, integer:5; 236, integer:0; 237, call; 237, 238; 237, 239; 238, identifier:min; 239, argument_list; 239, 240; 239, 243; 240, binary_operator:+; 240, 241; 240, 242; 241, identifier:row; 242, integer:5; 243, attribute; 243, 244; 243, 245; 244, identifier:mask_grid; 245, identifier:y_size; 246, block; 246, 247; 247, for_statement; 247, 248; 247, 249; 247, 268; 248, identifier:col_ix; 249, call; 249, 250; 249, 251; 250, identifier:range; 251, argument_list; 251, 252; 251, 259; 252, call; 252, 253; 252, 254; 253, identifier:max; 254, argument_list; 254, 255; 254, 258; 255, binary_operator:-; 255, 256; 255, 257; 256, identifier:col; 257, integer:5; 258, integer:0; 259, call; 259, 260; 259, 261; 260, identifier:min; 261, argument_list; 261, 262; 261, 265; 262, binary_operator:+; 262, 263; 262, 264; 263, identifier:col; 264, integer:5; 265, attribute; 265, 266; 265, 267; 266, identifier:mask_grid; 267, identifier:x_size; 268, block; 268, 269; 268, 276; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:val; 272, subscript; 272, 273; 272, 274; 272, 275; 273, identifier:ma_elevation_array; 274, identifier:row_ix; 275, identifier:col_ix; 276, if_statement; 276, 277; 276, 285; 277, not_operator; 277, 278; 278, comparison_operator:is; 278, 279; 278, 280; 279, identifier:val; 280, attribute; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:np; 283, identifier:ma; 284, identifier:masked; 285, block; 285, 286; 285, 295; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:val_diff; 289, call; 289, 290; 289, 291; 290, identifier:abs; 291, argument_list; 291, 292; 292, binary_operator:-; 292, 293; 292, 294; 293, identifier:val; 294, identifier:actual_value; 295, if_statement; 295, 296; 295, 299; 296, comparison_operator:<; 296, 297; 296, 298; 297, identifier:val_diff; 298, identifier:max_diff; 299, block; 299, 300; 299, 304; 299, 308; 299, 312; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:max_diff; 303, identifier:val_diff; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:nval; 307, identifier:val; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:nrow; 311, identifier:row_ix; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:ncol; 315, identifier:col_ix; 316, if_statement; 316, 317; 316, 323; 317, comparison_operator:not; 317, 318; 317, 319; 318, None; 319, tuple; 319, 320; 319, 321; 319, 322; 320, identifier:nrow; 321, identifier:ncol; 322, identifier:nval; 323, block; 323, 324; 323, 328; 323, 332; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:row; 327, identifier:nrow; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:col; 331, identifier:ncol; 332, expression_statement; 332, 333; 333, assignment; 333, 334; 333, 335; 334, identifier:elevation_value; 335, identifier:nval; 336, if_statement; 336, 337; 336, 340; 337, comparison_operator:<; 337, 338; 337, 339; 338, identifier:elevation_value; 339, identifier:min_elevation; 340, block; 340, 341; 340, 345; 341, expression_statement; 341, 342; 342, assignment; 342, 343; 342, 344; 343, identifier:min_elevation; 344, identifier:elevation_value; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 348; 347, identifier:outlet_pt; 348, tuple; 348, 349; 348, 350; 349, identifier:col; 350, identifier:row; 351, if_statement; 351, 352; 351, 355; 352, comparison_operator:is; 352, 353; 352, 354; 353, identifier:outlet_pt; 354, None; 355, block; 355, 356; 356, raise_statement; 356, 357; 357, call; 357, 358; 357, 359; 358, identifier:IndexError; 359, argument_list; 359, 360; 360, string:'No valid outlet points found on boundary ...'; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 366; 363, pattern_list; 363, 364; 363, 365; 364, identifier:outcol; 365, identifier:outrow; 366, identifier:outlet_pt; 367, expression_statement; 367, 368; 368, call; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:self; 371, identifier:setOutlet; 372, argument_list; 372, 373; 372, 378; 373, keyword_argument; 373, 374; 373, 375; 374, identifier:col; 375, binary_operator:+; 375, 376; 375, 377; 376, identifier:outcol; 377, integer:1; 378, keyword_argument; 378, 379; 378, 380; 379, identifier:row; 380, binary_operator:+; 380, 381; 380, 382; 381, identifier:outrow; 382, integer:1
def findOutlet(self, shapefile_path): check_watershed_boundary_geometry(shapefile_path) shapefile = ogr.Open(shapefile_path) source_layer = shapefile.GetLayer(0) source_lyr_proj = source_layer.GetSpatialRef() osr_geographic_proj = osr.SpatialReference() osr_geographic_proj.ImportFromEPSG(4326) proj_transform = osr.CoordinateTransformation(source_lyr_proj, osr_geographic_proj) boundary_feature = source_layer.GetFeature(0) feat_geom = boundary_feature.GetGeometryRef() feat_geom.Transform(proj_transform) polygon = shapely_loads(feat_geom.ExportToWkb()) mask_grid = self.getGrid() elevation_grid = self.getGrid(use_mask=False) elevation_array = elevation_grid.np_array() ma_elevation_array = np.ma.array(elevation_array, mask=mask_grid.np_array()==0) min_elevation = sys.maxsize outlet_pt = None for coord in list(polygon.exterior.coords): try: col, row = mask_grid.lonlat2pixel(*coord) except IndexError: continue elevation_value = ma_elevation_array[row, col] if elevation_value is np.ma.masked: actual_value = elevation_array[row, col] max_diff = sys.maxsize nrow = None ncol = None nval = None for row_ix in range(max(row-5, 0), min(row+5, mask_grid.y_size)): for col_ix in range(max(col-5, 0), min(col+5, mask_grid.x_size)): val = ma_elevation_array[row_ix, col_ix] if not val is np.ma.masked: val_diff = abs(val-actual_value) if val_diff < max_diff: max_diff = val_diff nval = val nrow = row_ix ncol = col_ix if None not in (nrow, ncol, nval): row = nrow col = ncol elevation_value = nval if elevation_value < min_elevation: min_elevation = elevation_value outlet_pt = (col, row) if outlet_pt is None: raise IndexError('No valid outlet points found on boundary ...') outcol, outrow = outlet_pt self.setOutlet(col=outcol+1, row=outrow+1)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_write; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:session; 6, identifier:openFile; 7, identifier:replaceParamFile; 8, block; 8, 9; 8, 15; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:events; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:precipEvents; 15, for_statement; 15, 16; 15, 17; 15, 18; 16, identifier:event; 17, identifier:events; 18, block; 18, 19; 18, 37; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:openFile; 23, identifier:write; 24, argument_list; 24, 25; 25, binary_operator:%; 25, 26; 25, 27; 26, string:'EVENT "%s"\nNRGAG %s\nNRPDS %s\n'; 27, tuple; 27, 28; 27, 31; 27, 34; 28, attribute; 28, 29; 28, 30; 29, identifier:event; 30, identifier:description; 31, attribute; 31, 32; 31, 33; 32, identifier:event; 33, identifier:nrGag; 34, attribute; 34, 35; 34, 36; 35, identifier:event; 36, identifier:nrPds; 37, if_statement; 37, 38; 37, 43; 38, comparison_operator:>; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:event; 41, identifier:nrGag; 42, integer:0; 43, block; 43, 44; 43, 50; 43, 54; 43, 87; 43, 102; 43, 134; 43, 156; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:values; 47, attribute; 47, 48; 47, 49; 48, identifier:event; 49, identifier:values; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:valList; 53, list:[]; 54, for_statement; 54, 55; 54, 56; 54, 57; 55, identifier:value; 56, identifier:values; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:valList; 62, identifier:append; 63, argument_list; 63, 64; 64, dictionary; 64, 65; 64, 70; 64, 75; 64, 82; 65, pair; 65, 66; 65, 67; 66, string:'ValueType'; 67, attribute; 67, 68; 67, 69; 68, identifier:value; 69, identifier:valueType; 70, pair; 70, 71; 70, 72; 71, string:'DateTime'; 72, attribute; 72, 73; 72, 74; 73, identifier:value; 74, identifier:dateTime; 75, pair; 75, 76; 75, 77; 76, string:'Gage'; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:value; 80, identifier:gage; 81, identifier:id; 82, pair; 82, 83; 82, 84; 83, string:'Value'; 84, attribute; 84, 85; 84, 86; 85, identifier:value; 86, identifier:value; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:pivotedValues; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:pivot; 93, identifier:pivot; 94, argument_list; 94, 95; 94, 96; 94, 99; 94, 101; 95, identifier:valList; 96, tuple; 96, 97; 96, 98; 97, string:'DateTime'; 98, string:'ValueType'; 99, tuple; 99, 100; 100, string:'Gage'; 101, string:'Value'; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:gages; 105, call; 105, 106; 105, 133; 106, attribute; 106, 107; 106, 131; 106, 132; 107, call; 107, 108; 107, 127; 108, attribute; 108, 109; 108, 125; 108, 126; 109, call; 109, 110; 109, 119; 110, attribute; 110, 111; 110, 117; 110, 118; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:session; 114, identifier:query; 115, argument_list; 115, 116; 116, identifier:PrecipGage; 117, line_continuation:\; 118, identifier:filter; 119, argument_list; 119, 120; 120, comparison_operator:==; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:PrecipGage; 123, identifier:event; 124, identifier:event; 125, line_continuation:\; 126, identifier:order_by; 127, argument_list; 127, 128; 128, attribute; 128, 129; 128, 130; 129, identifier:PrecipGage; 130, identifier:id; 131, line_continuation:\; 132, identifier:all; 133, argument_list; 134, for_statement; 134, 135; 134, 136; 134, 137; 135, identifier:gage; 136, identifier:gages; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:openFile; 142, identifier:write; 143, argument_list; 143, 144; 144, binary_operator:%; 144, 145; 144, 146; 145, string:'COORD %s %s "%s"\n'; 146, tuple; 146, 147; 146, 150; 146, 153; 147, attribute; 147, 148; 147, 149; 148, identifier:gage; 149, identifier:x; 150, attribute; 150, 151; 150, 152; 151, identifier:gage; 152, identifier:y; 153, attribute; 153, 154; 153, 155; 154, identifier:gage; 155, identifier:description; 156, for_statement; 156, 157; 156, 158; 156, 159; 157, identifier:row; 158, identifier:pivotedValues; 159, block; 159, 160; 159, 164; 159, 183; 159, 206; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:valString; 163, string:''; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:keys; 167, call; 167, 168; 167, 169; 168, identifier:sorted; 169, argument_list; 169, 170; 170, list_comprehension; 170, 171; 170, 172; 170, 175; 171, identifier:key; 172, for_in_clause; 172, 173; 172, 174; 173, identifier:key; 174, identifier:row; 175, if_clause; 175, 176; 176, boolean_operator:and; 176, 177; 176, 180; 177, comparison_operator:!=; 177, 178; 177, 179; 178, identifier:key; 179, string:'DateTime'; 180, comparison_operator:!=; 180, 181; 180, 182; 181, identifier:key; 182, string:'ValueType'; 183, for_statement; 183, 184; 183, 185; 183, 186; 184, identifier:key; 185, identifier:keys; 186, block; 186, 187; 187, if_statement; 187, 188; 187, 195; 188, boolean_operator:and; 188, 189; 188, 192; 189, comparison_operator:!=; 189, 190; 189, 191; 190, identifier:key; 191, string:'DateTime'; 192, comparison_operator:!=; 192, 193; 192, 194; 193, identifier:key; 194, string:'ValueType'; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:valString; 199, binary_operator:%; 199, 200; 199, 201; 200, string:'%s %.3f'; 201, tuple; 201, 202; 201, 203; 202, identifier:valString; 203, subscript; 203, 204; 203, 205; 204, identifier:row; 205, identifier:key; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:openFile; 210, identifier:write; 211, argument_list; 211, 212; 212, binary_operator:%; 212, 213; 212, 214; 213, string:'%s %.4d %.2d %.2d %.2d %.2d%s\n'; 214, tuple; 214, 215; 214, 218; 214, 223; 214, 228; 214, 233; 214, 238; 214, 243; 215, subscript; 215, 216; 215, 217; 216, identifier:row; 217, string:'ValueType'; 218, attribute; 218, 219; 218, 222; 219, subscript; 219, 220; 219, 221; 220, identifier:row; 221, string:'DateTime'; 222, identifier:year; 223, attribute; 223, 224; 223, 227; 224, subscript; 224, 225; 224, 226; 225, identifier:row; 226, string:'DateTime'; 227, identifier:month; 228, attribute; 228, 229; 228, 232; 229, subscript; 229, 230; 229, 231; 230, identifier:row; 231, string:'DateTime'; 232, identifier:day; 233, attribute; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:row; 236, string:'DateTime'; 237, identifier:hour; 238, attribute; 238, 239; 238, 242; 239, subscript; 239, 240; 239, 241; 240, identifier:row; 241, string:'DateTime'; 242, identifier:minute; 243, identifier:valString
def _write(self, session, openFile, replaceParamFile): events = self.precipEvents for event in events: openFile.write('EVENT "%s"\nNRGAG %s\nNRPDS %s\n' % (event.description, event.nrGag, event.nrPds)) if event.nrGag > 0: values = event.values valList = [] for value in values: valList.append({'ValueType': value.valueType, 'DateTime': value.dateTime, 'Gage': value.gage.id, 'Value': value.value}) pivotedValues = pivot.pivot(valList, ('DateTime', 'ValueType'), ('Gage',), 'Value') gages = session.query(PrecipGage). \ filter(PrecipGage.event == event). \ order_by(PrecipGage.id). \ all() for gage in gages: openFile.write('COORD %s %s "%s"\n' % (gage.x, gage.y, gage.description)) for row in pivotedValues: valString = '' keys = sorted([key for key in row if key != 'DateTime' and key != 'ValueType']) for key in keys: if key != 'DateTime' and key != 'ValueType': valString = '%s %.3f' % (valString, row[key]) openFile.write('%s %.4d %.2d %.2d %.2d %.2d%s\n' % ( row['ValueType'], row['DateTime'].year, row['DateTime'].month, row['DateTime'].day, row['DateTime'].hour, row['DateTime'].minute, valString))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:valueWritePreprocessor; 3, parameters; 3, 4; 3, 5; 4, identifier:valueString; 5, default_parameter; 5, 6; 5, 7; 6, identifier:replaceParamsFile; 7, None; 8, block; 8, 9; 8, 26; 8, 30; 8, 90; 9, if_statement; 9, 10; 9, 16; 10, comparison_operator:is; 10, 11; 10, 15; 11, call; 11, 12; 11, 13; 12, identifier:type; 13, argument_list; 13, 14; 14, identifier:valueString; 15, identifier:bool; 16, block; 16, 17; 16, 24; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:log; 21, identifier:warning; 22, argument_list; 22, 23; 23, string:"Only numerical variable types can be handled by the valueReadPreprocessor function."; 24, return_statement; 24, 25; 25, identifier:valueString; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:variableString; 29, identifier:valueString; 30, if_statement; 30, 31; 30, 34; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:replaceParamsFile; 33, None; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 39; 35, 44; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:variableString; 38, identifier:REPLACE_NO_VALUE; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:variableString; 43, string:'[NO_VARIABLE]'; 44, else_clause; 44, 45; 45, block; 45, 46; 46, try_statement; 46, 47; 46, 87; 47, block; 47, 48; 47, 55; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:number; 51, call; 51, 52; 51, 53; 52, identifier:int; 53, argument_list; 53, 54; 54, identifier:valueString; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:<; 56, 57; 56, 58; 57, identifier:number; 58, integer:0; 59, block; 59, 60; 59, 67; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:parameterID; 63, binary_operator:*; 63, 64; 63, 65; 64, identifier:number; 65, unary_operator:-; 65, 66; 66, integer:1; 67, for_statement; 67, 68; 67, 69; 67, 72; 68, identifier:targetParam; 69, attribute; 69, 70; 69, 71; 70, identifier:replaceParamsFile; 71, identifier:targetParameters; 72, block; 72, 73; 73, if_statement; 73, 74; 73, 79; 74, comparison_operator:==; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:targetParam; 77, identifier:id; 78, identifier:parameterID; 79, block; 79, 80; 79, 86; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:variableString; 83, attribute; 83, 84; 83, 85; 84, identifier:targetParam; 85, identifier:targetVariable; 86, break_statement; 87, except_clause; 87, 88; 88, block; 88, 89; 89, pass_statement; 90, return_statement; 90, 91; 91, identifier:variableString
def valueWritePreprocessor(valueString, replaceParamsFile=None): if type(valueString) is bool: log.warning("Only numerical variable types can be handled by the valueReadPreprocessor function.") return valueString variableString = valueString if replaceParamsFile is not None: if variableString == REPLACE_NO_VALUE: variableString = '[NO_VARIABLE]' else: try: number = int(valueString) if number < 0: parameterID = number * -1 for targetParam in replaceParamsFile.targetParameters: if targetParam.id == parameterID: variableString = targetParam.targetVariable break except: pass return variableString
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_createGsshaPyObjects; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:mapTables; 6, identifier:indexMaps; 7, identifier:replaceParamFile; 8, identifier:directory; 9, identifier:session; 10, identifier:spatial; 11, identifier:spatialReferenceID; 12, block; 12, 13; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:mt; 15, identifier:mapTables; 16, block; 16, 17; 17, try_statement; 17, 18; 17, 295; 18, block; 18, 19; 18, 32; 18, 87; 18, 93; 18, 108; 19, if_statement; 19, 20; 19, 25; 20, comparison_operator:is; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:mt; 23, string:'indexMapName'; 24, None; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, subscript; 27, 28; 27, 29; 28, identifier:indexMaps; 29, subscript; 29, 30; 29, 31; 30, identifier:mt; 31, string:'indexMapName'; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:mapTable; 35, call; 35, 36; 35, 37; 36, identifier:MapTable; 37, argument_list; 37, 38; 37, 43; 37, 50; 37, 57; 37, 67; 37, 77; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:name; 40, subscript; 40, 41; 40, 42; 41, identifier:mt; 42, string:'name'; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:numIDs; 45, subscript; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:mt; 48, string:'numVars'; 49, string:'NUM_IDS'; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:maxNumCells; 52, subscript; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:mt; 55, string:'numVars'; 56, string:'MAX_NUMBER_CELLS'; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:numSed; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:mt; 63, string:'numVars'; 64, identifier:get; 65, argument_list; 65, 66; 66, string:'NUM_SED'; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:numContam; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:mt; 73, string:'numVars'; 74, identifier:get; 75, argument_list; 75, 76; 76, string:'NUM_CONTAM'; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:maxSoilID; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:mt; 83, string:'numVars'; 84, identifier:get; 85, argument_list; 85, 86; 86, string:'MAX_SOIL_ID'; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:mapTable; 91, identifier:mapTableFile; 92, identifier:self; 93, if_statement; 93, 94; 93, 97; 94, subscript; 94, 95; 94, 96; 95, identifier:mt; 96, string:'indexMapName'; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:mapTable; 102, identifier:indexMap; 103, subscript; 103, 104; 103, 105; 104, identifier:indexMaps; 105, subscript; 105, 106; 105, 107; 106, identifier:mt; 107, string:'indexMapName'; 108, if_statement; 108, 109; 108, 114; 108, 216; 108, 269; 109, comparison_operator:==; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:mt; 112, string:'name'; 113, string:'CONTAMINANT_TRANSPORT'; 114, block; 114, 115; 115, for_statement; 115, 116; 115, 117; 115, 120; 116, identifier:contam; 117, subscript; 117, 118; 117, 119; 118, identifier:mt; 119, string:'contaminants'; 120, block; 120, 121; 120, 132; 120, 175; 120, 183; 120, 189; 120, 205; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:outputBaseFilename; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:_preprocessContaminantOutFilePath; 128, argument_list; 128, 129; 129, subscript; 129, 130; 129, 131; 130, identifier:contam; 131, string:'outPath'; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:contaminant; 135, call; 135, 136; 135, 137; 136, identifier:MTContaminant; 137, argument_list; 137, 138; 137, 143; 137, 146; 137, 157; 137, 168; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:name; 140, subscript; 140, 141; 140, 142; 141, identifier:contam; 142, string:'name'; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:outputFilename; 145, identifier:outputBaseFilename; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:precipConc; 148, call; 148, 149; 148, 150; 149, identifier:vrp; 150, argument_list; 150, 151; 150, 156; 151, subscript; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:contam; 154, string:'contamVars'; 155, string:'PRECIP_CONC'; 156, identifier:replaceParamFile; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:partition; 159, call; 159, 160; 159, 161; 160, identifier:vrp; 161, argument_list; 161, 162; 161, 167; 162, subscript; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:contam; 165, string:'contamVars'; 166, string:'PARTITION'; 167, identifier:replaceParamFile; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:numIDs; 170, subscript; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:contam; 173, string:'contamVars'; 174, string:'NUM_IDS'; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:indexMap; 178, subscript; 178, 179; 178, 180; 179, identifier:indexMaps; 180, subscript; 180, 181; 180, 182; 181, identifier:contam; 182, string:'indexMapName'; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:contaminant; 187, identifier:indexMap; 188, identifier:indexMap; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:_createValueObjects; 194, argument_list; 194, 195; 194, 198; 194, 201; 194, 202; 194, 203; 194, 204; 195, subscript; 195, 196; 195, 197; 196, identifier:contam; 197, string:'valueList'; 198, subscript; 198, 199; 198, 200; 199, identifier:contam; 200, string:'varList'; 201, identifier:mapTable; 202, identifier:indexMap; 203, identifier:contaminant; 204, identifier:replaceParamFile; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:_readContaminantOutputFiles; 210, argument_list; 210, 211; 210, 212; 210, 213; 210, 214; 210, 215; 211, identifier:directory; 212, identifier:outputBaseFilename; 213, identifier:session; 214, identifier:spatial; 215, identifier:spatialReferenceID; 216, elif_clause; 216, 217; 216, 222; 217, comparison_operator:==; 217, 218; 217, 221; 218, subscript; 218, 219; 218, 220; 219, identifier:mt; 220, string:'name'; 221, string:'SEDIMENTS'; 222, block; 222, 223; 223, for_statement; 223, 224; 223, 225; 223, 228; 224, identifier:line; 225, subscript; 225, 226; 225, 227; 226, identifier:mt; 227, string:'valueList'; 228, block; 228, 229; 228, 263; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:sediment; 232, call; 232, 233; 232, 234; 233, identifier:MTSediment; 234, argument_list; 234, 235; 234, 240; 234, 249; 234, 258; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:description; 237, subscript; 237, 238; 237, 239; 238, identifier:line; 239, integer:0; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:specificGravity; 242, call; 242, 243; 242, 244; 243, identifier:vrp; 244, argument_list; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:line; 247, integer:1; 248, identifier:replaceParamFile; 249, keyword_argument; 249, 250; 249, 251; 250, identifier:particleDiameter; 251, call; 251, 252; 251, 253; 252, identifier:vrp; 253, argument_list; 253, 254; 253, 257; 254, subscript; 254, 255; 254, 256; 255, identifier:line; 256, integer:2; 257, identifier:replaceParamFile; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:outputFilename; 260, subscript; 260, 261; 260, 262; 261, identifier:line; 262, integer:3; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:sediment; 267, identifier:mapTable; 268, identifier:mapTable; 269, else_clause; 269, 270; 270, block; 270, 271; 270, 279; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:indexMap; 274, subscript; 274, 275; 274, 276; 275, identifier:indexMaps; 276, subscript; 276, 277; 276, 278; 277, identifier:mt; 278, string:'indexMapName'; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:self; 283, identifier:_createValueObjects; 284, argument_list; 284, 285; 284, 288; 284, 291; 284, 292; 284, 293; 284, 294; 285, subscript; 285, 286; 285, 287; 286, identifier:mt; 287, string:'valueList'; 288, subscript; 288, 289; 288, 290; 289, identifier:mt; 290, string:'varList'; 291, identifier:mapTable; 292, identifier:indexMap; 293, None; 294, identifier:replaceParamFile; 295, except_clause; 295, 296; 295, 297; 296, identifier:KeyError; 297, block; 297, 298; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:log; 302, identifier:info; 303, argument_list; 303, 304; 304, binary_operator:%; 304, 305; 304, 309; 305, parenthesized_expression; 305, 306; 306, concatenated_string; 306, 307; 306, 308; 307, string:'Index Map "%s" for Mapping Table "%s" not found in list of index maps in the mapping '; 308, string:'table file. The Mapping Table was not read into the database.'; 309, tuple; 309, 310; 309, 313; 310, subscript; 310, 311; 310, 312; 311, identifier:mt; 312, string:'indexMapName'; 313, subscript; 313, 314; 313, 315; 314, identifier:mt; 315, string:'name'
def _createGsshaPyObjects(self, mapTables, indexMaps, replaceParamFile, directory, session, spatial, spatialReferenceID): for mt in mapTables: try: if mt['indexMapName'] is not None: indexMaps[mt['indexMapName']] mapTable = MapTable(name=mt['name'], numIDs=mt['numVars']['NUM_IDS'], maxNumCells=mt['numVars']['MAX_NUMBER_CELLS'], numSed=mt['numVars'].get('NUM_SED'), numContam=mt['numVars'].get('NUM_CONTAM'), maxSoilID=mt['numVars'].get('MAX_SOIL_ID')) mapTable.mapTableFile = self if mt['indexMapName']: mapTable.indexMap = indexMaps[mt['indexMapName']] if mt['name'] == 'CONTAMINANT_TRANSPORT': for contam in mt['contaminants']: outputBaseFilename = self._preprocessContaminantOutFilePath(contam['outPath']) contaminant = MTContaminant(name=contam['name'], outputFilename=outputBaseFilename, precipConc=vrp(contam['contamVars']['PRECIP_CONC'], replaceParamFile), partition=vrp(contam['contamVars']['PARTITION'], replaceParamFile), numIDs=contam['contamVars']['NUM_IDS']) indexMap = indexMaps[contam['indexMapName']] contaminant.indexMap = indexMap self._createValueObjects(contam['valueList'], contam['varList'], mapTable, indexMap, contaminant, replaceParamFile) self._readContaminantOutputFiles(directory, outputBaseFilename, session, spatial, spatialReferenceID) elif mt['name'] == 'SEDIMENTS': for line in mt['valueList']: sediment = MTSediment(description=line[0], specificGravity=vrp(line[1], replaceParamFile), particleDiameter=vrp(line[2], replaceParamFile), outputFilename=line[3]) sediment.mapTable = mapTable else: indexMap = indexMaps[mt['indexMapName']] self._createValueObjects(mt['valueList'], mt['varList'], mapTable, indexMap, None, replaceParamFile) except KeyError: log.info(('Index Map "%s" for Mapping Table "%s" not found in list of index maps in the mapping ' 'table file. The Mapping Table was not read into the database.') % ( mt['indexMapName'], mt['name']))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_valuePivot; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:session; 6, identifier:mapTable; 7, identifier:contaminant; 8, identifier:replaceParaFile; 9, block; 9, 10; 9, 60; 9, 65; 9, 81; 9, 85; 9, 89; 9, 345; 9, 349; 9, 404; 9, 420; 9, 428; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:indexes; 13, call; 13, 14; 13, 59; 14, attribute; 14, 15; 14, 57; 14, 58; 15, call; 15, 16; 15, 53; 16, attribute; 16, 17; 16, 51; 16, 52; 17, call; 17, 18; 17, 45; 18, attribute; 18, 19; 18, 43; 18, 44; 19, call; 19, 20; 19, 37; 20, attribute; 20, 21; 20, 35; 20, 36; 21, call; 21, 22; 21, 31; 22, attribute; 22, 23; 22, 29; 22, 30; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:session; 26, identifier:query; 27, argument_list; 27, 28; 28, identifier:MTIndex; 29, line_continuation:\; 30, identifier:join; 31, argument_list; 31, 32; 32, attribute; 32, 33; 32, 34; 33, identifier:MTValue; 34, identifier:index; 35, line_continuation:\; 36, identifier:filter; 37, argument_list; 37, 38; 38, comparison_operator:==; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:MTValue; 41, identifier:mapTable; 42, identifier:mapTable; 43, line_continuation:\; 44, identifier:filter; 45, argument_list; 45, 46; 46, comparison_operator:==; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:MTValue; 49, identifier:contaminant; 50, identifier:contaminant; 51, line_continuation:\; 52, identifier:order_by; 53, argument_list; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:MTIndex; 56, identifier:index; 57, line_continuation:\; 58, identifier:all; 59, argument_list; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:layer_indices; 63, list:[0]; 63, 64; 64, integer:0; 65, if_statement; 65, 66; 65, 73; 66, comparison_operator:in; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:mapTable; 69, identifier:name; 70, tuple; 70, 71; 70, 72; 71, string:'MULTI_LAYER_SOIL'; 72, string:'RICHARDS_EQN_INFILTRATION_BROOKS'; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:layer_indices; 77, call; 77, 78; 77, 79; 78, identifier:range; 79, argument_list; 79, 80; 80, integer:3; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:lines; 84, list:[]; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:values; 88, dictionary; 89, for_statement; 89, 90; 89, 91; 89, 92; 90, identifier:idx; 91, identifier:indexes; 92, block; 92, 93; 93, for_statement; 93, 94; 93, 95; 93, 96; 94, identifier:layer_index; 95, identifier:layer_indices; 96, block; 96, 97; 96, 159; 96, 163; 96, 213; 96, 231; 96, 246; 96, 261; 96, 338; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:values; 100, call; 100, 101; 100, 158; 101, attribute; 101, 102; 101, 156; 101, 157; 102, call; 102, 103; 102, 152; 103, attribute; 103, 104; 103, 150; 103, 151; 104, call; 104, 105; 104, 144; 105, attribute; 105, 106; 105, 142; 105, 143; 106, call; 106, 107; 106, 136; 107, attribute; 107, 108; 107, 134; 107, 135; 108, call; 108, 109; 108, 128; 109, attribute; 109, 110; 109, 126; 109, 127; 110, call; 110, 111; 110, 120; 111, attribute; 111, 112; 111, 118; 111, 119; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:session; 115, identifier:query; 116, argument_list; 116, 117; 117, identifier:MTValue; 118, line_continuation:\; 119, identifier:filter; 120, argument_list; 120, 121; 121, comparison_operator:==; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:MTValue; 124, identifier:mapTable; 125, identifier:mapTable; 126, line_continuation:\; 127, identifier:filter; 128, argument_list; 128, 129; 129, comparison_operator:==; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:MTValue; 132, identifier:contaminant; 133, identifier:contaminant; 134, line_continuation:\; 135, identifier:filter; 136, argument_list; 136, 137; 137, comparison_operator:==; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:MTValue; 140, identifier:index; 141, identifier:idx; 142, line_continuation:\; 143, identifier:filter; 144, argument_list; 144, 145; 145, comparison_operator:==; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:MTValue; 148, identifier:layer_id; 149, identifier:layer_index; 150, line_continuation:\; 151, identifier:order_by; 152, argument_list; 152, 153; 153, attribute; 153, 154; 153, 155; 154, identifier:MTValue; 155, identifier:id; 156, line_continuation:\; 157, identifier:all; 158, argument_list; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:valString; 162, string:''; 163, for_statement; 163, 164; 163, 165; 163, 166; 164, identifier:val; 165, identifier:values; 166, block; 166, 167; 166, 176; 166, 186; 166, 202; 167, if_statement; 167, 168; 167, 174; 168, comparison_operator:<=; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:val; 171, identifier:value; 172, unary_operator:-; 172, 173; 173, integer:9999; 174, block; 174, 175; 175, continue_statement; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:processedValue; 179, call; 179, 180; 179, 181; 180, identifier:vwp; 181, argument_list; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:val; 184, identifier:value; 185, identifier:replaceParaFile; 186, try_statement; 186, 187; 186, 194; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:numString; 191, binary_operator:%; 191, 192; 191, 193; 192, string:'%.6f'; 193, identifier:processedValue; 194, except_clause; 194, 195; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:numString; 199, binary_operator:%; 199, 200; 199, 201; 200, string:'%s'; 201, identifier:processedValue; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:valString; 205, binary_operator:%; 205, 206; 205, 207; 206, string:'%s%s%s'; 207, tuple; 207, 208; 207, 209; 207, 210; 208, identifier:valString; 209, identifier:numString; 210, binary_operator:*; 210, 211; 210, 212; 211, string:' '; 212, integer:3; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:spacing1; 216, call; 216, 217; 216, 218; 217, identifier:max; 218, argument_list; 218, 219; 218, 220; 219, integer:1; 220, binary_operator:-; 220, 221; 220, 222; 221, integer:6; 222, call; 222, 223; 222, 224; 223, identifier:len; 224, argument_list; 224, 225; 225, call; 225, 226; 225, 227; 226, identifier:str; 227, argument_list; 227, 228; 228, attribute; 228, 229; 228, 230; 229, identifier:idx; 230, identifier:index; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:spacing2; 234, call; 234, 235; 234, 236; 235, identifier:max; 236, argument_list; 236, 237; 236, 238; 237, integer:1; 238, binary_operator:-; 238, 239; 238, 240; 239, integer:40; 240, call; 240, 241; 240, 242; 241, identifier:len; 242, argument_list; 242, 243; 243, attribute; 243, 244; 243, 245; 244, identifier:idx; 245, identifier:description1; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:spacing3; 249, call; 249, 250; 249, 251; 250, identifier:max; 251, argument_list; 251, 252; 251, 253; 252, integer:1; 253, binary_operator:-; 253, 254; 253, 255; 254, integer:40; 255, call; 255, 256; 255, 257; 256, identifier:len; 257, argument_list; 257, 258; 258, attribute; 258, 259; 258, 260; 259, identifier:idx; 260, identifier:description2; 261, if_statement; 261, 262; 261, 265; 261, 291; 262, comparison_operator:==; 262, 263; 262, 264; 263, identifier:layer_index; 264, integer:0; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:line; 269, binary_operator:%; 269, 270; 269, 271; 270, string:'%s%s%s%s%s%s%s\n'; 271, tuple; 271, 272; 271, 275; 271, 278; 271, 281; 271, 284; 271, 287; 271, 290; 272, attribute; 272, 273; 272, 274; 273, identifier:idx; 274, identifier:index; 275, binary_operator:*; 275, 276; 275, 277; 276, string:' '; 277, identifier:spacing1; 278, attribute; 278, 279; 278, 280; 279, identifier:idx; 280, identifier:description1; 281, binary_operator:*; 281, 282; 281, 283; 282, string:' '; 283, identifier:spacing2; 284, attribute; 284, 285; 284, 286; 285, identifier:idx; 286, identifier:description2; 287, binary_operator:*; 287, 288; 287, 289; 288, string:' '; 289, identifier:spacing3; 290, identifier:valString; 291, else_clause; 291, 292; 292, block; 292, 293; 292, 326; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:num_prepend_spaces; 296, binary_operator:+; 296, 297; 296, 325; 297, binary_operator:+; 297, 298; 297, 319; 298, binary_operator:+; 298, 299; 298, 317; 298, 318; 299, binary_operator:+; 299, 300; 299, 311; 300, binary_operator:+; 300, 301; 300, 310; 301, call; 301, 302; 301, 303; 302, identifier:len; 303, argument_list; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:str; 306, argument_list; 306, 307; 307, attribute; 307, 308; 307, 309; 308, identifier:idx; 309, identifier:index; 310, identifier:spacing1; 311, call; 311, 312; 311, 313; 312, identifier:len; 313, argument_list; 313, 314; 314, attribute; 314, 315; 314, 316; 315, identifier:idx; 316, identifier:description1; 317, line_continuation:\; 318, identifier:spacing2; 319, call; 319, 320; 319, 321; 320, identifier:len; 321, argument_list; 321, 322; 322, attribute; 322, 323; 322, 324; 323, identifier:idx; 324, identifier:description2; 325, identifier:spacing3; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 329; 328, identifier:line; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, string:'{0}{1}\n'; 332, identifier:format; 333, argument_list; 333, 334; 333, 337; 334, binary_operator:*; 334, 335; 334, 336; 335, string:' '; 336, identifier:num_prepend_spaces; 337, identifier:valString; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:lines; 342, identifier:append; 343, argument_list; 343, 344; 344, identifier:line; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 348; 347, identifier:varString; 348, string:''; 349, for_statement; 349, 350; 349, 353; 349, 357; 350, pattern_list; 350, 351; 350, 352; 351, identifier:idx; 352, identifier:val; 353, call; 353, 354; 353, 355; 354, identifier:enumerate; 355, argument_list; 355, 356; 356, identifier:values; 357, block; 357, 358; 358, if_statement; 358, 359; 358, 364; 358, 389; 359, comparison_operator:==; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:val; 362, identifier:variable; 363, string:'XSEDIMENT'; 364, block; 364, 365; 365, if_statement; 365, 366; 365, 374; 366, comparison_operator:>=; 366, 367; 366, 368; 367, identifier:idx; 368, binary_operator:-; 368, 369; 368, 373; 369, call; 369, 370; 369, 371; 370, identifier:len; 371, argument_list; 371, 372; 372, identifier:values; 373, integer:1; 374, block; 374, 375; 375, expression_statement; 375, 376; 376, assignment; 376, 377; 376, 378; 377, identifier:varString; 378, binary_operator:%; 378, 379; 378, 380; 379, string:'%s%s%s%s'; 380, tuple; 380, 381; 380, 382; 380, 385; 380, 386; 381, identifier:varString; 382, attribute; 382, 383; 382, 384; 383, identifier:mapTable; 384, identifier:numSed; 385, string:' SEDIMENTS....'; 386, binary_operator:*; 386, 387; 386, 388; 387, string:' '; 388, integer:2; 389, else_clause; 389, 390; 390, block; 390, 391; 391, expression_statement; 391, 392; 392, assignment; 392, 393; 392, 394; 393, identifier:varString; 394, binary_operator:%; 394, 395; 394, 396; 395, string:'%s%s%s'; 396, tuple; 396, 397; 396, 398; 396, 401; 397, identifier:varString; 398, attribute; 398, 399; 398, 400; 399, identifier:val; 400, identifier:variable; 401, binary_operator:*; 401, 402; 401, 403; 402, string:' '; 403, integer:2; 404, expression_statement; 404, 405; 405, assignment; 405, 406; 405, 407; 406, identifier:header; 407, binary_operator:%; 407, 408; 407, 409; 408, string:'ID%sDESCRIPTION1%sDESCRIPTION2%s%s\n'; 409, tuple; 409, 410; 409, 413; 409, 416; 409, 419; 410, binary_operator:*; 410, 411; 410, 412; 411, string:' '; 412, integer:4; 413, binary_operator:*; 413, 414; 413, 415; 414, string:' '; 415, integer:28; 416, binary_operator:*; 416, 417; 416, 418; 417, string:' '; 418, integer:28; 419, identifier:varString; 420, expression_statement; 420, 421; 421, call; 421, 422; 421, 425; 422, attribute; 422, 423; 422, 424; 423, identifier:lines; 424, identifier:insert; 425, argument_list; 425, 426; 425, 427; 426, integer:0; 427, identifier:header; 428, return_statement; 428, 429; 429, identifier:lines
def _valuePivot(self, session, mapTable, contaminant, replaceParaFile): indexes = session.query(MTIndex). \ join(MTValue.index). \ filter(MTValue.mapTable == mapTable). \ filter(MTValue.contaminant == contaminant). \ order_by(MTIndex.index). \ all() layer_indices = [0] if mapTable.name in ('MULTI_LAYER_SOIL', 'RICHARDS_EQN_INFILTRATION_BROOKS'): layer_indices = range(3) lines = [] values = {} for idx in indexes: for layer_index in layer_indices: values = session.query(MTValue). \ filter(MTValue.mapTable == mapTable). \ filter(MTValue.contaminant == contaminant). \ filter(MTValue.index == idx). \ filter(MTValue.layer_id == layer_index). \ order_by(MTValue.id). \ all() valString = '' for val in values: if val.value <= -9999: continue processedValue = vwp(val.value, replaceParaFile) try: numString = '%.6f' % processedValue except: numString = '%s' % processedValue valString = '%s%s%s' % (valString, numString, ' ' * 3) spacing1 = max(1, 6 - len(str(idx.index))) spacing2 = max(1, 40 - len(idx.description1)) spacing3 = max(1, 40 - len(idx.description2)) if layer_index == 0: line = '%s%s%s%s%s%s%s\n' % ( idx.index, ' ' * spacing1, idx.description1, ' ' * spacing2, idx.description2, ' ' * spacing3, valString) else: num_prepend_spaces = len(str(idx.index)) + spacing1 + len(idx.description1) \ + spacing2 + len(idx.description2) + spacing3 line = '{0}{1}\n'.format(' ' * num_prepend_spaces, valString) lines.append(line) varString = '' for idx, val in enumerate(values): if val.variable == 'XSEDIMENT': if idx >= len(values) - 1: varString = '%s%s%s%s' % (varString, mapTable.numSed, ' SEDIMENTS....', ' ' * 2) else: varString = '%s%s%s' % (varString, val.variable, ' ' * 2) header = 'ID%sDESCRIPTION1%sDESCRIPTION2%s%s\n' % (' ' * 4, ' ' * 28, ' ' * 28, varString) lines.insert(0, header) return lines
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:addRoughnessMapFromLandUse; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:self; 5, identifier:name; 6, identifier:session; 7, identifier:land_use_grid; 8, default_parameter; 8, 9; 8, 10; 9, identifier:land_use_to_roughness_table; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:land_use_grid_id; 13, None; 14, block; 14, 15; 14, 28; 14, 136; 14, 147; 14, 169; 14, 182; 14, 195; 14, 218; 14, 226; 14, 252; 14, 261; 14, 267; 14, 273; 14, 279; 14, 331; 14, 342; 14, 358; 14, 371; 14, 397; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:LAND_USE_GRID_TABLES; 18, dictionary; 18, 19; 18, 22; 18, 25; 19, pair; 19, 20; 19, 21; 20, string:'nga'; 21, string:'land_cover_nga.txt'; 22, pair; 22, 23; 22, 24; 23, string:'glcf'; 24, string:'land_cover_glcf_modis.txt'; 25, pair; 25, 26; 25, 27; 26, string:'nlcd'; 27, string:'land_cover_nlcd.txt'; 28, if_statement; 28, 29; 28, 36; 28, 41; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 33; 32, identifier:land_use_to_roughness_table; 33, attribute; 33, 34; 33, 35; 34, identifier:pd; 35, identifier:DataFrame; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:df; 40, identifier:land_use_to_roughness_table; 41, else_clause; 41, 42; 42, block; 42, 43; 42, 89; 42, 100; 43, if_statement; 43, 44; 43, 47; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:land_use_to_roughness_table; 46, None; 47, block; 47, 48; 47, 58; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:is; 49, 50; 49, 51; 50, identifier:land_use_grid_id; 51, None; 52, block; 52, 53; 53, raise_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:ValueError; 56, argument_list; 56, 57; 57, string:"Must have land_use_to_roughness_table or land_use_grid_id set ..."; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:land_use_to_roughness_table; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:os; 65, identifier:path; 66, identifier:join; 67, argument_list; 67, 68; 67, 83; 67, 84; 67, 85; 67, 86; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:os; 72, identifier:path; 73, identifier:dirname; 74, argument_list; 74, 75; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:os; 79, identifier:path; 80, identifier:realpath; 81, argument_list; 81, 82; 82, identifier:__file__; 83, string:'..'; 84, string:'grid'; 85, string:'land_cover'; 86, subscript; 86, 87; 86, 88; 87, identifier:LAND_USE_GRID_TABLES; 88, identifier:land_use_grid_id; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:land_use_to_roughness_table; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:os; 96, identifier:path; 97, identifier:abspath; 98, argument_list; 98, 99; 99, identifier:land_use_to_roughness_table; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:df; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:pd; 106, identifier:read_table; 107, argument_list; 107, 108; 107, 109; 107, 112; 107, 115; 107, 118; 107, 124; 108, identifier:land_use_to_roughness_table; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:delim_whitespace; 111, True; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:header; 114, None; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:skiprows; 117, integer:1; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:names; 120, tuple; 120, 121; 120, 122; 120, 123; 121, string:'id'; 122, string:'description'; 123, string:'roughness'; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:dtype; 126, dictionary; 126, 127; 126, 130; 126, 133; 127, pair; 127, 128; 127, 129; 128, string:'id'; 129, string:'int'; 130, pair; 130, 131; 130, 132; 131, string:'description'; 132, string:'str'; 133, pair; 133, 134; 133, 135; 134, string:'roughness'; 135, string:'float'; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:land_use_grid; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:os; 143, identifier:path; 144, identifier:abspath; 145, argument_list; 145, 146; 146, identifier:land_use_grid; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:land_use_resampled; 150, call; 150, 151; 150, 152; 151, identifier:resample_grid; 152, argument_list; 152, 153; 152, 154; 152, 161; 152, 166; 153, identifier:land_use_grid; 154, call; 154, 155; 154, 160; 155, attribute; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:projectFile; 159, identifier:getGrid; 160, argument_list; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:resample_method; 163, attribute; 163, 164; 163, 165; 164, identifier:gdalconst; 165, identifier:GRA_NearestNeighbour; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:as_gdal_grid; 168, True; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:unique_land_use_ids; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:np; 175, identifier:unique; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:land_use_resampled; 180, identifier:np_array; 181, argument_list; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:df; 185, subscript; 185, 186; 185, 187; 186, identifier:df; 187, call; 187, 188; 187, 193; 188, attribute; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:df; 191, identifier:id; 192, identifier:isin; 193, argument_list; 193, 194; 194, identifier:unique_land_use_ids; 195, for_statement; 195, 196; 195, 197; 195, 198; 196, identifier:land_use_id; 197, identifier:unique_land_use_ids; 198, block; 198, 199; 199, if_statement; 199, 200; 199, 207; 200, comparison_operator:not; 200, 201; 200, 202; 201, identifier:land_use_id; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:df; 205, identifier:id; 206, identifier:values; 207, block; 207, 208; 208, raise_statement; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:IndexError; 211, argument_list; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, string:"Land use ID {0} not found in table."; 215, identifier:format; 216, argument_list; 216, 217; 217, identifier:land_use_id; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:deleteMapTable; 223, argument_list; 223, 224; 223, 225; 224, string:"ROUGHNESS"; 225, identifier:session; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:mapTable; 229, call; 229, 230; 229, 231; 230, identifier:MapTable; 231, argument_list; 231, 232; 231, 235; 231, 243; 231, 246; 231, 249; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:name; 234, string:"ROUGHNESS"; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:numIDs; 237, call; 237, 238; 237, 239; 238, identifier:len; 239, argument_list; 239, 240; 240, attribute; 240, 241; 240, 242; 241, identifier:df; 242, identifier:index; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:maxNumCells; 245, integer:0; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:numSed; 248, integer:0; 249, keyword_argument; 249, 250; 249, 251; 250, identifier:numContam; 251, integer:0; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:indexMap; 255, call; 255, 256; 255, 257; 256, identifier:IndexMap; 257, argument_list; 257, 258; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:name; 260, identifier:name; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:indexMap; 265, identifier:mapTableFile; 266, identifier:self; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:mapTable; 271, identifier:indexMap; 272, identifier:indexMap; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:mapTable; 277, identifier:mapTableFile; 278, identifier:self; 279, for_statement; 279, 280; 279, 281; 279, 286; 280, identifier:row; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:df; 284, identifier:itertuples; 285, argument_list; 286, block; 286, 287; 286, 303; 286, 309; 286, 319; 286, 325; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:idx; 290, call; 290, 291; 290, 292; 291, identifier:MTIndex; 292, argument_list; 292, 293; 292, 299; 292, 302; 293, call; 293, 294; 293, 295; 294, identifier:str; 295, argument_list; 295, 296; 296, attribute; 296, 297; 296, 298; 297, identifier:row; 298, identifier:id; 299, attribute; 299, 300; 299, 301; 300, identifier:row; 301, identifier:description; 302, string:''; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:idx; 307, identifier:indexMap; 308, identifier:indexMap; 309, expression_statement; 309, 310; 310, assignment; 310, 311; 310, 312; 311, identifier:val; 312, call; 312, 313; 312, 314; 313, identifier:MTValue; 314, argument_list; 314, 315; 314, 316; 315, string:'ROUGH'; 316, attribute; 316, 317; 316, 318; 317, identifier:row; 318, identifier:roughness; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:val; 323, identifier:index; 324, identifier:idx; 325, expression_statement; 325, 326; 326, assignment; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:val; 329, identifier:mapTable; 330, identifier:mapTable; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 334; 333, identifier:manningn_card; 334, call; 334, 335; 334, 340; 335, attribute; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:self; 338, identifier:projectFile; 339, identifier:getCard; 340, argument_list; 340, 341; 341, string:'MANNING_N'; 342, if_statement; 342, 343; 342, 344; 343, identifier:manningn_card; 344, block; 344, 345; 344, 352; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:session; 349, identifier:delete; 350, argument_list; 350, 351; 351, identifier:manningn_card; 352, expression_statement; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:session; 356, identifier:commit; 357, argument_list; 358, expression_statement; 358, 359; 359, assignment; 359, 360; 359, 365; 360, attribute; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:mapTable; 363, identifier:indexMap; 364, identifier:filename; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, string:'{0}.idx'; 368, identifier:format; 369, argument_list; 369, 370; 370, identifier:name; 371, with_statement; 371, 372; 371, 382; 372, with_clause; 372, 373; 373, with_item; 373, 374; 374, call; 374, 375; 374, 376; 375, identifier:tmp_chdir; 376, argument_list; 376, 377; 377, attribute; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:self; 380, identifier:projectFile; 381, identifier:project_directory; 382, block; 382, 383; 383, expression_statement; 383, 384; 384, call; 384, 385; 384, 388; 385, attribute; 385, 386; 385, 387; 386, identifier:land_use_resampled; 387, identifier:to_grass_ascii; 388, argument_list; 388, 389; 388, 394; 389, attribute; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:mapTable; 392, identifier:indexMap; 393, identifier:filename; 394, keyword_argument; 394, 395; 394, 396; 395, identifier:print_nodata; 396, False; 397, if_statement; 397, 398; 397, 407; 398, not_operator; 398, 399; 399, call; 399, 400; 399, 405; 400, attribute; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:self; 403, identifier:projectFile; 404, identifier:getCard; 405, argument_list; 405, 406; 406, string:'MAPPING_TABLE'; 407, block; 407, 408; 408, expression_statement; 408, 409; 409, call; 409, 410; 409, 415; 410, attribute; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:self; 413, identifier:projectFile; 414, identifier:setCard; 415, argument_list; 415, 416; 415, 417; 415, 427; 416, string:'MAPPING_TABLE'; 417, call; 417, 418; 417, 421; 418, attribute; 418, 419; 418, 420; 419, string:'{0}.cmt'; 420, identifier:format; 421, argument_list; 421, 422; 422, attribute; 422, 423; 422, 426; 423, attribute; 423, 424; 423, 425; 424, identifier:self; 425, identifier:projectFile; 426, identifier:name; 427, keyword_argument; 427, 428; 427, 429; 428, identifier:add_quotes; 429, True
def addRoughnessMapFromLandUse(self, name, session, land_use_grid, land_use_to_roughness_table=None, land_use_grid_id=None, ): LAND_USE_GRID_TABLES = { 'nga' : 'land_cover_nga.txt', 'glcf' : 'land_cover_glcf_modis.txt', 'nlcd' : 'land_cover_nlcd.txt', } if isinstance(land_use_to_roughness_table, pd.DataFrame): df = land_use_to_roughness_table else: if land_use_to_roughness_table is None: if land_use_grid_id is None: raise ValueError("Must have land_use_to_roughness_table or land_use_grid_id set ...") land_use_to_roughness_table = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'grid', 'land_cover', LAND_USE_GRID_TABLES[land_use_grid_id]) land_use_to_roughness_table = os.path.abspath(land_use_to_roughness_table) df = pd.read_table(land_use_to_roughness_table, delim_whitespace=True, header=None, skiprows=1, names=('id', 'description', 'roughness'), dtype={'id':'int', 'description':'str', 'roughness':'float'}, ) land_use_grid = os.path.abspath(land_use_grid) land_use_resampled = resample_grid(land_use_grid, self.projectFile.getGrid(), resample_method=gdalconst.GRA_NearestNeighbour, as_gdal_grid=True) unique_land_use_ids = np.unique(land_use_resampled.np_array()) df = df[df.id.isin(unique_land_use_ids)] for land_use_id in unique_land_use_ids: if land_use_id not in df.id.values: raise IndexError("Land use ID {0} not found in table.".format(land_use_id)) self.deleteMapTable("ROUGHNESS", session) mapTable = MapTable(name="ROUGHNESS", numIDs=len(df.index), maxNumCells=0, numSed=0, numContam=0) indexMap = IndexMap(name=name) indexMap.mapTableFile = self mapTable.indexMap = indexMap mapTable.mapTableFile = self for row in df.itertuples(): idx = MTIndex(str(row.id), row.description, '') idx.indexMap = indexMap val = MTValue('ROUGH', row.roughness) val.index = idx val.mapTable = mapTable manningn_card = self.projectFile.getCard('MANNING_N') if manningn_card: session.delete(manningn_card) session.commit() mapTable.indexMap.filename = '{0}.idx'.format(name) with tmp_chdir(self.projectFile.project_directory): land_use_resampled.to_grass_ascii(mapTable.indexMap.filename, print_nodata=False) if not self.projectFile.getCard('MAPPING_TABLE'): self.projectFile.setCard('MAPPING_TABLE', '{0}.cmt'.format(self.projectFile.name), add_quotes=True)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:result; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:timeout; 7, None; 8, block; 8, 9; 8, 19; 8, 29; 8, 102; 8, 184; 8, 196; 8, 262; 8, 272; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 15; 11, pattern_list; 11, 12; 11, 13; 11, 14; 12, identifier:it; 13, identifier:exceptions; 14, identifier:future_lists; 15, expression_list; 15, 16; 15, 17; 15, 18; 16, list:[]; 17, list:[]; 18, list:[]; 19, import_from_statement; 19, 20; 19, 23; 19, 25; 20, dotted_name; 20, 21; 20, 22; 21, identifier:concurrent; 22, identifier:futures; 23, dotted_name; 23, 24; 24, identifier:Future; 25, aliased_import; 25, 26; 25, 28; 26, dotted_name; 26, 27; 27, identifier:wait; 28, identifier:wait_fut; 29, function_definition; 29, 30; 29, 31; 29, 35; 30, function_name:update; 31, parameters; 31, 32; 31, 33; 31, 34; 32, identifier:fut; 33, identifier:data; 34, identifier:key; 35, block; 35, 36; 36, if_statement; 36, 37; 36, 42; 36, 53; 37, call; 37, 38; 37, 39; 38, identifier:isinstance; 39, argument_list; 39, 40; 39, 41; 40, identifier:fut; 41, identifier:Future; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:it; 47, identifier:append; 48, argument_list; 48, 49; 49, tuple; 49, 50; 49, 51; 49, 52; 50, identifier:fut; 51, identifier:data; 52, identifier:key; 53, elif_clause; 53, 54; 53, 63; 54, boolean_operator:and; 54, 55; 54, 60; 55, call; 55, 56; 55, 57; 56, identifier:isinstance; 57, argument_list; 57, 58; 57, 59; 58, identifier:fut; 59, identifier:AsyncList; 60, comparison_operator:not; 60, 61; 60, 62; 61, identifier:fut; 62, identifier:future_lists; 63, block; 63, 64; 63, 71; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:future_lists; 68, identifier:append; 69, argument_list; 69, 70; 70, identifier:fut; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:it; 75, identifier:extend; 76, argument_list; 76, 77; 77, subscript; 77, 78; 77, 97; 78, list_comprehension; 78, 79; 78, 83; 78, 91; 79, tuple; 79, 80; 79, 81; 79, 82; 80, identifier:j; 81, identifier:fut; 82, identifier:i; 83, for_in_clause; 83, 84; 83, 87; 84, pattern_list; 84, 85; 84, 86; 85, identifier:i; 86, identifier:j; 87, call; 87, 88; 87, 89; 88, identifier:enumerate; 89, argument_list; 89, 90; 90, identifier:fut; 91, if_clause; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:isinstance; 94, argument_list; 94, 95; 94, 96; 95, identifier:j; 96, identifier:Future; 97, slice; 97, 98; 97, 99; 97, 100; 98, colon; 99, colon; 100, unary_operator:-; 100, 101; 101, integer:1; 102, for_statement; 102, 103; 102, 104; 102, 111; 103, identifier:s; 104, call; 104, 105; 104, 110; 105, attribute; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:sub_sol; 109, identifier:values; 110, argument_list; 111, block; 111, 112; 111, 132; 111, 158; 112, for_statement; 112, 113; 112, 116; 112, 124; 113, pattern_list; 113, 114; 113, 115; 114, identifier:k; 115, identifier:v; 116, call; 116, 117; 116, 118; 117, identifier:list; 118, argument_list; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:s; 122, identifier:items; 123, argument_list; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:update; 128, argument_list; 128, 129; 128, 130; 128, 131; 129, identifier:v; 130, identifier:s; 131, identifier:k; 132, for_statement; 132, 133; 132, 134; 132, 143; 133, identifier:d; 134, call; 134, 135; 134, 142; 135, attribute; 135, 136; 135, 141; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:s; 139, identifier:workflow; 140, identifier:nodes; 141, identifier:values; 142, argument_list; 143, block; 143, 144; 144, if_statement; 144, 145; 144, 148; 145, comparison_operator:in; 145, 146; 145, 147; 146, string:'results'; 147, identifier:d; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:update; 152, argument_list; 152, 153; 152, 156; 152, 157; 153, subscript; 153, 154; 153, 155; 154, identifier:d; 155, string:'results'; 156, identifier:d; 157, string:'results'; 158, for_statement; 158, 159; 158, 160; 158, 169; 159, identifier:d; 160, call; 160, 161; 160, 168; 161, attribute; 161, 162; 161, 167; 162, attribute; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:s; 165, identifier:workflow; 166, identifier:edges; 167, identifier:values; 168, argument_list; 169, block; 169, 170; 170, if_statement; 170, 171; 170, 174; 171, comparison_operator:in; 171, 172; 171, 173; 172, string:'value'; 173, identifier:d; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:update; 178, argument_list; 178, 179; 178, 182; 178, 183; 179, subscript; 179, 180; 179, 181; 180, identifier:d; 181, string:'value'; 182, identifier:d; 183, string:'value'; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:wait_fut; 187, argument_list; 187, 188; 187, 195; 188, set_comprehension; 188, 189; 188, 192; 189, subscript; 189, 190; 189, 191; 190, identifier:v; 191, integer:0; 192, for_in_clause; 192, 193; 192, 194; 193, identifier:v; 194, identifier:it; 195, identifier:timeout; 196, for_statement; 196, 197; 196, 201; 196, 202; 197, pattern_list; 197, 198; 197, 199; 197, 200; 198, identifier:f; 199, identifier:d; 200, identifier:k; 201, identifier:it; 202, block; 202, 203; 203, try_statement; 203, 204; 203, 215; 203, 238; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 210; 207, subscript; 207, 208; 207, 209; 208, identifier:d; 209, identifier:k; 210, call; 210, 211; 210, 212; 211, identifier:await_result; 212, argument_list; 212, 213; 212, 214; 213, identifier:f; 214, integer:0; 215, except_clause; 215, 216; 215, 220; 216, as_pattern; 216, 217; 216, 218; 217, identifier:SkipNode; 218, as_pattern_target; 218, 219; 219, identifier:e; 220, block; 220, 221; 220, 234; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:exceptions; 225, identifier:append; 226, argument_list; 226, 227; 227, tuple; 227, 228; 227, 229; 227, 230; 227, 231; 228, identifier:f; 229, identifier:d; 230, identifier:k; 231, attribute; 231, 232; 231, 233; 232, identifier:e; 233, identifier:ex; 234, delete_statement; 234, 235; 235, subscript; 235, 236; 235, 237; 236, identifier:d; 237, identifier:k; 238, except_clause; 238, 239; 238, 246; 239, as_pattern; 239, 240; 239, 244; 240, tuple; 240, 241; 240, 242; 240, 243; 241, identifier:Exception; 242, identifier:ExecutorShutdown; 243, identifier:DispatcherAbort; 244, as_pattern_target; 244, 245; 245, identifier:ex; 246, block; 246, 247; 246, 258; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:exceptions; 251, identifier:append; 252, argument_list; 252, 253; 253, tuple; 253, 254; 253, 255; 253, 256; 253, 257; 254, identifier:f; 255, identifier:d; 256, identifier:k; 257, identifier:ex; 258, delete_statement; 258, 259; 259, subscript; 259, 260; 259, 261; 260, identifier:d; 261, identifier:k; 262, if_statement; 262, 263; 262, 264; 263, identifier:exceptions; 264, block; 264, 265; 265, raise_statement; 265, 266; 266, subscript; 266, 267; 266, 270; 267, subscript; 267, 268; 267, 269; 268, identifier:exceptions; 269, integer:0; 270, unary_operator:-; 270, 271; 271, integer:1; 272, return_statement; 272, 273; 273, identifier:self
def result(self, timeout=None): it, exceptions, future_lists = [], [], [] from concurrent.futures import Future, wait as wait_fut def update(fut, data, key): if isinstance(fut, Future): it.append((fut, data, key)) elif isinstance(fut, AsyncList) and fut not in future_lists: future_lists.append(fut) it.extend([(j, fut, i) for i, j in enumerate(fut) if isinstance(j, Future)][::-1]) for s in self.sub_sol.values(): for k, v in list(s.items()): update(v, s, k) for d in s.workflow.nodes.values(): if 'results' in d: update(d['results'], d, 'results') for d in s.workflow.edges.values(): if 'value' in d: update(d['value'], d, 'value') wait_fut({v[0] for v in it}, timeout) for f, d, k in it: try: d[k] = await_result(f, 0) except SkipNode as e: exceptions.append((f, d, k, e.ex)) del d[k] except (Exception, ExecutorShutdown, DispatcherAbort) as ex: exceptions.append((f, d, k, ex)) del d[k] if exceptions: raise exceptions[0][-1] return self
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:_set_data_node_output; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:self; 5, identifier:node_id; 6, identifier:node_attr; 7, identifier:no_call; 8, default_parameter; 8, 9; 8, 10; 9, identifier:next_nds; 10, None; 11, dictionary_splat_pattern; 11, 12; 12, identifier:kw; 13, block; 13, 14; 13, 26; 13, 154; 13, 289; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 19; 16, pattern_list; 16, 17; 16, 18; 17, identifier:est; 18, identifier:wait_in; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_get_node_estimations; 23, argument_list; 23, 24; 23, 25; 24, identifier:node_attr; 25, identifier:node_id; 26, if_statement; 26, 27; 26, 29; 26, 142; 27, not_operator; 27, 28; 28, identifier:no_call; 29, block; 29, 30; 29, 55; 29, 78; 29, 104; 29, 124; 29, 135; 30, if_statement; 30, 31; 30, 34; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:node_id; 33, identifier:PLOT; 34, block; 34, 35; 34, 43; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:est; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:est; 41, identifier:copy; 42, argument_list; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:est; 47, identifier:PLOT; 48, dictionary; 48, 49; 49, pair; 49, 50; 49, 51; 50, string:'value'; 51, dictionary; 51, 52; 52, pair; 52, 53; 52, 54; 53, string:'obj'; 54, identifier:self; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, pattern_list; 57, 58; 57, 59; 58, identifier:sf; 59, identifier:args; 60, expression_list; 60, 61; 60, 62; 61, False; 62, tuple; 62, 63; 63, dictionary_comprehension; 63, 64; 63, 69; 64, pair; 64, 65; 64, 66; 65, identifier:k; 66, subscript; 66, 67; 66, 68; 67, identifier:v; 68, string:'value'; 69, for_in_clause; 69, 70; 69, 73; 70, pattern_list; 70, 71; 70, 72; 71, identifier:k; 72, identifier:v; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:est; 76, identifier:items; 77, argument_list; 78, if_statement; 78, 79; 78, 86; 79, not_operator; 79, 80; 80, parenthesized_expression; 80, 81; 81, boolean_operator:or; 81, 82; 81, 83; 82, identifier:wait_in; 83, comparison_operator:in; 83, 84; 83, 85; 84, string:'function'; 85, identifier:node_attr; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, pattern_list; 89, 90; 89, 91; 90, identifier:sf; 91, identifier:args; 92, expression_list; 92, 93; 92, 94; 93, True; 94, call; 94, 95; 94, 96; 95, identifier:tuple; 96, argument_list; 96, 97; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:args; 101, integer:0; 102, identifier:values; 103, argument_list; 104, try_statement; 104, 105; 104, 119; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:value; 109, call; 109, 110; 109, 111; 110, identifier:async_thread; 111, argument_list; 111, 112; 111, 113; 111, 114; 111, 115; 111, 116; 111, 117; 112, identifier:self; 113, identifier:args; 114, identifier:node_attr; 115, identifier:node_id; 116, identifier:sf; 117, dictionary_splat; 117, 118; 118, identifier:kw; 119, except_clause; 119, 120; 119, 121; 120, identifier:SkipNode; 121, block; 121, 122; 122, return_statement; 122, 123; 123, False; 124, if_statement; 124, 125; 124, 128; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:value; 127, identifier:NONE; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:self; 133, identifier:node_id; 134, identifier:value; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:value; 138, dictionary; 138, 139; 139, pair; 139, 140; 139, 141; 140, string:'value'; 141, identifier:value; 142, else_clause; 142, 143; 143, block; 143, 144; 143, 150; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:self; 148, identifier:node_id; 149, identifier:NONE; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:value; 153, dictionary; 154, if_statement; 154, 155; 154, 156; 154, 175; 155, identifier:next_nds; 156, block; 156, 157; 156, 163; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:wf_add_edge; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:_wf_add_edge; 163, for_statement; 163, 164; 163, 165; 163, 166; 164, identifier:u; 165, identifier:next_nds; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 170; 169, identifier:wf_add_edge; 170, argument_list; 170, 171; 170, 172; 170, 173; 171, identifier:node_id; 172, identifier:u; 173, dictionary_splat; 173, 174; 174, identifier:value; 175, else_clause; 175, 176; 176, block; 176, 177; 176, 195; 176, 243; 176, 260; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 183; 179, pattern_list; 179, 180; 179, 181; 179, 182; 180, identifier:n; 181, identifier:has; 182, identifier:sub_sol; 183, expression_list; 183, 184; 183, 187; 183, 192; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:nodes; 187, attribute; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:workflow; 191, identifier:has_edge; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:sub_sol; 195, function_definition; 195, 196; 195, 197; 195, 199; 196, function_name:no_visited_in_sub_dsp; 197, parameters; 197, 198; 198, identifier:i; 199, block; 199, 200; 199, 206; 199, 241; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:node; 203, subscript; 203, 204; 203, 205; 204, identifier:n; 205, identifier:i; 206, if_statement; 206, 207; 206, 218; 207, boolean_operator:and; 207, 208; 207, 213; 208, comparison_operator:==; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:node; 211, string:'type'; 212, string:'dispatcher'; 213, call; 213, 214; 213, 215; 214, identifier:has; 215, argument_list; 215, 216; 215, 217; 216, identifier:i; 217, identifier:node_id; 218, block; 218, 219; 218, 233; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:visited; 222, attribute; 222, 223; 222, 232; 223, subscript; 223, 224; 223, 225; 224, identifier:sub_sol; 225, binary_operator:+; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:index; 229, subscript; 229, 230; 229, 231; 230, identifier:node; 231, string:'index'; 232, identifier:_visited; 233, return_statement; 233, 234; 234, comparison_operator:not; 234, 235; 234, 240; 235, subscript; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:node; 238, string:'inputs'; 239, identifier:node_id; 240, identifier:visited; 241, return_statement; 241, 242; 242, True; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:succ_fun; 246, list_comprehension; 246, 247; 246, 248; 246, 255; 247, identifier:u; 248, for_in_clause; 248, 249; 248, 250; 249, identifier:u; 250, subscript; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:_succ; 254, identifier:node_id; 255, if_clause; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:no_visited_in_sub_dsp; 258, argument_list; 258, 259; 259, identifier:u; 260, if_statement; 260, 261; 260, 270; 261, boolean_operator:and; 261, 262; 261, 263; 262, identifier:succ_fun; 263, comparison_operator:not; 263, 264; 263, 267; 264, subscript; 264, 265; 264, 266; 265, identifier:succ_fun; 266, integer:0; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:_visited; 270, block; 270, 271; 270, 277; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:wf_add_edge; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:_wf_add_edge; 277, for_statement; 277, 278; 277, 279; 277, 280; 278, identifier:u; 279, identifier:succ_fun; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 284; 283, identifier:wf_add_edge; 284, argument_list; 284, 285; 284, 286; 284, 287; 285, identifier:node_id; 286, identifier:u; 287, dictionary_splat; 287, 288; 288, identifier:value; 289, return_statement; 289, 290; 290, True
def _set_data_node_output(self, node_id, node_attr, no_call, next_nds=None, **kw): est, wait_in = self._get_node_estimations(node_attr, node_id) if not no_call: if node_id is PLOT: est = est.copy() est[PLOT] = {'value': {'obj': self}} sf, args = False, ({k: v['value'] for k, v in est.items()},) if not (wait_in or 'function' in node_attr): sf, args = True, tuple(args[0].values()) try: value = async_thread(self, args, node_attr, node_id, sf, **kw) except SkipNode: return False if value is not NONE: self[node_id] = value value = {'value': value} else: self[node_id] = NONE value = {} if next_nds: wf_add_edge = self._wf_add_edge for u in next_nds: wf_add_edge(node_id, u, **value) else: n, has, sub_sol = self.nodes, self.workflow.has_edge, self.sub_sol def no_visited_in_sub_dsp(i): node = n[i] if node['type'] == 'dispatcher' and has(i, node_id): visited = sub_sol[self.index + node['index']]._visited return node['inputs'][node_id] not in visited return True succ_fun = [u for u in self._succ[node_id] if no_visited_in_sub_dsp(u)] if succ_fun and succ_fun[0] not in self._visited: wf_add_edge = self._wf_add_edge for u in succ_fun: wf_add_edge(node_id, u, **value) return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:_set_function_node_output; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:self; 5, identifier:node_id; 6, identifier:node_attr; 7, identifier:no_call; 8, default_parameter; 8, 9; 8, 10; 9, identifier:next_nds; 10, None; 11, dictionary_splat_pattern; 11, 12; 12, identifier:kw; 13, block; 13, 14; 13, 26; 13, 44; 13, 59; 13, 65; 13, 80; 13, 88; 13, 102; 13, 142; 13, 179; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 19; 16, pattern_list; 16, 17; 16, 18; 17, identifier:o_nds; 18, identifier:dist; 19, expression_list; 19, 20; 19, 23; 20, subscript; 20, 21; 20, 22; 21, identifier:node_attr; 22, string:'outputs'; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:dist; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:output_nodes; 29, boolean_operator:or; 29, 30; 29, 31; 30, identifier:next_nds; 31, call; 31, 32; 31, 42; 32, attribute; 32, 33; 32, 41; 33, call; 33, 34; 33, 35; 34, identifier:set; 35, argument_list; 35, 36; 36, subscript; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_succ; 40, identifier:node_id; 41, identifier:difference; 42, argument_list; 42, 43; 43, identifier:dist; 44, if_statement; 44, 45; 44, 47; 45, not_operator; 45, 46; 46, identifier:output_nodes; 47, block; 47, 48; 47, 57; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:workflow; 54, identifier:remove_node; 55, argument_list; 55, 56; 56, identifier:node_id; 57, return_statement; 57, 58; 58, False; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:wf_add_edge; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:_wf_add_edge; 65, if_statement; 65, 66; 65, 67; 66, identifier:no_call; 67, block; 67, 68; 67, 78; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:u; 70, identifier:output_nodes; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:wf_add_edge; 75, argument_list; 75, 76; 75, 77; 76, identifier:node_id; 77, identifier:u; 78, return_statement; 78, 79; 79, True; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:args; 83, subscript; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:_wf_pred; 87, identifier:node_id; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:args; 91, list_comprehension; 91, 92; 91, 97; 92, subscript; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:args; 95, identifier:k; 96, string:'value'; 97, for_in_clause; 97, 98; 97, 99; 98, identifier:k; 99, subscript; 99, 100; 99, 101; 100, identifier:node_attr; 101, string:'inputs'; 102, try_statement; 102, 103; 102, 137; 103, block; 103, 104; 103, 113; 103, 125; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:_check_function_domain; 109, argument_list; 109, 110; 109, 111; 109, 112; 110, identifier:args; 111, identifier:node_attr; 112, identifier:node_id; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:res; 116, call; 116, 117; 116, 118; 117, identifier:async_thread; 118, argument_list; 118, 119; 118, 120; 118, 121; 118, 122; 118, 123; 119, identifier:self; 120, identifier:args; 121, identifier:node_attr; 122, identifier:node_id; 123, dictionary_splat; 123, 124; 124, identifier:kw; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 136; 127, subscript; 127, 128; 127, 135; 128, subscript; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:workflow; 133, identifier:node; 134, identifier:node_id; 135, string:'results'; 136, identifier:res; 137, except_clause; 137, 138; 137, 139; 138, identifier:SkipNode; 139, block; 139, 140; 140, return_statement; 140, 141; 141, False; 142, for_statement; 142, 143; 142, 146; 142, 160; 143, pattern_list; 143, 144; 143, 145; 144, identifier:k; 145, identifier:v; 146, call; 146, 147; 146, 148; 147, identifier:zip; 148, argument_list; 148, 149; 148, 150; 149, identifier:o_nds; 150, conditional_expression:if; 150, 151; 150, 152; 150, 158; 151, identifier:res; 152, comparison_operator:>; 152, 153; 152, 157; 153, call; 153, 154; 153, 155; 154, identifier:len; 155, argument_list; 155, 156; 156, identifier:o_nds; 157, integer:1; 158, list:[res]; 158, 159; 159, identifier:res; 160, block; 160, 161; 161, if_statement; 161, 162; 161, 169; 162, boolean_operator:and; 162, 163; 162, 166; 163, comparison_operator:in; 163, 164; 163, 165; 164, identifier:k; 165, identifier:output_nodes; 166, comparison_operator:is; 166, 167; 166, 168; 167, identifier:v; 168, identifier:NONE; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:wf_add_edge; 173, argument_list; 173, 174; 173, 175; 173, 176; 174, identifier:node_id; 175, identifier:k; 176, keyword_argument; 176, 177; 176, 178; 177, identifier:value; 178, identifier:v; 179, return_statement; 179, 180; 180, True
def _set_function_node_output(self, node_id, node_attr, no_call, next_nds=None, **kw): o_nds, dist = node_attr['outputs'], self.dist output_nodes = next_nds or set(self._succ[node_id]).difference(dist) if not output_nodes: self.workflow.remove_node(node_id) return False wf_add_edge = self._wf_add_edge if no_call: for u in output_nodes: wf_add_edge(node_id, u) return True args = self._wf_pred[node_id] args = [args[k]['value'] for k in node_attr['inputs']] try: self._check_function_domain(args, node_attr, node_id) res = async_thread(self, args, node_attr, node_id, **kw) self.workflow.node[node_id]['results'] = res except SkipNode: return False for k, v in zip(o_nds, res if len(o_nds) > 1 else [res]): if k in output_nodes and v is not NONE: wf_add_edge(node_id, k, value=v) return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:_add_initial_value; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:self; 5, identifier:data_id; 6, identifier:value; 7, default_parameter; 7, 8; 7, 9; 8, identifier:initial_dist; 9, float:0.0; 10, default_parameter; 10, 11; 10, 12; 11, identifier:fringe; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:check_cutoff; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:no_call; 18, None; 19, block; 19, 20; 19, 36; 19, 48; 19, 60; 19, 66; 19, 77; 19, 88; 19, 96; 19, 103; 19, 111; 19, 119; 19, 127; 19, 268; 19, 274; 19, 326; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 26; 22, pattern_list; 22, 23; 22, 24; 22, 25; 23, identifier:nodes; 24, identifier:seen; 25, identifier:edge_weight; 26, expression_list; 26, 27; 26, 30; 26, 33; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:nodes; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:seen; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_edge_length; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 41; 38, pattern_list; 38, 39; 38, 40; 39, identifier:wf_remove_edge; 40, identifier:check_wait_in; 41, expression_list; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:_wf_remove_edge; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:check_wait_in; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 53; 50, pattern_list; 50, 51; 50, 52; 51, identifier:wf_add_edge; 52, identifier:dsp_in; 53, expression_list; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_wf_add_edge; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_set_sub_dsp_node_input; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:update_view; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:_update_meeting; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:is; 67, 68; 67, 69; 68, identifier:fringe; 69, None; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:fringe; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:fringe; 77, if_statement; 77, 78; 77, 81; 78, comparison_operator:is; 78, 79; 78, 80; 79, identifier:no_call; 80, None; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:no_call; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:no_call; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:check_cutoff; 91, boolean_operator:or; 91, 92; 91, 93; 92, identifier:check_cutoff; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:check_cutoff; 96, if_statement; 96, 97; 96, 100; 97, comparison_operator:not; 97, 98; 97, 99; 98, identifier:data_id; 99, identifier:nodes; 100, block; 100, 101; 101, return_statement; 101, 102; 102, False; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:wait_in; 106, subscript; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:nodes; 109, identifier:data_id; 110, string:'wait_inputs'; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:index; 114, subscript; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:nodes; 117, identifier:data_id; 118, string:'index'; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:wf_add_edge; 122, argument_list; 122, 123; 122, 124; 122, 125; 123, identifier:START; 124, identifier:data_id; 125, dictionary_splat; 125, 126; 126, identifier:value; 127, if_statement; 127, 128; 127, 133; 128, comparison_operator:in; 128, 129; 128, 130; 129, identifier:data_id; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:_wildcards; 133, block; 133, 134; 133, 143; 133, 152; 133, 266; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 141; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:_visited; 140, identifier:add; 141, argument_list; 141, 142; 142, identifier:data_id; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:workflow; 149, identifier:add_node; 150, argument_list; 150, 151; 151, identifier:data_id; 152, for_statement; 152, 153; 152, 156; 152, 165; 153, pattern_list; 153, 154; 153, 155; 154, identifier:w; 155, identifier:edge_data; 156, call; 156, 157; 156, 164; 157, attribute; 157, 158; 157, 163; 158, subscript; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:dmap; 162, identifier:data_id; 163, identifier:items; 164, argument_list; 165, block; 165, 166; 165, 174; 165, 180; 165, 190; 165, 196; 165, 234; 165, 240; 165, 253; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:wf_add_edge; 169, argument_list; 169, 170; 169, 171; 169, 172; 170, identifier:data_id; 171, identifier:w; 172, dictionary_splat; 172, 173; 173, identifier:value; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:node; 177, subscript; 177, 178; 177, 179; 178, identifier:nodes; 179, identifier:w; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:vw_dist; 183, binary_operator:+; 183, 184; 183, 185; 184, identifier:initial_dist; 185, call; 185, 186; 185, 187; 186, identifier:edge_weight; 187, argument_list; 187, 188; 187, 189; 188, identifier:edge_data; 189, identifier:node; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:update_view; 193, argument_list; 193, 194; 193, 195; 194, identifier:w; 195, identifier:vw_dist; 196, if_statement; 196, 197; 196, 201; 196, 209; 196, 226; 197, call; 197, 198; 197, 199; 198, identifier:check_cutoff; 199, argument_list; 199, 200; 200, identifier:vw_dist; 201, block; 201, 202; 201, 208; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:wf_remove_edge; 205, argument_list; 205, 206; 205, 207; 206, identifier:data_id; 207, identifier:w; 208, continue_statement; 209, elif_clause; 209, 210; 209, 215; 210, comparison_operator:==; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:node; 213, string:'type'; 214, string:'dispatcher'; 215, block; 215, 216; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 219; 218, identifier:dsp_in; 219, argument_list; 219, 220; 219, 221; 219, 222; 219, 223; 219, 224; 219, 225; 220, identifier:data_id; 221, identifier:w; 222, identifier:fringe; 223, identifier:check_cutoff; 224, identifier:no_call; 225, identifier:vw_dist; 226, elif_clause; 226, 227; 226, 232; 227, call; 227, 228; 227, 229; 228, identifier:check_wait_in; 229, argument_list; 229, 230; 229, 231; 230, True; 231, identifier:w; 232, block; 232, 233; 233, continue_statement; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:seen; 238, identifier:w; 239, identifier:vw_dist; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:vd; 243, tuple; 243, 244; 243, 245; 243, 246; 244, True; 245, identifier:w; 246, binary_operator:+; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:self; 249, identifier:index; 250, subscript; 250, 251; 250, 252; 251, identifier:node; 252, string:'index'; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:heapq; 257, identifier:heappush; 258, argument_list; 258, 259; 258, 260; 259, identifier:fringe; 260, tuple; 260, 261; 260, 262; 260, 263; 261, identifier:vw_dist; 262, identifier:vd; 263, tuple; 263, 264; 263, 265; 264, identifier:w; 265, identifier:self; 266, return_statement; 266, 267; 267, True; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 271; 270, identifier:update_view; 271, argument_list; 271, 272; 271, 273; 272, identifier:data_id; 273, identifier:initial_dist; 274, if_statement; 274, 275; 274, 279; 274, 286; 275, call; 275, 276; 275, 277; 276, identifier:check_cutoff; 277, argument_list; 277, 278; 278, identifier:initial_dist; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 283; 282, identifier:wf_remove_edge; 283, argument_list; 283, 284; 283, 285; 284, identifier:START; 285, identifier:data_id; 286, elif_clause; 286, 287; 286, 293; 287, not_operator; 287, 288; 288, call; 288, 289; 288, 290; 289, identifier:check_wait_in; 290, argument_list; 290, 291; 290, 292; 291, identifier:wait_in; 292, identifier:data_id; 293, block; 293, 294; 293, 300; 293, 311; 293, 324; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 299; 296, subscript; 296, 297; 296, 298; 297, identifier:seen; 298, identifier:data_id; 299, identifier:initial_dist; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:vd; 303, tuple; 303, 304; 303, 305; 303, 306; 304, identifier:wait_in; 305, identifier:data_id; 306, binary_operator:+; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:self; 309, identifier:index; 310, identifier:index; 311, expression_statement; 311, 312; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:heapq; 315, identifier:heappush; 316, argument_list; 316, 317; 316, 318; 317, identifier:fringe; 318, tuple; 318, 319; 318, 320; 318, 321; 319, identifier:initial_dist; 320, identifier:vd; 321, tuple; 321, 322; 321, 323; 322, identifier:data_id; 323, identifier:self; 324, return_statement; 324, 325; 325, True; 326, return_statement; 326, 327; 327, False
def _add_initial_value(self, data_id, value, initial_dist=0.0, fringe=None, check_cutoff=None, no_call=None): nodes, seen, edge_weight = self.nodes, self.seen, self._edge_length wf_remove_edge, check_wait_in = self._wf_remove_edge, self.check_wait_in wf_add_edge, dsp_in = self._wf_add_edge, self._set_sub_dsp_node_input update_view = self._update_meeting if fringe is None: fringe = self.fringe if no_call is None: no_call = self.no_call check_cutoff = check_cutoff or self.check_cutoff if data_id not in nodes: return False wait_in = nodes[data_id]['wait_inputs'] index = nodes[data_id]['index'] wf_add_edge(START, data_id, **value) if data_id in self._wildcards: self._visited.add(data_id) self.workflow.add_node(data_id) for w, edge_data in self.dmap[data_id].items(): wf_add_edge(data_id, w, **value) node = nodes[w] vw_dist = initial_dist + edge_weight(edge_data, node) update_view(w, vw_dist) if check_cutoff(vw_dist): wf_remove_edge(data_id, w) continue elif node['type'] == 'dispatcher': dsp_in(data_id, w, fringe, check_cutoff, no_call, vw_dist) elif check_wait_in(True, w): continue seen[w] = vw_dist vd = (True, w, self.index + node['index']) heapq.heappush(fringe, (vw_dist, vd, (w, self))) return True update_view(data_id, initial_dist) if check_cutoff(initial_dist): wf_remove_edge(START, data_id) elif not check_wait_in(wait_in, data_id): seen[data_id] = initial_dist vd = (wait_in, data_id, self.index + index) heapq.heappush(fringe, (initial_dist, vd, (data_id, self))) return True return False
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_see_node; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:node_id; 6, identifier:fringe; 7, identifier:dist; 8, default_parameter; 8, 9; 8, 10; 9, identifier:w_wait_in; 10, integer:0; 11, block; 11, 12; 11, 24; 11, 34; 11, 42; 11, 132; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 17; 14, pattern_list; 14, 15; 14, 16; 15, identifier:seen; 16, identifier:dists; 17, expression_list; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:seen; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:dist; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:wait_in; 27, subscript; 27, 28; 27, 33; 28, subscript; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:nodes; 32, identifier:node_id; 33, string:'wait_inputs'; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_update_meeting; 39, argument_list; 39, 40; 39, 41; 40, identifier:node_id; 41, identifier:dist; 42, if_statement; 42, 43; 42, 50; 42, 52; 42, 74; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:check_wait_in; 47, argument_list; 47, 48; 47, 49; 48, identifier:wait_in; 49, identifier:node_id; 50, block; 50, 51; 51, pass_statement; 52, elif_clause; 52, 53; 52, 56; 53, comparison_operator:in; 53, 54; 53, 55; 54, identifier:node_id; 55, identifier:dists; 56, block; 56, 57; 57, if_statement; 57, 58; 57, 63; 58, comparison_operator:<; 58, 59; 58, 60; 59, identifier:dist; 60, subscript; 60, 61; 60, 62; 61, identifier:dists; 62, identifier:node_id; 63, block; 63, 64; 64, raise_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:DispatcherError; 67, argument_list; 67, 68; 67, 71; 68, concatenated_string; 68, 69; 68, 70; 69, string:'Contradictory paths found: '; 70, string:'negative weights?'; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:sol; 73, identifier:self; 74, elif_clause; 74, 75; 74, 84; 75, boolean_operator:or; 75, 76; 75, 79; 76, comparison_operator:not; 76, 77; 76, 78; 77, identifier:node_id; 78, identifier:seen; 79, comparison_operator:<; 79, 80; 79, 81; 80, identifier:dist; 81, subscript; 81, 82; 81, 83; 82, identifier:seen; 83, identifier:node_id; 84, block; 84, 85; 84, 91; 84, 101; 84, 117; 84, 130; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:seen; 89, identifier:node_id; 90, identifier:dist; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:index; 94, subscript; 94, 95; 94, 100; 95, subscript; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:nodes; 99, identifier:node_id; 100, string:'index'; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:vd; 104, tuple; 104, 105; 104, 111; 104, 112; 105, binary_operator:+; 105, 106; 105, 107; 106, identifier:w_wait_in; 107, call; 107, 108; 107, 109; 108, identifier:int; 109, argument_list; 109, 110; 110, identifier:wait_in; 111, identifier:node_id; 112, binary_operator:+; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:index; 116, identifier:index; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:heapq; 121, identifier:heappush; 122, argument_list; 122, 123; 122, 124; 123, identifier:fringe; 124, tuple; 124, 125; 124, 126; 124, 127; 125, identifier:dist; 126, identifier:vd; 127, tuple; 127, 128; 127, 129; 128, identifier:node_id; 129, identifier:self; 130, return_statement; 130, 131; 131, True; 132, return_statement; 132, 133; 133, False
def _see_node(self, node_id, fringe, dist, w_wait_in=0): seen, dists = self.seen, self.dist wait_in = self.nodes[node_id]['wait_inputs'] self._update_meeting(node_id, dist) if self.check_wait_in(wait_in, node_id): pass elif node_id in dists: if dist < dists[node_id]: raise DispatcherError('Contradictory paths found: ' 'negative weights?', sol=self) elif node_id not in seen or dist < seen[node_id]: seen[node_id] = dist index = self.nodes[node_id]['index'] vd = (w_wait_in + int(wait_in), node_id, self.index + index) heapq.heappush(fringe, (dist, vd, (node_id, self))) return True return False
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:tick; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:events; 6, block; 6, 7; 6, 13; 6, 71; 6, 274; 6, 278; 6, 402; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:add_new_threads; 12, argument_list; 13, if_statement; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:drag_sprite; 17, block; 17, 18; 17, 30; 17, 38; 17, 48; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 23; 20, tuple_pattern; 20, 21; 20, 22; 21, identifier:mx; 22, identifier:my; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:screen; 28, identifier:get_mouse_pos; 29, argument_list; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, tuple_pattern; 32, 33; 32, 34; 33, identifier:ox; 34, identifier:oy; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:drag_offset; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:new_position; 41, tuple; 41, 42; 41, 45; 42, binary_operator:+; 42, 43; 42, 44; 43, identifier:mx; 44, identifier:ox; 45, binary_operator:+; 45, 46; 45, 47; 46, identifier:my; 47, identifier:oy; 48, if_statement; 48, 49; 48, 56; 49, comparison_operator:!=; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:drag_sprite; 54, identifier:position; 55, identifier:new_position; 56, block; 56, 57; 56, 63; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:has_dragged; 62, True; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:drag_sprite; 69, identifier:position; 70, identifier:new_position; 71, for_statement; 71, 72; 71, 73; 71, 74; 72, identifier:event; 73, identifier:events; 74, block; 74, 75; 75, if_statement; 75, 76; 75, 81; 75, 108; 75, 240; 76, comparison_operator:==; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:event; 79, identifier:kind; 80, string:"key_pressed"; 81, block; 81, 82; 81, 98; 82, assert_statement; 82, 83; 83, comparison_operator:in; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:event; 86, identifier:value; 87, call; 87, 88; 87, 97; 88, attribute; 88, 89; 88, 96; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:kurt; 92, identifier:Insert; 93, argument_list; 93, 94; 93, 95; 94, None; 95, string:"key"; 96, identifier:options; 97, argument_list; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:trigger_hats; 103, argument_list; 103, 104; 103, 105; 104, string:"whenKeyPressed"; 105, attribute; 105, 106; 105, 107; 106, identifier:event; 107, identifier:value; 108, elif_clause; 108, 109; 108, 114; 109, comparison_operator:==; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:event; 112, identifier:kind; 113, string:"mouse_down"; 114, block; 114, 115; 114, 125; 114, 176; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:mouse_pos; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:screen; 123, identifier:get_mouse_pos; 124, argument_list; 125, for_statement; 125, 126; 125, 127; 125, 135; 125, 166; 126, identifier:sprite; 127, call; 127, 128; 127, 129; 128, identifier:reversed; 129, argument_list; 129, 130; 130, attribute; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:project; 134, identifier:sprites; 135, block; 135, 136; 135, 143; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:rect; 139, call; 139, 140; 139, 141; 140, identifier:bounds; 141, argument_list; 141, 142; 142, identifier:sprite; 143, if_statement; 143, 144; 143, 150; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:rect; 147, identifier:collide_point; 148, argument_list; 148, 149; 149, identifier:mouse_pos; 150, block; 150, 151; 151, if_statement; 151, 152; 151, 160; 152, call; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:screen; 157, identifier:touching_mouse; 158, argument_list; 158, 159; 159, identifier:sprite; 160, block; 160, 161; 160, 165; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:scriptable; 164, identifier:sprite; 165, break_statement; 166, else_clause; 166, 167; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:scriptable; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:project; 175, identifier:stage; 176, if_statement; 176, 177; 176, 180; 176, 230; 177, attribute; 177, 178; 177, 179; 178, identifier:scriptable; 179, identifier:is_draggable; 180, block; 180, 181; 180, 193; 180, 201; 180, 213; 180, 219; 180, 225; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 186; 183, tuple_pattern; 183, 184; 183, 185; 184, identifier:mx; 185, identifier:my; 186, call; 186, 187; 186, 192; 187, attribute; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:screen; 191, identifier:get_mouse_pos; 192, argument_list; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, tuple_pattern; 195, 196; 195, 197; 196, identifier:x; 197, identifier:y; 198, attribute; 198, 199; 198, 200; 199, identifier:scriptable; 200, identifier:position; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:drag_offset; 206, tuple; 206, 207; 206, 210; 207, binary_operator:-; 207, 208; 207, 209; 208, identifier:x; 209, identifier:mx; 210, binary_operator:-; 210, 211; 210, 212; 211, identifier:y; 212, identifier:my; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:drag_sprite; 218, identifier:scriptable; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:has_dragged; 224, False; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 228; 227, identifier:go_to_front; 228, argument_list; 228, 229; 229, identifier:scriptable; 230, else_clause; 230, 231; 231, block; 231, 232; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:trigger_scriptable_hats; 237, argument_list; 237, 238; 237, 239; 238, identifier:scriptable; 239, string:"whenClicked"; 240, elif_clause; 240, 241; 240, 246; 241, comparison_operator:==; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:event; 244, identifier:kind; 245, string:"mouse_up"; 246, block; 246, 247; 247, if_statement; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:drag_sprite; 251, block; 251, 252; 251, 268; 252, if_statement; 252, 253; 252, 257; 253, not_operator; 253, 254; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:has_dragged; 257, block; 257, 258; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:trigger_scriptable_hats; 263, argument_list; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:drag_sprite; 267, string:"whenClicked"; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:self; 272, identifier:drag_sprite; 273, None; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:remove_threads; 277, list:[]; 278, while_statement; 278, 279; 278, 280; 279, integer:1; 280, block; 280, 281; 281, for_statement; 281, 282; 281, 285; 281, 292; 281, 399; 282, tuple_pattern; 282, 283; 282, 284; 283, identifier:script; 284, identifier:thread; 285, call; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:threads; 290, identifier:items; 291, argument_list; 292, block; 292, 293; 292, 297; 292, 395; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:modified; 296, False; 297, for_statement; 297, 298; 297, 299; 297, 304; 298, identifier:event; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:thread; 302, identifier:tick; 303, argument_list; 304, block; 304, 305; 305, if_statement; 305, 306; 305, 311; 305, 390; 306, comparison_operator:==; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:event; 309, identifier:kind; 310, string:"stop"; 311, block; 311, 312; 312, if_statement; 312, 313; 312, 318; 312, 326; 312, 371; 313, comparison_operator:==; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:event; 316, identifier:value; 317, string:"all"; 318, block; 318, 319; 318, 325; 319, expression_statement; 319, 320; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:self; 323, identifier:stop; 324, argument_list; 325, return_statement; 326, elif_clause; 326, 327; 326, 332; 327, comparison_operator:==; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:event; 330, identifier:value; 331, string:"other scripts in sprite"; 332, block; 332, 333; 332, 366; 332, 370; 333, for_statement; 333, 334; 333, 337; 333, 344; 334, tuple_pattern; 334, 335; 334, 336; 335, identifier:script; 336, identifier:other; 337, call; 337, 338; 337, 343; 338, attribute; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:self; 341, identifier:threads; 342, identifier:items; 343, argument_list; 344, block; 344, 345; 345, if_statement; 345, 346; 345, 353; 346, comparison_operator:==; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:other; 349, identifier:scriptable; 350, attribute; 350, 351; 350, 352; 351, identifier:thread; 352, identifier:scriptable; 353, block; 353, 354; 353, 360; 354, expression_statement; 354, 355; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:other; 358, identifier:finish; 359, argument_list; 360, delete_statement; 360, 361; 361, subscript; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:self; 364, identifier:threads; 365, identifier:script; 366, expression_statement; 366, 367; 367, assignment; 367, 368; 367, 369; 368, identifier:modified; 369, True; 370, break_statement; 371, else_clause; 371, 372; 372, block; 372, 373; 372, 379; 372, 385; 372, 389; 373, expression_statement; 373, 374; 374, call; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:thread; 377, identifier:finish; 378, argument_list; 379, delete_statement; 379, 380; 380, subscript; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:self; 383, identifier:threads; 384, identifier:script; 385, expression_statement; 385, 386; 386, assignment; 386, 387; 386, 388; 387, identifier:modified; 388, True; 389, break_statement; 390, else_clause; 390, 391; 391, block; 391, 392; 392, expression_statement; 392, 393; 393, yield; 393, 394; 394, identifier:event; 395, if_statement; 395, 396; 395, 397; 396, identifier:modified; 397, block; 397, 398; 398, break_statement; 399, else_clause; 399, 400; 400, block; 400, 401; 401, break_statement; 402, expression_statement; 402, 403; 403, call; 403, 404; 403, 407; 404, attribute; 404, 405; 404, 406; 405, identifier:self; 406, identifier:add_new_threads; 407, argument_list
def tick(self, events): self.add_new_threads() if self.drag_sprite: (mx, my) = self.screen.get_mouse_pos() (ox, oy) = self.drag_offset new_position = (mx + ox, my + oy) if self.drag_sprite.position != new_position: self.has_dragged = True self.drag_sprite.position = new_position for event in events: if event.kind == "key_pressed": assert event.value in kurt.Insert(None, "key").options() self.trigger_hats("whenKeyPressed", event.value) elif event.kind == "mouse_down": mouse_pos = self.screen.get_mouse_pos() for sprite in reversed(self.project.sprites): rect = bounds(sprite) if rect.collide_point(mouse_pos): if self.screen.touching_mouse(sprite): scriptable = sprite break else: scriptable = self.project.stage if scriptable.is_draggable: (mx, my) = self.screen.get_mouse_pos() (x, y) = scriptable.position self.drag_offset = (x - mx, y - my) self.drag_sprite = scriptable self.has_dragged = False go_to_front(scriptable) else: self.trigger_scriptable_hats(scriptable, "whenClicked") elif event.kind == "mouse_up": if self.drag_sprite: if not self.has_dragged: self.trigger_scriptable_hats(self.drag_sprite, "whenClicked") self.drag_sprite = None remove_threads = [] while 1: for (script, thread) in self.threads.items(): modified = False for event in thread.tick(): if event.kind == "stop": if event.value == "all": self.stop() return elif event.value == "other scripts in sprite": for (script, other) in self.threads.items(): if other.scriptable == thread.scriptable: other.finish() del self.threads[script] modified = True break else: thread.finish() del self.threads[script] modified = True break else: yield event if modified: break else: break self.add_new_threads()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:evaluate; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:s; 6, identifier:value; 7, default_parameter; 7, 8; 7, 9; 8, identifier:insert; 9, None; 10, block; 10, 11; 10, 20; 10, 29; 10, 208; 10, 414; 11, assert_statement; 11, 12; 12, not_operator; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:value; 17, attribute; 17, 18; 17, 19; 18, identifier:kurt; 19, identifier:Script; 20, if_statement; 20, 21; 20, 26; 21, boolean_operator:and; 21, 22; 21, 23; 22, identifier:insert; 23, attribute; 23, 24; 23, 25; 24, identifier:insert; 25, identifier:unevaluated; 26, block; 26, 27; 27, return_statement; 27, 28; 28, identifier:value; 29, if_statement; 29, 30; 29, 37; 30, call; 30, 31; 30, 32; 31, identifier:isinstance; 32, argument_list; 32, 33; 32, 34; 33, identifier:value; 34, attribute; 34, 35; 34, 36; 35, identifier:kurt; 36, identifier:Block; 37, block; 37, 38; 37, 49; 37, 103; 37, 113; 37, 143; 37, 152; 37, 184; 37, 199; 38, if_statement; 38, 39; 38, 46; 39, comparison_operator:==; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:value; 43, identifier:type; 44, identifier:shape; 45, string:"hat"; 46, block; 46, 47; 47, return_statement; 47, 48; 48, list:[]; 49, if_statement; 49, 50; 49, 57; 50, comparison_operator:not; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:value; 53, identifier:type; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:COMMANDS; 57, block; 57, 58; 58, if_statement; 58, 59; 58, 67; 58, 92; 59, call; 59, 60; 59, 61; 60, identifier:getattr; 61, argument_list; 61, 62; 61, 65; 61, 66; 62, attribute; 62, 63; 62, 64; 63, identifier:value; 64, identifier:type; 65, string:'_workaround'; 66, None; 67, block; 67, 68; 67, 79; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:value; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:value; 75, identifier:type; 76, identifier:_workaround; 77, argument_list; 77, 78; 78, identifier:value; 79, if_statement; 79, 80; 79, 82; 80, not_operator; 80, 81; 81, identifier:value; 82, block; 82, 83; 83, raise_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:kurt; 87, identifier:BlockNotSupported; 88, argument_list; 88, 89; 89, attribute; 89, 90; 89, 91; 90, identifier:value; 91, identifier:type; 92, else_clause; 92, 93; 93, block; 93, 94; 94, raise_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:kurt; 98, identifier:BlockNotSupported; 99, argument_list; 99, 100; 100, attribute; 100, 101; 100, 102; 101, identifier:value; 102, identifier:type; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:f; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:COMMANDS; 110, attribute; 110, 111; 110, 112; 111, identifier:value; 112, identifier:type; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:args; 116, list_comprehension; 116, 117; 116, 125; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:evaluate; 121, argument_list; 121, 122; 121, 123; 121, 124; 122, identifier:s; 123, identifier:arg; 124, identifier:arg_insert; 125, for_in_clause; 125, 126; 125, 129; 126, tuple_pattern; 126, 127; 126, 128; 127, identifier:arg; 128, identifier:arg_insert; 129, call; 129, 130; 129, 131; 130, identifier:zip; 131, argument_list; 131, 132; 131, 138; 132, call; 132, 133; 132, 134; 133, identifier:list; 134, argument_list; 134, 135; 135, attribute; 135, 136; 135, 137; 136, identifier:value; 137, identifier:args; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:value; 141, identifier:type; 142, identifier:inserts; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:value; 146, call; 146, 147; 146, 148; 147, identifier:f; 148, argument_list; 148, 149; 148, 150; 149, identifier:s; 150, list_splat; 150, 151; 151, identifier:args; 152, function_definition; 152, 153; 152, 154; 152, 156; 153, function_name:flatten_generators; 154, parameters; 154, 155; 155, identifier:gen; 156, block; 156, 157; 157, for_statement; 157, 158; 157, 159; 157, 160; 158, identifier:item; 159, identifier:gen; 160, block; 160, 161; 161, if_statement; 161, 162; 161, 168; 161, 179; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:inspect; 165, identifier:isgenerator; 166, argument_list; 166, 167; 167, identifier:item; 168, block; 168, 169; 169, for_statement; 169, 170; 169, 171; 169, 175; 170, identifier:x; 171, call; 171, 172; 171, 173; 172, identifier:flatten_generators; 173, argument_list; 173, 174; 174, identifier:item; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, yield; 177, 178; 178, identifier:x; 179, else_clause; 179, 180; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, yield; 182, 183; 183, identifier:item; 184, if_statement; 184, 185; 184, 191; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:inspect; 188, identifier:isgenerator; 189, argument_list; 189, 190; 190, identifier:value; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:value; 195, call; 195, 196; 195, 197; 196, identifier:flatten_generators; 197, argument_list; 197, 198; 198, identifier:value; 199, if_statement; 199, 200; 199, 203; 200, comparison_operator:is; 200, 201; 200, 202; 201, identifier:value; 202, None; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:value; 207, list:[]; 208, if_statement; 208, 209; 208, 210; 209, identifier:insert; 210, block; 210, 211; 210, 260; 210, 281; 211, if_statement; 211, 212; 211, 217; 212, call; 212, 213; 212, 214; 213, identifier:isinstance; 214, argument_list; 214, 215; 214, 216; 215, identifier:value; 216, identifier:basestring; 217, block; 217, 218; 217, 225; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:value; 221, call; 221, 222; 221, 223; 222, identifier:unicode; 223, argument_list; 223, 224; 224, identifier:value; 225, if_statement; 225, 226; 225, 234; 226, comparison_operator:in; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:insert; 229, identifier:shape; 230, tuple; 230, 231; 230, 232; 230, 233; 231, string:"number"; 232, string:"number-menu"; 233, string:"string"; 234, block; 234, 235; 235, try_statement; 235, 236; 235, 244; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:value; 240, call; 240, 241; 240, 242; 241, identifier:float; 242, argument_list; 242, 243; 243, identifier:value; 244, except_clause; 244, 245; 244, 248; 245, tuple; 245, 246; 245, 247; 246, identifier:TypeError; 247, identifier:ValueError; 248, block; 248, 249; 249, if_statement; 249, 250; 249, 255; 250, comparison_operator:==; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:insert; 253, identifier:shape; 254, string:"number"; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:value; 259, integer:0; 260, if_statement; 260, 261; 260, 273; 261, boolean_operator:and; 261, 262; 261, 267; 262, call; 262, 263; 262, 264; 263, identifier:isinstance; 264, argument_list; 264, 265; 264, 266; 265, identifier:value; 266, identifier:float; 267, comparison_operator:==; 267, 268; 267, 269; 268, identifier:value; 269, call; 269, 270; 269, 271; 270, identifier:int; 271, argument_list; 271, 272; 272, identifier:value; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:value; 277, call; 277, 278; 277, 279; 278, identifier:int; 279, argument_list; 279, 280; 280, identifier:value; 281, if_statement; 281, 282; 281, 292; 281, 321; 281, 355; 281, 389; 282, comparison_operator:in; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:insert; 285, identifier:kind; 286, tuple; 286, 287; 286, 288; 286, 289; 286, 290; 286, 291; 287, string:"spriteOrStage"; 288, string:"spriteOrMouse"; 289, string:"stageOrThis"; 290, string:"spriteOnly"; 291, string:"touching"; 292, block; 292, 293; 293, if_statement; 293, 294; 293, 299; 294, comparison_operator:not; 294, 295; 294, 296; 295, identifier:value; 296, tuple; 296, 297; 296, 298; 297, string:"mouse-pointer"; 298, string:"edge"; 299, block; 299, 300; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:value; 303, parenthesized_expression; 303, 304; 304, conditional_expression:if; 304, 305; 304, 310; 304, 313; 305, attribute; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:self; 308, identifier:project; 309, identifier:stage; 310, comparison_operator:==; 310, 311; 310, 312; 311, identifier:value; 312, string:"Stage"; 313, call; 313, 314; 313, 319; 314, attribute; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:self; 317, identifier:project; 318, identifier:get_sprite; 319, argument_list; 319, 320; 320, identifier:value; 321, elif_clause; 321, 322; 321, 327; 322, comparison_operator:==; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:insert; 325, identifier:kind; 326, string:"var"; 327, block; 327, 328; 328, if_statement; 328, 329; 328, 334; 328, 343; 329, comparison_operator:in; 329, 330; 329, 331; 330, identifier:value; 331, attribute; 331, 332; 331, 333; 332, identifier:s; 333, identifier:variables; 334, block; 334, 335; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:value; 338, subscript; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:s; 341, identifier:variables; 342, identifier:value; 343, else_clause; 343, 344; 344, block; 344, 345; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 348; 347, identifier:value; 348, subscript; 348, 349; 348, 354; 349, attribute; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:s; 352, identifier:project; 353, identifier:variables; 354, identifier:value; 355, elif_clause; 355, 356; 355, 361; 356, comparison_operator:==; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:insert; 359, identifier:kind; 360, string:"list"; 361, block; 361, 362; 362, if_statement; 362, 363; 362, 368; 362, 377; 363, comparison_operator:in; 363, 364; 363, 365; 364, identifier:value; 365, attribute; 365, 366; 365, 367; 366, identifier:s; 367, identifier:lists; 368, block; 368, 369; 369, expression_statement; 369, 370; 370, assignment; 370, 371; 370, 372; 371, identifier:value; 372, subscript; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:s; 375, identifier:lists; 376, identifier:value; 377, else_clause; 377, 378; 378, block; 378, 379; 379, expression_statement; 379, 380; 380, assignment; 380, 381; 380, 382; 381, identifier:value; 382, subscript; 382, 383; 382, 388; 383, attribute; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:s; 386, identifier:project; 387, identifier:lists; 388, identifier:value; 389, elif_clause; 389, 390; 389, 395; 390, comparison_operator:==; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:insert; 393, identifier:kind; 394, string:"sound"; 395, block; 395, 396; 396, for_statement; 396, 397; 396, 398; 396, 401; 397, identifier:sound; 398, attribute; 398, 399; 398, 400; 399, identifier:s; 400, identifier:sounds; 401, block; 401, 402; 402, if_statement; 402, 403; 402, 408; 403, comparison_operator:==; 403, 404; 403, 407; 404, attribute; 404, 405; 404, 406; 405, identifier:sound; 406, identifier:name; 407, identifier:value; 408, block; 408, 409; 408, 413; 409, expression_statement; 409, 410; 410, assignment; 410, 411; 410, 412; 411, identifier:value; 412, identifier:sound; 413, break_statement; 414, return_statement; 414, 415; 415, identifier:value
def evaluate(self, s, value, insert=None): assert not isinstance(value, kurt.Script) if insert and insert.unevaluated: return value if isinstance(value, kurt.Block): if value.type.shape == "hat": return [] if value.type not in self.COMMANDS: if getattr(value.type, '_workaround', None): value = value.type._workaround(value) if not value: raise kurt.BlockNotSupported(value.type) else: raise kurt.BlockNotSupported(value.type) f = self.COMMANDS[value.type] args = [self.evaluate(s, arg, arg_insert) for (arg, arg_insert) in zip(list(value.args), value.type.inserts)] value = f(s, *args) def flatten_generators(gen): for item in gen: if inspect.isgenerator(item): for x in flatten_generators(item): yield x else: yield item if inspect.isgenerator(value): value = flatten_generators(value) if value is None: value = [] if insert: if isinstance(value, basestring): value = unicode(value) if insert.shape in ("number", "number-menu", "string"): try: value = float(value) except (TypeError, ValueError): if insert.shape == "number": value = 0 if isinstance(value, float) and value == int(value): value = int(value) if insert.kind in ("spriteOrStage", "spriteOrMouse", "stageOrThis", "spriteOnly", "touching"): if value not in ("mouse-pointer", "edge"): value = (self.project.stage if value == "Stage" else self.project.get_sprite(value)) elif insert.kind == "var": if value in s.variables: value = s.variables[value] else: value = s.project.variables[value] elif insert.kind == "list": if value in s.lists: value = s.lists[value] else: value = s.project.lists[value] elif insert.kind == "sound": for sound in s.sounds: if sound.name == value: value = sound break return value
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_write; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:session; 6, identifier:openFile; 7, identifier:maskMap; 8, block; 8, 9; 8, 13; 8, 20; 8, 80; 8, 94; 8, 108; 8, 122; 8, 136; 8, 140; 8, 200; 8, 269; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:FIRST_VALUE_INDEX; 12, integer:12; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:openFile; 17, identifier:write; 18, argument_list; 18, 19; 19, string:'DATASET\r\n'; 20, if_statement; 20, 21; 20, 28; 20, 50; 21, comparison_operator:==; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:type; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:SCALAR_TYPE; 28, block; 28, 29; 28, 43; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:openFile; 33, identifier:write; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:'OBJTYPE {0}\r\n'; 38, identifier:format; 39, argument_list; 39, 40; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:objectType; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:openFile; 47, identifier:write; 48, argument_list; 48, 49; 49, string:'BEGSCL\r\n'; 50, elif_clause; 50, 51; 50, 58; 51, comparison_operator:==; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:type; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:VECTOR_TYPE; 58, block; 58, 59; 58, 73; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:openFile; 63, identifier:write; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, string:'VECTYPE {0}\r\n'; 68, identifier:format; 69, argument_list; 69, 70; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:vectorType; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:openFile; 77, identifier:write; 78, argument_list; 78, 79; 79, string:'BEGVEC\r\n'; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:openFile; 84, identifier:write; 85, argument_list; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, string:'OBJID {0}\r\n'; 89, identifier:format; 90, argument_list; 90, 91; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:objectID; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:openFile; 98, identifier:write; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, string:'ND {0}\r\n'; 103, identifier:format; 104, argument_list; 104, 105; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:numberData; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:openFile; 112, identifier:write; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, string:'NC {0}\r\n'; 117, identifier:format; 118, argument_list; 118, 119; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:numberCells; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:openFile; 126, identifier:write; 127, argument_list; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, string:'NAME {0}\r\n'; 131, identifier:format; 132, argument_list; 132, 133; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:name; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:statusString; 139, string:''; 140, if_statement; 140, 141; 140, 146; 141, call; 141, 142; 141, 143; 142, identifier:isinstance; 143, argument_list; 143, 144; 143, 145; 144, identifier:maskMap; 145, identifier:RasterMapFile; 146, block; 146, 147; 146, 156; 146, 181; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:statusGrassRasterString; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:maskMap; 153, identifier:getAsGrassAsciiGrid; 154, argument_list; 154, 155; 155, identifier:session; 156, if_statement; 156, 157; 156, 160; 156, 169; 157, comparison_operator:is; 157, 158; 157, 159; 158, identifier:statusGrassRasterString; 159, None; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:statusValues; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:statusGrassRasterString; 167, identifier:split; 168, argument_list; 169, else_clause; 169, 170; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:statusValues; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:maskMap; 178, identifier:rasterText; 179, identifier:split; 180, argument_list; 181, for_statement; 181, 182; 181, 183; 181, 191; 182, identifier:i; 183, call; 183, 184; 183, 185; 184, identifier:range; 185, argument_list; 185, 186; 185, 187; 186, identifier:FIRST_VALUE_INDEX; 187, call; 187, 188; 187, 189; 188, identifier:len; 189, argument_list; 189, 190; 190, identifier:statusValues; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, augmented_assignment:+=; 193, 194; 193, 195; 194, identifier:statusString; 195, binary_operator:+; 195, 196; 195, 199; 196, subscript; 196, 197; 196, 198; 197, identifier:statusValues; 198, identifier:i; 199, string:'\r\n'; 200, for_statement; 200, 201; 200, 202; 200, 205; 201, identifier:timeStepRaster; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:rasters; 205, block; 205, 206; 205, 223; 205, 237; 205, 246; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:openFile; 210, identifier:write; 211, argument_list; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, string:'TS {0} {1}\r\n'; 215, identifier:format; 216, argument_list; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:timeStepRaster; 219, identifier:iStatus; 220, attribute; 220, 221; 220, 222; 221, identifier:timeStepRaster; 222, identifier:timestamp; 223, if_statement; 223, 224; 223, 229; 224, comparison_operator:==; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:timeStepRaster; 227, identifier:iStatus; 228, integer:1; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:openFile; 234, identifier:write; 235, argument_list; 235, 236; 236, identifier:statusString; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:valueString; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:timeStepRaster; 243, identifier:getAsWmsDatasetString; 244, argument_list; 244, 245; 245, identifier:session; 246, if_statement; 246, 247; 246, 250; 246, 258; 247, comparison_operator:is; 247, 248; 247, 249; 248, identifier:valueString; 249, None; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:openFile; 255, identifier:write; 256, argument_list; 256, 257; 257, identifier:valueString; 258, else_clause; 258, 259; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:openFile; 264, identifier:write; 265, argument_list; 265, 266; 266, attribute; 266, 267; 266, 268; 267, identifier:timeStepRaster; 268, identifier:rasterText; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:openFile; 273, identifier:write; 274, argument_list; 274, 275; 275, string:'ENDDS\r\n'
def _write(self, session, openFile, maskMap): FIRST_VALUE_INDEX = 12 openFile.write('DATASET\r\n') if self.type == self.SCALAR_TYPE: openFile.write('OBJTYPE {0}\r\n'.format(self.objectType)) openFile.write('BEGSCL\r\n') elif self.type == self.VECTOR_TYPE: openFile.write('VECTYPE {0}\r\n'.format(self.vectorType)) openFile.write('BEGVEC\r\n') openFile.write('OBJID {0}\r\n'.format(self.objectID)) openFile.write('ND {0}\r\n'.format(self.numberData)) openFile.write('NC {0}\r\n'.format(self.numberCells)) openFile.write('NAME {0}\r\n'.format(self.name)) statusString = '' if isinstance(maskMap, RasterMapFile): statusGrassRasterString = maskMap.getAsGrassAsciiGrid(session) if statusGrassRasterString is not None: statusValues = statusGrassRasterString.split() else: statusValues = maskMap.rasterText.split() for i in range(FIRST_VALUE_INDEX, len(statusValues)): statusString += statusValues[i] + '\r\n' for timeStepRaster in self.rasters: openFile.write('TS {0} {1}\r\n'.format(timeStepRaster.iStatus, timeStepRaster.timestamp)) if timeStepRaster.iStatus == 1: openFile.write(statusString) valueString = timeStepRaster.getAsWmsDatasetString(session) if valueString is not None: openFile.write(valueString) else: openFile.write(timeStepRaster.rasterText) openFile.write('ENDDS\r\n')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:get_batch; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:sentences; 5, identifier:token_dict; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ignore_case; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:unk_index; 11, integer:1; 12, default_parameter; 12, 13; 12, 14; 13, identifier:eos_index; 14, integer:2; 15, block; 15, 16; 15, 23; 15, 34; 15, 48; 15, 62; 15, 76; 15, 189; 15, 207; 15, 225; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:batch_size; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, identifier:sentences; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:max_sentence_len; 26, call; 26, 27; 26, 28; 27, identifier:max; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:map; 31, argument_list; 31, 32; 31, 33; 32, identifier:len; 33, identifier:sentences; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:inputs; 37, list_comprehension; 37, 38; 37, 42; 38, binary_operator:*; 38, 39; 38, 41; 39, list:[0]; 39, 40; 40, integer:0; 41, identifier:max_sentence_len; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:_; 44, call; 44, 45; 44, 46; 45, identifier:range; 46, argument_list; 46, 47; 47, identifier:batch_size; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:outputs_forward; 51, list_comprehension; 51, 52; 51, 56; 52, binary_operator:*; 52, 53; 52, 55; 53, list:[0]; 53, 54; 54, integer:0; 55, identifier:max_sentence_len; 56, for_in_clause; 56, 57; 56, 58; 57, identifier:_; 58, call; 58, 59; 58, 60; 59, identifier:range; 60, argument_list; 60, 61; 61, identifier:batch_size; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:outputs_backward; 65, list_comprehension; 65, 66; 65, 70; 66, binary_operator:*; 66, 67; 66, 69; 67, list:[0]; 67, 68; 68, integer:0; 69, identifier:max_sentence_len; 70, for_in_clause; 70, 71; 70, 72; 71, identifier:_; 72, call; 72, 73; 72, 74; 73, identifier:range; 74, argument_list; 74, 75; 75, identifier:batch_size; 76, for_statement; 76, 77; 76, 80; 76, 84; 77, pattern_list; 77, 78; 77, 79; 78, identifier:i; 79, identifier:sentence; 80, call; 80, 81; 80, 82; 81, identifier:enumerate; 82, argument_list; 82, 83; 83, identifier:sentences; 84, block; 84, 85; 84, 98; 84, 106; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 97; 87, subscript; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:outputs_forward; 90, identifier:i; 91, binary_operator:-; 91, 92; 91, 96; 92, call; 92, 93; 92, 94; 93, identifier:len; 94, argument_list; 94, 95; 95, identifier:sentence; 96, integer:1; 97, identifier:eos_index; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 105; 100, subscript; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:outputs_backward; 103, identifier:i; 104, integer:0; 105, identifier:eos_index; 106, for_statement; 106, 107; 106, 110; 106, 114; 107, pattern_list; 107, 108; 107, 109; 108, identifier:j; 109, identifier:token; 110, call; 110, 111; 110, 112; 111, identifier:enumerate; 112, argument_list; 112, 113; 113, identifier:sentence; 114, block; 114, 115; 114, 144; 114, 152; 114, 169; 115, if_statement; 115, 116; 115, 117; 115, 132; 116, identifier:ignore_case; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:index; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:token_dict; 124, identifier:get; 125, argument_list; 125, 126; 125, 131; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:token; 129, identifier:lower; 130, argument_list; 131, identifier:unk_index; 132, else_clause; 132, 133; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:index; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:token_dict; 140, identifier:get; 141, argument_list; 141, 142; 141, 143; 142, identifier:token; 143, identifier:unk_index; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 151; 146, subscript; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:inputs; 149, identifier:i; 150, identifier:j; 151, identifier:index; 152, if_statement; 152, 153; 152, 158; 153, comparison_operator:>=; 153, 154; 153, 157; 154, binary_operator:-; 154, 155; 154, 156; 155, identifier:j; 156, integer:1; 157, integer:0; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 168; 161, subscript; 161, 162; 161, 165; 162, subscript; 162, 163; 162, 164; 163, identifier:outputs_forward; 164, identifier:i; 165, binary_operator:-; 165, 166; 165, 167; 166, identifier:j; 167, integer:1; 168, identifier:index; 169, if_statement; 169, 170; 169, 178; 170, comparison_operator:<; 170, 171; 170, 174; 171, binary_operator:+; 171, 172; 171, 173; 172, identifier:j; 173, integer:1; 174, call; 174, 175; 174, 176; 175, identifier:len; 176, argument_list; 176, 177; 177, identifier:sentence; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 188; 181, subscript; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:outputs_backward; 184, identifier:i; 185, binary_operator:+; 185, 186; 185, 187; 186, identifier:j; 187, integer:1; 188, identifier:index; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:outputs_forward; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:np; 195, identifier:expand_dims; 196, argument_list; 196, 197; 196, 203; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:np; 200, identifier:asarray; 201, argument_list; 201, 202; 202, identifier:outputs_forward; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:axis; 205, unary_operator:-; 205, 206; 206, integer:1; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:outputs_backward; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:np; 213, identifier:expand_dims; 214, argument_list; 214, 215; 214, 221; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:np; 218, identifier:asarray; 219, argument_list; 219, 220; 220, identifier:outputs_backward; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:axis; 223, unary_operator:-; 223, 224; 224, integer:1; 225, return_statement; 225, 226; 226, expression_list; 226, 227; 226, 233; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:np; 230, identifier:asarray; 231, argument_list; 231, 232; 232, identifier:inputs; 233, list:[outputs_forward, outputs_backward]; 233, 234; 233, 235; 234, identifier:outputs_forward; 235, identifier:outputs_backward
def get_batch(sentences, token_dict, ignore_case=False, unk_index=1, eos_index=2): batch_size = len(sentences) max_sentence_len = max(map(len, sentences)) inputs = [[0] * max_sentence_len for _ in range(batch_size)] outputs_forward = [[0] * max_sentence_len for _ in range(batch_size)] outputs_backward = [[0] * max_sentence_len for _ in range(batch_size)] for i, sentence in enumerate(sentences): outputs_forward[i][len(sentence) - 1] = eos_index outputs_backward[i][0] = eos_index for j, token in enumerate(sentence): if ignore_case: index = token_dict.get(token.lower(), unk_index) else: index = token_dict.get(token, unk_index) inputs[i][j] = index if j - 1 >= 0: outputs_forward[i][j - 1] = index if j + 1 < len(sentence): outputs_backward[i][j + 1] = index outputs_forward = np.expand_dims(np.asarray(outputs_forward), axis=-1) outputs_backward = np.expand_dims(np.asarray(outputs_backward), axis=-1) return np.asarray(inputs), [outputs_forward, outputs_backward]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_gene_info; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:ensembl_ids; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:hgnc_symbols; 9, None; 10, block; 10, 11; 10, 24; 10, 37; 10, 41; 10, 45; 10, 134; 10, 211; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:uniq_ensembl_ids; 14, call; 14, 15; 14, 16; 15, identifier:set; 16, generator_expression; 16, 17; 16, 18; 17, identifier:ensembl_id; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:ensembl_id; 20, parenthesized_expression; 20, 21; 21, boolean_operator:or; 21, 22; 21, 23; 22, identifier:ensembl_ids; 23, list:[]; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:uniq_hgnc_symbols; 27, call; 27, 28; 27, 29; 28, identifier:set; 29, generator_expression; 29, 30; 29, 31; 30, identifier:hgnc_symbol; 31, for_in_clause; 31, 32; 31, 33; 32, identifier:hgnc_symbol; 33, parenthesized_expression; 33, 34; 34, boolean_operator:or; 34, 35; 34, 36; 35, identifier:hgnc_symbols; 36, list:[]; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:genes; 40, list:[]; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:gene_data; 44, list:[]; 45, if_statement; 45, 46; 45, 47; 45, 68; 46, identifier:uniq_ensembl_ids; 47, block; 47, 48; 48, for_statement; 48, 49; 48, 50; 48, 51; 49, identifier:ensembl_id; 50, identifier:uniq_ensembl_ids; 51, block; 51, 52; 52, for_statement; 52, 53; 52, 54; 52, 60; 53, identifier:res; 54, call; 54, 55; 54, 56; 55, identifier:query_gene; 56, argument_list; 56, 57; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:ensembl_id; 59, identifier:ensembl_id; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:gene_data; 65, identifier:append; 66, argument_list; 66, 67; 67, identifier:res; 68, elif_clause; 68, 69; 68, 70; 69, identifier:uniq_hgnc_symbols; 70, block; 70, 71; 71, for_statement; 71, 72; 71, 73; 71, 74; 72, identifier:hgnc_symbol; 73, identifier:uniq_hgnc_symbols; 74, block; 74, 75; 74, 84; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:query_res; 78, call; 78, 79; 78, 80; 79, identifier:query_gene; 80, argument_list; 80, 81; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:hgnc_symbol; 83, identifier:hgnc_symbol; 84, if_statement; 84, 85; 84, 86; 84, 98; 85, identifier:query_res; 86, block; 86, 87; 87, for_statement; 87, 88; 87, 89; 87, 90; 88, identifier:res; 89, identifier:query_res; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:gene_data; 95, identifier:append; 96, argument_list; 96, 97; 97, identifier:res; 98, else_clause; 98, 99; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:gene_data; 104, identifier:append; 105, argument_list; 105, 106; 106, dictionary; 106, 107; 106, 110; 106, 113; 106, 116; 106, 119; 106, 122; 106, 125; 106, 128; 106, 131; 107, pair; 107, 108; 107, 109; 108, string:'hgnc_symbol'; 109, identifier:hgnc_symbol; 110, pair; 110, 111; 110, 112; 111, string:'hgnc_id'; 112, None; 113, pair; 113, 114; 113, 115; 114, string:'ensembl_id'; 115, None; 116, pair; 116, 117; 116, 118; 117, string:'description'; 118, None; 119, pair; 119, 120; 119, 121; 120, string:'chrom'; 121, string:'unknown'; 122, pair; 122, 123; 122, 124; 123, string:'start'; 124, integer:0; 125, pair; 125, 126; 125, 127; 126, string:'stop'; 127, integer:0; 128, pair; 128, 129; 128, 130; 129, string:'hi_score'; 130, None; 131, pair; 131, 132; 131, 133; 132, string:'constraint_score'; 133, None; 134, for_statement; 134, 135; 134, 136; 134, 137; 135, identifier:gene; 136, identifier:gene_data; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:genes; 142, identifier:append; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:Gene; 146, argument_list; 146, 147; 146, 152; 146, 157; 146, 162; 146, 167; 146, 172; 146, 177; 146, 182; 146, 193; 146, 198; 146, 203; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:symbol; 149, subscript; 149, 150; 149, 151; 150, identifier:gene; 151, string:'hgnc_symbol'; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:hgnc_id; 154, subscript; 154, 155; 154, 156; 155, identifier:gene; 156, string:'hgnc_id'; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:ensembl_id; 159, subscript; 159, 160; 159, 161; 160, identifier:gene; 161, string:'ensembl_id'; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:description; 164, subscript; 164, 165; 164, 166; 165, identifier:gene; 166, string:'description'; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:chrom; 169, subscript; 169, 170; 169, 171; 170, identifier:gene; 171, string:'chrom'; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:start; 174, subscript; 174, 175; 174, 176; 175, identifier:gene; 176, string:'start'; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:stop; 179, subscript; 179, 180; 179, 181; 180, identifier:gene; 181, string:'stop'; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:location; 184, call; 184, 185; 184, 186; 185, identifier:get_cytoband_coord; 186, argument_list; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:gene; 189, string:'chrom'; 190, subscript; 190, 191; 190, 192; 191, identifier:gene; 192, string:'start'; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:hi_score; 195, subscript; 195, 196; 195, 197; 196, identifier:gene; 197, string:'hi_score'; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:constraint_score; 200, subscript; 200, 201; 200, 202; 201, identifier:gene; 202, string:'constraint_score'; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:omim_number; 205, call; 205, 206; 205, 207; 206, identifier:get_omim_number; 207, argument_list; 207, 208; 208, subscript; 208, 209; 208, 210; 209, identifier:gene; 210, string:'hgnc_symbol'; 211, return_statement; 211, 212; 212, identifier:genes
def get_gene_info(ensembl_ids=None, hgnc_symbols=None): uniq_ensembl_ids = set(ensembl_id for ensembl_id in (ensembl_ids or [])) uniq_hgnc_symbols = set(hgnc_symbol for hgnc_symbol in (hgnc_symbols or [])) genes = [] gene_data = [] if uniq_ensembl_ids: for ensembl_id in uniq_ensembl_ids: for res in query_gene(ensembl_id=ensembl_id): gene_data.append(res) elif uniq_hgnc_symbols: for hgnc_symbol in uniq_hgnc_symbols: query_res = query_gene(hgnc_symbol=hgnc_symbol) if query_res: for res in query_res: gene_data.append(res) else: gene_data.append({ 'hgnc_symbol': hgnc_symbol, 'hgnc_id': None, 'ensembl_id': None, 'description': None, 'chrom': 'unknown', 'start': 0, 'stop': 0, 'hi_score': None, 'constraint_score': None, }) for gene in gene_data: genes.append(Gene( symbol=gene ['hgnc_symbol'], hgnc_id=gene['hgnc_id'], ensembl_id=gene['ensembl_id'], description=gene['description'], chrom=gene['chrom'], start=gene['start'], stop=gene['stop'], location=get_cytoband_coord(gene['chrom'], gene['start']), hi_score=gene['hi_score'], constraint_score=gene['constraint_score'], omim_number=get_omim_number(gene['hgnc_symbol']) )) return genes
0, module; 0, 1; 0, 13; 0, 17; 0, 29; 0, 33; 0, 42; 0, 46; 0, 60; 0, 109; 0, 121; 0, 135; 0, 146; 0, 150; 0, 376; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:parse_mapping; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:map_path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:source; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:dotfiles; 11, None; 12, block:; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:include_re; 16, identifier:r; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:include_re; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:re; 23, identifier:compile; 24, argument_list; 24, 25; 24, 26; 25, identifier:include_re; 26, attribute; 26, 27; 26, 28; 27, identifier:re; 28, identifier:I; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:mapping_re; 32, identifier:r; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:mapping_re; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:re; 39, identifier:compile; 40, argument_list; 40, 41; 41, identifier:mapping_re; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:filename; 45, None; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:map_path; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:path; 52, identifier:realpath; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:path; 57, identifier:expanduser; 58, argument_list; 58, 59; 59, identifier:map_path; 60, if_statement; 60, 61; 60, 67; 60, 72; 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:map_path; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:filename; 71, identifier:map_path; 72, elif_clause; 72, 73; 72, 79; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:path; 76, identifier:isdir; 77, argument_list; 77, 78; 78, identifier:map_path; 79, block; 79, 80; 80, for_statement; 80, 81; 80, 82; 80, 85; 81, identifier:map_name; 82, expression_list; 82, 83; 82, 84; 83, string:'.dotfiles'; 84, string:'dotfiles'; 85, block; 85, 86; 85, 96; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:candidate; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:path; 92, identifier:join; 93, argument_list; 93, 94; 93, 95; 94, identifier:map_path; 95, identifier:map_name; 96, if_statement; 96, 97; 96, 103; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:path; 100, identifier:isfile; 101, argument_list; 101, 102; 102, identifier:candidate; 103, block; 103, 104; 103, 108; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:filename; 107, identifier:candidate; 108, break_statement; 109, if_statement; 109, 110; 109, 113; 110, comparison_operator:is; 110, 111; 110, 112; 111, identifier:filename; 112, None; 113, block; 113, 114; 114, raise_statement; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:ValueError; 117, argument_list; 117, 118; 118, binary_operator:%; 118, 119; 118, 120; 119, string:'No dotfile mapping found in %s'; 120, identifier:map_path; 121, if_statement; 121, 122; 121, 125; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:source; 124, None; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:source; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:path; 132, identifier:dirname; 133, argument_list; 133, 134; 134, identifier:map_path; 135, if_statement; 135, 136; 135, 139; 136, comparison_operator:is; 136, 137; 136, 138; 137, identifier:dotfiles; 138, None; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:dotfiles; 143, call; 143, 144; 143, 145; 144, identifier:OrderedDict; 145, argument_list; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:lineno; 149, integer:0; 150, with_statement; 150, 151; 150, 160; 151, with_clause; 151, 152; 152, with_item; 152, 153; 153, as_pattern; 153, 154; 153, 158; 154, call; 154, 155; 154, 156; 155, identifier:open; 156, argument_list; 156, 157; 157, identifier:filename; 158, as_pattern_target; 158, 159; 159, identifier:fh; 160, block; 160, 161; 161, for_statement; 161, 162; 161, 163; 161, 164; 162, identifier:line; 163, identifier:fh; 164, block; 164, 165; 164, 169; 164, 177; 164, 186; 164, 296; 165, expression_statement; 165, 166; 166, augmented_assignment:+=; 166, 167; 166, 168; 167, identifier:lineno; 168, integer:1; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:content; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:line; 175, identifier:strip; 176, argument_list; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:match; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:include_re; 183, identifier:match; 184, argument_list; 184, 185; 185, identifier:content; 186, if_statement; 186, 187; 186, 188; 187, identifier:match; 188, block; 188, 189; 188, 203; 188, 250; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:include_path; 192, call; 192, 193; 192, 201; 193, attribute; 193, 194; 193, 200; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:match; 197, identifier:group; 198, argument_list; 198, 199; 199, integer:1; 200, identifier:strip; 201, argument_list; 201, 202; 202, string:'\'"'; 203, if_statement; 203, 204; 203, 218; 203, 233; 204, parenthesized_expression; 204, 205; 205, boolean_operator:or; 205, 206; 205, 212; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:include_path; 209, identifier:startswith; 210, argument_list; 210, 211; 211, string:'/'; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:include_path; 215, identifier:startswith; 216, argument_list; 216, 217; 217, string:'~'; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:include_path; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:path; 225, identifier:realpath; 226, argument_list; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:path; 230, identifier:expanduser; 231, argument_list; 231, 232; 232, identifier:include_path; 233, else_clause; 233, 234; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:include_path; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:path; 241, identifier:join; 242, argument_list; 242, 243; 242, 249; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:path; 246, identifier:dirname; 247, argument_list; 247, 248; 248, identifier:filename; 249, identifier:include_path; 250, if_statement; 250, 251; 250, 257; 250, 280; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:path; 254, identifier:exists; 255, argument_list; 255, 256; 256, identifier:include_path; 257, block; 257, 258; 257, 268; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 265; 260, attribute; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:self; 263, identifier:log; 264, identifier:debug; 265, argument_list; 265, 266; 265, 267; 266, string:'Recursively parsing mapping in %s'; 267, identifier:include_path; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:dotfiles; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:parse_mapping; 275, argument_list; 275, 276; 275, 277; 276, identifier:include_path; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:dotfiles; 279, identifier:dotfiles; 280, else_clause; 280, 281; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, call; 283, 284; 283, 289; 284, attribute; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:self; 287, identifier:log; 288, identifier:warning; 289, argument_list; 289, 290; 289, 294; 289, 295; 290, concatenated_string; 290, 291; 290, 292; 290, 293; 291, string:'Include command points to file or '; 292, string:'directory that does not exist, "%s",'; 293, string:' on line %d'; 294, identifier:include_path; 295, identifier:lineno; 296, if_statement; 296, 297; 296, 303; 296, 313; 296, 367; 297, boolean_operator:or; 297, 298; 297, 300; 298, not_operator; 298, 299; 299, identifier:content; 300, attribute; 300, 301; 300, 302; 301, identifier:content; 302, identifier:startswith; 303, ERROR; 303, 304; 303, 306; 303, 312; 304, ERROR; 304, 305; 305, identifier:continue; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:mapping_re; 309, identifier:match; 310, argument_list; 310, 311; 311, identifier:content; 312, identifier:match; 313, block; 313, 314; 313, 324; 313, 339; 313, 361; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 319; 316, pattern_list; 316, 317; 316, 318; 317, identifier:source_path; 318, identifier:target_path; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:match; 322, identifier:groups; 323, argument_list; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:source_path; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:path; 330, identifier:join; 331, argument_list; 331, 332; 331, 333; 332, identifier:source; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:source_path; 336, identifier:strip; 337, argument_list; 337, 338; 338, string:'\'"'; 339, if_statement; 339, 340; 339, 343; 339, 356; 340, comparison_operator:in; 340, 341; 340, 342; 341, identifier:source_path; 342, identifier:dotfiles; 343, ERROR; 343, 344; 343, 349; 343, 350; 343, 353; 344, attribute; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:self; 347, identifier:log; 348, identifier:warning; 349, string:'Duplicate dotfile source "%s" '; 350, ERROR; 350, 351; 350, 352; 351, identifier:on; 352, identifier:line; 353, comparison_operator:is; 353, 354; 353, 355; 354, identifier:target_path; 355, None; 356, block; 356, 357; 357, expression_statement; 357, 358; 358, assignment; 358, 359; 358, 360; 359, identifier:target_path; 360, identifier:source_path; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 366; 363, subscript; 363, 364; 363, 365; 364, identifier:dotfiles; 365, identifier:source_path; 366, identifier:target_path; 367, else_clause; 367, 368; 367, 375; 368, ERROR; 368, 369; 368, 374; 369, attribute; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:self; 372, identifier:log; 373, identifier:warning; 374, string:'Dotfile mapping regex failed on line '; 375, block:; 376, return_statement; 376, 377; 377, identifier:dotfiles
def parse_mapping(self, map_path, source=None, dotfiles=None): include_re = r include_re = re.compile(include_re, re.I) mapping_re = r mapping_re = re.compile(mapping_re) filename = None map_path = path.realpath(path.expanduser(map_path)) if path.isfile(map_path): filename = map_path elif path.isdir(map_path): for map_name in '.dotfiles', 'dotfiles': candidate = path.join(map_path, map_name) if path.isfile(candidate): filename = candidate break if filename is None: raise ValueError('No dotfile mapping found in %s' % map_path) if source is None: source = path.dirname(map_path) if dotfiles is None: dotfiles = OrderedDict() lineno = 0 with open(filename) as fh: for line in fh: lineno += 1 content = line.strip() match = include_re.match(content) if match: include_path = match.group(1).strip('\'"') if (include_path.startswith('/') or include_path.startswith('~')): include_path = path.realpath( path.expanduser(include_path)) else: include_path = path.join(path.dirname(filename), include_path) if path.exists(include_path): self.log.debug('Recursively parsing mapping in %s', include_path) dotfiles = self.parse_mapping(include_path, dotfiles=dotfiles) else: self.log.warning('Include command points to file or ' 'directory that does not exist, "%s",' ' on line %d', include_path, lineno) if not content or content.startswith(' continue match = mapping_re.match(content) if match: source_path, target_path = match.groups() source_path = path.join(source, source_path.strip('\'"')) if source_path in dotfiles: self.log.warning('Duplicate dotfile source "%s" ' 'on line continue if target_path is None: target_path = source_path dotfiles[source_path] = target_path else: self.log.warning('Dotfile mapping regex failed on line ' ' return dotfiles
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_add_compounds; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:variant_obj; 6, identifier:info_dict; 7, block; 7, 8; 7, 12; 7, 21; 7, 106; 7, 123; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:compound_list; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:compound_entry; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:info_dict; 18, identifier:get; 19, argument_list; 19, 20; 20, string:'Compounds'; 21, if_statement; 21, 22; 21, 23; 22, identifier:compound_entry; 23, block; 23, 24; 24, for_statement; 24, 25; 24, 26; 24, 32; 25, identifier:family_annotation; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:compound_entry; 29, identifier:split; 30, argument_list; 30, 31; 31, string:','; 32, block; 32, 33; 32, 50; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:compounds; 36, call; 36, 37; 36, 48; 37, attribute; 37, 38; 37, 47; 38, subscript; 38, 39; 38, 45; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:family_annotation; 42, identifier:split; 43, argument_list; 43, 44; 44, string:':'; 45, unary_operator:-; 45, 46; 46, integer:1; 47, identifier:split; 48, argument_list; 48, 49; 49, string:'|'; 50, for_statement; 50, 51; 50, 52; 50, 53; 51, identifier:compound; 52, identifier:compounds; 53, block; 53, 54; 53, 63; 53, 67; 53, 91; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:splitted_compound; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:compound; 60, identifier:split; 61, argument_list; 61, 62; 62, string:'>'; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:compound_score; 66, None; 67, if_statement; 67, 68; 67, 74; 68, comparison_operator:>; 68, 69; 68, 73; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, identifier:splitted_compound; 73, integer:1; 74, block; 74, 75; 74, 81; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:compound_id; 78, subscript; 78, 79; 78, 80; 79, identifier:splitted_compound; 80, integer:0; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:compound_score; 84, call; 84, 85; 84, 86; 85, identifier:int; 86, argument_list; 86, 87; 87, subscript; 87, 88; 87, 89; 88, identifier:splitted_compound; 89, unary_operator:-; 89, 90; 90, integer:1; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:compound_list; 95, identifier:append; 96, argument_list; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:Compound; 99, argument_list; 99, 100; 99, 103; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:variant_id; 102, identifier:compound_id; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:combined_score; 105, identifier:compound_score; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:compound_list; 110, identifier:sort; 111, argument_list; 111, 112; 111, 120; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:key; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:operator; 117, identifier:attrgetter; 118, argument_list; 118, 119; 119, string:'combined_score'; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:reverse; 122, True; 123, for_statement; 123, 124; 123, 125; 123, 126; 124, identifier:compound; 125, identifier:compound_list; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:variant_obj; 131, identifier:add_compound; 132, argument_list; 132, 133; 133, identifier:compound
def _add_compounds(self, variant_obj, info_dict): compound_list = [] compound_entry = info_dict.get('Compounds') if compound_entry: for family_annotation in compound_entry.split(','): compounds = family_annotation.split(':')[-1].split('|') for compound in compounds: splitted_compound = compound.split('>') compound_score = None if len(splitted_compound) > 1: compound_id = splitted_compound[0] compound_score = int(splitted_compound[-1]) compound_list.append(Compound( variant_id=compound_id, combined_score=compound_score ) ) compound_list.sort(key = operator.attrgetter('combined_score'), reverse=True) for compound in compound_list: variant_obj.add_compound(compound)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:dump_xml; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:props; 5, identifier:fp; 6, default_parameter; 6, 7; 6, 8; 7, identifier:comment; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:encoding; 11, string:'UTF-8'; 12, default_parameter; 12, 13; 12, 14; 13, identifier:sort_keys; 14, False; 15, block; 15, 16; 15, 33; 15, 49; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:fp; 19, call; 19, 20; 19, 28; 20, attribute; 20, 21; 20, 27; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:codecs; 24, identifier:lookup; 25, argument_list; 25, 26; 26, identifier:encoding; 27, identifier:streamwriter; 28, argument_list; 28, 29; 28, 30; 29, identifier:fp; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:errors; 32, string:'xmlcharrefreplace'; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:print; 36, argument_list; 36, 37; 36, 46; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, string:'<?xml version="1.0" encoding={0} standalone="no"?>'; 40, identifier:format; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:quoteattr; 44, argument_list; 44, 45; 45, identifier:encoding; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:file; 48, identifier:fp; 49, for_statement; 49, 50; 49, 51; 49, 57; 50, identifier:s; 51, call; 51, 52; 51, 53; 52, identifier:_stream_xml; 53, argument_list; 53, 54; 53, 55; 53, 56; 54, identifier:props; 55, identifier:comment; 56, identifier:sort_keys; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:print; 61, argument_list; 61, 62; 61, 63; 62, identifier:s; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:file; 65, identifier:fp
def dump_xml(props, fp, comment=None, encoding='UTF-8', sort_keys=False): fp = codecs.lookup(encoding).streamwriter(fp, errors='xmlcharrefreplace') print('<?xml version="1.0" encoding={0} standalone="no"?>' .format(quoteattr(encoding)), file=fp) for s in _stream_xml(props, comment, sort_keys): print(s, file=fp)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:dumps_xml; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:props; 5, default_parameter; 5, 6; 5, 7; 6, identifier:comment; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_keys; 10, False; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, string:''; 16, identifier:join; 17, generator_expression; 17, 18; 17, 21; 18, binary_operator:+; 18, 19; 18, 20; 19, identifier:s; 20, string:'\n'; 21, for_in_clause; 21, 22; 21, 23; 22, identifier:s; 23, call; 23, 24; 23, 25; 24, identifier:_stream_xml; 25, argument_list; 25, 26; 25, 27; 25, 28; 26, identifier:props; 27, identifier:comment; 28, identifier:sort_keys
def dumps_xml(props, comment=None, sort_keys=False): return ''.join(s + '\n' for s in _stream_xml(props, comment, sort_keys))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:gene_list; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:list_id; 6, None; 7, block; 7, 8; 7, 24; 7, 76; 7, 130; 7, 267; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:all_case_ids; 11, list_comprehension; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:case; 14, identifier:case_id; 15, for_in_clause; 15, 16; 15, 17; 16, identifier:case; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:app; 21, identifier:db; 22, identifier:cases; 23, argument_list; 24, if_statement; 24, 25; 24, 26; 25, identifier:list_id; 26, block; 26, 27; 26, 38; 26, 60; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:genelist_obj; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:app; 34, identifier:db; 35, identifier:gene_list; 36, argument_list; 36, 37; 37, identifier:list_id; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:case_ids; 41, list_comprehension; 41, 42; 41, 45; 41, 54; 42, attribute; 42, 43; 42, 44; 43, identifier:case; 44, identifier:case_id; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:case; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:app; 51, identifier:db; 52, identifier:cases; 53, argument_list; 54, if_clause; 54, 55; 55, comparison_operator:not; 55, 56; 55, 57; 56, identifier:case; 57, attribute; 57, 58; 57, 59; 58, identifier:genelist_obj; 59, identifier:cases; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:is; 61, 62; 61, 63; 62, identifier:genelist_obj; 63, None; 64, block; 64, 65; 65, return_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:abort; 68, argument_list; 68, 69; 68, 70; 69, integer:404; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:"gene list not found: {}"; 73, identifier:format; 74, argument_list; 74, 75; 75, identifier:list_id; 76, if_statement; 76, 77; 76, 82; 77, comparison_operator:in; 77, 78; 77, 79; 78, string:'download'; 79, attribute; 79, 80; 79, 81; 80, identifier:request; 81, identifier:args; 82, block; 82, 83; 82, 97; 82, 111; 82, 120; 82, 128; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:response; 86, call; 86, 87; 86, 88; 87, identifier:make_response; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, string:'\n'; 92, identifier:join; 93, argument_list; 93, 94; 94, attribute; 94, 95; 94, 96; 95, identifier:genelist_obj; 96, identifier:gene_ids; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:filename; 100, call; 100, 101; 100, 102; 101, identifier:secure_filename; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, string:"{}.txt"; 106, identifier:format; 107, argument_list; 107, 108; 108, attribute; 108, 109; 108, 110; 109, identifier:genelist_obj; 110, identifier:list_id; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:header; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, string:"attachment; filename={}"; 117, identifier:format; 118, argument_list; 118, 119; 119, identifier:filename; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 127; 122, subscript; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:response; 125, identifier:headers; 126, string:'Content-Disposition'; 127, identifier:header; 128, return_statement; 128, 129; 129, identifier:response; 130, if_statement; 130, 131; 130, 136; 131, comparison_operator:==; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:request; 134, identifier:method; 135, string:'POST'; 136, block; 136, 137; 137, if_statement; 137, 138; 137, 139; 137, 190; 138, identifier:list_id; 139, block; 139, 140; 139, 151; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:case_ids; 143, call; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:request; 147, identifier:form; 148, identifier:getlist; 149, argument_list; 149, 150; 150, string:'case_id'; 151, for_statement; 151, 152; 151, 153; 151, 154; 152, identifier:case_id; 153, identifier:case_ids; 154, block; 154, 155; 154, 166; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:case_obj; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:app; 162, identifier:db; 163, identifier:case; 164, argument_list; 164, 165; 165, identifier:case_id; 166, if_statement; 166, 167; 166, 172; 167, comparison_operator:not; 167, 168; 167, 169; 168, identifier:case_obj; 169, attribute; 169, 170; 169, 171; 170, identifier:genelist_obj; 171, identifier:cases; 172, block; 172, 173; 172, 182; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:genelist_obj; 178, identifier:cases; 179, identifier:append; 180, argument_list; 180, 181; 181, identifier:case_obj; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:app; 187, identifier:db; 188, identifier:save; 189, argument_list; 190, else_clause; 190, 191; 191, block; 191, 192; 191, 200; 191, 216; 191, 232; 191, 242; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:req_file; 195, subscript; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:request; 198, identifier:files; 199, string:'file'; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:new_listid; 203, parenthesized_expression; 203, 204; 204, boolean_operator:or; 204, 205; 204, 210; 205, subscript; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:request; 208, identifier:form; 209, string:'list_id'; 210, call; 210, 211; 210, 212; 211, identifier:secure_filename; 212, argument_list; 212, 213; 213, attribute; 213, 214; 213, 215; 214, identifier:req_file; 215, identifier:filename; 216, if_statement; 216, 217; 216, 225; 217, call; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:app; 221, identifier:db; 222, identifier:gene_list; 223, argument_list; 223, 224; 224, identifier:new_listid; 225, block; 225, 226; 226, return_statement; 226, 227; 227, call; 227, 228; 227, 229; 228, identifier:abort; 229, argument_list; 229, 230; 229, 231; 230, integer:500; 231, string:'Please provide a unique list name'; 232, if_statement; 232, 233; 232, 235; 233, not_operator; 233, 234; 234, identifier:req_file; 235, block; 235, 236; 236, return_statement; 236, 237; 237, call; 237, 238; 237, 239; 238, identifier:abort; 239, argument_list; 239, 240; 239, 241; 240, integer:500; 241, string:'Please provide a file for upload'; 242, ERROR; 242, 243; 242, 244; 242, 245; 242, 250; 242, 253; 242, 254; 242, 265; 242, 266; 243, identifier:gene_ids; 244, identifier:line; 245, for_in_clause; 245, 246; 245, 247; 246, identifier:line; 247, attribute; 247, 248; 247, 249; 248, identifier:req_file; 249, identifier:stream; 250, attribute; 250, 251; 250, 252; 251, identifier:line; 252, identifier:startswith; 253, ERROR; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:genelist_obj; 256, call; 256, 257; 256, 262; 257, attribute; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:app; 260, identifier:db; 261, identifier:add_genelist; 262, argument_list; 262, 263; 262, 264; 263, identifier:new_listid; 264, identifier:gene_ids; 265, identifier:case_ids; 266, identifier:all_case_ids; 267, return_statement; 267, 268; 268, call; 268, 269; 268, 270; 269, identifier:render_template; 270, argument_list; 270, 271; 270, 272; 270, 275; 271, string:'gene_list.html'; 272, keyword_argument; 272, 273; 272, 274; 273, identifier:gene_list; 274, identifier:genelist_obj; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:case_ids; 277, identifier:case_ids
def gene_list(list_id=None): all_case_ids = [case.case_id for case in app.db.cases()] if list_id: genelist_obj = app.db.gene_list(list_id) case_ids = [case.case_id for case in app.db.cases() if case not in genelist_obj.cases] if genelist_obj is None: return abort(404, "gene list not found: {}".format(list_id)) if 'download' in request.args: response = make_response('\n'.join(genelist_obj.gene_ids)) filename = secure_filename("{}.txt".format(genelist_obj.list_id)) header = "attachment; filename={}".format(filename) response.headers['Content-Disposition'] = header return response if request.method == 'POST': if list_id: case_ids = request.form.getlist('case_id') for case_id in case_ids: case_obj = app.db.case(case_id) if case_obj not in genelist_obj.cases: genelist_obj.cases.append(case_obj) app.db.save() else: req_file = request.files['file'] new_listid = (request.form['list_id'] or secure_filename(req_file.filename)) if app.db.gene_list(new_listid): return abort(500, 'Please provide a unique list name') if not req_file: return abort(500, 'Please provide a file for upload') gene_ids = [line for line in req_file.stream if not line.startswith(' genelist_obj = app.db.add_genelist(new_listid, gene_ids) case_ids = all_case_ids return render_template('gene_list.html', gene_list=genelist_obj, case_ids=case_ids)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_functarguments; 3, parameters; 3, 4; 4, identifier:func; 5, block; 5, 6; 5, 15; 5, 75; 5, 91; 5, 97; 5, 101; 5, 108; 5, 153; 5, 288; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:argspec; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:inspect; 12, identifier:getargspec; 13, argument_list; 13, 14; 14, identifier:func; 15, if_statement; 15, 16; 15, 21; 15, 63; 16, comparison_operator:is; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:argspec; 19, identifier:defaults; 20, None; 21, block; 21, 22; 21, 38; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:args; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:argspec; 28, identifier:args; 29, slice; 29, 30; 29, 31; 30, colon; 31, unary_operator:-; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:len; 34, argument_list; 34, 35; 35, attribute; 35, 36; 35, 37; 36, identifier:argspec; 37, identifier:defaults; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:kwargs; 41, call; 41, 42; 41, 43; 42, identifier:dict; 43, argument_list; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:zip; 46, argument_list; 46, 47; 46, 60; 47, subscript; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:argspec; 50, identifier:args; 51, slice; 51, 52; 51, 59; 52, unary_operator:-; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, attribute; 56, 57; 56, 58; 57, identifier:argspec; 58, identifier:defaults; 59, colon; 60, attribute; 60, 61; 60, 62; 61, identifier:argspec; 62, identifier:defaults; 63, else_clause; 63, 64; 64, block; 64, 65; 64, 71; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:args; 68, attribute; 68, 69; 68, 70; 69, identifier:argspec; 70, identifier:args; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:kwargs; 74, dictionary; 75, if_statement; 75, 76; 75, 83; 76, boolean_operator:and; 76, 77; 76, 78; 77, identifier:args; 78, comparison_operator:==; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:args; 81, integer:0; 82, string:'self'; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:args; 88, identifier:pop; 89, argument_list; 89, 90; 90, integer:0; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:func; 95, identifier:__named__; 96, list:[]; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:arguments; 100, list:[]; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:shared; 104, call; 104, 105; 104, 106; 105, identifier:get_shared; 106, argument_list; 106, 107; 107, identifier:func; 108, for_statement; 108, 109; 108, 110; 108, 111; 109, identifier:arg; 110, identifier:args; 111, block; 111, 112; 111, 122; 111, 134; 111, 144; 112, if_statement; 112, 113; 112, 120; 113, comparison_operator:is; 113, 114; 113, 119; 114, call; 114, 115; 114, 116; 115, identifier:has_shared; 116, argument_list; 116, 117; 116, 118; 117, identifier:arg; 118, identifier:shared; 119, False; 120, block; 120, 121; 121, continue_statement; 122, if_statement; 122, 123; 122, 132; 123, comparison_operator:is; 123, 124; 123, 131; 124, call; 124, 125; 124, 126; 125, identifier:has_argument; 126, argument_list; 126, 127; 126, 128; 127, identifier:arg; 128, attribute; 128, 129; 128, 130; 129, identifier:func; 130, identifier:__cls__; 131, False; 132, block; 132, 133; 133, continue_statement; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:arguments; 138, identifier:append; 139, argument_list; 139, 140; 140, tuple; 140, 141; 140, 143; 141, list:[arg]; 141, 142; 142, identifier:arg; 143, dictionary; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 151; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:func; 149, identifier:__named__; 150, identifier:append; 151, argument_list; 151, 152; 152, identifier:arg; 153, for_statement; 153, 154; 153, 157; 153, 162; 154, pattern_list; 154, 155; 154, 156; 155, identifier:key; 156, identifier:val; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:kwargs; 160, identifier:items; 161, argument_list; 162, block; 162, 163; 162, 173; 162, 185; 162, 270; 162, 279; 163, if_statement; 163, 164; 163, 171; 164, comparison_operator:is; 164, 165; 164, 170; 165, call; 165, 166; 165, 167; 166, identifier:has_shared; 167, argument_list; 167, 168; 167, 169; 168, identifier:key; 169, identifier:shared; 170, False; 171, block; 171, 172; 172, continue_statement; 173, if_statement; 173, 174; 173, 183; 174, comparison_operator:is; 174, 175; 174, 182; 175, call; 175, 176; 175, 177; 176, identifier:has_argument; 177, argument_list; 177, 178; 177, 179; 178, identifier:key; 179, attribute; 179, 180; 179, 181; 180, identifier:func; 181, identifier:__cls__; 182, False; 183, block; 183, 184; 184, continue_statement; 185, if_statement; 185, 186; 185, 191; 185, 242; 186, call; 186, 187; 186, 188; 187, identifier:isinstance; 188, argument_list; 188, 189; 188, 190; 189, identifier:val; 190, identifier:dict; 191, block; 191, 192; 191, 205; 191, 215; 191, 231; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:flags; 195, list:[val.pop('lflag', '--%s' % key)]; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:val; 199, identifier:pop; 200, argument_list; 200, 201; 200, 202; 201, string:'lflag'; 202, binary_operator:%; 202, 203; 202, 204; 203, string:'--%s'; 204, identifier:key; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:short; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:val; 211, identifier:pop; 212, argument_list; 212, 213; 212, 214; 213, string:'flag'; 214, None; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:dest; 218, call; 218, 219; 218, 228; 219, attribute; 219, 220; 219, 227; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:val; 223, identifier:get; 224, argument_list; 224, 225; 224, 226; 225, string:'dest'; 226, identifier:key; 227, identifier:replace; 228, argument_list; 228, 229; 228, 230; 229, string:'-'; 230, string:'_'; 231, if_statement; 231, 232; 231, 233; 232, identifier:short; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:flags; 238, identifier:insert; 239, argument_list; 239, 240; 239, 241; 240, integer:0; 241, identifier:short; 242, else_clause; 242, 243; 243, block; 243, 244; 243, 251; 243, 260; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:flags; 247, list:['--%s' % key]; 247, 248; 248, binary_operator:%; 248, 249; 248, 250; 249, string:'--%s'; 250, identifier:key; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:val; 254, call; 254, 255; 254, 256; 255, identifier:dict; 256, argument_list; 256, 257; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:default; 259, identifier:val; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:dest; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:key; 266, identifier:replace; 267, argument_list; 267, 268; 267, 269; 268, string:'-'; 269, string:'_'; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 277; 272, attribute; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:func; 275, identifier:__named__; 276, identifier:append; 277, argument_list; 277, 278; 278, identifier:dest; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:arguments; 283, identifier:append; 284, argument_list; 284, 285; 285, tuple; 285, 286; 285, 287; 286, identifier:flags; 287, identifier:val; 288, return_statement; 288, 289; 289, identifier:arguments
def get_functarguments(func): argspec = inspect.getargspec(func) if argspec.defaults is not None: args = argspec.args[:-len(argspec.defaults)] kwargs = dict( zip(argspec.args[-len(argspec.defaults):], argspec.defaults)) else: args = argspec.args kwargs = {} if args and args[0] == 'self': args.pop(0) func.__named__ = [] arguments = [] shared = get_shared(func) for arg in args: if has_shared(arg, shared) is not False: continue if has_argument(arg, func.__cls__) is not False: continue arguments.append(([arg], {}, )) func.__named__.append(arg) for key, val in kwargs.items(): if has_shared(key, shared) is not False: continue if has_argument(key, func.__cls__) is not False: continue if isinstance(val, dict): flags = [val.pop('lflag', '--%s' % key)] short = val.pop('flag', None) dest = val.get('dest', key).replace('-', '_') if short: flags.insert(0, short) else: flags = ['--%s' % key] val = dict(default=val) dest = key.replace('-', '_') func.__named__.append(dest) arguments.append((flags, val, )) return arguments
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:load; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:ctx; 5, identifier:variant_source; 6, identifier:family_file; 7, identifier:family_type; 8, identifier:root; 9, block; 9, 10; 9, 32; 9, 55; 9, 67; 9, 79; 9, 91; 9, 115; 9, 139; 9, 146; 9, 193; 9, 205; 9, 212; 9, 224; 9, 245; 9, 266; 9, 273; 9, 280; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:root; 13, boolean_operator:or; 13, 14; 13, 24; 14, boolean_operator:or; 14, 15; 14, 16; 15, identifier:root; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:ctx; 20, identifier:obj; 21, identifier:get; 22, argument_list; 22, 23; 23, string:'root'; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:os; 28, identifier:path; 29, identifier:expanduser; 30, argument_list; 30, 31; 31, string:"~/.puzzle"; 32, if_statement; 32, 33; 32, 41; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:os; 37, identifier:path; 38, identifier:isfile; 39, argument_list; 39, 40; 40, identifier:root; 41, block; 41, 42; 41, 49; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:logger; 46, identifier:error; 47, argument_list; 47, 48; 48, string:"'root' can't be a file"; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:ctx; 53, identifier:abort; 54, argument_list; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:logger; 59, identifier:info; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, string:"Root directory is: {}"; 64, identifier:format; 65, argument_list; 65, 66; 66, identifier:root; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:db_path; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:os; 74, identifier:path; 75, identifier:join; 76, argument_list; 76, 77; 76, 78; 77, identifier:root; 78, string:'puzzle_db.sqlite3'; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:logger; 83, identifier:info; 84, argument_list; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, string:"db path is: {}"; 88, identifier:format; 89, argument_list; 89, 90; 90, identifier:db_path; 91, if_statement; 91, 92; 91, 101; 92, not_operator; 92, 93; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:os; 97, identifier:path; 98, identifier:exists; 99, argument_list; 99, 100; 100, identifier:db_path; 101, block; 101, 102; 101, 109; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:logger; 106, identifier:warn; 107, argument_list; 107, 108; 108, string:"database not initialized, run 'puzzle init'"; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:ctx; 113, identifier:abort; 114, argument_list; 115, if_statement; 115, 116; 115, 125; 116, not_operator; 116, 117; 117, call; 117, 118; 117, 123; 118, attribute; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:os; 121, identifier:path; 122, identifier:isfile; 123, argument_list; 123, 124; 124, identifier:variant_source; 125, block; 125, 126; 125, 133; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:logger; 130, identifier:error; 131, argument_list; 131, 132; 132, string:"Variant source has to be a file"; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:ctx; 137, identifier:abort; 138, argument_list; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:mode; 142, call; 142, 143; 142, 144; 143, identifier:get_file_type; 144, argument_list; 144, 145; 145, identifier:variant_source; 146, if_statement; 146, 147; 146, 150; 146, 164; 147, comparison_operator:==; 147, 148; 147, 149; 148, identifier:mode; 149, string:'unknown'; 150, block; 150, 151; 150, 158; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:logger; 155, identifier:error; 156, argument_list; 156, 157; 157, string:"Unknown file type"; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:ctx; 162, identifier:abort; 163, argument_list; 164, elif_clause; 164, 165; 164, 168; 165, comparison_operator:==; 165, 166; 165, 167; 166, identifier:mode; 167, string:'gemini'; 168, block; 168, 169; 168, 176; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:logger; 173, identifier:debug; 174, argument_list; 174, 175; 175, string:"Initialzing GEMINI plugin"; 176, if_statement; 176, 177; 176, 179; 177, not_operator; 177, 178; 178, identifier:GEMINI; 179, block; 179, 180; 179, 187; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:logger; 184, identifier:error; 185, argument_list; 185, 186; 186, string:"Need to have gemini installed to use gemini plugin"; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:ctx; 191, identifier:abort; 192, argument_list; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:logger; 197, identifier:debug; 198, argument_list; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, string:'Set puzzle backend to {0}'; 202, identifier:format; 203, argument_list; 203, 204; 204, identifier:mode; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:variant_type; 208, call; 208, 209; 208, 210; 209, identifier:get_variant_type; 210, argument_list; 210, 211; 211, identifier:variant_source; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:logger; 216, identifier:debug; 217, argument_list; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, string:'Set variant type to {0}'; 221, identifier:format; 222, argument_list; 222, 223; 223, identifier:variant_type; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:cases; 227, call; 227, 228; 227, 229; 228, identifier:get_cases; 229, argument_list; 229, 230; 229, 233; 229, 236; 229, 239; 229, 242; 230, keyword_argument; 230, 231; 230, 232; 231, identifier:variant_source; 232, identifier:variant_source; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:case_lines; 235, identifier:family_file; 236, keyword_argument; 236, 237; 236, 238; 237, identifier:case_type; 238, identifier:family_type; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:variant_type; 241, identifier:variant_type; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:variant_mode; 244, identifier:mode; 245, if_statement; 245, 246; 245, 252; 246, comparison_operator:==; 246, 247; 246, 251; 247, call; 247, 248; 247, 249; 248, identifier:len; 249, argument_list; 249, 250; 250, identifier:cases; 251, integer:0; 252, block; 252, 253; 252, 260; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:logger; 257, identifier:warning; 258, argument_list; 258, 259; 259, string:"No cases found"; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:ctx; 264, identifier:abort; 265, argument_list; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:logger; 270, identifier:info; 271, argument_list; 271, 272; 272, string:"Initializing sqlite plugin"; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:store; 276, call; 276, 277; 276, 278; 277, identifier:SqlStore; 278, argument_list; 278, 279; 279, identifier:db_path; 280, for_statement; 280, 281; 280, 282; 280, 283; 281, identifier:case_obj; 282, identifier:cases; 283, block; 283, 284; 283, 311; 283, 325; 284, if_statement; 284, 285; 284, 295; 285, comparison_operator:is; 285, 286; 285, 294; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:store; 289, identifier:case; 290, argument_list; 290, 291; 291, attribute; 291, 292; 291, 293; 292, identifier:case_obj; 293, identifier:case_id; 294, None; 295, block; 295, 296; 295, 310; 296, expression_statement; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:logger; 300, identifier:warn; 301, argument_list; 301, 302; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, string:"{} already exists in the database"; 305, identifier:format; 306, argument_list; 306, 307; 307, attribute; 307, 308; 307, 309; 308, identifier:case_obj; 309, identifier:case_id; 310, continue_statement; 311, expression_statement; 311, 312; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:logger; 315, identifier:debug; 316, argument_list; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, string:"adding case: {} to puzzle db"; 320, identifier:format; 321, argument_list; 321, 322; 322, attribute; 322, 323; 322, 324; 323, identifier:case_obj; 324, identifier:case_id; 325, expression_statement; 325, 326; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:store; 329, identifier:add_case; 330, argument_list; 330, 331; 330, 332; 330, 335; 331, identifier:case_obj; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:vtype; 334, identifier:variant_type; 335, keyword_argument; 335, 336; 335, 337; 336, identifier:mode; 337, identifier:mode
def load(ctx, variant_source, family_file, family_type, root): root = root or ctx.obj.get('root') or os.path.expanduser("~/.puzzle") if os.path.isfile(root): logger.error("'root' can't be a file") ctx.abort() logger.info("Root directory is: {}".format(root)) db_path = os.path.join(root, 'puzzle_db.sqlite3') logger.info("db path is: {}".format(db_path)) if not os.path.exists(db_path): logger.warn("database not initialized, run 'puzzle init'") ctx.abort() if not os.path.isfile(variant_source): logger.error("Variant source has to be a file") ctx.abort() mode = get_file_type(variant_source) if mode == 'unknown': logger.error("Unknown file type") ctx.abort() elif mode == 'gemini': logger.debug("Initialzing GEMINI plugin") if not GEMINI: logger.error("Need to have gemini installed to use gemini plugin") ctx.abort() logger.debug('Set puzzle backend to {0}'.format(mode)) variant_type = get_variant_type(variant_source) logger.debug('Set variant type to {0}'.format(variant_type)) cases = get_cases( variant_source=variant_source, case_lines=family_file, case_type=family_type, variant_type=variant_type, variant_mode=mode ) if len(cases) == 0: logger.warning("No cases found") ctx.abort() logger.info("Initializing sqlite plugin") store = SqlStore(db_path) for case_obj in cases: if store.case(case_obj.case_id) is not None: logger.warn("{} already exists in the database" .format(case_obj.case_id)) continue logger.debug("adding case: {} to puzzle db".format(case_obj.case_id)) store.add_case(case_obj, vtype=variant_type, mode=mode)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:toposort; 3, parameters; 3, 4; 3, 5; 4, identifier:graph; 5, default_parameter; 5, 6; 5, 7; 6, identifier:pick_first; 7, string:'head'; 8, block; 8, 9; 8, 13; 8, 54; 8, 59; 8, 63; 8, 69; 8, 155; 8, 173; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:in_deg; 12, dictionary; 13, for_statement; 13, 14; 13, 17; 13, 23; 14, pattern_list; 14, 15; 14, 16; 15, identifier:node; 16, identifier:next_nodes; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:six; 20, identifier:iteritems; 21, argument_list; 21, 22; 22, identifier:graph; 23, block; 23, 24; 24, for_statement; 24, 25; 24, 26; 24, 33; 25, identifier:next_node; 26, list:[next_nodes.head_node, next_nodes.update_node]; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:next_nodes; 29, identifier:head_node; 30, attribute; 30, 31; 30, 32; 31, identifier:next_nodes; 32, identifier:update_node; 33, block; 33, 34; 33, 40; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:next_node; 37, None; 38, block; 38, 39; 39, continue_statement; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:in_deg; 44, identifier:next_node; 45, binary_operator:+; 45, 46; 45, 53; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:in_deg; 49, identifier:get; 50, argument_list; 50, 51; 50, 52; 51, identifier:next_node; 52, integer:0; 53, integer:1; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:stk; 57, list:[FIRST]; 57, 58; 58, identifier:FIRST; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:ordered; 62, list:[]; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:visited; 66, call; 66, 67; 66, 68; 67, identifier:set; 68, argument_list; 69, while_statement; 69, 70; 69, 71; 70, identifier:stk; 71, block; 71, 72; 71, 80; 71, 87; 71, 99; 71, 115; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:node; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:stk; 78, identifier:pop; 79, argument_list; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:visited; 84, identifier:add; 85, argument_list; 85, 86; 86, identifier:node; 87, if_statement; 87, 88; 87, 91; 88, comparison_operator:!=; 88, 89; 88, 90; 89, identifier:node; 90, identifier:FIRST; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:ordered; 96, identifier:append; 97, argument_list; 97, 98; 98, identifier:node; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:traversal; 102, call; 102, 103; 102, 104; 103, identifier:_get_traversal; 104, argument_list; 104, 105; 104, 114; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:graph; 108, identifier:get; 109, argument_list; 109, 110; 109, 111; 110, identifier:node; 111, call; 111, 112; 111, 113; 112, identifier:BeforeNodes; 113, argument_list; 114, identifier:pick_first; 115, for_statement; 115, 116; 115, 117; 115, 118; 116, identifier:next_node; 117, identifier:traversal; 118, block; 118, 119; 118, 125; 118, 135; 118, 141; 119, if_statement; 119, 120; 119, 123; 120, comparison_operator:is; 120, 121; 120, 122; 121, identifier:next_node; 122, None; 123, block; 123, 124; 124, continue_statement; 125, if_statement; 125, 126; 125, 129; 126, comparison_operator:in; 126, 127; 126, 128; 127, identifier:next_node; 128, identifier:visited; 129, block; 129, 130; 130, raise_statement; 130, 131; 131, call; 131, 132; 131, 133; 132, identifier:ValueError; 133, argument_list; 133, 134; 134, string:'Graph has a cycle'; 135, expression_statement; 135, 136; 136, augmented_assignment:-=; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:in_deg; 139, identifier:next_node; 140, integer:1; 141, if_statement; 141, 142; 141, 147; 142, comparison_operator:==; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:in_deg; 145, identifier:next_node; 146, integer:0; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:stk; 152, identifier:append; 153, argument_list; 153, 154; 154, identifier:next_node; 155, if_statement; 155, 156; 155, 167; 156, comparison_operator:!=; 156, 157; 156, 161; 157, call; 157, 158; 157, 159; 158, identifier:len; 159, argument_list; 159, 160; 160, identifier:ordered; 161, binary_operator:-; 161, 162; 161, 166; 162, call; 162, 163; 162, 164; 163, identifier:len; 164, argument_list; 164, 165; 165, identifier:graph; 166, integer:1; 167, block; 167, 168; 168, raise_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:ValueError; 171, argument_list; 171, 172; 172, string:'Graph has a cycle'; 173, return_statement; 173, 174; 174, identifier:ordered
def toposort(graph, pick_first='head'): in_deg = {} for node, next_nodes in six.iteritems(graph): for next_node in [next_nodes.head_node, next_nodes.update_node]: if next_node is None: continue in_deg[next_node] = in_deg.get(next_node, 0) + 1 stk = [FIRST] ordered = [] visited = set() while stk: node = stk.pop() visited.add(node) if node != FIRST: ordered.append(node) traversal = _get_traversal(graph.get(node, BeforeNodes()), pick_first) for next_node in traversal: if next_node is None: continue if next_node in visited: raise ValueError('Graph has a cycle') in_deg[next_node] -= 1 if in_deg[next_node] == 0: stk.append(next_node) if len(ordered) != len(graph) - 1: raise ValueError('Graph has a cycle') return ordered