sequence
stringlengths
492
15.9k
code
stringlengths
75
8.58k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_paths_for_status; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:status; 6, block; 6, 7; 6, 16; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 13; 9, pattern_list; 9, 10; 9, 11; 9, 12; 10, identifier:added; 11, identifier:modified; 12, identifier:deleted; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_changes_cache; 16, return_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:sorted; 19, argument_list; 19, 20; 20, subscript; 20, 21; 20, 40; 21, dictionary; 21, 22; 21, 28; 21, 34; 22, pair; 22, 23; 22, 24; 23, string:'added'; 24, call; 24, 25; 24, 26; 25, identifier:list; 26, argument_list; 26, 27; 27, identifier:added; 28, pair; 28, 29; 28, 30; 29, string:'modified'; 30, call; 30, 31; 30, 32; 31, identifier:list; 32, argument_list; 32, 33; 33, identifier:modified; 34, pair; 34, 35; 34, 36; 35, string:'deleted'; 36, call; 36, 37; 36, 38; 37, identifier:list; 38, argument_list; 38, 39; 39, identifier:deleted; 40, identifier:status
def _get_paths_for_status(self, status): added, modified, deleted = self._changes_cache return sorted({ 'added': list(added), 'modified': list(modified), 'deleted': list(deleted)}[status] )
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 22; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_list; 16, identifier:sort; 17, argument_list; 17, 18; 17, 20; 18, list_splat; 18, 19; 19, identifier:args; 20, dictionary_splat; 20, 21; 21, identifier:kwargs; 22, for_statement; 22, 23; 22, 26; 22, 32; 23, pattern_list; 23, 24; 23, 25; 24, identifier:index; 25, identifier:value; 26, call; 26, 27; 26, 28; 27, identifier:enumerate; 28, argument_list; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:_list; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 40; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_dict; 39, identifier:value; 40, identifier:index
def sort(self, *args, **kwargs): self._list.sort(*args, **kwargs) for index, value in enumerate(self._list): self._dict[value] = index
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:find; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:term; 6, default_parameter; 6, 7; 6, 8; 7, identifier:limit; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:ranks; 14, None; 15, block; 15, 16; 15, 24; 15, 28; 15, 32; 15, 100; 15, 112; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:ranks; 19, boolean_operator:or; 19, 20; 19, 21; 20, identifier:ranks; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:ranks; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:found_indices; 27, list:[]; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:count; 31, integer:0; 32, if_statement; 32, 33; 32, 35; 32, 61; 33, not_operator; 33, 34; 34, identifier:limit; 35, block; 35, 36; 36, for_statement; 36, 37; 36, 40; 36, 46; 37, pattern_list; 37, 38; 37, 39; 38, identifier:i; 39, identifier:card; 40, call; 40, 41; 40, 42; 41, identifier:enumerate; 42, argument_list; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:cards; 46, block; 46, 47; 47, if_statement; 47, 48; 47, 53; 48, call; 48, 49; 48, 50; 49, identifier:check_term; 50, argument_list; 50, 51; 50, 52; 51, identifier:card; 52, identifier:term; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:found_indices; 58, identifier:append; 59, argument_list; 59, 60; 60, identifier:i; 61, else_clause; 61, 62; 62, block; 62, 63; 63, for_statement; 63, 64; 63, 67; 63, 73; 64, pattern_list; 64, 65; 64, 66; 65, identifier:i; 66, identifier:card; 67, call; 67, 68; 67, 69; 68, identifier:enumerate; 69, argument_list; 69, 70; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:cards; 73, block; 73, 74; 74, if_statement; 74, 75; 74, 78; 74, 97; 75, comparison_operator:<; 75, 76; 75, 77; 76, identifier:count; 77, identifier:limit; 78, block; 78, 79; 79, if_statement; 79, 80; 79, 85; 80, call; 80, 81; 80, 82; 81, identifier:check_term; 82, argument_list; 82, 83; 82, 84; 83, identifier:card; 84, identifier:term; 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:found_indices; 90, identifier:append; 91, argument_list; 91, 92; 92, identifier:i; 93, expression_statement; 93, 94; 94, augmented_assignment:+=; 94, 95; 94, 96; 95, identifier:count; 96, integer:1; 97, else_clause; 97, 98; 98, block; 98, 99; 99, break_statement; 100, if_statement; 100, 101; 100, 102; 101, identifier:sort; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:found_indices; 106, call; 106, 107; 106, 108; 107, identifier:sort_card_indices; 108, argument_list; 108, 109; 108, 110; 108, 111; 109, identifier:self; 110, identifier:found_indices; 111, identifier:ranks; 112, return_statement; 112, 113; 113, identifier:found_indices
def find(self, term, limit=0, sort=False, ranks=None): ranks = ranks or self.ranks found_indices = [] count = 0 if not limit: for i, card in enumerate(self.cards): if check_term(card, term): found_indices.append(i) else: for i, card in enumerate(self.cards): if count < limit: if check_term(card, term): found_indices.append(i) count += 1 else: break if sort: found_indices = sort_card_indices(self, found_indices, ranks) return found_indices
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:get_list; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:terms; 6, default_parameter; 6, 7; 6, 8; 7, identifier:limit; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:ranks; 14, None; 15, block; 15, 16; 15, 24; 15, 28; 15, 177; 15, 188; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:ranks; 19, boolean_operator:or; 19, 20; 19, 21; 20, identifier:ranks; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:ranks; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:got_cards; 27, list:[]; 28, try_statement; 28, 29; 28, 83; 29, block; 29, 30; 29, 42; 29, 62; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:indices; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:find_list; 37, argument_list; 37, 38; 37, 39; 38, identifier:terms; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:limit; 41, identifier:limit; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:got_cards; 45, list_comprehension; 45, 46; 45, 51; 45, 54; 46, subscript; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:cards; 50, identifier:i; 51, for_in_clause; 51, 52; 51, 53; 52, identifier:i; 53, identifier:indices; 54, if_clause; 54, 55; 55, comparison_operator:not; 55, 56; 55, 61; 56, subscript; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:cards; 60, identifier:i; 61, identifier:got_cards; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:cards; 67, list_comprehension; 67, 68; 67, 69; 67, 79; 68, identifier:v; 69, for_in_clause; 69, 70; 69, 73; 70, pattern_list; 70, 71; 70, 72; 71, identifier:i; 72, identifier:v; 73, call; 73, 74; 73, 75; 74, identifier:enumerate; 75, argument_list; 75, 76; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:cards; 79, if_clause; 79, 80; 80, comparison_operator:not; 80, 81; 80, 82; 81, identifier:i; 82, identifier:indices; 83, except_clause; 83, 84; 84, block; 84, 85; 84, 89; 84, 156; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:indices; 88, list:[]; 89, for_statement; 89, 90; 89, 91; 89, 92; 90, identifier:item; 91, identifier:terms; 92, block; 92, 93; 93, try_statement; 93, 94; 93, 122; 94, block; 94, 95; 94, 103; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:card; 98, subscript; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:cards; 102, identifier:item; 103, if_statement; 103, 104; 103, 107; 104, comparison_operator:not; 104, 105; 104, 106; 105, identifier:card; 106, identifier:got_cards; 107, block; 107, 108; 107, 115; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:got_cards; 112, identifier:append; 113, argument_list; 113, 114; 114, identifier:card; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:indices; 119, identifier:append; 120, argument_list; 120, 121; 121, identifier:item; 122, except_clause; 122, 123; 123, block; 123, 124; 123, 136; 124, expression_statement; 124, 125; 125, augmented_assignment:+=; 125, 126; 125, 127; 126, identifier:indices; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:find; 131, argument_list; 131, 132; 131, 133; 132, identifier:item; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:limit; 135, identifier:limit; 136, expression_statement; 136, 137; 137, augmented_assignment:+=; 137, 138; 137, 139; 138, identifier:got_cards; 139, list_comprehension; 139, 140; 139, 145; 139, 148; 140, subscript; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:cards; 144, identifier:i; 145, for_in_clause; 145, 146; 145, 147; 146, identifier:i; 147, identifier:indices; 148, if_clause; 148, 149; 149, comparison_operator:not; 149, 150; 149, 155; 150, subscript; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:cards; 154, identifier:i; 155, identifier:got_cards; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:cards; 161, list_comprehension; 161, 162; 161, 163; 161, 173; 162, identifier:v; 163, for_in_clause; 163, 164; 163, 167; 164, pattern_list; 164, 165; 164, 166; 165, identifier:i; 166, identifier:v; 167, call; 167, 168; 167, 169; 168, identifier:enumerate; 169, argument_list; 169, 170; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:cards; 173, if_clause; 173, 174; 174, comparison_operator:not; 174, 175; 174, 176; 175, identifier:i; 176, identifier:indices; 177, if_statement; 177, 178; 177, 179; 178, identifier:sort; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:got_cards; 183, call; 183, 184; 183, 185; 184, identifier:sort_cards; 185, argument_list; 185, 186; 185, 187; 186, identifier:got_cards; 187, identifier:ranks; 188, return_statement; 188, 189; 189, identifier:got_cards
def get_list(self, terms, limit=0, sort=False, ranks=None): ranks = ranks or self.ranks got_cards = [] try: indices = self.find_list(terms, limit=limit) got_cards = [self.cards[i] for i in indices if self.cards[i] not in got_cards] self.cards = [v for i, v in enumerate(self.cards) if i not in indices] except: indices = [] for item in terms: try: card = self.cards[item] if card not in got_cards: got_cards.append(card) indices.append(item) except: indices += self.find(item, limit=limit) got_cards += [self.cards[i] for i in indices if self.cards[i] not in got_cards] self.cards = [v for i, v in enumerate(self.cards) if i not in indices] if sort: got_cards = sort_cards(got_cards, ranks) return got_cards
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:is_sorted; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ranks; 7, None; 8, block; 8, 9; 8, 17; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:ranks; 12, boolean_operator:or; 12, 13; 12, 14; 13, identifier:ranks; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:ranks; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:check_sorted; 20, argument_list; 20, 21; 20, 22; 21, identifier:self; 22, identifier:ranks
def is_sorted(self, ranks=None): ranks = ranks or self.ranks return check_sorted(self, ranks)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ranks; 7, None; 8, block; 8, 9; 8, 17; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:ranks; 12, boolean_operator:or; 12, 13; 12, 14; 13, identifier:ranks; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:ranks; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:cards; 22, call; 22, 23; 22, 24; 23, identifier:sort_cards; 24, argument_list; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:cards; 28, identifier:ranks
def sort(self, ranks=None): ranks = ranks or self.ranks self.cards = sort_cards(self.cards, ranks)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:canonical_headers; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:headers_to_sign; 6, block; 6, 7; 6, 33; 6, 39; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:l; 10, list_comprehension; 10, 11; 10, 30; 11, binary_operator:%; 11, 12; 11, 13; 12, string:'%s:%s'; 13, tuple; 13, 14; 13, 23; 14, call; 14, 15; 14, 22; 15, attribute; 15, 16; 15, 21; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:n; 19, identifier:lower; 20, argument_list; 21, identifier:strip; 22, argument_list; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:headers_to_sign; 27, identifier:n; 28, identifier:strip; 29, argument_list; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:n; 32, identifier:headers_to_sign; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:l; 37, identifier:sort; 38, argument_list; 39, return_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, string:'\n'; 43, identifier:join; 44, argument_list; 44, 45; 45, identifier:l
def canonical_headers(self, headers_to_sign): l = ['%s:%s'%(n.lower().strip(), headers_to_sign[n].strip()) for n in headers_to_sign] l.sort() return '\n'.join(l)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:build_cards; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:jokers; 6, False; 7, default_parameter; 7, 8; 7, 9; 8, identifier:num_jokers; 9, integer:0; 10, block; 10, 11; 10, 15; 10, 33; 10, 48; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:new_deck; 14, list:[]; 15, if_statement; 15, 16; 15, 17; 16, identifier:jokers; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, augmented_assignment:+=; 19, 20; 19, 21; 20, identifier:new_deck; 21, list_comprehension; 21, 22; 21, 27; 22, call; 22, 23; 22, 24; 23, identifier:Card; 24, argument_list; 24, 25; 24, 26; 25, string:"Joker"; 26, None; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:i; 29, call; 29, 30; 29, 31; 30, identifier:xrange; 31, argument_list; 31, 32; 32, identifier:num_jokers; 33, expression_statement; 33, 34; 34, augmented_assignment:+=; 34, 35; 34, 36; 35, identifier:new_deck; 36, list_comprehension; 36, 37; 36, 42; 36, 45; 37, call; 37, 38; 37, 39; 38, identifier:Card; 39, argument_list; 39, 40; 39, 41; 40, identifier:value; 41, identifier:suit; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:value; 44, identifier:VALUES; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:suit; 47, identifier:SUITS; 48, return_statement; 48, 49; 49, identifier:new_deck
def build_cards(jokers=False, num_jokers=0): new_deck = [] if jokers: new_deck += [Card("Joker", None) for i in xrange(num_jokers)] new_deck += [Card(value, suit) for value in VALUES for suit in SUITS] return new_deck
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:check_sorted; 3, parameters; 3, 4; 3, 5; 4, identifier:cards; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ranks; 7, None; 8, block; 8, 9; 8, 15; 8, 23; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:ranks; 12, boolean_operator:or; 12, 13; 12, 14; 13, identifier:ranks; 14, identifier:DEFAULT_RANKS; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:sorted_cards; 18, call; 18, 19; 18, 20; 19, identifier:sort_cards; 20, argument_list; 20, 21; 20, 22; 21, identifier:cards; 22, identifier:ranks; 23, if_statement; 23, 24; 23, 37; 23, 40; 24, boolean_operator:or; 24, 25; 24, 28; 25, comparison_operator:==; 25, 26; 25, 27; 26, identifier:cards; 27, identifier:sorted_cards; 28, comparison_operator:==; 28, 29; 28, 36; 29, subscript; 29, 30; 29, 31; 30, identifier:cards; 31, slice; 31, 32; 31, 33; 31, 34; 32, colon; 33, colon; 34, unary_operator:-; 34, 35; 35, integer:1; 36, identifier:sorted_cards; 37, block; 37, 38; 38, return_statement; 38, 39; 39, True; 40, else_clause; 40, 41; 41, block; 41, 42; 42, return_statement; 42, 43; 43, False
def check_sorted(cards, ranks=None): ranks = ranks or DEFAULT_RANKS sorted_cards = sort_cards(cards, ranks) if cards == sorted_cards or cards[::-1] == sorted_cards: return True else: return False
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_card_indices; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cards; 5, identifier:indices; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ranks; 8, None; 9, block; 9, 10; 9, 16; 9, 54; 9, 83; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:ranks; 13, boolean_operator:or; 13, 14; 13, 15; 14, identifier:ranks; 15, identifier:DEFAULT_RANKS; 16, if_statement; 16, 17; 16, 23; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:ranks; 20, identifier:get; 21, argument_list; 21, 22; 22, string:"suits"; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:indices; 27, call; 27, 28; 27, 29; 28, identifier:sorted; 29, argument_list; 29, 30; 29, 31; 30, identifier:indices; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:key; 33, lambda; 33, 34; 33, 36; 34, lambda_parameters; 34, 35; 35, identifier:x; 36, conditional_expression:if; 36, 37; 36, 46; 36, 53; 37, subscript; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:ranks; 40, string:"suits"; 41, attribute; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:cards; 44, identifier:x; 45, identifier:suit; 46, comparison_operator:!=; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:cards; 50, identifier:x; 51, identifier:suit; 52, None; 53, integer:0; 54, if_statement; 54, 55; 54, 61; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:ranks; 58, identifier:get; 59, argument_list; 59, 60; 60, string:"values"; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:indices; 65, call; 65, 66; 65, 67; 66, identifier:sorted; 67, argument_list; 67, 68; 67, 69; 68, identifier:indices; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:key; 71, lambda; 71, 72; 71, 74; 72, lambda_parameters; 72, 73; 73, identifier:x; 74, subscript; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:ranks; 77, string:"values"; 78, attribute; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:cards; 81, identifier:x; 82, identifier:value; 83, return_statement; 83, 84; 84, identifier:indices
def sort_card_indices(cards, indices, ranks=None): ranks = ranks or DEFAULT_RANKS if ranks.get("suits"): indices = sorted( indices, key=lambda x: ranks["suits"][cards[x].suit] if cards[x].suit != None else 0 ) if ranks.get("values"): indices = sorted( indices, key=lambda x: ranks["values"][cards[x].value] ) return indices
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_cards; 3, parameters; 3, 4; 3, 5; 4, identifier:cards; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ranks; 7, None; 8, block; 8, 9; 8, 15; 8, 49; 8, 76; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:ranks; 12, boolean_operator:or; 12, 13; 12, 14; 13, identifier:ranks; 14, identifier:DEFAULT_RANKS; 15, if_statement; 15, 16; 15, 22; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:ranks; 19, identifier:get; 20, argument_list; 20, 21; 21, string:"suits"; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:cards; 26, call; 26, 27; 26, 28; 27, identifier:sorted; 28, argument_list; 28, 29; 28, 30; 29, identifier:cards; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:key; 32, lambda; 32, 33; 32, 35; 33, lambda_parameters; 33, 34; 34, identifier:x; 35, conditional_expression:if; 35, 36; 35, 43; 35, 48; 36, subscript; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:ranks; 39, string:"suits"; 40, attribute; 40, 41; 40, 42; 41, identifier:x; 42, identifier:suit; 43, comparison_operator:!=; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:x; 46, identifier:suit; 47, None; 48, integer:0; 49, if_statement; 49, 50; 49, 56; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:ranks; 53, identifier:get; 54, argument_list; 54, 55; 55, string:"values"; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:cards; 60, call; 60, 61; 60, 62; 61, identifier:sorted; 62, argument_list; 62, 63; 62, 64; 63, identifier:cards; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:key; 66, lambda; 66, 67; 66, 69; 67, lambda_parameters; 67, 68; 68, identifier:x; 69, subscript; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:ranks; 72, string:"values"; 73, attribute; 73, 74; 73, 75; 74, identifier:x; 75, identifier:value; 76, return_statement; 76, 77; 77, identifier:cards
def sort_cards(cards, ranks=None): ranks = ranks or DEFAULT_RANKS if ranks.get("suits"): cards = sorted( cards, key=lambda x: ranks["suits"][x.suit] if x.suit != None else 0 ) if ranks.get("values"): cards = sorted( cards, key=lambda x: ranks["values"][x.value] ) return cards
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:key; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:frame; 6, block; 6, 7; 6, 9; 6, 32; 6, 54; 6, 91; 6, 115; 7, expression_statement; 7, 8; 8, string:"Return the sort key for the given frame."; 9, function_definition; 9, 10; 9, 11; 9, 13; 10, function_name:keytuple; 11, parameters; 11, 12; 12, identifier:primary; 13, block; 13, 14; 13, 25; 14, if_statement; 14, 15; 14, 20; 15, comparison_operator:is; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:frame; 18, identifier:frameno; 19, None; 20, block; 20, 21; 21, return_statement; 21, 22; 22, tuple; 22, 23; 22, 24; 23, identifier:primary; 24, integer:1; 25, return_statement; 25, 26; 26, tuple; 26, 27; 26, 28; 26, 29; 27, identifier:primary; 28, integer:0; 29, attribute; 29, 30; 29, 31; 30, identifier:frame; 31, identifier:frameno; 32, if_statement; 32, 33; 32, 41; 33, comparison_operator:in; 33, 34; 33, 38; 34, call; 34, 35; 34, 36; 35, identifier:type; 36, argument_list; 36, 37; 37, identifier:frame; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:frame_keys; 41, block; 41, 42; 42, return_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:keytuple; 45, argument_list; 45, 46; 46, subscript; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:frame_keys; 50, call; 50, 51; 50, 52; 51, identifier:type; 52, argument_list; 52, 53; 53, identifier:frame; 54, if_statement; 54, 55; 54, 74; 55, boolean_operator:and; 55, 56; 55, 62; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:frame; 59, identifier:_in_version; 60, argument_list; 60, 61; 61, integer:2; 62, comparison_operator:in; 62, 63; 62, 71; 63, subscript; 63, 64; 63, 70; 64, attribute; 64, 65; 64, 69; 65, call; 65, 66; 65, 67; 66, identifier:type; 67, argument_list; 67, 68; 68, identifier:frame; 69, identifier:__bases__; 70, integer:0; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:frame_keys; 74, block; 74, 75; 75, return_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:keytuple; 78, argument_list; 78, 79; 79, subscript; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:frame_keys; 83, subscript; 83, 84; 83, 90; 84, attribute; 84, 85; 84, 89; 85, call; 85, 86; 85, 87; 86, identifier:type; 87, argument_list; 87, 88; 88, identifier:frame; 89, identifier:__bases__; 90, integer:0; 91, for_statement; 91, 92; 91, 95; 91, 98; 92, tuple_pattern; 92, 93; 92, 94; 93, identifier:pattern; 94, identifier:key; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:re_keys; 98, block; 98, 99; 99, if_statement; 99, 100; 99, 109; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:re; 103, identifier:match; 104, argument_list; 104, 105; 104, 106; 105, identifier:pattern; 106, attribute; 106, 107; 106, 108; 107, identifier:frame; 108, identifier:frameid; 109, block; 109, 110; 110, return_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:keytuple; 113, argument_list; 113, 114; 114, identifier:key; 115, return_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:keytuple; 118, argument_list; 118, 119; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:unknown_key
def key(self, frame): "Return the sort key for the given frame." def keytuple(primary): if frame.frameno is None: return (primary, 1) return (primary, 0, frame.frameno) if type(frame) in self.frame_keys: return keytuple(self.frame_keys[type(frame)]) if frame._in_version(2) and type(frame).__bases__[0] in self.frame_keys: return keytuple(self.frame_keys[type(frame).__bases__[0]]) for (pattern, key) in self.re_keys: if re.match(pattern, frame.frameid): return keytuple(key) return keytuple(self.unknown_key)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:frames; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:orig_order; 10, False; 11, block; 11, 12; 11, 54; 11, 58; 11, 83; 11, 116; 11, 125; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:key; 15, None; 16, block; 16, 17; 16, 26; 16, 48; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:key; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_normalize_key; 24, argument_list; 24, 25; 25, identifier:key; 26, if_statement; 26, 27; 26, 37; 27, comparison_operator:==; 27, 28; 27, 36; 28, call; 28, 29; 28, 30; 29, identifier:len; 30, argument_list; 30, 31; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_frames; 35, identifier:key; 36, integer:0; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:KeyError; 41, argument_list; 41, 42; 42, binary_operator:+; 42, 43; 42, 44; 43, string:"Key not found: "; 44, call; 44, 45; 44, 46; 45, identifier:repr; 46, argument_list; 46, 47; 47, identifier:key; 48, return_statement; 48, 49; 49, subscript; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_frames; 53, identifier:key; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:frames; 57, list:[]; 58, for_statement; 58, 59; 58, 60; 58, 67; 59, identifier:frameid; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:_frames; 65, identifier:keys; 66, argument_list; 67, block; 67, 68; 68, for_statement; 68, 69; 68, 70; 68, 75; 69, identifier:frame; 70, subscript; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_frames; 74, identifier:frameid; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:frames; 80, identifier:append; 81, argument_list; 81, 82; 82, identifier:frame; 83, if_statement; 83, 84; 83, 85; 83, 106; 84, identifier:orig_order; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:key; 89, parenthesized_expression; 89, 90; 90, lambda; 90, 91; 90, 93; 91, lambda_parameters; 91, 92; 92, identifier:frame; 93, conditional_expression:if; 93, 94; 93, 99; 93, 104; 94, tuple; 94, 95; 94, 96; 95, integer:0; 96, attribute; 96, 97; 96, 98; 97, identifier:frame; 98, identifier:frameno; 99, comparison_operator:is; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:frame; 102, identifier:frameno; 103, None; 104, tuple; 104, 105; 105, integer:1; 106, else_clause; 106, 107; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:key; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:frame_order; 115, identifier:key; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:frames; 120, identifier:sort; 121, argument_list; 121, 122; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:key; 124, identifier:key; 125, return_statement; 125, 126; 126, identifier:frames
def frames(self, key=None, orig_order=False): if key is not None: key = self._normalize_key(key) if len(self._frames[key]) == 0: raise KeyError("Key not found: " + repr(key)) return self._frames[key] frames = [] for frameid in self._frames.keys(): for frame in self._frames[frameid]: frames.append(frame) if orig_order: key = (lambda frame: (0, frame.frameno) if frame.frameno is not None else (1,)) else: key = self.frame_order.key frames.sort(key=key) return frames
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:detach; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:force; 7, False; 8, block; 8, 9; 8, 13; 8, 26; 8, 30; 8, 43; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:instance_id; 12, None; 13, if_statement; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:attach_data; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:instance_id; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:attach_data; 25, identifier:instance_id; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:device; 29, None; 30, if_statement; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:attach_data; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:device; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:attach_data; 42, identifier:device; 43, return_statement; 43, 44; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:connection; 49, identifier:detach_volume; 50, argument_list; 50, 51; 50, 54; 50, 55; 50, 56; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:id; 54, identifier:instance_id; 55, identifier:device; 56, identifier:force
def detach(self, force=False): instance_id = None if self.attach_data: instance_id = self.attach_data.instance_id device = None if self.attach_data: device = self.attach_data.device return self.connection.detach_volume(self.id, instance_id, device, force)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:make_node_dict; 3, parameters; 3, 4; 3, 5; 4, identifier:outer_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, string:"zone"; 8, block; 8, 9; 8, 13; 8, 17; 8, 35; 8, 115; 8, 119; 8, 123; 8, 143; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:raw_dict; 12, dictionary; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:x; 16, integer:1; 17, for_statement; 17, 18; 17, 19; 17, 20; 18, identifier:inner_list; 19, identifier:outer_list; 20, block; 20, 21; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:node; 23, identifier:inner_list; 24, block; 24, 25; 24, 31; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:raw_dict; 29, identifier:x; 30, identifier:node; 31, expression_statement; 31, 32; 32, augmented_assignment:+=; 32, 33; 32, 34; 33, identifier:x; 34, integer:1; 35, if_statement; 35, 36; 35, 39; 35, 74; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:sort; 38, string:"name"; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:srt_dict; 43, call; 43, 44; 43, 45; 44, identifier:OrderedDict; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:sorted; 48, argument_list; 48, 49; 48, 54; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:raw_dict; 52, identifier:items; 53, argument_list; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:key; 56, lambda; 56, 57; 56, 59; 57, lambda_parameters; 57, 58; 58, identifier:k; 59, tuple; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:k; 63, integer:1; 64, identifier:cloud; 65, call; 65, 66; 65, 73; 66, attribute; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:k; 70, integer:1; 71, identifier:name; 72, identifier:lower; 73, argument_list; 74, else_clause; 74, 75; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:srt_dict; 79, call; 79, 80; 79, 81; 80, identifier:OrderedDict; 81, argument_list; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:sorted; 84, argument_list; 84, 85; 84, 90; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:raw_dict; 88, identifier:items; 89, argument_list; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:key; 92, lambda; 92, 93; 92, 95; 93, lambda_parameters; 93, 94; 94, identifier:k; 95, tuple; 95, 96; 95, 101; 95, 106; 96, attribute; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:k; 99, integer:1; 100, identifier:cloud; 101, attribute; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:k; 104, integer:1; 105, identifier:zone; 106, call; 106, 107; 106, 114; 107, attribute; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:k; 111, integer:1; 112, identifier:name; 113, identifier:lower; 114, argument_list; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:x; 118, integer:1; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:node_dict; 122, dictionary; 123, for_statement; 123, 124; 123, 127; 123, 132; 124, pattern_list; 124, 125; 124, 126; 125, identifier:i; 126, identifier:v; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:srt_dict; 130, identifier:items; 131, argument_list; 132, block; 132, 133; 132, 139; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:node_dict; 137, identifier:x; 138, identifier:v; 139, expression_statement; 139, 140; 140, augmented_assignment:+=; 140, 141; 140, 142; 141, identifier:x; 142, integer:1; 143, return_statement; 143, 144; 144, identifier:node_dict
def make_node_dict(outer_list, sort="zone"): raw_dict = {} x = 1 for inner_list in outer_list: for node in inner_list: raw_dict[x] = node x += 1 if sort == "name": srt_dict = OrderedDict(sorted(raw_dict.items(), key=lambda k: (k[1].cloud, k[1].name.lower()))) else: srt_dict = OrderedDict(sorted(raw_dict.items(), key=lambda k: (k[1].cloud, k[1].zone, k[1].name.lower()))) x = 1 node_dict = {} for i, v in srt_dict.items(): node_dict[x] = v x += 1 return node_dict
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:crack; 3, parameters; 3, 4; 3, 5; 3, 7; 3, 10; 4, identifier:ciphertext; 5, list_splat_pattern; 5, 6; 6, identifier:fitness_functions; 7, default_parameter; 7, 8; 7, 9; 8, identifier:ntrials; 9, integer:30; 10, default_parameter; 10, 11; 10, 12; 11, identifier:nswaps; 12, integer:3000; 13, block; 13, 14; 13, 28; 13, 99; 13, 134; 13, 151; 14, if_statement; 14, 15; 14, 22; 15, boolean_operator:or; 15, 16; 15, 19; 16, comparison_operator:<=; 16, 17; 16, 18; 17, identifier:ntrials; 18, integer:0; 19, comparison_operator:<=; 19, 20; 19, 21; 20, identifier:nswaps; 21, integer:0; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:ValueError; 26, argument_list; 26, 27; 27, string:"ntrials and nswaps must be positive integers"; 28, function_definition; 28, 29; 28, 30; 28, 32; 29, function_name:next_node_inner_climb; 30, parameters; 30, 31; 31, identifier:node; 32, block; 32, 33; 32, 51; 32, 67; 32, 75; 32, 84; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, pattern_list; 35, 36; 35, 37; 36, identifier:a; 37, identifier:b; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:random; 41, identifier:sample; 42, argument_list; 42, 43; 42, 50; 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, identifier:node; 50, integer:2; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 60; 53, pattern_list; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:node; 56, identifier:a; 57, subscript; 57, 58; 57, 59; 58, identifier:node; 59, identifier:b; 60, expression_list; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:node; 63, identifier:b; 64, subscript; 64, 65; 64, 66; 65, identifier:node; 66, identifier:a; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:plaintext; 70, call; 70, 71; 70, 72; 71, identifier:decrypt; 72, argument_list; 72, 73; 72, 74; 73, identifier:node; 74, identifier:ciphertext; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:node_score; 78, call; 78, 79; 78, 80; 79, identifier:score; 80, argument_list; 80, 81; 80, 82; 81, identifier:plaintext; 82, list_splat; 82, 83; 83, identifier:fitness_functions; 84, return_statement; 84, 85; 85, expression_list; 85, 86; 85, 87; 85, 88; 86, identifier:node; 87, identifier:node_score; 88, call; 88, 89; 88, 90; 89, identifier:Decryption; 90, argument_list; 90, 91; 90, 92; 90, 98; 91, identifier:plaintext; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, string:''; 95, identifier:join; 96, argument_list; 96, 97; 97, identifier:node; 98, identifier:node_score; 99, function_definition; 99, 100; 99, 101; 99, 103; 100, function_name:next_node_outer_climb; 101, parameters; 101, 102; 102, identifier:node; 103, block; 103, 104; 103, 111; 103, 126; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:random; 108, identifier:shuffle; 109, argument_list; 109, 110; 110, identifier:node; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 117; 113, pattern_list; 113, 114; 113, 115; 113, 116; 114, identifier:key; 115, identifier:best_score; 116, identifier:outputs; 117, call; 117, 118; 117, 119; 118, identifier:hill_climb; 119, argument_list; 119, 120; 119, 121; 119, 125; 120, identifier:nswaps; 121, subscript; 121, 122; 121, 123; 122, identifier:node; 123, slice; 123, 124; 124, colon; 125, identifier:next_node_inner_climb; 126, return_statement; 126, 127; 127, expression_list; 127, 128; 127, 129; 127, 130; 128, identifier:key; 129, identifier:best_score; 130, subscript; 130, 131; 130, 132; 131, identifier:outputs; 132, unary_operator:-; 132, 133; 133, integer:1; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 140; 136, pattern_list; 136, 137; 136, 138; 136, 139; 137, identifier:_; 138, identifier:_; 139, identifier:decryptions; 140, call; 140, 141; 140, 142; 141, identifier:hill_climb; 142, argument_list; 142, 143; 142, 144; 142, 150; 143, identifier:ntrials; 144, call; 144, 145; 144, 146; 145, identifier:list; 146, argument_list; 146, 147; 147, attribute; 147, 148; 147, 149; 148, identifier:string; 149, identifier:ascii_uppercase; 150, identifier:next_node_outer_climb; 151, return_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:sorted; 154, argument_list; 154, 155; 154, 156; 155, identifier:decryptions; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:reverse; 158, True
def crack(ciphertext, *fitness_functions, ntrials=30, nswaps=3000): if ntrials <= 0 or nswaps <= 0: raise ValueError("ntrials and nswaps must be positive integers") def next_node_inner_climb(node): a, b = random.sample(range(len(node)), 2) node[a], node[b] = node[b], node[a] plaintext = decrypt(node, ciphertext) node_score = score(plaintext, *fitness_functions) return node, node_score, Decryption(plaintext, ''.join(node), node_score) def next_node_outer_climb(node): random.shuffle(node) key, best_score, outputs = hill_climb(nswaps, node[:], next_node_inner_climb) return key, best_score, outputs[-1] _, _, decryptions = hill_climb(ntrials, list(string.ascii_uppercase), next_node_outer_climb) return sorted(decryptions, reverse=True)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:key_periods; 3, parameters; 3, 4; 3, 5; 4, identifier:ciphertext; 5, identifier:max_key_period; 6, block; 6, 7; 6, 17; 6, 21; 6, 64; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:<=; 8, 9; 8, 10; 9, identifier:max_key_period; 10, integer:0; 11, block; 11, 12; 12, raise_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:ValueError; 15, argument_list; 15, 16; 16, string:"max_key_period must be a positive integer"; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:key_scores; 20, list:[]; 21, for_statement; 21, 22; 21, 23; 21, 37; 22, identifier:period; 23, call; 23, 24; 23, 25; 24, identifier:range; 25, argument_list; 25, 26; 25, 27; 26, integer:1; 27, binary_operator:+; 27, 28; 27, 36; 28, call; 28, 29; 28, 30; 29, identifier:min; 30, argument_list; 30, 31; 30, 32; 31, identifier:max_key_period; 32, call; 32, 33; 32, 34; 33, identifier:len; 34, argument_list; 34, 35; 35, identifier:ciphertext; 36, integer:1; 37, block; 37, 38; 37, 55; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:score; 41, call; 41, 42; 41, 43; 42, identifier:abs; 43, argument_list; 43, 44; 44, binary_operator:-; 44, 45; 44, 46; 45, identifier:ENGLISH_IC; 46, call; 46, 47; 46, 48; 47, identifier:index_of_coincidence; 48, argument_list; 48, 49; 49, list_splat; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:split_columns; 52, argument_list; 52, 53; 52, 54; 53, identifier:ciphertext; 54, identifier:period; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:key_scores; 59, identifier:append; 60, argument_list; 60, 61; 61, tuple; 61, 62; 61, 63; 62, identifier:period; 63, identifier:score; 64, return_statement; 64, 65; 65, list_comprehension; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:p; 68, integer:0; 69, for_in_clause; 69, 70; 69, 71; 70, identifier:p; 71, call; 71, 72; 71, 73; 72, identifier:sorted; 73, argument_list; 73, 74; 73, 75; 74, identifier:key_scores; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:key; 77, lambda; 77, 78; 77, 80; 78, lambda_parameters; 78, 79; 79, identifier:x; 80, subscript; 80, 81; 80, 82; 81, identifier:x; 82, integer:1
def key_periods(ciphertext, max_key_period): if max_key_period <= 0: raise ValueError("max_key_period must be a positive integer") key_scores = [] for period in range(1, min(max_key_period, len(ciphertext)) + 1): score = abs(ENGLISH_IC - index_of_coincidence(*split_columns(ciphertext, period))) key_scores.append((period, score)) return [p[0] for p in sorted(key_scores, key=lambda x: x[1])]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:crack; 3, parameters; 3, 4; 3, 5; 3, 7; 3, 10; 3, 13; 4, identifier:ciphertext; 5, list_splat_pattern; 5, 6; 6, identifier:fitness_functions; 7, default_parameter; 7, 8; 7, 9; 8, identifier:min_key; 9, integer:0; 10, default_parameter; 10, 11; 10, 12; 11, identifier:max_key; 12, integer:26; 13, default_parameter; 13, 14; 13, 15; 14, identifier:shift_function; 15, identifier:shift_case_english; 16, block; 16, 17; 16, 27; 16, 31; 16, 67; 17, if_statement; 17, 18; 17, 21; 18, comparison_operator:>=; 18, 19; 18, 20; 19, identifier:min_key; 20, identifier:max_key; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:ValueError; 25, argument_list; 25, 26; 26, string:"min_key cannot exceed max_key"; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:decryptions; 30, list:[]; 31, for_statement; 31, 32; 31, 33; 31, 38; 32, identifier:key; 33, call; 33, 34; 33, 35; 34, identifier:range; 35, argument_list; 35, 36; 35, 37; 36, identifier:min_key; 37, identifier:max_key; 38, block; 38, 39; 38, 50; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:plaintext; 42, call; 42, 43; 42, 44; 43, identifier:decrypt; 44, argument_list; 44, 45; 44, 46; 44, 47; 45, identifier:key; 46, identifier:ciphertext; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:shift_function; 49, identifier:shift_function; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:decryptions; 54, identifier:append; 55, argument_list; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:Decryption; 58, argument_list; 58, 59; 58, 60; 58, 61; 59, identifier:plaintext; 60, identifier:key; 61, call; 61, 62; 61, 63; 62, identifier:score; 63, argument_list; 63, 64; 63, 65; 64, identifier:plaintext; 65, list_splat; 65, 66; 66, identifier:fitness_functions; 67, return_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:sorted; 70, argument_list; 70, 71; 70, 72; 71, identifier:decryptions; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:reverse; 74, True
def crack(ciphertext, *fitness_functions, min_key=0, max_key=26, shift_function=shift_case_english): if min_key >= max_key: raise ValueError("min_key cannot exceed max_key") decryptions = [] for key in range(min_key, max_key): plaintext = decrypt(key, ciphertext, shift_function=shift_function) decryptions.append(Decryption(plaintext, key, score(plaintext, *fitness_functions))) return sorted(decryptions, reverse=True)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:get_sort_limit; 3, parameters; 4, block; 4, 5; 4, 20; 4, 30; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:limit; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:_; 11, identifier:convert; 12, argument_list; 12, 13; 12, 17; 13, call; 13, 14; 13, 15; 14, identifier:get; 15, argument_list; 15, 16; 16, string:"sort_limit"; 17, attribute; 17, 18; 17, 19; 18, identifier:_; 19, identifier:to_int; 20, if_statement; 20, 21; 20, 25; 21, parenthesized_expression; 21, 22; 22, comparison_operator:<; 22, 23; 22, 24; 23, identifier:limit; 24, integer:1; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:limit; 29, None; 30, return_statement; 30, 31; 31, identifier:limit
def get_sort_limit(): limit = _.convert(get("sort_limit"), _.to_int) if (limit < 1): limit = None return limit
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_sort_on; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:allowed_indexes; 6, None; 7, block; 7, 8; 7, 15; 7, 36; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:sort_on; 11, call; 11, 12; 11, 13; 12, identifier:get; 13, argument_list; 13, 14; 14, string:"sort_on"; 15, if_statement; 15, 16; 15, 21; 16, boolean_operator:and; 16, 17; 16, 18; 17, identifier:allowed_indexes; 18, comparison_operator:not; 18, 19; 18, 20; 19, identifier:sort_on; 20, identifier:allowed_indexes; 21, block; 21, 22; 21, 34; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:logger; 26, identifier:warn; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, string:"Index '{}' is not in allowed_indexes"; 31, identifier:format; 32, argument_list; 32, 33; 33, identifier:sort_on; 34, return_statement; 34, 35; 35, None; 36, return_statement; 36, 37; 37, identifier:sort_on
def get_sort_on(allowed_indexes=None): sort_on = get("sort_on") if allowed_indexes and sort_on not in allowed_indexes: logger.warn("Index '{}' is not in allowed_indexes".format(sort_on)) return None return sort_on
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:to_list; 3, parameters; 3, 4; 4, identifier:thing; 5, block; 5, 6; 5, 13; 5, 25; 5, 49; 5, 65; 6, if_statement; 6, 7; 6, 10; 7, comparison_operator:is; 7, 8; 7, 9; 8, identifier:thing; 9, None; 10, block; 10, 11; 11, return_statement; 11, 12; 12, list:[]; 13, if_statement; 13, 14; 13, 19; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:thing; 18, identifier:set; 19, block; 19, 20; 20, return_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:list; 23, argument_list; 23, 24; 24, identifier:thing; 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:thing; 30, attribute; 30, 31; 30, 32; 31, identifier:types; 32, identifier:StringTypes; 33, block; 33, 34; 34, if_statement; 34, 35; 34, 41; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:thing; 38, identifier:startswith; 39, argument_list; 39, 40; 40, string:"["; 41, block; 41, 42; 42, return_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:ast; 46, identifier:literal_eval; 47, argument_list; 47, 48; 48, identifier:thing; 49, if_statement; 49, 50; 49, 61; 50, not_operator; 50, 51; 51, parenthesized_expression; 51, 52; 52, boolean_operator:or; 52, 53; 52, 57; 53, call; 53, 54; 53, 55; 54, identifier:is_list; 55, argument_list; 55, 56; 56, identifier:thing; 57, call; 57, 58; 57, 59; 58, identifier:is_tuple; 59, argument_list; 59, 60; 60, identifier:thing; 61, block; 61, 62; 62, return_statement; 62, 63; 63, list:[thing]; 63, 64; 64, identifier:thing; 65, return_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:list; 68, argument_list; 68, 69; 69, identifier:thing
def to_list(thing): if thing is None: return [] if isinstance(thing, set): return list(thing) if isinstance(thing, types.StringTypes): if thing.startswith("["): return ast.literal_eval(thing) if not (is_list(thing) or is_tuple(thing)): return [thing] return list(thing)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_sort_spec; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 16; 5, 27; 5, 35; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:all_indexes; 9, call; 9, 10; 9, 15; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:catalog; 14, identifier:get_indexes; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:si; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:req; 22, identifier:get_sort_on; 23, argument_list; 23, 24; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:allowed_indexes; 26, identifier:all_indexes; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:so; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:req; 33, identifier:get_sort_order; 34, argument_list; 35, return_statement; 35, 36; 36, expression_list; 36, 37; 36, 38; 37, identifier:si; 38, identifier:so
def get_sort_spec(self): all_indexes = self.catalog.get_indexes() si = req.get_sort_on(allowed_indexes=all_indexes) so = req.get_sort_order() return si, so
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sort_dict; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:data; 6, identifier:key; 7, block; 7, 8; 7, 10; 8, expression_statement; 8, 9; 9, string:'''Sort a list of dictionaries by dictionary key'''; 10, return_statement; 10, 11; 11, conditional_expression:if; 11, 12; 11, 22; 11, 23; 12, call; 12, 13; 12, 14; 13, identifier:sorted; 14, argument_list; 14, 15; 14, 16; 15, identifier:data; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:key; 18, call; 18, 19; 18, 20; 19, identifier:itemgetter; 20, argument_list; 20, 21; 21, identifier:key; 22, identifier:data; 23, list:[]
def sort_dict(self, data, key): '''Sort a list of dictionaries by dictionary key''' return sorted(data, key=itemgetter(key)) if data else []
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:load_drops; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:dropin; 6, block; 6, 7; 6, 14; 6, 51; 6, 64; 6, 79; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:obj; 10, call; 10, 11; 10, 12; 11, identifier:load_object; 12, argument_list; 12, 13; 13, identifier:dropin; 14, try_statement; 14, 15; 14, 26; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:drops; 19, call; 19, 20; 19, 21; 20, identifier:getattr; 21, argument_list; 21, 22; 21, 23; 22, identifier:obj; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:drops_type; 26, except_clause; 26, 27; 26, 28; 27, identifier:AttributeError; 28, block; 28, 29; 29, try_statement; 29, 30; 29, 44; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:drops; 34, call; 34, 35; 34, 36; 35, identifier:load_object; 36, argument_list; 36, 37; 37, binary_operator:%; 37, 38; 37, 39; 38, string:'%s.%s'; 39, tuple; 39, 40; 39, 41; 40, identifier:dropin; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:drops_type; 44, except_clause; 44, 45; 44, 46; 45, identifier:ImportError; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:drops; 50, None; 51, if_statement; 51, 52; 51, 57; 52, call; 52, 53; 52, 54; 53, identifier:hasattr; 54, argument_list; 54, 55; 54, 56; 55, identifier:drops; 56, string:'__drops__'; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:drops; 61, attribute; 61, 62; 61, 63; 62, identifier:drops; 63, identifier:__drops__; 64, if_statement; 64, 65; 64, 69; 65, call; 65, 66; 65, 67; 66, identifier:callable; 67, argument_list; 67, 68; 68, identifier:drops; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:drops; 73, call; 73, 74; 73, 75; 74, identifier:drops; 75, argument_list; 75, 76; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:app; 79, return_statement; 79, 80; 80, boolean_operator:or; 80, 81; 80, 82; 81, identifier:drops; 82, list:[]
def load_drops(self, dropin): obj = load_object(dropin) try: drops = getattr(obj, self.drops_type) except AttributeError: try: drops = load_object('%s.%s' % (dropin, self.drops_type)) except ImportError: drops = None if hasattr(drops, '__drops__'): drops = drops.__drops__ if callable(drops): drops = drops(self.app) return drops or []
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:attr_or_key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:direction; 8, string:'asc'; 9, block; 9, 10; 9, 49; 9, 69; 9, 79; 10, if_statement; 10, 11; 10, 19; 10, 26; 10, 42; 11, comparison_operator:in; 11, 12; 11, 13; 12, identifier:direction; 13, tuple; 13, 14; 13, 15; 13, 16; 14, string:'+'; 15, string:'asc'; 16, attribute; 16, 17; 16, 18; 17, identifier:gtk; 18, identifier:SORT_ASCENDING; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:direction; 23, attribute; 23, 24; 23, 25; 24, identifier:gtk; 25, identifier:SORT_ASCENDING; 26, elif_clause; 26, 27; 26, 35; 27, comparison_operator:in; 27, 28; 27, 29; 28, identifier:direction; 29, tuple; 29, 30; 29, 31; 29, 32; 30, string:'-'; 31, string:'desc'; 32, attribute; 32, 33; 32, 34; 33, identifier:gtk; 34, identifier:SORT_DESCENDING; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:direction; 39, attribute; 39, 40; 39, 41; 40, identifier:gtk; 41, identifier:SORT_DESCENDING; 42, else_clause; 42, 43; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:AttributeError; 47, argument_list; 47, 48; 48, string:'unrecognised direction'; 49, if_statement; 49, 50; 49, 54; 49, 61; 50, call; 50, 51; 50, 52; 51, identifier:callable; 52, argument_list; 52, 53; 53, identifier:attr_or_key; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:sort_func; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_key_sort_func; 61, else_clause; 61, 62; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:sort_func; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:_attr_sort_func; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:model; 75, identifier:set_default_sort_func; 76, argument_list; 76, 77; 76, 78; 77, identifier:sort_func; 78, identifier:attr_or_key; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:model; 85, identifier:set_sort_column_id; 86, argument_list; 86, 87; 86, 89; 87, unary_operator:-; 87, 88; 88, integer:1; 89, identifier:direction
def sort_by(self, attr_or_key, direction='asc'): if direction in ('+', 'asc', gtk.SORT_ASCENDING): direction = gtk.SORT_ASCENDING elif direction in ('-', 'desc', gtk.SORT_DESCENDING): direction = gtk.SORT_DESCENDING else: raise AttributeError('unrecognised direction') if callable(attr_or_key): sort_func = self._key_sort_func else: sort_func = self._attr_sort_func self.model.set_default_sort_func(sort_func, attr_or_key) self.model.set_sort_column_id(-1, direction)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:load_file; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:filepath; 6, block; 6, 7; 6, 13; 6, 28; 6, 43; 6, 64; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:file_path; 12, identifier:filepath; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 20; 15, pattern_list; 15, 16; 15, 17; 16, identifier:_; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:file_type; 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:splitext; 26, argument_list; 26, 27; 27, identifier:filepath; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 35; 30, pattern_list; 30, 31; 30, 32; 31, identifier:_; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:file_name; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:os; 39, identifier:path; 40, identifier:split; 41, argument_list; 41, 42; 42, identifier:filepath; 43, with_statement; 43, 44; 43, 53; 44, with_clause; 44, 45; 45, with_item; 45, 46; 46, as_pattern; 46, 47; 46, 51; 47, call; 47, 48; 47, 49; 48, identifier:open; 49, argument_list; 49, 50; 50, identifier:filepath; 51, as_pattern_target; 51, 52; 52, identifier:ffile; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:file_content; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:ffile; 62, identifier:readlines; 63, argument_list; 64, return_statement; 64, 65; 65, parenthesized_expression; 65, 66; 66, call; 66, 67; 66, 74; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_load_funcs; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:file_type; 74, argument_list
def load_file(self, filepath): self.file_path = filepath _, self.file_type = os.path.splitext(filepath) _, self.file_name = os.path.split(filepath) with open(filepath) as ffile: self.file_content = ffile.readlines() return (self._load_funcs[self.file_type]())
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:find; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:limit; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:exclude; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:duplicates; 19, True; 20, default_parameter; 20, 21; 20, 22; 21, identifier:pretty; 22, False; 23, dictionary_splat_pattern; 23, 24; 24, identifier:filters; 25, block; 25, 26; 25, 35; 25, 46; 25, 59; 25, 68; 25, 72; 25, 235; 25, 253; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:exclude; 29, None; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:exclude; 34, list:[]; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:not; 36, 37; 36, 38; 37, string:'href'; 38, identifier:filters; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:filters; 44, string:'href'; 45, True; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:search; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_soup; 54, identifier:findAll; 55, argument_list; 55, 56; 55, 57; 56, string:'a'; 57, dictionary_splat; 57, 58; 58, identifier:filters; 59, if_statement; 59, 60; 59, 61; 60, identifier:reverse; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:search; 66, identifier:reverse; 67, argument_list; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:links; 71, list:[]; 72, for_statement; 72, 73; 72, 74; 72, 75; 73, identifier:anchor; 74, identifier:search; 75, block; 75, 76; 75, 82; 75, 99; 75, 117; 75, 121; 75, 190; 75, 211; 75, 222; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:build_link; 79, attribute; 79, 80; 79, 81; 80, identifier:anchor; 81, identifier:attrs; 82, try_statement; 82, 83; 82, 95; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:build_link; 88, string:u'seo'; 89, call; 89, 90; 89, 91; 90, identifier:seoify_hyperlink; 91, argument_list; 91, 92; 92, subscript; 92, 93; 92, 94; 93, identifier:anchor; 94, string:'href'; 95, except_clause; 95, 96; 95, 97; 96, identifier:KeyError; 97, block; 97, 98; 98, pass_statement; 99, try_statement; 99, 100; 99, 113; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:build_link; 105, string:u'text'; 106, boolean_operator:or; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:anchor; 109, identifier:string; 110, subscript; 110, 111; 110, 112; 111, identifier:build_link; 112, string:'seo'; 113, except_clause; 113, 114; 113, 115; 114, identifier:KeyError; 115, block; 115, 116; 116, pass_statement; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:ignore_link; 120, False; 121, for_statement; 121, 122; 121, 123; 121, 124; 122, identifier:nixd; 123, identifier:exclude; 124, block; 124, 125; 125, for_statement; 125, 126; 125, 129; 125, 135; 126, pattern_list; 126, 127; 126, 128; 127, identifier:key; 128, identifier:value; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:six; 132, identifier:iteritems; 133, argument_list; 133, 134; 134, identifier:nixd; 135, block; 135, 136; 136, if_statement; 136, 137; 136, 140; 137, comparison_operator:in; 137, 138; 137, 139; 138, identifier:key; 139, identifier:build_link; 140, block; 140, 141; 141, if_statement; 141, 142; 141, 163; 141, 178; 142, parenthesized_expression; 142, 143; 143, boolean_operator:and; 143, 144; 143, 153; 144, call; 144, 145; 144, 146; 145, identifier:isinstance; 146, argument_list; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:build_link; 149, identifier:key; 150, attribute; 150, 151; 150, 152; 151, identifier:collections; 152, identifier:Iterable; 153, not_operator; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:isinstance; 156, argument_list; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:build_link; 159, identifier:key; 160, attribute; 160, 161; 160, 162; 161, identifier:six; 162, identifier:string_types; 163, block; 163, 164; 164, for_statement; 164, 165; 164, 166; 164, 169; 165, identifier:item; 166, subscript; 166, 167; 166, 168; 167, identifier:build_link; 168, identifier:key; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:ignore_link; 173, call; 173, 174; 173, 175; 174, identifier:exclude_match; 175, argument_list; 175, 176; 175, 177; 176, identifier:value; 177, identifier:item; 178, else_clause; 178, 179; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:ignore_link; 183, call; 183, 184; 183, 185; 184, identifier:exclude_match; 185, argument_list; 185, 186; 185, 187; 186, identifier:value; 187, subscript; 187, 188; 187, 189; 188, identifier:build_link; 189, identifier:key; 190, if_statement; 190, 191; 190, 193; 191, not_operator; 191, 192; 192, identifier:duplicates; 193, block; 193, 194; 194, for_statement; 194, 195; 194, 196; 194, 197; 195, identifier:link; 196, identifier:links; 197, block; 197, 198; 198, if_statement; 198, 199; 198, 206; 199, comparison_operator:==; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:link; 202, string:'href'; 203, subscript; 203, 204; 203, 205; 204, identifier:anchor; 205, string:'href'; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:ignore_link; 210, True; 211, if_statement; 211, 212; 211, 214; 212, not_operator; 212, 213; 213, identifier:ignore_link; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:links; 219, identifier:append; 220, argument_list; 220, 221; 221, identifier:build_link; 222, if_statement; 222, 223; 222, 233; 223, boolean_operator:and; 223, 224; 223, 227; 224, comparison_operator:is; 224, 225; 224, 226; 225, identifier:limit; 226, None; 227, comparison_operator:==; 227, 228; 227, 232; 228, call; 228, 229; 228, 230; 229, identifier:len; 230, argument_list; 230, 231; 231, identifier:links; 232, identifier:limit; 233, block; 233, 234; 234, break_statement; 235, if_statement; 235, 236; 235, 239; 236, comparison_operator:is; 236, 237; 236, 238; 237, identifier:sort; 238, None; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:links; 243, call; 243, 244; 243, 245; 244, identifier:sorted; 245, argument_list; 245, 246; 245, 247; 245, 250; 246, identifier:links; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:key; 249, identifier:sort; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:reverse; 252, identifier:reverse; 253, if_statement; 253, 254; 253, 255; 253, 274; 254, identifier:pretty; 255, block; 255, 256; 255, 267; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:pp; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:pprint; 262, identifier:PrettyPrinter; 263, argument_list; 263, 264; 264, keyword_argument; 264, 265; 264, 266; 265, identifier:indent; 266, integer:4; 267, return_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:pp; 271, identifier:pprint; 272, argument_list; 272, 273; 273, identifier:links; 274, else_clause; 274, 275; 275, block; 275, 276; 276, return_statement; 276, 277; 277, identifier:links
def find(self, limit=None, reverse=False, sort=None, exclude=None, duplicates=True, pretty=False, **filters): if exclude is None: exclude = [] if 'href' not in filters: filters['href'] = True search = self._soup.findAll('a', **filters) if reverse: search.reverse() links = [] for anchor in search: build_link = anchor.attrs try: build_link[u'seo'] = seoify_hyperlink(anchor['href']) except KeyError: pass try: build_link[u'text'] = anchor.string or build_link['seo'] except KeyError: pass ignore_link = False for nixd in exclude: for key, value in six.iteritems(nixd): if key in build_link: if (isinstance(build_link[key], collections.Iterable) and not isinstance(build_link[key], six.string_types)): for item in build_link[key]: ignore_link = exclude_match(value, item) else: ignore_link = exclude_match(value, build_link[key]) if not duplicates: for link in links: if link['href'] == anchor['href']: ignore_link = True if not ignore_link: links.append(build_link) if limit is not None and len(links) == limit: break if sort is not None: links = sorted(links, key=sort, reverse=reverse) if pretty: pp = pprint.PrettyPrinter(indent=4) return pp.pprint(links) else: return links
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:__draw_cmp; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:obj1; 6, identifier:obj2; 7, block; 7, 8; 8, if_statement; 8, 9; 8, 16; 8, 19; 8, 31; 9, comparison_operator:>; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:obj1; 12, identifier:draw_order; 13, attribute; 13, 14; 13, 15; 14, identifier:obj2; 15, identifier:draw_order; 16, block; 16, 17; 17, return_statement; 17, 18; 18, integer:1; 19, elif_clause; 19, 20; 19, 27; 20, comparison_operator:<; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:obj1; 23, identifier:draw_order; 24, attribute; 24, 25; 24, 26; 25, identifier:obj2; 26, identifier:draw_order; 27, block; 27, 28; 28, return_statement; 28, 29; 29, unary_operator:-; 29, 30; 30, integer:1; 31, else_clause; 31, 32; 32, block; 32, 33; 33, return_statement; 33, 34; 34, integer:0
def __draw_cmp(self, obj1, obj2): if obj1.draw_order > obj2.draw_order: return 1 elif obj1.draw_order < obj2.draw_order: return -1 else: return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:__up_cmp; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:obj1; 6, identifier:obj2; 7, block; 7, 8; 8, if_statement; 8, 9; 8, 16; 8, 19; 8, 31; 9, comparison_operator:>; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:obj1; 12, identifier:update_order; 13, attribute; 13, 14; 13, 15; 14, identifier:obj2; 15, identifier:update_order; 16, block; 16, 17; 17, return_statement; 17, 18; 18, integer:1; 19, elif_clause; 19, 20; 19, 27; 20, comparison_operator:<; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:obj1; 23, identifier:update_order; 24, attribute; 24, 25; 24, 26; 25, identifier:obj2; 26, identifier:update_order; 27, block; 27, 28; 28, return_statement; 28, 29; 29, unary_operator:-; 29, 30; 30, integer:1; 31, else_clause; 31, 32; 32, block; 32, 33; 33, return_statement; 33, 34; 34, integer:0
def __up_cmp(self, obj1, obj2): if obj1.update_order > obj2.update_order: return 1 elif obj1.update_order < obj2.update_order: return -1 else: return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:discover; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:timeout; 6, integer:1; 7, default_parameter; 7, 8; 7, 9; 8, identifier:retries; 9, integer:1; 10, block; 10, 11; 10, 15; 10, 21; 10, 25; 10, 51; 10, 58; 10, 191; 10, 202; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:locations; 14, list:[]; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:group; 18, tuple; 18, 19; 18, 20; 19, string:'239.255.255.250'; 20, integer:1900; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:service; 24, string:'ssdp:urn:schemas-upnp-org:device:MediaRenderer:1'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:message; 28, call; 28, 29; 28, 44; 29, attribute; 29, 30; 29, 43; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, string:'\r\n'; 33, identifier:join; 34, argument_list; 34, 35; 35, list:['M-SEARCH * HTTP/1.1', 'HOST: {group[0]}:{group[1]}', 'MAN: "ssdp:discover"', 'ST: {st}', 'MX: 1', '', '']; 35, 36; 35, 37; 35, 38; 35, 39; 35, 40; 35, 41; 35, 42; 36, string:'M-SEARCH * HTTP/1.1'; 37, string:'HOST: {group[0]}:{group[1]}'; 38, string:'MAN: "ssdp:discover"'; 39, string:'ST: {st}'; 40, string:'MX: 1'; 41, string:''; 42, string:''; 43, identifier:format; 44, argument_list; 44, 45; 44, 48; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:group; 47, identifier:group; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:st; 50, identifier:service; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:socket; 55, identifier:setdefaulttimeout; 56, argument_list; 56, 57; 57, identifier:timeout; 58, for_statement; 58, 59; 58, 60; 58, 64; 59, identifier:_; 60, call; 60, 61; 60, 62; 61, identifier:range; 62, argument_list; 62, 63; 63, identifier:retries; 64, block; 64, 65; 64, 82; 64, 95; 64, 108; 64, 121; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:sock; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:socket; 71, identifier:socket; 72, argument_list; 72, 73; 72, 76; 72, 79; 73, attribute; 73, 74; 73, 75; 74, identifier:socket; 75, identifier:AF_INET; 76, attribute; 76, 77; 76, 78; 77, identifier:socket; 78, identifier:SOCK_DGRAM; 79, attribute; 79, 80; 79, 81; 80, identifier:socket; 81, identifier:IPPROTO_UDP; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:sock; 86, identifier:setsockopt; 87, argument_list; 87, 88; 87, 91; 87, 94; 88, attribute; 88, 89; 88, 90; 89, identifier:socket; 90, identifier:SOL_SOCKET; 91, attribute; 91, 92; 91, 93; 92, identifier:socket; 93, identifier:SO_REUSEADDR; 94, integer:1; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:sock; 99, identifier:setsockopt; 100, argument_list; 100, 101; 100, 104; 100, 107; 101, attribute; 101, 102; 101, 103; 102, identifier:socket; 103, identifier:IPPROTO_IP; 104, attribute; 104, 105; 104, 106; 105, identifier:socket; 106, identifier:IP_MULTICAST_TTL; 107, integer:2; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:sock; 112, identifier:sendto; 113, argument_list; 113, 114; 113, 120; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:message; 117, identifier:encode; 118, argument_list; 118, 119; 119, string:'utf-8'; 120, identifier:group; 121, while_statement; 121, 122; 121, 123; 122, True; 123, block; 123, 124; 124, try_statement; 124, 125; 124, 185; 125, block; 125, 126; 125, 140; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:response; 129, call; 129, 130; 129, 138; 130, attribute; 130, 131; 130, 137; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:sock; 134, identifier:recv; 135, argument_list; 135, 136; 136, integer:2048; 137, identifier:decode; 138, argument_list; 138, 139; 139, string:'utf-8'; 140, for_statement; 140, 141; 140, 142; 140, 148; 141, identifier:line; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:response; 145, identifier:split; 146, argument_list; 146, 147; 147, string:'\r\n'; 148, block; 148, 149; 149, if_statement; 149, 150; 149, 156; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:line; 153, identifier:startswith; 154, argument_list; 154, 155; 155, string:'Location: '; 156, block; 156, 157; 156, 172; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:location; 160, call; 160, 161; 160, 171; 161, attribute; 161, 162; 161, 170; 162, subscript; 162, 163; 162, 169; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:line; 166, identifier:split; 167, argument_list; 167, 168; 168, string:' '; 169, integer:1; 170, identifier:strip; 171, argument_list; 172, if_statement; 172, 173; 172, 177; 173, not_operator; 173, 174; 174, comparison_operator:in; 174, 175; 174, 176; 175, identifier:location; 176, identifier:locations; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:locations; 182, identifier:append; 183, argument_list; 183, 184; 184, identifier:location; 185, except_clause; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:socket; 188, identifier:timeout; 189, block; 189, 190; 190, break_statement; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:devices; 194, list_comprehension; 194, 195; 194, 199; 195, call; 195, 196; 195, 197; 196, identifier:RaumfeldDevice; 197, argument_list; 197, 198; 198, identifier:location; 199, for_in_clause; 199, 200; 199, 201; 200, identifier:location; 201, identifier:locations; 202, return_statement; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:sorted; 205, argument_list; 205, 206; 205, 217; 206, list_comprehension; 206, 207; 206, 208; 206, 211; 207, identifier:device; 208, for_in_clause; 208, 209; 208, 210; 209, identifier:device; 210, identifier:devices; 211, if_clause; 211, 212; 212, comparison_operator:==; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:device; 215, identifier:model_description; 216, string:'Virtual Media Player'; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:key; 219, lambda; 219, 220; 219, 222; 220, lambda_parameters; 220, 221; 221, identifier:device; 222, attribute; 222, 223; 222, 224; 223, identifier:device; 224, identifier:friendly_name
def discover(timeout=1, retries=1): locations = [] group = ('239.255.255.250', 1900) service = 'ssdp:urn:schemas-upnp-org:device:MediaRenderer:1' message = '\r\n'.join(['M-SEARCH * HTTP/1.1', 'HOST: {group[0]}:{group[1]}', 'MAN: "ssdp:discover"', 'ST: {st}', 'MX: 1', '', '']).format(group=group, st=service) socket.setdefaulttimeout(timeout) for _ in range(retries): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) sock.sendto(message.encode('utf-8'), group) while True: try: response = sock.recv(2048).decode('utf-8') for line in response.split('\r\n'): if line.startswith('Location: '): location = line.split(' ')[1].strip() if not location in locations: locations.append(location) except socket.timeout: break devices = [RaumfeldDevice(location) for location in locations] return sorted([device for device in devices if device.model_description == 'Virtual Media Player'], key=lambda device: device.friendly_name)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_user_trades; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:limit; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:offset; 10, integer:0; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, string:'desc'; 14, block; 14, 15; 14, 22; 14, 52; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_log; 20, argument_list; 20, 21; 21, string:'get user trades'; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:res; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_rest_client; 30, identifier:post; 31, argument_list; 31, 32; 31, 35; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:endpoint; 34, string:'/user_transactions'; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:payload; 37, dictionary; 37, 38; 37, 43; 37, 46; 37, 49; 38, pair; 38, 39; 38, 40; 39, string:'book'; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:name; 43, pair; 43, 44; 43, 45; 44, string:'limit'; 45, identifier:limit; 46, pair; 46, 47; 46, 48; 47, string:'offset'; 48, identifier:offset; 49, pair; 49, 50; 49, 51; 50, string:'sort'; 51, identifier:sort; 52, return_statement; 52, 53; 53, conditional_expression:if; 53, 54; 53, 59; 53, 66; 54, subscript; 54, 55; 54, 56; 55, identifier:res; 56, slice; 56, 57; 56, 58; 57, colon; 58, identifier:limit; 59, comparison_operator:>; 59, 60; 59, 64; 59, 65; 60, call; 60, 61; 60, 62; 61, identifier:len; 62, argument_list; 62, 63; 63, identifier:res; 64, identifier:limit; 65, integer:0; 66, identifier:res
def get_user_trades(self, limit=0, offset=0, sort='desc'): self._log('get user trades') res = self._rest_client.post( endpoint='/user_transactions', payload={ 'book': self.name, 'limit': limit, 'offset': offset, 'sort': sort } ) return res[:limit] if len(res) > limit > 0 else res
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:col; 7, type; 7, 8; 8, identifier:str; 9, block; 9, 10; 10, try_statement; 10, 11; 10, 29; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:df; 17, call; 17, 18; 17, 27; 18, attribute; 18, 19; 18, 26; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:df; 24, identifier:copy; 25, argument_list; 26, identifier:sort_values; 27, argument_list; 27, 28; 28, identifier:col; 29, except_clause; 29, 30; 29, 34; 30, as_pattern; 30, 31; 30, 32; 31, identifier:Exception; 32, as_pattern_target; 32, 33; 33, identifier:e; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:err; 40, argument_list; 40, 41; 40, 42; 41, identifier:e; 42, binary_operator:+; 42, 43; 42, 44; 43, string:"Can not sort the dataframe from column "; 44, call; 44, 45; 44, 46; 45, identifier:str; 46, argument_list; 46, 47; 47, identifier:col
def sort(self, col: str): try: self.df = self.df.copy().sort_values(col) except Exception as e: self.err(e, "Can not sort the dataframe from column " + str(col))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:iterate; 3, parameters; 3, 4; 3, 5; 3, 13; 3, 16; 3, 19; 3, 22; 4, identifier:MachineClass; 5, default_parameter; 5, 6; 5, 7; 6, identifier:stop_function; 7, lambda; 7, 8; 7, 10; 8, lambda_parameters; 8, 9; 9, identifier:iterations; 10, comparison_operator:<; 10, 11; 10, 12; 11, identifier:iterations; 12, integer:10000; 13, default_parameter; 13, 14; 13, 15; 14, identifier:machines; 15, integer:1000; 16, default_parameter; 16, 17; 16, 18; 17, identifier:survival_rate; 18, float:0.05; 19, default_parameter; 19, 20; 19, 21; 20, identifier:mutation_rate; 21, float:0.075; 22, default_parameter; 22, 23; 22, 24; 23, identifier:silent; 24, False; 25, block; 25, 26; 25, 39; 25, 64; 25, 90; 25, 101; 25, 105; 25, 124; 25, 362; 26, function_definition; 26, 27; 26, 28; 26, 30; 27, function_name:make_random; 28, parameters; 28, 29; 29, identifier:n; 30, block; 30, 31; 31, return_statement; 31, 32; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, call; 34, 35; 34, 36; 35, identifier:MachineClass; 36, argument_list; 37, identifier:randomize; 38, argument_list; 39, function_definition; 39, 40; 39, 41; 39, 43; 40, function_name:run_once; 41, parameters; 41, 42; 42, identifier:m; 43, block; 43, 44; 43, 50; 43, 56; 43, 62; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:m; 48, identifier:setUp; 49, argument_list; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:m; 54, identifier:run; 55, argument_list; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:m; 60, identifier:tearDown; 61, argument_list; 62, return_statement; 62, 63; 63, identifier:m; 64, function_definition; 64, 65; 64, 66; 64, 68; 65, function_name:make_offspring; 66, parameters; 66, 67; 67, identifier:survivors; 68, block; 68, 69; 68, 76; 68, 83; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:a; 72, call; 72, 73; 72, 74; 73, identifier:stochastic_choice; 74, argument_list; 74, 75; 75, identifier:survivors; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:b; 79, call; 79, 80; 79, 81; 80, identifier:stochastic_choice; 81, argument_list; 81, 82; 82, identifier:survivors; 83, return_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:a; 87, identifier:crossover; 88, argument_list; 88, 89; 89, identifier:b; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:generation; 93, call; 93, 94; 93, 95; 94, identifier:map; 95, argument_list; 95, 96; 95, 97; 96, identifier:make_random; 97, call; 97, 98; 97, 99; 98, identifier:xrange; 99, argument_list; 99, 100; 100, identifier:machines; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:survivors; 104, identifier:generation; 105, if_statement; 105, 106; 105, 107; 105, 118; 106, identifier:silent; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:log; 111, lambda; 111, 112; 111, 117; 112, lambda_parameters; 112, 113; 112, 114; 113, identifier:s; 114, default_parameter; 114, 115; 114, 116; 115, identifier:stream; 116, None; 117, None; 118, else_clause; 118, 119; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:log; 123, identifier:_log; 124, try_statement; 124, 125; 124, 358; 125, block; 125, 126; 125, 130; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:iterations; 129, integer:0; 130, while_statement; 130, 131; 130, 137; 131, not_operator; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:stop_function; 134, argument_list; 134, 135; 134, 136; 135, identifier:iterations; 136, identifier:survivors; 137, block; 137, 138; 137, 142; 137, 147; 137, 155; 137, 172; 137, 188; 137, 214; 137, 231; 137, 260; 137, 265; 137, 275; 137, 286; 137, 305; 138, expression_statement; 138, 139; 139, augmented_assignment:+=; 139, 140; 139, 141; 140, identifier:iterations; 141, integer:1; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:log; 145, argument_list; 145, 146; 146, string:"running ... "; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:generation; 150, call; 150, 151; 150, 152; 151, identifier:map; 152, argument_list; 152, 153; 152, 154; 153, identifier:run_once; 154, identifier:generation; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:generation; 158, call; 158, 159; 158, 160; 159, identifier:sorted; 160, argument_list; 160, 161; 160, 162; 161, identifier:generation; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:key; 164, lambda; 164, 165; 164, 167; 165, lambda_parameters; 165, 166; 166, identifier:m; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:m; 170, identifier:score; 171, argument_list; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:survivors; 175, subscript; 175, 176; 175, 177; 176, identifier:generation; 177, slice; 177, 178; 177, 179; 178, colon; 179, call; 179, 180; 179, 181; 180, identifier:int; 181, argument_list; 181, 182; 182, binary_operator:*; 182, 183; 182, 184; 183, identifier:survival_rate; 184, call; 184, 185; 184, 186; 185, identifier:len; 186, argument_list; 186, 187; 187, identifier:generation; 188, for_statement; 188, 189; 188, 190; 188, 191; 189, identifier:s; 190, identifier:survivors; 191, block; 191, 192; 192, if_statement; 192, 193; 192, 201; 193, comparison_operator:>=; 193, 194; 193, 200; 194, call; 194, 195; 194, 196; 195, identifier:len; 196, argument_list; 196, 197; 197, attribute; 197, 198; 197, 199; 198, identifier:s; 199, identifier:code; 200, integer:50; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:s; 206, identifier:code; 207, subscript; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:s; 210, identifier:code; 211, slice; 211, 212; 211, 213; 212, colon; 213, integer:50; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:survivors; 217, list_comprehension; 217, 218; 217, 219; 217, 222; 218, identifier:s; 219, for_in_clause; 219, 220; 219, 221; 220, identifier:s; 221, identifier:survivors; 222, if_clause; 222, 223; 223, comparison_operator:>; 223, 224; 223, 230; 224, call; 224, 225; 224, 226; 225, identifier:len; 226, argument_list; 226, 227; 227, attribute; 227, 228; 227, 229; 228, identifier:s; 229, identifier:code; 230, integer:0; 231, if_statement; 231, 232; 231, 238; 232, comparison_operator:==; 232, 233; 232, 237; 233, call; 233, 234; 233, 235; 234, identifier:len; 235, argument_list; 235, 236; 236, identifier:survivors; 237, integer:0; 238, block; 238, 239; 238, 244; 238, 255; 238, 259; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 242; 241, identifier:log; 242, argument_list; 242, 243; 243, string:"\nNo survivors, restarting"; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:survivors; 247, call; 247, 248; 247, 249; 248, identifier:map; 249, argument_list; 249, 250; 249, 251; 250, identifier:make_random; 251, call; 251, 252; 251, 253; 252, identifier:xrange; 253, argument_list; 253, 254; 254, identifier:machines; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:generation; 258, identifier:survivors; 259, continue_statement; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 263; 262, identifier:log; 263, argument_list; 263, 264; 264, string:"crossover ... "; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:cross; 268, lambda; 268, 269; 268, 271; 269, lambda_parameters; 269, 270; 270, identifier:_; 271, call; 271, 272; 271, 273; 272, identifier:make_offspring; 273, argument_list; 273, 274; 274, identifier:survivors; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:generation; 278, call; 278, 279; 278, 280; 279, identifier:map; 280, argument_list; 280, 281; 280, 282; 281, identifier:cross; 282, call; 282, 283; 282, 284; 283, identifier:xrange; 284, argument_list; 284, 285; 285, identifier:machines; 286, for_statement; 286, 287; 286, 288; 286, 289; 287, identifier:m; 288, identifier:generation; 289, block; 289, 290; 290, if_statement; 290, 291; 290, 298; 291, comparison_operator:>; 291, 292; 291, 297; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:random; 295, identifier:random; 296, argument_list; 297, identifier:mutation_rate; 298, block; 298, 299; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:m; 303, identifier:mutate; 304, argument_list; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 308; 307, identifier:log; 308, argument_list; 308, 309; 309, binary_operator:%; 309, 310; 309, 311; 310, string:"\rgen %d 1-fitness %.12f avg code len %.2f avg stack len %.2f\n"; 311, tuple; 311, 312; 311, 313; 311, 325; 311, 338; 312, identifier:iterations; 313, call; 313, 314; 313, 315; 314, identifier:average; 315, argument_list; 315, 316; 315, 317; 316, identifier:survivors; 317, lambda; 317, 318; 317, 320; 318, lambda_parameters; 318, 319; 319, identifier:m; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:m; 323, identifier:score; 324, argument_list; 325, call; 325, 326; 325, 327; 326, identifier:average; 327, argument_list; 327, 328; 327, 329; 328, identifier:survivors; 329, lambda; 329, 330; 329, 332; 330, lambda_parameters; 330, 331; 331, identifier:m; 332, call; 332, 333; 332, 334; 333, identifier:len; 334, argument_list; 334, 335; 335, attribute; 335, 336; 335, 337; 336, identifier:m; 337, identifier:code; 338, call; 338, 339; 338, 340; 339, identifier:average; 340, argument_list; 340, 341; 340, 342; 341, identifier:survivors; 342, lambda; 342, 343; 342, 345; 343, lambda_parameters; 343, 344; 344, identifier:m; 345, binary_operator:+; 345, 346; 345, 352; 346, call; 346, 347; 346, 348; 347, identifier:len; 348, argument_list; 348, 349; 349, attribute; 349, 350; 349, 351; 350, identifier:m; 351, identifier:stack; 352, call; 352, 353; 352, 354; 353, identifier:len; 354, argument_list; 354, 355; 355, attribute; 355, 356; 355, 357; 356, identifier:m; 357, identifier:return_stack; 358, except_clause; 358, 359; 358, 360; 359, identifier:KeyboardInterrupt; 360, block; 360, 361; 361, pass_statement; 362, return_statement; 362, 363; 363, identifier:survivors
def iterate(MachineClass, stop_function=lambda iterations: iterations < 10000, machines=1000, survival_rate=0.05, mutation_rate=0.075, silent=False): def make_random(n): return MachineClass().randomize() def run_once(m): m.setUp() m.run() m.tearDown() return m def make_offspring(survivors): a = stochastic_choice(survivors) b = stochastic_choice(survivors) return a.crossover(b) generation = map(make_random, xrange(machines)) survivors = generation if silent: log = lambda s,stream=None: None else: log = _log try: iterations = 0 while not stop_function(iterations, survivors): iterations += 1 log("running ... ") generation = map(run_once, generation) generation = sorted(generation, key=lambda m: m.score()) survivors = generation[:int(survival_rate * len(generation))] for s in survivors: if len(s.code) >= 50: s.code = s.code[:50] survivors = [s for s in survivors if len(s.code)>0] if len(survivors) == 0: log("\nNo survivors, restarting") survivors = map(make_random, xrange(machines)) generation = survivors continue log("crossover ... ") cross = lambda _: make_offspring(survivors) generation = map(cross, xrange(machines)) for m in generation: if random.random() > mutation_rate: m.mutate() log("\rgen %d 1-fitness %.12f avg code len %.2f avg stack len %.2f\n" % (iterations, average(survivors, lambda m: m.score()), average(survivors, lambda m: len(m.code)), average(survivors, lambda m: len(m.stack) + len(m.return_stack)))) except KeyboardInterrupt: pass return survivors
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:count_account; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:domain; 6, block; 6, 7; 6, 15; 6, 28; 6, 32; 6, 61; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:selector; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:domain; 13, identifier:to_selector; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:cos_list; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:request_list; 22, argument_list; 22, 23; 22, 24; 23, string:'CountAccount'; 24, dictionary; 24, 25; 25, pair; 25, 26; 25, 27; 26, string:'domain'; 27, identifier:selector; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:ret; 31, list:[]; 32, for_statement; 32, 33; 32, 34; 32, 35; 33, identifier:i; 34, identifier:cos_list; 35, block; 35, 36; 35, 45; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:count; 39, call; 39, 40; 39, 41; 40, identifier:int; 41, argument_list; 41, 42; 42, subscript; 42, 43; 42, 44; 43, identifier:i; 44, string:'_content'; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:ret; 49, identifier:append; 50, argument_list; 50, 51; 51, tuple; 51, 52; 51, 60; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:zobjects; 56, identifier:ClassOfService; 57, identifier:from_dict; 58, argument_list; 58, 59; 59, identifier:i; 60, identifier:count; 61, return_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:list; 64, argument_list; 64, 65; 65, identifier:ret
def count_account(self, domain): selector = domain.to_selector() cos_list = self.request_list('CountAccount', {'domain': selector}) ret = [] for i in cos_list: count = int(i['_content']) ret.append((zobjects.ClassOfService.from_dict(i), count)) return list(ret)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:search_directory; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 18; 7, 22; 7, 61; 7, 113; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:search_response; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:request; 15, argument_list; 15, 16; 15, 17; 16, string:'SearchDirectory'; 17, identifier:kwargs; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:result; 21, dictionary; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:items; 25, dictionary; 25, 26; 25, 33; 25, 40; 25, 47; 25, 54; 26, pair; 26, 27; 26, 28; 27, string:"account"; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:zobjects; 31, identifier:Account; 32, identifier:from_dict; 33, pair; 33, 34; 33, 35; 34, string:"domain"; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:zobjects; 38, identifier:Domain; 39, identifier:from_dict; 40, pair; 40, 41; 40, 42; 41, string:"dl"; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:zobjects; 45, identifier:DistributionList; 46, identifier:from_dict; 47, pair; 47, 48; 47, 49; 48, string:"cos"; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:zobjects; 52, identifier:COS; 53, identifier:from_dict; 54, pair; 54, 55; 54, 56; 55, string:"calresource"; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:zobjects; 59, identifier:CalendarResource; 60, identifier:from_dict; 61, for_statement; 61, 62; 61, 65; 61, 70; 62, pattern_list; 62, 63; 62, 64; 63, identifier:obj_type; 64, identifier:func; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:items; 68, identifier:items; 69, argument_list; 70, block; 70, 71; 71, if_statement; 71, 72; 71, 75; 72, comparison_operator:in; 72, 73; 72, 74; 73, identifier:obj_type; 74, identifier:search_response; 75, block; 75, 76; 76, if_statement; 76, 77; 76, 84; 76, 100; 77, call; 77, 78; 77, 79; 78, identifier:isinstance; 79, argument_list; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:search_response; 82, identifier:obj_type; 83, identifier:list; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:result; 89, identifier:obj_type; 90, list_comprehension; 90, 91; 90, 95; 91, call; 91, 92; 91, 93; 92, identifier:func; 93, argument_list; 93, 94; 94, identifier:v; 95, for_in_clause; 95, 96; 95, 97; 96, identifier:v; 97, subscript; 97, 98; 97, 99; 98, identifier:search_response; 99, identifier:obj_type; 100, else_clause; 100, 101; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:result; 106, identifier:obj_type; 107, call; 107, 108; 107, 109; 108, identifier:func; 109, argument_list; 109, 110; 110, subscript; 110, 111; 110, 112; 111, identifier:search_response; 112, identifier:obj_type; 113, return_statement; 113, 114; 114, identifier:result
def search_directory(self, **kwargs): search_response = self.request('SearchDirectory', kwargs) result = {} items = { "account": zobjects.Account.from_dict, "domain": zobjects.Domain.from_dict, "dl": zobjects.DistributionList.from_dict, "cos": zobjects.COS.from_dict, "calresource": zobjects.CalendarResource.from_dict } for obj_type, func in items.items(): if obj_type in search_response: if isinstance(search_response[obj_type], list): result[obj_type] = [ func(v) for v in search_response[obj_type]] else: result[obj_type] = func(search_response[obj_type]) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:query; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 13; 8, 22; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:content; 12, identifier:kwargs; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 18; 15, subscript; 15, 16; 15, 17; 16, identifier:content; 17, string:'query'; 18, dictionary; 18, 19; 19, pair; 19, 20; 19, 21; 20, string:'_content'; 21, identifier:query; 22, return_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:request; 27, argument_list; 27, 28; 27, 29; 28, string:'Search'; 29, identifier:content
def search(self, query, **kwargs): content = kwargs content['query'] = {'_content': query} return self.request('Search', content)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_call_zincrby; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 9; 4, identifier:self; 5, identifier:command; 6, identifier:value; 7, list_splat_pattern; 7, 8; 8, identifier:args; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 25; 12, if_statement; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:indexable; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:index; 22, argument_list; 22, 23; 23, list:[value]; 23, 24; 24, identifier:value; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_traverse_command; 30, argument_list; 30, 31; 30, 32; 30, 33; 30, 35; 31, identifier:command; 32, identifier:value; 33, list_splat; 33, 34; 34, identifier:args; 35, dictionary_splat; 35, 36; 36, identifier:kwargs
def _call_zincrby(self, command, value, *args, **kwargs): if self.indexable: self.index([value]) return self._traverse_command(command, value, *args, **kwargs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_extract_value_from_storage; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:string; 6, block; 6, 7; 6, 18; 6, 26; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:parts; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:string; 13, identifier:split; 14, argument_list; 14, 15; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:separator; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:pk; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:parts; 24, identifier:pop; 25, argument_list; 26, return_statement; 26, 27; 27, expression_list; 27, 28; 27, 36; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:separator; 33, identifier:join; 34, argument_list; 34, 35; 35, identifier:parts; 36, identifier:pk
def _extract_value_from_storage(self, string): parts = string.split(self.separator) pk = parts.pop() return self.separator.join(parts), pk
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_boundaries; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:filter_type; 6, identifier:value; 7, block; 7, 8; 7, 14; 7, 18; 7, 22; 7, 26; 7, 143; 8, assert_statement; 8, 9; 9, comparison_operator:in; 9, 10; 9, 11; 10, identifier:filter_type; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:handled_suffixes; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:start; 17, string:'-'; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:end; 21, string:'+'; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:exclude; 25, None; 26, if_statement; 26, 27; 26, 32; 26, 54; 26, 69; 26, 80; 26, 95; 26, 121; 27, comparison_operator:in; 27, 28; 27, 29; 28, identifier:filter_type; 29, tuple; 29, 30; 29, 31; 30, None; 31, string:'eq'; 32, block; 32, 33; 32, 43; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:start; 36, binary_operator:%; 36, 37; 36, 38; 37, string:u'[%s%s'; 38, tuple; 38, 39; 38, 40; 39, identifier:value; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:separator; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:end; 46, binary_operator:+; 46, 47; 46, 53; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:start; 50, identifier:encode; 51, argument_list; 51, 52; 52, string:'utf-8'; 53, string:b'\xff'; 54, elif_clause; 54, 55; 54, 58; 55, comparison_operator:==; 55, 56; 55, 57; 56, identifier:filter_type; 57, string:'gt'; 58, block; 58, 59; 58, 65; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:start; 62, binary_operator:%; 62, 63; 62, 64; 63, string:u'(%s'; 64, identifier:value; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:exclude; 68, identifier:value; 69, elif_clause; 69, 70; 69, 73; 70, comparison_operator:==; 70, 71; 70, 72; 71, identifier:filter_type; 72, string:'gte'; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:start; 77, binary_operator:%; 77, 78; 77, 79; 78, string:u'[%s'; 79, identifier:value; 80, elif_clause; 80, 81; 80, 84; 81, comparison_operator:==; 81, 82; 81, 83; 82, identifier:filter_type; 83, string:'lt'; 84, block; 84, 85; 84, 91; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:end; 88, binary_operator:%; 88, 89; 88, 90; 89, string:u'(%s'; 90, identifier:value; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:exclude; 94, identifier:value; 95, elif_clause; 95, 96; 95, 99; 96, comparison_operator:==; 96, 97; 96, 98; 97, identifier:filter_type; 98, string:'lte'; 99, block; 99, 100; 99, 110; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:end; 103, binary_operator:%; 103, 104; 103, 105; 104, string:u'[%s%s'; 105, tuple; 105, 106; 105, 107; 106, identifier:value; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:separator; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:end; 113, binary_operator:+; 113, 114; 113, 120; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:end; 117, identifier:encode; 118, argument_list; 118, 119; 119, string:'utf-8'; 120, string:b'\xff'; 121, elif_clause; 121, 122; 121, 125; 122, comparison_operator:==; 122, 123; 122, 124; 123, identifier:filter_type; 124, string:'startswith'; 125, block; 125, 126; 125, 132; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:start; 129, binary_operator:%; 129, 130; 129, 131; 130, string:u'[%s'; 131, identifier:value; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:end; 135, binary_operator:+; 135, 136; 135, 142; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:start; 139, identifier:encode; 140, argument_list; 140, 141; 141, string:'utf-8'; 142, string:b'\xff'; 143, return_statement; 143, 144; 144, expression_list; 144, 145; 144, 146; 144, 147; 145, identifier:start; 146, identifier:end; 147, identifier:exclude
def get_boundaries(self, filter_type, value): assert filter_type in self.handled_suffixes start = '-' end = '+' exclude = None if filter_type in (None, 'eq'): start = u'[%s%s' % (value, self.separator) end = start.encode('utf-8') + b'\xff' elif filter_type == 'gt': start = u'(%s' % value exclude = value elif filter_type == 'gte': start = u'[%s' % value elif filter_type == 'lt': end = u'(%s' % value exclude = value elif filter_type == 'lte': end = u'[%s%s' % (value, self.separator) end = end.encode('utf-8') + b'\xff' elif filter_type == 'startswith': start = u'[%s' % value end = start.encode('utf-8') + b'\xff' return start, end, exclude
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_boundaries; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:filter_type; 6, identifier:value; 7, block; 7, 8; 7, 14; 7, 18; 7, 22; 7, 26; 7, 79; 8, assert_statement; 8, 9; 9, comparison_operator:in; 9, 10; 9, 11; 10, identifier:filter_type; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:handled_suffixes; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:start; 17, string:'-inf'; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:end; 21, string:'+inf'; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:exclude; 25, None; 26, if_statement; 26, 27; 26, 32; 26, 39; 26, 50; 26, 59; 26, 70; 27, comparison_operator:in; 27, 28; 27, 29; 28, identifier:filter_type; 29, tuple; 29, 30; 29, 31; 30, None; 31, string:'eq'; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:start; 36, assignment; 36, 37; 36, 38; 37, identifier:end; 38, identifier:value; 39, elif_clause; 39, 40; 39, 43; 40, comparison_operator:==; 40, 41; 40, 42; 41, identifier:filter_type; 42, string:'gt'; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:start; 47, binary_operator:%; 47, 48; 47, 49; 48, string:'(%s'; 49, identifier:value; 50, elif_clause; 50, 51; 50, 54; 51, comparison_operator:==; 51, 52; 51, 53; 52, identifier:filter_type; 53, string:'gte'; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:start; 58, identifier:value; 59, elif_clause; 59, 60; 59, 63; 60, comparison_operator:==; 60, 61; 60, 62; 61, identifier:filter_type; 62, string:'lt'; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:end; 67, binary_operator:%; 67, 68; 67, 69; 68, string:'(%s'; 69, identifier:value; 70, elif_clause; 70, 71; 70, 74; 71, comparison_operator:==; 71, 72; 71, 73; 72, identifier:filter_type; 73, string:'lte'; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:end; 78, identifier:value; 79, return_statement; 79, 80; 80, expression_list; 80, 81; 80, 82; 80, 83; 81, identifier:start; 82, identifier:end; 83, identifier:exclude
def get_boundaries(self, filter_type, value): assert filter_type in self.handled_suffixes start = '-inf' end = '+inf' exclude = None if filter_type in (None, 'eq'): start = end = value elif filter_type == 'gt': start = '(%s' % value elif filter_type == 'gte': start = value elif filter_type == 'lt': end = '(%s' % value elif filter_type == 'lte': end = value return start, end, exclude
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_combine_sets; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:sets; 6, identifier:final_set; 7, block; 7, 8; 7, 46; 8, if_statement; 8, 9; 8, 12; 8, 30; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:_has_sortedsets; 12, block; 12, 13; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 24; 15, attribute; 15, 16; 15, 23; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:cls; 21, identifier:get_connection; 22, argument_list; 23, identifier:zinterstore; 24, argument_list; 24, 25; 24, 26; 25, identifier:final_set; 26, call; 26, 27; 26, 28; 27, identifier:list; 28, argument_list; 28, 29; 29, identifier:sets; 30, else_clause; 30, 31; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:final_set; 35, call; 35, 36; 35, 43; 36, attribute; 36, 37; 36, 42; 37, call; 37, 38; 37, 39; 38, identifier:super; 39, argument_list; 39, 40; 39, 41; 40, identifier:ExtendedCollectionManager; 41, identifier:self; 42, identifier:_combine_sets; 43, argument_list; 43, 44; 43, 45; 44, identifier:sets; 45, identifier:final_set; 46, return_statement; 46, 47; 47, identifier:final_set
def _combine_sets(self, sets, final_set): if self._has_sortedsets: self.cls.get_connection().zinterstore(final_set, list(sets)) else: final_set = super(ExtendedCollectionManager, self)._combine_sets(sets, final_set) return final_set
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_final_redis_call; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:final_set; 6, identifier:sort_options; 7, block; 7, 8; 7, 18; 7, 37; 7, 84; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:conn; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:cls; 16, identifier:get_connection; 17, argument_list; 18, if_statement; 18, 19; 18, 26; 19, boolean_operator:and; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_has_sortedsets; 23, comparison_operator:is; 23, 24; 23, 25; 24, identifier:sort_options; 25, None; 26, block; 26, 27; 27, return_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:conn; 31, identifier:zrange; 32, argument_list; 32, 33; 32, 34; 32, 35; 33, identifier:final_set; 34, integer:0; 35, unary_operator:-; 35, 36; 36, integer:1; 37, if_statement; 37, 38; 37, 73; 38, boolean_operator:and; 38, 39; 38, 61; 38, 62; 39, boolean_operator:and; 39, 40; 39, 50; 39, 51; 40, boolean_operator:and; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:stored_key; 44, not_operator; 44, 45; 45, subscript; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_lazy_collection; 49, string:'sets'; 50, line_continuation:\; 51, comparison_operator:==; 51, 52; 51, 60; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, subscript; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:_lazy_collection; 59, string:'intersects'; 60, integer:1; 61, line_continuation:\; 62, parenthesized_expression; 62, 63; 63, boolean_operator:or; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:sort_options; 66, None; 67, comparison_operator:==; 67, 68; 67, 69; 68, identifier:sort_options; 69, dictionary; 69, 70; 70, pair; 70, 71; 70, 72; 71, string:'by'; 72, string:'nosort'; 73, block; 73, 74; 74, return_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:conn; 78, identifier:lrange; 79, argument_list; 79, 80; 79, 81; 79, 82; 80, identifier:final_set; 81, integer:0; 82, unary_operator:-; 82, 83; 83, integer:1; 84, return_statement; 84, 85; 85, call; 85, 86; 85, 93; 86, attribute; 86, 87; 86, 92; 87, call; 87, 88; 87, 89; 88, identifier:super; 89, argument_list; 89, 90; 89, 91; 90, identifier:ExtendedCollectionManager; 91, identifier:self; 92, identifier:_final_redis_call; 93, argument_list; 93, 94; 93, 95; 94, identifier:final_set; 95, identifier:sort_options
def _final_redis_call(self, final_set, sort_options): conn = self.cls.get_connection() if self._has_sortedsets and sort_options is None: return conn.zrange(final_set, 0, -1) if self.stored_key and not self._lazy_collection['sets']\ and len(self._lazy_collection['intersects']) == 1\ and (sort_options is None or sort_options == {'by': 'nosort'}): return conn.lrange(final_set, 0, -1) return super(ExtendedCollectionManager, self)._final_redis_call( final_set, sort_options)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_collection_length; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:final_set; 6, block; 6, 7; 6, 17; 6, 60; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:conn; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:cls; 15, identifier:get_connection; 16, argument_list; 17, if_statement; 17, 18; 17, 21; 17, 29; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_has_sortedsets; 21, block; 21, 22; 22, return_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:conn; 26, identifier:zcard; 27, argument_list; 27, 28; 28, identifier:final_set; 29, elif_clause; 29, 30; 29, 52; 30, boolean_operator:and; 30, 31; 30, 41; 30, 42; 31, boolean_operator:and; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:stored_key; 35, not_operator; 35, 36; 36, subscript; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_lazy_collection; 40, string:'sets'; 41, line_continuation:\; 42, comparison_operator:==; 42, 43; 42, 51; 43, call; 43, 44; 43, 45; 44, identifier:len; 45, argument_list; 45, 46; 46, subscript; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_lazy_collection; 50, string:'intersects'; 51, integer:1; 52, block; 52, 53; 53, return_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:conn; 57, identifier:llen; 58, argument_list; 58, 59; 59, identifier:final_set; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 69; 62, attribute; 62, 63; 62, 68; 63, call; 63, 64; 63, 65; 64, identifier:super; 65, argument_list; 65, 66; 65, 67; 66, identifier:ExtendedCollectionManager; 67, identifier:self; 68, identifier:_collection_length; 69, argument_list; 69, 70; 70, identifier:final_set
def _collection_length(self, final_set): conn = self.cls.get_connection() if self._has_sortedsets: return conn.zcard(final_set) elif self.stored_key and not self._lazy_collection['sets']\ and len(self._lazy_collection['intersects']) == 1: return conn.llen(final_set) return super(ExtendedCollectionManager, self)._collection_length(final_set)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_prepare_sort_by_score; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:values; 6, identifier:sort_options; 7, block; 7, 8; 7, 28; 7, 36; 7, 61; 7, 97; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, pattern_list; 10, 11; 10, 12; 11, identifier:base_tmp_key; 12, identifier:tmp_keys; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_zset_to_keys; 17, argument_list; 17, 18; 17, 25; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:key; 20, subscript; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_sort_by_sortedset; 24, string:'by'; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:values; 27, identifier:values; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:sort_options; 32, string:'by'; 33, binary_operator:%; 33, 34; 33, 35; 34, string:'%s:*'; 35, identifier:base_tmp_key; 36, for_statement; 36, 37; 36, 38; 36, 43; 37, identifier:key; 38, tuple; 38, 39; 38, 40; 38, 41; 38, 42; 39, string:'desc'; 40, string:'alpha'; 41, string:'get'; 42, string:'store'; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 50; 45, comparison_operator:in; 45, 46; 45, 47; 46, identifier:key; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_sort_by_sortedset; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:sort_options; 55, identifier:key; 56, subscript; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_sort_by_sortedset; 60, identifier:key; 61, if_statement; 61, 62; 61, 68; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:sort_options; 65, identifier:get; 66, argument_list; 66, 67; 67, string:'get'; 68, block; 68, 69; 69, try_statement; 69, 70; 69, 82; 69, 85; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:pos; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:sort_options; 78, string:'get'; 79, identifier:index; 80, argument_list; 80, 81; 81, identifier:SORTED_SCORE; 82, except_clause; 82, 83; 83, block; 83, 84; 84, pass_statement; 85, else_clause; 85, 86; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 94; 89, subscript; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:sort_options; 92, string:'get'; 93, identifier:pos; 94, binary_operator:%; 94, 95; 94, 96; 95, string:'%s:*'; 96, identifier:base_tmp_key; 97, return_statement; 97, 98; 98, expression_list; 98, 99; 98, 100; 99, identifier:base_tmp_key; 100, identifier:tmp_keys
def _prepare_sort_by_score(self, values, sort_options): base_tmp_key, tmp_keys = self._zset_to_keys( key=self._sort_by_sortedset['by'], values=values, ) sort_options['by'] = '%s:*' % base_tmp_key for key in ('desc', 'alpha', 'get', 'store'): if key in self._sort_by_sortedset: sort_options[key] = self._sort_by_sortedset[key] if sort_options.get('get'): try: pos = sort_options['get'].index(SORTED_SCORE) except: pass else: sort_options['get'][pos] = '%s:*' % base_tmp_key return base_tmp_key, tmp_keys
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_prepare_sort_options; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:has_pk; 6, block; 6, 7; 6, 20; 6, 45; 6, 112; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:sort_options; 10, call; 10, 11; 10, 18; 11, attribute; 11, 12; 11, 17; 12, call; 12, 13; 12, 14; 13, identifier:super; 14, argument_list; 14, 15; 14, 16; 15, identifier:ExtendedCollectionManager; 16, identifier:self; 17, identifier:_prepare_sort_options; 18, argument_list; 18, 19; 19, identifier:has_pk; 20, if_statement; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_values; 24, block; 24, 25; 24, 33; 25, if_statement; 25, 26; 25, 28; 26, not_operator; 26, 27; 27, identifier:sort_options; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:sort_options; 32, dictionary; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:sort_options; 37, string:'get'; 38, subscript; 38, 39; 38, 44; 39, subscript; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_values; 43, string:'fields'; 44, string:'keys'; 45, if_statement; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_sort_by_sortedset_after; 49, block; 49, 50; 49, 69; 49, 104; 50, for_statement; 50, 51; 50, 52; 50, 55; 51, identifier:key; 52, tuple; 52, 53; 52, 54; 53, string:'get'; 54, string:'store'; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 62; 57, comparison_operator:in; 57, 58; 57, 59; 58, identifier:key; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:_sort_by_sortedset; 62, block; 62, 63; 63, delete_statement; 63, 64; 64, subscript; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:_sort_by_sortedset; 68, identifier:key; 69, if_statement; 69, 70; 69, 79; 70, boolean_operator:and; 70, 71; 70, 72; 71, identifier:sort_options; 72, parenthesized_expression; 72, 73; 73, boolean_operator:or; 73, 74; 73, 76; 74, not_operator; 74, 75; 75, identifier:has_pk; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:_want_score_value; 79, block; 79, 80; 80, for_statement; 80, 81; 80, 82; 80, 85; 81, identifier:key; 82, tuple; 82, 83; 82, 84; 83, string:'get'; 84, string:'store'; 85, block; 85, 86; 86, if_statement; 86, 87; 86, 90; 87, comparison_operator:in; 87, 88; 87, 89; 88, identifier:key; 89, identifier:sort_options; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 98; 93, subscript; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:_sort_by_sortedset; 97, identifier:key; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:sort_options; 101, identifier:pop; 102, argument_list; 102, 103; 103, identifier:key; 104, if_statement; 104, 105; 104, 107; 105, not_operator; 105, 106; 106, identifier:sort_options; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:sort_options; 111, None; 112, return_statement; 112, 113; 113, identifier:sort_options
def _prepare_sort_options(self, has_pk): sort_options = super(ExtendedCollectionManager, self)._prepare_sort_options(has_pk) if self._values: if not sort_options: sort_options = {} sort_options['get'] = self._values['fields']['keys'] if self._sort_by_sortedset_after: for key in ('get', 'store'): if key in self._sort_by_sortedset: del self._sort_by_sortedset[key] if sort_options and (not has_pk or self._want_score_value): for key in ('get', 'store'): if key in sort_options: self._sort_by_sortedset[key] = sort_options.pop(key) if not sort_options: sort_options = None return sort_options
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_get_final_set; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:sets; 6, identifier:pk; 7, identifier:sort_options; 8, block; 8, 9; 8, 64; 8, 81; 8, 119; 9, if_statement; 9, 10; 9, 15; 10, subscript; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_lazy_collection; 14, string:'intersects'; 15, block; 15, 16; 15, 24; 15, 35; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:sets; 19, subscript; 19, 20; 19, 21; 20, identifier:sets; 21, slice; 21, 22; 21, 23; 22, colon; 23, colon; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:sets; 28, identifier:extend; 29, argument_list; 29, 30; 30, subscript; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_lazy_collection; 34, string:'intersects'; 35, if_statement; 35, 36; 35, 47; 36, boolean_operator:and; 36, 37; 36, 43; 37, not_operator; 37, 38; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_lazy_collection; 42, string:'sets'; 43, not_operator; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:stored_key; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:sets; 52, identifier:append; 53, argument_list; 53, 54; 54, attribute; 54, 55; 54, 63; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:cls; 60, identifier:get_field; 61, argument_list; 61, 62; 62, string:'pk'; 63, identifier:collection_key; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, pattern_list; 66, 67; 66, 68; 67, identifier:final_set; 68, identifier:keys_to_delete_later; 69, call; 69, 70; 69, 77; 70, attribute; 70, 71; 70, 76; 71, call; 71, 72; 71, 73; 72, identifier:super; 73, argument_list; 73, 74; 73, 75; 74, identifier:ExtendedCollectionManager; 75, identifier:self; 76, identifier:_get_final_set; 77, argument_list; 77, 78; 77, 79; 77, 80; 78, identifier:sets; 79, identifier:pk; 80, identifier:sort_options; 81, if_statement; 81, 82; 81, 87; 82, boolean_operator:and; 82, 83; 82, 84; 83, identifier:final_set; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:_sort_by_sortedset_before; 87, block; 87, 88; 87, 100; 87, 108; 87, 115; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, pattern_list; 90, 91; 90, 92; 91, identifier:base_tmp_key; 92, identifier:tmp_keys; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:_prepare_sort_by_score; 97, argument_list; 97, 98; 97, 99; 98, None; 99, identifier:sort_options; 100, if_statement; 100, 101; 100, 103; 101, not_operator; 101, 102; 102, identifier:keys_to_delete_later; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:keys_to_delete_later; 107, list:[]; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:keys_to_delete_later; 112, identifier:append; 113, argument_list; 113, 114; 114, identifier:base_tmp_key; 115, expression_statement; 115, 116; 116, augmented_assignment:+=; 116, 117; 116, 118; 117, identifier:keys_to_delete_later; 118, identifier:tmp_keys; 119, return_statement; 119, 120; 120, expression_list; 120, 121; 120, 122; 121, identifier:final_set; 122, identifier:keys_to_delete_later
def _get_final_set(self, sets, pk, sort_options): if self._lazy_collection['intersects']: sets = sets[::] sets.extend(self._lazy_collection['intersects']) if not self._lazy_collection['sets'] and not self.stored_key: sets.append(self.cls.get_field('pk').collection_key) final_set, keys_to_delete_later = super(ExtendedCollectionManager, self)._get_final_set(sets, pk, sort_options) if final_set and self._sort_by_sortedset_before: base_tmp_key, tmp_keys = self._prepare_sort_by_score(None, sort_options) if not keys_to_delete_later: keys_to_delete_later = [] keys_to_delete_later.append(base_tmp_key) keys_to_delete_later += tmp_keys return final_set, keys_to_delete_later
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_prepare_sort_options; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:has_pk; 6, block; 6, 7; 6, 11; 6, 30; 6, 89; 6, 103; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:sort_options; 10, dictionary; 11, if_statement; 11, 12; 11, 20; 12, boolean_operator:and; 12, 13; 12, 18; 13, comparison_operator:is; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_sort; 17, None; 18, not_operator; 18, 19; 19, identifier:has_pk; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:sort_options; 25, identifier:update; 26, argument_list; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_sort; 30, if_statement; 30, 31; 30, 36; 31, comparison_operator:is; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_sort_limits; 35, None; 36, block; 36, 37; 36, 80; 37, if_statement; 37, 38; 37, 49; 37, 59; 38, boolean_operator:and; 38, 39; 38, 44; 39, comparison_operator:in; 39, 40; 39, 41; 40, string:'start'; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:_sort_limits; 44, comparison_operator:not; 44, 45; 44, 46; 45, string:'num'; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_sort_limits; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 57; 52, subscript; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_sort_limits; 56, string:'num'; 57, unary_operator:-; 57, 58; 58, integer:1; 59, elif_clause; 59, 60; 59, 71; 60, boolean_operator:and; 60, 61; 60, 66; 61, comparison_operator:in; 61, 62; 61, 63; 62, string:'num'; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:_sort_limits; 66, comparison_operator:not; 66, 67; 66, 68; 67, string:'start'; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_sort_limits; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 79; 74, subscript; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:_sort_limits; 78, string:'start'; 79, integer:0; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:sort_options; 84, identifier:update; 85, argument_list; 85, 86; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:_sort_limits; 89, if_statement; 89, 90; 89, 98; 90, boolean_operator:and; 90, 91; 90, 93; 91, not_operator; 91, 92; 92, identifier:sort_options; 93, comparison_operator:is; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:_sort; 97, None; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:sort_options; 102, None; 103, return_statement; 103, 104; 104, identifier:sort_options
def _prepare_sort_options(self, has_pk): sort_options = {} if self._sort is not None and not has_pk: sort_options.update(self._sort) if self._sort_limits is not None: if 'start' in self._sort_limits and 'num' not in self._sort_limits: self._sort_limits['num'] = -1 elif 'num' in self._sort_limits and 'start' not in self._sort_limits: self._sort_limits['start'] = 0 sort_options.update(self._sort_limits) if not sort_options and self._sort is None: sort_options = None return sort_options
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_final_redis_call; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:final_set; 6, identifier:sort_options; 7, block; 7, 8; 7, 18; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:conn; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:cls; 16, identifier:get_connection; 17, argument_list; 18, if_statement; 18, 19; 18, 22; 18, 32; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:sort_options; 21, None; 22, block; 22, 23; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:conn; 27, identifier:sort; 28, argument_list; 28, 29; 28, 30; 29, identifier:final_set; 30, dictionary_splat; 30, 31; 31, identifier:sort_options; 32, else_clause; 32, 33; 33, block; 33, 34; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:conn; 38, identifier:smembers; 39, argument_list; 39, 40; 40, identifier:final_set
def _final_redis_call(self, final_set, sort_options): conn = self.cls.get_connection() if sort_options is not None: return conn.sort(final_set, **sort_options) else: return conn.smembers(final_set)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:query_mongo_sort_decend; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 20; 3, 23; 4, identifier:database_name; 5, identifier:collection_name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:query; 8, dictionary; 9, default_parameter; 9, 10; 9, 11; 10, identifier:skip; 11, integer:0; 12, default_parameter; 12, 13; 12, 14; 13, identifier:limit; 14, call; 14, 15; 14, 16; 15, identifier:getattr; 16, argument_list; 16, 17; 16, 18; 16, 19; 17, identifier:settings; 18, string:'MONGO_LIMIT'; 19, integer:200; 20, default_parameter; 20, 21; 20, 22; 21, identifier:return_keys; 22, tuple; 23, default_parameter; 23, 24; 23, 25; 24, identifier:sortkey; 25, None; 26, block; 26, 27; 26, 31; 26, 35; 26, 245; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:l; 30, list:[]; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:response_dict; 34, dictionary; 35, try_statement; 35, 36; 35, 189; 36, block; 36, 37; 36, 46; 36, 56; 36, 65; 36, 74; 36, 144; 36, 150; 36, 156; 36, 183; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:mongodb_client_url; 40, call; 40, 41; 40, 42; 41, identifier:getattr; 42, argument_list; 42, 43; 42, 44; 42, 45; 43, identifier:settings; 44, string:'MONGODB_CLIENT'; 45, string:'mongodb://localhost:27017/'; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:mc; 49, call; 49, 50; 49, 51; 50, identifier:MongoClient; 51, argument_list; 51, 52; 51, 53; 52, identifier:mongodb_client_url; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:document_class; 55, identifier:OrderedDict; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:db; 59, subscript; 59, 60; 59, 61; 60, identifier:mc; 61, call; 61, 62; 61, 63; 62, identifier:str; 63, argument_list; 63, 64; 64, identifier:database_name; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:collection; 68, subscript; 68, 69; 68, 70; 69, identifier:db; 70, call; 70, 71; 70, 72; 71, identifier:str; 72, argument_list; 72, 73; 73, identifier:collection_name; 74, if_statement; 74, 75; 74, 76; 74, 117; 75, identifier:return_keys; 76, block; 76, 77; 76, 81; 76, 91; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:return_dict; 80, dictionary; 81, for_statement; 81, 82; 81, 83; 81, 84; 82, identifier:k; 83, identifier:return_keys; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:return_dict; 89, identifier:k; 90, integer:1; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:mysearchresult; 94, call; 94, 95; 94, 114; 95, attribute; 95, 96; 95, 113; 96, call; 96, 97; 96, 111; 97, attribute; 97, 98; 97, 110; 98, call; 98, 99; 98, 108; 99, attribute; 99, 100; 99, 107; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:collection; 103, identifier:find; 104, argument_list; 104, 105; 104, 106; 105, identifier:query; 106, identifier:return_dict; 107, identifier:skip; 108, argument_list; 108, 109; 109, identifier:skip; 110, identifier:limit; 111, argument_list; 111, 112; 112, identifier:limit; 113, identifier:sort; 114, argument_list; 114, 115; 114, 116; 115, identifier:sortkey; 116, identifier:DESCENDING; 117, else_clause; 117, 118; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:mysearchresult; 122, call; 122, 123; 122, 141; 123, attribute; 123, 124; 123, 140; 124, call; 124, 125; 124, 138; 125, attribute; 125, 126; 125, 137; 126, call; 126, 127; 126, 135; 127, attribute; 127, 128; 127, 134; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:collection; 131, identifier:find; 132, argument_list; 132, 133; 133, identifier:query; 134, identifier:skip; 135, argument_list; 135, 136; 136, identifier:skip; 137, identifier:limit; 138, argument_list; 138, 139; 139, identifier:limit; 140, identifier:sort; 141, argument_list; 141, 142; 141, 143; 142, identifier:sortkey; 143, identifier:DESCENDING; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:response_dict; 148, string:'code'; 149, integer:200; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:response_dict; 154, string:'type'; 155, string:"search-results"; 156, for_statement; 156, 157; 156, 158; 156, 159; 157, identifier:d; 158, identifier:mysearchresult; 159, block; 159, 160; 159, 172; 159, 176; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, subscript; 162, 163; 162, 164; 163, identifier:d; 164, string:'id'; 165, call; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:d; 169, string:'_id'; 170, identifier:__str__; 171, argument_list; 172, delete_statement; 172, 173; 173, subscript; 173, 174; 173, 175; 174, identifier:d; 175, string:'_id'; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:l; 180, identifier:append; 181, argument_list; 181, 182; 182, identifier:d; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:response_dict; 187, string:'results'; 188, identifier:l; 189, except_clause; 189, 190; 190, block; 190, 191; 190, 196; 190, 208; 190, 214; 190, 220; 190, 226; 190, 232; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 194; 193, identifier:print; 194, argument_list; 194, 195; 195, string:"Error reading from Mongo"; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 199; 198, identifier:print; 199, argument_list; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:str; 202, argument_list; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:sys; 206, identifier:exc_info; 207, argument_list; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 210, subscript; 210, 211; 210, 212; 211, identifier:response_dict; 212, string:'num_results'; 213, integer:0; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 219; 216, subscript; 216, 217; 216, 218; 217, identifier:response_dict; 218, string:'code'; 219, integer:500; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:response_dict; 224, string:'type'; 225, string:"Error"; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:response_dict; 230, string:'results'; 231, list:[]; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:response_dict; 236, string:'message'; 237, call; 237, 238; 237, 239; 238, identifier:str; 239, argument_list; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:sys; 243, identifier:exc_info; 244, argument_list; 245, return_statement; 245, 246; 246, identifier:response_dict
def query_mongo_sort_decend( database_name, collection_name, query={}, skip=0, limit=getattr( settings, 'MONGO_LIMIT', 200), return_keys=(), sortkey=None): l = [] response_dict = {} try: mongodb_client_url = getattr(settings, 'MONGODB_CLIENT', 'mongodb://localhost:27017/') mc = MongoClient(mongodb_client_url,document_class=OrderedDict) db = mc[str(database_name)] collection = db[str(collection_name)] if return_keys: return_dict = {} for k in return_keys: return_dict[k] = 1 mysearchresult = collection.find( query, return_dict).skip(skip).limit(limit).sort( sortkey, DESCENDING) else: mysearchresult = collection.find(query).skip( skip).limit(limit).sort(sortkey, DESCENDING) response_dict['code'] = 200 response_dict['type'] = "search-results" for d in mysearchresult: d['id'] = d['_id'].__str__() del d['_id'] l.append(d) response_dict['results'] = l except: print("Error reading from Mongo") print(str(sys.exc_info())) response_dict['num_results'] = 0 response_dict['code'] = 500 response_dict['type'] = "Error" response_dict['results'] = [] response_dict['message'] = str(sys.exc_info()) return response_dict
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:build_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 14; 7, 24; 7, 75; 8, expression_statement; 8, 9; 9, string:''' Break url parameters and turn into sort arguments '''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sort; 13, list:[]; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:order; 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:'order_by'; 23, None; 24, if_statement; 24, 25; 24, 26; 25, identifier:order; 26, block; 26, 27; 26, 41; 27, if_statement; 27, 28; 27, 34; 28, comparison_operator:is; 28, 29; 28, 33; 29, call; 29, 30; 29, 31; 30, identifier:type; 31, argument_list; 31, 32; 32, identifier:order; 33, identifier:list; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:order; 38, subscript; 38, 39; 38, 40; 39, identifier:order; 40, integer:0; 41, if_statement; 41, 42; 41, 49; 41, 64; 42, comparison_operator:==; 42, 43; 42, 48; 43, subscript; 43, 44; 43, 45; 44, identifier:order; 45, slice; 45, 46; 45, 47; 46, colon; 47, integer:1; 48, string:'-'; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:sort; 54, identifier:append; 55, argument_list; 55, 56; 56, tuple; 56, 57; 56, 62; 57, subscript; 57, 58; 57, 59; 58, identifier:order; 59, slice; 59, 60; 59, 61; 60, integer:1; 61, colon; 62, unary_operator:-; 62, 63; 63, integer:1; 64, else_clause; 64, 65; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:sort; 70, identifier:append; 71, argument_list; 71, 72; 72, tuple; 72, 73; 72, 74; 73, identifier:order; 74, integer:1; 75, return_statement; 75, 76; 76, identifier:sort
def build_sort(self, **kwargs): ''' Break url parameters and turn into sort arguments ''' sort = [] order = kwargs.get('order_by', None) if order: if type(order) is list: order = order[0] if order[:1] == '-': sort.append((order[1:], -1)) else: sort.append((order, 1)) return sort
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:load_remotes; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:extra_path; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:load_user; 9, True; 10, block; 10, 11; 10, 17; 10, 39; 11, import_from_statement; 11, 12; 11, 15; 12, dotted_name; 12, 13; 12, 14; 13, identifier:os; 14, identifier:path; 15, dotted_name; 15, 16; 16, identifier:getmtime; 17, try_statement; 17, 18; 17, 32; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:remotes_file; 22, call; 22, 23; 22, 24; 23, identifier:find_config_file; 24, argument_list; 24, 25; 24, 26; 24, 29; 25, identifier:REMOTES_FILE; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:extra_path; 28, identifier:extra_path; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:load_user; 31, identifier:load_user; 32, except_clause; 32, 33; 32, 34; 33, identifier:ConfigurationError; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:remotes_file; 38, None; 39, if_statement; 39, 40; 39, 52; 39, 95; 40, boolean_operator:and; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:remotes_file; 43, None; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:os; 48, identifier:path; 49, identifier:exists; 50, argument_list; 50, 51; 51, identifier:remotes_file; 52, block; 52, 53; 52, 59; 52, 66; 52, 80; 52, 93; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:config; 56, call; 56, 57; 56, 58; 57, identifier:AttrDict; 58, argument_list; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:config; 63, identifier:update_yaml; 64, argument_list; 64, 65; 65, identifier:remotes_file; 66, if_statement; 66, 67; 66, 71; 67, not_operator; 67, 68; 68, comparison_operator:in; 68, 69; 68, 70; 69, string:'remotes'; 70, identifier:config; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:config; 76, identifier:remotes; 77, call; 77, 78; 77, 79; 78, identifier:AttrDict; 79, argument_list; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:config; 85, identifier:remotes; 86, identifier:loaded; 87, list:[remotes_file, getmtime(remotes_file)]; 87, 88; 87, 89; 88, identifier:remotes_file; 89, call; 89, 90; 89, 91; 90, identifier:getmtime; 91, argument_list; 91, 92; 92, identifier:remotes_file; 93, return_statement; 93, 94; 94, identifier:config; 95, else_clause; 95, 96; 96, block; 96, 97; 97, return_statement; 97, 98; 98, None
def load_remotes(extra_path=None, load_user=True): from os.path import getmtime try: remotes_file = find_config_file(REMOTES_FILE, extra_path=extra_path, load_user=load_user) except ConfigurationError: remotes_file = None if remotes_file is not None and os.path.exists(remotes_file): config = AttrDict() config.update_yaml(remotes_file) if not 'remotes' in config: config.remotes = AttrDict() config.remotes.loaded = [remotes_file, getmtime(remotes_file)] return config else: return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:find_previous; 3, parameters; 3, 4; 3, 5; 4, identifier:element; 5, identifier:l; 6, block; 6, 7; 6, 14; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:length; 10, call; 10, 11; 10, 12; 11, identifier:len; 12, argument_list; 12, 13; 13, identifier:l; 14, for_statement; 14, 15; 14, 18; 14, 22; 15, pattern_list; 15, 16; 15, 17; 16, identifier:index; 17, identifier:current; 18, call; 18, 19; 18, 20; 19, identifier:enumerate; 20, argument_list; 20, 21; 21, identifier:l; 22, block; 22, 23; 22, 32; 22, 44; 23, if_statement; 23, 24; 23, 29; 24, comparison_operator:==; 24, 25; 24, 28; 25, binary_operator:-; 25, 26; 25, 27; 26, identifier:length; 27, integer:1; 28, identifier:index; 29, block; 29, 30; 30, return_statement; 30, 31; 31, identifier:current; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:==; 33, 34; 33, 35; 34, identifier:index; 35, integer:0; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 41; 38, comparison_operator:<; 38, 39; 38, 40; 39, identifier:element; 40, identifier:current; 41, block; 41, 42; 42, return_statement; 42, 43; 43, None; 44, if_statement; 44, 45; 44, 53; 45, comparison_operator:<=; 45, 46; 45, 47; 45, 48; 46, identifier:current; 47, identifier:element; 48, subscript; 48, 49; 48, 50; 49, identifier:l; 50, binary_operator:+; 50, 51; 50, 52; 51, identifier:index; 52, integer:1; 53, block; 53, 54; 54, return_statement; 54, 55; 55, identifier:current
def find_previous(element, l): length = len(l) for index, current in enumerate(l): if length - 1 == index: return current if index == 0: if element < current: return None if current <= element < l[index+1]: return current
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:tsort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 30; 5, 38; 5, 42; 5, 102; 5, 110; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:task_dict; 9, dictionary; 10, for_statement; 10, 11; 10, 14; 10, 21; 11, pattern_list; 11, 12; 11, 13; 12, identifier:key; 13, identifier:task; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:tasks; 19, identifier:iteritems; 20, argument_list; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, subscript; 24, 25; 24, 26; 25, identifier:task_dict; 26, identifier:task; 27, attribute; 27, 28; 27, 29; 28, identifier:task; 29, identifier:dependencies; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:parts; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:task_dict; 36, identifier:copy; 37, argument_list; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:result; 41, list:[]; 42, while_statement; 42, 43; 42, 44; 43, True; 44, block; 44, 45; 44, 65; 44, 70; 44, 77; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:level; 48, call; 48, 49; 48, 50; 49, identifier:set; 50, argument_list; 50, 51; 51, list_comprehension; 51, 52; 51, 53; 51, 62; 52, identifier:name; 53, for_in_clause; 53, 54; 53, 57; 54, pattern_list; 54, 55; 54, 56; 55, identifier:name; 56, identifier:deps; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:parts; 60, identifier:iteritems; 61, argument_list; 62, if_clause; 62, 63; 63, not_operator; 63, 64; 64, identifier:deps; 65, if_statement; 65, 66; 65, 68; 66, not_operator; 66, 67; 67, identifier:level; 68, block; 68, 69; 69, break_statement; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:result; 74, identifier:append; 75, argument_list; 75, 76; 76, identifier:level; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:parts; 80, call; 80, 81; 80, 82; 81, identifier:dict; 82, argument_list; 82, 83; 83, list_comprehension; 83, 84; 83, 89; 83, 98; 84, tuple; 84, 85; 84, 86; 85, identifier:name; 86, binary_operator:-; 86, 87; 86, 88; 87, identifier:deps; 88, identifier:level; 89, for_in_clause; 89, 90; 89, 93; 90, pattern_list; 90, 91; 90, 92; 91, identifier:name; 92, identifier:deps; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:parts; 96, identifier:iteritems; 97, argument_list; 98, if_clause; 98, 99; 99, comparison_operator:not; 99, 100; 99, 101; 100, identifier:name; 101, identifier:level; 102, if_statement; 102, 103; 102, 104; 103, identifier:parts; 104, block; 104, 105; 105, raise_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:ValueError; 108, argument_list; 108, 109; 109, string:'total ordering not possible (check for circular or missing dependencies)'; 110, return_statement; 110, 111; 111, identifier:result
def tsort(self): task_dict = {} for key, task in self.tasks.iteritems(): task_dict[task] = task.dependencies parts = task_dict.copy() result = [] while True: level = set([name for name, deps in parts.iteritems() if not deps]) if not level: break result.append(level) parts = dict([(name, deps - level) for name, deps in parts.iteritems() if name not in level]) if parts: raise ValueError('total ordering not possible (check for circular or missing dependencies)') return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:getBounds; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:tzinfo; 7, None; 8, block; 8, 9; 8, 49; 9, if_statement; 9, 10; 9, 27; 9, 41; 10, boolean_operator:and; 10, 11; 10, 23; 10, 24; 11, comparison_operator:>=; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:resolution; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:datetime; 18, identifier:timedelta; 19, argument_list; 19, 20; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:days; 22, integer:1; 23, line_continuation:\; 24, comparison_operator:is; 24, 25; 24, 26; 25, identifier:tzinfo; 26, None; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:time; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_time; 36, identifier:replace; 37, argument_list; 37, 38; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:tzinfo; 40, identifier:tzinfo; 41, else_clause; 41, 42; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:time; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_time; 49, return_statement; 49, 50; 50, tuple; 50, 51; 50, 68; 51, call; 51, 52; 51, 53; 52, identifier:min; 53, argument_list; 53, 54; 53, 60; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:fromDatetime; 58, argument_list; 58, 59; 59, identifier:time; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:fromDatetime; 64, argument_list; 64, 65; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:_time; 68, call; 68, 69; 68, 70; 69, identifier:max; 70, argument_list; 70, 71; 70, 81; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:fromDatetime; 75, argument_list; 75, 76; 76, binary_operator:+; 76, 77; 76, 78; 77, identifier:time; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:resolution; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:fromDatetime; 85, argument_list; 85, 86; 86, binary_operator:+; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_time; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:resolution
def getBounds(self, tzinfo=None): if self.resolution >= datetime.timedelta(days=1) \ and tzinfo is not None: time = self._time.replace(tzinfo=tzinfo) else: time = self._time return ( min(self.fromDatetime(time), self.fromDatetime(self._time)), max(self.fromDatetime(time + self.resolution), self.fromDatetime(self._time + self.resolution)) )
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:_get_all_migrations; 3, parameters; 4, block; 4, 5; 4, 10; 4, 14; 4, 22; 4, 26; 4, 72; 4, 87; 5, import_from_statement; 5, 6; 5, 8; 6, relative_import; 6, 7; 7, import_prefix; 8, dotted_name; 8, 9; 9, identifier:migrations; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:package; 13, identifier:migrations; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:prefix; 17, binary_operator:+; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:package; 20, identifier:__name__; 21, string:'.'; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:all_migrations; 25, list:[]; 26, for_statement; 26, 27; 26, 31; 26, 40; 27, pattern_list; 27, 28; 27, 29; 27, 30; 28, identifier:importer; 29, identifier:modname; 30, identifier:ispkg; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:pkgutil; 34, identifier:iter_modules; 35, argument_list; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:package; 38, identifier:__path__; 39, identifier:prefix; 40, block; 40, 41; 40, 63; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:version; 44, call; 44, 45; 44, 46; 45, identifier:int; 46, argument_list; 46, 47; 47, subscript; 47, 48; 47, 62; 48, call; 48, 49; 48, 60; 49, attribute; 49, 50; 49, 59; 50, subscript; 50, 51; 50, 57; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:modname; 54, identifier:split; 55, argument_list; 55, 56; 56, string:'.'; 57, unary_operator:-; 57, 58; 58, integer:1; 59, identifier:split; 60, argument_list; 60, 61; 61, string:'_'; 62, integer:0; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:all_migrations; 67, identifier:append; 68, argument_list; 68, 69; 69, tuple; 69, 70; 69, 71; 70, identifier:version; 71, identifier:modname; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:all_migrations; 75, call; 75, 76; 75, 77; 76, identifier:sorted; 77, argument_list; 77, 78; 77, 79; 78, identifier:all_migrations; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:key; 81, lambda; 81, 82; 81, 84; 82, lambda_parameters; 82, 83; 83, identifier:x; 84, subscript; 84, 85; 84, 86; 85, identifier:x; 86, integer:0; 87, return_statement; 87, 88; 88, identifier:all_migrations
def _get_all_migrations(): from . import migrations package = migrations prefix = package.__name__ + '.' all_migrations = [] for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix): version = int(modname.split('.')[-1].split('_')[0]) all_migrations.append((version, modname)) all_migrations = sorted(all_migrations, key=lambda x: x[0]) return all_migrations
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sort_genes; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:stable; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:inplace; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:ascending; 13, True; 14, block; 14, 15; 14, 19; 14, 26; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:kind; 18, string:'quicksort'; 19, if_statement; 19, 20; 19, 21; 20, identifier:stable; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:kind; 25, string:'mergesort'; 26, return_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:sort_index; 31, argument_list; 31, 32; 31, 35; 31, 38; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:kind; 34, identifier:kind; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:inplace; 37, identifier:inplace; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:ascending; 40, identifier:ascending
def sort_genes(self, stable=True, inplace=False, ascending=True): kind = 'quicksort' if stable: kind = 'mergesort' return self.sort_index(kind=kind, inplace=inplace, ascending=ascending)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sort_samples; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:stable; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:inplace; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:ascending; 13, True; 14, block; 14, 15; 14, 19; 14, 26; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:kind; 18, string:'quicksort'; 19, if_statement; 19, 20; 19, 21; 20, identifier:stable; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:kind; 25, string:'mergesort'; 26, return_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:sort_index; 31, argument_list; 31, 32; 31, 35; 31, 38; 31, 41; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:axis; 34, integer:1; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:kind; 37, identifier:kind; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:inplace; 40, identifier:inplace; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:ascending; 43, identifier:ascending
def sort_samples(self, stable=True, inplace=False, ascending=True): kind = 'quicksort' if stable: kind = 'mergesort' return self.sort_index(axis=1, kind=kind, inplace=inplace, ascending=ascending)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parseColors; 3, parameters; 3, 4; 3, 5; 4, identifier:colors; 5, identifier:defaultColor; 6, block; 6, 7; 6, 11; 6, 140; 6, 155; 6, 177; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:result; 10, list:[]; 11, if_statement; 11, 12; 11, 13; 12, identifier:colors; 13, block; 13, 14; 14, for_statement; 14, 15; 14, 16; 14, 17; 15, identifier:colorInfo; 16, identifier:colors; 17, block; 17, 18; 17, 29; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:fields; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:colorInfo; 24, identifier:split; 25, argument_list; 25, 26; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:maxsplit; 28, integer:1; 29, if_statement; 29, 30; 29, 36; 29, 116; 30, comparison_operator:==; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, identifier:fields; 35, integer:2; 36, block; 36, 37; 36, 43; 36, 78; 36, 107; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 42; 39, pattern_list; 39, 40; 39, 41; 40, identifier:threshold; 41, identifier:color; 42, identifier:fields; 43, try_statement; 43, 44; 43, 52; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:threshold; 48, call; 48, 49; 48, 50; 49, identifier:float; 50, argument_list; 50, 51; 51, identifier:threshold; 52, except_clause; 52, 53; 52, 54; 53, identifier:ValueError; 54, block; 54, 55; 54, 71; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:print; 58, argument_list; 58, 59; 58, 66; 59, binary_operator:%; 59, 60; 59, 65; 60, concatenated_string; 60, 61; 60, 62; 60, 63; 60, 64; 61, string:'--color arguments must be given as space-separated '; 62, string:'pairs of "value color" where the value is a '; 63, string:'numeric identity threshold. Your value %r is not '; 64, string:'numeric.'; 65, identifier:threshold; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:file; 68, attribute; 68, 69; 68, 70; 69, identifier:sys; 70, identifier:stderr; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:sys; 75, identifier:exit; 76, argument_list; 76, 77; 77, integer:1; 78, if_statement; 78, 79; 78, 83; 79, comparison_operator:>; 79, 80; 79, 81; 79, 82; 80, float:0.0; 81, identifier:threshold; 82, float:1.0; 83, block; 83, 84; 83, 100; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:print; 87, argument_list; 87, 88; 87, 95; 88, binary_operator:%; 88, 89; 88, 94; 89, concatenated_string; 89, 90; 89, 91; 89, 92; 89, 93; 90, string:'--color arguments must be given as space-separated '; 91, string:'pairs of "value color" where the value is a '; 92, string:'numeric identity threshold from 0.0 to 1.0. Your '; 93, string:'value %r is not in that range.'; 94, identifier:threshold; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:file; 97, attribute; 97, 98; 97, 99; 98, identifier:sys; 99, identifier:stderr; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:sys; 104, identifier:exit; 105, argument_list; 105, 106; 106, integer:1; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:result; 111, identifier:append; 112, argument_list; 112, 113; 113, tuple; 113, 114; 113, 115; 114, identifier:threshold; 115, identifier:color; 116, else_clause; 116, 117; 117, block; 117, 118; 117, 133; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:print; 121, argument_list; 121, 122; 121, 128; 122, binary_operator:%; 122, 123; 122, 127; 123, concatenated_string; 123, 124; 123, 125; 123, 126; 124, string:'--color arguments must be given as space-separated '; 125, string:'pairs of "value color". You have given %r, which does '; 126, string:'not contain a space.'; 127, identifier:colorInfo; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:file; 130, attribute; 130, 131; 130, 132; 131, identifier:sys; 132, identifier:stderr; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:sys; 137, identifier:exit; 138, argument_list; 138, 139; 139, integer:1; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:result; 144, identifier:sort; 145, argument_list; 145, 146; 145, 152; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:key; 148, call; 148, 149; 148, 150; 149, identifier:itemgetter; 150, argument_list; 150, 151; 151, integer:0; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:reverse; 154, True; 155, if_statement; 155, 156; 155, 167; 156, boolean_operator:or; 156, 157; 156, 159; 157, not_operator; 157, 158; 158, identifier:result; 159, comparison_operator:>; 159, 160; 159, 166; 160, subscript; 160, 161; 160, 165; 161, subscript; 161, 162; 161, 163; 162, identifier:result; 163, unary_operator:-; 163, 164; 164, integer:1; 165, integer:0; 166, float:0.0; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:result; 172, identifier:append; 173, argument_list; 173, 174; 174, tuple; 174, 175; 174, 176; 175, float:0.0; 176, identifier:defaultColor; 177, return_statement; 177, 178; 178, identifier:result
def parseColors(colors, defaultColor): result = [] if colors: for colorInfo in colors: fields = colorInfo.split(maxsplit=1) if len(fields) == 2: threshold, color = fields try: threshold = float(threshold) except ValueError: print('--color arguments must be given as space-separated ' 'pairs of "value color" where the value is a ' 'numeric identity threshold. Your value %r is not ' 'numeric.' % threshold, file=sys.stderr) sys.exit(1) if 0.0 > threshold > 1.0: print('--color arguments must be given as space-separated ' 'pairs of "value color" where the value is a ' 'numeric identity threshold from 0.0 to 1.0. Your ' 'value %r is not in that range.' % threshold, file=sys.stderr) sys.exit(1) result.append((threshold, color)) else: print('--color arguments must be given as space-separated ' 'pairs of "value color". You have given %r, which does ' 'not contain a space.' % colorInfo, file=sys.stderr) sys.exit(1) result.sort(key=itemgetter(0), reverse=True) if not result or result[-1][0] > 0.0: result.append((0.0, defaultColor)) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:bisect_index; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, identifier:x; 6, block; 6, 7; 6, 17; 6, 33; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:i; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:bisect; 13, identifier:bisect_left; 14, argument_list; 14, 15; 14, 16; 15, identifier:a; 16, identifier:x; 17, if_statement; 17, 18; 17, 30; 18, boolean_operator:and; 18, 19; 18, 25; 19, comparison_operator:!=; 19, 20; 19, 21; 20, identifier:i; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:a; 25, comparison_operator:==; 25, 26; 25, 29; 26, subscript; 26, 27; 26, 28; 27, identifier:a; 28, identifier:i; 29, identifier:x; 30, block; 30, 31; 31, return_statement; 31, 32; 32, identifier:i; 33, raise_statement; 33, 34; 34, identifier:ValueError
def bisect_index(a, x): i = bisect.bisect_left(a, x) if i != len(a) and a[i] == x: return i raise ValueError
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:writeSampleIndex; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:fp; 6, block; 6, 7; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:print; 10, argument_list; 10, 11; 10, 42; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, string:'\n'; 14, identifier:join; 15, generator_expression; 15, 16; 15, 21; 16, binary_operator:%; 16, 17; 16, 18; 17, string:'%d %s'; 18, tuple; 18, 19; 18, 20; 19, identifier:index; 20, identifier:name; 21, for_in_clause; 21, 22; 21, 25; 22, tuple_pattern; 22, 23; 22, 24; 23, identifier:index; 24, identifier:name; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, generator_expression; 27, 28; 27, 31; 28, tuple; 28, 29; 28, 30; 29, identifier:index; 30, identifier:name; 31, for_in_clause; 31, 32; 31, 35; 32, tuple_pattern; 32, 33; 32, 34; 33, identifier:name; 34, identifier:index; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_samples; 40, identifier:items; 41, argument_list; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:file; 44, identifier:fp
def writeSampleIndex(self, fp): print('\n'.join( '%d %s' % (index, name) for (index, name) in sorted((index, name) for (name, index) in self._samples.items()) ), file=fp)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:writePathogenIndex; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:fp; 6, block; 6, 7; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:print; 10, argument_list; 10, 11; 10, 42; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, string:'\n'; 14, identifier:join; 15, generator_expression; 15, 16; 15, 21; 16, binary_operator:%; 16, 17; 16, 18; 17, string:'%d %s'; 18, tuple; 18, 19; 18, 20; 19, identifier:index; 20, identifier:name; 21, for_in_clause; 21, 22; 21, 25; 22, tuple_pattern; 22, 23; 22, 24; 23, identifier:index; 24, identifier:name; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, generator_expression; 27, 28; 27, 31; 28, tuple; 28, 29; 28, 30; 29, identifier:index; 30, identifier:name; 31, for_in_clause; 31, 32; 31, 35; 32, tuple_pattern; 32, 33; 32, 34; 33, identifier:name; 34, identifier:index; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_pathogens; 40, identifier:items; 41, argument_list; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:file; 44, identifier:fp
def writePathogenIndex(self, fp): print('\n'.join( '%d %s' % (index, name) for (index, name) in sorted((index, name) for (name, index) in self._pathogens.items()) ), file=fp)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_transform_chrom; 3, parameters; 3, 4; 4, identifier:chrom; 5, block; 5, 6; 6, try_statement; 6, 7; 6, 15; 6, 39; 7, block; 7, 8; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:c; 11, call; 11, 12; 11, 13; 12, identifier:int; 13, argument_list; 13, 14; 14, identifier:chrom; 15, except_clause; 15, 16; 16, block; 16, 17; 17, if_statement; 17, 18; 17, 23; 17, 26; 17, 33; 18, comparison_operator:in; 18, 19; 18, 20; 19, identifier:chrom; 20, list:['X', 'Y']; 20, 21; 20, 22; 21, string:'X'; 22, string:'Y'; 23, block; 23, 24; 24, return_statement; 24, 25; 25, identifier:chrom; 26, elif_clause; 26, 27; 26, 30; 27, comparison_operator:==; 27, 28; 27, 29; 28, identifier:chrom; 29, string:'MT'; 30, block; 30, 31; 31, return_statement; 31, 32; 32, string:'_MT'; 33, else_clause; 33, 34; 34, block; 34, 35; 35, return_statement; 35, 36; 36, binary_operator:+; 36, 37; 36, 38; 37, string:'__'; 38, identifier:chrom; 39, else_clause; 39, 40; 40, block; 40, 41; 41, return_statement; 41, 42; 42, binary_operator:%; 42, 43; 42, 44; 43, string:'%02d'; 44, identifier:c
def _transform_chrom(chrom): try: c = int(chrom) except: if chrom in ['X', 'Y']: return chrom elif chrom == 'MT': return '_MT' else: return '__' + chrom else: return '%02d' % c
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_show; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 23; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, call; 9, 10; 9, 11; 10, identifier:_runshell; 11, argument_list; 11, 12; 11, 18; 12, list:[brctlexe, 'show', self.name]; 12, 13; 12, 14; 12, 15; 13, identifier:brctlexe; 14, string:'show'; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:name; 18, binary_operator:%; 18, 19; 18, 20; 19, string:"Could not show %s."; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:name; 23, return_statement; 23, 24; 24, subscript; 24, 25; 24, 36; 25, call; 25, 26; 25, 35; 26, attribute; 26, 27; 26, 34; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:p; 31, identifier:stdout; 32, identifier:read; 33, argument_list; 34, identifier:split; 35, argument_list; 36, slice; 36, 37; 36, 38; 37, integer:7; 38, colon
def _show(self): p = _runshell([brctlexe, 'show', self.name], "Could not show %s." % self.name) return p.stdout.read().split()[7:]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_assembly; 3, parameters; 3, 4; 4, identifier:name; 5, block; 5, 6; 5, 23; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:fn; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:pkg_resources; 12, identifier:resource_filename; 13, argument_list; 13, 14; 13, 15; 14, identifier:__name__; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:_assy_path_fmt; 18, identifier:format; 19, argument_list; 19, 20; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:name; 22, identifier:name; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:json; 27, identifier:load; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:gzip; 32, identifier:open; 33, argument_list; 33, 34; 33, 35; 33, 38; 34, identifier:fn; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:mode; 37, string:"rt"; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:encoding; 40, string:"utf-8"
def get_assembly(name): fn = pkg_resources.resource_filename( __name__, _assy_path_fmt.format(name=name)) return json.load(gzip.open(fn, mode="rt", encoding="utf-8"))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:coverageInfo; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 13; 5, 59; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:result; 9, call; 9, 10; 9, 11; 10, identifier:defaultdict; 11, argument_list; 11, 12; 12, identifier:list; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:titleAlignment; 15, identifier:self; 16, block; 16, 17; 17, for_statement; 17, 18; 17, 19; 17, 22; 18, identifier:hsp; 19, attribute; 19, 20; 19, 21; 20, identifier:titleAlignment; 21, identifier:hsps; 22, block; 22, 23; 22, 31; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:score; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:hsp; 29, identifier:score; 30, identifier:score; 31, for_statement; 31, 32; 31, 36; 31, 47; 32, tuple_pattern; 32, 33; 32, 34; 32, 35; 33, identifier:subjectOffset; 34, identifier:base; 35, identifier:_; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:titleAlignment; 40, identifier:read; 41, identifier:walkHSP; 42, argument_list; 42, 43; 42, 44; 43, identifier:hsp; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:includeWhiskers; 46, False; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:result; 53, identifier:subjectOffset; 54, identifier:append; 55, argument_list; 55, 56; 56, tuple; 56, 57; 56, 58; 57, identifier:score; 58, identifier:base; 59, return_statement; 59, 60; 60, identifier:result
def coverageInfo(self): result = defaultdict(list) for titleAlignment in self: for hsp in titleAlignment.hsps: score = hsp.score.score for (subjectOffset, base, _) in titleAlignment.read.walkHSP( hsp, includeWhiskers=False): result[subjectOffset].append((score, base)) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:filter; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:minMatchingReads; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:minMedianScore; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:withScoreBetterThan; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:minNewReads; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:minCoverage; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:maxTitles; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:sortOn; 25, string:'maxScore'; 26, block; 26, 27; 26, 60; 26, 78; 26, 123; 26, 238; 27, if_statement; 27, 28; 27, 31; 27, 36; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:minNewReads; 30, None; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:readSetFilter; 35, None; 36, else_clause; 36, 37; 37, block; 37, 38; 37, 54; 38, if_statement; 38, 39; 38, 44; 39, comparison_operator:is; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:readSetFilter; 43, None; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:readSetFilter; 50, call; 50, 51; 50, 52; 51, identifier:ReadSetFilter; 52, argument_list; 52, 53; 53, identifier:minNewReads; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:readSetFilter; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:readSetFilter; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:result; 63, call; 63, 64; 63, 65; 64, identifier:TitlesAlignments; 65, argument_list; 65, 66; 65, 69; 65, 72; 65, 75; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:readsAlignments; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:scoreClass; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:readSetFilter; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:importReadsAlignmentsTitles; 77, False; 78, if_statement; 78, 79; 78, 89; 78, 113; 79, boolean_operator:and; 79, 80; 79, 83; 80, comparison_operator:is; 80, 81; 80, 82; 81, identifier:maxTitles; 82, None; 83, comparison_operator:>; 83, 84; 83, 88; 84, call; 84, 85; 84, 86; 85, identifier:len; 86, argument_list; 86, 87; 87, identifier:self; 88, identifier:maxTitles; 89, block; 89, 90; 90, if_statement; 90, 91; 90, 94; 90, 102; 91, comparison_operator:<; 91, 92; 91, 93; 92, identifier:maxTitles; 93, integer:0; 94, block; 94, 95; 95, raise_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:ValueError; 98, argument_list; 98, 99; 99, binary_operator:%; 99, 100; 99, 101; 100, string:'maxTitles (%r) cannot be negative.'; 101, identifier:maxTitles; 102, else_clause; 102, 103; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:titles; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:sortTitles; 111, argument_list; 111, 112; 112, identifier:sortOn; 113, else_clause; 113, 114; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:titles; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:keys; 122, argument_list; 123, for_statement; 123, 124; 123, 125; 123, 126; 124, identifier:title; 125, identifier:titles; 126, block; 126, 127; 126, 140; 126, 146; 126, 161; 126, 186; 126, 201; 126, 216; 126, 230; 127, if_statement; 127, 128; 127, 138; 128, boolean_operator:and; 128, 129; 128, 132; 129, comparison_operator:is; 129, 130; 129, 131; 130, identifier:maxTitles; 131, None; 132, comparison_operator:==; 132, 133; 132, 137; 133, call; 133, 134; 133, 135; 134, identifier:len; 135, argument_list; 135, 136; 136, identifier:result; 137, identifier:maxTitles; 138, block; 138, 139; 139, break_statement; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:titleAlignments; 143, subscript; 143, 144; 143, 145; 144, identifier:self; 145, identifier:title; 146, if_statement; 146, 147; 146, 159; 147, parenthesized_expression; 147, 148; 148, boolean_operator:and; 148, 149; 148, 152; 149, comparison_operator:is; 149, 150; 149, 151; 150, identifier:minMatchingReads; 151, None; 152, comparison_operator:<; 152, 153; 152, 158; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:titleAlignments; 156, identifier:readCount; 157, argument_list; 158, identifier:minMatchingReads; 159, block; 159, 160; 160, continue_statement; 161, if_statement; 161, 162; 161, 184; 162, parenthesized_expression; 162, 163; 163, boolean_operator:and; 163, 164; 163, 167; 164, comparison_operator:is; 164, 165; 164, 166; 165, identifier:minMedianScore; 166, None; 167, comparison_operator:<; 167, 168; 167, 178; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:scoreClass; 172, argument_list; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:titleAlignments; 176, identifier:medianScore; 177, argument_list; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:scoreClass; 182, argument_list; 182, 183; 183, identifier:minMedianScore; 184, block; 184, 185; 185, continue_statement; 186, if_statement; 186, 187; 186, 199; 187, parenthesized_expression; 187, 188; 188, boolean_operator:and; 188, 189; 188, 192; 189, comparison_operator:is; 189, 190; 189, 191; 190, identifier:withScoreBetterThan; 191, None; 192, not_operator; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:titleAlignments; 196, identifier:hasScoreBetterThan; 197, argument_list; 197, 198; 198, identifier:withScoreBetterThan; 199, block; 199, 200; 200, continue_statement; 201, if_statement; 201, 202; 201, 214; 202, parenthesized_expression; 202, 203; 203, boolean_operator:and; 203, 204; 203, 207; 204, comparison_operator:is; 204, 205; 204, 206; 205, identifier:minCoverage; 206, None; 207, comparison_operator:<; 207, 208; 207, 213; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:titleAlignments; 211, identifier:coverage; 212, argument_list; 213, identifier:minCoverage; 214, block; 214, 215; 215, continue_statement; 216, if_statement; 216, 217; 216, 228; 217, parenthesized_expression; 217, 218; 218, boolean_operator:and; 218, 219; 218, 220; 219, identifier:readSetFilter; 220, not_operator; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:readSetFilter; 224, identifier:accept; 225, argument_list; 225, 226; 225, 227; 226, identifier:title; 227, identifier:titleAlignments; 228, block; 228, 229; 229, continue_statement; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:result; 234, identifier:addTitle; 235, argument_list; 235, 236; 235, 237; 236, identifier:title; 237, identifier:titleAlignments; 238, return_statement; 238, 239; 239, identifier:result
def filter(self, minMatchingReads=None, minMedianScore=None, withScoreBetterThan=None, minNewReads=None, minCoverage=None, maxTitles=None, sortOn='maxScore'): if minNewReads is None: readSetFilter = None else: if self.readSetFilter is None: self.readSetFilter = ReadSetFilter(minNewReads) readSetFilter = self.readSetFilter result = TitlesAlignments( self.readsAlignments, self.scoreClass, self.readSetFilter, importReadsAlignmentsTitles=False) if maxTitles is not None and len(self) > maxTitles: if maxTitles < 0: raise ValueError('maxTitles (%r) cannot be negative.' % maxTitles) else: titles = self.sortTitles(sortOn) else: titles = self.keys() for title in titles: if maxTitles is not None and len(result) == maxTitles: break titleAlignments = self[title] if (minMatchingReads is not None and titleAlignments.readCount() < minMatchingReads): continue if (minMedianScore is not None and self.scoreClass(titleAlignments.medianScore()) < self.scoreClass(minMedianScore)): continue if (withScoreBetterThan is not None and not titleAlignments.hasScoreBetterThan(withScoreBetterThan)): continue if (minCoverage is not None and titleAlignments.coverage() < minCoverage): continue if (readSetFilter and not readSetFilter.accept(title, titleAlignments)): continue result.addTitle(title, titleAlignments) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sortTitles; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:by; 6, block; 6, 7; 6, 17; 6, 40; 6, 65; 6, 95; 6, 120; 6, 127; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:titles; 10, call; 10, 11; 10, 12; 11, identifier:sorted; 12, argument_list; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:iter; 15, argument_list; 15, 16; 16, identifier:self; 17, if_statement; 17, 18; 17, 21; 18, comparison_operator:==; 18, 19; 18, 20; 19, identifier:by; 20, string:'length'; 21, block; 21, 22; 22, return_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:sorted; 25, argument_list; 25, 26; 25, 27; 25, 30; 26, identifier:titles; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:reverse; 29, True; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:key; 32, lambda; 32, 33; 32, 35; 33, lambda_parameters; 33, 34; 34, identifier:title; 35, attribute; 35, 36; 35, 39; 36, subscript; 36, 37; 36, 38; 37, identifier:self; 38, identifier:title; 39, identifier:subjectLength; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:==; 41, 42; 41, 43; 42, identifier:by; 43, string:'maxScore'; 44, block; 44, 45; 45, return_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:sorted; 48, argument_list; 48, 49; 48, 50; 48, 53; 49, identifier:titles; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:reverse; 52, True; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:key; 55, lambda; 55, 56; 55, 58; 56, lambda_parameters; 56, 57; 57, identifier:title; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, subscript; 60, 61; 60, 62; 61, identifier:self; 62, identifier:title; 63, identifier:bestHsp; 64, argument_list; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:==; 66, 67; 66, 68; 67, identifier:by; 68, string:'medianScore'; 69, block; 69, 70; 70, return_statement; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:sorted; 73, argument_list; 73, 74; 73, 75; 73, 78; 74, identifier:titles; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:reverse; 77, True; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:key; 80, lambda; 80, 81; 80, 83; 81, lambda_parameters; 81, 82; 82, identifier:title; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:scoreClass; 87, argument_list; 87, 88; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:self; 92, identifier:title; 93, identifier:medianScore; 94, argument_list; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:==; 96, 97; 96, 98; 97, identifier:by; 98, string:'readCount'; 99, block; 99, 100; 100, return_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:sorted; 103, argument_list; 103, 104; 103, 105; 103, 108; 104, identifier:titles; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:reverse; 107, True; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:key; 110, lambda; 110, 111; 110, 113; 111, lambda_parameters; 111, 112; 112, identifier:title; 113, call; 113, 114; 113, 119; 114, attribute; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:self; 117, identifier:title; 118, identifier:readCount; 119, argument_list; 120, if_statement; 120, 121; 120, 124; 121, comparison_operator:==; 121, 122; 121, 123; 122, identifier:by; 123, string:'title'; 124, block; 124, 125; 125, return_statement; 125, 126; 126, identifier:titles; 127, raise_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:ValueError; 130, argument_list; 130, 131; 131, concatenated_string; 131, 132; 131, 133; 132, string:'Sort attribute must be one of "length", "maxScore", '; 133, string:'"medianScore", "readCount", "title".'
def sortTitles(self, by): titles = sorted(iter(self)) if by == 'length': return sorted( titles, reverse=True, key=lambda title: self[title].subjectLength) if by == 'maxScore': return sorted( titles, reverse=True, key=lambda title: self[title].bestHsp()) if by == 'medianScore': return sorted( titles, reverse=True, key=lambda title: self.scoreClass(self[title].medianScore())) if by == 'readCount': return sorted( titles, reverse=True, key=lambda title: self[title].readCount()) if by == 'title': return titles raise ValueError('Sort attribute must be one of "length", "maxScore", ' '"medianScore", "readCount", "title".')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:summary; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sortOn; 7, None; 8, block; 8, 9; 8, 23; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:titles; 12, conditional_expression:if; 12, 13; 12, 14; 12, 17; 13, identifier:self; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:sortOn; 16, None; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:sortTitles; 21, argument_list; 21, 22; 22, identifier:sortOn; 23, for_statement; 23, 24; 23, 25; 23, 26; 24, identifier:title; 25, identifier:titles; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, yield; 28, 29; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:self; 33, identifier:title; 34, identifier:summary; 35, argument_list
def summary(self, sortOn=None): titles = self if sortOn is None else self.sortTitles(sortOn) for title in titles: yield self[title].summary()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:tabSeparatedSummary; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sortOn; 7, None; 8, block; 8, 9; 8, 13; 8, 43; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:result; 12, list:[]; 13, for_statement; 13, 14; 13, 15; 13, 21; 14, identifier:titleSummary; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:summary; 19, argument_list; 19, 20; 20, identifier:sortOn; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:result; 26, identifier:append; 27, argument_list; 27, 28; 28, binary_operator:%; 28, 29; 28, 42; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, string:'\t'; 32, identifier:join; 33, argument_list; 33, 34; 34, list:[ '%(coverage)f', '%(medianScore)f', '%(bestScore)f', '%(readCount)d', '%(hspCount)d', '%(subjectLength)d', '%(subjectTitle)s', ]; 34, 35; 34, 36; 34, 37; 34, 38; 34, 39; 34, 40; 34, 41; 35, string:'%(coverage)f'; 36, string:'%(medianScore)f'; 37, string:'%(bestScore)f'; 38, string:'%(readCount)d'; 39, string:'%(hspCount)d'; 40, string:'%(subjectLength)d'; 41, string:'%(subjectTitle)s'; 42, identifier:titleSummary; 43, return_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, string:'\n'; 47, identifier:join; 48, argument_list; 48, 49; 49, identifier:result
def tabSeparatedSummary(self, sortOn=None): result = [] for titleSummary in self.summary(sortOn): result.append('\t'.join([ '%(coverage)f', '%(medianScore)f', '%(bestScore)f', '%(readCount)d', '%(hspCount)d', '%(subjectLength)d', '%(subjectTitle)s', ]) % titleSummary) return '\n'.join(result)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:infer_namespaces; 3, parameters; 3, 4; 4, identifier:ac; 5, block; 5, 6; 6, return_statement; 6, 7; 7, list_comprehension; 7, 8; 7, 9; 7, 18; 8, identifier:v; 9, for_in_clause; 9, 10; 9, 13; 10, pattern_list; 10, 11; 10, 12; 11, identifier:k; 12, identifier:v; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:ac_namespace_regexps; 16, identifier:items; 17, argument_list; 18, if_clause; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:k; 22, identifier:match; 23, argument_list; 23, 24; 24, identifier:ac
def infer_namespaces(ac): return [v for k, v in ac_namespace_regexps.items() if k.match(ac)]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:to_digraph; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 18; 9, 171; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:digraph; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:_nx; 16, identifier:DiGraph; 17, argument_list; 18, for_statement; 18, 19; 18, 20; 18, 23; 19, identifier:equation; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:equations; 23, block; 23, 24; 23, 45; 23, 73; 23, 82; 23, 110; 23, 119; 23, 146; 23, 156; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 30; 26, pattern_list; 26, 27; 26, 28; 26, 29; 27, identifier:reactants; 28, identifier:arrow; 29, identifier:products; 30, list_comprehension; 30, 31; 30, 36; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:value; 34, identifier:strip; 35, argument_list; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:value; 38, call; 38, 39; 38, 40; 39, identifier:_split_arrows; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:str; 43, argument_list; 43, 44; 44, identifier:equation; 45, try_statement; 45, 46; 45, 64; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:attr; 50, call; 50, 51; 50, 63; 51, attribute; 51, 52; 51, 62; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:equation; 55, identifier:to_series; 56, argument_list; 56, 57; 56, 58; 56, 60; 57, string:"reactants"; 58, list_splat; 58, 59; 59, identifier:args; 60, dictionary_splat; 60, 61; 61, identifier:kwargs; 62, identifier:to_dict; 63, argument_list; 64, except_clause; 64, 65; 64, 66; 65, identifier:ValueError; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:attr; 70, call; 70, 71; 70, 72; 71, identifier:dict; 72, argument_list; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:digraph; 77, identifier:add_node; 78, argument_list; 78, 79; 78, 80; 79, identifier:reactants; 80, dictionary_splat; 80, 81; 81, identifier:attr; 82, try_statement; 82, 83; 82, 101; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:attr; 87, call; 87, 88; 87, 100; 88, attribute; 88, 89; 88, 99; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:equation; 92, identifier:to_series; 93, argument_list; 93, 94; 93, 95; 93, 97; 94, string:"products"; 95, list_splat; 95, 96; 96, identifier:args; 97, dictionary_splat; 97, 98; 98, identifier:kwargs; 99, identifier:to_dict; 100, argument_list; 101, except_clause; 101, 102; 101, 103; 102, identifier:ValueError; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:attr; 107, call; 107, 108; 107, 109; 108, identifier:dict; 109, argument_list; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:digraph; 114, identifier:add_node; 115, argument_list; 115, 116; 115, 117; 116, identifier:products; 117, dictionary_splat; 117, 118; 118, identifier:attr; 119, try_statement; 119, 120; 119, 137; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:attr; 124, call; 124, 125; 124, 136; 125, attribute; 125, 126; 125, 135; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:equation; 129, identifier:to_series; 130, argument_list; 130, 131; 130, 133; 131, list_splat; 131, 132; 132, identifier:args; 133, dictionary_splat; 133, 134; 134, identifier:kwargs; 135, identifier:to_dict; 136, argument_list; 137, except_clause; 137, 138; 137, 139; 138, identifier:ValueError; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:attr; 143, call; 143, 144; 143, 145; 144, identifier:dict; 145, argument_list; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:digraph; 150, identifier:add_edge; 151, argument_list; 151, 152; 151, 153; 151, 154; 152, identifier:reactants; 153, identifier:products; 154, dictionary_splat; 154, 155; 155, identifier:attr; 156, if_statement; 156, 157; 156, 160; 157, comparison_operator:==; 157, 158; 157, 159; 158, identifier:arrow; 159, string:'<=>'; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:digraph; 165, identifier:add_edge; 166, argument_list; 166, 167; 166, 168; 166, 169; 167, identifier:products; 168, identifier:reactants; 169, dictionary_splat; 169, 170; 170, identifier:attr; 171, return_statement; 171, 172; 172, identifier:digraph
def to_digraph(self, *args, **kwargs): digraph = _nx.DiGraph() for equation in self.equations: reactants, arrow, products = [value.strip() for value in _split_arrows(str(equation))] try: attr = equation.to_series("reactants", *args, **kwargs).to_dict() except ValueError: attr = dict() digraph.add_node(reactants, **attr) try: attr = equation.to_series("products", *args, **kwargs).to_dict() except ValueError: attr = dict() digraph.add_node(products, **attr) try: attr = equation.to_series(*args, **kwargs).to_dict() except ValueError: attr = dict() digraph.add_edge(reactants, products, **attr) if arrow == '<=>': digraph.add_edge(products, reactants, **attr) return digraph
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:get_streams; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:game; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:channels; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:limit; 13, integer:25; 14, default_parameter; 14, 15; 14, 16; 15, identifier:offset; 16, integer:0; 17, block; 17, 18; 17, 33; 17, 37; 17, 41; 17, 79; 17, 95; 17, 108; 18, if_statement; 18, 19; 18, 26; 19, call; 19, 20; 19, 21; 20, identifier:isinstance; 21, argument_list; 21, 22; 21, 23; 22, identifier:game; 23, attribute; 23, 24; 23, 25; 24, identifier:models; 25, identifier:Game; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:game; 30, attribute; 30, 31; 30, 32; 31, identifier:game; 32, identifier:name; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:channelnames; 36, list:[]; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:cparam; 40, None; 41, if_statement; 41, 42; 41, 43; 42, identifier:channels; 43, block; 43, 44; 43, 70; 44, for_statement; 44, 45; 44, 46; 44, 47; 45, identifier:c; 46, identifier:channels; 47, block; 47, 48; 47, 63; 48, if_statement; 48, 49; 48, 56; 49, call; 49, 50; 49, 51; 50, identifier:isinstance; 51, argument_list; 51, 52; 51, 53; 52, identifier:c; 53, attribute; 53, 54; 53, 55; 54, identifier:models; 55, identifier:Channel; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:c; 60, attribute; 60, 61; 60, 62; 61, identifier:c; 62, identifier:name; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:channelnames; 67, identifier:append; 68, argument_list; 68, 69; 69, identifier:c; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:cparam; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, string:','; 76, identifier:join; 77, argument_list; 77, 78; 78, identifier:channelnames; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:params; 82, dictionary; 82, 83; 82, 86; 82, 89; 82, 92; 83, pair; 83, 84; 83, 85; 84, string:'limit'; 85, identifier:limit; 86, pair; 86, 87; 86, 88; 87, string:'offset'; 88, identifier:offset; 89, pair; 89, 90; 89, 91; 90, string:'game'; 91, identifier:game; 92, pair; 92, 93; 92, 94; 93, string:'channel'; 94, identifier:cparam; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:r; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:kraken_request; 102, argument_list; 102, 103; 102, 104; 102, 105; 103, string:'GET'; 104, string:'streams'; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:params; 107, identifier:params; 108, return_statement; 108, 109; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:models; 113, identifier:Stream; 114, identifier:wrap_search; 115, argument_list; 115, 116; 116, identifier:r
def get_streams(self, game=None, channels=None, limit=25, offset=0): if isinstance(game, models.Game): game = game.name channelnames = [] cparam = None if channels: for c in channels: if isinstance(c, models.Channel): c = c.name channelnames.append(c) cparam = ','.join(channelnames) params = {'limit': limit, 'offset': offset, 'game': game, 'channel': cparam} r = self.kraken_request('GET', 'streams', params=params) return models.Stream.wrap_search(r)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_queryset; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:queryset; 5, identifier:request; 6, default_parameter; 6, 7; 6, 8; 7, identifier:context; 8, None; 9, block; 9, 10; 9, 21; 9, 139; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sort_by; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:request; 17, identifier:GET; 18, identifier:get; 19, argument_list; 19, 20; 20, string:'sort_by'; 21, if_statement; 21, 22; 21, 23; 22, identifier:sort_by; 23, block; 23, 24; 24, if_statement; 24, 25; 24, 40; 24, 50; 25, comparison_operator:in; 25, 26; 25, 27; 26, identifier:sort_by; 27, list_comprehension; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:el; 30, identifier:name; 31, for_in_clause; 31, 32; 31, 33; 32, identifier:el; 33, attribute; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:queryset; 37, identifier:model; 38, identifier:_meta; 39, identifier:fields; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:queryset; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:queryset; 47, identifier:order_by; 48, argument_list; 48, 49; 49, identifier:sort_by; 50, else_clause; 50, 51; 51, block; 51, 52; 52, if_statement; 52, 53; 52, 58; 52, 81; 53, comparison_operator:in; 53, 54; 53, 55; 54, identifier:sort_by; 55, attribute; 55, 56; 55, 57; 56, identifier:request; 57, identifier:session; 58, block; 58, 59; 58, 67; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:sort_by; 62, subscript; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:request; 65, identifier:session; 66, identifier:sort_by; 67, try_statement; 67, 68; 67, 78; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:queryset; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:queryset; 75, identifier:order_by; 76, argument_list; 76, 77; 77, identifier:sort_by; 78, except_clause; 78, 79; 79, block; 79, 80; 80, raise_statement; 81, elif_clause; 81, 82; 81, 85; 82, comparison_operator:is; 82, 83; 82, 84; 83, identifier:context; 84, None; 85, block; 85, 86; 85, 130; 86, if_statement; 86, 87; 86, 92; 86, 108; 87, comparison_operator:!=; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:sort_by; 90, integer:0; 91, string:'-'; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:sort_by; 96, subscript; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:context; 100, string:'cl'; 101, identifier:list_display; 102, binary_operator:-; 102, 103; 102, 107; 103, call; 103, 104; 103, 105; 104, identifier:int; 105, argument_list; 105, 106; 106, identifier:sort_by; 107, integer:1; 108, else_clause; 108, 109; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:sort_by; 113, binary_operator:+; 113, 114; 113, 115; 114, string:'-'; 115, subscript; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:context; 119, string:'cl'; 120, identifier:list_display; 121, binary_operator:-; 121, 122; 121, 129; 122, call; 122, 123; 122, 124; 123, identifier:abs; 124, argument_list; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:int; 127, argument_list; 127, 128; 128, identifier:sort_by; 129, integer:1; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:queryset; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:queryset; 136, identifier:order_by; 137, argument_list; 137, 138; 138, identifier:sort_by; 139, return_statement; 139, 140; 140, identifier:queryset
def sort_queryset(queryset, request, context=None): sort_by = request.GET.get('sort_by') if sort_by: if sort_by in [el.name for el in queryset.model._meta.fields]: queryset = queryset.order_by(sort_by) else: if sort_by in request.session: sort_by = request.session[sort_by] try: queryset = queryset.order_by(sort_by) except: raise elif context is not None: if sort_by[0] != '-': sort_by = context['cl'].list_display[int(sort_by) - 1] else: sort_by = '-' + context['cl'].list_display[abs(int(sort_by)) - 1] queryset = queryset.order_by(sort_by) return queryset
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:percentile; 3, parameters; 3, 4; 3, 5; 4, identifier:data; 5, identifier:n; 6, block; 6, 7; 6, 14; 6, 25; 6, 45; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:size; 10, call; 10, 11; 10, 12; 11, identifier:len; 12, argument_list; 12, 13; 13, identifier:data; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:idx; 17, binary_operator:-; 17, 18; 17, 24; 18, binary_operator:*; 18, 19; 18, 23; 19, parenthesized_expression; 19, 20; 20, binary_operator:/; 20, 21; 20, 22; 21, identifier:n; 22, float:100.0; 23, identifier:size; 24, float:0.5; 25, if_statement; 25, 26; 25, 33; 26, boolean_operator:or; 26, 27; 26, 30; 27, comparison_operator:<; 27, 28; 27, 29; 28, identifier:idx; 29, integer:0; 30, comparison_operator:>; 30, 31; 30, 32; 31, identifier:idx; 32, identifier:size; 33, block; 33, 34; 34, raise_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:StatisticsError; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, string:"Too few data points ({}) for {}th percentile"; 41, identifier:format; 42, argument_list; 42, 43; 42, 44; 43, identifier:size; 44, identifier:n; 45, return_statement; 45, 46; 46, subscript; 46, 47; 46, 48; 47, identifier:data; 48, call; 48, 49; 48, 50; 49, identifier:int; 50, argument_list; 50, 51; 51, identifier:idx
def percentile(data, n): size = len(data) idx = (n / 100.0) * size - 0.5 if idx < 0 or idx > size: raise StatisticsError("Too few data points ({}) for {}th percentile".format(size, n)) return data[int(idx)]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_histogram; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 13; 5, 28; 5, 34; 5, 41; 5, 48; 5, 58; 5, 68; 5, 88; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:count; 9, call; 9, 10; 9, 11; 10, identifier:len; 11, argument_list; 11, 12; 12, identifier:data; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:<; 14, 15; 14, 16; 15, identifier:count; 16, integer:2; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:StatisticsError; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, string:'Too few data points ({}) for get_histogram'; 25, identifier:format; 26, argument_list; 26, 27; 27, identifier:count; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:min_; 31, subscript; 31, 32; 31, 33; 32, identifier:data; 33, integer:0; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:max_; 37, subscript; 37, 38; 37, 39; 38, identifier:data; 39, unary_operator:-; 39, 40; 40, integer:1; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:std; 44, call; 44, 45; 44, 46; 45, identifier:stdev; 46, argument_list; 46, 47; 47, identifier:data; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:bins; 51, call; 51, 52; 51, 53; 52, identifier:get_histogram_bins; 53, argument_list; 53, 54; 53, 55; 53, 56; 53, 57; 54, identifier:min_; 55, identifier:max_; 56, identifier:std; 57, identifier:count; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:res; 61, dictionary_comprehension; 61, 62; 61, 65; 62, pair; 62, 63; 62, 64; 63, identifier:x; 64, integer:0; 65, for_in_clause; 65, 66; 65, 67; 66, identifier:x; 67, identifier:bins; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:value; 70, identifier:data; 71, block; 71, 72; 72, for_statement; 72, 73; 72, 74; 72, 75; 73, identifier:bin_; 74, identifier:bins; 75, block; 75, 76; 76, if_statement; 76, 77; 76, 80; 77, comparison_operator:<=; 77, 78; 77, 79; 78, identifier:value; 79, identifier:bin_; 80, block; 80, 81; 80, 87; 81, expression_statement; 81, 82; 82, augmented_assignment:+=; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:res; 85, identifier:bin_; 86, integer:1; 87, break_statement; 88, return_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:sorted; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:iteritems; 94, argument_list; 94, 95; 95, identifier:res
def get_histogram(data): count = len(data) if count < 2: raise StatisticsError('Too few data points ({}) for get_histogram'.format(count)) min_ = data[0] max_ = data[-1] std = stdev(data) bins = get_histogram_bins(min_, max_, std, count) res = {x: 0 for x in bins} for value in data: for bin_ in bins: if value <= bin_: res[bin_] += 1 break return sorted(iteritems(res))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:make_geohash_tables; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:table; 5, identifier:listofprecisions; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 15; 8, 19; 8, 47; 8, 56; 8, 64; 8, 68; 8, 88; 8, 98; 8, 124; 8, 283; 9, expression_statement; 9, 10; 10, string:''' sort_by - field to sort by for each group return_squares - boolean arg if true returns a list of squares instead of writing out to table '''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:return_squares; 14, False; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:sort_by; 18, string:'COUNT'; 19, for_statement; 19, 20; 19, 23; 19, 28; 20, pattern_list; 20, 21; 20, 22; 21, identifier:key; 22, identifier:value; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:kwargs; 26, identifier:iteritems; 27, argument_list; 28, block; 28, 29; 28, 38; 29, if_statement; 29, 30; 29, 33; 30, comparison_operator:==; 30, 31; 30, 32; 31, identifier:key; 32, string:'sort_by'; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:sort_by; 37, identifier:value; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:==; 39, 40; 39, 41; 40, identifier:key; 41, string:'return_squares'; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:return_squares; 46, identifier:value; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:header; 50, subscript; 50, 51; 50, 55; 51, call; 51, 52; 51, 53; 52, identifier:df2list; 53, argument_list; 53, 54; 54, identifier:table; 55, integer:0; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:columns; 59, subscript; 59, 60; 59, 61; 60, identifier:header; 61, slice; 61, 62; 61, 63; 62, integer:10; 63, colon; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:originaltable; 67, identifier:table; 68, if_statement; 68, 69; 68, 73; 69, not_operator; 69, 70; 70, comparison_operator:==; 70, 71; 70, 72; 71, identifier:sort_by; 72, string:'COUNT'; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:originaltable; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:originaltable; 80, identifier:sort; 81, argument_list; 81, 82; 81, 84; 82, list:[sort_by]; 82, 83; 83, identifier:sort_by; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:ascending; 86, list:[0]; 86, 87; 87, integer:0; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:listofprecisions; 91, call; 91, 92; 91, 93; 92, identifier:sorted; 93, argument_list; 93, 94; 93, 95; 94, identifier:listofprecisions; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:reverse; 97, True; 98, if_statement; 98, 99; 98, 109; 98, 115; 99, boolean_operator:and; 99, 100; 99, 103; 100, comparison_operator:==; 100, 101; 100, 102; 101, identifier:return_squares; 102, True; 103, comparison_operator:==; 103, 104; 103, 108; 104, subscript; 104, 105; 104, 106; 105, identifier:listofprecisions; 106, unary_operator:-; 106, 107; 107, integer:1; 108, integer:8; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:total_list; 113, list:[table]; 113, 114; 114, identifier:table; 115, elif_clause; 115, 116; 115, 119; 116, comparison_operator:==; 116, 117; 116, 118; 117, identifier:return_squares; 118, True; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:total_list; 123, list:[]; 124, for_statement; 124, 125; 124, 126; 124, 127; 125, identifier:row; 126, identifier:listofprecisions; 127, block; 127, 128; 127, 135; 127, 139; 127, 153; 127, 176; 127, 190; 127, 198; 127, 203; 127, 245; 127, 252; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:precision; 131, call; 131, 132; 131, 133; 132, identifier:int; 133, argument_list; 133, 134; 134, identifier:row; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:table; 138, identifier:originaltable; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:table; 143, string:'GEOHASH'; 144, subscript; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:table; 148, identifier:GEOHASH; 149, identifier:str; 150, slice; 150, 151; 150, 152; 151, colon; 152, identifier:precision; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:table; 156, call; 156, 157; 156, 175; 157, attribute; 157, 158; 157, 174; 158, call; 158, 159; 158, 168; 159, attribute; 159, 160; 159, 167; 160, subscript; 160, 161; 160, 162; 161, identifier:table; 162, binary_operator:+; 162, 163; 162, 166; 163, list:['GEOHASH','COUNT']; 163, 164; 163, 165; 164, string:'GEOHASH'; 165, string:'COUNT'; 166, identifier:columns; 167, identifier:groupby; 168, argument_list; 168, 169; 168, 171; 169, list:['GEOHASH']; 169, 170; 170, string:'GEOHASH'; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:sort; 173, True; 174, identifier:sum; 175, argument_list; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:table; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:table; 182, identifier:sort; 183, argument_list; 183, 184; 183, 186; 184, list:[sort_by]; 184, 185; 185, identifier:sort_by; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:ascending; 188, list:[0]; 188, 189; 189, integer:0; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:table; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:table; 196, identifier:reset_index; 197, argument_list; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:newsquares; 201, list:[header]; 201, 202; 202, identifier:header; 203, for_statement; 203, 204; 203, 205; 203, 213; 204, identifier:row; 205, subscript; 205, 206; 205, 210; 206, call; 206, 207; 206, 208; 207, identifier:df2list; 208, argument_list; 208, 209; 209, identifier:table; 210, slice; 210, 211; 210, 212; 211, integer:1; 212, colon; 213, block; 213, 214; 213, 223; 213, 238; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:points; 217, call; 217, 218; 217, 219; 218, identifier:get_points_geohash; 219, argument_list; 219, 220; 220, subscript; 220, 221; 220, 222; 221, identifier:row; 222, integer:0; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:newrow; 226, binary_operator:+; 226, 227; 226, 233; 227, binary_operator:+; 227, 228; 227, 232; 228, list:[row[0]]; 228, 229; 229, subscript; 229, 230; 229, 231; 230, identifier:row; 231, integer:0; 232, identifier:points; 233, subscript; 233, 234; 233, 235; 234, identifier:row; 235, slice; 235, 236; 235, 237; 236, integer:1; 237, colon; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:newsquares; 242, identifier:append; 243, argument_list; 243, 244; 244, identifier:newrow; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:table; 248, call; 248, 249; 248, 250; 249, identifier:list2df; 250, argument_list; 250, 251; 251, identifier:newsquares; 252, if_statement; 252, 253; 252, 256; 252, 264; 253, comparison_operator:==; 253, 254; 253, 255; 254, identifier:return_squares; 255, True; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:total_list; 261, identifier:append; 262, argument_list; 262, 263; 263, identifier:table; 264, else_clause; 264, 265; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:table; 270, identifier:to_csv; 271, argument_list; 271, 272; 271, 280; 272, binary_operator:+; 272, 273; 272, 279; 273, binary_operator:+; 273, 274; 273, 275; 274, string:'squares'; 275, call; 275, 276; 275, 277; 276, identifier:str; 277, argument_list; 277, 278; 278, identifier:precision; 279, string:'.csv'; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:index; 282, False; 283, if_statement; 283, 284; 283, 287; 283, 290; 284, comparison_operator:==; 284, 285; 284, 286; 285, identifier:return_squares; 286, True; 287, block; 287, 288; 288, return_statement; 288, 289; 289, identifier:total_list; 290, else_clause; 290, 291; 291, block; 291, 292; 292, print_statement; 292, 293; 293, string:'Wrote output squares tables to csv files.'
def make_geohash_tables(table,listofprecisions,**kwargs): ''' sort_by - field to sort by for each group return_squares - boolean arg if true returns a list of squares instead of writing out to table ''' return_squares = False sort_by = 'COUNT' for key,value in kwargs.iteritems(): if key == 'sort_by': sort_by = value if key == 'return_squares': return_squares = value header = df2list(table)[0] columns = header[10:] originaltable = table if not sort_by == 'COUNT': originaltable = originaltable.sort([sort_by],ascending=[0]) listofprecisions = sorted(listofprecisions,reverse=True) if return_squares == True and listofprecisions[-1] == 8: total_list = [table] elif return_squares == True: total_list = [] for row in listofprecisions: precision = int(row) table = originaltable table['GEOHASH'] = table.GEOHASH.str[:precision] table = table[['GEOHASH','COUNT']+columns].groupby(['GEOHASH'],sort=True).sum() table = table.sort([sort_by],ascending=[0]) table = table.reset_index() newsquares = [header] for row in df2list(table)[1:]: points = get_points_geohash(row[0]) newrow = [row[0]] + points + row[1:] newsquares.append(newrow) table = list2df(newsquares) if return_squares == True: total_list.append(table) else: table.to_csv('squares' + str(precision) + '.csv',index=False) if return_squares == True: return total_list else: print 'Wrote output squares tables to csv files.'
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:coercer; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:dataSets; 6, block; 6, 7; 6, 36; 6, 50; 6, 64; 6, 73; 6, 230; 6, 237; 7, function_definition; 7, 8; 7, 9; 7, 12; 8, function_name:makeSetter; 9, parameters; 9, 10; 9, 11; 10, identifier:identifier; 11, identifier:values; 12, block; 12, 13; 12, 34; 13, function_definition; 13, 14; 13, 15; 13, 17; 14, function_name:setter; 15, parameters; 15, 16; 16, identifier:defaultObject; 17, block; 17, 18; 17, 26; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 25; 20, subscript; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_idsToObjects; 24, identifier:identifier; 25, identifier:defaultObject; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 33; 28, subscript; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:_lastValues; 32, identifier:identifier; 33, identifier:values; 34, return_statement; 34, 35; 35, identifier:setter; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:created; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_coerceAll; 43, argument_list; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:_extractCreations; 48, argument_list; 48, 49; 49, identifier:dataSets; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:edited; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_coerceAll; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:_extractEdits; 62, argument_list; 62, 63; 63, identifier:dataSets; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:coerceDeferred; 67, call; 67, 68; 67, 69; 68, identifier:gatherResults; 69, argument_list; 69, 70; 70, list:[created, edited]; 70, 71; 70, 72; 71, identifier:created; 72, identifier:edited; 73, function_definition; 73, 74; 73, 75; 73, 79; 74, function_name:cbCoerced; 75, parameters; 75, 76; 76, tuple_pattern; 76, 77; 76, 78; 77, identifier:created; 78, identifier:edited; 79, block; 79, 80; 79, 86; 79, 90; 79, 118; 79, 122; 79, 176; 79, 180; 79, 223; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:receivedIdentifiers; 83, call; 83, 84; 83, 85; 84, identifier:set; 85, argument_list; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:createObjects; 89, list:[]; 90, for_statement; 90, 91; 90, 94; 90, 95; 91, tuple_pattern; 91, 92; 91, 93; 92, identifier:identifier; 93, identifier:dataSet; 94, identifier:created; 95, block; 95, 96; 95, 103; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:receivedIdentifiers; 100, identifier:add; 101, argument_list; 101, 102; 102, identifier:identifier; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:createObjects; 107, identifier:append; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:CreateObject; 111, argument_list; 111, 112; 111, 113; 112, identifier:dataSet; 113, call; 113, 114; 113, 115; 114, identifier:makeSetter; 115, argument_list; 115, 116; 115, 117; 116, identifier:identifier; 117, identifier:dataSet; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:editObjects; 121, list:[]; 122, for_statement; 122, 123; 122, 126; 122, 127; 123, tuple_pattern; 123, 124; 123, 125; 124, identifier:identifier; 125, identifier:dataSet; 126, identifier:edited; 127, block; 127, 128; 127, 135; 127, 143; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:receivedIdentifiers; 132, identifier:add; 133, argument_list; 133, 134; 134, identifier:identifier; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:lastValues; 138, subscript; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:_lastValues; 142, identifier:identifier; 143, if_statement; 143, 144; 143, 147; 144, comparison_operator:!=; 144, 145; 144, 146; 145, identifier:dataSet; 146, identifier:lastValues; 147, block; 147, 148; 147, 157; 147, 168; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:modelObject; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:_objectFromID; 155, argument_list; 155, 156; 156, identifier:identifier; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:editObjects; 161, identifier:append; 162, argument_list; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:EditObject; 165, argument_list; 165, 166; 165, 167; 166, identifier:modelObject; 167, identifier:dataSet; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 175; 170, subscript; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:_lastValues; 174, identifier:identifier; 175, identifier:dataSet; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:deleted; 179, list:[]; 180, for_statement; 180, 181; 180, 182; 180, 190; 181, identifier:identifier; 182, binary_operator:-; 182, 183; 182, 189; 183, call; 183, 184; 183, 185; 184, identifier:set; 185, argument_list; 185, 186; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:_idsToObjects; 189, identifier:receivedIdentifiers; 190, block; 190, 191; 190, 200; 190, 214; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:existing; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:_objectFromID; 198, argument_list; 198, 199; 199, identifier:identifier; 200, if_statement; 200, 201; 200, 206; 201, comparison_operator:is; 201, 202; 201, 203; 202, identifier:existing; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:_NO_OBJECT_MARKER; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:deleted; 211, identifier:append; 212, argument_list; 212, 213; 213, identifier:existing; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 221; 216, attribute; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:self; 219, identifier:_idsToObjects; 220, identifier:pop; 221, argument_list; 221, 222; 222, identifier:identifier; 223, return_statement; 223, 224; 224, call; 224, 225; 224, 226; 225, identifier:ListChanges; 226, argument_list; 226, 227; 226, 228; 226, 229; 227, identifier:createObjects; 228, identifier:editObjects; 229, identifier:deleted; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:coerceDeferred; 234, identifier:addCallback; 235, argument_list; 235, 236; 236, identifier:cbCoerced; 237, return_statement; 237, 238; 238, identifier:coerceDeferred
def coercer(self, dataSets): def makeSetter(identifier, values): def setter(defaultObject): self._idsToObjects[identifier] = defaultObject self._lastValues[identifier] = values return setter created = self._coerceAll(self._extractCreations(dataSets)) edited = self._coerceAll(self._extractEdits(dataSets)) coerceDeferred = gatherResults([created, edited]) def cbCoerced((created, edited)): receivedIdentifiers = set() createObjects = [] for (identifier, dataSet) in created: receivedIdentifiers.add(identifier) createObjects.append( CreateObject(dataSet, makeSetter(identifier, dataSet))) editObjects = [] for (identifier, dataSet) in edited: receivedIdentifiers.add(identifier) lastValues = self._lastValues[identifier] if dataSet != lastValues: modelObject = self._objectFromID(identifier) editObjects.append(EditObject(modelObject, dataSet)) self._lastValues[identifier] = dataSet deleted = [] for identifier in set(self._idsToObjects) - receivedIdentifiers: existing = self._objectFromID(identifier) if existing is not self._NO_OBJECT_MARKER: deleted.append(existing) self._idsToObjects.pop(identifier) return ListChanges(createObjects, editObjects, deleted) coerceDeferred.addCallback(cbCoerced) return coerceDeferred
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:zcard; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:name; 6, block; 6, 7; 7, with_statement; 7, 8; 7, 16; 8, with_clause; 8, 9; 9, with_item; 9, 10; 10, as_pattern; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:pipe; 14, as_pattern_target; 14, 15; 15, identifier:pipe; 16, block; 16, 17; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:pipe; 21, identifier:zcard; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:redis_key; 27, argument_list; 27, 28; 28, identifier:name
def zcard(self, name): with self.pipe as pipe: return pipe.zcard(self.redis_key(name))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:zscore; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, identifier:value; 7, block; 7, 8; 8, with_statement; 8, 9; 8, 17; 9, with_clause; 9, 10; 10, with_item; 10, 11; 11, as_pattern; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:pipe; 15, as_pattern_target; 15, 16; 16, identifier:pipe; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:pipe; 22, identifier:zscore; 23, argument_list; 23, 24; 23, 30; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:redis_key; 28, argument_list; 28, 29; 29, identifier:name; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:valueparse; 35, identifier:encode; 36, argument_list; 36, 37; 37, identifier:value
def zscore(self, name, value): with self.pipe as pipe: return pipe.zscore(self.redis_key(name), self.valueparse.encode(value))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:zrank; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, identifier:value; 7, block; 7, 8; 8, with_statement; 8, 9; 8, 17; 9, with_clause; 9, 10; 10, with_item; 10, 11; 11, as_pattern; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:pipe; 15, as_pattern_target; 15, 16; 16, identifier:pipe; 17, block; 17, 18; 17, 29; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:value; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:valueparse; 26, identifier:encode; 27, argument_list; 27, 28; 28, identifier:value; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:pipe; 33, identifier:zrank; 34, argument_list; 34, 35; 34, 41; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:redis_key; 39, argument_list; 39, 40; 40, identifier:name; 41, identifier:value
def zrank(self, name, value): with self.pipe as pipe: value = self.valueparse.encode(value) return pipe.zrank(self.redis_key(name), value)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:zlexcount; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:min; 7, identifier:max; 8, block; 8, 9; 9, with_statement; 9, 10; 9, 18; 10, with_clause; 10, 11; 11, with_item; 11, 12; 12, as_pattern; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:pipe; 16, as_pattern_target; 16, 17; 17, identifier:pipe; 18, block; 18, 19; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:pipe; 23, identifier:zlexcount; 24, argument_list; 24, 25; 24, 31; 24, 32; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:redis_key; 29, argument_list; 29, 30; 30, identifier:name; 31, identifier:min; 32, identifier:max
def zlexcount(self, name, min, max): with self.pipe as pipe: return pipe.zlexcount(self.redis_key(name), min, max)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:zrevrangebylex; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:self; 5, identifier:name; 6, identifier:max; 7, identifier:min; 8, default_parameter; 8, 9; 8, 10; 9, identifier:start; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:num; 13, None; 14, block; 14, 15; 15, with_statement; 15, 16; 15, 24; 16, with_clause; 16, 17; 17, with_item; 17, 18; 18, as_pattern; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:pipe; 22, as_pattern_target; 22, 23; 23, identifier:pipe; 24, block; 24, 25; 24, 31; 24, 53; 24, 75; 24, 82; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:f; 28, call; 28, 29; 28, 30; 29, identifier:Future; 30, argument_list; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:res; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:pipe; 37, identifier:zrevrangebylex; 38, argument_list; 38, 39; 38, 45; 38, 46; 38, 47; 38, 50; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:redis_key; 43, argument_list; 43, 44; 44, identifier:name; 45, identifier:max; 46, identifier:min; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:start; 49, identifier:start; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:num; 52, identifier:num; 53, function_definition; 53, 54; 53, 55; 53, 56; 54, function_name:cb; 55, parameters; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:f; 61, identifier:set; 62, argument_list; 62, 63; 63, list_comprehension; 63, 64; 63, 72; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:valueparse; 69, identifier:decode; 70, argument_list; 70, 71; 71, identifier:v; 72, for_in_clause; 72, 73; 72, 74; 73, identifier:v; 74, identifier:res; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:pipe; 79, identifier:on_execute; 80, argument_list; 80, 81; 81, identifier:cb; 82, return_statement; 82, 83; 83, identifier:f
def zrevrangebylex(self, name, max, min, start=None, num=None): with self.pipe as pipe: f = Future() res = pipe.zrevrangebylex(self.redis_key(name), max, min, start=start, num=num) def cb(): f.set([self.valueparse.decode(v) for v in res]) pipe.on_execute(cb) return f
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:zremrangebylex; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:min; 7, identifier:max; 8, block; 8, 9; 9, with_statement; 9, 10; 9, 18; 10, with_clause; 10, 11; 11, with_item; 11, 12; 12, as_pattern; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:pipe; 16, as_pattern_target; 16, 17; 17, identifier:pipe; 18, block; 18, 19; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:pipe; 23, identifier:zremrangebylex; 24, argument_list; 24, 25; 24, 31; 24, 32; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:redis_key; 29, argument_list; 29, 30; 30, identifier:name; 31, identifier:min; 32, identifier:max
def zremrangebylex(self, name, min, max): with self.pipe as pipe: return pipe.zremrangebylex(self.redis_key(name), min, max)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:resort; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:attributeID; 6, default_parameter; 6, 7; 6, 8; 7, identifier:isAscending; 8, None; 9, block; 9, 10; 9, 21; 9, 29; 9, 46; 9, 83; 9, 89; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:isAscending; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:isAscending; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:defaultSortAscending; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:newSortColumn; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:columns; 28, identifier:attributeID; 29, if_statement; 29, 30; 29, 37; 30, comparison_operator:is; 30, 31; 30, 36; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:newSortColumn; 34, identifier:sortAttribute; 35, argument_list; 36, None; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:Unsortable; 41, argument_list; 41, 42; 42, binary_operator:%; 42, 43; 42, 44; 43, string:'column %r has no sort attribute'; 44, tuple; 44, 45; 45, identifier:attributeID; 46, if_statement; 46, 47; 46, 52; 46, 71; 47, comparison_operator:==; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:currentSortColumn; 51, identifier:newSortColumn; 52, block; 52, 53; 53, if_statement; 53, 54; 53, 59; 53, 64; 54, comparison_operator:==; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:isAscending; 58, identifier:isAscending; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:offset; 63, integer:0; 64, else_clause; 64, 65; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:offset; 69, unary_operator:-; 69, 70; 70, integer:1; 71, else_clause; 71, 72; 72, block; 72, 73; 72, 77; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:offset; 76, integer:0; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:currentSortColumn; 82, identifier:newSortColumn; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:isAscending; 88, identifier:isAscending; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:_updateResults; 94, argument_list; 94, 95; 94, 101; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_sortAttributeValue; 99, argument_list; 99, 100; 100, identifier:offset; 101, True
def resort(self, attributeID, isAscending=None): if isAscending is None: isAscending = self.defaultSortAscending newSortColumn = self.columns[attributeID] if newSortColumn.sortAttribute() is None: raise Unsortable('column %r has no sort attribute' % (attributeID,)) if self.currentSortColumn == newSortColumn: if self.isAscending == isAscending: offset = 0 else: offset = -1 else: offset = 0 self.currentSortColumn = newSortColumn self.isAscending = isAscending self._updateResults(self._sortAttributeValue(offset), True)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_sortAttributeValue; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:offset; 6, block; 6, 7; 6, 42; 7, if_statement; 7, 8; 7, 11; 7, 36; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_currentResults; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:pageStart; 15, tuple; 15, 16; 15, 27; 16, subscript; 16, 17; 16, 22; 17, subscript; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_currentResults; 21, identifier:offset; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:currentSortColumn; 26, identifier:attributeID; 27, attribute; 27, 28; 27, 35; 28, subscript; 28, 29; 28, 34; 29, subscript; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_currentResults; 33, identifier:offset; 34, string:'__item__'; 35, identifier:storeID; 36, else_clause; 36, 37; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:pageStart; 41, None; 42, return_statement; 42, 43; 43, identifier:pageStart
def _sortAttributeValue(self, offset): if self._currentResults: pageStart = (self._currentResults[offset][ self.currentSortColumn.attributeID], self._currentResults[offset][ '__item__'].storeID) else: pageStart = None return pageStart
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:resort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:columnName; 6, block; 6, 7; 6, 13; 6, 21; 6, 34; 6, 62; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:csc; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:currentSortColumn; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:newSortColumn; 16, subscript; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:columns; 20, identifier:columnName; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:newSortColumn; 24, None; 25, block; 25, 26; 26, raise_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:Unsortable; 29, argument_list; 29, 30; 30, binary_operator:%; 30, 31; 30, 32; 31, string:'column %r has no sort attribute'; 32, tuple; 32, 33; 33, identifier:columnName; 34, if_statement; 34, 35; 34, 38; 34, 48; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:csc; 37, identifier:newSortColumn; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:isAscending; 44, not_operator; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:isAscending; 48, else_clause; 48, 49; 49, block; 49, 50; 49, 56; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:currentSortColumn; 55, identifier:newSortColumn; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:isAscending; 61, True; 62, return_statement; 62, 63; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:isAscending
def resort(self, columnName): csc = self.currentSortColumn newSortColumn = self.columns[columnName] if newSortColumn is None: raise Unsortable('column %r has no sort attribute' % (columnName,)) if csc is newSortColumn: self.isAscending = not self.isAscending else: self.currentSortColumn = newSortColumn self.isAscending = True return self.isAscending
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:rowsAfterValue; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:value; 6, identifier:count; 7, block; 7, 8; 7, 58; 8, if_statement; 8, 9; 8, 12; 8, 24; 9, comparison_operator:is; 9, 10; 9, 11; 10, identifier:value; 11, None; 12, block; 12, 13; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:query; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:inequalityQuery; 20, argument_list; 20, 21; 20, 22; 20, 23; 21, None; 22, identifier:count; 23, True; 24, else_clause; 24, 25; 25, block; 25, 26; 25, 35; 25, 45; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:pyvalue; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_toComparableValue; 33, argument_list; 33, 34; 34, identifier:value; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:currentSortAttribute; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:currentSortColumn; 43, identifier:sortAttribute; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:query; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:inequalityQuery; 52, argument_list; 52, 53; 52, 56; 52, 57; 53, comparison_operator:>=; 53, 54; 53, 55; 54, identifier:currentSortAttribute; 55, identifier:pyvalue; 56, identifier:count; 57, True; 58, return_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:constructRows; 63, argument_list; 63, 64; 64, identifier:query
def rowsAfterValue(self, value, count): if value is None: query = self.inequalityQuery(None, count, True) else: pyvalue = self._toComparableValue(value) currentSortAttribute = self.currentSortColumn.sortAttribute() query = self.inequalityQuery(currentSortAttribute >= pyvalue, count, True) return self.constructRows(query)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:rowsBeforeValue; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:value; 6, identifier:count; 7, block; 7, 8; 7, 58; 8, if_statement; 8, 9; 8, 12; 8, 24; 9, comparison_operator:is; 9, 10; 9, 11; 10, identifier:value; 11, None; 12, block; 12, 13; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:query; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:inequalityQuery; 20, argument_list; 20, 21; 20, 22; 20, 23; 21, None; 22, identifier:count; 23, False; 24, else_clause; 24, 25; 25, block; 25, 26; 25, 35; 25, 45; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:pyvalue; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_toComparableValue; 33, argument_list; 33, 34; 34, identifier:value; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:currentSortAttribute; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:currentSortColumn; 43, identifier:sortAttribute; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:query; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:inequalityQuery; 52, argument_list; 52, 53; 52, 56; 52, 57; 53, comparison_operator:<; 53, 54; 53, 55; 54, identifier:currentSortAttribute; 55, identifier:pyvalue; 56, identifier:count; 57, False; 58, return_statement; 58, 59; 59, subscript; 59, 60; 59, 66; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:constructRows; 64, argument_list; 64, 65; 65, identifier:query; 66, slice; 66, 67; 66, 68; 66, 69; 67, colon; 68, colon; 69, unary_operator:-; 69, 70; 70, integer:1
def rowsBeforeValue(self, value, count): if value is None: query = self.inequalityQuery(None, count, False) else: pyvalue = self._toComparableValue(value) currentSortAttribute = self.currentSortColumn.sortAttribute() query = self.inequalityQuery( currentSortAttribute < pyvalue, count, False) return self.constructRows(query)[::-1]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:rowsBeforeItem; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:item; 6, identifier:count; 7, block; 7, 8; 7, 18; 7, 31; 7, 56; 7, 65; 7, 72; 7, 100; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:currentSortAttribute; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:currentSortColumn; 16, identifier:sortAttribute; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:value; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:currentSortAttribute; 24, identifier:__get__; 25, argument_list; 25, 26; 25, 27; 26, identifier:item; 27, call; 27, 28; 27, 29; 28, identifier:type; 29, argument_list; 29, 30; 30, identifier:item; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:firstQuery; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:inequalityQuery; 38, argument_list; 38, 39; 38, 54; 38, 55; 39, call; 39, 40; 39, 41; 40, identifier:AND; 41, argument_list; 41, 42; 41, 45; 42, comparison_operator:==; 42, 43; 42, 44; 43, identifier:currentSortAttribute; 44, identifier:value; 45, comparison_operator:<; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:itemType; 50, identifier:storeID; 51, attribute; 51, 52; 51, 53; 52, identifier:item; 53, identifier:storeID; 54, identifier:count; 55, False; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:results; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:constructRows; 63, argument_list; 63, 64; 64, identifier:firstQuery; 65, expression_statement; 65, 66; 66, augmented_assignment:-=; 66, 67; 66, 68; 67, identifier:count; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:results; 72, if_statement; 72, 73; 72, 74; 73, identifier:count; 74, block; 74, 75; 74, 88; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:secondQuery; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:inequalityQuery; 82, argument_list; 82, 83; 82, 86; 82, 87; 83, comparison_operator:<; 83, 84; 83, 85; 84, identifier:currentSortAttribute; 85, identifier:value; 86, identifier:count; 87, False; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:results; 92, identifier:extend; 93, argument_list; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:constructRows; 98, argument_list; 98, 99; 99, identifier:secondQuery; 100, return_statement; 100, 101; 101, subscript; 101, 102; 101, 103; 102, identifier:results; 103, slice; 103, 104; 103, 105; 103, 106; 104, colon; 105, colon; 106, unary_operator:-; 106, 107; 107, integer:1
def rowsBeforeItem(self, item, count): currentSortAttribute = self.currentSortColumn.sortAttribute() value = currentSortAttribute.__get__(item, type(item)) firstQuery = self.inequalityQuery( AND(currentSortAttribute == value, self.itemType.storeID < item.storeID), count, False) results = self.constructRows(firstQuery) count -= len(results) if count: secondQuery = self.inequalityQuery(currentSortAttribute < value, count, False) results.extend(self.constructRows(secondQuery)) return results[::-1]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:getTableMetadata; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 61; 5, 88; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:coltypes; 9, dictionary; 10, for_statement; 10, 11; 10, 14; 10, 21; 11, tuple_pattern; 11, 12; 11, 13; 12, identifier:colname; 13, identifier:column; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:columns; 19, identifier:iteritems; 20, argument_list; 21, block; 21, 22; 21, 32; 21, 40; 21, 53; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:sortable; 25, comparison_operator:is; 25, 26; 25, 31; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:column; 29, identifier:sortAttribute; 30, argument_list; 31, None; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:coltype; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:column; 38, identifier:getType; 39, argument_list; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:coltype; 43, None; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:coltype; 48, call; 48, 49; 48, 50; 49, identifier:unicode; 50, argument_list; 50, 51; 50, 52; 51, identifier:coltype; 52, string:'ascii'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, subscript; 55, 56; 55, 57; 56, identifier:coltypes; 57, identifier:colname; 58, tuple; 58, 59; 58, 60; 59, identifier:coltype; 60, identifier:sortable; 61, if_statement; 61, 62; 61, 65; 61, 82; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:currentSortColumn; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:csc; 69, call; 69, 70; 69, 71; 70, identifier:unicode; 71, argument_list; 71, 72; 71, 81; 72, attribute; 72, 73; 72, 80; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:currentSortColumn; 78, identifier:sortAttribute; 79, argument_list; 80, identifier:attrname; 81, string:'ascii'; 82, else_clause; 82, 83; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:csc; 87, None; 88, return_statement; 88, 89; 89, list:[self.columnNames, coltypes, self.requestCurrentSize(), csc, self.isAscending]; 89, 90; 89, 93; 89, 94; 89, 99; 89, 100; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:columnNames; 93, identifier:coltypes; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:requestCurrentSize; 98, argument_list; 99, identifier:csc; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:isAscending
def getTableMetadata(self): coltypes = {} for (colname, column) in self.columns.iteritems(): sortable = column.sortAttribute() is not None coltype = column.getType() if coltype is not None: coltype = unicode(coltype, 'ascii') coltypes[colname] = (coltype, sortable) if self.currentSortColumn: csc = unicode(self.currentSortColumn.sortAttribute().attrname, 'ascii') else: csc = None return [self.columnNames, coltypes, self.requestCurrentSize(), csc, self.isAscending]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:getInitialArguments; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 15; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:ic; 9, call; 9, 10; 9, 11; 10, identifier:IColumn; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:currentSortColumn; 15, return_statement; 15, 16; 16, list:[ic.attributeID.decode('ascii'), self._getColumnList(), self.isAscending]; 16, 17; 16, 25; 16, 30; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:ic; 21, identifier:attributeID; 22, identifier:decode; 23, argument_list; 23, 24; 24, string:'ascii'; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_getColumnList; 29, argument_list; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:isAscending
def getInitialArguments(self): ic = IColumn(self.currentSortColumn) return [ic.attributeID.decode('ascii'), self._getColumnList(), self.isAscending]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:build_database_sortmerna; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 18; 4, identifier:fasta_path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_pos; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:output_dir; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:temp_dir; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:tempfile; 16, identifier:gettempdir; 17, argument_list; 18, default_parameter; 18, 19; 18, 20; 19, identifier:HALT_EXEC; 20, False; 21, block; 21, 22; 21, 34; 21, 43; 21, 57; 21, 66; 21, 74; 21, 86; 21, 101; 21, 112; 21, 128; 21, 134; 21, 162; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:is; 23, 24; 23, 25; 24, identifier:fasta_path; 25, None; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:ValueError; 30, argument_list; 30, 31; 31, concatenated_string; 31, 32; 31, 33; 32, string:"Error: path to fasta reference "; 33, string:"sequences must exist."; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, pattern_list; 36, 37; 36, 38; 37, identifier:fasta_dir; 38, identifier:fasta_filename; 39, call; 39, 40; 39, 41; 40, identifier:split; 41, argument_list; 41, 42; 42, identifier:fasta_path; 43, if_statement; 43, 44; 43, 46; 44, not_operator; 44, 45; 45, identifier:output_dir; 46, block; 46, 47; 46, 53; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:output_dir; 50, boolean_operator:or; 50, 51; 50, 52; 51, identifier:fasta_dir; 52, string:'.'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:fasta_path; 56, identifier:fasta_filename; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:index_basename; 60, subscript; 60, 61; 60, 65; 61, call; 61, 62; 61, 63; 62, identifier:splitext; 63, argument_list; 63, 64; 64, identifier:fasta_filename; 65, integer:0; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:db_name; 69, call; 69, 70; 69, 71; 70, identifier:join; 71, argument_list; 71, 72; 71, 73; 72, identifier:output_dir; 73, identifier:index_basename; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:sdb; 77, call; 77, 78; 77, 79; 78, identifier:IndexDB; 79, argument_list; 79, 80; 79, 83; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:WorkingDir; 82, identifier:output_dir; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:HALT_EXEC; 85, identifier:HALT_EXEC; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 95; 88, attribute; 88, 89; 88, 94; 89, subscript; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:sdb; 92, identifier:Parameters; 93, string:'--ref'; 94, identifier:on; 95, argument_list; 95, 96; 96, binary_operator:%; 96, 97; 96, 98; 97, string:"%s,%s"; 98, tuple; 98, 99; 98, 100; 99, identifier:fasta_path; 100, identifier:db_name; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 110; 103, attribute; 103, 104; 103, 109; 104, subscript; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:sdb; 107, identifier:Parameters; 108, string:'--tmpdir'; 109, identifier:on; 110, argument_list; 110, 111; 111, identifier:temp_dir; 112, if_statement; 112, 113; 112, 116; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:max_pos; 115, None; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 126; 119, attribute; 119, 120; 119, 125; 120, subscript; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:sdb; 123, identifier:Parameters; 124, string:'--max_pos'; 125, identifier:on; 126, argument_list; 126, 127; 127, identifier:max_pos; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:app_result; 131, call; 131, 132; 131, 133; 132, identifier:sdb; 133, argument_list; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:db_filepaths; 137, list_comprehension; 137, 138; 137, 141; 137, 150; 138, attribute; 138, 139; 138, 140; 139, identifier:v; 140, identifier:name; 141, for_in_clause; 141, 142; 141, 145; 142, pattern_list; 142, 143; 142, 144; 143, identifier:k; 144, identifier:v; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:app_result; 148, identifier:items; 149, argument_list; 150, if_clause; 150, 151; 151, boolean_operator:and; 151, 152; 151, 157; 152, comparison_operator:not; 152, 153; 152, 154; 153, identifier:k; 154, set; 154, 155; 154, 156; 155, string:'StdErr'; 156, string:'StdOut'; 157, call; 157, 158; 157, 159; 158, identifier:hasattr; 159, argument_list; 159, 160; 159, 161; 160, identifier:v; 161, string:'name'; 162, return_statement; 162, 163; 163, expression_list; 163, 164; 163, 165; 164, identifier:db_name; 165, identifier:db_filepaths
def build_database_sortmerna(fasta_path, max_pos=None, output_dir=None, temp_dir=tempfile.gettempdir(), HALT_EXEC=False): if fasta_path is None: raise ValueError("Error: path to fasta reference " "sequences must exist.") fasta_dir, fasta_filename = split(fasta_path) if not output_dir: output_dir = fasta_dir or '.' fasta_path = fasta_filename index_basename = splitext(fasta_filename)[0] db_name = join(output_dir, index_basename) sdb = IndexDB(WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) sdb.Parameters['--ref'].on("%s,%s" % (fasta_path, db_name)) sdb.Parameters['--tmpdir'].on(temp_dir) if max_pos is not None: sdb.Parameters['--max_pos'].on(max_pos) app_result = sdb() db_filepaths = [v.name for k, v in app_result.items() if k not in {'StdErr', 'StdOut'} and hasattr(v, 'name')] return db_name, db_filepaths
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 37; 2, function_name:sortmerna_ref_cluster; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 4, default_parameter; 4, 5; 4, 6; 5, identifier:seq_path; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:sortmerna_db; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:refseqs_fp; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:result_path; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:tabular; 18, False; 19, default_parameter; 19, 20; 19, 21; 20, identifier:max_e_value; 21, integer:1; 22, default_parameter; 22, 23; 22, 24; 23, identifier:similarity; 24, float:0.97; 25, default_parameter; 25, 26; 25, 27; 26, identifier:coverage; 27, float:0.97; 28, default_parameter; 28, 29; 28, 30; 29, identifier:threads; 30, integer:1; 31, default_parameter; 31, 32; 31, 33; 32, identifier:best; 33, integer:1; 34, default_parameter; 34, 35; 34, 36; 35, identifier:HALT_EXEC; 36, False; 37, block; 37, 38; 37, 47; 37, 70; 37, 102; 37, 112; 37, 119; 37, 143; 37, 159; 37, 175; 37, 191; 37, 207; 37, 221; 37, 237; 37, 243; 37, 249; 37, 266; 37, 282; 37, 288; 37, 309; 37, 328; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:smr; 41, call; 41, 42; 41, 43; 42, identifier:Sortmerna; 43, argument_list; 43, 44; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:HALT_EXEC; 46, identifier:HALT_EXEC; 47, if_statement; 47, 48; 47, 51; 47, 63; 48, comparison_operator:is; 48, 49; 48, 50; 49, identifier:seq_path; 50, None; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 61; 54, attribute; 54, 55; 54, 60; 55, subscript; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:smr; 58, identifier:Parameters; 59, string:'--reads'; 60, identifier:on; 61, argument_list; 61, 62; 62, identifier:seq_path; 63, else_clause; 63, 64; 64, block; 64, 65; 65, raise_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:ValueError; 68, argument_list; 68, 69; 69, string:"Error: a read file is mandatory input."; 70, if_statement; 70, 71; 70, 74; 70, 90; 71, comparison_operator:is; 71, 72; 71, 73; 72, identifier:sortmerna_db; 73, None; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 84; 77, attribute; 77, 78; 77, 83; 78, subscript; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:smr; 81, identifier:Parameters; 82, string:'--ref'; 83, identifier:on; 84, argument_list; 84, 85; 85, binary_operator:%; 85, 86; 85, 87; 86, string:"%s,%s"; 87, tuple; 87, 88; 87, 89; 88, identifier:refseqs_fp; 89, identifier:sortmerna_db; 90, else_clause; 90, 91; 91, block; 91, 92; 92, raise_statement; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:ValueError; 95, argument_list; 95, 96; 96, binary_operator:%; 96, 97; 96, 101; 97, concatenated_string; 97, 98; 97, 99; 97, 100; 98, string:"Error: an indexed database for reference set %s must"; 99, string:" already exist.\nUse indexdb_rna to index the"; 100, string:" database."; 101, identifier:refseqs_fp; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:result_path; 105, None; 106, block; 106, 107; 107, raise_statement; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:ValueError; 110, argument_list; 110, 111; 111, string:"Error: the result path must be set."; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:output_dir; 115, call; 115, 116; 115, 117; 116, identifier:dirname; 117, argument_list; 117, 118; 118, identifier:result_path; 119, if_statement; 119, 120; 119, 123; 120, comparison_operator:is; 120, 121; 120, 122; 121, identifier:output_dir; 122, None; 123, block; 123, 124; 123, 132; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:output_file; 127, call; 127, 128; 127, 129; 128, identifier:join; 129, argument_list; 129, 130; 129, 131; 130, identifier:output_dir; 131, string:"sortmerna_otus"; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 141; 134, attribute; 134, 135; 134, 140; 135, subscript; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:smr; 138, identifier:Parameters; 139, string:'--aligned'; 140, identifier:on; 141, argument_list; 141, 142; 142, identifier:output_file; 143, if_statement; 143, 144; 143, 147; 144, comparison_operator:is; 144, 145; 144, 146; 145, identifier:max_e_value; 146, None; 147, block; 147, 148; 148, expression_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:smr; 154, identifier:Parameters; 155, string:'-e'; 156, identifier:on; 157, argument_list; 157, 158; 158, identifier:max_e_value; 159, if_statement; 159, 160; 159, 163; 160, comparison_operator:is; 160, 161; 160, 162; 161, identifier:similarity; 162, None; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 173; 166, attribute; 166, 167; 166, 172; 167, subscript; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:smr; 170, identifier:Parameters; 171, string:'--id'; 172, identifier:on; 173, argument_list; 173, 174; 174, identifier:similarity; 175, if_statement; 175, 176; 175, 179; 176, comparison_operator:is; 176, 177; 176, 178; 177, identifier:coverage; 178, None; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 189; 182, attribute; 182, 183; 182, 188; 183, subscript; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:smr; 186, identifier:Parameters; 187, string:'--coverage'; 188, identifier:on; 189, argument_list; 189, 190; 190, identifier:coverage; 191, if_statement; 191, 192; 191, 195; 192, comparison_operator:is; 192, 193; 192, 194; 193, identifier:best; 194, None; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 205; 198, attribute; 198, 199; 198, 204; 199, subscript; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:smr; 202, identifier:Parameters; 203, string:'--best'; 204, identifier:on; 205, argument_list; 205, 206; 206, identifier:best; 207, if_statement; 207, 208; 207, 209; 208, identifier:tabular; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 219; 212, attribute; 212, 213; 212, 218; 213, subscript; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:smr; 216, identifier:Parameters; 217, string:'--blast'; 218, identifier:on; 219, argument_list; 219, 220; 220, string:"3"; 221, if_statement; 221, 222; 221, 225; 222, comparison_operator:is; 222, 223; 222, 224; 223, identifier:threads; 224, None; 225, block; 225, 226; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 235; 228, attribute; 228, 229; 228, 234; 229, subscript; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:smr; 232, identifier:Parameters; 233, string:'-a'; 234, identifier:on; 235, argument_list; 235, 236; 236, identifier:threads; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:app_result; 240, call; 240, 241; 240, 242; 241, identifier:smr; 242, argument_list; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:f_otumap; 246, subscript; 246, 247; 246, 248; 247, identifier:app_result; 248, string:'OtuMap'; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:rows; 252, generator_expression; 252, 253; 252, 263; 253, call; 253, 254; 253, 261; 254, attribute; 254, 255; 254, 260; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:line; 258, identifier:strip; 259, argument_list; 260, identifier:split; 261, argument_list; 261, 262; 262, string:'\t'; 263, for_in_clause; 263, 264; 263, 265; 264, identifier:line; 265, identifier:f_otumap; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:clusters; 269, dictionary_comprehension; 269, 270; 269, 279; 270, pair; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:r; 273, integer:0; 274, subscript; 274, 275; 274, 276; 275, identifier:r; 276, slice; 276, 277; 276, 278; 277, integer:1; 278, colon; 279, for_in_clause; 279, 280; 279, 281; 280, identifier:r; 281, identifier:rows; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:f_failure; 285, subscript; 285, 286; 285, 287; 286, identifier:app_result; 287, string:'FastaForDenovo'; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:failures; 291, list_comprehension; 291, 292; 291, 301; 292, subscript; 292, 293; 292, 300; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:re; 296, identifier:split; 297, argument_list; 297, 298; 297, 299; 298, string:'>| '; 299, identifier:label; 300, integer:0; 301, for_in_clause; 301, 302; 301, 305; 302, pattern_list; 302, 303; 302, 304; 303, identifier:label; 304, identifier:seq; 305, call; 305, 306; 305, 307; 306, identifier:parse_fasta; 307, argument_list; 307, 308; 308, identifier:f_failure; 309, expression_statement; 309, 310; 310, assignment; 310, 311; 310, 312; 311, identifier:smr_files_to_remove; 312, list:[app_result['FastaForDenovo'].name, app_result['FastaMatches'].name, app_result['OtuMap'].name]; 312, 313; 312, 318; 312, 323; 313, attribute; 313, 314; 313, 317; 314, subscript; 314, 315; 314, 316; 315, identifier:app_result; 316, string:'FastaForDenovo'; 317, identifier:name; 318, attribute; 318, 319; 318, 322; 319, subscript; 319, 320; 319, 321; 320, identifier:app_result; 321, string:'FastaMatches'; 322, identifier:name; 323, attribute; 323, 324; 323, 327; 324, subscript; 324, 325; 324, 326; 325, identifier:app_result; 326, string:'OtuMap'; 327, identifier:name; 328, return_statement; 328, 329; 329, expression_list; 329, 330; 329, 331; 329, 332; 330, identifier:clusters; 331, identifier:failures; 332, identifier:smr_files_to_remove
def sortmerna_ref_cluster(seq_path=None, sortmerna_db=None, refseqs_fp=None, result_path=None, tabular=False, max_e_value=1, similarity=0.97, coverage=0.97, threads=1, best=1, HALT_EXEC=False ): smr = Sortmerna(HALT_EXEC=HALT_EXEC) if seq_path is not None: smr.Parameters['--reads'].on(seq_path) else: raise ValueError("Error: a read file is mandatory input.") if sortmerna_db is not None: smr.Parameters['--ref'].on("%s,%s" % (refseqs_fp, sortmerna_db)) else: raise ValueError("Error: an indexed database for reference set %s must" " already exist.\nUse indexdb_rna to index the" " database." % refseqs_fp) if result_path is None: raise ValueError("Error: the result path must be set.") output_dir = dirname(result_path) if output_dir is not None: output_file = join(output_dir, "sortmerna_otus") smr.Parameters['--aligned'].on(output_file) if max_e_value is not None: smr.Parameters['-e'].on(max_e_value) if similarity is not None: smr.Parameters['--id'].on(similarity) if coverage is not None: smr.Parameters['--coverage'].on(coverage) if best is not None: smr.Parameters['--best'].on(best) if tabular: smr.Parameters['--blast'].on("3") if threads is not None: smr.Parameters['-a'].on(threads) app_result = smr() f_otumap = app_result['OtuMap'] rows = (line.strip().split('\t') for line in f_otumap) clusters = {r[0]: r[1:] for r in rows} f_failure = app_result['FastaForDenovo'] failures = [re.split('>| ', label)[0] for label, seq in parse_fasta(f_failure)] smr_files_to_remove = [app_result['FastaForDenovo'].name, app_result['FastaMatches'].name, app_result['OtuMap'].name] return clusters, failures, smr_files_to_remove
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 35; 2, function_name:sortmerna_map; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 4, identifier:seq_path; 5, identifier:output_dir; 6, identifier:refseqs_fp; 7, identifier:sortmerna_db; 8, default_parameter; 8, 9; 8, 10; 9, identifier:e_value; 10, integer:1; 11, default_parameter; 11, 12; 11, 13; 12, identifier:threads; 13, integer:1; 14, default_parameter; 14, 15; 14, 16; 15, identifier:best; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:num_alignments; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:HALT_EXEC; 22, False; 23, default_parameter; 23, 24; 23, 25; 24, identifier:output_sam; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:sam_SQ_tags; 28, False; 29, default_parameter; 29, 30; 29, 31; 30, identifier:blast_format; 31, integer:3; 32, default_parameter; 32, 33; 32, 34; 33, identifier:print_all_reads; 34, True; 35, block; 35, 36; 35, 50; 35, 63; 35, 72; 35, 87; 35, 98; 35, 112; 35, 138; 35, 151; 35, 159; 35, 170; 35, 186; 35, 202; 35, 218; 35, 234; 35, 244; 35, 254; 35, 264; 35, 274; 35, 284; 35, 290; 36, if_statement; 36, 37; 36, 42; 37, not_operator; 37, 38; 38, parenthesized_expression; 38, 39; 39, boolean_operator:or; 39, 40; 39, 41; 40, identifier:blast_format; 41, identifier:output_sam; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:ValueError; 46, argument_list; 46, 47; 47, concatenated_string; 47, 48; 47, 49; 48, string:"Either Blast or SAM output alignment "; 49, string:"format must be chosen."; 50, if_statement; 50, 51; 50, 55; 51, parenthesized_expression; 51, 52; 52, boolean_operator:and; 52, 53; 52, 54; 53, identifier:best; 54, identifier:num_alignments; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:ValueError; 59, argument_list; 59, 60; 60, concatenated_string; 60, 61; 60, 62; 61, string:"Only one of --best or --num_alignments "; 62, string:"options must be chosen."; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:smr; 66, call; 66, 67; 66, 68; 67, identifier:Sortmerna; 68, argument_list; 68, 69; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:HALT_EXEC; 71, identifier:HALT_EXEC; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 81; 74, attribute; 74, 75; 74, 80; 75, subscript; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:smr; 78, identifier:Parameters; 79, string:'--ref'; 80, identifier:on; 81, argument_list; 81, 82; 82, binary_operator:%; 82, 83; 82, 84; 83, string:"%s,%s"; 84, tuple; 84, 85; 84, 86; 85, identifier:refseqs_fp; 86, identifier:sortmerna_db; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 96; 89, attribute; 89, 90; 89, 95; 90, subscript; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:smr; 93, identifier:Parameters; 94, string:'--reads'; 95, identifier:on; 96, argument_list; 96, 97; 97, identifier:seq_path; 98, if_statement; 98, 99; 98, 100; 99, identifier:blast_format; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 110; 103, attribute; 103, 104; 103, 109; 104, subscript; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:smr; 107, identifier:Parameters; 108, string:'--blast'; 109, identifier:on; 110, argument_list; 110, 111; 111, identifier:blast_format; 112, if_statement; 112, 113; 112, 114; 113, identifier:output_sam; 114, block; 114, 115; 114, 125; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 124; 117, attribute; 117, 118; 117, 123; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:smr; 121, identifier:Parameters; 122, string:'--sam'; 123, identifier:on; 124, argument_list; 125, if_statement; 125, 126; 125, 127; 126, identifier:sam_SQ_tags; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 137; 130, attribute; 130, 131; 130, 136; 131, subscript; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:smr; 134, identifier:Parameters; 135, string:'--SQ'; 136, identifier:on; 137, argument_list; 138, if_statement; 138, 139; 138, 140; 139, identifier:print_all_reads; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 150; 143, attribute; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:smr; 147, identifier:Parameters; 148, string:'--print_all_reads'; 149, identifier:on; 150, argument_list; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:output_file; 154, call; 154, 155; 154, 156; 155, identifier:join; 156, argument_list; 156, 157; 156, 158; 157, identifier:output_dir; 158, string:"sortmerna_map"; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 168; 161, attribute; 161, 162; 161, 167; 162, subscript; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:smr; 165, identifier:Parameters; 166, string:'--aligned'; 167, identifier:on; 168, argument_list; 168, 169; 169, identifier:output_file; 170, if_statement; 170, 171; 170, 174; 171, comparison_operator:is; 171, 172; 171, 173; 172, identifier:e_value; 173, None; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 184; 177, attribute; 177, 178; 177, 183; 178, subscript; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:smr; 181, identifier:Parameters; 182, string:'-e'; 183, identifier:on; 184, argument_list; 184, 185; 185, identifier:e_value; 186, if_statement; 186, 187; 186, 190; 187, comparison_operator:is; 187, 188; 187, 189; 188, identifier:best; 189, None; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 200; 193, attribute; 193, 194; 193, 199; 194, subscript; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:smr; 197, identifier:Parameters; 198, string:'--best'; 199, identifier:on; 200, argument_list; 200, 201; 201, identifier:best; 202, if_statement; 202, 203; 202, 206; 203, comparison_operator:is; 203, 204; 203, 205; 204, identifier:num_alignments; 205, None; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 216; 209, attribute; 209, 210; 209, 215; 210, subscript; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:smr; 213, identifier:Parameters; 214, string:'--num_alignments'; 215, identifier:on; 216, argument_list; 216, 217; 217, identifier:num_alignments; 218, if_statement; 218, 219; 218, 222; 219, comparison_operator:is; 219, 220; 219, 221; 220, identifier:threads; 221, None; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 232; 225, attribute; 225, 226; 225, 231; 226, subscript; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:smr; 229, identifier:Parameters; 230, string:'-a'; 231, identifier:on; 232, argument_list; 232, 233; 233, identifier:threads; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 243; 236, attribute; 236, 237; 236, 242; 237, subscript; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:smr; 240, identifier:Parameters; 241, string:'--fastx'; 242, identifier:off; 243, argument_list; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 253; 246, attribute; 246, 247; 246, 252; 247, subscript; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:smr; 250, identifier:Parameters; 251, string:'--otu_map'; 252, identifier:off; 253, argument_list; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 263; 256, attribute; 256, 257; 256, 262; 257, subscript; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:smr; 260, identifier:Parameters; 261, string:'--de_novo_otu'; 262, identifier:off; 263, argument_list; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 273; 266, attribute; 266, 267; 266, 272; 267, subscript; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:smr; 270, identifier:Parameters; 271, string:'--id'; 272, identifier:off; 273, argument_list; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 283; 276, attribute; 276, 277; 276, 282; 277, subscript; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:smr; 280, identifier:Parameters; 281, string:'--coverage'; 282, identifier:off; 283, argument_list; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:app_result; 287, call; 287, 288; 287, 289; 288, identifier:smr; 289, argument_list; 290, return_statement; 290, 291; 291, identifier:app_result
def sortmerna_map(seq_path, output_dir, refseqs_fp, sortmerna_db, e_value=1, threads=1, best=None, num_alignments=None, HALT_EXEC=False, output_sam=False, sam_SQ_tags=False, blast_format=3, print_all_reads=True, ): if not (blast_format or output_sam): raise ValueError("Either Blast or SAM output alignment " "format must be chosen.") if (best and num_alignments): raise ValueError("Only one of --best or --num_alignments " "options must be chosen.") smr = Sortmerna(HALT_EXEC=HALT_EXEC) smr.Parameters['--ref'].on("%s,%s" % (refseqs_fp, sortmerna_db)) smr.Parameters['--reads'].on(seq_path) if blast_format: smr.Parameters['--blast'].on(blast_format) if output_sam: smr.Parameters['--sam'].on() if sam_SQ_tags: smr.Parameters['--SQ'].on() if print_all_reads: smr.Parameters['--print_all_reads'].on() output_file = join(output_dir, "sortmerna_map") smr.Parameters['--aligned'].on(output_file) if e_value is not None: smr.Parameters['-e'].on(e_value) if best is not None: smr.Parameters['--best'].on(best) if num_alignments is not None: smr.Parameters['--num_alignments'].on(num_alignments) if threads is not None: smr.Parameters['-a'].on(threads) smr.Parameters['--fastx'].off() smr.Parameters['--otu_map'].off() smr.Parameters['--de_novo_otu'].off() smr.Parameters['--id'].off() smr.Parameters['--coverage'].off() app_result = smr() return app_result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_dict_values_sorted_by_key; 3, parameters; 3, 4; 4, identifier:dictionary; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 10; 6, 26; 7, pattern_list; 7, 8; 7, 9; 8, identifier:_; 9, identifier:value; 10, call; 10, 11; 10, 12; 11, identifier:sorted; 12, argument_list; 12, 13; 12, 18; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:dictionary; 16, identifier:iteritems; 17, argument_list; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:key; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:operator; 23, identifier:itemgetter; 24, argument_list; 24, 25; 25, integer:0; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, yield; 28, 29; 29, identifier:value
def _dict_values_sorted_by_key(dictionary): for _, value in sorted(dictionary.iteritems(), key=operator.itemgetter(0)): yield value
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 52; 2, function_name:uclust_cluster_from_sorted_fasta_filepath; 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, 49; 4, identifier:fasta_filepath; 5, default_parameter; 5, 6; 5, 7; 6, identifier:uc_save_filepath; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:percent_ID; 10, float:0.97; 11, default_parameter; 11, 12; 11, 13; 12, identifier:max_accepts; 13, integer:1; 14, default_parameter; 14, 15; 14, 16; 15, identifier:max_rejects; 16, integer:8; 17, default_parameter; 17, 18; 17, 19; 18, identifier:stepwords; 19, integer:8; 20, default_parameter; 20, 21; 20, 22; 21, identifier:word_length; 22, integer:8; 23, default_parameter; 23, 24; 23, 25; 24, identifier:optimal; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:exact; 28, False; 29, default_parameter; 29, 30; 29, 31; 30, identifier:suppress_sort; 31, False; 32, default_parameter; 32, 33; 32, 34; 33, identifier:enable_rev_strand_matching; 34, False; 35, default_parameter; 35, 36; 35, 37; 36, identifier:subject_fasta_filepath; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:suppress_new_clusters; 40, False; 41, default_parameter; 41, 42; 41, 43; 42, identifier:stable_sort; 43, False; 44, default_parameter; 44, 45; 44, 46; 45, identifier:tmp_dir; 46, call; 46, 47; 46, 48; 47, identifier:gettempdir; 48, argument_list; 49, default_parameter; 49, 50; 49, 51; 50, identifier:HALT_EXEC; 51, False; 52, block; 52, 53; 52, 57; 52, 78; 52, 100; 52, 113; 52, 126; 52, 139; 52, 152; 52, 165; 52, 179; 52, 192; 52, 205; 52, 218; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:output_filepath; 56, identifier:uc_save_filepath; 57, if_statement; 57, 58; 57, 60; 58, not_operator; 58, 59; 59, identifier:output_filepath; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, pattern_list; 63, 64; 63, 65; 64, identifier:_; 65, identifier:output_filepath; 66, call; 66, 67; 66, 68; 67, identifier:mkstemp; 68, argument_list; 68, 69; 68, 72; 68, 75; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:dir; 71, identifier:tmp_dir; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:prefix; 74, string:'uclust_clusters'; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:suffix; 77, string:'.uc'; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:params; 81, dictionary; 81, 82; 81, 85; 81, 88; 81, 91; 81, 94; 81, 97; 82, pair; 82, 83; 82, 84; 83, string:'--id'; 84, identifier:percent_ID; 85, pair; 85, 86; 85, 87; 86, string:'--maxaccepts'; 87, identifier:max_accepts; 88, pair; 88, 89; 88, 90; 89, string:'--maxrejects'; 90, identifier:max_rejects; 91, pair; 91, 92; 91, 93; 92, string:'--stepwords'; 93, identifier:stepwords; 94, pair; 94, 95; 94, 96; 95, string:'--w'; 96, identifier:word_length; 97, pair; 97, 98; 97, 99; 98, string:'--tmpdir'; 99, identifier:tmp_dir; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:app; 103, call; 103, 104; 103, 105; 104, identifier:Uclust; 105, argument_list; 105, 106; 105, 107; 105, 110; 106, identifier:params; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:TmpDir; 109, identifier:tmp_dir; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:HALT_EXEC; 112, identifier:HALT_EXEC; 113, if_statement; 113, 114; 113, 115; 114, identifier:enable_rev_strand_matching; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 125; 118, attribute; 118, 119; 118, 124; 119, subscript; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:app; 122, identifier:Parameters; 123, string:'--rev'; 124, identifier:on; 125, argument_list; 126, if_statement; 126, 127; 126, 128; 127, identifier:optimal; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 138; 131, attribute; 131, 132; 131, 137; 132, subscript; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:app; 135, identifier:Parameters; 136, string:'--optimal'; 137, identifier:on; 138, argument_list; 139, if_statement; 139, 140; 139, 141; 140, identifier:exact; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 151; 144, attribute; 144, 145; 144, 150; 145, subscript; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:app; 148, identifier:Parameters; 149, string:'--exact'; 150, identifier:on; 151, argument_list; 152, if_statement; 152, 153; 152, 154; 153, identifier:suppress_sort; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 164; 157, attribute; 157, 158; 157, 163; 158, subscript; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:app; 161, identifier:Parameters; 162, string:'--usersort'; 163, identifier:on; 164, argument_list; 165, if_statement; 165, 166; 165, 167; 166, identifier:subject_fasta_filepath; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 177; 170, attribute; 170, 171; 170, 176; 171, subscript; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:app; 174, identifier:Parameters; 175, string:'--lib'; 176, identifier:on; 177, argument_list; 177, 178; 178, identifier:subject_fasta_filepath; 179, if_statement; 179, 180; 179, 181; 180, identifier:suppress_new_clusters; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 191; 184, attribute; 184, 185; 184, 190; 185, subscript; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:app; 188, identifier:Parameters; 189, string:'--libonly'; 190, identifier:on; 191, argument_list; 192, if_statement; 192, 193; 192, 194; 193, identifier:stable_sort; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 204; 197, attribute; 197, 198; 197, 203; 198, subscript; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:app; 201, identifier:Parameters; 202, string:'--stable_sort'; 203, identifier:on; 204, argument_list; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:app_result; 208, call; 208, 209; 208, 210; 209, identifier:app; 210, argument_list; 210, 211; 211, dictionary; 211, 212; 211, 215; 212, pair; 212, 213; 212, 214; 213, string:'--input'; 214, identifier:fasta_filepath; 215, pair; 215, 216; 215, 217; 216, string:'--uc'; 217, identifier:output_filepath; 218, return_statement; 218, 219; 219, identifier:app_result
def uclust_cluster_from_sorted_fasta_filepath( fasta_filepath, uc_save_filepath=None, percent_ID=0.97, max_accepts=1, max_rejects=8, stepwords=8, word_length=8, optimal=False, exact=False, suppress_sort=False, enable_rev_strand_matching=False, subject_fasta_filepath=None, suppress_new_clusters=False, stable_sort=False, tmp_dir=gettempdir(), HALT_EXEC=False): output_filepath = uc_save_filepath if not output_filepath: _, output_filepath = mkstemp(dir=tmp_dir, prefix='uclust_clusters', suffix='.uc') params = {'--id': percent_ID, '--maxaccepts': max_accepts, '--maxrejects': max_rejects, '--stepwords': stepwords, '--w': word_length, '--tmpdir': tmp_dir} app = Uclust(params, TmpDir=tmp_dir, HALT_EXEC=HALT_EXEC) if enable_rev_strand_matching: app.Parameters['--rev'].on() if optimal: app.Parameters['--optimal'].on() if exact: app.Parameters['--exact'].on() if suppress_sort: app.Parameters['--usersort'].on() if subject_fasta_filepath: app.Parameters['--lib'].on(subject_fasta_filepath) if suppress_new_clusters: app.Parameters['--libonly'].on() if stable_sort: app.Parameters['--stable_sort'].on() app_result = app({'--input': fasta_filepath, '--uc': output_filepath}) return app_result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 59; 2, function_name:get_clusters_from_fasta_filepath; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 3, 39; 3, 42; 3, 45; 3, 48; 3, 53; 3, 56; 4, identifier:fasta_filepath; 5, identifier:original_fasta_path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:percent_ID; 8, float:0.97; 9, default_parameter; 9, 10; 9, 11; 10, identifier:max_accepts; 11, integer:1; 12, default_parameter; 12, 13; 12, 14; 13, identifier:max_rejects; 14, integer:8; 15, default_parameter; 15, 16; 15, 17; 16, identifier:stepwords; 17, integer:8; 18, default_parameter; 18, 19; 18, 20; 19, identifier:word_length; 20, integer:8; 21, default_parameter; 21, 22; 21, 23; 22, identifier:optimal; 23, False; 24, default_parameter; 24, 25; 24, 26; 25, identifier:exact; 26, False; 27, default_parameter; 27, 28; 27, 29; 28, identifier:suppress_sort; 29, False; 30, default_parameter; 30, 31; 30, 32; 31, identifier:output_dir; 32, None; 33, default_parameter; 33, 34; 33, 35; 34, identifier:enable_rev_strand_matching; 35, False; 36, default_parameter; 36, 37; 36, 38; 37, identifier:subject_fasta_filepath; 38, None; 39, default_parameter; 39, 40; 39, 41; 40, identifier:suppress_new_clusters; 41, False; 42, default_parameter; 42, 43; 42, 44; 43, identifier:return_cluster_maps; 44, False; 45, default_parameter; 45, 46; 45, 47; 46, identifier:stable_sort; 47, False; 48, default_parameter; 48, 49; 48, 50; 49, identifier:tmp_dir; 50, call; 50, 51; 50, 52; 51, identifier:gettempdir; 52, argument_list; 53, default_parameter; 53, 54; 53, 55; 54, identifier:save_uc_files; 55, True; 56, default_parameter; 56, 57; 56, 58; 57, identifier:HALT_EXEC; 58, False; 59, block; 59, 60; 59, 64; 59, 68; 59, 72; 59, 87; 59, 104; 59, 108; 59, 112; 59, 116; 59, 120; 59, 247; 59, 260; 59, 270; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:fasta_output_filepath; 63, None; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:uc_output_filepath; 67, None; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:cd_hit_filepath; 71, None; 72, if_statement; 72, 73; 72, 82; 73, boolean_operator:and; 73, 74; 73, 75; 74, identifier:output_dir; 75, not_operator; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:output_dir; 79, identifier:endswith; 80, argument_list; 80, 81; 81, string:'/'; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, augmented_assignment:+=; 84, 85; 84, 86; 85, identifier:output_dir; 86, string:'/'; 87, if_statement; 87, 88; 87, 89; 87, 98; 88, identifier:save_uc_files; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:uc_save_filepath; 93, call; 93, 94; 93, 95; 94, identifier:get_output_filepaths; 95, argument_list; 95, 96; 95, 97; 96, identifier:output_dir; 97, identifier:original_fasta_path; 98, else_clause; 98, 99; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:uc_save_filepath; 103, None; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:sorted_fasta_filepath; 107, string:""; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:uc_filepath; 111, string:""; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:clstr_filepath; 115, string:""; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:files_to_remove; 119, list:[]; 120, try_statement; 120, 121; 120, 216; 120, 232; 121, block; 121, 122; 121, 161; 121, 211; 122, if_statement; 122, 123; 122, 125; 122, 151; 123, not_operator; 123, 124; 124, identifier:suppress_sort; 125, block; 125, 126; 125, 136; 125, 144; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:sort_fasta; 129, call; 129, 130; 129, 131; 130, identifier:uclust_fasta_sort_from_filepath; 131, argument_list; 131, 132; 131, 133; 132, identifier:fasta_filepath; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:output_filepath; 135, identifier:fasta_output_filepath; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:sorted_fasta_filepath; 139, attribute; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:sort_fasta; 142, string:'Output'; 143, identifier:name; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:files_to_remove; 148, identifier:append; 149, argument_list; 149, 150; 150, identifier:sorted_fasta_filepath; 151, else_clause; 151, 152; 152, block; 152, 153; 152, 157; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:sort_fasta; 156, None; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:sorted_fasta_filepath; 160, identifier:fasta_filepath; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:uclust_cluster; 164, call; 164, 165; 164, 166; 165, identifier:uclust_cluster_from_sorted_fasta_filepath; 166, argument_list; 166, 167; 166, 168; 166, 169; 166, 172; 166, 175; 166, 178; 166, 181; 166, 184; 166, 187; 166, 190; 166, 193; 166, 196; 166, 199; 166, 202; 166, 205; 166, 208; 167, identifier:sorted_fasta_filepath; 168, identifier:uc_save_filepath; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:percent_ID; 171, identifier:percent_ID; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:max_accepts; 174, identifier:max_accepts; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:max_rejects; 177, identifier:max_rejects; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:stepwords; 180, identifier:stepwords; 181, keyword_argument; 181, 182; 181, 183; 182, identifier:word_length; 183, identifier:word_length; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:optimal; 186, identifier:optimal; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:exact; 189, identifier:exact; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:suppress_sort; 192, identifier:suppress_sort; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:enable_rev_strand_matching; 195, identifier:enable_rev_strand_matching; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:subject_fasta_filepath; 198, identifier:subject_fasta_filepath; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:suppress_new_clusters; 201, identifier:suppress_new_clusters; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:stable_sort; 204, identifier:stable_sort; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:tmp_dir; 207, identifier:tmp_dir; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:HALT_EXEC; 210, identifier:HALT_EXEC; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:remove_files; 214, argument_list; 214, 215; 215, identifier:files_to_remove; 216, except_clause; 216, 217; 216, 218; 217, identifier:ApplicationError; 218, block; 218, 219; 218, 224; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 222; 221, identifier:remove_files; 222, argument_list; 222, 223; 223, identifier:files_to_remove; 224, raise_statement; 224, 225; 225, call; 225, 226; 225, 227; 226, identifier:ApplicationError; 227, argument_list; 227, 228; 228, concatenated_string; 228, 229; 228, 230; 228, 231; 229, string:'Error running uclust. Possible causes are '; 230, string:'unsupported version (current supported version is v1.2.22) is installed or '; 231, string:'improperly formatted input file was provided'; 232, except_clause; 232, 233; 232, 234; 233, identifier:ApplicationNotFoundError; 234, block; 234, 235; 234, 240; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 238; 237, identifier:remove_files; 238, argument_list; 238, 239; 239, identifier:files_to_remove; 240, raise_statement; 240, 241; 241, call; 241, 242; 241, 243; 242, identifier:ApplicationNotFoundError; 243, argument_list; 243, 244; 244, binary_operator:+; 244, 245; 244, 246; 245, string:'uclust not found, is it properly '; 246, string:'installed?'; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 253; 248, 254; 249, pattern_list; 249, 250; 249, 251; 249, 252; 250, identifier:clusters; 251, identifier:failures; 252, identifier:seeds; 253, line_continuation:\; 254, call; 254, 255; 254, 256; 255, identifier:clusters_from_uc_file; 256, argument_list; 256, 257; 257, subscript; 257, 258; 257, 259; 258, identifier:uclust_cluster; 259, string:'ClusterFile'; 260, if_statement; 260, 261; 260, 263; 261, not_operator; 261, 262; 262, identifier:save_uc_files; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:uclust_cluster; 268, identifier:cleanUp; 269, argument_list; 270, if_statement; 270, 271; 270, 272; 270, 278; 271, identifier:return_cluster_maps; 272, block; 272, 273; 273, return_statement; 273, 274; 274, expression_list; 274, 275; 274, 276; 274, 277; 275, identifier:clusters; 276, identifier:failures; 277, identifier:seeds; 278, else_clause; 278, 279; 279, block; 279, 280; 280, return_statement; 280, 281; 281, expression_list; 281, 282; 281, 287; 281, 288; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:clusters; 285, identifier:values; 286, argument_list; 287, identifier:failures; 288, identifier:seeds
def get_clusters_from_fasta_filepath( fasta_filepath, original_fasta_path, percent_ID=0.97, max_accepts=1, max_rejects=8, stepwords=8, word_length=8, optimal=False, exact=False, suppress_sort=False, output_dir=None, enable_rev_strand_matching=False, subject_fasta_filepath=None, suppress_new_clusters=False, return_cluster_maps=False, stable_sort=False, tmp_dir=gettempdir(), save_uc_files=True, HALT_EXEC=False): fasta_output_filepath = None uc_output_filepath = None cd_hit_filepath = None if output_dir and not output_dir.endswith('/'): output_dir += '/' if save_uc_files: uc_save_filepath = get_output_filepaths( output_dir, original_fasta_path) else: uc_save_filepath = None sorted_fasta_filepath = "" uc_filepath = "" clstr_filepath = "" files_to_remove = [] try: if not suppress_sort: sort_fasta = uclust_fasta_sort_from_filepath(fasta_filepath, output_filepath=fasta_output_filepath) sorted_fasta_filepath = sort_fasta['Output'].name files_to_remove.append(sorted_fasta_filepath) else: sort_fasta = None sorted_fasta_filepath = fasta_filepath uclust_cluster = uclust_cluster_from_sorted_fasta_filepath( sorted_fasta_filepath, uc_save_filepath, percent_ID=percent_ID, max_accepts=max_accepts, max_rejects=max_rejects, stepwords=stepwords, word_length=word_length, optimal=optimal, exact=exact, suppress_sort=suppress_sort, enable_rev_strand_matching=enable_rev_strand_matching, subject_fasta_filepath=subject_fasta_filepath, suppress_new_clusters=suppress_new_clusters, stable_sort=stable_sort, tmp_dir=tmp_dir, HALT_EXEC=HALT_EXEC) remove_files(files_to_remove) except ApplicationError: remove_files(files_to_remove) raise ApplicationError('Error running uclust. Possible causes are ' 'unsupported version (current supported version is v1.2.22) is installed or ' 'improperly formatted input file was provided') except ApplicationNotFoundError: remove_files(files_to_remove) raise ApplicationNotFoundError('uclust not found, is it properly ' + 'installed?') clusters, failures, seeds = \ clusters_from_uc_file(uclust_cluster['ClusterFile']) if not save_uc_files: uclust_cluster.cleanUp() if return_cluster_maps: return clusters, failures, seeds else: return clusters.values(), failures, seeds
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:ls; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:startswith; 7, None; 8, block; 8, 9; 8, 11; 8, 20; 8, 29; 8, 48; 9, expression_statement; 9, 10; 10, string:''' List all cubes available to the calling client. :param startswith: string to use in a simple "startswith" query filter :returns list: sorted list of cube names '''; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logger; 15, identifier:info; 16, argument_list; 16, 17; 17, binary_operator:%; 17, 18; 17, 19; 18, string:'Listing cubes starting with "%s")'; 19, identifier:startswith; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:startswith; 23, call; 23, 24; 23, 25; 24, identifier:unicode; 25, argument_list; 25, 26; 26, boolean_operator:or; 26, 27; 26, 28; 27, identifier:startswith; 28, string:''; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:tables; 32, call; 32, 33; 32, 34; 33, identifier:sorted; 34, generator_expression; 34, 35; 34, 36; 34, 41; 35, identifier:name; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:name; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:db_tables; 41, if_clause; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:name; 45, identifier:startswith; 46, argument_list; 46, 47; 47, identifier:startswith; 48, return_statement; 48, 49; 49, identifier:tables
def ls(self, startswith=None): ''' List all cubes available to the calling client. :param startswith: string to use in a simple "startswith" query filter :returns list: sorted list of cube names ''' logger.info('Listing cubes starting with "%s")' % startswith) startswith = unicode(startswith or '') tables = sorted(name for name in self.db_tables if name.startswith(startswith)) return tables
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 35; 2, function_name:usearch_sort_by_abundance; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 4, identifier:fasta_filepath; 5, default_parameter; 5, 6; 5, 7; 6, identifier:output_filepath; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sizein; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sizeout; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:minsize; 16, integer:0; 17, default_parameter; 17, 18; 17, 19; 18, identifier:log_name; 19, string:"abundance_sort.log"; 20, default_parameter; 20, 21; 20, 22; 21, identifier:usersort; 22, False; 23, default_parameter; 23, 24; 23, 25; 24, identifier:HALT_EXEC; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:save_intermediate_files; 28, False; 29, default_parameter; 29, 30; 29, 31; 30, identifier:remove_usearch_logs; 31, False; 32, default_parameter; 32, 33; 32, 34; 33, identifier:working_dir; 34, None; 35, block; 35, 36; 35, 54; 35, 71; 35, 75; 35, 88; 35, 101; 35, 115; 35, 128; 35, 141; 35, 151; 35, 161; 35, 180; 36, if_statement; 36, 37; 36, 39; 37, not_operator; 37, 38; 38, identifier:output_filepath; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, pattern_list; 42, 43; 42, 44; 43, identifier:_; 44, identifier:output_filepath; 45, call; 45, 46; 45, 47; 46, identifier:mkstemp; 47, argument_list; 47, 48; 47, 51; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:prefix; 50, string:'usearch_abundance_sorted'; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:suffix; 53, string:'.fasta'; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:log_filepath; 57, call; 57, 58; 57, 59; 58, identifier:join; 59, argument_list; 59, 60; 59, 61; 60, identifier:working_dir; 61, binary_operator:+; 61, 62; 61, 70; 62, binary_operator:+; 62, 63; 62, 69; 63, binary_operator:+; 63, 64; 63, 65; 64, string:"minsize_"; 65, call; 65, 66; 65, 67; 66, identifier:str; 67, argument_list; 67, 68; 68, identifier:minsize; 69, string:"_"; 70, identifier:log_name; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:params; 74, dictionary; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:app; 78, call; 78, 79; 78, 80; 79, identifier:Usearch; 80, argument_list; 80, 81; 80, 82; 80, 85; 81, identifier:params; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:WorkingDir; 84, identifier:working_dir; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:HALT_EXEC; 87, identifier:HALT_EXEC; 88, if_statement; 88, 89; 88, 90; 89, identifier:usersort; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 100; 93, attribute; 93, 94; 93, 99; 94, subscript; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:app; 97, identifier:Parameters; 98, string:'--usersort'; 99, identifier:on; 100, argument_list; 101, if_statement; 101, 102; 101, 103; 102, identifier:minsize; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 113; 106, attribute; 106, 107; 106, 112; 107, subscript; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:app; 110, identifier:Parameters; 111, string:'--minsize'; 112, identifier:on; 113, argument_list; 113, 114; 114, identifier:minsize; 115, if_statement; 115, 116; 115, 117; 116, identifier:sizein; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 127; 120, attribute; 120, 121; 120, 126; 121, subscript; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:app; 124, identifier:Parameters; 125, string:'--sizein'; 126, identifier:on; 127, argument_list; 128, if_statement; 128, 129; 128, 130; 129, identifier:sizeout; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 140; 133, attribute; 133, 134; 133, 139; 134, subscript; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:app; 137, identifier:Parameters; 138, string:'--sizeout'; 139, identifier:on; 140, argument_list; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:data; 144, dictionary; 144, 145; 144, 148; 145, pair; 145, 146; 145, 147; 146, string:'--sortsize'; 147, identifier:fasta_filepath; 148, pair; 148, 149; 148, 150; 149, string:'--output'; 150, identifier:output_filepath; 151, if_statement; 151, 152; 151, 154; 152, not_operator; 152, 153; 153, identifier:remove_usearch_logs; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:data; 159, string:'--log'; 160, identifier:log_filepath; 161, try_statement; 161, 162; 161, 170; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:app_result; 166, call; 166, 167; 166, 168; 167, identifier:app; 168, argument_list; 168, 169; 169, identifier:data; 170, except_clause; 170, 171; 170, 172; 171, identifier:ApplicationError; 172, block; 172, 173; 173, raise_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:ValueError; 176, argument_list; 176, 177; 177, binary_operator:+; 177, 178; 177, 179; 178, string:'No data following filter steps, please check '; 179, string:'parameter settings for usearch_qf.'; 180, return_statement; 180, 181; 181, expression_list; 181, 182; 181, 183; 182, identifier:app_result; 183, identifier:output_filepath
def usearch_sort_by_abundance( fasta_filepath, output_filepath=None, sizein=True, sizeout=True, minsize=0, log_name="abundance_sort.log", usersort=False, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): if not output_filepath: _, output_filepath = mkstemp(prefix='usearch_abundance_sorted', suffix='.fasta') log_filepath = join( working_dir, "minsize_" + str(minsize) + "_" + log_name) params = {} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() if minsize: app.Parameters['--minsize'].on(minsize) if sizein: app.Parameters['--sizein'].on() if sizeout: app.Parameters['--sizeout'].on() data = {'--sortsize': fasta_filepath, '--output': output_filepath } if not remove_usearch_logs: data['--log'] = log_filepath try: app_result = app(data) except ApplicationError: raise ValueError('No data following filter steps, please check ' + 'parameter settings for usearch_qf.') return app_result, output_filepath
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 47; 2, function_name:usearch_cluster_error_correction; 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; 4, identifier:fasta_filepath; 5, default_parameter; 5, 6; 5, 7; 6, identifier:output_filepath; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:output_uc_filepath; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:percent_id_err; 13, float:0.97; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sizein; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:sizeout; 19, True; 20, default_parameter; 20, 21; 20, 22; 21, identifier:w; 22, integer:64; 23, default_parameter; 23, 24; 23, 25; 24, identifier:slots; 25, integer:16769023; 26, default_parameter; 26, 27; 26, 28; 27, identifier:maxrejects; 28, integer:64; 29, default_parameter; 29, 30; 29, 31; 30, identifier:log_name; 31, string:"usearch_cluster_err_corrected.log"; 32, default_parameter; 32, 33; 32, 34; 33, identifier:usersort; 34, False; 35, default_parameter; 35, 36; 35, 37; 36, identifier:HALT_EXEC; 37, False; 38, default_parameter; 38, 39; 38, 40; 39, identifier:save_intermediate_files; 40, False; 41, default_parameter; 41, 42; 41, 43; 42, identifier:remove_usearch_logs; 43, False; 44, default_parameter; 44, 45; 44, 46; 45, identifier:working_dir; 46, None; 47, block; 47, 48; 47, 66; 47, 74; 47, 96; 47, 109; 47, 122; 47, 132; 47, 142; 47, 151; 47, 158; 48, if_statement; 48, 49; 48, 51; 49, not_operator; 49, 50; 50, identifier:output_filepath; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, pattern_list; 54, 55; 54, 56; 55, identifier:_; 56, identifier:output_filepath; 57, call; 57, 58; 57, 59; 58, identifier:mkstemp; 59, argument_list; 59, 60; 59, 63; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:prefix; 62, string:'usearch_cluster_err_corrected'; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:suffix; 65, string:'.fasta'; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:log_filepath; 69, call; 69, 70; 69, 71; 70, identifier:join; 71, argument_list; 71, 72; 71, 73; 72, identifier:working_dir; 73, identifier:log_name; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:params; 77, dictionary; 77, 78; 77, 81; 77, 84; 77, 87; 77, 90; 77, 93; 78, pair; 78, 79; 78, 80; 79, string:'--sizein'; 80, identifier:sizein; 81, pair; 81, 82; 81, 83; 82, string:'--sizeout'; 83, identifier:sizeout; 84, pair; 84, 85; 84, 86; 85, string:'--id'; 86, identifier:percent_id_err; 87, pair; 87, 88; 87, 89; 88, string:'--w'; 89, identifier:w; 90, pair; 90, 91; 90, 92; 91, string:'--slots'; 92, identifier:slots; 93, pair; 93, 94; 93, 95; 94, string:'--maxrejects'; 95, identifier:maxrejects; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:app; 99, call; 99, 100; 99, 101; 100, identifier:Usearch; 101, argument_list; 101, 102; 101, 103; 101, 106; 102, identifier:params; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:WorkingDir; 105, identifier:working_dir; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:HALT_EXEC; 108, identifier:HALT_EXEC; 109, if_statement; 109, 110; 109, 111; 110, identifier:usersort; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 121; 114, attribute; 114, 115; 114, 120; 115, subscript; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:app; 118, identifier:Parameters; 119, string:'--usersort'; 120, identifier:on; 121, argument_list; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:data; 125, dictionary; 125, 126; 125, 129; 126, pair; 126, 127; 126, 128; 127, string:'--cluster'; 128, identifier:fasta_filepath; 129, pair; 129, 130; 129, 131; 130, string:'--consout'; 131, identifier:output_filepath; 132, if_statement; 132, 133; 132, 135; 133, not_operator; 133, 134; 134, identifier:remove_usearch_logs; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:data; 140, string:'--log'; 141, identifier:log_filepath; 142, if_statement; 142, 143; 142, 144; 143, identifier:output_uc_filepath; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:data; 149, string:'--uc'; 150, identifier:output_uc_filepath; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:app_result; 154, call; 154, 155; 154, 156; 155, identifier:app; 156, argument_list; 156, 157; 157, identifier:data; 158, return_statement; 158, 159; 159, expression_list; 159, 160; 159, 161; 160, identifier:app_result; 161, identifier:output_filepath
def usearch_cluster_error_correction( fasta_filepath, output_filepath=None, output_uc_filepath=None, percent_id_err=0.97, sizein=True, sizeout=True, w=64, slots=16769023, maxrejects=64, log_name="usearch_cluster_err_corrected.log", usersort=False, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): if not output_filepath: _, output_filepath = mkstemp(prefix='usearch_cluster_err_corrected', suffix='.fasta') log_filepath = join(working_dir, log_name) params = {'--sizein': sizein, '--sizeout': sizeout, '--id': percent_id_err, '--w': w, '--slots': slots, '--maxrejects': maxrejects} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() data = {'--cluster': fasta_filepath, '--consout': output_filepath } if not remove_usearch_logs: data['--log'] = log_filepath if output_uc_filepath: data['--uc'] = output_uc_filepath app_result = app(data) return app_result, output_filepath