sequence
stringlengths 546
16.2k
| code
stringlengths 108
19.3k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:is_prime; 3, parameters; 3, 4; 3, 5; 4, identifier:n; 5, default_parameter; 5, 6; 5, 7; 6, identifier:k; 7, integer:64; 8, block; 8, 9; 8, 11; 8, 18; 8, 31; 8, 49; 8, 53; 8, 59; 8, 86; 8, 116; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:==; 12, 13; 12, 14; 13, identifier:n; 14, integer:2; 15, block; 15, 16; 16, return_statement; 16, 17; 17, True; 18, if_statement; 18, 19; 18, 28; 19, boolean_operator:or; 19, 20; 19, 23; 20, comparison_operator:<; 20, 21; 20, 22; 21, identifier:n; 22, integer:2; 23, comparison_operator:==; 23, 24; 23, 27; 24, binary_operator:%; 24, 25; 24, 26; 25, identifier:n; 26, integer:2; 27, integer:0; 28, block; 28, 29; 29, return_statement; 29, 30; 30, False; 31, for_statement; 31, 32; 31, 33; 31, 38; 31, 39; 32, identifier:i; 33, call; 33, 34; 33, 35; 34, identifier:range; 35, argument_list; 35, 36; 35, 37; 36, integer:3; 37, integer:2048; 38, comment; 39, block; 39, 40; 40, if_statement; 40, 41; 40, 46; 41, comparison_operator:==; 41, 42; 41, 45; 42, binary_operator:%; 42, 43; 42, 44; 43, identifier:n; 44, identifier:i; 45, integer:0; 46, block; 46, 47; 47, return_statement; 47, 48; 48, False; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:s; 52, integer:0; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:d; 56, binary_operator:-; 56, 57; 56, 58; 57, identifier:n; 58, integer:1; 59, while_statement; 59, 60; 59, 61; 60, True; 61, block; 61, 62; 61, 72; 61, 78; 61, 82; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, pattern_list; 64, 65; 64, 66; 65, identifier:q; 66, identifier:r; 67, call; 67, 68; 67, 69; 68, identifier:divmod; 69, argument_list; 69, 70; 69, 71; 70, identifier:d; 71, integer:2; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:==; 73, 74; 73, 75; 74, identifier:r; 75, integer:1; 76, block; 76, 77; 77, break_statement; 78, expression_statement; 78, 79; 79, augmented_assignment:+=; 79, 80; 79, 81; 80, identifier:s; 81, integer:1; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:d; 85, identifier:q; 86, for_statement; 86, 87; 86, 88; 86, 92; 87, identifier:i; 88, call; 88, 89; 88, 90; 89, identifier:range; 90, argument_list; 90, 91; 91, identifier:k; 92, block; 92, 93; 92, 105; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:a; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:random; 99, identifier:randint; 100, argument_list; 100, 101; 100, 102; 101, integer:2; 102, binary_operator:-; 102, 103; 102, 104; 103, identifier:n; 104, integer:1; 105, if_statement; 105, 106; 105, 113; 106, call; 106, 107; 106, 108; 107, identifier:check_candidate; 108, argument_list; 108, 109; 108, 110; 108, 111; 108, 112; 109, identifier:a; 110, identifier:d; 111, identifier:n; 112, identifier:s; 113, block; 113, 114; 114, return_statement; 114, 115; 115, False; 116, return_statement; 116, 117; 117, True | def is_prime(n, k=64):
"""
Test whether n is prime probabilisticly.
This uses the Miller-Rabin primality test. If n is composite,
then this test will declare it to be probably prime with a
probability of at most 4**-k.
To be on the safe side, a value of k=64 for integers up to
3072 bits is recommended (error probability = 2**-128). If
the function is used for RSA or DSA, NIST recommends some
values in FIPS PUB 186-3:
<http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf>
Do not use this function for small numbers.
"""
if n == 2:
return True
if n < 2 or n % 2 == 0:
return False
for i in range(3, 2048): # performace optimisation
if n % i == 0:
return False
s = 0
d = n - 1
while True:
q, r = divmod(d, 2)
if r == 1:
break
s += 1
d = q
for i in range(k):
a = random.randint(2, n - 1)
if check_candidate(a, d, n, s):
return False
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:iterrows; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:workbook; 7, None; 8, block; 8, 9; 8, 11; 8, 15; 8, 19; 8, 23; 8, 24; 8, 30; 8, 149; 8, 181; 8, 182; 8, 196; 8, 254; 8, 324; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:resolved_tables; 14, list:[]; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:max_height; 18, integer:0; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:max_width; 22, integer:0; 23, comment; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:__formula_values; 29, dictionary; 30, for_statement; 30, 31; 30, 38; 30, 48; 30, 49; 30, 50; 30, 51; 30, 52; 30, 53; 31, pattern_list; 31, 32; 31, 33; 32, identifier:name; 33, tuple_pattern; 33, 34; 33, 35; 34, identifier:table; 35, tuple_pattern; 35, 36; 35, 37; 36, identifier:row; 37, identifier:col; 38, call; 38, 39; 38, 40; 39, identifier:list; 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:self; 45, identifier:__tables; 46, identifier:items; 47, argument_list; 48, comment; 49, comment; 50, comment; 51, comment; 52, comment; 53, block; 53, 54; 53, 66; 53, 80; 53, 86; 53, 94; 53, 100; 53, 114; 53, 126; 53, 138; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 61; 56, subscript; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:__tables; 60, None; 61, tuple; 61, 62; 61, 63; 62, identifier:table; 63, tuple; 63, 64; 63, 65; 64, identifier:row; 65, identifier:col; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:data; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:table; 72, identifier:get_data; 73, argument_list; 73, 74; 73, 75; 73, 76; 73, 77; 74, identifier:workbook; 75, identifier:row; 76, identifier:col; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:__formula_values; 80, delete_statement; 80, 81; 81, subscript; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:__tables; 85, None; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, pattern_list; 88, 89; 88, 90; 89, identifier:height; 90, identifier:width; 91, attribute; 91, 92; 91, 93; 92, identifier:data; 93, identifier:shape; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:upper_left; 97, tuple; 97, 98; 97, 99; 98, identifier:row; 99, identifier:col; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:lower_right; 103, tuple; 103, 104; 103, 109; 104, binary_operator:-; 104, 105; 104, 108; 105, binary_operator:+; 105, 106; 105, 107; 106, identifier:row; 107, identifier:height; 108, integer:1; 109, binary_operator:-; 109, 110; 109, 113; 110, binary_operator:+; 110, 111; 110, 112; 111, identifier:col; 112, identifier:width; 113, integer:1; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:max_height; 117, call; 117, 118; 117, 119; 118, identifier:max; 119, argument_list; 119, 120; 119, 121; 120, identifier:max_height; 121, binary_operator:+; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:lower_right; 124, integer:0; 125, integer:1; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:max_width; 129, call; 129, 130; 129, 131; 130, identifier:max; 131, argument_list; 131, 132; 131, 133; 132, identifier:max_width; 133, binary_operator:+; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:lower_right; 136, integer:1; 137, integer:1; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:resolved_tables; 142, identifier:append; 143, argument_list; 143, 144; 144, tuple; 144, 145; 144, 146; 144, 147; 144, 148; 145, identifier:name; 146, identifier:data; 147, identifier:upper_left; 148, identifier:lower_right; 149, for_statement; 149, 150; 149, 153; 149, 160; 150, pattern_list; 150, 151; 150, 152; 151, identifier:row; 152, identifier:col; 153, call; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:__values; 158, identifier:keys; 159, argument_list; 160, block; 160, 161; 160, 171; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:max_width; 164, call; 164, 165; 164, 166; 165, identifier:max; 166, argument_list; 166, 167; 166, 168; 167, identifier:max_width; 168, binary_operator:+; 168, 169; 168, 170; 169, identifier:row; 170, integer:1; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:max_height; 174, call; 174, 175; 174, 176; 175, identifier:max; 176, argument_list; 176, 177; 176, 178; 177, identifier:max_height; 178, binary_operator:+; 178, 179; 178, 180; 179, identifier:col; 180, integer:1; 181, comment; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:table; 185, list_comprehension; 185, 186; 185, 190; 186, binary_operator:*; 186, 187; 186, 189; 187, list:[None]; 187, 188; 188, None; 189, identifier:max_width; 190, for_in_clause; 190, 191; 190, 192; 191, identifier:i; 192, call; 192, 193; 192, 194; 193, identifier:range; 194, argument_list; 194, 195; 195, identifier:max_height; 196, for_statement; 196, 197; 196, 202; 196, 203; 197, pattern_list; 197, 198; 197, 199; 197, 200; 197, 201; 198, identifier:name; 199, identifier:data; 200, identifier:upper_left; 201, identifier:lower_right; 202, identifier:resolved_tables; 203, block; 203, 204; 204, for_statement; 204, 205; 204, 208; 204, 222; 205, pattern_list; 205, 206; 205, 207; 206, identifier:i; 207, identifier:r; 208, call; 208, 209; 208, 210; 209, identifier:enumerate; 210, argument_list; 210, 211; 211, call; 211, 212; 211, 213; 212, identifier:range; 213, argument_list; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:upper_left; 216, integer:0; 217, binary_operator:+; 217, 218; 217, 221; 218, subscript; 218, 219; 218, 220; 219, identifier:lower_right; 220, integer:0; 221, integer:1; 222, block; 222, 223; 223, for_statement; 223, 224; 223, 227; 223, 241; 224, pattern_list; 224, 225; 224, 226; 225, identifier:j; 226, identifier:c; 227, call; 227, 228; 227, 229; 228, identifier:enumerate; 229, argument_list; 229, 230; 230, call; 230, 231; 230, 232; 231, identifier:range; 232, argument_list; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:upper_left; 235, integer:1; 236, binary_operator:+; 236, 237; 236, 240; 237, subscript; 237, 238; 237, 239; 238, identifier:lower_right; 239, integer:1; 240, integer:1; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 249; 244, subscript; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:table; 247, identifier:r; 248, identifier:c; 249, subscript; 249, 250; 249, 253; 250, subscript; 250, 251; 250, 252; 251, identifier:data; 252, identifier:i; 253, identifier:j; 254, for_statement; 254, 255; 254, 260; 254, 267; 255, pattern_list; 255, 256; 255, 259; 256, tuple_pattern; 256, 257; 256, 258; 257, identifier:r; 258, identifier:c; 259, identifier:value; 260, call; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:__values; 265, identifier:items; 266, argument_list; 267, block; 267, 268; 267, 281; 267, 316; 268, if_statement; 268, 269; 268, 274; 269, call; 269, 270; 269, 271; 270, identifier:isinstance; 271, argument_list; 271, 272; 271, 273; 272, identifier:value; 273, identifier:Value; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:value; 278, attribute; 278, 279; 278, 280; 279, identifier:value; 280, identifier:value; 281, if_statement; 281, 282; 281, 287; 282, call; 282, 283; 282, 284; 283, identifier:isinstance; 284, argument_list; 284, 285; 284, 286; 285, identifier:value; 286, identifier:Expression; 287, block; 287, 288; 287, 305; 288, if_statement; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:value; 291, identifier:has_value; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 302; 295, subscript; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:__formula_values; 299, tuple; 299, 300; 299, 301; 300, identifier:r; 301, identifier:c; 302, attribute; 302, 303; 302, 304; 303, identifier:value; 304, identifier:value; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 308; 307, identifier:value; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:value; 311, identifier:get_formula; 312, argument_list; 312, 313; 312, 314; 312, 315; 313, identifier:workbook; 314, identifier:r; 315, identifier:c; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 323; 318, subscript; 318, 319; 318, 322; 319, subscript; 319, 320; 319, 321; 320, identifier:table; 321, identifier:r; 322, identifier:c; 323, identifier:value; 324, for_statement; 324, 325; 324, 326; 324, 327; 325, identifier:row; 326, identifier:table; 327, block; 327, 328; 328, expression_statement; 328, 329; 329, yield; 329, 330; 330, identifier:row | def iterrows(self, workbook=None):
"""
Yield rows as lists of data.
The data is exactly as it is in the source pandas DataFrames and
any formulas are not resolved.
"""
resolved_tables = []
max_height = 0
max_width = 0
# while yielding rows __formula_values is updated with any formula values set on Expressions
self.__formula_values = {}
for name, (table, (row, col)) in list(self.__tables.items()):
# get the resolved 2d data array from the table
#
# expressions with no explicit table will use None when calling
# get_table/get_table_pos, which should return the current table.
#
self.__tables[None] = (table, (row, col))
data = table.get_data(workbook, row, col, self.__formula_values)
del self.__tables[None]
height, width = data.shape
upper_left = (row, col)
lower_right = (row + height - 1, col + width - 1)
max_height = max(max_height, lower_right[0] + 1)
max_width = max(max_width, lower_right[1] + 1)
resolved_tables.append((name, data, upper_left, lower_right))
for row, col in self.__values.keys():
max_width = max(max_width, row+1)
max_height = max(max_height, col+1)
# Build the whole table up-front. Doing it row by row is too slow.
table = [[None] * max_width for i in range(max_height)]
for name, data, upper_left, lower_right in resolved_tables:
for i, r in enumerate(range(upper_left[0], lower_right[0]+1)):
for j, c in enumerate(range(upper_left[1], lower_right[1]+1)):
table[r][c] = data[i][j]
for (r, c), value in self.__values.items():
if isinstance(value, Value):
value = value.value
if isinstance(value, Expression):
if value.has_value:
self.__formula_values[(r, c)] = value.value
value = value.get_formula(workbook, r, c)
table[r][c] = value
for row in table:
yield row |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:format_listfield_nodes; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:field_name; 5, identifier:field; 6, identifier:field_id; 7, identifier:state; 8, identifier:lineno; 9, block; 9, 10; 9, 12; 9, 13; 9, 21; 9, 32; 9, 40; 9, 53; 9, 57; 9, 61; 9, 113; 9, 117; 9, 169; 9, 173; 9, 225; 9, 226; 9, 234; 9, 248; 9, 256; 9, 264; 9, 283; 9, 293; 9, 313; 9, 328; 9, 332; 9, 336; 9, 337; 9, 347; 9, 356; 9, 357; 9, 368; 9, 372; 9, 373; 9, 381; 9, 389; 9, 393; 9, 400; 9, 407; 9, 414; 9, 415; 9, 423; 9, 424; 9, 435; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:itemtype_node; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:nodes; 19, identifier:definition_list_item; 20, argument_list; 21, expression_statement; 21, 22; 22, augmented_assignment:+=; 22, 23; 22, 24; 23, identifier:itemtype_node; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:nodes; 27, identifier:term; 28, argument_list; 28, 29; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:text; 31, string:'Item type'; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:itemtype_def; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:nodes; 38, identifier:definition; 39, argument_list; 40, expression_statement; 40, 41; 41, augmented_assignment:+=; 41, 42; 41, 43; 42, identifier:itemtype_def; 43, call; 43, 44; 43, 45; 44, identifier:make_python_xref_nodes_for_type; 45, argument_list; 45, 46; 45, 49; 45, 50; 46, attribute; 46, 47; 46, 48; 47, identifier:field; 48, identifier:itemtype; 49, identifier:state; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:hide_namespace; 52, False; 53, expression_statement; 53, 54; 54, augmented_assignment:+=; 54, 55; 54, 56; 55, identifier:itemtype_node; 56, identifier:itemtype_def; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:minlength_node; 60, None; 61, if_statement; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:field; 64, identifier:minLength; 65, block; 65, 66; 65, 74; 65, 85; 65, 93; 65, 109; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:minlength_node; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:nodes; 72, identifier:definition_list_item; 73, argument_list; 74, expression_statement; 74, 75; 75, augmented_assignment:+=; 75, 76; 75, 77; 76, identifier:minlength_node; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:nodes; 80, identifier:term; 81, argument_list; 81, 82; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:text; 84, string:'Minimum length'; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:minlength_def; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:nodes; 91, identifier:definition; 92, argument_list; 93, expression_statement; 93, 94; 94, augmented_assignment:+=; 94, 95; 94, 96; 95, identifier:minlength_def; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:nodes; 99, identifier:paragraph; 100, argument_list; 100, 101; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:text; 103, call; 103, 104; 103, 105; 104, identifier:str; 105, argument_list; 105, 106; 106, attribute; 106, 107; 106, 108; 107, identifier:field; 108, identifier:minLength; 109, expression_statement; 109, 110; 110, augmented_assignment:+=; 110, 111; 110, 112; 111, identifier:minlength_node; 112, identifier:minlength_def; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:maxlength_node; 116, None; 117, if_statement; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:field; 120, identifier:maxLength; 121, block; 121, 122; 121, 130; 121, 141; 121, 149; 121, 165; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:maxlength_node; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:nodes; 128, identifier:definition_list_item; 129, argument_list; 130, expression_statement; 130, 131; 131, augmented_assignment:+=; 131, 132; 131, 133; 132, identifier:maxlength_node; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:nodes; 136, identifier:term; 137, argument_list; 137, 138; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:text; 140, string:'Maximum length'; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:maxlength_def; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:nodes; 147, identifier:definition; 148, argument_list; 149, expression_statement; 149, 150; 150, augmented_assignment:+=; 150, 151; 150, 152; 151, identifier:maxlength_def; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:nodes; 155, identifier:paragraph; 156, argument_list; 156, 157; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:text; 159, call; 159, 160; 159, 161; 160, identifier:str; 161, argument_list; 161, 162; 162, attribute; 162, 163; 162, 164; 163, identifier:field; 164, identifier:maxLength; 165, expression_statement; 165, 166; 166, augmented_assignment:+=; 166, 167; 166, 168; 167, identifier:maxlength_node; 168, identifier:maxlength_def; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:length_node; 172, None; 173, if_statement; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:field; 176, identifier:length; 177, block; 177, 178; 177, 186; 177, 197; 177, 205; 177, 221; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:length_node; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:nodes; 184, identifier:definition_list_item; 185, argument_list; 186, expression_statement; 186, 187; 187, augmented_assignment:+=; 187, 188; 187, 189; 188, identifier:length_node; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:nodes; 192, identifier:term; 193, argument_list; 193, 194; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:text; 196, string:'Required length'; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:length_def; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:nodes; 203, identifier:definition; 204, argument_list; 205, expression_statement; 205, 206; 206, augmented_assignment:+=; 206, 207; 206, 208; 207, identifier:length_def; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:nodes; 211, identifier:paragraph; 212, argument_list; 212, 213; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:text; 215, call; 215, 216; 215, 217; 216, identifier:str; 217, argument_list; 217, 218; 218, attribute; 218, 219; 218, 220; 219, identifier:field; 220, identifier:length; 221, expression_statement; 221, 222; 222, augmented_assignment:+=; 222, 223; 222, 224; 223, identifier:length_node; 224, identifier:length_def; 225, comment; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:field_type_item; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:nodes; 232, identifier:definition_list_item; 233, argument_list; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:field_type_item; 238, identifier:append; 239, argument_list; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:nodes; 243, identifier:term; 244, argument_list; 244, 245; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:text; 247, string:"Field type"; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:field_type_item_content; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:nodes; 254, identifier:definition; 255, argument_list; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:field_type_item_content_p; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:nodes; 262, identifier:paragraph; 263, argument_list; 264, expression_statement; 264, 265; 265, augmented_assignment:+=; 265, 266; 265, 267; 266, identifier:field_type_item_content_p; 267, subscript; 267, 268; 267, 282; 268, attribute; 268, 269; 268, 281; 269, subscript; 269, 270; 269, 280; 270, call; 270, 271; 270, 272; 271, identifier:make_python_xref_nodes_for_type; 272, argument_list; 272, 273; 272, 276; 272, 277; 273, attribute; 273, 274; 273, 275; 274, identifier:field; 275, identifier:itemtype; 276, identifier:state; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:hide_namespace; 279, False; 280, integer:0; 281, identifier:children; 282, integer:0; 283, expression_statement; 283, 284; 284, augmented_assignment:+=; 284, 285; 284, 286; 285, identifier:field_type_item_content_p; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:nodes; 289, identifier:Text; 290, argument_list; 290, 291; 290, 292; 291, string:' '; 292, string:' '; 293, expression_statement; 293, 294; 294, augmented_assignment:+=; 294, 295; 294, 296; 295, identifier:field_type_item_content_p; 296, subscript; 296, 297; 296, 312; 297, attribute; 297, 298; 297, 311; 298, subscript; 298, 299; 298, 310; 299, call; 299, 300; 299, 301; 300, identifier:make_python_xref_nodes_for_type; 301, argument_list; 301, 302; 301, 306; 301, 307; 302, call; 302, 303; 302, 304; 303, identifier:type; 304, argument_list; 304, 305; 305, identifier:field; 306, identifier:state; 307, keyword_argument; 307, 308; 307, 309; 308, identifier:hide_namespace; 309, True; 310, integer:0; 311, identifier:children; 312, integer:0; 313, if_statement; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:field; 316, identifier:optional; 317, block; 317, 318; 318, expression_statement; 318, 319; 319, augmented_assignment:+=; 319, 320; 319, 321; 320, identifier:field_type_item_content_p; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:nodes; 324, identifier:Text; 325, argument_list; 325, 326; 325, 327; 326, string:' (optional)'; 327, string:' (optional)'; 328, expression_statement; 328, 329; 329, augmented_assignment:+=; 329, 330; 329, 331; 330, identifier:field_type_item_content; 331, identifier:field_type_item_content_p; 332, expression_statement; 332, 333; 333, augmented_assignment:+=; 333, 334; 333, 335; 334, identifier:field_type_item; 335, identifier:field_type_item_content; 336, comment; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 340; 339, identifier:env; 340, attribute; 340, 341; 340, 346; 341, attribute; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:state; 344, identifier:document; 345, identifier:settings; 346, identifier:env; 347, expression_statement; 347, 348; 348, assignment; 348, 349; 348, 350; 349, identifier:ref_target; 350, call; 350, 351; 350, 352; 351, identifier:create_configfield_ref_target_node; 352, argument_list; 352, 353; 352, 354; 352, 355; 353, identifier:field_id; 354, identifier:env; 355, identifier:lineno; 356, comment; 357, expression_statement; 357, 358; 358, assignment; 358, 359; 358, 360; 359, identifier:title; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:nodes; 363, identifier:title; 364, argument_list; 364, 365; 365, keyword_argument; 365, 366; 365, 367; 366, identifier:text; 367, identifier:field_name; 368, expression_statement; 368, 369; 369, augmented_assignment:+=; 369, 370; 369, 371; 370, identifier:title; 371, identifier:ref_target; 372, comment; 373, expression_statement; 373, 374; 374, assignment; 374, 375; 374, 376; 375, identifier:dl; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:nodes; 379, identifier:definition_list; 380, argument_list; 381, expression_statement; 381, 382; 382, augmented_assignment:+=; 382, 383; 382, 384; 383, identifier:dl; 384, call; 384, 385; 384, 386; 385, identifier:create_default_item_node; 386, argument_list; 386, 387; 386, 388; 387, identifier:field; 388, identifier:state; 389, expression_statement; 389, 390; 390, augmented_assignment:+=; 390, 391; 390, 392; 391, identifier:dl; 392, identifier:field_type_item; 393, if_statement; 393, 394; 393, 395; 394, identifier:minlength_node; 395, block; 395, 396; 396, expression_statement; 396, 397; 397, augmented_assignment:+=; 397, 398; 397, 399; 398, identifier:dl; 399, identifier:minlength_node; 400, if_statement; 400, 401; 400, 402; 401, identifier:maxlength_node; 402, block; 402, 403; 403, expression_statement; 403, 404; 404, augmented_assignment:+=; 404, 405; 404, 406; 405, identifier:dl; 406, identifier:maxlength_node; 407, if_statement; 407, 408; 407, 409; 408, identifier:length_node; 409, block; 409, 410; 410, expression_statement; 410, 411; 411, augmented_assignment:+=; 411, 412; 411, 413; 412, identifier:dl; 413, identifier:length_node; 414, comment; 415, expression_statement; 415, 416; 416, assignment; 416, 417; 416, 418; 417, identifier:desc_node; 418, call; 418, 419; 418, 420; 419, identifier:create_description_node; 420, argument_list; 420, 421; 420, 422; 421, identifier:field; 422, identifier:state; 423, comment; 424, expression_statement; 424, 425; 425, assignment; 425, 426; 425, 427; 426, identifier:title; 427, call; 427, 428; 427, 429; 428, identifier:create_title_node; 429, argument_list; 429, 430; 429, 431; 429, 432; 429, 433; 429, 434; 430, identifier:field_name; 431, identifier:field; 432, identifier:field_id; 433, identifier:state; 434, identifier:lineno; 435, return_statement; 435, 436; 436, list:[title, dl, desc_node]; 436, 437; 436, 438; 436, 439; 437, identifier:title; 438, identifier:dl; 439, identifier:desc_node | def format_listfield_nodes(field_name, field, field_id, state, lineno):
"""Create a section node that documents a ListField config field.
Parameters
----------
field_name : `str`
Name of the configuration field (the attribute name of on the config
class).
field : ``lsst.pex.config.ListField``
A configuration field.
field_id : `str`
Unique identifier for this field. This is used as the id and name of
the section node. with a -section suffix
state : ``docutils.statemachine.State``
Usually the directive's ``state`` attribute.
lineno (`int`)
Usually the directive's ``lineno`` attribute.
Returns
-------
``docutils.nodes.section``
Section containing documentation nodes for the ListField.
"""
# ListField's store their item types in the itemtype attribute
itemtype_node = nodes.definition_list_item()
itemtype_node += nodes.term(text='Item type')
itemtype_def = nodes.definition()
itemtype_def += make_python_xref_nodes_for_type(
field.itemtype,
state,
hide_namespace=False)
itemtype_node += itemtype_def
minlength_node = None
if field.minLength:
minlength_node = nodes.definition_list_item()
minlength_node += nodes.term(text='Minimum length')
minlength_def = nodes.definition()
minlength_def += nodes.paragraph(text=str(field.minLength))
minlength_node += minlength_def
maxlength_node = None
if field.maxLength:
maxlength_node = nodes.definition_list_item()
maxlength_node += nodes.term(text='Maximum length')
maxlength_def = nodes.definition()
maxlength_def += nodes.paragraph(text=str(field.maxLength))
maxlength_node += maxlength_def
length_node = None
if field.length:
length_node = nodes.definition_list_item()
length_node += nodes.term(text='Required length')
length_def = nodes.definition()
length_def += nodes.paragraph(text=str(field.length))
length_node += length_def
# Type description
field_type_item = nodes.definition_list_item()
field_type_item.append(nodes.term(text="Field type"))
field_type_item_content = nodes.definition()
field_type_item_content_p = nodes.paragraph()
field_type_item_content_p += make_python_xref_nodes_for_type(
field.itemtype,
state,
hide_namespace=False)[0].children[0]
field_type_item_content_p += nodes.Text(' ', ' ')
field_type_item_content_p += make_python_xref_nodes_for_type(
type(field),
state,
hide_namespace=True)[0].children[0]
if field.optional:
field_type_item_content_p += nodes.Text(' (optional)', ' (optional)')
field_type_item_content += field_type_item_content_p
field_type_item += field_type_item_content
# Reference target
env = state.document.settings.env
ref_target = create_configfield_ref_target_node(field_id, env, lineno)
# Title is the field's attribute name
title = nodes.title(text=field_name)
title += ref_target
# Definition list for key-value metadata
dl = nodes.definition_list()
dl += create_default_item_node(field, state)
dl += field_type_item
if minlength_node:
dl += minlength_node
if maxlength_node:
dl += maxlength_node
if length_node:
dl += length_node
# Doc for this ConfigurableField, parsed as rst
desc_node = create_description_node(field, state)
# Title for configuration field
title = create_title_node(field_name, field, field_id, state, lineno)
return [title, dl, desc_node] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:format_choicefield_nodes; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:field_name; 5, identifier:field; 6, identifier:field_id; 7, identifier:state; 8, identifier:lineno; 9, block; 9, 10; 9, 12; 9, 13; 9, 21; 9, 100; 9, 108; 9, 122; 9, 130; 9, 137; 9, 144; 9, 145; 9, 153; 9, 167; 9, 175; 9, 183; 9, 202; 9, 212; 9, 232; 9, 247; 9, 251; 9, 255; 9, 256; 9, 264; 9, 272; 9, 276; 9, 280; 9, 281; 9, 289; 9, 290; 9, 301; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:choice_dl; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:nodes; 19, identifier:definition_list; 20, argument_list; 21, for_statement; 21, 22; 21, 25; 21, 32; 22, pattern_list; 22, 23; 22, 24; 23, identifier:choice_value; 24, identifier:choice_doc; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:field; 29, identifier:allowed; 30, identifier:items; 31, argument_list; 32, block; 32, 33; 32, 41; 32, 49; 32, 63; 32, 67; 32, 75; 32, 89; 32, 93; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:item; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:nodes; 39, identifier:definition_list_item; 40, argument_list; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:item_term; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:nodes; 47, identifier:term; 48, argument_list; 49, expression_statement; 49, 50; 50, augmented_assignment:+=; 50, 51; 50, 52; 51, identifier:item_term; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:nodes; 55, identifier:literal; 56, argument_list; 56, 57; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:text; 59, call; 59, 60; 59, 61; 60, identifier:repr; 61, argument_list; 61, 62; 62, identifier:choice_value; 63, expression_statement; 63, 64; 64, augmented_assignment:+=; 64, 65; 64, 66; 65, identifier:item; 66, identifier:item_term; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:item_definition; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:nodes; 73, identifier:definition; 74, argument_list; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:item_definition; 79, identifier:append; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:nodes; 84, identifier:paragraph; 85, argument_list; 85, 86; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:text; 88, identifier:choice_doc; 89, expression_statement; 89, 90; 90, augmented_assignment:+=; 90, 91; 90, 92; 91, identifier:item; 92, identifier:item_definition; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:choice_dl; 97, identifier:append; 98, argument_list; 98, 99; 99, identifier:item; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:choices_node; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:nodes; 106, identifier:definition_list_item; 107, argument_list; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:choices_node; 112, identifier:append; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:nodes; 117, identifier:term; 118, argument_list; 118, 119; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:text; 121, string:'Choices'; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:choices_definition; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:nodes; 128, identifier:definition; 129, argument_list; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:choices_definition; 134, identifier:append; 135, argument_list; 135, 136; 136, identifier:choice_dl; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:choices_node; 141, identifier:append; 142, argument_list; 142, 143; 143, identifier:choices_definition; 144, comment; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:field_type_item; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:nodes; 151, identifier:definition_list_item; 152, argument_list; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:field_type_item; 157, identifier:append; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:nodes; 162, identifier:term; 163, argument_list; 163, 164; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:text; 166, string:"Field type"; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:field_type_item_content; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:nodes; 173, identifier:definition; 174, argument_list; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:field_type_item_content_p; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:nodes; 181, identifier:paragraph; 182, argument_list; 183, expression_statement; 183, 184; 184, augmented_assignment:+=; 184, 185; 184, 186; 185, identifier:field_type_item_content_p; 186, subscript; 186, 187; 186, 201; 187, attribute; 187, 188; 187, 200; 188, subscript; 188, 189; 188, 199; 189, call; 189, 190; 189, 191; 190, identifier:make_python_xref_nodes_for_type; 191, argument_list; 191, 192; 191, 195; 191, 196; 192, attribute; 192, 193; 192, 194; 193, identifier:field; 194, identifier:dtype; 195, identifier:state; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:hide_namespace; 198, False; 199, integer:0; 200, identifier:children; 201, integer:0; 202, expression_statement; 202, 203; 203, augmented_assignment:+=; 203, 204; 203, 205; 204, identifier:field_type_item_content_p; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:nodes; 208, identifier:Text; 209, argument_list; 209, 210; 209, 211; 210, string:' '; 211, string:' '; 212, expression_statement; 212, 213; 213, augmented_assignment:+=; 213, 214; 213, 215; 214, identifier:field_type_item_content_p; 215, subscript; 215, 216; 215, 231; 216, attribute; 216, 217; 216, 230; 217, subscript; 217, 218; 217, 229; 218, call; 218, 219; 218, 220; 219, identifier:make_python_xref_nodes_for_type; 220, argument_list; 220, 221; 220, 225; 220, 226; 221, call; 221, 222; 221, 223; 222, identifier:type; 223, argument_list; 223, 224; 224, identifier:field; 225, identifier:state; 226, keyword_argument; 226, 227; 226, 228; 227, identifier:hide_namespace; 228, True; 229, integer:0; 230, identifier:children; 231, integer:0; 232, if_statement; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:field; 235, identifier:optional; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, augmented_assignment:+=; 238, 239; 238, 240; 239, identifier:field_type_item_content_p; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:nodes; 243, identifier:Text; 244, argument_list; 244, 245; 244, 246; 245, string:' (optional)'; 246, string:' (optional)'; 247, expression_statement; 247, 248; 248, augmented_assignment:+=; 248, 249; 248, 250; 249, identifier:field_type_item_content; 250, identifier:field_type_item_content_p; 251, expression_statement; 251, 252; 252, augmented_assignment:+=; 252, 253; 252, 254; 253, identifier:field_type_item; 254, identifier:field_type_item_content; 255, comment; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:dl; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:nodes; 262, identifier:definition_list; 263, argument_list; 264, expression_statement; 264, 265; 265, augmented_assignment:+=; 265, 266; 265, 267; 266, identifier:dl; 267, call; 267, 268; 267, 269; 268, identifier:create_default_item_node; 269, argument_list; 269, 270; 269, 271; 270, identifier:field; 271, identifier:state; 272, expression_statement; 272, 273; 273, augmented_assignment:+=; 273, 274; 273, 275; 274, identifier:dl; 275, identifier:field_type_item; 276, expression_statement; 276, 277; 277, augmented_assignment:+=; 277, 278; 277, 279; 278, identifier:dl; 279, identifier:choices_node; 280, comment; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:desc_node; 284, call; 284, 285; 284, 286; 285, identifier:create_description_node; 286, argument_list; 286, 287; 286, 288; 287, identifier:field; 288, identifier:state; 289, comment; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:title; 293, call; 293, 294; 293, 295; 294, identifier:create_title_node; 295, argument_list; 295, 296; 295, 297; 295, 298; 295, 299; 295, 300; 296, identifier:field_name; 297, identifier:field; 298, identifier:field_id; 299, identifier:state; 300, identifier:lineno; 301, return_statement; 301, 302; 302, list:[title, dl, desc_node]; 302, 303; 302, 304; 302, 305; 303, identifier:title; 304, identifier:dl; 305, identifier:desc_node | def format_choicefield_nodes(field_name, field, field_id, state, lineno):
"""Create a section node that documents a ChoiceField config field.
Parameters
----------
field_name : `str`
Name of the configuration field (the attribute name of on the config
class).
field : ``lsst.pex.config.ChoiceField``
A configuration field.
field_id : `str`
Unique identifier for this field. This is used as the id and name of
the section node. with a -section suffix
state : ``docutils.statemachine.State``
Usually the directive's ``state`` attribute.
lineno (`int`)
Usually the directive's ``lineno`` attribute.
Returns
-------
``docutils.nodes.section``
Section containing documentation nodes for the ChoiceField.
"""
# Create a definition list for the choices
choice_dl = nodes.definition_list()
for choice_value, choice_doc in field.allowed.items():
item = nodes.definition_list_item()
item_term = nodes.term()
item_term += nodes.literal(text=repr(choice_value))
item += item_term
item_definition = nodes.definition()
item_definition.append(nodes.paragraph(text=choice_doc))
item += item_definition
choice_dl.append(item)
choices_node = nodes.definition_list_item()
choices_node.append(nodes.term(text='Choices'))
choices_definition = nodes.definition()
choices_definition.append(choice_dl)
choices_node.append(choices_definition)
# Field type
field_type_item = nodes.definition_list_item()
field_type_item.append(nodes.term(text="Field type"))
field_type_item_content = nodes.definition()
field_type_item_content_p = nodes.paragraph()
field_type_item_content_p += make_python_xref_nodes_for_type(
field.dtype,
state,
hide_namespace=False)[0].children[0]
field_type_item_content_p += nodes.Text(' ', ' ')
field_type_item_content_p += make_python_xref_nodes_for_type(
type(field),
state,
hide_namespace=True)[0].children[0]
if field.optional:
field_type_item_content_p += nodes.Text(' (optional)', ' (optional)')
field_type_item_content += field_type_item_content_p
field_type_item += field_type_item_content
# Definition list for key-value metadata
dl = nodes.definition_list()
dl += create_default_item_node(field, state)
dl += field_type_item
dl += choices_node
# Doc for this ConfigurableField, parsed as rst
desc_node = create_description_node(field, state)
# Title for configuration field
title = create_title_node(field_name, field, field_id, state, lineno)
return [title, dl, desc_node] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:format_configchoicefield_nodes; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:field_name; 5, identifier:field; 6, identifier:field_id; 7, identifier:state; 8, identifier:lineno; 9, block; 9, 10; 9, 12; 9, 13; 9, 21; 9, 122; 9, 130; 9, 144; 9, 152; 9, 159; 9, 166; 9, 167; 9, 175; 9, 189; 9, 197; 9, 205; 9, 220; 9, 230; 9, 250; 9, 265; 9, 269; 9, 273; 9, 281; 9, 289; 9, 293; 9, 297; 9, 298; 9, 306; 9, 307; 9, 318; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:choice_dl; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:nodes; 19, identifier:definition_list; 20, argument_list; 21, for_statement; 21, 22; 21, 25; 21, 32; 22, pattern_list; 22, 23; 22, 24; 23, identifier:choice_value; 24, identifier:choice_class; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:field; 29, identifier:typemap; 30, identifier:items; 31, argument_list; 32, block; 32, 33; 32, 41; 32, 49; 32, 63; 32, 67; 32, 75; 32, 83; 32, 98; 32, 107; 32, 111; 32, 115; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:item; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:nodes; 39, identifier:definition_list_item; 40, argument_list; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:item_term; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:nodes; 47, identifier:term; 48, argument_list; 49, expression_statement; 49, 50; 50, augmented_assignment:+=; 50, 51; 50, 52; 51, identifier:item_term; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:nodes; 55, identifier:literal; 56, argument_list; 56, 57; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:text; 59, call; 59, 60; 59, 61; 60, identifier:repr; 61, argument_list; 61, 62; 62, identifier:choice_value; 63, expression_statement; 63, 64; 64, augmented_assignment:+=; 64, 65; 64, 66; 65, identifier:item; 66, identifier:item_term; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:item_definition; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:nodes; 73, identifier:definition; 74, argument_list; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:def_para; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:nodes; 81, identifier:paragraph; 82, argument_list; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:name; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, string:'.'; 89, identifier:join; 90, argument_list; 90, 91; 91, tuple; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:choice_class; 94, identifier:__module__; 95, attribute; 95, 96; 95, 97; 96, identifier:choice_class; 97, identifier:__name__; 98, expression_statement; 98, 99; 99, augmented_assignment:+=; 99, 100; 99, 101; 100, identifier:def_para; 101, call; 101, 102; 101, 103; 102, identifier:pending_config_xref; 103, argument_list; 103, 104; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:rawsource; 106, identifier:name; 107, expression_statement; 107, 108; 108, augmented_assignment:+=; 108, 109; 108, 110; 109, identifier:item_definition; 110, identifier:def_para; 111, expression_statement; 111, 112; 112, augmented_assignment:+=; 112, 113; 112, 114; 113, identifier:item; 114, identifier:item_definition; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:choice_dl; 119, identifier:append; 120, argument_list; 120, 121; 121, identifier:item; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:choices_node; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:nodes; 128, identifier:definition_list_item; 129, argument_list; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:choices_node; 134, identifier:append; 135, argument_list; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:nodes; 139, identifier:term; 140, argument_list; 140, 141; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:text; 143, string:'Choices'; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:choices_definition; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:nodes; 150, identifier:definition; 151, argument_list; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:choices_definition; 156, identifier:append; 157, argument_list; 157, 158; 158, identifier:choice_dl; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:choices_node; 163, identifier:append; 164, argument_list; 164, 165; 165, identifier:choices_definition; 166, comment; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:field_type_item; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:nodes; 173, identifier:definition_list_item; 174, argument_list; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:field_type_item; 179, identifier:append; 180, argument_list; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:nodes; 184, identifier:term; 185, argument_list; 185, 186; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:text; 188, string:"Field type"; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:field_type_item_content; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:nodes; 195, identifier:definition; 196, argument_list; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:field_type_item_content_p; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:nodes; 203, identifier:paragraph; 204, argument_list; 205, if_statement; 205, 206; 205, 209; 205, 214; 206, attribute; 206, 207; 206, 208; 207, identifier:field; 208, identifier:multi; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:multi_text; 213, string:"Multi-selection "; 214, else_clause; 214, 215; 215, block; 215, 216; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:multi_text; 219, string:"Single-selection "; 220, expression_statement; 220, 221; 221, augmented_assignment:+=; 221, 222; 221, 223; 222, identifier:field_type_item_content_p; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:nodes; 226, identifier:Text; 227, argument_list; 227, 228; 227, 229; 228, identifier:multi_text; 229, identifier:multi_text; 230, expression_statement; 230, 231; 231, augmented_assignment:+=; 231, 232; 231, 233; 232, identifier:field_type_item_content_p; 233, subscript; 233, 234; 233, 249; 234, attribute; 234, 235; 234, 248; 235, subscript; 235, 236; 235, 247; 236, call; 236, 237; 236, 238; 237, identifier:make_python_xref_nodes_for_type; 238, argument_list; 238, 239; 238, 243; 238, 244; 239, call; 239, 240; 239, 241; 240, identifier:type; 241, argument_list; 241, 242; 242, identifier:field; 243, identifier:state; 244, keyword_argument; 244, 245; 244, 246; 245, identifier:hide_namespace; 246, True; 247, integer:0; 248, identifier:children; 249, integer:0; 250, if_statement; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:field; 253, identifier:optional; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, augmented_assignment:+=; 256, 257; 256, 258; 257, identifier:field_type_item_content_p; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:nodes; 261, identifier:Text; 262, argument_list; 262, 263; 262, 264; 263, string:' (optional)'; 264, string:' (optional)'; 265, expression_statement; 265, 266; 266, augmented_assignment:+=; 266, 267; 266, 268; 267, identifier:field_type_item_content; 268, identifier:field_type_item_content_p; 269, expression_statement; 269, 270; 270, augmented_assignment:+=; 270, 271; 270, 272; 271, identifier:field_type_item; 272, identifier:field_type_item_content; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:dl; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:nodes; 279, identifier:definition_list; 280, argument_list; 281, expression_statement; 281, 282; 282, augmented_assignment:+=; 282, 283; 282, 284; 283, identifier:dl; 284, call; 284, 285; 284, 286; 285, identifier:create_default_item_node; 286, argument_list; 286, 287; 286, 288; 287, identifier:field; 288, identifier:state; 289, expression_statement; 289, 290; 290, augmented_assignment:+=; 290, 291; 290, 292; 291, identifier:dl; 292, identifier:field_type_item; 293, expression_statement; 293, 294; 294, augmented_assignment:+=; 294, 295; 294, 296; 295, identifier:dl; 296, identifier:choices_node; 297, comment; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:desc_node; 301, call; 301, 302; 301, 303; 302, identifier:create_description_node; 303, argument_list; 303, 304; 303, 305; 304, identifier:field; 305, identifier:state; 306, comment; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:title; 310, call; 310, 311; 310, 312; 311, identifier:create_title_node; 312, argument_list; 312, 313; 312, 314; 312, 315; 312, 316; 312, 317; 313, identifier:field_name; 314, identifier:field; 315, identifier:field_id; 316, identifier:state; 317, identifier:lineno; 318, return_statement; 318, 319; 319, list:[title, dl, desc_node]; 319, 320; 319, 321; 319, 322; 320, identifier:title; 321, identifier:dl; 322, identifier:desc_node | def format_configchoicefield_nodes(field_name, field, field_id, state, lineno):
"""Create a section node that documents a ConfigChoiceField config field.
Parameters
----------
field_name : `str`
Name of the configuration field (the attribute name of on the config
class).
field : ``lsst.pex.config.ConfigChoiceField``
A configuration field.
field_id : `str`
Unique identifier for this field. This is used as the id and name of
the section node. with a -section suffix
state : ``docutils.statemachine.State``
Usually the directive's ``state`` attribute.
lineno (`int`)
Usually the directive's ``lineno`` attribute.
Returns
-------
``docutils.nodes.section``
Section containing documentation nodes for the ConfigChoiceField.
"""
# Create a definition list for the choices
choice_dl = nodes.definition_list()
for choice_value, choice_class in field.typemap.items():
item = nodes.definition_list_item()
item_term = nodes.term()
item_term += nodes.literal(text=repr(choice_value))
item += item_term
item_definition = nodes.definition()
def_para = nodes.paragraph()
name = '.'.join((choice_class.__module__, choice_class.__name__))
def_para += pending_config_xref(rawsource=name)
item_definition += def_para
item += item_definition
choice_dl.append(item)
choices_node = nodes.definition_list_item()
choices_node.append(nodes.term(text='Choices'))
choices_definition = nodes.definition()
choices_definition.append(choice_dl)
choices_node.append(choices_definition)
# Field type
field_type_item = nodes.definition_list_item()
field_type_item.append(nodes.term(text="Field type"))
field_type_item_content = nodes.definition()
field_type_item_content_p = nodes.paragraph()
if field.multi:
multi_text = "Multi-selection "
else:
multi_text = "Single-selection "
field_type_item_content_p += nodes.Text(multi_text, multi_text)
field_type_item_content_p += make_python_xref_nodes_for_type(
type(field),
state,
hide_namespace=True)[0].children[0]
if field.optional:
field_type_item_content_p += nodes.Text(' (optional)', ' (optional)')
field_type_item_content += field_type_item_content_p
field_type_item += field_type_item_content
dl = nodes.definition_list()
dl += create_default_item_node(field, state)
dl += field_type_item
dl += choices_node
# Doc for this field, parsed as rst
desc_node = create_description_node(field, state)
# Title for configuration field
title = create_title_node(field_name, field, field_id, state, lineno)
return [title, dl, desc_node] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:format_registryfield_nodes; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:field_name; 5, identifier:field; 6, identifier:field_id; 7, identifier:state; 8, identifier:lineno; 9, block; 9, 10; 9, 12; 9, 20; 9, 21; 9, 22; 9, 23; 9, 31; 9, 201; 9, 209; 9, 223; 9, 231; 9, 238; 9, 245; 9, 246; 9, 254; 9, 268; 9, 276; 9, 284; 9, 299; 9, 309; 9, 329; 9, 344; 9, 348; 9, 352; 9, 360; 9, 368; 9, 372; 9, 376; 9, 377; 9, 385; 9, 386; 9, 397; 10, expression_statement; 10, 11; 11, comment; 12, import_from_statement; 12, 13; 12, 18; 13, dotted_name; 13, 14; 13, 15; 13, 16; 13, 17; 14, identifier:lsst; 15, identifier:pex; 16, identifier:config; 17, identifier:registry; 18, dotted_name; 18, 19; 19, identifier:ConfigurableWrapper; 20, comment; 21, comment; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:choice_dl; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:nodes; 29, identifier:definition_list; 30, argument_list; 31, for_statement; 31, 32; 31, 35; 31, 42; 31, 43; 31, 44; 31, 45; 31, 46; 32, pattern_list; 32, 33; 32, 34; 33, identifier:choice_value; 34, identifier:choice_class; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:field; 39, identifier:registry; 40, identifier:items; 41, argument_list; 42, comment; 43, comment; 44, comment; 45, comment; 46, block; 46, 47; 46, 127; 46, 135; 46, 143; 46, 157; 46, 161; 46, 169; 46, 177; 46, 186; 46, 190; 46, 194; 47, if_statement; 47, 48; 47, 60; 47, 76; 47, 106; 48, boolean_operator:and; 48, 49; 48, 54; 48, 55; 49, call; 49, 50; 49, 51; 50, identifier:hasattr; 51, argument_list; 51, 52; 51, 53; 52, identifier:choice_class; 53, string:'__module__'; 54, line_continuation:\; 55, call; 55, 56; 55, 57; 56, identifier:hasattr; 57, argument_list; 57, 58; 57, 59; 58, identifier:choice_class; 59, string:'__name__'; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:name; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, string:'.'; 67, identifier:join; 68, argument_list; 68, 69; 69, tuple; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:choice_class; 72, identifier:__module__; 73, attribute; 73, 74; 73, 75; 74, identifier:choice_class; 75, identifier:__name__; 76, elif_clause; 76, 77; 76, 82; 77, call; 77, 78; 77, 79; 78, identifier:isinstance; 79, argument_list; 79, 80; 79, 81; 80, identifier:choice_class; 81, identifier:ConfigurableWrapper; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:name; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, string:'.'; 89, identifier:join; 90, argument_list; 90, 91; 91, tuple; 91, 92; 91, 99; 92, attribute; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:choice_class; 96, identifier:_target; 97, identifier:__class__; 98, identifier:__module__; 99, attribute; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:choice_class; 103, identifier:_target; 104, identifier:__class__; 105, identifier:__name__; 106, else_clause; 106, 107; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:name; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, string:'.'; 114, identifier:join; 115, argument_list; 115, 116; 116, tuple; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:choice_class; 120, identifier:__class__; 121, identifier:__module__; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:choice_class; 125, identifier:__class__; 126, identifier:__name__; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:item; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:nodes; 133, identifier:definition_list_item; 134, argument_list; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:item_term; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:nodes; 141, identifier:term; 142, argument_list; 143, expression_statement; 143, 144; 144, augmented_assignment:+=; 144, 145; 144, 146; 145, identifier:item_term; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:nodes; 149, identifier:literal; 150, argument_list; 150, 151; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:text; 153, call; 153, 154; 153, 155; 154, identifier:repr; 155, argument_list; 155, 156; 156, identifier:choice_value; 157, expression_statement; 157, 158; 158, augmented_assignment:+=; 158, 159; 158, 160; 159, identifier:item; 160, identifier:item_term; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:item_definition; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:nodes; 167, identifier:definition; 168, argument_list; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:def_para; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:nodes; 175, identifier:paragraph; 176, argument_list; 177, expression_statement; 177, 178; 178, augmented_assignment:+=; 178, 179; 178, 180; 179, identifier:def_para; 180, call; 180, 181; 180, 182; 181, identifier:pending_task_xref; 182, argument_list; 182, 183; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:rawsource; 185, identifier:name; 186, expression_statement; 186, 187; 187, augmented_assignment:+=; 187, 188; 187, 189; 188, identifier:item_definition; 189, identifier:def_para; 190, expression_statement; 190, 191; 191, augmented_assignment:+=; 191, 192; 191, 193; 192, identifier:item; 193, identifier:item_definition; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:choice_dl; 198, identifier:append; 199, argument_list; 199, 200; 200, identifier:item; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:choices_node; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:nodes; 207, identifier:definition_list_item; 208, argument_list; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:choices_node; 213, identifier:append; 214, argument_list; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:nodes; 218, identifier:term; 219, argument_list; 219, 220; 220, keyword_argument; 220, 221; 220, 222; 221, identifier:text; 222, string:'Choices'; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:choices_definition; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:nodes; 229, identifier:definition; 230, argument_list; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:choices_definition; 235, identifier:append; 236, argument_list; 236, 237; 237, identifier:choice_dl; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:choices_node; 242, identifier:append; 243, argument_list; 243, 244; 244, identifier:choices_definition; 245, comment; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:field_type_item; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:nodes; 252, identifier:definition_list_item; 253, argument_list; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:field_type_item; 258, identifier:append; 259, argument_list; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:nodes; 263, identifier:term; 264, argument_list; 264, 265; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:text; 267, string:"Field type"; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:field_type_item_content; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:nodes; 274, identifier:definition; 275, argument_list; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:field_type_item_content_p; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:nodes; 282, identifier:paragraph; 283, argument_list; 284, if_statement; 284, 285; 284, 288; 284, 293; 285, attribute; 285, 286; 285, 287; 286, identifier:field; 287, identifier:multi; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:multi_text; 292, string:"Multi-selection "; 293, else_clause; 293, 294; 294, block; 294, 295; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 298; 297, identifier:multi_text; 298, string:"Single-selection "; 299, expression_statement; 299, 300; 300, augmented_assignment:+=; 300, 301; 300, 302; 301, identifier:field_type_item_content_p; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:nodes; 305, identifier:Text; 306, argument_list; 306, 307; 306, 308; 307, identifier:multi_text; 308, identifier:multi_text; 309, expression_statement; 309, 310; 310, augmented_assignment:+=; 310, 311; 310, 312; 311, identifier:field_type_item_content_p; 312, subscript; 312, 313; 312, 328; 313, attribute; 313, 314; 313, 327; 314, subscript; 314, 315; 314, 326; 315, call; 315, 316; 315, 317; 316, identifier:make_python_xref_nodes_for_type; 317, argument_list; 317, 318; 317, 322; 317, 323; 318, call; 318, 319; 318, 320; 319, identifier:type; 320, argument_list; 320, 321; 321, identifier:field; 322, identifier:state; 323, keyword_argument; 323, 324; 323, 325; 324, identifier:hide_namespace; 325, True; 326, integer:0; 327, identifier:children; 328, integer:0; 329, if_statement; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:field; 332, identifier:optional; 333, block; 333, 334; 334, expression_statement; 334, 335; 335, augmented_assignment:+=; 335, 336; 335, 337; 336, identifier:field_type_item_content_p; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:nodes; 340, identifier:Text; 341, argument_list; 341, 342; 341, 343; 342, string:' (optional)'; 343, string:' (optional)'; 344, expression_statement; 344, 345; 345, augmented_assignment:+=; 345, 346; 345, 347; 346, identifier:field_type_item_content; 347, identifier:field_type_item_content_p; 348, expression_statement; 348, 349; 349, augmented_assignment:+=; 349, 350; 349, 351; 350, identifier:field_type_item; 351, identifier:field_type_item_content; 352, expression_statement; 352, 353; 353, assignment; 353, 354; 353, 355; 354, identifier:dl; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:nodes; 358, identifier:definition_list; 359, argument_list; 360, expression_statement; 360, 361; 361, augmented_assignment:+=; 361, 362; 361, 363; 362, identifier:dl; 363, call; 363, 364; 363, 365; 364, identifier:create_default_item_node; 365, argument_list; 365, 366; 365, 367; 366, identifier:field; 367, identifier:state; 368, expression_statement; 368, 369; 369, augmented_assignment:+=; 369, 370; 369, 371; 370, identifier:dl; 371, identifier:field_type_item; 372, expression_statement; 372, 373; 373, augmented_assignment:+=; 373, 374; 373, 375; 374, identifier:dl; 375, identifier:choices_node; 376, comment; 377, expression_statement; 377, 378; 378, assignment; 378, 379; 378, 380; 379, identifier:desc_node; 380, call; 380, 381; 380, 382; 381, identifier:create_description_node; 382, argument_list; 382, 383; 382, 384; 383, identifier:field; 384, identifier:state; 385, comment; 386, expression_statement; 386, 387; 387, assignment; 387, 388; 387, 389; 388, identifier:title; 389, call; 389, 390; 389, 391; 390, identifier:create_title_node; 391, argument_list; 391, 392; 391, 393; 391, 394; 391, 395; 391, 396; 392, identifier:field_name; 393, identifier:field; 394, identifier:field_id; 395, identifier:state; 396, identifier:lineno; 397, return_statement; 397, 398; 398, list:[title, dl, desc_node]; 398, 399; 398, 400; 398, 401; 399, identifier:title; 400, identifier:dl; 401, identifier:desc_node | def format_registryfield_nodes(field_name, field, field_id, state, lineno):
"""Create a section node that documents a RegistryField config field.
Parameters
----------
field_name : `str`
Name of the configuration field (the attribute name of on the config
class).
field : ``lsst.pex.config.RegistryField``
A configuration field.
field_id : `str`
Unique identifier for this field. This is used as the id and name of
the section node. with a -section suffix
state : ``docutils.statemachine.State``
Usually the directive's ``state`` attribute.
lineno (`int`)
Usually the directive's ``lineno`` attribute.
Returns
-------
``docutils.nodes.section``
Section containing documentation nodes for the RegistryField.
"""
from lsst.pex.config.registry import ConfigurableWrapper
# Create a definition list for the choices
# This iteration is over field.registry.items(), not field.items(), so
# that the directive shows the configurables, not their ConfigClasses.
choice_dl = nodes.definition_list()
for choice_value, choice_class in field.registry.items():
# Introspect the class name from item in the registry. This is harder
# than it should be. Most registry items seem to fall in the first
# category. Some are ConfigurableWrapper types that expose the
# underlying task class through the _target attribute.
if hasattr(choice_class, '__module__') \
and hasattr(choice_class, '__name__'):
name = '.'.join((choice_class.__module__, choice_class.__name__))
elif isinstance(choice_class, ConfigurableWrapper):
name = '.'.join((choice_class._target.__class__.__module__,
choice_class._target.__class__.__name__))
else:
name = '.'.join((choice_class.__class__.__module__,
choice_class.__class__.__name__))
item = nodes.definition_list_item()
item_term = nodes.term()
item_term += nodes.literal(text=repr(choice_value))
item += item_term
item_definition = nodes.definition()
def_para = nodes.paragraph()
def_para += pending_task_xref(rawsource=name)
item_definition += def_para
item += item_definition
choice_dl.append(item)
choices_node = nodes.definition_list_item()
choices_node.append(nodes.term(text='Choices'))
choices_definition = nodes.definition()
choices_definition.append(choice_dl)
choices_node.append(choices_definition)
# Field type
field_type_item = nodes.definition_list_item()
field_type_item.append(nodes.term(text="Field type"))
field_type_item_content = nodes.definition()
field_type_item_content_p = nodes.paragraph()
if field.multi:
multi_text = "Multi-selection "
else:
multi_text = "Single-selection "
field_type_item_content_p += nodes.Text(multi_text, multi_text)
field_type_item_content_p += make_python_xref_nodes_for_type(
type(field),
state,
hide_namespace=True)[0].children[0]
if field.optional:
field_type_item_content_p += nodes.Text(' (optional)', ' (optional)')
field_type_item_content += field_type_item_content_p
field_type_item += field_type_item_content
dl = nodes.definition_list()
dl += create_default_item_node(field, state)
dl += field_type_item
dl += choices_node
# Doc for this field, parsed as rst
desc_node = create_description_node(field, state)
# Title for configuration field
title = create_title_node(field_name, field, field_id, state, lineno)
return [title, dl, desc_node] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:translate_argv; 3, parameters; 3, 4; 4, identifier:raw_args; 5, block; 5, 6; 5, 8; 5, 12; 5, 59; 5, 66; 5, 88; 5, 95; 5, 149; 5, 156; 5, 167; 5, 174; 5, 185; 5, 192; 5, 206; 5, 213; 5, 227; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:kwargs; 11, dictionary; 12, function_definition; 12, 13; 12, 14; 12, 16; 13, function_name:get_parameter; 14, parameters; 14, 15; 15, identifier:param_str; 16, block; 16, 17; 16, 57; 17, for_statement; 17, 18; 17, 21; 17, 25; 18, pattern_list; 18, 19; 18, 20; 19, identifier:i; 20, identifier:a; 21, call; 21, 22; 21, 23; 22, identifier:enumerate; 23, argument_list; 23, 24; 24, identifier:raw_args; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:==; 27, 28; 27, 29; 28, identifier:a; 29, identifier:param_str; 30, block; 30, 31; 30, 51; 31, assert_statement; 31, 32; 31, 50; 32, boolean_operator:and; 32, 33; 32, 41; 33, comparison_operator:==; 33, 34; 33, 38; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, identifier:raw_args; 38, binary_operator:+; 38, 39; 38, 40; 39, identifier:i; 40, integer:2; 41, comparison_operator:!=; 41, 42; 41, 49; 42, subscript; 42, 43; 42, 48; 43, subscript; 43, 44; 43, 45; 44, identifier:raw_args; 45, binary_operator:+; 45, 46; 45, 47; 46, identifier:i; 47, integer:1; 48, integer:0; 49, string:'-'; 50, string:'All arguments must have a value, e.g. `-testing true`'; 51, return_statement; 51, 52; 52, subscript; 52, 53; 52, 54; 53, identifier:raw_args; 54, binary_operator:+; 54, 55; 54, 56; 55, identifier:i; 56, integer:1; 57, return_statement; 57, 58; 58, None; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:value; 62, call; 62, 63; 62, 64; 63, identifier:get_parameter; 64, argument_list; 64, 65; 65, string:'-testing'; 66, if_statement; 66, 67; 66, 81; 67, boolean_operator:and; 67, 68; 67, 71; 68, comparison_operator:is; 68, 69; 68, 70; 69, identifier:value; 70, None; 71, comparison_operator:in; 71, 72; 71, 77; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:value; 75, identifier:lower; 76, argument_list; 77, tuple; 77, 78; 77, 79; 77, 80; 78, string:'true'; 79, string:'t'; 80, string:'yes'; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:kwargs; 86, string:'testing'; 87, True; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:value; 91, call; 91, 92; 91, 93; 92, identifier:get_parameter; 93, argument_list; 93, 94; 94, string:'-connect'; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:is; 96, 97; 96, 98; 97, identifier:value; 98, None; 99, block; 99, 100; 99, 109; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:colon; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:value; 106, identifier:find; 107, argument_list; 107, 108; 108, string:':'; 109, if_statement; 109, 110; 109, 114; 109, 141; 110, comparison_operator:>; 110, 111; 110, 112; 111, identifier:colon; 112, unary_operator:-; 112, 113; 113, integer:1; 114, block; 114, 115; 114, 126; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:kwargs; 119, string:'host'; 120, subscript; 120, 121; 120, 122; 121, identifier:value; 122, slice; 122, 123; 122, 124; 122, 125; 123, integer:0; 124, colon; 125, identifier:colon; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:kwargs; 130, string:'port'; 131, call; 131, 132; 131, 133; 132, identifier:int; 133, argument_list; 133, 134; 134, subscript; 134, 135; 134, 136; 135, identifier:value; 136, slice; 136, 137; 136, 140; 137, binary_operator:+; 137, 138; 137, 139; 138, identifier:colon; 139, integer:1; 140, colon; 141, else_clause; 141, 142; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:kwargs; 147, string:'host'; 148, identifier:value; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:value; 152, call; 152, 153; 152, 154; 153, identifier:get_parameter; 154, argument_list; 154, 155; 155, string:'-name'; 156, if_statement; 156, 157; 156, 160; 157, comparison_operator:is; 157, 158; 157, 159; 158, identifier:value; 159, None; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:kwargs; 165, string:'name'; 166, identifier:value; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:value; 170, call; 170, 171; 170, 172; 171, identifier:get_parameter; 172, argument_list; 172, 173; 173, string:'-group'; 174, if_statement; 174, 175; 174, 178; 175, comparison_operator:is; 175, 176; 175, 177; 176, identifier:value; 177, None; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, subscript; 181, 182; 181, 183; 182, identifier:kwargs; 183, string:'group_name'; 184, identifier:value; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:value; 188, call; 188, 189; 188, 190; 189, identifier:get_parameter; 190, argument_list; 190, 191; 191, string:'-scan'; 192, if_statement; 192, 193; 192, 199; 193, comparison_operator:in; 193, 194; 193, 195; 194, identifier:value; 195, tuple; 195, 196; 195, 197; 195, 198; 196, string:'true'; 197, string:'t'; 198, string:'yes'; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:kwargs; 204, string:'scan_for_port'; 205, True; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:value; 209, call; 209, 210; 209, 211; 210, identifier:get_parameter; 211, argument_list; 211, 212; 212, string:'-debug'; 213, if_statement; 213, 214; 213, 220; 214, comparison_operator:in; 214, 215; 214, 216; 215, identifier:value; 216, tuple; 216, 217; 216, 218; 216, 219; 217, string:'true'; 218, string:'t'; 219, string:'yes'; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:kwargs; 225, string:'debug'; 226, True; 227, return_statement; 227, 228; 228, identifier:kwargs | def translate_argv(raw_args):
"""Enables conversion from system arguments.
Parameters
----------
raw_args : list
Arguments taken raw from the system input.
Returns
-------
kwargs : dict
The input arguments formatted as a kwargs dict.
To use as input, simply use `KQMLModule(**kwargs)`.
"""
kwargs = {}
def get_parameter(param_str):
for i, a in enumerate(raw_args):
if a == param_str:
assert len(raw_args) == i+2 and raw_args[i+1][0] != '-', \
'All arguments must have a value, e.g. `-testing true`'
return raw_args[i+1]
return None
value = get_parameter('-testing')
if value is not None and value.lower() in ('true', 't', 'yes'):
kwargs['testing'] = True
value = get_parameter('-connect')
if value is not None:
colon = value.find(':')
if colon > -1:
kwargs['host'] = value[0:colon]
kwargs['port'] = int(value[colon+1:])
else:
kwargs['host'] = value
value = get_parameter('-name')
if value is not None:
kwargs['name'] = value
value = get_parameter('-group')
if value is not None:
kwargs['group_name'] = value
value = get_parameter('-scan')
if value in ('true', 't', 'yes'):
kwargs['scan_for_port'] = True
value = get_parameter('-debug')
if value in ('true', 't', 'yes'):
kwargs['debug'] = True
return kwargs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:run; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 39; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:document; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:state; 15, identifier:document; 16, if_statement; 16, 17; 16, 23; 17, not_operator; 17, 18; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:document; 21, identifier:settings; 22, identifier:file_insertion_enabled; 23, block; 23, 24; 24, return_statement; 24, 25; 25, list:[document.reporter.warning('File insertion disabled',
line=self.lineno)]; 25, 26; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:document; 30, identifier:reporter; 31, identifier:warning; 32, argument_list; 32, 33; 32, 34; 33, string:'File insertion disabled'; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:line; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:lineno; 39, try_statement; 39, 40; 39, 299; 40, block; 40, 41; 40, 54; 40, 55; 40, 63; 40, 76; 40, 89; 40, 99; 40, 105; 40, 139; 40, 162; 40, 176; 40, 184; 40, 248; 40, 256; 40, 286; 40, 287; 40, 288; 40, 289; 40, 296; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:location; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:state_machine; 49, identifier:get_source_and_line; 50, argument_list; 50, 51; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:lineno; 54, comment; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:url; 58, subscript; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:arguments; 62, integer:0; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:reader; 66, call; 66, 67; 66, 68; 67, identifier:RemoteCodeBlockReader; 68, argument_list; 68, 69; 68, 70; 68, 73; 69, identifier:url; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:options; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:config; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, pattern_list; 78, 79; 78, 80; 79, identifier:text; 80, identifier:lines; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:reader; 84, identifier:read; 85, argument_list; 85, 86; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:location; 88, identifier:location; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:retnode; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:nodes; 95, identifier:literal_block; 96, argument_list; 96, 97; 96, 98; 97, identifier:text; 98, identifier:text; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:set_source_info; 102, argument_list; 102, 103; 102, 104; 103, identifier:self; 104, identifier:retnode; 105, if_statement; 105, 106; 105, 114; 105, 115; 105, 122; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:options; 111, identifier:get; 112, argument_list; 112, 113; 113, string:'diff'; 114, comment; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:retnode; 120, string:'language'; 121, string:'udiff'; 122, elif_clause; 122, 123; 122, 128; 123, comparison_operator:in; 123, 124; 123, 125; 124, string:'language'; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:options; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:retnode; 133, string:'language'; 134, subscript; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:options; 138, string:'language'; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:retnode; 143, string:'linenos'; 144, parenthesized_expression; 144, 145; 145, boolean_operator:or; 145, 146; 145, 157; 146, boolean_operator:or; 146, 147; 146, 152; 147, comparison_operator:in; 147, 148; 147, 149; 148, string:'linenos'; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:options; 152, comparison_operator:in; 152, 153; 152, 154; 153, string:'lineno-start'; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:options; 157, comparison_operator:in; 157, 158; 157, 159; 158, string:'lineno-match'; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:options; 162, expression_statement; 162, 163; 163, augmented_assignment:+=; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:retnode; 166, string:'classes'; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:options; 172, identifier:get; 173, argument_list; 173, 174; 173, 175; 174, string:'class'; 175, list:[]; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:extra_args; 179, assignment; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:retnode; 182, string:'highlight_args'; 183, dictionary; 184, if_statement; 184, 185; 184, 190; 185, comparison_operator:in; 185, 186; 185, 187; 186, string:'emphasize-lines'; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:options; 190, block; 190, 191; 190, 203; 190, 232; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:hl_lines; 194, call; 194, 195; 194, 196; 195, identifier:parselinenos; 196, argument_list; 196, 197; 196, 202; 197, subscript; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:options; 201, string:'emphasize-lines'; 202, identifier:lines; 203, if_statement; 203, 204; 203, 213; 204, call; 204, 205; 204, 206; 205, identifier:any; 206, generator_expression; 206, 207; 206, 210; 207, comparison_operator:>=; 207, 208; 207, 209; 208, identifier:i; 209, identifier:lines; 210, for_in_clause; 210, 211; 210, 212; 211, identifier:i; 212, identifier:hl_lines; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:logger; 218, identifier:warning; 219, argument_list; 219, 220; 219, 229; 220, binary_operator:%; 220, 221; 220, 222; 221, string:'line number spec is out of range(1-%d): %r'; 222, tuple; 222, 223; 222, 224; 223, identifier:lines; 224, subscript; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:options; 228, string:'emphasize-lines'; 229, keyword_argument; 229, 230; 229, 231; 230, identifier:location; 231, identifier:location; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:extra_args; 236, string:'hl_lines'; 237, list_comprehension; 237, 238; 237, 241; 237, 244; 238, binary_operator:+; 238, 239; 238, 240; 239, identifier:x; 240, integer:1; 241, for_in_clause; 241, 242; 241, 243; 242, identifier:x; 243, identifier:hl_lines; 244, if_clause; 244, 245; 245, comparison_operator:<; 245, 246; 245, 247; 246, identifier:x; 247, identifier:lines; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 253; 250, subscript; 250, 251; 250, 252; 251, identifier:extra_args; 252, string:'linenostart'; 253, attribute; 253, 254; 253, 255; 254, identifier:reader; 255, identifier:lineno_start; 256, if_statement; 256, 257; 256, 262; 257, comparison_operator:in; 257, 258; 257, 259; 258, string:'caption'; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:options; 262, block; 262, 263; 262, 277; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:caption; 266, boolean_operator:or; 266, 267; 266, 272; 267, subscript; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:options; 271, string:'caption'; 272, subscript; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:self; 275, identifier:arguments; 276, integer:0; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:retnode; 280, call; 280, 281; 280, 282; 281, identifier:container_wrapper; 282, argument_list; 282, 283; 282, 284; 282, 285; 283, identifier:self; 284, identifier:retnode; 285, identifier:caption; 286, comment; 287, comment; 288, comment; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:self; 293, identifier:add_name; 294, argument_list; 294, 295; 295, identifier:retnode; 296, return_statement; 296, 297; 297, list:[retnode]; 297, 298; 298, identifier:retnode; 299, except_clause; 299, 300; 299, 304; 300, as_pattern; 300, 301; 300, 302; 301, identifier:Exception; 302, as_pattern_target; 302, 303; 303, identifier:exc; 304, block; 304, 305; 305, return_statement; 305, 306; 306, list:[document.reporter.warning(str(exc), line=self.lineno)]; 306, 307; 307, call; 307, 308; 307, 313; 308, attribute; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:document; 311, identifier:reporter; 312, identifier:warning; 313, argument_list; 313, 314; 313, 318; 314, call; 314, 315; 314, 316; 315, identifier:str; 316, argument_list; 316, 317; 317, identifier:exc; 318, keyword_argument; 318, 319; 318, 320; 319, identifier:line; 320, attribute; 320, 321; 320, 322; 321, identifier:self; 322, identifier:lineno | def run(self):
"""Run the ``remote-code-block`` directive.
"""
document = self.state.document
if not document.settings.file_insertion_enabled:
return [document.reporter.warning('File insertion disabled',
line=self.lineno)]
try:
location = self.state_machine.get_source_and_line(self.lineno)
# Customized for RemoteCodeBlock
url = self.arguments[0]
reader = RemoteCodeBlockReader(url, self.options, self.config)
text, lines = reader.read(location=location)
retnode = nodes.literal_block(text, text)
set_source_info(self, retnode)
if self.options.get('diff'): # if diff is set, set udiff
retnode['language'] = 'udiff'
elif 'language' in self.options:
retnode['language'] = self.options['language']
retnode['linenos'] = ('linenos' in self.options or
'lineno-start' in self.options or
'lineno-match' in self.options)
retnode['classes'] += self.options.get('class', [])
extra_args = retnode['highlight_args'] = {}
if 'emphasize-lines' in self.options:
hl_lines = parselinenos(self.options['emphasize-lines'], lines)
if any(i >= lines for i in hl_lines):
logger.warning(
'line number spec is out of range(1-%d): %r' %
(lines, self.options['emphasize-lines']),
location=location)
extra_args['hl_lines'] = [x + 1 for x in hl_lines if x < lines]
extra_args['linenostart'] = reader.lineno_start
if 'caption' in self.options:
caption = self.options['caption'] or self.arguments[0]
retnode = container_wrapper(self, retnode, caption)
# retnode will be note_implicit_target that is linked from caption
# and numref. when options['name'] is provided, it should be
# primary ID.
self.add_name(retnode)
return [retnode]
except Exception as exc:
return [document.reporter.warning(str(exc), line=self.lineno)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:aggregate_duplicates; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:X; 5, identifier:Y; 6, default_parameter; 6, 7; 6, 8; 7, identifier:aggregator; 8, string:"mean"; 9, default_parameter; 9, 10; 9, 11; 10, identifier:precision; 11, identifier:precision; 12, block; 12, 13; 12, 15; 12, 141; 12, 149; 12, 160; 12, 172; 12, 179; 12, 186; 12, 195; 12, 210; 12, 225; 12, 240; 12, 287; 12, 299; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 20; 15, 22; 15, 37; 15, 52; 15, 67; 15, 84; 15, 102; 15, 121; 16, call; 16, 17; 16, 18; 17, identifier:callable; 18, argument_list; 18, 19; 19, identifier:aggregator; 20, block; 20, 21; 21, pass_statement; 22, elif_clause; 22, 23; 22, 30; 23, comparison_operator:in; 23, 24; 23, 25; 24, string:"min"; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:aggregator; 28, identifier:lower; 29, argument_list; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:aggregator; 34, attribute; 34, 35; 34, 36; 35, identifier:np; 36, identifier:min; 37, elif_clause; 37, 38; 37, 45; 38, comparison_operator:in; 38, 39; 38, 40; 39, string:"max"; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:aggregator; 43, identifier:lower; 44, argument_list; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:aggregator; 49, attribute; 49, 50; 49, 51; 50, identifier:np; 51, identifier:max; 52, elif_clause; 52, 53; 52, 60; 53, comparison_operator:in; 53, 54; 53, 55; 54, string:"median"; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:aggregator; 58, identifier:lower; 59, argument_list; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:aggregator; 64, attribute; 64, 65; 64, 66; 65, identifier:np; 66, identifier:median; 67, elif_clause; 67, 68; 67, 77; 68, comparison_operator:in; 68, 69; 68, 74; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:aggregator; 72, identifier:lower; 73, argument_list; 74, list:["average", "mean"]; 74, 75; 74, 76; 75, string:"average"; 76, string:"mean"; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:aggregator; 81, attribute; 81, 82; 81, 83; 82, identifier:np; 83, identifier:mean; 84, elif_clause; 84, 85; 84, 92; 85, comparison_operator:in; 85, 86; 85, 87; 86, string:"first"; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:aggregator; 90, identifier:lower; 91, argument_list; 92, block; 92, 93; 93, function_definition; 93, 94; 93, 95; 93, 97; 94, function_name:aggregator; 95, parameters; 95, 96; 96, identifier:x; 97, block; 97, 98; 98, return_statement; 98, 99; 99, subscript; 99, 100; 99, 101; 100, identifier:x; 101, integer:0; 102, elif_clause; 102, 103; 102, 110; 103, comparison_operator:in; 103, 104; 103, 105; 104, string:"last"; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:aggregator; 108, identifier:lower; 109, argument_list; 110, block; 110, 111; 111, function_definition; 111, 112; 111, 113; 111, 115; 112, function_name:aggregator; 113, parameters; 113, 114; 114, identifier:x; 115, block; 115, 116; 116, return_statement; 116, 117; 117, subscript; 117, 118; 117, 119; 118, identifier:x; 119, unary_operator:-; 119, 120; 120, integer:1; 121, else_clause; 121, 122; 122, block; 122, 123; 122, 137; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:warnings; 127, identifier:warn; 128, argument_list; 128, 129; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, concatenated_string; 131, 132; 131, 133; 132, string:'Aggregator "{}" not understood. Skipping sample '; 133, string:"aggregation."; 134, identifier:format; 135, argument_list; 135, 136; 136, identifier:aggregator; 137, return_statement; 137, 138; 138, expression_list; 138, 139; 138, 140; 139, identifier:X; 140, identifier:Y; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:is_y_multivariate; 144, comparison_operator:>; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:Y; 147, identifier:ndim; 148, integer:1; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:X_rounded; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:X; 155, identifier:round; 156, argument_list; 156, 157; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:decimals; 159, identifier:precision; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:unique_xs; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:np; 166, identifier:unique; 167, argument_list; 167, 168; 167, 169; 168, identifier:X_rounded; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:axis; 171, integer:0; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:old_size; 175, call; 175, 176; 175, 177; 176, identifier:len; 177, argument_list; 177, 178; 178, identifier:X_rounded; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:new_size; 182, call; 182, 183; 182, 184; 183, identifier:len; 184, argument_list; 184, 185; 185, identifier:unique_xs; 186, if_statement; 186, 187; 186, 190; 187, comparison_operator:==; 187, 188; 187, 189; 188, identifier:old_size; 189, identifier:new_size; 190, block; 190, 191; 191, return_statement; 191, 192; 192, expression_list; 192, 193; 192, 194; 193, identifier:X; 194, identifier:Y; 195, if_statement; 195, 196; 195, 198; 196, not_operator; 196, 197; 197, identifier:is_y_multivariate; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:Y; 202, attribute; 202, 203; 202, 209; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:np; 206, identifier:atleast_2d; 207, argument_list; 207, 208; 208, identifier:Y; 209, identifier:T; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:reduced_y; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:np; 216, identifier:empty; 217, argument_list; 217, 218; 218, tuple; 218, 219; 218, 220; 219, identifier:new_size; 220, subscript; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:Y; 223, identifier:shape; 224, integer:1; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:warnings; 229, identifier:warn; 230, argument_list; 230, 231; 231, binary_operator:+; 231, 232; 231, 233; 232, string:"Domain space duplicates caused a data reduction. "; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, string:"Original size: {} vs. New size: {}"; 236, identifier:format; 237, argument_list; 237, 238; 237, 239; 238, identifier:old_size; 239, identifier:new_size; 240, for_statement; 240, 241; 240, 242; 240, 250; 241, identifier:col; 242, call; 242, 243; 242, 244; 243, identifier:range; 244, argument_list; 244, 245; 245, subscript; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:Y; 248, identifier:shape; 249, integer:1; 250, block; 250, 251; 251, for_statement; 251, 252; 251, 255; 251, 259; 252, pattern_list; 252, 253; 252, 254; 253, identifier:i; 254, identifier:distinct_row; 255, call; 255, 256; 255, 257; 256, identifier:enumerate; 257, argument_list; 257, 258; 258, identifier:unique_xs; 259, block; 259, 260; 259, 274; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:filtered_rows; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:np; 266, identifier:all; 267, argument_list; 267, 268; 267, 271; 268, comparison_operator:==; 268, 269; 268, 270; 269, identifier:X_rounded; 270, identifier:distinct_row; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:axis; 273, integer:1; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 280; 276, subscript; 276, 277; 276, 278; 276, 279; 277, identifier:reduced_y; 278, identifier:i; 279, identifier:col; 280, call; 280, 281; 280, 282; 281, identifier:aggregator; 282, argument_list; 282, 283; 283, subscript; 283, 284; 283, 285; 283, 286; 284, identifier:Y; 285, identifier:filtered_rows; 286, identifier:col; 287, if_statement; 287, 288; 287, 290; 288, not_operator; 288, 289; 289, identifier:is_y_multivariate; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:reduced_y; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:reduced_y; 297, identifier:flatten; 298, argument_list; 299, return_statement; 299, 300; 300, expression_list; 300, 301; 300, 302; 301, identifier:unique_xs; 302, identifier:reduced_y | def aggregate_duplicates(X, Y, aggregator="mean", precision=precision):
""" A function that will attempt to collapse duplicates in
domain space, X, by aggregating values over the range space,
Y.
@ In, X, an m-by-n array of values specifying m
n-dimensional samples
@ In, Y, a m vector of values specifying the output
responses corresponding to the m samples specified by X
@ In, aggregator, an optional string or callable object that
specifies what type of aggregation to do when duplicates are
found in the domain space. Default value is mean meaning the
code will calculate the mean range value over each of the
unique, duplicated samples.
@ In, precision, an optional positive integer specifying how
many digits numbers should be rounded to in order to
determine if they are unique or not.
@ Out, (unique_X, aggregated_Y), a tuple where the first
value is an m'-by-n array specifying the unique domain
samples and the second value is an m' vector specifying the
associated range values. m' <= m.
"""
if callable(aggregator):
pass
elif "min" in aggregator.lower():
aggregator = np.min
elif "max" in aggregator.lower():
aggregator = np.max
elif "median" in aggregator.lower():
aggregator = np.median
elif aggregator.lower() in ["average", "mean"]:
aggregator = np.mean
elif "first" in aggregator.lower():
def aggregator(x):
return x[0]
elif "last" in aggregator.lower():
def aggregator(x):
return x[-1]
else:
warnings.warn(
'Aggregator "{}" not understood. Skipping sample '
"aggregation.".format(aggregator)
)
return X, Y
is_y_multivariate = Y.ndim > 1
X_rounded = X.round(decimals=precision)
unique_xs = np.unique(X_rounded, axis=0)
old_size = len(X_rounded)
new_size = len(unique_xs)
if old_size == new_size:
return X, Y
if not is_y_multivariate:
Y = np.atleast_2d(Y).T
reduced_y = np.empty((new_size, Y.shape[1]))
warnings.warn(
"Domain space duplicates caused a data reduction. "
+ "Original size: {} vs. New size: {}".format(old_size, new_size)
)
for col in range(Y.shape[1]):
for i, distinct_row in enumerate(unique_xs):
filtered_rows = np.all(X_rounded == distinct_row, axis=1)
reduced_y[i, col] = aggregator(Y[filtered_rows, col])
if not is_y_multivariate:
reduced_y = reduced_y.flatten()
return unique_xs, reduced_y |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:install; 3, parameters; 3, 4; 3, 5; 4, identifier:application; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 29; 7, 48; 7, 67; 7, 86; 7, 97; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 19; 11, comparison_operator:is; 11, 12; 11, 18; 12, call; 12, 13; 12, 14; 13, identifier:getattr; 14, argument_list; 14, 15; 14, 16; 14, 17; 15, identifier:application; 16, string:'statsd'; 17, None; 18, None; 19, block; 19, 20; 19, 27; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:LOGGER; 24, identifier:warning; 25, argument_list; 25, 26; 26, string:'Statsd collector is already installed'; 27, return_statement; 27, 28; 28, False; 29, if_statement; 29, 30; 29, 33; 30, comparison_operator:not; 30, 31; 30, 32; 31, string:'host'; 32, identifier:kwargs; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, subscript; 36, 37; 36, 38; 37, identifier:kwargs; 38, string:'host'; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:os; 43, identifier:environ; 44, identifier:get; 45, argument_list; 45, 46; 45, 47; 46, string:'STATSD_HOST'; 47, string:'127.0.0.1'; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:not; 49, 50; 49, 51; 50, string:'port'; 51, identifier:kwargs; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, subscript; 55, 56; 55, 57; 56, identifier:kwargs; 57, string:'port'; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:os; 62, identifier:environ; 63, identifier:get; 64, argument_list; 64, 65; 64, 66; 65, string:'STATSD_PORT'; 66, string:'8125'; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:not; 68, 69; 68, 70; 69, string:'protocol'; 70, identifier:kwargs; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:kwargs; 76, string:'protocol'; 77, call; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:os; 81, identifier:environ; 82, identifier:get; 83, argument_list; 83, 84; 83, 85; 84, string:'STATSD_PROTOCOL'; 85, string:'udp'; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 89; 88, identifier:setattr; 89, argument_list; 89, 90; 89, 91; 89, 92; 90, identifier:application; 91, string:'statsd'; 92, call; 92, 93; 92, 94; 93, identifier:StatsDCollector; 94, argument_list; 94, 95; 95, dictionary_splat; 95, 96; 96, identifier:kwargs; 97, return_statement; 97, 98; 98, True | def install(application, **kwargs):
"""Call this to install StatsD for the Tornado application.
:param tornado.web.Application application: the application to
install the collector into.
:param kwargs: keyword parameters to pass to the
:class:`StatsDCollector` initializer.
:returns: :data:`True` if the client was installed successfully,
or :data:`False` otherwise.
- **host** The StatsD host. If host is not specified, the
``STATSD_HOST`` environment variable, or default `127.0.0.1`,
will be pass into the :class:`StatsDCollector`.
- **port** The StatsD port. If port is not specified, the
``STATSD_PORT`` environment variable, or default `8125`,
will be pass into the :class:`StatsDCollector`.
- **namespace** The StatsD bucket to write metrics into.
"""
if getattr(application, 'statsd', None) is not None:
LOGGER.warning('Statsd collector is already installed')
return False
if 'host' not in kwargs:
kwargs['host'] = os.environ.get('STATSD_HOST', '127.0.0.1')
if 'port' not in kwargs:
kwargs['port'] = os.environ.get('STATSD_PORT', '8125')
if 'protocol' not in kwargs:
kwargs['protocol'] = os.environ.get('STATSD_PROTOCOL', 'udp')
setattr(application, 'statsd', StatsDCollector(**kwargs))
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sign; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:user_id; 5, default_parameter; 5, 6; 5, 7; 6, identifier:user_type; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:today; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:session; 13, None; 14, block; 14, 15; 14, 17; 14, 18; 14, 35; 14, 54; 14, 77; 14, 223; 14, 230; 15, expression_statement; 15, 16; 16, comment; 17, comment; 18, if_statement; 18, 19; 18, 22; 18, 29; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:session; 21, None; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:session; 26, call; 26, 27; 26, 28; 27, identifier:Session; 28, argument_list; 29, else_clause; 29, 30; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:session; 34, identifier:session; 35, if_statement; 35, 36; 35, 39; 35, 48; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:today; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:today; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:date; 46, identifier:today; 47, argument_list; 48, else_clause; 48, 49; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:today; 53, identifier:today; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:user; 57, parenthesized_expression; 57, 58; 58, call; 58, 59; 58, 76; 59, attribute; 59, 60; 59, 75; 60, call; 60, 61; 60, 69; 61, attribute; 61, 62; 61, 68; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:session; 65, identifier:query; 66, argument_list; 66, 67; 67, identifier:User; 68, identifier:filter; 69, argument_list; 69, 70; 70, comparison_operator:==; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:User; 73, identifier:user_id; 74, identifier:user_id; 75, identifier:one_or_none; 76, argument_list; 77, if_statement; 77, 78; 77, 79; 77, 211; 78, identifier:user; 79, block; 79, 80; 79, 112; 79, 205; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:signed_in_entries; 83, parenthesized_expression; 83, 84; 84, call; 84, 85; 84, 111; 85, attribute; 85, 86; 85, 110; 86, call; 86, 87; 86, 101; 87, attribute; 87, 88; 87, 100; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:user; 92, identifier:entries; 93, identifier:filter; 94, argument_list; 94, 95; 95, comparison_operator:==; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:Entry; 98, identifier:date; 99, identifier:today; 100, identifier:filter; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:Entry; 106, identifier:time_out; 107, identifier:is_; 108, argument_list; 108, 109; 109, None; 110, identifier:all; 111, argument_list; 112, if_statement; 112, 113; 112, 115; 112, 159; 113, not_operator; 113, 114; 114, identifier:signed_in_entries; 115, block; 115, 116; 115, 126; 115, 133; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:new_entry; 119, call; 119, 120; 119, 121; 120, identifier:sign_in; 121, argument_list; 121, 122; 121, 123; 122, identifier:user; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:user_type; 125, identifier:user_type; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:session; 130, identifier:add; 131, argument_list; 131, 132; 132, identifier:new_entry; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:status; 136, call; 136, 137; 136, 138; 137, identifier:Status; 138, argument_list; 138, 139; 138, 142; 138, 145; 138, 151; 138, 156; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:valid; 141, True; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:in_or_out; 144, string:'in'; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:user_name; 147, call; 147, 148; 147, 149; 148, identifier:get_user_name; 149, argument_list; 149, 150; 150, identifier:user; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:user_type; 153, attribute; 153, 154; 153, 155; 154, identifier:new_entry; 155, identifier:user_type; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:entry; 158, identifier:new_entry; 159, else_clause; 159, 160; 160, block; 160, 161; 161, for_statement; 161, 162; 161, 163; 161, 164; 162, identifier:entry; 163, identifier:signed_in_entries; 164, block; 164, 165; 164, 172; 164, 179; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:signed_out_entry; 168, call; 168, 169; 168, 170; 169, identifier:sign_out; 170, argument_list; 170, 171; 171, identifier:entry; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:session; 176, identifier:add; 177, argument_list; 177, 178; 178, identifier:signed_out_entry; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:status; 182, call; 182, 183; 182, 184; 183, identifier:Status; 184, argument_list; 184, 185; 184, 188; 184, 191; 184, 197; 184, 202; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:valid; 187, True; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:in_or_out; 190, string:'out'; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:user_name; 193, call; 193, 194; 193, 195; 194, identifier:get_user_name; 195, argument_list; 195, 196; 196, identifier:user; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:user_type; 199, attribute; 199, 200; 199, 201; 200, identifier:signed_out_entry; 201, identifier:user_type; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:entry; 204, identifier:signed_out_entry; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:session; 209, identifier:commit; 210, argument_list; 211, else_clause; 211, 212; 212, block; 212, 213; 213, raise_statement; 213, 214; 214, call; 214, 215; 214, 216; 215, identifier:UnregisteredUser; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, string:'{} not registered. Please register at the front desk.'; 220, identifier:format; 221, argument_list; 221, 222; 222, identifier:user_id; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:logger; 227, identifier:debug; 228, argument_list; 228, 229; 229, identifier:status; 230, return_statement; 230, 231; 231, identifier:status | def sign(user_id, user_type=None, today=None, session=None):
"""Check user id for validity, then sign user in if they are signed
out, or out if they are signed in.
:param user_id: The ID of the user to sign in or out.
:param user_type: (optional) Specify whether user is signing in as a `'student'` or `'tutor'`.
:param today: (optional) The current date as a `datetime.date` object. Used for testing.
:param session: (optional) SQLAlchemy session through which to access the database.
:return: `Status` named tuple object. Information about the sign attempt.
""" # noqa
if session is None:
session = Session()
else:
session = session
if today is None:
today = date.today()
else:
today = today
user = (
session
.query(User)
.filter(User.user_id == user_id)
.one_or_none()
)
if user:
signed_in_entries = (
user
.entries
.filter(Entry.date == today)
.filter(Entry.time_out.is_(None))
.all()
)
if not signed_in_entries:
new_entry = sign_in(user, user_type=user_type)
session.add(new_entry)
status = Status(
valid=True,
in_or_out='in',
user_name=get_user_name(user),
user_type=new_entry.user_type,
entry=new_entry
)
else:
for entry in signed_in_entries:
signed_out_entry = sign_out(entry)
session.add(signed_out_entry)
status = Status(
valid=True,
in_or_out='out',
user_name=get_user_name(user),
user_type=signed_out_entry.user_type,
entry=signed_out_entry
)
session.commit()
else:
raise UnregisteredUser(
'{} not registered. Please register at the front desk.'.format(
user_id
)
)
logger.debug(status)
return status |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:display; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:obj; 5, default_parameter; 5, 6; 5, 7; 6, identifier:skiphidden; 7, True; 8, dictionary_splat_pattern; 8, 9; 9, identifier:printargs; 10, block; 10, 11; 10, 13; 10, 20; 10, 21; 10, 22; 10, 23; 10, 42; 10, 92; 10, 127; 10, 215; 10, 216; 10, 217; 10, 218; 10, 249; 10, 250; 10, 251; 10, 264; 10, 283; 10, 293; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:top; 16, call; 16, 17; 16, 18; 17, identifier:findnode; 18, argument_list; 18, 19; 19, identifier:obj; 20, comment; 21, comment; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:maxhex; 26, binary_operator:-; 26, 27; 26, 41; 27, call; 27, 28; 27, 29; 28, identifier:len; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:hex; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:ctypes; 36, identifier:sizeof; 37, argument_list; 37, 38; 38, attribute; 38, 39; 38, 40; 39, identifier:top; 40, identifier:type; 41, integer:2; 42, function_definition; 42, 43; 42, 44; 42, 46; 43, function_name:addrformat; 44, parameters; 44, 45; 45, identifier:addr; 46, block; 46, 47; 47, if_statement; 47, 48; 47, 53; 47, 62; 48, call; 48, 49; 48, 50; 49, identifier:isinstance; 50, argument_list; 50, 51; 50, 52; 51, identifier:addr; 52, identifier:int; 53, block; 53, 54; 54, return_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, string:"0x{0:0{1}X}"; 58, identifier:format; 59, argument_list; 59, 60; 59, 61; 60, identifier:addr; 61, identifier:maxhex; 62, else_clause; 62, 63; 63, block; 63, 64; 63, 71; 63, 83; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:intpart; 67, call; 67, 68; 67, 69; 68, identifier:int; 69, argument_list; 69, 70; 70, identifier:addr; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:fracbits; 74, call; 74, 75; 74, 76; 75, identifier:int; 76, argument_list; 76, 77; 77, binary_operator:*; 77, 78; 77, 82; 78, parenthesized_expression; 78, 79; 79, binary_operator:-; 79, 80; 79, 81; 80, identifier:addr; 81, identifier:intpart; 82, integer:8; 83, return_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, string:"0x{0:0{1}X}'{2}"; 87, identifier:format; 88, argument_list; 88, 89; 88, 90; 88, 91; 89, identifier:intpart; 90, identifier:maxhex; 91, identifier:fracbits; 92, function_definition; 92, 93; 92, 94; 92, 96; 93, function_name:formatval; 94, parameters; 94, 95; 95, identifier:here; 96, block; 96, 97; 97, if_statement; 97, 98; 97, 103; 97, 118; 98, call; 98, 99; 98, 100; 99, identifier:isinstance; 100, argument_list; 100, 101; 100, 102; 101, identifier:here; 102, identifier:BoundSimpleNode; 103, block; 103, 104; 104, return_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, string:"{0}({1})"; 108, identifier:format; 109, argument_list; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:here; 113, identifier:type; 114, identifier:__name__; 115, attribute; 115, 116; 115, 117; 116, identifier:here; 117, identifier:value; 118, else_clause; 118, 119; 119, block; 119, 120; 120, return_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:str; 123, argument_list; 123, 124; 124, attribute; 124, 125; 124, 126; 125, identifier:here; 126, identifier:value; 127, if_statement; 127, 128; 127, 133; 127, 174; 128, call; 128, 129; 128, 130; 129, identifier:isinstance; 130, argument_list; 130, 131; 130, 132; 131, identifier:top; 132, identifier:UnboundNode; 133, block; 133, 134; 133, 141; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:headers; 137, list:['Path', 'Addr', 'Type']; 137, 138; 137, 139; 137, 140; 138, string:'Path'; 139, string:'Addr'; 140, string:'Type'; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:results; 144, list_comprehension; 144, 145; 144, 167; 145, tuple; 145, 146; 145, 156; 145, 162; 146, binary_operator:+; 146, 147; 146, 153; 147, parenthesized_expression; 147, 148; 148, binary_operator:*; 148, 149; 148, 150; 149, string:' '; 150, attribute; 150, 151; 150, 152; 151, identifier:n; 152, identifier:depth; 153, attribute; 153, 154; 153, 155; 154, identifier:n; 155, identifier:name; 156, call; 156, 157; 156, 158; 157, identifier:addrformat; 158, argument_list; 158, 159; 159, attribute; 159, 160; 159, 161; 160, identifier:n; 161, identifier:baseoffset; 162, attribute; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:n; 165, identifier:type; 166, identifier:__name__; 167, for_in_clause; 167, 168; 167, 169; 168, identifier:n; 169, call; 169, 170; 169, 171; 170, identifier:walknode; 171, argument_list; 171, 172; 171, 173; 172, identifier:top; 173, identifier:skiphidden; 174, else_clause; 174, 175; 175, block; 175, 176; 175, 183; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:headers; 179, list:['Path', 'Addr', 'Value']; 179, 180; 179, 181; 179, 182; 180, string:'Path'; 181, string:'Addr'; 182, string:'Value'; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:results; 186, list_comprehension; 186, 187; 186, 208; 187, tuple; 187, 188; 187, 198; 187, 204; 188, binary_operator:+; 188, 189; 188, 195; 189, parenthesized_expression; 189, 190; 190, binary_operator:*; 190, 191; 190, 192; 191, string:' '; 192, attribute; 192, 193; 192, 194; 193, identifier:n; 194, identifier:depth; 195, attribute; 195, 196; 195, 197; 196, identifier:n; 197, identifier:name; 198, call; 198, 199; 198, 200; 199, identifier:addrformat; 200, argument_list; 200, 201; 201, attribute; 201, 202; 201, 203; 202, identifier:n; 203, identifier:baseoffset; 204, call; 204, 205; 204, 206; 205, identifier:formatval; 206, argument_list; 206, 207; 207, identifier:n; 208, for_in_clause; 208, 209; 208, 210; 209, identifier:n; 210, call; 210, 211; 210, 212; 211, identifier:walknode; 212, argument_list; 212, 213; 212, 214; 213, identifier:top; 214, identifier:skiphidden; 215, comment; 216, comment; 217, comment; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:widths; 221, list_comprehension; 221, 222; 221, 241; 222, call; 222, 223; 222, 224; 223, identifier:max; 224, argument_list; 224, 225; 224, 237; 225, call; 225, 226; 225, 227; 226, identifier:max; 227, generator_expression; 227, 228; 227, 234; 228, call; 228, 229; 228, 230; 229, identifier:len; 230, argument_list; 230, 231; 231, subscript; 231, 232; 231, 233; 232, identifier:d; 233, identifier:col; 234, for_in_clause; 234, 235; 234, 236; 235, identifier:d; 236, identifier:results; 237, call; 237, 238; 237, 239; 238, identifier:len; 239, argument_list; 239, 240; 240, identifier:h; 241, for_in_clause; 241, 242; 241, 245; 242, pattern_list; 242, 243; 242, 244; 243, identifier:col; 244, identifier:h; 245, call; 245, 246; 245, 247; 246, identifier:enumerate; 247, argument_list; 247, 248; 248, identifier:headers; 249, comment; 250, comment; 251, function_definition; 251, 252; 251, 253; 251, 255; 252, function_name:lp; 253, parameters; 253, 254; 254, identifier:args; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 259; 258, identifier:print; 259, argument_list; 259, 260; 259, 262; 260, list_splat; 260, 261; 261, identifier:args; 262, dictionary_splat; 262, 263; 263, identifier:printargs; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:lp; 267, generator_expression; 267, 268; 267, 274; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:d; 271, identifier:center; 272, argument_list; 272, 273; 273, identifier:w; 274, for_in_clause; 274, 275; 274, 278; 275, pattern_list; 275, 276; 275, 277; 276, identifier:d; 277, identifier:w; 278, call; 278, 279; 278, 280; 279, identifier:zip; 280, argument_list; 280, 281; 280, 282; 281, identifier:headers; 282, identifier:widths; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 286; 285, identifier:lp; 286, generator_expression; 286, 287; 286, 290; 287, binary_operator:*; 287, 288; 287, 289; 288, string:'-'; 289, identifier:w; 290, for_in_clause; 290, 291; 290, 292; 291, identifier:w; 292, identifier:widths; 293, for_statement; 293, 294; 293, 295; 293, 296; 294, identifier:r; 295, identifier:results; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 300; 299, identifier:lp; 300, generator_expression; 300, 301; 300, 307; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:d; 304, identifier:ljust; 305, argument_list; 305, 306; 306, identifier:w; 307, for_in_clause; 307, 308; 307, 311; 308, pattern_list; 308, 309; 308, 310; 309, identifier:d; 310, identifier:w; 311, call; 311, 312; 311, 313; 312, identifier:zip; 313, argument_list; 313, 314; 313, 315; 314, identifier:r; 315, identifier:widths | def display(obj, skiphidden=True, **printargs):
"""Print a view of obj, where obj is either a ctypes-derived class or an
instance of such a class. Any additional keyword arguments are passed
directly to the print function.
This is mostly useful to introspect structures from an interactive session.
"""
top = findnode(obj)
#-------------------------------------------------------------------
# Iterate through the entire structure turning all the nodes into
# tuples of strings for display.
maxhex = len(hex(ctypes.sizeof(top.type))) - 2
def addrformat(addr):
if isinstance(addr, int):
return "0x{0:0{1}X}".format(addr, maxhex)
else:
intpart = int(addr)
fracbits = int((addr - intpart) * 8)
return "0x{0:0{1}X}'{2}".format(intpart, maxhex, fracbits)
def formatval(here):
if isinstance(here, BoundSimpleNode):
return "{0}({1})".format(here.type.__name__, here.value)
else:
return str(here.value)
if isinstance(top, UnboundNode):
headers = ['Path', 'Addr', 'Type']
results = [
((' ' * n.depth) + n.name, addrformat(n.baseoffset), n.type.__name__)
for n in walknode(top, skiphidden)
]
else:
headers = ['Path', 'Addr', 'Value']
results = [
((' ' * n.depth) + n.name, addrformat(n.baseoffset), formatval(n))
for n in walknode(top, skiphidden)
]
#-------------------------------------------------------------------
# Determine the maximum width of the text in each column, make the
# column always that wide.
widths = [
max(max(len(d[col]) for d in results), len(h))
for col, h in enumerate(headers)
]
#-------------------------------------------------------------------
# Print out the tabular data.
def lp(args):
print(*args, **printargs)
lp(d.center(w) for d, w in zip(headers, widths))
lp('-' * w for w in widths)
for r in results:
lp(d.ljust(w) for d, w in zip(r, widths)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 1, 11; 2, function_name:assemble; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 8; 4, identifier:self; 5, identifier:module; 6, list_splat_pattern; 6, 7; 7, identifier:modules; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, comment; 11, block; 11, 12; 11, 14; 11, 50; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:mgr; 17, call; 17, 18; 17, 19; 18, identifier:AssemblyManager; 19, argument_list; 19, 20; 19, 23; 19, 32; 19, 41; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:vector; 22, identifier:self; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:modules; 25, binary_operator:+; 25, 26; 25, 28; 26, list:[module]; 26, 27; 27, identifier:module; 28, call; 28, 29; 28, 30; 29, identifier:list; 30, argument_list; 30, 31; 31, identifier:modules; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:name; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:kwargs; 37, identifier:get; 38, argument_list; 38, 39; 38, 40; 39, string:"name"; 40, string:"assembly"; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:id_; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:kwargs; 46, identifier:get; 47, argument_list; 47, 48; 47, 49; 48, string:"id"; 49, string:"assembly"; 50, return_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:mgr; 54, identifier:assemble; 55, argument_list | def assemble(self, module, *modules, **kwargs):
# type: (AbstractModule, *AbstractModule, **Any) -> SeqRecord
"""Assemble the provided modules into the vector.
Arguments:
module (`~moclo.base.modules.AbstractModule`): a module to insert
in the vector.
modules (`~moclo.base.modules.AbstractModule`, optional): additional
modules to insert in the vector. The order of the parameters
is not important, since modules will be sorted by their start
overhang in the function.
Returns:
`~Bio.SeqRecord.SeqRecord`: the assembled sequence with sequence
annotations inherited from the vector and the modules.
Raises:
`~moclo.errors.DuplicateModules`: when two different modules share
the same start overhang, leading in possibly non-deterministic
constructs.
`~moclo.errors.MissingModule`: when a module has an end overhang
that is not shared by any other module, leading to a partial
construct only
`~moclo.errors.InvalidSequence`: when one of the modules does not
match the required module structure (missing site, wrong
overhang, etc.).
`~moclo.errors.UnusedModules`: when some modules were not used
during the assembly (mostly caused by duplicate parts).
"""
mgr = AssemblyManager(
vector=self,
modules=[module] + list(modules),
name=kwargs.get("name", "assembly"),
id_=kwargs.get("id", "assembly"),
)
return mgr.assemble() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:getback; 3, parameters; 3, 4; 3, 5; 4, identifier:config; 5, default_parameter; 5, 6; 5, 7; 6, identifier:force; 7, False; 8, block; 8, 9; 8, 11; 8, 17; 8, 23; 8, 35; 8, 73; 8, 79; 8, 88; 8, 98; 8, 102; 8, 106; 8, 125; 8, 139; 8, 140; 8, 150; 8, 161; 8, 162; 8, 163; 8, 204; 8, 210; 8, 216; 8, 246; 8, 252; 8, 277; 8, 281; 8, 304; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:repo; 14, attribute; 14, 15; 14, 16; 15, identifier:config; 16, identifier:repo; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:active_branch; 20, attribute; 20, 21; 20, 22; 21, identifier:repo; 22, identifier:active_branch; 23, if_statement; 23, 24; 23, 29; 24, comparison_operator:==; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:active_branch; 27, identifier:name; 28, string:"master"; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:error_out; 33, argument_list; 33, 34; 34, string:"You're already on the master branch."; 35, if_statement; 35, 36; 35, 41; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:repo; 39, identifier:is_dirty; 40, argument_list; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:error_out; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, string:'Repo is "dirty". ({})'; 49, identifier:format; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, string:", "; 54, identifier:join; 55, argument_list; 55, 56; 56, list_comprehension; 56, 57; 56, 63; 57, call; 57, 58; 57, 59; 58, identifier:repr; 59, argument_list; 59, 60; 60, attribute; 60, 61; 60, 62; 61, identifier:x; 62, identifier:b_path; 63, for_in_clause; 63, 64; 63, 65; 64, identifier:x; 65, call; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:repo; 69, identifier:index; 70, identifier:diff; 71, argument_list; 71, 72; 72, None; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:branch_name; 76, attribute; 76, 77; 76, 78; 77, identifier:active_branch; 78, identifier:name; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:state; 82, call; 82, 83; 82, 84; 83, identifier:read; 84, argument_list; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:config; 87, identifier:configfile; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:origin_name; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:state; 94, identifier:get; 95, argument_list; 95, 96; 95, 97; 96, string:"ORIGIN_NAME"; 97, string:"origin"; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:upstream_remote; 101, None; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:fork_remote; 105, None; 106, for_statement; 106, 107; 106, 108; 106, 111; 107, identifier:remote; 108, attribute; 108, 109; 108, 110; 109, identifier:repo; 110, identifier:remotes; 111, block; 111, 112; 112, if_statement; 112, 113; 112, 118; 112, 119; 113, comparison_operator:==; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:remote; 116, identifier:name; 117, identifier:origin_name; 118, comment; 119, block; 119, 120; 119, 124; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:upstream_remote; 123, identifier:remote; 124, break_statement; 125, if_statement; 125, 126; 125, 128; 126, not_operator; 126, 127; 127, identifier:upstream_remote; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:error_out; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, string:"No remote called {!r} found"; 136, identifier:format; 137, argument_list; 137, 138; 138, identifier:origin_name; 139, comment; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 149; 142, attribute; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:repo; 146, identifier:heads; 147, identifier:master; 148, identifier:checkout; 149, argument_list; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:upstream_remote; 154, identifier:pull; 155, argument_list; 155, 156; 156, attribute; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:repo; 159, identifier:heads; 160, identifier:master; 161, comment; 162, comment; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:merged_branches; 166, list_comprehension; 166, 167; 166, 172; 166, 186; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:x; 170, identifier:strip; 171, argument_list; 172, for_in_clause; 172, 173; 172, 174; 173, identifier:x; 174, call; 174, 175; 174, 185; 175, attribute; 175, 176; 175, 184; 176, call; 176, 177; 176, 182; 177, attribute; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:repo; 180, identifier:git; 181, identifier:branch; 182, argument_list; 182, 183; 183, string:"--merged"; 184, identifier:splitlines; 185, argument_list; 186, if_clause; 186, 187; 187, boolean_operator:and; 187, 188; 187, 193; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:x; 191, identifier:strip; 192, argument_list; 193, not_operator; 193, 194; 194, call; 194, 195; 194, 202; 195, attribute; 195, 196; 195, 201; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:x; 199, identifier:strip; 200, argument_list; 201, identifier:startswith; 202, argument_list; 202, 203; 203, string:"*"; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:was_merged; 207, comparison_operator:in; 207, 208; 207, 209; 208, identifier:branch_name; 209, identifier:merged_branches; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:certain; 213, boolean_operator:or; 213, 214; 213, 215; 214, identifier:was_merged; 215, identifier:force; 216, if_statement; 216, 217; 216, 219; 216, 220; 216, 221; 216, 222; 217, not_operator; 217, 218; 218, identifier:certain; 219, comment; 220, comment; 221, comment; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:certain; 226, parenthesized_expression; 226, 227; 227, comparison_operator:!=; 227, 228; 227, 245; 228, call; 228, 229; 228, 244; 229, attribute; 229, 230; 229, 243; 230, call; 230, 231; 230, 242; 231, attribute; 231, 232; 231, 241; 232, call; 232, 233; 232, 234; 233, identifier:input; 234, argument_list; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, string:"Are you certain {} is actually merged? [Y/n] "; 238, identifier:format; 239, argument_list; 239, 240; 240, identifier:branch_name; 241, identifier:lower; 242, argument_list; 243, identifier:strip; 244, argument_list; 245, string:"n"; 246, if_statement; 246, 247; 246, 249; 247, not_operator; 247, 248; 248, identifier:certain; 249, block; 249, 250; 250, return_statement; 250, 251; 251, integer:1; 252, if_statement; 252, 253; 252, 254; 252, 265; 253, identifier:was_merged; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 262; 257, attribute; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:repo; 260, identifier:git; 261, identifier:branch; 262, argument_list; 262, 263; 262, 264; 263, string:"-d"; 264, identifier:branch_name; 265, else_clause; 265, 266; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 274; 269, attribute; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:repo; 272, identifier:git; 273, identifier:branch; 274, argument_list; 274, 275; 274, 276; 275, string:"-D"; 276, identifier:branch_name; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:fork_remote; 280, None; 281, for_statement; 281, 282; 281, 283; 281, 286; 282, identifier:remote; 283, attribute; 283, 284; 283, 285; 284, identifier:repo; 285, identifier:remotes; 286, block; 286, 287; 287, if_statement; 287, 288; 287, 298; 288, comparison_operator:==; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:remote; 291, identifier:name; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:state; 295, identifier:get; 296, argument_list; 296, 297; 297, string:"FORK_NAME"; 298, block; 298, 299; 298, 303; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:fork_remote; 302, identifier:remote; 303, break_statement; 304, if_statement; 304, 305; 304, 306; 305, identifier:fork_remote; 306, block; 306, 307; 306, 316; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:fork_remote; 311, identifier:push; 312, argument_list; 312, 313; 313, binary_operator:+; 313, 314; 313, 315; 314, string:":"; 315, identifier:branch_name; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 319; 318, identifier:info_out; 319, argument_list; 319, 320; 320, string:"Remote branch on fork deleted too." | def getback(config, force=False):
"""Goes back to the master branch, deletes the current branch locally
and remotely."""
repo = config.repo
active_branch = repo.active_branch
if active_branch.name == "master":
error_out("You're already on the master branch.")
if repo.is_dirty():
error_out(
'Repo is "dirty". ({})'.format(
", ".join([repr(x.b_path) for x in repo.index.diff(None)])
)
)
branch_name = active_branch.name
state = read(config.configfile)
origin_name = state.get("ORIGIN_NAME", "origin")
upstream_remote = None
fork_remote = None
for remote in repo.remotes:
if remote.name == origin_name:
# remote.pull()
upstream_remote = remote
break
if not upstream_remote:
error_out("No remote called {!r} found".format(origin_name))
# Check out master
repo.heads.master.checkout()
upstream_remote.pull(repo.heads.master)
# Is this one of the merged branches?!
# XXX I don't know how to do this "natively" with GitPython.
merged_branches = [
x.strip()
for x in repo.git.branch("--merged").splitlines()
if x.strip() and not x.strip().startswith("*")
]
was_merged = branch_name in merged_branches
certain = was_merged or force
if not certain:
# Need to ask the user.
# XXX This is where we could get smart and compare this branch
# with the master.
certain = (
input("Are you certain {} is actually merged? [Y/n] ".format(branch_name))
.lower()
.strip()
!= "n"
)
if not certain:
return 1
if was_merged:
repo.git.branch("-d", branch_name)
else:
repo.git.branch("-D", branch_name)
fork_remote = None
for remote in repo.remotes:
if remote.name == state.get("FORK_NAME"):
fork_remote = remote
break
if fork_remote:
fork_remote.push(":" + branch_name)
info_out("Remote branch on fork deleted too.") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:untldict_normalizer; 3, parameters; 3, 4; 3, 5; 4, identifier:untl_dict; 5, identifier:normalizations; 6, block; 6, 7; 6, 9; 6, 10; 6, 110; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, for_statement; 10, 11; 10, 14; 10, 19; 10, 20; 11, pattern_list; 11, 12; 11, 13; 12, identifier:element_type; 13, identifier:element_list; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:untl_dict; 17, identifier:items; 18, argument_list; 19, comment; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 25; 21, 26; 22, comparison_operator:in; 22, 23; 22, 24; 23, identifier:element_type; 24, identifier:normalizations; 25, comment; 26, block; 26, 27; 26, 36; 26, 37; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:norm_qualifier_list; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:normalizations; 33, identifier:get; 34, argument_list; 34, 35; 35, identifier:element_type; 36, comment; 37, for_statement; 37, 38; 37, 39; 37, 40; 37, 41; 38, identifier:element; 39, identifier:element_list; 40, comment; 41, block; 41, 42; 41, 52; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:qualifier; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:element; 48, identifier:get; 49, argument_list; 49, 50; 49, 51; 50, string:'qualifier'; 51, None; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:in; 53, 54; 53, 55; 54, identifier:qualifier; 55, identifier:norm_qualifier_list; 56, block; 56, 57; 56, 67; 56, 68; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:content; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:element; 63, identifier:get; 64, argument_list; 64, 65; 64, 66; 65, string:'content'; 66, None; 67, comment; 68, if_statement; 68, 69; 68, 72; 69, comparison_operator:in; 69, 70; 69, 71; 70, identifier:element_type; 71, identifier:ELEMENT_NORMALIZERS; 72, block; 72, 73; 72, 83; 72, 84; 72, 85; 72, 86; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:elem_norms; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:ELEMENT_NORMALIZERS; 79, identifier:get; 80, argument_list; 80, 81; 80, 82; 81, identifier:element_type; 82, None; 83, comment; 84, comment; 85, comment; 86, if_statement; 86, 87; 86, 90; 87, comparison_operator:in; 87, 88; 87, 89; 88, identifier:qualifier; 89, identifier:elem_norms; 90, block; 90, 91; 91, if_statement; 91, 92; 91, 97; 92, boolean_operator:and; 92, 93; 92, 94; 93, identifier:content; 94, comparison_operator:!=; 94, 95; 94, 96; 95, identifier:content; 96, string:''; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 99, 104; 100, subscript; 100, 101; 100, 102; 101, identifier:element; 102, string:'content'; 103, line_continuation:\; 104, call; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:elem_norms; 107, identifier:qualifier; 108, argument_list; 108, 109; 109, identifier:content; 110, return_statement; 110, 111; 111, identifier:untl_dict | def untldict_normalizer(untl_dict, normalizations):
"""Normalize UNTL elements by their qualifier.
Takes a UNTL descriptive metadata dictionary and a dictionary of
the elements and the qualifiers for normalization:
{'element1': ['qualifier1', 'qualifier2'],
'element2': ['qualifier3']}
and normalizes the elements with that qualifier.
"""
# Loop through the element types in the UNTL metadata.
for element_type, element_list in untl_dict.items():
# A normalization is required for that element type.
if element_type in normalizations:
# Get the required normalizations for specific qualifiers list.
norm_qualifier_list = normalizations.get(element_type)
# Loop through the element lists within that element type.
for element in element_list:
# Determine if the qualifier requires normalization.
qualifier = element.get('qualifier', None)
if qualifier in norm_qualifier_list:
content = element.get('content', None)
# Determine if there is normalizing for the element.
if element_type in ELEMENT_NORMALIZERS:
elem_norms = ELEMENT_NORMALIZERS.get(element_type,
None)
# If the qualified element requires a
# normalization and has content, replace the
# content with the normalized.
if qualifier in elem_norms:
if content and content != '':
element['content'] = \
elem_norms[qualifier](content)
return untl_dict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:start; 3, parameters; 3, 4; 3, 5; 4, identifier:config; 5, default_parameter; 5, 6; 5, 7; 6, identifier:bugnumber; 7, string:""; 8, block; 8, 9; 8, 11; 8, 17; 8, 41; 8, 75; 8, 79; 8, 114; 8, 200; 8, 207; 8, 216; 8, 217; 8, 231; 8, 248; 8, 257; 8, 263; 8, 280; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:repo; 14, attribute; 14, 15; 14, 16; 15, identifier:config; 16, identifier:repo; 17, if_statement; 17, 18; 17, 19; 17, 31; 18, identifier:bugnumber; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 26; 22, pattern_list; 22, 23; 22, 24; 22, 25; 23, identifier:summary; 24, identifier:bugnumber; 25, identifier:url; 26, call; 26, 27; 26, 28; 27, identifier:get_summary; 28, argument_list; 28, 29; 28, 30; 29, identifier:config; 30, identifier:bugnumber; 31, else_clause; 31, 32; 32, block; 32, 33; 32, 37; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:url; 36, None; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:summary; 40, None; 41, if_statement; 41, 42; 41, 43; 41, 62; 42, identifier:summary; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:summary; 47, boolean_operator:or; 47, 48; 47, 61; 48, call; 48, 49; 48, 60; 49, attribute; 49, 50; 49, 59; 50, call; 50, 51; 50, 52; 51, identifier:input; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, string:'Summary ["{}"]: '; 56, identifier:format; 57, argument_list; 57, 58; 58, identifier:summary; 59, identifier:strip; 60, argument_list; 61, identifier:summary; 62, else_clause; 62, 63; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:summary; 67, call; 67, 68; 67, 74; 68, attribute; 68, 69; 68, 73; 69, call; 69, 70; 69, 71; 70, identifier:input; 71, argument_list; 71, 72; 72, string:"Summary: "; 73, identifier:strip; 74, argument_list; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:branch_name; 78, string:""; 79, if_statement; 79, 80; 79, 81; 80, identifier:bugnumber; 81, block; 81, 82; 82, if_statement; 82, 83; 82, 93; 82, 103; 83, call; 83, 84; 83, 85; 84, identifier:is_github; 85, argument_list; 85, 86; 86, dictionary; 86, 87; 86, 90; 87, pair; 87, 88; 87, 89; 88, string:"bugnumber"; 89, identifier:bugnumber; 90, pair; 90, 91; 90, 92; 91, string:"url"; 92, identifier:url; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:branch_name; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, string:"{}-"; 100, identifier:format; 101, argument_list; 101, 102; 102, identifier:bugnumber; 103, else_clause; 103, 104; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:branch_name; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, string:"{}-"; 111, identifier:format; 112, argument_list; 112, 113; 113, identifier:bugnumber; 114, function_definition; 114, 115; 114, 116; 114, 118; 115, function_name:clean_branch_name; 116, parameters; 116, 117; 117, identifier:string; 118, block; 118, 119; 118, 130; 118, 140; 118, 156; 118, 170; 118, 181; 118, 190; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:string; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:re; 125, identifier:sub; 126, argument_list; 126, 127; 126, 128; 126, 129; 127, string:r"\s+"; 128, string:" "; 129, identifier:string; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:string; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:string; 136, identifier:replace; 137, argument_list; 137, 138; 137, 139; 138, string:" "; 139, string:"-"; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:string; 143, call; 143, 144; 143, 153; 144, attribute; 144, 145; 144, 152; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:string; 148, identifier:replace; 149, argument_list; 149, 150; 149, 151; 150, string:"->"; 151, string:"-"; 152, identifier:replace; 153, argument_list; 153, 154; 153, 155; 154, string:"=>"; 155, string:"-"; 156, for_statement; 156, 157; 156, 158; 156, 159; 157, identifier:each; 158, string:"@%^&:'\"/(),[]{}!.?`$<>#*;="; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:string; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:string; 166, identifier:replace; 167, argument_list; 167, 168; 167, 169; 168, identifier:each; 169, string:""; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:string; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:re; 176, identifier:sub; 177, argument_list; 177, 178; 177, 179; 177, 180; 178, string:"-+"; 179, string:"-"; 180, identifier:string; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:string; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:string; 187, identifier:strip; 188, argument_list; 188, 189; 189, string:"-"; 190, return_statement; 190, 191; 191, call; 191, 192; 191, 199; 192, attribute; 192, 193; 192, 198; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:string; 196, identifier:lower; 197, argument_list; 198, identifier:strip; 199, argument_list; 200, expression_statement; 200, 201; 201, augmented_assignment:+=; 201, 202; 201, 203; 202, identifier:branch_name; 203, call; 203, 204; 203, 205; 204, identifier:clean_branch_name; 205, argument_list; 205, 206; 206, identifier:summary; 207, if_statement; 207, 208; 207, 210; 208, not_operator; 208, 209; 209, identifier:branch_name; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:error_out; 214, argument_list; 214, 215; 215, string:"Must provide a branch name"; 216, comment; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:found; 220, call; 220, 221; 220, 222; 221, identifier:list; 222, argument_list; 222, 223; 223, call; 223, 224; 223, 225; 224, identifier:find; 225, argument_list; 225, 226; 225, 227; 225, 228; 226, identifier:repo; 227, identifier:branch_name; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:exact; 230, True; 231, if_statement; 231, 232; 231, 233; 232, identifier:found; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 237; 236, identifier:error_out; 237, argument_list; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, string:"There is already a branch called {!r}"; 241, identifier:format; 242, argument_list; 242, 243; 243, attribute; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:found; 246, integer:0; 247, identifier:name; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:new_branch; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:repo; 254, identifier:create_head; 255, argument_list; 255, 256; 256, identifier:branch_name; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:new_branch; 261, identifier:checkout; 262, argument_list; 263, if_statement; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:config; 266, identifier:verbose; 267, block; 267, 268; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:click; 272, identifier:echo; 273, argument_list; 273, 274; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, string:"Checkout out new branch: {}"; 277, identifier:format; 278, argument_list; 278, 279; 279, identifier:branch_name; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 283; 282, identifier:save; 283, argument_list; 283, 284; 283, 287; 283, 288; 283, 289; 283, 292; 284, attribute; 284, 285; 284, 286; 285, identifier:config; 286, identifier:configfile; 287, identifier:summary; 288, identifier:branch_name; 289, keyword_argument; 289, 290; 289, 291; 290, identifier:bugnumber; 291, identifier:bugnumber; 292, keyword_argument; 292, 293; 292, 294; 293, identifier:url; 294, identifier:url | def start(config, bugnumber=""):
"""Create a new topic branch."""
repo = config.repo
if bugnumber:
summary, bugnumber, url = get_summary(config, bugnumber)
else:
url = None
summary = None
if summary:
summary = input('Summary ["{}"]: '.format(summary)).strip() or summary
else:
summary = input("Summary: ").strip()
branch_name = ""
if bugnumber:
if is_github({"bugnumber": bugnumber, "url": url}):
branch_name = "{}-".format(bugnumber)
else:
branch_name = "{}-".format(bugnumber)
def clean_branch_name(string):
string = re.sub(r"\s+", " ", string)
string = string.replace(" ", "-")
string = string.replace("->", "-").replace("=>", "-")
for each in "@%^&:'\"/(),[]{}!.?`$<>#*;=":
string = string.replace(each, "")
string = re.sub("-+", "-", string)
string = string.strip("-")
return string.lower().strip()
branch_name += clean_branch_name(summary)
if not branch_name:
error_out("Must provide a branch name")
# Check that the branch doesn't already exist
found = list(find(repo, branch_name, exact=True))
if found:
error_out("There is already a branch called {!r}".format(found[0].name))
new_branch = repo.create_head(branch_name)
new_branch.checkout()
if config.verbose:
click.echo("Checkout out new branch: {}".format(branch_name))
save(config.configfile, summary, branch_name, bugnumber=bugnumber, url=url) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 12; 2, function_name:getPortSideView; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:side; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, string:"LPort"; 12, block; 12, 13; 12, 15; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 21; 15, 26; 15, 37; 15, 48; 15, 59; 16, comparison_operator:==; 16, 17; 16, 18; 17, identifier:side; 18, attribute; 18, 19; 18, 20; 19, identifier:PortSide; 20, identifier:WEST; 21, block; 21, 22; 22, return_statement; 22, 23; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:west; 26, elif_clause; 26, 27; 26, 32; 27, comparison_operator:==; 27, 28; 27, 29; 28, identifier:side; 29, attribute; 29, 30; 29, 31; 30, identifier:PortSide; 31, identifier:EAST; 32, block; 32, 33; 33, return_statement; 33, 34; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:east; 37, elif_clause; 37, 38; 37, 43; 38, comparison_operator:==; 38, 39; 38, 40; 39, identifier:side; 40, attribute; 40, 41; 40, 42; 41, identifier:PortSide; 42, identifier:NORTH; 43, block; 43, 44; 44, return_statement; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:north; 48, elif_clause; 48, 49; 48, 54; 49, comparison_operator:==; 49, 50; 49, 51; 50, identifier:side; 51, attribute; 51, 52; 51, 53; 52, identifier:PortSide; 53, identifier:SOUTH; 54, block; 54, 55; 55, return_statement; 55, 56; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:south; 59, else_clause; 59, 60; 60, block; 60, 61; 61, raise_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:ValueError; 64, argument_list; 64, 65; 65, identifier:side | def getPortSideView(self, side) -> List["LPort"]:
"""
Returns a sublist view for all ports of given side.
:attention: Use this only after port sides are fixed!
This is currently the case after running the {@link org.eclipse.elk.alg.layered.intermediate.PortListSorter}.
Non-structural changes to this list are reflected in the original list. A structural modification is any
operation that adds or deletes one or more elements; merely setting the value of an element is not a structural
modification. Sublist indices can be cached using {@link LNode#cachePortSides()}.
:param side: a port side
:return: an iterable for the ports of given side
"""
if side == PortSide.WEST:
return self.west
elif side == PortSide.EAST:
return self.east
elif side == PortSide.NORTH:
return self.north
elif side == PortSide.SOUTH:
return self.south
else:
raise ValueError(side) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:command_line_config; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 18; 5, 22; 5, 26; 5, 30; 5, 110; 5, 210; 5, 243; 5, 244; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:args; 11, subscript; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:sys; 14, identifier:argv; 15, slice; 15, 16; 15, 17; 16, integer:1; 17, colon; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:args_dict; 21, dictionary; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:existed_keys; 25, list:[]; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:new_keys; 29, list:[]; 30, for_statement; 30, 31; 30, 32; 30, 33; 31, identifier:t; 32, identifier:args; 33, block; 33, 34; 33, 52; 33, 83; 33, 89; 34, if_statement; 34, 35; 34, 42; 35, not_operator; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:t; 39, identifier:startswith; 40, argument_list; 40, 41; 41, string:'--'; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:errors; 47, identifier:ArgsParseError; 48, argument_list; 48, 49; 49, binary_operator:%; 49, 50; 49, 51; 50, string:'Bad arg: %s'; 51, identifier:t; 52, try_statement; 52, 53; 52, 72; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, pattern_list; 56, 57; 56, 58; 57, identifier:key; 58, identifier:value; 59, call; 59, 60; 59, 61; 60, identifier:tuple; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 70; 63, attribute; 63, 64; 63, 69; 64, subscript; 64, 65; 64, 66; 65, identifier:t; 66, slice; 66, 67; 66, 68; 67, integer:2; 68, colon; 69, identifier:split; 70, argument_list; 70, 71; 71, string:'='; 72, except_clause; 72, 73; 73, block; 73, 74; 74, raise_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:errors; 78, identifier:ArgsParseError; 79, argument_list; 79, 80; 80, binary_operator:%; 80, 81; 80, 82; 81, string:'Bad arg: %s'; 82, identifier:t; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:args_dict; 87, identifier:key; 88, identifier:value; 89, if_statement; 89, 90; 89, 93; 89, 101; 90, comparison_operator:in; 90, 91; 90, 92; 91, identifier:key; 92, identifier:settings; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:existed_keys; 98, identifier:append; 99, argument_list; 99, 100; 100, identifier:key; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:new_keys; 107, identifier:append; 108, argument_list; 108, 109; 109, identifier:key; 110, if_statement; 110, 111; 110, 112; 111, identifier:existed_keys; 112, block; 112, 113; 112, 120; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:app_log; 117, identifier:debug; 118, argument_list; 118, 119; 119, string:'Changed settings:'; 120, for_statement; 120, 121; 120, 122; 120, 123; 121, identifier:i; 122, identifier:existed_keys; 123, block; 123, 124; 123, 130; 123, 137; 123, 186; 123, 192; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:before; 127, subscript; 127, 128; 127, 129; 128, identifier:settings; 129, identifier:i; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:type_; 133, call; 133, 134; 133, 135; 134, identifier:type; 135, argument_list; 135, 136; 136, identifier:before; 137, if_statement; 137, 138; 137, 141; 137, 175; 138, comparison_operator:is; 138, 139; 138, 140; 139, identifier:type_; 140, identifier:bool; 141, block; 141, 142; 142, if_statement; 142, 143; 142, 148; 142, 153; 142, 164; 143, comparison_operator:==; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:args_dict; 146, identifier:i; 147, string:'True'; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:_value; 152, True; 153, elif_clause; 153, 154; 153, 159; 154, comparison_operator:==; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:args_dict; 157, identifier:i; 158, string:'False'; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:_value; 163, False; 164, else_clause; 164, 165; 165, block; 165, 166; 166, raise_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:errors; 170, identifier:ArgsParseError; 171, argument_list; 171, 172; 172, binary_operator:%; 172, 173; 172, 174; 173, string:'%s should only be True or False'; 174, identifier:i; 175, else_clause; 175, 176; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:_value; 180, call; 180, 181; 180, 182; 181, identifier:type_; 182, argument_list; 182, 183; 183, subscript; 183, 184; 183, 185; 184, identifier:args_dict; 185, identifier:i; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 191; 188, subscript; 188, 189; 188, 190; 189, identifier:settings; 190, identifier:i; 191, identifier:_value; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:app_log; 196, identifier:debug; 197, argument_list; 197, 198; 197, 199; 197, 200; 197, 206; 197, 209; 198, string:' %s [%s]%s (%s)'; 199, identifier:i; 200, call; 200, 201; 200, 202; 201, identifier:type; 202, argument_list; 202, 203; 203, subscript; 203, 204; 203, 205; 204, identifier:settings; 205, identifier:i; 206, subscript; 206, 207; 206, 208; 207, identifier:settings; 208, identifier:i; 209, identifier:before; 210, if_statement; 210, 211; 210, 212; 211, identifier:new_keys; 212, block; 212, 213; 212, 220; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:app_log; 217, identifier:debug; 218, argument_list; 218, 219; 219, string:'New settings:'; 220, for_statement; 220, 221; 220, 222; 220, 223; 221, identifier:i; 222, identifier:new_keys; 223, block; 223, 224; 223, 232; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:settings; 228, identifier:i; 229, subscript; 229, 230; 229, 231; 230, identifier:args_dict; 231, identifier:i; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:app_log; 236, identifier:debug; 237, argument_list; 237, 238; 237, 239; 237, 240; 238, string:' %s %s'; 239, identifier:i; 240, subscript; 240, 241; 240, 242; 241, identifier:args_dict; 242, identifier:i; 243, comment; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:update_settings; 249, argument_list; 249, 250; 250, dictionary | def command_line_config(self):
"""
settings.py is the basis
if wants to change them by command line arguments,
the existing option will be transformed to the value type in settings.py
the unexisting option will be treated as string by default,
and transform to certain type if `!<type>` was added after the value.
example:
$ python app.py --PORT=1000
NOTE This method is deprecated, use `torext.script` to parse command line arguments instead.
"""
args = sys.argv[1:]
args_dict = {}
existed_keys = []
new_keys = []
for t in args:
if not t.startswith('--'):
raise errors.ArgsParseError('Bad arg: %s' % t)
try:
key, value = tuple(t[2:].split('='))
except:
raise errors.ArgsParseError('Bad arg: %s' % t)
args_dict[key] = value
if key in settings:
existed_keys.append(key)
else:
new_keys.append(key)
if existed_keys:
app_log.debug('Changed settings:')
for i in existed_keys:
before = settings[i]
type_ = type(before)
if type_ is bool:
if args_dict[i] == 'True':
_value = True
elif args_dict[i] == 'False':
_value = False
else:
raise errors.ArgsParseError('%s should only be True or False' % i)
else:
_value = type_(args_dict[i])
settings[i] = _value
app_log.debug(' %s [%s]%s (%s)', i, type(settings[i]), settings[i], before)
if new_keys:
app_log.debug('New settings:')
for i in new_keys:
settings[i] = args_dict[i]
app_log.debug(' %s %s', i, args_dict[i])
# NOTE if ``command_line_config`` is called, logging must be re-configed
self.update_settings({}) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:create_form_data; 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, 11; 7, 21; 7, 31; 7, 41; 7, 51; 7, 52; 7, 60; 7, 61; 7, 211; 7, 215; 7, 216; 7, 279; 7, 280; 7, 328; 7, 329; 7, 341; 7, 342; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:children; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:kwargs; 17, identifier:get; 18, argument_list; 18, 19; 18, 20; 19, string:'children'; 20, list:[]; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:sort_order; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:kwargs; 27, identifier:get; 28, argument_list; 28, 29; 28, 30; 29, string:'sort_order'; 30, None; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:solr_response; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:kwargs; 37, identifier:get; 38, argument_list; 38, 39; 38, 40; 39, string:'solr_response'; 40, None; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:superuser; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:kwargs; 47, identifier:get; 48, argument_list; 48, 49; 48, 50; 49, string:'superuser'; 50, False; 51, comment; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:vocabularies; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:get_vocabularies; 59, argument_list; 60, comment; 61, for_statement; 61, 62; 61, 63; 61, 64; 61, 65; 62, identifier:element; 63, identifier:children; 64, comment; 65, block; 65, 66; 65, 80; 65, 81; 65, 103; 65, 104; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:element; 70, identifier:children; 71, call; 71, 72; 71, 73; 72, identifier:add_missing_children; 73, argument_list; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:element; 76, identifier:contained_children; 77, attribute; 77, 78; 77, 79; 78, identifier:element; 79, identifier:children; 80, comment; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:element; 85, identifier:add_form; 86, argument_list; 86, 87; 86, 90; 86, 95; 86, 100; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:vocabularies; 89, identifier:vocabularies; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:qualifier; 92, attribute; 92, 93; 92, 94; 93, identifier:element; 94, identifier:qualifier; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:content; 97, attribute; 97, 98; 97, 99; 98, identifier:element; 99, identifier:content; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:superuser; 102, identifier:superuser; 103, comment; 104, if_statement; 104, 105; 104, 110; 104, 111; 104, 112; 105, attribute; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:element; 108, identifier:form; 109, identifier:has_children; 110, comment; 111, comment; 112, block; 112, 113; 112, 150; 112, 151; 112, 176; 112, 177; 113, if_statement; 113, 114; 113, 122; 114, call; 114, 115; 114, 116; 115, identifier:getattr; 116, argument_list; 116, 117; 116, 120; 116, 121; 117, attribute; 117, 118; 117, 119; 118, identifier:element; 119, identifier:form; 120, string:'qualifier_name'; 121, False; 122, block; 122, 123; 122, 140; 122, 141; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:add_parent; 126, call; 126, 127; 126, 134; 127, subscript; 127, 128; 127, 129; 128, identifier:PARENT_FORM; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:element; 132, identifier:form; 133, identifier:qualifier_name; 134, argument_list; 134, 135; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:content; 137, attribute; 137, 138; 137, 139; 138, identifier:element; 139, identifier:qualifier; 140, comment; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:element; 146, identifier:children; 147, identifier:append; 148, argument_list; 148, 149; 149, identifier:add_parent; 150, comment; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:element; 156, identifier:children; 157, identifier:sort; 158, argument_list; 158, 159; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:key; 161, lambda; 161, 162; 161, 164; 162, lambda_parameters; 162, 163; 163, identifier:obj; 164, call; 164, 165; 164, 172; 165, attribute; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:element; 169, identifier:form; 170, identifier:child_sort; 171, identifier:index; 172, argument_list; 172, 173; 173, attribute; 173, 174; 173, 175; 174, identifier:obj; 175, identifier:tag; 176, comment; 177, for_statement; 177, 178; 177, 179; 177, 182; 177, 183; 178, identifier:child; 179, attribute; 179, 180; 179, 181; 180, identifier:element; 181, identifier:children; 182, comment; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:child; 188, identifier:add_form; 189, argument_list; 189, 190; 189, 193; 189, 198; 189, 203; 189, 208; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:vocabularies; 192, identifier:vocabularies; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:qualifier; 195, attribute; 195, 196; 195, 197; 196, identifier:child; 197, identifier:qualifier; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:content; 200, attribute; 200, 201; 200, 202; 201, identifier:child; 202, identifier:content; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:parent_tag; 205, attribute; 205, 206; 205, 207; 206, identifier:element; 207, identifier:tag; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:superuser; 210, identifier:superuser; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:element_group_dict; 214, dictionary; 215, comment; 216, for_statement; 216, 217; 216, 218; 216, 219; 216, 220; 217, identifier:element; 218, identifier:children; 219, comment; 220, block; 220, 221; 221, if_statement; 221, 222; 221, 235; 221, 243; 221, 244; 222, boolean_operator:and; 222, 223; 222, 230; 223, comparison_operator:==; 223, 224; 223, 229; 224, attribute; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:element; 227, identifier:form; 228, identifier:name; 229, string:'meta'; 230, comparison_operator:==; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:element; 233, identifier:qualifier; 234, string:'hidden'; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 241; 238, subscript; 238, 239; 238, 240; 239, identifier:element_group_dict; 240, string:'hidden'; 241, list:[element]; 241, 242; 242, identifier:element; 243, comment; 244, else_clause; 244, 245; 244, 246; 245, comment; 246, block; 246, 247; 246, 266; 247, if_statement; 247, 248; 247, 255; 248, comparison_operator:not; 248, 249; 248, 254; 249, attribute; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:element; 252, identifier:form; 253, identifier:name; 254, identifier:element_group_dict; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 265; 258, subscript; 258, 259; 258, 260; 259, identifier:element_group_dict; 260, attribute; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:element; 263, identifier:form; 264, identifier:name; 265, list:[]; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 277; 268, attribute; 268, 269; 268, 276; 269, subscript; 269, 270; 269, 271; 270, identifier:element_group_dict; 271, attribute; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:element; 274, identifier:form; 275, identifier:name; 276, identifier:append; 277, argument_list; 277, 278; 278, identifier:element; 279, comment; 280, if_statement; 280, 281; 280, 284; 281, comparison_operator:not; 281, 282; 281, 283; 282, string:'hidden'; 283, identifier:element_group_dict; 284, block; 284, 285; 284, 299; 284, 321; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:hidden_element; 288, call; 288, 289; 288, 292; 289, subscript; 289, 290; 289, 291; 290, identifier:PYUNTL_DISPATCH; 291, string:'meta'; 292, argument_list; 292, 293; 292, 296; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:qualifier; 295, string:'hidden'; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:content; 298, string:'False'; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:hidden_element; 303, identifier:add_form; 304, argument_list; 304, 305; 304, 308; 304, 313; 304, 318; 305, keyword_argument; 305, 306; 305, 307; 306, identifier:vocabularies; 307, identifier:vocabularies; 308, keyword_argument; 308, 309; 308, 310; 309, identifier:qualifier; 310, attribute; 310, 311; 310, 312; 311, identifier:hidden_element; 312, identifier:qualifier; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:content; 315, attribute; 315, 316; 315, 317; 316, identifier:hidden_element; 317, identifier:content; 318, keyword_argument; 318, 319; 318, 320; 319, identifier:superuser; 320, identifier:superuser; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 326; 323, subscript; 323, 324; 323, 325; 324, identifier:element_group_dict; 325, string:'hidden'; 326, list:[hidden_element]; 326, 327; 327, identifier:hidden_element; 328, comment; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 332; 331, identifier:element_list; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:self; 335, identifier:create_form_groupings; 336, argument_list; 336, 337; 336, 338; 336, 339; 336, 340; 337, identifier:vocabularies; 338, identifier:solr_response; 339, identifier:element_group_dict; 340, identifier:sort_order; 341, comment; 342, return_statement; 342, 343; 343, identifier:element_list | def create_form_data(self, **kwargs):
"""Create groupings of form elements."""
# Get the specified keyword arguments.
children = kwargs.get('children', [])
sort_order = kwargs.get('sort_order', None)
solr_response = kwargs.get('solr_response', None)
superuser = kwargs.get('superuser', False)
# Get the vocabularies to pull the qualifiers from.
vocabularies = self.get_vocabularies()
# Loop through all UNTL elements in the Python object.
for element in children:
# Add children that are missing from the form.
element.children = add_missing_children(
element.contained_children,
element.children,
)
# Add the form attribute to the element.
element.add_form(
vocabularies=vocabularies,
qualifier=element.qualifier,
content=element.content,
superuser=superuser,
)
# Element can contain children.
if element.form.has_children:
# If the parent has a qualifier,
# create a representative form element for the parent.
if getattr(element.form, 'qualifier_name', False):
add_parent = PARENT_FORM[element.form.qualifier_name](
content=element.qualifier,
)
# Add the parent to the list of child elements.
element.children.append(add_parent)
# Sort the elements by the index of child sort.
element.children.sort(
key=lambda obj: element.form.child_sort.index(obj.tag)
)
# Loop through the element's children (if it has any).
for child in element.children:
# Add the form attribute to the element.
child.add_form(
vocabularies=vocabularies,
qualifier=child.qualifier,
content=child.content,
parent_tag=element.tag,
superuser=superuser,
)
element_group_dict = {}
# Group related objects together.
for element in children:
# Make meta-hidden its own group.
if element.form.name == 'meta' and element.qualifier == 'hidden':
element_group_dict['hidden'] = [element]
# Element is not meta-hidden.
else:
# Make sure the dictionary key exists.
if element.form.name not in element_group_dict:
element_group_dict[element.form.name] = []
element_group_dict[element.form.name].append(element)
# If the hidden meta element doesn't exist, add it to its own group.
if 'hidden' not in element_group_dict:
hidden_element = PYUNTL_DISPATCH['meta'](
qualifier='hidden',
content='False')
hidden_element.add_form(
vocabularies=vocabularies,
qualifier=hidden_element.qualifier,
content=hidden_element.content,
superuser=superuser,
)
element_group_dict['hidden'] = [hidden_element]
# Create a list of group object elements.
element_list = self.create_form_groupings(
vocabularies,
solr_response,
element_group_dict,
sort_order,
)
# Return the list of UNTL elements with form data added.
return element_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_untl; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:sort_structure; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:children; 15, identifier:sort; 16, argument_list; 16, 17; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:key; 19, lambda; 19, 20; 19, 22; 20, lambda_parameters; 20, 21; 21, identifier:obj; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:sort_structure; 25, identifier:index; 26, argument_list; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:obj; 29, identifier:tag | def sort_untl(self, sort_structure):
"""Sort the UNTL Python object by the index
of a sort structure pre-ordered list.
"""
self.children.sort(key=lambda obj: sort_structure.index(obj.tag)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:top; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:sort_by; 6, block; 6, 7; 6, 9; 6, 21; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:sort; 12, call; 12, 13; 12, 14; 13, identifier:sorted; 14, argument_list; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:results; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:key; 20, identifier:sort_by; 21, return_statement; 21, 22; 22, identifier:sort | def top(self, sort_by):
"""Get the best results according to your custom sort method."""
sort = sorted(self.results, key=sort_by)
return sort |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:portTryReduce; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:root; 6, type; 6, 7; 7, identifier:LNode; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:port; 10, type; 10, 11; 11, identifier:LPort; 12, block; 12, 13; 12, 15; 12, 22; 12, 34; 12, 38; 12, 46; 12, 52; 12, 76; 12, 83; 12, 100; 12, 106; 12, 112; 12, 299; 12, 300; 12, 316; 12, 332; 12, 333; 12, 334; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 20; 16, not_operator; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:port; 19, identifier:children; 20, block; 20, 21; 21, return_statement; 22, for_statement; 22, 23; 22, 24; 22, 27; 23, identifier:p; 24, attribute; 24, 25; 24, 26; 25, identifier:port; 26, identifier:children; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:portTryReduce; 31, argument_list; 31, 32; 31, 33; 32, identifier:root; 33, identifier:p; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:target_nodes; 37, dictionary; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:ch_cnt; 41, call; 41, 42; 41, 43; 42, identifier:countDirectlyConnected; 43, argument_list; 43, 44; 43, 45; 44, identifier:port; 45, identifier:target_nodes; 46, if_statement; 46, 47; 46, 49; 46, 50; 47, not_operator; 47, 48; 48, identifier:target_nodes; 49, comment; 50, block; 50, 51; 51, return_statement; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, pattern_list; 54, 55; 54, 56; 55, identifier:new_target; 56, identifier:children_edge_to_destroy; 57, call; 57, 58; 57, 59; 58, identifier:max; 59, argument_list; 59, 60; 59, 65; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:target_nodes; 63, identifier:items; 64, argument_list; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:key; 67, lambda; 67, 68; 67, 70; 68, lambda_parameters; 68, 69; 69, identifier:x; 70, call; 70, 71; 70, 72; 71, identifier:len; 72, argument_list; 72, 73; 73, subscript; 73, 74; 73, 75; 74, identifier:x; 75, integer:1; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:cnt; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, identifier:children_edge_to_destroy; 83, if_statement; 83, 84; 83, 97; 83, 98; 84, boolean_operator:or; 84, 85; 84, 90; 85, comparison_operator:<; 85, 86; 85, 87; 86, identifier:cnt; 87, binary_operator:/; 87, 88; 87, 89; 88, identifier:ch_cnt; 89, integer:2; 90, boolean_operator:and; 90, 91; 90, 94; 91, comparison_operator:==; 91, 92; 91, 93; 92, identifier:cnt; 93, integer:1; 94, comparison_operator:==; 94, 95; 94, 96; 95, identifier:ch_cnt; 96, integer:2; 97, comment; 98, block; 98, 99; 99, return_statement; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:children_to_destroy; 103, call; 103, 104; 103, 105; 104, identifier:set; 105, argument_list; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:on_target_children_to_destroy; 109, call; 109, 110; 109, 111; 110, identifier:set; 111, argument_list; 112, for_statement; 112, 113; 112, 116; 112, 117; 113, pattern_list; 113, 114; 113, 115; 114, identifier:child; 115, identifier:edge; 116, identifier:children_edge_to_destroy; 117, block; 117, 118; 117, 157; 117, 171; 117, 177; 117, 213; 117, 245; 117, 262; 117, 281; 118, if_statement; 118, 119; 118, 126; 118, 133; 118, 148; 119, comparison_operator:==; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:child; 122, identifier:direction; 123, attribute; 123, 124; 123, 125; 124, identifier:PortType; 125, identifier:OUTPUT; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:target_ch; 130, attribute; 130, 131; 130, 132; 131, identifier:edge; 132, identifier:dsts; 133, elif_clause; 133, 134; 133, 141; 134, comparison_operator:==; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:child; 137, identifier:direction; 138, attribute; 138, 139; 138, 140; 139, identifier:PortType; 140, identifier:INPUT; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:target_ch; 145, attribute; 145, 146; 145, 147; 146, identifier:edge; 147, identifier:srcs; 148, else_clause; 148, 149; 149, block; 149, 150; 150, raise_statement; 150, 151; 151, call; 151, 152; 151, 153; 152, identifier:ValueError; 153, argument_list; 153, 154; 154, attribute; 154, 155; 154, 156; 155, identifier:child; 156, identifier:direction; 157, if_statement; 157, 158; 157, 164; 158, comparison_operator:!=; 158, 159; 158, 163; 159, call; 159, 160; 159, 161; 160, identifier:len; 161, argument_list; 161, 162; 162, identifier:target_ch; 163, integer:1; 164, block; 164, 165; 165, raise_statement; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:NotImplementedError; 168, argument_list; 168, 169; 168, 170; 169, string:"multiple connected nodes"; 170, identifier:target_ch; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:target_ch; 174, subscript; 174, 175; 174, 176; 175, identifier:target_ch; 176, integer:0; 177, try_statement; 177, 178; 177, 191; 178, block; 178, 179; 179, assert_statement; 179, 180; 179, 185; 180, comparison_operator:is; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:target_ch; 183, identifier:parent; 184, identifier:new_target; 185, tuple; 185, 186; 185, 187; 185, 190; 186, identifier:target_ch; 187, attribute; 187, 188; 187, 189; 188, identifier:target_ch; 189, identifier:parent; 190, identifier:new_target; 191, except_clause; 191, 192; 191, 193; 192, identifier:AssertionError; 193, block; 193, 194; 193, 212; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:print; 197, argument_list; 197, 198; 197, 199; 197, 202; 197, 203; 197, 206; 197, 207; 197, 210; 197, 211; 198, string:'Wrong target:\n'; 199, attribute; 199, 200; 199, 201; 200, identifier:edge; 201, identifier:src; 202, string:"\n"; 203, attribute; 203, 204; 203, 205; 204, identifier:edge; 205, identifier:dst; 206, string:"\n"; 207, attribute; 207, 208; 207, 209; 208, identifier:target_ch; 209, identifier:parent; 210, string:"\n"; 211, identifier:new_target; 212, raise_statement; 213, if_statement; 213, 214; 213, 221; 213, 229; 214, comparison_operator:==; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:child; 217, identifier:direction; 218, attribute; 218, 219; 218, 220; 219, identifier:PortType; 220, identifier:OUTPUT; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:edge; 226, identifier:removeTarget; 227, argument_list; 227, 228; 228, identifier:target_ch; 229, elif_clause; 229, 230; 229, 237; 230, comparison_operator:==; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:child; 233, identifier:direction; 234, attribute; 234, 235; 234, 236; 235, identifier:PortType; 236, identifier:INPUT; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:edge; 242, identifier:removeTarget; 243, argument_list; 243, 244; 244, identifier:child; 245, if_statement; 245, 246; 245, 255; 246, boolean_operator:or; 246, 247; 246, 251; 247, not_operator; 247, 248; 248, attribute; 248, 249; 248, 250; 249, identifier:edge; 250, identifier:srcs; 251, not_operator; 251, 252; 252, attribute; 252, 253; 252, 254; 253, identifier:edge; 254, identifier:dsts; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:edge; 260, identifier:remove; 261, argument_list; 262, if_statement; 262, 263; 262, 272; 262, 273; 263, boolean_operator:and; 263, 264; 263, 268; 264, not_operator; 264, 265; 265, attribute; 265, 266; 265, 267; 266, identifier:target_ch; 267, identifier:incomingEdges; 268, not_operator; 268, 269; 269, attribute; 269, 270; 269, 271; 270, identifier:target_ch; 271, identifier:outgoingEdges; 272, comment; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:on_target_children_to_destroy; 278, identifier:add; 279, argument_list; 279, 280; 280, identifier:target_ch; 281, if_statement; 281, 282; 281, 291; 282, boolean_operator:and; 282, 283; 282, 287; 283, not_operator; 283, 284; 284, attribute; 284, 285; 284, 286; 285, identifier:child; 286, identifier:incomingEdges; 287, not_operator; 287, 288; 288, attribute; 288, 289; 288, 290; 289, identifier:child; 290, identifier:outgoingEdges; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:children_to_destroy; 296, identifier:add; 297, argument_list; 297, 298; 298, identifier:child; 299, comment; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:port; 304, identifier:children; 305, list_comprehension; 305, 306; 305, 307; 305, 312; 306, identifier:ch; 307, for_in_clause; 307, 308; 307, 309; 308, identifier:ch; 309, attribute; 309, 310; 309, 311; 310, identifier:port; 311, identifier:children; 312, if_clause; 312, 313; 313, comparison_operator:not; 313, 314; 313, 315; 314, identifier:ch; 315, identifier:children_to_destroy; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:new_target; 320, identifier:children; 321, list_comprehension; 321, 322; 321, 323; 321, 328; 322, identifier:ch; 323, for_in_clause; 323, 324; 323, 325; 324, identifier:ch; 325, attribute; 325, 326; 325, 327; 326, identifier:new_target; 327, identifier:children; 328, if_clause; 328, 329; 329, comparison_operator:not; 329, 330; 329, 331; 330, identifier:ch; 331, identifier:on_target_children_to_destroy; 332, comment; 333, comment; 334, if_statement; 334, 335; 334, 342; 334, 351; 334, 368; 335, comparison_operator:==; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:port; 338, identifier:direction; 339, attribute; 339, 340; 339, 341; 340, identifier:PortType; 341, identifier:OUTPUT; 342, block; 342, 343; 343, expression_statement; 343, 344; 344, call; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:root; 347, identifier:addEdge; 348, argument_list; 348, 349; 348, 350; 349, identifier:port; 350, identifier:new_target; 351, elif_clause; 351, 352; 351, 359; 352, comparison_operator:==; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:port; 355, identifier:direction; 356, attribute; 356, 357; 356, 358; 357, identifier:PortType; 358, identifier:INPUT; 359, block; 359, 360; 360, expression_statement; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:root; 364, identifier:addEdge; 365, argument_list; 365, 366; 365, 367; 366, identifier:new_target; 367, identifier:port; 368, else_clause; 368, 369; 369, block; 369, 370; 370, raise_statement; 370, 371; 371, call; 371, 372; 371, 373; 372, identifier:NotImplementedError; 373, argument_list; 373, 374; 374, attribute; 374, 375; 374, 376; 375, identifier:port; 376, identifier:direction | def portTryReduce(root: LNode, port: LPort):
"""
Check if majority of children is connected to same port
if it is the case reduce children and connect this port instead children
:note: use reduceUselessAssignments, extractSplits, flattenTrees before this function
to maximize it's effect
"""
if not port.children:
return
for p in port.children:
portTryReduce(root, p)
target_nodes = {}
ch_cnt = countDirectlyConnected(port, target_nodes)
if not target_nodes:
# disconnected port
return
new_target, children_edge_to_destroy = max(target_nodes.items(),
key=lambda x: len(x[1]))
cnt = len(children_edge_to_destroy)
if cnt < ch_cnt / 2 or cnt == 1 and ch_cnt == 2:
# too small to few shared connection to reduce
return
children_to_destroy = set()
on_target_children_to_destroy = set()
for child, edge in children_edge_to_destroy:
if child.direction == PortType.OUTPUT:
target_ch = edge.dsts
elif child.direction == PortType.INPUT:
target_ch = edge.srcs
else:
raise ValueError(child.direction)
if len(target_ch) != 1:
raise NotImplementedError("multiple connected nodes", target_ch)
target_ch = target_ch[0]
try:
assert target_ch.parent is new_target, (
target_ch,
target_ch.parent,
new_target)
except AssertionError:
print('Wrong target:\n', edge.src, "\n", edge.dst,
"\n", target_ch.parent, "\n", new_target)
raise
if child.direction == PortType.OUTPUT:
edge.removeTarget(target_ch)
elif child.direction == PortType.INPUT:
edge.removeTarget(child)
if not edge.srcs or not edge.dsts:
edge.remove()
if not target_ch.incomingEdges and not target_ch.outgoingEdges:
# disconnect selected children from this port and target
on_target_children_to_destroy.add(target_ch)
if not child.incomingEdges and not child.outgoingEdges:
children_to_destroy.add(child)
# destroy children of new target and this port if possible
port.children = [
ch for ch in port.children if ch not in children_to_destroy]
new_target.children = [
ch for ch in new_target.children if ch not in on_target_children_to_destroy]
# connect this port to new target as it was connected by children before
# [TODO] names for new edges
if port.direction == PortType.OUTPUT:
root.addEdge(port, new_target)
elif port.direction == PortType.INPUT:
root.addEdge(new_target, port)
else:
raise NotImplementedError(port.direction) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 14; 2, function_name:countDirectlyConnected; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:port; 6, type; 6, 7; 7, identifier:LPort; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:result; 10, type; 10, 11; 11, identifier:dict; 12, type; 12, 13; 13, identifier:int; 14, block; 14, 15; 14, 17; 14, 23; 14, 29; 15, expression_statement; 15, 16; 16, comment; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:inEdges; 20, attribute; 20, 21; 20, 22; 21, identifier:port; 22, identifier:incomingEdges; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:outEdges; 26, attribute; 26, 27; 26, 28; 27, identifier:port; 28, identifier:outgoingEdges; 29, if_statement; 29, 30; 29, 33; 29, 59; 29, 106; 30, attribute; 30, 31; 30, 32; 31, identifier:port; 32, identifier:children; 33, block; 33, 34; 33, 38; 33, 39; 33, 40; 33, 41; 33, 42; 33, 43; 33, 57; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:ch_cnt; 37, integer:0; 38, comment; 39, comment; 40, comment; 41, comment; 42, comment; 43, for_statement; 43, 44; 43, 45; 43, 48; 44, identifier:ch; 45, attribute; 45, 46; 45, 47; 46, identifier:port; 47, identifier:children; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, augmented_assignment:+=; 50, 51; 50, 52; 51, identifier:ch_cnt; 52, call; 52, 53; 52, 54; 53, identifier:countDirectlyConnected; 54, argument_list; 54, 55; 54, 56; 55, identifier:ch; 56, identifier:result; 57, return_statement; 57, 58; 58, identifier:ch_cnt; 59, elif_clause; 59, 60; 59, 65; 59, 66; 60, boolean_operator:and; 60, 61; 60, 63; 61, not_operator; 61, 62; 62, identifier:inEdges; 63, not_operator; 63, 64; 64, identifier:outEdges; 65, comment; 66, block; 66, 67; 66, 104; 67, if_statement; 67, 68; 67, 75; 68, comparison_operator:==; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:port; 71, identifier:direction; 72, attribute; 72, 73; 72, 74; 73, identifier:PortType; 74, identifier:INPUT; 75, block; 75, 76; 76, if_statement; 76, 77; 76, 82; 76, 95; 77, comparison_operator:is; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:port; 80, identifier:originObj; 81, None; 82, block; 82, 83; 83, assert_statement; 83, 84; 83, 92; 84, not_operator; 84, 85; 85, attribute; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:port; 89, identifier:originObj; 90, identifier:src; 91, identifier:drivers; 92, attribute; 92, 93; 92, 94; 93, identifier:port; 94, identifier:originObj; 95, else_clause; 95, 96; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:print; 100, argument_list; 100, 101; 100, 102; 100, 103; 101, string:"Warning"; 102, identifier:port; 103, string:"not connected"; 104, return_statement; 104, 105; 105, integer:0; 106, else_clause; 106, 107; 107, block; 107, 108; 107, 112; 107, 132; 107, 152; 107, 159; 107, 176; 107, 177; 107, 196; 107, 229; 107, 230; 107, 263; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:connectedElemCnt; 111, integer:0; 112, for_statement; 112, 113; 112, 114; 112, 115; 113, identifier:e; 114, identifier:inEdges; 115, block; 115, 116; 115, 125; 116, expression_statement; 116, 117; 117, augmented_assignment:+=; 117, 118; 117, 119; 118, identifier:connectedElemCnt; 119, call; 119, 120; 119, 121; 120, identifier:len; 121, argument_list; 121, 122; 122, attribute; 122, 123; 122, 124; 123, identifier:e; 124, identifier:srcs; 125, if_statement; 125, 126; 125, 129; 126, comparison_operator:>; 126, 127; 126, 128; 127, identifier:connectedElemCnt; 128, integer:1; 129, block; 129, 130; 130, return_statement; 130, 131; 131, integer:0; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:e; 134, identifier:outEdges; 135, block; 135, 136; 135, 145; 136, expression_statement; 136, 137; 137, augmented_assignment:+=; 137, 138; 137, 139; 138, identifier:connectedElemCnt; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, attribute; 142, 143; 142, 144; 143, identifier:e; 144, identifier:dsts; 145, if_statement; 145, 146; 145, 149; 146, comparison_operator:>; 146, 147; 146, 148; 147, identifier:connectedElemCnt; 148, integer:1; 149, block; 149, 150; 150, return_statement; 150, 151; 151, integer:0; 152, if_statement; 152, 153; 152, 156; 153, comparison_operator:!=; 153, 154; 153, 155; 154, identifier:connectedElemCnt; 155, integer:1; 156, block; 156, 157; 157, return_statement; 157, 158; 158, integer:0; 159, if_statement; 159, 160; 159, 161; 159, 168; 160, identifier:inEdges; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:e; 165, subscript; 165, 166; 165, 167; 166, identifier:inEdges; 167, integer:0; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:e; 173, subscript; 173, 174; 173, 175; 174, identifier:outEdges; 175, integer:0; 176, comment; 177, if_statement; 177, 178; 177, 193; 178, comparison_operator:!=; 178, 179; 178, 186; 179, attribute; 179, 180; 179, 185; 180, subscript; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:e; 183, identifier:srcs; 184, integer:0; 185, identifier:name; 186, attribute; 186, 187; 186, 192; 187, subscript; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:e; 190, identifier:dsts; 191, integer:0; 192, identifier:name; 193, block; 193, 194; 194, return_statement; 194, 195; 195, integer:0; 196, if_statement; 196, 197; 196, 204; 196, 215; 197, comparison_operator:is; 197, 198; 197, 203; 198, subscript; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:e; 201, identifier:srcs; 202, integer:0; 203, identifier:port; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:p; 208, attribute; 208, 209; 208, 214; 209, subscript; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:e; 212, identifier:dsts; 213, integer:0; 214, identifier:parent; 215, else_clause; 215, 216; 215, 217; 215, 218; 216, comment; 217, comment; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:p; 222, attribute; 222, 223; 222, 228; 223, subscript; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:e; 226, identifier:srcs; 227, integer:0; 228, identifier:parent; 229, comment; 230, if_statement; 230, 231; 230, 237; 231, not_operator; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:isinstance; 234, argument_list; 234, 235; 234, 236; 235, identifier:p; 236, identifier:LNode; 237, block; 237, 238; 237, 248; 237, 257; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:connections; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:result; 244, identifier:get; 245, argument_list; 245, 246; 245, 247; 246, identifier:p; 247, list:[]; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:connections; 252, identifier:append; 253, argument_list; 253, 254; 254, tuple; 254, 255; 254, 256; 255, identifier:port; 256, identifier:e; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 262; 259, subscript; 259, 260; 259, 261; 260, identifier:result; 261, identifier:p; 262, identifier:connections; 263, return_statement; 263, 264; 264, integer:1 | def countDirectlyConnected(port: LPort, result: dict) -> int:
"""
Count how many ports are directly connected to other nodes
:return: cumulative sum of port counts
"""
inEdges = port.incomingEdges
outEdges = port.outgoingEdges
if port.children:
ch_cnt = 0
# try:
# assert not inEdges, (port, port.children, inEdges)
# assert not outEdges, (port, port.children, outEdges)
# except AssertionError:
# raise
for ch in port.children:
ch_cnt += countDirectlyConnected(ch, result)
return ch_cnt
elif not inEdges and not outEdges:
# this port is not connected, just check if it expected state
if port.direction == PortType.INPUT:
if port.originObj is not None:
assert not port.originObj.src.drivers, port.originObj
else:
print("Warning", port, "not connected")
return 0
else:
connectedElemCnt = 0
for e in inEdges:
connectedElemCnt += len(e.srcs)
if connectedElemCnt > 1:
return 0
for e in outEdges:
connectedElemCnt += len(e.dsts)
if connectedElemCnt > 1:
return 0
if connectedElemCnt != 1:
return 0
if inEdges:
e = inEdges[0]
else:
e = outEdges[0]
# if is connected to different port
if e.srcs[0].name != e.dsts[0].name:
return 0
if e.srcs[0] is port:
p = e.dsts[0].parent
else:
# (can be hyperedge and then this does not have to be)
# assert e.dsts[0] is port, (e, port)
p = e.srcs[0].parent
# if is part of interface which can be reduced
if not isinstance(p, LNode):
connections = result.get(p, [])
connections.append((port, e))
result[p] = connections
return 1 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:untlxml2py; 3, parameters; 3, 4; 4, identifier:untl_filename; 5, block; 5, 6; 5, 8; 5, 9; 5, 13; 5, 14; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:parent_stack; 12, list:[]; 13, comment; 14, for_statement; 14, 15; 14, 18; 14, 27; 15, pattern_list; 15, 16; 15, 17; 16, identifier:event; 17, identifier:element; 18, call; 18, 19; 18, 20; 19, identifier:iterparse; 20, argument_list; 20, 21; 20, 22; 21, identifier:untl_filename; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:events; 24, tuple; 24, 25; 24, 26; 25, string:'start'; 26, string:'end'; 27, block; 27, 28; 27, 64; 27, 65; 28, if_statement; 28, 29; 28, 38; 28, 56; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:NAMESPACE_REGEX; 32, identifier:search; 33, argument_list; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:element; 36, identifier:tag; 37, integer:0; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:element_tag; 42, call; 42, 43; 42, 54; 43, attribute; 43, 44; 43, 53; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:NAMESPACE_REGEX; 47, identifier:search; 48, argument_list; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:element; 51, identifier:tag; 52, integer:0; 53, identifier:group; 54, argument_list; 54, 55; 55, integer:1; 56, else_clause; 56, 57; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:element_tag; 61, attribute; 61, 62; 61, 63; 62, identifier:element; 63, identifier:tag; 64, comment; 65, if_statement; 65, 66; 65, 69; 65, 70; 65, 71; 65, 180; 66, comparison_operator:in; 66, 67; 66, 68; 67, identifier:element_tag; 68, identifier:PYUNTL_DISPATCH; 69, comment; 70, comment; 71, block; 71, 72; 72, if_statement; 72, 73; 72, 76; 72, 88; 72, 89; 72, 90; 73, comparison_operator:==; 73, 74; 73, 75; 74, identifier:event; 75, string:'start'; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:parent_stack; 81, identifier:append; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:PYUNTL_DISPATCH; 86, identifier:element_tag; 87, argument_list; 88, comment; 89, comment; 90, elif_clause; 90, 91; 90, 94; 91, comparison_operator:==; 91, 92; 91, 93; 92, identifier:event; 93, string:'end'; 94, block; 94, 95; 94, 103; 94, 134; 94, 155; 94, 156; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:child; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:parent_stack; 101, identifier:pop; 102, argument_list; 103, if_statement; 103, 104; 103, 109; 104, comparison_operator:is; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:element; 107, identifier:text; 108, None; 109, block; 109, 110; 109, 120; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:content; 113, call; 113, 114; 113, 119; 114, attribute; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:element; 117, identifier:text; 118, identifier:strip; 119, argument_list; 120, if_statement; 120, 121; 120, 124; 121, comparison_operator:!=; 121, 122; 121, 123; 122, identifier:content; 123, string:''; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:child; 129, identifier:set_content; 130, argument_list; 130, 131; 131, attribute; 131, 132; 131, 133; 132, identifier:element; 133, identifier:text; 134, if_statement; 134, 135; 134, 142; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:element; 138, identifier:get; 139, argument_list; 139, 140; 139, 141; 140, string:'qualifier'; 141, False; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:child; 147, identifier:set_qualifier; 148, argument_list; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:element; 152, identifier:get; 153, argument_list; 153, 154; 154, string:'qualifier'; 155, comment; 156, if_statement; 156, 157; 156, 163; 156, 174; 156, 175; 156, 176; 157, comparison_operator:>; 157, 158; 157, 162; 158, call; 158, 159; 158, 160; 159, identifier:len; 160, argument_list; 160, 161; 161, identifier:parent_stack; 162, integer:0; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 172; 166, attribute; 166, 167; 166, 171; 167, subscript; 167, 168; 167, 169; 168, identifier:parent_stack; 169, unary_operator:-; 169, 170; 170, integer:1; 171, identifier:add_child; 172, argument_list; 172, 173; 173, identifier:child; 174, comment; 175, comment; 176, else_clause; 176, 177; 177, block; 177, 178; 178, return_statement; 178, 179; 179, identifier:child; 180, else_clause; 180, 181; 181, block; 181, 182; 182, raise_statement; 182, 183; 183, call; 183, 184; 183, 185; 184, identifier:PyuntlException; 185, argument_list; 185, 186; 186, binary_operator:%; 186, 187; 186, 188; 187, string:'Element "%s" not in UNTL dispatch.'; 188, parenthesized_expression; 188, 189; 189, identifier:element_tag | def untlxml2py(untl_filename):
"""Parse a UNTL XML file object into a pyuntl element tree.
You can also pass this a string as file input like so:
import StringIO
untlxml2py(StringIO.StringIO(untl_string))
"""
# Create a stack to hold parents.
parent_stack = []
# Use iterparse to open the file and loop through elements.
for event, element in iterparse(untl_filename, events=('start', 'end')):
if NAMESPACE_REGEX.search(element.tag, 0):
element_tag = NAMESPACE_REGEX.search(element.tag, 0).group(1)
else:
element_tag = element.tag
# Process the element if it exists in UNTL.
if element_tag in PYUNTL_DISPATCH:
# If it is the element's opening tag,
# add it to the parent stack.
if event == 'start':
parent_stack.append(PYUNTL_DISPATCH[element_tag]())
# If it is the element's closing tag,
# remove element from stack. Add qualifier and content.
elif event == 'end':
child = parent_stack.pop()
if element.text is not None:
content = element.text.strip()
if content != '':
child.set_content(element.text)
if element.get('qualifier', False):
child.set_qualifier(element.get('qualifier'))
# Add the element to its parent.
if len(parent_stack) > 0:
parent_stack[-1].add_child(child)
# If it doesn't have a parent, it is the root element,
# so return it.
else:
return child
else:
raise PyuntlException(
'Element "%s" not in UNTL dispatch.' % (element_tag)
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:post2pydict; 3, parameters; 3, 4; 3, 5; 4, identifier:post; 5, identifier:ignore_list; 6, block; 6, 7; 6, 9; 6, 17; 6, 21; 6, 22; 6, 23; 6, 34; 6, 35; 6, 85; 6, 401; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:root_element; 12, call; 12, 13; 12, 16; 13, subscript; 13, 14; 13, 15; 14, identifier:PYUNTL_DISPATCH; 15, string:'metadata'; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:untl_form_dict; 20, dictionary; 21, comment; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:form_post; 26, call; 26, 27; 26, 28; 27, identifier:dict; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:post; 32, identifier:copy; 33, argument_list; 34, comment; 35, for_statement; 35, 36; 35, 39; 35, 44; 36, pattern_list; 36, 37; 36, 38; 37, identifier:key; 38, identifier:value_list; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:form_post; 42, identifier:items; 43, argument_list; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 49; 45, 50; 45, 51; 46, comparison_operator:not; 46, 47; 46, 48; 47, identifier:key; 48, identifier:ignore_list; 49, comment; 50, comment; 51, block; 51, 52; 51, 64; 51, 75; 51, 76; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, tuple_pattern; 54, 55; 54, 56; 55, identifier:element_tag; 56, identifier:element_attribute; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:key; 60, identifier:split; 61, argument_list; 61, 62; 61, 63; 62, string:'-'; 63, integer:1; 64, if_statement; 64, 65; 64, 68; 65, comparison_operator:not; 65, 66; 65, 67; 66, identifier:element_tag; 67, identifier:untl_form_dict; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:untl_form_dict; 73, identifier:element_tag; 74, tuple; 75, comment; 76, expression_statement; 76, 77; 77, augmented_assignment:+=; 77, 78; 77, 81; 78, subscript; 78, 79; 78, 80; 79, identifier:untl_form_dict; 80, identifier:element_tag; 81, expression_list; 81, 82; 82, tuple; 82, 83; 82, 84; 83, identifier:element_attribute; 84, identifier:value_list; 85, for_statement; 85, 86; 85, 89; 85, 94; 85, 95; 86, pattern_list; 86, 87; 86, 88; 87, identifier:element_tag; 88, identifier:attribute_tuple; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:untl_form_dict; 92, identifier:items; 93, argument_list; 94, comment; 95, block; 95, 96; 95, 103; 95, 104; 95, 115; 95, 116; 95, 147; 95, 148; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:attribute_count; 99, call; 99, 100; 99, 101; 100, identifier:len; 101, argument_list; 101, 102; 102, identifier:attribute_tuple; 103, comment; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:value_count; 107, call; 107, 108; 107, 109; 108, identifier:len; 109, argument_list; 109, 110; 110, subscript; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:attribute_tuple; 113, integer:0; 114, integer:1; 115, comment; 116, for_statement; 116, 117; 116, 118; 116, 123; 117, identifier:i; 118, call; 118, 119; 118, 120; 119, identifier:range; 120, argument_list; 120, 121; 120, 122; 121, integer:0; 122, identifier:attribute_count; 123, block; 123, 124; 124, if_statement; 124, 125; 124, 136; 125, not_operator; 125, 126; 126, comparison_operator:==; 126, 127; 126, 135; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, subscript; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:attribute_tuple; 133, identifier:i; 134, integer:1; 135, identifier:value_count; 136, block; 136, 137; 137, raise_statement; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:PyuntlException; 140, argument_list; 140, 141; 141, binary_operator:%; 141, 142; 141, 145; 142, concatenated_string; 142, 143; 142, 144; 143, string:'Field values did not match up '; 144, string:'numerically for %s'; 145, parenthesized_expression; 145, 146; 146, identifier:element_tag; 147, comment; 148, for_statement; 148, 149; 148, 150; 148, 155; 149, identifier:i; 150, call; 150, 151; 150, 152; 151, identifier:range; 152, argument_list; 152, 153; 152, 154; 153, integer:0; 154, identifier:value_count; 155, block; 155, 156; 155, 160; 155, 164; 155, 168; 155, 172; 155, 173; 155, 174; 155, 175; 155, 176; 155, 291; 155, 292; 155, 364; 155, 365; 155, 388; 155, 389; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:untl_element; 159, None; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:content; 163, string:''; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:qualifier; 167, string:''; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:child_list; 171, list:[]; 172, comment; 173, comment; 174, comment; 175, comment; 176, for_statement; 176, 177; 176, 178; 176, 183; 177, identifier:j; 178, call; 178, 179; 178, 180; 179, identifier:range; 180, argument_list; 180, 181; 180, 182; 181, integer:0; 182, identifier:attribute_count; 183, block; 183, 184; 184, if_statement; 184, 185; 184, 192; 184, 206; 184, 225; 184, 226; 185, comparison_operator:==; 185, 186; 185, 191; 186, subscript; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:attribute_tuple; 189, identifier:j; 190, integer:0; 191, string:'content'; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:content; 196, call; 196, 197; 196, 198; 197, identifier:unicode; 198, argument_list; 198, 199; 199, subscript; 199, 200; 199, 205; 200, subscript; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:attribute_tuple; 203, identifier:j; 204, integer:1; 205, identifier:i; 206, elif_clause; 206, 207; 206, 214; 207, comparison_operator:==; 207, 208; 207, 213; 208, subscript; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:attribute_tuple; 211, identifier:j; 212, integer:0; 213, string:'qualifier'; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:qualifier; 218, subscript; 218, 219; 218, 224; 219, subscript; 219, 220; 219, 223; 220, subscript; 220, 221; 220, 222; 221, identifier:attribute_tuple; 222, identifier:j; 223, integer:1; 224, identifier:i; 225, comment; 226, else_clause; 226, 227; 226, 228; 227, comment; 228, block; 228, 229; 229, if_statement; 229, 230; 229, 239; 230, comparison_operator:!=; 230, 231; 230, 238; 231, subscript; 231, 232; 231, 237; 232, subscript; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:attribute_tuple; 235, identifier:j; 236, integer:1; 237, identifier:i; 238, string:''; 239, block; 239, 240; 239, 248; 239, 249; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:child_tag; 243, subscript; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:attribute_tuple; 246, identifier:j; 247, integer:0; 248, comment; 249, if_statement; 249, 250; 249, 253; 249, 264; 249, 265; 250, comparison_operator:in; 250, 251; 250, 252; 251, identifier:child_tag; 252, identifier:PARENT_FORM; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:qualifier; 257, subscript; 257, 258; 257, 263; 258, subscript; 258, 259; 258, 262; 259, subscript; 259, 260; 259, 261; 260, identifier:attribute_tuple; 261, identifier:j; 262, integer:1; 263, identifier:i; 264, comment; 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:child_list; 271, identifier:append; 272, argument_list; 272, 273; 273, call; 273, 274; 273, 281; 274, subscript; 274, 275; 274, 276; 275, identifier:PYUNTL_DISPATCH; 276, subscript; 276, 277; 276, 280; 277, subscript; 277, 278; 277, 279; 278, identifier:attribute_tuple; 279, identifier:j; 280, integer:0; 281, argument_list; 281, 282; 282, keyword_argument; 282, 283; 282, 284; 283, identifier:content; 284, subscript; 284, 285; 284, 290; 285, subscript; 285, 286; 285, 289; 286, subscript; 286, 287; 286, 288; 287, identifier:attribute_tuple; 288, identifier:j; 289, integer:1; 290, identifier:i; 291, comment; 292, if_statement; 292, 293; 292, 300; 292, 315; 292, 331; 292, 347; 292, 348; 293, boolean_operator:and; 293, 294; 293, 297; 294, comparison_operator:!=; 294, 295; 294, 296; 295, identifier:content; 296, string:''; 297, comparison_operator:!=; 297, 298; 297, 299; 298, identifier:qualifier; 299, string:''; 300, block; 300, 301; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:untl_element; 304, call; 304, 305; 304, 308; 305, subscript; 305, 306; 305, 307; 306, identifier:PYUNTL_DISPATCH; 307, identifier:element_tag; 308, argument_list; 308, 309; 308, 312; 309, keyword_argument; 309, 310; 309, 311; 310, identifier:content; 311, identifier:content; 312, keyword_argument; 312, 313; 312, 314; 313, identifier:qualifier; 314, identifier:qualifier; 315, elif_clause; 315, 316; 315, 319; 316, comparison_operator:!=; 316, 317; 316, 318; 317, identifier:content; 318, string:''; 319, block; 319, 320; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:untl_element; 323, call; 323, 324; 323, 327; 324, subscript; 324, 325; 324, 326; 325, identifier:PYUNTL_DISPATCH; 326, identifier:element_tag; 327, argument_list; 327, 328; 328, keyword_argument; 328, 329; 328, 330; 329, identifier:content; 330, identifier:content; 331, elif_clause; 331, 332; 331, 335; 332, comparison_operator:!=; 332, 333; 332, 334; 333, identifier:qualifier; 334, string:''; 335, block; 335, 336; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:untl_element; 339, call; 339, 340; 339, 343; 340, subscript; 340, 341; 340, 342; 341, identifier:PYUNTL_DISPATCH; 342, identifier:element_tag; 343, argument_list; 343, 344; 344, keyword_argument; 344, 345; 344, 346; 345, identifier:qualifier; 346, identifier:qualifier; 347, comment; 348, elif_clause; 348, 349; 348, 355; 349, comparison_operator:>; 349, 350; 349, 354; 350, call; 350, 351; 350, 352; 351, identifier:len; 352, argument_list; 352, 353; 353, identifier:child_list; 354, integer:0; 355, block; 355, 356; 356, expression_statement; 356, 357; 357, assignment; 357, 358; 357, 359; 358, identifier:untl_element; 359, call; 359, 360; 359, 363; 360, subscript; 360, 361; 360, 362; 361, identifier:PYUNTL_DISPATCH; 362, identifier:element_tag; 363, argument_list; 364, comment; 365, if_statement; 365, 366; 365, 376; 366, boolean_operator:and; 366, 367; 366, 373; 367, comparison_operator:>; 367, 368; 367, 372; 368, call; 368, 369; 368, 370; 369, identifier:len; 370, argument_list; 370, 371; 371, identifier:child_list; 372, integer:0; 373, comparison_operator:is; 373, 374; 373, 375; 374, identifier:untl_element; 375, None; 376, block; 376, 377; 377, for_statement; 377, 378; 377, 379; 377, 380; 378, identifier:child; 379, identifier:child_list; 380, block; 380, 381; 381, expression_statement; 381, 382; 382, call; 382, 383; 382, 386; 383, attribute; 383, 384; 383, 385; 384, identifier:untl_element; 385, identifier:add_child; 386, argument_list; 386, 387; 387, identifier:child; 388, comment; 389, if_statement; 389, 390; 389, 393; 390, comparison_operator:is; 390, 391; 390, 392; 391, identifier:untl_element; 392, None; 393, block; 393, 394; 394, expression_statement; 394, 395; 395, call; 395, 396; 395, 399; 396, attribute; 396, 397; 396, 398; 397, identifier:root_element; 398, identifier:add_child; 399, argument_list; 399, 400; 400, identifier:untl_element; 401, return_statement; 401, 402; 402, call; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, identifier:root_element; 405, identifier:create_element_dict; 406, argument_list | def post2pydict(post, ignore_list):
"""Convert the UNTL posted data to a Python dictionary."""
root_element = PYUNTL_DISPATCH['metadata']()
untl_form_dict = {}
# Turn the posted data into usable data
# (otherwise the value lists get messed up).
form_post = dict(post.copy())
# Loop through all the field lists.
for key, value_list in form_post.items():
if key not in ignore_list:
# Split the key into the element_tag (ex. title)
# and element attribute (ex. qualifier, content).
(element_tag, element_attribute) = key.split('-', 1)
if element_tag not in untl_form_dict:
untl_form_dict[element_tag] = ()
# Add the value list to the dictionary.
untl_form_dict[element_tag] += (element_attribute, value_list),
for element_tag, attribute_tuple in untl_form_dict.items():
# Get the count of attributes/content in the element tuple.
attribute_count = len(attribute_tuple)
# Get the count of the first attribute's values.
value_count = len(attribute_tuple[0][1])
# Check to see that all attribute/content values align numerically.
for i in range(0, attribute_count):
if not len(attribute_tuple[i][1]) == value_count:
raise PyuntlException('Field values did not match up '
'numerically for %s' % (element_tag))
# Create a value loop to get all values from the tuple.
for i in range(0, value_count):
untl_element = None
content = ''
qualifier = ''
child_list = []
# Loop through the attributes.
# attribute_tuple[j][0] represents the attribute/content name.
# attribute_tuple[j][1][i] represents the
# current attribute/content value.
for j in range(0, attribute_count):
if attribute_tuple[j][0] == 'content':
content = unicode(attribute_tuple[j][1][i])
elif attribute_tuple[j][0] == 'qualifier':
qualifier = attribute_tuple[j][1][i]
# Create a child UNTL element from the data.
else:
# If the child has content, append it to the child list.
if attribute_tuple[j][1][i] != '':
child_tag = attribute_tuple[j][0]
# Check if the child is the attribute of the element.
if child_tag in PARENT_FORM:
qualifier = attribute_tuple[j][1][i]
# Else, the child is a normal child of the element.
else:
child_list.append(
PYUNTL_DISPATCH[attribute_tuple[j][0]](
content=attribute_tuple[j][1][i]
)
)
# Create the UNTL element.
if content != '' and qualifier != '':
untl_element = PYUNTL_DISPATCH[element_tag](content=content,
qualifier=qualifier)
elif content != '':
untl_element = PYUNTL_DISPATCH[element_tag](content=content)
elif qualifier != '':
untl_element = PYUNTL_DISPATCH[element_tag](qualifier=qualifier)
# This element only has children elements.
elif len(child_list) > 0:
untl_element = PYUNTL_DISPATCH[element_tag]()
# If the element has children, add them.
if len(child_list) > 0 and untl_element is not None:
for child in child_list:
untl_element.add_child(child)
# Add the UNTL element to the root element.
if untl_element is not None:
root_element.add_child(untl_element)
return root_element.create_element_dict() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:untlpy2dcpy; 3, parameters; 3, 4; 3, 5; 4, identifier:untl_elements; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 14; 7, 18; 7, 28; 7, 38; 7, 48; 7, 58; 7, 68; 7, 78; 7, 79; 7, 107; 7, 108; 7, 116; 7, 248; 7, 249; 7, 250; 7, 305; 7, 357; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sDate; 13, None; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:eDate; 17, None; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:ark; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:kwargs; 24, identifier:get; 25, argument_list; 25, 26; 25, 27; 26, string:'ark'; 27, None; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:domain_name; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:kwargs; 34, identifier:get; 35, argument_list; 35, 36; 35, 37; 36, string:'domain_name'; 37, None; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:scheme; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:kwargs; 44, identifier:get; 45, argument_list; 45, 46; 45, 47; 46, string:'scheme'; 47, string:'http'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:resolve_values; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:kwargs; 54, identifier:get; 55, argument_list; 55, 56; 55, 57; 56, string:'resolve_values'; 57, None; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:resolve_urls; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:kwargs; 64, identifier:get; 65, argument_list; 65, 66; 65, 67; 66, string:'resolve_urls'; 67, None; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:verbose_vocabularies; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:kwargs; 74, identifier:get; 75, argument_list; 75, 76; 75, 77; 76, string:'verbose_vocabularies'; 77, None; 78, comment; 79, if_statement; 79, 80; 79, 83; 79, 101; 80, boolean_operator:or; 80, 81; 80, 82; 81, identifier:resolve_values; 82, identifier:resolve_urls; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 86; 84, 87; 84, 92; 85, identifier:verbose_vocabularies; 86, comment; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:vocab_data; 91, identifier:verbose_vocabularies; 92, else_clause; 92, 93; 92, 94; 93, comment; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:vocab_data; 98, call; 98, 99; 98, 100; 99, identifier:retrieve_vocab; 100, argument_list; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:vocab_data; 106, None; 107, comment; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:dc_root; 111, call; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:DC_CONVERSION_DISPATCH; 114, string:'dc'; 115, argument_list; 116, for_statement; 116, 117; 116, 118; 116, 121; 116, 122; 117, identifier:element; 118, attribute; 118, 119; 118, 120; 119, identifier:untl_elements; 120, identifier:children; 121, comment; 122, block; 122, 123; 123, if_statement; 123, 124; 123, 129; 123, 130; 124, comparison_operator:in; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:element; 127, identifier:tag; 128, identifier:DC_CONVERSION_DISPATCH; 129, comment; 130, block; 130, 131; 130, 197; 131, if_statement; 131, 132; 131, 135; 131, 165; 131, 166; 132, attribute; 132, 133; 132, 134; 133, identifier:element; 134, identifier:children; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:dc_element; 139, call; 139, 140; 139, 145; 140, subscript; 140, 141; 140, 142; 141, identifier:DC_CONVERSION_DISPATCH; 142, attribute; 142, 143; 142, 144; 143, identifier:element; 144, identifier:tag; 145, argument_list; 145, 146; 145, 151; 145, 156; 145, 159; 145, 162; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:qualifier; 148, attribute; 148, 149; 148, 150; 149, identifier:element; 150, identifier:qualifier; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:children; 153, attribute; 153, 154; 153, 155; 154, identifier:element; 155, identifier:children; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:resolve_values; 158, identifier:resolve_values; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:resolve_urls; 161, identifier:resolve_urls; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:vocab_data; 164, identifier:vocab_data; 165, comment; 166, else_clause; 166, 167; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:dc_element; 171, call; 171, 172; 171, 177; 172, subscript; 172, 173; 172, 174; 173, identifier:DC_CONVERSION_DISPATCH; 174, attribute; 174, 175; 174, 176; 175, identifier:element; 176, identifier:tag; 177, argument_list; 177, 178; 177, 183; 177, 188; 177, 191; 177, 194; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:qualifier; 180, attribute; 180, 181; 180, 182; 181, identifier:element; 182, identifier:qualifier; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:content; 185, attribute; 185, 186; 185, 187; 186, identifier:element; 187, identifier:content; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:resolve_values; 190, identifier:resolve_values; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:resolve_urls; 193, identifier:resolve_urls; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:vocab_data; 196, identifier:vocab_data; 197, if_statement; 197, 198; 197, 203; 197, 204; 197, 237; 197, 238; 198, comparison_operator:==; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:element; 201, identifier:tag; 202, string:'coverage'; 203, comment; 204, block; 204, 205; 205, if_statement; 205, 206; 205, 211; 205, 216; 205, 227; 205, 228; 206, comparison_operator:==; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:element; 209, identifier:qualifier; 210, string:'sDate'; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:sDate; 215, identifier:dc_element; 216, elif_clause; 216, 217; 216, 222; 217, comparison_operator:==; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:element; 220, identifier:qualifier; 221, string:'eDate'; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:eDate; 226, identifier:dc_element; 227, comment; 228, else_clause; 228, 229; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:dc_root; 234, identifier:add_child; 235, argument_list; 235, 236; 236, identifier:dc_element; 237, comment; 238, elif_clause; 238, 239; 238, 240; 239, identifier:dc_element; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:dc_root; 245, identifier:add_child; 246, argument_list; 246, 247; 247, identifier:dc_element; 248, comment; 249, comment; 250, if_statement; 250, 251; 250, 254; 250, 255; 251, boolean_operator:and; 251, 252; 251, 253; 252, identifier:ark; 253, identifier:domain_name; 254, comment; 255, block; 255, 256; 255, 276; 255, 283; 255, 284; 255, 298; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:permalink_identifier; 259, call; 259, 260; 259, 263; 260, subscript; 260, 261; 260, 262; 261, identifier:DC_CONVERSION_DISPATCH; 262, string:'identifier'; 263, argument_list; 263, 264; 263, 267; 263, 270; 263, 273; 264, keyword_argument; 264, 265; 264, 266; 265, identifier:qualifier; 266, string:'permalink'; 267, keyword_argument; 267, 268; 267, 269; 268, identifier:domain_name; 269, identifier:domain_name; 270, keyword_argument; 270, 271; 270, 272; 271, identifier:ark; 272, identifier:ark; 273, keyword_argument; 273, 274; 273, 275; 274, identifier:scheme; 275, identifier:scheme; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:dc_root; 280, identifier:add_child; 281, argument_list; 281, 282; 282, identifier:permalink_identifier; 283, comment; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:ark_identifier; 287, call; 287, 288; 287, 291; 288, subscript; 288, 289; 288, 290; 289, identifier:DC_CONVERSION_DISPATCH; 290, string:'identifier'; 291, argument_list; 291, 292; 291, 295; 292, keyword_argument; 292, 293; 292, 294; 293, identifier:qualifier; 294, string:'ark'; 295, keyword_argument; 295, 296; 295, 297; 296, identifier:content; 297, identifier:ark; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:dc_root; 302, identifier:add_child; 303, argument_list; 303, 304; 304, identifier:ark_identifier; 305, if_statement; 305, 306; 305, 309; 305, 310; 305, 337; 305, 347; 306, boolean_operator:and; 306, 307; 306, 308; 307, identifier:sDate; 308, identifier:eDate; 309, comment; 310, block; 310, 311; 310, 330; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:dc_element; 314, call; 314, 315; 314, 318; 315, subscript; 315, 316; 315, 317; 316, identifier:DC_CONVERSION_DISPATCH; 317, string:'coverage'; 318, argument_list; 318, 319; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:content; 321, binary_operator:%; 321, 322; 321, 323; 322, string:'%s-%s'; 323, tuple; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:sDate; 326, identifier:content; 327, attribute; 327, 328; 327, 329; 328, identifier:eDate; 329, identifier:content; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:dc_root; 334, identifier:add_child; 335, argument_list; 335, 336; 336, identifier:dc_element; 337, elif_clause; 337, 338; 337, 339; 338, identifier:sDate; 339, block; 339, 340; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:dc_root; 344, identifier:add_child; 345, argument_list; 345, 346; 346, identifier:sDate; 347, elif_clause; 347, 348; 347, 349; 348, identifier:eDate; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:dc_root; 354, identifier:add_child; 355, argument_list; 355, 356; 356, identifier:eDate; 357, return_statement; 357, 358; 358, identifier:dc_root | def untlpy2dcpy(untl_elements, **kwargs):
"""Convert the UNTL elements structure into a DC structure.
kwargs can be passed to the function for certain effects:
ark: Takes an ark string and creates an identifier element out of it.
domain_name: Takes a domain string and creates an ark URL from it
(ark and domain_name must be passed together to work properly).
resolve_values: Converts abbreviated content into resolved vocabulary
labels.
resolve_urls: Converts abbreviated content into resolved vocabulary
URLs.
verbose_vocabularies: Uses the verbose vocabularies passed to the
function instead of this function being required to retrieve them.
# Create a DC Python object from a UNTL XML file.
from pyuntl.untldoc import untlxml2py
untl_elements = untlxml2py(untl_filename) # Or pass a file-like object.
# OR Create a DC Python object from a UNTL dictionary.
from pyuntl.untldoc import untldict2py
untl_elements = untldict2py(untl_dict)
# Convert to UNTL Python object to DC Python object.
dc_elements = untlpy2dcpy(untl_elements)
dc_dict = dcpy2dict(dc_elements)
# Output DC in a specified string format.
from pyuntl.untldoc
import generate_dc_xml, generate_dc_json, generate_dc_txt
# Create a DC XML string.
generate_dc_xml(dc_dict)
# Create a DC JSON string.
generate_dc_json(dc_dict)
# Create a DC text string.
generate_dc_txt(dc_dict)
"""
sDate = None
eDate = None
ark = kwargs.get('ark', None)
domain_name = kwargs.get('domain_name', None)
scheme = kwargs.get('scheme', 'http')
resolve_values = kwargs.get('resolve_values', None)
resolve_urls = kwargs.get('resolve_urls', None)
verbose_vocabularies = kwargs.get('verbose_vocabularies', None)
# If either resolvers were requested, get the vocabulary data.
if resolve_values or resolve_urls:
if verbose_vocabularies:
# If the vocabularies were passed to the function, use them.
vocab_data = verbose_vocabularies
else:
# Otherwise, retrieve them using the pyuntl method.
vocab_data = retrieve_vocab()
else:
vocab_data = None
# Create the DC parent element.
dc_root = DC_CONVERSION_DISPATCH['dc']()
for element in untl_elements.children:
# Check if the UNTL element should be converted to DC.
if element.tag in DC_CONVERSION_DISPATCH:
# Check if the element has its content stored in children nodes.
if element.children:
dc_element = DC_CONVERSION_DISPATCH[element.tag](
qualifier=element.qualifier,
children=element.children,
resolve_values=resolve_values,
resolve_urls=resolve_urls,
vocab_data=vocab_data,
)
# It is a normal element.
else:
dc_element = DC_CONVERSION_DISPATCH[element.tag](
qualifier=element.qualifier,
content=element.content,
resolve_values=resolve_values,
resolve_urls=resolve_urls,
vocab_data=vocab_data,
)
if element.tag == 'coverage':
# Handle start and end dates.
if element.qualifier == 'sDate':
sDate = dc_element
elif element.qualifier == 'eDate':
eDate = dc_element
# Otherwise, add the coverage element to the structure.
else:
dc_root.add_child(dc_element)
# Add non coverage DC element to the structure.
elif dc_element:
dc_root.add_child(dc_element)
# If the domain and ark were specified
# try to turn them into indentifier elements.
if ark and domain_name:
# Create and add the permalink identifier.
permalink_identifier = DC_CONVERSION_DISPATCH['identifier'](
qualifier='permalink',
domain_name=domain_name,
ark=ark,
scheme=scheme
)
dc_root.add_child(permalink_identifier)
# Create and add the ark identifier.
ark_identifier = DC_CONVERSION_DISPATCH['identifier'](
qualifier='ark',
content=ark,
)
dc_root.add_child(ark_identifier)
if sDate and eDate:
# If a start and end date exist, combine them into one element.
dc_element = DC_CONVERSION_DISPATCH['coverage'](
content='%s-%s' % (sDate.content, eDate.content),
)
dc_root.add_child(dc_element)
elif sDate:
dc_root.add_child(sDate)
elif eDate:
dc_root.add_child(eDate)
return dc_root |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:untlpy2highwirepy; 3, parameters; 3, 4; 3, 5; 4, identifier:untl_elements; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 14; 7, 18; 7, 22; 7, 26; 7, 36; 7, 189; 7, 199; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:highwire_list; 13, list:[]; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:title; 17, None; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:publisher; 21, None; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:creation; 25, None; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:escape; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:kwargs; 32, identifier:get; 33, argument_list; 33, 34; 33, 35; 34, string:'escape'; 35, False; 36, for_statement; 36, 37; 36, 38; 36, 41; 36, 42; 36, 43; 37, identifier:element; 38, attribute; 38, 39; 38, 40; 39, identifier:untl_elements; 40, identifier:children; 41, comment; 42, comment; 43, block; 43, 44; 43, 188; 44, if_statement; 44, 45; 44, 50; 45, comparison_operator:in; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:element; 48, identifier:tag; 49, identifier:HIGHWIRE_CONVERSION_DISPATCH; 50, block; 50, 51; 50, 79; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:highwire_element; 54, call; 54, 55; 54, 60; 55, subscript; 55, 56; 55, 57; 56, identifier:HIGHWIRE_CONVERSION_DISPATCH; 57, attribute; 57, 58; 57, 59; 58, identifier:element; 59, identifier:tag; 60, argument_list; 60, 61; 60, 66; 60, 71; 60, 76; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:qualifier; 63, attribute; 63, 64; 63, 65; 64, identifier:element; 65, identifier:qualifier; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:content; 68, attribute; 68, 69; 68, 70; 69, identifier:element; 70, identifier:content; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:children; 73, attribute; 73, 74; 73, 75; 74, identifier:element; 75, identifier:children; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:escape; 78, identifier:escape; 79, if_statement; 79, 80; 79, 81; 80, identifier:highwire_element; 81, block; 81, 82; 82, if_statement; 82, 83; 82, 88; 82, 114; 82, 137; 82, 175; 82, 176; 83, comparison_operator:==; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:element; 86, identifier:tag; 87, string:'title'; 88, block; 88, 89; 89, if_statement; 89, 90; 89, 98; 89, 103; 90, boolean_operator:and; 90, 91; 90, 96; 91, comparison_operator:!=; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:element; 94, identifier:qualifier; 95, string:'officialtitle'; 96, not_operator; 96, 97; 97, identifier:title; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:title; 102, identifier:highwire_element; 103, elif_clause; 103, 104; 103, 109; 104, comparison_operator:==; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:element; 107, identifier:qualifier; 108, string:'officialtitle'; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:title; 113, identifier:highwire_element; 114, elif_clause; 114, 115; 114, 120; 115, comparison_operator:==; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:element; 118, identifier:tag; 119, string:'publisher'; 120, block; 120, 121; 121, if_statement; 121, 122; 121, 124; 121, 125; 122, not_operator; 122, 123; 123, identifier:publisher; 124, comment; 125, block; 125, 126; 125, 130; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:publisher; 129, identifier:highwire_element; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:highwire_list; 134, identifier:append; 135, argument_list; 135, 136; 136, identifier:publisher; 137, elif_clause; 137, 138; 137, 143; 137, 144; 137, 145; 138, comparison_operator:==; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:element; 141, identifier:tag; 142, string:'date'; 143, comment; 144, comment; 145, block; 145, 146; 146, if_statement; 146, 147; 146, 155; 147, boolean_operator:and; 147, 148; 147, 150; 148, not_operator; 148, 149; 149, identifier:creation; 150, comparison_operator:==; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:element; 153, identifier:qualifier; 154, string:'creation'; 155, block; 155, 156; 156, if_statement; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:highwire_element; 159, identifier:content; 160, block; 160, 161; 160, 165; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:creation; 164, identifier:highwire_element; 165, if_statement; 165, 166; 165, 167; 166, identifier:creation; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:highwire_list; 172, identifier:append; 173, argument_list; 173, 174; 174, identifier:creation; 175, comment; 176, elif_clause; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:highwire_element; 179, identifier:content; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:highwire_list; 185, identifier:append; 186, argument_list; 186, 187; 187, identifier:highwire_element; 188, comment; 189, if_statement; 189, 190; 189, 191; 190, identifier:title; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:highwire_list; 196, identifier:append; 197, argument_list; 197, 198; 198, identifier:title; 199, return_statement; 199, 200; 200, identifier:highwire_list | def untlpy2highwirepy(untl_elements, **kwargs):
"""Convert a UNTL Python object to a highwire Python object."""
highwire_list = []
title = None
publisher = None
creation = None
escape = kwargs.get('escape', False)
for element in untl_elements.children:
# If the UNTL element should be converted to highwire,
# create highwire element.
if element.tag in HIGHWIRE_CONVERSION_DISPATCH:
highwire_element = HIGHWIRE_CONVERSION_DISPATCH[element.tag](
qualifier=element.qualifier,
content=element.content,
children=element.children,
escape=escape,
)
if highwire_element:
if element.tag == 'title':
if element.qualifier != 'officialtitle' and not title:
title = highwire_element
elif element.qualifier == 'officialtitle':
title = highwire_element
elif element.tag == 'publisher':
if not publisher:
# This is the first publisher element.
publisher = highwire_element
highwire_list.append(publisher)
elif element.tag == 'date':
# If a creation date hasn't been found yet,
# verify this date is acceptable.
if not creation and element.qualifier == 'creation':
if highwire_element.content:
creation = highwire_element
if creation:
highwire_list.append(creation)
# Otherwise, add the element to the list if it has content.
elif highwire_element.content:
highwire_list.append(highwire_element)
# If the title was found, add it to the list.
if title:
highwire_list.append(title)
return highwire_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:untlpy2etd_ms; 3, parameters; 3, 4; 3, 5; 4, identifier:untl_elements; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 14; 7, 18; 7, 22; 7, 23; 7, 31; 7, 306; 7, 307; 7, 365; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:degree_children; 13, dictionary; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:date_exists; 17, False; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:seen_creation; 21, False; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:etd_ms_root; 26, call; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:ETD_MS_CONVERSION_DISPATCH; 29, string:'thesis'; 30, argument_list; 31, for_statement; 31, 32; 31, 33; 31, 36; 32, identifier:element; 33, attribute; 33, 34; 33, 35; 34, identifier:untl_elements; 35, identifier:children; 36, block; 36, 37; 36, 41; 36, 42; 36, 220; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:etd_ms_element; 40, None; 41, comment; 42, if_statement; 42, 43; 42, 48; 42, 49; 42, 50; 43, comparison_operator:in; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:element; 46, identifier:tag; 47, identifier:ETD_MS_CONVERSION_DISPATCH; 48, comment; 49, comment; 50, block; 50, 51; 50, 209; 50, 210; 51, if_statement; 51, 52; 51, 55; 51, 76; 51, 77; 51, 106; 51, 107; 51, 178; 51, 179; 52, attribute; 52, 53; 52, 54; 53, identifier:element; 54, identifier:children; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:etd_ms_element; 59, call; 59, 60; 59, 65; 60, subscript; 60, 61; 60, 62; 61, identifier:ETD_MS_CONVERSION_DISPATCH; 62, attribute; 62, 63; 62, 64; 63, identifier:element; 64, identifier:tag; 65, argument_list; 65, 66; 65, 71; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:qualifier; 68, attribute; 68, 69; 68, 70; 69, identifier:element; 70, identifier:qualifier; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:children; 73, attribute; 73, 74; 73, 75; 74, identifier:element; 75, identifier:children; 76, comment; 77, elif_clause; 77, 78; 77, 83; 77, 84; 78, comparison_operator:==; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:element; 81, identifier:tag; 82, string:'degree'; 83, comment; 84, block; 84, 85; 85, if_statement; 85, 86; 85, 95; 86, comparison_operator:in; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:element; 89, identifier:qualifier; 90, list:['name',
'level',
'discipline',
'grantor']; 90, 91; 90, 92; 90, 93; 90, 94; 91, string:'name'; 92, string:'level'; 93, string:'discipline'; 94, string:'grantor'; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 103; 98, subscript; 98, 99; 98, 100; 99, identifier:degree_children; 100, attribute; 100, 101; 100, 102; 101, identifier:element; 102, identifier:qualifier; 103, attribute; 103, 104; 103, 105; 104, identifier:element; 105, identifier:content; 106, comment; 107, elif_clause; 107, 108; 107, 113; 108, comparison_operator:==; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:element; 111, identifier:tag; 112, string:'date'; 113, block; 113, 114; 114, if_statement; 114, 115; 114, 120; 114, 121; 115, comparison_operator:==; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:element; 118, identifier:qualifier; 119, string:'creation'; 120, comment; 121, block; 121, 122; 121, 145; 121, 149; 122, for_statement; 122, 123; 122, 124; 122, 127; 123, identifier:child; 124, attribute; 124, 125; 124, 126; 125, identifier:etd_ms_root; 126, identifier:children; 127, block; 127, 128; 128, if_statement; 128, 129; 128, 134; 129, comparison_operator:==; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:child; 132, identifier:tag; 133, string:'date'; 134, block; 134, 135; 134, 137; 135, delete_statement; 135, 136; 136, identifier:child; 137, if_statement; 137, 138; 137, 140; 138, not_operator; 138, 139; 139, identifier:seen_creation; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:date_exists; 144, False; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:seen_creation; 148, True; 149, if_statement; 149, 150; 149, 152; 149, 153; 150, not_operator; 150, 151; 151, identifier:date_exists; 152, comment; 153, block; 153, 154; 153, 174; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:etd_ms_element; 157, call; 157, 158; 157, 163; 158, subscript; 158, 159; 158, 160; 159, identifier:ETD_MS_CONVERSION_DISPATCH; 160, attribute; 160, 161; 160, 162; 161, identifier:element; 162, identifier:tag; 163, argument_list; 163, 164; 163, 169; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:qualifier; 166, attribute; 166, 167; 166, 168; 167, identifier:element; 168, identifier:qualifier; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:content; 171, attribute; 171, 172; 171, 173; 172, identifier:element; 173, identifier:content; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:date_exists; 177, True; 178, comment; 179, elif_clause; 179, 180; 179, 187; 179, 188; 180, comparison_operator:not; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:element; 183, identifier:tag; 184, list:['date', 'degree']; 184, 185; 184, 186; 185, string:'date'; 186, string:'degree'; 187, comment; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:etd_ms_element; 192, call; 192, 193; 192, 198; 193, subscript; 193, 194; 193, 195; 194, identifier:ETD_MS_CONVERSION_DISPATCH; 195, attribute; 195, 196; 195, 197; 196, identifier:element; 197, identifier:tag; 198, argument_list; 198, 199; 198, 204; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:qualifier; 201, attribute; 201, 202; 201, 203; 202, identifier:element; 203, identifier:qualifier; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:content; 206, attribute; 206, 207; 206, 208; 207, identifier:element; 208, identifier:content; 209, comment; 210, if_statement; 210, 211; 210, 212; 211, identifier:etd_ms_element; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:etd_ms_root; 217, identifier:add_child; 218, argument_list; 218, 219; 219, identifier:etd_ms_element; 220, if_statement; 220, 221; 220, 226; 220, 227; 221, comparison_operator:==; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:element; 224, identifier:tag; 225, string:'meta'; 226, comment; 227, block; 227, 228; 227, 232; 227, 233; 227, 259; 227, 260; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:ark; 231, False; 232, comment; 233, for_statement; 233, 234; 233, 235; 233, 238; 234, identifier:i; 235, attribute; 235, 236; 235, 237; 236, identifier:etd_ms_root; 237, identifier:children; 238, block; 238, 239; 239, if_statement; 239, 240; 239, 254; 240, boolean_operator:and; 240, 241; 240, 246; 241, comparison_operator:==; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:i; 244, identifier:tag; 245, string:'identifier'; 246, call; 246, 247; 246, 252; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:i; 250, identifier:content; 251, identifier:startswith; 252, argument_list; 252, 253; 253, string:'http://digital.library.unt.edu/'; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:ark; 258, True; 259, comment; 260, if_statement; 260, 261; 260, 263; 260, 264; 261, not_operator; 261, 262; 262, identifier:ark; 263, comment; 264, block; 264, 265; 264, 269; 264, 282; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:ark; 268, False; 269, if_statement; 269, 270; 269, 275; 270, comparison_operator:==; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:element; 273, identifier:qualifier; 274, string:'ark'; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:ark; 279, attribute; 279, 280; 279, 281; 280, identifier:element; 281, identifier:content; 282, if_statement; 282, 283; 282, 286; 282, 287; 283, comparison_operator:is; 283, 284; 283, 285; 284, identifier:ark; 285, None; 286, comment; 287, block; 287, 288; 287, 299; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:ark_identifier; 291, call; 291, 292; 291, 295; 292, subscript; 292, 293; 292, 294; 293, identifier:ETD_MS_CONVERSION_DISPATCH; 294, string:'identifier'; 295, argument_list; 295, 296; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:ark; 298, identifier:ark; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:etd_ms_root; 303, identifier:add_child; 304, argument_list; 304, 305; 305, identifier:ark_identifier; 306, comment; 307, if_statement; 307, 308; 307, 309; 308, identifier:degree_children; 309, block; 309, 310; 309, 318; 309, 319; 309, 320; 309, 324; 309, 358; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:degree_element; 313, call; 313, 314; 313, 317; 314, subscript; 314, 315; 314, 316; 315, identifier:ETD_MS_CONVERSION_DISPATCH; 316, string:'degree'; 317, argument_list; 318, comment; 319, comment; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:degree_child_element; 323, None; 324, for_statement; 324, 325; 324, 328; 324, 333; 324, 334; 325, pattern_list; 325, 326; 325, 327; 326, identifier:k; 327, identifier:v; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:degree_children; 331, identifier:iteritems; 332, argument_list; 333, comment; 334, block; 334, 335; 334, 346; 334, 347; 334, 348; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:degree_child_element; 338, call; 338, 339; 338, 342; 339, subscript; 339, 340; 339, 341; 340, identifier:ETD_MS_DEGREE_DISPATCH; 341, identifier:k; 342, argument_list; 342, 343; 343, keyword_argument; 343, 344; 343, 345; 344, identifier:content; 345, identifier:v; 346, comment; 347, comment; 348, if_statement; 348, 349; 348, 350; 349, identifier:degree_child_element; 350, block; 350, 351; 351, expression_statement; 351, 352; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:degree_element; 355, identifier:add_child; 356, argument_list; 356, 357; 357, identifier:degree_child_element; 358, expression_statement; 358, 359; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:etd_ms_root; 362, identifier:add_child; 363, argument_list; 363, 364; 364, identifier:degree_element; 365, return_statement; 365, 366; 366, identifier:etd_ms_root | def untlpy2etd_ms(untl_elements, **kwargs):
"""Convert the UNTL elements structure into an ETD_MS structure.
kwargs can be passed to the function for certain effects.
"""
degree_children = {}
date_exists = False
seen_creation = False
# Make the root element.
etd_ms_root = ETD_MS_CONVERSION_DISPATCH['thesis']()
for element in untl_elements.children:
etd_ms_element = None
# Convert the UNTL element to etd_ms where applicable.
if element.tag in ETD_MS_CONVERSION_DISPATCH:
# Create the etd_ms_element if the element's content
# is stored in children nodes.
if element.children:
etd_ms_element = ETD_MS_CONVERSION_DISPATCH[element.tag](
qualifier=element.qualifier,
children=element.children,
)
# If we hit a degree element, make just that one.
elif element.tag == 'degree':
# Make a dict of the degree children information.
if element.qualifier in ['name',
'level',
'discipline',
'grantor']:
degree_children[element.qualifier] = element.content
# For date elements, limit to first instance of creation date.
elif element.tag == 'date':
if element.qualifier == 'creation':
# If the root already has a date, delete the child.
for child in etd_ms_root.children:
if child.tag == 'date':
del child
if not seen_creation:
date_exists = False
seen_creation = True
if not date_exists:
# Create the etd_ms element.
etd_ms_element = ETD_MS_CONVERSION_DISPATCH[element.tag](
qualifier=element.qualifier,
content=element.content,
)
date_exists = True
# It is a normal element.
elif element.tag not in ['date', 'degree']:
# Create the etd_ms_element.
etd_ms_element = ETD_MS_CONVERSION_DISPATCH[element.tag](
qualifier=element.qualifier,
content=element.content,
)
# Add the element to the structure if the element exists.
if etd_ms_element:
etd_ms_root.add_child(etd_ms_element)
if element.tag == 'meta':
# Initialize ark to False because it may not exist yet.
ark = False
# Iterate through children and look for ark.
for i in etd_ms_root.children:
if i.tag == 'identifier' and i.content.startswith(
'http://digital.library.unt.edu/'
):
ark = True
# If the ark doesn't yet exist, try and create it.
if not ark:
# Reset for future tests.
ark = False
if element.qualifier == 'ark':
ark = element.content
if ark is not None:
# Create the ark identifier element and add it.
ark_identifier = ETD_MS_CONVERSION_DISPATCH['identifier'](
ark=ark,
)
etd_ms_root.add_child(ark_identifier)
# If children exist for the degree, make a degree element.
if degree_children:
degree_element = ETD_MS_CONVERSION_DISPATCH['degree']()
# When we have all the elements stored, add the children to the
# degree node.
degree_child_element = None
for k, v in degree_children.iteritems():
# Create the individual classes for degrees.
degree_child_element = ETD_MS_DEGREE_DISPATCH[k](
content=v,
)
# If the keys in degree_children are valid,
# add it to the child.
if degree_child_element:
degree_element.add_child(degree_child_element)
etd_ms_root.add_child(degree_element)
return etd_ms_root |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:global_request; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:kind; 6, default_parameter; 6, 7; 6, 8; 7, identifier:data; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:wait; 11, True; 12, block; 12, 13; 12, 15; 12, 28; 12, 34; 12, 41; 12, 48; 12, 55; 12, 68; 12, 78; 12, 85; 12, 91; 12, 121; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 17; 16, identifier:wait; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:completion_event; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:threading; 26, identifier:Event; 27, argument_list; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:m; 31, call; 31, 32; 31, 33; 32, identifier:Message; 33, argument_list; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:m; 38, identifier:add_byte; 39, argument_list; 39, 40; 40, identifier:cMSG_GLOBAL_REQUEST; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:m; 45, identifier:add_string; 46, argument_list; 46, 47; 47, identifier:kind; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:m; 52, identifier:add_boolean; 53, argument_list; 53, 54; 54, identifier:wait; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:data; 58, None; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:m; 64, identifier:add; 65, argument_list; 65, 66; 66, list_splat; 66, 67; 67, identifier:data; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:_log; 73, argument_list; 73, 74; 73, 75; 74, identifier:DEBUG; 75, binary_operator:%; 75, 76; 75, 77; 76, string:'Sending global request "%s"'; 77, identifier:kind; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:_send_user_message; 83, argument_list; 83, 84; 84, identifier:m; 85, if_statement; 85, 86; 85, 88; 86, not_operator; 86, 87; 87, identifier:wait; 88, block; 88, 89; 89, return_statement; 89, 90; 90, None; 91, while_statement; 91, 92; 91, 93; 92, True; 93, block; 93, 94; 93, 103; 93, 111; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:completion_event; 100, identifier:wait; 101, argument_list; 101, 102; 102, float:0.1; 103, if_statement; 103, 104; 103, 108; 104, not_operator; 104, 105; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:active; 108, block; 108, 109; 109, return_statement; 109, 110; 110, None; 111, if_statement; 111, 112; 111, 119; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:completion_event; 117, identifier:isSet; 118, argument_list; 119, block; 119, 120; 120, break_statement; 121, return_statement; 121, 122; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:global_response | def global_request(self, kind, data=None, wait=True):
"""
Make a global request to the remote host. These are normally
extensions to the SSH2 protocol.
:param str kind: name of the request.
:param tuple data:
an optional tuple containing additional data to attach to the
request.
:param bool wait:
``True`` if this method should not return until a response is
received; ``False`` otherwise.
:return:
a `.Message` containing possible additional data if the request was
successful (or an empty `.Message` if ``wait`` was ``False``);
``None`` if the request was denied.
"""
if wait:
self.completion_event = threading.Event()
m = Message()
m.add_byte(cMSG_GLOBAL_REQUEST)
m.add_string(kind)
m.add_boolean(wait)
if data is not None:
m.add(*data)
self._log(DEBUG, 'Sending global request "%s"' % kind)
self._send_user_message(m)
if not wait:
return None
while True:
self.completion_event.wait(0.1)
if not self.active:
return None
if self.completion_event.isSet():
break
return self.global_response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_by_range; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:model_cls; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 21; 9, 30; 9, 48; 9, 68; 9, 69; 9, 70; 9, 71; 9, 108; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:start_timestamp; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:kwargs; 18, identifier:get; 19, argument_list; 19, 20; 20, string:'start_timestamp'; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:end_timestamp; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:kwargs; 27, identifier:get; 28, argument_list; 28, 29; 29, string:'end_timestamp'; 30, if_statement; 30, 31; 30, 45; 31, boolean_operator:and; 31, 32; 31, 41; 32, boolean_operator:and; 32, 33; 32, 37; 33, parenthesized_expression; 33, 34; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:start_timestamp; 36, None; 37, parenthesized_expression; 37, 38; 38, comparison_operator:is; 38, 39; 38, 40; 39, identifier:end_timestamp; 40, None; 41, parenthesized_expression; 41, 42; 42, comparison_operator:>; 42, 43; 42, 44; 43, identifier:start_timestamp; 44, identifier:end_timestamp; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, identifier:InvalidTimestampRange; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:models; 51, call; 51, 52; 51, 64; 52, attribute; 52, 53; 52, 63; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:model_cls; 56, identifier:read_time_range; 57, argument_list; 57, 58; 57, 60; 58, list_splat; 58, 59; 59, identifier:args; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:end_timestamp; 62, identifier:end_timestamp; 63, identifier:order_by; 64, argument_list; 64, 65; 65, attribute; 65, 66; 65, 67; 66, identifier:model_cls; 67, identifier:time_order; 68, comment; 69, comment; 70, comment; 71, if_statement; 71, 72; 71, 75; 72, comparison_operator:is; 72, 73; 72, 74; 73, identifier:start_timestamp; 74, None; 75, block; 75, 76; 75, 80; 75, 100; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:index; 79, integer:0; 80, for_statement; 80, 81; 80, 84; 80, 91; 81, pattern_list; 81, 82; 81, 83; 82, identifier:index; 83, identifier:model; 84, call; 84, 85; 84, 86; 85, identifier:enumerate; 86, argument_list; 86, 87; 86, 88; 87, identifier:models; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:start; 90, integer:1; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 98; 93, comparison_operator:<=; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:model; 96, identifier:timestamp; 97, identifier:start_timestamp; 98, block; 98, 99; 99, break_statement; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:models; 103, subscript; 103, 104; 103, 105; 104, identifier:models; 105, slice; 105, 106; 105, 107; 106, colon; 107, identifier:index; 108, return_statement; 108, 109; 109, identifier:models | def get_by_range(model_cls, *args, **kwargs):
"""
Get ordered list of models for the specified time range.
The timestamp on the earliest model will likely occur before start_timestamp. This is to ensure that we return
the models for the entire range.
:param model_cls: the class of the model to return
:param args: arguments specific to the model class
:param kwargs: start_timestamp and end_timestamp (see below) as well as keyword args specific to the model class
:keyword start_timestamp: the most recent models set before this and all after, defaults to 0
:keyword end_timestamp: only models set before (and including) this timestamp, defaults to now
:return: model generator
"""
start_timestamp = kwargs.get('start_timestamp')
end_timestamp = kwargs.get('end_timestamp')
if (start_timestamp is not None) and (end_timestamp is not None) and (start_timestamp > end_timestamp):
raise InvalidTimestampRange
models = model_cls.read_time_range(*args, end_timestamp=end_timestamp).order_by(model_cls.time_order)
#
# start time -> Loop through until you find one set before or on start
#
if start_timestamp is not None:
index = 0
for index, model in enumerate(models, start=1):
if model.timestamp <= start_timestamp:
break
models = models[:index]
return models |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:add_data; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:metadata; 8, None; 9, block; 9, 10; 9, 12; 9, 21; 9, 22; 9, 63; 9, 64; 9, 72; 9, 113; 9, 130; 9, 134; 9, 175; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:subdata; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:np; 18, identifier:atleast_2d; 19, argument_list; 19, 20; 20, identifier:data; 21, comment; 22, if_statement; 22, 23; 22, 34; 23, comparison_operator:!=; 23, 24; 23, 29; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:subdata; 27, identifier:shape; 28, integer:1; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:grid; 33, identifier:nr_of_elements; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 47; 35, 54; 36, comparison_operator:==; 36, 37; 36, 42; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:subdata; 40, identifier:shape; 41, integer:0; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:grid; 46, identifier:nr_of_elements; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:subdata; 51, attribute; 51, 52; 51, 53; 52, identifier:subdata; 53, identifier:T; 54, else_clause; 54, 55; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:Exception; 59, argument_list; 59, 60; 60, binary_operator:+; 60, 61; 60, 62; 61, string:'Number of values does not match the number of '; 62, string:'elements in the grid'; 63, comment; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:K; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:subdata; 70, identifier:shape; 71, integer:0; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:is; 73, 74; 73, 75; 74, identifier:metadata; 75, None; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 81; 77, 105; 78, comparison_operator:>; 78, 79; 78, 80; 79, identifier:K; 80, integer:1; 81, block; 81, 82; 82, if_statement; 82, 83; 82, 99; 83, parenthesized_expression; 83, 84; 84, boolean_operator:or; 84, 85; 84, 93; 85, not_operator; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:isinstance; 88, argument_list; 88, 89; 88, 90; 89, identifier:metadata; 90, tuple; 90, 91; 90, 92; 91, identifier:list; 92, identifier:tuple; 93, comparison_operator:!=; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, identifier:metadata; 98, identifier:K; 99, block; 99, 100; 100, raise_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:Exception; 103, argument_list; 103, 104; 104, string:'metadata does not fit the provided data'; 105, else_clause; 105, 106; 105, 107; 106, comment; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:metadata; 111, list:[metadata, ]; 111, 112; 112, identifier:metadata; 113, if_statement; 113, 114; 113, 117; 114, comparison_operator:is; 114, 115; 114, 116; 115, identifier:metadata; 116, None; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:metadata; 121, list_comprehension; 121, 122; 121, 123; 122, None; 123, for_in_clause; 123, 124; 123, 125; 124, identifier:i; 125, call; 125, 126; 125, 127; 126, identifier:range; 127, argument_list; 127, 128; 127, 129; 128, integer:0; 129, identifier:K; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:return_ids; 133, list:[]; 134, for_statement; 134, 135; 134, 138; 134, 143; 135, pattern_list; 135, 136; 135, 137; 136, identifier:dataset; 137, identifier:meta; 138, call; 138, 139; 138, 140; 139, identifier:zip; 140, argument_list; 140, 141; 140, 142; 141, identifier:subdata; 142, identifier:metadata; 143, block; 143, 144; 143, 152; 143, 160; 143, 168; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:cid; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:_get_next_index; 151, argument_list; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 159; 154, subscript; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:parsets; 158, identifier:cid; 159, identifier:dataset; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 167; 162, subscript; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:metadata; 166, identifier:cid; 167, identifier:meta; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:return_ids; 172, identifier:append; 173, argument_list; 173, 174; 174, identifier:cid; 175, if_statement; 175, 176; 175, 182; 175, 187; 176, comparison_operator:==; 176, 177; 176, 181; 177, call; 177, 178; 177, 179; 178, identifier:len; 179, argument_list; 179, 180; 180, identifier:return_ids; 181, integer:1; 182, block; 182, 183; 183, return_statement; 183, 184; 184, subscript; 184, 185; 184, 186; 185, identifier:return_ids; 186, integer:0; 187, else_clause; 187, 188; 188, block; 188, 189; 189, return_statement; 189, 190; 190, identifier:return_ids | def add_data(self, data, metadata=None):
"""Add data to the parameter set
Parameters
----------
data: numpy.ndarray
one or more parameter sets. It must either be 1D or 2D, with the
first dimension the number of parameter sets (K), and the second
the number of elements (N): K x N
metadata: object, optional
the provided object will be stored in in the metadata dict and can
be received with the ID that is returned. If multiple (K) datasets
are added at ones, provide a list of objects with len K.
Returns
-------
int, ID
ID which can be used to access the parameter set
Examples
--------
>>> # suppose that grid is a fully initialized grid oject with 100
# elements
parman = ParMan(grid)
#
one_data_set = np.ones(100)
cid = parman.add_data(one_data_set)
print(parman.parsets[cid])
two_data_sets = np.ones((2, 100))
cids = parman.add_data(two_data_sets)
print(cids)
[0, ]
[1, 2]
"""
subdata = np.atleast_2d(data)
# we try to accommodate transposed input
if subdata.shape[1] != self.grid.nr_of_elements:
if subdata.shape[0] == self.grid.nr_of_elements:
subdata = subdata.T
else:
raise Exception(
'Number of values does not match the number of ' +
'elements in the grid'
)
# now make sure that metadata can be zipped with the subdata
K = subdata.shape[0]
if metadata is not None:
if K > 1:
if(not isinstance(metadata, (list, tuple)) or
len(metadata) != K):
raise Exception('metadata does not fit the provided data')
else:
# K == 1
metadata = [metadata, ]
if metadata is None:
metadata = [None for i in range(0, K)]
return_ids = []
for dataset, meta in zip(subdata, metadata):
cid = self._get_next_index()
self.parsets[cid] = dataset
self.metadata[cid] = meta
return_ids.append(cid)
if len(return_ids) == 1:
return return_ids[0]
else:
return return_ids |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:linked_model_for_class; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:cls; 6, default_parameter; 6, 7; 6, 8; 7, identifier:make_constants_variable; 8, False; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 14; 11, 25; 11, 31; 11, 38; 11, 119; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:constructor_args; 17, attribute; 17, 18; 17, 24; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:inspect; 21, identifier:getfullargspec; 22, argument_list; 22, 23; 23, identifier:cls; 24, identifier:args; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:attribute_tuples; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:attribute_tuples; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:new_model; 34, call; 34, 35; 34, 36; 35, identifier:PriorModel; 36, argument_list; 36, 37; 37, identifier:cls; 38, for_statement; 38, 39; 38, 40; 38, 41; 39, identifier:attribute_tuple; 40, identifier:attribute_tuples; 41, block; 41, 42; 41, 48; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:name; 45, attribute; 45, 46; 45, 47; 46, identifier:attribute_tuple; 47, identifier:name; 48, if_statement; 48, 49; 48, 65; 49, boolean_operator:or; 49, 50; 49, 53; 50, comparison_operator:in; 50, 51; 50, 52; 51, identifier:name; 52, identifier:constructor_args; 53, parenthesized_expression; 53, 54; 54, boolean_operator:and; 54, 55; 54, 59; 55, call; 55, 56; 55, 57; 56, identifier:is_tuple_like_attribute_name; 57, argument_list; 57, 58; 58, identifier:name; 59, comparison_operator:in; 59, 60; 59, 64; 60, call; 60, 61; 60, 62; 61, identifier:tuple_name; 62, argument_list; 62, 63; 63, identifier:name; 64, identifier:constructor_args; 65, block; 65, 66; 65, 79; 65, 112; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:attribute; 69, conditional_expression:if; 69, 70; 69, 73; 69, 76; 70, subscript; 70, 71; 70, 72; 71, identifier:kwargs; 72, identifier:name; 73, comparison_operator:in; 73, 74; 73, 75; 74, identifier:name; 75, identifier:kwargs; 76, attribute; 76, 77; 76, 78; 77, identifier:attribute_tuple; 78, identifier:value; 79, if_statement; 79, 80; 79, 87; 80, boolean_operator:and; 80, 81; 80, 82; 81, identifier:make_constants_variable; 82, call; 82, 83; 82, 84; 83, identifier:isinstance; 84, argument_list; 84, 85; 84, 86; 85, identifier:attribute; 86, identifier:Constant; 87, block; 87, 88; 87, 96; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:new_attribute; 91, call; 91, 92; 91, 93; 92, identifier:getattr; 93, argument_list; 93, 94; 93, 95; 94, identifier:new_model; 95, identifier:name; 96, if_statement; 96, 97; 96, 102; 97, call; 97, 98; 97, 99; 98, identifier:isinstance; 99, argument_list; 99, 100; 99, 101; 100, identifier:new_attribute; 101, identifier:Prior; 102, block; 102, 103; 102, 111; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:new_attribute; 107, identifier:mean; 108, attribute; 108, 109; 108, 110; 109, identifier:attribute; 110, identifier:value; 111, continue_statement; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:setattr; 115, argument_list; 115, 116; 115, 117; 115, 118; 116, identifier:new_model; 117, identifier:name; 118, identifier:attribute; 119, return_statement; 119, 120; 120, identifier:new_model | def linked_model_for_class(self, cls, make_constants_variable=False, **kwargs):
"""
Create a PriorModel wrapping the specified class with attributes from this instance. Priors can be overridden
using keyword arguments. Any constructor arguments of the new class for which there is no attribute associated
with this class and no keyword argument are created from config.
If make_constants_variable is True then constants associated with this instance will be used to set the mean
of priors in the new instance rather than overriding them.
Parameters
----------
cls: class
The class that the new PriorModel will wrap
make_constants_variable: bool
If True constants from this instance will be used to determine the mean values for priors in the new
instance rather than overriding them
kwargs
Keyword arguments passed in here are used to override attributes from this instance or add new attributes
Returns
-------
new_model: PriorModel
A new prior model with priors derived from this instance
"""
constructor_args = inspect.getfullargspec(cls).args
attribute_tuples = self.attribute_tuples
new_model = PriorModel(cls)
for attribute_tuple in attribute_tuples:
name = attribute_tuple.name
if name in constructor_args or (
is_tuple_like_attribute_name(name) and tuple_name(name) in constructor_args):
attribute = kwargs[name] if name in kwargs else attribute_tuple.value
if make_constants_variable and isinstance(attribute, Constant):
new_attribute = getattr(new_model, name)
if isinstance(new_attribute, Prior):
new_attribute.mean = attribute.value
continue
setattr(new_model, name, attribute)
return new_model |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:load_categories; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_pages; 7, integer:30; 8, block; 8, 9; 8, 11; 8, 18; 8, 19; 8, 41; 8, 52; 8, 59; 8, 63; 8, 73; 8, 92; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logger; 15, identifier:info; 16, argument_list; 16, 17; 17, string:"loading categories"; 18, comment; 19, if_statement; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:purge_first; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 40; 26, attribute; 26, 27; 26, 39; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:Category; 31, identifier:objects; 32, identifier:filter; 33, argument_list; 33, 34; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:site_id; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:site_id; 39, identifier:delete; 40, argument_list; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:path; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, string:"sites/{}/categories"; 47, identifier:format; 48, argument_list; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:site_id; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:params; 55, dictionary; 55, 56; 56, pair; 56, 57; 56, 58; 57, string:"number"; 58, integer:100; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:page; 62, integer:1; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:response; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:get; 70, argument_list; 70, 71; 70, 72; 71, identifier:path; 72, identifier:params; 73, if_statement; 73, 74; 73, 78; 74, not_operator; 74, 75; 75, attribute; 75, 76; 75, 77; 76, identifier:response; 77, identifier:ok; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:logger; 83, identifier:warning; 84, argument_list; 84, 85; 84, 86; 84, 89; 85, string:"Response NOT OK! status_code=%s\n%s"; 86, attribute; 86, 87; 86, 88; 87, identifier:response; 88, identifier:status_code; 89, attribute; 89, 90; 89, 91; 90, identifier:response; 91, identifier:text; 92, while_statement; 92, 93; 92, 104; 93, boolean_operator:and; 93, 94; 93, 101; 94, boolean_operator:and; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:response; 97, identifier:ok; 98, attribute; 98, 99; 98, 100; 99, identifier:response; 100, identifier:text; 101, comparison_operator:<; 101, 102; 101, 103; 102, identifier:page; 103, identifier:max_pages; 104, block; 104, 105; 104, 113; 104, 126; 104, 132; 104, 136; 104, 190; 104, 210; 104, 211; 104, 215; 104, 221; 104, 231; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:logger; 109, identifier:info; 110, argument_list; 110, 111; 110, 112; 111, string:" - page: %d"; 112, identifier:page; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:api_categories; 116, call; 116, 117; 116, 124; 117, attribute; 117, 118; 117, 123; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:response; 121, identifier:json; 122, argument_list; 123, identifier:get; 124, argument_list; 124, 125; 125, string:"categories"; 126, if_statement; 126, 127; 126, 129; 126, 130; 127, not_operator; 127, 128; 128, identifier:api_categories; 129, comment; 130, block; 130, 131; 131, break_statement; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:categories; 135, list:[]; 136, for_statement; 136, 137; 136, 138; 136, 139; 136, 140; 137, identifier:api_category; 138, identifier:api_categories; 139, comment; 140, block; 140, 141; 140, 165; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:existing_category; 144, call; 144, 145; 144, 164; 145, attribute; 145, 146; 145, 163; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:Category; 150, identifier:objects; 151, identifier:filter; 152, argument_list; 152, 153; 152, 158; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:site_id; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:site_id; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:wp_id; 160, subscript; 160, 161; 160, 162; 161, identifier:api_category; 162, string:"ID"; 163, identifier:first; 164, argument_list; 165, if_statement; 165, 166; 165, 167; 165, 176; 166, identifier:existing_category; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:update_existing_category; 173, argument_list; 173, 174; 173, 175; 174, identifier:existing_category; 175, identifier:api_category; 176, else_clause; 176, 177; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:categories; 182, identifier:append; 183, argument_list; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:get_new_category; 188, argument_list; 188, 189; 189, identifier:api_category; 190, if_statement; 190, 191; 190, 192; 190, 202; 191, identifier:categories; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:Category; 198, identifier:objects; 199, identifier:bulk_create; 200, argument_list; 200, 201; 201, identifier:categories; 202, elif_clause; 202, 203; 202, 207; 202, 208; 203, not_operator; 203, 204; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:full; 207, comment; 208, block; 208, 209; 209, break_statement; 210, comment; 211, expression_statement; 211, 212; 212, augmented_assignment:+=; 212, 213; 212, 214; 213, identifier:page; 214, integer:1; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 220; 217, subscript; 217, 218; 217, 219; 218, identifier:params; 219, string:"page"; 220, identifier:page; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:response; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:get; 228, argument_list; 228, 229; 228, 230; 229, identifier:path; 230, identifier:params; 231, if_statement; 231, 232; 231, 236; 232, not_operator; 232, 233; 233, attribute; 233, 234; 233, 235; 234, identifier:response; 235, identifier:ok; 236, block; 236, 237; 236, 250; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:logger; 241, identifier:warning; 242, argument_list; 242, 243; 242, 244; 242, 247; 243, string:"Response NOT OK! status_code=%s\n%s"; 244, attribute; 244, 245; 244, 246; 245, identifier:response; 246, identifier:status_code; 247, attribute; 247, 248; 247, 249; 248, identifier:response; 249, identifier:text; 250, return_statement | def load_categories(self, max_pages=30):
"""
Load all WordPress categories from the given site.
:param max_pages: kill counter to avoid infinite looping
:return: None
"""
logger.info("loading categories")
# clear them all out so we don't get dupes if requested
if self.purge_first:
Category.objects.filter(site_id=self.site_id).delete()
path = "sites/{}/categories".format(self.site_id)
params = {"number": 100}
page = 1
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
while response.ok and response.text and page < max_pages:
logger.info(" - page: %d", page)
api_categories = response.json().get("categories")
if not api_categories:
# we're done here
break
categories = []
for api_category in api_categories:
# if it exists locally, update local version if anything has changed
existing_category = Category.objects.filter(site_id=self.site_id, wp_id=api_category["ID"]).first()
if existing_category:
self.update_existing_category(existing_category, api_category)
else:
categories.append(self.get_new_category(api_category))
if categories:
Category.objects.bulk_create(categories)
elif not self.full:
# we're done here
break
# get next page
page += 1
params["page"] = page
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:load_tags; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_pages; 7, integer:30; 8, block; 8, 9; 8, 11; 8, 18; 8, 19; 8, 41; 8, 52; 8, 59; 8, 63; 8, 73; 8, 92; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logger; 15, identifier:info; 16, argument_list; 16, 17; 17, string:"loading tags"; 18, comment; 19, if_statement; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:purge_first; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 40; 26, attribute; 26, 27; 26, 39; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:Tag; 31, identifier:objects; 32, identifier:filter; 33, argument_list; 33, 34; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:site_id; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:site_id; 39, identifier:delete; 40, argument_list; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:path; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, string:"sites/{}/tags"; 47, identifier:format; 48, argument_list; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:site_id; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:params; 55, dictionary; 55, 56; 56, pair; 56, 57; 56, 58; 57, string:"number"; 58, integer:1000; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:page; 62, integer:1; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:response; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:get; 70, argument_list; 70, 71; 70, 72; 71, identifier:path; 72, identifier:params; 73, if_statement; 73, 74; 73, 78; 74, not_operator; 74, 75; 75, attribute; 75, 76; 75, 77; 76, identifier:response; 77, identifier:ok; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:logger; 83, identifier:warning; 84, argument_list; 84, 85; 84, 86; 84, 89; 85, string:"Response NOT OK! status_code=%s\n%s"; 86, attribute; 86, 87; 86, 88; 87, identifier:response; 88, identifier:status_code; 89, attribute; 89, 90; 89, 91; 90, identifier:response; 91, identifier:text; 92, while_statement; 92, 93; 92, 104; 93, boolean_operator:and; 93, 94; 93, 101; 94, boolean_operator:and; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:response; 97, identifier:ok; 98, attribute; 98, 99; 98, 100; 99, identifier:response; 100, identifier:text; 101, comparison_operator:<; 101, 102; 101, 103; 102, identifier:page; 103, identifier:max_pages; 104, block; 104, 105; 104, 113; 104, 126; 104, 132; 104, 136; 104, 190; 104, 210; 104, 211; 104, 215; 104, 221; 104, 231; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:logger; 109, identifier:info; 110, argument_list; 110, 111; 110, 112; 111, string:" - page: %d"; 112, identifier:page; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:api_tags; 116, call; 116, 117; 116, 124; 117, attribute; 117, 118; 117, 123; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:response; 121, identifier:json; 122, argument_list; 123, identifier:get; 124, argument_list; 124, 125; 125, string:"tags"; 126, if_statement; 126, 127; 126, 129; 126, 130; 127, not_operator; 127, 128; 128, identifier:api_tags; 129, comment; 130, block; 130, 131; 131, break_statement; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:tags; 135, list:[]; 136, for_statement; 136, 137; 136, 138; 136, 139; 136, 140; 137, identifier:api_tag; 138, identifier:api_tags; 139, comment; 140, block; 140, 141; 140, 165; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:existing_tag; 144, call; 144, 145; 144, 164; 145, attribute; 145, 146; 145, 163; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:Tag; 150, identifier:objects; 151, identifier:filter; 152, argument_list; 152, 153; 152, 158; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:site_id; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:site_id; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:wp_id; 160, subscript; 160, 161; 160, 162; 161, identifier:api_tag; 162, string:"ID"; 163, identifier:first; 164, argument_list; 165, if_statement; 165, 166; 165, 167; 165, 176; 166, identifier:existing_tag; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:update_existing_tag; 173, argument_list; 173, 174; 173, 175; 174, identifier:existing_tag; 175, identifier:api_tag; 176, else_clause; 176, 177; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:tags; 182, identifier:append; 183, argument_list; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:get_new_tag; 188, argument_list; 188, 189; 189, identifier:api_tag; 190, if_statement; 190, 191; 190, 192; 190, 202; 191, identifier:tags; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:Tag; 198, identifier:objects; 199, identifier:bulk_create; 200, argument_list; 200, 201; 201, identifier:tags; 202, elif_clause; 202, 203; 202, 207; 202, 208; 203, not_operator; 203, 204; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:full; 207, comment; 208, block; 208, 209; 209, break_statement; 210, comment; 211, expression_statement; 211, 212; 212, augmented_assignment:+=; 212, 213; 212, 214; 213, identifier:page; 214, integer:1; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 220; 217, subscript; 217, 218; 217, 219; 218, identifier:params; 219, string:"page"; 220, identifier:page; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:response; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:get; 228, argument_list; 228, 229; 228, 230; 229, identifier:path; 230, identifier:params; 231, if_statement; 231, 232; 231, 236; 232, not_operator; 232, 233; 233, attribute; 233, 234; 233, 235; 234, identifier:response; 235, identifier:ok; 236, block; 236, 237; 236, 250; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:logger; 241, identifier:warning; 242, argument_list; 242, 243; 242, 244; 242, 247; 243, string:"Response NOT OK! status_code=%s\n%s"; 244, attribute; 244, 245; 244, 246; 245, identifier:response; 246, identifier:status_code; 247, attribute; 247, 248; 247, 249; 248, identifier:response; 249, identifier:text; 250, return_statement | def load_tags(self, max_pages=30):
"""
Load all WordPress tags from the given site.
:param max_pages: kill counter to avoid infinite looping
:return: None
"""
logger.info("loading tags")
# clear them all out so we don't get dupes if requested
if self.purge_first:
Tag.objects.filter(site_id=self.site_id).delete()
path = "sites/{}/tags".format(self.site_id)
params = {"number": 1000}
page = 1
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
while response.ok and response.text and page < max_pages:
logger.info(" - page: %d", page)
api_tags = response.json().get("tags")
if not api_tags:
# we're done here
break
tags = []
for api_tag in api_tags:
# if it exists locally, update local version if anything has changed
existing_tag = Tag.objects.filter(site_id=self.site_id, wp_id=api_tag["ID"]).first()
if existing_tag:
self.update_existing_tag(existing_tag, api_tag)
else:
tags.append(self.get_new_tag(api_tag))
if tags:
Tag.objects.bulk_create(tags)
elif not self.full:
# we're done here
break
# get next page
page += 1
params["page"] = page
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:load_authors; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_pages; 7, integer:10; 8, block; 8, 9; 8, 11; 8, 18; 8, 19; 8, 41; 8, 52; 8, 59; 8, 63; 8, 73; 8, 92; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logger; 15, identifier:info; 16, argument_list; 16, 17; 17, string:"loading authors"; 18, comment; 19, if_statement; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:purge_first; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 40; 26, attribute; 26, 27; 26, 39; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:Author; 31, identifier:objects; 32, identifier:filter; 33, argument_list; 33, 34; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:site_id; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:site_id; 39, identifier:delete; 40, argument_list; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:path; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, string:"sites/{}/users"; 47, identifier:format; 48, argument_list; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:site_id; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:params; 55, dictionary; 55, 56; 56, pair; 56, 57; 56, 58; 57, string:"number"; 58, integer:100; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:page; 62, integer:1; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:response; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:get; 70, argument_list; 70, 71; 70, 72; 71, identifier:path; 72, identifier:params; 73, if_statement; 73, 74; 73, 78; 74, not_operator; 74, 75; 75, attribute; 75, 76; 75, 77; 76, identifier:response; 77, identifier:ok; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:logger; 83, identifier:warning; 84, argument_list; 84, 85; 84, 86; 84, 89; 85, string:"Response NOT OK! status_code=%s\n%s"; 86, attribute; 86, 87; 86, 88; 87, identifier:response; 88, identifier:status_code; 89, attribute; 89, 90; 89, 91; 90, identifier:response; 91, identifier:text; 92, while_statement; 92, 93; 92, 104; 93, boolean_operator:and; 93, 94; 93, 101; 94, boolean_operator:and; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:response; 97, identifier:ok; 98, attribute; 98, 99; 98, 100; 99, identifier:response; 100, identifier:text; 101, comparison_operator:<; 101, 102; 101, 103; 102, identifier:page; 103, identifier:max_pages; 104, block; 104, 105; 104, 113; 104, 126; 104, 132; 104, 136; 104, 190; 104, 210; 104, 211; 104, 212; 104, 220; 104, 224; 104, 234; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:logger; 109, identifier:info; 110, argument_list; 110, 111; 110, 112; 111, string:" - page: %d"; 112, identifier:page; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:api_users; 116, call; 116, 117; 116, 124; 117, attribute; 117, 118; 117, 123; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:response; 121, identifier:json; 122, argument_list; 123, identifier:get; 124, argument_list; 124, 125; 125, string:"users"; 126, if_statement; 126, 127; 126, 129; 126, 130; 127, not_operator; 127, 128; 128, identifier:api_users; 129, comment; 130, block; 130, 131; 131, break_statement; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:authors; 135, list:[]; 136, for_statement; 136, 137; 136, 138; 136, 139; 136, 140; 137, identifier:api_author; 138, identifier:api_users; 139, comment; 140, block; 140, 141; 140, 165; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:existing_author; 144, call; 144, 145; 144, 164; 145, attribute; 145, 146; 145, 163; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:Author; 150, identifier:objects; 151, identifier:filter; 152, argument_list; 152, 153; 152, 158; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:site_id; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:site_id; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:wp_id; 160, subscript; 160, 161; 160, 162; 161, identifier:api_author; 162, string:"ID"; 163, identifier:first; 164, argument_list; 165, if_statement; 165, 166; 165, 167; 165, 176; 166, identifier:existing_author; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:update_existing_author; 173, argument_list; 173, 174; 173, 175; 174, identifier:existing_author; 175, identifier:api_author; 176, else_clause; 176, 177; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:authors; 182, identifier:append; 183, argument_list; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:get_new_author; 188, argument_list; 188, 189; 189, identifier:api_author; 190, if_statement; 190, 191; 190, 192; 190, 202; 191, identifier:authors; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:Author; 198, identifier:objects; 199, identifier:bulk_create; 200, argument_list; 200, 201; 201, identifier:authors; 202, elif_clause; 202, 203; 202, 207; 202, 208; 203, not_operator; 203, 204; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:full; 207, comment; 208, block; 208, 209; 209, break_statement; 210, comment; 211, comment; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:params; 216, string:"offset"; 217, binary_operator:*; 217, 218; 217, 219; 218, identifier:page; 219, integer:100; 220, expression_statement; 220, 221; 221, augmented_assignment:+=; 221, 222; 221, 223; 222, identifier:page; 223, integer:1; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:response; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:get; 231, argument_list; 231, 232; 231, 233; 232, identifier:path; 233, identifier:params; 234, if_statement; 234, 235; 234, 239; 235, not_operator; 235, 236; 236, attribute; 236, 237; 236, 238; 237, identifier:response; 238, identifier:ok; 239, block; 239, 240; 239, 253; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:logger; 244, identifier:warning; 245, argument_list; 245, 246; 245, 247; 245, 250; 246, string:"Response NOT OK! status_code=%s\n%s"; 247, attribute; 247, 248; 247, 249; 248, identifier:response; 249, identifier:status_code; 250, attribute; 250, 251; 250, 252; 251, identifier:response; 252, identifier:text; 253, return_statement | def load_authors(self, max_pages=10):
"""
Load all WordPress authors from the given site.
:param max_pages: kill counter to avoid infinite looping
:return: None
"""
logger.info("loading authors")
# clear them all out so we don't get dupes if requested
if self.purge_first:
Author.objects.filter(site_id=self.site_id).delete()
path = "sites/{}/users".format(self.site_id)
params = {"number": 100}
page = 1
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
while response.ok and response.text and page < max_pages:
logger.info(" - page: %d", page)
api_users = response.json().get("users")
if not api_users:
# we're done here
break
authors = []
for api_author in api_users:
# if it exists locally, update local version if anything has changed
existing_author = Author.objects.filter(site_id=self.site_id, wp_id=api_author["ID"]).first()
if existing_author:
self.update_existing_author(existing_author, api_author)
else:
authors.append(self.get_new_author(api_author))
if authors:
Author.objects.bulk_create(authors)
elif not self.full:
# we're done here
break
# get next page
# this endpoint doesn't have a page param, so use offset
params["offset"] = page * 100
page += 1
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:load_media; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_pages; 7, integer:150; 8, block; 8, 9; 8, 11; 8, 18; 8, 19; 8, 51; 8, 62; 8, 69; 8, 76; 8, 80; 8, 90; 8, 109; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logger; 15, identifier:info; 16, argument_list; 16, 17; 17, string:"loading media"; 18, comment; 19, if_statement; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:purge_first; 23, block; 23, 24; 23, 34; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:logger; 28, identifier:warning; 29, argument_list; 29, 30; 29, 31; 30, string:"purging ALL media from site %s"; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:site_id; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 50; 36, attribute; 36, 37; 36, 49; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:Media; 41, identifier:objects; 42, identifier:filter; 43, argument_list; 43, 44; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:site_id; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:site_id; 49, identifier:delete; 50, argument_list; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:path; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, string:"sites/{}/media"; 57, identifier:format; 58, argument_list; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:site_id; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:params; 65, dictionary; 65, 66; 66, pair; 66, 67; 66, 68; 67, string:"number"; 68, integer:100; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:set_media_params_after; 74, argument_list; 74, 75; 75, identifier:params; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:page; 79, integer:1; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:response; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:get; 87, argument_list; 87, 88; 87, 89; 88, identifier:path; 89, identifier:params; 90, if_statement; 90, 91; 90, 95; 91, not_operator; 91, 92; 92, attribute; 92, 93; 92, 94; 93, identifier:response; 94, identifier:ok; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:logger; 100, identifier:warning; 101, argument_list; 101, 102; 101, 103; 101, 106; 102, string:"Response NOT OK! status_code=%s\n%s"; 103, attribute; 103, 104; 103, 105; 104, identifier:response; 105, identifier:status_code; 106, attribute; 106, 107; 106, 108; 107, identifier:response; 108, identifier:text; 109, while_statement; 109, 110; 109, 121; 110, boolean_operator:and; 110, 111; 110, 118; 111, boolean_operator:and; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:response; 114, identifier:ok; 115, attribute; 115, 116; 115, 117; 116, identifier:response; 117, identifier:text; 118, comparison_operator:<; 118, 119; 118, 120; 119, identifier:page; 120, identifier:max_pages; 121, block; 121, 122; 121, 130; 121, 143; 121, 149; 121, 153; 121, 215; 121, 227; 121, 228; 121, 232; 121, 238; 121, 248; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:logger; 126, identifier:info; 127, argument_list; 127, 128; 127, 129; 128, string:" - page: %d"; 129, identifier:page; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:api_medias; 133, call; 133, 134; 133, 141; 134, attribute; 134, 135; 134, 140; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:response; 138, identifier:json; 139, argument_list; 140, identifier:get; 141, argument_list; 141, 142; 142, string:"media"; 143, if_statement; 143, 144; 143, 146; 143, 147; 144, not_operator; 144, 145; 145, identifier:api_medias; 146, comment; 147, block; 147, 148; 148, break_statement; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:medias; 152, list:[]; 153, for_statement; 153, 154; 153, 155; 153, 156; 153, 157; 154, identifier:api_media; 155, identifier:api_medias; 156, comment; 157, block; 157, 158; 158, if_statement; 158, 159; 158, 164; 158, 165; 159, comparison_operator:!=; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:api_media; 162, string:"post_ID"; 163, integer:0; 164, comment; 165, block; 165, 166; 165, 190; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:existing_media; 169, call; 169, 170; 169, 189; 170, attribute; 170, 171; 170, 188; 171, call; 171, 172; 171, 177; 172, attribute; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:Media; 175, identifier:objects; 176, identifier:filter; 177, argument_list; 177, 178; 177, 183; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:site_id; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:site_id; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:wp_id; 185, subscript; 185, 186; 185, 187; 186, identifier:api_media; 187, string:"ID"; 188, identifier:first; 189, argument_list; 190, if_statement; 190, 191; 190, 192; 190, 201; 191, identifier:existing_media; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:update_existing_media; 198, argument_list; 198, 199; 198, 200; 199, identifier:existing_media; 200, identifier:api_media; 201, else_clause; 201, 202; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:medias; 207, identifier:append; 208, argument_list; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:get_new_media; 213, argument_list; 213, 214; 214, identifier:api_media; 215, if_statement; 215, 216; 215, 217; 216, identifier:medias; 217, block; 217, 218; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 225; 220, attribute; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:Media; 223, identifier:objects; 224, identifier:bulk_create; 225, argument_list; 225, 226; 226, identifier:medias; 227, comment; 228, expression_statement; 228, 229; 229, augmented_assignment:+=; 229, 230; 229, 231; 230, identifier:page; 231, integer:1; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:params; 236, string:"page"; 237, identifier:page; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:response; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:get; 245, argument_list; 245, 246; 245, 247; 246, identifier:path; 247, identifier:params; 248, if_statement; 248, 249; 248, 253; 249, not_operator; 249, 250; 250, attribute; 250, 251; 250, 252; 251, identifier:response; 252, identifier:ok; 253, block; 253, 254; 253, 267; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:logger; 258, identifier:warning; 259, argument_list; 259, 260; 259, 261; 259, 264; 260, string:"Response NOT OK! status_code=%s\n%s"; 261, attribute; 261, 262; 261, 263; 262, identifier:response; 263, identifier:status_code; 264, attribute; 264, 265; 264, 266; 265, identifier:response; 266, identifier:text; 267, return_statement | def load_media(self, max_pages=150):
"""
Load all WordPress media from the given site.
:param max_pages: kill counter to avoid infinite looping
:return: None
"""
logger.info("loading media")
# clear them all out so we don't get dupes
if self.purge_first:
logger.warning("purging ALL media from site %s", self.site_id)
Media.objects.filter(site_id=self.site_id).delete()
path = "sites/{}/media".format(self.site_id)
params = {"number": 100}
self.set_media_params_after(params)
page = 1
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
while response.ok and response.text and page < max_pages:
logger.info(" - page: %d", page)
api_medias = response.json().get("media")
if not api_medias:
# we're done here
break
medias = []
for api_media in api_medias:
# exclude media items that are not attached to posts (for now)
if api_media["post_ID"] != 0:
# if it exists locally, update local version if anything has changed
existing_media = Media.objects.filter(site_id=self.site_id, wp_id=api_media["ID"]).first()
if existing_media:
self.update_existing_media(existing_media, api_media)
else:
medias.append(self.get_new_media(api_media))
if medias:
Media.objects.bulk_create(medias)
# get next page
page += 1
params["page"] = page
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:load_wp_post; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:api_post; 6, default_parameter; 6, 7; 6, 8; 7, identifier:bulk_mode; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:post_categories; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:post_tags; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:post_media_attachments; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:posts; 20, None; 21, block; 21, 22; 21, 24; 21, 25; 21, 34; 21, 43; 21, 52; 21, 61; 21, 62; 21, 66; 21, 88; 21, 89; 21, 98; 21, 107; 21, 116; 21, 117; 21, 141; 21, 171; 21, 172; 21, 173; 21, 174; 22, expression_statement; 22, 23; 23, comment; 24, comment; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:post_categories; 28, None; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:post_categories; 33, dictionary; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:post_tags; 37, None; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:post_tags; 42, dictionary; 43, if_statement; 43, 44; 43, 47; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:post_media_attachments; 46, None; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:post_media_attachments; 51, dictionary; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:is; 53, 54; 53, 55; 54, identifier:posts; 55, None; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:posts; 60, list:[]; 61, comment; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:author; 65, None; 66, if_statement; 66, 67; 66, 75; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:api_post; 71, string:"author"; 72, identifier:get; 73, argument_list; 73, 74; 74, string:"ID"; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:author; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:process_post_author; 83, argument_list; 83, 84; 83, 85; 84, identifier:bulk_mode; 85, subscript; 85, 86; 85, 87; 86, identifier:api_post; 87, string:"author"; 88, comment; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:process_post_categories; 94, argument_list; 94, 95; 94, 96; 94, 97; 95, identifier:bulk_mode; 96, identifier:api_post; 97, identifier:post_categories; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:process_post_tags; 103, argument_list; 103, 104; 103, 105; 103, 106; 104, identifier:bulk_mode; 105, identifier:api_post; 106, identifier:post_tags; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:process_post_media_attachments; 112, argument_list; 112, 113; 112, 114; 112, 115; 113, identifier:bulk_mode; 114, identifier:api_post; 115, identifier:post_media_attachments; 116, comment; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:existing_post; 120, call; 120, 121; 120, 140; 121, attribute; 121, 122; 121, 139; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:Post; 126, identifier:objects; 127, identifier:filter; 128, argument_list; 128, 129; 128, 134; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:site_id; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:site_id; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:wp_id; 136, subscript; 136, 137; 136, 138; 137, identifier:api_post; 138, string:"ID"; 139, identifier:first; 140, argument_list; 141, if_statement; 141, 142; 141, 143; 141, 156; 142, identifier:existing_post; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:process_existing_post; 149, argument_list; 149, 150; 149, 151; 149, 152; 149, 153; 149, 154; 149, 155; 150, identifier:existing_post; 151, identifier:api_post; 152, identifier:author; 153, identifier:post_categories; 154, identifier:post_tags; 155, identifier:post_media_attachments; 156, else_clause; 156, 157; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:process_new_post; 163, argument_list; 163, 164; 163, 165; 163, 166; 163, 167; 163, 168; 163, 169; 163, 170; 164, identifier:bulk_mode; 165, identifier:api_post; 166, identifier:posts; 167, identifier:author; 168, identifier:post_categories; 169, identifier:post_tags; 170, identifier:post_media_attachments; 171, comment; 172, comment; 173, comment; 174, if_statement; 174, 175; 174, 180; 175, comparison_operator:==; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:api_post; 178, string:"type"; 179, string:"post"; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:sync_deleted_attachments; 186, argument_list; 186, 187; 187, identifier:api_post | def load_wp_post(self, api_post, bulk_mode=True, post_categories=None, post_tags=None, post_media_attachments=None, posts=None):
"""
Load a single post from API data.
:param api_post: the API data for the post
:param bulk_mode: If True, minimize db operations by bulk creating post objects
:param post_categories: a mapping of Categories in the site, keyed by post ID
:param post_tags: a mapping of Tags in the site, keyed by post ID
:param post_media_attachments: a mapping of Media in the site, keyed by post ID
:param posts: a list of posts to be created or updated
:return: None
"""
# initialize reference vars if none supplied
if post_categories is None:
post_categories = {}
if post_tags is None:
post_tags = {}
if post_media_attachments is None:
post_media_attachments = {}
if posts is None:
posts = []
# process objects related to this post
author = None
if api_post["author"].get("ID"):
author = self.process_post_author(bulk_mode, api_post["author"])
# process many-to-many fields
self.process_post_categories(bulk_mode, api_post, post_categories)
self.process_post_tags(bulk_mode, api_post, post_tags)
self.process_post_media_attachments(bulk_mode, api_post, post_media_attachments)
# if this post exists, update it; else create it
existing_post = Post.objects.filter(site_id=self.site_id, wp_id=api_post["ID"]).first()
if existing_post:
self.process_existing_post(existing_post, api_post, author, post_categories, post_tags, post_media_attachments)
else:
self.process_new_post(bulk_mode, api_post, posts, author, post_categories, post_tags, post_media_attachments)
# if this is a real post (not an attachment, page, etc.), sync child attachments that haven been deleted
# these are generally other posts with post_type=attachment representing media that has been "uploaded to the post"
# they can be deleted on the WP side, creating an orphan here without this step.
if api_post["type"] == "post":
self.sync_deleted_attachments(api_post) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sync_deleted_attachments; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:api_post; 6, block; 6, 7; 6, 9; 6, 48; 6, 49; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:existing_IDs; 12, call; 12, 13; 12, 14; 13, identifier:set; 14, argument_list; 14, 15; 15, call; 15, 16; 15, 43; 16, attribute; 16, 17; 16, 42; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:Post; 21, identifier:objects; 22, identifier:filter; 23, argument_list; 23, 24; 23, 29; 23, 32; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:site_id; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:site_id; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:post_type; 31, string:"attachment"; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:parent__icontains; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, string:'"ID":{}'; 37, identifier:format; 38, argument_list; 38, 39; 39, subscript; 39, 40; 39, 41; 40, identifier:api_post; 41, string:"ID"; 42, identifier:values_list; 43, argument_list; 43, 44; 43, 45; 44, string:"wp_id"; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:flat; 47, True; 48, comment; 49, if_statement; 49, 50; 49, 51; 50, identifier:existing_IDs; 51, block; 51, 52; 51, 58; 51, 59; 51, 70; 51, 88; 51, 92; 51, 102; 51, 121; 51, 122; 51, 229; 51, 230; 51, 236; 51, 237; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:api_IDs; 55, call; 55, 56; 55, 57; 56, identifier:set; 57, argument_list; 58, comment; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:path; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, string:"sites/{}/posts/"; 65, identifier:format; 66, argument_list; 66, 67; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:site_id; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:params; 73, dictionary; 73, 74; 73, 77; 73, 82; 73, 85; 74, pair; 74, 75; 74, 76; 75, string:"type"; 76, string:"attachment"; 77, pair; 77, 78; 77, 79; 78, string:"parent_id"; 79, subscript; 79, 80; 79, 81; 80, identifier:api_post; 81, string:"ID"; 82, pair; 82, 83; 82, 84; 83, string:"fields"; 84, string:"ID"; 85, pair; 85, 86; 85, 87; 86, string:"number"; 87, integer:100; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:page; 91, integer:1; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:response; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:get; 99, argument_list; 99, 100; 99, 101; 100, identifier:path; 101, identifier:params; 102, if_statement; 102, 103; 102, 107; 103, not_operator; 103, 104; 104, attribute; 104, 105; 104, 106; 105, identifier:response; 106, identifier:ok; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:logger; 112, identifier:warning; 113, argument_list; 113, 114; 113, 115; 113, 118; 114, string:"Response NOT OK! status_code=%s\n%s"; 115, attribute; 115, 116; 115, 117; 116, identifier:response; 117, identifier:status_code; 118, attribute; 118, 119; 118, 120; 119, identifier:response; 120, identifier:text; 121, comment; 122, while_statement; 122, 123; 122, 134; 123, boolean_operator:and; 123, 124; 123, 131; 124, boolean_operator:and; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:response; 127, identifier:ok; 128, attribute; 128, 129; 128, 130; 129, identifier:response; 130, identifier:text; 131, comparison_operator:<; 131, 132; 131, 133; 132, identifier:page; 133, integer:10; 134, block; 134, 135; 134, 143; 134, 153; 134, 154; 134, 166; 134, 167; 134, 171; 134, 186; 134, 199; 134, 209; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:api_json; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:response; 141, identifier:json; 142, argument_list; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:api_attachments; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:api_json; 149, identifier:get; 150, argument_list; 150, 151; 150, 152; 151, string:"posts"; 152, list:[]; 153, comment; 154, expression_statement; 154, 155; 155, augmented_assignment:|=; 155, 156; 155, 157; 156, identifier:api_IDs; 157, call; 157, 158; 157, 159; 158, identifier:set; 159, generator_expression; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:a; 162, string:"ID"; 163, for_in_clause; 163, 164; 163, 165; 164, identifier:a; 165, identifier:api_attachments; 166, comment; 167, expression_statement; 167, 168; 168, augmented_assignment:+=; 168, 169; 168, 170; 169, identifier:page; 170, integer:1; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:next_page_handle; 174, call; 174, 175; 174, 184; 175, attribute; 175, 176; 175, 183; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:api_json; 179, identifier:get; 180, argument_list; 180, 181; 180, 182; 181, string:"meta"; 182, dictionary; 183, identifier:get; 184, argument_list; 184, 185; 185, string:"next_page"; 186, if_statement; 186, 187; 186, 188; 186, 195; 187, identifier:next_page_handle; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:params; 193, string:"page_handle"; 194, identifier:next_page_handle; 195, else_clause; 195, 196; 195, 197; 196, comment; 197, block; 197, 198; 198, break_statement; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:response; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:get; 206, argument_list; 206, 207; 206, 208; 207, identifier:path; 208, identifier:params; 209, if_statement; 209, 210; 209, 214; 210, not_operator; 210, 211; 211, attribute; 211, 212; 211, 213; 212, identifier:response; 213, identifier:ok; 214, block; 214, 215; 214, 228; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:logger; 219, identifier:warning; 220, argument_list; 220, 221; 220, 222; 220, 225; 221, string:"Response NOT OK! status_code=%s\n%s"; 222, attribute; 222, 223; 222, 224; 223, identifier:response; 224, identifier:status_code; 225, attribute; 225, 226; 225, 227; 226, identifier:response; 227, identifier:text; 228, return_statement; 229, comment; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:to_remove; 233, binary_operator:-; 233, 234; 233, 235; 234, identifier:existing_IDs; 235, identifier:api_IDs; 236, comment; 237, if_statement; 237, 238; 237, 239; 238, identifier:to_remove; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 275; 242, attribute; 242, 243; 242, 274; 243, call; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:Post; 247, identifier:objects; 248, identifier:filter; 249, argument_list; 249, 250; 249, 255; 249, 258; 249, 268; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:site_id; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:site_id; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:post_type; 257, string:"attachment"; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:parent__icontains; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, string:'"ID":{}'; 263, identifier:format; 264, argument_list; 264, 265; 265, subscript; 265, 266; 265, 267; 266, identifier:api_post; 267, string:"ID"; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:wp_id__in; 270, call; 270, 271; 270, 272; 271, identifier:list; 272, argument_list; 272, 273; 273, identifier:to_remove; 274, identifier:delete; 275, argument_list | def sync_deleted_attachments(self, api_post):
"""
Remove Posts with post_type=attachment that have been removed from the given Post on the WordPress side.
Logic:
- get the list of Posts with post_type = attachment whose parent_id = this post_id
- get the corresponding list from WP API
- perform set difference
- delete extra local attachments if any
:param api_post: the API data for the Post
:return: None
"""
existing_IDs = set(Post.objects.filter(site_id=self.site_id,
post_type="attachment",
parent__icontains='"ID":{}'.format(api_post["ID"]))
.values_list("wp_id", flat=True))
# can't delete what we don't have
if existing_IDs:
api_IDs = set()
# call the API again to the get the full list of attachment posts whose parent is this post's wp_id
path = "sites/{}/posts/".format(self.site_id)
params = {
"type": "attachment",
"parent_id": api_post["ID"],
"fields": "ID",
"number": 100
}
page = 1
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
# loop around since there may be more than 100 attachments (example: really large slideshows)
while response.ok and response.text and page < 10:
api_json = response.json()
api_attachments = api_json.get("posts", [])
# iteratively extend the set to include this page's IDs
api_IDs |= set(a["ID"] for a in api_attachments)
# get next page
page += 1
next_page_handle = api_json.get("meta", {}).get("next_page")
if next_page_handle:
params["page_handle"] = next_page_handle
else:
# no more pages left
break
response = self.get(path, params)
if not response.ok:
logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
return
# perform set difference
to_remove = existing_IDs - api_IDs
# purge the extras
if to_remove:
Post.objects.filter(site_id=self.site_id,
post_type="attachment",
parent__icontains='"ID":{}'.format(api_post["ID"]),
wp_id__in=list(to_remove)).delete() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:http_request; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 4, identifier:self; 5, identifier:verb; 6, identifier:uri; 7, default_parameter; 7, 8; 7, 9; 8, identifier:data; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:headers; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:files; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:response_format; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:is_rdf; 21, True; 22, default_parameter; 22, 23; 22, 24; 23, identifier:stream; 24, False; 25, block; 25, 26; 25, 28; 25, 29; 25, 81; 25, 82; 25, 102; 25, 115; 25, 116; 25, 124; 25, 156; 25, 165; 25, 177; 26, expression_statement; 26, 27; 27, string:'''
Primary route for all HTTP requests to repository. Ability to set most parameters for requests library,
with some additional convenience parameters as well.
Args:
verb (str): HTTP verb to use for request, e.g. PUT, POST, GET, HEAD, PATCH, etc.
uri (rdflib.term.URIRef,str): input URI
data (str,file): payload of data to send for request, may be overridden in preperation of request
headers (dict): optional dictionary of headers passed directly to requests.request
files (dict): optional dictionary of files passed directly to requests.request
response_format (str): desired response format for resource's payload, e.g. 'application/rdf+xml', 'text/turtle', etc.
is_rdf (bool): if True, set Accept header based on combination of response_format and headers
stream (bool): passed directly to requests.request for stream parameter
Returns:
requests.models.Response
'''; 28, comment; 29, if_statement; 29, 30; 29, 31; 30, identifier:is_rdf; 31, block; 31, 32; 31, 34; 31, 35; 32, expression_statement; 32, 33; 33, string:'''
Acceptable content negotiated response formats include:
application/ld+json (discouraged, if not prohibited, as it drops prefixes used in repository)
application/n-triples
application/rdf+xml
text/n3 (or text/rdf+n3)
text/plain
text/turtle (or application/x-turtle)
'''; 34, comment; 35, if_statement; 35, 36; 35, 39; 35, 40; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:verb; 38, string:'GET'; 39, comment; 40, block; 40, 41; 40, 53; 40, 54; 41, if_statement; 41, 42; 41, 44; 42, not_operator; 42, 43; 43, identifier:response_format; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:response_format; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:repo; 52, identifier:default_serialization; 53, comment; 54, if_statement; 54, 55; 54, 64; 54, 71; 54, 72; 55, boolean_operator:and; 55, 56; 55, 57; 56, identifier:headers; 57, comparison_operator:not; 57, 58; 57, 59; 58, string:'Accept'; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:headers; 62, identifier:keys; 63, argument_list; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:headers; 69, string:'Accept'; 70, identifier:response_format; 71, comment; 72, else_clause; 72, 73; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:headers; 77, dictionary; 77, 78; 78, pair; 78, 79; 78, 80; 79, string:'Accept'; 80, identifier:response_format; 81, comment; 82, if_statement; 82, 83; 82, 93; 83, comparison_operator:==; 83, 84; 83, 88; 84, call; 84, 85; 84, 86; 85, identifier:type; 86, argument_list; 86, 87; 87, identifier:uri; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:rdflib; 91, identifier:term; 92, identifier:URIRef; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:uri; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:uri; 100, identifier:toPython; 101, argument_list; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:logger; 106, identifier:debug; 107, argument_list; 107, 108; 108, binary_operator:%; 108, 109; 108, 110; 109, string:"%s request for %s, format %s, headers %s"; 110, tuple; 110, 111; 110, 112; 110, 113; 110, 114; 111, identifier:verb; 112, identifier:uri; 113, identifier:response_format; 114, identifier:headers; 115, comment; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:session; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:requests; 122, identifier:Session; 123, argument_list; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:request; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:requests; 130, identifier:Request; 131, argument_list; 131, 132; 131, 133; 131, 134; 131, 147; 131, 150; 131, 153; 132, identifier:verb; 133, identifier:uri; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:auth; 136, tuple; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:repo; 141, identifier:username; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:repo; 146, identifier:password; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:data; 149, identifier:data; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:headers; 152, identifier:headers; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:files; 155, identifier:files; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:prepped_request; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:session; 162, identifier:prepare_request; 163, argument_list; 163, 164; 164, identifier:request; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:response; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:session; 171, identifier:send; 172, argument_list; 172, 173; 172, 174; 173, identifier:prepped_request; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:stream; 176, identifier:stream; 177, return_statement; 177, 178; 178, identifier:response | def http_request(self,
verb,
uri,
data=None,
headers=None,
files=None,
response_format=None,
is_rdf = True,
stream = False
):
'''
Primary route for all HTTP requests to repository. Ability to set most parameters for requests library,
with some additional convenience parameters as well.
Args:
verb (str): HTTP verb to use for request, e.g. PUT, POST, GET, HEAD, PATCH, etc.
uri (rdflib.term.URIRef,str): input URI
data (str,file): payload of data to send for request, may be overridden in preperation of request
headers (dict): optional dictionary of headers passed directly to requests.request
files (dict): optional dictionary of files passed directly to requests.request
response_format (str): desired response format for resource's payload, e.g. 'application/rdf+xml', 'text/turtle', etc.
is_rdf (bool): if True, set Accept header based on combination of response_format and headers
stream (bool): passed directly to requests.request for stream parameter
Returns:
requests.models.Response
'''
# set content negotiated response format for RDFSources
if is_rdf:
'''
Acceptable content negotiated response formats include:
application/ld+json (discouraged, if not prohibited, as it drops prefixes used in repository)
application/n-triples
application/rdf+xml
text/n3 (or text/rdf+n3)
text/plain
text/turtle (or application/x-turtle)
'''
# set for GET requests only
if verb == 'GET':
# if no response_format has been requested to this point, use repository instance default
if not response_format:
response_format = self.repo.default_serialization
# if headers present, append
if headers and 'Accept' not in headers.keys():
headers['Accept'] = response_format
# if headers are blank, init dictionary
else:
headers = {'Accept':response_format}
# prepare uri for HTTP request
if type(uri) == rdflib.term.URIRef:
uri = uri.toPython()
logger.debug("%s request for %s, format %s, headers %s" %
(verb, uri, response_format, headers))
# manually prepare request
session = requests.Session()
request = requests.Request(verb, uri, auth=(self.repo.username, self.repo.password), data=data, headers=headers, files=files)
prepped_request = session.prepare_request(request)
response = session.send(prepped_request,
stream=stream,
)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:create; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:specify_uri; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ignore_tombstone; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:serialization_format; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:stream; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:auto_refresh; 19, None; 20, block; 20, 21; 20, 23; 20, 24; 21, expression_statement; 21, 22; 22, string:'''
Primary method to create resources.
Args:
specify_uri (bool): If True, uses PUT verb and sets the URI during creation. If False, uses POST and gets repository minted URI
ignore_tombstone (bool): If True, will attempt creation, if tombstone exists (409), will delete tombstone and retry
serialization_format(str): Content-Type header / mimetype that will be used to serialize self.rdf.graph, and set headers for PUT/POST requests
auto_refresh (bool): If True, refreshes resource after update. If left None, defaults to repo.default_auto_refresh
'''; 23, comment; 24, if_statement; 24, 25; 24, 28; 24, 34; 24, 35; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:exists; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:Exception; 32, argument_list; 32, 33; 33, string:'resource exists attribute True, aborting'; 34, comment; 35, else_clause; 35, 36; 35, 37; 36, comment; 37, block; 37, 38; 37, 51; 37, 64; 37, 65; 37, 66; 37, 150; 37, 151; 37, 178; 38, if_statement; 38, 39; 38, 40; 38, 45; 39, identifier:specify_uri; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:verb; 44, string:'PUT'; 45, else_clause; 45, 46; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:verb; 50, string:'POST'; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:logger; 55, identifier:debug; 56, argument_list; 56, 57; 57, binary_operator:%; 57, 58; 57, 59; 58, string:'creating resource %s with verb %s'; 59, tuple; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:uri; 63, identifier:verb; 64, comment; 65, comment; 66, if_statement; 66, 67; 66, 75; 66, 92; 66, 93; 67, call; 67, 68; 67, 69; 68, identifier:issubclass; 69, argument_list; 69, 70; 69, 74; 70, call; 70, 71; 70, 72; 71, identifier:type; 72, argument_list; 72, 73; 73, identifier:self; 74, identifier:NonRDFSource; 75, block; 75, 76; 75, 84; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:binary; 82, identifier:_prep_binary; 83, argument_list; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:data; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:binary; 91, identifier:data; 92, comment; 93, else_clause; 93, 94; 93, 95; 94, comment; 95, block; 95, 96; 95, 108; 95, 123; 95, 130; 95, 142; 96, if_statement; 96, 97; 96, 99; 97, not_operator; 97, 98; 98, identifier:serialization_format; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:serialization_format; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:repo; 107, identifier:default_serialization; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:data; 111, call; 111, 112; 111, 119; 112, attribute; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:rdf; 117, identifier:graph; 118, identifier:serialize; 119, argument_list; 119, 120; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:format; 122, identifier:serialization_format; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:logger; 127, identifier:debug; 128, argument_list; 128, 129; 129, string:'Serialized graph used for resource creation:'; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:logger; 134, identifier:debug; 135, argument_list; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:data; 139, identifier:decode; 140, argument_list; 140, 141; 141, string:'utf-8'; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:headers; 148, string:'Content-Type'; 149, identifier:serialization_format; 150, comment; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:response; 154, call; 154, 155; 154, 162; 155, attribute; 155, 156; 155, 161; 156, attribute; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:repo; 160, identifier:api; 161, identifier:http_request; 162, argument_list; 162, 163; 162, 164; 162, 167; 162, 170; 162, 175; 163, identifier:verb; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:uri; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:data; 169, identifier:data; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:headers; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:headers; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:stream; 177, identifier:stream; 178, return_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:_handle_create; 183, argument_list; 183, 184; 183, 185; 183, 186; 184, identifier:response; 185, identifier:ignore_tombstone; 186, identifier:auto_refresh | def create(self, specify_uri=False, ignore_tombstone=False, serialization_format=None, stream=False, auto_refresh=None):
'''
Primary method to create resources.
Args:
specify_uri (bool): If True, uses PUT verb and sets the URI during creation. If False, uses POST and gets repository minted URI
ignore_tombstone (bool): If True, will attempt creation, if tombstone exists (409), will delete tombstone and retry
serialization_format(str): Content-Type header / mimetype that will be used to serialize self.rdf.graph, and set headers for PUT/POST requests
auto_refresh (bool): If True, refreshes resource after update. If left None, defaults to repo.default_auto_refresh
'''
# if resource claims existence, raise exception
if self.exists:
raise Exception('resource exists attribute True, aborting')
# else, continue
else:
# determine verb based on specify_uri parameter
if specify_uri:
verb = 'PUT'
else:
verb = 'POST'
logger.debug('creating resource %s with verb %s' % (self.uri, verb))
# check if NonRDFSource, or extension thereof
#if so, run self.binary._prep_binary()
if issubclass(type(self),NonRDFSource):
self.binary._prep_binary()
data = self.binary.data
# otherwise, prep for RDF
else:
# determine serialization
if not serialization_format:
serialization_format = self.repo.default_serialization
data = self.rdf.graph.serialize(format=serialization_format)
logger.debug('Serialized graph used for resource creation:')
logger.debug(data.decode('utf-8'))
self.headers['Content-Type'] = serialization_format
# fire creation request
response = self.repo.api.http_request(verb, self.uri, data=data, headers=self.headers, stream=stream)
return self._handle_create(response, ignore_tombstone, auto_refresh) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:refresh; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:refresh_binary; 7, True; 8, block; 8, 9; 8, 11; 8, 24; 8, 25; 8, 51; 9, expression_statement; 9, 10; 10, string:'''
Performs GET request and refreshes RDF information for resource.
Args:
None
Returns:
None
'''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:updated_self; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:repo; 19, identifier:get_resource; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:uri; 24, comment; 25, if_statement; 25, 26; 25, 35; 26, not_operator; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:isinstance; 29, argument_list; 29, 30; 29, 31; 30, identifier:self; 31, call; 31, 32; 31, 33; 32, identifier:type; 33, argument_list; 33, 34; 34, identifier:updated_self; 35, block; 35, 36; 36, raise_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:Exception; 39, argument_list; 39, 40; 40, binary_operator:%; 40, 41; 40, 42; 41, string:'Instantiated %s, but repository reports this resource is %s'; 42, tuple; 42, 43; 42, 47; 43, call; 43, 44; 43, 45; 44, identifier:type; 45, argument_list; 45, 46; 46, identifier:updated_self; 47, call; 47, 48; 47, 49; 48, identifier:type; 49, argument_list; 49, 50; 50, identifier:self; 51, if_statement; 51, 52; 51, 53; 51, 54; 51, 153; 52, identifier:updated_self; 53, comment; 54, block; 54, 55; 54, 63; 54, 75; 54, 83; 54, 91; 54, 92; 54, 106; 54, 107; 54, 115; 54, 116; 54, 135; 54, 136; 54, 149; 54, 150; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:status_code; 60, attribute; 60, 61; 60, 62; 61, identifier:updated_self; 62, identifier:status_code; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:rdf; 69, identifier:data; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:updated_self; 73, identifier:rdf; 74, identifier:data; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:headers; 80, attribute; 80, 81; 80, 82; 81, identifier:updated_self; 82, identifier:headers; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:exists; 88, attribute; 88, 89; 88, 90; 89, identifier:updated_self; 90, identifier:exists; 91, comment; 92, if_statement; 92, 93; 92, 99; 93, comparison_operator:!=; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:type; 96, argument_list; 96, 97; 97, identifier:self; 98, identifier:NonRDFSource; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:_parse_graph; 105, argument_list; 106, comment; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:versions; 112, call; 112, 113; 112, 114; 113, identifier:SimpleNamespace; 114, argument_list; 115, comment; 116, if_statement; 116, 117; 116, 125; 117, boolean_operator:and; 117, 118; 117, 124; 118, comparison_operator:==; 118, 119; 118, 123; 119, call; 119, 120; 119, 121; 120, identifier:type; 121, argument_list; 121, 122; 122, identifier:updated_self; 123, identifier:NonRDFSource; 124, identifier:refresh_binary; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 133; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:binary; 132, identifier:refresh; 133, argument_list; 133, 134; 134, identifier:updated_self; 135, comment; 136, if_statement; 136, 137; 136, 142; 137, call; 137, 138; 137, 139; 138, identifier:hasattr; 139, argument_list; 139, 140; 139, 141; 140, identifier:self; 141, string:'_post_refresh'; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:_post_refresh; 148, argument_list; 149, comment; 150, delete_statement; 150, 151; 151, parenthesized_expression; 151, 152; 152, identifier:updated_self; 153, else_clause; 153, 154; 154, block; 154, 155; 154, 162; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:logger; 159, identifier:debug; 160, argument_list; 160, 161; 161, string:'resource %s not found, dumping values'; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:_empty_resource_attributes; 167, argument_list | def refresh(self, refresh_binary=True):
'''
Performs GET request and refreshes RDF information for resource.
Args:
None
Returns:
None
'''
updated_self = self.repo.get_resource(self.uri)
# if resource type of updated_self != self, raise exception
if not isinstance(self, type(updated_self)):
raise Exception('Instantiated %s, but repository reports this resource is %s' % (type(updated_self), type(self)) )
if updated_self:
# update attributes
self.status_code = updated_self.status_code
self.rdf.data = updated_self.rdf.data
self.headers = updated_self.headers
self.exists = updated_self.exists
# update graph if RDFSource
if type(self) != NonRDFSource:
self._parse_graph()
# empty versions
self.versions = SimpleNamespace()
# if NonRDF, set binary attributes
if type(updated_self) == NonRDFSource and refresh_binary:
self.binary.refresh(updated_self)
# fire resource._post_create hook if exists
if hasattr(self,'_post_refresh'):
self._post_refresh()
# cleanup
del(updated_self)
else:
logger.debug('resource %s not found, dumping values')
self._empty_resource_attributes() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:update; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sparql_query_only; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:auto_refresh; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:update_binary; 13, True; 14, block; 14, 15; 14, 17; 14, 18; 14, 24; 14, 40; 14, 49; 14, 81; 14, 82; 14, 107; 14, 108; 14, 219; 14, 220; 14, 233; 14, 234; 14, 236; 14, 269; 15, expression_statement; 15, 16; 16, string:'''
Method to update resources in repository. Firing this method computes the difference in the local modified graph and the original one,
creates an instance of SparqlUpdate and builds a sparql query that represents these differences, and sends this as a PATCH request.
Note: send PATCH request, regardless of RDF or NonRDF, to [uri]/fcr:metadata
If the resource is NonRDF (Binary), this also method also updates the binary data.
Args:
sparql_query_only (bool): If True, returns only the sparql query string and does not perform any actual updates
auto_refresh (bool): If True, refreshes resource after update. If left None, defaults to repo.default_auto_refresh
update_binary (bool): If True, and resource is NonRDF, updates binary data as well
Returns:
(bool)
'''; 17, comment; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_diff_graph; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:sq; 27, call; 27, 28; 27, 29; 28, identifier:SparqlUpdate; 29, argument_list; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:rdf; 34, identifier:prefixes; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:rdf; 39, identifier:diffs; 40, if_statement; 40, 41; 40, 42; 41, identifier:sparql_query_only; 42, block; 42, 43; 43, return_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:sq; 47, identifier:build_query; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:response; 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:repo; 58, identifier:api; 59, identifier:http_request; 60, argument_list; 60, 61; 60, 62; 60, 67; 60, 68; 60, 75; 61, string:'PATCH'; 62, binary_operator:%; 62, 63; 62, 64; 63, string:'%s/fcr:metadata'; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:uri; 67, comment; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:data; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:sq; 73, identifier:build_query; 74, argument_list; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:headers; 77, dictionary; 77, 78; 78, pair; 78, 79; 78, 80; 79, string:'Content-Type'; 80, string:'application/sparql-update'; 81, comment; 82, if_statement; 82, 83; 82, 88; 83, comparison_operator:!=; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:response; 86, identifier:status_code; 87, integer:204; 88, block; 88, 89; 88, 98; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:logger; 93, identifier:debug; 94, argument_list; 94, 95; 95, attribute; 95, 96; 95, 97; 96, identifier:response; 97, identifier:content; 98, raise_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:Exception; 101, argument_list; 101, 102; 102, binary_operator:%; 102, 103; 102, 104; 103, string:'HTTP %s, expecting 204'; 104, attribute; 104, 105; 104, 106; 105, identifier:response; 106, identifier:status_code; 107, comment; 108, if_statement; 108, 109; 108, 132; 109, boolean_operator:and; 109, 110; 109, 118; 110, boolean_operator:and; 110, 111; 110, 117; 111, comparison_operator:==; 111, 112; 111, 116; 112, call; 112, 113; 112, 114; 113, identifier:type; 114, argument_list; 114, 115; 115, identifier:self; 116, identifier:NonRDFSource; 117, identifier:update_binary; 118, comparison_operator:!=; 118, 119; 118, 127; 119, call; 119, 120; 119, 121; 120, identifier:type; 121, argument_list; 121, 122; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:binary; 126, identifier:data; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:requests; 130, identifier:models; 131, identifier:Response; 132, block; 132, 133; 132, 141; 132, 149; 132, 178; 132, 179; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:binary; 139, identifier:_prep_binary; 140, argument_list; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:binary_data; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:binary; 148, identifier:data; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:binary_response; 152, call; 152, 153; 152, 160; 153, attribute; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:repo; 158, identifier:api; 159, identifier:http_request; 160, argument_list; 160, 161; 160, 162; 160, 165; 160, 168; 161, string:'PUT'; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:uri; 165, keyword_argument; 165, 166; 165, 167; 166, identifier:data; 167, identifier:binary_data; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:headers; 170, dictionary; 170, 171; 171, pair; 171, 172; 171, 173; 172, string:'Content-Type'; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:binary; 177, identifier:mimetype; 178, comment; 179, if_statement; 179, 180; 179, 189; 180, boolean_operator:and; 180, 181; 180, 183; 181, not_operator; 181, 182; 182, identifier:auto_refresh; 183, not_operator; 183, 184; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:repo; 188, identifier:default_auto_refresh; 189, block; 189, 190; 189, 197; 189, 210; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:logger; 194, identifier:debug; 195, argument_list; 195, 196; 196, string:"not refreshing resource RDF, but updated binary, so must refresh binary data"; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:updated_self; 200, call; 200, 201; 200, 206; 201, attribute; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:repo; 205, identifier:get_resource; 206, argument_list; 206, 207; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:uri; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 217; 212, attribute; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:binary; 216, identifier:refresh; 217, argument_list; 217, 218; 218, identifier:updated_self; 219, comment; 220, if_statement; 220, 221; 220, 226; 221, call; 221, 222; 221, 223; 222, identifier:hasattr; 223, argument_list; 223, 224; 223, 225; 224, identifier:self; 225, string:'_post_update'; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:self; 231, identifier:_post_update; 232, argument_list; 233, comment; 234, expression_statement; 234, 235; 235, string:'''
If not updating binary, pass that bool to refresh as refresh_binary flag to avoid touching binary data
'''; 236, if_statement; 236, 237; 236, 238; 236, 248; 237, identifier:auto_refresh; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:refresh; 244, argument_list; 244, 245; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:refresh_binary; 247, identifier:update_binary; 248, elif_clause; 248, 249; 248, 252; 249, comparison_operator:==; 249, 250; 249, 251; 250, identifier:auto_refresh; 251, None; 252, block; 252, 253; 253, if_statement; 253, 254; 253, 259; 254, attribute; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:self; 257, identifier:repo; 258, identifier:default_auto_refresh; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:refresh; 265, argument_list; 265, 266; 266, keyword_argument; 266, 267; 266, 268; 267, identifier:refresh_binary; 268, identifier:update_binary; 269, return_statement; 269, 270; 270, True | def update(self, sparql_query_only=False, auto_refresh=None, update_binary=True):
'''
Method to update resources in repository. Firing this method computes the difference in the local modified graph and the original one,
creates an instance of SparqlUpdate and builds a sparql query that represents these differences, and sends this as a PATCH request.
Note: send PATCH request, regardless of RDF or NonRDF, to [uri]/fcr:metadata
If the resource is NonRDF (Binary), this also method also updates the binary data.
Args:
sparql_query_only (bool): If True, returns only the sparql query string and does not perform any actual updates
auto_refresh (bool): If True, refreshes resource after update. If left None, defaults to repo.default_auto_refresh
update_binary (bool): If True, and resource is NonRDF, updates binary data as well
Returns:
(bool)
'''
# run diff on graphs, send as PATCH request
self._diff_graph()
sq = SparqlUpdate(self.rdf.prefixes, self.rdf.diffs)
if sparql_query_only:
return sq.build_query()
response = self.repo.api.http_request(
'PATCH',
'%s/fcr:metadata' % self.uri, # send RDF updates to URI/fcr:metadata
data=sq.build_query(),
headers={'Content-Type':'application/sparql-update'})
# if RDF update not 204, raise Exception
if response.status_code != 204:
logger.debug(response.content)
raise Exception('HTTP %s, expecting 204' % response.status_code)
# if NonRDFSource, and self.binary.data is not a Response object, update binary as well
if type(self) == NonRDFSource and update_binary and type(self.binary.data) != requests.models.Response:
self.binary._prep_binary()
binary_data = self.binary.data
binary_response = self.repo.api.http_request(
'PUT',
self.uri,
data=binary_data,
headers={'Content-Type':self.binary.mimetype})
# if not refreshing RDF, still update binary here
if not auto_refresh and not self.repo.default_auto_refresh:
logger.debug("not refreshing resource RDF, but updated binary, so must refresh binary data")
updated_self = self.repo.get_resource(self.uri)
self.binary.refresh(updated_self)
# fire optional post-update hook
if hasattr(self,'_post_update'):
self._post_update()
# determine refreshing
'''
If not updating binary, pass that bool to refresh as refresh_binary flag to avoid touching binary data
'''
if auto_refresh:
self.refresh(refresh_binary=update_binary)
elif auto_refresh == None:
if self.repo.default_auto_refresh:
self.refresh(refresh_binary=update_binary)
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:update_gunicorns; 3, parameters; 4, block; 4, 5; 4, 7; 4, 9; 4, 13; 4, 24; 4, 28; 4, 47; 4, 68; 4, 81; 4, 90; 4, 99; 4, 243; 4, 244; 4, 268; 4, 269; 4, 288; 5, expression_statement; 5, 6; 6, comment; 7, global_statement; 7, 8; 8, identifier:tick; 9, expression_statement; 9, 10; 10, augmented_assignment:+=; 10, 11; 10, 12; 11, identifier:tick; 12, integer:1; 13, if_statement; 13, 14; 13, 22; 14, comparison_operator:!=; 14, 15; 14, 21; 15, binary_operator:%; 15, 16; 15, 20; 16, parenthesized_expression; 16, 17; 17, binary_operator:*; 17, 18; 17, 19; 18, identifier:tick; 19, identifier:screen_delay; 20, identifier:ps_delay; 21, integer:0; 22, block; 22, 23; 23, return_statement; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:tick; 27, integer:0; 28, for_statement; 28, 29; 28, 30; 28, 31; 29, identifier:pid; 30, identifier:gunicorns; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:gunicorns; 37, identifier:pid; 38, identifier:update; 39, argument_list; 39, 40; 40, dictionary; 40, 41; 40, 44; 41, pair; 41, 42; 41, 43; 42, string:"workers"; 43, integer:0; 44, pair; 44, 45; 44, 46; 45, string:"mem"; 46, integer:0; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:ps; 50, call; 50, 51; 50, 66; 51, attribute; 51, 52; 51, 65; 52, subscript; 52, 53; 52, 64; 53, call; 53, 54; 53, 63; 54, attribute; 54, 55; 54, 62; 55, call; 55, 56; 55, 57; 56, identifier:Popen; 57, argument_list; 57, 58; 57, 59; 58, identifier:PS_ARGS; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:stdout; 61, identifier:PIPE; 62, identifier:communicate; 63, argument_list; 64, integer:0; 65, identifier:split; 66, argument_list; 66, 67; 67, string:"\n"; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:headings; 71, call; 71, 72; 71, 80; 72, attribute; 72, 73; 72, 79; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:ps; 76, identifier:pop; 77, argument_list; 77, 78; 78, integer:0; 79, identifier:split; 80, argument_list; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:name_col; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:headings; 87, identifier:index; 88, argument_list; 88, 89; 89, identifier:cmd_heading; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:num_cols; 93, binary_operator:-; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, identifier:headings; 98, integer:1; 99, for_statement; 99, 100; 99, 101; 99, 102; 100, identifier:row; 101, identifier:ps; 102, block; 102, 103; 102, 113; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:cols; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:row; 109, identifier:split; 110, argument_list; 110, 111; 110, 112; 111, None; 112, identifier:num_cols; 113, if_statement; 113, 114; 113, 121; 114, boolean_operator:and; 114, 115; 114, 116; 115, identifier:cols; 116, comparison_operator:in; 116, 117; 116, 118; 117, string:"gunicorn: "; 118, subscript; 118, 119; 118, 120; 119, identifier:cols; 120, identifier:name_col; 121, block; 121, 122; 121, 139; 121, 166; 121, 214; 121, 232; 122, if_statement; 122, 123; 122, 128; 122, 133; 123, comparison_operator:in; 123, 124; 123, 125; 124, string:"gunicorn: worker"; 125, subscript; 125, 126; 125, 127; 126, identifier:cols; 127, identifier:name_col; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:is_worker; 132, True; 133, else_clause; 133, 134; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:is_worker; 138, False; 139, if_statement; 139, 140; 139, 141; 139, 153; 140, identifier:is_worker; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:pid; 145, subscript; 145, 146; 145, 147; 146, identifier:cols; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:headings; 150, identifier:index; 151, argument_list; 151, 152; 152, string:"PPID"; 153, else_clause; 153, 154; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:pid; 158, subscript; 158, 159; 158, 160; 159, identifier:cols; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:headings; 163, identifier:index; 164, argument_list; 164, 165; 165, string:"PID"; 166, if_statement; 166, 167; 166, 170; 167, comparison_operator:not; 167, 168; 167, 169; 168, identifier:pid; 169, identifier:gunicorns; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:gunicorns; 175, identifier:pid; 176, dictionary; 176, 177; 176, 180; 176, 183; 176, 186; 177, pair; 177, 178; 177, 179; 178, string:"workers"; 179, integer:0; 180, pair; 180, 181; 180, 182; 181, string:"mem"; 182, integer:0; 183, pair; 183, 184; 183, 185; 184, string:"port"; 185, None; 186, pair; 186, 187; 186, 188; 187, string:"name"; 188, subscript; 188, 189; 188, 210; 189, call; 189, 190; 189, 207; 190, attribute; 190, 191; 190, 206; 191, subscript; 191, 192; 191, 205; 192, call; 192, 193; 192, 202; 193, attribute; 193, 194; 193, 201; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, subscript; 196, 197; 196, 198; 197, identifier:cols; 198, identifier:name_col; 199, identifier:strip; 200, argument_list; 201, identifier:split; 202, argument_list; 202, 203; 202, 204; 203, string:"["; 204, integer:1; 205, integer:1; 206, identifier:split; 207, argument_list; 207, 208; 207, 209; 208, string:"]"; 209, integer:1; 210, slice; 210, 211; 210, 212; 211, colon; 212, unary_operator:-; 212, 213; 213, integer:1; 214, expression_statement; 214, 215; 215, augmented_assignment:+=; 215, 216; 215, 221; 216, subscript; 216, 217; 216, 220; 217, subscript; 217, 218; 217, 219; 218, identifier:gunicorns; 219, identifier:pid; 220, string:"mem"; 221, call; 221, 222; 221, 223; 222, identifier:int; 223, argument_list; 223, 224; 224, subscript; 224, 225; 224, 226; 225, identifier:cols; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:headings; 229, identifier:index; 230, argument_list; 230, 231; 231, string:"RSS"; 232, if_statement; 232, 233; 232, 234; 233, identifier:is_worker; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, augmented_assignment:+=; 236, 237; 236, 242; 237, subscript; 237, 238; 237, 241; 238, subscript; 238, 239; 238, 240; 239, identifier:gunicorns; 240, identifier:pid; 241, string:"workers"; 242, integer:1; 243, comment; 244, for_statement; 244, 245; 244, 246; 244, 254; 245, identifier:pid; 246, subscript; 246, 247; 246, 252; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:gunicorns; 250, identifier:keys; 251, argument_list; 252, slice; 252, 253; 253, colon; 254, block; 254, 255; 255, if_statement; 255, 256; 255, 263; 256, comparison_operator:==; 256, 257; 256, 262; 257, subscript; 257, 258; 257, 261; 258, subscript; 258, 259; 258, 260; 259, identifier:gunicorns; 260, identifier:pid; 261, string:"workers"; 262, integer:0; 263, block; 263, 264; 264, delete_statement; 264, 265; 265, subscript; 265, 266; 265, 267; 266, identifier:gunicorns; 267, identifier:pid; 268, comment; 269, if_statement; 269, 270; 269, 286; 270, not_operator; 270, 271; 271, list_comprehension; 271, 272; 271, 273; 271, 280; 272, identifier:g; 273, for_in_clause; 273, 274; 273, 275; 274, identifier:g; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:gunicorns; 278, identifier:values; 279, argument_list; 280, if_clause; 280, 281; 281, comparison_operator:is; 281, 282; 281, 285; 282, subscript; 282, 283; 282, 284; 283, identifier:g; 284, string:"port"; 285, None; 286, block; 286, 287; 287, return_statement; 288, for_statement; 288, 289; 288, 292; 288, 300; 289, tuple_pattern; 289, 290; 289, 291; 290, identifier:pid; 291, identifier:port; 292, call; 292, 293; 292, 294; 293, identifier:ports_for_pids; 294, argument_list; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:gunicorns; 298, identifier:keys; 299, argument_list; 300, block; 300, 301; 301, if_statement; 301, 302; 301, 305; 302, comparison_operator:in; 302, 303; 302, 304; 303, identifier:pid; 304, identifier:gunicorns; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 313; 308, subscript; 308, 309; 308, 312; 309, subscript; 309, 310; 309, 311; 310, identifier:gunicorns; 311, identifier:pid; 312, string:"port"; 313, identifier:port | def update_gunicorns():
"""
Updates the dict of gunicorn processes. Run the ps command and parse its
output for processes named after gunicorn, building up a dict of gunicorn
processes. When new gunicorns are discovered, run the netstat command to
determine the ports they're serving on.
"""
global tick
tick += 1
if (tick * screen_delay) % ps_delay != 0:
return
tick = 0
for pid in gunicorns:
gunicorns[pid].update({"workers": 0, "mem": 0})
ps = Popen(PS_ARGS, stdout=PIPE).communicate()[0].split("\n")
headings = ps.pop(0).split()
name_col = headings.index(cmd_heading)
num_cols = len(headings) - 1
for row in ps:
cols = row.split(None, num_cols)
if cols and "gunicorn: " in cols[name_col]:
if "gunicorn: worker" in cols[name_col]:
is_worker = True
else:
is_worker = False
if is_worker:
pid = cols[headings.index("PPID")]
else:
pid = cols[headings.index("PID")]
if pid not in gunicorns:
gunicorns[pid] = {"workers": 0, "mem": 0, "port": None, "name":
cols[name_col].strip().split("[",1)[1].split("]",1)[:-1]}
gunicorns[pid]["mem"] += int(cols[headings.index("RSS")])
if is_worker:
gunicorns[pid]["workers"] += 1
# Remove gunicorns that were not found in the process list.
for pid in gunicorns.keys()[:]:
if gunicorns[pid]["workers"] == 0:
del gunicorns[pid]
# Determine ports if any are missing.
if not [g for g in gunicorns.values() if g["port"] is None]:
return
for (pid, port) in ports_for_pids(gunicorns.keys()):
if pid in gunicorns:
gunicorns[pid]["port"] = port |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:handle_keypress; 3, parameters; 3, 4; 4, identifier:screen; 5, block; 5, 6; 5, 8; 5, 10; 5, 27; 6, expression_statement; 6, 7; 7, comment; 8, global_statement; 8, 9; 9, identifier:selected_pid; 10, try_statement; 10, 11; 10, 24; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:key; 15, call; 15, 16; 15, 23; 16, attribute; 16, 17; 16, 22; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:screen; 20, identifier:getkey; 21, argument_list; 22, identifier:upper; 23, argument_list; 24, except_clause; 24, 25; 25, block; 25, 26; 26, return_statement; 27, if_statement; 27, 28; 27, 33; 27, 38; 27, 52; 27, 77; 27, 111; 27, 135; 27, 170; 27, 195; 28, comparison_operator:in; 28, 29; 28, 30; 29, identifier:key; 30, tuple; 30, 31; 30, 32; 31, string:"KEY_DOWN"; 32, string:"J"; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:move_selection; 37, argument_list; 38, elif_clause; 38, 39; 38, 44; 39, comparison_operator:in; 39, 40; 39, 41; 40, identifier:key; 41, tuple; 41, 42; 41, 43; 42, string:"KEY_UP"; 43, string:"K"; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:move_selection; 48, argument_list; 48, 49; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:reverse; 51, True; 52, elif_clause; 52, 53; 52, 58; 53, comparison_operator:in; 53, 54; 53, 55; 54, identifier:key; 55, tuple; 55, 56; 55, 57; 56, string:"A"; 57, string:"+"; 58, block; 58, 59; 58, 64; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:send_signal; 62, argument_list; 62, 63; 63, string:"TTIN"; 64, if_statement; 64, 65; 64, 68; 65, comparison_operator:in; 65, 66; 65, 67; 66, identifier:selected_pid; 67, identifier:gunicorns; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 76; 71, subscript; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:gunicorns; 74, identifier:selected_pid; 75, string:"workers"; 76, integer:0; 77, elif_clause; 77, 78; 77, 83; 78, comparison_operator:in; 78, 79; 78, 80; 79, identifier:key; 80, tuple; 80, 81; 80, 82; 81, string:"W"; 82, string:"-"; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 88; 85, comparison_operator:in; 85, 86; 85, 87; 86, identifier:selected_pid; 87, identifier:gunicorns; 88, block; 88, 89; 89, if_statement; 89, 90; 89, 97; 90, comparison_operator:!=; 90, 91; 90, 96; 91, subscript; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:gunicorns; 94, identifier:selected_pid; 95, string:"workers"; 96, integer:1; 97, block; 97, 98; 97, 103; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:send_signal; 101, argument_list; 101, 102; 102, string:"TTOU"; 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:gunicorns; 108, identifier:selected_pid; 109, string:"workers"; 110, integer:0; 111, elif_clause; 111, 112; 111, 116; 112, comparison_operator:in; 112, 113; 112, 114; 113, identifier:key; 114, tuple; 114, 115; 115, string:"R"; 116, block; 116, 117; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:in; 118, 119; 118, 120; 119, identifier:selected_pid; 120, identifier:gunicorns; 121, block; 121, 122; 121, 127; 121, 131; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:send_signal; 125, argument_list; 125, 126; 126, string:"HUP"; 127, delete_statement; 127, 128; 128, subscript; 128, 129; 128, 130; 129, identifier:gunicorns; 130, identifier:selected_pid; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:selected_pid; 134, None; 135, elif_clause; 135, 136; 135, 140; 136, comparison_operator:in; 136, 137; 136, 138; 137, identifier:key; 138, tuple; 138, 139; 139, string:"T"; 140, block; 140, 141; 141, for_statement; 141, 142; 141, 143; 141, 152; 142, identifier:pid; 143, call; 143, 144; 143, 151; 144, attribute; 144, 145; 144, 150; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:gunicorns; 148, identifier:copy; 149, argument_list; 150, identifier:iterkeys; 151, argument_list; 152, block; 152, 153; 152, 157; 152, 162; 152, 166; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:selected_pid; 156, identifier:pid; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:send_signal; 160, argument_list; 160, 161; 161, string:"HUP"; 162, delete_statement; 162, 163; 163, subscript; 163, 164; 163, 165; 164, identifier:gunicorns; 165, identifier:selected_pid; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:selected_pid; 169, None; 170, elif_clause; 170, 171; 170, 176; 171, comparison_operator:in; 171, 172; 171, 173; 172, identifier:key; 173, tuple; 173, 174; 173, 175; 174, string:"M"; 175, string:"-"; 176, block; 176, 177; 177, if_statement; 177, 178; 177, 181; 178, comparison_operator:in; 178, 179; 178, 180; 179, identifier:selected_pid; 180, identifier:gunicorns; 181, block; 181, 182; 181, 187; 181, 191; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 185; 184, identifier:send_signal; 185, argument_list; 185, 186; 186, string:"QUIT"; 187, delete_statement; 187, 188; 188, subscript; 188, 189; 188, 190; 189, identifier:gunicorns; 190, identifier:selected_pid; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:selected_pid; 194, None; 195, elif_clause; 195, 196; 195, 200; 196, comparison_operator:in; 196, 197; 196, 198; 197, identifier:key; 198, tuple; 198, 199; 199, string:"Q"; 200, block; 200, 201; 201, raise_statement; 201, 202; 202, identifier:KeyboardInterrupt | def handle_keypress(screen):
"""
Check for a key being pressed and handle it if applicable.
"""
global selected_pid
try:
key = screen.getkey().upper()
except:
return
if key in ("KEY_DOWN", "J"):
move_selection()
elif key in ("KEY_UP", "K"):
move_selection(reverse=True)
elif key in ("A", "+"):
send_signal("TTIN")
if selected_pid in gunicorns:
gunicorns[selected_pid]["workers"] = 0
elif key in ("W", "-"):
if selected_pid in gunicorns:
if gunicorns[selected_pid]["workers"] != 1:
send_signal("TTOU")
gunicorns[selected_pid]["workers"] = 0
elif key in ("R",):
if selected_pid in gunicorns:
send_signal("HUP")
del gunicorns[selected_pid]
selected_pid = None
elif key in ("T",):
for pid in gunicorns.copy().iterkeys():
selected_pid = pid
send_signal("HUP")
del gunicorns[selected_pid]
selected_pid = None
elif key in ("M", "-"):
if selected_pid in gunicorns:
send_signal("QUIT")
del gunicorns[selected_pid]
selected_pid = None
elif key in ("Q",):
raise KeyboardInterrupt |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:renderContent; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 20; 5, 21; 5, 22; 5, 44; 5, 75; 5, 76; 5, 82; 5, 152; 5, 172; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:stm; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:stm; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:portCtx; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:portCtx; 20, comment; 21, comment; 22, for_statement; 22, 23; 22, 24; 22, 27; 23, identifier:o; 24, attribute; 24, 25; 24, 26; 25, identifier:stm; 26, identifier:_outputs; 27, block; 27, 28; 28, if_statement; 28, 29; 28, 33; 29, not_operator; 29, 30; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:isVirtual; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:portCtx; 38, identifier:register; 39, argument_list; 39, 40; 39, 41; 40, identifier:o; 41, attribute; 41, 42; 41, 43; 42, identifier:PortType; 43, identifier:OUTPUT; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:canHaveRamPorts; 47, boolean_operator:and; 47, 48; 47, 53; 48, call; 48, 49; 48, 50; 49, identifier:isinstance; 50, argument_list; 50, 51; 50, 52; 51, identifier:stm; 52, identifier:IfContainer; 53, call; 53, 54; 53, 55; 54, identifier:arr_any; 55, argument_list; 55, 56; 55, 65; 56, call; 56, 57; 56, 58; 57, identifier:chain; 58, argument_list; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:stm; 61, identifier:_inputs; 62, attribute; 62, 63; 62, 64; 63, identifier:stm; 64, identifier:_outputs; 65, lambda; 65, 66; 65, 68; 66, lambda_parameters; 66, 67; 67, identifier:s; 68, call; 68, 69; 68, 70; 69, identifier:isinstance; 70, argument_list; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:s; 73, identifier:_dtype; 74, identifier:HArray; 75, comment; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:consumedOutputs; 79, call; 79, 80; 79, 81; 80, identifier:set; 81, argument_list; 82, if_statement; 82, 83; 82, 84; 83, identifier:canHaveRamPorts; 84, block; 84, 85; 85, for_statement; 85, 86; 85, 92; 85, 99; 86, pattern_list; 86, 87; 86, 88; 86, 89; 86, 90; 86, 91; 87, identifier:pType; 88, identifier:memSig; 89, identifier:addrSig; 90, identifier:enSig; 91, identifier:io; 92, call; 92, 93; 92, 94; 93, identifier:detectRamPorts; 94, argument_list; 94, 95; 94, 96; 95, identifier:stm; 96, attribute; 96, 97; 96, 98; 97, identifier:stm; 98, identifier:cond; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 104; 100, 123; 100, 146; 101, comparison_operator:==; 101, 102; 101, 103; 102, identifier:pType; 103, identifier:RAM_READ; 104, block; 104, 105; 104, 116; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:createRamReadNode; 110, argument_list; 110, 111; 110, 112; 110, 113; 110, 114; 110, 115; 111, identifier:memSig; 112, identifier:enSig; 113, identifier:addrSig; 114, identifier:io; 115, True; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:consumedOutputs; 120, identifier:add; 121, argument_list; 121, 122; 122, identifier:io; 123, elif_clause; 123, 124; 123, 127; 124, comparison_operator:==; 124, 125; 124, 126; 125, identifier:pType; 126, identifier:RAM_WRITE; 127, block; 127, 128; 127, 139; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:createRamWriteNode; 133, argument_list; 133, 134; 133, 135; 133, 136; 133, 137; 133, 138; 134, identifier:memSig; 135, identifier:enSig; 136, identifier:addrSig; 137, identifier:io; 138, True; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:consumedOutputs; 143, identifier:add; 144, argument_list; 144, 145; 145, identifier:memSig; 146, else_clause; 146, 147; 147, block; 147, 148; 148, raise_statement; 148, 149; 149, call; 149, 150; 149, 151; 150, identifier:TypeError; 151, argument_list; 152, for_statement; 152, 153; 152, 154; 152, 157; 153, identifier:o; 154, attribute; 154, 155; 154, 156; 155, identifier:stm; 156, identifier:_outputs; 157, block; 157, 158; 158, if_statement; 158, 159; 158, 162; 159, comparison_operator:not; 159, 160; 159, 161; 160, identifier:o; 161, identifier:consumedOutputs; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:renderForSignal; 168, argument_list; 168, 169; 168, 170; 168, 171; 169, identifier:stm; 170, identifier:o; 171, True; 172, if_statement; 172, 173; 172, 177; 173, not_operator; 173, 174; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:isVirtual; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:netCtxs; 184, identifier:applyConnections; 185, argument_list; 185, 186; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:node | def renderContent(self):
"""
Walk from outputs to inputs
for each public signal register port of wrap node if required
lazy load all operator and statement nodes for signals
"""
stm = self.stm
portCtx = self.portCtx
# for each inputs and outputs render expression trees
# walk statements and render muxs and memories
for o in stm._outputs:
if not self.isVirtual:
portCtx.register(o, PortType.OUTPUT)
canHaveRamPorts = isinstance(stm, IfContainer) and arr_any(
chain(stm._inputs, stm._outputs),
lambda s: isinstance(s._dtype, HArray))
# render RAM ports
consumedOutputs = set()
if canHaveRamPorts:
for pType, memSig, addrSig, enSig, io in detectRamPorts(stm, stm.cond):
if pType == RAM_READ:
self.createRamReadNode(memSig, enSig, addrSig,
io, True)
consumedOutputs.add(io)
elif pType == RAM_WRITE:
self.createRamWriteNode(memSig, enSig, addrSig,
io, True)
consumedOutputs.add(memSig)
else:
raise TypeError()
for o in stm._outputs:
if o not in consumedOutputs:
self.renderForSignal(stm, o, True)
if not self.isVirtual:
self.netCtxs.applyConnections(self.node) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:generate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:project; 6, block; 6, 7; 6, 9; 6, 32; 6, 33; 6, 34; 6, 35; 6, 36; 6, 37; 6, 38; 6, 39; 6, 43; 6, 62; 6, 104; 6, 123; 6, 142; 6, 161; 6, 180; 6, 199; 6, 218; 6, 228; 6, 236; 7, expression_statement; 7, 8; 8, comment; 9, for_statement; 9, 10; 9, 11; 9, 14; 10, identifier:assignment; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:s2n_mapping; 14, block; 14, 15; 15, if_statement; 15, 16; 15, 21; 16, comparison_operator:==; 16, 17; 16, 20; 17, subscript; 17, 18; 17, 19; 18, identifier:assignment; 19, string:"ipprefix"; 20, identifier:project; 21, block; 21, 22; 21, 30; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_name; 27, subscript; 27, 28; 27, 29; 28, identifier:assignment; 29, string:"package"; 30, return_statement; 30, 31; 31, identifier:self; 32, comment; 33, comment; 34, comment; 35, comment; 36, comment; 37, comment; 38, comment; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:name; 42, identifier:project; 43, if_statement; 43, 44; 43, 50; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:name; 47, identifier:startswith; 48, argument_list; 48, 49; 49, string:"github.com"; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:name; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:re; 57, identifier:sub; 58, argument_list; 58, 59; 58, 60; 58, 61; 59, string:r"^github\.com"; 60, string:"github"; 61, identifier:name; 62, if_statement; 62, 63; 62, 69; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:name; 66, identifier:startswith; 67, argument_list; 67, 68; 68, string:"gopkg.in"; 69, block; 69, 70; 69, 81; 69, 82; 69, 93; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:name; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:re; 76, identifier:sub; 77, argument_list; 77, 78; 77, 79; 77, 80; 78, string:r"gopkg\.in"; 79, string:"gopkg"; 80, identifier:name; 81, comment; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:name; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:re; 88, identifier:sub; 89, argument_list; 89, 90; 89, 91; 89, 92; 90, string:r"\.v\d"; 91, string:""; 92, identifier:name; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:name; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:re; 99, identifier:sub; 100, argument_list; 100, 101; 100, 102; 100, 103; 101, string:r"/v\d/"; 102, string:"/"; 103, identifier:name; 104, if_statement; 104, 105; 104, 111; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:name; 108, identifier:startswith; 109, argument_list; 109, 110; 110, string:"code.google.com/p"; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:name; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:re; 118, identifier:sub; 119, argument_list; 119, 120; 119, 121; 119, 122; 120, string:r"^code\.google\.com/p"; 121, string:"googlecode"; 122, identifier:name; 123, if_statement; 123, 124; 123, 130; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:name; 127, identifier:startswith; 128, argument_list; 128, 129; 129, string:"golang.org/x"; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:name; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:re; 137, identifier:sub; 138, argument_list; 138, 139; 138, 140; 138, 141; 139, string:r"^golang\.org/x"; 140, string:"golangorg"; 141, identifier:name; 142, if_statement; 142, 143; 142, 149; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:name; 146, identifier:startswith; 147, argument_list; 147, 148; 148, string:"google.golang.org"; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:name; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:re; 156, identifier:sub; 157, argument_list; 157, 158; 157, 159; 157, 160; 158, string:r"^google\.golang\.org"; 159, string:"googlegolangorg"; 160, identifier:name; 161, if_statement; 161, 162; 161, 168; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:name; 165, identifier:startswith; 166, argument_list; 166, 167; 167, string:"bitbucket.org"; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:name; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:re; 175, identifier:sub; 176, argument_list; 176, 177; 176, 178; 176, 179; 177, string:r"^bitbucket\.org"; 178, string:"bitbucket"; 179, identifier:name; 180, if_statement; 180, 181; 180, 187; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:name; 184, identifier:startswith; 185, argument_list; 185, 186; 186, string:"k8s.io"; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:name; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:re; 194, identifier:sub; 195, argument_list; 195, 196; 195, 197; 195, 198; 196, string:r"^k8s\.io"; 197, string:"k8s"; 198, identifier:name; 199, if_statement; 199, 200; 199, 206; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:name; 203, identifier:endswith; 204, argument_list; 204, 205; 205, string:".org"; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:name; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:re; 213, identifier:sub; 214, argument_list; 214, 215; 214, 216; 214, 217; 215, string:r"\.org$"; 216, string:""; 217, identifier:name; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:name; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:name; 224, identifier:replace; 225, argument_list; 225, 226; 225, 227; 226, string:"/"; 227, string:"-"; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:_name; 233, binary_operator:%; 233, 234; 233, 235; 234, string:"golang-%s"; 235, identifier:name; 236, return_statement; 236, 237; 237, identifier:self | def generate(self, project):
"""
Package name construction is based on provider, not on prefix.
Prefix does not have to equal provider_prefix.
"""
for assignment in self.s2n_mapping:
if assignment["ipprefix"] == project:
self._name = assignment["package"]
return self
#
# github.com -> github
# code.google.com/p/ -> googlecode
# golang.org/x/ -> golangorg
# gopkg.in/check.v1 -> gopkg-check
# camlistore.org
#
name = project
if name.startswith("github.com"):
name = re.sub(r"^github\.com", "github", name)
if name.startswith("gopkg.in"):
name = re.sub(r"gopkg\.in", "gopkg", name)
# any version marks?
name = re.sub(r"\.v\d", "", name)
name = re.sub(r"/v\d/", "/", name)
if name.startswith("code.google.com/p"):
name = re.sub(r"^code\.google\.com/p", "googlecode", name)
if name.startswith("golang.org/x"):
name = re.sub(r"^golang\.org/x", "golangorg", name)
if name.startswith("google.golang.org"):
name = re.sub(r"^google\.golang\.org", "googlegolangorg", name)
if name.startswith("bitbucket.org"):
name = re.sub(r"^bitbucket\.org", "bitbucket", name)
if name.startswith("k8s.io"):
name = re.sub(r"^k8s\.io", "k8s", name)
if name.endswith(".org"):
name = re.sub(r"\.org$", "", name)
name = name.replace("/", "-")
self._name = "golang-%s" % name
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_read_elem_nodes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:fid; 6, block; 6, 7; 6, 9; 6, 13; 6, 14; 6, 15; 6, 16; 6, 17; 6, 35; 6, 78; 6, 79; 6, 80; 6, 104; 6, 105; 6, 106; 6, 107; 6, 151; 6, 152; 6, 301; 6, 302; 6, 308; 6, 314; 6, 320; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:nodes; 12, dictionary; 13, comment; 14, comment; 15, comment; 16, comment; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:nodes_raw; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:np; 23, identifier:empty; 24, argument_list; 24, 25; 24, 32; 25, tuple; 25, 26; 25, 31; 26, subscript; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:header; 30, string:'nr_nodes'; 31, integer:3; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:dtype; 34, identifier:float; 35, for_statement; 35, 36; 35, 37; 35, 46; 36, identifier:nr; 37, call; 37, 38; 37, 39; 38, identifier:range; 39, argument_list; 39, 40; 39, 41; 40, integer:0; 41, subscript; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:header; 45, string:'nr_nodes'; 46, block; 46, 47; 46, 59; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:node_line; 50, call; 50, 51; 50, 58; 51, attribute; 51, 52; 51, 57; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:fid; 55, identifier:readline; 56, argument_list; 57, identifier:lstrip; 58, argument_list; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 66; 61, subscript; 61, 62; 61, 63; 61, 64; 62, identifier:nodes_raw; 63, identifier:nr; 64, slice; 64, 65; 65, colon; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:np; 69, identifier:fromstring; 70, argument_list; 70, 71; 70, 72; 70, 75; 71, identifier:node_line; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:dtype; 74, identifier:float; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:sep; 77, string:' '; 78, comment; 79, comment; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 90; 82, subscript; 82, 83; 82, 84; 82, 86; 83, identifier:nodes_raw; 84, slice; 84, 85; 85, colon; 86, slice; 86, 87; 86, 88; 86, 89; 87, integer:1; 88, colon; 89, integer:3; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:round; 94, argument_list; 94, 95; 94, 103; 95, subscript; 95, 96; 95, 97; 95, 99; 96, identifier:nodes_raw; 97, slice; 97, 98; 98, colon; 99, slice; 99, 100; 99, 101; 99, 102; 100, integer:1; 101, colon; 102, integer:3; 103, integer:5; 104, comment; 105, comment; 106, comment; 107, if_statement; 107, 108; 107, 127; 107, 141; 108, parenthesized_expression; 108, 109; 109, comparison_operator:!=; 109, 110; 109, 115; 110, subscript; 110, 111; 110, 112; 110, 114; 111, identifier:nodes_raw; 112, slice; 112, 113; 113, colon; 114, integer:0; 115, call; 115, 116; 115, 117; 116, identifier:list; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:range; 120, argument_list; 120, 121; 120, 122; 121, integer:1; 122, subscript; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:nodes_raw; 125, identifier:shape; 126, integer:0; 127, block; 127, 128; 127, 136; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 135; 130, subscript; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:header; 134, string:'cutmck'; 135, True; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 139; 138, identifier:print; 139, argument_list; 139, 140; 140, string:'This grid was sorted using CutMcK. The nodes were resorted!'; 141, else_clause; 141, 142; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 150; 145, subscript; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:header; 149, string:'cutmck'; 150, False; 151, comment; 152, if_statement; 152, 153; 152, 159; 152, 289; 153, parenthesized_expression; 153, 154; 154, subscript; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:header; 158, string:'cutmck'; 159, block; 159, 160; 159, 169; 159, 185; 159, 257; 159, 258; 159, 266; 159, 272; 159, 278; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:nodes_cutmck; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:np; 166, identifier:empty_like; 167, argument_list; 167, 168; 168, identifier:nodes_raw; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:nodes_cutmck_index; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:np; 175, identifier:zeros; 176, argument_list; 176, 177; 176, 182; 177, subscript; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:nodes_raw; 180, identifier:shape; 181, integer:0; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:dtype; 184, identifier:int; 185, for_statement; 185, 186; 185, 187; 185, 196; 186, identifier:node; 187, call; 187, 188; 187, 189; 188, identifier:range; 189, argument_list; 189, 190; 189, 191; 190, integer:0; 191, subscript; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:header; 195, string:'nr_nodes'; 196, block; 196, 197; 196, 220; 196, 238; 196, 249; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:new_index; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:np; 203, identifier:where; 204, argument_list; 204, 205; 205, comparison_operator:==; 205, 206; 205, 216; 206, call; 206, 207; 206, 214; 207, attribute; 207, 208; 207, 213; 208, subscript; 208, 209; 208, 210; 208, 212; 209, identifier:nodes_raw; 210, slice; 210, 211; 211, colon; 212, integer:0; 213, identifier:astype; 214, argument_list; 214, 215; 215, identifier:int; 216, parenthesized_expression; 216, 217; 217, binary_operator:+; 217, 218; 217, 219; 218, identifier:node; 219, integer:1; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 231; 222, subscript; 222, 223; 222, 224; 222, 227; 223, identifier:nodes_cutmck; 224, subscript; 224, 225; 224, 226; 225, identifier:new_index; 226, integer:0; 227, slice; 227, 228; 227, 229; 227, 230; 228, integer:1; 229, colon; 230, integer:3; 231, subscript; 231, 232; 231, 233; 231, 234; 232, identifier:nodes_raw; 233, identifier:node; 234, slice; 234, 235; 234, 236; 234, 237; 235, integer:1; 236, colon; 237, integer:3; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 246; 240, subscript; 240, 241; 240, 242; 240, 245; 241, identifier:nodes_cutmck; 242, subscript; 242, 243; 242, 244; 243, identifier:new_index; 244, integer:0; 245, integer:0; 246, subscript; 246, 247; 246, 248; 247, identifier:new_index; 248, integer:0; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 254; 251, subscript; 251, 252; 251, 253; 252, identifier:nodes_cutmck_index; 253, identifier:node; 254, subscript; 254, 255; 254, 256; 255, identifier:new_index; 256, integer:0; 257, comment; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:nodes_sorted; 261, subscript; 261, 262; 261, 263; 261, 264; 262, identifier:nodes_cutmck; 263, identifier:nodes_cutmck_index; 264, slice; 264, 265; 265, colon; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 271; 268, subscript; 268, 269; 268, 270; 269, identifier:nodes; 270, string:'presort'; 271, identifier:nodes_cutmck; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 277; 274, subscript; 274, 275; 274, 276; 275, identifier:nodes; 276, string:'cutmck_index'; 277, identifier:nodes_cutmck_index; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 283; 280, subscript; 280, 281; 280, 282; 281, identifier:nodes; 282, string:'rev_cutmck_index'; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:np; 286, identifier:argsort; 287, argument_list; 287, 288; 288, identifier:nodes_cutmck_index; 289, else_clause; 289, 290; 290, block; 290, 291; 290, 295; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:nodes_sorted; 294, identifier:nodes_raw; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 300; 297, subscript; 297, 298; 297, 299; 298, identifier:nodes; 299, string:'presort'; 300, identifier:nodes_raw; 301, comment; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 307; 304, subscript; 304, 305; 304, 306; 305, identifier:nodes; 306, string:'raw'; 307, identifier:nodes_raw; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 313; 310, subscript; 310, 311; 310, 312; 311, identifier:nodes; 312, string:'sorted'; 313, identifier:nodes_sorted; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:self; 318, identifier:nodes; 319, identifier:nodes; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:self; 324, identifier:nr_of_nodes; 325, subscript; 325, 326; 325, 331; 326, attribute; 326, 327; 326, 330; 327, subscript; 327, 328; 327, 329; 328, identifier:nodes; 329, string:'raw'; 330, identifier:shape; 331, integer:0 | def _read_elem_nodes(self, fid):
""" Read the nodes from an opened elem.dat file. Correct for CutMcK
transformations.
We store three typed of nodes in the dict 'nodes':
* "raw" : as read from the elem.dat file
* "presort" : pre-sorted so we can directly read node numbers from
a elec.dat file and use them as indices.
* "sorted" : completely sorted as in the original grid (before any
CutMcK)
For completeness, we also store the following keys:
* "cutmck_index" : Array containing the indices in "presort" to
obtain the "sorted" values:
nodes['sorted'] = nodes['presort'] [nodes['cutmck_index'], :]
* "rev_cutmck_index" : argsort(cutmck_index)
"""
nodes = {}
# # prepare nodes
# nodes_sorted = np.zeros((number_of_nodes, 3), dtype=float)
# nodes = np.zeros((number_of_nodes, 3), dtype=float)
# read in nodes
nodes_raw = np.empty((self.header['nr_nodes'], 3), dtype=float)
for nr in range(0, self.header['nr_nodes']):
node_line = fid.readline().lstrip()
nodes_raw[nr, :] = np.fromstring(
node_line, dtype=float, sep=' ')
# round node coordinates to 5th decimal point. Sometimes this is
# important when we deal with mal-formatted node data
nodes_raw[:, 1:3] = np.round(nodes_raw[:, 1:3], 5)
# check for CutMcK
# The check is based on the first node, but if one node was renumbered,
# so were all the others.
if(nodes_raw[:, 0] != list(range(1, nodes_raw.shape[0]))):
self.header['cutmck'] = True
print(
'This grid was sorted using CutMcK. The nodes were resorted!')
else:
self.header['cutmck'] = False
# Rearrange nodes when CutMcK was used.
if(self.header['cutmck']):
nodes_cutmck = np.empty_like(nodes_raw)
nodes_cutmck_index = np.zeros(nodes_raw.shape[0], dtype=int)
for node in range(0, self.header['nr_nodes']):
new_index = np.where(nodes_raw[:, 0].astype(int) == (node + 1))
nodes_cutmck[new_index[0], 1:3] = nodes_raw[node, 1:3]
nodes_cutmck[new_index[0], 0] = new_index[0]
nodes_cutmck_index[node] = new_index[0]
# sort them
nodes_sorted = nodes_cutmck[nodes_cutmck_index, :]
nodes['presort'] = nodes_cutmck
nodes['cutmck_index'] = nodes_cutmck_index
nodes['rev_cutmck_index'] = np.argsort(nodes_cutmck_index)
else:
nodes_sorted = nodes_raw
nodes['presort'] = nodes_raw
# prepare node dict
nodes['raw'] = nodes_raw
nodes['sorted'] = nodes_sorted
self.nodes = nodes
self.nr_of_nodes = nodes['raw'].shape[0] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:errorhandle; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:resp; 6, block; 6, 7; 6, 9; 6, 204; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 15; 9, 144; 9, 193; 10, comparison_operator:==; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:format; 14, string:'json'; 15, block; 15, 16; 15, 25; 15, 37; 15, 38; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:parsed; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:xmltodict; 22, identifier:parse; 23, argument_list; 23, 24; 24, identifier:resp; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:errors; 28, subscript; 28, 29; 28, 34; 29, subscript; 29, 30; 29, 31; 30, identifier:parsed; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:RESPONSE_TOKEN; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:ERROR_TOKEN; 37, comment; 38, if_statement; 38, 39; 38, 52; 38, 87; 39, boolean_operator:and; 39, 40; 39, 46; 40, comparison_operator:is; 40, 41; 40, 45; 41, call; 41, 42; 41, 43; 42, identifier:type; 43, argument_list; 43, 44; 44, identifier:errors; 45, identifier:list; 46, comparison_operator:>; 46, 47; 46, 51; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, identifier:errors; 51, integer:1; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:messages; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, string:", "; 59, identifier:join; 60, argument_list; 60, 61; 61, list_comprehension; 61, 62; 61, 84; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, string:" "; 65, identifier:join; 66, argument_list; 66, 67; 67, list_comprehension; 67, 68; 67, 75; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, string:"{}: {}"; 71, identifier:format; 72, argument_list; 72, 73; 72, 74; 73, identifier:k; 74, identifier:v; 75, for_in_clause; 75, 76; 75, 79; 76, pattern_list; 76, 77; 76, 78; 77, identifier:k; 78, identifier:v; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:e; 82, identifier:items; 83, argument_list; 84, for_in_clause; 84, 85; 84, 86; 85, identifier:e; 86, identifier:errors; 87, else_clause; 87, 88; 88, block; 88, 89; 88, 109; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:overlimit; 92, call; 92, 93; 92, 94; 93, identifier:any; 94, generator_expression; 94, 95; 94, 102; 95, comparison_operator:in; 95, 96; 95, 97; 96, string:'transaction limit'; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:msg; 100, identifier:lower; 101, argument_list; 102, for_in_clause; 102, 103; 102, 104; 103, identifier:msg; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:errors; 107, identifier:values; 108, argument_list; 109, if_statement; 109, 110; 109, 111; 109, 117; 110, identifier:overlimit; 111, block; 111, 112; 112, raise_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:APILimitExceeded; 115, argument_list; 115, 116; 116, string:"This API key has used up its daily quota of calls."; 117, else_clause; 117, 118; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:messages; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, string:" "; 125, identifier:join; 126, argument_list; 126, 127; 127, list_comprehension; 127, 128; 127, 135; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, string:"{}: {}"; 131, identifier:format; 132, argument_list; 132, 133; 132, 134; 133, identifier:k; 134, identifier:v; 135, for_in_clause; 135, 136; 135, 139; 136, pattern_list; 136, 137; 136, 138; 137, identifier:k; 138, identifier:v; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:errors; 142, identifier:items; 143, argument_list; 144, elif_clause; 144, 145; 144, 150; 145, comparison_operator:==; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:format; 149, string:'xml'; 150, block; 150, 151; 150, 158; 150, 174; 151, import_statement; 151, 152; 152, aliased_import; 152, 153; 152, 157; 153, dotted_name; 153, 154; 153, 155; 153, 156; 154, identifier:xml; 155, identifier:etree; 156, identifier:ElementTree; 157, identifier:ET; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:errors; 161, call; 161, 162; 161, 170; 162, attribute; 162, 163; 162, 169; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:ET; 166, identifier:fromstring; 167, argument_list; 167, 168; 168, identifier:resp; 169, identifier:findall; 170, argument_list; 170, 171; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:ERROR_TOKEN; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:messages; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, string:", "; 180, identifier:join; 181, generator_expression; 181, 182; 181, 190; 182, attribute; 182, 183; 182, 189; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:err; 186, identifier:find; 187, argument_list; 187, 188; 188, string:'msg'; 189, identifier:text; 190, for_in_clause; 190, 191; 190, 192; 191, identifier:err; 192, identifier:errors; 193, else_clause; 193, 194; 194, block; 194, 195; 195, raise_statement; 195, 196; 196, call; 196, 197; 196, 198; 197, identifier:ValueError; 198, argument_list; 198, 199; 199, binary_operator:%; 199, 200; 199, 201; 200, string:"Invalid API response format specified: {}."; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:format; 204, raise_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:BustimeError; 207, argument_list; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, string:"API returned: {}"; 211, identifier:format; 212, argument_list; 212, 213; 213, identifier:messages | def errorhandle(self, resp):
"""Parse API error responses and raise appropriate exceptions."""
if self.format == 'json':
parsed = xmltodict.parse(resp)
errors = parsed[self.RESPONSE_TOKEN][self.ERROR_TOKEN]
# Create list of errors if more than one error response is given
if type(errors) is list and len(errors) > 1:
messages = ", ".join([" ".join(["{}: {}".format(k,v) for k, v in e.items()]) for e in errors])
else:
overlimit = any('transaction limit' in msg.lower() for msg in errors.values())
if overlimit:
raise APILimitExceeded("This API key has used up its daily quota of calls.")
else:
messages = " ".join(["{}: {}".format(k,v) for k, v in errors.items()])
elif self.format == 'xml':
import xml.etree.ElementTree as ET
errors = ET.fromstring(resp).findall(self.ERROR_TOKEN)
messages = ", ".join(err.find('msg').text for err in errors)
else:
raise ValueError("Invalid API response format specified: {}." % self.format)
raise BustimeError("API returned: {}".format(messages)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:cleanup; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:config; 5, identifier:searchstring; 6, default_parameter; 6, 7; 6, 8; 7, identifier:force; 8, False; 9, block; 9, 10; 9, 12; 9, 18; 9, 29; 9, 70; 9, 77; 9, 85; 9, 91; 9, 103; 9, 104; 9, 108; 9, 112; 9, 121; 9, 131; 9, 150; 9, 164; 9, 165; 9, 175; 9, 186; 9, 187; 9, 188; 9, 229; 9, 235; 9, 241; 9, 271; 9, 277; 9, 302; 9, 306; 9, 315; 9, 338; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:repo; 15, attribute; 15, 16; 15, 17; 16, identifier:config; 17, identifier:repo; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:branches_; 21, call; 21, 22; 21, 23; 22, identifier:list; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:find; 26, argument_list; 26, 27; 26, 28; 27, identifier:repo; 28, identifier:searchstring; 29, if_statement; 29, 30; 29, 32; 29, 38; 30, not_operator; 30, 31; 31, identifier:branches_; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:error_out; 36, argument_list; 36, 37; 37, string:"No branches found"; 38, elif_clause; 38, 39; 38, 45; 39, comparison_operator:>; 39, 40; 39, 44; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, identifier:branches_; 44, integer:1; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:error_out; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, string:"More than one branch found.{}"; 53, identifier:format; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, string:"\n\t"; 58, identifier:join; 59, argument_list; 59, 60; 60, binary_operator:+; 60, 61; 60, 63; 61, list:[""]; 61, 62; 62, string:""; 63, list_comprehension; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:x; 66, identifier:name; 67, for_in_clause; 67, 68; 67, 69; 68, identifier:x; 69, identifier:branches_; 70, assert_statement; 70, 71; 71, comparison_operator:==; 71, 72; 71, 76; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, identifier:branches_; 76, integer:1; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:branch_name; 80, attribute; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:branches_; 83, integer:0; 84, identifier:name; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:active_branch; 88, attribute; 88, 89; 88, 90; 89, identifier:repo; 90, identifier:active_branch; 91, if_statement; 91, 92; 91, 97; 92, comparison_operator:==; 92, 93; 92, 94; 93, identifier:branch_name; 94, attribute; 94, 95; 94, 96; 95, identifier:active_branch; 96, identifier:name; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:error_out; 101, argument_list; 101, 102; 102, string:"Can't clean up the current active branch."; 103, comment; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:upstream_remote; 107, None; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:fork_remote; 111, None; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:state; 115, call; 115, 116; 115, 117; 116, identifier:read; 117, argument_list; 117, 118; 118, attribute; 118, 119; 118, 120; 119, identifier:config; 120, identifier:configfile; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:origin_name; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:state; 127, identifier:get; 128, argument_list; 128, 129; 128, 130; 129, string:"ORIGIN_NAME"; 130, string:"origin"; 131, for_statement; 131, 132; 131, 133; 131, 136; 132, identifier:remote; 133, attribute; 133, 134; 133, 135; 134, identifier:repo; 135, identifier:remotes; 136, block; 136, 137; 137, if_statement; 137, 138; 137, 143; 137, 144; 138, comparison_operator:==; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:remote; 141, identifier:name; 142, identifier:origin_name; 143, comment; 144, block; 144, 145; 144, 149; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:upstream_remote; 148, identifier:remote; 149, break_statement; 150, if_statement; 150, 151; 150, 153; 151, not_operator; 151, 152; 152, identifier:upstream_remote; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:error_out; 157, argument_list; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, string:"No remote called {!r} found"; 161, identifier:format; 162, argument_list; 162, 163; 163, identifier:origin_name; 164, comment; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 174; 167, attribute; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:repo; 171, identifier:heads; 172, identifier:master; 173, identifier:checkout; 174, argument_list; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:upstream_remote; 179, identifier:pull; 180, argument_list; 180, 181; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:repo; 184, identifier:heads; 185, identifier:master; 186, comment; 187, comment; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:merged_branches; 191, list_comprehension; 191, 192; 191, 197; 191, 211; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:x; 195, identifier:strip; 196, argument_list; 197, for_in_clause; 197, 198; 197, 199; 198, identifier:x; 199, call; 199, 200; 199, 210; 200, attribute; 200, 201; 200, 209; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:repo; 205, identifier:git; 206, identifier:branch; 207, argument_list; 207, 208; 208, string:"--merged"; 209, identifier:splitlines; 210, argument_list; 211, if_clause; 211, 212; 212, boolean_operator:and; 212, 213; 212, 218; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:x; 216, identifier:strip; 217, argument_list; 218, not_operator; 218, 219; 219, call; 219, 220; 219, 227; 220, attribute; 220, 221; 220, 226; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:x; 224, identifier:strip; 225, argument_list; 226, identifier:startswith; 227, argument_list; 227, 228; 228, string:"*"; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:was_merged; 232, comparison_operator:in; 232, 233; 232, 234; 233, identifier:branch_name; 234, identifier:merged_branches; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:certain; 238, boolean_operator:or; 238, 239; 238, 240; 239, identifier:was_merged; 240, identifier:force; 241, if_statement; 241, 242; 241, 244; 241, 245; 241, 246; 241, 247; 242, not_operator; 242, 243; 243, identifier:certain; 244, comment; 245, comment; 246, comment; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:certain; 251, parenthesized_expression; 251, 252; 252, comparison_operator:!=; 252, 253; 252, 270; 253, call; 253, 254; 253, 269; 254, attribute; 254, 255; 254, 268; 255, call; 255, 256; 255, 267; 256, attribute; 256, 257; 256, 266; 257, call; 257, 258; 257, 259; 258, identifier:input; 259, argument_list; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, string:"Are you certain {} is actually merged? [Y/n] "; 263, identifier:format; 264, argument_list; 264, 265; 265, identifier:branch_name; 266, identifier:lower; 267, argument_list; 268, identifier:strip; 269, argument_list; 270, string:"n"; 271, if_statement; 271, 272; 271, 274; 272, not_operator; 272, 273; 273, identifier:certain; 274, block; 274, 275; 275, return_statement; 275, 276; 276, integer:1; 277, if_statement; 277, 278; 277, 279; 277, 290; 278, identifier:was_merged; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 287; 282, attribute; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:repo; 285, identifier:git; 286, identifier:branch; 287, argument_list; 287, 288; 287, 289; 288, string:"-d"; 289, identifier:branch_name; 290, else_clause; 290, 291; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 299; 294, attribute; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:repo; 297, identifier:git; 298, identifier:branch; 299, argument_list; 299, 300; 299, 301; 300, string:"-D"; 301, identifier:branch_name; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:fork_remote; 305, None; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:state; 309, call; 309, 310; 309, 311; 310, identifier:read; 311, argument_list; 311, 312; 312, attribute; 312, 313; 312, 314; 313, identifier:config; 314, identifier:configfile; 315, for_statement; 315, 316; 315, 317; 315, 320; 316, identifier:remote; 317, attribute; 317, 318; 317, 319; 318, identifier:repo; 319, identifier:remotes; 320, block; 320, 321; 321, if_statement; 321, 322; 321, 332; 322, comparison_operator:==; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:remote; 325, identifier:name; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:state; 329, identifier:get; 330, argument_list; 330, 331; 331, string:"FORK_NAME"; 332, block; 332, 333; 332, 337; 333, expression_statement; 333, 334; 334, assignment; 334, 335; 334, 336; 335, identifier:fork_remote; 336, identifier:remote; 337, break_statement; 338, if_statement; 338, 339; 338, 340; 339, identifier:fork_remote; 340, block; 340, 341; 340, 350; 341, expression_statement; 341, 342; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:fork_remote; 345, identifier:push; 346, argument_list; 346, 347; 347, binary_operator:+; 347, 348; 347, 349; 348, string:":"; 349, identifier:branch_name; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 353; 352, identifier:info_out; 353, argument_list; 353, 354; 354, string:"Remote branch on fork deleted too." | def cleanup(config, searchstring, force=False):
"""Deletes a found branch locally and remotely."""
repo = config.repo
branches_ = list(find(repo, searchstring))
if not branches_:
error_out("No branches found")
elif len(branches_) > 1:
error_out(
"More than one branch found.{}".format(
"\n\t".join([""] + [x.name for x in branches_])
)
)
assert len(branches_) == 1
branch_name = branches_[0].name
active_branch = repo.active_branch
if branch_name == active_branch.name:
error_out("Can't clean up the current active branch.")
# branch_name = active_branch.name
upstream_remote = None
fork_remote = None
state = read(config.configfile)
origin_name = state.get("ORIGIN_NAME", "origin")
for remote in repo.remotes:
if remote.name == origin_name:
# remote.pull()
upstream_remote = remote
break
if not upstream_remote:
error_out("No remote called {!r} found".format(origin_name))
# Check out master
repo.heads.master.checkout()
upstream_remote.pull(repo.heads.master)
# Is this one of the merged branches?!
# XXX I don't know how to do this "nativly" with GitPython.
merged_branches = [
x.strip()
for x in repo.git.branch("--merged").splitlines()
if x.strip() and not x.strip().startswith("*")
]
was_merged = branch_name in merged_branches
certain = was_merged or force
if not certain:
# Need to ask the user.
# XXX This is where we could get smart and compare this branch
# with the master.
certain = (
input("Are you certain {} is actually merged? [Y/n] ".format(branch_name))
.lower()
.strip()
!= "n"
)
if not certain:
return 1
if was_merged:
repo.git.branch("-d", branch_name)
else:
repo.git.branch("-D", branch_name)
fork_remote = None
state = read(config.configfile)
for remote in repo.remotes:
if remote.name == state.get("FORK_NAME"):
fork_remote = remote
break
if fork_remote:
fork_remote.push(":" + branch_name)
info_out("Remote branch on fork deleted too.") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:construct; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:data; 6, block; 6, 7; 6, 9; 6, 13; 6, 17; 6, 18; 6, 97; 6, 103; 6, 104; 6, 147; 6, 153; 6, 154; 6, 176; 6, 177; 6, 190; 6, 191; 6, 195; 6, 199; 6, 243; 6, 252; 6, 261; 6, 262; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:occurrences; 12, dictionary; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:main_occurrences; 16, dictionary; 17, comment; 18, for_statement; 18, 19; 18, 20; 18, 25; 19, identifier:pkg; 20, subscript; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:data; 23, string:"data"; 24, string:"dependencies"; 25, block; 25, 26; 25, 32; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:package; 29, subscript; 29, 30; 29, 31; 30, identifier:pkg; 31, string:"package"; 32, for_statement; 32, 33; 32, 34; 32, 37; 33, identifier:item; 34, subscript; 34, 35; 34, 36; 35, identifier:pkg; 36, string:"dependencies"; 37, block; 37, 38; 37, 44; 37, 74; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:dep; 41, subscript; 41, 42; 41, 43; 42, identifier:item; 43, string:"name"; 44, if_statement; 44, 45; 44, 48; 44, 66; 45, comparison_operator:!=; 45, 46; 45, 47; 46, identifier:package; 47, string:"."; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:deps; 52, call; 52, 53; 52, 54; 53, identifier:map; 54, argument_list; 54, 55; 54, 63; 55, lambda; 55, 56; 55, 58; 56, lambda_parameters; 56, 57; 57, identifier:l; 58, binary_operator:%; 58, 59; 58, 60; 59, string:"%s/%s"; 60, tuple; 60, 61; 60, 62; 61, identifier:package; 62, identifier:l; 63, subscript; 63, 64; 63, 65; 64, identifier:item; 65, string:"location"; 66, else_clause; 66, 67; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:deps; 71, subscript; 71, 72; 71, 73; 72, identifier:item; 73, string:"location"; 74, if_statement; 74, 75; 74, 78; 74, 85; 75, comparison_operator:not; 75, 76; 75, 77; 76, identifier:dep; 77, identifier:occurrences; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:occurrences; 83, identifier:dep; 84, identifier:deps; 85, else_clause; 85, 86; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:occurrences; 91, identifier:dep; 92, binary_operator:+; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:occurrences; 95, identifier:dep; 96, identifier:deps; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:occurrences; 102, identifier:occurrences; 103, comment; 104, for_statement; 104, 105; 104, 106; 104, 111; 105, identifier:main; 106, subscript; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:data; 109, string:"data"; 110, string:"main"; 111, block; 111, 112; 111, 118; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:filename; 115, subscript; 115, 116; 115, 117; 116, identifier:main; 117, string:"filename"; 118, for_statement; 118, 119; 118, 120; 118, 123; 119, identifier:dep; 120, subscript; 120, 121; 120, 122; 121, identifier:main; 122, string:"dependencies"; 123, block; 123, 124; 124, if_statement; 124, 125; 124, 128; 124, 136; 125, comparison_operator:not; 125, 126; 125, 127; 126, identifier:dep; 127, identifier:main_occurrences; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:main_occurrences; 133, identifier:dep; 134, list:[filename]; 134, 135; 135, identifier:filename; 136, else_clause; 136, 137; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:main_occurrences; 143, identifier:dep; 144, identifier:append; 145, argument_list; 145, 146; 146, identifier:filename; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:main_occurrences; 152, identifier:main_occurrences; 153, comment; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:test_directories; 159, call; 159, 160; 159, 161; 160, identifier:sorted; 161, argument_list; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:map; 164, argument_list; 164, 165; 164, 171; 165, lambda; 165, 166; 165, 168; 166, lambda_parameters; 166, 167; 167, identifier:l; 168, subscript; 168, 169; 168, 170; 169, identifier:l; 170, string:"test"; 171, subscript; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:data; 174, string:"data"; 175, string:"tests"; 176, comment; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:provided_packages; 182, call; 182, 183; 182, 184; 183, identifier:sorted; 184, argument_list; 184, 185; 185, subscript; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:data; 188, string:"data"; 189, string:"packages"; 190, comment; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:imported_packages; 194, list:[]; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:imported_native_packages; 198, list:[]; 199, for_statement; 199, 200; 199, 201; 199, 202; 200, identifier:path; 201, identifier:occurrences; 202, block; 202, 203; 202, 218; 203, try_statement; 203, 204; 203, 214; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 212; 207, attribute; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:ipparser; 211, identifier:parse; 212, argument_list; 212, 213; 213, identifier:path; 214, except_clause; 214, 215; 214, 216; 215, identifier:ValueError; 216, block; 216, 217; 217, continue_statement; 218, if_statement; 218, 219; 218, 226; 218, 234; 219, call; 219, 220; 219, 225; 220, attribute; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:ipparser; 224, identifier:isNative; 225, argument_list; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:imported_native_packages; 231, identifier:append; 232, argument_list; 232, 233; 233, identifier:path; 234, else_clause; 234, 235; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:imported_packages; 240, identifier:append; 241, argument_list; 241, 242; 242, identifier:path; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:imported_packages; 248, call; 248, 249; 248, 250; 249, identifier:sorted; 250, argument_list; 250, 251; 251, identifier:imported_packages; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:imported_native_packages; 257, call; 257, 258; 257, 259; 258, identifier:sorted; 259, argument_list; 259, 260; 260, identifier:imported_native_packages; 261, comment; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:main_packages; 267, call; 267, 268; 267, 269; 268, identifier:map; 269, argument_list; 269, 270; 269, 276; 270, lambda; 270, 271; 270, 273; 271, lambda_parameters; 271, 272; 272, identifier:l; 273, subscript; 273, 274; 273, 275; 274, identifier:l; 275, string:"filename"; 276, subscript; 276, 277; 276, 280; 277, subscript; 277, 278; 277, 279; 278, identifier:data; 279, string:"data"; 280, string:"main" | def construct(self, data):
"""Construct info about a project from artefact
:param data: golang-project-packages artefact
:type data: json/dict
"""
occurrences = {}
main_occurrences = {}
# occurrences of devel packages
for pkg in data["data"]["dependencies"]:
package = pkg["package"]
for item in pkg["dependencies"]:
dep = item["name"]
if package != ".":
deps = map(lambda l: "%s/%s" % (package, l), item["location"])
else:
deps = item["location"]
if dep not in occurrences:
occurrences[dep] = deps
else:
occurrences[dep] = occurrences[dep] + deps
self.occurrences = occurrences
# occurrences of main packages
for main in data["data"]["main"]:
filename = main["filename"]
for dep in main["dependencies"]:
if dep not in main_occurrences:
main_occurrences[dep] = [filename]
else:
main_occurrences[dep].append(filename)
self.main_occurrences = main_occurrences
# test directories
self.test_directories = sorted(map(lambda l: l["test"], data["data"]["tests"]))
# provided devel packages
self.provided_packages = sorted(data["data"]["packages"])
# imported paths in devel packages
imported_packages = []
imported_native_packages = []
for path in occurrences:
try:
self.ipparser.parse(path)
except ValueError:
continue
if self.ipparser.isNative():
imported_native_packages.append(path)
else:
imported_packages.append(path)
self.imported_packages = sorted(imported_packages)
self.imported_native_packages = sorted(imported_native_packages)
# main packages
self.main_packages = map(lambda l: l["filename"], data["data"]["main"]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:td_is_finished; 3, parameters; 3, 4; 4, identifier:tomodir; 5, block; 5, 6; 5, 8; 5, 20; 5, 21; 5, 22; 5, 23; 5, 125; 5, 126; 5, 127; 5, 128; 5, 301; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:is_tomodir; 12, argument_list; 12, 13; 13, identifier:tomodir; 14, block; 14, 15; 15, raise_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:Exception; 18, argument_list; 18, 19; 19, string:'Supplied directory is not a tomodir!'; 20, comment; 21, comment; 22, comment; 23, if_statement; 23, 24; 23, 114; 23, 119; 24, parenthesized_expression; 24, 25; 25, boolean_operator:and; 25, 26; 25, 100; 26, boolean_operator:and; 26, 27; 26, 86; 27, boolean_operator:and; 27, 28; 27, 72; 28, boolean_operator:and; 28, 29; 28, 58; 29, boolean_operator:and; 29, 30; 29, 44; 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, binary_operator:+; 37, 38; 37, 43; 38, binary_operator:+; 38, 39; 38, 40; 39, identifier:tomodir; 40, attribute; 40, 41; 40, 42; 41, identifier:os; 42, identifier:sep; 43, string:'config/config.dat'; 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:isfile; 50, argument_list; 50, 51; 51, binary_operator:+; 51, 52; 51, 57; 52, binary_operator:+; 52, 53; 52, 54; 53, identifier:tomodir; 54, attribute; 54, 55; 54, 56; 55, identifier:os; 56, identifier:sep; 57, string:'rho/rho.dat'; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:os; 62, identifier:path; 63, identifier:isfile; 64, argument_list; 64, 65; 65, binary_operator:+; 65, 66; 65, 71; 66, binary_operator:+; 66, 67; 66, 68; 67, identifier:tomodir; 68, attribute; 68, 69; 68, 70; 69, identifier:os; 70, identifier:sep; 71, string:'grid/elem.dat'; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:os; 76, identifier:path; 77, identifier:isfile; 78, argument_list; 78, 79; 79, binary_operator:+; 79, 80; 79, 85; 80, binary_operator:+; 80, 81; 80, 82; 81, identifier:tomodir; 82, attribute; 82, 83; 82, 84; 83, identifier:os; 84, identifier:sep; 85, string:'grid/elec.dat'; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:os; 90, identifier:path; 91, identifier:isfile; 92, argument_list; 92, 93; 93, binary_operator:+; 93, 94; 93, 99; 94, binary_operator:+; 94, 95; 94, 96; 95, identifier:tomodir; 96, attribute; 96, 97; 96, 98; 97, identifier:os; 98, identifier:sep; 99, string:'exe/crmod.cfg'; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:os; 104, identifier:path; 105, identifier:isfile; 106, argument_list; 106, 107; 107, binary_operator:+; 107, 108; 107, 113; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:tomodir; 110, attribute; 110, 111; 110, 112; 111, identifier:os; 112, identifier:sep; 113, string:'mod/volt.dat'; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:crmod_is_finished; 118, True; 119, else_clause; 119, 120; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:crmod_is_finished; 124, False; 125, comment; 126, comment; 127, comment; 128, if_statement; 128, 129; 128, 219; 128, 295; 129, parenthesized_expression; 129, 130; 130, boolean_operator:and; 130, 131; 130, 205; 131, boolean_operator:and; 131, 132; 131, 191; 132, boolean_operator:and; 132, 133; 132, 177; 133, boolean_operator:and; 133, 134; 133, 163; 134, boolean_operator:and; 134, 135; 134, 149; 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:isfile; 141, argument_list; 141, 142; 142, binary_operator:+; 142, 143; 142, 148; 143, binary_operator:+; 143, 144; 143, 145; 144, identifier:tomodir; 145, attribute; 145, 146; 145, 147; 146, identifier:os; 147, identifier:sep; 148, string:'grid/elem.dat'; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:os; 153, identifier:path; 154, identifier:isfile; 155, argument_list; 155, 156; 156, binary_operator:+; 156, 157; 156, 162; 157, binary_operator:+; 157, 158; 157, 159; 158, identifier:tomodir; 159, attribute; 159, 160; 159, 161; 160, identifier:os; 161, identifier:sep; 162, string:'grid/elec.dat'; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:os; 167, identifier:path; 168, identifier:isfile; 169, argument_list; 169, 170; 170, binary_operator:+; 170, 171; 170, 176; 171, binary_operator:+; 171, 172; 171, 173; 172, identifier:tomodir; 173, attribute; 173, 174; 173, 175; 174, identifier:os; 175, identifier:sep; 176, string:'exe/crtomo.cfg'; 177, call; 177, 178; 177, 183; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:os; 181, identifier:path; 182, identifier:isfile; 183, argument_list; 183, 184; 184, binary_operator:+; 184, 185; 184, 190; 185, binary_operator:+; 185, 186; 185, 187; 186, identifier:tomodir; 187, attribute; 187, 188; 187, 189; 188, identifier:os; 189, identifier:sep; 190, string:'inv/inv.ctr'; 191, call; 191, 192; 191, 197; 192, attribute; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:os; 195, identifier:path; 196, identifier:isfile; 197, argument_list; 197, 198; 198, binary_operator:+; 198, 199; 198, 204; 199, binary_operator:+; 199, 200; 199, 201; 200, identifier:tomodir; 201, attribute; 201, 202; 201, 203; 202, identifier:os; 203, identifier:sep; 204, string:'inv/run.ctr'; 205, call; 205, 206; 205, 211; 206, attribute; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:os; 209, identifier:path; 210, identifier:isfile; 211, argument_list; 211, 212; 212, binary_operator:+; 212, 213; 212, 218; 213, binary_operator:+; 213, 214; 213, 215; 214, identifier:tomodir; 215, attribute; 215, 216; 215, 217; 216, identifier:os; 217, identifier:sep; 218, string:'mod/volt.dat'; 219, block; 219, 220; 220, with_statement; 220, 221; 220, 237; 221, with_clause; 221, 222; 222, with_item; 222, 223; 223, as_pattern; 223, 224; 223, 235; 224, call; 224, 225; 224, 226; 225, identifier:open; 226, argument_list; 226, 227; 226, 234; 227, binary_operator:+; 227, 228; 227, 233; 228, binary_operator:+; 228, 229; 228, 230; 229, identifier:tomodir; 230, attribute; 230, 231; 230, 232; 231, identifier:os; 232, identifier:sep; 233, string:'inv/run.ctr'; 234, string:'r'; 235, as_pattern_target; 235, 236; 236, identifier:fid; 237, block; 237, 238; 237, 246; 237, 250; 237, 251; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:lines; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:fid; 244, identifier:readlines; 245, argument_list; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:crtomo_is_finished; 249, False; 250, comment; 251, for_statement; 251, 252; 251, 253; 251, 259; 252, identifier:line; 253, subscript; 253, 254; 253, 255; 254, identifier:lines; 255, slice; 255, 256; 255, 258; 256, unary_operator:-; 256, 257; 257, integer:5; 258, colon; 259, block; 259, 260; 259, 268; 259, 277; 259, 286; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:test_line; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:line; 266, identifier:strip; 267, argument_list; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:regex; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:re; 274, identifier:compile; 275, argument_list; 275, 276; 276, string:'CPU'; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:result; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:regex; 283, identifier:match; 284, argument_list; 284, 285; 285, identifier:test_line; 286, if_statement; 286, 287; 286, 290; 287, comparison_operator:is; 287, 288; 287, 289; 288, identifier:result; 289, None; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:crtomo_is_finished; 294, True; 295, else_clause; 295, 296; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 300; 299, identifier:crtomo_is_finished; 300, False; 301, return_statement; 301, 302; 302, expression_list; 302, 303; 302, 304; 303, identifier:crmod_is_finished; 304, identifier:crtomo_is_finished | def td_is_finished(tomodir):
"""Return the state of modeling and inversion for a given tomodir. The
result does not take into account sensitivities or potentials, as
optionally generated by CRMod.
Parameters
----------
tomodir: string
Directory to check
Returns
-------
crmod_is_finished: bool
True if a successful CRMod result is contained in the tomodir
directory.
crtomo_is_finished: bool
True if a successful CRTomo inversion results is contained in the
tomodir directory.
"""
if not is_tomodir(tomodir):
raise Exception('Supplied directory is not a tomodir!')
# crmod finished is determined by:
# config.dat/rho.dat/crmod.cfg are present
# volt.dat is present
if(os.path.isfile(tomodir + os.sep + 'config/config.dat') and
os.path.isfile(tomodir + os.sep + 'rho/rho.dat') and
os.path.isfile(tomodir + os.sep + 'grid/elem.dat') and
os.path.isfile(tomodir + os.sep + 'grid/elec.dat') and
os.path.isfile(tomodir + os.sep + 'exe/crmod.cfg') and
os.path.isfile(tomodir + os.sep + 'mod/volt.dat')):
crmod_is_finished = True
else:
crmod_is_finished = False
# crtomo is finished if
# crtomo.cfg/volt.dat/elem.dat/elec.dat are present
# inv/run.ctr contains the word "CPU" in the last line
if(os.path.isfile(tomodir + os.sep + 'grid/elem.dat') and
os.path.isfile(tomodir + os.sep + 'grid/elec.dat') and
os.path.isfile(tomodir + os.sep + 'exe/crtomo.cfg') and
os.path.isfile(tomodir + os.sep + 'inv/inv.ctr') and
os.path.isfile(tomodir + os.sep + 'inv/run.ctr') and
os.path.isfile(tomodir + os.sep + 'mod/volt.dat')):
with open(tomodir + os.sep + 'inv/run.ctr', 'r') as fid:
lines = fid.readlines()
crtomo_is_finished = False
# check the last 5 lines
for line in lines[-5:]:
test_line = line.strip()
regex = re.compile('CPU')
result = regex.match(test_line)
if result is not None:
crtomo_is_finished = True
else:
crtomo_is_finished = False
return crmod_is_finished, crtomo_is_finished |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sipdir_is_finished; 3, parameters; 3, 4; 4, identifier:sipdir; 5, block; 5, 6; 5, 8; 5, 20; 5, 44; 5, 61; 5, 65; 5, 69; 5, 98; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:is_sipdir; 12, argument_list; 12, 13; 13, identifier:sipdir; 14, block; 14, 15; 15, raise_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:Exception; 18, argument_list; 18, 19; 19, string:'Directory is not a valid SIP directory!'; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:subdirs_raw; 23, call; 23, 24; 23, 25; 24, identifier:sorted; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:glob; 29, identifier:glob; 30, argument_list; 30, 31; 31, binary_operator:+; 31, 32; 31, 43; 32, binary_operator:+; 32, 33; 32, 40; 33, binary_operator:+; 33, 34; 33, 39; 34, binary_operator:+; 34, 35; 34, 36; 35, identifier:sipdir; 36, attribute; 36, 37; 36, 38; 37, identifier:os; 38, identifier:sep; 39, string:'invmod'; 40, attribute; 40, 41; 40, 42; 41, identifier:os; 42, identifier:sep; 43, string:'*'; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:subdirs; 47, list_comprehension; 47, 48; 47, 49; 47, 52; 48, identifier:x; 49, for_in_clause; 49, 50; 49, 51; 50, identifier:x; 51, identifier:subdirs_raw; 52, if_clause; 52, 53; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:os; 57, identifier:path; 58, identifier:isdir; 59, argument_list; 59, 60; 60, identifier:x; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:crmod_finished; 64, True; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:crtomo_finished; 68, True; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:subdir; 71, identifier:subdirs; 72, block; 72, 73; 72, 82; 72, 90; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, pattern_list; 75, 76; 75, 77; 76, identifier:subcrmod; 77, identifier:subcrtomo; 78, call; 78, 79; 78, 80; 79, identifier:td_is_finished; 80, argument_list; 80, 81; 81, identifier:subdir; 82, if_statement; 82, 83; 82, 85; 83, not_operator; 83, 84; 84, identifier:subcrmod; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:crmod_finished; 89, False; 90, if_statement; 90, 91; 90, 93; 91, not_operator; 91, 92; 92, identifier:subcrtomo; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:crtomo_finished; 97, False; 98, return_statement; 98, 99; 99, expression_list; 99, 100; 99, 101; 100, identifier:crmod_finished; 101, identifier:crtomo_finished | def sipdir_is_finished(sipdir):
"""Return the state of modeling and inversion for a given SIP dir. The
result does not take into account sensitivities or potentials, as
optionally generated by CRMod.
Parameters
----------
sipdir: string
Directory to check
Returns
-------
crmod_is_finished: bool
True if all tomodirs of this SIP directory contain finished modeling
results.
crtomo_is_finished: bool
True if all tomodirs of this SIP directory contain finished inversion
results.
"""
if not is_sipdir(sipdir):
raise Exception('Directory is not a valid SIP directory!')
subdirs_raw = sorted(glob.glob(sipdir + os.sep + 'invmod' + os.sep + '*'))
subdirs = [x for x in subdirs_raw if os.path.isdir(x)]
crmod_finished = True
crtomo_finished = True
for subdir in subdirs:
subcrmod, subcrtomo = td_is_finished(subdir)
if not subcrmod:
crmod_finished = False
if not subcrtomo:
crtomo_finished = False
return crmod_finished, crtomo_finished |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 38; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:source_ids; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:seniority; 10, string:"all"; 11, default_parameter; 11, 12; 11, 13; 12, identifier:stage; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:date_start; 16, string:"1494539999"; 17, default_parameter; 17, 18; 17, 19; 18, identifier:date_end; 19, identifier:TIMESTAMP_NOW; 20, default_parameter; 20, 21; 20, 22; 21, identifier:filter_id; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:page; 25, integer:1; 26, default_parameter; 26, 27; 26, 28; 27, identifier:limit; 28, integer:30; 29, default_parameter; 29, 30; 29, 31; 30, identifier:sort_by; 31, string:'ranking'; 32, default_parameter; 32, 33; 32, 34; 33, identifier:filter_reference; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:order_by; 37, None; 38, block; 38, 39; 38, 41; 38, 45; 38, 55; 38, 65; 38, 77; 38, 89; 38, 98; 38, 107; 38, 116; 38, 125; 38, 139; 38, 148; 38, 154; 38, 166; 39, expression_statement; 39, 40; 40, comment; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:query_params; 44, dictionary; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:query_params; 49, string:"date_end"; 50, call; 50, 51; 50, 52; 51, identifier:_validate_timestamp; 52, argument_list; 52, 53; 52, 54; 53, identifier:date_end; 54, string:"date_end"; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:query_params; 59, string:"date_start"; 60, call; 60, 61; 60, 62; 61, identifier:_validate_timestamp; 62, argument_list; 62, 63; 62, 64; 63, identifier:date_start; 64, string:"date_start"; 65, if_statement; 65, 66; 65, 67; 66, identifier:filter_id; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:query_params; 72, string:"filter_id"; 73, call; 73, 74; 73, 75; 74, identifier:_validate_filter_id; 75, argument_list; 75, 76; 76, identifier:filter_id; 77, if_statement; 77, 78; 77, 79; 78, identifier:filter_reference; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:query_params; 84, string:"filter_reference"; 85, call; 85, 86; 85, 87; 86, identifier:_validate_filter_reference; 87, argument_list; 87, 88; 88, identifier:filter_reference; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:query_params; 93, string:"limit"; 94, call; 94, 95; 94, 96; 95, identifier:_validate_limit; 96, argument_list; 96, 97; 97, identifier:limit; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:query_params; 102, string:"page"; 103, call; 103, 104; 103, 105; 104, identifier:_validate_page; 105, argument_list; 105, 106; 106, identifier:page; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:query_params; 111, string:"seniority"; 112, call; 112, 113; 112, 114; 113, identifier:_validate_seniority; 114, argument_list; 114, 115; 115, identifier:seniority; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:query_params; 120, string:"sort_by"; 121, call; 121, 122; 121, 123; 122, identifier:_validate_sort_by; 123, argument_list; 123, 124; 124, identifier:sort_by; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:query_params; 129, string:"source_ids"; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:json; 133, identifier:dumps; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:_validate_source_ids; 137, argument_list; 137, 138; 138, identifier:source_ids; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:query_params; 143, string:"stage"; 144, call; 144, 145; 144, 146; 145, identifier:_validate_stage; 146, argument_list; 146, 147; 147, identifier:stage; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:query_params; 152, string:"order_by"; 153, identifier:order_by; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:response; 157, call; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:client; 162, identifier:get; 163, argument_list; 163, 164; 163, 165; 164, string:"profiles"; 165, identifier:query_params; 166, return_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:response; 170, identifier:json; 171, argument_list | def list(self, source_ids=None, seniority="all", stage=None,
date_start="1494539999", date_end=TIMESTAMP_NOW, filter_id=None,
page=1, limit=30, sort_by='ranking', filter_reference=None, order_by=None):
"""
Retreive all profiles that match the query param.
Args:
date_end: <string> REQUIRED (default to timestamp of now)
profiles' last date of reception
date_start: <string> REQUIRED (default to "1494539999")
profiles' first date of reception
filter_id: <string>
limit: <int> (default to 30)
number of fetched profiles/page
page: <int> REQUIRED default to 1
number of the page associated to the pagination
seniority: <string> defaut to "all"
profiles' seniority ("all", "senior", "junior")
sort_by: <string>
source_ids: <array of strings> REQUIRED
stage: <string>
Returns
Retrieve the profiles data as <dict>
"""
query_params = {}
query_params["date_end"] = _validate_timestamp(date_end, "date_end")
query_params["date_start"] = _validate_timestamp(date_start, "date_start")
if filter_id:
query_params["filter_id"] = _validate_filter_id(filter_id)
if filter_reference:
query_params["filter_reference"] = _validate_filter_reference(filter_reference)
query_params["limit"] = _validate_limit(limit)
query_params["page"] = _validate_page(page)
query_params["seniority"] = _validate_seniority(seniority)
query_params["sort_by"] = _validate_sort_by(sort_by)
query_params["source_ids"] = json.dumps(_validate_source_ids(source_ids))
query_params["stage"] = _validate_stage(stage)
query_params["order_by"] = order_by
response = self.client.get("profiles", query_params)
return response.json() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:iterdupes; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:compare; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:filt; 10, None; 11, block; 11, 12; 11, 14; 11, 24; 11, 28; 11, 29; 11, 33; 11, 34; 11, 48; 12, expression_statement; 12, 13; 13, string:''' streaming item iterator with low overhead duplicate file detection
Parameters:
- compare compare function between files (defaults to md5sum)
'''; 14, if_statement; 14, 15; 14, 17; 15, not_operator; 15, 16; 16, identifier:compare; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:compare; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:md5sum; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:seen_siz; 27, dictionary; 28, comment; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:seen_sum; 32, dictionary; 33, comment; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:size_func; 37, lambda; 37, 38; 37, 40; 38, lambda_parameters; 38, 39; 39, identifier:x; 40, attribute; 40, 41; 40, 47; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:os; 44, identifier:stat; 45, argument_list; 45, 46; 46, identifier:x; 47, identifier:st_size; 48, for_statement; 48, 49; 48, 52; 48, 66; 49, tuple_pattern; 49, 50; 49, 51; 50, identifier:fsize; 51, identifier:f; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:iteritems; 56, argument_list; 56, 57; 56, 60; 56, 63; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:want_dirs; 59, False; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:func; 62, identifier:size_func; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:filt; 65, identifier:filt; 66, block; 66, 67; 67, if_statement; 67, 68; 67, 71; 67, 72; 67, 80; 68, comparison_operator:not; 68, 69; 68, 70; 69, identifier:fsize; 70, identifier:seen_siz; 71, comment; 72, block; 72, 73; 72, 79; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:seen_siz; 77, identifier:fsize; 78, identifier:f; 79, continue_statement; 80, else_clause; 80, 81; 81, block; 81, 82; 81, 125; 81, 126; 81, 133; 82, if_statement; 82, 83; 82, 86; 82, 87; 83, subscript; 83, 84; 83, 85; 84, identifier:seen_siz; 85, identifier:fsize; 86, comment; 87, block; 87, 88; 87, 97; 87, 119; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:chksum; 91, call; 91, 92; 91, 93; 92, identifier:compare; 93, argument_list; 93, 94; 94, subscript; 94, 95; 94, 96; 95, identifier:seen_siz; 96, identifier:fsize; 97, if_statement; 97, 98; 97, 101; 97, 109; 98, comparison_operator:in; 98, 99; 98, 100; 99, identifier:chksum; 100, identifier:seen_sum; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, yield; 103, 104; 104, tuple; 104, 105; 104, 106; 105, identifier:chksum; 106, subscript; 106, 107; 106, 108; 107, identifier:seen_siz; 108, identifier:fsize; 109, else_clause; 109, 110; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:seen_sum; 115, identifier:chksum; 116, subscript; 116, 117; 116, 118; 117, identifier:seen_siz; 118, identifier:fsize; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, subscript; 121, 122; 121, 123; 122, identifier:seen_siz; 123, identifier:fsize; 124, None; 125, comment; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:chksum; 129, call; 129, 130; 129, 131; 130, identifier:compare; 131, argument_list; 131, 132; 132, identifier:f; 133, if_statement; 133, 134; 133, 137; 133, 138; 133, 162; 134, comparison_operator:in; 134, 135; 134, 136; 135, identifier:chksum; 136, identifier:seen_sum; 137, comment; 138, block; 138, 139; 138, 157; 139, if_statement; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:seen_sum; 142, identifier:chksum; 143, block; 143, 144; 143, 151; 144, expression_statement; 144, 145; 145, yield; 145, 146; 146, tuple; 146, 147; 146, 148; 147, identifier:chksum; 148, subscript; 148, 149; 148, 150; 149, identifier:seen_sum; 150, identifier:chksum; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:seen_sum; 155, identifier:chksum; 156, None; 157, expression_statement; 157, 158; 158, yield; 158, 159; 159, tuple; 159, 160; 159, 161; 160, identifier:chksum; 161, identifier:f; 162, else_clause; 162, 163; 162, 164; 163, comment; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:seen_sum; 169, identifier:chksum; 170, identifier:f | def iterdupes(self, compare=None, filt=None):
''' streaming item iterator with low overhead duplicate file detection
Parameters:
- compare compare function between files (defaults to md5sum)
'''
if not compare: compare = self.md5sum
seen_siz = {} ## store size -> first seen filename
seen_sum = {} ## store chksum -> first seen filename
size_func = lambda x: os.stat(x).st_size
for (fsize, f) in self.iteritems(want_dirs=False, func=size_func, filt=filt):
if fsize not in seen_siz: ## state 1: no previous size collisions
seen_siz[fsize] = f
continue
else:
if seen_siz[fsize]: ## state 2: defined key => str (initial, unscanned path)
chksum = compare(seen_siz[fsize])
if chksum in seen_sum: yield (chksum, seen_siz[fsize])
else: seen_sum[chksum] = seen_siz[fsize]
seen_siz[fsize] = None
## state 3: defined key => None (already scanned path, no-op)
chksum = compare(f)
if chksum in seen_sum:
## if it's a dupe, check if the first one was ever yielded then yield
if seen_sum[chksum]:
yield (chksum, seen_sum[chksum])
seen_sum[chksum] = None
yield (chksum, f)
else:
## if not, set the initial filename
seen_sum[chksum] = f |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 1, 10; 2, function_name:objects_to_root; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:objects; 6, type; 6, 7; 7, identifier:List; 8, type; 8, 9; 9, identifier:Root; 10, block; 10, 11; 10, 13; 10, 124; 10, 200; 10, 207; 11, expression_statement; 11, 12; 12, comment; 13, function_definition; 13, 14; 13, 15; 13, 20; 13, 22; 14, function_name:_to_tree; 15, parameters; 15, 16; 16, typed_parameter; 16, 17; 16, 18; 17, identifier:objs; 18, type; 18, 19; 19, identifier:Iterable; 20, type; 20, 21; 21, identifier:Dict; 22, block; 22, 23; 22, 25; 22, 29; 22, 122; 23, expression_statement; 23, 24; 24, comment; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:path_tree; 28, dictionary; 29, for_statement; 29, 30; 29, 31; 29, 32; 30, identifier:obj; 31, identifier:objs; 32, block; 32, 33; 32, 44; 32, 61; 32, 68; 32, 72; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:is_dir; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:obj; 40, identifier:key; 41, identifier:endswith; 42, argument_list; 42, 43; 43, string:'/'; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:chunks; 47, list_comprehension; 47, 48; 47, 49; 47, 59; 48, identifier:chunk; 49, for_in_clause; 49, 50; 49, 51; 50, identifier:chunk; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:obj; 55, identifier:key; 56, identifier:split; 57, argument_list; 57, 58; 58, string:'/'; 59, if_clause; 59, 60; 60, identifier:chunk; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:chunk_count; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, identifier:chunks; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:tmp; 71, identifier:path_tree; 72, for_statement; 72, 73; 72, 76; 72, 80; 73, pattern_list; 73, 74; 73, 75; 74, identifier:i; 75, identifier:chunk; 76, call; 76, 77; 76, 78; 77, identifier:enumerate; 78, argument_list; 78, 79; 79, identifier:chunks; 80, block; 80, 81; 80, 89; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:is_last_chunk; 84, comparison_operator:==; 84, 85; 84, 86; 85, identifier:i; 86, binary_operator:-; 86, 87; 86, 88; 87, identifier:chunk_count; 88, integer:1; 89, if_statement; 89, 90; 89, 94; 89, 101; 90, boolean_operator:and; 90, 91; 90, 92; 91, identifier:is_last_chunk; 92, not_operator; 92, 93; 93, identifier:is_dir; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:tmp; 99, identifier:chunk; 100, identifier:obj; 101, else_clause; 101, 102; 101, 103; 102, comment; 103, block; 103, 104; 103, 116; 104, if_statement; 104, 105; 104, 108; 104, 109; 105, comparison_operator:not; 105, 106; 105, 107; 106, identifier:chunk; 107, identifier:tmp; 108, comment; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:tmp; 114, identifier:chunk; 115, dictionary; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:tmp; 119, subscript; 119, 120; 119, 121; 120, identifier:tmp; 121, identifier:chunk; 122, return_statement; 122, 123; 123, identifier:path_tree; 124, function_definition; 124, 125; 124, 126; 124, 141; 124, 143; 125, function_name:_to_entity; 126, parameters; 126, 127; 126, 131; 127, typed_parameter; 127, 128; 127, 129; 128, identifier:key; 129, type; 129, 130; 130, identifier:str; 131, typed_parameter; 131, 132; 131, 133; 132, identifier:value; 133, type; 133, 134; 134, generic_type; 134, 135; 134, 136; 135, identifier:Union; 136, type_parameter; 136, 137; 136, 139; 137, type; 137, 138; 138, identifier:Dict; 139, type; 139, 140; 140, identifier:Any; 141, type; 141, 142; 142, identifier:Entity; 143, block; 143, 144; 143, 146; 143, 175; 144, expression_statement; 144, 145; 145, comment; 146, if_statement; 146, 147; 146, 152; 147, call; 147, 148; 147, 149; 148, identifier:isinstance; 149, argument_list; 149, 150; 149, 151; 150, identifier:value; 151, identifier:dict; 152, block; 152, 153; 153, return_statement; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:Directory; 156, argument_list; 156, 157; 156, 158; 157, identifier:key; 158, dictionary_comprehension; 158, 159; 158, 166; 159, pair; 159, 160; 159, 161; 160, identifier:key_; 161, call; 161, 162; 161, 163; 162, identifier:_to_entity; 163, argument_list; 163, 164; 163, 165; 164, identifier:key_; 165, identifier:value_; 166, for_in_clause; 166, 167; 166, 170; 167, pattern_list; 167, 168; 167, 169; 168, identifier:key_; 169, identifier:value_; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:value; 173, identifier:items; 174, argument_list; 175, return_statement; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:File; 178, argument_list; 178, 179; 178, 189; 178, 192; 179, attribute; 179, 180; 179, 188; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:pathlib; 183, identifier:PurePath; 184, argument_list; 184, 185; 185, attribute; 185, 186; 185, 187; 186, identifier:value; 187, identifier:key; 188, identifier:name; 189, attribute; 189, 190; 189, 191; 190, identifier:value; 191, identifier:size; 192, call; 192, 193; 192, 198; 193, attribute; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:value; 196, identifier:e_tag; 197, identifier:strip; 198, argument_list; 198, 199; 199, string:'"'; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:tree; 203, call; 203, 204; 203, 205; 204, identifier:_to_tree; 205, argument_list; 205, 206; 206, identifier:objects; 207, return_statement; 207, 208; 208, call; 208, 209; 208, 210; 209, identifier:Root; 210, argument_list; 210, 211; 211, dictionary_comprehension; 211, 212; 211, 226; 212, pair; 212, 213; 212, 221; 213, attribute; 213, 214; 213, 220; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:pathlib; 217, identifier:PurePath; 218, argument_list; 218, 219; 219, identifier:key; 220, identifier:name; 221, call; 221, 222; 221, 223; 222, identifier:_to_entity; 223, argument_list; 223, 224; 223, 225; 224, identifier:key; 225, identifier:value; 226, for_in_clause; 226, 227; 226, 230; 227, pattern_list; 227, 228; 227, 229; 228, identifier:key; 229, identifier:value; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:tree; 233, identifier:items; 234, argument_list | def objects_to_root(objects: List) -> Root:
"""
Convert a list of s3 ObjectSummaries into a directory tree.
:param objects: The list of objects, e.g. the result of calling
`.objects.all()` on a bucket.
:return: The tree structure, contained within a root node.
"""
def _to_tree(objs: Iterable) -> Dict:
"""
Build a tree structure from a flat list of objects.
:param objs: The raw iterable of S3 `ObjectSummary`s, as returned by a
bucket listing.
:return: The listing as a nested dictionary where keys are directory
and file names. The values of directories will in turn be a
dict. The values of keys representing files will be the
`ObjectSummary` instance.
"""
path_tree = {}
for obj in objs:
is_dir = obj.key.endswith('/')
chunks = [chunk for chunk in obj.key.split('/') if chunk]
chunk_count = len(chunks)
tmp = path_tree
for i, chunk in enumerate(chunks):
is_last_chunk = i == chunk_count - 1
if is_last_chunk and not is_dir:
tmp[chunk] = obj
else:
# must be a directory
if chunk not in tmp:
# it doesn't exist - create it
tmp[chunk] = {}
tmp = tmp[chunk]
return path_tree
def _to_entity(key: str, value: Union[Dict, Any]) -> Entity:
"""
Turn a nested dictionary representing an S3 bucket into the correct
`Entity` object.
:param key: The name of the entity.
:param value: If the entity is a directory, the nested dict
representing its contents. Otherwise, the `ObjectSummary`
instance representing the file.
:return: The entity representing the entity name and value pair.
"""
if isinstance(value, dict):
return Directory(
key,
{key_: _to_entity(key_, value_)
for key_, value_ in value.items()})
return File(pathlib.PurePath(value.key).name, value.size,
value.e_tag.strip('"'))
tree = _to_tree(objects)
return Root({pathlib.PurePath(key).name: _to_entity(key, value)
for key, value in tree.items()}) |
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:xml_file; 6, block; 6, 7; 6, 9; 6, 13; 6, 34; 6, 337; 7, expression_statement; 7, 8; 8, string:"Get a list of parsed recipes from BeerXML input"; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:recipes; 12, list:[]; 13, with_statement; 13, 14; 13, 24; 14, with_clause; 14, 15; 15, with_item; 15, 16; 16, as_pattern; 16, 17; 16, 22; 17, call; 17, 18; 17, 19; 18, identifier:open; 19, argument_list; 19, 20; 19, 21; 20, identifier:xml_file; 21, string:"rt"; 22, as_pattern_target; 22, 23; 23, identifier:f; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:tree; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:ElementTree; 31, identifier:parse; 32, argument_list; 32, 33; 33, identifier:f; 34, for_statement; 34, 35; 34, 36; 34, 41; 35, identifier:recipeNode; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:tree; 39, identifier:iter; 40, argument_list; 41, block; 41, 42; 41, 55; 41, 61; 41, 68; 42, if_statement; 42, 43; 42, 53; 43, comparison_operator:!=; 43, 44; 43, 52; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:to_lower; 48, argument_list; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:recipeNode; 51, identifier:tag; 52, string:"recipe"; 53, block; 53, 54; 54, continue_statement; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:recipe; 58, call; 58, 59; 58, 60; 59, identifier:Recipe; 60, argument_list; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:recipes; 65, identifier:append; 66, argument_list; 66, 67; 67, identifier:recipe; 68, for_statement; 68, 69; 68, 70; 68, 74; 69, identifier:recipeProperty; 70, call; 70, 71; 70, 72; 71, identifier:list; 72, argument_list; 72, 73; 73, identifier:recipeNode; 74, block; 74, 75; 74, 86; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:tag_name; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:to_lower; 82, argument_list; 82, 83; 83, attribute; 83, 84; 83, 85; 84, identifier:recipeProperty; 85, identifier:tag; 86, if_statement; 86, 87; 86, 90; 86, 121; 86, 156; 86, 191; 86, 226; 86, 251; 86, 327; 87, comparison_operator:==; 87, 88; 87, 89; 88, identifier:tag_name; 89, string:"fermentables"; 90, block; 90, 91; 91, for_statement; 91, 92; 91, 93; 91, 97; 92, identifier:fermentable_node; 93, call; 93, 94; 93, 95; 94, identifier:list; 95, argument_list; 95, 96; 96, identifier:recipeProperty; 97, block; 97, 98; 97, 104; 97, 112; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:fermentable; 101, call; 101, 102; 101, 103; 102, identifier:Fermentable; 103, argument_list; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:nodes_to_object; 109, argument_list; 109, 110; 109, 111; 110, identifier:fermentable_node; 111, identifier:fermentable; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 119; 114, attribute; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:recipe; 117, identifier:fermentables; 118, identifier:append; 119, argument_list; 119, 120; 120, identifier:fermentable; 121, elif_clause; 121, 122; 121, 125; 122, comparison_operator:==; 122, 123; 122, 124; 123, identifier:tag_name; 124, string:"yeasts"; 125, block; 125, 126; 126, for_statement; 126, 127; 126, 128; 126, 132; 127, identifier:yeast_node; 128, call; 128, 129; 128, 130; 129, identifier:list; 130, argument_list; 130, 131; 131, identifier:recipeProperty; 132, block; 132, 133; 132, 139; 132, 147; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:yeast; 136, call; 136, 137; 136, 138; 137, identifier:Yeast; 138, argument_list; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:nodes_to_object; 144, argument_list; 144, 145; 144, 146; 145, identifier:yeast_node; 146, identifier:yeast; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:recipe; 152, identifier:yeasts; 153, identifier:append; 154, argument_list; 154, 155; 155, identifier:yeast; 156, elif_clause; 156, 157; 156, 160; 157, comparison_operator:==; 157, 158; 157, 159; 158, identifier:tag_name; 159, string:"hops"; 160, block; 160, 161; 161, for_statement; 161, 162; 161, 163; 161, 167; 162, identifier:hop_node; 163, call; 163, 164; 163, 165; 164, identifier:list; 165, argument_list; 165, 166; 166, identifier:recipeProperty; 167, block; 167, 168; 167, 174; 167, 182; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:hop; 171, call; 171, 172; 171, 173; 172, identifier:Hop; 173, argument_list; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:nodes_to_object; 179, argument_list; 179, 180; 179, 181; 180, identifier:hop_node; 181, identifier:hop; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:recipe; 187, identifier:hops; 188, identifier:append; 189, argument_list; 189, 190; 190, identifier:hop; 191, elif_clause; 191, 192; 191, 195; 192, comparison_operator:==; 192, 193; 192, 194; 193, identifier:tag_name; 194, string:"miscs"; 195, block; 195, 196; 196, for_statement; 196, 197; 196, 198; 196, 202; 197, identifier:misc_node; 198, call; 198, 199; 198, 200; 199, identifier:list; 200, argument_list; 200, 201; 201, identifier:recipeProperty; 202, block; 202, 203; 202, 209; 202, 217; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:misc; 206, call; 206, 207; 206, 208; 207, identifier:Misc; 208, argument_list; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:nodes_to_object; 214, argument_list; 214, 215; 214, 216; 215, identifier:misc_node; 216, identifier:misc; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 224; 219, attribute; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:recipe; 222, identifier:miscs; 223, identifier:append; 224, argument_list; 224, 225; 225, identifier:misc; 226, elif_clause; 226, 227; 226, 230; 227, comparison_operator:==; 227, 228; 227, 229; 228, identifier:tag_name; 229, string:"style"; 230, block; 230, 231; 230, 237; 230, 243; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:style; 234, call; 234, 235; 234, 236; 235, identifier:Style; 236, argument_list; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:recipe; 241, identifier:style; 242, identifier:style; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:nodes_to_object; 248, argument_list; 248, 249; 248, 250; 249, identifier:recipeProperty; 250, identifier:style; 251, elif_clause; 251, 252; 251, 255; 252, comparison_operator:==; 252, 253; 252, 254; 253, identifier:tag_name; 254, string:"mash"; 255, block; 255, 256; 256, for_statement; 256, 257; 256, 258; 256, 262; 257, identifier:mash_node; 258, call; 258, 259; 258, 260; 259, identifier:list; 260, argument_list; 260, 261; 261, identifier:recipeProperty; 262, block; 262, 263; 262, 269; 262, 275; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:mash; 266, call; 266, 267; 266, 268; 267, identifier:Mash; 268, argument_list; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:recipe; 273, identifier:mash; 274, identifier:mash; 275, if_statement; 275, 276; 275, 286; 275, 317; 276, comparison_operator:==; 276, 277; 276, 285; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:to_lower; 281, argument_list; 281, 282; 282, attribute; 282, 283; 282, 284; 283, identifier:mash_node; 284, identifier:tag; 285, string:"mash_steps"; 286, block; 286, 287; 287, for_statement; 287, 288; 287, 289; 287, 293; 288, identifier:mash_step_node; 289, call; 289, 290; 289, 291; 290, identifier:list; 291, argument_list; 291, 292; 292, identifier:mash_node; 293, block; 293, 294; 293, 300; 293, 308; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:mash_step; 297, call; 297, 298; 297, 299; 298, identifier:MashStep; 299, argument_list; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:self; 304, identifier:nodes_to_object; 305, argument_list; 305, 306; 305, 307; 306, identifier:mash_step_node; 307, identifier:mash_step; 308, expression_statement; 308, 309; 309, call; 309, 310; 309, 315; 310, attribute; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:mash; 313, identifier:steps; 314, identifier:append; 315, argument_list; 315, 316; 316, identifier:mash_step; 317, else_clause; 317, 318; 318, block; 318, 319; 319, expression_statement; 319, 320; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:self; 323, identifier:nodes_to_object; 324, argument_list; 324, 325; 324, 326; 325, identifier:mash_node; 326, identifier:mash; 327, else_clause; 327, 328; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:node_to_object; 334, argument_list; 334, 335; 334, 336; 335, identifier:recipeProperty; 336, identifier:recipe; 337, return_statement; 337, 338; 338, identifier:recipes | def parse(self, xml_file):
"Get a list of parsed recipes from BeerXML input"
recipes = []
with open(xml_file, "rt") as f:
tree = ElementTree.parse(f)
for recipeNode in tree.iter():
if self.to_lower(recipeNode.tag) != "recipe":
continue
recipe = Recipe()
recipes.append(recipe)
for recipeProperty in list(recipeNode):
tag_name = self.to_lower(recipeProperty.tag)
if tag_name == "fermentables":
for fermentable_node in list(recipeProperty):
fermentable = Fermentable()
self.nodes_to_object(fermentable_node, fermentable)
recipe.fermentables.append(fermentable)
elif tag_name == "yeasts":
for yeast_node in list(recipeProperty):
yeast = Yeast()
self.nodes_to_object(yeast_node, yeast)
recipe.yeasts.append(yeast)
elif tag_name == "hops":
for hop_node in list(recipeProperty):
hop = Hop()
self.nodes_to_object(hop_node, hop)
recipe.hops.append(hop)
elif tag_name == "miscs":
for misc_node in list(recipeProperty):
misc = Misc()
self.nodes_to_object(misc_node, misc)
recipe.miscs.append(misc)
elif tag_name == "style":
style = Style()
recipe.style = style
self.nodes_to_object(recipeProperty, style)
elif tag_name == "mash":
for mash_node in list(recipeProperty):
mash = Mash()
recipe.mash = mash
if self.to_lower(mash_node.tag) == "mash_steps":
for mash_step_node in list(mash_node):
mash_step = MashStep()
self.nodes_to_object(mash_step_node, mash_step)
mash.steps.append(mash_step)
else:
self.nodes_to_object(mash_node, mash)
else:
self.node_to_object(recipeProperty, recipe)
return recipes |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_parse_extra; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:fp; 6, block; 6, 7; 6, 9; 6, 13; 6, 17; 6, 24; 6, 158; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:comment; 12, string:''; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:section; 16, string:''; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:fp; 21, identifier:seek; 22, argument_list; 22, 23; 23, integer:0; 24, for_statement; 24, 25; 24, 26; 24, 27; 25, identifier:line; 26, identifier:fp; 27, block; 27, 28; 27, 36; 27, 48; 27, 64; 27, 154; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:line; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:line; 34, identifier:rstrip; 35, argument_list; 36, if_statement; 36, 37; 36, 39; 37, not_operator; 37, 38; 38, identifier:line; 39, block; 39, 40; 39, 47; 40, if_statement; 40, 41; 40, 42; 41, identifier:comment; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, augmented_assignment:+=; 44, 45; 44, 46; 45, identifier:comment; 46, string:'\n'; 47, continue_statement; 48, if_statement; 48, 49; 48, 55; 48, 56; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:line; 52, identifier:startswith; 53, argument_list; 53, 54; 54, string:'#'; 55, comment; 56, block; 56, 57; 56, 63; 57, expression_statement; 57, 58; 58, augmented_assignment:+=; 58, 59; 58, 60; 59, identifier:comment; 60, binary_operator:+; 60, 61; 60, 62; 61, identifier:line; 62, string:'\n'; 63, continue_statement; 64, if_statement; 64, 65; 64, 71; 64, 72; 64, 104; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:line; 68, identifier:startswith; 69, argument_list; 69, 70; 70, string:'['; 71, comment; 72, block; 72, 73; 72, 82; 72, 89; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:section; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:line; 79, identifier:strip; 80, argument_list; 80, 81; 81, string:'[]'; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:_add_dot_key; 87, argument_list; 87, 88; 88, identifier:section; 89, if_statement; 89, 90; 89, 91; 90, identifier:comment; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 99; 94, subscript; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:_comments; 98, identifier:section; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:comment; 102, identifier:rstrip; 103, argument_list; 104, elif_clause; 104, 105; 104, 111; 104, 112; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:CONFIG_KEY_RE; 108, identifier:match; 109, argument_list; 109, 110; 110, identifier:line; 111, comment; 112, block; 112, 113; 112, 129; 112, 137; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:key; 116, call; 116, 117; 116, 128; 117, attribute; 117, 118; 117, 127; 118, subscript; 118, 119; 118, 126; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:line; 122, identifier:split; 123, argument_list; 123, 124; 123, 125; 124, string:'='; 125, integer:1; 126, integer:0; 127, identifier:strip; 128, argument_list; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:_add_dot_key; 134, argument_list; 134, 135; 134, 136; 135, identifier:section; 136, identifier:key; 137, if_statement; 137, 138; 137, 139; 138, identifier:comment; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 149; 142, subscript; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:_comments; 146, tuple; 146, 147; 146, 148; 147, identifier:section; 148, identifier:key; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:comment; 152, identifier:rstrip; 153, argument_list; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:comment; 157, string:''; 158, if_statement; 158, 159; 158, 160; 159, identifier:comment; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 170; 163, subscript; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:_comments; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:LAST_COMMENT_KEY; 170, identifier:comment | def _parse_extra(self, fp):
""" Parse and store the config comments and create maps for dot notion lookup """
comment = ''
section = ''
fp.seek(0)
for line in fp:
line = line.rstrip()
if not line:
if comment:
comment += '\n'
continue
if line.startswith('#'): # Comment
comment += line + '\n'
continue
if line.startswith('['): # Section
section = line.strip('[]')
self._add_dot_key(section)
if comment:
self._comments[section] = comment.rstrip()
elif CONFIG_KEY_RE.match(line): # Config
key = line.split('=', 1)[0].strip()
self._add_dot_key(section, key)
if comment:
self._comments[(section, key)] = comment.rstrip()
comment = ''
if comment:
self._comments[self.LAST_COMMENT_KEY] = comment |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 43; 1, 47; 2, function_name:_sample_action_fluent; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 15; 3, 23; 3, 33; 3, 39; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:name; 7, type; 7, 8; 8, identifier:str; 9, typed_parameter; 9, 10; 9, 11; 10, identifier:dtype; 11, type; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:tf; 14, identifier:DType; 15, typed_parameter; 15, 16; 15, 17; 16, identifier:size; 17, type; 17, 18; 18, generic_type; 18, 19; 18, 20; 19, identifier:Sequence; 20, type_parameter; 20, 21; 21, type; 21, 22; 22, identifier:int; 23, typed_parameter; 23, 24; 23, 25; 24, identifier:constraints; 25, type; 25, 26; 26, generic_type; 26, 27; 26, 28; 27, identifier:Dict; 28, type_parameter; 28, 29; 28, 31; 29, type; 29, 30; 30, identifier:str; 31, type; 31, 32; 32, identifier:Constraints; 33, typed_parameter; 33, 34; 33, 35; 34, identifier:default_value; 35, type; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:tf; 38, identifier:Tensor; 39, typed_parameter; 39, 40; 39, 41; 40, identifier:prob; 41, type; 41, 42; 42, identifier:float; 43, type; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:tf; 46, identifier:Tensor; 47, block; 47, 48; 47, 50; 47, 62; 47, 364; 47, 387; 47, 398; 48, expression_statement; 48, 49; 49, string:'''Samples the action fluent with given `name`, `dtype`, and `size`.
With probability `prob` it chooses the action fluent `default_value`,
with probability 1-`prob` it samples the fluent w.r.t. its `constraints`.
Args:
name (str): The name of the action fluent.
dtype (tf.DType): The data type of the action fluent.
size (Sequence[int]): The size and shape of the action fluent.
constraints (Dict[str, Tuple[Optional[TensorFluent], Optional[TensorFluent]]]): The bounds for each action fluent.
default_value (tf.Tensor): The default value for the action fluent.
prob (float): A probability measure.
Returns:
tf.Tensor: A tensor for sampling the action fluent.
'''; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:shape; 53, binary_operator:+; 53, 54; 53, 58; 54, list:[self.batch_size]; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:batch_size; 58, call; 58, 59; 58, 60; 59, identifier:list; 60, argument_list; 60, 61; 61, identifier:size; 62, if_statement; 62, 63; 62, 68; 62, 283; 62, 326; 63, comparison_operator:==; 63, 64; 63, 65; 64, identifier:dtype; 65, attribute; 65, 66; 65, 67; 66, identifier:tf; 67, identifier:float32; 68, block; 68, 69; 68, 78; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:bounds; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:constraints; 75, identifier:get; 76, argument_list; 76, 77; 77, identifier:name; 78, if_statement; 78, 79; 78, 82; 78, 121; 79, comparison_operator:is; 79, 80; 79, 81; 80, identifier:bounds; 81, None; 82, block; 82, 83; 82, 96; 82, 112; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, pattern_list; 85, 86; 85, 87; 86, identifier:low; 87, identifier:high; 88, expression_list; 88, 89; 88, 93; 89, unary_operator:-; 89, 90; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:MAX_REAL_VALUE; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:MAX_REAL_VALUE; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:dist; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:tf; 103, identifier:distributions; 104, identifier:Uniform; 105, argument_list; 105, 106; 105, 109; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:low; 108, identifier:low; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:high; 111, identifier:high; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:sampled_fluent; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:dist; 118, identifier:sample; 119, argument_list; 119, 120; 120, identifier:shape; 121, else_clause; 121, 122; 122, block; 122, 123; 122, 129; 122, 149; 122, 171; 122, 192; 122, 208; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, pattern_list; 125, 126; 125, 127; 126, identifier:low; 127, identifier:high; 128, identifier:bounds; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:batch; 132, boolean_operator:or; 132, 133; 132, 141; 133, parenthesized_expression; 133, 134; 134, boolean_operator:and; 134, 135; 134, 138; 135, comparison_operator:is; 135, 136; 135, 137; 136, identifier:low; 137, None; 138, attribute; 138, 139; 138, 140; 139, identifier:low; 140, identifier:batch; 141, parenthesized_expression; 141, 142; 142, boolean_operator:and; 142, 143; 142, 146; 143, comparison_operator:is; 143, 144; 143, 145; 144, identifier:high; 145, None; 146, attribute; 146, 147; 146, 148; 147, identifier:high; 148, identifier:batch; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:low; 152, conditional_expression:if; 152, 153; 152, 164; 152, 167; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:tf; 156, identifier:cast; 157, argument_list; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:low; 160, identifier:tensor; 161, attribute; 161, 162; 161, 163; 162, identifier:tf; 163, identifier:float32; 164, comparison_operator:is; 164, 165; 164, 166; 165, identifier:low; 166, None; 167, unary_operator:-; 167, 168; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:MAX_REAL_VALUE; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:high; 174, conditional_expression:if; 174, 175; 174, 186; 174, 189; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:tf; 178, identifier:cast; 179, argument_list; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:high; 182, identifier:tensor; 183, attribute; 183, 184; 183, 185; 184, identifier:tf; 185, identifier:float32; 186, comparison_operator:is; 186, 187; 186, 188; 187, identifier:high; 188, None; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:MAX_REAL_VALUE; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:dist; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:tf; 199, identifier:distributions; 200, identifier:Uniform; 201, argument_list; 201, 202; 201, 205; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:low; 204, identifier:low; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:high; 207, identifier:high; 208, if_statement; 208, 209; 208, 210; 208, 219; 208, 272; 209, identifier:batch; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:sampled_fluent; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:dist; 217, identifier:sample; 218, argument_list; 219, elif_clause; 219, 220; 219, 235; 220, boolean_operator:or; 220, 221; 220, 228; 221, call; 221, 222; 221, 223; 222, identifier:isinstance; 223, argument_list; 223, 224; 223, 225; 224, identifier:low; 225, attribute; 225, 226; 225, 227; 226, identifier:tf; 227, identifier:Tensor; 228, call; 228, 229; 228, 230; 229, identifier:isinstance; 230, argument_list; 230, 231; 230, 232; 231, identifier:high; 232, attribute; 232, 233; 232, 234; 233, identifier:tf; 234, identifier:Tensor; 235, block; 235, 236; 236, if_statement; 236, 237; 236, 252; 236, 265; 237, comparison_operator:==; 237, 238; 237, 248; 238, call; 238, 239; 238, 247; 239, attribute; 239, 240; 239, 246; 240, attribute; 240, 241; 240, 245; 241, parenthesized_expression; 241, 242; 242, binary_operator:+; 242, 243; 242, 244; 243, identifier:low; 244, identifier:high; 245, identifier:shape; 246, identifier:as_list; 247, argument_list; 248, call; 248, 249; 248, 250; 249, identifier:list; 250, argument_list; 250, 251; 251, identifier:size; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:sampled_fluent; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:dist; 259, identifier:sample; 260, argument_list; 260, 261; 261, list:[self.batch_size]; 261, 262; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:batch_size; 265, else_clause; 265, 266; 266, block; 266, 267; 267, raise_statement; 267, 268; 268, call; 268, 269; 268, 270; 269, identifier:ValueError; 270, argument_list; 270, 271; 271, string:'bounds are not compatible with action fluent.'; 272, else_clause; 272, 273; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:sampled_fluent; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:dist; 280, identifier:sample; 281, argument_list; 281, 282; 282, identifier:shape; 283, elif_clause; 283, 284; 283, 289; 284, comparison_operator:==; 284, 285; 284, 286; 285, identifier:dtype; 286, attribute; 286, 287; 286, 288; 287, identifier:tf; 288, identifier:int32; 289, block; 289, 290; 289, 299; 289, 317; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:logits; 293, binary_operator:*; 293, 294; 293, 296; 294, list:[1.0]; 294, 295; 295, float:1.0; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:MAX_INT_VALUE; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:dist; 302, call; 302, 303; 302, 308; 303, attribute; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:tf; 306, identifier:distributions; 307, identifier:Categorical; 308, argument_list; 308, 309; 308, 312; 309, keyword_argument; 309, 310; 309, 311; 310, identifier:logits; 311, identifier:logits; 312, keyword_argument; 312, 313; 312, 314; 313, identifier:dtype; 314, attribute; 314, 315; 314, 316; 315, identifier:tf; 316, identifier:int32; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:sampled_fluent; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:dist; 323, identifier:sample; 324, argument_list; 324, 325; 325, identifier:shape; 326, elif_clause; 326, 327; 326, 332; 327, comparison_operator:==; 327, 328; 327, 329; 328, identifier:dtype; 329, attribute; 329, 330; 329, 331; 330, identifier:tf; 331, identifier:bool; 332, block; 332, 333; 332, 337; 332, 355; 333, expression_statement; 333, 334; 334, assignment; 334, 335; 334, 336; 335, identifier:probs; 336, float:0.5; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 340; 339, identifier:dist; 340, call; 340, 341; 340, 346; 341, attribute; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:tf; 344, identifier:distributions; 345, identifier:Bernoulli; 346, argument_list; 346, 347; 346, 350; 347, keyword_argument; 347, 348; 347, 349; 348, identifier:probs; 349, identifier:probs; 350, keyword_argument; 350, 351; 350, 352; 351, identifier:dtype; 352, attribute; 352, 353; 352, 354; 353, identifier:tf; 354, identifier:bool; 355, expression_statement; 355, 356; 356, assignment; 356, 357; 356, 358; 357, identifier:sampled_fluent; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:dist; 361, identifier:sample; 362, argument_list; 362, 363; 363, identifier:shape; 364, expression_statement; 364, 365; 365, assignment; 365, 366; 365, 367; 366, identifier:select_default; 367, call; 367, 368; 367, 383; 368, attribute; 368, 369; 368, 382; 369, call; 369, 370; 369, 375; 370, attribute; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:tf; 373, identifier:distributions; 374, identifier:Bernoulli; 375, argument_list; 375, 376; 375, 377; 376, identifier:prob; 377, keyword_argument; 377, 378; 377, 379; 378, identifier:dtype; 379, attribute; 379, 380; 379, 381; 380, identifier:tf; 381, identifier:bool; 382, identifier:sample; 383, argument_list; 383, 384; 384, attribute; 384, 385; 384, 386; 385, identifier:self; 386, identifier:batch_size; 387, expression_statement; 387, 388; 388, assignment; 388, 389; 388, 390; 389, identifier:action_fluent; 390, call; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:tf; 393, identifier:where; 394, argument_list; 394, 395; 394, 396; 394, 397; 395, identifier:select_default; 396, identifier:default_value; 397, identifier:sampled_fluent; 398, return_statement; 398, 399; 399, identifier:action_fluent | def _sample_action_fluent(self,
name: str,
dtype: tf.DType,
size: Sequence[int],
constraints: Dict[str, Constraints],
default_value: tf.Tensor,
prob: float) -> tf.Tensor:
'''Samples the action fluent with given `name`, `dtype`, and `size`.
With probability `prob` it chooses the action fluent `default_value`,
with probability 1-`prob` it samples the fluent w.r.t. its `constraints`.
Args:
name (str): The name of the action fluent.
dtype (tf.DType): The data type of the action fluent.
size (Sequence[int]): The size and shape of the action fluent.
constraints (Dict[str, Tuple[Optional[TensorFluent], Optional[TensorFluent]]]): The bounds for each action fluent.
default_value (tf.Tensor): The default value for the action fluent.
prob (float): A probability measure.
Returns:
tf.Tensor: A tensor for sampling the action fluent.
'''
shape = [self.batch_size] + list(size)
if dtype == tf.float32:
bounds = constraints.get(name)
if bounds is None:
low, high = -self.MAX_REAL_VALUE, self.MAX_REAL_VALUE
dist = tf.distributions.Uniform(low=low, high=high)
sampled_fluent = dist.sample(shape)
else:
low, high = bounds
batch = (low is not None and low.batch) or (high is not None and high.batch)
low = tf.cast(low.tensor, tf.float32) if low is not None else -self.MAX_REAL_VALUE
high = tf.cast(high.tensor, tf.float32) if high is not None else self.MAX_REAL_VALUE
dist = tf.distributions.Uniform(low=low, high=high)
if batch:
sampled_fluent = dist.sample()
elif isinstance(low, tf.Tensor) or isinstance(high, tf.Tensor):
if (low+high).shape.as_list() == list(size):
sampled_fluent = dist.sample([self.batch_size])
else:
raise ValueError('bounds are not compatible with action fluent.')
else:
sampled_fluent = dist.sample(shape)
elif dtype == tf.int32:
logits = [1.0] * self.MAX_INT_VALUE
dist = tf.distributions.Categorical(logits=logits, dtype=tf.int32)
sampled_fluent = dist.sample(shape)
elif dtype == tf.bool:
probs = 0.5
dist = tf.distributions.Bernoulli(probs=probs, dtype=tf.bool)
sampled_fluent = dist.sample(shape)
select_default = tf.distributions.Bernoulli(prob, dtype=tf.bool).sample(self.batch_size)
action_fluent = tf.where(select_default, default_value, sampled_fluent)
return action_fluent |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 1, 31; 2, function_name:UnitToLNode; 3, parameters; 3, 4; 3, 8; 3, 17; 3, 26; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:u; 6, type; 6, 7; 7, identifier:Unit; 8, typed_default_parameter; 8, 9; 8, 10; 8, 16; 9, identifier:node; 10, type; 10, 11; 11, generic_type; 11, 12; 11, 13; 12, identifier:Optional; 13, type_parameter; 13, 14; 14, type; 14, 15; 15, identifier:LNode; 16, None; 17, typed_default_parameter; 17, 18; 17, 19; 17, 25; 18, identifier:toL; 19, type; 19, 20; 20, generic_type; 20, 21; 20, 22; 21, identifier:Optional; 22, type_parameter; 22, 23; 23, type; 23, 24; 24, identifier:dict; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:optimizations; 28, list:[]; 29, type; 29, 30; 30, identifier:LNode; 31, block; 31, 32; 31, 34; 31, 43; 31, 71; 31, 75; 31, 76; 31, 83; 31, 84; 31, 114; 31, 115; 31, 133; 31, 134; 31, 146; 31, 147; 31, 208; 31, 209; 31, 278; 31, 285; 31, 294; 31, 302; 31, 400; 32, expression_statement; 32, 33; 33, comment; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:toL; 37, None; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:toL; 42, dictionary; 43, if_statement; 43, 44; 43, 47; 43, 65; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:node; 46, None; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:root; 51, call; 51, 52; 51, 53; 52, identifier:LNode; 53, argument_list; 53, 54; 53, 59; 53, 62; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:name; 56, attribute; 56, 57; 56, 58; 57, identifier:u; 58, identifier:_name; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:originObj; 61, identifier:u; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:node2lnode; 64, identifier:toL; 65, else_clause; 65, 66; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:root; 70, identifier:node; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:stmPorts; 74, dictionary; 75, comment; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:netCtx; 79, call; 79, 80; 79, 81; 80, identifier:NetCtxs; 81, argument_list; 81, 82; 82, identifier:root; 83, comment; 84, for_statement; 84, 85; 84, 86; 84, 89; 85, identifier:su; 86, attribute; 86, 87; 86, 88; 87, identifier:u; 88, identifier:_units; 89, block; 89, 90; 89, 106; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:n; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:root; 96, identifier:addNode; 97, argument_list; 97, 98; 97, 103; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:name; 100, attribute; 100, 101; 100, 102; 101, identifier:su; 102, identifier:_name; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:originObj; 105, identifier:su; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:UnitToLNode; 109, argument_list; 109, 110; 109, 111; 109, 112; 109, 113; 110, identifier:su; 111, identifier:n; 112, identifier:toL; 113, identifier:optimizations; 114, comment; 115, for_statement; 115, 116; 115, 117; 115, 122; 116, identifier:stm; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:u; 120, identifier:_ctx; 121, identifier:statements; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:n; 126, call; 126, 127; 126, 128; 127, identifier:addStmAsLNode; 128, argument_list; 128, 129; 128, 130; 128, 131; 128, 132; 129, identifier:root; 130, identifier:stm; 131, identifier:stmPorts; 132, identifier:netCtx; 133, comment; 134, for_statement; 134, 135; 134, 136; 134, 139; 135, identifier:intf; 136, attribute; 136, 137; 136, 138; 137, identifier:u; 138, identifier:_interfaces; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:addPort; 143, argument_list; 143, 144; 143, 145; 144, identifier:root; 145, identifier:intf; 146, comment; 147, for_statement; 147, 148; 147, 149; 147, 154; 148, identifier:stm; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:u; 152, identifier:_ctx; 153, identifier:statements; 154, block; 154, 155; 154, 165; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:n; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:toL; 161, identifier:get; 162, argument_list; 162, 163; 162, 164; 163, identifier:stm; 164, None; 165, if_statement; 165, 166; 165, 169; 166, comparison_operator:is; 166, 167; 166, 168; 167, identifier:n; 168, None; 169, block; 169, 170; 169, 192; 169, 202; 170, if_statement; 170, 171; 170, 176; 170, 177; 170, 182; 171, call; 171, 172; 171, 173; 172, identifier:isinstance; 173, argument_list; 173, 174; 173, 175; 174, identifier:n; 175, identifier:VirtualLNode; 176, comment; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:p; 181, None; 182, else_clause; 182, 183; 182, 184; 182, 185; 183, comment; 184, comment; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:p; 189, subscript; 189, 190; 189, 191; 190, identifier:stmPorts; 191, identifier:n; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:r; 195, call; 195, 196; 195, 197; 196, identifier:StatementRenderer; 197, argument_list; 197, 198; 197, 199; 197, 200; 197, 201; 198, identifier:n; 199, identifier:toL; 200, identifier:p; 201, identifier:netCtx; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:r; 206, identifier:renderContent; 207, argument_list; 208, comment; 209, for_statement; 209, 210; 209, 211; 209, 216; 210, identifier:s; 211, attribute; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:u; 214, identifier:_ctx; 215, identifier:signals; 216, block; 216, 217; 217, if_statement; 217, 218; 217, 222; 218, not_operator; 218, 219; 219, attribute; 219, 220; 219, 221; 220, identifier:s; 221, identifier:hidden; 222, block; 222, 223; 222, 234; 222, 256; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, pattern_list; 225, 226; 225, 227; 226, identifier:net; 227, identifier:_; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:netCtx; 231, identifier:getDefault; 232, argument_list; 232, 233; 233, identifier:s; 234, for_statement; 234, 235; 234, 236; 234, 239; 235, identifier:e; 236, attribute; 236, 237; 236, 238; 237, identifier:s; 238, identifier:endpoints; 239, block; 239, 240; 240, if_statement; 240, 241; 240, 246; 241, call; 241, 242; 241, 243; 242, identifier:isinstance; 243, argument_list; 243, 244; 243, 245; 244, identifier:e; 245, identifier:PortItem; 246, block; 246, 247; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:net; 251, identifier:addEndpoint; 252, argument_list; 252, 253; 253, subscript; 253, 254; 253, 255; 254, identifier:toL; 255, identifier:e; 256, for_statement; 256, 257; 256, 258; 256, 261; 257, identifier:d; 258, attribute; 258, 259; 258, 260; 259, identifier:s; 260, identifier:drivers; 261, block; 261, 262; 262, if_statement; 262, 263; 262, 268; 263, call; 263, 264; 263, 265; 264, identifier:isinstance; 265, argument_list; 265, 266; 265, 267; 266, identifier:d; 267, identifier:PortItem; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:net; 273, identifier:addDriver; 274, argument_list; 274, 275; 275, subscript; 275, 276; 275, 277; 276, identifier:toL; 277, identifier:d; 278, expression_statement; 278, 279; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:netCtx; 282, identifier:applyConnections; 283, argument_list; 283, 284; 284, identifier:root; 285, for_statement; 285, 286; 285, 287; 285, 288; 286, identifier:opt; 287, identifier:optimizations; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 292; 291, identifier:opt; 292, argument_list; 292, 293; 293, identifier:root; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:isRootOfWholeGraph; 297, comparison_operator:is; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:root; 300, identifier:parent; 301, None; 302, if_statement; 302, 303; 302, 305; 303, not_operator; 303, 304; 304, identifier:isRootOfWholeGraph; 305, block; 305, 306; 306, for_statement; 306, 307; 306, 308; 306, 311; 306, 312; 306, 313; 307, identifier:intf; 308, attribute; 308, 309; 308, 310; 309, identifier:u; 310, identifier:_interfaces; 311, comment; 312, comment; 313, block; 313, 314; 313, 325; 313, 333; 313, 334; 313, 383; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:ext_p; 317, attribute; 317, 318; 317, 324; 318, subscript; 318, 319; 318, 320; 319, identifier:toL; 320, call; 320, 321; 320, 322; 321, identifier:originObjOfPort; 322, argument_list; 322, 323; 323, identifier:intf; 324, identifier:parentNode; 325, expression_statement; 325, 326; 326, assignment; 326, 327; 326, 328; 327, identifier:nodePort; 328, call; 328, 329; 328, 330; 329, identifier:addPortToLNode; 330, argument_list; 330, 331; 330, 332; 331, identifier:root; 332, identifier:intf; 333, comment; 334, if_statement; 334, 335; 334, 342; 334, 362; 335, comparison_operator:==; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:intf; 338, identifier:_direction; 339, attribute; 339, 340; 339, 341; 340, identifier:INTF_DIRECTION; 341, identifier:SLAVE; 342, block; 342, 343; 342, 347; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 346; 345, identifier:src; 346, identifier:nodePort; 347, expression_statement; 347, 348; 348, assignment; 348, 349; 348, 350; 349, identifier:dst; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:ext_p; 353, identifier:addPort; 354, argument_list; 354, 355; 354, 356; 354, 359; 355, string:""; 356, attribute; 356, 357; 356, 358; 357, identifier:PortType; 358, identifier:INPUT; 359, attribute; 359, 360; 359, 361; 360, identifier:PortSide; 361, identifier:WEST; 362, else_clause; 362, 363; 363, block; 363, 364; 363, 379; 364, expression_statement; 364, 365; 365, assignment; 365, 366; 365, 367; 366, identifier:src; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:ext_p; 370, identifier:addPort; 371, argument_list; 371, 372; 371, 373; 371, 376; 372, string:""; 373, attribute; 373, 374; 373, 375; 374, identifier:PortType; 375, identifier:OUTPUT; 376, attribute; 376, 377; 376, 378; 377, identifier:PortSide; 378, identifier:EAST; 379, expression_statement; 379, 380; 380, assignment; 380, 381; 380, 382; 381, identifier:dst; 382, identifier:nodePort; 383, expression_statement; 383, 384; 384, call; 384, 385; 384, 388; 385, attribute; 385, 386; 385, 387; 386, identifier:root; 387, identifier:addEdge; 388, argument_list; 388, 389; 388, 390; 388, 391; 388, 397; 389, identifier:src; 390, identifier:dst; 391, keyword_argument; 391, 392; 391, 393; 392, identifier:name; 393, call; 393, 394; 393, 395; 394, identifier:repr; 395, argument_list; 395, 396; 396, identifier:intf; 397, keyword_argument; 397, 398; 397, 399; 398, identifier:originObj; 399, identifier:intf; 400, return_statement; 400, 401; 401, identifier:root | def UnitToLNode(u: Unit, node: Optional[LNode]=None,
toL: Optional[dict]=None,
optimizations=[]) -> LNode:
"""
Build LNode instance from Unit instance
:attention: unit has to be synthesized
"""
if toL is None:
toL = {}
if node is None:
root = LNode(name=u._name, originObj=u, node2lnode=toL)
else:
root = node
stmPorts = {}
# {RtlSignal: NetCtx}
netCtx = NetCtxs(root)
# create subunits
for su in u._units:
n = root.addNode(name=su._name, originObj=su)
UnitToLNode(su, n, toL, optimizations)
# create subunits from statements
for stm in u._ctx.statements:
n = addStmAsLNode(root, stm, stmPorts, netCtx)
# create ports for this unit
for intf in u._interfaces:
addPort(root, intf)
# render content of statements
for stm in u._ctx.statements:
n = toL.get(stm, None)
if n is not None:
if isinstance(n, VirtualLNode):
# statement is not in wrap and does not need any port context
p = None
else:
# statement is in wrap and needs a port context
# to resolve port connections to wrap
p = stmPorts[n]
r = StatementRenderer(n, toL, p, netCtx)
r.renderContent()
# connect nets inside this unit
for s in u._ctx.signals:
if not s.hidden:
net, _ = netCtx.getDefault(s)
for e in s.endpoints:
if isinstance(e, PortItem):
net.addEndpoint(toL[e])
for d in s.drivers:
if isinstance(d, PortItem):
net.addDriver(toL[d])
netCtx.applyConnections(root)
for opt in optimizations:
opt(root)
isRootOfWholeGraph = root.parent is None
if not isRootOfWholeGraph:
for intf in u._interfaces:
# connect my external port to port on my container on parent
# also override toL to use this new port
ext_p = toL[originObjOfPort(intf)].parentNode
nodePort = addPortToLNode(root, intf)
# connect this node which represents port to port of this node
if intf._direction == INTF_DIRECTION.SLAVE:
src = nodePort
dst = ext_p.addPort("", PortType.INPUT, PortSide.WEST)
else:
src = ext_p.addPort("", PortType.OUTPUT, PortSide.EAST)
dst = nodePort
root.addEdge(src, dst, name=repr(intf), originObj=intf)
return root |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_hypergeometric_stats; 3, parameters; 3, 4; 3, 5; 4, identifier:N; 5, identifier:indices; 6, block; 6, 7; 6, 9; 6, 19; 6, 40; 6, 46; 6, 62; 6, 78; 6, 84; 6, 90; 6, 94; 6, 98; 6, 102; 6, 229; 7, expression_statement; 7, 8; 8, comment; 9, assert_statement; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:isinstance; 12, argument_list; 12, 13; 12, 14; 13, identifier:N; 14, tuple; 14, 15; 14, 16; 15, identifier:int; 16, attribute; 16, 17; 16, 18; 17, identifier:np; 18, identifier:integer; 19, assert_statement; 19, 20; 20, boolean_operator:and; 20, 21; 20, 28; 20, 29; 21, call; 21, 22; 21, 23; 22, identifier:isinstance; 23, argument_list; 23, 24; 23, 25; 24, identifier:indices; 25, attribute; 25, 26; 25, 27; 26, identifier:np; 27, identifier:ndarray; 28, line_continuation:\; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:np; 32, identifier:issubdtype; 33, argument_list; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:indices; 36, identifier:dtype; 37, attribute; 37, 38; 37, 39; 38, identifier:np; 39, identifier:uint16; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:K; 43, attribute; 43, 44; 43, 45; 44, identifier:indices; 45, identifier:size; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:pvals; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:np; 52, identifier:empty; 53, argument_list; 53, 54; 53, 57; 54, binary_operator:+; 54, 55; 54, 56; 55, identifier:N; 56, integer:1; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:dtype; 59, attribute; 59, 60; 59, 61; 60, identifier:np; 61, identifier:float64; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:folds; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:np; 68, identifier:empty; 69, argument_list; 69, 70; 69, 73; 70, binary_operator:+; 70, 71; 70, 72; 71, identifier:N; 72, integer:1; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:dtype; 75, attribute; 75, 76; 75, 77; 76, identifier:np; 77, identifier:float64; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:pvals; 82, integer:0; 83, float:1.0; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:folds; 88, integer:0; 89, float:1.0; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:n; 93, integer:0; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:k; 97, integer:0; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:p; 101, float:1.0; 102, while_statement; 102, 103; 102, 106; 103, comparison_operator:<; 103, 104; 103, 105; 104, identifier:n; 105, identifier:N; 106, block; 106, 107; 106, 193; 106, 197; 106, 198; 106, 211; 106, 212; 107, if_statement; 107, 108; 107, 117; 107, 118; 107, 119; 107, 154; 108, boolean_operator:and; 108, 109; 108, 112; 109, comparison_operator:<; 109, 110; 109, 111; 110, identifier:k; 111, identifier:K; 112, comparison_operator:==; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:indices; 115, identifier:k; 116, identifier:n; 117, comment; 118, comment; 119, block; 119, 120; 119, 150; 120, expression_statement; 120, 121; 121, augmented_assignment:*=; 121, 122; 121, 123; 122, identifier:p; 123, parenthesized_expression; 123, 124; 124, binary_operator:/; 124, 125; 124, 137; 124, 138; 125, call; 125, 126; 125, 127; 126, identifier:float; 127, argument_list; 127, 128; 128, binary_operator:*; 128, 129; 128, 133; 129, parenthesized_expression; 129, 130; 130, binary_operator:+; 130, 131; 130, 132; 131, identifier:n; 132, integer:1; 133, parenthesized_expression; 133, 134; 134, binary_operator:-; 134, 135; 134, 136; 135, identifier:K; 136, identifier:k; 137, line_continuation:\; 138, call; 138, 139; 138, 140; 139, identifier:float; 140, argument_list; 140, 141; 141, binary_operator:*; 141, 142; 141, 146; 142, parenthesized_expression; 142, 143; 143, binary_operator:-; 143, 144; 143, 145; 144, identifier:N; 145, identifier:n; 146, parenthesized_expression; 146, 147; 147, binary_operator:+; 147, 148; 147, 149; 148, identifier:k; 149, integer:1; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 153; 152, identifier:k; 153, integer:1; 154, else_clause; 154, 155; 154, 156; 154, 157; 155, comment; 156, comment; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, augmented_assignment:*=; 159, 160; 159, 161; 160, identifier:p; 161, parenthesized_expression; 161, 162; 162, binary_operator:/; 162, 163; 162, 179; 163, call; 163, 164; 163, 165; 164, identifier:float; 165, argument_list; 165, 166; 166, binary_operator:*; 166, 167; 166, 171; 167, parenthesized_expression; 167, 168; 168, binary_operator:+; 168, 169; 168, 170; 169, identifier:n; 170, integer:1; 171, parenthesized_expression; 171, 172; 172, binary_operator:+; 172, 173; 172, 178; 173, binary_operator:-; 173, 174; 173, 177; 174, binary_operator:-; 174, 175; 174, 176; 175, identifier:N; 176, identifier:K; 177, identifier:n; 178, identifier:k; 179, call; 179, 180; 179, 181; 180, identifier:float; 181, argument_list; 181, 182; 182, binary_operator:*; 182, 183; 182, 187; 183, parenthesized_expression; 183, 184; 184, binary_operator:-; 184, 185; 184, 186; 185, identifier:N; 186, identifier:n; 187, parenthesized_expression; 187, 188; 188, binary_operator:+; 188, 189; 188, 192; 189, binary_operator:-; 189, 190; 189, 191; 190, identifier:n; 191, identifier:k; 192, integer:1; 193, expression_statement; 193, 194; 194, augmented_assignment:+=; 194, 195; 194, 196; 195, identifier:n; 196, integer:1; 197, comment; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:pvals; 202, identifier:n; 203, call; 203, 204; 203, 205; 204, identifier:get_hgp; 205, argument_list; 205, 206; 205, 207; 205, 208; 205, 209; 205, 210; 206, identifier:p; 207, identifier:k; 208, identifier:N; 209, identifier:K; 210, identifier:n; 211, comment; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:folds; 216, identifier:n; 217, binary_operator:/; 217, 218; 217, 219; 218, identifier:k; 219, parenthesized_expression; 219, 220; 220, binary_operator:*; 220, 221; 220, 222; 221, identifier:K; 222, parenthesized_expression; 222, 223; 223, binary_operator:/; 223, 224; 223, 225; 224, identifier:n; 225, call; 225, 226; 225, 227; 226, identifier:float; 227, argument_list; 227, 228; 228, identifier:N; 229, return_statement; 229, 230; 230, expression_list; 230, 231; 230, 232; 231, identifier:pvals; 232, identifier:folds | def get_hypergeometric_stats(N, indices):
"""Calculates hypergeom. p-values and fold enrichments for all cutoffs.
Parameters
----------
N: int
The length of the list
indices: `numpy.ndarray` with ``dtype=np.uint16``
The (sorted) indices of the "1's" in the list.
"""
assert isinstance(N, (int, np.integer))
assert isinstance(indices, np.ndarray) and \
np.issubdtype(indices.dtype, np.uint16)
K = indices.size
pvals = np.empty(N+1, dtype=np.float64)
folds = np.empty(N+1, dtype=np.float64)
pvals[0] = 1.0
folds[0] = 1.0
n = 0
k = 0
p = 1.0
while n < N:
if k < K and indices[k] == n:
# "add one"
# calculate f(k+1; N,K,n+1) from f(k; N,K,n)
p *= (float((n+1) * (K-k)) / \
float((N-n) * (k+1)))
k += 1
else:
# "add zero"
# calculate f(k; N,K,n+1) from f(k; N,K,n)
p *= (float((n+1) * (N-K-n+k)) /
float((N-n) * (n-k+1)))
n += 1
# calculate hypergeometric p-value
pvals[n] = get_hgp(p, k, N, K, n)
# calculate fold enrichment
folds[n] = k / (K*(n/float(N)))
return pvals, folds |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:purge_existing_ovb; 3, parameters; 3, 4; 3, 5; 4, identifier:nova_api; 5, identifier:neutron; 6, block; 6, 7; 6, 9; 6, 16; 6, 57; 6, 139; 6, 231; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:LOG; 13, identifier:info; 14, argument_list; 14, 15; 15, string:'Cleaning up OVB environment from the tenant.'; 16, for_statement; 16, 17; 16, 18; 16, 25; 17, identifier:server; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:nova_api; 22, identifier:servers; 23, identifier:list; 24, argument_list; 25, block; 25, 26; 25, 41; 26, if_statement; 26, 27; 26, 34; 27, comparison_operator:in; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:server; 30, identifier:name; 31, tuple; 31, 32; 31, 33; 32, string:'bmc'; 33, string:'undercloud'; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:server; 39, identifier:delete; 40, argument_list; 41, if_statement; 41, 42; 41, 50; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:server; 46, identifier:name; 47, identifier:startswith; 48, argument_list; 48, 49; 49, string:'baremetal_'; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:server; 55, identifier:delete; 56, argument_list; 57, for_statement; 57, 58; 57, 59; 57, 69; 58, identifier:router; 59, call; 59, 60; 59, 67; 60, attribute; 60, 61; 60, 66; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:neutron; 64, identifier:list_routers; 65, argument_list; 66, identifier:get; 67, argument_list; 67, 68; 68, string:'routers'; 69, block; 69, 70; 69, 80; 70, if_statement; 70, 71; 70, 78; 71, comparison_operator:not; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:router; 74, string:'name'; 75, tuple; 75, 76; 75, 77; 76, string:'router'; 77, string:'bmc_router'; 78, block; 78, 79; 79, continue_statement; 80, for_statement; 80, 81; 80, 82; 80, 92; 81, identifier:subnet; 82, call; 82, 83; 82, 90; 83, attribute; 83, 84; 83, 89; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:neutron; 87, identifier:list_subnets; 88, argument_list; 89, identifier:get; 90, argument_list; 90, 91; 91, string:'subnets'; 92, block; 92, 93; 92, 112; 93, if_statement; 93, 94; 93, 110; 94, not_operator; 94, 95; 95, parenthesized_expression; 95, 96; 96, boolean_operator:or; 96, 97; 96, 105; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:subnet; 101, string:'name'; 102, identifier:startswith; 103, argument_list; 103, 104; 104, string:'bmc_eth'; 105, comparison_operator:==; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:subnet; 108, string:'name'; 109, string:'rdo-m-subnet'; 110, block; 110, 111; 111, continue_statement; 112, try_statement; 112, 113; 112, 129; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:neutron; 118, identifier:remove_interface_router; 119, argument_list; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:router; 122, string:'id'; 123, dictionary; 123, 124; 124, pair; 124, 125; 124, 126; 125, string:'subnet_id'; 126, subscript; 126, 127; 126, 128; 127, identifier:subnet; 128, string:'id'; 129, except_clause; 129, 130; 129, 137; 130, attribute; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:neutronclient; 134, identifier:common; 135, identifier:exceptions; 136, identifier:NotFound; 137, block; 137, 138; 138, pass_statement; 139, try_statement; 139, 140; 139, 226; 140, block; 140, 141; 140, 159; 140, 217; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:bmc_router; 144, subscript; 144, 145; 144, 158; 145, call; 145, 146; 145, 156; 146, attribute; 146, 147; 146, 155; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:neutron; 150, identifier:list_routers; 151, argument_list; 151, 152; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:name; 154, string:'bmc_router'; 155, identifier:get; 156, argument_list; 156, 157; 157, string:'routers'; 158, integer:0; 159, for_statement; 159, 160; 159, 161; 159, 173; 160, identifier:port; 161, subscript; 161, 162; 161, 172; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:neutron; 165, identifier:list_ports; 166, argument_list; 166, 167; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:device_id; 169, subscript; 169, 170; 169, 171; 170, identifier:bmc_router; 171, string:'id'; 172, string:'ports'; 173, block; 173, 174; 173, 185; 173, 207; 174, if_statement; 174, 175; 174, 183; 175, comparison_operator:==; 175, 176; 175, 182; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:port; 179, identifier:get; 180, argument_list; 180, 181; 181, string:'device_owner'; 182, string:'network:router_gateway'; 183, block; 183, 184; 184, continue_statement; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:info; 188, dictionary; 188, 189; 188, 194; 188, 199; 189, pair; 189, 190; 189, 191; 190, string:'id'; 191, subscript; 191, 192; 191, 193; 192, identifier:router; 193, string:'id'; 194, pair; 194, 195; 194, 196; 195, string:'port_id'; 196, subscript; 196, 197; 196, 198; 197, identifier:port; 198, string:'id'; 199, pair; 199, 200; 199, 201; 200, string:'tenant_id'; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:bmc_router; 204, identifier:get; 205, argument_list; 205, 206; 206, string:'tenant_id'; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:neutron; 211, identifier:remove_interface_router; 212, argument_list; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:bmc_router; 215, string:'id'; 216, identifier:info; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:neutron; 221, identifier:delete_router; 222, argument_list; 222, 223; 223, subscript; 223, 224; 223, 225; 224, identifier:bmc_router; 225, string:'id'; 226, except_clause; 226, 227; 226, 228; 226, 229; 227, identifier:IndexError; 228, comment; 229, block; 229, 230; 230, pass_statement; 231, for_statement; 231, 232; 231, 233; 231, 238; 232, identifier:_; 233, call; 233, 234; 233, 235; 234, identifier:range; 235, argument_list; 235, 236; 235, 237; 236, integer:0; 237, integer:5; 238, block; 238, 239; 239, try_statement; 239, 240; 239, 375; 239, 398; 240, block; 240, 241; 240, 270; 241, for_statement; 241, 242; 241, 243; 241, 250; 242, identifier:port; 243, subscript; 243, 244; 243, 249; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:neutron; 247, identifier:list_ports; 248, argument_list; 249, string:'ports'; 250, block; 250, 251; 251, if_statement; 251, 252; 251, 260; 252, call; 252, 253; 252, 258; 253, attribute; 253, 254; 253, 257; 254, subscript; 254, 255; 254, 256; 255, identifier:port; 256, string:'name'; 257, identifier:endswith; 258, argument_list; 258, 259; 259, string:'_provision'; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:neutron; 265, identifier:delete_port; 266, argument_list; 266, 267; 267, subscript; 267, 268; 267, 269; 268, identifier:port; 269, string:'id'; 270, for_statement; 270, 271; 270, 272; 270, 282; 271, identifier:net; 272, call; 272, 273; 272, 280; 273, attribute; 273, 274; 273, 279; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:neutron; 277, identifier:list_networks; 278, argument_list; 279, identifier:get; 280, argument_list; 280, 281; 281, string:'networks'; 282, block; 282, 283; 282, 295; 282, 366; 283, if_statement; 283, 284; 283, 293; 284, not_operator; 284, 285; 285, call; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, subscript; 287, 288; 287, 289; 288, identifier:net; 289, string:'name'; 290, identifier:startswith; 291, argument_list; 291, 292; 292, string:'provision_'; 293, block; 293, 294; 294, continue_statement; 295, for_statement; 295, 296; 295, 297; 295, 309; 296, identifier:port; 297, subscript; 297, 298; 297, 308; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:neutron; 301, identifier:list_ports; 302, argument_list; 302, 303; 303, keyword_argument; 303, 304; 303, 305; 304, identifier:network_id; 305, subscript; 305, 306; 305, 307; 306, identifier:net; 307, string:'id'; 308, string:'ports'; 309, block; 309, 310; 309, 321; 309, 342; 310, if_statement; 310, 311; 310, 319; 311, comparison_operator:==; 311, 312; 311, 318; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:port; 315, identifier:get; 316, argument_list; 316, 317; 317, string:'device_owner'; 318, string:'network:router_interface'; 319, block; 319, 320; 320, continue_statement; 321, try_statement; 321, 322; 321, 332; 322, block; 322, 323; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:neutron; 327, identifier:delete_port; 328, argument_list; 328, 329; 329, subscript; 329, 330; 329, 331; 330, identifier:port; 331, string:'id'; 332, except_clause; 332, 333; 332, 340; 333, attribute; 333, 334; 333, 339; 334, attribute; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:neutronclient; 337, identifier:common; 338, identifier:exceptions; 339, identifier:PortNotFoundClient; 340, block; 340, 341; 341, pass_statement; 342, for_statement; 342, 343; 342, 344; 342, 356; 343, identifier:subnet; 344, subscript; 344, 345; 344, 355; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:neutron; 348, identifier:list_subnets; 349, argument_list; 349, 350; 350, keyword_argument; 350, 351; 350, 352; 351, identifier:network_id; 352, subscript; 352, 353; 352, 354; 353, identifier:net; 354, string:'id'; 355, string:'subnets'; 356, block; 356, 357; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:neutron; 361, identifier:delete_subnet; 362, argument_list; 362, 363; 363, subscript; 363, 364; 363, 365; 364, identifier:subnet; 365, string:'id'; 366, expression_statement; 366, 367; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:neutron; 370, identifier:delete_network; 371, argument_list; 371, 372; 372, subscript; 372, 373; 372, 374; 373, identifier:net; 374, string:'id'; 375, except_clause; 375, 376; 375, 383; 376, attribute; 376, 377; 376, 382; 377, attribute; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:neutronclient; 380, identifier:common; 381, identifier:exceptions; 382, identifier:Conflict; 383, block; 383, 384; 383, 391; 384, expression_statement; 384, 385; 385, call; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:LOG; 388, identifier:debug; 389, argument_list; 389, 390; 390, string:'waiting for all the ports to be freed...'; 391, expression_statement; 391, 392; 392, call; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:time; 395, identifier:sleep; 396, argument_list; 396, 397; 397, integer:5; 398, else_clause; 398, 399; 399, block; 399, 400; 400, return_statement | def purge_existing_ovb(nova_api, neutron):
"""Purge any trace of an existing OVB deployment.
"""
LOG.info('Cleaning up OVB environment from the tenant.')
for server in nova_api.servers.list():
if server.name in ('bmc', 'undercloud'):
server.delete()
if server.name.startswith('baremetal_'):
server.delete()
for router in neutron.list_routers().get('routers'):
if router['name'] not in ('router', 'bmc_router'):
continue
for subnet in neutron.list_subnets().get('subnets'):
if not (subnet['name'].startswith('bmc_eth') or subnet['name'] == 'rdo-m-subnet'):
continue
try:
neutron.remove_interface_router(router['id'], {'subnet_id': subnet['id']})
except neutronclient.common.exceptions.NotFound:
pass
try:
bmc_router = neutron.list_routers(name='bmc_router').get('routers')[0]
for port in neutron.list_ports(device_id=bmc_router['id'])['ports']:
if port.get('device_owner') == 'network:router_gateway':
continue
info = {'id': router['id'],
'port_id': port['id'],
'tenant_id': bmc_router.get('tenant_id'),
}
neutron.remove_interface_router(bmc_router['id'], info)
neutron.delete_router(bmc_router['id'])
except IndexError: # already doesnt exist
pass
for _ in range(0, 5):
try:
for port in neutron.list_ports()['ports']:
if port['name'].endswith('_provision'):
neutron.delete_port(port['id'])
for net in neutron.list_networks().get('networks'):
if not net['name'].startswith('provision_'):
continue
for port in neutron.list_ports(network_id=net['id'])['ports']:
if port.get('device_owner') == 'network:router_interface':
continue
try:
neutron.delete_port(port['id'])
except neutronclient.common.exceptions.PortNotFoundClient:
pass
for subnet in neutron.list_subnets(network_id=net['id'])['subnets']:
neutron.delete_subnet(subnet['id'])
neutron.delete_network(net['id'])
except neutronclient.common.exceptions.Conflict:
LOG.debug('waiting for all the ports to be freed...')
time.sleep(5)
else:
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:reduceUselessAssignments; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:root; 6, type; 6, 7; 7, identifier:LNode; 8, block; 8, 9; 8, 11; 8, 27; 8, 31; 8, 225; 9, expression_statement; 9, 10; 10, comment; 11, for_statement; 11, 12; 11, 13; 11, 16; 12, identifier:n; 13, attribute; 13, 14; 13, 15; 14, identifier:root; 15, identifier:children; 16, block; 16, 17; 17, if_statement; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:n; 20, identifier:children; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:reduceUselessAssignments; 25, argument_list; 25, 26; 26, identifier:n; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:do_update; 30, False; 31, for_statement; 31, 32; 31, 33; 31, 36; 32, identifier:n; 33, attribute; 33, 34; 33, 35; 34, identifier:root; 35, identifier:children; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 63; 38, boolean_operator:and; 38, 39; 38, 54; 38, 55; 39, boolean_operator:and; 39, 40; 39, 47; 39, 48; 40, call; 40, 41; 40, 42; 41, identifier:isinstance; 42, argument_list; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:n; 45, identifier:originObj; 46, identifier:Assignment; 47, line_continuation:\; 48, not_operator; 48, 49; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:n; 52, identifier:originObj; 53, identifier:indexes; 54, line_continuation:\; 55, comparison_operator:==; 55, 56; 55, 62; 56, call; 56, 57; 56, 58; 57, identifier:len; 58, argument_list; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:n; 61, identifier:west; 62, integer:1; 63, block; 63, 64; 63, 72; 63, 84; 63, 101; 63, 108; 63, 112; 63, 116; 63, 120; 63, 129; 63, 138; 63, 168; 63, 194; 63, 204; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:src; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:n; 70, identifier:originObj; 71, identifier:src; 72, if_statement; 72, 73; 72, 82; 73, boolean_operator:and; 73, 74; 73, 79; 74, call; 74, 75; 74, 76; 75, identifier:isinstance; 76, argument_list; 76, 77; 76, 78; 77, identifier:src; 78, identifier:RtlSignalBase; 79, attribute; 79, 80; 79, 81; 80, identifier:src; 81, identifier:hidden; 82, block; 82, 83; 83, continue_statement; 84, if_statement; 84, 85; 84, 87; 85, not_operator; 85, 86; 86, identifier:do_update; 87, block; 87, 88; 87, 97; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:nodes; 91, call; 91, 92; 91, 93; 92, identifier:set; 93, argument_list; 93, 94; 94, attribute; 94, 95; 94, 96; 95, identifier:root; 96, identifier:children; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:do_update; 100, True; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:nodes; 105, identifier:remove; 106, argument_list; 106, 107; 107, identifier:n; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:srcPorts; 111, list:[]; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:dstPorts; 115, list:[]; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:edgesToRemove; 119, list:[]; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:inP; 123, call; 123, 124; 123, 125; 124, identifier:getSinglePort; 125, argument_list; 125, 126; 126, attribute; 126, 127; 126, 128; 127, identifier:n; 128, identifier:west; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:outP; 132, call; 132, 133; 132, 134; 133, identifier:getSinglePort; 134, argument_list; 134, 135; 135, attribute; 135, 136; 135, 137; 136, identifier:n; 137, identifier:east; 138, for_statement; 138, 139; 138, 140; 138, 143; 139, identifier:e; 140, attribute; 140, 141; 140, 142; 141, identifier:inP; 142, identifier:incomingEdges; 143, block; 143, 144; 143, 150; 143, 161; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:sPort; 147, attribute; 147, 148; 147, 149; 148, identifier:e; 149, identifier:src; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:srcPorts; 154, identifier:append; 155, argument_list; 155, 156; 156, tuple; 156, 157; 156, 158; 157, identifier:sPort; 158, attribute; 158, 159; 158, 160; 159, identifier:e; 160, identifier:originObj; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:edgesToRemove; 165, identifier:append; 166, argument_list; 166, 167; 167, identifier:e; 168, for_statement; 168, 169; 168, 170; 168, 173; 169, identifier:e; 170, attribute; 170, 171; 170, 172; 171, identifier:outP; 172, identifier:outgoingEdges; 173, block; 173, 174; 173, 180; 173, 187; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:dPort; 177, attribute; 177, 178; 177, 179; 178, identifier:e; 179, identifier:dst; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:dstPorts; 184, identifier:append; 185, argument_list; 185, 186; 186, identifier:dPort; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:edgesToRemove; 191, identifier:append; 192, argument_list; 192, 193; 193, identifier:e; 194, for_statement; 194, 195; 194, 196; 194, 197; 195, identifier:e; 196, identifier:edgesToRemove; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:e; 202, identifier:remove; 203, argument_list; 204, for_statement; 204, 205; 204, 208; 204, 209; 205, pattern_list; 205, 206; 205, 207; 206, identifier:srcPort; 207, identifier:originObj; 208, identifier:srcPorts; 209, block; 209, 210; 210, for_statement; 210, 211; 210, 212; 210, 213; 211, identifier:dstPort; 212, identifier:dstPorts; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:root; 218, identifier:addEdge; 219, argument_list; 219, 220; 219, 221; 219, 222; 220, identifier:srcPort; 221, identifier:dstPort; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:originObj; 224, identifier:originObj; 225, if_statement; 225, 226; 225, 227; 226, identifier:do_update; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:root; 232, identifier:children; 233, call; 233, 234; 233, 235; 234, identifier:list; 235, argument_list; 235, 236; 236, identifier:nodes | def reduceUselessAssignments(root: LNode):
"""
Remove assignments if it is only a direct connection and can be replaced with direct link
"""
for n in root.children:
if n.children:
reduceUselessAssignments(n)
do_update = False
for n in root.children:
if isinstance(n.originObj, Assignment)\
and not n.originObj.indexes\
and len(n.west) == 1:
src = n.originObj.src
if isinstance(src, RtlSignalBase) and src.hidden:
continue
if not do_update:
nodes = set(root.children)
do_update = True
nodes.remove(n)
srcPorts = []
dstPorts = []
edgesToRemove = []
inP = getSinglePort(n.west)
outP = getSinglePort(n.east)
for e in inP.incomingEdges:
sPort = e.src
srcPorts.append((sPort, e.originObj))
edgesToRemove.append(e)
for e in outP.outgoingEdges:
dPort = e.dst
dstPorts.append(dPort)
edgesToRemove.append(e)
for e in edgesToRemove:
e.remove()
for srcPort, originObj in srcPorts:
for dstPort in dstPorts:
root.addEdge(srcPort, dstPort,
originObj=originObj)
if do_update:
root.children = list(nodes) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:determine_completeness; 3, parameters; 3, 4; 4, identifier:py_untl; 5, block; 5, 6; 5, 8; 5, 9; 5, 94; 5, 110; 5, 114; 5, 115; 5, 116; 5, 208; 5, 209; 5, 233; 5, 234; 5, 240; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:completeness_dict; 12, dictionary; 12, 13; 12, 22; 12, 31; 12, 40; 12, 49; 12, 58; 12, 67; 12, 76; 12, 85; 13, pair; 13, 14; 13, 15; 14, string:'title'; 15, dictionary; 15, 16; 15, 19; 16, pair; 16, 17; 16, 18; 17, string:'present'; 18, False; 19, pair; 19, 20; 19, 21; 20, string:'weight'; 21, integer:10; 22, pair; 22, 23; 22, 24; 23, string:'description'; 24, dictionary; 24, 25; 24, 28; 25, pair; 25, 26; 25, 27; 26, string:'present'; 27, False; 28, pair; 28, 29; 28, 30; 29, string:'weight'; 30, integer:1; 31, pair; 31, 32; 31, 33; 32, string:'language'; 33, dictionary; 33, 34; 33, 37; 34, pair; 34, 35; 34, 36; 35, string:'present'; 36, False; 37, pair; 37, 38; 37, 39; 38, string:'weight'; 39, integer:1; 40, pair; 40, 41; 40, 42; 41, string:'collection'; 42, dictionary; 42, 43; 42, 46; 43, pair; 43, 44; 43, 45; 44, string:'present'; 45, False; 46, pair; 46, 47; 46, 48; 47, string:'weight'; 48, integer:10; 49, pair; 49, 50; 49, 51; 50, string:'institution'; 51, dictionary; 51, 52; 51, 55; 52, pair; 52, 53; 52, 54; 53, string:'present'; 54, False; 55, pair; 55, 56; 55, 57; 56, string:'weight'; 57, integer:10; 58, pair; 58, 59; 58, 60; 59, string:'resourceType'; 60, dictionary; 60, 61; 60, 64; 61, pair; 61, 62; 61, 63; 62, string:'present'; 63, False; 64, pair; 64, 65; 64, 66; 65, string:'weight'; 66, integer:5; 67, pair; 67, 68; 67, 69; 68, string:'format'; 69, dictionary; 69, 70; 69, 73; 70, pair; 70, 71; 70, 72; 71, string:'present'; 72, False; 73, pair; 73, 74; 73, 75; 74, string:'weight'; 75, integer:1; 76, pair; 76, 77; 76, 78; 77, string:'subject'; 78, dictionary; 78, 79; 78, 82; 79, pair; 79, 80; 79, 81; 80, string:'present'; 81, False; 82, pair; 82, 83; 82, 84; 83, string:'weight'; 84, integer:1; 85, pair; 85, 86; 85, 87; 86, string:'meta'; 87, dictionary; 87, 88; 87, 91; 88, pair; 88, 89; 88, 90; 89, string:'present'; 90, False; 91, pair; 91, 92; 91, 93; 92, string:'weight'; 93, integer:20; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:total_points; 97, call; 97, 98; 97, 99; 98, identifier:sum; 99, generator_expression; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:item; 102, string:'weight'; 103, for_in_clause; 103, 104; 103, 105; 104, identifier:item; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:completeness_dict; 108, identifier:values; 109, argument_list; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:py_untl_object_score; 113, float:0.0; 114, comment; 115, comment; 116, for_statement; 116, 117; 116, 118; 116, 121; 116, 122; 117, identifier:i; 118, attribute; 118, 119; 118, 120; 119, identifier:py_untl; 120, identifier:children; 121, comment; 122, block; 122, 123; 123, if_statement; 123, 124; 123, 129; 124, comparison_operator:in; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:i; 127, identifier:tag; 128, identifier:PYUNTL_COMPLETENESS_SCORED_ATTRIBUTES; 129, block; 129, 130; 130, if_statement; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:i; 133, identifier:content; 134, block; 134, 135; 134, 145; 134, 146; 134, 158; 134, 159; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:content; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:i; 142, identifier:content; 143, identifier:lower; 144, argument_list; 145, comment; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:match; 149, call; 149, 150; 149, 151; 150, identifier:bool; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:DEFAULT_VALUE_REGEX; 155, identifier:search; 156, argument_list; 156, 157; 157, identifier:content; 158, comment; 159, if_statement; 159, 160; 159, 166; 159, 167; 160, boolean_operator:and; 160, 161; 160, 164; 161, comparison_operator:not; 161, 162; 161, 163; 162, identifier:content; 163, identifier:COMMON_DEFAULT_ATTRIBUTE_VALUES; 164, not_operator; 164, 165; 165, identifier:match; 166, comment; 167, block; 167, 168; 168, if_statement; 168, 169; 168, 174; 168, 194; 169, comparison_operator:==; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:i; 172, identifier:tag; 173, string:'meta'; 174, block; 174, 175; 175, if_statement; 175, 176; 175, 181; 176, comparison_operator:==; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:i; 179, identifier:qualifier; 180, string:'system'; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 193; 184, subscript; 184, 185; 184, 192; 185, subscript; 185, 186; 185, 187; 186, identifier:completeness_dict; 187, binary_operator:%; 187, 188; 187, 189; 188, string:'%s'; 189, attribute; 189, 190; 189, 191; 190, identifier:i; 191, identifier:tag; 192, string:'present'; 193, True; 194, else_clause; 194, 195; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 207; 198, subscript; 198, 199; 198, 206; 199, subscript; 199, 200; 199, 201; 200, identifier:completeness_dict; 201, binary_operator:%; 201, 202; 201, 203; 202, string:'%s'; 203, attribute; 203, 204; 203, 205; 204, identifier:i; 205, identifier:tag; 206, string:'present'; 207, True; 208, comment; 209, for_statement; 209, 210; 209, 213; 209, 218; 209, 219; 210, pattern_list; 210, 211; 210, 212; 211, identifier:k; 212, identifier:v; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:completeness_dict; 216, identifier:iteritems; 217, argument_list; 218, comment; 219, block; 219, 220; 220, if_statement; 220, 221; 220, 224; 221, subscript; 221, 222; 221, 223; 222, identifier:v; 223, string:'present'; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, augmented_assignment:+=; 226, 227; 226, 228; 227, identifier:py_untl_object_score; 228, subscript; 228, 229; 228, 232; 229, subscript; 229, 230; 229, 231; 230, identifier:completeness_dict; 231, identifier:k; 232, string:'weight'; 233, comment; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:completeness; 237, binary_operator:/; 237, 238; 237, 239; 238, identifier:py_untl_object_score; 239, identifier:total_points; 240, return_statement; 240, 241; 241, identifier:completeness | def determine_completeness(py_untl):
"""Take a Python untl and calculate the completeness.
Completeness is based on this: metadata_quality.rst documentation.
Returns a float 0.0 - 1.0.
"""
# Default values for the completeness dictionary.
completeness_dict = {
'title': {'present': False, 'weight': 10, },
'description': {'present': False, 'weight': 1, },
'language': {'present': False, 'weight': 1, },
'collection': {'present': False, 'weight': 10, },
'institution': {'present': False, 'weight': 10, },
'resourceType': {'present': False, 'weight': 5, },
'format': {'present': False, 'weight': 1, },
'subject': {'present': False, 'weight': 1, },
'meta': {'present': False, 'weight': 20, },
}
total_points = sum(item['weight'] for item in completeness_dict.values())
py_untl_object_score = 0.0
# Iterate through the attributes of the pyuntl record.
# This loop will toggle the Boolean for scoring.
for i in py_untl.children:
# Process attribute that is scorable and has content.
if i.tag in PYUNTL_COMPLETENESS_SCORED_ATTRIBUTES:
if i.content:
content = i.content.lower()
# Try and match against new default placeholders.
match = bool(DEFAULT_VALUE_REGEX.search(content))
# The content is not a legacy placeholder.
if content not in COMMON_DEFAULT_ATTRIBUTE_VALUES and not match:
# Only consider <meta qualifier="system"> records.
if i.tag == 'meta':
if i.qualifier == 'system':
completeness_dict['%s' % i.tag]['present'] = True
else:
completeness_dict['%s' % i.tag]['present'] = True
# Get total score of the pyuntl object.
for k, v in completeness_dict.iteritems():
# If presence was toggled true, adjust score based on weight.
if v['present']:
py_untl_object_score += completeness_dict[k]['weight']
# Calculate the float score completeness.
completeness = py_untl_object_score / total_points
return completeness |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:read_char_lengths; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:filename; 6, identifier:electrode_filename; 7, block; 7, 8; 7, 10; 7, 147; 7, 164; 7, 170; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 19; 10, 136; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:os; 15, identifier:path; 16, identifier:isfile; 17, argument_list; 17, 18; 18, identifier:filename; 19, block; 19, 20; 19, 34; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:data; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:np; 26, identifier:atleast_1d; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:np; 31, identifier:loadtxt; 32, argument_list; 32, 33; 33, identifier:filename; 34, if_statement; 34, 35; 34, 40; 34, 121; 35, comparison_operator:==; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:data; 38, identifier:size; 39, integer:4; 40, block; 40, 41; 40, 45; 40, 46; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:characteristic_length; 44, identifier:data; 45, comment; 46, if_statement; 46, 47; 46, 52; 47, comparison_operator:<; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:characteristic_length; 50, integer:0; 51, integer:0; 52, block; 52, 53; 52, 71; 52, 76; 52, 89; 52, 107; 53, try_statement; 53, 54; 53, 64; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:elec_positions; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:np; 61, identifier:loadtxt; 62, argument_list; 62, 63; 63, identifier:electrode_filename; 64, except_clause; 64, 65; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:IOError; 69, argument_list; 69, 70; 70, string:'The was an error opening the electrode file'; 71, import_statement; 71, 72; 72, dotted_name; 72, 73; 72, 74; 72, 75; 73, identifier:scipy; 74, identifier:spatial; 75, identifier:distance; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:distances; 79, call; 79, 80; 79, 87; 80, attribute; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:scipy; 84, identifier:spatial; 85, identifier:distance; 86, identifier:pdist; 87, argument_list; 87, 88; 88, identifier:elec_positions; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:characteristic_length; 93, integer:0; 94, binary_operator:*; 94, 95; 94, 99; 95, call; 95, 96; 95, 97; 96, identifier:min; 97, argument_list; 97, 98; 98, identifier:distances; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:np; 102, identifier:abs; 103, argument_list; 103, 104; 104, subscript; 104, 105; 104, 106; 105, identifier:characteristic_length; 106, integer:0; 107, if_statement; 107, 108; 107, 113; 108, comparison_operator:==; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:characteristic_length; 111, integer:0; 112, integer:0; 113, block; 113, 114; 114, raise_statement; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:Exception; 117, argument_list; 117, 118; 118, binary_operator:+; 118, 119; 118, 120; 119, string:'Error computing electrode '; 120, string:'distances (got a minimal distance of zero'; 121, else_clause; 121, 122; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:characteristic_length; 126, binary_operator:*; 126, 127; 126, 133; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:np; 130, identifier:ones; 131, argument_list; 131, 132; 132, integer:4; 133, subscript; 133, 134; 133, 135; 134, identifier:data; 135, integer:0; 136, else_clause; 136, 137; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:characteristic_length; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:np; 144, identifier:ones; 145, argument_list; 145, 146; 146, integer:4; 147, if_statement; 147, 148; 147, 156; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:np; 151, identifier:any; 152, argument_list; 152, 153; 153, comparison_operator:<=; 153, 154; 153, 155; 154, identifier:characteristic_length; 155, integer:0; 156, block; 156, 157; 157, raise_statement; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:Exception; 160, argument_list; 160, 161; 161, binary_operator:+; 161, 162; 161, 163; 162, string:'No negative characteristic lengths allowed '; 163, string:'(except for electrode length'; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:char_lengths; 169, dictionary; 170, for_statement; 170, 171; 170, 174; 170, 183; 171, pattern_list; 171, 172; 171, 173; 172, identifier:key; 173, identifier:item; 174, call; 174, 175; 174, 176; 175, identifier:zip; 176, argument_list; 176, 177; 176, 182; 177, tuple; 177, 178; 177, 179; 177, 180; 177, 181; 178, string:'electrode'; 179, string:'boundary'; 180, string:'extra_line'; 181, string:'extra_node'; 182, identifier:characteristic_length; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 191; 186, subscript; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:char_lengths; 190, identifier:key; 191, identifier:item | def read_char_lengths(self, filename, electrode_filename):
"""Read characteristic lengths from the given file.
The file is expected to have either 1 or 4 entries/lines with
characteristic lengths > 0 (floats). If only one value is encountered,
it is used for all four entities. If four values are encountered, they
are assigned, in order, to:
1) electrode nodes
2) boundary nodes
3) nodes from extra lines
4) nodes from extra nodes
Note that in case one node belongs to multiple entities, the smallest
characteristic length will be used.
If four values are used and the electrode length is negative, then the
electrode positions will be read in (todo: we open the electrode.dat
file two times here...) and the minimal distance between all electrodes
will be multiplied by the absolute value of the imported value, and
used as the characteristic length:
.. math::
l_{electrodes} = min(pdist(electrodes)) * |l_{electrodes}^{from
file}|
The function scipy.spatial.distance.pdist is used to compute the global
minimal distance between any two electrodes.
It is advisable to only used values in the range [-1, 0) for the
automatic char length option.
"""
if os.path.isfile(filename):
data = np.atleast_1d(np.loadtxt(filename))
if data.size == 4:
characteristic_length = data
# check sign of first (electrode) length value
if characteristic_length[0] < 0:
try:
elec_positions = np.loadtxt(electrode_filename)
except:
raise IOError(
'The was an error opening the electrode file')
import scipy.spatial.distance
distances = scipy.spatial.distance.pdist(elec_positions)
characteristic_length[0] = min(distances) * np.abs(
characteristic_length[0])
if characteristic_length[0] == 0:
raise Exception(
'Error computing electrode ' +
'distances (got a minimal distance of zero')
else:
characteristic_length = np.ones(4) * data[0]
else:
characteristic_length = np.ones(4)
if np.any(characteristic_length <= 0):
raise Exception('No negative characteristic lengths allowed ' +
'(except for electrode length')
self.char_lengths = {}
for key, item in zip(('electrode',
'boundary',
'extra_line',
'extra_node'),
characteristic_length):
self.char_lengths[key] = item |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:parse_atom_tag_data; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, identifier:tag_content; 7, block; 7, 8; 7, 10; 7, 16; 8, expression_statement; 8, 9; 9, string:'''Parse the atom tag data.'''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:current_atom_site; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:current_atom_site; 16, if_statement; 16, 17; 16, 20; 16, 21; 16, 23; 16, 173; 16, 174; 16, 211; 16, 212; 16, 265; 16, 286; 16, 319; 16, 337; 16, 358; 17, attribute; 17, 18; 17, 19; 18, identifier:current_atom_site; 19, identifier:IsHETATM; 20, comment; 21, block; 21, 22; 22, return_statement; 23, elif_clause; 23, 24; 23, 27; 23, 28; 23, 29; 24, comparison_operator:==; 24, 25; 24, 26; 25, identifier:name; 26, string:'PDBx:atom_site'; 27, comment; 28, comment; 29, block; 29, 30; 29, 36; 29, 42; 29, 48; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_BLOCK; 35, None; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:current_atom_site; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:current_atom_site; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:current_atom_site; 46, identifier:validate; 47, argument_list; 48, if_statement; 48, 49; 48, 52; 48, 53; 49, attribute; 49, 50; 49, 51; 50, identifier:current_atom_site; 51, identifier:IsATOM; 52, comment; 53, block; 53, 54; 53, 69; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 61; 56, pattern_list; 56, 57; 56, 58; 56, 59; 56, 60; 57, identifier:r; 58, identifier:seqres; 59, identifier:ResidueAA; 60, identifier:Residue3AA; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:current_atom_site; 64, identifier:convert_to_residue; 65, argument_list; 65, 66; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:modified_residues; 69, if_statement; 69, 70; 69, 71; 70, identifier:r; 71, block; 71, 72; 72, if_statement; 72, 73; 72, 84; 72, 85; 73, not_operator; 73, 74; 74, parenthesized_expression; 74, 75; 75, boolean_operator:and; 75, 76; 75, 81; 76, comparison_operator:in; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:pdb_id; 80, identifier:cases_with_ACE_residues_we_can_ignore; 81, comparison_operator:==; 81, 82; 81, 83; 82, identifier:Residue3AA; 83, string:'ACE'; 84, comment; 85, block; 85, 86; 85, 93; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:full_residue_id; 89, call; 89, 90; 89, 91; 90, identifier:str; 91, argument_list; 91, 92; 92, identifier:r; 93, if_statement; 93, 94; 93, 102; 93, 116; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_residues_read; 99, identifier:get; 100, argument_list; 100, 101; 101, identifier:full_residue_id; 102, block; 102, 103; 103, assert_statement; 103, 104; 104, parenthesized_expression; 104, 105; 105, comparison_operator:==; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:_residues_read; 110, identifier:full_residue_id; 111, tuple; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:r; 114, identifier:ResidueAA; 115, identifier:seqres; 116, else_clause; 116, 117; 117, block; 117, 118; 117, 130; 117, 150; 117, 158; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 125; 120, subscript; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:_residues_read; 124, identifier:full_residue_id; 125, tuple; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:r; 128, identifier:ResidueAA; 129, identifier:seqres; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 139; 132, subscript; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:_residue_map; 136, attribute; 136, 137; 136, 138; 137, identifier:r; 138, identifier:Chain; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:_residue_map; 144, identifier:get; 145, argument_list; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:r; 148, identifier:Chain; 149, dictionary; 150, assert_statement; 150, 151; 151, parenthesized_expression; 151, 152; 152, comparison_operator:==; 152, 153; 152, 157; 153, call; 153, 154; 153, 155; 154, identifier:type; 155, argument_list; 155, 156; 156, identifier:seqres; 157, identifier:int_type; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 172; 160, subscript; 160, 161; 160, 168; 161, subscript; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:_residue_map; 165, attribute; 165, 166; 165, 167; 166, identifier:r; 167, identifier:Chain; 168, call; 168, 169; 168, 170; 169, identifier:str; 170, argument_list; 170, 171; 171, identifier:r; 172, identifier:seqres; 173, comment; 174, elif_clause; 174, 175; 174, 178; 174, 179; 175, comparison_operator:==; 175, 176; 175, 177; 176, identifier:name; 177, string:'PDBx:group_PDB'; 178, comment; 179, block; 179, 180; 180, if_statement; 180, 181; 180, 184; 180, 191; 180, 202; 181, comparison_operator:==; 181, 182; 181, 183; 182, identifier:tag_content; 183, string:'ATOM'; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:current_atom_site; 189, identifier:IsATOM; 190, True; 191, elif_clause; 191, 192; 191, 195; 192, comparison_operator:==; 192, 193; 192, 194; 193, identifier:tag_content; 194, string:'HETATM'; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:current_atom_site; 200, identifier:IsHETATM; 201, True; 202, else_clause; 202, 203; 203, block; 203, 204; 204, raise_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:Exception; 207, argument_list; 207, 208; 208, binary_operator:%; 208, 209; 208, 210; 209, string:"PDBx:group_PDB was expected to be 'ATOM' or 'HETATM'. '%s' read instead."; 210, identifier:tag_content; 211, comment; 212, elif_clause; 212, 213; 212, 216; 213, comparison_operator:==; 213, 214; 213, 215; 214, identifier:name; 215, string:'PDBx:auth_asym_id'; 216, block; 216, 217; 216, 224; 216, 230; 217, assert_statement; 217, 218; 218, parenthesized_expression; 218, 219; 219, not_operator; 219, 220; 220, parenthesized_expression; 220, 221; 221, attribute; 221, 222; 221, 223; 222, identifier:current_atom_site; 223, identifier:PDBChainID; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:current_atom_site; 228, identifier:PDBChainID; 229, identifier:tag_content; 230, if_statement; 230, 231; 230, 233; 231, not_operator; 231, 232; 232, identifier:tag_content; 233, block; 233, 234; 233, 239; 234, assert_statement; 234, 235; 235, parenthesized_expression; 235, 236; 236, attribute; 236, 237; 236, 238; 237, identifier:current_atom_site; 238, identifier:PDBChainIDIsNull; 239, if_statement; 239, 240; 239, 249; 239, 257; 240, comparison_operator:==; 240, 241; 240, 248; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:pdb_id; 246, identifier:upper; 247, argument_list; 248, string:'2MBP'; 249, block; 249, 250; 249, 256; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:current_atom_site; 254, identifier:PDBChainID; 255, string:'A'; 256, comment; 257, else_clause; 257, 258; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:current_atom_site; 263, identifier:PDBChainID; 264, string:' '; 265, elif_clause; 265, 266; 265, 269; 266, comparison_operator:==; 266, 267; 266, 268; 267, identifier:name; 268, string:'PDBx:auth_seq_id'; 269, block; 269, 270; 269, 277; 270, assert_statement; 270, 271; 271, parenthesized_expression; 271, 272; 272, not_operator; 272, 273; 273, parenthesized_expression; 273, 274; 274, attribute; 274, 275; 274, 276; 275, identifier:current_atom_site; 276, identifier:ATOMResidueID; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:current_atom_site; 281, identifier:ATOMResidueID; 282, call; 282, 283; 282, 284; 283, identifier:int; 284, argument_list; 284, 285; 285, identifier:tag_content; 286, elif_clause; 286, 287; 286, 290; 287, comparison_operator:==; 287, 288; 287, 289; 288, identifier:name; 289, string:"PDBx:pdbx_PDB_ins_code"; 290, block; 290, 291; 291, if_statement; 291, 292; 291, 295; 291, 304; 292, attribute; 292, 293; 292, 294; 293, identifier:current_atom_site; 294, identifier:ATOMResidueiCodeIsNull; 295, block; 295, 296; 296, assert_statement; 296, 297; 297, parenthesized_expression; 297, 298; 298, comparison_operator:==; 298, 299; 298, 303; 299, call; 299, 300; 299, 301; 300, identifier:len; 301, argument_list; 301, 302; 302, identifier:tag_content; 303, integer:0; 304, else_clause; 304, 305; 305, block; 305, 306; 305, 313; 306, assert_statement; 306, 307; 307, parenthesized_expression; 307, 308; 308, comparison_operator:==; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:current_atom_site; 311, identifier:ATOMResidueiCode; 312, string:' '; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:current_atom_site; 317, identifier:ATOMResidueiCode; 318, identifier:tag_content; 319, elif_clause; 319, 320; 319, 323; 320, comparison_operator:==; 320, 321; 320, 322; 321, identifier:name; 322, string:"PDBx:auth_comp_id"; 323, block; 323, 324; 323, 331; 324, assert_statement; 324, 325; 325, parenthesized_expression; 325, 326; 326, not_operator; 326, 327; 327, parenthesized_expression; 327, 328; 328, attribute; 328, 329; 328, 330; 329, identifier:current_atom_site; 330, identifier:ATOMResidueAA; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:current_atom_site; 335, identifier:ATOMResidueAA; 336, identifier:tag_content; 337, elif_clause; 337, 338; 337, 341; 338, comparison_operator:==; 338, 339; 338, 340; 339, identifier:name; 340, string:"PDBx:label_seq_id"; 341, block; 341, 342; 341, 349; 342, assert_statement; 342, 343; 343, parenthesized_expression; 343, 344; 344, not_operator; 344, 345; 345, parenthesized_expression; 345, 346; 346, attribute; 346, 347; 346, 348; 347, identifier:current_atom_site; 348, identifier:SEQRESIndex; 349, expression_statement; 349, 350; 350, assignment; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:current_atom_site; 353, identifier:SEQRESIndex; 354, call; 354, 355; 354, 356; 355, identifier:int; 356, argument_list; 356, 357; 357, identifier:tag_content; 358, elif_clause; 358, 359; 358, 362; 359, comparison_operator:==; 359, 360; 359, 361; 360, identifier:name; 361, string:"PDBx:label_comp_id"; 362, block; 362, 363; 362, 370; 363, assert_statement; 363, 364; 364, parenthesized_expression; 364, 365; 365, not_operator; 365, 366; 366, parenthesized_expression; 366, 367; 367, attribute; 367, 368; 367, 369; 368, identifier:current_atom_site; 369, identifier:ATOMSeqresResidueAA; 370, expression_statement; 370, 371; 371, assignment; 371, 372; 371, 375; 372, attribute; 372, 373; 372, 374; 373, identifier:current_atom_site; 374, identifier:ATOMSeqresResidueAA; 375, identifier:tag_content | def parse_atom_tag_data(self, name, tag_content):
'''Parse the atom tag data.'''
current_atom_site = self.current_atom_site
if current_atom_site.IsHETATM:
# Early out - do not parse HETATM records
return
elif name == 'PDBx:atom_site':
# We have to handle the atom_site close tag here since we jump based on self._BLOCK first in end_element
#'''Add the residue to the residue map.'''
self._BLOCK = None
current_atom_site = self.current_atom_site
current_atom_site.validate()
if current_atom_site.IsATOM:
# Only parse ATOM records
r, seqres, ResidueAA, Residue3AA = current_atom_site.convert_to_residue(self.modified_residues)
if r:
if not(self.pdb_id in cases_with_ACE_residues_we_can_ignore and Residue3AA == 'ACE'):
# skip certain ACE residues
full_residue_id = str(r)
if self._residues_read.get(full_residue_id):
assert(self._residues_read[full_residue_id] == (r.ResidueAA, seqres))
else:
self._residues_read[full_residue_id] = (r.ResidueAA, seqres)
self._residue_map[r.Chain] = self._residue_map.get(r.Chain, {})
assert(type(seqres) == int_type)
self._residue_map[r.Chain][str(r)] = seqres
# Record type
elif name == 'PDBx:group_PDB':
# ATOM or HETATM
if tag_content == 'ATOM':
current_atom_site.IsATOM = True
elif tag_content == 'HETATM':
current_atom_site.IsHETATM = True
else:
raise Exception("PDBx:group_PDB was expected to be 'ATOM' or 'HETATM'. '%s' read instead." % tag_content)
# Residue identifier - chain ID, residue ID, insertion code
elif name == 'PDBx:auth_asym_id':
assert(not(current_atom_site.PDBChainID))
current_atom_site.PDBChainID = tag_content
if not tag_content:
assert(current_atom_site.PDBChainIDIsNull)
if self.pdb_id.upper() == '2MBP':
current_atom_site.PDBChainID = 'A' # e.g. 2MBP
else:
current_atom_site.PDBChainID = ' '
elif name == 'PDBx:auth_seq_id':
assert(not(current_atom_site.ATOMResidueID))
current_atom_site.ATOMResidueID = int(tag_content)
elif name == "PDBx:pdbx_PDB_ins_code":
if current_atom_site.ATOMResidueiCodeIsNull:
assert(len(tag_content) == 0)
else:
assert(current_atom_site.ATOMResidueiCode == ' ')
current_atom_site.ATOMResidueiCode = tag_content
elif name == "PDBx:auth_comp_id":
assert(not(current_atom_site.ATOMResidueAA))
current_atom_site.ATOMResidueAA = tag_content
elif name == "PDBx:label_seq_id":
assert(not(current_atom_site.SEQRESIndex))
current_atom_site.SEQRESIndex = int(tag_content)
elif name == "PDBx:label_comp_id":
assert(not(current_atom_site.ATOMSeqresResidueAA))
current_atom_site.ATOMSeqresResidueAA = tag_content |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:link; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 4, default_parameter; 4, 5; 4, 6; 5, identifier:origin; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:rel; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:value; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:attributes; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:source; 18, None; 19, block; 19, 20; 19, 22; 19, 28; 19, 29; 19, 244; 20, expression_statement; 20, 21; 21, string:'''
Action function generator to create a link based on the context's current link, or on provided parameters
:param origin: IRI/string, or list of same; origins for the created relationships.
If None, the action context provides the parameter.
:param rel: IRI/string, or list of same; IDs for the created relationships.
If None, the action context provides the parameter.
:param value: IRI/string, or list of same; values/targets for the created relationships.
If None, the action context provides the parameter.
:param source: pattern action to be executed, generating contexts to determine the output statements. If given, overrides specific origin, rel or value params
:return: Versa action function to do the actual work
'''; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:attributes; 25, boolean_operator:or; 25, 26; 25, 27; 26, identifier:attributes; 27, dictionary; 28, comment; 29, function_definition; 29, 30; 29, 31; 29, 33; 30, function_name:_link; 31, parameters; 31, 32; 32, identifier:ctx; 33, block; 33, 34; 33, 85; 33, 95; 33, 108; 33, 127; 33, 128; 33, 141; 33, 160; 33, 161; 33, 174; 33, 193; 33, 194; 33, 207; 33, 208; 33, 209; 33, 243; 34, if_statement; 34, 35; 34, 36; 35, identifier:source; 36, block; 36, 37; 36, 49; 36, 56; 36, 84; 37, if_statement; 37, 38; 37, 43; 38, not_operator; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:callable; 41, argument_list; 41, 42; 42, identifier:source; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:ValueError; 47, argument_list; 47, 48; 48, string:'Link source must be a pattern action function'; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:contexts; 52, call; 52, 53; 52, 54; 53, identifier:source; 54, argument_list; 54, 55; 55, identifier:ctx; 56, for_statement; 56, 57; 56, 58; 56, 59; 57, identifier:ctx; 58, identifier:contexts; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:ctx; 65, identifier:output_model; 66, identifier:add; 67, argument_list; 67, 68; 67, 73; 67, 78; 67, 83; 68, subscript; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:ctx; 71, identifier:current_link; 72, identifier:ORIGIN; 73, subscript; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:ctx; 76, identifier:current_link; 77, identifier:RELATIONSHIP; 78, subscript; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:ctx; 81, identifier:current_link; 82, identifier:TARGET; 83, identifier:attributes; 84, return_statement; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 92; 87, tuple_pattern; 87, 88; 87, 89; 87, 90; 87, 91; 88, identifier:o; 89, identifier:r; 90, identifier:v; 91, identifier:a; 92, attribute; 92, 93; 92, 94; 93, identifier:ctx; 94, identifier:current_link; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:_origin; 98, conditional_expression:if; 98, 99; 98, 103; 98, 107; 99, call; 99, 100; 99, 101; 100, identifier:origin; 101, argument_list; 101, 102; 102, identifier:ctx; 103, call; 103, 104; 103, 105; 104, identifier:callable; 105, argument_list; 105, 106; 106, identifier:origin; 107, identifier:origin; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:o_list; 111, conditional_expression:if; 111, 112; 111, 114; 111, 117; 112, list:[o]; 112, 113; 113, identifier:o; 114, comparison_operator:is; 114, 115; 114, 116; 115, identifier:_origin; 116, None; 117, parenthesized_expression; 117, 118; 118, conditional_expression:if; 118, 119; 118, 120; 118, 125; 119, identifier:_origin; 120, call; 120, 121; 120, 122; 121, identifier:isinstance; 122, argument_list; 122, 123; 122, 124; 123, identifier:_origin; 124, identifier:list; 125, list:[_origin]; 125, 126; 126, identifier:_origin; 127, comment; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:_rel; 131, conditional_expression:if; 131, 132; 131, 136; 131, 140; 132, call; 132, 133; 132, 134; 133, identifier:rel; 134, argument_list; 134, 135; 135, identifier:ctx; 136, call; 136, 137; 136, 138; 137, identifier:callable; 138, argument_list; 138, 139; 139, identifier:rel; 140, identifier:rel; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:r_list; 144, conditional_expression:if; 144, 145; 144, 147; 144, 150; 145, list:[r]; 145, 146; 146, identifier:r; 147, comparison_operator:is; 147, 148; 147, 149; 148, identifier:_rel; 149, None; 150, parenthesized_expression; 150, 151; 151, conditional_expression:if; 151, 152; 151, 153; 151, 158; 152, identifier:_rel; 153, call; 153, 154; 153, 155; 154, identifier:isinstance; 155, argument_list; 155, 156; 155, 157; 156, identifier:_rel; 157, identifier:list; 158, list:[_rel]; 158, 159; 159, identifier:_rel; 160, comment; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:_value; 164, conditional_expression:if; 164, 165; 164, 169; 164, 173; 165, call; 165, 166; 165, 167; 166, identifier:value; 167, argument_list; 167, 168; 168, identifier:ctx; 169, call; 169, 170; 169, 171; 170, identifier:callable; 171, argument_list; 171, 172; 172, identifier:value; 173, identifier:value; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:v_list; 177, conditional_expression:if; 177, 178; 177, 180; 177, 183; 178, list:[v]; 178, 179; 179, identifier:v; 180, comparison_operator:is; 180, 181; 180, 182; 181, identifier:_value; 182, None; 183, parenthesized_expression; 183, 184; 184, conditional_expression:if; 184, 185; 184, 186; 184, 191; 185, identifier:_value; 186, call; 186, 187; 186, 188; 187, identifier:isinstance; 188, argument_list; 188, 189; 188, 190; 189, identifier:_value; 190, identifier:list; 191, list:[_value]; 191, 192; 192, identifier:_value; 193, comment; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:_attributes; 197, conditional_expression:if; 197, 198; 197, 202; 197, 206; 198, call; 198, 199; 198, 200; 199, identifier:attributes; 200, argument_list; 200, 201; 201, identifier:ctx; 202, call; 202, 203; 202, 204; 203, identifier:callable; 204, argument_list; 204, 205; 205, identifier:attributes; 206, identifier:attributes; 207, comment; 208, comment; 209, for_statement; 209, 210; 209, 215; 209, 230; 210, tuple_pattern; 210, 211; 210, 212; 210, 213; 210, 214; 211, identifier:o; 212, identifier:r; 213, identifier:v; 214, identifier:a; 215, list_comprehension; 215, 216; 215, 221; 215, 224; 215, 227; 216, tuple; 216, 217; 216, 218; 216, 219; 216, 220; 217, identifier:o; 218, identifier:r; 219, identifier:v; 220, identifier:a; 221, for_in_clause; 221, 222; 221, 223; 222, identifier:o; 223, identifier:o_list; 224, for_in_clause; 224, 225; 224, 226; 225, identifier:r; 226, identifier:r_list; 227, for_in_clause; 227, 228; 227, 229; 228, identifier:v; 229, identifier:v_list; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 238; 233, attribute; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:ctx; 236, identifier:output_model; 237, identifier:add; 238, argument_list; 238, 239; 238, 240; 238, 241; 238, 242; 239, identifier:o; 240, identifier:r; 241, identifier:v; 242, identifier:attributes; 243, return_statement; 244, return_statement; 244, 245; 245, identifier:_link | def link(origin=None, rel=None, value=None, attributes=None, source=None):
'''
Action function generator to create a link based on the context's current link, or on provided parameters
:param origin: IRI/string, or list of same; origins for the created relationships.
If None, the action context provides the parameter.
:param rel: IRI/string, or list of same; IDs for the created relationships.
If None, the action context provides the parameter.
:param value: IRI/string, or list of same; values/targets for the created relationships.
If None, the action context provides the parameter.
:param source: pattern action to be executed, generating contexts to determine the output statements. If given, overrides specific origin, rel or value params
:return: Versa action function to do the actual work
'''
attributes = attributes or {}
#rel = I(iri.absolutize(rel, ctx.base))
def _link(ctx):
if source:
if not callable(source):
raise ValueError('Link source must be a pattern action function')
contexts = source(ctx)
for ctx in contexts:
ctx.output_model.add(ctx.current_link[ORIGIN], ctx.current_link[RELATIONSHIP], ctx.current_link[TARGET], attributes)
return
(o, r, v, a) = ctx.current_link
_origin = origin(ctx) if callable(origin) else origin
o_list = [o] if _origin is None else (_origin if isinstance(_origin, list) else [_origin])
#_origin = _origin if isinstance(_origin, set) else set([_origin])
_rel = rel(ctx) if callable(rel) else rel
r_list = [r] if _rel is None else (_rel if isinstance(_rel, list) else [_rel])
#_rel = _rel if isinstance(_rel, set) else set([_rel])
_value = value(ctx) if callable(value) else value
v_list = [v] if _value is None else (_value if isinstance(_value, list) else [_value])
#_target = _target if isinstance(_target, set) else set([_target])
_attributes = attributes(ctx) if callable(attributes) else attributes
#(ctx_o, ctx_r, ctx_t, ctx_a) = ctx.current_link
#FIXME: Add test for IRI output via wrapper action function
for (o, r, v, a) in [ (o, r, v, a) for o in o_list for r in r_list for v in v_list ]:
ctx.output_model.add(o, r, v, attributes)
return
return _link |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:foreach; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:origin; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:rel; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:target; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:attributes; 15, None; 16, block; 16, 17; 16, 19; 16, 199; 17, expression_statement; 17, 18; 18, string:'''
Action function generator to compute a combination of links
:return: Versa action function to do the actual work
'''; 19, function_definition; 19, 20; 19, 21; 19, 23; 20, function_name:_foreach; 21, parameters; 21, 22; 22, identifier:ctx; 23, block; 23, 24; 23, 26; 23, 39; 23, 52; 23, 65; 23, 78; 23, 88; 23, 107; 23, 126; 23, 145; 23, 146; 23, 165; 23, 166; 23, 167; 23, 196; 23, 197; 23, 198; 24, expression_statement; 24, 25; 25, string:'''
Versa action function utility to compute a list of values from a list of expressions
:param ctx: Versa context used in processing (e.g. includes the prototype link)
'''; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:_origin; 29, conditional_expression:if; 29, 30; 29, 34; 29, 38; 30, call; 30, 31; 30, 32; 31, identifier:origin; 32, argument_list; 32, 33; 33, identifier:ctx; 34, call; 34, 35; 34, 36; 35, identifier:callable; 36, argument_list; 36, 37; 37, identifier:origin; 38, identifier:origin; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:_rel; 42, conditional_expression:if; 42, 43; 42, 47; 42, 51; 43, call; 43, 44; 43, 45; 44, identifier:rel; 45, argument_list; 45, 46; 46, identifier:ctx; 47, call; 47, 48; 47, 49; 48, identifier:callable; 49, argument_list; 49, 50; 50, identifier:rel; 51, identifier:rel; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:_target; 55, conditional_expression:if; 55, 56; 55, 60; 55, 64; 56, call; 56, 57; 56, 58; 57, identifier:target; 58, argument_list; 58, 59; 59, identifier:ctx; 60, call; 60, 61; 60, 62; 61, identifier:callable; 62, argument_list; 62, 63; 63, identifier:target; 64, identifier:target; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:_attributes; 68, conditional_expression:if; 68, 69; 68, 73; 68, 77; 69, call; 69, 70; 69, 71; 70, identifier:attributes; 71, argument_list; 71, 72; 72, identifier:ctx; 73, call; 73, 74; 73, 75; 74, identifier:callable; 75, argument_list; 75, 76; 76, identifier:attributes; 77, identifier:attributes; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 85; 80, tuple_pattern; 80, 81; 80, 82; 80, 83; 80, 84; 81, identifier:o; 82, identifier:r; 83, identifier:t; 84, identifier:a; 85, attribute; 85, 86; 85, 87; 86, identifier:ctx; 87, identifier:current_link; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:o; 91, conditional_expression:if; 91, 92; 91, 94; 91, 97; 92, list:[o]; 92, 93; 93, identifier:o; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:_origin; 96, None; 97, parenthesized_expression; 97, 98; 98, conditional_expression:if; 98, 99; 98, 100; 98, 105; 99, identifier:_origin; 100, call; 100, 101; 100, 102; 101, identifier:isinstance; 102, argument_list; 102, 103; 102, 104; 103, identifier:_origin; 104, identifier:list; 105, list:[_origin]; 105, 106; 106, identifier:_origin; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:r; 110, conditional_expression:if; 110, 111; 110, 113; 110, 116; 111, list:[r]; 111, 112; 112, identifier:r; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:_rel; 115, None; 116, parenthesized_expression; 116, 117; 117, conditional_expression:if; 117, 118; 117, 119; 117, 124; 118, identifier:_rel; 119, call; 119, 120; 119, 121; 120, identifier:isinstance; 121, argument_list; 121, 122; 121, 123; 122, identifier:_rel; 123, identifier:list; 124, list:[_rel]; 124, 125; 125, identifier:_rel; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:t; 129, conditional_expression:if; 129, 130; 129, 132; 129, 135; 130, list:[t]; 130, 131; 131, identifier:t; 132, comparison_operator:is; 132, 133; 132, 134; 133, identifier:_target; 134, None; 135, parenthesized_expression; 135, 136; 136, conditional_expression:if; 136, 137; 136, 138; 136, 143; 137, identifier:_target; 138, call; 138, 139; 138, 140; 139, identifier:isinstance; 140, argument_list; 140, 141; 140, 142; 141, identifier:_target; 142, identifier:list; 143, list:[_target]; 143, 144; 144, identifier:_target; 145, comment; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:a; 149, conditional_expression:if; 149, 150; 149, 152; 149, 155; 150, list:[a]; 150, 151; 151, identifier:a; 152, comparison_operator:is; 152, 153; 152, 154; 153, identifier:_attributes; 154, None; 155, parenthesized_expression; 155, 156; 156, conditional_expression:if; 156, 157; 156, 158; 156, 163; 157, identifier:_attributes; 158, call; 158, 159; 158, 160; 159, identifier:isinstance; 160, argument_list; 160, 161; 160, 162; 161, identifier:_attributes; 162, identifier:list; 163, list:[_attributes]; 163, 164; 164, identifier:_attributes; 165, comment; 166, comment; 167, return_statement; 167, 168; 168, list_comprehension; 168, 169; 168, 181; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:ctx; 172, identifier:copy; 173, argument_list; 173, 174; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:current_link; 176, tuple; 176, 177; 176, 178; 176, 179; 176, 180; 177, identifier:curr_o; 178, identifier:curr_r; 179, identifier:curr_t; 180, identifier:curr_a; 181, for_in_clause; 181, 182; 181, 187; 182, tuple_pattern; 182, 183; 182, 184; 182, 185; 182, 186; 183, identifier:curr_o; 184, identifier:curr_r; 185, identifier:curr_t; 186, identifier:curr_a; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:itertools; 190, identifier:product; 191, argument_list; 191, 192; 191, 193; 191, 194; 191, 195; 192, identifier:o; 193, identifier:r; 194, identifier:t; 195, identifier:a; 196, comment; 197, comment; 198, comment; 199, return_statement; 199, 200; 200, identifier:_foreach | def foreach(origin=None, rel=None, target=None, attributes=None):
'''
Action function generator to compute a combination of links
:return: Versa action function to do the actual work
'''
def _foreach(ctx):
'''
Versa action function utility to compute a list of values from a list of expressions
:param ctx: Versa context used in processing (e.g. includes the prototype link)
'''
_origin = origin(ctx) if callable(origin) else origin
_rel = rel(ctx) if callable(rel) else rel
_target = target(ctx) if callable(target) else target
_attributes = attributes(ctx) if callable(attributes) else attributes
(o, r, t, a) = ctx.current_link
o = [o] if _origin is None else (_origin if isinstance(_origin, list) else [_origin])
r = [r] if _rel is None else (_rel if isinstance(_rel, list) else [_rel])
t = [t] if _target is None else (_target if isinstance(_target, list) else [_target])
#a = [a] if _attributes is None else _attributes
a = [a] if _attributes is None else (_attributes if isinstance(_attributes, list) else [_attributes])
#print([(curr_o, curr_r, curr_t, curr_a) for (curr_o, curr_r, curr_t, curr_a)
# in product(o, r, t, a)])
return [ ctx.copy(current_link=(curr_o, curr_r, curr_t, curr_a))
for (curr_o, curr_r, curr_t, curr_a)
in itertools.product(o, r, t, a) ]
#for (curr_o, curr_r, curr_t, curr_a) in product(origin or [o], rel or [r], target or [t], attributes or [a]):
# newctx = ctx.copy(current_link=(curr_o, curr_r, curr_t, curr_a))
#ctx.output_model.add(I(objid), VTYPE_REL, I(iri.absolutize(_typ, ctx.base)), {})
return _foreach |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_method_documentation; 3, parameters; 3, 4; 4, identifier:method; 5, block; 5, 6; 5, 8; 5, 13; 5, 45; 5, 52; 5, 56; 5, 179; 5, 190; 5, 205; 5, 345; 5, 356; 6, expression_statement; 6, 7; 7, comment; 8, import_from_statement; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier:inspect; 11, dotted_name; 11, 12; 12, identifier:getargspec; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:result; 16, dictionary; 16, 17; 16, 22; 17, pair; 17, 18; 17, 19; 18, string:'name'; 19, attribute; 19, 20; 19, 21; 20, identifier:method; 21, identifier:__name__; 22, pair; 22, 23; 22, 24; 23, string:'friendly_name'; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, string:' '; 27, identifier:join; 28, argument_list; 28, 29; 29, list_comprehension; 29, 30; 29, 35; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:name; 33, identifier:capitalize; 34, argument_list; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:name; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:method; 41, identifier:__name__; 42, identifier:split; 43, argument_list; 43, 44; 44, string:'_'; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:arg_specs; 48, call; 48, 49; 48, 50; 49, identifier:getargspec; 50, argument_list; 50, 51; 51, identifier:method; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:arguments; 55, dictionary; 56, if_statement; 56, 57; 56, 61; 56, 91; 57, not_operator; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:arg_specs; 60, identifier:defaults; 61, block; 61, 62; 62, if_statement; 62, 63; 62, 75; 63, comparison_operator:>; 63, 64; 63, 74; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:arg_specs; 70, identifier:args; 71, slice; 71, 72; 71, 73; 72, integer:1; 73, colon; 74, integer:0; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, subscript; 78, 79; 78, 80; 79, identifier:arguments; 80, string:'required'; 81, call; 81, 82; 81, 83; 82, identifier:list; 83, argument_list; 83, 84; 84, subscript; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:arg_specs; 87, identifier:args; 88, slice; 88, 89; 88, 90; 89, integer:1; 90, colon; 91, else_clause; 91, 92; 92, block; 92, 93; 92, 136; 92, 142; 93, if_statement; 93, 94; 93, 112; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, subscript; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:arg_specs; 100, identifier:args; 101, slice; 101, 102; 101, 103; 101, 104; 102, integer:1; 103, colon; 104, unary_operator:-; 104, 105; 105, parenthesized_expression; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:len; 108, argument_list; 108, 109; 109, attribute; 109, 110; 109, 111; 110, identifier:arg_specs; 111, identifier:defaults; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:arguments; 117, string:'required'; 118, call; 118, 119; 118, 120; 119, identifier:list; 120, argument_list; 120, 121; 121, subscript; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:arg_specs; 124, identifier:args; 125, slice; 125, 126; 125, 127; 125, 128; 126, integer:1; 127, colon; 128, unary_operator:-; 128, 129; 129, parenthesized_expression; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:len; 132, argument_list; 132, 133; 133, attribute; 133, 134; 133, 135; 134, identifier:arg_specs; 135, identifier:defaults; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:arguments; 140, string:'optional'; 141, dictionary; 142, for_statement; 142, 143; 142, 144; 142, 153; 143, identifier:i; 144, call; 144, 145; 144, 146; 145, identifier:range; 146, argument_list; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:len; 149, argument_list; 149, 150; 150, attribute; 150, 151; 150, 152; 151, identifier:arg_specs; 152, identifier:defaults; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 174; 156, subscript; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:arguments; 159, string:'optional'; 160, subscript; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:arg_specs; 163, identifier:args; 164, binary_operator:+; 164, 165; 164, 173; 165, unary_operator:-; 165, 166; 166, parenthesized_expression; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:len; 169, argument_list; 169, 170; 170, attribute; 170, 171; 170, 172; 171, identifier:arg_specs; 172, identifier:defaults; 173, identifier:i; 174, subscript; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:arg_specs; 177, identifier:defaults; 178, identifier:i; 179, if_statement; 179, 180; 179, 183; 180, comparison_operator:!=; 180, 181; 180, 182; 181, identifier:arguments; 182, dictionary; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:result; 188, string:'parameters'; 189, identifier:arguments; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:doc; 193, conditional_expression:if; 193, 194; 193, 201; 193, 204; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:method; 198, identifier:__doc__; 199, identifier:strip; 200, argument_list; 201, attribute; 201, 202; 201, 203; 202, identifier:method; 203, identifier:__doc__; 204, string:''; 205, if_statement; 205, 206; 205, 211; 206, comparison_operator:in; 206, 207; 206, 208; 207, string:':'; 208, attribute; 208, 209; 208, 210; 209, identifier:method; 210, identifier:__doc__; 211, block; 211, 212; 211, 235; 211, 247; 211, 281; 211, 297; 211, 308; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:doc; 215, dictionary; 215, 216; 216, pair; 216, 217; 216, 218; 217, string:'summary'; 218, call; 218, 219; 218, 234; 219, attribute; 219, 220; 219, 233; 220, subscript; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:method; 223, identifier:__doc__; 224, slice; 224, 225; 224, 226; 224, 227; 225, integer:0; 226, colon; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:doc; 230, identifier:find; 231, argument_list; 231, 232; 232, string:' :'; 233, identifier:strip; 234, argument_list; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:params; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:re; 241, identifier:findall; 242, argument_list; 242, 243; 242, 244; 243, string:r":param ([^\s]*): (.*)\n"; 244, attribute; 244, 245; 244, 246; 245, identifier:method; 246, identifier:__doc__; 247, if_statement; 247, 248; 247, 254; 248, comparison_operator:>; 248, 249; 248, 253; 249, call; 249, 250; 249, 251; 250, identifier:len; 251, argument_list; 251, 252; 252, identifier:params; 253, integer:0; 254, block; 254, 255; 254, 261; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 260; 257, subscript; 257, 258; 257, 259; 258, identifier:doc; 259, string:'parameters'; 260, dictionary; 261, for_statement; 261, 262; 261, 263; 261, 264; 262, identifier:param; 263, identifier:params; 264, block; 264, 265; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 274; 267, subscript; 267, 268; 267, 271; 268, subscript; 268, 269; 268, 270; 269, identifier:doc; 270, string:'parameters'; 271, subscript; 271, 272; 271, 273; 272, identifier:param; 273, integer:0; 274, call; 274, 275; 274, 280; 275, attribute; 275, 276; 275, 279; 276, subscript; 276, 277; 276, 278; 277, identifier:param; 278, integer:1; 279, identifier:strip; 280, argument_list; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:regex; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:re; 287, identifier:compile; 288, argument_list; 288, 289; 288, 290; 289, string:r":returns:(.*)"; 290, binary_operator:|; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:re; 293, identifier:MULTILINE; 294, attribute; 294, 295; 294, 296; 295, identifier:re; 296, identifier:DOTALL; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 300; 299, identifier:returns; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:regex; 303, identifier:search; 304, argument_list; 304, 305; 305, attribute; 305, 306; 305, 307; 306, identifier:method; 307, identifier:__doc__; 308, if_statement; 308, 309; 308, 317; 309, boolean_operator:and; 309, 310; 309, 311; 310, identifier:returns; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:returns; 314, identifier:group; 315, argument_list; 315, 316; 316, integer:0; 317, block; 317, 318; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 323; 320, subscript; 320, 321; 320, 322; 321, identifier:doc; 322, string:'return'; 323, call; 323, 324; 323, 344; 324, attribute; 324, 325; 324, 343; 325, call; 325, 326; 325, 340; 326, attribute; 326, 327; 326, 339; 327, call; 327, 328; 327, 336; 328, attribute; 328, 329; 328, 335; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:returns; 332, identifier:group; 333, argument_list; 333, 334; 334, integer:0; 335, identifier:replace; 336, argument_list; 336, 337; 336, 338; 337, string:':returns:'; 338, string:''; 339, identifier:replace; 340, argument_list; 340, 341; 340, 342; 341, string:'\n '; 342, string:'\n'; 343, identifier:strip; 344, argument_list; 345, if_statement; 345, 346; 345, 349; 346, comparison_operator:!=; 346, 347; 346, 348; 347, identifier:doc; 348, string:''; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 355; 352, subscript; 352, 353; 352, 354; 353, identifier:result; 354, string:'help'; 355, identifier:doc; 356, return_statement; 356, 357; 357, identifier:result | def get_method_documentation(method):
"""
This function uses "inspect" to retrieve information about a method.
Also, if you place comment on the method, method can be docummented with "reStructured Text".
:param method: method to describe
:returns:
{
'name' : <string> - name of the method,
'friendly_name' : <string> - friendly name of the method,
'parameters' : {
'required' : [ 'param1', 'param2' ],
'optionnal' : {
'param3' : 'default_value3',
'param4' : 'default_value4',
},
'help' : {
'summary' : <string> - Summary - general description like in the comment,
'parameters' : {
'param1' : 'description',
'param2' : 'description',
},
'return' : <string> - Can be multiline,
}
}
"""
from inspect import getargspec
result = {
'name': method.__name__,
'friendly_name': ' '.join([name.capitalize() for name in method.__name__.split('_')]),
}
arg_specs = getargspec(method)
arguments = {}
if not arg_specs.defaults:
if len(arg_specs.args[1:]) > 0:
arguments['required'] = list(arg_specs.args[1:])
else:
if len(arg_specs.args[1:-(len(arg_specs.defaults))]):
arguments['required'] = list(arg_specs.args[1:-(len(arg_specs.defaults))])
arguments['optional'] = {}
for i in range(len(arg_specs.defaults)):
arguments['optional'][arg_specs.args[-(len(arg_specs.defaults)) + i]] = arg_specs.defaults[i]
if arguments != {}:
result['parameters'] = arguments
doc = method.__doc__.strip() if method.__doc__ else ''
if ':' in method.__doc__:
doc = {'summary': method.__doc__[0:doc.find(' :')].strip()}
params = re.findall(r":param ([^\s]*): (.*)\n", method.__doc__)
if len(params) > 0:
doc['parameters'] = {}
for param in params:
doc['parameters'][param[0]] = param[1].strip()
regex = re.compile(r":returns:(.*)", re.MULTILINE | re.DOTALL)
returns = regex.search(method.__doc__)
if returns and returns.group(0):
doc['return'] = returns.group(0).replace(':returns:', '').replace('\n ', '\n').strip()
if doc != '':
result['help'] = doc
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_dictionary_list; 3, parameters; 3, 4; 3, 5; 4, identifier:dict_list; 5, identifier:sort_key; 6, block; 6, 7; 6, 9; 6, 22; 6, 34; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 19; 10, boolean_operator:or; 10, 11; 10, 13; 11, not_operator; 11, 12; 12, identifier:dict_list; 13, comparison_operator:==; 13, 14; 13, 18; 14, call; 14, 15; 14, 16; 15, identifier:len; 16, argument_list; 16, 17; 17, identifier:dict_list; 18, integer:0; 19, block; 19, 20; 20, return_statement; 20, 21; 21, identifier:dict_list; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:dict_list; 26, identifier:sort; 27, argument_list; 27, 28; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:key; 30, call; 30, 31; 30, 32; 31, identifier:itemgetter; 32, argument_list; 32, 33; 33, identifier:sort_key; 34, return_statement; 34, 35; 35, identifier:dict_list | def sort_dictionary_list(dict_list, sort_key):
"""
sorts a list of dictionaries based on the value of the sort_key
dict_list - a list of dictionaries
sort_key - a string that identifies the key to sort the dictionaries with.
Test sorting a list of dictionaries:
>>> sort_dictionary_list([{'b' : 1, 'value' : 2}, {'c' : 2, 'value' : 3}, {'a' : 3, 'value' : 1}], 'value')
[{'a': 3, 'value': 1}, {'b': 1, 'value': 2}, {'c': 2, 'value': 3}]
"""
if not dict_list or len(dict_list) == 0:
return dict_list
dict_list.sort(key=itemgetter(sort_key))
return dict_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_push; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:title; 6, identifier:view; 7, identifier:class_name; 8, identifier:is_class; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 14; 11, 15; 11, 25; 11, 31; 11, 37; 11, 49; 11, 59; 11, 67; 11, 77; 11, 78; 11, 91; 11, 101; 11, 118; 11, 124; 11, 125; 11, 136; 11, 149; 11, 165; 11, 171; 11, 177; 11, 183; 11, 189; 11, 232; 11, 240; 11, 251; 11, 261; 11, 272; 12, expression_statement; 12, 13; 13, comment; 14, comment; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:set_view_attr; 18, argument_list; 18, 19; 18, 20; 18, 21; 18, 22; 19, identifier:view; 20, string:"title"; 21, identifier:title; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:cls_name; 24, identifier:class_name; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:module_name; 28, attribute; 28, 29; 28, 30; 29, identifier:view; 30, identifier:__module__; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:method_name; 34, attribute; 34, 35; 34, 36; 35, identifier:view; 36, identifier:__name__; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:_endpoint; 40, call; 40, 41; 40, 42; 41, identifier:build_endpoint_route_name; 42, argument_list; 42, 43; 42, 44; 42, 48; 43, identifier:view; 44, conditional_expression:if; 44, 45; 44, 46; 44, 47; 45, string:"index"; 46, identifier:is_class; 47, identifier:method_name; 48, identifier:class_name; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:endpoint; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:kwargs; 55, identifier:pop; 56, argument_list; 56, 57; 56, 58; 57, string:"endpoint"; 58, identifier:_endpoint; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:kwargs; 63, identifier:setdefault; 64, argument_list; 64, 65; 64, 66; 65, string:"endpoint_kwargs"; 66, dictionary; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:order; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:kwargs; 73, identifier:pop; 74, argument_list; 74, 75; 74, 76; 75, string:"order"; 76, integer:0; 77, comment; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:_nav_tags; 81, call; 81, 82; 81, 83; 82, identifier:get_view_attr; 83, argument_list; 83, 84; 83, 85; 83, 86; 83, 88; 84, identifier:view; 85, string:"nav_tags"; 86, list:["default"]; 86, 87; 87, string:"default"; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:cls_name; 90, identifier:class_name; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:tags; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:kwargs; 97, identifier:pop; 98, argument_list; 98, 99; 98, 100; 99, string:"tags"; 100, identifier:_nav_tags; 101, if_statement; 101, 102; 101, 108; 102, not_operator; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:isinstance; 105, argument_list; 105, 106; 105, 107; 106, identifier:tags; 107, identifier:list; 108, block; 108, 109; 108, 113; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:_; 112, identifier:tags; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:tags; 116, list:[_]; 116, 117; 117, identifier:_; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:kwargs; 122, string:"tags"; 123, identifier:tags; 124, comment; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:visible; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:kwargs; 131, identifier:pop; 132, argument_list; 132, 133; 132, 134; 133, string:"visible"; 134, list:[True]; 134, 135; 135, True; 136, if_statement; 136, 137; 136, 143; 137, not_operator; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:isinstance; 140, argument_list; 140, 141; 140, 142; 141, identifier:visible; 142, identifier:list; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:visible; 147, list:[visible]; 147, 148; 148, identifier:visible; 149, if_statement; 149, 150; 149, 160; 150, comparison_operator:is; 150, 151; 150, 159; 151, call; 151, 152; 151, 153; 152, identifier:get_view_attr; 153, argument_list; 153, 154; 153, 155; 153, 156; 154, identifier:view; 155, string:"nav_visible"; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:cls_name; 158, identifier:class_name; 159, False; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:visible; 164, False; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:kwargs; 169, string:"view"; 170, identifier:view; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:kwargs; 175, string:"visible"; 176, identifier:visible; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:kwargs; 181, string:"active"; 182, False; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:kwargs; 187, string:"key"; 188, identifier:class_name; 189, if_statement; 189, 190; 189, 191; 189, 192; 189, 205; 190, identifier:is_class; 191, comment; 192, block; 192, 193; 192, 199; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, subscript; 195, 196; 195, 197; 196, identifier:kwargs; 197, string:"endpoint"; 198, identifier:endpoint; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:kwargs; 203, string:"has_subnav"; 204, True; 205, else_clause; 205, 206; 206, block; 206, 207; 206, 213; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:kwargs; 211, string:"has_subnav"; 212, False; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:kwargs; 217, identifier:update; 218, argument_list; 218, 219; 219, dictionary; 219, 220; 219, 223; 219, 226; 219, 229; 220, pair; 220, 221; 220, 222; 221, string:"order"; 222, identifier:order; 223, pair; 223, 224; 223, 225; 224, string:"has_subnav"; 225, False; 226, pair; 226, 227; 226, 228; 227, string:"title"; 228, identifier:title; 229, pair; 229, 230; 229, 231; 230, string:"endpoint"; 231, identifier:endpoint; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 239; 234, subscript; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:_title_map; 238, identifier:endpoint; 239, identifier:title; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:path; 243, binary_operator:%; 243, 244; 243, 245; 244, string:"%s.%s"; 245, tuple; 245, 246; 245, 247; 246, identifier:module_name; 247, conditional_expression:if; 247, 248; 247, 249; 247, 250; 248, identifier:method_name; 249, identifier:is_class; 250, identifier:class_name; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:attach_to; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:kwargs; 257, identifier:pop; 258, argument_list; 258, 259; 258, 260; 259, string:"attach_to"; 260, list:[]; 261, if_statement; 261, 262; 261, 264; 262, not_operator; 262, 263; 263, identifier:attach_to; 264, block; 264, 265; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:attach_to; 269, identifier:append; 270, argument_list; 270, 271; 271, identifier:path; 272, for_statement; 272, 273; 272, 274; 272, 275; 273, identifier:path; 274, identifier:attach_to; 275, block; 275, 276; 275, 309; 276, if_statement; 276, 277; 276, 282; 277, comparison_operator:not; 277, 278; 277, 279; 278, identifier:path; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:MENU; 282, block; 282, 283; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 290; 285, subscript; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:MENU; 289, identifier:path; 290, dictionary; 290, 291; 290, 294; 290, 297; 290, 300; 290, 303; 290, 306; 291, pair; 291, 292; 291, 293; 292, string:"title"; 293, None; 294, pair; 294, 295; 294, 296; 295, string:"endpoint"; 296, None; 297, pair; 297, 298; 297, 299; 298, string:"endpoint_kwargs"; 299, dictionary; 300, pair; 300, 301; 300, 302; 301, string:"order"; 302, None; 303, pair; 303, 304; 303, 305; 304, string:"subnav"; 305, list:[]; 306, pair; 306, 307; 306, 308; 307, string:"kwargs"; 308, dictionary; 309, if_statement; 309, 310; 309, 311; 309, 312; 309, 343; 310, identifier:is_class; 311, comment; 312, block; 312, 313; 312, 323; 312, 333; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 322; 315, subscript; 315, 316; 315, 321; 316, subscript; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:self; 319, identifier:MENU; 320, identifier:path; 321, string:"title"; 322, identifier:title; 323, expression_statement; 323, 324; 324, assignment; 324, 325; 324, 332; 325, subscript; 325, 326; 325, 331; 326, subscript; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:self; 329, identifier:MENU; 330, identifier:path; 331, string:"order"; 332, identifier:order; 333, expression_statement; 333, 334; 334, assignment; 334, 335; 334, 342; 335, subscript; 335, 336; 335, 341; 336, subscript; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:self; 339, identifier:MENU; 340, identifier:path; 341, string:"kwargs"; 342, identifier:kwargs; 343, else_clause; 343, 344; 343, 345; 344, comment; 345, block; 345, 346; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 357; 348, attribute; 348, 349; 348, 356; 349, subscript; 349, 350; 349, 355; 350, subscript; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:self; 353, identifier:MENU; 354, identifier:path; 355, string:"subnav"; 356, identifier:append; 357, argument_list; 357, 358; 358, identifier:kwargs | def _push(self, title, view, class_name, is_class, **kwargs):
""" Push nav data stack """
# Set the page title
set_view_attr(view, "title", title, cls_name=class_name)
module_name = view.__module__
method_name = view.__name__
_endpoint = build_endpoint_route_name(view, "index" if is_class else method_name, class_name)
endpoint = kwargs.pop("endpoint", _endpoint)
kwargs.setdefault("endpoint_kwargs", {})
order = kwargs.pop("order", 0)
# Tags
_nav_tags = get_view_attr(view, "nav_tags", ["default"], cls_name=class_name)
tags = kwargs.pop("tags", _nav_tags)
if not isinstance(tags, list):
_ = tags
tags = [_]
kwargs["tags"] = tags
# visible: accepts a bool or list of callback to execute
visible = kwargs.pop("visible", [True])
if not isinstance(visible, list):
visible = [visible]
if get_view_attr(view, "nav_visible", cls_name=class_name) is False:
visible = False
kwargs["view"] = view
kwargs["visible"] = visible
kwargs["active"] = False
kwargs["key"] = class_name
if is_class: # class menu
kwargs["endpoint"] = endpoint
kwargs["has_subnav"] = True
else:
kwargs["has_subnav"] = False
kwargs.update({
"order": order,
"has_subnav": False,
"title": title,
"endpoint": endpoint,
})
self._title_map[endpoint] = title
path = "%s.%s" % (module_name, method_name if is_class else class_name)
attach_to = kwargs.pop("attach_to", [])
if not attach_to:
attach_to.append(path)
for path in attach_to:
if path not in self.MENU:
self.MENU[path] = {
"title": None,
"endpoint": None,
"endpoint_kwargs": {},
"order": None,
"subnav": [],
"kwargs": {}
}
if is_class: # class menu
self.MENU[path]["title"] = title
self.MENU[path]["order"] = order
self.MENU[path]["kwargs"] = kwargs
else: # sub menu
self.MENU[path]["subnav"].append(kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:render; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 12; 5, 16; 5, 218; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:menu_list; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:menu_index; 15, integer:0; 16, for_statement; 16, 17; 16, 20; 16, 32; 17, pattern_list; 17, 18; 17, 19; 18, identifier:_; 19, identifier:menu; 20, call; 20, 21; 20, 31; 21, attribute; 21, 22; 21, 30; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:copy; 25, identifier:deepcopy; 26, argument_list; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:MENU; 30, identifier:items; 31, argument_list; 32, block; 32, 33; 32, 37; 32, 48; 32, 56; 32, 80; 32, 160; 32, 166; 32, 214; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:subnav; 36, list:[]; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 44; 39, subscript; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:menu; 42, string:"kwargs"; 43, string:"_id"; 44, call; 44, 45; 44, 46; 45, identifier:str; 46, argument_list; 46, 47; 47, identifier:menu_index; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 55; 50, subscript; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:menu; 53, string:"kwargs"; 54, string:"active"; 55, False; 56, if_statement; 56, 57; 56, 62; 57, comparison_operator:in; 57, 58; 57, 59; 58, string:"visible"; 59, subscript; 59, 60; 59, 61; 60, identifier:menu; 61, string:"kwargs"; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 70; 65, subscript; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:menu; 68, string:"kwargs"; 69, string:"visible"; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_test_visibility; 74, argument_list; 74, 75; 75, subscript; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:menu; 78, string:"kwargs"; 79, string:"visible"; 80, for_statement; 80, 81; 80, 82; 80, 85; 81, identifier:s; 82, subscript; 82, 83; 82, 84; 83, identifier:menu; 84, string:"subnav"; 85, block; 85, 86; 85, 104; 85, 127; 85, 140; 85, 144; 85, 153; 86, if_statement; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:s; 89, string:"title"; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:s; 95, string:"title"; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_get_title; 100, argument_list; 100, 101; 101, subscript; 101, 102; 101, 103; 102, identifier:s; 103, string:"title"; 104, if_statement; 104, 105; 104, 112; 105, comparison_operator:==; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:s; 108, string:"endpoint"; 109, attribute; 109, 110; 109, 111; 110, identifier:request; 111, identifier:endpoint; 112, block; 112, 113; 112, 119; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:s; 117, string:"active"; 118, True; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 126; 121, subscript; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:menu; 124, string:"kwargs"; 125, string:"active"; 126, True; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:s; 131, string:"visible"; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:_test_visibility; 136, argument_list; 136, 137; 137, subscript; 137, 138; 137, 139; 138, identifier:s; 139, string:"visible"; 140, expression_statement; 140, 141; 141, augmented_assignment:+=; 141, 142; 141, 143; 142, identifier:menu_index; 143, integer:1; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:s; 148, string:"_id"; 149, call; 149, 150; 149, 151; 150, identifier:str; 151, argument_list; 151, 152; 152, identifier:menu_index; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:subnav; 157, identifier:append; 158, argument_list; 158, 159; 159, identifier:s; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:_kwargs; 163, subscript; 163, 164; 163, 165; 164, identifier:menu; 165, string:"kwargs"; 166, if_statement; 166, 167; 166, 170; 166, 208; 167, subscript; 167, 168; 167, 169; 168, identifier:menu; 169, string:"title"; 170, block; 170, 171; 170, 201; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:_kwargs; 175, identifier:update; 176, argument_list; 176, 177; 177, dictionary; 177, 178; 177, 186; 177, 191; 178, pair; 178, 179; 178, 180; 179, string:"subnav"; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:_sort; 184, argument_list; 184, 185; 185, identifier:subnav; 186, pair; 186, 187; 186, 188; 187, string:"order"; 188, subscript; 188, 189; 188, 190; 189, identifier:menu; 190, string:"order"; 191, pair; 191, 192; 191, 193; 192, string:"title"; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:_get_title; 197, argument_list; 197, 198; 198, subscript; 198, 199; 198, 200; 199, identifier:menu; 200, string:"title"; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:menu_list; 205, identifier:append; 206, argument_list; 206, 207; 207, identifier:_kwargs; 208, else_clause; 208, 209; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, augmented_assignment:+=; 211, 212; 211, 213; 212, identifier:menu_list; 213, identifier:subnav; 214, expression_statement; 214, 215; 215, augmented_assignment:+=; 215, 216; 215, 217; 216, identifier:menu_index; 217, integer:1; 218, return_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:_sort; 223, argument_list; 223, 224; 224, identifier:menu_list | def render(self):
""" Render the menu into a sorted by order multi dict """
menu_list = []
menu_index = 0
for _, menu in copy.deepcopy(self.MENU).items():
subnav = []
menu["kwargs"]["_id"] = str(menu_index)
menu["kwargs"]["active"] = False
if "visible" in menu["kwargs"]:
menu["kwargs"]["visible"] = self._test_visibility(menu["kwargs"]["visible"])
for s in menu["subnav"]:
if s["title"]:
s["title"] = self._get_title(s["title"])
if s["endpoint"] == request.endpoint:
s["active"] = True
menu["kwargs"]["active"] = True
s["visible"] = self._test_visibility(s["visible"])
menu_index += 1
s["_id"] = str(menu_index)
subnav.append(s)
_kwargs = menu["kwargs"]
if menu["title"]:
_kwargs.update({
"subnav": self._sort(subnav),
"order": menu["order"],
"title": self._get_title(menu["title"])
})
menu_list.append(_kwargs)
else:
menu_list += subnav
menu_index += 1
return self._sort(menu_list) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:add_item; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:url; 6, default_parameter; 6, 7; 6, 8; 7, identifier:title; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:selection; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:jsonp; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:redirect; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:response_info; 20, False; 21, block; 21, 22; 21, 24; 21, 41; 21, 42; 21, 61; 21, 72; 21, 83; 21, 94; 21, 95; 21, 109; 21, 110; 21, 117; 21, 128; 21, 129; 22, expression_statement; 22, 23; 23, comment; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:parameters; 27, dictionary; 27, 28; 27, 33; 27, 38; 28, pair; 28, 29; 28, 30; 29, string:'username'; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:user; 33, pair; 33, 34; 33, 35; 34, string:'password'; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:password; 38, pair; 38, 39; 38, 40; 39, string:'url'; 40, identifier:url; 41, comment; 42, if_statement; 42, 43; 42, 46; 42, 53; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:title; 45, None; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:parameters; 51, string:'title'; 52, identifier:title; 53, else_clause; 53, 54; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:parameters; 59, string:'auto-title'; 60, integer:1; 61, if_statement; 61, 62; 61, 65; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:selection; 64, None; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:parameters; 70, string:'selection'; 71, identifier:selection; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:is; 73, 74; 73, 75; 74, identifier:redirect; 75, None; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:parameters; 81, string:'redirect'; 82, identifier:redirect; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:is; 84, 85; 84, 86; 85, identifier:jsonp; 86, None; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:parameters; 92, string:'jsonp'; 93, identifier:jsonp; 94, comment; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, pattern_list; 97, 98; 97, 99; 98, identifier:status; 99, identifier:headers; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:_query; 104, argument_list; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:addurl; 108, identifier:parameters; 109, comment; 110, if_statement; 110, 111; 110, 114; 111, comparison_operator:is; 111, 112; 111, 113; 112, identifier:jsonp; 113, None; 114, block; 114, 115; 115, return_statement; 115, 116; 116, identifier:status; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:statustxt; 120, subscript; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:add_status_codes; 124, call; 124, 125; 124, 126; 125, identifier:int; 126, argument_list; 126, 127; 127, identifier:status; 128, comment; 129, if_statement; 129, 130; 129, 131; 129, 145; 130, identifier:response_info; 131, block; 131, 132; 132, return_statement; 132, 133; 133, tuple; 133, 134; 133, 138; 133, 139; 133, 142; 134, call; 134, 135; 134, 136; 135, identifier:int; 136, argument_list; 136, 137; 137, identifier:status; 138, identifier:statustxt; 139, subscript; 139, 140; 139, 141; 140, identifier:headers; 141, string:'title'; 142, subscript; 142, 143; 142, 144; 143, identifier:headers; 144, string:'location'; 145, else_clause; 145, 146; 146, block; 146, 147; 147, return_statement; 147, 148; 148, tuple; 148, 149; 148, 153; 149, call; 149, 150; 149, 151; 150, identifier:int; 151, argument_list; 151, 152; 152, identifier:status; 153, identifier:statustxt | def add_item(self, url, title=None, selection=None,
jsonp=None, redirect=None, response_info=False):
""" Method to add a new item to a instapaper account
Parameters: url -> URL to add
title -> optional title for the URL
Returns: (status as int, status error message)
"""
parameters = {
'username' : self.user,
'password' : self.password,
'url' : url,
}
# look for optional parameters title and selection
if title is not None:
parameters['title'] = title
else:
parameters['auto-title'] = 1
if selection is not None:
parameters['selection'] = selection
if redirect is not None:
parameters['redirect'] = redirect
if jsonp is not None:
parameters['jsonp'] = jsonp
# make query with the chosen parameters
status, headers = self._query(self.addurl, parameters)
# return the callback call if we want jsonp
if jsonp is not None:
return status
statustxt = self.add_status_codes[int(status)]
# if response headers are desired, return them also
if response_info:
return (int(status), statustxt, headers['title'], headers['location'])
else:
return (int(status), statustxt) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_determine_representative_chains; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 13; 5, 19; 5, 152; 5, 173; 5, 179; 6, expression_statement; 6, 7; 7, string:''' Quotient the chains to get equivalence classes of chains. These will be used for the actual mapping.'''; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:equivalence_fiber; 12, dictionary; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:matched_chains; 16, call; 16, 17; 16, 18; 17, identifier:set; 18, argument_list; 19, for_statement; 19, 20; 19, 23; 19, 30; 20, pattern_list; 20, 21; 20, 22; 21, identifier:chain_id; 22, identifier:equivalent_chains; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:identical_sequences; 28, identifier:iteritems; 29, argument_list; 30, block; 30, 31; 30, 38; 30, 44; 30, 93; 30, 97; 30, 130; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:matched_chains; 35, identifier:add; 36, argument_list; 36, 37; 37, identifier:chain_id; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:equivalent_chain_ids; 41, call; 41, 42; 41, 43; 42, identifier:set; 43, argument_list; 44, for_statement; 44, 45; 44, 46; 44, 47; 45, identifier:equivalent_chain; 46, identifier:equivalent_chains; 47, block; 47, 48; 47, 56; 47, 83; 47, 84; 48, assert_statement; 48, 49; 49, parenthesized_expression; 49, 50; 50, comparison_operator:==; 50, 51; 50, 55; 51, call; 51, 52; 51, 53; 52, identifier:len; 53, argument_list; 53, 54; 54, identifier:equivalent_chain; 55, integer:6; 56, assert_statement; 56, 57; 57, parenthesized_expression; 57, 58; 58, boolean_operator:or; 58, 59; 58, 71; 59, parenthesized_expression; 59, 60; 60, comparison_operator:==; 60, 61; 60, 66; 61, subscript; 61, 62; 61, 63; 62, identifier:equivalent_chain; 63, slice; 63, 64; 63, 65; 64, colon; 65, integer:5; 66, binary_operator:%; 66, 67; 66, 68; 67, string:'%s_'; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:pdb_id; 71, parenthesized_expression; 71, 72; 72, comparison_operator:==; 72, 73; 72, 78; 73, subscript; 73, 74; 73, 75; 74, identifier:equivalent_chain; 75, slice; 75, 76; 75, 77; 76, colon; 77, integer:5; 78, binary_operator:%; 78, 79; 78, 80; 79, string:'%s:'; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:pdb_id; 83, comment; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:equivalent_chain_ids; 88, identifier:add; 89, argument_list; 89, 90; 90, subscript; 90, 91; 90, 92; 91, identifier:equivalent_chain; 92, integer:5; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:found; 96, False; 97, for_statement; 97, 98; 97, 99; 97, 100; 98, identifier:equivalent_chain_id; 99, identifier:equivalent_chain_ids; 100, block; 100, 101; 101, if_statement; 101, 102; 101, 108; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:equivalence_fiber; 105, identifier:get; 106, argument_list; 106, 107; 107, identifier:equivalent_chain_id; 108, block; 108, 109; 108, 113; 108, 129; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:found; 112, True; 113, assert_statement; 113, 114; 114, parenthesized_expression; 114, 115; 115, comparison_operator:==; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:equivalence_fiber; 118, identifier:equivalent_chain_id; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:equivalent_chain_ids; 122, identifier:union; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:set; 126, argument_list; 126, 127; 127, list:[chain_id]; 127, 128; 128, identifier:chain_id; 129, break_statement; 130, if_statement; 130, 131; 130, 133; 131, not_operator; 131, 132; 132, identifier:found; 133, block; 133, 134; 133, 143; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, subscript; 136, 137; 136, 138; 137, identifier:equivalence_fiber; 138, identifier:chain_id; 139, call; 139, 140; 139, 141; 140, identifier:set; 141, argument_list; 141, 142; 142, identifier:equivalent_chain_ids; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:equivalence_fiber; 148, identifier:chain_id; 149, identifier:add; 150, argument_list; 150, 151; 151, identifier:chain_id; 152, for_statement; 152, 153; 152, 154; 152, 157; 153, identifier:c; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:chains; 157, block; 157, 158; 158, if_statement; 158, 159; 158, 162; 159, comparison_operator:not; 159, 160; 159, 161; 160, identifier:c; 161, identifier:matched_chains; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:equivalence_fiber; 167, identifier:c; 168, call; 168, 169; 168, 170; 169, identifier:set; 170, argument_list; 170, 171; 171, list:[c]; 171, 172; 172, identifier:c; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:equivalence_fiber; 178, identifier:equivalence_fiber; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:representative_chains; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:equivalence_fiber; 187, identifier:keys; 188, argument_list | def _determine_representative_chains(self):
''' Quotient the chains to get equivalence classes of chains. These will be used for the actual mapping.'''
# todo: This logic should be moved into the FASTA class or a more general module (maybe a fast exists which uses a C/C++ library?) but at present it is easier to write here since we do not need to worry about other PDB IDs.
equivalence_fiber = {}
matched_chains = set()
for chain_id, equivalent_chains in self.identical_sequences.iteritems():
matched_chains.add(chain_id)
equivalent_chain_ids = set()
for equivalent_chain in equivalent_chains:
assert(len(equivalent_chain) == 6)
assert((equivalent_chain[:5] == '%s_' % self.pdb_id) or (equivalent_chain[:5] == '%s:' % self.pdb_id)) # ClustalW changes e.g. 1KI1:A to 1KI1_A in its output
equivalent_chain_ids.add(equivalent_chain[5])
found = False
for equivalent_chain_id in equivalent_chain_ids:
if equivalence_fiber.get(equivalent_chain_id):
found = True
assert(equivalence_fiber[equivalent_chain_id] == equivalent_chain_ids.union(set([chain_id])))
break
if not found:
equivalence_fiber[chain_id] = set(equivalent_chain_ids)
equivalence_fiber[chain_id].add(chain_id)
for c in self.chains:
if c not in matched_chains:
equivalence_fiber[c] = set([c])
self.equivalence_fiber = equivalence_fiber
self.representative_chains = equivalence_fiber.keys() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_align_with_substrings; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:chains_to_skip; 7, call; 7, 8; 7, 9; 8, identifier:set; 9, argument_list; 10, block; 10, 11; 10, 13; 10, 189; 10, 190; 10, 199; 10, 208; 10, 343; 10, 344; 10, 345; 10, 346; 11, expression_statement; 11, 12; 12, string:'''Simple substring-based matching'''; 13, for_statement; 13, 14; 13, 15; 13, 18; 13, 19; 14, identifier:c; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:representative_chains; 18, comment; 19, block; 19, 20; 20, if_statement; 20, 21; 20, 24; 20, 25; 20, 26; 21, comparison_operator:not; 21, 22; 21, 23; 22, identifier:c; 23, identifier:chains_to_skip; 24, comment; 25, comment; 26, block; 26, 27; 26, 35; 26, 39; 26, 181; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:fasta_sequence; 30, subscript; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:fasta; 34, identifier:c; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:substring_matches; 38, dictionary; 39, for_statement; 39, 40; 39, 43; 39, 53; 40, pattern_list; 40, 41; 40, 42; 41, identifier:uniparc_id; 42, identifier:uniparc_sequence; 43, call; 43, 44; 43, 45; 44, identifier:sorted; 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:self; 50, identifier:uniparc_sequences; 51, identifier:iteritems; 52, argument_list; 53, block; 53, 54; 53, 61; 53, 70; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:uniparc_sequence; 57, call; 57, 58; 57, 59; 58, identifier:str; 59, argument_list; 59, 60; 60, identifier:uniparc_sequence; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:idx; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:uniparc_sequence; 67, identifier:find; 68, argument_list; 68, 69; 69, identifier:fasta_sequence; 70, if_statement; 70, 71; 70, 75; 70, 82; 70, 146; 71, comparison_operator:!=; 71, 72; 71, 73; 72, identifier:idx; 73, unary_operator:-; 73, 74; 74, integer:1; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, subscript; 78, 79; 78, 80; 79, identifier:substring_matches; 80, identifier:uniparc_id; 81, integer:0; 82, elif_clause; 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:fasta_sequence; 88, integer:30; 89, block; 89, 90; 89, 105; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:idx; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:uniparc_sequence; 96, identifier:find; 97, argument_list; 97, 98; 98, subscript; 98, 99; 98, 100; 99, identifier:fasta_sequence; 100, slice; 100, 101; 100, 102; 100, 103; 101, integer:5; 102, colon; 103, unary_operator:-; 103, 104; 104, integer:5; 105, if_statement; 105, 106; 105, 110; 105, 117; 106, comparison_operator:!=; 106, 107; 106, 108; 107, identifier:idx; 108, unary_operator:-; 108, 109; 109, integer:1; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:substring_matches; 115, identifier:uniparc_id; 116, integer:5; 117, else_clause; 117, 118; 118, block; 118, 119; 118, 134; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:idx; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:uniparc_sequence; 125, identifier:find; 126, argument_list; 126, 127; 127, subscript; 127, 128; 127, 129; 128, identifier:fasta_sequence; 129, slice; 129, 130; 129, 131; 129, 132; 130, integer:7; 131, colon; 132, unary_operator:-; 132, 133; 133, integer:7; 134, if_statement; 134, 135; 134, 139; 135, comparison_operator:!=; 135, 136; 135, 137; 136, identifier:idx; 137, unary_operator:-; 137, 138; 138, integer:1; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:substring_matches; 144, identifier:uniparc_id; 145, integer:7; 146, elif_clause; 146, 147; 146, 153; 147, comparison_operator:>; 147, 148; 147, 152; 148, call; 148, 149; 148, 150; 149, identifier:len; 150, argument_list; 150, 151; 151, identifier:fasta_sequence; 152, integer:15; 153, block; 153, 154; 153, 169; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:idx; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:uniparc_sequence; 160, identifier:find; 161, argument_list; 161, 162; 162, subscript; 162, 163; 162, 164; 163, identifier:fasta_sequence; 164, slice; 164, 165; 164, 166; 164, 167; 165, integer:3; 166, colon; 167, unary_operator:-; 167, 168; 168, integer:3; 169, if_statement; 169, 170; 169, 174; 170, comparison_operator:!=; 170, 171; 170, 172; 171, identifier:idx; 172, unary_operator:-; 172, 173; 173, integer:1; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:substring_matches; 179, identifier:uniparc_id; 180, integer:3; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 188; 183, subscript; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:substring_matches; 187, identifier:c; 188, identifier:substring_matches; 189, comment; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:colortext; 194, identifier:pcyan; 195, argument_list; 195, 196; 196, binary_operator:*; 196, 197; 196, 198; 197, string:'*'; 198, integer:100; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:pprint; 203, identifier:pprint; 204, argument_list; 204, 205; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:substring_matches; 208, if_statement; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:restrict_to_uniparc_values; 212, block; 212, 213; 213, for_statement; 213, 214; 213, 215; 213, 218; 213, 219; 213, 220; 214, identifier:c; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:representative_chains; 218, comment; 219, comment; 220, block; 220, 221; 221, if_statement; 221, 222; 221, 250; 221, 251; 221, 252; 221, 253; 221, 254; 222, comparison_operator:>; 222, 223; 222, 249; 223, call; 223, 224; 223, 242; 224, attribute; 224, 225; 224, 241; 225, call; 225, 226; 225, 227; 226, identifier:set; 227, argument_list; 227, 228; 228, call; 228, 229; 228, 230; 229, identifier:map; 230, argument_list; 230, 231; 230, 232; 231, identifier:str; 232, call; 232, 233; 232, 240; 233, attribute; 233, 234; 233, 239; 234, subscript; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:substring_matches; 238, identifier:c; 239, identifier:keys; 240, argument_list; 241, identifier:intersection; 242, argument_list; 242, 243; 243, call; 243, 244; 243, 245; 244, identifier:set; 245, argument_list; 245, 246; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:restrict_to_uniparc_values; 249, integer:0; 250, comment; 251, comment; 252, comment; 253, comment; 254, block; 254, 255; 254, 293; 254, 335; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:restricted_matches; 258, call; 258, 259; 258, 260; 259, identifier:dict; 260, generator_expression; 260, 261; 260, 273; 260, 284; 261, tuple; 261, 262; 261, 266; 262, call; 262, 263; 262, 264; 263, identifier:str; 264, argument_list; 264, 265; 265, identifier:k; 266, subscript; 266, 267; 266, 272; 267, subscript; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:substring_matches; 271, identifier:c; 272, identifier:k; 273, for_in_clause; 273, 274; 273, 275; 274, identifier:k; 275, call; 275, 276; 275, 283; 276, attribute; 276, 277; 276, 282; 277, subscript; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:substring_matches; 281, identifier:c; 282, identifier:keys; 283, argument_list; 284, if_clause; 284, 285; 285, comparison_operator:in; 285, 286; 285, 290; 286, call; 286, 287; 286, 288; 287, identifier:str; 288, argument_list; 288, 289; 289, identifier:k; 290, attribute; 290, 291; 290, 292; 291, identifier:self; 292, identifier:restrict_to_uniparc_values; 293, if_statement; 293, 294; 293, 307; 294, comparison_operator:!=; 294, 295; 294, 299; 295, call; 295, 296; 295, 297; 296, identifier:len; 297, argument_list; 297, 298; 298, identifier:restricted_matches; 299, call; 299, 300; 299, 301; 300, identifier:len; 301, argument_list; 301, 302; 302, subscript; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:self; 305, identifier:substring_matches; 306, identifier:c; 307, block; 307, 308; 307, 334; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:removed_matches; 311, call; 311, 312; 311, 313; 312, identifier:sorted; 313, argument_list; 313, 314; 314, call; 314, 315; 314, 329; 315, attribute; 315, 316; 315, 328; 316, call; 316, 317; 316, 318; 317, identifier:set; 318, argument_list; 318, 319; 319, call; 319, 320; 319, 327; 320, attribute; 320, 321; 320, 326; 321, subscript; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:self; 324, identifier:substring_matches; 325, identifier:c; 326, identifier:keys; 327, argument_list; 328, identifier:difference; 329, argument_list; 329, 330; 330, call; 330, 331; 330, 332; 331, identifier:set; 332, argument_list; 332, 333; 333, identifier:restricted_matches; 334, comment; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 342; 337, subscript; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:substring_matches; 341, identifier:c; 342, identifier:restricted_matches; 343, comment; 344, comment; 345, comment; 346, for_statement; 346, 347; 346, 350; 346, 357; 347, pattern_list; 347, 348; 347, 349; 348, identifier:c_1; 349, identifier:related_chains; 350, call; 350, 351; 350, 356; 351, attribute; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:self; 354, identifier:equivalence_fiber; 355, identifier:iteritems; 356, argument_list; 357, block; 357, 358; 358, for_statement; 358, 359; 358, 360; 358, 361; 359, identifier:c_2; 360, identifier:related_chains; 361, block; 361, 362; 362, expression_statement; 362, 363; 363, assignment; 363, 364; 363, 369; 364, subscript; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:self; 367, identifier:substring_matches; 368, identifier:c_2; 369, subscript; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:self; 372, identifier:substring_matches; 373, identifier:c_1 | def _align_with_substrings(self, chains_to_skip = set()):
'''Simple substring-based matching'''
for c in self.representative_chains:
# Skip specified chains
if c not in chains_to_skip:
#colortext.pcyan(c)
#colortext.warning(self.fasta[c])
fasta_sequence = self.fasta[c]
substring_matches = {}
for uniparc_id, uniparc_sequence in sorted(self.uniparc_sequences.iteritems()):
uniparc_sequence = str(uniparc_sequence)
idx = uniparc_sequence.find(fasta_sequence)
if idx != -1:
substring_matches[uniparc_id] = 0
elif len(fasta_sequence) > 30:
idx = uniparc_sequence.find(fasta_sequence[5:-5])
if idx != -1:
substring_matches[uniparc_id] = 5
else:
idx = uniparc_sequence.find(fasta_sequence[7:-7])
if idx != -1:
substring_matches[uniparc_id] = 7
elif len(fasta_sequence) > 15:
idx = uniparc_sequence.find(fasta_sequence[3:-3])
if idx != -1:
substring_matches[uniparc_id] = 3
self.substring_matches[c] = substring_matches
# Restrict the matches to a given set of UniParc IDs. This can be used to remove ambiguity when the correct mapping has been determined e.g. from the SIFTS database.
colortext.pcyan('*' * 100)
pprint.pprint(self.substring_matches)
if self.restrict_to_uniparc_values:
for c in self.representative_chains:
#print('HERE!')
#print(c)
if set(map(str, self.substring_matches[c].keys())).intersection(set(self.restrict_to_uniparc_values)) > 0:
# Only restrict in cases where there is at least one match in self.restrict_to_uniparc_values
# Otherwise, chains which are not considered in self.restrict_to_uniparc_values may throw away valid matches
# e.g. when looking for structures related to 1KTZ (A -> P10600 -> UPI000000D8EC, B -> P37173 -> UPI000011DD7E),
# we find the close match 2PJY. However, 2PJY has 3 chains: A -> P10600, B -> P37173, and C -> P36897 -> UPI000011D62A
restricted_matches = dict((str(k), self.substring_matches[c][k]) for k in self.substring_matches[c].keys() if str(k) in self.restrict_to_uniparc_values)
if len(restricted_matches) != len(self.substring_matches[c]):
removed_matches = sorted(set(self.substring_matches[c].keys()).difference(set(restricted_matches)))
# todo: see above re:quiet colortext.pcyan('Ignoring {0} as those chains were not included in the list self.restrict_to_uniparc_values ({1}).'.format(', '.join(removed_matches), ', '.join(self.restrict_to_uniparc_values)))
self.substring_matches[c] = restricted_matches
#pprint.pprint(self.substring_matches)
#colortext.pcyan('*' * 100)
# Use the representatives' alignments for their respective equivalent classes
for c_1, related_chains in self.equivalence_fiber.iteritems():
for c_2 in related_chains:
self.substring_matches[c_2] = self.substring_matches[c_1] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_chain_mutations; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:pdb_id_1; 6, identifier:chain_1; 7, identifier:pdb_id_2; 8, identifier:chain_2; 9, block; 9, 10; 9, 12; 9, 13; 9, 22; 9, 31; 9, 43; 9, 55; 9, 56; 9, 57; 9, 69; 9, 70; 9, 92; 9, 114; 9, 129; 9, 144; 9, 159; 9, 174; 9, 181; 9, 188; 9, 189; 9, 195; 9, 209; 9, 223; 9, 229; 9, 239; 9, 240; 9, 241; 9, 247; 9, 266; 9, 287; 9, 301; 9, 302; 9, 306; 9, 312; 9, 313; 9, 314; 9, 477; 10, expression_statement; 10, 11; 11, string:'''Returns a list of tuples each containing a SEQRES Mutation object and an ATOM Mutation object representing the
mutations from pdb_id_1, chain_1 to pdb_id_2, chain_2.
SequenceMaps are constructed in this function between the chains based on the alignment.
PDBMutationPair are returned as they are hashable and amenable to Set construction to eliminate duplicates.
'''; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:p1; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:add_pdb; 20, argument_list; 20, 21; 21, identifier:pdb_id_1; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:p2; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:add_pdb; 29, argument_list; 29, 30; 30, identifier:pdb_id_2; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, pattern_list; 33, 34; 33, 35; 34, identifier:sifts_1; 35, identifier:pdb_1; 36, expression_list; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:p1; 39, string:'sifts'; 40, subscript; 40, 41; 40, 42; 41, identifier:p1; 42, string:'pdb'; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, pattern_list; 45, 46; 45, 47; 46, identifier:sifts_2; 47, identifier:pdb_2; 48, expression_list; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:p2; 51, string:'sifts'; 52, subscript; 52, 53; 52, 54; 53, identifier:p2; 54, string:'pdb'; 55, comment; 56, comment; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:seqres_to_atom_sequence_maps_1; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:sifts_1; 64, identifier:seqres_to_atom_sequence_maps; 65, identifier:get; 66, argument_list; 66, 67; 66, 68; 67, identifier:chain_1; 68, dictionary; 69, comment; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, pattern_list; 72, 73; 72, 74; 73, identifier:seqres_1; 74, identifier:atom_1; 75, expression_list; 75, 76; 75, 84; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:pdb_1; 80, identifier:seqres_sequences; 81, identifier:get; 82, argument_list; 82, 83; 83, identifier:chain_1; 84, call; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:pdb_1; 88, identifier:atom_sequences; 89, identifier:get; 90, argument_list; 90, 91; 91, identifier:chain_1; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, pattern_list; 94, 95; 94, 96; 95, identifier:seqres_2; 96, identifier:atom_2; 97, expression_list; 97, 98; 97, 106; 98, call; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:pdb_2; 102, identifier:seqres_sequences; 103, identifier:get; 104, argument_list; 104, 105; 105, identifier:chain_2; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:pdb_2; 110, identifier:atom_sequences; 111, identifier:get; 112, argument_list; 112, 113; 113, identifier:chain_2; 114, if_statement; 114, 115; 114, 117; 115, not_operator; 115, 116; 116, identifier:seqres_1; 117, block; 117, 118; 118, raise_statement; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:Exception; 121, argument_list; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, string:'No SEQRES sequence for chain {0} of {1}.'; 125, identifier:format; 126, argument_list; 126, 127; 126, 128; 127, identifier:chain_1; 128, identifier:pdb_1; 129, if_statement; 129, 130; 129, 132; 130, not_operator; 130, 131; 131, identifier:atom_1; 132, block; 132, 133; 133, raise_statement; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:Exception; 136, argument_list; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, string:'No ATOM sequence for chain {0} of {1}.'; 140, identifier:format; 141, argument_list; 141, 142; 141, 143; 142, identifier:chain_1; 143, identifier:pdb_1; 144, if_statement; 144, 145; 144, 147; 145, not_operator; 145, 146; 146, identifier:seqres_2; 147, block; 147, 148; 148, raise_statement; 148, 149; 149, call; 149, 150; 149, 151; 150, identifier:Exception; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, string:'No SEQRES sequence for chain {0} of {1}.'; 155, identifier:format; 156, argument_list; 156, 157; 156, 158; 157, identifier:chain_2; 158, identifier:pdb_2; 159, if_statement; 159, 160; 159, 162; 160, not_operator; 160, 161; 161, identifier:atom_2; 162, block; 162, 163; 163, raise_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:Exception; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, string:'No ATOM sequence for chain {0} of {1}.'; 170, identifier:format; 171, argument_list; 171, 172; 171, 173; 172, identifier:chain_2; 173, identifier:pdb_2; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:seqres_str_1; 177, call; 177, 178; 177, 179; 178, identifier:str; 179, argument_list; 179, 180; 180, identifier:seqres_1; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:seqres_str_2; 184, call; 184, 185; 184, 186; 185, identifier:str; 186, argument_list; 186, 187; 187, identifier:seqres_2; 188, comment; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:sa; 192, call; 192, 193; 192, 194; 193, identifier:SequenceAligner; 194, argument_list; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:sa; 199, identifier:add_sequence; 200, argument_list; 200, 201; 200, 208; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, string:'{0}_{1}'; 204, identifier:format; 205, argument_list; 205, 206; 205, 207; 206, identifier:pdb_id_1; 207, identifier:chain_1; 208, identifier:seqres_str_1; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:sa; 213, identifier:add_sequence; 214, argument_list; 214, 215; 214, 222; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, string:'{0}_{1}'; 218, identifier:format; 219, argument_list; 219, 220; 219, 221; 220, identifier:pdb_id_2; 221, identifier:chain_2; 222, identifier:seqres_str_2; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:sa; 227, identifier:align; 228, argument_list; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 234; 231, pattern_list; 231, 232; 231, 233; 232, identifier:seqres_residue_mapping; 233, identifier:seqres_match_mapping; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:sa; 237, identifier:get_residue_mapping; 238, argument_list; 239, comment; 240, comment; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:seqres_sequence_map; 244, call; 244, 245; 244, 246; 245, identifier:SequenceMap; 246, argument_list; 247, assert_statement; 247, 248; 248, parenthesized_expression; 248, 249; 249, comparison_operator:==; 249, 250; 249, 258; 250, call; 250, 251; 250, 252; 251, identifier:sorted; 252, argument_list; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:seqres_residue_mapping; 256, identifier:keys; 257, argument_list; 258, call; 258, 259; 258, 260; 259, identifier:sorted; 260, argument_list; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:seqres_match_mapping; 264, identifier:keys; 265, argument_list; 266, for_statement; 266, 267; 266, 270; 266, 275; 267, pattern_list; 267, 268; 267, 269; 268, identifier:k; 269, identifier:v; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:seqres_residue_mapping; 273, identifier:iteritems; 274, argument_list; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:seqres_sequence_map; 280, identifier:add; 281, argument_list; 281, 282; 281, 283; 281, 284; 282, identifier:k; 283, identifier:v; 284, subscript; 284, 285; 284, 286; 285, identifier:seqres_match_mapping; 286, identifier:k; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 300; 289, subscript; 289, 290; 289, 297; 290, subscript; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:self; 293, identifier:seqres_sequence_maps; 294, tuple; 294, 295; 294, 296; 295, identifier:pdb_id_1; 296, identifier:chain_1; 297, tuple; 297, 298; 297, 299; 298, identifier:pdb_id_2; 299, identifier:chain_2; 300, identifier:seqres_sequence_map; 301, comment; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:mutations; 305, list:[]; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:clustal_symbols; 309, attribute; 309, 310; 309, 311; 310, identifier:SubstitutionScore; 311, identifier:clustal_symbols; 312, comment; 313, comment; 314, for_statement; 314, 315; 314, 318; 314, 323; 314, 324; 315, pattern_list; 315, 316; 315, 317; 316, identifier:seqres_res_id; 317, identifier:v; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:seqres_match_mapping; 321, identifier:iteritems; 322, argument_list; 323, comment; 324, block; 324, 325; 325, if_statement; 325, 326; 325, 333; 325, 334; 326, comparison_operator:!=; 326, 327; 326, 332; 327, subscript; 327, 328; 327, 329; 328, identifier:clustal_symbols; 329, attribute; 329, 330; 329, 331; 330, identifier:v; 331, identifier:clustal; 332, string:'*'; 333, comment; 334, block; 334, 335; 334, 341; 334, 342; 334, 350; 334, 351; 334, 352; 334, 356; 334, 365; 334, 422; 334, 423; 334, 424; 334, 425; 334, 426; 334, 427; 334, 443; 334, 447; 334, 466; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:seqres_wt_residue; 338, subscript; 338, 339; 338, 340; 339, identifier:seqres_1; 340, identifier:seqres_res_id; 341, comment; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 345; 344, identifier:seqres_mutant_residue; 345, subscript; 345, 346; 345, 347; 346, identifier:seqres_2; 347, subscript; 347, 348; 347, 349; 348, identifier:seqres_residue_mapping; 349, identifier:seqres_res_id; 350, comment; 351, comment; 352, expression_statement; 352, 353; 353, assignment; 353, 354; 353, 355; 354, identifier:atom_res_id; 355, None; 356, expression_statement; 356, 357; 357, assignment; 357, 358; 357, 359; 358, identifier:atom_chain_res_id; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:seqres_to_atom_sequence_maps_1; 362, identifier:get; 363, argument_list; 363, 364; 364, identifier:seqres_res_id; 365, try_statement; 365, 366; 365, 407; 366, block; 366, 367; 367, if_statement; 367, 368; 367, 369; 368, identifier:atom_chain_res_id; 369, block; 369, 370; 369, 377; 369, 383; 369, 391; 369, 400; 370, assert_statement; 370, 371; 371, parenthesized_expression; 371, 372; 372, comparison_operator:==; 372, 373; 372, 376; 373, subscript; 373, 374; 373, 375; 374, identifier:atom_chain_res_id; 375, integer:0; 376, identifier:chain_1; 377, expression_statement; 377, 378; 378, assignment; 378, 379; 378, 380; 379, identifier:atom_residue; 380, subscript; 380, 381; 380, 382; 381, identifier:atom_1; 382, identifier:atom_chain_res_id; 383, expression_statement; 383, 384; 384, assignment; 384, 385; 384, 386; 385, identifier:atom_res_id; 386, subscript; 386, 387; 386, 388; 387, identifier:atom_chain_res_id; 388, slice; 388, 389; 388, 390; 389, integer:1; 390, colon; 391, assert_statement; 391, 392; 392, parenthesized_expression; 392, 393; 393, comparison_operator:==; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:atom_residue; 396, identifier:ResidueAA; 397, attribute; 397, 398; 397, 399; 398, identifier:seqres_wt_residue; 399, identifier:ResidueAA; 400, assert_statement; 400, 401; 401, parenthesized_expression; 401, 402; 402, comparison_operator:==; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, identifier:atom_residue; 405, identifier:ResidueID; 406, identifier:atom_res_id; 407, except_clause; 407, 408; 408, block; 408, 409; 408, 413; 409, expression_statement; 409, 410; 410, assignment; 410, 411; 410, 412; 411, identifier:atom_res_id; 412, None; 413, if_statement; 413, 414; 413, 419; 413, 420; 414, comparison_operator:!=; 414, 415; 414, 418; 415, attribute; 415, 416; 415, 417; 416, identifier:seqres_wt_residue; 417, identifier:ResidueAA; 418, string:'X'; 419, comment; 420, block; 420, 421; 421, raise_statement; 422, comment; 423, comment; 424, comment; 425, comment; 426, comment; 427, expression_statement; 427, 428; 428, assignment; 428, 429; 428, 430; 429, identifier:seqres_mutation; 430, call; 430, 431; 430, 432; 431, identifier:ChainMutation; 432, argument_list; 432, 433; 432, 436; 432, 437; 432, 440; 433, attribute; 433, 434; 433, 435; 434, identifier:seqres_wt_residue; 435, identifier:ResidueAA; 436, identifier:seqres_res_id; 437, attribute; 437, 438; 437, 439; 438, identifier:seqres_mutant_residue; 439, identifier:ResidueAA; 440, keyword_argument; 440, 441; 440, 442; 441, identifier:Chain; 442, identifier:chain_1; 443, expression_statement; 443, 444; 444, assignment; 444, 445; 444, 446; 445, identifier:atom_mutation; 446, None; 447, if_statement; 447, 448; 447, 449; 448, identifier:atom_res_id; 449, block; 449, 450; 450, expression_statement; 450, 451; 451, assignment; 451, 452; 451, 453; 452, identifier:atom_mutation; 453, call; 453, 454; 453, 455; 454, identifier:ChainMutation; 455, argument_list; 455, 456; 455, 459; 455, 460; 455, 463; 456, attribute; 456, 457; 456, 458; 457, identifier:seqres_wt_residue; 458, identifier:ResidueAA; 459, identifier:atom_res_id; 460, attribute; 460, 461; 460, 462; 461, identifier:seqres_mutant_residue; 462, identifier:ResidueAA; 463, keyword_argument; 463, 464; 463, 465; 464, identifier:Chain; 465, identifier:chain_1; 466, expression_statement; 466, 467; 467, call; 467, 468; 467, 471; 468, attribute; 468, 469; 468, 470; 469, identifier:mutations; 470, identifier:append; 471, argument_list; 471, 472; 472, call; 472, 473; 472, 474; 473, identifier:PDBMutationPair; 474, argument_list; 474, 475; 474, 476; 475, identifier:seqres_mutation; 476, identifier:atom_mutation; 477, return_statement; 477, 478; 478, identifier:mutations | def get_chain_mutations(self, pdb_id_1, chain_1, pdb_id_2, chain_2):
'''Returns a list of tuples each containing a SEQRES Mutation object and an ATOM Mutation object representing the
mutations from pdb_id_1, chain_1 to pdb_id_2, chain_2.
SequenceMaps are constructed in this function between the chains based on the alignment.
PDBMutationPair are returned as they are hashable and amenable to Set construction to eliminate duplicates.
'''
# Set up the objects
p1 = self.add_pdb(pdb_id_1)
p2 = self.add_pdb(pdb_id_2)
sifts_1, pdb_1 = p1['sifts'], p1['pdb']
sifts_2, pdb_2 = p2['sifts'], p2['pdb']
# Set up the sequences
#pprint.pprint(sifts_1.seqres_to_atom_sequence_maps)
seqres_to_atom_sequence_maps_1 = sifts_1.seqres_to_atom_sequence_maps.get(chain_1, {}) # this is not guaranteed to exist e.g. 2ZNW chain A
seqres_1, atom_1 = pdb_1.seqres_sequences.get(chain_1), pdb_1.atom_sequences.get(chain_1)
seqres_2, atom_2 = pdb_2.seqres_sequences.get(chain_2), pdb_2.atom_sequences.get(chain_2)
if not seqres_1: raise Exception('No SEQRES sequence for chain {0} of {1}.'.format(chain_1, pdb_1))
if not atom_1: raise Exception('No ATOM sequence for chain {0} of {1}.'.format(chain_1, pdb_1))
if not seqres_2: raise Exception('No SEQRES sequence for chain {0} of {1}.'.format(chain_2, pdb_2))
if not atom_2: raise Exception('No ATOM sequence for chain {0} of {1}.'.format(chain_2, pdb_2))
seqres_str_1 = str(seqres_1)
seqres_str_2 = str(seqres_2)
# Align the SEQRES sequences
sa = SequenceAligner()
sa.add_sequence('{0}_{1}'.format(pdb_id_1, chain_1), seqres_str_1)
sa.add_sequence('{0}_{1}'.format(pdb_id_2, chain_2), seqres_str_2)
sa.align()
seqres_residue_mapping, seqres_match_mapping = sa.get_residue_mapping()
#colortext.pcyan(sa.alignment_output)
# Create a SequenceMap
seqres_sequence_map = SequenceMap()
assert(sorted(seqres_residue_mapping.keys()) == sorted(seqres_match_mapping.keys()))
for k, v in seqres_residue_mapping.iteritems():
seqres_sequence_map.add(k, v, seqres_match_mapping[k])
self.seqres_sequence_maps[(pdb_id_1, chain_1)][(pdb_id_2, chain_2)] = seqres_sequence_map
# Determine the mutations between the SEQRES sequences and use these to generate a list of ATOM mutations
mutations = []
clustal_symbols = SubstitutionScore.clustal_symbols
#print(pdb_id_1, chain_1, pdb_id_2, chain_2)
#print(seqres_to_atom_sequence_maps_1)
for seqres_res_id, v in seqres_match_mapping.iteritems():
# Look at all positions which differ. seqres_res_id is 1-indexed, following the SEQRES and UniProt convention. However, so our our Sequence objects.
if clustal_symbols[v.clustal] != '*':
# Get the wildtype Residue objects
seqres_wt_residue = seqres_1[seqres_res_id]
#print(seqres_wt_residue)
seqres_mutant_residue = seqres_2[seqres_residue_mapping[seqres_res_id]] # todo: this will probably fail for some cases where there is no corresponding mapping
# If there is an associated ATOM record for the wildtype residue, get its residue ID
atom_res_id = None
atom_chain_res_id = seqres_to_atom_sequence_maps_1.get(seqres_res_id)
try:
if atom_chain_res_id:
assert(atom_chain_res_id[0] == chain_1)
atom_residue = atom_1[atom_chain_res_id]
atom_res_id = atom_chain_res_id[1:]
assert(atom_residue.ResidueAA == seqres_wt_residue.ResidueAA)
assert(atom_residue.ResidueID == atom_res_id)
except:
atom_res_id = None
if seqres_wt_residue.ResidueAA != 'X':
# we do not seem to keep ATOM records for unknown/non-canonicals: see 2BTF chain A -> 2PBD chain A
raise
# Create two mutations - one for the SEQRES residue and one for the corresponding (if any) ATOM residue
# We create both so that the user is informed whether there is a mutation between the structures which is
# not captured by the coordinates.
# If there are no ATOM coordinates, there is no point creating an ATOM mutation object so we instead use
# the None type. This also fits with the approach in the SpiderWeb framework.
seqres_mutation = ChainMutation(seqres_wt_residue.ResidueAA, seqres_res_id,seqres_mutant_residue.ResidueAA, Chain = chain_1)
atom_mutation = None
if atom_res_id:
atom_mutation = ChainMutation(seqres_wt_residue.ResidueAA, atom_res_id, seqres_mutant_residue.ResidueAA, Chain = chain_1)
mutations.append(PDBMutationPair(seqres_mutation, atom_mutation))
return mutations |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:make; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:apps; 6, block; 6, 7; 6, 9; 6, 370; 6, 371; 7, expression_statement; 7, 8; 8, comment; 9, for_statement; 9, 10; 9, 13; 9, 35; 10, tuple_pattern; 10, 11; 10, 12; 11, identifier:appname; 12, identifier:app; 13, call; 13, 14; 13, 15; 14, identifier:sorted; 15, argument_list; 15, 16; 15, 21; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:apps; 19, identifier:items; 20, argument_list; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:key; 23, lambda; 23, 24; 23, 26; 24, lambda_parameters; 24, 25; 25, identifier:x; 26, tuple; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, subscript; 28, 29; 28, 30; 29, identifier:x; 30, integer:1; 31, identifier:priority; 32, subscript; 32, 33; 32, 34; 33, identifier:x; 34, integer:0; 35, block; 35, 36; 35, 44; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:logger; 40, identifier:info; 41, argument_list; 41, 42; 41, 43; 42, string:'Getting report results from %r'; 43, identifier:appname; 44, for_statement; 44, 45; 44, 46; 44, 49; 45, identifier:report_data; 46, attribute; 46, 47; 46, 48; 47, identifier:app; 48, identifier:report_data; 49, block; 49, 50; 49, 60; 49, 356; 50, if_statement; 50, 51; 50, 58; 51, comparison_operator:!=; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:report_data; 54, identifier:subreport; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:name; 58, block; 58, 59; 59, continue_statement; 60, if_statement; 60, 61; 60, 66; 60, 190; 60, 273; 61, comparison_operator:==; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:report_data; 64, identifier:function; 65, string:'total'; 66, block; 66, 67; 67, for_statement; 67, 68; 67, 69; 67, 70; 68, identifier:opt; 69, identifier:report_data; 70, block; 70, 71; 70, 80; 70, 89; 70, 98; 70, 107; 70, 121; 70, 135; 70, 141; 70, 176; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:match; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:report_data; 77, identifier:parse_report_data; 78, argument_list; 78, 79; 79, identifier:opt; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:cond; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:match; 86, identifier:group; 87, argument_list; 87, 88; 88, string:'condition'; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:valfld; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:match; 95, identifier:group; 96, argument_list; 96, 97; 97, string:'valfld'; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:unit; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:match; 104, identifier:group; 105, argument_list; 105, 106; 106, string:'unit'; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:itemtitle; 110, call; 110, 111; 110, 119; 111, attribute; 111, 112; 111, 118; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:match; 115, identifier:group; 116, argument_list; 116, 117; 117, string:'fields'; 118, identifier:strip; 119, argument_list; 119, 120; 120, string:'"'; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:total; 124, call; 124, 125; 124, 132; 125, attribute; 125, 126; 125, 131; 126, subscript; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:report_data; 129, identifier:rules; 130, identifier:opt; 131, identifier:total_events; 132, argument_list; 132, 133; 132, 134; 133, identifier:cond; 134, identifier:valfld; 135, if_statement; 135, 136; 135, 139; 136, comparison_operator:==; 136, 137; 136, 138; 137, identifier:total; 138, integer:0; 139, block; 139, 140; 140, continue_statement; 141, if_statement; 141, 142; 141, 145; 141, 167; 142, comparison_operator:is; 142, 143; 142, 144; 143, identifier:unit; 144, None; 145, block; 145, 146; 145, 157; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, pattern_list; 148, 149; 148, 150; 149, identifier:total; 150, identifier:unit; 151, call; 151, 152; 151, 153; 152, identifier:get_value_unit; 153, argument_list; 153, 154; 153, 155; 153, 156; 154, identifier:total; 155, identifier:unit; 156, string:'T'; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:total; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, string:'{0} {1}'; 163, identifier:format; 164, argument_list; 164, 165; 164, 166; 165, identifier:total; 166, identifier:unit; 167, else_clause; 167, 168; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:total; 172, call; 172, 173; 172, 174; 173, identifier:str; 174, argument_list; 174, 175; 175, identifier:total; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 183; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:report_data; 181, identifier:results; 182, identifier:append; 183, argument_list; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:tuple; 186, argument_list; 186, 187; 187, list:[total, itemtitle]; 187, 188; 187, 189; 188, identifier:total; 189, identifier:itemtitle; 190, elif_clause; 190, 191; 190, 196; 191, comparison_operator:==; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:report_data; 194, identifier:function; 195, string:'top'; 196, block; 196, 197; 196, 206; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:k; 200, call; 200, 201; 200, 202; 201, identifier:int; 202, argument_list; 202, 203; 203, attribute; 203, 204; 203, 205; 204, identifier:report_data; 205, identifier:topnum; 206, for_statement; 206, 207; 206, 208; 206, 209; 207, identifier:opt; 208, identifier:report_data; 209, block; 209, 210; 209, 219; 209, 228; 209, 237; 209, 248; 209, 264; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:match; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:report_data; 216, identifier:parse_report_data; 217, argument_list; 217, 218; 218, identifier:opt; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:valfld; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:match; 225, identifier:group; 226, argument_list; 226, 227; 227, string:'valfld'; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:field; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:match; 234, identifier:group; 235, argument_list; 235, 236; 236, string:'fields'; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:usemax; 240, comparison_operator:is; 240, 241; 240, 247; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:match; 244, identifier:group; 245, argument_list; 245, 246; 246, string:'add2res'; 247, None; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:toplist; 251, call; 251, 252; 251, 259; 252, attribute; 252, 253; 252, 258; 253, subscript; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:report_data; 256, identifier:rules; 257, identifier:opt; 258, identifier:top_events; 259, argument_list; 259, 260; 259, 261; 259, 262; 259, 263; 260, identifier:k; 261, identifier:valfld; 262, identifier:usemax; 263, identifier:field; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 271; 266, attribute; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:report_data; 269, identifier:results; 270, identifier:extend; 271, argument_list; 271, 272; 272, identifier:toplist; 273, elif_clause; 273, 274; 273, 279; 274, comparison_operator:==; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:report_data; 277, identifier:function; 278, string:'table'; 279, block; 279, 280; 279, 295; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:cols; 283, call; 283, 284; 283, 285; 284, identifier:len; 285, argument_list; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:re; 289, identifier:split; 290, argument_list; 290, 291; 290, 292; 291, string:'\s*,\s*'; 292, attribute; 292, 293; 292, 294; 293, identifier:report_data; 294, identifier:headers; 295, for_statement; 295, 296; 295, 297; 295, 298; 296, identifier:opt; 297, identifier:report_data; 298, block; 298, 299; 298, 308; 298, 317; 298, 332; 298, 347; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:match; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:report_data; 305, identifier:parse_report_data; 306, argument_list; 306, 307; 307, identifier:opt; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:cond; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:match; 314, identifier:group; 315, argument_list; 315, 316; 316, string:'condition'; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:fields; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:re; 323, identifier:split; 324, argument_list; 324, 325; 324, 326; 325, string:'\s*,\s*'; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:match; 329, identifier:group; 330, argument_list; 330, 331; 331, string:'fields'; 332, expression_statement; 332, 333; 333, assignment; 333, 334; 333, 335; 334, identifier:tablelist; 335, call; 335, 336; 335, 343; 336, attribute; 336, 337; 336, 342; 337, subscript; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:report_data; 340, identifier:rules; 341, identifier:opt; 342, identifier:list_events; 343, argument_list; 343, 344; 343, 345; 343, 346; 344, identifier:cond; 345, identifier:cols; 346, identifier:fields; 347, expression_statement; 347, 348; 348, call; 348, 349; 348, 354; 349, attribute; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:report_data; 352, identifier:results; 353, identifier:extend; 354, argument_list; 354, 355; 355, identifier:tablelist; 356, if_statement; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:report_data; 359, identifier:results; 360, block; 360, 361; 361, expression_statement; 361, 362; 362, call; 362, 363; 362, 368; 363, attribute; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:self; 366, identifier:report_data; 367, identifier:append; 368, argument_list; 368, 369; 369, identifier:report_data; 370, comment; 371, for_statement; 371, 372; 371, 373; 371, 376; 372, identifier:report_data; 373, attribute; 373, 374; 373, 375; 374, identifier:self; 375, identifier:report_data; 376, block; 376, 377; 377, if_statement; 377, 378; 377, 383; 377, 384; 378, comparison_operator:==; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:report_data; 381, identifier:function; 382, string:'top'; 383, comment; 384, block; 384, 385; 384, 407; 384, 408; 384, 412; 384, 440; 385, expression_statement; 385, 386; 386, assignment; 386, 387; 386, 390; 387, attribute; 387, 388; 387, 389; 388, identifier:report_data; 389, identifier:results; 390, call; 390, 391; 390, 392; 391, identifier:sorted; 392, argument_list; 392, 393; 392, 396; 392, 404; 393, attribute; 393, 394; 393, 395; 394, identifier:report_data; 395, identifier:results; 396, keyword_argument; 396, 397; 396, 398; 397, identifier:key; 398, lambda; 398, 399; 398, 401; 399, lambda_parameters; 399, 400; 400, identifier:x; 401, subscript; 401, 402; 401, 403; 402, identifier:x; 403, integer:0; 404, keyword_argument; 404, 405; 404, 406; 405, identifier:reverse; 406, True; 407, comment; 408, expression_statement; 408, 409; 409, assignment; 409, 410; 409, 411; 410, identifier:unit; 411, None; 412, for_statement; 412, 413; 412, 414; 412, 415; 413, identifier:opt; 414, identifier:report_data; 415, block; 415, 416; 415, 425; 415, 434; 416, expression_statement; 416, 417; 417, assignment; 417, 418; 417, 419; 418, identifier:match; 419, call; 419, 420; 419, 423; 420, attribute; 420, 421; 420, 422; 421, identifier:report_data; 422, identifier:parse_report_data; 423, argument_list; 423, 424; 424, identifier:opt; 425, expression_statement; 425, 426; 426, assignment; 426, 427; 426, 428; 427, identifier:unit; 428, call; 428, 429; 428, 432; 429, attribute; 429, 430; 429, 431; 430, identifier:match; 431, identifier:group; 432, argument_list; 432, 433; 433, string:'unit'; 434, if_statement; 434, 435; 434, 438; 435, comparison_operator:is; 435, 436; 435, 437; 436, identifier:unit; 437, None; 438, block; 438, 439; 439, break_statement; 440, for_statement; 440, 441; 440, 442; 440, 445; 441, identifier:res; 442, attribute; 442, 443; 442, 444; 443, identifier:report_data; 444, identifier:results; 445, block; 445, 446; 446, if_statement; 446, 447; 446, 450; 446, 476; 447, comparison_operator:is; 447, 448; 447, 449; 448, identifier:unit; 449, None; 450, block; 450, 451; 450, 464; 451, expression_statement; 451, 452; 452, assignment; 452, 453; 452, 456; 453, pattern_list; 453, 454; 453, 455; 454, identifier:v; 455, identifier:u; 456, call; 456, 457; 456, 458; 457, identifier:get_value_unit; 458, argument_list; 458, 459; 458, 462; 458, 463; 459, subscript; 459, 460; 459, 461; 460, identifier:res; 461, integer:0; 462, identifier:unit; 463, string:'T'; 464, expression_statement; 464, 465; 465, assignment; 465, 466; 465, 469; 466, subscript; 466, 467; 466, 468; 467, identifier:res; 468, integer:0; 469, call; 469, 470; 469, 473; 470, attribute; 470, 471; 470, 472; 471, string:'{0} {1}'; 472, identifier:format; 473, argument_list; 473, 474; 473, 475; 474, identifier:v; 475, identifier:u; 476, else_clause; 476, 477; 477, block; 477, 478; 478, expression_statement; 478, 479; 479, assignment; 479, 480; 479, 483; 480, subscript; 480, 481; 480, 482; 481, identifier:res; 482, integer:0; 483, call; 483, 484; 483, 485; 484, identifier:str; 485, argument_list; 485, 486; 486, subscript; 486, 487; 486, 488; 487, identifier:res; 488, integer:0 | def make(self, apps):
"""
Make subreport items from results.
"""
for (appname, app) in sorted(apps.items(), key=lambda x: (x[1].priority, x[0])):
logger.info('Getting report results from %r', appname)
for report_data in app.report_data:
if report_data.subreport != self.name:
continue
if report_data.function == 'total':
for opt in report_data:
match = report_data.parse_report_data(opt)
cond = match.group('condition')
valfld = match.group('valfld')
unit = match.group('unit')
itemtitle = match.group('fields').strip('"')
total = report_data.rules[opt].total_events(cond, valfld)
if total == 0:
continue
if unit is not None:
total, unit = get_value_unit(total, unit, 'T')
total = '{0} {1}'.format(total, unit)
else:
total = str(total)
report_data.results.append(tuple([total, itemtitle]))
elif report_data.function == 'top':
k = int(report_data.topnum)
for opt in report_data:
match = report_data.parse_report_data(opt)
valfld = match.group('valfld')
field = match.group('fields')
usemax = match.group('add2res') is None
toplist = report_data.rules[opt].top_events(k, valfld, usemax, field)
report_data.results.extend(toplist)
elif report_data.function == 'table':
cols = len(re.split('\s*,\s*', report_data.headers))
for opt in report_data:
match = report_data.parse_report_data(opt)
cond = match.group('condition')
fields = re.split('\s*,\s*', match.group('fields'))
tablelist = report_data.rules[opt].list_events(cond, cols, fields)
report_data.results.extend(tablelist)
if report_data.results:
self.report_data.append(report_data)
# Sort and rewrite results as strings with units
for report_data in self.report_data:
if report_data.function == 'top':
# Sort values
report_data.results = sorted(report_data.results, key=lambda x: x[0], reverse=True)
# Get the unit if any and convert numeric results to strings
unit = None
for opt in report_data:
match = report_data.parse_report_data(opt)
unit = match.group('unit')
if unit is not None:
break
for res in report_data.results:
if unit is not None:
v, u = get_value_unit(res[0], unit, 'T')
res[0] = '{0} {1}'.format(v, u)
else:
res[0] = str(res[0]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_report_parts; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:apps; 6, identifier:formats; 7, block; 7, 8; 7, 10; 7, 43; 7, 50; 7, 141; 7, 145; 7, 181; 7, 214; 7, 223; 7, 227; 7, 302; 8, expression_statement; 8, 9; 9, comment; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:fmt; 12, identifier:formats; 13, block; 13, 14; 13, 29; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:width; 17, conditional_expression:if; 17, 18; 17, 19; 17, 22; 18, integer:100; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:fmt; 21, None; 22, subscript; 22, 23; 22, 28; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:tui; 26, identifier:get_terminal_size; 27, argument_list; 28, integer:0; 29, for_statement; 29, 30; 29, 31; 29, 34; 30, identifier:sr; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:subreports; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:sr; 39, identifier:make_format; 40, argument_list; 40, 41; 40, 42; 41, identifier:fmt; 42, identifier:width; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:logger; 47, identifier:debug; 48, argument_list; 48, 49; 49, string:'Build a map for arguments and run\'s statistics ...'; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:value_mapping; 53, dictionary; 53, 54; 53, 59; 53, 80; 53, 94; 53, 108; 53, 138; 54, pair; 54, 55; 54, 56; 55, string:'title'; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:title; 59, pair; 59, 60; 59, 61; 60, string:'patterns'; 61, boolean_operator:or; 61, 62; 61, 79; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, string:', '; 65, identifier:join; 66, argument_list; 66, 67; 67, list_comprehension; 67, 68; 67, 72; 68, call; 68, 69; 68, 70; 69, identifier:repr; 70, argument_list; 70, 71; 71, identifier:pattern; 72, for_in_clause; 72, 73; 72, 74; 73, identifier:pattern; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:args; 78, identifier:patterns; 79, None; 80, pair; 80, 81; 80, 82; 81, string:'pattern_files'; 82, boolean_operator:or; 82, 83; 82, 93; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, string:', '; 86, identifier:join; 87, argument_list; 87, 88; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:args; 92, identifier:pattern_files; 93, None; 94, pair; 94, 95; 94, 96; 95, string:'hosts'; 96, boolean_operator:or; 96, 97; 96, 107; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, string:', '; 100, identifier:join; 101, argument_list; 101, 102; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:args; 106, identifier:hosts; 107, None; 108, pair; 108, 109; 108, 110; 109, string:'apps'; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, string:u', '; 113, identifier:join; 114, argument_list; 114, 115; 115, list_comprehension; 115, 116; 115, 125; 115, 132; 116, binary_operator:%; 116, 117; 116, 118; 117, string:u'%s(%d)'; 118, tuple; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:app; 121, identifier:name; 122, attribute; 122, 123; 122, 124; 123, identifier:app; 124, identifier:matches; 125, for_in_clause; 125, 126; 125, 127; 126, identifier:app; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:apps; 130, identifier:values; 131, argument_list; 132, if_clause; 132, 133; 133, comparison_operator:>; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:app; 136, identifier:matches; 137, integer:0; 138, pair; 138, 139; 138, 140; 139, string:'version'; 140, identifier:__version__; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:filters; 144, list:[]; 145, for_statement; 145, 146; 145, 147; 145, 152; 146, identifier:flt; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:args; 151, identifier:filters; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:filters; 157, identifier:append; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, string:' AND '; 162, identifier:join; 163, argument_list; 163, 164; 164, list_comprehension; 164, 165; 164, 172; 165, binary_operator:%; 165, 166; 165, 167; 166, string:'%s=%r'; 167, tuple; 167, 168; 167, 169; 168, identifier:k; 169, attribute; 169, 170; 169, 171; 170, identifier:v; 171, identifier:pattern; 172, for_in_clause; 172, 173; 172, 176; 173, pattern_list; 173, 174; 173, 175; 174, identifier:k; 175, identifier:v; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:flt; 179, identifier:items; 180, argument_list; 181, if_statement; 181, 182; 181, 183; 181, 201; 182, identifier:filters; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:value_mapping; 188, string:'filters'; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, string:' OR '; 192, identifier:join; 193, argument_list; 193, 194; 194, list_comprehension; 194, 195; 194, 198; 195, binary_operator:%; 195, 196; 195, 197; 196, string:'(%s)'; 197, identifier:item; 198, for_in_clause; 198, 199; 198, 200; 199, identifier:item; 200, identifier:filters; 201, else_clause; 201, 202; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, subscript; 205, 206; 205, 207; 206, identifier:value_mapping; 207, string:'filters'; 208, conditional_expression:if; 208, 209; 208, 212; 208, 213; 209, subscript; 209, 210; 209, 211; 210, identifier:filters; 211, integer:0; 212, identifier:filters; 213, None; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:value_mapping; 218, identifier:update; 219, argument_list; 219, 220; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:stats; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:report; 226, list:[]; 227, for_statement; 227, 228; 227, 229; 227, 230; 228, identifier:fmt; 229, identifier:formats; 230, block; 230, 231; 231, if_statement; 231, 232; 231, 235; 231, 255; 231, 279; 232, comparison_operator:==; 232, 233; 232, 234; 233, identifier:fmt; 234, string:'text'; 235, block; 235, 236; 235, 243; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:logger; 240, identifier:info; 241, argument_list; 241, 242; 242, string:'appends a text page report'; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:report; 247, identifier:append; 248, argument_list; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:make_text_page; 253, argument_list; 253, 254; 254, identifier:value_mapping; 255, elif_clause; 255, 256; 255, 259; 256, comparison_operator:==; 256, 257; 256, 258; 257, identifier:fmt; 258, string:'html'; 259, block; 259, 260; 259, 267; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:logger; 264, identifier:info; 265, argument_list; 265, 266; 266, string:'appends a html page report'; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:report; 271, identifier:append; 272, argument_list; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:make_html_page; 277, argument_list; 277, 278; 278, identifier:value_mapping; 279, elif_clause; 279, 280; 279, 283; 280, comparison_operator:==; 280, 281; 280, 282; 281, identifier:fmt; 282, string:'csv'; 283, block; 283, 284; 283, 291; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:logger; 288, identifier:info; 289, argument_list; 289, 290; 290, string:'extends with a list of csv subreports'; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:report; 295, identifier:extend; 296, argument_list; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:self; 300, identifier:make_csv_tables; 301, argument_list; 302, return_statement; 302, 303; 303, identifier:report | def get_report_parts(self, apps, formats):
"""
Make report item texts in a specified format.
"""
for fmt in formats:
width = 100 if fmt is not None else tui.get_terminal_size()[0]
for sr in self.subreports:
sr.make_format(fmt, width)
logger.debug('Build a map for arguments and run\'s statistics ...')
value_mapping = {
'title': self.title,
'patterns': ', '.join([repr(pattern) for pattern in self.args.patterns]) or None,
'pattern_files': ', '.join(self.args.pattern_files) or None,
'hosts': ', '.join(self.args.hosts) or None,
'apps': u', '.join([
u'%s(%d)' % (app.name, app.matches) for app in apps.values() if app.matches > 0
]),
'version': __version__
}
filters = []
for flt in self.args.filters:
filters.append(' AND '.join(['%s=%r' % (k, v.pattern) for k, v in flt.items()]))
if filters:
value_mapping['filters'] = ' OR '.join(['(%s)' % item for item in filters])
else:
value_mapping['filters'] = filters[0] if filters else None
value_mapping.update(self.stats)
report = []
for fmt in formats:
if fmt == 'text':
logger.info('appends a text page report')
report.append(self.make_text_page(value_mapping))
elif fmt == 'html':
logger.info('appends a html page report')
report.append(self.make_html_page(value_mapping))
elif fmt == 'csv':
logger.info('extends with a list of csv subreports')
report.extend(self.make_csv_tables())
return report |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_convert; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:chain_id; 6, identifier:residue_id; 7, identifier:from_scheme; 8, identifier:to_scheme; 9, block; 9, 10; 9, 12; 9, 13; 9, 51; 9, 106; 9, 161; 9, 199; 10, expression_statement; 10, 11; 11, string:'''The actual 'private' conversion function.'''; 12, comment; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:==; 14, 15; 14, 16; 15, identifier:from_scheme; 16, string:'rosetta'; 17, block; 17, 18; 17, 32; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:atom_id; 21, subscript; 21, 22; 21, 31; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:rosetta_to_atom_sequence_maps; 27, identifier:get; 28, argument_list; 28, 29; 28, 30; 29, identifier:chain_id; 30, dictionary; 31, identifier:residue_id; 32, if_statement; 32, 33; 32, 36; 32, 39; 33, comparison_operator:==; 33, 34; 33, 35; 34, identifier:to_scheme; 35, string:'atom'; 36, block; 36, 37; 37, return_statement; 37, 38; 38, identifier:atom_id; 39, else_clause; 39, 40; 40, block; 40, 41; 41, return_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:_convert; 46, argument_list; 46, 47; 46, 48; 46, 49; 46, 50; 47, identifier:chain_id; 48, identifier:atom_id; 49, string:'atom'; 50, identifier:to_scheme; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:==; 52, 53; 52, 54; 53, identifier:from_scheme; 54, string:'atom'; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 60; 56, 73; 57, comparison_operator:==; 57, 58; 57, 59; 58, identifier:to_scheme; 59, string:'rosetta'; 60, block; 60, 61; 61, return_statement; 61, 62; 62, subscript; 62, 63; 62, 72; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:atom_to_rosetta_sequence_maps; 68, identifier:get; 69, argument_list; 69, 70; 69, 71; 70, identifier:chain_id; 71, dictionary; 72, identifier:residue_id; 73, else_clause; 73, 74; 74, block; 74, 75; 74, 89; 74, 96; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:seqres_id; 78, subscript; 78, 79; 78, 88; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:atom_to_seqres_sequence_maps; 84, identifier:get; 85, argument_list; 85, 86; 85, 87; 86, identifier:chain_id; 87, dictionary; 88, identifier:residue_id; 89, if_statement; 89, 90; 89, 93; 90, comparison_operator:==; 90, 91; 90, 92; 91, identifier:to_scheme; 92, string:'seqres'; 93, block; 93, 94; 94, return_statement; 94, 95; 95, identifier:seqres_id; 96, return_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:convert; 101, argument_list; 101, 102; 101, 103; 101, 104; 101, 105; 102, identifier:chain_id; 103, identifier:seqres_id; 104, string:'seqres'; 105, identifier:to_scheme; 106, if_statement; 106, 107; 106, 110; 107, comparison_operator:==; 107, 108; 107, 109; 108, identifier:from_scheme; 109, string:'seqres'; 110, block; 110, 111; 111, if_statement; 111, 112; 111, 115; 111, 128; 112, comparison_operator:==; 112, 113; 112, 114; 113, identifier:to_scheme; 114, string:'uniparc'; 115, block; 115, 116; 116, return_statement; 116, 117; 117, subscript; 117, 118; 117, 127; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:seqres_to_uniparc_sequence_maps; 123, identifier:get; 124, argument_list; 124, 125; 124, 126; 125, identifier:chain_id; 126, dictionary; 127, identifier:residue_id; 128, else_clause; 128, 129; 129, block; 129, 130; 129, 144; 129, 151; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:atom_id; 133, subscript; 133, 134; 133, 143; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:seqres_to_atom_sequence_maps; 139, identifier:get; 140, argument_list; 140, 141; 140, 142; 141, identifier:chain_id; 142, dictionary; 143, identifier:residue_id; 144, if_statement; 144, 145; 144, 148; 145, comparison_operator:==; 145, 146; 145, 147; 146, identifier:to_scheme; 147, string:'atom'; 148, block; 148, 149; 149, return_statement; 149, 150; 150, identifier:atom_id; 151, return_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:convert; 156, argument_list; 156, 157; 156, 158; 156, 159; 156, 160; 157, identifier:chain_id; 158, identifier:atom_id; 159, string:'atom'; 160, identifier:to_scheme; 161, if_statement; 161, 162; 161, 165; 162, comparison_operator:==; 162, 163; 162, 164; 163, identifier:from_scheme; 164, string:'uniparc'; 165, block; 165, 166; 165, 180; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:seqres_id; 169, subscript; 169, 170; 169, 179; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:uniparc_to_seqres_sequence_maps; 175, identifier:get; 176, argument_list; 176, 177; 176, 178; 177, identifier:chain_id; 178, dictionary; 179, identifier:residue_id; 180, if_statement; 180, 181; 180, 184; 180, 187; 181, comparison_operator:==; 181, 182; 181, 183; 182, identifier:to_scheme; 183, string:'seqres'; 184, block; 184, 185; 185, return_statement; 185, 186; 186, identifier:seqres_id; 187, else_clause; 187, 188; 188, block; 188, 189; 189, return_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:_convert; 194, argument_list; 194, 195; 194, 196; 194, 197; 194, 198; 195, identifier:chain_id; 196, identifier:seqres_id; 197, string:'seqres'; 198, identifier:to_scheme; 199, raise_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:Exception; 202, argument_list; 202, 203; 203, string:"We should never reach this line." | def _convert(self, chain_id, residue_id, from_scheme, to_scheme):
'''The actual 'private' conversion function.'''
# There are 12 valid combinations but rather than write them all out explicitly, we will use recursion, sacrificing speed for brevity
if from_scheme == 'rosetta':
atom_id = self.rosetta_to_atom_sequence_maps.get(chain_id, {})[residue_id]
if to_scheme == 'atom':
return atom_id
else:
return self._convert(chain_id, atom_id, 'atom', to_scheme)
if from_scheme == 'atom':
if to_scheme == 'rosetta':
return self.atom_to_rosetta_sequence_maps.get(chain_id, {})[residue_id]
else:
seqres_id = self.atom_to_seqres_sequence_maps.get(chain_id, {})[residue_id]
if to_scheme == 'seqres':
return seqres_id
return self.convert(chain_id, seqres_id, 'seqres', to_scheme)
if from_scheme == 'seqres':
if to_scheme == 'uniparc':
return self.seqres_to_uniparc_sequence_maps.get(chain_id, {})[residue_id]
else:
atom_id = self.seqres_to_atom_sequence_maps.get(chain_id, {})[residue_id]
if to_scheme == 'atom':
return atom_id
return self.convert(chain_id, atom_id, 'atom', to_scheme)
if from_scheme == 'uniparc':
seqres_id = self.uniparc_to_seqres_sequence_maps.get(chain_id, {})[residue_id]
if to_scheme == 'seqres':
return seqres_id
else:
return self._convert(chain_id, seqres_id, 'seqres', to_scheme)
raise Exception("We should never reach this line.") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_create_sequences; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 41; 5, 42; 5, 73; 5, 88; 5, 98; 5, 108; 5, 151; 5, 152; 5, 156; 5, 263; 5, 340; 5, 341; 6, expression_statement; 6, 7; 7, string:'''Get all of the Sequences - Rosetta, ATOM, SEQRES, FASTA, UniParc.'''; 8, comment; 9, try_statement; 9, 10; 9, 32; 10, block; 10, 11; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:pdb; 17, identifier:construct_pdb_to_rosetta_residue_map; 18, argument_list; 18, 19; 18, 22; 18, 27; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:rosetta_scripts_path; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:rosetta_database_path; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:rosetta_database_path; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:cache_dir; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:cache_dir; 32, except_clause; 32, 33; 32, 34; 33, identifier:PDBMissingMainchainAtomsException; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:pdb_to_rosetta_residue_map_error; 40, True; 41, comment; 42, if_statement; 42, 43; 42, 48; 42, 59; 43, comparison_operator:not; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:pdb_id; 47, identifier:do_not_use_the_sequence_aligner; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:uniparc_sequences; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:PDB_UniParc_SA; 58, identifier:uniparc_sequences; 59, else_clause; 59, 60; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:uniparc_sequences; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:sifts; 71, identifier:get_uniparc_sequences; 72, argument_list; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:fasta_sequences; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:FASTA; 83, identifier:get_sequences; 84, argument_list; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:pdb_id; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:seqres_sequences; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:pdb; 97, identifier:seqres_sequences; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:atom_sequences; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:pdb; 107, identifier:atom_sequences; 108, if_statement; 108, 109; 108, 112; 108, 139; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:pdb_to_rosetta_residue_map_error; 112, block; 112, 113; 112, 119; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:rosetta_sequences; 118, dictionary; 119, for_statement; 119, 120; 119, 121; 119, 128; 120, identifier:c; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:atom_sequences; 126, identifier:keys; 127, argument_list; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 136; 131, subscript; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:rosetta_sequences; 135, identifier:c; 136, call; 136, 137; 136, 138; 137, identifier:Sequence; 138, argument_list; 139, else_clause; 139, 140; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:rosetta_sequences; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:pdb; 150, identifier:rosetta_sequences; 151, comment; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:uniparc_pdb_chain_mapping; 155, dictionary; 156, if_statement; 156, 157; 156, 162; 156, 220; 157, comparison_operator:not; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:pdb_id; 161, identifier:do_not_use_the_sequence_aligner; 162, block; 162, 163; 163, for_statement; 163, 164; 163, 167; 163, 176; 164, pattern_list; 164, 165; 164, 166; 165, identifier:pdb_chain_id; 166, identifier:matches; 167, call; 167, 168; 167, 175; 168, attribute; 168, 169; 168, 174; 169, attribute; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:PDB_UniParc_SA; 173, identifier:clustal_matches; 174, identifier:iteritems; 175, argument_list; 176, block; 176, 177; 177, if_statement; 177, 178; 177, 179; 177, 180; 178, identifier:matches; 179, comment; 180, block; 180, 181; 180, 191; 180, 199; 180, 211; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:uniparc_chain_id; 184, subscript; 184, 185; 184, 190; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:matches; 188, identifier:keys; 189, argument_list; 190, integer:0; 191, assert_statement; 191, 192; 192, parenthesized_expression; 192, 193; 193, comparison_operator:==; 193, 194; 193, 198; 194, call; 194, 195; 194, 196; 195, identifier:len; 196, argument_list; 196, 197; 197, identifier:matches; 198, integer:1; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:uniparc_pdb_chain_mapping; 203, identifier:uniparc_chain_id; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:uniparc_pdb_chain_mapping; 207, identifier:get; 208, argument_list; 208, 209; 208, 210; 209, identifier:uniparc_chain_id; 210, list:[]; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:uniparc_pdb_chain_mapping; 216, identifier:uniparc_chain_id; 217, identifier:append; 218, argument_list; 218, 219; 219, identifier:pdb_chain_id; 220, else_clause; 220, 221; 221, block; 221, 222; 222, for_statement; 222, 223; 222, 226; 222, 237; 223, pattern_list; 223, 224; 223, 225; 224, identifier:pdb_chain_id; 225, identifier:uniparc_chain_ids; 226, call; 226, 227; 226, 236; 227, attribute; 227, 228; 227, 235; 228, call; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:sifts; 233, identifier:get_pdb_chain_to_uniparc_id_map; 234, argument_list; 235, identifier:iteritems; 236, argument_list; 237, block; 237, 238; 238, for_statement; 238, 239; 238, 240; 238, 241; 239, identifier:uniparc_chain_id; 240, identifier:uniparc_chain_ids; 241, block; 241, 242; 241, 254; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:uniparc_pdb_chain_mapping; 246, identifier:uniparc_chain_id; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:uniparc_pdb_chain_mapping; 250, identifier:get; 251, argument_list; 251, 252; 251, 253; 252, identifier:uniparc_chain_id; 253, list:[]; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 261; 256, attribute; 256, 257; 256, 260; 257, subscript; 257, 258; 257, 259; 258, identifier:uniparc_pdb_chain_mapping; 259, identifier:uniparc_chain_id; 260, identifier:append; 261, argument_list; 261, 262; 262, identifier:pdb_chain_id; 263, for_statement; 263, 264; 263, 267; 263, 272; 264, pattern_list; 264, 265; 264, 266; 265, identifier:uniparc_chain_id; 266, identifier:pdb_chain_ids; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:uniparc_pdb_chain_mapping; 270, identifier:iteritems; 271, argument_list; 272, block; 272, 273; 272, 290; 272, 298; 272, 306; 272, 317; 272, 328; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:sequence_type; 276, call; 276, 277; 276, 278; 277, identifier:set; 278, argument_list; 278, 279; 279, list_comprehension; 279, 280; 279, 287; 280, attribute; 280, 281; 280, 286; 281, subscript; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:seqres_sequences; 285, identifier:p; 286, identifier:sequence_type; 287, for_in_clause; 287, 288; 287, 289; 288, identifier:p; 289, identifier:pdb_chain_ids; 290, assert_statement; 290, 291; 291, parenthesized_expression; 291, 292; 292, comparison_operator:==; 292, 293; 292, 297; 293, call; 293, 294; 293, 295; 294, identifier:len; 295, argument_list; 295, 296; 296, identifier:sequence_type; 297, integer:1; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:sequence_type; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:sequence_type; 304, identifier:pop; 305, argument_list; 306, assert_statement; 306, 307; 307, parenthesized_expression; 307, 308; 308, comparison_operator:==; 308, 309; 308, 316; 309, attribute; 309, 310; 309, 315; 310, subscript; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:uniparc_sequences; 314, identifier:uniparc_chain_id; 315, identifier:sequence_type; 316, None; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 326; 319, attribute; 319, 320; 319, 325; 320, subscript; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:self; 323, identifier:uniparc_sequences; 324, identifier:uniparc_chain_id; 325, identifier:set_type; 326, argument_list; 326, 327; 327, identifier:sequence_type; 328, for_statement; 328, 329; 328, 330; 328, 331; 329, identifier:p; 330, identifier:pdb_chain_ids; 331, block; 331, 332; 332, expression_statement; 332, 333; 333, assignment; 333, 334; 333, 339; 334, subscript; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:self; 337, identifier:pdb_chain_to_uniparc_chain_mapping; 338, identifier:p; 339, identifier:uniparc_chain_id; 340, comment; 341, for_statement; 341, 342; 341, 345; 341, 352; 342, pattern_list; 342, 343; 342, 344; 343, identifier:chain_id; 344, identifier:sequence; 345, call; 345, 346; 345, 351; 346, attribute; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:self; 349, identifier:seqres_sequences; 350, identifier:iteritems; 351, argument_list; 352, block; 352, 353; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 362; 355, attribute; 355, 356; 355, 361; 356, subscript; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:self; 359, identifier:fasta_sequences; 360, identifier:chain_id; 361, identifier:set_type; 362, argument_list; 362, 363; 363, attribute; 363, 364; 363, 365; 364, identifier:sequence; 365, identifier:sequence_type | def _create_sequences(self):
'''Get all of the Sequences - Rosetta, ATOM, SEQRES, FASTA, UniParc.'''
# Create the Rosetta sequences and the maps from the Rosetta sequences to the ATOM sequences
try:
self.pdb.construct_pdb_to_rosetta_residue_map(self.rosetta_scripts_path, rosetta_database_path = self.rosetta_database_path, cache_dir = self.cache_dir)
except PDBMissingMainchainAtomsException:
self.pdb_to_rosetta_residue_map_error = True
# Get all the Sequences
if self.pdb_id not in do_not_use_the_sequence_aligner:
self.uniparc_sequences = self.PDB_UniParc_SA.uniparc_sequences
else:
self.uniparc_sequences = self.sifts.get_uniparc_sequences()
self.fasta_sequences = self.FASTA.get_sequences(self.pdb_id)
self.seqres_sequences = self.pdb.seqres_sequences
self.atom_sequences = self.pdb.atom_sequences
if self.pdb_to_rosetta_residue_map_error:
self.rosetta_sequences = {}
for c in self.atom_sequences.keys():
self.rosetta_sequences[c] = Sequence()
else:
self.rosetta_sequences = self.pdb.rosetta_sequences
# Update the chain types for the UniParc sequences
uniparc_pdb_chain_mapping = {}
if self.pdb_id not in do_not_use_the_sequence_aligner:
for pdb_chain_id, matches in self.PDB_UniParc_SA.clustal_matches.iteritems():
if matches:
# we are not guaranteed to have a match e.g. the short chain J in 1A2C, chimeras, etc.
uniparc_chain_id = matches.keys()[0]
assert(len(matches) == 1)
uniparc_pdb_chain_mapping[uniparc_chain_id] = uniparc_pdb_chain_mapping.get(uniparc_chain_id, [])
uniparc_pdb_chain_mapping[uniparc_chain_id].append(pdb_chain_id)
else:
for pdb_chain_id, uniparc_chain_ids in self.sifts.get_pdb_chain_to_uniparc_id_map().iteritems():
for uniparc_chain_id in uniparc_chain_ids:
uniparc_pdb_chain_mapping[uniparc_chain_id] = uniparc_pdb_chain_mapping.get(uniparc_chain_id, [])
uniparc_pdb_chain_mapping[uniparc_chain_id].append(pdb_chain_id)
for uniparc_chain_id, pdb_chain_ids in uniparc_pdb_chain_mapping.iteritems():
sequence_type = set([self.seqres_sequences[p].sequence_type for p in pdb_chain_ids])
assert(len(sequence_type) == 1)
sequence_type = sequence_type.pop()
assert(self.uniparc_sequences[uniparc_chain_id].sequence_type == None)
self.uniparc_sequences[uniparc_chain_id].set_type(sequence_type)
for p in pdb_chain_ids:
self.pdb_chain_to_uniparc_chain_mapping[p] = uniparc_chain_id
# Update the chain types for the FASTA sequences
for chain_id, sequence in self.seqres_sequences.iteritems():
self.fasta_sequences[chain_id].set_type(sequence.sequence_type) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:search_update_index; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 19; 5, 37; 5, 45; 5, 106; 5, 264; 5, 276; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:doc_id; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:search_get_document_id; 15, argument_list; 15, 16; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:key; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:fields; 22, list_comprehension; 22, 23; 22, 30; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:search; 26, identifier:AtomField; 27, argument_list; 27, 28; 27, 29; 28, string:'class_name'; 29, identifier:name; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:name; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:search_get_class_names; 36, argument_list; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:index; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:search_get_index; 44, argument_list; 45, if_statement; 45, 46; 45, 51; 45, 98; 46, comparison_operator:is; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:searchable_fields; 50, None; 51, block; 51, 52; 51, 56; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:searchable_fields; 55, list:[]; 56, for_statement; 56, 57; 56, 60; 56, 67; 57, pattern_list; 57, 58; 57, 59; 58, identifier:field; 59, identifier:prop; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:_properties; 65, identifier:items; 66, argument_list; 67, block; 67, 68; 67, 74; 68, if_statement; 68, 69; 68, 72; 69, comparison_operator:==; 69, 70; 69, 71; 70, identifier:field; 71, string:'class'; 72, block; 72, 73; 73, continue_statement; 74, for_statement; 74, 75; 74, 78; 74, 83; 75, pattern_list; 75, 76; 75, 77; 76, identifier:class_; 77, identifier:field_type; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:SEARCHABLE_PROPERTY_TYPES; 81, identifier:items; 82, argument_list; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 90; 85, call; 85, 86; 85, 87; 86, identifier:isinstance; 87, argument_list; 87, 88; 87, 89; 88, identifier:prop; 89, identifier:class_; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:searchable_fields; 95, identifier:append; 96, argument_list; 96, 97; 97, identifier:field; 98, else_clause; 98, 99; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:searchable_fields; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:searchable_fields; 106, for_statement; 106, 107; 106, 108; 106, 112; 107, identifier:f; 108, call; 108, 109; 108, 110; 109, identifier:set; 110, argument_list; 110, 111; 111, identifier:searchable_fields; 112, block; 112, 113; 112, 121; 112, 129; 112, 133; 112, 137; 112, 237; 112, 252; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:prop; 116, subscript; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:_properties; 120, identifier:f; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:value; 124, call; 124, 125; 124, 126; 125, identifier:getattr; 126, argument_list; 126, 127; 126, 128; 127, identifier:self; 128, identifier:f; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:field; 132, None; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:field_found; 136, False; 137, for_statement; 137, 138; 137, 141; 137, 146; 138, pattern_list; 138, 139; 138, 140; 139, identifier:class_; 140, identifier:field_type; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:SEARCHABLE_PROPERTY_TYPES; 144, identifier:items; 145, argument_list; 146, block; 146, 147; 147, if_statement; 147, 148; 147, 153; 148, call; 148, 149; 148, 150; 149, identifier:isinstance; 150, argument_list; 150, 151; 150, 152; 151, identifier:prop; 152, identifier:class_; 153, block; 153, 154; 153, 158; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:field_found; 157, True; 158, if_statement; 158, 159; 158, 162; 159, comparison_operator:is; 159, 160; 159, 161; 160, identifier:value; 161, None; 162, block; 162, 163; 163, if_statement; 163, 164; 163, 181; 163, 198; 163, 223; 164, boolean_operator:or; 164, 165; 164, 176; 165, boolean_operator:or; 165, 166; 165, 171; 166, call; 166, 167; 166, 168; 167, identifier:isinstance; 168, argument_list; 168, 169; 168, 170; 169, identifier:value; 170, identifier:list; 171, call; 171, 172; 171, 173; 172, identifier:isinstance; 173, argument_list; 173, 174; 173, 175; 174, identifier:value; 175, identifier:tuple; 176, call; 176, 177; 176, 178; 177, identifier:isinstance; 178, argument_list; 178, 179; 178, 180; 179, identifier:value; 180, identifier:set; 181, block; 181, 182; 182, for_statement; 182, 183; 182, 184; 182, 185; 183, identifier:v; 184, identifier:value; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:field; 189, call; 189, 190; 189, 191; 190, identifier:field_type; 191, argument_list; 191, 192; 191, 195; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:name; 194, identifier:f; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:value; 197, identifier:v; 198, elif_clause; 198, 199; 198, 206; 199, call; 199, 200; 199, 201; 200, identifier:isinstance; 201, argument_list; 201, 202; 201, 203; 202, identifier:value; 203, attribute; 203, 204; 203, 205; 204, identifier:ndb; 205, identifier:Key; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:field; 210, call; 210, 211; 210, 212; 211, identifier:field_type; 212, argument_list; 212, 213; 212, 216; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:name; 215, identifier:f; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:value; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:value; 221, identifier:urlsafe; 222, argument_list; 223, else_clause; 223, 224; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:field; 228, call; 228, 229; 228, 230; 229, identifier:field_type; 230, argument_list; 230, 231; 230, 234; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:name; 233, identifier:f; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:value; 236, identifier:value; 237, if_statement; 237, 238; 237, 240; 238, not_operator; 238, 239; 239, identifier:field_found; 240, block; 240, 241; 241, raise_statement; 241, 242; 242, call; 242, 243; 242, 244; 243, identifier:ValueError; 244, argument_list; 244, 245; 245, binary_operator:%; 245, 246; 245, 247; 246, string:'Cannot find field type for %r on %r'; 247, tuple; 247, 248; 247, 249; 248, identifier:prop; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:__class__; 252, if_statement; 252, 253; 252, 256; 253, comparison_operator:is; 253, 254; 253, 255; 254, identifier:field; 255, None; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:fields; 261, identifier:append; 262, argument_list; 262, 263; 263, identifier:field; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:document; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:search; 270, identifier:Document; 271, argument_list; 271, 272; 271, 273; 272, identifier:doc_id; 273, keyword_argument; 273, 274; 273, 275; 274, identifier:fields; 275, identifier:fields; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:index; 280, identifier:put; 281, argument_list; 281, 282; 282, identifier:document | def search_update_index(self):
"""
Updates the search index for this instance.
This happens automatically on put.
"""
doc_id = self.search_get_document_id(self.key)
fields = [search.AtomField('class_name', name) for name in self.search_get_class_names()]
index = self.search_get_index()
if self.searchable_fields is None:
searchable_fields = []
for field, prop in self._properties.items():
if field == 'class':
continue
for class_, field_type in SEARCHABLE_PROPERTY_TYPES.items():
if isinstance(prop, class_):
searchable_fields.append(field)
else:
searchable_fields = self.searchable_fields
for f in set(searchable_fields):
prop = self._properties[f]
value = getattr(self, f)
field = None
field_found = False
for class_, field_type in SEARCHABLE_PROPERTY_TYPES.items():
if isinstance(prop, class_):
field_found = True
if value is not None:
if isinstance(value, list) or isinstance(value, tuple) or isinstance(value, set):
for v in value:
field = field_type(name=f, value=v)
elif isinstance(value, ndb.Key):
field = field_type(name=f, value=value.urlsafe())
else:
field = field_type(name=f, value=value)
if not field_found:
raise ValueError('Cannot find field type for %r on %r' % (prop, self.__class__))
if field is not None:
fields.append(field)
document = search.Document(doc_id, fields=fields)
index.put(document) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:index_siblings; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:pid; 5, default_parameter; 5, 6; 5, 7; 6, identifier:include_pid; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:children; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:neighbors_eager; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:eager; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:with_deposits; 19, True; 20, block; 20, 21; 20, 23; 20, 30; 20, 65; 20, 74; 20, 87; 20, 104; 20, 105; 20, 106; 20, 107; 20, 108; 20, 133; 20, 143; 20, 205; 20, 238; 20, 255; 20, 268; 21, expression_statement; 21, 22; 22, comment; 23, assert_statement; 23, 24; 23, 29; 24, not_operator; 24, 25; 25, parenthesized_expression; 25, 26; 26, boolean_operator:and; 26, 27; 26, 28; 27, identifier:neighbors_eager; 28, identifier:eager; 29, comment; 30, if_statement; 30, 31; 30, 34; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:children; 33, None; 34, block; 34, 35; 34, 50; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:parent_pid; 38, call; 38, 39; 38, 49; 39, attribute; 39, 40; 39, 48; 40, attribute; 40, 41; 40, 47; 41, call; 41, 42; 41, 43; 42, identifier:PIDNodeVersioning; 43, argument_list; 43, 44; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:pid; 46, identifier:pid; 47, identifier:parents; 48, identifier:first; 49, argument_list; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:children; 53, call; 53, 54; 53, 64; 54, attribute; 54, 55; 54, 63; 55, attribute; 55, 56; 55, 62; 56, call; 56, 57; 56, 58; 57, identifier:PIDNodeVersioning; 58, argument_list; 58, 59; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:pid; 61, identifier:parent_pid; 62, identifier:children; 63, identifier:all; 64, argument_list; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:objid; 68, call; 68, 69; 68, 70; 69, identifier:str; 70, argument_list; 70, 71; 71, attribute; 71, 72; 71, 73; 72, identifier:pid; 73, identifier:object_uuid; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:children; 77, list_comprehension; 77, 78; 77, 84; 78, call; 78, 79; 78, 80; 79, identifier:str; 80, argument_list; 80, 81; 81, attribute; 81, 82; 81, 83; 82, identifier:p; 83, identifier:object_uuid; 84, for_in_clause; 84, 85; 84, 86; 85, identifier:p; 86, identifier:children; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:idx; 90, conditional_expression:if; 90, 91; 90, 97; 90, 100; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:children; 94, identifier:index; 95, argument_list; 95, 96; 96, identifier:objid; 97, comparison_operator:in; 97, 98; 97, 99; 98, identifier:objid; 99, identifier:children; 100, call; 100, 101; 100, 102; 101, identifier:len; 102, argument_list; 102, 103; 103, identifier:children; 104, comment; 105, comment; 106, comment; 107, comment; 108, if_statement; 108, 109; 108, 110; 108, 111; 108, 122; 109, identifier:include_pid; 110, comment; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:left; 115, subscript; 115, 116; 115, 117; 116, identifier:children; 117, slice; 117, 118; 117, 119; 118, colon; 119, binary_operator:+; 119, 120; 119, 121; 120, identifier:idx; 121, integer:1; 122, else_clause; 122, 123; 122, 124; 123, comment; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:left; 128, subscript; 128, 129; 128, 130; 129, identifier:children; 130, slice; 130, 131; 130, 132; 131, colon; 132, identifier:idx; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:right; 136, subscript; 136, 137; 136, 138; 137, identifier:children; 138, slice; 138, 139; 138, 142; 139, binary_operator:+; 139, 140; 139, 141; 140, identifier:idx; 141, integer:1; 142, colon; 143, if_statement; 143, 144; 143, 145; 143, 156; 143, 193; 144, identifier:eager; 145, block; 145, 146; 145, 152; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:eager_uuids; 149, binary_operator:+; 149, 150; 149, 151; 150, identifier:left; 151, identifier:right; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:bulk_uuids; 155, list:[]; 156, elif_clause; 156, 157; 156, 158; 156, 159; 156, 160; 157, identifier:neighbors_eager; 158, comment; 159, comment; 160, block; 160, 161; 160, 176; 160, 177; 160, 178; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:eager_uuids; 164, binary_operator:+; 164, 165; 164, 171; 165, subscript; 165, 166; 165, 167; 166, identifier:left; 167, slice; 167, 168; 167, 170; 168, unary_operator:-; 168, 169; 169, integer:1; 170, colon; 171, subscript; 171, 172; 171, 173; 172, identifier:right; 173, slice; 173, 174; 173, 175; 174, colon; 175, integer:1; 176, comment; 177, comment; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:bulk_uuids; 181, binary_operator:+; 181, 182; 181, 188; 182, subscript; 182, 183; 182, 184; 183, identifier:left; 184, slice; 184, 185; 184, 186; 185, colon; 186, unary_operator:-; 186, 187; 187, integer:1; 188, subscript; 188, 189; 188, 190; 189, identifier:right; 190, slice; 190, 191; 190, 192; 191, integer:1; 192, colon; 193, else_clause; 193, 194; 194, block; 194, 195; 194, 199; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:eager_uuids; 198, list:[]; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:bulk_uuids; 202, binary_operator:+; 202, 203; 202, 204; 203, identifier:left; 204, identifier:right; 205, function_definition; 205, 206; 205, 207; 205, 209; 206, function_name:get_dep_uuids; 207, parameters; 207, 208; 208, identifier:rec_uuids; 209, block; 209, 210; 209, 212; 210, expression_statement; 210, 211; 211, comment; 212, return_statement; 212, 213; 213, list_comprehension; 213, 214; 213, 235; 214, call; 214, 215; 214, 216; 215, identifier:str; 216, argument_list; 216, 217; 217, attribute; 217, 218; 217, 234; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:PersistentIdentifier; 221, identifier:get; 222, argument_list; 222, 223; 222, 224; 223, string:'depid'; 224, subscript; 224, 225; 224, 233; 225, subscript; 225, 226; 225, 232; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:Record; 229, identifier:get_record; 230, argument_list; 230, 231; 231, identifier:id_; 232, string:'_deposit'; 233, string:'id'; 234, identifier:object_uuid; 235, for_in_clause; 235, 236; 235, 237; 236, identifier:id_; 237, identifier:rec_uuids; 238, if_statement; 238, 239; 238, 240; 239, identifier:with_deposits; 240, block; 240, 241; 240, 248; 241, expression_statement; 241, 242; 242, augmented_assignment:+=; 242, 243; 242, 244; 243, identifier:eager_uuids; 244, call; 244, 245; 244, 246; 245, identifier:get_dep_uuids; 246, argument_list; 246, 247; 247, identifier:eager_uuids; 248, expression_statement; 248, 249; 249, augmented_assignment:+=; 249, 250; 249, 251; 250, identifier:bulk_uuids; 251, call; 251, 252; 251, 253; 252, identifier:get_dep_uuids; 253, argument_list; 253, 254; 254, identifier:bulk_uuids; 255, for_statement; 255, 256; 255, 257; 255, 258; 256, identifier:id_; 257, identifier:eager_uuids; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, call; 262, 263; 262, 264; 263, identifier:RecordIndexer; 264, argument_list; 265, identifier:index_by_id; 266, argument_list; 266, 267; 267, identifier:id_; 268, if_statement; 268, 269; 268, 270; 269, identifier:bulk_uuids; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 278; 273, attribute; 273, 274; 273, 277; 274, call; 274, 275; 274, 276; 275, identifier:RecordIndexer; 276, argument_list; 277, identifier:bulk_index; 278, argument_list; 278, 279; 279, identifier:bulk_uuids | def index_siblings(pid, include_pid=False, children=None,
neighbors_eager=False, eager=False, with_deposits=True):
"""Send sibling records of the passed pid for indexing.
Note: By default does not index the 'pid' itself,
only zero or more siblings.
:param pid: PID (recid) of whose siblings are to be indexed.
:param children: Overrides children with a fixed list of PID.
Children should contain the 'pid' itself if 'neighbors_eager' is to
be used, otherwise the last child is treated as the only neighbor.
:param eager: Index all siblings immediately.
:param include_pid: If True, will index also the provided 'pid'
(default:False).
:param neighbors_eager: Index the neighboring PIDs w.r.t. 'pid'
immediately, and the rest with a bulk_index (default: False)
:param with_deposits: Reindex also corresponding record's deposits.
"""
assert not (neighbors_eager and eager), \
"""Only one of the 'eager' and 'neighbors_eager' flags
can be set to True, not both"""
if children is None:
parent_pid = PIDNodeVersioning(pid=pid).parents.first()
children = PIDNodeVersioning(pid=parent_pid).children.all()
objid = str(pid.object_uuid)
children = [str(p.object_uuid) for p in children]
idx = children.index(objid) if objid in children else len(children)
# Split children (which can include the pid) into left and right siblings
# If 'pid' is not in children, idx is the length of list, so 'left'
# will be all children, and 'right' will be an empty list
# [X X X] X [X X X]
if include_pid:
# [X X X X] [X X X] Includes pid to the 'left' set
left = children[:idx + 1]
else:
# [X X X] X [X X X]
left = children[:idx]
right = children[idx + 1:]
if eager:
eager_uuids = left + right
bulk_uuids = []
elif neighbors_eager:
# neighbors are last of 'left' and first or 'right' siblings
# X X [X] X [X] X X
eager_uuids = left[-1:] + right[:1]
# all of the siblings, except the neighbours
# [X X] X X X [X X]
bulk_uuids = left[:-1] + right[1:]
else:
eager_uuids = []
bulk_uuids = left + right
def get_dep_uuids(rec_uuids):
"""Get corresponding deposit UUIDs from record's UUIDs."""
return [str(PersistentIdentifier.get(
'depid',
Record.get_record(id_)['_deposit']['id']).object_uuid)
for id_ in rec_uuids]
if with_deposits:
eager_uuids += get_dep_uuids(eager_uuids)
bulk_uuids += get_dep_uuids(bulk_uuids)
for id_ in eager_uuids:
RecordIndexer().index_by_id(id_)
if bulk_uuids:
RecordIndexer().bulk_index(bulk_uuids) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:iter_paths; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:pathnames; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:mapfunc; 10, None; 11, block; 11, 12; 11, 14; 11, 22; 11, 42; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:pathnames; 17, boolean_operator:or; 17, 18; 17, 19; 18, identifier:pathnames; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_pathnames; 22, if_statement; 22, 23; 22, 29; 22, 35; 23, boolean_operator:and; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:recursive; 27, not_operator; 27, 28; 28, identifier:pathnames; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:pathnames; 33, list:['.']; 33, 34; 34, string:'.'; 35, elif_clause; 35, 36; 35, 38; 36, not_operator; 36, 37; 37, identifier:pathnames; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, yield; 40, 41; 41, list:[]; 42, if_statement; 42, 43; 42, 46; 42, 157; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:mapfunc; 45, None; 46, block; 46, 47; 47, for_statement; 47, 48; 47, 49; 47, 54; 48, identifier:mapped_paths; 49, call; 49, 50; 49, 51; 50, identifier:map; 51, argument_list; 51, 52; 51, 53; 52, identifier:mapfunc; 53, identifier:pathnames; 54, block; 54, 55; 55, for_statement; 55, 56; 55, 57; 55, 58; 56, identifier:path; 57, identifier:mapped_paths; 58, block; 58, 59; 59, if_statement; 59, 60; 59, 82; 59, 123; 60, boolean_operator:and; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:recursive; 64, parenthesized_expression; 64, 65; 65, boolean_operator:or; 65, 66; 65, 74; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:os; 70, identifier:path; 71, identifier:isdir; 72, argument_list; 72, 73; 73, identifier:path; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:os; 78, identifier:path; 79, identifier:islink; 80, argument_list; 80, 81; 81, identifier:path; 82, block; 82, 83; 83, for_statement; 83, 84; 83, 85; 83, 96; 84, identifier:t; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:os; 88, identifier:walk; 89, argument_list; 89, 90; 89, 91; 90, identifier:path; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:followlinks; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:follow_symlinks; 96, block; 96, 97; 97, for_statement; 97, 98; 97, 101; 97, 117; 98, pattern_list; 98, 99; 98, 100; 99, identifier:filename; 100, identifier:values; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:iglob; 105, argument_list; 105, 106; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:os; 110, identifier:path; 111, identifier:join; 112, argument_list; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:t; 115, integer:0; 116, string:'*'; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, yield; 119, 120; 120, expression_list; 120, 121; 120, 122; 121, identifier:filename; 122, identifier:values; 123, else_clause; 123, 124; 124, block; 124, 125; 124, 129; 124, 149; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:empty_glob; 128, True; 129, for_statement; 129, 130; 129, 133; 129, 139; 130, pattern_list; 130, 131; 130, 132; 131, identifier:filename; 132, identifier:values; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:iglob; 137, argument_list; 137, 138; 138, identifier:path; 139, block; 139, 140; 139, 145; 140, expression_statement; 140, 141; 141, yield; 141, 142; 142, expression_list; 142, 143; 142, 144; 143, identifier:filename; 144, identifier:values; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:empty_glob; 148, False; 149, if_statement; 149, 150; 149, 151; 150, identifier:empty_glob; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, yield; 153, 154; 154, expression_list; 154, 155; 154, 156; 155, identifier:path; 156, None; 157, else_clause; 157, 158; 158, block; 158, 159; 159, for_statement; 159, 160; 159, 161; 159, 162; 160, identifier:path; 161, identifier:pathnames; 162, block; 162, 163; 163, if_statement; 163, 164; 163, 186; 163, 227; 164, boolean_operator:and; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:recursive; 168, parenthesized_expression; 168, 169; 169, boolean_operator:or; 169, 170; 169, 178; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:os; 174, identifier:path; 175, identifier:isdir; 176, argument_list; 176, 177; 177, identifier:path; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:os; 182, identifier:path; 183, identifier:islink; 184, argument_list; 184, 185; 185, identifier:path; 186, block; 186, 187; 187, for_statement; 187, 188; 187, 189; 187, 200; 188, identifier:t; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:os; 192, identifier:walk; 193, argument_list; 193, 194; 193, 195; 194, identifier:path; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:followlinks; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:follow_symlinks; 200, block; 200, 201; 201, for_statement; 201, 202; 201, 205; 201, 221; 202, pattern_list; 202, 203; 202, 204; 203, identifier:filename; 204, identifier:values; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:iglob; 209, argument_list; 209, 210; 210, call; 210, 211; 210, 216; 211, attribute; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:os; 214, identifier:path; 215, identifier:join; 216, argument_list; 216, 217; 216, 220; 217, subscript; 217, 218; 217, 219; 218, identifier:t; 219, integer:0; 220, string:'*'; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, yield; 223, 224; 224, expression_list; 224, 225; 224, 226; 225, identifier:filename; 226, identifier:values; 227, else_clause; 227, 228; 228, block; 228, 229; 228, 233; 228, 253; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:empty_glob; 232, True; 233, for_statement; 233, 234; 233, 237; 233, 243; 234, pattern_list; 234, 235; 234, 236; 235, identifier:filename; 236, identifier:values; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:iglob; 241, argument_list; 241, 242; 242, identifier:path; 243, block; 243, 244; 243, 249; 244, expression_statement; 244, 245; 245, yield; 245, 246; 246, expression_list; 246, 247; 246, 248; 247, identifier:filename; 248, identifier:values; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:empty_glob; 252, False; 253, if_statement; 253, 254; 253, 255; 254, identifier:empty_glob; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, yield; 257, 258; 258, expression_list; 258, 259; 258, 260; 259, identifier:path; 260, None | def iter_paths(self, pathnames=None, mapfunc=None):
"""
Special iteration on paths. Yields couples of path and items. If a expanded path
doesn't match with any files a couple with path and `None` is returned.
:param pathnames: Iterable with a set of pathnames. If is `None` uses the all \
the stored pathnames.
:param mapfunc: A mapping function for building the effective path from various \
wildcards (eg. time spec wildcards).
:return: Yields 2-tuples.
"""
pathnames = pathnames or self._pathnames
if self.recursive and not pathnames:
pathnames = ['.']
elif not pathnames:
yield []
if mapfunc is not None:
for mapped_paths in map(mapfunc, pathnames):
for path in mapped_paths:
if self.recursive and (os.path.isdir(path) or os.path.islink(path)):
for t in os.walk(path, followlinks=self.follow_symlinks):
for filename, values in self.iglob(os.path.join(t[0], '*')):
yield filename, values
else:
empty_glob = True
for filename, values in self.iglob(path):
yield filename, values
empty_glob = False
if empty_glob:
yield path, None
else:
for path in pathnames:
if self.recursive and (os.path.isdir(path) or os.path.islink(path)):
for t in os.walk(path, followlinks=self.follow_symlinks):
for filename, values in self.iglob(os.path.join(t[0], '*')):
yield filename, values
else:
empty_glob = True
for filename, values in self.iglob(path):
yield filename, values
empty_glob = False
if empty_glob:
yield path, None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:process; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:source; 5, identifier:target; 6, identifier:rdfsonly; 7, default_parameter; 7, 8; 7, 9; 8, identifier:base; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:logger; 12, identifier:logging; 13, block; 13, 14; 13, 16; 13, 296; 14, expression_statement; 14, 15; 15, string:'''
Prepare a statement into a triple ready for rdflib graph
'''; 16, for_statement; 16, 17; 16, 18; 16, 23; 17, identifier:link; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:source; 21, identifier:match; 22, argument_list; 23, block; 23, 24; 23, 35; 23, 36; 23, 47; 23, 58; 23, 69; 23, 132; 23, 177; 23, 229; 23, 236; 23, 237; 23, 251; 23, 268; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 30; 26, pattern_list; 26, 27; 26, 28; 26, 29; 27, identifier:s; 28, identifier:p; 29, identifier:o; 30, subscript; 30, 31; 30, 32; 31, identifier:link; 32, slice; 32, 33; 32, 34; 33, colon; 34, integer:3; 35, comment; 36, if_statement; 36, 37; 36, 45; 37, comparison_operator:==; 37, 38; 37, 39; 38, identifier:s; 39, binary_operator:+; 39, 40; 39, 44; 40, parenthesized_expression; 40, 41; 41, boolean_operator:or; 41, 42; 41, 43; 42, identifier:base; 43, string:''; 44, string:'@docheader'; 45, block; 45, 46; 46, continue_statement; 47, if_statement; 47, 48; 47, 51; 48, comparison_operator:in; 48, 49; 48, 50; 49, identifier:p; 50, identifier:RESOURCE_MAPPING; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:p; 55, subscript; 55, 56; 55, 57; 56, identifier:RESOURCE_MAPPING; 57, identifier:p; 58, if_statement; 58, 59; 58, 62; 59, comparison_operator:in; 59, 60; 59, 61; 60, identifier:o; 61, identifier:RESOURCE_MAPPING; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:o; 66, subscript; 66, 67; 66, 68; 67, identifier:RESOURCE_MAPPING; 68, identifier:o; 69, if_statement; 69, 70; 69, 75; 70, comparison_operator:==; 70, 71; 70, 72; 71, identifier:p; 72, binary_operator:+; 72, 73; 72, 74; 73, identifier:VERSA_BASEIRI; 74, string:'refines'; 75, block; 75, 76; 75, 89; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:tlinks; 79, call; 79, 80; 79, 81; 80, identifier:list; 81, argument_list; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:source; 85, identifier:match; 86, argument_list; 86, 87; 86, 88; 87, identifier:s; 88, identifier:TYPE_REL; 89, if_statement; 89, 90; 89, 91; 90, identifier:tlinks; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 102; 92, 112; 93, comparison_operator:==; 93, 94; 93, 99; 94, subscript; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:tlinks; 97, integer:0; 98, identifier:TARGET; 99, binary_operator:+; 99, 100; 99, 101; 100, identifier:VERSA_BASEIRI; 101, string:'Resource'; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:p; 106, call; 106, 107; 106, 108; 107, identifier:I; 108, argument_list; 108, 109; 109, binary_operator:+; 109, 110; 109, 111; 110, identifier:RDFS_NAMESPACE; 111, string:'subClassOf'; 112, elif_clause; 112, 113; 112, 122; 113, comparison_operator:==; 113, 114; 113, 119; 114, subscript; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:tlinks; 117, integer:0; 118, identifier:TARGET; 119, binary_operator:+; 119, 120; 119, 121; 120, identifier:VERSA_BASEIRI; 121, string:'Property'; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:p; 126, call; 126, 127; 126, 128; 127, identifier:I; 128, argument_list; 128, 129; 129, binary_operator:+; 129, 130; 129, 131; 130, identifier:RDFS_NAMESPACE; 131, string:'subPropertyOf'; 132, if_statement; 132, 133; 132, 138; 133, comparison_operator:==; 133, 134; 133, 135; 134, identifier:p; 135, binary_operator:+; 135, 136; 135, 137; 136, identifier:VERSA_BASEIRI; 137, string:'properties'; 138, block; 138, 139; 138, 155; 138, 176; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:suri; 142, conditional_expression:if; 142, 143; 142, 153; 142, 154; 143, call; 143, 144; 143, 145; 144, identifier:I; 145, argument_list; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:iri; 149, identifier:absolutize; 150, argument_list; 150, 151; 150, 152; 151, identifier:s; 152, identifier:base; 153, identifier:base; 154, identifier:s; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:target; 159, identifier:add; 160, argument_list; 160, 161; 161, tuple; 161, 162; 161, 166; 161, 172; 162, call; 162, 163; 162, 164; 163, identifier:URIRef; 164, argument_list; 164, 165; 165, identifier:o; 166, call; 166, 167; 166, 168; 167, identifier:URIRef; 168, argument_list; 168, 169; 169, binary_operator:+; 169, 170; 169, 171; 170, identifier:RDFS_NAMESPACE; 171, string:'domain'; 172, call; 172, 173; 172, 174; 173, identifier:URIRef; 174, argument_list; 174, 175; 175, identifier:suri; 176, continue_statement; 177, if_statement; 177, 178; 177, 183; 178, comparison_operator:==; 178, 179; 178, 180; 179, identifier:p; 180, binary_operator:+; 180, 181; 180, 182; 181, identifier:VERSA_BASEIRI; 182, string:'value'; 183, block; 183, 184; 184, if_statement; 184, 185; 184, 190; 185, comparison_operator:not; 185, 186; 185, 187; 186, identifier:o; 187, list:['Literal', 'IRI']; 187, 188; 187, 189; 188, string:'Literal'; 189, string:'IRI'; 190, block; 190, 191; 190, 207; 190, 228; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:ouri; 194, conditional_expression:if; 194, 195; 194, 205; 194, 206; 195, call; 195, 196; 195, 197; 196, identifier:I; 197, argument_list; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:iri; 201, identifier:absolutize; 202, argument_list; 202, 203; 202, 204; 203, identifier:o; 204, identifier:base; 205, identifier:base; 206, identifier:o; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:target; 211, identifier:add; 212, argument_list; 212, 213; 213, tuple; 213, 214; 213, 218; 213, 224; 214, call; 214, 215; 214, 216; 215, identifier:URIRef; 216, argument_list; 216, 217; 217, identifier:s; 218, call; 218, 219; 218, 220; 219, identifier:URIRef; 220, argument_list; 220, 221; 221, binary_operator:+; 221, 222; 221, 223; 222, identifier:RDFS_NAMESPACE; 223, string:'range'; 224, call; 224, 225; 224, 226; 225, identifier:URIRef; 226, argument_list; 226, 227; 227, identifier:ouri; 228, continue_statement; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:s; 232, call; 232, 233; 232, 234; 233, identifier:URIRef; 234, argument_list; 234, 235; 235, identifier:s; 236, comment; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:p; 240, conditional_expression:if; 240, 241; 240, 244; 240, 247; 241, attribute; 241, 242; 241, 243; 242, identifier:RDF; 243, identifier:type; 244, comparison_operator:==; 244, 245; 244, 246; 245, identifier:p; 246, identifier:TYPE_REL; 247, call; 247, 248; 247, 249; 248, identifier:URIRef; 249, argument_list; 249, 250; 250, identifier:p; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:o; 254, conditional_expression:if; 254, 255; 254, 259; 254, 264; 255, call; 255, 256; 255, 257; 256, identifier:URIRef; 257, argument_list; 257, 258; 258, identifier:o; 259, call; 259, 260; 259, 261; 260, identifier:isinstance; 261, argument_list; 261, 262; 261, 263; 262, identifier:o; 263, identifier:I; 264, call; 264, 265; 264, 266; 265, identifier:Literal; 266, argument_list; 266, 267; 267, identifier:o; 268, if_statement; 268, 269; 268, 285; 269, boolean_operator:or; 269, 270; 269, 279; 270, boolean_operator:or; 270, 271; 270, 273; 271, not_operator; 271, 272; 272, identifier:rdfsonly; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:p; 276, identifier:startswith; 277, argument_list; 277, 278; 278, identifier:RDF_NAMESPACE; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:p; 282, identifier:startswith; 283, argument_list; 283, 284; 284, identifier:RDFS_NAMESPACE; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:target; 290, identifier:add; 291, argument_list; 291, 292; 292, tuple; 292, 293; 292, 294; 292, 295; 293, identifier:s; 294, identifier:p; 295, identifier:o; 296, return_statement | def process(source, target, rdfsonly, base=None, logger=logging):
'''
Prepare a statement into a triple ready for rdflib graph
'''
for link in source.match():
s, p, o = link[:3]
#SKip docheader statements
if s == (base or '') + '@docheader': continue
if p in RESOURCE_MAPPING: p = RESOURCE_MAPPING[p]
if o in RESOURCE_MAPPING: o = RESOURCE_MAPPING[o]
if p == VERSA_BASEIRI + 'refines':
tlinks = list(source.match(s, TYPE_REL))
if tlinks:
if tlinks[0][TARGET] == VERSA_BASEIRI + 'Resource':
p = I(RDFS_NAMESPACE + 'subClassOf')
elif tlinks[0][TARGET] == VERSA_BASEIRI + 'Property':
p = I(RDFS_NAMESPACE + 'subPropertyOf')
if p == VERSA_BASEIRI + 'properties':
suri = I(iri.absolutize(s, base)) if base else s
target.add((URIRef(o), URIRef(RDFS_NAMESPACE + 'domain'), URIRef(suri)))
continue
if p == VERSA_BASEIRI + 'value':
if o not in ['Literal', 'IRI']:
ouri = I(iri.absolutize(o, base)) if base else o
target.add((URIRef(s), URIRef(RDFS_NAMESPACE + 'range'), URIRef(ouri)))
continue
s = URIRef(s)
#Translate v:type to rdf:type
p = RDF.type if p == TYPE_REL else URIRef(p)
o = URIRef(o) if isinstance(o, I) else Literal(o)
if not rdfsonly or p.startswith(RDF_NAMESPACE) or p.startswith(RDFS_NAMESPACE):
target.add((s, p, o))
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:show_more; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 4, identifier:request; 5, identifier:post_process_fun; 6, identifier:get_fun; 7, identifier:object_class; 8, default_parameter; 8, 9; 8, 10; 9, identifier:should_cache; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:template; 13, string:'common_json.html'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:to_json_kwargs; 16, None; 17, block; 17, 18; 17, 20; 17, 50; 17, 80; 17, 89; 17, 95; 17, 114; 17, 129; 18, expression_statement; 18, 19; 19, comment; 20, if_statement; 20, 21; 20, 29; 21, boolean_operator:and; 21, 22; 21, 24; 22, not_operator; 22, 23; 23, identifier:should_cache; 24, comparison_operator:in; 24, 25; 24, 26; 25, string:'json_orderby'; 26, attribute; 26, 27; 26, 28; 27, identifier:request; 28, identifier:GET; 29, block; 29, 30; 30, return_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:render_json; 33, argument_list; 33, 34; 33, 35; 33, 39; 33, 42; 33, 47; 34, identifier:request; 35, dictionary; 35, 36; 36, pair; 36, 37; 36, 38; 37, string:'error'; 38, string:"Can't order the result according to the JSON field, because the caching for this type of object is turned off. See the documentation."; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:template; 41, string:'questions_json.html'; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:help_text; 44, attribute; 44, 45; 44, 46; 45, identifier:show_more; 46, identifier:__doc__; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:status; 49, integer:501; 50, if_statement; 50, 51; 50, 59; 51, boolean_operator:and; 51, 52; 51, 54; 52, not_operator; 52, 53; 53, identifier:should_cache; 54, comparison_operator:in; 54, 55; 54, 56; 55, string:'all'; 56, attribute; 56, 57; 56, 58; 57, identifier:request; 58, identifier:GET; 59, block; 59, 60; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:render_json; 63, argument_list; 63, 64; 63, 65; 63, 69; 63, 72; 63, 77; 64, identifier:request; 65, dictionary; 65, 66; 66, pair; 66, 67; 66, 68; 67, string:'error'; 68, string:"Can't get all objects, because the caching for this type of object is turned off. See the documentation."; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:template; 71, string:'questions_json.html'; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:help_text; 74, attribute; 74, 75; 74, 76; 75, identifier:show_more; 76, identifier:__doc__; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:status; 79, integer:501; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:is; 81, 82; 81, 83; 82, identifier:to_json_kwargs; 83, None; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:to_json_kwargs; 88, dictionary; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:time_start; 92, call; 92, 93; 92, 94; 93, identifier:time_lib; 94, argument_list; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:limit; 98, call; 98, 99; 98, 100; 99, identifier:min; 100, argument_list; 100, 101; 100, 113; 101, call; 101, 102; 101, 103; 102, identifier:int; 103, argument_list; 103, 104; 104, call; 104, 105; 104, 110; 105, attribute; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:request; 108, identifier:GET; 109, identifier:get; 110, argument_list; 110, 111; 110, 112; 111, string:'limit'; 112, integer:10; 113, integer:100; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:page; 117, call; 117, 118; 117, 119; 118, identifier:int; 119, argument_list; 119, 120; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:request; 124, identifier:GET; 125, identifier:get; 126, argument_list; 126, 127; 126, 128; 127, string:'page'; 128, integer:0; 129, try_statement; 129, 130; 129, 411; 130, block; 130, 131; 130, 139; 130, 174; 130, 203; 130, 233; 130, 242; 130, 298; 130, 311; 130, 319; 130, 397; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:objs; 134, call; 134, 135; 134, 136; 135, identifier:get_fun; 136, argument_list; 136, 137; 136, 138; 137, identifier:request; 138, identifier:object_class; 139, if_statement; 139, 140; 139, 145; 140, comparison_operator:in; 140, 141; 140, 142; 141, string:'db_orderby'; 142, attribute; 142, 143; 142, 144; 143, identifier:request; 144, identifier:GET; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:objs; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:objs; 152, identifier:order_by; 153, argument_list; 153, 154; 154, binary_operator:+; 154, 155; 154, 164; 155, parenthesized_expression; 155, 156; 156, conditional_expression:if; 156, 157; 156, 158; 156, 163; 157, string:'-'; 158, comparison_operator:in; 158, 159; 158, 160; 159, string:'desc'; 160, attribute; 160, 161; 160, 162; 161, identifier:request; 162, identifier:GET; 163, string:''; 164, call; 164, 165; 164, 172; 165, attribute; 165, 166; 165, 171; 166, subscript; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:request; 169, identifier:GET; 170, string:'db_orderby'; 171, identifier:strip; 172, argument_list; 172, 173; 173, string:'/'; 174, if_statement; 174, 175; 174, 186; 175, boolean_operator:and; 175, 176; 175, 181; 176, comparison_operator:not; 176, 177; 176, 178; 177, string:'all'; 178, attribute; 178, 179; 178, 180; 179, identifier:request; 180, identifier:GET; 181, comparison_operator:not; 181, 182; 181, 183; 182, string:'json_orderby'; 183, attribute; 183, 184; 183, 185; 184, identifier:request; 185, identifier:GET; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:objs; 190, subscript; 190, 191; 190, 192; 191, identifier:objs; 192, slice; 192, 193; 192, 196; 192, 197; 193, binary_operator:*; 193, 194; 193, 195; 194, identifier:page; 195, identifier:limit; 196, colon; 197, binary_operator:*; 197, 198; 197, 202; 198, parenthesized_expression; 198, 199; 199, binary_operator:+; 199, 200; 199, 201; 200, identifier:page; 201, integer:1; 202, identifier:limit; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:cache_key; 206, binary_operator:%; 206, 207; 206, 208; 207, string:'proso_common_sql_json_%s'; 208, call; 208, 209; 208, 232; 209, attribute; 209, 210; 209, 231; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:hashlib; 213, identifier:sha1; 214, argument_list; 214, 215; 215, call; 215, 216; 215, 230; 216, attribute; 216, 217; 216, 229; 217, parenthesized_expression; 217, 218; 218, binary_operator:+; 218, 219; 218, 225; 219, call; 219, 220; 219, 221; 220, identifier:str; 221, argument_list; 221, 222; 222, attribute; 222, 223; 222, 224; 223, identifier:objs; 224, identifier:query; 225, call; 225, 226; 225, 227; 226, identifier:str; 227, argument_list; 227, 228; 228, identifier:to_json_kwargs; 229, identifier:encode; 230, argument_list; 231, identifier:hexdigest; 232, argument_list; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:cached; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:cache; 239, identifier:get; 240, argument_list; 240, 241; 241, identifier:cache_key; 242, if_statement; 242, 243; 242, 246; 242, 256; 243, boolean_operator:and; 243, 244; 243, 245; 244, identifier:should_cache; 245, identifier:cached; 246, block; 246, 247; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:list_objs; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:json_lib; 253, identifier:loads; 254, argument_list; 254, 255; 255, identifier:cached; 256, else_clause; 256, 257; 257, block; 257, 258; 257, 275; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:list_objs; 261, list_comprehension; 261, 262; 261, 269; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:x; 265, identifier:to_json; 266, argument_list; 266, 267; 267, dictionary_splat; 267, 268; 268, identifier:to_json_kwargs; 269, for_in_clause; 269, 270; 269, 271; 270, identifier:x; 271, call; 271, 272; 271, 273; 272, identifier:list; 273, argument_list; 273, 274; 274, identifier:objs; 275, if_statement; 275, 276; 275, 277; 276, identifier:should_cache; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:cache; 282, identifier:set; 283, argument_list; 283, 284; 283, 285; 283, 291; 284, identifier:cache_key; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:json_lib; 288, identifier:dumps; 289, argument_list; 289, 290; 290, identifier:list_objs; 291, binary_operator:*; 291, 292; 291, 297; 292, binary_operator:*; 292, 293; 292, 296; 293, binary_operator:*; 293, 294; 293, 295; 294, integer:60; 295, integer:60; 296, integer:24; 297, integer:30; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:LOGGER; 302, identifier:debug; 303, argument_list; 303, 304; 303, 305; 304, string:'loading objects in show_more view took %s seconds'; 305, parenthesized_expression; 305, 306; 306, binary_operator:-; 306, 307; 306, 310; 307, call; 307, 308; 307, 309; 308, identifier:time_lib; 309, argument_list; 310, identifier:time_start; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:json; 314, call; 314, 315; 314, 316; 315, identifier:post_process_fun; 316, argument_list; 316, 317; 316, 318; 317, identifier:request; 318, identifier:list_objs; 319, if_statement; 319, 320; 319, 325; 320, comparison_operator:in; 320, 321; 320, 322; 321, string:'json_orderby'; 322, attribute; 322, 323; 322, 324; 323, identifier:request; 324, identifier:GET; 325, block; 325, 326; 325, 332; 325, 361; 325, 384; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 329; 328, identifier:time_before_json_sort; 329, call; 329, 330; 329, 331; 330, identifier:time_lib; 331, argument_list; 332, expression_statement; 332, 333; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:json; 336, identifier:sort; 337, argument_list; 337, 338; 338, keyword_argument; 338, 339; 338, 340; 339, identifier:key; 340, lambda; 340, 341; 340, 343; 341, lambda_parameters; 341, 342; 342, identifier:x; 343, binary_operator:*; 343, 344; 343, 354; 344, parenthesized_expression; 344, 345; 345, conditional_expression:if; 345, 346; 345, 348; 345, 353; 346, unary_operator:-; 346, 347; 347, integer:1; 348, comparison_operator:in; 348, 349; 348, 350; 349, string:'desc'; 350, attribute; 350, 351; 350, 352; 351, identifier:request; 352, identifier:GET; 353, integer:1; 354, subscript; 354, 355; 354, 356; 355, identifier:x; 356, subscript; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:request; 359, identifier:GET; 360, string:'json_orderby'; 361, if_statement; 361, 362; 361, 367; 362, comparison_operator:not; 362, 363; 362, 364; 363, string:'all'; 364, attribute; 364, 365; 364, 366; 365, identifier:request; 366, identifier:GET; 367, block; 367, 368; 368, expression_statement; 368, 369; 369, assignment; 369, 370; 369, 371; 370, identifier:json; 371, subscript; 371, 372; 371, 373; 372, identifier:json; 373, slice; 373, 374; 373, 377; 373, 378; 374, binary_operator:*; 374, 375; 374, 376; 375, identifier:page; 376, identifier:limit; 377, colon; 378, binary_operator:*; 378, 379; 378, 383; 379, parenthesized_expression; 379, 380; 380, binary_operator:+; 380, 381; 380, 382; 381, identifier:page; 382, integer:1; 383, identifier:limit; 384, expression_statement; 384, 385; 385, call; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:LOGGER; 388, identifier:debug; 389, argument_list; 389, 390; 389, 391; 390, string:'sorting objects according to JSON field took %s seconds'; 391, parenthesized_expression; 391, 392; 392, binary_operator:-; 392, 393; 392, 396; 393, call; 393, 394; 393, 395; 394, identifier:time_lib; 395, argument_list; 396, identifier:time_before_json_sort; 397, return_statement; 397, 398; 398, call; 398, 399; 398, 400; 399, identifier:render_json; 400, argument_list; 400, 401; 400, 402; 400, 403; 400, 406; 401, identifier:request; 402, identifier:json; 403, keyword_argument; 403, 404; 403, 405; 404, identifier:template; 405, identifier:template; 406, keyword_argument; 406, 407; 406, 408; 407, identifier:help_text; 408, attribute; 408, 409; 408, 410; 409, identifier:show_more; 410, identifier:__doc__; 411, except_clause; 411, 412; 411, 413; 412, identifier:EmptyResultSet; 413, block; 413, 414; 414, return_statement; 414, 415; 415, call; 415, 416; 415, 417; 416, identifier:render_json; 417, argument_list; 417, 418; 417, 419; 417, 420; 417, 423; 418, identifier:request; 419, list:[]; 420, keyword_argument; 420, 421; 420, 422; 421, identifier:template; 422, identifier:template; 423, keyword_argument; 423, 424; 423, 425; 424, identifier:help_text; 425, attribute; 425, 426; 425, 427; 426, identifier:show_more; 427, identifier:__doc__ | def show_more(request, post_process_fun, get_fun, object_class, should_cache=True, template='common_json.html', to_json_kwargs=None):
"""
Return list of objects of the given type.
GET parameters:
limit:
number of returned objects (default 10, maximum 100)
page:
current page number
filter_column:
column name used to filter the results
filter_value:
value for the specified column used to filter the results
user:
identifier of the current user
all:
return all objects available instead of paging; be aware this parameter
can be used only for objects for wich the caching is turned on
db_orderby:
database column which the result should be ordered by
json_orderby:
field of the JSON object which the result should be ordered by, it is
less effective than the ordering via db_orderby; be aware this parameter
can be used only for objects for which the caching is turned on
desc
turn on the descending order
stats:
turn on the enrichment of the objects by some statistics
html
turn on the HTML version of the API
environment
turn on the enrichment of the related environment values
"""
if not should_cache and 'json_orderby' in request.GET:
return render_json(request, {
'error': "Can't order the result according to the JSON field, because the caching for this type of object is turned off. See the documentation."
},
template='questions_json.html', help_text=show_more.__doc__, status=501)
if not should_cache and 'all' in request.GET:
return render_json(request, {
'error': "Can't get all objects, because the caching for this type of object is turned off. See the documentation."
},
template='questions_json.html', help_text=show_more.__doc__, status=501)
if to_json_kwargs is None:
to_json_kwargs = {}
time_start = time_lib()
limit = min(int(request.GET.get('limit', 10)), 100)
page = int(request.GET.get('page', 0))
try:
objs = get_fun(request, object_class)
if 'db_orderby' in request.GET:
objs = objs.order_by(('-' if 'desc' in request.GET else '') + request.GET['db_orderby'].strip('/'))
if 'all' not in request.GET and 'json_orderby' not in request.GET:
objs = objs[page * limit:(page + 1) * limit]
cache_key = 'proso_common_sql_json_%s' % hashlib.sha1((str(objs.query) + str(to_json_kwargs)).encode()).hexdigest()
cached = cache.get(cache_key)
if should_cache and cached:
list_objs = json_lib.loads(cached)
else:
list_objs = [x.to_json(**to_json_kwargs) for x in list(objs)]
if should_cache:
cache.set(cache_key, json_lib.dumps(list_objs), 60 * 60 * 24 * 30)
LOGGER.debug('loading objects in show_more view took %s seconds', (time_lib() - time_start))
json = post_process_fun(request, list_objs)
if 'json_orderby' in request.GET:
time_before_json_sort = time_lib()
json.sort(key=lambda x: (-1 if 'desc' in request.GET else 1) * x[request.GET['json_orderby']])
if 'all' not in request.GET:
json = json[page * limit:(page + 1) * limit]
LOGGER.debug('sorting objects according to JSON field took %s seconds', (time_lib() - time_before_json_sort))
return render_json(request, json, template=template, help_text=show_more.__doc__)
except EmptyResultSet:
return render_json(request, [], template=template, help_text=show_more.__doc__) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:cache_control; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 4, default_parameter; 4, 5; 4, 6; 5, identifier:max_age; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:private; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:public; 12, False; 13, default_parameter; 13, 14; 13, 15; 14, identifier:s_maxage; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:must_revalidate; 18, False; 19, default_parameter; 19, 20; 19, 21; 20, identifier:proxy_revalidate; 21, False; 22, default_parameter; 22, 23; 22, 24; 23, identifier:no_cache; 24, False; 25, default_parameter; 25, 26; 25, 27; 26, identifier:no_store; 27, False; 28, block; 28, 29; 28, 31; 28, 44; 28, 61; 28, 78; 28, 82; 28, 92; 28, 102; 28, 116; 28, 130; 28, 140; 28, 150; 28, 160; 28, 170; 29, expression_statement; 29, 30; 30, comment; 31, if_statement; 31, 32; 31, 38; 32, call; 32, 33; 32, 34; 33, identifier:all; 34, argument_list; 34, 35; 35, list:[private, public]; 35, 36; 35, 37; 36, identifier:private; 37, identifier:public; 38, block; 38, 39; 39, raise_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:ValueError; 42, argument_list; 42, 43; 43, string:"'private' and 'public' are mutually exclusive"; 44, if_statement; 44, 45; 44, 50; 45, call; 45, 46; 45, 47; 46, identifier:isinstance; 47, argument_list; 47, 48; 47, 49; 48, identifier:max_age; 49, identifier:timedelta; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:max_age; 54, call; 54, 55; 54, 56; 55, identifier:int; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:total_seconds; 59, argument_list; 59, 60; 60, identifier:max_age; 61, if_statement; 61, 62; 61, 67; 62, call; 62, 63; 62, 64; 63, identifier:isinstance; 64, argument_list; 64, 65; 64, 66; 65, identifier:s_maxage; 66, identifier:timedelta; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:s_maxage; 71, call; 71, 72; 71, 73; 72, identifier:int; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:total_seconds; 76, argument_list; 76, 77; 77, identifier:s_maxage; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:directives; 81, list:[]; 82, if_statement; 82, 83; 82, 84; 83, identifier:public; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:directives; 89, identifier:append; 90, argument_list; 90, 91; 91, string:'public'; 92, if_statement; 92, 93; 92, 94; 93, identifier:private; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:directives; 99, identifier:append; 100, argument_list; 100, 101; 101, string:'private'; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:max_age; 105, None; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:directives; 111, identifier:append; 112, argument_list; 112, 113; 113, binary_operator:%; 113, 114; 113, 115; 114, string:'max-age=%d'; 115, identifier:max_age; 116, if_statement; 116, 117; 116, 120; 117, comparison_operator:is; 117, 118; 117, 119; 118, identifier:s_maxage; 119, None; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:directives; 125, identifier:append; 126, argument_list; 126, 127; 127, binary_operator:%; 127, 128; 127, 129; 128, string:'s-maxage=%d'; 129, identifier:s_maxage; 130, if_statement; 130, 131; 130, 132; 131, identifier:no_cache; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:directives; 137, identifier:append; 138, argument_list; 138, 139; 139, string:'no-cache'; 140, if_statement; 140, 141; 140, 142; 141, identifier:no_store; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:directives; 147, identifier:append; 148, argument_list; 148, 149; 149, string:'no-store'; 150, if_statement; 150, 151; 150, 152; 151, identifier:must_revalidate; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:directives; 157, identifier:append; 158, argument_list; 158, 159; 159, string:'must-revalidate'; 160, if_statement; 160, 161; 160, 162; 161, identifier:proxy_revalidate; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:directives; 167, identifier:append; 168, argument_list; 168, 169; 169, string:'proxy-revalidate'; 170, return_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, string:', '; 174, identifier:join; 175, argument_list; 175, 176; 176, identifier:directives | def cache_control(max_age=None, private=False, public=False, s_maxage=None,
must_revalidate=False, proxy_revalidate=False, no_cache=False,
no_store=False):
"""Generate the value for a Cache-Control header.
Example:
>>> from rhino.http import cache_control as cc
>>> from datetime import timedelta
>>> cc(public=1, max_age=3600)
'public, max-age=3600'
>>> cc(public=1, max_age=timedelta(hours=1))
'public, max-age=3600'
>>> cc(private=True, no_cache=True, no_store=True)
'private, no-cache, no-store'
"""
if all([private, public]):
raise ValueError("'private' and 'public' are mutually exclusive")
if isinstance(max_age, timedelta):
max_age = int(total_seconds(max_age))
if isinstance(s_maxage, timedelta):
s_maxage = int(total_seconds(s_maxage))
directives = []
if public: directives.append('public')
if private: directives.append('private')
if max_age is not None: directives.append('max-age=%d' % max_age)
if s_maxage is not None: directives.append('s-maxage=%d' % s_maxage)
if no_cache: directives.append('no-cache')
if no_store: directives.append('no-store')
if must_revalidate: directives.append('must-revalidate')
if proxy_revalidate: directives.append('proxy-revalidate')
return ', '.join(directives) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:plot_places; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 25; 5, 29; 5, 33; 5, 90; 5, 133; 5, 149; 5, 159; 5, 169; 5, 212; 6, expression_statement; 6, 7; 7, string:'''Plot places where the agent has been and generated a spirograph.
'''; 8, import_from_statement; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier:matplotlib; 11, aliased_import; 11, 12; 11, 14; 12, dotted_name; 12, 13; 13, identifier:pyplot; 14, identifier:plt; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:fig; 19, identifier:ax; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:plt; 23, identifier:subplots; 24, argument_list; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:x; 28, list:[]; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:y; 32, list:[]; 33, if_statement; 33, 34; 33, 42; 34, comparison_operator:>; 34, 35; 34, 41; 35, call; 35, 36; 35, 37; 36, identifier:len; 37, argument_list; 37, 38; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:arg_history; 41, integer:1; 42, block; 42, 43; 42, 47; 42, 51; 42, 75; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:xs; 46, list:[]; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:ys; 50, list:[]; 51, for_statement; 51, 52; 51, 53; 51, 56; 52, identifier:p; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:arg_history; 56, block; 56, 57; 56, 66; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:xs; 61, identifier:append; 62, argument_list; 62, 63; 63, subscript; 63, 64; 63, 65; 64, identifier:p; 65, integer:0; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:ys; 70, identifier:append; 71, argument_list; 71, 72; 72, subscript; 72, 73; 72, 74; 73, identifier:p; 74, integer:1; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:ax; 79, identifier:plot; 80, argument_list; 80, 81; 80, 82; 80, 83; 81, identifier:xs; 82, identifier:ys; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:color; 85, tuple; 85, 86; 85, 87; 85, 88; 85, 89; 86, float:0.0; 87, float:0.0; 88, float:1.0; 89, float:0.1; 90, for_statement; 90, 91; 90, 92; 90, 95; 91, identifier:a; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:A; 95, block; 95, 96; 96, if_statement; 96, 97; 96, 102; 97, comparison_operator:==; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:a; 100, identifier:self_criticism; 101, string:'pass'; 102, block; 102, 103; 102, 115; 102, 124; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:args; 106, subscript; 106, 107; 106, 114; 107, subscript; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:a; 110, identifier:framings; 111, attribute; 111, 112; 111, 113; 112, identifier:a; 113, identifier:creator; 114, string:'args'; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:x; 119, identifier:append; 120, argument_list; 120, 121; 121, subscript; 121, 122; 121, 123; 122, identifier:args; 123, integer:0; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:y; 128, identifier:append; 129, argument_list; 129, 130; 130, subscript; 130, 131; 130, 132; 131, identifier:args; 132, integer:1; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:sc; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:ax; 139, identifier:scatter; 140, argument_list; 140, 141; 140, 142; 140, 143; 140, 146; 141, identifier:x; 142, identifier:y; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:marker; 145, string:"x"; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:color; 148, string:'red'; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:ax; 153, identifier:set_xlim; 154, argument_list; 154, 155; 155, list:[-200, 200]; 155, 156; 155, 158; 156, unary_operator:-; 156, 157; 157, integer:200; 158, integer:200; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:ax; 163, identifier:set_ylim; 164, argument_list; 164, 165; 165, list:[-200, 200]; 165, 166; 165, 168; 166, unary_operator:-; 166, 167; 167, integer:200; 168, integer:200; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:agent_vars; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, string:"{}_{}_{}{}_last={}_stmem=list{}_veto={}_sc={}_jump={}_sw={}_mr={}_maxN"; 175, identifier:format; 176, argument_list; 176, 177; 176, 180; 176, 183; 176, 186; 176, 189; 176, 192; 176, 197; 176, 200; 176, 203; 176, 206; 176, 209; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:name; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:age; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:env_learning_method; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:env_learning_amount; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:env_learn_on_add; 192, attribute; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:stmem; 196, identifier:length; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:_novelty_threshold; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:_own_threshold; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:jump; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:search_width; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:move_radius; 212, if_statement; 212, 213; 212, 218; 212, 390; 213, comparison_operator:is; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:logger; 217, None; 218, block; 218, 219; 218, 240; 218, 247; 218, 253; 218, 274; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:imname; 222, call; 222, 223; 222, 228; 223, attribute; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:os; 226, identifier:path; 227, identifier:join; 228, argument_list; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:logger; 233, identifier:folder; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, string:'{}.png'; 237, identifier:format; 238, argument_list; 238, 239; 239, identifier:agent_vars; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:plt; 244, identifier:savefig; 245, argument_list; 245, 246; 246, identifier:imname; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:plt; 251, identifier:close; 252, argument_list; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:fname; 256, call; 256, 257; 256, 262; 257, attribute; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:os; 260, identifier:path; 261, identifier:join; 262, argument_list; 262, 263; 262, 268; 263, attribute; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:logger; 267, identifier:folder; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, string:'{}.txt'; 271, identifier:format; 272, argument_list; 272, 273; 273, identifier:agent_vars; 274, with_statement; 274, 275; 274, 285; 275, with_clause; 275, 276; 276, with_item; 276, 277; 277, as_pattern; 277, 278; 277, 283; 278, call; 278, 279; 278, 280; 279, identifier:open; 280, argument_list; 280, 281; 280, 282; 281, identifier:fname; 282, string:"w"; 283, as_pattern_target; 283, 284; 284, identifier:f; 285, block; 285, 286; 285, 305; 285, 312; 285, 331; 285, 338; 285, 357; 285, 364; 285, 383; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:f; 290, identifier:write; 291, argument_list; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, string:" "; 295, identifier:join; 296, argument_list; 296, 297; 297, list_comprehension; 297, 298; 297, 302; 298, call; 298, 299; 298, 300; 299, identifier:str; 300, argument_list; 300, 301; 301, identifier:e; 302, for_in_clause; 302, 303; 302, 304; 303, identifier:e; 304, identifier:xs; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:f; 309, identifier:write; 310, argument_list; 310, 311; 311, string:"\n"; 312, expression_statement; 312, 313; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:f; 316, identifier:write; 317, argument_list; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, string:" "; 321, identifier:join; 322, argument_list; 322, 323; 323, list_comprehension; 323, 324; 323, 328; 324, call; 324, 325; 324, 326; 325, identifier:str; 326, argument_list; 326, 327; 327, identifier:e; 328, for_in_clause; 328, 329; 328, 330; 329, identifier:e; 330, identifier:ys; 331, expression_statement; 331, 332; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:f; 335, identifier:write; 336, argument_list; 336, 337; 337, string:"\n"; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:f; 342, identifier:write; 343, argument_list; 343, 344; 344, call; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, string:" "; 347, identifier:join; 348, argument_list; 348, 349; 349, list_comprehension; 349, 350; 349, 354; 350, call; 350, 351; 350, 352; 351, identifier:str; 352, argument_list; 352, 353; 353, identifier:e; 354, for_in_clause; 354, 355; 354, 356; 355, identifier:e; 356, identifier:x; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:f; 361, identifier:write; 362, argument_list; 362, 363; 363, string:"\n"; 364, expression_statement; 364, 365; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:f; 368, identifier:write; 369, argument_list; 369, 370; 370, call; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, string:" "; 373, identifier:join; 374, argument_list; 374, 375; 375, list_comprehension; 375, 376; 375, 380; 376, call; 376, 377; 376, 378; 377, identifier:str; 378, argument_list; 378, 379; 379, identifier:e; 380, for_in_clause; 380, 381; 380, 382; 381, identifier:e; 382, identifier:y; 383, expression_statement; 383, 384; 384, call; 384, 385; 384, 388; 385, attribute; 385, 386; 385, 387; 386, identifier:f; 387, identifier:write; 388, argument_list; 388, 389; 389, string:"\n"; 390, else_clause; 390, 391; 391, block; 391, 392; 392, expression_statement; 392, 393; 393, call; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:plt; 396, identifier:show; 397, argument_list | def plot_places(self):
'''Plot places where the agent has been and generated a spirograph.
'''
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
x = []
y = []
if len(self.arg_history) > 1:
xs = []
ys = []
for p in self.arg_history:
xs.append(p[0])
ys.append(p[1])
ax.plot(xs, ys, color=(0.0, 0.0, 1.0, 0.1))
for a in self.A:
if a.self_criticism == 'pass':
args = a.framings[a.creator]['args']
x.append(args[0])
y.append(args[1])
sc = ax.scatter(x, y, marker="x", color='red')
ax.set_xlim([-200, 200])
ax.set_ylim([-200, 200])
agent_vars = "{}_{}_{}{}_last={}_stmem=list{}_veto={}_sc={}_jump={}_sw={}_mr={}_maxN".format(
self.name, self.age, self.env_learning_method, self.env_learning_amount, self.env_learn_on_add,
self.stmem.length, self._novelty_threshold, self._own_threshold,
self.jump, self.search_width, self.move_radius)
if self.logger is not None:
imname = os.path.join(self.logger.folder, '{}.png'.format(agent_vars))
plt.savefig(imname)
plt.close()
fname = os.path.join(self.logger.folder, '{}.txt'.format(agent_vars))
with open(fname, "w") as f:
f.write(" ".join([str(e) for e in xs]))
f.write("\n")
f.write(" ".join([str(e) for e in ys]))
f.write("\n")
f.write(" ".join([str(e) for e in x]))
f.write("\n")
f.write(" ".join([str(e) for e in y]))
f.write("\n")
else:
plt.show() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:df; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:unit; 6, string:'GB'; 7, block; 7, 8; 7, 10; 7, 14; 7, 25; 7, 32; 7, 38; 7, 56; 7, 57; 7, 67; 7, 76; 7, 102; 7, 113; 7, 131; 7, 322; 8, expression_statement; 8, 9; 9, string:'''A wrapper for the df shell command.'''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:details; 13, dictionary; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:headers; 17, list:['Filesystem', 'Type', 'Size', 'Used', 'Available', 'Capacity', 'MountedOn']; 17, 18; 17, 19; 17, 20; 17, 21; 17, 22; 17, 23; 17, 24; 18, string:'Filesystem'; 19, string:'Type'; 20, string:'Size'; 21, string:'Used'; 22, string:'Available'; 23, string:'Capacity'; 24, string:'MountedOn'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:n; 28, call; 28, 29; 28, 30; 29, identifier:len; 30, argument_list; 30, 31; 31, identifier:headers; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:unit; 35, subscript; 35, 36; 35, 37; 36, identifier:df_conversions; 37, identifier:unit; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:p; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:subprocess; 44, identifier:Popen; 45, argument_list; 45, 46; 45, 51; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:args; 48, list:['df', '-TP']; 48, 49; 48, 50; 49, string:'df'; 50, string:'-TP'; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:stdout; 53, attribute; 53, 54; 53, 55; 54, identifier:subprocess; 55, identifier:PIPE; 56, comment; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, pattern_list; 59, 60; 59, 61; 60, identifier:stdout; 61, identifier:stderr; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:p; 65, identifier:communicate; 66, argument_list; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:lines; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:stdout; 73, identifier:split; 74, argument_list; 74, 75; 75, string:"\n"; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, subscript; 78, 79; 78, 80; 79, identifier:lines; 80, integer:0; 81, call; 81, 82; 81, 99; 82, attribute; 82, 83; 82, 98; 83, call; 83, 84; 83, 95; 84, attribute; 84, 85; 84, 94; 85, call; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:lines; 89, integer:0; 90, identifier:replace; 91, argument_list; 91, 92; 91, 93; 92, string:"Mounted on"; 93, string:"MountedOn"; 94, identifier:replace; 95, argument_list; 95, 96; 95, 97; 96, string:"1K-blocks"; 97, string:"Size"; 98, identifier:replace; 99, argument_list; 99, 100; 99, 101; 100, string:"1024-blocks"; 101, string:"Size"; 102, assert_statement; 102, 103; 103, parenthesized_expression; 103, 104; 104, comparison_operator:==; 104, 105; 104, 112; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:lines; 109, integer:0; 110, identifier:split; 111, argument_list; 112, identifier:headers; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:lines; 116, list_comprehension; 116, 117; 116, 122; 116, 125; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:l; 120, identifier:strip; 121, argument_list; 122, for_in_clause; 122, 123; 122, 124; 123, identifier:l; 124, identifier:lines; 125, if_clause; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:l; 129, identifier:strip; 130, argument_list; 131, for_statement; 131, 132; 131, 133; 131, 138; 132, identifier:line; 133, subscript; 133, 134; 133, 135; 134, identifier:lines; 135, slice; 135, 136; 135, 137; 136, integer:1; 137, colon; 138, block; 138, 139; 138, 147; 138, 156; 138, 164; 138, 168; 138, 189; 138, 202; 138, 212; 138, 220; 138, 233; 138, 246; 138, 261; 138, 262; 138, 314; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:tokens; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:line; 145, identifier:split; 146, argument_list; 147, if_statement; 147, 148; 147, 153; 147, 154; 148, comparison_operator:==; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:tokens; 151, integer:0; 152, string:'none'; 153, comment; 154, block; 154, 155; 155, continue_statement; 156, assert_statement; 156, 157; 157, parenthesized_expression; 157, 158; 158, comparison_operator:==; 158, 159; 158, 163; 159, call; 159, 160; 159, 161; 160, identifier:len; 161, argument_list; 161, 162; 162, identifier:tokens; 163, identifier:n; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:d; 167, dictionary; 168, for_statement; 168, 169; 168, 170; 168, 178; 169, identifier:x; 170, call; 170, 171; 170, 172; 171, identifier:range; 172, argument_list; 172, 173; 172, 174; 173, integer:1; 174, call; 174, 175; 174, 176; 175, identifier:len; 176, argument_list; 176, 177; 177, identifier:headers; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 186; 181, subscript; 181, 182; 181, 183; 182, identifier:d; 183, subscript; 183, 184; 183, 185; 184, identifier:headers; 185, identifier:x; 186, subscript; 186, 187; 186, 188; 187, identifier:tokens; 188, identifier:x; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:d; 193, string:'Size'; 194, binary_operator:/; 194, 195; 194, 201; 195, call; 195, 196; 195, 197; 196, identifier:float; 197, argument_list; 197, 198; 198, subscript; 198, 199; 198, 200; 199, identifier:d; 200, string:'Size'; 201, identifier:unit; 202, assert_statement; 202, 203; 203, parenthesized_expression; 203, 204; 204, call; 204, 205; 204, 210; 205, attribute; 205, 206; 205, 209; 206, subscript; 206, 207; 206, 208; 207, identifier:d; 208, string:'Capacity'; 209, identifier:endswith; 210, argument_list; 210, 211; 211, string:"%"; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:d; 216, string:'Use%'; 217, subscript; 217, 218; 217, 219; 218, identifier:d; 219, string:'Capacity'; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:d; 224, string:'Used'; 225, binary_operator:/; 225, 226; 225, 232; 226, call; 226, 227; 226, 228; 227, identifier:float; 228, argument_list; 228, 229; 229, subscript; 229, 230; 229, 231; 230, identifier:d; 231, string:'Used'; 232, identifier:unit; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 238; 235, subscript; 235, 236; 235, 237; 236, identifier:d; 237, string:'Available'; 238, binary_operator:/; 238, 239; 238, 245; 239, call; 239, 240; 239, 241; 240, identifier:float; 241, argument_list; 241, 242; 242, subscript; 242, 243; 242, 244; 243, identifier:d; 244, string:'Available'; 245, identifier:unit; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:d; 250, string:'Using'; 251, binary_operator:*; 251, 252; 251, 253; 252, integer:100; 253, parenthesized_expression; 253, 254; 254, binary_operator:/; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:d; 257, string:'Used'; 258, subscript; 258, 259; 258, 260; 259, identifier:d; 260, string:'Size'; 261, comment; 262, if_statement; 262, 263; 262, 271; 262, 280; 263, call; 263, 264; 263, 269; 264, attribute; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:d; 267, string:'Type'; 268, identifier:startswith; 269, argument_list; 269, 270; 270, string:'ext'; 271, block; 271, 272; 271, 273; 271, 279; 272, pass_statement; 273, expression_statement; 273, 274; 274, augmented_assignment:+=; 274, 275; 274, 278; 275, subscript; 275, 276; 275, 277; 276, identifier:d; 277, string:'Using'; 278, integer:5; 279, comment; 280, else_clause; 280, 281; 281, block; 281, 282; 281, 289; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:ext3_filesystems; 285, list:['ganon:', 'kortemmelab:', 'albana:']; 285, 286; 285, 287; 285, 288; 286, string:'ganon:'; 287, string:'kortemmelab:'; 288, string:'albana:'; 289, for_statement; 289, 290; 289, 291; 289, 292; 290, identifier:e3fs; 291, identifier:ext3_filesystems; 292, block; 292, 293; 293, if_statement; 293, 294; 293, 305; 294, comparison_operator:!=; 294, 295; 294, 303; 295, call; 295, 296; 295, 301; 296, attribute; 296, 297; 296, 300; 297, subscript; 297, 298; 297, 299; 298, identifier:tokens; 299, integer:0; 300, identifier:find; 301, argument_list; 301, 302; 302, identifier:e3fs; 303, unary_operator:-; 303, 304; 304, integer:1; 305, block; 305, 306; 305, 312; 305, 313; 306, expression_statement; 306, 307; 307, augmented_assignment:+=; 307, 308; 307, 311; 308, subscript; 308, 309; 308, 310; 309, identifier:d; 310, string:'Using'; 311, integer:5; 312, comment; 313, break_statement; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 321; 316, subscript; 316, 317; 316, 318; 317, identifier:details; 318, subscript; 318, 319; 318, 320; 319, identifier:tokens; 320, integer:0; 321, identifier:d; 322, return_statement; 322, 323; 323, identifier:details | def df(unit = 'GB'):
'''A wrapper for the df shell command.'''
details = {}
headers = ['Filesystem', 'Type', 'Size', 'Used', 'Available', 'Capacity', 'MountedOn']
n = len(headers)
unit = df_conversions[unit]
p = subprocess.Popen(args = ['df', '-TP'], stdout = subprocess.PIPE) # -P prevents line wrapping on long filesystem names
stdout, stderr = p.communicate()
lines = stdout.split("\n")
lines[0] = lines[0].replace("Mounted on", "MountedOn").replace("1K-blocks", "Size").replace("1024-blocks", "Size")
assert(lines[0].split() == headers)
lines = [l.strip() for l in lines if l.strip()]
for line in lines[1:]:
tokens = line.split()
if tokens[0] == 'none': # skip uninteresting entries
continue
assert(len(tokens) == n)
d = {}
for x in range(1, len(headers)):
d[headers[x]] = tokens[x]
d['Size'] = float(d['Size']) / unit
assert(d['Capacity'].endswith("%"))
d['Use%'] = d['Capacity']
d['Used'] = float(d['Used']) / unit
d['Available'] = float(d['Available']) / unit
d['Using'] = 100*(d['Used']/d['Size']) # same as Use% but with more precision
if d['Type'].startswith('ext'):
pass
d['Using'] += 5 # ext2, ext3, and ext4 reserve 5% by default
else:
ext3_filesystems = ['ganon:', 'kortemmelab:', 'albana:']
for e3fs in ext3_filesystems:
if tokens[0].find(e3fs) != -1:
d['Using'] += 5 # ext3 reserves 5%
break
details[tokens[0]] = d
return details |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:vote_mean; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:candidates; 5, identifier:votes; 6, identifier:n_winners; 7, block; 7, 8; 7, 10; 7, 23; 7, 47; 7, 69; 7, 80; 7, 97; 7, 112; 7, 116; 7, 145; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sums; 13, dictionary_comprehension; 13, 14; 13, 20; 14, pair; 14, 15; 14, 19; 15, call; 15, 16; 15, 17; 16, identifier:str; 17, argument_list; 17, 18; 18, identifier:candidate; 19, list:[]; 20, for_in_clause; 20, 21; 20, 22; 21, identifier:candidate; 22, identifier:candidates; 23, for_statement; 23, 24; 23, 25; 23, 26; 24, identifier:vote; 25, identifier:votes; 26, block; 26, 27; 27, for_statement; 27, 28; 27, 29; 27, 30; 28, identifier:v; 29, identifier:vote; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 43; 33, attribute; 33, 34; 33, 42; 34, subscript; 34, 35; 34, 36; 35, identifier:sums; 36, call; 36, 37; 36, 38; 37, identifier:str; 38, argument_list; 38, 39; 39, subscript; 39, 40; 39, 41; 40, identifier:v; 41, integer:0; 42, identifier:append; 43, argument_list; 43, 44; 44, subscript; 44, 45; 44, 46; 45, identifier:v; 46, integer:1; 47, for_statement; 47, 48; 47, 49; 47, 50; 48, identifier:s; 49, identifier:sums; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:sums; 55, identifier:s; 56, binary_operator:/; 56, 57; 56, 63; 57, call; 57, 58; 57, 59; 58, identifier:sum; 59, argument_list; 59, 60; 60, subscript; 60, 61; 60, 62; 61, identifier:sums; 62, identifier:s; 63, call; 63, 64; 63, 65; 64, identifier:len; 65, argument_list; 65, 66; 66, subscript; 66, 67; 66, 68; 67, identifier:sums; 68, identifier:s; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:ordering; 72, call; 72, 73; 72, 74; 73, identifier:list; 74, argument_list; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:sums; 78, identifier:items; 79, argument_list; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:ordering; 84, identifier:sort; 85, argument_list; 85, 86; 85, 94; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:key; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:operator; 91, identifier:itemgetter; 92, argument_list; 92, 93; 93, integer:1; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:reverse; 96, True; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:best; 100, subscript; 100, 101; 100, 102; 101, identifier:ordering; 102, slice; 102, 103; 102, 104; 103, colon; 104, call; 104, 105; 104, 106; 105, identifier:min; 106, argument_list; 106, 107; 106, 108; 107, identifier:n_winners; 108, call; 108, 109; 108, 110; 109, identifier:len; 110, argument_list; 110, 111; 111, identifier:ordering; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:d; 115, list:[]; 116, for_statement; 116, 117; 116, 118; 116, 119; 117, identifier:e; 118, identifier:best; 119, block; 119, 120; 120, for_statement; 120, 121; 120, 122; 120, 123; 121, identifier:c; 122, identifier:candidates; 123, block; 123, 124; 124, if_statement; 124, 125; 124, 133; 125, comparison_operator:==; 125, 126; 125, 130; 126, call; 126, 127; 126, 128; 127, identifier:str; 128, argument_list; 128, 129; 129, identifier:c; 130, subscript; 130, 131; 130, 132; 131, identifier:e; 132, integer:0; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:d; 138, identifier:append; 139, argument_list; 139, 140; 140, tuple; 140, 141; 140, 142; 141, identifier:c; 142, subscript; 142, 143; 142, 144; 143, identifier:e; 144, integer:1; 145, return_statement; 145, 146; 146, identifier:d | def vote_mean(candidates, votes, n_winners):
"""Perform mean voting based on votes.
Mean voting computes the mean preference for each of the artifact
candidates from the votes and sorts the candidates in the mean preference
order.
Ties are resolved randomly.
:param candidates: All candidates in the vote
:param votes: Votes from the agents
:param int n_winners: The number of vote winners
"""
sums = {str(candidate): [] for candidate in candidates}
for vote in votes:
for v in vote:
sums[str(v[0])].append(v[1])
for s in sums:
sums[s] = sum(sums[s]) / len(sums[s])
ordering = list(sums.items())
ordering.sort(key=operator.itemgetter(1), reverse=True)
best = ordering[:min(n_winners, len(ordering))]
d = []
for e in best:
for c in candidates:
if str(c) == e[0]:
d.append((c, e[1]))
return d |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:vote; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:candidates; 6, block; 6, 7; 6, 9; 6, 26; 6, 43; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:ranks; 12, list_comprehension; 12, 13; 12, 23; 13, tuple; 13, 14; 13, 15; 14, identifier:c; 15, subscript; 15, 16; 15, 22; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:evaluate; 20, argument_list; 20, 21; 21, identifier:c; 22, integer:0; 23, for_in_clause; 23, 24; 23, 25; 24, identifier:c; 25, identifier:candidates; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:ranks; 30, identifier:sort; 31, argument_list; 31, 32; 31, 40; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:key; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:operator; 37, identifier:itemgetter; 38, argument_list; 38, 39; 39, integer:1; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:reverse; 42, True; 43, return_statement; 43, 44; 44, identifier:ranks | def vote(self, candidates):
"""Rank artifact candidates.
The voting is needed for the agents living in societies using
social decision making. The function should return a sorted list
of (candidate, evaluation)-tuples. Depending on the social choice
function used, the evaluation might be omitted from the actual decision
making, or only a number of (the highest ranking) candidates may be
used.
This basic implementation ranks candidates based on
:meth:`~creamas.core.agent.CreativeAgent.evaluate`.
:param candidates:
list of :py:class:`~creamas.core.artifact.Artifact` objects to be
ranked
:returns:
Ordered list of (candidate, evaluation)-tuples
"""
ranks = [(c, self.evaluate(c)[0]) for c in candidates]
ranks.sort(key=operator.itemgetter(1), reverse=True)
return ranks |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:gather_votes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:candidates; 6, block; 6, 7; 6, 9; 6, 13; 6, 40; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:votes; 12, list:[]; 13, for_statement; 13, 14; 13, 15; 13, 23; 14, identifier:a; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:get_agents; 19, argument_list; 19, 20; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:addr; 22, False; 23, block; 23, 24; 23, 33; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:vote; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:a; 30, identifier:vote; 31, argument_list; 31, 32; 32, identifier:candidates; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:votes; 37, identifier:append; 38, argument_list; 38, 39; 39, identifier:vote; 40, return_statement; 40, 41; 41, identifier:votes | def gather_votes(self, candidates):
"""Gather votes for the given candidates from the agents in the
environment.
Returned votes are anonymous, i.e. they cannot be tracked to any
individual agent afterwards.
:returns:
A list of votes. Each vote is a list of ``(artifact, preference)``
-tuples sorted in a preference order of a single agent.
"""
votes = []
for a in self.get_agents(addr=False):
vote = a.vote(candidates)
votes.append(vote)
return votes |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:install_dependencies; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:feature; 6, None; 7, block; 7, 8; 7, 10; 7, 13; 7, 21; 7, 31; 7, 51; 7, 52; 7, 109; 7, 110; 7, 120; 7, 132; 7, 133; 7, 164; 7, 173; 7, 181; 7, 196; 7, 197; 7, 213; 7, 356; 8, expression_statement; 8, 9; 9, comment; 10, import_statement; 10, 11; 11, dotted_name; 11, 12; 12, identifier:subprocess; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:echo; 16, argument_list; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:green; 19, argument_list; 19, 20; 20, string:'\nInstall dependencies:'; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:echo; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:green; 27, argument_list; 27, 28; 28, binary_operator:*; 28, 29; 28, 30; 29, string:'-'; 30, integer:40; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:req_path; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:os; 38, identifier:path; 39, identifier:realpath; 40, argument_list; 40, 41; 41, binary_operator:+; 41, 42; 41, 50; 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:dirname; 48, argument_list; 48, 49; 49, identifier:__file__; 50, string:'/../_requirements'; 51, comment; 52, if_statement; 52, 53; 52, 55; 53, not_operator; 53, 54; 54, identifier:feature; 55, block; 55, 56; 55, 64; 55, 104; 55, 108; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:echo; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:yellow; 62, argument_list; 62, 63; 63, string:'Please specify a feature to install. \n'; 64, for_statement; 64, 65; 64, 68; 64, 77; 65, pattern_list; 65, 66; 65, 67; 66, identifier:index; 67, identifier:item; 68, call; 68, 69; 68, 70; 69, identifier:enumerate; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:os; 74, identifier:listdir; 75, argument_list; 75, 76; 76, identifier:req_path; 77, block; 77, 78; 77, 88; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:item; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:item; 84, identifier:replace; 85, argument_list; 85, 86; 85, 87; 86, string:'.txt'; 87, string:''; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:echo; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:green; 94, argument_list; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, string:'{}. {}'; 98, identifier:format; 99, argument_list; 99, 100; 99, 103; 100, binary_operator:+; 100, 101; 100, 102; 101, identifier:index; 102, integer:1; 103, identifier:item; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:echo; 107, argument_list; 108, return_statement; 109, comment; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:feature_file; 113, binary_operator:+; 113, 114; 113, 119; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:feature; 117, identifier:lower; 118, argument_list; 119, string:'.txt'; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:feature_reqs; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:os; 127, identifier:path; 128, identifier:join; 129, argument_list; 129, 130; 129, 131; 130, identifier:req_path; 131, identifier:feature_file; 132, comment; 133, if_statement; 133, 134; 133, 143; 134, not_operator; 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:isfile; 141, argument_list; 141, 142; 142, identifier:feature_reqs; 143, block; 143, 144; 143, 148; 143, 163; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:msg; 147, string:'Unable to locate feature requirements file [{}]'; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 151; 150, identifier:echo; 151, argument_list; 151, 152; 152, binary_operator:+; 152, 153; 152, 162; 153, call; 153, 154; 153, 155; 154, identifier:red; 155, argument_list; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:msg; 159, identifier:format; 160, argument_list; 160, 161; 161, identifier:feature_file; 162, string:'\n'; 163, return_statement; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:msg; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, string:'Now installing dependencies for "{}" feature...'; 170, identifier:format; 171, argument_list; 171, 172; 172, identifier:feature; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:echo; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:yellow; 179, argument_list; 179, 180; 180, identifier:msg; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:subprocess; 185, identifier:check_call; 186, argument_list; 186, 187; 187, list:[
sys.executable, '-m', 'pip', 'install', '-r', feature_reqs]; 187, 188; 187, 191; 187, 192; 187, 193; 187, 194; 187, 195; 188, attribute; 188, 189; 188, 190; 189, identifier:sys; 190, identifier:executable; 191, string:'-m'; 192, string:'pip'; 193, string:'install'; 194, string:'-r'; 195, identifier:feature_reqs; 196, comment; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:reqs; 200, call; 200, 201; 200, 206; 201, attribute; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:os; 204, identifier:path; 205, identifier:join; 206, argument_list; 206, 207; 206, 212; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:os; 210, identifier:getcwd; 211, argument_list; 212, string:'requirements.txt'; 213, if_statement; 213, 214; 213, 222; 214, call; 214, 215; 214, 220; 215, attribute; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:os; 218, identifier:path; 219, identifier:exists; 220, argument_list; 220, 221; 221, identifier:reqs; 222, block; 222, 223; 222, 259; 222, 264; 222, 337; 223, with_statement; 223, 224; 223, 233; 224, with_clause; 224, 225; 225, with_item; 225, 226; 226, as_pattern; 226, 227; 226, 231; 227, call; 227, 228; 227, 229; 228, identifier:open; 229, argument_list; 229, 230; 230, identifier:reqs; 231, as_pattern_target; 231, 232; 232, identifier:file; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:existing; 237, list_comprehension; 237, 238; 237, 250; 237, 257; 238, subscript; 238, 239; 238, 249; 239, call; 239, 240; 239, 247; 240, attribute; 240, 241; 240, 246; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:x; 244, identifier:strip; 245, argument_list; 246, identifier:split; 247, argument_list; 247, 248; 248, string:'=='; 249, integer:0; 250, for_in_clause; 250, 251; 250, 252; 251, identifier:x; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:file; 255, identifier:readlines; 256, argument_list; 257, if_clause; 257, 258; 258, identifier:x; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:lines; 262, list:['\n']; 262, 263; 263, string:'\n'; 264, with_statement; 264, 265; 264, 274; 265, with_clause; 265, 266; 266, with_item; 266, 267; 267, as_pattern; 267, 268; 267, 272; 268, call; 268, 269; 268, 270; 269, identifier:open; 270, argument_list; 270, 271; 271, identifier:feature_reqs; 272, as_pattern_target; 272, 273; 273, identifier:file; 274, block; 274, 275; 274, 283; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:incoming; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:file; 281, identifier:readlines; 282, argument_list; 283, for_statement; 283, 284; 283, 285; 283, 286; 284, identifier:line; 285, identifier:incoming; 286, block; 286, 287; 286, 310; 286, 325; 287, if_statement; 287, 288; 287, 301; 288, boolean_operator:or; 288, 289; 288, 295; 289, not_operator; 289, 290; 290, parenthesized_expression; 290, 291; 291, call; 291, 292; 291, 293; 292, identifier:len; 293, argument_list; 293, 294; 294, identifier:line; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:line; 298, identifier:startswith; 299, argument_list; 299, 300; 300, string:'#'; 301, block; 301, 302; 301, 309; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:lines; 306, identifier:append; 307, argument_list; 307, 308; 308, identifier:line; 309, continue_statement; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:package; 313, subscript; 313, 314; 313, 324; 314, call; 314, 315; 314, 322; 315, attribute; 315, 316; 315, 321; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:line; 319, identifier:strip; 320, argument_list; 321, identifier:split; 322, argument_list; 322, 323; 323, string:'=='; 324, integer:0; 325, if_statement; 325, 326; 325, 329; 326, comparison_operator:not; 326, 327; 326, 328; 327, identifier:package; 328, identifier:existing; 329, block; 329, 330; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:lines; 334, identifier:append; 335, argument_list; 335, 336; 336, identifier:line; 337, with_statement; 337, 338; 337, 348; 338, with_clause; 338, 339; 339, with_item; 339, 340; 340, as_pattern; 340, 341; 340, 346; 341, call; 341, 342; 341, 343; 342, identifier:open; 343, argument_list; 343, 344; 343, 345; 344, identifier:reqs; 345, string:'a'; 346, as_pattern_target; 346, 347; 347, identifier:file; 348, block; 348, 349; 349, expression_statement; 349, 350; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:file; 353, identifier:writelines; 354, argument_list; 354, 355; 355, identifier:lines; 356, expression_statement; 356, 357; 357, call; 357, 358; 357, 359; 358, identifier:echo; 359, argument_list; 359, 360; 360, call; 360, 361; 360, 362; 361, identifier:green; 362, argument_list; 362, 363; 363, string:'DONE\n' | def install_dependencies(feature=None):
""" Install dependencies for a feature """
import subprocess
echo(green('\nInstall dependencies:'))
echo(green('-' * 40))
req_path = os.path.realpath(os.path.dirname(__file__) + '/../_requirements')
# list all features if no feature name
if not feature:
echo(yellow('Please specify a feature to install. \n'))
for index, item in enumerate(os.listdir(req_path)):
item = item.replace('.txt', '')
echo(green('{}. {}'.format(index + 1, item)))
echo()
return
# install if got feature name
feature_file = feature.lower() + '.txt'
feature_reqs = os.path.join(req_path, feature_file)
# check existence
if not os.path.isfile(feature_reqs):
msg = 'Unable to locate feature requirements file [{}]'
echo(red(msg.format(feature_file)) + '\n')
return
msg = 'Now installing dependencies for "{}" feature...'.format(feature)
echo(yellow(msg))
subprocess.check_call([
sys.executable, '-m', 'pip', 'install', '-r', feature_reqs]
)
# update requirements file with dependencies
reqs = os.path.join(os.getcwd(), 'requirements.txt')
if os.path.exists(reqs):
with open(reqs) as file:
existing = [x.strip().split('==')[0] for x in file.readlines() if x]
lines = ['\n']
with open(feature_reqs) as file:
incoming = file.readlines()
for line in incoming:
if not(len(line)) or line.startswith('#'):
lines.append(line)
continue
package = line.strip().split('==')[0]
if package not in existing:
lines.append(line)
with open(reqs, 'a') as file:
file.writelines(lines)
echo(green('DONE\n')) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:resolve_handler; 3, parameters; 3, 4; 3, 5; 4, identifier:request; 5, identifier:view_handlers; 6, block; 6, 7; 6, 9; 6, 13; 6, 53; 6, 60; 6, 66; 6, 72; 6, 138; 6, 144; 6, 150; 6, 179; 6, 202; 6, 208; 6, 225; 6, 236; 6, 253; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:view; 12, None; 13, if_statement; 13, 14; 13, 17; 13, 18; 14, attribute; 14, 15; 14, 16; 15, identifier:request; 16, identifier:_context; 17, comment; 18, block; 18, 19; 18, 32; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:route_name; 22, attribute; 22, 23; 22, 31; 23, attribute; 23, 24; 23, 30; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:request; 27, identifier:_context; 28, unary_operator:-; 28, 29; 29, integer:1; 30, identifier:route; 31, identifier:name; 32, if_statement; 32, 33; 32, 38; 33, boolean_operator:and; 33, 34; 33, 35; 34, identifier:route_name; 35, comparison_operator:in; 35, 36; 35, 37; 36, identifier:VIEW_SEPARATOR; 37, identifier:route_name; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:view; 42, boolean_operator:or; 42, 43; 42, 52; 43, subscript; 43, 44; 43, 51; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:route_name; 47, identifier:split; 48, argument_list; 48, 49; 48, 50; 49, identifier:VIEW_SEPARATOR; 50, integer:1; 51, integer:1; 52, None; 53, if_statement; 53, 54; 53, 57; 54, comparison_operator:not; 54, 55; 54, 56; 55, identifier:view; 56, identifier:view_handlers; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, identifier:NotFound; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:method_handlers; 63, subscript; 63, 64; 63, 65; 64, identifier:view_handlers; 65, identifier:view; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:verb; 69, attribute; 69, 70; 69, 71; 70, identifier:request; 71, identifier:method; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:not; 73, 74; 73, 75; 74, identifier:verb; 75, identifier:method_handlers; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 85; 77, 90; 78, boolean_operator:and; 78, 79; 78, 82; 79, comparison_operator:==; 79, 80; 79, 81; 80, identifier:verb; 81, string:'HEAD'; 82, comparison_operator:in; 82, 83; 82, 84; 83, string:'GET'; 84, identifier:method_handlers; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:verb; 89, string:'GET'; 90, else_clause; 90, 91; 91, block; 91, 92; 91, 103; 91, 119; 91, 131; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:allowed_methods; 95, call; 95, 96; 95, 97; 96, identifier:set; 97, argument_list; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:method_handlers; 101, identifier:keys; 102, argument_list; 103, if_statement; 103, 104; 103, 111; 104, boolean_operator:and; 104, 105; 104, 108; 105, comparison_operator:not; 105, 106; 105, 107; 106, string:'HEAD'; 107, identifier:allowed_methods; 108, comparison_operator:in; 108, 109; 108, 110; 109, string:'GET'; 110, identifier:allowed_methods; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:allowed_methods; 116, identifier:add; 117, argument_list; 117, 118; 118, string:'HEAD'; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:allow; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, string:', '; 125, identifier:join; 126, argument_list; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:sorted; 129, argument_list; 129, 130; 130, identifier:allowed_methods; 131, raise_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:MethodNotAllowed; 134, argument_list; 134, 135; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:allow; 137, identifier:allow; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:handlers; 141, subscript; 141, 142; 141, 143; 142, identifier:method_handlers; 143, identifier:verb; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:vary; 147, call; 147, 148; 147, 149; 148, identifier:set; 149, argument_list; 150, if_statement; 150, 151; 150, 171; 151, comparison_operator:>; 151, 152; 151, 170; 152, call; 152, 153; 152, 154; 153, identifier:len; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:set; 157, generator_expression; 157, 158; 157, 161; 157, 164; 158, attribute; 158, 159; 158, 160; 159, identifier:h; 160, identifier:provides; 161, for_in_clause; 161, 162; 161, 163; 162, identifier:h; 163, identifier:handlers; 164, if_clause; 164, 165; 165, comparison_operator:is; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:h; 168, identifier:provides; 169, None; 170, integer:1; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:vary; 176, identifier:add; 177, argument_list; 177, 178; 178, string:'Accept'; 179, if_statement; 179, 180; 179, 194; 180, comparison_operator:>; 180, 181; 180, 193; 181, call; 181, 182; 181, 183; 182, identifier:len; 183, argument_list; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:set; 186, generator_expression; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:h; 189, identifier:accepts; 190, for_in_clause; 190, 191; 190, 192; 191, identifier:h; 192, identifier:handlers; 193, integer:1; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:vary; 199, identifier:add; 200, argument_list; 200, 201; 201, string:'Content-Type'; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:content_type; 205, attribute; 205, 206; 205, 207; 206, identifier:request; 207, identifier:content_type; 208, if_statement; 208, 209; 208, 210; 209, identifier:content_type; 210, block; 210, 211; 210, 219; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:handlers; 214, call; 214, 215; 214, 216; 215, identifier:negotiate_content_type; 216, argument_list; 216, 217; 216, 218; 217, identifier:content_type; 218, identifier:handlers; 219, if_statement; 219, 220; 219, 222; 220, not_operator; 220, 221; 221, identifier:handlers; 222, block; 222, 223; 223, raise_statement; 223, 224; 224, identifier:UnsupportedMediaType; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:accept; 228, call; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:request; 232, identifier:headers; 233, identifier:get; 234, argument_list; 234, 235; 235, string:'Accept'; 236, if_statement; 236, 237; 236, 238; 237, identifier:accept; 238, block; 238, 239; 238, 247; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:handlers; 242, call; 242, 243; 242, 244; 243, identifier:negotiate_accept; 244, argument_list; 244, 245; 244, 246; 245, identifier:accept; 246, identifier:handlers; 247, if_statement; 247, 248; 247, 250; 248, not_operator; 248, 249; 249, identifier:handlers; 250, block; 250, 251; 251, raise_statement; 251, 252; 252, identifier:NotAcceptable; 253, return_statement; 253, 254; 254, expression_list; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:handlers; 257, integer:0; 258, identifier:vary | def resolve_handler(request, view_handlers):
"""Select a suitable handler to handle the request.
Returns a (handler, vary) tuple, where handler is a handler_metadata tuple
and vary is a set containing header names that were used during content
negotiation and that should be included in the 'Vary' header of the
outgoing response.
When no suitable handler exists, raises NotFound, MethodNotAllowed,
UnsupportedMediaType or NotAcceptable.
"""
view = None
if request._context: # Allow context to be missing for easier testing
route_name = request._context[-1].route.name
if route_name and VIEW_SEPARATOR in route_name:
view = route_name.split(VIEW_SEPARATOR, 1)[1] or None
if view not in view_handlers:
raise NotFound
method_handlers = view_handlers[view]
verb = request.method
if verb not in method_handlers:
if verb == 'HEAD' and 'GET' in method_handlers:
verb = 'GET'
else:
allowed_methods = set(method_handlers.keys())
if 'HEAD' not in allowed_methods and 'GET' in allowed_methods:
allowed_methods.add('HEAD')
allow = ', '.join(sorted(allowed_methods))
raise MethodNotAllowed(allow=allow)
handlers = method_handlers[verb]
vary = set()
if len(set(h.provides for h in handlers if h.provides is not None)) > 1:
vary.add('Accept')
if len(set(h.accepts for h in handlers)) > 1:
vary.add('Content-Type')
content_type = request.content_type
if content_type:
handlers = negotiate_content_type(content_type, handlers)
if not handlers:
raise UnsupportedMediaType
accept = request.headers.get('Accept')
if accept:
handlers = negotiate_accept(accept, handlers)
if not handlers:
raise NotAcceptable
return handlers[0], vary |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:url_for; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:args; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kw; 8, block; 8, 9; 8, 11; 8, 12; 8, 33; 8, 43; 8, 53; 8, 65; 8, 112; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 18; 14, pattern_list; 14, 15; 14, 16; 14, 17; 15, identifier:self; 16, identifier:target; 17, identifier:args; 18, expression_list; 18, 19; 18, 22; 18, 25; 19, subscript; 19, 20; 19, 21; 20, identifier:args; 21, integer:0; 22, subscript; 22, 23; 22, 24; 23, identifier:args; 24, integer:1; 25, call; 25, 26; 25, 27; 26, identifier:list; 27, argument_list; 27, 28; 28, subscript; 28, 29; 28, 30; 29, identifier:args; 30, slice; 30, 31; 30, 32; 31, integer:2; 32, colon; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:query; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:kw; 39, identifier:pop; 40, argument_list; 40, 41; 40, 42; 41, string:'_query'; 42, None; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:relative; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:kw; 49, identifier:pop; 50, argument_list; 50, 51; 50, 52; 51, string:'_relative'; 52, False; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:url; 56, call; 56, 57; 56, 58; 57, identifier:build_url; 58, argument_list; 58, 59; 58, 62; 58, 63; 58, 64; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:_context; 62, identifier:target; 63, identifier:args; 64, identifier:kw; 65, if_statement; 65, 66; 65, 67; 66, identifier:query; 67, block; 67, 68; 67, 86; 67, 95; 67, 104; 68, if_statement; 68, 69; 68, 74; 69, call; 69, 70; 69, 71; 70, identifier:isinstance; 71, argument_list; 71, 72; 71, 73; 72, identifier:query; 73, identifier:dict; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:query; 78, call; 78, 79; 78, 80; 79, identifier:sorted; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:query; 84, identifier:items; 85, argument_list; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:query_part; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:urllib; 92, identifier:urlencode; 93, argument_list; 93, 94; 94, identifier:query; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:query_sep; 98, conditional_expression:if; 98, 99; 98, 100; 98, 103; 99, string:'&'; 100, comparison_operator:in; 100, 101; 100, 102; 101, string:'?'; 102, identifier:url; 103, string:'?'; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:url; 107, binary_operator:+; 107, 108; 107, 111; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:url; 110, identifier:query_sep; 111, identifier:query_part; 112, if_statement; 112, 113; 112, 114; 112, 117; 113, identifier:relative; 114, block; 114, 115; 115, return_statement; 115, 116; 116, identifier:url; 117, else_clause; 117, 118; 118, block; 118, 119; 119, return_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:urlparse; 123, identifier:urljoin; 124, argument_list; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:application_uri; 128, identifier:url | def url_for(*args, **kw):
"""Build the URL for a target route.
The target is the first positional argument, and can be any valid
target for `Mapper.path`, which will be looked up on the current
mapper object and used to build the URL for that route.
Additionally, it can be one of:
'.'
: Builds the URL for the current route.
'/'
: Builds the URL for the root (top-most) mapper object.
'/a', '/a:b', etc.
: Builds the URL for a named route relative to the root mapper.
'.a', '..a', '..a:b', etc.
: Builds a URL for a named route relative to the current mapper.
Each additional leading '.' after the first one starts one
level higher in the hierarchy of nested mappers (i.e. '.a' is
equivalent to 'a').
Special keyword arguments:
`_query`
: Append a query string to the URL (dict or list of tuples)
`_relative`
: When True, build a relative URL (default: False)
All other keyword arguments are treated as parameters for the URL
template.
"""
# Allow passing 'self' as named parameter
self, target, args = args[0], args[1], list(args[2:])
query = kw.pop('_query', None)
relative = kw.pop('_relative', False)
url = build_url(self._context, target, args, kw)
if query:
if isinstance(query, dict):
query = sorted(query.items())
query_part = urllib.urlencode(query)
query_sep = '&' if '?' in url else '?'
url = url + query_sep + query_part
if relative:
return url
else:
return urlparse.urljoin(self.application_uri, url) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 35; 2, function_name:execute; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 4, identifier:command; 5, default_parameter; 5, 6; 5, 7; 6, identifier:return_output; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:log_file; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:log_settings; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:error_logfile; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:timeout; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:line_function; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:poll_timing; 25, float:0.01; 26, default_parameter; 26, 27; 26, 28; 27, identifier:logger; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:working_folder; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:env; 34, None; 35, block; 35, 36; 35, 38; 35, 42; 35, 68; 35, 130; 35, 143; 35, 151; 35, 168; 35, 175; 35, 181; 35, 189; 35, 199; 35, 207; 35, 224; 35, 232; 35, 236; 35, 245; 35, 256; 35, 257; 35, 258; 35, 259; 35, 260; 35, 278; 35, 305; 35, 426; 35, 437; 35, 447; 35, 448; 35, 461; 35, 503; 36, expression_statement; 36, 37; 37, comment; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:tmp_log; 41, False; 42, if_statement; 42, 43; 42, 44; 42, 54; 43, identifier:log_settings; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:log_folder; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:log_settings; 51, identifier:get; 52, argument_list; 52, 53; 53, string:'LOG_FOLDER'; 54, else_clause; 54, 55; 55, block; 55, 56; 55, 60; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:tmp_log; 59, True; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:log_folder; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:tempfile; 66, identifier:mkdtemp; 67, argument_list; 68, if_statement; 68, 69; 68, 71; 69, not_operator; 69, 70; 70, identifier:log_file; 71, block; 71, 72; 71, 91; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:log_file; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:os; 79, identifier:path; 80, identifier:join; 81, argument_list; 81, 82; 81, 83; 81, 84; 82, identifier:log_folder; 83, string:"commands"; 84, binary_operator:%; 84, 85; 84, 86; 85, string:"execute-command-logfile-%s.log"; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:UUID; 89, identifier:uuid4; 90, argument_list; 91, try_statement; 91, 92; 91, 127; 92, block; 92, 93; 93, if_statement; 93, 94; 93, 111; 94, not_operator; 94, 95; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:os; 99, identifier:path; 100, identifier:isdir; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:os; 106, identifier:path; 107, identifier:join; 108, argument_list; 108, 109; 108, 110; 109, identifier:log_folder; 110, string:"commands"; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:os; 116, identifier:makedirs; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:os; 122, identifier:path; 123, identifier:join; 124, argument_list; 124, 125; 124, 126; 125, identifier:log_folder; 126, string:"commands"; 127, except_clause; 127, 128; 128, block; 128, 129; 129, pass_statement; 130, if_statement; 130, 131; 130, 133; 131, not_operator; 131, 132; 132, identifier:logger; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:logger; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:logging; 140, identifier:getLogger; 141, argument_list; 141, 142; 142, string:'command_execute'; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:logfile_writer; 146, call; 146, 147; 146, 148; 147, identifier:open; 148, argument_list; 148, 149; 148, 150; 149, identifier:log_file; 150, string:'a'; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:header; 154, binary_operator:%; 154, 155; 154, 156; 155, string:"%s - Executing command (timeout=%s) :\n\t%s\n\n\n"; 156, tuple; 156, 157; 156, 166; 156, 167; 157, call; 157, 158; 157, 165; 158, attribute; 158, 159; 158, 164; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:datetime; 162, identifier:now; 163, argument_list; 164, identifier:isoformat; 165, argument_list; 166, identifier:timeout; 167, identifier:command; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:logfile_writer; 172, identifier:write; 173, argument_list; 173, 174; 174, identifier:header; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:logfile_writer; 179, identifier:flush; 180, argument_list; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:logfile_reader; 184, call; 184, 185; 184, 186; 185, identifier:open; 186, argument_list; 186, 187; 186, 188; 187, identifier:log_file; 188, string:'rb'; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:logfile_reader; 193, identifier:seek; 194, argument_list; 194, 195; 194, 196; 195, integer:0; 196, attribute; 196, 197; 196, 198; 197, identifier:os; 198, identifier:SEEK_END; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:logfile_start_position; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:logfile_reader; 205, identifier:tell; 206, argument_list; 207, if_statement; 207, 208; 207, 209; 207, 218; 208, identifier:error_logfile; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:err_logfile_writer; 213, call; 213, 214; 213, 215; 214, identifier:open; 215, argument_list; 215, 216; 215, 217; 216, identifier:error_logfile; 217, string:'a'; 218, else_clause; 218, 219; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:err_logfile_writer; 223, identifier:logfile_writer; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:start; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:datetime; 230, identifier:now; 231, argument_list; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:timeout_string; 235, string:""; 236, if_statement; 236, 237; 236, 238; 237, identifier:timeout; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:timeout_string; 242, binary_operator:%; 242, 243; 242, 244; 243, string:"(timeout=%s)"; 244, identifier:timeout; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:logger; 249, identifier:info; 250, argument_list; 250, 251; 251, binary_operator:%; 251, 252; 251, 253; 252, string:u"Executing command %s :\n\t\t%s"; 253, tuple; 253, 254; 253, 255; 254, identifier:timeout_string; 255, identifier:command; 256, comment; 257, comment; 258, comment; 259, comment; 260, if_statement; 260, 261; 260, 266; 261, comparison_operator:!=; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:sys; 264, identifier:platform; 265, string:'win32'; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:command; 270, binary_operator:%; 270, 271; 270, 272; 271, string:u"exec %s"; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:text_utils; 275, identifier:uni; 276, argument_list; 276, 277; 277, identifier:command; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:process; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:subprocess; 284, identifier:Popen; 285, argument_list; 285, 286; 285, 287; 285, 290; 285, 293; 285, 296; 285, 299; 285, 302; 286, identifier:command; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:stdout; 289, identifier:logfile_writer; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:stderr; 292, identifier:err_logfile_writer; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:bufsize; 295, integer:1; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:shell; 298, True; 299, keyword_argument; 299, 300; 299, 301; 300, identifier:cwd; 301, identifier:working_folder; 302, keyword_argument; 302, 303; 302, 304; 303, identifier:env; 304, identifier:env; 305, while_statement; 305, 306; 305, 313; 305, 314; 306, comparison_operator:==; 306, 307; 306, 312; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:process; 310, identifier:poll; 311, argument_list; 312, None; 313, comment; 314, block; 314, 315; 314, 322; 314, 323; 314, 377; 314, 378; 314, 379; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:time; 319, identifier:sleep; 320, argument_list; 320, 321; 321, identifier:poll_timing; 322, comment; 323, if_statement; 323, 324; 323, 327; 324, comparison_operator:!=; 324, 325; 324, 326; 325, identifier:timeout; 326, None; 327, block; 327, 328; 327, 336; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:now; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:datetime; 334, identifier:now; 335, argument_list; 336, if_statement; 336, 337; 336, 345; 336, 346; 337, comparison_operator:>; 337, 338; 337, 344; 338, attribute; 338, 339; 338, 343; 339, parenthesized_expression; 339, 340; 340, binary_operator:-; 340, 341; 340, 342; 341, identifier:now; 342, identifier:start; 343, identifier:seconds; 344, identifier:timeout; 345, comment; 346, block; 346, 347; 346, 359; 346, 370; 347, expression_statement; 347, 348; 348, call; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:os; 351, identifier:kill; 352, argument_list; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:process; 355, identifier:pid; 356, attribute; 356, 357; 356, 358; 357, identifier:signal; 358, identifier:SIGKILL; 359, expression_statement; 359, 360; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:os; 363, identifier:waitpid; 364, argument_list; 364, 365; 364, 367; 365, unary_operator:-; 365, 366; 366, integer:1; 367, attribute; 367, 368; 367, 369; 368, identifier:os; 369, identifier:WNOHANG; 370, raise_statement; 370, 371; 371, call; 371, 372; 371, 373; 372, identifier:Exception; 373, argument_list; 373, 374; 374, binary_operator:%; 374, 375; 374, 376; 375, string:"Command execution timed out (took more than %s seconds...)"; 376, identifier:timeout; 377, comment; 378, comment; 379, if_statement; 379, 380; 379, 381; 380, identifier:line_function; 381, block; 381, 382; 381, 399; 382, expression_statement; 382, 383; 383, assignment; 383, 384; 383, 385; 384, identifier:o; 385, call; 385, 386; 385, 398; 386, attribute; 386, 387; 386, 397; 387, call; 387, 388; 387, 391; 388, attribute; 388, 389; 388, 390; 389, identifier:text_utils; 390, identifier:uni; 391, argument_list; 391, 392; 392, call; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:logfile_reader; 395, identifier:readline; 396, argument_list; 397, identifier:rstrip; 398, argument_list; 399, while_statement; 399, 400; 399, 403; 400, comparison_operator:!=; 400, 401; 400, 402; 401, identifier:o; 402, string:''; 403, block; 403, 404; 403, 409; 404, expression_statement; 404, 405; 405, call; 405, 406; 405, 407; 406, identifier:line_function; 407, argument_list; 407, 408; 408, identifier:o; 409, expression_statement; 409, 410; 410, assignment; 410, 411; 410, 412; 411, identifier:o; 412, call; 412, 413; 412, 425; 413, attribute; 413, 414; 413, 424; 414, call; 414, 415; 414, 418; 415, attribute; 415, 416; 415, 417; 416, identifier:text_utils; 417, identifier:uni; 418, argument_list; 418, 419; 419, call; 419, 420; 419, 423; 420, attribute; 420, 421; 420, 422; 421, identifier:logfile_reader; 422, identifier:readline; 423, argument_list; 424, identifier:rstrip; 425, argument_list; 426, if_statement; 426, 427; 426, 429; 426, 430; 427, not_operator; 427, 428; 428, identifier:return_output; 429, comment; 430, block; 430, 431; 431, return_statement; 431, 432; 432, call; 432, 433; 432, 436; 433, attribute; 433, 434; 433, 435; 434, identifier:process; 435, identifier:wait; 436, argument_list; 437, expression_statement; 437, 438; 438, call; 438, 439; 438, 442; 439, attribute; 439, 440; 439, 441; 440, identifier:logfile_reader; 441, identifier:seek; 442, argument_list; 442, 443; 442, 444; 443, identifier:logfile_start_position; 444, attribute; 444, 445; 444, 446; 445, identifier:os; 446, identifier:SEEK_SET; 447, comment; 448, expression_statement; 448, 449; 449, assignment; 449, 450; 449, 451; 450, identifier:res; 451, call; 451, 452; 451, 455; 452, attribute; 452, 453; 452, 454; 453, identifier:text_utils; 454, identifier:uni; 455, argument_list; 455, 456; 456, call; 456, 457; 456, 460; 457, attribute; 457, 458; 457, 459; 458, identifier:logfile_reader; 459, identifier:read; 460, argument_list; 461, try_statement; 461, 462; 461, 494; 462, block; 462, 463; 462, 469; 462, 475; 462, 481; 463, expression_statement; 463, 464; 464, call; 464, 465; 464, 468; 465, attribute; 465, 466; 465, 467; 466, identifier:logfile_reader; 467, identifier:close; 468, argument_list; 469, expression_statement; 469, 470; 470, call; 470, 471; 470, 474; 471, attribute; 471, 472; 471, 473; 472, identifier:logfile_writer; 473, identifier:close; 474, argument_list; 475, expression_statement; 475, 476; 476, call; 476, 477; 476, 480; 477, attribute; 477, 478; 477, 479; 478, identifier:err_logfile_writer; 479, identifier:close; 480, argument_list; 481, if_statement; 481, 482; 481, 483; 482, identifier:tmp_log; 483, block; 483, 484; 484, expression_statement; 484, 485; 485, call; 485, 486; 485, 489; 486, attribute; 486, 487; 486, 488; 487, identifier:shutil; 488, identifier:rmtree; 489, argument_list; 489, 490; 489, 491; 490, identifier:log_folder; 491, keyword_argument; 491, 492; 491, 493; 492, identifier:ignore_errors; 493, True; 494, except_clause; 494, 495; 495, block; 495, 496; 496, expression_statement; 496, 497; 497, call; 497, 498; 497, 501; 498, attribute; 498, 499; 498, 500; 499, identifier:logger; 500, identifier:exception; 501, argument_list; 501, 502; 502, string:"Error while cleaning after tbx.execute() call."; 503, return_statement; 503, 504; 504, identifier:res | def execute(command, return_output=True, log_file=None, log_settings=None, error_logfile=None, timeout=None, line_function=None, poll_timing = 0.01, logger=None, working_folder=None, env=None):
"""
Execute a program and logs standard output into a file.
:param return_output: returns the STDOUT value if True or returns the return code
:param logfile: path where log file should be written ( displayed on STDOUT if not set)
:param error_logfile: path where error log file should be written ( displayed on STDERR if not set)
:param timeout: if set, it will kill the subprocess created when "timeout" seconds is reached. It will then raise an Exception.
:param line_function: set it to a "function pointer" for the function to be called each time a new line is written (line passed as a parameter).
:param poll_timing: wait time between timeout checks and std output check.
:returns: Standard output of the command or if return_output=False, it will give the "return code" of the command
"""
tmp_log = False
if log_settings:
log_folder = log_settings.get('LOG_FOLDER')
else:
tmp_log = True
log_folder = tempfile.mkdtemp()
if not log_file:
log_file = os.path.join(log_folder, "commands", "execute-command-logfile-%s.log" % UUID.uuid4())
try:
if not os.path.isdir(os.path.join(log_folder, "commands")):
os.makedirs(os.path.join(log_folder, "commands"))
except:
pass
if not logger:
logger = logging.getLogger('command_execute')
logfile_writer = open(log_file, 'a')
header = "%s - Executing command (timeout=%s) :\n\t%s\n\n\n" % (datetime.now().isoformat(), timeout, command)
logfile_writer.write(header)
logfile_writer.flush()
logfile_reader = open(log_file, 'rb')
logfile_reader.seek(0, os.SEEK_END)
logfile_start_position = logfile_reader.tell()
if error_logfile:
err_logfile_writer = open(error_logfile, 'a')
else:
err_logfile_writer = logfile_writer
start = datetime.now()
timeout_string = ""
if timeout:
timeout_string = "(timeout=%s)" % timeout
logger.info(u"Executing command %s :\n\t\t%s" % (timeout_string, command) )
# We use "exec <command>" as Popen launches a shell, that runs the command.
# It will transform the child process "sh" into the "command exectable" because of the "exec".
# Said more accuratly, it won't fork to create launch the command in a sub sub process.
# Therefore, when you kill the child process, you kill the "command" process and not the unecessary "sh" parent process.
if sys.platform != 'win32':
command = u"exec %s" % text_utils.uni(command)
process = subprocess.Popen(command, stdout=logfile_writer, stderr=err_logfile_writer, bufsize=1, shell=True, cwd=working_folder, env=env)
while process.poll() == None:
# In order to avoid unecessary cpu usage, we wait for "poll_timing" seconds ( default: 0.1 sec )
time.sleep(poll_timing)
# Timeout check
if timeout != None:
now = datetime.now()
if (now - start).seconds> timeout:
#process.terminate() ??
os.kill(process.pid, signal.SIGKILL)
os.waitpid(-1, os.WNOHANG)
raise Exception("Command execution timed out (took more than %s seconds...)" % timeout)
# Line function call:
# => if line_function is defined, we call it on each new line of the file.
if line_function:
o = text_utils.uni(logfile_reader.readline()).rstrip()
while o != '':
line_function(o)
o = text_utils.uni(logfile_reader.readline()).rstrip()
if not return_output:
# Return result code and ensure we have waited for the end of sub process
return process.wait()
logfile_reader.seek(logfile_start_position, os.SEEK_SET) #back to the beginning of the file
res = text_utils.uni(logfile_reader.read())
try:
logfile_reader.close()
logfile_writer.close()
err_logfile_writer.close()
if tmp_log:
shutil.rmtree(log_folder, ignore_errors=True)
except:
logger.exception("Error while cleaning after tbx.execute() call.")
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:add_backbone_atoms_linearly_from_loop_filepaths; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:loop_json_filepath; 6, identifier:fasta_filepath; 7, identifier:residue_ids; 8, block; 8, 9; 8, 11; 8, 12; 8, 24; 8, 34; 8, 44; 8, 54; 8, 80; 8, 106; 8, 111; 8, 116; 8, 117; 8, 130; 8, 142; 8, 152; 8, 169; 8, 170; 8, 171; 8, 175; 8, 179; 8, 183; 8, 187; 8, 240; 8, 249; 8, 258; 8, 259; 8, 302; 9, expression_statement; 9, 10; 10, string:'''A utility wrapper around add_backbone_atoms_linearly. Adds backbone atoms in a straight line from the first to
the last residue of residue_ids.
loop_json_filepath is a path to a JSON file using the JSON format for Rosetta loops files. This file identifies
the insertion points of the sequence.
fasta_filepath is a path to a FASTA file with one sequence. This sequence will be used as the sequence for
the inserted residues (between the start and stop residues defined in loop_json_filepath).
residue_ids is a list of PDB chain residues (columns 22-27 of ATOM lines in the PDB format). It is assumed that
they are sequential although the logic does not depend on that. This list should have the length length as the
sequence identified in the FASTA file.
'''; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:loop_def; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:json; 18, identifier:loads; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:read_file; 22, argument_list; 22, 23; 23, identifier:loop_json_filepath; 24, assert_statement; 24, 25; 25, parenthesized_expression; 25, 26; 26, comparison_operator:==; 26, 27; 26, 33; 27, call; 27, 28; 27, 29; 28, identifier:len; 29, argument_list; 29, 30; 30, subscript; 30, 31; 30, 32; 31, identifier:loop_def; 32, string:'LoopSet'; 33, integer:1; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:start_res; 37, subscript; 37, 38; 37, 43; 38, subscript; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:loop_def; 41, string:'LoopSet'; 42, integer:0; 43, string:'start'; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:end_res; 47, subscript; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:loop_def; 51, string:'LoopSet'; 52, integer:0; 53, string:'stop'; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:start_res; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:PDB; 60, identifier:ChainResidueID2String; 61, argument_list; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:start_res; 64, string:'chainID'; 65, call; 65, 66; 65, 79; 66, attribute; 66, 67; 66, 78; 67, parenthesized_expression; 67, 68; 68, binary_operator:+; 68, 69; 68, 75; 69, call; 69, 70; 69, 71; 70, identifier:str; 71, argument_list; 71, 72; 72, subscript; 72, 73; 72, 74; 73, identifier:start_res; 74, string:'resSeq'; 75, subscript; 75, 76; 75, 77; 76, identifier:start_res; 77, string:'iCode'; 78, identifier:strip; 79, argument_list; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:end_res; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:PDB; 86, identifier:ChainResidueID2String; 87, argument_list; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:end_res; 90, string:'chainID'; 91, call; 91, 92; 91, 105; 92, attribute; 92, 93; 92, 104; 93, parenthesized_expression; 93, 94; 94, binary_operator:+; 94, 95; 94, 101; 95, call; 95, 96; 95, 97; 96, identifier:str; 97, argument_list; 97, 98; 98, subscript; 98, 99; 98, 100; 99, identifier:end_res; 100, string:'resSeq'; 101, subscript; 101, 102; 101, 103; 102, identifier:end_res; 103, string:'iCode'; 104, identifier:strip; 105, argument_list; 106, assert_statement; 106, 107; 107, parenthesized_expression; 107, 108; 108, comparison_operator:in; 108, 109; 108, 110; 109, identifier:start_res; 110, identifier:residue_ids; 111, assert_statement; 111, 112; 112, parenthesized_expression; 112, 113; 113, comparison_operator:in; 113, 114; 113, 115; 114, identifier:end_res; 115, identifier:residue_ids; 116, comment; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:f; 120, call; 120, 121; 120, 122; 121, identifier:FASTA; 122, argument_list; 122, 123; 122, 127; 123, call; 123, 124; 123, 125; 124, identifier:read_file; 125, argument_list; 125, 126; 126, identifier:fasta_filepath; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:strict; 129, False; 130, assert_statement; 130, 131; 131, parenthesized_expression; 131, 132; 132, comparison_operator:==; 132, 133; 132, 141; 133, call; 133, 134; 133, 135; 134, identifier:len; 135, argument_list; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:f; 139, identifier:get_sequences; 140, argument_list; 141, integer:1; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:insertion_sequence; 145, subscript; 145, 146; 145, 151; 146, subscript; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:f; 149, identifier:sequences; 150, integer:0; 151, integer:2; 152, if_statement; 152, 153; 152, 163; 153, not_operator; 153, 154; 154, comparison_operator:==; 154, 155; 154, 159; 155, call; 155, 156; 155, 157; 156, identifier:len; 157, argument_list; 157, 158; 158, identifier:residue_ids; 159, call; 159, 160; 159, 161; 160, identifier:len; 161, argument_list; 161, 162; 162, identifier:insertion_sequence; 163, block; 163, 164; 164, raise_statement; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:Exception; 167, argument_list; 167, 168; 168, string:'The sequence in the FASTA file must have the same length as the list of residues.'; 169, comment; 170, comment; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:kept_residues; 174, list:[]; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:insertion_residue_map; 178, dictionary; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:in_section; 182, False; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:found_end; 186, False; 187, for_statement; 187, 188; 187, 189; 187, 196; 188, identifier:x; 189, call; 189, 190; 189, 191; 190, identifier:range; 191, argument_list; 191, 192; 192, call; 192, 193; 192, 194; 193, identifier:len; 194, argument_list; 194, 195; 195, identifier:residue_ids; 196, block; 196, 197; 196, 203; 196, 212; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:residue_id; 200, subscript; 200, 201; 200, 202; 201, identifier:residue_ids; 202, identifier:x; 203, if_statement; 203, 204; 203, 207; 204, comparison_operator:==; 204, 205; 204, 206; 205, identifier:residue_id; 206, identifier:start_res; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:in_section; 211, True; 212, if_statement; 212, 213; 212, 214; 213, identifier:in_section; 214, block; 214, 215; 214, 222; 214, 230; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:kept_residues; 219, identifier:append; 220, argument_list; 220, 221; 221, identifier:residue_id; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 227; 224, subscript; 224, 225; 224, 226; 225, identifier:insertion_residue_map; 226, identifier:residue_id; 227, subscript; 227, 228; 227, 229; 228, identifier:insertion_sequence; 229, identifier:x; 230, if_statement; 230, 231; 230, 234; 231, comparison_operator:==; 231, 232; 231, 233; 232, identifier:residue_id; 233, identifier:end_res; 234, block; 234, 235; 234, 239; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:found_end; 238, True; 239, break_statement; 240, if_statement; 240, 241; 240, 243; 241, not_operator; 241, 242; 242, identifier:kept_residues; 243, block; 243, 244; 244, raise_statement; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:Exception; 247, argument_list; 247, 248; 248, string:'The insertion sequence is empty (check the start and end residue ids).'; 249, if_statement; 249, 250; 249, 252; 250, not_operator; 250, 251; 251, identifier:found_end; 252, block; 252, 253; 253, raise_statement; 253, 254; 254, call; 254, 255; 254, 256; 255, identifier:Exception; 256, argument_list; 256, 257; 257, string:'The end residue was not encountered when iterating over the insertion sequence (check the start and end residue ids).'; 258, comment; 259, try_statement; 259, 260; 259, 293; 260, block; 260, 261; 260, 277; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:start_res; 264, subscript; 264, 265; 264, 272; 265, subscript; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:residues; 269, subscript; 269, 270; 269, 271; 270, identifier:start_res; 271, integer:0; 272, subscript; 272, 273; 272, 274; 273, identifier:start_res; 274, slice; 274, 275; 274, 276; 275, integer:1; 276, colon; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:end_res; 280, subscript; 280, 281; 280, 288; 281, subscript; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:residues; 285, subscript; 285, 286; 285, 287; 286, identifier:end_res; 287, integer:0; 288, subscript; 288, 289; 288, 290; 289, identifier:end_res; 290, slice; 290, 291; 290, 292; 291, integer:1; 292, colon; 293, except_clause; 293, 294; 293, 295; 293, 296; 294, identifier:Exception; 295, identifier:e; 296, block; 296, 297; 297, raise_statement; 297, 298; 298, call; 298, 299; 298, 300; 299, identifier:Exception; 300, argument_list; 300, 301; 301, string:'The start or end residue could not be found in the PDB file.'; 302, return_statement; 302, 303; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:add_backbone_atoms_linearly; 307, argument_list; 307, 308; 307, 309; 307, 310; 307, 311; 308, identifier:start_res; 309, identifier:end_res; 310, identifier:kept_residues; 311, identifier:insertion_residue_map | def add_backbone_atoms_linearly_from_loop_filepaths(self, loop_json_filepath, fasta_filepath, residue_ids):
'''A utility wrapper around add_backbone_atoms_linearly. Adds backbone atoms in a straight line from the first to
the last residue of residue_ids.
loop_json_filepath is a path to a JSON file using the JSON format for Rosetta loops files. This file identifies
the insertion points of the sequence.
fasta_filepath is a path to a FASTA file with one sequence. This sequence will be used as the sequence for
the inserted residues (between the start and stop residues defined in loop_json_filepath).
residue_ids is a list of PDB chain residues (columns 22-27 of ATOM lines in the PDB format). It is assumed that
they are sequential although the logic does not depend on that. This list should have the length length as the
sequence identified in the FASTA file.
'''
# Parse the loop file
loop_def = json.loads(read_file(loop_json_filepath))
assert(len(loop_def['LoopSet']) == 1)
start_res = loop_def['LoopSet'][0]['start']
end_res = loop_def['LoopSet'][0]['stop']
start_res = PDB.ChainResidueID2String(start_res['chainID'], (str(start_res['resSeq']) + start_res['iCode']).strip())
end_res = PDB.ChainResidueID2String(end_res['chainID'], (str(end_res['resSeq']) + end_res['iCode']).strip())
assert(start_res in residue_ids)
assert(end_res in residue_ids)
# Parse the FASTA file and extract the sequence
f = FASTA(read_file(fasta_filepath), strict = False)
assert(len(f.get_sequences()) == 1)
insertion_sequence = f.sequences[0][2]
if not len(residue_ids) == len(insertion_sequence):
raise Exception('The sequence in the FASTA file must have the same length as the list of residues.')
# Create the insertion sequence (a sub-sequence of the FASTA sequence)
# The post-condition is that the start and end residues are the first and last elements of kept_residues respectively
kept_residues = []
insertion_residue_map = {}
in_section = False
found_end = False
for x in range(len(residue_ids)):
residue_id = residue_ids[x]
if residue_id == start_res:
in_section = True
if in_section:
kept_residues.append(residue_id)
insertion_residue_map[residue_id] = insertion_sequence[x]
if residue_id == end_res:
found_end = True
break
if not kept_residues:
raise Exception('The insertion sequence is empty (check the start and end residue ids).')
if not found_end:
raise Exception('The end residue was not encountered when iterating over the insertion sequence (check the start and end residue ids).')
# Identify the start and end Residue objects
try:
start_res = self.residues[start_res[0]][start_res[1:]]
end_res = self.residues[end_res[0]][end_res[1:]]
except Exception, e:
raise Exception('The start or end residue could not be found in the PDB file.')
return self.add_backbone_atoms_linearly(start_res, end_res, kept_residues, insertion_residue_map) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:add_atoms_linearly; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:start_atom; 6, identifier:end_atom; 7, identifier:new_atoms; 8, default_parameter; 8, 9; 8, 10; 9, identifier:jitterbug; 10, float:0.2; 11, block; 11, 12; 11, 14; 11, 30; 11, 43; 11, 51; 11, 52; 11, 62; 11, 78; 11, 92; 11, 106; 11, 120; 11, 139; 11, 143; 11, 163; 11, 167; 11, 185; 11, 189; 11, 328; 11, 332; 11, 336; 11, 413; 12, expression_statement; 12, 13; 13, string:'''A low-level function which adds new_atoms between start_atom and end_atom. This function does not validate the
input i.e. the calling functions are responsible for ensuring that the insertion makes sense.
Returns the PDB file content with the new atoms added. These atoms are given fresh serial numbers, starting
from the first serial number larger than the current serial numbers i.e. the ATOM serial numbers do not now
necessarily increase in document order.
The jitter adds some X, Y, Z variability to the new atoms. This is important in the Rosetta software suite when
placing backbone atoms as colinearly placed atoms will break the dihedral angle calculations (the dihedral angle
over 4 colinear atoms is undefined).
'''; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:atom_name_map; 17, dictionary; 17, 18; 17, 21; 17, 24; 17, 27; 18, pair; 18, 19; 18, 20; 19, string:'CA'; 20, string:' CA '; 21, pair; 21, 22; 21, 23; 22, string:'C'; 23, string:' C '; 24, pair; 24, 25; 24, 26; 25, string:'N'; 26, string:' N '; 27, pair; 27, 28; 27, 29; 28, string:'O'; 29, string:' O '; 30, assert_statement; 30, 31; 31, parenthesized_expression; 31, 32; 32, comparison_operator:==; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:start_atom; 36, identifier:residue; 37, identifier:chain; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:end_atom; 41, identifier:residue; 42, identifier:chain; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:chain_id; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:start_atom; 49, identifier:residue; 50, identifier:chain; 51, comment; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:num_new_atoms; 55, call; 55, 56; 55, 57; 56, identifier:float; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:len; 60, argument_list; 60, 61; 61, identifier:new_atoms; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 68; 64, pattern_list; 64, 65; 64, 66; 64, 67; 65, identifier:X; 66, identifier:Y; 67, identifier:Z; 68, expression_list; 68, 69; 68, 72; 68, 75; 69, attribute; 69, 70; 69, 71; 70, identifier:start_atom; 71, identifier:x; 72, attribute; 72, 73; 72, 74; 73, identifier:start_atom; 74, identifier:y; 75, attribute; 75, 76; 75, 77; 76, identifier:start_atom; 77, identifier:z; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:x_step; 81, binary_operator:/; 81, 82; 81, 88; 82, parenthesized_expression; 82, 83; 83, binary_operator:-; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:end_atom; 86, identifier:x; 87, identifier:X; 88, parenthesized_expression; 88, 89; 89, binary_operator:+; 89, 90; 89, 91; 90, identifier:num_new_atoms; 91, float:1.0; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:y_step; 95, binary_operator:/; 95, 96; 95, 102; 96, parenthesized_expression; 96, 97; 97, binary_operator:-; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:end_atom; 100, identifier:y; 101, identifier:Y; 102, parenthesized_expression; 102, 103; 103, binary_operator:+; 103, 104; 103, 105; 104, identifier:num_new_atoms; 105, float:1.0; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:z_step; 109, binary_operator:/; 109, 110; 109, 116; 110, parenthesized_expression; 110, 111; 111, binary_operator:-; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:end_atom; 114, identifier:z; 115, identifier:Z; 116, parenthesized_expression; 116, 117; 117, binary_operator:+; 117, 118; 117, 119; 118, identifier:num_new_atoms; 119, float:1.0; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:D; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:math; 126, identifier:sqrt; 127, argument_list; 127, 128; 128, binary_operator:+; 128, 129; 128, 136; 129, binary_operator:+; 129, 130; 129, 133; 130, binary_operator:*; 130, 131; 130, 132; 131, identifier:x_step; 132, identifier:x_step; 133, binary_operator:*; 133, 134; 133, 135; 134, identifier:y_step; 135, identifier:y_step; 136, binary_operator:*; 136, 137; 136, 138; 137, identifier:z_step; 138, identifier:z_step; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:jitter; 142, integer:0; 143, if_statement; 143, 144; 143, 145; 144, identifier:jitterbug; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:jitter; 149, binary_operator:/; 149, 150; 149, 162; 150, parenthesized_expression; 150, 151; 151, binary_operator:*; 151, 152; 151, 161; 152, parenthesized_expression; 152, 153; 153, binary_operator:/; 153, 154; 153, 160; 154, parenthesized_expression; 154, 155; 155, binary_operator:+; 155, 156; 155, 159; 156, binary_operator:+; 156, 157; 156, 158; 157, identifier:x_step; 158, identifier:y_step; 159, identifier:z_step; 160, float:3.0; 161, identifier:jitterbug; 162, identifier:D; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:new_lines; 166, list:[]; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:next_serial_number; 170, binary_operator:+; 170, 171; 170, 184; 171, call; 171, 172; 171, 173; 172, identifier:max; 173, argument_list; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:sorted; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 183; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:atoms; 182, identifier:keys; 183, argument_list; 184, integer:1; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:round; 188, integer:0; 189, for_statement; 189, 190; 189, 191; 189, 192; 190, identifier:new_atom; 191, identifier:new_atoms; 192, block; 192, 193; 192, 209; 192, 273; 192, 280; 192, 288; 192, 296; 192, 324; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 199; 195, pattern_list; 195, 196; 195, 197; 195, 198; 196, identifier:X; 197, identifier:Y; 198, identifier:Z; 199, expression_list; 199, 200; 199, 203; 199, 206; 200, binary_operator:+; 200, 201; 200, 202; 201, identifier:X; 202, identifier:x_step; 203, binary_operator:+; 203, 204; 203, 205; 204, identifier:Y; 205, identifier:y_step; 206, binary_operator:+; 206, 207; 206, 208; 207, identifier:Z; 208, identifier:z_step; 209, if_statement; 209, 210; 209, 211; 210, identifier:jitter; 211, block; 211, 212; 211, 269; 212, if_statement; 212, 213; 212, 218; 212, 231; 212, 250; 213, comparison_operator:==; 213, 214; 213, 217; 214, binary_operator:%; 214, 215; 214, 216; 215, identifier:round; 216, integer:3; 217, integer:0; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 224; 221, pattern_list; 221, 222; 221, 223; 222, identifier:X; 223, identifier:Y; 224, expression_list; 224, 225; 224, 228; 225, binary_operator:+; 225, 226; 225, 227; 226, identifier:X; 227, identifier:jitter; 228, binary_operator:-; 228, 229; 228, 230; 229, identifier:Y; 230, identifier:jitter; 231, elif_clause; 231, 232; 231, 237; 232, comparison_operator:==; 232, 233; 232, 236; 233, binary_operator:%; 233, 234; 233, 235; 234, identifier:round; 235, integer:3; 236, integer:1; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 243; 240, pattern_list; 240, 241; 240, 242; 241, identifier:Y; 242, identifier:Z; 243, expression_list; 243, 244; 243, 247; 244, binary_operator:+; 244, 245; 244, 246; 245, identifier:Y; 246, identifier:jitter; 247, binary_operator:-; 247, 248; 247, 249; 248, identifier:Z; 249, identifier:jitter; 250, elif_clause; 250, 251; 250, 256; 251, comparison_operator:==; 251, 252; 251, 255; 252, binary_operator:%; 252, 253; 252, 254; 253, identifier:round; 254, integer:3; 255, integer:2; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 262; 259, pattern_list; 259, 260; 259, 261; 260, identifier:Z; 261, identifier:X; 262, expression_list; 262, 263; 262, 266; 263, binary_operator:+; 263, 264; 263, 265; 264, identifier:Z; 265, identifier:jitter; 266, binary_operator:-; 266, 267; 266, 268; 267, identifier:X; 268, identifier:jitter; 269, expression_statement; 269, 270; 270, augmented_assignment:+=; 270, 271; 270, 272; 271, identifier:round; 272, integer:1; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 279; 275, pattern_list; 275, 276; 275, 277; 275, 278; 276, identifier:residue_id; 277, identifier:residue_type; 278, identifier:atom_name; 279, identifier:new_atom; 280, assert_statement; 280, 281; 281, parenthesized_expression; 281, 282; 282, comparison_operator:==; 282, 283; 282, 287; 283, call; 283, 284; 283, 285; 284, identifier:len; 285, argument_list; 285, 286; 286, identifier:residue_type; 287, integer:3; 288, assert_statement; 288, 289; 289, parenthesized_expression; 289, 290; 290, comparison_operator:==; 290, 291; 290, 295; 291, call; 291, 292; 291, 293; 292, identifier:len; 293, argument_list; 293, 294; 294, identifier:residue_id; 295, integer:6; 296, expression_statement; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:new_lines; 300, identifier:append; 301, argument_list; 301, 302; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, string:'ATOM {0} {1} {2} {3} {4:>8.3f}{5:>8.3f}{6:>8.3f} 1.00 0.00 '; 305, identifier:format; 306, argument_list; 306, 307; 306, 316; 306, 319; 306, 320; 306, 321; 306, 322; 306, 323; 307, call; 307, 308; 307, 314; 308, attribute; 308, 309; 308, 313; 309, call; 309, 310; 309, 311; 310, identifier:str; 311, argument_list; 311, 312; 312, identifier:next_serial_number; 313, identifier:rjust; 314, argument_list; 314, 315; 315, integer:5; 316, subscript; 316, 317; 316, 318; 317, identifier:atom_name_map; 318, identifier:atom_name; 319, identifier:residue_type; 320, identifier:residue_id; 321, identifier:X; 322, identifier:Y; 323, identifier:Z; 324, expression_statement; 324, 325; 325, augmented_assignment:+=; 325, 326; 325, 327; 326, identifier:next_serial_number; 327, integer:1; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:new_pdb; 331, list:[]; 332, expression_statement; 332, 333; 333, assignment; 333, 334; 333, 335; 334, identifier:in_start_residue; 335, False; 336, for_statement; 336, 337; 336, 338; 336, 341; 337, identifier:l; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:indexed_lines; 341, block; 341, 342; 341, 361; 341, 386; 342, if_statement; 342, 343; 342, 356; 343, boolean_operator:and; 343, 344; 343, 347; 344, subscript; 344, 345; 344, 346; 345, identifier:l; 346, integer:0; 347, comparison_operator:==; 347, 348; 347, 353; 348, attribute; 348, 349; 348, 352; 349, subscript; 349, 350; 349, 351; 350, identifier:l; 351, integer:3; 352, identifier:serial_number; 353, attribute; 353, 354; 353, 355; 354, identifier:start_atom; 355, identifier:serial_number; 356, block; 356, 357; 357, expression_statement; 357, 358; 358, assignment; 358, 359; 358, 360; 359, identifier:in_start_residue; 360, True; 361, if_statement; 361, 362; 361, 373; 362, boolean_operator:and; 362, 363; 362, 364; 363, identifier:in_start_residue; 364, comparison_operator:!=; 364, 365; 364, 370; 365, attribute; 365, 366; 365, 369; 366, subscript; 366, 367; 366, 368; 367, identifier:l; 368, integer:3; 369, identifier:serial_number; 370, attribute; 370, 371; 370, 372; 371, identifier:start_atom; 372, identifier:serial_number; 373, block; 373, 374; 373, 381; 373, 382; 374, expression_statement; 374, 375; 375, call; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:new_pdb; 378, identifier:extend; 379, argument_list; 379, 380; 380, identifier:new_lines; 381, comment; 382, expression_statement; 382, 383; 383, assignment; 383, 384; 383, 385; 384, identifier:in_start_residue; 385, False; 386, if_statement; 386, 387; 386, 390; 386, 391; 386, 401; 387, subscript; 387, 388; 387, 389; 388, identifier:l; 389, integer:0; 390, comment; 391, block; 391, 392; 392, expression_statement; 392, 393; 393, call; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:new_pdb; 396, identifier:append; 397, argument_list; 397, 398; 398, subscript; 398, 399; 398, 400; 399, identifier:l; 400, integer:2; 401, else_clause; 401, 402; 401, 403; 402, comment; 403, block; 403, 404; 404, expression_statement; 404, 405; 405, call; 405, 406; 405, 409; 406, attribute; 406, 407; 406, 408; 407, identifier:new_pdb; 408, identifier:append; 409, argument_list; 409, 410; 410, subscript; 410, 411; 410, 412; 411, identifier:l; 412, integer:1; 413, return_statement; 413, 414; 414, call; 414, 415; 414, 418; 415, attribute; 415, 416; 415, 417; 416, string:'\n'; 417, identifier:join; 418, argument_list; 418, 419; 419, identifier:new_pdb | def add_atoms_linearly(self, start_atom, end_atom, new_atoms, jitterbug = 0.2):
'''A low-level function which adds new_atoms between start_atom and end_atom. This function does not validate the
input i.e. the calling functions are responsible for ensuring that the insertion makes sense.
Returns the PDB file content with the new atoms added. These atoms are given fresh serial numbers, starting
from the first serial number larger than the current serial numbers i.e. the ATOM serial numbers do not now
necessarily increase in document order.
The jitter adds some X, Y, Z variability to the new atoms. This is important in the Rosetta software suite when
placing backbone atoms as colinearly placed atoms will break the dihedral angle calculations (the dihedral angle
over 4 colinear atoms is undefined).
'''
atom_name_map = {
'CA' : ' CA ',
'C' : ' C ',
'N' : ' N ',
'O' : ' O ',
}
assert(start_atom.residue.chain == end_atom.residue.chain)
chain_id = start_atom.residue.chain
# Initialize steps
num_new_atoms = float(len(new_atoms))
X, Y, Z = start_atom.x, start_atom.y, start_atom.z
x_step = (end_atom.x - X) / (num_new_atoms + 1.0)
y_step = (end_atom.y - Y) / (num_new_atoms + 1.0)
z_step = (end_atom.z - Z) / (num_new_atoms + 1.0)
D = math.sqrt(x_step * x_step + y_step * y_step + z_step * z_step)
jitter = 0
if jitterbug:
jitter = (((x_step + y_step + z_step) / 3.0) * jitterbug) / D
new_lines = []
next_serial_number = max(sorted(self.atoms.keys())) + 1
round = 0
for new_atom in new_atoms:
X, Y, Z = X + x_step, Y + y_step, Z + z_step
if jitter:
if round % 3 == 0:
X, Y = X + jitter, Y - jitter
elif round % 3 == 1:
Y, Z = Y + jitter, Z - jitter
elif round % 3 == 2:
Z, X = Z + jitter, X - jitter
round += 1
residue_id, residue_type, atom_name = new_atom
assert(len(residue_type) == 3)
assert(len(residue_id) == 6)
new_lines.append('ATOM {0} {1} {2} {3} {4:>8.3f}{5:>8.3f}{6:>8.3f} 1.00 0.00 '.format(str(next_serial_number).rjust(5), atom_name_map[atom_name], residue_type, residue_id, X, Y, Z))
next_serial_number += 1
new_pdb = []
in_start_residue = False
for l in self.indexed_lines:
if l[0] and l[3].serial_number == start_atom.serial_number:
in_start_residue = True
if in_start_residue and l[3].serial_number != start_atom.serial_number:
new_pdb.extend(new_lines)
#colortext.warning('\n'.join(new_lines))
in_start_residue = False
if l[0]:
#print(l[2])
new_pdb.append(l[2])
else:
#print(l[1])
new_pdb.append(l[1])
return '\n'.join(new_pdb) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:dispatch_request; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 20; 5, 21; 5, 30; 5, 40; 5, 65; 5, 66; 5, 75; 5, 100; 5, 101; 5, 212; 5, 213; 5, 222; 5, 231; 5, 240; 5, 249; 5, 250; 5, 261; 5, 278; 5, 279; 5, 357; 5, 358; 5, 382; 5, 383; 5, 390; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:current_user; 11, identifier:is_authenticated; 12, block; 12, 13; 13, return_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:redirect; 16, argument_list; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:next; 20, comment; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:in; 22, 23; 22, 24; 23, string:'social_data'; 24, identifier:session; 25, block; 25, 26; 26, delete_statement; 26, 27; 27, subscript; 27, 28; 27, 29; 28, identifier:session; 29, string:'social_data'; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:res; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:app; 38, identifier:authorized_response; 39, argument_list; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:res; 43, None; 44, block; 44, 45; 44, 58; 45, if_statement; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:flash; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:flash; 53, argument_list; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:auth_failed_msg; 57, string:'danger'; 58, return_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:redirect; 61, argument_list; 61, 62; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:next; 65, comment; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:data; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:get_profile_data; 73, argument_list; 73, 74; 74, identifier:res; 75, if_statement; 75, 76; 75, 79; 76, comparison_operator:is; 76, 77; 76, 78; 77, identifier:data; 78, None; 79, block; 79, 80; 79, 93; 80, if_statement; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:flash; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:flash; 88, argument_list; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:data_failed_msg; 92, string:'danger'; 93, return_statement; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:redirect; 96, argument_list; 96, 97; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:next; 100, comment; 101, try_statement; 101, 102; 101, 147; 101, 197; 102, block; 102, 103; 102, 117; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:ok; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:user_service; 109, identifier:attempt_social_login; 110, argument_list; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:provider; 114, subscript; 114, 115; 114, 116; 115, identifier:data; 116, string:'id'; 117, if_statement; 117, 118; 117, 119; 118, identifier:ok; 119, block; 119, 120; 119, 140; 120, if_statement; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:flash; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:flash; 128, argument_list; 128, 129; 128, 139; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:logged_in_msg; 134, identifier:format; 135, argument_list; 135, 136; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:provider; 139, string:'success'; 140, return_statement; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:redirect; 143, argument_list; 143, 144; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:logged_in; 147, except_clause; 147, 148; 147, 154; 148, as_pattern; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:x; 151, identifier:AccountLocked; 152, as_pattern_target; 152, 153; 153, identifier:locked; 154, block; 154, 155; 154, 168; 154, 179; 154, 192; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:msg; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:lock_msg; 163, identifier:format; 164, argument_list; 164, 165; 165, attribute; 165, 166; 165, 167; 166, identifier:locked; 167, identifier:locked_until; 168, if_statement; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:flash; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:flash; 176, argument_list; 176, 177; 176, 178; 177, identifier:msg; 178, string:'danger'; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:url; 182, call; 182, 183; 182, 184; 183, identifier:url_for; 184, argument_list; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:lock_redirect; 188, dictionary_splat; 188, 189; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:lock_redirect_params; 192, return_statement; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:redirect; 195, argument_list; 195, 196; 196, identifier:url; 197, except_clause; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:x; 200, identifier:EmailNotConfirmed; 201, block; 201, 202; 202, return_statement; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:redirect; 205, argument_list; 205, 206; 206, call; 206, 207; 206, 208; 207, identifier:url_for; 208, argument_list; 208, 209; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:unconfirmed_email_endpoint; 212, comment; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:email; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:data; 219, identifier:get; 220, argument_list; 220, 221; 221, string:'email'; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:provider; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:data; 228, identifier:get; 229, argument_list; 229, 230; 230, string:'provider'; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:id; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:data; 237, identifier:get; 238, argument_list; 238, 239; 239, string:'id'; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:id_column; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, string:'{}_id'; 246, identifier:format; 247, argument_list; 247, 248; 248, identifier:provider; 249, comment; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:user; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:user_service; 256, identifier:first; 257, argument_list; 257, 258; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:email; 260, identifier:email; 261, if_statement; 261, 262; 261, 263; 262, identifier:user; 263, block; 263, 264; 263, 271; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:setattr; 267, argument_list; 267, 268; 267, 269; 267, 270; 268, identifier:user; 269, identifier:id_column; 270, identifier:id; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:user_service; 275, identifier:save; 276, argument_list; 276, 277; 277, identifier:user; 278, comment; 279, if_statement; 279, 280; 279, 282; 280, not_operator; 280, 281; 281, identifier:user; 282, block; 282, 283; 282, 289; 282, 298; 282, 307; 282, 325; 282, 334; 282, 340; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:cfg; 286, attribute; 286, 287; 286, 288; 287, identifier:current_app; 288, identifier:config; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:send_welcome; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:cfg; 295, identifier:get; 296, argument_list; 296, 297; 297, string:'USER_SEND_WELCOME_MESSAGE'; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:base_confirm_url; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:cfg; 304, identifier:get; 305, argument_list; 305, 306; 306, string:'USER_BASE_EMAIL_CONFIRM_URL'; 307, if_statement; 307, 308; 307, 310; 308, not_operator; 308, 309; 309, identifier:base_confirm_url; 310, block; 310, 311; 310, 315; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:endpoint; 314, string:'user.confirm.email.request'; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:base_confirm_url; 318, call; 318, 319; 318, 320; 319, identifier:url_for; 320, argument_list; 320, 321; 320, 322; 321, identifier:endpoint; 322, keyword_argument; 322, 323; 322, 324; 323, identifier:_external; 324, True; 325, expression_statement; 325, 326; 326, assignment; 326, 327; 326, 328; 327, identifier:data; 328, call; 328, 329; 328, 330; 329, identifier:dict; 330, argument_list; 330, 331; 331, keyword_argument; 331, 332; 331, 333; 332, identifier:email; 333, identifier:email; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 339; 336, subscript; 336, 337; 336, 338; 337, identifier:data; 338, identifier:id_column; 339, identifier:id; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:user; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:user_service; 346, identifier:register; 347, argument_list; 347, 348; 347, 351; 347, 354; 348, keyword_argument; 348, 349; 348, 350; 349, identifier:user_data; 350, identifier:data; 351, keyword_argument; 351, 352; 351, 353; 352, identifier:send_welcome; 353, identifier:send_welcome; 354, keyword_argument; 354, 355; 354, 356; 355, identifier:base_confirm_url; 356, identifier:base_confirm_url; 357, comment; 358, if_statement; 358, 359; 358, 367; 359, boolean_operator:and; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:user_service; 362, identifier:require_confirmation; 363, not_operator; 363, 364; 364, attribute; 364, 365; 364, 366; 365, identifier:user; 366, identifier:email_confirmed; 367, block; 367, 368; 368, return_statement; 368, 369; 369, call; 369, 370; 369, 371; 370, identifier:redirect; 371, argument_list; 371, 372; 372, call; 372, 373; 372, 374; 373, identifier:url_for; 374, argument_list; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:self; 377, identifier:ok_endpoint; 378, dictionary_splat; 378, 379; 379, attribute; 379, 380; 379, 381; 380, identifier:self; 381, identifier:ok_params; 382, comment; 383, expression_statement; 383, 384; 384, call; 384, 385; 384, 388; 385, attribute; 385, 386; 385, 387; 386, identifier:user_service; 387, identifier:force_login; 388, argument_list; 388, 389; 389, identifier:user; 390, return_statement; 390, 391; 391, call; 391, 392; 391, 393; 392, identifier:redirect; 393, argument_list; 393, 394; 394, attribute; 394, 395; 394, 396; 395, identifier:self; 396, identifier:force_login_redirect | def dispatch_request(self):
""" Handle redirect back from provider """
if current_user.is_authenticated:
return redirect(self.next)
# clear previous!
if 'social_data' in session:
del session['social_data']
res = self.app.authorized_response()
if res is None:
if self.flash: flash(self.auth_failed_msg, 'danger')
return redirect(self.next)
# retrieve profile
data = self.get_profile_data(res)
if data is None:
if self.flash: flash(self.data_failed_msg, 'danger')
return redirect(self.next)
# attempt login
try:
ok = user_service.attempt_social_login(self.provider, data['id'])
if ok:
if self.flash:
flash(self.logged_in_msg.format(self.provider), 'success')
return redirect(self.logged_in)
except x.AccountLocked as locked:
msg = self.lock_msg.format(locked.locked_until)
if self.flash: flash(msg, 'danger')
url = url_for(self.lock_redirect, **self.lock_redirect_params)
return redirect(url)
except x.EmailNotConfirmed:
return redirect(url_for(self.unconfirmed_email_endpoint))
# get data
email = data.get('email')
provider = data.get('provider')
id = data.get('id')
id_column = '{}_id'.format(provider)
# user exists: add social id to profile
user = user_service.first(email=email)
if user:
setattr(user, id_column, id)
user_service.save(user)
# no user: register
if not user:
cfg = current_app.config
send_welcome = cfg.get('USER_SEND_WELCOME_MESSAGE')
base_confirm_url = cfg.get('USER_BASE_EMAIL_CONFIRM_URL')
if not base_confirm_url:
endpoint = 'user.confirm.email.request'
base_confirm_url = url_for(endpoint, _external=True)
data = dict(email=email)
data[id_column] = id
user = user_service.register(
user_data=data,
send_welcome=send_welcome,
base_confirm_url=base_confirm_url
)
# email confirmed?
if user_service.require_confirmation and not user.email_confirmed:
return redirect(url_for(self.ok_endpoint, **self.ok_params))
# otherwise just login
user_service.force_login(user)
return redirect(self.force_login_redirect) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:get_duration_measures; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:source_file_path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:output_path; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:phonemic; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:semantic; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:quiet; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:similarity_file; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:threshold; 22, None; 23, block; 23, 24; 23, 26; 23, 27; 23, 33; 23, 39; 23, 45; 23, 51; 23, 57; 23, 63; 23, 69; 23, 75; 23, 82; 23, 166; 23, 195; 23, 227; 24, expression_statement; 24, 25; 25, comment; 26, comment; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:args; 30, call; 30, 31; 30, 32; 31, identifier:Args; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:args; 37, identifier:output_path; 38, identifier:output_path; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:args; 43, identifier:phonemic; 44, identifier:phonemic; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:args; 49, identifier:semantic; 50, identifier:semantic; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:args; 55, identifier:source_file_path; 56, identifier:source_file_path; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:args; 61, identifier:quiet; 62, identifier:quiet; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:args; 67, identifier:similarity_file; 68, identifier:similarity_file; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:args; 73, identifier:threshold; 74, identifier:threshold; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:args; 78, call; 78, 79; 78, 80; 79, identifier:validate_arguments; 80, argument_list; 80, 81; 81, identifier:args; 82, if_statement; 82, 83; 82, 86; 82, 119; 82, 156; 83, attribute; 83, 84; 83, 85; 84, identifier:args; 85, identifier:phonemic; 86, block; 86, 87; 86, 93; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:response_category; 90, attribute; 90, 91; 90, 92; 91, identifier:args; 92, identifier:phonemic; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:output_prefix; 96, binary_operator:+; 96, 97; 96, 116; 97, binary_operator:+; 97, 98; 97, 115; 98, subscript; 98, 99; 98, 114; 99, call; 99, 100; 99, 112; 100, attribute; 100, 101; 100, 111; 101, call; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:os; 105, identifier:path; 106, identifier:basename; 107, argument_list; 107, 108; 108, attribute; 108, 109; 108, 110; 109, identifier:args; 110, identifier:source_file_path; 111, identifier:split; 112, argument_list; 112, 113; 113, string:'.'; 114, integer:0; 115, string:"_vfclust_phonemic_"; 116, attribute; 116, 117; 116, 118; 117, identifier:args; 118, identifier:phonemic; 119, elif_clause; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:args; 122, identifier:semantic; 123, block; 123, 124; 123, 130; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:response_category; 127, attribute; 127, 128; 127, 129; 128, identifier:args; 129, identifier:semantic; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:output_prefix; 133, binary_operator:+; 133, 134; 133, 153; 134, binary_operator:+; 134, 135; 134, 152; 135, subscript; 135, 136; 135, 151; 136, call; 136, 137; 136, 149; 137, attribute; 137, 138; 137, 148; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:os; 142, identifier:path; 143, identifier:basename; 144, argument_list; 144, 145; 145, attribute; 145, 146; 145, 147; 146, identifier:args; 147, identifier:source_file_path; 148, identifier:split; 149, argument_list; 149, 150; 150, string:'.'; 151, integer:0; 152, string:"_vfclust_semantic_"; 153, attribute; 153, 154; 153, 155; 154, identifier:args; 155, identifier:semantic; 156, else_clause; 156, 157; 157, block; 157, 158; 157, 162; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:response_category; 161, string:""; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:output_prefix; 165, string:""; 166, if_statement; 166, 167; 166, 170; 166, 171; 166, 188; 167, attribute; 167, 168; 167, 169; 168, identifier:args; 169, identifier:output_path; 170, comment; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:target_file_path; 175, call; 175, 176; 175, 181; 176, attribute; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:os; 179, identifier:path; 180, identifier:join; 181, argument_list; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:args; 184, identifier:output_path; 185, binary_operator:+; 185, 186; 185, 187; 186, identifier:output_prefix; 187, string:'.csv'; 188, else_clause; 188, 189; 188, 190; 189, comment; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:target_file_path; 194, False; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:engine; 198, call; 198, 199; 198, 200; 199, identifier:VFClustEngine; 200, argument_list; 200, 201; 200, 204; 200, 209; 200, 212; 200, 217; 200, 222; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:response_category; 203, identifier:response_category; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:response_file_path; 206, attribute; 206, 207; 206, 208; 207, identifier:args; 208, identifier:source_file_path; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:target_file_path; 211, identifier:target_file_path; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:quiet; 214, attribute; 214, 215; 214, 216; 215, identifier:args; 216, identifier:quiet; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:similarity_file; 219, attribute; 219, 220; 219, 221; 220, identifier:args; 221, identifier:similarity_file; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:threshold; 224, attribute; 224, 225; 224, 226; 225, identifier:args; 226, identifier:threshold; 227, return_statement; 227, 228; 228, call; 228, 229; 228, 230; 229, identifier:dict; 230, argument_list; 230, 231; 231, attribute; 231, 232; 231, 233; 232, identifier:engine; 233, identifier:measures | def get_duration_measures(source_file_path,
output_path=None,
phonemic=False,
semantic=False,
quiet=False,
similarity_file = None,
threshold = None):
"""Parses input arguments and runs clustering algorithm.
:param source_file_path: Required. Location of the .csv or .TextGrid file to be
analyzed.
:param output_path: Path to which to write the resultant csv file. If left None,
path will be set to the source_file_path. If set to False, no file will be
written.
:param phonemic: The letter used for phonetic clustering. Note: should be False if
semantic clustering is being used.
:param semantic: The word category used for semantic clustering. Note: should be
False if phonetic clustering is being used.
:param quiet: Set to True if you want to suppress output to the screen during processing.
:param similarity_file (optional): When doing semantic processing, this is the path of
a file containing custom term similarity scores that will be used for clustering.
If a custom file is used, the default LSA-based clustering will not be performed.
:param threshold (optional): When doing semantic processing, this threshold is used
in conjunction with a custom similarity file. The value is used as a semantic
similarity cutoff in clustering. This argument is required if a custom similarity
file is specified. This argument can also be used to override the built-in
cluster/chain thresholds.
:return data: A dictionary of measures derived by clustering the input response.
"""
#validate arguments here rather than where they're first passed in, in case this is used as a package
args = Args()
args.output_path = output_path
args.phonemic = phonemic
args.semantic = semantic
args.source_file_path = source_file_path
args.quiet = quiet
args.similarity_file = similarity_file
args.threshold = threshold
args = validate_arguments(args)
if args.phonemic:
response_category = args.phonemic
output_prefix = os.path.basename(args.source_file_path).split('.')[0] + "_vfclust_phonemic_" + args.phonemic
elif args.semantic:
response_category = args.semantic
output_prefix = os.path.basename(args.source_file_path).split('.')[0] + "_vfclust_semantic_" + args.semantic
else:
response_category = ""
output_prefix = ""
if args.output_path:
#want to output csv file
target_file_path = os.path.join(args.output_path, output_prefix + '.csv')
else:
#no output to system
target_file_path = False
engine = VFClustEngine(response_category=response_category,
response_file_path=args.source_file_path,
target_file_path=target_file_path,
quiet = args.quiet,
similarity_file = args.similarity_file,
threshold = args.threshold
)
return dict(engine.measures) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:tokenize; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 18; 5, 19; 5, 23; 5, 56; 5, 60; 5, 64; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 13; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:quiet; 13, block; 13, 14; 13, 16; 14, expression_statement; 14, 15; 15, identifier:print; 16, print_statement; 16, 17; 17, string:"Finding compound words..."; 18, comment; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:compound_word_dict; 22, dictionary; 23, for_statement; 23, 24; 23, 25; 23, 32; 24, identifier:compound_length; 25, call; 25, 26; 25, 27; 26, identifier:range; 27, argument_list; 27, 28; 27, 29; 27, 30; 28, integer:5; 29, integer:1; 30, unary_operator:-; 30, 31; 31, integer:1; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:compound_word_dict; 37, identifier:compound_length; 38, list_comprehension; 38, 39; 38, 40; 38, 45; 39, identifier:name; 40, for_in_clause; 40, 41; 40, 42; 41, identifier:name; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:names; 45, if_clause; 45, 46; 46, comparison_operator:==; 46, 47; 46, 55; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:name; 53, identifier:split; 54, argument_list; 55, identifier:compound_length; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:current_index; 59, integer:0; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:finished; 63, False; 64, while_statement; 64, 65; 64, 67; 65, not_operator; 65, 66; 66, identifier:finished; 67, block; 67, 68; 68, for_statement; 68, 69; 68, 70; 68, 77; 68, 78; 68, 155; 69, identifier:compound_length; 70, call; 70, 71; 70, 72; 71, identifier:range; 72, argument_list; 72, 73; 72, 74; 72, 75; 73, integer:5; 74, integer:1; 75, unary_operator:-; 75, 76; 76, integer:1; 77, comment; 78, block; 78, 79; 79, if_statement; 79, 80; 79, 92; 79, 93; 80, comparison_operator:<; 80, 81; 80, 86; 81, binary_operator:-; 81, 82; 81, 85; 82, binary_operator:+; 82, 83; 82, 84; 83, identifier:current_index; 84, identifier:compound_length; 85, integer:1; 86, call; 86, 87; 86, 88; 87, identifier:len; 88, argument_list; 88, 89; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:unit_list; 92, comment; 93, block; 93, 94; 93, 98; 93, 99; 93, 120; 93, 128; 93, 129; 93, 130; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:compound_word; 97, string:""; 98, comment; 99, for_statement; 99, 100; 99, 101; 99, 111; 100, identifier:word; 101, subscript; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:unit_list; 105, slice; 105, 106; 105, 107; 105, 108; 106, identifier:current_index; 107, colon; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:current_index; 110, identifier:compound_length; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, augmented_assignment:+=; 113, 114; 113, 115; 114, identifier:compound_word; 115, binary_operator:+; 115, 116; 115, 117; 116, string:" "; 117, attribute; 117, 118; 117, 119; 118, identifier:word; 119, identifier:text; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:compound_word; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:compound_word; 126, identifier:strip; 127, argument_list; 128, comment; 129, comment; 130, if_statement; 130, 131; 130, 136; 130, 137; 131, comparison_operator:in; 131, 132; 131, 133; 132, identifier:compound_word; 133, subscript; 133, 134; 133, 135; 134, identifier:compound_word_dict; 135, identifier:compound_length; 136, comment; 137, block; 137, 138; 137, 150; 137, 154; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:make_compound_word; 143, argument_list; 143, 144; 143, 147; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:start_index; 146, identifier:current_index; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:how_many; 149, identifier:compound_length; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 153; 152, identifier:current_index; 153, integer:1; 154, break_statement; 155, else_clause; 155, 156; 155, 157; 156, comment; 157, block; 157, 158; 157, 162; 158, expression_statement; 158, 159; 159, augmented_assignment:+=; 159, 160; 159, 161; 160, identifier:current_index; 161, integer:1; 162, if_statement; 162, 163; 162, 171; 162, 172; 162, 173; 163, comparison_operator:>=; 163, 164; 163, 165; 164, identifier:current_index; 165, call; 165, 166; 165, 167; 166, identifier:len; 167, argument_list; 167, 168; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:unit_list; 171, comment; 172, comment; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:finished; 177, True | def tokenize(self):
"""Tokenizes all multiword names in the list of Units.
Modifies:
- (indirectly) self.unit_list, by combining words into compound words.
This is done because many names may be composed of multiple words, e.g.,
'grizzly bear'. In order to count the number of permissible words
generated, and also to compute semantic relatedness between these
multiword names and other names, multiword names must each be reduced to
a respective single token.
"""
if not self.quiet:
print
print "Finding compound words..."
# lists of animal names containing 2-5 separate words
compound_word_dict = {}
for compound_length in range(5,1,-1):
compound_word_dict[compound_length] = [name for name in self.names if len(name.split()) == compound_length]
current_index = 0
finished = False
while not finished:
for compound_length in range(5,1,-1): #[5, 4, 3, 2]
if current_index + compound_length - 1 < len(self.unit_list): #don't want to overstep bounds of the list
compound_word = ""
#create compound word
for word in self.unit_list[current_index:current_index + compound_length]:
compound_word += " " + word.text
compound_word = compound_word.strip() # remove initial white space
#check if compound word is in list
if compound_word in compound_word_dict[compound_length]:
#if so, create the compound word
self.make_compound_word(start_index = current_index, how_many = compound_length)
current_index += 1
break
else: #if no breaks for any number of words
current_index += 1
if current_index >= len(self.unit_list): # check here instead of at the top in case
# changing the unit list length introduces a bug
finished = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:clean; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 26; 5, 36; 5, 37; 5, 41; 5, 142; 5, 143; 5, 147; 5, 151; 5, 211; 5, 212; 5, 280; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 13; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:quiet; 13, block; 13, 14; 13, 16; 13, 18; 13, 20; 14, expression_statement; 14, 15; 15, identifier:print; 16, print_statement; 16, 17; 17, string:"Preprocessing input..."; 18, print_statement; 18, 19; 19, string:"Raw response:"; 20, print_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:display; 25, argument_list; 26, if_statement; 26, 27; 26, 31; 27, not_operator; 27, 28; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:quiet; 31, block; 31, 32; 31, 34; 32, expression_statement; 32, 33; 33, identifier:print; 34, print_statement; 34, 35; 35, string:"Cleaning words..."; 36, comment; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:current_index; 40, integer:0; 41, while_statement; 41, 42; 41, 50; 42, comparison_operator:<; 42, 43; 42, 44; 43, identifier:current_index; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:unit_list; 50, block; 50, 51; 50, 61; 50, 121; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:word; 54, attribute; 54, 55; 54, 60; 55, subscript; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:unit_list; 59, identifier:current_index; 60, identifier:text; 61, if_statement; 61, 62; 61, 67; 61, 106; 62, comparison_operator:==; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:type; 66, string:"PHONETIC"; 67, block; 67, 68; 67, 105; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:test; 71, parenthesized_expression; 71, 72; 72, boolean_operator:and; 72, 73; 72, 95; 72, 96; 73, boolean_operator:and; 73, 74; 73, 91; 73, 92; 74, boolean_operator:and; 74, 75; 74, 83; 74, 84; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:word; 78, identifier:startswith; 79, argument_list; 79, 80; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:letter_or_category; 83, comment; 84, not_operator; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:word; 88, identifier:endswith; 89, argument_list; 89, 90; 90, string:'-'; 91, comment; 92, comparison_operator:not; 92, 93; 92, 94; 93, string:'_'; 94, identifier:word; 95, comment; 96, comparison_operator:in; 96, 97; 96, 102; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:word; 100, identifier:lower; 101, argument_list; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:english_words; 105, comment; 106, elif_clause; 106, 107; 106, 112; 107, comparison_operator:==; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:type; 111, string:"SEMANTIC"; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:test; 116, comparison_operator:in; 116, 117; 116, 118; 117, identifier:word; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:permissible_words; 121, if_statement; 121, 122; 121, 124; 121, 125; 121, 135; 122, not_operator; 122, 123; 123, identifier:test; 124, comment; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:remove_unit; 131, argument_list; 131, 132; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:index; 134, identifier:current_index; 135, else_clause; 135, 136; 135, 137; 136, comment; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, augmented_assignment:+=; 139, 140; 139, 141; 140, identifier:current_index; 141, integer:1; 142, comment; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:current_index; 146, integer:0; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:finished; 150, False; 151, while_statement; 151, 152; 151, 162; 151, 163; 152, comparison_operator:<; 152, 153; 152, 154; 153, identifier:current_index; 154, binary_operator:-; 154, 155; 154, 161; 155, call; 155, 156; 155, 157; 156, identifier:len; 157, argument_list; 157, 158; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:unit_list; 161, integer:1; 162, comment; 163, block; 163, 164; 164, if_statement; 164, 165; 164, 193; 164, 194; 164, 204; 165, comparison_operator:==; 165, 166; 165, 178; 165, 179; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:stemmer; 169, identifier:stem; 170, argument_list; 170, 171; 171, attribute; 171, 172; 171, 177; 172, subscript; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:unit_list; 176, identifier:current_index; 177, identifier:text; 178, line_continuation:\; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:stemmer; 182, identifier:stem; 183, argument_list; 183, 184; 184, attribute; 184, 185; 184, 192; 185, subscript; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:unit_list; 189, binary_operator:+; 189, 190; 189, 191; 190, identifier:current_index; 191, integer:1; 192, identifier:text; 193, comment; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:combine_same_stem_units; 200, argument_list; 200, 201; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:index; 203, identifier:current_index; 204, else_clause; 204, 205; 204, 206; 205, comment; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, augmented_assignment:+=; 208, 209; 208, 210; 209, identifier:current_index; 210, integer:1; 211, comment; 212, if_statement; 212, 213; 212, 218; 213, comparison_operator:==; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:type; 217, string:"PHONETIC"; 218, block; 218, 219; 219, for_statement; 219, 220; 219, 221; 219, 224; 220, identifier:unit; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:unit_list; 224, block; 224, 225; 224, 231; 224, 232; 224, 248; 224, 274; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:word; 228, attribute; 228, 229; 228, 230; 229, identifier:unit; 230, identifier:text; 231, comment; 232, if_statement; 232, 233; 232, 238; 232, 239; 233, comparison_operator:in; 233, 234; 233, 235; 234, identifier:word; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:cmudict; 238, comment; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:phonetic_representation; 243, subscript; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:cmudict; 247, identifier:word; 248, if_statement; 248, 249; 248, 254; 248, 255; 249, comparison_operator:not; 249, 250; 249, 251; 250, identifier:word; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:cmudict; 254, comment; 255, block; 255, 256; 255, 265; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:phonetic_representation; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:generate_phonetic_representation; 263, argument_list; 263, 264; 264, identifier:word; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:phonetic_representation; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:modify_phonetic_representation; 272, argument_list; 272, 273; 273, identifier:phonetic_representation; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:unit; 278, identifier:phonetic_representation; 279, identifier:phonetic_representation; 280, if_statement; 280, 281; 280, 285; 281, not_operator; 281, 282; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:quiet; 285, block; 285, 286; 285, 288; 285, 290; 286, expression_statement; 286, 287; 287, identifier:print; 288, print_statement; 288, 289; 289, string:"Cleaned response:"; 290, print_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:display; 295, argument_list | def clean(self):
""" Removes any Units that are not applicable given the current semantic or phonetic category.
Modifies:
- self.unit_list: Removes Units from this list that do not fit into the clustering category.
it does by by either combining units to make compound words, combining units with the
same stem, or eliminating units altogether if they do not conform to the category.
If the type is phonetic, this method also generates phonetic clusters for all Unit
objects in self.unit_list.
This method performs three main tasks:
1. Removes words that do not conform to the clustering category (i.e. start with the
wrong letter, or are not an animal).
2. Combine adjacent words with the same stem into a single unit. The NLTK Porter Stemmer
is used for determining whether stems are the same.
http://www.nltk.org/_modules/nltk/stem/porter.html
3. In the case of PHONETIC clustering, compute the phonetic representation of each unit.
"""
if not self.quiet:
print
print "Preprocessing input..."
print "Raw response:"
print self.display()
if not self.quiet:
print
print "Cleaning words..."
#weed out words not starting with the right letter or in the right category
current_index = 0
while current_index < len(self.unit_list):
word = self.unit_list[current_index].text
if self.type == "PHONETIC":
test = (word.startswith(self.letter_or_category) and #starts with required letter
not word.endswith('-') and # Weed out word fragments
'_' not in word and # Weed out, e.g., 'filledpause_um'
word.lower() in self.english_words) #make sure the word is english
elif self.type == "SEMANTIC":
test = word in self.permissible_words
if not test: #if test fails remove word
self.remove_unit(index = current_index)
else: # otherwise just increment, but check to see if you're at the end of the list
current_index += 1
#combine words with the same stem
current_index = 0
finished = False
while current_index < len(self.unit_list) - 1:
#don't combine for lists of length 0, 1
if stemmer.stem(self.unit_list[current_index].text) == \
stemmer.stem(self.unit_list[current_index + 1].text):
#if same stem as next, merge next unit with current unit
self.combine_same_stem_units(index = current_index)
else: # if not same stem, increment index
current_index += 1
#get phonetic representations
if self.type == "PHONETIC":
for unit in self.unit_list:
word = unit.text
#get phonetic representation
if word in self.cmudict:
# If word in CMUdict, get its phonetic representation
phonetic_representation = self.cmudict[word]
if word not in self.cmudict:
# Else, generate a phonetic representation for it
phonetic_representation = self.generate_phonetic_representation(word)
phonetic_representation = self.modify_phonetic_representation(phonetic_representation)
unit.phonetic_representation = phonetic_representation
if not self.quiet:
print
print "Cleaned response:"
print self.display() |
Subsets and Splits