sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_raw_counts; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 14; 5, 20; 5, 351; 5, 378; 5, 405; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:words; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:labels; 13, list:[]; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:words_said; 17, call; 17, 18; 17, 19; 18, identifier:set; 19, argument_list; 20, for_statement; 20, 21; 20, 22; 20, 25; 21, identifier:unit; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:parsed_response; 25, block; 25, 26; 25, 32; 25, 36; 25, 105; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:word; 29, attribute; 29, 30; 29, 31; 30, identifier:unit; 31, identifier:text; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:test; 35, False; 36, if_statement; 36, 37; 36, 42; 36, 89; 37, comparison_operator:==; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:type; 41, string:"PHONETIC"; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:test; 46, parenthesized_expression; 46, 47; 47, boolean_operator:and; 47, 48; 47, 80; 48, boolean_operator:and; 48, 49; 48, 73; 49, boolean_operator:and; 49, 50; 49, 70; 50, boolean_operator:and; 50, 51; 50, 67; 51, boolean_operator:and; 51, 52; 51, 64; 52, boolean_operator:and; 52, 53; 52, 61; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:word; 56, identifier:startswith; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:letter; 61, comparison_operator:not; 61, 62; 61, 63; 62, string:"T_"; 63, identifier:word; 64, comparison_operator:not; 64, 65; 64, 66; 65, string:"E_"; 66, identifier:word; 67, comparison_operator:not; 67, 68; 67, 69; 68, string:"!"; 69, identifier:word; 70, comparison_operator:not; 70, 71; 70, 72; 71, string:"FILLEDPAUSE_"; 72, identifier:word; 73, not_operator; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:word; 77, identifier:endswith; 78, argument_list; 78, 79; 79, string:'-'; 80, comparison_operator:in; 80, 81; 80, 86; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:word; 84, identifier:lower; 85, argument_list; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:english_words; 89, elif_clause; 89, 90; 89, 95; 90, comparison_operator:==; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:type; 94, string:"SEMANTIC"; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:test; 99, parenthesized_expression; 99, 100; 100, comparison_operator:in; 100, 101; 100, 102; 101, identifier:word; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:permissible_words; 105, if_statement; 105, 106; 105, 107; 105, 209; 105, 243; 105, 273; 105, 307; 106, identifier:test; 107, block; 107, 108; 107, 116; 107, 124; 107, 195; 107, 202; 108, expression_statement; 108, 109; 109, augmented_assignment:+=; 109, 110; 109, 115; 110, subscript; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:measures; 114, string:'COUNT_total_words'; 115, integer:1; 116, expression_statement; 116, 117; 117, augmented_assignment:+=; 117, 118; 117, 123; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:measures; 122, string:'COUNT_permissible_words'; 123, integer:1; 124, if_statement; 124, 125; 124, 134; 124, 150; 124, 186; 125, call; 125, 126; 125, 127; 126, identifier:any; 127, generator_expression; 127, 128; 127, 131; 128, comparison_operator:==; 128, 129; 128, 130; 129, identifier:word; 130, identifier:w; 131, for_in_clause; 131, 132; 131, 133; 132, identifier:w; 133, identifier:words_said; 134, block; 134, 135; 134, 143; 135, expression_statement; 135, 136; 136, augmented_assignment:+=; 136, 137; 136, 142; 137, subscript; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:measures; 141, string:'COUNT_exact_repetitions'; 142, integer:1; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:labels; 147, identifier:append; 148, argument_list; 148, 149; 149, string:'EXACT REPETITION'; 150, elif_clause; 150, 151; 150, 170; 151, call; 151, 152; 151, 153; 152, identifier:any; 153, generator_expression; 153, 154; 153, 167; 154, comparison_operator:==; 154, 155; 154, 161; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:stemmer; 158, identifier:stem; 159, argument_list; 159, 160; 160, identifier:word; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:stemmer; 164, identifier:stem; 165, argument_list; 165, 166; 166, identifier:w; 167, for_in_clause; 167, 168; 167, 169; 168, identifier:w; 169, identifier:words_said; 170, block; 170, 171; 170, 179; 171, expression_statement; 171, 172; 172, augmented_assignment:+=; 172, 173; 172, 178; 173, subscript; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:measures; 177, string:'COUNT_stem_repetitions'; 178, integer:1; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:labels; 183, identifier:append; 184, argument_list; 184, 185; 185, string:'STEM REPETITION'; 186, else_clause; 186, 187; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:labels; 192, identifier:append; 193, argument_list; 193, 194; 194, string:'PERMISSIBLE WORD'; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:words_said; 199, identifier:add; 200, argument_list; 200, 201; 201, identifier:word; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:words; 206, identifier:append; 207, argument_list; 207, 208; 208, identifier:word; 209, elif_clause; 209, 210; 209, 220; 210, call; 210, 211; 210, 218; 211, attribute; 211, 212; 211, 217; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:word; 215, identifier:lower; 216, argument_list; 217, identifier:startswith; 218, argument_list; 218, 219; 219, string:'e_'; 220, block; 220, 221; 220, 229; 220, 236; 221, expression_statement; 221, 222; 222, augmented_assignment:+=; 222, 223; 222, 228; 223, subscript; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:measures; 227, string:'COUNT_examiner_words'; 228, integer:1; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:words; 233, identifier:append; 234, argument_list; 234, 235; 235, identifier:word; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:labels; 240, identifier:append; 241, argument_list; 241, 242; 242, string:'EXAMINER WORD'; 243, elif_clause; 243, 244; 243, 250; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:word; 247, identifier:endswith; 248, argument_list; 248, 249; 249, string:'-'; 250, block; 250, 251; 250, 259; 250, 266; 251, expression_statement; 251, 252; 252, augmented_assignment:+=; 252, 253; 252, 258; 253, subscript; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:measures; 257, string:'COUNT_word_fragments'; 258, integer:1; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:words; 263, identifier:append; 264, argument_list; 264, 265; 265, identifier:word; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:labels; 270, identifier:append; 271, argument_list; 271, 272; 272, string:'WORD FRAGMENT'; 273, elif_clause; 273, 274; 273, 284; 274, call; 274, 275; 274, 282; 275, attribute; 275, 276; 275, 281; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:word; 279, identifier:lower; 280, argument_list; 281, identifier:startswith; 282, argument_list; 282, 283; 283, string:'filledpause'; 284, block; 284, 285; 284, 293; 284, 300; 285, expression_statement; 285, 286; 286, augmented_assignment:+=; 286, 287; 286, 292; 287, subscript; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:self; 290, identifier:measures; 291, string:'COUNT_filled_pauses'; 292, integer:1; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:words; 297, identifier:append; 298, argument_list; 298, 299; 299, identifier:word; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:labels; 304, identifier:append; 305, argument_list; 305, 306; 306, string:'FILLED PAUSE'; 307, elif_clause; 307, 308; 307, 320; 308, comparison_operator:not; 308, 309; 308, 314; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:word; 312, identifier:lower; 313, argument_list; 314, list:['!sil', 't_noise', 't_cough', 't_lipsmack', 't_breath']; 314, 315; 314, 316; 314, 317; 314, 318; 314, 319; 315, string:'!sil'; 316, string:'t_noise'; 317, string:'t_cough'; 318, string:'t_lipsmack'; 319, string:'t_breath'; 320, block; 320, 321; 320, 329; 320, 337; 320, 344; 321, expression_statement; 321, 322; 322, augmented_assignment:+=; 322, 323; 322, 328; 323, subscript; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:self; 326, identifier:measures; 327, string:'COUNT_total_words'; 328, integer:1; 329, expression_statement; 329, 330; 330, augmented_assignment:+=; 330, 331; 330, 336; 331, subscript; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:self; 334, identifier:measures; 335, string:'COUNT_asides'; 336, integer:1; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:words; 341, identifier:append; 342, argument_list; 342, 343; 343, identifier:word; 344, expression_statement; 344, 345; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:labels; 348, identifier:append; 349, argument_list; 349, 350; 350, string:'ASIDE'; 351, if_statement; 351, 352; 351, 356; 352, not_operator; 352, 353; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:quiet; 356, block; 356, 357; 356, 359; 356, 361; 357, expression_statement; 357, 358; 358, identifier:print; 359, print_statement; 359, 360; 360, string:"Labels:"; 361, expression_statement; 361, 362; 362, call; 362, 363; 362, 364; 363, identifier:print_table; 364, argument_list; 364, 365; 365, list_comprehension; 365, 366; 365, 369; 366, tuple; 366, 367; 366, 368; 367, identifier:word; 368, identifier:label; 369, for_in_clause; 369, 370; 369, 373; 370, pattern_list; 370, 371; 370, 372; 371, identifier:word; 372, identifier:label; 373, call; 373, 374; 373, 375; 374, identifier:zip; 375, argument_list; 375, 376; 375, 377; 376, identifier:words; 377, identifier:labels; 378, expression_statement; 378, 379; 379, assignment; 379, 380; 379, 385; 379, 386; 380, subscript; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:self; 383, identifier:measures; 384, string:'COUNT_unique_permissible_words'; 385, line_continuation:\; 386, binary_operator:-; 386, 387; 386, 399; 386, 400; 387, binary_operator:-; 387, 388; 387, 393; 387, 394; 388, subscript; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:self; 391, identifier:measures; 392, string:'COUNT_permissible_words'; 393, line_continuation:\; 394, subscript; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:self; 397, identifier:measures; 398, string:'COUNT_exact_repetitions'; 399, line_continuation:\; 400, subscript; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:self; 403, identifier:measures; 404, string:'COUNT_stem_repetitions'; 405, if_statement; 405, 406; 405, 410; 406, not_operator; 406, 407; 407, attribute; 407, 408; 407, 409; 408, identifier:self; 409, identifier:quiet; 410, block; 410, 411; 410, 413; 410, 415; 410, 432; 410, 438; 411, expression_statement; 411, 412; 412, identifier:print; 413, print_statement; 413, 414; 414, string:"Counts:"; 415, expression_statement; 415, 416; 416, assignment; 416, 417; 416, 418; 417, identifier:collection_measures; 418, list_comprehension; 418, 419; 418, 420; 418, 425; 419, identifier:x; 420, for_in_clause; 420, 421; 420, 422; 421, identifier:x; 422, attribute; 422, 423; 422, 424; 423, identifier:self; 424, identifier:measures; 425, if_clause; 425, 426; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:x; 429, identifier:startswith; 430, argument_list; 430, 431; 431, string:"COUNT_"; 432, expression_statement; 432, 433; 433, call; 433, 434; 433, 437; 434, attribute; 434, 435; 434, 436; 435, identifier:collection_measures; 436, identifier:sort; 437, argument_list; 438, if_statement; 438, 439; 438, 443; 439, not_operator; 439, 440; 440, attribute; 440, 441; 440, 442; 441, identifier:self; 442, identifier:quiet; 443, block; 443, 444; 444, expression_statement; 444, 445; 445, call; 445, 446; 445, 447; 446, identifier:print_table; 447, argument_list; 447, 448; 448, list_comprehension; 448, 449; 448, 459; 449, tuple; 449, 450; 449, 451; 450, identifier:k; 451, call; 451, 452; 451, 453; 452, identifier:str; 453, argument_list; 453, 454; 454, subscript; 454, 455; 454, 458; 455, attribute; 455, 456; 455, 457; 456, identifier:self; 457, identifier:measures; 458, identifier:k; 459, for_in_clause; 459, 460; 459, 461; 460, identifier:k; 461, identifier:collection_measures | def get_raw_counts(self):
words = []
labels = []
words_said = set()
for unit in self.parsed_response:
word = unit.text
test = False
if self.type == "PHONETIC":
test = (word.startswith(self.letter) and
"T_" not in word and "E_" not in word and "!" not in word and
"FILLEDPAUSE_" not in word and
not word.endswith('-') and
word.lower() in self.english_words)
elif self.type == "SEMANTIC":
test = (word in self.permissible_words)
if test:
self.measures['COUNT_total_words'] += 1
self.measures['COUNT_permissible_words'] += 1
if any(word == w for w in words_said):
self.measures['COUNT_exact_repetitions'] += 1
labels.append('EXACT REPETITION')
elif any(stemmer.stem(word) == stemmer.stem(w) for w in words_said):
self.measures['COUNT_stem_repetitions'] += 1
labels.append('STEM REPETITION')
else:
labels.append('PERMISSIBLE WORD')
words_said.add(word)
words.append(word)
elif word.lower().startswith('e_'):
self.measures['COUNT_examiner_words'] += 1
words.append(word)
labels.append('EXAMINER WORD')
elif word.endswith('-'):
self.measures['COUNT_word_fragments'] += 1
words.append(word)
labels.append('WORD FRAGMENT')
elif word.lower().startswith('filledpause'):
self.measures['COUNT_filled_pauses'] += 1
words.append(word)
labels.append('FILLED PAUSE')
elif word.lower() not in ['!sil', 't_noise', 't_cough', 't_lipsmack', 't_breath']:
self.measures['COUNT_total_words'] += 1
self.measures['COUNT_asides'] += 1
words.append(word)
labels.append('ASIDE')
if not self.quiet:
print
print "Labels:"
print_table([(word,label) for word,label in zip(words,labels)])
self.measures['COUNT_unique_permissible_words'] = \
self.measures['COUNT_permissible_words'] - \
self.measures['COUNT_exact_repetitions'] - \
self.measures['COUNT_stem_repetitions']
if not self.quiet:
print
print "Counts:"
collection_measures = [x for x in self.measures if x.startswith("COUNT_")]
collection_measures.sort()
if not self.quiet:
print_table([(k, str(self.measures[k])) for k in collection_measures]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:compute_similarity_score; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:unit1; 6, identifier:unit2; 7, block; 7, 8; 7, 380; 8, if_statement; 8, 9; 8, 14; 8, 224; 9, comparison_operator:==; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:type; 13, string:"PHONETIC"; 14, block; 14, 15; 14, 21; 14, 27; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:word1; 18, attribute; 18, 19; 18, 20; 19, identifier:unit1; 20, identifier:phonetic_representation; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:word2; 24, attribute; 24, 25; 24, 26; 25, identifier:unit2; 26, identifier:phonetic_representation; 27, if_statement; 27, 28; 27, 33; 27, 178; 28, comparison_operator:==; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:current_similarity_measure; 32, string:"phone"; 33, block; 33, 34; 33, 48; 33, 69; 33, 78; 33, 166; 33, 176; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, pattern_list; 36, 37; 36, 38; 37, identifier:word1_length; 38, identifier:word2_length; 39, expression_list; 39, 40; 39, 44; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, identifier:word1; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, identifier:word2; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:>; 49, 50; 49, 51; 50, identifier:word1_length; 51, identifier:word2_length; 52, block; 52, 53; 52, 61; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, pattern_list; 55, 56; 55, 57; 56, identifier:word1; 57, identifier:word2; 58, expression_list; 58, 59; 58, 60; 59, identifier:word2; 60, identifier:word1; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, pattern_list; 63, 64; 63, 65; 64, identifier:word1_length; 65, identifier:word2_length; 66, expression_list; 66, 67; 66, 68; 67, identifier:word2_length; 68, identifier:word1_length; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:current; 72, call; 72, 73; 72, 74; 73, identifier:range; 74, argument_list; 74, 75; 75, binary_operator:+; 75, 76; 75, 77; 76, identifier:word1_length; 77, integer:1; 78, for_statement; 78, 79; 78, 80; 78, 87; 79, identifier:i; 80, call; 80, 81; 80, 82; 81, identifier:range; 82, argument_list; 82, 83; 82, 84; 83, integer:1; 84, binary_operator:+; 84, 85; 84, 86; 85, identifier:word2_length; 86, integer:1; 87, block; 87, 88; 87, 102; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, pattern_list; 90, 91; 90, 92; 91, identifier:previous; 92, identifier:current; 93, expression_list; 93, 94; 93, 95; 94, identifier:current; 95, binary_operator:+; 95, 96; 95, 98; 96, list:[i]; 96, 97; 97, identifier:i; 98, binary_operator:*; 98, 99; 98, 101; 99, list:[0]; 99, 100; 100, integer:0; 101, identifier:word1_length; 102, for_statement; 102, 103; 102, 104; 102, 111; 103, identifier:j; 104, call; 104, 105; 104, 106; 105, identifier:range; 106, argument_list; 106, 107; 106, 108; 107, integer:1; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:word1_length; 110, integer:1; 111, block; 111, 112; 111, 130; 111, 138; 111, 155; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, pattern_list; 114, 115; 114, 116; 115, identifier:add; 116, identifier:delete; 117, expression_list; 117, 118; 117, 123; 118, binary_operator:+; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:previous; 121, identifier:j; 122, integer:1; 123, binary_operator:+; 123, 124; 123, 129; 124, subscript; 124, 125; 124, 126; 125, identifier:current; 126, binary_operator:-; 126, 127; 126, 128; 127, identifier:j; 128, integer:1; 129, integer:1; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:change; 133, subscript; 133, 134; 133, 135; 134, identifier:previous; 135, binary_operator:-; 135, 136; 135, 137; 136, identifier:j; 137, integer:1; 138, if_statement; 138, 139; 138, 150; 139, comparison_operator:!=; 139, 140; 139, 145; 140, subscript; 140, 141; 140, 142; 141, identifier:word1; 142, binary_operator:-; 142, 143; 142, 144; 143, identifier:j; 144, integer:1; 145, subscript; 145, 146; 145, 147; 146, identifier:word2; 147, binary_operator:-; 147, 148; 147, 149; 148, identifier:i; 149, integer:1; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, augmented_assignment:+=; 152, 153; 152, 154; 153, identifier:change; 154, integer:1; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:current; 159, identifier:j; 160, call; 160, 161; 160, 162; 161, identifier:min; 162, argument_list; 162, 163; 162, 164; 162, 165; 163, identifier:add; 164, identifier:delete; 165, identifier:change; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:phonetic_similarity_score; 169, binary_operator:-; 169, 170; 169, 171; 170, integer:1; 171, binary_operator:/; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:current; 174, identifier:word1_length; 175, identifier:word2_length; 176, return_statement; 176, 177; 177, identifier:phonetic_similarity_score; 178, elif_clause; 178, 179; 178, 184; 179, comparison_operator:==; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:current_similarity_measure; 183, string:"biphone"; 184, block; 184, 185; 184, 222; 185, if_statement; 185, 186; 185, 211; 185, 216; 186, boolean_operator:or; 186, 187; 186, 198; 187, comparison_operator:==; 187, 188; 187, 193; 188, subscript; 188, 189; 188, 190; 189, identifier:word1; 190, slice; 190, 191; 190, 192; 191, colon; 192, integer:2; 193, subscript; 193, 194; 193, 195; 194, identifier:word2; 195, slice; 195, 196; 195, 197; 196, colon; 197, integer:2; 198, comparison_operator:==; 198, 199; 198, 205; 199, subscript; 199, 200; 199, 201; 200, identifier:word1; 201, slice; 201, 202; 201, 204; 202, unary_operator:-; 202, 203; 203, integer:2; 204, colon; 205, subscript; 205, 206; 205, 207; 206, identifier:word2; 207, slice; 207, 208; 207, 210; 208, unary_operator:-; 208, 209; 209, integer:2; 210, colon; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:common_biphone_score; 215, integer:1; 216, else_clause; 216, 217; 217, block; 217, 218; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:common_biphone_score; 221, integer:0; 222, return_statement; 222, 223; 223, identifier:common_biphone_score; 224, elif_clause; 224, 225; 224, 230; 225, comparison_operator:==; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:type; 229, string:"SEMANTIC"; 230, block; 230, 231; 230, 237; 230, 243; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:word1; 234, attribute; 234, 235; 234, 236; 235, identifier:unit1; 236, identifier:text; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:word2; 240, attribute; 240, 241; 240, 242; 241, identifier:unit2; 242, identifier:text; 243, if_statement; 243, 244; 243, 249; 243, 328; 244, comparison_operator:==; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:current_similarity_measure; 248, string:"lsa"; 249, block; 249, 250; 249, 258; 249, 266; 249, 285; 249, 301; 249, 317; 249, 326; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:w1_vec; 253, subscript; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:term_vectors; 257, identifier:word1; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:w2_vec; 261, subscript; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:term_vectors; 265, identifier:word2; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:dot; 269, call; 269, 270; 269, 271; 270, identifier:sum; 271, argument_list; 271, 272; 272, list_comprehension; 272, 273; 272, 276; 273, binary_operator:*; 273, 274; 273, 275; 274, identifier:w1; 275, identifier:w2; 276, for_in_clause; 276, 277; 276, 280; 277, pattern_list; 277, 278; 277, 279; 278, identifier:w1; 279, identifier:w2; 280, call; 280, 281; 280, 282; 281, identifier:zip; 282, argument_list; 282, 283; 282, 284; 283, identifier:w1_vec; 284, identifier:w2_vec; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:norm1; 288, call; 288, 289; 288, 290; 289, identifier:sqrt; 290, argument_list; 290, 291; 291, call; 291, 292; 291, 293; 292, identifier:sum; 293, argument_list; 293, 294; 294, list_comprehension; 294, 295; 294, 298; 295, binary_operator:*; 295, 296; 295, 297; 296, identifier:w; 297, identifier:w; 298, for_in_clause; 298, 299; 298, 300; 299, identifier:w; 300, identifier:w1_vec; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:norm2; 304, call; 304, 305; 304, 306; 305, identifier:sqrt; 306, argument_list; 306, 307; 307, call; 307, 308; 307, 309; 308, identifier:sum; 309, argument_list; 309, 310; 310, list_comprehension; 310, 311; 310, 314; 311, binary_operator:*; 311, 312; 311, 313; 312, identifier:w; 313, identifier:w; 314, for_in_clause; 314, 315; 314, 316; 315, identifier:w; 316, identifier:w2_vec; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:semantic_relatedness_score; 320, binary_operator:/; 320, 321; 320, 322; 321, identifier:dot; 322, parenthesized_expression; 322, 323; 323, binary_operator:*; 323, 324; 323, 325; 324, identifier:norm1; 325, identifier:norm2; 326, return_statement; 326, 327; 327, identifier:semantic_relatedness_score; 328, elif_clause; 328, 329; 328, 334; 329, comparison_operator:==; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:self; 332, identifier:current_similarity_measure; 333, string:"custom"; 334, block; 334, 335; 334, 378; 335, try_statement; 335, 336; 335, 347; 336, block; 336, 337; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 340; 339, identifier:similarity; 340, subscript; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:self; 343, identifier:custom_similarity_scores; 344, tuple; 344, 345; 344, 346; 345, identifier:word1; 346, identifier:word2; 347, except_clause; 347, 348; 347, 349; 348, identifier:KeyError; 349, block; 349, 350; 350, try_statement; 350, 351; 350, 362; 351, block; 351, 352; 352, expression_statement; 352, 353; 353, assignment; 353, 354; 353, 355; 354, identifier:similarity; 355, subscript; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:custom_similarity_scores; 359, tuple; 359, 360; 359, 361; 360, identifier:word2; 361, identifier:word1; 362, except_clause; 362, 363; 362, 364; 363, identifier:KeyError; 364, block; 364, 365; 365, if_statement; 365, 366; 365, 369; 365, 374; 366, comparison_operator:==; 366, 367; 366, 368; 367, identifier:word1; 368, identifier:word2; 369, block; 369, 370; 370, return_statement; 370, 371; 371, attribute; 371, 372; 371, 373; 372, identifier:self; 373, identifier:same_word_similarity; 374, else_clause; 374, 375; 375, block; 375, 376; 376, return_statement; 376, 377; 377, integer:0; 378, return_statement; 378, 379; 379, identifier:similarity; 380, return_statement; 380, 381; 381, None | def compute_similarity_score(self, unit1, unit2):
if self.type == "PHONETIC":
word1 = unit1.phonetic_representation
word2 = unit2.phonetic_representation
if self.current_similarity_measure == "phone":
word1_length, word2_length = len(word1), len(word2)
if word1_length > word2_length:
word1, word2 = word2, word1
word1_length, word2_length = word2_length, word1_length
current = range(word1_length + 1)
for i in range(1, word2_length + 1):
previous, current = current, [i] + [0] * word1_length
for j in range(1, word1_length + 1):
add, delete = previous[j] + 1, current[j - 1] + 1
change = previous[j - 1]
if word1[j - 1] != word2[i - 1]:
change += 1
current[j] = min(add, delete, change)
phonetic_similarity_score = 1 - current[word1_length] / word2_length
return phonetic_similarity_score
elif self.current_similarity_measure == "biphone":
if word1[:2] == word2[:2] or word1[-2:] == word2[-2:]:
common_biphone_score = 1
else:
common_biphone_score = 0
return common_biphone_score
elif self.type == "SEMANTIC":
word1 = unit1.text
word2 = unit2.text
if self.current_similarity_measure == "lsa":
w1_vec = self.term_vectors[word1]
w2_vec = self.term_vectors[word2]
dot = sum([w1*w2 for w1,w2 in zip(w1_vec, w2_vec)])
norm1 = sqrt(sum([w*w for w in w1_vec]))
norm2 = sqrt(sum([w*w for w in w2_vec]))
semantic_relatedness_score = dot/(norm1 * norm2)
return semantic_relatedness_score
elif self.current_similarity_measure == "custom":
try:
similarity = self.custom_similarity_scores[(word1,word2)]
except KeyError:
try:
similarity = self.custom_similarity_scores[(word2,word1)]
except KeyError:
if word1 == word2:
return self.same_word_similarity
else:
return 0
return similarity
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:compute_pairwise_similarity_score; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 14; 5, 93; 5, 107; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:pairs; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:all_scores; 13, list:[]; 14, for_statement; 14, 15; 14, 18; 14, 24; 15, pattern_list; 15, 16; 15, 17; 16, identifier:i; 17, identifier:unit; 18, call; 18, 19; 18, 20; 19, identifier:enumerate; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:parsed_response; 24, block; 24, 25; 25, for_statement; 25, 26; 25, 29; 25, 35; 26, pattern_list; 26, 27; 26, 28; 27, identifier:j; 28, identifier:other_unit; 29, call; 29, 30; 29, 31; 30, identifier:enumerate; 31, argument_list; 31, 32; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:parsed_response; 35, block; 35, 36; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:!=; 37, 38; 37, 39; 38, identifier:i; 39, identifier:j; 40, block; 40, 41; 40, 47; 40, 53; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:pair; 44, tuple; 44, 45; 44, 46; 45, identifier:i; 46, identifier:j; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:rev_pair; 50, tuple; 50, 51; 50, 52; 51, identifier:j; 52, identifier:i; 53, if_statement; 53, 54; 53, 61; 54, boolean_operator:and; 54, 55; 54, 58; 55, comparison_operator:not; 55, 56; 55, 57; 56, identifier:pair; 57, identifier:pairs; 58, comparison_operator:not; 58, 59; 58, 60; 59, identifier:rev_pair; 60, identifier:pairs; 61, block; 61, 62; 61, 72; 61, 79; 61, 86; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:score; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:compute_similarity_score; 69, argument_list; 69, 70; 69, 71; 70, identifier:unit; 71, identifier:other_unit; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:pairs; 76, identifier:append; 77, argument_list; 77, 78; 78, identifier:pair; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:pairs; 83, identifier:append; 84, argument_list; 84, 85; 85, identifier:rev_pair; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:all_scores; 90, identifier:append; 91, argument_list; 91, 92; 92, identifier:score; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:all_scores; 96, list_comprehension; 96, 97; 96, 98; 96, 101; 97, identifier:i; 98, for_in_clause; 98, 99; 98, 100; 99, identifier:i; 100, identifier:all_scores; 101, if_clause; 101, 102; 102, comparison_operator:!=; 102, 103; 102, 104; 103, identifier:i; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:same_word_similarity; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 120; 109, subscript; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:measures; 113, binary_operator:+; 113, 114; 113, 119; 114, binary_operator:+; 114, 115; 114, 116; 115, string:"COLLECTION_"; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:current_similarity_measure; 119, string:"_pairwise_similarity_score_mean"; 120, conditional_expression:if; 120, 121; 120, 125; 120, 126; 120, 132; 121, call; 121, 122; 121, 123; 122, identifier:get_mean; 123, argument_list; 123, 124; 124, identifier:all_scores; 125, line_continuation:\; 126, comparison_operator:>; 126, 127; 126, 131; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, identifier:pairs; 131, integer:0; 132, string:'NA' | def compute_pairwise_similarity_score(self):
pairs = []
all_scores = []
for i, unit in enumerate(self.parsed_response):
for j, other_unit in enumerate(self.parsed_response):
if i != j:
pair = (i, j)
rev_pair = (j, i)
if pair not in pairs and rev_pair not in pairs:
score = self.compute_similarity_score(unit, other_unit)
pairs.append(pair)
pairs.append(rev_pair)
all_scores.append(score)
all_scores = [i for i in all_scores if i != self.same_word_similarity]
self.measures["COLLECTION_" + self.current_similarity_measure + "_pairwise_similarity_score_mean"] = get_mean(
all_scores) \
if len(pairs) > 0 else 'NA' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:compute_between_collection_interval_duration; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:prefix; 6, block; 6, 7; 6, 11; 6, 43; 6, 73; 6, 95; 6, 117; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:durations; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 16; 12, identifier:collection; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:collection_list; 16, block; 16, 17; 16, 25; 16, 34; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:start; 20, attribute; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:collection; 23, integer:0; 24, identifier:start_time; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:end; 28, attribute; 28, 29; 28, 33; 29, subscript; 29, 30; 29, 31; 30, identifier:collection; 31, unary_operator:-; 31, 32; 32, integer:1; 33, identifier:end_time; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:durations; 38, identifier:append; 39, argument_list; 39, 40; 40, tuple; 40, 41; 40, 42; 41, identifier:start; 42, identifier:end; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:interstices; 46, list_comprehension; 46, 47; 46, 60; 47, binary_operator:-; 47, 48; 47, 55; 48, subscript; 48, 49; 48, 54; 49, subscript; 49, 50; 49, 51; 50, identifier:durations; 51, binary_operator:+; 51, 52; 51, 53; 52, identifier:i; 53, integer:1; 54, integer:0; 55, subscript; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:durations; 58, identifier:i; 59, integer:1; 60, for_in_clause; 60, 61; 60, 64; 61, pattern_list; 61, 62; 61, 63; 62, identifier:i; 63, identifier:d; 64, call; 64, 65; 64, 66; 65, identifier:enumerate; 66, argument_list; 66, 67; 67, subscript; 67, 68; 67, 69; 68, identifier:durations; 69, slice; 69, 70; 69, 71; 70, colon; 71, unary_operator:-; 71, 72; 72, integer:1; 73, for_statement; 73, 74; 73, 77; 73, 81; 74, pattern_list; 74, 75; 74, 76; 75, identifier:i; 76, identifier:entry; 77, call; 77, 78; 77, 79; 78, identifier:enumerate; 79, argument_list; 79, 80; 80, identifier:interstices; 81, block; 81, 82; 82, if_statement; 82, 83; 82, 88; 83, comparison_operator:<; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:interstices; 86, identifier:i; 87, integer:0; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:interstices; 93, identifier:i; 94, integer:0; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 104; 97, subscript; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:measures; 101, binary_operator:+; 101, 102; 101, 103; 102, identifier:prefix; 103, string:'between_collection_interval_duration_mean'; 104, conditional_expression:if; 104, 105; 104, 109; 104, 110; 104, 116; 105, call; 105, 106; 105, 107; 106, identifier:get_mean; 107, argument_list; 107, 108; 108, identifier:interstices; 109, line_continuation:\; 110, comparison_operator:>; 110, 111; 110, 115; 111, call; 111, 112; 111, 113; 112, identifier:len; 113, argument_list; 113, 114; 114, identifier:interstices; 115, integer:0; 116, string:'NA'; 117, if_statement; 117, 118; 117, 122; 118, not_operator; 118, 119; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:quiet; 122, block; 122, 123; 122, 125; 122, 137; 122, 189; 122, 194; 122, 196; 123, expression_statement; 123, 124; 124, identifier:print; 125, print_statement; 125, 126; 126, binary_operator:+; 126, 127; 126, 136; 127, binary_operator:+; 127, 128; 127, 133; 128, binary_operator:+; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:current_similarity_measure; 132, string:" between-"; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:current_collection_type; 136, string:" durations"; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:table; 140, binary_operator:+; 140, 141; 140, 154; 140, 155; 141, list:[(self.current_collection_type + " 1 (start,end)", "Interval",
self.current_collection_type + " 2 (start,end)")]; 141, 142; 142, tuple; 142, 143; 142, 148; 142, 149; 143, binary_operator:+; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:current_collection_type; 147, string:" 1 (start,end)"; 148, string:"Interval"; 149, binary_operator:+; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:current_collection_type; 153, string:" 2 (start,end)"; 154, line_continuation:\; 155, list_comprehension; 155, 156; 155, 169; 156, tuple; 156, 157; 156, 161; 156, 165; 157, call; 157, 158; 157, 159; 158, identifier:str; 159, argument_list; 159, 160; 160, identifier:d1; 161, call; 161, 162; 161, 163; 162, identifier:str; 163, argument_list; 163, 164; 164, identifier:i1; 165, call; 165, 166; 165, 167; 166, identifier:str; 167, argument_list; 167, 168; 168, identifier:d2; 169, for_in_clause; 169, 170; 169, 174; 170, pattern_list; 170, 171; 170, 172; 170, 173; 171, identifier:d1; 172, identifier:i1; 173, identifier:d2; 174, call; 174, 175; 174, 176; 175, identifier:zip; 176, argument_list; 176, 177; 176, 183; 176, 184; 177, subscript; 177, 178; 177, 179; 178, identifier:durations; 179, slice; 179, 180; 179, 181; 180, colon; 181, unary_operator:-; 181, 182; 182, integer:1; 183, identifier:interstices; 184, subscript; 184, 185; 184, 186; 185, identifier:durations; 186, slice; 186, 187; 186, 188; 187, integer:1; 188, colon; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:print_table; 192, argument_list; 192, 193; 193, identifier:table; 194, expression_statement; 194, 195; 195, identifier:print; 196, print_statement; 196, 197; 196, 210; 196, 211; 197, binary_operator:+; 197, 198; 197, 209; 198, binary_operator:+; 198, 199; 198, 206; 199, binary_operator:+; 199, 200; 199, 205; 200, binary_operator:+; 200, 201; 200, 202; 201, string:"Mean "; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:current_similarity_measure; 205, string:" between-"; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:current_collection_type; 209, string:" duration"; 210, line_continuation:\; 211, subscript; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:measures; 215, binary_operator:+; 215, 216; 215, 217; 216, identifier:prefix; 217, string:'between_collection_interval_duration_mean' | def compute_between_collection_interval_duration(self, prefix):
durations = []
for collection in self.collection_list:
start = collection[0].start_time
end = collection[-1].end_time
durations.append((start, end))
interstices = [durations[i + 1][0] - durations[i][1] for i, d in enumerate(durations[:-1])]
for i, entry in enumerate(interstices):
if interstices[i] < 0:
interstices[i] = 0
self.measures[prefix + 'between_collection_interval_duration_mean'] = get_mean(interstices) \
if len(interstices) > 0 else 'NA'
if not self.quiet:
print
print self.current_similarity_measure + " between-" + self.current_collection_type + " durations"
table = [(self.current_collection_type + " 1 (start,end)", "Interval",
self.current_collection_type + " 2 (start,end)")] + \
[(str(d1), str(i1), str(d2)) for d1, i1, d2 in zip(durations[:-1], interstices, durations[1:])]
print_table(table)
print
print "Mean " + self.current_similarity_measure + " between-" + self.current_collection_type + " duration", \
self.measures[prefix + 'between_collection_interval_duration_mean'] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:compute_within_collection_vowel_duration; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:prefix; 6, default_parameter; 6, 7; 6, 8; 7, identifier:no_singletons; 8, False; 9, block; 9, 10; 9, 27; 9, 31; 9, 87; 9, 109; 10, if_statement; 10, 11; 10, 12; 10, 17; 11, identifier:no_singletons; 12, block; 12, 13; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:min_size; 16, integer:2; 17, else_clause; 17, 18; 18, block; 18, 19; 18, 23; 19, expression_statement; 19, 20; 20, augmented_assignment:+=; 20, 21; 20, 22; 21, identifier:prefix; 22, string:"no_singletons_"; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:min_size; 26, integer:1; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:durations; 30, list:[]; 31, for_statement; 31, 32; 31, 33; 31, 36; 32, identifier:cluster; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:collection_list; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 44; 38, comparison_operator:>=; 38, 39; 38, 43; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, identifier:cluster; 43, identifier:min_size; 44, block; 44, 45; 45, for_statement; 45, 46; 45, 47; 45, 48; 46, identifier:word; 47, identifier:cluster; 48, block; 48, 49; 48, 59; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:word; 52, subscript; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:full_timed_response; 56, attribute; 56, 57; 56, 58; 57, identifier:word; 58, identifier:index_in_timed_response; 59, for_statement; 59, 60; 59, 61; 59, 64; 60, identifier:phone; 61, attribute; 61, 62; 61, 63; 62, identifier:word; 63, identifier:phones; 64, block; 64, 65; 65, if_statement; 65, 66; 65, 73; 66, comparison_operator:in; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:phone; 69, identifier:string; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:vowels; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:durations; 78, identifier:append; 79, argument_list; 79, 80; 80, binary_operator:-; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:phone; 83, identifier:end; 84, attribute; 84, 85; 84, 86; 85, identifier:phone; 86, identifier:start; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 96; 89, subscript; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:measures; 93, binary_operator:+; 93, 94; 93, 95; 94, identifier:prefix; 95, string:'within_collection_vowel_duration_mean'; 96, conditional_expression:if; 96, 97; 96, 101; 96, 102; 96, 108; 97, call; 97, 98; 97, 99; 98, identifier:get_mean; 99, argument_list; 99, 100; 100, identifier:durations; 101, line_continuation:\; 102, comparison_operator:>; 102, 103; 102, 107; 103, call; 103, 104; 103, 105; 104, identifier:len; 105, argument_list; 105, 106; 106, identifier:durations; 107, integer:0; 108, string:'NA'; 109, if_statement; 109, 110; 109, 114; 110, not_operator; 110, 111; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:quiet; 114, block; 114, 115; 115, if_statement; 115, 116; 115, 117; 115, 140; 116, identifier:no_singletons; 117, block; 117, 118; 118, print_statement; 118, 119; 118, 132; 118, 133; 119, binary_operator:+; 119, 120; 119, 131; 120, binary_operator:+; 120, 121; 120, 128; 121, binary_operator:+; 121, 122; 121, 127; 122, binary_operator:+; 122, 123; 122, 124; 123, string:"Mean within-"; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:current_similarity_measure; 127, string:"-"; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:current_collection_type; 131, string:" vowel duration, excluding singletons:"; 132, line_continuation:\; 133, subscript; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:measures; 137, binary_operator:+; 137, 138; 137, 139; 138, identifier:prefix; 139, string:'within_collection_vowel_duration_mean'; 140, else_clause; 140, 141; 141, block; 141, 142; 142, print_statement; 142, 143; 142, 156; 142, 157; 143, binary_operator:+; 143, 144; 143, 155; 144, binary_operator:+; 144, 145; 144, 152; 145, binary_operator:+; 145, 146; 145, 151; 146, binary_operator:+; 146, 147; 146, 148; 147, string:"Mean within-"; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:current_similarity_measure; 151, string:"-"; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:current_collection_type; 155, string:" vowel duration, including singletons:"; 156, line_continuation:\; 157, subscript; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:measures; 161, binary_operator:+; 161, 162; 161, 163; 162, identifier:prefix; 163, string:'within_collection_vowel_duration_mean' | def compute_within_collection_vowel_duration(self, prefix, no_singletons=False):
if no_singletons:
min_size = 2
else:
prefix += "no_singletons_"
min_size = 1
durations = []
for cluster in self.collection_list:
if len(cluster) >= min_size:
for word in cluster:
word = self.full_timed_response[word.index_in_timed_response]
for phone in word.phones:
if phone.string in self.vowels:
durations.append(phone.end - phone.start)
self.measures[prefix + 'within_collection_vowel_duration_mean'] = get_mean(durations) \
if len(durations) > 0 else 'NA'
if not self.quiet:
if no_singletons:
print "Mean within-" + self.current_similarity_measure + "-" + self.current_collection_type + \
" vowel duration, excluding singletons:", \
self.measures[prefix + 'within_collection_vowel_duration_mean']
else:
print "Mean within-" + self.current_similarity_measure + "-" + self.current_collection_type + \
" vowel duration, including singletons:", \
self.measures[prefix + 'within_collection_vowel_duration_mean'] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:print_output; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 32; 5, 181; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:==; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:response_format; 11, string:"csv"; 12, block; 12, 13; 13, for_statement; 13, 14; 13, 15; 13, 18; 14, identifier:key; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:measures; 18, block; 18, 19; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:in; 20, 21; 20, 22; 21, string:"TIMING_"; 22, identifier:key; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 31; 26, subscript; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:measures; 30, identifier:key; 31, string:"NA"; 32, if_statement; 32, 33; 32, 37; 33, not_operator; 33, 34; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:quiet; 37, block; 37, 38; 37, 40; 37, 50; 37, 64; 37, 70; 37, 72; 37, 90; 37, 104; 37, 110; 37, 112; 37, 114; 37, 132; 38, expression_statement; 38, 39; 39, identifier:print; 40, print_statement; 40, 41; 41, binary_operator:+; 41, 42; 41, 49; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:type; 47, identifier:upper; 48, argument_list; 49, string:" RESULTS:"; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:keys; 53, list_comprehension; 53, 54; 53, 55; 53, 60; 54, identifier:e; 55, for_in_clause; 55, 56; 55, 57; 56, identifier:e; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:measures; 60, if_clause; 60, 61; 61, comparison_operator:in; 61, 62; 61, 63; 62, string:'COUNT_'; 63, identifier:e; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:keys; 68, identifier:sort; 69, argument_list; 70, print_statement; 70, 71; 71, string:"Counts:"; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:print_table; 75, argument_list; 75, 76; 76, list_comprehension; 76, 77; 76, 87; 77, tuple; 77, 78; 77, 79; 78, identifier:entry; 79, call; 79, 80; 79, 81; 80, identifier:str; 81, argument_list; 81, 82; 82, subscript; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:measures; 86, identifier:entry; 87, for_in_clause; 87, 88; 87, 89; 88, identifier:entry; 89, identifier:keys; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:keys; 93, list_comprehension; 93, 94; 93, 95; 93, 100; 94, identifier:e; 95, for_in_clause; 95, 96; 95, 97; 96, identifier:e; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:measures; 100, if_clause; 100, 101; 101, comparison_operator:in; 101, 102; 101, 103; 102, string:'COLLECTION_'; 103, identifier:e; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:keys; 108, identifier:sort; 109, argument_list; 110, expression_statement; 110, 111; 111, identifier:print; 112, print_statement; 112, 113; 113, string:"Collection measures:"; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:print_table; 117, argument_list; 117, 118; 118, list_comprehension; 118, 119; 118, 129; 119, tuple; 119, 120; 119, 121; 120, identifier:entry; 121, call; 121, 122; 121, 123; 122, identifier:str; 123, argument_list; 123, 124; 124, subscript; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:measures; 128, identifier:entry; 129, for_in_clause; 129, 130; 129, 131; 130, identifier:entry; 131, identifier:keys; 132, if_statement; 132, 133; 132, 138; 133, comparison_operator:==; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:response_format; 137, string:"TextGrid"; 138, block; 138, 139; 138, 153; 138, 159; 138, 161; 138, 163; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:keys; 142, list_comprehension; 142, 143; 142, 144; 142, 149; 143, identifier:e; 144, for_in_clause; 144, 145; 144, 146; 145, identifier:e; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:measures; 149, if_clause; 149, 150; 150, comparison_operator:in; 150, 151; 150, 152; 151, string:'TIMING_'; 152, identifier:e; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:keys; 157, identifier:sort; 158, argument_list; 159, expression_statement; 159, 160; 160, identifier:print; 161, print_statement; 161, 162; 162, string:"Time-based measures:"; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:print_table; 166, argument_list; 166, 167; 167, list_comprehension; 167, 168; 167, 178; 168, tuple; 168, 169; 168, 170; 169, identifier:entry; 170, call; 170, 171; 170, 172; 171, identifier:str; 172, argument_list; 172, 173; 173, subscript; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:measures; 177, identifier:entry; 178, for_in_clause; 178, 179; 178, 180; 179, identifier:entry; 180, identifier:keys; 181, if_statement; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:target_file; 185, block; 185, 186; 186, with_statement; 186, 187; 186, 199; 187, with_clause; 187, 188; 188, with_item; 188, 189; 189, as_pattern; 189, 190; 189, 197; 190, call; 190, 191; 190, 192; 191, identifier:open; 192, argument_list; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:target_file; 196, string:'w'; 197, as_pattern_target; 197, 198; 198, identifier:outfile; 199, block; 199, 200; 199, 262; 199, 276; 199, 283; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:header; 203, binary_operator:+; 203, 204; 203, 244; 203, 245; 204, binary_operator:+; 204, 205; 204, 226; 204, 227; 205, binary_operator:+; 205, 206; 205, 208; 205, 209; 206, list:['file_id']; 206, 207; 207, string:'file_id'; 208, line_continuation:\; 209, list_comprehension; 209, 210; 209, 217; 209, 222; 210, binary_operator:+; 210, 211; 210, 216; 211, binary_operator:+; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:type; 215, string:"_"; 216, identifier:e; 217, for_in_clause; 217, 218; 217, 219; 218, identifier:e; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:measures; 222, if_clause; 222, 223; 223, comparison_operator:in; 223, 224; 223, 225; 224, string:'COUNT_'; 225, identifier:e; 226, line_continuation:\; 227, list_comprehension; 227, 228; 227, 235; 227, 240; 228, binary_operator:+; 228, 229; 228, 234; 229, binary_operator:+; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:type; 233, string:"_"; 234, identifier:e; 235, for_in_clause; 235, 236; 235, 237; 236, identifier:e; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:measures; 240, if_clause; 240, 241; 241, comparison_operator:in; 241, 242; 241, 243; 242, string:'COLLECTION_'; 243, identifier:e; 244, line_continuation:\; 245, list_comprehension; 245, 246; 245, 253; 245, 258; 246, binary_operator:+; 246, 247; 246, 252; 247, binary_operator:+; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:type; 251, string:"_"; 252, identifier:e; 253, for_in_clause; 253, 254; 253, 255; 254, identifier:e; 255, attribute; 255, 256; 255, 257; 256, identifier:self; 257, identifier:measures; 258, if_clause; 258, 259; 259, comparison_operator:in; 259, 260; 259, 261; 260, string:'TIMING_'; 261, identifier:e; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:writer; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:csv; 268, identifier:writer; 269, argument_list; 269, 270; 269, 271; 270, identifier:outfile; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:quoting; 273, attribute; 273, 274; 273, 275; 274, identifier:csv; 275, identifier:QUOTE_MINIMAL; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:writer; 280, identifier:writerow; 281, argument_list; 281, 282; 282, identifier:header; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:writer; 287, identifier:writerow; 288, argument_list; 288, 289; 289, binary_operator:+; 289, 290; 289, 296; 290, list:[self.measures["file_id"]]; 290, 291; 291, subscript; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:measures; 295, string:"file_id"; 296, list_comprehension; 296, 297; 296, 316; 297, subscript; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:self; 300, identifier:measures; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, string:"_"; 304, identifier:join; 305, argument_list; 305, 306; 306, subscript; 306, 307; 306, 313; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:e; 310, identifier:split; 311, argument_list; 311, 312; 312, string:'_'; 313, slice; 313, 314; 313, 315; 314, integer:1; 315, colon; 316, for_in_clause; 316, 317; 316, 318; 317, identifier:e; 318, subscript; 318, 319; 318, 320; 319, identifier:header; 320, slice; 320, 321; 320, 322; 321, integer:1; 322, colon | def print_output(self):
if self.response_format == "csv":
for key in self.measures:
if "TIMING_" in key:
self.measures[key] = "NA"
if not self.quiet:
print
print self.type.upper() + " RESULTS:"
keys = [e for e in self.measures if 'COUNT_' in e]
keys.sort()
print "Counts:"
print_table([(entry, str(self.measures[entry])) for entry in keys])
keys = [e for e in self.measures if 'COLLECTION_' in e]
keys.sort()
print
print "Collection measures:"
print_table([(entry, str(self.measures[entry])) for entry in keys])
if self.response_format == "TextGrid":
keys = [e for e in self.measures if 'TIMING_' in e]
keys.sort()
print
print "Time-based measures:"
print_table([(entry, str(self.measures[entry])) for entry in keys])
if self.target_file:
with open(self.target_file, 'w') as outfile:
header = ['file_id'] + \
[self.type + "_" + e for e in self.measures if 'COUNT_' in e] + \
[self.type + "_" + e for e in self.measures if 'COLLECTION_' in e] + \
[self.type + "_" + e for e in self.measures if 'TIMING_' in e]
writer = csv.writer(outfile, quoting=csv.QUOTE_MINIMAL)
writer.writerow(header)
writer.writerow([self.measures["file_id"]] +
[self.measures["_".join(e.split('_')[1:])] for e in header[1:]]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_by; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:fieldName; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reverse; 8, False; 9, block; 9, 10; 9, 12; 10, expression_statement; 10, 11; 11, string:'''
sort_by - Return a copy of this collection, sorted by the given fieldName.
The fieldName is accessed the same way as other filtering, so it supports custom properties, etc.
@param fieldName <str> - The name of the field on which to sort by
@param reverse <bool> Default False - If True, list will be in reverse order.
@return <QueryableList> - A QueryableList of the same type with the elements sorted based on arguments.
'''; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:__class__; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 20, 22; 20, 34; 21, identifier:self; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:key; 24, lambda; 24, 25; 24, 27; 25, lambda_parameters; 25, 26; 26, identifier:item; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_get_item_value; 31, argument_list; 31, 32; 31, 33; 32, identifier:item; 33, identifier:fieldName; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:reverse; 36, identifier:reverse | def sort_by(self, fieldName, reverse=False):
'''
sort_by - Return a copy of this collection, sorted by the given fieldName.
The fieldName is accessed the same way as other filtering, so it supports custom properties, etc.
@param fieldName <str> - The name of the field on which to sort by
@param reverse <bool> Default False - If True, list will be in reverse order.
@return <QueryableList> - A QueryableList of the same type with the elements sorted based on arguments.
'''
return self.__class__(
sorted(self, key = lambda item : self._get_item_value(item, fieldName), reverse=reverse)
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_qtls_from_rqtl_data; 3, parameters; 3, 4; 3, 5; 4, identifier:matrix; 5, identifier:lod_threshold; 6, block; 6, 7; 6, 18; 6, 28; 6, 189; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:t_matrix; 10, call; 10, 11; 10, 12; 11, identifier:list; 12, argument_list; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:zip; 15, argument_list; 15, 16; 16, list_splat; 16, 17; 17, identifier:matrix; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:qtls; 21, list:[['Trait', 'Linkage Group', 'Position', 'Exact marker', 'LOD']]; 21, 22; 22, list:['Trait', 'Linkage Group', 'Position', 'Exact marker', 'LOD']; 22, 23; 22, 24; 22, 25; 22, 26; 22, 27; 23, string:'Trait'; 24, string:'Linkage Group'; 25, string:'Position'; 26, string:'Exact marker'; 27, string:'LOD'; 28, for_statement; 28, 29; 28, 30; 28, 35; 29, identifier:row; 30, subscript; 30, 31; 30, 32; 31, identifier:t_matrix; 32, slice; 32, 33; 32, 34; 33, integer:3; 34, colon; 35, block; 35, 36; 35, 40; 35, 44; 35, 48; 35, 52; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:lgroup; 39, None; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:max_lod; 43, None; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:peak; 47, None; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:cnt; 51, integer:1; 52, while_statement; 52, 53; 52, 59; 53, comparison_operator:<; 53, 54; 53, 55; 54, identifier:cnt; 55, call; 55, 56; 55, 57; 56, identifier:len; 57, argument_list; 57, 58; 58, identifier:row; 59, block; 59, 60; 59, 73; 59, 183; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:is; 61, 62; 61, 63; 62, identifier:lgroup; 63, None; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:lgroup; 68, subscript; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:t_matrix; 71, integer:1; 72, identifier:cnt; 73, if_statement; 73, 74; 73, 81; 73, 122; 74, comparison_operator:==; 74, 75; 74, 76; 75, identifier:lgroup; 76, subscript; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:t_matrix; 79, integer:1; 80, identifier:cnt; 81, block; 81, 82; 81, 96; 82, if_statement; 82, 83; 82, 86; 83, comparison_operator:is; 83, 84; 83, 85; 84, identifier:max_lod; 85, None; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:max_lod; 90, call; 90, 91; 90, 92; 91, identifier:float; 92, argument_list; 92, 93; 93, subscript; 93, 94; 93, 95; 94, identifier:row; 95, identifier:cnt; 96, if_statement; 96, 97; 96, 108; 97, comparison_operator:>; 97, 98; 97, 104; 98, call; 98, 99; 98, 100; 99, identifier:float; 100, argument_list; 100, 101; 101, subscript; 101, 102; 101, 103; 102, identifier:row; 103, identifier:cnt; 104, call; 104, 105; 104, 106; 105, identifier:float; 106, argument_list; 106, 107; 107, identifier:max_lod; 108, block; 108, 109; 108, 118; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:max_lod; 112, call; 112, 113; 112, 114; 113, identifier:float; 114, argument_list; 114, 115; 115, subscript; 115, 116; 115, 117; 116, identifier:row; 117, identifier:cnt; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:peak; 121, identifier:cnt; 122, else_clause; 122, 123; 123, block; 123, 124; 123, 171; 123, 175; 123, 179; 124, if_statement; 124, 125; 124, 140; 125, boolean_operator:and; 125, 126; 125, 138; 125, 139; 126, boolean_operator:and; 126, 127; 126, 128; 126, 129; 127, identifier:max_lod; 128, line_continuation:\; 129, comparison_operator:>; 129, 130; 129, 134; 130, call; 130, 131; 130, 132; 131, identifier:float; 132, argument_list; 132, 133; 133, identifier:max_lod; 134, call; 134, 135; 134, 136; 135, identifier:float; 136, argument_list; 136, 137; 137, identifier:lod_threshold; 138, line_continuation:\; 139, identifier:peak; 140, block; 140, 141; 140, 164; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:qtl; 144, list:[row[0],
t_matrix[1][peak],
t_matrix[2][peak],
t_matrix[0][peak],
max_lod,
]; 144, 145; 144, 148; 144, 153; 144, 158; 144, 163; 145, subscript; 145, 146; 145, 147; 146, identifier:row; 147, integer:0; 148, subscript; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:t_matrix; 151, integer:1; 152, identifier:peak; 153, subscript; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:t_matrix; 156, integer:2; 157, identifier:peak; 158, subscript; 158, 159; 158, 162; 159, subscript; 159, 160; 159, 161; 160, identifier:t_matrix; 161, integer:0; 162, identifier:peak; 163, identifier:max_lod; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:qtls; 168, identifier:append; 169, argument_list; 169, 170; 170, identifier:qtl; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:lgroup; 174, None; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:max_lod; 178, None; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:peak; 182, identifier:cnt; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:cnt; 186, binary_operator:+; 186, 187; 186, 188; 187, identifier:cnt; 188, integer:1; 189, return_statement; 189, 190; 190, identifier:qtls | def get_qtls_from_rqtl_data(matrix, lod_threshold):
t_matrix = list(zip(*matrix))
qtls = [['Trait', 'Linkage Group', 'Position', 'Exact marker', 'LOD']]
for row in t_matrix[3:]:
lgroup = None
max_lod = None
peak = None
cnt = 1
while cnt < len(row):
if lgroup is None:
lgroup = t_matrix[1][cnt]
if lgroup == t_matrix[1][cnt]:
if max_lod is None:
max_lod = float(row[cnt])
if float(row[cnt]) > float(max_lod):
max_lod = float(row[cnt])
peak = cnt
else:
if max_lod \
and float(max_lod) > float(lod_threshold) \
and peak:
qtl = [row[0],
t_matrix[1][peak],
t_matrix[2][peak],
t_matrix[0][peak],
max_lod,
]
qtls.append(qtl)
lgroup = None
max_lod = None
peak = cnt
cnt = cnt + 1
return qtls |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:response; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:code; 5, default_parameter; 5, 6; 5, 7; 6, identifier:body; 7, string:''; 8, default_parameter; 8, 9; 8, 10; 9, identifier:etag; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:last_modified; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:expires; 16, None; 17, dictionary_splat_pattern; 17, 18; 18, identifier:kw; 19, block; 19, 20; 19, 53; 19, 67; 19, 99; 19, 128; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:etag; 23, None; 24, block; 24, 25; 24, 47; 25, if_statement; 25, 26; 25, 40; 26, not_operator; 26, 27; 27, parenthesized_expression; 27, 28; 28, boolean_operator:and; 28, 29; 28, 34; 29, comparison_operator:==; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:etag; 32, integer:0; 33, string:'"'; 34, comparison_operator:==; 34, 35; 34, 39; 35, subscript; 35, 36; 35, 37; 36, identifier:etag; 37, unary_operator:-; 37, 38; 38, integer:1; 39, string:'"'; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:etag; 44, binary_operator:%; 44, 45; 44, 46; 45, string:'"%s"'; 46, identifier:etag; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:kw; 51, string:'etag'; 52, identifier:etag; 53, if_statement; 53, 54; 53, 57; 54, comparison_operator:is; 54, 55; 54, 56; 55, identifier:last_modified; 56, None; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 63; 60, subscript; 60, 61; 60, 62; 61, identifier:kw; 62, string:'last_modified'; 63, call; 63, 64; 63, 65; 64, identifier:datetime_to_httpdate; 65, argument_list; 65, 66; 66, identifier:last_modified; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:is; 68, 69; 68, 70; 69, identifier:expires; 70, None; 71, block; 71, 72; 72, if_statement; 72, 73; 72, 78; 72, 88; 73, call; 73, 74; 73, 75; 74, identifier:isinstance; 75, argument_list; 75, 76; 75, 77; 76, identifier:expires; 77, identifier:datetime; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:kw; 83, string:'expires'; 84, call; 84, 85; 84, 86; 85, identifier:datetime_to_httpdate; 86, argument_list; 86, 87; 87, identifier:expires; 88, else_clause; 88, 89; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:kw; 94, string:'expires'; 95, call; 95, 96; 95, 97; 96, identifier:timedelta_to_httpdate; 97, argument_list; 97, 98; 98, identifier:expires; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:headers; 102, list_comprehension; 102, 103; 102, 116; 103, tuple; 103, 104; 103, 115; 104, call; 104, 105; 104, 114; 105, attribute; 105, 106; 105, 113; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:k; 109, identifier:replace; 110, argument_list; 110, 111; 110, 112; 111, string:'_'; 112, string:'-'; 113, identifier:title; 114, argument_list; 115, identifier:v; 116, for_in_clause; 116, 117; 116, 120; 117, pattern_list; 117, 118; 117, 119; 118, identifier:k; 119, identifier:v; 120, call; 120, 121; 120, 122; 121, identifier:sorted; 122, argument_list; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:kw; 126, identifier:items; 127, argument_list; 128, return_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:Response; 131, argument_list; 131, 132; 131, 133; 131, 134; 132, identifier:code; 133, identifier:headers; 134, identifier:body | def response(code, body='', etag=None, last_modified=None, expires=None, **kw):
if etag is not None:
if not (etag[0] == '"' and etag[-1] == '"'):
etag = '"%s"' % etag
kw['etag'] = etag
if last_modified is not None:
kw['last_modified'] = datetime_to_httpdate(last_modified)
if expires is not None:
if isinstance(expires, datetime):
kw['expires'] = datetime_to_httpdate(expires)
else:
kw['expires'] = timedelta_to_httpdate(expires)
headers = [(k.replace('_', '-').title(), v) for k, v in sorted(kw.items())]
return Response(code, headers, body) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:plot_optimum_prediction_fraction_correct_cutoffs_over_range; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, identifier:analysis_set; 6, identifier:min_stability_classication_x_cutoff; 7, identifier:max_stability_classication_x_cutoff; 8, default_parameter; 8, 9; 8, 10; 9, identifier:suppress_plot; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:analysis_file_prefix; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:verbose; 16, True; 17, block; 17, 18; 17, 20; 17, 24; 17, 28; 17, 54; 17, 59; 17, 63; 17, 67; 17, 71; 17, 75; 17, 85; 17, 153; 17, 167; 17, 176; 17, 185; 17, 194; 17, 200; 17, 209; 17, 215; 17, 226; 17, 299; 18, expression_statement; 18, 19; 19, string:'''Plots the optimum cutoff for the predictions to maximize the fraction correct metric over a range of experimental cutoffs.
Returns the average scalar corresponding to the best value of fraction correct over a range of cutoff values for the experimental cutoffs.'''; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:analysis_set_prefix; 23, string:''; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:plot_filename; 27, None; 28, if_statement; 28, 29; 28, 31; 29, not_operator; 29, 30; 30, identifier:suppress_plot; 31, block; 31, 32; 31, 42; 31, 48; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:output_filename_prefix; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:'{0}{1}optimum_fraction_correct_at_varying_kcal_mol'; 38, identifier:format; 39, argument_list; 39, 40; 39, 41; 40, identifier:analysis_file_prefix; 41, identifier:analysis_set_prefix; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:plot_filename; 45, binary_operator:+; 45, 46; 45, 47; 46, identifier:output_filename_prefix; 47, string:'.png'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:csv_filename; 51, binary_operator:+; 51, 52; 51, 53; 52, identifier:output_filename_prefix; 53, string:'.txt'; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:lines; 57, list:['ExperimentalCutoff,BestPredictionCutoff']; 57, 58; 58, string:'ExperimentalCutoff,BestPredictionCutoff'; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:x_cutoff; 62, identifier:min_stability_classication_x_cutoff; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:x_values; 66, list:[]; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:y_values; 70, list:[]; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:avg_scale; 74, integer:0; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:plot_graph; 78, boolean_operator:and; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:generate_plots; 82, not_operator; 82, 83; 83, parenthesized_expression; 83, 84; 84, identifier:suppress_plot; 85, while_statement; 85, 86; 85, 91; 86, comparison_operator:<; 86, 87; 86, 88; 87, identifier:x_cutoff; 88, binary_operator:+; 88, 89; 88, 90; 89, identifier:max_stability_classication_x_cutoff; 90, float:0.1; 91, block; 91, 92; 91, 108; 91, 129; 91, 136; 91, 143; 91, 149; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 98; 94, pattern_list; 94, 95; 94, 96; 94, 97; 95, identifier:max_value_cutoff; 96, identifier:max_value; 97, identifier:fraction_correct_range; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:determine_optimum_fraction_correct_cutoffs; 102, argument_list; 102, 103; 102, 104; 102, 107; 103, identifier:analysis_set; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:dataframe; 107, identifier:x_cutoff; 108, if_statement; 108, 109; 108, 110; 109, identifier:plot_graph; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:lines; 115, identifier:append; 116, argument_list; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, string:','; 120, identifier:join; 121, argument_list; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:map; 124, argument_list; 124, 125; 124, 126; 125, identifier:str; 126, tuple; 126, 127; 126, 128; 127, identifier:x_cutoff; 128, identifier:max_value_cutoff; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:x_values; 133, identifier:append; 134, argument_list; 134, 135; 135, identifier:x_cutoff; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:y_values; 140, identifier:append; 141, argument_list; 141, 142; 142, identifier:max_value_cutoff; 143, expression_statement; 143, 144; 144, augmented_assignment:+=; 144, 145; 144, 146; 145, identifier:avg_scale; 146, binary_operator:/; 146, 147; 146, 148; 147, identifier:max_value_cutoff; 148, identifier:x_cutoff; 149, expression_statement; 149, 150; 150, augmented_assignment:+=; 150, 151; 150, 152; 151, identifier:x_cutoff; 152, float:0.1; 153, if_statement; 153, 154; 153, 155; 154, identifier:plot_graph; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:write_file; 159, argument_list; 159, 160; 159, 161; 160, identifier:csv_filename; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, string:'\n'; 164, identifier:join; 165, argument_list; 165, 166; 166, identifier:lines; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:avg_scale; 170, binary_operator:/; 170, 171; 170, 172; 171, identifier:avg_scale; 172, call; 172, 173; 172, 174; 173, identifier:len; 174, argument_list; 174, 175; 175, identifier:x_values; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:x_values; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:numpy; 182, identifier:array; 183, argument_list; 183, 184; 184, identifier:x_values; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:y_values; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:numpy; 191, identifier:array; 192, argument_list; 192, 193; 193, identifier:y_values; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:scalars; 197, binary_operator:/; 197, 198; 197, 199; 198, identifier:y_values; 199, identifier:x_values; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:average_scalar; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:numpy; 206, identifier:mean; 207, argument_list; 207, 208; 208, identifier:scalars; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:plot_label_1; 212, binary_operator:%; 212, 213; 212, 214; 213, string:'Scalar == %0.2f'; 214, identifier:average_scalar; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:plot_label_2; 218, binary_operator:%; 218, 219; 218, 220; 219, string:'sigma == %0.2f'; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:numpy; 223, identifier:std; 224, argument_list; 224, 225; 225, identifier:scalars; 226, if_statement; 226, 227; 226, 228; 227, identifier:plot_graph; 228, block; 228, 229; 229, if_statement; 229, 230; 229, 246; 230, not_operator; 230, 231; 231, parenthesized_expression; 231, 232; 232, boolean_operator:and; 232, 233; 232, 241; 233, call; 233, 234; 233, 239; 234, attribute; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:os; 237, identifier:path; 238, identifier:exists; 239, argument_list; 239, 240; 240, identifier:plot_filename; 241, not_operator; 241, 242; 242, parenthesized_expression; 242, 243; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:recreate_graphs; 246, block; 246, 247; 246, 268; 246, 272; 246, 284; 246, 288; 247, if_statement; 247, 248; 247, 249; 248, identifier:verbose; 249, block; 249, 250; 249, 259; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:log; 255, argument_list; 255, 256; 256, binary_operator:%; 256, 257; 256, 258; 257, string:'Saving scatterplot to %s.'; 258, identifier:plot_filename; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:self; 263, identifier:log; 264, argument_list; 264, 265; 265, binary_operator:%; 265, 266; 265, 267; 266, string:'Saving plot of approximate optimal fraction correct cutoffs over varying experimental cutoffs to %s.'; 267, identifier:plot_filename; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:title; 271, string:'Optimum cutoff for fraction correct metric at varying experimental cutoffs'; 272, if_statement; 272, 273; 272, 274; 273, identifier:analysis_set; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, augmented_assignment:+=; 276, 277; 276, 278; 277, identifier:title; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, string:' for {0}'; 281, identifier:format; 282, argument_list; 282, 283; 283, identifier:analysis_set; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:r_script; 287, string:'''library(ggplot2)
library(gridExtra)
library(scales)
library(qualV)
png('%(plot_filename)s', height=4096, width=4096, bg="white", res=600)
plot_data <- read.csv('%(csv_filename)s', header=T)
max_y = max(plot_data$BestPredictionCutoff)
p <- ggplot(data = plot_data, aes(x = ExperimentalCutoff, y = BestPredictionCutoff)) +
xlab("Experimental cutoff (kcal/mol)") +
ylab("Optimal prediction cutoff (energy units)") +
ggtitle("%(title)s") +
geom_point() +
geom_line() +
geom_smooth() +
geom_text(hjust=0, size=4, color="black", aes(0.5, max_y, fontface="plain", family = "sans", label="%(plot_label_1)s"), parse = T) +
geom_text(hjust=0, size=4, color="black", aes(0.5, max_y - 0.5, fontface="plain", family = "sans", label="%(plot_label_2)s"), parse = T)
p
dev.off()'''; 288, expression_statement; 288, 289; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:RInterface; 292, identifier:_runRScript; 293, argument_list; 293, 294; 294, binary_operator:%; 294, 295; 294, 296; 295, identifier:r_script; 296, call; 296, 297; 296, 298; 297, identifier:locals; 298, argument_list; 299, return_statement; 299, 300; 300, expression_list; 300, 301; 300, 302; 301, identifier:average_scalar; 302, identifier:plot_filename | def plot_optimum_prediction_fraction_correct_cutoffs_over_range(self, analysis_set, min_stability_classication_x_cutoff, max_stability_classication_x_cutoff, suppress_plot = False, analysis_file_prefix = None, verbose = True):
'''Plots the optimum cutoff for the predictions to maximize the fraction correct metric over a range of experimental cutoffs.
Returns the average scalar corresponding to the best value of fraction correct over a range of cutoff values for the experimental cutoffs.'''
analysis_set_prefix = ''
plot_filename = None
if not suppress_plot:
output_filename_prefix = '{0}{1}optimum_fraction_correct_at_varying_kcal_mol'.format(analysis_file_prefix, analysis_set_prefix)
plot_filename = output_filename_prefix + '.png'
csv_filename = output_filename_prefix + '.txt'
lines = ['ExperimentalCutoff,BestPredictionCutoff']
x_cutoff = min_stability_classication_x_cutoff
x_values = []
y_values = []
avg_scale = 0
plot_graph = self.generate_plots and not(suppress_plot)
while x_cutoff < max_stability_classication_x_cutoff + 0.1:
max_value_cutoff, max_value, fraction_correct_range = self.determine_optimum_fraction_correct_cutoffs(analysis_set, self.dataframe, x_cutoff)
if plot_graph:
lines.append(','.join(map(str, (x_cutoff, max_value_cutoff))))
x_values.append(x_cutoff)
y_values.append(max_value_cutoff)
avg_scale += max_value_cutoff / x_cutoff
x_cutoff += 0.1
if plot_graph:
write_file(csv_filename, '\n'.join(lines))
avg_scale = avg_scale / len(x_values)
x_values = numpy.array(x_values)
y_values = numpy.array(y_values)
scalars = y_values / x_values
average_scalar = numpy.mean(scalars)
plot_label_1 = 'Scalar == %0.2f' % average_scalar
plot_label_2 = 'sigma == %0.2f' % numpy.std(scalars)
if plot_graph:
if not(os.path.exists(plot_filename) and not(self.recreate_graphs)):
if verbose:
self.log('Saving scatterplot to %s.' % plot_filename)
self.log('Saving plot of approximate optimal fraction correct cutoffs over varying experimental cutoffs to %s.' % plot_filename)
title = 'Optimum cutoff for fraction correct metric at varying experimental cutoffs'
if analysis_set:
title += ' for {0}'.format(analysis_set)
r_script = '''library(ggplot2)
library(gridExtra)
library(scales)
library(qualV)
png('%(plot_filename)s', height=4096, width=4096, bg="white", res=600)
plot_data <- read.csv('%(csv_filename)s', header=T)
max_y = max(plot_data$BestPredictionCutoff)
p <- ggplot(data = plot_data, aes(x = ExperimentalCutoff, y = BestPredictionCutoff)) +
xlab("Experimental cutoff (kcal/mol)") +
ylab("Optimal prediction cutoff (energy units)") +
ggtitle("%(title)s") +
geom_point() +
geom_line() +
geom_smooth() +
geom_text(hjust=0, size=4, color="black", aes(0.5, max_y, fontface="plain", family = "sans", label="%(plot_label_1)s"), parse = T) +
geom_text(hjust=0, size=4, color="black", aes(0.5, max_y - 0.5, fontface="plain", family = "sans", label="%(plot_label_2)s"), parse = T)
p
dev.off()'''
RInterface._runRScript(r_script % locals())
return average_scalar, plot_filename |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_chain_details_by_related_pdb_chains; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:pdb_id; 6, identifier:chain_id; 7, identifier:pfam_accs; 8, block; 8, 9; 8, 11; 8, 17; 8, 23; 8, 31; 8, 49; 8, 53; 8, 57; 8, 122; 8, 142; 8, 165; 8, 169; 8, 174; 8, 179; 8, 189; 8, 223; 8, 233; 8, 239; 8, 249; 8, 261; 8, 279; 8, 300; 8, 315; 9, expression_statement; 9, 10; 10, string:''' Returns a dict of SCOPe details using info
This returns Pfam-level information for a PDB chain i.e. no details on the protein, species, or domain will be returned.
If there are SCOPe entries for the associated Pfam accession numbers which agree then this function returns
pretty complete information.
'''; 11, if_statement; 11, 12; 11, 14; 12, not_operator; 12, 13; 13, identifier:pfam_accs; 14, block; 14, 15; 15, return_statement; 15, 16; 16, None; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:associated_pdb_chains; 20, call; 20, 21; 20, 22; 21, identifier:set; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:pfam_api; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:get_pfam_api; 30, argument_list; 31, for_statement; 31, 32; 31, 33; 31, 34; 32, identifier:pfam_acc; 33, identifier:pfam_accs; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:associated_pdb_chains; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:associated_pdb_chains; 41, identifier:union; 42, argument_list; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:pfam_api; 46, identifier:get_pdb_chains_from_pfam_accession_number; 47, argument_list; 47, 48; 48, identifier:pfam_acc; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:hits; 52, list:[]; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:pfam_scop_mapping; 56, dictionary; 57, for_statement; 57, 58; 57, 59; 57, 60; 58, identifier:pdb_chain_pair; 59, identifier:associated_pdb_chains; 60, block; 60, 61; 60, 73; 60, 91; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, pattern_list; 63, 64; 63, 65; 64, identifier:ass_pdb_id; 65, identifier:ass_chain_id; 66, expression_list; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:pdb_chain_pair; 69, integer:0; 70, subscript; 70, 71; 70, 72; 71, identifier:pdb_chain_pair; 72, integer:1; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:hit; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:get_chain_details; 80, argument_list; 80, 81; 80, 82; 80, 85; 80, 88; 81, identifier:ass_pdb_id; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:chain; 84, identifier:ass_chain_id; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:internal_function_call; 87, True; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:pfam_scop_mapping; 90, identifier:pfam_scop_mapping; 91, if_statement; 91, 92; 91, 100; 92, boolean_operator:and; 92, 93; 92, 94; 93, identifier:hit; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:hit; 97, identifier:get; 98, argument_list; 98, 99; 99, string:'chains'; 100, block; 100, 101; 100, 111; 101, assert_statement; 101, 102; 102, parenthesized_expression; 102, 103; 103, comparison_operator:==; 103, 104; 103, 110; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, subscript; 107, 108; 107, 109; 108, identifier:hit; 109, string:'chains'; 110, integer:1; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:hits; 115, identifier:append; 116, argument_list; 116, 117; 117, subscript; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:hit; 120, string:'chains'; 121, identifier:ass_chain_id; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:allowed_scop_domains; 125, call; 125, 126; 125, 127; 126, identifier:map; 127, argument_list; 127, 128; 127, 129; 128, identifier:int; 129, subscript; 129, 130; 129, 141; 130, call; 130, 131; 130, 132; 131, identifier:map; 132, argument_list; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:set; 135, identifier:intersection; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:pfam_scop_mapping; 139, identifier:values; 140, argument_list; 141, integer:0; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:allowed_scop_domains; 145, call; 145, 146; 145, 147; 146, identifier:list; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 150; 149, identifier:set; 150, argument_list; 150, 151; 151, binary_operator:+; 151, 152; 151, 156; 152, parenthesized_expression; 152, 153; 153, boolean_operator:or; 153, 154; 153, 155; 154, identifier:allowed_scop_domains; 155, list:[]; 156, parenthesized_expression; 156, 157; 157, boolean_operator:or; 157, 158; 157, 164; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:get_sunid_for_pfam_accs; 162, argument_list; 162, 163; 163, identifier:pfam_accs; 164, list:[]; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:filtered_hits; 168, list:[]; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 172; 171, identifier:print; 172, argument_list; 172, 173; 173, identifier:pfam_accs; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 177; 176, identifier:print; 177, argument_list; 177, 178; 178, identifier:allowed_scop_domains; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:print; 182, argument_list; 182, 183; 183, binary_operator:%; 183, 184; 183, 185; 184, string:'%d hits'; 185, call; 185, 186; 185, 187; 186, identifier:len; 187, argument_list; 187, 188; 188, identifier:hits; 189, for_statement; 189, 190; 189, 191; 189, 192; 190, identifier:hit; 191, identifier:hits; 192, block; 192, 193; 192, 197; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:domains_to_ignore; 196, list:[]; 197, for_statement; 197, 198; 197, 201; 197, 208; 198, pattern_list; 198, 199; 198, 200; 199, identifier:k; 200, identifier:v; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:hit; 205, string:'domains'; 206, identifier:iteritems; 207, argument_list; 208, block; 208, 209; 209, if_statement; 209, 210; 209, 215; 210, comparison_operator:in; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:v; 213, string:'sunid'; 214, identifier:allowed_scop_domains; 215, block; 215, 216; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:filtered_hits; 220, identifier:append; 221, argument_list; 221, 222; 222, identifier:v; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 226; 225, identifier:print; 226, argument_list; 226, 227; 227, binary_operator:%; 227, 228; 227, 229; 228, string:'%d filtered_hits'; 229, call; 229, 230; 229, 231; 230, identifier:len; 231, argument_list; 231, 232; 232, identifier:filtered_hits; 233, if_statement; 233, 234; 233, 236; 234, not_operator; 234, 235; 235, identifier:filtered_hits; 236, block; 236, 237; 237, return_statement; 237, 238; 238, None; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:d; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:get_basic_pdb_chain_information; 246, argument_list; 246, 247; 246, 248; 247, identifier:pdb_id; 248, identifier:chain_id; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:d; 253, identifier:update; 254, argument_list; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:get_common_fields; 259, argument_list; 259, 260; 260, identifier:filtered_hits; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:d; 265, identifier:update; 266, argument_list; 266, 267; 267, call; 267, 268; 267, 269; 268, identifier:dict; 269, argument_list; 269, 270; 269, 273; 269, 276; 270, keyword_argument; 270, 271; 270, 272; 271, identifier:SCOPe_sources; 272, string:'Pfam + SCOPe'; 273, keyword_argument; 273, 274; 273, 275; 274, identifier:SCOPe_search_fields; 275, string:'Pfam + link_pdb.pdb_chain_id'; 276, keyword_argument; 276, 277; 276, 278; 277, identifier:SCOPe_trust_level; 278, integer:3; 279, for_statement; 279, 280; 279, 283; 279, 293; 280, pattern_list; 280, 281; 280, 282; 281, identifier:k; 282, identifier:v; 283, call; 283, 284; 283, 285; 284, identifier:sorted; 285, argument_list; 285, 286; 286, call; 286, 287; 286, 292; 287, attribute; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:self; 290, identifier:levels; 291, identifier:iteritems; 292, argument_list; 293, block; 293, 294; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 299; 296, subscript; 296, 297; 296, 298; 297, identifier:d; 298, identifier:v; 299, None; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:d; 304, identifier:update; 305, argument_list; 305, 306; 306, call; 306, 307; 306, 308; 307, identifier:dict; 308, argument_list; 308, 309; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:self; 312, identifier:get_common_hierarchy; 313, argument_list; 313, 314; 314, identifier:filtered_hits; 315, return_statement; 315, 316; 316, identifier:d | def get_chain_details_by_related_pdb_chains(self, pdb_id, chain_id, pfam_accs):
''' Returns a dict of SCOPe details using info
This returns Pfam-level information for a PDB chain i.e. no details on the protein, species, or domain will be returned.
If there are SCOPe entries for the associated Pfam accession numbers which agree then this function returns
pretty complete information.
'''
if not pfam_accs:
return None
associated_pdb_chains = set()
pfam_api = self.get_pfam_api()
for pfam_acc in pfam_accs:
associated_pdb_chains = associated_pdb_chains.union(pfam_api.get_pdb_chains_from_pfam_accession_number(pfam_acc))
hits = []
pfam_scop_mapping = {}
for pdb_chain_pair in associated_pdb_chains:
ass_pdb_id, ass_chain_id = pdb_chain_pair[0], pdb_chain_pair[1]
hit = self.get_chain_details(ass_pdb_id, chain = ass_chain_id, internal_function_call = True, pfam_scop_mapping = pfam_scop_mapping)
if hit and hit.get('chains'):
assert(len(hit['chains']) == 1)
hits.append(hit['chains'][ass_chain_id])
allowed_scop_domains = map(int, map(set.intersection, pfam_scop_mapping.values())[0])
allowed_scop_domains = list(set((allowed_scop_domains or []) + (self.get_sunid_for_pfam_accs(pfam_accs) or [])))
filtered_hits = []
print(pfam_accs)
print(allowed_scop_domains)
print('%d hits' % len(hits))
for hit in hits:
domains_to_ignore = []
for k, v in hit['domains'].iteritems():
if v['sunid'] in allowed_scop_domains:
filtered_hits.append(v)
print('%d filtered_hits' % len(filtered_hits))
if not filtered_hits:
return None
d = self.get_basic_pdb_chain_information(pdb_id, chain_id)
d.update(self.get_common_fields(filtered_hits))
d.update(dict(
SCOPe_sources = 'Pfam + SCOPe',
SCOPe_search_fields = 'Pfam + link_pdb.pdb_chain_id',
SCOPe_trust_level = 3
))
for k, v in sorted(self.levels.iteritems()):
d[v] = None
d.update(dict(self.get_common_hierarchy(filtered_hits)))
return d |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:recall_service; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:service; 6, block; 6, 7; 6, 20; 6, 41; 6, 211; 7, if_statement; 7, 8; 7, 14; 8, not_operator; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 13; 12, identifier:service; 13, identifier:Service; 14, block; 14, 15; 15, raise_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:TypeError; 18, argument_list; 18, 19; 19, string:"service must be of type Service."; 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, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, string:"The deployment for {0} on {1} failed starting the rollback."; 29, identifier:format; 30, argument_list; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:service; 33, identifier:alias; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:url; 39, identifier:geturl; 40, argument_list; 41, function_definition; 41, 42; 41, 43; 41, 45; 42, function_name:anonymous; 43, parameters; 43, 44; 44, identifier:anonymous_service; 45, block; 45, 46; 45, 59; 45, 68; 46, if_statement; 46, 47; 46, 53; 47, not_operator; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:isinstance; 50, argument_list; 50, 51; 50, 52; 51, identifier:anonymous_service; 52, identifier:Service; 53, block; 53, 54; 54, raise_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:TypeError; 57, argument_list; 57, 58; 58, string:"service must be an instance of Service."; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:containers; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:find_previous_service_containers; 66, argument_list; 66, 67; 67, identifier:anonymous_service; 68, if_statement; 68, 69; 68, 70; 69, identifier:containers; 70, block; 70, 71; 70, 90; 70, 98; 71, for_statement; 71, 72; 71, 73; 71, 83; 72, identifier:name; 73, call; 73, 74; 73, 75; 74, identifier:list; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:anonymous_service; 80, identifier:containers; 81, identifier:keys; 82, argument_list; 83, block; 83, 84; 84, delete_statement; 84, 85; 85, subscript; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:anonymous_service; 88, identifier:containers; 89, identifier:name; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:anonymous_service; 95, identifier:cargo; 96, identifier:delete; 97, argument_list; 98, for_statement; 98, 99; 98, 102; 98, 108; 99, pattern_list; 99, 100; 99, 101; 100, identifier:name; 101, identifier:container; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:six; 105, identifier:iteritems; 106, argument_list; 106, 107; 107, identifier:containers; 108, block; 108, 109; 109, if_statement; 109, 110; 109, 120; 109, 139; 110, call; 110, 111; 110, 118; 111, attribute; 111, 112; 111, 117; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:container; 115, identifier:state; 116, argument_list; 117, identifier:get; 118, argument_list; 118, 119; 119, string:'running'; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:logger; 125, identifier:info; 126, argument_list; 126, 127; 126, 128; 127, string:"is already running... Might want to investigate."; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:extra; 130, dictionary; 130, 131; 130, 134; 131, pair; 131, 132; 131, 133; 132, string:'formatter'; 133, string:'container'; 134, pair; 134, 135; 134, 136; 135, string:'container'; 136, attribute; 136, 137; 136, 138; 137, identifier:container; 138, identifier:name; 139, else_clause; 139, 140; 140, block; 140, 141; 141, if_statement; 141, 142; 141, 147; 141, 166; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:container; 145, identifier:start; 146, argument_list; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:logger; 152, identifier:info; 153, argument_list; 153, 154; 153, 155; 154, string:"is restarted and healthy."; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:extra; 157, dictionary; 157, 158; 157, 161; 158, pair; 158, 159; 158, 160; 159, string:'formatter'; 160, string:'container'; 161, pair; 161, 162; 161, 163; 162, string:'container'; 163, attribute; 163, 164; 163, 165; 164, identifier:container; 165, identifier:name; 166, else_clause; 166, 167; 167, block; 167, 168; 167, 186; 167, 192; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:logger; 172, identifier:error; 173, argument_list; 173, 174; 173, 175; 174, string:"failed to start."; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:extra; 177, dictionary; 177, 178; 177, 181; 178, pair; 178, 179; 178, 180; 179, string:'formatter'; 180, string:'container'; 181, pair; 181, 182; 181, 183; 182, string:'container'; 183, attribute; 183, 184; 183, 185; 184, identifier:container; 185, identifier:name; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:container; 190, identifier:dump_logs; 191, argument_list; 192, raise_statement; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:Exception; 195, argument_list; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, string:"The deployment for {0} on {1} went horribly wrong"; 199, identifier:format; 200, argument_list; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:container; 203, identifier:name; 204, call; 204, 205; 204, 210; 205, attribute; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:url; 209, identifier:geturl; 210, argument_list; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:_service_map; 216, argument_list; 216, 217; 216, 218; 216, 219; 217, identifier:service; 218, identifier:anonymous; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:descending; 221, False | def recall_service(self, service):
if not isinstance(service, Service):
raise TypeError("service must be of type Service.")
logger.warning("The deployment for {0} on {1} failed starting the rollback.".format(service.alias, self.url.geturl()))
def anonymous(anonymous_service):
if not isinstance(anonymous_service, Service):
raise TypeError("service must be an instance of Service.")
containers = self.find_previous_service_containers(anonymous_service)
if containers:
for name in list(anonymous_service.containers.keys()):
del anonymous_service.containers[name]
anonymous_service.cargo.delete()
for name, container in six.iteritems(containers):
if container.state().get('running'):
logger.info(
"is already running... Might want to investigate.",
extra={'formatter': 'container', 'container': container.name}
)
else:
if container.start():
logger.info(
"is restarted and healthy.",
extra={'formatter': 'container', 'container': container.name}
)
else:
logger.error(
"failed to start.",
extra={'formatter': 'container', 'container': container.name}
)
container.dump_logs()
raise Exception(
"The deployment for {0} on {1} went horribly wrong".format(container.name, self.url.geturl())
)
self._service_map(service, anonymous, descending=False) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sorted_items; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:d; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key; 7, identifier:__identity; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, block; 11, 12; 11, 24; 12, function_definition; 12, 13; 12, 14; 12, 16; 13, function_name:pairkey_key; 14, parameters; 14, 15; 15, identifier:item; 16, block; 16, 17; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:key; 20, argument_list; 20, 21; 21, subscript; 21, 22; 21, 23; 22, identifier:item; 23, integer:0; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 27, 33; 27, 36; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:d; 31, identifier:items; 32, argument_list; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:key; 35, identifier:pairkey_key; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:reverse; 38, identifier:reverse | def sorted_items(d, key=__identity, reverse=False):
def pairkey_key(item):
return key(item[0])
return sorted(d.items(), key=pairkey_key, reverse=reverse) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:get_or_create_in_transaction; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 4, identifier:tsession; 5, identifier:model; 6, identifier:values; 7, default_parameter; 7, 8; 7, 9; 8, identifier:missing_columns; 9, list:[]; 10, default_parameter; 10, 11; 10, 12; 11, identifier:variable_columns; 12, list:[]; 13, default_parameter; 13, 14; 13, 15; 14, identifier:updatable_columns; 15, list:[]; 16, default_parameter; 16, 17; 16, 18; 17, identifier:only_use_supplied_columns; 18, False; 19, default_parameter; 19, 20; 19, 21; 20, identifier:read_only; 21, False; 22, block; 22, 23; 22, 25; 22, 34; 22, 52; 22, 63; 22, 74; 22, 90; 22, 178; 22, 182; 22, 213; 22, 228; 22, 242; 22, 250; 23, expression_statement; 23, 24; 24, string:'''
Uses the SQLAlchemy model to retrieve an existing record based on the supplied field values or, if there is no
existing record, to create a new database record.
:param tsession: An SQLAlchemy transactioned session
:param model: The name of the SQLAlchemy class representing the table
:param values: A dict of values which will be used to populate the fields of the model
:param missing_columns: Elements of missing_columns are expected to be fields in the model but are left blank regardless of whether they exist in values. This is useful for auto_increment fields.
:param updatable_columns: If these are specified, they are treated as missing columns in the record matching and if a record is found, these fields will be updated
:param variable_columns: If these are specified, they are treated as missing columns in the record matching but are not updated. A good use of these are for datetime fields which default to the current datetime
:param read_only: If this is set then we query the database and return an instance if one exists but we do not create a new record.
:return:
Note: This function is a convenience function and is NOT efficient. The "tsession.query(model).filter_by(**pruned_values)"
call is only (sometimes) efficient if an index exists on the keys of pruned_values. If any of the fields of pruned_values are
large (even if otherwise deferred/loaded lazily) then you will incur a performance hit on lookup. You may need
to reconsider any calls to this function in inner loops of your code.'''; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:values; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:copy; 31, identifier:deepcopy; 32, argument_list; 32, 33; 33, identifier:values; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:fieldnames; 37, list_comprehension; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:c; 40, identifier:name; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:c; 43, call; 43, 44; 43, 45; 44, identifier:list; 45, argument_list; 45, 46; 46, attribute; 46, 47; 46, 51; 47, call; 47, 48; 47, 49; 48, identifier:sqlalchemy_inspect; 49, argument_list; 49, 50; 50, identifier:model; 51, identifier:columns; 52, for_statement; 52, 53; 52, 54; 52, 55; 53, identifier:c; 54, identifier:missing_columns; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:fieldnames; 60, identifier:remove; 61, argument_list; 61, 62; 62, identifier:c; 63, for_statement; 63, 64; 63, 65; 63, 66; 64, identifier:c; 65, identifier:updatable_columns; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:fieldnames; 71, identifier:remove; 72, argument_list; 72, 73; 73, identifier:c; 74, for_statement; 74, 75; 74, 76; 74, 77; 75, identifier:c; 76, identifier:variable_columns; 77, block; 77, 78; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:in; 79, 80; 79, 81; 80, identifier:c; 81, identifier:fieldnames; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:fieldnames; 87, identifier:remove; 88, argument_list; 88, 89; 89, identifier:c; 90, if_statement; 90, 91; 90, 92; 90, 115; 91, identifier:only_use_supplied_columns; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:fieldnames; 96, call; 96, 97; 96, 98; 97, identifier:sorted; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 106; 100, attribute; 100, 101; 100, 105; 101, call; 101, 102; 101, 103; 102, identifier:set; 103, argument_list; 103, 104; 104, identifier:fieldnames; 105, identifier:intersection; 106, argument_list; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:set; 109, argument_list; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:values; 113, identifier:keys; 114, argument_list; 115, else_clause; 115, 116; 116, block; 116, 117; 116, 152; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:unexpected_fields; 120, call; 120, 121; 120, 147; 121, attribute; 121, 122; 121, 146; 122, call; 122, 123; 122, 141; 123, attribute; 123, 124; 123, 140; 124, call; 124, 125; 124, 135; 125, attribute; 125, 126; 125, 134; 126, call; 126, 127; 126, 128; 127, identifier:set; 128, argument_list; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:values; 132, identifier:keys; 133, argument_list; 134, identifier:difference; 135, argument_list; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:set; 138, argument_list; 138, 139; 139, identifier:fieldnames; 140, identifier:difference; 141, argument_list; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:set; 144, argument_list; 144, 145; 145, identifier:variable_columns; 146, identifier:difference; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 150; 149, identifier:set; 150, argument_list; 150, 151; 151, identifier:updatable_columns; 152, if_statement; 152, 153; 152, 154; 153, identifier:unexpected_fields; 154, block; 154, 155; 155, raise_statement; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:Exception; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, string:"The fields '{0}' were passed but not found in the schema for table {1}."; 162, identifier:format; 163, argument_list; 163, 164; 163, 173; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, string:"', '"; 167, identifier:join; 168, argument_list; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:sorted; 171, argument_list; 171, 172; 172, identifier:unexpected_fields; 173, subscript; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:model; 176, identifier:__dict__; 177, string:'__tablename__'; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:pruned_values; 181, dictionary; 182, for_statement; 182, 183; 182, 184; 182, 200; 183, identifier:k; 184, call; 184, 185; 184, 195; 185, attribute; 185, 186; 185, 194; 186, call; 186, 187; 186, 188; 187, identifier:set; 188, argument_list; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:values; 192, identifier:keys; 193, argument_list; 194, identifier:intersection; 195, argument_list; 195, 196; 196, call; 196, 197; 196, 198; 197, identifier:set; 198, argument_list; 198, 199; 199, identifier:fieldnames; 200, block; 200, 201; 200, 207; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:v; 204, subscript; 204, 205; 204, 206; 205, identifier:values; 206, identifier:k; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:pruned_values; 211, identifier:k; 212, identifier:v; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:instance; 216, call; 216, 217; 216, 225; 217, attribute; 217, 218; 217, 224; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:tsession; 221, identifier:query; 222, argument_list; 222, 223; 223, identifier:model; 224, identifier:filter_by; 225, argument_list; 225, 226; 226, dictionary_splat; 226, 227; 227, identifier:pruned_values; 228, if_statement; 228, 229; 228, 236; 229, comparison_operator:>; 229, 230; 229, 235; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:instance; 233, identifier:count; 234, argument_list; 235, integer:1; 236, block; 236, 237; 237, raise_statement; 237, 238; 238, call; 238, 239; 238, 240; 239, identifier:Exception; 240, argument_list; 240, 241; 241, string:'Multiple records were found with the search criteria.'; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:instance; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:instance; 248, identifier:first; 249, argument_list; 250, if_statement; 250, 251; 250, 252; 250, 279; 251, identifier:instance; 252, block; 252, 253; 252, 277; 253, if_statement; 253, 254; 253, 257; 254, comparison_operator:==; 254, 255; 254, 256; 255, identifier:read_only; 256, False; 257, block; 257, 258; 257, 271; 258, for_statement; 258, 259; 258, 260; 258, 261; 259, identifier:c; 260, identifier:updatable_columns; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 265; 264, identifier:setattr; 265, argument_list; 265, 266; 265, 267; 265, 268; 266, identifier:instance; 267, identifier:c; 268, subscript; 268, 269; 268, 270; 269, identifier:values; 270, identifier:c; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:tsession; 275, identifier:flush; 276, argument_list; 277, return_statement; 277, 278; 278, identifier:instance; 279, else_clause; 279, 280; 280, block; 280, 281; 280, 346; 281, if_statement; 281, 282; 281, 285; 282, comparison_operator:==; 282, 283; 282, 284; 283, identifier:read_only; 284, False; 285, block; 285, 286; 285, 323; 285, 331; 285, 338; 285, 344; 286, if_statement; 286, 287; 286, 300; 287, comparison_operator:!=; 287, 288; 287, 296; 288, call; 288, 289; 288, 290; 289, identifier:sorted; 290, argument_list; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:pruned_values; 294, identifier:keys; 295, argument_list; 296, call; 296, 297; 296, 298; 297, identifier:sorted; 298, argument_list; 298, 299; 299, identifier:fieldnames; 300, block; 300, 301; 301, raise_statement; 301, 302; 302, call; 302, 303; 302, 304; 303, identifier:Exception; 304, argument_list; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, string:'Some required fields are missing: {0}. Either supply these fields or add them to the missing_columns list.'; 308, identifier:format; 309, argument_list; 309, 310; 310, call; 310, 311; 310, 317; 311, attribute; 311, 312; 311, 316; 312, call; 312, 313; 312, 314; 313, identifier:set; 314, argument_list; 314, 315; 315, identifier:fieldnames; 316, identifier:difference; 317, argument_list; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:pruned_values; 321, identifier:keys; 322, argument_list; 323, expression_statement; 323, 324; 324, assignment; 324, 325; 324, 326; 325, identifier:instance; 326, call; 326, 327; 326, 328; 327, identifier:model; 328, argument_list; 328, 329; 329, dictionary_splat; 329, 330; 330, identifier:pruned_values; 331, expression_statement; 331, 332; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:tsession; 335, identifier:add; 336, argument_list; 336, 337; 337, identifier:instance; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:tsession; 342, identifier:flush; 343, argument_list; 344, return_statement; 344, 345; 345, identifier:instance; 346, return_statement; 346, 347; 347, None | def get_or_create_in_transaction(tsession, model, values, missing_columns = [], variable_columns = [], updatable_columns = [], only_use_supplied_columns = False, read_only = False):
'''
Uses the SQLAlchemy model to retrieve an existing record based on the supplied field values or, if there is no
existing record, to create a new database record.
:param tsession: An SQLAlchemy transactioned session
:param model: The name of the SQLAlchemy class representing the table
:param values: A dict of values which will be used to populate the fields of the model
:param missing_columns: Elements of missing_columns are expected to be fields in the model but are left blank regardless of whether they exist in values. This is useful for auto_increment fields.
:param updatable_columns: If these are specified, they are treated as missing columns in the record matching and if a record is found, these fields will be updated
:param variable_columns: If these are specified, they are treated as missing columns in the record matching but are not updated. A good use of these are for datetime fields which default to the current datetime
:param read_only: If this is set then we query the database and return an instance if one exists but we do not create a new record.
:return:
Note: This function is a convenience function and is NOT efficient. The "tsession.query(model).filter_by(**pruned_values)"
call is only (sometimes) efficient if an index exists on the keys of pruned_values. If any of the fields of pruned_values are
large (even if otherwise deferred/loaded lazily) then you will incur a performance hit on lookup. You may need
to reconsider any calls to this function in inner loops of your code.'''
values = copy.deepcopy(values)
fieldnames = [c.name for c in list(sqlalchemy_inspect(model).columns)]
for c in missing_columns:
fieldnames.remove(c)
for c in updatable_columns:
fieldnames.remove(c)
for c in variable_columns:
if c in fieldnames:
fieldnames.remove(c)
if only_use_supplied_columns:
fieldnames = sorted(set(fieldnames).intersection(set(values.keys())))
else:
unexpected_fields = set(values.keys()).difference(set(fieldnames)).difference(set(variable_columns)).difference(set(updatable_columns))
if unexpected_fields:
raise Exception("The fields '{0}' were passed but not found in the schema for table {1}.".format("', '".join(sorted(unexpected_fields)), model.__dict__['__tablename__']))
pruned_values = {}
for k in set(values.keys()).intersection(set(fieldnames)):
v = values[k]
pruned_values[k] = v
instance = tsession.query(model).filter_by(**pruned_values)
if instance.count() > 1:
raise Exception('Multiple records were found with the search criteria.')
instance = instance.first()
if instance:
if read_only == False:
for c in updatable_columns:
setattr(instance, c, values[c])
tsession.flush()
return instance
else:
if read_only == False:
if sorted(pruned_values.keys()) != sorted(fieldnames):
raise Exception('Some required fields are missing: {0}. Either supply these fields or add them to the missing_columns list.'.format(set(fieldnames).difference(pruned_values.keys())))
instance = model(**pruned_values)
tsession.add(instance)
tsession.flush()
return instance
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:errors; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:instance; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 13; 7, 21; 7, 82; 7, 181; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 12; 11, identifier:instance; 12, identifier:dict; 13, block; 13, 14; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_validate; 19, argument_list; 19, 20; 20, identifier:instance; 21, elif_clause; 21, 22; 21, 29; 22, call; 22, 23; 22, 24; 23, identifier:isinstance; 24, argument_list; 24, 25; 24, 26; 25, identifier:instance; 26, attribute; 26, 27; 26, 28; 27, identifier:forms; 28, identifier:BaseForm; 29, block; 29, 30; 29, 50; 30, if_statement; 30, 31; 30, 40; 31, boolean_operator:and; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:instance; 34, identifier:is_bound; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:instance; 38, identifier:is_valid; 39, argument_list; 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:_validate; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:instance; 49, identifier:cleaned_data; 50, return_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_validate; 55, argument_list; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:dict; 58, argument_list; 58, 59; 59, list_comprehension; 59, 60; 59, 77; 60, tuple; 60, 61; 60, 62; 61, identifier:f; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:instance; 66, identifier:initial; 67, identifier:get; 68, argument_list; 68, 69; 68, 70; 69, identifier:f; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:instance; 74, identifier:f; 75, identifier:value; 76, argument_list; 77, for_in_clause; 77, 78; 77, 79; 78, identifier:f; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:validators; 82, elif_clause; 82, 83; 82, 90; 83, call; 83, 84; 83, 85; 84, identifier:isinstance; 85, argument_list; 85, 86; 85, 87; 86, identifier:instance; 87, attribute; 87, 88; 87, 89; 88, identifier:formsets; 89, identifier:BaseFormSet; 90, block; 90, 91; 91, if_statement; 91, 92; 91, 95; 91, 148; 92, attribute; 92, 93; 92, 94; 93, identifier:instance; 94, identifier:can_delete; 95, block; 95, 96; 95, 137; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:validate_forms; 99, binary_operator:+; 99, 100; 99, 115; 100, list_comprehension; 100, 101; 100, 102; 100, 107; 101, identifier:form; 102, for_in_clause; 102, 103; 102, 104; 103, identifier:form; 104, attribute; 104, 105; 104, 106; 105, identifier:instance; 106, identifier:initial_forms; 107, if_clause; 107, 108; 108, not_operator; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:instance; 112, identifier:_should_delete_form; 113, argument_list; 113, 114; 114, identifier:form; 115, list_comprehension; 115, 116; 115, 117; 115, 122; 116, identifier:form; 117, for_in_clause; 117, 118; 117, 119; 118, identifier:form; 119, attribute; 119, 120; 119, 121; 120, identifier:instance; 121, identifier:extra_forms; 122, if_clause; 122, 123; 123, parenthesized_expression; 123, 124; 124, boolean_operator:and; 124, 125; 124, 130; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:form; 128, identifier:has_changed; 129, argument_list; 130, not_operator; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:instance; 134, identifier:_should_delete_form; 135, argument_list; 135, 136; 136, identifier:form; 137, return_statement; 137, 138; 138, list_comprehension; 138, 139; 138, 145; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:errors; 143, argument_list; 143, 144; 144, identifier:f; 145, for_in_clause; 145, 146; 145, 147; 146, identifier:f; 147, identifier:validate_forms; 148, else_clause; 148, 149; 149, block; 149, 150; 149, 170; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:validate_forms; 153, binary_operator:+; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:instance; 156, identifier:initial_forms; 157, list_comprehension; 157, 158; 157, 159; 157, 164; 158, identifier:form; 159, for_in_clause; 159, 160; 159, 161; 160, identifier:form; 161, attribute; 161, 162; 161, 163; 162, identifier:instance; 163, identifier:extra_forms; 164, if_clause; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:form; 168, identifier:has_changed; 169, argument_list; 170, return_statement; 170, 171; 171, list_comprehension; 171, 172; 171, 178; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:errors; 176, argument_list; 176, 177; 177, identifier:f; 178, for_in_clause; 178, 179; 178, 180; 179, identifier:f; 180, identifier:validate_forms; 181, elif_clause; 181, 182; 181, 189; 182, call; 182, 183; 182, 184; 183, identifier:isinstance; 184, argument_list; 184, 185; 184, 186; 185, identifier:instance; 186, attribute; 186, 187; 186, 188; 187, identifier:models; 188, identifier:Model; 189, block; 189, 190; 190, return_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:_validate; 195, argument_list; 195, 196; 196, call; 196, 197; 196, 198; 197, identifier:dict; 198, argument_list; 198, 199; 199, list_comprehension; 199, 200; 199, 207; 200, tuple; 200, 201; 200, 202; 201, identifier:f; 202, call; 202, 203; 202, 204; 203, identifier:getattr; 204, argument_list; 204, 205; 204, 206; 205, identifier:instance; 206, identifier:f; 207, for_in_clause; 207, 208; 207, 209; 208, identifier:f; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:validators | def errors(self, instance):
if isinstance(instance, dict):
return self._validate(instance)
elif isinstance(instance, forms.BaseForm):
if instance.is_bound and instance.is_valid():
return self._validate(instance.cleaned_data)
return self._validate(dict(
[
(f, instance.initial.get(f, instance[f].value()))
for f in self.validators
]
))
elif isinstance(instance, formsets.BaseFormSet):
if instance.can_delete:
validate_forms = [
form for form in instance.initial_forms
if not instance._should_delete_form(form)
] + [
form for form in instance.extra_forms
if (form.has_changed() and
not instance._should_delete_form(form))
]
return [
self.errors(f)
for f in validate_forms
]
else:
validate_forms = instance.initial_forms + [
form for form in instance.extra_forms
if form.has_changed()
]
return [self.errors(f) for f in validate_forms]
elif isinstance(instance, models.Model):
return self._validate(dict(
[(f, getattr(instance, f)) for f in self.validators]
)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:multimatch; 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:origin; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:rel; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:target; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:attrs; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:include_ids; 19, False; 20, block; 20, 21; 20, 23; 20, 25; 20, 44; 20, 63; 20, 82; 20, 219; 21, expression_statement; 21, 22; 22, string:'''
Iterator over relationship IDs that match a pattern of components, with multiple options provided for each component
origin - (optional) origin of the relationship (similar to an RDF subject), or set of values. If omitted any origin will be matched.
rel - (optional) type IRI of the relationship (similar to an RDF predicate), or set of values. If omitted any relationship will be matched.
target - (optional) target of the relationship (similar to an RDF object), a boolean, floating point or unicode object, or set of values. If omitted any target will be matched.
attrs - (optional) attribute mapping of relationship metadata, i.e. {attrname1: attrval1, attrname2: attrval2}. If any attribute is specified, an exact match is made (i.e. the attribute name and value must match).
include_ids - If true include statement IDs with yield values
'''; 23, raise_statement; 23, 24; 24, identifier:NotImplementedError; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:origin; 28, conditional_expression:if; 28, 29; 28, 30; 28, 39; 29, identifier:origin; 30, boolean_operator:or; 30, 31; 30, 34; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:origin; 33, None; 34, call; 34, 35; 34, 36; 35, identifier:isinstance; 36, argument_list; 36, 37; 36, 38; 37, identifier:origin; 38, identifier:set; 39, call; 39, 40; 39, 41; 40, identifier:set; 41, argument_list; 41, 42; 42, list:[origin]; 42, 43; 43, identifier:origin; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:rel; 47, conditional_expression:if; 47, 48; 47, 49; 47, 58; 48, identifier:rel; 49, boolean_operator:or; 49, 50; 49, 53; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:rel; 52, None; 53, call; 53, 54; 53, 55; 54, identifier:isinstance; 55, argument_list; 55, 56; 55, 57; 56, identifier:rel; 57, identifier:set; 58, call; 58, 59; 58, 60; 59, identifier:set; 60, argument_list; 60, 61; 61, list:[rel]; 61, 62; 62, identifier:rel; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:target; 66, conditional_expression:if; 66, 67; 66, 68; 66, 77; 67, identifier:target; 68, boolean_operator:or; 68, 69; 68, 72; 69, comparison_operator:is; 69, 70; 69, 71; 70, identifier:target; 71, None; 72, call; 72, 73; 72, 74; 73, identifier:isinstance; 74, argument_list; 74, 75; 74, 76; 75, identifier:target; 76, identifier:set; 77, call; 77, 78; 77, 79; 78, identifier:set; 79, argument_list; 79, 80; 80, list:[target]; 80, 81; 81, identifier:target; 82, for_statement; 82, 83; 82, 86; 82, 92; 83, pattern_list; 83, 84; 83, 85; 84, identifier:index; 85, identifier:curr_rel; 86, call; 86, 87; 86, 88; 87, identifier:enumerate; 88, argument_list; 88, 89; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:_relationships; 92, block; 92, 93; 92, 97; 92, 110; 92, 123; 92, 136; 92, 171; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:matches; 96, True; 97, if_statement; 97, 98; 97, 105; 98, boolean_operator:and; 98, 99; 98, 100; 99, identifier:origin; 100, comparison_operator:not; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:curr_rel; 103, identifier:ORIGIN; 104, identifier:origin; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:matches; 109, False; 110, if_statement; 110, 111; 110, 118; 111, boolean_operator:and; 111, 112; 111, 113; 112, identifier:rel; 113, comparison_operator:not; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:curr_rel; 116, identifier:RELATIONSHIP; 117, identifier:rel; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:matches; 122, False; 123, if_statement; 123, 124; 123, 131; 124, boolean_operator:and; 124, 125; 124, 126; 125, identifier:target; 126, comparison_operator:not; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:curr_rel; 129, identifier:TARGET; 130, identifier:target; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:matches; 135, False; 136, if_statement; 136, 137; 136, 138; 137, identifier:attrs; 138, block; 138, 139; 139, for_statement; 139, 140; 139, 143; 139, 148; 140, pattern_list; 140, 141; 140, 142; 141, identifier:k; 142, identifier:v; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:attrs; 146, identifier:items; 147, argument_list; 148, block; 148, 149; 149, if_statement; 149, 150; 149, 166; 150, boolean_operator:or; 150, 151; 150, 156; 151, comparison_operator:not; 151, 152; 151, 153; 152, identifier:k; 153, subscript; 153, 154; 153, 155; 154, identifier:curr_rel; 155, identifier:ATTRIBUTES; 156, comparison_operator:!=; 156, 157; 156, 165; 157, call; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, subscript; 159, 160; 159, 161; 160, identifier:curr_rel; 161, identifier:ATTRIBUTES; 162, identifier:get; 163, argument_list; 163, 164; 164, identifier:k; 165, identifier:v; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:matches; 170, False; 171, if_statement; 171, 172; 171, 173; 172, identifier:matches; 173, block; 173, 174; 174, if_statement; 174, 175; 174, 176; 174, 198; 175, identifier:include_ids; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, yield; 178, 179; 179, expression_list; 179, 180; 179, 181; 180, identifier:index; 181, tuple; 181, 182; 181, 185; 181, 188; 181, 191; 182, subscript; 182, 183; 182, 184; 183, identifier:curr_rel; 184, integer:0; 185, subscript; 185, 186; 185, 187; 186, identifier:curr_rel; 187, integer:1; 188, subscript; 188, 189; 188, 190; 189, identifier:curr_rel; 190, integer:2; 191, call; 191, 192; 191, 197; 192, attribute; 192, 193; 192, 196; 193, subscript; 193, 194; 193, 195; 194, identifier:curr_rel; 195, integer:3; 196, identifier:copy; 197, argument_list; 198, else_clause; 198, 199; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, yield; 201, 202; 202, tuple; 202, 203; 202, 206; 202, 209; 202, 212; 203, subscript; 203, 204; 203, 205; 204, identifier:curr_rel; 205, integer:0; 206, subscript; 206, 207; 206, 208; 207, identifier:curr_rel; 208, integer:1; 209, subscript; 209, 210; 209, 211; 210, identifier:curr_rel; 211, integer:2; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:curr_rel; 216, integer:3; 217, identifier:copy; 218, argument_list; 219, return_statement | def multimatch(self, origin=None, rel=None, target=None, attrs=None, include_ids=False):
'''
Iterator over relationship IDs that match a pattern of components, with multiple options provided for each component
origin - (optional) origin of the relationship (similar to an RDF subject), or set of values. If omitted any origin will be matched.
rel - (optional) type IRI of the relationship (similar to an RDF predicate), or set of values. If omitted any relationship will be matched.
target - (optional) target of the relationship (similar to an RDF object), a boolean, floating point or unicode object, or set of values. If omitted any target will be matched.
attrs - (optional) attribute mapping of relationship metadata, i.e. {attrname1: attrval1, attrname2: attrval2}. If any attribute is specified, an exact match is made (i.e. the attribute name and value must match).
include_ids - If true include statement IDs with yield values
'''
raise NotImplementedError
origin = origin if origin is None or isinstance(origin, set) else set([origin])
rel = rel if rel is None or isinstance(rel, set) else set([rel])
target = target if target is None or isinstance(target, set) else set([target])
for index, curr_rel in enumerate(self._relationships):
matches = True
if origin and curr_rel[ORIGIN] not in origin:
matches = False
if rel and curr_rel[RELATIONSHIP] not in rel:
matches = False
if target and curr_rel[TARGET] not in target:
matches = False
if attrs:
for k, v in attrs.items():
if k not in curr_rel[ATTRIBUTES] or curr_rel[ATTRIBUTES].get(k) != v:
matches = False
if matches:
if include_ids:
yield index, (curr_rel[0], curr_rel[1], curr_rel[2], curr_rel[3].copy())
else:
yield (curr_rel[0], curr_rel[1], curr_rel[2], curr_rel[3].copy())
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_qtls_from_mapqtl_data; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:matrix; 5, identifier:threshold; 6, identifier:inputfile; 7, block; 7, 8; 7, 27; 7, 31; 7, 35; 7, 136; 7, 167; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:trait_name; 11, subscript; 11, 12; 11, 26; 12, call; 12, 13; 12, 24; 13, attribute; 13, 14; 13, 23; 14, subscript; 14, 15; 14, 22; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:inputfile; 18, identifier:split; 19, argument_list; 19, 20; 19, 21; 20, string:')_'; 21, integer:1; 22, integer:1; 23, identifier:split; 24, argument_list; 24, 25; 25, string:'.mqo'; 26, integer:0; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:qtls; 30, list:[]; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:qtl; 34, None; 35, for_statement; 35, 36; 35, 37; 35, 42; 36, identifier:entry; 37, subscript; 37, 38; 37, 39; 38, identifier:matrix; 39, slice; 39, 40; 39, 41; 40, integer:1; 41, colon; 42, block; 42, 43; 42, 52; 42, 91; 42, 104; 42, 117; 43, if_statement; 43, 44; 43, 47; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:qtl; 46, None; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:qtl; 51, identifier:entry; 52, if_statement; 52, 53; 52, 60; 53, comparison_operator:!=; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:qtl; 56, integer:1; 57, subscript; 57, 58; 57, 59; 58, identifier:entry; 59, integer:1; 60, block; 60, 61; 60, 87; 61, if_statement; 61, 62; 61, 73; 62, comparison_operator:>; 62, 63; 62, 69; 63, call; 63, 64; 63, 65; 64, identifier:float; 65, argument_list; 65, 66; 66, subscript; 66, 67; 66, 68; 67, identifier:qtl; 68, integer:4; 69, call; 69, 70; 69, 71; 70, identifier:float; 71, argument_list; 71, 72; 72, identifier:threshold; 73, block; 73, 74; 73, 80; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:qtl; 78, integer:0; 79, identifier:trait_name; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:qtls; 84, identifier:append; 85, argument_list; 85, 86; 86, identifier:qtl; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:qtl; 90, identifier:entry; 91, if_statement; 91, 92; 91, 97; 92, comparison_operator:==; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:entry; 95, integer:4; 96, string:''; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:entry; 102, integer:4; 103, integer:0; 104, if_statement; 104, 105; 104, 110; 105, comparison_operator:==; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:qtl; 108, integer:4; 109, string:''; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:qtl; 115, integer:4; 116, integer:0; 117, if_statement; 117, 118; 117, 131; 118, comparison_operator:>; 118, 119; 118, 125; 119, call; 119, 120; 119, 121; 120, identifier:float; 121, argument_list; 121, 122; 122, subscript; 122, 123; 122, 124; 123, identifier:entry; 124, integer:4; 125, call; 125, 126; 125, 127; 126, identifier:float; 127, argument_list; 127, 128; 128, subscript; 128, 129; 128, 130; 129, identifier:qtl; 130, integer:4; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:qtl; 135, identifier:entry; 136, if_statement; 136, 137; 136, 148; 137, comparison_operator:>; 137, 138; 137, 144; 138, call; 138, 139; 138, 140; 139, identifier:float; 140, argument_list; 140, 141; 141, subscript; 141, 142; 141, 143; 142, identifier:qtl; 143, integer:4; 144, call; 144, 145; 144, 146; 145, identifier:float; 146, argument_list; 146, 147; 147, identifier:threshold; 148, block; 148, 149; 148, 155; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:qtl; 153, integer:0; 154, identifier:trait_name; 155, if_statement; 155, 156; 155, 159; 156, comparison_operator:not; 156, 157; 156, 158; 157, identifier:qtl; 158, identifier:qtls; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:qtls; 164, identifier:append; 165, argument_list; 165, 166; 166, identifier:qtl; 167, return_statement; 167, 168; 168, identifier:qtls | def get_qtls_from_mapqtl_data(matrix, threshold, inputfile):
trait_name = inputfile.split(')_', 1)[1].split('.mqo')[0]
qtls = []
qtl = None
for entry in matrix[1:]:
if qtl is None:
qtl = entry
if qtl[1] != entry[1]:
if float(qtl[4]) > float(threshold):
qtl[0] = trait_name
qtls.append(qtl)
qtl = entry
if entry[4] == '':
entry[4] = 0
if qtl[4] == '':
qtl[4] = 0
if float(entry[4]) > float(qtl[4]):
qtl = entry
if float(qtl[4]) > float(threshold):
qtl[0] = trait_name
if qtl not in qtls:
qtls.append(qtl)
return qtls |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:merge_range_pairs; 3, parameters; 3, 4; 4, identifier:prs; 5, block; 5, 6; 5, 8; 5, 12; 5, 23; 5, 30; 5, 34; 5, 38; 5, 144; 6, expression_statement; 6, 7; 7, string:'''Takes in a list of pairs specifying ranges and returns a sorted list of merged, sorted ranges.'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:new_prs; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:sprs; 15, list_comprehension; 15, 16; 15, 20; 16, call; 16, 17; 16, 18; 17, identifier:sorted; 18, argument_list; 18, 19; 19, identifier:p; 20, for_in_clause; 20, 21; 20, 22; 21, identifier:p; 22, identifier:prs; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:sprs; 26, call; 26, 27; 26, 28; 27, identifier:sorted; 28, argument_list; 28, 29; 29, identifier:sprs; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:merged; 33, False; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:x; 37, integer:0; 38, while_statement; 38, 39; 38, 45; 39, comparison_operator:<; 39, 40; 39, 41; 40, identifier:x; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:sprs; 45, block; 45, 46; 45, 52; 45, 61; 45, 128; 45, 140; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:newx; 49, binary_operator:+; 49, 50; 49, 51; 50, identifier:x; 51, integer:1; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:new_pair; 55, call; 55, 56; 55, 57; 56, identifier:list; 57, argument_list; 57, 58; 58, subscript; 58, 59; 58, 60; 59, identifier:sprs; 60, identifier:x; 61, for_statement; 61, 62; 61, 63; 61, 73; 62, identifier:y; 63, call; 63, 64; 63, 65; 64, identifier:range; 65, argument_list; 65, 66; 65, 69; 66, binary_operator:+; 66, 67; 66, 68; 67, identifier:x; 68, integer:1; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, identifier:sprs; 73, block; 73, 74; 74, if_statement; 74, 75; 74, 89; 75, comparison_operator:<=; 75, 76; 75, 79; 75, 86; 76, subscript; 76, 77; 76, 78; 77, identifier:new_pair; 78, integer:0; 79, binary_operator:-; 79, 80; 79, 85; 80, subscript; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:sprs; 83, identifier:y; 84, integer:0; 85, integer:1; 86, subscript; 86, 87; 86, 88; 87, identifier:new_pair; 88, integer:1; 89, block; 89, 90; 89, 106; 89, 122; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:new_pair; 94, integer:0; 95, call; 95, 96; 95, 97; 96, identifier:min; 97, argument_list; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:new_pair; 100, integer:0; 101, subscript; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:sprs; 104, identifier:y; 105, integer:0; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:new_pair; 110, integer:1; 111, call; 111, 112; 111, 113; 112, identifier:max; 113, argument_list; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:new_pair; 116, integer:1; 117, subscript; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:sprs; 120, identifier:y; 121, integer:1; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:newx; 125, binary_operator:+; 125, 126; 125, 127; 126, identifier:y; 127, integer:1; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:not; 129, 130; 129, 131; 130, identifier:new_pair; 131, identifier:new_prs; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:new_prs; 137, identifier:append; 138, argument_list; 138, 139; 139, identifier:new_pair; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:x; 143, identifier:newx; 144, return_statement; 144, 145; 145, identifier:new_prs | def merge_range_pairs(prs):
'''Takes in a list of pairs specifying ranges and returns a sorted list of merged, sorted ranges.'''
new_prs = []
sprs = [sorted(p) for p in prs]
sprs = sorted(sprs)
merged = False
x = 0
while x < len(sprs):
newx = x + 1
new_pair = list(sprs[x])
for y in range(x + 1, len(sprs)):
if new_pair[0] <= sprs[y][0] - 1 <= new_pair[1]:
new_pair[0] = min(new_pair[0], sprs[y][0])
new_pair[1] = max(new_pair[1], sprs[y][1])
newx = y + 1
if new_pair not in new_prs:
new_prs.append(new_pair)
x = newx
return new_prs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:create; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:agent_cls; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:n_agents; 10, integer:10; 11, default_parameter; 11, 12; 11, 13; 12, identifier:agent_kwargs; 13, dictionary; 14, default_parameter; 14, 15; 14, 16; 15, identifier:env_cls; 16, identifier:Environment; 17, default_parameter; 17, 18; 17, 19; 18, identifier:env_kwargs; 19, dictionary; 20, default_parameter; 20, 21; 20, 22; 21, identifier:callback; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:conns; 25, integer:0; 26, default_parameter; 26, 27; 26, 28; 27, identifier:log_folder; 28, None; 29, block; 29, 30; 29, 52; 29, 69; 29, 126; 29, 136; 29, 140; 29, 225; 29, 239; 30, if_statement; 30, 31; 30, 37; 31, not_operator; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:issubclass; 34, argument_list; 34, 35; 34, 36; 35, identifier:env_cls; 36, identifier:Environment; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:TypeError; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, string:"Environment class must be derived from ({}"; 45, identifier:format; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:Environment; 50, identifier:__class__; 51, identifier:__name__; 52, if_statement; 52, 53; 52, 63; 53, boolean_operator:and; 53, 54; 53, 57; 54, comparison_operator:is; 54, 55; 54, 56; 55, identifier:callback; 56, None; 57, not_operator; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:hasattr; 60, argument_list; 60, 61; 60, 62; 61, identifier:callback; 62, string:'__call__'; 63, block; 63, 64; 64, raise_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:TypeError; 67, argument_list; 67, 68; 68, string:"Callback must be callable."; 69, if_statement; 69, 70; 69, 75; 69, 102; 70, call; 70, 71; 70, 72; 71, identifier:hasattr; 72, argument_list; 72, 73; 72, 74; 73, identifier:agent_cls; 74, string:'__iter__'; 75, block; 75, 76; 76, for_statement; 76, 77; 76, 78; 76, 79; 77, identifier:e; 78, identifier:agent_cls; 79, block; 79, 80; 80, if_statement; 80, 81; 80, 87; 81, not_operator; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:issubclass; 84, argument_list; 84, 85; 84, 86; 85, identifier:e; 86, identifier:CreativeAgent; 87, block; 87, 88; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:TypeError; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, string:"All agent classes must be derived from {}"; 95, identifier:format; 96, argument_list; 96, 97; 97, attribute; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:CreativeAgent; 100, identifier:__class__; 101, identifier:__name__; 102, else_clause; 102, 103; 103, block; 103, 104; 104, if_statement; 104, 105; 104, 111; 105, not_operator; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:issubclass; 108, argument_list; 108, 109; 108, 110; 109, identifier:agent_cls; 110, identifier:CreativeAgent; 111, block; 111, 112; 112, raise_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:TypeError; 115, argument_list; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, string:"Agent class must be derived from {}"; 119, identifier:format; 120, argument_list; 120, 121; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:CreativeAgent; 124, identifier:__class__; 125, identifier:__name__; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:env; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:env_cls; 132, identifier:create; 133, argument_list; 133, 134; 134, dictionary_splat; 134, 135; 135, identifier:env_kwargs; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:agents; 139, list:[]; 140, if_statement; 140, 141; 140, 146; 140, 196; 141, call; 141, 142; 141, 143; 142, identifier:hasattr; 143, argument_list; 143, 144; 143, 145; 144, identifier:agent_cls; 145, string:'__iter__'; 146, block; 146, 147; 147, for_statement; 147, 148; 147, 149; 147, 156; 148, identifier:i; 149, call; 149, 150; 149, 151; 150, identifier:range; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:len; 154, argument_list; 154, 155; 155, identifier:n_agents; 156, block; 156, 157; 156, 165; 156, 173; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 164; 159, subscript; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:agent_kwargs; 162, identifier:i; 163, string:'environment'; 164, identifier:env; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 172; 167, subscript; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:agent_kwargs; 170, identifier:i; 171, string:'log_folder'; 172, identifier:log_folder; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:agents; 176, binary_operator:+; 176, 177; 176, 178; 177, identifier:agents; 178, list_comprehension; 178, 179; 178, 188; 179, call; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:agent_cls; 182, identifier:i; 183, argument_list; 183, 184; 184, dictionary_splat; 184, 185; 185, subscript; 185, 186; 185, 187; 186, identifier:agent_kwargs; 187, identifier:i; 188, for_in_clause; 188, 189; 188, 190; 189, identifier:e; 190, call; 190, 191; 190, 192; 191, identifier:range; 192, argument_list; 192, 193; 193, subscript; 193, 194; 193, 195; 194, identifier:n_agents; 195, identifier:i; 196, else_clause; 196, 197; 197, block; 197, 198; 197, 204; 197, 210; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:agent_kwargs; 202, string:'environment'; 203, identifier:env; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 209; 206, subscript; 206, 207; 206, 208; 207, identifier:agent_kwargs; 208, string:'log_folder'; 209, identifier:log_folder; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:agents; 213, list_comprehension; 213, 214; 213, 219; 214, call; 214, 215; 214, 216; 215, identifier:agent_cls; 216, argument_list; 216, 217; 217, dictionary_splat; 217, 218; 218, identifier:agent_kwargs; 219, for_in_clause; 219, 220; 219, 221; 220, identifier:e; 221, call; 221, 222; 221, 223; 222, identifier:range; 223, argument_list; 223, 224; 224, identifier:n_agents; 225, if_statement; 225, 226; 225, 229; 226, comparison_operator:>; 226, 227; 226, 228; 227, identifier:conns; 228, integer:0; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:env; 234, identifier:create_random_connections; 235, argument_list; 235, 236; 236, keyword_argument; 236, 237; 236, 238; 237, identifier:n; 238, identifier:conns; 239, return_statement; 239, 240; 240, call; 240, 241; 240, 242; 241, identifier:Simulation; 242, argument_list; 242, 243; 242, 244; 242, 245; 243, identifier:env; 244, identifier:callback; 245, identifier:log_folder | def create(self, agent_cls=None, n_agents=10, agent_kwargs={},
env_cls=Environment, env_kwargs={}, callback=None, conns=0,
log_folder=None):
if not issubclass(env_cls, Environment):
raise TypeError("Environment class must be derived from ({}"
.format(Environment.__class__.__name__))
if callback is not None and not hasattr(callback, '__call__'):
raise TypeError("Callback must be callable.")
if hasattr(agent_cls, '__iter__'):
for e in agent_cls:
if not issubclass(e, CreativeAgent):
raise TypeError("All agent classes must be derived from {}"
.format(CreativeAgent.__class__.__name__))
else:
if not issubclass(agent_cls, CreativeAgent):
raise TypeError("Agent class must be derived from {}"
.format(CreativeAgent.__class__.__name__))
env = env_cls.create(**env_kwargs)
agents = []
if hasattr(agent_cls, '__iter__'):
for i in range(len(n_agents)):
agent_kwargs[i]['environment'] = env
agent_kwargs[i]['log_folder'] = log_folder
agents = agents + [agent_cls[i](**agent_kwargs[i]) for e in
range(n_agents[i])]
else:
agent_kwargs['environment'] = env
agent_kwargs['log_folder'] = log_folder
agents = [agent_cls(**agent_kwargs) for e in range(n_agents)]
if conns > 0:
env.create_random_connections(n=conns)
return Simulation(env, callback, log_folder) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:callproc; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:procname; 6, default_parameter; 6, 7; 6, 8; 7, identifier:parameters; 8, tuple; 9, default_parameter; 9, 10; 9, 11; 10, identifier:quiet; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:expect_return_value; 14, False; 15, block; 15, 16; 15, 22; 15, 26; 15, 30; 15, 34; 15, 38; 15, 89; 15, 105; 15, 122; 15, 272; 15, 322; 16, expression_statement; 16, 17; 17, augmented_assignment:+=; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:procedures_run; 21, integer:1; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:i; 25, integer:0; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:errcode; 29, integer:0; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:caughte; 33, None; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:out_param_indices; 37, list:[]; 38, for_statement; 38, 39; 38, 40; 38, 47; 39, identifier:j; 40, call; 40, 41; 40, 42; 41, identifier:range; 42, argument_list; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:len; 45, argument_list; 45, 46; 46, identifier:parameters; 47, block; 47, 48; 47, 54; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:p; 51, subscript; 51, 52; 51, 53; 52, identifier:parameters; 53, identifier:j; 54, if_statement; 54, 55; 54, 70; 55, boolean_operator:and; 55, 56; 55, 65; 56, comparison_operator:==; 56, 57; 56, 61; 57, call; 57, 58; 57, 59; 58, identifier:type; 59, argument_list; 59, 60; 60, identifier:p; 61, call; 61, 62; 61, 63; 62, identifier:type; 63, argument_list; 63, 64; 64, string:''; 65, comparison_operator:==; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:p; 68, integer:0; 69, string:'@'; 70, block; 70, 71; 70, 82; 71, assert_statement; 71, 72; 72, parenthesized_expression; 72, 73; 73, comparison_operator:==; 73, 74; 73, 80; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:p; 77, identifier:find; 78, argument_list; 78, 79; 79, string:' '; 80, unary_operator:-; 80, 81; 81, integer:1; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:out_param_indices; 86, identifier:append; 87, argument_list; 87, 88; 88, identifier:j; 89, if_statement; 89, 90; 89, 97; 90, comparison_operator:not; 90, 91; 90, 92; 91, identifier:procname; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:list_stored_procedures; 96, argument_list; 97, block; 97, 98; 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:"The stored procedure '%s' does not exist."; 104, identifier:procname; 105, if_statement; 105, 106; 105, 114; 106, not_operator; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:re; 110, identifier:match; 111, argument_list; 111, 112; 111, 113; 112, string:"^\s*\w+\s*$"; 113, identifier:procname; 114, block; 114, 115; 115, raise_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:Exception; 118, argument_list; 118, 119; 119, binary_operator:%; 119, 120; 119, 121; 120, string:"Expected a stored procedure name in callproc but received '%s'."; 121, identifier:procname; 122, while_statement; 122, 123; 122, 128; 123, comparison_operator:<; 123, 124; 123, 125; 124, identifier:i; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:numTries; 128, block; 128, 129; 128, 133; 129, expression_statement; 129, 130; 130, augmented_assignment:+=; 130, 131; 130, 132; 131, identifier:i; 132, integer:1; 133, try_statement; 133, 134; 133, 234; 133, 257; 134, block; 134, 135; 134, 141; 134, 151; 134, 167; 134, 177; 134, 188; 134, 194; 134, 198; 134, 232; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:_get_connection; 140, argument_list; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:cursor; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:connection; 149, identifier:cursor; 150, argument_list; 151, if_statement; 151, 152; 151, 161; 152, comparison_operator:!=; 152, 153; 152, 157; 153, call; 153, 154; 153, 155; 154, identifier:type; 155, argument_list; 155, 156; 156, identifier:parameters; 157, call; 157, 158; 157, 159; 158, identifier:type; 159, argument_list; 159, 160; 160, tuple; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:parameters; 165, tuple; 165, 166; 166, identifier:parameters; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:errcode; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:cursor; 173, identifier:callproc; 174, argument_list; 174, 175; 174, 176; 175, identifier:procname; 176, identifier:parameters; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:lastrowid; 182, call; 182, 183; 182, 184; 183, identifier:int; 184, argument_list; 184, 185; 185, attribute; 185, 186; 185, 187; 186, identifier:cursor; 187, identifier:lastrowid; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:cursor; 192, identifier:close; 193, argument_list; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:out_param_results; 197, list:[]; 198, if_statement; 198, 199; 198, 200; 199, identifier:out_param_indices; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:out_param_results; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:execute; 208, argument_list; 208, 209; 209, binary_operator:%; 209, 210; 209, 211; 210, string:'SELECT %s'; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, string:", "; 214, identifier:join; 215, argument_list; 215, 216; 216, list_comprehension; 216, 217; 216, 229; 217, binary_operator:%; 217, 218; 217, 219; 218, string:'@_%s_%d AS %s'; 219, tuple; 219, 220; 219, 221; 219, 222; 220, identifier:procname; 221, identifier:pindex; 222, subscript; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:parameters; 225, identifier:pindex; 226, slice; 226, 227; 226, 228; 227, integer:1; 228, colon; 229, for_in_clause; 229, 230; 229, 231; 230, identifier:pindex; 231, identifier:out_param_indices; 232, return_statement; 232, 233; 233, identifier:out_param_results; 234, except_clause; 234, 235; 234, 238; 234, 239; 235, attribute; 235, 236; 235, 237; 236, identifier:MySQLdb; 237, identifier:OperationalError; 238, identifier:e; 239, block; 239, 240; 239, 246; 239, 252; 239, 256; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:_close_connection; 245, argument_list; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:errcode; 249, subscript; 249, 250; 249, 251; 250, identifier:e; 251, integer:0; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:caughte; 255, identifier:e; 256, continue_statement; 257, except_clause; 257, 258; 258, block; 258, 259; 258, 265; 258, 271; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:self; 263, identifier:_close_connection; 264, argument_list; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:traceback; 269, identifier:print_exc; 270, argument_list; 271, break_statement; 272, if_statement; 272, 273; 272, 275; 273, not_operator; 273, 274; 274, identifier:quiet; 275, block; 275, 276; 275, 298; 275, 314; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 283; 278, attribute; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:sys; 281, identifier:stderr; 282, identifier:write; 283, argument_list; 283, 284; 284, binary_operator:%; 284, 285; 284, 286; 285, string:"\nSQL execution error call stored procedure %s at %s:"; 286, tuple; 286, 287; 286, 288; 287, identifier:procname; 288, call; 288, 289; 288, 296; 289, attribute; 289, 290; 289, 295; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:datetime; 293, identifier:now; 294, argument_list; 295, identifier:strftime; 296, argument_list; 296, 297; 297, string:"%Y-%m-%d %H:%M:%S"; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 305; 300, attribute; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:sys; 303, identifier:stderr; 304, identifier:write; 305, argument_list; 305, 306; 306, binary_operator:%; 306, 307; 306, 308; 307, string:"\nErrorcode/Error: %d - '%s'.\n"; 308, tuple; 308, 309; 308, 310; 309, identifier:errcode; 310, call; 310, 311; 310, 312; 311, identifier:str; 312, argument_list; 312, 313; 313, identifier:caughte; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 321; 316, attribute; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:sys; 319, identifier:stderr; 320, identifier:flush; 321, argument_list; 322, raise_statement; 322, 323; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:MySQLdb; 326, identifier:OperationalError; 327, argument_list; 327, 328; 328, identifier:caughte | def callproc(self, procname, parameters=(), quiet=False, expect_return_value=False):
self.procedures_run += 1
i = 0
errcode = 0
caughte = None
out_param_indices = []
for j in range(len(parameters)):
p = parameters[j]
if type(p) == type('') and p[0] == '@':
assert(p.find(' ') == -1)
out_param_indices.append(j)
if procname not in self.list_stored_procedures():
raise Exception("The stored procedure '%s' does not exist." % procname)
if not re.match("^\s*\w+\s*$", procname):
raise Exception("Expected a stored procedure name in callproc but received '%s'." % procname)
while i < self.numTries:
i += 1
try:
self._get_connection()
cursor = self.connection.cursor()
if type(parameters) != type(()):
parameters = (parameters,)
errcode = cursor.callproc(procname, parameters)
self.lastrowid = int(cursor.lastrowid)
cursor.close()
out_param_results = []
if out_param_indices:
out_param_results = self.execute('SELECT %s' % ", ".join(['@_%s_%d AS %s' % (procname, pindex, parameters[pindex][1:]) for pindex in out_param_indices]))
return out_param_results
except MySQLdb.OperationalError, e:
self._close_connection()
errcode = e[0]
caughte = e
continue
except:
self._close_connection()
traceback.print_exc()
break
if not quiet:
sys.stderr.write("\nSQL execution error call stored procedure %s at %s:" % (
procname, datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
sys.stderr.write("\nErrorcode/Error: %d - '%s'.\n" % (errcode, str(caughte)))
sys.stderr.flush()
raise MySQLdb.OperationalError(caughte) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:create_insert_dict_string; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 4, identifier:self; 5, identifier:tblname; 6, identifier:d; 7, default_parameter; 7, 8; 7, 9; 8, identifier:PKfields; 9, list:[]; 10, default_parameter; 10, 11; 10, 12; 11, identifier:fields; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:check_existing; 15, False; 16, block; 16, 17; 16, 19; 16, 35; 16, 51; 16, 55; 16, 59; 17, expression_statement; 17, 18; 18, string:'''The main function of the insert_dict functions.
This creates and returns the SQL query and parameters used by the other functions but does not insert any data into the database.
Simple function for inserting a dictionary whose keys match the fieldnames of tblname. The function returns two values, the
second of which is a dict containing the primary keys of the record. If a record already exists then no insertion is performed and
(False, the dictionary of existing primary keys) is returned. Otherwise, the record is inserted into the database and (True, d)
is returned.'''; 19, if_statement; 19, 20; 19, 29; 20, comparison_operator:==; 20, 21; 20, 25; 21, call; 21, 22; 21, 23; 22, identifier:type; 23, argument_list; 23, 24; 24, identifier:PKfields; 25, call; 25, 26; 25, 27; 26, identifier:type; 27, argument_list; 27, 28; 28, string:""; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:PKfields; 33, list:[PKfields]; 33, 34; 34, identifier:PKfields; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:fields; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:fields; 43, call; 43, 44; 43, 45; 44, identifier:sorted; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:d; 49, identifier:keys; 50, argument_list; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:values; 54, None; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:SQL; 58, None; 59, try_statement; 59, 60; 59, 207; 60, block; 60, 61; 60, 65; 60, 69; 60, 109; 60, 117; 60, 125; 60, 129; 60, 162; 60, 189; 60, 202; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:wherestr; 64, list:[]; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:PKvalues; 68, list:[]; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:PKfield; 71, identifier:PKfields; 72, block; 72, 73; 73, if_statement; 73, 74; 73, 79; 73, 89; 74, comparison_operator:==; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:d; 77, identifier:PKfield; 78, None; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:wherestr; 84, identifier:append; 85, argument_list; 85, 86; 86, binary_operator:%; 86, 87; 86, 88; 87, string:"%s IS NULL"; 88, identifier:PKfield; 89, else_clause; 89, 90; 90, block; 90, 91; 90, 100; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:wherestr; 95, identifier:append; 96, argument_list; 96, 97; 97, binary_operator:%; 97, 98; 97, 99; 98, string:"%s=%%s"; 99, identifier:PKfield; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:PKvalues; 104, identifier:append; 105, argument_list; 105, 106; 106, subscript; 106, 107; 106, 108; 107, identifier:d; 108, identifier:PKfield; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:PKfields; 112, call; 112, 113; 112, 114; 113, identifier:join; 114, argument_list; 114, 115; 114, 116; 115, identifier:PKfields; 116, string:","; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:wherestr; 120, call; 120, 121; 120, 122; 121, identifier:join; 122, argument_list; 122, 123; 122, 124; 123, identifier:wherestr; 124, string:" AND "; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:record_exists; 128, None; 129, if_statement; 129, 130; 129, 131; 130, identifier:check_existing; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:record_exists; 135, not_operator; 135, 136; 136, parenthesized_expression; 136, 137; 137, not_operator; 137, 138; 138, parenthesized_expression; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:execute_select; 143, argument_list; 143, 144; 143, 153; 143, 159; 144, binary_operator:+; 144, 145; 144, 150; 145, binary_operator:%; 145, 146; 145, 147; 146, string:"SELECT %s FROM %s"; 147, tuple; 147, 148; 147, 149; 148, identifier:PKfields; 149, identifier:tblname; 150, binary_operator:%; 150, 151; 150, 152; 151, string:" WHERE %s"; 152, identifier:wherestr; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:parameters; 155, call; 155, 156; 155, 157; 156, identifier:tuple; 157, argument_list; 157, 158; 158, identifier:PKvalues; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:locked; 161, False; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:SQL; 165, binary_operator:%; 165, 166; 165, 167; 166, string:'INSERT INTO %s (%s) VALUES (%s)'; 167, tuple; 167, 168; 167, 169; 167, 174; 168, identifier:tblname; 169, call; 169, 170; 169, 171; 170, identifier:join; 171, argument_list; 171, 172; 171, 173; 172, identifier:fields; 173, string:", "; 174, call; 174, 175; 174, 176; 175, identifier:join; 176, argument_list; 176, 177; 176, 188; 177, list_comprehension; 177, 178; 177, 179; 178, string:'%s'; 179, for_in_clause; 179, 180; 179, 181; 180, identifier:x; 181, call; 181, 182; 181, 183; 182, identifier:range; 183, argument_list; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:len; 186, argument_list; 186, 187; 187, identifier:fields; 188, string:','; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:values; 192, call; 192, 193; 192, 194; 193, identifier:tuple; 194, argument_list; 194, 195; 195, list_comprehension; 195, 196; 195, 199; 196, subscript; 196, 197; 196, 198; 197, identifier:d; 198, identifier:k; 199, for_in_clause; 199, 200; 199, 201; 200, identifier:k; 201, identifier:fields; 202, return_statement; 202, 203; 203, expression_list; 203, 204; 203, 205; 203, 206; 204, identifier:SQL; 205, identifier:values; 206, identifier:record_exists; 207, except_clause; 207, 208; 207, 209; 207, 210; 208, identifier:Exception; 209, identifier:e; 210, block; 210, 211; 211, raise_statement; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:Exception; 214, argument_list; 214, 215; 215, binary_operator:%; 215, 216; 215, 217; 216, string:"Error occurred during database insertion: '%s'. %s"; 217, tuple; 217, 218; 217, 222; 218, call; 218, 219; 218, 220; 219, identifier:str; 220, argument_list; 220, 221; 221, identifier:e; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:traceback; 225, identifier:format_exc; 226, argument_list | def create_insert_dict_string(self, tblname, d, PKfields=[], fields=None, check_existing = False):
'''The main function of the insert_dict functions.
This creates and returns the SQL query and parameters used by the other functions but does not insert any data into the database.
Simple function for inserting a dictionary whose keys match the fieldnames of tblname. The function returns two values, the
second of which is a dict containing the primary keys of the record. If a record already exists then no insertion is performed and
(False, the dictionary of existing primary keys) is returned. Otherwise, the record is inserted into the database and (True, d)
is returned.'''
if type(PKfields) == type(""):
PKfields = [PKfields]
if fields == None:
fields = sorted(d.keys())
values = None
SQL = None
try:
wherestr = []
PKvalues = []
for PKfield in PKfields:
if d[PKfield] == None:
wherestr.append("%s IS NULL" % PKfield)
else:
wherestr.append("%s=%%s" % PKfield)
PKvalues.append(d[PKfield])
PKfields = join(PKfields, ",")
wherestr = join(wherestr, " AND ")
record_exists = None
if check_existing:
record_exists = not(not(self.execute_select("SELECT %s FROM %s" % (PKfields, tblname) + " WHERE %s" % wherestr, parameters=tuple(PKvalues), locked = False)))
SQL = 'INSERT INTO %s (%s) VALUES (%s)' % (
tblname, join(fields, ", "), join(['%s' for x in range(len(fields))], ','))
values = tuple([d[k] for k in fields])
return SQL, values, record_exists
except Exception, e:
raise Exception("Error occurred during database insertion: '%s'. %s" % (str(e), traceback.format_exc())) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:fixed_point; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:is_zero; 5, identifier:plus; 6, identifier:minus; 7, identifier:f; 8, identifier:x; 9, block; 9, 10; 9, 55; 10, decorated_definition; 10, 11; 10, 13; 11, decorator; 11, 12; 12, identifier:memo_Y; 13, function_definition; 13, 14; 13, 15; 13, 17; 14, function_name:_fixed_point; 15, parameters; 15, 16; 16, identifier:fixed_point_fun; 17, block; 17, 18; 17, 53; 18, function_definition; 18, 19; 18, 20; 18, 23; 19, function_name:__fixed_point; 20, parameters; 20, 21; 20, 22; 21, identifier:collected; 22, identifier:new; 23, block; 23, 24; 23, 32; 23, 40; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:diff; 27, call; 27, 28; 27, 29; 28, identifier:minus; 29, argument_list; 29, 30; 29, 31; 30, identifier:new; 31, identifier:collected; 32, if_statement; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:is_zero; 35, argument_list; 35, 36; 36, identifier:diff; 37, block; 37, 38; 38, return_statement; 38, 39; 39, identifier:collected; 40, return_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:fixed_point_fun; 43, argument_list; 43, 44; 43, 49; 44, call; 44, 45; 44, 46; 45, identifier:plus; 46, argument_list; 46, 47; 46, 48; 47, identifier:collected; 48, identifier:diff; 49, call; 49, 50; 49, 51; 50, identifier:f; 51, argument_list; 51, 52; 52, identifier:diff; 53, return_statement; 53, 54; 54, identifier:__fixed_point; 55, return_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:_fixed_point; 58, argument_list; 58, 59; 58, 60; 59, identifier:x; 60, call; 60, 61; 60, 62; 61, identifier:f; 62, argument_list; 62, 63; 63, identifier:x | def fixed_point(is_zero, plus, minus, f, x):
@memo_Y
def _fixed_point(fixed_point_fun):
def __fixed_point(collected, new):
diff = minus(new, collected)
if is_zero(diff):
return collected
return fixed_point_fun(plus(collected, diff), f(diff))
return __fixed_point
return _fixed_point(x, f(x)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:connections_from_graph; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:env; 5, identifier:G; 6, default_parameter; 6, 7; 6, 8; 7, identifier:edge_data; 8, False; 9, block; 9, 10; 9, 29; 9, 42; 9, 53; 9, 84; 9, 91; 9, 97; 9, 105; 10, if_statement; 10, 11; 10, 21; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:issubclass; 14, argument_list; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:G; 17, identifier:__class__; 18, tuple; 18, 19; 18, 20; 19, identifier:Graph; 20, identifier:DiGraph; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:TypeError; 25, argument_list; 25, 26; 26, concatenated_string; 26, 27; 26, 28; 27, string:"Graph structure must be derived from Networkx's "; 28, string:"Graph or DiGraph."; 29, if_statement; 29, 30; 29, 36; 30, not_operator; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:hasattr; 33, argument_list; 33, 34; 33, 35; 34, identifier:env; 35, string:'get_agents'; 36, block; 36, 37; 37, raise_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:TypeError; 40, argument_list; 40, 41; 41, string:"Parameter 'env' must have get_agents."; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:addrs; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:env; 48, identifier:get_agents; 49, argument_list; 49, 50; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:addr; 52, True; 53, if_statement; 53, 54; 53, 63; 54, comparison_operator:!=; 54, 55; 54, 59; 55, call; 55, 56; 55, 57; 56, identifier:len; 57, argument_list; 57, 58; 58, identifier:addrs; 59, call; 59, 60; 59, 61; 60, identifier:len; 61, argument_list; 61, 62; 62, identifier:G; 63, block; 63, 64; 64, raise_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:ValueError; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 75; 69, attribute; 69, 70; 69, 74; 70, concatenated_string; 70, 71; 70, 72; 70, 73; 71, string:"The number of graph nodes and agents in the "; 72, string:"environment (excluding the manager agent) must "; 73, string:"match. Now got {} nodes and {} agents."; 74, identifier:format; 75, argument_list; 75, 76; 75, 80; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, identifier:G; 80, call; 80, 81; 80, 82; 81, identifier:len; 82, argument_list; 82, 83; 83, identifier:addrs; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:addrs; 87, call; 87, 88; 87, 89; 88, identifier:sort_addrs; 89, argument_list; 89, 90; 90, identifier:addrs; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:_addrs2nodes; 94, argument_list; 94, 95; 94, 96; 95, identifier:addrs; 96, identifier:G; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:conn_map; 100, call; 100, 101; 100, 102; 101, identifier:_edges2conns; 102, argument_list; 102, 103; 102, 104; 103, identifier:G; 104, identifier:edge_data; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:env; 109, identifier:create_connections; 110, argument_list; 110, 111; 111, identifier:conn_map | def connections_from_graph(env, G, edge_data=False):
if not issubclass(G.__class__, (Graph, DiGraph)):
raise TypeError("Graph structure must be derived from Networkx's "
"Graph or DiGraph.")
if not hasattr(env, 'get_agents'):
raise TypeError("Parameter 'env' must have get_agents.")
addrs = env.get_agents(addr=True)
if len(addrs) != len(G):
raise ValueError("The number of graph nodes and agents in the "
"environment (excluding the manager agent) must "
"match. Now got {} nodes and {} agents."
.format(len(G), len(addrs)))
addrs = sort_addrs(addrs)
_addrs2nodes(addrs, G)
conn_map = _edges2conns(G, edge_data)
env.create_connections(conn_map) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:graph_from_connections; 3, parameters; 3, 4; 3, 5; 4, identifier:env; 5, default_parameter; 5, 6; 5, 7; 6, identifier:directed; 7, False; 8, block; 8, 9; 8, 20; 8, 31; 8, 83; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:G; 12, conditional_expression:if; 12, 13; 12, 16; 12, 17; 13, call; 13, 14; 13, 15; 14, identifier:DiGraph; 15, argument_list; 16, identifier:directed; 17, call; 17, 18; 17, 19; 18, identifier:Graph; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:conn_list; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:env; 26, identifier:get_connections; 27, argument_list; 27, 28; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:data; 30, True; 31, for_statement; 31, 32; 31, 35; 31, 36; 32, pattern_list; 32, 33; 32, 34; 33, identifier:agent; 34, identifier:conns; 35, identifier:conn_list; 36, block; 36, 37; 36, 44; 36, 48; 36, 68; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:G; 41, identifier:add_node; 42, argument_list; 42, 43; 43, identifier:agent; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:ebunch; 47, list:[]; 48, for_statement; 48, 49; 48, 52; 48, 57; 49, pattern_list; 49, 50; 49, 51; 50, identifier:nb; 51, identifier:data; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:conns; 55, identifier:items; 56, argument_list; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:ebunch; 62, identifier:append; 63, argument_list; 63, 64; 64, tuple; 64, 65; 64, 66; 64, 67; 65, identifier:agent; 66, identifier:nb; 67, identifier:data; 68, if_statement; 68, 69; 68, 75; 69, comparison_operator:>; 69, 70; 69, 74; 70, call; 70, 71; 70, 72; 71, identifier:len; 72, argument_list; 72, 73; 73, identifier:ebunch; 74, integer:0; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:G; 80, identifier:add_edges_from; 81, argument_list; 81, 82; 82, identifier:ebunch; 83, return_statement; 83, 84; 84, identifier:G | def graph_from_connections(env, directed=False):
G = DiGraph() if directed else Graph()
conn_list = env.get_connections(data=True)
for agent, conns in conn_list:
G.add_node(agent)
ebunch = []
for nb, data in conns.items():
ebunch.append((agent, nb, data))
if len(ebunch) > 0:
G.add_edges_from(ebunch)
return G |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:profile; 3, parameters; 3, 4; 3, 5; 4, identifier:request; 5, default_parameter; 5, 6; 5, 7; 6, identifier:status; 7, integer:200; 8, block; 8, 9; 9, if_statement; 9, 10; 9, 15; 9, 149; 9, 301; 10, comparison_operator:==; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:request; 13, identifier:method; 14, string:'GET'; 15, block; 15, 16; 15, 132; 16, if_statement; 16, 17; 16, 26; 16, 62; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:request; 21, identifier:GET; 22, identifier:get; 23, argument_list; 23, 24; 23, 25; 24, string:"username"; 25, False; 26, block; 26, 27; 27, try_statement; 27, 28; 27, 54; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:user_profile; 32, attribute; 32, 33; 32, 53; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:User; 37, identifier:objects; 38, identifier:get; 39, argument_list; 39, 40; 39, 50; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:username; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:request; 46, identifier:GET; 47, identifier:get; 48, argument_list; 48, 49; 49, string:"username"; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:userprofile__public; 52, True; 53, identifier:userprofile; 54, except_clause; 54, 55; 54, 56; 55, identifier:ObjectDoesNotExist; 56, block; 56, 57; 57, raise_statement; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:Http404; 60, argument_list; 60, 61; 61, string:"user not found or have not public profile"; 62, else_clause; 62, 63; 63, block; 63, 64; 63, 71; 63, 122; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:user_id; 67, call; 67, 68; 67, 69; 68, identifier:get_user_id; 69, argument_list; 69, 70; 70, identifier:request; 71, if_statement; 71, 72; 71, 86; 72, boolean_operator:and; 72, 73; 72, 81; 73, call; 73, 74; 73, 75; 74, identifier:get_config; 75, argument_list; 75, 76; 75, 77; 75, 78; 76, string:'proso_user'; 77, string:'google.openid.migration'; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:default; 80, True; 81, not_operator; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:is_user_id_overridden; 84, argument_list; 84, 85; 85, identifier:request; 86, block; 86, 87; 86, 96; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:migrated_user; 90, call; 90, 91; 90, 92; 91, identifier:migrate_google_openid_user; 92, argument_list; 92, 93; 93, attribute; 93, 94; 93, 95; 94, identifier:request; 95, identifier:user; 96, if_statement; 96, 97; 96, 100; 97, comparison_operator:is; 97, 98; 97, 99; 98, identifier:migrated_user; 99, None; 100, block; 100, 101; 100, 108; 100, 114; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:auth; 105, identifier:logout; 106, argument_list; 106, 107; 107, identifier:request; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:migrated_user; 112, identifier:backend; 113, string:'social.backends.google.GoogleOAuth2'; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:auth; 118, identifier:login; 119, argument_list; 119, 120; 119, 121; 120, identifier:request; 121, identifier:migrated_user; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:user_profile; 125, call; 125, 126; 125, 127; 126, identifier:get_object_or_404; 127, argument_list; 127, 128; 127, 129; 128, identifier:UserProfile; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:user_id; 131, identifier:user_id; 132, return_statement; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:render_json; 135, argument_list; 135, 136; 135, 137; 135, 138; 135, 141; 135, 144; 136, identifier:request; 137, identifier:user_profile; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:status; 140, identifier:status; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:template; 143, string:'user_profile.html'; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:help_text; 146, attribute; 146, 147; 146, 148; 147, identifier:profile; 148, identifier:__doc__; 149, elif_clause; 149, 150; 149, 155; 150, comparison_operator:==; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:request; 153, identifier:method; 154, string:'POST'; 155, block; 155, 156; 155, 287; 155, 293; 156, with_statement; 156, 157; 156, 164; 157, with_clause; 157, 158; 158, with_item; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:transaction; 162, identifier:atomic; 163, argument_list; 164, block; 164, 165; 164, 179; 164, 186; 164, 196; 164, 206; 164, 222; 164, 238; 164, 267; 164, 281; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:to_save; 168, call; 168, 169; 168, 170; 169, identifier:json_body; 170, argument_list; 170, 171; 171, call; 171, 172; 171, 177; 172, attribute; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:request; 175, identifier:body; 176, identifier:decode; 177, argument_list; 177, 178; 178, string:"utf-8"; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:user_id; 182, call; 182, 183; 182, 184; 183, identifier:get_user_id; 184, argument_list; 184, 185; 185, identifier:request; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:user_profile; 189, call; 189, 190; 189, 191; 190, identifier:get_object_or_404; 191, argument_list; 191, 192; 191, 193; 192, identifier:UserProfile; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:user_id; 195, identifier:user_id; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:user; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:to_save; 202, identifier:get; 203, argument_list; 203, 204; 203, 205; 204, string:'user'; 205, None; 206, if_statement; 206, 207; 206, 210; 207, comparison_operator:in; 207, 208; 207, 209; 208, string:'send_emails'; 209, identifier:to_save; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:user_profile; 215, identifier:send_emails; 216, call; 216, 217; 216, 218; 217, identifier:bool; 218, argument_list; 218, 219; 219, subscript; 219, 220; 219, 221; 220, identifier:to_save; 221, string:'send_emails'; 222, if_statement; 222, 223; 222, 226; 223, comparison_operator:in; 223, 224; 223, 225; 224, string:'public'; 225, identifier:to_save; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:user_profile; 231, identifier:public; 232, call; 232, 233; 232, 234; 233, identifier:bool; 234, argument_list; 234, 235; 235, subscript; 235, 236; 235, 237; 236, identifier:to_save; 237, string:'public'; 238, if_statement; 238, 239; 238, 240; 239, identifier:user; 240, block; 240, 241; 240, 252; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:error; 244, call; 244, 245; 244, 246; 245, identifier:_save_user; 246, argument_list; 246, 247; 246, 248; 246, 249; 247, identifier:request; 248, identifier:user; 249, keyword_argument; 249, 250; 249, 251; 250, identifier:new; 251, False; 252, if_statement; 252, 253; 252, 254; 253, identifier:error; 254, block; 254, 255; 255, return_statement; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:render_json; 258, argument_list; 258, 259; 258, 260; 258, 261; 258, 264; 259, identifier:request; 260, identifier:error; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:template; 263, string:'user_json.html'; 264, keyword_argument; 264, 265; 264, 266; 265, identifier:status; 266, integer:400; 267, if_statement; 267, 268; 267, 271; 268, comparison_operator:in; 268, 269; 268, 270; 269, string:'properties'; 270, identifier:to_save; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:user_profile; 276, identifier:save_properties; 277, argument_list; 277, 278; 278, subscript; 278, 279; 278, 280; 279, identifier:to_save; 280, string:'properties'; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:user_profile; 285, identifier:save; 286, argument_list; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:request; 291, identifier:method; 292, string:"GET"; 293, return_statement; 293, 294; 294, call; 294, 295; 294, 296; 295, identifier:profile; 296, argument_list; 296, 297; 296, 298; 297, identifier:request; 298, keyword_argument; 298, 299; 298, 300; 299, identifier:status; 300, integer:202; 301, else_clause; 301, 302; 302, block; 302, 303; 303, return_statement; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:HttpResponseBadRequest; 306, argument_list; 306, 307; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, string:"method %s is not allowed"; 310, identifier:format; 311, argument_list; 311, 312; 312, attribute; 312, 313; 312, 314; 313, identifier:request; 314, identifier:method | def profile(request, status=200):
if request.method == 'GET':
if request.GET.get("username", False):
try:
user_profile = User.objects.get(username=request.GET.get("username"),
userprofile__public=True).userprofile
except ObjectDoesNotExist:
raise Http404("user not found or have not public profile")
else:
user_id = get_user_id(request)
if get_config('proso_user', 'google.openid.migration', default=True) and not is_user_id_overridden(request):
migrated_user = migrate_google_openid_user(request.user)
if migrated_user is not None:
auth.logout(request)
migrated_user.backend = 'social.backends.google.GoogleOAuth2'
auth.login(request, migrated_user)
user_profile = get_object_or_404(UserProfile, user_id=user_id)
return render_json(
request, user_profile, status=status,
template='user_profile.html', help_text=profile.__doc__)
elif request.method == 'POST':
with transaction.atomic():
to_save = json_body(request.body.decode("utf-8"))
user_id = get_user_id(request)
user_profile = get_object_or_404(UserProfile, user_id=user_id)
user = to_save.get('user', None)
if 'send_emails' in to_save:
user_profile.send_emails = bool(to_save['send_emails'])
if 'public' in to_save:
user_profile.public = bool(to_save['public'])
if user:
error = _save_user(request, user, new=False)
if error:
return render_json(request, error, template='user_json.html', status=400)
if 'properties' in to_save:
user_profile.save_properties(to_save['properties'])
user_profile.save()
request.method = "GET"
return profile(request, status=202)
else:
return HttpResponseBadRequest("method %s is not allowed".format(request.method)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_session_identifiers; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:cls; 5, default_parameter; 5, 6; 5, 7; 6, identifier:folder; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:inputfile; 10, None; 11, block; 11, 12; 11, 16; 11, 26; 11, 175; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:sessions; 15, list:[]; 16, if_statement; 16, 17; 16, 20; 17, boolean_operator:and; 17, 18; 17, 19; 18, identifier:inputfile; 19, identifier:folder; 20, block; 20, 21; 21, raise_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:MQ2Exception; 24, argument_list; 24, 25; 25, string:'You should specify either a folder or a file'; 26, if_statement; 26, 27; 26, 28; 26, 115; 27, identifier:folder; 28, block; 28, 29; 28, 42; 29, if_statement; 29, 30; 29, 39; 30, not_operator; 30, 31; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:os; 35, identifier:path; 36, identifier:isdir; 37, argument_list; 37, 38; 38, identifier:folder; 39, block; 39, 40; 40, return_statement; 40, 41; 41, identifier:sessions; 42, for_statement; 42, 43; 42, 47; 42, 53; 43, pattern_list; 43, 44; 43, 45; 43, 46; 44, identifier:root; 45, identifier:dirs; 46, identifier:files; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:os; 50, identifier:walk; 51, argument_list; 51, 52; 52, identifier:folder; 53, block; 53, 54; 54, for_statement; 54, 55; 54, 56; 54, 57; 55, identifier:filename; 56, identifier:files; 57, block; 57, 58; 57, 70; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:filename; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:os; 65, identifier:path; 66, identifier:join; 67, argument_list; 67, 68; 67, 69; 68, identifier:root; 69, identifier:filename; 70, for_statement; 70, 71; 70, 72; 70, 73; 71, identifier:ext; 72, identifier:SUPPORTED_FILES; 73, block; 73, 74; 74, if_statement; 74, 75; 74, 81; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:filename; 78, identifier:endswith; 79, argument_list; 79, 80; 80, identifier:ext; 81, block; 81, 82; 81, 91; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:wbook; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:xlrd; 88, identifier:open_workbook; 89, argument_list; 89, 90; 90, identifier:filename; 91, for_statement; 91, 92; 91, 93; 91, 98; 92, identifier:sheet; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:wbook; 96, identifier:sheets; 97, argument_list; 98, block; 98, 99; 99, if_statement; 99, 100; 99, 105; 100, comparison_operator:not; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:sheet; 103, identifier:name; 104, identifier:sessions; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:sessions; 110, identifier:append; 111, argument_list; 111, 112; 112, attribute; 112, 113; 112, 114; 113, identifier:sheet; 114, identifier:name; 115, elif_clause; 115, 116; 115, 117; 116, identifier:inputfile; 117, block; 117, 118; 117, 130; 118, if_statement; 118, 119; 118, 127; 119, call; 119, 120; 119, 125; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:os; 123, identifier:path; 124, identifier:isdir; 125, argument_list; 125, 126; 126, identifier:inputfile; 127, block; 127, 128; 128, return_statement; 128, 129; 129, identifier:sessions; 130, for_statement; 130, 131; 130, 132; 130, 133; 131, identifier:ext; 132, identifier:SUPPORTED_FILES; 133, block; 133, 134; 134, if_statement; 134, 135; 134, 141; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:inputfile; 138, identifier:endswith; 139, argument_list; 139, 140; 140, identifier:ext; 141, block; 141, 142; 141, 151; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:wbook; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:xlrd; 148, identifier:open_workbook; 149, argument_list; 149, 150; 150, identifier:inputfile; 151, for_statement; 151, 152; 151, 153; 151, 158; 152, identifier:sheet; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:wbook; 156, identifier:sheets; 157, argument_list; 158, block; 158, 159; 159, if_statement; 159, 160; 159, 165; 160, comparison_operator:not; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:sheet; 163, identifier:name; 164, identifier:sessions; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:sessions; 170, identifier:append; 171, argument_list; 171, 172; 172, attribute; 172, 173; 172, 174; 173, identifier:sheet; 174, identifier:name; 175, return_statement; 175, 176; 176, identifier:sessions | def get_session_identifiers(cls, folder=None, inputfile=None):
sessions = []
if inputfile and folder:
raise MQ2Exception(
'You should specify either a folder or a file')
if folder:
if not os.path.isdir(folder):
return sessions
for root, dirs, files in os.walk(folder):
for filename in files:
filename = os.path.join(root, filename)
for ext in SUPPORTED_FILES:
if filename.endswith(ext):
wbook = xlrd.open_workbook(filename)
for sheet in wbook.sheets():
if sheet.name not in sessions:
sessions.append(sheet.name)
elif inputfile:
if os.path.isdir(inputfile):
return sessions
for ext in SUPPORTED_FILES:
if inputfile.endswith(ext):
wbook = xlrd.open_workbook(inputfile)
for sheet in wbook.sheets():
if sheet.name not in sessions:
sessions.append(sheet.name)
return sessions |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:template2regex; 3, parameters; 3, 4; 3, 5; 4, identifier:template; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ranges; 7, None; 8, block; 8, 9; 8, 45; 8, 54; 8, 58; 8, 62; 8, 79; 8, 83; 8, 87; 8, 92; 8, 96; 8, 100; 8, 104; 8, 310; 8, 322; 8, 334; 8, 344; 9, if_statement; 9, 10; 9, 30; 10, boolean_operator:and; 10, 11; 10, 15; 11, call; 11, 12; 11, 13; 12, identifier:len; 13, argument_list; 13, 14; 14, identifier:template; 15, comparison_operator:<; 15, 16; 15, 18; 15, 24; 16, unary_operator:-; 16, 17; 17, integer:1; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:template; 21, identifier:find; 22, argument_list; 22, 23; 23, string:'|'; 24, binary_operator:-; 24, 25; 24, 29; 25, call; 25, 26; 25, 27; 26, identifier:len; 27, argument_list; 27, 28; 28, identifier:template; 29, integer:1; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:InvalidTemplateError; 34, argument_list; 34, 35; 35, binary_operator:%; 35, 36; 35, 37; 36, string:"'|' may only appear at the end, found at position %d in %s"; 37, tuple; 37, 38; 37, 44; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:template; 41, identifier:find; 42, argument_list; 42, 43; 43, string:'|'; 44, identifier:template; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:ranges; 48, None; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:ranges; 53, identifier:DEFAULT_RANGES; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:anchor; 57, True; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:state; 61, identifier:S_PATH; 62, if_statement; 62, 63; 62, 74; 63, boolean_operator:and; 63, 64; 63, 68; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, identifier:template; 68, comparison_operator:==; 68, 69; 68, 73; 69, subscript; 69, 70; 69, 71; 70, identifier:template; 71, unary_operator:-; 71, 72; 72, integer:1; 73, string:'|'; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:anchor; 78, False; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:params; 82, list:[]; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:bracketdepth; 86, integer:0; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:result; 90, list:['^']; 90, 91; 91, string:'^'; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:name; 95, string:""; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:pattern; 99, string:"[^/]+"; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:rangename; 103, None; 104, for_statement; 104, 105; 104, 106; 104, 112; 105, identifier:c; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:template_splitter; 109, identifier:split; 110, argument_list; 110, 111; 111, identifier:template; 112, block; 112, 113; 113, if_statement; 113, 114; 113, 117; 113, 227; 114, comparison_operator:==; 114, 115; 114, 116; 115, identifier:state; 116, identifier:S_PATH; 117, block; 117, 118; 118, if_statement; 118, 119; 118, 125; 118, 138; 118, 154; 118, 182; 118, 195; 118, 207; 118, 213; 119, comparison_operator:>; 119, 120; 119, 124; 120, call; 120, 121; 120, 122; 121, identifier:len; 122, argument_list; 122, 123; 123, identifier:c; 124, integer:1; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:result; 130, identifier:append; 131, argument_list; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:re; 135, identifier:escape; 136, argument_list; 136, 137; 137, identifier:c; 138, elif_clause; 138, 139; 138, 142; 139, comparison_operator:==; 139, 140; 139, 141; 140, identifier:c; 141, string:'['; 142, block; 142, 143; 142, 150; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:result; 147, identifier:append; 148, argument_list; 148, 149; 149, string:"("; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 153; 152, identifier:bracketdepth; 153, integer:1; 154, elif_clause; 154, 155; 154, 158; 155, comparison_operator:==; 155, 156; 155, 157; 156, identifier:c; 157, string:']'; 158, block; 158, 159; 158, 163; 158, 175; 159, expression_statement; 159, 160; 160, augmented_assignment:-=; 160, 161; 160, 162; 161, identifier:bracketdepth; 162, integer:1; 163, if_statement; 163, 164; 163, 167; 164, comparison_operator:<; 164, 165; 164, 166; 165, identifier:bracketdepth; 166, integer:0; 167, block; 167, 168; 168, raise_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:InvalidTemplateError; 171, argument_list; 171, 172; 172, binary_operator:%; 172, 173; 172, 174; 173, string:"Mismatched brackets in %s"; 174, identifier:template; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:result; 179, identifier:append; 180, argument_list; 180, 181; 181, string:")?"; 182, elif_clause; 182, 183; 182, 186; 183, comparison_operator:==; 183, 184; 183, 185; 184, identifier:c; 185, string:'{'; 186, block; 186, 187; 186, 191; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:name; 190, string:""; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:state; 194, identifier:S_TEMPLATE; 195, elif_clause; 195, 196; 195, 199; 196, comparison_operator:==; 196, 197; 196, 198; 197, identifier:c; 198, string:'}'; 199, block; 199, 200; 200, raise_statement; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:InvalidTemplateError; 203, argument_list; 203, 204; 204, binary_operator:%; 204, 205; 204, 206; 205, string:"Mismatched braces in %s"; 206, identifier:template; 207, elif_clause; 207, 208; 207, 211; 208, comparison_operator:==; 208, 209; 208, 210; 209, identifier:c; 210, string:'|'; 211, block; 211, 212; 212, pass_statement; 213, else_clause; 213, 214; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:result; 219, identifier:append; 220, argument_list; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:re; 224, identifier:escape; 225, argument_list; 225, 226; 226, identifier:c; 227, else_clause; 227, 228; 228, block; 228, 229; 229, if_statement; 229, 230; 229, 233; 229, 282; 230, comparison_operator:==; 230, 231; 230, 232; 231, identifier:c; 232, string:'}'; 233, block; 233, 234; 233, 267; 233, 274; 233, 278; 234, if_statement; 234, 235; 234, 240; 234, 254; 235, boolean_operator:and; 235, 236; 235, 237; 236, identifier:rangename; 237, comparison_operator:in; 237, 238; 237, 239; 238, identifier:rangename; 239, identifier:ranges; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:result; 245, identifier:append; 246, argument_list; 246, 247; 247, binary_operator:%; 247, 248; 247, 249; 248, string:"(?P<%s>%s)"; 249, tuple; 249, 250; 249, 251; 250, identifier:name; 251, subscript; 251, 252; 251, 253; 252, identifier:ranges; 253, identifier:rangename; 254, else_clause; 254, 255; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:result; 260, identifier:append; 261, argument_list; 261, 262; 262, binary_operator:%; 262, 263; 262, 264; 263, string:"(?P<%s>%s)"; 264, tuple; 264, 265; 264, 266; 265, identifier:name; 266, identifier:pattern; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:params; 271, identifier:append; 272, argument_list; 272, 273; 273, identifier:name; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:state; 277, identifier:S_PATH; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:rangename; 281, None; 282, else_clause; 282, 283; 283, block; 283, 284; 283, 288; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:name; 287, identifier:c; 288, if_statement; 288, 289; 288, 298; 289, comparison_operator:>; 289, 290; 289, 296; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:name; 293, identifier:find; 294, argument_list; 294, 295; 295, string:":"; 296, unary_operator:-; 296, 297; 297, integer:1; 298, block; 298, 299; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 304; 301, pattern_list; 301, 302; 301, 303; 302, identifier:name; 303, identifier:rangename; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:name; 307, identifier:split; 308, argument_list; 308, 309; 309, string:":"; 310, if_statement; 310, 311; 310, 314; 311, comparison_operator:!=; 311, 312; 311, 313; 312, identifier:bracketdepth; 313, integer:0; 314, block; 314, 315; 315, raise_statement; 315, 316; 316, call; 316, 317; 316, 318; 317, identifier:InvalidTemplateError; 318, argument_list; 318, 319; 319, binary_operator:%; 319, 320; 319, 321; 320, string:"Mismatched brackets in %s"; 321, identifier:template; 322, if_statement; 322, 323; 322, 326; 323, comparison_operator:==; 323, 324; 323, 325; 324, identifier:state; 325, identifier:S_TEMPLATE; 326, block; 326, 327; 327, raise_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:InvalidTemplateError; 330, argument_list; 330, 331; 331, binary_operator:%; 331, 332; 331, 333; 332, string:"Mismatched braces in %s"; 333, identifier:template; 334, if_statement; 334, 335; 334, 336; 335, identifier:anchor; 336, block; 336, 337; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:result; 341, identifier:append; 342, argument_list; 342, 343; 343, string:'$'; 344, return_statement; 344, 345; 345, expression_list; 345, 346; 345, 352; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, string:""; 349, identifier:join; 350, argument_list; 350, 351; 351, identifier:result; 352, identifier:params | def template2regex(template, ranges=None):
if len(template) and -1 < template.find('|') < len(template) - 1:
raise InvalidTemplateError("'|' may only appear at the end, found at position %d in %s" % (template.find('|'), template))
if ranges is None:
ranges = DEFAULT_RANGES
anchor = True
state = S_PATH
if len(template) and template[-1] == '|':
anchor = False
params = []
bracketdepth = 0
result = ['^']
name = ""
pattern = "[^/]+"
rangename = None
for c in template_splitter.split(template):
if state == S_PATH:
if len(c) > 1:
result.append(re.escape(c))
elif c == '[':
result.append("(")
bracketdepth += 1
elif c == ']':
bracketdepth -= 1
if bracketdepth < 0:
raise InvalidTemplateError("Mismatched brackets in %s" % template)
result.append(")?")
elif c == '{':
name = ""
state = S_TEMPLATE
elif c == '}':
raise InvalidTemplateError("Mismatched braces in %s" % template)
elif c == '|':
pass
else:
result.append(re.escape(c))
else:
if c == '}':
if rangename and rangename in ranges:
result.append("(?P<%s>%s)" % (name, ranges[rangename]))
else:
result.append("(?P<%s>%s)" % (name, pattern))
params.append(name)
state = S_PATH
rangename = None
else:
name = c
if name.find(":") > -1:
name, rangename = name.split(":")
if bracketdepth != 0:
raise InvalidTemplateError("Mismatched brackets in %s" % template)
if state == S_TEMPLATE:
raise InvalidTemplateError("Mismatched braces in %s" % template)
if anchor:
result.append('$')
return "".join(result), params |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:path; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:target; 6, identifier:args; 7, identifier:kw; 8, block; 8, 9; 9, if_statement; 9, 10; 9, 16; 9, 93; 9, 132; 10, comparison_operator:in; 10, 11; 10, 15; 11, call; 11, 12; 11, 13; 12, identifier:type; 13, argument_list; 13, 14; 14, identifier:target; 15, identifier:string_types; 16, block; 16, 17; 17, if_statement; 17, 18; 17, 21; 17, 79; 18, comparison_operator:in; 18, 19; 18, 20; 19, string:':'; 20, identifier:target; 21, block; 21, 22; 21, 34; 21, 42; 21, 52; 21, 62; 21, 68; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, pattern_list; 24, 25; 24, 26; 25, identifier:prefix; 26, identifier:rest; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:target; 30, identifier:split; 31, argument_list; 31, 32; 31, 33; 32, string:':'; 33, integer:1; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:route; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:named_routes; 41, identifier:prefix; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:prefix_params; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:route; 48, identifier:_pop_params; 49, argument_list; 49, 50; 49, 51; 50, identifier:args; 51, identifier:kw; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:prefix_path; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:route; 58, identifier:path; 59, argument_list; 59, 60; 59, 61; 60, list:[]; 61, identifier:prefix_params; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:next_mapper; 65, attribute; 65, 66; 65, 67; 66, identifier:route; 67, identifier:resource; 68, return_statement; 68, 69; 69, binary_operator:+; 69, 70; 69, 71; 70, identifier:prefix_path; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:next_mapper; 74, identifier:path; 75, argument_list; 75, 76; 75, 77; 75, 78; 76, identifier:rest; 77, identifier:args; 78, identifier:kw; 79, else_clause; 79, 80; 80, block; 80, 81; 81, return_statement; 81, 82; 82, call; 82, 83; 82, 90; 83, attribute; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:named_routes; 88, identifier:target; 89, identifier:path; 90, argument_list; 90, 91; 90, 92; 91, identifier:args; 92, identifier:kw; 93, elif_clause; 93, 94; 93, 99; 94, call; 94, 95; 94, 96; 95, identifier:isinstance; 96, argument_list; 96, 97; 96, 98; 97, identifier:target; 98, identifier:Route; 99, block; 99, 100; 99, 119; 100, for_statement; 100, 101; 100, 102; 100, 105; 101, identifier:route; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:routes; 105, block; 105, 106; 106, if_statement; 106, 107; 106, 110; 107, comparison_operator:is; 107, 108; 107, 109; 108, identifier:route; 109, identifier:target; 110, block; 110, 111; 111, return_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:route; 115, identifier:path; 116, argument_list; 116, 117; 116, 118; 117, identifier:args; 118, identifier:kw; 119, raise_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:InvalidArgumentError; 122, argument_list; 122, 123; 123, binary_operator:%; 123, 124; 123, 125; 124, string:"Route '%s' not found in this %s object."; 125, tuple; 125, 126; 125, 127; 126, identifier:target; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:__class__; 131, identifier:__name__; 132, else_clause; 132, 133; 133, block; 133, 134; 133, 141; 133, 160; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:target_id; 137, call; 137, 138; 137, 139; 138, identifier:id; 139, argument_list; 139, 140; 140, identifier:target; 141, if_statement; 141, 142; 141, 147; 142, comparison_operator:in; 142, 143; 142, 144; 143, identifier:target_id; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:_lookup; 147, block; 147, 148; 148, return_statement; 148, 149; 149, call; 149, 150; 149, 157; 150, attribute; 150, 151; 150, 156; 151, subscript; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:_lookup; 155, identifier:target_id; 156, identifier:path; 157, argument_list; 157, 158; 157, 159; 158, identifier:args; 159, identifier:kw; 160, raise_statement; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:InvalidArgumentError; 163, argument_list; 163, 164; 164, binary_operator:%; 164, 165; 164, 166; 165, string:"No Route found for target '%s' in this %s object."; 166, tuple; 166, 167; 166, 168; 167, identifier:target; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:__class__; 172, identifier:__name__ | def path(self, target, args, kw):
if type(target) in string_types:
if ':' in target:
prefix, rest = target.split(':', 1)
route = self.named_routes[prefix]
prefix_params = route._pop_params(args, kw)
prefix_path = route.path([], prefix_params)
next_mapper = route.resource
return prefix_path + next_mapper.path(rest, args, kw)
else:
return self.named_routes[target].path(args, kw)
elif isinstance(target, Route):
for route in self.routes:
if route is target:
return route.path(args, kw)
raise InvalidArgumentError("Route '%s' not found in this %s object." % (target, self.__class__.__name__))
else:
target_id = id(target)
if target_id in self._lookup:
return self._lookup[target_id].path(args, kw)
raise InvalidArgumentError("No Route found for target '%s' in this %s object." % (target, self.__class__.__name__)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_children_graph; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:item_ids; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:language; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:forbidden_item_ids; 13, None; 14, block; 14, 15; 14, 26; 14, 133; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:forbidden_item_ids; 18, None; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:forbidden_item_ids; 23, call; 23, 24; 23, 25; 24, identifier:set; 25, argument_list; 26, function_definition; 26, 27; 26, 28; 26, 30; 27, function_name:_children; 28, parameters; 28, 29; 29, identifier:item_ids; 30, block; 30, 31; 30, 92; 31, if_statement; 31, 32; 31, 35; 31, 54; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:item_ids; 34, None; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:items; 39, call; 39, 40; 39, 52; 40, attribute; 40, 41; 40, 51; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:Item; 45, identifier:objects; 46, identifier:filter; 47, argument_list; 47, 48; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:active; 50, True; 51, identifier:prefetch_related; 52, argument_list; 52, 53; 53, string:'children'; 54, else_clause; 54, 55; 55, block; 55, 56; 55, 71; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:item_ids; 59, list_comprehension; 59, 60; 59, 61; 59, 68; 60, identifier:ii; 61, for_in_clause; 61, 62; 61, 63; 62, identifier:iis; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:item_ids; 66, identifier:values; 67, argument_list; 68, for_in_clause; 68, 69; 68, 70; 69, identifier:ii; 70, identifier:iis; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:items; 74, call; 74, 75; 74, 90; 75, attribute; 75, 76; 75, 89; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:Item; 80, identifier:objects; 81, identifier:filter; 82, argument_list; 82, 83; 82, 86; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:id__in; 85, identifier:item_ids; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:active; 88, True; 89, identifier:prefetch_related; 90, argument_list; 90, 91; 91, string:'children'; 92, return_statement; 92, 93; 93, dictionary_comprehension; 93, 94; 93, 124; 93, 127; 94, pair; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:item; 97, identifier:id; 98, call; 98, 99; 98, 100; 99, identifier:sorted; 100, argument_list; 100, 101; 101, list_comprehension; 101, 102; 101, 105; 101, 114; 102, attribute; 102, 103; 102, 104; 103, identifier:_item; 104, identifier:id; 105, for_in_clause; 105, 106; 105, 107; 106, identifier:_item; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:item; 111, identifier:children; 112, identifier:all; 113, argument_list; 114, if_clause; 114, 115; 115, boolean_operator:and; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:_item; 118, identifier:active; 119, comparison_operator:not; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:_item; 122, identifier:id; 123, identifier:forbidden_item_ids; 124, for_in_clause; 124, 125; 124, 126; 125, identifier:item; 126, identifier:items; 127, if_clause; 127, 128; 128, comparison_operator:not; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:item; 131, identifier:id; 132, identifier:forbidden_item_ids; 133, if_statement; 133, 134; 133, 137; 133, 149; 134, comparison_operator:is; 134, 135; 134, 136; 135, identifier:item_ids; 136, None; 137, block; 137, 138; 138, return_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:_reachable_graph; 143, argument_list; 143, 144; 143, 145; 143, 146; 144, None; 145, identifier:_children; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:language; 148, identifier:language; 149, else_clause; 149, 150; 150, block; 150, 151; 150, 164; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:graph; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:get_children_graph; 158, argument_list; 158, 159; 158, 160; 158, 161; 159, None; 160, identifier:language; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:forbidden_item_ids; 163, identifier:forbidden_item_ids; 164, return_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:_subset_graph; 169, argument_list; 169, 170; 169, 171; 170, identifier:graph; 171, binary_operator:-; 171, 172; 171, 176; 172, call; 172, 173; 172, 174; 173, identifier:set; 174, argument_list; 174, 175; 175, identifier:item_ids; 176, call; 176, 177; 176, 178; 177, identifier:set; 178, argument_list; 178, 179; 179, identifier:forbidden_item_ids | def get_children_graph(self, item_ids=None, language=None, forbidden_item_ids=None):
if forbidden_item_ids is None:
forbidden_item_ids = set()
def _children(item_ids):
if item_ids is None:
items = Item.objects.filter(active=True).prefetch_related('children')
else:
item_ids = [ii for iis in item_ids.values() for ii in iis]
items = Item.objects.filter(id__in=item_ids, active=True).prefetch_related('children')
return {
item.id: sorted([
_item.id for _item in item.children.all()
if _item.active and _item.id not in forbidden_item_ids
])
for item in items if item.id not in forbidden_item_ids
}
if item_ids is None:
return self._reachable_graph(None, _children, language=language)
else:
graph = self.get_children_graph(None, language, forbidden_item_ids=forbidden_item_ids)
return self._subset_graph(graph, set(item_ids) - set(forbidden_item_ids)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_parents_graph; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:item_ids; 6, default_parameter; 6, 7; 6, 8; 7, identifier:language; 8, None; 9, block; 9, 10; 9, 101; 9, 112; 10, function_definition; 10, 11; 10, 12; 10, 14; 11, function_name:_parents; 12, parameters; 12, 13; 13, identifier:item_ids; 14, block; 14, 15; 14, 76; 15, if_statement; 15, 16; 15, 19; 15, 38; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:item_ids; 18, None; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:items; 23, call; 23, 24; 23, 36; 24, attribute; 24, 25; 24, 35; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:Item; 29, identifier:objects; 30, identifier:filter; 31, argument_list; 31, 32; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:active; 34, True; 35, identifier:prefetch_related; 36, argument_list; 36, 37; 37, string:'parents'; 38, else_clause; 38, 39; 39, block; 39, 40; 39, 55; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:item_ids; 43, list_comprehension; 43, 44; 43, 45; 43, 52; 44, identifier:ii; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:iis; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:item_ids; 50, identifier:values; 51, argument_list; 52, for_in_clause; 52, 53; 52, 54; 53, identifier:ii; 54, identifier:iis; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:items; 58, call; 58, 59; 58, 74; 59, attribute; 59, 60; 59, 73; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:Item; 64, identifier:objects; 65, identifier:filter; 66, argument_list; 66, 67; 66, 70; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:id__in; 69, identifier:item_ids; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:active; 72, True; 73, identifier:prefetch_related; 74, argument_list; 74, 75; 75, string:'parents'; 76, return_statement; 76, 77; 77, dictionary_comprehension; 77, 78; 77, 98; 78, pair; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:item; 81, identifier:id; 82, call; 82, 83; 82, 84; 83, identifier:sorted; 84, argument_list; 84, 85; 85, list_comprehension; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:_item; 88, identifier:id; 89, for_in_clause; 89, 90; 89, 91; 90, identifier:_item; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:item; 95, identifier:parents; 96, identifier:all; 97, argument_list; 98, for_in_clause; 98, 99; 98, 100; 99, identifier:item; 100, identifier:items; 101, return_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_reachable_graph; 106, argument_list; 106, 107; 106, 108; 106, 109; 107, identifier:item_ids; 108, identifier:_parents; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:language; 111, identifier:language; 112, if_statement; 112, 113; 112, 116; 112, 128; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:item_ids; 115, None; 116, block; 116, 117; 117, return_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:_reachable_graph; 122, argument_list; 122, 123; 122, 124; 122, 125; 123, None; 124, identifier:_parents; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:language; 127, identifier:language; 128, else_clause; 128, 129; 129, block; 129, 130; 129, 140; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:graph; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:get_parents_graph; 137, argument_list; 137, 138; 137, 139; 138, None; 139, identifier:language; 140, return_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:_subset_graph; 145, argument_list; 145, 146; 145, 147; 146, identifier:graph; 147, identifier:item_ids | def get_parents_graph(self, item_ids, language=None):
def _parents(item_ids):
if item_ids is None:
items = Item.objects.filter(active=True).prefetch_related('parents')
else:
item_ids = [ii for iis in item_ids.values() for ii in iis]
items = Item.objects.filter(id__in=item_ids, active=True).prefetch_related('parents')
return {item.id: sorted([_item.id for _item in item.parents.all()]) for item in items}
return self._reachable_graph(item_ids, _parents, language=language)
if item_ids is None:
return self._reachable_graph(None, _parents, language=language)
else:
graph = self.get_parents_graph(None, language)
return self._subset_graph(graph, item_ids) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_graph; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:item_ids; 6, default_parameter; 6, 7; 6, 8; 7, identifier:language; 8, None; 9, block; 9, 10; 9, 114; 10, function_definition; 10, 11; 10, 12; 10, 14; 11, function_name:_related; 12, parameters; 12, 13; 13, identifier:item_ids; 14, block; 14, 15; 14, 78; 15, if_statement; 15, 16; 15, 19; 15, 39; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:item_ids; 18, None; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:items; 23, call; 23, 24; 23, 36; 24, attribute; 24, 25; 24, 35; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:Item; 29, identifier:objects; 30, identifier:filter; 31, argument_list; 31, 32; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:active; 34, True; 35, identifier:prefetch_related; 36, argument_list; 36, 37; 36, 38; 37, string:'parents'; 38, string:'children'; 39, else_clause; 39, 40; 40, block; 40, 41; 40, 56; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:item_ids; 44, list_comprehension; 44, 45; 44, 46; 44, 53; 45, identifier:ii; 46, for_in_clause; 46, 47; 46, 48; 47, identifier:iis; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:item_ids; 51, identifier:values; 52, argument_list; 53, for_in_clause; 53, 54; 53, 55; 54, identifier:ii; 55, identifier:iis; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:items; 59, call; 59, 60; 59, 75; 60, attribute; 60, 61; 60, 74; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:Item; 65, identifier:objects; 66, identifier:filter; 67, argument_list; 67, 68; 67, 71; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:id__in; 70, identifier:item_ids; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:active; 73, True; 74, identifier:prefetch_related; 75, argument_list; 75, 76; 75, 77; 76, string:'parents'; 77, string:'children'; 78, return_statement; 78, 79; 79, dictionary_comprehension; 79, 80; 79, 111; 80, pair; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:item; 83, identifier:id; 84, call; 84, 85; 84, 86; 85, identifier:sorted; 86, argument_list; 86, 87; 87, list_comprehension; 87, 88; 87, 91; 87, 108; 88, attribute; 88, 89; 88, 90; 89, identifier:_item; 90, identifier:id; 91, for_in_clause; 91, 92; 91, 93; 92, identifier:rel; 93, list:[item.parents.all(), item.children.all()]; 93, 94; 93, 101; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:item; 98, identifier:parents; 99, identifier:all; 100, argument_list; 101, call; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:item; 105, identifier:children; 106, identifier:all; 107, argument_list; 108, for_in_clause; 108, 109; 108, 110; 109, identifier:_item; 110, identifier:rel; 111, for_in_clause; 111, 112; 111, 113; 112, identifier:item; 113, identifier:items; 114, if_statement; 114, 115; 114, 118; 114, 130; 115, comparison_operator:is; 115, 116; 115, 117; 116, identifier:item_ids; 117, None; 118, block; 118, 119; 119, return_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:_reachable_graph; 124, argument_list; 124, 125; 124, 126; 124, 127; 125, None; 126, identifier:_related; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:language; 129, identifier:language; 130, else_clause; 130, 131; 131, block; 131, 132; 131, 142; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:graph; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:get_graph; 139, argument_list; 139, 140; 139, 141; 140, None; 141, identifier:language; 142, return_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:_subset_graph; 147, argument_list; 147, 148; 147, 149; 148, identifier:graph; 149, identifier:item_ids | def get_graph(self, item_ids, language=None):
def _related(item_ids):
if item_ids is None:
items = Item.objects.filter(active=True).prefetch_related('parents', 'children')
else:
item_ids = [ii for iis in item_ids.values() for ii in iis]
items = Item.objects.filter(id__in=item_ids, active=True).prefetch_related('parents', 'children')
return {item.id: sorted([_item.id for rel in [item.parents.all(), item.children.all()] for _item in rel]) for item in items}
if item_ids is None:
return self._reachable_graph(None, _related, language=language)
else:
graph = self.get_graph(None, language)
return self._subset_graph(graph, item_ids) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:translate_item_ids; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:item_ids; 6, identifier:language; 7, default_parameter; 7, 8; 7, 9; 8, identifier:is_nested; 9, None; 10, block; 10, 11; 10, 43; 10, 53; 10, 72; 10, 76; 10, 244; 11, if_statement; 11, 12; 11, 15; 11, 23; 11, 37; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:is_nested; 14, None; 15, block; 15, 16; 16, function_definition; 16, 17; 16, 18; 16, 20; 17, function_name:is_nested_fun; 18, parameters; 18, 19; 19, identifier:x; 20, block; 20, 21; 21, return_statement; 21, 22; 22, True; 23, elif_clause; 23, 24; 23, 29; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 28; 27, identifier:is_nested; 28, identifier:bool; 29, block; 29, 30; 30, function_definition; 30, 31; 30, 32; 30, 34; 31, function_name:is_nested_fun; 32, parameters; 32, 33; 33, identifier:x; 34, block; 34, 35; 35, return_statement; 35, 36; 36, identifier:is_nested; 37, else_clause; 37, 38; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:is_nested_fun; 42, identifier:is_nested; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:all_item_type_ids; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:ItemType; 50, identifier:objects; 51, identifier:get_all_item_type_ids; 52, argument_list; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:groupped; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:proso; 60, identifier:list; 61, identifier:group_by; 62, argument_list; 62, 63; 62, 64; 63, identifier:item_ids; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:by; 66, lambda; 66, 67; 66, 69; 67, lambda_parameters; 67, 68; 68, identifier:item_id; 69, subscript; 69, 70; 69, 71; 70, identifier:all_item_type_ids; 71, identifier:item_id; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:result; 75, dictionary; 76, for_statement; 76, 77; 76, 80; 76, 85; 77, pattern_list; 77, 78; 77, 79; 78, identifier:item_type_id; 79, identifier:items; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:groupped; 83, identifier:items; 84, argument_list; 85, block; 85, 86; 86, with_statement; 86, 87; 86, 98; 87, with_clause; 87, 88; 88, with_item; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:timeit; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, string:'translating item type {}'; 95, identifier:format; 96, argument_list; 96, 97; 97, identifier:item_type_id; 98, block; 98, 99; 98, 111; 98, 122; 98, 136; 98, 149; 98, 208; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:item_type; 102, subscript; 102, 103; 102, 110; 103, call; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:ItemType; 107, identifier:objects; 108, identifier:get_all_types; 109, argument_list; 110, identifier:item_type_id; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:model; 114, call; 114, 115; 114, 120; 115, attribute; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:ItemType; 118, identifier:objects; 119, identifier:get_model; 120, argument_list; 120, 121; 121, identifier:item_type_id; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:kwargs; 125, dictionary; 125, 126; 126, pair; 126, 127; 126, 135; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, string:'{}__in'; 130, identifier:format; 131, argument_list; 131, 132; 132, subscript; 132, 133; 132, 134; 133, identifier:item_type; 134, string:'foreign_key'; 135, identifier:items; 136, if_statement; 136, 137; 136, 140; 137, comparison_operator:in; 137, 138; 137, 139; 138, string:'language'; 139, identifier:item_type; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 148; 143, subscript; 143, 144; 143, 145; 144, identifier:kwargs; 145, subscript; 145, 146; 145, 147; 146, identifier:item_type; 147, string:'language'; 148, identifier:language; 149, if_statement; 149, 150; 149, 170; 149, 181; 149, 200; 150, boolean_operator:and; 150, 151; 150, 163; 151, call; 151, 152; 151, 153; 152, identifier:any; 153, argument_list; 153, 154; 154, list_comprehension; 154, 155; 154, 160; 155, not_operator; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:is_nested_fun; 158, argument_list; 158, 159; 159, identifier:item_id; 160, for_in_clause; 160, 161; 160, 162; 161, identifier:item_id; 162, identifier:items; 163, call; 163, 164; 163, 165; 164, identifier:hasattr; 165, argument_list; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:model; 168, identifier:objects; 169, string:'prepare_related'; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:objs; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:model; 178, identifier:objects; 179, identifier:prepare_related; 180, argument_list; 181, elif_clause; 181, 182; 181, 189; 182, call; 182, 183; 182, 184; 183, identifier:hasattr; 184, argument_list; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:model; 187, identifier:objects; 188, string:'prepare'; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:objs; 193, call; 193, 194; 193, 199; 194, attribute; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:model; 197, identifier:objects; 198, identifier:prepare; 199, argument_list; 200, else_clause; 200, 201; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:objs; 205, attribute; 205, 206; 205, 207; 206, identifier:model; 207, identifier:objects; 208, for_statement; 208, 209; 208, 210; 208, 217; 209, identifier:obj; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:objs; 213, identifier:filter; 214, argument_list; 214, 215; 215, dictionary_splat; 215, 216; 216, identifier:kwargs; 217, block; 217, 218; 217, 228; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:item_id; 221, call; 221, 222; 221, 223; 222, identifier:getattr; 223, argument_list; 223, 224; 223, 225; 224, identifier:obj; 225, subscript; 225, 226; 225, 227; 226, identifier:item_type; 227, string:'foreign_key'; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 233; 230, subscript; 230, 231; 230, 232; 231, identifier:result; 232, identifier:item_id; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:obj; 236, identifier:to_json; 237, argument_list; 237, 238; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:nested; 240, call; 240, 241; 240, 242; 241, identifier:is_nested_fun; 242, argument_list; 242, 243; 243, identifier:item_id; 244, return_statement; 244, 245; 245, identifier:result | def translate_item_ids(self, item_ids, language, is_nested=None):
if is_nested is None:
def is_nested_fun(x):
return True
elif isinstance(is_nested, bool):
def is_nested_fun(x):
return is_nested
else:
is_nested_fun = is_nested
all_item_type_ids = ItemType.objects.get_all_item_type_ids()
groupped = proso.list.group_by(item_ids, by=lambda item_id: all_item_type_ids[item_id])
result = {}
for item_type_id, items in groupped.items():
with timeit('translating item type {}'.format(item_type_id)):
item_type = ItemType.objects.get_all_types()[item_type_id]
model = ItemType.objects.get_model(item_type_id)
kwargs = {'{}__in'.format(item_type['foreign_key']): items}
if 'language' in item_type:
kwargs[item_type['language']] = language
if any([not is_nested_fun(item_id) for item_id in items]) and hasattr(model.objects, 'prepare_related'):
objs = model.objects.prepare_related()
elif hasattr(model.objects, 'prepare'):
objs = model.objects.prepare()
else:
objs = model.objects
for obj in objs.filter(**kwargs):
item_id = getattr(obj, item_type['foreign_key'])
result[item_id] = obj.to_json(nested=is_nested_fun(item_id))
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_leaves; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:item_ids; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:language; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:forbidden_item_ids; 13, None; 14, block; 14, 15; 14, 29; 14, 44; 14, 55; 14, 71; 14, 216; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:forbidden_item_ids; 18, conditional_expression:if; 18, 19; 18, 22; 18, 25; 19, call; 19, 20; 19, 21; 20, identifier:set; 21, argument_list; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:forbidden_item_ids; 24, None; 25, call; 25, 26; 25, 27; 26, identifier:set; 27, argument_list; 27, 28; 28, identifier:forbidden_item_ids; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:children; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:get_children_graph; 36, argument_list; 36, 37; 36, 38; 36, 41; 37, identifier:item_ids; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:language; 40, identifier:language; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:forbidden_item_ids; 43, identifier:forbidden_item_ids; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:counts; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:get_children_counts; 51, argument_list; 51, 52; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:active; 54, None; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:item_ids; 58, None; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:item_ids; 63, call; 63, 64; 63, 65; 64, identifier:set; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:children; 69, identifier:keys; 70, argument_list; 71, function_definition; 71, 72; 71, 73; 71, 75; 72, function_name:_get_leaves; 73, parameters; 73, 74; 74, identifier:item_id; 75, block; 75, 76; 75, 82; 75, 134; 75, 174; 75, 188; 75, 198; 75, 212; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:leaves; 79, call; 79, 80; 79, 81; 80, identifier:set; 81, argument_list; 82, function_definition; 82, 83; 82, 84; 82, 86; 83, function_name:__search; 84, parameters; 84, 85; 85, identifier:item_ids; 86, block; 86, 87; 86, 107; 86, 123; 86, 130; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:result; 90, call; 90, 91; 90, 92; 91, identifier:set; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:flatten; 95, argument_list; 95, 96; 96, list_comprehension; 96, 97; 96, 104; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:children; 100, identifier:get; 101, argument_list; 101, 102; 101, 103; 102, identifier:item_id; 103, list:[]; 104, for_in_clause; 104, 105; 104, 106; 105, identifier:item_id; 106, identifier:item_ids; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:new_leaves; 110, set_comprehension; 110, 111; 110, 112; 110, 115; 111, identifier:item_id; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:item_id; 114, identifier:result; 115, if_clause; 115, 116; 116, comparison_operator:not; 116, 117; 116, 118; 117, identifier:item_id; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:children; 121, identifier:keys; 122, argument_list; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:leaves; 127, identifier:update; 128, argument_list; 128, 129; 129, identifier:new_leaves; 130, return_statement; 130, 131; 131, binary_operator:-; 131, 132; 131, 133; 132, identifier:result; 133, identifier:new_leaves; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:fixed_point; 137, argument_list; 137, 138; 137, 149; 137, 158; 137, 167; 137, 170; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:is_zero; 140, lambda; 140, 141; 140, 143; 141, lambda_parameters; 141, 142; 142, identifier:to_visit; 143, comparison_operator:==; 143, 144; 143, 148; 144, call; 144, 145; 144, 146; 145, identifier:len; 146, argument_list; 146, 147; 147, identifier:to_visit; 148, integer:0; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:minus; 151, lambda; 151, 152; 151, 155; 152, lambda_parameters; 152, 153; 152, 154; 153, identifier:to_visit; 154, identifier:visited; 155, binary_operator:-; 155, 156; 155, 157; 156, identifier:to_visit; 157, identifier:visited; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:plus; 160, lambda; 160, 161; 160, 164; 161, lambda_parameters; 161, 162; 161, 163; 162, identifier:visited_x; 163, identifier:visited_y; 164, binary_operator:|; 164, 165; 164, 166; 165, identifier:visited_x; 166, identifier:visited_y; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:f; 169, identifier:__search; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:x; 172, set; 172, 173; 173, identifier:item_id; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:leaves; 177, set_comprehension; 177, 178; 177, 179; 177, 182; 178, identifier:leaf; 179, for_in_clause; 179, 180; 179, 181; 180, identifier:leaf; 181, identifier:leaves; 182, if_clause; 182, 183; 183, comparison_operator:==; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:counts; 186, identifier:leaf; 187, integer:0; 188, if_statement; 188, 189; 188, 195; 189, comparison_operator:>; 189, 190; 189, 194; 190, call; 190, 191; 190, 192; 191, identifier:len; 192, argument_list; 192, 193; 193, identifier:leaves; 194, integer:0; 195, block; 195, 196; 196, return_statement; 196, 197; 197, identifier:leaves; 198, if_statement; 198, 199; 198, 208; 199, boolean_operator:and; 199, 200; 199, 205; 200, comparison_operator:==; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:counts; 203, identifier:item_id; 204, integer:0; 205, comparison_operator:not; 205, 206; 205, 207; 206, identifier:item_id; 207, identifier:forbidden_item_ids; 208, block; 208, 209; 209, return_statement; 209, 210; 210, set; 210, 211; 211, identifier:item_id; 212, return_statement; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:set; 215, argument_list; 216, return_statement; 216, 217; 217, dictionary_comprehension; 217, 218; 217, 224; 218, pair; 218, 219; 218, 220; 219, identifier:item_id; 220, call; 220, 221; 220, 222; 221, identifier:_get_leaves; 222, argument_list; 222, 223; 223, identifier:item_id; 224, for_in_clause; 224, 225; 224, 226; 225, identifier:item_id; 226, identifier:item_ids | def get_leaves(self, item_ids=None, language=None, forbidden_item_ids=None):
forbidden_item_ids = set() if forbidden_item_ids is None else set(forbidden_item_ids)
children = self.get_children_graph(item_ids, language=language, forbidden_item_ids=forbidden_item_ids)
counts = self.get_children_counts(active=None)
if item_ids is None:
item_ids = set(children.keys())
def _get_leaves(item_id):
leaves = set()
def __search(item_ids):
result = set(flatten([children.get(item_id, []) for item_id in item_ids]))
new_leaves = {item_id for item_id in result if item_id not in children.keys()}
leaves.update(new_leaves)
return result - new_leaves
fixed_point(
is_zero=lambda to_visit: len(to_visit) == 0,
minus=lambda to_visit, visited: to_visit - visited,
plus=lambda visited_x, visited_y: visited_x | visited_y,
f=__search,
x={item_id}
)
leaves = {leaf for leaf in leaves if counts[leaf] == 0}
if len(leaves) > 0:
return leaves
if counts[item_id] == 0 and item_id not in forbidden_item_ids:
return {item_id}
return set()
return {item_id: _get_leaves(item_id) for item_id in item_ids} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:get_image; 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:imgtype; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:tags; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:nsfw; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:hidden; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:filetype; 19, None; 20, block; 20, 21; 20, 33; 20, 48; 20, 63; 20, 78; 20, 104; 20, 119; 20, 153; 21, if_statement; 21, 22; 21, 27; 22, boolean_operator:and; 22, 23; 22, 25; 23, not_operator; 23, 24; 24, identifier:imgtype; 25, not_operator; 25, 26; 26, identifier:tags; 27, block; 27, 28; 28, raise_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:MissingTypeOrTags; 31, argument_list; 31, 32; 32, string:"'get_image' requires at least one of either type or tags."; 33, if_statement; 33, 34; 33, 42; 34, boolean_operator:and; 34, 35; 34, 36; 35, identifier:imgtype; 36, not_operator; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:isinstance; 39, argument_list; 39, 40; 39, 41; 40, identifier:imgtype; 41, identifier:str; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:TypeError; 46, argument_list; 46, 47; 47, string:"type of 'imgtype' must be str."; 48, if_statement; 48, 49; 48, 57; 49, boolean_operator:and; 49, 50; 49, 51; 50, identifier:tags; 51, not_operator; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:isinstance; 54, argument_list; 54, 55; 54, 56; 55, identifier:tags; 56, identifier:list; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:TypeError; 61, argument_list; 61, 62; 62, string:"type of 'tags' must be list or None."; 63, if_statement; 63, 64; 63, 72; 64, boolean_operator:and; 64, 65; 64, 66; 65, identifier:hidden; 66, not_operator; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:isinstance; 69, argument_list; 69, 70; 69, 71; 70, identifier:hidden; 71, identifier:bool; 72, block; 72, 73; 73, raise_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:TypeError; 76, argument_list; 76, 77; 77, string:"type of 'hidden' must be bool or None."; 78, if_statement; 78, 79; 78, 98; 79, boolean_operator:and; 79, 80; 79, 88; 80, boolean_operator:and; 80, 81; 80, 82; 81, identifier:nsfw; 82, not_operator; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:isinstance; 85, argument_list; 85, 86; 85, 87; 86, identifier:nsfw; 87, identifier:bool; 88, parenthesized_expression; 88, 89; 89, boolean_operator:and; 89, 90; 89, 95; 90, call; 90, 91; 90, 92; 91, identifier:isinstance; 92, argument_list; 92, 93; 92, 94; 93, identifier:nsfw; 94, identifier:str; 95, comparison_operator:==; 95, 96; 95, 97; 96, identifier:nsfw; 97, string:'only'; 98, block; 98, 99; 99, raise_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:TypeError; 102, argument_list; 102, 103; 103, string:"type of 'nsfw' must be str, bool or None."; 104, if_statement; 104, 105; 104, 113; 105, boolean_operator:and; 105, 106; 105, 107; 106, identifier:filetype; 107, not_operator; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:isinstance; 110, argument_list; 110, 111; 110, 112; 111, identifier:filetype; 112, identifier:str; 113, block; 113, 114; 114, raise_statement; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:TypeError; 117, argument_list; 117, 118; 118, string:"type of 'filetype' must be str."; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:url; 122, binary_operator:+; 122, 123; 122, 148; 123, binary_operator:+; 123, 124; 123, 143; 124, binary_operator:+; 124, 125; 124, 138; 125, binary_operator:+; 125, 126; 125, 133; 126, binary_operator:+; 126, 127; 126, 128; 127, string:'https://api.weeb.sh/images/random'; 128, parenthesized_expression; 128, 129; 129, conditional_expression:if; 129, 130; 129, 131; 129, 132; 130, string:f'?type={imgtype}'; 131, identifier:imgtype; 132, string:''; 133, parenthesized_expression; 133, 134; 134, conditional_expression:if; 134, 135; 134, 136; 134, 137; 135, string:f'{"?" if not imgtype else "&"}tags={",".join(tags)}'; 136, identifier:tags; 137, string:''; 138, parenthesized_expression; 138, 139; 139, conditional_expression:if; 139, 140; 139, 141; 139, 142; 140, string:f'&nsfw={nsfw.lower()}'; 141, identifier:nsfw; 142, string:''; 143, parenthesized_expression; 143, 144; 144, conditional_expression:if; 144, 145; 144, 146; 144, 147; 145, string:f'&hidden={hidden}'; 146, identifier:hidden; 147, string:''; 148, parenthesized_expression; 148, 149; 149, conditional_expression:if; 149, 150; 149, 151; 149, 152; 150, string:f'&filetype={filetype}'; 151, identifier:filetype; 152, string:''; 153, with_statement; 153, 154; 153, 164; 154, with_clause; 154, 155; 155, with_item; 155, 156; 156, as_pattern; 156, 157; 156, 162; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:aiohttp; 160, identifier:ClientSession; 161, argument_list; 162, as_pattern_target; 162, 163; 163, identifier:session; 164, block; 164, 165; 165, with_statement; 165, 166; 165, 182; 166, with_clause; 166, 167; 167, with_item; 167, 168; 168, as_pattern; 168, 169; 168, 180; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:session; 172, identifier:get; 173, argument_list; 173, 174; 173, 175; 174, identifier:url; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:headers; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:__headers; 180, as_pattern_target; 180, 181; 181, identifier:resp; 182, block; 182, 183; 183, if_statement; 183, 184; 183, 189; 183, 210; 184, comparison_operator:==; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:resp; 187, identifier:status; 188, integer:200; 189, block; 189, 190; 189, 199; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:js; 193, await; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:resp; 197, identifier:json; 198, argument_list; 199, return_statement; 199, 200; 200, list:[js['url'], js['id'], js['fileType']]; 200, 201; 200, 204; 200, 207; 201, subscript; 201, 202; 201, 203; 202, identifier:js; 203, string:'url'; 204, subscript; 204, 205; 204, 206; 205, identifier:js; 206, string:'id'; 207, subscript; 207, 208; 207, 209; 208, identifier:js; 209, string:'fileType'; 210, else_clause; 210, 211; 211, block; 211, 212; 212, raise_statement; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:Exception; 215, argument_list; 215, 216; 216, subscript; 216, 217; 216, 224; 217, parenthesized_expression; 217, 218; 218, await; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:resp; 222, identifier:json; 223, argument_list; 224, string:'message' | async def get_image(self, imgtype=None, tags=None, nsfw=None, hidden=None, filetype=None):
if not imgtype and not tags:
raise MissingTypeOrTags("'get_image' requires at least one of either type or tags.")
if imgtype and not isinstance(imgtype, str):
raise TypeError("type of 'imgtype' must be str.")
if tags and not isinstance(tags, list):
raise TypeError("type of 'tags' must be list or None.")
if hidden and not isinstance(hidden, bool):
raise TypeError("type of 'hidden' must be bool or None.")
if nsfw and not isinstance(nsfw, bool) and (isinstance(nsfw, str) and nsfw == 'only'):
raise TypeError("type of 'nsfw' must be str, bool or None.")
if filetype and not isinstance(filetype, str):
raise TypeError("type of 'filetype' must be str.")
url = 'https://api.weeb.sh/images/random' + (f'?type={imgtype}' if imgtype else '') + (
f'{"?" if not imgtype else "&"}tags={",".join(tags)}' if tags else '') + (
f'&nsfw={nsfw.lower()}' if nsfw else '') + (f'&hidden={hidden}' if hidden else '') + (
f'&filetype={filetype}' if filetype else '')
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=self.__headers) as resp:
if resp.status == 200:
js = await resp.json()
return [js['url'], js['id'], js['fileType']]
else:
raise Exception((await resp.json())['message']) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 4, identifier:logfile; 5, default_parameter; 5, 6; 5, 7; 6, identifier:jobID; 7, None; 8, block; 8, 9; 8, 17; 8, 47; 8, 70; 8, 76; 8, 82; 8, 86; 8, 114; 8, 129; 8, 142; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:joblist; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logfile; 15, identifier:readFromLogfile; 16, argument_list; 17, if_statement; 17, 18; 17, 29; 17, 40; 18, boolean_operator:and; 18, 19; 18, 20; 19, identifier:jobID; 20, comparison_operator:==; 20, 21; 20, 25; 21, call; 21, 22; 21, 23; 22, identifier:type; 23, argument_list; 23, 24; 24, identifier:jobID; 25, call; 25, 26; 25, 27; 26, identifier:type; 27, argument_list; 27, 28; 28, integer:1; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:command; 33, list:['qstat', '-j', str(jobID)]; 33, 34; 33, 35; 33, 36; 34, string:'qstat'; 35, string:'-j'; 36, call; 36, 37; 36, 38; 37, identifier:str; 38, argument_list; 38, 39; 39, identifier:jobID; 40, else_clause; 40, 41; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:command; 45, list:['qstat']; 45, 46; 46, string:'qstat'; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:processoutput; 50, call; 50, 51; 50, 69; 51, attribute; 51, 52; 51, 68; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:subprocess; 55, identifier:Popen; 56, argument_list; 56, 57; 56, 58; 56, 63; 57, identifier:command; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:stdout; 60, attribute; 60, 61; 60, 62; 61, identifier:subprocess; 62, identifier:PIPE; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:stderr; 65, attribute; 65, 66; 65, 67; 66, identifier:subprocess; 67, identifier:PIPE; 68, identifier:communicate; 69, argument_list; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:output; 73, subscript; 73, 74; 73, 75; 74, identifier:processoutput; 75, integer:0; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:serror; 79, subscript; 79, 80; 79, 81; 80, identifier:processoutput; 81, integer:1; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:jobs; 85, dictionary; 86, if_statement; 86, 87; 86, 96; 87, comparison_operator:==; 87, 88; 87, 92; 88, call; 88, 89; 88, 90; 89, identifier:type; 90, argument_list; 90, 91; 91, identifier:jobID; 92, call; 92, 93; 92, 94; 93, identifier:type; 94, argument_list; 94, 95; 95, integer:1; 96, block; 96, 97; 97, if_statement; 97, 98; 97, 107; 97, 110; 98, comparison_operator:!=; 98, 99; 98, 105; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:serror; 102, identifier:find; 103, argument_list; 103, 104; 104, string:"Following jobs do not exist"; 105, unary_operator:-; 105, 106; 106, integer:1; 107, block; 107, 108; 108, return_statement; 108, 109; 109, False; 110, else_clause; 110, 111; 111, block; 111, 112; 112, return_statement; 112, 113; 113, True; 114, if_statement; 114, 115; 114, 121; 115, not_operator; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:output; 119, identifier:strip; 120, argument_list; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:colorprinter; 126, identifier:message; 127, argument_list; 127, 128; 128, string:"No jobs running at present."; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:output; 132, call; 132, 133; 132, 140; 133, attribute; 133, 134; 133, 139; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:output; 137, identifier:strip; 138, argument_list; 139, identifier:split; 140, argument_list; 140, 141; 141, string:"\n"; 142, if_statement; 142, 143; 142, 149; 143, comparison_operator:>; 143, 144; 143, 148; 144, call; 144, 145; 144, 146; 145, identifier:len; 146, argument_list; 146, 147; 147, identifier:output; 148, integer:2; 149, block; 149, 150; 149, 374; 150, for_statement; 150, 151; 150, 152; 150, 157; 151, identifier:line; 152, subscript; 152, 153; 152, 154; 153, identifier:output; 154, slice; 154, 155; 154, 156; 155, integer:2; 156, colon; 157, block; 157, 158; 157, 166; 157, 175; 157, 181; 157, 217; 157, 221; 157, 275; 157, 295; 157, 308; 157, 316; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:tokens; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:line; 164, identifier:split; 165, argument_list; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:jid; 169, call; 169, 170; 169, 171; 170, identifier:int; 171, argument_list; 171, 172; 172, subscript; 172, 173; 172, 174; 173, identifier:tokens; 174, integer:0; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:jobstate; 178, subscript; 178, 179; 178, 180; 179, identifier:tokens; 180, integer:4; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:details; 184, dictionary; 184, 185; 184, 188; 184, 193; 184, 198; 184, 203; 184, 206; 185, pair; 185, 186; 185, 187; 186, string:"jobid"; 187, identifier:jid; 188, pair; 188, 189; 188, 190; 189, string:"prior"; 190, subscript; 190, 191; 190, 192; 191, identifier:tokens; 192, integer:1; 193, pair; 193, 194; 193, 195; 194, string:"name"; 195, subscript; 195, 196; 195, 197; 196, identifier:tokens; 197, integer:2; 198, pair; 198, 199; 198, 200; 199, string:"user"; 200, subscript; 200, 201; 200, 202; 201, identifier:tokens; 202, integer:3; 203, pair; 203, 204; 203, 205; 204, string:"state"; 205, identifier:jobstate; 206, pair; 206, 207; 206, 208; 207, string:"submit/start at"; 208, binary_operator:%; 208, 209; 208, 210; 209, string:"%s %s"; 210, tuple; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:tokens; 213, integer:5; 214, subscript; 214, 215; 214, 216; 215, identifier:tokens; 216, integer:6; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:jataskID; 220, integer:0; 221, if_statement; 221, 222; 221, 225; 221, 242; 222, comparison_operator:==; 222, 223; 222, 224; 223, identifier:jobstate; 224, string:"r"; 225, block; 225, 226; 225, 234; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:details; 230, string:"queue"; 231, subscript; 231, 232; 231, 233; 232, identifier:tokens; 233, integer:7; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:details; 238, string:"slots"; 239, subscript; 239, 240; 239, 241; 240, identifier:tokens; 241, integer:8; 242, elif_clause; 242, 243; 242, 246; 243, comparison_operator:==; 243, 244; 243, 245; 244, identifier:jobstate; 245, string:"qw"; 246, block; 246, 247; 246, 255; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 252; 249, subscript; 249, 250; 249, 251; 250, identifier:details; 251, string:"slots"; 252, subscript; 252, 253; 252, 254; 253, identifier:tokens; 254, integer:7; 255, if_statement; 255, 256; 255, 262; 256, comparison_operator:>=; 256, 257; 256, 261; 257, call; 257, 258; 257, 259; 258, identifier:len; 259, argument_list; 259, 260; 260, identifier:tokens; 261, integer:9; 262, block; 262, 263; 262, 269; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:jataskID; 266, subscript; 266, 267; 266, 268; 267, identifier:tokens; 268, integer:8; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:details; 273, string:"ja-task-ID"; 274, identifier:jataskID; 275, if_statement; 275, 276; 275, 282; 276, comparison_operator:>; 276, 277; 276, 281; 277, call; 277, 278; 277, 279; 278, identifier:len; 279, argument_list; 279, 280; 280, identifier:tokens; 281, integer:9; 282, block; 282, 283; 282, 289; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:jataskID; 286, subscript; 286, 287; 286, 288; 287, identifier:tokens; 288, integer:9; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 294; 291, subscript; 291, 292; 291, 293; 292, identifier:details; 293, string:"ja-task-ID"; 294, identifier:jataskID; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 300; 297, subscript; 297, 298; 297, 299; 298, identifier:jobs; 299, identifier:jid; 300, boolean_operator:or; 300, 301; 300, 307; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:jobs; 304, identifier:get; 305, argument_list; 305, 306; 306, identifier:jid; 307, dictionary; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 315; 310, subscript; 310, 311; 310, 314; 311, subscript; 311, 312; 311, 313; 312, identifier:jobs; 313, identifier:jid; 314, identifier:jataskID; 315, identifier:details; 316, if_statement; 316, 317; 316, 323; 316, 355; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:joblist; 320, identifier:get; 321, argument_list; 321, 322; 322, identifier:jid; 323, block; 323, 324; 323, 332; 323, 340; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:jobdir; 327, subscript; 327, 328; 327, 331; 328, subscript; 328, 329; 328, 330; 329, identifier:joblist; 330, identifier:jid; 331, string:"Directory"; 332, expression_statement; 332, 333; 333, assignment; 333, 334; 333, 335; 334, identifier:jobtime; 335, subscript; 335, 336; 335, 339; 336, subscript; 336, 337; 336, 338; 337, identifier:joblist; 338, identifier:jid; 339, string:"TimeInSeconds"; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:colorprinter; 344, identifier:message; 345, argument_list; 345, 346; 346, binary_operator:%; 346, 347; 346, 348; 347, string:"Job %d submitted %d minutes ago. Status: '%s'. Destination directory: %s."; 348, tuple; 348, 349; 348, 350; 348, 353; 348, 354; 349, identifier:jid; 350, binary_operator:/; 350, 351; 350, 352; 351, identifier:jobtime; 352, integer:60; 353, identifier:jobstate; 354, identifier:jobdir; 355, else_clause; 355, 356; 356, block; 356, 357; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:colorprinter; 361, identifier:message; 362, argument_list; 362, 363; 363, binary_operator:%; 363, 364; 363, 365; 364, string:"Job %d submitted at %s %s. Status: '%s'. Destination directory unknown."; 365, tuple; 365, 366; 365, 367; 365, 370; 365, 373; 366, identifier:jid; 367, subscript; 367, 368; 367, 369; 368, identifier:tokens; 369, integer:5; 370, subscript; 370, 371; 370, 372; 371, identifier:tokens; 372, integer:6; 373, identifier:jobstate; 374, return_statement; 374, 375; 375, True | def query(logfile, jobID = None):
joblist = logfile.readFromLogfile()
if jobID and type(jobID) == type(1):
command = ['qstat', '-j', str(jobID)]
else:
command = ['qstat']
processoutput = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
output = processoutput[0]
serror = processoutput[1]
jobs = {}
if type(jobID) == type(1):
if serror.find("Following jobs do not exist") != -1:
return False
else:
return True
if not output.strip():
colorprinter.message("No jobs running at present.")
output = output.strip().split("\n")
if len(output) > 2:
for line in output[2:]:
tokens = line.split()
jid = int(tokens[0])
jobstate = tokens[4]
details = { "jobid" : jid,
"prior" : tokens[1],
"name" : tokens[2],
"user" : tokens[3],
"state" : jobstate,
"submit/start at" : "%s %s" % (tokens[5], tokens[6])
}
jataskID = 0
if jobstate == "r":
details["queue"] = tokens[7]
details["slots"] = tokens[8]
elif jobstate == "qw":
details["slots"] = tokens[7]
if len(tokens) >= 9:
jataskID = tokens[8]
details["ja-task-ID"] = jataskID
if len(tokens) > 9:
jataskID = tokens[9]
details["ja-task-ID"] = jataskID
jobs[jid] = jobs.get(jid) or {}
jobs[jid][jataskID] = details
if joblist.get(jid):
jobdir = joblist[jid]["Directory"]
jobtime = joblist[jid]["TimeInSeconds"]
colorprinter.message("Job %d submitted %d minutes ago. Status: '%s'. Destination directory: %s." % (jid, jobtime / 60, jobstate, jobdir))
else:
colorprinter.message("Job %d submitted at %s %s. Status: '%s'. Destination directory unknown." % (jid, tokens[5], tokens[6], jobstate))
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:build; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:client; 5, identifier:repository_tag; 6, identifier:docker_file; 7, default_parameter; 7, 8; 7, 9; 8, identifier:tag; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:use_cache; 12, False; 13, block; 13, 14; 13, 29; 13, 59; 13, 74; 13, 82; 13, 100; 13, 105; 13, 120; 13, 124; 13, 230; 13, 235; 13, 241; 14, if_statement; 14, 15; 14, 23; 15, not_operator; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:isinstance; 18, argument_list; 18, 19; 18, 20; 19, identifier:client; 20, attribute; 20, 21; 20, 22; 21, identifier:docker; 22, identifier:Client; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:TypeError; 27, argument_list; 27, 28; 28, string:"client needs to be of type docker.Client."; 29, if_statement; 29, 30; 29, 48; 30, boolean_operator:or; 30, 31; 30, 39; 31, not_operator; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:isinstance; 34, argument_list; 34, 35; 34, 36; 35, identifier:docker_file; 36, attribute; 36, 37; 36, 38; 37, identifier:six; 38, identifier:string_types; 39, not_operator; 39, 40; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:os; 44, identifier:path; 45, identifier:exists; 46, argument_list; 46, 47; 47, identifier:docker_file; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:Exception; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, string:"docker file path doesn't exist: {0}"; 56, identifier:format; 57, argument_list; 57, 58; 58, identifier:docker_file; 59, if_statement; 59, 60; 59, 68; 60, not_operator; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:isinstance; 63, argument_list; 63, 64; 63, 65; 64, identifier:repository_tag; 65, attribute; 65, 66; 65, 67; 66, identifier:six; 67, identifier:string_types; 68, block; 68, 69; 69, raise_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:TypeError; 72, argument_list; 72, 73; 73, string:'repository must be a string'; 74, if_statement; 74, 75; 74, 77; 75, not_operator; 75, 76; 76, identifier:tag; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:tag; 81, string:'latest'; 82, if_statement; 82, 83; 82, 89; 83, not_operator; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:isinstance; 86, argument_list; 86, 87; 86, 88; 87, identifier:use_cache; 88, identifier:bool; 89, block; 89, 90; 90, raise_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:TypeError; 93, argument_list; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, string:"use_cache must be a bool. {0} was passed."; 97, identifier:format; 98, argument_list; 98, 99; 99, identifier:use_cache; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:no_cache; 103, not_operator; 103, 104; 104, identifier:use_cache; 105, if_statement; 105, 106; 105, 109; 106, comparison_operator:not; 106, 107; 106, 108; 107, string:':'; 108, identifier:repository_tag; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:repository_tag; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, string:"{0}:{1}"; 116, identifier:format; 117, argument_list; 117, 118; 117, 119; 118, identifier:repository_tag; 119, identifier:tag; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:file_obj; 123, None; 124, try_statement; 124, 125; 124, 211; 124, 219; 125, block; 125, 126; 126, if_statement; 126, 127; 126, 135; 126, 186; 127, call; 127, 128; 127, 133; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:os; 131, identifier:path; 132, identifier:isfile; 133, argument_list; 133, 134; 134, identifier:docker_file; 135, block; 135, 136; 135, 144; 135, 160; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:path; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:os; 142, identifier:getcwd; 143, argument_list; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:docker_file; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, string:"./{0}"; 150, identifier:format; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:os; 156, identifier:path; 157, identifier:relpath; 158, argument_list; 158, 159; 159, identifier:docker_file; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:response; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:client; 166, identifier:build; 167, argument_list; 167, 168; 167, 171; 167, 174; 167, 177; 167, 180; 167, 183; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:path; 170, identifier:path; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:nocache; 173, identifier:no_cache; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:dockerfile; 176, identifier:docker_file; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:tag; 179, identifier:repository_tag; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:rm; 182, True; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:stream; 185, True; 186, else_clause; 186, 187; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:response; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:client; 194, identifier:build; 195, argument_list; 195, 196; 195, 199; 195, 202; 195, 205; 195, 208; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:path; 198, identifier:docker_file; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:tag; 201, identifier:repository_tag; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:rm; 204, True; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:nocache; 207, identifier:no_cache; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:stream; 210, True; 211, except_clause; 211, 212; 211, 216; 212, as_pattern; 212, 213; 212, 214; 213, identifier:Exception; 214, as_pattern_target; 214, 215; 215, identifier:e; 216, block; 216, 217; 217, raise_statement; 217, 218; 218, identifier:e; 219, finally_clause; 219, 220; 220, block; 220, 221; 221, if_statement; 221, 222; 221, 223; 222, identifier:file_obj; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:file_obj; 228, identifier:close; 229, argument_list; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 233; 232, identifier:parse_stream; 233, argument_list; 233, 234; 234, identifier:response; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:client; 239, identifier:close; 240, argument_list; 241, return_statement; 241, 242; 242, call; 242, 243; 242, 244; 243, identifier:Image; 244, argument_list; 244, 245; 244, 246; 245, identifier:client; 246, identifier:repository_tag | def build(client, repository_tag, docker_file, tag=None, use_cache=False):
if not isinstance(client, docker.Client):
raise TypeError("client needs to be of type docker.Client.")
if not isinstance(docker_file, six.string_types) or not os.path.exists(docker_file):
raise Exception("docker file path doesn't exist: {0}".format(docker_file))
if not isinstance(repository_tag, six.string_types):
raise TypeError('repository must be a string')
if not tag:
tag = 'latest'
if not isinstance(use_cache, bool):
raise TypeError("use_cache must be a bool. {0} was passed.".format(use_cache))
no_cache = not use_cache
if ':' not in repository_tag:
repository_tag = "{0}:{1}".format(repository_tag, tag)
file_obj = None
try:
if os.path.isfile(docker_file):
path = os.getcwd()
docker_file = "./{0}".format(os.path.relpath(docker_file))
response = client.build(
path=path,
nocache=no_cache,
dockerfile=docker_file,
tag=repository_tag,
rm=True,
stream=True
)
else:
response = client.build(path=docker_file, tag=repository_tag, rm=True, nocache=no_cache, stream=True)
except Exception as e:
raise e
finally:
if file_obj:
file_obj.close()
parse_stream(response)
client.close()
return Image(client, repository_tag) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:create_class; 3, parameters; 3, 4; 4, identifier:request; 5, block; 5, 6; 5, 25; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:==; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:request; 10, identifier:method; 11, string:'GET'; 12, block; 12, 13; 13, return_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:render; 16, argument_list; 16, 17; 16, 18; 16, 19; 16, 20; 17, identifier:request; 18, string:'classes_create.html'; 19, dictionary; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:help_text; 22, attribute; 22, 23; 22, 24; 23, identifier:create_class; 24, identifier:__doc__; 25, if_statement; 25, 26; 25, 31; 25, 213; 26, comparison_operator:==; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:request; 29, identifier:method; 30, string:'POST'; 31, block; 31, 32; 31, 72; 31, 86; 31, 129; 31, 160; 31, 178; 31, 191; 31, 197; 32, if_statement; 32, 33; 32, 50; 33, boolean_operator:or; 33, 34; 33, 42; 34, not_operator; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:request; 39, identifier:user; 40, identifier:is_authenticated; 41, argument_list; 42, not_operator; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:hasattr; 45, argument_list; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:request; 48, identifier:user; 49, string:"userprofile"; 50, block; 50, 51; 51, return_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:render_json; 54, argument_list; 54, 55; 54, 56; 54, 66; 54, 69; 55, identifier:request; 56, dictionary; 56, 57; 56, 63; 57, pair; 57, 58; 57, 59; 58, string:'error'; 59, call; 59, 60; 59, 61; 60, identifier:_; 61, argument_list; 61, 62; 62, string:'User is not logged in.'; 63, pair; 63, 64; 63, 65; 64, string:'error_type'; 65, string:'user_unauthorized'; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:template; 68, string:'classes_create.html'; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:status; 71, integer:401; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:data; 75, call; 75, 76; 75, 77; 76, identifier:json_body; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:request; 82, identifier:body; 83, identifier:decode; 84, argument_list; 84, 85; 85, string:"utf-8"; 86, if_statement; 86, 87; 86, 107; 87, boolean_operator:and; 87, 88; 87, 91; 88, comparison_operator:in; 88, 89; 88, 90; 89, string:'code'; 90, identifier:data; 91, call; 91, 92; 91, 106; 92, attribute; 92, 93; 92, 105; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:Class; 97, identifier:objects; 98, identifier:filter; 99, argument_list; 99, 100; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:code; 102, subscript; 102, 103; 102, 104; 103, identifier:data; 104, string:'code'; 105, identifier:exists; 106, argument_list; 107, block; 107, 108; 108, return_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:render_json; 111, argument_list; 111, 112; 111, 113; 111, 123; 111, 126; 112, identifier:request; 113, dictionary; 113, 114; 113, 120; 114, pair; 114, 115; 114, 116; 115, string:'error'; 116, call; 116, 117; 116, 118; 117, identifier:_; 118, argument_list; 118, 119; 119, string:'A class with this code already exists.'; 120, pair; 120, 121; 120, 122; 121, string:'error_type'; 122, string:'class_with_code_exists'; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:template; 125, string:'classes_create.html'; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:status; 128, integer:400; 129, if_statement; 129, 130; 129, 138; 130, boolean_operator:or; 130, 131; 130, 134; 131, comparison_operator:not; 131, 132; 131, 133; 132, string:'name'; 133, identifier:data; 134, not_operator; 134, 135; 135, subscript; 135, 136; 135, 137; 136, identifier:data; 137, string:'name'; 138, block; 138, 139; 139, return_statement; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:render_json; 142, argument_list; 142, 143; 142, 144; 142, 154; 142, 157; 143, identifier:request; 144, dictionary; 144, 145; 144, 151; 145, pair; 145, 146; 145, 147; 146, string:'error'; 147, call; 147, 148; 147, 149; 148, identifier:_; 149, argument_list; 149, 150; 150, string:'Class name is missing.'; 151, pair; 151, 152; 151, 153; 152, string:'error_type'; 153, string:'missing_class_name'; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:template; 156, string:'classes_create.html'; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:status; 159, integer:400; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:cls; 163, call; 163, 164; 163, 165; 164, identifier:Class; 165, argument_list; 165, 166; 165, 171; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:name; 168, subscript; 168, 169; 168, 170; 169, identifier:data; 170, string:'name'; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:owner; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:request; 176, identifier:user; 177, identifier:userprofile; 178, if_statement; 178, 179; 178, 182; 179, comparison_operator:in; 179, 180; 179, 181; 180, string:'code'; 181, identifier:data; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:cls; 187, identifier:code; 188, subscript; 188, 189; 188, 190; 189, identifier:data; 190, string:'code'; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:cls; 195, identifier:save; 196, argument_list; 197, return_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:render_json; 200, argument_list; 200, 201; 200, 202; 200, 207; 200, 210; 201, identifier:request; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:cls; 205, identifier:to_json; 206, argument_list; 207, keyword_argument; 207, 208; 207, 209; 208, identifier:template; 209, string:'classes_create.html'; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:status; 212, integer:201; 213, else_clause; 213, 214; 214, block; 214, 215; 215, return_statement; 215, 216; 216, call; 216, 217; 216, 218; 217, identifier:HttpResponseBadRequest; 218, argument_list; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, string:"method %s is not allowed"; 222, identifier:format; 223, argument_list; 223, 224; 224, attribute; 224, 225; 224, 226; 225, identifier:request; 226, identifier:method | def create_class(request):
if request.method == 'GET':
return render(request, 'classes_create.html', {}, help_text=create_class.__doc__)
if request.method == 'POST':
if not request.user.is_authenticated() or not hasattr(request.user, "userprofile"):
return render_json(request, {
'error': _('User is not logged in.'),
'error_type': 'user_unauthorized'
}, template='classes_create.html', status=401)
data = json_body(request.body.decode("utf-8"))
if 'code' in data and Class.objects.filter(code=data['code']).exists():
return render_json(request, {
'error': _('A class with this code already exists.'),
'error_type': 'class_with_code_exists'
}, template='classes_create.html', status=400)
if 'name' not in data or not data['name']:
return render_json(request, {'error': _('Class name is missing.'), 'error_type': 'missing_class_name'},
template='classes_create.html', status=400)
cls = Class(name=data['name'], owner=request.user.userprofile)
if 'code' in data:
cls.code = data['code']
cls.save()
return render_json(request, cls.to_json(), template='classes_create.html', status=201)
else:
return HttpResponseBadRequest("method %s is not allowed".format(request.method)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:create_student; 3, parameters; 3, 4; 4, identifier:request; 5, block; 5, 6; 5, 43; 5, 62; 6, if_statement; 6, 7; 6, 16; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:get_config; 10, argument_list; 10, 11; 10, 12; 10, 13; 11, string:'proso_user'; 12, string:'allow_create_students'; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:default; 15, False; 16, block; 16, 17; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:render_json; 20, argument_list; 20, 21; 20, 22; 20, 32; 20, 35; 20, 40; 21, identifier:request; 22, dictionary; 22, 23; 22, 29; 23, pair; 23, 24; 23, 25; 24, string:'error'; 25, call; 25, 26; 25, 27; 26, identifier:_; 27, argument_list; 27, 28; 28, string:'Creation of new users is not allowed.'; 29, pair; 29, 30; 29, 31; 30, string:'error_type'; 31, string:'student_creation_not_allowed'; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:template; 34, string:'class_create_student.html'; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:help_text; 37, attribute; 37, 38; 37, 39; 38, identifier:create_student; 39, identifier:__doc__; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:status; 42, integer:403; 43, if_statement; 43, 44; 43, 49; 44, comparison_operator:==; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:request; 47, identifier:method; 48, string:'GET'; 49, block; 49, 50; 50, return_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:render; 53, argument_list; 53, 54; 53, 55; 53, 56; 53, 57; 54, identifier:request; 55, string:'class_create_student.html'; 56, dictionary; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:help_text; 59, attribute; 59, 60; 59, 61; 60, identifier:create_student; 61, identifier:__doc__; 62, if_statement; 62, 63; 62, 68; 62, 409; 63, comparison_operator:==; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:request; 66, identifier:method; 67, string:'POST'; 68, block; 68, 69; 68, 109; 68, 123; 68, 175; 68, 206; 68, 217; 68, 233; 68, 288; 68, 354; 68, 371; 68, 377; 68, 388; 69, if_statement; 69, 70; 69, 87; 70, boolean_operator:or; 70, 71; 70, 79; 71, not_operator; 71, 72; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:request; 76, identifier:user; 77, identifier:is_authenticated; 78, argument_list; 79, not_operator; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:hasattr; 82, argument_list; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:request; 85, identifier:user; 86, string:"userprofile"; 87, block; 87, 88; 88, return_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:render_json; 91, argument_list; 91, 92; 91, 93; 91, 103; 91, 106; 92, identifier:request; 93, dictionary; 93, 94; 93, 100; 94, pair; 94, 95; 94, 96; 95, string:'error'; 96, call; 96, 97; 96, 98; 97, identifier:_; 98, argument_list; 98, 99; 99, string:'User is not logged in.'; 100, pair; 100, 101; 100, 102; 101, string:'error_type'; 102, string:'user_unauthorized'; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:template; 105, string:'class_create_student.html'; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:status; 108, integer:401; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:data; 112, call; 112, 113; 112, 114; 113, identifier:json_body; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:request; 119, identifier:body; 120, identifier:decode; 121, argument_list; 121, 122; 122, string:"utf-8"; 123, try_statement; 123, 124; 123, 147; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:cls; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:Class; 132, identifier:objects; 133, identifier:get; 134, argument_list; 134, 135; 134, 140; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:pk; 137, subscript; 137, 138; 137, 139; 138, identifier:data; 139, string:'class'; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:owner; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:request; 145, identifier:user; 146, identifier:userprofile; 147, except_clause; 147, 148; 147, 153; 148, tuple; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:Class; 151, identifier:DoesNotExist; 152, identifier:KeyError; 153, block; 153, 154; 154, return_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:render_json; 157, argument_list; 157, 158; 157, 159; 157, 169; 157, 172; 158, identifier:request; 159, dictionary; 159, 160; 159, 166; 160, pair; 160, 161; 160, 162; 161, string:'error'; 162, call; 162, 163; 162, 164; 163, identifier:_; 164, argument_list; 164, 165; 165, string:'Class with given id not found.'; 166, pair; 166, 167; 166, 168; 167, string:'error_type'; 168, string:'class_not_found'; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:template; 171, string:'class_create_student.html'; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:status; 174, integer:404; 175, if_statement; 175, 176; 175, 184; 176, boolean_operator:or; 176, 177; 176, 180; 177, comparison_operator:not; 177, 178; 177, 179; 178, string:'first_name'; 179, identifier:data; 180, not_operator; 180, 181; 181, subscript; 181, 182; 181, 183; 182, identifier:data; 183, string:'first_name'; 184, block; 184, 185; 185, return_statement; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:render_json; 188, argument_list; 188, 189; 188, 190; 188, 200; 188, 203; 189, identifier:request; 190, dictionary; 190, 191; 190, 197; 191, pair; 191, 192; 191, 193; 192, string:'error'; 193, call; 193, 194; 193, 195; 194, identifier:_; 195, argument_list; 195, 196; 196, string:'First name code is missing.'; 197, pair; 197, 198; 197, 199; 198, string:'error_type'; 199, string:'missing_first_name'; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:template; 202, string:'class_create_student.html'; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:status; 205, integer:400; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:user; 209, call; 209, 210; 209, 211; 210, identifier:User; 211, argument_list; 211, 212; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:first_name; 214, subscript; 214, 215; 214, 216; 215, identifier:data; 216, string:'first_name'; 217, if_statement; 217, 218; 217, 224; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:data; 221, identifier:get; 222, argument_list; 222, 223; 223, string:'last_name'; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:user; 229, identifier:last_name; 230, subscript; 230, 231; 230, 232; 231, identifier:data; 232, string:'last_name'; 233, if_statement; 233, 234; 233, 240; 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:'email'; 240, block; 240, 241; 240, 280; 241, if_statement; 241, 242; 241, 258; 242, call; 242, 243; 242, 257; 243, attribute; 243, 244; 243, 256; 244, call; 244, 245; 244, 250; 245, attribute; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:User; 248, identifier:objects; 249, identifier:filter; 250, argument_list; 250, 251; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:email; 253, subscript; 253, 254; 253, 255; 254, identifier:data; 255, string:'email'; 256, identifier:exists; 257, argument_list; 258, block; 258, 259; 259, return_statement; 259, 260; 260, call; 260, 261; 260, 262; 261, identifier:render_json; 262, argument_list; 262, 263; 262, 264; 262, 274; 262, 277; 263, identifier:request; 264, dictionary; 264, 265; 264, 271; 265, pair; 265, 266; 265, 267; 266, string:'error'; 267, call; 267, 268; 267, 269; 268, identifier:_; 269, argument_list; 269, 270; 270, string:'There is already a user with the given e-mail.'; 271, pair; 271, 272; 271, 273; 272, string:'error_type'; 273, string:'email_exists'; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:template; 276, string:'class_create_student.html'; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:status; 279, integer:400; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:user; 284, identifier:email; 285, subscript; 285, 286; 285, 287; 286, identifier:data; 287, string:'email'; 288, if_statement; 288, 289; 288, 295; 288, 343; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:data; 292, identifier:get; 293, argument_list; 293, 294; 294, string:'username'; 295, block; 295, 296; 295, 335; 296, if_statement; 296, 297; 296, 313; 297, call; 297, 298; 297, 312; 298, attribute; 298, 299; 298, 311; 299, call; 299, 300; 299, 305; 300, attribute; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:User; 303, identifier:objects; 304, identifier:filter; 305, argument_list; 305, 306; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:username; 308, subscript; 308, 309; 308, 310; 309, identifier:data; 310, string:'username'; 311, identifier:exists; 312, argument_list; 313, block; 313, 314; 314, return_statement; 314, 315; 315, call; 315, 316; 315, 317; 316, identifier:render_json; 317, argument_list; 317, 318; 317, 319; 317, 329; 317, 332; 318, identifier:request; 319, dictionary; 319, 320; 319, 326; 320, pair; 320, 321; 320, 322; 321, string:'error'; 322, call; 322, 323; 322, 324; 323, identifier:_; 324, argument_list; 324, 325; 325, string:'There is already a user with the given username.'; 326, pair; 326, 327; 326, 328; 327, string:'error_type'; 328, string:'username_exists'; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:template; 331, string:'class_create_student.html'; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:status; 334, integer:400; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:user; 339, identifier:username; 340, subscript; 340, 341; 340, 342; 341, identifier:data; 342, string:'username'; 343, else_clause; 343, 344; 344, block; 344, 345; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:user; 349, identifier:username; 350, call; 350, 351; 350, 352; 351, identifier:get_unused_username; 352, argument_list; 352, 353; 353, identifier:user; 354, if_statement; 354, 355; 354, 361; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:data; 358, identifier:get; 359, argument_list; 359, 360; 360, string:'password'; 361, block; 361, 362; 362, expression_statement; 362, 363; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:user; 366, identifier:set_password; 367, argument_list; 367, 368; 368, subscript; 368, 369; 368, 370; 369, identifier:data; 370, string:'password'; 371, expression_statement; 371, 372; 372, call; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:user; 375, identifier:save; 376, argument_list; 377, expression_statement; 377, 378; 378, call; 378, 379; 378, 384; 379, attribute; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:cls; 382, identifier:members; 383, identifier:add; 384, argument_list; 384, 385; 385, attribute; 385, 386; 385, 387; 386, identifier:user; 387, identifier:userprofile; 388, return_statement; 388, 389; 389, call; 389, 390; 389, 391; 390, identifier:render_json; 391, argument_list; 391, 392; 391, 393; 391, 403; 391, 406; 392, identifier:request; 393, call; 393, 394; 393, 399; 394, attribute; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:user; 397, identifier:userprofile; 398, identifier:to_json; 399, argument_list; 399, 400; 400, keyword_argument; 400, 401; 400, 402; 401, identifier:nested; 402, True; 403, keyword_argument; 403, 404; 403, 405; 404, identifier:template; 405, string:'class_create_student.html'; 406, keyword_argument; 406, 407; 406, 408; 407, identifier:status; 408, integer:201; 409, else_clause; 409, 410; 410, block; 410, 411; 411, return_statement; 411, 412; 412, call; 412, 413; 412, 414; 413, identifier:HttpResponseBadRequest; 414, argument_list; 414, 415; 415, call; 415, 416; 415, 419; 416, attribute; 416, 417; 416, 418; 417, string:"method %s is not allowed"; 418, identifier:format; 419, argument_list; 419, 420; 420, attribute; 420, 421; 420, 422; 421, identifier:request; 422, identifier:method | def create_student(request):
if not get_config('proso_user', 'allow_create_students', default=False):
return render_json(request, {
'error': _('Creation of new users is not allowed.'),
'error_type': 'student_creation_not_allowed'
}, template='class_create_student.html', help_text=create_student.__doc__, status=403)
if request.method == 'GET':
return render(request, 'class_create_student.html', {}, help_text=create_student.__doc__)
if request.method == 'POST':
if not request.user.is_authenticated() or not hasattr(request.user, "userprofile"):
return render_json(request, {
'error': _('User is not logged in.'),
'error_type': 'user_unauthorized'
}, template='class_create_student.html', status=401)
data = json_body(request.body.decode("utf-8"))
try:
cls = Class.objects.get(pk=data['class'], owner=request.user.userprofile)
except (Class.DoesNotExist, KeyError):
return render_json(request, {
'error': _('Class with given id not found.'),
'error_type': 'class_not_found',
}, template='class_create_student.html', status=404)
if 'first_name' not in data or not data['first_name']:
return render_json(request, {
'error': _('First name code is missing.'),
'error_type': 'missing_first_name'
}, template='class_create_student.html', status=400)
user = User(first_name=data['first_name'])
if data.get('last_name'):
user.last_name = data['last_name']
if data.get('email'):
if User.objects.filter(email=data['email']).exists():
return render_json(request, {
'error': _('There is already a user with the given e-mail.'),
'error_type': 'email_exists'
}, template='class_create_student.html', status=400)
user.email = data['email']
if data.get('username'):
if User.objects.filter(username=data['username']).exists():
return render_json(request, {
'error': _('There is already a user with the given username.'),
'error_type': 'username_exists'
}, template='class_create_student.html', status=400)
user.username = data['username']
else:
user.username = get_unused_username(user)
if data.get('password'):
user.set_password(data['password'])
user.save()
cls.members.add(user.userprofile)
return render_json(request, user.userprofile.to_json(nested=True), template='class_create_student.html', status=201)
else:
return HttpResponseBadRequest("method %s is not allowed".format(request.method)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 80; 2, function_name:lograptor; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 3, 41; 3, 44; 3, 47; 3, 50; 3, 53; 3, 56; 3, 59; 3, 62; 3, 65; 3, 68; 3, 71; 3, 74; 3, 77; 4, identifier:files; 5, default_parameter; 5, 6; 5, 7; 6, identifier:patterns; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:matcher; 10, string:'ruled'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:cfgfiles; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:apps; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:hosts; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:filters; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:time_period; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:time_range; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:case; 31, False; 32, default_parameter; 32, 33; 32, 34; 33, identifier:invert; 34, False; 35, default_parameter; 35, 36; 35, 37; 36, identifier:word; 37, False; 38, default_parameter; 38, 39; 38, 40; 39, identifier:files_with_match; 40, None; 41, default_parameter; 41, 42; 41, 43; 42, identifier:count; 43, False; 44, default_parameter; 44, 45; 44, 46; 45, identifier:quiet; 46, False; 47, default_parameter; 47, 48; 47, 49; 48, identifier:max_count; 49, integer:0; 50, default_parameter; 50, 51; 50, 52; 51, identifier:only_matching; 52, False; 53, default_parameter; 53, 54; 53, 55; 54, identifier:line_number; 55, False; 56, default_parameter; 56, 57; 56, 58; 57, identifier:with_filename; 58, None; 59, default_parameter; 59, 60; 59, 61; 60, identifier:ip_lookup; 61, False; 62, default_parameter; 62, 63; 62, 64; 63, identifier:uid_lookup; 64, False; 65, default_parameter; 65, 66; 65, 67; 66, identifier:anonymize; 67, False; 68, default_parameter; 68, 69; 68, 70; 69, identifier:thread; 70, False; 71, default_parameter; 71, 72; 71, 73; 72, identifier:before_context; 73, integer:0; 74, default_parameter; 74, 75; 74, 76; 75, identifier:after_context; 76, integer:0; 77, default_parameter; 77, 78; 77, 79; 78, identifier:context; 79, integer:0; 80, block; 80, 81; 80, 87; 80, 95; 80, 101; 80, 107; 80, 113; 80, 119; 80, 125; 80, 131; 80, 137; 80, 143; 80, 149; 80, 155; 80, 161; 80, 167; 80, 173; 80, 179; 80, 185; 80, 191; 80, 197; 80, 203; 80, 209; 80, 215; 80, 221; 80, 227; 80, 239; 80, 250; 80, 261; 80, 272; 80, 279; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:cli_parser; 84, call; 84, 85; 84, 86; 85, identifier:create_argument_parser; 86, argument_list; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:args; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:cli_parser; 93, identifier:parse_args; 94, argument_list; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:args; 99, identifier:files; 100, identifier:files; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:args; 105, identifier:matcher; 106, identifier:matcher; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:args; 111, identifier:cfgfiles; 112, identifier:cfgfiles; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:args; 117, identifier:time_period; 118, identifier:time_period; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:args; 123, identifier:time_range; 124, identifier:time_range; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:args; 129, identifier:case; 130, identifier:case; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:args; 135, identifier:invert; 136, identifier:invert; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:args; 141, identifier:word; 142, identifier:word; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:args; 147, identifier:files_with_match; 148, identifier:files_with_match; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:args; 153, identifier:count; 154, identifier:count; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:args; 159, identifier:quiet; 160, identifier:quiet; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:args; 165, identifier:max_count; 166, identifier:max_count; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:args; 171, identifier:only_matching; 172, identifier:only_matching; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:args; 177, identifier:line_number; 178, identifier:line_number; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:args; 183, identifier:with_filename; 184, identifier:with_filename; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:args; 189, identifier:anonymize; 190, identifier:anonymize; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:args; 195, identifier:ip_lookup; 196, identifier:ip_lookup; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:args; 201, identifier:uid_lookup; 202, identifier:uid_lookup; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:args; 207, identifier:thread; 208, identifier:thread; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:args; 213, identifier:context; 214, identifier:context; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:args; 219, identifier:after_context; 220, identifier:after_context; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:args; 225, identifier:before_context; 226, identifier:before_context; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:args; 231, identifier:patterns; 232, conditional_expression:if; 232, 233; 232, 235; 232, 238; 233, list:['']; 233, 234; 234, string:''; 235, comparison_operator:is; 235, 236; 235, 237; 236, identifier:patterns; 237, None; 238, identifier:patterns; 239, if_statement; 239, 240; 239, 243; 240, comparison_operator:is; 240, 241; 240, 242; 241, identifier:apps; 242, None; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:args; 248, identifier:apps; 249, identifier:apps; 250, if_statement; 250, 251; 250, 254; 251, comparison_operator:is; 251, 252; 251, 253; 252, identifier:hosts; 253, None; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:args; 259, identifier:hosts; 260, identifier:hosts; 261, if_statement; 261, 262; 261, 265; 262, comparison_operator:is; 262, 263; 262, 264; 263, identifier:filters; 264, None; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:args; 270, identifier:filters; 271, identifier:filters; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:_lograptor; 275, call; 275, 276; 275, 277; 276, identifier:LogRaptor; 277, argument_list; 277, 278; 278, identifier:args; 279, return_statement; 279, 280; 280, call; 280, 281; 280, 282; 281, identifier:_lograptor; 282, argument_list | def lograptor(files, patterns=None, matcher='ruled', cfgfiles=None, apps=None, hosts=None,
filters=None, time_period=None, time_range=None, case=False, invert=False,
word=False, files_with_match=None, count=False, quiet=False, max_count=0,
only_matching=False, line_number=False, with_filename=None,
ip_lookup=False, uid_lookup=False, anonymize=False, thread=False,
before_context=0, after_context=0, context=0):
cli_parser = create_argument_parser()
args = cli_parser.parse_args()
args.files = files
args.matcher = matcher
args.cfgfiles = cfgfiles
args.time_period = time_period
args.time_range = time_range
args.case = case
args.invert = invert
args.word = word
args.files_with_match = files_with_match
args.count = count
args.quiet = quiet
args.max_count = max_count
args.only_matching = only_matching
args.line_number = line_number
args.with_filename = with_filename
args.anonymize = anonymize
args.ip_lookup = ip_lookup
args.uid_lookup = uid_lookup
args.thread = thread
args.context = context
args.after_context = after_context
args.before_context = before_context
args.patterns = [''] if patterns is None else patterns
if apps is not None:
args.apps = apps
if hosts is not None:
args.hosts = hosts
if filters is not None:
args.filters = filters
_lograptor = LogRaptor(args)
return _lograptor() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sanitize_codon_list; 3, parameters; 3, 4; 3, 5; 4, identifier:codon_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:forbidden_seqs; 7, tuple; 8, block; 8, 9; 8, 31; 8, 37; 8, 53; 8, 68; 8, 89; 8, 102; 8, 106; 8, 122; 9, for_statement; 9, 10; 9, 11; 9, 12; 10, identifier:codon; 11, identifier:codon_list; 12, block; 12, 13; 13, if_statement; 13, 14; 13, 20; 14, comparison_operator:!=; 14, 15; 14, 19; 15, call; 15, 16; 15, 17; 16, identifier:len; 17, argument_list; 17, 18; 18, identifier:codon; 19, integer:3; 20, block; 20, 21; 21, raise_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:ValueError; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, string:"Codons must have exactly 3 bases: '{}'"; 28, identifier:format; 29, argument_list; 29, 30; 30, identifier:codon; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:bad_seqs; 34, call; 34, 35; 34, 36; 35, identifier:set; 36, argument_list; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:bad_seqs; 41, identifier:union; 42, generator_expression; 42, 43; 42, 50; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:restriction_sites; 46, identifier:get; 47, argument_list; 47, 48; 47, 49; 48, identifier:seq; 49, identifier:seq; 50, for_in_clause; 50, 51; 50, 52; 51, identifier:seq; 52, identifier:forbidden_seqs; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:bad_seqs; 57, identifier:union; 58, generator_expression; 58, 59; 58, 65; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:dna; 62, identifier:reverse_complement; 63, argument_list; 63, 64; 64, identifier:seq; 65, for_in_clause; 65, 66; 65, 67; 66, identifier:seq; 67, identifier:bad_seqs; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:bad_seqs; 72, identifier:union; 73, generator_expression; 73, 74; 73, 84; 74, binary_operator:*; 74, 75; 74, 76; 75, identifier:base; 76, parenthesized_expression; 76, 77; 77, binary_operator:+; 77, 78; 77, 83; 78, subscript; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:gen9; 81, identifier:homopolymer_max_lengths; 82, identifier:base; 83, integer:1; 84, for_in_clause; 84, 85; 84, 86; 85, identifier:base; 86, attribute; 86, 87; 86, 88; 87, identifier:dna; 88, identifier:dna_bases; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:bad_seqs; 92, list_comprehension; 92, 93; 92, 99; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:dna; 96, identifier:dna_to_re; 97, argument_list; 97, 98; 98, identifier:bs; 99, for_in_clause; 99, 100; 99, 101; 100, identifier:bs; 101, identifier:bad_seqs; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:num_corrections; 105, integer:0; 106, for_statement; 106, 107; 106, 108; 106, 109; 107, identifier:bad_seq; 108, identifier:bad_seqs; 109, block; 109, 110; 110, while_statement; 110, 111; 110, 117; 111, call; 111, 112; 111, 113; 112, identifier:remove_bad_sequence; 113, argument_list; 113, 114; 113, 115; 113, 116; 114, identifier:codon_list; 115, identifier:bad_seq; 116, identifier:bad_seqs; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, augmented_assignment:+=; 119, 120; 119, 121; 120, identifier:num_corrections; 121, integer:1; 122, return_statement; 122, 123; 123, identifier:num_corrections | def sanitize_codon_list(codon_list, forbidden_seqs=()):
for codon in codon_list:
if len(codon) != 3:
raise ValueError("Codons must have exactly 3 bases: '{}'".format(codon))
bad_seqs = set()
bad_seqs.union(
restriction_sites.get(seq, seq)
for seq in forbidden_seqs)
bad_seqs.union(
dna.reverse_complement(seq)
for seq in bad_seqs)
bad_seqs.union(
base * (gen9.homopolymer_max_lengths[base] + 1)
for base in dna.dna_bases)
bad_seqs = [
dna.dna_to_re(bs)
for bs in bad_seqs]
num_corrections = 0
for bad_seq in bad_seqs:
while remove_bad_sequence(codon_list, bad_seq, bad_seqs):
num_corrections += 1
return num_corrections |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:add_node; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:node; 6, block; 6, 7; 6, 15; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:nodes; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:nodes; 14, argument_list; 15, if_statement; 15, 16; 15, 24; 15, 57; 16, comparison_operator:<=; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:nodes; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:m0; 24, block; 24, 25; 24, 41; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:other_nodes; 28, list_comprehension; 28, 29; 28, 30; 28, 33; 29, identifier:n; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:n; 32, identifier:nodes; 33, if_clause; 33, 34; 34, comparison_operator:!=; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:n; 37, identifier:id; 38, attribute; 38, 39; 38, 40; 39, identifier:node; 40, identifier:id; 41, for_statement; 41, 42; 41, 43; 41, 44; 42, identifier:n; 43, identifier:other_nodes; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:node; 49, identifier:connect; 50, argument_list; 50, 51; 50, 54; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:direction; 53, string:"both"; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:whom; 56, identifier:n; 57, else_clause; 57, 58; 58, block; 58, 59; 59, for_statement; 59, 60; 59, 61; 59, 67; 60, identifier:idx_newvector; 61, call; 61, 62; 61, 63; 62, identifier:xrange; 63, argument_list; 63, 64; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:m; 67, block; 67, 68; 67, 98; 67, 116; 67, 133; 67, 146; 67, 150; 67, 174; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:these_nodes; 71, list_comprehension; 71, 72; 71, 73; 71, 76; 72, identifier:n; 73, for_in_clause; 73, 74; 73, 75; 74, identifier:n; 75, identifier:nodes; 76, if_clause; 76, 77; 77, parenthesized_expression; 77, 78; 78, boolean_operator:and; 78, 79; 78, 86; 79, comparison_operator:!=; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:n; 82, identifier:id; 83, attribute; 83, 84; 83, 85; 84, identifier:node; 85, identifier:id; 86, not_operator; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:n; 90, identifier:is_connected; 91, argument_list; 91, 92; 91, 95; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:direction; 94, string:"either"; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:whom; 97, identifier:node; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:outdegrees; 101, list_comprehension; 101, 102; 101, 113; 102, call; 102, 103; 102, 104; 103, identifier:len; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:n; 108, identifier:vectors; 109, argument_list; 109, 110; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:direction; 112, string:"outgoing"; 113, for_in_clause; 113, 114; 113, 115; 114, identifier:n; 115, identifier:these_nodes; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:ps; 119, list_comprehension; 119, 120; 119, 130; 120, parenthesized_expression; 120, 121; 121, binary_operator:/; 121, 122; 121, 123; 122, identifier:d; 123, parenthesized_expression; 123, 124; 124, binary_operator:*; 124, 125; 124, 126; 125, float:1.0; 126, call; 126, 127; 126, 128; 127, identifier:sum; 128, argument_list; 128, 129; 129, identifier:outdegrees; 130, for_in_clause; 130, 131; 130, 132; 131, identifier:d; 132, identifier:outdegrees; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:rnd; 136, binary_operator:*; 136, 137; 136, 142; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:random; 140, identifier:random; 141, argument_list; 142, call; 142, 143; 142, 144; 143, identifier:sum; 144, argument_list; 144, 145; 145, identifier:ps; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:cur; 149, float:0.0; 150, for_statement; 150, 151; 150, 154; 150, 158; 151, pattern_list; 151, 152; 151, 153; 152, identifier:i; 153, identifier:p; 154, call; 154, 155; 154, 156; 155, identifier:enumerate; 156, argument_list; 156, 157; 157, identifier:ps; 158, block; 158, 159; 158, 163; 159, expression_statement; 159, 160; 160, augmented_assignment:+=; 160, 161; 160, 162; 161, identifier:cur; 162, identifier:p; 163, if_statement; 163, 164; 163, 167; 164, comparison_operator:<; 164, 165; 164, 166; 165, identifier:rnd; 166, identifier:cur; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:vector_to; 171, subscript; 171, 172; 171, 173; 172, identifier:these_nodes; 173, identifier:i; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:node; 178, identifier:connect; 179, argument_list; 179, 180; 179, 183; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:direction; 182, string:"both"; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:whom; 185, identifier:vector_to | def add_node(self, node):
nodes = self.nodes()
if len(nodes) <= self.m0:
other_nodes = [n for n in nodes if n.id != node.id]
for n in other_nodes:
node.connect(direction="both", whom=n)
else:
for idx_newvector in xrange(self.m):
these_nodes = [
n for n in nodes if (
n.id != node.id and
not n.is_connected(direction="either", whom=node))]
outdegrees = [
len(n.vectors(direction="outgoing")) for n in these_nodes]
ps = [(d / (1.0 * sum(outdegrees))) for d in outdegrees]
rnd = random.random() * sum(ps)
cur = 0.0
for i, p in enumerate(ps):
cur += p
if rnd < cur:
vector_to = these_nodes[i]
node.connect(direction="both", whom=vector_to) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_concepts_to_recalculate; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:users; 6, identifier:lang; 7, default_parameter; 7, 8; 7, 9; 8, identifier:concepts; 9, None; 10, block; 10, 11; 10, 15; 10, 32; 10, 41; 10, 49; 10, 65; 10, 81; 10, 97; 10, 107; 10, 248; 10, 257; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:only_one_user; 14, False; 15, if_statement; 15, 16; 15, 22; 16, not_operator; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:users; 21, identifier:list; 22, block; 22, 23; 22, 27; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:only_one_user; 26, True; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:users; 30, list:[users]; 30, 31; 31, identifier:users; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:mapping; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:get_item_concept_mapping; 39, argument_list; 39, 40; 40, identifier:lang; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:current_user_stats; 44, call; 44, 45; 44, 46; 45, identifier:defaultdict; 46, argument_list; 46, 47; 47, lambda; 47, 48; 48, dictionary; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:user_stats_qs; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:UserStat; 56, identifier:objects; 57, identifier:filter; 58, argument_list; 58, 59; 58, 62; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:user__in; 61, identifier:users; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:stat; 64, string:"answer_count"; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:concepts; 68, None; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:user_stats_qs; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:user_stats_qs; 76, identifier:filter; 77, argument_list; 77, 78; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:concept__in; 80, identifier:concepts; 81, for_statement; 81, 82; 81, 83; 81, 84; 82, identifier:user_stat; 83, identifier:user_stats_qs; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 96; 87, subscript; 87, 88; 87, 93; 88, subscript; 88, 89; 88, 90; 89, identifier:current_user_stats; 90, attribute; 90, 91; 90, 92; 91, identifier:user_stat; 92, identifier:user_id; 93, attribute; 93, 94; 93, 95; 94, identifier:user_stat; 95, identifier:concept_id; 96, identifier:user_stat; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:concepts_to_recalculate; 100, call; 100, 101; 100, 102; 101, identifier:defaultdict; 102, argument_list; 102, 103; 103, lambda; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:set; 106, argument_list; 107, for_statement; 107, 108; 107, 112; 107, 137; 108, pattern_list; 108, 109; 108, 110; 108, 111; 109, identifier:user; 110, identifier:item; 111, identifier:time; 112, call; 112, 113; 112, 132; 113, attribute; 113, 114; 113, 131; 114, call; 114, 115; 114, 128; 115, attribute; 115, 116; 115, 126; 115, 127; 116, call; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:Answer; 120, identifier:objects; 121, identifier:filter; 122, argument_list; 122, 123; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:user__in; 125, identifier:users; 126, line_continuation:\; 127, identifier:values_list; 128, argument_list; 128, 129; 128, 130; 129, string:"user_id"; 130, string:"item"; 131, identifier:annotate; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:Max; 135, argument_list; 135, 136; 136, string:"time"; 137, block; 137, 138; 137, 144; 137, 155; 137, 166; 138, if_statement; 138, 139; 138, 142; 139, comparison_operator:not; 139, 140; 139, 141; 140, identifier:item; 141, identifier:mapping; 142, block; 142, 143; 143, continue_statement; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:time_expiration_lower_bound; 147, call; 147, 148; 147, 149; 148, identifier:get_config; 149, argument_list; 149, 150; 149, 151; 149, 152; 150, string:'proso_models'; 151, string:'knowledge_overview.time_shift_hours'; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:default; 154, integer:4; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:time_expiration_factor; 158, call; 158, 159; 158, 160; 159, identifier:get_config; 160, argument_list; 160, 161; 160, 162; 160, 163; 161, string:'proso_models'; 162, string:'knowledge_overview.time_expiration_factor'; 163, keyword_argument; 163, 164; 163, 165; 164, identifier:default; 165, integer:2; 166, for_statement; 166, 167; 166, 168; 166, 171; 167, identifier:concept; 168, subscript; 168, 169; 168, 170; 169, identifier:mapping; 170, identifier:item; 171, block; 171, 172; 171, 213; 172, if_statement; 172, 173; 172, 193; 173, boolean_operator:and; 173, 174; 173, 183; 173, 184; 174, boolean_operator:and; 174, 175; 174, 178; 175, comparison_operator:in; 175, 176; 175, 177; 176, identifier:user; 177, identifier:current_user_stats; 178, comparison_operator:in; 178, 179; 178, 180; 179, identifier:concept; 180, subscript; 180, 181; 180, 182; 181, identifier:current_user_stats; 182, identifier:user; 183, line_continuation:\; 184, comparison_operator:>; 184, 185; 184, 192; 185, attribute; 185, 186; 185, 191; 186, subscript; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:current_user_stats; 189, identifier:user; 190, identifier:concept; 191, identifier:time; 192, identifier:time; 193, block; 193, 194; 194, if_statement; 194, 195; 194, 211; 195, not_operator; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:has_time_expired; 200, argument_list; 200, 201; 200, 208; 200, 209; 200, 210; 201, attribute; 201, 202; 201, 207; 202, subscript; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:current_user_stats; 205, identifier:user; 206, identifier:concept; 207, identifier:time; 208, identifier:time; 209, identifier:time_expiration_lower_bound; 210, identifier:time_expiration_factor; 211, block; 211, 212; 212, continue_statement; 213, if_statement; 213, 214; 213, 238; 214, boolean_operator:or; 214, 215; 214, 218; 215, comparison_operator:is; 215, 216; 215, 217; 216, identifier:concepts; 217, None; 218, comparison_operator:in; 218, 219; 218, 220; 219, identifier:concept; 220, parenthesized_expression; 220, 221; 221, conditional_expression:if; 221, 222; 221, 229; 221, 237; 222, list_comprehension; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:c; 225, identifier:pk; 226, for_in_clause; 226, 227; 226, 228; 227, identifier:c; 228, identifier:concepts; 229, comparison_operator:==; 229, 230; 229, 236; 230, call; 230, 231; 230, 232; 231, identifier:type; 232, argument_list; 232, 233; 233, subscript; 233, 234; 233, 235; 234, identifier:concepts; 235, integer:0; 236, identifier:Concept; 237, identifier:Concept; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, subscript; 242, 243; 242, 244; 243, identifier:concepts_to_recalculate; 244, identifier:user; 245, identifier:add; 246, argument_list; 246, 247; 247, identifier:concept; 248, if_statement; 248, 249; 248, 250; 249, identifier:only_one_user; 250, block; 250, 251; 251, return_statement; 251, 252; 252, subscript; 252, 253; 252, 254; 253, identifier:concepts_to_recalculate; 254, subscript; 254, 255; 254, 256; 255, identifier:users; 256, integer:0; 257, return_statement; 257, 258; 258, identifier:concepts_to_recalculate | def get_concepts_to_recalculate(self, users, lang, concepts=None):
only_one_user = False
if not isinstance(users, list):
only_one_user = True
users = [users]
mapping = self.get_item_concept_mapping(lang)
current_user_stats = defaultdict(lambda: {})
user_stats_qs = UserStat.objects.filter(user__in=users, stat="answer_count")
if concepts is not None:
user_stats_qs = user_stats_qs.filter(concept__in=concepts)
for user_stat in user_stats_qs:
current_user_stats[user_stat.user_id][user_stat.concept_id] = user_stat
concepts_to_recalculate = defaultdict(lambda: set())
for user, item, time in Answer.objects.filter(user__in=users)\
.values_list("user_id", "item").annotate(Max("time")):
if item not in mapping:
continue
time_expiration_lower_bound = get_config('proso_models', 'knowledge_overview.time_shift_hours', default=4)
time_expiration_factor = get_config('proso_models', 'knowledge_overview.time_expiration_factor', default=2)
for concept in mapping[item]:
if user in current_user_stats and concept in current_user_stats[user] \
and current_user_stats[user][concept].time > time:
if not self.has_time_expired(current_user_stats[user][concept].time, time, time_expiration_lower_bound, time_expiration_factor):
continue
if concepts is None or concept in ([c.pk for c in concepts] if type(concepts[0]) == Concept else Concept):
concepts_to_recalculate[user].add(concept)
if only_one_user:
return concepts_to_recalculate[users[0]]
return concepts_to_recalculate |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:recalculate_concepts; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:concepts; 6, default_parameter; 6, 7; 6, 8; 7, identifier:lang; 8, None; 9, block; 9, 10; 9, 19; 9, 71; 9, 77; 9, 83; 10, if_statement; 10, 11; 10, 17; 11, comparison_operator:==; 11, 12; 11, 16; 12, call; 12, 13; 12, 14; 13, identifier:len; 14, argument_list; 14, 15; 15, identifier:concepts; 16, integer:0; 17, block; 17, 18; 18, return_statement; 19, if_statement; 19, 20; 19, 23; 19, 56; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:lang; 22, None; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:items; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:Concept; 31, identifier:objects; 32, identifier:get_concept_item_mapping; 33, argument_list; 33, 34; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:concepts; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:Concept; 40, identifier:objects; 41, identifier:filter; 42, argument_list; 42, 43; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:pk__in; 45, call; 45, 46; 45, 47; 46, identifier:set; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:flatten; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:concepts; 54, identifier:values; 55, argument_list; 56, else_clause; 56, 57; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:items; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:Concept; 65, identifier:objects; 66, identifier:get_concept_item_mapping; 67, argument_list; 67, 68; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:lang; 70, identifier:lang; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:environment; 74, call; 74, 75; 74, 76; 75, identifier:get_environment; 76, argument_list; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:mastery_threshold; 80, call; 80, 81; 80, 82; 81, identifier:get_mastery_trashold; 82, argument_list; 83, for_statement; 83, 84; 83, 87; 83, 92; 84, pattern_list; 84, 85; 84, 86; 85, identifier:user; 86, identifier:concepts; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:concepts; 90, identifier:items; 91, argument_list; 92, block; 92, 93; 92, 112; 92, 122; 92, 132; 92, 160; 92, 164; 92, 170; 92, 385; 92, 396; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:all_items; 96, call; 96, 97; 96, 98; 97, identifier:list; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:set; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:flatten; 104, argument_list; 104, 105; 105, list_comprehension; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:items; 108, identifier:c; 109, for_in_clause; 109, 110; 109, 111; 110, identifier:c; 111, identifier:concepts; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:answer_counts; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:environment; 118, identifier:number_of_answers_more_items; 119, argument_list; 119, 120; 119, 121; 120, identifier:all_items; 121, identifier:user; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:correct_answer_counts; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:environment; 128, identifier:number_of_correct_answers_more_items; 129, argument_list; 129, 130; 129, 131; 130, identifier:all_items; 131, identifier:user; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:predictions; 135, call; 135, 136; 135, 137; 136, identifier:dict; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:list; 140, argument_list; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:zip; 143, argument_list; 143, 144; 143, 145; 144, identifier:all_items; 145, call; 145, 146; 145, 151; 146, attribute; 146, 147; 146, 150; 147, call; 147, 148; 147, 149; 148, identifier:get_predictive_model; 149, argument_list; 150, identifier:predict_more_items; 151, argument_list; 151, 152; 151, 153; 151, 154; 151, 155; 152, identifier:environment; 153, identifier:user; 154, identifier:all_items; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:time; 157, call; 157, 158; 157, 159; 158, identifier:get_time_for_knowledge_overview; 159, argument_list; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:new_user_stats; 163, list:[]; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:stats_to_delete_condition; 167, call; 167, 168; 167, 169; 168, identifier:Q; 169, argument_list; 170, for_statement; 170, 171; 170, 172; 170, 173; 171, identifier:concept; 172, identifier:concepts; 173, block; 173, 174; 173, 221; 173, 342; 173, 354; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:answer_aggregates; 177, call; 177, 178; 177, 195; 178, attribute; 178, 179; 178, 194; 179, call; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:Answer; 183, identifier:objects; 184, identifier:filter; 185, argument_list; 185, 186; 185, 189; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:user; 188, identifier:user; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:item__in; 191, subscript; 191, 192; 191, 193; 192, identifier:items; 193, identifier:concept; 194, identifier:aggregate; 195, argument_list; 195, 196; 195, 202; 195, 209; 195, 215; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:time_spent; 198, call; 198, 199; 198, 200; 199, identifier:Sum; 200, argument_list; 200, 201; 201, string:"response_time"; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:sessions; 204, call; 204, 205; 204, 206; 205, identifier:Count; 206, argument_list; 206, 207; 206, 208; 207, string:"session"; 208, True; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:time_first; 211, call; 211, 212; 211, 213; 212, identifier:Min; 213, argument_list; 213, 214; 214, string:"time"; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:time_last; 217, call; 217, 218; 217, 219; 218, identifier:Max; 219, argument_list; 219, 220; 220, string:"time"; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:stats; 224, dictionary; 224, 225; 224, 238; 224, 251; 224, 259; 224, 275; 224, 291; 224, 312; 224, 319; 224, 324; 224, 333; 225, pair; 225, 226; 225, 227; 226, string:"answer_count"; 227, call; 227, 228; 227, 229; 228, identifier:sum; 229, generator_expression; 229, 230; 229, 233; 230, subscript; 230, 231; 230, 232; 231, identifier:answer_counts; 232, identifier:i; 233, for_in_clause; 233, 234; 233, 235; 234, identifier:i; 235, subscript; 235, 236; 235, 237; 236, identifier:items; 237, identifier:concept; 238, pair; 238, 239; 238, 240; 239, string:"correct_answer_count"; 240, call; 240, 241; 240, 242; 241, identifier:sum; 242, generator_expression; 242, 243; 242, 246; 243, subscript; 243, 244; 243, 245; 244, identifier:correct_answer_counts; 245, identifier:i; 246, for_in_clause; 246, 247; 246, 248; 247, identifier:i; 248, subscript; 248, 249; 248, 250; 249, identifier:items; 250, identifier:concept; 251, pair; 251, 252; 251, 253; 252, string:"item_count"; 253, call; 253, 254; 253, 255; 254, identifier:len; 255, argument_list; 255, 256; 256, subscript; 256, 257; 256, 258; 257, identifier:items; 258, identifier:concept; 259, pair; 259, 260; 259, 261; 260, string:"practiced_items_count"; 261, call; 261, 262; 261, 263; 262, identifier:sum; 263, argument_list; 263, 264; 264, list_comprehension; 264, 265; 264, 270; 265, comparison_operator:>; 265, 266; 265, 269; 266, subscript; 266, 267; 266, 268; 267, identifier:answer_counts; 268, identifier:i; 269, integer:0; 270, for_in_clause; 270, 271; 270, 272; 271, identifier:i; 272, subscript; 272, 273; 272, 274; 273, identifier:items; 274, identifier:concept; 275, pair; 275, 276; 275, 277; 276, string:"mastered_items_count"; 277, call; 277, 278; 277, 279; 278, identifier:sum; 279, argument_list; 279, 280; 280, list_comprehension; 280, 281; 280, 286; 281, comparison_operator:>=; 281, 282; 281, 285; 282, subscript; 282, 283; 282, 284; 283, identifier:predictions; 284, identifier:i; 285, identifier:mastery_threshold; 286, for_in_clause; 286, 287; 286, 288; 287, identifier:i; 288, subscript; 288, 289; 288, 290; 289, identifier:items; 290, identifier:concept; 291, pair; 291, 292; 291, 293; 292, string:"prediction"; 293, binary_operator:/; 293, 294; 293, 306; 294, call; 294, 295; 294, 296; 295, identifier:sum; 296, argument_list; 296, 297; 297, list_comprehension; 297, 298; 297, 301; 298, subscript; 298, 299; 298, 300; 299, identifier:predictions; 300, identifier:i; 301, for_in_clause; 301, 302; 301, 303; 302, identifier:i; 303, subscript; 303, 304; 303, 305; 304, identifier:items; 305, identifier:concept; 306, call; 306, 307; 306, 308; 307, identifier:len; 308, argument_list; 308, 309; 309, subscript; 309, 310; 309, 311; 310, identifier:items; 311, identifier:concept; 312, pair; 312, 313; 312, 314; 313, string:"time_spent"; 314, binary_operator:/; 314, 315; 314, 318; 315, subscript; 315, 316; 315, 317; 316, identifier:answer_aggregates; 317, string:"time_spent"; 318, integer:1000; 319, pair; 319, 320; 319, 321; 320, string:"session_count"; 321, subscript; 321, 322; 321, 323; 322, identifier:answer_aggregates; 323, string:"sessions"; 324, pair; 324, 325; 324, 326; 325, string:"time_first"; 326, call; 326, 327; 326, 332; 327, attribute; 327, 328; 327, 331; 328, subscript; 328, 329; 328, 330; 329, identifier:answer_aggregates; 330, string:"time_first"; 331, identifier:timestamp; 332, argument_list; 333, pair; 333, 334; 333, 335; 334, string:"time_last"; 335, call; 335, 336; 335, 341; 336, attribute; 336, 337; 336, 340; 337, subscript; 337, 338; 337, 339; 338, identifier:answer_aggregates; 339, string:"time_last"; 340, identifier:timestamp; 341, argument_list; 342, expression_statement; 342, 343; 343, augmented_assignment:|=; 343, 344; 343, 345; 344, identifier:stats_to_delete_condition; 345, call; 345, 346; 345, 347; 346, identifier:Q; 347, argument_list; 347, 348; 347, 351; 348, keyword_argument; 348, 349; 348, 350; 349, identifier:user; 350, identifier:user; 351, keyword_argument; 351, 352; 351, 353; 352, identifier:concept; 353, identifier:concept; 354, for_statement; 354, 355; 354, 358; 354, 363; 355, pattern_list; 355, 356; 355, 357; 356, identifier:stat_name; 357, identifier:value; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:stats; 361, identifier:items; 362, argument_list; 363, block; 363, 364; 364, expression_statement; 364, 365; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:new_user_stats; 368, identifier:append; 369, argument_list; 369, 370; 370, call; 370, 371; 370, 372; 371, identifier:UserStat; 372, argument_list; 372, 373; 372, 376; 372, 379; 372, 382; 373, keyword_argument; 373, 374; 373, 375; 374, identifier:user_id; 375, identifier:user; 376, keyword_argument; 376, 377; 376, 378; 377, identifier:concept_id; 378, identifier:concept; 379, keyword_argument; 379, 380; 379, 381; 380, identifier:stat; 381, identifier:stat_name; 382, keyword_argument; 382, 383; 382, 384; 383, identifier:value; 384, identifier:value; 385, expression_statement; 385, 386; 386, call; 386, 387; 386, 395; 387, attribute; 387, 388; 387, 394; 388, call; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:self; 391, identifier:filter; 392, argument_list; 392, 393; 393, identifier:stats_to_delete_condition; 394, identifier:delete; 395, argument_list; 396, expression_statement; 396, 397; 397, call; 397, 398; 397, 401; 398, attribute; 398, 399; 398, 400; 399, identifier:self; 400, identifier:bulk_create; 401, argument_list; 401, 402; 402, identifier:new_user_stats | def recalculate_concepts(self, concepts, lang=None):
if len(concepts) == 0:
return
if lang is None:
items = Concept.objects.get_concept_item_mapping(concepts=Concept.objects.filter(pk__in=set(flatten(concepts.values()))))
else:
items = Concept.objects.get_concept_item_mapping(lang=lang)
environment = get_environment()
mastery_threshold = get_mastery_trashold()
for user, concepts in concepts.items():
all_items = list(set(flatten([items[c] for c in concepts])))
answer_counts = environment.number_of_answers_more_items(all_items, user)
correct_answer_counts = environment.number_of_correct_answers_more_items(all_items, user)
predictions = dict(list(zip(all_items, get_predictive_model().
predict_more_items(environment, user, all_items, time=get_time_for_knowledge_overview()))))
new_user_stats = []
stats_to_delete_condition = Q()
for concept in concepts:
answer_aggregates = Answer.objects.filter(user=user, item__in=items[concept]).aggregate(
time_spent=Sum("response_time"),
sessions=Count("session", True),
time_first=Min("time"),
time_last=Max("time"),
)
stats = {
"answer_count": sum(answer_counts[i] for i in items[concept]),
"correct_answer_count": sum(correct_answer_counts[i] for i in items[concept]),
"item_count": len(items[concept]),
"practiced_items_count": sum([answer_counts[i] > 0 for i in items[concept]]),
"mastered_items_count": sum([predictions[i] >= mastery_threshold for i in items[concept]]),
"prediction": sum([predictions[i] for i in items[concept]]) / len(items[concept]),
"time_spent": answer_aggregates["time_spent"] / 1000,
"session_count": answer_aggregates["sessions"],
"time_first": answer_aggregates["time_first"].timestamp(),
"time_last": answer_aggregates["time_last"].timestamp(),
}
stats_to_delete_condition |= Q(user=user, concept=concept)
for stat_name, value in stats.items():
new_user_stats.append(UserStat(user_id=user, concept_id=concept, stat=stat_name, value=value))
self.filter(stats_to_delete_condition).delete()
self.bulk_create(new_user_stats) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:get_user_stats; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:users; 6, default_parameter; 6, 7; 6, 8; 7, identifier:lang; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:concepts; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:since; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:recalculate; 17, True; 18, block; 18, 19; 18, 23; 18, 40; 18, 112; 18, 130; 18, 146; 18, 162; 18, 178; 18, 190; 18, 214; 18, 237; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:only_one_user; 22, False; 23, if_statement; 23, 24; 23, 30; 24, not_operator; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:isinstance; 27, argument_list; 27, 28; 27, 29; 28, identifier:users; 29, identifier:list; 30, block; 30, 31; 30, 36; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:users; 34, list:[users]; 34, 35; 35, identifier:users; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:only_one_user; 39, True; 40, if_statement; 40, 41; 40, 42; 41, identifier:recalculate; 42, block; 42, 43; 42, 53; 42, 59; 42, 72; 42, 85; 42, 91; 42, 99; 43, if_statement; 43, 44; 43, 47; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:lang; 46, None; 47, block; 47, 48; 48, raise_statement; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:ValueError; 51, argument_list; 51, 52; 52, string:'Recalculation without lang is not supported.'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:time_start; 56, call; 56, 57; 56, 58; 57, identifier:time_lib; 58, argument_list; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:concepts_to_recalculate; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:Concept; 66, identifier:objects; 67, identifier:get_concepts_to_recalculate; 68, argument_list; 68, 69; 68, 70; 68, 71; 69, identifier:users; 70, identifier:lang; 71, identifier:concepts; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:LOGGER; 76, identifier:debug; 77, argument_list; 77, 78; 77, 79; 78, string:"user_stats - getting identifying concepts to recalculate: %ss"; 79, parenthesized_expression; 79, 80; 80, binary_operator:-; 80, 81; 80, 84; 81, call; 81, 82; 81, 83; 82, identifier:time_lib; 83, argument_list; 84, identifier:time_start; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:time_start; 88, call; 88, 89; 88, 90; 89, identifier:time_lib; 90, argument_list; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:recalculate_concepts; 96, argument_list; 96, 97; 96, 98; 97, identifier:concepts_to_recalculate; 98, identifier:lang; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:LOGGER; 103, identifier:debug; 104, argument_list; 104, 105; 104, 106; 105, string:"user_stats - recalculating concepts: %ss"; 106, parenthesized_expression; 106, 107; 107, binary_operator:-; 107, 108; 107, 111; 108, call; 108, 109; 108, 110; 109, identifier:time_lib; 110, argument_list; 111, identifier:time_start; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:qs; 115, call; 115, 116; 115, 123; 116, attribute; 116, 117; 116, 122; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:prepare_related; 121, argument_list; 122, identifier:filter; 123, argument_list; 123, 124; 123, 127; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:user__in; 126, identifier:users; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:concept__active; 129, True; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:is; 131, 132; 131, 133; 132, identifier:concepts; 133, None; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:qs; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:qs; 141, identifier:filter; 142, argument_list; 142, 143; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:concept__in; 145, identifier:concepts; 146, if_statement; 146, 147; 146, 150; 147, comparison_operator:is; 147, 148; 147, 149; 148, identifier:lang; 149, None; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:qs; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:qs; 157, identifier:filter; 158, argument_list; 158, 159; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:concept__lang; 161, identifier:lang; 162, if_statement; 162, 163; 162, 166; 163, comparison_operator:is; 163, 164; 163, 165; 164, identifier:since; 165, None; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:qs; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:qs; 173, identifier:filter; 174, argument_list; 174, 175; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:time__gte; 177, identifier:since; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:data; 181, call; 181, 182; 181, 183; 182, identifier:defaultdict; 183, argument_list; 183, 184; 184, lambda; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:defaultdict; 187, argument_list; 187, 188; 188, lambda; 188, 189; 189, dictionary; 190, for_statement; 190, 191; 190, 192; 190, 193; 191, identifier:user_stat; 192, identifier:qs; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 211; 196, subscript; 196, 197; 196, 208; 197, subscript; 197, 198; 197, 203; 198, subscript; 198, 199; 198, 200; 199, identifier:data; 200, attribute; 200, 201; 200, 202; 201, identifier:user_stat; 202, identifier:user_id; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:user_stat; 206, identifier:concept; 207, identifier:identifier; 208, attribute; 208, 209; 208, 210; 209, identifier:user_stat; 210, identifier:stat; 211, attribute; 211, 212; 211, 213; 212, identifier:user_stat; 213, identifier:value; 214, if_statement; 214, 215; 214, 216; 215, identifier:only_one_user; 216, block; 216, 217; 217, return_statement; 217, 218; 218, subscript; 218, 219; 218, 220; 219, identifier:data; 220, conditional_expression:if; 220, 221; 220, 226; 220, 234; 221, attribute; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:users; 224, integer:0; 225, identifier:pk; 226, comparison_operator:==; 226, 227; 226, 233; 227, call; 227, 228; 227, 229; 228, identifier:type; 229, argument_list; 229, 230; 230, subscript; 230, 231; 230, 232; 231, identifier:users; 232, integer:0; 233, identifier:User; 234, subscript; 234, 235; 234, 236; 235, identifier:users; 236, integer:0; 237, return_statement; 237, 238; 238, identifier:data | def get_user_stats(self, users, lang=None, concepts=None, since=None, recalculate=True):
only_one_user = False
if not isinstance(users, list):
users = [users]
only_one_user = True
if recalculate:
if lang is None:
raise ValueError('Recalculation without lang is not supported.')
time_start = time_lib()
concepts_to_recalculate = Concept.objects.get_concepts_to_recalculate(users, lang, concepts)
LOGGER.debug("user_stats - getting identifying concepts to recalculate: %ss", (time_lib() - time_start))
time_start = time_lib()
self.recalculate_concepts(concepts_to_recalculate, lang)
LOGGER.debug("user_stats - recalculating concepts: %ss", (time_lib() - time_start))
qs = self.prepare_related().filter(user__in=users, concept__active=True)
if concepts is not None:
qs = qs.filter(concept__in=concepts)
if lang is not None:
qs = qs.filter(concept__lang=lang)
if since is not None:
qs = qs.filter(time__gte=since)
data = defaultdict(lambda: defaultdict(lambda: {}))
for user_stat in qs:
data[user_stat.user_id][user_stat.concept.identifier][user_stat.stat] = user_stat.value
if only_one_user:
return data[users[0].pk if type(users[0]) == User else users[0]]
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:execute; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:sql; 6, default_parameter; 6, 7; 6, 8; 7, identifier:parameters; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:cursorClass; 11, identifier:DictCursor; 12, default_parameter; 12, 13; 12, 14; 13, identifier:quiet; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:locked; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:do_commit; 20, True; 21, block; 21, 22; 21, 26; 21, 30; 21, 34; 21, 38; 21, 66; 21, 332; 21, 382; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:i; 25, integer:0; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:errcode; 29, integer:0; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:caughte; 33, None; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:cursor; 37, None; 38, if_statement; 38, 39; 38, 58; 39, boolean_operator:or; 39, 40; 39, 49; 40, comparison_operator:!=; 40, 41; 40, 47; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:sql; 44, identifier:find; 45, argument_list; 45, 46; 46, string:";"; 47, unary_operator:-; 47, 48; 48, integer:1; 49, comparison_operator:!=; 49, 50; 49, 56; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:sql; 53, identifier:find; 54, argument_list; 54, 55; 55, string:"\\G"; 56, unary_operator:-; 56, 57; 57, integer:1; 58, block; 58, 59; 59, raise_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:Exception; 62, argument_list; 62, 63; 63, binary_operator:%; 63, 64; 63, 65; 64, string:"The SQL command '%s' contains a semi-colon or \\G. This is a potential SQL injection."; 65, identifier:sql; 66, while_statement; 66, 67; 66, 72; 67, comparison_operator:<; 67, 68; 67, 69; 68, identifier:i; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:numTries; 72, block; 72, 73; 72, 77; 72, 327; 73, expression_statement; 73, 74; 74, augmented_assignment:+=; 74, 75; 74, 76; 75, identifier:i; 76, integer:1; 77, try_statement; 77, 78; 77, 219; 77, 274; 78, block; 78, 79; 78, 94; 78, 101; 78, 111; 78, 129; 78, 153; 78, 164; 78, 179; 78, 187; 78, 205; 78, 211; 78, 217; 79, assert_statement; 79, 80; 80, parenthesized_expression; 80, 81; 81, boolean_operator:or; 81, 82; 81, 87; 82, not_operator; 82, 83; 83, parenthesized_expression; 83, 84; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:connection; 87, not_operator; 87, 88; 88, parenthesized_expression; 88, 89; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:connection; 93, identifier:open; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_get_connection; 99, argument_list; 99, 100; 100, identifier:cursorClass; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:cursor; 104, call; 104, 105; 104, 110; 105, attribute; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:connection; 109, identifier:cursor; 110, argument_list; 111, if_statement; 111, 112; 111, 113; 112, identifier:locked; 113, block; 113, 114; 113, 123; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:cursor; 118, identifier:execute; 119, argument_list; 119, 120; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:lockstring; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:locked; 128, True; 129, if_statement; 129, 130; 129, 131; 129, 142; 130, identifier:parameters; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:errcode; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:cursor; 138, identifier:execute; 139, argument_list; 139, 140; 139, 141; 140, identifier:sql; 141, identifier:parameters; 142, else_clause; 142, 143; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:errcode; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:cursor; 150, identifier:execute; 151, argument_list; 151, 152; 152, identifier:sql; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:lastrowid; 158, call; 158, 159; 158, 160; 159, identifier:int; 160, argument_list; 160, 161; 161, attribute; 161, 162; 161, 163; 162, identifier:cursor; 163, identifier:lastrowid; 164, if_statement; 164, 165; 164, 170; 165, boolean_operator:and; 165, 166; 165, 167; 166, identifier:do_commit; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:isInnoDB; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:connection; 177, identifier:commit; 178, argument_list; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:results; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:cursor; 185, identifier:fetchall; 186, argument_list; 187, if_statement; 187, 188; 187, 189; 188, identifier:locked; 189, block; 189, 190; 189, 199; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:cursor; 194, identifier:execute; 195, argument_list; 195, 196; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:unlockstring; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:locked; 204, False; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:cursor; 209, identifier:close; 210, argument_list; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:_close_connection; 216, argument_list; 217, return_statement; 217, 218; 218, identifier:results; 219, except_clause; 219, 220; 219, 223; 219, 224; 220, attribute; 220, 221; 220, 222; 221, identifier:MySQLdb; 222, identifier:OperationalError; 223, identifier:e; 224, block; 224, 225; 224, 254; 224, 260; 224, 267; 224, 273; 225, if_statement; 225, 226; 225, 227; 226, identifier:cursor; 227, block; 227, 228; 227, 248; 228, if_statement; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:self; 231, identifier:locked; 232, block; 232, 233; 232, 242; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:cursor; 237, identifier:execute; 238, argument_list; 238, 239; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:unlockstring; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:locked; 247, False; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:cursor; 252, identifier:close; 253, argument_list; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:_close_connection; 259, argument_list; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:caughte; 263, call; 263, 264; 263, 265; 264, identifier:str; 265, argument_list; 265, 266; 266, identifier:e; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:errcode; 270, subscript; 270, 271; 270, 272; 271, identifier:e; 272, integer:0; 273, continue_statement; 274, except_clause; 274, 275; 274, 276; 274, 277; 275, identifier:Exception; 276, identifier:e; 277, block; 277, 278; 277, 307; 277, 313; 277, 320; 277, 326; 278, if_statement; 278, 279; 278, 280; 279, identifier:cursor; 280, block; 280, 281; 280, 301; 281, if_statement; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:locked; 285, block; 285, 286; 285, 295; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:cursor; 290, identifier:execute; 291, argument_list; 291, 292; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:unlockstring; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:self; 299, identifier:locked; 300, False; 301, expression_statement; 301, 302; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:cursor; 305, identifier:close; 306, argument_list; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:self; 311, identifier:_close_connection; 312, argument_list; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:caughte; 316, call; 316, 317; 316, 318; 317, identifier:str; 318, argument_list; 318, 319; 319, identifier:e; 320, expression_statement; 320, 321; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:traceback; 324, identifier:print_exc; 325, argument_list; 326, break_statement; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:sleep; 330, argument_list; 330, 331; 331, float:0.2; 332, if_statement; 332, 333; 332, 335; 333, not_operator; 333, 334; 334, identifier:quiet; 335, block; 335, 336; 335, 358; 335, 374; 336, expression_statement; 336, 337; 337, call; 337, 338; 337, 343; 338, attribute; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:sys; 341, identifier:stderr; 342, identifier:write; 343, argument_list; 343, 344; 344, binary_operator:%; 344, 345; 344, 346; 345, string:"\nSQL execution error in query %s at %s:"; 346, tuple; 346, 347; 346, 348; 347, identifier:sql; 348, call; 348, 349; 348, 356; 349, attribute; 349, 350; 349, 355; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:datetime; 353, identifier:now; 354, argument_list; 355, identifier:strftime; 356, argument_list; 356, 357; 357, string:"%Y-%m-%d %H:%M:%S"; 358, expression_statement; 358, 359; 359, call; 359, 360; 359, 365; 360, attribute; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:sys; 363, identifier:stderr; 364, identifier:write; 365, argument_list; 365, 366; 366, binary_operator:%; 366, 367; 366, 368; 367, string:"\nErrorcode/Error: %d - '%s'.\n"; 368, tuple; 368, 369; 368, 370; 369, identifier:errcode; 370, call; 370, 371; 370, 372; 371, identifier:str; 372, argument_list; 372, 373; 373, identifier:caughte; 374, expression_statement; 374, 375; 375, call; 375, 376; 375, 381; 376, attribute; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:sys; 379, identifier:stderr; 380, identifier:flush; 381, argument_list; 382, raise_statement; 382, 383; 383, call; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:MySQLdb; 386, identifier:OperationalError; 387, argument_list; 387, 388; 388, identifier:caughte | def execute(self, sql, parameters = None, cursorClass = DictCursor, quiet = False, locked = False, do_commit = True):
i = 0
errcode = 0
caughte = None
cursor = None
if sql.find(";") != -1 or sql.find("\\G") != -1:
raise Exception("The SQL command '%s' contains a semi-colon or \\G. This is a potential SQL injection." % sql)
while i < self.numTries:
i += 1
try:
assert(not(self.connection) or not(self.connection.open))
self._get_connection(cursorClass)
cursor = self.connection.cursor()
if locked:
cursor.execute(self.lockstring)
self.locked = True
if parameters:
errcode = cursor.execute(sql, parameters)
else:
errcode = cursor.execute(sql)
self.lastrowid = int(cursor.lastrowid)
if do_commit and self.isInnoDB:
self.connection.commit()
results = cursor.fetchall()
if locked:
cursor.execute(self.unlockstring)
self.locked = False
cursor.close()
self._close_connection()
return results
except MySQLdb.OperationalError, e:
if cursor:
if self.locked:
cursor.execute(self.unlockstring)
self.locked = False
cursor.close()
self._close_connection()
caughte = str(e)
errcode = e[0]
continue
except Exception, e:
if cursor:
if self.locked:
cursor.execute(self.unlockstring)
self.locked = False
cursor.close()
self._close_connection()
caughte = str(e)
traceback.print_exc()
break
sleep(0.2)
if not quiet:
sys.stderr.write("\nSQL execution error in query %s at %s:" % (sql, datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
sys.stderr.write("\nErrorcode/Error: %d - '%s'.\n" % (errcode, str(caughte)))
sys.stderr.flush()
raise MySQLdb.OperationalError(caughte) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:create_tasks; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 8; 3, 11; 4, identifier:task_coro; 5, identifier:addrs; 6, list_splat_pattern; 6, 7; 7, identifier:args; 8, default_parameter; 8, 9; 8, 10; 9, identifier:flatten; 10, True; 11, dictionary_splat_pattern; 11, 12; 12, identifier:kwargs; 13, block; 13, 14; 13, 16; 13, 20; 13, 47; 14, expression_statement; 14, 15; 15, string:'''Create and schedule a set of asynchronous tasks.
The function creates the tasks using a given list of agent addresses and
wraps each of them in :func:`asyncio.ensure_future`. The ``*args`` and
``**kwargs`` are passed down to :func:`task_coro` when creating tasks for
each address in :attr:`addrs`.
Usage example for a method in a class derived from
:class:`~creamas.mp.MultiEnvironment`::
async def my_method(self, *args, **kwargs):
async def task(addr, *args, **kwargs):
r_manager = await self.env.connect(addr)
return await r_manager.my_method(*args, **kwargs)
return await util.create_tasks(task, self.addrs, *args, **kwargs)
:param task_coro:
Coroutine which is used for each address in :attr:`addrs`. The
coroutine should accept an agent address as the first parameter.
:param list addrs:
A list of agent addresses used as the first parameters of
:func:`task_coro`.
:param bool flatten:
If ``True`` the returned results are flattened into one list if the
tasks return iterable objects. The parameter does nothing if all the
results are not iterable.
:returns:
An awaitable coroutine which returns the results of tasks as a list or
as a flattened list
'''; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:tasks; 19, list:[]; 20, for_statement; 20, 21; 20, 22; 20, 23; 21, identifier:agent_addr; 22, identifier:addrs; 23, block; 23, 24; 23, 40; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:task; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:asyncio; 30, identifier:ensure_future; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:task_coro; 34, argument_list; 34, 35; 34, 36; 34, 38; 35, identifier:agent_addr; 36, list_splat; 36, 37; 37, identifier:args; 38, dictionary_splat; 38, 39; 39, identifier:kwargs; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:tasks; 44, identifier:append; 45, argument_list; 45, 46; 46, identifier:task; 47, return_statement; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:wait_tasks; 50, argument_list; 50, 51; 50, 52; 51, identifier:tasks; 52, identifier:flatten | def create_tasks(task_coro, addrs, *args, flatten=True, **kwargs):
'''Create and schedule a set of asynchronous tasks.
The function creates the tasks using a given list of agent addresses and
wraps each of them in :func:`asyncio.ensure_future`. The ``*args`` and
``**kwargs`` are passed down to :func:`task_coro` when creating tasks for
each address in :attr:`addrs`.
Usage example for a method in a class derived from
:class:`~creamas.mp.MultiEnvironment`::
async def my_method(self, *args, **kwargs):
async def task(addr, *args, **kwargs):
r_manager = await self.env.connect(addr)
return await r_manager.my_method(*args, **kwargs)
return await util.create_tasks(task, self.addrs, *args, **kwargs)
:param task_coro:
Coroutine which is used for each address in :attr:`addrs`. The
coroutine should accept an agent address as the first parameter.
:param list addrs:
A list of agent addresses used as the first parameters of
:func:`task_coro`.
:param bool flatten:
If ``True`` the returned results are flattened into one list if the
tasks return iterable objects. The parameter does nothing if all the
results are not iterable.
:returns:
An awaitable coroutine which returns the results of tasks as a list or
as a flattened list
'''
tasks = []
for agent_addr in addrs:
task = asyncio.ensure_future(task_coro(agent_addr, *args, **kwargs))
tasks.append(task)
return wait_tasks(tasks, flatten) |
0, module; 0, 1; 1, ERROR; 1, 2; 1, 204; 2, function_definition; 2, 3; 2, 4; 2, 21; 3, function_name:write; 4, parameters; 4, 5; 4, 6; 4, 9; 4, 12; 4, 15; 4, 18; 5, identifier:models; 6, default_parameter; 6, 7; 6, 8; 7, identifier:out; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:base; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:propertybase; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:shorteners; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:logger; 20, identifier:logging; 21, block; 21, 22; 21, 24; 21, 28; 21, 41; 21, 47; 21, 55; 21, 62; 21, 197; 22, expression_statement; 22, 23; 23, string:'''
models - input Versa models from which output is generated. Must be a sequence
object, not an iterator
'''; 24, assert_statement; 24, 25; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:out; 27, None; 28, if_statement; 28, 29; 28, 35; 29, not_operator; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:isinstance; 32, argument_list; 32, 33; 32, 34; 33, identifier:models; 34, identifier:list; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:models; 39, list:[models]; 39, 40; 40, identifier:models; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:shorteners; 44, boolean_operator:or; 44, 45; 44, 46; 45, identifier:shorteners; 46, dictionary; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:all_propertybase; 50, conditional_expression:if; 50, 51; 50, 53; 50, 54; 51, list:[propertybase]; 51, 52; 52, identifier:propertybase; 53, identifier:propertybase; 54, list:[]; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:all_propertybase; 59, identifier:append; 60, argument_list; 60, 61; 61, identifier:VERSA_BASEIRI; 62, if_statement; 62, 63; 62, 70; 62, 133; 63, call; 63, 64; 63, 65; 64, identifier:any; 65, argument_list; 65, 66; 66, tuple; 66, 67; 66, 68; 66, 69; 67, identifier:base; 68, identifier:propertybase; 69, identifier:shorteners; 70, ERROR; 70, 71; 70, 74; 70, 94; 70, 95; 70, 117; 70, 120; 70, 122; 70, 123; 70, 124; 70, 125; 71, attribute; 71, 72; 71, 73; 72, identifier:out; 73, identifier:write; 74, ERROR; 74, 75; 74, 76; 74, 77; 74, 88; 75, identifier:if; 76, identifier:base; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:out; 80, identifier:write; 81, argument_list; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, string:' * @base: {0}'; 85, identifier:format; 86, argument_list; 86, 87; 87, identifier:base; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:out; 91, identifier:write; 92, argument_list; 92, 93; 93, string:'\n\n'; 94, identifier:origin_space; 95, ERROR; 95, 96; 95, 104; 95, 113; 95, 114; 96, comparison_operator:in; 96, 97; 96, 100; 96, 103; 97, call; 97, 98; 97, 99; 98, identifier:set; 99, argument_list; 100, ERROR; 100, 101; 100, 102; 101, identifier:for; 102, identifier:m; 103, identifier:models; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:origin_space; 107, identifier:update; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:all_origins; 111, argument_list; 111, 112; 112, identifier:m; 113, identifier:for; 114, comparison_operator:in; 114, 115; 114, 116; 115, identifier:o; 116, identifier:origin_space; 117, attribute; 117, 118; 117, 119; 118, identifier:out; 119, identifier:write; 120, ERROR; 120, 121; 121, identifier:for; 122, identifier:o_; 123, identifier:r; 124, identifier:t; 125, comparison_operator:in; 125, 126; 125, 127; 126, identifier:a; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:m; 130, identifier:match; 131, argument_list; 131, 132; 132, identifier:o; 133, block; 133, 134; 133, 142; 133, 147; 133, 163; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:abbr_r; 137, call; 137, 138; 137, 139; 138, identifier:abbreviate; 139, argument_list; 139, 140; 139, 141; 140, identifier:r; 141, identifier:all_propertybase; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:value_format; 145, argument_list; 145, 146; 146, identifier:t; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:out; 151, identifier:write; 152, argument_list; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, string:'* {0}: {1}\n'; 156, identifier:format; 157, argument_list; 157, 158; 157, 159; 158, identifier:abbr_r; 159, call; 159, 160; 159, 161; 160, identifier:value_format; 161, argument_list; 161, 162; 162, identifier:t; 163, for_statement; 163, 164; 163, 167; 163, 172; 164, pattern_list; 164, 165; 164, 166; 165, identifier:k; 166, identifier:v; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:a; 170, identifier:items; 171, argument_list; 172, block; 172, 173; 172, 181; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:abbr_k; 176, call; 176, 177; 176, 178; 177, identifier:abbreviate; 178, argument_list; 178, 179; 178, 180; 179, identifier:k; 180, identifier:all_propertybase; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:out; 185, identifier:write; 186, argument_list; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, string:' * {0}: {1}\n'; 190, identifier:format; 191, argument_list; 191, 192; 191, 193; 192, identifier:k; 193, call; 193, 194; 193, 195; 194, identifier:value_format; 195, argument_list; 195, 196; 196, identifier:v; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:out; 201, identifier:write; 202, argument_list; 202, 203; 203, string:'\n'; 204, return_statement | def write(models, out=None, base=None, propertybase=None, shorteners=None, logger=logging):
'''
models - input Versa models from which output is generated. Must be a sequence
object, not an iterator
'''
assert out is not None
if not isinstance(models, list): models = [models]
shorteners = shorteners or {}
all_propertybase = [propertybase] if propertybase else []
all_propertybase.append(VERSA_BASEIRI)
if any((base, propertybase, shorteners)):
out.write('
if base:
out.write(' * @base: {0}'.format(base))
out.write('\n\n')
origin_space = set()
for m in models:
origin_space.update(all_origins(m))
for o in origin_space:
out.write('
for o_, r, t, a in m.match(o):
abbr_r = abbreviate(r, all_propertybase)
value_format(t)
out.write('* {0}: {1}\n'.format(abbr_r, value_format(t)))
for k, v in a.items():
abbr_k = abbreviate(k, all_propertybase)
out.write(' * {0}: {1}\n'.format(k, value_format(v)))
out.write('\n')
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:register_extensions; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, try_statement; 6, 7; 6, 159; 7, block; 7, 8; 8, for_statement; 8, 9; 8, 12; 8, 21; 9, pattern_list; 9, 10; 9, 11; 10, identifier:extension; 11, identifier:config; 12, call; 12, 13; 12, 20; 13, attribute; 13, 14; 13, 19; 14, subscript; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:config; 18, string:'extensions'; 19, identifier:items; 20, argument_list; 21, block; 21, 22; 21, 26; 21, 35; 21, 62; 21, 69; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:extension_bstr; 25, string:''; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:extension_pieces; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:extension; 32, identifier:split; 33, argument_list; 33, 34; 34, string:'.'; 35, if_statement; 35, 36; 35, 42; 35, 52; 36, comparison_operator:>; 36, 37; 36, 41; 37, call; 37, 38; 37, 39; 38, identifier:len; 39, argument_list; 39, 40; 40, identifier:extension_pieces; 41, integer:1; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:extension_bstr; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, string:'.'; 49, identifier:join; 50, argument_list; 50, 51; 51, identifier:extension_pieces; 52, else_clause; 52, 53; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:extension_bstr; 57, binary_operator:%; 57, 58; 57, 59; 58, string:'glim_extensions.%s'; 59, subscript; 59, 60; 59, 61; 60, identifier:extension_pieces; 61, integer:0; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:extension_module; 65, call; 65, 66; 65, 67; 66, identifier:import_module; 67, argument_list; 67, 68; 68, identifier:extension_bstr; 69, if_statement; 69, 70; 69, 71; 69, 148; 70, identifier:extension_module; 71, block; 71, 72; 71, 80; 71, 90; 71, 98; 71, 108; 71, 124; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:extension_startstr; 75, binary_operator:%; 75, 76; 75, 77; 76, string:'%s.%s'; 77, tuple; 77, 78; 77, 79; 78, identifier:extension_bstr; 79, string:'start'; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:extension_start; 83, call; 83, 84; 83, 85; 84, identifier:import_module; 85, argument_list; 85, 86; 85, 87; 86, identifier:extension_startstr; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:pass_errors; 89, True; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:extension_cmdsstr; 93, binary_operator:%; 93, 94; 93, 95; 94, string:'%s.%s'; 95, tuple; 95, 96; 95, 97; 96, identifier:extension_bstr; 97, string:'commands'; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:extension_cmds; 101, call; 101, 102; 101, 103; 102, identifier:import_module; 103, argument_list; 103, 104; 103, 105; 104, identifier:extension_cmdsstr; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:pass_errors; 107, True; 108, if_statement; 108, 109; 108, 112; 109, comparison_operator:is; 109, 110; 109, 111; 110, identifier:extension_start; 111, None; 112, block; 112, 113; 112, 119; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:before; 116, attribute; 116, 117; 116, 118; 117, identifier:extension_start; 118, identifier:before; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:before; 122, argument_list; 122, 123; 123, identifier:config; 124, if_statement; 124, 125; 124, 128; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:extension_cmds; 127, None; 128, block; 128, 129; 129, if_statement; 129, 130; 129, 135; 130, comparison_operator:is; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:commandadapter; 134, None; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:commandadapter; 142, identifier:register_extension; 143, argument_list; 143, 144; 143, 145; 144, identifier:extension_cmds; 145, subscript; 145, 146; 145, 147; 146, identifier:extension_pieces; 147, integer:0; 148, else_clause; 148, 149; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:GlimLog; 154, identifier:error; 155, argument_list; 155, 156; 156, binary_operator:%; 156, 157; 156, 158; 157, string:'Extension %s could not be loaded'; 158, identifier:extension; 159, except_clause; 159, 160; 159, 164; 160, as_pattern; 160, 161; 160, 162; 161, identifier:Exception; 162, as_pattern_target; 162, 163; 163, identifier:e; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:GlimLog; 169, identifier:error; 170, argument_list; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:traceback; 174, identifier:format_exc; 175, argument_list | def register_extensions(self):
try:
for extension, config in self.config['extensions'].items():
extension_bstr = ''
extension_pieces = extension.split('.')
if len(extension_pieces) > 1:
extension_bstr = '.'.join(extension_pieces)
else:
extension_bstr = 'glim_extensions.%s' % extension_pieces[0]
extension_module = import_module(extension_bstr)
if extension_module:
extension_startstr = '%s.%s' % (extension_bstr, 'start')
extension_start = import_module(extension_startstr, pass_errors=True)
extension_cmdsstr = '%s.%s' % (extension_bstr, 'commands')
extension_cmds = import_module(extension_cmdsstr, pass_errors=True)
if extension_start is not None:
before = extension_start.before
before(config)
if extension_cmds is not None:
if self.commandadapter is not None:
self.commandadapter.register_extension(extension_cmds, extension_pieces[0])
else:
GlimLog.error('Extension %s could not be loaded' % extension)
except Exception as e:
GlimLog.error(traceback.format_exc()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:request; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:self; 5, identifier:method; 6, identifier:path; 7, default_parameter; 7, 8; 7, 9; 8, identifier:query; 9, dictionary; 10, default_parameter; 10, 11; 10, 12; 11, identifier:headers; 12, dictionary; 13, default_parameter; 13, 14; 13, 15; 14, identifier:body; 15, dictionary; 16, default_parameter; 16, 17; 16, 18; 17, identifier:base_url; 18, None; 19, block; 19, 20; 19, 22; 19, 34; 19, 45; 19, 58; 19, 86; 19, 103; 19, 125; 19, 265; 20, expression_statement; 20, 21; 21, string:'''
Issues a request to Onshape
Args:
- method (str): HTTP method
- path (str): Path e.g. /api/documents/:id
- query (dict, default={}): Query params in key-value pairs
- headers (dict, default={}): Key-value pairs of headers
- body (dict, default={}): Body for POST request
- base_url (str, default=None): Host, including scheme and port (if different from creds file)
Returns:
- requests.Response: Object containing the response from Onshape
'''; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:req_headers; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_make_headers; 29, argument_list; 29, 30; 29, 31; 29, 32; 29, 33; 30, identifier:method; 31, identifier:path; 32, identifier:query; 33, identifier:headers; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:base_url; 37, None; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:base_url; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:_url; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:url; 48, binary_operator:+; 48, 49; 48, 54; 49, binary_operator:+; 49, 50; 49, 53; 50, binary_operator:+; 50, 51; 50, 52; 51, identifier:base_url; 52, identifier:path; 53, string:'?'; 54, call; 54, 55; 54, 56; 55, identifier:urlencode; 56, argument_list; 56, 57; 57, identifier:query; 58, if_statement; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:_logging; 62, block; 62, 63; 62, 70; 62, 77; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:utils; 67, identifier:log; 68, argument_list; 68, 69; 69, identifier:body; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:utils; 74, identifier:log; 75, argument_list; 75, 76; 76, identifier:req_headers; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:utils; 81, identifier:log; 82, argument_list; 82, 83; 83, binary_operator:+; 83, 84; 83, 85; 84, string:'request url: '; 85, identifier:url; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:body; 89, conditional_expression:if; 89, 90; 89, 96; 89, 102; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:json; 93, identifier:dumps; 94, argument_list; 94, 95; 95, identifier:body; 96, comparison_operator:==; 96, 97; 96, 101; 97, call; 97, 98; 97, 99; 98, identifier:type; 99, argument_list; 99, 100; 100, identifier:body; 101, identifier:dict; 102, identifier:body; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:res; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:requests; 109, identifier:request; 110, argument_list; 110, 111; 110, 112; 110, 113; 110, 116; 110, 119; 110, 122; 111, identifier:method; 112, identifier:url; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:headers; 115, identifier:req_headers; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:data; 118, identifier:body; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:allow_redirects; 121, False; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:stream; 124, True; 125, if_statement; 125, 126; 125, 131; 125, 219; 125, 247; 126, comparison_operator:==; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:res; 129, identifier:status_code; 130, integer:307; 131, block; 131, 132; 131, 143; 131, 152; 131, 170; 131, 174; 131, 186; 131, 200; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:location; 135, call; 135, 136; 135, 137; 136, identifier:urlparse; 137, argument_list; 137, 138; 138, subscript; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:res; 141, identifier:headers; 142, string:"Location"; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:querystring; 146, call; 146, 147; 146, 148; 147, identifier:parse_qs; 148, argument_list; 148, 149; 149, attribute; 149, 150; 149, 151; 150, identifier:location; 151, identifier:query; 152, if_statement; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:_logging; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:utils; 161, identifier:log; 162, argument_list; 162, 163; 163, binary_operator:+; 163, 164; 163, 165; 164, string:'request redirected to: '; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:location; 168, identifier:geturl; 169, argument_list; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:new_query; 173, dictionary; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:new_base_url; 177, binary_operator:+; 177, 178; 177, 183; 178, binary_operator:+; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:location; 181, identifier:scheme; 182, string:'://'; 183, attribute; 183, 184; 183, 185; 184, identifier:location; 185, identifier:netloc; 186, for_statement; 186, 187; 186, 188; 186, 189; 187, identifier:key; 188, identifier:querystring; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:new_query; 194, identifier:key; 195, subscript; 195, 196; 195, 199; 196, subscript; 196, 197; 196, 198; 197, identifier:querystring; 198, identifier:key; 199, integer:0; 200, return_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:request; 205, argument_list; 205, 206; 205, 207; 205, 210; 205, 213; 205, 216; 206, identifier:method; 207, attribute; 207, 208; 207, 209; 208, identifier:location; 209, identifier:path; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:query; 212, identifier:new_query; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:headers; 215, identifier:headers; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:base_url; 218, identifier:new_base_url; 219, elif_clause; 219, 220; 219, 227; 220, not_operator; 220, 221; 221, comparison_operator:<=; 221, 222; 221, 223; 221, 226; 222, integer:200; 223, attribute; 223, 224; 223, 225; 224, identifier:res; 225, identifier:status_code; 226, integer:206; 227, block; 227, 228; 228, if_statement; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:self; 231, identifier:_logging; 232, block; 232, 233; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:utils; 237, identifier:log; 238, argument_list; 238, 239; 238, 244; 239, binary_operator:+; 239, 240; 239, 241; 240, string:'request failed, details: '; 241, attribute; 241, 242; 241, 243; 242, identifier:res; 243, identifier:text; 244, keyword_argument; 244, 245; 244, 246; 245, identifier:level; 246, integer:1; 247, else_clause; 247, 248; 248, block; 248, 249; 249, if_statement; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:_logging; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:utils; 258, identifier:log; 259, argument_list; 259, 260; 260, binary_operator:+; 260, 261; 260, 262; 261, string:'request succeeded, details: '; 262, attribute; 262, 263; 262, 264; 263, identifier:res; 264, identifier:text; 265, return_statement; 265, 266; 266, identifier:res | def request(self, method, path, query={}, headers={}, body={}, base_url=None):
'''
Issues a request to Onshape
Args:
- method (str): HTTP method
- path (str): Path e.g. /api/documents/:id
- query (dict, default={}): Query params in key-value pairs
- headers (dict, default={}): Key-value pairs of headers
- body (dict, default={}): Body for POST request
- base_url (str, default=None): Host, including scheme and port (if different from creds file)
Returns:
- requests.Response: Object containing the response from Onshape
'''
req_headers = self._make_headers(method, path, query, headers)
if base_url is None:
base_url = self._url
url = base_url + path + '?' + urlencode(query)
if self._logging:
utils.log(body)
utils.log(req_headers)
utils.log('request url: ' + url)
body = json.dumps(body) if type(body) == dict else body
res = requests.request(method, url, headers=req_headers, data=body, allow_redirects=False, stream=True)
if res.status_code == 307:
location = urlparse(res.headers["Location"])
querystring = parse_qs(location.query)
if self._logging:
utils.log('request redirected to: ' + location.geturl())
new_query = {}
new_base_url = location.scheme + '://' + location.netloc
for key in querystring:
new_query[key] = querystring[key][0]
return self.request(method, location.path, query=new_query, headers=headers, base_url=new_base_url)
elif not 200 <= res.status_code <= 206:
if self._logging:
utils.log('request failed, details: ' + res.text, level=1)
else:
if self._logging:
utils.log('request succeeded, details: ' + res.text)
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:fix_pdb; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 20; 5, 50; 6, expression_statement; 6, 7; 7, string:'''A function to fix fatal errors in PDB files when they can be automatically fixed. At present, this only runs if
self.strict is False. We may want a separate property for this since we may want to keep strict mode but still
allow PDBs to be fixed.
The only fixes at the moment are for missing chain IDs which get filled in with a valid PDB ID, if possible.'''; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:strict; 12, block; 12, 13; 13, return_statement; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:chains; 17, call; 17, 18; 17, 19; 18, identifier:set; 19, argument_list; 20, for_statement; 20, 21; 20, 22; 20, 25; 21, identifier:l; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:lines; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 40; 27, boolean_operator:or; 27, 28; 27, 34; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:l; 31, identifier:startswith; 32, argument_list; 32, 33; 33, string:'ATOM '; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:l; 37, identifier:startswith; 38, argument_list; 38, 39; 39, string:'HETATM'; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:chains; 45, identifier:add; 46, argument_list; 46, 47; 47, subscript; 47, 48; 47, 49; 48, identifier:l; 49, integer:21; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:in; 51, 52; 51, 53; 52, string:' '; 53, identifier:chains; 54, block; 54, 55; 54, 59; 54, 84; 54, 100; 54, 109; 54, 113; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:fresh_id; 58, None; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:allowed_chain_ids; 62, binary_operator:+; 62, 63; 62, 76; 63, binary_operator:+; 63, 64; 63, 70; 64, call; 64, 65; 64, 66; 65, identifier:list; 66, argument_list; 66, 67; 67, attribute; 67, 68; 67, 69; 68, identifier:string; 69, identifier:uppercase; 70, call; 70, 71; 70, 72; 71, identifier:list; 72, argument_list; 72, 73; 73, attribute; 73, 74; 73, 75; 74, identifier:string; 75, identifier:lowercase; 76, call; 76, 77; 76, 78; 77, identifier:map; 78, argument_list; 78, 79; 78, 80; 79, identifier:str; 80, call; 80, 81; 80, 82; 81, identifier:range; 82, argument_list; 82, 83; 83, integer:10; 84, for_statement; 84, 85; 84, 86; 84, 87; 85, identifier:c; 86, identifier:chains; 87, block; 87, 88; 88, try_statement; 88, 89; 88, 97; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:allowed_chain_ids; 94, identifier:remove; 95, argument_list; 95, 96; 96, identifier:c; 97, except_clause; 97, 98; 98, block; 98, 99; 99, pass_statement; 100, if_statement; 100, 101; 100, 102; 101, identifier:allowed_chain_ids; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:fresh_id; 106, subscript; 106, 107; 106, 108; 107, identifier:allowed_chain_ids; 108, integer:0; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:new_lines; 112, list:[]; 113, if_statement; 113, 114; 113, 115; 114, identifier:fresh_id; 115, block; 115, 116; 115, 173; 116, for_statement; 116, 117; 116, 118; 116, 121; 117, identifier:l; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:lines; 121, block; 121, 122; 122, if_statement; 122, 123; 122, 143; 122, 164; 123, boolean_operator:and; 123, 124; 123, 138; 124, parenthesized_expression; 124, 125; 125, boolean_operator:or; 125, 126; 125, 132; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:l; 129, identifier:startswith; 130, argument_list; 130, 131; 131, string:'ATOM '; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:l; 135, identifier:startswith; 136, argument_list; 136, 137; 137, string:'HETATM'; 138, comparison_operator:==; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:l; 141, integer:21; 142, string:' '; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:new_lines; 148, identifier:append; 149, argument_list; 149, 150; 150, binary_operator:%; 150, 151; 150, 152; 151, string:'%s%s%s'; 152, tuple; 152, 153; 152, 158; 152, 159; 153, subscript; 153, 154; 153, 155; 154, identifier:l; 155, slice; 155, 156; 155, 157; 156, colon; 157, integer:21; 158, identifier:fresh_id; 159, subscript; 159, 160; 159, 161; 160, identifier:l; 161, slice; 161, 162; 161, 163; 162, integer:22; 163, colon; 164, else_clause; 164, 165; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:new_lines; 170, identifier:append; 171, argument_list; 171, 172; 172, identifier:l; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:lines; 178, identifier:new_lines | def fix_pdb(self):
'''A function to fix fatal errors in PDB files when they can be automatically fixed. At present, this only runs if
self.strict is False. We may want a separate property for this since we may want to keep strict mode but still
allow PDBs to be fixed.
The only fixes at the moment are for missing chain IDs which get filled in with a valid PDB ID, if possible.'''
if self.strict:
return
chains = set()
for l in self.lines:
if l.startswith('ATOM ') or l.startswith('HETATM'):
chains.add(l[21])
if ' ' in chains:
fresh_id = None
allowed_chain_ids = list(string.uppercase) + list(string.lowercase) + map(str, range(10))
for c in chains:
try: allowed_chain_ids.remove(c)
except: pass
if allowed_chain_ids:
fresh_id = allowed_chain_ids[0]
new_lines = []
if fresh_id:
for l in self.lines:
if (l.startswith('ATOM ') or l.startswith('HETATM')) and l[21] == ' ':
new_lines.append('%s%s%s' % (l[:21], fresh_id, l[22:]))
else:
new_lines.append(l)
self.lines = new_lines |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:stripForDDG; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:chains; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:keepHETATM; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:numberOfModels; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:raise_exception; 16, True; 17, block; 17, 18; 17, 20; 17, 28; 17, 34; 17, 38; 17, 42; 17, 46; 17, 50; 17, 54; 17, 58; 17, 263; 17, 269; 17, 275; 17, 281; 17, 285; 17, 296; 17, 304; 17, 319; 17, 325; 17, 331; 17, 341; 17, 348; 17, 352; 17, 364; 17, 369; 18, expression_statement; 18, 19; 19, string:'''Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines.
By default all PDB chains are kept. The chains parameter should be True or a list.
In the latter case, only those chains in the list are kept.
Unoccupied ATOM lines are discarded.
This function also builds maps from PDB numbering to Rosetta numbering and vice versa.
'''; 20, if_statement; 20, 21; 20, 22; 21, identifier:raise_exception; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:Exception; 26, argument_list; 26, 27; 27, string:'This code is deprecated.'; 28, import_from_statement; 28, 29; 28, 32; 29, dotted_name; 29, 30; 29, 31; 30, identifier:Bio; 31, identifier:PDB; 32, dotted_name; 32, 33; 33, identifier:PDBParser; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:resmap; 37, dictionary; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:iresmap; 41, dictionary; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:newlines; 45, list:[]; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:residx; 49, integer:0; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:oldres; 53, None; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:model_number; 57, integer:1; 58, for_statement; 58, 59; 58, 60; 58, 63; 59, identifier:line; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:lines; 63, block; 63, 64; 63, 77; 63, 104; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:fieldtype; 67, call; 67, 68; 67, 76; 68, attribute; 68, 69; 68, 75; 69, subscript; 69, 70; 69, 71; 70, identifier:line; 71, slice; 71, 72; 71, 73; 71, 74; 72, integer:0; 73, colon; 74, integer:6; 75, identifier:strip; 76, argument_list; 77, if_statement; 77, 78; 77, 81; 78, comparison_operator:==; 78, 79; 78, 80; 79, identifier:fieldtype; 80, string:"ENDMDL"; 81, block; 81, 82; 81, 86; 81, 95; 82, expression_statement; 82, 83; 83, augmented_assignment:+=; 83, 84; 83, 85; 84, identifier:model_number; 85, integer:1; 86, if_statement; 86, 87; 86, 93; 87, boolean_operator:and; 87, 88; 87, 89; 88, identifier:numberOfModels; 89, parenthesized_expression; 89, 90; 90, comparison_operator:>; 90, 91; 90, 92; 91, identifier:model_number; 92, identifier:numberOfModels; 93, block; 93, 94; 94, break_statement; 95, if_statement; 95, 96; 95, 98; 96, not_operator; 96, 97; 97, identifier:numberOfModels; 98, block; 98, 99; 99, raise_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:Exception; 102, argument_list; 102, 103; 103, string:"The logic here does not handle multiple models yet."; 104, if_statement; 104, 105; 104, 129; 105, boolean_operator:and; 105, 106; 105, 117; 106, parenthesized_expression; 106, 107; 107, boolean_operator:or; 107, 108; 107, 111; 108, comparison_operator:==; 108, 109; 108, 110; 109, identifier:fieldtype; 110, string:"ATOM"; 111, parenthesized_expression; 111, 112; 112, boolean_operator:and; 112, 113; 112, 116; 113, comparison_operator:==; 113, 114; 113, 115; 114, identifier:fieldtype; 115, string:"HETATM"; 116, identifier:keepHETATM; 117, parenthesized_expression; 117, 118; 118, comparison_operator:!=; 118, 119; 118, 128; 119, call; 119, 120; 119, 121; 120, identifier:float; 121, argument_list; 121, 122; 122, subscript; 122, 123; 122, 124; 123, identifier:line; 124, slice; 124, 125; 124, 126; 124, 127; 125, integer:54; 126, colon; 127, integer:60; 128, integer:0; 129, block; 129, 130; 129, 139; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:chain; 133, subscript; 133, 134; 133, 135; 134, identifier:line; 135, slice; 135, 136; 135, 137; 135, 138; 136, integer:21; 137, colon; 138, integer:22; 139, if_statement; 139, 140; 139, 149; 140, boolean_operator:or; 140, 141; 140, 145; 141, parenthesized_expression; 141, 142; 142, comparison_operator:==; 142, 143; 142, 144; 143, identifier:chains; 144, True; 145, parenthesized_expression; 145, 146; 146, comparison_operator:in; 146, 147; 146, 148; 147, identifier:chain; 148, identifier:chains; 149, block; 149, 150; 149, 159; 149, 168; 149, 217; 149, 224; 149, 248; 149, 256; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:resid; 153, subscript; 153, 154; 153, 155; 154, identifier:line; 155, slice; 155, 156; 155, 157; 155, 158; 156, integer:21; 157, colon; 158, integer:27; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:iCode; 162, subscript; 162, 163; 162, 164; 163, identifier:line; 164, slice; 164, 165; 164, 166; 164, 167; 165, integer:26; 166, colon; 167, integer:27; 168, if_statement; 168, 169; 168, 172; 169, comparison_operator:!=; 169, 170; 169, 171; 170, identifier:resid; 171, identifier:oldres; 172, block; 172, 173; 172, 177; 172, 185; 172, 193; 172, 201; 172, 207; 172, 213; 173, expression_statement; 173, 174; 174, augmented_assignment:+=; 174, 175; 174, 176; 175, identifier:residx; 176, integer:1; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:newnumbering; 180, binary_operator:%; 180, 181; 180, 182; 181, string:"%s%4.i "; 182, tuple; 182, 183; 182, 184; 183, identifier:chain; 184, identifier:residx; 185, assert_statement; 185, 186; 186, parenthesized_expression; 186, 187; 187, comparison_operator:==; 187, 188; 187, 192; 188, call; 188, 189; 188, 190; 189, identifier:len; 190, argument_list; 190, 191; 191, identifier:newnumbering; 192, integer:6; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:id; 196, binary_operator:+; 196, 197; 196, 200; 197, binary_operator:+; 197, 198; 197, 199; 198, identifier:fieldtype; 199, string:"-"; 200, identifier:resid; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:resmap; 205, identifier:id; 206, identifier:residx; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:iresmap; 211, identifier:residx; 212, identifier:id; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:oldres; 216, identifier:resid; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:oldlength; 220, call; 220, 221; 220, 222; 221, identifier:len; 222, argument_list; 222, 223; 223, identifier:line; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:line; 227, binary_operator:%; 227, 228; 227, 229; 228, string:"%s%4.i %s"; 229, tuple; 229, 230; 229, 236; 229, 243; 230, subscript; 230, 231; 230, 232; 231, identifier:line; 232, slice; 232, 233; 232, 234; 232, 235; 233, integer:0; 234, colon; 235, integer:22; 236, subscript; 236, 237; 236, 238; 237, identifier:resmap; 238, binary_operator:+; 238, 239; 238, 242; 239, binary_operator:+; 239, 240; 239, 241; 240, identifier:fieldtype; 241, string:"-"; 242, identifier:resid; 243, subscript; 243, 244; 243, 245; 244, identifier:line; 245, slice; 245, 246; 245, 247; 246, integer:27; 247, colon; 248, assert_statement; 248, 249; 249, parenthesized_expression; 249, 250; 250, comparison_operator:==; 250, 251; 250, 255; 251, call; 251, 252; 251, 253; 252, identifier:len; 253, argument_list; 253, 254; 254, identifier:line; 255, identifier:oldlength; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:newlines; 260, identifier:append; 261, argument_list; 261, 262; 262, identifier:line; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:lines; 268, identifier:newlines; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:self; 273, identifier:ddGresmap; 274, identifier:resmap; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:self; 279, identifier:ddGiresmap; 280, identifier:iresmap; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:tmpfile; 284, string:"/tmp/ddgtemp.pdb"; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:lines; 290, boolean_operator:or; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:self; 293, identifier:lines; 294, list:["\n"]; 294, 295; 295, string:"\n"; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:F; 299, call; 299, 300; 299, 301; 300, identifier:open; 301, argument_list; 301, 302; 301, 303; 302, identifier:tmpfile; 303, string:'w'; 304, expression_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:F; 308, identifier:write; 309, argument_list; 309, 310; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:string; 313, identifier:join; 314, argument_list; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:self; 317, identifier:lines; 318, string:"\n"; 319, expression_statement; 319, 320; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:F; 323, identifier:close; 324, argument_list; 325, expression_statement; 325, 326; 326, assignment; 326, 327; 326, 328; 327, identifier:parser; 328, call; 328, 329; 328, 330; 329, identifier:PDBParser; 330, argument_list; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 334; 333, identifier:structure; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:parser; 337, identifier:get_structure; 338, argument_list; 338, 339; 338, 340; 339, string:'tmp'; 340, identifier:tmpfile; 341, expression_statement; 341, 342; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:os; 345, identifier:remove; 346, argument_list; 346, 347; 347, identifier:tmpfile; 348, expression_statement; 348, 349; 349, assignment; 349, 350; 349, 351; 350, identifier:count; 351, integer:0; 352, for_statement; 352, 353; 352, 354; 352, 359; 353, identifier:residue; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:structure; 357, identifier:get_residues; 358, argument_list; 359, block; 359, 360; 360, expression_statement; 360, 361; 361, augmented_assignment:+=; 361, 362; 361, 363; 362, identifier:count; 363, integer:1; 364, assert_statement; 364, 365; 365, parenthesized_expression; 365, 366; 366, comparison_operator:==; 366, 367; 366, 368; 367, identifier:count; 368, identifier:residx; 369, assert_statement; 369, 370; 370, parenthesized_expression; 370, 371; 371, comparison_operator:==; 371, 372; 371, 376; 372, call; 372, 373; 372, 374; 373, identifier:len; 374, argument_list; 374, 375; 375, identifier:resmap; 376, call; 376, 377; 376, 378; 377, identifier:len; 378, argument_list; 378, 379; 379, identifier:iresmap | def stripForDDG(self, chains = True, keepHETATM = False, numberOfModels = None, raise_exception = True):
'''Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines.
By default all PDB chains are kept. The chains parameter should be True or a list.
In the latter case, only those chains in the list are kept.
Unoccupied ATOM lines are discarded.
This function also builds maps from PDB numbering to Rosetta numbering and vice versa.
'''
if raise_exception:
raise Exception('This code is deprecated.')
from Bio.PDB import PDBParser
resmap = {}
iresmap = {}
newlines = []
residx = 0
oldres = None
model_number = 1
for line in self.lines:
fieldtype = line[0:6].strip()
if fieldtype == "ENDMDL":
model_number += 1
if numberOfModels and (model_number > numberOfModels):
break
if not numberOfModels:
raise Exception("The logic here does not handle multiple models yet.")
if (fieldtype == "ATOM" or (fieldtype == "HETATM" and keepHETATM)) and (float(line[54:60]) != 0):
chain = line[21:22]
if (chains == True) or (chain in chains):
resid = line[21:27]
iCode = line[26:27]
if resid != oldres:
residx += 1
newnumbering = "%s%4.i " % (chain, residx)
assert(len(newnumbering) == 6)
id = fieldtype + "-" + resid
resmap[id] = residx
iresmap[residx] = id
oldres = resid
oldlength = len(line)
line = "%s%4.i %s" % (line[0:22], resmap[fieldtype + "-" + resid], line[27:])
assert(len(line) == oldlength)
newlines.append(line)
self.lines = newlines
self.ddGresmap = resmap
self.ddGiresmap = iresmap
tmpfile = "/tmp/ddgtemp.pdb"
self.lines = self.lines or ["\n"]
F = open(tmpfile,'w')
F.write(string.join(self.lines, "\n"))
F.close()
parser=PDBParser()
structure=parser.get_structure('tmp', tmpfile)
os.remove(tmpfile)
count = 0
for residue in structure.get_residues():
count += 1
assert(count == residx)
assert(len(resmap) == len(iresmap)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:neighbors2; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:distance; 6, identifier:chain_residue; 7, default_parameter; 7, 8; 7, 9; 8, identifier:atom; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:resid_list; 12, None; 13, block; 13, 14; 13, 16; 13, 76; 13, 85; 13, 133; 13, 137; 13, 218; 14, expression_statement; 14, 15; 15, string:'''this one is more precise since it uses the chain identifier also'''; 16, if_statement; 16, 17; 16, 20; 16, 43; 17, comparison_operator:==; 17, 18; 17, 19; 18, identifier:atom; 19, None; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:lines; 24, list_comprehension; 24, 25; 24, 26; 24, 34; 25, identifier:line; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:line; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:atomlines; 32, argument_list; 32, 33; 33, identifier:resid_list; 34, if_clause; 34, 35; 35, comparison_operator:in; 35, 36; 35, 42; 36, subscript; 36, 37; 36, 38; 37, identifier:line; 38, slice; 38, 39; 38, 40; 38, 41; 39, integer:17; 40, colon; 41, integer:20; 42, identifier:allowed_PDB_residues_types; 43, else_clause; 43, 44; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:lines; 48, list_comprehension; 48, 49; 48, 50; 48, 58; 49, identifier:line; 50, for_in_clause; 50, 51; 50, 52; 51, identifier:line; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:atomlines; 56, argument_list; 56, 57; 57, identifier:resid_list; 58, if_clause; 58, 59; 59, boolean_operator:and; 59, 60; 59, 68; 60, comparison_operator:in; 60, 61; 60, 67; 61, subscript; 61, 62; 61, 63; 62, identifier:line; 63, slice; 63, 64; 63, 65; 63, 66; 64, integer:17; 65, colon; 66, integer:20; 67, identifier:allowed_PDB_residues_types; 68, comparison_operator:==; 68, 69; 68, 75; 69, subscript; 69, 70; 69, 71; 70, identifier:line; 71, slice; 71, 72; 71, 73; 71, 74; 72, integer:12; 73, colon; 74, integer:16; 75, identifier:atom; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:shash; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:spatialhash; 82, identifier:SpatialHash; 83, argument_list; 83, 84; 84, identifier:distance; 85, for_statement; 85, 86; 85, 87; 85, 88; 86, identifier:line; 87, identifier:lines; 88, block; 88, 89; 88, 120; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:pos; 92, tuple; 92, 93; 92, 102; 92, 111; 93, call; 93, 94; 93, 95; 94, identifier:float; 95, argument_list; 95, 96; 96, subscript; 96, 97; 96, 98; 97, identifier:line; 98, slice; 98, 99; 98, 100; 98, 101; 99, integer:30; 100, colon; 101, integer:38; 102, call; 102, 103; 102, 104; 103, identifier:float; 104, argument_list; 104, 105; 105, subscript; 105, 106; 105, 107; 106, identifier:line; 107, slice; 107, 108; 107, 109; 107, 110; 108, integer:38; 109, colon; 110, integer:46; 111, call; 111, 112; 111, 113; 112, identifier:float; 113, argument_list; 113, 114; 114, subscript; 114, 115; 114, 116; 115, identifier:line; 116, slice; 116, 117; 116, 118; 116, 119; 117, integer:46; 118, colon; 119, integer:54; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:shash; 124, identifier:insert; 125, argument_list; 125, 126; 125, 127; 126, identifier:pos; 127, subscript; 127, 128; 127, 129; 128, identifier:line; 129, slice; 129, 130; 129, 131; 129, 132; 130, integer:21; 131, colon; 132, integer:26; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:neighbor_list; 136, list:[]; 137, for_statement; 137, 138; 137, 139; 137, 140; 138, identifier:line; 139, identifier:lines; 140, block; 140, 141; 140, 150; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:resid; 144, subscript; 144, 145; 144, 146; 145, identifier:line; 146, slice; 146, 147; 146, 148; 146, 149; 147, integer:21; 148, colon; 149, integer:26; 150, if_statement; 150, 151; 150, 154; 151, comparison_operator:==; 151, 152; 151, 153; 152, identifier:resid; 153, identifier:chain_residue; 154, block; 154, 155; 154, 186; 154, 212; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:pos; 158, tuple; 158, 159; 158, 168; 158, 177; 159, call; 159, 160; 159, 161; 160, identifier:float; 161, argument_list; 161, 162; 162, subscript; 162, 163; 162, 164; 163, identifier:line; 164, slice; 164, 165; 164, 166; 164, 167; 165, integer:30; 166, colon; 167, integer:38; 168, call; 168, 169; 168, 170; 169, identifier:float; 170, argument_list; 170, 171; 171, subscript; 171, 172; 171, 173; 172, identifier:line; 173, slice; 173, 174; 173, 175; 173, 176; 174, integer:38; 175, colon; 176, integer:46; 177, call; 177, 178; 177, 179; 178, identifier:float; 179, argument_list; 179, 180; 180, subscript; 180, 181; 180, 182; 181, identifier:line; 182, slice; 182, 183; 182, 184; 182, 185; 183, integer:46; 184, colon; 185, integer:54; 186, for_statement; 186, 187; 186, 188; 186, 195; 187, identifier:data; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:shash; 191, identifier:nearby; 192, argument_list; 192, 193; 192, 194; 193, identifier:pos; 194, identifier:distance; 195, block; 195, 196; 196, if_statement; 196, 197; 196, 202; 197, comparison_operator:not; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:data; 200, integer:1; 201, identifier:neighbor_list; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:neighbor_list; 207, identifier:append; 208, argument_list; 208, 209; 209, subscript; 209, 210; 209, 211; 210, identifier:data; 211, integer:1; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:neighbor_list; 216, identifier:sort; 217, argument_list; 218, return_statement; 218, 219; 219, identifier:neighbor_list | def neighbors2(self, distance, chain_residue, atom = None, resid_list = None):
'''this one is more precise since it uses the chain identifier also'''
if atom == None:
lines = [line for line in self.atomlines(resid_list) if line[17:20] in allowed_PDB_residues_types]
else:
lines = [line for line in self.atomlines(resid_list) if line[17:20] in allowed_PDB_residues_types and line[12:16] == atom]
shash = spatialhash.SpatialHash(distance)
for line in lines:
pos = (float(line[30:38]), float(line[38:46]), float(line[46:54]))
shash.insert(pos, line[21:26])
neighbor_list = []
for line in lines:
resid = line[21:26]
if resid == chain_residue:
pos = (float(line[30:38]), float(line[38:46]), float(line[46:54]))
for data in shash.nearby(pos, distance):
if data[1] not in neighbor_list:
neighbor_list.append(data[1])
neighbor_list.sort()
return neighbor_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:add_document; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, identifier:item_uri; 6, identifier:name; 7, identifier:metadata; 8, default_parameter; 8, 9; 8, 10; 9, identifier:content; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:docurl; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:file; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:displaydoc; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:preferName; 22, False; 23, default_parameter; 23, 24; 23, 25; 24, identifier:contrib_id; 25, None; 26, block; 26, 27; 26, 52; 26, 70; 26, 79; 26, 88; 26, 133; 26, 186; 26, 193; 26, 211; 26, 219; 27, if_statement; 27, 28; 27, 34; 27, 46; 28, boolean_operator:and; 28, 29; 28, 31; 29, not_operator; 29, 30; 30, identifier:preferName; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:file; 33, None; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:docid; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:os; 42, identifier:path; 43, identifier:basename; 44, argument_list; 44, 45; 45, identifier:file; 46, else_clause; 46, 47; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:docid; 51, identifier:name; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:docmeta; 55, dictionary; 55, 56; 56, pair; 56, 57; 56, 58; 57, string:"metadata"; 58, dictionary; 58, 59; 58, 64; 58, 67; 59, pair; 59, 60; 59, 61; 60, string:"@context"; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:context; 64, pair; 64, 65; 64, 66; 65, string:"@type"; 66, string:"foaf:Document"; 67, pair; 67, 68; 67, 69; 68, string:"dcterms:identifier"; 69, identifier:docid; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:docmeta; 75, string:"metadata"; 76, identifier:update; 77, argument_list; 77, 78; 78, identifier:metadata; 79, if_statement; 79, 80; 79, 81; 80, identifier:contrib_id; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:docmeta; 86, string:'contribution_id'; 87, identifier:contrib_id; 88, if_statement; 88, 89; 88, 92; 88, 99; 88, 115; 88, 126; 89, comparison_operator:is; 89, 90; 89, 91; 90, identifier:content; 91, None; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:docmeta; 97, string:'document_content'; 98, identifier:content; 99, elif_clause; 99, 100; 99, 103; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:docurl; 102, None; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:docmeta; 109, string:"metadata"; 110, string:"dcterms:source"; 111, dictionary; 111, 112; 112, pair; 112, 113; 112, 114; 113, string:"@id"; 114, identifier:docurl; 115, elif_clause; 115, 116; 115, 119; 116, comparison_operator:is; 116, 117; 116, 118; 117, identifier:file; 118, None; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:docmeta; 123, subscript; 123, 124; 123, 125; 124, identifier:docmeta; 125, string:'metadata'; 126, else_clause; 126, 127; 127, block; 127, 128; 128, raise_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:Exception; 131, argument_list; 131, 132; 132, string:"One of content, docurl or file must be specified in add_document"; 133, if_statement; 133, 134; 133, 137; 133, 164; 134, comparison_operator:is; 134, 135; 134, 136; 135, identifier:file; 136, None; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:result; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:api_request; 145, argument_list; 145, 146; 145, 147; 145, 150; 145, 161; 146, identifier:item_uri; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:method; 149, string:'POST'; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:data; 152, dictionary; 152, 153; 153, pair; 153, 154; 153, 155; 154, string:'metadata'; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:json; 158, identifier:dumps; 159, argument_list; 159, 160; 160, identifier:docmeta; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:file; 163, identifier:file; 164, else_clause; 164, 165; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:result; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:api_request; 173, argument_list; 173, 174; 173, 175; 173, 178; 174, identifier:item_uri; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:method; 177, string:'POST'; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:data; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:json; 183, identifier:dumps; 184, argument_list; 184, 185; 185, identifier:docmeta; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:__check_success; 191, argument_list; 191, 192; 192, identifier:result; 193, if_statement; 193, 194; 193, 195; 194, identifier:displaydoc; 195, block; 195, 196; 195, 203; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:itemmeta; 199, dictionary; 199, 200; 200, pair; 200, 201; 200, 202; 201, string:"http://alveo.edu.org/vocabulary/display_document"; 202, identifier:docid; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:modify_item; 208, argument_list; 208, 209; 208, 210; 209, identifier:item_uri; 210, identifier:itemmeta; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:doc_uri; 214, binary_operator:+; 214, 215; 214, 218; 215, binary_operator:+; 215, 216; 215, 217; 216, identifier:item_uri; 217, string:"/document/"; 218, identifier:name; 219, return_statement; 219, 220; 220, identifier:doc_uri | def add_document(self, item_uri, name, metadata,
content=None, docurl=None, file=None,
displaydoc=False, preferName=False,
contrib_id=None):
if not preferName and file is not None:
docid = os.path.basename(file)
else:
docid = name
docmeta = {"metadata": {"@context": self.context,
"@type": "foaf:Document",
"dcterms:identifier": docid,
}
}
docmeta["metadata"].update(metadata)
if contrib_id:
docmeta['contribution_id'] = contrib_id
if content is not None:
docmeta['document_content'] = content
elif docurl is not None:
docmeta["metadata"]["dcterms:source"] = { "@id": docurl }
elif file is not None:
docmeta = docmeta['metadata']
else:
raise Exception("One of content, docurl or file must be specified in add_document")
if file is not None:
result = self.api_request(item_uri, method='POST', data={'metadata': json.dumps(docmeta)}, file=file)
else:
result = self.api_request(item_uri, method='POST', data=json.dumps(docmeta))
self.__check_success(result)
if displaydoc:
itemmeta = {"http://alveo.edu.org/vocabulary/display_document": docid}
self.modify_item(item_uri, itemmeta)
doc_uri = item_uri + "/document/" + name
return doc_uri |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_agents; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:addr; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:agent_cls; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:include_manager; 13, False; 14, block; 14, 15; 14, 17; 14, 32; 14, 71; 14, 91; 14, 104; 15, expression_statement; 15, 16; 16, string:'''Get agents in the environment.
:param bool addr: If ``True``, returns only addresses of the agents.
:param agent_cls:
Optional, if specified returns only agents belonging to that
particular class.
:param bool include_manager:
If `True``` includes the environment's manager, i.e. the agent in
the address ``tcp://environment-host:port/0``, to the returned
list if the environment has attribute :attr:`manager`. If
environment does not have :attr:`manager`, then the parameter does
nothing.
:returns: A list of agents in the environment.
:rtype: list
.. note::
By design, manager agents are excluded from the returned lists of
agents by default.
'''; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:agents; 20, call; 20, 21; 20, 22; 21, identifier:list; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 31; 24, attribute; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:agents; 29, identifier:dict; 30, identifier:values; 31, argument_list; 32, if_statement; 32, 33; 32, 44; 33, boolean_operator:and; 33, 34; 33, 39; 34, call; 34, 35; 34, 36; 35, identifier:hasattr; 36, argument_list; 36, 37; 36, 38; 37, identifier:self; 38, string:'manager'; 39, comparison_operator:is; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:manager; 43, None; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 48; 46, not_operator; 46, 47; 47, identifier:include_manager; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:agents; 52, list_comprehension; 52, 53; 52, 54; 52, 57; 53, identifier:a; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:a; 56, identifier:agents; 57, if_clause; 57, 58; 58, comparison_operator:!=; 58, 59; 58, 70; 59, subscript; 59, 60; 59, 69; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:a; 64, identifier:addr; 65, identifier:rsplit; 66, argument_list; 66, 67; 66, 68; 67, string:'/'; 68, integer:1; 69, integer:1; 70, string:'0'; 71, if_statement; 71, 72; 71, 75; 72, comparison_operator:is; 72, 73; 72, 74; 73, identifier:agent_cls; 74, None; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:agents; 79, list_comprehension; 79, 80; 79, 81; 79, 84; 80, identifier:a; 81, for_in_clause; 81, 82; 81, 83; 82, identifier:a; 83, identifier:agents; 84, if_clause; 84, 85; 85, comparison_operator:is; 85, 86; 85, 90; 86, call; 86, 87; 86, 88; 87, identifier:type; 88, argument_list; 88, 89; 89, identifier:a; 90, identifier:agent_cls; 91, if_statement; 91, 92; 91, 93; 92, identifier:addr; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:agents; 97, list_comprehension; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:agent; 100, identifier:addr; 101, for_in_clause; 101, 102; 101, 103; 102, identifier:agent; 103, identifier:agents; 104, return_statement; 104, 105; 105, identifier:agents | def get_agents(self, addr=True, agent_cls=None, include_manager=False):
'''Get agents in the environment.
:param bool addr: If ``True``, returns only addresses of the agents.
:param agent_cls:
Optional, if specified returns only agents belonging to that
particular class.
:param bool include_manager:
If `True``` includes the environment's manager, i.e. the agent in
the address ``tcp://environment-host:port/0``, to the returned
list if the environment has attribute :attr:`manager`. If
environment does not have :attr:`manager`, then the parameter does
nothing.
:returns: A list of agents in the environment.
:rtype: list
.. note::
By design, manager agents are excluded from the returned lists of
agents by default.
'''
agents = list(self.agents.dict.values())
if hasattr(self, 'manager') and self.manager is not None:
if not include_manager:
agents = [a for a in agents if a.addr.rsplit('/', 1)[1] != '0']
if agent_cls is not None:
agents = [a for a in agents if type(a) is agent_cls]
if addr:
agents = [agent.addr for agent in agents]
return agents |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:tee; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:popenargs; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 16; 8, 38; 8, 46; 8, 73; 8, 167; 8, 181; 8, 195; 9, import_statement; 9, 10; 9, 12; 9, 14; 10, dotted_name; 10, 11; 11, identifier:subprocess; 12, dotted_name; 12, 13; 13, identifier:select; 14, dotted_name; 14, 15; 15, identifier:sys; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:process; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:subprocess; 22, identifier:Popen; 23, argument_list; 23, 24; 23, 29; 23, 34; 23, 36; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:stdout; 26, attribute; 26, 27; 26, 28; 27, identifier:subprocess; 28, identifier:PIPE; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:stderr; 31, attribute; 31, 32; 31, 33; 32, identifier:subprocess; 33, identifier:PIPE; 34, list_splat; 34, 35; 35, identifier:popenargs; 36, dictionary_splat; 36, 37; 37, identifier:kwargs; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, pattern_list; 40, 41; 40, 42; 41, identifier:stdout; 42, identifier:stderr; 43, expression_list; 43, 44; 43, 45; 44, string:''; 45, string:''; 46, function_definition; 46, 47; 46, 48; 46, 51; 47, function_name:read_stream; 48, parameters; 48, 49; 48, 50; 49, identifier:input_callback; 50, identifier:output_stream; 51, block; 51, 52; 51, 58; 51, 65; 51, 71; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:read; 55, call; 55, 56; 55, 57; 56, identifier:input_callback; 57, argument_list; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:output_stream; 62, identifier:write; 63, argument_list; 63, 64; 64, identifier:read; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:output_stream; 69, identifier:flush; 70, argument_list; 71, return_statement; 71, 72; 72, identifier:read; 73, while_statement; 73, 74; 73, 81; 74, comparison_operator:is; 74, 75; 74, 80; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:process; 78, identifier:poll; 79, argument_list; 80, None; 81, block; 81, 82; 81, 100; 81, 113; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:watch; 85, expression_list; 85, 86; 85, 93; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:process; 90, identifier:stdout; 91, identifier:fileno; 92, argument_list; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:process; 97, identifier:stderr; 98, identifier:fileno; 99, argument_list; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:ready; 103, subscript; 103, 104; 103, 112; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:select; 107, identifier:select; 108, argument_list; 108, 109; 108, 110; 108, 111; 109, identifier:watch; 110, list:[]; 111, list:[]; 112, integer:0; 113, for_statement; 113, 114; 113, 115; 113, 116; 114, identifier:fd; 115, identifier:ready; 116, block; 116, 117; 116, 142; 117, if_statement; 117, 118; 117, 127; 118, comparison_operator:==; 118, 119; 118, 120; 119, identifier:fd; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:process; 124, identifier:stdout; 125, identifier:fileno; 126, argument_list; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, augmented_assignment:+=; 129, 130; 129, 131; 130, identifier:stdout; 131, call; 131, 132; 131, 133; 132, identifier:read_stream; 133, argument_list; 133, 134; 133, 139; 134, attribute; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:process; 137, identifier:stdout; 138, identifier:readline; 139, attribute; 139, 140; 139, 141; 140, identifier:sys; 141, identifier:stdout; 142, if_statement; 142, 143; 142, 152; 143, comparison_operator:==; 143, 144; 143, 145; 144, identifier:fd; 145, call; 145, 146; 145, 151; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:process; 149, identifier:stderr; 150, identifier:fileno; 151, argument_list; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, augmented_assignment:+=; 154, 155; 154, 156; 155, identifier:stderr; 156, call; 156, 157; 156, 158; 157, identifier:read_stream; 158, argument_list; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:process; 162, identifier:stderr; 163, identifier:readline; 164, attribute; 164, 165; 164, 166; 165, identifier:sys; 166, identifier:stderr; 167, expression_statement; 167, 168; 168, augmented_assignment:+=; 168, 169; 168, 170; 169, identifier:stdout; 170, call; 170, 171; 170, 172; 171, identifier:read_stream; 172, argument_list; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:process; 176, identifier:stdout; 177, identifier:read; 178, attribute; 178, 179; 178, 180; 179, identifier:sys; 180, identifier:stdout; 181, expression_statement; 181, 182; 182, augmented_assignment:+=; 182, 183; 182, 184; 183, identifier:stderr; 184, call; 184, 185; 184, 186; 185, identifier:read_stream; 186, argument_list; 186, 187; 186, 192; 187, attribute; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:process; 190, identifier:stderr; 191, identifier:read; 192, attribute; 192, 193; 192, 194; 193, identifier:sys; 194, identifier:stderr; 195, return_statement; 195, 196; 196, expression_list; 196, 197; 196, 198; 197, identifier:stdout; 198, identifier:stderr | def tee(*popenargs, **kwargs):
import subprocess, select, sys
process = subprocess.Popen(
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
*popenargs, **kwargs)
stdout, stderr = '', ''
def read_stream(input_callback, output_stream):
read = input_callback()
output_stream.write(read)
output_stream.flush()
return read
while process.poll() is None:
watch = process.stdout.fileno(), process.stderr.fileno()
ready = select.select(watch, [], [])[0]
for fd in ready:
if fd == process.stdout.fileno():
stdout += read_stream(process.stdout.readline, sys.stdout)
if fd == process.stderr.fileno():
stderr += read_stream(process.stderr.readline, sys.stderr)
stdout += read_stream(process.stdout.read, sys.stdout)
stderr += read_stream(process.stderr.read, sys.stderr)
return stdout, stderr |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:dump_object; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:obj; 6, block; 6, 7; 6, 21; 6, 34; 6, 56; 7, if_statement; 7, 8; 7, 15; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 12; 11, identifier:obj; 12, attribute; 12, 13; 12, 14; 13, identifier:uuid; 14, identifier:UUID; 15, block; 15, 16; 16, return_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:str; 19, argument_list; 19, 20; 20, identifier:obj; 21, if_statement; 21, 22; 21, 27; 22, call; 22, 23; 22, 24; 23, identifier:hasattr; 24, argument_list; 24, 25; 24, 26; 25, identifier:obj; 26, string:'isoformat'; 27, block; 27, 28; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:obj; 32, identifier:isoformat; 33, argument_list; 34, if_statement; 34, 35; 34, 43; 35, call; 35, 36; 35, 37; 36, identifier:isinstance; 37, argument_list; 37, 38; 37, 39; 38, identifier:obj; 39, tuple; 39, 40; 39, 41; 39, 42; 40, identifier:bytes; 41, identifier:bytearray; 42, identifier:memoryview; 43, block; 43, 44; 44, return_statement; 44, 45; 45, call; 45, 46; 45, 54; 46, attribute; 46, 47; 46, 53; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:base64; 50, identifier:b64encode; 51, argument_list; 51, 52; 52, identifier:obj; 53, identifier:decode; 54, argument_list; 54, 55; 55, string:'ASCII'; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:TypeError; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, string:'{!r} is not JSON serializable'; 63, identifier:format; 64, argument_list; 64, 65; 65, identifier:obj | def dump_object(self, obj):
if isinstance(obj, uuid.UUID):
return str(obj)
if hasattr(obj, 'isoformat'):
return obj.isoformat()
if isinstance(obj, (bytes, bytearray, memoryview)):
return base64.b64encode(obj).decode('ASCII')
raise TypeError('{!r} is not JSON serializable'.format(obj)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:normalize_datum; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:datum; 6, block; 6, 7; 6, 14; 6, 25; 6, 41; 6, 55; 6, 70; 6, 85; 6, 96; 6, 120; 6, 156; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:is; 8, 9; 8, 10; 9, identifier:datum; 10, None; 11, block; 11, 12; 12, return_statement; 12, 13; 13, identifier:datum; 14, if_statement; 14, 15; 14, 22; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:datum; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:PACKABLE_TYPES; 22, block; 22, 23; 23, return_statement; 23, 24; 24, identifier:datum; 25, if_statement; 25, 26; 25, 33; 26, call; 26, 27; 26, 28; 27, identifier:isinstance; 28, argument_list; 28, 29; 28, 30; 29, identifier:datum; 30, attribute; 30, 31; 30, 32; 31, identifier:uuid; 32, identifier:UUID; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:datum; 37, call; 37, 38; 37, 39; 38, identifier:str; 39, argument_list; 39, 40; 40, identifier:datum; 41, if_statement; 41, 42; 41, 47; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 46; 45, identifier:datum; 46, identifier:bytearray; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:datum; 51, call; 51, 52; 51, 53; 52, identifier:bytes; 53, argument_list; 53, 54; 54, identifier:datum; 55, if_statement; 55, 56; 55, 61; 56, call; 56, 57; 56, 58; 57, identifier:isinstance; 58, argument_list; 58, 59; 58, 60; 59, identifier:datum; 60, identifier:memoryview; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:datum; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:datum; 68, identifier:tobytes; 69, argument_list; 70, if_statement; 70, 71; 70, 76; 71, call; 71, 72; 71, 73; 72, identifier:hasattr; 73, argument_list; 73, 74; 73, 75; 74, identifier:datum; 75, string:'isoformat'; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:datum; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:datum; 83, identifier:isoformat; 84, argument_list; 85, if_statement; 85, 86; 85, 93; 86, call; 86, 87; 86, 88; 87, identifier:isinstance; 88, argument_list; 88, 89; 88, 90; 89, identifier:datum; 90, tuple; 90, 91; 90, 92; 91, identifier:bytes; 92, identifier:str; 93, block; 93, 94; 94, return_statement; 94, 95; 95, identifier:datum; 96, if_statement; 96, 97; 96, 108; 97, call; 97, 98; 97, 99; 98, identifier:isinstance; 99, argument_list; 99, 100; 99, 101; 100, identifier:datum; 101, tuple; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:collections; 104, identifier:Sequence; 105, attribute; 105, 106; 105, 107; 106, identifier:collections; 107, identifier:Set; 108, block; 108, 109; 109, return_statement; 109, 110; 110, list_comprehension; 110, 111; 110, 117; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:normalize_datum; 115, argument_list; 115, 116; 116, identifier:item; 117, for_in_clause; 117, 118; 117, 119; 118, identifier:item; 119, identifier:datum; 120, if_statement; 120, 121; 120, 128; 121, call; 121, 122; 121, 123; 122, identifier:isinstance; 123, argument_list; 123, 124; 123, 125; 124, identifier:datum; 125, attribute; 125, 126; 125, 127; 126, identifier:collections; 127, identifier:Mapping; 128, block; 128, 129; 128, 133; 128, 154; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:out; 132, dictionary; 133, for_statement; 133, 134; 133, 137; 133, 142; 134, pattern_list; 134, 135; 134, 136; 135, identifier:k; 136, identifier:v; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:datum; 140, identifier:items; 141, argument_list; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:out; 147, identifier:k; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:normalize_datum; 152, argument_list; 152, 153; 153, identifier:v; 154, return_statement; 154, 155; 155, identifier:out; 156, raise_statement; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:TypeError; 159, argument_list; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, string:'{} is not msgpackable'; 163, identifier:format; 164, argument_list; 164, 165; 165, attribute; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:datum; 168, identifier:__class__; 169, identifier:__name__ | def normalize_datum(self, datum):
if datum is None:
return datum
if isinstance(datum, self.PACKABLE_TYPES):
return datum
if isinstance(datum, uuid.UUID):
datum = str(datum)
if isinstance(datum, bytearray):
datum = bytes(datum)
if isinstance(datum, memoryview):
datum = datum.tobytes()
if hasattr(datum, 'isoformat'):
datum = datum.isoformat()
if isinstance(datum, (bytes, str)):
return datum
if isinstance(datum, (collections.Sequence, collections.Set)):
return [self.normalize_datum(item) for item in datum]
if isinstance(datum, collections.Mapping):
out = {}
for k, v in datum.items():
out[k] = self.normalize_datum(v)
return out
raise TypeError(
'{} is not msgpackable'.format(datum.__class__.__name__)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:redirect; 3, parameters; 3, 4; 3, 5; 4, identifier:endpoint; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kw; 7, block; 7, 8; 7, 12; 7, 128; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:_endpoint; 11, None; 12, if_statement; 12, 13; 12, 20; 12, 73; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:endpoint; 17, attribute; 17, 18; 17, 19; 18, identifier:six; 19, identifier:string_types; 20, block; 20, 21; 20, 25; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:_endpoint; 24, identifier:endpoint; 25, if_statement; 25, 26; 25, 29; 25, 35; 26, comparison_operator:in; 26, 27; 26, 28; 27, string:"/"; 28, identifier:endpoint; 29, block; 29, 30; 30, return_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:f_redirect; 33, argument_list; 33, 34; 34, identifier:endpoint; 35, else_clause; 35, 36; 36, block; 36, 37; 37, for_statement; 37, 38; 37, 39; 37, 48; 38, identifier:r; 39, call; 39, 40; 39, 47; 40, attribute; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:Mocha; 44, identifier:_app; 45, identifier:url_map; 46, identifier:iter_rules; 47, argument_list; 48, block; 48, 49; 48, 53; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:_endpoint; 52, identifier:endpoint; 53, if_statement; 53, 54; 53, 65; 54, boolean_operator:and; 54, 55; 54, 60; 55, comparison_operator:in; 55, 56; 55, 57; 56, string:'GET'; 57, attribute; 57, 58; 57, 59; 58, identifier:r; 59, identifier:methods; 60, comparison_operator:in; 60, 61; 60, 62; 61, identifier:endpoint; 62, attribute; 62, 63; 62, 64; 63, identifier:r; 64, identifier:endpoint; 65, block; 65, 66; 65, 72; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:_endpoint; 69, attribute; 69, 70; 69, 71; 70, identifier:r; 71, identifier:endpoint; 72, break_statement; 73, else_clause; 73, 74; 74, block; 74, 75; 74, 104; 75, if_statement; 75, 76; 75, 81; 76, call; 76, 77; 76, 78; 77, identifier:isinstance; 78, argument_list; 78, 79; 78, 80; 79, identifier:endpoint; 80, identifier:Mocha; 81, block; 81, 82; 81, 96; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:fn; 85, attribute; 85, 86; 85, 95; 86, attribute; 86, 87; 86, 94; 87, attribute; 87, 88; 87, 93; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:sys; 91, identifier:_getframe; 92, argument_list; 93, identifier:f_back; 94, identifier:f_code; 95, identifier:co_name; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:endpoint; 99, call; 99, 100; 99, 101; 100, identifier:getattr; 101, argument_list; 101, 102; 101, 103; 102, identifier:endpoint; 103, identifier:fn; 104, if_statement; 104, 105; 104, 109; 105, call; 105, 106; 105, 107; 106, identifier:is_method; 107, argument_list; 107, 108; 108, identifier:endpoint; 109, block; 109, 110; 109, 117; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:_endpoint; 113, call; 113, 114; 113, 115; 114, identifier:_get_action_endpoint; 115, argument_list; 115, 116; 116, identifier:endpoint; 117, if_statement; 117, 118; 117, 120; 118, not_operator; 118, 119; 119, identifier:_endpoint; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:_endpoint; 124, call; 124, 125; 124, 126; 125, identifier:_build_endpoint_route_name; 126, argument_list; 126, 127; 127, identifier:endpoint; 128, if_statement; 128, 129; 128, 130; 128, 141; 129, identifier:_endpoint; 130, block; 130, 131; 131, return_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:f_redirect; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:url_for; 137, argument_list; 137, 138; 137, 139; 138, identifier:_endpoint; 139, dictionary_splat; 139, 140; 140, identifier:kw; 141, else_clause; 141, 142; 142, block; 142, 143; 143, raise_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:exceptions; 147, identifier:MochaError; 148, argument_list; 148, 149; 149, string:"Invalid endpoint" | def redirect(endpoint, **kw):
_endpoint = None
if isinstance(endpoint, six.string_types):
_endpoint = endpoint
if "/" in endpoint:
return f_redirect(endpoint)
else:
for r in Mocha._app.url_map.iter_rules():
_endpoint = endpoint
if 'GET' in r.methods and endpoint in r.endpoint:
_endpoint = r.endpoint
break
else:
if isinstance(endpoint, Mocha):
fn = sys._getframe().f_back.f_code.co_name
endpoint = getattr(endpoint, fn)
if is_method(endpoint):
_endpoint = _get_action_endpoint(endpoint)
if not _endpoint:
_endpoint = _build_endpoint_route_name(endpoint)
if _endpoint:
return f_redirect(url_for(_endpoint, **kw))
else:
raise exceptions.MochaError("Invalid endpoint") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_search; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:query; 6, identifier:search_term; 7, block; 7, 8; 7, 16; 7, 24; 7, 33; 7, 80; 7, 329; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:criterias; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:mongoengine; 14, identifier:Q; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:rel_criterias; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:mongoengine; 22, identifier:Q; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:terms; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:shlex; 30, identifier:split; 31, argument_list; 31, 32; 32, identifier:search_term; 33, if_statement; 33, 34; 33, 50; 34, boolean_operator:and; 34, 35; 34, 41; 35, comparison_operator:==; 35, 36; 35, 40; 36, call; 36, 37; 36, 38; 37, identifier:len; 38, argument_list; 38, 39; 39, identifier:terms; 40, integer:1; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:re; 44, identifier:match; 45, argument_list; 45, 46; 45, 47; 46, identifier:RE_OBJECTID; 47, subscript; 47, 48; 47, 49; 48, identifier:terms; 49, integer:0; 50, block; 50, 51; 50, 69; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:q; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:query; 57, identifier:filter; 58, argument_list; 58, 59; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:id; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:bson; 64, identifier:ObjectId; 65, argument_list; 65, 66; 66, subscript; 66, 67; 66, 68; 67, identifier:terms; 68, integer:0; 69, if_statement; 69, 70; 69, 77; 70, comparison_operator:==; 70, 71; 70, 76; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:q; 74, identifier:count; 75, argument_list; 76, integer:1; 77, block; 77, 78; 78, return_statement; 78, 79; 79, identifier:q; 80, for_statement; 80, 81; 80, 82; 80, 83; 81, identifier:term; 82, identifier:terms; 83, block; 83, 84; 83, 93; 83, 102; 83, 110; 83, 325; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, pattern_list; 86, 87; 86, 88; 87, identifier:op; 88, identifier:term; 89, call; 89, 90; 89, 91; 90, identifier:parse_like_term; 91, argument_list; 91, 92; 92, identifier:term; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:==; 94, 95; 94, 96; 95, identifier:op; 96, string:'contains'; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:op; 101, string:'icontains'; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:criteria; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:mongoengine; 108, identifier:Q; 109, argument_list; 110, for_statement; 110, 111; 110, 112; 110, 115; 111, identifier:field; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:_search_fields; 115, block; 115, 116; 116, if_statement; 116, 117; 116, 126; 116, 206; 116, 296; 117, call; 117, 118; 117, 119; 118, identifier:isinstance; 119, argument_list; 119, 120; 119, 121; 120, identifier:field; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:mongoengine; 124, identifier:fields; 125, identifier:ReferenceField; 126, block; 126, 127; 126, 133; 126, 158; 126, 174; 126, 189; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:rel_model; 130, attribute; 130, 131; 130, 132; 131, identifier:field; 132, identifier:document_type; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:rel_fields; 136, parenthesized_expression; 136, 137; 137, call; 137, 138; 137, 154; 138, attribute; 138, 139; 138, 153; 139, call; 139, 140; 139, 148; 140, attribute; 140, 141; 140, 147; 141, call; 141, 142; 141, 143; 142, identifier:getattr; 143, argument_list; 143, 144; 143, 145; 143, 146; 144, identifier:self; 145, string:'column_searchable_refs'; 146, dictionary; 147, identifier:get; 148, argument_list; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:field; 151, identifier:name; 152, dictionary; 153, identifier:get; 154, argument_list; 154, 155; 154, 156; 155, string:'fields'; 156, list:['id']; 156, 157; 157, string:'id'; 158, if_statement; 158, 159; 158, 172; 159, boolean_operator:and; 159, 160; 159, 164; 160, comparison_operator:==; 160, 161; 160, 162; 161, identifier:rel_fields; 162, list:['id']; 162, 163; 163, string:'id'; 164, not_operator; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:re; 168, identifier:match; 169, argument_list; 169, 170; 169, 171; 170, identifier:RE_OBJECTID; 171, identifier:term; 172, block; 172, 173; 173, continue_statement; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:ids; 177, list_comprehension; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:o; 180, identifier:id; 181, for_in_clause; 181, 182; 181, 183; 182, identifier:o; 183, call; 183, 184; 183, 185; 184, identifier:search_relative_field; 185, argument_list; 185, 186; 185, 187; 185, 188; 186, identifier:rel_model; 187, identifier:rel_fields; 188, identifier:term; 189, expression_statement; 189, 190; 190, augmented_assignment:|=; 190, 191; 190, 192; 191, identifier:rel_criterias; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:mongoengine; 195, identifier:Q; 196, argument_list; 196, 197; 197, dictionary_splat; 197, 198; 198, dictionary; 198, 199; 199, pair; 199, 200; 199, 205; 200, binary_operator:%; 200, 201; 200, 202; 201, string:'%s__in'; 202, attribute; 202, 203; 202, 204; 203, identifier:field; 204, identifier:name; 205, identifier:ids; 206, elif_clause; 206, 207; 206, 216; 207, call; 207, 208; 207, 209; 208, identifier:isinstance; 209, argument_list; 209, 210; 209, 211; 210, identifier:field; 211, attribute; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:mongoengine; 214, identifier:fields; 215, identifier:ListField; 216, block; 216, 217; 216, 232; 216, 240; 216, 264; 216, 279; 217, if_statement; 217, 218; 217, 230; 218, not_operator; 218, 219; 219, call; 219, 220; 219, 221; 220, identifier:isinstance; 221, argument_list; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:field; 224, identifier:field; 225, attribute; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:mongoengine; 228, identifier:fields; 229, identifier:ReferenceField; 230, block; 230, 231; 231, continue_statement; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:rel_model; 235, attribute; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:field; 238, identifier:field; 239, identifier:document_type_obj; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:rel_fields; 243, parenthesized_expression; 243, 244; 244, call; 244, 245; 244, 261; 245, attribute; 245, 246; 245, 260; 246, call; 246, 247; 246, 255; 247, attribute; 247, 248; 247, 254; 248, call; 248, 249; 248, 250; 249, identifier:getattr; 250, argument_list; 250, 251; 250, 252; 250, 253; 251, identifier:self; 252, string:'column_searchable_refs'; 253, dictionary; 254, identifier:get; 255, argument_list; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:field; 258, identifier:name; 259, dictionary; 260, identifier:get; 261, argument_list; 261, 262; 261, 263; 262, string:'fields'; 263, string:'id'; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:ids; 267, list_comprehension; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:o; 270, identifier:id; 271, for_in_clause; 271, 272; 271, 273; 272, identifier:o; 273, call; 273, 274; 273, 275; 274, identifier:search_relative_field; 275, argument_list; 275, 276; 275, 277; 275, 278; 276, identifier:rel_model; 277, identifier:rel_fields; 278, identifier:term; 279, expression_statement; 279, 280; 280, augmented_assignment:|=; 280, 281; 280, 282; 281, identifier:rel_criterias; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:mongoengine; 285, identifier:Q; 286, argument_list; 286, 287; 287, dictionary_splat; 287, 288; 288, dictionary; 288, 289; 289, pair; 289, 290; 289, 295; 290, binary_operator:%; 290, 291; 290, 292; 291, string:'%s__in'; 292, attribute; 292, 293; 292, 294; 293, identifier:field; 294, identifier:name; 295, identifier:ids; 296, else_clause; 296, 297; 297, block; 297, 298; 297, 311; 297, 321; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:flt; 301, dictionary; 301, 302; 302, pair; 302, 303; 302, 310; 303, binary_operator:%; 303, 304; 303, 305; 304, string:'%s__%s'; 305, tuple; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:field; 308, identifier:name; 309, identifier:op; 310, identifier:term; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:q; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:mongoengine; 317, identifier:Q; 318, argument_list; 318, 319; 319, dictionary_splat; 319, 320; 320, identifier:flt; 321, expression_statement; 321, 322; 322, augmented_assignment:|=; 322, 323; 322, 324; 323, identifier:criteria; 324, identifier:q; 325, expression_statement; 325, 326; 326, augmented_assignment:&=; 326, 327; 326, 328; 327, identifier:criterias; 328, identifier:criteria; 329, return_statement; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:query; 333, identifier:filter; 334, argument_list; 334, 335; 335, binary_operator:|; 335, 336; 335, 337; 336, identifier:criterias; 337, identifier:rel_criterias | def _search(self, query, search_term):
criterias = mongoengine.Q()
rel_criterias = mongoengine.Q()
terms = shlex.split(search_term)
if len(terms) == 1 and re.match(RE_OBJECTID, terms[0]):
q = query.filter(id=bson.ObjectId(terms[0]))
if q.count() == 1:
return q
for term in terms:
op, term = parse_like_term(term)
if op == 'contains':
op = 'icontains'
criteria = mongoengine.Q()
for field in self._search_fields:
if isinstance(field, mongoengine.fields.ReferenceField):
rel_model = field.document_type
rel_fields = (
getattr(self, 'column_searchable_refs', {})
.get(field.name, {})
.get('fields', ['id'])
)
if rel_fields == ['id'] and not re.match(RE_OBJECTID, term):
continue
ids = [
o.id for o in search_relative_field(rel_model, rel_fields, term)
]
rel_criterias |= mongoengine.Q(**{'%s__in' % field.name: ids})
elif isinstance(field, mongoengine.fields.ListField):
if not isinstance(field.field, mongoengine.fields.ReferenceField):
continue
rel_model = field.field.document_type_obj
rel_fields = (
getattr(self, 'column_searchable_refs', {})
.get(field.name, {})
.get('fields', 'id')
)
ids = [
o.id for o in search_relative_field(rel_model, rel_fields, term)
]
rel_criterias |= mongoengine.Q(**{'%s__in' % field.name: ids})
else:
flt = {'%s__%s' % (field.name, op): term}
q = mongoengine.Q(**flt)
criteria |= q
criterias &= criteria
return query.filter(criterias | rel_criterias) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:replace_seqres; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:pdb; 6, default_parameter; 6, 7; 6, 8; 7, identifier:update_atoms; 8, True; 9, block; 9, 10; 9, 16; 9, 20; 9, 42; 9, 46; 9, 143; 9, 261; 9, 275; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:newpdb; 13, call; 13, 14; 13, 15; 14, identifier:PDB; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:inserted_seqres; 19, False; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:entries_before_seqres; 23, call; 23, 24; 23, 25; 24, identifier:set; 25, argument_list; 25, 26; 26, list:["HEADER", "OBSLTE", "TITLE", "CAVEAT", "COMPND", "SOURCE",
"KEYWDS", "EXPDTA", "AUTHOR", "REVDAT", "SPRSDE", "JRNL",
"REMARK", "DBREF", "SEQADV"]; 26, 27; 26, 28; 26, 29; 26, 30; 26, 31; 26, 32; 26, 33; 26, 34; 26, 35; 26, 36; 26, 37; 26, 38; 26, 39; 26, 40; 26, 41; 27, string:"HEADER"; 28, string:"OBSLTE"; 29, string:"TITLE"; 30, string:"CAVEAT"; 31, string:"COMPND"; 32, string:"SOURCE"; 33, string:"KEYWDS"; 34, string:"EXPDTA"; 35, string:"AUTHOR"; 36, string:"REVDAT"; 37, string:"SPRSDE"; 38, string:"JRNL"; 39, string:"REMARK"; 40, string:"DBREF"; 41, string:"SEQADV"; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:mutated_resids; 45, dictionary; 46, if_statement; 46, 47; 46, 48; 47, identifier:update_atoms; 48, block; 48, 49; 48, 55; 48, 64; 48, 76; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:old_seqs; 52, call; 52, 53; 52, 54; 53, identifier:ChainSequences; 54, argument_list; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:chainresnums; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:old_seqs; 61, identifier:parse_atoms; 62, argument_list; 62, 63; 63, identifier:pdb; 64, assert_statement; 64, 65; 65, comparison_operator:==; 65, 66; 65, 71; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:keys; 70, argument_list; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:old_seqs; 74, identifier:keys; 75, argument_list; 76, for_statement; 76, 77; 76, 78; 76, 83; 77, identifier:chain; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:keys; 82, argument_list; 83, block; 83, 84; 83, 98; 84, assert_statement; 84, 85; 85, comparison_operator:==; 85, 86; 85, 92; 86, call; 86, 87; 86, 88; 87, identifier:len; 88, argument_list; 88, 89; 89, subscript; 89, 90; 89, 91; 90, identifier:self; 91, identifier:chain; 92, call; 92, 93; 92, 94; 93, identifier:len; 94, argument_list; 94, 95; 95, subscript; 95, 96; 95, 97; 96, identifier:old_seqs; 97, identifier:chain; 98, for_statement; 98, 99; 98, 100; 98, 109; 99, identifier:i; 100, call; 100, 101; 100, 102; 101, identifier:xrange; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:len; 105, argument_list; 105, 106; 106, subscript; 106, 107; 106, 108; 107, identifier:self; 108, identifier:chain; 109, block; 109, 110; 110, if_statement; 110, 111; 110, 122; 111, comparison_operator:!=; 111, 112; 111, 117; 112, subscript; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:self; 115, identifier:chain; 116, identifier:i; 117, subscript; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:old_seqs; 120, identifier:chain; 121, identifier:i; 122, block; 122, 123; 122, 133; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:resid; 126, binary_operator:+; 126, 127; 126, 128; 127, identifier:chain; 128, subscript; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:chainresnums; 131, identifier:chain; 132, identifier:i; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:mutated_resids; 137, identifier:resid; 138, subscript; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:self; 141, identifier:chain; 142, identifier:i; 143, for_statement; 143, 144; 143, 145; 143, 148; 144, identifier:line; 145, attribute; 145, 146; 145, 147; 146, identifier:pdb; 147, identifier:lines; 148, block; 148, 149; 148, 158; 148, 181; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:entry; 152, subscript; 152, 153; 152, 154; 153, identifier:line; 154, slice; 154, 155; 154, 156; 154, 157; 155, integer:0; 156, colon; 157, integer:6; 158, if_statement; 158, 159; 158, 166; 159, boolean_operator:and; 159, 160; 159, 163; 160, parenthesized_expression; 160, 161; 161, not_operator; 161, 162; 162, identifier:inserted_seqres; 163, comparison_operator:not; 163, 164; 163, 165; 164, identifier:entry; 165, identifier:entries_before_seqres; 166, block; 166, 167; 166, 171; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:inserted_seqres; 170, True; 171, expression_statement; 171, 172; 172, augmented_assignment:+=; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:newpdb; 175, identifier:lines; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:seqres_lines; 180, argument_list; 181, if_statement; 181, 182; 181, 187; 181, 249; 182, boolean_operator:and; 182, 183; 182, 184; 183, identifier:update_atoms; 184, comparison_operator:==; 184, 185; 184, 186; 185, identifier:entry; 186, string:"ATOM "; 187, block; 187, 188; 187, 197; 187, 210; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:resid; 191, subscript; 191, 192; 191, 193; 192, identifier:line; 193, slice; 193, 194; 193, 195; 193, 196; 194, integer:21; 195, colon; 196, integer:27; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:atom; 200, call; 200, 201; 200, 209; 201, attribute; 201, 202; 201, 208; 202, subscript; 202, 203; 202, 204; 203, identifier:line; 204, slice; 204, 205; 204, 206; 204, 207; 205, integer:12; 206, colon; 207, integer:16; 208, identifier:strip; 209, argument_list; 210, if_statement; 210, 211; 210, 218; 210, 226; 211, not_operator; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:mutated_resids; 215, identifier:has_key; 216, argument_list; 216, 217; 217, identifier:resid; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, augmented_assignment:+=; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:newpdb; 223, identifier:lines; 224, list:[line]; 224, 225; 225, identifier:line; 226, else_clause; 226, 227; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, augmented_assignment:+=; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:newpdb; 232, identifier:lines; 233, list:[line[:17] + mutated_resids[resid] + line[20:]]; 233, 234; 234, binary_operator:+; 234, 235; 234, 244; 235, binary_operator:+; 235, 236; 235, 241; 236, subscript; 236, 237; 236, 238; 237, identifier:line; 238, slice; 238, 239; 238, 240; 239, colon; 240, integer:17; 241, subscript; 241, 242; 241, 243; 242, identifier:mutated_resids; 243, identifier:resid; 244, subscript; 244, 245; 244, 246; 245, identifier:line; 246, slice; 246, 247; 246, 248; 247, integer:20; 248, colon; 249, elif_clause; 249, 250; 249, 253; 250, comparison_operator:!=; 250, 251; 250, 252; 251, identifier:entry; 252, string:"SEQRES"; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, augmented_assignment:+=; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:newpdb; 258, identifier:lines; 259, list:[line]; 259, 260; 260, identifier:line; 261, if_statement; 261, 262; 261, 263; 262, identifier:update_atoms; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:newpdb; 268, identifier:remove_nonbackbone_atoms; 269, argument_list; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:mutated_resids; 273, identifier:keys; 274, argument_list; 275, return_statement; 275, 276; 276, identifier:newpdb | def replace_seqres(self, pdb, update_atoms = True):
newpdb = PDB()
inserted_seqres = False
entries_before_seqres = set(["HEADER", "OBSLTE", "TITLE", "CAVEAT", "COMPND", "SOURCE",
"KEYWDS", "EXPDTA", "AUTHOR", "REVDAT", "SPRSDE", "JRNL",
"REMARK", "DBREF", "SEQADV"])
mutated_resids = {}
if update_atoms:
old_seqs = ChainSequences()
chainresnums = old_seqs.parse_atoms(pdb)
assert self.keys() == old_seqs.keys()
for chain in self.keys():
assert len(self[chain]) == len(old_seqs[chain])
for i in xrange(len(self[chain])):
if self[chain][i] != old_seqs[chain][i]:
resid = chain + chainresnums[chain][i]
mutated_resids[resid] = self[chain][i]
for line in pdb.lines:
entry = line[0:6]
if (not inserted_seqres) and entry not in entries_before_seqres:
inserted_seqres = True
newpdb.lines += self.seqres_lines()
if update_atoms and entry == "ATOM ":
resid = line[21:27]
atom = line[12:16].strip()
if not mutated_resids.has_key(resid):
newpdb.lines += [line]
else:
newpdb.lines += [line[:17] + mutated_resids[resid] + line[20:]]
elif entry != "SEQRES":
newpdb.lines += [line]
if update_atoms:
newpdb.remove_nonbackbone_atoms(mutated_resids.keys())
return newpdb |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:enrich_json_objects_by_object_type; 3, parameters; 3, 4; 3, 5; 4, identifier:request; 5, identifier:value; 6, block; 6, 7; 6, 13; 6, 62; 6, 74; 6, 212; 6, 228; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:time_start_globally; 10, call; 10, 11; 10, 12; 11, identifier:time; 12, argument_list; 13, if_statement; 13, 14; 13, 19; 13, 39; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:value; 18, identifier:list; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:json; 23, list_comprehension; 23, 24; 23, 36; 24, conditional_expression:if; 24, 25; 24, 30; 24, 35; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:x; 28, identifier:to_json; 29, argument_list; 30, call; 30, 31; 30, 32; 31, identifier:hasattr; 32, argument_list; 32, 33; 32, 34; 33, identifier:x; 34, string:"to_json"; 35, identifier:x; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:x; 38, identifier:value; 39, else_clause; 39, 40; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 47; 41, 52; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 46; 45, identifier:value; 46, identifier:dict; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:json; 51, identifier:value; 52, else_clause; 52, 53; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:json; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:value; 60, identifier:to_json; 61, argument_list; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, pattern_list; 64, 65; 64, 66; 65, identifier:objects; 66, identifier:nested; 67, call; 67, 68; 67, 69; 68, identifier:_collect_json_objects; 69, argument_list; 69, 70; 69, 71; 70, identifier:json; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:by; 73, string:'object_type'; 74, for_statement; 74, 75; 74, 76; 74, 79; 75, identifier:enricher_info; 76, call; 76, 77; 76, 78; 77, identifier:_get_OBJECT_TYPE_ENRICHER_ORDER; 78, argument_list; 79, block; 79, 80; 79, 152; 80, if_statement; 80, 81; 80, 89; 80, 128; 81, comparison_operator:>; 81, 82; 81, 88; 82, call; 82, 83; 82, 84; 83, identifier:len; 84, argument_list; 84, 85; 85, subscript; 85, 86; 85, 87; 86, identifier:enricher_info; 87, string:'object_types'; 88, integer:0; 89, block; 89, 90; 89, 109; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:enricher_objects; 93, call; 93, 94; 93, 95; 94, identifier:flatten; 95, argument_list; 95, 96; 96, list_comprehension; 96, 97; 96, 104; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:objects; 100, identifier:get; 101, argument_list; 101, 102; 101, 103; 102, identifier:object_type; 103, list:[]; 104, for_in_clause; 104, 105; 104, 106; 105, identifier:object_type; 106, subscript; 106, 107; 106, 108; 107, identifier:enricher_info; 108, string:'object_types'; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:enricher_nested; 112, call; 112, 113; 112, 114; 113, identifier:any; 114, argument_list; 114, 115; 115, list_comprehension; 115, 116; 115, 123; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:nested; 119, identifier:get; 120, argument_list; 120, 121; 120, 122; 121, identifier:object_type; 122, False; 123, for_in_clause; 123, 124; 123, 125; 124, identifier:object_type; 125, subscript; 125, 126; 125, 127; 126, identifier:enricher_info; 127, string:'object_types'; 128, else_clause; 128, 129; 129, block; 129, 130; 129, 141; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:enricher_objects; 133, call; 133, 134; 133, 135; 134, identifier:flatten; 135, argument_list; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:objects; 139, identifier:values; 140, argument_list; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:enricher_nested; 144, call; 144, 145; 144, 146; 145, identifier:any; 146, argument_list; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:nested; 150, identifier:values; 151, argument_list; 152, if_statement; 152, 153; 152, 159; 153, comparison_operator:>; 153, 154; 153, 158; 154, call; 154, 155; 154, 156; 155, identifier:len; 156, argument_list; 156, 157; 157, identifier:enricher_objects; 158, integer:0; 159, block; 159, 160; 159, 166; 159, 175; 159, 194; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:time_start; 163, call; 163, 164; 163, 165; 164, identifier:time; 165, argument_list; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:enricher_info; 170, string:'enricher'; 171, argument_list; 171, 172; 171, 173; 171, 174; 172, identifier:request; 173, identifier:enricher_objects; 174, identifier:enricher_nested; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:LOGGER; 179, identifier:debug; 180, argument_list; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, string:'enrichment "{}" took {} seconds'; 184, identifier:format; 185, argument_list; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:enricher_info; 188, string:'enricher_name'; 189, binary_operator:-; 189, 190; 189, 193; 190, call; 190, 191; 190, 192; 191, identifier:time; 192, argument_list; 193, identifier:time_start; 194, if_statement; 194, 195; 194, 199; 195, not_operator; 195, 196; 196, subscript; 196, 197; 196, 198; 197, identifier:enricher_info; 198, string:'pure'; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 205; 202, pattern_list; 202, 203; 202, 204; 203, identifier:objects; 204, identifier:nested; 205, call; 205, 206; 205, 207; 206, identifier:_collect_json_objects; 207, argument_list; 207, 208; 207, 209; 208, identifier:json; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:by; 211, string:'object_type'; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:LOGGER; 216, identifier:debug; 217, argument_list; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, string:'The whole enrichment of json objects by their object_type took {} seconds.'; 221, identifier:format; 222, argument_list; 222, 223; 223, binary_operator:-; 223, 224; 223, 227; 224, call; 224, 225; 224, 226; 225, identifier:time; 226, argument_list; 227, identifier:time_start_globally; 228, return_statement; 228, 229; 229, identifier:json | def enrich_json_objects_by_object_type(request, value):
time_start_globally = time()
if isinstance(value, list):
json = [x.to_json() if hasattr(x, "to_json") else x for x in value]
else:
if isinstance(value, dict):
json = value
else:
json = value.to_json()
objects, nested = _collect_json_objects(json, by='object_type')
for enricher_info in _get_OBJECT_TYPE_ENRICHER_ORDER():
if len(enricher_info['object_types']) > 0:
enricher_objects = flatten([objects.get(object_type, []) for object_type in enricher_info['object_types']])
enricher_nested = any([nested.get(object_type, False) for object_type in enricher_info['object_types']])
else:
enricher_objects = flatten(objects.values())
enricher_nested = any(nested.values())
if len(enricher_objects) > 0:
time_start = time()
enricher_info['enricher'](request, enricher_objects, enricher_nested)
LOGGER.debug('enrichment "{}" took {} seconds'.format(enricher_info['enricher_name'], time() - time_start))
if not enricher_info['pure']:
objects, nested = _collect_json_objects(json, by='object_type')
LOGGER.debug('The whole enrichment of json objects by their object_type took {} seconds.'.format(time() - time_start_globally))
return json |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:change_parent; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:sender; 5, identifier:instance; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 17; 8, 131; 8, 258; 9, if_statement; 9, 10; 9, 15; 10, comparison_operator:is; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:instance; 13, identifier:id; 14, None; 15, block; 15, 16; 16, return_statement; 17, if_statement; 17, 18; 17, 33; 18, comparison_operator:!=; 18, 19; 18, 32; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, binary_operator:&; 22, 23; 22, 26; 23, set; 23, 24; 23, 25; 24, string:'term'; 25, string:'term_id'; 26, call; 26, 27; 26, 28; 27, identifier:set; 28, argument_list; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:instance; 31, identifier:changed_fields; 32, integer:0; 33, block; 33, 34; 33, 40; 33, 57; 33, 63; 33, 110; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:diff; 37, attribute; 37, 38; 37, 39; 38, identifier:instance; 39, identifier:diff; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:parent; 43, conditional_expression:if; 43, 44; 43, 49; 43, 52; 44, subscript; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:diff; 47, string:'term'; 48, integer:0; 49, comparison_operator:in; 49, 50; 49, 51; 50, string:'term'; 51, identifier:diff; 52, subscript; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:diff; 55, string:'term_id'; 56, integer:0; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:child_id; 60, attribute; 60, 61; 60, 62; 61, identifier:instance; 62, identifier:item_id; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:parent; 66, None; 67, block; 67, 68; 67, 92; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:parent_id; 71, conditional_expression:if; 71, 72; 71, 75; 71, 80; 72, attribute; 72, 73; 72, 74; 73, identifier:parent; 74, identifier:item_id; 75, call; 75, 76; 75, 77; 76, identifier:isinstance; 77, argument_list; 77, 78; 77, 79; 78, identifier:parent; 79, identifier:Term; 80, attribute; 80, 81; 80, 91; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:Term; 85, identifier:objects; 86, identifier:get; 87, argument_list; 87, 88; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:pk; 90, identifier:parent; 91, identifier:item_id; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 109; 94, attribute; 94, 95; 94, 108; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:ItemRelation; 99, identifier:objects; 100, identifier:filter; 101, argument_list; 101, 102; 101, 105; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:parent_id; 104, identifier:parent_id; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:child_id; 107, identifier:child_id; 108, identifier:delete; 109, argument_list; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:ItemRelation; 115, identifier:objects; 116, identifier:get_or_create; 117, argument_list; 117, 118; 117, 125; 117, 128; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:parent_id; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:instance; 123, identifier:term; 124, identifier:item_id; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:child_id; 127, identifier:child_id; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:visible; 130, True; 131, if_statement; 131, 132; 131, 147; 132, comparison_operator:!=; 132, 133; 132, 146; 133, call; 133, 134; 133, 135; 134, identifier:len; 135, argument_list; 135, 136; 136, binary_operator:&; 136, 137; 136, 140; 137, set; 137, 138; 137, 139; 138, string:'term_secondary'; 139, string:'term_secondary_id'; 140, call; 140, 141; 140, 142; 141, identifier:set; 142, argument_list; 142, 143; 143, attribute; 143, 144; 143, 145; 144, identifier:instance; 145, identifier:changed_fields; 146, integer:0; 147, block; 147, 148; 147, 154; 147, 160; 147, 177; 147, 224; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:diff; 151, attribute; 151, 152; 151, 153; 152, identifier:instance; 153, identifier:diff; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:child_id; 157, attribute; 157, 158; 157, 159; 158, identifier:instance; 159, identifier:item_id; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:parent; 163, conditional_expression:if; 163, 164; 163, 169; 163, 172; 164, subscript; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:diff; 167, string:'term_secondary'; 168, integer:0; 169, comparison_operator:in; 169, 170; 169, 171; 170, string:'term_secondary'; 171, identifier:diff; 172, subscript; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:diff; 175, string:'term_secondary_id'; 176, integer:0; 177, if_statement; 177, 178; 177, 181; 178, comparison_operator:is; 178, 179; 178, 180; 179, identifier:parent; 180, None; 181, block; 181, 182; 181, 206; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:parent_id; 185, conditional_expression:if; 185, 186; 185, 189; 185, 194; 186, attribute; 186, 187; 186, 188; 187, identifier:parent; 188, identifier:item_id; 189, call; 189, 190; 189, 191; 190, identifier:isinstance; 191, argument_list; 191, 192; 191, 193; 192, identifier:parent; 193, identifier:Term; 194, attribute; 194, 195; 194, 205; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:Term; 199, identifier:objects; 200, identifier:get; 201, argument_list; 201, 202; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:pk; 204, identifier:parent; 205, identifier:item_id; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 223; 208, attribute; 208, 209; 208, 222; 209, call; 209, 210; 209, 215; 210, attribute; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:ItemRelation; 213, identifier:objects; 214, identifier:filter; 215, argument_list; 215, 216; 215, 219; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:parent_id; 218, identifier:parent_id; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:child_id; 221, identifier:child_id; 222, identifier:delete; 223, argument_list; 224, if_statement; 224, 225; 224, 236; 225, boolean_operator:or; 225, 226; 225, 231; 226, comparison_operator:is; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:instance; 229, identifier:term_secondary; 230, None; 231, comparison_operator:is; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:instance; 234, identifier:term_secondary_id; 235, None; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 244; 239, attribute; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:ItemRelation; 242, identifier:objects; 243, identifier:get_or_create; 244, argument_list; 244, 245; 244, 252; 244, 255; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:parent_id; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:instance; 250, identifier:term_secondary; 251, identifier:item_id; 252, keyword_argument; 252, 253; 252, 254; 253, identifier:child_id; 254, identifier:child_id; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:visible; 257, True; 258, if_statement; 258, 259; 258, 274; 259, comparison_operator:!=; 259, 260; 259, 273; 260, call; 260, 261; 260, 262; 261, identifier:len; 262, argument_list; 262, 263; 263, binary_operator:&; 263, 264; 263, 267; 264, set; 264, 265; 264, 266; 265, string:'context'; 266, string:'context_id'; 267, call; 267, 268; 267, 269; 268, identifier:set; 269, argument_list; 269, 270; 270, attribute; 270, 271; 270, 272; 271, identifier:instance; 272, identifier:changed_fields; 273, integer:0; 274, block; 274, 275; 274, 281; 274, 298; 274, 304; 274, 351; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:diff; 278, attribute; 278, 279; 278, 280; 279, identifier:instance; 280, identifier:diff; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:parent; 284, conditional_expression:if; 284, 285; 284, 290; 284, 293; 285, subscript; 285, 286; 285, 289; 286, subscript; 286, 287; 286, 288; 287, identifier:diff; 288, string:'context'; 289, integer:0; 290, comparison_operator:in; 290, 291; 290, 292; 291, string:'context'; 292, identifier:diff; 293, subscript; 293, 294; 293, 297; 294, subscript; 294, 295; 294, 296; 295, identifier:diff; 296, string:'context_id'; 297, integer:0; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:child_id; 301, attribute; 301, 302; 301, 303; 302, identifier:instance; 303, identifier:item_id; 304, if_statement; 304, 305; 304, 308; 305, comparison_operator:is; 305, 306; 305, 307; 306, identifier:parent; 307, None; 308, block; 308, 309; 308, 333; 309, expression_statement; 309, 310; 310, assignment; 310, 311; 310, 312; 311, identifier:parent_id; 312, conditional_expression:if; 312, 313; 312, 316; 312, 321; 313, attribute; 313, 314; 313, 315; 314, identifier:parent; 315, identifier:item_id; 316, call; 316, 317; 316, 318; 317, identifier:isinstance; 318, argument_list; 318, 319; 318, 320; 319, identifier:parent; 320, identifier:Context; 321, attribute; 321, 322; 321, 332; 322, call; 322, 323; 322, 328; 323, attribute; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:Context; 326, identifier:objects; 327, identifier:get; 328, argument_list; 328, 329; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:pk; 331, identifier:parent; 332, identifier:item_id; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 350; 335, attribute; 335, 336; 335, 349; 336, call; 336, 337; 336, 342; 337, attribute; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:ItemRelation; 340, identifier:objects; 341, identifier:filter; 342, argument_list; 342, 343; 342, 346; 343, keyword_argument; 343, 344; 343, 345; 344, identifier:parent_id; 345, identifier:parent_id; 346, keyword_argument; 346, 347; 346, 348; 347, identifier:child_id; 348, identifier:child_id; 349, identifier:delete; 350, argument_list; 351, expression_statement; 351, 352; 352, call; 352, 353; 352, 358; 353, attribute; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:ItemRelation; 356, identifier:objects; 357, identifier:get_or_create; 358, argument_list; 358, 359; 358, 366; 358, 369; 359, keyword_argument; 359, 360; 359, 361; 360, identifier:parent_id; 361, attribute; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:instance; 364, identifier:context; 365, identifier:item_id; 366, keyword_argument; 366, 367; 366, 368; 367, identifier:child_id; 368, identifier:child_id; 369, keyword_argument; 369, 370; 369, 371; 370, identifier:visible; 371, True | def change_parent(sender, instance, **kwargs):
if instance.id is None:
return
if len({'term', 'term_id'} & set(instance.changed_fields)) != 0:
diff = instance.diff
parent = diff['term'][0] if 'term' in diff else diff['term_id'][0]
child_id = instance.item_id
if parent is not None:
parent_id = parent.item_id if isinstance(parent, Term) else Term.objects.get(pk=parent).item_id
ItemRelation.objects.filter(parent_id=parent_id, child_id=child_id).delete()
ItemRelation.objects.get_or_create(parent_id=instance.term.item_id, child_id=child_id, visible=True)
if len({'term_secondary', 'term_secondary_id'} & set(instance.changed_fields)) != 0:
diff = instance.diff
child_id = instance.item_id
parent = diff['term_secondary'][0] if 'term_secondary' in diff else diff['term_secondary_id'][0]
if parent is not None:
parent_id = parent.item_id if isinstance(parent, Term) else Term.objects.get(pk=parent).item_id
ItemRelation.objects.filter(parent_id=parent_id, child_id=child_id).delete()
if instance.term_secondary is not None or instance.term_secondary_id is not None:
ItemRelation.objects.get_or_create(parent_id=instance.term_secondary.item_id, child_id=child_id, visible=True)
if len({'context', 'context_id'} & set(instance.changed_fields)) != 0:
diff = instance.diff
parent = diff['context'][0] if 'context' in diff else diff['context_id'][0]
child_id = instance.item_id
if parent is not None:
parent_id = parent.item_id if isinstance(parent, Context) else Context.objects.get(pk=parent).item_id
ItemRelation.objects.filter(parent_id=parent_id, child_id=child_id).delete()
ItemRelation.objects.get_or_create(parent_id=instance.context.item_id, child_id=child_id, visible=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:bin_atoms; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 26; 5, 44; 5, 60; 5, 90; 5, 94; 5, 162; 5, 231; 5, 299; 5, 303; 5, 359; 6, expression_statement; 6, 7; 7, string:'''This function bins the Atoms into fixed-size sections of the protein space in 3D.'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:low_point; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:numpy; 14, identifier:array; 15, argument_list; 15, 16; 16, list:[self.min_x, self.min_y, self.min_z]; 16, 17; 16, 20; 16, 23; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:min_x; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:min_y; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:min_z; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:high_point; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:numpy; 32, identifier:array; 33, argument_list; 33, 34; 34, list:[self.max_x, self.max_y, self.max_z]; 34, 35; 34, 38; 34, 41; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:max_x; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:max_y; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:max_z; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:atom_bin_dimensions; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:numpy; 50, identifier:ceil; 51, argument_list; 51, 52; 52, binary_operator:/; 52, 53; 52, 57; 53, parenthesized_expression; 53, 54; 54, binary_operator:-; 54, 55; 54, 56; 55, identifier:high_point; 56, identifier:low_point; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:bin_size; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:atom_bin_dimensions; 65, tuple; 65, 66; 65, 74; 65, 82; 66, binary_operator:-; 66, 67; 66, 73; 67, call; 67, 68; 67, 69; 68, identifier:int; 69, argument_list; 69, 70; 70, subscript; 70, 71; 70, 72; 71, identifier:atom_bin_dimensions; 72, integer:0; 73, integer:1; 74, binary_operator:-; 74, 75; 74, 81; 75, call; 75, 76; 75, 77; 76, identifier:int; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 80; 79, identifier:atom_bin_dimensions; 80, integer:1; 81, integer:1; 82, binary_operator:-; 82, 83; 82, 89; 83, call; 83, 84; 83, 85; 84, identifier:int; 85, argument_list; 85, 86; 86, subscript; 86, 87; 86, 88; 87, identifier:atom_bin_dimensions; 88, integer:2; 89, integer:1; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:atom_bins; 93, list:[]; 94, for_statement; 94, 95; 94, 96; 94, 105; 95, identifier:x; 96, call; 96, 97; 96, 98; 97, identifier:range; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:int; 101, argument_list; 101, 102; 102, subscript; 102, 103; 102, 104; 103, identifier:atom_bin_dimensions; 104, integer:0; 105, block; 105, 106; 105, 113; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:atom_bins; 110, identifier:append; 111, argument_list; 111, 112; 112, list:[]; 113, for_statement; 113, 114; 113, 115; 113, 124; 114, identifier:y; 115, call; 115, 116; 115, 117; 116, identifier:range; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:int; 120, argument_list; 120, 121; 121, subscript; 121, 122; 121, 123; 122, identifier:atom_bin_dimensions; 123, integer:1; 124, block; 124, 125; 124, 134; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:atom_bins; 130, identifier:x; 131, identifier:append; 132, argument_list; 132, 133; 133, list:[]; 134, for_statement; 134, 135; 134, 136; 134, 145; 135, identifier:z; 136, call; 136, 137; 136, 138; 137, identifier:range; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:int; 141, argument_list; 141, 142; 142, subscript; 142, 143; 142, 144; 143, identifier:atom_bin_dimensions; 144, integer:2; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 155; 148, attribute; 148, 149; 148, 154; 149, subscript; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:atom_bins; 152, identifier:x; 153, identifier:y; 154, identifier:append; 155, argument_list; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:Bin; 158, argument_list; 158, 159; 158, 160; 158, 161; 159, identifier:x; 160, identifier:y; 161, identifier:z; 162, for_statement; 162, 163; 162, 166; 162, 173; 163, pattern_list; 163, 164; 163, 165; 164, identifier:serial_number; 165, identifier:atom; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:atoms; 171, identifier:iteritems; 172, argument_list; 173, block; 173, 174; 173, 192; 173, 217; 173, 224; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:bin_location; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:numpy; 180, identifier:trunc; 181, argument_list; 181, 182; 182, binary_operator:/; 182, 183; 182, 189; 183, parenthesized_expression; 183, 184; 184, binary_operator:-; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:atom; 187, identifier:point; 188, identifier:low_point; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:bin_size; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:bin; 195, subscript; 195, 196; 195, 211; 196, subscript; 196, 197; 196, 205; 197, subscript; 197, 198; 197, 199; 198, identifier:atom_bins; 199, call; 199, 200; 199, 201; 200, identifier:int; 201, argument_list; 201, 202; 202, subscript; 202, 203; 202, 204; 203, identifier:bin_location; 204, integer:0; 205, call; 205, 206; 205, 207; 206, identifier:int; 207, argument_list; 207, 208; 208, subscript; 208, 209; 208, 210; 209, identifier:bin_location; 210, integer:1; 211, call; 211, 212; 211, 213; 212, identifier:int; 213, argument_list; 213, 214; 214, subscript; 214, 215; 214, 216; 215, identifier:bin_location; 216, integer:2; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:bin; 221, identifier:append; 222, argument_list; 222, 223; 223, identifier:atom; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:atom; 228, identifier:set_bin; 229, argument_list; 229, 230; 230, identifier:bin; 231, if_statement; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:self; 234, identifier:safe_mode; 235, block; 235, 236; 235, 240; 235, 289; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:num_atoms; 239, integer:0; 240, for_statement; 240, 241; 240, 242; 240, 251; 241, identifier:x; 242, call; 242, 243; 242, 244; 243, identifier:range; 244, argument_list; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:int; 247, argument_list; 247, 248; 248, subscript; 248, 249; 248, 250; 249, identifier:atom_bin_dimensions; 250, integer:0; 251, block; 251, 252; 252, for_statement; 252, 253; 252, 254; 252, 263; 253, identifier:y; 254, call; 254, 255; 254, 256; 255, identifier:range; 256, argument_list; 256, 257; 257, call; 257, 258; 257, 259; 258, identifier:int; 259, argument_list; 259, 260; 260, subscript; 260, 261; 260, 262; 261, identifier:atom_bin_dimensions; 262, integer:1; 263, block; 263, 264; 264, for_statement; 264, 265; 264, 266; 264, 275; 265, identifier:z; 266, call; 266, 267; 266, 268; 267, identifier:range; 268, argument_list; 268, 269; 269, call; 269, 270; 269, 271; 270, identifier:int; 271, argument_list; 271, 272; 272, subscript; 272, 273; 272, 274; 273, identifier:atom_bin_dimensions; 274, integer:2; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, augmented_assignment:+=; 277, 278; 277, 279; 278, identifier:num_atoms; 279, call; 279, 280; 279, 281; 280, identifier:len; 281, argument_list; 281, 282; 282, subscript; 282, 283; 282, 288; 283, subscript; 283, 284; 283, 287; 284, subscript; 284, 285; 284, 286; 285, identifier:atom_bins; 286, identifier:x; 287, identifier:y; 288, identifier:z; 289, assert_statement; 289, 290; 290, parenthesized_expression; 290, 291; 291, comparison_operator:==; 291, 292; 291, 293; 292, identifier:num_atoms; 293, call; 293, 294; 293, 295; 294, identifier:len; 295, argument_list; 295, 296; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:atoms; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:blank_section; 302, tuple; 303, for_statement; 303, 304; 303, 305; 303, 314; 304, identifier:x; 305, call; 305, 306; 305, 307; 306, identifier:range; 307, argument_list; 307, 308; 308, call; 308, 309; 308, 310; 309, identifier:int; 310, argument_list; 310, 311; 311, subscript; 311, 312; 311, 313; 312, identifier:atom_bin_dimensions; 313, integer:0; 314, block; 314, 315; 315, for_statement; 315, 316; 315, 317; 315, 326; 316, identifier:y; 317, call; 317, 318; 317, 319; 318, identifier:range; 319, argument_list; 319, 320; 320, call; 320, 321; 320, 322; 321, identifier:int; 322, argument_list; 322, 323; 323, subscript; 323, 324; 323, 325; 324, identifier:atom_bin_dimensions; 325, integer:1; 326, block; 326, 327; 327, for_statement; 327, 328; 327, 329; 327, 338; 328, identifier:z; 329, call; 329, 330; 329, 331; 330, identifier:range; 331, argument_list; 331, 332; 332, call; 332, 333; 332, 334; 333, identifier:int; 334, argument_list; 334, 335; 335, subscript; 335, 336; 335, 337; 336, identifier:atom_bin_dimensions; 337, integer:2; 338, block; 338, 339; 339, if_statement; 339, 340; 339, 348; 340, not_operator; 340, 341; 341, subscript; 341, 342; 341, 347; 342, subscript; 342, 343; 342, 346; 343, subscript; 343, 344; 343, 345; 344, identifier:atom_bins; 345, identifier:x; 346, identifier:y; 347, identifier:z; 348, block; 348, 349; 349, expression_statement; 349, 350; 350, assignment; 350, 351; 350, 358; 351, subscript; 351, 352; 351, 357; 352, subscript; 352, 353; 352, 356; 353, subscript; 353, 354; 353, 355; 354, identifier:atom_bins; 355, identifier:x; 356, identifier:y; 357, identifier:z; 358, identifier:blank_section; 359, expression_statement; 359, 360; 360, assignment; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:self; 363, identifier:atom_bins; 364, identifier:atom_bins | def bin_atoms(self):
'''This function bins the Atoms into fixed-size sections of the protein space in 3D.'''
low_point = numpy.array([self.min_x, self.min_y, self.min_z])
high_point = numpy.array([self.max_x, self.max_y, self.max_z])
atom_bin_dimensions = numpy.ceil((high_point - low_point) / self.bin_size)
self.atom_bin_dimensions = (int(atom_bin_dimensions[0]) - 1, int(atom_bin_dimensions[1]) - 1, int(atom_bin_dimensions[2]) - 1)
atom_bins = []
for x in range(int(atom_bin_dimensions[0])):
atom_bins.append([])
for y in range(int(atom_bin_dimensions[1])):
atom_bins[x].append([])
for z in range(int(atom_bin_dimensions[2])):
atom_bins[x][y].append(Bin(x, y, z))
for serial_number, atom in self.atoms.iteritems():
bin_location = numpy.trunc((atom.point - low_point) / self.bin_size)
bin = atom_bins[int(bin_location[0])][int(bin_location[1])][int(bin_location[2])]
bin.append(atom)
atom.set_bin(bin)
if self.safe_mode:
num_atoms = 0
for x in range(int(atom_bin_dimensions[0])):
for y in range(int(atom_bin_dimensions[1])):
for z in range(int(atom_bin_dimensions[2])):
num_atoms += len(atom_bins[x][y][z])
assert(num_atoms == len(self.atoms))
blank_section = ()
for x in range(int(atom_bin_dimensions[0])):
for y in range(int(atom_bin_dimensions[1])):
for z in range(int(atom_bin_dimensions[2])):
if not atom_bins[x][y][z]:
atom_bins[x][y][z] = blank_section
self.atom_bins = atom_bins |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:attr_name; 6, list_splat_pattern; 6, 7; 7, identifier:args; 8, block; 8, 9; 8, 24; 8, 39; 8, 43; 8, 52; 8, 109; 9, if_statement; 9, 10; 9, 18; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:attr_name; 15, attribute; 15, 16; 15, 17; 16, identifier:six; 17, identifier:string_types; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:TypeError; 22, argument_list; 22, 23; 23, string:'attr_name must be a str.'; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:in; 25, 26; 25, 27; 26, string:'-'; 27, identifier:attr_name; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:attr_name; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:attr_name; 35, identifier:replace; 36, argument_list; 36, 37; 36, 38; 37, string:'-'; 38, string:'_'; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:parent_attr; 42, identifier:self; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:attr; 46, call; 46, 47; 46, 48; 47, identifier:getattr; 48, argument_list; 48, 49; 48, 50; 48, 51; 49, identifier:parent_attr; 50, identifier:attr_name; 51, None; 52, for_statement; 52, 53; 52, 54; 52, 55; 52, 106; 53, identifier:arg; 54, identifier:args; 55, block; 55, 56; 55, 76; 56, if_statement; 56, 57; 56, 65; 57, not_operator; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:isinstance; 60, argument_list; 60, 61; 60, 62; 61, identifier:arg; 62, attribute; 62, 63; 62, 64; 63, identifier:six; 64, identifier:string_types; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:TypeError; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:'each additional argument must be a string. {0} was not a string'; 73, identifier:format; 74, argument_list; 74, 75; 75, identifier:arg; 76, if_statement; 76, 77; 76, 82; 77, call; 77, 78; 77, 79; 78, identifier:hasattr; 79, argument_list; 79, 80; 79, 81; 80, identifier:parent_attr; 81, identifier:arg; 82, block; 82, 83; 82, 91; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:parent_attr; 86, call; 86, 87; 86, 88; 87, identifier:getattr; 88, argument_list; 88, 89; 88, 90; 89, identifier:parent_attr; 90, identifier:arg; 91, if_statement; 91, 92; 91, 97; 92, call; 92, 93; 92, 94; 93, identifier:hasattr; 94, argument_list; 94, 95; 94, 96; 95, identifier:parent_attr; 96, identifier:attr_name; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:attr; 101, call; 101, 102; 101, 103; 102, identifier:getattr; 103, argument_list; 103, 104; 103, 105; 104, identifier:parent_attr; 105, identifier:attr_name; 106, else_clause; 106, 107; 107, block; 107, 108; 108, pass_statement; 109, return_statement; 109, 110; 110, identifier:attr | def get(self, attr_name, *args):
if not isinstance(attr_name, six.string_types):
raise TypeError('attr_name must be a str.')
if '-' in attr_name:
attr_name = attr_name.replace('-', '_')
parent_attr = self
attr = getattr(parent_attr, attr_name, None)
for arg in args:
if not isinstance(arg, six.string_types):
raise TypeError(
'each additional argument must be a string. {0} was not a string'.format(arg)
)
if hasattr(parent_attr, arg):
parent_attr = getattr(parent_attr, arg)
if hasattr(parent_attr, attr_name):
attr = getattr(parent_attr, attr_name)
else:
pass
return attr |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_load_yml_config; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:config_file; 6, block; 6, 7; 6, 22; 7, if_statement; 7, 8; 7, 16; 8, not_operator; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 13; 12, identifier:config_file; 13, attribute; 13, 14; 13, 15; 14, identifier:six; 15, identifier:string_types; 16, block; 16, 17; 17, raise_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:TypeError; 20, argument_list; 20, 21; 21, string:'config_file must be a str.'; 22, try_statement; 22, 23; 22, 263; 23, block; 23, 24; 23, 55; 23, 87; 23, 126; 23, 158; 23, 190; 23, 198; 23, 206; 23, 214; 23, 222; 23, 230; 23, 241; 23, 251; 24, function_definition; 24, 25; 24, 26; 24, 29; 25, function_name:construct_yaml_int; 26, parameters; 26, 27; 26, 28; 27, identifier:self; 28, identifier:node; 29, block; 29, 30; 29, 40; 29, 53; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:obj; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:SafeConstructor; 36, identifier:construct_yaml_int; 37, argument_list; 37, 38; 37, 39; 38, identifier:self; 39, identifier:node; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:data; 43, call; 43, 44; 43, 45; 44, identifier:ConfigInt; 45, argument_list; 45, 46; 45, 47; 45, 50; 46, identifier:obj; 47, attribute; 47, 48; 47, 49; 48, identifier:node; 49, identifier:start_mark; 50, attribute; 50, 51; 50, 52; 51, identifier:node; 52, identifier:end_mark; 53, return_statement; 53, 54; 54, identifier:data; 55, function_definition; 55, 56; 55, 57; 55, 60; 56, function_name:construct_yaml_float; 57, parameters; 57, 58; 57, 59; 58, identifier:self; 59, identifier:node; 60, block; 60, 61; 60, 72; 60, 85; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 65; 63, pattern_list; 63, 64; 64, identifier:obj; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:SafeConstructor; 68, identifier:construct_yaml_float; 69, argument_list; 69, 70; 69, 71; 70, identifier:self; 71, identifier:node; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:data; 75, call; 75, 76; 75, 77; 76, identifier:ConfigFloat; 77, argument_list; 77, 78; 77, 79; 77, 82; 78, identifier:obj; 79, attribute; 79, 80; 79, 81; 80, identifier:node; 81, identifier:start_mark; 82, attribute; 82, 83; 82, 84; 83, identifier:node; 84, identifier:end_mark; 85, return_statement; 85, 86; 86, identifier:data; 87, function_definition; 87, 88; 87, 89; 87, 92; 88, function_name:construct_yaml_str; 89, parameters; 89, 90; 89, 91; 90, identifier:self; 91, identifier:node; 92, block; 92, 93; 92, 103; 92, 111; 92, 124; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:obj; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:SafeConstructor; 99, identifier:construct_scalar; 100, argument_list; 100, 101; 100, 102; 101, identifier:self; 102, identifier:node; 103, assert_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:isinstance; 106, argument_list; 106, 107; 106, 108; 107, identifier:obj; 108, attribute; 108, 109; 108, 110; 109, identifier:six; 110, identifier:string_types; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:data; 114, call; 114, 115; 114, 116; 115, identifier:ConfigUnicode; 116, argument_list; 116, 117; 116, 118; 116, 121; 117, identifier:obj; 118, attribute; 118, 119; 118, 120; 119, identifier:node; 120, identifier:start_mark; 121, attribute; 121, 122; 121, 123; 122, identifier:node; 123, identifier:end_mark; 124, return_statement; 124, 125; 125, identifier:data; 126, function_definition; 126, 127; 126, 128; 126, 131; 127, function_name:construct_yaml_mapping; 128, parameters; 128, 129; 128, 130; 129, identifier:self; 130, identifier:node; 131, block; 131, 132; 131, 143; 131, 156; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 136; 134, pattern_list; 134, 135; 135, identifier:obj; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:SafeConstructor; 139, identifier:construct_yaml_map; 140, argument_list; 140, 141; 140, 142; 141, identifier:self; 142, identifier:node; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:data; 146, call; 146, 147; 146, 148; 147, identifier:ConfigDict; 148, argument_list; 148, 149; 148, 150; 148, 153; 149, identifier:obj; 150, attribute; 150, 151; 150, 152; 151, identifier:node; 152, identifier:start_mark; 153, attribute; 153, 154; 153, 155; 154, identifier:node; 155, identifier:end_mark; 156, return_statement; 156, 157; 157, identifier:data; 158, function_definition; 158, 159; 158, 160; 158, 163; 159, function_name:construct_yaml_seq; 160, parameters; 160, 161; 160, 162; 161, identifier:self; 162, identifier:node; 163, block; 163, 164; 163, 175; 163, 188; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 168; 166, pattern_list; 166, 167; 167, identifier:obj; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:SafeConstructor; 171, identifier:construct_yaml_seq; 172, argument_list; 172, 173; 172, 174; 173, identifier:self; 174, identifier:node; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:data; 178, call; 178, 179; 178, 180; 179, identifier:ConfigSeq; 180, argument_list; 180, 181; 180, 182; 180, 185; 181, identifier:obj; 182, attribute; 182, 183; 182, 184; 183, identifier:node; 184, identifier:start_mark; 185, attribute; 185, 186; 185, 187; 186, identifier:node; 187, identifier:end_mark; 188, return_statement; 188, 189; 189, identifier:data; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:SafeConstructor; 194, identifier:add_constructor; 195, argument_list; 195, 196; 195, 197; 196, string:u'tag:yaml.org,2002:float'; 197, identifier:construct_yaml_float; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:SafeConstructor; 202, identifier:add_constructor; 203, argument_list; 203, 204; 203, 205; 204, string:u'tag:yaml.org,2002:int'; 205, identifier:construct_yaml_int; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:SafeConstructor; 210, identifier:add_constructor; 211, argument_list; 211, 212; 211, 213; 212, string:u'tag:yaml.org,2002:map'; 213, identifier:construct_yaml_mapping; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:SafeConstructor; 218, identifier:add_constructor; 219, argument_list; 219, 220; 219, 221; 220, string:u'tag:yaml.org,2002:seq'; 221, identifier:construct_yaml_seq; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:SafeConstructor; 226, identifier:add_constructor; 227, argument_list; 227, 228; 227, 229; 228, string:u'tag:yaml.org,2002:str'; 229, identifier:construct_yaml_str; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:data; 233, call; 233, 234; 233, 240; 234, attribute; 234, 235; 234, 239; 235, call; 235, 236; 235, 237; 236, identifier:SafeLoader; 237, argument_list; 237, 238; 238, identifier:config_file; 239, identifier:get_data; 240, argument_list; 241, if_statement; 241, 242; 241, 245; 242, comparison_operator:is; 242, 243; 242, 244; 243, identifier:data; 244, None; 245, block; 245, 246; 246, raise_statement; 246, 247; 247, call; 247, 248; 247, 249; 248, identifier:AttributeError; 249, argument_list; 249, 250; 250, string:'The configuration file needs to have data in it.'; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:_data; 256, call; 256, 257; 256, 258; 257, identifier:normalize_keys; 258, argument_list; 258, 259; 258, 260; 259, identifier:data; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:snake_case; 262, False; 263, except_clause; 263, 264; 263, 268; 264, as_pattern; 264, 265; 264, 266; 265, identifier:YAMLError; 266, as_pattern_target; 266, 267; 267, identifier:e; 268, block; 268, 269; 269, if_statement; 269, 270; 269, 275; 269, 301; 270, call; 270, 271; 270, 272; 271, identifier:hasattr; 272, argument_list; 272, 273; 272, 274; 273, identifier:e; 274, string:'problem_mark'; 275, block; 275, 276; 275, 282; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:mark; 279, attribute; 279, 280; 279, 281; 280, identifier:e; 281, identifier:problem_mark; 282, raise_statement; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:SyntaxError; 285, argument_list; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, string:"There is a syntax error in your freight-forwarder config file line: {0} column: {1}"; 289, identifier:format; 290, argument_list; 290, 291; 290, 296; 291, binary_operator:+; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:mark; 294, identifier:line; 295, integer:1; 296, binary_operator:+; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:mark; 299, identifier:column; 300, integer:1; 301, else_clause; 301, 302; 302, block; 302, 303; 303, raise_statement; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:SyntaxError; 306, argument_list; 306, 307; 307, string:"There is a syntax error in your freight-forwarder config." | def _load_yml_config(self, config_file):
if not isinstance(config_file, six.string_types):
raise TypeError('config_file must be a str.')
try:
def construct_yaml_int(self, node):
obj = SafeConstructor.construct_yaml_int(self, node)
data = ConfigInt(
obj,
node.start_mark,
node.end_mark
)
return data
def construct_yaml_float(self, node):
obj, = SafeConstructor.construct_yaml_float(self, node)
data = ConfigFloat(
obj,
node.start_mark,
node.end_mark
)
return data
def construct_yaml_str(self, node):
obj = SafeConstructor.construct_scalar(self, node)
assert isinstance(obj, six.string_types)
data = ConfigUnicode(
obj,
node.start_mark,
node.end_mark
)
return data
def construct_yaml_mapping(self, node):
obj, = SafeConstructor.construct_yaml_map(self, node)
data = ConfigDict(
obj,
node.start_mark,
node.end_mark
)
return data
def construct_yaml_seq(self, node):
obj, = SafeConstructor.construct_yaml_seq(self, node)
data = ConfigSeq(
obj,
node.start_mark,
node.end_mark
)
return data
SafeConstructor.add_constructor(u'tag:yaml.org,2002:float', construct_yaml_float)
SafeConstructor.add_constructor(u'tag:yaml.org,2002:int', construct_yaml_int)
SafeConstructor.add_constructor(u'tag:yaml.org,2002:map', construct_yaml_mapping)
SafeConstructor.add_constructor(u'tag:yaml.org,2002:seq', construct_yaml_seq)
SafeConstructor.add_constructor(u'tag:yaml.org,2002:str', construct_yaml_str)
data = SafeLoader(config_file).get_data()
if data is None:
raise AttributeError('The configuration file needs to have data in it.')
self._data = normalize_keys(data, snake_case=False)
except YAMLError as e:
if hasattr(e, 'problem_mark'):
mark = e.problem_mark
raise SyntaxError(
"There is a syntax error in your freight-forwarder config file line: {0} column: {1}".format(
mark.line + 1,
mark.column + 1
)
)
else:
raise SyntaxError("There is a syntax error in your freight-forwarder config.") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_create_attr; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:property_key; 6, identifier:data; 7, identifier:ancestors; 8, block; 8, 9; 8, 32; 8, 53; 8, 57; 8, 70; 8, 74; 8, 159; 9, if_statement; 9, 10; 9, 18; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:property_key; 15, attribute; 15, 16; 15, 17; 16, identifier:six; 17, identifier:string_types; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:TypeError; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, string:"property_key must be a string. type: {0} was passed."; 26, identifier:format; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:type; 30, argument_list; 30, 31; 31, identifier:property_key; 32, if_statement; 32, 33; 32, 39; 33, not_operator; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:isinstance; 36, argument_list; 36, 37; 36, 38; 37, identifier:ancestors; 38, identifier:OrderedDict; 39, block; 39, 40; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:TypeError; 43, argument_list; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, string:"ancestors must be an OrderedDict. type: {0} was passed."; 47, identifier:format; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:type; 51, argument_list; 51, 52; 52, identifier:ancestors; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:previous_element; 56, identifier:self; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:normalized_key; 60, call; 60, 61; 60, 67; 61, attribute; 61, 62; 61, 66; 62, call; 62, 63; 62, 64; 63, identifier:normalize_value; 64, argument_list; 64, 65; 65, identifier:property_key; 66, identifier:replace; 67, argument_list; 67, 68; 67, 69; 68, string:'-'; 69, string:'_'; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:normalized_ancestor_key; 73, None; 74, if_statement; 74, 75; 74, 76; 75, identifier:ancestors; 76, block; 76, 77; 77, for_statement; 77, 78; 77, 81; 77, 87; 78, pattern_list; 78, 79; 78, 80; 79, identifier:ancestor_key; 80, identifier:ancestors_value; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:six; 84, identifier:iteritems; 85, argument_list; 85, 86; 86, identifier:ancestors; 87, block; 87, 88; 87, 101; 87, 111; 87, 151; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:normalized_ancestor_key; 91, call; 91, 92; 91, 98; 92, attribute; 92, 93; 92, 97; 93, call; 93, 94; 93, 95; 94, identifier:normalize_value; 95, argument_list; 95, 96; 96, identifier:ancestor_key; 97, identifier:replace; 98, argument_list; 98, 99; 98, 100; 99, string:'-'; 100, string:'_'; 101, if_statement; 101, 102; 101, 109; 102, comparison_operator:==; 102, 103; 102, 108; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:normalized_ancestor_key; 106, identifier:lower; 107, argument_list; 108, string:'root'; 109, block; 109, 110; 110, continue_statement; 111, if_statement; 111, 112; 111, 118; 112, not_operator; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:hasattr; 115, argument_list; 115, 116; 115, 117; 116, identifier:previous_element; 117, identifier:normalized_ancestor_key; 118, block; 118, 119; 118, 132; 118, 138; 118, 144; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:config_attr; 122, call; 122, 123; 122, 124; 123, identifier:ConfigDict; 124, argument_list; 124, 125; 124, 126; 124, 129; 125, dictionary; 126, attribute; 126, 127; 126, 128; 127, identifier:ancestors_value; 128, identifier:start_mark; 129, attribute; 129, 130; 129, 131; 130, identifier:ancestors_value; 131, identifier:end_mark; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:config_attr; 136, identifier:name; 137, identifier:normalized_ancestor_key; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:config_attr; 142, identifier:alias; 143, identifier:ancestor_key; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:setattr; 147, argument_list; 147, 148; 147, 149; 147, 150; 148, identifier:previous_element; 149, identifier:normalized_ancestor_key; 150, identifier:config_attr; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:previous_element; 154, call; 154, 155; 154, 156; 155, identifier:getattr; 156, argument_list; 156, 157; 156, 158; 157, identifier:previous_element; 158, identifier:normalized_ancestor_key; 159, if_statement; 159, 160; 159, 163; 159, 165; 160, comparison_operator:==; 160, 161; 160, 162; 161, identifier:normalized_key; 162, identifier:normalized_ancestor_key; 163, block; 163, 164; 164, pass_statement; 165, else_clause; 165, 166; 166, block; 166, 167; 166, 186; 167, if_statement; 167, 168; 167, 173; 168, call; 168, 169; 168, 170; 169, identifier:isinstance; 170, argument_list; 170, 171; 170, 172; 171, identifier:data; 172, identifier:ConfigNode; 173, block; 173, 174; 173, 180; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:data; 178, identifier:name; 179, identifier:normalized_key; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:data; 184, identifier:alias; 185, identifier:property_key; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 189; 188, identifier:setattr; 189, argument_list; 189, 190; 189, 191; 189, 192; 190, identifier:previous_element; 191, identifier:normalized_key; 192, identifier:data | def _create_attr(self, property_key, data, ancestors):
if not isinstance(property_key, six.string_types):
raise TypeError("property_key must be a string. type: {0} was passed.".format(type(property_key)))
if not isinstance(ancestors, OrderedDict):
raise TypeError("ancestors must be an OrderedDict. type: {0} was passed.".format(type(ancestors)))
previous_element = self
normalized_key = normalize_value(property_key).replace('-', '_')
normalized_ancestor_key = None
if ancestors:
for ancestor_key, ancestors_value in six.iteritems(ancestors):
normalized_ancestor_key = normalize_value(ancestor_key).replace('-', '_')
if normalized_ancestor_key.lower() == 'root':
continue
if not hasattr(previous_element, normalized_ancestor_key):
config_attr = ConfigDict({}, ancestors_value.start_mark, ancestors_value.end_mark)
config_attr.name = normalized_ancestor_key
config_attr.alias = ancestor_key
setattr(
previous_element,
normalized_ancestor_key,
config_attr
)
previous_element = getattr(previous_element, normalized_ancestor_key)
if normalized_key == normalized_ancestor_key:
pass
else:
if isinstance(data, ConfigNode):
data.name = normalized_key
data.alias = property_key
setattr(previous_element, normalized_key, data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_collect_unrecognized_values; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:scheme; 6, identifier:data; 7, identifier:ancestors; 8, block; 8, 9; 8, 30; 8, 51; 8, 55; 8, 184; 9, if_statement; 9, 10; 9, 16; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:ancestors; 15, identifier:OrderedDict; 16, block; 16, 17; 17, raise_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:TypeError; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, string:"ancestors must be an OrderedDict. type: {0} was passed."; 24, identifier:format; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:type; 28, argument_list; 28, 29; 29, identifier:ancestors; 30, if_statement; 30, 31; 30, 37; 31, not_operator; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:isinstance; 34, argument_list; 34, 35; 34, 36; 35, identifier:scheme; 36, identifier:dict; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:TypeError; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, string:'scheme must be a dict. type: {0} was passed'; 45, identifier:format; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:type; 49, argument_list; 49, 50; 50, identifier:scheme; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:unrecognized_values; 54, dictionary; 55, if_statement; 55, 56; 55, 61; 55, 181; 56, call; 56, 57; 56, 58; 57, identifier:isinstance; 58, argument_list; 58, 59; 58, 60; 59, identifier:data; 60, identifier:dict; 61, block; 61, 62; 61, 84; 61, 107; 61, 116; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:pruned_scheme; 65, list_comprehension; 65, 66; 65, 67; 65, 74; 66, identifier:key; 67, for_in_clause; 67, 68; 67, 69; 68, identifier:key; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:scheme; 72, identifier:keys; 73, argument_list; 74, if_clause; 74, 75; 75, boolean_operator:and; 75, 76; 75, 79; 76, comparison_operator:not; 76, 77; 76, 78; 77, identifier:key; 78, identifier:RESERVED_SCHEME_KEYS; 79, comparison_operator:not; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:key; 82, integer:0; 83, identifier:RESERVED_SCHEME_KEYS; 84, for_statement; 84, 85; 84, 88; 84, 94; 85, pattern_list; 85, 86; 85, 87; 86, identifier:key; 87, identifier:value; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:six; 91, identifier:iteritems; 92, argument_list; 92, 93; 93, identifier:data; 94, block; 94, 95; 94, 101; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:in; 96, 97; 96, 98; 97, identifier:key; 98, identifier:pruned_scheme; 99, block; 99, 100; 100, continue_statement; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:unrecognized_values; 105, identifier:key; 106, identifier:value; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:validations; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:scheme; 113, identifier:get; 114, argument_list; 114, 115; 115, string:'is'; 116, if_statement; 116, 117; 116, 122; 117, boolean_operator:and; 117, 118; 117, 119; 118, identifier:validations; 119, comparison_operator:in; 119, 120; 119, 121; 120, string:'one_of'; 121, identifier:validations; 122, block; 122, 123; 123, for_statement; 123, 124; 123, 125; 123, 128; 124, identifier:nested_scheme; 125, subscript; 125, 126; 125, 127; 126, identifier:validations; 127, string:'one_of'; 128, block; 128, 129; 129, if_statement; 129, 130; 129, 135; 130, call; 130, 131; 130, 132; 131, identifier:isinstance; 132, argument_list; 132, 133; 132, 134; 133, identifier:nested_scheme; 134, identifier:dict; 135, block; 135, 136; 135, 146; 135, 168; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:updated_scheme; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:_update_scheme; 143, argument_list; 143, 144; 143, 145; 144, identifier:nested_scheme; 145, identifier:ancestors; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:pruned_scheme; 149, list_comprehension; 149, 150; 149, 151; 149, 158; 150, identifier:key; 151, for_in_clause; 151, 152; 151, 153; 152, identifier:key; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:updated_scheme; 156, identifier:keys; 157, argument_list; 158, if_clause; 158, 159; 159, boolean_operator:and; 159, 160; 159, 163; 160, comparison_operator:not; 160, 161; 160, 162; 161, identifier:key; 162, identifier:RESERVED_SCHEME_KEYS; 163, comparison_operator:not; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:key; 166, integer:0; 167, identifier:RESERVED_SCHEME_KEYS; 168, for_statement; 168, 169; 168, 170; 168, 171; 169, identifier:key; 170, identifier:pruned_scheme; 171, block; 171, 172; 172, if_statement; 172, 173; 172, 176; 173, comparison_operator:in; 173, 174; 173, 175; 174, identifier:key; 175, identifier:unrecognized_values; 176, block; 176, 177; 177, delete_statement; 177, 178; 178, subscript; 178, 179; 178, 180; 179, identifier:unrecognized_values; 180, identifier:key; 181, else_clause; 181, 182; 182, block; 182, 183; 183, pass_statement; 184, return_statement; 184, 185; 185, identifier:unrecognized_values | def _collect_unrecognized_values(self, scheme, data, ancestors):
if not isinstance(ancestors, OrderedDict):
raise TypeError("ancestors must be an OrderedDict. type: {0} was passed.".format(type(ancestors)))
if not isinstance(scheme, dict):
raise TypeError('scheme must be a dict. type: {0} was passed'.format(type(scheme)))
unrecognized_values = {}
if isinstance(data, dict):
pruned_scheme = [key for key in scheme.keys() if key not in RESERVED_SCHEME_KEYS and key[0] not in RESERVED_SCHEME_KEYS]
for key, value in six.iteritems(data):
if key in pruned_scheme:
continue
unrecognized_values[key] = value
validations = scheme.get('is')
if validations and 'one_of' in validations:
for nested_scheme in validations['one_of']:
if isinstance(nested_scheme, dict):
updated_scheme = self._update_scheme(nested_scheme, ancestors)
pruned_scheme = [key for key in updated_scheme.keys() if key not in RESERVED_SCHEME_KEYS and key[0] not in RESERVED_SCHEME_KEYS]
for key in pruned_scheme:
if key in unrecognized_values:
del unrecognized_values[key]
else:
pass
return unrecognized_values |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_update_scheme; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:scheme; 6, identifier:ancestors; 7, block; 7, 8; 7, 29; 7, 50; 7, 59; 7, 74; 7, 78; 7, 221; 7, 228; 8, if_statement; 8, 9; 8, 15; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:isinstance; 12, argument_list; 12, 13; 12, 14; 13, identifier:ancestors; 14, identifier:OrderedDict; 15, block; 15, 16; 16, raise_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:TypeError; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, string:"ancestors must be an OrderedDict. type: {0} was passed."; 23, identifier:format; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:type; 27, argument_list; 27, 28; 28, identifier:ancestors; 29, if_statement; 29, 30; 29, 36; 30, not_operator; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:isinstance; 33, argument_list; 33, 34; 33, 35; 34, identifier:scheme; 35, identifier:dict; 36, block; 36, 37; 37, raise_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:TypeError; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, string:'scheme must be a dict. type: {0} was passed'; 44, identifier:format; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:type; 48, argument_list; 48, 49; 49, identifier:scheme; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:definitions; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:ROOT_SCHEME; 56, identifier:get; 57, argument_list; 57, 58; 58, string:'_'; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:in; 60, 61; 60, 62; 61, string:'inherit'; 62, identifier:scheme; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:scheme; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_scheme_propagation; 71, argument_list; 71, 72; 71, 73; 72, identifier:scheme; 73, identifier:definitions; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:updated_scheme; 77, dictionary; 78, for_statement; 78, 79; 78, 80; 78, 86; 79, identifier:scheme_key; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:six; 83, identifier:iterkeys; 84, argument_list; 84, 85; 85, identifier:scheme; 86, block; 86, 87; 86, 107; 87, if_statement; 87, 88; 87, 96; 88, not_operator; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:isinstance; 91, argument_list; 91, 92; 91, 93; 92, identifier:scheme_key; 93, attribute; 93, 94; 93, 95; 94, identifier:six; 95, identifier:string_types; 96, block; 96, 97; 97, raise_statement; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:TypeError; 100, argument_list; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, string:'scheme keys are required to be strings. type: {0} was passed.'; 104, identifier:format; 105, argument_list; 105, 106; 106, identifier:scheme_key; 107, if_statement; 107, 108; 107, 111; 107, 169; 108, comparison_operator:in; 108, 109; 108, 110; 109, string:'@'; 110, identifier:scheme_key; 111, block; 111, 112; 111, 120; 111, 131; 111, 144; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:ref; 115, subscript; 115, 116; 115, 117; 116, identifier:scheme_key; 117, slice; 117, 118; 117, 119; 118, integer:1; 119, colon; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:scheme_reference; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:_scheme_references; 128, identifier:get; 129, argument_list; 129, 130; 130, identifier:ref; 131, if_statement; 131, 132; 131, 134; 132, not_operator; 132, 133; 133, identifier:scheme_reference; 134, block; 134, 135; 135, raise_statement; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:ConfigValidationException; 138, argument_list; 138, 139; 138, 140; 138, 141; 138, 142; 138, 143; 139, identifier:ancestors; 140, identifier:ref; 141, identifier:scheme_reference; 142, string:'required'; 143, identifier:scheme; 144, for_statement; 144, 145; 144, 146; 144, 149; 145, identifier:reference_key; 146, subscript; 146, 147; 146, 148; 147, identifier:scheme_reference; 148, string:'keys'; 149, block; 149, 150; 149, 161; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:scheme_reference; 155, string:'scheme'; 156, identifier:update; 157, argument_list; 157, 158; 158, subscript; 158, 159; 158, 160; 159, identifier:scheme; 160, identifier:scheme_key; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:updated_scheme; 165, identifier:reference_key; 166, subscript; 166, 167; 166, 168; 167, identifier:scheme_reference; 168, string:'scheme'; 169, elif_clause; 169, 170; 169, 173; 170, comparison_operator:in; 170, 171; 170, 172; 171, string:'~'; 172, identifier:scheme_key; 173, block; 173, 174; 173, 182; 173, 193; 173, 207; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:ref; 177, subscript; 177, 178; 177, 179; 178, identifier:scheme_key; 179, slice; 179, 180; 179, 181; 180, integer:1; 181, colon; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:scheme_reference; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:_scheme_references; 190, identifier:get; 191, argument_list; 191, 192; 192, identifier:ref; 193, if_statement; 193, 194; 193, 196; 194, not_operator; 194, 195; 195, identifier:scheme_reference; 196, block; 196, 197; 197, raise_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:LookupError; 200, argument_list; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, string:"was unable to find {0} in scheme reference."; 204, identifier:format; 205, argument_list; 205, 206; 206, identifier:ref; 207, for_statement; 207, 208; 207, 209; 207, 212; 208, identifier:reference_key; 209, subscript; 209, 210; 209, 211; 210, identifier:scheme_reference; 211, string:'keys'; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 218; 215, subscript; 215, 216; 215, 217; 216, identifier:updated_scheme; 217, identifier:reference_key; 218, subscript; 218, 219; 218, 220; 219, identifier:scheme; 220, identifier:scheme_key; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:scheme; 225, identifier:update; 226, argument_list; 226, 227; 227, identifier:updated_scheme; 228, return_statement; 228, 229; 229, identifier:scheme | def _update_scheme(self, scheme, ancestors):
if not isinstance(ancestors, OrderedDict):
raise TypeError("ancestors must be an OrderedDict. type: {0} was passed.".format(type(ancestors)))
if not isinstance(scheme, dict):
raise TypeError('scheme must be a dict. type: {0} was passed'.format(type(scheme)))
definitions = ROOT_SCHEME.get('_')
if 'inherit' in scheme:
scheme = self._scheme_propagation(scheme, definitions)
updated_scheme = {}
for scheme_key in six.iterkeys(scheme):
if not isinstance(scheme_key, six.string_types):
raise TypeError('scheme keys are required to be strings. type: {0} was passed.'.format(scheme_key))
if '@' in scheme_key:
ref = scheme_key[1:]
scheme_reference = self._scheme_references.get(ref)
if not scheme_reference:
raise ConfigValidationException(ancestors, ref, scheme_reference, 'required', scheme)
for reference_key in scheme_reference['keys']:
scheme_reference['scheme'].update(scheme[scheme_key])
updated_scheme[reference_key] = scheme_reference['scheme']
elif '~' in scheme_key:
ref = scheme_key[1:]
scheme_reference = self._scheme_references.get(ref)
if not scheme_reference:
raise LookupError("was unable to find {0} in scheme reference.".format(ref))
for reference_key in scheme_reference['keys']:
updated_scheme[reference_key] = scheme[scheme_key]
scheme.update(updated_scheme)
return scheme |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:_walk_tree; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 4, identifier:self; 5, identifier:data; 6, identifier:scheme; 7, default_parameter; 7, 8; 7, 9; 8, identifier:ancestors; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:property_name; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:prefix; 15, None; 16, block; 16, 17; 16, 73; 16, 94; 16, 105; 16, 142; 16, 163; 16, 173; 16, 207; 16, 244; 16, 254; 16, 262; 17, if_statement; 17, 18; 17, 21; 18, comparison_operator:is; 18, 19; 18, 20; 19, identifier:property_name; 20, None; 21, block; 21, 22; 21, 26; 21, 46; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:property_name; 25, string:'root'; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:order; 29, binary_operator:+; 29, 30; 29, 32; 30, list:['registries']; 30, 31; 31, string:'registries'; 32, list_comprehension; 32, 33; 32, 34; 32, 41; 33, identifier:key; 34, for_in_clause; 34, 35; 34, 36; 35, identifier:key; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:scheme; 39, identifier:keys; 40, argument_list; 41, if_clause; 41, 42; 42, comparison_operator:not; 42, 43; 42, 44; 43, identifier:key; 44, tuple; 44, 45; 45, string:'registries'; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:scheme; 49, call; 49, 50; 49, 51; 50, identifier:OrderedDict; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:sorted; 54, argument_list; 54, 55; 54, 60; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:scheme; 58, identifier:items; 59, argument_list; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:key; 62, lambda; 62, 63; 62, 65; 63, lambda_parameters; 63, 64; 64, identifier:x; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:order; 68, identifier:index; 69, argument_list; 69, 70; 70, subscript; 70, 71; 70, 72; 71, identifier:x; 72, integer:0; 73, if_statement; 73, 74; 73, 77; 73, 79; 74, comparison_operator:is; 74, 75; 74, 76; 75, identifier:data; 76, None; 77, block; 77, 78; 78, return_statement; 79, elif_clause; 79, 80; 79, 88; 80, not_operator; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:isinstance; 83, argument_list; 83, 84; 83, 85; 84, identifier:property_name; 85, attribute; 85, 86; 85, 87; 86, identifier:six; 87, identifier:string_types; 88, block; 88, 89; 89, raise_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:TypeError; 92, argument_list; 92, 93; 93, string:'property_name must be a string.'; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:ancestors; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:_update_ancestors; 101, argument_list; 101, 102; 101, 103; 101, 104; 102, identifier:data; 103, identifier:property_name; 104, identifier:ancestors; 105, if_statement; 105, 106; 105, 111; 105, 127; 106, call; 106, 107; 106, 108; 107, identifier:isinstance; 108, argument_list; 108, 109; 108, 110; 109, identifier:ancestors; 110, identifier:OrderedDict; 111, block; 111, 112; 112, if_statement; 112, 113; 112, 121; 113, comparison_operator:!=; 113, 114; 113, 120; 114, subscript; 114, 115; 114, 119; 115, call; 115, 116; 115, 117; 116, identifier:list; 117, argument_list; 117, 118; 118, identifier:ancestors; 119, integer:0; 120, string:'root'; 121, block; 121, 122; 122, raise_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:LookupError; 125, argument_list; 125, 126; 126, string:'root must be the first item in ancestors.'; 127, else_clause; 127, 128; 128, block; 128, 129; 129, raise_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:TypeError; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, string:'ancestors must be an OrderedDict. {0} was passed'; 136, identifier:format; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:type; 140, argument_list; 140, 141; 141, identifier:ancestors; 142, if_statement; 142, 143; 142, 149; 143, not_operator; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:isinstance; 146, argument_list; 146, 147; 146, 148; 147, identifier:scheme; 148, identifier:dict; 149, block; 149, 150; 150, raise_statement; 150, 151; 151, call; 151, 152; 151, 153; 152, identifier:TypeError; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, string:'scheme must be a dict. {0} was passed.'; 157, identifier:format; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 161; 160, identifier:type; 161, argument_list; 161, 162; 162, identifier:scheme; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:scheme; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:_update_scheme; 170, argument_list; 170, 171; 170, 172; 171, identifier:scheme; 172, identifier:ancestors; 173, if_statement; 173, 174; 173, 179; 174, boolean_operator:and; 174, 175; 174, 178; 175, comparison_operator:is; 175, 176; 175, 177; 176, identifier:property_name; 177, None; 178, identifier:data; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:data; 183, conditional_expression:if; 183, 184; 183, 199; 183, 206; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:_get_cascading_attr; 188, argument_list; 188, 189; 188, 190; 189, identifier:property_name; 190, list_splat; 190, 191; 191, subscript; 191, 192; 191, 196; 192, call; 192, 193; 192, 194; 193, identifier:list; 194, argument_list; 194, 195; 195, identifier:ancestors; 196, slice; 196, 197; 196, 198; 197, integer:1; 198, colon; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:scheme; 202, identifier:get; 203, argument_list; 203, 204; 203, 205; 204, string:'cascading'; 205, False; 206, identifier:data; 207, for_statement; 207, 208; 207, 209; 207, 227; 208, identifier:err; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:__execute_validations; 213, argument_list; 213, 214; 213, 221; 213, 222; 213, 223; 213, 224; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:scheme; 217, identifier:get; 218, argument_list; 218, 219; 218, 220; 219, string:'is'; 220, dictionary; 221, identifier:data; 222, identifier:property_name; 223, identifier:ancestors; 224, keyword_argument; 224, 225; 224, 226; 225, identifier:prefix; 226, identifier:prefix; 227, block; 227, 228; 228, if_statement; 228, 229; 228, 230; 228, 233; 229, identifier:err; 230, block; 230, 231; 231, raise_statement; 231, 232; 232, identifier:err; 233, else_clause; 233, 234; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:_create_attr; 240, argument_list; 240, 241; 240, 242; 240, 243; 241, identifier:property_name; 242, identifier:data; 243, identifier:ancestors; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:__validate_unrecognized_values; 249, argument_list; 249, 250; 249, 251; 249, 252; 249, 253; 250, identifier:scheme; 251, identifier:data; 252, identifier:ancestors; 253, identifier:prefix; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:__populate_scheme_references; 259, argument_list; 259, 260; 259, 261; 260, identifier:scheme; 261, identifier:property_name; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:__validate_config_properties; 267, argument_list; 267, 268; 267, 269; 267, 270; 267, 271; 268, identifier:scheme; 269, identifier:data; 270, identifier:ancestors; 271, identifier:prefix | def _walk_tree(self, data, scheme, ancestors=None, property_name=None, prefix=None):
if property_name is None:
property_name = 'root'
order = ['registries'] + [key for key in scheme.keys() if key not in ('registries',)]
scheme = OrderedDict(sorted(scheme.items(), key=lambda x: order.index(x[0])))
if data is None:
return
elif not isinstance(property_name, six.string_types):
raise TypeError('property_name must be a string.')
ancestors = self._update_ancestors(data, property_name, ancestors)
if isinstance(ancestors, OrderedDict):
if list(ancestors)[0] != 'root':
raise LookupError('root must be the first item in ancestors.')
else:
raise TypeError('ancestors must be an OrderedDict. {0} was passed'.format(type(ancestors)))
if not isinstance(scheme, dict):
raise TypeError('scheme must be a dict. {0} was passed.'.format(type(scheme)))
scheme = self._update_scheme(scheme, ancestors)
if property_name is not None and data:
data = self._get_cascading_attr(
property_name, *list(ancestors)[1:]
) if scheme.get('cascading', False) else data
for err in self.__execute_validations(scheme.get('is', {}), data, property_name, ancestors, prefix=prefix):
if err:
raise err
else:
self._create_attr(property_name, data, ancestors)
self.__validate_unrecognized_values(scheme, data, ancestors, prefix)
self.__populate_scheme_references(scheme, property_name)
self.__validate_config_properties(scheme, data, ancestors, prefix) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:__execute_validations; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 4, identifier:self; 5, identifier:validations; 6, identifier:data; 7, identifier:property_name; 8, identifier:ancestors; 9, default_parameter; 9, 10; 9, 11; 10, identifier:negation; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:prefix; 14, None; 15, block; 15, 16; 15, 37; 15, 58; 15, 81; 15, 103; 15, 130; 16, if_statement; 16, 17; 16, 23; 17, not_operator; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:isinstance; 20, argument_list; 20, 21; 20, 22; 21, identifier:ancestors; 22, identifier:OrderedDict; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:TypeError; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, string:"ancestors must be an OrderedDict. type: {0} was passed."; 31, identifier:format; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:type; 35, argument_list; 35, 36; 36, identifier:ancestors; 37, if_statement; 37, 38; 37, 44; 38, not_operator; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:isinstance; 41, argument_list; 41, 42; 41, 43; 42, identifier:validations; 43, identifier:dict; 44, block; 44, 45; 45, raise_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:TypeError; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, string:'validations is required to be a dict. type: {1} was passed.'; 52, identifier:format; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:type; 56, argument_list; 56, 57; 57, identifier:validations; 58, if_statement; 58, 59; 58, 67; 59, not_operator; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:isinstance; 62, argument_list; 62, 63; 62, 64; 63, identifier:property_name; 64, attribute; 64, 65; 64, 66; 65, identifier:six; 66, identifier:string_types; 67, block; 67, 68; 68, raise_statement; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:TypeError; 71, argument_list; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, string:"property_key must be a string. type: {0} was passed."; 75, identifier:format; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:type; 79, argument_list; 79, 80; 80, identifier:property_name; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:order; 84, binary_operator:+; 84, 85; 84, 88; 85, list:['type', 'required']; 85, 86; 85, 87; 86, string:'type'; 87, string:'required'; 88, list_comprehension; 88, 89; 88, 90; 88, 97; 89, identifier:key; 90, for_in_clause; 90, 91; 90, 92; 91, identifier:key; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:validations; 95, identifier:keys; 96, argument_list; 97, if_clause; 97, 98; 98, comparison_operator:not; 98, 99; 98, 100; 99, identifier:key; 100, tuple; 100, 101; 100, 102; 101, string:'required'; 102, string:'type'; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:ordered_validations; 106, call; 106, 107; 106, 108; 107, identifier:OrderedDict; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:sorted; 111, argument_list; 111, 112; 111, 117; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:validations; 115, identifier:items; 116, argument_list; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:key; 119, lambda; 119, 120; 119, 122; 120, lambda_parameters; 120, 121; 121, identifier:x; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:order; 125, identifier:index; 126, argument_list; 126, 127; 127, subscript; 127, 128; 127, 129; 128, identifier:x; 129, integer:0; 130, for_statement; 130, 131; 130, 134; 130, 140; 131, pattern_list; 131, 132; 131, 133; 132, identifier:validation; 133, identifier:value; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:six; 137, identifier:iteritems; 138, argument_list; 138, 139; 139, identifier:ordered_validations; 140, block; 140, 141; 141, if_statement; 141, 142; 141, 145; 141, 193; 142, comparison_operator:in; 142, 143; 142, 144; 143, identifier:validation; 144, identifier:VALIDATORS; 145, block; 145, 146; 145, 169; 146, if_statement; 146, 147; 146, 150; 147, comparison_operator:==; 147, 148; 147, 149; 148, identifier:validation; 149, string:'not'; 150, block; 150, 151; 150, 168; 151, for_statement; 151, 152; 151, 153; 151, 164; 152, identifier:err; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:__execute_validations; 157, argument_list; 157, 158; 157, 159; 157, 160; 157, 161; 157, 162; 157, 163; 158, identifier:value; 159, identifier:data; 160, identifier:property_name; 161, identifier:ancestors; 162, identifier:negation; 163, identifier:prefix; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, yield; 166, 167; 167, identifier:err; 168, continue_statement; 169, for_statement; 169, 170; 169, 171; 169, 189; 170, identifier:err; 171, call; 171, 172; 171, 182; 172, call; 172, 173; 172, 174; 173, identifier:getattr; 174, argument_list; 174, 175; 174, 176; 175, identifier:self; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, string:'_{0}'; 179, identifier:format; 180, argument_list; 180, 181; 181, identifier:validation; 182, argument_list; 182, 183; 182, 184; 182, 185; 182, 186; 182, 187; 182, 188; 183, identifier:value; 184, identifier:data; 185, identifier:property_name; 186, identifier:ancestors; 187, identifier:negation; 188, identifier:prefix; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, yield; 191, 192; 192, identifier:err; 193, else_clause; 193, 194; 194, block; 194, 195; 195, raise_statement; 195, 196; 196, call; 196, 197; 196, 198; 197, identifier:LookupError; 198, argument_list; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, string:"{0} isn't a validator or reserved scheme key."; 202, identifier:format; 203, argument_list; 203, 204; 204, identifier:validation | def __execute_validations(self, validations, data, property_name, ancestors, negation=False, prefix=None):
if not isinstance(ancestors, OrderedDict):
raise TypeError("ancestors must be an OrderedDict. type: {0} was passed.".format(type(ancestors)))
if not isinstance(validations, dict):
raise TypeError('validations is required to be a dict. type: {1} was passed.'.format(type(validations)))
if not isinstance(property_name, six.string_types):
raise TypeError("property_key must be a string. type: {0} was passed.".format(type(property_name)))
order = ['type', 'required'] + [key for key in validations.keys() if key not in ('required', 'type')]
ordered_validations = OrderedDict(sorted(validations.items(), key=lambda x: order.index(x[0])))
for validation, value in six.iteritems(ordered_validations):
if validation in VALIDATORS:
if validation == 'not':
for err in self.__execute_validations(value, data, property_name, ancestors, negation, prefix):
yield err
continue
for err in getattr(self, '_{0}'.format(validation))(value, data, property_name, ancestors, negation, prefix):
yield err
else:
raise LookupError("{0} isn't a validator or reserved scheme key.".format(validation)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:users_feature; 3, parameters; 3, 4; 4, identifier:app; 5, block; 5, 6; 5, 25; 5, 33; 5, 40; 5, 47; 5, 53; 5, 59; 5, 76; 5, 83; 5, 90; 5, 98; 5, 136; 5, 143; 5, 184; 6, if_statement; 6, 7; 6, 17; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 14; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:app; 12, identifier:config; 13, identifier:get; 14, argument_list; 14, 15; 14, 16; 15, string:'USER_JWT_SECRET'; 16, None; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:x; 22, identifier:JwtSecretMissing; 23, argument_list; 23, 24; 24, string:'Please set USER_JWT_SECRET in config'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:app; 29, identifier:session_interface; 30, call; 30, 31; 30, 32; 31, identifier:BoilerSessionInterface; 32, argument_list; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:user_service; 37, identifier:init; 38, argument_list; 38, 39; 39, identifier:app; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:login_manager; 44, identifier:init_app; 45, argument_list; 45, 46; 46, identifier:app; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:login_manager; 51, identifier:login_view; 52, string:'user.login'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:login_manager; 57, identifier:login_message; 58, None; 59, decorated_definition; 59, 60; 59, 64; 60, decorator; 60, 61; 61, attribute; 61, 62; 61, 63; 62, identifier:login_manager; 63, identifier:user_loader; 64, function_definition; 64, 65; 64, 66; 64, 68; 65, function_name:load_user; 66, parameters; 66, 67; 67, identifier:id; 68, block; 68, 69; 69, return_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:user_service; 73, identifier:get; 74, argument_list; 74, 75; 75, identifier:id; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:oauth; 80, identifier:init_app; 81, argument_list; 81, 82; 82, identifier:app; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:registry; 86, call; 86, 87; 86, 88; 87, identifier:OauthProviders; 88, argument_list; 88, 89; 89, identifier:app; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:providers; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:registry; 96, identifier:get_providers; 97, argument_list; 98, with_statement; 98, 99; 98, 106; 99, with_clause; 99, 100; 100, with_item; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:app; 104, identifier:app_context; 105, argument_list; 106, block; 106, 107; 107, for_statement; 107, 108; 107, 109; 107, 110; 108, identifier:provider; 109, identifier:providers; 110, block; 110, 111; 111, if_statement; 111, 112; 111, 117; 112, comparison_operator:not; 112, 113; 112, 114; 113, identifier:provider; 114, attribute; 114, 115; 114, 116; 115, identifier:oauth; 116, identifier:remote_apps; 117, block; 117, 118; 117, 129; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:oauth; 122, identifier:remote_app; 123, argument_list; 123, 124; 123, 125; 124, identifier:provider; 125, dictionary_splat; 125, 126; 126, subscript; 126, 127; 126, 128; 127, identifier:providers; 128, identifier:provider; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:registry; 133, identifier:register_token_getter; 134, argument_list; 134, 135; 135, identifier:provider; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:principal; 140, identifier:init_app; 141, argument_list; 141, 142; 142, identifier:app; 143, decorated_definition; 143, 144; 143, 148; 144, decorator; 144, 145; 145, attribute; 145, 146; 145, 147; 146, identifier:principal; 147, identifier:identity_loader; 148, function_definition; 148, 149; 148, 150; 148, 151; 149, function_name:load_identity; 150, parameters; 151, block; 151, 152; 151, 164; 151, 172; 151, 180; 152, if_statement; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:current_user; 155, identifier:is_authenticated; 156, block; 156, 157; 157, return_statement; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:Identity; 160, argument_list; 160, 161; 161, attribute; 161, 162; 161, 163; 162, identifier:current_user; 163, identifier:id; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:session; 168, identifier:pop; 169, argument_list; 169, 170; 169, 171; 170, string:'identity.name'; 171, None; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:session; 176, identifier:pop; 177, argument_list; 177, 178; 177, 179; 178, string:'identity.auth_type'; 179, None; 180, return_statement; 180, 181; 181, call; 181, 182; 181, 183; 182, identifier:AnonymousIdentity; 183, argument_list; 184, decorated_definition; 184, 185; 184, 192; 185, decorator; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:identity_loaded; 189, identifier:connect_via; 190, argument_list; 190, 191; 191, identifier:app; 192, function_definition; 192, 193; 192, 194; 192, 197; 193, function_name:on_identity_loaded; 194, parameters; 194, 195; 194, 196; 195, identifier:sender; 196, identifier:identity; 197, block; 197, 198; 197, 204; 197, 211; 197, 225; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:identity; 202, identifier:user; 203, identifier:current_user; 204, if_statement; 204, 205; 204, 209; 205, not_operator; 205, 206; 206, attribute; 206, 207; 206, 208; 207, identifier:current_user; 208, identifier:is_authenticated; 209, block; 209, 210; 210, return_statement; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:identity; 216, identifier:provides; 217, identifier:add; 218, argument_list; 218, 219; 219, call; 219, 220; 219, 221; 220, identifier:UserNeed; 221, argument_list; 221, 222; 222, attribute; 222, 223; 222, 224; 223, identifier:current_user; 224, identifier:id; 225, for_statement; 225, 226; 225, 227; 225, 230; 226, identifier:role; 227, attribute; 227, 228; 227, 229; 228, identifier:current_user; 229, identifier:roles; 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:identity; 236, identifier:provides; 237, identifier:add; 238, argument_list; 238, 239; 239, call; 239, 240; 239, 241; 240, identifier:RoleNeed; 241, argument_list; 241, 242; 242, attribute; 242, 243; 242, 244; 243, identifier:role; 244, identifier:handle | def users_feature(app):
if not app.config.get('USER_JWT_SECRET', None):
raise x.JwtSecretMissing('Please set USER_JWT_SECRET in config')
app.session_interface = BoilerSessionInterface()
user_service.init(app)
login_manager.init_app(app)
login_manager.login_view = 'user.login'
login_manager.login_message = None
@login_manager.user_loader
def load_user(id):
return user_service.get(id)
oauth.init_app(app)
registry = OauthProviders(app)
providers = registry.get_providers()
with app.app_context():
for provider in providers:
if provider not in oauth.remote_apps:
oauth.remote_app(provider, **providers[provider])
registry.register_token_getter(provider)
principal.init_app(app)
@principal.identity_loader
def load_identity():
if current_user.is_authenticated:
return Identity(current_user.id)
session.pop('identity.name', None)
session.pop('identity.auth_type', None)
return AnonymousIdentity()
@identity_loaded.connect_via(app)
def on_identity_loaded(sender, identity):
identity.user = current_user
if not current_user.is_authenticated:
return
identity.provides.add(UserNeed(current_user.id))
for role in current_user.roles:
identity.provides.add(RoleNeed(role.handle)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:match; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:other; 6, block; 6, 7; 6, 9; 6, 16; 7, expression_statement; 7, 8; 8, string:''' This is a noisy terminal-printing function at present since there is no need to make it a proper API function.'''; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:colortext; 13, identifier:message; 14, argument_list; 14, 15; 15, string:"FASTA Match"; 16, for_statement; 16, 17; 16, 20; 16, 28; 17, pattern_list; 17, 18; 17, 19; 18, identifier:frompdbID; 19, identifier:fromchains; 20, call; 20, 21; 20, 22; 21, identifier:sorted; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:iteritems; 27, argument_list; 28, block; 28, 29; 28, 33; 28, 37; 28, 118; 28, 122; 28, 134; 28, 177; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:matched_pdbs; 32, dictionary; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:matched_chains; 36, dictionary; 37, for_statement; 37, 38; 37, 41; 37, 46; 38, pattern_list; 38, 39; 38, 40; 39, identifier:fromchain; 40, identifier:fromsequence; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:fromchains; 44, identifier:iteritems; 45, argument_list; 46, block; 46, 47; 47, for_statement; 47, 48; 47, 51; 47, 56; 48, pattern_list; 48, 49; 48, 50; 49, identifier:topdbID; 50, identifier:tochains; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:other; 54, identifier:iteritems; 55, argument_list; 56, block; 56, 57; 57, for_statement; 57, 58; 57, 61; 57, 66; 58, pattern_list; 58, 59; 58, 60; 59, identifier:tochain; 60, identifier:tosequence; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:tochains; 64, identifier:iteritems; 65, argument_list; 66, block; 66, 67; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:==; 68, 69; 68, 70; 69, identifier:fromsequence; 70, identifier:tosequence; 71, block; 71, 72; 71, 86; 71, 95; 71, 107; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:matched_pdbs; 76, identifier:topdbID; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:matched_pdbs; 80, identifier:get; 81, argument_list; 81, 82; 81, 83; 82, identifier:topdbID; 83, call; 83, 84; 83, 85; 84, identifier:set; 85, argument_list; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:matched_pdbs; 91, identifier:topdbID; 92, identifier:add; 93, argument_list; 93, 94; 94, identifier:fromchain; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:matched_chains; 99, identifier:fromchain; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:matched_chains; 103, identifier:get; 104, argument_list; 104, 105; 104, 106; 105, identifier:fromchain; 106, list:[]; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 114; 109, attribute; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:matched_chains; 112, identifier:fromchain; 113, identifier:append; 114, argument_list; 114, 115; 115, tuple; 115, 116; 115, 117; 116, identifier:topdbID; 117, identifier:tochain; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:foundmatches; 121, list:[]; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:colortext; 126, identifier:printf; 127, argument_list; 127, 128; 127, 131; 128, binary_operator:%; 128, 129; 128, 130; 129, string:" %s"; 130, identifier:frompdbID; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:color; 133, string:"silver"; 134, for_statement; 134, 135; 134, 138; 134, 143; 135, pattern_list; 135, 136; 135, 137; 136, identifier:mpdbID; 137, identifier:mchains; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:matched_pdbs; 141, identifier:iteritems; 142, argument_list; 143, block; 143, 144; 144, if_statement; 144, 145; 144, 155; 145, comparison_operator:==; 145, 146; 145, 147; 146, identifier:mchains; 147, call; 147, 148; 147, 149; 148, identifier:set; 149, argument_list; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:fromchains; 153, identifier:keys; 154, argument_list; 155, block; 155, 156; 155, 163; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:foundmatches; 160, identifier:append; 161, argument_list; 161, 162; 162, identifier:mpdbID; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:colortext; 167, identifier:printf; 168, argument_list; 168, 169; 168, 174; 169, binary_operator:%; 169, 170; 169, 171; 170, string:" PDB %s matched PDB %s on all chains"; 171, tuple; 171, 172; 171, 173; 172, identifier:mpdbID; 173, identifier:frompdbID; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:color; 176, string:"white"; 177, if_statement; 177, 178; 177, 179; 177, 266; 178, identifier:foundmatches; 179, block; 179, 180; 180, for_statement; 180, 181; 180, 184; 180, 189; 181, pattern_list; 181, 182; 181, 183; 182, identifier:fromchain; 183, identifier:fromsequence; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:fromchains; 187, identifier:iteritems; 188, argument_list; 189, block; 189, 190; 189, 203; 189, 220; 189, 224; 189, 252; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:colortext; 194, identifier:printf; 195, argument_list; 195, 196; 195, 200; 196, binary_operator:%; 196, 197; 196, 198; 197, string:" %s"; 198, parenthesized_expression; 198, 199; 199, identifier:fromchain; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:color; 202, string:"silver"; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:colortext; 207, identifier:printf; 208, argument_list; 208, 209; 208, 213; 209, binary_operator:%; 209, 210; 209, 211; 210, string:" %s"; 211, parenthesized_expression; 211, 212; 212, identifier:fromsequence; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:color; 215, subscript; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:unique_sequences; 219, identifier:fromsequence; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:mstr; 223, list:[]; 224, for_statement; 224, 225; 224, 226; 224, 229; 225, identifier:mchain; 226, subscript; 226, 227; 226, 228; 227, identifier:matched_chains; 228, identifier:fromchain; 229, block; 229, 230; 230, if_statement; 230, 231; 230, 236; 231, comparison_operator:in; 231, 232; 231, 235; 232, subscript; 232, 233; 232, 234; 233, identifier:mchain; 234, integer:0; 235, identifier:foundmatches; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:mstr; 241, identifier:append; 242, argument_list; 242, 243; 243, binary_operator:%; 243, 244; 243, 245; 244, string:"%s chain %s"; 245, tuple; 245, 246; 245, 249; 246, subscript; 246, 247; 246, 248; 247, identifier:mchain; 248, integer:0; 249, subscript; 249, 250; 249, 251; 250, identifier:mchain; 251, integer:1; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:colortext; 256, identifier:printf; 257, argument_list; 257, 258; 258, binary_operator:%; 258, 259; 258, 260; 259, string:" Matches: %s"; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, string:", "; 263, identifier:join; 264, argument_list; 264, 265; 265, identifier:mstr; 266, else_clause; 266, 267; 267, block; 267, 268; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:colortext; 272, identifier:error; 273, argument_list; 273, 274; 274, string:" No matches found." | def match(self, other):
''' This is a noisy terminal-printing function at present since there is no need to make it a proper API function.'''
colortext.message("FASTA Match")
for frompdbID, fromchains in sorted(self.iteritems()):
matched_pdbs = {}
matched_chains = {}
for fromchain, fromsequence in fromchains.iteritems():
for topdbID, tochains in other.iteritems():
for tochain, tosequence in tochains.iteritems():
if fromsequence == tosequence:
matched_pdbs[topdbID] = matched_pdbs.get(topdbID, set())
matched_pdbs[topdbID].add(fromchain)
matched_chains[fromchain] = matched_chains.get(fromchain, [])
matched_chains[fromchain].append((topdbID, tochain))
foundmatches = []
colortext.printf(" %s" % frompdbID, color="silver")
for mpdbID, mchains in matched_pdbs.iteritems():
if mchains == set(fromchains.keys()):
foundmatches.append(mpdbID)
colortext.printf(" PDB %s matched PDB %s on all chains" % (mpdbID, frompdbID), color="white")
if foundmatches:
for fromchain, fromsequence in fromchains.iteritems():
colortext.printf(" %s" % (fromchain), color = "silver")
colortext.printf(" %s" % (fromsequence), color = self.unique_sequences[fromsequence])
mstr = []
for mchain in matched_chains[fromchain]:
if mchain[0] in foundmatches:
mstr.append("%s chain %s" % (mchain[0], mchain[1]))
colortext.printf(" Matches: %s" % ", ".join(mstr))
else:
colortext.error(" No matches found.") |
0, ERROR; 0, 1; 0, 2; 0, 7; 0, 9; 0, 15; 0, 19; 0, 26; 0, 33; 0, 36; 0, 37; 0, 40; 0, 46; 0, 48; 0, 49; 0, 50; 0, 51; 0, 54; 0, 55; 0, 56; 0, 57; 0, 60; 0, 61; 0, 62; 0, 63; 0, 69; 0, 72; 0, 82; 0, 86; 0, 91; 0, 101; 0, 116; 0, 126; 0, 131; 0, 171; 0, 179; 0, 211; 0, 214; 0, 215; 0, 219; 0, 222; 0, 223; 0, 226; 0, 227; 0, 230; 0, 233; 0, 252; 0, 256; 0, 259; 0, 276; 0, 280; 0, 283; 1, identifier:generateSummaryHTMLTable; 2, parameters; 2, 3; 2, 4; 3, identifier:self; 4, default_parameter; 4, 5; 4, 6; 5, identifier:extraLapse; 6, identifier:TYPICAL_LAPSE; 7, expression_statement; 7, 8; 8, string:'''Generates a summary in HTML of the status of the expected scripts broken based on the log.
This summary is returned as a list of strings.
'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:scriptsRun; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:scriptsRun; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:html; 18, list:[]; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:html; 23, identifier:append; 24, argument_list; 24, 25; 25, string:"<table style='text-align:center;border:1px solid black;margin-left: auto;margin-right: auto;'>\n"; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:html; 30, identifier:append; 31, argument_list; 31, 32; 32, string:' <tr><td colspan="4" style="text-align:center"></td></tr>\n'; 33, attribute; 33, 34; 33, 35; 34, identifier:html; 35, identifier:append; 36, string:'; 37, ERROR; 37, 38; 37, 39; 38, identifier:tr; 39, identifier:style; 40, binary_operator:-; 40, 41; 40, 42; 40, 45; 41, identifier:font; 42, ERROR; 42, 43; 42, 44; 43, identifier:weight; 44, identifier:bold; 45, identifier:background; 46, ERROR; 46, 47; 47, identifier:color; 48, identifier:tablestyle; 49, ERROR; 50, ERROR; 51, binary_operator:-; 51, 52; 51, 53; 52, identifier:background; 53, identifier:color; 54, identifier:warningstyle; 55, ERROR; 56, ERROR; 57, binary_operator:-; 57, 58; 57, 59; 58, identifier:background; 59, identifier:color; 60, identifier:failstyle; 61, ERROR; 62, ERROR; 63, slice; 63, 64; 63, 67; 63, 68; 64, binary_operator:-; 64, 65; 64, 66; 65, identifier:background; 66, identifier:color; 67, colon; 68, identifier:count; 69, ERROR; 69, 70; 69, 71; 70, integer:0; 71, identifier:name; 72, comparison_operator:in; 72, 73; 72, 74; 73, identifier:details; 74, call; 74, 75; 74, 76; 75, identifier:sorted; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:scriptsRun; 80, identifier:iteritems; 81, argument_list; 82, ERROR; 82, 83; 82, 84; 82, 85; 83, identifier:status; 84, None; 85, identifier:rowstyle; 86, subscript; 86, 87; 86, 88; 87, identifier:tablestyle; 88, binary_operator:%; 88, 89; 88, 90; 89, identifier:count; 90, integer:2; 91, boolean_operator:and; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:details; 94, string:"lastSuccess"; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:expectedScripts; 98, identifier:get; 99, argument_list; 99, 100; 100, identifier:name; 101, ERROR; 101, 102; 101, 115; 102, ERROR; 102, 103; 102, 114; 103, not_operator; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:expectedScripts; 107, identifier:check; 108, argument_list; 108, 109; 108, 110; 108, 113; 109, identifier:name; 110, subscript; 110, 111; 110, 112; 111, identifier:details; 112, string:"lastSuccess"; 113, identifier:extraLapse; 114, identifier:status; 115, string:"STOPPED"; 116, ERROR; 116, 117; 116, 118; 116, 123; 116, 124; 116, 125; 117, identifier:rowstyle; 118, subscript; 118, 119; 118, 120; 119, identifier:failstyle; 120, binary_operator:%; 120, 121; 120, 122; 121, identifier:count; 122, integer:2; 123, identifier:status; 124, string:"FAIL"; 125, identifier:laststatusstyle; 126, subscript; 126, 127; 126, 128; 127, identifier:tablestyle; 128, binary_operator:%; 128, 129; 128, 130; 129, identifier:count; 130, integer:2; 131, ERROR; 131, 132; 131, 137; 131, 138; 131, 143; 131, 144; 131, 145; 131, 154; 131, 155; 131, 160; 131, 161; 131, 162; 131, 169; 131, 170; 132, binary_operator:&; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:details; 135, string:"status"; 136, identifier:RETROSPECT_FAIL; 137, identifier:laststatusstyle; 138, subscript; 138, 139; 138, 140; 139, identifier:failstyle; 140, binary_operator:%; 140, 141; 140, 142; 141, identifier:count; 142, integer:2; 143, identifier:status; 144, string:"FAIL"; 145, boolean_operator:and; 145, 146; 145, 149; 146, comparison_operator:!=; 146, 147; 146, 148; 147, identifier:status; 148, string:"STOPPED"; 149, binary_operator:&; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:details; 152, string:"status"; 153, identifier:RETROSPECT_WARNING; 154, identifier:laststatusstyle; 155, subscript; 155, 156; 155, 157; 156, identifier:warningstyle; 157, binary_operator:%; 157, 158; 157, 159; 158, identifier:count; 159, integer:2; 160, identifier:status; 161, string:"WARNINGS"; 162, boolean_operator:and; 162, 163; 162, 166; 163, comparison_operator:!=; 163, 164; 163, 165; 164, identifier:status; 165, string:"FAIL"; 166, comparison_operator:!=; 166, 167; 166, 168; 167, identifier:status; 168, string:"STOPPED"; 169, identifier:status; 170, string:"OK"; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:html; 174, identifier:append; 175, argument_list; 175, 176; 176, binary_operator:%; 176, 177; 176, 178; 177, string:'<tr style="text-align:left;%s">\n'; 178, identifier:rowstyle; 179, ERROR; 179, 180; 179, 183; 179, 197; 180, comparison_operator:==; 180, 181; 180, 182; 181, identifier:status; 182, string:"STOPPED"; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:html; 186, identifier:append; 187, argument_list; 187, 188; 188, binary_operator:%; 188, 189; 188, 190; 189, string:'\t<td style="%s">%s</td>\n'; 190, tuple; 190, 191; 190, 196; 191, subscript; 191, 192; 191, 193; 192, identifier:failstyle; 193, binary_operator:%; 193, 194; 193, 195; 194, identifier:count; 195, integer:2; 196, identifier:name; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:html; 200, identifier:append; 201, argument_list; 201, 202; 202, binary_operator:%; 202, 203; 202, 204; 203, string:'\t<td style="%s">%s</td>'; 204, tuple; 204, 205; 204, 210; 205, subscript; 205, 206; 205, 207; 206, identifier:tablestyle; 207, binary_operator:%; 207, 208; 207, 209; 208, identifier:count; 209, integer:2; 210, identifier:name; 211, subscript; 211, 212; 211, 213; 212, identifier:details; 213, string:"lastRun"; 214, ERROR; 215, ERROR; 215, 216; 216, comparison_operator:==; 216, 217; 216, 218; 217, identifier:status; 218, string:"STOPPED"; 219, attribute; 219, 220; 219, 221; 220, identifier:html; 221, identifier:append; 222, string:'\t; 223, ERROR; 223, 224; 223, 225; 224, identifier:td; 225, identifier:style; 226, string:"%s"; 227, ERROR; 227, 228; 227, 229; 228, identifier:a; 229, identifier:href; 230, attribute; 230, 231; 230, 232; 231, identifier:html; 232, identifier:append; 233, comparison_operator:<; 233, 234; 233, 235; 233, 238; 233, 239; 233, 242; 234, string:'\t; 235, ERROR; 235, 236; 235, 237; 236, identifier:td; 237, identifier:style; 238, string:"%s"; 239, ERROR; 239, 240; 239, 241; 240, identifier:a; 241, identifier:href; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:html; 245, identifier:append; 246, argument_list; 246, 247; 247, binary_operator:%; 247, 248; 247, 249; 248, string:'\t<td style="%s">%s</td>\n'; 249, tuple; 249, 250; 249, 251; 250, identifier:laststatusstyle; 251, identifier:status; 252, ERROR; 252, 253; 253, subscript; 253, 254; 253, 255; 254, identifier:details; 255, string:"lastRun"; 256, attribute; 256, 257; 256, 258; 257, identifier:html; 258, identifier:append; 259, comparison_operator:<; 259, 260; 259, 261; 259, 264; 259, 265; 259, 268; 260, string:'\t; 261, ERROR; 261, 262; 261, 263; 262, identifier:td; 263, identifier:style; 264, string:"%s"; 265, ERROR; 265, 266; 265, 267; 266, identifier:a; 267, identifier:href; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:html; 271, identifier:append; 272, argument_list; 272, 273; 273, binary_operator:%; 273, 274; 273, 275; 274, string:'\t<td style="%s">none found</td>\n'; 275, identifier:laststatusstyle; 276, ERROR; 276, 277; 277, subscript; 277, 278; 277, 279; 278, identifier:details; 279, string:"lastSuccess"; 280, attribute; 280, 281; 280, 282; 281, identifier:html; 282, identifier:append; 283, comparison_operator:<; 283, 284; 283, 285; 283, 286; 283, 312; 284, string:'\t; 285, identifier:td; 286, ERROR; 286, 287; 286, 288; 286, 289; 286, 302; 286, 303; 286, 311; 287, identifier:a; 288, identifier:href; 289, call; 289, 290; 289, 300; 290, attribute; 290, 291; 290, 297; 290, 299; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:html; 294, identifier:append; 295, argument_list; 295, 296; 296, string:'\t<td>none found</td>\n'; 297, ERROR; 297, 298; 298, identifier:html; 299, identifier:append; 300, argument_list; 300, 301; 301, string:'</tr>\n'; 302, identifier:count; 303, call; 303, 304; 303, 309; 304, attribute; 304, 305; 304, 306; 304, 308; 305, integer:1; 306, ERROR; 306, 307; 307, identifier:html; 308, identifier:append; 309, argument_list; 309, 310; 310, string:"</table>"; 311, identifier:return; 312, identifier:html | def generateSummaryHTMLTable(self, extraLapse = TYPICAL_LAPSE):
'''Generates a summary in HTML of the status of the expected scripts broken based on the log.
This summary is returned as a list of strings.
'''
scriptsRun = self.scriptsRun
html = []
html.append("<table style='text-align:center;border:1px solid black;margin-left: auto;margin-right: auto;'>\n")
html.append(' <tr><td colspan="4" style="text-align:center"></td></tr>\n')
html.append(' <tr style="font-weight:bold;background-color:
tablestyle = ['background-color:
warningstyle = ['background-color:
failstyle = ['background-color:
count = 0
for name, details in sorted(scriptsRun.iteritems()):
status = None
rowstyle = tablestyle[count % 2]
if details["lastSuccess"] and expectedScripts.get(name):
if not expectedScripts.check(name, details["lastSuccess"], extraLapse):
status = "STOPPED"
else:
rowstyle = failstyle[count % 2]
status = "FAIL"
laststatusstyle = tablestyle[count % 2]
if details["status"] & RETROSPECT_FAIL:
laststatusstyle = failstyle[count % 2]
status = "FAIL"
elif status != "STOPPED" and details["status"] & RETROSPECT_WARNING:
laststatusstyle = warningstyle[count % 2]
status = "WARNINGS"
elif status != "FAIL" and status != "STOPPED":
status = "OK"
html.append('<tr style="text-align:left;%s">\n' % rowstyle)
if status == "STOPPED":
html.append('\t<td style="%s">%s</td>\n' % (failstyle[count % 2], name))
else:
html.append('\t<td style="%s">%s</td>' % (tablestyle[count % 2], name))
if details["lastRun"]:
if status == "STOPPED":
html.append('\t<td style="%s"><a href="
else:
html.append('\t<td style="%s"><a href="
else:
html.append('\t<td style="%s">%s</td>\n' % (laststatusstyle, status))
if details["lastRun"]:
html.append('\t<td style="%s"><a href="
else:
html.append('\t<td style="%s">none found</td>\n' % laststatusstyle)
if details["lastSuccess"]:
html.append('\t<td><a href="
else:
html.append('\t<td>none found</td>\n')
html.append('</tr>\n')
count += 1
html.append("</table>")
return html |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:apply_quality_control_checks; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:seq; 5, default_parameter; 5, 6; 5, 7; 6, identifier:check_gen9_seqs; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:check_short_length; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:check_local_gc_content; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:check_global_gc_content; 16, True; 17, block; 17, 18; 17, 26; 17, 30; 17, 55; 17, 77; 17, 147; 17, 191; 17, 264; 17, 304; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:seq; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:seq; 24, identifier:upper; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:failure_reasons; 29, list:[]; 30, if_statement; 30, 31; 30, 32; 31, identifier:check_short_length; 32, block; 32, 33; 33, if_statement; 33, 34; 33, 40; 34, comparison_operator:<; 34, 35; 34, 39; 35, call; 35, 36; 35, 37; 36, identifier:len; 37, argument_list; 37, 38; 38, identifier:seq; 39, identifier:min_gene_length; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:failure_reasons; 45, identifier:append; 46, argument_list; 46, 47; 47, binary_operator:%; 47, 48; 47, 49; 48, string:'minimum_length: Sequence is %d bp long and needs to be at least %d bp'; 49, tuple; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:seq; 54, identifier:min_gene_length; 55, if_statement; 55, 56; 55, 62; 56, comparison_operator:>; 56, 57; 56, 61; 57, call; 57, 58; 57, 59; 58, identifier:len; 59, argument_list; 59, 60; 60, identifier:seq; 61, identifier:max_gene_length; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:failure_reasons; 67, identifier:append; 68, argument_list; 68, 69; 69, binary_operator:%; 69, 70; 69, 71; 70, string:'maximum_length: Sequence is %d bp long and needs to be shorter than %d bp'; 71, tuple; 71, 72; 71, 76; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, identifier:seq; 76, identifier:max_gene_length; 77, if_statement; 77, 78; 77, 79; 78, identifier:check_gen9_seqs; 79, block; 79, 80; 80, for_statement; 80, 81; 80, 82; 80, 83; 81, identifier:site; 82, identifier:reserved_restriction_sites; 83, block; 83, 84; 83, 93; 83, 102; 83, 111; 83, 129; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:pattern; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:dna; 90, identifier:dna_to_re; 91, argument_list; 91, 92; 92, identifier:site; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:reverse_site; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:dna; 99, identifier:reverse_complement; 100, argument_list; 100, 101; 101, identifier:site; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:reverse_pattern; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:dna; 108, identifier:dna_to_re; 109, argument_list; 109, 110; 110, identifier:reverse_site; 111, if_statement; 111, 112; 111, 118; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:pattern; 115, identifier:match; 116, argument_list; 116, 117; 117, identifier:seq; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:failure_reasons; 123, identifier:append; 124, argument_list; 124, 125; 125, binary_operator:%; 125, 126; 125, 127; 126, string:'gen9_restricted_sequences: Reserved sequence %s is present'; 127, parenthesized_expression; 127, 128; 128, identifier:site; 129, if_statement; 129, 130; 129, 136; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:reverse_pattern; 133, identifier:match; 134, argument_list; 134, 135; 135, identifier:seq; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:failure_reasons; 141, identifier:append; 142, argument_list; 142, 143; 143, binary_operator:%; 143, 144; 143, 145; 144, string:'gen9_restricted_sequences: Reverse-complement of reserved sequence %s is present'; 145, parenthesized_expression; 145, 146; 146, identifier:site; 147, if_statement; 147, 148; 147, 149; 148, identifier:check_global_gc_content; 149, block; 149, 150; 149, 159; 149, 175; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:gc_content; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:dna; 156, identifier:gc_content; 157, argument_list; 157, 158; 158, identifier:seq; 159, if_statement; 159, 160; 159, 163; 160, comparison_operator:<; 160, 161; 160, 162; 161, identifier:gc_content; 162, identifier:global_gc_content_min; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:failure_reasons; 168, identifier:append; 169, argument_list; 169, 170; 170, binary_operator:%; 170, 171; 170, 172; 171, string:'global_gc_content_min: Global GC content is %.3f%% and must be at least %.3f%%'; 172, tuple; 172, 173; 172, 174; 173, identifier:gc_content; 174, identifier:global_gc_content_min; 175, if_statement; 175, 176; 175, 179; 176, comparison_operator:>; 176, 177; 176, 178; 177, identifier:gc_content; 178, identifier:global_gc_content_max; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:failure_reasons; 184, identifier:append; 185, argument_list; 185, 186; 186, binary_operator:%; 186, 187; 186, 188; 187, string:'global_gc_content_max: Global GC content is %.3f%% and must be less than %.3f%%'; 188, tuple; 188, 189; 188, 190; 189, identifier:gc_content; 190, identifier:global_gc_content_max; 191, if_statement; 191, 192; 191, 193; 192, identifier:check_local_gc_content; 193, block; 193, 194; 193, 199; 193, 217; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:windows; 197, list:[seq]; 197, 198; 198, identifier:seq; 199, if_statement; 199, 200; 199, 206; 200, comparison_operator:<; 200, 201; 200, 202; 201, identifier:local_gc_window_size; 202, call; 202, 203; 202, 204; 203, identifier:len; 204, argument_list; 204, 205; 205, identifier:seq; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:windows; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:dna; 213, identifier:sliding_window; 214, argument_list; 214, 215; 214, 216; 215, identifier:seq; 216, identifier:local_gc_window_size; 217, for_statement; 217, 218; 217, 219; 217, 220; 218, identifier:seq_window; 219, identifier:windows; 220, block; 220, 221; 220, 230; 220, 247; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:lgc_content; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:dna; 227, identifier:gc_content; 228, argument_list; 228, 229; 229, identifier:seq_window; 230, if_statement; 230, 231; 230, 234; 231, comparison_operator:<; 231, 232; 231, 233; 232, identifier:lgc_content; 233, identifier:local_gc_content_min; 234, block; 234, 235; 234, 246; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:failure_reasons; 239, identifier:append; 240, argument_list; 240, 241; 241, binary_operator:%; 241, 242; 241, 243; 242, string:'local_gc_content_min: Local GC content is %.3f%% and must be at least %.3f%%'; 243, tuple; 243, 244; 243, 245; 244, identifier:lgc_content; 245, identifier:local_gc_content_min; 246, break_statement; 247, if_statement; 247, 248; 247, 251; 248, comparison_operator:>; 248, 249; 248, 250; 249, identifier:lgc_content; 250, identifier:local_gc_content_max; 251, block; 251, 252; 251, 263; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:failure_reasons; 256, identifier:append; 257, argument_list; 257, 258; 258, binary_operator:%; 258, 259; 258, 260; 259, string:'local_gc_content_max: Local GC content is %.3f%% and must be less than %.3f%%'; 260, tuple; 260, 261; 260, 262; 261, identifier:lgc_content; 262, identifier:local_gc_content_max; 263, break_statement; 264, for_statement; 264, 265; 264, 266; 264, 269; 265, identifier:base; 266, attribute; 266, 267; 266, 268; 267, identifier:dna; 268, identifier:dna_bases; 269, block; 269, 270; 269, 278; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:homopolymer; 273, binary_operator:*; 273, 274; 273, 275; 274, identifier:base; 275, subscript; 275, 276; 275, 277; 276, identifier:homopolymer_max_lengths; 277, identifier:base; 278, if_statement; 278, 279; 278, 282; 279, comparison_operator:in; 279, 280; 279, 281; 280, identifier:homopolymer; 281, identifier:seq; 282, block; 282, 283; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:failure_reasons; 287, identifier:append; 288, argument_list; 288, 289; 289, binary_operator:%; 289, 290; 289, 291; 290, string:'max_%s_homopolymer: %s'; 291, tuple; 291, 292; 291, 297; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:base; 295, identifier:lower; 296, argument_list; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:dna; 300, identifier:case_highlight; 301, argument_list; 301, 302; 301, 303; 302, identifier:seq; 303, identifier:a_homopolymer; 304, if_statement; 304, 305; 304, 306; 305, identifier:failure_reasons; 306, block; 306, 307; 306, 311; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:intro; 310, string:"The given sequence fails following Gen9 design guidelines:"; 311, raise_statement; 311, 312; 312, call; 312, 313; 312, 314; 313, identifier:ValueError; 314, argument_list; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, string:'\n'; 318, identifier:join; 319, argument_list; 319, 320; 320, binary_operator:+; 320, 321; 320, 323; 321, list:[intro]; 321, 322; 322, identifier:intro; 323, identifier:failure_reasons | def apply_quality_control_checks(
seq,
check_gen9_seqs=True,
check_short_length=True,
check_local_gc_content=True,
check_global_gc_content=True):
seq = seq.upper()
failure_reasons = []
if check_short_length:
if len(seq) < min_gene_length:
failure_reasons.append('minimum_length: Sequence is %d bp long and needs to be at least %d bp'%(len(seq),min_gene_length))
if len(seq) > max_gene_length:
failure_reasons.append('maximum_length: Sequence is %d bp long and needs to be shorter than %d bp'%(len(seq),max_gene_length))
if check_gen9_seqs:
for site in reserved_restriction_sites:
pattern = dna.dna_to_re(site)
reverse_site = dna.reverse_complement(site)
reverse_pattern = dna.dna_to_re(reverse_site)
if pattern.match(seq):
failure_reasons.append('gen9_restricted_sequences: Reserved sequence %s is present'%(site))
if reverse_pattern.match(seq):
failure_reasons.append('gen9_restricted_sequences: Reverse-complement of reserved sequence %s is present'%(site))
if check_global_gc_content:
gc_content = dna.gc_content(seq)
if gc_content < global_gc_content_min:
failure_reasons.append('global_gc_content_min: Global GC content is %.3f%% and must be at least %.3f%%'%(gc_content,global_gc_content_min))
if gc_content > global_gc_content_max:
failure_reasons.append('global_gc_content_max: Global GC content is %.3f%% and must be less than %.3f%%'%(gc_content,global_gc_content_max))
if check_local_gc_content:
windows = [seq]
if local_gc_window_size < len(seq):
windows = dna.sliding_window(seq, local_gc_window_size)
for seq_window in windows:
lgc_content = dna.gc_content(seq_window)
if lgc_content < local_gc_content_min:
failure_reasons.append('local_gc_content_min: Local GC content is %.3f%% and must be at least %.3f%%'%(lgc_content,local_gc_content_min))
break
if lgc_content > local_gc_content_max:
failure_reasons.append('local_gc_content_max: Local GC content is %.3f%% and must be less than %.3f%%'%(lgc_content,local_gc_content_max))
break
for base in dna.dna_bases:
homopolymer = base * homopolymer_max_lengths[base]
if homopolymer in seq:
failure_reasons.append('max_%s_homopolymer: %s'%(
base.lower(), dna.case_highlight(seq,a_homopolymer)))
if failure_reasons:
intro = "The given sequence fails following Gen9 design guidelines:"
raise ValueError('\n'.join([intro] + failure_reasons)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:oauth_connect; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:provider; 6, identifier:action; 7, block; 7, 8; 7, 15; 7, 32; 7, 69; 7, 77; 7, 83; 7, 92; 7, 101; 7, 105; 7, 109; 7, 113; 7, 152; 7, 259; 7, 387; 7, 398; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:valid_actions; 11, list:["connect", "authorized", "test"]; 11, 12; 11, 13; 11, 14; 12, string:"connect"; 13, string:"authorized"; 14, string:"test"; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:_redirect; 18, conditional_expression:if; 18, 19; 18, 26; 18, 29; 19, attribute; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:views; 23, identifier:auth; 24, identifier:Account; 25, identifier:account_settings; 26, call; 26, 27; 26, 28; 27, identifier:is_authenticated; 28, argument_list; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:login; 32, if_statement; 32, 33; 32, 63; 33, boolean_operator:or; 33, 34; 33, 56; 33, 57; 34, boolean_operator:or; 34, 35; 34, 48; 34, 49; 35, boolean_operator:or; 35, 36; 35, 39; 35, 40; 36, comparison_operator:not; 36, 37; 36, 38; 37, identifier:action; 38, identifier:valid_actions; 39, line_continuation:\; 40, comparison_operator:not; 40, 41; 40, 42; 41, string:"oauth"; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:__options__; 45, identifier:get; 46, argument_list; 46, 47; 47, string:"registration_methods"; 48, line_continuation:\; 49, not_operator; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:__options__; 53, identifier:get; 54, argument_list; 54, 55; 55, string:"allow_registration"; 56, line_continuation:\; 57, not_operator; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:hasattr; 60, argument_list; 60, 61; 60, 62; 61, identifier:oauth; 62, identifier:provider; 63, block; 63, 64; 64, return_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:redirect; 67, argument_list; 67, 68; 68, identifier:_redirect; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:client; 72, call; 72, 73; 72, 74; 73, identifier:getattr; 74, argument_list; 74, 75; 74, 76; 75, identifier:oauth; 76, identifier:provider; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:params; 80, attribute; 80, 81; 80, 82; 81, identifier:client; 82, identifier:__params__; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:me_args; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:params; 89, identifier:get; 90, argument_list; 90, 91; 91, string:"me"; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:user_id; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:params; 98, identifier:get; 99, argument_list; 99, 100; 100, string:"user_id"; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:oauth_user_id; 104, None; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:oauth_name; 108, None; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:oauth_email; 112, None; 113, if_statement; 113, 114; 113, 117; 114, comparison_operator:==; 114, 115; 114, 116; 115, identifier:action; 116, string:"test"; 117, block; 117, 118; 117, 134; 117, 139; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:session_data; 121, dictionary; 121, 122; 121, 125; 121, 128; 121, 131; 122, pair; 122, 123; 122, 124; 123, string:"provider"; 124, string:"ensure"; 125, pair; 125, 126; 125, 127; 126, string:"user_id"; 127, string:"1234"; 128, pair; 128, 129; 128, 130; 129, string:"name"; 130, string:"Mardix"; 131, pair; 131, 132; 131, 133; 132, string:"email"; 133, string:"mardix@email.com"; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:set_oauth_session; 137, argument_list; 137, 138; 138, identifier:session_data; 139, return_statement; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:redirect; 142, argument_list; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:url_for; 145, argument_list; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:register; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:oauth; 151, integer:1; 152, if_statement; 152, 153; 152, 156; 152, 202; 153, comparison_operator:==; 153, 154; 153, 155; 154, identifier:action; 155, string:"connect"; 156, block; 156, 157; 156, 168; 156, 193; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:_next; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:request; 164, identifier:args; 165, identifier:get; 166, argument_list; 166, 167; 167, string:'next'; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:authorized_url; 171, call; 171, 172; 171, 173; 172, identifier:url_for; 173, argument_list; 173, 174; 173, 175; 173, 178; 173, 181; 173, 190; 174, identifier:self; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:provider; 177, identifier:provider; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:action; 180, string:"authorized"; 181, keyword_argument; 181, 182; 181, 183; 182, identifier:next; 183, boolean_operator:or; 183, 184; 183, 189; 184, boolean_operator:or; 184, 185; 184, 186; 185, identifier:_next; 186, attribute; 186, 187; 186, 188; 187, identifier:request; 188, identifier:referrer; 189, None; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:_external; 192, True; 193, return_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:client; 197, identifier:authorize; 198, argument_list; 198, 199; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:callback; 201, identifier:authorized_url; 202, elif_clause; 202, 203; 202, 206; 203, comparison_operator:==; 203, 204; 203, 205; 204, identifier:action; 205, string:"authorized"; 206, block; 206, 207; 206, 215; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:resp; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:client; 213, identifier:authorized_response; 214, argument_list; 215, if_statement; 215, 216; 215, 219; 215, 221; 215, 233; 216, comparison_operator:is; 216, 217; 216, 218; 217, identifier:resp; 218, None; 219, block; 219, 220; 220, pass_statement; 221, elif_clause; 221, 222; 221, 227; 222, call; 222, 223; 222, 224; 223, identifier:isinstance; 224, argument_list; 224, 225; 224, 226; 225, identifier:resp; 226, identifier:OAuthException; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:flash_error; 231, argument_list; 231, 232; 232, string:"Access Denied"; 233, else_clause; 233, 234; 234, block; 234, 235; 235, if_statement; 235, 236; 235, 238; 235, 248; 236, not_operator; 236, 237; 237, identifier:me_args; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:oauth_user_id; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:resp; 245, identifier:get; 246, argument_list; 246, 247; 247, identifier:user_id; 248, else_clause; 248, 249; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:me; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:client; 256, identifier:get; 257, argument_list; 257, 258; 258, identifier:me_args; 259, if_statement; 259, 260; 259, 265; 259, 380; 260, boolean_operator:and; 260, 261; 260, 264; 261, comparison_operator:==; 261, 262; 261, 263; 262, identifier:action; 263, string:"authorized"; 264, identifier:oauth_user_id; 265, block; 265, 266; 266, if_statement; 266, 267; 266, 270; 266, 320; 267, call; 267, 268; 267, 269; 268, identifier:is_authenticated; 269, argument_list; 270, block; 270, 271; 270, 309; 271, try_statement; 271, 272; 271, 296; 272, block; 272, 273; 272, 285; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:current_user; 277, identifier:add_federated_login; 278, argument_list; 278, 279; 278, 282; 279, keyword_argument; 279, 280; 279, 281; 280, identifier:provider; 281, identifier:provider; 282, keyword_argument; 282, 283; 282, 284; 283, identifier:federated_id; 284, identifier:oauth_user_id; 285, expression_statement; 285, 286; 286, call; 286, 287; 286, 288; 287, identifier:flash_success; 288, argument_list; 288, 289; 289, binary_operator:%; 289, 290; 289, 291; 290, string:"You can now login with your %s account"; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:provider; 294, identifier:upper; 295, argument_list; 296, except_clause; 296, 297; 296, 301; 297, as_pattern; 297, 298; 297, 299; 298, identifier:Exception; 299, as_pattern_target; 299, 300; 300, identifier:e; 301, block; 301, 302; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:logging; 306, identifier:exception; 307, argument_list; 307, 308; 308, identifier:e; 309, return_statement; 309, 310; 310, call; 310, 311; 310, 312; 311, identifier:redirect; 312, argument_list; 312, 313; 313, attribute; 313, 314; 313, 319; 314, attribute; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:views; 317, identifier:auth; 318, identifier:Account; 319, identifier:account_settings; 320, else_clause; 320, 321; 321, block; 321, 322; 321, 330; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:user; 325, call; 325, 326; 325, 327; 326, identifier:with_federation; 327, argument_list; 327, 328; 327, 329; 328, identifier:provider; 329, identifier:oauth_user_id; 330, if_statement; 330, 331; 330, 332; 330, 357; 331, identifier:user; 332, block; 332, 333; 332, 338; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 336; 335, identifier:create_session; 336, argument_list; 336, 337; 337, identifier:user; 338, return_statement; 338, 339; 339, call; 339, 340; 339, 341; 340, identifier:redirect; 341, argument_list; 341, 342; 342, boolean_operator:or; 342, 343; 342, 351; 343, call; 343, 344; 343, 349; 344, attribute; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:request; 347, identifier:args; 348, identifier:get; 349, argument_list; 349, 350; 350, string:"next"; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:__options__; 354, identifier:get; 355, argument_list; 355, 356; 356, string:"login_view"; 357, else_clause; 357, 358; 358, block; 358, 359; 358, 375; 359, expression_statement; 359, 360; 360, assignment; 360, 361; 360, 362; 361, identifier:session_data; 362, dictionary; 362, 363; 362, 366; 362, 369; 362, 372; 363, pair; 363, 364; 363, 365; 364, string:"provider"; 365, identifier:provider; 366, pair; 366, 367; 366, 368; 367, string:"user_id"; 368, identifier:oauth_user_id; 369, pair; 369, 370; 369, 371; 370, string:"name"; 371, identifier:oauth_name; 372, pair; 372, 373; 372, 374; 373, string:"email"; 374, identifier:oauth_email; 375, expression_statement; 375, 376; 376, call; 376, 377; 376, 378; 377, identifier:set_oauth_session; 378, argument_list; 378, 379; 379, identifier:session_data; 380, else_clause; 380, 381; 381, block; 381, 382; 382, return_statement; 382, 383; 383, call; 383, 384; 383, 385; 384, identifier:redirect; 385, argument_list; 385, 386; 386, identifier:_redirect; 387, return_statement; 387, 388; 388, dictionary; 388, 389; 388, 392; 388, 395; 389, pair; 389, 390; 389, 391; 390, string:"action"; 391, identifier:action; 392, pair; 392, 393; 392, 394; 393, string:"provider"; 394, identifier:provider; 395, pair; 395, 396; 395, 397; 396, string:"authorized_url"; 397, string:""; 398, return_statement; 398, 399; 399, call; 399, 400; 399, 401; 400, identifier:redirect; 401, argument_list; 401, 402; 402, identifier:_redirect | def oauth_connect(self, provider, action):
valid_actions = ["connect", "authorized", "test"]
_redirect = views.auth.Account.account_settings if is_authenticated() else self.login
if action not in valid_actions \
or "oauth" not in __options__.get("registration_methods") \
or not __options__.get("allow_registration") \
or not hasattr(oauth, provider):
return redirect(_redirect)
client = getattr(oauth, provider)
params = client.__params__
me_args = params.get("me")
user_id = params.get("user_id")
oauth_user_id = None
oauth_name = None
oauth_email = None
if action == "test":
session_data = {
"provider": "ensure",
"user_id": "1234",
"name": "Mardix",
"email": "mardix@email.com",
}
set_oauth_session(session_data)
return redirect(url_for(self.register, oauth=1))
if action == "connect":
_next = request.args.get('next')
authorized_url = url_for(self,
provider=provider,
action="authorized",
next=_next or request.referrer or None,
_external=True)
return client.authorize(callback=authorized_url)
elif action == "authorized":
resp = client.authorized_response()
if resp is None:
pass
elif isinstance(resp, OAuthException):
flash_error("Access Denied")
else:
if not me_args:
oauth_user_id = resp.get(user_id)
else:
me = client.get(me_args)
if action == "authorized" and oauth_user_id:
if is_authenticated():
try:
current_user.add_federated_login(provider=provider,
federated_id=oauth_user_id)
flash_success(
"You can now login with your %s account" % provider.upper())
except Exception as e:
logging.exception(e)
return redirect(views.auth.Account.account_settings)
else:
user = with_federation(provider, oauth_user_id)
if user:
create_session(user)
return redirect(request.args.get("next") or __options__.get(
"login_view"))
else:
session_data = {
"provider": provider,
"user_id": oauth_user_id,
"name": oauth_name,
"email": oauth_email,
}
set_oauth_session(session_data)
else:
return redirect(_redirect)
return {
"action": action,
"provider": provider,
"authorized_url": ""
}
return redirect(_redirect) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:set_neighbors; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 25; 5, 29; 5, 186; 5, 195; 5, 206; 5, 210; 5, 237; 5, 246; 5, 266; 5, 284; 5, 298; 6, expression_statement; 6, 7; 7, string:'''Set neighbors for multi-environments, their slave environments,
and agents.
'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:t; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:time; 14, identifier:time; 15, argument_list; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:logger; 22, identifier:debug; 23, argument_list; 23, 24; 24, string:"Settings grid neighbors for the multi-environments."; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:tasks; 28, list:[]; 29, for_statement; 29, 30; 29, 31; 29, 40; 30, identifier:i; 31, call; 31, 32; 31, 33; 32, identifier:range; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:grid; 40, block; 40, 41; 41, for_statement; 41, 42; 41, 43; 41, 54; 42, identifier:j; 43, call; 43, 44; 43, 45; 44, identifier:range; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:len; 48, argument_list; 48, 49; 49, subscript; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:grid; 53, integer:0; 54, block; 54, 55; 54, 65; 54, 77; 54, 94; 54, 118; 54, 135; 54, 161; 54, 179; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:addr; 58, subscript; 58, 59; 58, 64; 59, subscript; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:grid; 63, identifier:i; 64, identifier:j; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 72; 67, pattern_list; 67, 68; 67, 69; 67, 70; 67, 71; 68, identifier:N; 69, identifier:E; 70, identifier:S; 71, identifier:W; 72, expression_list; 72, 73; 72, 74; 72, 75; 72, 76; 73, None; 74, None; 75, None; 76, None; 77, if_statement; 77, 78; 77, 81; 78, comparison_operator:!=; 78, 79; 78, 80; 79, identifier:i; 80, integer:0; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:W; 85, subscript; 85, 86; 85, 93; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:grid; 90, binary_operator:-; 90, 91; 90, 92; 91, identifier:i; 92, integer:1; 93, identifier:j; 94, if_statement; 94, 95; 94, 105; 95, comparison_operator:!=; 95, 96; 95, 97; 96, identifier:i; 97, binary_operator:-; 97, 98; 97, 104; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:grid; 104, integer:1; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:E; 109, subscript; 109, 110; 109, 117; 110, subscript; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:grid; 114, binary_operator:+; 114, 115; 114, 116; 115, identifier:i; 116, integer:1; 117, identifier:j; 118, if_statement; 118, 119; 118, 122; 119, comparison_operator:!=; 119, 120; 119, 121; 120, identifier:j; 121, integer:0; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:N; 126, subscript; 126, 127; 126, 132; 127, subscript; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:grid; 131, identifier:i; 132, binary_operator:-; 132, 133; 132, 134; 133, identifier:j; 134, integer:1; 135, if_statement; 135, 136; 135, 148; 136, comparison_operator:!=; 136, 137; 136, 138; 137, identifier:j; 138, binary_operator:-; 138, 139; 138, 147; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, subscript; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:grid; 146, integer:0; 147, integer:1; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:S; 152, subscript; 152, 153; 152, 158; 153, subscript; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:grid; 157, identifier:i; 158, binary_operator:+; 158, 159; 158, 160; 159, identifier:j; 160, integer:1; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:task; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:asyncio; 167, identifier:ensure_future; 168, argument_list; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:_set_node_neighbors; 173, argument_list; 173, 174; 173, 175; 173, 176; 173, 177; 173, 178; 174, identifier:addr; 175, identifier:N; 176, identifier:E; 177, identifier:S; 178, identifier:W; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:tasks; 183, identifier:append; 184, argument_list; 184, 185; 185, identifier:task; 186, expression_statement; 186, 187; 187, await; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:asyncio; 191, identifier:gather; 192, argument_list; 192, 193; 193, list_splat; 193, 194; 194, identifier:tasks; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:logger; 201, identifier:debug; 202, argument_list; 202, 203; 203, concatenated_string; 203, 204; 203, 205; 204, string:"Setting grid neighbors for the slave environments "; 205, string:"and their agents."; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:tasks; 209, list:[]; 210, for_statement; 210, 211; 210, 212; 210, 215; 211, identifier:addr; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:addrs; 215, block; 215, 216; 215, 230; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:task; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:asyncio; 222, identifier:ensure_future; 223, argument_list; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:_set_neighbors; 228, argument_list; 228, 229; 229, identifier:addr; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:tasks; 234, identifier:append; 235, argument_list; 235, 236; 236, identifier:task; 237, expression_statement; 237, 238; 238, await; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:asyncio; 242, identifier:gather; 243, argument_list; 243, 244; 244, list_splat; 244, 245; 245, identifier:tasks; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 253; 248, attribute; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:logger; 252, identifier:debug; 253, argument_list; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, string:"All grid neighbors set in {} seconds."; 257, identifier:format; 258, argument_list; 258, 259; 259, binary_operator:-; 259, 260; 259, 265; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:time; 263, identifier:time; 264, argument_list; 265, identifier:t; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:x; 269, binary_operator:*; 269, 270; 269, 281; 270, binary_operator:*; 270, 271; 270, 276; 271, subscript; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:_ngs; 275, integer:0; 276, subscript; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:self; 279, identifier:_gs; 280, integer:0; 281, attribute; 281, 282; 281, 283; 282, identifier:self; 283, identifier:_n_slaves; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:y; 287, binary_operator:*; 287, 288; 287, 293; 288, subscript; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:_ngs; 292, integer:1; 293, subscript; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:self; 296, identifier:_gs; 297, integer:1; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 305; 300, attribute; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:self; 303, identifier:logger; 304, identifier:info; 305, argument_list; 305, 306; 306, call; 306, 307; 306, 312; 307, attribute; 307, 308; 307, 311; 308, concatenated_string; 308, 309; 308, 310; 309, string:"Initialized a distributed grid with overall size "; 310, string:"({}, {}). Total of {} agents."; 311, identifier:format; 312, argument_list; 312, 313; 312, 314; 312, 315; 313, identifier:x; 314, identifier:y; 315, binary_operator:*; 315, 316; 315, 317; 316, identifier:x; 317, identifier:y | async def set_neighbors(self):
'''Set neighbors for multi-environments, their slave environments,
and agents.
'''
t = time.time()
self.logger.debug("Settings grid neighbors for the multi-environments.")
tasks = []
for i in range(len(self.grid)):
for j in range(len(self.grid[0])):
addr = self.grid[i][j]
N, E, S, W = None, None, None, None
if i != 0:
W = self.grid[i-1][j]
if i != len(self.grid) - 1:
E = self.grid[i+1][j]
if j != 0:
N = self.grid[i][j-1]
if j != len(self.grid[0]) - 1:
S = self.grid[i][j+1]
task = asyncio.ensure_future(self._set_node_neighbors(addr, N, E, S, W))
tasks.append(task)
await asyncio.gather(*tasks)
self.logger.debug("Setting grid neighbors for the slave environments "
"and their agents.")
tasks = []
for addr in self.addrs:
task = asyncio.ensure_future(self._set_neighbors(addr))
tasks.append(task)
await asyncio.gather(*tasks)
self.logger.debug("All grid neighbors set in {} seconds."
.format(time.time() - t))
x = self._ngs[0] * self._gs[0] * self._n_slaves
y = self._ngs[1] * self._gs[1]
self.logger.info("Initialized a distributed grid with overall size "
"({}, {}). Total of {} agents.".format(x, y, x*y)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:vectors; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:direction; 7, string:"all"; 8, default_parameter; 8, 9; 8, 10; 9, identifier:failed; 10, False; 11, block; 11, 12; 11, 32; 11, 50; 12, if_statement; 12, 13; 12, 19; 13, comparison_operator:not; 13, 14; 13, 15; 14, identifier:direction; 15, list:["all", "incoming", "outgoing"]; 15, 16; 15, 17; 15, 18; 16, string:"all"; 17, string:"incoming"; 18, string:"outgoing"; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:ValueError; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, concatenated_string; 26, 27; 26, 28; 27, string:"{} is not a valid vector direction. "; 28, string:"Must be all, incoming or outgoing."; 29, identifier:format; 30, argument_list; 30, 31; 31, identifier:direction; 32, if_statement; 32, 33; 32, 39; 33, comparison_operator:not; 33, 34; 33, 35; 34, identifier:failed; 35, list:["all", False, True]; 35, 36; 35, 37; 35, 38; 36, string:"all"; 37, False; 38, True; 39, block; 39, 40; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:ValueError; 43, argument_list; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, string:"{} is not a valid vector failed"; 47, identifier:format; 48, argument_list; 48, 49; 49, identifier:failed; 50, if_statement; 50, 51; 50, 54; 50, 139; 51, comparison_operator:==; 51, 52; 51, 53; 52, identifier:failed; 53, string:"all"; 54, block; 54, 55; 54, 91; 54, 115; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:==; 56, 57; 56, 58; 57, identifier:direction; 58, string:"all"; 59, block; 59, 60; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 90; 62, attribute; 62, 63; 62, 88; 62, 89; 63, call; 63, 64; 63, 70; 64, attribute; 64, 65; 64, 68; 64, 69; 65, attribute; 65, 66; 65, 67; 66, identifier:Vector; 67, identifier:query; 68, line_continuation:\; 69, identifier:filter; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:or_; 73, argument_list; 73, 74; 73, 81; 74, comparison_operator:==; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:Vector; 77, identifier:destination_id; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:id; 81, comparison_operator:==; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:Vector; 84, identifier:origin_id; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:id; 88, line_continuation:\; 89, identifier:all; 90, argument_list; 91, if_statement; 91, 92; 91, 95; 92, comparison_operator:==; 92, 93; 92, 94; 93, identifier:direction; 94, string:"incoming"; 95, block; 95, 96; 96, return_statement; 96, 97; 97, call; 97, 98; 97, 114; 98, attribute; 98, 99; 98, 112; 98, 113; 99, call; 99, 100; 99, 106; 100, attribute; 100, 101; 100, 104; 100, 105; 101, attribute; 101, 102; 101, 103; 102, identifier:Vector; 103, identifier:query; 104, line_continuation:\; 105, identifier:filter_by; 106, argument_list; 106, 107; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:destination_id; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:id; 112, line_continuation:\; 113, identifier:all; 114, argument_list; 115, if_statement; 115, 116; 115, 119; 116, comparison_operator:==; 116, 117; 116, 118; 117, identifier:direction; 118, string:"outgoing"; 119, block; 119, 120; 120, return_statement; 120, 121; 121, call; 121, 122; 121, 138; 122, attribute; 122, 123; 122, 136; 122, 137; 123, call; 123, 124; 123, 130; 124, attribute; 124, 125; 124, 128; 124, 129; 125, attribute; 125, 126; 125, 127; 126, identifier:Vector; 127, identifier:query; 128, line_continuation:\; 129, identifier:filter_by; 130, argument_list; 130, 131; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:origin_id; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:id; 136, line_continuation:\; 137, identifier:all; 138, argument_list; 139, else_clause; 139, 140; 140, block; 140, 141; 140, 185; 140, 212; 141, if_statement; 141, 142; 141, 145; 142, comparison_operator:==; 142, 143; 142, 144; 143, identifier:direction; 144, string:"all"; 145, block; 145, 146; 146, return_statement; 146, 147; 147, call; 147, 148; 147, 184; 148, attribute; 148, 149; 148, 182; 148, 183; 149, call; 149, 150; 149, 156; 150, attribute; 150, 151; 150, 154; 150, 155; 151, attribute; 151, 152; 151, 153; 152, identifier:Vector; 153, identifier:query; 154, line_continuation:\; 155, identifier:filter; 156, argument_list; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:and_; 159, argument_list; 159, 160; 159, 165; 160, comparison_operator:==; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:Vector; 163, identifier:failed; 164, identifier:failed; 165, call; 165, 166; 165, 167; 166, identifier:or_; 167, argument_list; 167, 168; 167, 175; 168, comparison_operator:==; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:Vector; 171, identifier:destination_id; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:id; 175, comparison_operator:==; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:Vector; 178, identifier:origin_id; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:id; 182, line_continuation:\; 183, identifier:all; 184, argument_list; 185, if_statement; 185, 186; 185, 189; 186, comparison_operator:==; 186, 187; 186, 188; 187, identifier:direction; 188, string:"incoming"; 189, block; 189, 190; 190, return_statement; 190, 191; 191, call; 191, 192; 191, 211; 192, attribute; 192, 193; 192, 209; 192, 210; 193, call; 193, 194; 193, 200; 194, attribute; 194, 195; 194, 198; 194, 199; 195, attribute; 195, 196; 195, 197; 196, identifier:Vector; 197, identifier:query; 198, line_continuation:\; 199, identifier:filter_by; 200, argument_list; 200, 201; 200, 206; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:destination_id; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:id; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:failed; 208, identifier:failed; 209, line_continuation:\; 210, identifier:all; 211, argument_list; 212, if_statement; 212, 213; 212, 216; 213, comparison_operator:==; 213, 214; 213, 215; 214, identifier:direction; 215, string:"outgoing"; 216, block; 216, 217; 217, return_statement; 217, 218; 218, call; 218, 219; 218, 238; 219, attribute; 219, 220; 219, 236; 219, 237; 220, call; 220, 221; 220, 227; 221, attribute; 221, 222; 221, 225; 221, 226; 222, attribute; 222, 223; 222, 224; 223, identifier:Vector; 224, identifier:query; 225, line_continuation:\; 226, identifier:filter_by; 227, argument_list; 227, 228; 227, 233; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:origin_id; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:id; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:failed; 235, identifier:failed; 236, line_continuation:\; 237, identifier:all; 238, argument_list | def vectors(self, direction="all", failed=False):
if direction not in ["all", "incoming", "outgoing"]:
raise ValueError(
"{} is not a valid vector direction. "
"Must be all, incoming or outgoing.".format(direction))
if failed not in ["all", False, True]:
raise ValueError("{} is not a valid vector failed".format(failed))
if failed == "all":
if direction == "all":
return Vector.query\
.filter(or_(Vector.destination_id == self.id,
Vector.origin_id == self.id))\
.all()
if direction == "incoming":
return Vector.query\
.filter_by(destination_id=self.id)\
.all()
if direction == "outgoing":
return Vector.query\
.filter_by(origin_id=self.id)\
.all()
else:
if direction == "all":
return Vector.query\
.filter(and_(Vector.failed == failed,
or_(Vector.destination_id == self.id,
Vector.origin_id == self.id)))\
.all()
if direction == "incoming":
return Vector.query\
.filter_by(destination_id=self.id, failed=failed)\
.all()
if direction == "outgoing":
return Vector.query\
.filter_by(origin_id=self.id, failed=failed)\
.all() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:transmissions; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:direction; 7, string:"outgoing"; 8, default_parameter; 8, 9; 8, 10; 9, identifier:status; 10, string:"all"; 11, default_parameter; 11, 12; 11, 13; 12, identifier:failed; 13, False; 14, block; 14, 15; 14, 36; 14, 57; 14, 75; 14, 170; 14, 238; 15, if_statement; 15, 16; 15, 22; 16, comparison_operator:not; 16, 17; 16, 18; 17, identifier:direction; 18, list:["incoming", "outgoing", "all"]; 18, 19; 18, 20; 18, 21; 19, string:"incoming"; 20, string:"outgoing"; 21, string:"all"; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, parenthesized_expression; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:ValueError; 27, argument_list; 27, 28; 28, binary_operator:+; 28, 29; 28, 35; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, string:"You cannot get transmissions of direction {}."; 32, identifier:format; 33, argument_list; 33, 34; 34, identifier:direction; 35, string:"Type can only be incoming, outgoing or all."; 36, if_statement; 36, 37; 36, 43; 37, comparison_operator:not; 37, 38; 37, 39; 38, identifier:status; 39, list:["all", "pending", "received"]; 39, 40; 39, 41; 39, 42; 40, string:"all"; 41, string:"pending"; 42, string:"received"; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, parenthesized_expression; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:ValueError; 48, argument_list; 48, 49; 49, binary_operator:+; 49, 50; 49, 56; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, string:"You cannot get transmission of status {}."; 53, identifier:format; 54, argument_list; 54, 55; 55, identifier:status; 56, string:"Status can only be pending, received or all"; 57, if_statement; 57, 58; 57, 64; 58, comparison_operator:not; 58, 59; 58, 60; 59, identifier:failed; 60, list:["all", False, True]; 60, 61; 60, 62; 60, 63; 61, string:"all"; 62, False; 63, True; 64, block; 64, 65; 65, raise_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:ValueError; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:"{} is not a valid transmission failed"; 72, identifier:format; 73, argument_list; 73, 74; 74, identifier:failed; 75, if_statement; 75, 76; 75, 79; 76, comparison_operator:==; 76, 77; 76, 78; 77, identifier:direction; 78, string:"all"; 79, block; 79, 80; 80, if_statement; 80, 81; 80, 84; 80, 124; 81, comparison_operator:==; 81, 82; 81, 83; 82, identifier:status; 83, string:"all"; 84, block; 84, 85; 85, return_statement; 85, 86; 86, call; 86, 87; 86, 123; 87, attribute; 87, 88; 87, 121; 87, 122; 88, call; 88, 89; 88, 95; 89, attribute; 89, 90; 89, 93; 89, 94; 90, attribute; 90, 91; 90, 92; 91, identifier:Transmission; 92, identifier:query; 93, line_continuation:\; 94, identifier:filter; 95, argument_list; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:and_; 98, argument_list; 98, 99; 98, 104; 99, comparison_operator:==; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:Transmission; 102, identifier:failed; 103, False; 104, call; 104, 105; 104, 106; 105, identifier:or_; 106, argument_list; 106, 107; 106, 114; 107, comparison_operator:==; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:Transmission; 110, identifier:destination_id; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:id; 114, comparison_operator:==; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:Transmission; 117, identifier:origin_id; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:id; 121, line_continuation:\; 122, identifier:all; 123, argument_list; 124, else_clause; 124, 125; 125, block; 125, 126; 126, return_statement; 126, 127; 127, call; 127, 128; 127, 169; 128, attribute; 128, 129; 128, 167; 128, 168; 129, call; 129, 130; 129, 136; 130, attribute; 130, 131; 130, 134; 130, 135; 131, attribute; 131, 132; 131, 133; 132, identifier:Transmission; 133, identifier:query; 134, line_continuation:\; 135, identifier:filter; 136, argument_list; 136, 137; 137, call; 137, 138; 137, 139; 138, identifier:and_; 139, argument_list; 139, 140; 139, 145; 139, 150; 140, comparison_operator:==; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:Transmission; 143, identifier:failed; 144, False; 145, comparison_operator:==; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:Transmission; 148, identifier:status; 149, identifier:status; 150, call; 150, 151; 150, 152; 151, identifier:or_; 152, argument_list; 152, 153; 152, 160; 153, comparison_operator:==; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:Transmission; 156, identifier:destination_id; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:id; 160, comparison_operator:==; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:Transmission; 163, identifier:origin_id; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:id; 167, line_continuation:\; 168, identifier:all; 169, argument_list; 170, if_statement; 170, 171; 170, 174; 171, comparison_operator:==; 171, 172; 171, 173; 172, identifier:direction; 173, string:"incoming"; 174, block; 174, 175; 175, if_statement; 175, 176; 175, 179; 175, 202; 176, comparison_operator:==; 176, 177; 176, 178; 177, identifier:status; 178, string:"all"; 179, block; 179, 180; 180, return_statement; 180, 181; 181, call; 181, 182; 181, 201; 182, attribute; 182, 183; 182, 199; 182, 200; 183, call; 183, 184; 183, 190; 184, attribute; 184, 185; 184, 188; 184, 189; 185, attribute; 185, 186; 185, 187; 186, identifier:Transmission; 187, identifier:query; 188, line_continuation:\; 189, identifier:filter_by; 190, argument_list; 190, 191; 190, 194; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:failed; 193, False; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:destination_id; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:id; 199, line_continuation:\; 200, identifier:all; 201, argument_list; 202, else_clause; 202, 203; 203, block; 203, 204; 204, return_statement; 204, 205; 205, call; 205, 206; 205, 237; 206, attribute; 206, 207; 206, 235; 206, 236; 207, call; 207, 208; 207, 214; 208, attribute; 208, 209; 208, 212; 208, 213; 209, attribute; 209, 210; 209, 211; 210, identifier:Transmission; 211, identifier:query; 212, line_continuation:\; 213, identifier:filter; 214, argument_list; 214, 215; 215, call; 215, 216; 215, 217; 216, identifier:and_; 217, argument_list; 217, 218; 217, 223; 217, 230; 218, comparison_operator:==; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:Transmission; 221, identifier:failed; 222, False; 223, comparison_operator:==; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:Transmission; 226, identifier:destination_id; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:id; 230, comparison_operator:==; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:Transmission; 233, identifier:status; 234, identifier:status; 235, line_continuation:\; 236, identifier:all; 237, argument_list; 238, if_statement; 238, 239; 238, 242; 239, comparison_operator:==; 239, 240; 239, 241; 240, identifier:direction; 241, string:"outgoing"; 242, block; 242, 243; 243, if_statement; 243, 244; 243, 247; 243, 270; 244, comparison_operator:==; 244, 245; 244, 246; 245, identifier:status; 246, string:"all"; 247, block; 247, 248; 248, return_statement; 248, 249; 249, call; 249, 250; 249, 269; 250, attribute; 250, 251; 250, 267; 250, 268; 251, call; 251, 252; 251, 258; 252, attribute; 252, 253; 252, 256; 252, 257; 253, attribute; 253, 254; 253, 255; 254, identifier:Transmission; 255, identifier:query; 256, line_continuation:\; 257, identifier:filter_by; 258, argument_list; 258, 259; 258, 262; 259, keyword_argument; 259, 260; 259, 261; 260, identifier:failed; 261, False; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:origin_id; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:id; 267, line_continuation:\; 268, identifier:all; 269, argument_list; 270, else_clause; 270, 271; 271, block; 271, 272; 272, return_statement; 272, 273; 273, call; 273, 274; 273, 305; 274, attribute; 274, 275; 274, 303; 274, 304; 275, call; 275, 276; 275, 282; 276, attribute; 276, 277; 276, 280; 276, 281; 277, attribute; 277, 278; 277, 279; 278, identifier:Transmission; 279, identifier:query; 280, line_continuation:\; 281, identifier:filter; 282, argument_list; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:and_; 285, argument_list; 285, 286; 285, 291; 285, 298; 286, comparison_operator:==; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:Transmission; 289, identifier:failed; 290, False; 291, comparison_operator:==; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:Transmission; 294, identifier:origin_id; 295, attribute; 295, 296; 295, 297; 296, identifier:self; 297, identifier:id; 298, comparison_operator:==; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:Transmission; 301, identifier:status; 302, identifier:status; 303, line_continuation:\; 304, identifier:all; 305, argument_list | def transmissions(self, direction="outgoing", status="all", failed=False):
if direction not in ["incoming", "outgoing", "all"]:
raise(ValueError("You cannot get transmissions of direction {}."
.format(direction) +
"Type can only be incoming, outgoing or all."))
if status not in ["all", "pending", "received"]:
raise(ValueError("You cannot get transmission of status {}."
.format(status) +
"Status can only be pending, received or all"))
if failed not in ["all", False, True]:
raise ValueError("{} is not a valid transmission failed"
.format(failed))
if direction == "all":
if status == "all":
return Transmission.query\
.filter(and_(Transmission.failed == False,
or_(Transmission.destination_id == self.id,
Transmission.origin_id == self.id)))\
.all()
else:
return Transmission.query\
.filter(and_(Transmission.failed == False,
Transmission.status == status,
or_(Transmission.destination_id == self.id,
Transmission.origin_id == self.id)))\
.all()
if direction == "incoming":
if status == "all":
return Transmission.query\
.filter_by(failed=False, destination_id=self.id)\
.all()
else:
return Transmission.query\
.filter(and_(Transmission.failed == False,
Transmission.destination_id == self.id,
Transmission.status == status))\
.all()
if direction == "outgoing":
if status == "all":
return Transmission.query\
.filter_by(failed=False, origin_id=self.id)\
.all()
else:
return Transmission.query\
.filter(and_(Transmission.failed == False,
Transmission.origin_id == self.id,
Transmission.status == status))\
.all() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:user_stats; 3, parameters; 3, 4; 4, identifier:request; 5, block; 5, 6; 5, 11; 5, 15; 5, 19; 5, 44; 5, 61; 5, 80; 5, 86; 5, 102; 5, 109; 5, 116; 5, 136; 5, 148; 5, 164; 5, 174; 5, 184; 5, 250; 5, 362; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:timer; 9, argument_list; 9, 10; 10, string:'user_stats'; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:response; 14, dictionary; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:data; 18, None; 19, if_statement; 19, 20; 19, 25; 20, comparison_operator:==; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:request; 23, identifier:method; 24, string:"POST"; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:data; 29, subscript; 29, 30; 29, 43; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:json; 33, identifier:loads; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:request; 39, identifier:body; 40, identifier:decode; 41, argument_list; 41, 42; 42, string:"utf-8"; 43, string:"filters"; 44, if_statement; 44, 45; 44, 50; 45, comparison_operator:in; 45, 46; 45, 47; 46, string:"filters"; 47, attribute; 47, 48; 47, 49; 48, identifier:request; 49, identifier:GET; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:data; 54, call; 54, 55; 54, 56; 55, identifier:load_query_json; 56, argument_list; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:request; 59, identifier:GET; 60, string:"filters"; 61, if_statement; 61, 62; 61, 65; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:data; 64, None; 65, block; 65, 66; 66, return_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:render_json; 69, argument_list; 69, 70; 69, 71; 69, 72; 69, 75; 70, identifier:request; 71, dictionary; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:template; 74, string:'models_user_stats.html'; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:help_text; 77, attribute; 77, 78; 77, 79; 78, identifier:user_stats; 79, identifier:__doc__; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:environment; 83, call; 83, 84; 83, 85; 84, identifier:get_environment; 85, argument_list; 86, if_statement; 86, 87; 86, 91; 87, call; 87, 88; 87, 89; 88, identifier:is_time_overridden; 89, argument_list; 89, 90; 90, identifier:request; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:environment; 96, identifier:shift_time; 97, argument_list; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:get_time; 100, argument_list; 100, 101; 101, identifier:request; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:user_id; 105, call; 105, 106; 105, 107; 106, identifier:get_user_id; 107, argument_list; 107, 108; 108, identifier:request; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:language; 112, call; 112, 113; 112, 114; 113, identifier:get_language; 114, argument_list; 114, 115; 115, identifier:request; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, pattern_list; 118, 119; 118, 120; 119, identifier:filter_names; 120, identifier:filter_filters; 121, call; 121, 122; 121, 123; 122, identifier:list; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:zip; 126, argument_list; 126, 127; 127, list_splat; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:sorted; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:data; 134, identifier:items; 135, argument_list; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:reachable_leaves; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:Item; 143, identifier:objects; 144, identifier:filter_all_reachable_leaves_many; 145, argument_list; 145, 146; 145, 147; 146, identifier:filter_filters; 147, identifier:language; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:all_leaves; 151, call; 151, 152; 151, 153; 152, identifier:sorted; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:list; 156, argument_list; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:set; 159, argument_list; 159, 160; 160, call; 160, 161; 160, 162; 161, identifier:flatten; 162, argument_list; 162, 163; 163, identifier:reachable_leaves; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:answers; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:environment; 170, identifier:number_of_answers_more_items; 171, argument_list; 171, 172; 171, 173; 172, identifier:all_leaves; 173, identifier:user_id; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:correct_answers; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:environment; 180, identifier:number_of_correct_answers_more_items; 181, argument_list; 181, 182; 181, 183; 182, identifier:all_leaves; 183, identifier:user_id; 184, if_statement; 184, 185; 184, 193; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:request; 189, identifier:GET; 190, identifier:get; 191, argument_list; 191, 192; 192, string:"mastered"; 193, block; 193, 194; 193, 199; 193, 205; 193, 218; 193, 238; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:timer; 197, argument_list; 197, 198; 198, string:'user_stats_mastered'; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:mastery_threshold; 202, call; 202, 203; 202, 204; 203, identifier:get_mastery_trashold; 204, argument_list; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:predictions; 208, call; 208, 209; 208, 214; 209, attribute; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:Item; 212, identifier:objects; 213, identifier:predict_for_overview; 214, argument_list; 214, 215; 214, 216; 214, 217; 215, identifier:environment; 216, identifier:user_id; 217, identifier:all_leaves; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:mastered; 221, call; 221, 222; 221, 223; 222, identifier:dict; 223, argument_list; 223, 224; 224, call; 224, 225; 224, 226; 225, identifier:list; 226, argument_list; 226, 227; 227, call; 227, 228; 227, 229; 228, identifier:zip; 229, argument_list; 229, 230; 229, 231; 230, identifier:all_leaves; 231, list_comprehension; 231, 232; 231, 235; 232, comparison_operator:>=; 232, 233; 232, 234; 233, identifier:p; 234, identifier:mastery_threshold; 235, for_in_clause; 235, 236; 235, 237; 236, identifier:p; 237, identifier:predictions; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:LOGGER; 242, identifier:debug; 243, argument_list; 243, 244; 243, 245; 244, string:"user_stats - getting predictions for items took %s seconds"; 245, parenthesized_expression; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:timer; 248, argument_list; 248, 249; 249, string:'user_stats_mastered'; 250, for_statement; 250, 251; 250, 254; 250, 259; 251, pattern_list; 251, 252; 251, 253; 252, identifier:identifier; 253, identifier:items; 254, call; 254, 255; 254, 256; 255, identifier:zip; 256, argument_list; 256, 257; 256, 258; 257, identifier:filter_names; 258, identifier:reachable_leaves; 259, block; 259, 260; 260, if_statement; 260, 261; 260, 267; 260, 282; 261, comparison_operator:==; 261, 262; 261, 266; 262, call; 262, 263; 262, 264; 263, identifier:len; 264, argument_list; 264, 265; 265, identifier:items; 266, integer:0; 267, block; 267, 268; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 273; 270, subscript; 270, 271; 270, 272; 271, identifier:response; 272, identifier:identifier; 273, dictionary; 273, 274; 273, 279; 274, pair; 274, 275; 274, 276; 275, string:"filter"; 276, subscript; 276, 277; 276, 278; 277, identifier:data; 278, identifier:identifier; 279, pair; 279, 280; 279, 281; 280, string:"number_of_items"; 281, integer:0; 282, else_clause; 282, 283; 283, block; 283, 284; 283, 336; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 289; 286, subscript; 286, 287; 286, 288; 287, identifier:response; 288, identifier:identifier; 289, dictionary; 289, 290; 289, 295; 289, 301; 289, 314; 289, 325; 290, pair; 290, 291; 290, 292; 291, string:"filter"; 292, subscript; 292, 293; 292, 294; 293, identifier:data; 294, identifier:identifier; 295, pair; 295, 296; 295, 297; 296, string:"number_of_items"; 297, call; 297, 298; 297, 299; 298, identifier:len; 299, argument_list; 299, 300; 300, identifier:items; 301, pair; 301, 302; 301, 303; 302, string:"number_of_practiced_items"; 303, call; 303, 304; 303, 305; 304, identifier:sum; 305, generator_expression; 305, 306; 305, 311; 306, comparison_operator:>; 306, 307; 306, 310; 307, subscript; 307, 308; 307, 309; 308, identifier:answers; 309, identifier:i; 310, integer:0; 311, for_in_clause; 311, 312; 311, 313; 312, identifier:i; 313, identifier:items; 314, pair; 314, 315; 314, 316; 315, string:"number_of_answers"; 316, call; 316, 317; 316, 318; 317, identifier:sum; 318, generator_expression; 318, 319; 318, 322; 319, subscript; 319, 320; 319, 321; 320, identifier:answers; 321, identifier:i; 322, for_in_clause; 322, 323; 322, 324; 323, identifier:i; 324, identifier:items; 325, pair; 325, 326; 325, 327; 326, string:"number_of_correct_answers"; 327, call; 327, 328; 327, 329; 328, identifier:sum; 329, generator_expression; 329, 330; 329, 333; 330, subscript; 330, 331; 330, 332; 331, identifier:correct_answers; 332, identifier:i; 333, for_in_clause; 333, 334; 333, 335; 334, identifier:i; 335, identifier:items; 336, if_statement; 336, 337; 336, 345; 337, call; 337, 338; 337, 343; 338, attribute; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:request; 341, identifier:GET; 342, identifier:get; 343, argument_list; 343, 344; 344, string:"mastered"; 345, block; 345, 346; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 353; 348, subscript; 348, 349; 348, 352; 349, subscript; 349, 350; 349, 351; 350, identifier:response; 351, identifier:identifier; 352, string:"number_of_mastered_items"; 353, call; 353, 354; 353, 355; 354, identifier:sum; 355, generator_expression; 355, 356; 355, 359; 356, subscript; 356, 357; 356, 358; 357, identifier:mastered; 358, identifier:i; 359, for_in_clause; 359, 360; 359, 361; 360, identifier:i; 361, identifier:items; 362, return_statement; 362, 363; 363, call; 363, 364; 363, 365; 364, identifier:render_json; 365, argument_list; 365, 366; 365, 367; 365, 368; 365, 371; 366, identifier:request; 367, identifier:response; 368, keyword_argument; 368, 369; 368, 370; 369, identifier:template; 370, string:'models_user_stats.html'; 371, keyword_argument; 371, 372; 371, 373; 372, identifier:help_text; 373, attribute; 373, 374; 373, 375; 374, identifier:user_stats; 375, identifier:__doc__ | def user_stats(request):
timer('user_stats')
response = {}
data = None
if request.method == "POST":
data = json.loads(request.body.decode("utf-8"))["filters"]
if "filters" in request.GET:
data = load_query_json(request.GET, "filters")
if data is None:
return render_json(request, {}, template='models_user_stats.html', help_text=user_stats.__doc__)
environment = get_environment()
if is_time_overridden(request):
environment.shift_time(get_time(request))
user_id = get_user_id(request)
language = get_language(request)
filter_names, filter_filters = list(zip(*sorted(data.items())))
reachable_leaves = Item.objects.filter_all_reachable_leaves_many(filter_filters, language)
all_leaves = sorted(list(set(flatten(reachable_leaves))))
answers = environment.number_of_answers_more_items(all_leaves, user_id)
correct_answers = environment.number_of_correct_answers_more_items(all_leaves, user_id)
if request.GET.get("mastered"):
timer('user_stats_mastered')
mastery_threshold = get_mastery_trashold()
predictions = Item.objects.predict_for_overview(environment, user_id, all_leaves)
mastered = dict(list(zip(all_leaves, [p >= mastery_threshold for p in predictions])))
LOGGER.debug("user_stats - getting predictions for items took %s seconds", (timer('user_stats_mastered')))
for identifier, items in zip(filter_names, reachable_leaves):
if len(items) == 0:
response[identifier] = {
"filter": data[identifier],
"number_of_items": 0,
}
else:
response[identifier] = {
"filter": data[identifier],
"number_of_items": len(items),
"number_of_practiced_items": sum(answers[i] > 0 for i in items),
"number_of_answers": sum(answers[i] for i in items),
"number_of_correct_answers": sum(correct_answers[i] for i in items),
}
if request.GET.get("mastered"):
response[identifier]["number_of_mastered_items"]= sum(mastered[i] for i in items)
return render_json(request, response, template='models_user_stats.html', help_text=user_stats.__doc__) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:create_resource; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:output_model; 5, identifier:rtype; 6, identifier:unique; 7, identifier:links; 8, default_parameter; 8, 9; 8, 10; 9, identifier:existing_ids; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:id_helper; 13, None; 14, block; 14, 15; 14, 17; 14, 61; 14, 82; 14, 96; 14, 117; 14, 126; 14, 141; 15, expression_statement; 15, 16; 16, string:'''
General-purpose routine to create a new resource in the output model, based on data provided
output_model - Versa connection to model to be updated
rtype - Type IRI for the new resource, set with Versa type
unique - list of key/value pairs for determining a unique hash for the new resource
links - list of key/value pairs for setting properties on the new resource
id_helper - If a string, a base URL for the generatd ID. If callable, a function used to return the entity. If None, set a default good enough for testing.
existing_ids - set of existing IDs to not recreate, or None, in which case a new resource will always be created
'''; 17, if_statement; 17, 18; 17, 23; 17, 31; 17, 42; 17, 54; 18, call; 18, 19; 18, 20; 19, identifier:isinstance; 20, argument_list; 20, 21; 20, 22; 21, identifier:id_helper; 22, identifier:str; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:idg; 27, call; 27, 28; 27, 29; 28, identifier:idgen; 29, argument_list; 29, 30; 30, identifier:id_helper; 31, elif_clause; 31, 32; 31, 37; 32, call; 32, 33; 32, 34; 33, identifier:isinstance; 34, argument_list; 34, 35; 34, 36; 35, identifier:id_helper; 36, identifier:GeneratorType; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:idg; 41, identifier:id_helper; 42, elif_clause; 42, 43; 42, 46; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:id_helper; 45, None; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:idg; 50, call; 50, 51; 50, 52; 51, identifier:default_idgen; 52, argument_list; 52, 53; 53, None; 54, else_clause; 54, 55; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:ValueError; 59, argument_list; 59, 60; 60, string:'id_helper must be string (URL), callable or None'; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:ctx; 64, call; 64, 65; 64, 66; 65, identifier:context; 66, argument_list; 66, 67; 66, 68; 66, 69; 66, 70; 66, 73; 66, 76; 66, 79; 67, None; 68, None; 69, identifier:output_model; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:base; 72, None; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:idgen; 75, identifier:idg; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:existing_ids; 78, identifier:existing_ids; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:extras; 81, None; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:rid; 85, call; 85, 86; 85, 87; 86, identifier:I; 87, argument_list; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:materialize_entity; 90, argument_list; 90, 91; 90, 92; 90, 93; 91, identifier:ctx; 92, identifier:rtype; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:unique; 95, identifier:unique; 96, if_statement; 96, 97; 96, 100; 97, comparison_operator:is; 97, 98; 97, 99; 98, identifier:existing_ids; 99, None; 100, block; 100, 101; 100, 110; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:in; 102, 103; 102, 104; 103, identifier:rid; 104, identifier:existing_ids; 105, block; 105, 106; 106, return_statement; 106, 107; 107, tuple; 107, 108; 107, 109; 108, False; 109, identifier:rid; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:existing_ids; 114, identifier:add; 115, argument_list; 115, 116; 116, identifier:rid; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:output_model; 121, identifier:add; 122, argument_list; 122, 123; 122, 124; 122, 125; 123, identifier:rid; 124, identifier:VTYPE_REL; 125, identifier:rtype; 126, for_statement; 126, 127; 126, 130; 126, 131; 127, pattern_list; 127, 128; 127, 129; 128, identifier:r; 129, identifier:t; 130, identifier:links; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:output_model; 136, identifier:add; 137, argument_list; 137, 138; 137, 139; 137, 140; 138, identifier:rid; 139, identifier:r; 140, identifier:t; 141, return_statement; 141, 142; 142, tuple; 142, 143; 142, 144; 143, True; 144, identifier:rid | def create_resource(output_model, rtype, unique, links, existing_ids=None, id_helper=None):
'''
General-purpose routine to create a new resource in the output model, based on data provided
output_model - Versa connection to model to be updated
rtype - Type IRI for the new resource, set with Versa type
unique - list of key/value pairs for determining a unique hash for the new resource
links - list of key/value pairs for setting properties on the new resource
id_helper - If a string, a base URL for the generatd ID. If callable, a function used to return the entity. If None, set a default good enough for testing.
existing_ids - set of existing IDs to not recreate, or None, in which case a new resource will always be created
'''
if isinstance(id_helper, str):
idg = idgen(id_helper)
elif isinstance(id_helper, GeneratorType):
idg = id_helper
elif id_helper is None:
idg = default_idgen(None)
else:
raise ValueError('id_helper must be string (URL), callable or None')
ctx = context(None, None, output_model, base=None, idgen=idg, existing_ids=existing_ids, extras=None)
rid = I(materialize_entity(ctx, rtype, unique=unique))
if existing_ids is not None:
if rid in existing_ids:
return (False, rid)
existing_ids.add(rid)
output_model.add(rid, VTYPE_REL, rtype)
for r, t in links:
output_model.add(rid, r, t)
return (True, rid) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:patterns; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 52; 5, 58; 5, 90; 5, 101; 5, 109; 5, 125; 6, if_statement; 6, 7; 6, 20; 7, boolean_operator:and; 7, 8; 7, 14; 8, not_operator; 8, 9; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:args; 13, identifier:patterns; 14, not_operator; 14, 15; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:args; 19, identifier:pattern_files; 20, block; 20, 21; 21, try_statement; 21, 22; 21, 43; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 32; 25, attribute; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:args; 30, identifier:patterns; 31, identifier:append; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 41; 34, attribute; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:args; 39, identifier:files; 40, identifier:pop; 41, argument_list; 41, 42; 42, integer:0; 43, except_clause; 43, 44; 43, 45; 44, identifier:IndexError; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:LogRaptorArgumentError; 49, argument_list; 49, 50; 49, 51; 50, string:'PATTERN'; 51, string:'no search pattern'; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:patterns; 55, call; 55, 56; 55, 57; 56, identifier:set; 57, argument_list; 58, if_statement; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:args; 63, identifier:pattern_files; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:patterns; 69, identifier:update; 70, argument_list; 70, 71; 71, list_comprehension; 71, 72; 71, 78; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:p; 75, identifier:rstrip; 76, argument_list; 76, 77; 77, string:'\n'; 78, for_in_clause; 78, 79; 78, 80; 79, identifier:p; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:fileinput; 83, identifier:input; 84, argument_list; 84, 85; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:args; 89, identifier:pattern_files; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:patterns; 94, identifier:update; 95, argument_list; 95, 96; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:args; 100, identifier:patterns; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:logger; 105, identifier:debug; 106, argument_list; 106, 107; 106, 108; 107, string:"search patterns to be processed: %r"; 108, identifier:patterns; 109, if_statement; 109, 110; 109, 113; 110, comparison_operator:in; 110, 111; 110, 112; 111, string:''; 112, identifier:patterns; 113, block; 113, 114; 113, 121; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:logger; 118, identifier:info; 119, argument_list; 119, 120; 120, string:"an empty pattern provided: match all strings!"; 121, return_statement; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:tuple; 124, argument_list; 125, try_statement; 125, 126; 125, 174; 126, block; 126, 127; 126, 144; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:flags; 130, conditional_expression:if; 130, 131; 130, 134; 130, 139; 131, attribute; 131, 132; 131, 133; 132, identifier:re; 133, identifier:IGNORECASE; 134, attribute; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:args; 138, identifier:case; 139, binary_operator:|; 139, 140; 139, 141; 140, integer:0; 141, attribute; 141, 142; 141, 143; 142, identifier:re; 143, identifier:UNICODE; 144, return_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:tuple; 147, argument_list; 147, 148; 148, list_comprehension; 148, 149; 148, 169; 148, 172; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:re; 152, identifier:compile; 153, argument_list; 153, 154; 153, 166; 154, conditional_expression:if; 154, 155; 154, 158; 154, 163; 155, binary_operator:%; 155, 156; 155, 157; 156, string:r'(\b%s\b)'; 157, identifier:pat; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:args; 162, identifier:word; 163, binary_operator:%; 163, 164; 163, 165; 164, string:'(%s)'; 165, identifier:pat; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:flags; 168, identifier:flags; 169, for_in_clause; 169, 170; 169, 171; 170, identifier:pat; 171, identifier:patterns; 172, if_clause; 172, 173; 173, identifier:pat; 174, except_clause; 174, 175; 174, 181; 175, as_pattern; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:re; 178, identifier:error; 179, as_pattern_target; 179, 180; 180, identifier:err; 181, block; 181, 182; 182, raise_statement; 182, 183; 183, call; 183, 184; 183, 185; 184, identifier:LogRaptorArgumentError; 185, argument_list; 185, 186; 186, binary_operator:%; 186, 187; 186, 188; 187, string:'wrong regex syntax for pattern: %r'; 188, identifier:err | def patterns(self):
if not self.args.patterns and not self.args.pattern_files:
try:
self.args.patterns.append(self.args.files.pop(0))
except IndexError:
raise LogRaptorArgumentError('PATTERN', 'no search pattern')
patterns = set()
if self.args.pattern_files:
patterns.update([p.rstrip('\n') for p in fileinput.input(self.args.pattern_files)])
patterns.update(self.args.patterns)
logger.debug("search patterns to be processed: %r", patterns)
if '' in patterns:
logger.info("an empty pattern provided: match all strings!")
return tuple()
try:
flags = re.IGNORECASE if self.args.case else 0 | re.UNICODE
return tuple([
re.compile(r'(\b%s\b)' % pat if self.args.word else '(%s)' % pat, flags=flags)
for pat in patterns if pat
])
except re.error as err:
raise LogRaptorArgumentError('wrong regex syntax for pattern: %r' % err) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:qualify; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:qualification; 5, identifier:value; 6, identifier:worker; 7, block; 7, 8; 7, 15; 7, 21; 7, 27; 7, 37; 7, 47; 7, 55; 7, 121; 7, 128; 7, 138; 7, 152; 7, 181; 7, 191; 7, 198; 7, 214; 7, 224; 7, 240; 8, import_from_statement; 8, 9; 8, 13; 9, dotted_name; 9, 10; 9, 11; 9, 12; 10, identifier:boto; 11, identifier:mturk; 12, identifier:connection; 13, dotted_name; 13, 14; 14, identifier:MTurkConnection; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:config; 18, call; 18, 19; 18, 20; 19, identifier:PsiturkConfig; 20, argument_list; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:config; 25, identifier:load_config; 26, argument_list; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:aws_access_key_id; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:config; 33, identifier:get; 34, argument_list; 34, 35; 34, 36; 35, string:'AWS Access'; 36, string:'aws_access_key_id'; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:aws_secret_access_key; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:config; 43, identifier:get; 44, argument_list; 44, 45; 44, 46; 45, string:'AWS Access'; 46, string:'aws_secret_access_key'; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:conn; 50, call; 50, 51; 50, 52; 51, identifier:MTurkConnection; 52, argument_list; 52, 53; 52, 54; 53, identifier:aws_access_key_id; 54, identifier:aws_secret_access_key; 55, function_definition; 55, 56; 55, 57; 55, 59; 56, function_name:get_workers_with_qualification; 57, parameters; 57, 58; 58, identifier:qualification; 59, block; 59, 60; 59, 64; 59, 68; 59, 72; 59, 119; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:results; 63, list:[]; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:continue_flag; 67, True; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:page; 71, integer:1; 72, while_statement; 72, 73; 72, 75; 73, parenthesized_expression; 73, 74; 74, identifier:continue_flag; 75, block; 75, 76; 75, 91; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:new_results; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:conn; 82, identifier:get_qualifications_for_qualification_type; 83, argument_list; 83, 84; 83, 85; 83, 88; 84, identifier:qualification; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:page_size; 87, integer:100; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:page_number; 90, identifier:page; 91, if_statement; 91, 92; 91, 99; 91, 104; 92, parenthesized_expression; 92, 93; 93, comparison_operator:==; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, identifier:new_results; 98, integer:0; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:continue_flag; 103, False; 104, else_clause; 104, 105; 105, block; 105, 106; 105, 113; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:results; 110, identifier:extend; 111, argument_list; 111, 112; 112, identifier:new_results; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:page; 116, binary_operator:+; 116, 117; 116, 118; 117, identifier:page; 118, integer:1; 119, return_statement; 119, 120; 120, identifier:results; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:results; 124, call; 124, 125; 124, 126; 125, identifier:get_workers_with_qualification; 126, argument_list; 126, 127; 127, identifier:qualification; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:workers; 131, list_comprehension; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:x; 134, identifier:SubjectId; 135, for_in_clause; 135, 136; 135, 137; 136, identifier:x; 137, identifier:results; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:click; 142, identifier:echo; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, string:"Assigning qualification {} with value {} to worker {}"; 147, identifier:format; 148, argument_list; 148, 149; 148, 150; 148, 151; 149, identifier:qualification; 150, identifier:value; 151, identifier:worker; 152, if_statement; 152, 153; 152, 156; 152, 168; 153, comparison_operator:in; 153, 154; 153, 155; 154, identifier:worker; 155, identifier:workers; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:result; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:conn; 163, identifier:update_qualification_score; 164, argument_list; 164, 165; 164, 166; 164, 167; 165, identifier:qualification; 166, identifier:worker; 167, identifier:value; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:result; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:conn; 176, identifier:assign_qualification; 177, argument_list; 177, 178; 177, 179; 177, 180; 178, identifier:qualification; 179, identifier:worker; 180, identifier:value; 181, if_statement; 181, 182; 181, 183; 182, identifier:result; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:click; 188, identifier:echo; 189, argument_list; 189, 190; 190, identifier:result; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:results; 194, call; 194, 195; 194, 196; 195, identifier:get_workers_with_qualification; 196, argument_list; 196, 197; 197, identifier:qualification; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:click; 202, identifier:echo; 203, argument_list; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, string:"{} workers with qualification {}:"; 207, identifier:format; 208, argument_list; 208, 209; 208, 213; 209, call; 209, 210; 209, 211; 210, identifier:len; 211, argument_list; 211, 212; 212, identifier:results; 213, identifier:qualification; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:values; 217, list_comprehension; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:r; 220, identifier:IntegerValue; 221, for_in_clause; 221, 222; 221, 223; 222, identifier:r; 223, identifier:results; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:unique_values; 227, call; 227, 228; 227, 229; 228, identifier:list; 229, argument_list; 229, 230; 230, call; 230, 231; 230, 232; 231, identifier:set; 232, argument_list; 232, 233; 233, list_comprehension; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:r; 236, identifier:IntegerValue; 237, for_in_clause; 237, 238; 237, 239; 238, identifier:r; 239, identifier:results; 240, for_statement; 240, 241; 240, 242; 240, 243; 241, identifier:v; 242, identifier:unique_values; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:click; 248, identifier:echo; 249, argument_list; 249, 250; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, string:"{} with value {}"; 253, identifier:format; 254, argument_list; 254, 255; 254, 267; 255, call; 255, 256; 255, 257; 256, identifier:len; 257, argument_list; 257, 258; 258, list_comprehension; 258, 259; 258, 260; 258, 263; 259, identifier:val; 260, for_in_clause; 260, 261; 260, 262; 261, identifier:val; 262, identifier:values; 263, if_clause; 263, 264; 264, comparison_operator:==; 264, 265; 264, 266; 265, identifier:val; 266, identifier:v; 267, identifier:v | def qualify(qualification, value, worker):
from boto.mturk.connection import MTurkConnection
config = PsiturkConfig()
config.load_config()
aws_access_key_id = config.get('AWS Access', 'aws_access_key_id')
aws_secret_access_key = config.get('AWS Access', 'aws_secret_access_key')
conn = MTurkConnection(aws_access_key_id, aws_secret_access_key)
def get_workers_with_qualification(qualification):
results = []
continue_flag = True
page = 1
while(continue_flag):
new_results = conn.get_qualifications_for_qualification_type(
qualification,
page_size=100,
page_number=page)
if(len(new_results) == 0):
continue_flag = False
else:
results.extend(new_results)
page = page + 1
return results
results = get_workers_with_qualification(qualification)
workers = [x.SubjectId for x in results]
click.echo(
"Assigning qualification {} with value {} to worker {}".format(
qualification,
value,
worker))
if worker in workers:
result = conn.update_qualification_score(qualification, worker, value)
else:
result = conn.assign_qualification(qualification, worker, value)
if result:
click.echo(result)
results = get_workers_with_qualification(qualification)
click.echo("{} workers with qualification {}:".format(
len(results),
qualification))
values = [r.IntegerValue for r in results]
unique_values = list(set([r.IntegerValue for r in results]))
for v in unique_values:
click.echo("{} with value {}".format(
len([val for val in values if val == v]),
v)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:setup_jobs; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:outpath; 5, identifier:options; 6, identifier:input_files; 7, block; 7, 8; 7, 10; 7, 14; 7, 18; 7, 22; 7, 142; 7, 153; 7, 161; 7, 169; 7, 173; 7, 209; 7, 220; 7, 255; 7, 286; 7, 301; 7, 338; 8, expression_statement; 8, 9; 9, string:''' This function sets up the jobs by creating the necessary input files as expected.
- outpath is where the output is to be stored.
- options is the optparse options object.
- input_files is a list of paths to input files.
'''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:job_inputs; 13, None; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:reverse_mapping; 17, None; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:fasta_file_contents; 21, dictionary; 22, for_statement; 22, 23; 22, 24; 22, 25; 23, identifier:input_file; 24, identifier:input_files; 25, block; 25, 26; 25, 36; 26, assert_statement; 26, 27; 27, parenthesized_expression; 27, 28; 28, not_operator; 28, 29; 29, parenthesized_expression; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:fasta_file_contents; 33, identifier:get; 34, argument_list; 34, 35; 35, identifier:input_file; 36, if_statement; 36, 37; 36, 48; 36, 129; 37, call; 37, 38; 37, 39; 38, identifier:any; 39, generator_expression; 39, 40; 39, 45; 40, call; 40, 41; 40, 42; 41, identifier:fnmatch; 42, argument_list; 42, 43; 42, 44; 43, identifier:input_file; 44, identifier:x; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:x; 47, identifier:pdb_file_wildcards; 48, block; 48, 49; 48, 61; 48, 81; 48, 114; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:pdb; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:PDB; 55, identifier:from_filepath; 56, argument_list; 56, 57; 56, 58; 57, identifier:input_file; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:strict; 60, True; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:pdb; 65, identifier:pdb_id; 66, subscript; 66, 67; 66, 80; 67, call; 67, 68; 67, 78; 68, attribute; 68, 69; 68, 77; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:os; 73, identifier:path; 74, identifier:basename; 75, argument_list; 75, 76; 76, identifier:input_file; 77, identifier:split; 78, argument_list; 78, 79; 79, string:'.'; 80, integer:0; 81, if_statement; 81, 82; 81, 99; 82, boolean_operator:and; 82, 83; 82, 91; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:pdb; 87, identifier:pdb_id; 88, identifier:startswith; 89, argument_list; 89, 90; 90, string:'pdb'; 91, comparison_operator:>=; 91, 92; 91, 98; 92, call; 92, 93; 92, 94; 93, identifier:len; 94, argument_list; 94, 95; 95, attribute; 95, 96; 95, 97; 96, identifier:pdb; 97, identifier:pdb_id; 98, integer:7; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:pdb; 104, identifier:pdb_id; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:pdb; 109, identifier:pdb_id; 110, identifier:replace; 111, argument_list; 111, 112; 111, 113; 112, string:'pdb'; 113, string:''; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:fasta_file_contents; 118, identifier:input_file; 119, tuple; 119, 120; 119, 128; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:pdb; 123, identifier:create_fasta; 124, argument_list; 124, 125; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:prefer_seqres_order; 127, False; 128, string:'PDB'; 129, else_clause; 129, 130; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:fasta_file_contents; 135, identifier:input_file; 136, tuple; 136, 137; 136, 141; 137, call; 137, 138; 137, 139; 138, identifier:read_file; 139, argument_list; 139, 140; 140, identifier:input_file; 141, string:'FASTA'; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 148; 144, pattern_list; 144, 145; 144, 146; 144, 147; 145, identifier:found_sequences; 146, identifier:reverse_mapping; 147, identifier:errors; 148, call; 148, 149; 148, 150; 149, identifier:get_sequences; 150, argument_list; 150, 151; 150, 152; 151, identifier:options; 152, identifier:fasta_file_contents; 153, if_statement; 153, 154; 153, 155; 154, identifier:found_sequences; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:reformat; 159, argument_list; 159, 160; 160, identifier:found_sequences; 161, if_statement; 161, 162; 161, 163; 162, identifier:errors; 163, block; 163, 164; 164, return_statement; 164, 165; 165, expression_list; 165, 166; 165, 167; 165, 168; 166, None; 167, False; 168, identifier:errors; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:desired_sequences; 172, dictionary; 173, for_statement; 173, 174; 173, 177; 173, 182; 174, pattern_list; 174, 175; 174, 176; 175, identifier:key; 176, identifier:sequence; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:found_sequences; 180, identifier:iteritems; 181, argument_list; 182, block; 182, 183; 182, 190; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 189; 185, pattern_list; 185, 186; 185, 187; 185, 188; 186, identifier:pdb_id; 187, identifier:chain; 188, identifier:file_name; 189, identifier:key; 190, if_statement; 190, 191; 190, 202; 191, boolean_operator:or; 191, 192; 191, 197; 192, comparison_operator:is; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:options; 195, identifier:chain; 196, None; 197, comparison_operator:==; 197, 198; 197, 199; 198, identifier:chain; 199, attribute; 199, 200; 199, 201; 200, identifier:options; 201, identifier:chain; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, subscript; 205, 206; 205, 207; 206, identifier:desired_sequences; 207, identifier:key; 208, identifier:sequence; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, pattern_list; 211, 212; 211, 213; 212, identifier:job_inputs; 213, identifier:errors; 214, call; 214, 215; 214, 216; 215, identifier:create_inputs; 216, argument_list; 216, 217; 216, 218; 216, 219; 217, identifier:options; 218, identifier:outpath; 219, identifier:desired_sequences; 220, if_statement; 220, 221; 220, 222; 221, identifier:reverse_mapping; 222, block; 222, 223; 222, 235; 222, 244; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:segment_mapping_file; 226, call; 226, 227; 226, 232; 227, attribute; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:os; 230, identifier:path; 231, identifier:join; 232, argument_list; 232, 233; 232, 234; 233, identifier:outpath; 234, string:"segment_map.json"; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:colorprinter; 239, identifier:message; 240, argument_list; 240, 241; 241, binary_operator:%; 241, 242; 241, 243; 242, string:"Creating a reverse mapping file %s."; 243, identifier:segment_mapping_file; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:write_file; 247, argument_list; 247, 248; 247, 249; 248, identifier:segment_mapping_file; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:json; 252, identifier:dumps; 253, argument_list; 253, 254; 254, identifier:reverse_mapping; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:post_processing_script; 258, call; 258, 259; 258, 260; 259, identifier:read_file; 260, argument_list; 260, 261; 261, call; 261, 262; 261, 267; 262, attribute; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:os; 265, identifier:path; 266, identifier:join; 267, argument_list; 267, 268; 267, 285; 268, subscript; 268, 269; 268, 284; 269, call; 269, 270; 269, 275; 270, attribute; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:os; 273, identifier:path; 274, identifier:split; 275, argument_list; 275, 276; 276, call; 276, 277; 276, 282; 277, attribute; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:os; 280, identifier:path; 281, identifier:realpath; 282, argument_list; 282, 283; 283, identifier:__file__; 284, integer:0; 285, string:'post_processing.py'; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 289; 288, identifier:write_file; 289, argument_list; 289, 290; 289, 299; 289, 300; 290, call; 290, 291; 290, 296; 291, attribute; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:os; 294, identifier:path; 295, identifier:join; 296, argument_list; 296, 297; 296, 298; 297, identifier:outpath; 298, string:'post_processing.py'; 299, identifier:post_processing_script; 300, string:'w'; 301, if_statement; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:options; 304, identifier:secondary_structure_file; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 309; 308, identifier:write_file; 309, argument_list; 309, 310; 309, 319; 309, 337; 310, call; 310, 311; 310, 316; 311, attribute; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:os; 314, identifier:path; 315, identifier:join; 316, argument_list; 316, 317; 316, 318; 317, identifier:outpath; 318, string:'ss_filter.json'; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:json; 322, identifier:dumps; 323, argument_list; 323, 324; 324, dictionary; 324, 325; 325, pair; 325, 326; 325, 327; 326, string:'secondary_structure_filter'; 327, attribute; 327, 328; 327, 336; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:SecondaryStructureDefinition; 331, identifier:from_filepath; 332, argument_list; 332, 333; 333, attribute; 333, 334; 333, 335; 334, identifier:options; 335, identifier:secondary_structure_file; 336, identifier:data; 337, string:'w'; 338, return_statement; 338, 339; 339, expression_list; 339, 340; 339, 341; 339, 344; 340, identifier:job_inputs; 341, comparison_operator:!=; 341, 342; 341, 343; 342, identifier:reverse_mapping; 343, None; 344, identifier:errors | def setup_jobs(outpath, options, input_files):
''' This function sets up the jobs by creating the necessary input files as expected.
- outpath is where the output is to be stored.
- options is the optparse options object.
- input_files is a list of paths to input files.
'''
job_inputs = None
reverse_mapping = None
fasta_file_contents = {}
for input_file in input_files:
assert(not(fasta_file_contents.get(input_file)))
if any(fnmatch(input_file, x) for x in pdb_file_wildcards):
pdb = PDB.from_filepath(input_file, strict=True)
pdb.pdb_id = os.path.basename(input_file).split('.')[0]
if pdb.pdb_id.startswith('pdb') and len(pdb.pdb_id) >= 7:
pdb.pdb_id = pdb.pdb_id.replace('pdb', '')
fasta_file_contents[input_file] = (pdb.create_fasta(prefer_seqres_order = False), 'PDB')
else:
fasta_file_contents[input_file] = (read_file(input_file), 'FASTA')
found_sequences, reverse_mapping, errors = get_sequences(options, fasta_file_contents)
if found_sequences:
reformat(found_sequences)
if errors:
return None, False, errors
desired_sequences = {}
for key, sequence in found_sequences.iteritems():
pdb_id, chain, file_name = key
if options.chain is None or chain == options.chain:
desired_sequences[key] = sequence
job_inputs, errors = create_inputs(options, outpath, desired_sequences)
if reverse_mapping:
segment_mapping_file = os.path.join(outpath, "segment_map.json")
colorprinter.message("Creating a reverse mapping file %s." % segment_mapping_file)
write_file(segment_mapping_file, json.dumps(reverse_mapping))
post_processing_script = read_file(os.path.join(os.path.split(os.path.realpath(__file__))[0], 'post_processing.py'))
write_file(os.path.join(outpath, 'post_processing.py'), post_processing_script, 'w')
if options.secondary_structure_file:
write_file(os.path.join(outpath, 'ss_filter.json'), json.dumps({'secondary_structure_filter' : SecondaryStructureDefinition.from_filepath(options.secondary_structure_file).data}), 'w')
return job_inputs, reverse_mapping != None, errors |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:load_stdlib; 3, parameters; 4, block; 4, 5; 4, 7; 4, 12; 4, 49; 4, 74; 4, 96; 4, 105; 4, 192; 5, expression_statement; 5, 6; 6, string:'''Scans sys.path for standard library modules.
'''; 7, if_statement; 7, 8; 7, 9; 8, identifier:_stdlib; 9, block; 9, 10; 10, return_statement; 10, 11; 11, identifier:_stdlib; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:prefixes; 15, call; 15, 16; 15, 17; 16, identifier:tuple; 17, argument_list; 17, 18; 18, set_comprehension; 18, 19; 18, 27; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:os; 23, identifier:path; 24, identifier:abspath; 25, argument_list; 25, 26; 26, identifier:p; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:p; 29, tuple; 29, 30; 29, 33; 29, 41; 30, attribute; 30, 31; 30, 32; 31, identifier:sys; 32, identifier:prefix; 33, call; 33, 34; 33, 35; 34, identifier:getattr; 35, argument_list; 35, 36; 35, 37; 35, 38; 36, identifier:sys; 37, string:'real_prefix'; 38, attribute; 38, 39; 38, 40; 39, identifier:sys; 40, identifier:prefix; 41, call; 41, 42; 41, 43; 42, identifier:getattr; 43, argument_list; 43, 44; 43, 45; 43, 46; 44, identifier:sys; 45, string:'base_prefix'; 46, attribute; 46, 47; 46, 48; 47, identifier:sys; 48, identifier:prefix; 49, for_statement; 49, 50; 49, 51; 49, 54; 50, identifier:sp; 51, attribute; 51, 52; 51, 53; 52, identifier:sys; 53, identifier:path; 54, block; 54, 55; 54, 60; 55, if_statement; 55, 56; 55, 58; 56, not_operator; 56, 57; 57, identifier:sp; 58, block; 58, 59; 59, continue_statement; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:_import_paths; 64, identifier:append; 65, argument_list; 65, 66; 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:abspath; 72, argument_list; 72, 73; 73, identifier:sp; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:stdpaths; 77, call; 77, 78; 77, 79; 78, identifier:tuple; 79, argument_list; 79, 80; 80, set_comprehension; 80, 81; 80, 82; 80, 85; 81, identifier:p; 82, for_in_clause; 82, 83; 82, 84; 83, identifier:p; 84, identifier:_import_paths; 85, if_clause; 85, 86; 86, boolean_operator:and; 86, 87; 86, 93; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:p; 90, identifier:startswith; 91, argument_list; 91, 92; 92, identifier:prefixes; 93, comparison_operator:not; 93, 94; 93, 95; 94, string:'site-packages'; 95, identifier:p; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:_stdlib; 100, identifier:update; 101, argument_list; 101, 102; 102, attribute; 102, 103; 102, 104; 103, identifier:sys; 104, identifier:builtin_module_names; 105, for_statement; 105, 106; 105, 107; 105, 108; 106, identifier:stdpath; 107, identifier:stdpaths; 108, block; 108, 109; 108, 121; 109, if_statement; 109, 110; 109, 119; 110, not_operator; 110, 111; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:os; 115, identifier:path; 116, identifier:isdir; 117, argument_list; 117, 118; 118, identifier:stdpath; 119, block; 119, 120; 120, continue_statement; 121, for_statement; 121, 122; 121, 123; 121, 129; 122, identifier:item; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:os; 126, identifier:listdir; 127, argument_list; 127, 128; 128, identifier:stdpath; 129, block; 129, 130; 129, 143; 129, 155; 129, 177; 130, if_statement; 130, 131; 130, 141; 131, boolean_operator:or; 131, 132; 131, 138; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:item; 135, identifier:startswith; 136, argument_list; 136, 137; 137, string:'.'; 138, comparison_operator:==; 138, 139; 138, 140; 139, identifier:item; 140, string:'site-packages'; 141, block; 141, 142; 142, continue_statement; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:p; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:os; 150, identifier:path; 151, identifier:join; 152, argument_list; 152, 153; 152, 154; 153, identifier:stdpath; 154, identifier:item; 155, if_statement; 155, 156; 155, 175; 156, boolean_operator:and; 156, 157; 156, 166; 157, not_operator; 157, 158; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:os; 162, identifier:path; 163, identifier:isdir; 164, argument_list; 164, 165; 165, identifier:p; 166, not_operator; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:item; 170, identifier:endswith; 171, argument_list; 171, 172; 172, tuple; 172, 173; 172, 174; 173, string:'.py'; 174, string:'.so'; 175, block; 175, 176; 176, continue_statement; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:_stdlib; 181, identifier:add; 182, argument_list; 182, 183; 183, subscript; 183, 184; 183, 191; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:item; 187, identifier:split; 188, argument_list; 188, 189; 188, 190; 189, string:'.'; 190, integer:1; 191, integer:0; 192, return_statement; 192, 193; 193, identifier:_stdlib | def load_stdlib():
'''Scans sys.path for standard library modules.
'''
if _stdlib:
return _stdlib
prefixes = tuple({os.path.abspath(p) for p in (
sys.prefix,
getattr(sys, 'real_prefix', sys.prefix),
getattr(sys, 'base_prefix', sys.prefix),
)})
for sp in sys.path:
if not sp:
continue
_import_paths.append(os.path.abspath(sp))
stdpaths = tuple({p for p in _import_paths
if p.startswith(prefixes) and 'site-packages' not in p})
_stdlib.update(sys.builtin_module_names)
for stdpath in stdpaths:
if not os.path.isdir(stdpath):
continue
for item in os.listdir(stdpath):
if item.startswith('.') or item == 'site-packages':
continue
p = os.path.join(stdpath, item)
if not os.path.isdir(p) and not item.endswith(('.py', '.so')):
continue
_stdlib.add(item.split('.', 1)[0])
return _stdlib |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:is_python_script; 3, parameters; 3, 4; 4, identifier:filename; 5, block; 5, 6; 5, 8; 5, 22; 5, 35; 5, 78; 6, expression_statement; 6, 7; 7, string:'''Checks a file to see if it's a python script of some sort.
'''; 8, if_statement; 8, 9; 8, 19; 9, call; 9, 10; 9, 17; 10, attribute; 10, 11; 10, 16; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:filename; 14, identifier:lower; 15, argument_list; 16, identifier:endswith; 17, argument_list; 17, 18; 18, string:'.py'; 19, block; 19, 20; 20, return_statement; 20, 21; 21, True; 22, if_statement; 22, 23; 22, 32; 23, not_operator; 23, 24; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:os; 28, identifier:path; 29, identifier:isfile; 30, argument_list; 30, 31; 31, identifier:filename; 32, block; 32, 33; 33, return_statement; 33, 34; 34, False; 35, try_statement; 35, 36; 35, 74; 36, block; 36, 37; 37, with_statement; 37, 38; 37, 48; 37, 73; 38, with_clause; 38, 39; 39, with_item; 39, 40; 40, as_pattern; 40, 41; 40, 46; 41, call; 41, 42; 41, 43; 42, identifier:open; 43, argument_list; 43, 44; 43, 45; 44, identifier:filename; 45, string:'rb'; 46, as_pattern_target; 46, 47; 47, identifier:fp; 48, ERROR; 48, 49; 49, comparison_operator:!=; 49, 50; 49, 56; 49, 59; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:fp; 53, identifier:read; 54, argument_list; 54, 55; 55, integer:2; 56, ERROR; 56, 57; 56, 58; 57, identifier:return; 58, False; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:re; 62, identifier:match; 63, argument_list; 63, 64; 63, 65; 64, string:r'.*python'; 65, call; 65, 66; 65, 67; 66, identifier:str_; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:fp; 71, identifier:readline; 72, argument_list; 73, block:; 74, except_clause; 74, 75; 74, 76; 75, identifier:IOError; 76, block; 76, 77; 77, pass_statement; 78, return_statement; 78, 79; 79, False | def is_python_script(filename):
'''Checks a file to see if it's a python script of some sort.
'''
if filename.lower().endswith('.py'):
return True
if not os.path.isfile(filename):
return False
try:
with open(filename, 'rb') as fp:
if fp.read(2) != b'
return False
return re.match(r'.*python', str_(fp.readline()))
except IOError:
pass
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:fit; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:dataset; 5, default_parameter; 5, 6; 5, 7; 6, identifier:alpha; 7, float:1e-8; 8, default_parameter; 8, 9; 8, 10; 9, identifier:max_iterations; 10, integer:10; 11, default_parameter; 11, 12; 11, 13; 12, identifier:save_results; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:show; 16, False; 17, block; 17, 18; 17, 28; 17, 36; 17, 41; 17, 55; 17, 89; 17, 107; 17, 112; 17, 280; 18, import_from_statement; 18, 19; 18, 24; 18, 26; 19, dotted_name; 19, 20; 19, 21; 19, 22; 19, 23; 20, identifier:disco; 21, identifier:worker; 22, identifier:pipeline; 23, identifier:worker; 24, dotted_name; 24, 25; 25, identifier:Worker; 26, dotted_name; 26, 27; 27, identifier:Stage; 28, import_from_statement; 28, 29; 28, 32; 28, 34; 29, dotted_name; 29, 30; 29, 31; 30, identifier:disco; 31, identifier:core; 32, dotted_name; 32, 33; 33, identifier:Job; 34, dotted_name; 34, 35; 35, identifier:result_iterator; 36, import_statement; 36, 37; 37, aliased_import; 37, 38; 37, 40; 38, dotted_name; 38, 39; 39, identifier:numpy; 40, identifier:np; 41, if_statement; 41, 42; 41, 49; 42, comparison_operator:==; 42, 43; 42, 48; 43, subscript; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:dataset; 46, identifier:params; 47, string:"y_map"; 48, list:[]; 49, block; 49, 50; 50, raise_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:Exception; 53, argument_list; 53, 54; 54, string:"Logistic regression requires a target label mapping parameter."; 55, try_statement; 55, 56; 55, 81; 56, block; 56, 57; 56, 64; 56, 71; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:alpha; 60, call; 60, 61; 60, 62; 61, identifier:float; 62, argument_list; 62, 63; 63, identifier:alpha; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:max_iterations; 67, call; 67, 68; 67, 69; 68, identifier:int; 69, argument_list; 69, 70; 70, identifier:max_iterations; 71, if_statement; 71, 72; 71, 75; 72, comparison_operator:<; 72, 73; 72, 74; 73, identifier:max_iterations; 74, integer:1; 75, block; 75, 76; 76, raise_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:Exception; 79, argument_list; 79, 80; 80, string:"Parameter max_iterations should be greater than 0."; 81, except_clause; 81, 82; 81, 83; 82, identifier:ValueError; 83, block; 83, 84; 84, raise_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:Exception; 87, argument_list; 87, 88; 88, string:"Parameters should be numerical."; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:thetas; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:np; 95, identifier:zeros; 96, argument_list; 96, 97; 97, binary_operator:+; 97, 98; 97, 106; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, subscript; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:dataset; 104, identifier:params; 105, string:"X_indices"; 106, integer:1; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:J; 110, list:[0]; 110, 111; 111, integer:0; 112, for_statement; 112, 113; 112, 114; 112, 118; 113, identifier:i; 114, call; 114, 115; 114, 116; 115, identifier:range; 116, argument_list; 116, 117; 117, identifier:max_iterations; 118, block; 118, 119; 118, 133; 118, 173; 118, 181; 118, 189; 118, 210; 118, 221; 118, 248; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:job; 122, call; 122, 123; 122, 124; 123, identifier:Job; 124, argument_list; 124, 125; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:worker; 127, call; 127, 128; 127, 129; 128, identifier:Worker; 129, argument_list; 129, 130; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:save_results; 132, identifier:save_results; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:job; 137, identifier:pipeline; 138, list:[
("split", Stage("map", input_chain=dataset.params["input_chain"], init=simple_init, process=map_fit)),
('group_all', Stage("reduce", init=simple_init, process=reduce_fit, combine=True))]; 138, 139; 138, 158; 139, tuple; 139, 140; 139, 141; 140, string:"split"; 141, call; 141, 142; 141, 143; 142, identifier:Stage; 143, argument_list; 143, 144; 143, 145; 143, 152; 143, 155; 144, string:"map"; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:input_chain; 147, subscript; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:dataset; 150, identifier:params; 151, string:"input_chain"; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:init; 154, identifier:simple_init; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:process; 157, identifier:map_fit; 158, tuple; 158, 159; 158, 160; 159, string:'group_all'; 160, call; 160, 161; 160, 162; 161, identifier:Stage; 162, argument_list; 162, 163; 162, 164; 162, 167; 162, 170; 163, string:"reduce"; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:init; 166, identifier:simple_init; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:process; 169, identifier:reduce_fit; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:combine; 172, True; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:job; 177, identifier:params; 178, attribute; 178, 179; 178, 180; 179, identifier:dataset; 180, identifier:params; 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:job; 186, identifier:params; 187, string:"thetas"; 188, identifier:thetas; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:job; 193, identifier:run; 194, argument_list; 194, 195; 194, 203; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:name; 197, binary_operator:%; 197, 198; 197, 199; 198, string:"logreg_fit_iter_%d"; 199, parenthesized_expression; 199, 200; 200, binary_operator:+; 200, 201; 200, 202; 201, identifier:i; 202, integer:1; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:input; 205, subscript; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:dataset; 208, identifier:params; 209, string:"data_tag"; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:fitmodel_url; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:job; 216, identifier:wait; 217, argument_list; 217, 218; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:show; 220, identifier:show; 221, for_statement; 221, 222; 221, 225; 221, 229; 222, pattern_list; 222, 223; 222, 224; 223, identifier:k; 224, identifier:v; 225, call; 225, 226; 225, 227; 226, identifier:result_iterator; 227, argument_list; 227, 228; 228, identifier:fitmodel_url; 229, block; 229, 230; 230, if_statement; 230, 231; 230, 234; 230, 242; 231, comparison_operator:==; 231, 232; 231, 233; 232, identifier:k; 233, string:"J"; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:J; 239, identifier:append; 240, argument_list; 240, 241; 241, identifier:v; 242, else_clause; 242, 243; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:thetas; 247, identifier:v; 248, if_statement; 248, 249; 248, 265; 249, comparison_operator:<; 249, 250; 249, 264; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:np; 253, identifier:abs; 254, argument_list; 254, 255; 255, binary_operator:-; 255, 256; 255, 260; 256, subscript; 256, 257; 256, 258; 257, identifier:J; 258, unary_operator:-; 258, 259; 259, integer:2; 260, subscript; 260, 261; 260, 262; 261, identifier:J; 262, unary_operator:-; 262, 263; 263, integer:1; 264, identifier:alpha; 265, block; 265, 266; 265, 279; 266, if_statement; 266, 267; 266, 268; 267, identifier:show; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 272; 271, identifier:print; 272, argument_list; 272, 273; 273, binary_operator:%; 273, 274; 273, 275; 274, string:"Converged at iteration %d"; 275, parenthesized_expression; 275, 276; 276, binary_operator:+; 276, 277; 276, 278; 277, identifier:i; 278, integer:1; 279, break_statement; 280, return_statement; 280, 281; 281, dictionary; 281, 282; 282, pair; 282, 283; 282, 284; 283, string:"logreg_fitmodel"; 284, identifier:fitmodel_url | def fit(dataset, alpha=1e-8, max_iterations=10, save_results=True, show=False):
from disco.worker.pipeline.worker import Worker, Stage
from disco.core import Job, result_iterator
import numpy as np
if dataset.params["y_map"] == []:
raise Exception("Logistic regression requires a target label mapping parameter.")
try:
alpha = float(alpha)
max_iterations = int(max_iterations)
if max_iterations < 1:
raise Exception("Parameter max_iterations should be greater than 0.")
except ValueError:
raise Exception("Parameters should be numerical.")
thetas = np.zeros(len(dataset.params["X_indices"]) + 1)
J = [0]
for i in range(max_iterations):
job = Job(worker=Worker(save_results=save_results))
job.pipeline = [
("split", Stage("map", input_chain=dataset.params["input_chain"], init=simple_init, process=map_fit)),
('group_all', Stage("reduce", init=simple_init, process=reduce_fit, combine=True))]
job.params = dataset.params
job.params["thetas"] = thetas
job.run(name="logreg_fit_iter_%d" % (i + 1), input=dataset.params["data_tag"])
fitmodel_url = job.wait(show=show)
for k, v in result_iterator(fitmodel_url):
if k == "J":
J.append(v)
else:
thetas = v
if np.abs(J[-2] - J[-1]) < alpha:
if show:
print("Converged at iteration %d" % (i + 1))
break
return {"logreg_fitmodel": fitmodel_url} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:draw_image; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:image; 6, default_parameter; 6, 7; 6, 8; 7, identifier:xmin; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:ymin; 11, integer:0; 12, default_parameter; 12, 13; 12, 14; 13, identifier:xmax; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:ymax; 17, None; 18, block; 18, 19; 18, 34; 18, 49; 18, 73; 18, 93; 18, 113; 18, 133; 18, 153; 18, 161; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:xmax; 22, None; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:xmax; 27, binary_operator:+; 27, 28; 27, 29; 28, identifier:xmin; 29, subscript; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:image; 32, identifier:size; 33, integer:0; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:ymax; 37, None; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:ymax; 42, binary_operator:+; 42, 43; 42, 44; 43, identifier:ymin; 44, subscript; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:image; 47, identifier:size; 48, integer:1; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:bitmap_list; 55, identifier:append; 56, argument_list; 56, 57; 57, dictionary; 57, 58; 57, 61; 57, 64; 57, 67; 57, 70; 58, pair; 58, 59; 58, 60; 59, string:'image'; 60, identifier:image; 61, pair; 61, 62; 61, 63; 62, string:'xmin'; 63, identifier:xmin; 64, pair; 64, 65; 64, 66; 65, string:'xmax'; 66, identifier:xmax; 67, pair; 67, 68; 67, 69; 68, string:'ymin'; 69, identifier:ymin; 70, pair; 70, 71; 70, 72; 71, string:'ymax'; 72, identifier:ymax; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:xmin; 76, call; 76, 77; 76, 78; 77, identifier:min; 78, generator_expression; 78, 79; 78, 80; 78, 89; 79, identifier:x; 80, for_in_clause; 80, 81; 80, 82; 81, identifier:x; 82, tuple; 82, 83; 82, 84; 83, identifier:xmin; 84, subscript; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:limits; 88, string:'xmin'; 89, if_clause; 89, 90; 90, comparison_operator:is; 90, 91; 90, 92; 91, identifier:x; 92, None; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:ymin; 96, call; 96, 97; 96, 98; 97, identifier:min; 98, generator_expression; 98, 99; 98, 100; 98, 109; 99, identifier:y; 100, for_in_clause; 100, 101; 100, 102; 101, identifier:y; 102, tuple; 102, 103; 102, 104; 103, identifier:ymin; 104, subscript; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:limits; 108, string:'ymin'; 109, if_clause; 109, 110; 110, comparison_operator:is; 110, 111; 110, 112; 111, identifier:y; 112, None; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:xmax; 116, call; 116, 117; 116, 118; 117, identifier:max; 118, generator_expression; 118, 119; 118, 120; 118, 129; 119, identifier:x; 120, for_in_clause; 120, 121; 120, 122; 121, identifier:x; 122, tuple; 122, 123; 122, 124; 123, identifier:xmax; 124, subscript; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:limits; 128, string:'xmax'; 129, if_clause; 129, 130; 130, comparison_operator:is; 130, 131; 130, 132; 131, identifier:x; 132, None; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:ymax; 136, call; 136, 137; 136, 138; 137, identifier:max; 138, generator_expression; 138, 139; 138, 140; 138, 149; 139, identifier:y; 140, for_in_clause; 140, 141; 140, 142; 141, identifier:y; 142, tuple; 142, 143; 142, 144; 143, identifier:ymax; 144, subscript; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:limits; 148, string:'ymax'; 149, if_clause; 149, 150; 150, comparison_operator:is; 150, 151; 150, 152; 151, identifier:y; 152, None; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:set_xlimits; 158, argument_list; 158, 159; 158, 160; 159, identifier:xmin; 160, identifier:xmax; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:set_ylimits; 166, argument_list; 166, 167; 166, 168; 167, identifier:ymin; 168, identifier:ymax | def draw_image(self, image, xmin=0, ymin=0, xmax=None, ymax=None):
if xmax is None:
xmax = xmin + image.size[0]
if ymax is None:
ymax = ymin + image.size[1]
self.bitmap_list.append({'image': image,
'xmin': xmin,
'xmax': xmax,
'ymin': ymin,
'ymax': ymax})
xmin = min(x for x in (xmin, self.limits['xmin'])
if x is not None)
ymin = min(y for y in (ymin, self.limits['ymin'])
if y is not None)
xmax = max(x for x in (xmax, self.limits['xmax'])
if x is not None)
ymax = max(y for y in (ymax, self.limits['ymax'])
if y is not None)
self.set_xlimits(xmin, xmax)
self.set_ylimits(ymin, ymax) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_prepare_data; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 22; 5, 28; 5, 151; 5, 157; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, pattern_list; 8, 9; 8, 10; 9, identifier:xmin; 10, identifier:xmax; 11, expression_list; 11, 12; 11, 17; 12, subscript; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:limits; 16, string:'xmin'; 17, subscript; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:limits; 21, string:'xmax'; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:prepared_plot_series_list; 27, list:[]; 28, for_statement; 28, 29; 28, 30; 28, 33; 29, identifier:series; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:plot_series_list; 33, block; 33, 34; 33, 42; 33, 48; 33, 60; 33, 142; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:prepared_series; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:series; 40, identifier:copy; 41, argument_list; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:data; 45, subscript; 45, 46; 45, 47; 46, identifier:prepared_series; 47, string:'data'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 55; 50, pattern_list; 50, 51; 50, 52; 50, 53; 50, 54; 51, identifier:x; 52, identifier:_; 53, identifier:_; 54, identifier:_; 55, call; 55, 56; 55, 57; 56, identifier:zip; 57, argument_list; 57, 58; 58, list_splat; 58, 59; 59, identifier:data; 60, if_statement; 60, 61; 60, 70; 61, comparison_operator:==; 61, 62; 61, 66; 62, call; 62, 63; 62, 64; 63, identifier:sorted; 64, argument_list; 64, 65; 65, identifier:x; 66, call; 66, 67; 66, 68; 67, identifier:list; 68, argument_list; 68, 69; 69, identifier:x; 70, block; 70, 71; 70, 80; 70, 109; 70, 131; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:x; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:np; 77, identifier:array; 78, argument_list; 78, 79; 79, identifier:x; 80, if_statement; 80, 81; 80, 84; 80, 103; 81, comparison_operator:is; 81, 82; 81, 83; 82, identifier:xmin; 83, None; 84, block; 84, 85; 84, 94; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:min_idx; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:x; 91, identifier:searchsorted; 92, argument_list; 92, 93; 93, identifier:xmin; 94, if_statement; 94, 95; 94, 98; 95, comparison_operator:>; 95, 96; 95, 97; 96, identifier:min_idx; 97, integer:0; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, augmented_assignment:-=; 100, 101; 100, 102; 101, identifier:min_idx; 102, integer:1; 103, else_clause; 103, 104; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:min_idx; 108, None; 109, if_statement; 109, 110; 109, 113; 109, 125; 110, comparison_operator:is; 110, 111; 110, 112; 111, identifier:xmax; 112, None; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:max_idx; 117, binary_operator:+; 117, 118; 117, 124; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:x; 121, identifier:searchsorted; 122, argument_list; 122, 123; 123, identifier:xmax; 124, integer:1; 125, else_clause; 125, 126; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:max_idx; 130, None; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:prepared_series; 135, string:'data'; 136, subscript; 136, 137; 136, 138; 137, identifier:data; 138, slice; 138, 139; 138, 140; 138, 141; 139, identifier:min_idx; 140, colon; 141, identifier:max_idx; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:prepared_plot_series_list; 148, identifier:append; 149, argument_list; 149, 150; 150, identifier:prepared_series; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:prepared_shaded_regions_list; 156, list:[]; 157, for_statement; 157, 158; 157, 159; 157, 162; 158, identifier:series; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:shaded_regions_list; 162, block; 162, 163; 162, 171; 162, 177; 162, 188; 162, 270; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:prepared_series; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:series; 169, identifier:copy; 170, argument_list; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:data; 174, subscript; 174, 175; 174, 176; 175, identifier:prepared_series; 176, string:'data'; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 183; 179, pattern_list; 179, 180; 179, 181; 179, 182; 180, identifier:x; 181, identifier:_; 182, identifier:_; 183, call; 183, 184; 183, 185; 184, identifier:zip; 185, argument_list; 185, 186; 186, list_splat; 186, 187; 187, identifier:data; 188, if_statement; 188, 189; 188, 198; 189, comparison_operator:==; 189, 190; 189, 194; 190, call; 190, 191; 190, 192; 191, identifier:sorted; 192, argument_list; 192, 193; 193, identifier:x; 194, call; 194, 195; 194, 196; 195, identifier:list; 196, argument_list; 196, 197; 197, identifier:x; 198, block; 198, 199; 198, 208; 198, 237; 198, 259; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:x; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:np; 205, identifier:array; 206, argument_list; 206, 207; 207, identifier:x; 208, if_statement; 208, 209; 208, 212; 208, 231; 209, comparison_operator:is; 209, 210; 209, 211; 210, identifier:xmin; 211, None; 212, block; 212, 213; 212, 222; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:min_idx; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:x; 219, identifier:searchsorted; 220, argument_list; 220, 221; 221, identifier:xmin; 222, if_statement; 222, 223; 222, 226; 223, comparison_operator:>; 223, 224; 223, 225; 224, identifier:min_idx; 225, integer:0; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, augmented_assignment:-=; 228, 229; 228, 230; 229, identifier:min_idx; 230, integer:1; 231, else_clause; 231, 232; 232, block; 232, 233; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:min_idx; 236, None; 237, if_statement; 237, 238; 237, 241; 237, 253; 238, comparison_operator:is; 238, 239; 238, 240; 239, identifier:xmax; 240, None; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:max_idx; 245, binary_operator:+; 245, 246; 245, 252; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:x; 249, identifier:searchsorted; 250, argument_list; 250, 251; 251, identifier:xmax; 252, integer:1; 253, else_clause; 253, 254; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:max_idx; 258, None; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 264; 261, subscript; 261, 262; 261, 263; 262, identifier:prepared_series; 263, string:'data'; 264, subscript; 264, 265; 264, 266; 265, identifier:data; 266, slice; 266, 267; 266, 268; 266, 269; 267, identifier:min_idx; 268, colon; 269, identifier:max_idx; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 277; 272, attribute; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:self; 275, identifier:prepared_shaded_regions_list; 276, identifier:append; 277, argument_list; 277, 278; 278, identifier:prepared_series | def _prepare_data(self):
xmin, xmax = self.limits['xmin'], self.limits['xmax']
self.prepared_plot_series_list = []
for series in self.plot_series_list:
prepared_series = series.copy()
data = prepared_series['data']
x, _, _, _ = zip(*data)
if sorted(x) == list(x):
x = np.array(x)
if xmin is not None:
min_idx = x.searchsorted(xmin)
if min_idx > 0:
min_idx -= 1
else:
min_idx = None
if xmax is not None:
max_idx = x.searchsorted(xmax) + 1
else:
max_idx = None
prepared_series['data'] = data[min_idx:max_idx]
self.prepared_plot_series_list.append(prepared_series)
self.prepared_shaded_regions_list = []
for series in self.shaded_regions_list:
prepared_series = series.copy()
data = prepared_series['data']
x, _, _ = zip(*data)
if sorted(x) == list(x):
x = np.array(x)
if xmin is not None:
min_idx = x.searchsorted(xmin)
if min_idx > 0:
min_idx -= 1
else:
min_idx = None
if xmax is not None:
max_idx = x.searchsorted(xmax) + 1
else:
max_idx = None
prepared_series['data'] = data[min_idx:max_idx]
self.prepared_shaded_regions_list.append(prepared_series) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_departures; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:stop_id; 6, identifier:route; 7, identifier:destination; 8, identifier:api_key; 9, block; 9, 10; 9, 16; 9, 22; 9, 28; 9, 34; 9, 49; 9, 57; 9, 67; 9, 97; 9, 115; 9, 123; 9, 143; 9, 147; 9, 151; 9, 323; 9, 379; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:stop_id; 15, identifier:stop_id; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:route; 21, identifier:route; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:destination; 27, identifier:destination; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:api_key; 33, identifier:api_key; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:url; 37, binary_operator:+; 37, 38; 37, 47; 37, 48; 38, binary_operator:+; 38, 39; 38, 43; 38, 44; 39, concatenated_string; 39, 40; 39, 41; 39, 42; 40, string:'https://api.transport.nsw.gov.au/v1/tp/departure_mon?'; 41, string:'outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326&'; 42, string:'mode=direct&type_dm=stop&name_dm='; 43, line_continuation:\; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:stop_id; 47, line_continuation:\; 48, string:'&departureMonitorMacro=true&TfNSWDM=true&version=10.2.1.42'; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:auth; 52, binary_operator:+; 52, 53; 52, 54; 53, string:'apikey '; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:api_key; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:header; 60, dictionary; 60, 61; 60, 64; 61, pair; 61, 62; 61, 63; 62, string:'Accept'; 63, string:'application/json'; 64, pair; 64, 65; 64, 66; 65, string:'Authorization'; 66, identifier:auth; 67, try_statement; 67, 68; 67, 84; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:response; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:requests; 75, identifier:get; 76, argument_list; 76, 77; 76, 78; 76, 81; 77, identifier:url; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:headers; 80, identifier:header; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:timeout; 83, integer:10; 84, except_clause; 84, 85; 85, block; 85, 86; 85, 93; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:logger; 90, identifier:warning; 91, argument_list; 91, 92; 92, string:"Network or Timeout error"; 93, return_statement; 93, 94; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:info; 97, if_statement; 97, 98; 97, 103; 98, comparison_operator:!=; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:response; 101, identifier:status_code; 102, integer:200; 103, block; 103, 104; 103, 111; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:logger; 108, identifier:warning; 109, argument_list; 109, 110; 110, string:"Error with the request sent; check api key"; 111, return_statement; 111, 112; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:info; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:result; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:response; 121, identifier:json; 122, argument_list; 123, try_statement; 123, 124; 123, 129; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, subscript; 126, 127; 126, 128; 127, identifier:result; 128, string:'stopEvents'; 129, except_clause; 129, 130; 129, 131; 130, identifier:KeyError; 131, block; 131, 132; 131, 139; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:logger; 136, identifier:warning; 137, argument_list; 137, 138; 138, string:"No stop events for this query"; 139, return_statement; 139, 140; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:info; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:maxresults; 146, integer:1; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:monitor; 150, list:[]; 151, if_statement; 151, 152; 151, 157; 151, 222; 151, 291; 152, comparison_operator:!=; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:destination; 156, string:''; 157, block; 157, 158; 158, for_statement; 158, 159; 158, 160; 158, 169; 159, identifier:i; 160, call; 160, 161; 160, 162; 161, identifier:range; 162, argument_list; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:len; 165, argument_list; 165, 166; 166, subscript; 166, 167; 166, 168; 167, identifier:result; 168, string:'stopEvents'; 169, block; 169, 170; 169, 184; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:destination; 173, subscript; 173, 174; 173, 183; 174, subscript; 174, 175; 174, 182; 175, subscript; 175, 176; 175, 181; 176, subscript; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:result; 179, string:'stopEvents'; 180, identifier:i; 181, string:'transportation'; 182, string:'destination'; 183, string:'name'; 184, if_statement; 184, 185; 184, 190; 185, comparison_operator:==; 185, 186; 185, 187; 186, identifier:destination; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:destination; 190, block; 190, 191; 190, 201; 190, 213; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:event; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:parseEvent; 198, argument_list; 198, 199; 198, 200; 199, identifier:result; 200, identifier:i; 201, if_statement; 201, 202; 201, 205; 202, comparison_operator:!=; 202, 203; 202, 204; 203, identifier:event; 204, None; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:monitor; 210, identifier:append; 211, argument_list; 211, 212; 212, identifier:event; 213, if_statement; 213, 214; 213, 220; 214, comparison_operator:>=; 214, 215; 214, 219; 215, call; 215, 216; 215, 217; 216, identifier:len; 217, argument_list; 217, 218; 218, identifier:monitor; 219, identifier:maxresults; 220, block; 220, 221; 221, break_statement; 222, elif_clause; 222, 223; 222, 228; 223, comparison_operator:!=; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:route; 227, string:''; 228, block; 228, 229; 229, for_statement; 229, 230; 229, 231; 229, 240; 230, identifier:i; 231, call; 231, 232; 231, 233; 232, identifier:range; 233, argument_list; 233, 234; 234, call; 234, 235; 234, 236; 235, identifier:len; 236, argument_list; 236, 237; 237, subscript; 237, 238; 237, 239; 238, identifier:result; 239, string:'stopEvents'; 240, block; 240, 241; 240, 253; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:number; 244, subscript; 244, 245; 244, 252; 245, subscript; 245, 246; 245, 251; 246, subscript; 246, 247; 246, 250; 247, subscript; 247, 248; 247, 249; 248, identifier:result; 249, string:'stopEvents'; 250, identifier:i; 251, string:'transportation'; 252, string:'number'; 253, if_statement; 253, 254; 253, 259; 254, comparison_operator:==; 254, 255; 254, 256; 255, identifier:number; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:route; 259, block; 259, 260; 259, 270; 259, 282; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:event; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:parseEvent; 267, argument_list; 267, 268; 267, 269; 268, identifier:result; 269, identifier:i; 270, if_statement; 270, 271; 270, 274; 271, comparison_operator:!=; 271, 272; 271, 273; 272, identifier:event; 273, None; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:monitor; 279, identifier:append; 280, argument_list; 280, 281; 281, identifier:event; 282, if_statement; 282, 283; 282, 289; 283, comparison_operator:>=; 283, 284; 283, 288; 284, call; 284, 285; 284, 286; 285, identifier:len; 286, argument_list; 286, 287; 287, identifier:monitor; 288, identifier:maxresults; 289, block; 289, 290; 290, break_statement; 291, else_clause; 291, 292; 292, block; 292, 293; 293, for_statement; 293, 294; 293, 295; 293, 300; 294, identifier:i; 295, call; 295, 296; 295, 297; 296, identifier:range; 297, argument_list; 297, 298; 297, 299; 298, integer:0; 299, identifier:maxresults; 300, block; 300, 301; 300, 311; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:event; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:self; 307, identifier:parseEvent; 308, argument_list; 308, 309; 308, 310; 309, identifier:result; 310, identifier:i; 311, if_statement; 311, 312; 311, 315; 312, comparison_operator:!=; 312, 313; 312, 314; 313, identifier:event; 314, None; 315, block; 315, 316; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:monitor; 320, identifier:append; 321, argument_list; 321, 322; 322, identifier:event; 323, if_statement; 323, 324; 323, 325; 324, identifier:monitor; 325, block; 325, 326; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:self; 330, identifier:info; 331, dictionary; 331, 332; 331, 337; 331, 344; 331, 351; 331, 358; 331, 365; 331, 372; 332, pair; 332, 333; 332, 334; 333, identifier:ATTR_STOP_ID; 334, attribute; 334, 335; 334, 336; 335, identifier:self; 336, identifier:stop_id; 337, pair; 337, 338; 337, 339; 338, identifier:ATTR_ROUTE; 339, subscript; 339, 340; 339, 343; 340, subscript; 340, 341; 340, 342; 341, identifier:monitor; 342, integer:0; 343, integer:0; 344, pair; 344, 345; 344, 346; 345, identifier:ATTR_DUE_IN; 346, subscript; 346, 347; 346, 350; 347, subscript; 347, 348; 347, 349; 348, identifier:monitor; 349, integer:0; 350, integer:1; 351, pair; 351, 352; 351, 353; 352, identifier:ATTR_DELAY; 353, subscript; 353, 354; 353, 357; 354, subscript; 354, 355; 354, 356; 355, identifier:monitor; 356, integer:0; 357, integer:2; 358, pair; 358, 359; 358, 360; 359, identifier:ATTR_REALTIME; 360, subscript; 360, 361; 360, 364; 361, subscript; 361, 362; 361, 363; 362, identifier:monitor; 363, integer:0; 364, integer:5; 365, pair; 365, 366; 365, 367; 366, identifier:ATTR_DESTINATION; 367, subscript; 367, 368; 367, 371; 368, subscript; 368, 369; 368, 370; 369, identifier:monitor; 370, integer:0; 371, integer:6; 372, pair; 372, 373; 372, 374; 373, identifier:ATTR_MODE; 374, subscript; 374, 375; 374, 378; 375, subscript; 375, 376; 375, 377; 376, identifier:monitor; 377, integer:0; 378, integer:7; 379, return_statement; 379, 380; 380, attribute; 380, 381; 380, 382; 381, identifier:self; 382, identifier:info | def get_departures(self, stop_id, route, destination, api_key):
self.stop_id = stop_id
self.route = route
self.destination = destination
self.api_key = api_key
url = \
'https://api.transport.nsw.gov.au/v1/tp/departure_mon?' \
'outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326&' \
'mode=direct&type_dm=stop&name_dm=' \
+ self.stop_id \
+ '&departureMonitorMacro=true&TfNSWDM=true&version=10.2.1.42'
auth = 'apikey ' + self.api_key
header = {'Accept': 'application/json', 'Authorization': auth}
try:
response = requests.get(url, headers=header, timeout=10)
except:
logger.warning("Network or Timeout error")
return self.info
if response.status_code != 200:
logger.warning("Error with the request sent; check api key")
return self.info
result = response.json()
try:
result['stopEvents']
except KeyError:
logger.warning("No stop events for this query")
return self.info
maxresults = 1
monitor = []
if self.destination != '':
for i in range(len(result['stopEvents'])):
destination = result['stopEvents'][i]['transportation']['destination']['name']
if destination == self.destination:
event = self.parseEvent(result, i)
if event != None:
monitor.append(event)
if len(monitor) >= maxresults:
break
elif self.route != '':
for i in range(len(result['stopEvents'])):
number = result['stopEvents'][i]['transportation']['number']
if number == self.route:
event = self.parseEvent(result, i)
if event != None:
monitor.append(event)
if len(monitor) >= maxresults:
break
else:
for i in range(0, maxresults):
event = self.parseEvent(result, i)
if event != None:
monitor.append(event)
if monitor:
self.info = {
ATTR_STOP_ID: self.stop_id,
ATTR_ROUTE: monitor[0][0],
ATTR_DUE_IN: monitor[0][1],
ATTR_DELAY: monitor[0][2],
ATTR_REALTIME: monitor[0][5],
ATTR_DESTINATION: monitor[0][6],
ATTR_MODE: monitor[0][7]
}
return self.info |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:pw; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 4, identifier:ctx; 5, identifier:key_pattern; 6, identifier:user_pattern; 7, identifier:mode; 8, identifier:strict_flag; 9, identifier:user_flag; 10, identifier:file; 11, identifier:edit_subcommand; 12, identifier:gen_subcommand; 13, block; 13, 14; 13, 33; 13, 43; 13, 73; 13, 103; 13, 112; 13, 128; 13, 138; 13, 145; 13, 172; 13, 198; 14, function_definition; 14, 15; 14, 16; 14, 19; 15, function_name:handle_sigint; 16, parameters; 16, 17; 17, list_splat_pattern; 17, 18; 18, identifier:_; 19, block; 19, 20; 19, 26; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:click; 24, identifier:echo; 25, argument_list; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:ctx; 30, identifier:exit; 31, argument_list; 31, 32; 32, integer:1; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:signal; 37, identifier:signal; 38, argument_list; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:signal; 41, identifier:SIGINT; 42, identifier:handle_sigint; 43, if_statement; 43, 44; 43, 45; 43, 63; 44, identifier:gen_subcommand; 45, block; 45, 46; 45, 56; 45, 62; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:length; 49, conditional_expression:if; 49, 50; 49, 54; 49, 55; 50, call; 50, 51; 50, 52; 51, identifier:int; 52, argument_list; 52, 53; 53, identifier:key_pattern; 54, identifier:key_pattern; 55, None; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:generate_password; 59, argument_list; 59, 60; 59, 61; 60, identifier:mode; 61, identifier:length; 62, return_statement; 63, elif_clause; 63, 64; 63, 65; 64, identifier:edit_subcommand; 65, block; 65, 66; 65, 72; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:launch_editor; 69, argument_list; 69, 70; 69, 71; 70, identifier:ctx; 71, identifier:file; 72, return_statement; 73, if_statement; 73, 74; 73, 83; 74, not_operator; 74, 75; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:os; 79, identifier:path; 80, identifier:exists; 81, argument_list; 81, 82; 82, identifier:file; 83, block; 83, 84; 83, 96; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:click; 88, identifier:echo; 89, argument_list; 89, 90; 89, 93; 90, binary_operator:%; 90, 91; 90, 92; 91, string:"error: password store not found at '%s'"; 92, identifier:file; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:err; 95, True; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:ctx; 100, identifier:exit; 101, argument_list; 101, 102; 102, integer:1; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:store; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:Store; 109, identifier:load; 110, argument_list; 110, 111; 111, identifier:file; 112, if_statement; 112, 113; 112, 115; 113, not_operator; 113, 114; 114, identifier:user_pattern; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 122; 118, pattern_list; 118, 119; 118, 120; 118, 121; 119, identifier:user_pattern; 120, identifier:_; 121, identifier:key_pattern; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:key_pattern; 125, identifier:rpartition; 126, argument_list; 126, 127; 127, string:"@"; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:results; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:store; 134, identifier:search; 135, argument_list; 135, 136; 135, 137; 136, identifier:key_pattern; 137, identifier:user_pattern; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:results; 141, call; 141, 142; 141, 143; 142, identifier:list; 143, argument_list; 143, 144; 144, identifier:results; 145, if_statement; 145, 146; 145, 154; 146, boolean_operator:and; 146, 147; 146, 148; 147, identifier:strict_flag; 148, comparison_operator:!=; 148, 149; 148, 153; 149, call; 149, 150; 149, 151; 150, identifier:len; 151, argument_list; 151, 152; 152, identifier:results; 153, integer:1; 154, block; 154, 155; 154, 165; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:click; 159, identifier:echo; 160, argument_list; 160, 161; 160, 162; 161, string:"error: multiple or no records found (but using --strict flag)"; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:err; 164, True; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:ctx; 169, identifier:exit; 170, argument_list; 170, 171; 171, integer:2; 172, if_statement; 172, 173; 172, 178; 173, comparison_operator:==; 173, 174; 173, 175; 174, identifier:mode; 175, attribute; 175, 176; 175, 177; 176, identifier:Mode; 177, identifier:RAW; 178, block; 178, 179; 178, 197; 179, for_statement; 179, 180; 179, 181; 179, 182; 180, identifier:entry; 181, identifier:results; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:click; 187, identifier:echo; 188, argument_list; 188, 189; 189, conditional_expression:if; 189, 190; 189, 193; 189, 194; 190, attribute; 190, 191; 190, 192; 191, identifier:entry; 192, identifier:user; 193, identifier:user_flag; 194, attribute; 194, 195; 194, 196; 195, identifier:entry; 196, identifier:password; 197, return_statement; 198, for_statement; 198, 199; 198, 202; 198, 206; 199, pattern_list; 199, 200; 199, 201; 200, identifier:idx; 201, identifier:entry; 202, call; 202, 203; 202, 204; 203, identifier:enumerate; 204, argument_list; 204, 205; 205, identifier:results; 206, block; 206, 207; 206, 217; 206, 234; 206, 314; 206, 380; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:line; 210, call; 210, 211; 210, 212; 211, identifier:highlight_match; 212, argument_list; 212, 213; 212, 214; 213, identifier:key_pattern; 214, attribute; 214, 215; 214, 216; 215, identifier:entry; 216, identifier:key; 217, if_statement; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:entry; 220, identifier:user; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, augmented_assignment:+=; 223, 224; 223, 225; 224, identifier:line; 225, binary_operator:+; 225, 226; 225, 227; 226, string:": "; 227, call; 227, 228; 227, 229; 228, identifier:highlight_match; 229, argument_list; 229, 230; 229, 231; 230, identifier:user_pattern; 231, attribute; 231, 232; 231, 233; 232, identifier:entry; 233, identifier:user; 234, if_statement; 234, 235; 234, 243; 234, 255; 235, boolean_operator:and; 235, 236; 235, 241; 236, comparison_operator:==; 236, 237; 236, 238; 237, identifier:mode; 238, attribute; 238, 239; 238, 240; 239, identifier:Mode; 240, identifier:ECHO; 241, not_operator; 241, 242; 242, identifier:user_flag; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, augmented_assignment:+=; 245, 246; 245, 247; 246, identifier:line; 247, binary_operator:+; 247, 248; 247, 249; 248, string:" | "; 249, call; 249, 250; 249, 251; 250, identifier:style_password; 251, argument_list; 251, 252; 252, attribute; 252, 253; 252, 254; 253, identifier:entry; 254, identifier:password; 255, elif_clause; 255, 256; 255, 265; 256, boolean_operator:and; 256, 257; 256, 262; 257, comparison_operator:==; 257, 258; 257, 259; 258, identifier:mode; 259, attribute; 259, 260; 259, 261; 260, identifier:Mode; 261, identifier:COPY; 262, comparison_operator:==; 262, 263; 262, 264; 263, identifier:idx; 264, integer:0; 265, block; 265, 266; 265, 308; 266, try_statement; 266, 267; 266, 298; 267, block; 267, 268; 267, 271; 267, 285; 268, import_statement; 268, 269; 269, dotted_name; 269, 270; 270, identifier:pyperclip; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:pyperclip; 275, identifier:copy; 276, argument_list; 276, 277; 277, conditional_expression:if; 277, 278; 277, 281; 277, 282; 278, attribute; 278, 279; 278, 280; 279, identifier:entry; 280, identifier:user; 281, identifier:user_flag; 282, attribute; 282, 283; 282, 284; 283, identifier:entry; 284, identifier:password; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:result; 288, call; 288, 289; 288, 290; 289, identifier:style_success; 290, argument_list; 290, 291; 291, binary_operator:%; 291, 292; 291, 293; 292, string:"*** %s COPIED TO CLIPBOARD ***"; 293, parenthesized_expression; 293, 294; 294, conditional_expression:if; 294, 295; 294, 296; 294, 297; 295, string:"USERNAME"; 296, identifier:user_flag; 297, string:"PASSWORD"; 298, except_clause; 298, 299; 298, 300; 299, identifier:ImportError; 300, block; 300, 301; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:result; 304, call; 304, 305; 304, 306; 305, identifier:style_error; 306, argument_list; 306, 307; 307, string:'*** PYTHON PACKAGE "PYPERCLIP" NOT FOUND ***'; 308, expression_statement; 308, 309; 309, augmented_assignment:+=; 309, 310; 309, 311; 310, identifier:line; 311, binary_operator:+; 311, 312; 311, 313; 312, string:" | "; 313, identifier:result; 314, if_statement; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:entry; 317, identifier:notes; 318, block; 318, 319; 319, if_statement; 319, 320; 319, 323; 319, 348; 320, comparison_operator:==; 320, 321; 320, 322; 321, identifier:idx; 322, integer:0; 323, block; 323, 324; 323, 328; 324, expression_statement; 324, 325; 325, augmented_assignment:+=; 325, 326; 325, 327; 326, identifier:line; 327, string:"\n"; 328, expression_statement; 328, 329; 329, augmented_assignment:+=; 329, 330; 329, 331; 330, identifier:line; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, string:"\n"; 334, identifier:join; 335, generator_expression; 335, 336; 335, 339; 336, binary_operator:+; 336, 337; 336, 338; 337, string:" "; 338, identifier:line; 339, for_in_clause; 339, 340; 339, 341; 340, identifier:line; 341, call; 341, 342; 341, 347; 342, attribute; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:entry; 345, identifier:notes; 346, identifier:splitlines; 347, argument_list; 348, else_clause; 348, 349; 349, block; 349, 350; 349, 360; 349, 368; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 353; 352, identifier:lines; 353, call; 353, 354; 353, 359; 354, attribute; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:entry; 357, identifier:notes; 358, identifier:splitlines; 359, argument_list; 360, expression_statement; 360, 361; 361, augmented_assignment:+=; 361, 362; 361, 363; 362, identifier:line; 363, binary_operator:+; 363, 364; 363, 365; 364, string:" | "; 365, subscript; 365, 366; 365, 367; 366, identifier:lines; 367, integer:0; 368, if_statement; 368, 369; 368, 375; 369, comparison_operator:>; 369, 370; 369, 374; 370, call; 370, 371; 370, 372; 371, identifier:len; 372, argument_list; 372, 373; 373, identifier:lines; 374, integer:1; 375, block; 375, 376; 376, expression_statement; 376, 377; 377, augmented_assignment:+=; 377, 378; 377, 379; 378, identifier:line; 379, string:" (...)"; 380, expression_statement; 380, 381; 381, call; 381, 382; 381, 385; 382, attribute; 382, 383; 382, 384; 383, identifier:click; 384, identifier:echo; 385, argument_list; 385, 386; 386, identifier:line | def pw(
ctx,
key_pattern,
user_pattern,
mode,
strict_flag,
user_flag,
file,
edit_subcommand,
gen_subcommand,
):
def handle_sigint(*_):
click.echo()
ctx.exit(1)
signal.signal(signal.SIGINT, handle_sigint)
if gen_subcommand:
length = int(key_pattern) if key_pattern else None
generate_password(mode, length)
return
elif edit_subcommand:
launch_editor(ctx, file)
return
if not os.path.exists(file):
click.echo("error: password store not found at '%s'" % file, err=True)
ctx.exit(1)
store = Store.load(file)
if not user_pattern:
user_pattern, _, key_pattern = key_pattern.rpartition("@")
results = store.search(key_pattern, user_pattern)
results = list(results)
if strict_flag and len(results) != 1:
click.echo(
"error: multiple or no records found (but using --strict flag)", err=True
)
ctx.exit(2)
if mode == Mode.RAW:
for entry in results:
click.echo(entry.user if user_flag else entry.password)
return
for idx, entry in enumerate(results):
line = highlight_match(key_pattern, entry.key)
if entry.user:
line += ": " + highlight_match(user_pattern, entry.user)
if mode == Mode.ECHO and not user_flag:
line += " | " + style_password(entry.password)
elif mode == Mode.COPY and idx == 0:
try:
import pyperclip
pyperclip.copy(entry.user if user_flag else entry.password)
result = style_success(
"*** %s COPIED TO CLIPBOARD ***"
% ("USERNAME" if user_flag else "PASSWORD")
)
except ImportError:
result = style_error('*** PYTHON PACKAGE "PYPERCLIP" NOT FOUND ***')
line += " | " + result
if entry.notes:
if idx == 0:
line += "\n"
line += "\n".join(" " + line for line in entry.notes.splitlines())
else:
lines = entry.notes.splitlines()
line += " | " + lines[0]
if len(lines) > 1:
line += " (...)"
click.echo(line) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:launch_editor; 3, parameters; 3, 4; 3, 5; 4, identifier:ctx; 5, identifier:file; 6, block; 6, 7; 6, 18; 6, 36; 6, 66; 6, 75; 6, 101; 6, 133; 6, 142; 6, 165; 6, 178; 6, 187; 6, 211; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:editor; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:os; 14, identifier:environ; 15, identifier:get; 16, argument_list; 16, 17; 17, string:"PW_EDITOR"; 18, if_statement; 18, 19; 18, 21; 19, not_operator; 19, 20; 20, identifier:editor; 21, block; 21, 22; 21, 29; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:click; 26, identifier:echo; 27, argument_list; 27, 28; 28, string:"error: no editor set in PW_EDITOR environment variables"; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:ctx; 33, identifier:exit; 34, argument_list; 34, 35; 35, integer:1; 36, if_statement; 36, 37; 36, 46; 37, not_operator; 37, 38; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:os; 42, identifier:path; 43, identifier:exists; 44, argument_list; 44, 45; 45, identifier:file; 46, block; 46, 47; 46, 59; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:click; 51, identifier:echo; 52, argument_list; 52, 53; 52, 56; 53, binary_operator:%; 53, 54; 53, 55; 54, string:"error: password store not found at '%s'"; 55, identifier:file; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:err; 58, True; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:ctx; 63, identifier:exit; 64, argument_list; 64, 65; 65, integer:1; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:is_encrypted; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:_gpg; 72, identifier:is_encrypted; 73, argument_list; 73, 74; 74, identifier:file; 75, if_statement; 75, 76; 75, 77; 75, 87; 76, identifier:is_encrypted; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:original; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:_gpg; 84, identifier:decrypt; 85, argument_list; 85, 86; 86, identifier:file; 87, else_clause; 87, 88; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:original; 92, call; 92, 93; 92, 100; 93, attribute; 93, 94; 93, 99; 94, call; 94, 95; 94, 96; 95, identifier:open; 96, argument_list; 96, 97; 96, 98; 97, identifier:file; 98, string:"rb"; 99, identifier:read; 100, argument_list; 101, if_statement; 101, 102; 101, 103; 102, identifier:is_encrypted; 103, block; 103, 104; 103, 115; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:recipient; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:os; 111, identifier:environ; 112, identifier:get; 113, argument_list; 113, 114; 114, string:"PW_GPG_RECIPIENT"; 115, if_statement; 115, 116; 115, 118; 116, not_operator; 116, 117; 117, identifier:recipient; 118, block; 118, 119; 118, 126; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:click; 123, identifier:echo; 124, argument_list; 124, 125; 125, string:"error: no recipient set in PW_GPG_RECIPIENT environment variables"; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:ctx; 130, identifier:exit; 131, argument_list; 131, 132; 132, integer:1; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:ext; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:_gpg; 139, identifier:unencrypted_ext; 140, argument_list; 140, 141; 141, identifier:file; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:modified; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:click; 148, identifier:edit; 149, argument_list; 149, 150; 149, 156; 149, 159; 149, 162; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:original; 153, identifier:decode; 154, argument_list; 154, 155; 155, string:"utf-8"; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:editor; 158, identifier:editor; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:require_save; 161, True; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:extension; 164, identifier:ext; 165, if_statement; 165, 166; 165, 169; 166, comparison_operator:is; 166, 167; 166, 168; 167, identifier:modified; 168, None; 169, block; 169, 170; 169, 177; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:click; 174, identifier:echo; 175, argument_list; 175, 176; 176, string:"not modified"; 177, return_statement; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:modified; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:modified; 184, identifier:encode; 185, argument_list; 185, 186; 186, string:"utf-8"; 187, if_statement; 187, 188; 187, 190; 188, not_operator; 188, 189; 189, identifier:is_encrypted; 190, block; 190, 191; 190, 210; 191, with_statement; 191, 192; 191, 202; 192, with_clause; 192, 193; 193, with_item; 193, 194; 194, as_pattern; 194, 195; 194, 200; 195, call; 195, 196; 195, 197; 196, identifier:open; 197, argument_list; 197, 198; 197, 199; 198, identifier:file; 199, string:"wb"; 200, as_pattern_target; 200, 201; 201, identifier:fp; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:fp; 207, identifier:write; 208, argument_list; 208, 209; 209, identifier:modified; 210, return_statement; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:_gpg; 215, identifier:encrypt; 216, argument_list; 216, 217; 216, 220; 216, 223; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:recipient; 219, identifier:recipient; 220, keyword_argument; 220, 221; 220, 222; 221, identifier:dest_path; 222, identifier:file; 223, keyword_argument; 223, 224; 223, 225; 224, identifier:content; 225, identifier:modified | def launch_editor(ctx, file):
editor = os.environ.get("PW_EDITOR")
if not editor:
click.echo("error: no editor set in PW_EDITOR environment variables")
ctx.exit(1)
if not os.path.exists(file):
click.echo("error: password store not found at '%s'" % file, err=True)
ctx.exit(1)
is_encrypted = _gpg.is_encrypted(file)
if is_encrypted:
original = _gpg.decrypt(file)
else:
original = open(file, "rb").read()
if is_encrypted:
recipient = os.environ.get("PW_GPG_RECIPIENT")
if not recipient:
click.echo(
"error: no recipient set in PW_GPG_RECIPIENT environment variables"
)
ctx.exit(1)
ext = _gpg.unencrypted_ext(file)
modified = click.edit(
original.decode("utf-8"), editor=editor, require_save=True, extension=ext
)
if modified is None:
click.echo("not modified")
return
modified = modified.encode("utf-8")
if not is_encrypted:
with open(file, "wb") as fp:
fp.write(modified)
return
_gpg.encrypt(recipient=recipient, dest_path=file, content=modified) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:fit; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:sim_mat; 5, identifier:D_len; 6, identifier:cidx; 7, block; 7, 8; 7, 14; 7, 166; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:min_energy; 11, attribute; 11, 12; 11, 13; 12, identifier:np; 13, identifier:inf; 14, for_statement; 14, 15; 14, 16; 14, 20; 15, identifier:j; 16, call; 16, 17; 16, 18; 17, identifier:range; 18, argument_list; 18, 19; 19, integer:3; 20, block; 20, 21; 20, 53; 20, 57; 20, 61; 20, 151; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:inds; 24, list_comprehension; 24, 25; 24, 43; 24, 49; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:np; 28, identifier:argmin; 29, argument_list; 29, 30; 30, list_comprehension; 30, 31; 30, 40; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:sim_mat; 35, identifier:idy; 36, identifier:get; 37, argument_list; 37, 38; 37, 39; 38, identifier:idx; 39, integer:0; 40, for_in_clause; 40, 41; 40, 42; 41, identifier:idx; 42, identifier:cidx; 43, for_in_clause; 43, 44; 43, 45; 44, identifier:idy; 45, call; 45, 46; 45, 47; 46, identifier:range; 47, argument_list; 47, 48; 48, identifier:D_len; 49, if_clause; 49, 50; 50, comparison_operator:in; 50, 51; 50, 52; 51, identifier:idy; 52, identifier:sim_mat; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:cidx; 56, list:[]; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:energy; 60, integer:0; 61, for_statement; 61, 62; 61, 63; 61, 69; 62, identifier:i; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:np; 66, identifier:unique; 67, argument_list; 67, 68; 68, identifier:inds; 69, block; 69, 70; 69, 83; 69, 91; 69, 138; 69, 142; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:indsi; 73, subscript; 73, 74; 73, 82; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:np; 77, identifier:where; 78, argument_list; 78, 79; 79, comparison_operator:==; 79, 80; 79, 81; 80, identifier:inds; 81, identifier:i; 82, integer:0; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, pattern_list; 85, 86; 85, 87; 86, identifier:minind; 87, identifier:min_value; 88, expression_list; 88, 89; 88, 90; 89, integer:0; 90, integer:0; 91, for_statement; 91, 92; 91, 95; 91, 99; 92, pattern_list; 92, 93; 92, 94; 93, identifier:index; 94, identifier:idy; 95, call; 95, 96; 95, 97; 96, identifier:enumerate; 97, argument_list; 97, 98; 98, identifier:indsi; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 104; 101, comparison_operator:in; 101, 102; 101, 103; 102, identifier:idy; 103, identifier:sim_mat; 104, block; 104, 105; 104, 109; 104, 125; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:value; 108, integer:0; 109, for_statement; 109, 110; 109, 111; 109, 112; 110, identifier:idx; 111, identifier:indsi; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, augmented_assignment:+=; 114, 115; 114, 116; 115, identifier:value; 116, call; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:sim_mat; 120, identifier:idy; 121, identifier:get; 122, argument_list; 122, 123; 122, 124; 123, identifier:idx; 124, integer:0; 125, if_statement; 125, 126; 125, 129; 126, comparison_operator:<; 126, 127; 126, 128; 127, identifier:value; 128, identifier:min_value; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 135; 132, pattern_list; 132, 133; 132, 134; 133, identifier:minind; 134, identifier:min_value; 135, expression_list; 135, 136; 135, 137; 136, identifier:index; 137, identifier:value; 138, expression_statement; 138, 139; 139, augmented_assignment:+=; 139, 140; 139, 141; 140, identifier:energy; 141, identifier:min_value; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:cidx; 146, identifier:append; 147, argument_list; 147, 148; 148, subscript; 148, 149; 148, 150; 149, identifier:indsi; 150, identifier:minind; 151, if_statement; 151, 152; 151, 155; 152, comparison_operator:<; 152, 153; 152, 154; 153, identifier:energy; 154, identifier:min_energy; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 162; 158, pattern_list; 158, 159; 158, 160; 158, 161; 159, identifier:min_energy; 160, identifier:inds_min; 161, identifier:cidx_min; 162, expression_list; 162, 163; 162, 164; 162, 165; 163, identifier:energy; 164, identifier:inds; 165, identifier:cidx; 166, return_statement; 166, 167; 167, expression_list; 167, 168; 167, 169; 168, identifier:inds_min; 169, identifier:cidx_min | def fit(sim_mat, D_len, cidx):
min_energy = np.inf
for j in range(3):
inds = [np.argmin([sim_mat[idy].get(idx, 0) for idx in cidx]) for idy in range(D_len) if idy in sim_mat]
cidx = []
energy = 0
for i in np.unique(inds):
indsi = np.where(inds == i)[0]
minind, min_value = 0, 0
for index, idy in enumerate(indsi):
if idy in sim_mat:
value = 0
for idx in indsi:
value += sim_mat[idy].get(idx, 0)
if value < min_value:
minind, min_value = index, value
energy += min_value
cidx.append(indsi[minind])
if energy < min_energy:
min_energy, inds_min, cidx_min = energy, inds, cidx
return inds_min, cidx_min |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:authenticate; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:request; 6, default_parameter; 6, 7; 6, 8; 7, identifier:remote_user; 8, None; 9, block; 9, 10; 9, 18; 9, 24; 9, 28; 9, 37; 9, 283; 10, if_statement; 10, 11; 10, 13; 11, not_operator; 11, 12; 12, identifier:remote_user; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:remote_user; 17, identifier:request; 18, if_statement; 18, 19; 18, 21; 19, not_operator; 19, 20; 20, identifier:remote_user; 21, block; 21, 22; 22, return_statement; 22, 23; 23, None; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:user; 27, None; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:username; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:clean_username; 35, argument_list; 35, 36; 36, identifier:remote_user; 37, try_statement; 37, 38; 37, 176; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 43; 39, 155; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:create_unknown_user; 43, block; 43, 44; 43, 48; 43, 113; 43, 135; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:defaults; 47, dictionary; 48, if_statement; 48, 49; 48, 54; 49, call; 49, 50; 49, 51; 50, identifier:isinstance; 51, argument_list; 51, 52; 51, 53; 52, identifier:request; 53, identifier:dict; 54, block; 54, 55; 54, 59; 54, 89; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:session_data; 58, identifier:request; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:in; 60, 61; 60, 62; 61, string:'full_name'; 62, identifier:session_data; 63, block; 63, 64; 63, 76; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 70; 66, pattern_list; 66, 67; 66, 68; 66, 69; 67, identifier:first_name; 68, identifier:_; 69, identifier:last_name; 70, call; 70, 71; 70, 72; 71, identifier:full_name_natural_split; 72, argument_list; 72, 73; 73, subscript; 73, 74; 73, 75; 74, identifier:session_data; 75, string:'full_name'; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:defaults; 80, identifier:update; 81, argument_list; 81, 82; 82, dictionary; 82, 83; 82, 86; 83, pair; 83, 84; 83, 85; 84, string:'first_name'; 85, identifier:first_name; 86, pair; 86, 87; 86, 88; 87, string:'last_name'; 88, identifier:last_name; 89, for_statement; 89, 90; 89, 91; 89, 95; 90, identifier:key; 91, tuple; 91, 92; 91, 93; 91, 94; 92, string:'email'; 93, string:'first_name'; 94, string:'last_name'; 95, block; 95, 96; 96, if_statement; 96, 97; 96, 100; 97, comparison_operator:in; 97, 98; 97, 99; 98, identifier:key; 99, identifier:session_data; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:defaults; 105, identifier:update; 106, argument_list; 106, 107; 107, dictionary; 107, 108; 108, pair; 108, 109; 108, 110; 109, identifier:key; 110, subscript; 110, 111; 110, 112; 111, identifier:session_data; 112, identifier:key; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, pattern_list; 115, 116; 115, 117; 116, identifier:user; 117, identifier:created; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:UserModel; 122, identifier:_default_manager; 123, identifier:get_or_create; 124, argument_list; 124, 125; 125, dictionary_splat; 125, 126; 126, dictionary; 126, 127; 126, 132; 127, pair; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:UserModel; 130, identifier:USERNAME_FIELD; 131, identifier:username; 132, pair; 132, 133; 132, 134; 133, string:'defaults'; 134, identifier:defaults; 135, if_statement; 135, 136; 135, 137; 136, identifier:created; 137, block; 137, 138; 137, 146; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:LOGGER; 142, identifier:debug; 143, argument_list; 143, 144; 143, 145; 144, string:"created user '%s' in database."; 145, identifier:username; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:user; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:configure_user; 153, argument_list; 153, 154; 154, identifier:user; 155, else_clause; 155, 156; 156, block; 156, 157; 157, try_statement; 157, 158; 157, 170; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:user; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:UserModel; 166, identifier:_default_manager; 167, identifier:get_by_natural_key; 168, argument_list; 168, 169; 169, identifier:username; 170, except_clause; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:UserModel; 173, identifier:DoesNotExist; 174, block; 174, 175; 175, pass_statement; 176, except_clause; 176, 177; 176, 181; 177, as_pattern; 177, 178; 177, 179; 178, identifier:DatabaseError; 179, as_pattern_target; 179, 180; 180, identifier:err; 181, block; 181, 182; 181, 190; 181, 237; 181, 260; 181, 273; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:LOGGER; 186, identifier:debug; 187, argument_list; 187, 188; 187, 189; 188, string:"User table missing from database? (err:%s)"; 189, identifier:err; 190, for_statement; 190, 191; 190, 192; 190, 200; 191, identifier:user; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:six; 195, identifier:itervalues; 196, argument_list; 196, 197; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:users; 200, block; 200, 201; 200, 215; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:LOGGER; 205, identifier:debug; 206, argument_list; 206, 207; 206, 208; 206, 209; 206, 212; 207, string:"match %s with User(id=%d, username=%s)"; 208, identifier:username; 209, attribute; 209, 210; 209, 211; 210, identifier:user; 211, identifier:id; 212, attribute; 212, 213; 212, 214; 213, identifier:user; 214, identifier:username; 215, if_statement; 215, 216; 215, 221; 216, comparison_operator:==; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:user; 219, identifier:username; 220, identifier:username; 221, block; 221, 222; 221, 235; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:LOGGER; 226, identifier:debug; 227, argument_list; 227, 228; 227, 229; 227, 232; 228, string:"found %d %s"; 229, attribute; 229, 230; 229, 231; 230, identifier:user; 231, identifier:id; 232, attribute; 232, 233; 232, 234; 233, identifier:user; 234, identifier:username; 235, return_statement; 235, 236; 236, identifier:user; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:user; 240, call; 240, 241; 240, 242; 241, identifier:UserModel; 242, argument_list; 242, 243; 242, 257; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:id; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:random; 248, identifier:randint; 249, argument_list; 249, 250; 249, 251; 250, integer:1; 251, binary_operator:-; 251, 252; 251, 256; 252, parenthesized_expression; 252, 253; 253, binary_operator:<<; 253, 254; 253, 255; 254, integer:1; 255, integer:32; 256, integer:1; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:username; 259, identifier:username; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:LOGGER; 264, identifier:debug; 265, argument_list; 265, 266; 265, 267; 265, 270; 266, string:"add User(id=%d, username=%s) to cache."; 267, attribute; 267, 268; 267, 269; 268, identifier:user; 269, identifier:id; 270, attribute; 270, 271; 270, 272; 271, identifier:user; 272, identifier:username; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 282; 275, subscript; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:users; 279, attribute; 279, 280; 279, 281; 280, identifier:user; 281, identifier:id; 282, identifier:user; 283, return_statement; 283, 284; 284, conditional_expression:if; 284, 285; 284, 286; 284, 292; 285, identifier:user; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:user_can_authenticate; 290, argument_list; 290, 291; 291, identifier:user; 292, None | def authenticate(self, request, remote_user=None):
if not remote_user:
remote_user = request
if not remote_user:
return None
user = None
username = self.clean_username(remote_user)
try:
if self.create_unknown_user:
defaults = {}
if isinstance(request, dict):
session_data = request
if 'full_name' in session_data:
first_name, _, last_name = full_name_natural_split(
session_data['full_name'])
defaults.update({
'first_name': first_name,
'last_name': last_name
})
for key in ('email', 'first_name', 'last_name'):
if key in session_data:
defaults.update({key: session_data[key]})
user, created = UserModel._default_manager.get_or_create(**{
UserModel.USERNAME_FIELD: username,
'defaults': defaults,
})
if created:
LOGGER.debug("created user '%s' in database.", username)
user = self.configure_user(user)
else:
try:
user = UserModel._default_manager.get_by_natural_key(
username)
except UserModel.DoesNotExist:
pass
except DatabaseError as err:
LOGGER.debug("User table missing from database? (err:%s)", err)
for user in six.itervalues(self.users):
LOGGER.debug("match %s with User(id=%d, username=%s)",
username, user.id, user.username)
if user.username == username:
LOGGER.debug("found %d %s", user.id, user.username)
return user
user = UserModel(
id=random.randint(1, (1 << 32) - 1), username=username)
LOGGER.debug("add User(id=%d, username=%s) to cache.",
user.id, user.username)
self.users[user.id] = user
return user if self.user_can_authenticate(user) else None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:bc2pg; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 4, identifier:dataset; 5, identifier:db_url; 6, identifier:table; 7, identifier:schema; 8, identifier:query; 9, identifier:append; 10, identifier:pagesize; 11, identifier:sortby; 12, identifier:max_workers; 13, block; 13, 14; 13, 23; 13, 42; 13, 50; 13, 58; 13, 67; 13, 93; 13, 111; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:src; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:bcdata; 20, identifier:validate_name; 21, argument_list; 21, 22; 22, identifier:dataset; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, pattern_list; 25, 26; 25, 27; 26, identifier:src_schema; 27, identifier:src_table; 28, list_comprehension; 28, 29; 28, 34; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:i; 32, identifier:lower; 33, argument_list; 34, for_in_clause; 34, 35; 34, 36; 35, identifier:i; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:src; 39, identifier:split; 40, argument_list; 40, 41; 41, string:"."; 42, if_statement; 42, 43; 42, 45; 43, not_operator; 43, 44; 44, identifier:schema; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:schema; 49, identifier:src_schema; 50, if_statement; 50, 51; 50, 53; 51, not_operator; 51, 52; 52, identifier:table; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:table; 57, identifier:src_table; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:conn; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:pgdata; 64, identifier:connect; 65, argument_list; 65, 66; 66, identifier:db_url; 67, if_statement; 67, 68; 67, 73; 68, comparison_operator:not; 68, 69; 68, 70; 69, identifier:schema; 70, attribute; 70, 71; 70, 72; 71, identifier:conn; 72, identifier:schemas; 73, block; 73, 74; 73, 86; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:click; 78, identifier:echo; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, string:"Schema {} does not exist, creating it"; 83, identifier:format; 84, argument_list; 84, 85; 85, identifier:schema; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:conn; 90, identifier:create_schema; 91, argument_list; 91, 92; 92, identifier:schema; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:param_dicts; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:bcdata; 99, identifier:define_request; 100, argument_list; 100, 101; 100, 102; 100, 105; 100, 108; 101, identifier:dataset; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:query; 104, identifier:query; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:sortby; 107, identifier:sortby; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:pagesize; 110, identifier:pagesize; 111, try_statement; 111, 112; 111, 377; 112, block; 112, 113; 112, 125; 112, 135; 112, 142; 112, 170; 112, 217; 112, 359; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:payload; 116, call; 116, 117; 116, 118; 117, identifier:urlencode; 118, argument_list; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:param_dicts; 121, integer:0; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:doseq; 124, True; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:url; 128, binary_operator:+; 128, 129; 128, 134; 129, binary_operator:+; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:bcdata; 132, identifier:WFS_URL; 133, string:"?"; 134, identifier:payload; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:db; 138, call; 138, 139; 138, 140; 139, identifier:parse_db_url; 140, argument_list; 140, 141; 141, identifier:db_url; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:db_string; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, string:"PG:host={h} user={u} dbname={db} password={pwd}"; 148, identifier:format; 149, argument_list; 149, 150; 149, 155; 149, 160; 149, 165; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:h; 152, subscript; 152, 153; 152, 154; 153, identifier:db; 154, string:"host"; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:u; 157, subscript; 157, 158; 157, 159; 158, identifier:db; 159, string:"user"; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:db; 162, subscript; 162, 163; 162, 164; 163, identifier:db; 164, string:"database"; 165, keyword_argument; 165, 166; 165, 167; 166, identifier:pwd; 167, subscript; 167, 168; 167, 169; 168, identifier:db; 169, string:"password"; 170, if_statement; 170, 171; 170, 173; 171, not_operator; 171, 172; 172, identifier:append; 173, block; 173, 174; 173, 198; 173, 210; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:command; 177, list:[
"ogr2ogr",
"-lco",
"OVERWRITE=YES",
"-lco",
"SCHEMA={}".format(schema),
"-lco",
"GEOMETRY_NAME=geom",
"-f",
"PostgreSQL",
db_string,
"-t_srs",
"EPSG:3005",
"-nln",
table,
url,
]; 177, 178; 177, 179; 177, 180; 177, 181; 177, 182; 177, 188; 177, 189; 177, 190; 177, 191; 177, 192; 177, 193; 177, 194; 177, 195; 177, 196; 177, 197; 178, string:"ogr2ogr"; 179, string:"-lco"; 180, string:"OVERWRITE=YES"; 181, string:"-lco"; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, string:"SCHEMA={}"; 185, identifier:format; 186, argument_list; 186, 187; 187, identifier:schema; 188, string:"-lco"; 189, string:"GEOMETRY_NAME=geom"; 190, string:"-f"; 191, string:"PostgreSQL"; 192, identifier:db_string; 193, string:"-t_srs"; 194, string:"EPSG:3005"; 195, string:"-nln"; 196, identifier:table; 197, identifier:url; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:click; 202, identifier:echo; 203, argument_list; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, string:" "; 207, identifier:join; 208, argument_list; 208, 209; 209, identifier:command; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:subprocess; 214, identifier:run; 215, argument_list; 215, 216; 216, identifier:command; 217, if_statement; 217, 218; 217, 226; 218, boolean_operator:or; 218, 219; 218, 225; 219, comparison_operator:>; 219, 220; 219, 224; 220, call; 220, 221; 220, 222; 221, identifier:len; 222, argument_list; 222, 223; 223, identifier:param_dicts; 224, integer:1; 225, identifier:append; 226, block; 226, 227; 226, 240; 226, 244; 226, 303; 226, 310; 227, if_statement; 227, 228; 227, 229; 227, 234; 228, identifier:append; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:idx; 233, integer:0; 234, else_clause; 234, 235; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:idx; 239, integer:1; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:commands; 243, list:[]; 244, for_statement; 244, 245; 244, 248; 244, 256; 245, pattern_list; 245, 246; 245, 247; 246, identifier:chunk; 247, identifier:paramdict; 248, call; 248, 249; 248, 250; 249, identifier:enumerate; 250, argument_list; 250, 251; 251, subscript; 251, 252; 251, 253; 252, identifier:param_dicts; 253, slice; 253, 254; 253, 255; 254, identifier:idx; 255, colon; 256, block; 256, 257; 256, 267; 256, 277; 256, 296; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:payload; 260, call; 260, 261; 260, 262; 261, identifier:urlencode; 262, argument_list; 262, 263; 262, 264; 263, identifier:paramdict; 264, keyword_argument; 264, 265; 264, 266; 265, identifier:doseq; 266, True; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:url; 270, binary_operator:+; 270, 271; 270, 276; 271, binary_operator:+; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:bcdata; 274, identifier:WFS_URL; 275, string:"?"; 276, identifier:payload; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:command; 280, list:[
"ogr2ogr",
"-update",
"-append",
"-f",
"PostgreSQL",
db_string + " active_schema=" + schema,
"-t_srs",
"EPSG:3005",
"-nln",
table,
url,
]; 280, 281; 280, 282; 280, 283; 280, 284; 280, 285; 280, 286; 280, 291; 280, 292; 280, 293; 280, 294; 280, 295; 281, string:"ogr2ogr"; 282, string:"-update"; 283, string:"-append"; 284, string:"-f"; 285, string:"PostgreSQL"; 286, binary_operator:+; 286, 287; 286, 290; 287, binary_operator:+; 287, 288; 287, 289; 288, identifier:db_string; 289, string:" active_schema="; 290, identifier:schema; 291, string:"-t_srs"; 292, string:"EPSG:3005"; 293, string:"-nln"; 294, identifier:table; 295, identifier:url; 296, expression_statement; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:commands; 300, identifier:append; 301, argument_list; 301, 302; 302, identifier:command; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 306; 305, identifier:pool; 306, call; 306, 307; 306, 308; 307, identifier:Pool; 308, argument_list; 308, 309; 309, identifier:max_workers; 310, with_statement; 310, 311; 310, 337; 311, with_clause; 311, 312; 312, with_item; 312, 313; 313, as_pattern; 313, 314; 313, 335; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:click; 317, identifier:progressbar; 318, argument_list; 318, 319; 318, 329; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:pool; 322, identifier:imap; 323, argument_list; 323, 324; 323, 328; 324, call; 324, 325; 324, 326; 325, identifier:partial; 326, argument_list; 326, 327; 327, identifier:call; 328, identifier:commands; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:length; 331, call; 331, 332; 331, 333; 332, identifier:len; 333, argument_list; 333, 334; 334, identifier:param_dicts; 335, as_pattern_target; 335, 336; 336, identifier:bar; 337, block; 337, 338; 338, for_statement; 338, 339; 338, 340; 338, 341; 339, identifier:returncode; 340, identifier:bar; 341, block; 341, 342; 342, if_statement; 342, 343; 342, 346; 343, comparison_operator:!=; 343, 344; 343, 345; 344, identifier:returncode; 345, integer:0; 346, block; 346, 347; 347, expression_statement; 347, 348; 348, call; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:click; 351, identifier:echo; 352, argument_list; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, string:"Command failed: {}"; 356, identifier:format; 357, argument_list; 357, 358; 358, identifier:returncode; 359, expression_statement; 359, 360; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:click; 363, identifier:echo; 364, argument_list; 364, 365; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, string:"Load of {} to {} in {} complete"; 368, identifier:format; 369, argument_list; 369, 370; 369, 371; 369, 376; 370, identifier:src; 371, binary_operator:+; 371, 372; 371, 375; 372, binary_operator:+; 372, 373; 372, 374; 373, identifier:schema; 374, string:"."; 375, identifier:table; 376, identifier:db_url; 377, except_clause; 377, 378; 377, 379; 378, identifier:Exception; 379, block; 379, 380; 379, 387; 380, expression_statement; 380, 381; 381, call; 381, 382; 381, 385; 382, attribute; 382, 383; 382, 384; 383, identifier:click; 384, identifier:echo; 385, argument_list; 385, 386; 386, string:"Data load failed"; 387, raise_statement; 387, 388; 388, call; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:click; 391, identifier:Abort; 392, argument_list | def bc2pg(dataset, db_url, table, schema, query, append, pagesize, sortby, max_workers):
src = bcdata.validate_name(dataset)
src_schema, src_table = [i.lower() for i in src.split(".")]
if not schema:
schema = src_schema
if not table:
table = src_table
conn = pgdata.connect(db_url)
if schema not in conn.schemas:
click.echo("Schema {} does not exist, creating it".format(schema))
conn.create_schema(schema)
param_dicts = bcdata.define_request(
dataset, query=query, sortby=sortby, pagesize=pagesize
)
try:
payload = urlencode(param_dicts[0], doseq=True)
url = bcdata.WFS_URL + "?" + payload
db = parse_db_url(db_url)
db_string = "PG:host={h} user={u} dbname={db} password={pwd}".format(
h=db["host"], u=db["user"], db=db["database"], pwd=db["password"]
)
if not append:
command = [
"ogr2ogr",
"-lco",
"OVERWRITE=YES",
"-lco",
"SCHEMA={}".format(schema),
"-lco",
"GEOMETRY_NAME=geom",
"-f",
"PostgreSQL",
db_string,
"-t_srs",
"EPSG:3005",
"-nln",
table,
url,
]
click.echo(" ".join(command))
subprocess.run(command)
if len(param_dicts) > 1 or append:
if append:
idx = 0
else:
idx = 1
commands = []
for chunk, paramdict in enumerate(param_dicts[idx:]):
payload = urlencode(paramdict, doseq=True)
url = bcdata.WFS_URL + "?" + payload
command = [
"ogr2ogr",
"-update",
"-append",
"-f",
"PostgreSQL",
db_string + " active_schema=" + schema,
"-t_srs",
"EPSG:3005",
"-nln",
table,
url,
]
commands.append(command)
pool = Pool(max_workers)
with click.progressbar(
pool.imap(partial(call), commands), length=len(param_dicts)
) as bar:
for returncode in bar:
if returncode != 0:
click.echo("Command failed: {}".format(returncode))
click.echo(
"Load of {} to {} in {} complete".format(src, schema + "." + table, db_url)
)
except Exception:
click.echo("Data load failed")
raise click.Abort() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:__parseFormat; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:fmt; 6, identifier:content; 7, default_parameter; 7, 8; 7, 9; 8, identifier:fps; 9, integer:25; 10, block; 10, 11; 10, 13; 10, 17; 10, 21; 11, expression_statement; 11, 12; 12, string:'''Actual parser. Please note that time_to is not required to process as not all subtitles
provide it.'''; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:headerFound; 16, False; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:subSection; 20, string:''; 21, for_statement; 21, 22; 21, 25; 21, 29; 22, pattern_list; 22, 23; 22, 24; 23, identifier:lineNo; 24, identifier:line; 25, call; 25, 26; 25, 27; 26, identifier:enumerate; 27, argument_list; 27, 28; 28, identifier:content; 29, block; 29, 30; 29, 40; 29, 58; 29, 69; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:line; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_initialLinePrepare; 37, argument_list; 37, 38; 37, 39; 38, identifier:line; 39, identifier:lineNo; 40, if_statement; 40, 41; 40, 56; 41, boolean_operator:and; 41, 42; 41, 51; 42, boolean_operator:and; 42, 43; 42, 47; 43, not_operator; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:fmt; 46, identifier:WITH_HEADER; 47, not_operator; 47, 48; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_formatFound; 51, comparison_operator:>; 51, 52; 51, 53; 52, identifier:lineNo; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_maxFmtSearch; 56, block; 56, 57; 57, return_statement; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:subSection; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, string:''; 64, identifier:join; 65, argument_list; 65, 66; 66, list:[subSection, line]; 66, 67; 66, 68; 67, identifier:subSection; 68, identifier:line; 69, if_statement; 69, 70; 69, 76; 69, 114; 70, boolean_operator:and; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:fmt; 73, identifier:WITH_HEADER; 74, not_operator; 74, 75; 75, identifier:headerFound; 76, block; 76, 77; 76, 85; 76, 101; 77, if_statement; 77, 78; 77, 83; 78, comparison_operator:>; 78, 79; 78, 80; 79, identifier:lineNo; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:_maxHeaderLen; 83, block; 83, 84; 84, return_statement; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:headerFound; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:fmt; 91, identifier:addHeaderInfo; 92, argument_list; 92, 93; 92, 94; 93, identifier:subSection; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_subtitles; 99, identifier:header; 100, argument_list; 101, if_statement; 101, 102; 101, 103; 102, identifier:headerFound; 103, block; 103, 104; 103, 110; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:_formatFound; 109, True; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:subSection; 113, string:''; 114, elif_clause; 114, 115; 114, 131; 115, boolean_operator:or; 115, 116; 115, 122; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:fmt; 119, identifier:subtitleEnds; 120, argument_list; 120, 121; 121, identifier:line; 122, comparison_operator:==; 122, 123; 122, 127; 123, parenthesized_expression; 123, 124; 124, binary_operator:+; 124, 125; 124, 126; 125, identifier:lineNo; 126, integer:1; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, identifier:content; 131, block; 131, 132; 131, 142; 131, 183; 131, 235; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:subtitle; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:fmt; 138, identifier:createSubtitle; 139, argument_list; 139, 140; 139, 141; 140, identifier:fps; 141, identifier:subSection; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:is; 143, 144; 143, 145; 144, identifier:subtitle; 145, None; 146, block; 146, 147; 147, if_statement; 147, 148; 147, 154; 147, 160; 147, 180; 148, comparison_operator:in; 148, 149; 148, 150; 149, identifier:subSection; 150, tuple; 150, 151; 150, 152; 150, 153; 151, string:'\n'; 152, string:'\r\n'; 153, string:'\r'; 154, block; 154, 155; 154, 159; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:subSection; 158, string:''; 159, continue_statement; 160, elif_clause; 160, 161; 160, 170; 161, comparison_operator:>; 161, 162; 161, 169; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:_subtitles; 167, identifier:size; 168, argument_list; 169, integer:0; 170, block; 170, 171; 171, raise_statement; 171, 172; 172, call; 172, 173; 172, 174; 173, identifier:SubParsingError; 174, argument_list; 174, 175; 174, 179; 175, call; 175, 176; 175, 177; 176, identifier:_; 177, argument_list; 177, 178; 178, string:"Parsing error"; 179, identifier:lineNo; 180, else_clause; 180, 181; 181, block; 181, 182; 182, return_statement; 183, if_statement; 183, 184; 183, 191; 183, 221; 183, 232; 184, boolean_operator:and; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:subtitle; 187, identifier:start; 188, attribute; 188, 189; 188, 190; 189, identifier:subtitle; 190, identifier:text; 191, block; 191, 192; 191, 198; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:_formatFound; 197, True; 198, try_statement; 198, 199; 198, 209; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:_subtitles; 206, identifier:append; 207, argument_list; 207, 208; 208, identifier:subtitle; 209, except_clause; 209, 210; 209, 214; 210, as_pattern; 210, 211; 210, 212; 211, identifier:SubException; 212, as_pattern_target; 212, 213; 213, identifier:msg; 214, block; 214, 215; 215, raise_statement; 215, 216; 216, call; 216, 217; 216, 218; 217, identifier:SubParsingError; 218, argument_list; 218, 219; 218, 220; 219, identifier:msg; 220, identifier:lineNo; 221, elif_clause; 221, 222; 221, 230; 222, boolean_operator:and; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:subtitle; 225, identifier:start; 226, not_operator; 226, 227; 227, attribute; 227, 228; 227, 229; 228, identifier:subtitle; 229, identifier:text; 230, block; 230, 231; 231, pass_statement; 232, else_clause; 232, 233; 233, block; 233, 234; 234, return_statement; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:subSection; 238, string:'' | def __parseFormat(self, fmt, content, fps = 25):
'''Actual parser. Please note that time_to is not required to process as not all subtitles
provide it.'''
headerFound = False
subSection = ''
for lineNo, line in enumerate(content):
line = self._initialLinePrepare(line, lineNo)
if not fmt.WITH_HEADER and not self._formatFound and lineNo > self._maxFmtSearch:
return
subSection = ''.join([subSection, line])
if fmt.WITH_HEADER and not headerFound:
if lineNo > self._maxHeaderLen:
return
headerFound = fmt.addHeaderInfo(subSection, self._subtitles.header())
if headerFound:
self._formatFound = True
subSection = ''
elif fmt.subtitleEnds(line) or (lineNo + 1) == len(content):
subtitle = fmt.createSubtitle(fps, subSection)
if subtitle is None:
if subSection in ('\n', '\r\n', '\r'):
subSection = ''
continue
elif self._subtitles.size() > 0:
raise SubParsingError(_("Parsing error"), lineNo)
else:
return
if subtitle.start and subtitle.text:
self._formatFound = True
try:
self._subtitles.append(subtitle)
except SubException as msg:
raise SubParsingError(msg, lineNo)
elif subtitle.start and not subtitle.text:
pass
else:
return
subSection = '' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:_get_json; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:model; 6, default_parameter; 6, 7; 6, 8; 7, identifier:space; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:rel_path; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:extra_params; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:get_all; 17, None; 18, block; 18, 19; 18, 37; 18, 45; 18, 57; 18, 82; 18, 146; 19, if_statement; 19, 20; 19, 29; 20, boolean_operator:and; 20, 21; 20, 24; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:space; 23, None; 24, comparison_operator:not; 24, 25; 24, 26; 25, identifier:model; 26, tuple; 26, 27; 26, 28; 27, identifier:Space; 28, identifier:Event; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:Exception; 33, argument_list; 33, 34; 34, concatenated_string; 34, 35; 34, 36; 35, string:'In general, `API._get_json` should always '; 36, string:'be called with a `space` argument.'; 37, if_statement; 37, 38; 37, 40; 38, not_operator; 38, 39; 39, identifier:extra_params; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:extra_params; 44, dictionary; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:extra_params; 49, string:'page'; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:extra_params; 53, identifier:get; 54, argument_list; 54, 55; 54, 56; 55, string:'page'; 56, integer:1; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:url; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, string:'{0}/{1}/{2}.json?{3}'; 63, identifier:format; 64, argument_list; 64, 65; 64, 68; 64, 71; 64, 76; 65, attribute; 65, 66; 65, 67; 66, identifier:settings; 67, identifier:API_ROOT_PATH; 68, attribute; 68, 69; 68, 70; 69, identifier:settings; 70, identifier:API_VERSION; 71, boolean_operator:or; 71, 72; 71, 73; 72, identifier:rel_path; 73, attribute; 73, 74; 73, 75; 74, identifier:model; 75, identifier:rel_path; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:urllib; 79, identifier:urlencode; 80, argument_list; 80, 81; 81, identifier:extra_params; 82, if_statement; 82, 83; 82, 92; 82, 101; 83, boolean_operator:and; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:cache_responses; 87, comparison_operator:in; 87, 88; 87, 89; 88, identifier:url; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:cache; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:response; 96, subscript; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:cache; 100, identifier:url; 101, else_clause; 101, 102; 102, block; 102, 103; 102, 117; 102, 133; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:headers; 106, dictionary; 106, 107; 106, 112; 107, pair; 107, 108; 107, 109; 108, string:'X-Api-Key'; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:key; 112, pair; 112, 113; 112, 114; 113, string:'X-Api-Secret'; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:secret; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:response; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:session; 125, identifier:get; 126, argument_list; 126, 127; 126, 130; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:url; 129, identifier:url; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:headers; 132, identifier:headers; 133, if_statement; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:cache_responses; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 145; 140, subscript; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:cache; 144, identifier:url; 145, identifier:response; 146, if_statement; 146, 147; 146, 152; 146, 253; 146, 262; 147, comparison_operator:==; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:response; 150, identifier:status_code; 151, integer:200; 152, block; 152, 153; 152, 157; 152, 165; 152, 200; 152, 210; 152, 251; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:results; 156, list:[]; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:json_response; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:response; 163, identifier:json; 164, argument_list; 165, for_statement; 165, 166; 165, 167; 165, 168; 166, identifier:obj; 167, identifier:json_response; 168, block; 168, 169; 168, 178; 168, 184; 168, 193; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:instance; 172, call; 172, 173; 172, 174; 173, identifier:model; 174, argument_list; 174, 175; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:data; 177, identifier:obj; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:instance; 182, identifier:api; 183, identifier:self; 184, if_statement; 184, 185; 184, 186; 185, identifier:space; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:instance; 191, identifier:space; 192, identifier:space; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:results; 197, identifier:append; 198, argument_list; 198, 199; 199, identifier:instance; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:per_page; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:extra_params; 206, identifier:get; 207, argument_list; 207, 208; 207, 209; 208, string:'per_page'; 209, None; 210, if_statement; 210, 211; 210, 227; 211, parenthesized_expression; 211, 212; 212, boolean_operator:and; 212, 213; 212, 221; 213, boolean_operator:and; 213, 214; 213, 217; 214, boolean_operator:and; 214, 215; 214, 216; 215, identifier:get_all; 216, identifier:per_page; 217, call; 217, 218; 217, 219; 218, identifier:len; 219, argument_list; 219, 220; 220, identifier:json_response; 221, comparison_operator:==; 221, 222; 221, 223; 222, identifier:per_page; 223, call; 223, 224; 223, 225; 224, identifier:len; 225, argument_list; 225, 226; 226, identifier:json_response; 227, block; 227, 228; 227, 234; 228, expression_statement; 228, 229; 229, augmented_assignment:+=; 229, 230; 229, 233; 230, subscript; 230, 231; 230, 232; 231, identifier:extra_params; 232, string:'page'; 233, integer:1; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:results; 237, binary_operator:+; 237, 238; 237, 239; 238, identifier:results; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:_get_json; 243, argument_list; 243, 244; 243, 245; 243, 246; 243, 247; 243, 248; 244, identifier:model; 245, identifier:space; 246, identifier:rel_path; 247, identifier:extra_params; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:get_all; 250, identifier:get_all; 251, return_statement; 251, 252; 252, identifier:results; 253, elif_clause; 253, 254; 253, 259; 254, comparison_operator:==; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:response; 257, identifier:status_code; 258, integer:204; 259, block; 259, 260; 260, return_statement; 260, 261; 261, list:[]; 262, else_clause; 262, 263; 263, block; 263, 264; 264, raise_statement; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:Exception; 267, argument_list; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, string:'Code {0} returned from `{1}`. Response text: "{2}".'; 271, identifier:format; 272, argument_list; 272, 273; 272, 276; 272, 277; 273, attribute; 273, 274; 273, 275; 274, identifier:response; 275, identifier:status_code; 276, identifier:url; 277, attribute; 277, 278; 277, 279; 278, identifier:response; 279, identifier:text | def _get_json(self, model, space=None, rel_path=None, extra_params=None, get_all=None):
if space is None and model not in (Space, Event):
raise Exception(
'In general, `API._get_json` should always '
'be called with a `space` argument.'
)
if not extra_params:
extra_params = {}
extra_params['page'] = extra_params.get('page', 1)
url = '{0}/{1}/{2}.json?{3}'.format(
settings.API_ROOT_PATH,
settings.API_VERSION,
rel_path or model.rel_path,
urllib.urlencode(extra_params),
)
if self.cache_responses and url in self.cache:
response = self.cache[url]
else:
headers = {
'X-Api-Key': self.key,
'X-Api-Secret': self.secret,
}
response = self.session.get(url=url, headers=headers)
if self.cache_responses:
self.cache[url] = response
if response.status_code == 200:
results = []
json_response = response.json()
for obj in json_response:
instance = model(data=obj)
instance.api = self
if space:
instance.space = space
results.append(instance)
per_page = extra_params.get('per_page', None)
if (
get_all
and per_page
and len(json_response)
and per_page == len(json_response)
):
extra_params['page'] += 1
results = results + self._get_json(model, space, rel_path, extra_params, get_all=get_all)
return results
elif response.status_code == 204:
return []
else:
raise Exception(
'Code {0} returned from `{1}`. Response text: "{2}".'.format(
response.status_code,
url,
response.text
)
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:load_config; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:app_name; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 14; 9, 24; 9, 34; 9, 44; 9, 72; 9, 76; 9, 96; 9, 121; 9, 125; 9, 383; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:configure_logging; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:prefix; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:kwargs; 20, identifier:get; 21, argument_list; 21, 22; 21, 23; 22, string:'prefix'; 23, string:'etc'; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:verbose; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:kwargs; 30, identifier:get; 31, argument_list; 31, 32; 31, 33; 32, string:'verbose'; 33, False; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:location; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:kwargs; 40, identifier:get; 41, argument_list; 41, 42; 41, 43; 42, string:'location'; 43, None; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:passphrase; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:kwargs; 50, identifier:get; 51, argument_list; 51, 52; 51, 53; 52, string:'passphrase'; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:os; 56, identifier:getenv; 57, argument_list; 57, 58; 57, 65; 58, binary_operator:%; 58, 59; 58, 60; 59, string:"%s_SETTINGS_CRYPT_KEY"; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:app_name; 63, identifier:upper; 64, argument_list; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:os; 68, identifier:getenv; 69, argument_list; 69, 70; 69, 71; 70, string:"SETTINGS_CRYPT_KEY"; 71, None; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:confnames; 75, identifier:args; 76, if_statement; 76, 77; 76, 79; 77, not_operator; 77, 78; 78, identifier:location; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:location; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:os; 86, identifier:getenv; 87, argument_list; 87, 88; 87, 95; 88, binary_operator:%; 88, 89; 88, 90; 89, string:"%s_SETTINGS_LOCATION"; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:app_name; 93, identifier:upper; 94, argument_list; 95, None; 96, if_statement; 96, 97; 96, 99; 97, not_operator; 97, 98; 98, identifier:location; 99, block; 99, 100; 99, 110; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:location; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:os; 106, identifier:getenv; 107, argument_list; 107, 108; 107, 109; 108, string:"SETTINGS_LOCATION"; 109, None; 110, if_statement; 110, 111; 110, 112; 111, identifier:location; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:location; 116, binary_operator:%; 116, 117; 116, 118; 117, string:"%s/%s"; 118, tuple; 118, 119; 118, 120; 119, identifier:location; 120, identifier:app_name; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:config; 124, dictionary; 125, for_statement; 125, 126; 125, 127; 125, 128; 126, identifier:confname; 127, identifier:confnames; 128, block; 128, 129; 128, 133; 128, 239; 128, 283; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:content; 132, None; 133, if_statement; 133, 134; 133, 142; 134, boolean_operator:and; 134, 135; 134, 136; 135, identifier:location; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:location; 139, identifier:startswith; 140, argument_list; 140, 141; 141, string:'s3://'; 142, block; 142, 143; 143, try_statement; 143, 144; 143, 235; 144, block; 144, 145; 144, 148; 144, 162; 145, import_statement; 145, 146; 146, dotted_name; 146, 147; 147, identifier:boto; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 154; 150, pattern_list; 150, 151; 150, 152; 150, 153; 151, identifier:_; 152, identifier:bucket_name; 153, identifier:prefix; 154, subscript; 154, 155; 154, 159; 155, call; 155, 156; 155, 157; 156, identifier:urlparse; 157, argument_list; 157, 158; 158, identifier:location; 159, slice; 159, 160; 159, 161; 160, colon; 161, integer:3; 162, try_statement; 162, 163; 162, 218; 163, block; 163, 164; 163, 172; 163, 181; 163, 189; 163, 198; 163, 206; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:conn; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:boto; 170, identifier:connect_s3; 171, argument_list; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:bucket; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:conn; 178, identifier:get_bucket; 179, argument_list; 179, 180; 180, identifier:bucket_name; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:key_name; 184, binary_operator:%; 184, 185; 184, 186; 185, string:'%s/%s'; 186, tuple; 186, 187; 186, 188; 187, identifier:prefix; 188, identifier:confname; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:key; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:bucket; 195, identifier:get_key; 196, argument_list; 196, 197; 197, identifier:key_name; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:content; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:key; 204, identifier:get_contents_as_string; 205, argument_list; 206, if_statement; 206, 207; 206, 208; 207, identifier:verbose; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:LOGGER; 213, identifier:info; 214, argument_list; 214, 215; 214, 216; 214, 217; 215, string:"config loaded from 's3://%s/%s'"; 216, identifier:bucket_name; 217, identifier:key_name; 218, except_clause; 218, 219; 218, 233; 219, as_pattern; 219, 220; 219, 231; 220, tuple; 220, 221; 220, 226; 221, attribute; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:boto; 224, identifier:exception; 225, identifier:NoAuthHandlerFound; 226, attribute; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:boto; 229, identifier:exception; 230, identifier:S3ResponseError; 231, as_pattern_target; 231, 232; 232, identifier:_; 233, block; 233, 234; 234, pass_statement; 235, except_clause; 235, 236; 235, 237; 236, identifier:ImportError; 237, block; 237, 238; 238, pass_statement; 239, if_statement; 239, 240; 239, 242; 240, not_operator; 240, 241; 241, identifier:content; 242, block; 242, 243; 242, 260; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:confpath; 246, call; 246, 247; 246, 248; 247, identifier:locate_config; 248, argument_list; 248, 249; 248, 250; 248, 251; 248, 254; 248, 257; 249, identifier:confname; 250, identifier:app_name; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:location; 253, identifier:location; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:prefix; 256, identifier:prefix; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:verbose; 259, identifier:verbose; 260, if_statement; 260, 261; 260, 262; 261, identifier:confpath; 262, block; 262, 263; 263, with_statement; 263, 264; 263, 274; 264, with_clause; 264, 265; 265, with_item; 265, 266; 266, as_pattern; 266, 267; 266, 272; 267, call; 267, 268; 267, 269; 268, identifier:open; 269, argument_list; 269, 270; 269, 271; 270, identifier:confpath; 271, string:'rb'; 272, as_pattern_target; 272, 273; 273, identifier:conffile; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:content; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:conffile; 281, identifier:read; 282, argument_list; 283, if_statement; 283, 284; 283, 285; 284, identifier:content; 285, block; 285, 286; 285, 299; 285, 315; 286, if_statement; 286, 287; 286, 288; 287, identifier:passphrase; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:content; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:crypt; 295, identifier:decrypt; 296, argument_list; 296, 297; 296, 298; 297, identifier:content; 298, identifier:passphrase; 299, if_statement; 299, 300; 299, 305; 300, call; 300, 301; 300, 302; 301, identifier:hasattr; 302, argument_list; 302, 303; 302, 304; 303, identifier:content; 304, string:'decode'; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:content; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:content; 312, identifier:decode; 313, argument_list; 313, 314; 314, string:'utf-8'; 315, for_statement; 315, 316; 315, 317; 315, 323; 316, identifier:line; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:content; 320, identifier:split; 321, argument_list; 321, 322; 322, string:'\n'; 323, block; 323, 324; 324, if_statement; 324, 325; 324, 329; 324, 347; 325, not_operator; 325, 326; 326, attribute; 326, 327; 326, 328; 327, identifier:line; 328, identifier:startswith; 329, ERROR; 329, 330; 329, 346; 330, call; 330, 331; 330, 332; 331, string:'
look = re.match(r'; 332, argument_list; 332, 333; 332, 334; 333, ERROR:\; 334, binary_operator:+; 334, 335; 334, 336; 334, 337; 335, identifier:w; 336, ERROR; 337, binary_operator:*; 337, 338; 337, 342; 337, 345; 338, binary_operator:*; 338, 339; 338, 340; 338, 341; 339, identifier:s; 340, ERROR; 341, identifier:s; 342, ERROR; 342, 343; 343, tuple; 343, 344; 344, ERROR; 345, identifier:line; 346, identifier:look; 347, block; 347, 348; 348, try_statement; 348, 349; 348, 379; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:config; 354, identifier:update; 355, argument_list; 355, 356; 356, dictionary; 356, 357; 357, pair; 357, 358; 357, 368; 358, call; 358, 359; 358, 367; 359, attribute; 359, 360; 359, 366; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:look; 363, identifier:group; 364, argument_list; 364, 365; 365, integer:1; 366, identifier:upper; 367, argument_list; 368, call; 368, 369; 368, 370; 369, identifier:eval; 370, argument_list; 370, 371; 370, 377; 370, 378; 371, call; 371, 372; 371, 375; 372, attribute; 372, 373; 372, 374; 373, identifier:look; 374, identifier:group; 375, argument_list; 375, 376; 376, integer:2; 377, dictionary; 378, dictionary; 379, except_clause; 379, 380; 379, 381; 380, identifier:Exception; 381, block; 381, 382; 382, raise_statement; 383, return_statement; 383, 384; 384, identifier:config | def load_config(app_name, *args, **kwargs):
configure_logging()
prefix = kwargs.get('prefix', 'etc')
verbose = kwargs.get('verbose', False)
location = kwargs.get('location', None)
passphrase = kwargs.get('passphrase',
os.getenv("%s_SETTINGS_CRYPT_KEY" % app_name.upper(),
os.getenv("SETTINGS_CRYPT_KEY", None)))
confnames = args
if not location:
location = os.getenv("%s_SETTINGS_LOCATION" % app_name.upper(), None)
if not location:
location = os.getenv("SETTINGS_LOCATION", None)
if location:
location = "%s/%s" % (location, app_name)
config = {}
for confname in confnames:
content = None
if location and location.startswith('s3://'):
try:
import boto
_, bucket_name, prefix = urlparse(location)[:3]
try:
conn = boto.connect_s3()
bucket = conn.get_bucket(bucket_name)
key_name = '%s/%s' % (prefix, confname)
key = bucket.get_key(key_name)
content = key.get_contents_as_string()
if verbose:
LOGGER.info("config loaded from 's3://%s/%s'",
bucket_name, key_name)
except (boto.exception.NoAuthHandlerFound,
boto.exception.S3ResponseError) as _:
pass
except ImportError:
pass
if not content:
confpath = locate_config(
confname, app_name, location=location,
prefix=prefix, verbose=verbose)
if confpath:
with open(confpath, 'rb') as conffile:
content = conffile.read()
if content:
if passphrase:
content = crypt.decrypt(content, passphrase)
if hasattr(content, 'decode'):
content = content.decode('utf-8')
for line in content.split('\n'):
if not line.startswith('
look = re.match(r'(\w+)\s*=\s*(.*)', line)
if look:
try:
config.update({look.group(1).upper():
eval(look.group(2), {}, {})})
except Exception:
raise
return config |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:predict; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:tree; 5, identifier:x; 6, default_parameter; 6, 7; 6, 8; 7, identifier:y; 8, list:[]; 9, default_parameter; 9, 10; 9, 11; 10, identifier:dist; 11, False; 12, block; 12, 13; 12, 17; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:node_id; 16, integer:1; 17, while_statement; 17, 18; 17, 19; 18, integer:1; 19, block; 19, 20; 19, 26; 19, 213; 19, 223; 19, 267; 19, 287; 19, 294; 19, 349; 19, 397; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:nodes; 23, subscript; 23, 24; 23, 25; 24, identifier:tree; 25, identifier:node_id; 26, if_statement; 26, 27; 26, 34; 26, 76; 27, comparison_operator:==; 27, 28; 27, 33; 28, subscript; 28, 29; 28, 32; 29, subscript; 29, 30; 29, 31; 30, identifier:nodes; 31, integer:0; 32, integer:5; 33, string:"c"; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 49; 35, 62; 36, comparison_operator:<=; 36, 37; 36, 44; 37, subscript; 37, 38; 37, 39; 38, identifier:x; 39, subscript; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:nodes; 42, integer:0; 43, integer:1; 44, subscript; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:nodes; 47, integer:0; 48, integer:2; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, pattern_list; 52, 53; 52, 54; 53, identifier:index; 54, identifier:node_id; 55, expression_list; 55, 56; 55, 57; 56, integer:0; 57, subscript; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:nodes; 60, integer:0; 61, integer:0; 62, else_clause; 62, 63; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, pattern_list; 66, 67; 66, 68; 67, identifier:index; 68, identifier:node_id; 69, expression_list; 69, 70; 69, 71; 70, integer:1; 71, subscript; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:nodes; 74, integer:1; 75, integer:0; 76, else_clause; 76, 77; 77, block; 77, 78; 78, if_statement; 78, 79; 78, 92; 78, 105; 78, 132; 79, comparison_operator:in; 79, 80; 79, 87; 80, subscript; 80, 81; 80, 82; 81, identifier:x; 82, subscript; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:nodes; 85, integer:0; 86, integer:1; 87, subscript; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:nodes; 90, integer:0; 91, integer:2; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, pattern_list; 95, 96; 95, 97; 96, identifier:index; 97, identifier:node_id; 98, expression_list; 98, 99; 98, 100; 99, integer:0; 100, subscript; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:nodes; 103, integer:0; 104, integer:0; 105, elif_clause; 105, 106; 105, 119; 106, comparison_operator:in; 106, 107; 106, 114; 107, subscript; 107, 108; 107, 109; 108, identifier:x; 109, subscript; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:nodes; 112, integer:1; 113, integer:1; 114, subscript; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:nodes; 117, integer:1; 118, integer:2; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, pattern_list; 122, 123; 122, 124; 123, identifier:index; 124, identifier:node_id; 125, expression_list; 125, 126; 125, 127; 126, integer:1; 127, subscript; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:nodes; 130, integer:1; 131, integer:0; 132, else_clause; 132, 133; 133, block; 133, 134; 133, 156; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:node_id; 137, binary_operator:+; 137, 138; 137, 148; 138, binary_operator:+; 138, 139; 138, 147; 139, call; 139, 140; 139, 141; 140, identifier:str; 141, argument_list; 141, 142; 142, subscript; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:nodes; 145, integer:0; 146, integer:0; 147, string:","; 148, call; 148, 149; 148, 150; 149, identifier:str; 150, argument_list; 150, 151; 151, subscript; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:nodes; 154, integer:1; 155, integer:0; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, pattern_list; 158, 159; 158, 160; 159, identifier:index; 160, identifier:nodes; 161, expression_list; 161, 162; 161, 163; 162, integer:0; 163, list:[[0, 0, 0, {k: nodes[0][3].get(k, 0) + nodes[1][3].get(k, 0) for k in
set(nodes[0][3]) | set(nodes[1][3])}]]; 163, 164; 164, list:[0, 0, 0, {k: nodes[0][3].get(k, 0) + nodes[1][3].get(k, 0) for k in
set(nodes[0][3]) | set(nodes[1][3])}]; 164, 165; 164, 166; 164, 167; 164, 168; 165, integer:0; 166, integer:0; 167, integer:0; 168, dictionary_comprehension; 168, 169; 168, 194; 169, pair; 169, 170; 169, 171; 170, identifier:k; 171, binary_operator:+; 171, 172; 171, 183; 172, call; 172, 173; 172, 180; 173, attribute; 173, 174; 173, 179; 174, subscript; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:nodes; 177, integer:0; 178, integer:3; 179, identifier:get; 180, argument_list; 180, 181; 180, 182; 181, identifier:k; 182, integer:0; 183, call; 183, 184; 183, 191; 184, attribute; 184, 185; 184, 190; 185, subscript; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:nodes; 188, integer:1; 189, integer:3; 190, identifier:get; 191, argument_list; 191, 192; 191, 193; 192, identifier:k; 193, integer:0; 194, for_in_clause; 194, 195; 194, 196; 195, identifier:k; 196, binary_operator:|; 196, 197; 196, 205; 197, call; 197, 198; 197, 199; 198, identifier:set; 199, argument_list; 199, 200; 200, subscript; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:nodes; 203, integer:0; 204, integer:3; 205, call; 205, 206; 205, 207; 206, identifier:set; 207, argument_list; 207, 208; 208, subscript; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:nodes; 211, integer:1; 212, integer:3; 213, if_statement; 213, 214; 213, 221; 214, comparison_operator:in; 214, 215; 214, 216; 215, identifier:node_id; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:tree; 219, identifier:keys; 220, argument_list; 221, block; 221, 222; 222, continue_statement; 223, if_statement; 223, 224; 223, 225; 224, identifier:dist; 225, block; 225, 226; 225, 241; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:suma; 229, call; 229, 230; 229, 231; 230, identifier:sum; 231, argument_list; 231, 232; 232, call; 232, 233; 232, 240; 233, attribute; 233, 234; 233, 239; 234, subscript; 234, 235; 234, 238; 235, subscript; 235, 236; 235, 237; 236, identifier:nodes; 237, identifier:index; 238, integer:3; 239, identifier:values; 240, argument_list; 241, return_statement; 241, 242; 242, call; 242, 243; 242, 244; 243, identifier:Counter; 244, argument_list; 244, 245; 245, dictionary_comprehension; 245, 246; 245, 254; 246, pair; 246, 247; 246, 248; 247, identifier:k; 248, binary_operator:/; 248, 249; 248, 250; 249, identifier:v; 250, call; 250, 251; 250, 252; 251, identifier:float; 252, argument_list; 252, 253; 253, identifier:suma; 254, for_in_clause; 254, 255; 254, 258; 255, pattern_list; 255, 256; 255, 257; 256, identifier:k; 257, identifier:v; 258, call; 258, 259; 258, 266; 259, attribute; 259, 260; 259, 265; 260, subscript; 260, 261; 260, 264; 261, subscript; 261, 262; 261, 263; 262, identifier:nodes; 263, identifier:index; 264, integer:3; 265, identifier:iteritems; 266, argument_list; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:prediction; 270, call; 270, 271; 270, 272; 271, identifier:max; 272, argument_list; 272, 273; 272, 278; 273, subscript; 273, 274; 273, 277; 274, subscript; 274, 275; 274, 276; 275, identifier:nodes; 276, identifier:index; 277, integer:3; 278, keyword_argument; 278, 279; 278, 280; 279, identifier:key; 280, attribute; 280, 281; 280, 286; 281, subscript; 281, 282; 281, 285; 282, subscript; 282, 283; 282, 284; 283, identifier:nodes; 284, identifier:index; 285, integer:3; 286, identifier:get; 287, if_statement; 287, 288; 287, 291; 288, comparison_operator:==; 288, 289; 288, 290; 289, identifier:y; 290, list:[]; 291, block; 291, 292; 292, return_statement; 292, 293; 293, identifier:prediction; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:probs; 297, call; 297, 298; 297, 299; 298, identifier:sorted; 299, argument_list; 299, 300; 299, 340; 299, 346; 300, call; 300, 301; 300, 302; 301, identifier:zip; 302, argument_list; 302, 303; 302, 312; 303, call; 303, 304; 303, 311; 304, attribute; 304, 305; 304, 310; 305, subscript; 305, 306; 305, 309; 306, subscript; 306, 307; 306, 308; 307, identifier:nodes; 308, identifier:index; 309, integer:3; 310, identifier:keys; 311, argument_list; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:np; 315, identifier:true_divide; 316, argument_list; 316, 317; 316, 326; 317, call; 317, 318; 317, 325; 318, attribute; 318, 319; 318, 324; 319, subscript; 319, 320; 319, 323; 320, subscript; 320, 321; 320, 322; 321, identifier:nodes; 322, identifier:index; 323, integer:3; 324, identifier:values; 325, argument_list; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:np; 329, identifier:sum; 330, argument_list; 330, 331; 331, call; 331, 332; 331, 339; 332, attribute; 332, 333; 332, 338; 333, subscript; 333, 334; 333, 337; 334, subscript; 334, 335; 334, 336; 335, identifier:nodes; 336, identifier:index; 337, integer:3; 338, identifier:values; 339, argument_list; 340, keyword_argument; 340, 341; 340, 342; 341, identifier:key; 342, call; 342, 343; 342, 344; 343, identifier:itemgetter; 344, argument_list; 344, 345; 345, integer:1; 346, keyword_argument; 346, 347; 346, 348; 347, identifier:reverse; 348, True; 349, if_statement; 349, 350; 349, 353; 349, 376; 350, comparison_operator:==; 350, 351; 350, 352; 351, identifier:prediction; 352, identifier:y; 353, block; 353, 354; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 357; 356, identifier:margin; 357, conditional_expression:if; 357, 358; 357, 369; 357, 375; 358, binary_operator:-; 358, 359; 358, 364; 359, subscript; 359, 360; 359, 363; 360, subscript; 360, 361; 360, 362; 361, identifier:probs; 362, integer:0; 363, integer:1; 364, subscript; 364, 365; 364, 368; 365, subscript; 365, 366; 365, 367; 366, identifier:probs; 367, integer:1; 368, integer:1; 369, comparison_operator:>; 369, 370; 369, 374; 370, call; 370, 371; 370, 372; 371, identifier:len; 372, argument_list; 372, 373; 373, identifier:probs; 374, integer:1; 375, integer:1; 376, else_clause; 376, 377; 377, block; 377, 378; 378, expression_statement; 378, 379; 379, assignment; 379, 380; 379, 381; 380, identifier:margin; 381, binary_operator:-; 381, 382; 381, 392; 382, call; 382, 383; 382, 389; 383, attribute; 383, 384; 383, 388; 384, call; 384, 385; 384, 386; 385, identifier:dict; 386, argument_list; 386, 387; 387, identifier:probs; 388, identifier:get; 389, argument_list; 389, 390; 389, 391; 390, identifier:y; 391, integer:0; 392, subscript; 392, 393; 392, 396; 393, subscript; 393, 394; 393, 395; 394, identifier:probs; 395, integer:0; 396, integer:1; 397, return_statement; 397, 398; 398, expression_list; 398, 399; 398, 400; 399, identifier:node_id; 400, identifier:margin | def predict(tree, x, y=[], dist=False):
node_id = 1
while 1:
nodes = tree[node_id]
if nodes[0][5] == "c":
if x[nodes[0][1]] <= nodes[0][2]:
index, node_id = 0, nodes[0][0]
else:
index, node_id = 1, nodes[1][0]
else:
if x[nodes[0][1]] in nodes[0][2]:
index, node_id = 0, nodes[0][0]
elif x[nodes[1][1]] in nodes[1][2]:
index, node_id = 1, nodes[1][0]
else:
node_id = str(nodes[0][0]) + "," + str(nodes[1][0])
index, nodes = 0, [[0, 0, 0, {k: nodes[0][3].get(k, 0) + nodes[1][3].get(k, 0) for k in
set(nodes[0][3]) | set(nodes[1][3])}]]
if node_id in tree.keys():
continue
if dist:
suma = sum(nodes[index][3].values())
return Counter({k: v / float(suma) for k, v in nodes[index][3].iteritems()})
prediction = max(nodes[index][3], key=nodes[index][3].get)
if y == []:
return prediction
probs = sorted(
zip(nodes[index][3].keys(), np.true_divide(nodes[index][3].values(), np.sum(nodes[index][3].values()))),
key=itemgetter(1), reverse=True)
if prediction == y:
margin = probs[0][1] - probs[1][1] if len(probs) > 1 else 1
else:
margin = dict(probs).get(y, 0) - probs[0][1]
return node_id, margin |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 11; 2, function_name:pay_with_account_credit_cards; 3, parameters; 3, 4; 4, identifier:invoice_id; 5, type; 5, 6; 6, generic_type; 6, 7; 6, 8; 7, identifier:Optional; 8, type_parameter; 8, 9; 9, type; 9, 10; 10, identifier:Transaction; 11, block; 11, 12; 11, 22; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:logger; 16, identifier:debug; 17, argument_list; 17, 18; 17, 19; 18, string:'invoice-payment-started'; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:invoice_id; 21, identifier:invoice_id; 22, with_statement; 22, 23; 22, 30; 23, with_clause; 23, 24; 24, with_item; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:transaction; 28, identifier:atomic; 29, argument_list; 30, block; 30, 31; 30, 48; 30, 66; 30, 78; 30, 91; 30, 104; 30, 110; 30, 122; 30, 146; 30, 155; 30, 289; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:invoice; 34, call; 34, 35; 34, 44; 35, attribute; 35, 36; 35, 43; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:Invoice; 40, identifier:objects; 41, identifier:select_for_update; 42, argument_list; 43, identifier:get; 44, argument_list; 44, 45; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:pk; 47, identifier:invoice_id; 48, if_statement; 48, 49; 48, 53; 49, not_operator; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:invoice; 52, identifier:in_payable_state; 53, block; 53, 54; 54, raise_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:PreconditionError; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, string:'Cannot pay invoice with status {}.'; 61, identifier:format; 62, argument_list; 62, 63; 63, attribute; 63, 64; 63, 65; 64, identifier:invoice; 65, identifier:status; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:due; 69, call; 69, 70; 69, 77; 70, attribute; 70, 71; 70, 76; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:invoice; 74, identifier:due; 75, argument_list; 76, identifier:monies; 77, argument_list; 78, if_statement; 78, 79; 78, 85; 79, comparison_operator:==; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:len; 82, argument_list; 82, 83; 83, identifier:due; 84, integer:0; 85, block; 85, 86; 86, raise_statement; 86, 87; 87, call; 87, 88; 87, 89; 88, identifier:PreconditionError; 89, argument_list; 89, 90; 90, string:'Cannot pay empty invoice.'; 91, if_statement; 91, 92; 91, 98; 92, comparison_operator:>; 92, 93; 92, 97; 93, call; 93, 94; 93, 95; 94, identifier:len; 95, argument_list; 95, 96; 96, identifier:due; 97, integer:1; 98, block; 98, 99; 99, raise_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:PreconditionError; 102, argument_list; 102, 103; 103, string:'Cannot pay invoice with more than one currency.'; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:amount; 107, subscript; 107, 108; 107, 109; 108, identifier:due; 109, integer:0; 110, if_statement; 110, 111; 110, 116; 111, comparison_operator:<=; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:amount; 114, identifier:amount; 115, integer:0; 116, block; 116, 117; 117, raise_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:PreconditionError; 120, argument_list; 120, 121; 121, string:'Cannot pay invoice with non-positive amount.'; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:valid_credit_cards; 125, call; 125, 126; 125, 144; 126, attribute; 126, 127; 126, 143; 127, call; 127, 128; 127, 137; 128, attribute; 128, 129; 128, 136; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:CreditCard; 133, identifier:objects; 134, identifier:valid; 135, argument_list; 136, identifier:filter; 137, argument_list; 137, 138; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:account; 140, attribute; 140, 141; 140, 142; 141, identifier:invoice; 142, identifier:account; 143, identifier:order_by; 144, argument_list; 144, 145; 145, string:'status'; 146, if_statement; 146, 147; 146, 149; 147, not_operator; 147, 148; 148, identifier:valid_credit_cards; 149, block; 149, 150; 150, raise_statement; 150, 151; 151, call; 151, 152; 151, 153; 152, identifier:PreconditionError; 153, argument_list; 153, 154; 154, string:'No valid credit card on account.'; 155, for_statement; 155, 156; 155, 157; 155, 158; 156, identifier:credit_card; 157, identifier:valid_credit_cards; 158, block; 158, 159; 159, try_statement; 159, 160; 159, 267; 160, block; 160, 161; 160, 185; 160, 222; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, pattern_list; 163, 164; 163, 165; 164, identifier:success; 165, identifier:payment_psp_object; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:psp; 169, identifier:charge_credit_card; 170, argument_list; 170, 171; 170, 176; 170, 179; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:credit_card_psp_object; 173, attribute; 173, 174; 173, 175; 174, identifier:credit_card; 175, identifier:psp_object; 176, keyword_argument; 176, 177; 176, 178; 177, identifier:amount; 178, identifier:amount; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:client_ref; 181, call; 181, 182; 181, 183; 182, identifier:str; 183, argument_list; 183, 184; 184, identifier:invoice_id; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:payment; 188, call; 188, 189; 188, 194; 189, attribute; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:Transaction; 192, identifier:objects; 193, identifier:create; 194, argument_list; 194, 195; 194, 200; 194, 203; 194, 206; 194, 209; 194, 214; 194, 219; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:account; 197, attribute; 197, 198; 197, 199; 198, identifier:invoice; 199, identifier:account; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:invoice; 202, identifier:invoice; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:amount; 205, identifier:amount; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:success; 208, identifier:success; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:payment_method; 211, attribute; 211, 212; 211, 213; 212, identifier:credit_card; 213, identifier:type; 214, keyword_argument; 214, 215; 214, 216; 215, identifier:credit_card_number; 216, attribute; 216, 217; 216, 218; 217, identifier:credit_card; 218, identifier:number; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:psp_object; 221, identifier:payment_psp_object; 222, if_statement; 222, 223; 222, 224; 222, 252; 223, identifier:success; 224, block; 224, 225; 224, 231; 224, 237; 224, 250; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:invoice; 229, identifier:pay; 230, argument_list; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:invoice; 235, identifier:save; 236, argument_list; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:logger; 241, identifier:info; 242, argument_list; 242, 243; 242, 244; 242, 247; 243, string:'invoice-payment-success'; 244, keyword_argument; 244, 245; 244, 246; 245, identifier:invoice; 246, identifier:invoice_id; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:payment; 249, identifier:payment; 250, return_statement; 250, 251; 251, identifier:payment; 252, else_clause; 252, 253; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:logger; 258, identifier:info; 259, argument_list; 259, 260; 259, 261; 259, 264; 260, string:'invoice-payment-failure'; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:invoice; 263, identifier:invoice_id; 264, keyword_argument; 264, 265; 264, 266; 265, identifier:payment; 266, identifier:payment; 267, except_clause; 267, 268; 267, 272; 268, as_pattern; 268, 269; 268, 270; 269, identifier:Exception; 270, as_pattern_target; 270, 271; 271, identifier:e; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:logger; 277, identifier:error; 278, argument_list; 278, 279; 278, 280; 278, 283; 278, 286; 279, string:'invoice-payment-error'; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:invoice_id; 282, identifier:invoice_id; 283, keyword_argument; 283, 284; 283, 285; 284, identifier:credit_card; 285, identifier:credit_card; 286, keyword_argument; 286, 287; 286, 288; 287, identifier:exc_info; 288, identifier:e; 289, return_statement; 289, 290; 290, None | def pay_with_account_credit_cards(invoice_id) -> Optional[Transaction]:
logger.debug('invoice-payment-started', invoice_id=invoice_id)
with transaction.atomic():
invoice = Invoice.objects.select_for_update().get(pk=invoice_id)
if not invoice.in_payable_state:
raise PreconditionError('Cannot pay invoice with status {}.'.format(invoice.status))
due = invoice.due().monies()
if len(due) == 0:
raise PreconditionError('Cannot pay empty invoice.')
if len(due) > 1:
raise PreconditionError('Cannot pay invoice with more than one currency.')
amount = due[0]
if amount.amount <= 0:
raise PreconditionError('Cannot pay invoice with non-positive amount.')
valid_credit_cards = CreditCard.objects.valid().filter(account=invoice.account).order_by('status')
if not valid_credit_cards:
raise PreconditionError('No valid credit card on account.')
for credit_card in valid_credit_cards:
try:
success, payment_psp_object = psp.charge_credit_card(
credit_card_psp_object=credit_card.psp_object,
amount=amount,
client_ref=str(invoice_id))
payment = Transaction.objects.create(
account=invoice.account,
invoice=invoice,
amount=amount,
success=success,
payment_method=credit_card.type,
credit_card_number=credit_card.number,
psp_object=payment_psp_object)
if success:
invoice.pay()
invoice.save()
logger.info('invoice-payment-success', invoice=invoice_id, payment=payment)
return payment
else:
logger.info('invoice-payment-failure', invoice=invoice_id, payment=payment)
except Exception as e:
logger.error('invoice-payment-error', invoice_id=invoice_id, credit_card=credit_card, exc_info=e)
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:handle_django_settings; 3, parameters; 3, 4; 4, identifier:filename; 5, block; 5, 6; 5, 8; 5, 17; 5, 28; 5, 39; 5, 47; 5, 66; 5, 83; 5, 90; 5, 99; 5, 107; 5, 130; 5, 147; 5, 153; 5, 159; 5, 165; 5, 291; 5, 305; 5, 416; 5, 425; 5, 432; 5, 454; 6, expression_statement; 6, 7; 7, string:'''Attempts to load a Django project and get package dependencies from
settings.
Tested using Django 1.4 and 1.8. Not sure if some nuances are missed in
the other versions.
'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:old_sys_path; 11, subscript; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:sys; 14, identifier:path; 15, slice; 15, 16; 16, colon; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:dirpath; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:os; 24, identifier:path; 25, identifier:dirname; 26, argument_list; 26, 27; 27, identifier:filename; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:project; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:os; 35, identifier:path; 36, identifier:basename; 37, argument_list; 37, 38; 38, identifier:dirpath; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:cwd; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:os; 45, identifier:getcwd; 46, argument_list; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:project_path; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:os; 54, identifier:path; 55, identifier:normpath; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:os; 61, identifier:path; 62, identifier:join; 63, argument_list; 63, 64; 63, 65; 64, identifier:dirpath; 65, string:'..'; 66, if_statement; 66, 67; 66, 72; 67, comparison_operator:not; 67, 68; 67, 69; 68, identifier:project_path; 69, attribute; 69, 70; 69, 71; 70, identifier:sys; 71, identifier:path; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:sys; 78, identifier:path; 79, identifier:insert; 80, argument_list; 80, 81; 80, 82; 81, integer:0; 82, identifier:project_path; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:os; 87, identifier:chdir; 88, argument_list; 88, 89; 89, identifier:project_path; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:project_settings; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, string:'{}.settings'; 96, identifier:format; 97, argument_list; 97, 98; 98, identifier:project; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 106; 101, subscript; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:os; 104, identifier:environ; 105, string:'DJANGO_SETTINGS_MODULE'; 106, identifier:project_settings; 107, try_statement; 107, 108; 107, 119; 108, block; 108, 109; 108, 112; 109, import_statement; 109, 110; 110, dotted_name; 110, 111; 111, identifier:django; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:django; 116, identifier:setup; 117, lambda; 117, 118; 118, False; 119, except_clause; 119, 120; 119, 121; 120, identifier:ImportError; 121, block; 121, 122; 121, 129; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:log; 126, identifier:error; 127, argument_list; 127, 128; 128, string:'Found Django settings, but Django is not installed.'; 129, return_statement; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:log; 134, identifier:warn; 135, argument_list; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, string:'Loading Django Settings (Using {}): {}'; 139, identifier:format; 140, argument_list; 140, 141; 140, 146; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:django; 144, identifier:get_version; 145, argument_list; 146, identifier:filename; 147, import_from_statement; 147, 148; 147, 151; 148, dotted_name; 148, 149; 148, 150; 149, identifier:django; 150, identifier:conf; 151, dotted_name; 151, 152; 152, identifier:LazySettings; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:installed_apps; 156, call; 156, 157; 156, 158; 157, identifier:set; 158, argument_list; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:settings_imports; 162, call; 162, 163; 162, 164; 163, identifier:set; 164, argument_list; 165, try_statement; 165, 166; 165, 266; 166, block; 166, 167; 166, 173; 166, 179; 166, 213; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:settings; 170, call; 170, 171; 170, 172; 171, identifier:LazySettings; 172, argument_list; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:settings; 177, identifier:_setup; 178, argument_list; 179, for_statement; 179, 180; 179, 183; 179, 193; 180, pattern_list; 180, 181; 180, 182; 181, identifier:k; 182, identifier:v; 183, call; 183, 184; 183, 192; 184, attribute; 184, 185; 184, 191; 185, call; 185, 186; 185, 187; 186, identifier:vars; 187, argument_list; 187, 188; 188, attribute; 188, 189; 188, 190; 189, identifier:settings; 190, identifier:_wrapped; 191, identifier:items; 192, argument_list; 193, block; 193, 194; 194, if_statement; 194, 195; 194, 206; 195, boolean_operator:and; 195, 196; 195, 199; 196, comparison_operator:not; 196, 197; 196, 198; 197, identifier:k; 198, identifier:_excluded_settings; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:re; 202, identifier:match; 203, argument_list; 203, 204; 203, 205; 204, string:r'^[A-Z_]+$'; 205, identifier:k; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 210; 209, identifier:scan_django_settings; 210, argument_list; 210, 211; 210, 212; 211, identifier:v; 212, identifier:settings_imports; 213, for_statement; 213, 214; 213, 215; 213, 221; 214, identifier:app; 215, call; 215, 216; 215, 217; 216, identifier:getattr; 217, argument_list; 217, 218; 217, 219; 217, 220; 218, identifier:settings; 219, string:'INSTALLED_APPS'; 220, list:[]; 221, block; 221, 222; 222, if_statement; 222, 223; 222, 234; 222, 257; 223, boolean_operator:and; 223, 224; 223, 229; 224, call; 224, 225; 224, 226; 225, identifier:hasattr; 226, argument_list; 226, 227; 226, 228; 227, identifier:app; 228, string:'__file__'; 229, call; 229, 230; 229, 231; 230, identifier:getattr; 231, argument_list; 231, 232; 231, 233; 232, identifier:app; 233, string:'__file__'; 234, block; 234, 235; 234, 250; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 240; 237, pattern_list; 237, 238; 237, 239; 238, identifier:imp; 239, identifier:_; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:utils; 243, identifier:import_path_from_file; 244, argument_list; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:getattr; 247, argument_list; 247, 248; 247, 249; 248, identifier:app; 249, string:'__file__'; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:installed_apps; 254, identifier:add; 255, argument_list; 255, 256; 256, identifier:imp; 257, else_clause; 257, 258; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:installed_apps; 263, identifier:add; 264, argument_list; 264, 265; 265, identifier:app; 266, except_clause; 266, 267; 266, 271; 267, as_pattern; 267, 268; 267, 269; 268, identifier:Exception; 269, as_pattern_target; 269, 270; 270, identifier:e; 271, block; 271, 272; 271, 280; 271, 290; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:log; 276, identifier:error; 277, argument_list; 277, 278; 277, 279; 278, string:'Could not load Django settings: %s'; 279, identifier:e; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:log; 284, identifier:debug; 285, argument_list; 285, 286; 285, 287; 286, string:''; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:exc_info; 289, True; 290, return_statement; 291, if_statement; 291, 292; 291, 297; 292, boolean_operator:or; 292, 293; 292, 295; 293, not_operator; 293, 294; 294, identifier:installed_apps; 295, not_operator; 295, 296; 296, identifier:settings_imports; 297, block; 297, 298; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:log; 302, identifier:error; 303, argument_list; 303, 304; 304, string:'Got empty settings values from Django settings.'; 305, try_statement; 305, 306; 305, 398; 306, block; 306, 307; 306, 318; 306, 340; 306, 348; 307, import_from_statement; 307, 308; 307, 312; 307, 314; 307, 316; 308, dotted_name; 308, 309; 308, 310; 308, 311; 309, identifier:django; 310, identifier:apps; 311, identifier:registry; 312, dotted_name; 312, 313; 313, identifier:apps; 314, dotted_name; 314, 315; 315, identifier:Apps; 316, dotted_name; 316, 317; 317, identifier:AppRegistryNotReady; 318, if_statement; 318, 319; 318, 323; 318, 331; 319, not_operator; 319, 320; 320, attribute; 320, 321; 320, 322; 321, identifier:apps; 322, identifier:apps_ready; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:apps; 328, identifier:populate; 329, argument_list; 329, 330; 330, identifier:installed_apps; 331, else_clause; 331, 332; 332, block; 332, 333; 333, expression_statement; 333, 334; 334, assignment; 334, 335; 334, 336; 335, identifier:apps; 336, call; 336, 337; 336, 338; 337, identifier:Apps; 338, argument_list; 338, 339; 339, identifier:installed_apps; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:start; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:time; 346, identifier:time; 347, argument_list; 348, while_statement; 348, 349; 348, 350; 349, True; 350, block; 350, 351; 350, 397; 351, try_statement; 351, 352; 351, 370; 352, block; 352, 353; 353, for_statement; 353, 354; 353, 355; 353, 360; 354, identifier:app; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:apps; 358, identifier:get_app_configs; 359, argument_list; 360, block; 360, 361; 361, expression_statement; 361, 362; 362, call; 362, 363; 362, 366; 363, attribute; 363, 364; 363, 365; 364, identifier:installed_apps; 365, identifier:add; 366, argument_list; 366, 367; 367, attribute; 367, 368; 367, 369; 368, identifier:app; 369, identifier:name; 370, except_clause; 370, 371; 370, 372; 371, identifier:AppRegistryNotReady; 372, block; 372, 373; 372, 389; 372, 396; 373, if_statement; 373, 374; 373, 383; 374, comparison_operator:>; 374, 375; 374, 382; 375, binary_operator:-; 375, 376; 375, 381; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:time; 379, identifier:time; 380, argument_list; 381, identifier:start; 382, integer:10; 383, block; 383, 384; 384, raise_statement; 384, 385; 385, call; 385, 386; 385, 387; 386, identifier:Exception; 387, argument_list; 387, 388; 388, string:'Bail out of waiting for Django'; 389, expression_statement; 389, 390; 390, call; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:log; 393, identifier:debug; 394, argument_list; 394, 395; 395, string:'Waiting for apps to load...'; 396, continue_statement; 397, break_statement; 398, except_clause; 398, 399; 398, 403; 399, as_pattern; 399, 400; 399, 401; 400, identifier:Exception; 401, as_pattern_target; 401, 402; 402, identifier:e; 403, block; 403, 404; 404, expression_statement; 404, 405; 405, call; 405, 406; 405, 409; 406, attribute; 406, 407; 406, 408; 407, identifier:log; 408, identifier:debug; 409, argument_list; 409, 410; 410, call; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, string:'Could not use AppConfig: {}'; 413, identifier:format; 414, argument_list; 414, 415; 415, identifier:e; 416, expression_statement; 416, 417; 417, assignment; 417, 418; 417, 424; 418, subscript; 418, 419; 418, 422; 419, attribute; 419, 420; 419, 421; 420, identifier:sys; 421, identifier:path; 422, slice; 422, 423; 423, colon; 424, identifier:old_sys_path; 425, expression_statement; 425, 426; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:os; 429, identifier:chdir; 430, argument_list; 430, 431; 431, identifier:cwd; 432, for_statement; 432, 433; 432, 434; 432, 435; 433, identifier:item; 434, identifier:settings_imports; 435, block; 435, 436; 435, 445; 436, expression_statement; 436, 437; 437, assignment; 437, 438; 437, 439; 438, identifier:need_scan; 439, call; 439, 440; 439, 443; 440, attribute; 440, 441; 440, 442; 441, identifier:item; 442, identifier:startswith; 443, argument_list; 443, 444; 444, identifier:_filescan_modules; 445, expression_statement; 445, 446; 446, yield; 446, 447; 447, tuple; 447, 448; 447, 449; 447, 450; 448, string:'django'; 449, identifier:item; 450, conditional_expression:if; 450, 451; 450, 452; 450, 453; 451, identifier:project_path; 452, identifier:need_scan; 453, None; 454, for_statement; 454, 455; 454, 456; 454, 457; 455, identifier:app; 456, identifier:installed_apps; 457, block; 457, 458; 457, 467; 458, expression_statement; 458, 459; 459, assignment; 459, 460; 459, 461; 460, identifier:need_scan; 461, call; 461, 462; 461, 465; 462, attribute; 462, 463; 462, 464; 463, identifier:app; 464, identifier:startswith; 465, argument_list; 465, 466; 466, identifier:project; 467, expression_statement; 467, 468; 468, yield; 468, 469; 469, tuple; 469, 470; 469, 471; 469, 472; 470, string:'django'; 471, identifier:app; 472, conditional_expression:if; 472, 473; 472, 474; 472, 475; 473, identifier:project_path; 474, identifier:need_scan; 475, None | def handle_django_settings(filename):
'''Attempts to load a Django project and get package dependencies from
settings.
Tested using Django 1.4 and 1.8. Not sure if some nuances are missed in
the other versions.
'''
old_sys_path = sys.path[:]
dirpath = os.path.dirname(filename)
project = os.path.basename(dirpath)
cwd = os.getcwd()
project_path = os.path.normpath(os.path.join(dirpath, '..'))
if project_path not in sys.path:
sys.path.insert(0, project_path)
os.chdir(project_path)
project_settings = '{}.settings'.format(project)
os.environ['DJANGO_SETTINGS_MODULE'] = project_settings
try:
import django
django.setup = lambda: False
except ImportError:
log.error('Found Django settings, but Django is not installed.')
return
log.warn('Loading Django Settings (Using {}): {}'
.format(django.get_version(), filename))
from django.conf import LazySettings
installed_apps = set()
settings_imports = set()
try:
settings = LazySettings()
settings._setup()
for k, v in vars(settings._wrapped).items():
if k not in _excluded_settings and re.match(r'^[A-Z_]+$', k):
scan_django_settings(v, settings_imports)
for app in getattr(settings, 'INSTALLED_APPS', []):
if hasattr(app, '__file__') and getattr(app, '__file__'):
imp, _ = utils.import_path_from_file(getattr(app, '__file__'))
installed_apps.add(imp)
else:
installed_apps.add(app)
except Exception as e:
log.error('Could not load Django settings: %s', e)
log.debug('', exc_info=True)
return
if not installed_apps or not settings_imports:
log.error('Got empty settings values from Django settings.')
try:
from django.apps.registry import apps, Apps, AppRegistryNotReady
if not apps.apps_ready:
apps.populate(installed_apps)
else:
apps = Apps(installed_apps)
start = time.time()
while True:
try:
for app in apps.get_app_configs():
installed_apps.add(app.name)
except AppRegistryNotReady:
if time.time() - start > 10:
raise Exception('Bail out of waiting for Django')
log.debug('Waiting for apps to load...')
continue
break
except Exception as e:
log.debug('Could not use AppConfig: {}'.format(e))
sys.path[:] = old_sys_path
os.chdir(cwd)
for item in settings_imports:
need_scan = item.startswith(_filescan_modules)
yield ('django', item, project_path if need_scan else None)
for app in installed_apps:
need_scan = app.startswith(project)
yield ('django', app, project_path if need_scan else None) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.