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; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:slug; 6, block; 6, 7; 6, 16; 6, 21; 6, 29; 6, 42; 6, 55; 6, 68; 6, 81; 6, 94; 6, 107; 6, 115; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:kb; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:api; 13, identifier:get_kb_by_slug; 14, argument_list; 14, 15; 15, identifier:slug; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:check_knowledge_access; 19, argument_list; 19, 20; 20, identifier:kb; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:parser; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:reqparse; 27, identifier:RequestParser; 28, argument_list; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:parser; 33, identifier:add_argument; 34, argument_list; 34, 35; 34, 36; 34, 39; 35, string:'from'; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:type; 38, identifier:str; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:help; 41, string:"Return only entries where 'from' matches this."; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:parser; 46, identifier:add_argument; 47, argument_list; 47, 48; 47, 49; 47, 52; 48, string:'to'; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:type; 51, identifier:str; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:help; 54, string:"Return only entries where 'to' matches this."; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:parser; 59, identifier:add_argument; 60, argument_list; 60, 61; 60, 62; 60, 65; 61, string:'page'; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:type; 64, identifier:int; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:help; 67, string:"Require a specific page"; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:parser; 72, identifier:add_argument; 73, argument_list; 73, 74; 73, 75; 73, 78; 74, string:'per_page'; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:type; 77, identifier:int; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:help; 80, string:"Set how much result per page"; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:parser; 85, identifier:add_argument; 86, argument_list; 86, 87; 86, 88; 86, 91; 87, string:'match_type'; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:type; 90, identifier:str; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:help; 93, string:"s=substring, e=exact, sw=startswith"; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:parser; 98, identifier:add_argument; 99, argument_list; 99, 100; 99, 101; 99, 104; 100, string:'sortby'; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:type; 103, identifier:str; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:help; 106, string:"the sorting criteria ('from' or 'to')"; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:args; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:parser; 113, identifier:parse_args; 114, argument_list; 115, return_statement; 115, 116; 116, call; 116, 117; 116, 121; 117, attribute; 117, 118; 117, 119; 117, 120; 118, identifier:KnwKBMappingsResource; 119, line_continuation:\; 120, identifier:search_mappings; 121, argument_list; 121, 122; 121, 123; 121, 126; 121, 129; 121, 132; 121, 135; 121, 138; 122, identifier:kb; 123, subscript; 123, 124; 123, 125; 124, identifier:args; 125, string:'from'; 126, subscript; 126, 127; 126, 128; 127, identifier:args; 128, string:'to'; 129, subscript; 129, 130; 129, 131; 130, identifier:args; 131, string:'match_type'; 132, subscript; 132, 133; 132, 134; 133, identifier:args; 134, string:'sortby'; 135, subscript; 135, 136; 135, 137; 136, identifier:args; 137, string:'page'; 138, subscript; 138, 139; 138, 140; 139, identifier:args; 140, string:'per_page'
def get(self, slug): kb = api.get_kb_by_slug(slug) check_knowledge_access(kb) parser = reqparse.RequestParser() parser.add_argument( 'from', type=str, help="Return only entries where 'from' matches this.") parser.add_argument( 'to', type=str, help="Return only entries where 'to' matches this.") parser.add_argument('page', type=int, help="Require a specific page") parser.add_argument('per_page', type=int, help="Set how much result per page") parser.add_argument('match_type', type=str, help="s=substring, e=exact, sw=startswith") parser.add_argument('sortby', type=str, help="the sorting criteria ('from' or 'to')") args = parser.parse_args() return KnwKBMappingsResource \ .search_mappings(kb, args['from'], args['to'], args['match_type'], args['sortby'], args['page'], args['per_page'])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:pretty; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 95; 6, expression_statement; 6, 7; 7, string:"sort values and format output for viewing and comparing in test scenarios"; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:pretty_obj; 11, call; 11, 12; 11, 13; 12, identifier:OrderedDict; 13, argument_list; 14, for_statement; 14, 15; 14, 18; 14, 27; 15, pattern_list; 15, 16; 15, 17; 16, identifier:key; 17, identifier:value; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:iteritems; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:__dict__; 27, block; 27, 28; 28, if_statement; 28, 29; 28, 32; 28, 39; 28, 58; 28, 71; 28, 84; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:value; 31, None; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:pretty_obj; 37, identifier:key; 38, None; 39, elif_clause; 39, 40; 39, 44; 40, call; 40, 41; 40, 42; 41, identifier:is_str_or_unicode; 42, argument_list; 42, 43; 43, identifier:value; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:pretty_obj; 49, identifier:key; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:__dict__; 55, identifier:get; 56, argument_list; 56, 57; 57, identifier:key; 58, elif_clause; 58, 59; 58, 64; 59, call; 59, 60; 59, 61; 60, identifier:isinstance; 61, argument_list; 61, 62; 61, 63; 62, identifier:value; 63, identifier:list; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:pretty_obj; 69, identifier:key; 70, list:[]; 71, elif_clause; 71, 72; 71, 77; 72, call; 72, 73; 72, 74; 73, identifier:isinstance; 74, argument_list; 74, 75; 74, 76; 75, identifier:value; 76, identifier:dict; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:pretty_obj; 82, identifier:key; 83, dictionary; 84, else_clause; 84, 85; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:pretty_obj; 90, identifier:key; 91, call; 91, 92; 91, 93; 92, identifier:unicode_value; 93, argument_list; 93, 94; 94, identifier:value; 95, return_statement; 95, 96; 96, identifier:pretty_obj
def pretty(self): "sort values and format output for viewing and comparing in test scenarios" pretty_obj = OrderedDict() for key, value in sorted(iteritems(self.__dict__)): if value is None: pretty_obj[key] = None elif is_str_or_unicode(value): pretty_obj[key] = self.__dict__.get(key) elif isinstance(value, list): pretty_obj[key] = [] elif isinstance(value, dict): pretty_obj[key] = {} else: pretty_obj[key] = unicode_value(value) return pretty_obj
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 1, 17; 2, function_name:import_directory; 3, parameters; 3, 4; 3, 8; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:module_basename; 6, type; 6, 7; 7, identifier:str; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:directory; 10, type; 10, 11; 11, identifier:str; 12, default_parameter; 12, 13; 12, 14; 13, identifier:sort_key; 14, None; 15, type; 15, 16; 16, None; 17, block; 17, 18; 17, 20; 17, 28; 17, 36; 17, 78; 17, 87; 18, expression_statement; 18, 19; 19, string:'''Load all python modules in directory and directory's children. Parameters ---------- :``module_basename``: module name prefix for loaded modules :``directory``: directory to load python modules from :``sort_key``: function to sort module names with before loading '''; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:logger; 24, identifier:info; 25, argument_list; 25, 26; 25, 27; 26, string:'loading submodules of %s'; 27, identifier:module_basename; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:logger; 32, identifier:info; 33, argument_list; 33, 34; 33, 35; 34, string:'loading modules from %s'; 35, identifier:directory; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:filenames; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:itertools; 42, identifier:chain; 43, argument_list; 43, 44; 44, list_splat; 44, 45; 45, list_comprehension; 45, 46; 45, 63; 45, 71; 46, list_comprehension; 46, 47; 46, 58; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:os; 51, identifier:path; 52, identifier:join; 53, argument_list; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:_; 56, integer:0; 57, identifier:filename; 58, for_in_clause; 58, 59; 58, 60; 59, identifier:filename; 60, subscript; 60, 61; 60, 62; 61, identifier:_; 62, integer:2; 63, for_in_clause; 63, 64; 63, 65; 64, identifier:_; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:os; 68, identifier:walk; 69, argument_list; 69, 70; 70, identifier:directory; 71, if_clause; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, subscript; 75, 76; 75, 77; 76, identifier:_; 77, integer:2; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:modulenames; 81, call; 81, 82; 81, 83; 82, identifier:_filenames_to_modulenames; 83, argument_list; 83, 84; 83, 85; 83, 86; 84, identifier:filenames; 85, identifier:module_basename; 86, identifier:directory; 87, for_statement; 87, 88; 87, 89; 87, 96; 88, identifier:modulename; 89, call; 89, 90; 89, 91; 90, identifier:sorted; 91, argument_list; 91, 92; 91, 93; 92, identifier:modulenames; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:key; 95, identifier:sort_key; 96, block; 96, 97; 97, try_statement; 97, 98; 97, 106; 97, 124; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:importlib; 103, identifier:import_module; 104, argument_list; 104, 105; 105, identifier:modulename; 106, except_clause; 106, 107; 106, 108; 107, identifier:ImportError; 108, block; 108, 109; 108, 117; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:logger; 113, identifier:warning; 114, argument_list; 114, 115; 114, 116; 115, string:'failed loading %s'; 116, identifier:modulename; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:logger; 121, identifier:exception; 122, argument_list; 122, 123; 123, string:'module loading failure'; 124, else_clause; 124, 125; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:logger; 130, identifier:info; 131, argument_list; 131, 132; 131, 133; 132, string:'successfully loaded %s'; 133, identifier:modulename
def import_directory(module_basename: str, directory: str, sort_key = None) -> None: '''Load all python modules in directory and directory's children. Parameters ---------- :``module_basename``: module name prefix for loaded modules :``directory``: directory to load python modules from :``sort_key``: function to sort module names with before loading ''' logger.info('loading submodules of %s', module_basename) logger.info('loading modules from %s', directory) filenames = itertools.chain(*[ [ os.path.join(_[0], filename) for filename in _[2] ] for _ in os.walk(directory) if len(_[2]) ]) modulenames = _filenames_to_modulenames(filenames, module_basename, directory) for modulename in sorted(modulenames, key = sort_key): try: importlib.import_module(modulename) except ImportError: logger.warning('failed loading %s', modulename) logger.exception('module loading failure') else: logger.info('successfully loaded %s', modulename)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:read; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:given_file; 6, block; 6, 7; 6, 25; 6, 36; 6, 50; 6, 108; 6, 119; 6, 136; 7, if_statement; 7, 8; 7, 19; 8, boolean_operator:and; 8, 9; 8, 14; 9, comparison_operator:is; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:unique; 13, False; 14, comparison_operator:is; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:unique; 18, True; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:AttributeError; 23, argument_list; 23, 24; 24, string:"Attribute 'unique' is not True or False."; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:filename; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:str; 33, identifier:strip; 34, argument_list; 34, 35; 35, identifier:given_file; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:log; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, string:'Read-only opening {0}'; 45, identifier:format; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:filename; 50, with_statement; 50, 51; 50, 63; 51, with_clause; 51, 52; 52, with_item; 52, 53; 53, as_pattern; 53, 54; 53, 61; 54, call; 54, 55; 54, 56; 55, identifier:open; 56, argument_list; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:filename; 60, string:'r'; 61, as_pattern_target; 61, 62; 62, identifier:handle; 63, block; 63, 64; 64, for_statement; 64, 65; 64, 66; 64, 67; 65, identifier:line; 66, identifier:handle; 67, block; 67, 68; 67, 77; 67, 86; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:line; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:line; 74, identifier:rstrip; 75, argument_list; 75, 76; 76, string:'\r\n'; 77, if_statement; 77, 78; 77, 81; 78, comparison_operator:is; 78, 79; 78, 80; 79, identifier:line; 80, None; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:line; 85, string:''; 86, if_statement; 86, 87; 86, 98; 87, boolean_operator:or; 87, 88; 87, 93; 88, comparison_operator:is; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:unique; 92, False; 93, comparison_operator:not; 93, 94; 93, 95; 94, identifier:line; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:contents; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:contents; 105, identifier:append; 106, argument_list; 106, 107; 107, identifier:line; 108, if_statement; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:sorted; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:sort; 118, argument_list; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:log; 124, argument_list; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, string:'Read {0} lines.'; 128, identifier:format; 129, argument_list; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:len; 132, argument_list; 132, 133; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:contents; 136, return_statement; 136, 137; 137, True
def read(self, given_file): if self.unique is not False and self.unique is not True: raise AttributeError("Attribute 'unique' is not True or False.") self.filename = str.strip(given_file) self.log('Read-only opening {0}'.format(self.filename)) with open(self.filename, 'r') as handle: for line in handle: line = line.rstrip('\r\n') if line is None: line = '' if self.unique is False or line not in self.contents: self.contents.append(line) if self.sorted: self.sort() self.log('Read {0} lines.'.format(len(self.contents))) return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:force_clear_lock; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, string:'''Kick out whoever currently owns the namespace global lock. This is intended as purely a last-resort tool. If another process has managed to get the global lock for a very long time, or if it requested the lock with a long expiration and then crashed, this can make the system functional again. If the original lock holder is still alive, its session calls may fail with exceptions. '''; 8, return_statement; 8, 9; 9, call; 9, 10; 9, 22; 10, attribute; 10, 11; 10, 21; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:redis; 14, identifier:Redis; 15, argument_list; 15, 16; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:connection_pool; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:pool; 21, identifier:delete; 22, argument_list; 22, 23; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:_lock_name
def force_clear_lock(self): '''Kick out whoever currently owns the namespace global lock. This is intended as purely a last-resort tool. If another process has managed to get the global lock for a very long time, or if it requested the lock with a long expiration and then crashed, this can make the system functional again. If the original lock holder is still alive, its session calls may fail with exceptions. ''' return redis.Redis(connection_pool=self.pool).delete(self._lock_name)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:prettyprint; 3, parameters; 3, 4; 4, identifier:d; 5, block; 5, 6; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:print; 9, argument_list; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:json; 13, identifier:dumps; 14, argument_list; 14, 15; 14, 16; 14, 19; 14, 22; 15, identifier:d; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:sort_keys; 18, True; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:indent; 21, integer:4; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:separators; 24, tuple; 24, 25; 24, 26; 25, string:","; 26, string:": "
def prettyprint(d): print(json.dumps(d, sort_keys=True, indent=4, separators=("," , ": ")))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_is_iterable; 3, parameters; 3, 4; 4, identifier:val; 5, block; 5, 6; 6, try_statement; 6, 7; 6, 13; 6, 20; 7, block; 7, 8; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:iter; 11, argument_list; 11, 12; 12, identifier:val; 13, except_clause; 13, 14; 13, 17; 14, tuple; 14, 15; 14, 16; 15, identifier:ValueError; 16, identifier:TypeError; 17, block; 17, 18; 18, return_statement; 18, 19; 19, False; 20, else_clause; 20, 21; 21, block; 21, 22; 22, return_statement; 22, 23; 23, not_operator; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 28; 27, identifier:val; 28, identifier:basestring
def _is_iterable(val): try: iter(val) except (ValueError, TypeError): return False else: return not isinstance(val, basestring)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:square_off; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:series; 5, default_parameter; 5, 6; 5, 7; 6, identifier:time_delta; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:transition_seconds; 10, integer:1; 11, block; 11, 12; 11, 94; 12, if_statement; 12, 13; 12, 14; 12, 42; 13, identifier:time_delta; 14, block; 14, 15; 14, 34; 15, if_statement; 15, 16; 15, 23; 16, call; 16, 17; 16, 18; 17, identifier:isinstance; 18, argument_list; 18, 19; 18, 20; 19, identifier:time_delta; 20, tuple; 20, 21; 20, 22; 21, identifier:int; 22, identifier:float; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:time_delta; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:datetime; 30, identifier:timedelta; 31, argument_list; 31, 32; 31, 33; 32, integer:0; 33, identifier:time_delta; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:new_times; 37, binary_operator:+; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:series; 40, identifier:index; 41, identifier:time_delta; 42, else_clause; 42, 43; 43, block; 43, 44; 43, 55; 43, 69; 43, 77; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:diff; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:np; 50, identifier:diff; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:series; 54, identifier:index; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:time_delta; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:np; 61, identifier:append; 62, argument_list; 62, 63; 62, 64; 63, identifier:diff; 64, list:[diff[-1]]; 64, 65; 65, subscript; 65, 66; 65, 67; 66, identifier:diff; 67, unary_operator:-; 67, 68; 68, integer:1; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:new_times; 72, binary_operator:+; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:series; 75, identifier:index; 76, identifier:time_delta; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:new_times; 80, binary_operator:-; 80, 81; 80, 87; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:pd; 84, identifier:DatetimeIndex; 85, argument_list; 85, 86; 86, identifier:new_times; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:datetime; 90, identifier:timedelta; 91, argument_list; 91, 92; 91, 93; 92, integer:0; 93, identifier:transition_seconds; 94, return_statement; 94, 95; 95, call; 95, 96; 95, 116; 96, attribute; 96, 97; 96, 115; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:pd; 100, identifier:concat; 101, argument_list; 101, 102; 102, list:[series, pd.Series(series.values, index=new_times)]; 102, 103; 102, 104; 103, identifier:series; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:pd; 107, identifier:Series; 108, argument_list; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:series; 111, identifier:values; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:index; 114, identifier:new_times; 115, identifier:sort_index; 116, argument_list
def square_off(series, time_delta=None, transition_seconds=1): if time_delta: if isinstance(time_delta, (int, float)): time_delta = datetime.timedelta(0, time_delta) new_times = series.index + time_delta else: diff = np.diff(series.index) time_delta = np.append(diff, [diff[-1]]) new_times = series.index + time_delta new_times = pd.DatetimeIndex(new_times) - datetime.timedelta(0, transition_seconds) return pd.concat([series, pd.Series(series.values, index=new_times)]).sort_index()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sortframe; 3, parameters; 3, 4; 4, identifier:frame; 5, block; 5, 6; 5, 8; 5, 14; 5, 32; 5, 38; 5, 44; 6, expression_statement; 6, 7; 7, string:''' sorts particles for a frame '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:d; 11, subscript; 11, 12; 11, 13; 12, identifier:frame; 13, string:'data'; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:sortedargs; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:np; 20, identifier:lexsort; 21, argument_list; 21, 22; 22, list:[d['xi'],d['yi'],d['zi']]; 22, 23; 22, 26; 22, 29; 23, subscript; 23, 24; 23, 25; 24, identifier:d; 25, string:'xi'; 26, subscript; 26, 27; 26, 28; 27, identifier:d; 28, string:'yi'; 29, subscript; 29, 30; 29, 31; 30, identifier:d; 31, string:'zi'; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:d; 35, subscript; 35, 36; 35, 37; 36, identifier:d; 37, identifier:sortedargs; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:frame; 42, string:'data'; 43, identifier:d; 44, return_statement; 44, 45; 45, identifier:frame
def sortframe(frame): ''' sorts particles for a frame ''' d = frame['data']; sortedargs = np.lexsort([d['xi'],d['yi'],d['zi']]) d = d[sortedargs]; frame['data']=d; return frame;
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_release_id; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:version; 6, None; 7, block; 7, 8; 7, 21; 7, 28; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:ts; 11, call; 11, 12; 11, 19; 12, attribute; 12, 13; 12, 18; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:datetime; 16, identifier:utcnow; 17, argument_list; 18, identifier:strftime; 19, argument_list; 19, 20; 20, identifier:RELEASE_DATE_FMT; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:version; 24, None; 25, block; 25, 26; 26, return_statement; 26, 27; 27, identifier:ts; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, string:'{0}-{1}'; 32, identifier:format; 33, argument_list; 33, 34; 33, 35; 34, identifier:ts; 35, identifier:version
def get_release_id(version=None): ts = datetime.utcnow().strftime(RELEASE_DATE_FMT) if version is None: return ts return '{0}-{1}'.format(ts, version)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:group_objects_by; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:list; 6, identifier:attr; 7, default_parameter; 7, 8; 7, 9; 8, identifier:valueLabel; 9, string:"value"; 10, default_parameter; 10, 11; 10, 12; 11, identifier:childrenLabel; 12, string:"children"; 13, block; 13, 14; 13, 18; 13, 104; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:groups; 17, list:[]; 18, for_statement; 18, 19; 18, 20; 18, 21; 19, identifier:obj; 20, identifier:list; 21, block; 21, 22; 21, 31; 21, 36; 21, 50; 21, 54; 21, 93; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:val; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:obj; 28, identifier:get; 29, argument_list; 29, 30; 30, identifier:attr; 31, if_statement; 31, 32; 31, 34; 32, not_operator; 32, 33; 33, identifier:val; 34, block; 34, 35; 35, pass_statement; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:newGroup; 39, dictionary; 39, 40; 39, 43; 39, 46; 40, pair; 40, 41; 40, 42; 41, string:"attribute"; 42, identifier:attr; 43, pair; 43, 44; 43, 45; 44, identifier:valueLabel; 45, identifier:val; 46, pair; 46, 47; 46, 48; 47, identifier:childrenLabel; 48, list:[obj]; 48, 49; 49, identifier:obj; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:found; 53, False; 54, for_statement; 54, 55; 54, 56; 54, 64; 55, identifier:i; 56, call; 56, 57; 56, 58; 57, identifier:range; 58, argument_list; 58, 59; 58, 60; 59, integer:0; 60, call; 60, 61; 60, 62; 61, identifier:len; 62, argument_list; 62, 63; 63, identifier:groups; 64, block; 64, 65; 65, if_statement; 65, 66; 65, 76; 66, comparison_operator:==; 66, 67; 66, 68; 67, identifier:val; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:groups; 72, identifier:i; 73, identifier:get; 74, argument_list; 74, 75; 75, identifier:valueLabel; 76, block; 76, 77; 76, 81; 76, 92; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:found; 80, True; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 90; 83, attribute; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:groups; 87, identifier:i; 88, identifier:childrenLabel; 89, identifier:append; 90, argument_list; 90, 91; 91, identifier:obj; 92, pass_statement; 93, if_statement; 93, 94; 93, 96; 94, not_operator; 94, 95; 95, identifier:found; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:groups; 101, identifier:append; 102, argument_list; 102, 103; 103, identifier:newGroup; 104, return_statement; 104, 105; 105, identifier:groups
def group_objects_by(self, list, attr, valueLabel="value", childrenLabel="children"): groups = [] for obj in list: val = obj.get(attr) if not val: pass newGroup = {"attribute": attr, valueLabel: val, childrenLabel: [obj]} found = False for i in range(0,len(groups)): if val == groups[i].get(valueLabel): found = True groups[i][childrenLabel].append(obj) pass if not found: groups.append(newGroup) return groups
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorts_query; 3, parameters; 3, 4; 4, identifier:sortables; 5, block; 5, 6; 5, 10; 5, 49; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:stmts; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:sortable; 12, identifier:sortables; 13, block; 13, 14; 14, if_statement; 14, 15; 14, 18; 14, 33; 15, attribute; 15, 16; 15, 17; 16, identifier:sortable; 17, identifier:desc; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:stmts; 23, identifier:append; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, string:'{} DESC'; 28, identifier:format; 29, argument_list; 29, 30; 30, attribute; 30, 31; 30, 32; 31, identifier:sortable; 32, identifier:field; 33, else_clause; 33, 34; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:stmts; 39, identifier:append; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, string:'{} ASC'; 44, identifier:format; 45, argument_list; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:sortable; 48, identifier:field; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, string:' ORDER BY {}'; 53, identifier:format; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, string:', '; 58, identifier:join; 59, argument_list; 59, 60; 60, identifier:stmts
def sorts_query(sortables): stmts = [] for sortable in sortables: if sortable.desc: stmts.append('{} DESC'.format(sortable.field)) else: stmts.append('{} ASC'.format(sortable.field)) return ' ORDER BY {}'.format(', '.join(stmts))
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:rtype; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 16; 8, 20; 8, 34; 8, 57; 8, 78; 8, 88; 8, 99; 8, 117; 8, 128; 8, 148; 8, 152; 8, 156; 8, 160; 8, 174; 8, 186; 8, 197; 8, 214; 8, 223; 8, 238; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:model; 12, call; 12, 13; 12, 14; 13, identifier:rtype_to_model; 14, argument_list; 14, 15; 15, identifier:rtype; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:param; 19, dictionary; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:pages; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:pages_query; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:kwargs; 31, identifier:get; 32, argument_list; 32, 33; 33, string:'pages'; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:sorts; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:sorts_query; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:kwargs; 45, identifier:get; 46, argument_list; 46, 47; 46, 48; 47, string:'sorts'; 48, list:[Sortable(goldman.config.SORT)]; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:Sortable; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:goldman; 55, identifier:config; 56, identifier:SORT; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:query; 60, assignment; 60, 61; 60, 62; 61, identifier:query; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:query; 65, identifier:format; 66, argument_list; 66, 67; 66, 75; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:cols; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:field_cols; 73, argument_list; 73, 74; 74, identifier:model; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:table; 77, identifier:rtype; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:filters; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:kwargs; 84, identifier:get; 85, argument_list; 85, 86; 85, 87; 86, string:'filters'; 87, list:[]; 88, expression_statement; 88, 89; 89, augmented_assignment:+=; 89, 90; 89, 91; 90, identifier:filters; 91, boolean_operator:or; 91, 92; 91, 98; 92, call; 92, 93; 92, 94; 93, identifier:getattr; 94, argument_list; 94, 95; 94, 96; 94, 97; 95, identifier:model; 96, string:'search_filters'; 97, list:[]; 98, list:[]; 99, if_statement; 99, 100; 99, 101; 100, identifier:filters; 101, block; 101, 102; 101, 113; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, pattern_list; 104, 105; 104, 106; 105, identifier:where; 106, identifier:param; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:filters_query; 111, argument_list; 111, 112; 112, identifier:filters; 113, expression_statement; 113, 114; 114, augmented_assignment:+=; 114, 115; 114, 116; 115, identifier:query; 116, identifier:where; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:model_query; 120, boolean_operator:or; 120, 121; 120, 127; 121, call; 121, 122; 121, 123; 122, identifier:getattr; 123, argument_list; 123, 124; 123, 125; 123, 126; 124, identifier:model; 125, string:'search_query'; 126, string:''; 127, string:''; 128, if_statement; 128, 129; 128, 132; 128, 139; 129, boolean_operator:and; 129, 130; 129, 131; 130, identifier:filters; 131, identifier:model_query; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:model_query; 136, binary_operator:+; 136, 137; 136, 138; 137, string:' AND '; 138, identifier:model_query; 139, elif_clause; 139, 140; 139, 141; 140, identifier:model_query; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:model_query; 145, binary_operator:+; 145, 146; 145, 147; 146, string:' WHERE '; 147, identifier:model_query; 148, expression_statement; 148, 149; 149, augmented_assignment:+=; 149, 150; 149, 151; 150, identifier:query; 151, identifier:model_query; 152, expression_statement; 152, 153; 153, augmented_assignment:+=; 153, 154; 153, 155; 154, identifier:query; 155, identifier:sorts; 156, expression_statement; 156, 157; 157, augmented_assignment:+=; 157, 158; 157, 159; 158, identifier:query; 159, identifier:pages; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 167; 162, attribute; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:signals; 165, identifier:pre_search; 166, identifier:send; 167, argument_list; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:model; 170, identifier:__class__; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:model; 173, identifier:model; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:result; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:query; 181, argument_list; 181, 182; 181, 183; 182, identifier:query; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:param; 185, identifier:param; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:models; 189, list_comprehension; 189, 190; 189, 194; 190, call; 190, 191; 190, 192; 191, identifier:model; 192, argument_list; 192, 193; 193, identifier:res; 194, for_in_clause; 194, 195; 194, 196; 195, identifier:res; 196, identifier:result; 197, if_statement; 197, 198; 197, 199; 198, identifier:models; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:signals; 205, identifier:post_search; 206, identifier:send; 207, argument_list; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:model; 210, identifier:__class__; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:models; 213, identifier:result; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:pages; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:kwargs; 220, identifier:get; 221, argument_list; 221, 222; 222, string:'pages'; 223, if_statement; 223, 224; 223, 227; 224, boolean_operator:and; 224, 225; 224, 226; 225, identifier:pages; 226, identifier:result; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:pages; 232, identifier:total; 233, subscript; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:result; 236, integer:0; 237, string:'_count'; 238, return_statement; 238, 239; 239, identifier:models
def search(self, rtype, **kwargs): model = rtype_to_model(rtype) param = {} pages = self.pages_query(kwargs.get('pages')) sorts = self.sorts_query(kwargs.get( 'sorts', [Sortable(goldman.config.SORT)] )) query = query = query.format( cols=self.field_cols(model), table=rtype, ) filters = kwargs.get('filters', []) filters += getattr(model, 'search_filters', []) or [] if filters: where, param = self.filters_query(filters) query += where model_query = getattr(model, 'search_query', '') or '' if filters and model_query: model_query = ' AND ' + model_query elif model_query: model_query = ' WHERE ' + model_query query += model_query query += sorts query += pages signals.pre_search.send(model.__class__, model=model) result = self.query(query, param=param) models = [model(res) for res in result] if models: signals.post_search.send(model.__class__, models=result) pages = kwargs.get('pages') if pages and result: pages.total = result[0]['_count'] return models
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:force_seek; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:fd; 5, identifier:offset; 6, default_parameter; 6, 7; 6, 8; 7, identifier:chunk; 8, identifier:CHUNK; 9, block; 9, 10; 10, try_statement; 10, 11; 10, 19; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:fd; 16, identifier:seek; 17, argument_list; 17, 18; 18, identifier:offset; 19, except_clause; 19, 20; 19, 25; 20, tuple; 20, 21; 20, 22; 21, identifier:AttributeError; 22, attribute; 22, 23; 22, 24; 23, identifier:io; 24, identifier:UnsupportedOperation; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:emulate_seek; 29, argument_list; 29, 30; 29, 31; 29, 32; 30, identifier:fd; 31, identifier:offset; 32, identifier:chunk
def force_seek(fd, offset, chunk=CHUNK): try: fd.seek(offset) except (AttributeError, io.UnsupportedOperation): emulate_seek(fd, offset, chunk)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:append; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:hcont; 6, identifier:value; 7, default_parameter; 7, 8; 7, 9; 8, identifier:score; 9, None; 10, block; 10, 11; 10, 25; 10, 44; 11, assert_statement; 11, 12; 12, comparison_operator:!=; 12, 13; 12, 17; 13, parenthesized_expression; 13, 14; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:score; 16, None; 17, parenthesized_expression; 17, 18; 18, comparison_operator:is; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:field; 23, identifier:sort_field; 24, None; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:score; 28, None; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:score; 33, call; 33, 34; 33, 35; 34, identifier:getattr; 35, argument_list; 35, 36; 35, 37; 36, identifier:value; 37, attribute; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:field; 42, identifier:sort_field; 43, identifier:name; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:ContainerFieldWriter; 48, identifier:append; 49, argument_list; 49, 50; 49, 51; 49, 52; 49, 53; 50, identifier:self; 51, identifier:hcont; 52, identifier:value; 53, identifier:score
def append(self, hcont, value, score = None): assert (score is None) != (self.field.sort_field is None) if score is None: score = getattr(value, self.field.sort_field.name) ContainerFieldWriter.append(self, hcont, value, score)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:raise_errors_on_nested_writes; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:method_name; 5, identifier:serializer; 6, identifier:validated_data; 7, block; 7, 8; 7, 71; 8, assert_statement; 8, 9; 8, 44; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:any; 12, generator_expression; 12, 13; 12, 33; 13, boolean_operator:and; 13, 14; 13, 24; 14, boolean_operator:and; 14, 15; 14, 20; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:field; 19, identifier:BaseSerializer; 20, parenthesized_expression; 20, 21; 21, comparison_operator:in; 21, 22; 21, 23; 22, identifier:key; 23, identifier:validated_data; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:validated_data; 29, identifier:key; 30, tuple; 30, 31; 30, 32; 31, identifier:list; 32, identifier:dict; 33, for_in_clause; 33, 34; 33, 37; 34, pattern_list; 34, 35; 34, 36; 35, identifier:key; 36, identifier:field; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:serializer; 41, identifier:fields; 42, identifier:items; 43, argument_list; 44, parenthesized_expression; 44, 45; 45, call; 45, 46; 45, 53; 46, attribute; 46, 47; 46, 52; 47, concatenated_string; 47, 48; 47, 49; 47, 50; 47, 51; 48, string:'The `.{method_name}()` method does not support writable nested'; 49, string:'fields by default.\nWrite an explicit `.{method_name}()` method for '; 50, string:'serializer `{module}.{class_name}`, or set `read_only=True` on '; 51, string:'nested serializer fields.'; 52, identifier:format; 53, argument_list; 53, 54; 53, 57; 53, 64; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:method_name; 56, identifier:method_name; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:module; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:serializer; 62, identifier:__class__; 63, identifier:__module__; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:class_name; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:serializer; 69, identifier:__class__; 70, identifier:__name__; 71, assert_statement; 71, 72; 71, 107; 72, not_operator; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:any; 75, generator_expression; 75, 76; 75, 96; 76, boolean_operator:and; 76, 77; 76, 87; 77, boolean_operator:and; 77, 78; 77, 83; 78, comparison_operator:in; 78, 79; 78, 80; 79, string:'.'; 80, attribute; 80, 81; 80, 82; 81, identifier:field; 82, identifier:source; 83, parenthesized_expression; 83, 84; 84, comparison_operator:in; 84, 85; 84, 86; 85, identifier:key; 86, identifier:validated_data; 87, call; 87, 88; 87, 89; 88, identifier:isinstance; 89, argument_list; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:validated_data; 92, identifier:key; 93, tuple; 93, 94; 93, 95; 94, identifier:list; 95, identifier:dict; 96, for_in_clause; 96, 97; 96, 100; 97, pattern_list; 97, 98; 97, 99; 98, identifier:key; 99, identifier:field; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:serializer; 104, identifier:fields; 105, identifier:items; 106, argument_list; 107, parenthesized_expression; 107, 108; 108, call; 108, 109; 108, 116; 109, attribute; 109, 110; 109, 115; 110, concatenated_string; 110, 111; 110, 112; 110, 113; 110, 114; 111, string:'The `.{method_name}()` method does not support writable dotted-source '; 112, string:'fields by default.\nWrite an explicit `.{method_name}()` method for '; 113, string:'serializer `{module}.{class_name}`, or set `read_only=True` on '; 114, string:'dotted-source serializer fields.'; 115, identifier:format; 116, argument_list; 116, 117; 116, 120; 116, 127; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:method_name; 119, identifier:method_name; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:module; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:serializer; 125, identifier:__class__; 126, identifier:__module__; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:class_name; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:serializer; 132, identifier:__class__; 133, identifier:__name__
def raise_errors_on_nested_writes(method_name, serializer, validated_data): assert not any( isinstance(field, BaseSerializer) and (key in validated_data) and isinstance(validated_data[key], (list, dict)) for key, field in serializer.fields.items() ), ( 'The `.{method_name}()` method does not support writable nested' 'fields by default.\nWrite an explicit `.{method_name}()` method for ' 'serializer `{module}.{class_name}`, or set `read_only=True` on ' 'nested serializer fields.'.format( method_name=method_name, module=serializer.__class__.__module__, class_name=serializer.__class__.__name__ ) ) assert not any( '.' in field.source and (key in validated_data) and isinstance(validated_data[key], (list, dict)) for key, field in serializer.fields.items() ), ( 'The `.{method_name}()` method does not support writable dotted-source ' 'fields by default.\nWrite an explicit `.{method_name}()` method for ' 'serializer `{module}.{class_name}`, or set `read_only=True` on ' 'dotted-source serializer fields.'.format( method_name=method_name, module=serializer.__class__.__module__, class_name=serializer.__class__.__name__ ) )
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:threenum; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:h5file; 5, identifier:var; 6, default_parameter; 6, 7; 6, 8; 7, identifier:post_col; 8, string:'mult'; 9, block; 9, 10; 9, 20; 9, 26; 9, 32; 9, 40; 9, 48; 9, 60; 9, 71; 9, 75; 9, 79; 9, 205; 9, 211; 9, 220; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:f; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:h5py; 16, identifier:File; 17, argument_list; 17, 18; 17, 19; 18, identifier:h5file; 19, string:'r'; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:d; 23, subscript; 23, 24; 23, 25; 24, identifier:f; 25, identifier:var; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:w; 29, subscript; 29, 30; 29, 31; 30, identifier:f; 31, identifier:post_col; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:s; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:d; 38, identifier:chunks; 39, integer:0; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:n; 43, subscript; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:d; 46, identifier:shape; 47, integer:0; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:maxval; 51, unary_operator:-; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:np; 55, identifier:abs; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:d; 59, integer:0; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:minval; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:np; 66, identifier:abs; 67, argument_list; 67, 68; 68, subscript; 68, 69; 68, 70; 69, identifier:d; 70, integer:0; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:total; 74, integer:0; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:wsum; 78, integer:0; 79, for_statement; 79, 80; 79, 81; 79, 87; 80, identifier:x; 81, call; 81, 82; 81, 83; 82, identifier:range; 83, argument_list; 83, 84; 83, 85; 83, 86; 84, integer:0; 85, identifier:n; 86, identifier:s; 87, block; 87, 88; 87, 123; 87, 136; 87, 149; 87, 158; 87, 167; 87, 176; 87, 185; 87, 196; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:aN; 91, unary_operator:~; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:np; 95, identifier:logical_or; 96, argument_list; 96, 97; 96, 110; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:np; 100, identifier:isnan; 101, argument_list; 101, 102; 102, subscript; 102, 103; 102, 104; 103, identifier:d; 104, slice; 104, 105; 104, 106; 104, 107; 105, identifier:x; 106, colon; 107, binary_operator:+; 107, 108; 107, 109; 108, identifier:x; 109, identifier:s; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:np; 113, identifier:isinf; 114, argument_list; 114, 115; 115, subscript; 115, 116; 115, 117; 116, identifier:d; 117, slice; 117, 118; 117, 119; 117, 120; 118, identifier:x; 119, colon; 120, binary_operator:+; 120, 121; 120, 122; 121, identifier:x; 122, identifier:s; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:d_c; 126, subscript; 126, 127; 126, 135; 127, subscript; 127, 128; 127, 129; 128, identifier:d; 129, slice; 129, 130; 129, 131; 129, 132; 130, identifier:x; 131, colon; 132, binary_operator:+; 132, 133; 132, 134; 133, identifier:x; 134, identifier:s; 135, identifier:aN; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:w_c; 139, subscript; 139, 140; 139, 148; 140, subscript; 140, 141; 140, 142; 141, identifier:w; 142, slice; 142, 143; 142, 144; 142, 145; 143, identifier:x; 144, colon; 145, binary_operator:+; 145, 146; 145, 147; 146, identifier:x; 147, identifier:s; 148, identifier:aN; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:chunk_max; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:np; 155, identifier:max; 156, argument_list; 156, 157; 157, identifier:d_c; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:chunk_min; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:np; 164, identifier:min; 165, argument_list; 165, 166; 166, identifier:d_c; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:maxval; 170, conditional_expression:if; 170, 171; 170, 172; 170, 175; 171, identifier:chunk_max; 172, comparison_operator:>; 172, 173; 172, 174; 173, identifier:chunk_max; 174, identifier:maxval; 175, identifier:maxval; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:minval; 179, conditional_expression:if; 179, 180; 179, 181; 179, 184; 180, identifier:chunk_min; 181, comparison_operator:<; 181, 182; 181, 183; 182, identifier:chunk_min; 183, identifier:minval; 184, identifier:minval; 185, expression_statement; 185, 186; 186, augmented_assignment:+=; 186, 187; 186, 188; 187, identifier:total; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:np; 191, identifier:sum; 192, argument_list; 192, 193; 193, binary_operator:*; 193, 194; 193, 195; 194, identifier:w_c; 195, identifier:d_c; 196, expression_statement; 196, 197; 197, augmented_assignment:+=; 197, 198; 197, 199; 198, identifier:wsum; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:np; 202, identifier:sum; 203, argument_list; 203, 204; 204, identifier:w_c; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:f; 209, identifier:close; 210, argument_list; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:mean; 214, binary_operator:/; 214, 215; 214, 216; 215, identifier:total; 216, call; 216, 217; 216, 218; 217, identifier:float; 218, argument_list; 218, 219; 219, identifier:wsum; 220, return_statement; 220, 221; 221, tuple; 221, 222; 221, 223; 221, 224; 222, identifier:minval; 223, identifier:maxval; 224, identifier:mean
def threenum(h5file, var, post_col='mult'): f = h5py.File(h5file, 'r') d = f[var] w = f[post_col] s = d.chunks[0] n = d.shape[0] maxval = -np.abs(d[0]) minval = np.abs(d[0]) total = 0 wsum = 0 for x in range(0, n, s): aN = ~np.logical_or(np.isnan(d[x:x+s]), np.isinf(d[x:x+s])) d_c = d[x:x+s][aN] w_c = w[x:x+s][aN] chunk_max = np.max(d_c) chunk_min = np.min(d_c) maxval = chunk_max if chunk_max > maxval else maxval minval = chunk_min if chunk_min < minval else minval total += np.sum(w_c*d_c) wsum += np.sum(w_c) f.close() mean = total/float(wsum) return (minval, maxval, mean)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:_filter_keys; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:content_id; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:prefix; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:subtopic_id; 13, None; 14, block; 14, 15; 14, 17; 14, 126; 15, expression_statement; 15, 16; 16, string:'''Filter out-of-order labels by key tuple. :class:`Label` always sorts by `(cid1,cid2,sid1,sid2)`, but for efficient lookups on `cid2` this class also stores in order `(cid2,cid1,sid2,sid1)`. Filter out things that are in the wrong order. But, if an original query specified `content_id` or `subtopic_id`, account for the possibility that something might be apparently out-of-order but its dual will not be in the query at all. '''; 17, function_definition; 17, 18; 17, 19; 17, 21; 18, function_name:accept; 19, parameters; 19, 20; 20, identifier:kvp; 21, block; 21, 22; 21, 34; 21, 50; 21, 90; 21, 106; 21, 113; 21, 124; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 31; 24, tuple_pattern; 24, 25; 24, 26; 24, 27; 24, 28; 24, 29; 24, 30; 25, identifier:content_id1; 26, identifier:content_id2; 27, identifier:subtopic_id1; 28, identifier:subtopic_id2; 29, identifier:annotator_id; 30, identifier:inverted_epoch_ticks; 31, subscript; 31, 32; 31, 33; 32, identifier:kvp; 33, integer:0; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:is_sorted; 37, parenthesized_expression; 37, 38; 38, boolean_operator:or; 38, 39; 38, 42; 39, comparison_operator:<; 39, 40; 39, 41; 40, identifier:content_id1; 41, identifier:content_id2; 42, parenthesized_expression; 42, 43; 43, boolean_operator:and; 43, 44; 43, 47; 44, comparison_operator:==; 44, 45; 44, 46; 45, identifier:content_id1; 46, identifier:content_id2; 47, comparison_operator:<=; 47, 48; 47, 49; 48, identifier:subtopic_id1; 49, identifier:subtopic_id2; 50, if_statement; 50, 51; 50, 54; 50, 59; 50, 84; 51, comparison_operator:is; 51, 52; 51, 53; 52, identifier:content_id; 53, None; 54, block; 54, 55; 55, assert_statement; 55, 56; 56, comparison_operator:==; 56, 57; 56, 58; 57, identifier:content_id1; 58, identifier:content_id; 59, elif_clause; 59, 60; 59, 63; 60, comparison_operator:is; 60, 61; 60, 62; 61, identifier:prefix; 62, None; 63, block; 63, 64; 63, 71; 64, assert_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:content_id1; 68, identifier:startswith; 69, argument_list; 69, 70; 70, identifier:prefix; 71, if_statement; 71, 72; 71, 81; 72, boolean_operator:and; 72, 73; 72, 79; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:content_id2; 76, identifier:startswith; 77, argument_list; 77, 78; 78, identifier:prefix; 79, not_operator; 79, 80; 80, identifier:is_sorted; 81, block; 81, 82; 82, return_statement; 82, 83; 83, False; 84, elif_clause; 84, 85; 84, 87; 85, not_operator; 85, 86; 86, identifier:is_sorted; 87, block; 87, 88; 88, return_statement; 88, 89; 89, False; 90, if_statement; 90, 91; 90, 94; 91, comparison_operator:is; 91, 92; 91, 93; 92, identifier:subtopic_id; 93, None; 94, block; 94, 95; 94, 102; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:!=; 96, 97; 96, 98; 97, identifier:content_id2; 98, identifier:content_id; 99, block; 99, 100; 100, return_statement; 100, 101; 101, True; 102, return_statement; 102, 103; 103, comparison_operator:<=; 103, 104; 103, 105; 104, identifier:subtopic_id1; 105, identifier:subtopic_id2; 106, if_statement; 106, 107; 106, 110; 107, comparison_operator:==; 107, 108; 107, 109; 108, identifier:subtopic_id; 109, identifier:subtopic_id1; 110, block; 110, 111; 111, return_statement; 111, 112; 112, True; 113, if_statement; 113, 114; 113, 121; 114, boolean_operator:and; 114, 115; 114, 118; 115, comparison_operator:==; 115, 116; 115, 117; 116, identifier:content_id; 117, identifier:content_id2; 118, comparison_operator:==; 118, 119; 118, 120; 119, identifier:subtopic_id; 120, identifier:subtopic_id2; 121, block; 121, 122; 122, return_statement; 122, 123; 123, True; 124, return_statement; 124, 125; 125, False; 126, return_statement; 126, 127; 127, identifier:accept
def _filter_keys(self, content_id=None, prefix=None, subtopic_id=None): '''Filter out-of-order labels by key tuple. :class:`Label` always sorts by `(cid1,cid2,sid1,sid2)`, but for efficient lookups on `cid2` this class also stores in order `(cid2,cid1,sid2,sid1)`. Filter out things that are in the wrong order. But, if an original query specified `content_id` or `subtopic_id`, account for the possibility that something might be apparently out-of-order but its dual will not be in the query at all. ''' def accept(kvp): (content_id1, content_id2, subtopic_id1, subtopic_id2, annotator_id, inverted_epoch_ticks) = kvp[0] is_sorted = (content_id1 < content_id2 or (content_id1 == content_id2 and subtopic_id1 <= subtopic_id2)) if content_id is not None: assert content_id1 == content_id elif prefix is not None: assert content_id1.startswith(prefix) if content_id2.startswith(prefix) and not is_sorted: return False elif not is_sorted: return False if subtopic_id is None: if content_id2 != content_id: return True return subtopic_id1 <= subtopic_id2 if subtopic_id == subtopic_id1: return True if content_id == content_id2 and subtopic_id == subtopic_id2: return True return False return accept
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:topological_sorting; 3, parameters; 3, 4; 3, 5; 4, identifier:nodes; 5, identifier:relations; 6, block; 6, 7; 6, 9; 6, 13; 6, 25; 6, 32; 6, 39; 6, 47; 6, 110; 6, 135; 7, expression_statement; 7, 8; 8, string:'''An implementation of Kahn's algorithm. '''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:ret; 12, list:[]; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:nodes; 16, binary_operator:|; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:set; 19, argument_list; 19, 20; 20, identifier:nodes; 21, call; 21, 22; 21, 23; 22, identifier:_nodes; 23, argument_list; 23, 24; 24, identifier:relations; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:inc; 28, call; 28, 29; 28, 30; 29, identifier:_incoming; 30, argument_list; 30, 31; 31, identifier:relations; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:out; 35, call; 35, 36; 35, 37; 36, identifier:_outgoing; 37, argument_list; 37, 38; 38, identifier:relations; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:free; 42, call; 42, 43; 42, 44; 43, identifier:_free_nodes; 44, argument_list; 44, 45; 44, 46; 45, identifier:nodes; 46, identifier:inc; 47, while_statement; 47, 48; 47, 49; 48, identifier:free; 49, block; 49, 50; 49, 58; 49, 65; 49, 74; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:n; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:free; 56, identifier:pop; 57, argument_list; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:ret; 62, identifier:append; 63, argument_list; 63, 64; 64, identifier:n; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:out_n; 68, call; 68, 69; 68, 70; 69, identifier:list; 70, argument_list; 70, 71; 71, subscript; 71, 72; 71, 73; 72, identifier:out; 73, identifier:n; 74, for_statement; 74, 75; 74, 76; 74, 77; 75, identifier:m; 76, identifier:out_n; 77, block; 77, 78; 77, 87; 77, 96; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:out; 83, identifier:n; 84, identifier:remove; 85, argument_list; 85, 86; 86, identifier:m; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:inc; 92, identifier:m; 93, identifier:remove; 94, argument_list; 94, 95; 95, identifier:n; 96, if_statement; 96, 97; 96, 102; 97, call; 97, 98; 97, 99; 98, identifier:_is_free; 99, argument_list; 99, 100; 99, 101; 100, identifier:m; 101, identifier:inc; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:free; 107, identifier:add; 108, argument_list; 108, 109; 109, identifier:m; 110, if_statement; 110, 111; 110, 129; 111, not_operator; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:all; 114, generator_expression; 114, 115; 114, 126; 115, boolean_operator:and; 115, 116; 115, 121; 116, call; 116, 117; 116, 118; 117, identifier:_is_free; 118, argument_list; 118, 119; 118, 120; 119, identifier:node; 120, identifier:inc; 121, call; 121, 122; 121, 123; 122, identifier:_is_free; 123, argument_list; 123, 124; 123, 125; 124, identifier:node; 125, identifier:out; 126, for_in_clause; 126, 127; 126, 128; 127, identifier:node; 128, identifier:nodes; 129, block; 129, 130; 130, raise_statement; 130, 131; 131, call; 131, 132; 131, 133; 132, identifier:ValueError; 133, argument_list; 133, 134; 134, string:"Cycle detected"; 135, return_statement; 135, 136; 136, identifier:ret
def topological_sorting(nodes, relations): '''An implementation of Kahn's algorithm. ''' ret = [] nodes = set(nodes) | _nodes(relations) inc = _incoming(relations) out = _outgoing(relations) free = _free_nodes(nodes, inc) while free: n = free.pop() ret.append(n) out_n = list(out[n]) for m in out_n: out[n].remove(m) inc[m].remove(n) if _is_free(m, inc): free.add(m) if not all(_is_free(node, inc) and _is_free(node, out) for node in nodes): raise ValueError("Cycle detected") return ret
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:solve_resource; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:value; 6, identifier:resource; 7, block; 7, 8; 7, 31; 8, for_statement; 8, 9; 8, 10; 8, 16; 9, identifier:solver; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:get_resource_solvers; 14, argument_list; 14, 15; 15, identifier:resource; 16, block; 16, 17; 17, try_statement; 17, 18; 17, 27; 18, block; 18, 19; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:solver; 23, identifier:solve; 24, argument_list; 24, 25; 24, 26; 25, identifier:value; 26, identifier:resource; 27, except_clause; 27, 28; 27, 29; 28, identifier:CannotSolve; 29, block; 29, 30; 30, continue_statement; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:SolveFailure; 34, argument_list; 34, 35; 34, 36; 34, 37; 35, identifier:self; 36, identifier:resource; 37, identifier:value
def solve_resource(self, value, resource): for solver in self.get_resource_solvers(resource): try: return solver.solve(value, resource) except CannotSolve: continue raise SolveFailure(self, resource, value)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:incrementName; 3, parameters; 3, 4; 3, 5; 4, identifier:nameList; 5, identifier:name; 6, block; 6, 7; 6, 14; 6, 23; 6, 67; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:not; 8, 9; 8, 10; 9, identifier:name; 10, identifier:nameList; 11, block; 11, 12; 12, return_statement; 12, 13; 13, identifier:name; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:newName; 17, binary_operator:+; 17, 18; 17, 19; 18, identifier:name; 19, call; 19, 20; 19, 21; 20, identifier:str; 21, argument_list; 21, 22; 22, integer:1; 23, for_statement; 23, 24; 23, 25; 23, 35; 24, identifier:n; 25, call; 25, 26; 25, 27; 26, identifier:range; 27, argument_list; 27, 28; 27, 29; 28, integer:1; 29, binary_operator:+; 29, 30; 29, 34; 30, call; 30, 31; 30, 32; 31, identifier:len; 32, argument_list; 32, 33; 33, identifier:nameList; 34, integer:2; 35, block; 35, 36; 35, 40; 35, 62; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:found; 39, False; 40, for_statement; 40, 41; 40, 42; 40, 43; 41, identifier:b; 42, identifier:nameList; 43, block; 43, 44; 43, 53; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:newName; 47, binary_operator:+; 47, 48; 47, 49; 48, identifier:name; 49, call; 49, 50; 49, 51; 50, identifier:str; 51, argument_list; 51, 52; 52, identifier:n; 53, if_statement; 53, 54; 53, 57; 54, comparison_operator:==; 54, 55; 54, 56; 55, identifier:b; 56, identifier:newName; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:found; 61, True; 62, if_statement; 62, 63; 62, 65; 63, not_operator; 63, 64; 64, identifier:found; 65, block; 65, 66; 66, break_statement; 67, return_statement; 67, 68; 68, identifier:newName
def incrementName(nameList, name): if name not in nameList: return name newName = name + str(1) for n in range(1, len(nameList) + 2): found = False for b in nameList: newName = name + str(n) if b == newName: found = True if not found: break return newName
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:polylines; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 10; 6, 14; 7, pattern_list; 7, 8; 7, 9; 8, identifier:n; 9, identifier:c; 10, call; 10, 11; 10, 12; 11, identifier:enumerate; 12, argument_list; 12, 13; 13, identifier:polylines; 14, block; 14, 15; 14, 22; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:l; 18, call; 18, 19; 18, 20; 19, identifier:len; 20, argument_list; 20, 21; 21, identifier:c; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:>; 23, 24; 23, 25; 24, identifier:l; 25, integer:2; 26, block; 26, 27; 26, 38; 26, 45; 26, 56; 26, 65; 26, 76; 26, 112; 26, 119; 26, 128; 26, 137; 26, 143; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:mid; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:c; 33, identifier:mean; 34, argument_list; 34, 35; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:axis; 37, integer:0; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:distV; 41, parenthesized_expression; 41, 42; 42, binary_operator:-; 42, 43; 42, 44; 43, identifier:c; 44, identifier:mid; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:dists; 48, call; 48, 49; 48, 50; 49, identifier:norm; 50, argument_list; 50, 51; 50, 52; 51, identifier:distV; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:axis; 54, unary_operator:-; 54, 55; 55, integer:1; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:firstI; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:np; 62, identifier:argmax; 63, argument_list; 63, 64; 64, identifier:dists; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:sign; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:np; 71, identifier:sign; 72, argument_list; 72, 73; 73, subscript; 73, 74; 73, 75; 74, identifier:distV; 75, identifier:firstI; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:dd; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:np; 82, identifier:logical_or; 83, argument_list; 83, 84; 83, 98; 84, comparison_operator:!=; 84, 85; 84, 95; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:np; 88, identifier:sign; 89, argument_list; 89, 90; 90, subscript; 90, 91; 90, 92; 90, 94; 91, identifier:distV; 92, slice; 92, 93; 93, colon; 94, integer:0; 95, subscript; 95, 96; 95, 97; 96, identifier:sign; 97, integer:0; 98, comparison_operator:!=; 98, 99; 98, 109; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:np; 102, identifier:sign; 103, argument_list; 103, 104; 104, subscript; 104, 105; 104, 106; 104, 108; 105, identifier:distV; 106, slice; 106, 107; 107, colon; 108, integer:1; 109, subscript; 109, 110; 109, 111; 110, identifier:sign; 111, integer:1; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 118; 114, subscript; 114, 115; 114, 116; 115, identifier:dists; 116, unary_operator:~; 116, 117; 117, identifier:dd; 118, integer:0; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:lastI; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:np; 125, identifier:argmax; 126, argument_list; 126, 127; 127, identifier:dists; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:ind; 131, call; 131, 132; 131, 133; 132, identifier:_sort; 133, argument_list; 133, 134; 133, 135; 133, 136; 134, identifier:c; 135, identifier:firstI; 136, identifier:lastI; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:c; 140, subscript; 140, 141; 140, 142; 141, identifier:c; 142, identifier:ind; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:polylines; 147, identifier:n; 148, identifier:c
def sort(polylines): for n, c in enumerate(polylines): l = len(c) if l > 2: mid = c.mean(axis=0) distV = (c - mid) dists = norm(distV, axis=-1) firstI = np.argmax(dists) sign = np.sign(distV[firstI]) dd = np.logical_or(np.sign(distV[:, 0]) != sign[0], np.sign(distV[:, 1]) != sign[1]) dists[~dd] = 0 lastI = np.argmax(dists) ind = _sort(c, firstI, lastI) c = c[ind] polylines[n] = c
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_queryset; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 18; 5, 34; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:queryset; 9, call; 9, 10; 9, 17; 10, attribute; 10, 11; 10, 16; 11, call; 11, 12; 11, 13; 12, identifier:super; 13, argument_list; 13, 14; 13, 15; 14, identifier:MostVotedManager; 15, identifier:self; 16, identifier:get_queryset; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:sql; 21, assignment; 21, 22; 21, 23; 22, identifier:messages; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:queryset; 26, identifier:extra; 27, argument_list; 27, 28; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:select; 30, dictionary; 30, 31; 31, pair; 31, 32; 31, 33; 32, string:'vote_count'; 33, identifier:sql; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:messages; 38, identifier:order_by; 39, argument_list; 39, 40; 39, 41; 40, string:'-vote_count'; 41, string:'received_time'
def get_queryset(self): queryset = super(MostVotedManager, self).get_queryset() sql = messages = queryset.extra( select={ 'vote_count': sql, } ) return messages.order_by('-vote_count', 'received_time')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:deleteByOrigIndex; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:index; 6, block; 6, 7; 6, 11; 6, 15; 6, 53; 6, 59; 6, 65; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:result; 10, list:[]; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:result_tracker; 14, list:[]; 15, for_statement; 15, 16; 15, 19; 15, 25; 16, pattern_list; 16, 17; 16, 18; 17, identifier:counter; 18, identifier:row; 19, call; 19, 20; 19, 21; 20, identifier:enumerate; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:table; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 34; 27, comparison_operator:!=; 27, 28; 27, 33; 28, subscript; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:index_track; 32, identifier:counter; 33, identifier:index; 34, block; 34, 35; 34, 42; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:result; 39, identifier:append; 40, argument_list; 40, 41; 41, identifier:row; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:result_tracker; 46, identifier:append; 47, argument_list; 47, 48; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:index_track; 52, identifier:counter; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:table; 58, identifier:result; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:index_track; 64, identifier:result_tracker; 65, return_statement; 65, 66; 66, identifier:self
def deleteByOrigIndex(self, index): result = [] result_tracker = [] for counter, row in enumerate(self.table): if self.index_track[counter] != index: result.append(row) result_tracker.append(self.index_track[counter]) self.table = result self.index_track = result_tracker return self
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:deleteByOrigIndexList; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:indexList; 6, block; 6, 7; 6, 11; 6, 15; 6, 19; 6, 53; 6, 59; 6, 65; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:result; 10, list:[]; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:result_tracker; 14, list:[]; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:counter; 18, integer:0; 19, for_statement; 19, 20; 19, 21; 19, 24; 20, identifier:row; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:table; 24, block; 24, 25; 24, 49; 25, if_statement; 25, 26; 25, 30; 26, not_operator; 26, 27; 27, comparison_operator:in; 27, 28; 27, 29; 28, identifier:counter; 29, identifier:indexList; 30, block; 30, 31; 30, 38; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:result; 35, identifier:append; 36, argument_list; 36, 37; 37, identifier:row; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:result_tracker; 42, identifier:append; 43, argument_list; 43, 44; 44, subscript; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:index_track; 48, identifier:counter; 49, expression_statement; 49, 50; 50, augmented_assignment:+=; 50, 51; 50, 52; 51, identifier:counter; 52, integer:1; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:table; 58, identifier:result; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:index_track; 64, identifier:result_tracker; 65, return_statement; 65, 66; 66, identifier:self
def deleteByOrigIndexList(self, indexList): result = [] result_tracker = [] counter = 0 for row in self.table: if not counter in indexList: result.append(row) result_tracker.append(self.index_track[counter]) counter += 1 self.table = result self.index_track = result_tracker return self
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reverse; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:none_greater; 11, False; 12, block; 12, 13; 12, 15; 12, 128; 13, expression_statement; 13, 14; 14, string:'''Sort the list in the order of the dictionary key. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "wigs": 68 }, ... {"name": "Larry", "age": 18, "wigs": [3, 2, 9]}, ... {"name": "Joe", "age": 20, "income": 15000, "wigs": [1, 2, 3]}, ... {"name": "Bill", "age": 19, "income": 29000 }, ... ] >>> print PLOD(test).sort("name").returnString() [ {age: 19, income: 29000, name: 'Bill' , wigs: None }, {age: 18, income: 93000, name: 'Jim' , wigs: 68}, {age: 20, income: 15000, name: 'Joe' , wigs: [1, 2, 3]}, {age: 18, income: None , name: 'Larry', wigs: [3, 2, 9]} ] >>> print PLOD(test).sort("income").returnString() [ {age: 18, income: None , name: 'Larry', wigs: [3, 2, 9]}, {age: 20, income: 15000, name: 'Joe' , wigs: [1, 2, 3]}, {age: 19, income: 29000, name: 'Bill' , wigs: None }, {age: 18, income: 93000, name: 'Jim' , wigs: 68} ] >>> print PLOD(test).sort(["age", "income"]).returnString() [ {age: 18, income: None , name: 'Larry', wigs: [3, 2, 9]}, {age: 18, income: 93000, name: 'Jim' , wigs: 68}, {age: 19, income: 29000, name: 'Bill' , wigs: None }, {age: 20, income: 15000, name: 'Joe' , wigs: [1, 2, 3]} ] .. versionadded:: 0.0.2 :param key: A dictionary key (or a list of keys) that should be the basis of the sorting. :param reverse: Defaults to False. If True, then list is sorted decrementally. :param none_greater: Defaults to False. If True, then entries missing the key/value pair are considered be of greater value than the non-missing values. :returns: self '''; 15, for_statement; 15, 16; 15, 17; 15, 27; 16, identifier:i; 17, call; 17, 18; 17, 19; 18, identifier:range; 19, argument_list; 19, 20; 19, 21; 20, integer:0; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:table; 27, block; 27, 28; 27, 32; 27, 75; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:min; 31, identifier:i; 32, for_statement; 32, 33; 32, 34; 32, 46; 33, identifier:j; 34, call; 34, 35; 34, 36; 35, identifier:range; 36, argument_list; 36, 37; 36, 40; 37, binary_operator:+; 37, 38; 37, 39; 38, identifier:i; 39, integer:1; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:table; 46, block; 46, 47; 47, if_statement; 47, 48; 47, 70; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:internal; 51, identifier:is_first_lessor; 52, argument_list; 52, 53; 52, 58; 52, 63; 52, 64; 52, 67; 53, subscript; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:table; 57, identifier:j; 58, subscript; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:table; 62, identifier:min; 63, identifier:key; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:none_greater; 66, identifier:none_greater; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:reverse; 69, identifier:reverse; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:min; 74, identifier:j; 75, if_statement; 75, 76; 75, 79; 76, comparison_operator:!=; 76, 77; 76, 78; 77, identifier:i; 78, identifier:min; 79, block; 79, 80; 79, 104; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 93; 82, pattern_list; 82, 83; 82, 88; 83, subscript; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:table; 87, identifier:i; 88, subscript; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:table; 92, identifier:min; 93, expression_list; 93, 94; 93, 99; 94, subscript; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:table; 98, identifier:min; 99, subscript; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:table; 103, identifier:i; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 117; 106, pattern_list; 106, 107; 106, 112; 107, subscript; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:index_track; 111, identifier:i; 112, subscript; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:index_track; 116, identifier:min; 117, expression_list; 117, 118; 117, 123; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:index_track; 122, identifier:min; 123, subscript; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:index_track; 127, identifier:i; 128, return_statement; 128, 129; 129, identifier:self
def sort(self, key, reverse=False, none_greater=False): '''Sort the list in the order of the dictionary key. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "wigs": 68 }, ... {"name": "Larry", "age": 18, "wigs": [3, 2, 9]}, ... {"name": "Joe", "age": 20, "income": 15000, "wigs": [1, 2, 3]}, ... {"name": "Bill", "age": 19, "income": 29000 }, ... ] >>> print PLOD(test).sort("name").returnString() [ {age: 19, income: 29000, name: 'Bill' , wigs: None }, {age: 18, income: 93000, name: 'Jim' , wigs: 68}, {age: 20, income: 15000, name: 'Joe' , wigs: [1, 2, 3]}, {age: 18, income: None , name: 'Larry', wigs: [3, 2, 9]} ] >>> print PLOD(test).sort("income").returnString() [ {age: 18, income: None , name: 'Larry', wigs: [3, 2, 9]}, {age: 20, income: 15000, name: 'Joe' , wigs: [1, 2, 3]}, {age: 19, income: 29000, name: 'Bill' , wigs: None }, {age: 18, income: 93000, name: 'Jim' , wigs: 68} ] >>> print PLOD(test).sort(["age", "income"]).returnString() [ {age: 18, income: None , name: 'Larry', wigs: [3, 2, 9]}, {age: 18, income: 93000, name: 'Jim' , wigs: 68}, {age: 19, income: 29000, name: 'Bill' , wigs: None }, {age: 20, income: 15000, name: 'Joe' , wigs: [1, 2, 3]} ] .. versionadded:: 0.0.2 :param key: A dictionary key (or a list of keys) that should be the basis of the sorting. :param reverse: Defaults to False. If True, then list is sorted decrementally. :param none_greater: Defaults to False. If True, then entries missing the key/value pair are considered be of greater value than the non-missing values. :returns: self ''' for i in range(0, len(self.table)): min = i for j in range(i + 1, len(self.table)): if internal.is_first_lessor(self.table[j], self.table[min], key, none_greater=none_greater, reverse=reverse): min = j if i!=min: self.table[i], self.table[min] = self.table[min], self.table[i] self.index_track[i], self.index_track[min] = self.index_track[min], self.index_track[i] return self
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:returnIndexList; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:limit; 7, False; 8, block; 8, 9; 8, 11; 8, 20; 8, 24; 8, 52; 9, expression_statement; 9, 10; 10, string:'''Return a list of integers that are list-index references to the original list of dictionaries." Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "order": 2}, ... {"name": "Larry", "age": 18, "order": 3}, ... {"name": "Joe", "age": 20, "income": 15000, "order": 1}, ... {"name": "Bill", "age": 19, "income": 29000, "order": 4}, ... ] >>> print PLOD(test).returnIndexList() [0, 1, 2, 3] >>> print PLOD(test).sort("name").returnIndexList() [3, 0, 2, 1] :param limit: A number limiting the quantity of entries to return. Defaults to False, which means that the full list is returned. :return: A list of integers representing the original indices. '''; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:==; 12, 13; 12, 14; 13, identifier:limit; 14, False; 15, block; 15, 16; 16, return_statement; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:index_track; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:result; 23, list:[]; 24, for_statement; 24, 25; 24, 26; 24, 30; 25, identifier:i; 26, call; 26, 27; 26, 28; 27, identifier:range; 28, argument_list; 28, 29; 29, identifier:limit; 30, block; 30, 31; 31, if_statement; 31, 32; 31, 40; 32, comparison_operator:>; 32, 33; 32, 39; 33, call; 33, 34; 33, 35; 34, identifier:len; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:table; 39, identifier:i; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:result; 45, identifier:append; 46, argument_list; 46, 47; 47, subscript; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:index_track; 51, identifier:i; 52, return_statement; 52, 53; 53, identifier:result
def returnIndexList(self, limit=False): '''Return a list of integers that are list-index references to the original list of dictionaries." Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "order": 2}, ... {"name": "Larry", "age": 18, "order": 3}, ... {"name": "Joe", "age": 20, "income": 15000, "order": 1}, ... {"name": "Bill", "age": 19, "income": 29000, "order": 4}, ... ] >>> print PLOD(test).returnIndexList() [0, 1, 2, 3] >>> print PLOD(test).sort("name").returnIndexList() [3, 0, 2, 1] :param limit: A number limiting the quantity of entries to return. Defaults to False, which means that the full list is returned. :return: A list of integers representing the original indices. ''' if limit==False: return self.index_track result = [] for i in range(limit): if len(self.table)>i: result.append(self.index_track[i]) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:returnValue; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:last; 8, False; 9, block; 9, 10; 9, 12; 9, 23; 9, 29; 9, 38; 10, expression_statement; 10, 11; 11, string:'''Return the key's value for the first entry in the current list. If 'last=True', then the last entry is referenced." Returns None is the list is empty or the key is missing. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "order": 2}, ... {"name": "Larry", "age": 18, "order": 3}, ... {"name": "Joe", "age": 20, "income": 15000, "order": 1}, ... {"name": "Bill", "age": 19, "income": 29000, "order": 4}, ... ] >>> print PLOD(test).returnValue("name") Jim >>> print PLOD(test).sort("name").returnValue("name", last=True) Larry >>> print PLOD(test).sort("name").returnValue("income", last=True) None :param last: If True, the last entry is used rather than the first. :return: A value, or None if the list is empty or the key is missing. '''; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:row; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:returnOneEntry; 19, argument_list; 19, 20; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:last; 22, identifier:last; 23, if_statement; 23, 24; 23, 26; 24, not_operator; 24, 25; 25, identifier:row; 26, block; 26, 27; 27, return_statement; 27, 28; 28, None; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:dict_row; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:internal; 35, identifier:convert_to_dict; 36, argument_list; 36, 37; 37, identifier:row; 38, return_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:dict_row; 42, identifier:get; 43, argument_list; 43, 44; 43, 45; 44, identifier:key; 45, None
def returnValue(self, key, last=False): '''Return the key's value for the first entry in the current list. If 'last=True', then the last entry is referenced." Returns None is the list is empty or the key is missing. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "order": 2}, ... {"name": "Larry", "age": 18, "order": 3}, ... {"name": "Joe", "age": 20, "income": 15000, "order": 1}, ... {"name": "Bill", "age": 19, "income": 29000, "order": 4}, ... ] >>> print PLOD(test).returnValue("name") Jim >>> print PLOD(test).sort("name").returnValue("name", last=True) Larry >>> print PLOD(test).sort("name").returnValue("income", last=True) None :param last: If True, the last entry is used rather than the first. :return: A value, or None if the list is empty or the key is missing. ''' row = self.returnOneEntry(last=last) if not row: return None dict_row = internal.convert_to_dict(row) return dict_row.get(key, None)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:returnValueList; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key_list; 6, default_parameter; 6, 7; 6, 8; 7, identifier:last; 8, False; 9, block; 9, 10; 9, 12; 9, 16; 9, 27; 9, 33; 9, 42; 9, 59; 10, expression_statement; 10, 11; 11, string:'''Return a list of key values for the first entry in the current list. If 'last=True', then the last entry is referenced." Returns None is the list is empty. If a key is missing, then that entry in the list is None. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "order": 2}, ... {"name": "Larry", "age": 18, "order": 3}, ... {"name": "Joe", "age": 20, "income": 15000, "order": 1}, ... {"name": "Bill", "age": 19, "income": 29000, "order": 4}, ... ] >>> print PLOD(test).returnValueList(["name", "income"]) ['Jim', 93000] >>> print PLOD(test).sort("name").returnValueList(["name", "income"], last=True) ['Larry', None] :param last: If True, the last entry is used rather than the first. :return: A value, or None if the list is empty. '''; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:result; 15, list:[]; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:row; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:returnOneEntry; 23, argument_list; 23, 24; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:last; 26, identifier:last; 27, if_statement; 27, 28; 27, 30; 28, not_operator; 28, 29; 29, identifier:row; 30, block; 30, 31; 31, return_statement; 31, 32; 32, None; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:dict_row; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:internal; 39, identifier:convert_to_dict; 40, argument_list; 40, 41; 41, identifier:row; 42, for_statement; 42, 43; 42, 44; 42, 45; 43, identifier:field; 44, identifier:key_list; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:result; 50, identifier:append; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:dict_row; 55, identifier:get; 56, argument_list; 56, 57; 56, 58; 57, identifier:field; 58, None; 59, return_statement; 59, 60; 60, identifier:result
def returnValueList(self, key_list, last=False): '''Return a list of key values for the first entry in the current list. If 'last=True', then the last entry is referenced." Returns None is the list is empty. If a key is missing, then that entry in the list is None. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "order": 2}, ... {"name": "Larry", "age": 18, "order": 3}, ... {"name": "Joe", "age": 20, "income": 15000, "order": 1}, ... {"name": "Bill", "age": 19, "income": 29000, "order": 4}, ... ] >>> print PLOD(test).returnValueList(["name", "income"]) ['Jim', 93000] >>> print PLOD(test).sort("name").returnValueList(["name", "income"], last=True) ['Larry', None] :param last: If True, the last entry is used rather than the first. :return: A value, or None if the list is empty. ''' result = [] row = self.returnOneEntry(last=last) if not row: return None dict_row = internal.convert_to_dict(row) for field in key_list: result.append(dict_row.get(field, None)) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_seq_records; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:seq_records; 6, block; 6, 7; 6, 25; 6, 38; 6, 45; 6, 61; 6, 74; 6, 81; 6, 97; 6, 101; 6, 138; 7, for_statement; 7, 8; 7, 9; 7, 10; 8, identifier:seq_record; 9, identifier:seq_records; 10, block; 10, 11; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:seq_record; 15, identifier:voucher_code; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:seq_record; 20, identifier:voucher_code; 21, identifier:replace; 22, argument_list; 22, 23; 22, 24; 23, string:"-"; 24, string:"_"; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:unsorted_gene_codes; 28, call; 28, 29; 28, 30; 29, identifier:set; 30, argument_list; 30, 31; 31, list_comprehension; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:i; 34, identifier:gene_code; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:i; 37, identifier:seq_records; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:sorted_gene_codes; 41, call; 41, 42; 41, 43; 42, identifier:list; 43, argument_list; 43, 44; 44, identifier:unsorted_gene_codes; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:sorted_gene_codes; 49, identifier:sort; 50, argument_list; 50, 51; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:key; 53, lambda; 53, 54; 53, 56; 54, lambda_parameters; 54, 55; 55, identifier:x; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:x; 59, identifier:lower; 60, argument_list; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:unsorted_voucher_codes; 64, call; 64, 65; 64, 66; 65, identifier:set; 66, argument_list; 66, 67; 67, list_comprehension; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:i; 70, identifier:voucher_code; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:i; 73, identifier:seq_records; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:sorted_voucher_codes; 77, call; 77, 78; 77, 79; 78, identifier:list; 79, argument_list; 79, 80; 80, identifier:unsorted_voucher_codes; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:sorted_voucher_codes; 85, identifier:sort; 86, argument_list; 86, 87; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:key; 89, lambda; 89, 90; 89, 92; 90, lambda_parameters; 90, 91; 91, identifier:x; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:x; 95, identifier:lower; 96, argument_list; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:sorted_seq_records; 100, list:[]; 101, for_statement; 101, 102; 101, 103; 101, 104; 102, identifier:gene_code; 103, identifier:sorted_gene_codes; 104, block; 104, 105; 105, for_statement; 105, 106; 105, 107; 105, 108; 106, identifier:voucher_code; 107, identifier:sorted_voucher_codes; 108, block; 108, 109; 109, for_statement; 109, 110; 109, 111; 109, 112; 110, identifier:seq_record; 111, identifier:seq_records; 112, block; 112, 113; 112, 128; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:should_be_done; 116, parenthesized_expression; 116, 117; 117, boolean_operator:and; 117, 118; 117, 123; 118, comparison_operator:==; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:seq_record; 121, identifier:gene_code; 122, identifier:gene_code; 123, comparison_operator:==; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:seq_record; 126, identifier:voucher_code; 127, identifier:voucher_code; 128, if_statement; 128, 129; 128, 130; 129, identifier:should_be_done; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:sorted_seq_records; 135, identifier:append; 136, argument_list; 136, 137; 137, identifier:seq_record; 138, return_statement; 138, 139; 139, identifier:sorted_seq_records
def sort_seq_records(self, seq_records): for seq_record in seq_records: seq_record.voucher_code = seq_record.voucher_code.replace("-", "_") unsorted_gene_codes = set([i.gene_code for i in seq_records]) sorted_gene_codes = list(unsorted_gene_codes) sorted_gene_codes.sort(key=lambda x: x.lower()) unsorted_voucher_codes = set([i.voucher_code for i in seq_records]) sorted_voucher_codes = list(unsorted_voucher_codes) sorted_voucher_codes.sort(key=lambda x: x.lower()) sorted_seq_records = [] for gene_code in sorted_gene_codes: for voucher_code in sorted_voucher_codes: for seq_record in seq_records: should_be_done = ( seq_record.gene_code == gene_code and seq_record.voucher_code == voucher_code ) if should_be_done: sorted_seq_records.append(seq_record) return sorted_seq_records
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:extractFromSQLFile; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:filePointer; 6, default_parameter; 6, 7; 6, 8; 7, identifier:delimiter; 8, string:";"; 9, block; 9, 10; 9, 18; 9, 22; 9, 26; 9, 80; 9, 84; 9, 88; 9, 164; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:data; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:filePointer; 16, identifier:read; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:dataLines; 21, list:[]; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:dataLinesIndex; 25, integer:0; 26, for_statement; 26, 27; 26, 28; 26, 29; 27, identifier:c; 28, identifier:data; 29, block; 29, 30; 29, 47; 30, if_statement; 30, 31; 30, 39; 31, comparison_operator:<; 31, 32; 31, 38; 32, binary_operator:-; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:len; 35, argument_list; 35, 36; 36, identifier:dataLines; 37, integer:1; 38, identifier:dataLinesIndex; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:dataLines; 44, identifier:append; 45, argument_list; 45, 46; 46, string:""; 47, if_statement; 47, 48; 47, 59; 47, 64; 48, boolean_operator:or; 48, 49; 48, 56; 49, boolean_operator:or; 49, 50; 49, 53; 50, comparison_operator:==; 50, 51; 50, 52; 51, identifier:c; 52, string:"\r\n"; 53, comparison_operator:==; 53, 54; 53, 55; 54, identifier:c; 55, string:"\r"; 56, comparison_operator:==; 56, 57; 56, 58; 57, identifier:c; 58, string:"\n"; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, augmented_assignment:+=; 61, 62; 61, 63; 62, identifier:dataLinesIndex; 63, integer:1; 64, else_clause; 64, 65; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:dataLines; 70, identifier:dataLinesIndex; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, string:"{}{}"; 74, identifier:format; 75, argument_list; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:dataLines; 78, identifier:dataLinesIndex; 79, identifier:c; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:statements; 83, list:[]; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:statementsIndex; 87, integer:0; 88, for_statement; 88, 89; 88, 90; 88, 91; 89, identifier:line; 90, identifier:dataLines; 91, block; 91, 92; 91, 120; 92, if_statement; 92, 93; 92, 103; 92, 118; 93, boolean_operator:or; 93, 94; 93, 100; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:line; 97, identifier:startswith; 98, argument_list; 98, 99; 99, string:"--"; 100, attribute; 100, 101; 100, 102; 101, identifier:line; 102, identifier:startswith; 103, ERROR; 103, 104; 103, 106; 103, 107; 103, 112; 104, ERROR; 104, 105; 105, identifier:continue; 106, identifier:line; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:line; 110, identifier:strip; 111, argument_list; 112, comparison_operator:==; 112, 113; 112, 117; 113, call; 113, 114; 113, 115; 114, identifier:len; 115, argument_list; 115, 116; 116, identifier:line; 117, integer:0; 118, block; 118, 119; 119, continue_statement; 120, for_statement; 120, 121; 120, 122; 120, 123; 121, identifier:c; 122, identifier:line; 123, block; 123, 124; 123, 141; 123, 155; 124, if_statement; 124, 125; 124, 133; 125, comparison_operator:<; 125, 126; 125, 132; 126, binary_operator:-; 126, 127; 126, 131; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, identifier:statements; 131, integer:1; 132, identifier:statementsIndex; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:statements; 138, identifier:append; 139, argument_list; 139, 140; 140, string:""; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:statements; 145, identifier:statementsIndex; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, string:"{}{}"; 149, identifier:format; 150, argument_list; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:statements; 153, identifier:statementsIndex; 154, identifier:c; 155, if_statement; 155, 156; 155, 159; 156, comparison_operator:==; 156, 157; 156, 158; 157, identifier:c; 158, identifier:delimiter; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, augmented_assignment:+=; 161, 162; 161, 163; 162, identifier:statementsIndex; 163, integer:1; 164, return_statement; 164, 165; 165, identifier:statements
def extractFromSQLFile(self, filePointer, delimiter=";"): data = filePointer.read() dataLines = [] dataLinesIndex = 0 for c in data: if len(dataLines) - 1 < dataLinesIndex: dataLines.append("") if c == "\r\n" or c == "\r" or c == "\n": dataLinesIndex += 1 else: dataLines[dataLinesIndex] = "{}{}".format( dataLines[dataLinesIndex], c ) statements = [] statementsIndex = 0 for line in dataLines: if line.startswith("--") or line.startswith(" continue line = line.strip() if len(line) == 0: continue for c in line: if len(statements) - 1 < statementsIndex: statements.append("") statements[statementsIndex] = "{}{}".format( statements[statementsIndex], c ) if c == delimiter: statementsIndex += 1 return statements
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:sort_data; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:data; 6, identifier:sort_key; 7, default_parameter; 7, 8; 7, 9; 8, identifier:reverse; 9, False; 10, block; 10, 11; 10, 15; 10, 33; 10, 44; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:sorted_data; 14, list:[]; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:lines; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 20, 22; 20, 30; 21, identifier:data; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:key; 24, lambda; 24, 25; 24, 27; 25, lambda_parameters; 25, 26; 26, identifier:k; 27, subscript; 27, 28; 27, 29; 28, identifier:k; 29, identifier:sort_key; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:reverse; 32, identifier:reverse; 33, for_statement; 33, 34; 33, 35; 33, 36; 34, identifier:line; 35, identifier:lines; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:sorted_data; 41, identifier:append; 42, argument_list; 42, 43; 43, identifier:line; 44, return_statement; 44, 45; 45, identifier:sorted_data
async def sort_data(self, data, sort_key, reverse=False): sorted_data = [] lines = sorted(data, key=lambda k: k[sort_key], reverse=reverse) for line in lines: sorted_data.append(line) return sorted_data
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 11; 2, function_name:get_ceiling; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:clouds; 6, type; 6, 7; 7, list:[Cloud]; 7, 8; 8, identifier:Cloud; 9, type; 9, 10; 10, identifier:Cloud; 11, block; 11, 12; 11, 32; 12, for_statement; 12, 13; 12, 14; 12, 15; 13, identifier:cloud; 14, identifier:clouds; 15, block; 15, 16; 16, if_statement; 16, 17; 16, 29; 17, boolean_operator:and; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:cloud; 20, identifier:altitude; 21, comparison_operator:in; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:cloud; 24, identifier:type; 25, tuple; 25, 26; 25, 27; 25, 28; 26, string:'OVC'; 27, string:'BKN'; 28, string:'VV'; 29, block; 29, 30; 30, return_statement; 30, 31; 31, identifier:cloud; 32, return_statement; 32, 33; 33, None
def get_ceiling(clouds: [Cloud]) -> Cloud: for cloud in clouds: if cloud.altitude and cloud.type in ('OVC', 'BKN', 'VV'): return cloud return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_finish_filter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:lst; 6, identifier:key; 7, identifier:include_self; 8, identifier:exclusive; 9, identifier:biggest_first; 10, block; 10, 11; 10, 20; 10, 30; 10, 50; 10, 67; 10, 77; 10, 154; 10, 183; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:key; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_actual_key; 18, argument_list; 18, 19; 19, identifier:key; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:locations; 23, list_comprehension; 23, 24; 23, 27; 24, subscript; 24, 25; 24, 26; 25, identifier:x; 26, integer:0; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:x; 29, identifier:lst; 30, if_statement; 30, 31; 30, 37; 31, boolean_operator:and; 31, 32; 31, 34; 32, not_operator; 32, 33; 33, identifier:include_self; 34, comparison_operator:in; 34, 35; 34, 36; 35, identifier:key; 36, identifier:locations; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:lst; 42, identifier:pop; 43, argument_list; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:locations; 47, identifier:index; 48, argument_list; 48, 49; 49, identifier:key; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:lst; 54, identifier:sort; 55, argument_list; 55, 56; 55, 64; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:key; 58, lambda; 58, 59; 58, 61; 59, lambda_parameters; 59, 60; 60, identifier:x; 61, subscript; 61, 62; 61, 63; 62, identifier:x; 63, integer:1; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:reverse; 66, identifier:biggest_first; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:lst; 70, list_comprehension; 70, 71; 70, 72; 71, identifier:x; 72, for_in_clause; 72, 73; 72, 76; 73, pattern_list; 73, 74; 73, 75; 74, identifier:x; 75, identifier:y; 76, identifier:lst; 77, if_statement; 77, 78; 77, 87; 77, 96; 78, boolean_operator:and; 78, 79; 78, 86; 79, boolean_operator:and; 79, 80; 79, 83; 80, comparison_operator:==; 80, 81; 80, 82; 81, identifier:key; 82, string:'RoW'; 83, comparison_operator:not; 83, 84; 83, 85; 84, string:'RoW'; 85, identifier:self; 86, identifier:exclusive; 87, block; 87, 88; 88, return_statement; 88, 89; 89, conditional_expression:if; 89, 90; 89, 92; 89, 95; 90, list:['RoW']; 90, 91; 91, string:'RoW'; 92, comparison_operator:in; 92, 93; 92, 94; 93, string:'RoW'; 94, identifier:lst; 95, list:[]; 96, elif_clause; 96, 97; 96, 98; 97, identifier:exclusive; 98, block; 98, 99; 98, 109; 98, 150; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, pattern_list; 101, 102; 101, 103; 102, identifier:removed; 103, identifier:remaining; 104, expression_list; 104, 105; 104, 108; 105, call; 105, 106; 105, 107; 106, identifier:set; 107, argument_list; 108, list:[]; 109, while_statement; 109, 110; 109, 111; 110, identifier:lst; 111, block; 111, 112; 111, 121; 111, 127; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:current; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:lst; 118, identifier:pop; 119, argument_list; 119, 120; 120, integer:0; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:faces; 124, subscript; 124, 125; 124, 126; 125, identifier:self; 126, identifier:current; 127, if_statement; 127, 128; 127, 135; 128, not_operator; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:faces; 132, identifier:intersection; 133, argument_list; 133, 134; 134, identifier:removed; 135, block; 135, 136; 135, 143; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:removed; 140, identifier:update; 141, argument_list; 141, 142; 142, identifier:faces; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:remaining; 147, identifier:append; 148, argument_list; 148, 149; 149, identifier:current; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:lst; 153, identifier:remaining; 154, if_statement; 154, 155; 154, 162; 155, boolean_operator:and; 155, 156; 155, 159; 156, comparison_operator:not; 156, 157; 156, 158; 157, string:'RoW'; 158, identifier:self; 159, comparison_operator:in; 159, 160; 159, 161; 160, string:'RoW'; 161, identifier:lst; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 172; 165, subscript; 165, 166; 165, 167; 166, identifier:lst; 167, conditional_expression:if; 167, 168; 167, 170; 167, 171; 168, unary_operator:-; 168, 169; 169, integer:1; 170, identifier:biggest_first; 171, integer:0; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:lst; 175, identifier:pop; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:lst; 180, identifier:index; 181, argument_list; 181, 182; 182, string:'RoW'; 183, return_statement; 183, 184; 184, identifier:lst
def _finish_filter(self, lst, key, include_self, exclusive, biggest_first): key = self._actual_key(key) locations = [x[0] for x in lst] if not include_self and key in locations: lst.pop(locations.index(key)) lst.sort(key=lambda x: x[1], reverse=biggest_first) lst = [x for x, y in lst] if key == 'RoW' and 'RoW' not in self and exclusive: return ['RoW'] if 'RoW' in lst else [] elif exclusive: removed, remaining = set(), [] while lst: current = lst.pop(0) faces = self[current] if not faces.intersection(removed): removed.update(faces) remaining.append(current) lst = remaining if 'RoW' not in self and 'RoW' in lst: lst[-1 if biggest_first else 0] = lst.pop(lst.index('RoW')) return lst
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:intersects; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:include_self; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:exclusive; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:biggest_first; 14, True; 15, default_parameter; 15, 16; 15, 17; 16, identifier:only; 17, None; 18, block; 18, 19; 18, 38; 18, 55; 18, 61; 18, 98; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:possibles; 22, conditional_expression:if; 22, 23; 22, 26; 22, 29; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:topology; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:only; 28, None; 29, dictionary_comprehension; 29, 30; 29, 35; 30, pair; 30, 31; 30, 32; 31, identifier:k; 32, subscript; 32, 33; 32, 34; 33, identifier:self; 34, identifier:k; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:k; 37, identifier:only; 38, if_statement; 38, 39; 38, 46; 39, boolean_operator:and; 39, 40; 39, 43; 40, comparison_operator:==; 40, 41; 40, 42; 41, identifier:key; 42, string:'RoW'; 43, comparison_operator:not; 43, 44; 43, 45; 44, string:'RoW'; 45, identifier:self; 46, block; 46, 47; 47, return_statement; 47, 48; 48, conditional_expression:if; 48, 49; 48, 51; 48, 54; 49, list:['RoW']; 49, 50; 50, string:'RoW'; 51, comparison_operator:in; 51, 52; 51, 53; 52, string:'RoW'; 53, identifier:possibles; 54, list:[]; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:faces; 58, subscript; 58, 59; 58, 60; 59, identifier:self; 60, identifier:key; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:lst; 64, list_comprehension; 64, 65; 64, 81; 64, 90; 65, tuple; 65, 66; 65, 67; 66, identifier:k; 67, tuple; 67, 68; 67, 77; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:v; 74, identifier:intersection; 75, argument_list; 75, 76; 76, identifier:faces; 77, call; 77, 78; 77, 79; 78, identifier:len; 79, argument_list; 79, 80; 80, identifier:v; 81, for_in_clause; 81, 82; 81, 85; 82, pattern_list; 82, 83; 82, 84; 83, identifier:k; 84, identifier:v; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:possibles; 88, identifier:items; 89, argument_list; 90, if_clause; 90, 91; 91, parenthesized_expression; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:faces; 95, identifier:intersection; 96, argument_list; 96, 97; 97, identifier:v; 98, return_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:_finish_filter; 103, argument_list; 103, 104; 103, 105; 103, 106; 103, 107; 103, 108; 104, identifier:lst; 105, identifier:key; 106, identifier:include_self; 107, identifier:exclusive; 108, identifier:biggest_first
def intersects(self, key, include_self=False, exclusive=False, biggest_first=True, only=None): possibles = self.topology if only is None else {k: self[k] for k in only} if key == 'RoW' and 'RoW' not in self: return ['RoW'] if 'RoW' in possibles else [] faces = self[key] lst = [ (k, (len(v.intersection(faces)), len(v))) for k, v in possibles.items() if (faces.intersection(v)) ] return self._finish_filter(lst, key, include_self, exclusive, biggest_first)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:group_by_key_func; 3, parameters; 3, 4; 3, 5; 4, identifier:iterable; 5, identifier:key_func; 6, block; 6, 7; 6, 14; 6, 30; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:result; 10, call; 10, 11; 10, 12; 11, identifier:defaultdict; 12, argument_list; 12, 13; 13, identifier:list; 14, for_statement; 14, 15; 14, 16; 14, 17; 15, identifier:item; 16, identifier:iterable; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 28; 20, attribute; 20, 21; 20, 27; 21, subscript; 21, 22; 21, 23; 22, identifier:result; 23, call; 23, 24; 23, 25; 24, identifier:key_func; 25, argument_list; 25, 26; 26, identifier:item; 27, identifier:append; 28, argument_list; 28, 29; 29, identifier:item; 30, return_statement; 30, 31; 31, identifier:result
def group_by_key_func(iterable, key_func): result = defaultdict(list) for item in iterable: result[key_func(item)].append(item) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:line; 5, block; 5, 6; 5, 14; 5, 18; 5, 51; 5, 60; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 13; 8, pattern_list; 8, 9; 8, 10; 8, 11; 8, 12; 9, identifier:x0; 10, identifier:y0; 11, identifier:x1; 12, identifier:y1; 13, identifier:line; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:turn; 17, False; 18, if_statement; 18, 19; 18, 32; 18, 42; 19, comparison_operator:>; 19, 20; 19, 26; 20, call; 20, 21; 20, 22; 21, identifier:abs; 22, argument_list; 22, 23; 23, binary_operator:-; 23, 24; 23, 25; 24, identifier:x1; 25, identifier:x0; 26, call; 26, 27; 26, 28; 27, identifier:abs; 28, argument_list; 28, 29; 29, binary_operator:-; 29, 30; 29, 31; 30, identifier:y1; 31, identifier:y0; 32, block; 32, 33; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:<; 34, 35; 34, 36; 35, identifier:x1; 36, identifier:x0; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:turn; 41, True; 42, elif_clause; 42, 43; 42, 46; 43, comparison_operator:<; 43, 44; 43, 45; 44, identifier:y1; 45, identifier:y0; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:turn; 50, True; 51, if_statement; 51, 52; 51, 53; 52, identifier:turn; 53, block; 53, 54; 54, return_statement; 54, 55; 55, tuple; 55, 56; 55, 57; 55, 58; 55, 59; 56, identifier:x1; 57, identifier:y1; 58, identifier:x0; 59, identifier:y0; 60, return_statement; 60, 61; 61, identifier:line
def sort(line): x0, y0, x1, y1 = line turn = False if abs(x1 - x0) > abs(y1 - y0): if x1 < x0: turn = True elif y1 < y0: turn = True if turn: return (x1, y1, x0, y0) return line
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:vectorizable_features; 3, parameters; 3, 4; 4, identifier:fcs; 5, block; 5, 6; 5, 8; 5, 21; 6, expression_statement; 6, 7; 7, string:'''Discovers the ordered set of vectorizable features in ``fcs``. Returns a list of feature names, sorted lexicographically. Feature names are only included if the corresponding features are vectorizable (i.e., they are an instance of :class:`collections.Mapping`). '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:is_mapping; 11, lambda; 11, 12; 11, 14; 12, lambda_parameters; 12, 13; 13, identifier:obj; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:obj; 18, attribute; 18, 19; 18, 20; 19, identifier:collections; 20, identifier:Mapping; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:sorted; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:set; 27, argument_list; 27, 28; 28, list_comprehension; 28, 29; 28, 30; 28, 33; 28, 36; 29, identifier:name; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:fc; 32, identifier:fcs; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:name; 35, identifier:fc; 36, if_clause; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:is_mapping; 39, argument_list; 39, 40; 40, subscript; 40, 41; 40, 42; 41, identifier:fc; 42, identifier:name
def vectorizable_features(fcs): '''Discovers the ordered set of vectorizable features in ``fcs``. Returns a list of feature names, sorted lexicographically. Feature names are only included if the corresponding features are vectorizable (i.e., they are an instance of :class:`collections.Mapping`). ''' is_mapping = lambda obj: isinstance(obj, collections.Mapping) return sorted(set([name for fc in fcs for name in fc if is_mapping(fc[name])]))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:extension_sort_key; 3, parameters; 3, 4; 4, identifier:extension; 5, block; 5, 6; 5, 12; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:name; 9, attribute; 9, 10; 9, 11; 10, identifier:extension; 11, identifier:name; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:category; 15, subscript; 15, 16; 15, 23; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:name; 19, identifier:split; 20, argument_list; 20, 21; 20, 22; 21, string:'_'; 22, integer:2; 23, integer:1; 24, return_statement; 24, 25; 25, conditional_expression:if; 25, 26; 25, 29; 25, 35; 26, tuple; 26, 27; 26, 28; 27, integer:0; 28, identifier:name; 29, comparison_operator:in; 29, 30; 29, 31; 30, identifier:category; 31, tuple; 31, 32; 31, 33; 31, 34; 32, string:'ARB'; 33, string:'KHR'; 34, string:'OES'; 35, tuple; 35, 36; 35, 37; 36, integer:1; 37, identifier:name
def extension_sort_key(extension): name = extension.name category = name.split('_', 2)[1] return (0, name) if category in ('ARB', 'KHR', 'OES') else (1, name)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:estimate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:upgrades; 6, block; 6, 7; 6, 11; 6, 23; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:val; 10, integer:0; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:u; 13, identifier:upgrades; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, augmented_assignment:+=; 16, 17; 16, 18; 17, identifier:val; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:u; 21, identifier:estimate; 22, argument_list; 23, return_statement; 23, 24; 24, identifier:val
def estimate(self, upgrades): val = 0 for u in upgrades: val += u.estimate() return val
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:human_estimate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:upgrades; 6, block; 6, 7; 6, 16; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:val; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:estimate; 14, argument_list; 14, 15; 15, identifier:upgrades; 16, if_statement; 16, 17; 16, 20; 16, 23; 16, 30; 16, 37; 16, 44; 16, 51; 16, 60; 16, 69; 16, 78; 16, 85; 17, comparison_operator:<; 17, 18; 17, 19; 18, identifier:val; 19, integer:60; 20, block; 20, 21; 21, return_statement; 21, 22; 22, string:"less than 1 minute"; 23, elif_clause; 23, 24; 23, 27; 24, comparison_operator:<; 24, 25; 24, 26; 25, identifier:val; 26, integer:300; 27, block; 27, 28; 28, return_statement; 28, 29; 29, string:"less than 5 minutes"; 30, elif_clause; 30, 31; 30, 34; 31, comparison_operator:<; 31, 32; 31, 33; 32, identifier:val; 33, integer:600; 34, block; 34, 35; 35, return_statement; 35, 36; 36, string:"less than 10 minutes"; 37, elif_clause; 37, 38; 37, 41; 38, comparison_operator:<; 38, 39; 38, 40; 39, identifier:val; 40, integer:1800; 41, block; 41, 42; 42, return_statement; 42, 43; 43, string:"less than 30 minutes"; 44, elif_clause; 44, 45; 44, 48; 45, comparison_operator:<; 45, 46; 45, 47; 46, identifier:val; 47, integer:3600; 48, block; 48, 49; 49, return_statement; 49, 50; 50, string:"less than 1 hour"; 51, elif_clause; 51, 52; 51, 57; 52, comparison_operator:<; 52, 53; 52, 54; 53, identifier:val; 54, binary_operator:*; 54, 55; 54, 56; 55, integer:3; 56, integer:3600; 57, block; 57, 58; 58, return_statement; 58, 59; 59, string:"less than 3 hours"; 60, elif_clause; 60, 61; 60, 66; 61, comparison_operator:<; 61, 62; 61, 63; 62, identifier:val; 63, binary_operator:*; 63, 64; 63, 65; 64, integer:6; 65, integer:3600; 66, block; 66, 67; 67, return_statement; 67, 68; 68, string:"less than 6 hours"; 69, elif_clause; 69, 70; 69, 75; 70, comparison_operator:<; 70, 71; 70, 72; 71, identifier:val; 72, binary_operator:*; 72, 73; 72, 74; 73, integer:12; 74, integer:3600; 75, block; 75, 76; 76, return_statement; 76, 77; 77, string:"less than 12 hours"; 78, elif_clause; 78, 79; 78, 82; 79, comparison_operator:<; 79, 80; 79, 81; 80, identifier:val; 81, integer:86400; 82, block; 82, 83; 83, return_statement; 83, 84; 84, string:"less than 1 day"; 85, else_clause; 85, 86; 86, block; 86, 87; 87, return_statement; 87, 88; 88, string:"more than 1 day"
def human_estimate(self, upgrades): val = self.estimate(upgrades) if val < 60: return "less than 1 minute" elif val < 300: return "less than 5 minutes" elif val < 600: return "less than 10 minutes" elif val < 1800: return "less than 30 minutes" elif val < 3600: return "less than 1 hour" elif val < 3 * 3600: return "less than 3 hours" elif val < 6 * 3600: return "less than 6 hours" elif val < 12 * 3600: return "less than 12 hours" elif val < 86400: return "less than 1 day" else: return "more than 1 day"
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:pre_upgrade_checks; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:upgrades; 6, block; 6, 7; 6, 11; 6, 53; 6, 95; 6, 101; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:errors; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 16; 12, identifier:check; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:global_pre_upgrade; 16, block; 16, 17; 16, 28; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_setup_log_prefix; 22, argument_list; 22, 23; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:plugin_id; 25, attribute; 25, 26; 25, 27; 26, identifier:check; 27, identifier:__name__; 28, try_statement; 28, 29; 28, 34; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:check; 33, argument_list; 34, except_clause; 34, 35; 34, 39; 35, as_pattern; 35, 36; 35, 37; 36, identifier:RuntimeError; 37, as_pattern_target; 37, 38; 38, identifier:e; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:errors; 44, identifier:append; 45, argument_list; 45, 46; 46, tuple; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:check; 49, identifier:__name__; 50, attribute; 50, 51; 50, 52; 51, identifier:e; 52, identifier:args; 53, for_statement; 53, 54; 53, 55; 53, 56; 54, identifier:u; 55, identifier:upgrades; 56, block; 56, 57; 56, 68; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:_setup_log_prefix; 62, argument_list; 62, 63; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:plugin_id; 65, attribute; 65, 66; 65, 67; 66, identifier:u; 67, identifier:name; 68, try_statement; 68, 69; 68, 76; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:u; 74, identifier:pre_upgrade; 75, argument_list; 76, except_clause; 76, 77; 76, 81; 77, as_pattern; 77, 78; 77, 79; 78, identifier:RuntimeError; 79, as_pattern_target; 79, 80; 80, identifier:e; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:errors; 86, identifier:append; 87, argument_list; 87, 88; 88, tuple; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:u; 91, identifier:name; 92, attribute; 92, 93; 92, 94; 93, identifier:e; 94, identifier:args; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_teardown_log_prefix; 100, argument_list; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_check_errors; 106, argument_list; 106, 107; 106, 108; 107, identifier:errors; 108, concatenated_string; 108, 109; 108, 110; 109, string:"Pre-upgrade check for %s failed with the"; 110, string:" following errors:"
def pre_upgrade_checks(self, upgrades): errors = [] for check in self.global_pre_upgrade: self._setup_log_prefix(plugin_id=check.__name__) try: check() except RuntimeError as e: errors.append((check.__name__, e.args)) for u in upgrades: self._setup_log_prefix(plugin_id=u.name) try: u.pre_upgrade() except RuntimeError as e: errors.append((u.name, e.args)) self._teardown_log_prefix() self._check_errors(errors, "Pre-upgrade check for %s failed with the" " following errors:")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:post_upgrade_checks; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:upgrades; 6, block; 6, 7; 6, 11; 6, 53; 6, 95; 6, 101; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:errors; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:u; 13, identifier:upgrades; 14, block; 14, 15; 14, 26; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_setup_log_prefix; 20, argument_list; 20, 21; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:plugin_id; 23, attribute; 23, 24; 23, 25; 24, identifier:u; 25, identifier:name; 26, try_statement; 26, 27; 26, 34; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:u; 32, identifier:post_upgrade; 33, argument_list; 34, except_clause; 34, 35; 34, 39; 35, as_pattern; 35, 36; 35, 37; 36, identifier:RuntimeError; 37, as_pattern_target; 37, 38; 38, identifier:e; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:errors; 44, identifier:append; 45, argument_list; 45, 46; 46, tuple; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:u; 49, identifier:name; 50, attribute; 50, 51; 50, 52; 51, identifier:e; 52, identifier:args; 53, for_statement; 53, 54; 53, 55; 53, 58; 54, identifier:check; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:global_post_upgrade; 58, block; 58, 59; 58, 70; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:_setup_log_prefix; 64, argument_list; 64, 65; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:plugin_id; 67, attribute; 67, 68; 67, 69; 68, identifier:check; 69, identifier:__name__; 70, try_statement; 70, 71; 70, 76; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:check; 75, argument_list; 76, except_clause; 76, 77; 76, 81; 77, as_pattern; 77, 78; 77, 79; 78, identifier:RuntimeError; 79, as_pattern_target; 79, 80; 80, identifier:e; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:errors; 86, identifier:append; 87, argument_list; 87, 88; 88, tuple; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:check; 91, identifier:__name__; 92, attribute; 92, 93; 92, 94; 93, identifier:e; 94, identifier:args; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_teardown_log_prefix; 100, argument_list; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_check_errors; 106, argument_list; 106, 107; 106, 108; 107, identifier:errors; 108, concatenated_string; 108, 109; 108, 110; 109, string:"Post-upgrade check for %s failed with the "; 110, string:"following errors:"
def post_upgrade_checks(self, upgrades): errors = [] for u in upgrades: self._setup_log_prefix(plugin_id=u.name) try: u.post_upgrade() except RuntimeError as e: errors.append((u.name, e.args)) for check in self.global_post_upgrade: self._setup_log_prefix(plugin_id=check.__name__) try: check() except RuntimeError as e: errors.append((check.__name__, e.args)) self._teardown_log_prefix() self._check_errors(errors, "Post-upgrade check for %s failed with the " "following errors:")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:order_upgrades; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:upgrades; 6, default_parameter; 6, 7; 6, 8; 7, identifier:history; 8, None; 9, block; 9, 10; 9, 16; 9, 28; 9, 131; 9, 162; 9, 184; 9, 188; 9, 241; 9, 264; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:history; 13, boolean_operator:or; 13, 14; 13, 15; 14, identifier:history; 15, dictionary; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 21; 18, pattern_list; 18, 19; 18, 20; 19, identifier:graph_incoming; 20, identifier:graph_outgoing; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:_create_graph; 25, argument_list; 25, 26; 25, 27; 26, identifier:upgrades; 27, identifier:history; 28, for_statement; 28, 29; 28, 30; 28, 36; 29, identifier:node_id; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:six; 33, identifier:iterkeys; 34, argument_list; 34, 35; 35, identifier:history; 36, block; 36, 37; 36, 42; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:start_nodes; 40, list:[node_id, ]; 40, 41; 41, identifier:node_id; 42, while_statement; 42, 43; 42, 44; 43, identifier:start_nodes; 44, block; 44, 45; 44, 53; 44, 89; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:node; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:start_nodes; 51, identifier:pop; 52, argument_list; 53, try_statement; 53, 54; 53, 77; 54, block; 54, 55; 55, for_statement; 55, 56; 55, 57; 55, 60; 56, identifier:d; 57, subscript; 57, 58; 57, 59; 58, identifier:graph_outgoing; 59, identifier:node; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, subscript; 63, 64; 63, 65; 64, identifier:graph_incoming; 65, identifier:d; 66, list_comprehension; 66, 67; 66, 68; 66, 73; 67, identifier:x; 68, for_in_clause; 68, 69; 68, 70; 69, identifier:x; 70, subscript; 70, 71; 70, 72; 71, identifier:graph_incoming; 72, identifier:d; 73, if_clause; 73, 74; 74, comparison_operator:!=; 74, 75; 74, 76; 75, identifier:x; 76, identifier:node; 77, except_clause; 77, 78; 77, 79; 78, identifier:KeyError; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:warnings; 84, identifier:warn; 85, argument_list; 85, 86; 86, binary_operator:%; 86, 87; 86, 88; 87, string:"Ghost upgrade %s detected"; 88, identifier:node; 89, if_statement; 89, 90; 89, 93; 90, comparison_operator:in; 90, 91; 90, 92; 91, identifier:node; 92, identifier:graph_incoming; 93, block; 93, 94; 93, 100; 93, 127; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:depends_on; 97, subscript; 97, 98; 97, 99; 98, identifier:graph_incoming; 99, identifier:node; 100, for_statement; 100, 101; 100, 102; 100, 103; 101, identifier:d; 102, identifier:depends_on; 103, block; 103, 104; 103, 120; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:graph_outgoing; 108, identifier:d; 109, list_comprehension; 109, 110; 109, 111; 109, 116; 110, identifier:x; 111, for_in_clause; 111, 112; 111, 113; 112, identifier:x; 113, subscript; 113, 114; 113, 115; 114, identifier:graph_outgoing; 115, identifier:d; 116, if_clause; 116, 117; 117, comparison_operator:!=; 117, 118; 117, 119; 118, identifier:x; 119, identifier:node; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:start_nodes; 124, identifier:append; 125, argument_list; 125, 126; 126, identifier:d; 127, delete_statement; 127, 128; 128, subscript; 128, 129; 128, 130; 129, identifier:graph_incoming; 130, identifier:node; 131, for_statement; 131, 132; 131, 135; 131, 141; 132, pattern_list; 132, 133; 132, 134; 133, identifier:node_id; 134, identifier:depends_on; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:six; 138, identifier:iteritems; 139, argument_list; 139, 140; 140, identifier:graph_incoming; 141, block; 141, 142; 142, for_statement; 142, 143; 142, 144; 142, 145; 143, identifier:d; 144, identifier:depends_on; 145, block; 145, 146; 146, if_statement; 146, 147; 146, 150; 147, comparison_operator:not; 147, 148; 147, 149; 148, identifier:d; 149, identifier:graph_incoming; 150, block; 150, 151; 151, raise_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:RuntimeError; 154, argument_list; 154, 155; 155, binary_operator:%; 155, 156; 155, 159; 156, concatenated_string; 156, 157; 156, 158; 157, string:"Upgrade %s depends on an unknown"; 158, string:" upgrade %s"; 159, tuple; 159, 160; 159, 161; 160, identifier:node_id; 161, identifier:d; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:start_nodes; 165, list_comprehension; 165, 166; 165, 167; 165, 175; 166, identifier:x; 167, for_in_clause; 167, 168; 167, 169; 168, identifier:x; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:six; 172, identifier:iterkeys; 173, argument_list; 173, 174; 174, identifier:graph_incoming; 175, if_clause; 175, 176; 176, comparison_operator:==; 176, 177; 176, 183; 177, call; 177, 178; 177, 179; 178, identifier:len; 179, argument_list; 179, 180; 180, subscript; 180, 181; 180, 182; 181, identifier:graph_incoming; 182, identifier:x; 183, integer:0; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:topo_order; 187, list:[]; 188, while_statement; 188, 189; 188, 190; 189, identifier:start_nodes; 190, block; 190, 191; 190, 199; 190, 206; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:node_n; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:start_nodes; 197, identifier:pop; 198, argument_list; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:topo_order; 203, identifier:append; 204, argument_list; 204, 205; 205, identifier:node_n; 206, for_statement; 206, 207; 206, 208; 206, 211; 207, identifier:node_m; 208, subscript; 208, 209; 208, 210; 209, identifier:graph_outgoing; 210, identifier:node_n; 211, block; 211, 212; 211, 228; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:graph_incoming; 216, identifier:node_m; 217, list_comprehension; 217, 218; 217, 219; 217, 224; 218, identifier:x; 219, for_in_clause; 219, 220; 219, 221; 220, identifier:x; 221, subscript; 221, 222; 221, 223; 222, identifier:graph_incoming; 223, identifier:node_m; 224, if_clause; 224, 225; 225, comparison_operator:!=; 225, 226; 225, 227; 226, identifier:x; 227, identifier:node_n; 228, if_statement; 228, 229; 228, 233; 229, not_operator; 229, 230; 230, subscript; 230, 231; 230, 232; 231, identifier:graph_incoming; 232, identifier:node_m; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:start_nodes; 238, identifier:append; 239, argument_list; 239, 240; 240, identifier:node_m; 241, for_statement; 241, 242; 241, 245; 241, 251; 242, pattern_list; 242, 243; 242, 244; 243, identifier:node; 244, identifier:edges; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:six; 248, identifier:iteritems; 249, argument_list; 249, 250; 250, identifier:graph_incoming; 251, block; 251, 252; 252, if_statement; 252, 253; 252, 254; 253, identifier:edges; 254, block; 254, 255; 255, raise_statement; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:RuntimeError; 258, argument_list; 258, 259; 259, binary_operator:%; 259, 260; 259, 263; 260, concatenated_string; 260, 261; 260, 262; 261, string:"The upgrades have at least one cyclic "; 262, string:"dependency involving %s."; 263, identifier:node; 264, return_statement; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:map; 267, argument_list; 267, 268; 267, 274; 268, lambda; 268, 269; 268, 271; 269, lambda_parameters; 269, 270; 270, identifier:x; 271, subscript; 271, 272; 271, 273; 272, identifier:upgrades; 273, identifier:x; 274, identifier:topo_order
def order_upgrades(self, upgrades, history=None): history = history or {} graph_incoming, graph_outgoing = self._create_graph(upgrades, history) for node_id in six.iterkeys(history): start_nodes = [node_id, ] while start_nodes: node = start_nodes.pop() try: for d in graph_outgoing[node]: graph_incoming[d] = [x for x in graph_incoming[d] if x != node] except KeyError: warnings.warn("Ghost upgrade %s detected" % node) if node in graph_incoming: depends_on = graph_incoming[node] for d in depends_on: graph_outgoing[d] = [x for x in graph_outgoing[d] if x != node] start_nodes.append(d) del graph_incoming[node] for node_id, depends_on in six.iteritems(graph_incoming): for d in depends_on: if d not in graph_incoming: raise RuntimeError("Upgrade %s depends on an unknown" " upgrade %s" % (node_id, d)) start_nodes = [x for x in six.iterkeys(graph_incoming) if len(graph_incoming[x]) == 0] topo_order = [] while start_nodes: node_n = start_nodes.pop() topo_order.append(node_n) for node_m in graph_outgoing[node_n]: graph_incoming[node_m] = [x for x in graph_incoming[node_m] if x != node_n] if not graph_incoming[node_m]: start_nodes.append(node_m) for node, edges in six.iteritems(graph_incoming): if edges: raise RuntimeError("The upgrades have at least one cyclic " "dependency involving %s." % node) return map(lambda x: upgrades[x], topo_order)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_validate_field; 3, parameters; 3, 4; 3, 5; 4, identifier:param; 5, identifier:fields; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 13; 8, comparison_operator:not; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:param; 11, identifier:field; 12, identifier:fields; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:InvalidQueryParams; 17, argument_list; 17, 18; 18, dictionary_splat; 18, 19; 19, dictionary; 19, 20; 19, 30; 19, 33; 20, pair; 20, 21; 20, 22; 21, string:'detail'; 22, binary_operator:%; 22, 23; 22, 27; 23, concatenated_string; 23, 24; 23, 25; 23, 26; 24, string:'The sort query param value of "%s" is '; 25, string:'invalid. That field does not exist on the '; 26, string:'resource being requested.'; 27, attribute; 27, 28; 27, 29; 28, identifier:param; 29, identifier:raw_field; 30, pair; 30, 31; 30, 32; 31, string:'links'; 32, identifier:LINK; 33, pair; 33, 34; 33, 35; 34, string:'parameter'; 35, identifier:PARAM
def _validate_field(param, fields): if param.field not in fields: raise InvalidQueryParams(**{ 'detail': 'The sort query param value of "%s" is ' 'invalid. That field does not exist on the ' 'resource being requested.' % param.raw_field, 'links': LINK, 'parameter': PARAM, })
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_validate_no_rels; 3, parameters; 3, 4; 3, 5; 4, identifier:param; 5, identifier:rels; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 13; 8, comparison_operator:in; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:param; 11, identifier:field; 12, identifier:rels; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:InvalidQueryParams; 17, argument_list; 17, 18; 18, dictionary_splat; 18, 19; 19, dictionary; 19, 20; 19, 30; 19, 33; 20, pair; 20, 21; 20, 22; 21, string:'detail'; 22, binary_operator:%; 22, 23; 22, 27; 23, concatenated_string; 23, 24; 23, 25; 23, 26; 24, string:'The sort query param value of "%s" is not '; 25, string:'supported. Sorting on relationships is not '; 26, string:'currently supported'; 27, attribute; 27, 28; 27, 29; 28, identifier:param; 29, identifier:raw_field; 30, pair; 30, 31; 30, 32; 31, string:'links'; 32, identifier:LINK; 33, pair; 33, 34; 33, 35; 34, string:'parameter'; 35, identifier:PARAM
def _validate_no_rels(param, rels): if param.field in rels: raise InvalidQueryParams(**{ 'detail': 'The sort query param value of "%s" is not ' 'supported. Sorting on relationships is not ' 'currently supported' % param.raw_field, 'links': LINK, 'parameter': PARAM, })
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:init; 3, parameters; 3, 4; 3, 5; 4, identifier:req; 5, identifier:model; 6, block; 6, 7; 6, 13; 6, 19; 6, 35; 6, 50; 6, 66; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:rels; 10, attribute; 10, 11; 10, 12; 11, identifier:model; 12, identifier:relationships; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:fields; 16, attribute; 16, 17; 16, 18; 17, identifier:model; 18, identifier:all_fields; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:params; 22, boolean_operator:or; 22, 23; 22, 29; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:req; 26, identifier:get_param_as_list; 27, argument_list; 27, 28; 28, string:'sort'; 29, list:[goldman.config.SORT]; 29, 30; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:goldman; 33, identifier:config; 34, identifier:SORT; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:params; 38, list_comprehension; 38, 39; 38, 47; 39, call; 39, 40; 39, 41; 40, identifier:Sortable; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:param; 45, identifier:lower; 46, argument_list; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:param; 49, identifier:params; 50, for_statement; 50, 51; 50, 52; 50, 53; 51, identifier:param; 52, identifier:params; 53, block; 53, 54; 53, 60; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:_validate_no_rels; 57, argument_list; 57, 58; 57, 59; 58, identifier:param; 59, identifier:rels; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:_validate_field; 63, argument_list; 63, 64; 63, 65; 64, identifier:param; 65, identifier:fields; 66, return_statement; 66, 67; 67, identifier:params
def init(req, model): rels = model.relationships fields = model.all_fields params = req.get_param_as_list('sort') or [goldman.config.SORT] params = [Sortable(param.lower()) for param in params] for param in params: _validate_no_rels(param, rels) _validate_field(param, fields) return params
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_allposts; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 27; 5, 48; 5, 57; 5, 61; 5, 65; 5, 225; 5, 240; 6, expression_statement; 6, 7; 7, string:''' Return all posts in blog sorted by date '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:result; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:client; 16, identifier:posts; 17, argument_list; 17, 18; 17, 21; 17, 24; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:blog; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:offset; 23, integer:0; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:limit; 26, integer:1; 27, try_statement; 27, 28; 27, 35; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:total_posts; 32, subscript; 32, 33; 32, 34; 33, identifier:result; 34, string:'total_posts'; 35, except_clause; 35, 36; 36, block; 36, 37; 37, raise_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:phasetumblr_errors; 41, identifier:TumblrBlogException; 42, argument_list; 42, 43; 43, subscript; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:result; 46, string:'meta'; 47, string:'msg'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:delta; 51, binary_operator:+; 51, 52; 51, 56; 52, parenthesized_expression; 52, 53; 53, binary_operator:/; 53, 54; 53, 55; 54, identifier:total_posts; 55, integer:10; 56, integer:1; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:all_posts; 60, list:[]; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:posts_ids; 64, list:[]; 65, for_statement; 65, 66; 65, 67; 65, 71; 66, identifier:j; 67, call; 67, 68; 67, 69; 68, identifier:range; 69, argument_list; 69, 70; 70, identifier:delta; 71, block; 71, 72; 71, 78; 71, 87; 71, 108; 71, 116; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:start; 75, binary_operator:*; 75, 76; 75, 77; 76, identifier:j; 77, integer:10; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:end; 81, binary_operator:*; 81, 82; 81, 86; 82, parenthesized_expression; 82, 83; 83, binary_operator:+; 83, 84; 83, 85; 84, identifier:j; 85, integer:1; 86, integer:10; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:posts; 90, subscript; 90, 91; 90, 107; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:client; 96, identifier:posts; 97, argument_list; 97, 98; 97, 101; 97, 104; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:blog; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:offset; 103, identifier:start; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:limit; 106, identifier:end; 107, string:'posts'; 108, if_statement; 108, 109; 108, 114; 109, not_operator; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:len; 112, argument_list; 112, 113; 113, identifier:posts; 114, block; 114, 115; 115, break_statement; 116, for_statement; 116, 117; 116, 118; 116, 119; 117, identifier:i; 118, identifier:posts; 119, block; 119, 120; 119, 128; 119, 137; 119, 147; 119, 151; 119, 159; 119, 167; 119, 181; 119, 189; 119, 197; 119, 203; 119, 209; 119, 216; 120, if_statement; 120, 121; 120, 126; 121, comparison_operator:in; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:i; 124, string:'id'; 125, identifier:posts_ids; 126, block; 126, 127; 127, continue_statement; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:description; 131, call; 131, 132; 131, 133; 132, identifier:split_body; 133, argument_list; 133, 134; 134, subscript; 134, 135; 134, 136; 135, identifier:i; 136, string:'body'; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:body; 140, call; 140, 141; 140, 142; 141, identifier:split_body; 142, argument_list; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:i; 145, string:'body'; 146, integer:1; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:post; 150, dictionary; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:post; 155, string:'title'; 156, subscript; 156, 157; 156, 158; 157, identifier:i; 158, string:'title'; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:post; 163, string:'link'; 164, subscript; 164, 165; 164, 166; 165, identifier:i; 166, string:'post_url'; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, subscript; 169, 170; 169, 171; 170, identifier:post; 171, string:'date'; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:datetime; 175, identifier:strptime; 176, argument_list; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:i; 179, string:'date'; 180, string:'%Y-%m-%d %H:%M:%S %Z'; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 186; 183, subscript; 183, 184; 183, 185; 184, identifier:post; 185, string:'tags'; 186, subscript; 186, 187; 186, 188; 187, identifier:i; 188, string:'tags'; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:post; 193, string:'id'; 194, subscript; 194, 195; 194, 196; 195, identifier:i; 196, string:'id'; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 202; 199, subscript; 199, 200; 199, 201; 200, identifier:post; 201, string:'body'; 202, identifier:body; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, subscript; 205, 206; 205, 207; 206, identifier:post; 207, string:'description'; 208, identifier:description; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:all_posts; 213, identifier:append; 214, argument_list; 214, 215; 215, identifier:post; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:posts_ids; 220, identifier:append; 221, argument_list; 221, 222; 222, subscript; 222, 223; 222, 224; 223, identifier:i; 224, string:'id'; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:newlist; 228, call; 228, 229; 228, 230; 229, identifier:sorted; 230, argument_list; 230, 231; 230, 232; 231, identifier:all_posts; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:key; 234, lambda; 234, 235; 234, 237; 235, lambda_parameters; 235, 236; 236, identifier:k; 237, subscript; 237, 238; 237, 239; 238, identifier:k; 239, string:'date'; 240, return_statement; 240, 241; 241, identifier:newlist
def get_allposts(self): ''' Return all posts in blog sorted by date ''' result = self.client.posts(self.blog, offset = 0, limit = 1) try: total_posts = result['total_posts'] except: raise phasetumblr_errors.TumblrBlogException(result['meta']['msg']) delta = (total_posts / 10) + 1 all_posts = [] posts_ids = [] for j in range(delta): start = j * 10 end = (j + 1) * 10 posts = self.client.posts(self.blog, offset = start, limit = end)['posts'] if not len(posts): break for i in posts: if i['id'] in posts_ids: continue description = split_body(i['body']) body = split_body(i['body'], 1) post = {} post['title'] = i['title'] post['link'] = i['post_url'] post['date'] = datetime.strptime(i['date'], '%Y-%m-%d %H:%M:%S %Z') post['tags'] = i['tags'] post['id'] = i['id'] post['body'] = body post['description'] = description all_posts.append(post) posts_ids.append(i['id']) newlist = sorted(all_posts, key=lambda k: k['date']) return newlist
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_dict_by_key; 3, parameters; 3, 4; 4, identifier:obj; 5, block; 5, 6; 5, 15; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sort_func; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:x; 12, subscript; 12, 13; 12, 14; 13, identifier:x; 14, integer:0; 15, return_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:OrderedDict; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:sorted; 21, argument_list; 21, 22; 21, 27; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:obj; 25, identifier:items; 26, argument_list; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:key; 29, identifier:sort_func
def sort_dict_by_key(obj): sort_func = lambda x: x[0] return OrderedDict(sorted(obj.items(), key=sort_func))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sortBy; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, block; 7, 8; 7, 10; 7, 16; 7, 45; 8, expression_statement; 8, 9; 9, string:'''sort results by given criteria'''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:criteria; 13, list:['seeds', 'size']; 13, 14; 13, 15; 14, string:'seeds'; 15, string:'size'; 16, for_statement; 16, 17; 16, 18; 16, 19; 17, identifier:k; 18, identifier:args; 19, block; 19, 20; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:in; 21, 22; 21, 23; 22, identifier:k; 23, identifier:criteria; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:results; 30, call; 30, 31; 30, 32; 31, identifier:sorted; 32, argument_list; 32, 33; 32, 36; 32, 42; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:results; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:key; 38, call; 38, 39; 38, 40; 39, identifier:attrgetter; 40, argument_list; 40, 41; 41, identifier:k; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:reverse; 44, True; 45, return_statement; 45, 46; 46, identifier:self
def sortBy(self, *args): '''sort results by given criteria''' criteria = ['seeds', 'size'] for k in args: if k in criteria: self.results = sorted( self.results, key=attrgetter(k), reverse=True) return self
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:rate_limited; 3, parameters; 3, 4; 4, identifier:max_per_second; 5, block; 5, 6; 5, 9; 5, 20; 5, 25; 5, 129; 6, import_statement; 6, 7; 7, dotted_name; 7, 8; 8, identifier:datetime; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:min_request_time; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:datetime; 15, identifier:timedelta; 16, argument_list; 16, 17; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:seconds; 19, identifier:max_per_second; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:last_time_called; 23, list:[None]; 23, 24; 24, None; 25, function_definition; 25, 26; 25, 27; 25, 29; 26, function_name:decorate; 27, parameters; 27, 28; 28, identifier:func; 29, block; 29, 30; 29, 121; 30, function_definition; 30, 31; 30, 32; 30, 37; 31, function_name:rate_limited_function; 32, parameters; 32, 33; 32, 35; 33, list_splat_pattern; 33, 34; 34, identifier:args; 35, dictionary_splat_pattern; 35, 36; 36, identifier:kwargs; 37, block; 37, 38; 37, 97; 37, 107; 37, 119; 38, if_statement; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:last_time_called; 41, integer:0; 42, block; 42, 43; 42, 57; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:delta; 46, binary_operator:-; 46, 47; 46, 54; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:datetime; 51, identifier:datetime; 52, identifier:now; 53, argument_list; 54, subscript; 54, 55; 54, 56; 55, identifier:last_time_called; 56, integer:0; 57, if_statement; 57, 58; 57, 65; 57, 74; 58, comparison_operator:<; 58, 59; 58, 60; 59, identifier:delta; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:datetime; 63, identifier:timedelta; 64, identifier:min; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, expression_list; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:chrw; 71, identifier:exceptions; 72, identifier:TimeIsBackToFront; 73, string:"Call the Doc!"; 74, elif_clause; 74, 75; 74, 78; 75, comparison_operator:<; 75, 76; 75, 77; 76, identifier:delta; 77, identifier:min_request_time; 78, block; 78, 79; 78, 89; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:msg; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, string:"Last request was {0}, should be at least {1}"; 85, identifier:format; 86, argument_list; 86, 87; 86, 88; 87, identifier:delta; 88, identifier:min_request_time; 89, raise_statement; 89, 90; 90, expression_list; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:chrw; 94, identifier:exceptions; 95, identifier:RequestRateTooHigh; 96, identifier:msg; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:ret; 100, call; 100, 101; 100, 102; 101, identifier:func; 102, argument_list; 102, 103; 102, 105; 103, list_splat; 103, 104; 104, identifier:args; 105, dictionary_splat; 105, 106; 106, identifier:kwargs; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:last_time_called; 111, integer:0; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:datetime; 116, identifier:datetime; 117, identifier:now; 118, argument_list; 119, return_statement; 119, 120; 120, identifier:ret; 121, return_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:functools; 125, identifier:update_wrapper; 126, argument_list; 126, 127; 126, 128; 127, identifier:rate_limited_function; 128, identifier:func; 129, return_statement; 129, 130; 130, identifier:decorate
def rate_limited(max_per_second): import datetime min_request_time = datetime.timedelta(seconds=max_per_second) last_time_called = [None] def decorate(func): def rate_limited_function(*args, **kwargs): if last_time_called[0]: delta = datetime.datetime.now() - last_time_called[0] if delta < datetime.timedelta.min: raise chrw.exceptions.TimeIsBackToFront, "Call the Doc!" elif delta < min_request_time: msg = "Last request was {0}, should be at least {1}".format( delta, min_request_time ) raise chrw.exceptions.RequestRateTooHigh, msg ret = func(*args, **kwargs) last_time_called[0] = datetime.datetime.now() return ret return functools.update_wrapper(rate_limited_function, func) return decorate
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:monotony; 3, parameters; 3, 4; 4, identifier:seq; 5, block; 5, 6; 6, if_statement; 6, 7; 6, 13; 6, 16; 6, 33; 7, comparison_operator:==; 7, 8; 7, 9; 8, identifier:seq; 9, call; 9, 10; 9, 11; 10, identifier:sorted; 11, argument_list; 11, 12; 12, identifier:seq; 13, block; 13, 14; 14, return_statement; 14, 15; 15, integer:1; 16, elif_clause; 16, 17; 16, 29; 17, comparison_operator:==; 17, 18; 17, 19; 18, identifier:seq; 19, call; 19, 20; 19, 21; 20, identifier:list; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:reversed; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 28, identifier:seq; 29, block; 29, 30; 30, return_statement; 30, 31; 31, unary_operator:-; 31, 32; 32, integer:1; 33, else_clause; 33, 34; 34, block; 34, 35; 35, return_statement; 35, 36; 36, integer:0
def monotony(seq): if seq == sorted(seq): return 1 elif seq == list(reversed(sorted(seq))): return -1 else: return 0
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:variables; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_operator:and; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:o; 17, identifier:Variable; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_docfilter; 22, argument_list; 22, 23; 23, identifier:o; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:filter; 30, argument_list; 30, 31; 30, 32; 31, identifier:p; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:doc; 37, identifier:values; 38, argument_list
def variables(self): p = lambda o: isinstance(o, Variable) and self._docfilter(o) return sorted(filter(p, self.doc.values()))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:classes; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_operator:and; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:o; 17, identifier:Class; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_docfilter; 22, argument_list; 22, 23; 23, identifier:o; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:filter; 30, argument_list; 30, 31; 30, 32; 31, identifier:p; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:doc; 37, identifier:values; 38, argument_list
def classes(self): p = lambda o: isinstance(o, Class) and self._docfilter(o) return sorted(filter(p, self.doc.values()))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:functions; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_operator:and; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:o; 17, identifier:Function; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_docfilter; 22, argument_list; 22, 23; 23, identifier:o; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:filter; 30, argument_list; 30, 31; 30, 32; 31, identifier:p; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:doc; 37, identifier:values; 38, argument_list
def functions(self): p = lambda o: isinstance(o, Function) and self._docfilter(o) return sorted(filter(p, self.doc.values()))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:submodules; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_operator:and; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:o; 17, identifier:Module; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_docfilter; 22, argument_list; 22, 23; 23, identifier:o; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:filter; 30, argument_list; 30, 31; 30, 32; 31, identifier:p; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:doc; 37, identifier:values; 38, argument_list
def submodules(self): p = lambda o: isinstance(o, Module) and self._docfilter(o) return sorted(filter(p, self.doc.values()))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:class_variables; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 26; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_operator:and; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:o; 17, identifier:Variable; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:module; 23, identifier:_docfilter; 24, argument_list; 24, 25; 25, identifier:o; 26, return_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:filter; 29, argument_list; 29, 30; 29, 31; 30, identifier:p; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:doc; 36, identifier:values; 37, argument_list
def class_variables(self): p = lambda o: isinstance(o, Variable) and self.module._docfilter(o) return filter(p, self.doc.values())
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:BEDIterator; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:filehandle; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sortedby; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:verbose; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:scoreType; 13, identifier:int; 14, default_parameter; 14, 15; 14, 16; 15, identifier:dropAfter; 16, None; 17, block; 17, 18; 17, 24; 17, 28; 17, 45; 17, 101; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:chromsSeen; 21, call; 21, 22; 21, 23; 22, identifier:set; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:prev; 27, None; 28, if_statement; 28, 29; 28, 37; 29, comparison_operator:==; 29, 30; 29, 36; 30, attribute; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:type; 33, argument_list; 33, 34; 34, identifier:filehandle; 35, identifier:__name__; 36, string:"str"; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:filehandle; 41, call; 41, 42; 41, 43; 42, identifier:open; 43, argument_list; 43, 44; 44, identifier:filehandle; 45, if_statement; 45, 46; 45, 47; 46, identifier:verbose; 47, block; 47, 48; 48, try_statement; 48, 49; 48, 78; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:pind; 53, call; 53, 54; 53, 55; 54, identifier:ProgressIndicator; 55, argument_list; 55, 56; 55, 68; 55, 71; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:totalToDo; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:os; 62, identifier:path; 63, identifier:getsize; 64, argument_list; 64, 65; 65, attribute; 65, 66; 65, 67; 66, identifier:filehandle; 67, identifier:name; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:messagePrefix; 70, string:"completed"; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:messageSuffix; 73, binary_operator:+; 73, 74; 73, 75; 74, string:"of processing "; 75, attribute; 75, 76; 75, 77; 76, identifier:filehandle; 77, identifier:name; 78, except_clause; 78, 79; 78, 85; 79, as_pattern; 79, 80; 79, 83; 80, tuple; 80, 81; 80, 82; 81, identifier:AttributeError; 82, identifier:OSError; 83, as_pattern_target; 83, 84; 84, identifier:e; 85, block; 85, 86; 85, 97; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:sys; 91, identifier:stderr; 92, identifier:write; 93, argument_list; 93, 94; 94, binary_operator:+; 94, 95; 94, 96; 95, string:"BEDIterator -- warning: "; 96, string:"unable to show progress for stream"; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:verbose; 100, False; 101, for_statement; 101, 102; 101, 103; 101, 104; 102, identifier:line; 103, identifier:filehandle; 104, block; 104, 105; 104, 124; 104, 134; 104, 165; 104, 208; 104, 222; 104, 311; 104, 387; 104, 390; 105, if_statement; 105, 106; 105, 107; 106, identifier:verbose; 107, block; 107, 108; 107, 118; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:pind; 112, identifier:done; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:filehandle; 116, identifier:tell; 117, argument_list; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:pind; 122, identifier:showProgress; 123, argument_list; 124, if_statement; 124, 125; 124, 132; 125, comparison_operator:==; 125, 126; 125, 131; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:line; 129, identifier:strip; 130, argument_list; 131, string:""; 132, block; 132, 133; 133, continue_statement; 134, try_statement; 134, 135; 134, 147; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:e; 139, call; 139, 140; 139, 141; 140, identifier:parseBEDString; 141, argument_list; 141, 142; 141, 143; 141, 144; 142, identifier:line; 143, identifier:scoreType; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:dropAfter; 146, identifier:dropAfter; 147, except_clause; 147, 148; 147, 152; 148, as_pattern; 148, 149; 148, 150; 149, identifier:GenomicIntervalError; 150, as_pattern_target; 150, 151; 151, identifier:e; 152, block; 152, 153; 153, raise_statement; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:BEDError; 156, argument_list; 156, 157; 157, binary_operator:+; 157, 158; 157, 164; 158, binary_operator:+; 158, 159; 158, 163; 159, call; 159, 160; 159, 161; 160, identifier:str; 161, argument_list; 161, 162; 162, identifier:e; 163, string:" on line "; 164, identifier:line; 165, if_statement; 165, 166; 165, 184; 166, parenthesized_expression; 166, 167; 167, boolean_operator:and; 167, 168; 167, 176; 168, parenthesized_expression; 168, 169; 169, boolean_operator:and; 169, 170; 169, 173; 170, comparison_operator:==; 170, 171; 170, 172; 171, identifier:sortedby; 172, identifier:ITERATOR_SORTED_NAME; 173, comparison_operator:is; 173, 174; 173, 175; 174, identifier:prev; 175, None; 176, parenthesized_expression; 176, 177; 177, comparison_operator:>; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:prev; 180, identifier:name; 181, attribute; 181, 182; 181, 183; 182, identifier:e; 183, identifier:name; 184, block; 184, 185; 185, raise_statement; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:BEDError; 188, argument_list; 188, 189; 189, binary_operator:+; 189, 190; 189, 205; 190, binary_operator:+; 190, 191; 190, 204; 191, binary_operator:+; 191, 192; 191, 201; 192, binary_operator:+; 192, 193; 192, 200; 193, binary_operator:+; 193, 194; 193, 199; 194, binary_operator:+; 194, 195; 194, 196; 195, string:"bed file "; 196, attribute; 196, 197; 196, 198; 197, identifier:filehandle; 198, identifier:name; 199, string:" not sorted by element name"; 200, string:" found "; 201, attribute; 201, 202; 201, 203; 202, identifier:e; 203, identifier:name; 204, string:" after "; 205, attribute; 205, 206; 205, 207; 206, identifier:prev; 207, identifier:name; 208, if_statement; 208, 209; 208, 212; 209, comparison_operator:is; 209, 210; 209, 211; 210, identifier:prev; 211, None; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:chromsSeen; 217, identifier:add; 218, argument_list; 218, 219; 219, attribute; 219, 220; 219, 221; 220, identifier:e; 221, identifier:chrom; 222, if_statement; 222, 223; 222, 238; 223, boolean_operator:and; 223, 224; 223, 231; 224, boolean_operator:and; 224, 225; 224, 228; 225, comparison_operator:is; 225, 226; 225, 227; 226, identifier:prev; 227, None; 228, comparison_operator:is; 228, 229; 228, 230; 229, identifier:sortedby; 230, None; 231, comparison_operator:==; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:e; 234, identifier:chrom; 235, attribute; 235, 236; 235, 237; 236, identifier:prev; 237, identifier:chrom; 238, block; 238, 239; 238, 275; 239, if_statement; 239, 240; 239, 251; 240, boolean_operator:and; 240, 241; 240, 244; 241, comparison_operator:==; 241, 242; 241, 243; 242, identifier:sortedby; 243, identifier:ITERATOR_SORTED_START; 244, comparison_operator:>; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:prev; 247, identifier:start; 248, attribute; 248, 249; 248, 250; 249, identifier:e; 250, identifier:start; 251, block; 251, 252; 252, raise_statement; 252, 253; 253, call; 253, 254; 253, 255; 254, identifier:BEDError; 255, argument_list; 255, 256; 256, binary_operator:+; 256, 257; 256, 271; 257, binary_operator:+; 257, 258; 257, 270; 258, binary_operator:+; 258, 259; 258, 266; 259, binary_operator:+; 259, 260; 259, 265; 260, binary_operator:+; 260, 261; 260, 262; 261, string:"bed file "; 262, attribute; 262, 263; 262, 264; 263, identifier:filehandle; 264, identifier:name; 265, string:" not sorted by start index - saw item "; 266, call; 266, 267; 266, 268; 267, identifier:str; 268, argument_list; 268, 269; 269, identifier:prev; 270, string:" before "; 271, call; 271, 272; 271, 273; 272, identifier:str; 273, argument_list; 273, 274; 274, identifier:e; 275, if_statement; 275, 276; 275, 287; 276, boolean_operator:and; 276, 277; 276, 280; 277, comparison_operator:==; 277, 278; 277, 279; 278, identifier:sortedby; 279, identifier:ITERATOR_SORTED_END; 280, comparison_operator:>; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:prev; 283, identifier:end; 284, attribute; 284, 285; 284, 286; 285, identifier:e; 286, identifier:end; 287, block; 287, 288; 288, raise_statement; 288, 289; 289, call; 289, 290; 289, 291; 290, identifier:BEDError; 291, argument_list; 291, 292; 292, binary_operator:+; 292, 293; 292, 307; 293, binary_operator:+; 293, 294; 293, 306; 294, binary_operator:+; 294, 295; 294, 302; 295, binary_operator:+; 295, 296; 295, 301; 296, binary_operator:+; 296, 297; 296, 298; 297, string:"bed file "; 298, attribute; 298, 299; 298, 300; 299, identifier:filehandle; 300, identifier:name; 301, string:" not sorted by end index - saw item "; 302, call; 302, 303; 302, 304; 303, identifier:str; 304, argument_list; 304, 305; 305, identifier:prev; 306, string:" before "; 307, call; 307, 308; 307, 309; 308, identifier:str; 309, argument_list; 309, 310; 310, identifier:e; 311, if_statement; 311, 312; 311, 323; 312, boolean_operator:and; 312, 313; 312, 316; 313, comparison_operator:is; 313, 314; 313, 315; 314, identifier:prev; 315, None; 316, comparison_operator:!=; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:prev; 319, identifier:chrom; 320, attribute; 320, 321; 320, 322; 321, identifier:e; 322, identifier:chrom; 323, block; 323, 324; 323, 378; 324, if_statement; 324, 325; 324, 353; 325, boolean_operator:and; 325, 326; 325, 338; 325, 339; 326, parenthesized_expression; 326, 327; 327, boolean_operator:or; 327, 328; 327, 335; 328, boolean_operator:or; 328, 329; 328, 332; 329, comparison_operator:==; 329, 330; 329, 331; 330, identifier:sortedby; 331, identifier:ITERATOR_SORTED_START; 332, comparison_operator:==; 332, 333; 332, 334; 333, identifier:sortedby; 334, identifier:ITERATOR_SORTED_END; 335, comparison_operator:==; 335, 336; 335, 337; 336, identifier:sortedby; 337, identifier:ITERATOR_SORTED_CHROM; 338, line_continuation:\; 339, parenthesized_expression; 339, 340; 340, boolean_operator:or; 340, 341; 340, 346; 341, comparison_operator:in; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:e; 344, identifier:chrom; 345, identifier:chromsSeen; 346, comparison_operator:>; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:prev; 349, identifier:chrom; 350, attribute; 350, 351; 350, 352; 351, identifier:e; 352, identifier:chrom; 353, block; 353, 354; 353, 369; 354, try_statement; 354, 355; 354, 362; 355, block; 355, 356; 356, expression_statement; 356, 357; 357, assignment; 357, 358; 357, 359; 358, identifier:e_fn; 359, attribute; 359, 360; 359, 361; 360, identifier:filehandle; 361, identifier:name; 362, except_clause; 362, 363; 362, 364; 363, identifier:AttributeError; 364, block; 364, 365; 365, expression_statement; 365, 366; 366, assignment; 366, 367; 366, 368; 367, identifier:e_fn; 368, string:"UNNAMED STREAM"; 369, raise_statement; 369, 370; 370, call; 370, 371; 370, 372; 371, identifier:BEDError; 372, argument_list; 372, 373; 373, binary_operator:+; 373, 374; 373, 377; 374, binary_operator:+; 374, 375; 374, 376; 375, string:"BED file "; 376, identifier:e_fn; 377, string:" not sorted by chrom"; 378, expression_statement; 378, 379; 379, call; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:chromsSeen; 382, identifier:add; 383, argument_list; 383, 384; 384, attribute; 384, 385; 384, 386; 385, identifier:e; 386, identifier:chrom; 387, expression_statement; 387, 388; 388, yield; 388, 389; 389, identifier:e; 390, expression_statement; 390, 391; 391, assignment; 391, 392; 391, 393; 392, identifier:prev; 393, identifier:e
def BEDIterator(filehandle, sortedby=None, verbose=False, scoreType=int, dropAfter=None): chromsSeen = set() prev = None if type(filehandle).__name__ == "str": filehandle = open(filehandle) if verbose: try: pind = ProgressIndicator(totalToDo=os.path.getsize(filehandle.name), messagePrefix="completed", messageSuffix="of processing " + filehandle.name) except (AttributeError, OSError) as e: sys.stderr.write("BEDIterator -- warning: " + "unable to show progress for stream") verbose = False for line in filehandle: if verbose: pind.done = filehandle.tell() pind.showProgress() if line.strip() == "": continue try: e = parseBEDString(line, scoreType, dropAfter=dropAfter) except GenomicIntervalError as e: raise BEDError(str(e) + " on line " + line) if ((sortedby == ITERATOR_SORTED_NAME and prev is not None) and (prev.name > e.name)): raise BEDError("bed file " + filehandle.name + " not sorted by element name" + " found " + e.name + " after " + prev.name) if prev is None: chromsSeen.add(e.chrom) if prev is not None and sortedby is not None and e.chrom == prev.chrom: if sortedby == ITERATOR_SORTED_START and prev.start > e.start: raise BEDError("bed file " + filehandle.name + " not sorted by start index - saw item " + str(prev) + " before " + str(e)) if sortedby == ITERATOR_SORTED_END and prev.end > e.end: raise BEDError("bed file " + filehandle.name + " not sorted by end index - saw item " + str(prev) + " before " + str(e)) if prev is not None and prev.chrom != e.chrom: if (sortedby == ITERATOR_SORTED_START or sortedby == ITERATOR_SORTED_END or sortedby == ITERATOR_SORTED_CHROM) and\ (e.chrom in chromsSeen or prev.chrom > e.chrom): try: e_fn = filehandle.name except AttributeError: e_fn = "UNNAMED STREAM" raise BEDError("BED file " + e_fn + " not sorted by chrom") chromsSeen.add(e.chrom) yield e prev = e
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:compress_and_sort_index; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 18; 5, 40; 5, 50; 5, 63; 5, 69; 5, 80; 5, 88; 5, 100; 5, 107; 5, 118; 5, 129; 5, 135; 5, 154; 5, 161; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:idx_fname; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, string:'{name}.{date}.mbox.csv'; 12, identifier:format; 13, argument_list; 13, 14; 14, dictionary_splat; 14, 15; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:__dict__; 18, try_statement; 18, 19; 18, 35; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:reader; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:csv; 26, identifier:reader; 27, argument_list; 27, 28; 27, 32; 28, call; 28, 29; 28, 30; 29, identifier:open; 30, argument_list; 30, 31; 31, identifier:idx_fname; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:dialect; 34, string:'excel-tab'; 35, except_clause; 35, 36; 35, 37; 36, identifier:IOError; 37, block; 37, 38; 38, return_statement; 38, 39; 39, False; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:index; 43, list_comprehension; 43, 44; 43, 45; 43, 48; 44, identifier:x; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:x; 47, identifier:reader; 48, if_clause; 48, 49; 49, identifier:x; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:sorted_index; 53, call; 53, 54; 53, 55; 54, identifier:sorted; 55, argument_list; 55, 56; 55, 57; 56, identifier:index; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:key; 59, call; 59, 60; 59, 61; 60, identifier:itemgetter; 61, argument_list; 61, 62; 62, integer:0; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:gzip_idx_fname; 66, binary_operator:+; 66, 67; 66, 68; 67, identifier:idx_fname; 68, string:'.gz'; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:header; 72, list:[ '\xef\xbb\xbf 'start', 'length', ]; 72, 73; 72, 78; 73, concatenated_string; 73, 74; 73, 75; 73, 77; 74, string:'\xef\xbb\xbf '; 75, ERROR; 75, 76; 76, identifier:start; 77, string:', '; 78, ERROR; 78, 79; 79, identifier:length; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:s; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:cStringIO; 86, identifier:StringIO; 87, argument_list; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:writer; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:csv; 94, identifier:writer; 95, argument_list; 95, 96; 95, 97; 96, identifier:s; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:dialect; 99, string:'excel-tab'; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:writer; 104, identifier:writerow; 105, argument_list; 105, 106; 106, identifier:header; 107, for_statement; 107, 108; 107, 109; 107, 110; 108, identifier:line; 109, identifier:sorted_index; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:writer; 115, identifier:writerow; 116, argument_list; 116, 117; 117, identifier:line; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:compressed_index; 121, call; 121, 122; 121, 123; 122, identifier:inline_compress_chunk; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:s; 127, identifier:getvalue; 128, argument_list; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:s; 133, identifier:close; 134, argument_list; 135, with_statement; 135, 136; 135, 146; 136, with_clause; 136, 137; 137, with_item; 137, 138; 138, as_pattern; 138, 139; 138, 144; 139, call; 139, 140; 139, 141; 140, identifier:open; 141, argument_list; 141, 142; 141, 143; 142, identifier:gzip_idx_fname; 143, string:'ab'; 144, as_pattern_target; 144, 145; 145, identifier:fp; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:fp; 151, identifier:write; 152, argument_list; 152, 153; 153, identifier:compressed_index; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:os; 158, identifier:remove; 159, argument_list; 159, 160; 160, identifier:idx_fname; 161, return_statement; 161, 162; 162, True
def compress_and_sort_index(self): idx_fname = '{name}.{date}.mbox.csv'.format(**self.__dict__) try: reader = csv.reader(open(idx_fname), dialect='excel-tab') except IOError: return False index = [x for x in reader if x] sorted_index = sorted(index, key=itemgetter(0)) gzip_idx_fname = idx_fname + '.gz' header = [ '\xef\xbb\xbf 'start', 'length', ] s = cStringIO.StringIO() writer = csv.writer(s, dialect='excel-tab') writer.writerow(header) for line in sorted_index: writer.writerow(line) compressed_index = inline_compress_chunk(s.getvalue()) s.close() with open(gzip_idx_fname, 'ab') as fp: fp.write(compressed_index) os.remove(idx_fname) return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:versions; 11, call; 11, 12; 11, 13; 12, identifier:OrderedDict; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:sorted; 16, argument_list; 16, 17; 16, 24; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:versions; 22, identifier:items; 23, argument_list; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:key; 26, lambda; 26, 27; 26, 29; 27, lambda_parameters; 27, 28; 28, identifier:v; 29, subscript; 29, 30; 29, 31; 30, identifier:v; 31, integer:0
def _sort(self): self.versions = OrderedDict(sorted(self.versions.items(), key=lambda v: v[0]))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_workspace_activities; 3, parameters; 3, 4; 3, 5; 4, identifier:brain; 5, default_parameter; 5, 6; 5, 7; 6, identifier:limit; 7, integer:1; 8, block; 8, 9; 8, 16; 8, 32; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:mb; 12, call; 12, 13; 12, 14; 13, identifier:queryUtility; 14, argument_list; 14, 15; 15, identifier:IMicroblogTool; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:items; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:mb; 22, identifier:context_values; 23, argument_list; 23, 24; 23, 29; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:brain; 27, identifier:getObject; 28, argument_list; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:limit; 31, identifier:limit; 32, return_statement; 32, 33; 33, list_comprehension; 33, 34; 33, 71; 34, dictionary; 34, 35; 34, 40; 34, 43; 34, 48; 35, pair; 35, 36; 35, 37; 36, string:'subject'; 37, attribute; 37, 38; 37, 39; 38, identifier:item; 39, identifier:creator; 40, pair; 40, 41; 40, 42; 41, string:'verb'; 42, string:'published'; 43, pair; 43, 44; 43, 45; 44, string:'object'; 45, attribute; 45, 46; 45, 47; 46, identifier:item; 47, identifier:text; 48, pair; 48, 49; 48, 50; 49, string:'time'; 50, dictionary; 50, 51; 50, 61; 51, pair; 51, 52; 51, 53; 52, string:'datetime'; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:item; 57, identifier:date; 58, identifier:strftime; 59, argument_list; 59, 60; 60, string:'%Y-%m-%d'; 61, pair; 61, 62; 61, 63; 62, string:'title'; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:item; 67, identifier:date; 68, identifier:strftime; 69, argument_list; 69, 70; 70, string:'%d %B %Y, %H:%M'; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:item; 73, identifier:items
def get_workspace_activities(brain, limit=1): mb = queryUtility(IMicroblogTool) items = mb.context_values(brain.getObject(), limit=limit) return [ { 'subject': item.creator, 'verb': 'published', 'object': item.text, 'time': { 'datetime': item.date.strftime('%Y-%m-%d'), 'title': item.date.strftime('%d %B %Y, %H:%M'), } } for item in items ]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_by; 3, parameters; 3, 4; 3, 5; 4, identifier:items; 5, identifier:attr; 6, block; 6, 7; 6, 38; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:key_func; 9, parameters; 9, 10; 10, identifier:item; 11, block; 11, 12; 12, try_statement; 12, 13; 12, 20; 13, block; 13, 14; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:getattr; 17, argument_list; 17, 18; 17, 19; 18, identifier:item; 19, identifier:attr; 20, except_clause; 20, 21; 20, 22; 21, identifier:AttributeError; 22, block; 22, 23; 23, try_statement; 23, 24; 23, 29; 24, block; 24, 25; 25, return_statement; 25, 26; 26, subscript; 26, 27; 26, 28; 27, identifier:item; 28, identifier:attr; 29, except_clause; 29, 30; 29, 31; 30, identifier:TypeError; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:getattr; 35, argument_list; 35, 36; 35, 37; 36, identifier:item; 37, identifier:attr; 38, return_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:sorted; 41, argument_list; 41, 42; 41, 43; 42, identifier:items; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:key; 45, identifier:key_func
def sort_by(items, attr): def key_func(item): try: return getattr(item, attr) except AttributeError: try: return item[attr] except TypeError: getattr(item, attr) return sorted(items, key=key_func)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorted_migrations; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 35; 6, if_statement; 6, 7; 6, 11; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_sorted_migrations; 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:_sorted_migrations; 17, call; 17, 18; 17, 19; 18, identifier:sorted; 19, argument_list; 19, 20; 19, 27; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:migration_registry; 25, identifier:items; 26, argument_list; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:key; 29, lambda; 29, 30; 29, 32; 30, lambda_parameters; 30, 31; 31, identifier:migration_tuple; 32, subscript; 32, 33; 32, 34; 33, identifier:migration_tuple; 34, integer:0; 35, return_statement; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_sorted_migrations
def sorted_migrations(self): if not self._sorted_migrations: self._sorted_migrations = sorted( self.migration_registry.items(), key=lambda migration_tuple: migration_tuple[0]) return self._sorted_migrations
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sorter; 3, parameters; 3, 4; 4, identifier:generated; 5, block; 5, 6; 5, 36; 5, 42; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:pairs; 9, list_comprehension; 9, 10; 9, 27; 10, tuple; 10, 11; 10, 19; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:os; 15, identifier:path; 16, identifier:dirname; 17, argument_list; 17, 18; 18, identifier:f; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:os; 23, identifier:path; 24, identifier:basename; 25, argument_list; 25, 26; 26, identifier:f; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:f; 29, call; 29, 30; 29, 31; 30, identifier:set; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:list; 34, argument_list; 34, 35; 35, identifier:generated; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:pairs; 40, identifier:sort; 41, argument_list; 42, return_statement; 42, 43; 43, list_comprehension; 43, 44; 43, 57; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:os; 48, identifier:path; 49, identifier:join; 50, argument_list; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:pair; 53, integer:0; 54, subscript; 54, 55; 54, 56; 55, identifier:pair; 56, integer:1; 57, for_in_clause; 57, 58; 57, 59; 58, identifier:pair; 59, identifier:pairs
def _sorter(generated): pairs = [(os.path.dirname(f), os.path.basename(f)) for f in set(list(generated))] pairs.sort() return [os.path.join(pair[0], pair[1]) for pair in pairs]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:regionsIntersection; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:s1; 5, identifier:s2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:collapse; 8, True; 9, block; 9, 10; 9, 14; 9, 21; 9, 28; 9, 45; 9, 49; 9, 53; 9, 346; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:debug; 13, False; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:s1_c; 17, call; 17, 18; 17, 19; 18, identifier:collapseRegions; 19, argument_list; 19, 20; 20, identifier:s1; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:s2_c; 24, call; 24, 25; 24, 26; 25, identifier:collapseRegions; 26, argument_list; 26, 27; 27, identifier:s2; 28, if_statement; 28, 29; 28, 42; 29, boolean_operator:or; 29, 30; 29, 36; 30, comparison_operator:==; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, identifier:s1_c; 35, integer:0; 36, comparison_operator:==; 36, 37; 36, 41; 37, call; 37, 38; 37, 39; 38, identifier:len; 39, argument_list; 39, 40; 40, identifier:s2_c; 41, integer:0; 42, block; 42, 43; 43, return_statement; 43, 44; 44, list:[]; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:res; 48, list:[]; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:j; 52, integer:0; 53, for_statement; 53, 54; 53, 55; 53, 63; 54, identifier:i; 55, call; 55, 56; 55, 57; 56, identifier:range; 57, argument_list; 57, 58; 57, 59; 58, integer:0; 59, call; 59, 60; 59, 61; 60, identifier:len; 61, argument_list; 61, 62; 62, identifier:s1_c; 63, block; 63, 64; 63, 85; 63, 111; 63, 162; 63, 209; 63, 321; 63, 325; 64, if_statement; 64, 65; 64, 66; 65, identifier:debug; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:sys; 72, identifier:stderr; 73, identifier:write; 74, argument_list; 74, 75; 75, binary_operator:+; 75, 76; 75, 84; 76, binary_operator:+; 76, 77; 76, 78; 77, string:"processing from s1_c : "; 78, call; 78, 79; 78, 80; 79, identifier:str; 80, argument_list; 80, 81; 81, subscript; 81, 82; 81, 83; 82, identifier:s1_c; 83, identifier:i; 84, string:"\n"; 85, if_statement; 85, 86; 85, 87; 86, identifier:debug; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:sys; 93, identifier:stderr; 94, identifier:write; 95, argument_list; 95, 96; 96, binary_operator:+; 96, 97; 96, 110; 97, binary_operator:+; 97, 98; 97, 106; 98, binary_operator:+; 98, 99; 98, 105; 99, binary_operator:+; 99, 100; 99, 101; 100, string:"i = "; 101, call; 101, 102; 101, 103; 102, identifier:str; 103, argument_list; 103, 104; 104, identifier:i; 105, string:" and j = "; 106, call; 106, 107; 106, 108; 107, identifier:str; 108, argument_list; 108, 109; 109, identifier:j; 110, string:"\n"; 111, while_statement; 111, 112; 111, 157; 112, parenthesized_expression; 112, 113; 113, boolean_operator:and; 113, 114; 113, 120; 114, comparison_operator:<; 114, 115; 114, 116; 115, identifier:j; 116, call; 116, 117; 116, 118; 117, identifier:len; 118, argument_list; 118, 119; 119, identifier:s2_c; 120, parenthesized_expression; 120, 121; 121, boolean_operator:or; 121, 122; 121, 133; 122, comparison_operator:<; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:s2_c; 126, identifier:j; 127, identifier:chrom; 128, attribute; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:s1_c; 131, identifier:i; 132, identifier:chrom; 133, parenthesized_expression; 133, 134; 134, boolean_operator:and; 134, 135; 134, 146; 135, comparison_operator:==; 135, 136; 135, 141; 136, attribute; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:s2_c; 139, identifier:j; 140, identifier:chrom; 141, attribute; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:s1_c; 144, identifier:i; 145, identifier:chrom; 146, comparison_operator:<=; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:s2_c; 150, identifier:j; 151, identifier:end; 152, attribute; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:s1_c; 155, identifier:i; 156, identifier:start; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, augmented_assignment:+=; 159, 160; 159, 161; 160, identifier:j; 161, integer:1; 162, if_statement; 162, 163; 162, 207; 163, boolean_operator:or; 163, 164; 163, 182; 163, 183; 164, boolean_operator:or; 164, 165; 164, 171; 165, comparison_operator:>=; 165, 166; 165, 167; 166, identifier:j; 167, call; 167, 168; 167, 169; 168, identifier:len; 169, argument_list; 169, 170; 170, identifier:s2_c; 171, comparison_operator:>; 171, 172; 171, 177; 172, attribute; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:s2_c; 175, identifier:j; 176, identifier:chrom; 177, attribute; 177, 178; 177, 181; 178, subscript; 178, 179; 178, 180; 179, identifier:s1_c; 180, identifier:i; 181, identifier:chrom; 182, line_continuation:\; 183, parenthesized_expression; 183, 184; 184, boolean_operator:and; 184, 185; 184, 196; 185, comparison_operator:==; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:s2_c; 189, identifier:j; 190, identifier:chrom; 191, attribute; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:s1_c; 194, identifier:i; 195, identifier:chrom; 196, comparison_operator:>=; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:s2_c; 200, identifier:j; 201, identifier:start; 202, attribute; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:s1_c; 205, identifier:i; 206, identifier:end; 207, block; 207, 208; 208, continue_statement; 209, while_statement; 209, 210; 209, 221; 210, comparison_operator:<; 210, 211; 210, 216; 211, attribute; 211, 212; 211, 215; 212, subscript; 212, 213; 212, 214; 213, identifier:s2_c; 214, identifier:j; 215, identifier:start; 216, attribute; 216, 217; 216, 220; 217, subscript; 217, 218; 217, 219; 218, identifier:s1_c; 219, identifier:i; 220, identifier:end; 221, block; 221, 222; 221, 238; 221, 254; 221, 270; 221, 289; 221, 296; 221, 300; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:s; 225, call; 225, 226; 225, 227; 226, identifier:max; 227, argument_list; 227, 228; 227, 233; 228, attribute; 228, 229; 228, 232; 229, subscript; 229, 230; 229, 231; 230, identifier:s1_c; 231, identifier:i; 232, identifier:start; 233, attribute; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:s2_c; 236, identifier:j; 237, identifier:start; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:e; 241, call; 241, 242; 241, 243; 242, identifier:min; 243, argument_list; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:s1_c; 247, identifier:i; 248, identifier:end; 249, attribute; 249, 250; 249, 253; 250, subscript; 250, 251; 250, 252; 251, identifier:s2_c; 252, identifier:j; 253, identifier:end; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:overlap; 257, call; 257, 258; 257, 259; 258, identifier:GenomicInterval; 259, argument_list; 259, 260; 259, 265; 259, 266; 259, 267; 259, 268; 259, 269; 260, attribute; 260, 261; 260, 264; 261, subscript; 261, 262; 261, 263; 262, identifier:s1_c; 263, identifier:i; 264, identifier:chrom; 265, identifier:s; 266, identifier:e; 267, string:"X"; 268, integer:0; 269, string:"+"; 270, if_statement; 270, 271; 270, 272; 271, identifier:debug; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 280; 275, attribute; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:sys; 278, identifier:stderr; 279, identifier:write; 280, argument_list; 280, 281; 281, binary_operator:+; 281, 282; 281, 288; 282, binary_operator:+; 282, 283; 282, 284; 283, string:"\tadding to overlaps: "; 284, call; 284, 285; 284, 286; 285, identifier:str; 286, argument_list; 286, 287; 287, identifier:overlap; 288, string:"\n"; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:res; 293, identifier:append; 294, argument_list; 294, 295; 295, identifier:overlap; 296, expression_statement; 296, 297; 297, augmented_assignment:+=; 297, 298; 297, 299; 298, identifier:j; 299, integer:1; 300, if_statement; 300, 301; 300, 319; 301, boolean_operator:or; 301, 302; 301, 308; 302, comparison_operator:>=; 302, 303; 302, 304; 303, identifier:j; 304, call; 304, 305; 304, 306; 305, identifier:len; 306, argument_list; 306, 307; 307, identifier:s2_c; 308, comparison_operator:!=; 308, 309; 308, 314; 309, attribute; 309, 310; 309, 313; 310, subscript; 310, 311; 310, 312; 311, identifier:s2_c; 312, identifier:j; 313, identifier:chrom; 314, attribute; 314, 315; 314, 318; 315, subscript; 315, 316; 315, 317; 316, identifier:s1_c; 317, identifier:i; 318, identifier:chrom; 319, block; 319, 320; 320, break_statement; 321, expression_statement; 321, 322; 322, augmented_assignment:-=; 322, 323; 322, 324; 323, identifier:j; 324, integer:1; 325, if_statement; 325, 326; 325, 327; 326, identifier:debug; 327, block; 327, 328; 328, expression_statement; 328, 329; 329, call; 329, 330; 329, 335; 330, attribute; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:sys; 333, identifier:stderr; 334, identifier:write; 335, argument_list; 335, 336; 336, binary_operator:+; 336, 337; 336, 345; 337, binary_operator:+; 337, 338; 337, 339; 338, string:"\tmoving s2_c index back to "; 339, call; 339, 340; 339, 341; 340, identifier:str; 341, argument_list; 341, 342; 342, subscript; 342, 343; 342, 344; 343, identifier:s2_c; 344, identifier:j; 345, string:"\n"; 346, return_statement; 346, 347; 347, identifier:res
def regionsIntersection(s1, s2, collapse=True): debug = False s1_c = collapseRegions(s1) s2_c = collapseRegions(s2) if len(s1_c) == 0 or len(s2_c) == 0: return [] res = [] j = 0 for i in range(0, len(s1_c)): if debug: sys.stderr.write("processing from s1_c : " + str(s1_c[i]) + "\n") if debug: sys.stderr.write("i = " + str(i) + " and j = " + str(j) + "\n") while (j < len(s2_c) and (s2_c[j].chrom < s1_c[i].chrom or (s2_c[j].chrom == s1_c[i].chrom and s2_c[j].end <= s1_c[i].start))): j += 1 if j >= len(s2_c) or s2_c[j].chrom > s1_c[i].chrom or \ (s2_c[j].chrom == s1_c[i].chrom and s2_c[j].start >= s1_c[i].end): continue while s2_c[j].start < s1_c[i].end: s = max(s1_c[i].start, s2_c[j].start) e = min(s1_c[i].end, s2_c[j].end) overlap = GenomicInterval(s1_c[i].chrom, s, e, "X", 0, "+") if debug: sys.stderr.write("\tadding to overlaps: " + str(overlap) + "\n") res.append(overlap) j += 1 if j >= len(s2_c) or s2_c[j].chrom != s1_c[i].chrom: break j -= 1 if debug: sys.stderr.write("\tmoving s2_c index back to " + str(s2_c[j]) + "\n") return res
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:bucketIterator; 3, parameters; 3, 4; 3, 5; 4, identifier:elements; 5, identifier:buckets; 6, block; 6, 7; 6, 66; 6, 200; 6, 204; 6, 208; 6, 216; 7, function_definition; 7, 8; 7, 9; 7, 12; 8, function_name:check_sorted; 9, parameters; 9, 10; 9, 11; 10, identifier:current; 11, identifier:previous; 12, block; 12, 13; 13, if_statement; 13, 14; 13, 48; 14, boolean_operator:and; 14, 15; 14, 19; 14, 20; 15, parenthesized_expression; 15, 16; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:previous; 18, None; 19, line_continuation:\; 20, parenthesized_expression; 20, 21; 21, boolean_operator:or; 21, 22; 21, 30; 22, parenthesized_expression; 22, 23; 23, comparison_operator:>; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:previous; 26, identifier:chrom; 27, attribute; 27, 28; 27, 29; 28, identifier:current; 29, identifier:chrom; 30, parenthesized_expression; 30, 31; 31, boolean_operator:and; 31, 32; 31, 40; 32, parenthesized_expression; 32, 33; 33, comparison_operator:==; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:previous; 36, identifier:chrom; 37, attribute; 37, 38; 37, 39; 38, identifier:current; 39, identifier:chrom; 40, parenthesized_expression; 40, 41; 41, comparison_operator:>; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:previous; 44, identifier:start; 45, attribute; 45, 46; 45, 47; 46, identifier:current; 47, identifier:start; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:GenomicIntervalError; 52, argument_list; 52, 53; 53, binary_operator:+; 53, 54; 53, 62; 54, binary_operator:+; 54, 55; 54, 61; 55, binary_operator:+; 55, 56; 55, 57; 56, string:"elements not sorted. Saw "; 57, call; 57, 58; 57, 59; 58, identifier:str; 59, argument_list; 59, 60; 60, identifier:previous; 61, string:" before "; 62, call; 62, 63; 62, 64; 63, identifier:str; 64, argument_list; 64, 65; 65, identifier:current; 66, function_definition; 66, 67; 66, 68; 66, 74; 67, function_name:updateOpen; 68, parameters; 68, 69; 68, 70; 68, 71; 68, 72; 68, 73; 69, identifier:openHeap; 70, identifier:elementIterator; 71, identifier:bucketChrom; 72, identifier:bucketStart; 73, identifier:bucketEnd; 74, block; 74, 75; 74, 117; 75, while_statement; 75, 76; 75, 111; 76, boolean_operator:and; 76, 77; 76, 83; 77, comparison_operator:>; 77, 78; 77, 82; 78, call; 78, 79; 78, 80; 79, identifier:len; 80, argument_list; 80, 81; 81, identifier:openHeap; 82, integer:0; 83, parenthesized_expression; 83, 84; 84, boolean_operator:or; 84, 85; 84, 93; 85, parenthesized_expression; 85, 86; 86, comparison_operator:<; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:openHeap; 90, integer:0; 91, identifier:chrom; 92, identifier:bucketChrom; 93, parenthesized_expression; 93, 94; 94, boolean_operator:and; 94, 95; 94, 103; 95, parenthesized_expression; 95, 96; 96, comparison_operator:==; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:openHeap; 100, integer:0; 101, identifier:chrom; 102, identifier:bucketChrom; 103, parenthesized_expression; 103, 104; 104, comparison_operator:<=; 104, 105; 104, 110; 105, attribute; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:openHeap; 108, integer:0; 109, identifier:end; 110, identifier:bucketStart; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:heappop; 115, argument_list; 115, 116; 116, identifier:openHeap; 117, while_statement; 117, 118; 117, 162; 118, boolean_operator:and; 118, 119; 118, 127; 118, 128; 119, parenthesized_expression; 119, 120; 120, comparison_operator:is; 120, 121; 120, 126; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:elementIterator; 124, identifier:peek; 125, argument_list; 126, None; 127, line_continuation:\; 128, parenthesized_expression; 128, 129; 129, boolean_operator:or; 129, 130; 129, 140; 130, parenthesized_expression; 130, 131; 131, comparison_operator:<; 131, 132; 131, 139; 132, attribute; 132, 133; 132, 138; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:elementIterator; 136, identifier:peek; 137, argument_list; 138, identifier:chrom; 139, identifier:bucketChrom; 140, parenthesized_expression; 140, 141; 141, boolean_operator:and; 141, 142; 141, 152; 142, parenthesized_expression; 142, 143; 143, comparison_operator:==; 143, 144; 143, 151; 144, attribute; 144, 145; 144, 150; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:elementIterator; 148, identifier:peek; 149, argument_list; 150, identifier:chrom; 151, identifier:bucketChrom; 152, parenthesized_expression; 152, 153; 153, comparison_operator:<; 153, 154; 153, 161; 154, attribute; 154, 155; 154, 160; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:elementIterator; 158, identifier:peek; 159, argument_list; 160, identifier:start; 161, identifier:bucketEnd; 162, block; 162, 163; 162, 171; 162, 194; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:e; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:elementIterator; 169, identifier:__next__; 170, argument_list; 171, if_statement; 171, 172; 171, 192; 172, boolean_operator:or; 172, 173; 172, 179; 172, 180; 173, parenthesized_expression; 173, 174; 174, comparison_operator:<; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:e; 177, identifier:chrom; 178, identifier:bucketChrom; 179, line_continuation:\; 180, parenthesized_expression; 180, 181; 181, boolean_operator:and; 181, 182; 181, 187; 182, comparison_operator:==; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:e; 185, identifier:chrom; 186, identifier:bucketChrom; 187, comparison_operator:<=; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:e; 190, identifier:end; 191, identifier:bucketStart; 192, block; 192, 193; 193, continue_statement; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:heappush; 197, argument_list; 197, 198; 197, 199; 198, identifier:openHeap; 199, identifier:e; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:openElems; 203, list:[]; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:prevBucket; 207, None; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:elementIter; 211, call; 211, 212; 211, 213; 212, identifier:AutoApplyIterator; 213, argument_list; 213, 214; 213, 215; 214, identifier:elements; 215, identifier:check_sorted; 216, for_statement; 216, 217; 216, 218; 216, 219; 217, identifier:bucket; 218, identifier:buckets; 219, block; 219, 220; 219, 269; 219, 284; 219, 301; 220, if_statement; 220, 221; 220, 251; 221, boolean_operator:and; 221, 222; 221, 225; 222, comparison_operator:is; 222, 223; 222, 224; 223, identifier:prevBucket; 224, None; 225, parenthesized_expression; 225, 226; 226, boolean_operator:or; 226, 227; 226, 235; 227, parenthesized_expression; 227, 228; 228, comparison_operator:<; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:bucket; 231, identifier:chrom; 232, attribute; 232, 233; 232, 234; 233, identifier:prevBucket; 234, identifier:chrom; 235, parenthesized_expression; 235, 236; 236, boolean_operator:and; 236, 237; 236, 244; 237, comparison_operator:==; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:bucket; 240, identifier:chrom; 241, attribute; 241, 242; 241, 243; 242, identifier:prevBucket; 243, identifier:chrom; 244, comparison_operator:<; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:bucket; 247, identifier:start; 248, attribute; 248, 249; 248, 250; 249, identifier:prevBucket; 250, identifier:start; 251, block; 251, 252; 252, raise_statement; 252, 253; 253, call; 253, 254; 253, 255; 254, identifier:GenomicIntervalError; 255, argument_list; 255, 256; 256, binary_operator:+; 256, 257; 256, 265; 257, binary_operator:+; 257, 258; 257, 264; 258, binary_operator:+; 258, 259; 258, 260; 259, string:"regions-of-interest are not sorted. Saw "; 260, call; 260, 261; 260, 262; 261, identifier:str; 262, argument_list; 262, 263; 263, identifier:prevBucket; 264, string:" before "; 265, call; 265, 266; 265, 267; 266, identifier:str; 267, argument_list; 267, 268; 268, identifier:bucket; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 272; 271, identifier:updateOpen; 272, argument_list; 272, 273; 272, 274; 272, 275; 272, 278; 272, 281; 273, identifier:openElems; 274, identifier:elementIter; 275, attribute; 275, 276; 275, 277; 276, identifier:bucket; 277, identifier:chrom; 278, attribute; 278, 279; 278, 280; 279, identifier:bucket; 280, identifier:start; 281, attribute; 281, 282; 281, 283; 282, identifier:bucket; 283, identifier:end; 284, expression_statement; 284, 285; 285, yield; 285, 286; 286, expression_list; 286, 287; 286, 288; 287, identifier:bucket; 288, list_comprehension; 288, 289; 288, 290; 288, 293; 289, identifier:x; 290, for_in_clause; 290, 291; 290, 292; 291, identifier:x; 292, identifier:openElems; 293, if_clause; 293, 294; 294, comparison_operator:<; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:x; 297, identifier:start; 298, attribute; 298, 299; 298, 300; 299, identifier:bucket; 300, identifier:end; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:prevBucket; 304, identifier:bucket
def bucketIterator(elements, buckets): def check_sorted(current, previous): if (previous is not None) and \ ((previous.chrom > current.chrom) or ((previous.chrom == current.chrom) and (previous.start > current.start))): raise GenomicIntervalError("elements not sorted. Saw " + str(previous) + " before " + str(current)) def updateOpen(openHeap, elementIterator, bucketChrom, bucketStart, bucketEnd): while len(openHeap) > 0 and ((openHeap[0].chrom < bucketChrom) or ((openHeap[0].chrom == bucketChrom) and (openHeap[0].end <= bucketStart))): heappop(openHeap) while (elementIterator.peek() is not None) and \ ((elementIterator.peek().chrom < bucketChrom) or ((elementIterator.peek().chrom == bucketChrom) and (elementIterator.peek().start < bucketEnd))): e = elementIterator.__next__() if (e.chrom < bucketChrom) or \ (e.chrom == bucketChrom and e.end <= bucketStart): continue heappush(openHeap, e) openElems = [] prevBucket = None elementIter = AutoApplyIterator(elements, check_sorted) for bucket in buckets: if prevBucket is not None and ((bucket.chrom < prevBucket.chrom) or (bucket.chrom == prevBucket.chrom and bucket.start < prevBucket.start)): raise GenomicIntervalError("regions-of-interest are not sorted. Saw " + str(prevBucket) + " before " + str(bucket)) updateOpen(openElems, elementIter, bucket.chrom, bucket. start, bucket.end) yield bucket, [x for x in openElems if x.start < bucket.end] prevBucket = bucket
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_ordered; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:generator; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 28; 9, 45; 9, 51; 9, 63; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:unordered_dict; 13, dictionary_comprehension; 13, 14; 13, 17; 14, pair; 14, 15; 14, 16; 15, identifier:k; 16, identifier:v; 17, for_in_clause; 17, 18; 17, 21; 18, pattern_list; 18, 19; 18, 20; 19, identifier:k; 20, identifier:v; 21, call; 21, 22; 21, 23; 22, identifier:generator; 23, argument_list; 23, 24; 23, 26; 24, list_splat; 24, 25; 25, identifier:args; 26, dictionary_splat; 26, 27; 27, identifier:kwargs; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:keys; 31, call; 31, 32; 31, 33; 32, identifier:sorted; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:list; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 44; 38, attribute; 38, 39; 38, 43; 39, call; 39, 40; 39, 41; 40, identifier:dict; 41, argument_list; 41, 42; 42, identifier:unordered_dict; 43, identifier:keys; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:result; 48, call; 48, 49; 48, 50; 49, identifier:OrderedDict; 50, argument_list; 51, for_statement; 51, 52; 51, 53; 51, 54; 52, identifier:key; 53, identifier:keys; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:result; 59, identifier:key; 60, subscript; 60, 61; 60, 62; 61, identifier:unordered_dict; 62, identifier:key; 63, return_statement; 63, 64; 64, identifier:result
def _ordered(generator, *args, **kwargs): unordered_dict = {k: v for k, v in generator(*args, **kwargs)} keys = sorted(list(dict(unordered_dict).keys())) result = OrderedDict() for key in keys: result[key] = unordered_dict[key] return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:str2dict_keys; 3, parameters; 3, 4; 4, identifier:str_in; 5, block; 5, 6; 5, 8; 5, 15; 5, 22; 6, expression_statement; 6, 7; 7, string:''' Extracts the keys from a string that represents a dict and returns them sorted by key. Args: str_in (string) that contains python dict Returns: (list) with keys or None if no valid dict was found Raises: - '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:tmp_dict; 11, call; 11, 12; 11, 13; 12, identifier:str2dict; 13, argument_list; 13, 14; 14, identifier:str_in; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:tmp_dict; 18, None; 19, block; 19, 20; 20, return_statement; 20, 21; 21, None; 22, return_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:sorted; 25, argument_list; 25, 26; 26, list_comprehension; 26, 27; 26, 28; 27, identifier:k; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:k; 30, identifier:tmp_dict
def str2dict_keys(str_in): ''' Extracts the keys from a string that represents a dict and returns them sorted by key. Args: str_in (string) that contains python dict Returns: (list) with keys or None if no valid dict was found Raises: - ''' tmp_dict = str2dict(str_in) if tmp_dict is None: return None return sorted([k for k in tmp_dict])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:str2dict_values; 3, parameters; 3, 4; 4, identifier:str_in; 5, block; 5, 6; 5, 8; 5, 15; 5, 22; 6, expression_statement; 6, 7; 7, string:''' Extracts the values from a string that represents a dict and returns them sorted by key. Args: str_in (string) that contains python dict Returns: (list) with values or None if no valid dict was found Raises: - '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:tmp_dict; 11, call; 11, 12; 11, 13; 12, identifier:str2dict; 13, argument_list; 13, 14; 14, identifier:str_in; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:tmp_dict; 18, None; 19, block; 19, 20; 20, return_statement; 20, 21; 21, None; 22, return_statement; 22, 23; 23, list_comprehension; 23, 24; 23, 27; 24, subscript; 24, 25; 24, 26; 25, identifier:tmp_dict; 26, identifier:key; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:key; 29, call; 29, 30; 29, 31; 30, identifier:sorted; 31, generator_expression; 31, 32; 31, 33; 32, identifier:k; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:k; 35, identifier:tmp_dict
def str2dict_values(str_in): ''' Extracts the values from a string that represents a dict and returns them sorted by key. Args: str_in (string) that contains python dict Returns: (list) with values or None if no valid dict was found Raises: - ''' tmp_dict = str2dict(str_in) if tmp_dict is None: return None return [tmp_dict[key] for key in sorted(k for k in tmp_dict)]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:to_json; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, keyword_separator; 6, default_parameter; 6, 7; 6, 8; 7, identifier:include_keys; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:exclude_keys; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:use_default_excludes; 14, True; 15, default_parameter; 15, 16; 15, 17; 16, identifier:pretty; 17, False; 18, block; 18, 19; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:to_json; 22, argument_list; 22, 23; 22, 37; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:to_dict; 27, argument_list; 27, 28; 27, 31; 27, 34; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:include_keys; 30, identifier:include_keys; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:exclude_keys; 33, identifier:exclude_keys; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:use_default_excludes; 36, identifier:use_default_excludes; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:pretty; 39, identifier:pretty
def to_json(self, *, include_keys=None, exclude_keys=None, use_default_excludes=True, pretty=False): return to_json( self.to_dict( include_keys=include_keys, exclude_keys=exclude_keys, use_default_excludes=use_default_excludes), pretty=pretty)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 34; 2, function_name:get_annotations; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 4, identifier:cls; 5, identifier:target; 6, default_parameter; 6, 7; 6, 8; 7, identifier:exclude; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:ctx; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:select; 14, lambda; 14, 15; 14, 18; 15, lambda_parameters; 15, 16; 16, list_splat_pattern; 16, 17; 17, identifier:p; 18, True; 19, default_parameter; 19, 20; 19, 21; 20, identifier:mindepth; 21, integer:0; 22, default_parameter; 22, 23; 22, 24; 23, identifier:maxdepth; 24, integer:0; 25, default_parameter; 25, 26; 25, 27; 26, identifier:followannotated; 27, True; 28, default_parameter; 28, 29; 28, 30; 29, identifier:public; 30, True; 31, default_parameter; 31, 32; 31, 33; 32, identifier:_history; 33, None; 34, block; 34, 35; 34, 39; 34, 226; 34, 335; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:result; 38, list:[]; 39, if_statement; 39, 40; 39, 43; 40, comparison_operator:<=; 40, 41; 40, 42; 41, identifier:mindepth; 42, integer:0; 43, block; 43, 44; 43, 70; 43, 142; 43, 151; 44, try_statement; 44, 45; 44, 63; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:annotations_by_ctx; 49, call; 49, 50; 49, 51; 50, identifier:get_property; 51, argument_list; 51, 52; 51, 55; 51, 60; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:elt; 54, identifier:target; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:key; 57, attribute; 57, 58; 57, 59; 58, identifier:Annotation; 59, identifier:__ANNOTATIONS_KEY__; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:ctx; 62, identifier:ctx; 63, except_clause; 63, 64; 63, 65; 64, identifier:TypeError; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:annotations_by_ctx; 69, dictionary; 70, if_statement; 70, 71; 70, 73; 71, not_operator; 71, 72; 72, identifier:annotations_by_ctx; 73, block; 73, 74; 74, if_statement; 74, 75; 74, 79; 74, 122; 75, call; 75, 76; 75, 77; 76, identifier:ismethod; 77, argument_list; 77, 78; 78, identifier:target; 79, block; 79, 80; 79, 87; 79, 104; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:func; 83, call; 83, 84; 83, 85; 84, identifier:get_method_function; 85, argument_list; 85, 86; 86, identifier:target; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:annotations_by_ctx; 90, call; 90, 91; 90, 92; 91, identifier:get_property; 92, argument_list; 92, 93; 92, 96; 92, 101; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:elt; 95, identifier:func; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:key; 98, attribute; 98, 99; 98, 100; 99, identifier:Annotation; 100, identifier:__ANNOTATIONS_KEY__; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:ctx; 103, identifier:ctx; 104, if_statement; 104, 105; 104, 107; 105, not_operator; 105, 106; 106, identifier:annotations_by_ctx; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:annotations_by_ctx; 111, call; 111, 112; 111, 113; 112, identifier:get_property; 113, argument_list; 113, 114; 113, 117; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:elt; 116, identifier:func; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:key; 119, attribute; 119, 120; 119, 121; 120, identifier:Annotation; 121, identifier:__ANNOTATIONS_KEY__; 122, elif_clause; 122, 123; 122, 127; 123, call; 123, 124; 123, 125; 124, identifier:isfunction; 125, argument_list; 125, 126; 126, identifier:target; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:annotations_by_ctx; 131, call; 131, 132; 131, 133; 132, identifier:get_property; 133, argument_list; 133, 134; 133, 137; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:elt; 136, identifier:target; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:key; 139, attribute; 139, 140; 139, 141; 140, identifier:Annotation; 141, identifier:__ANNOTATIONS_KEY__; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:exclude; 145, conditional_expression:if; 145, 146; 145, 147; 145, 150; 146, tuple; 147, comparison_operator:is; 147, 148; 147, 149; 148, identifier:exclude; 149, None; 150, identifier:exclude; 151, for_statement; 151, 152; 151, 155; 151, 156; 152, pattern_list; 152, 153; 152, 154; 153, identifier:elt; 154, identifier:annotations; 155, identifier:annotations_by_ctx; 156, block; 156, 157; 157, for_statement; 157, 158; 157, 159; 157, 160; 158, identifier:annotation; 159, identifier:annotations; 160, block; 160, 161; 160, 174; 160, 185; 160, 197; 161, if_statement; 161, 162; 161, 167; 162, call; 162, 163; 162, 164; 163, identifier:isinstance; 164, argument_list; 164, 165; 164, 166; 165, identifier:annotation; 166, identifier:StopPropagation; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:exclude; 171, attribute; 171, 172; 171, 173; 172, identifier:annotation; 173, identifier:annotation_types; 174, if_statement; 174, 175; 174, 183; 175, boolean_operator:and; 175, 176; 175, 179; 176, comparison_operator:is; 176, 177; 176, 178; 177, identifier:elt; 178, identifier:target; 179, not_operator; 179, 180; 180, attribute; 180, 181; 180, 182; 181, identifier:annotation; 182, identifier:propagate; 183, block; 183, 184; 184, continue_statement; 185, if_statement; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:annotation; 188, identifier:override; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, augmented_assignment:+=; 191, 192; 191, 193; 192, identifier:exclude; 193, tuple; 193, 194; 194, attribute; 194, 195; 194, 196; 195, identifier:annotation; 196, identifier:__class__; 197, if_statement; 197, 198; 197, 218; 198, parenthesized_expression; 198, 199; 199, boolean_operator:and; 199, 200; 199, 212; 200, boolean_operator:and; 200, 201; 200, 206; 201, call; 201, 202; 201, 203; 202, identifier:isinstance; 203, argument_list; 203, 204; 203, 205; 204, identifier:annotation; 205, identifier:cls; 206, not_operator; 206, 207; 207, call; 207, 208; 207, 209; 208, identifier:isinstance; 209, argument_list; 209, 210; 209, 211; 210, identifier:annotation; 211, identifier:exclude; 212, call; 212, 213; 212, 214; 213, identifier:select; 214, argument_list; 214, 215; 214, 216; 214, 217; 215, identifier:target; 216, identifier:ctx; 217, identifier:annotation; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:result; 223, identifier:append; 224, argument_list; 224, 225; 225, identifier:annotation; 226, if_statement; 226, 227; 226, 241; 227, boolean_operator:or; 227, 228; 227, 231; 228, comparison_operator:>=; 228, 229; 228, 230; 229, identifier:mindepth; 230, integer:0; 231, parenthesized_expression; 231, 232; 232, boolean_operator:and; 232, 233; 232, 236; 233, comparison_operator:>; 233, 234; 233, 235; 234, identifier:maxdepth; 235, integer:0; 236, parenthesized_expression; 236, 237; 237, boolean_operator:or; 237, 238; 237, 239; 238, identifier:result; 239, not_operator; 239, 240; 240, identifier:followannotated; 241, block; 241, 242; 241, 261; 242, if_statement; 242, 243; 242, 246; 242, 252; 243, comparison_operator:is; 243, 244; 243, 245; 244, identifier:_history; 245, None; 246, block; 246, 247; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:_history; 250, list:[target]; 250, 251; 251, identifier:target; 252, else_clause; 252, 253; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:_history; 258, identifier:append; 259, argument_list; 259, 260; 260, identifier:target; 261, for_statement; 261, 262; 261, 265; 261, 269; 262, pattern_list; 262, 263; 262, 264; 263, identifier:name; 264, identifier:member; 265, call; 265, 266; 265, 267; 266, identifier:getmembers; 267, argument_list; 267, 268; 268, identifier:target; 269, block; 269, 270; 270, if_statement; 270, 271; 270, 284; 271, boolean_operator:and; 271, 272; 271, 281; 272, parenthesized_expression; 272, 273; 273, boolean_operator:or; 273, 274; 273, 279; 274, comparison_operator:!=; 274, 275; 274, 278; 275, subscript; 275, 276; 275, 277; 276, identifier:name; 277, integer:0; 278, string:'_'; 279, not_operator; 279, 280; 280, identifier:public; 281, comparison_operator:not; 281, 282; 281, 283; 282, identifier:member; 283, identifier:_history; 284, block; 284, 285; 284, 299; 285, if_statement; 285, 286; 285, 297; 286, boolean_operator:and; 286, 287; 286, 291; 287, call; 287, 288; 287, 289; 288, identifier:ismethod; 289, argument_list; 289, 290; 290, identifier:target; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:name; 294, identifier:startswith; 295, argument_list; 295, 296; 296, string:'im_'; 297, block; 297, 298; 298, continue_statement; 299, expression_statement; 299, 300; 300, augmented_assignment:+=; 300, 301; 300, 302; 301, identifier:result; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:cls; 305, identifier:get_annotations; 306, argument_list; 306, 307; 306, 310; 306, 313; 306, 316; 306, 319; 306, 324; 306, 329; 306, 332; 307, keyword_argument; 307, 308; 307, 309; 308, identifier:target; 309, identifier:member; 310, keyword_argument; 310, 311; 310, 312; 311, identifier:exclude; 312, identifier:exclude; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:ctx; 315, identifier:ctx; 316, keyword_argument; 316, 317; 316, 318; 317, identifier:select; 318, identifier:select; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:mindepth; 321, binary_operator:-; 321, 322; 321, 323; 322, identifier:mindepth; 323, integer:1; 324, keyword_argument; 324, 325; 324, 326; 325, identifier:maxdepth; 326, binary_operator:-; 326, 327; 326, 328; 327, identifier:maxdepth; 328, integer:1; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:followannotated; 331, identifier:followannotated; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:_history; 334, identifier:_history; 335, return_statement; 335, 336; 336, identifier:result
def get_annotations( cls, target, exclude=None, ctx=None, select=lambda *p: True, mindepth=0, maxdepth=0, followannotated=True, public=True, _history=None ): result = [] if mindepth <= 0: try: annotations_by_ctx = get_property( elt=target, key=Annotation.__ANNOTATIONS_KEY__, ctx=ctx ) except TypeError: annotations_by_ctx = {} if not annotations_by_ctx: if ismethod(target): func = get_method_function(target) annotations_by_ctx = get_property( elt=func, key=Annotation.__ANNOTATIONS_KEY__, ctx=ctx ) if not annotations_by_ctx: annotations_by_ctx = get_property( elt=func, key=Annotation.__ANNOTATIONS_KEY__ ) elif isfunction(target): annotations_by_ctx = get_property( elt=target, key=Annotation.__ANNOTATIONS_KEY__ ) exclude = () if exclude is None else exclude for elt, annotations in annotations_by_ctx: for annotation in annotations: if isinstance(annotation, StopPropagation): exclude += annotation.annotation_types if elt is not target and not annotation.propagate: continue if annotation.override: exclude += (annotation.__class__, ) if (isinstance(annotation, cls) and not isinstance(annotation, exclude) and select(target, ctx, annotation)): result.append(annotation) if mindepth >= 0 or (maxdepth > 0 and (result or not followannotated)): if _history is None: _history = [target] else: _history.append(target) for name, member in getmembers(target): if (name[0] != '_' or not public) and member not in _history: if ismethod(target) and name.startswith('im_'): continue result += cls.get_annotations( target=member, exclude=exclude, ctx=ctx, select=select, mindepth=mindepth - 1, maxdepth=maxdepth - 1, followannotated=followannotated, _history=_history ) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_filenames; 3, parameters; 3, 4; 4, identifier:dirname; 5, block; 5, 6; 5, 20; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:filenames; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:glob; 12, identifier:glob; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, string:'{}/*.pkl'; 17, identifier:format; 18, argument_list; 18, 19; 19, identifier:dirname; 20, return_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:sorted; 23, argument_list; 23, 24; 23, 25; 24, identifier:filenames; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:key; 27, identifier:_f_to_i
def get_filenames(dirname): filenames = glob.glob('{}/*.pkl'.format(dirname)) return sorted(filenames, key=_f_to_i)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_states; 3, parameters; 3, 4; 3, 5; 4, identifier:states; 5, identifier:sort_list; 6, block; 6, 7; 6, 15; 6, 73; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:sorted_states; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:states; 13, identifier:copy; 14, argument_list; 15, for_statement; 15, 16; 15, 17; 15, 24; 16, identifier:sort_pair; 17, call; 17, 18; 17, 19; 18, identifier:reversed; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:_convert_list_of_dict_to_tuple; 22, argument_list; 22, 23; 23, identifier:sort_list; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 39; 25, 49; 26, comparison_operator:in; 26, 27; 26, 35; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, subscript; 29, 30; 29, 31; 30, identifier:sort_pair; 31, integer:0; 32, identifier:lstrip; 33, argument_list; 33, 34; 34, string:'-'; 35, list:['data','measure','meta']; 35, 36; 35, 37; 35, 38; 36, string:'data'; 37, string:'measure'; 38, string:'meta'; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:sorted_states; 43, call; 43, 44; 43, 45; 44, identifier:_state_value_sort; 45, argument_list; 45, 46; 45, 47; 45, 48; 46, identifier:sorted_states; 47, identifier:sort_pair; 48, identifier:_state_key_function; 49, elif_clause; 49, 50; 49, 55; 50, comparison_operator:==; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:sort_pair; 53, integer:0; 54, string:'groupings'; 55, block; 55, 56; 56, for_statement; 56, 57; 56, 58; 56, 64; 57, identifier:grouping; 58, call; 58, 59; 58, 60; 59, identifier:reversed; 60, argument_list; 60, 61; 61, subscript; 61, 62; 61, 63; 62, identifier:sort_pair; 63, integer:1; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:sorted_states; 68, call; 68, 69; 68, 70; 69, identifier:_groupings_values_sort; 70, argument_list; 70, 71; 70, 72; 71, identifier:sorted_states; 72, identifier:grouping; 73, return_statement; 73, 74; 74, identifier:sorted_states
def sort_states(states, sort_list): sorted_states= states.copy() for sort_pair in reversed( _convert_list_of_dict_to_tuple(sort_list) ): if sort_pair[0].lstrip('-') in ['data','measure','meta']: sorted_states= _state_value_sort(sorted_states, sort_pair, _state_key_function) elif sort_pair[0] == 'groupings': for grouping in reversed(sort_pair[1]): sorted_states= _groupings_values_sort(sorted_states, grouping) return sorted_states
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 11; 3, 14; 3, 19; 4, identifier:self; 5, identifier:terms; 6, default_parameter; 6, 7; 6, 8; 7, identifier:category; 8, attribute; 8, 9; 8, 10; 9, identifier:Category; 10, identifier:all_categories; 11, default_parameter; 11, 12; 11, 13; 12, identifier:page; 13, integer:1; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort_key; 16, attribute; 16, 17; 16, 18; 17, identifier:SearchSortKey; 18, identifier:date; 19, default_parameter; 19, 20; 19, 21; 20, identifier:order_key; 21, attribute; 21, 22; 21, 23; 22, identifier:SearchOrderKey; 23, identifier:descending; 24, block; 24, 25; 24, 50; 24, 64; 24, 73; 24, 82; 24, 119; 24, 123; 24, 148; 24, 320; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:params; 28, dictionary; 28, 29; 28, 32; 28, 35; 28, 40; 28, 45; 29, pair; 29, 30; 29, 31; 30, string:'page'; 31, string:'search'; 32, pair; 32, 33; 32, 34; 33, string:'term'; 34, identifier:terms; 35, pair; 35, 36; 35, 37; 36, string:'cats'; 37, attribute; 37, 38; 37, 39; 38, identifier:category; 39, identifier:value; 40, pair; 40, 41; 40, 42; 41, string:'sort'; 42, attribute; 42, 43; 42, 44; 43, identifier:sort_key; 44, identifier:value; 45, pair; 45, 46; 45, 47; 46, string:'order'; 47, attribute; 47, 48; 47, 49; 48, identifier:order_key; 49, identifier:value; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:r; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:requests; 56, identifier:get; 57, argument_list; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:base_url; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:params; 63, identifier:params; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:content; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_get_page_content; 71, argument_list; 71, 72; 72, identifier:r; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:a_to_last_page; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:content; 79, identifier:findall; 80, argument_list; 80, 81; 81, string:'.//div[@class="rightpages"]/a[2]'; 82, if_statement; 82, 83; 82, 85; 82, 90; 83, not_operator; 83, 84; 84, identifier:a_to_last_page; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:total_pages; 89, integer:1; 90, else_clause; 90, 91; 91, block; 91, 92; 91, 102; 91, 112; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:last_page_url; 95, subscript; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:a_to_last_page; 99, integer:0; 100, identifier:attrib; 101, string:'href'; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:offset; 105, subscript; 105, 106; 105, 111; 106, call; 106, 107; 106, 108; 107, identifier:extract_url_query_parameter; 108, argument_list; 108, 109; 108, 110; 109, identifier:last_page_url; 110, string:"offset"; 111, integer:0; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:total_pages; 115, call; 115, 116; 115, 117; 116, identifier:int; 117, argument_list; 117, 118; 118, identifier:offset; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:torrent_stubs; 122, list:[]; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:rows; 126, generator_expression; 126, 127; 126, 128; 126, 136; 127, identifier:x; 128, for_in_clause; 128, 129; 128, 130; 129, identifier:x; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:content; 133, identifier:findall; 134, argument_list; 134, 135; 135, string:'.//table//tr'; 136, if_clause; 136, 137; 137, comparison_operator:in; 137, 138; 137, 139; 138, string:'tlistrow'; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:x; 143, identifier:attrib; 144, identifier:get; 145, argument_list; 145, 146; 145, 147; 146, string:'class'; 147, string:''; 148, for_statement; 148, 149; 148, 150; 148, 151; 149, identifier:row; 150, identifier:rows; 151, block; 151, 152; 151, 161; 151, 182; 151, 191; 151, 212; 151, 225; 151, 233; 151, 261; 151, 289; 151, 300; 151, 313; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:cell_td_elems; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:row; 158, identifier:findall; 159, argument_list; 159, 160; 160, string:'td'; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:category_value; 164, subscript; 164, 165; 164, 181; 165, call; 165, 166; 165, 167; 166, identifier:extract_url_query_parameter; 167, argument_list; 167, 168; 167, 180; 168, subscript; 168, 169; 168, 179; 169, attribute; 169, 170; 169, 178; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:cell_td_elems; 174, integer:0; 175, identifier:find; 176, argument_list; 176, 177; 177, string:'a'; 178, identifier:attrib; 179, string:'href'; 180, string:'cats'; 181, integer:0; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:category; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:Category; 188, identifier:lookup_category; 189, argument_list; 189, 190; 190, identifier:category_value; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:torrent_id; 194, subscript; 194, 195; 194, 211; 195, call; 195, 196; 195, 197; 196, identifier:extract_url_query_parameter; 197, argument_list; 197, 198; 197, 210; 198, subscript; 198, 199; 198, 209; 199, attribute; 199, 200; 199, 208; 200, call; 200, 201; 200, 206; 201, attribute; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:cell_td_elems; 204, integer:1; 205, identifier:find; 206, argument_list; 206, 207; 207, string:'a'; 208, identifier:attrib; 209, string:'href'; 210, string:"tid"; 211, integer:0; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:name; 215, attribute; 215, 216; 215, 224; 216, call; 216, 217; 216, 222; 217, attribute; 217, 218; 217, 221; 218, subscript; 218, 219; 218, 220; 219, identifier:cell_td_elems; 220, integer:1; 221, identifier:find; 222, argument_list; 222, 223; 223, string:'a'; 224, identifier:text; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:file_size; 228, attribute; 228, 229; 228, 232; 229, subscript; 229, 230; 229, 231; 230, identifier:cell_td_elems; 231, integer:3; 232, identifier:text; 233, if_statement; 233, 234; 233, 243; 233, 255; 234, call; 234, 235; 234, 242; 235, attribute; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, subscript; 237, 238; 237, 239; 238, identifier:cell_td_elems; 239, integer:4; 240, identifier:text; 241, identifier:isdigit; 242, argument_list; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:seeders; 247, call; 247, 248; 247, 249; 248, identifier:int; 249, argument_list; 249, 250; 250, attribute; 250, 251; 250, 254; 251, subscript; 251, 252; 251, 253; 252, identifier:cell_td_elems; 253, integer:4; 254, identifier:text; 255, else_clause; 255, 256; 256, block; 256, 257; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:seeders; 260, None; 261, if_statement; 261, 262; 261, 271; 261, 283; 262, call; 262, 263; 262, 270; 263, attribute; 263, 264; 263, 269; 264, attribute; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:cell_td_elems; 267, integer:5; 268, identifier:text; 269, identifier:isdigit; 270, argument_list; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:leechers; 275, call; 275, 276; 275, 277; 276, identifier:int; 277, argument_list; 277, 278; 278, attribute; 278, 279; 278, 282; 279, subscript; 279, 280; 279, 281; 280, identifier:cell_td_elems; 281, integer:5; 282, identifier:text; 283, else_clause; 283, 284; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:leechers; 288, None; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:downloads; 292, call; 292, 293; 292, 294; 293, identifier:int; 294, argument_list; 294, 295; 295, attribute; 295, 296; 295, 299; 296, subscript; 296, 297; 296, 298; 297, identifier:cell_td_elems; 298, integer:6; 299, identifier:text; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:stub; 303, call; 303, 304; 303, 305; 304, identifier:TorrentStub; 305, argument_list; 305, 306; 305, 307; 305, 308; 305, 309; 305, 310; 305, 311; 305, 312; 306, identifier:torrent_id; 307, identifier:name; 308, identifier:category; 309, identifier:seeders; 310, identifier:leechers; 311, identifier:file_size; 312, identifier:downloads; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:torrent_stubs; 317, identifier:append; 318, argument_list; 318, 319; 319, identifier:stub; 320, return_statement; 320, 321; 321, call; 321, 322; 321, 323; 322, identifier:SearchResultPage; 323, argument_list; 323, 324; 323, 325; 323, 326; 323, 327; 323, 328; 323, 329; 323, 330; 324, identifier:terms; 325, identifier:category; 326, identifier:sort_key; 327, identifier:order_key; 328, identifier:page; 329, identifier:total_pages; 330, identifier:torrent_stubs
def search(self, terms, category=Category.all_categories, page=1, sort_key=SearchSortKey.date, order_key=SearchOrderKey.descending): params = { 'page': 'search', 'term': terms, 'cats': category.value, 'sort': sort_key.value, 'order': order_key.value, } r = requests.get(self.base_url, params=params) content = self._get_page_content(r) a_to_last_page = content.findall('.//div[@class="rightpages"]/a[2]') if not a_to_last_page: total_pages = 1 else: last_page_url = a_to_last_page[0].attrib['href'] offset = extract_url_query_parameter(last_page_url, "offset")[0] total_pages = int(offset) torrent_stubs = [] rows = (x for x in content.findall('.//table//tr') if 'tlistrow' in x.attrib.get('class', '')) for row in rows: cell_td_elems = row.findall('td') category_value = extract_url_query_parameter( cell_td_elems[0].find('a').attrib['href'], 'cats')[0] category = Category.lookup_category(category_value) torrent_id = extract_url_query_parameter( cell_td_elems[1].find('a').attrib['href'], "tid")[0] name = cell_td_elems[1].find('a').text file_size = cell_td_elems[3].text if cell_td_elems[4].text.isdigit(): seeders = int(cell_td_elems[4].text) else: seeders = None if cell_td_elems[5].text.isdigit(): leechers = int(cell_td_elems[5].text) else: leechers = None downloads = int(cell_td_elems[6].text) stub = TorrentStub(torrent_id, name, category, seeders, leechers, file_size, downloads) torrent_stubs.append(stub) return SearchResultPage( terms, category, sort_key, order_key, page, total_pages, torrent_stubs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:partition; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:mapped_values; 6, block; 6, 7; 6, 16; 6, 31; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:partitioned_data; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:collections; 13, identifier:defaultdict; 14, argument_list; 14, 15; 15, identifier:list; 16, for_statement; 16, 17; 16, 20; 16, 21; 17, pattern_list; 17, 18; 17, 19; 18, identifier:key; 19, identifier:value; 20, identifier:mapped_values; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:partitioned_data; 27, identifier:key; 28, identifier:append; 29, argument_list; 29, 30; 30, identifier:value; 31, return_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:partitioned_data; 35, identifier:items; 36, argument_list
def partition(self, mapped_values): partitioned_data = collections.defaultdict(list) for key, value in mapped_values: partitioned_data[key].append(value) return partitioned_data.items()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:cond_int; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:conkey; 6, block; 6, 7; 6, 19; 6, 25; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:m; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:re; 13, identifier:match; 14, argument_list; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:numrx; 18, identifier:conkey; 19, if_statement; 19, 20; 19, 22; 20, not_operator; 20, 21; 21, identifier:m; 22, block; 22, 23; 23, return_statement; 23, 24; 24, identifier:conkey; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:int; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:m; 32, identifier:group; 33, argument_list; 33, 34; 34, integer:1
def cond_int(self, conkey): m = re.match(self.numrx, conkey) if not m: return conkey return int(m.group(1))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sorted_conkeys; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:prefix; 7, None; 8, block; 8, 9; 8, 13; 8, 42; 8, 48; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:conkeys; 12, list:[]; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:cond; 15, identifier:_COND_PREFIXES; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, augmented_assignment:+=; 18, 19; 18, 20; 19, identifier:conkeys; 20, call; 20, 21; 20, 22; 21, identifier:sorted; 22, argument_list; 22, 23; 22, 37; 23, list_comprehension; 23, 24; 23, 25; 23, 30; 24, identifier:key; 25, for_in_clause; 25, 26; 25, 27; 26, identifier:key; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:conditions; 30, if_clause; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:key; 34, identifier:startswith; 35, argument_list; 35, 36; 36, identifier:cond; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:key; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:cond_int; 42, if_statement; 42, 43; 42, 45; 43, not_operator; 43, 44; 44, identifier:prefix; 45, block; 45, 46; 46, return_statement; 46, 47; 47, identifier:conkeys; 48, return_statement; 48, 49; 49, list_comprehension; 49, 50; 49, 51; 49, 54; 50, identifier:key; 51, for_in_clause; 51, 52; 51, 53; 52, identifier:key; 53, identifier:conkeys; 54, if_clause; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:key; 58, identifier:startswith; 59, argument_list; 59, 60; 60, identifier:prefix
def sorted_conkeys(self, prefix=None): conkeys = [] for cond in _COND_PREFIXES: conkeys += sorted([key for key in self.conditions if key.startswith(cond)], key=self.cond_int) if not prefix: return conkeys return [key for key in conkeys if key.startswith(prefix)]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:isordinal; 3, parameters; 3, 4; 4, identifier:x; 5, block; 5, 6; 5, 11; 5, 34; 5, 69; 6, import_statement; 6, 7; 7, aliased_import; 7, 8; 7, 10; 8, dotted_name; 8, 9; 9, identifier:numpy; 10, identifier:np; 11, if_statement; 11, 12; 11, 26; 12, comparison_operator:==; 12, 13; 12, 17; 13, call; 13, 14; 13, 15; 14, identifier:len; 15, argument_list; 15, 16; 16, identifier:x; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:np; 23, identifier:unique; 24, argument_list; 24, 25; 25, identifier:x; 26, block; 26, 27; 27, return_statement; 27, 28; 28, expression_list; 28, 29; 28, 30; 29, False; 30, parenthesized_expression; 30, 31; 31, concatenated_string; 31, 32; 31, 33; 32, string:"number of observations equals the "; 33, string:"number of unique values."; 34, if_statement; 34, 35; 34, 43; 35, not_operator; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:isinstance; 38, argument_list; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:x; 41, integer:0; 42, identifier:str; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 64; 45, not_operator; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:np; 49, identifier:all; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:np; 54, identifier:equal; 55, argument_list; 55, 56; 55, 63; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:np; 59, identifier:mod; 60, argument_list; 60, 61; 60, 62; 61, identifier:x; 62, integer:1; 63, integer:0; 64, block; 64, 65; 65, return_statement; 65, 66; 66, expression_list; 66, 67; 66, 68; 67, False; 68, string:"elements are not integer or strings."; 69, return_statement; 69, 70; 70, expression_list; 70, 71; 70, 72; 71, True; 72, string:"is ordinal"
def isordinal(x): import numpy as np if len(x) == len(np.unique(x)): return False, ("number of observations equals the " "number of unique values.") if not isinstance(x[0], str): if not np.all(np.equal(np.mod(x, 1), 0)): return False, "elements are not integer or strings." return True, "is ordinal"
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:sort; 7, block; 7, 8; 7, 30; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:add_get_param; 13, argument_list; 13, 14; 13, 15; 14, string:'sort'; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:FILTER_DELIMITER; 18, identifier:join; 19, argument_list; 19, 20; 20, list_comprehension; 20, 21; 20, 27; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:ELEMENT_DELIMITER; 24, identifier:join; 25, argument_list; 25, 26; 26, identifier:elements; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:elements; 29, identifier:sort; 30, return_statement; 30, 31; 31, identifier:self
def sort(self, *sort): self.add_get_param('sort', FILTER_DELIMITER.join( [ELEMENT_DELIMITER.join(elements) for elements in sort])) return self
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:to_json; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:drop_null; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:camel; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:indent; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort_keys; 16, False; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:json; 22, identifier:dumps; 23, argument_list; 23, 24; 23, 31; 23, 34; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:to_dict; 28, argument_list; 28, 29; 28, 30; 29, identifier:drop_null; 30, identifier:camel; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:indent; 33, identifier:indent; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:sort_keys; 36, identifier:sort_keys
def to_json(self, drop_null=True, camel=False, indent=None, sort_keys=False): return json.dumps(self.to_dict(drop_null, camel), indent=indent, sort_keys=sort_keys)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_by_name; 3, parameters; 3, 4; 4, identifier:names; 5, block; 5, 6; 5, 61; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:last_name_key; 8, parameters; 8, 9; 9, identifier:full_name; 10, block; 10, 11; 10, 20; 10, 34; 10, 55; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:parts; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:full_name; 17, identifier:split; 18, argument_list; 18, 19; 19, string:' '; 20, if_statement; 20, 21; 20, 27; 21, comparison_operator:==; 21, 22; 21, 26; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, identifier:parts; 26, integer:1; 27, block; 27, 28; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:full_name; 32, identifier:upper; 33, argument_list; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:last_first; 37, binary_operator:+; 37, 38; 37, 44; 38, binary_operator:+; 38, 39; 38, 43; 39, subscript; 39, 40; 39, 41; 40, identifier:parts; 41, unary_operator:-; 41, 42; 42, integer:1; 43, string:' '; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, string:' '; 47, identifier:join; 48, argument_list; 48, 49; 49, subscript; 49, 50; 49, 51; 50, identifier:parts; 51, slice; 51, 52; 51, 53; 52, colon; 53, unary_operator:-; 53, 54; 54, integer:1; 55, return_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:last_first; 59, identifier:upper; 60, argument_list; 61, return_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:sorted; 64, argument_list; 64, 65; 64, 69; 65, call; 65, 66; 65, 67; 66, identifier:set; 67, argument_list; 67, 68; 68, identifier:names; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:key; 71, identifier:last_name_key
def sort_by_name(names): def last_name_key(full_name): parts = full_name.split(' ') if len(parts) == 1: return full_name.upper() last_first = parts[-1] + ' ' + ' '.join(parts[:-1]) return last_first.upper() return sorted(set(names), key=last_name_key)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 47; 5, 67; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:users; 9, list:[]; 10, for_statement; 10, 11; 10, 14; 10, 31; 11, pattern_list; 11, 12; 11, 13; 12, identifier:_; 13, identifier:group; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:itertools; 17, identifier:groupby; 18, argument_list; 18, 19; 18, 25; 19, call; 19, 20; 19, 21; 20, identifier:sorted; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:commits; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:operator; 28, identifier:attrgetter; 29, argument_list; 29, 30; 30, string:'author_mail'; 31, block; 31, 32; 32, if_statement; 32, 33; 32, 34; 33, identifier:group; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:users; 39, identifier:append; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:merge_user_commits; 45, argument_list; 45, 46; 46, identifier:group; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:sorted_commits; 52, call; 52, 53; 52, 54; 53, identifier:sorted; 54, argument_list; 54, 55; 54, 56; 54, 64; 55, identifier:users; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:key; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:operator; 61, identifier:attrgetter; 62, argument_list; 62, 63; 63, string:'line_count'; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:reverse; 66, True; 67, return_statement; 67, 68; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:sorted_commits
def sort(self): users = [] for _, group in itertools.groupby(sorted(self.commits), operator.attrgetter('author_mail')): if group: users.append(self.merge_user_commits(group)) self.sorted_commits = sorted(users, key=operator.attrgetter('line_count'), reverse=True) return self.sorted_commits
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 22; 5, 33; 5, 39; 5, 45; 5, 107; 5, 121; 5, 130; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:sorted_commits; 11, list:[]; 12, if_statement; 12, 13; 12, 17; 13, not_operator; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:commits; 17, block; 17, 18; 18, return_statement; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:sorted_commits; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:prev_commit; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:commits; 30, identifier:pop; 31, argument_list; 31, 32; 32, integer:0; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:prev_line; 36, attribute; 36, 37; 36, 38; 37, identifier:prev_commit; 38, identifier:line_number; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:prev_uuid; 42, attribute; 42, 43; 42, 44; 43, identifier:prev_commit; 44, identifier:uuid; 45, for_statement; 45, 46; 45, 47; 45, 50; 46, identifier:commit; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:commits; 50, block; 50, 51; 50, 95; 50, 101; 51, if_statement; 51, 52; 51, 67; 52, parenthesized_expression; 52, 53; 53, boolean_operator:or; 53, 54; 53, 59; 54, comparison_operator:!=; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:commit; 57, identifier:uuid; 58, identifier:prev_uuid; 59, comparison_operator:!=; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:commit; 62, identifier:line_number; 63, parenthesized_expression; 63, 64; 64, binary_operator:+; 64, 65; 64, 66; 65, identifier:prev_line; 66, integer:1; 67, block; 67, 68; 67, 82; 67, 91; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:prev_commit; 72, identifier:lines; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:line_range; 77, argument_list; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:prev_commit; 80, identifier:line_number; 81, identifier:prev_line; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:sorted_commits; 88, identifier:append; 89, argument_list; 89, 90; 90, identifier:prev_commit; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:prev_commit; 94, identifier:commit; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:prev_line; 98, attribute; 98, 99; 98, 100; 99, identifier:commit; 100, identifier:line_number; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:prev_uuid; 104, attribute; 104, 105; 104, 106; 105, identifier:commit; 106, identifier:uuid; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:prev_commit; 111, identifier:lines; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:line_range; 116, argument_list; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:prev_commit; 119, identifier:line_number; 120, identifier:prev_line; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:sorted_commits; 127, identifier:append; 128, argument_list; 128, 129; 129, identifier:prev_commit; 130, return_statement; 130, 131; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:sorted_commits
def sort(self): self.sorted_commits = [] if not self.commits: return self.sorted_commits prev_commit = self.commits.pop(0) prev_line = prev_commit.line_number prev_uuid = prev_commit.uuid for commit in self.commits: if (commit.uuid != prev_uuid or commit.line_number != (prev_line + 1)): prev_commit.lines = self.line_range(prev_commit.line_number, prev_line) self.sorted_commits.append(prev_commit) prev_commit = commit prev_line = commit.line_number prev_uuid = commit.uuid prev_commit.lines = self.line_range(prev_commit.line_number, prev_line) self.sorted_commits.append(prev_commit) return self.sorted_commits
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:truncate_most_common; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:truncation_length; 6, block; 6, 7; 6, 9; 6, 26; 7, expression_statement; 7, 8; 8, string:''' Sorts the counter and keeps only the most common items up to ``truncation_length`` in place. :type truncation_length: int '''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:keep_keys; 12, call; 12, 13; 12, 14; 13, identifier:set; 14, generator_expression; 14, 15; 14, 18; 15, subscript; 15, 16; 15, 17; 16, identifier:v; 17, integer:0; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:v; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:most_common; 24, argument_list; 24, 25; 25, identifier:truncation_length; 26, for_statement; 26, 27; 26, 28; 26, 33; 27, identifier:key; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:keys; 32, argument_list; 33, block; 33, 34; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:not; 35, 36; 35, 37; 36, identifier:key; 37, identifier:keep_keys; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:pop; 44, argument_list; 44, 45; 45, identifier:key
def truncate_most_common(self, truncation_length): ''' Sorts the counter and keeps only the most common items up to ``truncation_length`` in place. :type truncation_length: int ''' keep_keys = set(v[0] for v in self.most_common(truncation_length)) for key in self.keys(): if key not in keep_keys: self.pop(key)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_ordered_values; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:keypath; 6, identifier:distance_from; 7, default_parameter; 7, 8; 7, 9; 8, identifier:open_interval; 9, True; 10, block; 10, 11; 10, 15; 10, 30; 10, 76; 10, 86; 10, 95; 10, 103; 10, 109; 10, 128; 10, 150; 10, 159; 10, 165; 10, 169; 10, 340; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:values; 14, list:[]; 15, if_statement; 15, 16; 15, 21; 16, comparison_operator:==; 16, 17; 16, 20; 17, subscript; 17, 18; 17, 19; 18, identifier:keypath; 19, integer:0; 20, string:'target'; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:keypath; 25, subscript; 25, 26; 25, 27; 26, identifier:keypath; 27, slice; 27, 28; 27, 29; 28, integer:1; 29, colon; 30, for_statement; 30, 31; 30, 34; 30, 39; 31, pattern_list; 31, 32; 31, 33; 32, identifier:_; 33, identifier:instance; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:iter_singleton_referents; 38, argument_list; 39, block; 39, 40; 39, 49; 39, 66; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:value; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:instance; 46, identifier:get_value_from_path; 47, argument_list; 47, 48; 48, identifier:keypath; 49, if_statement; 49, 50; 49, 63; 50, boolean_operator:and; 50, 51; 50, 56; 51, call; 51, 52; 51, 53; 52, identifier:hasattr; 53, argument_list; 53, 54; 53, 55; 54, identifier:value; 55, string:'low'; 56, comparison_operator:!=; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:value; 59, identifier:low; 60, attribute; 60, 61; 60, 62; 61, identifier:value; 62, identifier:high; 63, block; 63, 64; 64, return_statement; 64, 65; 65, list:[]; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:values; 70, identifier:append; 71, argument_list; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:float; 74, argument_list; 74, 75; 75, identifier:value; 76, if_statement; 76, 77; 76, 83; 77, comparison_operator:==; 77, 78; 77, 82; 78, call; 78, 79; 78, 80; 79, identifier:len; 80, argument_list; 80, 81; 81, identifier:values; 82, integer:0; 83, block; 83, 84; 84, return_statement; 84, 85; 85, list:[]; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:values; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:np; 92, identifier:array; 93, argument_list; 93, 94; 94, identifier:values; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:anchor; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:values; 101, identifier:min; 102, argument_list; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:diffs; 106, binary_operator:-; 106, 107; 106, 108; 107, identifier:values; 108, identifier:anchor; 109, if_statement; 109, 110; 109, 113; 110, comparison_operator:==; 110, 111; 110, 112; 111, identifier:distance_from; 112, string:'max'; 113, block; 113, 114; 113, 122; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:anchor; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:values; 120, identifier:max; 121, argument_list; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:diffs; 125, binary_operator:-; 125, 126; 125, 127; 126, identifier:anchor; 127, identifier:values; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:==; 129, 130; 129, 131; 130, identifier:distance_from; 131, string:'mean'; 132, block; 132, 133; 132, 141; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:anchor; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:values; 139, identifier:mean; 140, argument_list; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:diffs; 144, call; 144, 145; 144, 146; 145, identifier:abs; 146, argument_list; 146, 147; 147, binary_operator:-; 147, 148; 147, 149; 148, identifier:anchor; 149, identifier:values; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:sdiffs; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:np; 156, identifier:unique; 157, argument_list; 157, 158; 158, identifier:diffs; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:sdiffs; 163, identifier:sort; 164, argument_list; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:results; 168, list:[]; 169, for_statement; 169, 170; 169, 173; 169, 177; 170, pattern_list; 170, 171; 170, 172; 171, identifier:ix; 172, identifier:el; 173, call; 173, 174; 173, 175; 174, identifier:enumerate; 175, argument_list; 175, 176; 176, identifier:sdiffs; 177, block; 177, 178; 177, 184; 177, 190; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:mask; 181, comparison_operator:<=; 181, 182; 181, 183; 182, identifier:diffs; 183, identifier:el; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:vals; 187, subscript; 187, 188; 187, 189; 188, identifier:values; 189, identifier:mask; 190, if_statement; 190, 191; 190, 192; 190, 212; 190, 258; 190, 305; 191, False; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:results; 197, identifier:append; 198, argument_list; 198, 199; 199, call; 199, 200; 199, 201; 200, identifier:IntervalCell; 201, argument_list; 201, 202; 201, 207; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:vals; 205, identifier:min; 206, argument_list; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:vals; 210, identifier:max; 211, argument_list; 212, elif_clause; 212, 213; 212, 216; 213, comparison_operator:==; 213, 214; 213, 215; 214, identifier:distance_from; 215, string:'max'; 216, block; 216, 217; 217, if_statement; 217, 218; 217, 219; 217, 237; 218, identifier:open_interval; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:results; 224, identifier:append; 225, argument_list; 225, 226; 226, call; 226, 227; 226, 228; 227, identifier:IntervalCell; 228, argument_list; 228, 229; 228, 234; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:vals; 232, identifier:min; 233, argument_list; 234, attribute; 234, 235; 234, 236; 235, identifier:np; 236, identifier:inf; 237, else_clause; 237, 238; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:results; 243, identifier:append; 244, argument_list; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:IntervalCell; 247, argument_list; 247, 248; 247, 253; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:vals; 251, identifier:min; 252, argument_list; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:vals; 256, identifier:min; 257, argument_list; 258, elif_clause; 258, 259; 258, 262; 259, comparison_operator:==; 259, 260; 259, 261; 260, identifier:distance_from; 261, string:'min'; 262, block; 262, 263; 263, if_statement; 263, 264; 263, 265; 263, 284; 264, identifier:open_interval; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:results; 270, identifier:append; 271, argument_list; 271, 272; 272, call; 272, 273; 272, 274; 273, identifier:IntervalCell; 274, argument_list; 274, 275; 274, 279; 275, unary_operator:-; 275, 276; 276, attribute; 276, 277; 276, 278; 277, identifier:np; 278, identifier:inf; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:vals; 282, identifier:max; 283, argument_list; 284, else_clause; 284, 285; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:results; 290, identifier:append; 291, argument_list; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:IntervalCell; 294, argument_list; 294, 295; 294, 300; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:vals; 298, identifier:max; 299, argument_list; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:vals; 303, identifier:max; 304, argument_list; 305, elif_clause; 305, 306; 305, 309; 306, comparison_operator:==; 306, 307; 306, 308; 307, identifier:distance_from; 308, string:'mean'; 309, block; 309, 310; 309, 321; 310, if_statement; 310, 311; 310, 319; 311, comparison_operator:==; 311, 312; 311, 315; 312, binary_operator:+; 312, 313; 312, 314; 313, identifier:ix; 314, integer:1; 315, call; 315, 316; 315, 317; 316, identifier:len; 317, argument_list; 317, 318; 318, identifier:sdiffs; 319, block; 319, 320; 320, continue_statement; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:results; 325, identifier:append; 326, argument_list; 326, 327; 327, call; 327, 328; 327, 329; 328, identifier:IntervalCell; 329, argument_list; 329, 330; 329, 335; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:vals; 333, identifier:min; 334, argument_list; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:vals; 338, identifier:max; 339, argument_list; 340, return_statement; 340, 341; 341, identifier:results
def get_ordered_values(self, keypath, distance_from, open_interval=True): values = [] if keypath[0] == 'target': keypath = keypath[1:] for _, instance in self.iter_singleton_referents(): value = instance.get_value_from_path(keypath) if hasattr(value, 'low') and value.low != value.high: return [] values.append(float(value)) if len(values) == 0: return [] values = np.array(values) anchor = values.min() diffs = values - anchor if distance_from == 'max': anchor = values.max() diffs = anchor - values if distance_from == 'mean': anchor = values.mean() diffs = abs(anchor - values) sdiffs = np.unique(diffs) sdiffs.sort() results = [] for ix, el in enumerate(sdiffs): mask = diffs <= el vals = values[mask] if False: results.append(IntervalCell(vals.min(), vals.max())) elif distance_from == 'max': if open_interval: results.append(IntervalCell(vals.min(), np.inf)) else: results.append(IntervalCell(vals.min(), vals.min())) elif distance_from == 'min': if open_interval: results.append(IntervalCell(-np.inf, vals.max())) else: results.append(IntervalCell(vals.max(), vals.max())) elif distance_from == 'mean': if ix+1 == len(sdiffs): continue results.append(IntervalCell(vals.min(), vals.max())) return results
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:gp_datdir; 3, parameters; 3, 4; 3, 5; 4, identifier:initial; 5, identifier:topN; 6, block; 6, 7; 6, 15; 6, 23; 6, 35; 6, 50; 6, 56; 6, 138; 6, 145; 6, 179; 6, 201; 6, 208; 6, 270; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, pattern_list; 9, 10; 9, 11; 10, identifier:inDir; 11, identifier:outDir; 12, call; 12, 13; 12, 14; 13, identifier:getWorkDirs; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:initial; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:initial; 21, identifier:capitalize; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:inDir; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:os; 30, identifier:path; 31, identifier:join; 32, argument_list; 32, 33; 32, 34; 33, identifier:inDir; 34, identifier:initial; 35, if_statement; 35, 36; 35, 45; 36, not_operator; 36, 37; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:os; 41, identifier:path; 42, identifier:exists; 43, argument_list; 43, 44; 44, identifier:inDir; 45, block; 45, 46; 46, return_statement; 46, 47; 47, binary_operator:%; 47, 48; 47, 49; 48, string:"initial %s doesn't exist"; 49, identifier:initial; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:data; 53, call; 53, 54; 53, 55; 54, identifier:OrderedDict; 55, argument_list; 56, for_statement; 56, 57; 56, 58; 56, 64; 57, identifier:file; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:os; 61, identifier:listdir; 62, argument_list; 62, 63; 63, identifier:inDir; 64, block; 64, 65; 64, 78; 64, 90; 64, 105; 64, 115; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:country; 68, subscript; 68, 69; 68, 77; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:os; 73, identifier:path; 74, identifier:splitext; 75, argument_list; 75, 76; 76, identifier:file; 77, integer:0; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:file_url; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:os; 85, identifier:path; 86, identifier:join; 87, argument_list; 87, 88; 87, 89; 88, identifier:inDir; 89, identifier:file; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:data; 94, identifier:country; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:np; 98, identifier:loadtxt; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:open; 102, argument_list; 102, 103; 102, 104; 103, identifier:file_url; 104, string:'rb'; 105, expression_statement; 105, 106; 106, augmented_assignment:/=; 106, 107; 106, 114; 107, subscript; 107, 108; 107, 111; 107, 113; 108, subscript; 108, 109; 108, 110; 109, identifier:data; 110, identifier:country; 111, slice; 111, 112; 112, colon; 113, integer:1; 114, float:1e6; 115, if_statement; 115, 116; 115, 125; 116, comparison_operator:>; 116, 117; 116, 124; 117, subscript; 117, 118; 117, 123; 118, attribute; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:data; 121, identifier:country; 122, identifier:shape; 123, integer:1; 124, integer:2; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, augmented_assignment:/=; 127, 128; 127, 137; 128, subscript; 128, 129; 128, 132; 128, 134; 129, subscript; 129, 130; 129, 131; 130, identifier:data; 131, identifier:country; 132, slice; 132, 133; 133, colon; 134, slice; 134, 135; 134, 136; 135, integer:3; 136, colon; 137, float:1e6; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:logging; 142, identifier:debug; 143, argument_list; 143, 144; 144, identifier:data; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:sorted_data; 148, call; 148, 149; 148, 150; 149, identifier:OrderedDict; 150, argument_list; 150, 151; 151, call; 151, 152; 151, 153; 152, identifier:sorted; 153, argument_list; 153, 154; 153, 159; 153, 176; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:data; 157, identifier:items; 158, argument_list; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:key; 161, lambda; 161, 162; 161, 164; 162, lambda_parameters; 162, 163; 163, identifier:t; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:np; 167, identifier:mean; 168, argument_list; 168, 169; 169, subscript; 169, 170; 169, 173; 169, 175; 170, subscript; 170, 171; 170, 172; 171, identifier:t; 172, integer:1; 173, slice; 173, 174; 174, colon; 175, integer:1; 176, keyword_argument; 176, 177; 176, 178; 177, identifier:reverse; 178, True; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:top_data; 182, call; 182, 183; 182, 184; 183, identifier:OrderedDict; 184, generator_expression; 184, 185; 184, 193; 184, 199; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:sorted_data; 188, identifier:popitem; 189, argument_list; 189, 190; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:last; 192, False; 193, for_in_clause; 193, 194; 193, 195; 194, identifier:i; 195, call; 195, 196; 195, 197; 196, identifier:xrange; 197, argument_list; 197, 198; 198, identifier:topN; 199, if_clause; 199, 200; 200, identifier:sorted_data; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:nSets; 204, call; 204, 205; 204, 206; 205, identifier:len; 206, argument_list; 206, 207; 207, identifier:top_data; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:make_plot; 211, argument_list; 211, 212; 211, 219; 211, 232; 211, 239; 211, 250; 211, 255; 211, 258; 211, 261; 211, 264; 211, 267; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:data; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:top_data; 217, identifier:values; 218, argument_list; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:properties; 221, list_comprehension; 221, 222; 221, 226; 222, call; 222, 223; 222, 224; 223, identifier:getOpts; 224, argument_list; 224, 225; 225, identifier:i; 226, for_in_clause; 226, 227; 226, 228; 227, identifier:i; 228, call; 228, 229; 228, 230; 229, identifier:xrange; 230, argument_list; 230, 231; 231, identifier:nSets; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:titles; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:top_data; 237, identifier:keys; 238, argument_list; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:name; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:os; 245, identifier:path; 246, identifier:join; 247, argument_list; 247, 248; 247, 249; 248, identifier:outDir; 249, identifier:initial; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:key; 252, list:[ 'at graph 1., 1.2', 'maxrows 2' ]; 252, 253; 252, 254; 253, string:'at graph 1., 1.2'; 254, string:'maxrows 2'; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:ylabel; 257, string:'total population ({/Symbol \664} 10^{6})'; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:xlabel; 260, string:'year'; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:rmargin; 263, float:0.99; 264, keyword_argument; 264, 265; 264, 266; 265, identifier:tmargin; 266, float:0.85; 267, keyword_argument; 267, 268; 267, 269; 268, identifier:size; 269, string:'8.5in,8in'; 270, return_statement; 270, 271; 271, string:'done'
def gp_datdir(initial, topN): inDir, outDir = getWorkDirs() initial = initial.capitalize() inDir = os.path.join(inDir, initial) if not os.path.exists(inDir): return "initial %s doesn't exist" % initial data = OrderedDict() for file in os.listdir(inDir): country = os.path.splitext(file)[0] file_url = os.path.join(inDir, file) data[country] = np.loadtxt(open(file_url, 'rb')) data[country][:, 1] /= 1e6 if data[country].shape[1] > 2: data[country][:, 3:] /= 1e6 logging.debug(data) sorted_data = OrderedDict(sorted( data.items(), key = lambda t: np.mean(t[1][:,1]), reverse = True )) top_data = OrderedDict( sorted_data.popitem(last = False) for i in xrange(topN) if sorted_data ) nSets = len(top_data) make_plot( data = top_data.values(), properties = [ getOpts(i) for i in xrange(nSets) ], titles = top_data.keys(), name = os.path.join(outDir, initial), key = [ 'at graph 1., 1.2', 'maxrows 2' ], ylabel = 'total population ({/Symbol \664} 10^{6})', xlabel = 'year', rmargin = 0.99, tmargin = 0.85, size='8.5in,8in' ) return 'done'
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:rankingEval; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 19; 5, 30; 5, 61; 5, 69; 5, 91; 5, 99; 5, 110; 5, 114; 5, 161; 5, 167; 5, 173; 6, expression_statement; 6, 7; 7, string:''' Sorting the pop. base on the fitnessEval result '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:fitnessAll; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:numpy; 14, identifier:zeros; 15, argument_list; 15, 16; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:length; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:fitnessNorm; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:numpy; 25, identifier:zeros; 26, argument_list; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:length; 30, for_statement; 30, 31; 30, 32; 30, 38; 31, identifier:i; 32, call; 32, 33; 32, 34; 33, identifier:range; 34, argument_list; 34, 35; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:length; 38, block; 38, 39; 38, 49; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 48; 41, attribute; 41, 42; 41, 47; 42, subscript; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:Ind; 46, identifier:i; 47, identifier:fitnessEval; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:fitnessAll; 53, identifier:i; 54, attribute; 54, 55; 54, 60; 55, subscript; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:Ind; 59, identifier:i; 60, identifier:fitness; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:maxFitness; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:fitnessAll; 67, identifier:max; 68, argument_list; 69, for_statement; 69, 70; 69, 71; 69, 77; 70, identifier:i; 71, call; 71, 72; 71, 73; 72, identifier:range; 73, argument_list; 73, 74; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:length; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:fitnessNorm; 82, identifier:i; 83, binary_operator:/; 83, 84; 83, 90; 84, parenthesized_expression; 84, 85; 85, binary_operator:-; 85, 86; 85, 87; 86, identifier:maxFitness; 87, subscript; 87, 88; 87, 89; 88, identifier:fitnessAll; 89, identifier:i; 90, identifier:maxFitness; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:fitnessSorted; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:fitnessNorm; 97, identifier:argsort; 98, argument_list; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:probability; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:numpy; 105, identifier:zeros; 106, argument_list; 106, 107; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:length; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:S; 113, float:2.0; 114, for_statement; 114, 115; 114, 116; 114, 122; 115, identifier:i; 116, call; 116, 117; 116, 118; 117, identifier:range; 118, argument_list; 118, 119; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:length; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 130; 125, subscript; 125, 126; 125, 127; 126, identifier:probability; 127, subscript; 127, 128; 127, 129; 128, identifier:fitnessSorted; 129, identifier:i; 130, binary_operator:+; 130, 131; 130, 140; 131, parenthesized_expression; 131, 132; 132, binary_operator:/; 132, 133; 132, 137; 133, parenthesized_expression; 133, 134; 134, binary_operator:-; 134, 135; 134, 136; 135, integer:2; 136, identifier:S; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:length; 140, binary_operator:/; 140, 141; 140, 150; 141, parenthesized_expression; 141, 142; 142, binary_operator:*; 142, 143; 142, 146; 143, binary_operator:*; 143, 144; 143, 145; 144, integer:2; 145, identifier:i; 146, parenthesized_expression; 146, 147; 147, binary_operator:-; 147, 148; 147, 149; 148, identifier:S; 149, integer:1; 150, parenthesized_expression; 150, 151; 151, binary_operator:*; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:length; 155, parenthesized_expression; 155, 156; 156, binary_operator:-; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:length; 160, integer:1; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:rankingComputed; 166, integer:1; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:fitness; 172, identifier:fitnessAll; 173, return_statement; 173, 174; 174, list:[fitnessAll, fitnessSorted[::-1], probability]; 174, 175; 174, 176; 174, 183; 175, identifier:fitnessAll; 176, subscript; 176, 177; 176, 178; 177, identifier:fitnessSorted; 178, slice; 178, 179; 178, 180; 178, 181; 179, colon; 180, colon; 181, unary_operator:-; 181, 182; 182, integer:1; 183, identifier:probability
def rankingEval(self): ''' Sorting the pop. base on the fitnessEval result ''' fitnessAll = numpy.zeros(self.length) fitnessNorm = numpy.zeros(self.length) for i in range(self.length): self.Ind[i].fitnessEval() fitnessAll[i] = self.Ind[i].fitness maxFitness = fitnessAll.max() for i in range(self.length): fitnessNorm[i] = (maxFitness - fitnessAll[i]) / maxFitness fitnessSorted = fitnessNorm.argsort() probability = numpy.zeros(self.length) S = 2.0 for i in range(self.length): probability[fitnessSorted[i]] = ((2-S)/self.length) + (2*i*(S-1))/(self.length*(self.length-1)) self.rankingComputed = 1 self.fitness = fitnessAll return [fitnessAll, fitnessSorted[::-1], probability]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sortedbyAge; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 19; 5, 40; 5, 48; 6, expression_statement; 6, 7; 7, string:''' Sorting the pop. base of the age '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:ageAll; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:numpy; 14, identifier:zeros; 15, argument_list; 15, 16; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:length; 19, for_statement; 19, 20; 19, 21; 19, 27; 20, identifier:i; 21, call; 21, 22; 21, 23; 22, identifier:range; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:length; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:ageAll; 32, identifier:i; 33, attribute; 33, 34; 33, 39; 34, subscript; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:Ind; 38, identifier:i; 39, identifier:age; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:ageSorted; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:ageAll; 46, identifier:argsort; 47, argument_list; 48, return_statement; 48, 49; 49, subscript; 49, 50; 49, 51; 50, identifier:ageSorted; 51, slice; 51, 52; 51, 53; 51, 54; 52, colon; 53, colon; 54, unary_operator:-; 54, 55; 55, integer:1
def sortedbyAge(self): ''' Sorting the pop. base of the age ''' ageAll = numpy.zeros(self.length) for i in range(self.length): ageAll[i] = self.Ind[i].age ageSorted = ageAll.argsort() return ageSorted[::-1]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:upcoming_releases; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:product; 6, block; 6, 7; 6, 11; 6, 19; 6, 36; 6, 42; 6, 52; 6, 59; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:url; 10, string:'api/v6/releases/'; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:url; 14, binary_operator:+; 14, 15; 14, 18; 15, binary_operator:+; 15, 16; 15, 17; 16, identifier:url; 17, string:'?product__shortname='; 18, identifier:product; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:url; 22, binary_operator:+; 22, 23; 22, 26; 23, binary_operator:+; 23, 24; 23, 25; 24, identifier:url; 25, string:'&ga_date__gte='; 26, call; 26, 27; 26, 34; 27, attribute; 27, 28; 27, 33; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:date; 31, identifier:today; 32, argument_list; 33, identifier:strftime; 34, argument_list; 34, 35; 35, string:'%Y-%m-%d'; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:url; 39, binary_operator:+; 39, 40; 39, 41; 40, identifier:url; 41, string:'&ordering=shortname_sort'; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:releases; 45, yield; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_get; 50, argument_list; 50, 51; 51, identifier:url; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:result; 55, call; 55, 56; 55, 57; 56, identifier:munchify; 57, argument_list; 57, 58; 58, identifier:releases; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:defer; 63, identifier:returnValue; 64, argument_list; 64, 65; 65, identifier:result
def upcoming_releases(self, product): url = 'api/v6/releases/' url = url + '?product__shortname=' + product url = url + '&ga_date__gte=' + date.today().strftime('%Y-%m-%d') url = url + '&ordering=shortname_sort' releases = yield self._get(url) result = munchify(releases) defer.returnValue(result)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:es_field_sort; 3, parameters; 3, 4; 4, identifier:fld_name; 5, block; 5, 6; 5, 15; 5, 35; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:parts; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:fld_name; 12, identifier:split; 13, argument_list; 13, 14; 14, string:"."; 15, if_statement; 15, 16; 15, 22; 16, comparison_operator:not; 16, 17; 16, 18; 17, string:"_"; 18, subscript; 18, 19; 18, 20; 19, identifier:parts; 20, unary_operator:-; 20, 21; 21, integer:1; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 29; 25, subscript; 25, 26; 25, 27; 26, identifier:parts; 27, unary_operator:-; 27, 28; 28, integer:1; 29, binary_operator:+; 29, 30; 29, 31; 30, string:"_"; 31, subscript; 31, 32; 31, 33; 32, identifier:parts; 33, unary_operator:-; 33, 34; 34, integer:1; 35, return_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, string:"."; 39, identifier:join; 40, argument_list; 40, 41; 41, identifier:parts
def es_field_sort(fld_name): parts = fld_name.split(".") if "_" not in parts[-1]: parts[-1] = "_" + parts[-1] return ".".join(parts)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_vars; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 5, 40; 5, 44; 5, 106; 5, 129; 5, 337; 5, 349; 5, 356; 6, expression_statement; 6, 7; 7, string:''' load the vars section from a play, accounting for all sorts of variable features including loading from yaml files, prompting, and conditional includes of the first file found in a list. '''; 8, if_statement; 8, 9; 8, 14; 9, comparison_operator:is; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:vars; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:vars; 20, dictionary; 21, if_statement; 21, 22; 21, 32; 22, comparison_operator:not; 22, 23; 22, 29; 23, call; 23, 24; 23, 25; 24, identifier:type; 25, argument_list; 25, 26; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:vars; 29, list:[dict, list]; 29, 30; 29, 31; 30, identifier:dict; 31, identifier:list; 32, block; 32, 33; 33, raise_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:errors; 37, identifier:AnsibleError; 38, argument_list; 38, 39; 39, string:"'vars' section must contain only key/value pairs"; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:vars; 43, dictionary; 44, if_statement; 44, 45; 44, 53; 44, 95; 45, comparison_operator:==; 45, 46; 45, 52; 46, call; 46, 47; 46, 48; 47, identifier:type; 48, argument_list; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:vars; 52, identifier:list; 53, block; 53, 54; 54, for_statement; 54, 55; 54, 56; 54, 59; 55, identifier:item; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:vars; 59, block; 59, 60; 59, 77; 59, 89; 60, if_statement; 60, 61; 60, 69; 61, comparison_operator:is; 61, 62; 61, 68; 62, call; 62, 63; 62, 64; 63, identifier:getattr; 64, argument_list; 64, 65; 64, 66; 64, 67; 65, identifier:item; 66, string:'items'; 67, None; 68, None; 69, block; 69, 70; 70, raise_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:errors; 74, identifier:AnsibleError; 75, argument_list; 75, 76; 76, string:"expecting a key-value pair in 'vars' section"; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, pattern_list; 79, 80; 79, 81; 80, identifier:k; 81, identifier:v; 82, subscript; 82, 83; 82, 88; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:item; 86, identifier:items; 87, argument_list; 88, integer:0; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:vars; 93, identifier:k; 94, identifier:v; 95, else_clause; 95, 96; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:vars; 101, identifier:update; 102, argument_list; 102, 103; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:vars; 106, if_statement; 106, 107; 106, 117; 107, comparison_operator:==; 107, 108; 107, 116; 108, call; 108, 109; 108, 110; 109, identifier:type; 110, argument_list; 110, 111; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:playbook; 115, identifier:extra_vars; 116, identifier:dict; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:vars; 122, identifier:update; 123, argument_list; 123, 124; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:playbook; 128, identifier:extra_vars; 129, if_statement; 129, 130; 129, 138; 129, 265; 129, 328; 130, comparison_operator:==; 130, 131; 130, 137; 131, call; 131, 132; 131, 133; 132, identifier:type; 133, argument_list; 133, 134; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:vars_prompt; 137, identifier:list; 138, block; 138, 139; 139, for_statement; 139, 140; 139, 141; 139, 144; 140, identifier:var; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:vars_prompt; 144, block; 144, 145; 144, 158; 144, 164; 144, 174; 144, 184; 144, 194; 144, 204; 144, 214; 144, 224; 144, 234; 145, if_statement; 145, 146; 145, 150; 146, not_operator; 146, 147; 147, comparison_operator:in; 147, 148; 147, 149; 148, string:'name'; 149, identifier:var; 150, block; 150, 151; 151, raise_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:errors; 155, identifier:AnsibleError; 156, argument_list; 156, 157; 157, string:"'vars_prompt' item is missing 'name:'"; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:vname; 161, subscript; 161, 162; 161, 163; 162, identifier:var; 163, string:'name'; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:prompt; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:var; 170, identifier:get; 171, argument_list; 171, 172; 171, 173; 172, string:"prompt"; 173, identifier:vname; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:default; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:var; 180, identifier:get; 181, argument_list; 181, 182; 181, 183; 182, string:"default"; 183, None; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:private; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:var; 190, identifier:get; 191, argument_list; 191, 192; 191, 193; 192, string:"private"; 193, True; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:confirm; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:var; 200, identifier:get; 201, argument_list; 201, 202; 201, 203; 202, string:"confirm"; 203, False; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:encrypt; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:var; 210, identifier:get; 211, argument_list; 211, 212; 211, 213; 212, string:"encrypt"; 213, None; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:salt_size; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:var; 220, identifier:get; 221, argument_list; 221, 222; 221, 223; 222, string:"salt_size"; 223, None; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:salt; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:var; 230, identifier:get; 231, argument_list; 231, 232; 231, 233; 232, string:"salt"; 233, None; 234, if_statement; 234, 235; 234, 242; 235, comparison_operator:not; 235, 236; 235, 237; 236, identifier:vname; 237, attribute; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:playbook; 241, identifier:extra_vars; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:vars; 247, identifier:vname; 248, call; 248, 249; 248, 256; 249, attribute; 249, 250; 249, 255; 250, attribute; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:playbook; 254, identifier:callbacks; 255, identifier:on_vars_prompt; 256, argument_list; 256, 257; 256, 258; 256, 259; 256, 260; 256, 261; 256, 262; 256, 263; 256, 264; 257, identifier:vname; 258, identifier:private; 259, identifier:prompt; 260, identifier:encrypt; 261, identifier:confirm; 262, identifier:salt_size; 263, identifier:salt; 264, identifier:default; 265, elif_clause; 265, 266; 265, 274; 266, comparison_operator:==; 266, 267; 266, 273; 267, call; 267, 268; 267, 269; 268, identifier:type; 269, argument_list; 269, 270; 270, attribute; 270, 271; 270, 272; 271, identifier:self; 272, identifier:vars_prompt; 273, identifier:dict; 274, block; 274, 275; 275, for_statement; 275, 276; 275, 279; 275, 286; 276, tuple_pattern; 276, 277; 276, 278; 277, identifier:vname; 278, identifier:prompt; 279, call; 279, 280; 279, 285; 280, attribute; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:self; 283, identifier:vars_prompt; 284, identifier:iteritems; 285, argument_list; 286, block; 286, 287; 286, 293; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:prompt_msg; 290, binary_operator:%; 290, 291; 290, 292; 291, string:"%s: "; 292, identifier:prompt; 293, if_statement; 293, 294; 293, 301; 294, comparison_operator:not; 294, 295; 294, 296; 295, identifier:vname; 296, attribute; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:self; 299, identifier:playbook; 300, identifier:extra_vars; 301, block; 301, 302; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 307; 304, subscript; 304, 305; 304, 306; 305, identifier:vars; 306, identifier:vname; 307, call; 307, 308; 307, 315; 308, attribute; 308, 309; 308, 314; 309, attribute; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:self; 312, identifier:playbook; 313, identifier:callbacks; 314, identifier:on_vars_prompt; 315, argument_list; 315, 316; 315, 319; 315, 322; 315, 325; 316, keyword_argument; 316, 317; 316, 318; 317, identifier:varname; 318, identifier:vname; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:private; 321, False; 322, keyword_argument; 322, 323; 322, 324; 323, identifier:prompt; 324, identifier:prompt_msg; 325, keyword_argument; 325, 326; 325, 327; 326, identifier:default; 327, None; 328, else_clause; 328, 329; 329, block; 329, 330; 330, raise_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:errors; 334, identifier:AnsibleError; 335, argument_list; 335, 336; 336, string:"'vars_prompt' section is malformed, see docs"; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 340; 339, identifier:results; 340, call; 340, 341; 340, 348; 341, attribute; 341, 342; 341, 347; 342, attribute; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:self; 345, identifier:playbook; 346, identifier:extra_vars; 347, identifier:copy; 348, argument_list; 349, expression_statement; 349, 350; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:results; 353, identifier:update; 354, argument_list; 354, 355; 355, identifier:vars; 356, return_statement; 356, 357; 357, identifier:results
def _get_vars(self): ''' load the vars section from a play, accounting for all sorts of variable features including loading from yaml files, prompting, and conditional includes of the first file found in a list. ''' if self.vars is None: self.vars = {} if type(self.vars) not in [dict, list]: raise errors.AnsibleError("'vars' section must contain only key/value pairs") vars = {} if type(self.vars) == list: for item in self.vars: if getattr(item, 'items', None) is None: raise errors.AnsibleError("expecting a key-value pair in 'vars' section") k, v = item.items()[0] vars[k] = v else: vars.update(self.vars) if type(self.playbook.extra_vars) == dict: vars.update(self.playbook.extra_vars) if type(self.vars_prompt) == list: for var in self.vars_prompt: if not 'name' in var: raise errors.AnsibleError("'vars_prompt' item is missing 'name:'") vname = var['name'] prompt = var.get("prompt", vname) default = var.get("default", None) private = var.get("private", True) confirm = var.get("confirm", False) encrypt = var.get("encrypt", None) salt_size = var.get("salt_size", None) salt = var.get("salt", None) if vname not in self.playbook.extra_vars: vars[vname] = self.playbook.callbacks.on_vars_prompt ( vname, private, prompt, encrypt, confirm, salt_size, salt, default ) elif type(self.vars_prompt) == dict: for (vname, prompt) in self.vars_prompt.iteritems(): prompt_msg = "%s: " % prompt if vname not in self.playbook.extra_vars: vars[vname] = self.playbook.callbacks.on_vars_prompt( varname=vname, private=False, prompt=prompt_msg, default=None ) else: raise errors.AnsibleError("'vars_prompt' section is malformed, see docs") results = self.playbook.extra_vars.copy() results.update(vars) return results
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:list_refs; 3, parameters; 3, 4; 3, 5; 4, identifier:profile; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ref_type; 7, None; 8, block; 8, 9; 8, 13; 8, 22; 8, 32; 8, 43; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:resource; 12, string:"/refs"; 13, if_statement; 13, 14; 13, 15; 14, identifier:ref_type; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, augmented_assignment:+=; 17, 18; 17, 19; 18, identifier:resource; 19, binary_operator:+; 19, 20; 19, 21; 20, string:"/"; 21, identifier:ref_type; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:data; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:api; 28, identifier:get_request; 29, argument_list; 29, 30; 29, 31; 30, identifier:profile; 31, identifier:resource; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:result; 35, list_comprehension; 35, 36; 35, 40; 36, call; 36, 37; 36, 38; 37, identifier:prepare; 38, argument_list; 38, 39; 39, identifier:x; 40, for_in_clause; 40, 41; 40, 42; 41, identifier:x; 42, identifier:data; 43, return_statement; 43, 44; 44, identifier:result
def list_refs(profile, ref_type=None): resource = "/refs" if ref_type: resource += "/" + ref_type data = api.get_request(profile, resource) result = [prepare(x) for x in data] return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 12; 3, 15; 4, identifier:self; 5, identifier:fieldname; 6, default_parameter; 6, 7; 6, 8; 7, identifier:key; 8, lambda; 8, 9; 8, 11; 9, lambda_parameters; 9, 10; 10, identifier:x; 11, identifier:x; 12, default_parameter; 12, 13; 12, 14; 13, identifier:desc; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:inplace; 17, False; 18, block; 18, 19; 18, 45; 18, 84; 18, 93; 18, 114; 19, try_statement; 19, 20; 19, 35; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:field_index; 24, call; 24, 25; 24, 33; 25, attribute; 25, 26; 25, 32; 26, call; 26, 27; 26, 28; 27, identifier:tuple; 28, argument_list; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:fields; 32, identifier:index; 33, argument_list; 33, 34; 34, identifier:fieldname; 35, except_clause; 35, 36; 35, 37; 36, identifier:ValueError; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:ValueError; 41, argument_list; 41, 42; 42, binary_operator:%; 42, 43; 42, 44; 43, string:"Sorting on a field that doesn't exist: `%s`"; 44, identifier:fieldname; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:data_cols; 48, call; 48, 49; 48, 50; 49, identifier:izip; 50, argument_list; 50, 51; 51, list_splat; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:sorted; 54, argument_list; 54, 55; 54, 70; 54, 81; 55, call; 55, 56; 55, 57; 56, identifier:izip; 57, argument_list; 57, 58; 58, list_splat; 58, 59; 59, list_comprehension; 59, 60; 59, 65; 60, subscript; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:__data; 64, identifier:field; 65, for_in_clause; 65, 66; 65, 67; 66, identifier:field; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:fields; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:key; 72, lambda; 72, 73; 72, 75; 73, lambda_parameters; 73, 74; 74, identifier:row; 75, call; 75, 76; 75, 77; 76, identifier:key; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 80; 79, identifier:row; 80, identifier:field_index; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:reverse; 83, identifier:desc; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:target_table; 87, conditional_expression:if; 87, 88; 87, 89; 87, 90; 88, identifier:self; 89, identifier:inplace; 90, call; 90, 91; 90, 92; 91, identifier:DataTable; 92, argument_list; 93, for_statement; 93, 94; 93, 97; 93, 104; 94, pattern_list; 94, 95; 94, 96; 95, identifier:field; 96, identifier:data_col; 97, call; 97, 98; 97, 99; 98, identifier:izip; 99, argument_list; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:fields; 103, identifier:data_cols; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:target_table; 109, identifier:field; 110, call; 110, 111; 110, 112; 111, identifier:list; 112, argument_list; 112, 113; 113, identifier:data_col; 114, return_statement; 114, 115; 115, identifier:target_table
def sort(self, fieldname, key=lambda x: x, desc=False, inplace=False): try: field_index = tuple(self.fields).index(fieldname) except ValueError: raise ValueError("Sorting on a field that doesn't exist: `%s`" % fieldname) data_cols = izip(*sorted(izip(*[self.__data[field] for field in self.fields]), key=lambda row: key(row[field_index]), reverse=desc)) target_table = self if inplace else DataTable() for field, data_col in izip(self.fields, data_cols): target_table[field] = list(data_col) return target_table
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:intersectingIntervalIterator; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:start; 6, identifier:end; 7, block; 7, 8; 7, 18; 7, 32; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:items; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:intersectingInterval; 15, argument_list; 15, 16; 15, 17; 16, identifier:start; 17, identifier:end; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:items; 22, identifier:sort; 23, argument_list; 23, 24; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:key; 26, lambda; 26, 27; 26, 29; 27, lambda_parameters; 27, 28; 28, identifier:x; 29, attribute; 29, 30; 29, 31; 30, identifier:x; 31, identifier:start; 32, for_statement; 32, 33; 32, 34; 32, 35; 33, identifier:item; 34, identifier:items; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, yield; 37, 38; 38, identifier:item
def intersectingIntervalIterator(self, start, end): items = self.intersectingInterval(start, end) items.sort(key=lambda x: x.start) for item in items: yield item
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sanitize_usecols; 3, parameters; 3, 4; 4, identifier:usecols; 5, block; 5, 6; 5, 13; 5, 63; 5, 67; 5, 128; 5, 138; 5, 144; 6, if_statement; 6, 7; 6, 10; 7, comparison_operator:is; 7, 8; 7, 9; 8, identifier:usecols; 9, None; 10, block; 10, 11; 11, return_statement; 11, 12; 12, None; 13, try_statement; 13, 14; 13, 38; 14, block; 14, 15; 14, 24; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:pats; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:usecols; 21, identifier:split; 22, argument_list; 22, 23; 23, string:','; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:pats; 27, list_comprehension; 27, 28; 27, 33; 27, 36; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:p; 31, identifier:strip; 32, argument_list; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:p; 35, identifier:pats; 36, if_clause; 36, 37; 37, identifier:p; 38, except_clause; 38, 39; 38, 40; 39, identifier:AttributeError; 40, block; 40, 41; 40, 52; 40, 58; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:usecols; 44, list_comprehension; 44, 45; 44, 49; 45, call; 45, 46; 45, 47; 46, identifier:int; 47, argument_list; 47, 48; 48, identifier:c; 49, for_in_clause; 49, 50; 49, 51; 50, identifier:c; 51, identifier:usecols; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:usecols; 56, identifier:sort; 57, argument_list; 58, return_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:tuple; 61, argument_list; 61, 62; 62, identifier:usecols; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:cols; 66, list:[]; 67, for_statement; 67, 68; 67, 69; 67, 70; 68, identifier:pat; 69, identifier:pats; 70, block; 70, 71; 71, if_statement; 71, 72; 71, 75; 71, 115; 72, comparison_operator:in; 72, 73; 72, 74; 73, string:':'; 74, identifier:pat; 75, block; 75, 76; 75, 87; 75, 97; 75, 107; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, pattern_list; 78, 79; 78, 80; 79, identifier:c1; 80, identifier:c2; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:pat; 84, identifier:split; 85, argument_list; 85, 86; 86, string:':'; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:n1; 90, call; 90, 91; 90, 92; 91, identifier:letter2num; 92, argument_list; 92, 93; 92, 94; 93, identifier:c1; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:zbase; 96, True; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:n2; 100, call; 100, 101; 100, 102; 101, identifier:letter2num; 102, argument_list; 102, 103; 102, 104; 103, identifier:c2; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:zbase; 106, False; 107, expression_statement; 107, 108; 108, augmented_assignment:+=; 108, 109; 108, 110; 109, identifier:cols; 110, call; 110, 111; 110, 112; 111, identifier:range; 112, argument_list; 112, 113; 112, 114; 113, identifier:n1; 114, identifier:n2; 115, else_clause; 115, 116; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, augmented_assignment:+=; 118, 119; 118, 120; 119, identifier:cols; 120, list:[letter2num(pat, zbase=True)]; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:letter2num; 123, argument_list; 123, 124; 123, 125; 124, identifier:pat; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:zbase; 127, True; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:cols; 131, call; 131, 132; 131, 133; 132, identifier:list; 133, argument_list; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:set; 136, argument_list; 136, 137; 137, identifier:cols; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:cols; 142, identifier:sort; 143, argument_list; 144, return_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:tuple; 147, argument_list; 147, 148; 148, identifier:cols
def _sanitize_usecols(usecols): if usecols is None: return None try: pats = usecols.split(',') pats = [p.strip() for p in pats if p] except AttributeError: usecols = [int(c) for c in usecols] usecols.sort() return tuple(usecols) cols = [] for pat in pats: if ':' in pat: c1, c2 = pat.split(':') n1 = letter2num(c1, zbase=True) n2 = letter2num(c2, zbase=False) cols += range(n1, n2) else: cols += [letter2num(pat, zbase=True)] cols = list(set(cols)) cols.sort() return tuple(cols)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:binary_search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:data; 5, identifier:target; 6, default_parameter; 6, 7; 6, 8; 7, identifier:lo; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:hi; 11, None; 12, block; 12, 13; 12, 25; 12, 34; 12, 62; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:hi; 16, conditional_expression:if; 16, 17; 16, 18; 16, 21; 17, identifier:hi; 18, comparison_operator:is; 18, 19; 18, 20; 19, identifier:hi; 20, None; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:data; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:mid; 28, binary_operator://; 28, 29; 28, 33; 29, parenthesized_expression; 29, 30; 30, binary_operator:+; 30, 31; 30, 32; 31, identifier:lo; 32, identifier:hi; 33, integer:2; 34, if_statement; 34, 35; 34, 58; 35, boolean_operator:or; 35, 36; 35, 53; 36, boolean_operator:or; 36, 37; 36, 47; 37, boolean_operator:or; 37, 38; 37, 41; 38, comparison_operator:<; 38, 39; 38, 40; 39, identifier:hi; 40, integer:2; 41, comparison_operator:>; 41, 42; 41, 43; 42, identifier:hi; 43, call; 43, 44; 43, 45; 44, identifier:len; 45, argument_list; 45, 46; 46, identifier:data; 47, comparison_operator:>; 47, 48; 47, 49; 48, identifier:target; 49, subscript; 49, 50; 49, 51; 50, identifier:data; 51, unary_operator:-; 51, 52; 52, integer:1; 53, comparison_operator:<; 53, 54; 53, 55; 54, identifier:target; 55, subscript; 55, 56; 55, 57; 56, identifier:data; 57, integer:0; 58, block; 58, 59; 59, return_statement; 59, 60; 60, unary_operator:-; 60, 61; 61, integer:1; 62, if_statement; 62, 63; 62, 68; 62, 81; 62, 103; 63, comparison_operator:>; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:data; 66, identifier:mid; 67, identifier:target; 68, block; 68, 69; 69, return_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:binary_search; 72, argument_list; 72, 73; 72, 74; 72, 75; 72, 78; 73, identifier:data; 74, identifier:target; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:lo; 77, identifier:lo; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:hi; 80, identifier:mid; 81, elif_clause; 81, 82; 81, 87; 82, comparison_operator:<; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:data; 85, identifier:mid; 86, identifier:target; 87, block; 87, 88; 88, return_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:binary_search; 91, argument_list; 91, 92; 91, 93; 91, 94; 91, 100; 92, identifier:data; 93, identifier:target; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:lo; 96, parenthesized_expression; 96, 97; 97, binary_operator:+; 97, 98; 97, 99; 98, identifier:mid; 99, integer:1; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:hi; 102, identifier:hi; 103, elif_clause; 103, 104; 103, 109; 104, comparison_operator:==; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:data; 107, identifier:mid; 108, identifier:target; 109, block; 109, 110; 110, return_statement; 110, 111; 111, identifier:mid
def binary_search(data, target, lo=0, hi=None): hi = hi if hi is not None else len(data) mid = (lo + hi) // 2 if hi < 2 or hi > len(data) or target > data[-1] or target < data[0]: return -1 if data[mid] > target: return binary_search(data, target, lo=lo, hi=mid) elif data[mid] < target: return binary_search(data, target, lo=(mid + 1), hi=hi) elif data[mid] == target: return mid
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:repr_feature; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:feature; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_keys; 7, integer:100; 8, default_parameter; 8, 9; 8, 10; 9, identifier:indent; 10, integer:8; 11, default_parameter; 11, 12; 11, 13; 12, identifier:lexigraphic; 13, False; 14, block; 14, 15; 14, 17; 14, 46; 14, 77; 15, expression_statement; 15, 16; 16, string:''' generate a pretty-printed string for a feature Currently implemented: * StringCounter @max_keys: truncate long counters @indent: indent multi-line displays by this many spaces @lexigraphic: instead of sorting counters by count (default), sort keys lexigraphically '''; 17, if_statement; 17, 18; 17, 25; 18, call; 18, 19; 18, 20; 19, identifier:isinstance; 20, argument_list; 20, 21; 20, 22; 21, identifier:feature; 22, tuple; 22, 23; 22, 24; 23, identifier:str; 24, identifier:bytes; 25, block; 25, 26; 26, try_statement; 26, 27; 26, 39; 27, block; 27, 28; 27, 37; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:ustr; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:feature; 34, identifier:decode; 35, argument_list; 35, 36; 36, string:'utf8'; 37, return_statement; 37, 38; 38, identifier:ustr; 39, except_clause; 39, 40; 40, block; 40, 41; 41, return_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:repr; 44, argument_list; 44, 45; 45, identifier:feature; 46, if_statement; 46, 47; 46, 52; 46, 61; 46, 70; 47, call; 47, 48; 47, 49; 48, identifier:isinstance; 49, argument_list; 49, 50; 49, 51; 50, identifier:feature; 51, identifier:StringCounter; 52, block; 52, 53; 53, return_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:repr_stringcounter; 56, argument_list; 56, 57; 56, 58; 56, 59; 56, 60; 57, identifier:feature; 58, identifier:max_keys; 59, identifier:indent; 60, identifier:lexigraphic; 61, elif_clause; 61, 62; 61, 67; 62, call; 62, 63; 62, 64; 63, identifier:isinstance; 64, argument_list; 64, 65; 64, 66; 65, identifier:feature; 66, identifier:unicode; 67, block; 67, 68; 68, return_statement; 68, 69; 69, identifier:feature; 70, else_clause; 70, 71; 71, block; 71, 72; 72, return_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:repr; 75, argument_list; 75, 76; 76, identifier:feature; 77, assert_statement; 77, 78; 77, 79; 78, False; 79, string:'internal logic failure, no branch taken'
def repr_feature(feature, max_keys=100, indent=8, lexigraphic=False): ''' generate a pretty-printed string for a feature Currently implemented: * StringCounter @max_keys: truncate long counters @indent: indent multi-line displays by this many spaces @lexigraphic: instead of sorting counters by count (default), sort keys lexigraphically ''' if isinstance(feature, (str, bytes)): try: ustr = feature.decode('utf8') return ustr except: return repr(feature) if isinstance(feature, StringCounter): return repr_stringcounter(feature, max_keys, indent, lexigraphic) elif isinstance(feature, unicode): return feature else: return repr(feature) assert False, 'internal logic failure, no branch taken'
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_getkey; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:args; 6, identifier:kwargs; 7, block; 7, 8; 7, 15; 7, 25; 7, 40; 7, 50; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:values; 11, call; 11, 12; 11, 13; 12, identifier:list; 13, argument_list; 13, 14; 14, identifier:args; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:keys; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:list; 23, argument_list; 23, 24; 24, identifier:kwargs; 25, for_statement; 25, 26; 25, 27; 25, 28; 26, identifier:key; 27, identifier:keys; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:values; 33, identifier:append; 34, argument_list; 34, 35; 35, tuple; 35, 36; 35, 37; 36, identifier:key; 37, subscript; 37, 38; 37, 39; 38, identifier:kwargs; 39, identifier:key; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:result; 43, call; 43, 44; 43, 45; 44, identifier:hash; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:tuple; 48, argument_list; 48, 49; 49, identifier:values; 50, return_statement; 50, 51; 51, identifier:result
def _getkey(self, args, kwargs): values = list(args) keys = sorted(list(kwargs)) for key in keys: values.append((key, kwargs[key])) result = hash(tuple(values)) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:iterator; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 18; 5, 143; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:results; 9, call; 9, 10; 9, 17; 10, attribute; 10, 11; 10, 16; 11, call; 11, 12; 11, 13; 12, identifier:super; 13, argument_list; 13, 14; 13, 15; 14, identifier:SearchableQuerySet; 15, identifier:self; 16, identifier:iterator; 17, argument_list; 18, if_statement; 18, 19; 18, 27; 19, boolean_operator:and; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_search_terms; 23, not_operator; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_search_ordered; 27, block; 27, 28; 27, 35; 27, 138; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:results; 31, call; 31, 32; 31, 33; 32, identifier:list; 33, argument_list; 33, 34; 34, identifier:results; 35, for_statement; 35, 36; 35, 39; 35, 43; 36, pattern_list; 36, 37; 36, 38; 37, identifier:i; 38, identifier:result; 39, call; 39, 40; 39, 41; 40, identifier:enumerate; 41, argument_list; 41, 42; 42, identifier:results; 43, block; 43, 44; 43, 48; 43, 52; 43, 109; 43, 130; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:count; 47, integer:0; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:related_weights; 51, list:[]; 52, for_statement; 52, 53; 52, 56; 52, 63; 53, tuple_pattern; 53, 54; 53, 55; 54, identifier:field; 55, identifier:weight; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_search_fields; 61, identifier:items; 62, argument_list; 63, block; 63, 64; 63, 76; 64, if_statement; 64, 65; 64, 68; 65, comparison_operator:in; 65, 66; 65, 67; 66, string:"__"; 67, identifier:field; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:related_weights; 73, identifier:append; 74, argument_list; 74, 75; 75, identifier:weight; 76, for_statement; 76, 77; 76, 78; 76, 81; 77, identifier:term; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:_search_terms; 81, block; 81, 82; 81, 91; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:field_value; 85, call; 85, 86; 85, 87; 86, identifier:getattr; 87, argument_list; 87, 88; 87, 89; 87, 90; 88, identifier:result; 89, identifier:field; 90, None; 91, if_statement; 91, 92; 91, 93; 92, identifier:field_value; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, augmented_assignment:+=; 95, 96; 95, 97; 96, identifier:count; 97, binary_operator:*; 97, 98; 97, 108; 98, call; 98, 99; 98, 106; 99, attribute; 99, 100; 99, 105; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:field_value; 103, identifier:lower; 104, argument_list; 105, identifier:count; 106, argument_list; 106, 107; 107, identifier:term; 108, identifier:weight; 109, if_statement; 109, 110; 109, 114; 110, boolean_operator:and; 110, 111; 110, 113; 111, not_operator; 111, 112; 112, identifier:count; 113, identifier:related_weights; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:count; 118, call; 118, 119; 118, 120; 119, identifier:int; 120, argument_list; 120, 121; 121, binary_operator:/; 121, 122; 121, 126; 122, call; 122, 123; 122, 124; 123, identifier:sum; 124, argument_list; 124, 125; 125, identifier:related_weights; 126, call; 126, 127; 126, 128; 127, identifier:len; 128, argument_list; 128, 129; 129, identifier:related_weights; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:results; 135, identifier:i; 136, identifier:result_count; 137, identifier:count; 138, return_statement; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:iter; 141, argument_list; 141, 142; 142, identifier:results; 143, return_statement; 143, 144; 144, identifier:results
def iterator(self): results = super(SearchableQuerySet, self).iterator() if self._search_terms and not self._search_ordered: results = list(results) for i, result in enumerate(results): count = 0 related_weights = [] for (field, weight) in self._search_fields.items(): if "__" in field: related_weights.append(weight) for term in self._search_terms: field_value = getattr(result, field, None) if field_value: count += field_value.lower().count(term) * weight if not count and related_weights: count = int(sum(related_weights) / len(related_weights)) results[i].result_count = count return iter(results) return results
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:save_as_json; 3, parameters; 3, 4; 3, 8; 3, 11; 3, 16; 3, 19; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:total; 6, type; 6, 7; 7, identifier:list; 8, default_parameter; 8, 9; 8, 10; 9, identifier:name; 10, string:'data.json'; 11, typed_default_parameter; 11, 12; 11, 13; 11, 15; 12, identifier:sort_by; 13, type; 13, 14; 14, identifier:str; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:no_duplicate; 18, False; 19, default_parameter; 19, 20; 19, 21; 20, identifier:order; 21, string:'asc'; 22, block; 22, 23; 22, 48; 22, 64; 22, 76; 23, if_statement; 23, 24; 23, 25; 24, identifier:sort_by; 25, block; 25, 26; 25, 32; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:reverse; 29, comparison_operator:==; 29, 30; 29, 31; 30, identifier:order; 31, string:'desc'; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:total; 35, call; 35, 36; 35, 37; 36, identifier:sorted; 37, argument_list; 37, 38; 37, 39; 37, 45; 38, identifier:total; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:key; 41, call; 41, 42; 41, 43; 42, identifier:itemgetter; 43, argument_list; 43, 44; 44, identifier:sort_by; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:reverse; 47, identifier:reverse; 48, if_statement; 48, 49; 48, 50; 49, identifier:no_duplicate; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:total; 54, list_comprehension; 54, 55; 54, 56; 55, identifier:key; 56, for_in_clause; 56, 57; 56, 60; 57, pattern_list; 57, 58; 57, 59; 58, identifier:key; 59, identifier:_; 60, call; 60, 61; 60, 62; 61, identifier:groupby; 62, argument_list; 62, 63; 63, identifier:total; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:data; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:json; 70, identifier:dumps; 71, argument_list; 71, 72; 71, 73; 72, identifier:total; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:ensure_ascii; 75, False; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 84; 78, attribute; 78, 79; 78, 83; 79, call; 79, 80; 79, 81; 80, identifier:Path; 81, argument_list; 81, 82; 82, identifier:name; 83, identifier:write_text; 84, argument_list; 84, 85; 84, 86; 85, identifier:data; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:encoding; 88, string:'utf-8'
def save_as_json(total: list, name='data.json', sort_by: str = None, no_duplicate=False, order='asc'): if sort_by: reverse = order == 'desc' total = sorted(total, key=itemgetter(sort_by), reverse=reverse) if no_duplicate: total = [key for key, _ in groupby(total)] data = json.dumps(total, ensure_ascii=False) Path(name).write_text(data, encoding='utf-8')