sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:goto; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:reference_beats; 5, identifier:estimated_beats; 6, default_parameter; 6, 7; 6, 8; 7, identifier:goto_threshold; 8, float:0.35; 9, default_parameter; 9, 10; 9, 11; 10, identifier:goto_mu; 11, float:0.2; 12, default_parameter; 12, 13; 12, 14; 13, identifier:goto_sigma; 14, float:0.2; 15, block; 15, 16; 15, 22; 15, 37; 15, 50; 15, 63; 15, 67; 15, 213; 15, 229; 15, 339; 15, 374; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:validate; 19, argument_list; 19, 20; 19, 21; 20, identifier:reference_beats; 21, identifier:estimated_beats; 22, if_statement; 22, 23; 22, 34; 23, boolean_operator:or; 23, 24; 23, 29; 24, comparison_operator:==; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:estimated_beats; 27, identifier:size; 28, integer:0; 29, comparison_operator:==; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:reference_beats; 32, identifier:size; 33, integer:0; 34, block; 34, 35; 35, return_statement; 35, 36; 36, float:0.; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:beat_error; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:np; 43, identifier:ones; 44, argument_list; 44, 45; 45, subscript; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:reference_beats; 48, identifier:shape; 49, integer:0; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:paired; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:np; 56, identifier:zeros; 57, argument_list; 57, 58; 58, subscript; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:reference_beats; 61, identifier:shape; 62, integer:0; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:goto_criteria; 66, integer:0; 67, for_statement; 67, 68; 67, 69; 67, 80; 68, identifier:n; 69, call; 69, 70; 69, 71; 70, identifier:range; 71, argument_list; 71, 72; 71, 73; 72, integer:1; 73, binary_operator:-; 73, 74; 73, 79; 74, subscript; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:reference_beats; 77, identifier:shape; 78, integer:0; 79, integer:1; 80, block; 80, 81; 80, 96; 80, 104; 80, 119; 80, 127; 80, 143; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:previous_interval; 84, binary_operator:*; 84, 85; 84, 86; 85, float:0.5; 86, parenthesized_expression; 86, 87; 87, binary_operator:-; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:reference_beats; 90, identifier:n; 91, subscript; 91, 92; 91, 93; 92, identifier:reference_beats; 93, binary_operator:-; 93, 94; 93, 95; 94, identifier:n; 95, integer:1; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:window_min; 99, binary_operator:-; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:reference_beats; 102, identifier:n; 103, identifier:previous_interval; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:next_interval; 107, binary_operator:*; 107, 108; 107, 109; 108, float:0.5; 109, parenthesized_expression; 109, 110; 110, binary_operator:-; 110, 111; 110, 116; 111, subscript; 111, 112; 111, 113; 112, identifier:reference_beats; 113, binary_operator:+; 113, 114; 113, 115; 114, identifier:n; 115, integer:1; 116, subscript; 116, 117; 116, 118; 117, identifier:reference_beats; 118, identifier:n; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:window_max; 122, binary_operator:+; 122, 123; 122, 126; 123, subscript; 123, 124; 123, 125; 124, identifier:reference_beats; 125, identifier:n; 126, identifier:next_interval; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:beats_in_window; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:np; 133, identifier:logical_and; 134, argument_list; 134, 135; 134, 139; 135, parenthesized_expression; 135, 136; 136, comparison_operator:>=; 136, 137; 136, 138; 137, identifier:estimated_beats; 138, identifier:window_min; 139, parenthesized_expression; 139, 140; 140, comparison_operator:<; 140, 141; 140, 142; 141, identifier:estimated_beats; 142, identifier:window_max; 143, if_statement; 143, 144; 143, 159; 143, 172; 144, boolean_operator:or; 144, 145; 144, 152; 145, comparison_operator:==; 145, 146; 145, 151; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:beats_in_window; 149, identifier:sum; 150, argument_list; 151, integer:0; 152, comparison_operator:>; 152, 153; 152, 158; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:beats_in_window; 156, identifier:sum; 157, argument_list; 158, integer:1; 159, block; 159, 160; 159, 166; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, subscript; 162, 163; 162, 164; 163, identifier:paired; 164, identifier:n; 165, integer:0; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:beat_error; 170, identifier:n; 171, integer:1; 172, else_clause; 172, 173; 173, block; 173, 174; 173, 180; 173, 190; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:paired; 178, identifier:n; 179, integer:1; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:offset; 183, binary_operator:-; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:estimated_beats; 186, identifier:beats_in_window; 187, subscript; 187, 188; 187, 189; 188, identifier:reference_beats; 189, identifier:n; 190, if_statement; 190, 191; 190, 194; 190, 203; 191, comparison_operator:<; 191, 192; 191, 193; 192, identifier:offset; 193, integer:0; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:beat_error; 199, identifier:n; 200, binary_operator:/; 200, 201; 200, 202; 201, identifier:offset; 202, identifier:previous_interval; 203, else_clause; 203, 204; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 210; 207, subscript; 207, 208; 207, 209; 208, identifier:beat_error; 209, identifier:n; 210, binary_operator:/; 210, 211; 210, 212; 211, identifier:offset; 212, identifier:next_interval; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:incorrect_beats; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:np; 219, identifier:flatnonzero; 220, argument_list; 220, 221; 221, comparison_operator:>; 221, 222; 221, 228; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:np; 225, identifier:abs; 226, argument_list; 226, 227; 227, identifier:beat_error; 228, identifier:goto_threshold; 229, if_statement; 229, 230; 229, 237; 229, 260; 230, comparison_operator:<; 230, 231; 230, 236; 231, subscript; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:incorrect_beats; 234, identifier:shape; 235, integer:0; 236, integer:3; 237, block; 237, 238; 237, 256; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:track; 241, subscript; 241, 242; 241, 243; 242, identifier:beat_error; 243, slice; 243, 244; 243, 249; 243, 250; 244, binary_operator:+; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:incorrect_beats; 247, integer:0; 248, integer:1; 249, colon; 250, binary_operator:-; 250, 251; 250, 255; 251, subscript; 251, 252; 251, 253; 252, identifier:incorrect_beats; 253, unary_operator:-; 253, 254; 254, integer:1; 255, integer:1; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:goto_criteria; 259, integer:1; 260, else_clause; 260, 261; 261, block; 261, 262; 261, 276; 261, 294; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:track_len; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:np; 268, identifier:max; 269, argument_list; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:np; 273, identifier:diff; 274, argument_list; 274, 275; 275, identifier:incorrect_beats; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:track_start; 279, subscript; 279, 280; 279, 293; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:np; 283, identifier:flatnonzero; 284, argument_list; 284, 285; 285, comparison_operator:==; 285, 286; 285, 292; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:np; 289, identifier:diff; 290, argument_list; 290, 291; 291, identifier:incorrect_beats; 292, identifier:track_len; 293, integer:0; 294, if_statement; 294, 295; 294, 309; 295, comparison_operator:>; 295, 296; 295, 299; 296, binary_operator:-; 296, 297; 296, 298; 297, identifier:track_len; 298, integer:1; 299, binary_operator:*; 299, 300; 299, 301; 300, float:.25; 301, parenthesized_expression; 301, 302; 302, binary_operator:-; 302, 303; 302, 308; 303, subscript; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:reference_beats; 306, identifier:shape; 307, integer:0; 308, integer:2; 309, block; 309, 310; 309, 314; 309, 320; 309, 328; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:goto_criteria; 313, integer:1; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:start_beat; 317, subscript; 317, 318; 317, 319; 318, identifier:incorrect_beats; 319, identifier:track_start; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:end_beat; 323, subscript; 323, 324; 323, 325; 324, identifier:incorrect_beats; 325, binary_operator:+; 325, 326; 325, 327; 326, identifier:track_start; 327, integer:1; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:track; 331, subscript; 331, 332; 331, 333; 332, identifier:beat_error; 333, slice; 333, 334; 333, 335; 333, 336; 334, identifier:start_beat; 335, colon; 336, binary_operator:+; 336, 337; 336, 338; 337, identifier:end_beat; 338, integer:1; 339, if_statement; 339, 340; 339, 341; 340, identifier:goto_criteria; 341, block; 341, 342; 342, if_statement; 342, 343; 342, 369; 343, boolean_operator:and; 343, 344; 343, 357; 343, 358; 344, comparison_operator:<; 344, 345; 344, 356; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:np; 348, identifier:mean; 349, argument_list; 349, 350; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:np; 353, identifier:abs; 354, argument_list; 354, 355; 355, identifier:track; 356, identifier:goto_mu; 357, line_continuation:\; 358, comparison_operator:<; 358, 359; 358, 368; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:np; 362, identifier:std; 363, argument_list; 363, 364; 363, 365; 364, identifier:track; 365, keyword_argument; 365, 366; 365, 367; 366, identifier:ddof; 367, integer:1; 368, identifier:goto_sigma; 369, block; 369, 370; 370, expression_statement; 370, 371; 371, assignment; 371, 372; 371, 373; 372, identifier:goto_criteria; 373, integer:3; 374, return_statement; 374, 375; 375, binary_operator:*; 375, 376; 375, 377; 376, float:1.0; 377, parenthesized_expression; 377, 378; 378, comparison_operator:==; 378, 379; 378, 380; 379, identifier:goto_criteria; 380, integer:3 | def goto(reference_beats,
estimated_beats,
goto_threshold=0.35,
goto_mu=0.2,
goto_sigma=0.2):
validate(reference_beats, estimated_beats)
if estimated_beats.size == 0 or reference_beats.size == 0:
return 0.
beat_error = np.ones(reference_beats.shape[0])
paired = np.zeros(reference_beats.shape[0])
goto_criteria = 0
for n in range(1, reference_beats.shape[0]-1):
previous_interval = 0.5*(reference_beats[n] - reference_beats[n-1])
window_min = reference_beats[n] - previous_interval
next_interval = 0.5*(reference_beats[n+1] - reference_beats[n])
window_max = reference_beats[n] + next_interval
beats_in_window = np.logical_and((estimated_beats >= window_min),
(estimated_beats < window_max))
if beats_in_window.sum() == 0 or beats_in_window.sum() > 1:
paired[n] = 0
beat_error[n] = 1
else:
paired[n] = 1
offset = estimated_beats[beats_in_window] - reference_beats[n]
if offset < 0:
beat_error[n] = offset/previous_interval
else:
beat_error[n] = offset/next_interval
incorrect_beats = np.flatnonzero(np.abs(beat_error) > goto_threshold)
if incorrect_beats.shape[0] < 3:
track = beat_error[incorrect_beats[0] + 1:incorrect_beats[-1] - 1]
goto_criteria = 1
else:
track_len = np.max(np.diff(incorrect_beats))
track_start = np.flatnonzero(np.diff(incorrect_beats) == track_len)[0]
if track_len - 1 > .25*(reference_beats.shape[0] - 2):
goto_criteria = 1
start_beat = incorrect_beats[track_start]
end_beat = incorrect_beats[track_start + 1]
track = beat_error[start_beat:end_beat + 1]
if goto_criteria:
if np.mean(np.abs(track)) < goto_mu \
and np.std(track, ddof=1) < goto_sigma:
goto_criteria = 3
return 1.0*(goto_criteria == 3) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_labeled_intervals; 3, parameters; 3, 4; 3, 5; 4, identifier:intervals; 5, default_parameter; 5, 6; 5, 7; 6, identifier:labels; 7, None; 8, block; 8, 9; 8, 11; 8, 24; 8, 30; 9, expression_statement; 9, 10; 10, string:'''Sort intervals, and optionally, their corresponding labels
according to start time.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
The input intervals
labels : list, optional
Labels for each interval
Returns
-------
intervals_sorted or (intervals_sorted, labels_sorted)
Labels are only returned if provided as input
'''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:idx; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:np; 17, identifier:argsort; 18, argument_list; 18, 19; 19, subscript; 19, 20; 19, 21; 19, 23; 20, identifier:intervals; 21, slice; 21, 22; 22, colon; 23, integer:0; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:intervals_sorted; 27, subscript; 27, 28; 27, 29; 28, identifier:intervals; 29, identifier:idx; 30, if_statement; 30, 31; 30, 34; 30, 37; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:labels; 33, None; 34, block; 34, 35; 35, return_statement; 35, 36; 36, identifier:intervals_sorted; 37, else_clause; 37, 38; 38, block; 38, 39; 39, return_statement; 39, 40; 40, expression_list; 40, 41; 40, 42; 41, identifier:intervals_sorted; 42, list_comprehension; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:labels; 45, identifier:_; 46, for_in_clause; 46, 47; 46, 48; 47, identifier:_; 48, identifier:idx | def sort_labeled_intervals(intervals, labels=None):
'''Sort intervals, and optionally, their corresponding labels
according to start time.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
The input intervals
labels : list, optional
Labels for each interval
Returns
-------
intervals_sorted or (intervals_sorted, labels_sorted)
Labels are only returned if provided as input
'''
idx = np.argsort(intervals[:, 0])
intervals_sorted = intervals[idx]
if labels is None:
return intervals_sorted
else:
return intervals_sorted, [labels[_] for _ in idx] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:bss_eval_sources; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:reference_sources; 5, identifier:estimated_sources; 6, default_parameter; 6, 7; 6, 8; 7, identifier:compute_permutation; 8, True; 9, block; 9, 10; 9, 27; 9, 44; 9, 50; 9, 89; 9, 97; 10, if_statement; 10, 11; 10, 16; 11, comparison_operator:==; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:estimated_sources; 14, identifier:ndim; 15, integer:1; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:estimated_sources; 20, subscript; 20, 21; 20, 22; 20, 25; 21, identifier:estimated_sources; 22, attribute; 22, 23; 22, 24; 23, identifier:np; 24, identifier:newaxis; 25, slice; 25, 26; 26, colon; 27, if_statement; 27, 28; 27, 33; 28, comparison_operator:==; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:reference_sources; 31, identifier:ndim; 32, integer:1; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:reference_sources; 37, subscript; 37, 38; 37, 39; 37, 42; 38, identifier:reference_sources; 39, attribute; 39, 40; 39, 41; 40, identifier:np; 41, identifier:newaxis; 42, slice; 42, 43; 43, colon; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:validate; 47, argument_list; 47, 48; 47, 49; 48, identifier:reference_sources; 49, identifier:estimated_sources; 50, if_statement; 50, 51; 50, 62; 51, boolean_operator:or; 51, 52; 51, 57; 52, comparison_operator:==; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:reference_sources; 55, identifier:size; 56, integer:0; 57, comparison_operator:==; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:estimated_sources; 60, identifier:size; 61, integer:0; 62, block; 62, 63; 63, return_statement; 63, 64; 64, expression_list; 64, 65; 64, 71; 64, 77; 64, 83; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:np; 68, identifier:array; 69, argument_list; 69, 70; 70, list:[]; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:np; 74, identifier:array; 75, argument_list; 75, 76; 76, list:[]; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:np; 80, identifier:array; 81, argument_list; 81, 82; 82, list:[]; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:np; 86, identifier:array; 87, argument_list; 87, 88; 88, list:[]; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:nsrc; 92, subscript; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:estimated_sources; 95, identifier:shape; 96, integer:0; 97, if_statement; 97, 98; 97, 99; 97, 283; 98, identifier:compute_permutation; 99, block; 99, 100; 99, 111; 99, 122; 99, 133; 99, 187; 99, 205; 99, 217; 99, 226; 99, 249; 99, 260; 99, 266; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:sdr; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:np; 106, identifier:empty; 107, argument_list; 107, 108; 108, tuple; 108, 109; 108, 110; 109, identifier:nsrc; 110, identifier:nsrc; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:sir; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:np; 117, identifier:empty; 118, argument_list; 118, 119; 119, tuple; 119, 120; 119, 121; 120, identifier:nsrc; 121, identifier:nsrc; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:sar; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:np; 128, identifier:empty; 129, argument_list; 129, 130; 130, tuple; 130, 131; 130, 132; 131, identifier:nsrc; 132, identifier:nsrc; 133, for_statement; 133, 134; 133, 135; 133, 139; 134, identifier:jest; 135, call; 135, 136; 135, 137; 136, identifier:range; 137, argument_list; 137, 138; 138, identifier:nsrc; 139, block; 139, 140; 140, for_statement; 140, 141; 140, 142; 140, 146; 141, identifier:jtrue; 142, call; 142, 143; 142, 144; 143, identifier:range; 144, argument_list; 144, 145; 145, identifier:nsrc; 146, block; 146, 147; 146, 164; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 154; 148, 155; 149, pattern_list; 149, 150; 149, 151; 149, 152; 149, 153; 150, identifier:s_true; 151, identifier:e_spat; 152, identifier:e_interf; 153, identifier:e_artif; 154, line_continuation:\; 155, call; 155, 156; 155, 157; 156, identifier:_bss_decomp_mtifilt; 157, argument_list; 157, 158; 157, 159; 157, 162; 157, 163; 158, identifier:reference_sources; 159, subscript; 159, 160; 159, 161; 160, identifier:estimated_sources; 161, identifier:jest; 162, identifier:jtrue; 163, integer:512; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 179; 165, 180; 166, pattern_list; 166, 167; 166, 171; 166, 175; 167, subscript; 167, 168; 167, 169; 167, 170; 168, identifier:sdr; 169, identifier:jest; 170, identifier:jtrue; 171, subscript; 171, 172; 171, 173; 171, 174; 172, identifier:sir; 173, identifier:jest; 174, identifier:jtrue; 175, subscript; 175, 176; 175, 177; 175, 178; 176, identifier:sar; 177, identifier:jest; 178, identifier:jtrue; 179, line_continuation:\; 180, call; 180, 181; 180, 182; 181, identifier:_bss_source_crit; 182, argument_list; 182, 183; 182, 184; 182, 185; 182, 186; 183, identifier:s_true; 184, identifier:e_spat; 185, identifier:e_interf; 186, identifier:e_artif; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:perms; 190, call; 190, 191; 190, 192; 191, identifier:list; 192, argument_list; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:itertools; 196, identifier:permutations; 197, argument_list; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:list; 200, argument_list; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:range; 203, argument_list; 203, 204; 204, identifier:nsrc; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:mean_sir; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:np; 211, identifier:empty; 212, argument_list; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:len; 215, argument_list; 215, 216; 216, identifier:perms; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:dum; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:np; 223, identifier:arange; 224, argument_list; 224, 225; 225, identifier:nsrc; 226, for_statement; 226, 227; 226, 230; 226, 234; 227, tuple_pattern; 227, 228; 227, 229; 228, identifier:i; 229, identifier:perm; 230, call; 230, 231; 230, 232; 231, identifier:enumerate; 232, argument_list; 232, 233; 233, identifier:perms; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 240; 237, subscript; 237, 238; 237, 239; 238, identifier:mean_sir; 239, identifier:i; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:np; 243, identifier:mean; 244, argument_list; 244, 245; 245, subscript; 245, 246; 245, 247; 245, 248; 246, identifier:sir; 247, identifier:perm; 248, identifier:dum; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:popt; 252, subscript; 252, 253; 252, 254; 253, identifier:perms; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:np; 257, identifier:argmax; 258, argument_list; 258, 259; 259, identifier:mean_sir; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:idx; 263, tuple; 263, 264; 263, 265; 264, identifier:popt; 265, identifier:dum; 266, return_statement; 266, 267; 267, tuple; 267, 268; 267, 271; 267, 274; 267, 277; 268, subscript; 268, 269; 268, 270; 269, identifier:sdr; 270, identifier:idx; 271, subscript; 271, 272; 271, 273; 272, identifier:sir; 273, identifier:idx; 274, subscript; 274, 275; 274, 276; 275, identifier:sar; 276, identifier:idx; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:np; 280, identifier:asarray; 281, argument_list; 281, 282; 282, identifier:popt; 283, else_clause; 283, 284; 284, block; 284, 285; 284, 294; 284, 303; 284, 312; 284, 356; 284, 365; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:sdr; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:np; 291, identifier:empty; 292, argument_list; 292, 293; 293, identifier:nsrc; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:sir; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:np; 300, identifier:empty; 301, argument_list; 301, 302; 302, identifier:nsrc; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 306; 305, identifier:sar; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:np; 309, identifier:empty; 310, argument_list; 310, 311; 311, identifier:nsrc; 312, for_statement; 312, 313; 312, 314; 312, 318; 313, identifier:j; 314, call; 314, 315; 314, 316; 315, identifier:range; 316, argument_list; 316, 317; 317, identifier:nsrc; 318, block; 318, 319; 318, 336; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 326; 320, 327; 321, pattern_list; 321, 322; 321, 323; 321, 324; 321, 325; 322, identifier:s_true; 323, identifier:e_spat; 324, identifier:e_interf; 325, identifier:e_artif; 326, line_continuation:\; 327, call; 327, 328; 327, 329; 328, identifier:_bss_decomp_mtifilt; 329, argument_list; 329, 330; 329, 331; 329, 334; 329, 335; 330, identifier:reference_sources; 331, subscript; 331, 332; 331, 333; 332, identifier:estimated_sources; 333, identifier:j; 334, identifier:j; 335, integer:512; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 348; 337, 349; 338, pattern_list; 338, 339; 338, 342; 338, 345; 339, subscript; 339, 340; 339, 341; 340, identifier:sdr; 341, identifier:j; 342, subscript; 342, 343; 342, 344; 343, identifier:sir; 344, identifier:j; 345, subscript; 345, 346; 345, 347; 346, identifier:sar; 347, identifier:j; 348, line_continuation:\; 349, call; 349, 350; 349, 351; 350, identifier:_bss_source_crit; 351, argument_list; 351, 352; 351, 353; 351, 354; 351, 355; 352, identifier:s_true; 353, identifier:e_spat; 354, identifier:e_interf; 355, identifier:e_artif; 356, expression_statement; 356, 357; 357, assignment; 357, 358; 357, 359; 358, identifier:popt; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:np; 362, identifier:arange; 363, argument_list; 363, 364; 364, identifier:nsrc; 365, return_statement; 365, 366; 366, tuple; 366, 367; 366, 368; 366, 369; 366, 370; 367, identifier:sdr; 368, identifier:sir; 369, identifier:sar; 370, identifier:popt | def bss_eval_sources(reference_sources, estimated_sources,
compute_permutation=True):
if estimated_sources.ndim == 1:
estimated_sources = estimated_sources[np.newaxis, :]
if reference_sources.ndim == 1:
reference_sources = reference_sources[np.newaxis, :]
validate(reference_sources, estimated_sources)
if reference_sources.size == 0 or estimated_sources.size == 0:
return np.array([]), np.array([]), np.array([]), np.array([])
nsrc = estimated_sources.shape[0]
if compute_permutation:
sdr = np.empty((nsrc, nsrc))
sir = np.empty((nsrc, nsrc))
sar = np.empty((nsrc, nsrc))
for jest in range(nsrc):
for jtrue in range(nsrc):
s_true, e_spat, e_interf, e_artif = \
_bss_decomp_mtifilt(reference_sources,
estimated_sources[jest],
jtrue, 512)
sdr[jest, jtrue], sir[jest, jtrue], sar[jest, jtrue] = \
_bss_source_crit(s_true, e_spat, e_interf, e_artif)
perms = list(itertools.permutations(list(range(nsrc))))
mean_sir = np.empty(len(perms))
dum = np.arange(nsrc)
for (i, perm) in enumerate(perms):
mean_sir[i] = np.mean(sir[perm, dum])
popt = perms[np.argmax(mean_sir)]
idx = (popt, dum)
return (sdr[idx], sir[idx], sar[idx], np.asarray(popt))
else:
sdr = np.empty(nsrc)
sir = np.empty(nsrc)
sar = np.empty(nsrc)
for j in range(nsrc):
s_true, e_spat, e_interf, e_artif = \
_bss_decomp_mtifilt(reference_sources,
estimated_sources[j],
j, 512)
sdr[j], sir[j], sar[j] = \
_bss_source_crit(s_true, e_spat, e_interf, e_artif)
popt = np.arange(nsrc)
return (sdr, sir, sar, popt) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:bss_eval_sources_framewise; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 11; 3, 16; 4, identifier:reference_sources; 5, identifier:estimated_sources; 6, default_parameter; 6, 7; 6, 8; 7, identifier:window; 8, binary_operator:*; 8, 9; 8, 10; 9, integer:30; 10, integer:44100; 11, default_parameter; 11, 12; 11, 13; 12, identifier:hop; 13, binary_operator:*; 13, 14; 13, 15; 14, integer:15; 15, integer:44100; 16, default_parameter; 16, 17; 16, 18; 17, identifier:compute_permutation; 18, False; 19, block; 19, 20; 19, 37; 19, 54; 19, 60; 19, 99; 19, 107; 19, 130; 19, 157; 19, 168; 19, 179; 19, 190; 19, 201; 19, 311; 20, if_statement; 20, 21; 20, 26; 21, comparison_operator:==; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:estimated_sources; 24, identifier:ndim; 25, integer:1; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:estimated_sources; 30, subscript; 30, 31; 30, 32; 30, 35; 31, identifier:estimated_sources; 32, attribute; 32, 33; 32, 34; 33, identifier:np; 34, identifier:newaxis; 35, slice; 35, 36; 36, colon; 37, if_statement; 37, 38; 37, 43; 38, comparison_operator:==; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:reference_sources; 41, identifier:ndim; 42, integer:1; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:reference_sources; 47, subscript; 47, 48; 47, 49; 47, 52; 48, identifier:reference_sources; 49, attribute; 49, 50; 49, 51; 50, identifier:np; 51, identifier:newaxis; 52, slice; 52, 53; 53, colon; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:validate; 57, argument_list; 57, 58; 57, 59; 58, identifier:reference_sources; 59, identifier:estimated_sources; 60, if_statement; 60, 61; 60, 72; 61, boolean_operator:or; 61, 62; 61, 67; 62, comparison_operator:==; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:reference_sources; 65, identifier:size; 66, integer:0; 67, comparison_operator:==; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:estimated_sources; 70, identifier:size; 71, integer:0; 72, block; 72, 73; 73, return_statement; 73, 74; 74, expression_list; 74, 75; 74, 81; 74, 87; 74, 93; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:np; 78, identifier:array; 79, argument_list; 79, 80; 80, list:[]; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:np; 84, identifier:array; 85, argument_list; 85, 86; 86, list:[]; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:np; 90, identifier:array; 91, argument_list; 91, 92; 92, list:[]; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:np; 96, identifier:array; 97, argument_list; 97, 98; 98, list:[]; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:nsrc; 102, subscript; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:reference_sources; 105, identifier:shape; 106, integer:0; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:nwin; 110, call; 110, 111; 110, 112; 111, identifier:int; 112, argument_list; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:np; 116, identifier:floor; 117, argument_list; 117, 118; 118, binary_operator:/; 118, 119; 118, 129; 119, parenthesized_expression; 119, 120; 120, binary_operator:+; 120, 121; 120, 128; 121, binary_operator:-; 121, 122; 121, 127; 122, subscript; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:reference_sources; 125, identifier:shape; 126, integer:1; 127, identifier:window; 128, identifier:hop; 129, identifier:hop; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:<; 131, 132; 131, 133; 132, identifier:nwin; 133, integer:2; 134, block; 134, 135; 134, 144; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:result; 138, call; 138, 139; 138, 140; 139, identifier:bss_eval_sources; 140, argument_list; 140, 141; 140, 142; 140, 143; 141, identifier:reference_sources; 142, identifier:estimated_sources; 143, identifier:compute_permutation; 144, return_statement; 144, 145; 145, list_comprehension; 145, 146; 145, 154; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:np; 149, identifier:expand_dims; 150, argument_list; 150, 151; 150, 152; 151, identifier:score; 152, unary_operator:-; 152, 153; 153, integer:1; 154, for_in_clause; 154, 155; 154, 156; 155, identifier:score; 156, identifier:result; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:sdr; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:np; 163, identifier:empty; 164, argument_list; 164, 165; 165, tuple; 165, 166; 165, 167; 166, identifier:nsrc; 167, identifier:nwin; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:sir; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:np; 174, identifier:empty; 175, argument_list; 175, 176; 176, tuple; 176, 177; 176, 178; 177, identifier:nsrc; 178, identifier:nwin; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:sar; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:np; 185, identifier:empty; 186, argument_list; 186, 187; 187, tuple; 187, 188; 187, 189; 188, identifier:nsrc; 189, identifier:nwin; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:perm; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:np; 196, identifier:empty; 197, argument_list; 197, 198; 198, tuple; 198, 199; 198, 200; 199, identifier:nsrc; 200, identifier:nwin; 201, for_statement; 201, 202; 201, 203; 201, 207; 202, identifier:k; 203, call; 203, 204; 203, 205; 204, identifier:range; 205, argument_list; 205, 206; 206, identifier:nwin; 207, block; 207, 208; 207, 222; 207, 230; 207, 238; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:win_slice; 211, call; 211, 212; 211, 213; 212, identifier:slice; 213, argument_list; 213, 214; 213, 217; 214, binary_operator:*; 214, 215; 214, 216; 215, identifier:k; 216, identifier:hop; 217, binary_operator:+; 217, 218; 217, 221; 218, binary_operator:*; 218, 219; 218, 220; 219, identifier:k; 220, identifier:hop; 221, identifier:window; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:ref_slice; 225, subscript; 225, 226; 225, 227; 225, 229; 226, identifier:reference_sources; 227, slice; 227, 228; 228, colon; 229, identifier:win_slice; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:est_slice; 233, subscript; 233, 234; 233, 235; 233, 237; 234, identifier:estimated_sources; 235, slice; 235, 236; 236, colon; 237, identifier:win_slice; 238, if_statement; 238, 239; 238, 251; 238, 281; 239, parenthesized_expression; 239, 240; 240, boolean_operator:and; 240, 241; 240, 246; 241, not_operator; 241, 242; 242, call; 242, 243; 242, 244; 243, identifier:_any_source_silent; 244, argument_list; 244, 245; 245, identifier:ref_slice; 246, not_operator; 246, 247; 247, call; 247, 248; 247, 249; 248, identifier:_any_source_silent; 249, argument_list; 249, 250; 250, identifier:est_slice; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 275; 254, pattern_list; 254, 255; 254, 260; 254, 265; 254, 270; 255, subscript; 255, 256; 255, 257; 255, 259; 256, identifier:sdr; 257, slice; 257, 258; 258, colon; 259, identifier:k; 260, subscript; 260, 261; 260, 262; 260, 264; 261, identifier:sir; 262, slice; 262, 263; 263, colon; 264, identifier:k; 265, subscript; 265, 266; 265, 267; 265, 269; 266, identifier:sar; 267, slice; 267, 268; 268, colon; 269, identifier:k; 270, subscript; 270, 271; 270, 272; 270, 274; 271, identifier:perm; 272, slice; 272, 273; 273, colon; 274, identifier:k; 275, call; 275, 276; 275, 277; 276, identifier:bss_eval_sources; 277, argument_list; 277, 278; 277, 279; 277, 280; 278, identifier:ref_slice; 279, identifier:est_slice; 280, identifier:compute_permutation; 281, else_clause; 281, 282; 282, block; 282, 283; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 290; 285, subscript; 285, 286; 285, 287; 285, 289; 286, identifier:sdr; 287, slice; 287, 288; 288, colon; 289, identifier:k; 290, assignment; 290, 291; 290, 296; 291, subscript; 291, 292; 291, 293; 291, 295; 292, identifier:sir; 293, slice; 293, 294; 294, colon; 295, identifier:k; 296, assignment; 296, 297; 296, 302; 297, subscript; 297, 298; 297, 299; 297, 301; 298, identifier:sar; 299, slice; 299, 300; 300, colon; 301, identifier:k; 302, assignment; 302, 303; 302, 308; 303, subscript; 303, 304; 303, 305; 303, 307; 304, identifier:perm; 305, slice; 305, 306; 306, colon; 307, identifier:k; 308, attribute; 308, 309; 308, 310; 309, identifier:np; 310, identifier:nan; 311, return_statement; 311, 312; 312, expression_list; 312, 313; 312, 314; 312, 315; 312, 316; 313, identifier:sdr; 314, identifier:sir; 315, identifier:sar; 316, identifier:perm | def bss_eval_sources_framewise(reference_sources, estimated_sources,
window=30*44100, hop=15*44100,
compute_permutation=False):
if estimated_sources.ndim == 1:
estimated_sources = estimated_sources[np.newaxis, :]
if reference_sources.ndim == 1:
reference_sources = reference_sources[np.newaxis, :]
validate(reference_sources, estimated_sources)
if reference_sources.size == 0 or estimated_sources.size == 0:
return np.array([]), np.array([]), np.array([]), np.array([])
nsrc = reference_sources.shape[0]
nwin = int(
np.floor((reference_sources.shape[1] - window + hop) / hop)
)
if nwin < 2:
result = bss_eval_sources(reference_sources,
estimated_sources,
compute_permutation)
return [np.expand_dims(score, -1) for score in result]
sdr = np.empty((nsrc, nwin))
sir = np.empty((nsrc, nwin))
sar = np.empty((nsrc, nwin))
perm = np.empty((nsrc, nwin))
for k in range(nwin):
win_slice = slice(k * hop, k * hop + window)
ref_slice = reference_sources[:, win_slice]
est_slice = estimated_sources[:, win_slice]
if (not _any_source_silent(ref_slice) and
not _any_source_silent(est_slice)):
sdr[:, k], sir[:, k], sar[:, k], perm[:, k] = bss_eval_sources(
ref_slice, est_slice, compute_permutation
)
else:
sdr[:, k] = sir[:, k] = sar[:, k] = perm[:, k] = np.nan
return sdr, sir, sar, perm |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:bss_eval_images_framewise; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 11; 3, 16; 4, identifier:reference_sources; 5, identifier:estimated_sources; 6, default_parameter; 6, 7; 6, 8; 7, identifier:window; 8, binary_operator:*; 8, 9; 8, 10; 9, integer:30; 10, integer:44100; 11, default_parameter; 11, 12; 11, 13; 12, identifier:hop; 13, binary_operator:*; 13, 14; 13, 15; 14, integer:15; 15, integer:44100; 16, default_parameter; 16, 17; 16, 18; 17, identifier:compute_permutation; 18, False; 19, block; 19, 20; 19, 29; 19, 38; 19, 44; 19, 83; 19, 91; 19, 114; 19, 141; 19, 152; 19, 163; 19, 174; 19, 185; 19, 196; 19, 316; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:estimated_sources; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:np; 26, identifier:atleast_3d; 27, argument_list; 27, 28; 28, identifier:estimated_sources; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:reference_sources; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:np; 35, identifier:atleast_3d; 36, argument_list; 36, 37; 37, identifier:reference_sources; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:validate; 41, argument_list; 41, 42; 41, 43; 42, identifier:reference_sources; 43, identifier:estimated_sources; 44, if_statement; 44, 45; 44, 56; 45, boolean_operator:or; 45, 46; 45, 51; 46, comparison_operator:==; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:reference_sources; 49, identifier:size; 50, integer:0; 51, comparison_operator:==; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:estimated_sources; 54, identifier:size; 55, integer:0; 56, block; 56, 57; 57, return_statement; 57, 58; 58, expression_list; 58, 59; 58, 65; 58, 71; 58, 77; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:np; 62, identifier:array; 63, argument_list; 63, 64; 64, list:[]; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:np; 68, identifier:array; 69, argument_list; 69, 70; 70, list:[]; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:np; 74, identifier:array; 75, argument_list; 75, 76; 76, list:[]; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:np; 80, identifier:array; 81, argument_list; 81, 82; 82, list:[]; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:nsrc; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:reference_sources; 89, identifier:shape; 90, integer:0; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:nwin; 94, call; 94, 95; 94, 96; 95, identifier:int; 96, argument_list; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:np; 100, identifier:floor; 101, argument_list; 101, 102; 102, binary_operator:/; 102, 103; 102, 113; 103, parenthesized_expression; 103, 104; 104, binary_operator:+; 104, 105; 104, 112; 105, binary_operator:-; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:reference_sources; 109, identifier:shape; 110, integer:1; 111, identifier:window; 112, identifier:hop; 113, identifier:hop; 114, if_statement; 114, 115; 114, 118; 115, comparison_operator:<; 115, 116; 115, 117; 116, identifier:nwin; 117, integer:2; 118, block; 118, 119; 118, 128; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:result; 122, call; 122, 123; 122, 124; 123, identifier:bss_eval_images; 124, argument_list; 124, 125; 124, 126; 124, 127; 125, identifier:reference_sources; 126, identifier:estimated_sources; 127, identifier:compute_permutation; 128, return_statement; 128, 129; 129, list_comprehension; 129, 130; 129, 138; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:np; 133, identifier:expand_dims; 134, argument_list; 134, 135; 134, 136; 135, identifier:score; 136, unary_operator:-; 136, 137; 137, integer:1; 138, for_in_clause; 138, 139; 138, 140; 139, identifier:score; 140, identifier:result; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:sdr; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:np; 147, identifier:empty; 148, argument_list; 148, 149; 149, tuple; 149, 150; 149, 151; 150, identifier:nsrc; 151, identifier:nwin; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:isr; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:np; 158, identifier:empty; 159, argument_list; 159, 160; 160, tuple; 160, 161; 160, 162; 161, identifier:nsrc; 162, identifier:nwin; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:sir; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:np; 169, identifier:empty; 170, argument_list; 170, 171; 171, tuple; 171, 172; 171, 173; 172, identifier:nsrc; 173, identifier:nwin; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:sar; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:np; 180, identifier:empty; 181, argument_list; 181, 182; 182, tuple; 182, 183; 182, 184; 183, identifier:nsrc; 184, identifier:nwin; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:perm; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:np; 191, identifier:empty; 192, argument_list; 192, 193; 193, tuple; 193, 194; 193, 195; 194, identifier:nsrc; 195, identifier:nwin; 196, for_statement; 196, 197; 196, 198; 196, 202; 197, identifier:k; 198, call; 198, 199; 198, 200; 199, identifier:range; 200, argument_list; 200, 201; 201, identifier:nwin; 202, block; 202, 203; 202, 217; 202, 227; 202, 237; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:win_slice; 206, call; 206, 207; 206, 208; 207, identifier:slice; 208, argument_list; 208, 209; 208, 212; 209, binary_operator:*; 209, 210; 209, 211; 210, identifier:k; 211, identifier:hop; 212, binary_operator:+; 212, 213; 212, 216; 213, binary_operator:*; 213, 214; 213, 215; 214, identifier:k; 215, identifier:hop; 216, identifier:window; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:ref_slice; 220, subscript; 220, 221; 220, 222; 220, 224; 220, 225; 221, identifier:reference_sources; 222, slice; 222, 223; 223, colon; 224, identifier:win_slice; 225, slice; 225, 226; 226, colon; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:est_slice; 230, subscript; 230, 231; 230, 232; 230, 234; 230, 235; 231, identifier:estimated_sources; 232, slice; 232, 233; 233, colon; 234, identifier:win_slice; 235, slice; 235, 236; 236, colon; 237, if_statement; 237, 238; 237, 250; 237, 286; 238, parenthesized_expression; 238, 239; 239, boolean_operator:and; 239, 240; 239, 245; 240, not_operator; 240, 241; 241, call; 241, 242; 241, 243; 242, identifier:_any_source_silent; 243, argument_list; 243, 244; 244, identifier:ref_slice; 245, not_operator; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:_any_source_silent; 248, argument_list; 248, 249; 249, identifier:est_slice; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 279; 252, 280; 253, pattern_list; 253, 254; 253, 259; 253, 264; 253, 269; 253, 274; 254, subscript; 254, 255; 254, 256; 254, 258; 255, identifier:sdr; 256, slice; 256, 257; 257, colon; 258, identifier:k; 259, subscript; 259, 260; 259, 261; 259, 263; 260, identifier:isr; 261, slice; 261, 262; 262, colon; 263, identifier:k; 264, subscript; 264, 265; 264, 266; 264, 268; 265, identifier:sir; 266, slice; 266, 267; 267, colon; 268, identifier:k; 269, subscript; 269, 270; 269, 271; 269, 273; 270, identifier:sar; 271, slice; 271, 272; 272, colon; 273, identifier:k; 274, subscript; 274, 275; 274, 276; 274, 278; 275, identifier:perm; 276, slice; 276, 277; 277, colon; 278, identifier:k; 279, line_continuation:\; 280, call; 280, 281; 280, 282; 281, identifier:bss_eval_images; 282, argument_list; 282, 283; 282, 284; 282, 285; 283, identifier:ref_slice; 284, identifier:est_slice; 285, identifier:compute_permutation; 286, else_clause; 286, 287; 287, block; 287, 288; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 295; 290, subscript; 290, 291; 290, 292; 290, 294; 291, identifier:sdr; 292, slice; 292, 293; 293, colon; 294, identifier:k; 295, assignment; 295, 296; 295, 301; 296, subscript; 296, 297; 296, 298; 296, 300; 297, identifier:sir; 298, slice; 298, 299; 299, colon; 300, identifier:k; 301, assignment; 301, 302; 301, 307; 302, subscript; 302, 303; 302, 304; 302, 306; 303, identifier:sar; 304, slice; 304, 305; 305, colon; 306, identifier:k; 307, assignment; 307, 308; 307, 313; 308, subscript; 308, 309; 308, 310; 308, 312; 309, identifier:perm; 310, slice; 310, 311; 311, colon; 312, identifier:k; 313, attribute; 313, 314; 313, 315; 314, identifier:np; 315, identifier:nan; 316, return_statement; 316, 317; 317, expression_list; 317, 318; 317, 319; 317, 320; 317, 321; 317, 322; 318, identifier:sdr; 319, identifier:isr; 320, identifier:sir; 321, identifier:sar; 322, identifier:perm | def bss_eval_images_framewise(reference_sources, estimated_sources,
window=30*44100, hop=15*44100,
compute_permutation=False):
estimated_sources = np.atleast_3d(estimated_sources)
reference_sources = np.atleast_3d(reference_sources)
validate(reference_sources, estimated_sources)
if reference_sources.size == 0 or estimated_sources.size == 0:
return np.array([]), np.array([]), np.array([]), np.array([])
nsrc = reference_sources.shape[0]
nwin = int(
np.floor((reference_sources.shape[1] - window + hop) / hop)
)
if nwin < 2:
result = bss_eval_images(reference_sources,
estimated_sources,
compute_permutation)
return [np.expand_dims(score, -1) for score in result]
sdr = np.empty((nsrc, nwin))
isr = np.empty((nsrc, nwin))
sir = np.empty((nsrc, nwin))
sar = np.empty((nsrc, nwin))
perm = np.empty((nsrc, nwin))
for k in range(nwin):
win_slice = slice(k * hop, k * hop + window)
ref_slice = reference_sources[:, win_slice, :]
est_slice = estimated_sources[:, win_slice, :]
if (not _any_source_silent(ref_slice) and
not _any_source_silent(est_slice)):
sdr[:, k], isr[:, k], sir[:, k], sar[:, k], perm[:, k] = \
bss_eval_images(
ref_slice, est_slice, compute_permutation
)
else:
sdr[:, k] = sir[:, k] = sar[:, k] = perm[:, k] = np.nan
return sdr, isr, sir, sar, perm |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:time_frequency; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 13; 3, 16; 4, identifier:gram; 5, identifier:frequencies; 6, identifier:times; 7, identifier:fs; 8, default_parameter; 8, 9; 8, 10; 9, identifier:function; 10, attribute; 10, 11; 10, 12; 11, identifier:np; 12, identifier:sin; 13, default_parameter; 13, 14; 13, 15; 14, identifier:length; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:n_dec; 18, integer:1; 19, block; 19, 20; 19, 36; 19, 54; 19, 68; 19, 76; 19, 84; 19, 179; 19, 193; 19, 203; 19, 212; 19, 229; 19, 347; 19, 360; 19, 378; 20, if_statement; 20, 21; 20, 26; 21, comparison_operator:==; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:times; 24, identifier:ndim; 25, integer:1; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:times; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:util; 33, identifier:boundaries_to_intervals; 34, argument_list; 34, 35; 35, identifier:times; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:length; 39, None; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:length; 44, call; 44, 45; 44, 46; 45, identifier:int; 46, argument_list; 46, 47; 47, binary_operator:*; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 50; 48, 52; 49, identifier:times; 50, unary_operator:-; 50, 51; 51, integer:1; 52, integer:1; 53, identifier:fs; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, pattern_list; 56, 57; 56, 58; 57, identifier:times; 58, identifier:_; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:util; 62, identifier:adjust_intervals; 63, argument_list; 63, 64; 63, 65; 64, identifier:times; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:t_max; 67, identifier:length; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:n_times; 71, subscript; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:gram; 74, identifier:shape; 75, integer:1; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:times; 79, subscript; 79, 80; 79, 81; 80, identifier:times; 81, slice; 81, 82; 81, 83; 82, colon; 83, identifier:n_times; 84, function_definition; 84, 85; 84, 86; 84, 88; 85, function_name:_fast_synthesize; 86, parameters; 86, 87; 87, identifier:frequency; 88, block; 88, 89; 88, 99; 88, 110; 88, 132; 88, 153; 88, 175; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:frequency; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:np; 95, identifier:round; 96, argument_list; 96, 97; 96, 98; 97, identifier:frequency; 98, identifier:n_dec; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:n_samples; 102, call; 102, 103; 102, 104; 103, identifier:int; 104, argument_list; 104, 105; 105, binary_operator:*; 105, 106; 105, 109; 106, binary_operator:**; 106, 107; 106, 108; 107, float:10.0; 108, identifier:n_dec; 109, identifier:fs; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:short_signal; 113, call; 113, 114; 113, 115; 114, identifier:function; 115, argument_list; 115, 116; 116, binary_operator:/; 116, 117; 116, 131; 117, binary_operator:*; 117, 118; 117, 130; 118, binary_operator:*; 118, 119; 118, 124; 119, binary_operator:*; 119, 120; 119, 121; 120, float:2.0; 121, attribute; 121, 122; 121, 123; 122, identifier:np; 123, identifier:pi; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:np; 127, identifier:arange; 128, argument_list; 128, 129; 129, identifier:n_samples; 130, identifier:frequency; 131, identifier:fs; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:n_repeats; 135, call; 135, 136; 135, 137; 136, identifier:int; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:np; 141, identifier:ceil; 142, argument_list; 142, 143; 143, binary_operator:/; 143, 144; 143, 145; 144, identifier:length; 145, call; 145, 146; 145, 147; 146, identifier:float; 147, argument_list; 147, 148; 148, subscript; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:short_signal; 151, identifier:shape; 152, integer:0; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:long_signal; 156, call; 156, 157; 156, 158; 157, identifier:as_strided; 158, argument_list; 158, 159; 158, 160; 158, 168; 159, identifier:short_signal; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:shape; 162, tuple; 162, 163; 162, 164; 163, identifier:n_repeats; 164, call; 164, 165; 164, 166; 165, identifier:len; 166, argument_list; 166, 167; 167, identifier:short_signal; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:strides; 170, tuple; 170, 171; 170, 172; 171, integer:0; 172, attribute; 172, 173; 172, 174; 173, identifier:short_signal; 174, identifier:itemsize; 175, return_statement; 175, 176; 176, attribute; 176, 177; 176, 178; 177, identifier:long_signal; 178, identifier:flat; 179, function_definition; 179, 180; 179, 181; 179, 183; 180, function_name:_const_interpolator; 181, parameters; 181, 182; 182, identifier:value; 183, block; 183, 184; 183, 191; 184, function_definition; 184, 185; 184, 186; 184, 188; 185, function_name:__interpolator; 186, parameters; 186, 187; 187, identifier:x; 188, block; 188, 189; 189, return_statement; 189, 190; 190, identifier:value; 191, return_statement; 191, 192; 192, identifier:__interpolator; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:gram; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:np; 199, identifier:maximum; 200, argument_list; 200, 201; 200, 202; 201, identifier:gram; 202, integer:0; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:output; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:np; 209, identifier:zeros; 210, argument_list; 210, 211; 211, identifier:length; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:time_centers; 215, binary_operator:*; 215, 216; 215, 225; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:np; 219, identifier:mean; 220, argument_list; 220, 221; 220, 222; 221, identifier:times; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:axis; 224, integer:1; 225, call; 225, 226; 225, 227; 226, identifier:float; 227, argument_list; 227, 228; 228, identifier:fs; 229, for_statement; 229, 230; 229, 233; 229, 237; 230, pattern_list; 230, 231; 230, 232; 231, identifier:n; 232, identifier:frequency; 233, call; 233, 234; 233, 235; 234, identifier:enumerate; 235, argument_list; 235, 236; 236, identifier:frequencies; 237, block; 237, 238; 237, 245; 237, 286; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:wave; 241, call; 241, 242; 241, 243; 242, identifier:_fast_synthesize; 243, argument_list; 243, 244; 244, identifier:frequency; 245, if_statement; 245, 246; 245, 252; 245, 274; 246, comparison_operator:>; 246, 247; 246, 251; 247, call; 247, 248; 247, 249; 248, identifier:len; 249, argument_list; 249, 250; 250, identifier:time_centers; 251, integer:1; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:gram_interpolator; 256, call; 256, 257; 256, 258; 257, identifier:interp1d; 258, argument_list; 258, 259; 258, 260; 258, 265; 258, 268; 258, 271; 259, identifier:time_centers; 260, subscript; 260, 261; 260, 262; 260, 263; 261, identifier:gram; 262, identifier:n; 263, slice; 263, 264; 264, colon; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:kind; 267, string:'linear'; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:bounds_error; 270, False; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:fill_value; 273, float:0.0; 274, else_clause; 274, 275; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:gram_interpolator; 279, call; 279, 280; 279, 281; 280, identifier:_const_interpolator; 281, argument_list; 281, 282; 282, subscript; 282, 283; 282, 284; 282, 285; 283, identifier:gram; 284, identifier:n; 285, integer:0; 286, for_statement; 286, 287; 286, 292; 286, 304; 287, pattern_list; 287, 288; 287, 289; 288, identifier:m; 289, tuple_pattern; 289, 290; 289, 291; 290, identifier:start; 291, identifier:end; 292, call; 292, 293; 292, 294; 293, identifier:enumerate; 294, argument_list; 294, 295; 295, call; 295, 296; 295, 302; 296, attribute; 296, 297; 296, 301; 297, parenthesized_expression; 297, 298; 298, binary_operator:*; 298, 299; 298, 300; 299, identifier:times; 300, identifier:fs; 301, identifier:astype; 302, argument_list; 302, 303; 303, identifier:int; 304, block; 304, 305; 304, 321; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 310; 307, pattern_list; 307, 308; 307, 309; 308, identifier:start; 309, identifier:end; 310, expression_list; 310, 311; 310, 316; 311, call; 311, 312; 311, 313; 312, identifier:max; 313, argument_list; 313, 314; 313, 315; 314, identifier:start; 315, integer:0; 316, call; 316, 317; 316, 318; 317, identifier:min; 318, argument_list; 318, 319; 318, 320; 319, identifier:end; 320, identifier:length; 321, expression_statement; 321, 322; 322, augmented_assignment:+=; 322, 323; 322, 329; 323, subscript; 323, 324; 323, 325; 324, identifier:output; 325, slice; 325, 326; 325, 327; 325, 328; 326, identifier:start; 327, colon; 328, identifier:end; 329, parenthesized_expression; 329, 330; 330, binary_operator:*; 330, 331; 330, 337; 331, subscript; 331, 332; 331, 333; 332, identifier:wave; 333, slice; 333, 334; 333, 335; 333, 336; 334, identifier:start; 335, colon; 336, identifier:end; 337, call; 337, 338; 337, 339; 338, identifier:gram_interpolator; 339, argument_list; 339, 340; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:np; 343, identifier:arange; 344, argument_list; 344, 345; 344, 346; 345, identifier:start; 346, identifier:end; 347, expression_statement; 347, 348; 348, assignment; 348, 349; 348, 350; 349, identifier:norm; 350, call; 350, 351; 350, 359; 351, attribute; 351, 352; 351, 358; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:np; 355, identifier:abs; 356, argument_list; 356, 357; 357, identifier:output; 358, identifier:max; 359, argument_list; 360, if_statement; 360, 361; 360, 373; 361, comparison_operator:>=; 361, 362; 361, 363; 362, identifier:norm; 363, attribute; 363, 364; 363, 372; 364, call; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:np; 367, identifier:finfo; 368, argument_list; 368, 369; 369, attribute; 369, 370; 369, 371; 370, identifier:output; 371, identifier:dtype; 372, identifier:tiny; 373, block; 373, 374; 374, expression_statement; 374, 375; 375, augmented_assignment:/=; 375, 376; 375, 377; 376, identifier:output; 377, identifier:norm; 378, return_statement; 378, 379; 379, identifier:output | def time_frequency(gram, frequencies, times, fs, function=np.sin, length=None,
n_dec=1):
if times.ndim == 1:
times = util.boundaries_to_intervals(times)
if length is None:
length = int(times[-1, 1] * fs)
times, _ = util.adjust_intervals(times, t_max=length)
n_times = gram.shape[1]
times = times[:n_times]
def _fast_synthesize(frequency):
frequency = np.round(frequency, n_dec)
n_samples = int(10.0**n_dec * fs)
short_signal = function(2.0 * np.pi * np.arange(n_samples) *
frequency / fs)
n_repeats = int(np.ceil(length/float(short_signal.shape[0])))
long_signal = as_strided(short_signal,
shape=(n_repeats, len(short_signal)),
strides=(0, short_signal.itemsize))
return long_signal.flat
def _const_interpolator(value):
def __interpolator(x):
return value
return __interpolator
gram = np.maximum(gram, 0)
output = np.zeros(length)
time_centers = np.mean(times, axis=1) * float(fs)
for n, frequency in enumerate(frequencies):
wave = _fast_synthesize(frequency)
if len(time_centers) > 1:
gram_interpolator = interp1d(
time_centers, gram[n, :],
kind='linear', bounds_error=False,
fill_value=0.0)
else:
gram_interpolator = _const_interpolator(gram[n, 0])
for m, (start, end) in enumerate((times * fs).astype(int)):
start, end = max(start, 0), min(end, length)
output[start:end] += (
wave[start:end] * gram_interpolator(np.arange(start, end)))
norm = np.abs(output).max()
if norm >= np.finfo(output.dtype).tiny:
output /= norm
return output |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:match_note_offsets; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:ref_intervals; 5, identifier:est_intervals; 6, default_parameter; 6, 7; 6, 8; 7, identifier:offset_ratio; 8, float:0.2; 9, default_parameter; 9, 10; 9, 11; 10, identifier:offset_min_tolerance; 11, float:0.05; 12, default_parameter; 12, 13; 12, 14; 13, identifier:strict; 14, False; 15, block; 15, 16; 15, 33; 15, 58; 15, 70; 15, 79; 15, 91; 15, 107; 15, 116; 15, 120; 15, 150; 15, 166; 16, if_statement; 16, 17; 16, 18; 16, 25; 17, identifier:strict; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:cmp_func; 22, attribute; 22, 23; 22, 24; 23, identifier:np; 24, identifier:less; 25, else_clause; 25, 26; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:cmp_func; 30, attribute; 30, 31; 30, 32; 31, identifier:np; 32, identifier:less_equal; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:offset_distances; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:np; 39, identifier:abs; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:np; 45, identifier:subtract; 46, identifier:outer; 47, argument_list; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 50; 48, 52; 49, identifier:ref_intervals; 50, slice; 50, 51; 51, colon; 52, integer:1; 53, subscript; 53, 54; 53, 55; 53, 57; 54, identifier:est_intervals; 55, slice; 55, 56; 56, colon; 57, integer:1; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:offset_distances; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:np; 64, identifier:around; 65, argument_list; 65, 66; 65, 67; 66, identifier:offset_distances; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:decimals; 69, identifier:N_DECIMALS; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:ref_durations; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:util; 76, identifier:intervals_to_durations; 77, argument_list; 77, 78; 78, identifier:ref_intervals; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:offset_tolerances; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:np; 85, identifier:maximum; 86, argument_list; 86, 87; 86, 90; 87, binary_operator:*; 87, 88; 87, 89; 88, identifier:offset_ratio; 89, identifier:ref_durations; 90, identifier:offset_min_tolerance; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:offset_hit_matrix; 94, parenthesized_expression; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:cmp_func; 97, argument_list; 97, 98; 97, 99; 98, identifier:offset_distances; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:offset_tolerances; 102, identifier:reshape; 103, argument_list; 103, 104; 103, 106; 104, unary_operator:-; 104, 105; 105, integer:1; 106, integer:1; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:hits; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:np; 113, identifier:where; 114, argument_list; 114, 115; 115, identifier:offset_hit_matrix; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:G; 119, dictionary; 120, for_statement; 120, 121; 120, 124; 120, 129; 121, pattern_list; 121, 122; 121, 123; 122, identifier:ref_i; 123, identifier:est_i; 124, call; 124, 125; 124, 126; 125, identifier:zip; 126, argument_list; 126, 127; 127, list_splat; 127, 128; 128, identifier:hits; 129, block; 129, 130; 129, 141; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:not; 131, 132; 131, 133; 132, identifier:est_i; 133, identifier:G; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:G; 139, identifier:est_i; 140, list:[]; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:G; 146, identifier:est_i; 147, identifier:append; 148, argument_list; 148, 149; 149, identifier:ref_i; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:matching; 153, call; 153, 154; 153, 155; 154, identifier:sorted; 155, argument_list; 155, 156; 156, call; 156, 157; 156, 165; 157, attribute; 157, 158; 157, 164; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:util; 161, identifier:_bipartite_match; 162, argument_list; 162, 163; 163, identifier:G; 164, identifier:items; 165, argument_list; 166, return_statement; 166, 167; 167, identifier:matching | def match_note_offsets(ref_intervals, est_intervals, offset_ratio=0.2,
offset_min_tolerance=0.05, strict=False):
if strict:
cmp_func = np.less
else:
cmp_func = np.less_equal
offset_distances = np.abs(np.subtract.outer(ref_intervals[:, 1],
est_intervals[:, 1]))
offset_distances = np.around(offset_distances, decimals=N_DECIMALS)
ref_durations = util.intervals_to_durations(ref_intervals)
offset_tolerances = np.maximum(offset_ratio * ref_durations,
offset_min_tolerance)
offset_hit_matrix = (
cmp_func(offset_distances, offset_tolerances.reshape(-1, 1)))
hits = np.where(offset_hit_matrix)
G = {}
for ref_i, est_i in zip(*hits):
if est_i not in G:
G[est_i] = []
G[est_i].append(ref_i)
matching = sorted(util._bipartite_match(G).items())
return matching |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:match_note_onsets; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:ref_intervals; 5, identifier:est_intervals; 6, default_parameter; 6, 7; 6, 8; 7, identifier:onset_tolerance; 8, float:0.05; 9, default_parameter; 9, 10; 9, 11; 10, identifier:strict; 11, False; 12, block; 12, 13; 12, 30; 12, 55; 12, 67; 12, 75; 12, 84; 12, 88; 12, 118; 12, 134; 13, if_statement; 13, 14; 13, 15; 13, 22; 14, identifier:strict; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:cmp_func; 19, attribute; 19, 20; 19, 21; 20, identifier:np; 21, identifier:less; 22, else_clause; 22, 23; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:cmp_func; 27, attribute; 27, 28; 27, 29; 28, identifier:np; 29, identifier:less_equal; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:onset_distances; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:np; 36, identifier:abs; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:np; 42, identifier:subtract; 43, identifier:outer; 44, argument_list; 44, 45; 44, 50; 45, subscript; 45, 46; 45, 47; 45, 49; 46, identifier:ref_intervals; 47, slice; 47, 48; 48, colon; 49, integer:0; 50, subscript; 50, 51; 50, 52; 50, 54; 51, identifier:est_intervals; 52, slice; 52, 53; 53, colon; 54, integer:0; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:onset_distances; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:np; 61, identifier:around; 62, argument_list; 62, 63; 62, 64; 63, identifier:onset_distances; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:decimals; 66, identifier:N_DECIMALS; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:onset_hit_matrix; 70, call; 70, 71; 70, 72; 71, identifier:cmp_func; 72, argument_list; 72, 73; 72, 74; 73, identifier:onset_distances; 74, identifier:onset_tolerance; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:hits; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:np; 81, identifier:where; 82, argument_list; 82, 83; 83, identifier:onset_hit_matrix; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:G; 87, dictionary; 88, for_statement; 88, 89; 88, 92; 88, 97; 89, pattern_list; 89, 90; 89, 91; 90, identifier:ref_i; 91, identifier:est_i; 92, call; 92, 93; 92, 94; 93, identifier:zip; 94, argument_list; 94, 95; 95, list_splat; 95, 96; 96, identifier:hits; 97, block; 97, 98; 97, 109; 98, if_statement; 98, 99; 98, 102; 99, comparison_operator:not; 99, 100; 99, 101; 100, identifier:est_i; 101, identifier:G; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:G; 107, identifier:est_i; 108, list:[]; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:G; 114, identifier:est_i; 115, identifier:append; 116, argument_list; 116, 117; 117, identifier:ref_i; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:matching; 121, call; 121, 122; 121, 123; 122, identifier:sorted; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 133; 125, attribute; 125, 126; 125, 132; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:util; 129, identifier:_bipartite_match; 130, argument_list; 130, 131; 131, identifier:G; 132, identifier:items; 133, argument_list; 134, return_statement; 134, 135; 135, identifier:matching | def match_note_onsets(ref_intervals, est_intervals, onset_tolerance=0.05,
strict=False):
if strict:
cmp_func = np.less
else:
cmp_func = np.less_equal
onset_distances = np.abs(np.subtract.outer(ref_intervals[:, 0],
est_intervals[:, 0]))
onset_distances = np.around(onset_distances, decimals=N_DECIMALS)
onset_hit_matrix = cmp_func(onset_distances, onset_tolerance)
hits = np.where(onset_hit_matrix)
G = {}
for ref_i, est_i in zip(*hits):
if est_i not in G:
G[est_i] = []
G[est_i].append(ref_i)
matching = sorted(util._bipartite_match(G).items())
return matching |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:validate; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:ref_time; 5, identifier:ref_freqs; 6, identifier:est_time; 7, identifier:est_freqs; 8, block; 8, 9; 8, 19; 8, 29; 8, 43; 8, 55; 8, 70; 8, 84; 8, 96; 8, 111; 8, 128; 8, 145; 8, 165; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:util; 13, identifier:validate_events; 14, argument_list; 14, 15; 14, 16; 15, identifier:ref_time; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:max_time; 18, identifier:MAX_TIME; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:util; 23, identifier:validate_events; 24, argument_list; 24, 25; 24, 26; 25, identifier:est_time; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:max_time; 28, identifier:MAX_TIME; 29, if_statement; 29, 30; 29, 35; 30, comparison_operator:==; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:ref_time; 33, identifier:size; 34, integer:0; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:warnings; 40, identifier:warn; 41, argument_list; 41, 42; 42, string:"Reference times are empty."; 43, if_statement; 43, 44; 43, 49; 44, comparison_operator:!=; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:ref_time; 47, identifier:ndim; 48, integer:1; 49, block; 49, 50; 50, raise_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:ValueError; 53, argument_list; 53, 54; 54, string:"Reference times have invalid dimension"; 55, if_statement; 55, 56; 55, 62; 56, comparison_operator:==; 56, 57; 56, 61; 57, call; 57, 58; 57, 59; 58, identifier:len; 59, argument_list; 59, 60; 60, identifier:ref_freqs; 61, integer:0; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:warnings; 67, identifier:warn; 68, argument_list; 68, 69; 69, string:"Reference frequencies are empty."; 70, if_statement; 70, 71; 70, 76; 71, comparison_operator:==; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:est_time; 74, identifier:size; 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:warnings; 81, identifier:warn; 82, argument_list; 82, 83; 83, string:"Estimated times are empty."; 84, if_statement; 84, 85; 84, 90; 85, comparison_operator:!=; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:est_time; 88, identifier:ndim; 89, integer:1; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:ValueError; 94, argument_list; 94, 95; 95, string:"Estimated times have invalid dimension"; 96, if_statement; 96, 97; 96, 103; 97, comparison_operator:==; 97, 98; 97, 102; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, identifier:est_freqs; 102, integer:0; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:warnings; 108, identifier:warn; 109, argument_list; 109, 110; 110, string:"Estimated frequencies are empty."; 111, if_statement; 111, 112; 111, 120; 112, comparison_operator:!=; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:ref_time; 115, identifier:size; 116, call; 116, 117; 116, 118; 117, identifier:len; 118, argument_list; 118, 119; 119, identifier:ref_freqs; 120, block; 120, 121; 121, raise_statement; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:ValueError; 124, argument_list; 124, 125; 125, concatenated_string; 125, 126; 125, 127; 126, string:'Reference times and frequencies have unequal '; 127, string:'lengths.'; 128, if_statement; 128, 129; 128, 137; 129, comparison_operator:!=; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:est_time; 132, identifier:size; 133, call; 133, 134; 133, 135; 134, identifier:len; 135, argument_list; 135, 136; 136, identifier:est_freqs; 137, block; 137, 138; 138, raise_statement; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:ValueError; 141, argument_list; 141, 142; 142, concatenated_string; 142, 143; 142, 144; 143, string:'Estimate times and frequencies have unequal '; 144, string:'lengths.'; 145, for_statement; 145, 146; 145, 147; 145, 148; 146, identifier:freq; 147, identifier:ref_freqs; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:util; 153, identifier:validate_frequencies; 154, argument_list; 154, 155; 154, 156; 154, 159; 154, 162; 155, identifier:freq; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:max_freq; 158, identifier:MAX_FREQ; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:min_freq; 161, identifier:MIN_FREQ; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:allow_negatives; 164, False; 165, for_statement; 165, 166; 165, 167; 165, 168; 166, identifier:freq; 167, identifier:est_freqs; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:util; 173, identifier:validate_frequencies; 174, argument_list; 174, 175; 174, 176; 174, 179; 174, 182; 175, identifier:freq; 176, keyword_argument; 176, 177; 176, 178; 177, identifier:max_freq; 178, identifier:MAX_FREQ; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:min_freq; 181, identifier:MIN_FREQ; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:allow_negatives; 184, False | def validate(ref_time, ref_freqs, est_time, est_freqs):
util.validate_events(ref_time, max_time=MAX_TIME)
util.validate_events(est_time, max_time=MAX_TIME)
if ref_time.size == 0:
warnings.warn("Reference times are empty.")
if ref_time.ndim != 1:
raise ValueError("Reference times have invalid dimension")
if len(ref_freqs) == 0:
warnings.warn("Reference frequencies are empty.")
if est_time.size == 0:
warnings.warn("Estimated times are empty.")
if est_time.ndim != 1:
raise ValueError("Estimated times have invalid dimension")
if len(est_freqs) == 0:
warnings.warn("Estimated frequencies are empty.")
if ref_time.size != len(ref_freqs):
raise ValueError('Reference times and frequencies have unequal '
'lengths.')
if est_time.size != len(est_freqs):
raise ValueError('Estimate times and frequencies have unequal '
'lengths.')
for freq in ref_freqs:
util.validate_frequencies(freq, max_freq=MAX_FREQ, min_freq=MIN_FREQ,
allow_negatives=False)
for freq in est_freqs:
util.validate_frequencies(freq, max_freq=MAX_FREQ, min_freq=MIN_FREQ,
allow_negatives=False) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:segments; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 4, identifier:intervals; 5, identifier:labels; 6, default_parameter; 6, 7; 6, 8; 7, identifier:base; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:height; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:text; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:text_kw; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:ax; 20, None; 21, dictionary_splat_pattern; 21, 22; 22, identifier:kwargs; 23, block; 23, 24; 23, 26; 23, 37; 23, 45; 23, 53; 23, 69; 23, 78; 23, 87; 23, 98; 23, 110; 23, 125; 23, 140; 23, 148; 23, 154; 23, 222; 23, 312; 23, 322; 23, 346; 24, expression_statement; 24, 25; 25, string:'''Plot a segmentation as a set of disjoint rectangles.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
segment intervals, in the format returned by
:func:`mir_eval.io.load_intervals` or
:func:`mir_eval.io.load_labeled_intervals`.
labels : list, shape=(n,)
reference segment labels, in the format returned by
:func:`mir_eval.io.load_labeled_intervals`.
base : number
The vertical position of the base of the rectangles.
By default, this will be the bottom of the plot.
height : number
The height of the rectangles.
By default, this will be the top of the plot (minus ``base``).
text : bool
If true, each segment's label is displayed in its
upper-left corner
text_kw : dict
If ``text == True``, the properties of the text
object can be specified here.
See ``matplotlib.pyplot.Text`` for valid parameters
ax : matplotlib.pyplot.axes
An axis handle on which to draw the segmentation.
If none is provided, a new set of axes is created.
kwargs
Additional keyword arguments to pass to
``matplotlib.patches.Rectangle``.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:text_kw; 29, None; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:text_kw; 34, call; 34, 35; 34, 36; 35, identifier:dict; 36, argument_list; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:text_kw; 41, identifier:setdefault; 42, argument_list; 42, 43; 42, 44; 43, string:'va'; 44, string:'top'; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:text_kw; 49, identifier:setdefault; 50, argument_list; 50, 51; 50, 52; 51, string:'clip_on'; 52, True; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:text_kw; 57, identifier:setdefault; 58, argument_list; 58, 59; 58, 60; 59, string:'bbox'; 60, call; 60, 61; 60, 62; 61, identifier:dict; 62, argument_list; 62, 63; 62, 66; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:boxstyle; 65, string:'round'; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:facecolor; 68, string:'white'; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:intervals; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:np; 75, identifier:atleast_2d; 76, argument_list; 76, 77; 77, identifier:intervals; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:seg_def_style; 81, call; 81, 82; 81, 83; 82, identifier:dict; 83, argument_list; 83, 84; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:linewidth; 86, integer:1; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, pattern_list; 89, 90; 89, 91; 90, identifier:ax; 91, identifier:new_axes; 92, call; 92, 93; 92, 94; 93, identifier:__get_axes; 94, argument_list; 94, 95; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:ax; 97, identifier:ax; 98, if_statement; 98, 99; 98, 100; 99, identifier:new_axes; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:ax; 105, identifier:set_ylim; 106, argument_list; 106, 107; 107, list:[0, 1]; 107, 108; 107, 109; 108, integer:0; 109, integer:1; 110, if_statement; 110, 111; 110, 114; 111, comparison_operator:is; 111, 112; 111, 113; 112, identifier:base; 113, None; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:base; 118, subscript; 118, 119; 118, 124; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:ax; 122, identifier:get_ylim; 123, argument_list; 124, integer:0; 125, if_statement; 125, 126; 125, 129; 126, comparison_operator:is; 126, 127; 126, 128; 127, identifier:height; 128, None; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:height; 133, subscript; 133, 134; 133, 139; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:ax; 137, identifier:get_ylim; 138, argument_list; 139, integer:1; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:cycler; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:ax; 146, identifier:_get_patches_for_fill; 147, identifier:prop_cycler; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:seg_map; 151, call; 151, 152; 151, 153; 152, identifier:dict; 153, argument_list; 154, for_statement; 154, 155; 154, 156; 154, 157; 155, identifier:lab; 156, identifier:labels; 157, block; 157, 158; 157, 164; 157, 171; 157, 181; 157, 190; 157, 205; 157, 214; 158, if_statement; 158, 159; 158, 162; 159, comparison_operator:in; 159, 160; 159, 161; 160, identifier:lab; 161, identifier:seg_map; 162, block; 162, 163; 163, continue_statement; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:style; 167, call; 167, 168; 167, 169; 168, identifier:next; 169, argument_list; 169, 170; 170, identifier:cycler; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:seg_map; 175, identifier:lab; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:seg_def_style; 179, identifier:copy; 180, argument_list; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 188; 183, attribute; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:seg_map; 186, identifier:lab; 187, identifier:update; 188, argument_list; 188, 189; 189, identifier:style; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 197; 192, subscript; 192, 193; 192, 196; 193, subscript; 193, 194; 193, 195; 194, identifier:seg_map; 195, identifier:lab; 196, string:'facecolor'; 197, call; 197, 198; 197, 203; 198, attribute; 198, 199; 198, 202; 199, subscript; 199, 200; 199, 201; 200, identifier:seg_map; 201, identifier:lab; 202, identifier:pop; 203, argument_list; 203, 204; 204, string:'color'; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 212; 207, attribute; 207, 208; 207, 211; 208, subscript; 208, 209; 208, 210; 209, identifier:seg_map; 210, identifier:lab; 211, identifier:update; 212, argument_list; 212, 213; 213, identifier:kwargs; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 221; 216, subscript; 216, 217; 216, 220; 217, subscript; 217, 218; 217, 219; 218, identifier:seg_map; 219, identifier:lab; 220, string:'label'; 221, identifier:lab; 222, for_statement; 222, 223; 222, 226; 222, 231; 223, pattern_list; 223, 224; 223, 225; 224, identifier:ival; 225, identifier:lab; 226, call; 226, 227; 226, 228; 227, identifier:zip; 228, argument_list; 228, 229; 228, 230; 229, identifier:intervals; 230, identifier:labels; 231, block; 231, 232; 231, 255; 231, 262; 231, 272; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:rect; 235, call; 235, 236; 235, 237; 236, identifier:Rectangle; 237, argument_list; 237, 238; 237, 243; 237, 250; 237, 251; 238, tuple; 238, 239; 238, 242; 239, subscript; 239, 240; 239, 241; 240, identifier:ival; 241, integer:0; 242, identifier:base; 243, binary_operator:-; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:ival; 246, integer:1; 247, subscript; 247, 248; 247, 249; 248, identifier:ival; 249, integer:0; 250, identifier:height; 251, dictionary_splat; 251, 252; 252, subscript; 252, 253; 252, 254; 253, identifier:seg_map; 254, identifier:lab; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:ax; 259, identifier:add_patch; 260, argument_list; 260, 261; 261, identifier:rect; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 269; 264, attribute; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:seg_map; 267, identifier:lab; 268, identifier:pop; 269, argument_list; 269, 270; 269, 271; 270, string:'label'; 271, None; 272, if_statement; 272, 273; 272, 274; 273, identifier:text; 274, block; 274, 275; 274, 305; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:ann; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:ax; 281, identifier:annotate; 282, argument_list; 282, 283; 282, 284; 282, 291; 282, 294; 282, 300; 282, 303; 283, identifier:lab; 284, keyword_argument; 284, 285; 284, 286; 285, identifier:xy; 286, tuple; 286, 287; 286, 290; 287, subscript; 287, 288; 287, 289; 288, identifier:ival; 289, integer:0; 290, identifier:height; 291, keyword_argument; 291, 292; 291, 293; 292, identifier:xycoords; 293, string:'data'; 294, keyword_argument; 294, 295; 294, 296; 295, identifier:xytext; 296, tuple; 296, 297; 296, 298; 297, integer:8; 298, unary_operator:-; 298, 299; 299, integer:10; 300, keyword_argument; 300, 301; 300, 302; 301, identifier:textcoords; 302, string:'offset points'; 303, dictionary_splat; 303, 304; 304, identifier:text_kw; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:ann; 309, identifier:set_clip_path; 310, argument_list; 310, 311; 311, identifier:rect; 312, if_statement; 312, 313; 312, 314; 313, identifier:new_axes; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:ax; 319, identifier:set_yticks; 320, argument_list; 320, 321; 321, list:[]; 322, if_statement; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:intervals; 325, identifier:size; 326, block; 326, 327; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:__expand_limits; 330, argument_list; 330, 331; 330, 332; 330, 343; 331, identifier:ax; 332, list:[intervals.min(), intervals.max()]; 332, 333; 332, 338; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:intervals; 336, identifier:min; 337, argument_list; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:intervals; 341, identifier:max; 342, argument_list; 343, keyword_argument; 343, 344; 343, 345; 344, identifier:which; 345, string:'x'; 346, return_statement; 346, 347; 347, identifier:ax | def segments(intervals, labels, base=None, height=None, text=False,
text_kw=None, ax=None, **kwargs):
'''Plot a segmentation as a set of disjoint rectangles.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
segment intervals, in the format returned by
:func:`mir_eval.io.load_intervals` or
:func:`mir_eval.io.load_labeled_intervals`.
labels : list, shape=(n,)
reference segment labels, in the format returned by
:func:`mir_eval.io.load_labeled_intervals`.
base : number
The vertical position of the base of the rectangles.
By default, this will be the bottom of the plot.
height : number
The height of the rectangles.
By default, this will be the top of the plot (minus ``base``).
text : bool
If true, each segment's label is displayed in its
upper-left corner
text_kw : dict
If ``text == True``, the properties of the text
object can be specified here.
See ``matplotlib.pyplot.Text`` for valid parameters
ax : matplotlib.pyplot.axes
An axis handle on which to draw the segmentation.
If none is provided, a new set of axes is created.
kwargs
Additional keyword arguments to pass to
``matplotlib.patches.Rectangle``.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''
if text_kw is None:
text_kw = dict()
text_kw.setdefault('va', 'top')
text_kw.setdefault('clip_on', True)
text_kw.setdefault('bbox', dict(boxstyle='round', facecolor='white'))
intervals = np.atleast_2d(intervals)
seg_def_style = dict(linewidth=1)
ax, new_axes = __get_axes(ax=ax)
if new_axes:
ax.set_ylim([0, 1])
if base is None:
base = ax.get_ylim()[0]
if height is None:
height = ax.get_ylim()[1]
cycler = ax._get_patches_for_fill.prop_cycler
seg_map = dict()
for lab in labels:
if lab in seg_map:
continue
style = next(cycler)
seg_map[lab] = seg_def_style.copy()
seg_map[lab].update(style)
seg_map[lab]['facecolor'] = seg_map[lab].pop('color')
seg_map[lab].update(kwargs)
seg_map[lab]['label'] = lab
for ival, lab in zip(intervals, labels):
rect = Rectangle((ival[0], base), ival[1] - ival[0], height,
**seg_map[lab])
ax.add_patch(rect)
seg_map[lab].pop('label', None)
if text:
ann = ax.annotate(lab,
xy=(ival[0], height), xycoords='data',
xytext=(8, -10), textcoords='offset points',
**text_kw)
ann.set_clip_path(rect)
if new_axes:
ax.set_yticks([])
if intervals.size:
__expand_limits(ax, [intervals.min(), intervals.max()], which='x')
return ax |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:labeled_intervals; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 4, identifier:intervals; 5, identifier:labels; 6, default_parameter; 6, 7; 6, 8; 7, identifier:label_set; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:base; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:height; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:extend_labels; 17, True; 18, default_parameter; 18, 19; 18, 20; 19, identifier:ax; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:tick; 23, True; 24, dictionary_splat_pattern; 24, 25; 25, identifier:kwargs; 26, block; 26, 27; 26, 29; 26, 40; 26, 49; 26, 90; 26, 129; 26, 138; 26, 152; 26, 163; 26, 170; 26, 187; 26, 196; 26, 215; 26, 221; 26, 241; 26, 248; 26, 283; 26, 312; 26, 333; 26, 383; 26, 410; 26, 434; 27, expression_statement; 27, 28; 28, string:'''Plot labeled intervals with each label on its own row.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
segment intervals, in the format returned by
:func:`mir_eval.io.load_intervals` or
:func:`mir_eval.io.load_labeled_intervals`.
labels : list, shape=(n,)
reference segment labels, in the format returned by
:func:`mir_eval.io.load_labeled_intervals`.
label_set : list
An (ordered) list of labels to determine the plotting order.
If not provided, the labels will be inferred from
``ax.get_yticklabels()``.
If no ``yticklabels`` exist, then the sorted set of unique values
in ``labels`` is taken as the label set.
base : np.ndarray, shape=(n,), optional
Vertical positions of each label.
By default, labels are positioned at integers
``np.arange(len(labels))``.
height : scalar or np.ndarray, shape=(n,), optional
Height for each label.
If scalar, the same value is applied to all labels.
By default, each label has ``height=1``.
extend_labels : bool
If ``False``, only values of ``labels`` that also exist in
``label_set`` will be shown.
If ``True``, all labels are shown, with those in `labels` but
not in `label_set` appended to the top of the plot.
A horizontal line is drawn to indicate the separation between
values in or out of ``label_set``.
ax : matplotlib.pyplot.axes
An axis handle on which to draw the intervals.
If none is provided, a new set of axes is created.
tick : bool
If ``True``, sets tick positions and labels on the y-axis.
kwargs
Additional keyword arguments to pass to
`matplotlib.collection.BrokenBarHCollection`.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, pattern_list; 31, 32; 31, 33; 32, identifier:ax; 33, identifier:_; 34, call; 34, 35; 34, 36; 35, identifier:__get_axes; 36, argument_list; 36, 37; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:ax; 39, identifier:ax; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:intervals; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:atleast_2d; 47, argument_list; 47, 48; 48, identifier:intervals; 49, if_statement; 49, 50; 49, 53; 49, 81; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:label_set; 52, None; 53, block; 53, 54; 53, 70; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:label_set; 57, list_comprehension; 57, 58; 57, 63; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:_; 61, identifier:get_text; 62, argument_list; 63, for_in_clause; 63, 64; 63, 65; 64, identifier:_; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:ax; 68, identifier:get_yticklabels; 69, argument_list; 70, if_statement; 70, 71; 70, 76; 71, not_operator; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:any; 74, argument_list; 74, 75; 75, identifier:label_set; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:label_set; 80, list:[]; 81, else_clause; 81, 82; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:label_set; 86, call; 86, 87; 86, 88; 87, identifier:list; 88, argument_list; 88, 89; 89, identifier:label_set; 90, if_statement; 90, 91; 90, 92; 90, 110; 90, 117; 91, identifier:extend_labels; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:ticks; 96, binary_operator:+; 96, 97; 96, 98; 97, identifier:label_set; 98, call; 98, 99; 98, 100; 99, identifier:sorted; 100, argument_list; 100, 101; 101, binary_operator:-; 101, 102; 101, 106; 102, call; 102, 103; 102, 104; 103, identifier:set; 104, argument_list; 104, 105; 105, identifier:labels; 106, call; 106, 107; 106, 108; 107, identifier:set; 108, argument_list; 108, 109; 109, identifier:label_set; 110, elif_clause; 110, 111; 110, 112; 111, identifier:label_set; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:ticks; 116, identifier:label_set; 117, else_clause; 117, 118; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:ticks; 122, call; 122, 123; 122, 124; 123, identifier:sorted; 124, argument_list; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:set; 127, argument_list; 127, 128; 128, identifier:labels; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:style; 132, call; 132, 133; 132, 134; 133, identifier:dict; 134, argument_list; 134, 135; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:linewidth; 137, integer:1; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:style; 142, identifier:update; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:next; 146, argument_list; 146, 147; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:ax; 150, identifier:_get_patches_for_fill; 151, identifier:prop_cycler; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:style; 156, string:'facecolor'; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:style; 160, identifier:pop; 161, argument_list; 161, 162; 162, string:'color'; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:style; 167, identifier:update; 168, argument_list; 168, 169; 169, identifier:kwargs; 170, if_statement; 170, 171; 170, 174; 171, comparison_operator:is; 171, 172; 171, 173; 172, identifier:base; 173, None; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:base; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:np; 181, identifier:arange; 182, argument_list; 182, 183; 183, call; 183, 184; 183, 185; 184, identifier:len; 185, argument_list; 185, 186; 186, identifier:ticks; 187, if_statement; 187, 188; 187, 191; 188, comparison_operator:is; 188, 189; 188, 190; 189, identifier:height; 190, None; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:height; 195, integer:1; 196, if_statement; 196, 197; 196, 203; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:np; 200, identifier:isscalar; 201, argument_list; 201, 202; 202, identifier:height; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:height; 207, binary_operator:*; 207, 208; 207, 209; 208, identifier:height; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:np; 212, identifier:ones_like; 213, argument_list; 213, 214; 214, identifier:base; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:seg_y; 218, call; 218, 219; 218, 220; 219, identifier:dict; 220, argument_list; 221, for_statement; 221, 222; 221, 226; 221, 232; 222, pattern_list; 222, 223; 222, 224; 222, 225; 223, identifier:ybase; 224, identifier:yheight; 225, identifier:lab; 226, call; 226, 227; 226, 228; 227, identifier:zip; 228, argument_list; 228, 229; 228, 230; 228, 231; 229, identifier:base; 230, identifier:height; 231, identifier:ticks; 232, block; 232, 233; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 238; 235, subscript; 235, 236; 235, 237; 236, identifier:seg_y; 237, identifier:lab; 238, tuple; 238, 239; 238, 240; 239, identifier:ybase; 240, identifier:yheight; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:xvals; 244, call; 244, 245; 244, 246; 245, identifier:defaultdict; 246, argument_list; 246, 247; 247, identifier:list; 248, for_statement; 248, 249; 248, 252; 248, 257; 249, pattern_list; 249, 250; 249, 251; 250, identifier:ival; 251, identifier:lab; 252, call; 252, 253; 252, 254; 253, identifier:zip; 254, argument_list; 254, 255; 254, 256; 255, identifier:intervals; 256, identifier:labels; 257, block; 257, 258; 257, 264; 258, if_statement; 258, 259; 258, 262; 259, comparison_operator:not; 259, 260; 259, 261; 260, identifier:lab; 261, identifier:seg_y; 262, block; 262, 263; 263, continue_statement; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 271; 266, attribute; 266, 267; 266, 270; 267, subscript; 267, 268; 267, 269; 268, identifier:xvals; 269, identifier:lab; 270, identifier:append; 271, argument_list; 271, 272; 272, tuple; 272, 273; 272, 276; 273, subscript; 273, 274; 273, 275; 274, identifier:ival; 275, integer:0; 276, binary_operator:-; 276, 277; 276, 280; 277, subscript; 277, 278; 277, 279; 278, identifier:ival; 279, integer:1; 280, subscript; 280, 281; 280, 282; 281, identifier:ival; 282, integer:0; 283, for_statement; 283, 284; 283, 285; 283, 286; 284, identifier:lab; 285, identifier:seg_y; 286, block; 286, 287; 286, 304; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:ax; 291, identifier:add_collection; 292, argument_list; 292, 293; 293, call; 293, 294; 293, 295; 294, identifier:BrokenBarHCollection; 295, argument_list; 295, 296; 295, 299; 295, 302; 296, subscript; 296, 297; 296, 298; 297, identifier:xvals; 298, identifier:lab; 299, subscript; 299, 300; 299, 301; 300, identifier:seg_y; 301, identifier:lab; 302, dictionary_splat; 302, 303; 303, identifier:style; 304, expression_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:style; 308, identifier:pop; 309, argument_list; 309, 310; 309, 311; 310, string:'label'; 311, None; 312, if_statement; 312, 313; 312, 316; 313, comparison_operator:!=; 313, 314; 313, 315; 314, identifier:label_set; 315, identifier:ticks; 316, block; 316, 317; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:ax; 321, identifier:axhline; 322, argument_list; 322, 323; 322, 327; 322, 330; 323, call; 323, 324; 323, 325; 324, identifier:len; 325, argument_list; 325, 326; 326, identifier:label_set; 327, keyword_argument; 327, 328; 327, 329; 328, identifier:color; 329, string:'k'; 330, keyword_argument; 330, 331; 330, 332; 331, identifier:alpha; 332, float:0.5; 333, if_statement; 333, 334; 333, 335; 334, identifier:tick; 335, block; 335, 336; 335, 346; 335, 353; 335, 360; 335, 370; 336, expression_statement; 336, 337; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:ax; 340, identifier:grid; 341, argument_list; 341, 342; 341, 343; 342, True; 343, keyword_argument; 343, 344; 343, 345; 344, identifier:axis; 345, string:'y'; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:ax; 350, identifier:set_yticks; 351, argument_list; 351, 352; 352, list:[]; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:ax; 357, identifier:set_yticks; 358, argument_list; 358, 359; 359, identifier:base; 360, expression_statement; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:ax; 364, identifier:set_yticklabels; 365, argument_list; 365, 366; 365, 367; 366, identifier:ticks; 367, keyword_argument; 367, 368; 367, 369; 368, identifier:va; 369, string:'bottom'; 370, expression_statement; 370, 371; 371, call; 371, 372; 371, 377; 372, attribute; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:ax; 375, identifier:yaxis; 376, identifier:set_major_formatter; 377, argument_list; 377, 378; 378, call; 378, 379; 378, 380; 379, identifier:IntervalFormatter; 380, argument_list; 380, 381; 380, 382; 381, identifier:base; 382, identifier:ticks; 383, if_statement; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:base; 386, identifier:size; 387, block; 387, 388; 388, expression_statement; 388, 389; 389, call; 389, 390; 389, 391; 390, identifier:__expand_limits; 391, argument_list; 391, 392; 391, 393; 391, 407; 392, identifier:ax; 393, list:[base.min(), (base + height).max()]; 393, 394; 393, 399; 394, call; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:base; 397, identifier:min; 398, argument_list; 399, call; 399, 400; 399, 406; 400, attribute; 400, 401; 400, 405; 401, parenthesized_expression; 401, 402; 402, binary_operator:+; 402, 403; 402, 404; 403, identifier:base; 404, identifier:height; 405, identifier:max; 406, argument_list; 407, keyword_argument; 407, 408; 407, 409; 408, identifier:which; 409, string:'y'; 410, if_statement; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:intervals; 413, identifier:size; 414, block; 414, 415; 415, expression_statement; 415, 416; 416, call; 416, 417; 416, 418; 417, identifier:__expand_limits; 418, argument_list; 418, 419; 418, 420; 418, 431; 419, identifier:ax; 420, list:[intervals.min(), intervals.max()]; 420, 421; 420, 426; 421, call; 421, 422; 421, 425; 422, attribute; 422, 423; 422, 424; 423, identifier:intervals; 424, identifier:min; 425, argument_list; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:intervals; 429, identifier:max; 430, argument_list; 431, keyword_argument; 431, 432; 431, 433; 432, identifier:which; 433, string:'x'; 434, return_statement; 434, 435; 435, identifier:ax | def labeled_intervals(intervals, labels, label_set=None,
base=None, height=None, extend_labels=True,
ax=None, tick=True, **kwargs):
'''Plot labeled intervals with each label on its own row.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
segment intervals, in the format returned by
:func:`mir_eval.io.load_intervals` or
:func:`mir_eval.io.load_labeled_intervals`.
labels : list, shape=(n,)
reference segment labels, in the format returned by
:func:`mir_eval.io.load_labeled_intervals`.
label_set : list
An (ordered) list of labels to determine the plotting order.
If not provided, the labels will be inferred from
``ax.get_yticklabels()``.
If no ``yticklabels`` exist, then the sorted set of unique values
in ``labels`` is taken as the label set.
base : np.ndarray, shape=(n,), optional
Vertical positions of each label.
By default, labels are positioned at integers
``np.arange(len(labels))``.
height : scalar or np.ndarray, shape=(n,), optional
Height for each label.
If scalar, the same value is applied to all labels.
By default, each label has ``height=1``.
extend_labels : bool
If ``False``, only values of ``labels`` that also exist in
``label_set`` will be shown.
If ``True``, all labels are shown, with those in `labels` but
not in `label_set` appended to the top of the plot.
A horizontal line is drawn to indicate the separation between
values in or out of ``label_set``.
ax : matplotlib.pyplot.axes
An axis handle on which to draw the intervals.
If none is provided, a new set of axes is created.
tick : bool
If ``True``, sets tick positions and labels on the y-axis.
kwargs
Additional keyword arguments to pass to
`matplotlib.collection.BrokenBarHCollection`.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''
ax, _ = __get_axes(ax=ax)
intervals = np.atleast_2d(intervals)
if label_set is None:
label_set = [_.get_text() for _ in ax.get_yticklabels()]
if not any(label_set):
label_set = []
else:
label_set = list(label_set)
if extend_labels:
ticks = label_set + sorted(set(labels) - set(label_set))
elif label_set:
ticks = label_set
else:
ticks = sorted(set(labels))
style = dict(linewidth=1)
style.update(next(ax._get_patches_for_fill.prop_cycler))
style['facecolor'] = style.pop('color')
style.update(kwargs)
if base is None:
base = np.arange(len(ticks))
if height is None:
height = 1
if np.isscalar(height):
height = height * np.ones_like(base)
seg_y = dict()
for ybase, yheight, lab in zip(base, height, ticks):
seg_y[lab] = (ybase, yheight)
xvals = defaultdict(list)
for ival, lab in zip(intervals, labels):
if lab not in seg_y:
continue
xvals[lab].append((ival[0], ival[1] - ival[0]))
for lab in seg_y:
ax.add_collection(BrokenBarHCollection(xvals[lab], seg_y[lab],
**style))
style.pop('label', None)
if label_set != ticks:
ax.axhline(len(label_set), color='k', alpha=0.5)
if tick:
ax.grid(True, axis='y')
ax.set_yticks([])
ax.set_yticks(base)
ax.set_yticklabels(ticks, va='bottom')
ax.yaxis.set_major_formatter(IntervalFormatter(base, ticks))
if base.size:
__expand_limits(ax, [base.min(), (base + height).max()], which='y')
if intervals.size:
__expand_limits(ax, [intervals.min(), intervals.max()], which='x')
return ax |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:events; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:times; 5, default_parameter; 5, 6; 5, 7; 6, identifier:labels; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:base; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:height; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:ax; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:text_kw; 19, None; 20, dictionary_splat_pattern; 20, 21; 21, identifier:kwargs; 22, block; 22, 23; 22, 25; 22, 36; 22, 44; 22, 52; 22, 68; 22, 77; 22, 88; 22, 150; 22, 158; 22, 169; 22, 176; 22, 189; 22, 204; 22, 253; 22, 263; 22, 276; 22, 300; 23, expression_statement; 23, 24; 24, string:'''Plot event times as a set of vertical lines
Parameters
----------
times : np.ndarray, shape=(n,)
event times, in the format returned by
:func:`mir_eval.io.load_events` or
:func:`mir_eval.io.load_labeled_events`.
labels : list, shape=(n,), optional
event labels, in the format returned by
:func:`mir_eval.io.load_labeled_events`.
base : number
The vertical position of the base of the line.
By default, this will be the bottom of the plot.
height : number
The height of the lines.
By default, this will be the top of the plot (minus `base`).
ax : matplotlib.pyplot.axes
An axis handle on which to draw the segmentation.
If none is provided, a new set of axes is created.
text_kw : dict
If `labels` is provided, the properties of the text
objects can be specified here.
See `matplotlib.pyplot.Text` for valid parameters
kwargs
Additional keyword arguments to pass to
`matplotlib.pyplot.vlines`.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:text_kw; 28, None; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:text_kw; 33, call; 33, 34; 33, 35; 34, identifier:dict; 35, argument_list; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:text_kw; 40, identifier:setdefault; 41, argument_list; 41, 42; 41, 43; 42, string:'va'; 43, string:'top'; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:text_kw; 48, identifier:setdefault; 49, argument_list; 49, 50; 49, 51; 50, string:'clip_on'; 51, True; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:text_kw; 56, identifier:setdefault; 57, argument_list; 57, 58; 57, 59; 58, string:'bbox'; 59, call; 59, 60; 59, 61; 60, identifier:dict; 61, argument_list; 61, 62; 61, 65; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:boxstyle; 64, string:'round'; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:facecolor; 67, string:'white'; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:times; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:np; 74, identifier:asarray; 75, argument_list; 75, 76; 76, identifier:times; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, pattern_list; 79, 80; 79, 81; 80, identifier:ax; 81, identifier:new_axes; 82, call; 82, 83; 82, 84; 83, identifier:__get_axes; 84, argument_list; 84, 85; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:ax; 87, identifier:ax; 88, if_statement; 88, 89; 88, 90; 88, 118; 89, identifier:new_axes; 90, block; 90, 91; 90, 100; 90, 109; 91, if_statement; 91, 92; 91, 95; 92, comparison_operator:is; 92, 93; 92, 94; 93, identifier:base; 94, None; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:base; 99, integer:0; 100, if_statement; 100, 101; 100, 104; 101, comparison_operator:is; 101, 102; 101, 103; 102, identifier:height; 103, None; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:height; 108, integer:1; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:ax; 113, identifier:set_ylim; 114, argument_list; 114, 115; 115, list:[base, height]; 115, 116; 115, 117; 116, identifier:base; 117, identifier:height; 118, else_clause; 118, 119; 119, block; 119, 120; 119, 135; 120, if_statement; 120, 121; 120, 124; 121, comparison_operator:is; 121, 122; 121, 123; 122, identifier:base; 123, None; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:base; 128, subscript; 128, 129; 128, 134; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:ax; 132, identifier:get_ylim; 133, argument_list; 134, integer:0; 135, if_statement; 135, 136; 135, 139; 136, comparison_operator:is; 136, 137; 136, 138; 137, identifier:height; 138, None; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:height; 143, subscript; 143, 144; 143, 149; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:ax; 147, identifier:get_ylim; 148, argument_list; 149, integer:1; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:cycler; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:ax; 156, identifier:_get_patches_for_fill; 157, identifier:prop_cycler; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:style; 161, call; 161, 162; 161, 168; 162, attribute; 162, 163; 162, 167; 163, call; 163, 164; 163, 165; 164, identifier:next; 165, argument_list; 165, 166; 166, identifier:cycler; 167, identifier:copy; 168, argument_list; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:style; 173, identifier:update; 174, argument_list; 174, 175; 175, identifier:kwargs; 176, if_statement; 176, 177; 176, 180; 177, comparison_operator:in; 177, 178; 177, 179; 178, string:'colors'; 179, identifier:style; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:style; 185, identifier:pop; 186, argument_list; 186, 187; 186, 188; 187, string:'color'; 188, None; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:lines; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:ax; 195, identifier:vlines; 196, argument_list; 196, 197; 196, 198; 196, 199; 196, 202; 197, identifier:times; 198, identifier:base; 199, binary_operator:+; 199, 200; 199, 201; 200, identifier:base; 201, identifier:height; 202, dictionary_splat; 202, 203; 203, identifier:style; 204, if_statement; 204, 205; 204, 206; 205, identifier:labels; 206, block; 206, 207; 207, for_statement; 207, 208; 207, 211; 207, 220; 208, pattern_list; 208, 209; 208, 210; 209, identifier:path; 210, identifier:lab; 211, call; 211, 212; 211, 213; 212, identifier:zip; 213, argument_list; 213, 214; 213, 219; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:lines; 217, identifier:get_paths; 218, argument_list; 219, identifier:labels; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:ax; 225, identifier:annotate; 226, argument_list; 226, 227; 226, 228; 226, 239; 226, 242; 226, 248; 226, 251; 227, identifier:lab; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:xy; 230, tuple; 230, 231; 230, 238; 231, subscript; 231, 232; 231, 237; 232, subscript; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:path; 235, identifier:vertices; 236, integer:0; 237, integer:0; 238, identifier:height; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:xycoords; 241, string:'data'; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:xytext; 244, tuple; 244, 245; 244, 246; 245, integer:8; 246, unary_operator:-; 246, 247; 247, integer:10; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:textcoords; 250, string:'offset points'; 251, dictionary_splat; 251, 252; 252, identifier:text_kw; 253, if_statement; 253, 254; 253, 255; 254, identifier:new_axes; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:ax; 260, identifier:set_yticks; 261, argument_list; 261, 262; 262, list:[]; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 266; 265, identifier:__expand_limits; 266, argument_list; 266, 267; 266, 268; 266, 273; 267, identifier:ax; 268, list:[base, base + height]; 268, 269; 268, 270; 269, identifier:base; 270, binary_operator:+; 270, 271; 270, 272; 271, identifier:base; 272, identifier:height; 273, keyword_argument; 273, 274; 273, 275; 274, identifier:which; 275, string:'y'; 276, if_statement; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:times; 279, identifier:size; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 284; 283, identifier:__expand_limits; 284, argument_list; 284, 285; 284, 286; 284, 297; 285, identifier:ax; 286, list:[times.min(), times.max()]; 286, 287; 286, 292; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:times; 290, identifier:min; 291, argument_list; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:times; 295, identifier:max; 296, argument_list; 297, keyword_argument; 297, 298; 297, 299; 298, identifier:which; 299, string:'x'; 300, return_statement; 300, 301; 301, identifier:ax | def events(times, labels=None, base=None, height=None, ax=None, text_kw=None,
**kwargs):
'''Plot event times as a set of vertical lines
Parameters
----------
times : np.ndarray, shape=(n,)
event times, in the format returned by
:func:`mir_eval.io.load_events` or
:func:`mir_eval.io.load_labeled_events`.
labels : list, shape=(n,), optional
event labels, in the format returned by
:func:`mir_eval.io.load_labeled_events`.
base : number
The vertical position of the base of the line.
By default, this will be the bottom of the plot.
height : number
The height of the lines.
By default, this will be the top of the plot (minus `base`).
ax : matplotlib.pyplot.axes
An axis handle on which to draw the segmentation.
If none is provided, a new set of axes is created.
text_kw : dict
If `labels` is provided, the properties of the text
objects can be specified here.
See `matplotlib.pyplot.Text` for valid parameters
kwargs
Additional keyword arguments to pass to
`matplotlib.pyplot.vlines`.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''
if text_kw is None:
text_kw = dict()
text_kw.setdefault('va', 'top')
text_kw.setdefault('clip_on', True)
text_kw.setdefault('bbox', dict(boxstyle='round', facecolor='white'))
times = np.asarray(times)
ax, new_axes = __get_axes(ax=ax)
if new_axes:
if base is None:
base = 0
if height is None:
height = 1
ax.set_ylim([base, height])
else:
if base is None:
base = ax.get_ylim()[0]
if height is None:
height = ax.get_ylim()[1]
cycler = ax._get_patches_for_fill.prop_cycler
style = next(cycler).copy()
style.update(kwargs)
if 'colors' in style:
style.pop('color', None)
lines = ax.vlines(times, base, base + height, **style)
if labels:
for path, lab in zip(lines.get_paths(), labels):
ax.annotate(lab,
xy=(path.vertices[0][0], height),
xycoords='data',
xytext=(8, -10), textcoords='offset points',
**text_kw)
if new_axes:
ax.set_yticks([])
__expand_limits(ax, [base, base + height], which='y')
if times.size:
__expand_limits(ax, [times.min(), times.max()], which='x')
return ax |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:pitch; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:times; 5, identifier:frequencies; 6, default_parameter; 6, 7; 6, 8; 7, identifier:midi; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:unvoiced; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:ax; 14, None; 15, dictionary_splat_pattern; 15, 16; 16, identifier:kwargs; 17, block; 17, 18; 17, 20; 17, 31; 17, 40; 17, 59; 17, 81; 17, 103; 17, 111; 17, 161; 17, 167; 17, 181; 17, 188; 17, 220; 17, 246; 17, 281; 18, expression_statement; 18, 19; 19, string:'''Visualize pitch contours
Parameters
----------
times : np.ndarray, shape=(n,)
Sample times of frequencies
frequencies : np.ndarray, shape=(n,)
frequencies (in Hz) of the pitch contours.
Voicing is indicated by sign (positive for voiced,
non-positive for non-voiced).
midi : bool
If `True`, plot on a MIDI-numbered vertical axis.
Otherwise, plot on a linear frequency axis.
unvoiced : bool
If `True`, unvoiced pitch contours are plotted and indicated
by transparency.
Otherwise, unvoiced pitch contours are omitted from the display.
ax : matplotlib.pyplot.axes
An axis handle on which to draw the pitch contours.
If none is provided, a new set of axes is created.
kwargs
Additional keyword arguments to `matplotlib.pyplot.plot`.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 25; 22, pattern_list; 22, 23; 22, 24; 23, identifier:ax; 24, identifier:_; 25, call; 25, 26; 25, 27; 26, identifier:__get_axes; 27, argument_list; 27, 28; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:ax; 30, identifier:ax; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:times; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:np; 37, identifier:asarray; 38, argument_list; 38, 39; 39, identifier:times; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, pattern_list; 42, 43; 42, 44; 43, identifier:frequencies; 44, identifier:voicings; 45, call; 45, 46; 45, 47; 46, identifier:freq_to_voicing; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:np; 51, identifier:asarray; 52, argument_list; 52, 53; 52, 54; 53, identifier:frequencies; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:dtype; 56, attribute; 56, 57; 56, 58; 57, identifier:np; 58, identifier:float; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:v_changes; 62, binary_operator:+; 62, 63; 62, 64; 63, integer:1; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:np; 67, identifier:flatnonzero; 68, argument_list; 68, 69; 69, comparison_operator:!=; 69, 70; 69, 75; 70, subscript; 70, 71; 70, 72; 71, identifier:voicings; 72, slice; 72, 73; 72, 74; 73, integer:1; 74, colon; 75, subscript; 75, 76; 75, 77; 76, identifier:voicings; 77, slice; 77, 78; 77, 79; 78, colon; 79, unary_operator:-; 79, 80; 80, integer:1; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:v_changes; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:np; 87, identifier:unique; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:np; 92, identifier:concatenate; 93, argument_list; 93, 94; 94, list:[[0], v_changes, [len(voicings)]]; 94, 95; 94, 97; 94, 98; 95, list:[0]; 95, 96; 96, integer:0; 97, identifier:v_changes; 98, list:[len(voicings)]; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:len; 101, argument_list; 101, 102; 102, identifier:voicings; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, pattern_list; 105, 106; 105, 107; 106, identifier:v_slices; 107, identifier:u_slices; 108, expression_list; 108, 109; 108, 110; 109, list:[]; 110, list:[]; 111, for_statement; 111, 112; 111, 115; 111, 124; 112, pattern_list; 112, 113; 112, 114; 113, identifier:start; 114, identifier:end; 115, call; 115, 116; 115, 117; 116, identifier:zip; 117, argument_list; 117, 118; 117, 119; 118, identifier:v_changes; 119, subscript; 119, 120; 119, 121; 120, identifier:v_changes; 121, slice; 121, 122; 121, 123; 122, integer:1; 123, colon; 124, block; 124, 125; 124, 133; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:idx; 128, call; 128, 129; 128, 130; 129, identifier:slice; 130, argument_list; 130, 131; 130, 132; 131, identifier:start; 132, identifier:end; 133, if_statement; 133, 134; 133, 137; 133, 145; 134, subscript; 134, 135; 134, 136; 135, identifier:voicings; 136, identifier:start; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:v_slices; 142, identifier:append; 143, argument_list; 143, 144; 144, identifier:idx; 145, elif_clause; 145, 146; 145, 153; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:frequencies; 150, identifier:idx; 151, identifier:all; 152, argument_list; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:u_slices; 158, identifier:append; 159, argument_list; 159, 160; 160, identifier:idx; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:style; 164, call; 164, 165; 164, 166; 165, identifier:dict; 166, argument_list; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:style; 171, identifier:update; 172, argument_list; 172, 173; 173, call; 173, 174; 173, 175; 174, identifier:next; 175, argument_list; 175, 176; 176, attribute; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:ax; 179, identifier:_get_lines; 180, identifier:prop_cycler; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:style; 185, identifier:update; 186, argument_list; 186, 187; 187, identifier:kwargs; 188, if_statement; 188, 189; 188, 190; 189, identifier:midi; 190, block; 190, 191; 190, 197; 190, 208; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:idx; 194, comparison_operator:>; 194, 195; 194, 196; 195, identifier:frequencies; 196, integer:0; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 202; 199, subscript; 199, 200; 199, 201; 200, identifier:frequencies; 201, identifier:idx; 202, call; 202, 203; 202, 204; 203, identifier:hz_to_midi; 204, argument_list; 204, 205; 205, subscript; 205, 206; 205, 207; 206, identifier:frequencies; 207, identifier:idx; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 215; 210, attribute; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:ax; 213, identifier:yaxis; 214, identifier:set_minor_locator; 215, argument_list; 215, 216; 216, call; 216, 217; 216, 218; 217, identifier:MultipleLocator; 218, argument_list; 218, 219; 219, integer:1; 220, for_statement; 220, 221; 220, 222; 220, 223; 221, identifier:idx; 222, identifier:v_slices; 223, block; 223, 224; 223, 238; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:ax; 228, identifier:plot; 229, argument_list; 229, 230; 229, 233; 229, 236; 230, subscript; 230, 231; 230, 232; 231, identifier:times; 232, identifier:idx; 233, subscript; 233, 234; 233, 235; 234, identifier:frequencies; 235, identifier:idx; 236, dictionary_splat; 236, 237; 237, identifier:style; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:style; 242, identifier:pop; 243, argument_list; 243, 244; 243, 245; 244, string:'label'; 245, None; 246, if_statement; 246, 247; 246, 248; 247, identifier:unvoiced; 248, block; 248, 249; 248, 263; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 254; 251, subscript; 251, 252; 251, 253; 252, identifier:style; 253, string:'alpha'; 254, binary_operator:*; 254, 255; 254, 262; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:style; 258, identifier:get; 259, argument_list; 259, 260; 259, 261; 260, string:'alpha'; 261, float:1.0; 262, float:0.5; 263, for_statement; 263, 264; 263, 265; 263, 266; 264, identifier:idx; 265, identifier:u_slices; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:ax; 271, identifier:plot; 272, argument_list; 272, 273; 272, 276; 272, 279; 273, subscript; 273, 274; 273, 275; 274, identifier:times; 275, identifier:idx; 276, subscript; 276, 277; 276, 278; 277, identifier:frequencies; 278, identifier:idx; 279, dictionary_splat; 279, 280; 280, identifier:style; 281, return_statement; 281, 282; 282, identifier:ax | def pitch(times, frequencies, midi=False, unvoiced=False, ax=None, **kwargs):
'''Visualize pitch contours
Parameters
----------
times : np.ndarray, shape=(n,)
Sample times of frequencies
frequencies : np.ndarray, shape=(n,)
frequencies (in Hz) of the pitch contours.
Voicing is indicated by sign (positive for voiced,
non-positive for non-voiced).
midi : bool
If `True`, plot on a MIDI-numbered vertical axis.
Otherwise, plot on a linear frequency axis.
unvoiced : bool
If `True`, unvoiced pitch contours are plotted and indicated
by transparency.
Otherwise, unvoiced pitch contours are omitted from the display.
ax : matplotlib.pyplot.axes
An axis handle on which to draw the pitch contours.
If none is provided, a new set of axes is created.
kwargs
Additional keyword arguments to `matplotlib.pyplot.plot`.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''
ax, _ = __get_axes(ax=ax)
times = np.asarray(times)
frequencies, voicings = freq_to_voicing(np.asarray(frequencies,
dtype=np.float))
v_changes = 1 + np.flatnonzero(voicings[1:] != voicings[:-1])
v_changes = np.unique(np.concatenate([[0], v_changes, [len(voicings)]]))
v_slices, u_slices = [], []
for start, end in zip(v_changes, v_changes[1:]):
idx = slice(start, end)
if voicings[start]:
v_slices.append(idx)
elif frequencies[idx].all():
u_slices.append(idx)
style = dict()
style.update(next(ax._get_lines.prop_cycler))
style.update(kwargs)
if midi:
idx = frequencies > 0
frequencies[idx] = hz_to_midi(frequencies[idx])
ax.yaxis.set_minor_locator(MultipleLocator(1))
for idx in v_slices:
ax.plot(times[idx], frequencies[idx], **style)
style.pop('label', None)
if unvoiced:
style['alpha'] = style.get('alpha', 1.0) * 0.5
for idx in u_slices:
ax.plot(times[idx], frequencies[idx], **style)
return ax |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:create; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:archive; 6, default_parameter; 6, 7; 6, 8; 7, identifier:interval; 8, None; 9, dictionary_splat_pattern; 9, 10; 10, identifier:import_args; 11, block; 11, 12; 11, 27; 11, 58; 11, 79; 11, 87; 11, 104; 11, 110; 11, 114; 11, 172; 11, 201; 11, 236; 11, 290; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:archive; 15, conditional_expression:if; 15, 16; 15, 21; 15, 26; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:archive; 19, identifier:lower; 20, argument_list; 21, call; 21, 22; 21, 23; 22, identifier:hasattr; 23, argument_list; 23, 24; 23, 25; 24, identifier:archive; 25, string:"lower"; 26, identifier:archive; 27, if_statement; 27, 28; 27, 37; 27, 47; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:is_sync_table; 32, argument_list; 32, 33; 32, 34; 32, 35; 33, identifier:archive; 34, identifier:interval; 35, dictionary_splat; 35, 36; 36, identifier:import_args; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:manager; 41, call; 41, 42; 41, 43; 42, identifier:SyncTableJobManager; 43, argument_list; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:client; 47, else_clause; 47, 48; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:manager; 52, call; 52, 53; 52, 54; 53, identifier:FileImportJobManager; 54, argument_list; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:client; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:import_job; 61, conditional_expression:if; 61, 62; 61, 68; 61, 71; 61, 72; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:manager; 65, identifier:create; 66, argument_list; 66, 67; 67, identifier:archive; 68, comparison_operator:is; 68, 69; 68, 70; 69, identifier:interval; 70, None; 71, line_continuation:\; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:manager; 75, identifier:create; 76, argument_list; 76, 77; 76, 78; 77, identifier:archive; 78, identifier:interval; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:import_job; 83, identifier:run; 84, argument_list; 84, 85; 85, dictionary_splat; 85, 86; 86, identifier:import_args; 87, if_statement; 87, 88; 87, 95; 88, comparison_operator:is; 88, 89; 88, 94; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:import_job; 92, identifier:get_id; 93, argument_list; 94, None; 95, block; 95, 96; 96, raise_statement; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:CartoException; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:_; 102, argument_list; 102, 103; 103, string:"Import API returned corrupt job details \
when creating dataset"; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:import_job; 108, identifier:refresh; 109, argument_list; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:count; 113, integer:0; 114, while_statement; 114, 115; 114, 141; 115, boolean_operator:or; 115, 116; 115, 128; 115, 129; 116, comparison_operator:in; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:import_job; 119, identifier:state; 120, tuple; 120, 121; 120, 122; 120, 123; 120, 124; 120, 125; 120, 126; 120, 127; 121, string:"enqueued"; 122, string:"queued"; 123, string:"pending"; 124, string:"uploading"; 125, string:"unpacking"; 126, string:"importing"; 127, string:"guessing"; 128, line_continuation:\; 129, parenthesized_expression; 129, 130; 130, boolean_operator:and; 130, 131; 130, 136; 131, call; 131, 132; 131, 133; 132, identifier:isinstance; 133, argument_list; 133, 134; 133, 135; 134, identifier:manager; 135, identifier:SyncTableJobManager; 136, comparison_operator:==; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:import_job; 139, identifier:state; 140, string:"created"; 141, block; 141, 142; 141, 155; 141, 162; 141, 168; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:>=; 143, 144; 143, 145; 144, identifier:count; 145, identifier:MAX_NUMBER_OF_RETRIES; 146, block; 146, 147; 147, raise_statement; 147, 148; 148, call; 148, 149; 148, 150; 149, identifier:CartoException; 150, argument_list; 150, 151; 151, call; 151, 152; 151, 153; 152, identifier:_; 153, argument_list; 153, 154; 154, string:"Maximum number of retries exceeded \
when polling the import API for \
dataset creation"; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:time; 159, identifier:sleep; 160, argument_list; 160, 161; 161, identifier:INTERVAL_BETWEEN_RETRIES_S; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:import_job; 166, identifier:refresh; 167, argument_list; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:count; 171, integer:1; 172, if_statement; 172, 173; 172, 178; 173, comparison_operator:==; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:import_job; 176, identifier:state; 177, string:"failure"; 178, block; 178, 179; 179, raise_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:CartoException; 182, argument_list; 182, 183; 183, call; 183, 184; 183, 190; 184, attribute; 184, 185; 184, 189; 185, call; 185, 186; 185, 187; 186, identifier:_; 187, argument_list; 187, 188; 188, string:"Dataset creation was not successful \
because of failed import (error: {error}"; 189, identifier:format; 190, argument_list; 190, 191; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:error; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:json; 196, identifier:dumps; 197, argument_list; 197, 198; 198, attribute; 198, 199; 198, 200; 199, identifier:import_job; 200, identifier:get_error_text; 201, if_statement; 201, 202; 201, 227; 202, boolean_operator:or; 202, 203; 202, 221; 202, 222; 203, parenthesized_expression; 203, 204; 204, boolean_operator:and; 204, 205; 204, 216; 205, boolean_operator:and; 205, 206; 205, 211; 206, comparison_operator:!=; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:import_job; 209, identifier:state; 210, string:"complete"; 211, comparison_operator:!=; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:import_job; 214, identifier:state; 215, string:"created"; 216, comparison_operator:!=; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:import_job; 219, identifier:state; 220, string:"success"; 221, line_continuation:\; 222, comparison_operator:is; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:import_job; 225, identifier:success; 226, False; 227, block; 227, 228; 228, raise_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:CartoException; 231, argument_list; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:_; 234, argument_list; 234, 235; 235, string:"Dataset creation was not successful \
because of unknown import error"; 236, if_statement; 236, 237; 236, 249; 236, 256; 237, boolean_operator:and; 237, 238; 237, 243; 237, 244; 238, call; 238, 239; 238, 240; 239, identifier:hasattr; 240, argument_list; 240, 241; 240, 242; 241, identifier:import_job; 242, string:"visualization_id"; 243, line_continuation:\; 244, comparison_operator:is; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:import_job; 247, identifier:visualization_id; 248, None; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:visualization_id; 253, attribute; 253, 254; 253, 255; 254, identifier:import_job; 255, identifier:visualization_id; 256, else_clause; 256, 257; 257, block; 257, 258; 257, 274; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:table; 261, call; 261, 262; 261, 270; 262, attribute; 262, 263; 262, 269; 263, call; 263, 264; 263, 265; 264, identifier:TableManager; 265, argument_list; 265, 266; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:client; 269, identifier:get; 270, argument_list; 270, 271; 271, attribute; 271, 272; 271, 273; 272, identifier:import_job; 273, identifier:table_id; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:visualization_id; 277, conditional_expression:if; 277, 278; 277, 285; 277, 286; 277, 289; 278, call; 278, 279; 278, 284; 279, attribute; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:table; 282, identifier:table_visualization; 283, identifier:get_id; 284, argument_list; 285, line_continuation:\; 286, comparison_operator:is; 286, 287; 286, 288; 287, identifier:table; 288, None; 289, None; 290, try_statement; 290, 291; 290, 305; 291, block; 291, 292; 292, return_statement; 292, 293; 293, conditional_expression:if; 293, 294; 293, 300; 293, 303; 293, 304; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:self; 297, identifier:get; 298, argument_list; 298, 299; 299, identifier:visualization_id; 300, comparison_operator:is; 300, 301; 300, 302; 301, identifier:visualization_id; 302, None; 303, line_continuation:\; 304, None; 305, except_clause; 305, 306; 305, 307; 306, identifier:AttributeError; 307, block; 307, 308; 308, raise_statement; 308, 309; 309, call; 309, 310; 309, 311; 310, identifier:CartoException; 311, argument_list; 311, 312; 312, call; 312, 313; 312, 314; 313, identifier:_; 314, argument_list; 314, 315; 315, string:"Dataset creation was not successful \
because of unknown error" | def create(self, archive, interval=None, **import_args):
archive = archive.lower() if hasattr(archive, "lower") else archive
if self.is_sync_table(archive, interval, **import_args):
manager = SyncTableJobManager(self.client)
else:
manager = FileImportJobManager(self.client)
import_job = manager.create(archive) if interval is None \
else manager.create(archive, interval)
import_job.run(**import_args)
if import_job.get_id() is None:
raise CartoException(_("Import API returned corrupt job details \
when creating dataset"))
import_job.refresh()
count = 0
while import_job.state in ("enqueued", "queued", "pending", "uploading",
"unpacking", "importing", "guessing") \
or (isinstance(manager, SyncTableJobManager)
and import_job.state == "created"):
if count >= MAX_NUMBER_OF_RETRIES:
raise CartoException(_("Maximum number of retries exceeded \
when polling the import API for \
dataset creation"))
time.sleep(INTERVAL_BETWEEN_RETRIES_S)
import_job.refresh()
count += 1
if import_job.state == "failure":
raise CartoException(_("Dataset creation was not successful \
because of failed import (error: {error}")
.format(error=json.dumps(
import_job.get_error_text)))
if (import_job.state != "complete" and import_job.state != "created"
and import_job.state != "success") \
or import_job.success is False:
raise CartoException(_("Dataset creation was not successful \
because of unknown import error"))
if hasattr(import_job, "visualization_id") \
and import_job.visualization_id is not None:
visualization_id = import_job.visualization_id
else:
table = TableManager(self.client).get(import_job.table_id)
visualization_id = table.table_visualization.get_id() \
if table is not None else None
try:
return self.get(visualization_id) if visualization_id is not None \
else None
except AttributeError:
raise CartoException(_("Dataset creation was not successful \
because of unknown error")) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:copy_data; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:data_length; 5, identifier:blocksize; 6, identifier:infp; 7, identifier:outfp; 8, block; 8, 9; 8, 11; 8, 15; 8, 48; 9, expression_statement; 9, 10; 10, string:'''
A utility function to copy data from the input file object to the output
file object. This function will use the most efficient copy method available,
which is often sendfile.
Parameters:
data_length - The amount of data to copy.
blocksize - How much data to copy per iteration.
infp - The file object to copy data from.
outfp - The file object to copy data to.
Returns:
Nothing.
'''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:use_sendfile; 14, False; 15, if_statement; 15, 16; 15, 17; 16, identifier:have_sendfile; 17, block; 17, 18; 18, try_statement; 18, 19; 18, 40; 19, block; 19, 20; 19, 28; 19, 36; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:x_unused; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:infp; 26, identifier:fileno; 27, argument_list; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:y_unused; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:outfp; 34, identifier:fileno; 35, argument_list; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:use_sendfile; 39, True; 40, except_clause; 40, 41; 40, 46; 41, tuple; 41, 42; 41, 43; 42, identifier:AttributeError; 43, attribute; 43, 44; 43, 45; 44, identifier:io; 45, identifier:UnsupportedOperation; 46, block; 46, 47; 47, pass_statement; 48, if_statement; 48, 49; 48, 50; 48, 101; 49, identifier:use_sendfile; 50, block; 50, 51; 50, 59; 50, 67; 50, 83; 50, 92; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:in_offset; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:infp; 57, identifier:tell; 58, argument_list; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:out_offset; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:outfp; 65, identifier:tell; 66, argument_list; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:sendfile; 70, argument_list; 70, 71; 70, 76; 70, 81; 70, 82; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:outfp; 74, identifier:fileno; 75, argument_list; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:infp; 79, identifier:fileno; 80, argument_list; 81, identifier:in_offset; 82, identifier:data_length; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:infp; 87, identifier:seek; 88, argument_list; 88, 89; 89, binary_operator:+; 89, 90; 89, 91; 90, identifier:in_offset; 91, identifier:data_length; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:outfp; 96, identifier:seek; 97, argument_list; 97, 98; 98, binary_operator:+; 98, 99; 98, 100; 99, identifier:out_offset; 100, identifier:data_length; 101, else_clause; 101, 102; 102, block; 102, 103; 102, 107; 102, 111; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:left; 106, identifier:data_length; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:readsize; 110, identifier:blocksize; 111, while_statement; 111, 112; 111, 115; 112, comparison_operator:>; 112, 113; 112, 114; 113, identifier:left; 114, integer:0; 115, block; 115, 116; 115, 125; 115, 134; 115, 141; 115, 150; 115, 157; 116, if_statement; 116, 117; 116, 120; 117, comparison_operator:<; 117, 118; 117, 119; 118, identifier:left; 119, identifier:readsize; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:readsize; 124, identifier:left; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:data; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:infp; 131, identifier:read; 132, argument_list; 132, 133; 133, identifier:readsize; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:data_len; 137, call; 137, 138; 137, 139; 138, identifier:len; 139, argument_list; 139, 140; 140, identifier:data; 141, if_statement; 141, 142; 141, 145; 142, comparison_operator:!=; 142, 143; 142, 144; 143, identifier:data_len; 144, identifier:readsize; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:data_len; 149, identifier:left; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:outfp; 154, identifier:write; 155, argument_list; 155, 156; 156, identifier:data; 157, expression_statement; 157, 158; 158, augmented_assignment:-=; 158, 159; 158, 160; 159, identifier:left; 160, identifier:data_len | def copy_data(data_length, blocksize, infp, outfp):
'''
A utility function to copy data from the input file object to the output
file object. This function will use the most efficient copy method available,
which is often sendfile.
Parameters:
data_length - The amount of data to copy.
blocksize - How much data to copy per iteration.
infp - The file object to copy data from.
outfp - The file object to copy data to.
Returns:
Nothing.
'''
use_sendfile = False
if have_sendfile:
try:
x_unused = infp.fileno()
y_unused = outfp.fileno()
use_sendfile = True
except (AttributeError, io.UnsupportedOperation):
pass
if use_sendfile:
in_offset = infp.tell()
out_offset = outfp.tell()
sendfile(outfp.fileno(), infp.fileno(), in_offset, data_length)
infp.seek(in_offset + data_length)
outfp.seek(out_offset + data_length)
else:
left = data_length
readsize = blocksize
while left > 0:
if left < readsize:
readsize = left
data = infp.read(readsize)
data_len = len(data)
if data_len != readsize:
data_len = left
outfp.write(data)
left -= data_len |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parse; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:instr; 6, block; 6, 7; 6, 9; 6, 21; 6, 36; 6, 80; 6, 117; 6, 129; 6, 141; 6, 154; 6, 241; 6, 277; 6, 287; 6, 293; 6, 299; 7, expression_statement; 7, 8; 8, string:'''
A method to parse ISO hybridization info out of an existing ISO.
Parameters:
instr - The data for the ISO hybridization.
Returns:
Nothing.
'''; 9, if_statement; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_initialized; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:pycdlibexception; 18, identifier:PyCdlibInternalError; 19, argument_list; 19, 20; 20, string:'This IsoHybrid object is already initialized'; 21, if_statement; 21, 22; 21, 28; 22, comparison_operator:!=; 22, 23; 22, 27; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:instr; 27, integer:512; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:pycdlibexception; 33, identifier:PyCdlibInvalidISO; 34, argument_list; 34, 35; 35, string:'Invalid size of the instr'; 36, if_statement; 36, 37; 36, 47; 36, 56; 36, 76; 37, comparison_operator:==; 37, 38; 37, 44; 38, subscript; 38, 39; 38, 40; 39, identifier:instr; 40, slice; 40, 41; 40, 42; 40, 43; 41, integer:0; 42, colon; 43, integer:32; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:ORIG_HEADER; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:header; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:ORIG_HEADER; 56, elif_clause; 56, 57; 56, 67; 57, comparison_operator:==; 57, 58; 57, 64; 58, subscript; 58, 59; 58, 60; 59, identifier:instr; 60, slice; 60, 61; 60, 62; 60, 63; 61, integer:0; 62, colon; 63, integer:32; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:MAC_AFP; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:header; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:MAC_AFP; 76, else_clause; 76, 77; 77, block; 77, 78; 78, return_statement; 78, 79; 79, False; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 94; 82, tuple_pattern; 82, 83; 82, 86; 82, 89; 82, 90; 82, 93; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:mbr; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:rba; 89, identifier:unused1; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:mbr_id; 93, identifier:unused2; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:struct; 97, identifier:unpack_from; 98, argument_list; 98, 99; 98, 102; 98, 116; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:FMT; 102, subscript; 102, 103; 102, 104; 103, identifier:instr; 104, slice; 104, 105; 104, 106; 105, colon; 106, binary_operator:+; 106, 107; 106, 108; 107, integer:32; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:struct; 111, identifier:calcsize; 112, argument_list; 112, 113; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:FMT; 116, integer:32; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:!=; 118, 119; 118, 120; 119, identifier:unused1; 120, integer:0; 121, block; 121, 122; 122, raise_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:pycdlibexception; 126, identifier:PyCdlibInvalidISO; 127, argument_list; 127, 128; 128, string:'Invalid IsoHybrid section'; 129, if_statement; 129, 130; 129, 133; 130, comparison_operator:!=; 130, 131; 130, 132; 131, identifier:unused2; 132, integer:0; 133, block; 133, 134; 134, raise_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:pycdlibexception; 138, identifier:PyCdlibInvalidISO; 139, argument_list; 139, 140; 140, string:'Invalid IsoHybrid section'; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:offset; 144, binary_operator:+; 144, 145; 144, 146; 145, integer:32; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:struct; 149, identifier:calcsize; 150, argument_list; 150, 151; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:FMT; 154, for_statement; 154, 155; 154, 156; 154, 161; 154, 232; 155, identifier:i; 156, call; 156, 157; 156, 158; 157, identifier:range; 158, argument_list; 158, 159; 158, 160; 159, integer:1; 160, integer:5; 161, block; 161, 162; 161, 228; 162, if_statement; 162, 163; 162, 175; 163, comparison_operator:==; 163, 164; 163, 174; 164, call; 164, 165; 164, 166; 165, identifier:bytes; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:bytearray; 169, argument_list; 169, 170; 170, list:[instr[offset]]; 170, 171; 171, subscript; 171, 172; 171, 173; 172, identifier:instr; 173, identifier:offset; 174, string:b'\x80'; 175, block; 175, 176; 175, 182; 175, 227; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:part_entry; 181, identifier:i; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 213; 184, tuple_pattern; 184, 185; 184, 186; 184, 189; 184, 192; 184, 195; 184, 198; 184, 201; 184, 204; 184, 207; 184, 210; 185, identifier:const_unused; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:bhead; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:bsect; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:bcyle; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:ptype; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:ehead; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:esect; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:ecyle; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:part_offset; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:psize; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:struct; 216, identifier:unpack_from; 217, argument_list; 217, 218; 217, 219; 217, 226; 218, string:'=BBBBBBBBLL'; 219, subscript; 219, 220; 219, 221; 220, identifier:instr; 221, slice; 221, 222; 221, 223; 222, colon; 223, binary_operator:+; 223, 224; 223, 225; 224, identifier:offset; 225, integer:16; 226, identifier:offset; 227, break_statement; 228, expression_statement; 228, 229; 229, augmented_assignment:+=; 229, 230; 229, 231; 230, identifier:offset; 231, integer:16; 232, else_clause; 232, 233; 233, block; 233, 234; 234, raise_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:pycdlibexception; 238, identifier:PyCdlibInvalidISO; 239, argument_list; 239, 240; 240, string:'No valid partition found in IsoHybrid!'; 241, if_statement; 241, 242; 241, 269; 242, boolean_operator:or; 242, 243; 242, 256; 243, comparison_operator:!=; 243, 244; 243, 255; 244, call; 244, 245; 244, 246; 245, identifier:bytes; 246, argument_list; 246, 247; 247, call; 247, 248; 247, 249; 248, identifier:bytearray; 249, argument_list; 249, 250; 250, list:[instr[-2]]; 250, 251; 251, subscript; 251, 252; 251, 253; 252, identifier:instr; 253, unary_operator:-; 253, 254; 254, integer:2; 255, string:b'\x55'; 256, comparison_operator:!=; 256, 257; 256, 268; 257, call; 257, 258; 257, 259; 258, identifier:bytes; 259, argument_list; 259, 260; 260, call; 260, 261; 260, 262; 261, identifier:bytearray; 262, argument_list; 262, 263; 263, list:[instr[-1]]; 263, 264; 264, subscript; 264, 265; 264, 266; 265, identifier:instr; 266, unary_operator:-; 266, 267; 267, integer:1; 268, string:b'\xaa'; 269, block; 269, 270; 270, raise_statement; 270, 271; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:pycdlibexception; 274, identifier:PyCdlibInvalidISO; 275, argument_list; 275, 276; 276, string:'Invalid tail on isohybrid section'; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:geometry_heads; 282, binary_operator:+; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:self; 285, identifier:ehead; 286, integer:1; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:geometry_sectors; 292, integer:32; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:self; 297, identifier:_initialized; 298, True; 299, return_statement; 299, 300; 300, True | def parse(self, instr):
'''
A method to parse ISO hybridization info out of an existing ISO.
Parameters:
instr - The data for the ISO hybridization.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized')
if len(instr) != 512:
raise pycdlibexception.PyCdlibInvalidISO('Invalid size of the instr')
if instr[0:32] == self.ORIG_HEADER:
self.header = self.ORIG_HEADER
elif instr[0:32] == self.MAC_AFP:
self.header = self.MAC_AFP
else:
return False
(self.mbr, self.rba, unused1, self.mbr_id,
unused2) = struct.unpack_from(self.FMT, instr[:32 + struct.calcsize(self.FMT)], 32)
if unused1 != 0:
raise pycdlibexception.PyCdlibInvalidISO('Invalid IsoHybrid section')
if unused2 != 0:
raise pycdlibexception.PyCdlibInvalidISO('Invalid IsoHybrid section')
offset = 32 + struct.calcsize(self.FMT)
for i in range(1, 5):
if bytes(bytearray([instr[offset]])) == b'\x80':
self.part_entry = i
(const_unused, self.bhead, self.bsect, self.bcyle, self.ptype,
self.ehead, self.esect, self.ecyle, self.part_offset,
self.psize) = struct.unpack_from('=BBBBBBBBLL', instr[:offset + 16], offset)
break
offset += 16
else:
raise pycdlibexception.PyCdlibInvalidISO('No valid partition found in IsoHybrid!')
if bytes(bytearray([instr[-2]])) != b'\x55' or bytes(bytearray([instr[-1]])) != b'\xaa':
raise pycdlibexception.PyCdlibInvalidISO('Invalid tail on isohybrid section')
self.geometry_heads = self.ehead + 1
self.geometry_sectors = 32
self._initialized = True
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:new; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:mac; 6, identifier:part_entry; 7, identifier:mbr_id; 8, identifier:part_offset; 9, identifier:geometry_sectors; 10, identifier:geometry_heads; 11, identifier:part_type; 12, block; 12, 13; 12, 15; 12, 27; 12, 48; 12, 52; 12, 58; 12, 64; 12, 70; 12, 88; 12, 94; 12, 105; 12, 116; 12, 127; 12, 140; 12, 146; 12, 152; 12, 160; 12, 166; 12, 172; 12, 178; 13, expression_statement; 13, 14; 14, string:'''
A method to add ISO hybridization to an ISO.
Parameters:
mac - Whether this ISO should be made bootable for the Macintosh.
part_entry - The partition entry for the hybridization.
mbr_id - The mbr_id to use for the hybridization.
part_offset - The partition offset to use for the hybridization.
geometry_sectors - The number of sectors to use for the hybridization.
geometry_heads - The number of heads to use for the hybridization.
part_type - The partition type for the hybridization.
Returns:
Nothing.
'''; 15, if_statement; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_initialized; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:pycdlibexception; 24, identifier:PyCdlibInternalError; 25, argument_list; 25, 26; 26, string:'This IsoHybrid object is already initialized'; 27, if_statement; 27, 28; 27, 29; 27, 38; 28, identifier:mac; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:header; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:MAC_AFP; 38, else_clause; 38, 39; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:header; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:ORIG_HEADER; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:isohybrid_data_hd0; 51, string:b'\x33\xed\xfa\x8e\xd5\xbc\x00\x7c\xfb\xfc\x66\x31\xdb\x66\x31\xc9\x66\x53\x66\x51\x06\x57\x8e\xdd\x8e\xc5\x52\xbe\x00\x7c\xbf\x00\x06\xb9\x00\x01\xf3\xa5\xea\x4b\x06\x00\x00\x52\xb4\x41\xbb\xaa\x55\x31\xc9\x30\xf6\xf9\xcd\x13\x72\x16\x81\xfb\x55\xaa\x75\x10\x83\xe1\x01\x74\x0b\x66\xc7\x06\xf1\x06\xb4\x42\xeb\x15\xeb\x00\x5a\x51\xb4\x08\xcd\x13\x83\xe1\x3f\x5b\x51\x0f\xb6\xc6\x40\x50\xf7\xe1\x53\x52\x50\xbb\x00\x7c\xb9\x04\x00\x66\xa1\xb0\x07\xe8\x44\x00\x0f\x82\x80\x00\x66\x40\x80\xc7\x02\xe2\xf2\x66\x81\x3e\x40\x7c\xfb\xc0\x78\x70\x75\x09\xfa\xbc\xec\x7b\xea\x44\x7c\x00\x00\xe8\x83\x00\x69\x73\x6f\x6c\x69\x6e\x75\x78\x2e\x62\x69\x6e\x20\x6d\x69\x73\x73\x69\x6e\x67\x20\x6f\x72\x20\x63\x6f\x72\x72\x75\x70\x74\x2e\x0d\x0a\x66\x60\x66\x31\xd2\x66\x03\x06\xf8\x7b\x66\x13\x16\xfc\x7b\x66\x52\x66\x50\x06\x53\x6a\x01\x6a\x10\x89\xe6\x66\xf7\x36\xe8\x7b\xc0\xe4\x06\x88\xe1\x88\xc5\x92\xf6\x36\xee\x7b\x88\xc6\x08\xe1\x41\xb8\x01\x02\x8a\x16\xf2\x7b\xcd\x13\x8d\x64\x10\x66\x61\xc3\xe8\x1e\x00\x4f\x70\x65\x72\x61\x74\x69\x6e\x67\x20\x73\x79\x73\x74\x65\x6d\x20\x6c\x6f\x61\x64\x20\x65\x72\x72\x6f\x72\x2e\x0d\x0a\x5e\xac\xb4\x0e\x8a\x3e\x62\x04\xb3\x07\xcd\x10\x3c\x0a\x75\xf1\xcd\x18\xf4\xeb\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:mbr; 57, identifier:isohybrid_data_hd0; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:rba; 63, integer:0; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:mbr_id; 69, identifier:mbr_id; 70, if_statement; 70, 71; 70, 76; 71, comparison_operator:is; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:mbr_id; 75, None; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:mbr_id; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:random; 85, identifier:getrandbits; 86, argument_list; 86, 87; 87, integer:32; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:part_entry; 93, identifier:part_entry; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:bhead; 99, binary_operator:%; 99, 100; 99, 104; 100, parenthesized_expression; 100, 101; 101, binary_operator://; 101, 102; 101, 103; 102, identifier:part_offset; 103, identifier:geometry_sectors; 104, identifier:geometry_heads; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:bsect; 110, binary_operator:+; 110, 111; 110, 115; 111, parenthesized_expression; 111, 112; 112, binary_operator:%; 112, 113; 112, 114; 113, identifier:part_offset; 114, identifier:geometry_sectors; 115, integer:1; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:bcyle; 121, binary_operator://; 121, 122; 121, 123; 122, identifier:part_offset; 123, parenthesized_expression; 123, 124; 124, binary_operator:*; 124, 125; 124, 126; 125, identifier:geometry_heads; 126, identifier:geometry_sectors; 127, expression_statement; 127, 128; 128, augmented_assignment:+=; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:bsect; 132, binary_operator:>>; 132, 133; 132, 139; 133, parenthesized_expression; 133, 134; 134, binary_operator:&; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:bcyle; 138, integer:0x300; 139, integer:2; 140, expression_statement; 140, 141; 141, augmented_assignment:&=; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:bcyle; 145, integer:0xff; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:ptype; 151, identifier:part_type; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:ehead; 157, binary_operator:-; 157, 158; 157, 159; 158, identifier:geometry_heads; 159, integer:1; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:part_offset; 165, identifier:part_offset; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:geometry_heads; 171, identifier:geometry_heads; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:geometry_sectors; 177, identifier:geometry_sectors; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:_initialized; 183, True | def new(self, mac, part_entry, mbr_id, part_offset,
geometry_sectors, geometry_heads, part_type):
'''
A method to add ISO hybridization to an ISO.
Parameters:
mac - Whether this ISO should be made bootable for the Macintosh.
part_entry - The partition entry for the hybridization.
mbr_id - The mbr_id to use for the hybridization.
part_offset - The partition offset to use for the hybridization.
geometry_sectors - The number of sectors to use for the hybridization.
geometry_heads - The number of heads to use for the hybridization.
part_type - The partition type for the hybridization.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized')
if mac:
self.header = self.MAC_AFP
else:
self.header = self.ORIG_HEADER
isohybrid_data_hd0 = b'\x33\xed\xfa\x8e\xd5\xbc\x00\x7c\xfb\xfc\x66\x31\xdb\x66\x31\xc9\x66\x53\x66\x51\x06\x57\x8e\xdd\x8e\xc5\x52\xbe\x00\x7c\xbf\x00\x06\xb9\x00\x01\xf3\xa5\xea\x4b\x06\x00\x00\x52\xb4\x41\xbb\xaa\x55\x31\xc9\x30\xf6\xf9\xcd\x13\x72\x16\x81\xfb\x55\xaa\x75\x10\x83\xe1\x01\x74\x0b\x66\xc7\x06\xf1\x06\xb4\x42\xeb\x15\xeb\x00\x5a\x51\xb4\x08\xcd\x13\x83\xe1\x3f\x5b\x51\x0f\xb6\xc6\x40\x50\xf7\xe1\x53\x52\x50\xbb\x00\x7c\xb9\x04\x00\x66\xa1\xb0\x07\xe8\x44\x00\x0f\x82\x80\x00\x66\x40\x80\xc7\x02\xe2\xf2\x66\x81\x3e\x40\x7c\xfb\xc0\x78\x70\x75\x09\xfa\xbc\xec\x7b\xea\x44\x7c\x00\x00\xe8\x83\x00\x69\x73\x6f\x6c\x69\x6e\x75\x78\x2e\x62\x69\x6e\x20\x6d\x69\x73\x73\x69\x6e\x67\x20\x6f\x72\x20\x63\x6f\x72\x72\x75\x70\x74\x2e\x0d\x0a\x66\x60\x66\x31\xd2\x66\x03\x06\xf8\x7b\x66\x13\x16\xfc\x7b\x66\x52\x66\x50\x06\x53\x6a\x01\x6a\x10\x89\xe6\x66\xf7\x36\xe8\x7b\xc0\xe4\x06\x88\xe1\x88\xc5\x92\xf6\x36\xee\x7b\x88\xc6\x08\xe1\x41\xb8\x01\x02\x8a\x16\xf2\x7b\xcd\x13\x8d\x64\x10\x66\x61\xc3\xe8\x1e\x00\x4f\x70\x65\x72\x61\x74\x69\x6e\x67\x20\x73\x79\x73\x74\x65\x6d\x20\x6c\x6f\x61\x64\x20\x65\x72\x72\x6f\x72\x2e\x0d\x0a\x5e\xac\xb4\x0e\x8a\x3e\x62\x04\xb3\x07\xcd\x10\x3c\x0a\x75\xf1\xcd\x18\xf4\xeb\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
self.mbr = isohybrid_data_hd0
self.rba = 0
self.mbr_id = mbr_id
if self.mbr_id is None:
self.mbr_id = random.getrandbits(32)
self.part_entry = part_entry
self.bhead = (part_offset // geometry_sectors) % geometry_heads
self.bsect = (part_offset % geometry_sectors) + 1
self.bcyle = part_offset // (geometry_heads * geometry_sectors)
self.bsect += (self.bcyle & 0x300) >> 2
self.bcyle &= 0xff
self.ptype = part_type
self.ehead = geometry_heads - 1
self.part_offset = part_offset
self.geometry_heads = geometry_heads
self.geometry_sectors = geometry_sectors
self._initialized = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_new; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:vd; 6, identifier:name; 7, identifier:parent; 8, identifier:seqnum; 9, identifier:isdir; 10, identifier:length; 11, identifier:xa; 12, block; 12, 13; 12, 15; 12, 25; 12, 33; 12, 49; 12, 55; 12, 61; 12, 67; 12, 73; 12, 79; 12, 90; 12, 107; 12, 113; 12, 129; 12, 135; 12, 141; 12, 147; 12, 153; 12, 164; 12, 193; 12, 204; 12, 251; 12, 257; 13, expression_statement; 13, 14; 14, string:'''
Internal method to create a new Directory Record.
Parameters:
vd - The Volume Descriptor this record is part of.
name - The name for this directory record.
parent - The parent of this directory record.
seqnum - The sequence number to associate with this directory record.
isdir - Whether this directory record represents a directory.
length - The length of the data for this directory record.
xa - True if this is an Extended Attribute record.
Returns:
Nothing.
'''; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:date; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:dates; 23, identifier:DirectoryRecordDate; 24, argument_list; 25, expression_statement; 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:date; 31, identifier:new; 32, argument_list; 33, if_statement; 33, 34; 33, 41; 34, comparison_operator:>; 34, 35; 34, 36; 35, identifier:length; 36, binary_operator:-; 36, 37; 36, 40; 37, binary_operator:**; 37, 38; 37, 39; 38, integer:2; 39, integer:32; 40, integer:1; 41, block; 41, 42; 42, raise_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:pycdlibexception; 46, identifier:PyCdlibInvalidInput; 47, argument_list; 47, 48; 48, string:'Maximum supported file length is 2^32-1'; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:data_length; 54, identifier:length; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:file_ident; 60, identifier:name; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:isdir; 66, identifier:isdir; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:seqnum; 72, identifier:seqnum; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:orig_extent_loc; 78, None; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:len_fi; 84, call; 84, 85; 84, 86; 85, identifier:len; 86, argument_list; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:file_ident; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:dr_len; 95, binary_operator:+; 95, 96; 95, 104; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:struct; 99, identifier:calcsize; 100, argument_list; 100, 101; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:FMT; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:len_fi; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:file_flags; 112, integer:0; 113, if_statement; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:isdir; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, augmented_assignment:|=; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:file_flags; 123, parenthesized_expression; 123, 124; 124, binary_operator:<<; 124, 125; 124, 126; 125, integer:1; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:FILE_FLAG_DIRECTORY_BIT; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:file_unit_size; 134, integer:0; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:interleave_gap_size; 140, integer:0; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:xattr_len; 146, integer:0; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:parent; 152, identifier:parent; 153, if_statement; 153, 154; 153, 157; 154, comparison_operator:is; 154, 155; 154, 156; 155, identifier:parent; 156, None; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:is_root; 163, True; 164, if_statement; 164, 165; 164, 166; 165, identifier:xa; 166, block; 166, 167; 166, 175; 166, 183; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:xa_record; 172, call; 172, 173; 172, 174; 173, identifier:XARecord; 174, argument_list; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 182; 177, attribute; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:xa_record; 181, identifier:new; 182, argument_list; 183, expression_statement; 183, 184; 184, augmented_assignment:+=; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:dr_len; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:XARecord; 191, identifier:length; 192, argument_list; 193, expression_statement; 193, 194; 194, augmented_assignment:+=; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:dr_len; 198, parenthesized_expression; 198, 199; 199, binary_operator:%; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:dr_len; 203, integer:2; 204, if_statement; 204, 205; 204, 208; 204, 215; 204, 228; 204, 241; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:is_root; 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:_printable_name; 214, string:b'/'; 215, elif_clause; 215, 216; 215, 221; 216, comparison_operator:==; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:self; 219, identifier:file_ident; 220, string:b'\x00'; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:_printable_name; 227, string:b'.'; 228, elif_clause; 228, 229; 228, 234; 229, comparison_operator:==; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:file_ident; 233, string:b'\x01'; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:_printable_name; 240, string:b'..'; 241, else_clause; 241, 242; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:_printable_name; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:file_ident; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:vd; 256, identifier:vd; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:_initialized; 262, True | def _new(self, vd, name, parent, seqnum, isdir, length, xa):
'''
Internal method to create a new Directory Record.
Parameters:
vd - The Volume Descriptor this record is part of.
name - The name for this directory record.
parent - The parent of this directory record.
seqnum - The sequence number to associate with this directory record.
isdir - Whether this directory record represents a directory.
length - The length of the data for this directory record.
xa - True if this is an Extended Attribute record.
Returns:
Nothing.
'''
self.date = dates.DirectoryRecordDate()
self.date.new()
if length > 2**32 - 1:
raise pycdlibexception.PyCdlibInvalidInput('Maximum supported file length is 2^32-1')
self.data_length = length
self.file_ident = name
self.isdir = isdir
self.seqnum = seqnum
self.orig_extent_loc = None
self.len_fi = len(self.file_ident)
self.dr_len = struct.calcsize(self.FMT) + self.len_fi
self.file_flags = 0
if self.isdir:
self.file_flags |= (1 << self.FILE_FLAG_DIRECTORY_BIT)
self.file_unit_size = 0
self.interleave_gap_size = 0
self.xattr_len = 0
self.parent = parent
if parent is None:
self.is_root = True
if xa:
self.xa_record = XARecord()
self.xa_record.new()
self.dr_len += XARecord.length()
self.dr_len += (self.dr_len % 2)
if self.is_root:
self._printable_name = b'/'
elif self.file_ident == b'\x00':
self._printable_name = b'.'
elif self.file_ident == b'\x01':
self._printable_name = b'..'
else:
self._printable_name = self.file_ident
self.vd = vd
self._initialized = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:new_dir; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 4, identifier:self; 5, identifier:vd; 6, identifier:name; 7, identifier:parent; 8, identifier:seqnum; 9, identifier:rock_ridge; 10, identifier:rr_name; 11, identifier:log_block_size; 12, identifier:rr_relocated_child; 13, identifier:rr_relocated; 14, identifier:xa; 15, identifier:file_mode; 16, block; 16, 17; 16, 19; 16, 31; 16, 44; 17, expression_statement; 17, 18; 18, string:'''
Create a new directory Directory Record.
Parameters:
vd - The Volume Descriptor this record is part of.
name - The name for this directory record.
parent - The parent of this directory record.
seqnum - The sequence number for this directory record.
rock_ridge - Whether to make this a Rock Ridge directory record.
rr_name - The Rock Ridge name for this directory record.
log_block_size - The logical block size to use.
rr_relocated_child - True if this is a Rock Ridge relocated child.
rr_relocated - True if this is a Rock Ridge relocated entry.
xa - True if this is an Extended Attribute record.
file_mode - The POSIX file mode to set for this directory.
Returns:
Nothing.
'''; 19, if_statement; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_initialized; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:pycdlibexception; 28, identifier:PyCdlibInternalError; 29, argument_list; 29, 30; 30, string:'Directory Record already initialized'; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_new; 36, argument_list; 36, 37; 36, 38; 36, 39; 36, 40; 36, 41; 36, 42; 36, 43; 37, identifier:vd; 38, identifier:name; 39, identifier:parent; 40, identifier:seqnum; 41, True; 42, identifier:log_block_size; 43, identifier:xa; 44, if_statement; 44, 45; 44, 46; 45, identifier:rock_ridge; 46, block; 46, 47; 46, 60; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_rr_new; 52, argument_list; 52, 53; 52, 54; 52, 55; 52, 56; 52, 57; 52, 58; 52, 59; 53, identifier:rock_ridge; 54, identifier:rr_name; 55, string:b''; 56, identifier:rr_relocated_child; 57, identifier:rr_relocated; 58, False; 59, identifier:file_mode; 60, if_statement; 60, 61; 60, 66; 61, boolean_operator:and; 61, 62; 61, 63; 62, identifier:rr_relocated_child; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:rock_ridge; 66, block; 66, 67; 66, 73; 66, 79; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:isdir; 72, False; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:file_flags; 78, integer:0; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:rock_ridge; 85, identifier:add_to_file_links; 86, argument_list | def new_dir(self, vd, name, parent, seqnum, rock_ridge, rr_name, log_block_size,
rr_relocated_child, rr_relocated, xa, file_mode):
'''
Create a new directory Directory Record.
Parameters:
vd - The Volume Descriptor this record is part of.
name - The name for this directory record.
parent - The parent of this directory record.
seqnum - The sequence number for this directory record.
rock_ridge - Whether to make this a Rock Ridge directory record.
rr_name - The Rock Ridge name for this directory record.
log_block_size - The logical block size to use.
rr_relocated_child - True if this is a Rock Ridge relocated child.
rr_relocated - True if this is a Rock Ridge relocated entry.
xa - True if this is an Extended Attribute record.
file_mode - The POSIX file mode to set for this directory.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized')
self._new(vd, name, parent, seqnum, True, log_block_size, xa)
if rock_ridge:
self._rr_new(rock_ridge, rr_name, b'', rr_relocated_child,
rr_relocated, False, file_mode)
if rr_relocated_child and self.rock_ridge:
self.isdir = False
self.file_flags = 0
self.rock_ridge.add_to_file_links() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_add_child; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:child; 6, identifier:logical_block_size; 7, identifier:allow_duplicate; 8, identifier:check_overflow; 9, block; 9, 10; 9, 12; 9, 25; 9, 37; 9, 122; 9, 132; 9, 245; 9, 257; 9, 261; 9, 351; 10, expression_statement; 10, 11; 11, string:'''
An internal method to add a child to this object. Note that this is called both
during parsing and when adding a new object to the system, so it
it shouldn't have any functionality that is not appropriate for both.
Parameters:
child - The child directory record object to add.
logical_block_size - The size of a logical block for this volume descriptor.
allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed.
check_overflow - Whether to check for overflow; if we are parsing, we don't want to do this.
Returns:
True if adding this child caused the directory to overflow into another
extent, False otherwise.
'''; 12, if_statement; 12, 13; 12, 17; 13, not_operator; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:isdir; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:pycdlibexception; 22, identifier:PyCdlibInvalidInput; 23, argument_list; 23, 24; 24, string:'Trying to add a child to a record that is not a directory'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:index; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:bisect; 31, identifier:bisect_left; 32, argument_list; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:children; 36, identifier:child; 37, if_statement; 37, 38; 37, 58; 38, boolean_operator:and; 38, 39; 38, 47; 39, comparison_operator:!=; 39, 40; 39, 41; 40, identifier:index; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:children; 47, comparison_operator:==; 47, 48; 47, 55; 48, attribute; 48, 49; 48, 54; 49, subscript; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:children; 53, identifier:index; 54, identifier:file_ident; 55, attribute; 55, 56; 55, 57; 56, identifier:child; 57, identifier:file_ident; 58, block; 58, 59; 59, if_statement; 59, 60; 59, 77; 60, boolean_operator:and; 60, 61; 60, 71; 61, not_operator; 61, 62; 62, call; 62, 63; 62, 70; 63, attribute; 63, 64; 63, 69; 64, subscript; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:children; 68, identifier:index; 69, identifier:is_associated_file; 70, argument_list; 71, not_operator; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:child; 75, identifier:is_associated_file; 76, argument_list; 77, block; 77, 78; 78, if_statement; 78, 79; 78, 94; 79, not_operator; 79, 80; 80, parenthesized_expression; 80, 81; 81, boolean_operator:and; 81, 82; 81, 87; 82, comparison_operator:is; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:rock_ridge; 86, None; 87, comparison_operator:==; 87, 88; 87, 93; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:file_identifier; 92, argument_list; 93, string:b'RR_MOVED'; 94, block; 94, 95; 95, if_statement; 95, 96; 95, 98; 95, 106; 96, not_operator; 96, 97; 97, identifier:allow_duplicate; 98, block; 98, 99; 99, raise_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:pycdlibexception; 103, identifier:PyCdlibInvalidInput; 104, argument_list; 104, 105; 105, string:'Failed adding duplicate name to parent'; 106, else_clause; 106, 107; 107, block; 107, 108; 107, 118; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 117; 110, attribute; 110, 111; 110, 116; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:children; 115, identifier:index; 116, identifier:data_continuation; 117, identifier:child; 118, expression_statement; 118, 119; 119, augmented_assignment:+=; 119, 120; 119, 121; 120, identifier:index; 121, integer:1; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:children; 128, identifier:insert; 129, argument_list; 129, 130; 129, 131; 130, identifier:index; 131, identifier:child; 132, if_statement; 132, 133; 132, 152; 133, boolean_operator:and; 133, 134; 133, 146; 134, boolean_operator:and; 134, 135; 134, 140; 135, comparison_operator:is; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:child; 138, identifier:rock_ridge; 139, None; 140, not_operator; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:child; 144, identifier:is_dot; 145, argument_list; 146, not_operator; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:child; 150, identifier:is_dotdot; 151, argument_list; 152, block; 152, 153; 152, 157; 152, 166; 152, 231; 152, 235; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:lo; 156, integer:0; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:hi; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:rr_children; 166, while_statement; 166, 167; 166, 170; 167, comparison_operator:<; 167, 168; 167, 169; 168, identifier:lo; 169, identifier:hi; 170, block; 170, 171; 170, 180; 170, 190; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:mid; 174, binary_operator://; 174, 175; 174, 179; 175, parenthesized_expression; 175, 176; 176, binary_operator:+; 176, 177; 176, 178; 177, identifier:lo; 178, identifier:hi; 179, integer:2; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:rr; 183, attribute; 183, 184; 183, 189; 184, subscript; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:rr_children; 188, identifier:mid; 189, identifier:rock_ridge; 190, if_statement; 190, 191; 190, 194; 190, 222; 191, comparison_operator:is; 191, 192; 191, 193; 192, identifier:rr; 193, None; 194, block; 194, 195; 195, if_statement; 195, 196; 195, 209; 195, 216; 196, comparison_operator:<; 196, 197; 196, 202; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:rr; 200, identifier:name; 201, argument_list; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:child; 206, identifier:rock_ridge; 207, identifier:name; 208, argument_list; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:lo; 213, binary_operator:+; 213, 214; 213, 215; 214, identifier:mid; 215, integer:1; 216, else_clause; 216, 217; 217, block; 217, 218; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:hi; 221, identifier:mid; 222, else_clause; 222, 223; 223, block; 223, 224; 224, raise_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:pycdlibexception; 228, identifier:PyCdlibInternalError; 229, argument_list; 229, 230; 230, string:'Expected all children to have Rock Ridge, but one did not'; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:rr_index; 234, identifier:lo; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 242; 237, attribute; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:rr_children; 241, identifier:insert; 242, argument_list; 242, 243; 242, 244; 243, identifier:rr_index; 244, identifier:child; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 250; 247, pattern_list; 247, 248; 247, 249; 248, identifier:num_extents; 249, identifier:offset_unused; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:_recalculate_extents_and_offsets; 254, argument_list; 254, 255; 254, 256; 255, identifier:index; 256, identifier:logical_block_size; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:overflowed; 260, False; 261, if_statement; 261, 262; 261, 272; 262, boolean_operator:and; 262, 263; 262, 264; 263, identifier:check_overflow; 264, parenthesized_expression; 264, 265; 265, comparison_operator:>; 265, 266; 265, 269; 266, binary_operator:*; 266, 267; 266, 268; 267, identifier:num_extents; 268, identifier:logical_block_size; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:data_length; 272, block; 272, 273; 272, 277; 272, 283; 272, 295; 272, 314; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:overflowed; 276, True; 277, expression_statement; 277, 278; 278, augmented_assignment:+=; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:data_length; 282, identifier:logical_block_size; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 292; 285, attribute; 285, 286; 285, 291; 286, subscript; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:children; 290, integer:0; 291, identifier:data_length; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:data_length; 295, if_statement; 295, 296; 295, 301; 296, comparison_operator:is; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:self; 299, identifier:parent; 300, None; 301, block; 301, 302; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 311; 304, attribute; 304, 305; 304, 310; 305, subscript; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:self; 308, identifier:children; 309, integer:1; 310, identifier:data_length; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:data_length; 314, for_statement; 314, 315; 314, 316; 314, 319; 315, identifier:c; 316, attribute; 316, 317; 316, 318; 317, identifier:self; 318, identifier:children; 319, block; 319, 320; 319, 329; 320, if_statement; 320, 321; 320, 327; 321, not_operator; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:c; 325, identifier:is_dir; 326, argument_list; 327, block; 327, 328; 328, continue_statement; 329, if_statement; 329, 330; 329, 338; 330, comparison_operator:>; 330, 331; 330, 337; 331, call; 331, 332; 331, 333; 332, identifier:len; 333, argument_list; 333, 334; 334, attribute; 334, 335; 334, 336; 335, identifier:c; 336, identifier:children; 337, integer:1; 338, block; 338, 339; 339, expression_statement; 339, 340; 340, assignment; 340, 341; 340, 348; 341, attribute; 341, 342; 341, 347; 342, subscript; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:c; 345, identifier:children; 346, integer:1; 347, identifier:data_length; 348, attribute; 348, 349; 348, 350; 349, identifier:self; 350, identifier:data_length; 351, return_statement; 351, 352; 352, identifier:overflowed | def _add_child(self, child, logical_block_size, allow_duplicate, check_overflow):
'''
An internal method to add a child to this object. Note that this is called both
during parsing and when adding a new object to the system, so it
it shouldn't have any functionality that is not appropriate for both.
Parameters:
child - The child directory record object to add.
logical_block_size - The size of a logical block for this volume descriptor.
allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed.
check_overflow - Whether to check for overflow; if we are parsing, we don't want to do this.
Returns:
True if adding this child caused the directory to overflow into another
extent, False otherwise.
'''
if not self.isdir:
raise pycdlibexception.PyCdlibInvalidInput('Trying to add a child to a record that is not a directory')
index = bisect.bisect_left(self.children, child)
if index != len(self.children) and self.children[index].file_ident == child.file_ident:
if not self.children[index].is_associated_file() and not child.is_associated_file():
if not (self.rock_ridge is not None and self.file_identifier() == b'RR_MOVED'):
if not allow_duplicate:
raise pycdlibexception.PyCdlibInvalidInput('Failed adding duplicate name to parent')
else:
self.children[index].data_continuation = child
index += 1
self.children.insert(index, child)
if child.rock_ridge is not None and not child.is_dot() and not child.is_dotdot():
lo = 0
hi = len(self.rr_children)
while lo < hi:
mid = (lo + hi) // 2
rr = self.rr_children[mid].rock_ridge
if rr is not None:
if rr.name() < child.rock_ridge.name():
lo = mid + 1
else:
hi = mid
else:
raise pycdlibexception.PyCdlibInternalError('Expected all children to have Rock Ridge, but one did not')
rr_index = lo
self.rr_children.insert(rr_index, child)
num_extents, offset_unused = self._recalculate_extents_and_offsets(index,
logical_block_size)
overflowed = False
if check_overflow and (num_extents * logical_block_size > self.data_length):
overflowed = True
self.data_length += logical_block_size
self.children[0].data_length = self.data_length
if self.parent is None:
self.children[1].data_length = self.data_length
for c in self.children:
if not c.is_dir():
continue
if len(c.children) > 1:
c.children[1].data_length = self.data_length
return overflowed |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:remove_child; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:child; 6, identifier:index; 7, identifier:logical_block_size; 8, block; 8, 9; 8, 11; 8, 24; 8, 36; 8, 168; 8, 174; 8, 186; 8, 190; 8, 201; 8, 289; 9, expression_statement; 9, 10; 10, string:'''
A method to remove a child from this Directory Record.
Parameters:
child - The child DirectoryRecord object to remove.
index - The index of the child into this DirectoryRecord children list.
logical_block_size - The size of a logical block on this volume descriptor.
Returns:
True if removing this child caused an underflow, False otherwise.
'''; 11, if_statement; 11, 12; 11, 16; 12, not_operator; 12, 13; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_initialized; 16, block; 16, 17; 17, raise_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:pycdlibexception; 21, identifier:PyCdlibInternalError; 22, argument_list; 22, 23; 23, string:'Directory Record not yet initialized'; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:<; 25, 26; 25, 27; 26, identifier:index; 27, integer:0; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:pycdlibexception; 33, identifier:PyCdlibInternalError; 34, argument_list; 34, 35; 35, string:'Invalid child index to remove'; 36, if_statement; 36, 37; 36, 42; 37, comparison_operator:is; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:child; 40, identifier:rock_ridge; 41, None; 42, block; 42, 43; 43, if_statement; 43, 44; 43, 55; 44, boolean_operator:or; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:child; 47, identifier:isdir; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:child; 52, identifier:rock_ridge; 53, identifier:child_link_record_exists; 54, argument_list; 55, block; 55, 56; 55, 73; 55, 101; 56, if_statement; 56, 57; 56, 65; 57, comparison_operator:<; 57, 58; 57, 64; 58, call; 58, 59; 58, 60; 59, identifier:len; 60, argument_list; 60, 61; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:children; 64, integer:2; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:pycdlibexception; 70, identifier:PyCdlibInvalidISO; 71, argument_list; 71, 72; 72, string:'Expected a dot and dotdot entry, but missing; ISO is corrupt'; 73, if_statement; 73, 74; 73, 93; 74, boolean_operator:or; 74, 75; 74, 84; 75, comparison_operator:is; 75, 76; 75, 83; 76, attribute; 76, 77; 76, 82; 77, subscript; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:children; 81, integer:0; 82, identifier:rock_ridge; 83, None; 84, comparison_operator:is; 84, 85; 84, 92; 85, attribute; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:children; 90, integer:1; 91, identifier:rock_ridge; 92, None; 93, block; 93, 94; 94, raise_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:pycdlibexception; 98, identifier:PyCdlibInvalidISO; 99, argument_list; 99, 100; 100, string:'Missing Rock Ridge entry on dot or dotdot; ISO is corrupt'; 101, if_statement; 101, 102; 101, 107; 101, 132; 102, comparison_operator:is; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:parent; 106, None; 107, block; 107, 108; 107, 120; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 119; 110, attribute; 110, 111; 110, 118; 111, attribute; 111, 112; 111, 117; 112, subscript; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:children; 116, integer:0; 117, identifier:rock_ridge; 118, identifier:remove_from_file_links; 119, argument_list; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 131; 122, attribute; 122, 123; 122, 130; 123, attribute; 123, 124; 123, 129; 124, subscript; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:children; 128, integer:1; 129, identifier:rock_ridge; 130, identifier:remove_from_file_links; 131, argument_list; 132, else_clause; 132, 133; 133, block; 133, 134; 133, 148; 133, 156; 134, if_statement; 134, 135; 134, 140; 135, comparison_operator:is; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:rock_ridge; 139, None; 140, block; 140, 141; 141, raise_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:pycdlibexception; 145, identifier:PyCdlibInvalidISO; 146, argument_list; 146, 147; 147, string:'Child has Rock Ridge, but parent does not; ISO is corrupt'; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:rock_ridge; 154, identifier:remove_from_file_links; 155, argument_list; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 167; 158, attribute; 158, 159; 158, 166; 159, attribute; 159, 160; 159, 165; 160, subscript; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:children; 164, integer:0; 165, identifier:rock_ridge; 166, identifier:remove_from_file_links; 167, argument_list; 168, delete_statement; 168, 169; 169, subscript; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:children; 173, identifier:index; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, pattern_list; 176, 177; 176, 178; 177, identifier:num_extents; 178, identifier:dirrecord_offset; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:_recalculate_extents_and_offsets; 183, argument_list; 183, 184; 183, 185; 184, identifier:index; 185, identifier:logical_block_size; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:underflow; 189, False; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:total_size; 193, binary_operator:+; 193, 194; 193, 200; 194, binary_operator:*; 194, 195; 194, 199; 195, parenthesized_expression; 195, 196; 196, binary_operator:-; 196, 197; 196, 198; 197, identifier:num_extents; 198, integer:1; 199, identifier:logical_block_size; 200, identifier:dirrecord_offset; 201, if_statement; 201, 202; 201, 210; 202, comparison_operator:>; 202, 203; 202, 209; 203, parenthesized_expression; 203, 204; 204, binary_operator:-; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:data_length; 208, identifier:total_size; 209, identifier:logical_block_size; 210, block; 210, 211; 210, 217; 210, 229; 210, 248; 210, 285; 211, expression_statement; 211, 212; 212, augmented_assignment:-=; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:data_length; 216, identifier:logical_block_size; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 226; 219, attribute; 219, 220; 219, 225; 220, subscript; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:children; 224, integer:0; 225, identifier:data_length; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:data_length; 229, if_statement; 229, 230; 229, 235; 230, comparison_operator:is; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:parent; 234, None; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 245; 238, attribute; 238, 239; 238, 244; 239, subscript; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:children; 243, integer:1; 244, identifier:data_length; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:data_length; 248, for_statement; 248, 249; 248, 250; 248, 253; 249, identifier:c; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:children; 253, block; 253, 254; 253, 263; 254, if_statement; 254, 255; 254, 261; 255, not_operator; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:c; 259, identifier:is_dir; 260, argument_list; 261, block; 261, 262; 262, continue_statement; 263, if_statement; 263, 264; 263, 272; 264, comparison_operator:>; 264, 265; 264, 271; 265, call; 265, 266; 265, 267; 266, identifier:len; 267, argument_list; 267, 268; 268, attribute; 268, 269; 268, 270; 269, identifier:c; 270, identifier:children; 271, integer:1; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 282; 275, attribute; 275, 276; 275, 281; 276, subscript; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:c; 279, identifier:children; 280, integer:1; 281, identifier:data_length; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:data_length; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:underflow; 288, True; 289, return_statement; 289, 290; 290, identifier:underflow | def remove_child(self, child, index, logical_block_size):
'''
A method to remove a child from this Directory Record.
Parameters:
child - The child DirectoryRecord object to remove.
index - The index of the child into this DirectoryRecord children list.
logical_block_size - The size of a logical block on this volume descriptor.
Returns:
True if removing this child caused an underflow, False otherwise.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
if index < 0:
raise pycdlibexception.PyCdlibInternalError('Invalid child index to remove')
if child.rock_ridge is not None:
if child.isdir or child.rock_ridge.child_link_record_exists():
if len(self.children) < 2:
raise pycdlibexception.PyCdlibInvalidISO('Expected a dot and dotdot entry, but missing; ISO is corrupt')
if self.children[0].rock_ridge is None or self.children[1].rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidISO('Missing Rock Ridge entry on dot or dotdot; ISO is corrupt')
if self.parent is None:
self.children[0].rock_ridge.remove_from_file_links()
self.children[1].rock_ridge.remove_from_file_links()
else:
if self.rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidISO('Child has Rock Ridge, but parent does not; ISO is corrupt')
self.rock_ridge.remove_from_file_links()
self.children[0].rock_ridge.remove_from_file_links()
del self.children[index]
num_extents, dirrecord_offset = self._recalculate_extents_and_offsets(index,
logical_block_size)
underflow = False
total_size = (num_extents - 1) * logical_block_size + dirrecord_offset
if (self.data_length - total_size) > logical_block_size:
self.data_length -= logical_block_size
self.children[0].data_length = self.data_length
if self.parent is None:
self.children[1].data_length = self.data_length
for c in self.children:
if not c.is_dir():
continue
if len(c.children) > 1:
c.children[1].data_length = self.data_length
underflow = True
return underflow |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_record; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:entries; 6, block; 6, 7; 6, 9; 6, 13; 6, 33; 6, 53; 6, 70; 6, 93; 6, 110; 6, 130; 6, 150; 6, 170; 6, 190; 6, 207; 6, 227; 6, 247; 6, 264; 6, 284; 6, 304; 7, expression_statement; 7, 8; 8, string:'''
Return a string representing the Rock Ridge entry.
Parameters:
entries - The dr_entries or ce_entries to generate a record for.
Returns:
A string representing the Rock Ridge entry.
'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:outlist; 12, list:[]; 13, if_statement; 13, 14; 13, 19; 14, comparison_operator:is; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:entries; 17, identifier:sp_record; 18, None; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:outlist; 24, identifier:append; 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:entries; 30, identifier:sp_record; 31, identifier:record; 32, argument_list; 33, if_statement; 33, 34; 33, 39; 34, comparison_operator:is; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:entries; 37, identifier:rr_record; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:outlist; 44, identifier:append; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:entries; 50, identifier:rr_record; 51, identifier:record; 52, argument_list; 53, for_statement; 53, 54; 53, 55; 53, 58; 54, identifier:nm_record; 55, attribute; 55, 56; 55, 57; 56, identifier:entries; 57, identifier:nm_records; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:outlist; 63, identifier:append; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:nm_record; 68, identifier:record; 69, argument_list; 70, if_statement; 70, 71; 70, 76; 71, comparison_operator:is; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:entries; 74, identifier:px_record; 75, None; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:outlist; 81, identifier:append; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:entries; 87, identifier:px_record; 88, identifier:record; 89, argument_list; 89, 90; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:rr_version; 93, for_statement; 93, 94; 93, 95; 93, 98; 94, identifier:sl_record; 95, attribute; 95, 96; 95, 97; 96, identifier:entries; 97, identifier:sl_records; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:outlist; 103, identifier:append; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:sl_record; 108, identifier:record; 109, argument_list; 110, if_statement; 110, 111; 110, 116; 111, comparison_operator:is; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:entries; 114, identifier:tf_record; 115, None; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:outlist; 121, identifier:append; 122, argument_list; 122, 123; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:entries; 127, identifier:tf_record; 128, identifier:record; 129, argument_list; 130, if_statement; 130, 131; 130, 136; 131, comparison_operator:is; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:entries; 134, identifier:cl_record; 135, None; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:outlist; 141, identifier:append; 142, argument_list; 142, 143; 143, call; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:entries; 147, identifier:cl_record; 148, identifier:record; 149, argument_list; 150, if_statement; 150, 151; 150, 156; 151, comparison_operator:is; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:entries; 154, identifier:pl_record; 155, None; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:outlist; 161, identifier:append; 162, argument_list; 162, 163; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:entries; 167, identifier:pl_record; 168, identifier:record; 169, argument_list; 170, if_statement; 170, 171; 170, 176; 171, comparison_operator:is; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:entries; 174, identifier:re_record; 175, None; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:outlist; 181, identifier:append; 182, argument_list; 182, 183; 183, call; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:entries; 187, identifier:re_record; 188, identifier:record; 189, argument_list; 190, for_statement; 190, 191; 190, 192; 190, 195; 191, identifier:es_record; 192, attribute; 192, 193; 192, 194; 193, identifier:entries; 194, identifier:es_records; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:outlist; 200, identifier:append; 201, argument_list; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:es_record; 205, identifier:record; 206, argument_list; 207, if_statement; 207, 208; 207, 213; 208, comparison_operator:is; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:entries; 211, identifier:er_record; 212, None; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:outlist; 218, identifier:append; 219, argument_list; 219, 220; 220, call; 220, 221; 220, 226; 221, attribute; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:entries; 224, identifier:er_record; 225, identifier:record; 226, argument_list; 227, if_statement; 227, 228; 227, 233; 228, comparison_operator:is; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:entries; 231, identifier:ce_record; 232, None; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:outlist; 238, identifier:append; 239, argument_list; 239, 240; 240, call; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:entries; 244, identifier:ce_record; 245, identifier:record; 246, argument_list; 247, for_statement; 247, 248; 247, 249; 247, 252; 248, identifier:pd_record; 249, attribute; 249, 250; 249, 251; 250, identifier:entries; 251, identifier:pd_records; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:outlist; 257, identifier:append; 258, argument_list; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:pd_record; 262, identifier:record; 263, argument_list; 264, if_statement; 264, 265; 264, 270; 265, comparison_operator:is; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:entries; 268, identifier:st_record; 269, None; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:outlist; 275, identifier:append; 276, argument_list; 276, 277; 277, call; 277, 278; 277, 283; 278, attribute; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:entries; 281, identifier:st_record; 282, identifier:record; 283, argument_list; 284, if_statement; 284, 285; 284, 290; 285, comparison_operator:is; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:entries; 288, identifier:sf_record; 289, None; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:outlist; 295, identifier:append; 296, argument_list; 296, 297; 297, call; 297, 298; 297, 303; 298, attribute; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:entries; 301, identifier:sf_record; 302, identifier:record; 303, argument_list; 304, return_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, string:b''; 308, identifier:join; 309, argument_list; 309, 310; 310, identifier:outlist | def _record(self, entries):
'''
Return a string representing the Rock Ridge entry.
Parameters:
entries - The dr_entries or ce_entries to generate a record for.
Returns:
A string representing the Rock Ridge entry.
'''
outlist = []
if entries.sp_record is not None:
outlist.append(entries.sp_record.record())
if entries.rr_record is not None:
outlist.append(entries.rr_record.record())
for nm_record in entries.nm_records:
outlist.append(nm_record.record())
if entries.px_record is not None:
outlist.append(entries.px_record.record(self.rr_version))
for sl_record in entries.sl_records:
outlist.append(sl_record.record())
if entries.tf_record is not None:
outlist.append(entries.tf_record.record())
if entries.cl_record is not None:
outlist.append(entries.cl_record.record())
if entries.pl_record is not None:
outlist.append(entries.pl_record.record())
if entries.re_record is not None:
outlist.append(entries.re_record.record())
for es_record in entries.es_records:
outlist.append(es_record.record())
if entries.er_record is not None:
outlist.append(entries.er_record.record())
if entries.ce_record is not None:
outlist.append(entries.ce_record.record())
for pd_record in entries.pd_records:
outlist.append(pd_record.record())
if entries.st_record is not None:
outlist.append(entries.st_record.record())
if entries.sf_record is not None:
outlist.append(entries.sf_record.record())
return b''.join(outlist) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_add_name; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:rr_name; 6, identifier:curr_dr_len; 7, block; 7, 8; 7, 10; 7, 18; 7, 44; 7, 50; 7, 61; 7, 72; 7, 85; 7, 89; 7, 185; 8, expression_statement; 8, 9; 9, string:'''
An internal method to add the appropriate name records to the ISO.
Parameters:
rr_name - The Rock Ridge name to add to the ISO.
curr_dr_len - The current directory record length.
Returns:
The new directory record length.
'''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:len_here; 13, binary_operator:-; 13, 14; 13, 17; 14, binary_operator:-; 14, 15; 14, 16; 15, identifier:ALLOWED_DR_SIZE; 16, identifier:curr_dr_len; 17, integer:5; 18, if_statement; 18, 19; 18, 25; 19, comparison_operator:<; 19, 20; 19, 21; 20, identifier:len_here; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:rr_name; 25, block; 25, 26; 25, 36; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:curr_dr_len; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_add_ce_record; 33, argument_list; 33, 34; 33, 35; 34, identifier:curr_dr_len; 35, integer:0; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:len_here; 39, binary_operator:-; 39, 40; 39, 43; 40, binary_operator:-; 40, 41; 40, 42; 41, identifier:ALLOWED_DR_SIZE; 42, identifier:curr_dr_len; 43, integer:5; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:curr_nm; 47, call; 47, 48; 47, 49; 48, identifier:RRNMRecord; 49, argument_list; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:curr_nm; 54, identifier:new; 55, argument_list; 55, 56; 56, subscript; 56, 57; 56, 58; 57, identifier:rr_name; 58, slice; 58, 59; 58, 60; 59, colon; 60, identifier:len_here; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 70; 63, attribute; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:dr_entries; 68, identifier:nm_records; 69, identifier:append; 70, argument_list; 70, 71; 71, identifier:curr_nm; 72, expression_statement; 72, 73; 73, augmented_assignment:+=; 73, 74; 73, 75; 74, identifier:curr_dr_len; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:RRNMRecord; 78, identifier:length; 79, argument_list; 79, 80; 80, subscript; 80, 81; 80, 82; 81, identifier:rr_name; 82, slice; 82, 83; 82, 84; 83, colon; 84, identifier:len_here; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:offset; 88, identifier:len_here; 89, while_statement; 89, 90; 89, 96; 90, comparison_operator:<; 90, 91; 90, 92; 91, identifier:offset; 92, call; 92, 93; 92, 94; 93, identifier:len; 94, argument_list; 94, 95; 95, identifier:rr_name; 96, block; 96, 97; 96, 103; 96, 118; 96, 124; 96, 138; 96, 149; 96, 181; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:curr_nm; 101, identifier:set_continued; 102, argument_list; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:length; 106, call; 106, 107; 106, 108; 107, identifier:min; 108, argument_list; 108, 109; 108, 117; 109, call; 109, 110; 109, 111; 110, identifier:len; 111, argument_list; 111, 112; 112, subscript; 112, 113; 112, 114; 113, identifier:rr_name; 114, slice; 114, 115; 114, 116; 115, identifier:offset; 116, colon; 117, integer:250; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:curr_nm; 121, call; 121, 122; 121, 123; 122, identifier:RRNMRecord; 123, argument_list; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:curr_nm; 128, identifier:new; 129, argument_list; 129, 130; 130, subscript; 130, 131; 130, 132; 131, identifier:rr_name; 132, slice; 132, 133; 132, 134; 132, 135; 133, identifier:offset; 134, colon; 135, binary_operator:+; 135, 136; 135, 137; 136, identifier:offset; 137, identifier:length; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 147; 140, attribute; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:ce_entries; 145, identifier:nm_records; 146, identifier:append; 147, argument_list; 147, 148; 148, identifier:curr_nm; 149, if_statement; 149, 150; 149, 157; 150, comparison_operator:is; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:dr_entries; 155, identifier:ce_record; 156, None; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 167; 160, attribute; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:dr_entries; 165, identifier:ce_record; 166, identifier:add_record; 167, argument_list; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:RRNMRecord; 171, identifier:length; 172, argument_list; 172, 173; 173, subscript; 173, 174; 173, 175; 174, identifier:rr_name; 175, slice; 175, 176; 175, 177; 175, 178; 176, identifier:offset; 177, colon; 178, binary_operator:+; 178, 179; 178, 180; 179, identifier:offset; 180, identifier:length; 181, expression_statement; 181, 182; 182, augmented_assignment:+=; 182, 183; 182, 184; 183, identifier:offset; 184, identifier:length; 185, return_statement; 185, 186; 186, identifier:curr_dr_len | def _add_name(self, rr_name, curr_dr_len):
'''
An internal method to add the appropriate name records to the ISO.
Parameters:
rr_name - The Rock Ridge name to add to the ISO.
curr_dr_len - The current directory record length.
Returns:
The new directory record length.
'''
len_here = ALLOWED_DR_SIZE - curr_dr_len - 5
if len_here < len(rr_name):
curr_dr_len = self._add_ce_record(curr_dr_len, 0)
len_here = ALLOWED_DR_SIZE - curr_dr_len - 5
curr_nm = RRNMRecord()
curr_nm.new(rr_name[:len_here])
self.dr_entries.nm_records.append(curr_nm)
curr_dr_len += RRNMRecord.length(rr_name[:len_here])
offset = len_here
while offset < len(rr_name):
curr_nm.set_continued()
length = min(len(rr_name[offset:]), 250)
curr_nm = RRNMRecord()
curr_nm.new(rr_name[offset:offset + length])
self.ce_entries.nm_records.append(curr_nm)
if self.dr_entries.ce_record is not None:
self.dr_entries.ce_record.add_record(RRNMRecord.length(rr_name[offset:offset + length]))
offset += length
return curr_dr_len |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:add_entry; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:length; 6, block; 6, 7; 6, 9; 6, 14; 6, 156; 6, 175; 7, expression_statement; 7, 8; 8, string:'''
Add a new entry to this Rock Ridge Continuation Block. This method
attempts to find a gap that fits the new length anywhere within this
Continuation Block. If successful, it returns the offset at which
it placed this entry. If unsuccessful, it returns None.
Parameters:
length - The length of the entry to find a gap for.
Returns:
The offset the entry was placed at, or None if no gap was found.
'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:offset; 12, unary_operator:-; 12, 13; 13, integer:1; 14, for_statement; 14, 15; 14, 18; 14, 24; 14, 94; 15, pattern_list; 15, 16; 15, 17; 16, identifier:index; 17, identifier:entry; 18, call; 18, 19; 18, 20; 19, identifier:enumerate; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_entries; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 29; 25, 48; 26, comparison_operator:==; 26, 27; 26, 28; 27, identifier:index; 28, integer:0; 29, block; 29, 30; 30, if_statement; 30, 31; 30, 42; 31, boolean_operator:and; 31, 32; 31, 37; 32, comparison_operator:!=; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:entry; 35, identifier:offset; 36, integer:0; 37, comparison_operator:<=; 37, 38; 37, 39; 38, identifier:length; 39, attribute; 39, 40; 39, 41; 40, identifier:entry; 41, identifier:offset; 42, block; 42, 43; 42, 47; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:offset; 46, integer:0; 47, break_statement; 48, else_clause; 48, 49; 49, block; 49, 50; 49, 60; 49, 72; 49, 82; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:lastentry; 53, subscript; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_entries; 57, binary_operator:-; 57, 58; 57, 59; 58, identifier:index; 59, integer:1; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:lastend; 63, binary_operator:-; 63, 64; 63, 71; 64, binary_operator:+; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:lastentry; 67, identifier:offset; 68, attribute; 68, 69; 68, 70; 69, identifier:lastentry; 70, identifier:length; 71, integer:1; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:gapsize; 75, binary_operator:-; 75, 76; 75, 81; 76, binary_operator:-; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:entry; 79, identifier:offset; 80, identifier:lastend; 81, integer:1; 82, if_statement; 82, 83; 82, 86; 83, comparison_operator:>=; 83, 84; 83, 85; 84, identifier:gapsize; 85, identifier:length; 86, block; 86, 87; 86, 93; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:offset; 90, binary_operator:+; 90, 91; 90, 92; 91, identifier:lastend; 92, integer:1; 93, break_statement; 94, else_clause; 94, 95; 95, block; 95, 96; 96, if_statement; 96, 97; 96, 100; 96, 143; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_entries; 100, block; 100, 101; 100, 110; 100, 122; 100, 132; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:lastentry; 104, subscript; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:_entries; 108, unary_operator:-; 108, 109; 109, integer:1; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:lastend; 113, binary_operator:-; 113, 114; 113, 121; 114, binary_operator:+; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:lastentry; 117, identifier:offset; 118, attribute; 118, 119; 118, 120; 119, identifier:lastentry; 120, identifier:length; 121, integer:1; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:left; 125, binary_operator:-; 125, 126; 125, 131; 126, binary_operator:-; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:_max_block_size; 130, identifier:lastend; 131, integer:1; 132, if_statement; 132, 133; 132, 136; 133, comparison_operator:>=; 133, 134; 133, 135; 134, identifier:left; 135, identifier:length; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:offset; 140, binary_operator:+; 140, 141; 140, 142; 141, identifier:lastend; 142, integer:1; 143, else_clause; 143, 144; 144, block; 144, 145; 145, if_statement; 145, 146; 145, 151; 146, comparison_operator:>=; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:_max_block_size; 150, identifier:length; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:offset; 155, integer:0; 156, if_statement; 156, 157; 156, 160; 157, comparison_operator:>=; 157, 158; 157, 159; 158, identifier:offset; 159, integer:0; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:bisect; 165, identifier:insort_left; 166, argument_list; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:_entries; 170, call; 170, 171; 170, 172; 171, identifier:RockRidgeContinuationEntry; 172, argument_list; 172, 173; 172, 174; 173, identifier:offset; 174, identifier:length; 175, return_statement; 175, 176; 176, identifier:offset | def add_entry(self, length):
'''
Add a new entry to this Rock Ridge Continuation Block. This method
attempts to find a gap that fits the new length anywhere within this
Continuation Block. If successful, it returns the offset at which
it placed this entry. If unsuccessful, it returns None.
Parameters:
length - The length of the entry to find a gap for.
Returns:
The offset the entry was placed at, or None if no gap was found.
'''
offset = -1
for index, entry in enumerate(self._entries):
if index == 0:
if entry.offset != 0 and length <= entry.offset:
offset = 0
break
else:
lastentry = self._entries[index - 1]
lastend = lastentry.offset + lastentry.length - 1
gapsize = entry.offset - lastend - 1
if gapsize >= length:
offset = lastend + 1
break
else:
if self._entries:
lastentry = self._entries[-1]
lastend = lastentry.offset + lastentry.length - 1
left = self._max_block_size - lastend - 1
if left >= length:
offset = lastend + 1
else:
if self._max_block_size >= length:
offset = 0
if offset >= 0:
bisect.insort_left(self._entries,
RockRidgeContinuationEntry(offset, length))
return offset |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:parse; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:data; 6, identifier:extent; 7, block; 7, 8; 7, 10; 7, 22; 7, 53; 7, 65; 7, 84; 7, 97; 7, 113; 7, 144; 7, 168; 8, expression_statement; 8, 9; 9, string:'''
Parse the passed in data into a UDF Descriptor tag.
Parameters:
data - The data to parse.
extent - The extent to compare against for the tag location.
Returns:
Nothing.
'''; 10, if_statement; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_initialized; 14, block; 14, 15; 15, raise_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:pycdlibexception; 19, identifier:PyCdlibInternalError; 20, argument_list; 20, 21; 21, string:'UDF Tag already initialized'; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 43; 24, tuple_pattern; 24, 25; 24, 28; 24, 31; 24, 32; 24, 33; 24, 36; 24, 37; 24, 40; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:tag_ident; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:desc_version; 31, identifier:tag_checksum; 32, identifier:reserved; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:tag_serial_number; 36, identifier:desc_crc; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:desc_crc_length; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:tag_location; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:struct; 46, identifier:unpack_from; 47, argument_list; 47, 48; 47, 51; 47, 52; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:FMT; 51, identifier:data; 52, integer:0; 53, if_statement; 53, 54; 53, 57; 54, comparison_operator:!=; 54, 55; 54, 56; 55, identifier:reserved; 56, integer:0; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:pycdlibexception; 62, identifier:PyCdlibInvalidISO; 63, argument_list; 63, 64; 64, string:'Reserved data not 0!'; 65, if_statement; 65, 66; 65, 76; 66, comparison_operator:!=; 66, 67; 66, 75; 67, call; 67, 68; 67, 69; 68, identifier:_compute_csum; 69, argument_list; 69, 70; 70, subscript; 70, 71; 70, 72; 71, identifier:data; 72, slice; 72, 73; 72, 74; 73, colon; 74, integer:16; 75, identifier:tag_checksum; 76, block; 76, 77; 77, raise_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:pycdlibexception; 81, identifier:PyCdlibInvalidISO; 82, argument_list; 82, 83; 83, string:'Tag checksum does not match!'; 84, if_statement; 84, 85; 84, 90; 85, comparison_operator:!=; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:tag_location; 89, identifier:extent; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:tag_location; 96, identifier:extent; 97, if_statement; 97, 98; 97, 105; 98, comparison_operator:not; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:desc_version; 102, tuple; 102, 103; 102, 104; 103, integer:2; 104, integer:3; 105, block; 105, 106; 106, raise_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:pycdlibexception; 110, identifier:PyCdlibInvalidISO; 111, argument_list; 111, 112; 112, string:'Tag version not 2 or 3'; 113, if_statement; 113, 114; 113, 125; 114, comparison_operator:<; 114, 115; 114, 122; 115, parenthesized_expression; 115, 116; 116, binary_operator:-; 116, 117; 116, 121; 117, call; 117, 118; 117, 119; 118, identifier:len; 119, argument_list; 119, 120; 120, identifier:data; 121, integer:16; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:desc_crc_length; 125, block; 125, 126; 126, raise_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:pycdlibexception; 130, identifier:PyCdlibInternalError; 131, argument_list; 131, 132; 132, binary_operator:%; 132, 133; 132, 134; 133, string:'Not enough CRC bytes to compute (expected at least %d, got %d)'; 134, tuple; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:desc_crc_length; 138, binary_operator:-; 138, 139; 138, 143; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, identifier:data; 143, integer:16; 144, if_statement; 144, 145; 144, 160; 145, comparison_operator:!=; 145, 146; 145, 147; 146, identifier:desc_crc; 147, call; 147, 148; 147, 149; 148, identifier:crc_ccitt; 149, argument_list; 149, 150; 150, subscript; 150, 151; 150, 152; 151, identifier:data; 152, slice; 152, 153; 152, 154; 152, 155; 153, integer:16; 154, colon; 155, binary_operator:+; 155, 156; 155, 157; 156, integer:16; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:desc_crc_length; 160, block; 160, 161; 161, raise_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:pycdlibexception; 165, identifier:PyCdlibInvalidISO; 166, argument_list; 166, 167; 167, string:'Tag CRC does not match!'; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:_initialized; 173, True | def parse(self, data, extent):
'''
Parse the passed in data into a UDF Descriptor tag.
Parameters:
data - The data to parse.
extent - The extent to compare against for the tag location.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('UDF Tag already initialized')
(self.tag_ident, self.desc_version, tag_checksum, reserved,
self.tag_serial_number, desc_crc, self.desc_crc_length,
self.tag_location) = struct.unpack_from(self.FMT, data, 0)
if reserved != 0:
raise pycdlibexception.PyCdlibInvalidISO('Reserved data not 0!')
if _compute_csum(data[:16]) != tag_checksum:
raise pycdlibexception.PyCdlibInvalidISO('Tag checksum does not match!')
if self.tag_location != extent:
self.tag_location = extent
if self.desc_version not in (2, 3):
raise pycdlibexception.PyCdlibInvalidISO('Tag version not 2 or 3')
if (len(data) - 16) < self.desc_crc_length:
raise pycdlibexception.PyCdlibInternalError('Not enough CRC bytes to compute (expected at least %d, got %d)' % (self.desc_crc_length, len(data) - 16))
if desc_crc != crc_ccitt(data[16:16 + self.desc_crc_length]):
raise pycdlibexception.PyCdlibInvalidISO('Tag CRC does not match!')
self._initialized = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parse; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:data; 6, block; 6, 7; 6, 9; 6, 21; 6, 63; 6, 71; 6, 104; 6, 122; 6, 151; 6, 171; 6, 191; 6, 211; 6, 231; 6, 251; 6, 271; 7, expression_statement; 7, 8; 8, string:'''
Parse the passed in data into a UDF Timestamp.
Parameters:
data - The data to parse.
Returns:
Nothing.
'''; 9, if_statement; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_initialized; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:pycdlibexception; 18, identifier:PyCdlibInternalError; 19, argument_list; 19, 20; 20, string:'UDF Timestamp already initialized'; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 53; 23, tuple_pattern; 23, 24; 23, 25; 23, 26; 23, 29; 23, 32; 23, 35; 23, 38; 23, 41; 23, 44; 23, 47; 23, 50; 24, identifier:tz; 25, identifier:timetype; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:year; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:month; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:day; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:hour; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:minute; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:second; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:centiseconds; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:hundreds_microseconds; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:microseconds; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:struct; 56, identifier:unpack_from; 57, argument_list; 57, 58; 57, 61; 57, 62; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:FMT; 61, identifier:data; 62, integer:0; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:timetype; 68, binary_operator:>>; 68, 69; 68, 70; 69, identifier:timetype; 70, integer:4; 71, function_definition; 71, 72; 71, 73; 71, 76; 72, function_name:twos_comp; 73, parameters; 73, 74; 73, 75; 74, identifier:val; 75, identifier:bits; 76, block; 76, 77; 76, 79; 76, 102; 77, expression_statement; 77, 78; 78, string:'''
Compute the 2's complement of int value val
'''; 79, if_statement; 79, 80; 79, 92; 80, comparison_operator:!=; 80, 81; 80, 91; 81, parenthesized_expression; 81, 82; 82, binary_operator:&; 82, 83; 82, 84; 83, identifier:val; 84, parenthesized_expression; 84, 85; 85, binary_operator:<<; 85, 86; 85, 87; 86, integer:1; 87, parenthesized_expression; 87, 88; 88, binary_operator:-; 88, 89; 88, 90; 89, identifier:bits; 90, integer:1; 91, integer:0; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:val; 96, binary_operator:-; 96, 97; 96, 98; 97, identifier:val; 98, parenthesized_expression; 98, 99; 99, binary_operator:<<; 99, 100; 99, 101; 100, integer:1; 101, identifier:bits; 102, return_statement; 102, 103; 103, identifier:val; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:tz; 109, call; 109, 110; 109, 111; 110, identifier:twos_comp; 111, argument_list; 111, 112; 111, 121; 112, binary_operator:|; 112, 113; 112, 120; 113, parenthesized_expression; 113, 114; 114, binary_operator:<<; 114, 115; 114, 119; 115, parenthesized_expression; 115, 116; 116, binary_operator:&; 116, 117; 116, 118; 117, identifier:timetype; 118, integer:0xf; 119, integer:8; 120, identifier:tz; 121, integer:12; 122, if_statement; 122, 123; 122, 135; 123, boolean_operator:or; 123, 124; 123, 130; 124, comparison_operator:<; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:tz; 128, unary_operator:-; 128, 129; 129, integer:1440; 130, comparison_operator:>; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:tz; 134, integer:1440; 135, block; 135, 136; 136, if_statement; 136, 137; 136, 143; 137, comparison_operator:!=; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:tz; 141, unary_operator:-; 141, 142; 142, integer:2047; 143, block; 143, 144; 144, raise_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:pycdlibexception; 148, identifier:PyCdlibInvalidISO; 149, argument_list; 149, 150; 150, string:'Invalid UDF timezone'; 151, if_statement; 151, 152; 151, 163; 152, boolean_operator:or; 152, 153; 152, 158; 153, comparison_operator:<; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:year; 157, integer:1; 158, comparison_operator:>; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:year; 162, integer:9999; 163, block; 163, 164; 164, raise_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:pycdlibexception; 168, identifier:PyCdlibInvalidISO; 169, argument_list; 169, 170; 170, string:'Invalid UDF year'; 171, if_statement; 171, 172; 171, 183; 172, boolean_operator:or; 172, 173; 172, 178; 173, comparison_operator:<; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:month; 177, integer:1; 178, comparison_operator:>; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:month; 182, integer:12; 183, block; 183, 184; 184, raise_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:pycdlibexception; 188, identifier:PyCdlibInvalidISO; 189, argument_list; 189, 190; 190, string:'Invalid UDF month'; 191, if_statement; 191, 192; 191, 203; 192, boolean_operator:or; 192, 193; 192, 198; 193, comparison_operator:<; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:day; 197, integer:1; 198, comparison_operator:>; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:day; 202, integer:31; 203, block; 203, 204; 204, raise_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:pycdlibexception; 208, identifier:PyCdlibInvalidISO; 209, argument_list; 209, 210; 210, string:'Invalid UDF day'; 211, if_statement; 211, 212; 211, 223; 212, boolean_operator:or; 212, 213; 212, 218; 213, comparison_operator:<; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:hour; 217, integer:0; 218, comparison_operator:>; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:hour; 222, integer:23; 223, block; 223, 224; 224, raise_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:pycdlibexception; 228, identifier:PyCdlibInvalidISO; 229, argument_list; 229, 230; 230, string:'Invalid UDF hour'; 231, if_statement; 231, 232; 231, 243; 232, boolean_operator:or; 232, 233; 232, 238; 233, comparison_operator:<; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:minute; 237, integer:0; 238, comparison_operator:>; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:minute; 242, integer:59; 243, block; 243, 244; 244, raise_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:pycdlibexception; 248, identifier:PyCdlibInvalidISO; 249, argument_list; 249, 250; 250, string:'Invalid UDF minute'; 251, if_statement; 251, 252; 251, 263; 252, boolean_operator:or; 252, 253; 252, 258; 253, comparison_operator:<; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:second; 257, integer:0; 258, comparison_operator:>; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:second; 262, integer:59; 263, block; 263, 264; 264, raise_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:pycdlibexception; 268, identifier:PyCdlibInvalidISO; 269, argument_list; 269, 270; 270, string:'Invalid UDF second'; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:self; 275, identifier:_initialized; 276, True | def parse(self, data):
'''
Parse the passed in data into a UDF Timestamp.
Parameters:
data - The data to parse.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('UDF Timestamp already initialized')
(tz, timetype, self.year, self.month, self.day, self.hour, self.minute,
self.second, self.centiseconds, self.hundreds_microseconds,
self.microseconds) = struct.unpack_from(self.FMT, data, 0)
self.timetype = timetype >> 4
def twos_comp(val, bits):
'''
Compute the 2's complement of int value val
'''
if (val & (1 << (bits - 1))) != 0:
val = val - (1 << bits)
return val
self.tz = twos_comp(((timetype & 0xf) << 8) | tz, 12)
if self.tz < -1440 or self.tz > 1440:
if self.tz != -2047:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF timezone')
if self.year < 1 or self.year > 9999:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF year')
if self.month < 1 or self.month > 12:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF month')
if self.day < 1 or self.day > 31:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF day')
if self.hour < 0 or self.hour > 23:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF hour')
if self.minute < 0 or self.minute > 59:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF minute')
if self.second < 0 or self.second > 59:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF second')
self._initialized = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parse; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:data; 6, block; 6, 7; 6, 9; 6, 21; 6, 45; 6, 57; 6, 69; 6, 81; 6, 93; 6, 105; 6, 117; 6, 129; 6, 141; 6, 153; 6, 165; 7, expression_statement; 7, 8; 8, string:'''
Parse the passed in data into a UDF Partition Header Descriptor.
Parameters:
data - The data to parse.
Returns:
Nothing.
'''; 9, if_statement; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_initialized; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:pycdlibexception; 18, identifier:PyCdlibInternalError; 19, argument_list; 19, 20; 20, string:'UDF Partition Header Descriptor already initialized'; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 35; 23, tuple_pattern; 23, 24; 23, 25; 23, 26; 23, 27; 23, 28; 23, 29; 23, 30; 23, 31; 23, 32; 23, 33; 23, 34; 24, identifier:unalloc_table_length; 25, identifier:unalloc_table_pos; 26, identifier:unalloc_bitmap_length; 27, identifier:unalloc_bitmap_pos; 28, identifier:part_integrity_table_length; 29, identifier:part_integrity_table_pos; 30, identifier:freed_table_length; 31, identifier:freed_table_pos; 32, identifier:freed_bitmap_length; 33, identifier:freed_bitmap_pos; 34, identifier:reserved_unused; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:struct; 38, identifier:unpack_from; 39, argument_list; 39, 40; 39, 43; 39, 44; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:FMT; 43, identifier:data; 44, integer:0; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:!=; 46, 47; 46, 48; 47, identifier:unalloc_table_length; 48, integer:0; 49, block; 49, 50; 50, raise_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:pycdlibexception; 54, identifier:PyCdlibInvalidISO; 55, argument_list; 55, 56; 56, string:'Partition Header unallocated table length not 0'; 57, if_statement; 57, 58; 57, 61; 58, comparison_operator:!=; 58, 59; 58, 60; 59, identifier:unalloc_table_pos; 60, integer:0; 61, block; 61, 62; 62, raise_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:pycdlibexception; 66, identifier:PyCdlibInvalidISO; 67, argument_list; 67, 68; 68, string:'Partition Header unallocated table position not 0'; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:!=; 70, 71; 70, 72; 71, identifier:unalloc_bitmap_length; 72, integer:0; 73, block; 73, 74; 74, raise_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:pycdlibexception; 78, identifier:PyCdlibInvalidISO; 79, argument_list; 79, 80; 80, string:'Partition Header unallocated bitmap length not 0'; 81, if_statement; 81, 82; 81, 85; 82, comparison_operator:!=; 82, 83; 82, 84; 83, identifier:unalloc_bitmap_pos; 84, integer:0; 85, block; 85, 86; 86, raise_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:pycdlibexception; 90, identifier:PyCdlibInvalidISO; 91, argument_list; 91, 92; 92, string:'Partition Header unallocated bitmap position not 0'; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:!=; 94, 95; 94, 96; 95, identifier:part_integrity_table_length; 96, integer:0; 97, block; 97, 98; 98, raise_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:pycdlibexception; 102, identifier:PyCdlibInvalidISO; 103, argument_list; 103, 104; 104, string:'Partition Header partition integrity length not 0'; 105, if_statement; 105, 106; 105, 109; 106, comparison_operator:!=; 106, 107; 106, 108; 107, identifier:part_integrity_table_pos; 108, integer:0; 109, block; 109, 110; 110, raise_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:pycdlibexception; 114, identifier:PyCdlibInvalidISO; 115, argument_list; 115, 116; 116, string:'Partition Header partition integrity position not 0'; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:!=; 118, 119; 118, 120; 119, identifier:freed_table_length; 120, integer:0; 121, block; 121, 122; 122, raise_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:pycdlibexception; 126, identifier:PyCdlibInvalidISO; 127, argument_list; 127, 128; 128, string:'Partition Header freed table length not 0'; 129, if_statement; 129, 130; 129, 133; 130, comparison_operator:!=; 130, 131; 130, 132; 131, identifier:freed_table_pos; 132, integer:0; 133, block; 133, 134; 134, raise_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:pycdlibexception; 138, identifier:PyCdlibInvalidISO; 139, argument_list; 139, 140; 140, string:'Partition Header freed table position not 0'; 141, if_statement; 141, 142; 141, 145; 142, comparison_operator:!=; 142, 143; 142, 144; 143, identifier:freed_bitmap_length; 144, integer:0; 145, block; 145, 146; 146, raise_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:pycdlibexception; 150, identifier:PyCdlibInvalidISO; 151, argument_list; 151, 152; 152, string:'Partition Header freed bitmap length not 0'; 153, if_statement; 153, 154; 153, 157; 154, comparison_operator:!=; 154, 155; 154, 156; 155, identifier:freed_bitmap_pos; 156, integer:0; 157, block; 157, 158; 158, raise_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:pycdlibexception; 162, identifier:PyCdlibInvalidISO; 163, argument_list; 163, 164; 164, string:'Partition Header freed bitmap position not 0'; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:_initialized; 170, True | def parse(self, data):
'''
Parse the passed in data into a UDF Partition Header Descriptor.
Parameters:
data - The data to parse.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('UDF Partition Header Descriptor already initialized')
(unalloc_table_length, unalloc_table_pos, unalloc_bitmap_length,
unalloc_bitmap_pos, part_integrity_table_length,
part_integrity_table_pos, freed_table_length, freed_table_pos,
freed_bitmap_length, freed_bitmap_pos,
reserved_unused) = struct.unpack_from(self.FMT, data, 0)
if unalloc_table_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header unallocated table length not 0')
if unalloc_table_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header unallocated table position not 0')
if unalloc_bitmap_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header unallocated bitmap length not 0')
if unalloc_bitmap_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header unallocated bitmap position not 0')
if part_integrity_table_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header partition integrity length not 0')
if part_integrity_table_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header partition integrity position not 0')
if freed_table_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header freed table length not 0')
if freed_table_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header freed table position not 0')
if freed_bitmap_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header freed bitmap length not 0')
if freed_bitmap_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header freed bitmap position not 0')
self._initialized = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:finish_directory_parse; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 6, expression_statement; 6, 7; 7, string:'''
A method to finish up the parsing of this UDF File Entry directory.
In particular, this method checks to see if it is in sorted order for
future use.
Parameters:
None.
Returns:
Nothing.
'''; 8, if_statement; 8, 9; 8, 13; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_initialized; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:pycdlibexception; 18, identifier:PyCdlibInternalError; 19, argument_list; 19, 20; 20, string:'UDF File Entry not initialized'; 21, if_statement; 21, 22; 21, 29; 22, comparison_operator:!=; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:icb_tag; 27, identifier:file_type; 28, integer:4; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:pycdlibexception; 34, identifier:PyCdlibInternalError; 35, argument_list; 35, 36; 36, string:'Can only finish_directory for a directory' | def finish_directory_parse(self):
'''
A method to finish up the parsing of this UDF File Entry directory.
In particular, this method checks to see if it is in sorted order for
future use.
Parameters:
None.
Returns:
Nothing.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('UDF File Entry not initialized')
if self.icb_tag.file_type != 4:
raise pycdlibexception.PyCdlibInternalError('Can only finish_directory for a directory') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parse; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:valstr; 6, block; 6, 7; 6, 9; 6, 21; 6, 302; 7, expression_statement; 7, 8; 8, string:'''
A method to parse an El Torito Boot Catalog out of a string.
Parameters:
valstr - The string to parse the El Torito Boot Catalog out of.
Returns:
Nothing.
'''; 9, if_statement; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_initialized; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:pycdlibexception; 18, identifier:PyCdlibInternalError; 19, argument_list; 19, 20; 20, string:'El Torito Boot Catalog already initialized'; 21, if_statement; 21, 22; 21, 29; 21, 47; 21, 73; 22, comparison_operator:==; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:state; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:EXPECTING_VALIDATION_ENTRY; 29, block; 29, 30; 29, 39; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:validation_entry; 36, identifier:parse; 37, argument_list; 37, 38; 38, identifier:valstr; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:state; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:EXPECTING_INITIAL_ENTRY; 47, elif_clause; 47, 48; 47, 55; 48, comparison_operator:==; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:state; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:EXPECTING_INITIAL_ENTRY; 55, block; 55, 56; 55, 65; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:initial_entry; 62, identifier:parse; 63, argument_list; 63, 64; 64, identifier:valstr; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:state; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:EXPECTING_SECTION_HEADER_OR_DONE; 73, else_clause; 73, 74; 74, block; 74, 75; 74, 88; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:val; 78, call; 78, 79; 78, 80; 79, identifier:bytes; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:bytearray; 83, argument_list; 83, 84; 84, list:[valstr[0]]; 84, 85; 85, subscript; 85, 86; 85, 87; 86, identifier:valstr; 87, integer:0; 88, if_statement; 88, 89; 88, 92; 88, 170; 88, 199; 88, 268; 88, 293; 89, comparison_operator:==; 89, 90; 89, 91; 90, identifier:val; 91, string:b'\x00'; 92, block; 92, 93; 92, 104; 92, 164; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:last_section_index; 96, binary_operator:-; 96, 97; 96, 103; 97, call; 97, 98; 97, 99; 98, identifier:len; 99, argument_list; 99, 100; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:sections; 103, integer:1; 104, for_statement; 104, 105; 104, 108; 104, 114; 105, pattern_list; 105, 106; 105, 107; 106, identifier:index; 107, identifier:sec; 108, call; 108, 109; 108, 110; 109, identifier:enumerate; 110, argument_list; 110, 111; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:sections; 114, block; 114, 115; 114, 145; 115, if_statement; 115, 116; 115, 126; 116, comparison_operator:!=; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:sec; 119, identifier:num_section_entries; 120, call; 120, 121; 120, 122; 121, identifier:len; 122, argument_list; 122, 123; 123, attribute; 123, 124; 123, 125; 124, identifier:sec; 125, identifier:section_entries; 126, block; 126, 127; 127, raise_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:pycdlibexception; 131, identifier:PyCdlibInvalidISO; 132, argument_list; 132, 133; 133, binary_operator:%; 133, 134; 133, 135; 134, string:'El Torito section header specified %d entries, only saw %d'; 135, tuple; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:sec; 138, identifier:num_section_entries; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, attribute; 142, 143; 142, 144; 143, identifier:sec; 144, identifier:section_entries; 145, if_statement; 145, 146; 145, 149; 146, comparison_operator:!=; 146, 147; 146, 148; 147, identifier:index; 148, identifier:last_section_index; 149, block; 149, 150; 150, if_statement; 150, 151; 150, 156; 151, comparison_operator:!=; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:sec; 154, identifier:header_indicator; 155, integer:0x90; 156, block; 156, 157; 157, raise_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:pycdlibexception; 161, identifier:PyCdlibInvalidISO; 162, argument_list; 162, 163; 163, string:'Intermediate El Torito section header not properly specified'; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:_initialized; 169, True; 170, elif_clause; 170, 171; 170, 176; 171, comparison_operator:in; 171, 172; 171, 173; 172, identifier:val; 173, tuple; 173, 174; 173, 175; 174, string:b'\x90'; 175, string:b'\x91'; 176, block; 176, 177; 176, 183; 176, 190; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:section_header; 180, call; 180, 181; 180, 182; 181, identifier:EltoritoSectionHeader; 182, argument_list; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:section_header; 187, identifier:parse; 188, argument_list; 188, 189; 189, identifier:valstr; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 197; 192, attribute; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:sections; 196, identifier:append; 197, argument_list; 197, 198; 198, identifier:section_header; 199, elif_clause; 199, 200; 199, 205; 200, comparison_operator:in; 200, 201; 200, 202; 201, identifier:val; 202, tuple; 202, 203; 202, 204; 203, string:b'\x88'; 204, string:b'\x00'; 205, block; 205, 206; 205, 212; 205, 219; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:secentry; 209, call; 209, 210; 209, 211; 210, identifier:EltoritoEntry; 211, argument_list; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:secentry; 216, identifier:parse; 217, argument_list; 217, 218; 218, identifier:valstr; 219, if_statement; 219, 220; 219, 244; 219, 257; 220, boolean_operator:and; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:sections; 224, comparison_operator:<; 224, 225; 224, 236; 225, call; 225, 226; 225, 227; 226, identifier:len; 227, argument_list; 227, 228; 228, attribute; 228, 229; 228, 235; 229, subscript; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:sections; 233, unary_operator:-; 233, 234; 234, integer:1; 235, identifier:section_entries; 236, attribute; 236, 237; 236, 243; 237, subscript; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:sections; 241, unary_operator:-; 241, 242; 242, integer:1; 243, identifier:num_section_entries; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 255; 247, attribute; 247, 248; 247, 254; 248, subscript; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:sections; 252, unary_operator:-; 252, 253; 253, integer:1; 254, identifier:add_parsed_entry; 255, argument_list; 255, 256; 256, identifier:secentry; 257, else_clause; 257, 258; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:standalone_entries; 265, identifier:append; 266, argument_list; 266, 267; 267, identifier:secentry; 268, elif_clause; 268, 269; 268, 272; 269, comparison_operator:==; 269, 270; 269, 271; 270, identifier:val; 271, string:b'\x44'; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, augmented_assignment:+=; 274, 275; 274, 288; 275, attribute; 275, 276; 275, 287; 276, subscript; 276, 277; 276, 285; 277, attribute; 277, 278; 277, 284; 278, subscript; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:sections; 282, unary_operator:-; 282, 283; 283, integer:1; 284, identifier:section_entries; 285, unary_operator:-; 285, 286; 286, integer:1; 287, identifier:selection_criteria; 288, subscript; 288, 289; 288, 290; 289, identifier:valstr; 290, slice; 290, 291; 290, 292; 291, integer:2; 292, colon; 293, else_clause; 293, 294; 294, block; 294, 295; 295, raise_statement; 295, 296; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:pycdlibexception; 299, identifier:PyCdlibInvalidISO; 300, argument_list; 300, 301; 301, string:'Invalid El Torito Boot Catalog entry'; 302, return_statement; 302, 303; 303, attribute; 303, 304; 303, 305; 304, identifier:self; 305, identifier:_initialized | def parse(self, valstr):
'''
A method to parse an El Torito Boot Catalog out of a string.
Parameters:
valstr - The string to parse the El Torito Boot Catalog out of.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog already initialized')
if self.state == self.EXPECTING_VALIDATION_ENTRY:
self.validation_entry.parse(valstr)
self.state = self.EXPECTING_INITIAL_ENTRY
elif self.state == self.EXPECTING_INITIAL_ENTRY:
self.initial_entry.parse(valstr)
self.state = self.EXPECTING_SECTION_HEADER_OR_DONE
else:
val = bytes(bytearray([valstr[0]]))
if val == b'\x00':
last_section_index = len(self.sections) - 1
for index, sec in enumerate(self.sections):
if sec.num_section_entries != len(sec.section_entries):
raise pycdlibexception.PyCdlibInvalidISO('El Torito section header specified %d entries, only saw %d' % (sec.num_section_entries, len(sec.section_entries)))
if index != last_section_index:
if sec.header_indicator != 0x90:
raise pycdlibexception.PyCdlibInvalidISO('Intermediate El Torito section header not properly specified')
self._initialized = True
elif val in (b'\x90', b'\x91'):
section_header = EltoritoSectionHeader()
section_header.parse(valstr)
self.sections.append(section_header)
elif val in (b'\x88', b'\x00'):
secentry = EltoritoEntry()
secentry.parse(valstr)
if self.sections and len(self.sections[-1].section_entries) < self.sections[-1].num_section_entries:
self.sections[-1].add_parsed_entry(secentry)
else:
self.standalone_entries.append(secentry)
elif val == b'\x44':
self.sections[-1].section_entries[-1].selection_criteria += valstr[2:]
else:
raise pycdlibexception.PyCdlibInvalidISO('Invalid El Torito Boot Catalog entry')
return self._initialized |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_check_iso9660_filename; 3, parameters; 3, 4; 3, 5; 4, identifier:fullname; 5, identifier:interchange_level; 6, block; 6, 7; 6, 9; 6, 19; 6, 46; 6, 60; 6, 76; 6, 106; 7, expression_statement; 7, 8; 8, string:'''
A function to check that a file identifier conforms to the ISO9660 rules
for a particular interchange level.
Parameters:
fullname - The name to check.
interchange_level - The interchange level to check against.
Returns:
Nothing.
'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 15; 11, tuple_pattern; 11, 12; 11, 13; 11, 14; 12, identifier:name; 13, identifier:extension; 14, identifier:version; 15, call; 15, 16; 15, 17; 16, identifier:_split_iso9660_filename; 17, argument_list; 17, 18; 18, identifier:fullname; 19, if_statement; 19, 20; 19, 38; 20, boolean_operator:and; 20, 21; 20, 24; 21, comparison_operator:!=; 21, 22; 21, 23; 22, identifier:version; 23, string:b''; 24, parenthesized_expression; 24, 25; 25, boolean_operator:or; 25, 26; 25, 32; 26, comparison_operator:<; 26, 27; 26, 31; 27, call; 27, 28; 27, 29; 28, identifier:int; 29, argument_list; 29, 30; 30, identifier:version; 31, integer:1; 32, comparison_operator:>; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:int; 35, argument_list; 35, 36; 36, identifier:version; 37, integer:32767; 38, block; 38, 39; 39, raise_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:pycdlibexception; 43, identifier:PyCdlibInvalidInput; 44, argument_list; 44, 45; 45, string:'ISO9660 filenames must have a version between 1 and 32767'; 46, if_statement; 46, 47; 46, 52; 47, boolean_operator:and; 47, 48; 47, 50; 48, not_operator; 48, 49; 49, identifier:name; 50, not_operator; 50, 51; 51, identifier:extension; 52, block; 52, 53; 53, raise_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:pycdlibexception; 57, identifier:PyCdlibInvalidInput; 58, argument_list; 58, 59; 59, string:'ISO9660 filenames must have a non-empty name or extension'; 60, if_statement; 60, 61; 60, 68; 61, boolean_operator:or; 61, 62; 61, 65; 62, comparison_operator:in; 62, 63; 62, 64; 63, string:b';'; 64, identifier:name; 65, comparison_operator:in; 65, 66; 65, 67; 66, string:b';'; 67, identifier:extension; 68, block; 68, 69; 69, raise_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:pycdlibexception; 73, identifier:PyCdlibInvalidInput; 74, argument_list; 74, 75; 75, string:'ISO9660 filenames must contain exactly one semicolon'; 76, if_statement; 76, 77; 76, 80; 76, 103; 77, comparison_operator:==; 77, 78; 77, 79; 78, identifier:interchange_level; 79, integer:1; 80, block; 80, 81; 81, if_statement; 81, 82; 81, 95; 82, boolean_operator:or; 82, 83; 82, 89; 83, comparison_operator:>; 83, 84; 83, 88; 84, call; 84, 85; 84, 86; 85, identifier:len; 86, argument_list; 86, 87; 87, identifier:name; 88, integer:8; 89, comparison_operator:>; 89, 90; 89, 94; 90, call; 90, 91; 90, 92; 91, identifier:len; 92, argument_list; 92, 93; 93, identifier:extension; 94, integer:3; 95, block; 95, 96; 96, raise_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:pycdlibexception; 100, identifier:PyCdlibInvalidInput; 101, argument_list; 101, 102; 102, string:'ISO9660 filenames at interchange level 1 cannot have more than 8 characters or 3 characters in the extension'; 103, else_clause; 103, 104; 104, block; 104, 105; 105, pass_statement; 106, if_statement; 106, 107; 106, 110; 107, comparison_operator:<; 107, 108; 107, 109; 108, identifier:interchange_level; 109, integer:4; 110, block; 110, 111; 110, 116; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:_check_d1_characters; 114, argument_list; 114, 115; 115, identifier:name; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:_check_d1_characters; 119, argument_list; 119, 120; 120, identifier:extension | def _check_iso9660_filename(fullname, interchange_level):
'''
A function to check that a file identifier conforms to the ISO9660 rules
for a particular interchange level.
Parameters:
fullname - The name to check.
interchange_level - The interchange level to check against.
Returns:
Nothing.
'''
(name, extension, version) = _split_iso9660_filename(fullname)
if version != b'' and (int(version) < 1 or int(version) > 32767):
raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames must have a version between 1 and 32767')
if not name and not extension:
raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames must have a non-empty name or extension')
if b';' in name or b';' in extension:
raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames must contain exactly one semicolon')
if interchange_level == 1:
if len(name) > 8 or len(extension) > 3:
raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames at interchange level 1 cannot have more than 8 characters or 3 characters in the extension')
else:
pass
if interchange_level < 4:
_check_d1_characters(name)
_check_d1_characters(extension) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_yield_children; 3, parameters; 3, 4; 4, identifier:rec; 5, block; 5, 6; 5, 8; 5, 23; 5, 27; 6, expression_statement; 6, 7; 7, string:'''
An internal function to gather and yield all of the children of a Directory
Record.
Parameters:
rec - The Directory Record to get all of the children from (must be a
directory)
Yields:
Children of this Directory Record.
Returns:
Nothing.
'''; 8, if_statement; 8, 9; 8, 15; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:rec; 13, identifier:is_dir; 14, argument_list; 15, block; 15, 16; 16, raise_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:pycdlibexception; 20, identifier:PyCdlibInvalidInput; 21, argument_list; 21, 22; 22, string:'Record is not a directory!'; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:last; 26, string:b''; 27, for_statement; 27, 28; 27, 29; 27, 32; 28, identifier:child; 29, attribute; 29, 30; 29, 31; 30, identifier:rec; 31, identifier:children; 32, block; 32, 33; 32, 41; 32, 47; 32, 51; 32, 128; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:fi; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:child; 39, identifier:file_identifier; 40, argument_list; 41, if_statement; 41, 42; 41, 45; 42, comparison_operator:==; 42, 43; 42, 44; 43, identifier:fi; 44, identifier:last; 45, block; 45, 46; 46, continue_statement; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:last; 50, identifier:fi; 51, if_statement; 51, 52; 51, 83; 52, boolean_operator:and; 52, 53; 52, 74; 53, boolean_operator:and; 53, 54; 53, 67; 54, boolean_operator:and; 54, 55; 54, 60; 55, comparison_operator:is; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:child; 58, identifier:rock_ridge; 59, None; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:child; 64, identifier:rock_ridge; 65, identifier:child_link_record_exists; 66, argument_list; 67, comparison_operator:is; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:child; 71, identifier:rock_ridge; 72, identifier:cl_to_moved_dr; 73, None; 74, comparison_operator:is; 74, 75; 74, 82; 75, attribute; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:child; 79, identifier:rock_ridge; 80, identifier:cl_to_moved_dr; 81, identifier:parent; 82, None; 83, block; 83, 84; 83, 94; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:cl_parent; 87, attribute; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:child; 91, identifier:rock_ridge; 92, identifier:cl_to_moved_dr; 93, identifier:parent; 94, for_statement; 94, 95; 94, 96; 94, 99; 95, identifier:cl_child; 96, attribute; 96, 97; 96, 98; 97, identifier:cl_parent; 98, identifier:children; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 122; 101, boolean_operator:and; 101, 102; 101, 107; 102, comparison_operator:is; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:cl_child; 105, identifier:rock_ridge; 106, None; 107, comparison_operator:==; 107, 108; 107, 115; 108, call; 108, 109; 108, 114; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:cl_child; 112, identifier:rock_ridge; 113, identifier:name; 114, argument_list; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:child; 119, identifier:rock_ridge; 120, identifier:name; 121, argument_list; 122, block; 122, 123; 122, 127; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:child; 126, identifier:cl_child; 127, break_statement; 128, expression_statement; 128, 129; 129, yield; 129, 130; 130, identifier:child | def _yield_children(rec):
'''
An internal function to gather and yield all of the children of a Directory
Record.
Parameters:
rec - The Directory Record to get all of the children from (must be a
directory)
Yields:
Children of this Directory Record.
Returns:
Nothing.
'''
if not rec.is_dir():
raise pycdlibexception.PyCdlibInvalidInput('Record is not a directory!')
last = b''
for child in rec.children:
fi = child.file_identifier()
if fi == last:
continue
last = fi
if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists() and child.rock_ridge.cl_to_moved_dr is not None and child.rock_ridge.cl_to_moved_dr.parent is not None:
cl_parent = child.rock_ridge.cl_to_moved_dr.parent
for cl_child in cl_parent.children:
if cl_child.rock_ridge is not None and cl_child.rock_ridge.name() == child.rock_ridge.name():
child = cl_child
break
yield child |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_find_dr_record_by_name; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:vd; 5, identifier:path; 6, identifier:encoding; 7, block; 7, 8; 7, 10; 7, 26; 7, 34; 7, 41; 7, 50; 7, 69; 7, 73; 7, 81; 7, 243; 8, expression_statement; 8, 9; 9, string:'''
An internal function to find an directory record on the ISO given an ISO
or Joliet path. If the entry is found, it returns the directory record
object corresponding to that entry. If the entry could not be found,
a pycdlibexception.PyCdlibInvalidInput exception is raised.
Parameters:
vd - The Volume Descriptor to look in for the Directory Record.
path - The ISO or Joliet entry to find the Directory Record for.
encoding - The string encoding used for the path.
Returns:
The directory record entry representing the entry on the ISO.
'''; 10, if_statement; 10, 11; 10, 18; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:utils; 15, identifier:starts_with_slash; 16, argument_list; 16, 17; 17, identifier:path; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:pycdlibexception; 23, identifier:PyCdlibInvalidInput; 24, argument_list; 24, 25; 25, string:'Must be a path starting with /'; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:root_dir_record; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:vd; 32, identifier:root_directory_record; 33, argument_list; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:==; 35, 36; 35, 37; 36, identifier:path; 37, string:b'/'; 38, block; 38, 39; 39, return_statement; 39, 40; 40, identifier:root_dir_record; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:splitpath; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:utils; 47, identifier:split_path; 48, argument_list; 48, 49; 49, identifier:path; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:currpath; 53, call; 53, 54; 53, 67; 54, attribute; 54, 55; 54, 66; 55, call; 55, 56; 55, 64; 56, attribute; 56, 57; 56, 63; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:splitpath; 60, identifier:pop; 61, argument_list; 61, 62; 62, integer:0; 63, identifier:decode; 64, argument_list; 64, 65; 65, string:'utf-8'; 66, identifier:encode; 67, argument_list; 67, 68; 68, identifier:encoding; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:entry; 72, identifier:root_dir_record; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:tmpdr; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:dr; 79, identifier:DirectoryRecord; 80, argument_list; 81, while_statement; 81, 82; 81, 83; 82, True; 83, block; 83, 84; 83, 88; 83, 94; 83, 98; 83, 105; 83, 144; 83, 148; 83, 170; 83, 176; 83, 205; 83, 211; 83, 220; 83, 224; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:child; 87, None; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:thelist; 91, attribute; 91, 92; 91, 93; 92, identifier:entry; 93, identifier:children; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:lo; 97, integer:2; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:hi; 101, call; 101, 102; 101, 103; 102, identifier:len; 103, argument_list; 103, 104; 104, identifier:thelist; 105, while_statement; 105, 106; 105, 109; 106, comparison_operator:<; 106, 107; 106, 108; 107, identifier:lo; 108, identifier:hi; 109, block; 109, 110; 109, 119; 109, 125; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:mid; 113, binary_operator://; 113, 114; 113, 118; 114, parenthesized_expression; 114, 115; 115, binary_operator:+; 115, 116; 115, 117; 116, identifier:lo; 117, identifier:hi; 118, integer:2; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:tmpdr; 123, identifier:file_ident; 124, identifier:currpath; 125, if_statement; 125, 126; 125, 131; 125, 138; 126, comparison_operator:<; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:thelist; 129, identifier:mid; 130, identifier:tmpdr; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:lo; 135, binary_operator:+; 135, 136; 135, 137; 136, identifier:mid; 137, integer:1; 138, else_clause; 138, 139; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:hi; 143, identifier:mid; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:index; 147, identifier:lo; 148, if_statement; 148, 149; 148, 163; 149, boolean_operator:and; 149, 150; 149, 156; 150, comparison_operator:!=; 150, 151; 150, 152; 151, identifier:index; 152, call; 152, 153; 152, 154; 153, identifier:len; 154, argument_list; 154, 155; 155, identifier:thelist; 156, comparison_operator:==; 156, 157; 156, 162; 157, attribute; 157, 158; 157, 161; 158, subscript; 158, 159; 158, 160; 159, identifier:thelist; 160, identifier:index; 161, identifier:file_ident; 162, identifier:currpath; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:child; 167, subscript; 167, 168; 167, 169; 168, identifier:thelist; 169, identifier:index; 170, if_statement; 170, 171; 170, 174; 171, comparison_operator:is; 171, 172; 171, 173; 172, identifier:child; 173, None; 174, block; 174, 175; 175, break_statement; 176, if_statement; 176, 177; 176, 190; 177, boolean_operator:and; 177, 178; 177, 183; 178, comparison_operator:is; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:child; 181, identifier:rock_ridge; 182, None; 183, call; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:child; 187, identifier:rock_ridge; 188, identifier:child_link_record_exists; 189, argument_list; 190, block; 190, 191; 190, 199; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:child; 194, attribute; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:child; 197, identifier:rock_ridge; 198, identifier:cl_to_moved_dr; 199, if_statement; 199, 200; 199, 203; 200, comparison_operator:is; 200, 201; 200, 202; 201, identifier:child; 202, None; 203, block; 203, 204; 204, break_statement; 205, if_statement; 205, 206; 205, 208; 206, not_operator; 206, 207; 207, identifier:splitpath; 208, block; 208, 209; 209, return_statement; 209, 210; 210, identifier:child; 211, if_statement; 211, 212; 211, 218; 212, not_operator; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:child; 216, identifier:is_dir; 217, argument_list; 218, block; 218, 219; 219, break_statement; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:entry; 223, identifier:child; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:currpath; 227, call; 227, 228; 227, 241; 228, attribute; 228, 229; 228, 240; 229, call; 229, 230; 229, 238; 230, attribute; 230, 231; 230, 237; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:splitpath; 234, identifier:pop; 235, argument_list; 235, 236; 236, integer:0; 237, identifier:decode; 238, argument_list; 238, 239; 239, string:'utf-8'; 240, identifier:encode; 241, argument_list; 241, 242; 242, identifier:encoding; 243, raise_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:pycdlibexception; 247, identifier:PyCdlibInvalidInput; 248, argument_list; 248, 249; 249, string:'Could not find path' | def _find_dr_record_by_name(vd, path, encoding):
'''
An internal function to find an directory record on the ISO given an ISO
or Joliet path. If the entry is found, it returns the directory record
object corresponding to that entry. If the entry could not be found,
a pycdlibexception.PyCdlibInvalidInput exception is raised.
Parameters:
vd - The Volume Descriptor to look in for the Directory Record.
path - The ISO or Joliet entry to find the Directory Record for.
encoding - The string encoding used for the path.
Returns:
The directory record entry representing the entry on the ISO.
'''
if not utils.starts_with_slash(path):
raise pycdlibexception.PyCdlibInvalidInput('Must be a path starting with /')
root_dir_record = vd.root_directory_record()
if path == b'/':
return root_dir_record
splitpath = utils.split_path(path)
currpath = splitpath.pop(0).decode('utf-8').encode(encoding)
entry = root_dir_record
tmpdr = dr.DirectoryRecord()
while True:
child = None
thelist = entry.children
lo = 2
hi = len(thelist)
while lo < hi:
mid = (lo + hi) // 2
tmpdr.file_ident = currpath
if thelist[mid] < tmpdr:
lo = mid + 1
else:
hi = mid
index = lo
if index != len(thelist) and thelist[index].file_ident == currpath:
child = thelist[index]
if child is None:
break
if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists():
child = child.rock_ridge.cl_to_moved_dr
if child is None:
break
if not splitpath:
return child
if not child.is_dir():
break
entry = child
currpath = splitpath.pop(0).decode('utf-8').encode(encoding)
raise pycdlibexception.PyCdlibInvalidInput('Could not find path') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_parse_volume_descriptors; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 19; 5, 311; 5, 324; 5, 334; 5, 368; 6, expression_statement; 6, 7; 7, string:'''
An internal method to parse the volume descriptors on an ISO.
Parameters:
None.
Returns:
Nothing.
'''; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 15; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_cdfp; 14, identifier:seek; 15, argument_list; 15, 16; 16, binary_operator:*; 16, 17; 16, 18; 17, integer:16; 18, integer:2048; 19, while_statement; 19, 20; 19, 21; 20, True; 21, block; 21, 22; 21, 34; 21, 45; 21, 60; 21, 73; 21, 112; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:curr_extent; 25, binary_operator://; 25, 26; 25, 33; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_cdfp; 31, identifier:tell; 32, argument_list; 33, integer:2048; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:vd; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_cdfp; 42, identifier:read; 43, argument_list; 43, 44; 44, integer:2048; 45, if_statement; 45, 46; 45, 52; 46, comparison_operator:!=; 46, 47; 46, 51; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, identifier:vd; 51, integer:2048; 52, block; 52, 53; 53, raise_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:pycdlibexception; 57, identifier:PyCdlibInvalidISO; 58, argument_list; 58, 59; 59, string:'Failed to read entire volume descriptor'; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, tuple_pattern; 62, 63; 62, 64; 63, identifier:desc_type; 64, identifier:ident; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:struct; 68, identifier:unpack_from; 69, argument_list; 69, 70; 69, 71; 69, 72; 70, string:'=B5s'; 71, identifier:vd; 72, integer:0; 73, if_statement; 73, 74; 73, 97; 74, boolean_operator:or; 74, 75; 74, 90; 75, comparison_operator:not; 75, 76; 75, 77; 76, identifier:desc_type; 77, tuple; 77, 78; 77, 81; 77, 84; 77, 87; 78, attribute; 78, 79; 78, 80; 79, identifier:headervd; 80, identifier:VOLUME_DESCRIPTOR_TYPE_PRIMARY; 81, attribute; 81, 82; 81, 83; 82, identifier:headervd; 83, identifier:VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR; 84, attribute; 84, 85; 84, 86; 85, identifier:headervd; 86, identifier:VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD; 87, attribute; 87, 88; 87, 89; 88, identifier:headervd; 89, identifier:VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY; 90, comparison_operator:not; 90, 91; 90, 92; 91, identifier:ident; 92, tuple; 92, 93; 92, 94; 92, 95; 92, 96; 93, string:b'CD001'; 94, string:b'BEA01'; 95, string:b'NSR02'; 96, string:b'TEA01'; 97, block; 97, 98; 97, 111; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:_cdfp; 104, identifier:seek; 105, argument_list; 105, 106; 105, 108; 106, unary_operator:-; 106, 107; 107, integer:2048; 108, attribute; 108, 109; 108, 110; 109, identifier:os; 110, identifier:SEEK_CUR; 111, break_statement; 112, if_statement; 112, 113; 112, 118; 112, 147; 112, 179; 112, 276; 113, comparison_operator:==; 113, 114; 113, 115; 114, identifier:desc_type; 115, attribute; 115, 116; 115, 117; 116, identifier:headervd; 117, identifier:VOLUME_DESCRIPTOR_TYPE_PRIMARY; 118, block; 118, 119; 118, 130; 118, 138; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:pvd; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:headervd; 125, identifier:PrimaryOrSupplementaryVD; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 129; 128, identifier:headervd; 129, identifier:VOLUME_DESCRIPTOR_TYPE_PRIMARY; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:pvd; 134, identifier:parse; 135, argument_list; 135, 136; 135, 137; 136, identifier:vd; 137, identifier:curr_extent; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:pvds; 144, identifier:append; 145, argument_list; 145, 146; 146, identifier:pvd; 147, elif_clause; 147, 148; 147, 153; 148, comparison_operator:==; 148, 149; 148, 150; 149, identifier:desc_type; 150, attribute; 150, 151; 150, 152; 151, identifier:headervd; 152, identifier:VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR; 153, block; 153, 154; 153, 162; 153, 170; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:vdst; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:headervd; 160, identifier:VolumeDescriptorSetTerminator; 161, argument_list; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:vdst; 166, identifier:parse; 167, argument_list; 167, 168; 167, 169; 168, identifier:vd; 169, identifier:curr_extent; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 177; 172, attribute; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:vdsts; 176, identifier:append; 177, argument_list; 177, 178; 178, identifier:vdst; 179, elif_clause; 179, 180; 179, 185; 180, comparison_operator:==; 180, 181; 180, 182; 181, identifier:desc_type; 182, attribute; 182, 183; 182, 184; 183, identifier:headervd; 184, identifier:VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD; 185, block; 185, 186; 186, if_statement; 186, 187; 186, 190; 186, 216; 186, 237; 186, 252; 186, 267; 187, comparison_operator:==; 187, 188; 187, 189; 188, identifier:ident; 189, string:b'CD001'; 190, block; 190, 191; 190, 199; 190, 207; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:br; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:headervd; 197, identifier:BootRecord; 198, argument_list; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:br; 203, identifier:parse; 204, argument_list; 204, 205; 204, 206; 205, identifier:vd; 206, identifier:curr_extent; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 214; 209, attribute; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:brs; 213, identifier:append; 214, argument_list; 214, 215; 215, identifier:br; 216, elif_clause; 216, 217; 216, 220; 217, comparison_operator:==; 217, 218; 217, 219; 218, identifier:ident; 219, string:b'BEA01'; 220, block; 220, 221; 220, 227; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:self; 225, identifier:_has_udf; 226, True; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:udf_bea; 233, identifier:parse; 234, argument_list; 234, 235; 234, 236; 235, identifier:vd; 236, identifier:curr_extent; 237, elif_clause; 237, 238; 237, 241; 238, comparison_operator:==; 238, 239; 238, 240; 239, identifier:ident; 240, string:b'NSR02'; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:udf_nsr; 248, identifier:parse; 249, argument_list; 249, 250; 249, 251; 250, identifier:vd; 251, identifier:curr_extent; 252, elif_clause; 252, 253; 252, 256; 253, comparison_operator:==; 253, 254; 253, 255; 254, identifier:ident; 255, string:b'TEA01'; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 264; 259, attribute; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:udf_tea; 263, identifier:parse; 264, argument_list; 264, 265; 264, 266; 265, identifier:vd; 266, identifier:curr_extent; 267, else_clause; 267, 268; 268, block; 268, 269; 269, raise_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:pycdlibexception; 273, identifier:PyCdlibInvalidISO; 274, argument_list; 274, 275; 275, string:'Invalid volume identification type'; 276, elif_clause; 276, 277; 276, 282; 277, comparison_operator:==; 277, 278; 277, 279; 278, identifier:desc_type; 279, attribute; 279, 280; 279, 281; 280, identifier:headervd; 281, identifier:VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY; 282, block; 282, 283; 282, 294; 282, 302; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:svd; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:headervd; 289, identifier:PrimaryOrSupplementaryVD; 290, argument_list; 290, 291; 291, attribute; 291, 292; 291, 293; 292, identifier:headervd; 293, identifier:VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY; 294, expression_statement; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:svd; 298, identifier:parse; 299, argument_list; 299, 300; 299, 301; 300, identifier:vd; 301, identifier:curr_extent; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 309; 304, attribute; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:self; 307, identifier:svds; 308, identifier:append; 309, argument_list; 309, 310; 310, identifier:svd; 311, if_statement; 311, 312; 311, 316; 312, not_operator; 312, 313; 313, attribute; 313, 314; 313, 315; 314, identifier:self; 315, identifier:pvds; 316, block; 316, 317; 317, raise_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:pycdlibexception; 321, identifier:PyCdlibInvalidISO; 322, argument_list; 322, 323; 323, string:'Valid ISO9660 filesystems must have at least one PVD'; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:self; 328, identifier:pvd; 329, subscript; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:self; 332, identifier:pvds; 333, integer:0; 334, for_statement; 334, 335; 334, 336; 334, 343; 335, identifier:pvd; 336, subscript; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:self; 339, identifier:pvds; 340, slice; 340, 341; 340, 342; 341, integer:1; 342, colon; 343, block; 343, 344; 343, 358; 344, if_statement; 344, 345; 344, 350; 345, comparison_operator:!=; 345, 346; 345, 347; 346, identifier:pvd; 347, attribute; 347, 348; 347, 349; 348, identifier:self; 349, identifier:pvd; 350, block; 350, 351; 351, raise_statement; 351, 352; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:pycdlibexception; 355, identifier:PyCdlibInvalidISO; 356, argument_list; 356, 357; 357, string:'Multiple occurrences of PVD did not agree!'; 358, expression_statement; 358, 359; 359, assignment; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:pvd; 362, identifier:root_dir_record; 363, attribute; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:self; 366, identifier:pvd; 367, identifier:root_dir_record; 368, if_statement; 368, 369; 368, 373; 369, not_operator; 369, 370; 370, attribute; 370, 371; 370, 372; 371, identifier:self; 372, identifier:vdsts; 373, block; 373, 374; 374, raise_statement; 374, 375; 375, call; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:pycdlibexception; 378, identifier:PyCdlibInvalidISO; 379, argument_list; 379, 380; 380, string:'Valid ISO9660 filesystems must have at least one Volume Descriptor Set Terminator' | def _parse_volume_descriptors(self):
'''
An internal method to parse the volume descriptors on an ISO.
Parameters:
None.
Returns:
Nothing.
'''
self._cdfp.seek(16 * 2048)
while True:
curr_extent = self._cdfp.tell() // 2048
vd = self._cdfp.read(2048)
if len(vd) != 2048:
raise pycdlibexception.PyCdlibInvalidISO('Failed to read entire volume descriptor')
(desc_type, ident) = struct.unpack_from('=B5s', vd, 0)
if desc_type not in (headervd.VOLUME_DESCRIPTOR_TYPE_PRIMARY,
headervd.VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR,
headervd.VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD,
headervd.VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY) or ident not in (b'CD001', b'BEA01', b'NSR02', b'TEA01'):
self._cdfp.seek(-2048, os.SEEK_CUR)
break
if desc_type == headervd.VOLUME_DESCRIPTOR_TYPE_PRIMARY:
pvd = headervd.PrimaryOrSupplementaryVD(headervd.VOLUME_DESCRIPTOR_TYPE_PRIMARY)
pvd.parse(vd, curr_extent)
self.pvds.append(pvd)
elif desc_type == headervd.VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR:
vdst = headervd.VolumeDescriptorSetTerminator()
vdst.parse(vd, curr_extent)
self.vdsts.append(vdst)
elif desc_type == headervd.VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD:
if ident == b'CD001':
br = headervd.BootRecord()
br.parse(vd, curr_extent)
self.brs.append(br)
elif ident == b'BEA01':
self._has_udf = True
self.udf_bea.parse(vd, curr_extent)
elif ident == b'NSR02':
self.udf_nsr.parse(vd, curr_extent)
elif ident == b'TEA01':
self.udf_tea.parse(vd, curr_extent)
else:
raise pycdlibexception.PyCdlibInvalidISO('Invalid volume identification type')
elif desc_type == headervd.VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY:
svd = headervd.PrimaryOrSupplementaryVD(headervd.VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY)
svd.parse(vd, curr_extent)
self.svds.append(svd)
if not self.pvds:
raise pycdlibexception.PyCdlibInvalidISO('Valid ISO9660 filesystems must have at least one PVD')
self.pvd = self.pvds[0]
for pvd in self.pvds[1:]:
if pvd != self.pvd:
raise pycdlibexception.PyCdlibInvalidISO('Multiple occurrences of PVD did not agree!')
pvd.root_dir_record = self.pvd.root_dir_record
if not self.vdsts:
raise pycdlibexception.PyCdlibInvalidISO('Valid ISO9660 filesystems must have at least one Volume Descriptor Set Terminator') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_find_rr_record; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:rr_path; 6, block; 6, 7; 6, 9; 6, 25; 6, 35; 6, 42; 6, 51; 6, 70; 6, 74; 6, 268; 7, expression_statement; 7, 8; 8, string:'''
An internal method to find an directory record on the ISO given a Rock
Ridge path. If the entry is found, it returns the directory record
object corresponding to that entry. If the entry could not be found, a
pycdlibexception.PyCdlibInvalidInput is raised.
Parameters:
rr_path - The Rock Ridge path to lookup.
Returns:
The directory record entry representing the entry on the ISO.
'''; 9, if_statement; 9, 10; 9, 17; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:utils; 14, identifier:starts_with_slash; 15, argument_list; 15, 16; 16, identifier:rr_path; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:pycdlibexception; 22, identifier:PyCdlibInvalidInput; 23, argument_list; 23, 24; 24, string:'Must be a path starting with /'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:root_dir_record; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:pvd; 33, identifier:root_directory_record; 34, argument_list; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:rr_path; 38, string:b'/'; 39, block; 39, 40; 40, return_statement; 40, 41; 41, identifier:root_dir_record; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:splitpath; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:utils; 48, identifier:split_path; 49, argument_list; 49, 50; 50, identifier:rr_path; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:currpath; 54, call; 54, 55; 54, 68; 55, attribute; 55, 56; 55, 67; 56, call; 56, 57; 56, 65; 57, attribute; 57, 58; 57, 64; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:splitpath; 61, identifier:pop; 62, argument_list; 62, 63; 63, integer:0; 64, identifier:decode; 65, argument_list; 65, 66; 66, string:'utf-8'; 67, identifier:encode; 68, argument_list; 68, 69; 69, string:'utf-8'; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:entry; 73, identifier:root_dir_record; 74, while_statement; 74, 75; 74, 76; 75, True; 76, block; 76, 77; 76, 81; 76, 87; 76, 91; 76, 98; 76, 155; 76, 159; 76, 165; 76, 195; 76, 201; 76, 230; 76, 236; 76, 245; 76, 249; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:child; 80, None; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:thelist; 84, attribute; 84, 85; 84, 86; 85, identifier:entry; 86, identifier:rr_children; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:lo; 90, integer:0; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:hi; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, identifier:thelist; 98, while_statement; 98, 99; 98, 102; 99, comparison_operator:<; 99, 100; 99, 101; 100, identifier:lo; 101, identifier:hi; 102, block; 102, 103; 102, 112; 102, 118; 102, 132; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:mid; 106, binary_operator://; 106, 107; 106, 111; 107, parenthesized_expression; 107, 108; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:lo; 110, identifier:hi; 111, integer:2; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:tmpchild; 115, subscript; 115, 116; 115, 117; 116, identifier:thelist; 117, identifier:mid; 118, if_statement; 118, 119; 118, 124; 119, comparison_operator:is; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:tmpchild; 122, identifier:rock_ridge; 123, None; 124, block; 124, 125; 125, raise_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:pycdlibexception; 129, identifier:PyCdlibInvalidInput; 130, argument_list; 130, 131; 131, string:'Record without Rock Ridge entry on Rock Ridge ISO'; 132, if_statement; 132, 133; 132, 142; 132, 149; 133, comparison_operator:<; 133, 134; 133, 141; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:tmpchild; 138, identifier:rock_ridge; 139, identifier:name; 140, argument_list; 141, identifier:currpath; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:lo; 146, binary_operator:+; 146, 147; 146, 148; 147, identifier:mid; 148, integer:1; 149, else_clause; 149, 150; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:hi; 154, identifier:mid; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:index; 158, identifier:lo; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:tmpchild; 162, subscript; 162, 163; 162, 164; 163, identifier:thelist; 164, identifier:index; 165, if_statement; 165, 166; 165, 188; 166, boolean_operator:and; 166, 167; 166, 179; 167, boolean_operator:and; 167, 168; 167, 174; 168, comparison_operator:!=; 168, 169; 168, 170; 169, identifier:index; 170, call; 170, 171; 170, 172; 171, identifier:len; 172, argument_list; 172, 173; 173, identifier:thelist; 174, comparison_operator:is; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:tmpchild; 177, identifier:rock_ridge; 178, None; 179, comparison_operator:==; 179, 180; 179, 187; 180, call; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:tmpchild; 184, identifier:rock_ridge; 185, identifier:name; 186, argument_list; 187, identifier:currpath; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:child; 192, subscript; 192, 193; 192, 194; 193, identifier:thelist; 194, identifier:index; 195, if_statement; 195, 196; 195, 199; 196, comparison_operator:is; 196, 197; 196, 198; 197, identifier:child; 198, None; 199, block; 199, 200; 200, break_statement; 201, if_statement; 201, 202; 201, 215; 202, boolean_operator:and; 202, 203; 202, 208; 203, comparison_operator:is; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:child; 206, identifier:rock_ridge; 207, None; 208, call; 208, 209; 208, 214; 209, attribute; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:child; 212, identifier:rock_ridge; 213, identifier:child_link_record_exists; 214, argument_list; 215, block; 215, 216; 215, 224; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:child; 219, attribute; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:child; 222, identifier:rock_ridge; 223, identifier:cl_to_moved_dr; 224, if_statement; 224, 225; 224, 228; 225, comparison_operator:is; 225, 226; 225, 227; 226, identifier:child; 227, None; 228, block; 228, 229; 229, break_statement; 230, if_statement; 230, 231; 230, 233; 231, not_operator; 231, 232; 232, identifier:splitpath; 233, block; 233, 234; 234, return_statement; 234, 235; 235, identifier:child; 236, if_statement; 236, 237; 236, 243; 237, not_operator; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:child; 241, identifier:is_dir; 242, argument_list; 243, block; 243, 244; 244, break_statement; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:entry; 248, identifier:child; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:currpath; 252, call; 252, 253; 252, 266; 253, attribute; 253, 254; 253, 265; 254, call; 254, 255; 254, 263; 255, attribute; 255, 256; 255, 262; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:splitpath; 259, identifier:pop; 260, argument_list; 260, 261; 261, integer:0; 262, identifier:decode; 263, argument_list; 263, 264; 264, string:'utf-8'; 265, identifier:encode; 266, argument_list; 266, 267; 267, string:'utf-8'; 268, raise_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:pycdlibexception; 272, identifier:PyCdlibInvalidInput; 273, argument_list; 273, 274; 274, string:'Could not find path' | def _find_rr_record(self, rr_path):
'''
An internal method to find an directory record on the ISO given a Rock
Ridge path. If the entry is found, it returns the directory record
object corresponding to that entry. If the entry could not be found, a
pycdlibexception.PyCdlibInvalidInput is raised.
Parameters:
rr_path - The Rock Ridge path to lookup.
Returns:
The directory record entry representing the entry on the ISO.
'''
if not utils.starts_with_slash(rr_path):
raise pycdlibexception.PyCdlibInvalidInput('Must be a path starting with /')
root_dir_record = self.pvd.root_directory_record()
if rr_path == b'/':
return root_dir_record
splitpath = utils.split_path(rr_path)
currpath = splitpath.pop(0).decode('utf-8').encode('utf-8')
entry = root_dir_record
while True:
child = None
thelist = entry.rr_children
lo = 0
hi = len(thelist)
while lo < hi:
mid = (lo + hi) // 2
tmpchild = thelist[mid]
if tmpchild.rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidInput('Record without Rock Ridge entry on Rock Ridge ISO')
if tmpchild.rock_ridge.name() < currpath:
lo = mid + 1
else:
hi = mid
index = lo
tmpchild = thelist[index]
if index != len(thelist) and tmpchild.rock_ridge is not None and tmpchild.rock_ridge.name() == currpath:
child = thelist[index]
if child is None:
break
if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists():
child = child.rock_ridge.cl_to_moved_dr
if child is None:
break
if not splitpath:
return child
if not child.is_dir():
break
entry = child
currpath = splitpath.pop(0).decode('utf-8').encode('utf-8')
raise pycdlibexception.PyCdlibInvalidInput('Could not find path') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_parse_udf_descriptors; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 18; 5, 35; 5, 130; 5, 153; 5, 176; 5, 189; 5, 206; 5, 210; 5, 220; 5, 228; 5, 240; 5, 254; 5, 272; 5, 276; 5, 280; 5, 288; 5, 300; 5, 314; 5, 324; 5, 334; 5, 341; 5, 354; 5, 362; 5, 374; 5, 388; 5, 403; 5, 407; 5, 415; 5, 435; 5, 449; 6, expression_statement; 6, 7; 7, string:'''
An internal method to parse the UDF descriptors on the ISO. This should
only be called if it the ISO has a valid UDF Volume Recognition Sequence
at the beginning of the ISO.
Parameters:
None.
Returns:
Nothing.
'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:block_size; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:pvd; 16, identifier:logical_block_size; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:anchor_locations; 21, list:[(256 * block_size, os.SEEK_SET), (-2048, os.SEEK_END)]; 21, 22; 21, 29; 22, tuple; 22, 23; 22, 26; 23, binary_operator:*; 23, 24; 23, 25; 24, integer:256; 25, identifier:block_size; 26, attribute; 26, 27; 26, 28; 27, identifier:os; 28, identifier:SEEK_SET; 29, tuple; 29, 30; 29, 32; 30, unary_operator:-; 30, 31; 31, integer:2048; 32, attribute; 32, 33; 32, 34; 33, identifier:os; 34, identifier:SEEK_END; 35, for_statement; 35, 36; 35, 39; 35, 40; 36, pattern_list; 36, 37; 36, 38; 37, identifier:loc; 38, identifier:whence; 39, identifier:anchor_locations; 40, block; 40, 41; 40, 51; 40, 63; 40, 74; 40, 82; 40, 90; 40, 104; 40, 112; 40, 121; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_cdfp; 47, identifier:seek; 48, argument_list; 48, 49; 48, 50; 49, identifier:loc; 50, identifier:whence; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:extent; 54, binary_operator://; 54, 55; 54, 62; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_cdfp; 60, identifier:tell; 61, argument_list; 62, integer:2048; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:anchor_data; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_cdfp; 71, identifier:read; 72, argument_list; 72, 73; 73, integer:2048; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:anchor_tag; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:udfmod; 80, identifier:UDFTag; 81, argument_list; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:anchor_tag; 86, identifier:parse; 87, argument_list; 87, 88; 87, 89; 88, identifier:anchor_data; 89, identifier:extent; 90, if_statement; 90, 91; 90, 96; 91, comparison_operator:!=; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:anchor_tag; 94, identifier:tag_ident; 95, integer:2; 96, block; 96, 97; 97, raise_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:pycdlibexception; 101, identifier:PyCdlibInvalidISO; 102, argument_list; 102, 103; 103, string:'UDF Anchor Tag identifier not 2'; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:anchor; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:udfmod; 110, identifier:UDFAnchorVolumeStructure; 111, argument_list; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:anchor; 116, identifier:parse; 117, argument_list; 117, 118; 117, 119; 117, 120; 118, identifier:anchor_data; 119, identifier:extent; 120, identifier:anchor_tag; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:udf_anchors; 127, identifier:append; 128, argument_list; 128, 129; 129, identifier:anchor; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:_parse_udf_vol_descs; 135, argument_list; 135, 136; 135, 143; 135, 150; 136, attribute; 136, 137; 136, 142; 137, subscript; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:udf_anchors; 141, integer:0; 142, identifier:main_vd_extent; 143, attribute; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:udf_anchors; 148, integer:0; 149, identifier:main_vd_length; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:udf_main_descs; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:_parse_udf_vol_descs; 158, argument_list; 158, 159; 158, 166; 158, 173; 159, attribute; 159, 160; 159, 165; 160, subscript; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:udf_anchors; 164, integer:0; 165, identifier:reserve_vd_extent; 166, attribute; 166, 167; 166, 172; 167, subscript; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:udf_anchors; 171, integer:0; 172, identifier:reserve_vd_length; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:udf_reserve_descs; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:_seek_to_extent; 181, argument_list; 181, 182; 182, attribute; 182, 183; 182, 188; 183, attribute; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:udf_main_descs; 187, identifier:logical_volume; 188, identifier:integrity_sequence_extent; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:integrity_data; 192, call; 192, 193; 192, 198; 193, attribute; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:_cdfp; 197, identifier:read; 198, argument_list; 198, 199; 199, attribute; 199, 200; 199, 205; 200, attribute; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:udf_main_descs; 204, identifier:logical_volume; 205, identifier:integrity_sequence_length; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:offset; 209, integer:0; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:current_extent; 213, attribute; 213, 214; 213, 219; 214, attribute; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:udf_main_descs; 218, identifier:logical_volume; 219, identifier:integrity_sequence_extent; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:desc_tag; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:udfmod; 226, identifier:UDFTag; 227, argument_list; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:desc_tag; 232, identifier:parse; 233, argument_list; 233, 234; 233, 239; 234, subscript; 234, 235; 234, 236; 235, identifier:integrity_data; 236, slice; 236, 237; 236, 238; 237, identifier:offset; 238, colon; 239, identifier:current_extent; 240, if_statement; 240, 241; 240, 246; 241, comparison_operator:!=; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:desc_tag; 244, identifier:tag_ident; 245, integer:9; 246, block; 246, 247; 247, raise_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:pycdlibexception; 251, identifier:PyCdlibInvalidISO; 252, argument_list; 252, 253; 253, string:'UDF Volume Integrity Tag identifier not 9'; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 261; 256, attribute; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:self; 259, identifier:udf_logical_volume_integrity; 260, identifier:parse; 261, argument_list; 261, 262; 261, 270; 261, 271; 262, subscript; 262, 263; 262, 264; 263, identifier:integrity_data; 264, slice; 264, 265; 264, 266; 264, 267; 265, identifier:offset; 266, colon; 267, binary_operator:+; 267, 268; 267, 269; 268, identifier:offset; 269, integer:512; 270, identifier:current_extent; 271, identifier:desc_tag; 272, expression_statement; 272, 273; 273, augmented_assignment:+=; 273, 274; 273, 275; 274, identifier:offset; 275, identifier:block_size; 276, expression_statement; 276, 277; 277, augmented_assignment:+=; 277, 278; 277, 279; 278, identifier:current_extent; 279, integer:1; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:desc_tag; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:udfmod; 286, identifier:UDFTag; 287, argument_list; 288, expression_statement; 288, 289; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:desc_tag; 292, identifier:parse; 293, argument_list; 293, 294; 293, 299; 294, subscript; 294, 295; 294, 296; 295, identifier:integrity_data; 296, slice; 296, 297; 296, 298; 297, identifier:offset; 298, colon; 299, identifier:current_extent; 300, if_statement; 300, 301; 300, 306; 301, comparison_operator:!=; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:desc_tag; 304, identifier:tag_ident; 305, integer:8; 306, block; 306, 307; 307, raise_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:pycdlibexception; 311, identifier:PyCdlibInvalidISO; 312, argument_list; 312, 313; 313, string:'UDF Logical Volume Integrity Terminator Tag identifier not 8'; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 321; 316, attribute; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:self; 319, identifier:udf_logical_volume_integrity_terminator; 320, identifier:parse; 321, argument_list; 321, 322; 321, 323; 322, identifier:current_extent; 323, identifier:desc_tag; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:current_extent; 327, attribute; 327, 328; 327, 333; 328, attribute; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:self; 331, identifier:udf_main_descs; 332, identifier:partition; 333, identifier:part_start_location; 334, expression_statement; 334, 335; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:self; 338, identifier:_seek_to_extent; 339, argument_list; 339, 340; 340, identifier:current_extent; 341, expression_statement; 341, 342; 342, assignment; 342, 343; 342, 344; 343, identifier:file_set_and_term_data; 344, call; 344, 345; 344, 350; 345, attribute; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:self; 348, identifier:_cdfp; 349, identifier:read; 350, argument_list; 350, 351; 351, binary_operator:*; 351, 352; 351, 353; 352, integer:2; 353, identifier:block_size; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 357; 356, identifier:desc_tag; 357, call; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:udfmod; 360, identifier:UDFTag; 361, argument_list; 362, expression_statement; 362, 363; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:desc_tag; 366, identifier:parse; 367, argument_list; 367, 368; 367, 373; 368, subscript; 368, 369; 368, 370; 369, identifier:file_set_and_term_data; 370, slice; 370, 371; 370, 372; 371, colon; 372, identifier:block_size; 373, integer:0; 374, if_statement; 374, 375; 374, 380; 375, comparison_operator:!=; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:desc_tag; 378, identifier:tag_ident; 379, integer:256; 380, block; 380, 381; 381, raise_statement; 381, 382; 382, call; 382, 383; 382, 386; 383, attribute; 383, 384; 383, 385; 384, identifier:pycdlibexception; 385, identifier:PyCdlibInvalidISO; 386, argument_list; 386, 387; 387, string:'UDF File Set Tag identifier not 256'; 388, expression_statement; 388, 389; 389, call; 389, 390; 389, 395; 390, attribute; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:self; 393, identifier:udf_file_set; 394, identifier:parse; 395, argument_list; 395, 396; 395, 401; 395, 402; 396, subscript; 396, 397; 396, 398; 397, identifier:file_set_and_term_data; 398, slice; 398, 399; 398, 400; 399, colon; 400, identifier:block_size; 401, identifier:current_extent; 402, identifier:desc_tag; 403, expression_statement; 403, 404; 404, augmented_assignment:+=; 404, 405; 404, 406; 405, identifier:current_extent; 406, integer:1; 407, expression_statement; 407, 408; 408, assignment; 408, 409; 408, 410; 409, identifier:desc_tag; 410, call; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:udfmod; 413, identifier:UDFTag; 414, argument_list; 415, expression_statement; 415, 416; 416, call; 416, 417; 416, 420; 417, attribute; 417, 418; 417, 419; 418, identifier:desc_tag; 419, identifier:parse; 420, argument_list; 420, 421; 420, 426; 421, subscript; 421, 422; 421, 423; 422, identifier:file_set_and_term_data; 423, slice; 423, 424; 423, 425; 424, identifier:block_size; 425, colon; 426, binary_operator:-; 426, 427; 426, 428; 427, identifier:current_extent; 428, attribute; 428, 429; 428, 434; 429, attribute; 429, 430; 429, 433; 430, attribute; 430, 431; 430, 432; 431, identifier:self; 432, identifier:udf_main_descs; 433, identifier:partition; 434, identifier:part_start_location; 435, if_statement; 435, 436; 435, 441; 436, comparison_operator:!=; 436, 437; 436, 440; 437, attribute; 437, 438; 437, 439; 438, identifier:desc_tag; 439, identifier:tag_ident; 440, integer:8; 441, block; 441, 442; 442, raise_statement; 442, 443; 443, call; 443, 444; 443, 447; 444, attribute; 444, 445; 444, 446; 445, identifier:pycdlibexception; 446, identifier:PyCdlibInvalidISO; 447, argument_list; 447, 448; 448, string:'UDF File Set Terminator Tag identifier not 8'; 449, expression_statement; 449, 450; 450, call; 450, 451; 450, 456; 451, attribute; 451, 452; 451, 455; 452, attribute; 452, 453; 452, 454; 453, identifier:self; 454, identifier:udf_file_set_terminator; 455, identifier:parse; 456, argument_list; 456, 457; 456, 458; 457, identifier:current_extent; 458, identifier:desc_tag | def _parse_udf_descriptors(self):
'''
An internal method to parse the UDF descriptors on the ISO. This should
only be called if it the ISO has a valid UDF Volume Recognition Sequence
at the beginning of the ISO.
Parameters:
None.
Returns:
Nothing.
'''
block_size = self.pvd.logical_block_size()
anchor_locations = [(256 * block_size, os.SEEK_SET), (-2048, os.SEEK_END)]
for loc, whence in anchor_locations:
self._cdfp.seek(loc, whence)
extent = self._cdfp.tell() // 2048
anchor_data = self._cdfp.read(2048)
anchor_tag = udfmod.UDFTag()
anchor_tag.parse(anchor_data, extent)
if anchor_tag.tag_ident != 2:
raise pycdlibexception.PyCdlibInvalidISO('UDF Anchor Tag identifier not 2')
anchor = udfmod.UDFAnchorVolumeStructure()
anchor.parse(anchor_data, extent, anchor_tag)
self.udf_anchors.append(anchor)
self._parse_udf_vol_descs(self.udf_anchors[0].main_vd_extent,
self.udf_anchors[0].main_vd_length,
self.udf_main_descs)
self._parse_udf_vol_descs(self.udf_anchors[0].reserve_vd_extent,
self.udf_anchors[0].reserve_vd_length,
self.udf_reserve_descs)
self._seek_to_extent(self.udf_main_descs.logical_volume.integrity_sequence_extent)
integrity_data = self._cdfp.read(self.udf_main_descs.logical_volume.integrity_sequence_length)
offset = 0
current_extent = self.udf_main_descs.logical_volume.integrity_sequence_extent
desc_tag = udfmod.UDFTag()
desc_tag.parse(integrity_data[offset:], current_extent)
if desc_tag.tag_ident != 9:
raise pycdlibexception.PyCdlibInvalidISO('UDF Volume Integrity Tag identifier not 9')
self.udf_logical_volume_integrity.parse(integrity_data[offset:offset + 512], current_extent, desc_tag)
offset += block_size
current_extent += 1
desc_tag = udfmod.UDFTag()
desc_tag.parse(integrity_data[offset:], current_extent)
if desc_tag.tag_ident != 8:
raise pycdlibexception.PyCdlibInvalidISO('UDF Logical Volume Integrity Terminator Tag identifier not 8')
self.udf_logical_volume_integrity_terminator.parse(current_extent, desc_tag)
current_extent = self.udf_main_descs.partition.part_start_location
self._seek_to_extent(current_extent)
file_set_and_term_data = self._cdfp.read(2 * block_size)
desc_tag = udfmod.UDFTag()
desc_tag.parse(file_set_and_term_data[:block_size], 0)
if desc_tag.tag_ident != 256:
raise pycdlibexception.PyCdlibInvalidISO('UDF File Set Tag identifier not 256')
self.udf_file_set.parse(file_set_and_term_data[:block_size],
current_extent, desc_tag)
current_extent += 1
desc_tag = udfmod.UDFTag()
desc_tag.parse(file_set_and_term_data[block_size:],
current_extent - self.udf_main_descs.partition.part_start_location)
if desc_tag.tag_ident != 8:
raise pycdlibexception.PyCdlibInvalidISO('UDF File Set Terminator Tag identifier not 8')
self.udf_file_set_terminator.parse(current_extent, desc_tag) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_walk_udf_directories; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:extent_to_inode; 6, block; 6, 7; 6, 9; 6, 19; 6, 44; 6, 54; 6, 66; 7, expression_statement; 7, 8; 8, string:'''
An internal method to walk a UDF filesystem and add all the metadata
to this object.
Parameters:
extent_to_inode - A map from extent numbers to Inodes.
Returns:
Nothing.
'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:part_start; 12, attribute; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:udf_main_descs; 17, identifier:partition; 18, identifier:part_start_location; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:udf_root; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_parse_udf_file_entry; 28, argument_list; 28, 29; 28, 38; 28, 43; 29, binary_operator:+; 29, 30; 29, 31; 30, identifier:part_start; 31, attribute; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:udf_file_set; 36, identifier:root_dir_icb; 37, identifier:log_block_num; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:udf_file_set; 42, identifier:root_dir_icb; 43, None; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:log_block_size; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:pvd; 52, identifier:logical_block_size; 53, argument_list; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:udf_file_entries; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:collections; 60, identifier:deque; 61, argument_list; 61, 62; 62, list:[self.udf_root]; 62, 63; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:udf_root; 66, while_statement; 66, 67; 66, 68; 67, identifier:udf_file_entries; 68, block; 68, 69; 68, 77; 68, 83; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:udf_file_entry; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:udf_file_entries; 75, identifier:popleft; 76, argument_list; 77, if_statement; 77, 78; 77, 81; 78, comparison_operator:is; 78, 79; 78, 80; 79, identifier:udf_file_entry; 80, None; 81, block; 81, 82; 82, continue_statement; 83, for_statement; 83, 84; 83, 87; 83, 90; 84, pattern_list; 84, 85; 84, 86; 85, identifier:desc_len; 86, identifier:desc_pos; 87, attribute; 87, 88; 87, 89; 88, identifier:udf_file_entry; 89, identifier:alloc_descs; 90, block; 90, 91; 90, 97; 90, 104; 90, 115; 90, 119; 90, 415; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:abs_file_ident_extent; 94, binary_operator:+; 94, 95; 94, 96; 95, identifier:part_start; 96, identifier:desc_pos; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:_seek_to_extent; 102, argument_list; 102, 103; 103, identifier:abs_file_ident_extent; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:data; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:_cdfp; 112, identifier:read; 113, argument_list; 113, 114; 114, identifier:desc_len; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:offset; 118, integer:0; 119, while_statement; 119, 120; 119, 126; 120, comparison_operator:<; 120, 121; 120, 122; 121, identifier:offset; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:data; 126, block; 126, 127; 126, 138; 126, 146; 126, 160; 126, 174; 126, 182; 126, 198; 126, 213; 126, 223; 126, 236; 126, 243; 126, 265; 126, 271; 126, 277; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:current_extent; 130, binary_operator://; 130, 131; 130, 137; 131, parenthesized_expression; 131, 132; 132, binary_operator:+; 132, 133; 132, 136; 133, binary_operator:*; 133, 134; 133, 135; 134, identifier:abs_file_ident_extent; 135, identifier:log_block_size; 136, identifier:offset; 137, identifier:log_block_size; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:desc_tag; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:udfmod; 144, identifier:UDFTag; 145, argument_list; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:desc_tag; 150, identifier:parse; 151, argument_list; 151, 152; 151, 157; 152, subscript; 152, 153; 152, 154; 153, identifier:data; 154, slice; 154, 155; 154, 156; 155, identifier:offset; 156, colon; 157, binary_operator:-; 157, 158; 157, 159; 158, identifier:current_extent; 159, identifier:part_start; 160, if_statement; 160, 161; 160, 166; 161, comparison_operator:!=; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:desc_tag; 164, identifier:tag_ident; 165, integer:257; 166, block; 166, 167; 167, raise_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:pycdlibexception; 171, identifier:PyCdlibInvalidISO; 172, argument_list; 172, 173; 173, string:'UDF File Identifier Tag identifier not 257'; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:file_ident; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:udfmod; 180, identifier:UDFFileIdentifierDescriptor; 181, argument_list; 182, expression_statement; 182, 183; 183, augmented_assignment:+=; 183, 184; 183, 185; 184, identifier:offset; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:file_ident; 188, identifier:parse; 189, argument_list; 189, 190; 189, 195; 189, 196; 189, 197; 190, subscript; 190, 191; 190, 192; 191, identifier:data; 192, slice; 192, 193; 192, 194; 193, identifier:offset; 194, colon; 195, identifier:current_extent; 196, identifier:desc_tag; 197, identifier:udf_file_entry; 198, if_statement; 198, 199; 198, 204; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:file_ident; 202, identifier:is_parent; 203, argument_list; 204, block; 204, 205; 204, 212; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:udf_file_entry; 209, identifier:track_file_ident_desc; 210, argument_list; 210, 211; 211, identifier:file_ident; 212, continue_statement; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:abs_file_entry_extent; 216, binary_operator:+; 216, 217; 216, 218; 217, identifier:part_start; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:file_ident; 221, identifier:icb; 222, identifier:log_block_num; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:next_entry; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:_parse_udf_file_entry; 230, argument_list; 230, 231; 230, 232; 230, 235; 231, identifier:abs_file_entry_extent; 232, attribute; 232, 233; 232, 234; 233, identifier:file_ident; 234, identifier:icb; 235, identifier:udf_file_entry; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:udf_file_entry; 240, identifier:track_file_ident_desc; 241, argument_list; 241, 242; 242, identifier:file_ident; 243, if_statement; 243, 244; 243, 247; 244, comparison_operator:is; 244, 245; 244, 246; 245, identifier:next_entry; 246, None; 247, block; 247, 248; 248, if_statement; 248, 249; 248, 254; 248, 262; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:file_ident; 252, identifier:is_dir; 253, argument_list; 254, block; 254, 255; 255, raise_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:pycdlibexception; 259, identifier:PyCdlibInvalidISO; 260, argument_list; 260, 261; 261, string:'Empty UDF File Entry for directories are not allowed'; 262, else_clause; 262, 263; 263, block; 263, 264; 264, continue_statement; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:file_ident; 269, identifier:file_entry; 270, identifier:next_entry; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:next_entry; 275, identifier:file_ident; 276, identifier:file_ident; 277, if_statement; 277, 278; 277, 283; 277, 291; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:file_ident; 281, identifier:is_dir; 282, argument_list; 283, block; 283, 284; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:udf_file_entries; 288, identifier:append; 289, argument_list; 289, 290; 290, identifier:next_entry; 291, else_clause; 291, 292; 292, block; 292, 293; 292, 320; 293, if_statement; 293, 294; 293, 301; 293, 314; 294, comparison_operator:>; 294, 295; 294, 300; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:next_entry; 298, identifier:get_data_length; 299, argument_list; 300, integer:0; 301, block; 301, 302; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:abs_file_data_extent; 305, binary_operator:+; 305, 306; 305, 307; 306, identifier:part_start; 307, subscript; 307, 308; 307, 313; 308, subscript; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:next_entry; 311, identifier:alloc_descs; 312, integer:0; 313, integer:1; 314, else_clause; 314, 315; 315, block; 315, 316; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:abs_file_data_extent; 319, integer:0; 320, if_statement; 320, 321; 320, 336; 320, 346; 321, boolean_operator:and; 321, 322; 321, 327; 322, comparison_operator:is; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:eltorito_boot_catalog; 326, None; 327, comparison_operator:==; 327, 328; 327, 329; 328, identifier:abs_file_data_extent; 329, call; 329, 330; 329, 335; 330, attribute; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:eltorito_boot_catalog; 334, identifier:extent_location; 335, argument_list; 336, block; 336, 337; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 344; 339, attribute; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:self; 342, identifier:eltorito_boot_catalog; 343, identifier:add_dirrecord; 344, argument_list; 344, 345; 345, identifier:next_entry; 346, else_clause; 346, 347; 347, block; 347, 348; 347, 400; 347, 409; 348, if_statement; 348, 349; 348, 352; 348, 359; 349, comparison_operator:in; 349, 350; 349, 351; 350, identifier:abs_file_data_extent; 351, identifier:extent_to_inode; 352, block; 352, 353; 353, expression_statement; 353, 354; 354, assignment; 354, 355; 354, 356; 355, identifier:ino; 356, subscript; 356, 357; 356, 358; 357, identifier:extent_to_inode; 358, identifier:abs_file_data_extent; 359, else_clause; 359, 360; 360, block; 360, 361; 360, 369; 360, 385; 360, 391; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 364; 363, identifier:ino; 364, call; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:inode; 367, identifier:Inode; 368, argument_list; 369, expression_statement; 369, 370; 370, call; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:ino; 373, identifier:parse; 374, argument_list; 374, 375; 374, 376; 374, 381; 374, 384; 375, identifier:abs_file_data_extent; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:next_entry; 379, identifier:get_data_length; 380, argument_list; 381, attribute; 381, 382; 381, 383; 382, identifier:self; 383, identifier:_cdfp; 384, identifier:log_block_size; 385, expression_statement; 385, 386; 386, assignment; 386, 387; 386, 390; 387, subscript; 387, 388; 387, 389; 388, identifier:extent_to_inode; 389, identifier:abs_file_data_extent; 390, identifier:ino; 391, expression_statement; 391, 392; 392, call; 392, 393; 392, 398; 393, attribute; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:self; 396, identifier:inodes; 397, identifier:append; 398, argument_list; 398, 399; 399, identifier:ino; 400, expression_statement; 400, 401; 401, call; 401, 402; 401, 407; 402, attribute; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, identifier:ino; 405, identifier:linked_records; 406, identifier:append; 407, argument_list; 407, 408; 408, identifier:next_entry; 409, expression_statement; 409, 410; 410, assignment; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:next_entry; 413, identifier:inode; 414, identifier:ino; 415, expression_statement; 415, 416; 416, call; 416, 417; 416, 420; 417, attribute; 417, 418; 417, 419; 418, identifier:udf_file_entry; 419, identifier:finish_directory_parse; 420, argument_list | def _walk_udf_directories(self, extent_to_inode):
'''
An internal method to walk a UDF filesystem and add all the metadata
to this object.
Parameters:
extent_to_inode - A map from extent numbers to Inodes.
Returns:
Nothing.
'''
part_start = self.udf_main_descs.partition.part_start_location
self.udf_root = self._parse_udf_file_entry(part_start + self.udf_file_set.root_dir_icb.log_block_num,
self.udf_file_set.root_dir_icb,
None)
log_block_size = self.pvd.logical_block_size()
udf_file_entries = collections.deque([self.udf_root])
while udf_file_entries:
udf_file_entry = udf_file_entries.popleft()
if udf_file_entry is None:
continue
for desc_len, desc_pos in udf_file_entry.alloc_descs:
abs_file_ident_extent = part_start + desc_pos
self._seek_to_extent(abs_file_ident_extent)
data = self._cdfp.read(desc_len)
offset = 0
while offset < len(data):
current_extent = (abs_file_ident_extent * log_block_size + offset) // log_block_size
desc_tag = udfmod.UDFTag()
desc_tag.parse(data[offset:], current_extent - part_start)
if desc_tag.tag_ident != 257:
raise pycdlibexception.PyCdlibInvalidISO('UDF File Identifier Tag identifier not 257')
file_ident = udfmod.UDFFileIdentifierDescriptor()
offset += file_ident.parse(data[offset:],
current_extent,
desc_tag,
udf_file_entry)
if file_ident.is_parent():
udf_file_entry.track_file_ident_desc(file_ident)
continue
abs_file_entry_extent = part_start + file_ident.icb.log_block_num
next_entry = self._parse_udf_file_entry(abs_file_entry_extent,
file_ident.icb,
udf_file_entry)
udf_file_entry.track_file_ident_desc(file_ident)
if next_entry is None:
if file_ident.is_dir():
raise pycdlibexception.PyCdlibInvalidISO('Empty UDF File Entry for directories are not allowed')
else:
continue
file_ident.file_entry = next_entry
next_entry.file_ident = file_ident
if file_ident.is_dir():
udf_file_entries.append(next_entry)
else:
if next_entry.get_data_length() > 0:
abs_file_data_extent = part_start + next_entry.alloc_descs[0][1]
else:
abs_file_data_extent = 0
if self.eltorito_boot_catalog is not None and abs_file_data_extent == self.eltorito_boot_catalog.extent_location():
self.eltorito_boot_catalog.add_dirrecord(next_entry)
else:
if abs_file_data_extent in extent_to_inode:
ino = extent_to_inode[abs_file_data_extent]
else:
ino = inode.Inode()
ino.parse(abs_file_data_extent,
next_entry.get_data_length(), self._cdfp,
log_block_size)
extent_to_inode[abs_file_data_extent] = ino
self.inodes.append(ino)
ino.linked_records.append(next_entry)
next_entry.inode = ino
udf_file_entry.finish_directory_parse() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_write_directory_records; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:vd; 6, identifier:outfp; 7, identifier:progress; 8, block; 8, 9; 8, 11; 8, 19; 8, 23; 8, 27; 8, 41; 9, expression_statement; 9, 10; 10, string:'''
An internal method to write out the directory records from a particular
Volume Descriptor.
Parameters:
vd - The Volume Descriptor to write the Directory Records from.
outfp - The file object to write data to.
progress - The _Progress object to use for outputting progress.
Returns:
Nothing.
'''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:log_block_size; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:vd; 17, identifier:logical_block_size; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:le_ptr_offset; 22, integer:0; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:be_ptr_offset; 26, integer:0; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:dirs; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:collections; 33, identifier:deque; 34, argument_list; 34, 35; 35, list:[vd.root_directory_record()]; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:vd; 39, identifier:root_directory_record; 40, argument_list; 41, while_statement; 41, 42; 41, 43; 42, identifier:dirs; 43, block; 43, 44; 43, 52; 43, 56; 43, 164; 43, 172; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:curr; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:dirs; 50, identifier:popleft; 51, argument_list; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:curr_dirrecord_offset; 55, integer:0; 56, if_statement; 56, 57; 56, 62; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:curr; 60, identifier:is_dir; 61, argument_list; 62, block; 62, 63; 62, 77; 62, 90; 62, 100; 62, 108; 62, 115; 62, 128; 62, 138; 62, 146; 62, 153; 63, if_statement; 63, 64; 63, 69; 64, comparison_operator:is; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:curr; 67, identifier:ptr; 68, None; 69, block; 69, 70; 70, raise_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:pycdlibexception; 74, identifier:PyCdlibInternalError; 75, argument_list; 75, 76; 76, string:'Directory has no Path Table Record'; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:outfp; 81, identifier:seek; 82, argument_list; 82, 83; 83, binary_operator:+; 83, 84; 83, 89; 84, binary_operator:*; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:vd; 87, identifier:path_table_location_le; 88, identifier:log_block_size; 89, identifier:le_ptr_offset; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:ret; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:curr; 97, identifier:ptr; 98, identifier:record_little_endian; 99, argument_list; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:_outfp_write_with_check; 105, argument_list; 105, 106; 105, 107; 106, identifier:outfp; 107, identifier:ret; 108, expression_statement; 108, 109; 109, augmented_assignment:+=; 109, 110; 109, 111; 110, identifier:le_ptr_offset; 111, call; 111, 112; 111, 113; 112, identifier:len; 113, argument_list; 113, 114; 114, identifier:ret; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:outfp; 119, identifier:seek; 120, argument_list; 120, 121; 121, binary_operator:+; 121, 122; 121, 127; 122, binary_operator:*; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:vd; 125, identifier:path_table_location_be; 126, identifier:log_block_size; 127, identifier:be_ptr_offset; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:ret; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:curr; 135, identifier:ptr; 136, identifier:record_big_endian; 137, argument_list; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:_outfp_write_with_check; 143, argument_list; 143, 144; 143, 145; 144, identifier:outfp; 145, identifier:ret; 146, expression_statement; 146, 147; 147, augmented_assignment:+=; 147, 148; 147, 149; 148, identifier:be_ptr_offset; 149, call; 149, 150; 149, 151; 150, identifier:len; 151, argument_list; 151, 152; 152, identifier:ret; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:progress; 157, identifier:call; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:curr; 162, identifier:get_data_length; 163, argument_list; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:dir_extent; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:curr; 170, identifier:extent_location; 171, argument_list; 172, for_statement; 172, 173; 172, 174; 172, 177; 173, identifier:child; 174, attribute; 174, 175; 174, 176; 175, identifier:curr; 176, identifier:children; 177, block; 177, 178; 177, 186; 177, 205; 177, 216; 177, 224; 177, 231; 177, 318; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:recstr; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:child; 184, identifier:record; 185, argument_list; 186, if_statement; 186, 187; 186, 196; 187, comparison_operator:>; 187, 188; 187, 195; 188, parenthesized_expression; 188, 189; 189, binary_operator:+; 189, 190; 189, 191; 190, identifier:curr_dirrecord_offset; 191, call; 191, 192; 191, 193; 192, identifier:len; 193, argument_list; 193, 194; 194, identifier:recstr; 195, identifier:log_block_size; 196, block; 196, 197; 196, 201; 197, expression_statement; 197, 198; 198, augmented_assignment:+=; 198, 199; 198, 200; 199, identifier:dir_extent; 200, integer:1; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:curr_dirrecord_offset; 204, integer:0; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:outfp; 209, identifier:seek; 210, argument_list; 210, 211; 211, binary_operator:+; 211, 212; 211, 215; 212, binary_operator:*; 212, 213; 212, 214; 213, identifier:dir_extent; 214, identifier:log_block_size; 215, identifier:curr_dirrecord_offset; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:_outfp_write_with_check; 221, argument_list; 221, 222; 221, 223; 222, identifier:outfp; 223, identifier:recstr; 224, expression_statement; 224, 225; 225, augmented_assignment:+=; 225, 226; 225, 227; 226, identifier:curr_dirrecord_offset; 227, call; 227, 228; 227, 229; 228, identifier:len; 229, argument_list; 229, 230; 230, identifier:recstr; 231, if_statement; 231, 232; 231, 237; 232, comparison_operator:is; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:child; 235, identifier:rock_ridge; 236, None; 237, block; 237, 238; 237, 308; 238, if_statement; 238, 239; 238, 248; 239, comparison_operator:is; 239, 240; 239, 247; 240, attribute; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:child; 244, identifier:rock_ridge; 245, identifier:dr_entries; 246, identifier:ce_record; 247, None; 248, block; 248, 249; 248, 259; 248, 280; 248, 290; 248, 298; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:ce_rec; 252, attribute; 252, 253; 252, 258; 253, attribute; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:child; 256, identifier:rock_ridge; 257, identifier:dr_entries; 258, identifier:ce_record; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:outfp; 263, identifier:seek; 264, argument_list; 264, 265; 265, binary_operator:+; 265, 266; 265, 277; 266, binary_operator:*; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:ce_rec; 269, identifier:bl_cont_area; 270, call; 270, 271; 270, 276; 271, attribute; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:pvd; 275, identifier:logical_block_size; 276, argument_list; 277, attribute; 277, 278; 277, 279; 278, identifier:ce_rec; 279, identifier:offset_cont_area; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:rec; 283, call; 283, 284; 283, 289; 284, attribute; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:child; 287, identifier:rock_ridge; 288, identifier:record_ce_entries; 289, argument_list; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:_outfp_write_with_check; 295, argument_list; 295, 296; 295, 297; 296, identifier:outfp; 297, identifier:rec; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:progress; 302, identifier:call; 303, argument_list; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:len; 306, argument_list; 306, 307; 307, identifier:rec; 308, if_statement; 308, 309; 308, 316; 309, call; 309, 310; 309, 315; 310, attribute; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:child; 313, identifier:rock_ridge; 314, identifier:child_link_record_exists; 315, argument_list; 316, block; 316, 317; 317, continue_statement; 318, if_statement; 318, 319; 318, 324; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:child; 322, identifier:is_dir; 323, argument_list; 324, block; 324, 325; 325, if_statement; 325, 326; 325, 339; 326, boolean_operator:and; 326, 327; 326, 333; 327, not_operator; 327, 328; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:child; 331, identifier:is_dot; 332, argument_list; 333, not_operator; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:child; 337, identifier:is_dotdot; 338, argument_list; 339, block; 339, 340; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:dirs; 344, identifier:append; 345, argument_list; 345, 346; 346, identifier:child | def _write_directory_records(self, vd, outfp, progress):
'''
An internal method to write out the directory records from a particular
Volume Descriptor.
Parameters:
vd - The Volume Descriptor to write the Directory Records from.
outfp - The file object to write data to.
progress - The _Progress object to use for outputting progress.
Returns:
Nothing.
'''
log_block_size = vd.logical_block_size()
le_ptr_offset = 0
be_ptr_offset = 0
dirs = collections.deque([vd.root_directory_record()])
while dirs:
curr = dirs.popleft()
curr_dirrecord_offset = 0
if curr.is_dir():
if curr.ptr is None:
raise pycdlibexception.PyCdlibInternalError('Directory has no Path Table Record')
outfp.seek(vd.path_table_location_le * log_block_size + le_ptr_offset)
ret = curr.ptr.record_little_endian()
self._outfp_write_with_check(outfp, ret)
le_ptr_offset += len(ret)
outfp.seek(vd.path_table_location_be * log_block_size + be_ptr_offset)
ret = curr.ptr.record_big_endian()
self._outfp_write_with_check(outfp, ret)
be_ptr_offset += len(ret)
progress.call(curr.get_data_length())
dir_extent = curr.extent_location()
for child in curr.children:
recstr = child.record()
if (curr_dirrecord_offset + len(recstr)) > log_block_size:
dir_extent += 1
curr_dirrecord_offset = 0
outfp.seek(dir_extent * log_block_size + curr_dirrecord_offset)
self._outfp_write_with_check(outfp, recstr)
curr_dirrecord_offset += len(recstr)
if child.rock_ridge is not None:
if child.rock_ridge.dr_entries.ce_record is not None:
ce_rec = child.rock_ridge.dr_entries.ce_record
outfp.seek(ce_rec.bl_cont_area * self.pvd.logical_block_size() + ce_rec.offset_cont_area)
rec = child.rock_ridge.record_ce_entries()
self._outfp_write_with_check(outfp, rec)
progress.call(len(rec))
if child.rock_ridge.child_link_record_exists():
continue
if child.is_dir():
if not child.is_dot() and not child.is_dotdot():
dirs.append(child) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_rm_dr_link; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:rec; 6, block; 6, 7; 6, 9; 6, 24; 6, 28; 6, 38; 6, 42; 6, 199; 7, expression_statement; 7, 8; 8, string:'''
An internal method to remove a Directory Record link given the record.
Parameters:
rec - The Directory Record to remove.
Returns:
The number of bytes to remove from the ISO.
'''; 9, if_statement; 9, 10; 9, 16; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:rec; 14, identifier:is_file; 15, argument_list; 16, block; 16, 17; 17, raise_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:pycdlibexception; 21, identifier:PyCdlibInvalidInput; 22, argument_list; 22, 23; 23, string:'Cannot remove a directory with rm_hard_link (try rm_directory instead)'; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:num_bytes_to_remove; 27, integer:0; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:logical_block_size; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:rec; 35, identifier:vd; 36, identifier:logical_block_size; 37, argument_list; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:done; 41, False; 42, while_statement; 42, 43; 42, 45; 43, not_operator; 43, 44; 44, identifier:done; 45, block; 45, 46; 45, 59; 45, 180; 46, expression_statement; 46, 47; 47, augmented_assignment:+=; 47, 48; 47, 49; 48, identifier:num_bytes_to_remove; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_remove_child_from_dr; 53, argument_list; 53, 54; 53, 55; 53, 58; 54, identifier:rec; 55, attribute; 55, 56; 55, 57; 56, identifier:rec; 57, identifier:index_in_parent; 58, identifier:logical_block_size; 59, if_statement; 59, 60; 59, 65; 60, comparison_operator:is; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:rec; 63, identifier:inode; 64, None; 65, block; 65, 66; 65, 70; 65, 108; 65, 116; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:found_index; 69, None; 70, for_statement; 70, 71; 70, 74; 70, 82; 70, 99; 71, pattern_list; 71, 72; 71, 73; 72, identifier:index; 73, identifier:link; 74, call; 74, 75; 74, 76; 75, identifier:enumerate; 76, argument_list; 76, 77; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:rec; 80, identifier:inode; 81, identifier:linked_records; 82, block; 82, 83; 83, if_statement; 83, 84; 83, 93; 84, comparison_operator:==; 84, 85; 84, 89; 85, call; 85, 86; 85, 87; 86, identifier:id; 87, argument_list; 87, 88; 88, identifier:link; 89, call; 89, 90; 89, 91; 90, identifier:id; 91, argument_list; 91, 92; 92, identifier:rec; 93, block; 93, 94; 93, 98; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:found_index; 97, identifier:index; 98, break_statement; 99, else_clause; 99, 100; 100, block; 100, 101; 101, raise_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:pycdlibexception; 105, identifier:PyCdlibInternalError; 106, argument_list; 106, 107; 107, string:'Could not find inode corresponding to record'; 108, delete_statement; 108, 109; 109, subscript; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:rec; 113, identifier:inode; 114, identifier:linked_records; 115, identifier:found_index; 116, if_statement; 116, 117; 116, 123; 117, not_operator; 117, 118; 118, attribute; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:rec; 121, identifier:inode; 122, identifier:linked_records; 123, block; 123, 124; 123, 128; 123, 166; 123, 172; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:found_index; 127, None; 128, for_statement; 128, 129; 128, 132; 128, 138; 128, 157; 129, pattern_list; 129, 130; 129, 131; 130, identifier:index; 131, identifier:ino; 132, call; 132, 133; 132, 134; 133, identifier:enumerate; 134, argument_list; 134, 135; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:inodes; 138, block; 138, 139; 139, if_statement; 139, 140; 139, 151; 140, comparison_operator:==; 140, 141; 140, 145; 141, call; 141, 142; 141, 143; 142, identifier:id; 143, argument_list; 143, 144; 144, identifier:ino; 145, call; 145, 146; 145, 147; 146, identifier:id; 147, argument_list; 147, 148; 148, attribute; 148, 149; 148, 150; 149, identifier:rec; 150, identifier:inode; 151, block; 151, 152; 151, 156; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:found_index; 155, identifier:index; 156, break_statement; 157, else_clause; 157, 158; 158, block; 158, 159; 159, raise_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:pycdlibexception; 163, identifier:PyCdlibInternalError; 164, argument_list; 164, 165; 165, string:'Could not find inode corresponding to record'; 166, delete_statement; 166, 167; 167, subscript; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:inodes; 171, identifier:found_index; 172, expression_statement; 172, 173; 173, augmented_assignment:+=; 173, 174; 173, 175; 174, identifier:num_bytes_to_remove; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:rec; 178, identifier:get_data_length; 179, argument_list; 180, if_statement; 180, 181; 180, 186; 180, 193; 181, comparison_operator:is; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:rec; 184, identifier:data_continuation; 185, None; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:rec; 190, attribute; 190, 191; 190, 192; 191, identifier:rec; 192, identifier:data_continuation; 193, else_clause; 193, 194; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:done; 198, True; 199, return_statement; 199, 200; 200, identifier:num_bytes_to_remove | def _rm_dr_link(self, rec):
'''
An internal method to remove a Directory Record link given the record.
Parameters:
rec - The Directory Record to remove.
Returns:
The number of bytes to remove from the ISO.
'''
if not rec.is_file():
raise pycdlibexception.PyCdlibInvalidInput('Cannot remove a directory with rm_hard_link (try rm_directory instead)')
num_bytes_to_remove = 0
logical_block_size = rec.vd.logical_block_size()
done = False
while not done:
num_bytes_to_remove += self._remove_child_from_dr(rec,
rec.index_in_parent,
logical_block_size)
if rec.inode is not None:
found_index = None
for index, link in enumerate(rec.inode.linked_records):
if id(link) == id(rec):
found_index = index
break
else:
raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')
del rec.inode.linked_records[found_index]
if not rec.inode.linked_records:
found_index = None
for index, ino in enumerate(self.inodes):
if id(ino) == id(rec.inode):
found_index = index
break
else:
raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')
del self.inodes[found_index]
num_bytes_to_remove += rec.get_data_length()
if rec.data_continuation is not None:
rec = rec.data_continuation
else:
done = True
return num_bytes_to_remove |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_rm_udf_link; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:rec; 6, block; 6, 7; 6, 9; 6, 31; 6, 41; 6, 45; 6, 193; 6, 207; 6, 221; 7, expression_statement; 7, 8; 8, string:'''
An internal method to remove a UDF File Entry link.
Parameters:
rec - The UDF File Entry to remove.
Returns:
The number of bytes to remove from the ISO.
'''; 9, if_statement; 9, 10; 9, 23; 10, boolean_operator:and; 10, 11; 10, 17; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:rec; 15, identifier:is_file; 16, argument_list; 17, not_operator; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:rec; 21, identifier:is_symlink; 22, argument_list; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:pycdlibexception; 28, identifier:PyCdlibInvalidInput; 29, argument_list; 29, 30; 30, string:'Cannot remove a directory with rm_hard_link (try rm_directory instead)'; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:logical_block_size; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:pvd; 39, identifier:logical_block_size; 40, argument_list; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:num_bytes_to_remove; 44, integer:0; 45, if_statement; 45, 46; 45, 51; 45, 187; 46, comparison_operator:is; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:rec; 49, identifier:inode; 50, None; 51, block; 51, 52; 51, 56; 51, 94; 51, 102; 51, 110; 51, 174; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:found_index; 55, None; 56, for_statement; 56, 57; 56, 60; 56, 68; 56, 85; 57, pattern_list; 57, 58; 57, 59; 58, identifier:index; 59, identifier:link; 60, call; 60, 61; 60, 62; 61, identifier:enumerate; 62, argument_list; 62, 63; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:rec; 66, identifier:inode; 67, identifier:linked_records; 68, block; 68, 69; 69, if_statement; 69, 70; 69, 79; 70, comparison_operator:==; 70, 71; 70, 75; 71, call; 71, 72; 71, 73; 72, identifier:id; 73, argument_list; 73, 74; 74, identifier:link; 75, call; 75, 76; 75, 77; 76, identifier:id; 77, argument_list; 77, 78; 78, identifier:rec; 79, block; 79, 80; 79, 84; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:found_index; 83, identifier:index; 84, break_statement; 85, else_clause; 85, 86; 86, block; 86, 87; 87, raise_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:pycdlibexception; 91, identifier:PyCdlibInternalError; 92, argument_list; 92, 93; 93, string:'Could not find inode corresponding to record'; 94, delete_statement; 94, 95; 95, subscript; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:rec; 99, identifier:inode; 100, identifier:linked_records; 101, identifier:found_index; 102, expression_statement; 102, 103; 103, augmented_assignment:-=; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:rec; 107, identifier:inode; 108, identifier:num_udf; 109, integer:1; 110, if_statement; 110, 111; 110, 117; 111, not_operator; 111, 112; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:rec; 115, identifier:inode; 116, identifier:linked_records; 117, block; 117, 118; 117, 122; 117, 160; 117, 166; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:found_index; 121, None; 122, for_statement; 122, 123; 122, 126; 122, 132; 122, 151; 123, pattern_list; 123, 124; 123, 125; 124, identifier:index; 125, identifier:ino; 126, call; 126, 127; 126, 128; 127, identifier:enumerate; 128, argument_list; 128, 129; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:inodes; 132, block; 132, 133; 133, if_statement; 133, 134; 133, 145; 134, comparison_operator:==; 134, 135; 134, 139; 135, call; 135, 136; 135, 137; 136, identifier:id; 137, argument_list; 137, 138; 138, identifier:ino; 139, call; 139, 140; 139, 141; 140, identifier:id; 141, argument_list; 141, 142; 142, attribute; 142, 143; 142, 144; 143, identifier:rec; 144, identifier:inode; 145, block; 145, 146; 145, 150; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:found_index; 149, identifier:index; 150, break_statement; 151, else_clause; 151, 152; 152, block; 152, 153; 153, raise_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:pycdlibexception; 157, identifier:PyCdlibInternalError; 158, argument_list; 158, 159; 159, string:'Could not find inode corresponding to record'; 160, delete_statement; 160, 161; 161, subscript; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:inodes; 165, identifier:found_index; 166, expression_statement; 166, 167; 167, augmented_assignment:+=; 167, 168; 167, 169; 168, identifier:num_bytes_to_remove; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:rec; 172, identifier:get_data_length; 173, argument_list; 174, if_statement; 174, 175; 174, 182; 175, comparison_operator:==; 175, 176; 175, 181; 176, attribute; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:rec; 179, identifier:inode; 180, identifier:num_udf; 181, integer:0; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, augmented_assignment:+=; 184, 185; 184, 186; 185, identifier:num_bytes_to_remove; 186, identifier:logical_block_size; 187, else_clause; 187, 188; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, augmented_assignment:+=; 190, 191; 190, 192; 191, identifier:num_bytes_to_remove; 192, identifier:logical_block_size; 193, if_statement; 193, 194; 193, 199; 194, comparison_operator:is; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:rec; 197, identifier:parent; 198, None; 199, block; 199, 200; 200, raise_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:pycdlibexception; 204, identifier:PyCdlibInternalError; 205, argument_list; 205, 206; 206, string:'Cannot remove a UDF record with no parent'; 207, if_statement; 207, 208; 207, 213; 208, comparison_operator:is; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:rec; 211, identifier:file_ident; 212, None; 213, block; 213, 214; 214, raise_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:pycdlibexception; 218, identifier:PyCdlibInternalError; 219, argument_list; 219, 220; 220, string:'Cannot remove a UDF record with no file identifier'; 221, return_statement; 221, 222; 222, binary_operator:+; 222, 223; 222, 224; 223, identifier:num_bytes_to_remove; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:_rm_udf_file_ident; 228, argument_list; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:rec; 231, identifier:parent; 232, attribute; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:rec; 235, identifier:file_ident; 236, identifier:fi | def _rm_udf_link(self, rec):
'''
An internal method to remove a UDF File Entry link.
Parameters:
rec - The UDF File Entry to remove.
Returns:
The number of bytes to remove from the ISO.
'''
if not rec.is_file() and not rec.is_symlink():
raise pycdlibexception.PyCdlibInvalidInput('Cannot remove a directory with rm_hard_link (try rm_directory instead)')
logical_block_size = self.pvd.logical_block_size()
num_bytes_to_remove = 0
if rec.inode is not None:
found_index = None
for index, link in enumerate(rec.inode.linked_records):
if id(link) == id(rec):
found_index = index
break
else:
raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')
del rec.inode.linked_records[found_index]
rec.inode.num_udf -= 1
if not rec.inode.linked_records:
found_index = None
for index, ino in enumerate(self.inodes):
if id(ino) == id(rec.inode):
found_index = index
break
else:
raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')
del self.inodes[found_index]
num_bytes_to_remove += rec.get_data_length()
if rec.inode.num_udf == 0:
num_bytes_to_remove += logical_block_size
else:
num_bytes_to_remove += logical_block_size
if rec.parent is None:
raise pycdlibexception.PyCdlibInternalError('Cannot remove a UDF record with no parent')
if rec.file_ident is None:
raise pycdlibexception.PyCdlibInternalError('Cannot remove a UDF record with no file identifier')
return num_bytes_to_remove + self._rm_udf_file_ident(rec.parent, rec.file_ident.fi) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:rm_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:iso_path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:rr_name; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:joliet_path; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:udf_path; 14, None; 15, block; 15, 16; 15, 18; 15, 31; 15, 40; 15, 56; 15, 65; 15, 80; 15, 177; 15, 181; 15, 185; 15, 189; 15, 228; 15, 318; 15, 355; 16, expression_statement; 16, 17; 17, string:'''
Remove a file from the ISO.
Parameters:
iso_path - The path to the file to remove.
rr_name - The Rock Ridge name of the file to remove.
joliet_path - The Joliet path to the file to remove.
udf_path - The UDF path to the file to remove.
Returns:
Nothing.
'''; 18, if_statement; 18, 19; 18, 23; 19, not_operator; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_initialized; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:pycdlibexception; 28, identifier:PyCdlibInvalidInput; 29, argument_list; 29, 30; 30, string:'This object is not yet initialized; call either open() or new() to create an ISO'; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:iso_path_bytes; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:utils; 37, identifier:normpath; 38, argument_list; 38, 39; 39, identifier:iso_path; 40, if_statement; 40, 41; 40, 48; 41, not_operator; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:utils; 45, identifier:starts_with_slash; 46, argument_list; 46, 47; 47, identifier:iso_path_bytes; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:pycdlibexception; 53, identifier:PyCdlibInvalidInput; 54, argument_list; 54, 55; 55, string:'Must be a path starting with /'; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:child; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_find_iso_record; 63, argument_list; 63, 64; 64, identifier:iso_path_bytes; 65, if_statement; 65, 66; 65, 72; 66, not_operator; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:child; 70, identifier:is_file; 71, argument_list; 72, block; 72, 73; 73, raise_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:pycdlibexception; 77, identifier:PyCdlibInvalidInput; 78, argument_list; 78, 79; 79, string:'Cannot remove a directory with rm_file (try rm_directory instead)'; 80, if_statement; 80, 81; 80, 86; 81, comparison_operator:is; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:eltorito_boot_catalog; 85, None; 86, block; 86, 87; 86, 116; 86, 120; 86, 135; 86, 160; 87, if_statement; 87, 88; 87, 108; 88, call; 88, 89; 88, 90; 89, identifier:any; 90, argument_list; 90, 91; 91, list_comprehension; 91, 92; 91, 101; 92, comparison_operator:==; 92, 93; 92, 97; 93, call; 93, 94; 93, 95; 94, identifier:id; 95, argument_list; 95, 96; 96, identifier:child; 97, call; 97, 98; 97, 99; 98, identifier:id; 99, argument_list; 99, 100; 100, identifier:rec; 101, for_in_clause; 101, 102; 101, 103; 102, identifier:rec; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:eltorito_boot_catalog; 107, identifier:dirrecords; 108, block; 108, 109; 109, raise_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:pycdlibexception; 113, identifier:PyCdlibInvalidInput; 114, argument_list; 114, 115; 115, string:"Cannot remove a file that is referenced by El Torito; either use 'rm_eltorito' to remove El Torito first, or use 'rm_hard_link' to hide the entry"; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:eltorito_entries; 119, dictionary; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 134; 122, subscript; 122, 123; 122, 124; 123, identifier:eltorito_entries; 124, call; 124, 125; 124, 126; 125, identifier:id; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 133; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:eltorito_boot_catalog; 132, identifier:initial_entry; 133, identifier:inode; 134, True; 135, for_statement; 135, 136; 135, 137; 135, 142; 136, identifier:sec; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:eltorito_boot_catalog; 141, identifier:sections; 142, block; 142, 143; 143, for_statement; 143, 144; 143, 145; 143, 148; 144, identifier:entry; 145, attribute; 145, 146; 145, 147; 146, identifier:sec; 147, identifier:section_entries; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 159; 151, subscript; 151, 152; 151, 153; 152, identifier:eltorito_entries; 153, call; 153, 154; 153, 155; 154, identifier:id; 155, argument_list; 155, 156; 156, attribute; 156, 157; 156, 158; 157, identifier:entry; 158, identifier:inode; 159, True; 160, if_statement; 160, 161; 160, 169; 161, comparison_operator:in; 161, 162; 161, 168; 162, call; 162, 163; 162, 164; 163, identifier:id; 164, argument_list; 164, 165; 165, attribute; 165, 166; 165, 167; 166, identifier:child; 167, identifier:inode; 168, identifier:eltorito_entries; 169, block; 169, 170; 170, raise_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:pycdlibexception; 174, identifier:PyCdlibInvalidInput; 175, argument_list; 175, 176; 176, string:"Cannot remove a file that is referenced by El Torito; either use 'rm_eltorito' to remove El Torito first, or use 'rm_hard_link' to hide the entry"; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:num_bytes_to_remove; 180, integer:0; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:udf_file_ident; 184, None; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:udf_file_entry; 188, None; 189, if_statement; 189, 190; 189, 193; 190, comparison_operator:is; 190, 191; 190, 192; 191, identifier:udf_path; 192, None; 193, block; 193, 194; 193, 208; 193, 217; 194, if_statement; 194, 195; 194, 200; 195, comparison_operator:is; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:udf_root; 199, None; 200, block; 200, 201; 201, raise_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:pycdlibexception; 205, identifier:PyCdlibInvalidInput; 206, argument_list; 206, 207; 207, string:'Can only specify a udf_path for a UDF ISO'; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:udf_path_bytes; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:utils; 214, identifier:normpath; 215, argument_list; 215, 216; 216, identifier:udf_path; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 222; 219, tuple_pattern; 219, 220; 219, 221; 220, identifier:udf_file_ident; 221, identifier:udf_file_entry; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:self; 225, identifier:_find_udf_record; 226, argument_list; 226, 227; 227, identifier:udf_path_bytes; 228, if_statement; 228, 229; 228, 234; 228, 254; 229, comparison_operator:is; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:child; 232, identifier:inode; 233, None; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, augmented_assignment:+=; 236, 237; 236, 238; 237, identifier:num_bytes_to_remove; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:_remove_child_from_dr; 242, argument_list; 242, 243; 242, 244; 242, 247; 243, identifier:child; 244, attribute; 244, 245; 244, 246; 245, identifier:child; 246, identifier:index_in_parent; 247, call; 247, 248; 247, 253; 248, attribute; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:pvd; 252, identifier:logical_block_size; 253, argument_list; 254, else_clause; 254, 255; 255, block; 255, 256; 256, while_statement; 256, 257; 256, 262; 257, attribute; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:child; 260, identifier:inode; 261, identifier:linked_records; 262, block; 262, 263; 262, 273; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:rec; 266, subscript; 266, 267; 266, 272; 267, attribute; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:child; 270, identifier:inode; 271, identifier:linked_records; 272, integer:0; 273, if_statement; 273, 274; 273, 281; 273, 291; 273, 309; 274, call; 274, 275; 274, 276; 275, identifier:isinstance; 276, argument_list; 276, 277; 276, 278; 277, identifier:rec; 278, attribute; 278, 279; 278, 280; 279, identifier:dr; 280, identifier:DirectoryRecord; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, augmented_assignment:+=; 283, 284; 283, 285; 284, identifier:num_bytes_to_remove; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:_rm_dr_link; 289, argument_list; 289, 290; 290, identifier:rec; 291, elif_clause; 291, 292; 291, 299; 292, call; 292, 293; 292, 294; 293, identifier:isinstance; 294, argument_list; 294, 295; 294, 296; 295, identifier:rec; 296, attribute; 296, 297; 296, 298; 297, identifier:udfmod; 298, identifier:UDFFileEntry; 299, block; 299, 300; 300, expression_statement; 300, 301; 301, augmented_assignment:+=; 301, 302; 301, 303; 302, identifier:num_bytes_to_remove; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:_rm_udf_link; 307, argument_list; 307, 308; 308, identifier:rec; 309, else_clause; 309, 310; 310, block; 310, 311; 311, raise_statement; 311, 312; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:pycdlibexception; 315, identifier:PyCdlibInternalError; 316, argument_list; 316, 317; 317, string:'Saw a linked record that was neither ISO or UDF'; 318, if_statement; 318, 319; 318, 332; 319, boolean_operator:and; 319, 320; 319, 327; 320, boolean_operator:and; 320, 321; 320, 324; 321, comparison_operator:is; 321, 322; 321, 323; 322, identifier:udf_file_ident; 323, None; 324, comparison_operator:is; 324, 325; 324, 326; 325, identifier:udf_file_entry; 326, None; 327, comparison_operator:is; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:udf_file_ident; 330, identifier:parent; 331, None; 332, block; 332, 333; 332, 345; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:self; 337, identifier:_rm_udf_file_ident; 338, argument_list; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:udf_file_ident; 341, identifier:parent; 342, attribute; 342, 343; 342, 344; 343, identifier:udf_file_ident; 344, identifier:fi; 345, expression_statement; 345, 346; 346, augmented_assignment:+=; 346, 347; 346, 348; 347, identifier:num_bytes_to_remove; 348, call; 348, 349; 348, 354; 349, attribute; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:self; 352, identifier:pvd; 353, identifier:logical_block_size; 354, argument_list; 355, expression_statement; 355, 356; 356, call; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:self; 359, identifier:_finish_remove; 360, argument_list; 360, 361; 360, 362; 361, identifier:num_bytes_to_remove; 362, True | def rm_file(self, iso_path, rr_name=None, joliet_path=None, udf_path=None):
'''
Remove a file from the ISO.
Parameters:
iso_path - The path to the file to remove.
rr_name - The Rock Ridge name of the file to remove.
joliet_path - The Joliet path to the file to remove.
udf_path - The UDF path to the file to remove.
Returns:
Nothing.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInvalidInput('This object is not yet initialized; call either open() or new() to create an ISO')
iso_path_bytes = utils.normpath(iso_path)
if not utils.starts_with_slash(iso_path_bytes):
raise pycdlibexception.PyCdlibInvalidInput('Must be a path starting with /')
child = self._find_iso_record(iso_path_bytes)
if not child.is_file():
raise pycdlibexception.PyCdlibInvalidInput('Cannot remove a directory with rm_file (try rm_directory instead)')
if self.eltorito_boot_catalog is not None:
if any([id(child) == id(rec) for rec in self.eltorito_boot_catalog.dirrecords]):
raise pycdlibexception.PyCdlibInvalidInput("Cannot remove a file that is referenced by El Torito; either use 'rm_eltorito' to remove El Torito first, or use 'rm_hard_link' to hide the entry")
eltorito_entries = {}
eltorito_entries[id(self.eltorito_boot_catalog.initial_entry.inode)] = True
for sec in self.eltorito_boot_catalog.sections:
for entry in sec.section_entries:
eltorito_entries[id(entry.inode)] = True
if id(child.inode) in eltorito_entries:
raise pycdlibexception.PyCdlibInvalidInput("Cannot remove a file that is referenced by El Torito; either use 'rm_eltorito' to remove El Torito first, or use 'rm_hard_link' to hide the entry")
num_bytes_to_remove = 0
udf_file_ident = None
udf_file_entry = None
if udf_path is not None:
if self.udf_root is None:
raise pycdlibexception.PyCdlibInvalidInput('Can only specify a udf_path for a UDF ISO')
udf_path_bytes = utils.normpath(udf_path)
(udf_file_ident, udf_file_entry) = self._find_udf_record(udf_path_bytes)
if child.inode is None:
num_bytes_to_remove += self._remove_child_from_dr(child,
child.index_in_parent,
self.pvd.logical_block_size())
else:
while child.inode.linked_records:
rec = child.inode.linked_records[0]
if isinstance(rec, dr.DirectoryRecord):
num_bytes_to_remove += self._rm_dr_link(rec)
elif isinstance(rec, udfmod.UDFFileEntry):
num_bytes_to_remove += self._rm_udf_link(rec)
else:
raise pycdlibexception.PyCdlibInternalError('Saw a linked record that was neither ISO or UDF')
if udf_file_ident is not None and udf_file_entry is None and udf_file_ident.parent is not None:
self._rm_udf_file_ident(udf_file_ident.parent, udf_file_ident.fi)
num_bytes_to_remove += self.pvd.logical_block_size()
self._finish_remove(num_bytes_to_remove, True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_record; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 23; 7, 27; 7, 60; 7, 72; 7, 93; 7, 114; 7, 128; 8, expression_statement; 8, 9; 9, string:'''
Get the directory record for a particular path.
Parameters:
iso_path - The absolute path on the ISO9660 filesystem to get the
record for.
rr_path - The absolute path on the Rock Ridge filesystem to get the
record for.
joliet_path - The absolute path on the Joliet filesystem to get the
record for.
udf_path - The absolute path on the UDF filesystem to get the record
for.
Returns:
An object that represents the path. This may be a dr.DirectoryRecord
object (in the cases of iso_path, rr_path, or joliet_path), or a
udf.UDFFileEntry object (in the case of udf_path).
'''; 10, if_statement; 10, 11; 10, 15; 11, not_operator; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_initialized; 15, block; 15, 16; 16, raise_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:pycdlibexception; 20, identifier:PyCdlibInvalidInput; 21, argument_list; 21, 22; 22, string:'This object is not yet initialized; call either open() or new() to create an ISO'; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:num_paths; 26, integer:0; 27, for_statement; 27, 28; 27, 29; 27, 30; 28, identifier:key; 29, identifier:kwargs; 30, block; 30, 31; 31, if_statement; 31, 32; 31, 39; 31, 51; 32, comparison_operator:in; 32, 33; 32, 34; 33, identifier:key; 34, list:['joliet_path', 'rr_path', 'iso_path', 'udf_path']; 34, 35; 34, 36; 34, 37; 34, 38; 35, string:'joliet_path'; 36, string:'rr_path'; 37, string:'iso_path'; 38, string:'udf_path'; 39, block; 39, 40; 40, if_statement; 40, 41; 40, 46; 41, comparison_operator:is; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:kwargs; 44, identifier:key; 45, None; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, augmented_assignment:+=; 48, 49; 48, 50; 49, identifier:num_paths; 50, integer:1; 51, else_clause; 51, 52; 52, block; 52, 53; 53, raise_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:pycdlibexception; 57, identifier:PyCdlibInvalidInput; 58, argument_list; 58, 59; 59, string:"Invalid keyword, must be one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'"; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:!=; 61, 62; 61, 63; 62, identifier:num_paths; 63, integer:1; 64, block; 64, 65; 65, raise_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:pycdlibexception; 69, identifier:PyCdlibInvalidInput; 70, argument_list; 70, 71; 71, string:"Must specify one, and only one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'"; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:in; 73, 74; 73, 75; 74, string:'joliet_path'; 75, identifier:kwargs; 76, block; 76, 77; 77, return_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:_get_entry; 82, argument_list; 82, 83; 82, 84; 82, 85; 83, None; 84, None; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:_normalize_joliet_path; 89, argument_list; 89, 90; 90, subscript; 90, 91; 90, 92; 91, identifier:kwargs; 92, string:'joliet_path'; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:in; 94, 95; 94, 96; 95, string:'rr_path'; 96, identifier:kwargs; 97, block; 97, 98; 98, return_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:_get_entry; 103, argument_list; 103, 104; 103, 105; 103, 113; 104, None; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:utils; 108, identifier:normpath; 109, argument_list; 109, 110; 110, subscript; 110, 111; 110, 112; 111, identifier:kwargs; 112, string:'rr_path'; 113, None; 114, if_statement; 114, 115; 114, 118; 115, comparison_operator:in; 115, 116; 115, 117; 116, string:'udf_path'; 117, identifier:kwargs; 118, block; 118, 119; 119, return_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:_get_udf_entry; 124, argument_list; 124, 125; 125, subscript; 125, 126; 125, 127; 126, identifier:kwargs; 127, string:'udf_path'; 128, return_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:_get_entry; 133, argument_list; 133, 134; 133, 142; 133, 143; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:utils; 137, identifier:normpath; 138, argument_list; 138, 139; 139, subscript; 139, 140; 139, 141; 140, identifier:kwargs; 141, string:'iso_path'; 142, None; 143, None | def get_record(self, **kwargs):
'''
Get the directory record for a particular path.
Parameters:
iso_path - The absolute path on the ISO9660 filesystem to get the
record for.
rr_path - The absolute path on the Rock Ridge filesystem to get the
record for.
joliet_path - The absolute path on the Joliet filesystem to get the
record for.
udf_path - The absolute path on the UDF filesystem to get the record
for.
Returns:
An object that represents the path. This may be a dr.DirectoryRecord
object (in the cases of iso_path, rr_path, or joliet_path), or a
udf.UDFFileEntry object (in the case of udf_path).
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInvalidInput('This object is not yet initialized; call either open() or new() to create an ISO')
num_paths = 0
for key in kwargs:
if key in ['joliet_path', 'rr_path', 'iso_path', 'udf_path']:
if kwargs[key] is not None:
num_paths += 1
else:
raise pycdlibexception.PyCdlibInvalidInput("Invalid keyword, must be one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'")
if num_paths != 1:
raise pycdlibexception.PyCdlibInvalidInput("Must specify one, and only one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'")
if 'joliet_path' in kwargs:
return self._get_entry(None, None, self._normalize_joliet_path(kwargs['joliet_path']))
if 'rr_path' in kwargs:
return self._get_entry(None, utils.normpath(kwargs['rr_path']), None)
if 'udf_path' in kwargs:
return self._get_udf_entry(kwargs['udf_path'])
return self._get_entry(utils.normpath(kwargs['iso_path']), None, None) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:full_path_from_dirrecord; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:rec; 6, default_parameter; 6, 7; 6, 8; 7, identifier:rockridge; 8, False; 9, block; 9, 10; 9, 12; 9, 25; 9, 29; 9, 234; 9, 250; 10, expression_statement; 10, 11; 11, string:'''
A method to get the absolute path of a directory record.
Parameters:
rec - The directory record to get the full path for.
rockridge - Whether to get the rock ridge full path.
Returns:
A string representing the absolute path to the file on the ISO.
'''; 12, if_statement; 12, 13; 12, 17; 13, not_operator; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_initialized; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:pycdlibexception; 22, identifier:PyCdlibInvalidInput; 23, argument_list; 23, 24; 24, string:'This object is not yet initialized; call either open() or new() to create an ISO'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:ret; 28, string:b''; 29, if_statement; 29, 30; 29, 37; 29, 157; 30, call; 30, 31; 30, 32; 31, identifier:isinstance; 32, argument_list; 32, 33; 32, 34; 33, identifier:rec; 34, attribute; 34, 35; 34, 36; 35, identifier:dr; 36, identifier:DirectoryRecord; 37, block; 37, 38; 37, 42; 37, 67; 37, 76; 37, 83; 37, 99; 37, 103; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:encoding; 41, string:'utf-8'; 42, if_statement; 42, 43; 42, 62; 43, boolean_operator:and; 43, 44; 43, 49; 44, comparison_operator:is; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:joliet_vd; 48, None; 49, comparison_operator:==; 49, 50; 49, 56; 50, call; 50, 51; 50, 52; 51, identifier:id; 52, argument_list; 52, 53; 53, attribute; 53, 54; 53, 55; 54, identifier:rec; 55, identifier:vd; 56, call; 56, 57; 56, 58; 57, identifier:id; 58, argument_list; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:joliet_vd; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:encoding; 66, string:'utf-16_be'; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:slash; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:'/'; 73, identifier:encode; 74, argument_list; 74, 75; 75, identifier:encoding; 76, if_statement; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:rec; 79, identifier:is_root; 80, block; 80, 81; 81, return_statement; 81, 82; 82, string:'/'; 83, if_statement; 83, 84; 83, 91; 84, boolean_operator:and; 84, 85; 84, 86; 85, identifier:rockridge; 86, comparison_operator:is; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:rec; 89, identifier:rock_ridge; 90, None; 91, block; 91, 92; 92, raise_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:pycdlibexception; 96, identifier:PyCdlibInvalidInput; 97, argument_list; 97, 98; 98, string:'Cannot generate a Rock Ridge path on a non-Rock Ridge ISO'; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:parent; 102, identifier:rec; 103, while_statement; 103, 104; 103, 107; 104, comparison_operator:is; 104, 105; 104, 106; 105, identifier:parent; 106, None; 107, block; 107, 108; 107, 151; 108, if_statement; 108, 109; 108, 113; 109, not_operator; 109, 110; 110, attribute; 110, 111; 110, 112; 111, identifier:parent; 112, identifier:is_root; 113, block; 113, 114; 114, if_statement; 114, 115; 114, 122; 114, 137; 115, boolean_operator:and; 115, 116; 115, 117; 116, identifier:rockridge; 117, comparison_operator:is; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:parent; 120, identifier:rock_ridge; 121, None; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:ret; 126, binary_operator:+; 126, 127; 126, 136; 127, binary_operator:+; 127, 128; 127, 129; 128, identifier:slash; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:parent; 133, identifier:rock_ridge; 134, identifier:name; 135, argument_list; 136, identifier:ret; 137, else_clause; 137, 138; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:ret; 142, binary_operator:+; 142, 143; 142, 150; 143, binary_operator:+; 143, 144; 143, 145; 144, identifier:slash; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:parent; 148, identifier:file_identifier; 149, argument_list; 150, identifier:ret; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:parent; 154, attribute; 154, 155; 154, 156; 155, identifier:parent; 156, identifier:parent; 157, else_clause; 157, 158; 158, block; 158, 159; 158, 168; 158, 189; 158, 198; 158, 202; 159, if_statement; 159, 160; 159, 165; 160, comparison_operator:is; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:rec; 163, identifier:parent; 164, None; 165, block; 165, 166; 166, return_statement; 166, 167; 167, string:'/'; 168, if_statement; 168, 169; 168, 174; 168, 183; 169, comparison_operator:is; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:rec; 172, identifier:file_ident; 173, None; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:encoding; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:rec; 181, identifier:file_ident; 182, identifier:encoding; 183, else_clause; 183, 184; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:encoding; 188, string:'utf-8'; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:slash; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, string:'/'; 195, identifier:encode; 196, argument_list; 196, 197; 197, identifier:encoding; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:udfparent; 201, identifier:rec; 202, while_statement; 202, 203; 202, 206; 203, comparison_operator:is; 203, 204; 203, 205; 204, identifier:udfparent; 205, None; 206, block; 206, 207; 206, 215; 206, 228; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:ident; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:udfparent; 213, identifier:file_identifier; 214, argument_list; 215, if_statement; 215, 216; 215, 219; 216, comparison_operator:!=; 216, 217; 216, 218; 217, identifier:ident; 218, string:b'/'; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:ret; 223, binary_operator:+; 223, 224; 223, 227; 224, binary_operator:+; 224, 225; 224, 226; 225, identifier:slash; 226, identifier:ident; 227, identifier:ret; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:udfparent; 231, attribute; 231, 232; 231, 233; 232, identifier:udfparent; 233, identifier:parent; 234, if_statement; 234, 235; 234, 242; 235, comparison_operator:>=; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:sys; 238, identifier:version_info; 239, tuple; 239, 240; 239, 241; 240, integer:3; 241, integer:0; 242, block; 242, 243; 243, return_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:ret; 247, identifier:decode; 248, argument_list; 248, 249; 249, identifier:encoding; 250, return_statement; 250, 251; 251, call; 251, 252; 251, 260; 252, attribute; 252, 253; 252, 259; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:ret; 256, identifier:decode; 257, argument_list; 257, 258; 258, identifier:encoding; 259, identifier:encode; 260, argument_list; 260, 261; 261, string:'utf-8' | def full_path_from_dirrecord(self, rec, rockridge=False):
'''
A method to get the absolute path of a directory record.
Parameters:
rec - The directory record to get the full path for.
rockridge - Whether to get the rock ridge full path.
Returns:
A string representing the absolute path to the file on the ISO.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInvalidInput('This object is not yet initialized; call either open() or new() to create an ISO')
ret = b''
if isinstance(rec, dr.DirectoryRecord):
encoding = 'utf-8'
if self.joliet_vd is not None and id(rec.vd) == id(self.joliet_vd):
encoding = 'utf-16_be'
slash = '/'.encode(encoding)
if rec.is_root:
return '/'
if rockridge and rec.rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidInput('Cannot generate a Rock Ridge path on a non-Rock Ridge ISO')
parent = rec
while parent is not None:
if not parent.is_root:
if rockridge and parent.rock_ridge is not None:
ret = slash + parent.rock_ridge.name() + ret
else:
ret = slash + parent.file_identifier() + ret
parent = parent.parent
else:
if rec.parent is None:
return '/'
if rec.file_ident is not None:
encoding = rec.file_ident.encoding
else:
encoding = 'utf-8'
slash = '/'.encode(encoding)
udfparent = rec
while udfparent is not None:
ident = udfparent.file_identifier()
if ident != b'/':
ret = slash + ident + ret
udfparent = udfparent.parent
if sys.version_info >= (3, 0):
return ret.decode(encoding)
return ret.decode(encoding).encode('utf-8') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_update_bird_conf_file; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:operation; 6, block; 6, 7; 6, 11; 6, 15; 6, 21; 6, 31; 6, 41; 6, 52; 6, 63; 6, 97; 6, 120; 6, 150; 6, 166; 6, 208; 6, 220; 6, 235; 6, 250; 6, 260; 6, 307; 6, 327; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:conf_updated; 10, False; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:prefixes; 14, list:[]; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:ip_version; 18, attribute; 18, 19; 18, 20; 19, identifier:operation; 20, identifier:ip_version; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:config_file; 24, subscript; 24, 25; 24, 30; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:bird_configuration; 29, identifier:ip_version; 30, string:'config_file'; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:variable_name; 34, subscript; 34, 35; 34, 40; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:bird_configuration; 39, identifier:ip_version; 40, string:'variable_name'; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 42, 45; 43, identifier:changes_counter; 44, line_continuation:\; 45, subscript; 45, 46; 45, 51; 46, subscript; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:bird_configuration; 50, identifier:ip_version; 51, string:'changes_counter'; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 53, 56; 54, identifier:dummy_ip_prefix; 55, line_continuation:\; 56, subscript; 56, 57; 56, 62; 57, subscript; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:bird_configuration; 61, identifier:ip_version; 62, string:'dummy_ip_prefix'; 63, try_statement; 63, 64; 63, 72; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:prefixes; 68, call; 68, 69; 68, 70; 69, identifier:get_ip_prefixes_from_bird; 70, argument_list; 70, 71; 71, identifier:config_file; 72, except_clause; 72, 73; 72, 77; 73, as_pattern; 73, 74; 73, 75; 74, identifier:OSError; 75, as_pattern_target; 75, 76; 76, identifier:error; 77, block; 77, 78; 77, 90; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:log; 84, identifier:error; 85, argument_list; 85, 86; 85, 89; 86, concatenated_string; 86, 87; 86, 88; 87, string:"failed to open Bird configuration %s, this is a "; 88, string:"FATAL error, thus exiting main program"; 89, identifier:error; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:sys; 94, identifier:exit; 95, argument_list; 95, 96; 96, integer:1; 97, if_statement; 97, 98; 97, 100; 98, not_operator; 98, 99; 99, identifier:prefixes; 100, block; 100, 101; 100, 113; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:log; 107, identifier:error; 108, argument_list; 108, 109; 108, 112; 109, concatenated_string; 109, 110; 109, 111; 110, string:"found empty bird configuration %s, this is a FATAL"; 111, string:" error, thus exiting main program"; 112, identifier:config_file; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:sys; 117, identifier:exit; 118, argument_list; 118, 119; 119, integer:1; 120, if_statement; 120, 121; 120, 124; 121, comparison_operator:not; 121, 122; 121, 123; 122, identifier:dummy_ip_prefix; 123, identifier:prefixes; 124, block; 124, 125; 124, 138; 124, 146; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:log; 131, identifier:warning; 132, argument_list; 132, 133; 132, 137; 133, concatenated_string; 133, 134; 133, 135; 133, 136; 134, string:"dummy IP prefix %s wasn't found in bird "; 135, string:"configuration, adding it. This shouldn't have "; 136, string:"happened!"; 137, identifier:dummy_ip_prefix; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:prefixes; 142, identifier:insert; 143, argument_list; 143, 144; 143, 145; 144, integer:0; 145, identifier:dummy_ip_prefix; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:conf_updated; 149, True; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:ip_prefixes_without_check; 153, call; 153, 154; 153, 160; 154, attribute; 154, 155; 154, 159; 155, call; 155, 156; 155, 157; 156, identifier:set; 157, argument_list; 157, 158; 158, identifier:prefixes; 159, identifier:difference; 160, argument_list; 160, 161; 161, subscript; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:ip_prefixes; 165, identifier:ip_version; 166, if_statement; 166, 167; 166, 168; 167, identifier:ip_prefixes_without_check; 168, block; 168, 169; 168, 189; 168, 204; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:log; 175, identifier:warning; 176, argument_list; 176, 177; 176, 183; 177, concatenated_string; 177, 178; 177, 179; 177, 180; 177, 181; 177, 182; 178, string:"found %s IP prefixes in Bird configuration but "; 179, string:"we aren't configured to run health checks on "; 180, string:"them. Either someone modified the configuration "; 181, string:"manually or something went horrible wrong. We "; 182, string:"remove them from Bird configuration"; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, string:','; 186, identifier:join; 187, argument_list; 187, 188; 188, identifier:ip_prefixes_without_check; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 195; 191, subscript; 191, 192; 191, 193; 192, identifier:prefixes; 193, slice; 193, 194; 194, colon; 195, generator_expression; 195, 196; 195, 197; 195, 200; 196, identifier:ip; 197, for_in_clause; 197, 198; 197, 199; 198, identifier:ip; 199, identifier:prefixes; 200, if_clause; 200, 201; 201, comparison_operator:not; 201, 202; 201, 203; 202, identifier:ip; 203, identifier:ip_prefixes_without_check; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:conf_updated; 207, True; 208, if_statement; 208, 209; 208, 215; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:operation; 212, identifier:update; 213, argument_list; 213, 214; 214, identifier:prefixes; 215, block; 215, 216; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:conf_updated; 219, True; 220, if_statement; 220, 221; 220, 223; 221, not_operator; 221, 222; 222, identifier:conf_updated; 223, block; 223, 224; 223, 233; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 231; 226, attribute; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:log; 230, identifier:info; 231, argument_list; 231, 232; 232, string:'no updates for bird configuration'; 233, return_statement; 233, 234; 234, identifier:conf_updated; 235, if_statement; 235, 236; 235, 243; 236, subscript; 236, 237; 236, 242; 237, subscript; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:bird_configuration; 241, identifier:ip_version; 242, string:'keep_changes'; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:archive_bird_conf; 247, argument_list; 247, 248; 247, 249; 248, identifier:config_file; 249, identifier:changes_counter; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:tempname; 253, call; 253, 254; 253, 255; 254, identifier:write_temp_bird_conf; 255, argument_list; 255, 256; 255, 257; 255, 258; 255, 259; 256, identifier:dummy_ip_prefix; 257, identifier:config_file; 258, identifier:variable_name; 259, identifier:prefixes; 260, try_statement; 260, 261; 260, 270; 260, 295; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:os; 266, identifier:rename; 267, argument_list; 267, 268; 267, 269; 268, identifier:tempname; 269, identifier:config_file; 270, except_clause; 270, 271; 270, 275; 271, as_pattern; 271, 272; 271, 273; 272, identifier:OSError; 273, as_pattern_target; 273, 274; 274, identifier:error; 275, block; 275, 276; 275, 288; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 283; 278, attribute; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:log; 282, identifier:critical; 283, argument_list; 283, 284; 283, 287; 284, concatenated_string; 284, 285; 284, 286; 285, string:"failed to create Bird configuration %s, this "; 286, string:"is a FATAL error, thus exiting main program"; 287, identifier:error; 288, expression_statement; 288, 289; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:sys; 292, identifier:exit; 293, argument_list; 293, 294; 294, integer:1; 295, else_clause; 295, 296; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 304; 299, attribute; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:self; 302, identifier:log; 303, identifier:info; 304, argument_list; 304, 305; 304, 306; 305, string:"Bird configuration for IPv%s is updated"; 306, identifier:ip_version; 307, if_statement; 307, 308; 307, 314; 308, comparison_operator:==; 308, 309; 308, 313; 309, call; 309, 310; 309, 311; 310, identifier:len; 311, argument_list; 311, 312; 312, identifier:prefixes; 313, integer:1; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 322; 317, attribute; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:self; 320, identifier:log; 321, identifier:warning; 322, argument_list; 322, 323; 323, concatenated_string; 323, 324; 323, 325; 323, 326; 324, string:"Bird configuration doesn't have IP prefixes for "; 325, string:"any of the services we monitor! It means local "; 326, string:"node doesn't receive any traffic"; 327, return_statement; 327, 328; 328, identifier:conf_updated | def _update_bird_conf_file(self, operation):
conf_updated = False
prefixes = []
ip_version = operation.ip_version
config_file = self.bird_configuration[ip_version]['config_file']
variable_name = self.bird_configuration[ip_version]['variable_name']
changes_counter =\
self.bird_configuration[ip_version]['changes_counter']
dummy_ip_prefix =\
self.bird_configuration[ip_version]['dummy_ip_prefix']
try:
prefixes = get_ip_prefixes_from_bird(config_file)
except OSError as error:
self.log.error("failed to open Bird configuration %s, this is a "
"FATAL error, thus exiting main program", error)
sys.exit(1)
if not prefixes:
self.log.error("found empty bird configuration %s, this is a FATAL"
" error, thus exiting main program", config_file)
sys.exit(1)
if dummy_ip_prefix not in prefixes:
self.log.warning("dummy IP prefix %s wasn't found in bird "
"configuration, adding it. This shouldn't have "
"happened!", dummy_ip_prefix)
prefixes.insert(0, dummy_ip_prefix)
conf_updated = True
ip_prefixes_without_check = set(prefixes).difference(
self.ip_prefixes[ip_version])
if ip_prefixes_without_check:
self.log.warning("found %s IP prefixes in Bird configuration but "
"we aren't configured to run health checks on "
"them. Either someone modified the configuration "
"manually or something went horrible wrong. We "
"remove them from Bird configuration",
','.join(ip_prefixes_without_check))
prefixes[:] = (ip for ip in prefixes
if ip not in ip_prefixes_without_check)
conf_updated = True
if operation.update(prefixes):
conf_updated = True
if not conf_updated:
self.log.info('no updates for bird configuration')
return conf_updated
if self.bird_configuration[ip_version]['keep_changes']:
archive_bird_conf(config_file, changes_counter)
tempname = write_temp_bird_conf(
dummy_ip_prefix,
config_file,
variable_name,
prefixes
)
try:
os.rename(tempname, config_file)
except OSError as error:
self.log.critical("failed to create Bird configuration %s, this "
"is a FATAL error, thus exiting main program",
error)
sys.exit(1)
else:
self.log.info("Bird configuration for IPv%s is updated",
ip_version)
if len(prefixes) == 1:
self.log.warning("Bird configuration doesn't have IP prefixes for "
"any of the services we monitor! It means local "
"node doesn't receive any traffic")
return conf_updated |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:run; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 137; 6, if_statement; 6, 7; 6, 11; 6, 21; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:services; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:log; 18, identifier:warning; 19, argument_list; 19, 20; 20, string:"no service checks are configured"; 21, else_clause; 21, 22; 22, block; 22, 23; 22, 38; 22, 67; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:log; 29, identifier:info; 30, argument_list; 30, 31; 30, 32; 31, string:"going to lunch %s threads"; 32, call; 32, 33; 32, 34; 33, identifier:len; 34, argument_list; 34, 35; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:services; 38, if_statement; 38, 39; 38, 48; 38, 61; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:config; 44, identifier:has_option; 45, argument_list; 45, 46; 45, 47; 46, string:'daemon'; 47, string:'splay_startup'; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:splay_startup; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:config; 57, identifier:getfloat; 58, argument_list; 58, 59; 58, 60; 59, string:'daemon'; 60, string:'splay_startup'; 61, else_clause; 61, 62; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:splay_startup; 66, None; 67, for_statement; 67, 68; 67, 69; 67, 72; 68, identifier:service; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:services; 72, block; 72, 73; 72, 83; 72, 87; 72, 119; 72, 131; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:log; 79, identifier:debug; 80, argument_list; 80, 81; 80, 82; 81, string:"lunching thread for %s"; 82, identifier:service; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:_config; 86, dictionary; 87, for_statement; 87, 88; 87, 91; 87, 96; 88, pattern_list; 88, 89; 88, 90; 89, identifier:option; 90, identifier:getter; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:SERVICE_OPTIONS_TYPE; 94, identifier:items; 95, argument_list; 96, block; 96, 97; 97, try_statement; 97, 98; 97, 115; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:_config; 103, identifier:option; 104, call; 104, 105; 104, 112; 105, call; 105, 106; 105, 107; 106, identifier:getattr; 107, argument_list; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:config; 111, identifier:getter; 112, argument_list; 112, 113; 112, 114; 113, identifier:service; 114, identifier:option; 115, except_clause; 115, 116; 115, 117; 116, identifier:NoOptionError; 117, block; 117, 118; 118, pass_statement; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:_thread; 122, call; 122, 123; 122, 124; 123, identifier:ServiceCheck; 124, argument_list; 124, 125; 124, 126; 124, 127; 124, 130; 125, identifier:service; 126, identifier:_config; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:action; 130, identifier:splay_startup; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:_thread; 135, identifier:start; 136, argument_list; 137, while_statement; 137, 138; 137, 139; 138, True; 139, block; 139, 140; 139, 153; 139, 189; 139, 207; 139, 216; 139, 224; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:operation; 143, call; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:action; 148, identifier:get; 149, argument_list; 149, 150; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:block; 152, True; 153, if_statement; 153, 154; 153, 159; 154, call; 154, 155; 154, 156; 155, identifier:isinstance; 156, argument_list; 156, 157; 156, 158; 157, identifier:operation; 158, identifier:ServiceCheckDiedError; 159, block; 159, 160; 159, 169; 159, 182; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 167; 162, attribute; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:log; 166, identifier:critical; 167, argument_list; 167, 168; 168, identifier:operation; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:log; 175, identifier:critical; 176, argument_list; 176, 177; 177, concatenated_string; 177, 178; 177, 179; 177, 180; 177, 181; 178, string:"This is a fatal error and the only way to "; 179, string:"recover is to restart, thus exiting with a "; 180, string:"non-zero code and let systemd act by "; 181, string:"triggering a restart"; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:sys; 186, identifier:exit; 187, argument_list; 187, 188; 188, integer:1; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 196; 191, attribute; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:log; 195, identifier:info; 196, argument_list; 196, 197; 196, 200; 196, 203; 196, 206; 197, concatenated_string; 197, 198; 197, 199; 198, string:"returned an item from the queue for %s with IP "; 199, string:"prefix %s and action to %s Bird configuration"; 200, attribute; 200, 201; 200, 202; 201, identifier:operation; 202, identifier:name; 203, attribute; 203, 204; 203, 205; 204, identifier:operation; 205, identifier:ip_prefix; 206, identifier:operation; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:bird_updated; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:_update_bird_conf_file; 214, argument_list; 214, 215; 215, identifier:operation; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:action; 222, identifier:task_done; 223, argument_list; 224, if_statement; 224, 225; 224, 226; 225, identifier:bird_updated; 226, block; 226, 227; 226, 233; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:ip_version; 230, attribute; 230, 231; 230, 232; 231, identifier:operation; 232, identifier:ip_version; 233, if_statement; 233, 234; 233, 239; 233, 251; 234, comparison_operator:is; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:operation; 237, identifier:bird_reconfigure_cmd; 238, None; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 243; 242, identifier:reconfigure_bird; 243, argument_list; 243, 244; 244, subscript; 244, 245; 244, 250; 245, subscript; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:bird_configuration; 249, identifier:ip_version; 250, string:'reconfigure_cmd'; 251, else_clause; 251, 252; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 256; 255, identifier:run_custom_bird_reconfigure; 256, argument_list; 256, 257; 257, identifier:operation | def run(self):
if not self.services:
self.log.warning("no service checks are configured")
else:
self.log.info("going to lunch %s threads", len(self.services))
if self.config.has_option('daemon', 'splay_startup'):
splay_startup = self.config.getfloat('daemon', 'splay_startup')
else:
splay_startup = None
for service in self.services:
self.log.debug("lunching thread for %s", service)
_config = {}
for option, getter in SERVICE_OPTIONS_TYPE.items():
try:
_config[option] = getattr(self.config, getter)(service,
option)
except NoOptionError:
pass
_thread = ServiceCheck(service, _config, self.action,
splay_startup)
_thread.start()
while True:
operation = self.action.get(block=True)
if isinstance(operation, ServiceCheckDiedError):
self.log.critical(operation)
self.log.critical("This is a fatal error and the only way to "
"recover is to restart, thus exiting with a "
"non-zero code and let systemd act by "
"triggering a restart")
sys.exit(1)
self.log.info("returned an item from the queue for %s with IP "
"prefix %s and action to %s Bird configuration",
operation.name,
operation.ip_prefix,
operation)
bird_updated = self._update_bird_conf_file(operation)
self.action.task_done()
if bird_updated:
ip_version = operation.ip_version
if operation.bird_reconfigure_cmd is None:
reconfigure_bird(
self.bird_configuration[ip_version]['reconfigure_cmd'])
else:
run_custom_bird_reconfigure(operation) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:modify_ip_prefixes; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:config; 5, identifier:config_file; 6, identifier:variable_name; 7, identifier:dummy_ip_prefix; 8, identifier:reconfigure_cmd; 9, identifier:keep_changes; 10, identifier:changes_counter; 11, identifier:ip_version; 12, block; 12, 13; 12, 22; 12, 30; 12, 37; 12, 41; 12, 73; 12, 80; 12, 117; 12, 145; 12, 154; 12, 161; 12, 173; 12, 238; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:log; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:logging; 19, identifier:getLogger; 20, argument_list; 20, 21; 21, identifier:PROGRAM_NAME; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:services; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:config; 28, identifier:sections; 29, argument_list; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:services; 34, identifier:remove; 35, argument_list; 35, 36; 36, string:'daemon'; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:update_bird_conf; 40, False; 41, try_statement; 41, 42; 41, 50; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:ip_prefixes_in_bird; 46, call; 46, 47; 46, 48; 47, identifier:get_ip_prefixes_from_bird; 48, argument_list; 48, 49; 49, identifier:config_file; 50, except_clause; 50, 51; 50, 55; 51, as_pattern; 51, 52; 51, 53; 52, identifier:OSError; 53, as_pattern_target; 53, 54; 54, identifier:error; 55, block; 55, 56; 55, 66; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:log; 60, identifier:error; 61, argument_list; 61, 62; 61, 65; 62, concatenated_string; 62, 63; 62, 64; 63, string:"failed to open Bird configuration %s, this is a FATAL "; 64, string:"error, thus exiting main program"; 65, identifier:error; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:sys; 70, identifier:exit; 71, argument_list; 71, 72; 72, integer:1; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:_name; 76, call; 76, 77; 76, 78; 77, identifier:get_variable_name_from_bird; 78, argument_list; 78, 79; 79, identifier:config_file; 80, if_statement; 80, 81; 80, 84; 80, 97; 81, comparison_operator:is; 81, 82; 81, 83; 82, identifier:_name; 83, None; 84, block; 84, 85; 84, 93; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:log; 89, identifier:warning; 90, argument_list; 90, 91; 90, 92; 91, string:"failed to find variable name in %s, going to add it"; 92, identifier:config_file; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:update_bird_conf; 96, True; 97, elif_clause; 97, 98; 97, 101; 98, comparison_operator:!=; 98, 99; 98, 100; 99, identifier:_name; 100, identifier:variable_name; 101, block; 101, 102; 101, 113; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:log; 106, identifier:warning; 107, argument_list; 107, 108; 107, 111; 107, 112; 108, concatenated_string; 108, 109; 108, 110; 109, string:"found incorrect variable name in %s, going to add the "; 110, string:"correct one %s"; 111, identifier:_name; 112, identifier:variable_name; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:update_bird_conf; 116, True; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:not; 118, 119; 118, 120; 119, identifier:dummy_ip_prefix; 120, identifier:ip_prefixes_in_bird; 121, block; 121, 122; 121, 133; 121, 141; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:log; 126, identifier:warning; 127, argument_list; 127, 128; 127, 131; 127, 132; 128, concatenated_string; 128, 129; 128, 130; 129, string:"dummy IP prefix %s is missing from bird configuration "; 130, string:"%s, adding it"; 131, identifier:dummy_ip_prefix; 132, identifier:config_file; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:ip_prefixes_in_bird; 137, identifier:insert; 138, argument_list; 138, 139; 138, 140; 139, integer:0; 140, identifier:dummy_ip_prefix; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:update_bird_conf; 144, True; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:ip_prefixes_with_check; 148, call; 148, 149; 148, 150; 149, identifier:get_ip_prefixes_from_config; 150, argument_list; 150, 151; 150, 152; 150, 153; 151, identifier:config; 152, identifier:services; 153, identifier:ip_version; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:ip_prefixes_with_check; 158, identifier:add; 159, argument_list; 159, 160; 160, identifier:dummy_ip_prefix; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:ip_prefixes_without_check; 164, call; 164, 165; 164, 171; 165, attribute; 165, 166; 165, 170; 166, call; 166, 167; 166, 168; 167, identifier:set; 168, argument_list; 168, 169; 169, identifier:ip_prefixes_in_bird; 170, identifier:difference; 171, argument_list; 171, 172; 172, identifier:ip_prefixes_with_check; 173, if_statement; 173, 174; 173, 175; 174, identifier:ip_prefixes_without_check; 175, block; 175, 176; 176, if_statement; 176, 177; 176, 184; 176, 220; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:config; 180, identifier:getboolean; 181, argument_list; 181, 182; 181, 183; 182, string:'daemon'; 183, string:'purge_ip_prefixes'; 184, block; 184, 185; 184, 201; 184, 216; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:log; 189, identifier:warning; 190, argument_list; 190, 191; 190, 194; 190, 200; 191, concatenated_string; 191, 192; 191, 193; 192, string:"removing IP prefix(es) %s from %s because they don't "; 193, string:"have a service check configured"; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, string:','; 197, identifier:join; 198, argument_list; 198, 199; 199, identifier:ip_prefixes_without_check; 200, identifier:config_file; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 207; 203, subscript; 203, 204; 203, 205; 204, identifier:ip_prefixes_in_bird; 205, slice; 205, 206; 206, colon; 207, generator_expression; 207, 208; 207, 209; 207, 212; 208, identifier:ip; 209, for_in_clause; 209, 210; 209, 211; 210, identifier:ip; 211, identifier:ip_prefixes_in_bird; 212, if_clause; 212, 213; 213, comparison_operator:not; 213, 214; 213, 215; 214, identifier:ip; 215, identifier:ip_prefixes_without_check; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:update_bird_conf; 219, True; 220, else_clause; 220, 221; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:log; 226, identifier:warning; 227, argument_list; 227, 228; 227, 231; 227, 237; 228, concatenated_string; 228, 229; 228, 230; 229, string:"found IP prefixes %s in %s without a service "; 230, string:"check configured"; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, string:','; 234, identifier:join; 235, argument_list; 235, 236; 236, identifier:ip_prefixes_without_check; 237, identifier:config_file; 238, if_statement; 238, 239; 238, 240; 239, identifier:update_bird_conf; 240, block; 240, 241; 240, 250; 240, 260; 241, if_statement; 241, 242; 241, 243; 242, identifier:keep_changes; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:archive_bird_conf; 247, argument_list; 247, 248; 247, 249; 248, identifier:config_file; 249, identifier:changes_counter; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:tempname; 253, call; 253, 254; 253, 255; 254, identifier:write_temp_bird_conf; 255, argument_list; 255, 256; 255, 257; 255, 258; 255, 259; 256, identifier:dummy_ip_prefix; 257, identifier:config_file; 258, identifier:variable_name; 259, identifier:ip_prefixes_in_bird; 260, try_statement; 260, 261; 260, 270; 260, 304; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:os; 266, identifier:rename; 267, argument_list; 267, 268; 267, 269; 268, identifier:tempname; 269, identifier:config_file; 270, except_clause; 270, 271; 270, 275; 271, as_pattern; 271, 272; 271, 273; 272, identifier:OSError; 273, as_pattern_target; 273, 274; 274, identifier:error; 275, block; 275, 276; 275, 290; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:msg; 279, parenthesized_expression; 279, 280; 280, call; 280, 281; 280, 286; 281, attribute; 281, 282; 281, 285; 282, concatenated_string; 282, 283; 282, 284; 283, string:"CRITICAL: failed to create Bird configuration {e}, "; 284, string:"this is FATAL error, thus exiting main program"; 285, identifier:format; 286, argument_list; 286, 287; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:e; 289, identifier:error; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:sys; 294, identifier:exit; 295, argument_list; 295, 296; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, string:"{m}"; 299, identifier:format; 300, argument_list; 300, 301; 301, keyword_argument; 301, 302; 301, 303; 302, identifier:m; 303, identifier:msg; 304, else_clause; 304, 305; 305, block; 305, 306; 305, 314; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:log; 310, identifier:info; 311, argument_list; 311, 312; 311, 313; 312, string:"Bird configuration for IPv%s is updated"; 313, identifier:ip_version; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 317; 316, identifier:reconfigure_bird; 317, argument_list; 317, 318; 318, identifier:reconfigure_cmd | def modify_ip_prefixes(
config,
config_file,
variable_name,
dummy_ip_prefix,
reconfigure_cmd,
keep_changes,
changes_counter,
ip_version):
log = logging.getLogger(PROGRAM_NAME)
services = config.sections()
services.remove('daemon')
update_bird_conf = False
try:
ip_prefixes_in_bird = get_ip_prefixes_from_bird(config_file)
except OSError as error:
log.error("failed to open Bird configuration %s, this is a FATAL "
"error, thus exiting main program", error)
sys.exit(1)
_name = get_variable_name_from_bird(config_file)
if _name is None:
log.warning("failed to find variable name in %s, going to add it",
config_file)
update_bird_conf = True
elif _name != variable_name:
log.warning("found incorrect variable name in %s, going to add the "
"correct one %s", _name, variable_name)
update_bird_conf = True
if dummy_ip_prefix not in ip_prefixes_in_bird:
log.warning("dummy IP prefix %s is missing from bird configuration "
"%s, adding it", dummy_ip_prefix, config_file)
ip_prefixes_in_bird.insert(0, dummy_ip_prefix)
update_bird_conf = True
ip_prefixes_with_check = get_ip_prefixes_from_config(
config,
services,
ip_version)
ip_prefixes_with_check.add(dummy_ip_prefix)
ip_prefixes_without_check = set(ip_prefixes_in_bird).difference(
ip_prefixes_with_check)
if ip_prefixes_without_check:
if config.getboolean('daemon', 'purge_ip_prefixes'):
log.warning("removing IP prefix(es) %s from %s because they don't "
"have a service check configured",
','.join(ip_prefixes_without_check),
config_file)
ip_prefixes_in_bird[:] = (ip for ip in ip_prefixes_in_bird
if ip not in ip_prefixes_without_check)
update_bird_conf = True
else:
log.warning("found IP prefixes %s in %s without a service "
"check configured",
','.join(ip_prefixes_without_check),
config_file)
if update_bird_conf:
if keep_changes:
archive_bird_conf(config_file, changes_counter)
tempname = write_temp_bird_conf(
dummy_ip_prefix,
config_file,
variable_name,
ip_prefixes_in_bird
)
try:
os.rename(tempname, config_file)
except OSError as error:
msg = ("CRITICAL: failed to create Bird configuration {e}, "
"this is FATAL error, thus exiting main program"
.format(e=error))
sys.exit("{m}".format(m=msg))
else:
log.info("Bird configuration for IPv%s is updated", ip_version)
reconfigure_bird(reconfigure_cmd) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:load_configuration; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:config_file; 5, identifier:config_dir; 6, identifier:service_file; 7, block; 7, 8; 7, 13; 7, 21; 7, 28; 7, 53; 7, 144; 7, 166; 7, 171; 7, 178; 7, 183; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:config_files; 11, list:[config_file]; 11, 12; 12, identifier:config_file; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:config; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:configparser; 19, identifier:ConfigParser; 20, argument_list; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:config; 25, identifier:read_dict; 26, argument_list; 26, 27; 27, identifier:DEFAULT_OPTIONS; 28, if_statement; 28, 29; 28, 38; 29, not_operator; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:os; 34, identifier:path; 35, identifier:isfile; 36, argument_list; 36, 37; 37, identifier:config_file; 38, block; 38, 39; 39, raise_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:ValueError; 42, argument_list; 42, 43; 43, call; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, concatenated_string; 45, 46; 45, 47; 46, string:"{f} configuration file either isn't readable or "; 47, string:"doesn't exist"; 48, identifier:format; 49, argument_list; 49, 50; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:f; 52, identifier:config_file; 53, if_statement; 53, 54; 53, 57; 53, 92; 54, comparison_operator:is; 54, 55; 54, 56; 55, identifier:service_file; 56, None; 57, block; 57, 58; 58, if_statement; 58, 59; 58, 68; 58, 83; 59, not_operator; 59, 60; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:os; 64, identifier:path; 65, identifier:isfile; 66, argument_list; 66, 67; 67, identifier:service_file; 68, block; 68, 69; 69, raise_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:ValueError; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, concatenated_string; 75, 76; 75, 77; 76, string:"{f} configuration file for a service check "; 77, string:"doesn't exist"; 78, identifier:format; 79, argument_list; 79, 80; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:f; 82, identifier:service_file; 83, else_clause; 83, 84; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:config_files; 89, identifier:append; 90, argument_list; 90, 91; 91, identifier:service_file; 92, elif_clause; 92, 93; 92, 96; 93, comparison_operator:is; 93, 94; 93, 95; 94, identifier:config_dir; 95, None; 96, block; 96, 97; 97, if_statement; 97, 98; 97, 107; 97, 122; 98, not_operator; 98, 99; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:os; 103, identifier:path; 104, identifier:isdir; 105, argument_list; 105, 106; 106, identifier:config_dir; 107, block; 107, 108; 108, raise_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:ValueError; 111, argument_list; 111, 112; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, concatenated_string; 114, 115; 114, 116; 115, string:"{d} directory with configuration files for "; 116, string:"service checks doesn't exist"; 117, identifier:format; 118, argument_list; 118, 119; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:d; 121, identifier:config_dir; 122, else_clause; 122, 123; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:config_files; 128, identifier:extend; 129, argument_list; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:glob; 133, identifier:glob; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 141; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:os; 139, identifier:path; 140, identifier:join; 141, argument_list; 141, 142; 141, 143; 142, identifier:config_dir; 143, string:'*.conf'; 144, try_statement; 144, 145; 144, 153; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:config; 150, identifier:read; 151, argument_list; 151, 152; 152, identifier:config_files; 153, except_clause; 153, 154; 153, 160; 154, as_pattern; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:configparser; 157, identifier:Error; 158, as_pattern_target; 158, 159; 159, identifier:exc; 160, block; 160, 161; 161, raise_statement; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:ValueError; 164, argument_list; 164, 165; 165, identifier:exc; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:configuration_check; 169, argument_list; 169, 170; 170, identifier:config; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:bird_configuration; 174, call; 174, 175; 174, 176; 175, identifier:build_bird_configuration; 176, argument_list; 176, 177; 177, identifier:config; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:create_bird_config_files; 181, argument_list; 181, 182; 182, identifier:bird_configuration; 183, return_statement; 183, 184; 184, expression_list; 184, 185; 184, 186; 185, identifier:config; 186, identifier:bird_configuration | def load_configuration(config_file, config_dir, service_file):
config_files = [config_file]
config = configparser.ConfigParser()
config.read_dict(DEFAULT_OPTIONS)
if not os.path.isfile(config_file):
raise ValueError("{f} configuration file either isn't readable or "
"doesn't exist".format(f=config_file))
if service_file is not None:
if not os.path.isfile(service_file):
raise ValueError("{f} configuration file for a service check "
"doesn't exist".format(f=service_file))
else:
config_files.append(service_file)
elif config_dir is not None:
if not os.path.isdir(config_dir):
raise ValueError("{d} directory with configuration files for "
"service checks doesn't exist"
.format(d=config_dir))
else:
config_files.extend(glob.glob(os.path.join(config_dir, '*.conf')))
try:
config.read(config_files)
except configparser.Error as exc:
raise ValueError(exc)
configuration_check(config)
bird_configuration = build_bird_configuration(config)
create_bird_config_files(bird_configuration)
return config, bird_configuration |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:configuration_check; 3, parameters; 3, 4; 4, identifier:config; 5, block; 5, 6; 5, 16; 5, 29; 5, 39; 5, 76; 5, 94; 5, 133; 5, 212; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:log_level; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:config; 12, identifier:get; 13, argument_list; 13, 14; 13, 15; 14, string:'daemon'; 15, string:'loglevel'; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:num_level; 19, call; 19, 20; 19, 21; 20, identifier:getattr; 21, argument_list; 21, 22; 21, 23; 21, 28; 22, identifier:logging; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:log_level; 26, identifier:upper; 27, argument_list; 28, None; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:pidfile; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:config; 35, identifier:get; 36, argument_list; 36, 37; 36, 38; 37, string:'daemon'; 38, string:'pidfile'; 39, if_statement; 39, 40; 39, 56; 40, not_operator; 40, 41; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:os; 45, identifier:path; 46, identifier:isdir; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:os; 52, identifier:path; 53, identifier:dirname; 54, argument_list; 54, 55; 55, identifier:pidfile; 56, block; 56, 57; 57, raise_statement; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:ValueError; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, string:"{d} doesn't exit"; 64, identifier:format; 65, argument_list; 65, 66; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:d; 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, identifier:pidfile; 76, if_statement; 76, 77; 76, 83; 77, not_operator; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:isinstance; 80, argument_list; 80, 81; 80, 82; 81, identifier:num_level; 82, identifier:int; 83, block; 83, 84; 84, raise_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:ValueError; 87, argument_list; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, string:'Invalid log level: {}'; 91, identifier:format; 92, argument_list; 92, 93; 93, identifier:log_level; 94, for_statement; 94, 95; 94, 96; 94, 99; 95, identifier:_file; 96, expression_list; 96, 97; 96, 98; 97, string:'log_file'; 98, string:'stderr_file'; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 108; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:config; 104, identifier:has_option; 105, argument_list; 105, 106; 105, 107; 106, string:'daemon'; 107, identifier:_file; 108, block; 108, 109; 109, try_statement; 109, 110; 109, 122; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:touch; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:config; 118, identifier:get; 119, argument_list; 119, 120; 119, 121; 120, string:'daemon'; 121, identifier:_file; 122, except_clause; 122, 123; 122, 127; 123, as_pattern; 123, 124; 123, 125; 124, identifier:OSError; 125, as_pattern_target; 125, 126; 126, identifier:exc; 127, block; 127, 128; 128, raise_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:ValueError; 131, argument_list; 131, 132; 132, identifier:exc; 133, for_statement; 133, 134; 133, 137; 133, 142; 134, pattern_list; 134, 135; 134, 136; 135, identifier:option; 136, identifier:getter; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:DAEMON_OPTIONS_TYPE; 140, identifier:items; 141, argument_list; 142, block; 142, 143; 143, try_statement; 143, 144; 143, 155; 143, 173; 143, 186; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 152; 147, call; 147, 148; 147, 149; 148, identifier:getattr; 149, argument_list; 149, 150; 149, 151; 150, identifier:config; 151, identifier:getter; 152, argument_list; 152, 153; 152, 154; 153, string:'daemon'; 154, identifier:option; 155, except_clause; 155, 156; 155, 162; 156, as_pattern; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:configparser; 159, identifier:NoOptionError; 160, as_pattern_target; 160, 161; 161, identifier:error; 162, block; 162, 163; 163, if_statement; 163, 164; 163, 167; 164, comparison_operator:not; 164, 165; 164, 166; 165, identifier:option; 166, identifier:DAEMON_OPTIONAL_OPTIONS; 167, block; 167, 168; 168, raise_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:ValueError; 171, argument_list; 171, 172; 172, identifier:error; 173, except_clause; 173, 174; 173, 180; 174, as_pattern; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:configparser; 177, identifier:Error; 178, as_pattern_target; 178, 179; 179, identifier:error; 180, block; 180, 181; 181, raise_statement; 181, 182; 182, call; 182, 183; 182, 184; 183, identifier:ValueError; 184, argument_list; 184, 185; 185, identifier:error; 186, except_clause; 186, 187; 186, 191; 187, as_pattern; 187, 188; 187, 189; 188, identifier:ValueError; 189, as_pattern_target; 189, 190; 190, identifier:exc; 191, block; 191, 192; 191, 207; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:msg; 195, parenthesized_expression; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, string:"invalid data for '{opt}' option in daemon section: {err}"; 199, identifier:format; 200, argument_list; 200, 201; 200, 204; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:opt; 203, identifier:option; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:err; 206, identifier:exc; 207, raise_statement; 207, 208; 208, call; 208, 209; 208, 210; 209, identifier:ValueError; 210, argument_list; 210, 211; 211, identifier:msg; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:service_configuration_check; 215, argument_list; 215, 216; 216, identifier:config | def configuration_check(config):
log_level = config.get('daemon', 'loglevel')
num_level = getattr(logging, log_level.upper(), None)
pidfile = config.get('daemon', 'pidfile')
if not os.path.isdir(os.path.dirname(pidfile)):
raise ValueError("{d} doesn't exit".format(d=os.path.dirname(pidfile)))
if not isinstance(num_level, int):
raise ValueError('Invalid log level: {}'.format(log_level))
for _file in 'log_file', 'stderr_file':
if config.has_option('daemon', _file):
try:
touch(config.get('daemon', _file))
except OSError as exc:
raise ValueError(exc)
for option, getter in DAEMON_OPTIONS_TYPE.items():
try:
getattr(config, getter)('daemon', option)
except configparser.NoOptionError as error:
if option not in DAEMON_OPTIONAL_OPTIONS:
raise ValueError(error)
except configparser.Error as error:
raise ValueError(error)
except ValueError as exc:
msg = ("invalid data for '{opt}' option in daemon section: {err}"
.format(opt=option, err=exc))
raise ValueError(msg)
service_configuration_check(config) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:create_bird_config_files; 3, parameters; 3, 4; 4, identifier:bird_configuration; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 8; 6, 9; 7, identifier:ip_version; 8, identifier:bird_configuration; 9, block; 9, 10; 9, 18; 9, 46; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:config_file; 13, subscript; 13, 14; 13, 17; 14, subscript; 14, 15; 14, 16; 15, identifier:bird_configuration; 16, identifier:ip_version; 17, string:'config_file'; 18, try_statement; 18, 19; 18, 25; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:touch; 23, argument_list; 23, 24; 24, identifier:config_file; 25, except_clause; 25, 26; 25, 30; 26, as_pattern; 26, 27; 26, 28; 27, identifier:OSError; 28, as_pattern_target; 28, 29; 29, identifier:exc; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:ValueError; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:"failed to create {f}:{e}"; 38, identifier:format; 39, argument_list; 39, 40; 39, 43; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:f; 42, identifier:config_file; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:e; 45, identifier:exc; 46, if_statement; 46, 47; 46, 52; 47, subscript; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:bird_configuration; 50, identifier:ip_version; 51, string:'keep_changes'; 52, block; 52, 53; 52, 72; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:history_dir; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:os; 60, identifier:path; 61, identifier:join; 62, argument_list; 62, 63; 62, 71; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:os; 67, identifier:path; 68, identifier:dirname; 69, argument_list; 69, 70; 70, identifier:config_file; 71, string:'history'; 72, try_statement; 72, 73; 72, 81; 72, 85; 72, 111; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:os; 78, identifier:mkdir; 79, argument_list; 79, 80; 80, identifier:history_dir; 81, except_clause; 81, 82; 81, 83; 82, identifier:FileExistsError; 83, block; 83, 84; 84, pass_statement; 85, except_clause; 85, 86; 85, 90; 86, as_pattern; 86, 87; 86, 88; 87, identifier:OSError; 88, as_pattern_target; 88, 89; 89, identifier:exc; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:ValueError; 94, argument_list; 94, 95; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, concatenated_string; 97, 98; 97, 99; 98, string:"failed to make directory {d} for keeping a "; 99, string:"history of changes for {b}:{e}"; 100, identifier:format; 101, argument_list; 101, 102; 101, 105; 101, 108; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:d; 104, identifier:history_dir; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:b; 107, identifier:config_file; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:e; 110, identifier:exc; 111, else_clause; 111, 112; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:print; 116, argument_list; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, string:"{d} is created"; 120, identifier:format; 121, argument_list; 121, 122; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:d; 124, identifier:history_dir | def create_bird_config_files(bird_configuration):
for ip_version in bird_configuration:
config_file = bird_configuration[ip_version]['config_file']
try:
touch(config_file)
except OSError as exc:
raise ValueError("failed to create {f}:{e}"
.format(f=config_file, e=exc))
if bird_configuration[ip_version]['keep_changes']:
history_dir = os.path.join(os.path.dirname(config_file), 'history')
try:
os.mkdir(history_dir)
except FileExistsError:
pass
except OSError as exc:
raise ValueError("failed to make directory {d} for keeping a "
"history of changes for {b}:{e}"
.format(d=history_dir, b=config_file, e=exc))
else:
print("{d} is created".format(d=history_dir)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:setup_logger; 3, parameters; 3, 4; 4, identifier:config; 5, block; 5, 6; 5, 15; 5, 34; 5, 41; 5, 45; 5, 59; 5, 71; 5, 100; 5, 106; 5, 118; 5, 139; 5, 215; 5, 281; 5, 341; 5, 437; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:logger; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logging; 12, identifier:getLogger; 13, argument_list; 13, 14; 14, identifier:PROGRAM_NAME; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:num_level; 18, call; 18, 19; 18, 20; 19, identifier:getattr; 20, argument_list; 20, 21; 20, 22; 20, 33; 21, identifier:logging; 22, call; 22, 23; 22, 32; 23, attribute; 23, 24; 23, 31; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:config; 27, identifier:get; 28, argument_list; 28, 29; 28, 30; 29, string:'daemon'; 30, string:'loglevel'; 31, identifier:upper; 32, argument_list; 33, None; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:logger; 38, identifier:setLevel; 39, argument_list; 39, 40; 40, identifier:num_level; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:lengths; 44, list:[]; 45, for_statement; 45, 46; 45, 47; 45, 48; 46, identifier:section; 47, identifier:config; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:lengths; 53, identifier:append; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:len; 57, argument_list; 57, 58; 58, identifier:section; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:width; 62, binary_operator:+; 62, 63; 62, 70; 63, subscript; 63, 64; 63, 68; 64, call; 64, 65; 64, 66; 65, identifier:sorted; 66, argument_list; 66, 67; 67, identifier:lengths; 68, unary_operator:-; 68, 69; 69, integer:1; 70, integer:1; 71, function_definition; 71, 72; 71, 73; 71, 74; 72, function_name:log_format; 73, parameters; 74, block; 74, 75; 74, 84; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:supported_keys; 78, list:[
'asctime',
'levelname',
'process',
'threadName',
'message',
]; 78, 79; 78, 80; 78, 81; 78, 82; 78, 83; 79, string:'asctime'; 80, string:'levelname'; 81, string:'process'; 82, string:'threadName'; 83, string:'message'; 84, return_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, string:' '; 88, identifier:join; 89, argument_list; 89, 90; 90, list_comprehension; 90, 91; 90, 97; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, string:'%({0:s})'; 94, identifier:format; 95, argument_list; 95, 96; 96, identifier:i; 97, for_in_clause; 97, 98; 97, 99; 98, identifier:i; 99, identifier:supported_keys; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:custom_format; 103, call; 103, 104; 103, 105; 104, identifier:log_format; 105, argument_list; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:json_formatter; 109, call; 109, 110; 109, 111; 110, identifier:CustomJsonFormatter; 111, argument_list; 111, 112; 111, 113; 112, identifier:custom_format; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:prefix; 115, binary_operator:+; 115, 116; 115, 117; 116, identifier:PROGRAM_NAME; 117, string:': '; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:formatter; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:logging; 124, identifier:Formatter; 125, argument_list; 125, 126; 126, call; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, concatenated_string; 128, 129; 128, 130; 129, string:'%(asctime)s {program}[%(process)d] %(levelname)-8s '; 130, string:'%(threadName)-{width}s %(message)s'; 131, identifier:format; 132, argument_list; 132, 133; 132, 136; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:program; 135, identifier:PROGRAM_NAME; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:width; 138, identifier:width; 139, if_statement; 139, 140; 139, 147; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:config; 143, identifier:has_option; 144, argument_list; 144, 145; 144, 146; 145, string:'daemon'; 146, string:'log_file'; 147, block; 147, 148; 147, 183; 147, 208; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:file_handler; 151, call; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:logging; 155, identifier:handlers; 156, identifier:RotatingFileHandler; 157, argument_list; 157, 158; 157, 165; 157, 174; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:config; 161, identifier:get; 162, argument_list; 162, 163; 162, 164; 163, string:'daemon'; 164, string:'log_file'; 165, keyword_argument; 165, 166; 165, 167; 166, identifier:maxBytes; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:config; 170, identifier:getint; 171, argument_list; 171, 172; 171, 173; 172, string:'daemon'; 173, string:'log_maxbytes'; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:backupCount; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:config; 179, identifier:getint; 180, argument_list; 180, 181; 180, 182; 181, string:'daemon'; 182, string:'log_backups'; 183, if_statement; 183, 184; 183, 191; 183, 199; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:config; 187, identifier:getboolean; 188, argument_list; 188, 189; 188, 190; 189, string:'daemon'; 190, string:'json_log_file'; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:file_handler; 196, identifier:setFormatter; 197, argument_list; 197, 198; 198, identifier:json_formatter; 199, else_clause; 199, 200; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:file_handler; 205, identifier:setFormatter; 206, argument_list; 206, 207; 207, identifier:formatter; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:logger; 212, identifier:addHandler; 213, argument_list; 213, 214; 214, identifier:file_handler; 215, if_statement; 215, 216; 215, 223; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:config; 219, identifier:has_option; 220, argument_list; 220, 221; 220, 222; 221, string:'daemon'; 222, string:'log_server'; 223, block; 223, 224; 223, 249; 223, 274; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:udp_handler; 227, call; 227, 228; 227, 233; 228, attribute; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:logging; 231, identifier:handlers; 232, identifier:SysLogHandler; 233, argument_list; 233, 234; 234, tuple; 234, 235; 234, 242; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:config; 238, identifier:get; 239, argument_list; 239, 240; 239, 241; 240, string:'daemon'; 241, string:'log_server'; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:config; 245, identifier:getint; 246, argument_list; 246, 247; 246, 248; 247, string:'daemon'; 248, string:'log_server_port'; 249, if_statement; 249, 250; 249, 257; 249, 265; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:config; 253, identifier:getboolean; 254, argument_list; 254, 255; 254, 256; 255, string:'daemon'; 256, string:'json_log_server'; 257, block; 257, 258; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:udp_handler; 262, identifier:setFormatter; 263, argument_list; 263, 264; 264, identifier:json_formatter; 265, else_clause; 265, 266; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:udp_handler; 271, identifier:setFormatter; 272, argument_list; 272, 273; 273, identifier:formatter; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:logger; 278, identifier:addHandler; 279, argument_list; 279, 280; 280, identifier:udp_handler; 281, if_statement; 281, 282; 281, 300; 282, parenthesized_expression; 282, 283; 283, boolean_operator:and; 283, 284; 283, 292; 284, not_operator; 284, 285; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:config; 288, identifier:has_option; 289, argument_list; 289, 290; 289, 291; 290, string:'daemon'; 291, string:'log_file'; 292, not_operator; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:config; 296, identifier:has_option; 297, argument_list; 297, 298; 297, 299; 298, string:'daemon'; 299, string:'log_server'; 300, block; 300, 301; 300, 309; 300, 334; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:stream_handler; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:logging; 307, identifier:StreamHandler; 308, argument_list; 309, if_statement; 309, 310; 309, 317; 309, 325; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:config; 313, identifier:getboolean; 314, argument_list; 314, 315; 314, 316; 315, string:'daemon'; 316, string:'json_stdout'; 317, block; 317, 318; 318, expression_statement; 318, 319; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:stream_handler; 322, identifier:setFormatter; 323, argument_list; 323, 324; 324, identifier:json_formatter; 325, else_clause; 325, 326; 326, block; 326, 327; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:stream_handler; 331, identifier:setFormatter; 332, argument_list; 332, 333; 333, identifier:formatter; 334, expression_statement; 334, 335; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:logger; 338, identifier:addHandler; 339, argument_list; 339, 340; 340, identifier:stream_handler; 341, if_statement; 341, 342; 341, 349; 341, 385; 341, 430; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:config; 345, identifier:has_option; 346, argument_list; 346, 347; 346, 348; 347, string:'daemon'; 348, string:'stderr_file'; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:sys; 354, identifier:stderr; 355, call; 355, 356; 355, 357; 356, identifier:CustomRotatingFileLogger; 357, argument_list; 357, 358; 357, 367; 357, 376; 358, keyword_argument; 358, 359; 358, 360; 359, identifier:filepath; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:config; 363, identifier:get; 364, argument_list; 364, 365; 364, 366; 365, string:'daemon'; 366, string:'stderr_file'; 367, keyword_argument; 367, 368; 367, 369; 368, identifier:maxbytes; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:config; 372, identifier:getint; 373, argument_list; 373, 374; 373, 375; 374, string:'daemon'; 375, string:'log_maxbytes'; 376, keyword_argument; 376, 377; 376, 378; 377, identifier:backupcount; 378, call; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:config; 381, identifier:getint; 382, argument_list; 382, 383; 382, 384; 383, string:'daemon'; 384, string:'log_backups'; 385, elif_clause; 385, 386; 385, 403; 386, parenthesized_expression; 386, 387; 387, boolean_operator:and; 387, 388; 387, 395; 388, call; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:config; 391, identifier:has_option; 392, argument_list; 392, 393; 392, 394; 393, string:'daemon'; 394, string:'stderr_log_server'; 395, not_operator; 395, 396; 396, call; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:config; 399, identifier:has_option; 400, argument_list; 400, 401; 400, 402; 401, string:'daemon'; 402, string:'stderr_file'; 403, block; 403, 404; 404, expression_statement; 404, 405; 405, assignment; 405, 406; 405, 409; 406, attribute; 406, 407; 406, 408; 407, identifier:sys; 408, identifier:stderr; 409, call; 409, 410; 409, 411; 410, identifier:CustomUdpLogger; 411, argument_list; 411, 412; 411, 421; 412, keyword_argument; 412, 413; 412, 414; 413, identifier:server; 414, call; 414, 415; 414, 418; 415, attribute; 415, 416; 415, 417; 416, identifier:config; 417, identifier:get; 418, argument_list; 418, 419; 418, 420; 419, string:'daemon'; 420, string:'log_server'; 421, keyword_argument; 421, 422; 421, 423; 422, identifier:port; 423, call; 423, 424; 423, 427; 424, attribute; 424, 425; 424, 426; 425, identifier:config; 426, identifier:getint; 427, argument_list; 427, 428; 427, 429; 428, string:'daemon'; 429, string:'log_server_port'; 430, else_clause; 430, 431; 431, block; 431, 432; 432, expression_statement; 432, 433; 433, call; 433, 434; 433, 435; 434, identifier:print; 435, argument_list; 435, 436; 436, string:'messages for unhandled exceptions will go to STDERR'; 437, return_statement; 437, 438; 438, identifier:logger | def setup_logger(config):
logger = logging.getLogger(PROGRAM_NAME)
num_level = getattr(
logging,
config.get('daemon', 'loglevel').upper(),
None
)
logger.setLevel(num_level)
lengths = []
for section in config:
lengths.append(len(section))
width = sorted(lengths)[-1] + 1
def log_format():
supported_keys = [
'asctime',
'levelname',
'process',
'threadName',
'message',
]
return ' '.join(['%({0:s})'.format(i) for i in supported_keys])
custom_format = log_format()
json_formatter = CustomJsonFormatter(custom_format,
prefix=PROGRAM_NAME + ': ')
formatter = logging.Formatter(
'%(asctime)s {program}[%(process)d] %(levelname)-8s '
'%(threadName)-{width}s %(message)s'
.format(program=PROGRAM_NAME, width=width)
)
if config.has_option('daemon', 'log_file'):
file_handler = logging.handlers.RotatingFileHandler(
config.get('daemon', 'log_file'),
maxBytes=config.getint('daemon', 'log_maxbytes'),
backupCount=config.getint('daemon', 'log_backups')
)
if config.getboolean('daemon', 'json_log_file'):
file_handler.setFormatter(json_formatter)
else:
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
if config.has_option('daemon', 'log_server'):
udp_handler = logging.handlers.SysLogHandler(
(
config.get('daemon', 'log_server'),
config.getint('daemon', 'log_server_port')
)
)
if config.getboolean('daemon', 'json_log_server'):
udp_handler.setFormatter(json_formatter)
else:
udp_handler.setFormatter(formatter)
logger.addHandler(udp_handler)
if (not config.has_option('daemon', 'log_file')
and not config.has_option('daemon', 'log_server')):
stream_handler = logging.StreamHandler()
if config.getboolean('daemon', 'json_stdout'):
stream_handler.setFormatter(json_formatter)
else:
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
if config.has_option('daemon', 'stderr_file'):
sys.stderr = CustomRotatingFileLogger(
filepath=config.get('daemon', 'stderr_file'),
maxbytes=config.getint('daemon', 'log_maxbytes'),
backupcount=config.getint('daemon', 'log_backups')
)
elif (config.has_option('daemon', 'stderr_log_server')
and not config.has_option('daemon', 'stderr_file')):
sys.stderr = CustomUdpLogger(
server=config.get('daemon', 'log_server'),
port=config.getint('daemon', 'log_server_port')
)
else:
print('messages for unhandled exceptions will go to STDERR')
return logger |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:main; 3, parameters; 4, block; 4, 5; 4, 12; 4, 16; 4, 20; 4, 28; 4, 33; 4, 53; 4, 60; 4, 103; 4, 126; 4, 134; 4, 141; 4, 157; 4, 165; 4, 190; 4, 206; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:arguments; 8, call; 8, 9; 8, 10; 9, identifier:docopt; 10, argument_list; 10, 11; 11, identifier:__doc__; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:config_file; 15, string:'/etc/anycast-healthchecker.conf'; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:config_dir; 19, string:'/etc/anycast-healthchecker.d'; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:config; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:configparser; 26, identifier:ConfigParser; 27, argument_list; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:config_files; 31, list:[config_file]; 31, 32; 32, identifier:config_file; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:config_files; 37, identifier:extend; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:glob; 42, identifier:glob; 43, argument_list; 43, 44; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:os; 48, identifier:path; 49, identifier:join; 50, argument_list; 50, 51; 50, 52; 51, identifier:config_dir; 52, string:'*.conf'; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:config; 57, identifier:read; 58, argument_list; 58, 59; 59, identifier:config_files; 60, try_statement; 60, 61; 60, 69; 60, 94; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:pid; 65, call; 65, 66; 65, 67; 66, identifier:get_processid; 67, argument_list; 67, 68; 68, identifier:config; 69, except_clause; 69, 70; 69, 74; 70, as_pattern; 70, 71; 70, 72; 71, identifier:ValueError; 72, as_pattern_target; 72, 73; 73, identifier:exc; 74, block; 74, 75; 74, 87; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:print; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, string:"UNKNOWN: {e}"; 82, identifier:format; 83, argument_list; 83, 84; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:e; 86, identifier:exc; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:sys; 91, identifier:exit; 92, argument_list; 92, 93; 93, integer:3; 94, else_clause; 94, 95; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:process_up; 99, call; 99, 100; 99, 101; 100, identifier:running; 101, argument_list; 101, 102; 102, identifier:pid; 103, if_statement; 103, 104; 103, 106; 104, not_operator; 104, 105; 105, identifier:process_up; 106, block; 106, 107; 106, 119; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:print; 110, argument_list; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, string:"CRITICAL: anycast-healthchecker with pid ({p}) isn't running"; 114, identifier:format; 115, argument_list; 115, 116; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:p; 118, identifier:pid; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:sys; 123, identifier:exit; 124, argument_list; 124, 125; 125, integer:3; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:services; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:config; 132, identifier:sections; 133, argument_list; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:services; 138, identifier:remove; 139, argument_list; 139, 140; 140, string:'daemon'; 141, if_statement; 141, 142; 141, 144; 142, not_operator; 142, 143; 143, identifier:services; 144, block; 144, 145; 144, 150; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:print; 148, argument_list; 148, 149; 149, string:"UNKNOWN: No service checks are configured"; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:sys; 154, identifier:exit; 155, argument_list; 155, 156; 156, integer:3; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:enabled_service_checks; 160, call; 160, 161; 160, 162; 161, identifier:parse_services; 162, argument_list; 162, 163; 162, 164; 163, identifier:config; 164, identifier:services; 165, if_statement; 165, 166; 165, 169; 165, 182; 166, comparison_operator:==; 166, 167; 166, 168; 167, identifier:enabled_service_checks; 168, integer:0; 169, block; 169, 170; 169, 175; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:print; 173, argument_list; 173, 174; 174, string:"OK: Number of service checks is zero, no threads are running"; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:sys; 179, identifier:exit; 180, argument_list; 180, 181; 181, integer:0; 182, else_clause; 182, 183; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:configured_threads; 187, binary_operator:+; 187, 188; 187, 189; 188, identifier:enabled_service_checks; 189, integer:1; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:cmd; 193, list:['/bin/ps', 'h', '-T', '-p', '{n}'.format(n=pid)]; 193, 194; 193, 195; 193, 196; 193, 197; 193, 198; 194, string:'/bin/ps'; 195, string:'h'; 196, string:'-T'; 197, string:'-p'; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, string:'{n}'; 201, identifier:format; 202, argument_list; 202, 203; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:n; 205, identifier:pid; 206, try_statement; 206, 207; 206, 240; 206, 277; 206, 304; 207, block; 207, 208; 207, 228; 208, if_statement; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:arguments; 211, string:'-v'; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 216; 215, identifier:print; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, string:"running {}"; 220, identifier:format; 221, argument_list; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, string:' '; 225, identifier:join; 226, argument_list; 226, 227; 227, identifier:cmd; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:out; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:subprocess; 234, identifier:check_output; 235, argument_list; 235, 236; 235, 237; 236, identifier:cmd; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:timeout; 239, integer:1; 240, except_clause; 240, 241; 240, 247; 241, as_pattern; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:subprocess; 244, identifier:CalledProcessError; 245, as_pattern_target; 245, 246; 246, identifier:exc; 247, block; 247, 248; 247, 270; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 251; 250, identifier:print; 251, argument_list; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, string:"UNKNOWN: running '{c}' failed with return code: {r}"; 255, identifier:format; 256, argument_list; 256, 257; 256, 265; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:c; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, string:' '; 262, identifier:join; 263, argument_list; 263, 264; 264, identifier:cmd; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:r; 267, attribute; 267, 268; 267, 269; 268, identifier:exc; 269, identifier:returncode; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:sys; 274, identifier:exit; 275, argument_list; 275, 276; 276, integer:3; 277, except_clause; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:subprocess; 280, identifier:TimeoutExpired; 281, block; 281, 282; 281, 297; 282, expression_statement; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:print; 285, argument_list; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, string:"UNKNOWN: running '{}' timed out"; 289, identifier:format; 290, argument_list; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, string:' '; 294, identifier:join; 295, argument_list; 295, 296; 296, identifier:cmd; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:sys; 301, identifier:exit; 302, argument_list; 302, 303; 303, integer:3; 304, else_clause; 304, 305; 305, block; 305, 306; 305, 314; 305, 328; 305, 335; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:output_lines; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:out; 312, identifier:splitlines; 313, argument_list; 314, if_statement; 314, 315; 314, 318; 315, subscript; 315, 316; 315, 317; 316, identifier:arguments; 317, string:'-v'; 318, block; 318, 319; 319, for_statement; 319, 320; 319, 321; 319, 322; 320, identifier:line; 321, identifier:output_lines; 322, block; 322, 323; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 326; 325, identifier:print; 326, argument_list; 326, 327; 327, identifier:line; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:running_threads; 331, call; 331, 332; 331, 333; 332, identifier:len; 333, argument_list; 333, 334; 334, identifier:output_lines; 335, if_statement; 335, 336; 335, 339; 335, 364; 335, 383; 336, comparison_operator:==; 336, 337; 336, 338; 337, identifier:running_threads; 338, identifier:configured_threads; 339, block; 339, 340; 339, 357; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 343; 342, identifier:print; 343, argument_list; 343, 344; 344, call; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, string:"OK: UP (pid={p}) and all threads ({t}) are running"; 347, identifier:format; 348, argument_list; 348, 349; 348, 352; 349, keyword_argument; 349, 350; 349, 351; 350, identifier:p; 351, identifier:pid; 352, keyword_argument; 352, 353; 352, 354; 353, identifier:t; 354, binary_operator:-; 354, 355; 354, 356; 355, identifier:configured_threads; 356, integer:1; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:sys; 361, identifier:exit; 362, argument_list; 362, 363; 363, integer:0; 364, elif_clause; 364, 365; 364, 370; 365, comparison_operator:==; 365, 366; 365, 369; 366, binary_operator:-; 366, 367; 366, 368; 367, identifier:running_threads; 368, integer:1; 369, integer:0; 370, block; 370, 371; 370, 376; 371, expression_statement; 371, 372; 372, call; 372, 373; 372, 374; 373, identifier:print; 374, argument_list; 374, 375; 375, string:"CRITICAL: No threads are running OpDocs ANYCAST-03"; 376, expression_statement; 376, 377; 377, call; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:sys; 380, identifier:exit; 381, argument_list; 381, 382; 382, integer:2; 383, else_clause; 383, 384; 384, block; 384, 385; 384, 406; 385, expression_statement; 385, 386; 386, call; 386, 387; 386, 388; 387, identifier:print; 388, argument_list; 388, 389; 389, call; 389, 390; 389, 395; 390, attribute; 390, 391; 390, 394; 391, concatenated_string; 391, 392; 391, 393; 392, string:"CRITICAL: Found {n} running threads while configured "; 393, string:"number of threads is {c} OpDocs ANYCAST-03"; 394, identifier:format; 395, argument_list; 395, 396; 395, 401; 396, keyword_argument; 396, 397; 396, 398; 397, identifier:n; 398, binary_operator:-; 398, 399; 398, 400; 399, identifier:running_threads; 400, integer:1; 401, keyword_argument; 401, 402; 401, 403; 402, identifier:c; 403, binary_operator:-; 403, 404; 403, 405; 404, identifier:configured_threads; 405, integer:1; 406, expression_statement; 406, 407; 407, call; 407, 408; 407, 411; 408, attribute; 408, 409; 408, 410; 409, identifier:sys; 410, identifier:exit; 411, argument_list; 411, 412; 412, integer:2 | def main():
arguments = docopt(__doc__)
config_file = '/etc/anycast-healthchecker.conf'
config_dir = '/etc/anycast-healthchecker.d'
config = configparser.ConfigParser()
config_files = [config_file]
config_files.extend(glob.glob(os.path.join(config_dir, '*.conf')))
config.read(config_files)
try:
pid = get_processid(config)
except ValueError as exc:
print("UNKNOWN: {e}".format(e=exc))
sys.exit(3)
else:
process_up = running(pid)
if not process_up:
print("CRITICAL: anycast-healthchecker with pid ({p}) isn't running"
.format(p=pid))
sys.exit(3)
services = config.sections()
services.remove('daemon')
if not services:
print("UNKNOWN: No service checks are configured")
sys.exit(3)
enabled_service_checks = parse_services(config, services)
if enabled_service_checks == 0:
print("OK: Number of service checks is zero, no threads are running")
sys.exit(0)
else:
configured_threads = enabled_service_checks + 1
cmd = ['/bin/ps', 'h', '-T', '-p', '{n}'.format(n=pid)]
try:
if arguments['-v']:
print("running {}".format(' '.join(cmd)))
out = subprocess.check_output(cmd, timeout=1)
except subprocess.CalledProcessError as exc:
print("UNKNOWN: running '{c}' failed with return code: {r}"
.format(c=' '.join(cmd), r=exc.returncode))
sys.exit(3)
except subprocess.TimeoutExpired:
print("UNKNOWN: running '{}' timed out".format(' '.join(cmd)))
sys.exit(3)
else:
output_lines = out.splitlines()
if arguments['-v']:
for line in output_lines:
print(line)
running_threads = len(output_lines)
if running_threads == configured_threads:
print("OK: UP (pid={p}) and all threads ({t}) are running"
.format(p=pid, t=configured_threads - 1))
sys.exit(0)
elif running_threads - 1 == 0:
print("CRITICAL: No threads are running OpDocs ANYCAST-03")
sys.exit(2)
else:
print("CRITICAL: Found {n} running threads while configured "
"number of threads is {c} OpDocs ANYCAST-03"
.format(n=running_threads - 1, c=configured_threads - 1))
sys.exit(2) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_ve_base; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:environ; 6, block; 6, 7; 6, 22; 6, 48; 6, 146; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:ve_base_value; 10, call; 10, 11; 10, 20; 11, attribute; 11, 12; 11, 19; 12, subscript; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:headings; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:default_heading; 19, identifier:get; 20, argument_list; 20, 21; 21, string:'virtualenvs'; 22, if_statement; 22, 23; 22, 24; 22, 36; 23, identifier:ve_base_value; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:ve_base; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:os; 32, identifier:path; 33, identifier:expanduser; 34, argument_list; 34, 35; 35, identifier:ve_base_value; 36, else_clause; 36, 37; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:ve_base; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:environ; 44, identifier:get; 45, argument_list; 45, 46; 45, 47; 46, string:'WORKON_HOME'; 47, string:''; 48, if_statement; 48, 49; 48, 51; 49, not_operator; 49, 50; 50, identifier:ve_base; 51, block; 51, 52; 51, 113; 51, 128; 51, 134; 52, if_statement; 52, 53; 52, 66; 52, 101; 53, boolean_operator:and; 53, 54; 53, 61; 54, comparison_operator:==; 54, 55; 54, 60; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:platform; 58, identifier:system; 59, argument_list; 60, string:'Windows'; 61, comparison_operator:==; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:os; 64, identifier:name; 65, string:'nt'; 66, block; 66, 67; 66, 76; 66, 86; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:_win_drive; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:environ; 73, identifier:get; 74, argument_list; 74, 75; 75, string:'HOMEDRIVE'; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:home; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:environ; 82, identifier:get; 83, argument_list; 83, 84; 83, 85; 84, string:'HOMEPATH'; 85, string:''; 86, if_statement; 86, 87; 86, 88; 87, identifier:home; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:home; 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:join; 98, argument_list; 98, 99; 98, 100; 99, identifier:_win_drive; 100, identifier:home; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:home; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:environ; 109, identifier:get; 110, argument_list; 110, 111; 110, 112; 111, string:'HOME'; 112, string:''; 113, if_statement; 113, 114; 113, 116; 114, not_operator; 114, 115; 115, identifier:home; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:home; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:os; 124, identifier:path; 125, identifier:expanduser; 126, argument_list; 126, 127; 127, string:'~'; 128, if_statement; 128, 129; 128, 131; 129, not_operator; 129, 130; 130, identifier:home; 131, block; 131, 132; 132, return_statement; 132, 133; 133, string:''; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:ve_base; 137, call; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:os; 141, identifier:path; 142, identifier:join; 143, argument_list; 143, 144; 143, 145; 144, identifier:home; 145, string:'.virtualenvs'; 146, return_statement; 146, 147; 147, boolean_operator:or; 147, 148; 147, 149; 148, identifier:ve_base; 149, string:'' | def get_ve_base(self, environ):
ve_base_value = self.headings[self.default_heading].get('virtualenvs')
if ve_base_value:
ve_base = os.path.expanduser(ve_base_value)
else:
ve_base = environ.get('WORKON_HOME', '')
if not ve_base:
if platform.system() == 'Windows' and os.name == 'nt':
_win_drive = environ.get('HOMEDRIVE')
home = environ.get('HOMEPATH', '')
if home:
home = os.path.join(_win_drive, home)
else:
home = environ.get('HOME', '')
if not home:
home = os.path.expanduser('~')
if not home:
return ''
ve_base = os.path.join(home, '.virtualenvs')
return ve_base or '' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:generate; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:callback; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:interval; 10, integer:0; 11, block; 11, 12; 11, 62; 11, 91; 11, 131; 11, 135; 11, 177; 12, if_statement; 12, 13; 12, 18; 12, 24; 12, 40; 13, comparison_operator:is; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:path; 17, None; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:RuntimeError; 22, argument_list; 22, 23; 23, string:'generate() called with no path specified'; 24, elif_clause; 24, 25; 24, 30; 25, comparison_operator:<=; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:size; 29, integer:0; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:error; 35, identifier:PathEmptyError; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:path; 40, elif_clause; 40, 41; 40, 52; 41, not_operator; 41, 42; 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:exists; 48, argument_list; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:path; 52, block; 52, 53; 53, raise_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:error; 57, identifier:PathNotFoundError; 58, argument_list; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:path; 62, if_statement; 62, 63; 62, 66; 62, 81; 63, comparison_operator:is; 63, 64; 63, 65; 64, identifier:callback; 65, None; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:cancel; 70, lambda; 70, 71; 70, 74; 71, lambda_parameters; 71, 72; 72, list_splat_pattern; 72, 73; 73, identifier:status; 74, comparison_operator:is; 74, 75; 74, 80; 75, call; 75, 76; 75, 77; 76, identifier:callback; 77, argument_list; 77, 78; 78, list_splat; 78, 79; 79, identifier:status; 80, None; 81, else_clause; 81, 82; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:cancel; 86, lambda; 86, 87; 86, 90; 87, lambda_parameters; 87, 88; 88, list_splat_pattern; 88, 89; 89, identifier:status; 90, False; 91, if_statement; 91, 92; 91, 102; 91, 111; 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:isfile; 98, argument_list; 98, 99; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:path; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:pieces; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:_set_pieces_singlefile; 110, argument_list; 111, elif_clause; 111, 112; 111, 122; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:os; 116, identifier:path; 117, identifier:isdir; 118, argument_list; 118, 119; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:path; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:pieces; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:_set_pieces_multifile; 130, argument_list; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:last_cb_call; 134, integer:0; 135, for_statement; 135, 136; 135, 140; 135, 141; 136, pattern_list; 136, 137; 136, 138; 136, 139; 137, identifier:filepath; 138, identifier:pieces_done; 139, identifier:pieces_total; 140, identifier:pieces; 141, block; 141, 142; 141, 150; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:now; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:time; 148, identifier:time; 149, argument_list; 150, if_statement; 150, 151; 150, 161; 151, boolean_operator:or; 151, 152; 151, 157; 151, 158; 152, comparison_operator:>=; 152, 153; 152, 156; 153, binary_operator:-; 153, 154; 153, 155; 154, identifier:now; 155, identifier:last_cb_call; 156, identifier:interval; 157, line_continuation:\; 158, comparison_operator:>=; 158, 159; 158, 160; 159, identifier:pieces_done; 160, identifier:pieces_total; 161, block; 161, 162; 161, 166; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:last_cb_call; 165, identifier:now; 166, if_statement; 166, 167; 166, 174; 167, call; 167, 168; 167, 169; 168, identifier:cancel; 169, argument_list; 169, 170; 169, 171; 169, 172; 169, 173; 170, identifier:self; 171, identifier:filepath; 172, identifier:pieces_done; 173, identifier:pieces_total; 174, block; 174, 175; 175, return_statement; 175, 176; 176, False; 177, return_statement; 177, 178; 178, True | def generate(self, callback=None, interval=0):
if self.path is None:
raise RuntimeError('generate() called with no path specified')
elif self.size <= 0:
raise error.PathEmptyError(self.path)
elif not os.path.exists(self.path):
raise error.PathNotFoundError(self.path)
if callback is not None:
cancel = lambda *status: callback(*status) is not None
else:
cancel = lambda *status: False
if os.path.isfile(self.path):
pieces = self._set_pieces_singlefile()
elif os.path.isdir(self.path):
pieces = self._set_pieces_multifile()
last_cb_call = 0
for filepath,pieces_done,pieces_total in pieces:
now = time.time()
if now - last_cb_call >= interval or \
pieces_done >= pieces_total:
last_cb_call = now
if cancel(self, filepath, pieces_done, pieces_total):
return False
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:read_stream; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:stream; 6, default_parameter; 6, 7; 6, 8; 7, identifier:validate; 8, True; 9, block; 9, 10; 10, try_statement; 10, 11; 10, 23; 10, 38; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:content; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:stream; 18, identifier:read; 19, argument_list; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:cls; 22, identifier:MAX_TORRENT_FILE_SIZE; 23, except_clause; 23, 24; 23, 28; 24, as_pattern; 24, 25; 24, 26; 25, identifier:OSError; 26, as_pattern_target; 26, 27; 27, identifier:e; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:error; 33, identifier:ReadError; 34, argument_list; 34, 35; 35, attribute; 35, 36; 35, 37; 36, identifier:e; 37, identifier:errno; 38, else_clause; 38, 39; 39, block; 39, 40; 39, 61; 39, 109; 39, 159; 39, 165; 39, 171; 39, 188; 39, 196; 39, 227; 39, 236; 40, try_statement; 40, 41; 40, 49; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:metainfo_enc; 45, call; 45, 46; 45, 47; 46, identifier:bdecode; 47, argument_list; 47, 48; 48, identifier:content; 49, except_clause; 49, 50; 49, 54; 50, as_pattern; 50, 51; 50, 52; 51, identifier:BTFailure; 52, as_pattern_target; 52, 53; 53, identifier:e; 54, block; 54, 55; 55, raise_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:error; 59, identifier:ParseError; 60, argument_list; 61, if_statement; 61, 62; 61, 63; 62, identifier:validate; 63, block; 63, 64; 64, if_statement; 64, 65; 64, 68; 64, 76; 64, 95; 65, comparison_operator:not; 65, 66; 65, 67; 66, string:b'info'; 67, identifier:metainfo_enc; 68, block; 68, 69; 69, raise_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:error; 73, identifier:MetainfoError; 74, argument_list; 74, 75; 75, string:"Missing 'info'"; 76, elif_clause; 76, 77; 76, 87; 77, not_operator; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:isinstance; 80, argument_list; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:metainfo_enc; 83, string:b'info'; 84, attribute; 84, 85; 84, 86; 85, identifier:abc; 86, identifier:Mapping; 87, block; 87, 88; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:error; 92, identifier:MetainfoError; 93, argument_list; 93, 94; 94, string:"'info' is not a dictionary"; 95, elif_clause; 95, 96; 95, 101; 96, comparison_operator:not; 96, 97; 96, 98; 97, string:b'pieces'; 98, subscript; 98, 99; 98, 100; 99, identifier:metainfo_enc; 100, string:b'info'; 101, block; 101, 102; 102, raise_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:error; 106, identifier:MetainfoError; 107, argument_list; 107, 108; 108, string:"Missing 'pieces' in ['info']"; 109, if_statement; 109, 110; 109, 119; 109, 148; 110, boolean_operator:and; 110, 111; 110, 114; 111, comparison_operator:in; 111, 112; 111, 113; 112, string:b'info'; 113, identifier:metainfo_enc; 114, comparison_operator:in; 114, 115; 114, 116; 115, string:b'pieces'; 116, subscript; 116, 117; 116, 118; 117, identifier:metainfo_enc; 118, string:b'info'; 119, block; 119, 120; 119, 131; 119, 140; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:pieces; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:metainfo_enc; 127, string:b'info'; 128, identifier:pop; 129, argument_list; 129, 130; 130, string:b'pieces'; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:metainfo; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:utils; 137, identifier:decode_dict; 138, argument_list; 138, 139; 139, identifier:metainfo_enc; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 147; 142, subscript; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:metainfo; 145, string:'info'; 146, string:'pieces'; 147, identifier:pieces; 148, else_clause; 148, 149; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:metainfo; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:utils; 156, identifier:decode_dict; 157, argument_list; 157, 158; 158, identifier:metainfo_enc; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:torrent; 162, call; 162, 163; 162, 164; 163, identifier:cls; 164, argument_list; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:torrent; 169, identifier:_metainfo; 170, identifier:metainfo; 171, for_statement; 171, 172; 171, 173; 171, 176; 172, identifier:attr; 173, tuple; 173, 174; 173, 175; 174, string:'creation_date'; 175, string:'private'; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:setattr; 180, argument_list; 180, 181; 180, 182; 180, 183; 181, identifier:torrent; 182, identifier:attr; 183, call; 183, 184; 183, 185; 184, identifier:getattr; 185, argument_list; 185, 186; 185, 187; 186, identifier:torrent; 187, identifier:attr; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:info; 191, subscript; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:torrent; 194, identifier:metainfo; 195, string:'info'; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:torrent; 200, identifier:include_md5; 201, boolean_operator:or; 201, 202; 201, 210; 201, 211; 202, parenthesized_expression; 202, 203; 203, boolean_operator:and; 203, 204; 203, 207; 204, comparison_operator:in; 204, 205; 204, 206; 205, string:'length'; 206, identifier:info; 207, comparison_operator:in; 207, 208; 207, 209; 208, string:'md5sum'; 209, identifier:info; 210, line_continuation:\; 211, parenthesized_expression; 211, 212; 212, boolean_operator:and; 212, 213; 212, 216; 213, comparison_operator:in; 213, 214; 213, 215; 214, string:'files'; 215, identifier:info; 216, call; 216, 217; 216, 218; 217, identifier:all; 218, generator_expression; 218, 219; 218, 222; 219, comparison_operator:in; 219, 220; 219, 221; 220, string:'md5sum'; 221, identifier:fileinfo; 222, for_in_clause; 222, 223; 222, 224; 223, identifier:fileinfo; 224, subscript; 224, 225; 224, 226; 225, identifier:info; 226, string:'files'; 227, if_statement; 227, 228; 227, 229; 228, identifier:validate; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:torrent; 234, identifier:validate; 235, argument_list; 236, return_statement; 236, 237; 237, identifier:torrent | def read_stream(cls, stream, validate=True):
try:
content = stream.read(cls.MAX_TORRENT_FILE_SIZE)
except OSError as e:
raise error.ReadError(e.errno)
else:
try:
metainfo_enc = bdecode(content)
except BTFailure as e:
raise error.ParseError()
if validate:
if b'info' not in metainfo_enc:
raise error.MetainfoError("Missing 'info'")
elif not isinstance(metainfo_enc[b'info'], abc.Mapping):
raise error.MetainfoError("'info' is not a dictionary")
elif b'pieces' not in metainfo_enc[b'info']:
raise error.MetainfoError("Missing 'pieces' in ['info']")
if b'info' in metainfo_enc and b'pieces' in metainfo_enc[b'info']:
pieces = metainfo_enc[b'info'].pop(b'pieces')
metainfo = utils.decode_dict(metainfo_enc)
metainfo['info']['pieces'] = pieces
else:
metainfo = utils.decode_dict(metainfo_enc)
torrent = cls()
torrent._metainfo = metainfo
for attr in ('creation_date', 'private'):
setattr(torrent, attr, getattr(torrent, attr))
info = torrent.metainfo['info']
torrent.include_md5 = ('length' in info and 'md5sum' in info) or \
('files' in info and all('md5sum' in fileinfo
for fileinfo in info['files']))
if validate:
torrent.validate()
return torrent |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:filepaths; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:exclude; 7, tuple; 8, default_parameter; 8, 9; 8, 10; 9, identifier:hidden; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:empty; 13, True; 14, block; 14, 15; 14, 64; 15, if_statement; 15, 16; 15, 25; 15, 33; 16, not_operator; 16, 17; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:os; 21, identifier:path; 22, identifier:exists; 23, argument_list; 23, 24; 24, identifier:path; 25, block; 25, 26; 26, raise_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:error; 30, identifier:PathNotFoundError; 31, argument_list; 31, 32; 32, identifier:path; 33, elif_clause; 33, 34; 33, 53; 34, not_operator; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:os; 38, identifier:access; 39, argument_list; 39, 40; 39, 41; 39, 44; 40, identifier:path; 41, attribute; 41, 42; 41, 43; 42, identifier:os; 43, identifier:R_OK; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:effective_ids; 46, comparison_operator:in; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:os; 49, identifier:access; 50, attribute; 50, 51; 50, 52; 51, identifier:os; 52, identifier:supports_effective_ids; 53, block; 53, 54; 54, raise_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:error; 58, identifier:ReadError; 59, argument_list; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:errno; 62, identifier:EACCES; 63, identifier:path; 64, if_statement; 64, 65; 64, 73; 64, 77; 65, call; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:os; 69, identifier:path; 70, identifier:isfile; 71, argument_list; 71, 72; 72, identifier:path; 73, block; 73, 74; 74, return_statement; 74, 75; 75, list:[path]; 75, 76; 76, identifier:path; 77, else_clause; 77, 78; 78, block; 78, 79; 78, 83; 78, 175; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:filepaths; 82, list:[]; 83, for_statement; 83, 84; 83, 88; 83, 94; 84, pattern_list; 84, 85; 84, 86; 84, 87; 85, identifier:dirpath; 86, identifier:dirnames; 87, identifier:filenames; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:os; 91, identifier:walk; 92, argument_list; 92, 93; 93, identifier:path; 94, block; 94, 95; 94, 105; 95, if_statement; 95, 96; 95, 103; 96, boolean_operator:and; 96, 97; 96, 99; 97, not_operator; 97, 98; 98, identifier:hidden; 99, call; 99, 100; 99, 101; 100, identifier:is_hidden; 101, argument_list; 101, 102; 102, identifier:dirpath; 103, block; 103, 104; 104, continue_statement; 105, for_statement; 105, 106; 105, 107; 105, 108; 106, identifier:filename; 107, identifier:filenames; 108, block; 108, 109; 108, 119; 108, 131; 109, if_statement; 109, 110; 109, 117; 110, boolean_operator:and; 110, 111; 110, 113; 111, not_operator; 111, 112; 112, identifier:hidden; 113, call; 113, 114; 113, 115; 114, identifier:is_hidden; 115, argument_list; 115, 116; 116, identifier:filename; 117, block; 117, 118; 118, continue_statement; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:filepath; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:os; 126, identifier:path; 127, identifier:join; 128, argument_list; 128, 129; 128, 130; 129, identifier:dirpath; 130, identifier:filename; 131, if_statement; 131, 132; 131, 143; 131, 145; 132, call; 132, 133; 132, 134; 133, identifier:any; 134, generator_expression; 134, 135; 134, 140; 135, call; 135, 136; 135, 137; 136, identifier:is_match; 137, argument_list; 137, 138; 137, 139; 138, identifier:filepath; 139, identifier:pattern; 140, for_in_clause; 140, 141; 140, 142; 141, identifier:pattern; 142, identifier:exclude; 143, block; 143, 144; 144, continue_statement; 145, else_clause; 145, 146; 146, block; 146, 147; 147, if_statement; 147, 148; 147, 167; 148, boolean_operator:or; 148, 149; 148, 150; 149, identifier:empty; 150, comparison_operator:>; 150, 151; 150, 166; 151, call; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:os; 155, identifier:path; 156, identifier:getsize; 157, argument_list; 157, 158; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:os; 162, identifier:path; 163, identifier:realpath; 164, argument_list; 164, 165; 165, identifier:filepath; 166, integer:0; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:filepaths; 172, identifier:append; 173, argument_list; 173, 174; 174, identifier:filepath; 175, return_statement; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:sorted; 178, argument_list; 178, 179; 178, 180; 179, identifier:filepaths; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:key; 182, lambda; 182, 183; 182, 185; 183, lambda_parameters; 183, 184; 184, identifier:fp; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:fp; 188, identifier:casefold; 189, argument_list | def filepaths(path, exclude=(), hidden=True, empty=True):
if not os.path.exists(path):
raise error.PathNotFoundError(path)
elif not os.access(path, os.R_OK,
effective_ids=os.access in os.supports_effective_ids):
raise error.ReadError(errno.EACCES, path)
if os.path.isfile(path):
return [path]
else:
filepaths = []
for dirpath, dirnames, filenames in os.walk(path):
if not hidden and is_hidden(dirpath):
continue
for filename in filenames:
if not hidden and is_hidden(filename):
continue
filepath = os.path.join(dirpath, filename)
if any(is_match(filepath, pattern) for pattern in exclude):
continue
else:
if empty or os.path.getsize(os.path.realpath(filepath)) > 0:
filepaths.append(filepath)
return sorted(filepaths, key=lambda fp: fp.casefold()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:request; 6, default_parameter; 6, 7; 6, 8; 7, identifier:provider; 8, None; 9, block; 9, 10; 9, 28; 9, 50; 9, 77; 10, if_statement; 10, 11; 10, 15; 11, not_operator; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:settings; 14, identifier:CAS_FEDERATE; 15, block; 15, 16; 15, 23; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:logger; 20, identifier:warning; 21, argument_list; 21, 22; 22, string:"CAS_FEDERATE is False, set it to True to use federation"; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:redirect; 26, argument_list; 26, 27; 27, string:"cas_server:login"; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:renew; 31, call; 31, 32; 31, 33; 32, identifier:bool; 33, argument_list; 33, 34; 34, boolean_operator:and; 34, 35; 34, 43; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:request; 39, identifier:GET; 40, identifier:get; 41, argument_list; 41, 42; 42, string:'renew'; 43, comparison_operator:!=; 43, 44; 43, 49; 44, subscript; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:request; 47, identifier:GET; 48, string:'renew'; 49, string:"False"; 50, if_statement; 50, 51; 50, 64; 51, boolean_operator:and; 51, 52; 51, 62; 52, call; 52, 53; 52, 60; 53, attribute; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:request; 58, identifier:session; 59, identifier:get; 60, argument_list; 60, 61; 61, string:"authenticated"; 62, not_operator; 62, 63; 63, identifier:renew; 64, block; 64, 65; 64, 72; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:logger; 69, identifier:warning; 70, argument_list; 70, 71; 71, string:"User already authenticated, dropping federated authentication request"; 72, return_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:redirect; 75, argument_list; 75, 76; 76, string:"cas_server:login"; 77, try_statement; 77, 78; 77, 343; 78, block; 78, 79; 78, 92; 78, 103; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:provider; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:FederatedIendityProvider; 86, identifier:objects; 87, identifier:get; 88, argument_list; 88, 89; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:suffix; 91, identifier:provider; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:auth; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:get_cas_client; 99, argument_list; 99, 100; 99, 101; 99, 102; 100, identifier:request; 101, identifier:provider; 102, identifier:renew; 103, if_statement; 103, 104; 103, 109; 103, 132; 104, comparison_operator:not; 104, 105; 104, 106; 105, string:'ticket'; 106, attribute; 106, 107; 106, 108; 107, identifier:request; 108, identifier:GET; 109, block; 109, 110; 109, 123; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:logger; 114, identifier:info; 115, argument_list; 115, 116; 116, binary_operator:%; 116, 117; 116, 118; 117, string:"Trying to authenticate %s again"; 118, attribute; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:auth; 121, identifier:provider; 122, identifier:server_url; 123, return_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:HttpResponseRedirect; 126, argument_list; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:auth; 130, identifier:get_login_url; 131, argument_list; 132, else_clause; 132, 133; 133, block; 133, 134; 133, 142; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:ticket; 137, subscript; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:request; 140, identifier:GET; 141, string:'ticket'; 142, try_statement; 142, 143; 142, 297; 143, block; 143, 144; 144, if_statement; 144, 145; 144, 151; 144, 265; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:auth; 148, identifier:verify_ticket; 149, argument_list; 149, 150; 150, identifier:ticket; 151, block; 151, 152; 151, 169; 151, 185; 151, 195; 151, 203; 151, 218; 151, 228; 151, 235; 151, 263; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:logger; 156, identifier:info; 157, argument_list; 157, 158; 158, binary_operator:%; 158, 159; 158, 160; 159, string:"Got a valid ticket for %s from %s"; 160, tuple; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:auth; 163, identifier:username; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:auth; 167, identifier:provider; 168, identifier:server_url; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:params; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:utils; 175, identifier:copy_params; 176, argument_list; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:request; 179, identifier:GET; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:ignore; 182, set; 182, 183; 182, 184; 183, string:"ticket"; 184, string:"remember"; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 192; 187, subscript; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:request; 190, identifier:session; 191, string:"federate_username"; 192, attribute; 192, 193; 192, 194; 193, identifier:auth; 194, identifier:federated_username; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 202; 197, subscript; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:request; 200, identifier:session; 201, string:"federate_ticket"; 202, identifier:ticket; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:auth; 207, identifier:register_slo; 208, argument_list; 208, 209; 208, 212; 208, 217; 209, attribute; 209, 210; 209, 211; 210, identifier:auth; 211, identifier:federated_username; 212, attribute; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:request; 215, identifier:session; 216, identifier:session_key; 217, identifier:ticket; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:url; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:utils; 224, identifier:reverse_params; 225, argument_list; 225, 226; 225, 227; 226, string:"cas_server:login"; 227, identifier:params; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:response; 231, call; 231, 232; 231, 233; 232, identifier:HttpResponseRedirect; 233, argument_list; 233, 234; 234, identifier:url; 235, if_statement; 235, 236; 235, 244; 236, call; 236, 237; 236, 242; 237, attribute; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:request; 240, identifier:GET; 241, identifier:get; 242, argument_list; 242, 243; 243, string:"remember"; 244, block; 244, 245; 244, 251; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:max_age; 248, attribute; 248, 249; 248, 250; 249, identifier:settings; 250, identifier:CAS_FEDERATE_REMEMBER_TIMEOUT; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:utils; 255, identifier:set_cookie; 256, argument_list; 256, 257; 256, 258; 256, 259; 256, 262; 257, identifier:response; 258, string:"remember_provider"; 259, attribute; 259, 260; 259, 261; 260, identifier:provider; 261, identifier:suffix; 262, identifier:max_age; 263, return_statement; 263, 264; 264, identifier:response; 265, else_clause; 265, 266; 266, block; 266, 267; 266, 288; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:logger; 271, identifier:info; 272, argument_list; 272, 273; 273, binary_operator:%; 273, 274; 273, 278; 274, parenthesized_expression; 274, 275; 275, concatenated_string; 275, 276; 275, 277; 276, string:"Got an invalid ticket %s from %s for service %s. "; 277, string:"Retrying authentication"; 278, tuple; 278, 279; 278, 280; 278, 285; 279, identifier:ticket; 280, attribute; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:auth; 283, identifier:provider; 284, identifier:server_url; 285, attribute; 285, 286; 285, 287; 286, identifier:self; 287, identifier:service_url; 288, return_statement; 288, 289; 289, call; 289, 290; 289, 291; 290, identifier:HttpResponseRedirect; 291, argument_list; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:auth; 295, identifier:get_login_url; 296, argument_list; 297, except_clause; 297, 298; 297, 302; 298, as_pattern; 298, 299; 298, 300; 299, identifier:SyntaxError; 300, as_pattern_target; 300, 301; 301, identifier:error; 302, block; 302, 303; 302, 327; 302, 334; 302, 341; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:messages; 307, identifier:add_message; 308, argument_list; 308, 309; 308, 310; 308, 313; 309, identifier:request; 310, attribute; 310, 311; 310, 312; 311, identifier:messages; 312, identifier:ERROR; 313, binary_operator:%; 313, 314; 313, 320; 314, call; 314, 315; 314, 316; 315, identifier:_; 316, argument_list; 316, 317; 317, concatenated_string; 317, 318; 317, 319; 318, string:u"Invalid response from your identity provider CAS upon "; 319, string:u"ticket %(ticket)s validation: %(error)r"; 320, dictionary; 320, 321; 320, 324; 321, pair; 321, 322; 321, 323; 322, string:'ticket'; 323, identifier:ticket; 324, pair; 324, 325; 324, 326; 325, string:'error'; 326, identifier:error; 327, expression_statement; 327, 328; 328, assignment; 328, 329; 328, 330; 329, identifier:response; 330, call; 330, 331; 330, 332; 331, identifier:redirect; 332, argument_list; 332, 333; 333, string:"cas_server:login"; 334, expression_statement; 334, 335; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:response; 338, identifier:delete_cookie; 339, argument_list; 339, 340; 340, string:"remember_provider"; 341, return_statement; 341, 342; 342, identifier:response; 343, except_clause; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:FederatedIendityProvider; 346, identifier:DoesNotExist; 347, block; 347, 348; 347, 357; 348, expression_statement; 348, 349; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:logger; 352, identifier:warning; 353, argument_list; 353, 354; 354, binary_operator:%; 354, 355; 354, 356; 355, string:"Identity provider suffix %s not found"; 356, identifier:provider; 357, return_statement; 357, 358; 358, call; 358, 359; 358, 360; 359, identifier:redirect; 360, argument_list; 360, 361; 361, string:"cas_server:login" | def get(self, request, provider=None):
if not settings.CAS_FEDERATE:
logger.warning("CAS_FEDERATE is False, set it to True to use federation")
return redirect("cas_server:login")
renew = bool(request.GET.get('renew') and request.GET['renew'] != "False")
if self.request.session.get("authenticated") and not renew:
logger.warning("User already authenticated, dropping federated authentication request")
return redirect("cas_server:login")
try:
provider = FederatedIendityProvider.objects.get(suffix=provider)
auth = self.get_cas_client(request, provider, renew)
if 'ticket' not in request.GET:
logger.info("Trying to authenticate %s again" % auth.provider.server_url)
return HttpResponseRedirect(auth.get_login_url())
else:
ticket = request.GET['ticket']
try:
if auth.verify_ticket(ticket):
logger.info(
"Got a valid ticket for %s from %s" % (
auth.username,
auth.provider.server_url
)
)
params = utils.copy_params(request.GET, ignore={"ticket", "remember"})
request.session["federate_username"] = auth.federated_username
request.session["federate_ticket"] = ticket
auth.register_slo(
auth.federated_username,
request.session.session_key,
ticket
)
url = utils.reverse_params("cas_server:login", params)
response = HttpResponseRedirect(url)
if request.GET.get("remember"):
max_age = settings.CAS_FEDERATE_REMEMBER_TIMEOUT
utils.set_cookie(
response,
"remember_provider",
provider.suffix,
max_age
)
return response
else:
logger.info(
(
"Got an invalid ticket %s from %s for service %s. "
"Retrying authentication"
) % (
ticket,
auth.provider.server_url,
self.service_url
)
)
return HttpResponseRedirect(auth.get_login_url())
except SyntaxError as error:
messages.add_message(
request,
messages.ERROR,
_(
u"Invalid response from your identity provider CAS upon "
u"ticket %(ticket)s validation: %(error)r"
) % {'ticket': ticket, 'error': error}
)
response = redirect("cas_server:login")
response.delete_cookie("remember_provider")
return response
except FederatedIendityProvider.DoesNotExist:
logger.warning("Identity provider suffix %s not found" % provider)
return redirect("cas_server:login") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:service_login; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 347; 5, 376; 6, try_statement; 6, 7; 6, 231; 6, 263; 6, 288; 6, 313; 7, block; 7, 8; 7, 19; 7, 28; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:service_pattern; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:ServicePattern; 14, identifier:validate; 15, argument_list; 15, 16; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:service; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:service_pattern; 23, identifier:check_user; 24, argument_list; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:user; 28, if_statement; 28, 29; 28, 45; 28, 164; 29, boolean_operator:and; 29, 30; 29, 41; 30, call; 30, 31; 30, 38; 31, attribute; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:request; 36, identifier:session; 37, identifier:get; 38, argument_list; 38, 39; 38, 40; 39, string:"warn"; 40, True; 41, not_operator; 41, 42; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:warned; 45, block; 45, 46; 45, 74; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:messages; 50, identifier:add_message; 51, argument_list; 51, 52; 51, 55; 51, 58; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:request; 55, attribute; 55, 56; 55, 57; 56, identifier:messages; 57, identifier:WARNING; 58, binary_operator:%; 58, 59; 58, 63; 59, call; 59, 60; 59, 61; 60, identifier:_; 61, argument_list; 61, 62; 62, string:u"Authentication has been required by service %(name)s (%(url)s)"; 63, dictionary; 63, 64; 63, 69; 64, pair; 64, 65; 64, 66; 65, string:'name'; 66, attribute; 66, 67; 66, 68; 67, identifier:service_pattern; 68, identifier:name; 69, pair; 69, 70; 69, 71; 70, string:'url'; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:service; 74, if_statement; 74, 75; 74, 78; 74, 97; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:ajax; 78, block; 78, 79; 78, 89; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:data; 82, dictionary; 82, 83; 82, 86; 83, pair; 83, 84; 83, 85; 84, string:"status"; 85, string:"error"; 86, pair; 86, 87; 86, 88; 87, string:"detail"; 88, string:"confirmation needed"; 89, return_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:json_response; 92, argument_list; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:request; 96, identifier:data; 97, else_clause; 97, 98; 98, block; 98, 99; 98, 145; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:warn_form; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:forms; 105, identifier:WarnForm; 106, argument_list; 106, 107; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:initial; 109, dictionary; 109, 110; 109, 115; 109, 120; 109, 125; 109, 130; 109, 133; 110, pair; 110, 111; 110, 112; 111, string:'service'; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:service; 115, pair; 115, 116; 115, 117; 116, string:'renew'; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:renew; 120, pair; 120, 121; 120, 122; 121, string:'gateway'; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:gateway; 125, pair; 125, 126; 125, 127; 126, string:'method'; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:method; 130, pair; 130, 131; 130, 132; 131, string:'warned'; 132, True; 133, pair; 133, 134; 133, 135; 134, string:'lt'; 135, subscript; 135, 136; 135, 143; 136, subscript; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:request; 141, identifier:session; 142, string:'lt'; 143, unary_operator:-; 143, 144; 144, integer:1; 145, return_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:render; 148, argument_list; 148, 149; 148, 152; 148, 155; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:request; 152, attribute; 152, 153; 152, 154; 153, identifier:settings; 154, identifier:CAS_WARN_TEMPLATE; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:utils; 158, identifier:context; 159, argument_list; 159, 160; 160, dictionary; 160, 161; 161, pair; 161, 162; 161, 163; 162, string:'form'; 163, identifier:warn_form; 164, else_clause; 164, 165; 165, block; 165, 166; 165, 178; 165, 197; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:list; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:messages; 173, identifier:get_messages; 174, argument_list; 174, 175; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:request; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:redirect_url; 181, call; 181, 182; 181, 187; 182, attribute; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:user; 186, identifier:get_service_url; 187, argument_list; 187, 188; 187, 191; 187, 192; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:service; 191, identifier:service_pattern; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:renew; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:renewed; 197, if_statement; 197, 198; 197, 202; 197, 208; 198, not_operator; 198, 199; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:ajax; 202, block; 202, 203; 203, return_statement; 203, 204; 204, call; 204, 205; 204, 206; 205, identifier:HttpResponseRedirect; 206, argument_list; 206, 207; 207, identifier:redirect_url; 208, else_clause; 208, 209; 209, block; 209, 210; 209, 223; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:data; 213, dictionary; 213, 214; 213, 217; 213, 220; 214, pair; 214, 215; 214, 216; 215, string:"status"; 216, string:"success"; 217, pair; 217, 218; 217, 219; 218, string:"detail"; 219, string:"auth"; 220, pair; 220, 221; 220, 222; 221, string:"url"; 222, identifier:redirect_url; 223, return_statement; 223, 224; 224, call; 224, 225; 224, 226; 225, identifier:json_response; 226, argument_list; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:request; 230, identifier:data; 231, except_clause; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:ServicePattern; 234, identifier:DoesNotExist; 235, block; 235, 236; 235, 240; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:error; 239, integer:1; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:messages; 244, identifier:add_message; 245, argument_list; 245, 246; 245, 249; 245, 252; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:request; 249, attribute; 249, 250; 249, 251; 250, identifier:messages; 251, identifier:ERROR; 252, binary_operator:%; 252, 253; 252, 257; 253, call; 253, 254; 253, 255; 254, identifier:_; 255, argument_list; 255, 256; 256, string:u'Service %(url)s not allowed.'; 257, dictionary; 257, 258; 258, pair; 258, 259; 258, 260; 259, string:'url'; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:service; 263, except_clause; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:models; 266, identifier:BadUsername; 267, block; 267, 268; 267, 272; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:error; 271, integer:2; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:messages; 276, identifier:add_message; 277, argument_list; 277, 278; 277, 281; 277, 284; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:request; 281, attribute; 281, 282; 281, 283; 282, identifier:messages; 283, identifier:ERROR; 284, call; 284, 285; 284, 286; 285, identifier:_; 286, argument_list; 286, 287; 287, string:u"Username not allowed"; 288, except_clause; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:models; 291, identifier:BadFilter; 292, block; 292, 293; 292, 297; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:error; 296, integer:3; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:messages; 301, identifier:add_message; 302, argument_list; 302, 303; 302, 306; 302, 309; 303, attribute; 303, 304; 303, 305; 304, identifier:self; 305, identifier:request; 306, attribute; 306, 307; 306, 308; 307, identifier:messages; 308, identifier:ERROR; 309, call; 309, 310; 309, 311; 310, identifier:_; 311, argument_list; 311, 312; 312, string:u"User characteristics not allowed"; 313, except_clause; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:models; 316, identifier:UserFieldNotDefined; 317, block; 317, 318; 317, 322; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:error; 321, integer:4; 322, expression_statement; 322, 323; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:messages; 326, identifier:add_message; 327, argument_list; 327, 328; 327, 331; 327, 334; 328, attribute; 328, 329; 328, 330; 329, identifier:self; 330, identifier:request; 331, attribute; 331, 332; 331, 333; 332, identifier:messages; 333, identifier:ERROR; 334, binary_operator:%; 334, 335; 334, 341; 335, call; 335, 336; 335, 337; 336, identifier:_; 337, argument_list; 337, 338; 338, concatenated_string; 338, 339; 338, 340; 339, string:u"The attribute %(field)s is needed to use"; 340, string:u" that service"; 341, dictionary; 341, 342; 342, pair; 342, 343; 342, 344; 343, string:'field'; 344, attribute; 344, 345; 344, 346; 345, identifier:service_pattern; 346, identifier:user_field; 347, if_statement; 347, 348; 347, 356; 348, boolean_operator:and; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:self; 351, identifier:gateway; 352, not_operator; 352, 353; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:ajax; 356, block; 356, 357; 356, 369; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 360; 359, identifier:list; 360, argument_list; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:messages; 364, identifier:get_messages; 365, argument_list; 365, 366; 366, attribute; 366, 367; 366, 368; 367, identifier:self; 368, identifier:request; 369, return_statement; 369, 370; 370, call; 370, 371; 370, 372; 371, identifier:HttpResponseRedirect; 372, argument_list; 372, 373; 373, attribute; 373, 374; 373, 375; 374, identifier:self; 375, identifier:service; 376, if_statement; 376, 377; 376, 381; 376, 405; 377, not_operator; 377, 378; 378, attribute; 378, 379; 378, 380; 379, identifier:self; 380, identifier:ajax; 381, block; 381, 382; 382, return_statement; 382, 383; 383, call; 383, 384; 383, 385; 384, identifier:render; 385, argument_list; 385, 386; 385, 389; 385, 392; 386, attribute; 386, 387; 386, 388; 387, identifier:self; 388, identifier:request; 389, attribute; 389, 390; 389, 391; 390, identifier:settings; 391, identifier:CAS_LOGGED_TEMPLATE; 392, call; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:utils; 395, identifier:context; 396, argument_list; 396, 397; 397, dictionary; 397, 398; 398, pair; 398, 399; 398, 400; 399, string:'session'; 400, attribute; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:self; 403, identifier:request; 404, identifier:session; 405, else_clause; 405, 406; 406, block; 406, 407; 406, 420; 407, expression_statement; 407, 408; 408, assignment; 408, 409; 408, 410; 409, identifier:data; 410, dictionary; 410, 411; 410, 414; 410, 417; 411, pair; 411, 412; 411, 413; 412, string:"status"; 413, string:"error"; 414, pair; 414, 415; 414, 416; 415, string:"detail"; 416, string:"auth"; 417, pair; 417, 418; 417, 419; 418, string:"code"; 419, identifier:error; 420, return_statement; 420, 421; 421, call; 421, 422; 421, 423; 422, identifier:json_response; 423, argument_list; 423, 424; 423, 427; 424, attribute; 424, 425; 424, 426; 425, identifier:self; 426, identifier:request; 427, identifier:data | def service_login(self):
try:
service_pattern = ServicePattern.validate(self.service)
service_pattern.check_user(self.user)
if self.request.session.get("warn", True) and not self.warned:
messages.add_message(
self.request,
messages.WARNING,
_(u"Authentication has been required by service %(name)s (%(url)s)") %
{'name': service_pattern.name, 'url': self.service}
)
if self.ajax:
data = {"status": "error", "detail": "confirmation needed"}
return json_response(self.request, data)
else:
warn_form = forms.WarnForm(initial={
'service': self.service,
'renew': self.renew,
'gateway': self.gateway,
'method': self.method,
'warned': True,
'lt': self.request.session['lt'][-1]
})
return render(
self.request,
settings.CAS_WARN_TEMPLATE,
utils.context({'form': warn_form})
)
else:
list(messages.get_messages(self.request))
redirect_url = self.user.get_service_url(
self.service,
service_pattern,
renew=self.renewed
)
if not self.ajax:
return HttpResponseRedirect(redirect_url)
else:
data = {"status": "success", "detail": "auth", "url": redirect_url}
return json_response(self.request, data)
except ServicePattern.DoesNotExist:
error = 1
messages.add_message(
self.request,
messages.ERROR,
_(u'Service %(url)s not allowed.') % {'url': self.service}
)
except models.BadUsername:
error = 2
messages.add_message(
self.request,
messages.ERROR,
_(u"Username not allowed")
)
except models.BadFilter:
error = 3
messages.add_message(
self.request,
messages.ERROR,
_(u"User characteristics not allowed")
)
except models.UserFieldNotDefined:
error = 4
messages.add_message(
self.request,
messages.ERROR,
_(u"The attribute %(field)s is needed to use"
u" that service") % {'field': service_pattern.user_field}
)
if self.gateway and not self.ajax:
list(messages.get_messages(self.request))
return HttpResponseRedirect(self.service)
if not self.ajax:
return render(
self.request,
settings.CAS_LOGGED_TEMPLATE,
utils.context({'session': self.request.session})
)
else:
data = {"status": "error", "detail": "auth", "code": error}
return json_response(self.request, data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:not_authenticated; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 162; 6, if_statement; 6, 7; 6, 10; 7, attribute; 7, 8; 7, 9; 8, identifier:self; 9, identifier:service; 10, block; 10, 11; 11, try_statement; 11, 12; 11, 132; 12, block; 12, 13; 12, 24; 12, 53; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:service_pattern; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:ServicePattern; 19, identifier:validate; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:service; 24, if_statement; 24, 25; 24, 33; 25, boolean_operator:and; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:gateway; 29, not_operator; 29, 30; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:ajax; 33, block; 33, 34; 33, 46; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:list; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:messages; 41, identifier:get_messages; 42, argument_list; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:request; 46, return_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:HttpResponseRedirect; 49, argument_list; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:service; 53, if_statement; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:settings; 56, identifier:CAS_SHOW_SERVICE_MESSAGES; 57, block; 57, 58; 58, if_statement; 58, 59; 58, 73; 58, 102; 59, boolean_operator:and; 59, 60; 59, 70; 60, call; 60, 61; 60, 68; 61, attribute; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:request; 66, identifier:session; 67, identifier:get; 68, argument_list; 68, 69; 69, string:"authenticated"; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:renew; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:messages; 78, identifier:add_message; 79, argument_list; 79, 80; 79, 83; 79, 86; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:request; 83, attribute; 83, 84; 83, 85; 84, identifier:messages; 85, identifier:WARNING; 86, binary_operator:%; 86, 87; 86, 91; 87, call; 87, 88; 87, 89; 88, identifier:_; 89, argument_list; 89, 90; 90, string:u"Authentication renewal required by service %(name)s (%(url)s)."; 91, dictionary; 91, 92; 91, 97; 92, pair; 92, 93; 92, 94; 93, string:'name'; 94, attribute; 94, 95; 94, 96; 95, identifier:service_pattern; 96, identifier:name; 97, pair; 97, 98; 97, 99; 98, string:'url'; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:service; 102, else_clause; 102, 103; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:messages; 108, identifier:add_message; 109, argument_list; 109, 110; 109, 113; 109, 116; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:request; 113, attribute; 113, 114; 113, 115; 114, identifier:messages; 115, identifier:WARNING; 116, binary_operator:%; 116, 117; 116, 121; 117, call; 117, 118; 117, 119; 118, identifier:_; 119, argument_list; 119, 120; 120, string:u"Authentication required by service %(name)s (%(url)s)."; 121, dictionary; 121, 122; 121, 127; 122, pair; 122, 123; 122, 124; 123, string:'name'; 124, attribute; 124, 125; 124, 126; 125, identifier:service_pattern; 126, identifier:name; 127, pair; 127, 128; 127, 129; 128, string:'url'; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:service; 132, except_clause; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:ServicePattern; 135, identifier:DoesNotExist; 136, block; 136, 137; 137, if_statement; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:settings; 140, identifier:CAS_SHOW_SERVICE_MESSAGES; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:messages; 146, identifier:add_message; 147, argument_list; 147, 148; 147, 151; 147, 154; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:request; 151, attribute; 151, 152; 151, 153; 152, identifier:messages; 153, identifier:ERROR; 154, binary_operator:%; 154, 155; 154, 159; 155, call; 155, 156; 155, 157; 156, identifier:_; 157, argument_list; 157, 158; 158, string:u'Service %s not allowed'; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:service; 162, if_statement; 162, 163; 162, 166; 162, 200; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:ajax; 166, block; 166, 167; 166, 192; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:data; 170, dictionary; 170, 171; 170, 174; 170, 177; 171, pair; 171, 172; 171, 173; 172, string:"status"; 173, string:"error"; 174, pair; 174, 175; 174, 176; 175, string:"detail"; 176, string:"login required"; 177, pair; 177, 178; 177, 179; 178, string:"url"; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:utils; 182, identifier:reverse_params; 183, argument_list; 183, 184; 183, 185; 184, string:"cas_server:login"; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:params; 187, attribute; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:request; 191, identifier:GET; 192, return_statement; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:json_response; 195, argument_list; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:request; 199, identifier:data; 200, else_clause; 200, 201; 201, block; 201, 202; 202, if_statement; 202, 203; 202, 206; 202, 435; 203, attribute; 203, 204; 203, 205; 204, identifier:settings; 205, identifier:CAS_FEDERATE; 206, block; 206, 207; 207, if_statement; 207, 208; 207, 215; 207, 246; 208, boolean_operator:and; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:username; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:ticket; 215, block; 215, 216; 216, return_statement; 216, 217; 217, call; 217, 218; 217, 219; 218, identifier:render; 219, argument_list; 219, 220; 219, 223; 219, 226; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:request; 223, attribute; 223, 224; 223, 225; 224, identifier:settings; 225, identifier:CAS_LOGIN_TEMPLATE; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:utils; 229, identifier:context; 230, argument_list; 230, 231; 231, dictionary; 231, 232; 231, 237; 231, 240; 232, pair; 232, 233; 232, 234; 233, string:'form'; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:form; 237, pair; 237, 238; 237, 239; 238, string:'auto_submit'; 239, True; 240, pair; 240, 241; 240, 242; 241, string:'post_url'; 242, call; 242, 243; 242, 244; 243, identifier:reverse; 244, argument_list; 244, 245; 245, string:"cas_server:login"; 246, else_clause; 246, 247; 247, block; 247, 248; 248, if_statement; 248, 249; 248, 277; 248, 322; 249, parenthesized_expression; 249, 250; 250, boolean_operator:and; 250, 251; 250, 261; 251, call; 251, 252; 251, 259; 252, attribute; 252, 253; 252, 258; 253, attribute; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:request; 257, identifier:COOKIES; 258, identifier:get; 259, argument_list; 259, 260; 260, string:'remember_provider'; 261, call; 261, 262; 261, 267; 262, attribute; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:FederatedIendityProvider; 265, identifier:objects; 266, identifier:filter; 267, argument_list; 267, 268; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:suffix; 270, subscript; 270, 271; 270, 276; 271, attribute; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:request; 275, identifier:COOKIES; 276, string:'remember_provider'; 277, block; 277, 278; 277, 291; 277, 317; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:params; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:utils; 284, identifier:copy_params; 285, argument_list; 285, 286; 286, attribute; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:request; 290, identifier:GET; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:url; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:utils; 297, identifier:reverse_params; 298, argument_list; 298, 299; 298, 300; 298, 303; 299, string:"cas_server:federateAuth"; 300, keyword_argument; 300, 301; 300, 302; 301, identifier:params; 302, identifier:params; 303, keyword_argument; 303, 304; 303, 305; 304, identifier:kwargs; 305, call; 305, 306; 305, 307; 306, identifier:dict; 307, argument_list; 307, 308; 308, keyword_argument; 308, 309; 308, 310; 309, identifier:provider; 310, subscript; 310, 311; 310, 316; 311, attribute; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:request; 315, identifier:COOKIES; 316, string:'remember_provider'; 317, return_statement; 317, 318; 318, call; 318, 319; 318, 320; 319, identifier:HttpResponseRedirect; 320, argument_list; 320, 321; 321, identifier:url; 322, else_clause; 322, 323; 323, block; 323, 324; 323, 408; 324, if_statement; 324, 325; 324, 339; 325, boolean_operator:and; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:self; 328, identifier:renew; 329, call; 329, 330; 329, 337; 330, attribute; 330, 331; 330, 336; 331, attribute; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:self; 334, identifier:request; 335, identifier:session; 336, identifier:get; 337, argument_list; 337, 338; 338, string:"authenticated"; 339, block; 339, 340; 340, try_statement; 340, 341; 340, 402; 341, block; 341, 342; 341, 360; 341, 373; 341, 397; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 345; 344, identifier:user; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:FederatedUser; 348, identifier:get_from_federated_username; 349, argument_list; 349, 350; 350, call; 350, 351; 350, 358; 351, attribute; 351, 352; 351, 357; 352, attribute; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:request; 356, identifier:session; 357, identifier:get; 358, argument_list; 358, 359; 359, string:"username"; 360, expression_statement; 360, 361; 361, assignment; 361, 362; 361, 363; 362, identifier:params; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:utils; 366, identifier:copy_params; 367, argument_list; 367, 368; 368, attribute; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:self; 371, identifier:request; 372, identifier:GET; 373, expression_statement; 373, 374; 374, assignment; 374, 375; 374, 376; 375, identifier:url; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:utils; 379, identifier:reverse_params; 380, argument_list; 380, 381; 380, 382; 380, 385; 381, string:"cas_server:federateAuth"; 382, keyword_argument; 382, 383; 382, 384; 383, identifier:params; 384, identifier:params; 385, keyword_argument; 385, 386; 385, 387; 386, identifier:kwargs; 387, call; 387, 388; 387, 389; 388, identifier:dict; 389, argument_list; 389, 390; 390, keyword_argument; 390, 391; 390, 392; 391, identifier:provider; 392, attribute; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:user; 395, identifier:provider; 396, identifier:suffix; 397, return_statement; 397, 398; 398, call; 398, 399; 398, 400; 399, identifier:HttpResponseRedirect; 400, argument_list; 400, 401; 401, identifier:url; 402, except_clause; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, identifier:FederatedUser; 405, identifier:DoesNotExist; 406, block; 406, 407; 407, pass_statement; 408, return_statement; 408, 409; 409, call; 409, 410; 409, 411; 410, identifier:render; 411, argument_list; 411, 412; 411, 415; 411, 418; 412, attribute; 412, 413; 412, 414; 413, identifier:self; 414, identifier:request; 415, attribute; 415, 416; 415, 417; 416, identifier:settings; 417, identifier:CAS_LOGIN_TEMPLATE; 418, call; 418, 419; 418, 422; 419, attribute; 419, 420; 419, 421; 420, identifier:utils; 421, identifier:context; 422, argument_list; 422, 423; 423, dictionary; 423, 424; 423, 429; 424, pair; 424, 425; 424, 426; 425, string:'form'; 426, attribute; 426, 427; 426, 428; 427, identifier:self; 428, identifier:form; 429, pair; 429, 430; 429, 431; 430, string:'post_url'; 431, call; 431, 432; 431, 433; 432, identifier:reverse; 433, argument_list; 433, 434; 434, string:"cas_server:federateAuth"; 435, else_clause; 435, 436; 436, block; 436, 437; 437, return_statement; 437, 438; 438, call; 438, 439; 438, 440; 439, identifier:render; 440, argument_list; 440, 441; 440, 444; 440, 447; 441, attribute; 441, 442; 441, 443; 442, identifier:self; 443, identifier:request; 444, attribute; 444, 445; 444, 446; 445, identifier:settings; 446, identifier:CAS_LOGIN_TEMPLATE; 447, call; 447, 448; 447, 451; 448, attribute; 448, 449; 448, 450; 449, identifier:utils; 450, identifier:context; 451, argument_list; 451, 452; 452, dictionary; 452, 453; 453, pair; 453, 454; 453, 455; 454, string:'form'; 455, attribute; 455, 456; 455, 457; 456, identifier:self; 457, identifier:form | def not_authenticated(self):
if self.service:
try:
service_pattern = ServicePattern.validate(self.service)
if self.gateway and not self.ajax:
list(messages.get_messages(self.request))
return HttpResponseRedirect(self.service)
if settings.CAS_SHOW_SERVICE_MESSAGES:
if self.request.session.get("authenticated") and self.renew:
messages.add_message(
self.request,
messages.WARNING,
_(u"Authentication renewal required by service %(name)s (%(url)s).") %
{'name': service_pattern.name, 'url': self.service}
)
else:
messages.add_message(
self.request,
messages.WARNING,
_(u"Authentication required by service %(name)s (%(url)s).") %
{'name': service_pattern.name, 'url': self.service}
)
except ServicePattern.DoesNotExist:
if settings.CAS_SHOW_SERVICE_MESSAGES:
messages.add_message(
self.request,
messages.ERROR,
_(u'Service %s not allowed') % self.service
)
if self.ajax:
data = {
"status": "error",
"detail": "login required",
"url": utils.reverse_params("cas_server:login", params=self.request.GET)
}
return json_response(self.request, data)
else:
if settings.CAS_FEDERATE:
if self.username and self.ticket:
return render(
self.request,
settings.CAS_LOGIN_TEMPLATE,
utils.context({
'form': self.form,
'auto_submit': True,
'post_url': reverse("cas_server:login")
})
)
else:
if (
self.request.COOKIES.get('remember_provider') and
FederatedIendityProvider.objects.filter(
suffix=self.request.COOKIES['remember_provider']
)
):
params = utils.copy_params(self.request.GET)
url = utils.reverse_params(
"cas_server:federateAuth",
params=params,
kwargs=dict(provider=self.request.COOKIES['remember_provider'])
)
return HttpResponseRedirect(url)
else:
if self.renew and self.request.session.get("authenticated"):
try:
user = FederatedUser.get_from_federated_username(
self.request.session.get("username")
)
params = utils.copy_params(self.request.GET)
url = utils.reverse_params(
"cas_server:federateAuth",
params=params,
kwargs=dict(provider=user.provider.suffix)
)
return HttpResponseRedirect(url)
except FederatedUser.DoesNotExist:
pass
return render(
self.request,
settings.CAS_LOGIN_TEMPLATE,
utils.context({
'form': self.form,
'post_url': reverse("cas_server:federateAuth")
})
)
else:
return render(
self.request,
settings.CAS_LOGIN_TEMPLATE,
utils.context({'form': self.form})
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:match_path_to_api_path; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:path_definitions; 5, identifier:target_path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:base_path; 8, string:''; 9, default_parameter; 9, 10; 9, 11; 10, identifier:context; 11, None; 12, block; 12, 13; 12, 22; 12, 30; 12, 164; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:context; 16, None; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:context; 21, dictionary; 22, assert_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:isinstance; 25, argument_list; 25, 26; 25, 27; 26, identifier:context; 27, attribute; 27, 28; 27, 29; 28, identifier:collections; 29, identifier:Mapping; 30, if_statement; 30, 31; 30, 37; 30, 154; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:target_path; 34, identifier:startswith; 35, argument_list; 35, 36; 36, identifier:base_path; 37, block; 37, 38; 37, 49; 37, 55; 37, 61; 37, 143; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:normalized_target_path; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:re; 44, identifier:sub; 45, argument_list; 45, 46; 45, 47; 45, 48; 46, identifier:NORMALIZE_SLASH_REGEX; 47, string:'/'; 48, identifier:target_path; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:matching_api_paths; 52, call; 52, 53; 52, 54; 53, identifier:list; 54, argument_list; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:matching_api_paths_regex; 58, call; 58, 59; 58, 60; 59, identifier:list; 60, argument_list; 61, for_statement; 61, 62; 61, 65; 61, 70; 62, pattern_list; 62, 63; 62, 64; 63, identifier:p; 64, identifier:v; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:path_definitions; 68, identifier:items; 69, argument_list; 70, block; 70, 71; 70, 84; 70, 108; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:full_path; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:re; 77, identifier:sub; 78, argument_list; 78, 79; 78, 80; 78, 81; 79, identifier:NORMALIZE_SLASH_REGEX; 80, string:'/'; 81, binary_operator:+; 81, 82; 81, 83; 82, identifier:base_path; 83, identifier:p; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:r; 87, call; 87, 88; 87, 89; 88, identifier:path_to_regex; 89, argument_list; 89, 90; 89, 93; 89, 99; 89, 105; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:api_path; 92, identifier:full_path; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:path_parameters; 95, call; 95, 96; 95, 97; 96, identifier:extract_path_parameters; 97, argument_list; 97, 98; 98, identifier:v; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:operation_parameters; 101, call; 101, 102; 101, 103; 102, identifier:extract_operation_parameters; 103, argument_list; 103, 104; 104, identifier:v; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:context; 107, identifier:context; 108, if_statement; 108, 109; 108, 112; 108, 120; 109, comparison_operator:==; 109, 110; 109, 111; 110, identifier:full_path; 111, identifier:normalized_target_path; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:matching_api_paths; 117, identifier:append; 118, argument_list; 118, 119; 119, identifier:p; 120, elif_clause; 120, 121; 120, 127; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:r; 124, identifier:match; 125, argument_list; 125, 126; 126, identifier:normalized_target_path; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 134; 130, attribute; 130, 131; 130, 132; 130, 133; 131, identifier:matching_api_paths_regex; 132, line_continuation:\; 133, identifier:append; 134, argument_list; 134, 135; 135, tuple; 135, 136; 135, 137; 136, identifier:p; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:r; 140, identifier:match; 141, argument_list; 141, 142; 142, identifier:normalized_target_path; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:target_path; 146, subscript; 146, 147; 146, 148; 147, identifier:target_path; 148, slice; 148, 149; 148, 153; 149, call; 149, 150; 149, 151; 150, identifier:len; 151, argument_list; 151, 152; 152, identifier:base_path; 153, colon; 154, else_clause; 154, 155; 155, block; 155, 156; 155, 160; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:matching_api_paths; 159, list:[]; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:matching_api_paths_regex; 163, list:[]; 164, if_statement; 164, 165; 164, 170; 164, 189; 164, 201; 164, 230; 164, 244; 164, 327; 165, boolean_operator:and; 165, 166; 165, 168; 166, not_operator; 166, 167; 167, identifier:matching_api_paths; 168, not_operator; 168, 169; 169, identifier:matching_api_paths_regex; 170, block; 170, 171; 170, 184; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:fstr; 174, call; 174, 175; 174, 182; 175, attribute; 175, 176; 175, 181; 176, subscript; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:MESSAGES; 179, string:'path'; 180, string:'no_matching_paths_found'; 181, identifier:format; 182, argument_list; 182, 183; 183, identifier:target_path; 184, raise_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:LookupError; 187, argument_list; 187, 188; 188, identifier:fstr; 189, elif_clause; 189, 190; 189, 196; 190, comparison_operator:==; 190, 191; 190, 195; 191, call; 191, 192; 191, 193; 192, identifier:len; 193, argument_list; 193, 194; 194, identifier:matching_api_paths; 195, integer:1; 196, block; 196, 197; 197, return_statement; 197, 198; 198, subscript; 198, 199; 198, 200; 199, identifier:matching_api_paths; 200, integer:0; 201, elif_clause; 201, 202; 201, 208; 202, comparison_operator:>; 202, 203; 202, 207; 203, call; 203, 204; 203, 205; 204, identifier:len; 205, argument_list; 205, 206; 206, identifier:matching_api_paths; 207, integer:1; 208, block; 208, 209; 209, raise_statement; 209, 210; 210, call; 210, 211; 210, 212; 211, identifier:MultiplePathsFound; 212, argument_list; 212, 213; 213, call; 213, 214; 213, 221; 214, attribute; 214, 215; 214, 220; 215, subscript; 215, 216; 215, 219; 216, subscript; 216, 217; 216, 218; 217, identifier:MESSAGES; 218, string:'path'; 219, string:'multiple_paths_found'; 220, identifier:format; 221, argument_list; 221, 222; 221, 223; 222, identifier:target_path; 223, list_comprehension; 223, 224; 223, 227; 224, subscript; 224, 225; 224, 226; 225, identifier:v; 226, integer:0; 227, for_in_clause; 227, 228; 227, 229; 228, identifier:v; 229, identifier:matching_api_paths; 230, elif_clause; 230, 231; 230, 237; 231, comparison_operator:==; 231, 232; 231, 236; 232, call; 232, 233; 232, 234; 233, identifier:len; 234, argument_list; 234, 235; 235, identifier:matching_api_paths_regex; 236, integer:1; 237, block; 237, 238; 238, return_statement; 238, 239; 239, subscript; 239, 240; 239, 243; 240, subscript; 240, 241; 240, 242; 241, identifier:matching_api_paths_regex; 242, integer:0; 243, integer:0; 244, elif_clause; 244, 245; 244, 251; 245, comparison_operator:>; 245, 246; 245, 250; 246, call; 246, 247; 246, 248; 247, identifier:len; 248, argument_list; 248, 249; 249, identifier:matching_api_paths_regex; 250, integer:1; 251, block; 251, 252; 251, 261; 251, 279; 251, 290; 251, 306; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:matches_by_path_size; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:collections; 258, identifier:defaultdict; 259, argument_list; 259, 260; 260, identifier:list; 261, for_statement; 261, 262; 261, 265; 261, 266; 262, pattern_list; 262, 263; 262, 264; 263, identifier:path; 264, identifier:match; 265, identifier:matching_api_paths_regex; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 277; 269, attribute; 269, 270; 269, 276; 270, subscript; 270, 271; 270, 272; 271, identifier:matches_by_path_size; 272, call; 272, 273; 272, 274; 273, identifier:len; 274, argument_list; 274, 275; 275, identifier:path; 276, identifier:append; 277, argument_list; 277, 278; 278, identifier:path; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:longest_match; 282, call; 282, 283; 282, 284; 283, identifier:max; 284, argument_list; 284, 285; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:matches_by_path_size; 288, identifier:keys; 289, argument_list; 290, if_statement; 290, 291; 290, 299; 291, comparison_operator:==; 291, 292; 291, 298; 292, call; 292, 293; 292, 294; 293, identifier:len; 294, argument_list; 294, 295; 295, subscript; 295, 296; 295, 297; 296, identifier:matches_by_path_size; 297, identifier:longest_match; 298, integer:1; 299, block; 299, 300; 300, return_statement; 300, 301; 301, subscript; 301, 302; 301, 305; 302, subscript; 302, 303; 302, 304; 303, identifier:matches_by_path_size; 304, identifier:longest_match; 305, integer:0; 306, raise_statement; 306, 307; 307, call; 307, 308; 307, 309; 308, identifier:MultiplePathsFound; 309, argument_list; 309, 310; 310, call; 310, 311; 310, 318; 311, attribute; 311, 312; 311, 317; 312, subscript; 312, 313; 312, 316; 313, subscript; 313, 314; 313, 315; 314, identifier:MESSAGES; 315, string:'path'; 316, string:'multiple_paths_found'; 317, identifier:format; 318, argument_list; 318, 319; 318, 320; 319, identifier:target_path; 320, list_comprehension; 320, 321; 320, 324; 321, subscript; 321, 322; 321, 323; 322, identifier:v; 323, integer:0; 324, for_in_clause; 324, 325; 324, 326; 325, identifier:v; 326, identifier:matching_api_paths_regex; 327, else_clause; 327, 328; 328, block; 328, 329; 329, return_statement; 329, 330; 330, subscript; 330, 331; 330, 334; 331, subscript; 331, 332; 331, 333; 332, identifier:matching_api_paths_regex; 333, integer:0; 334, integer:0 | def match_path_to_api_path(path_definitions, target_path, base_path='',
context=None):
if context is None:
context = {}
assert isinstance(context, collections.Mapping)
if target_path.startswith(base_path):
normalized_target_path = re.sub(NORMALIZE_SLASH_REGEX, '/',
target_path)
matching_api_paths = list()
matching_api_paths_regex = list()
for p, v in path_definitions.items():
full_path = re.sub(NORMALIZE_SLASH_REGEX, '/', base_path + p)
r = path_to_regex(
api_path=full_path,
path_parameters=extract_path_parameters(v),
operation_parameters=extract_operation_parameters(v),
context=context,
)
if full_path == normalized_target_path:
matching_api_paths.append(p)
elif r.match(normalized_target_path):
matching_api_paths_regex.\
append((p, r.match(normalized_target_path)))
target_path = target_path[len(base_path):]
else:
matching_api_paths = []
matching_api_paths_regex = []
if not matching_api_paths and not matching_api_paths_regex:
fstr = MESSAGES['path']['no_matching_paths_found'].format(target_path)
raise LookupError(fstr)
elif len(matching_api_paths) == 1:
return matching_api_paths[0]
elif len(matching_api_paths) > 1:
raise MultiplePathsFound(
MESSAGES['path']['multiple_paths_found'].format(
target_path, [v[0] for v in matching_api_paths],
)
)
elif len(matching_api_paths_regex) == 1:
return matching_api_paths_regex[0][0]
elif len(matching_api_paths_regex) > 1:
matches_by_path_size = collections.defaultdict(list)
for path, match in matching_api_paths_regex:
matches_by_path_size[len(path)].append(path)
longest_match = max(matches_by_path_size.keys())
if len(matches_by_path_size[longest_match]) == 1:
return matches_by_path_size[longest_match][0]
raise MultiplePathsFound(
MESSAGES['path']['multiple_paths_found'].format(
target_path, [v[0] for v in matching_api_paths_regex],
)
)
else:
return matching_api_paths_regex[0][0] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_read_frame; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:length; 6, block; 6, 7; 6, 18; 6, 35; 6, 47; 6, 51; 6, 75; 6, 87; 6, 91; 6, 104; 6, 110; 6, 129; 6, 153; 6, 163; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:response; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_read_data; 14, argument_list; 14, 15; 15, binary_operator:+; 15, 16; 15, 17; 16, identifier:length; 17, integer:8; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:logger; 22, identifier:debug; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, string:'Read frame: 0x{0}'; 27, identifier:format; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:binascii; 32, identifier:hexlify; 33, argument_list; 33, 34; 34, identifier:response; 35, if_statement; 35, 36; 35, 41; 36, comparison_operator:!=; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:response; 39, integer:0; 40, integer:0x01; 41, block; 41, 42; 42, raise_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:RuntimeError; 45, argument_list; 45, 46; 46, string:'Response frame does not start with 0x01!'; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:offset; 50, integer:1; 51, while_statement; 51, 52; 51, 57; 52, comparison_operator:==; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:response; 55, identifier:offset; 56, integer:0x00; 57, block; 57, 58; 57, 62; 58, expression_statement; 58, 59; 59, augmented_assignment:+=; 59, 60; 59, 61; 60, identifier:offset; 61, integer:1; 62, if_statement; 62, 63; 62, 69; 63, comparison_operator:>=; 63, 64; 63, 65; 64, identifier:offset; 65, call; 65, 66; 65, 67; 66, identifier:len; 67, argument_list; 67, 68; 68, identifier:response; 69, block; 69, 70; 70, raise_statement; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:RuntimeError; 73, argument_list; 73, 74; 74, string:'Response frame preamble does not contain 0x00FF!'; 75, if_statement; 75, 76; 75, 81; 76, comparison_operator:!=; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:response; 79, identifier:offset; 80, integer:0xFF; 81, block; 81, 82; 82, raise_statement; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:RuntimeError; 85, argument_list; 85, 86; 86, string:'Response frame preamble does not contain 0x00FF!'; 87, expression_statement; 87, 88; 88, augmented_assignment:+=; 88, 89; 88, 90; 89, identifier:offset; 90, integer:1; 91, if_statement; 91, 92; 91, 98; 92, comparison_operator:>=; 92, 93; 92, 94; 93, identifier:offset; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, identifier:response; 98, block; 98, 99; 99, raise_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:RuntimeError; 102, argument_list; 102, 103; 103, string:'Response contains no data!'; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:frame_len; 107, subscript; 107, 108; 107, 109; 108, identifier:response; 109, identifier:offset; 110, if_statement; 110, 111; 110, 123; 111, comparison_operator:!=; 111, 112; 111, 122; 112, binary_operator:&; 112, 113; 112, 121; 113, parenthesized_expression; 113, 114; 114, binary_operator:+; 114, 115; 114, 116; 115, identifier:frame_len; 116, subscript; 116, 117; 116, 118; 117, identifier:response; 118, binary_operator:+; 118, 119; 118, 120; 119, identifier:offset; 120, integer:1; 121, integer:0xFF; 122, integer:0; 123, block; 123, 124; 124, raise_statement; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:RuntimeError; 127, argument_list; 127, 128; 128, string:'Response length checksum did not match length!'; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:checksum; 132, call; 132, 133; 132, 134; 133, identifier:reduce; 134, argument_list; 134, 135; 134, 138; 134, 152; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:_uint8_add; 138, subscript; 138, 139; 138, 140; 139, identifier:response; 140, slice; 140, 141; 140, 144; 140, 145; 141, binary_operator:+; 141, 142; 141, 143; 142, identifier:offset; 143, integer:2; 144, colon; 145, binary_operator:+; 145, 146; 145, 151; 146, binary_operator:+; 146, 147; 146, 150; 147, binary_operator:+; 147, 148; 147, 149; 148, identifier:offset; 149, integer:2; 150, identifier:frame_len; 151, integer:1; 152, integer:0; 153, if_statement; 153, 154; 153, 157; 154, comparison_operator:!=; 154, 155; 154, 156; 155, identifier:checksum; 156, integer:0; 157, block; 157, 158; 158, raise_statement; 158, 159; 159, call; 159, 160; 159, 161; 160, identifier:RuntimeError; 161, argument_list; 161, 162; 162, string:'Response checksum did not match expected value!'; 163, return_statement; 163, 164; 164, subscript; 164, 165; 164, 166; 165, identifier:response; 166, slice; 166, 167; 166, 170; 166, 171; 167, binary_operator:+; 167, 168; 167, 169; 168, identifier:offset; 169, integer:2; 170, colon; 171, binary_operator:+; 171, 172; 171, 175; 172, binary_operator:+; 172, 173; 172, 174; 173, identifier:offset; 174, integer:2; 175, identifier:frame_len | def _read_frame(self, length):
response = self._read_data(length+8)
logger.debug('Read frame: 0x{0}'.format(binascii.hexlify(response)))
if response[0] != 0x01:
raise RuntimeError('Response frame does not start with 0x01!')
offset = 1
while response[offset] == 0x00:
offset += 1
if offset >= len(response):
raise RuntimeError('Response frame preamble does not contain 0x00FF!')
if response[offset] != 0xFF:
raise RuntimeError('Response frame preamble does not contain 0x00FF!')
offset += 1
if offset >= len(response):
raise RuntimeError('Response contains no data!')
frame_len = response[offset]
if (frame_len + response[offset+1]) & 0xFF != 0:
raise RuntimeError('Response length checksum did not match length!')
checksum = reduce(self._uint8_add, response[offset+2:offset+2+frame_len+1], 0)
if checksum != 0:
raise RuntimeError('Response checksum did not match expected value!')
return response[offset+2:offset+2+frame_len] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:call_function; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:command; 6, default_parameter; 6, 7; 6, 8; 7, identifier:response_length; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:params; 11, list:[]; 12, default_parameter; 12, 13; 12, 14; 13, identifier:timeout_sec; 14, integer:1; 15, block; 15, 16; 15, 28; 15, 34; 15, 42; 15, 50; 15, 57; 15, 68; 15, 80; 15, 90; 15, 101; 15, 112; 15, 135; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:data; 19, call; 19, 20; 19, 21; 20, identifier:bytearray; 21, argument_list; 21, 22; 22, binary_operator:+; 22, 23; 22, 24; 23, integer:2; 24, call; 24, 25; 24, 26; 25, identifier:len; 26, argument_list; 26, 27; 27, identifier:params; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:data; 32, integer:0; 33, identifier:PN532_HOSTTOPN532; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, subscript; 36, 37; 36, 38; 37, identifier:data; 38, integer:1; 39, binary_operator:&; 39, 40; 39, 41; 40, identifier:command; 41, integer:0xFF; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 49; 44, subscript; 44, 45; 44, 46; 45, identifier:data; 46, slice; 46, 47; 46, 48; 47, integer:2; 48, colon; 49, identifier:params; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_write_frame; 55, argument_list; 55, 56; 56, identifier:data; 57, if_statement; 57, 58; 57, 65; 58, not_operator; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_wait_ready; 63, argument_list; 63, 64; 64, identifier:timeout_sec; 65, block; 65, 66; 66, return_statement; 66, 67; 67, None; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:response; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:_read_data; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, identifier:PN532_ACK; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:!=; 81, 82; 81, 83; 82, identifier:response; 83, identifier:PN532_ACK; 84, block; 84, 85; 85, raise_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:RuntimeError; 88, argument_list; 88, 89; 89, string:'Did not receive expected ACK from PN532!'; 90, if_statement; 90, 91; 90, 98; 91, not_operator; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:_wait_ready; 96, argument_list; 96, 97; 97, identifier:timeout_sec; 98, block; 98, 99; 99, return_statement; 99, 100; 100, None; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:response; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:_read_frame; 108, argument_list; 108, 109; 109, binary_operator:+; 109, 110; 109, 111; 110, identifier:response_length; 111, integer:2; 112, if_statement; 112, 113; 112, 129; 113, not_operator; 113, 114; 114, parenthesized_expression; 114, 115; 115, boolean_operator:and; 115, 116; 115, 121; 116, comparison_operator:==; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:response; 119, integer:0; 120, identifier:PN532_PN532TOHOST; 121, comparison_operator:==; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:response; 124, integer:1; 125, parenthesized_expression; 125, 126; 126, binary_operator:+; 126, 127; 126, 128; 127, identifier:command; 128, integer:1; 129, block; 129, 130; 130, raise_statement; 130, 131; 131, call; 131, 132; 131, 133; 132, identifier:RuntimeError; 133, argument_list; 133, 134; 134, string:'Received unexpected command response!'; 135, return_statement; 135, 136; 136, subscript; 136, 137; 136, 138; 137, identifier:response; 138, slice; 138, 139; 138, 140; 139, integer:2; 140, colon | def call_function(self, command, response_length=0, params=[], timeout_sec=1):
data = bytearray(2+len(params))
data[0] = PN532_HOSTTOPN532
data[1] = command & 0xFF
data[2:] = params
self._write_frame(data)
if not self._wait_ready(timeout_sec):
return None
response = self._read_data(len(PN532_ACK))
if response != PN532_ACK:
raise RuntimeError('Did not receive expected ACK from PN532!')
if not self._wait_ready(timeout_sec):
return None
response = self._read_frame(response_length+2)
if not (response[0] == PN532_PN532TOHOST and response[1] == (command+1)):
raise RuntimeError('Received unexpected command response!')
return response[2:] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:createGraph; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:createCollections; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:isSmart; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:numberOfShards; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:smartGraphAttribute; 17, None; 18, block; 18, 19; 18, 44; 18, 53; 18, 57; 18, 108; 18, 115; 18, 119; 18, 128; 18, 137; 18, 152; 18, 161; 18, 170; 18, 179; 18, 197; 18, 205; 18, 242; 19, function_definition; 19, 20; 19, 21; 19, 23; 20, function_name:_checkCollectionList; 21, parameters; 21, 22; 22, identifier:lst; 23, block; 23, 24; 24, for_statement; 24, 25; 24, 26; 24, 27; 25, identifier:colName; 26, identifier:lst; 27, block; 27, 28; 28, if_statement; 28, 29; 28, 36; 29, not_operator; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:COL; 33, identifier:isCollection; 34, argument_list; 34, 35; 35, identifier:colName; 36, block; 36, 37; 37, raise_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:ValueError; 40, argument_list; 40, 41; 41, binary_operator:%; 41, 42; 41, 43; 42, string:"'%s' is not a defined Collection"; 43, identifier:colName; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:graphClass; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:GR; 50, identifier:getGraphClass; 51, argument_list; 51, 52; 52, identifier:name; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:ed; 56, list:[]; 57, for_statement; 57, 58; 57, 59; 57, 62; 58, identifier:e; 59, attribute; 59, 60; 59, 61; 60, identifier:graphClass; 61, identifier:_edgeDefinitions; 62, block; 62, 63; 62, 83; 62, 90; 62, 97; 63, if_statement; 63, 64; 63, 73; 64, not_operator; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:COL; 68, identifier:isEdgeCollection; 69, argument_list; 69, 70; 70, attribute; 70, 71; 70, 72; 71, identifier:e; 72, identifier:edgesCollection; 73, block; 73, 74; 74, raise_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:ValueError; 77, argument_list; 77, 78; 78, binary_operator:%; 78, 79; 78, 80; 79, string:"'%s' is not a defined Edge Collection"; 80, attribute; 80, 81; 80, 82; 81, identifier:e; 82, identifier:edgesCollection; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:_checkCollectionList; 86, argument_list; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:e; 89, identifier:fromCollections; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:_checkCollectionList; 93, argument_list; 93, 94; 94, attribute; 94, 95; 94, 96; 95, identifier:e; 96, identifier:toCollections; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:ed; 101, identifier:append; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:e; 106, identifier:toJson; 107, argument_list; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:_checkCollectionList; 111, argument_list; 111, 112; 112, attribute; 112, 113; 112, 114; 113, identifier:graphClass; 114, identifier:_orphanedCollections; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:options; 118, dictionary; 119, if_statement; 119, 120; 119, 121; 120, identifier:numberOfShards; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:options; 126, string:'numberOfShards'; 127, identifier:numberOfShards; 128, if_statement; 128, 129; 128, 130; 129, identifier:smartGraphAttribute; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:options; 135, string:'smartGraphAttribute'; 136, identifier:smartGraphAttribute; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:payload; 140, dictionary; 140, 141; 140, 144; 140, 147; 141, pair; 141, 142; 141, 143; 142, string:"name"; 143, identifier:name; 144, pair; 144, 145; 144, 146; 145, string:"edgeDefinitions"; 146, identifier:ed; 147, pair; 147, 148; 147, 149; 148, string:"orphanCollections"; 149, attribute; 149, 150; 149, 151; 150, identifier:graphClass; 151, identifier:_orphanedCollections; 152, if_statement; 152, 153; 152, 154; 153, identifier:isSmart; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:payload; 159, string:'isSmart'; 160, identifier:isSmart; 161, if_statement; 161, 162; 161, 163; 162, identifier:options; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:payload; 168, string:'options'; 169, identifier:options; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:payload; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:json; 176, identifier:dumps; 177, argument_list; 177, 178; 178, identifier:payload; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:r; 182, call; 182, 183; 182, 190; 183, attribute; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:connection; 188, identifier:session; 189, identifier:post; 190, argument_list; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:graphsURL; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:data; 196, identifier:payload; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:data; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:r; 203, identifier:json; 204, argument_list; 205, if_statement; 205, 206; 205, 217; 205, 232; 206, boolean_operator:or; 206, 207; 206, 212; 207, comparison_operator:==; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:r; 210, identifier:status_code; 211, integer:201; 212, comparison_operator:==; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:r; 215, identifier:status_code; 216, integer:202; 217, block; 217, 218; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 225; 220, subscript; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:graphs; 224, identifier:name; 225, call; 225, 226; 225, 227; 226, identifier:graphClass; 227, argument_list; 227, 228; 227, 229; 228, identifier:self; 229, subscript; 229, 230; 229, 231; 230, identifier:data; 231, string:"graph"; 232, else_clause; 232, 233; 233, block; 233, 234; 234, raise_statement; 234, 235; 235, call; 235, 236; 235, 237; 236, identifier:CreationError; 237, argument_list; 237, 238; 237, 241; 238, subscript; 238, 239; 238, 240; 239, identifier:data; 240, string:"errorMessage"; 241, identifier:data; 242, return_statement; 242, 243; 243, subscript; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:graphs; 247, identifier:name | def createGraph(self, name, createCollections = True, isSmart = False, numberOfShards = None, smartGraphAttribute = None) :
def _checkCollectionList(lst) :
for colName in lst :
if not COL.isCollection(colName) :
raise ValueError("'%s' is not a defined Collection" % colName)
graphClass = GR.getGraphClass(name)
ed = []
for e in graphClass._edgeDefinitions :
if not COL.isEdgeCollection(e.edgesCollection) :
raise ValueError("'%s' is not a defined Edge Collection" % e.edgesCollection)
_checkCollectionList(e.fromCollections)
_checkCollectionList(e.toCollections)
ed.append(e.toJson())
_checkCollectionList(graphClass._orphanedCollections)
options = {}
if numberOfShards:
options['numberOfShards'] = numberOfShards
if smartGraphAttribute:
options['smartGraphAttribute'] = smartGraphAttribute
payload = {
"name": name,
"edgeDefinitions": ed,
"orphanCollections": graphClass._orphanedCollections
}
if isSmart :
payload['isSmart'] = isSmart
if options:
payload['options'] = options
payload = json.dumps(payload)
r = self.connection.session.post(self.graphsURL, data = payload)
data = r.json()
if r.status_code == 201 or r.status_code == 202 :
self.graphs[name] = graphClass(self, data["graph"])
else :
raise CreationError(data["errorMessage"], data)
return self.graphs[name] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:map_v2_event_into_v1; 3, parameters; 3, 4; 4, identifier:event; 5, block; 5, 6; 5, 8; 5, 15; 5, 260; 6, expression_statement; 6, 7; 7, string:'''
Helper method to convert Sensu 2.x event into Sensu 1.x event.
'''; 8, if_statement; 8, 9; 8, 12; 9, comparison_operator:in; 9, 10; 9, 11; 10, string:"v2_event_mapped_into_v1"; 11, identifier:event; 12, block; 12, 13; 13, return_statement; 13, 14; 14, identifier:event; 15, if_statement; 15, 16; 15, 30; 16, boolean_operator:and; 16, 17; 16, 27; 17, not_operator; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:bool; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:event; 24, identifier:get; 25, argument_list; 25, 26; 26, string:'client'; 27, comparison_operator:in; 27, 28; 27, 29; 28, string:"entity"; 29, identifier:event; 30, block; 30, 31; 30, 39; 30, 58; 30, 77; 30, 96; 30, 115; 30, 128; 30, 149; 30, 182; 30, 254; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:event; 35, string:'client'; 36, subscript; 36, 37; 36, 38; 37, identifier:event; 38, string:'entity'; 39, if_statement; 39, 40; 39, 45; 40, comparison_operator:not; 40, 41; 40, 42; 41, string:"name"; 42, subscript; 42, 43; 42, 44; 43, identifier:event; 44, string:'client'; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:event; 51, string:'client'; 52, string:'name'; 53, subscript; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:event; 56, string:'entity'; 57, string:'id'; 58, if_statement; 58, 59; 58, 64; 59, comparison_operator:not; 59, 60; 59, 61; 60, string:"subscribers"; 61, subscript; 61, 62; 61, 63; 62, identifier:event; 63, string:'client'; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:event; 70, string:'client'; 71, string:'subscribers'; 72, subscript; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:event; 75, string:'entity'; 76, string:'subscriptions'; 77, if_statement; 77, 78; 77, 83; 78, comparison_operator:not; 78, 79; 78, 80; 79, string:"subscribers"; 80, subscript; 80, 81; 80, 82; 81, identifier:event; 82, string:'check'; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:event; 89, string:'check'; 90, string:'subscribers'; 91, subscript; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:event; 94, string:'check'; 95, string:'subscriptions'; 96, if_statement; 96, 97; 96, 102; 97, comparison_operator:not; 97, 98; 97, 99; 98, string:"source"; 99, subscript; 99, 100; 99, 101; 100, identifier:event; 101, string:'check'; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 110; 105, subscript; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:event; 108, string:'check'; 109, string:'source'; 110, subscript; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:event; 113, string:'check'; 114, string:'proxy_entity_id'; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:action_state_mapping; 118, dictionary; 118, 119; 118, 122; 118, 125; 119, pair; 119, 120; 119, 121; 120, string:'flapping'; 121, string:'flapping'; 122, pair; 122, 123; 122, 124; 123, string:'passing'; 124, string:'resolve'; 125, pair; 125, 126; 125, 127; 126, string:'failing'; 127, string:'create'; 128, if_statement; 128, 129; 128, 134; 128, 143; 129, comparison_operator:in; 129, 130; 129, 131; 130, string:"state"; 131, subscript; 131, 132; 131, 133; 132, identifier:event; 133, string:'check'; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:state; 138, subscript; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:event; 141, string:'check'; 142, string:'state'; 143, else_clause; 143, 144; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:state; 148, string:"unknown::2.0_event"; 149, if_statement; 149, 150; 149, 161; 149, 174; 150, boolean_operator:and; 150, 151; 150, 154; 151, comparison_operator:not; 151, 152; 151, 153; 152, string:"action"; 153, identifier:event; 154, comparison_operator:in; 154, 155; 154, 160; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:state; 158, identifier:lower; 159, argument_list; 160, identifier:action_state_mapping; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:event; 166, string:'action'; 167, subscript; 167, 168; 167, 169; 168, identifier:action_state_mapping; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:state; 172, identifier:lower; 173, argument_list; 174, else_clause; 174, 175; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, subscript; 178, 179; 178, 180; 179, identifier:event; 180, string:'action'; 181, identifier:state; 182, if_statement; 182, 183; 182, 188; 183, comparison_operator:in; 183, 184; 183, 185; 184, string:"history"; 185, subscript; 185, 186; 185, 187; 186, identifier:event; 187, string:'check'; 188, block; 188, 189; 188, 204; 188, 208; 188, 246; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 196; 191, subscript; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:event; 194, string:'check'; 195, string:'history_v2'; 196, call; 196, 197; 196, 198; 197, identifier:deepcopy; 198, argument_list; 198, 199; 199, subscript; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:event; 202, string:'check'; 203, string:'history'; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:legacy_history; 207, list:[]; 208, for_statement; 208, 209; 208, 210; 208, 215; 209, identifier:history; 210, subscript; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:event; 213, string:'check'; 214, string:'history'; 215, block; 215, 216; 216, if_statement; 216, 217; 216, 224; 216, 237; 217, call; 217, 218; 217, 219; 218, identifier:isinstance; 219, argument_list; 219, 220; 219, 223; 220, subscript; 220, 221; 220, 222; 221, identifier:history; 222, string:'status'; 223, identifier:int; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:legacy_history; 229, identifier:append; 230, argument_list; 230, 231; 231, call; 231, 232; 231, 233; 232, identifier:str; 233, argument_list; 233, 234; 234, subscript; 234, 235; 234, 236; 235, identifier:history; 236, string:'status'; 237, else_clause; 237, 238; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:legacy_history; 243, identifier:append; 244, argument_list; 244, 245; 245, string:"3"; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 253; 248, subscript; 248, 249; 248, 252; 249, subscript; 249, 250; 249, 251; 250, identifier:event; 251, string:'check'; 252, string:'history'; 253, identifier:legacy_history; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 259; 256, subscript; 256, 257; 256, 258; 257, identifier:event; 258, string:'v2_event_mapped_into_v1'; 259, True; 260, return_statement; 260, 261; 261, identifier:event | def map_v2_event_into_v1(event):
'''
Helper method to convert Sensu 2.x event into Sensu 1.x event.
'''
if "v2_event_mapped_into_v1" in event:
return event
if not bool(event.get('client')) and "entity" in event:
event['client'] = event['entity']
if "name" not in event['client']:
event['client']['name'] = event['entity']['id']
if "subscribers" not in event['client']:
event['client']['subscribers'] = event['entity']['subscriptions']
if "subscribers" not in event['check']:
event['check']['subscribers'] = event['check']['subscriptions']
if "source" not in event['check']:
event['check']['source'] = event['check']['proxy_entity_id']
action_state_mapping = {'flapping': 'flapping', 'passing': 'resolve',
'failing': 'create'}
if "state" in event['check']:
state = event['check']['state']
else:
state = "unknown::2.0_event"
if "action" not in event and state.lower() in action_state_mapping:
event['action'] = action_state_mapping[state.lower()]
else:
event['action'] = state
if "history" in event['check']:
event['check']['history_v2'] = deepcopy(event['check']['history'])
legacy_history = []
for history in event['check']['history']:
if isinstance(history['status'], int):
legacy_history.append(str(history['status']))
else:
legacy_history.append("3")
event['check']['history'] = legacy_history
event['v2_event_mapped_into_v1'] = True
return event |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 1, 14; 2, function_name:gen_df_site; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:list_csv_in; 6, identifier:list_table; 7, default_parameter; 7, 8; 7, 9; 8, identifier:url_base; 9, identifier:url_repo_input_site; 10, type; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:pd; 13, identifier:DataFrame; 14, block; 14, 15; 14, 17; 14, 27; 15, expression_statement; 15, 16; 16, string:'''Generate description info of supy output results as a dataframe
Parameters
----------
path_csv_out : str, optional
path to the output csv file (the default is 'df_output.csv')
list_csv_in : list, optional
list of file names for csv files with meta info (the default is url_repo_input_site, which is defined at the top of this file)
url_base : URL, optional
URL to the input dir of repo base (the default is url_repo_input, which is defined at the top of this file)
Returns
-------
pd.DataFrame
full path to the output csv file
'''; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:list_url_table; 20, list_comprehension; 20, 21; 20, 24; 21, binary_operator:/; 21, 22; 21, 23; 22, identifier:url_base; 23, identifier:table; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:table; 26, identifier:list_csv_in; 27, try_statement; 27, 28; 27, 47; 27, 68; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:df_var_info; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:pd; 35, identifier:concat; 36, argument_list; 36, 37; 37, list_comprehension; 37, 38; 37, 44; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:pd; 41, identifier:read_csv; 42, argument_list; 42, 43; 43, identifier:f; 44, for_in_clause; 44, 45; 44, 46; 45, identifier:f; 46, identifier:list_url_table; 47, except_clause; 47, 48; 48, block; 48, 49; 49, for_statement; 49, 50; 49, 51; 49, 52; 50, identifier:url; 51, identifier:list_url_table; 52, block; 52, 53; 53, if_statement; 53, 54; 53, 62; 54, not_operator; 54, 55; 55, attribute; 55, 56; 55, 61; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:url; 59, identifier:get; 60, argument_list; 61, identifier:ok; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:print; 66, argument_list; 66, 67; 67, string:f'{url} not existing!'; 68, else_clause; 68, 69; 69, block; 69, 70; 69, 91; 69, 113; 69, 128; 69, 142; 69, 181; 69, 212; 69, 238; 69, 245; 69, 263; 69, 281; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:df_var_info_x; 73, call; 73, 74; 73, 89; 74, attribute; 74, 75; 74, 87; 74, 88; 75, call; 75, 76; 75, 80; 76, attribute; 76, 77; 76, 78; 76, 79; 77, identifier:df_var_info; 78, line_continuation:\; 79, identifier:drop; 80, argument_list; 80, 81; 80, 84; 81, list:['No.', 'Use']; 81, 82; 81, 83; 82, string:'No.'; 83, string:'Use'; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:axis; 86, integer:1; 87, line_continuation:\; 88, identifier:set_index; 89, argument_list; 89, 90; 90, string:'Column Name'; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:df_var_info_x; 95, identifier:index; 96, call; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:df_var_info_x; 100, identifier:index; 101, identifier:map; 102, argument_list; 102, 103; 103, lambda; 103, 104; 103, 106; 104, lambda_parameters; 104, 105; 105, identifier:x; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:x; 109, identifier:replace; 110, argument_list; 110, 111; 110, 112; 111, string:'`'; 112, string:''; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:dict_var_full; 116, call; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:sp; 120, identifier:supy_load; 121, identifier:exp_dict_full; 122, argument_list; 122, 123; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:sp; 126, identifier:supy_load; 127, identifier:dict_var2SiteSelect; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:dict_var_ref_suews; 131, dictionary_comprehension; 131, 132; 131, 139; 132, pair; 132, 133; 132, 134; 133, identifier:k; 134, call; 134, 135; 134, 136; 135, identifier:extract_var_suews; 136, argument_list; 136, 137; 136, 138; 137, identifier:dict_var_full; 138, identifier:k; 139, for_in_clause; 139, 140; 139, 141; 140, identifier:k; 141, identifier:dict_var_full; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:df_var_ref_suews; 145, call; 145, 146; 145, 173; 146, attribute; 146, 147; 146, 172; 147, attribute; 147, 148; 147, 171; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:pd; 151, identifier:DataFrame; 152, argument_list; 152, 153; 152, 167; 153, dictionary_comprehension; 153, 154; 153, 164; 154, pair; 154, 155; 154, 156; 155, identifier:k; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, string:', '; 159, identifier:join; 160, argument_list; 160, 161; 161, subscript; 161, 162; 161, 163; 162, identifier:dict_var_ref_suews; 163, identifier:k; 164, for_in_clause; 164, 165; 164, 166; 165, identifier:k; 166, identifier:dict_var_ref_suews; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:index; 169, list:[0]; 169, 170; 170, integer:0; 171, identifier:T; 172, identifier:rename; 173, argument_list; 173, 174; 173, 178; 174, dictionary; 174, 175; 175, pair; 175, 176; 175, 177; 176, integer:0; 177, string:'SUEWS-related variables'; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:axis; 180, integer:1; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:dict_var_desc; 184, dictionary_comprehension; 184, 185; 184, 203; 185, pair; 185, 186; 185, 187; 186, identifier:k; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, string:'\n'; 190, identifier:join; 191, argument_list; 191, 192; 192, call; 192, 193; 192, 202; 193, attribute; 193, 194; 193, 201; 194, attribute; 194, 195; 194, 200; 195, subscript; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:df_var_info_x; 198, identifier:loc; 199, identifier:v; 200, identifier:values; 201, identifier:flatten; 202, argument_list; 203, for_in_clause; 203, 204; 203, 207; 204, pattern_list; 204, 205; 204, 206; 205, identifier:k; 206, identifier:v; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:dict_var_ref_suews; 210, identifier:items; 211, argument_list; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:df_var_desc; 215, call; 215, 216; 215, 231; 216, attribute; 216, 217; 216, 229; 216, 230; 217, attribute; 217, 218; 217, 228; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:pd; 221, identifier:DataFrame; 222, argument_list; 222, 223; 222, 224; 223, identifier:dict_var_desc; 224, keyword_argument; 224, 225; 224, 226; 225, identifier:index; 226, list:[0]; 226, 227; 227, integer:0; 228, identifier:T; 229, line_continuation:\; 230, identifier:rename; 231, argument_list; 231, 232; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:columns; 234, dictionary; 234, 235; 235, pair; 235, 236; 235, 237; 236, integer:0; 237, string:'Description'; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:df_var_dim; 241, call; 241, 242; 241, 243; 242, identifier:gen_df_dim; 243, argument_list; 243, 244; 244, identifier:df_init_sample; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:df_var_site_raw; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:pd; 251, identifier:concat; 252, argument_list; 252, 253; 252, 257; 252, 260; 253, list:[df_var_dim, df_var_desc, df_var_ref_suews]; 253, 254; 253, 255; 253, 256; 254, identifier:df_var_dim; 255, identifier:df_var_desc; 256, identifier:df_var_ref_suews; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:axis; 259, integer:1; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:sort; 262, False; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:df_var_site; 266, call; 266, 267; 266, 280; 267, attribute; 267, 268; 267, 279; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:df_var_site_raw; 271, identifier:filter; 272, argument_list; 272, 273; 272, 276; 273, keyword_argument; 273, 274; 273, 275; 274, identifier:items; 275, identifier:set_input; 276, keyword_argument; 276, 277; 276, 278; 277, identifier:axis; 278, integer:0; 279, identifier:dropna; 280, argument_list; 281, return_statement; 281, 282; 282, identifier:df_var_site | def gen_df_site(
list_csv_in=list_table,
url_base=url_repo_input_site)->pd.DataFrame:
'''Generate description info of supy output results as a dataframe
Parameters
----------
path_csv_out : str, optional
path to the output csv file (the default is 'df_output.csv')
list_csv_in : list, optional
list of file names for csv files with meta info (the default is url_repo_input_site, which is defined at the top of this file)
url_base : URL, optional
URL to the input dir of repo base (the default is url_repo_input, which is defined at the top of this file)
Returns
-------
pd.DataFrame
full path to the output csv file
'''
list_url_table = [
url_base/table for table in list_csv_in
]
try:
df_var_info = pd.concat([pd.read_csv(f) for f in list_url_table])
except:
for url in list_url_table:
if not url.get().ok:
print(f'{url} not existing!')
else:
df_var_info_x = df_var_info\
.drop(['No.', 'Use'], axis=1)\
.set_index('Column Name')
df_var_info_x.index = df_var_info_x.index.map(
lambda x: x.replace('`', ''))
dict_var_full = sp.supy_load.exp_dict_full(
sp.supy_load.dict_var2SiteSelect)
dict_var_ref_suews = {
k: extract_var_suews(dict_var_full, k)
for k in dict_var_full
}
df_var_ref_suews = pd.DataFrame(
{k: ', '.join(dict_var_ref_suews[k])
for k in dict_var_ref_suews},
index=[0]).T.rename({
0: 'SUEWS-related variables'
}, axis=1)
dict_var_desc = {
k: '\n'.join(df_var_info_x.loc[v].values.flatten())
for k, v in dict_var_ref_suews.items()
}
df_var_desc = pd.DataFrame(dict_var_desc, index=[0]).T\
.rename(columns={0: 'Description'})
df_var_dim = gen_df_dim(df_init_sample)
df_var_site_raw = pd.concat(
[df_var_dim, df_var_desc, df_var_ref_suews],
axis=1, sort=False)
df_var_site = df_var_site_raw.filter(items=set_input, axis=0).dropna()
return df_var_site |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:wait_for_tasks_to_complete; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:batch_service_client; 5, identifier:job_ids; 6, identifier:timeout; 7, block; 7, 8; 7, 20; 7, 33; 7, 118; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:timeout_expiration; 11, binary_operator:+; 11, 12; 11, 19; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:datetime; 16, identifier:datetime; 17, identifier:now; 18, argument_list; 19, identifier:timeout; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:print; 23, argument_list; 23, 24; 23, 30; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, string:"Monitoring all tasks for 'Completed' state, timeout in {}..."; 27, identifier:format; 28, argument_list; 28, 29; 29, identifier:timeout; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:end; 32, string:''; 33, while_statement; 33, 34; 33, 43; 34, comparison_operator:<; 34, 35; 34, 42; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:datetime; 39, identifier:datetime; 40, identifier:now; 41, argument_list; 42, identifier:timeout_expiration; 43, block; 43, 44; 43, 52; 43, 60; 43, 99; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:print; 47, argument_list; 47, 48; 47, 49; 48, string:'.'; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:end; 51, string:''; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:sys; 57, identifier:stdout; 58, identifier:flush; 59, argument_list; 60, for_statement; 60, 61; 60, 64; 60, 65; 61, tuple_pattern; 61, 62; 61, 63; 62, identifier:job_id; 63, identifier:_; 64, identifier:job_ids; 65, block; 65, 66; 65, 77; 65, 95; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:tasks; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:batch_service_client; 73, identifier:task; 74, identifier:list; 75, argument_list; 75, 76; 76, identifier:job_id; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:incomplete_tasks; 80, list_comprehension; 80, 81; 80, 82; 80, 85; 81, identifier:task; 82, for_in_clause; 82, 83; 82, 84; 83, identifier:task; 84, identifier:tasks; 85, if_clause; 85, 86; 86, comparison_operator:!=; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:task; 89, identifier:state; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:batchmodels; 93, identifier:TaskState; 94, identifier:completed; 95, if_statement; 95, 96; 95, 97; 96, identifier:incomplete_tasks; 97, block; 97, 98; 98, break_statement; 99, if_statement; 99, 100; 99, 102; 99, 109; 100, not_operator; 100, 101; 101, identifier:incomplete_tasks; 102, block; 102, 103; 102, 107; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:print; 106, argument_list; 107, return_statement; 107, 108; 108, True; 109, else_clause; 109, 110; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:time; 115, identifier:sleep; 116, argument_list; 116, 117; 117, integer:1; 118, raise_statement; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:RuntimeError; 121, argument_list; 121, 122; 122, binary_operator:+; 122, 123; 122, 126; 123, concatenated_string; 123, 124; 123, 125; 124, string:"ERROR: Tasks did not reach 'Completed' state within "; 125, string:"timeout period of "; 126, call; 126, 127; 126, 128; 127, identifier:str; 128, argument_list; 128, 129; 129, identifier:timeout | def wait_for_tasks_to_complete(batch_service_client, job_ids, timeout):
timeout_expiration = datetime.datetime.now() + timeout
print("Monitoring all tasks for 'Completed' state, timeout in {}...".format(timeout), end='')
while datetime.datetime.now() < timeout_expiration:
print('.', end='')
sys.stdout.flush()
for (job_id, _) in job_ids:
tasks = batch_service_client.task.list(job_id)
incomplete_tasks = [task for task in tasks if
task.state != batchmodels.TaskState.completed]
if incomplete_tasks:
break
if not incomplete_tasks:
print()
return True
else:
time.sleep(1)
raise RuntimeError("ERROR: Tasks did not reach 'Completed' state within "
"timeout period of " + str(timeout)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 52; 2, function_name:plot_world_with_elegans; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 39; 3, 46; 3, 49; 4, identifier:world; 5, default_parameter; 5, 6; 5, 7; 6, identifier:radius; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:width; 10, integer:350; 11, default_parameter; 11, 12; 11, 13; 12, identifier:height; 13, integer:350; 14, default_parameter; 14, 15; 14, 16; 15, identifier:config; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:grid; 19, True; 20, default_parameter; 20, 21; 20, 22; 21, identifier:wireframe; 22, False; 23, default_parameter; 23, 24; 23, 25; 24, identifier:species_list; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:debug; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:max_count; 31, integer:1000; 32, default_parameter; 32, 33; 32, 34; 33, identifier:camera_position; 34, tuple; 34, 35; 34, 37; 34, 38; 35, unary_operator:-; 35, 36; 36, integer:22; 37, integer:23; 38, integer:32; 39, default_parameter; 39, 40; 39, 41; 40, identifier:camera_rotation; 41, tuple; 41, 42; 41, 44; 41, 45; 42, unary_operator:-; 42, 43; 43, float:0.6; 44, float:0.5; 45, float:0.6; 46, default_parameter; 46, 47; 46, 48; 47, identifier:return_id; 48, False; 49, default_parameter; 49, 50; 49, 51; 50, identifier:predicator; 51, None; 52, block; 52, 53; 52, 59; 52, 68; 52, 75; 52, 89; 52, 100; 52, 109; 52, 113; 52, 155; 52, 218; 52, 249; 52, 260; 52, 275; 52, 328; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:config; 56, boolean_operator:or; 56, 57; 56, 58; 57, identifier:config; 58, dictionary; 59, import_from_statement; 59, 60; 59, 64; 59, 66; 60, dotted_name; 60, 61; 60, 62; 60, 63; 61, identifier:IPython; 62, identifier:core; 63, identifier:display; 64, dotted_name; 64, 65; 65, identifier:display; 66, dotted_name; 66, 67; 67, identifier:HTML; 68, import_from_statement; 68, 69; 68, 73; 69, relative_import; 69, 70; 69, 71; 70, import_prefix; 71, dotted_name; 71, 72; 72, identifier:simulation; 73, dotted_name; 73, 74; 74, identifier:load_world; 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:world; 80, identifier:str; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:world; 85, call; 85, 86; 85, 87; 86, identifier:load_world; 87, argument_list; 87, 88; 88, identifier:world; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:species; 92, call; 92, 93; 92, 94; 93, identifier:__parse_world; 94, argument_list; 94, 95; 94, 96; 94, 97; 94, 98; 94, 99; 95, identifier:world; 96, identifier:radius; 97, identifier:species_list; 98, identifier:max_count; 99, identifier:predicator; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:color_scale; 103, call; 103, 104; 103, 105; 104, identifier:default_color_scale; 105, argument_list; 105, 106; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:config; 108, identifier:config; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:plots; 112, list:[]; 113, for_statement; 113, 114; 113, 115; 113, 116; 114, identifier:species_info; 115, identifier:species; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:plots; 121, identifier:append; 122, argument_list; 122, 123; 123, dictionary; 123, 124; 123, 127; 123, 132; 124, pair; 124, 125; 124, 126; 125, string:'type'; 126, string:'Particles'; 127, pair; 127, 128; 127, 129; 128, string:'data'; 129, subscript; 129, 130; 129, 131; 130, identifier:species_info; 131, string:'data'; 132, pair; 132, 133; 132, 134; 133, string:'options'; 134, dictionary; 134, 135; 134, 140; 134, 150; 135, pair; 135, 136; 135, 137; 136, string:'name'; 137, subscript; 137, 138; 137, 139; 138, identifier:species_info; 139, string:'name'; 140, pair; 140, 141; 140, 142; 141, string:'color'; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:color_scale; 145, identifier:get_color; 146, argument_list; 146, 147; 147, subscript; 147, 148; 147, 149; 148, identifier:species_info; 149, string:'name'; 150, pair; 150, 151; 150, 152; 151, string:'size'; 152, subscript; 152, 153; 152, 154; 153, identifier:species_info; 154, string:'size'; 155, if_statement; 155, 156; 155, 159; 156, comparison_operator:is; 156, 157; 156, 158; 157, identifier:debug; 158, None; 159, block; 159, 160; 159, 179; 159, 202; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:data; 163, dictionary; 163, 164; 163, 167; 163, 170; 163, 173; 163, 176; 164, pair; 164, 165; 164, 166; 165, string:'type'; 166, list:[]; 167, pair; 167, 168; 167, 169; 168, string:'x'; 169, list:[]; 170, pair; 170, 171; 170, 172; 171, string:'y'; 172, list:[]; 173, pair; 173, 174; 173, 175; 174, string:'z'; 175, list:[]; 176, pair; 176, 177; 176, 178; 177, string:'options'; 178, list:[]; 179, for_statement; 179, 180; 179, 181; 179, 182; 180, identifier:obj; 181, identifier:debug; 182, block; 182, 183; 183, for_statement; 183, 184; 183, 187; 183, 192; 184, pattern_list; 184, 185; 184, 186; 185, identifier:k; 186, identifier:v; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:obj; 190, identifier:items; 191, argument_list; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, subscript; 196, 197; 196, 198; 197, identifier:data; 198, identifier:k; 199, identifier:append; 200, argument_list; 200, 201; 201, identifier:v; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:plots; 206, identifier:append; 207, argument_list; 207, 208; 208, dictionary; 208, 209; 208, 212; 208, 215; 209, pair; 209, 210; 209, 211; 210, string:'type'; 211, string:'DebugObject'; 212, pair; 212, 213; 212, 214; 213, string:'data'; 214, identifier:data; 215, pair; 215, 216; 215, 217; 216, string:'options'; 217, dictionary; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:model; 221, dictionary; 221, 222; 221, 225; 222, pair; 222, 223; 222, 224; 223, string:'plots'; 224, identifier:plots; 225, pair; 225, 226; 225, 227; 226, string:'options'; 227, dictionary; 227, 228; 227, 231; 227, 234; 227, 240; 227, 243; 227, 246; 228, pair; 228, 229; 228, 230; 229, string:'world_width'; 230, identifier:width; 231, pair; 231, 232; 231, 233; 232, string:'world_height'; 233, identifier:height; 234, pair; 234, 235; 234, 236; 235, string:'range'; 236, call; 236, 237; 236, 238; 237, identifier:__get_range_of_world; 238, argument_list; 238, 239; 239, identifier:world; 240, pair; 240, 241; 240, 242; 241, string:'autorange'; 242, False; 243, pair; 243, 244; 243, 245; 244, string:'grid'; 245, identifier:grid; 246, pair; 246, 247; 246, 248; 247, string:'save_image'; 248, True; 249, if_statement; 249, 250; 249, 251; 250, identifier:wireframe; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 259; 254, subscript; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:model; 257, string:'options'; 258, string:'space_mode'; 259, string:'wireframe'; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:model_id; 263, binary_operator:+; 263, 264; 263, 274; 264, binary_operator:+; 264, 265; 264, 266; 265, string:'"viz'; 266, call; 266, 267; 266, 268; 267, identifier:str; 268, argument_list; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:uuid; 272, identifier:uuid4; 273, argument_list; 274, string:'"'; 275, expression_statement; 275, 276; 276, call; 276, 277; 276, 278; 277, identifier:display; 278, argument_list; 278, 279; 279, call; 279, 280; 279, 281; 280, identifier:HTML; 281, argument_list; 281, 282; 282, call; 282, 283; 282, 284; 283, identifier:generate_html; 284, argument_list; 284, 285; 284, 327; 285, dictionary; 285, 286; 285, 294; 285, 297; 285, 302; 285, 307; 285, 312; 285, 317; 285, 322; 286, pair; 286, 287; 286, 288; 287, string:'model'; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:json; 291, identifier:dumps; 292, argument_list; 292, 293; 293, identifier:model; 294, pair; 294, 295; 294, 296; 295, string:'model_id'; 296, identifier:model_id; 297, pair; 297, 298; 297, 299; 298, string:'px'; 299, subscript; 299, 300; 299, 301; 300, identifier:camera_position; 301, integer:0; 302, pair; 302, 303; 302, 304; 303, string:'py'; 304, subscript; 304, 305; 304, 306; 305, identifier:camera_position; 306, integer:1; 307, pair; 307, 308; 307, 309; 308, string:'pz'; 309, subscript; 309, 310; 309, 311; 310, identifier:camera_position; 311, integer:2; 312, pair; 312, 313; 312, 314; 313, string:'rx'; 314, subscript; 314, 315; 314, 316; 315, identifier:camera_rotation; 316, integer:0; 317, pair; 317, 318; 317, 319; 318, string:'ry'; 319, subscript; 319, 320; 319, 321; 320, identifier:camera_rotation; 321, integer:1; 322, pair; 322, 323; 322, 324; 323, string:'rz'; 324, subscript; 324, 325; 324, 326; 325, identifier:camera_rotation; 326, integer:2; 327, string:'templates/particles.tmpl'; 328, if_statement; 328, 329; 328, 330; 329, identifier:return_id; 330, block; 330, 331; 331, return_statement; 331, 332; 332, identifier:model_id | def plot_world_with_elegans(
world, radius=None, width=350, height=350, config=None, grid=True,
wireframe=False, species_list=None, debug=None, max_count=1000,
camera_position=(-22, 23, 32), camera_rotation=(-0.6, 0.5, 0.6),
return_id=False, predicator=None):
config = config or {}
from IPython.core.display import display, HTML
from .simulation import load_world
if isinstance(world, str):
world = load_world(world)
species = __parse_world(world, radius, species_list, max_count, predicator)
color_scale = default_color_scale(config=config)
plots = []
for species_info in species:
plots.append({
'type': 'Particles',
'data': species_info['data'],
'options': {
'name': species_info['name'],
'color': color_scale.get_color(species_info['name']),
'size': species_info['size']
}
})
if debug is not None:
data = {'type': [], 'x': [], 'y': [], 'z': [], 'options': []}
for obj in debug:
for k, v in obj.items():
data[k].append(v)
plots.append({
'type': 'DebugObject',
'data': data,
'options': {}
})
model = {
'plots': plots,
'options': {
'world_width': width,
'world_height': height,
'range': __get_range_of_world(world),
'autorange': False,
'grid': grid,
'save_image': True
}
}
if wireframe:
model['options']['space_mode'] = 'wireframe'
model_id = '"viz' + str(uuid.uuid4()) + '"'
display(HTML(generate_html(
{'model': json.dumps(model), 'model_id': model_id,
'px': camera_position[0], 'py': camera_position[1], 'pz': camera_position[2],
'rx': camera_rotation[0], 'ry': camera_rotation[1], 'rz': camera_rotation[2]},
'templates/particles.tmpl')))
if return_id:
return model_id |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 31; 2, function_name:plot_trajectory2d_with_matplotlib; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:obs; 5, default_parameter; 5, 6; 5, 7; 6, identifier:plane; 7, string:'xy'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:max_count; 10, integer:10; 11, default_parameter; 11, 12; 11, 13; 12, identifier:figsize; 13, integer:6; 14, default_parameter; 14, 15; 14, 16; 15, identifier:legend; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:wireframe; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:grid; 22, True; 23, default_parameter; 23, 24; 23, 25; 24, identifier:noaxis; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:plot_range; 28, None; 29, dictionary_splat_pattern; 29, 30; 30, identifier:kwargs; 31, block; 31, 32; 31, 38; 31, 46; 31, 85; 31, 104; 31, 123; 31, 131; 31, 153; 31, 161; 31, 174; 31, 188; 31, 201; 31, 214; 31, 227; 31, 231; 31, 281; 31, 289; 31, 330; 32, import_statement; 32, 33; 33, aliased_import; 33, 34; 33, 37; 34, dotted_name; 34, 35; 34, 36; 35, identifier:matplotlib; 36, identifier:pyplot; 37, identifier:plt; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:plane; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:plane; 44, identifier:lower; 45, argument_list; 46, if_statement; 46, 47; 46, 71; 47, boolean_operator:or; 47, 48; 47, 63; 48, boolean_operator:or; 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:plane; 54, integer:2; 55, comparison_operator:not; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:plane; 58, integer:0; 59, tuple; 59, 60; 59, 61; 59, 62; 60, string:'x'; 61, string:'y'; 62, string:'z'; 63, comparison_operator:not; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:plane; 66, integer:1; 67, tuple; 67, 68; 67, 69; 67, 70; 68, string:'x'; 69, string:'y'; 70, string:'z'; 71, block; 71, 72; 72, raise_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:ValueError; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, string:"invalid 'plane' argument [{}] was given."; 79, identifier:format; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:repr; 83, argument_list; 83, 84; 84, identifier:plane; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:xidx; 88, conditional_expression:if; 88, 89; 88, 90; 88, 95; 89, integer:0; 90, comparison_operator:==; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:plane; 93, integer:0; 94, string:'x'; 95, parenthesized_expression; 95, 96; 96, conditional_expression:if; 96, 97; 96, 98; 96, 103; 97, integer:1; 98, comparison_operator:==; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:plane; 101, integer:0; 102, string:'y'; 103, integer:2; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:yidx; 107, conditional_expression:if; 107, 108; 107, 109; 107, 114; 108, integer:0; 109, comparison_operator:==; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:plane; 112, integer:1; 113, string:'x'; 114, parenthesized_expression; 114, 115; 115, conditional_expression:if; 115, 116; 115, 117; 115, 122; 116, integer:1; 117, comparison_operator:==; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:plane; 120, integer:1; 121, string:'y'; 122, integer:2; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:data; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:obs; 129, identifier:data; 130, argument_list; 131, if_statement; 131, 132; 131, 142; 132, boolean_operator:and; 132, 133; 132, 136; 133, comparison_operator:is; 133, 134; 133, 135; 134, identifier:max_count; 135, None; 136, comparison_operator:>; 136, 137; 136, 141; 137, call; 137, 138; 137, 139; 138, identifier:len; 139, argument_list; 139, 140; 140, identifier:data; 141, identifier:max_count; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:data; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:random; 149, identifier:sample; 150, argument_list; 150, 151; 150, 152; 151, identifier:data; 152, identifier:max_count; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:wrange; 156, call; 156, 157; 156, 158; 157, identifier:__get_range_of_trajectories; 158, argument_list; 158, 159; 158, 160; 159, identifier:data; 160, identifier:plot_range; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:wrange; 164, tuple; 164, 165; 164, 168; 164, 171; 165, subscript; 165, 166; 165, 167; 166, identifier:wrange; 167, string:'x'; 168, subscript; 168, 169; 168, 170; 169, identifier:wrange; 170, string:'y'; 171, subscript; 171, 172; 171, 173; 172, identifier:wrange; 173, string:'z'; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:wrange; 177, dictionary; 177, 178; 177, 183; 178, pair; 178, 179; 178, 180; 179, string:'x'; 180, subscript; 180, 181; 180, 182; 181, identifier:wrange; 182, identifier:xidx; 183, pair; 183, 184; 183, 185; 184, string:'y'; 185, subscript; 185, 186; 185, 187; 186, identifier:wrange; 187, identifier:yidx; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, pattern_list; 190, 191; 190, 192; 191, identifier:fig; 192, identifier:ax; 193, call; 193, 194; 193, 195; 194, identifier:__prepare_plot_with_matplotlib; 195, argument_list; 195, 196; 195, 197; 195, 198; 195, 199; 195, 200; 196, identifier:wrange; 197, identifier:figsize; 198, identifier:grid; 199, identifier:wireframe; 200, identifier:noaxis; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:ax; 205, identifier:set_xlabel; 206, argument_list; 206, 207; 207, call; 207, 208; 207, 213; 208, attribute; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:plane; 211, integer:0; 212, identifier:upper; 213, argument_list; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:ax; 218, identifier:set_ylabel; 219, argument_list; 219, 220; 220, call; 220, 221; 220, 226; 221, attribute; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:plane; 224, integer:1; 225, identifier:upper; 226, argument_list; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:lines; 230, list:[]; 231, for_statement; 231, 232; 231, 235; 231, 239; 232, pattern_list; 232, 233; 232, 234; 233, identifier:i; 234, identifier:y; 235, call; 235, 236; 235, 237; 236, identifier:enumerate; 237, argument_list; 237, 238; 238, identifier:data; 239, block; 239, 240; 239, 250; 239, 272; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 246; 242, pattern_list; 242, 243; 242, 244; 242, 245; 243, identifier:xarr; 244, identifier:yarr; 245, identifier:zarr; 246, expression_list; 246, 247; 246, 248; 246, 249; 247, list:[]; 248, list:[]; 249, list:[]; 250, for_statement; 250, 251; 250, 252; 250, 253; 251, identifier:pos; 252, identifier:y; 253, block; 253, 254; 253, 263; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:xarr; 258, identifier:append; 259, argument_list; 259, 260; 260, subscript; 260, 261; 260, 262; 261, identifier:pos; 262, identifier:xidx; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:yarr; 267, identifier:append; 268, argument_list; 268, 269; 269, subscript; 269, 270; 269, 271; 270, identifier:pos; 271, identifier:yidx; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:lines; 276, identifier:append; 277, argument_list; 277, 278; 278, tuple; 278, 279; 278, 280; 279, identifier:xarr; 280, identifier:yarr; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 284; 283, identifier:__plot_trajectory2d_with_matplotlib; 284, argument_list; 284, 285; 284, 286; 284, 287; 285, identifier:lines; 286, identifier:ax; 287, dictionary_splat; 287, 288; 288, identifier:kwargs; 289, if_statement; 289, 290; 289, 297; 290, boolean_operator:and; 290, 291; 290, 294; 291, comparison_operator:is; 291, 292; 291, 293; 292, identifier:legend; 293, None; 294, comparison_operator:is; 294, 295; 294, 296; 295, identifier:legend; 296, False; 297, block; 297, 298; 297, 308; 297, 322; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:legend_opts; 301, dictionary; 301, 302; 301, 305; 302, pair; 302, 303; 302, 304; 303, string:"loc"; 304, string:"best"; 305, pair; 305, 306; 305, 307; 306, string:"shadow"; 307, True; 308, if_statement; 308, 309; 308, 314; 309, call; 309, 310; 309, 311; 310, identifier:isinstance; 311, argument_list; 311, 312; 311, 313; 312, identifier:legend; 313, identifier:dict; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:legend_opts; 319, identifier:update; 320, argument_list; 320, 321; 321, identifier:legend; 322, expression_statement; 322, 323; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:ax; 326, identifier:legend; 327, argument_list; 327, 328; 328, dictionary_splat; 328, 329; 329, identifier:legend_opts; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:plt; 334, identifier:show; 335, argument_list | def plot_trajectory2d_with_matplotlib(
obs, plane='xy', max_count=10, figsize=6, legend=True,
wireframe=False, grid=True, noaxis=False, plot_range=None, **kwargs):
import matplotlib.pyplot as plt
plane = plane.lower()
if len(plane) != 2 or plane[0] not in ('x', 'y', 'z') or plane[1] not in ('x', 'y', 'z'):
raise ValueError("invalid 'plane' argument [{}] was given.".format(repr(plane)))
xidx = 0 if plane[0] == 'x' else (1 if plane[0] == 'y' else 2)
yidx = 0 if plane[1] == 'x' else (1 if plane[1] == 'y' else 2)
data = obs.data()
if max_count is not None and len(data) > max_count:
data = random.sample(data, max_count)
wrange = __get_range_of_trajectories(data, plot_range)
wrange = (wrange['x'], wrange['y'], wrange['z'])
wrange = {'x': wrange[xidx], 'y': wrange[yidx]}
fig, ax = __prepare_plot_with_matplotlib(
wrange, figsize, grid, wireframe, noaxis)
ax.set_xlabel(plane[0].upper())
ax.set_ylabel(plane[1].upper())
lines = []
for i, y in enumerate(data):
xarr, yarr, zarr = [], [], []
for pos in y:
xarr.append(pos[xidx])
yarr.append(pos[yidx])
lines.append((xarr, yarr))
__plot_trajectory2d_with_matplotlib(lines, ax, **kwargs)
if legend is not None and legend is not False:
legend_opts = {"loc": "best", "shadow": True}
if isinstance(legend, dict):
legend_opts.update(legend)
ax.legend(**legend_opts)
plt.show() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 40; 2, function_name:plot_world2d_with_matplotlib; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 4, identifier:world; 5, default_parameter; 5, 6; 5, 7; 6, identifier:plane; 7, string:'xy'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:marker_size; 10, integer:3; 11, default_parameter; 11, 12; 11, 13; 12, identifier:figsize; 13, integer:6; 14, default_parameter; 14, 15; 14, 16; 15, identifier:grid; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:wireframe; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:species_list; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:max_count; 25, integer:1000; 26, default_parameter; 26, 27; 26, 28; 27, identifier:angle; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:legend; 31, True; 32, default_parameter; 32, 33; 32, 34; 33, identifier:noaxis; 34, False; 35, default_parameter; 35, 36; 35, 37; 36, identifier:scale; 37, float:1.0; 38, dictionary_splat_pattern; 38, 39; 39, identifier:kwargs; 40, block; 40, 41; 40, 47; 40, 55; 40, 94; 40, 113; 40, 132; 40, 174; 40, 182; 40, 195; 40, 209; 40, 222; 40, 241; 40, 254; 40, 267; 40, 322; 41, import_statement; 41, 42; 42, aliased_import; 42, 43; 42, 46; 43, dotted_name; 43, 44; 43, 45; 44, identifier:matplotlib; 45, identifier:pyplot; 46, identifier:plt; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:plane; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:plane; 53, identifier:lower; 54, argument_list; 55, if_statement; 55, 56; 55, 80; 56, boolean_operator:or; 56, 57; 56, 72; 57, boolean_operator:or; 57, 58; 57, 64; 58, comparison_operator:!=; 58, 59; 58, 63; 59, call; 59, 60; 59, 61; 60, identifier:len; 61, argument_list; 61, 62; 62, identifier:plane; 63, integer:2; 64, comparison_operator:not; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:plane; 67, integer:0; 68, tuple; 68, 69; 68, 70; 68, 71; 69, string:'x'; 70, string:'y'; 71, string:'z'; 72, comparison_operator:not; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:plane; 75, integer:1; 76, tuple; 76, 77; 76, 78; 76, 79; 77, string:'x'; 78, string:'y'; 79, string:'z'; 80, block; 80, 81; 81, raise_statement; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:ValueError; 84, argument_list; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, string:"invalid 'plane' argument [{}] was given."; 88, identifier:format; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:repr; 92, argument_list; 92, 93; 93, identifier:plane; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:xidx; 97, conditional_expression:if; 97, 98; 97, 99; 97, 104; 98, integer:0; 99, comparison_operator:==; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:plane; 102, integer:0; 103, string:'x'; 104, parenthesized_expression; 104, 105; 105, conditional_expression:if; 105, 106; 105, 107; 105, 112; 106, integer:1; 107, comparison_operator:==; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:plane; 110, integer:0; 111, string:'y'; 112, integer:2; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:yidx; 116, conditional_expression:if; 116, 117; 116, 118; 116, 123; 117, integer:0; 118, comparison_operator:==; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:plane; 121, integer:1; 122, string:'x'; 123, parenthesized_expression; 123, 124; 124, conditional_expression:if; 124, 125; 124, 126; 124, 131; 125, integer:1; 126, comparison_operator:==; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:plane; 129, integer:1; 130, string:'y'; 131, integer:2; 132, if_statement; 132, 133; 132, 136; 133, comparison_operator:is; 133, 134; 133, 135; 134, identifier:species_list; 135, None; 136, block; 136, 137; 136, 159; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:species_list; 140, list_comprehension; 140, 141; 140, 150; 141, call; 141, 142; 141, 149; 142, attribute; 142, 143; 142, 148; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:p; 146, identifier:species; 147, argument_list; 148, identifier:serial; 149, argument_list; 150, for_in_clause; 150, 151; 150, 154; 151, pattern_list; 151, 152; 151, 153; 152, identifier:pid; 153, identifier:p; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:world; 157, identifier:list_particles; 158, argument_list; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:species_list; 162, call; 162, 163; 162, 164; 163, identifier:sorted; 164, argument_list; 164, 165; 164, 169; 165, call; 165, 166; 165, 167; 166, identifier:set; 167, argument_list; 167, 168; 168, identifier:species_list; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:key; 171, attribute; 171, 172; 171, 173; 172, identifier:species_list; 173, identifier:index; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:wrange; 177, call; 177, 178; 177, 179; 178, identifier:__get_range_of_world; 179, argument_list; 179, 180; 179, 181; 180, identifier:world; 181, identifier:scale; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:wrange; 185, tuple; 185, 186; 185, 189; 185, 192; 186, subscript; 186, 187; 186, 188; 187, identifier:wrange; 188, string:'x'; 189, subscript; 189, 190; 189, 191; 190, identifier:wrange; 191, string:'y'; 192, subscript; 192, 193; 192, 194; 193, identifier:wrange; 194, string:'z'; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:wrange; 198, dictionary; 198, 199; 198, 204; 199, pair; 199, 200; 199, 201; 200, string:'x'; 201, subscript; 201, 202; 201, 203; 202, identifier:wrange; 203, identifier:xidx; 204, pair; 204, 205; 204, 206; 205, string:'y'; 206, subscript; 206, 207; 206, 208; 207, identifier:wrange; 208, identifier:yidx; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, pattern_list; 211, 212; 211, 213; 212, identifier:fig; 213, identifier:ax; 214, call; 214, 215; 214, 216; 215, identifier:__prepare_plot_with_matplotlib; 216, argument_list; 216, 217; 216, 218; 216, 219; 216, 220; 216, 221; 217, identifier:wrange; 218, identifier:figsize; 219, identifier:grid; 220, identifier:wireframe; 221, identifier:noaxis; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 227; 224, pattern_list; 224, 225; 224, 226; 225, identifier:scatters; 226, identifier:plots; 227, call; 227, 228; 227, 229; 228, identifier:__scatter_world2d_with_matplotlib; 229, argument_list; 229, 230; 229, 231; 229, 234; 229, 235; 229, 236; 229, 237; 229, 238; 229, 239; 230, identifier:world; 231, tuple; 231, 232; 231, 233; 232, identifier:xidx; 233, identifier:yidx; 234, identifier:ax; 235, identifier:species_list; 236, identifier:marker_size; 237, identifier:max_count; 238, identifier:scale; 239, dictionary_splat; 239, 240; 240, identifier:kwargs; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:ax; 245, identifier:set_xlabel; 246, argument_list; 246, 247; 247, call; 247, 248; 247, 253; 248, attribute; 248, 249; 248, 252; 249, subscript; 249, 250; 249, 251; 250, identifier:plane; 251, integer:0; 252, identifier:upper; 253, argument_list; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:ax; 258, identifier:set_ylabel; 259, argument_list; 259, 260; 260, call; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, subscript; 262, 263; 262, 264; 263, identifier:plane; 264, integer:1; 265, identifier:upper; 266, argument_list; 267, if_statement; 267, 268; 267, 275; 268, boolean_operator:and; 268, 269; 268, 272; 269, comparison_operator:is; 269, 270; 269, 271; 270, identifier:legend; 271, None; 272, comparison_operator:is; 272, 273; 272, 274; 273, identifier:legend; 274, False; 275, block; 275, 276; 275, 300; 275, 314; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:legend_opts; 279, dictionary; 279, 280; 279, 283; 279, 288; 279, 291; 279, 294; 279, 297; 280, pair; 280, 281; 280, 282; 281, string:'loc'; 282, string:'center left'; 283, pair; 283, 284; 283, 285; 284, string:'bbox_to_anchor'; 285, tuple; 285, 286; 285, 287; 286, float:1.0; 287, float:0.5; 288, pair; 288, 289; 288, 290; 289, string:'shadow'; 290, False; 291, pair; 291, 292; 291, 293; 292, string:'frameon'; 293, False; 294, pair; 294, 295; 294, 296; 295, string:'fontsize'; 296, string:'x-large'; 297, pair; 297, 298; 297, 299; 298, string:'scatterpoints'; 299, integer:1; 300, if_statement; 300, 301; 300, 306; 301, call; 301, 302; 301, 303; 302, identifier:isinstance; 303, argument_list; 303, 304; 303, 305; 304, identifier:legend; 305, identifier:dict; 306, block; 306, 307; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:legend_opts; 311, identifier:update; 312, argument_list; 312, 313; 313, identifier:legend; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:ax; 318, identifier:legend; 319, argument_list; 319, 320; 320, dictionary_splat; 320, 321; 321, identifier:legend_opts; 322, expression_statement; 322, 323; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:plt; 326, identifier:show; 327, argument_list | def plot_world2d_with_matplotlib(
world, plane='xy', marker_size=3, figsize=6, grid=True,
wireframe=False, species_list=None, max_count=1000, angle=None,
legend=True, noaxis=False, scale=1.0, **kwargs):
import matplotlib.pyplot as plt
plane = plane.lower()
if len(plane) != 2 or plane[0] not in ('x', 'y', 'z') or plane[1] not in ('x', 'y', 'z'):
raise ValueError("invalid 'plane' argument [{}] was given.".format(repr(plane)))
xidx = 0 if plane[0] == 'x' else (1 if plane[0] == 'y' else 2)
yidx = 0 if plane[1] == 'x' else (1 if plane[1] == 'y' else 2)
if species_list is None:
species_list = [p.species().serial() for pid, p in world.list_particles()]
species_list = sorted(
set(species_list), key=species_list.index)
wrange = __get_range_of_world(world, scale)
wrange = (wrange['x'], wrange['y'], wrange['z'])
wrange = {'x': wrange[xidx], 'y': wrange[yidx]}
fig, ax = __prepare_plot_with_matplotlib(
wrange, figsize, grid, wireframe, noaxis)
scatters, plots = __scatter_world2d_with_matplotlib(
world, (xidx, yidx), ax, species_list, marker_size, max_count, scale, **kwargs)
ax.set_xlabel(plane[0].upper())
ax.set_ylabel(plane[1].upper())
if legend is not None and legend is not False:
legend_opts = {'loc': 'center left', 'bbox_to_anchor': (1.0, 0.5),
'shadow': False, 'frameon': False, 'fontsize': 'x-large',
'scatterpoints': 1}
if isinstance(legend, dict):
legend_opts.update(legend)
ax.legend(**legend_opts)
plt.show() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:get_model; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:is_netfree; 6, False; 7, default_parameter; 7, 8; 7, 9; 8, identifier:without_reset; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:seeds; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:effective; 15, False; 16, block; 16, 17; 16, 120; 17, try_statement; 17, 18; 17, 108; 18, block; 18, 19; 18, 48; 18, 59; 18, 70; 18, 78; 18, 90; 19, if_statement; 19, 20; 19, 25; 19, 36; 20, boolean_operator:or; 20, 21; 20, 24; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:seeds; 23, None; 24, identifier:is_netfree; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:m; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:ecell4_base; 33, identifier:core; 34, identifier:NetfreeModel; 35, argument_list; 36, else_clause; 36, 37; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:m; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:ecell4_base; 45, identifier:core; 46, identifier:NetworkModel; 47, argument_list; 48, for_statement; 48, 49; 48, 50; 48, 51; 49, identifier:sp; 50, identifier:SPECIES_ATTRIBUTES; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:m; 56, identifier:add_species_attribute; 57, argument_list; 57, 58; 58, identifier:sp; 59, for_statement; 59, 60; 59, 61; 59, 62; 60, identifier:rr; 61, identifier:REACTION_RULES; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:m; 67, identifier:add_reaction_rule; 68, argument_list; 68, 69; 69, identifier:rr; 70, if_statement; 70, 71; 70, 73; 71, not_operator; 71, 72; 72, identifier:without_reset; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:reset_model; 77, argument_list; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:is; 79, 80; 79, 81; 80, identifier:seeds; 81, None; 82, block; 82, 83; 83, return_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:m; 87, identifier:expand; 88, argument_list; 88, 89; 89, identifier:seeds; 90, if_statement; 90, 91; 90, 100; 91, call; 91, 92; 91, 93; 92, identifier:isinstance; 93, argument_list; 93, 94; 93, 95; 94, identifier:m; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:ecell4_base; 98, identifier:core; 99, identifier:NetfreeModel; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:m; 105, identifier:set_effective; 106, argument_list; 106, 107; 107, identifier:effective; 108, except_clause; 108, 109; 108, 113; 109, as_pattern; 109, 110; 109, 111; 110, identifier:Exception; 111, as_pattern_target; 111, 112; 112, identifier:e; 113, block; 113, 114; 113, 118; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:reset_model; 117, argument_list; 118, raise_statement; 118, 119; 119, identifier:e; 120, return_statement; 120, 121; 121, identifier:m | def get_model(is_netfree=False, without_reset=False, seeds=None, effective=False):
try:
if seeds is not None or is_netfree:
m = ecell4_base.core.NetfreeModel()
else:
m = ecell4_base.core.NetworkModel()
for sp in SPECIES_ATTRIBUTES:
m.add_species_attribute(sp)
for rr in REACTION_RULES:
m.add_reaction_rule(rr)
if not without_reset:
reset_model()
if seeds is not None:
return m.expand(seeds)
if isinstance(m, ecell4_base.core.NetfreeModel):
m.set_effective(effective)
except Exception as e:
reset_model()
raise e
return m |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:run_multiprocessing; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:target; 5, identifier:jobs; 6, default_parameter; 6, 7; 6, 8; 7, identifier:n; 8, integer:1; 9, default_parameter; 9, 10; 9, 11; 10, identifier:nproc; 11, None; 12, dictionary_splat_pattern; 12, 13; 13, identifier:kwargs; 14, block; 14, 15; 14, 74; 14, 217; 14, 253; 15, function_definition; 15, 16; 15, 17; 15, 21; 16, function_name:consumer; 17, parameters; 17, 18; 17, 19; 17, 20; 18, identifier:f; 19, identifier:q_in; 20, identifier:q_out; 21, block; 21, 22; 22, while_statement; 22, 23; 22, 24; 23, True; 24, block; 24, 25; 24, 33; 24, 45; 24, 51; 24, 61; 24, 67; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:val; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:q_in; 31, identifier:get; 32, argument_list; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:val; 36, None; 37, block; 37, 38; 37, 44; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:q_in; 42, identifier:task_done; 43, argument_list; 44, break_statement; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, pattern_list; 47, 48; 47, 49; 48, identifier:i; 49, identifier:x; 50, identifier:val; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:res; 54, tuple; 54, 55; 54, 56; 55, identifier:i; 56, call; 56, 57; 56, 58; 57, identifier:f; 58, argument_list; 58, 59; 59, list_splat; 59, 60; 60, identifier:x; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:q_in; 65, identifier:task_done; 66, argument_list; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:q_out; 71, identifier:put; 72, argument_list; 72, 73; 73, identifier:res; 74, function_definition; 74, 75; 74, 76; 74, 80; 75, function_name:mulpmap; 76, parameters; 76, 77; 76, 78; 76, 79; 77, identifier:f; 78, identifier:X; 79, identifier:nproc; 80, block; 80, 81; 80, 91; 80, 99; 80, 107; 80, 134; 80, 154; 80, 161; 80, 175; 80, 185; 80, 191; 80, 206; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:nproc; 84, boolean_operator:or; 84, 85; 84, 86; 85, identifier:nproc; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:multiprocessing; 89, identifier:cpu_count; 90, argument_list; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:q_in; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:multiprocessing; 97, identifier:JoinableQueue; 98, argument_list; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:q_out; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:multiprocessing; 105, identifier:Queue; 106, argument_list; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:workers; 110, list_comprehension; 110, 111; 110, 128; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:multiprocessing; 114, identifier:Process; 115, argument_list; 115, 116; 115, 119; 115, 125; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:target; 118, identifier:consumer; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:args; 121, tuple; 121, 122; 121, 123; 121, 124; 122, identifier:f; 123, identifier:q_in; 124, identifier:q_out; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:daemon; 127, True; 128, for_in_clause; 128, 129; 128, 130; 129, identifier:_; 130, call; 130, 131; 130, 132; 131, identifier:range; 132, argument_list; 132, 133; 133, identifier:nproc; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:sent; 137, list_comprehension; 137, 138; 137, 146; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:q_in; 141, identifier:put; 142, argument_list; 142, 143; 143, tuple; 143, 144; 143, 145; 144, identifier:i; 145, identifier:x; 146, for_in_clause; 146, 147; 146, 150; 147, pattern_list; 147, 148; 147, 149; 148, identifier:i; 149, identifier:x; 150, call; 150, 151; 150, 152; 151, identifier:enumerate; 152, argument_list; 152, 153; 153, identifier:X; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:num_tasks; 157, call; 157, 158; 157, 159; 158, identifier:len; 159, argument_list; 159, 160; 160, identifier:sent; 161, expression_statement; 161, 162; 162, list_comprehension; 162, 163; 162, 169; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:q_in; 166, identifier:put; 167, argument_list; 167, 168; 168, None; 169, for_in_clause; 169, 170; 169, 171; 170, identifier:_; 171, call; 171, 172; 171, 173; 172, identifier:range; 173, argument_list; 173, 174; 174, identifier:nproc; 175, expression_statement; 175, 176; 176, list_comprehension; 176, 177; 176, 182; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:w; 180, identifier:start; 181, argument_list; 182, for_in_clause; 182, 183; 182, 184; 183, identifier:w; 184, identifier:workers; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:q_in; 189, identifier:join; 190, argument_list; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:res; 194, list_comprehension; 194, 195; 194, 200; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:q_out; 198, identifier:get; 199, argument_list; 200, for_in_clause; 200, 201; 200, 202; 201, identifier:_; 202, call; 202, 203; 202, 204; 203, identifier:range; 204, argument_list; 204, 205; 205, identifier:num_tasks; 206, return_statement; 206, 207; 207, list_comprehension; 207, 208; 207, 209; 208, identifier:x; 209, for_in_clause; 209, 210; 209, 213; 210, tuple_pattern; 210, 211; 210, 212; 211, identifier:_; 212, identifier:x; 213, call; 213, 214; 213, 215; 214, identifier:sorted; 215, argument_list; 215, 216; 216, identifier:res; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:res; 220, call; 220, 221; 220, 222; 221, identifier:mulpmap; 222, argument_list; 222, 223; 222, 224; 222, 252; 223, identifier:target; 224, generator_expression; 224, 225; 224, 233; 225, tuple; 225, 226; 225, 227; 225, 230; 226, identifier:job; 227, binary_operator:+; 227, 228; 227, 229; 228, identifier:i; 229, integer:1; 230, binary_operator:+; 230, 231; 230, 232; 231, identifier:j; 232, integer:1; 233, for_in_clause; 233, 234; 233, 239; 234, pattern_list; 234, 235; 234, 238; 235, tuple_pattern; 235, 236; 235, 237; 236, identifier:i; 237, identifier:job; 238, identifier:j; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:itertools; 242, identifier:product; 243, argument_list; 243, 244; 243, 248; 244, call; 244, 245; 244, 246; 245, identifier:enumerate; 246, argument_list; 246, 247; 247, identifier:jobs; 248, call; 248, 249; 248, 250; 249, identifier:range; 250, argument_list; 250, 251; 251, identifier:n; 252, identifier:nproc; 253, return_statement; 253, 254; 254, list_comprehension; 254, 255; 254, 263; 255, subscript; 255, 256; 255, 257; 256, identifier:res; 257, slice; 257, 258; 257, 259; 257, 260; 258, identifier:i; 259, colon; 260, binary_operator:+; 260, 261; 260, 262; 261, identifier:i; 262, identifier:n; 263, for_in_clause; 263, 264; 263, 265; 264, identifier:i; 265, call; 265, 266; 265, 267; 266, identifier:range; 267, argument_list; 267, 268; 267, 269; 267, 273; 268, integer:0; 269, call; 269, 270; 269, 271; 270, identifier:len; 271, argument_list; 271, 272; 272, identifier:res; 273, identifier:n | def run_multiprocessing(target, jobs, n=1, nproc=None, **kwargs):
def consumer(f, q_in, q_out):
while True:
val = q_in.get()
if val is None:
q_in.task_done()
break
i, x = val
res = (i, f(*x))
q_in.task_done()
q_out.put(res)
def mulpmap(f, X, nproc):
nproc = nproc or multiprocessing.cpu_count()
q_in = multiprocessing.JoinableQueue()
q_out = multiprocessing.Queue()
workers = [multiprocessing.Process(target=consumer, args=(f, q_in, q_out), daemon=True) for _ in range(nproc)]
sent = [q_in.put((i, x)) for i, x in enumerate(X)]
num_tasks = len(sent)
[q_in.put(None) for _ in range(nproc)]
[w.start() for w in workers]
q_in.join()
res = [q_out.get() for _ in range(num_tasks)]
return [x for (_, x) in sorted(res)]
res = mulpmap(
target, ((job, i + 1, j + 1) for (i, job), j in itertools.product(enumerate(jobs), range(n))), nproc)
return [res[i: i + n] for i in range(0, len(res), n)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:readbits; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:bits; 6, block; 6, 7; 6, 14; 6, 36; 6, 40; 6, 46; 6, 105; 6, 208; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:==; 8, 9; 8, 10; 9, identifier:bits; 10, integer:0; 11, block; 11, 12; 12, return_statement; 12, 13; 13, integer:0; 14, if_statement; 14, 15; 14, 26; 15, boolean_operator:and; 15, 16; 15, 21; 16, comparison_operator:==; 16, 17; 16, 20; 17, binary_operator:%; 17, 18; 17, 19; 18, identifier:bits; 19, integer:8; 20, integer:0; 21, comparison_operator:==; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:_bits_pending; 25, integer:0; 26, block; 26, 27; 27, return_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:_read_bytes_aligned; 32, argument_list; 32, 33; 33, binary_operator://; 33, 34; 33, 35; 34, identifier:bits; 35, integer:8; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:out; 39, integer:0; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:masks; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:_masks; 46, function_definition; 46, 47; 46, 48; 46, 53; 47, function_name:transfer_bits; 48, parameters; 48, 49; 48, 50; 48, 51; 48, 52; 49, identifier:x; 50, identifier:y; 51, identifier:n; 52, identifier:t; 53, block; 53, 54; 53, 68; 53, 74; 53, 82; 53, 94; 54, if_statement; 54, 55; 54, 58; 55, comparison_operator:==; 55, 56; 55, 57; 56, identifier:n; 57, identifier:t; 58, block; 58, 59; 59, return_statement; 59, 60; 60, expression_list; 60, 61; 60, 67; 61, binary_operator:|; 61, 62; 61, 66; 62, parenthesized_expression; 62, 63; 63, binary_operator:<<; 63, 64; 63, 65; 64, identifier:x; 65, identifier:t; 66, identifier:y; 67, integer:0; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:mask; 71, subscript; 71, 72; 71, 73; 72, identifier:masks; 73, identifier:t; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:remainmask; 77, subscript; 77, 78; 77, 79; 78, identifier:masks; 79, binary_operator:-; 79, 80; 79, 81; 80, identifier:n; 81, identifier:t; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:taken; 85, parenthesized_expression; 85, 86; 86, binary_operator:&; 86, 87; 86, 93; 87, parenthesized_expression; 87, 88; 88, binary_operator:>>; 88, 89; 88, 90; 89, identifier:y; 90, binary_operator:-; 90, 91; 90, 92; 91, identifier:n; 92, identifier:t; 93, identifier:mask; 94, return_statement; 94, 95; 95, expression_list; 95, 96; 95, 102; 96, binary_operator:|; 96, 97; 96, 101; 97, parenthesized_expression; 97, 98; 98, binary_operator:<<; 98, 99; 98, 100; 99, identifier:x; 100, identifier:t; 101, identifier:taken; 102, binary_operator:&; 102, 103; 102, 104; 103, identifier:y; 104, identifier:remainmask; 105, while_statement; 105, 106; 105, 109; 106, comparison_operator:>; 106, 107; 106, 108; 107, identifier:bits; 108, integer:0; 109, block; 109, 110; 109, 175; 109, 186; 109, 193; 109, 202; 110, if_statement; 110, 111; 110, 116; 111, comparison_operator:>; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:_bits_pending; 115, integer:0; 116, block; 116, 117; 116, 123; 116, 133; 116, 151; 116, 164; 116, 170; 116, 174; 117, assert_statement; 117, 118; 118, comparison_operator:is; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:_partial_byte; 122, None; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:take; 126, call; 126, 127; 126, 128; 127, identifier:min; 128, argument_list; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:_bits_pending; 132, identifier:bits; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 140; 135, pattern_list; 135, 136; 135, 137; 136, identifier:out; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:_partial_byte; 140, call; 140, 141; 140, 142; 141, identifier:transfer_bits; 142, argument_list; 142, 143; 142, 144; 142, 147; 142, 150; 143, identifier:out; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:_partial_byte; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:_bits_pending; 150, identifier:take; 151, if_statement; 151, 152; 151, 157; 152, comparison_operator:==; 152, 153; 152, 154; 153, identifier:take; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:_bits_pending; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:_partial_byte; 163, None; 164, expression_statement; 164, 165; 165, augmented_assignment:-=; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:_bits_pending; 169, identifier:take; 170, expression_statement; 170, 171; 171, augmented_assignment:-=; 171, 172; 171, 173; 172, identifier:bits; 173, identifier:take; 174, continue_statement; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:r; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:f; 183, identifier:read; 184, argument_list; 184, 185; 185, integer:1; 186, if_statement; 186, 187; 186, 190; 187, comparison_operator:==; 187, 188; 187, 189; 188, identifier:r; 189, string:b''; 190, block; 190, 191; 191, raise_statement; 191, 192; 192, identifier:EOFError; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:_partial_byte; 198, call; 198, 199; 198, 200; 199, identifier:ord; 200, argument_list; 200, 201; 201, identifier:r; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:_bits_pending; 207, integer:8; 208, return_statement; 208, 209; 209, identifier:out | def readbits(self, bits):
if bits == 0:
return 0
if bits % 8 == 0 and self._bits_pending == 0:
return self._read_bytes_aligned(bits // 8)
out = 0
masks = self._masks
def transfer_bits(x, y, n, t):
if n == t:
return (x << t) | y, 0
mask = masks[t]
remainmask = masks[n - t]
taken = ((y >> n - t) & mask)
return (x << t) | taken, y & remainmask
while bits > 0:
if self._bits_pending > 0:
assert self._partial_byte is not None
take = min(self._bits_pending, bits)
out, self._partial_byte = transfer_bits(out, self._partial_byte, self._bits_pending, take)
if take == self._bits_pending:
self._partial_byte = None
self._bits_pending -= take
bits -= take
continue
r = self.f.read(1)
if r == b'':
raise EOFError
self._partial_byte = ord(r)
self._bits_pending = 8
return out |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:export; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:swf; 6, identifier:shape; 7, dictionary_splat_pattern; 7, 8; 8, identifier:export_opts; 9, block; 9, 10; 9, 65; 9, 71; 9, 96; 9, 230; 9, 236; 9, 242; 10, if_statement; 10, 11; 10, 16; 10, 21; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:shape; 15, identifier:Tag; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:shape_tag; 20, identifier:shape; 21, else_clause; 21, 22; 22, block; 22, 23; 22, 44; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:shapes; 26, list_comprehension; 26, 27; 26, 28; 26, 38; 27, identifier:x; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:x; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:swf; 33, identifier:all_tags_of_type; 34, argument_list; 34, 35; 35, tuple; 35, 36; 35, 37; 36, identifier:TagDefineShape; 37, identifier:TagDefineSprite; 38, if_clause; 38, 39; 39, comparison_operator:==; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:x; 42, identifier:characterId; 43, identifier:shape; 44, if_statement; 44, 45; 44, 49; 44, 56; 45, call; 45, 46; 45, 47; 46, identifier:len; 47, argument_list; 47, 48; 48, identifier:shapes; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:shape_tag; 53, subscript; 53, 54; 53, 55; 54, identifier:shapes; 55, integer:0; 56, else_clause; 56, 57; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:Exception; 61, argument_list; 61, 62; 62, binary_operator:%; 62, 63; 62, 64; 63, string:"Shape %s not found"; 64, identifier:shape; 65, import_from_statement; 65, 66; 65, 69; 66, dotted_name; 66, 67; 66, 68; 67, identifier:swf; 68, identifier:movie; 69, dotted_name; 69, 70; 70, identifier:SWF; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:example_place_objects; 74, list_comprehension; 74, 75; 74, 76; 74, 84; 75, identifier:x; 76, for_in_clause; 76, 77; 76, 78; 77, identifier:x; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:swf; 81, identifier:all_tags_of_type; 82, argument_list; 82, 83; 83, identifier:TagPlaceObject; 84, if_clause; 84, 85; 85, boolean_operator:and; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:x; 88, identifier:hasCharacter; 89, comparison_operator:==; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:x; 92, identifier:characterId; 93, attribute; 93, 94; 93, 95; 94, identifier:shape_tag; 95, identifier:characterId; 96, if_statement; 96, 97; 96, 101; 96, 202; 97, call; 97, 98; 97, 99; 98, identifier:len; 99, argument_list; 99, 100; 100, identifier:example_place_objects; 101, block; 101, 102; 101, 108; 101, 116; 101, 124; 101, 130; 101, 134; 101, 189; 101, 195; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:place_object; 105, subscript; 105, 106; 105, 107; 106, identifier:example_place_objects; 107, integer:0; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:characters; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:swf; 114, identifier:build_dictionary; 115, argument_list; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:ids_to_export; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:place_object; 122, identifier:get_dependencies; 123, argument_list; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:ids_exported; 127, call; 127, 128; 127, 129; 128, identifier:set; 129, argument_list; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:tags_to_export; 133, list:[]; 134, while_statement; 134, 135; 134, 139; 135, call; 135, 136; 135, 137; 136, identifier:len; 137, argument_list; 137, 138; 138, identifier:ids_to_export; 139, block; 139, 140; 139, 148; 139, 158; 139, 164; 139, 175; 139, 182; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:id; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:ids_to_export; 146, identifier:pop; 147, argument_list; 148, if_statement; 148, 149; 148, 156; 149, boolean_operator:or; 149, 150; 149, 153; 150, comparison_operator:in; 150, 151; 150, 152; 151, identifier:id; 152, identifier:ids_exported; 153, comparison_operator:not; 153, 154; 153, 155; 154, identifier:id; 155, identifier:characters; 156, block; 156, 157; 157, continue_statement; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:tag; 161, subscript; 161, 162; 161, 163; 162, identifier:characters; 163, identifier:id; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:ids_to_export; 168, identifier:update; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:tag; 173, identifier:get_dependencies; 174, argument_list; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:tags_to_export; 179, identifier:append; 180, argument_list; 180, 181; 181, identifier:tag; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:ids_exported; 186, identifier:add; 187, argument_list; 187, 188; 188, identifier:id; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:tags_to_export; 193, identifier:reverse; 194, argument_list; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:tags_to_export; 199, identifier:append; 200, argument_list; 200, 201; 201, identifier:place_object; 202, else_clause; 202, 203; 203, block; 203, 204; 203, 210; 203, 216; 203, 224; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:place_object; 207, call; 207, 208; 207, 209; 208, identifier:TagPlaceObject; 209, argument_list; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:place_object; 214, identifier:hasCharacter; 215, True; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:place_object; 220, identifier:characterId; 221, attribute; 221, 222; 221, 223; 222, identifier:shape_tag; 223, identifier:characterId; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:tags_to_export; 227, list:[ shape_tag, place_object ]; 227, 228; 227, 229; 228, identifier:shape_tag; 229, identifier:place_object; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:stunt_swf; 233, call; 233, 234; 233, 235; 234, identifier:SWF; 235, argument_list; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:stunt_swf; 240, identifier:tags; 241, identifier:tags_to_export; 242, return_statement; 242, 243; 243, call; 243, 244; 243, 251; 244, attribute; 244, 245; 244, 250; 245, call; 245, 246; 245, 247; 246, identifier:super; 247, argument_list; 247, 248; 247, 249; 248, identifier:SingleShapeSVGExporterMixin; 249, identifier:self; 250, identifier:export; 251, argument_list; 251, 252; 251, 253; 252, identifier:stunt_swf; 253, dictionary_splat; 253, 254; 254, identifier:export_opts | def export(self, swf, shape, **export_opts):
if isinstance(shape, Tag):
shape_tag = shape
else:
shapes = [x for x in swf.all_tags_of_type((TagDefineShape, TagDefineSprite)) if x.characterId == shape]
if len(shapes):
shape_tag = shapes[0]
else:
raise Exception("Shape %s not found" % shape)
from swf.movie import SWF
example_place_objects = [x for x in swf.all_tags_of_type(TagPlaceObject) if x.hasCharacter and x.characterId == shape_tag.characterId]
if len(example_place_objects):
place_object = example_place_objects[0]
characters = swf.build_dictionary()
ids_to_export = place_object.get_dependencies()
ids_exported = set()
tags_to_export = []
while len(ids_to_export):
id = ids_to_export.pop()
if id in ids_exported or id not in characters:
continue
tag = characters[id]
ids_to_export.update(tag.get_dependencies())
tags_to_export.append(tag)
ids_exported.add(id)
tags_to_export.reverse()
tags_to_export.append(place_object)
else:
place_object = TagPlaceObject()
place_object.hasCharacter = True
place_object.characterId = shape_tag.characterId
tags_to_export = [ shape_tag, place_object ]
stunt_swf = SWF()
stunt_swf.tags = tags_to_export
return super(SingleShapeSVGExporterMixin, self).export(stunt_swf, **export_opts) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:draw_residual; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:x; 5, identifier:y; 6, identifier:yerr; 7, identifier:xerr; 8, default_parameter; 8, 9; 8, 10; 9, identifier:show_errbars; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:ax; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:zero_line; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:grid; 19, True; 20, dictionary_splat_pattern; 20, 21; 21, identifier:kwargs; 22, block; 22, 23; 22, 30; 22, 43; 22, 119; 22, 152; 22, 162; 23, import_from_statement; 23, 24; 23, 26; 24, dotted_name; 24, 25; 25, identifier:matplotlib; 26, aliased_import; 26, 27; 26, 29; 27, dotted_name; 27, 28; 28, identifier:pyplot; 29, identifier:plt; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:ax; 33, conditional_expression:if; 33, 34; 33, 39; 33, 42; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:plt; 37, identifier:gca; 38, argument_list; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:ax; 41, None; 42, identifier:ax; 43, if_statement; 43, 44; 43, 45; 43, 82; 44, identifier:show_errbars; 45, block; 45, 46; 45, 58; 45, 65; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:plotopts; 49, call; 49, 50; 49, 51; 50, identifier:dict; 51, argument_list; 51, 52; 51, 55; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:fmt; 54, string:'b.'; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:capsize; 57, integer:0; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:plotopts; 62, identifier:update; 63, argument_list; 63, 64; 64, identifier:kwargs; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:pp; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:ax; 71, identifier:errorbar; 72, argument_list; 72, 73; 72, 74; 72, 75; 72, 76; 72, 77; 72, 80; 73, identifier:x; 74, identifier:y; 75, identifier:yerr; 76, identifier:xerr; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:zorder; 79, integer:0; 80, dictionary_splat; 80, 81; 81, identifier:plotopts; 82, else_clause; 82, 83; 83, block; 83, 84; 83, 93; 83, 100; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:plotopts; 87, call; 87, 88; 87, 89; 88, identifier:dict; 89, argument_list; 89, 90; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:color; 92, string:'k'; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:plotopts; 97, identifier:update; 98, argument_list; 98, 99; 99, identifier:kwargs; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:pp; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:ax; 106, identifier:bar; 107, argument_list; 107, 108; 107, 111; 107, 112; 107, 117; 108, binary_operator:-; 108, 109; 108, 110; 109, identifier:x; 110, identifier:xerr; 111, identifier:y; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:width; 114, binary_operator:*; 114, 115; 114, 116; 115, integer:2; 116, identifier:xerr; 117, dictionary_splat; 117, 118; 118, identifier:plotopts; 119, if_statement; 119, 120; 119, 121; 120, identifier:zero_line; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:ax; 126, identifier:plot; 127, argument_list; 127, 128; 127, 145; 127, 148; 127, 149; 128, list:[x[0] - xerr[0], x[-1] + xerr[-1]]; 128, 129; 128, 136; 129, binary_operator:-; 129, 130; 129, 133; 130, subscript; 130, 131; 130, 132; 131, identifier:x; 132, integer:0; 133, subscript; 133, 134; 133, 135; 134, identifier:xerr; 135, integer:0; 136, binary_operator:+; 136, 137; 136, 141; 137, subscript; 137, 138; 137, 139; 138, identifier:x; 139, unary_operator:-; 139, 140; 140, integer:1; 141, subscript; 141, 142; 141, 143; 142, identifier:xerr; 143, unary_operator:-; 143, 144; 144, integer:1; 145, list:[0, 0]; 145, 146; 145, 147; 146, integer:0; 147, integer:0; 148, string:'r-'; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:zorder; 151, integer:2; 152, if_statement; 152, 153; 152, 154; 153, identifier:grid; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:ax; 159, identifier:grid; 160, argument_list; 160, 161; 161, identifier:grid; 162, return_statement; 162, 163; 163, identifier:ax | def draw_residual(x, y, yerr, xerr,
show_errbars=True, ax=None,
zero_line=True, grid=True,
**kwargs):
from matplotlib import pyplot as plt
ax = plt.gca() if ax is None else ax
if show_errbars:
plotopts = dict(fmt='b.', capsize=0)
plotopts.update(kwargs)
pp = ax.errorbar(x, y, yerr, xerr, zorder=0, **plotopts)
else:
plotopts = dict(color='k')
plotopts.update(kwargs)
pp = ax.bar(x - xerr, y, width=2*xerr, **plotopts)
if zero_line:
ax.plot([x[0] - xerr[0], x[-1] + xerr[-1]], [0, 0], 'r-', zorder=2)
if grid:
ax.grid(grid)
return ax |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:combined_message_class; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 17; 5, 21; 5, 25; 5, 53; 5, 115; 5, 129; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:is; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:__combined_message_class; 11, None; 12, block; 12, 13; 13, return_statement; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:__combined_message_class; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:fields; 20, dictionary; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:field_number; 24, integer:1; 25, for_statement; 25, 26; 25, 27; 25, 34; 26, identifier:field; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:body_message_class; 32, identifier:all_fields; 33, argument_list; 34, block; 34, 35; 34, 49; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 42; 37, subscript; 37, 38; 37, 39; 38, identifier:fields; 39, attribute; 39, 40; 39, 41; 40, identifier:field; 41, identifier:name; 42, call; 42, 43; 42, 44; 43, identifier:_CopyField; 44, argument_list; 44, 45; 44, 46; 45, identifier:field; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:number; 48, identifier:field_number; 49, expression_statement; 49, 50; 50, augmented_assignment:+=; 50, 51; 50, 52; 51, identifier:field_number; 52, integer:1; 53, for_statement; 53, 54; 53, 55; 53, 62; 54, identifier:field; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:parameters_message_class; 60, identifier:all_fields; 61, argument_list; 62, block; 62, 63; 62, 97; 62, 111; 63, if_statement; 63, 64; 63, 69; 64, comparison_operator:in; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:field; 67, identifier:name; 68, identifier:fields; 69, block; 69, 70; 70, if_statement; 70, 71; 70, 81; 70, 94; 71, not_operator; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:_CompareFields; 74, argument_list; 74, 75; 74, 76; 75, identifier:field; 76, subscript; 76, 77; 76, 78; 77, identifier:fields; 78, attribute; 78, 79; 78, 80; 79, identifier:field; 80, identifier:name; 81, block; 81, 82; 82, raise_statement; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:TypeError; 85, argument_list; 85, 86; 86, binary_operator:%; 86, 87; 86, 90; 87, concatenated_string; 87, 88; 87, 89; 88, string:'Field %r contained in both parameters and request '; 89, string:'body, but the fields differ.'; 90, tuple; 90, 91; 91, attribute; 91, 92; 91, 93; 92, identifier:field; 93, identifier:name; 94, else_clause; 94, 95; 95, block; 95, 96; 96, continue_statement; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 104; 99, subscript; 99, 100; 99, 101; 100, identifier:fields; 101, attribute; 101, 102; 101, 103; 102, identifier:field; 103, identifier:name; 104, call; 104, 105; 104, 106; 105, identifier:_CopyField; 106, argument_list; 106, 107; 106, 108; 107, identifier:field; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:number; 110, identifier:field_number; 111, expression_statement; 111, 112; 112, augmented_assignment:+=; 112, 113; 112, 114; 113, identifier:field_number; 114, integer:1; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:__combined_message_class; 120, call; 120, 121; 120, 122; 121, identifier:type; 122, argument_list; 122, 123; 122, 124; 122, 128; 123, string:'CombinedContainer'; 124, tuple; 124, 125; 125, attribute; 125, 126; 125, 127; 126, identifier:messages; 127, identifier:Message; 128, identifier:fields; 129, return_statement; 129, 130; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:__combined_message_class | def combined_message_class(self):
if self.__combined_message_class is not None:
return self.__combined_message_class
fields = {}
field_number = 1
for field in self.body_message_class.all_fields():
fields[field.name] = _CopyField(field, number=field_number)
field_number += 1
for field in self.parameters_message_class.all_fields():
if field.name in fields:
if not _CompareFields(field, fields[field.name]):
raise TypeError('Field %r contained in both parameters and request '
'body, but the fields differ.' % (field.name,))
else:
continue
fields[field.name] = _CopyField(field, number=field_number)
field_number += 1
self.__combined_message_class = type('CombinedContainer',
(messages.Message,), fields)
return self.__combined_message_class |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:_get_token; 3, parameters; 3, 4; 3, 7; 3, 12; 4, default_parameter; 4, 5; 4, 6; 5, identifier:request; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:allowed_auth_schemes; 9, tuple; 9, 10; 9, 11; 10, string:'OAuth'; 11, string:'Bearer'; 12, default_parameter; 12, 13; 12, 14; 13, identifier:allowed_query_keys; 14, tuple; 14, 15; 14, 16; 15, string:'bearer_token'; 16, string:'access_token'; 17, block; 17, 18; 17, 29; 17, 40; 17, 68; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:allowed_auth_schemes; 21, call; 21, 22; 21, 23; 22, identifier:_listlike_guard; 23, argument_list; 23, 24; 23, 25; 23, 26; 24, identifier:allowed_auth_schemes; 25, string:'allowed_auth_schemes'; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:iterable_only; 28, True; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:auth_header; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:os; 36, identifier:environ; 37, identifier:get; 38, argument_list; 38, 39; 39, string:'HTTP_AUTHORIZATION'; 40, if_statement; 40, 41; 40, 42; 41, identifier:auth_header; 42, block; 42, 43; 42, 66; 43, for_statement; 43, 44; 43, 45; 43, 46; 44, identifier:auth_scheme; 45, identifier:allowed_auth_schemes; 46, block; 46, 47; 47, if_statement; 47, 48; 47, 54; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:auth_header; 51, identifier:startswith; 52, argument_list; 52, 53; 53, identifier:auth_scheme; 54, block; 54, 55; 55, return_statement; 55, 56; 56, subscript; 56, 57; 56, 58; 57, identifier:auth_header; 58, slice; 58, 59; 58, 65; 59, binary_operator:+; 59, 60; 59, 64; 60, call; 60, 61; 60, 62; 61, identifier:len; 62, argument_list; 62, 63; 63, identifier:auth_scheme; 64, integer:1; 65, colon; 66, return_statement; 66, 67; 67, None; 68, if_statement; 68, 69; 68, 70; 69, identifier:request; 70, block; 70, 71; 70, 82; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:allowed_query_keys; 74, call; 74, 75; 74, 76; 75, identifier:_listlike_guard; 76, argument_list; 76, 77; 76, 78; 76, 79; 77, identifier:allowed_query_keys; 78, string:'allowed_query_keys'; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:iterable_only; 81, True; 82, for_statement; 82, 83; 82, 84; 82, 85; 83, identifier:key; 84, identifier:allowed_query_keys; 85, block; 85, 86; 85, 97; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, pattern_list; 88, 89; 88, 90; 89, identifier:token; 90, identifier:_; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:request; 94, identifier:get_unrecognized_field_info; 95, argument_list; 95, 96; 96, identifier:key; 97, if_statement; 97, 98; 97, 99; 98, identifier:token; 99, block; 99, 100; 100, return_statement; 100, 101; 101, identifier:token | def _get_token(
request=None, allowed_auth_schemes=('OAuth', 'Bearer'),
allowed_query_keys=('bearer_token', 'access_token')):
allowed_auth_schemes = _listlike_guard(
allowed_auth_schemes, 'allowed_auth_schemes', iterable_only=True)
auth_header = os.environ.get('HTTP_AUTHORIZATION')
if auth_header:
for auth_scheme in allowed_auth_schemes:
if auth_header.startswith(auth_scheme):
return auth_header[len(auth_scheme) + 1:]
return None
if request:
allowed_query_keys = _listlike_guard(
allowed_query_keys, 'allowed_query_keys', iterable_only=True)
for key in allowed_query_keys:
token, _ = request.get_unrecognized_field_info(key)
if token:
return token |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_get_id_token_user; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:token; 5, identifier:issuers; 6, identifier:audiences; 7, identifier:allowed_client_ids; 8, identifier:time_now; 9, identifier:cache; 10, block; 10, 11; 11, for_statement; 11, 12; 11, 15; 11, 20; 12, pattern_list; 12, 13; 12, 14; 13, identifier:issuer_key; 14, identifier:issuer; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:issuers; 18, identifier:items; 19, argument_list; 20, block; 20, 21; 20, 30; 20, 59; 20, 72; 20, 85; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:issuer_cert_uri; 24, call; 24, 25; 24, 26; 25, identifier:convert_jwks_uri; 26, argument_list; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:issuer; 29, identifier:jwks_uri; 30, try_statement; 30, 31; 30, 44; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:parsed_token; 35, call; 35, 36; 35, 37; 36, identifier:_verify_signed_jwt_with_certs; 37, argument_list; 37, 38; 37, 39; 37, 40; 37, 41; 38, identifier:token; 39, identifier:time_now; 40, identifier:cache; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:cert_uri; 43, identifier:issuer_cert_uri; 44, except_clause; 44, 45; 44, 46; 45, identifier:Exception; 46, block; 46, 47; 46, 58; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:_logger; 51, identifier:debug; 52, argument_list; 52, 53; 52, 54; 52, 55; 53, string:'id_token verification failed for issuer %s'; 54, identifier:issuer_key; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:exc_info; 57, True; 58, continue_statement; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:issuer_values; 62, call; 62, 63; 62, 64; 63, identifier:_listlike_guard; 64, argument_list; 64, 65; 64, 68; 64, 69; 65, attribute; 65, 66; 65, 67; 66, identifier:issuer; 67, identifier:issuer; 68, string:'issuer'; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:log_warning; 71, False; 72, if_statement; 72, 73; 72, 78; 73, call; 73, 74; 73, 75; 74, identifier:isinstance; 75, argument_list; 75, 76; 75, 77; 76, identifier:audiences; 77, identifier:_Mapping; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:audiences; 82, subscript; 82, 83; 82, 84; 83, identifier:audiences; 84, identifier:issuer_key; 85, if_statement; 85, 86; 85, 101; 86, call; 86, 87; 86, 88; 87, identifier:_verify_parsed_token; 88, argument_list; 88, 89; 88, 90; 88, 91; 88, 92; 88, 93; 89, identifier:parsed_token; 90, identifier:issuer_values; 91, identifier:audiences; 92, identifier:allowed_client_ids; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:is_legacy_google_auth; 95, parenthesized_expression; 95, 96; 96, comparison_operator:==; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:issuer; 99, identifier:issuer; 100, identifier:_ISSUERS; 101, block; 101, 102; 101, 108; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:email; 105, subscript; 105, 106; 105, 107; 106, identifier:parsed_token; 107, string:'email'; 108, return_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:users; 112, identifier:User; 113, argument_list; 113, 114; 114, identifier:email | def _get_id_token_user(token, issuers, audiences, allowed_client_ids, time_now, cache):
for issuer_key, issuer in issuers.items():
issuer_cert_uri = convert_jwks_uri(issuer.jwks_uri)
try:
parsed_token = _verify_signed_jwt_with_certs(
token, time_now, cache, cert_uri=issuer_cert_uri)
except Exception:
_logger.debug(
'id_token verification failed for issuer %s', issuer_key, exc_info=True)
continue
issuer_values = _listlike_guard(issuer.issuer, 'issuer', log_warning=False)
if isinstance(audiences, _Mapping):
audiences = audiences[issuer_key]
if _verify_parsed_token(
parsed_token, issuer_values, audiences, allowed_client_ids,
is_legacy_google_auth=(issuer.issuer == _ISSUERS)):
email = parsed_token['email']
return users.User(email) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_verify_parsed_token; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:parsed_token; 5, identifier:issuers; 6, identifier:audiences; 7, identifier:allowed_client_ids; 8, default_parameter; 8, 9; 8, 10; 9, identifier:is_legacy_google_auth; 10, True; 11, block; 11, 12; 11, 37; 11, 46; 11, 59; 11, 68; 11, 82; 11, 96; 11, 136; 11, 143; 12, if_statement; 12, 13; 12, 21; 13, comparison_operator:not; 13, 14; 13, 20; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:parsed_token; 17, identifier:get; 18, argument_list; 18, 19; 19, string:'iss'; 20, identifier:issuers; 21, block; 21, 22; 21, 35; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:_logger; 26, identifier:warning; 27, argument_list; 27, 28; 27, 29; 28, string:'Issuer was not valid: %s'; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:parsed_token; 32, identifier:get; 33, argument_list; 33, 34; 34, string:'iss'; 35, return_statement; 35, 36; 36, False; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:aud; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:parsed_token; 43, identifier:get; 44, argument_list; 44, 45; 45, string:'aud'; 46, if_statement; 46, 47; 46, 49; 47, not_operator; 47, 48; 48, identifier:aud; 49, block; 49, 50; 49, 57; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:_logger; 54, identifier:warning; 55, argument_list; 55, 56; 56, string:'No aud field in token'; 57, return_statement; 57, 58; 58, False; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:cid; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:parsed_token; 65, identifier:get; 66, argument_list; 66, 67; 67, string:'azp'; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:audience_allowed; 71, boolean_operator:or; 71, 72; 71, 76; 72, parenthesized_expression; 72, 73; 73, comparison_operator:in; 73, 74; 73, 75; 74, identifier:aud; 75, identifier:audiences; 76, parenthesized_expression; 76, 77; 77, boolean_operator:and; 77, 78; 77, 79; 78, identifier:is_legacy_google_auth; 79, comparison_operator:==; 79, 80; 79, 81; 80, identifier:aud; 81, identifier:cid; 82, if_statement; 82, 83; 82, 85; 83, not_operator; 83, 84; 84, identifier:audience_allowed; 85, block; 85, 86; 85, 94; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:_logger; 90, identifier:warning; 91, argument_list; 91, 92; 91, 93; 92, string:'Audience not allowed: %s'; 93, identifier:aud; 94, return_statement; 94, 95; 95, False; 96, if_statement; 96, 97; 96, 98; 97, identifier:is_legacy_google_auth; 98, block; 98, 99; 99, if_statement; 99, 100; 99, 106; 99, 118; 100, comparison_operator:==; 100, 101; 100, 105; 101, call; 101, 102; 101, 103; 102, identifier:list; 103, argument_list; 103, 104; 104, identifier:allowed_client_ids; 105, identifier:SKIP_CLIENT_ID_CHECK; 106, block; 106, 107; 106, 116; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:_logger; 111, identifier:warning; 112, argument_list; 112, 113; 113, concatenated_string; 113, 114; 113, 115; 114, string:'Client ID check can\'t be skipped for ID tokens. '; 115, string:'Id_token cannot be verified.'; 116, return_statement; 116, 117; 117, False; 118, elif_clause; 118, 119; 118, 125; 119, boolean_operator:or; 119, 120; 119, 122; 120, not_operator; 120, 121; 121, identifier:cid; 122, comparison_operator:not; 122, 123; 122, 124; 123, identifier:cid; 124, identifier:allowed_client_ids; 125, block; 125, 126; 125, 134; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:_logger; 130, identifier:warning; 131, argument_list; 131, 132; 131, 133; 132, string:'Client ID is not allowed: %s'; 133, identifier:cid; 134, return_statement; 134, 135; 135, False; 136, if_statement; 136, 137; 136, 140; 137, comparison_operator:not; 137, 138; 137, 139; 138, string:'email'; 139, identifier:parsed_token; 140, block; 140, 141; 141, return_statement; 141, 142; 142, False; 143, return_statement; 143, 144; 144, True | def _verify_parsed_token(parsed_token, issuers, audiences, allowed_client_ids, is_legacy_google_auth=True):
if parsed_token.get('iss') not in issuers:
_logger.warning('Issuer was not valid: %s', parsed_token.get('iss'))
return False
aud = parsed_token.get('aud')
if not aud:
_logger.warning('No aud field in token')
return False
cid = parsed_token.get('azp')
audience_allowed = (aud in audiences) or (is_legacy_google_auth and aud == cid)
if not audience_allowed:
_logger.warning('Audience not allowed: %s', aud)
return False
if is_legacy_google_auth:
if list(allowed_client_ids) == SKIP_CLIENT_ID_CHECK:
_logger.warning('Client ID check can\'t be skipped for ID tokens. '
'Id_token cannot be verified.')
return False
elif not cid or cid not in allowed_client_ids:
_logger.warning('Client ID is not allowed: %s', cid)
return False
if 'email' not in parsed_token:
return False
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_verify_signed_jwt_with_certs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:jwt; 5, identifier:time_now; 6, identifier:cache; 7, default_parameter; 7, 8; 7, 9; 8, identifier:cert_uri; 9, identifier:_DEFAULT_CERT_URI; 10, block; 10, 11; 10, 20; 10, 35; 10, 47; 10, 56; 10, 69; 10, 78; 10, 96; 10, 118; 10, 126; 10, 136; 10, 148; 10, 161; 10, 165; 10, 252; 10, 261; 10, 270; 10, 288; 10, 297; 10, 307; 10, 313; 10, 322; 10, 332; 10, 344; 10, 350; 10, 364; 10, 378; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:segments; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:jwt; 17, identifier:split; 18, argument_list; 18, 19; 19, string:'.'; 20, if_statement; 20, 21; 20, 27; 21, comparison_operator:!=; 21, 22; 21, 26; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, identifier:segments; 26, integer:3; 27, block; 27, 28; 28, raise_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:_AppIdentityError; 31, argument_list; 31, 32; 32, concatenated_string; 32, 33; 32, 34; 33, string:'Token is not an id_token (Wrong number of '; 34, string:'segments)'; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:signed; 38, binary_operator:%; 38, 39; 38, 40; 39, string:'%s.%s'; 40, tuple; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:segments; 43, integer:0; 44, subscript; 44, 45; 44, 46; 45, identifier:segments; 46, integer:1; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:signature; 50, call; 50, 51; 50, 52; 51, identifier:_urlsafe_b64decode; 52, argument_list; 52, 53; 53, subscript; 53, 54; 53, 55; 54, identifier:segments; 55, integer:2; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:lsignature; 59, call; 59, 60; 59, 61; 60, identifier:long; 61, argument_list; 61, 62; 61, 68; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:signature; 65, identifier:encode; 66, argument_list; 66, 67; 67, string:'hex'; 68, integer:16; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:header_body; 72, call; 72, 73; 72, 74; 73, identifier:_urlsafe_b64decode; 74, argument_list; 74, 75; 75, subscript; 75, 76; 75, 77; 76, identifier:segments; 77, integer:0; 78, try_statement; 78, 79; 78, 89; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:header; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:json; 86, identifier:loads; 87, argument_list; 87, 88; 88, identifier:header_body; 89, except_clause; 89, 90; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:_AppIdentityError; 94, argument_list; 94, 95; 95, string:"Can't parse header"; 96, if_statement; 96, 97; 96, 105; 97, comparison_operator:!=; 97, 98; 97, 104; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:header; 101, identifier:get; 102, argument_list; 102, 103; 103, string:'alg'; 104, string:'RS256'; 105, block; 105, 106; 106, raise_statement; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:_AppIdentityError; 109, argument_list; 109, 110; 110, binary_operator:%; 110, 111; 110, 112; 111, string:'Unexpected encryption algorithm: %r'; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:header; 115, identifier:get; 116, argument_list; 116, 117; 117, string:'alg'; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:certs; 121, call; 121, 122; 121, 123; 122, identifier:_get_cached_certs; 123, argument_list; 123, 124; 123, 125; 124, identifier:cert_uri; 125, identifier:cache; 126, if_statement; 126, 127; 126, 130; 127, comparison_operator:is; 127, 128; 127, 129; 128, identifier:certs; 129, None; 130, block; 130, 131; 131, raise_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:_AppIdentityError; 134, argument_list; 134, 135; 135, string:'Unable to retrieve certs needed to verify the signed JWT'; 136, if_statement; 136, 137; 136, 139; 137, not_operator; 137, 138; 138, identifier:_CRYPTO_LOADED; 139, block; 139, 140; 140, raise_statement; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:_AppIdentityError; 143, argument_list; 143, 144; 144, concatenated_string; 144, 145; 144, 146; 144, 147; 145, string:'Unable to load pycrypto library. Can\'t verify '; 146, string:'id_token signature. See http://www.pycrypto.org '; 147, string:'for more information on pycrypto.'; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:local_hash; 151, call; 151, 152; 151, 160; 152, attribute; 152, 153; 152, 159; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:SHA256; 156, identifier:new; 157, argument_list; 157, 158; 158, identifier:signed; 159, identifier:hexdigest; 160, argument_list; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:verified; 164, False; 165, for_statement; 165, 166; 165, 167; 165, 170; 166, identifier:keyvalue; 167, subscript; 167, 168; 167, 169; 168, identifier:certs; 169, string:'keyvalues'; 170, block; 170, 171; 171, try_statement; 171, 172; 171, 239; 172, block; 172, 173; 172, 182; 172, 191; 172, 202; 172, 216; 172, 225; 172, 235; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:modulus; 176, call; 176, 177; 176, 178; 177, identifier:_b64_to_long; 178, argument_list; 178, 179; 179, subscript; 179, 180; 179, 181; 180, identifier:keyvalue; 181, string:'modulus'; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:exponent; 185, call; 185, 186; 185, 187; 186, identifier:_b64_to_long; 187, argument_list; 187, 188; 188, subscript; 188, 189; 188, 190; 189, identifier:keyvalue; 190, string:'exponent'; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:key; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:RSA; 197, identifier:construct; 198, argument_list; 198, 199; 199, tuple; 199, 200; 199, 201; 200, identifier:modulus; 201, identifier:exponent; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:hexsig; 205, binary_operator:%; 205, 206; 205, 207; 206, string:'%064x'; 207, subscript; 207, 208; 207, 215; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:key; 211, identifier:encrypt; 212, argument_list; 212, 213; 212, 214; 213, identifier:lsignature; 214, string:''; 215, integer:0; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:hexsig; 219, subscript; 219, 220; 219, 221; 220, identifier:hexsig; 221, slice; 221, 222; 221, 224; 222, unary_operator:-; 222, 223; 223, integer:64; 224, colon; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:verified; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:hmac; 231, identifier:compare_digest; 232, argument_list; 232, 233; 232, 234; 233, identifier:hexsig; 234, identifier:local_hash; 235, if_statement; 235, 236; 235, 237; 236, identifier:verified; 237, block; 237, 238; 238, break_statement; 239, except_clause; 239, 240; 239, 241; 239, 242; 240, identifier:Exception; 241, identifier:e; 242, block; 242, 243; 242, 251; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:_logger; 247, identifier:debug; 248, argument_list; 248, 249; 248, 250; 249, string:'Signature verification error: %s; continuing with the next cert.'; 250, identifier:e; 251, continue_statement; 252, if_statement; 252, 253; 252, 255; 253, not_operator; 253, 254; 254, identifier:verified; 255, block; 255, 256; 256, raise_statement; 256, 257; 257, call; 257, 258; 257, 259; 258, identifier:_AppIdentityError; 259, argument_list; 259, 260; 260, string:'Invalid token signature'; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:json_body; 264, call; 264, 265; 264, 266; 265, identifier:_urlsafe_b64decode; 266, argument_list; 266, 267; 267, subscript; 267, 268; 267, 269; 268, identifier:segments; 269, integer:1; 270, try_statement; 270, 271; 270, 281; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:parsed; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:json; 278, identifier:loads; 279, argument_list; 279, 280; 280, identifier:json_body; 281, except_clause; 281, 282; 282, block; 282, 283; 283, raise_statement; 283, 284; 284, call; 284, 285; 284, 286; 285, identifier:_AppIdentityError; 286, argument_list; 286, 287; 287, string:"Can't parse token body"; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:iat; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:parsed; 294, identifier:get; 295, argument_list; 295, 296; 296, string:'iat'; 297, if_statement; 297, 298; 297, 301; 298, comparison_operator:is; 298, 299; 298, 300; 299, identifier:iat; 300, None; 301, block; 301, 302; 302, raise_statement; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:_AppIdentityError; 305, argument_list; 305, 306; 306, string:'No iat field in token'; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:earliest; 310, binary_operator:-; 310, 311; 310, 312; 311, identifier:iat; 312, identifier:_CLOCK_SKEW_SECS; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:exp; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:parsed; 319, identifier:get; 320, argument_list; 320, 321; 321, string:'exp'; 322, if_statement; 322, 323; 322, 326; 323, comparison_operator:is; 323, 324; 323, 325; 324, identifier:exp; 325, None; 326, block; 326, 327; 327, raise_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:_AppIdentityError; 330, argument_list; 330, 331; 331, string:'No exp field in token'; 332, if_statement; 332, 333; 332, 338; 333, comparison_operator:>=; 333, 334; 333, 335; 334, identifier:exp; 335, binary_operator:+; 335, 336; 335, 337; 336, identifier:time_now; 337, identifier:_MAX_TOKEN_LIFETIME_SECS; 338, block; 338, 339; 339, raise_statement; 339, 340; 340, call; 340, 341; 340, 342; 341, identifier:_AppIdentityError; 342, argument_list; 342, 343; 343, string:'exp field too far in future'; 344, expression_statement; 344, 345; 345, assignment; 345, 346; 345, 347; 346, identifier:latest; 347, binary_operator:+; 347, 348; 347, 349; 348, identifier:exp; 349, identifier:_CLOCK_SKEW_SECS; 350, if_statement; 350, 351; 350, 354; 351, comparison_operator:<; 351, 352; 351, 353; 352, identifier:time_now; 353, identifier:earliest; 354, block; 354, 355; 355, raise_statement; 355, 356; 356, call; 356, 357; 356, 358; 357, identifier:_AppIdentityError; 358, argument_list; 358, 359; 359, binary_operator:%; 359, 360; 359, 361; 360, string:'Token used too early, %d < %d'; 361, tuple; 361, 362; 361, 363; 362, identifier:time_now; 363, identifier:earliest; 364, if_statement; 364, 365; 364, 368; 365, comparison_operator:>; 365, 366; 365, 367; 366, identifier:time_now; 367, identifier:latest; 368, block; 368, 369; 369, raise_statement; 369, 370; 370, call; 370, 371; 370, 372; 371, identifier:_AppIdentityError; 372, argument_list; 372, 373; 373, binary_operator:%; 373, 374; 373, 375; 374, string:'Token used too late, %d > %d'; 375, tuple; 375, 376; 375, 377; 376, identifier:time_now; 377, identifier:latest; 378, return_statement; 378, 379; 379, identifier:parsed | def _verify_signed_jwt_with_certs(
jwt, time_now, cache,
cert_uri=_DEFAULT_CERT_URI):
segments = jwt.split('.')
if len(segments) != 3:
raise _AppIdentityError('Token is not an id_token (Wrong number of '
'segments)')
signed = '%s.%s' % (segments[0], segments[1])
signature = _urlsafe_b64decode(segments[2])
lsignature = long(signature.encode('hex'), 16)
header_body = _urlsafe_b64decode(segments[0])
try:
header = json.loads(header_body)
except:
raise _AppIdentityError("Can't parse header")
if header.get('alg') != 'RS256':
raise _AppIdentityError('Unexpected encryption algorithm: %r' %
header.get('alg'))
certs = _get_cached_certs(cert_uri, cache)
if certs is None:
raise _AppIdentityError(
'Unable to retrieve certs needed to verify the signed JWT')
if not _CRYPTO_LOADED:
raise _AppIdentityError('Unable to load pycrypto library. Can\'t verify '
'id_token signature. See http://www.pycrypto.org '
'for more information on pycrypto.')
local_hash = SHA256.new(signed).hexdigest()
verified = False
for keyvalue in certs['keyvalues']:
try:
modulus = _b64_to_long(keyvalue['modulus'])
exponent = _b64_to_long(keyvalue['exponent'])
key = RSA.construct((modulus, exponent))
hexsig = '%064x' % key.encrypt(lsignature, '')[0]
hexsig = hexsig[-64:]
verified = hmac.compare_digest(hexsig, local_hash)
if verified:
break
except Exception, e:
_logger.debug(
'Signature verification error: %s; continuing with the next cert.', e)
continue
if not verified:
raise _AppIdentityError('Invalid token signature')
json_body = _urlsafe_b64decode(segments[1])
try:
parsed = json.loads(json_body)
except:
raise _AppIdentityError("Can't parse token body")
iat = parsed.get('iat')
if iat is None:
raise _AppIdentityError('No iat field in token')
earliest = iat - _CLOCK_SKEW_SECS
exp = parsed.get('exp')
if exp is None:
raise _AppIdentityError('No exp field in token')
if exp >= time_now + _MAX_TOKEN_LIFETIME_SECS:
raise _AppIdentityError('exp field too far in future')
latest = exp + _CLOCK_SKEW_SECS
if time_now < earliest:
raise _AppIdentityError('Token used too early, %d < %d' %
(time_now, earliest))
if time_now > latest:
raise _AppIdentityError('Token used too late, %d > %d' %
(time_now, latest))
return parsed |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_sorted_methods; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:methods; 6, block; 6, 7; 6, 13; 6, 166; 7, if_statement; 7, 8; 7, 10; 8, not_operator; 8, 9; 9, identifier:methods; 10, block; 10, 11; 11, return_statement; 11, 12; 12, identifier:methods; 13, function_definition; 13, 14; 13, 15; 13, 18; 14, function_name:_sorted_methods_comparison; 15, parameters; 15, 16; 15, 17; 16, identifier:method_info1; 17, identifier:method_info2; 18, block; 18, 19; 18, 70; 18, 85; 18, 100; 18, 109; 18, 133; 18, 140; 18, 164; 19, function_definition; 19, 20; 19, 21; 19, 23; 20, function_name:_score_path; 21, parameters; 21, 22; 22, identifier:path; 23, block; 23, 24; 23, 28; 23, 37; 23, 59; 23, 68; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:score; 27, integer:0; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:parts; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:path; 34, identifier:split; 35, argument_list; 35, 36; 36, string:'/'; 37, for_statement; 37, 38; 37, 39; 37, 40; 38, identifier:part; 39, identifier:parts; 40, block; 40, 41; 40, 45; 41, expression_statement; 41, 42; 42, augmented_assignment:<<=; 42, 43; 42, 44; 43, identifier:score; 44, integer:1; 45, if_statement; 45, 46; 45, 54; 46, boolean_operator:or; 46, 47; 46, 49; 47, not_operator; 47, 48; 48, identifier:part; 49, comparison_operator:!=; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:part; 52, integer:0; 53, string:'{'; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, augmented_assignment:+=; 56, 57; 56, 58; 57, identifier:score; 58, integer:1; 59, expression_statement; 59, 60; 60, augmented_assignment:<<=; 60, 61; 60, 62; 61, identifier:score; 62, binary_operator:-; 62, 63; 62, 64; 63, integer:31; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, identifier:parts; 68, return_statement; 68, 69; 69, identifier:score; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:path_score1; 73, call; 73, 74; 73, 75; 74, identifier:_score_path; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, subscript; 78, 79; 78, 80; 79, identifier:method_info1; 80, integer:1; 81, identifier:get; 82, argument_list; 82, 83; 82, 84; 83, string:'path'; 84, string:''; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:path_score2; 88, call; 88, 89; 88, 90; 89, identifier:_score_path; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:method_info2; 95, integer:1; 96, identifier:get; 97, argument_list; 97, 98; 97, 99; 98, string:'path'; 99, string:''; 100, if_statement; 100, 101; 100, 104; 101, comparison_operator:!=; 101, 102; 101, 103; 102, identifier:path_score1; 103, identifier:path_score2; 104, block; 104, 105; 105, return_statement; 105, 106; 106, binary_operator:-; 106, 107; 106, 108; 107, identifier:path_score2; 108, identifier:path_score1; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:path_result; 112, call; 112, 113; 112, 114; 113, identifier:cmp; 114, argument_list; 114, 115; 114, 124; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:method_info1; 119, integer:1; 120, identifier:get; 121, argument_list; 121, 122; 121, 123; 122, string:'path'; 123, string:''; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:method_info2; 128, integer:1; 129, identifier:get; 130, argument_list; 130, 131; 130, 132; 131, string:'path'; 132, string:''; 133, if_statement; 133, 134; 133, 137; 134, comparison_operator:!=; 134, 135; 134, 136; 135, identifier:path_result; 136, integer:0; 137, block; 137, 138; 138, return_statement; 138, 139; 139, identifier:path_result; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:method_result; 143, call; 143, 144; 143, 145; 144, identifier:cmp; 145, argument_list; 145, 146; 145, 155; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:method_info1; 150, integer:1; 151, identifier:get; 152, argument_list; 152, 153; 152, 154; 153, string:'httpMethod'; 154, string:''; 155, call; 155, 156; 155, 161; 156, attribute; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:method_info2; 159, integer:1; 160, identifier:get; 161, argument_list; 161, 162; 161, 163; 162, string:'httpMethod'; 163, string:''; 164, return_statement; 164, 165; 165, identifier:method_result; 166, return_statement; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:sorted; 169, argument_list; 169, 170; 169, 175; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:methods; 173, identifier:items; 174, argument_list; 175, identifier:_sorted_methods_comparison | def _get_sorted_methods(self, methods):
if not methods:
return methods
def _sorted_methods_comparison(method_info1, method_info2):
def _score_path(path):
score = 0
parts = path.split('/')
for part in parts:
score <<= 1
if not part or part[0] != '{':
score += 1
score <<= 31 - len(parts)
return score
path_score1 = _score_path(method_info1[1].get('path', ''))
path_score2 = _score_path(method_info2[1].get('path', ''))
if path_score1 != path_score2:
return path_score2 - path_score1
path_result = cmp(method_info1[1].get('path', ''),
method_info2[1].get('path', ''))
if path_result != 0:
return path_result
method_result = cmp(method_info1[1].get('httpMethod', ''),
method_info2[1].get('httpMethod', ''))
return method_result
return sorted(methods.items(), _sorted_methods_comparison) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:api_server; 3, parameters; 3, 4; 3, 5; 4, identifier:api_services; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 18; 7, 25; 7, 32; 7, 40; 7, 49; 7, 58; 7, 69; 7, 86; 7, 102; 7, 109; 7, 116; 7, 124; 7, 137; 7, 143; 7, 149; 8, if_statement; 8, 9; 8, 12; 9, comparison_operator:in; 9, 10; 9, 11; 10, string:'protocols'; 11, identifier:kwargs; 12, block; 12, 13; 13, raise_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:TypeError; 16, argument_list; 16, 17; 17, string:"__init__() got an unexpected keyword argument 'protocols'"; 18, import_from_statement; 18, 19; 18, 21; 19, relative_import; 19, 20; 20, import_prefix; 21, aliased_import; 21, 22; 21, 24; 22, dotted_name; 22, 23; 23, identifier:_logger; 24, identifier:endpoints_logger; 25, import_from_statement; 25, 26; 25, 28; 26, relative_import; 26, 27; 27, import_prefix; 28, aliased_import; 28, 29; 28, 31; 29, dotted_name; 29, 30; 30, identifier:__version__; 31, identifier:endpoints_version; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:endpoints_logger; 36, identifier:info; 37, argument_list; 37, 38; 37, 39; 38, string:'Initializing Endpoints Framework version %s'; 39, identifier:endpoints_version; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:apis_app; 43, call; 43, 44; 43, 45; 44, identifier:_ApiServer; 45, argument_list; 45, 46; 45, 47; 46, identifier:api_services; 47, dictionary_splat; 47, 48; 48, identifier:kwargs; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:dispatcher; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:endpoints_dispatcher; 55, identifier:EndpointsDispatcherMiddleware; 56, argument_list; 56, 57; 57, identifier:apis_app; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:service_name; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:os; 65, identifier:environ; 66, identifier:get; 67, argument_list; 67, 68; 68, string:'ENDPOINTS_SERVICE_NAME'; 69, if_statement; 69, 70; 69, 72; 70, not_operator; 70, 71; 71, identifier:service_name; 72, block; 72, 73; 72, 84; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:_logger; 77, identifier:warn; 78, argument_list; 78, 79; 79, concatenated_string; 79, 80; 79, 81; 79, 82; 79, 83; 80, string:'Did not specify the ENDPOINTS_SERVICE_NAME environment'; 81, string:' variable so service control is disabled. Please specify'; 82, string:' the name of service in ENDPOINTS_SERVICE_NAME to enable'; 83, string:' it.'; 84, return_statement; 84, 85; 85, identifier:dispatcher; 86, if_statement; 86, 87; 86, 92; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:control_wsgi; 90, identifier:running_on_devserver; 91, argument_list; 92, block; 92, 93; 92, 100; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:_logger; 97, identifier:warn; 98, argument_list; 98, 99; 99, string:'Running on local devserver, so service control is disabled.'; 100, return_statement; 100, 101; 101, identifier:dispatcher; 102, import_from_statement; 102, 103; 102, 105; 103, dotted_name; 103, 104; 104, identifier:endpoints_management; 105, aliased_import; 105, 106; 105, 108; 106, dotted_name; 106, 107; 107, identifier:_logger; 108, identifier:management_logger; 109, import_from_statement; 109, 110; 109, 112; 110, dotted_name; 110, 111; 111, identifier:endpoints_management; 112, aliased_import; 112, 113; 112, 115; 113, dotted_name; 113, 114; 114, identifier:__version__; 115, identifier:management_version; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:management_logger; 120, identifier:info; 121, argument_list; 121, 122; 121, 123; 122, string:'Initializing Endpoints Management Framework version %s'; 123, identifier:management_version; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:controller; 127, call; 127, 128; 127, 135; 128, attribute; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:control_client; 132, identifier:Loaders; 133, identifier:DEFAULT; 134, identifier:load; 135, argument_list; 135, 136; 136, identifier:service_name; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:control_client; 141, identifier:use_gae_thread; 142, argument_list; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:controller; 147, identifier:start; 148, argument_list; 149, return_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:control_wsgi; 153, identifier:add_all; 154, argument_list; 154, 155; 154, 156; 154, 161; 155, identifier:dispatcher; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:app_identity; 159, identifier:get_application_id; 160, argument_list; 161, identifier:controller | def api_server(api_services, **kwargs):
if 'protocols' in kwargs:
raise TypeError("__init__() got an unexpected keyword argument 'protocols'")
from . import _logger as endpoints_logger
from . import __version__ as endpoints_version
endpoints_logger.info('Initializing Endpoints Framework version %s', endpoints_version)
apis_app = _ApiServer(api_services, **kwargs)
dispatcher = endpoints_dispatcher.EndpointsDispatcherMiddleware(apis_app)
service_name = os.environ.get('ENDPOINTS_SERVICE_NAME')
if not service_name:
_logger.warn('Did not specify the ENDPOINTS_SERVICE_NAME environment'
' variable so service control is disabled. Please specify'
' the name of service in ENDPOINTS_SERVICE_NAME to enable'
' it.')
return dispatcher
if control_wsgi.running_on_devserver():
_logger.warn('Running on local devserver, so service control is disabled.')
return dispatcher
from endpoints_management import _logger as management_logger
from endpoints_management import __version__ as management_version
management_logger.info('Initializing Endpoints Management Framework version %s', management_version)
controller = control_client.Loaders.DEFAULT.load(service_name)
control_client.use_gae_thread()
controller.start()
return control_wsgi.add_all(
dispatcher,
app_identity.get_application_id(),
controller) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__register_services; 3, parameters; 3, 4; 3, 5; 4, identifier:api_name_version_map; 5, identifier:api_config_registry; 6, block; 6, 7; 6, 15; 6, 19; 6, 116; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:generator; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:api_config; 13, identifier:ApiConfigGenerator; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:protorpc_services; 18, list:[]; 19, for_statement; 19, 20; 19, 21; 19, 26; 20, identifier:service_factories; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:api_name_version_map; 24, identifier:itervalues; 25, argument_list; 26, block; 26, 27; 26, 37; 26, 46; 26, 53; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:service_classes; 30, list_comprehension; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:service_factory; 33, identifier:service_class; 34, for_in_clause; 34, 35; 34, 36; 35, identifier:service_factory; 36, identifier:service_factories; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:config_dict; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:generator; 43, identifier:get_config_dict; 44, argument_list; 44, 45; 45, identifier:service_classes; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:api_config_registry; 50, identifier:register_backend; 51, argument_list; 51, 52; 52, identifier:config_dict; 53, for_statement; 53, 54; 53, 55; 53, 56; 54, identifier:service_factory; 55, identifier:service_factories; 56, block; 56, 57; 56, 65; 56, 79; 56, 107; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:protorpc_class_name; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:service_factory; 63, identifier:service_class; 64, identifier:__name__; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:root; 68, binary_operator:%; 68, 69; 68, 70; 69, string:'%s%s'; 70, tuple; 70, 71; 70, 78; 71, attribute; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:service_factory; 75, identifier:service_class; 76, identifier:api_info; 77, identifier:base_path; 78, identifier:protorpc_class_name; 79, if_statement; 79, 80; 79, 97; 80, call; 80, 81; 80, 82; 81, identifier:any; 82, generator_expression; 82, 83; 82, 94; 83, boolean_operator:or; 83, 84; 83, 89; 84, comparison_operator:==; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:service_map; 87, integer:0; 88, identifier:root; 89, comparison_operator:==; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:service_map; 92, integer:1; 93, identifier:service_factory; 94, for_in_clause; 94, 95; 94, 96; 95, identifier:service_map; 96, identifier:protorpc_services; 97, block; 97, 98; 98, raise_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:api_config; 102, identifier:ApiConfigurationError; 103, argument_list; 103, 104; 104, binary_operator:%; 104, 105; 104, 106; 105, string:'Can\'t reuse the same class in multiple APIs: %s'; 106, identifier:protorpc_class_name; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:protorpc_services; 111, identifier:append; 112, argument_list; 112, 113; 113, tuple; 113, 114; 113, 115; 114, identifier:root; 115, identifier:service_factory; 116, return_statement; 116, 117; 117, identifier:protorpc_services | def __register_services(api_name_version_map, api_config_registry):
generator = api_config.ApiConfigGenerator()
protorpc_services = []
for service_factories in api_name_version_map.itervalues():
service_classes = [service_factory.service_class
for service_factory in service_factories]
config_dict = generator.get_config_dict(service_classes)
api_config_registry.register_backend(config_dict)
for service_factory in service_factories:
protorpc_class_name = service_factory.service_class.__name__
root = '%s%s' % (service_factory.service_class.api_info.base_path,
protorpc_class_name)
if any(service_map[0] == root or service_map[1] == service_factory
for service_map in protorpc_services):
raise api_config.ApiConfigurationError(
'Can\'t reuse the same class in multiple APIs: %s' %
protorpc_class_name)
protorpc_services.append((root, service_factory))
return protorpc_services |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:transform_rest_request; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:orig_request; 6, identifier:params; 7, identifier:method_parameters; 8, block; 8, 9; 8, 17; 8, 21; 8, 38; 8, 78; 8, 155; 8, 170; 8, 176; 8, 189; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:request; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:orig_request; 15, identifier:copy; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:body_json; 20, dictionary; 21, for_statement; 21, 22; 21, 25; 21, 30; 22, pattern_list; 22, 23; 22, 24; 23, identifier:key; 24, identifier:value; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:params; 28, identifier:iteritems; 29, argument_list; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:body_json; 35, identifier:key; 36, list:[value]; 36, 37; 37, identifier:value; 38, if_statement; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:request; 41, identifier:parameters; 42, block; 42, 43; 43, for_statement; 43, 44; 43, 47; 43, 54; 44, pattern_list; 44, 45; 44, 46; 45, identifier:key; 46, identifier:value; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:request; 51, identifier:parameters; 52, identifier:iteritems; 53, argument_list; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 59; 55, 70; 56, comparison_operator:in; 56, 57; 56, 58; 57, identifier:key; 58, identifier:body_json; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:body_json; 64, identifier:key; 65, binary_operator:+; 65, 66; 65, 67; 66, identifier:value; 67, subscript; 67, 68; 67, 69; 68, identifier:body_json; 69, identifier:key; 70, else_clause; 70, 71; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:body_json; 76, identifier:key; 77, identifier:value; 78, for_statement; 78, 79; 78, 82; 78, 87; 79, pattern_list; 79, 80; 79, 81; 80, identifier:key; 81, identifier:value; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:body_json; 85, identifier:items; 86, argument_list; 87, block; 87, 88; 87, 98; 87, 108; 87, 122; 87, 137; 87, 146; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:current_parameter; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:method_parameters; 94, identifier:get; 95, argument_list; 95, 96; 95, 97; 96, identifier:key; 97, dictionary; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:repeated; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:current_parameter; 104, identifier:get; 105, argument_list; 105, 106; 105, 107; 106, string:'repeated'; 107, False; 108, if_statement; 108, 109; 108, 111; 109, not_operator; 109, 110; 110, identifier:repeated; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:body_json; 116, identifier:key; 117, subscript; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:body_json; 120, identifier:key; 121, integer:0; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:body_json; 126, identifier:key; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:parameter_converter; 130, identifier:transform_parameter_value; 131, argument_list; 131, 132; 131, 133; 131, 136; 132, identifier:key; 133, subscript; 133, 134; 133, 135; 134, identifier:body_json; 135, identifier:key; 136, identifier:current_parameter; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:message_value; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:body_json; 143, identifier:pop; 144, argument_list; 144, 145; 145, identifier:key; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:_add_message_field; 151, argument_list; 151, 152; 151, 153; 151, 154; 152, identifier:key; 153, identifier:message_value; 154, identifier:body_json; 155, if_statement; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:request; 158, identifier:body_json; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:_update_from_body; 165, argument_list; 165, 166; 165, 167; 166, identifier:body_json; 167, attribute; 167, 168; 167, 169; 168, identifier:request; 169, identifier:body_json; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:request; 174, identifier:body_json; 175, identifier:body_json; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:request; 180, identifier:body; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:json; 184, identifier:dumps; 185, argument_list; 185, 186; 186, attribute; 186, 187; 186, 188; 187, identifier:request; 188, identifier:body_json; 189, return_statement; 189, 190; 190, identifier:request | def transform_rest_request(self, orig_request, params, method_parameters):
request = orig_request.copy()
body_json = {}
for key, value in params.iteritems():
body_json[key] = [value]
if request.parameters:
for key, value in request.parameters.iteritems():
if key in body_json:
body_json[key] = value + body_json[key]
else:
body_json[key] = value
for key, value in body_json.items():
current_parameter = method_parameters.get(key, {})
repeated = current_parameter.get('repeated', False)
if not repeated:
body_json[key] = body_json[key][0]
body_json[key] = parameter_converter.transform_parameter_value(
key, body_json[key], current_parameter)
message_value = body_json.pop(key)
self._add_message_field(key, message_value, body_json)
if request.body_json:
self._update_from_body(body_json, request.body_json)
request.body_json = body_json
request.body = json.dumps(request.body_json)
return request |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 66; 2, function_name:api; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 3, 39; 3, 42; 3, 45; 3, 48; 3, 51; 3, 54; 3, 57; 3, 60; 3, 63; 4, identifier:name; 5, identifier:version; 6, default_parameter; 6, 7; 6, 8; 7, identifier:description; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:hostname; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:audiences; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:scopes; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:allowed_client_ids; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:canonical_name; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:auth; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:owner_domain; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:owner_name; 32, None; 33, default_parameter; 33, 34; 33, 35; 34, identifier:package_path; 35, None; 36, default_parameter; 36, 37; 36, 38; 37, identifier:frontend_limits; 38, None; 39, default_parameter; 39, 40; 39, 41; 40, identifier:title; 41, None; 42, default_parameter; 42, 43; 42, 44; 43, identifier:documentation; 44, None; 45, default_parameter; 45, 46; 45, 47; 46, identifier:auth_level; 47, None; 48, default_parameter; 48, 49; 48, 50; 49, identifier:issuers; 50, None; 51, default_parameter; 51, 52; 51, 53; 52, identifier:namespace; 53, None; 54, default_parameter; 54, 55; 54, 56; 55, identifier:api_key_required; 56, None; 57, default_parameter; 57, 58; 57, 59; 58, identifier:base_path; 59, None; 60, default_parameter; 60, 61; 60, 62; 61, identifier:limit_definitions; 62, None; 63, default_parameter; 63, 64; 63, 65; 64, identifier:use_request_uri; 65, None; 66, block; 66, 67; 66, 79; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:is; 68, 69; 68, 70; 69, identifier:auth_level; 70, None; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:_logger; 76, identifier:warn; 77, argument_list; 77, 78; 78, identifier:_AUTH_LEVEL_WARNING; 79, return_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:_ApiDecorator; 82, argument_list; 82, 83; 82, 84; 82, 85; 82, 88; 82, 91; 82, 94; 82, 97; 82, 100; 82, 103; 82, 106; 82, 109; 82, 112; 82, 115; 82, 118; 82, 121; 82, 124; 82, 127; 82, 130; 82, 133; 82, 136; 82, 139; 82, 142; 83, identifier:name; 84, identifier:version; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:description; 87, identifier:description; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:hostname; 90, identifier:hostname; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:audiences; 93, identifier:audiences; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:scopes; 96, identifier:scopes; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:allowed_client_ids; 99, identifier:allowed_client_ids; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:canonical_name; 102, identifier:canonical_name; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:auth; 105, identifier:auth; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:owner_domain; 108, identifier:owner_domain; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:owner_name; 111, identifier:owner_name; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:package_path; 114, identifier:package_path; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:frontend_limits; 117, identifier:frontend_limits; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:title; 120, identifier:title; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:documentation; 123, identifier:documentation; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:auth_level; 126, identifier:auth_level; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:issuers; 129, identifier:issuers; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:namespace; 132, identifier:namespace; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:api_key_required; 135, identifier:api_key_required; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:base_path; 138, identifier:base_path; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:limit_definitions; 141, identifier:limit_definitions; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:use_request_uri; 144, identifier:use_request_uri | def api(name, version, description=None, hostname=None, audiences=None,
scopes=None, allowed_client_ids=None, canonical_name=None,
auth=None, owner_domain=None, owner_name=None, package_path=None,
frontend_limits=None, title=None, documentation=None, auth_level=None,
issuers=None, namespace=None, api_key_required=None, base_path=None,
limit_definitions=None, use_request_uri=None):
if auth_level is not None:
_logger.warn(_AUTH_LEVEL_WARNING)
return _ApiDecorator(name, version, description=description,
hostname=hostname, audiences=audiences, scopes=scopes,
allowed_client_ids=allowed_client_ids,
canonical_name=canonical_name, auth=auth,
owner_domain=owner_domain, owner_name=owner_name,
package_path=package_path,
frontend_limits=frontend_limits, title=title,
documentation=documentation, auth_level=auth_level,
issuers=issuers, namespace=namespace,
api_key_required=api_key_required, base_path=base_path,
limit_definitions=limit_definitions,
use_request_uri=use_request_uri) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 44; 2, function_name:method; 3, parameters; 3, 4; 3, 9; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 3, 41; 4, default_parameter; 4, 5; 4, 6; 5, identifier:request_message; 6, attribute; 6, 7; 6, 8; 7, identifier:message_types; 8, identifier:VoidMessage; 9, default_parameter; 9, 10; 9, 11; 10, identifier:response_message; 11, attribute; 11, 12; 11, 13; 12, identifier:message_types; 13, identifier:VoidMessage; 14, default_parameter; 14, 15; 14, 16; 15, identifier:name; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:path; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:http_method; 22, string:'POST'; 23, default_parameter; 23, 24; 23, 25; 24, identifier:scopes; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:audiences; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:allowed_client_ids; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:auth_level; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:api_key_required; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:metric_costs; 40, None; 41, default_parameter; 41, 42; 41, 43; 42, identifier:use_request_uri; 43, None; 44, block; 44, 45; 44, 57; 44, 61; 44, 255; 44, 268; 44, 277; 44, 284; 44, 289; 44, 296; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:auth_level; 48, None; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:_logger; 54, identifier:warn; 55, argument_list; 55, 56; 56, identifier:_AUTH_LEVEL_WARNING; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:DEFAULT_HTTP_METHOD; 60, string:'POST'; 61, function_definition; 61, 62; 61, 63; 61, 65; 62, function_name:apiserving_method_decorator; 63, parameters; 63, 64; 64, identifier:api_method; 65, block; 65, 66; 65, 70; 65, 74; 65, 123; 65, 130; 65, 160; 65, 168; 65, 189; 65, 243; 65, 253; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:request_body_class; 69, None; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:request_params_class; 73, None; 74, if_statement; 74, 75; 74, 82; 74, 111; 75, call; 75, 76; 75, 77; 76, identifier:isinstance; 77, argument_list; 77, 78; 77, 79; 78, identifier:request_message; 79, attribute; 79, 80; 79, 81; 80, identifier:resource_container; 81, identifier:ResourceContainer; 82, block; 82, 83; 82, 95; 82, 103; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:remote_decorator; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:remote; 89, identifier:method; 90, argument_list; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:request_message; 93, identifier:combined_message_class; 94, identifier:response_message; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:request_body_class; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:request_message; 101, identifier:body_message_class; 102, argument_list; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:request_params_class; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:request_message; 109, identifier:parameters_message_class; 110, argument_list; 111, else_clause; 111, 112; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:remote_decorator; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:remote; 119, identifier:method; 120, argument_list; 120, 121; 120, 122; 121, identifier:request_message; 122, identifier:response_message; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:remote_method; 126, call; 126, 127; 126, 128; 127, identifier:remote_decorator; 128, argument_list; 128, 129; 129, identifier:api_method; 130, function_definition; 130, 131; 130, 132; 130, 135; 131, function_name:invoke_remote; 132, parameters; 132, 133; 132, 134; 133, identifier:service_instance; 134, identifier:request; 135, block; 135, 136; 135, 154; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:users_id_token; 140, identifier:_maybe_set_current_user_vars; 141, argument_list; 141, 142; 141, 143; 141, 151; 142, identifier:invoke_remote; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:api_info; 145, call; 145, 146; 145, 147; 146, identifier:getattr; 147, argument_list; 147, 148; 147, 149; 147, 150; 148, identifier:service_instance; 149, string:'api_info'; 150, None; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:request; 153, identifier:request; 154, return_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:remote_method; 157, argument_list; 157, 158; 157, 159; 158, identifier:service_instance; 159, identifier:request; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:invoke_remote; 164, identifier:remote; 165, attribute; 165, 166; 165, 167; 166, identifier:remote_method; 167, identifier:remote; 168, if_statement; 168, 169; 168, 176; 169, call; 169, 170; 169, 171; 170, identifier:isinstance; 171, argument_list; 171, 172; 171, 173; 172, identifier:request_message; 173, attribute; 173, 174; 173, 175; 174, identifier:resource_container; 175, identifier:ResourceContainer; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:resource_container; 182, identifier:ResourceContainer; 183, identifier:add_to_cache; 184, argument_list; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:invoke_remote; 187, identifier:remote; 188, identifier:request_message; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:invoke_remote; 193, identifier:method_info; 194, call; 194, 195; 194, 196; 195, identifier:_MethodInfo; 196, argument_list; 196, 197; 196, 204; 196, 211; 196, 216; 196, 219; 196, 222; 196, 225; 196, 228; 196, 231; 196, 234; 196, 237; 196, 240; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:name; 199, boolean_operator:or; 199, 200; 199, 201; 200, identifier:name; 201, attribute; 201, 202; 201, 203; 202, identifier:api_method; 203, identifier:__name__; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:path; 206, boolean_operator:or; 206, 207; 206, 208; 207, identifier:path; 208, attribute; 208, 209; 208, 210; 209, identifier:api_method; 210, identifier:__name__; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:http_method; 213, boolean_operator:or; 213, 214; 213, 215; 214, identifier:http_method; 215, identifier:DEFAULT_HTTP_METHOD; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:scopes; 218, identifier:scopes; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:audiences; 221, identifier:audiences; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:allowed_client_ids; 224, identifier:allowed_client_ids; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:auth_level; 227, identifier:auth_level; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:api_key_required; 230, identifier:api_key_required; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:metric_costs; 233, identifier:metric_costs; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:use_request_uri; 236, identifier:use_request_uri; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:request_body_class; 239, identifier:request_body_class; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:request_params_class; 242, identifier:request_params_class; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:invoke_remote; 247, identifier:__name__; 248, attribute; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:invoke_remote; 251, identifier:method_info; 252, identifier:name; 253, return_statement; 253, 254; 254, identifier:invoke_remote; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:endpoints_util; 259, identifier:check_list_type; 260, argument_list; 260, 261; 260, 262; 260, 267; 261, identifier:scopes; 262, tuple; 262, 263; 262, 264; 263, identifier:basestring; 264, attribute; 264, 265; 264, 266; 265, identifier:endpoints_types; 266, identifier:OAuth2Scope; 267, string:'scopes'; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:endpoints_util; 272, identifier:check_list_type; 273, argument_list; 273, 274; 273, 275; 273, 276; 274, identifier:allowed_client_ids; 275, identifier:basestring; 276, string:'allowed_client_ids'; 277, expression_statement; 277, 278; 278, call; 278, 279; 278, 280; 279, identifier:_CheckEnum; 280, argument_list; 280, 281; 280, 282; 280, 283; 281, identifier:auth_level; 282, identifier:AUTH_LEVEL; 283, string:'auth_level'; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 287; 286, identifier:_CheckAudiences; 287, argument_list; 287, 288; 288, identifier:audiences; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 292; 291, identifier:_CheckType; 292, argument_list; 292, 293; 292, 294; 292, 295; 293, identifier:metric_costs; 294, identifier:dict; 295, string:'metric_costs'; 296, return_statement; 296, 297; 297, identifier:apiserving_method_decorator | def method(request_message=message_types.VoidMessage,
response_message=message_types.VoidMessage,
name=None,
path=None,
http_method='POST',
scopes=None,
audiences=None,
allowed_client_ids=None,
auth_level=None,
api_key_required=None,
metric_costs=None,
use_request_uri=None):
if auth_level is not None:
_logger.warn(_AUTH_LEVEL_WARNING)
DEFAULT_HTTP_METHOD = 'POST'
def apiserving_method_decorator(api_method):
request_body_class = None
request_params_class = None
if isinstance(request_message, resource_container.ResourceContainer):
remote_decorator = remote.method(request_message.combined_message_class,
response_message)
request_body_class = request_message.body_message_class()
request_params_class = request_message.parameters_message_class()
else:
remote_decorator = remote.method(request_message, response_message)
remote_method = remote_decorator(api_method)
def invoke_remote(service_instance, request):
users_id_token._maybe_set_current_user_vars(
invoke_remote, api_info=getattr(service_instance, 'api_info', None),
request=request)
return remote_method(service_instance, request)
invoke_remote.remote = remote_method.remote
if isinstance(request_message, resource_container.ResourceContainer):
resource_container.ResourceContainer.add_to_cache(
invoke_remote.remote, request_message)
invoke_remote.method_info = _MethodInfo(
name=name or api_method.__name__, path=path or api_method.__name__,
http_method=http_method or DEFAULT_HTTP_METHOD,
scopes=scopes, audiences=audiences,
allowed_client_ids=allowed_client_ids, auth_level=auth_level,
api_key_required=api_key_required, metric_costs=metric_costs,
use_request_uri=use_request_uri,
request_body_class=request_body_class,
request_params_class=request_params_class)
invoke_remote.__name__ = invoke_remote.method_info.name
return invoke_remote
endpoints_util.check_list_type(scopes, (basestring, endpoints_types.OAuth2Scope), 'scopes')
endpoints_util.check_list_type(allowed_client_ids, basestring,
'allowed_client_ids')
_CheckEnum(auth_level, AUTH_LEVEL, 'auth_level')
_CheckAudiences(audiences)
_CheckType(metric_costs, dict, 'metric_costs')
return apiserving_method_decorator |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:api_class; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:resource_name; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:path; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:audiences; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:scopes; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:allowed_client_ids; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:auth_level; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:api_key_required; 25, None; 26, block; 26, 27; 26, 39; 26, 87; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:auth_level; 30, None; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:_logger; 36, identifier:warn; 37, argument_list; 37, 38; 38, identifier:_AUTH_LEVEL_WARNING; 39, function_definition; 39, 40; 39, 41; 39, 43; 40, function_name:apiserving_api_decorator; 41, parameters; 41, 42; 42, identifier:api_class; 43, block; 43, 44; 43, 53; 43, 85; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:__classes; 50, identifier:append; 51, argument_list; 51, 52; 52, identifier:api_class; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:api_class; 57, identifier:api_info; 58, call; 58, 59; 58, 60; 59, identifier:_ApiInfo; 60, argument_list; 60, 61; 60, 64; 60, 67; 60, 70; 60, 73; 60, 76; 60, 79; 60, 82; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:__common_info; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:resource_name; 66, identifier:resource_name; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:path; 69, identifier:path; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:audiences; 72, identifier:audiences; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:scopes; 75, identifier:scopes; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:allowed_client_ids; 78, identifier:allowed_client_ids; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:auth_level; 81, identifier:auth_level; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:api_key_required; 84, identifier:api_key_required; 85, return_statement; 85, 86; 86, identifier:api_class; 87, return_statement; 87, 88; 88, identifier:apiserving_api_decorator | def api_class(self, resource_name=None, path=None, audiences=None,
scopes=None, allowed_client_ids=None, auth_level=None,
api_key_required=None):
if auth_level is not None:
_logger.warn(_AUTH_LEVEL_WARNING)
def apiserving_api_decorator(api_class):
self.__classes.append(api_class)
api_class.api_info = _ApiInfo(
self.__common_info, resource_name=resource_name,
path=path, audiences=audiences, scopes=scopes,
allowed_client_ids=allowed_client_ids, auth_level=auth_level,
api_key_required=api_key_required)
return api_class
return apiserving_api_decorator |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__field_to_subfields; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:field; 6, block; 6, 7; 6, 21; 6, 25; 6, 74; 7, if_statement; 7, 8; 7, 16; 8, not_operator; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 13; 12, identifier:field; 13, attribute; 13, 14; 13, 15; 14, identifier:messages; 15, identifier:MessageField; 16, block; 16, 17; 17, return_statement; 17, 18; 18, list:[[field]]; 18, 19; 19, list:[field]; 19, 20; 20, identifier:field; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:result; 24, list:[]; 25, for_statement; 25, 26; 25, 27; 25, 45; 26, identifier:subfield; 27, call; 27, 28; 27, 29; 28, identifier:sorted; 29, argument_list; 29, 30; 29, 37; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:field; 34, identifier:message_type; 35, identifier:all_fields; 36, argument_list; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:key; 39, lambda; 39, 40; 39, 42; 40, lambda_parameters; 40, 41; 41, identifier:f; 42, attribute; 42, 43; 42, 44; 43, identifier:f; 44, identifier:number; 45, block; 45, 46; 45, 55; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:subfield_results; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:__field_to_subfields; 53, argument_list; 53, 54; 54, identifier:subfield; 55, for_statement; 55, 56; 55, 57; 55, 58; 56, identifier:subfields_list; 57, identifier:subfield_results; 58, block; 58, 59; 58, 67; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:subfields_list; 63, identifier:insert; 64, argument_list; 64, 65; 64, 66; 65, integer:0; 66, identifier:field; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:result; 71, identifier:append; 72, argument_list; 72, 73; 73, identifier:subfields_list; 74, return_statement; 74, 75; 75, identifier:result | def __field_to_subfields(self, field):
if not isinstance(field, messages.MessageField):
return [[field]]
result = []
for subfield in sorted(field.message_type.all_fields(),
key=lambda f: f.number):
subfield_results = self.__field_to_subfields(subfield)
for subfields_list in subfield_results:
subfields_list.insert(0, field)
result.append(subfields_list)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:__schemas_descriptor; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 175; 5, 209; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:result; 9, dictionary; 10, for_statement; 10, 11; 10, 14; 10, 25; 11, pattern_list; 11, 12; 11, 13; 12, identifier:schema_key; 13, identifier:schema_value; 14, call; 14, 15; 14, 24; 15, attribute; 15, 16; 15, 23; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:__parser; 21, identifier:schemas; 22, argument_list; 23, identifier:iteritems; 24, argument_list; 25, block; 25, 26; 25, 34; 25, 38; 25, 146; 25, 166; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:field_keys; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:schema_value; 32, identifier:keys; 33, argument_list; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:key_result; 37, dictionary; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:in; 39, 40; 39, 41; 40, string:'properties'; 41, identifier:field_keys; 42, block; 42, 43; 42, 55; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:key_result; 47, string:'properties'; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:schema_value; 52, string:'properties'; 53, identifier:copy; 54, argument_list; 55, for_statement; 55, 56; 55, 59; 55, 66; 56, pattern_list; 56, 57; 56, 58; 57, identifier:prop_key; 58, identifier:prop_value; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:schema_value; 63, string:'properties'; 64, identifier:iteritems; 65, argument_list; 66, block; 66, 67; 66, 134; 67, if_statement; 67, 68; 67, 71; 67, 95; 68, comparison_operator:in; 68, 69; 68, 70; 69, string:'enum'; 70, identifier:prop_value; 71, block; 71, 72; 71, 81; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:num_enums; 75, call; 75, 76; 75, 77; 76, identifier:len; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 80; 79, identifier:prop_value; 80, string:'enum'; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 90; 83, subscript; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:key_result; 87, string:'properties'; 88, identifier:prop_key; 89, string:'enumDescriptions'; 90, parenthesized_expression; 90, 91; 91, binary_operator:*; 91, 92; 91, 94; 92, list:['']; 92, 93; 93, string:''; 94, identifier:num_enums; 95, elif_clause; 95, 96; 95, 99; 96, comparison_operator:in; 96, 97; 96, 98; 97, string:'default'; 98, identifier:prop_value; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 109; 100, 121; 101, comparison_operator:==; 101, 102; 101, 108; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:prop_value; 105, identifier:get; 106, argument_list; 106, 107; 107, string:'type'; 108, string:'boolean'; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:prop_value; 114, string:'default'; 115, conditional_expression:if; 115, 116; 115, 117; 115, 120; 116, string:'true'; 117, subscript; 117, 118; 117, 119; 118, identifier:prop_value; 119, string:'default'; 120, string:'false'; 121, else_clause; 121, 122; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:prop_value; 127, string:'default'; 128, call; 128, 129; 128, 130; 129, identifier:str; 130, argument_list; 130, 131; 131, subscript; 131, 132; 131, 133; 132, identifier:prop_value; 133, string:'default'; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 143; 136, attribute; 136, 137; 136, 142; 137, subscript; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:key_result; 140, string:'properties'; 141, identifier:prop_key; 142, identifier:pop; 143, argument_list; 143, 144; 143, 145; 144, string:'required'; 145, None; 146, for_statement; 146, 147; 146, 148; 146, 152; 147, identifier:key; 148, tuple; 148, 149; 148, 150; 148, 151; 149, string:'type'; 150, string:'id'; 151, string:'description'; 152, block; 152, 153; 153, if_statement; 153, 154; 153, 157; 154, comparison_operator:in; 154, 155; 154, 156; 155, identifier:key; 156, identifier:field_keys; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:key_result; 162, identifier:key; 163, subscript; 163, 164; 163, 165; 164, identifier:schema_value; 165, identifier:key; 166, if_statement; 166, 167; 166, 168; 167, identifier:key_result; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:result; 173, identifier:schema_key; 174, identifier:key_result; 175, for_statement; 175, 176; 175, 177; 175, 182; 176, identifier:schema_value; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:result; 180, identifier:itervalues; 181, argument_list; 182, block; 182, 183; 183, for_statement; 183, 184; 183, 185; 183, 190; 184, identifier:field_value; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:schema_value; 188, identifier:itervalues; 189, argument_list; 190, block; 190, 191; 191, if_statement; 191, 192; 191, 197; 192, call; 192, 193; 192, 194; 193, identifier:isinstance; 194, argument_list; 194, 195; 194, 196; 195, identifier:field_value; 196, identifier:dict; 197, block; 197, 198; 198, if_statement; 198, 199; 198, 202; 199, comparison_operator:in; 199, 200; 199, 201; 200, string:'$ref'; 201, identifier:field_value; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, subscript; 205, 206; 205, 207; 206, identifier:field_value; 207, string:'type'; 208, string:'object'; 209, return_statement; 209, 210; 210, identifier:result | def __schemas_descriptor(self):
result = {}
for schema_key, schema_value in self.__parser.schemas().iteritems():
field_keys = schema_value.keys()
key_result = {}
if 'properties' in field_keys:
key_result['properties'] = schema_value['properties'].copy()
for prop_key, prop_value in schema_value['properties'].iteritems():
if 'enum' in prop_value:
num_enums = len(prop_value['enum'])
key_result['properties'][prop_key]['enumDescriptions'] = (
[''] * num_enums)
elif 'default' in prop_value:
if prop_value.get('type') == 'boolean':
prop_value['default'] = 'true' if prop_value['default'] else 'false'
else:
prop_value['default'] = str(prop_value['default'])
key_result['properties'][prop_key].pop('required', None)
for key in ('type', 'id', 'description'):
if key in field_keys:
key_result[key] = schema_value[key]
if key_result:
result[schema_key] = key_result
for schema_value in result.itervalues():
for field_value in schema_value.itervalues():
if isinstance(field_value, dict):
if '$ref' in field_value:
field_value['type'] = 'object'
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:__discovery_doc_descriptor; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:services; 6, default_parameter; 6, 7; 6, 8; 7, identifier:hostname; 8, None; 9, block; 9, 10; 9, 19; 9, 31; 9, 37; 9, 56; 9, 65; 9, 75; 9, 86; 9, 170; 9, 174; 9, 178; 9, 182; 9, 191; 9, 195; 9, 376; 9, 398; 9, 407; 9, 416; 9, 424; 9, 433; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:merged_api_info; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:__get_merged_api_info; 17, argument_list; 17, 18; 18, identifier:services; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:descriptor; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:get_descriptor_defaults; 26, argument_list; 26, 27; 26, 28; 27, identifier:merged_api_info; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:hostname; 30, identifier:hostname; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:description; 34, attribute; 34, 35; 34, 36; 35, identifier:merged_api_info; 36, identifier:description; 37, if_statement; 37, 38; 37, 47; 38, boolean_operator:and; 38, 39; 38, 41; 39, not_operator; 39, 40; 40, identifier:description; 41, comparison_operator:==; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:services; 46, integer:1; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:description; 51, attribute; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:services; 54, integer:0; 55, identifier:__doc__; 56, if_statement; 56, 57; 56, 58; 57, identifier:description; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:descriptor; 63, string:'description'; 64, identifier:description; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:descriptor; 69, string:'parameters'; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:__standard_parameters_descriptor; 74, argument_list; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:descriptor; 79, string:'auth'; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:__standard_auth_descriptor; 84, argument_list; 84, 85; 85, identifier:services; 86, if_statement; 86, 87; 86, 90; 86, 123; 87, attribute; 87, 88; 87, 89; 88, identifier:merged_api_info; 89, identifier:namespace; 90, block; 90, 91; 90, 101; 90, 111; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:descriptor; 95, string:'ownerDomain'; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:merged_api_info; 99, identifier:namespace; 100, identifier:owner_domain; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:descriptor; 105, string:'ownerName'; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:merged_api_info; 109, identifier:namespace; 110, identifier:owner_name; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:descriptor; 115, string:'packagePath'; 116, boolean_operator:or; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:merged_api_info; 120, identifier:namespace; 121, identifier:package_path; 122, string:''; 123, else_clause; 123, 124; 124, block; 124, 125; 124, 140; 124, 155; 125, if_statement; 125, 126; 125, 131; 126, comparison_operator:is; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:merged_api_info; 129, identifier:owner_domain; 130, None; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:descriptor; 136, string:'ownerDomain'; 137, attribute; 137, 138; 137, 139; 138, identifier:merged_api_info; 139, identifier:owner_domain; 140, if_statement; 140, 141; 140, 146; 141, comparison_operator:is; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:merged_api_info; 144, identifier:owner_name; 145, None; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:descriptor; 151, string:'ownerName'; 152, attribute; 152, 153; 152, 154; 153, identifier:merged_api_info; 154, identifier:owner_name; 155, if_statement; 155, 156; 155, 161; 156, comparison_operator:is; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:merged_api_info; 159, identifier:package_path; 160, None; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:descriptor; 166, string:'packagePath'; 167, attribute; 167, 168; 167, 169; 168, identifier:merged_api_info; 169, identifier:package_path; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:method_map; 173, dictionary; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:method_collision_tracker; 177, dictionary; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:rest_collision_tracker; 181, dictionary; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:resource_index; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:collections; 188, identifier:defaultdict; 189, argument_list; 189, 190; 190, identifier:list; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:resource_map; 194, dictionary; 195, for_statement; 195, 196; 195, 197; 195, 198; 196, identifier:service; 197, identifier:services; 198, block; 198, 199; 198, 207; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:remote_methods; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:service; 205, identifier:all_remote_methods; 206, argument_list; 207, for_statement; 207, 208; 207, 211; 207, 216; 208, pattern_list; 208, 209; 208, 210; 209, identifier:protorpc_meth_name; 210, identifier:protorpc_meth_info; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:remote_methods; 214, identifier:iteritems; 215, argument_list; 216, block; 216, 217; 216, 226; 216, 232; 216, 243; 216, 254; 216, 263; 216, 272; 216, 303; 216, 311; 216, 345; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:method_info; 220, call; 220, 221; 220, 222; 221, identifier:getattr; 222, argument_list; 222, 223; 222, 224; 222, 225; 223, identifier:protorpc_meth_info; 224, string:'method_info'; 225, None; 226, if_statement; 226, 227; 226, 230; 227, comparison_operator:is; 227, 228; 227, 229; 228, identifier:method_info; 229, None; 230, block; 230, 231; 231, continue_statement; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:path; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:method_info; 238, identifier:get_path; 239, argument_list; 239, 240; 240, attribute; 240, 241; 240, 242; 241, identifier:service; 242, identifier:api_info; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:method_id; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:method_info; 249, identifier:method_id; 250, argument_list; 250, 251; 251, attribute; 251, 252; 251, 253; 252, identifier:service; 253, identifier:api_info; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:canonical_method_id; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:_get_canonical_method_id; 261, argument_list; 261, 262; 262, identifier:method_id; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:resource_path; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:_get_resource_path; 270, argument_list; 270, 271; 271, identifier:method_id; 272, if_statement; 272, 273; 272, 276; 272, 293; 273, comparison_operator:in; 273, 274; 273, 275; 274, identifier:method_id; 275, identifier:method_collision_tracker; 276, block; 276, 277; 277, raise_statement; 277, 278; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:api_exceptions; 281, identifier:ApiConfigurationError; 282, argument_list; 282, 283; 283, binary_operator:%; 283, 284; 283, 285; 284, string:'Method %s used multiple times, in classes %s and %s'; 285, tuple; 285, 286; 285, 287; 285, 290; 286, identifier:method_id; 287, subscript; 287, 288; 287, 289; 288, identifier:method_collision_tracker; 289, identifier:method_id; 290, attribute; 290, 291; 290, 292; 291, identifier:service; 292, identifier:__name__; 293, else_clause; 293, 294; 294, block; 294, 295; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 300; 297, subscript; 297, 298; 297, 299; 298, identifier:method_collision_tracker; 299, identifier:method_id; 300, attribute; 300, 301; 300, 302; 301, identifier:service; 302, identifier:__name__; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 306; 305, identifier:rest_identifier; 306, tuple; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:method_info; 309, identifier:http_method; 310, identifier:path; 311, if_statement; 311, 312; 311, 315; 311, 335; 312, comparison_operator:in; 312, 313; 312, 314; 313, identifier:rest_identifier; 314, identifier:rest_collision_tracker; 315, block; 315, 316; 316, raise_statement; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:api_exceptions; 320, identifier:ApiConfigurationError; 321, argument_list; 321, 322; 322, binary_operator:%; 322, 323; 322, 324; 323, string:'%s path "%s" used multiple times, in classes %s and %s'; 324, tuple; 324, 325; 324, 328; 324, 329; 324, 332; 325, attribute; 325, 326; 325, 327; 326, identifier:method_info; 327, identifier:http_method; 328, identifier:path; 329, subscript; 329, 330; 329, 331; 330, identifier:rest_collision_tracker; 331, identifier:rest_identifier; 332, attribute; 332, 333; 332, 334; 333, identifier:service; 334, identifier:__name__; 335, else_clause; 335, 336; 336, block; 336, 337; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 342; 339, subscript; 339, 340; 339, 341; 340, identifier:rest_collision_tracker; 341, identifier:rest_identifier; 342, attribute; 342, 343; 342, 344; 343, identifier:service; 344, identifier:__name__; 345, if_statement; 345, 346; 345, 347; 345, 361; 346, identifier:resource_path; 347, block; 347, 348; 348, expression_statement; 348, 349; 349, call; 349, 350; 349, 357; 350, attribute; 350, 351; 350, 356; 351, subscript; 351, 352; 351, 353; 352, identifier:resource_index; 353, subscript; 353, 354; 353, 355; 354, identifier:resource_path; 355, integer:0; 356, identifier:append; 357, argument_list; 357, 358; 358, tuple; 358, 359; 358, 360; 359, identifier:service; 360, identifier:protorpc_meth_info; 361, else_clause; 361, 362; 362, block; 362, 363; 363, expression_statement; 363, 364; 364, assignment; 364, 365; 364, 368; 365, subscript; 365, 366; 365, 367; 366, identifier:method_map; 367, identifier:canonical_method_id; 368, call; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:self; 371, identifier:__method_descriptor; 372, argument_list; 372, 373; 372, 374; 372, 375; 373, identifier:service; 374, identifier:method_info; 375, identifier:protorpc_meth_info; 376, for_statement; 376, 377; 376, 380; 376, 385; 377, pattern_list; 377, 378; 377, 379; 378, identifier:resource; 379, identifier:resource_methods; 380, call; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:resource_index; 383, identifier:items; 384, argument_list; 385, block; 385, 386; 386, expression_statement; 386, 387; 387, assignment; 387, 388; 387, 391; 388, subscript; 388, 389; 388, 390; 389, identifier:resource_map; 390, identifier:resource; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:self; 394, identifier:__resource_descriptor; 395, argument_list; 395, 396; 395, 397; 396, identifier:resource; 397, identifier:resource_methods; 398, if_statement; 398, 399; 398, 400; 399, identifier:method_map; 400, block; 400, 401; 401, expression_statement; 401, 402; 402, assignment; 402, 403; 402, 406; 403, subscript; 403, 404; 403, 405; 404, identifier:descriptor; 405, string:'methods'; 406, identifier:method_map; 407, if_statement; 407, 408; 407, 409; 408, identifier:resource_map; 409, block; 409, 410; 410, expression_statement; 410, 411; 411, assignment; 411, 412; 411, 415; 412, subscript; 412, 413; 412, 414; 413, identifier:descriptor; 414, string:'resources'; 415, identifier:resource_map; 416, expression_statement; 416, 417; 417, assignment; 417, 418; 417, 419; 418, identifier:schemas; 419, call; 419, 420; 419, 423; 420, attribute; 420, 421; 420, 422; 421, identifier:self; 422, identifier:__schemas_descriptor; 423, argument_list; 424, if_statement; 424, 425; 424, 426; 425, identifier:schemas; 426, block; 426, 427; 427, expression_statement; 427, 428; 428, assignment; 428, 429; 428, 432; 429, subscript; 429, 430; 429, 431; 430, identifier:descriptor; 431, string:'schemas'; 432, identifier:schemas; 433, return_statement; 433, 434; 434, identifier:descriptor | def __discovery_doc_descriptor(self, services, hostname=None):
merged_api_info = self.__get_merged_api_info(services)
descriptor = self.get_descriptor_defaults(merged_api_info,
hostname=hostname)
description = merged_api_info.description
if not description and len(services) == 1:
description = services[0].__doc__
if description:
descriptor['description'] = description
descriptor['parameters'] = self.__standard_parameters_descriptor()
descriptor['auth'] = self.__standard_auth_descriptor(services)
if merged_api_info.namespace:
descriptor['ownerDomain'] = merged_api_info.namespace.owner_domain
descriptor['ownerName'] = merged_api_info.namespace.owner_name
descriptor['packagePath'] = merged_api_info.namespace.package_path or ''
else:
if merged_api_info.owner_domain is not None:
descriptor['ownerDomain'] = merged_api_info.owner_domain
if merged_api_info.owner_name is not None:
descriptor['ownerName'] = merged_api_info.owner_name
if merged_api_info.package_path is not None:
descriptor['packagePath'] = merged_api_info.package_path
method_map = {}
method_collision_tracker = {}
rest_collision_tracker = {}
resource_index = collections.defaultdict(list)
resource_map = {}
for service in services:
remote_methods = service.all_remote_methods()
for protorpc_meth_name, protorpc_meth_info in remote_methods.iteritems():
method_info = getattr(protorpc_meth_info, 'method_info', None)
if method_info is None:
continue
path = method_info.get_path(service.api_info)
method_id = method_info.method_id(service.api_info)
canonical_method_id = self._get_canonical_method_id(method_id)
resource_path = self._get_resource_path(method_id)
if method_id in method_collision_tracker:
raise api_exceptions.ApiConfigurationError(
'Method %s used multiple times, in classes %s and %s' %
(method_id, method_collision_tracker[method_id],
service.__name__))
else:
method_collision_tracker[method_id] = service.__name__
rest_identifier = (method_info.http_method, path)
if rest_identifier in rest_collision_tracker:
raise api_exceptions.ApiConfigurationError(
'%s path "%s" used multiple times, in classes %s and %s' %
(method_info.http_method, path,
rest_collision_tracker[rest_identifier],
service.__name__))
else:
rest_collision_tracker[rest_identifier] = service.__name__
if resource_path:
resource_index[resource_path[0]].append((service, protorpc_meth_info))
else:
method_map[canonical_method_id] = self.__method_descriptor(
service, method_info, protorpc_meth_info)
for resource, resource_methods in resource_index.items():
resource_map[resource] = self.__resource_descriptor(resource,
resource_methods)
if method_map:
descriptor['methods'] = method_map
if resource_map:
descriptor['resources'] = resource_map
schemas = self.__schemas_descriptor()
if schemas:
descriptor['schemas'] = schemas
return descriptor |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:__definitions_descriptor; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 123; 5, 164; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:result; 9, dictionary; 10, for_statement; 10, 11; 10, 14; 10, 25; 11, pattern_list; 11, 12; 11, 13; 12, identifier:def_key; 13, identifier:def_value; 14, call; 14, 15; 14, 24; 15, attribute; 15, 16; 15, 23; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:__parser; 21, identifier:schemas; 22, argument_list; 23, identifier:iteritems; 24, argument_list; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 34; 27, boolean_operator:or; 27, 28; 27, 31; 28, comparison_operator:in; 28, 29; 28, 30; 29, string:'properties'; 30, identifier:def_value; 31, comparison_operator:in; 31, 32; 31, 33; 32, string:'type'; 33, identifier:def_value; 34, block; 34, 35; 34, 39; 34, 45; 34, 58; 34, 105; 34, 117; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:key_result; 38, dictionary; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:required_keys; 42, call; 42, 43; 42, 44; 43, identifier:set; 44, argument_list; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:in; 46, 47; 46, 48; 47, string:'type'; 48, identifier:def_value; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:key_result; 54, string:'type'; 55, subscript; 55, 56; 55, 57; 56, identifier:def_value; 57, string:'type'; 58, if_statement; 58, 59; 58, 62; 59, comparison_operator:in; 59, 60; 59, 61; 60, string:'properties'; 61, identifier:def_value; 62, block; 62, 63; 62, 97; 63, for_statement; 63, 64; 63, 67; 63, 74; 64, pattern_list; 64, 65; 64, 66; 65, identifier:prop_key; 66, identifier:prop_value; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:def_value; 71, string:'properties'; 72, identifier:items; 73, argument_list; 74, block; 74, 75; 75, if_statement; 75, 76; 75, 85; 76, boolean_operator:and; 76, 77; 76, 82; 77, call; 77, 78; 77, 79; 78, identifier:isinstance; 79, argument_list; 79, 80; 79, 81; 80, identifier:prop_value; 81, identifier:dict; 82, comparison_operator:in; 82, 83; 82, 84; 83, string:'required'; 84, identifier:prop_value; 85, block; 85, 86; 85, 93; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:required_keys; 90, identifier:add; 91, argument_list; 91, 92; 92, identifier:prop_key; 93, delete_statement; 93, 94; 94, subscript; 94, 95; 94, 96; 95, identifier:prop_value; 96, string:'required'; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:key_result; 101, string:'properties'; 102, subscript; 102, 103; 102, 104; 103, identifier:def_value; 104, string:'properties'; 105, if_statement; 105, 106; 105, 107; 106, identifier:required_keys; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:key_result; 112, string:'required'; 113, call; 113, 114; 113, 115; 114, identifier:sorted; 115, argument_list; 115, 116; 116, identifier:required_keys; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:result; 121, identifier:def_key; 122, identifier:key_result; 123, for_statement; 123, 124; 123, 125; 123, 130; 124, identifier:def_value; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:result; 128, identifier:itervalues; 129, argument_list; 130, block; 130, 131; 131, for_statement; 131, 132; 131, 133; 131, 138; 132, identifier:prop_value; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:def_value; 136, identifier:itervalues; 137, argument_list; 138, block; 138, 139; 139, if_statement; 139, 140; 139, 145; 140, call; 140, 141; 140, 142; 141, identifier:isinstance; 142, argument_list; 142, 143; 142, 144; 143, identifier:prop_value; 144, identifier:dict; 145, block; 145, 146; 145, 157; 146, if_statement; 146, 147; 146, 150; 147, comparison_operator:in; 147, 148; 147, 149; 148, string:'$ref'; 149, identifier:prop_value; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:prop_value; 155, string:'type'; 156, string:'object'; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:_add_def_paths; 162, argument_list; 162, 163; 163, identifier:prop_value; 164, return_statement; 164, 165; 165, identifier:result | def __definitions_descriptor(self):
result = {}
for def_key, def_value in self.__parser.schemas().iteritems():
if 'properties' in def_value or 'type' in def_value:
key_result = {}
required_keys = set()
if 'type' in def_value:
key_result['type'] = def_value['type']
if 'properties' in def_value:
for prop_key, prop_value in def_value['properties'].items():
if isinstance(prop_value, dict) and 'required' in prop_value:
required_keys.add(prop_key)
del prop_value['required']
key_result['properties'] = def_value['properties']
if required_keys:
key_result['required'] = sorted(required_keys)
result[def_key] = key_result
for def_value in result.itervalues():
for prop_value in def_value.itervalues():
if isinstance(prop_value, dict):
if '$ref' in prop_value:
prop_value['type'] = 'object'
self._add_def_paths(prop_value)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:__api_openapi_descriptor; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:services; 6, default_parameter; 6, 7; 6, 8; 7, identifier:hostname; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:x_google_api_name; 11, False; 12, block; 12, 13; 12, 22; 12, 37; 12, 43; 12, 62; 12, 73; 12, 84; 12, 88; 12, 92; 12, 96; 12, 343; 12, 352; 12, 360; 12, 369; 12, 375; 12, 386; 12, 395; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:merged_api_info; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:__get_merged_api_info; 20, argument_list; 20, 21; 21, identifier:services; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:descriptor; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:get_descriptor_defaults; 29, argument_list; 29, 30; 29, 31; 29, 34; 30, identifier:merged_api_info; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:hostname; 33, identifier:hostname; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:x_google_api_name; 36, identifier:x_google_api_name; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:description; 40, attribute; 40, 41; 40, 42; 41, identifier:merged_api_info; 42, identifier:description; 43, if_statement; 43, 44; 43, 53; 44, boolean_operator:and; 44, 45; 44, 47; 45, not_operator; 45, 46; 46, identifier:description; 47, comparison_operator:==; 47, 48; 47, 52; 48, call; 48, 49; 48, 50; 49, identifier:len; 50, argument_list; 50, 51; 51, identifier:services; 52, integer:1; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:description; 57, attribute; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:services; 60, integer:0; 61, identifier:__doc__; 62, if_statement; 62, 63; 62, 64; 63, identifier:description; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:descriptor; 70, string:'info'; 71, string:'description'; 72, identifier:description; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:security_definitions; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:__security_definitions_descriptor; 80, argument_list; 80, 81; 81, attribute; 81, 82; 81, 83; 82, identifier:merged_api_info; 83, identifier:issuers; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:method_map; 87, dictionary; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:method_collision_tracker; 91, dictionary; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:rest_collision_tracker; 95, dictionary; 96, for_statement; 96, 97; 96, 98; 96, 99; 97, identifier:service; 98, identifier:services; 99, block; 99, 100; 99, 108; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:remote_methods; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:service; 106, identifier:all_remote_methods; 107, argument_list; 108, for_statement; 108, 109; 108, 110; 108, 118; 109, identifier:protorpc_meth_name; 110, call; 110, 111; 110, 112; 111, identifier:sorted; 112, argument_list; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:remote_methods; 116, identifier:iterkeys; 117, argument_list; 118, block; 118, 119; 118, 125; 118, 134; 118, 140; 118, 151; 118, 162; 118, 184; 118, 194; 118, 205; 118, 227; 118, 239; 118, 256; 118, 287; 118, 302; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:protorpc_meth_info; 122, subscript; 122, 123; 122, 124; 123, identifier:remote_methods; 124, identifier:protorpc_meth_name; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:method_info; 128, call; 128, 129; 128, 130; 129, identifier:getattr; 130, argument_list; 130, 131; 130, 132; 130, 133; 131, identifier:protorpc_meth_info; 132, string:'method_info'; 133, None; 134, if_statement; 134, 135; 134, 138; 135, comparison_operator:is; 135, 136; 135, 137; 136, identifier:method_info; 137, None; 138, block; 138, 139; 139, continue_statement; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:method_id; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:method_info; 146, identifier:method_id; 147, argument_list; 147, 148; 148, attribute; 148, 149; 148, 150; 149, identifier:service; 150, identifier:api_info; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:is_api_key_required; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:method_info; 157, identifier:is_api_key_required; 158, argument_list; 158, 159; 159, attribute; 159, 160; 159, 161; 160, identifier:service; 161, identifier:api_info; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:path; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, string:'/{0}/{1}/{2}'; 168, identifier:format; 169, argument_list; 169, 170; 169, 173; 169, 176; 170, attribute; 170, 171; 170, 172; 171, identifier:merged_api_info; 172, identifier:name; 173, attribute; 173, 174; 173, 175; 174, identifier:merged_api_info; 175, identifier:path_version; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:method_info; 179, identifier:get_path; 180, argument_list; 180, 181; 181, attribute; 181, 182; 181, 183; 182, identifier:service; 183, identifier:api_info; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:verb; 187, call; 187, 188; 187, 193; 188, attribute; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:method_info; 191, identifier:http_method; 192, identifier:lower; 193, argument_list; 194, if_statement; 194, 195; 194, 198; 195, comparison_operator:not; 195, 196; 195, 197; 196, identifier:path; 197, identifier:method_map; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:method_map; 203, identifier:path; 204, dictionary; 205, if_statement; 205, 206; 205, 211; 206, boolean_operator:and; 206, 207; 206, 208; 207, identifier:is_api_key_required; 208, comparison_operator:not; 208, 209; 208, 210; 209, identifier:_API_KEY; 210, identifier:security_definitions; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:security_definitions; 216, identifier:_API_KEY; 217, dictionary; 217, 218; 217, 221; 217, 224; 218, pair; 218, 219; 218, 220; 219, string:'type'; 220, string:'apiKey'; 221, pair; 221, 222; 221, 223; 222, string:'name'; 223, identifier:_API_KEY_PARAM; 224, pair; 224, 225; 224, 226; 225, string:'in'; 226, string:'query'; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:operation_id; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:_construct_operation_id; 234, argument_list; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:service; 237, identifier:__name__; 238, identifier:protorpc_meth_name; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 246; 241, subscript; 241, 242; 241, 245; 242, subscript; 242, 243; 242, 244; 243, identifier:method_map; 244, identifier:path; 245, identifier:verb; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:self; 249, identifier:__method_descriptor; 250, argument_list; 250, 251; 250, 252; 250, 253; 250, 254; 250, 255; 251, identifier:service; 252, identifier:method_info; 253, identifier:operation_id; 254, identifier:protorpc_meth_info; 255, identifier:security_definitions; 256, if_statement; 256, 257; 256, 260; 256, 277; 257, comparison_operator:in; 257, 258; 257, 259; 258, identifier:method_id; 259, identifier:method_collision_tracker; 260, block; 260, 261; 261, raise_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:api_exceptions; 265, identifier:ApiConfigurationError; 266, argument_list; 266, 267; 267, binary_operator:%; 267, 268; 267, 269; 268, string:'Method %s used multiple times, in classes %s and %s'; 269, tuple; 269, 270; 269, 271; 269, 274; 270, identifier:method_id; 271, subscript; 271, 272; 271, 273; 272, identifier:method_collision_tracker; 273, identifier:method_id; 274, attribute; 274, 275; 274, 276; 275, identifier:service; 276, identifier:__name__; 277, else_clause; 277, 278; 278, block; 278, 279; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 284; 281, subscript; 281, 282; 281, 283; 282, identifier:method_collision_tracker; 283, identifier:method_id; 284, attribute; 284, 285; 284, 286; 285, identifier:service; 286, identifier:__name__; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:rest_identifier; 290, tuple; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:method_info; 293, identifier:http_method; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:method_info; 297, identifier:get_path; 298, argument_list; 298, 299; 299, attribute; 299, 300; 299, 301; 300, identifier:service; 301, identifier:api_info; 302, if_statement; 302, 303; 302, 306; 302, 333; 303, comparison_operator:in; 303, 304; 303, 305; 304, identifier:rest_identifier; 305, identifier:rest_collision_tracker; 306, block; 306, 307; 307, raise_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:api_exceptions; 311, identifier:ApiConfigurationError; 312, argument_list; 312, 313; 313, binary_operator:%; 313, 314; 313, 315; 314, string:'%s path "%s" used multiple times, in classes %s and %s'; 315, tuple; 315, 316; 315, 319; 315, 327; 315, 330; 316, attribute; 316, 317; 316, 318; 317, identifier:method_info; 318, identifier:http_method; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:method_info; 322, identifier:get_path; 323, argument_list; 323, 324; 324, attribute; 324, 325; 324, 326; 325, identifier:service; 326, identifier:api_info; 327, subscript; 327, 328; 327, 329; 328, identifier:rest_collision_tracker; 329, identifier:rest_identifier; 330, attribute; 330, 331; 330, 332; 331, identifier:service; 332, identifier:__name__; 333, else_clause; 333, 334; 334, block; 334, 335; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 340; 337, subscript; 337, 338; 337, 339; 338, identifier:rest_collision_tracker; 339, identifier:rest_identifier; 340, attribute; 340, 341; 340, 342; 341, identifier:service; 342, identifier:__name__; 343, if_statement; 343, 344; 343, 345; 344, identifier:method_map; 345, block; 345, 346; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 351; 348, subscript; 348, 349; 348, 350; 349, identifier:descriptor; 350, string:'paths'; 351, identifier:method_map; 352, expression_statement; 352, 353; 353, assignment; 353, 354; 353, 355; 354, identifier:definitions; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:__definitions_descriptor; 359, argument_list; 360, if_statement; 360, 361; 360, 362; 361, identifier:definitions; 362, block; 362, 363; 363, expression_statement; 363, 364; 364, assignment; 364, 365; 364, 368; 365, subscript; 365, 366; 365, 367; 366, identifier:descriptor; 367, string:'definitions'; 368, identifier:definitions; 369, expression_statement; 369, 370; 370, assignment; 370, 371; 370, 374; 371, subscript; 371, 372; 371, 373; 372, identifier:descriptor; 373, string:'securityDefinitions'; 374, identifier:security_definitions; 375, expression_statement; 375, 376; 376, assignment; 376, 377; 376, 378; 377, identifier:limit_definitions; 378, call; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:self; 381, identifier:__x_google_quota_definitions_descriptor; 382, argument_list; 382, 383; 383, attribute; 383, 384; 383, 385; 384, identifier:merged_api_info; 385, identifier:limit_definitions; 386, if_statement; 386, 387; 386, 388; 387, identifier:limit_definitions; 388, block; 388, 389; 389, expression_statement; 389, 390; 390, assignment; 390, 391; 390, 394; 391, subscript; 391, 392; 391, 393; 392, identifier:descriptor; 393, string:'x-google-management'; 394, identifier:limit_definitions; 395, return_statement; 395, 396; 396, identifier:descriptor | def __api_openapi_descriptor(self, services, hostname=None, x_google_api_name=False):
merged_api_info = self.__get_merged_api_info(services)
descriptor = self.get_descriptor_defaults(merged_api_info,
hostname=hostname,
x_google_api_name=x_google_api_name)
description = merged_api_info.description
if not description and len(services) == 1:
description = services[0].__doc__
if description:
descriptor['info']['description'] = description
security_definitions = self.__security_definitions_descriptor(
merged_api_info.issuers)
method_map = {}
method_collision_tracker = {}
rest_collision_tracker = {}
for service in services:
remote_methods = service.all_remote_methods()
for protorpc_meth_name in sorted(remote_methods.iterkeys()):
protorpc_meth_info = remote_methods[protorpc_meth_name]
method_info = getattr(protorpc_meth_info, 'method_info', None)
if method_info is None:
continue
method_id = method_info.method_id(service.api_info)
is_api_key_required = method_info.is_api_key_required(service.api_info)
path = '/{0}/{1}/{2}'.format(merged_api_info.name,
merged_api_info.path_version,
method_info.get_path(service.api_info))
verb = method_info.http_method.lower()
if path not in method_map:
method_map[path] = {}
if is_api_key_required and _API_KEY not in security_definitions:
security_definitions[_API_KEY] = {
'type': 'apiKey',
'name': _API_KEY_PARAM,
'in': 'query'
}
operation_id = self._construct_operation_id(
service.__name__, protorpc_meth_name)
method_map[path][verb] = self.__method_descriptor(
service, method_info, operation_id, protorpc_meth_info,
security_definitions)
if method_id in method_collision_tracker:
raise api_exceptions.ApiConfigurationError(
'Method %s used multiple times, in classes %s and %s' %
(method_id, method_collision_tracker[method_id],
service.__name__))
else:
method_collision_tracker[method_id] = service.__name__
rest_identifier = (method_info.http_method,
method_info.get_path(service.api_info))
if rest_identifier in rest_collision_tracker:
raise api_exceptions.ApiConfigurationError(
'%s path "%s" used multiple times, in classes %s and %s' %
(method_info.http_method, method_info.get_path(service.api_info),
rest_collision_tracker[rest_identifier],
service.__name__))
else:
rest_collision_tracker[rest_identifier] = service.__name__
if method_map:
descriptor['paths'] = method_map
definitions = self.__definitions_descriptor()
if definitions:
descriptor['definitions'] = definitions
descriptor['securityDefinitions'] = security_definitions
limit_definitions = self.__x_google_quota_definitions_descriptor(
merged_api_info.limit_definitions)
if limit_definitions:
descriptor['x-google-management'] = limit_definitions
return descriptor |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__message_to_schema; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:message_type; 6, block; 6, 7; 6, 16; 6, 26; 6, 39; 6, 43; 6, 306; 6, 312; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:name; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:__normalized_name; 14, argument_list; 14, 15; 15, identifier:message_type; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:schema; 19, dictionary; 19, 20; 19, 23; 20, pair; 20, 21; 20, 22; 21, string:'id'; 22, identifier:name; 23, pair; 23, 24; 23, 25; 24, string:'type'; 25, string:'object'; 26, if_statement; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:message_type; 29, identifier:__doc__; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:schema; 35, string:'description'; 36, attribute; 36, 37; 36, 38; 37, identifier:message_type; 38, identifier:__doc__; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:properties; 42, dictionary; 43, for_statement; 43, 44; 43, 45; 43, 50; 44, identifier:field; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:message_type; 48, identifier:all_fields; 49, argument_list; 50, block; 50, 51; 50, 55; 50, 59; 50, 182; 50, 225; 50, 236; 50, 272; 50, 298; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:descriptor; 54, dictionary; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:type_info; 58, dictionary; 59, if_statement; 59, 60; 59, 68; 59, 103; 60, comparison_operator:==; 60, 61; 60, 65; 61, call; 61, 62; 61, 63; 62, identifier:type; 63, argument_list; 63, 64; 64, identifier:field; 65, attribute; 65, 66; 65, 67; 66, identifier:messages; 67, identifier:MessageField; 68, block; 68, 69; 68, 79; 68, 90; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:field_type; 72, attribute; 72, 73; 72, 78; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:field; 76, identifier:type; 77, argument_list; 78, identifier:__class__; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:type_info; 83, string:'$ref'; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:add_message; 88, argument_list; 88, 89; 89, identifier:field_type; 90, if_statement; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:field_type; 93, identifier:__doc__; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:descriptor; 99, string:'description'; 100, attribute; 100, 101; 100, 102; 101, identifier:field_type; 102, identifier:__doc__; 103, else_clause; 103, 104; 104, block; 104, 105; 104, 122; 104, 161; 104, 169; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:schema_type; 108, call; 108, 109; 108, 114; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:__FIELD_TO_SCHEMA_TYPE_MAP; 113, identifier:get; 114, argument_list; 114, 115; 114, 119; 115, call; 115, 116; 115, 117; 116, identifier:type; 117, argument_list; 117, 118; 118, identifier:field; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:__DEFAULT_SCHEMA_TYPE; 122, if_statement; 122, 123; 122, 128; 123, call; 123, 124; 123, 125; 124, identifier:isinstance; 125, argument_list; 125, 126; 125, 127; 126, identifier:schema_type; 127, identifier:dict; 128, block; 128, 129; 128, 133; 128, 142; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:variant_map; 132, identifier:schema_type; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:variant; 136, call; 136, 137; 136, 138; 137, identifier:getattr; 138, argument_list; 138, 139; 138, 140; 138, 141; 139, identifier:field; 140, string:'variant'; 141, None; 142, if_statement; 142, 143; 142, 146; 142, 153; 143, comparison_operator:in; 143, 144; 143, 145; 144, identifier:variant; 145, identifier:variant_map; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:schema_type; 150, subscript; 150, 151; 150, 152; 151, identifier:variant_map; 152, identifier:variant; 153, else_clause; 153, 154; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:schema_type; 158, subscript; 158, 159; 158, 160; 159, identifier:variant_map; 160, None; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:type_info; 165, string:'type'; 166, subscript; 166, 167; 166, 168; 167, identifier:schema_type; 168, integer:0; 169, if_statement; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:schema_type; 172, integer:1; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:type_info; 178, string:'format'; 179, subscript; 179, 180; 179, 181; 180, identifier:schema_type; 181, integer:1; 182, if_statement; 182, 183; 182, 191; 183, comparison_operator:==; 183, 184; 183, 188; 184, call; 184, 185; 184, 186; 185, identifier:type; 186, argument_list; 186, 187; 187, identifier:field; 188, attribute; 188, 189; 188, 190; 189, identifier:messages; 190, identifier:EnumField; 191, block; 191, 192; 191, 213; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:sorted_enums; 195, call; 195, 196; 195, 197; 196, identifier:sorted; 197, argument_list; 197, 198; 197, 205; 198, list_comprehension; 198, 199; 198, 200; 199, identifier:enum_info; 200, for_in_clause; 200, 201; 200, 202; 201, identifier:enum_info; 202, attribute; 202, 203; 202, 204; 203, identifier:field; 204, identifier:type; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:key; 207, lambda; 207, 208; 207, 210; 208, lambda_parameters; 208, 209; 209, identifier:enum_info; 210, attribute; 210, 211; 210, 212; 211, identifier:enum_info; 212, identifier:number; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 218; 215, subscript; 215, 216; 215, 217; 216, identifier:type_info; 217, string:'enum'; 218, list_comprehension; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:enum_info; 221, identifier:name; 222, for_in_clause; 222, 223; 222, 224; 223, identifier:enum_info; 224, identifier:sorted_enums; 225, if_statement; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:field; 228, identifier:required; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 235; 232, subscript; 232, 233; 232, 234; 233, identifier:descriptor; 234, string:'required'; 235, True; 236, if_statement; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:field; 239, identifier:default; 240, block; 240, 241; 241, if_statement; 241, 242; 241, 250; 241, 262; 242, comparison_operator:==; 242, 243; 242, 247; 243, call; 243, 244; 243, 245; 244, identifier:type; 245, argument_list; 245, 246; 246, identifier:field; 247, attribute; 247, 248; 247, 249; 248, identifier:messages; 249, identifier:EnumField; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 256; 253, subscript; 253, 254; 253, 255; 254, identifier:descriptor; 255, string:'default'; 256, call; 256, 257; 256, 258; 257, identifier:str; 258, argument_list; 258, 259; 259, attribute; 259, 260; 259, 261; 260, identifier:field; 261, identifier:default; 262, else_clause; 262, 263; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 269; 266, subscript; 266, 267; 266, 268; 267, identifier:descriptor; 268, string:'default'; 269, attribute; 269, 270; 269, 271; 270, identifier:field; 271, identifier:default; 272, if_statement; 272, 273; 272, 276; 272, 289; 273, attribute; 273, 274; 273, 275; 274, identifier:field; 275, identifier:repeated; 276, block; 276, 277; 276, 283; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 282; 279, subscript; 279, 280; 279, 281; 280, identifier:descriptor; 281, string:'items'; 282, identifier:type_info; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 288; 285, subscript; 285, 286; 285, 287; 286, identifier:descriptor; 287, string:'type'; 288, string:'array'; 289, else_clause; 289, 290; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:descriptor; 295, identifier:update; 296, argument_list; 296, 297; 297, identifier:type_info; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 305; 300, subscript; 300, 301; 300, 302; 301, identifier:properties; 302, attribute; 302, 303; 302, 304; 303, identifier:field; 304, identifier:name; 305, identifier:descriptor; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 311; 308, subscript; 308, 309; 308, 310; 309, identifier:schema; 310, string:'properties'; 311, identifier:properties; 312, return_statement; 312, 313; 313, identifier:schema | def __message_to_schema(self, message_type):
name = self.__normalized_name(message_type)
schema = {
'id': name,
'type': 'object',
}
if message_type.__doc__:
schema['description'] = message_type.__doc__
properties = {}
for field in message_type.all_fields():
descriptor = {}
type_info = {}
if type(field) == messages.MessageField:
field_type = field.type().__class__
type_info['$ref'] = self.add_message(field_type)
if field_type.__doc__:
descriptor['description'] = field_type.__doc__
else:
schema_type = self.__FIELD_TO_SCHEMA_TYPE_MAP.get(
type(field), self.__DEFAULT_SCHEMA_TYPE)
if isinstance(schema_type, dict):
variant_map = schema_type
variant = getattr(field, 'variant', None)
if variant in variant_map:
schema_type = variant_map[variant]
else:
schema_type = variant_map[None]
type_info['type'] = schema_type[0]
if schema_type[1]:
type_info['format'] = schema_type[1]
if type(field) == messages.EnumField:
sorted_enums = sorted([enum_info for enum_info in field.type],
key=lambda enum_info: enum_info.number)
type_info['enum'] = [enum_info.name for enum_info in sorted_enums]
if field.required:
descriptor['required'] = True
if field.default:
if type(field) == messages.EnumField:
descriptor['default'] = str(field.default)
else:
descriptor['default'] = field.default
if field.repeated:
descriptor['items'] = type_info
descriptor['type'] = 'array'
else:
descriptor.update(type_info)
properties[field.name] = descriptor
schema['properties'] = properties
return schema |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:transform_parameter_value; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:parameter_name; 5, identifier:value; 6, identifier:parameter_config; 7, block; 7, 8; 7, 35; 7, 42; 7, 84; 8, if_statement; 8, 9; 8, 14; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 13; 12, identifier:value; 13, identifier:list; 14, block; 14, 15; 15, return_statement; 15, 16; 16, list_comprehension; 16, 17; 16, 27; 17, call; 17, 18; 17, 19; 18, identifier:transform_parameter_value; 19, argument_list; 19, 20; 19, 25; 19, 26; 20, binary_operator:%; 20, 21; 20, 22; 21, string:'%s[%d]'; 22, tuple; 22, 23; 22, 24; 23, identifier:parameter_name; 24, identifier:index; 25, identifier:element; 26, identifier:parameter_config; 27, for_in_clause; 27, 28; 27, 31; 28, pattern_list; 28, 29; 28, 30; 29, identifier:index; 30, identifier:element; 31, call; 31, 32; 31, 33; 32, identifier:enumerate; 33, argument_list; 33, 34; 34, identifier:value; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:entry; 38, call; 38, 39; 38, 40; 39, identifier:_get_parameter_conversion_entry; 40, argument_list; 40, 41; 41, identifier:parameter_config; 42, if_statement; 42, 43; 42, 44; 43, identifier:entry; 44, block; 44, 45; 44, 52; 44, 62; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 51; 47, pattern_list; 47, 48; 47, 49; 47, 50; 48, identifier:validation_func; 49, identifier:conversion_func; 50, identifier:type_name; 51, identifier:entry; 52, if_statement; 52, 53; 52, 54; 53, identifier:validation_func; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:validation_func; 58, argument_list; 58, 59; 58, 60; 58, 61; 59, identifier:parameter_name; 60, identifier:value; 61, identifier:parameter_config; 62, if_statement; 62, 63; 62, 64; 63, identifier:conversion_func; 64, block; 64, 65; 65, try_statement; 65, 66; 65, 72; 66, block; 66, 67; 67, return_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:conversion_func; 70, argument_list; 70, 71; 71, identifier:value; 72, except_clause; 72, 73; 72, 74; 73, identifier:ValueError; 74, block; 74, 75; 75, raise_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:errors; 79, identifier:BasicTypeParameterError; 80, argument_list; 80, 81; 80, 82; 80, 83; 81, identifier:parameter_name; 82, identifier:value; 83, identifier:type_name; 84, return_statement; 84, 85; 85, identifier:value | def transform_parameter_value(parameter_name, value, parameter_config):
if isinstance(value, list):
return [transform_parameter_value('%s[%d]' % (parameter_name, index),
element, parameter_config)
for index, element in enumerate(value)]
entry = _get_parameter_conversion_entry(parameter_config)
if entry:
validation_func, conversion_func, type_name = entry
if validation_func:
validation_func(parameter_name, value, parameter_config)
if conversion_func:
try:
return conversion_func(value)
except ValueError:
raise errors.BasicTypeParameterError(parameter_name, value, type_name)
return value |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:extract_conf_from; 3, parameters; 3, 4; 3, 5; 3, 11; 3, 14; 4, identifier:mod; 5, default_parameter; 5, 6; 5, 7; 6, identifier:conf; 7, call; 7, 8; 7, 9; 8, identifier:ModuleConfig; 9, argument_list; 9, 10; 10, identifier:CONF_SPEC; 11, default_parameter; 11, 12; 11, 13; 12, identifier:depth; 13, integer:0; 14, default_parameter; 14, 15; 14, 16; 15, identifier:max_depth; 16, integer:2; 17, block; 17, 18; 17, 40; 17, 79; 17, 182; 18, for_statement; 18, 19; 18, 22; 18, 28; 19, pattern_list; 19, 20; 19, 21; 20, identifier:key; 21, identifier:default_value; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:six; 25, identifier:iteritems; 26, argument_list; 26, 27; 27, identifier:conf; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:conf; 33, identifier:key; 34, call; 34, 35; 34, 36; 35, identifier:_get_key_from_module; 36, argument_list; 36, 37; 36, 38; 36, 39; 37, identifier:mod; 38, identifier:key; 39, identifier:default_value; 40, try_statement; 40, 41; 40, 56; 40, 60; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:filtered_apps; 45, list_comprehension; 45, 46; 45, 47; 45, 52; 46, identifier:app; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:app; 49, subscript; 49, 50; 49, 51; 50, identifier:conf; 51, string:'apps'; 52, if_clause; 52, 53; 53, comparison_operator:not; 53, 54; 53, 55; 54, identifier:app; 55, identifier:BLACKLIST; 56, except_clause; 56, 57; 56, 58; 57, identifier:TypeError; 58, block; 58, 59; 59, pass_statement; 60, except_clause; 60, 61; 60, 65; 61, as_pattern; 61, 62; 61, 63; 62, identifier:Exception; 63, as_pattern_target; 63, 64; 64, identifier:e; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:warnings; 70, identifier:warn; 71, argument_list; 71, 72; 72, binary_operator:%; 72, 73; 72, 74; 73, string:'Error %s during loading %s'; 74, tuple; 74, 75; 74, 76; 75, identifier:e; 76, subscript; 76, 77; 76, 78; 77, identifier:conf; 78, string:'apps'; 79, for_statement; 79, 80; 79, 81; 79, 82; 80, identifier:app; 81, identifier:filtered_apps; 82, block; 82, 83; 83, try_statement; 83, 84; 83, 175; 84, block; 84, 85; 84, 92; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:app_module; 88, call; 88, 89; 88, 90; 89, identifier:import_module; 90, argument_list; 90, 91; 91, identifier:app; 92, if_statement; 92, 93; 92, 96; 93, comparison_operator:!=; 93, 94; 93, 95; 94, identifier:app_module; 95, identifier:mod; 96, block; 96, 97; 96, 104; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:app_module; 100, call; 100, 101; 100, 102; 101, identifier:_get_correct_module; 102, argument_list; 102, 103; 103, identifier:app_module; 104, if_statement; 104, 105; 104, 108; 105, comparison_operator:<; 105, 106; 105, 107; 106, identifier:depth; 107, identifier:max_depth; 108, block; 108, 109; 108, 121; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:mod_conf; 112, call; 112, 113; 112, 114; 113, identifier:extract_conf_from; 114, argument_list; 114, 115; 114, 116; 115, identifier:app_module; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:depth; 118, binary_operator:+; 118, 119; 118, 120; 119, identifier:depth; 120, integer:1; 121, for_statement; 121, 122; 121, 125; 121, 131; 122, pattern_list; 122, 123; 122, 124; 123, identifier:k; 124, identifier:v; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:six; 128, identifier:iteritems; 129, argument_list; 129, 130; 130, identifier:mod_conf; 131, block; 131, 132; 131, 138; 132, if_statement; 132, 133; 132, 136; 133, comparison_operator:==; 133, 134; 133, 135; 134, identifier:k; 135, string:'config'; 136, block; 136, 137; 137, continue_statement; 138, if_statement; 138, 139; 138, 144; 138, 154; 139, call; 139, 140; 139, 141; 140, identifier:isinstance; 141, argument_list; 141, 142; 141, 143; 142, identifier:v; 143, identifier:dict; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:conf; 150, identifier:k; 151, identifier:update; 152, argument_list; 152, 153; 153, identifier:v; 154, elif_clause; 154, 155; 154, 162; 155, call; 155, 156; 155, 157; 156, identifier:isinstance; 157, argument_list; 157, 158; 157, 159; 158, identifier:v; 159, tuple; 159, 160; 159, 161; 160, identifier:list; 161, identifier:tuple; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:conf; 167, identifier:k; 168, call; 168, 169; 168, 170; 169, identifier:merge; 170, argument_list; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:conf; 173, identifier:k; 174, identifier:v; 175, except_clause; 175, 176; 175, 180; 176, as_pattern; 176, 177; 176, 178; 177, identifier:Exception; 178, as_pattern_target; 178, 179; 179, identifier:e; 180, block; 180, 181; 181, pass_statement; 182, return_statement; 182, 183; 183, identifier:conf | def extract_conf_from(mod, conf=ModuleConfig(CONF_SPEC), depth=0, max_depth=2):
for key, default_value in six.iteritems(conf):
conf[key] = _get_key_from_module(mod, key, default_value)
try:
filtered_apps = [app for app in conf['apps'] if app not in BLACKLIST]
except TypeError:
pass
except Exception as e:
warnings.warn('Error %s during loading %s' % (e, conf['apps']))
for app in filtered_apps:
try:
app_module = import_module(app)
if app_module != mod:
app_module = _get_correct_module(app_module)
if depth < max_depth:
mod_conf = extract_conf_from(app_module, depth=depth+1)
for k, v in six.iteritems(mod_conf):
if k == 'config':
continue
if isinstance(v, dict):
conf[k].update(v)
elif isinstance(v, (list, tuple)):
conf[k] = merge(conf[k], v)
except Exception as e:
pass
return conf |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:render_region; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 4, default_parameter; 4, 5; 4, 6; 5, identifier:widget; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:request; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:view; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:page; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:region; 18, None; 19, block; 19, 20; 19, 40; 19, 54; 19, 63; 19, 72; 19, 101; 19, 105; 19, 179; 19, 186; 19, 224; 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:request; 26, identifier:dict; 27, block; 27, 28; 27, 34; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:request; 32, identifier:query_string; 33, None; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:request; 38, identifier:method; 39, string:"GET"; 40, if_statement; 40, 41; 40, 47; 41, not_operator; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:hasattr; 44, argument_list; 44, 45; 44, 46; 45, identifier:request; 46, string:'_feincms_extra_context'; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:request; 52, identifier:_feincms_extra_context; 53, dictionary; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:leonardo_page; 57, conditional_expression:if; 57, 58; 57, 61; 57, 62; 58, attribute; 58, 59; 58, 60; 59, identifier:widget; 60, identifier:parent; 61, identifier:widget; 62, identifier:page; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:render_region; 66, conditional_expression:if; 66, 67; 66, 70; 66, 71; 67, attribute; 67, 68; 67, 69; 68, identifier:widget; 69, identifier:region; 70, identifier:widget; 71, identifier:region; 72, for_statement; 72, 73; 72, 74; 72, 87; 73, identifier:fn; 74, call; 74, 75; 74, 76; 75, identifier:reversed; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:list; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:leonardo_page; 84, identifier:request_processors; 85, identifier:values; 86, argument_list; 87, block; 87, 88; 88, try_statement; 88, 89; 88, 98; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:r; 93, call; 93, 94; 93, 95; 94, identifier:fn; 95, argument_list; 95, 96; 95, 97; 96, identifier:leonardo_page; 97, identifier:request; 98, except_clause; 98, 99; 99, block; 99, 100; 100, pass_statement; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:contents; 104, dictionary; 105, for_statement; 105, 106; 105, 107; 105, 120; 106, identifier:content; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:leonardo_page; 111, identifier:content; 112, identifier:all_of_type; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:tuple; 116, argument_list; 116, 117; 117, attribute; 117, 118; 117, 119; 118, identifier:leonardo_page; 119, identifier:_feincms_content_types_with_process; 120, block; 120, 121; 121, try_statement; 121, 122; 121, 135; 121, 138; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:r; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:content; 129, identifier:process; 130, argument_list; 130, 131; 130, 132; 131, identifier:request; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:view; 134, identifier:view; 135, except_clause; 135, 136; 136, block; 136, 137; 137, pass_statement; 138, else_clause; 138, 139; 139, block; 139, 140; 140, if_statement; 140, 141; 140, 149; 140, 169; 141, not_operator; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:isinstance; 144, argument_list; 144, 145; 144, 146; 145, identifier:r; 146, attribute; 146, 147; 146, 148; 147, identifier:six; 148, identifier:string_types; 149, block; 149, 150; 149, 156; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:r; 154, identifier:render; 155, argument_list; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 163; 158, subscript; 158, 159; 158, 160; 159, identifier:contents; 160, attribute; 160, 161; 160, 162; 161, identifier:content; 162, identifier:fe_identifier; 163, call; 163, 164; 163, 165; 164, identifier:getattr; 165, argument_list; 165, 166; 165, 167; 165, 168; 166, identifier:r; 167, string:'content'; 168, identifier:r; 169, else_clause; 169, 170; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 178; 173, subscript; 173, 174; 173, 175; 174, identifier:contents; 175, attribute; 175, 176; 175, 177; 176, identifier:content; 177, identifier:fe_identifier; 178, identifier:r; 179, import_from_statement; 179, 180; 179, 184; 180, dotted_name; 180, 181; 180, 182; 180, 183; 181, identifier:leonardo; 182, identifier:templatetags; 183, identifier:leonardo_tags; 184, dotted_name; 184, 185; 185, identifier:_render_content; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:region_content; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, string:''; 192, identifier:join; 193, generator_expression; 193, 194; 193, 215; 194, conditional_expression:if; 194, 195; 194, 200; 194, 205; 195, subscript; 195, 196; 195, 197; 196, identifier:contents; 197, attribute; 197, 198; 197, 199; 198, identifier:content; 199, identifier:fe_identifier; 200, comparison_operator:in; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:content; 203, identifier:fe_identifier; 204, identifier:contents; 205, call; 205, 206; 205, 207; 206, identifier:_render_content; 207, argument_list; 207, 208; 207, 209; 207, 212; 208, identifier:content; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:request; 211, identifier:request; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:context; 214, dictionary; 215, for_in_clause; 215, 216; 215, 217; 216, identifier:content; 217, call; 217, 218; 217, 219; 218, identifier:getattr; 219, argument_list; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:leonardo_page; 222, identifier:content; 223, identifier:render_region; 224, return_statement; 224, 225; 225, identifier:region_content | def render_region(widget=None, request=None, view=None,
page=None, region=None):
if not isinstance(request, dict):
request.query_string = None
request.method = "GET"
if not hasattr(request, '_feincms_extra_context'):
request._feincms_extra_context = {}
leonardo_page = widget.parent if widget else page
render_region = widget.region if widget else region
for fn in reversed(list(leonardo_page.request_processors.values())):
try:
r = fn(leonardo_page, request)
except:
pass
contents = {}
for content in leonardo_page.content.all_of_type(tuple(
leonardo_page._feincms_content_types_with_process)):
try:
r = content.process(request, view=view)
except:
pass
else:
if not isinstance(r, six.string_types):
r.render()
contents[content.fe_identifier] = getattr(r, 'content', r)
else:
contents[content.fe_identifier] = r
from leonardo.templatetags.leonardo_tags import _render_content
region_content = ''.join(
contents[content.fe_identifier] if content.fe_identifier in contents else _render_content(
content, request=request, context={})
for content in getattr(leonardo_page.content, render_region))
return region_content |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:handle_ajax_method; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:request; 6, identifier:method; 7, block; 7, 8; 7, 12; 7, 39; 7, 47; 7, 55; 7, 68; 7, 80; 7, 314; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:response; 11, dictionary; 12, function_definition; 12, 13; 12, 14; 12, 17; 13, function_name:get_param; 14, parameters; 14, 15; 14, 16; 15, identifier:request; 16, identifier:name; 17, block; 17, 18; 18, try_statement; 18, 19; 18, 26; 19, block; 19, 20; 20, return_statement; 20, 21; 21, subscript; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:request; 24, identifier:POST; 25, identifier:name; 26, except_clause; 26, 27; 26, 28; 27, identifier:KeyError; 28, block; 28, 29; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:request; 34, identifier:GET; 35, identifier:get; 36, argument_list; 36, 37; 36, 38; 37, identifier:name; 38, None; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:widget_id; 42, call; 42, 43; 42, 44; 43, identifier:get_param; 44, argument_list; 44, 45; 44, 46; 45, identifier:request; 46, string:"widget_id"; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:class_name; 50, call; 50, 51; 50, 52; 51, identifier:get_param; 52, argument_list; 52, 53; 52, 54; 53, identifier:request; 54, string:"class_name"; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:in; 56, 57; 56, 58; 57, identifier:method; 58, string:'widget_content'; 59, block; 59, 60; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:render_widget; 65, argument_list; 65, 66; 65, 67; 66, identifier:request; 67, identifier:widget_id; 68, if_statement; 68, 69; 68, 72; 69, comparison_operator:==; 69, 70; 69, 71; 70, identifier:method; 71, string:'region'; 72, block; 72, 73; 73, return_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:render_region; 78, argument_list; 78, 79; 79, identifier:request; 80, if_statement; 80, 81; 80, 82; 80, 124; 81, identifier:widget_id; 82, block; 82, 83; 82, 90; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:widget; 86, call; 86, 87; 86, 88; 87, identifier:get_widget_from_id; 88, argument_list; 88, 89; 89, identifier:widget_id; 90, try_statement; 90, 91; 90, 100; 90, 113; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:func; 95, call; 95, 96; 95, 97; 96, identifier:getattr; 97, argument_list; 97, 98; 97, 99; 98, identifier:widget; 99, identifier:method; 100, except_clause; 100, 101; 100, 102; 101, identifier:AttributeError; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:response; 107, string:"exception"; 108, binary_operator:%; 108, 109; 108, 110; 109, string:"%s method is not implmented on %s"; 110, tuple; 110, 111; 110, 112; 111, identifier:method; 112, identifier:widget; 113, else_clause; 113, 114; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:response; 119, string:"result"; 120, call; 120, 121; 120, 122; 121, identifier:func; 122, argument_list; 122, 123; 123, identifier:request; 124, elif_clause; 124, 125; 124, 126; 125, identifier:class_name; 126, block; 126, 127; 126, 164; 127, try_statement; 127, 128; 127, 142; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:cls; 132, call; 132, 133; 132, 134; 133, identifier:get_model; 134, argument_list; 134, 135; 135, list_splat; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:class_name; 139, identifier:split; 140, argument_list; 140, 141; 141, string:'.'; 142, except_clause; 142, 143; 142, 147; 143, as_pattern; 143, 144; 143, 145; 144, identifier:Exception; 145, as_pattern_target; 145, 146; 146, identifier:e; 147, block; 147, 148; 147, 157; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:response; 152, string:"exception"; 153, call; 153, 154; 153, 155; 154, identifier:str; 155, argument_list; 155, 156; 156, identifier:e; 157, return_statement; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:JsonResponse; 160, argument_list; 160, 161; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:data; 163, identifier:response; 164, if_statement; 164, 165; 164, 168; 164, 276; 165, comparison_operator:==; 165, 166; 165, 167; 166, identifier:method; 167, string:"render_preview"; 168, block; 168, 169; 168, 181; 168, 190; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:FormCls; 172, call; 172, 173; 172, 174; 173, identifier:modelform_factory; 174, argument_list; 174, 175; 174, 176; 175, identifier:cls; 176, keyword_argument; 176, 177; 176, 178; 177, identifier:exclude; 178, tuple; 178, 179; 178, 180; 179, string:'pk'; 180, string:'id'; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:form; 184, call; 184, 185; 184, 186; 185, identifier:FormCls; 186, argument_list; 186, 187; 187, attribute; 187, 188; 187, 189; 188, identifier:request; 189, identifier:POST; 190, if_statement; 190, 191; 190, 196; 190, 260; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:form; 194, identifier:is_valid; 195, argument_list; 196, block; 196, 197; 196, 207; 196, 213; 196, 254; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:widget; 200, call; 200, 201; 200, 202; 201, identifier:cls; 202, argument_list; 202, 203; 203, dictionary_splat; 203, 204; 204, attribute; 204, 205; 204, 206; 205, identifier:form; 206, identifier:cleaned_data; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:request; 211, identifier:frontend_editing; 212, False; 213, try_statement; 213, 214; 213, 228; 213, 246; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:content; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:widget; 221, identifier:render; 222, argument_list; 222, 223; 223, dictionary_splat; 223, 224; 224, dictionary; 224, 225; 225, pair; 225, 226; 225, 227; 226, string:'request'; 227, identifier:request; 228, except_clause; 228, 229; 228, 233; 229, as_pattern; 229, 230; 229, 231; 230, identifier:Exception; 231, as_pattern_target; 231, 232; 232, identifier:e; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:response; 238, string:'result'; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:widget; 242, identifier:handle_exception; 243, argument_list; 243, 244; 243, 245; 244, identifier:request; 245, identifier:e; 246, else_clause; 246, 247; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 253; 250, subscript; 250, 251; 250, 252; 251, identifier:response; 252, string:'result'; 253, identifier:content; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 259; 256, subscript; 256, 257; 256, 258; 257, identifier:response; 258, string:'id'; 259, identifier:widget_id; 260, else_clause; 260, 261; 261, block; 261, 262; 261, 270; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 267; 264, subscript; 264, 265; 264, 266; 265, identifier:response; 266, string:'result'; 267, attribute; 267, 268; 267, 269; 268, identifier:form; 269, identifier:errors; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 275; 272, subscript; 272, 273; 272, 274; 273, identifier:response; 274, string:'id'; 275, identifier:widget_id; 276, else_clause; 276, 277; 277, block; 277, 278; 278, try_statement; 278, 279; 278, 288; 278, 303; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:func; 283, call; 283, 284; 283, 285; 284, identifier:getattr; 285, argument_list; 285, 286; 285, 287; 286, identifier:cls; 287, identifier:method; 288, except_clause; 288, 289; 288, 293; 289, as_pattern; 289, 290; 289, 291; 290, identifier:Exception; 291, as_pattern_target; 291, 292; 292, identifier:e; 293, block; 293, 294; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 299; 296, subscript; 296, 297; 296, 298; 297, identifier:response; 298, string:"exception"; 299, call; 299, 300; 299, 301; 300, identifier:str; 301, argument_list; 301, 302; 302, identifier:e; 303, else_clause; 303, 304; 304, block; 304, 305; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 310; 307, subscript; 307, 308; 307, 309; 308, identifier:response; 309, string:"result"; 310, call; 310, 311; 310, 312; 311, identifier:func; 312, argument_list; 312, 313; 313, identifier:request; 314, return_statement; 314, 315; 315, call; 315, 316; 315, 317; 316, identifier:JsonResponse; 317, argument_list; 317, 318; 318, keyword_argument; 318, 319; 318, 320; 319, identifier:data; 320, identifier:response | def handle_ajax_method(self, request, method):
response = {}
def get_param(request, name):
try:
return request.POST[name]
except KeyError:
return request.GET.get(name, None)
widget_id = get_param(request, "widget_id")
class_name = get_param(request, "class_name")
if method in 'widget_content':
return self.render_widget(request, widget_id)
if method == 'region':
return self.render_region(request)
if widget_id:
widget = get_widget_from_id(widget_id)
try:
func = getattr(widget, method)
except AttributeError:
response["exception"] = "%s method is not implmented on %s" % (
method, widget)
else:
response["result"] = func(request)
elif class_name:
try:
cls = get_model(*class_name.split('.'))
except Exception as e:
response["exception"] = str(e)
return JsonResponse(data=response)
if method == "render_preview":
FormCls = modelform_factory(cls, exclude=('pk', 'id'))
form = FormCls(request.POST)
if form.is_valid():
widget = cls(**form.cleaned_data)
request.frontend_editing = False
try:
content = widget.render(**{'request': request})
except Exception as e:
response['result'] = widget.handle_exception(request, e)
else:
response['result'] = content
response['id'] = widget_id
else:
response['result'] = form.errors
response['id'] = widget_id
else:
try:
func = getattr(cls, method)
except Exception as e:
response["exception"] = str(e)
else:
response["result"] = func(request)
return JsonResponse(data=response) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:ajax_upload; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:request; 6, default_parameter; 6, 7; 6, 8; 7, identifier:folder_id; 8, None; 9, block; 9, 10; 9, 21; 9, 25; 9, 32; 9, 36; 9, 74; 9, 100; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:mimetype; 13, conditional_expression:if; 13, 14; 13, 15; 13, 20; 14, string:"application/json"; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:request; 18, identifier:is_ajax; 19, argument_list; 20, string:"text/html"; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:content_type_key; 24, string:'content_type'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:response_params; 28, dictionary; 28, 29; 29, pair; 29, 30; 29, 31; 30, identifier:content_type_key; 31, identifier:mimetype; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:folder; 35, None; 36, if_statement; 36, 37; 36, 38; 37, identifier:folder_id; 38, block; 38, 39; 39, try_statement; 39, 40; 39, 54; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:folder; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:Folder; 48, identifier:objects; 49, identifier:get; 50, argument_list; 50, 51; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:pk; 53, identifier:folder_id; 54, except_clause; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:Folder; 57, identifier:DoesNotExist; 58, block; 58, 59; 59, return_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:HttpResponse; 62, argument_list; 62, 63; 62, 72; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:json; 66, identifier:dumps; 67, argument_list; 67, 68; 68, dictionary; 68, 69; 69, pair; 69, 70; 69, 71; 70, string:'error'; 71, identifier:NO_FOLDER_ERROR; 72, dictionary_splat; 72, 73; 73, identifier:response_params; 74, if_statement; 74, 75; 74, 84; 75, boolean_operator:and; 75, 76; 75, 77; 76, identifier:folder; 77, not_operator; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:folder; 81, identifier:has_add_children_permission; 82, argument_list; 82, 83; 83, identifier:request; 84, block; 84, 85; 85, return_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:HttpResponse; 88, argument_list; 88, 89; 88, 98; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:json; 92, identifier:dumps; 93, argument_list; 93, 94; 94, dictionary; 94, 95; 95, pair; 95, 96; 95, 97; 96, string:'error'; 97, identifier:NO_PERMISSIONS_FOR_FOLDER; 98, dictionary_splat; 98, 99; 99, identifier:response_params; 100, try_statement; 100, 101; 100, 312; 101, block; 101, 102; 101, 134; 101, 173; 101, 194; 102, if_statement; 102, 103; 102, 111; 102, 122; 103, comparison_operator:==; 103, 104; 103, 110; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, attribute; 107, 108; 107, 109; 108, identifier:request; 109, identifier:FILES; 110, integer:1; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 118; 114, pattern_list; 114, 115; 114, 116; 114, 117; 115, identifier:upload; 116, identifier:filename; 117, identifier:is_raw; 118, call; 118, 119; 118, 120; 119, identifier:handle_request_files_upload; 120, argument_list; 120, 121; 121, identifier:request; 122, else_clause; 122, 123; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 130; 126, pattern_list; 126, 127; 126, 128; 126, 129; 127, identifier:upload; 128, identifier:filename; 129, identifier:is_raw; 130, call; 130, 131; 130, 132; 131, identifier:handle_upload; 132, argument_list; 132, 133; 133, identifier:request; 134, for_statement; 134, 135; 134, 136; 134, 139; 135, identifier:filer_class; 136, attribute; 136, 137; 136, 138; 137, identifier:media_settings; 138, identifier:MEDIA_FILE_MODELS; 139, block; 139, 140; 139, 147; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:FileSubClass; 143, call; 143, 144; 143, 145; 144, identifier:load_object; 145, argument_list; 145, 146; 146, identifier:filer_class; 147, if_statement; 147, 148; 147, 156; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:FileSubClass; 151, identifier:matches_file_type; 152, argument_list; 152, 153; 152, 154; 152, 155; 153, identifier:filename; 154, identifier:upload; 155, identifier:request; 156, block; 156, 157; 156, 172; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:FileForm; 160, call; 160, 161; 160, 162; 161, identifier:modelform_factory; 162, argument_list; 162, 163; 162, 166; 163, keyword_argument; 163, 164; 163, 165; 164, identifier:model; 165, identifier:FileSubClass; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:fields; 168, tuple; 168, 169; 168, 170; 168, 171; 169, string:'original_filename'; 170, string:'owner'; 171, string:'file'; 172, break_statement; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:uploadform; 176, call; 176, 177; 176, 178; 177, identifier:FileForm; 178, argument_list; 178, 179; 178, 190; 179, dictionary; 179, 180; 179, 183; 180, pair; 180, 181; 180, 182; 181, string:'original_filename'; 182, identifier:filename; 183, pair; 183, 184; 183, 185; 184, string:'owner'; 185, attribute; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:request; 188, identifier:user; 189, identifier:pk; 190, dictionary; 190, 191; 191, pair; 191, 192; 191, 193; 192, string:'file'; 193, identifier:upload; 194, if_statement; 194, 195; 194, 200; 194, 269; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:uploadform; 198, identifier:is_valid; 199, argument_list; 200, block; 200, 201; 200, 212; 200, 220; 200, 226; 200, 232; 200, 257; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:file_obj; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:uploadform; 207, identifier:save; 208, argument_list; 208, 209; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:commit; 211, False; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:file_obj; 216, identifier:is_public; 217, attribute; 217, 218; 217, 219; 218, identifier:settings; 219, identifier:MEDIA_IS_PUBLIC_DEFAULT; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:file_obj; 224, identifier:folder; 225, identifier:folder; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:file_obj; 230, identifier:save; 231, argument_list; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:json_response; 235, dictionary; 235, 236; 235, 243; 235, 246; 235, 252; 236, pair; 236, 237; 236, 238; 237, string:'thumbnail'; 238, subscript; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:file_obj; 241, identifier:icons; 242, string:'32'; 243, pair; 243, 244; 243, 245; 244, string:'alt_text'; 245, string:''; 246, pair; 246, 247; 246, 248; 247, string:'label'; 248, call; 248, 249; 248, 250; 249, identifier:str; 250, argument_list; 250, 251; 251, identifier:file_obj; 252, pair; 252, 253; 252, 254; 253, string:'file_id'; 254, attribute; 254, 255; 254, 256; 255, identifier:file_obj; 256, identifier:pk; 257, return_statement; 257, 258; 258, call; 258, 259; 258, 260; 259, identifier:HttpResponse; 260, argument_list; 260, 261; 260, 267; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:json; 264, identifier:dumps; 265, argument_list; 265, 266; 266, identifier:json_response; 267, dictionary_splat; 267, 268; 268, identifier:response_params; 269, else_clause; 269, 270; 270, block; 270, 271; 270, 304; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:form_errors; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, string:'; '; 277, identifier:join; 278, argument_list; 278, 279; 279, list_comprehension; 279, 280; 279, 290; 280, binary_operator:%; 280, 281; 280, 282; 281, string:'%s: %s'; 282, tuple; 282, 283; 282, 284; 283, identifier:field; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, string:', '; 287, identifier:join; 288, argument_list; 288, 289; 289, identifier:errors; 290, for_in_clause; 290, 291; 290, 294; 291, pattern_list; 291, 292; 291, 293; 292, identifier:field; 293, identifier:errors; 294, call; 294, 295; 294, 296; 295, identifier:list; 296, argument_list; 296, 297; 297, call; 297, 298; 297, 303; 298, attribute; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:uploadform; 301, identifier:errors; 302, identifier:items; 303, argument_list; 304, raise_statement; 304, 305; 305, call; 305, 306; 305, 307; 306, identifier:UploadException; 307, argument_list; 307, 308; 308, binary_operator:%; 308, 309; 308, 310; 309, string:"AJAX request not valid: form invalid '%s'"; 310, tuple; 310, 311; 311, identifier:form_errors; 312, except_clause; 312, 313; 312, 317; 313, as_pattern; 313, 314; 313, 315; 314, identifier:UploadException; 315, as_pattern_target; 315, 316; 316, identifier:e; 317, block; 317, 318; 318, return_statement; 318, 319; 319, call; 319, 320; 319, 321; 320, identifier:HttpResponse; 321, argument_list; 321, 322; 321, 334; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:json; 325, identifier:dumps; 326, argument_list; 326, 327; 327, dictionary; 327, 328; 328, pair; 328, 329; 328, 330; 329, string:'error'; 330, call; 330, 331; 330, 332; 331, identifier:str; 332, argument_list; 332, 333; 333, identifier:e; 334, dictionary_splat; 334, 335; 335, identifier:response_params | def ajax_upload(self, request, folder_id=None):
mimetype = "application/json" if request.is_ajax() else "text/html"
content_type_key = 'content_type'
response_params = {content_type_key: mimetype}
folder = None
if folder_id:
try:
folder = Folder.objects.get(pk=folder_id)
except Folder.DoesNotExist:
return HttpResponse(json.dumps({'error': NO_FOLDER_ERROR}),
**response_params)
if folder and not folder.has_add_children_permission(request):
return HttpResponse(
json.dumps({'error': NO_PERMISSIONS_FOR_FOLDER}),
**response_params)
try:
if len(request.FILES) == 1:
upload, filename, is_raw = handle_request_files_upload(request)
else:
upload, filename, is_raw = handle_upload(request)
for filer_class in media_settings.MEDIA_FILE_MODELS:
FileSubClass = load_object(filer_class)
if FileSubClass.matches_file_type(filename, upload, request):
FileForm = modelform_factory(
model=FileSubClass,
fields=('original_filename', 'owner', 'file')
)
break
uploadform = FileForm({'original_filename': filename,
'owner': request.user.pk},
{'file': upload})
if uploadform.is_valid():
file_obj = uploadform.save(commit=False)
file_obj.is_public = settings.MEDIA_IS_PUBLIC_DEFAULT
file_obj.folder = folder
file_obj.save()
json_response = {
'thumbnail': file_obj.icons['32'],
'alt_text': '',
'label': str(file_obj),
'file_id': file_obj.pk,
}
return HttpResponse(json.dumps(json_response),
**response_params)
else:
form_errors = '; '.join(['%s: %s' % (
field,
', '.join(errors)) for field, errors in list(uploadform.errors.items())
])
raise UploadException(
"AJAX request not valid: form invalid '%s'" % (form_errors,))
except UploadException as e:
return HttpResponse(json.dumps({'error': str(e)}),
**response_params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:collect; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 20; 5, 30; 5, 315; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:ignore_patterns; 11, list:[
'*.png', '*.jpg', '*.js', '*.gif', '*.ttf', '*.md', '*.rst',
'*.svg']; 11, 12; 11, 13; 11, 14; 11, 15; 11, 16; 11, 17; 11, 18; 11, 19; 12, string:'*.png'; 13, string:'*.jpg'; 14, string:'*.js'; 15, string:'*.gif'; 16, string:'*.ttf'; 17, string:'*.md'; 18, string:'*.rst'; 19, string:'*.svg'; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:page_themes; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:PageTheme; 27, identifier:objects; 28, identifier:all; 29, argument_list; 30, for_statement; 30, 31; 30, 32; 30, 35; 31, identifier:finder; 32, call; 32, 33; 32, 34; 33, identifier:get_finders; 34, argument_list; 35, block; 35, 36; 36, for_statement; 36, 37; 36, 40; 36, 48; 37, pattern_list; 37, 38; 37, 39; 38, identifier:path; 39, identifier:storage; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:finder; 43, identifier:list; 44, argument_list; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:ignore_patterns; 48, block; 48, 49; 49, for_statement; 49, 50; 49, 51; 49, 52; 50, identifier:t; 51, identifier:page_themes; 52, block; 52, 53; 52, 72; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:static_path; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, string:'themes/{0}'; 59, identifier:format; 60, argument_list; 60, 61; 61, subscript; 61, 62; 61, 70; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:t; 66, identifier:name; 67, identifier:split; 68, argument_list; 68, 69; 69, string:'/'; 70, unary_operator:-; 70, 71; 71, integer:1; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:in; 73, 74; 73, 75; 74, identifier:static_path; 75, identifier:path; 76, block; 76, 77; 76, 125; 76, 157; 77, try_statement; 77, 78; 77, 94; 77, 104; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:page_theme; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:PageTheme; 86, identifier:objects; 87, identifier:get; 88, argument_list; 88, 89; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:id; 91, attribute; 91, 92; 91, 93; 92, identifier:t; 93, identifier:id; 94, except_clause; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:PageTheme; 97, identifier:DoesNotExist; 98, block; 98, 99; 99, raise_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:Exception; 102, argument_list; 102, 103; 103, string:"Run sync_themes before this command"; 104, except_clause; 104, 105; 104, 109; 105, as_pattern; 105, 106; 105, 107; 106, identifier:Exception; 107, as_pattern_target; 107, 108; 108, identifier:e; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:stdout; 116, identifier:write; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, string:"Cannot load {} into database original error: {}"; 121, identifier:format; 122, argument_list; 122, 123; 122, 124; 123, identifier:t; 124, identifier:e; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:skins_path; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:os; 132, identifier:path; 133, identifier:join; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:storage; 138, identifier:path; 139, argument_list; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, string:'/'; 143, identifier:join; 144, argument_list; 144, 145; 145, subscript; 145, 146; 145, 152; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:path; 149, identifier:split; 150, argument_list; 150, 151; 151, string:'/'; 152, slice; 152, 153; 152, 154; 152, 155; 153, integer:0; 154, colon; 155, unary_operator:-; 155, 156; 156, integer:1; 157, for_statement; 157, 158; 157, 162; 157, 168; 158, pattern_list; 158, 159; 158, 160; 158, 161; 159, identifier:dirpath; 160, identifier:skins; 161, identifier:filenames; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:os; 165, identifier:walk; 166, argument_list; 166, 167; 167, identifier:skins_path; 168, block; 168, 169; 169, for_statement; 169, 170; 169, 171; 169, 181; 170, identifier:skin; 171, list_comprehension; 171, 172; 171, 173; 171, 176; 172, identifier:s; 173, for_in_clause; 173, 174; 173, 175; 174, identifier:s; 175, identifier:skins; 176, if_clause; 176, 177; 177, comparison_operator:not; 177, 178; 177, 179; 178, identifier:s; 179, list:['fonts']; 179, 180; 180, string:'fonts'; 181, block; 181, 182; 182, for_statement; 182, 183; 182, 187; 182, 201; 183, pattern_list; 183, 184; 183, 185; 183, 186; 184, identifier:skin_dirpath; 185, identifier:skins; 186, identifier:filenames; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:os; 190, identifier:walk; 191, argument_list; 191, 192; 192, call; 192, 193; 192, 198; 193, attribute; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:os; 196, identifier:path; 197, identifier:join; 198, argument_list; 198, 199; 198, 200; 199, identifier:dirpath; 200, identifier:skin; 201, block; 201, 202; 201, 227; 201, 303; 201, 309; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 207; 204, pattern_list; 204, 205; 204, 206; 205, identifier:skin; 206, identifier:created; 207, call; 207, 208; 207, 213; 208, attribute; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:PageColorScheme; 211, identifier:objects; 212, identifier:get_or_create; 213, argument_list; 213, 214; 213, 217; 213, 220; 214, keyword_argument; 214, 215; 214, 216; 215, identifier:theme; 216, identifier:page_theme; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:label; 219, identifier:skin; 220, keyword_argument; 220, 221; 220, 222; 221, identifier:name; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:skin; 225, identifier:title; 226, argument_list; 227, for_statement; 227, 228; 227, 229; 227, 230; 228, identifier:f; 229, identifier:filenames; 230, block; 230, 231; 231, if_statement; 231, 232; 231, 235; 231, 267; 232, comparison_operator:in; 232, 233; 232, 234; 233, string:'styles'; 234, identifier:f; 235, block; 235, 236; 236, with_statement; 236, 237; 236, 256; 237, with_clause; 237, 238; 238, with_item; 238, 239; 239, as_pattern; 239, 240; 239, 254; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:codecs; 243, identifier:open; 244, argument_list; 244, 245; 245, call; 245, 246; 245, 251; 246, attribute; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:os; 249, identifier:path; 250, identifier:join; 251, argument_list; 251, 252; 251, 253; 252, identifier:skin_dirpath; 253, identifier:f; 254, as_pattern_target; 254, 255; 255, identifier:style_file; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:skin; 261, identifier:styles; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:style_file; 265, identifier:read; 266, argument_list; 267, elif_clause; 267, 268; 267, 271; 268, comparison_operator:in; 268, 269; 268, 270; 269, string:'variables'; 270, identifier:f; 271, block; 271, 272; 272, with_statement; 272, 273; 272, 292; 273, with_clause; 273, 274; 274, with_item; 274, 275; 275, as_pattern; 275, 276; 275, 290; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:codecs; 279, identifier:open; 280, argument_list; 280, 281; 281, call; 281, 282; 281, 287; 282, attribute; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:os; 285, identifier:path; 286, identifier:join; 287, argument_list; 287, 288; 287, 289; 288, identifier:skin_dirpath; 289, identifier:f; 290, as_pattern_target; 290, 291; 291, identifier:variables_file; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:skin; 297, identifier:variables; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:variables_file; 301, identifier:read; 302, argument_list; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:skin; 307, identifier:save; 308, argument_list; 309, expression_statement; 309, 310; 310, augmented_assignment:+=; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:skins_updated; 314, integer:1; 315, expression_statement; 315, 316; 316, augmented_assignment:+=; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:self; 319, identifier:page_themes_updated; 320, call; 320, 321; 320, 322; 321, identifier:len; 322, argument_list; 322, 323; 323, identifier:page_themes | def collect(self):
self.ignore_patterns = [
'*.png', '*.jpg', '*.js', '*.gif', '*.ttf', '*.md', '*.rst',
'*.svg']
page_themes = PageTheme.objects.all()
for finder in get_finders():
for path, storage in finder.list(self.ignore_patterns):
for t in page_themes:
static_path = 'themes/{0}'.format(t.name.split('/')[-1])
if static_path in path:
try:
page_theme = PageTheme.objects.get(id=t.id)
except PageTheme.DoesNotExist:
raise Exception(
"Run sync_themes before this command")
except Exception as e:
self.stdout.write(
"Cannot load {} into database original error: {}".format(t, e))
skins_path = os.path.join(
storage.path('/'.join(path.split('/')[0:-1])))
for dirpath, skins, filenames in os.walk(skins_path):
for skin in [s for s in skins if s not in ['fonts']]:
for skin_dirpath, skins, filenames in os.walk(os.path.join(dirpath, skin)):
skin, created = PageColorScheme.objects.get_or_create(
theme=page_theme, label=skin, name=skin.title())
for f in filenames:
if 'styles' in f:
with codecs.open(os.path.join(skin_dirpath, f)) as style_file:
skin.styles = style_file.read()
elif 'variables' in f:
with codecs.open(os.path.join(skin_dirpath, f)) as variables_file:
skin.variables = variables_file.read()
skin.save()
self.skins_updated += 1
self.page_themes_updated += len(page_themes) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:urlpatterns; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 189; 6, expression_statement; 6, 7; 7, string:'''load and decorate urls from all modules
then store it as cached property for less loading
'''; 8, if_statement; 8, 9; 8, 15; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:hasattr; 12, argument_list; 12, 13; 12, 14; 13, identifier:self; 14, string:'_urlspatterns'; 15, block; 15, 16; 15, 20; 15, 90; 15, 96; 15, 183; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:urlpatterns; 19, list:[]; 20, for_statement; 20, 21; 20, 22; 20, 25; 21, identifier:mod; 22, attribute; 22, 23; 22, 24; 23, identifier:leonardo; 24, identifier:modules; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 31; 27, call; 27, 28; 27, 29; 28, identifier:is_leonardo_module; 29, argument_list; 29, 30; 30, identifier:mod; 31, block; 31, 32; 31, 39; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:conf; 35, call; 35, 36; 35, 37; 36, identifier:get_conf_from_module; 37, argument_list; 37, 38; 38, identifier:mod; 39, if_statement; 39, 40; 39, 45; 40, call; 40, 41; 40, 42; 41, identifier:module_has_submodule; 42, argument_list; 42, 43; 42, 44; 43, identifier:mod; 44, string:'urls'; 45, block; 45, 46; 45, 56; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:urls_mod; 49, call; 49, 50; 49, 51; 50, identifier:import_module; 51, argument_list; 51, 52; 51, 53; 52, string:'.urls'; 53, attribute; 53, 54; 53, 55; 54, identifier:mod; 55, identifier:__name__; 56, if_statement; 56, 57; 56, 62; 57, call; 57, 58; 57, 59; 58, identifier:hasattr; 59, argument_list; 59, 60; 59, 61; 60, identifier:urls_mod; 61, string:'urlpatterns'; 62, block; 62, 63; 63, if_statement; 63, 64; 63, 67; 63, 74; 64, subscript; 64, 65; 64, 66; 65, identifier:conf; 66, string:'public'; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, augmented_assignment:+=; 69, 70; 69, 71; 70, identifier:urlpatterns; 71, attribute; 71, 72; 71, 73; 72, identifier:urls_mod; 73, identifier:urlpatterns; 74, else_clause; 74, 75; 75, block; 75, 76; 75, 84; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:_decorate_urlconf; 79, argument_list; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:urls_mod; 82, identifier:urlpatterns; 83, identifier:require_auth; 84, expression_statement; 84, 85; 85, augmented_assignment:+=; 85, 86; 85, 87; 86, identifier:urlpatterns; 87, attribute; 87, 88; 87, 89; 88, identifier:urls_mod; 89, identifier:urlpatterns; 90, import_from_statement; 90, 91; 90, 94; 91, dotted_name; 91, 92; 91, 93; 92, identifier:django; 93, identifier:conf; 94, dotted_name; 94, 95; 95, identifier:settings; 96, for_statement; 96, 97; 96, 100; 96, 111; 97, pattern_list; 97, 98; 97, 99; 98, identifier:urls_conf; 99, identifier:conf; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:six; 103, identifier:iteritems; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:getattr; 107, argument_list; 107, 108; 107, 109; 107, 110; 108, identifier:settings; 109, string:'MODULE_URLS'; 110, dictionary; 111, block; 111, 112; 112, try_statement; 112, 113; 112, 165; 113, block; 113, 114; 114, if_statement; 114, 115; 114, 118; 114, 135; 115, subscript; 115, 116; 115, 117; 116, identifier:conf; 117, string:'is_public'; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, augmented_assignment:+=; 120, 121; 120, 122; 120, 123; 121, identifier:urlpatterns; 122, line_continuation:\; 123, call; 123, 124; 123, 125; 124, identifier:patterns; 125, argument_list; 125, 126; 125, 127; 126, string:''; 127, call; 127, 128; 127, 129; 128, identifier:url; 129, argument_list; 129, 130; 129, 131; 130, string:r''; 131, call; 131, 132; 131, 133; 132, identifier:include; 133, argument_list; 133, 134; 134, identifier:urls_conf; 135, else_clause; 135, 136; 136, block; 136, 137; 136, 150; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:_decorate_urlconf; 140, argument_list; 140, 141; 140, 149; 141, call; 141, 142; 141, 143; 142, identifier:url; 143, argument_list; 143, 144; 143, 145; 144, string:r''; 145, call; 145, 146; 145, 147; 146, identifier:include; 147, argument_list; 147, 148; 148, identifier:urls_conf; 149, identifier:require_auth; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 153; 152, identifier:urlpatterns; 153, call; 153, 154; 153, 155; 154, identifier:patterns; 155, argument_list; 155, 156; 155, 157; 156, string:''; 157, call; 157, 158; 157, 159; 158, identifier:url; 159, argument_list; 159, 160; 159, 161; 160, string:r''; 161, call; 161, 162; 161, 163; 162, identifier:include; 163, argument_list; 163, 164; 164, identifier:urls_conf; 165, except_clause; 165, 166; 165, 170; 166, as_pattern; 166, 167; 166, 168; 167, identifier:Exception; 168, as_pattern_target; 168, 169; 169, identifier:e; 170, block; 170, 171; 171, raise_statement; 171, 172; 172, call; 172, 173; 172, 174; 173, identifier:Exception; 174, argument_list; 174, 175; 175, binary_operator:%; 175, 176; 175, 177; 176, string:'raised %s during loading %s'; 177, tuple; 177, 178; 177, 182; 178, call; 178, 179; 178, 180; 179, identifier:str; 180, argument_list; 180, 181; 181, identifier:e; 182, identifier:urls_conf; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:_urlpatterns; 188, identifier:urlpatterns; 189, return_statement; 189, 190; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:_urlpatterns | def urlpatterns(self):
'''load and decorate urls from all modules
then store it as cached property for less loading
'''
if not hasattr(self, '_urlspatterns'):
urlpatterns = []
for mod in leonardo.modules:
if is_leonardo_module(mod):
conf = get_conf_from_module(mod)
if module_has_submodule(mod, 'urls'):
urls_mod = import_module('.urls', mod.__name__)
if hasattr(urls_mod, 'urlpatterns'):
if conf['public']:
urlpatterns += urls_mod.urlpatterns
else:
_decorate_urlconf(urls_mod.urlpatterns,
require_auth)
urlpatterns += urls_mod.urlpatterns
from django.conf import settings
for urls_conf, conf in six.iteritems(getattr(settings, 'MODULE_URLS', {})):
try:
if conf['is_public']:
urlpatterns += \
patterns('',
url(r'', include(urls_conf)),
)
else:
_decorate_urlconf(
url(r'', include(urls_conf)),
require_auth)
urlpatterns += patterns('',
url(r'', include(urls_conf)))
except Exception as e:
raise Exception('raised %s during loading %s' %
(str(e), urls_conf))
self._urlpatterns = urlpatterns
return self._urlpatterns |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:reverse; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:viewname; 5, default_parameter; 5, 6; 5, 7; 6, identifier:urlconf; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:args; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:kwargs; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:current_app; 16, None; 17, block; 17, 18; 17, 28; 17, 35; 17, 41; 17, 47; 17, 53; 17, 300; 18, if_statement; 18, 19; 18, 21; 19, not_operator; 19, 20; 20, identifier:urlconf; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:urlconf; 25, call; 25, 26; 25, 27; 26, identifier:get_urlconf; 27, argument_list; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:resolver; 31, call; 31, 32; 31, 33; 32, identifier:get_resolver; 33, argument_list; 33, 34; 34, identifier:urlconf; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:args; 38, boolean_operator:or; 38, 39; 38, 40; 39, identifier:args; 40, list:[]; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:kwargs; 44, boolean_operator:or; 44, 45; 44, 46; 45, identifier:kwargs; 46, dictionary; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:prefix; 50, call; 50, 51; 50, 52; 51, identifier:get_script_prefix; 52, argument_list; 53, if_statement; 53, 54; 53, 62; 53, 67; 54, not_operator; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:isinstance; 57, argument_list; 57, 58; 57, 59; 58, identifier:viewname; 59, attribute; 59, 60; 59, 61; 60, identifier:six; 61, identifier:string_types; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:view; 66, identifier:viewname; 67, else_clause; 67, 68; 68, block; 68, 69; 68, 78; 68, 84; 68, 90; 68, 98; 68, 102; 68, 106; 68, 289; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:parts; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:viewname; 75, identifier:split; 76, argument_list; 76, 77; 77, string:':'; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:parts; 82, identifier:reverse; 83, argument_list; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:view; 87, subscript; 87, 88; 87, 89; 88, identifier:parts; 89, integer:0; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:path; 93, subscript; 93, 94; 93, 95; 94, identifier:parts; 95, slice; 95, 96; 95, 97; 96, integer:1; 97, colon; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:resolved_path; 101, list:[]; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:ns_pattern; 105, string:''; 106, while_statement; 106, 107; 106, 108; 107, identifier:path; 108, block; 108, 109; 108, 117; 108, 153; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:ns; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:path; 115, identifier:pop; 116, argument_list; 117, try_statement; 117, 118; 117, 149; 118, block; 118, 119; 118, 127; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:app_list; 122, subscript; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:resolver; 125, identifier:app_dict; 126, identifier:ns; 127, if_statement; 127, 128; 127, 133; 127, 138; 128, boolean_operator:and; 128, 129; 128, 130; 129, identifier:current_app; 130, comparison_operator:in; 130, 131; 130, 132; 131, identifier:current_app; 132, identifier:app_list; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:ns; 137, identifier:current_app; 138, elif_clause; 138, 139; 138, 142; 139, comparison_operator:not; 139, 140; 139, 141; 140, identifier:ns; 141, identifier:app_list; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:ns; 146, subscript; 146, 147; 146, 148; 147, identifier:app_list; 148, integer:0; 149, except_clause; 149, 150; 149, 151; 150, identifier:KeyError; 151, block; 151, 152; 152, pass_statement; 153, try_statement; 153, 154; 153, 178; 154, block; 154, 155; 154, 165; 154, 172; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, pattern_list; 157, 158; 157, 159; 158, identifier:extra; 159, identifier:resolver; 160, subscript; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:resolver; 163, identifier:namespace_dict; 164, identifier:ns; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:resolved_path; 169, identifier:append; 170, argument_list; 170, 171; 171, identifier:ns; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:ns_pattern; 175, binary_operator:+; 175, 176; 175, 177; 176, identifier:ns_pattern; 177, identifier:extra; 178, except_clause; 178, 179; 178, 183; 179, as_pattern; 179, 180; 179, 181; 180, identifier:KeyError; 181, as_pattern_target; 181, 182; 182, identifier:key; 183, block; 183, 184; 183, 263; 184, for_statement; 184, 185; 184, 188; 184, 200; 185, pattern_list; 185, 186; 185, 187; 186, identifier:urlconf; 187, identifier:config; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:six; 191, identifier:iteritems; 192, argument_list; 192, 193; 193, attribute; 193, 194; 193, 199; 194, subscript; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:ApplicationWidget; 197, identifier:_feincms_content_models; 198, integer:0; 199, identifier:ALL_APPS_CONFIG; 200, block; 200, 201; 200, 210; 200, 216; 200, 224; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:partials; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:viewname; 207, identifier:split; 208, argument_list; 208, 209; 209, string:':'; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:app; 213, subscript; 213, 214; 213, 215; 214, identifier:partials; 215, integer:0; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:partials; 219, subscript; 219, 220; 219, 221; 220, identifier:partials; 221, slice; 221, 222; 221, 223; 222, integer:1; 223, colon; 224, if_statement; 224, 225; 224, 236; 225, comparison_operator:==; 225, 226; 225, 235; 226, subscript; 226, 227; 226, 233; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:urlconf; 230, identifier:split; 231, argument_list; 231, 232; 232, string:"."; 233, unary_operator:-; 233, 234; 234, integer:1; 235, identifier:app; 236, block; 236, 237; 237, try_statement; 237, 238; 237, 259; 238, block; 238, 239; 239, return_statement; 239, 240; 240, call; 240, 241; 240, 242; 241, identifier:app_reverse; 242, argument_list; 242, 243; 242, 249; 242, 250; 242, 253; 242, 256; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, string:':'; 246, identifier:join; 247, argument_list; 247, 248; 248, identifier:partials; 249, identifier:urlconf; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:args; 252, identifier:args; 253, keyword_argument; 253, 254; 253, 255; 254, identifier:kwargs; 255, identifier:kwargs; 256, keyword_argument; 256, 257; 256, 258; 257, identifier:current_app; 258, identifier:current_app; 259, except_clause; 259, 260; 259, 261; 260, identifier:NoReverseMatch; 261, block; 261, 262; 262, pass_statement; 263, if_statement; 263, 264; 263, 265; 263, 280; 264, identifier:resolved_path; 265, block; 265, 266; 266, raise_statement; 266, 267; 267, call; 267, 268; 267, 269; 268, identifier:NoReverseMatch; 269, argument_list; 269, 270; 270, binary_operator:%; 270, 271; 270, 272; 271, string:"%s is not a registered namespace inside '%s'"; 272, tuple; 272, 273; 272, 274; 273, identifier:key; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, string:':'; 277, identifier:join; 278, argument_list; 278, 279; 279, identifier:resolved_path; 280, else_clause; 280, 281; 281, block; 281, 282; 282, raise_statement; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:NoReverseMatch; 285, argument_list; 285, 286; 286, binary_operator:%; 286, 287; 286, 288; 287, string:"%s is not a registered namespace"; 288, identifier:key; 289, if_statement; 289, 290; 289, 291; 290, identifier:ns_pattern; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:resolver; 295, call; 295, 296; 295, 297; 296, identifier:get_ns_resolver; 297, argument_list; 297, 298; 297, 299; 298, identifier:ns_pattern; 299, identifier:resolver; 300, return_statement; 300, 301; 301, call; 301, 302; 301, 303; 302, identifier:iri_to_uri; 303, argument_list; 303, 304; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:resolver; 307, identifier:_reverse_with_prefix; 308, argument_list; 308, 309; 308, 310; 308, 311; 308, 313; 309, identifier:view; 310, identifier:prefix; 311, list_splat; 311, 312; 312, identifier:args; 313, dictionary_splat; 313, 314; 314, identifier:kwargs | def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
if not urlconf:
urlconf = get_urlconf()
resolver = get_resolver(urlconf)
args = args or []
kwargs = kwargs or {}
prefix = get_script_prefix()
if not isinstance(viewname, six.string_types):
view = viewname
else:
parts = viewname.split(':')
parts.reverse()
view = parts[0]
path = parts[1:]
resolved_path = []
ns_pattern = ''
while path:
ns = path.pop()
try:
app_list = resolver.app_dict[ns]
if current_app and current_app in app_list:
ns = current_app
elif ns not in app_list:
ns = app_list[0]
except KeyError:
pass
try:
extra, resolver = resolver.namespace_dict[ns]
resolved_path.append(ns)
ns_pattern = ns_pattern + extra
except KeyError as key:
for urlconf, config in six.iteritems(
ApplicationWidget._feincms_content_models[0].ALL_APPS_CONFIG):
partials = viewname.split(':')
app = partials[0]
partials = partials[1:]
if urlconf.split(".")[-1] == app:
try:
return app_reverse(
':'.join(partials),
urlconf, args=args, kwargs=kwargs,
current_app=current_app)
except NoReverseMatch:
pass
if resolved_path:
raise NoReverseMatch(
"%s is not a registered namespace inside '%s'" %
(key, ':'.join(resolved_path)))
else:
raise NoReverseMatch("%s is not a registered namespace" %
key)
if ns_pattern:
resolver = get_ns_resolver(ns_pattern, resolver)
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:process_response; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:request; 6, identifier:response; 7, block; 7, 8; 7, 174; 8, if_statement; 8, 9; 8, 20; 9, boolean_operator:and; 9, 10; 9, 15; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:request; 13, identifier:is_ajax; 14, argument_list; 15, call; 15, 16; 15, 17; 16, identifier:hasattr; 17, argument_list; 17, 18; 17, 19; 18, identifier:request; 19, string:'horizon'; 20, block; 20, 21; 20, 29; 20, 160; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:queued_msgs; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:request; 27, identifier:horizon; 28, string:'async_messages'; 29, if_statement; 29, 30; 29, 38; 30, comparison_operator:==; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:type; 33, argument_list; 33, 34; 34, identifier:response; 35, attribute; 35, 36; 35, 37; 36, identifier:http; 37, identifier:HttpResponseRedirect; 38, block; 38, 39; 38, 57; 38, 65; 38, 79; 38, 130; 38, 138; 38, 142; 38, 158; 39, for_statement; 39, 40; 39, 44; 39, 45; 40, pattern_list; 40, 41; 40, 42; 40, 43; 41, identifier:tag; 42, identifier:message; 43, identifier:extra_tags; 44, identifier:queued_msgs; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 53; 48, call; 48, 49; 48, 50; 49, identifier:getattr; 50, argument_list; 50, 51; 50, 52; 51, identifier:django_messages; 52, identifier:tag; 53, argument_list; 53, 54; 53, 55; 53, 56; 54, identifier:request; 55, identifier:message; 56, identifier:extra_tags; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:redirect_response; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:http; 63, identifier:HttpResponse; 64, argument_list; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:cookie_keys; 68, call; 68, 69; 68, 70; 69, identifier:set; 70, argument_list; 70, 71; 71, tuple; 71, 72; 71, 73; 71, 74; 71, 75; 71, 76; 71, 77; 71, 78; 72, string:'max_age'; 73, string:'expires'; 74, string:'path'; 75, string:'domain'; 76, string:'secure'; 77, string:'httponly'; 78, string:'logout_reason'; 79, for_statement; 79, 80; 79, 83; 79, 91; 80, pattern_list; 80, 81; 80, 82; 81, identifier:cookie_name; 82, identifier:cookie; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:six; 86, identifier:iteritems; 87, argument_list; 87, 88; 88, attribute; 88, 89; 88, 90; 89, identifier:response; 90, identifier:cookies; 91, block; 91, 92; 91, 118; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:cookie_kwargs; 95, call; 95, 96; 95, 97; 96, identifier:dict; 97, argument_list; 97, 98; 98, generator_expression; 98, 99; 98, 102; 98, 112; 99, tuple; 99, 100; 99, 101; 100, identifier:key; 101, identifier:value; 102, for_in_clause; 102, 103; 102, 106; 103, pattern_list; 103, 104; 103, 105; 104, identifier:key; 105, identifier:value; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:six; 109, identifier:iteritems; 110, argument_list; 110, 111; 111, identifier:cookie; 112, if_clause; 112, 113; 113, boolean_operator:and; 113, 114; 113, 117; 114, comparison_operator:in; 114, 115; 114, 116; 115, identifier:key; 116, identifier:cookie_keys; 117, identifier:value; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:redirect_response; 122, identifier:set_cookie; 123, argument_list; 123, 124; 123, 125; 123, 128; 124, identifier:cookie_name; 125, attribute; 125, 126; 125, 127; 126, identifier:cookie; 127, identifier:value; 128, dictionary_splat; 128, 129; 129, identifier:cookie_kwargs; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:redirect_response; 134, string:'X-Horizon-Location'; 135, subscript; 135, 136; 135, 137; 136, identifier:response; 137, string:'location'; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:upload_url_key; 141, string:'X-File-Upload-URL'; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:in; 143, 144; 143, 145; 144, identifier:upload_url_key; 145, identifier:response; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:copy_headers; 152, argument_list; 152, 153; 152, 154; 152, 155; 153, identifier:response; 154, identifier:redirect_response; 155, tuple; 155, 156; 155, 157; 156, identifier:upload_url_key; 157, string:'X-Auth-Token'; 158, return_statement; 158, 159; 159, identifier:redirect_response; 160, if_statement; 160, 161; 160, 162; 161, identifier:queued_msgs; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:response; 167, string:'X-Horizon-Messages'; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:json; 171, identifier:dumps; 172, argument_list; 172, 173; 173, identifier:queued_msgs; 174, return_statement; 174, 175; 175, identifier:response | def process_response(self, request, response):
if request.is_ajax() and hasattr(request, 'horizon'):
queued_msgs = request.horizon['async_messages']
if type(response) == http.HttpResponseRedirect:
for tag, message, extra_tags in queued_msgs:
getattr(django_messages, tag)(request, message, extra_tags)
redirect_response = http.HttpResponse()
cookie_keys = set(('max_age', 'expires', 'path', 'domain',
'secure', 'httponly', 'logout_reason'))
for cookie_name, cookie in six.iteritems(response.cookies):
cookie_kwargs = dict((
(key, value) for key, value in six.iteritems(cookie)
if key in cookie_keys and value
))
redirect_response.set_cookie(
cookie_name, cookie.value, **cookie_kwargs)
redirect_response['X-Horizon-Location'] = response['location']
upload_url_key = 'X-File-Upload-URL'
if upload_url_key in response:
self.copy_headers(response, redirect_response,
(upload_url_key, 'X-Auth-Token'))
return redirect_response
if queued_msgs:
response['X-Horizon-Messages'] = json.dumps(queued_msgs)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:process_exception; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:request; 6, identifier:exception; 7, block; 7, 8; 7, 182; 7, 198; 8, if_statement; 8, 9; 8, 20; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 13; 12, identifier:exception; 13, tuple; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:exceptions; 16, identifier:NotAuthorized; 17, attribute; 17, 18; 17, 19; 18, identifier:exceptions; 19, identifier:NotAuthenticated; 20, block; 20, 21; 20, 27; 20, 31; 20, 68; 20, 83; 20, 98; 20, 107; 20, 120; 20, 152; 20, 180; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:auth_url; 24, attribute; 24, 25; 24, 26; 25, identifier:settings; 26, identifier:LOGIN_URL; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:next_url; 30, None; 31, if_statement; 31, 32; 31, 39; 32, comparison_operator:in; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:request; 35, identifier:method; 36, tuple; 36, 37; 36, 38; 37, string:"POST"; 38, string:"PUT"; 39, block; 39, 40; 39, 51; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:referrer; 43, call; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:request; 47, identifier:META; 48, identifier:get; 49, argument_list; 49, 50; 50, string:'HTTP_REFERER'; 51, if_statement; 51, 52; 51, 63; 52, boolean_operator:and; 52, 53; 52, 54; 53, identifier:referrer; 54, call; 54, 55; 54, 56; 55, identifier:is_safe_url; 56, argument_list; 56, 57; 56, 58; 57, identifier:referrer; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:request; 61, identifier:get_host; 62, argument_list; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:next_url; 67, identifier:referrer; 68, if_statement; 68, 69; 68, 71; 69, not_operator; 69, 70; 70, identifier:next_url; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:next_url; 75, call; 75, 76; 75, 77; 76, identifier:iri_to_uri; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:request; 81, identifier:get_full_path; 82, argument_list; 83, if_statement; 83, 84; 83, 87; 83, 92; 84, comparison_operator:!=; 84, 85; 84, 86; 85, identifier:next_url; 86, identifier:auth_url; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:field_name; 91, identifier:REDIRECT_FIELD_NAME; 92, else_clause; 92, 93; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:field_name; 97, None; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:login_url; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:request; 104, identifier:build_absolute_uri; 105, argument_list; 105, 106; 106, identifier:auth_url; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:response; 110, call; 110, 111; 110, 112; 111, identifier:redirect_to_login; 112, argument_list; 112, 113; 112, 114; 112, 117; 113, identifier:next_url; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:login_url; 116, identifier:login_url; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:redirect_field_name; 119, identifier:field_name; 120, if_statement; 120, 121; 120, 128; 121, call; 121, 122; 121, 123; 122, identifier:isinstance; 123, argument_list; 123, 124; 123, 125; 124, identifier:exception; 125, attribute; 125, 126; 125, 127; 126, identifier:exceptions; 127, identifier:NotAuthorized; 128, block; 128, 129; 128, 136; 128, 145; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:logout_reason; 132, call; 132, 133; 132, 134; 133, identifier:_; 134, argument_list; 134, 135; 135, string:"Unauthorized. Please try logging in again."; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:utils; 140, identifier:add_logout_reason; 141, argument_list; 141, 142; 141, 143; 141, 144; 142, identifier:request; 143, identifier:response; 144, identifier:logout_reason; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:response; 149, identifier:delete_cookie; 150, argument_list; 150, 151; 151, string:'messages'; 152, if_statement; 152, 153; 152, 158; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:request; 156, identifier:is_ajax; 157, argument_list; 158, block; 158, 159; 158, 170; 158, 178; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:response_401; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:http; 165, identifier:HttpResponse; 166, argument_list; 166, 167; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:status; 169, integer:401; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:response_401; 174, string:'X-Horizon-Location'; 175, subscript; 175, 176; 175, 177; 176, identifier:response; 177, string:'location'; 178, return_statement; 178, 179; 179, identifier:response_401; 180, return_statement; 180, 181; 181, identifier:response; 182, if_statement; 182, 183; 182, 190; 183, call; 183, 184; 183, 185; 184, identifier:isinstance; 185, argument_list; 185, 186; 185, 187; 186, identifier:exception; 187, attribute; 187, 188; 187, 189; 188, identifier:exceptions; 189, identifier:NotFound; 190, block; 190, 191; 191, raise_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:http; 195, identifier:Http404; 196, argument_list; 196, 197; 197, identifier:exception; 198, if_statement; 198, 199; 198, 206; 199, call; 199, 200; 199, 201; 200, identifier:isinstance; 201, argument_list; 201, 202; 201, 203; 202, identifier:exception; 203, attribute; 203, 204; 203, 205; 204, identifier:exceptions; 205, identifier:Http302; 206, block; 206, 207; 207, return_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:shortcuts; 211, identifier:redirect; 212, argument_list; 212, 213; 213, attribute; 213, 214; 213, 215; 214, identifier:exception; 215, identifier:location | def process_exception(self, request, exception):
if isinstance(exception, (exceptions.NotAuthorized,
exceptions.NotAuthenticated)):
auth_url = settings.LOGIN_URL
next_url = None
if request.method in ("POST", "PUT"):
referrer = request.META.get('HTTP_REFERER')
if referrer and is_safe_url(referrer, request.get_host()):
next_url = referrer
if not next_url:
next_url = iri_to_uri(request.get_full_path())
if next_url != auth_url:
field_name = REDIRECT_FIELD_NAME
else:
field_name = None
login_url = request.build_absolute_uri(auth_url)
response = redirect_to_login(next_url, login_url=login_url,
redirect_field_name=field_name)
if isinstance(exception, exceptions.NotAuthorized):
logout_reason = _("Unauthorized. Please try logging in again.")
utils.add_logout_reason(request, response, logout_reason)
response.delete_cookie('messages')
if request.is_ajax():
response_401 = http.HttpResponse(status=401)
response_401['X-Horizon-Location'] = response['location']
return response_401
return response
if isinstance(exception, exceptions.NotFound):
raise http.Http404(exception)
if isinstance(exception, exceptions.Http302):
return shortcuts.redirect(exception.location) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.