sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_sh_ids; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:identity; 6, identifier:backend_name; 7, block; 7, 8; 7, 19; 7, 29; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:identity_tuple; 11, call; 11, 12; 11, 13; 12, identifier:tuple; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:identity; 17, identifier:items; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:sh_ids; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:__get_sh_ids_cache; 26, argument_list; 26, 27; 26, 28; 27, identifier:identity_tuple; 28, identifier:backend_name; 29, return_statement; 29, 30; 30, identifier:sh_ids | def get_sh_ids(self, identity, backend_name):
identity_tuple = tuple(identity.items())
sh_ids = self.__get_sh_ids_cache(identity_tuple, backend_name)
return sh_ids |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_sh_identity; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:item; 6, default_parameter; 6, 7; 6, 8; 7, identifier:identity_field; 8, None; 9, block; 9, 10; 9, 60; 9, 64; 9, 77; 9, 81; 9, 101; 9, 109; 10, function_definition; 10, 11; 10, 12; 10, 15; 11, function_name:fill_list_identity; 12, parameters; 12, 13; 12, 14; 13, identifier:identity; 14, identifier:user_list_data; 15, block; 15, 16; 15, 26; 15, 41; 15, 58; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 21; 18, subscript; 18, 19; 18, 20; 19, identifier:identity; 20, string:'username'; 21, subscript; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:user_list_data; 24, integer:0; 25, string:'__text__'; 26, if_statement; 26, 27; 26, 32; 27, comparison_operator:in; 27, 28; 27, 29; 28, string:'@'; 29, subscript; 29, 30; 29, 31; 30, identifier:identity; 31, string:'username'; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:identity; 37, string:'email'; 38, subscript; 38, 39; 38, 40; 39, identifier:identity; 40, string:'username'; 41, if_statement; 41, 42; 41, 47; 42, comparison_operator:in; 42, 43; 42, 44; 43, string:'name'; 44, subscript; 44, 45; 44, 46; 45, identifier:user_list_data; 46, integer:0; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:identity; 52, string:'name'; 53, subscript; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:user_list_data; 56, integer:0; 57, string:'name'; 58, return_statement; 58, 59; 59, identifier:identity; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:identity; 63, dictionary; 64, for_statement; 64, 65; 64, 66; 64, 70; 65, identifier:field; 66, list:['name', 'email', 'username']; 66, 67; 66, 68; 66, 69; 67, string:'name'; 68, string:'email'; 69, string:'username'; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:identity; 75, identifier:field; 76, None; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:user; 80, identifier:item; 81, if_statement; 81, 82; 81, 92; 82, boolean_operator:and; 82, 83; 82, 86; 83, comparison_operator:in; 83, 84; 83, 85; 84, string:'data'; 85, identifier:item; 86, comparison_operator:==; 86, 87; 86, 91; 87, call; 87, 88; 87, 89; 88, identifier:type; 89, argument_list; 89, 90; 90, identifier:item; 91, identifier:dict; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:user; 96, subscript; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:item; 99, string:'data'; 100, identifier:identity_field; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:identity; 104, call; 104, 105; 104, 106; 105, identifier:fill_list_identity; 106, argument_list; 106, 107; 106, 108; 107, identifier:identity; 108, identifier:user; 109, return_statement; 109, 110; 110, identifier:identity | def get_sh_identity(self, item, identity_field=None):
def fill_list_identity(identity, user_list_data):
identity['username'] = user_list_data[0]['__text__']
if '@' in identity['username']:
identity['email'] = identity['username']
if 'name' in user_list_data[0]:
identity['name'] = user_list_data[0]['name']
return identity
identity = {}
for field in ['name', 'email', 'username']:
identity[field] = None
user = item
if 'data' in item and type(item) == dict:
user = item['data'][identity_field]
identity = fill_list_identity(identity, user)
return identity |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:feed; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:from_date; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:from_offset; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:category; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:latest_items; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:arthur_items; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:filter_classified; 22, None; 23, block; 23, 24; 23, 62; 23, 72; 23, 87; 23, 100; 23, 104; 23, 147; 23, 151; 23, 203; 23, 207; 23, 218; 23, 229; 23, 319; 23, 326; 24, if_statement; 24, 25; 24, 28; 24, 47; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:fetch_archive; 28, block; 28, 29; 28, 39; 28, 46; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:items; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:perceval_backend; 37, identifier:fetch_from_archive; 38, argument_list; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:feed_items; 44, argument_list; 44, 45; 45, identifier:items; 46, return_statement; 47, elif_clause; 47, 48; 47, 49; 48, identifier:arthur_items; 49, block; 49, 50; 49, 54; 49, 61; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:items; 53, identifier:arthur_items; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:feed_items; 59, argument_list; 59, 60; 60, identifier:items; 61, return_statement; 62, if_statement; 62, 63; 62, 66; 63, boolean_operator:and; 63, 64; 63, 65; 64, identifier:from_date; 65, identifier:from_offset; 66, block; 66, 67; 67, raise_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:RuntimeError; 70, argument_list; 70, 71; 71, string:"Can't not feed using from_date and from_offset."; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:filters_; 75, list:[get_repository_filter(self.perceval_backend,
self.get_connector_name())]; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:get_repository_filter; 78, argument_list; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:perceval_backend; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:get_connector_name; 86, argument_list; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:signature; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:inspect; 93, identifier:signature; 94, argument_list; 94, 95; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:perceval_backend; 99, identifier:fetch; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:last_update; 103, None; 104, if_statement; 104, 105; 104, 110; 105, comparison_operator:in; 105, 106; 105, 107; 106, string:'from_date'; 107, attribute; 107, 108; 107, 109; 108, identifier:signature; 109, identifier:parameters; 110, block; 110, 111; 110, 139; 111, if_statement; 111, 112; 111, 113; 111, 118; 112, identifier:from_date; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:last_update; 117, identifier:from_date; 118, else_clause; 118, 119; 119, block; 119, 120; 119, 133; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:last_update; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:get_last_update_from_es; 129, argument_list; 129, 130; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:filters_; 132, identifier:filters_; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:last_update; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:last_update; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:logger; 143, identifier:info; 144, argument_list; 144, 145; 144, 146; 145, string:"Incremental from: %s"; 146, identifier:last_update; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:offset; 150, None; 151, if_statement; 151, 152; 151, 157; 152, comparison_operator:in; 152, 153; 152, 154; 153, string:'offset'; 154, attribute; 154, 155; 154, 156; 155, identifier:signature; 156, identifier:parameters; 157, block; 157, 158; 157, 181; 158, if_statement; 158, 159; 158, 160; 158, 165; 159, identifier:from_offset; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:offset; 164, identifier:from_offset; 165, else_clause; 165, 166; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:offset; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:elastic; 175, identifier:get_last_offset; 176, argument_list; 176, 177; 176, 178; 177, string:"offset"; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:filters_; 180, identifier:filters_; 181, if_statement; 181, 182; 181, 185; 181, 194; 182, comparison_operator:is; 182, 183; 182, 184; 183, identifier:offset; 184, None; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:logger; 190, identifier:info; 191, argument_list; 191, 192; 191, 193; 192, string:"Incremental from: %i offset"; 193, identifier:offset; 194, else_clause; 194, 195; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:logger; 200, identifier:info; 201, argument_list; 201, 202; 202, string:"Not incremental"; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:params; 206, dictionary; 207, if_statement; 207, 208; 207, 211; 208, comparison_operator:is; 208, 209; 208, 210; 209, identifier:category; 210, None; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:params; 216, string:'category'; 217, identifier:category; 218, if_statement; 218, 219; 218, 222; 219, comparison_operator:is; 219, 220; 219, 221; 220, identifier:filter_classified; 221, None; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, subscript; 225, 226; 225, 227; 226, identifier:params; 227, string:'filter_classified'; 228, identifier:filter_classified; 229, if_statement; 229, 230; 229, 231; 229, 250; 229, 282; 229, 305; 230, identifier:latest_items; 231, block; 231, 232; 231, 238; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:params; 236, string:'latest_items'; 237, identifier:latest_items; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:items; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:perceval_backend; 246, identifier:fetch; 247, argument_list; 247, 248; 248, dictionary_splat; 248, 249; 249, identifier:params; 250, elif_clause; 250, 251; 250, 252; 251, identifier:last_update; 252, block; 252, 253; 252, 264; 252, 270; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:last_update; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:last_update; 259, identifier:replace; 260, argument_list; 260, 261; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:tzinfo; 263, None; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 269; 266, subscript; 266, 267; 266, 268; 267, identifier:params; 268, string:'from_date'; 269, identifier:last_update; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:items; 273, call; 273, 274; 273, 279; 274, attribute; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:perceval_backend; 278, identifier:fetch; 279, argument_list; 279, 280; 280, dictionary_splat; 280, 281; 281, identifier:params; 282, elif_clause; 282, 283; 282, 286; 283, comparison_operator:is; 283, 284; 283, 285; 284, identifier:offset; 285, None; 286, block; 286, 287; 286, 293; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 292; 289, subscript; 289, 290; 289, 291; 290, identifier:params; 291, string:'offset'; 292, identifier:offset; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:items; 296, call; 296, 297; 296, 302; 297, attribute; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:self; 300, identifier:perceval_backend; 301, identifier:fetch; 302, argument_list; 302, 303; 303, dictionary_splat; 303, 304; 304, identifier:params; 305, else_clause; 305, 306; 306, block; 306, 307; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:items; 310, call; 310, 311; 310, 316; 311, attribute; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:perceval_backend; 315, identifier:fetch; 316, argument_list; 316, 317; 317, dictionary_splat; 317, 318; 318, identifier:params; 319, expression_statement; 319, 320; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:self; 323, identifier:feed_items; 324, argument_list; 324, 325; 325, identifier:items; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:self; 330, identifier:update_items; 331, argument_list | def feed(self, from_date=None, from_offset=None, category=None,
latest_items=None, arthur_items=None, filter_classified=None):
if self.fetch_archive:
items = self.perceval_backend.fetch_from_archive()
self.feed_items(items)
return
elif arthur_items:
items = arthur_items
self.feed_items(items)
return
if from_date and from_offset:
raise RuntimeError("Can't not feed using from_date and from_offset.")
filters_ = [get_repository_filter(self.perceval_backend,
self.get_connector_name())]
signature = inspect.signature(self.perceval_backend.fetch)
last_update = None
if 'from_date' in signature.parameters:
if from_date:
last_update = from_date
else:
self.last_update = self.get_last_update_from_es(filters_=filters_)
last_update = self.last_update
logger.info("Incremental from: %s", last_update)
offset = None
if 'offset' in signature.parameters:
if from_offset:
offset = from_offset
else:
offset = self.elastic.get_last_offset("offset", filters_=filters_)
if offset is not None:
logger.info("Incremental from: %i offset", offset)
else:
logger.info("Not incremental")
params = {}
if category is not None:
params['category'] = category
if filter_classified is not None:
params['filter_classified'] = filter_classified
if latest_items:
params['latest_items'] = latest_items
items = self.perceval_backend.fetch(**params)
elif last_update:
last_update = last_update.replace(tzinfo=None)
params['from_date'] = last_update
items = self.perceval_backend.fetch(**params)
elif offset is not None:
params['offset'] = offset
items = self.perceval_backend.fetch(**params)
else:
items = self.perceval_backend.fetch(**params)
self.feed_items(items)
self.update_items() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_identities; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:item; 6, block; 6, 7; 6, 156; 6, 164; 6, 270; 6, 376; 7, function_definition; 7, 8; 7, 9; 7, 13; 8, function_name:add_sh_github_identity; 9, parameters; 9, 10; 9, 11; 9, 12; 10, identifier:user; 11, identifier:user_field; 12, identifier:rol; 13, block; 13, 14; 13, 18; 13, 48; 13, 53; 13, 61; 13, 74; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:github_repo; 17, None; 18, if_statement; 18, 19; 18, 24; 19, comparison_operator:in; 19, 20; 19, 21; 20, identifier:GITHUB; 21, subscript; 21, 22; 21, 23; 22, identifier:item; 23, string:'origin'; 24, block; 24, 25; 24, 37; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:github_repo; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:item; 32, string:'origin'; 33, identifier:replace; 34, argument_list; 34, 35; 34, 36; 35, identifier:GITHUB; 36, string:''; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:github_repo; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:re; 43, identifier:sub; 44, argument_list; 44, 45; 44, 46; 44, 47; 45, string:'.git$'; 46, string:''; 47, identifier:github_repo; 48, if_statement; 48, 49; 48, 51; 49, not_operator; 49, 50; 50, identifier:github_repo; 51, block; 51, 52; 52, return_statement; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:user_data; 56, subscript; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:item; 59, string:'data'; 60, identifier:user_field; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:sh_identity; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:SortingHat; 67, identifier:get_github_commit_username; 68, argument_list; 68, 69; 68, 72; 68, 73; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:sh_db; 72, identifier:user; 73, identifier:SH_GIT_COMMIT; 74, if_statement; 74, 75; 74, 77; 74, 126; 75, not_operator; 75, 76; 76, identifier:sh_identity; 77, block; 77, 78; 77, 90; 77, 100; 77, 109; 77, 115; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:gh_username; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:get_github_login; 85, argument_list; 85, 86; 85, 87; 85, 88; 85, 89; 86, identifier:user_data; 87, identifier:rol; 88, identifier:commit_hash; 89, identifier:github_repo; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:logger; 94, identifier:debug; 95, argument_list; 95, 96; 95, 97; 95, 98; 95, 99; 96, string:"Adding new identity %s to SH %s: %s"; 97, identifier:gh_username; 98, identifier:SH_GIT_COMMIT; 99, identifier:user; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:user; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:get_sh_identity; 107, argument_list; 107, 108; 108, identifier:user_data; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:user; 113, string:'username'; 114, identifier:gh_username; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:SortingHat; 119, identifier:add_identity; 120, argument_list; 120, 121; 120, 124; 120, 125; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:sh_db; 124, identifier:user; 125, identifier:SH_GIT_COMMIT; 126, else_clause; 126, 127; 127, block; 127, 128; 128, if_statement; 128, 129; 128, 134; 129, comparison_operator:not; 129, 130; 129, 131; 130, identifier:user_data; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:github_logins; 134, block; 134, 135; 134, 145; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 142; 137, subscript; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:github_logins; 141, identifier:user_data; 142, subscript; 142, 143; 142, 144; 143, identifier:sh_identity; 144, string:'username'; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:logger; 149, identifier:debug; 150, argument_list; 150, 151; 150, 152; 150, 155; 151, string:"GitHub-commit exists. username:%s user:%s"; 152, subscript; 152, 153; 152, 154; 153, identifier:sh_identity; 154, string:'username'; 155, identifier:user_data; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:commit_hash; 159, subscript; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:item; 162, string:'data'; 163, string:'commit'; 164, if_statement; 164, 165; 164, 170; 165, subscript; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:item; 168, string:'data'; 169, string:'Author'; 170, block; 170, 171; 170, 186; 170, 201; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:m; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:AUTHOR_P2P_REGEX; 179, identifier:match; 180, argument_list; 180, 181; 181, subscript; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:item; 184, string:'data'; 185, string:"Author"; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:n; 189, call; 189, 190; 189, 195; 190, attribute; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:AUTHOR_P2P_NEW_REGEX; 194, identifier:match; 195, argument_list; 195, 196; 196, subscript; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:item; 199, string:'data'; 200, string:"Author"; 201, if_statement; 201, 202; 201, 210; 201, 240; 202, boolean_operator:and; 202, 203; 202, 207; 203, parenthesized_expression; 203, 204; 204, boolean_operator:or; 204, 205; 204, 206; 205, identifier:m; 206, identifier:n; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:pair_programming; 210, block; 210, 211; 210, 224; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:authors; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:__get_authors; 218, argument_list; 218, 219; 219, subscript; 219, 220; 219, 223; 220, subscript; 220, 221; 220, 222; 221, identifier:item; 222, string:'data'; 223, string:"Author"; 224, for_statement; 224, 225; 224, 226; 224, 227; 225, identifier:author; 226, identifier:authors; 227, block; 227, 228; 227, 237; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:user; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:self; 234, identifier:get_sh_identity; 235, argument_list; 235, 236; 236, identifier:author; 237, expression_statement; 237, 238; 238, yield; 238, 239; 239, identifier:user; 240, else_clause; 240, 241; 241, block; 241, 242; 241, 255; 241, 258; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:user; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:get_sh_identity; 249, argument_list; 249, 250; 250, subscript; 250, 251; 250, 254; 251, subscript; 251, 252; 251, 253; 252, identifier:item; 253, string:'data'; 254, string:"Author"; 255, expression_statement; 255, 256; 256, yield; 256, 257; 257, identifier:user; 258, if_statement; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:github_token; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 266; 265, identifier:add_sh_github_identity; 266, argument_list; 266, 267; 266, 268; 266, 269; 267, identifier:user; 268, string:'Author'; 269, string:'author'; 270, if_statement; 270, 271; 270, 276; 271, subscript; 271, 272; 271, 275; 272, subscript; 272, 273; 272, 274; 273, identifier:item; 274, string:'data'; 275, string:'Commit'; 276, block; 276, 277; 276, 292; 276, 307; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:m; 280, call; 280, 281; 280, 286; 281, attribute; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:AUTHOR_P2P_REGEX; 285, identifier:match; 286, argument_list; 286, 287; 287, subscript; 287, 288; 287, 291; 288, subscript; 288, 289; 288, 290; 289, identifier:item; 290, string:'data'; 291, string:"Commit"; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:n; 295, call; 295, 296; 295, 301; 296, attribute; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:self; 299, identifier:AUTHOR_P2P_NEW_REGEX; 300, identifier:match; 301, argument_list; 301, 302; 302, subscript; 302, 303; 302, 306; 303, subscript; 303, 304; 303, 305; 304, identifier:item; 305, string:'data'; 306, string:"Author"; 307, if_statement; 307, 308; 307, 316; 307, 346; 308, boolean_operator:and; 308, 309; 308, 313; 309, parenthesized_expression; 309, 310; 310, boolean_operator:or; 310, 311; 310, 312; 311, identifier:m; 312, identifier:n; 313, attribute; 313, 314; 313, 315; 314, identifier:self; 315, identifier:pair_programming; 316, block; 316, 317; 316, 330; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:committers; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:self; 323, identifier:__get_authors; 324, argument_list; 324, 325; 325, subscript; 325, 326; 325, 329; 326, subscript; 326, 327; 326, 328; 327, identifier:item; 328, string:'data'; 329, string:'Commit'; 330, for_statement; 330, 331; 330, 332; 330, 333; 331, identifier:committer; 332, identifier:committers; 333, block; 333, 334; 333, 343; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 337; 336, identifier:user; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:get_sh_identity; 341, argument_list; 341, 342; 342, identifier:committer; 343, expression_statement; 343, 344; 344, yield; 344, 345; 345, identifier:user; 346, else_clause; 346, 347; 347, block; 347, 348; 347, 361; 347, 364; 348, expression_statement; 348, 349; 349, assignment; 349, 350; 349, 351; 350, identifier:user; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:self; 354, identifier:get_sh_identity; 355, argument_list; 355, 356; 356, subscript; 356, 357; 356, 360; 357, subscript; 357, 358; 357, 359; 358, identifier:item; 359, string:'data'; 360, string:'Commit'; 361, expression_statement; 361, 362; 362, yield; 362, 363; 363, identifier:user; 364, if_statement; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:self; 367, identifier:github_token; 368, block; 368, 369; 369, expression_statement; 369, 370; 370, call; 370, 371; 370, 372; 371, identifier:add_sh_github_identity; 372, argument_list; 372, 373; 372, 374; 372, 375; 373, identifier:user; 374, string:'Commit'; 375, string:'committer'; 376, if_statement; 376, 377; 376, 386; 377, boolean_operator:and; 377, 378; 377, 383; 378, comparison_operator:in; 378, 379; 378, 380; 379, string:'Signed-off-by'; 380, subscript; 380, 381; 380, 382; 381, identifier:item; 382, string:'data'; 383, attribute; 383, 384; 383, 385; 384, identifier:self; 385, identifier:pair_programming; 386, block; 386, 387; 386, 395; 387, expression_statement; 387, 388; 388, assignment; 388, 389; 388, 390; 389, identifier:signers; 390, subscript; 390, 391; 390, 394; 391, subscript; 391, 392; 391, 393; 392, identifier:item; 393, string:'data'; 394, string:"Signed-off-by"; 395, for_statement; 395, 396; 395, 397; 395, 398; 396, identifier:signer; 397, identifier:signers; 398, block; 398, 399; 398, 408; 399, expression_statement; 399, 400; 400, assignment; 400, 401; 400, 402; 401, identifier:user; 402, call; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, identifier:self; 405, identifier:get_sh_identity; 406, argument_list; 406, 407; 407, identifier:signer; 408, expression_statement; 408, 409; 409, yield; 409, 410; 410, identifier:user | def get_identities(self, item):
def add_sh_github_identity(user, user_field, rol):
github_repo = None
if GITHUB in item['origin']:
github_repo = item['origin'].replace(GITHUB, '')
github_repo = re.sub('.git$', '', github_repo)
if not github_repo:
return
user_data = item['data'][user_field]
sh_identity = SortingHat.get_github_commit_username(self.sh_db, user, SH_GIT_COMMIT)
if not sh_identity:
gh_username = self.get_github_login(user_data, rol, commit_hash, github_repo)
logger.debug("Adding new identity %s to SH %s: %s", gh_username, SH_GIT_COMMIT, user)
user = self.get_sh_identity(user_data)
user['username'] = gh_username
SortingHat.add_identity(self.sh_db, user, SH_GIT_COMMIT)
else:
if user_data not in self.github_logins:
self.github_logins[user_data] = sh_identity['username']
logger.debug("GitHub-commit exists. username:%s user:%s",
sh_identity['username'], user_data)
commit_hash = item['data']['commit']
if item['data']['Author']:
m = self.AUTHOR_P2P_REGEX.match(item['data']["Author"])
n = self.AUTHOR_P2P_NEW_REGEX.match(item['data']["Author"])
if (m or n) and self.pair_programming:
authors = self.__get_authors(item['data']["Author"])
for author in authors:
user = self.get_sh_identity(author)
yield user
else:
user = self.get_sh_identity(item['data']["Author"])
yield user
if self.github_token:
add_sh_github_identity(user, 'Author', 'author')
if item['data']['Commit']:
m = self.AUTHOR_P2P_REGEX.match(item['data']["Commit"])
n = self.AUTHOR_P2P_NEW_REGEX.match(item['data']["Author"])
if (m or n) and self.pair_programming:
committers = self.__get_authors(item['data']['Commit'])
for committer in committers:
user = self.get_sh_identity(committer)
yield user
else:
user = self.get_sh_identity(item['data']['Commit'])
yield user
if self.github_token:
add_sh_github_identity(user, 'Commit', 'committer')
if 'Signed-off-by' in item['data'] and self.pair_programming:
signers = item['data']["Signed-off-by"]
for signer in signers:
user = self.get_sh_identity(signer)
yield user |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:areas_of_code; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:git_enrich; 5, identifier:in_conn; 6, identifier:out_conn; 7, default_parameter; 7, 8; 7, 9; 8, identifier:block_size; 9, integer:100; 10, block; 10, 11; 10, 29; 10, 37; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:aoc; 14, call; 14, 15; 14, 16; 15, identifier:AreasOfCode; 16, argument_list; 16, 17; 16, 20; 16, 23; 16, 26; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:in_connector; 19, identifier:in_conn; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:out_connector; 22, identifier:out_conn; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:block_size; 25, identifier:block_size; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:git_enrich; 28, identifier:git_enrich; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:ndocs; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:aoc; 35, identifier:analyze; 36, argument_list; 37, return_statement; 37, 38; 38, identifier:ndocs | def areas_of_code(git_enrich, in_conn, out_conn, block_size=100):
aoc = AreasOfCode(in_connector=in_conn, out_connector=out_conn, block_size=block_size,
git_enrich=git_enrich)
ndocs = aoc.analyze()
return ndocs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_make_serializer; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:meas; 5, identifier:schema; 6, identifier:rm_none; 7, identifier:extra_tags; 8, identifier:placeholder; 9, block; 9, 10; 9, 16; 9, 20; 9, 24; 9, 28; 9, 32; 9, 177; 9, 183; 9, 200; 9, 211; 9, 218; 9, 225; 9, 229; 9, 263; 9, 269; 9, 292; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:_validate_schema; 13, argument_list; 13, 14; 13, 15; 14, identifier:schema; 15, identifier:placeholder; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:tags; 19, list:[]; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:fields; 23, list:[]; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:ts; 27, None; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:meas; 31, identifier:meas; 32, for_statement; 32, 33; 32, 36; 32, 41; 33, pattern_list; 33, 34; 33, 35; 34, identifier:k; 35, identifier:t; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:schema; 39, identifier:items; 40, argument_list; 41, block; 41, 42; 42, if_statement; 42, 43; 42, 46; 42, 51; 42, 60; 42, 78; 42, 96; 42, 108; 42, 120; 42, 134; 42, 146; 42, 158; 42, 170; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:t; 45, identifier:MEASUREMENT; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:meas; 50, string:f"{{i.{k}}}"; 51, elif_clause; 51, 52; 51, 55; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:t; 54, identifier:TIMEINT; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:ts; 59, string:f"{{i.{k}}}"; 60, elif_clause; 60, 61; 60, 64; 61, comparison_operator:is; 61, 62; 61, 63; 62, identifier:t; 63, identifier:TIMESTR; 64, block; 64, 65; 65, if_statement; 65, 66; 65, 67; 65, 72; 66, identifier:pd; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:ts; 71, string:f"{{pd.Timestamp(i.{k} or 0).value}}"; 72, else_clause; 72, 73; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:ts; 77, string:f"{{dt_to_int(str_to_dt(i.{k}))}}"; 78, elif_clause; 78, 79; 78, 82; 79, comparison_operator:is; 79, 80; 79, 81; 80, identifier:t; 81, identifier:TIMEDT; 82, block; 82, 83; 83, if_statement; 83, 84; 83, 85; 83, 90; 84, identifier:pd; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:ts; 89, string:f"{{pd.Timestamp(i.{k} or 0).value}}"; 90, else_clause; 90, 91; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:ts; 95, string:f"{{dt_to_int(i.{k})}}"; 96, elif_clause; 96, 97; 96, 100; 97, comparison_operator:is; 97, 98; 97, 99; 98, identifier:t; 99, identifier:TAG; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:tags; 105, identifier:append; 106, argument_list; 106, 107; 107, string:f"{k}={{str(i.{k}).translate(tag_escape)}}"; 108, elif_clause; 108, 109; 108, 112; 109, comparison_operator:is; 109, 110; 109, 111; 110, identifier:t; 111, identifier:TAGENUM; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:tags; 117, identifier:append; 118, argument_list; 118, 119; 119, string:f"{k}={{getattr(i.{k}, 'name', i.{k} or None)}}"; 120, elif_clause; 120, 121; 120, 126; 121, comparison_operator:in; 121, 122; 121, 123; 122, identifier:t; 123, tuple; 123, 124; 123, 125; 124, identifier:FLOAT; 125, identifier:BOOL; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:fields; 131, identifier:append; 132, argument_list; 132, 133; 133, string:f"{k}={{i.{k}}}"; 134, elif_clause; 134, 135; 134, 138; 135, comparison_operator:is; 135, 136; 135, 137; 136, identifier:t; 137, identifier:INT; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:fields; 143, identifier:append; 144, argument_list; 144, 145; 145, string:f"{k}={{i.{k}}}i"; 146, elif_clause; 146, 147; 146, 150; 147, comparison_operator:is; 147, 148; 147, 149; 148, identifier:t; 149, identifier:STR; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:fields; 155, identifier:append; 156, argument_list; 156, 157; 157, string:f"{k}=\\\"{{str(i.{k}).translate(str_escape)}}\\\""; 158, elif_clause; 158, 159; 158, 162; 159, comparison_operator:is; 159, 160; 159, 161; 160, identifier:t; 161, identifier:ENUM; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:fields; 167, identifier:append; 168, argument_list; 168, 169; 169, string:f"{k}=\\\"{{getattr(i.{k}, 'name', i.{k} or None)}}\\\""; 170, else_clause; 170, 171; 171, block; 171, 172; 172, raise_statement; 172, 173; 173, call; 173, 174; 173, 175; 174, identifier:SchemaError; 175, argument_list; 175, 176; 176, string:f"Invalid attribute type {k!r}: {t!r}"; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:extra_tags; 180, boolean_operator:or; 180, 181; 180, 182; 181, identifier:extra_tags; 182, dictionary; 183, for_statement; 183, 184; 183, 187; 183, 192; 184, pattern_list; 184, 185; 184, 186; 185, identifier:k; 186, identifier:v; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:extra_tags; 190, identifier:items; 191, argument_list; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:tags; 197, identifier:append; 198, argument_list; 198, 199; 199, string:f"{k}={v}"; 200, if_statement; 200, 201; 200, 202; 201, identifier:placeholder; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:fields; 207, identifier:insert; 208, argument_list; 208, 209; 208, 210; 209, integer:0; 210, string:f"_=true"; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:sep; 214, conditional_expression:if; 214, 215; 214, 216; 214, 217; 215, string:','; 216, identifier:tags; 217, string:''; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:ts; 221, conditional_expression:if; 221, 222; 221, 223; 221, 224; 222, string:f' {ts}'; 223, identifier:ts; 224, string:''; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:fmt; 228, string:f"{meas}{sep}{','.join(tags)} {','.join(fields)}{ts}"; 229, if_statement; 229, 230; 229, 231; 229, 249; 230, identifier:rm_none; 231, block; 231, 232; 231, 236; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:pat; 235, string:r',\w+="?None"?i?'; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:f; 239, call; 239, 240; 239, 241; 240, identifier:eval; 241, argument_list; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, string:'lambda i: re.sub(r\'{}\', "", f"{}").encode()'; 245, identifier:format; 246, argument_list; 246, 247; 246, 248; 247, identifier:pat; 248, identifier:fmt; 249, else_clause; 249, 250; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:f; 254, call; 254, 255; 254, 256; 255, identifier:eval; 256, argument_list; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, string:'lambda i: f"{}".encode()'; 260, identifier:format; 261, argument_list; 261, 262; 262, identifier:fmt; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:f; 267, identifier:__doc__; 268, string:"Returns InfluxDB line protocol representation of user-defined class"; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:f; 273, identifier:_args; 274, call; 274, 275; 274, 276; 275, identifier:dict; 276, argument_list; 276, 277; 276, 280; 276, 283; 276, 286; 276, 289; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:meas; 279, identifier:meas; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:schema; 282, identifier:schema; 283, keyword_argument; 283, 284; 283, 285; 284, identifier:rm_none; 285, identifier:rm_none; 286, keyword_argument; 286, 287; 286, 288; 287, identifier:extra_tags; 288, identifier:extra_tags; 289, keyword_argument; 289, 290; 289, 291; 290, identifier:placeholder; 291, identifier:placeholder; 292, return_statement; 292, 293; 293, identifier:f | def _make_serializer(meas, schema, rm_none, extra_tags, placeholder):
_validate_schema(schema, placeholder)
tags = []
fields = []
ts = None
meas = meas
for k, t in schema.items():
if t is MEASUREMENT:
meas = f"{{i.{k}}}"
elif t is TIMEINT:
ts = f"{{i.{k}}}"
elif t is TIMESTR:
if pd:
ts = f"{{pd.Timestamp(i.{k} or 0).value}}"
else:
ts = f"{{dt_to_int(str_to_dt(i.{k}))}}"
elif t is TIMEDT:
if pd:
ts = f"{{pd.Timestamp(i.{k} or 0).value}}"
else:
ts = f"{{dt_to_int(i.{k})}}"
elif t is TAG:
tags.append(f"{k}={{str(i.{k}).translate(tag_escape)}}")
elif t is TAGENUM:
tags.append(f"{k}={{getattr(i.{k}, 'name', i.{k} or None)}}")
elif t in (FLOAT, BOOL):
fields.append(f"{k}={{i.{k}}}")
elif t is INT:
fields.append(f"{k}={{i.{k}}}i")
elif t is STR:
fields.append(f"{k}=\\\"{{str(i.{k}).translate(str_escape)}}\\\"")
elif t is ENUM:
fields.append(f"{k}=\\\"{{getattr(i.{k}, 'name', i.{k} or None)}}\\\"")
else:
raise SchemaError(f"Invalid attribute type {k!r}: {t!r}")
extra_tags = extra_tags or {}
for k, v in extra_tags.items():
tags.append(f"{k}={v}")
if placeholder:
fields.insert(0, f"_=true")
sep = ',' if tags else ''
ts = f' {ts}' if ts else ''
fmt = f"{meas}{sep}{','.join(tags)} {','.join(fields)}{ts}"
if rm_none:
pat = r',\w+="?None"?i?'
f = eval('lambda i: re.sub(r\'{}\', "", f"{}").encode()'.format(pat, fmt))
else:
f = eval('lambda i: f"{}".encode()'.format(fmt))
f.__doc__ = "Returns InfluxDB line protocol representation of user-defined class"
f._args = dict(meas=meas, schema=schema, rm_none=rm_none,
extra_tags=extra_tags, placeholder=placeholder)
return f |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 1, 23; 2, function_name:iterpoints; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:resp; 6, type; 6, 7; 7, identifier:dict; 8, typed_default_parameter; 8, 9; 8, 10; 8, 16; 9, identifier:parser; 10, type; 10, 11; 11, generic_type; 11, 12; 11, 13; 12, identifier:Optional; 13, type_parameter; 13, 14; 14, type; 14, 15; 15, identifier:Callable; 16, None; 17, type; 17, 18; 18, generic_type; 18, 19; 18, 20; 19, identifier:Iterator; 20, type_parameter; 20, 21; 21, type; 21, 22; 22, identifier:Any; 23, block; 23, 24; 23, 120; 24, for_statement; 24, 25; 24, 26; 24, 29; 25, identifier:statement; 26, subscript; 26, 27; 26, 28; 27, identifier:resp; 28, string:'results'; 29, block; 29, 30; 29, 36; 30, if_statement; 30, 31; 30, 34; 31, comparison_operator:not; 31, 32; 31, 33; 32, string:'series'; 33, identifier:statement; 34, block; 34, 35; 35, continue_statement; 36, for_statement; 36, 37; 36, 38; 36, 41; 37, identifier:series; 38, subscript; 38, 39; 38, 40; 39, identifier:statement; 40, string:'series'; 41, block; 41, 42; 42, if_statement; 42, 43; 42, 46; 42, 55; 42, 106; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:parser; 45, None; 46, block; 46, 47; 47, return_statement; 47, 48; 48, generator_expression; 48, 49; 48, 50; 49, identifier:x; 50, for_in_clause; 50, 51; 50, 52; 51, identifier:x; 52, subscript; 52, 53; 52, 54; 53, identifier:series; 54, string:'values'; 55, elif_clause; 55, 56; 55, 66; 56, comparison_operator:in; 56, 57; 56, 58; 57, string:'meta'; 58, attribute; 58, 59; 58, 65; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:inspect; 62, identifier:signature; 63, argument_list; 63, 64; 64, identifier:parser; 65, identifier:parameters; 66, block; 66, 67; 66, 83; 66, 91; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:meta; 70, dictionary_comprehension; 70, 71; 70, 76; 70, 79; 71, pair; 71, 72; 71, 73; 72, identifier:k; 73, subscript; 73, 74; 73, 75; 74, identifier:series; 75, identifier:k; 76, for_in_clause; 76, 77; 76, 78; 77, identifier:k; 78, identifier:series; 79, if_clause; 79, 80; 80, comparison_operator:!=; 80, 81; 80, 82; 81, identifier:k; 82, string:'values'; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:meta; 87, string:'statement_id'; 88, subscript; 88, 89; 88, 90; 89, identifier:statement; 90, string:'statement_id'; 91, return_statement; 91, 92; 92, generator_expression; 92, 93; 92, 101; 93, call; 93, 94; 93, 95; 94, identifier:parser; 95, argument_list; 95, 96; 95, 98; 96, list_splat; 96, 97; 97, identifier:x; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:meta; 100, identifier:meta; 101, for_in_clause; 101, 102; 101, 103; 102, identifier:x; 103, subscript; 103, 104; 103, 105; 104, identifier:series; 105, string:'values'; 106, else_clause; 106, 107; 107, block; 107, 108; 108, return_statement; 108, 109; 109, generator_expression; 109, 110; 109, 115; 110, call; 110, 111; 110, 112; 111, identifier:parser; 112, argument_list; 112, 113; 113, list_splat; 113, 114; 114, identifier:x; 115, for_in_clause; 115, 116; 115, 117; 116, identifier:x; 117, subscript; 117, 118; 117, 119; 118, identifier:series; 119, string:'values'; 120, return_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:iter; 123, argument_list; 123, 124; 124, list:[] | def iterpoints(resp: dict, parser: Optional[Callable] = None) -> Iterator[Any]:
for statement in resp['results']:
if 'series' not in statement:
continue
for series in statement['series']:
if parser is None:
return (x for x in series['values'])
elif 'meta' in inspect.signature(parser).parameters:
meta = {k: series[k] for k in series if k != 'values'}
meta['statement_id'] = statement['statement_id']
return (parser(*x, meta=meta) for x in series['values'])
else:
return (parser(*x) for x in series['values'])
return iter([]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 1, 13; 2, function_name:serialize; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:df; 5, identifier:measurement; 6, default_parameter; 6, 7; 6, 8; 7, identifier:tag_columns; 8, None; 9, dictionary_splat_pattern; 9, 10; 10, identifier:extra_tags; 11, type; 11, 12; 12, identifier:bytes; 13, block; 13, 14; 13, 24; 13, 41; 13, 50; 13, 65; 13, 69; 13, 73; 13, 90; 13, 177; 13, 197; 13, 214; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:is; 15, 16; 15, 17; 16, identifier:measurement; 17, None; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:ValueError; 22, argument_list; 22, 23; 23, string:"Missing 'measurement'"; 24, if_statement; 24, 25; 24, 35; 25, not_operator; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:isinstance; 28, argument_list; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:df; 31, identifier:index; 32, attribute; 32, 33; 32, 34; 33, identifier:pd; 34, identifier:DatetimeIndex; 35, block; 35, 36; 36, raise_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:ValueError; 39, argument_list; 39, 40; 40, string:'DataFrame index is not DatetimeIndex'; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:tag_columns; 44, call; 44, 45; 44, 46; 45, identifier:set; 46, argument_list; 46, 47; 47, boolean_operator:or; 47, 48; 47, 49; 48, identifier:tag_columns; 49, list:[]; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:isnull; 53, call; 53, 54; 53, 61; 54, attribute; 54, 55; 54, 60; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:df; 58, identifier:isnull; 59, argument_list; 60, identifier:any; 61, argument_list; 61, 62; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:axis; 64, integer:1; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:tags; 68, list:[]; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:fields; 72, list:[]; 73, for_statement; 73, 74; 73, 77; 73, 82; 74, pattern_list; 74, 75; 74, 76; 75, identifier:k; 76, identifier:v; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:extra_tags; 80, identifier:items; 81, argument_list; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:tags; 87, identifier:append; 88, argument_list; 88, 89; 89, string:f"{k}={escape(v, key_escape)}"; 90, for_statement; 90, 91; 90, 96; 90, 106; 91, pattern_list; 91, 92; 91, 93; 92, identifier:i; 93, tuple_pattern; 93, 94; 93, 95; 94, identifier:k; 95, identifier:v; 96, call; 96, 97; 96, 98; 97, identifier:enumerate; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:df; 103, identifier:dtypes; 104, identifier:items; 105, argument_list; 106, block; 106, 107; 106, 116; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:k; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:k; 113, identifier:translate; 114, argument_list; 114, 115; 115, identifier:key_escape; 116, if_statement; 116, 117; 116, 120; 116, 128; 116, 146; 116, 168; 117, comparison_operator:in; 117, 118; 117, 119; 118, identifier:k; 119, identifier:tag_columns; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:tags; 125, identifier:append; 126, argument_list; 126, 127; 127, string:f"{k}={{p[{i+1}]}}"; 128, elif_clause; 128, 129; 128, 138; 129, call; 129, 130; 129, 131; 130, identifier:issubclass; 131, argument_list; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:v; 134, identifier:type; 135, attribute; 135, 136; 135, 137; 136, identifier:np; 137, identifier:integer; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:fields; 143, identifier:append; 144, argument_list; 144, 145; 145, string:f"{k}={{p[{i+1}]}}i"; 146, elif_clause; 146, 147; 146, 160; 147, call; 147, 148; 147, 149; 148, identifier:issubclass; 149, argument_list; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:v; 152, identifier:type; 153, tuple; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:np; 156, identifier:float; 157, attribute; 157, 158; 157, 159; 158, identifier:np; 159, identifier:bool_; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:fields; 165, identifier:append; 166, argument_list; 166, 167; 167, string:f"{k}={{p[{i+1}]}}"; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:fields; 174, identifier:append; 175, argument_list; 175, 176; 176, string:f"{k}=\"{{p[{i+1}]}}\""; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:fmt; 180, tuple; 180, 181; 180, 182; 180, 183; 180, 189; 180, 190; 180, 196; 181, string:f'{measurement}'; 182, string:f'{"," if tags else ""}'; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, string:','; 186, identifier:join; 187, argument_list; 187, 188; 188, identifier:tags; 189, string:' '; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, string:','; 193, identifier:join; 194, argument_list; 194, 195; 195, identifier:fields; 196, string:' {p[0].value}'; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:f; 200, call; 200, 201; 200, 202; 201, identifier:eval; 202, argument_list; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, string:"lambda p: f'{}'"; 206, identifier:format; 207, argument_list; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, string:''; 211, identifier:join; 212, argument_list; 212, 213; 213, identifier:fmt; 214, if_statement; 214, 215; 214, 220; 214, 290; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:isnull; 218, identifier:any; 219, argument_list; 220, block; 220, 221; 220, 235; 220, 242; 220, 274; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:lp; 224, call; 224, 225; 224, 226; 225, identifier:map; 226, argument_list; 226, 227; 226, 228; 227, identifier:f; 228, call; 228, 229; 228, 230; 229, identifier:_itertuples; 230, argument_list; 230, 231; 231, subscript; 231, 232; 231, 233; 232, identifier:df; 233, unary_operator:~; 233, 234; 234, identifier:isnull; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:rep; 238, call; 238, 239; 238, 240; 239, identifier:_replace; 240, argument_list; 240, 241; 241, identifier:df; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:lp_nan; 245, generator_expression; 245, 246; 245, 266; 246, call; 246, 247; 246, 248; 247, identifier:reduce; 248, argument_list; 248, 249; 248, 261; 248, 262; 249, lambda; 249, 250; 249, 253; 250, lambda_parameters; 250, 251; 250, 252; 251, identifier:a; 252, identifier:b; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:re; 256, identifier:sub; 257, argument_list; 257, 258; 257, 260; 258, list_splat; 258, 259; 259, identifier:b; 260, identifier:a; 261, identifier:rep; 262, call; 262, 263; 262, 264; 263, identifier:f; 264, argument_list; 264, 265; 265, identifier:p; 266, for_in_clause; 266, 267; 266, 268; 267, identifier:p; 268, call; 268, 269; 268, 270; 269, identifier:_itertuples; 270, argument_list; 270, 271; 271, subscript; 271, 272; 271, 273; 272, identifier:df; 273, identifier:isnull; 274, return_statement; 274, 275; 275, call; 275, 276; 275, 288; 276, attribute; 276, 277; 276, 287; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, string:'\n'; 280, identifier:join; 281, argument_list; 281, 282; 282, call; 282, 283; 282, 284; 283, identifier:chain; 284, argument_list; 284, 285; 284, 286; 285, identifier:lp; 286, identifier:lp_nan; 287, identifier:encode; 288, argument_list; 288, 289; 289, string:'utf-8'; 290, else_clause; 290, 291; 291, block; 291, 292; 292, return_statement; 292, 293; 293, call; 293, 294; 293, 309; 294, attribute; 294, 295; 294, 308; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, string:'\n'; 298, identifier:join; 299, argument_list; 299, 300; 300, call; 300, 301; 300, 302; 301, identifier:map; 302, argument_list; 302, 303; 302, 304; 303, identifier:f; 304, call; 304, 305; 304, 306; 305, identifier:_itertuples; 306, argument_list; 306, 307; 307, identifier:df; 308, identifier:encode; 309, argument_list; 309, 310; 310, string:'utf-8' | def serialize(df, measurement, tag_columns=None, **extra_tags) -> bytes:
if measurement is None:
raise ValueError("Missing 'measurement'")
if not isinstance(df.index, pd.DatetimeIndex):
raise ValueError('DataFrame index is not DatetimeIndex')
tag_columns = set(tag_columns or [])
isnull = df.isnull().any(axis=1)
tags = []
fields = []
for k, v in extra_tags.items():
tags.append(f"{k}={escape(v, key_escape)}")
for i, (k, v) in enumerate(df.dtypes.items()):
k = k.translate(key_escape)
if k in tag_columns:
tags.append(f"{k}={{p[{i+1}]}}")
elif issubclass(v.type, np.integer):
fields.append(f"{k}={{p[{i+1}]}}i")
elif issubclass(v.type, (np.float, np.bool_)):
fields.append(f"{k}={{p[{i+1}]}}")
else:
fields.append(f"{k}=\"{{p[{i+1}]}}\"")
fmt = (f'{measurement}', f'{"," if tags else ""}', ','.join(tags),
' ', ','.join(fields), ' {p[0].value}')
f = eval("lambda p: f'{}'".format(''.join(fmt)))
if isnull.any():
lp = map(f, _itertuples(df[~isnull]))
rep = _replace(df)
lp_nan = (reduce(lambda a, b: re.sub(*b, a), rep, f(p))
for p in _itertuples(df[isnull]))
return '\n'.join(chain(lp, lp_nan)).encode('utf-8')
else:
return '\n'.join(map(f, _itertuples(df))).encode('utf-8') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:get_my_feed; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:limit; 7, integer:150; 8, default_parameter; 8, 9; 8, 10; 9, identifier:offset; 10, integer:20; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, string:"updated"; 14, default_parameter; 14, 15; 14, 16; 15, identifier:nid; 16, None; 17, block; 17, 18; 17, 46; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:r; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:request; 25, argument_list; 25, 26; 25, 29; 25, 32; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:method; 28, string:"network.get_my_feed"; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:nid; 31, identifier:nid; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:data; 34, call; 34, 35; 34, 36; 35, identifier:dict; 36, argument_list; 36, 37; 36, 40; 36, 43; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:limit; 39, identifier:limit; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:offset; 42, identifier:offset; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:sort; 45, identifier:sort; 46, return_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_handle_error; 51, argument_list; 51, 52; 51, 53; 52, identifier:r; 53, string:"Could not retrieve your feed." | def get_my_feed(self, limit=150, offset=20, sort="updated", nid=None):
r = self.request(
method="network.get_my_feed",
nid=nid,
data=dict(
limit=limit,
offset=offset,
sort=sort
)
)
return self._handle_error(r, "Could not retrieve your feed.") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:filter_feed; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:updated; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:following; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:folder; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:filter_folder; 16, string:""; 17, default_parameter; 17, 18; 17, 19; 18, identifier:sort; 19, string:"updated"; 20, default_parameter; 20, 21; 20, 22; 21, identifier:nid; 22, None; 23, block; 23, 24; 23, 34; 23, 39; 23, 77; 23, 101; 24, assert_statement; 24, 25; 25, comparison_operator:==; 25, 26; 25, 33; 26, call; 26, 27; 26, 28; 27, identifier:sum; 28, argument_list; 28, 29; 29, list:[updated, following, folder]; 29, 30; 29, 31; 29, 32; 30, identifier:updated; 31, identifier:following; 32, identifier:folder; 33, integer:1; 34, if_statement; 34, 35; 34, 36; 35, identifier:folder; 36, block; 36, 37; 37, assert_statement; 37, 38; 38, identifier:filter_folder; 39, if_statement; 39, 40; 39, 41; 39, 51; 39, 63; 40, identifier:updated; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:filter_type; 45, call; 45, 46; 45, 47; 46, identifier:dict; 47, argument_list; 47, 48; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:updated; 50, integer:1; 51, elif_clause; 51, 52; 51, 53; 52, identifier:following; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:filter_type; 57, call; 57, 58; 57, 59; 58, identifier:dict; 59, argument_list; 59, 60; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:following; 62, integer:1; 63, else_clause; 63, 64; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:filter_type; 68, call; 68, 69; 68, 70; 69, identifier:dict; 70, argument_list; 70, 71; 70, 74; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:folder; 73, integer:1; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:filter_folder; 76, identifier:filter_folder; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:r; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:request; 84, argument_list; 84, 85; 84, 88; 84, 91; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:nid; 87, identifier:nid; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:method; 90, string:"network.filter_feed"; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:data; 93, call; 93, 94; 93, 95; 94, identifier:dict; 95, argument_list; 95, 96; 95, 99; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:sort; 98, identifier:sort; 99, dictionary_splat; 99, 100; 100, identifier:filter_type; 101, return_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_handle_error; 106, argument_list; 106, 107; 106, 108; 107, identifier:r; 108, string:"Could not retrieve filtered feed." | def filter_feed(self, updated=False, following=False, folder=False,
filter_folder="", sort="updated", nid=None):
assert sum([updated, following, folder]) == 1
if folder:
assert filter_folder
if updated:
filter_type = dict(updated=1)
elif following:
filter_type = dict(following=1)
else:
filter_type = dict(folder=1, filter_folder=filter_folder)
r = self.request(
nid=nid,
method="network.filter_feed",
data=dict(
sort=sort,
**filter_type
)
)
return self._handle_error(r, "Could not retrieve filtered feed.") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_dataset; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:dataset; 6, block; 6, 7; 6, 11; 6, 19; 6, 216; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:success; 10, True; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:dataset_path; 14, binary_operator:+; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:base_dataset_path; 18, identifier:dataset; 19, if_statement; 19, 20; 19, 25; 20, not_operator; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:isdir; 23, argument_list; 23, 24; 24, identifier:dataset_path; 25, block; 25, 26; 25, 30; 25, 184; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:was_error; 29, False; 30, for_statement; 30, 31; 30, 32; 30, 36; 31, identifier:iteration; 32, call; 32, 33; 32, 34; 33, identifier:range; 34, argument_list; 34, 35; 35, integer:5; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 45; 38, boolean_operator:or; 38, 39; 38, 42; 39, comparison_operator:==; 39, 40; 39, 41; 40, identifier:iteration; 41, integer:0; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:was_error; 44, True; 45, block; 45, 46; 45, 52; 45, 117; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:zip_path; 49, binary_operator:+; 49, 50; 49, 51; 50, identifier:dataset_path; 51, string:".zip"; 52, if_statement; 52, 53; 52, 58; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:isfile; 56, argument_list; 56, 57; 57, identifier:zip_path; 58, block; 58, 59; 59, try_statement; 59, 60; 59, 98; 60, block; 60, 61; 61, with_statement; 61, 62; 61, 82; 62, with_clause; 62, 63; 63, with_item; 63, 64; 64, as_pattern; 64, 65; 64, 80; 65, call; 65, 66; 65, 67; 66, identifier:DLProgress; 67, argument_list; 67, 68; 67, 71; 67, 74; 67, 77; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:unit; 70, string:'B'; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:unit_scale; 73, True; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:miniters; 76, integer:1; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:desc; 79, identifier:dataset; 80, as_pattern_target; 80, 81; 81, identifier:pbar; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:urlretrieve; 86, argument_list; 86, 87; 86, 94; 86, 95; 87, subscript; 87, 88; 87, 93; 88, subscript; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:datasets; 92, identifier:dataset; 93, string:"url"; 94, identifier:zip_path; 95, attribute; 95, 96; 95, 97; 96, identifier:pbar; 97, identifier:hook; 98, except_clause; 98, 99; 98, 103; 99, as_pattern; 99, 100; 99, 101; 100, identifier:Exception; 101, as_pattern_target; 101, 102; 102, identifier:ex; 103, block; 103, 104; 103, 113; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:print; 107, argument_list; 107, 108; 108, binary_operator:%; 108, 109; 108, 110; 109, string:"Error downloading %s: %s"; 110, tuple; 110, 111; 110, 112; 111, identifier:dataset; 112, identifier:ex; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:was_error; 116, True; 117, if_statement; 117, 118; 117, 123; 118, not_operator; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:isdir; 121, argument_list; 121, 122; 122, identifier:dataset_path; 123, block; 123, 124; 124, try_statement; 124, 125; 124, 154; 125, block; 125, 126; 126, with_statement; 126, 127; 126, 138; 127, with_clause; 127, 128; 128, with_item; 128, 129; 129, as_pattern; 129, 130; 129, 136; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:zipfile; 133, identifier:ZipFile; 134, argument_list; 134, 135; 135, identifier:zip_path; 136, as_pattern_target; 136, 137; 137, identifier:zip_archive; 138, block; 138, 139; 138, 148; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:zip_archive; 143, identifier:extractall; 144, argument_list; 144, 145; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:path; 147, identifier:dataset_path; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:zip_archive; 152, identifier:close; 153, argument_list; 154, except_clause; 154, 155; 154, 159; 155, as_pattern; 155, 156; 155, 157; 156, identifier:Exception; 157, as_pattern_target; 157, 158; 158, identifier:ex; 159, block; 159, 160; 159, 169; 159, 180; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:print; 163, argument_list; 163, 164; 164, binary_operator:%; 164, 165; 164, 166; 165, string:"Error unzipping %s: %s"; 166, tuple; 166, 167; 166, 168; 167, identifier:zip_path; 168, identifier:ex; 169, try_statement; 169, 170; 169, 176; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 174; 173, identifier:remove; 174, argument_list; 174, 175; 175, identifier:zip_path; 176, except_clause; 176, 177; 176, 178; 177, identifier:FileNotFoundError; 178, block; 178, 179; 179, pass_statement; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:was_error; 183, True; 184, if_statement; 184, 185; 184, 186; 185, identifier:was_error; 186, block; 186, 187; 186, 192; 186, 205; 186, 212; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 190; 189, identifier:print; 190, argument_list; 190, 191; 191, string:"\nThis recognizer is trained by the CASIA handwriting database."; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:print; 195, argument_list; 195, 196; 196, binary_operator:%; 196, 197; 196, 198; 197, string:"If the download doesn't work, you can get the files at %s"; 198, subscript; 198, 199; 198, 204; 199, subscript; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:datasets; 203, identifier:dataset; 204, string:"url"; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 208; 207, identifier:print; 208, argument_list; 208, 209; 209, concatenated_string; 209, 210; 209, 211; 210, string:"If you have download problems, "; 211, string:"wget may be effective at downloading because of download resuming."; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:success; 215, False; 216, return_statement; 216, 217; 217, identifier:success | def get_dataset(self, dataset):
success = True
dataset_path = self.base_dataset_path + dataset
if not isdir(dataset_path):
was_error = False
for iteration in range(5):
if iteration == 0 or was_error is True:
zip_path = dataset_path + ".zip"
if not isfile(zip_path):
try:
with DLProgress(unit='B', unit_scale=True, miniters=1, desc=dataset) as pbar:
urlretrieve(self.datasets[dataset]["url"], zip_path, pbar.hook)
except Exception as ex:
print("Error downloading %s: %s" % (dataset, ex))
was_error = True
if not isdir(dataset_path):
try:
with zipfile.ZipFile(zip_path) as zip_archive:
zip_archive.extractall(path=dataset_path)
zip_archive.close()
except Exception as ex:
print("Error unzipping %s: %s" % (zip_path, ex))
try:
remove(zip_path)
except FileNotFoundError:
pass
was_error = True
if was_error:
print("\nThis recognizer is trained by the CASIA handwriting database.")
print("If the download doesn't work, you can get the files at %s" % self.datasets[dataset]["url"])
print("If you have download problems, "
"wget may be effective at downloading because of download resuming.")
success = False
return success |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:install; 3, parameters; 3, 4; 3, 7; 3, 27; 3, 30; 4, default_parameter; 4, 5; 4, 6; 5, identifier:verbose; 6, True; 7, default_parameter; 7, 8; 7, 9; 8, identifier:verbose_destination; 9, conditional_expression:if; 9, 10; 9, 17; 9, 24; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:sys; 14, identifier:__stderr__; 15, identifier:fileno; 16, argument_list; 17, call; 17, 18; 17, 19; 18, identifier:hasattr; 19, argument_list; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:sys; 22, identifier:__stderr__; 23, string:'fileno'; 24, attribute; 24, 25; 24, 26; 25, identifier:sys; 26, identifier:__stderr__; 27, default_parameter; 27, 28; 27, 29; 28, identifier:strict; 29, True; 30, dictionary_splat_pattern; 30, 31; 31, identifier:kwargs; 32, block; 32, 33; 32, 35; 32, 75; 32, 83; 32, 91; 33, global_statement; 33, 34; 34, identifier:_MANHOLE; 35, with_statement; 35, 36; 35, 39; 36, with_clause; 36, 37; 37, with_item; 37, 38; 38, identifier:_LOCK; 39, block; 39, 40; 40, if_statement; 40, 41; 40, 44; 40, 51; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:_MANHOLE; 43, None; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:_MANHOLE; 48, call; 48, 49; 48, 50; 49, identifier:Manhole; 50, argument_list; 51, else_clause; 51, 52; 52, block; 52, 53; 53, if_statement; 53, 54; 53, 55; 53, 61; 54, identifier:strict; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:AlreadyInstalled; 59, argument_list; 59, 60; 60, string:"Manhole already installed!"; 61, else_clause; 61, 62; 62, block; 62, 63; 62, 69; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:_LOG; 67, identifier:release; 68, argument_list; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:_MANHOLE; 73, identifier:release; 74, argument_list; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:_LOG; 79, identifier:configure; 80, argument_list; 80, 81; 80, 82; 81, identifier:verbose; 82, identifier:verbose_destination; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:_MANHOLE; 87, identifier:configure; 88, argument_list; 88, 89; 89, dictionary_splat; 89, 90; 90, identifier:kwargs; 91, return_statement; 91, 92; 92, identifier:_MANHOLE | def install(verbose=True,
verbose_destination=sys.__stderr__.fileno() if hasattr(sys.__stderr__, 'fileno') else sys.__stderr__,
strict=True,
**kwargs):
global _MANHOLE
with _LOCK:
if _MANHOLE is None:
_MANHOLE = Manhole()
else:
if strict:
raise AlreadyInstalled("Manhole already installed!")
else:
_LOG.release()
_MANHOLE.release()
_LOG.configure(verbose, verbose_destination)
_MANHOLE.configure(**kwargs)
return _MANHOLE |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 37; 2, function_name:update; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 4, identifier:self; 5, identifier:alert_condition_nrql_id; 6, identifier:policy_id; 7, default_parameter; 7, 8; 7, 9; 8, identifier:name; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:threshold_type; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:query; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:since_value; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:terms; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:expected_groups; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:value_function; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:runbook_url; 30, None; 31, default_parameter; 31, 32; 31, 33; 32, identifier:ignore_overlap; 33, None; 34, default_parameter; 34, 35; 34, 36; 35, identifier:enabled; 36, True; 37, block; 37, 38; 37, 47; 37, 51; 37, 72; 37, 90; 37, 144; 37, 164; 37, 192; 37, 220; 37, 248; 37, 276; 37, 360; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:conditions_nrql_dict; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:list; 45, argument_list; 45, 46; 46, identifier:policy_id; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:target_condition_nrql; 50, None; 51, for_statement; 51, 52; 51, 53; 51, 56; 52, identifier:condition; 53, subscript; 53, 54; 53, 55; 54, identifier:conditions_nrql_dict; 55, string:'nrql_conditions'; 56, block; 56, 57; 57, if_statement; 57, 58; 57, 66; 58, comparison_operator:==; 58, 59; 58, 65; 59, call; 59, 60; 59, 61; 60, identifier:int; 61, argument_list; 61, 62; 62, subscript; 62, 63; 62, 64; 63, identifier:condition; 64, string:'id'; 65, identifier:alert_condition_nrql_id; 66, block; 66, 67; 66, 71; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:target_condition_nrql; 70, identifier:condition; 71, break_statement; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:is; 73, 74; 73, 75; 74, identifier:target_condition_nrql; 75, None; 76, block; 76, 77; 77, raise_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:NoEntityException; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, concatenated_string; 83, 84; 83, 85; 84, string:'Target alert condition nrql is not included in that policy.'; 85, string:'policy_id: {}, alert_condition_nrql_id {}'; 86, identifier:format; 87, argument_list; 87, 88; 87, 89; 88, identifier:policy_id; 89, identifier:alert_condition_nrql_id; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:data; 93, dictionary; 93, 94; 94, pair; 94, 95; 94, 96; 95, string:'nrql_condition'; 96, dictionary; 96, 97; 96, 104; 96, 109; 96, 116; 96, 123; 97, pair; 97, 98; 97, 99; 98, string:'type'; 99, boolean_operator:or; 99, 100; 99, 101; 100, identifier:threshold_type; 101, subscript; 101, 102; 101, 103; 102, identifier:target_condition_nrql; 103, string:'type'; 104, pair; 104, 105; 104, 106; 105, string:'enabled'; 106, subscript; 106, 107; 106, 108; 107, identifier:target_condition_nrql; 108, string:'enabled'; 109, pair; 109, 110; 109, 111; 110, string:'name'; 111, boolean_operator:or; 111, 112; 111, 113; 112, identifier:name; 113, subscript; 113, 114; 113, 115; 114, identifier:target_condition_nrql; 115, string:'name'; 116, pair; 116, 117; 116, 118; 117, string:'terms'; 118, boolean_operator:or; 118, 119; 118, 120; 119, identifier:terms; 120, subscript; 120, 121; 120, 122; 121, identifier:target_condition_nrql; 122, string:'terms'; 123, pair; 123, 124; 123, 125; 124, string:'nrql'; 125, dictionary; 125, 126; 125, 135; 126, pair; 126, 127; 126, 128; 127, string:'query'; 128, boolean_operator:or; 128, 129; 128, 130; 129, identifier:query; 130, subscript; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:target_condition_nrql; 133, string:'nrql'; 134, string:'query'; 135, pair; 135, 136; 135, 137; 136, string:'since_value'; 137, boolean_operator:or; 137, 138; 137, 139; 138, identifier:since_value; 139, subscript; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:target_condition_nrql; 142, string:'nrql'; 143, string:'since_value'; 144, if_statement; 144, 145; 144, 148; 145, comparison_operator:is; 145, 146; 145, 147; 146, identifier:enabled; 147, None; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 156; 151, subscript; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:data; 154, string:'nrql_condition'; 155, string:'enabled'; 156, call; 156, 157; 156, 163; 157, attribute; 157, 158; 157, 162; 158, call; 158, 159; 158, 160; 159, identifier:str; 160, argument_list; 160, 161; 161, identifier:enabled; 162, identifier:lower; 163, argument_list; 164, if_statement; 164, 165; 164, 168; 164, 177; 165, comparison_operator:is; 165, 166; 165, 167; 166, identifier:runbook_url; 167, None; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 176; 171, subscript; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:data; 174, string:'nrql_condition'; 175, string:'runbook_url'; 176, identifier:runbook_url; 177, elif_clause; 177, 178; 177, 181; 178, comparison_operator:in; 178, 179; 178, 180; 179, string:'runbook_url'; 180, identifier:target_condition_nrql; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 189; 184, subscript; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:data; 187, string:'nrql_condition'; 188, string:'runbook_url'; 189, subscript; 189, 190; 189, 191; 190, identifier:target_condition_nrql; 191, string:'runbook_url'; 192, if_statement; 192, 193; 192, 196; 192, 205; 193, comparison_operator:is; 193, 194; 193, 195; 194, identifier:expected_groups; 195, None; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 204; 199, subscript; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:data; 202, string:'nrql_condition'; 203, string:'expected_groups'; 204, identifier:expected_groups; 205, elif_clause; 205, 206; 205, 209; 206, comparison_operator:in; 206, 207; 206, 208; 207, string:'expected_groups'; 208, identifier:target_condition_nrql; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 217; 212, subscript; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:data; 215, string:'nrql_condition'; 216, string:'expected_groups'; 217, subscript; 217, 218; 217, 219; 218, identifier:target_condition_nrql; 219, string:'expected_groups'; 220, if_statement; 220, 221; 220, 224; 220, 233; 221, comparison_operator:is; 221, 222; 221, 223; 222, identifier:ignore_overlap; 223, None; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 232; 227, subscript; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:data; 230, string:'nrql_condition'; 231, string:'ignore_overlap'; 232, identifier:ignore_overlap; 233, elif_clause; 233, 234; 233, 237; 234, comparison_operator:in; 234, 235; 234, 236; 235, string:'ignore_overlap'; 236, identifier:target_condition_nrql; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 245; 240, subscript; 240, 241; 240, 244; 241, subscript; 241, 242; 241, 243; 242, identifier:data; 243, string:'nrql_condition'; 244, string:'ignore_overlap'; 245, subscript; 245, 246; 245, 247; 246, identifier:target_condition_nrql; 247, string:'ignore_overlap'; 248, if_statement; 248, 249; 248, 252; 248, 261; 249, comparison_operator:is; 249, 250; 249, 251; 250, identifier:value_function; 251, None; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 260; 255, subscript; 255, 256; 255, 259; 256, subscript; 256, 257; 256, 258; 257, identifier:data; 258, string:'nrql_condition'; 259, string:'value_function'; 260, identifier:value_function; 261, elif_clause; 261, 262; 261, 265; 262, comparison_operator:in; 262, 263; 262, 264; 263, string:'value_function'; 264, identifier:target_condition_nrql; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 273; 268, subscript; 268, 269; 268, 272; 269, subscript; 269, 270; 269, 271; 270, identifier:data; 271, string:'nrql_condition'; 272, string:'value_function'; 273, subscript; 273, 274; 273, 275; 274, identifier:target_condition_nrql; 275, string:'value_function'; 276, if_statement; 276, 277; 276, 284; 276, 317; 277, comparison_operator:==; 277, 278; 277, 283; 278, subscript; 278, 279; 278, 282; 279, subscript; 279, 280; 279, 281; 280, identifier:data; 281, string:'nrql_condition'; 282, string:'type'; 283, string:'static'; 284, block; 284, 285; 284, 297; 284, 307; 285, if_statement; 285, 286; 285, 291; 286, comparison_operator:not; 286, 287; 286, 288; 287, string:'value_function'; 288, subscript; 288, 289; 288, 290; 289, identifier:data; 290, string:'nrql_condition'; 291, block; 291, 292; 292, raise_statement; 292, 293; 293, call; 293, 294; 293, 295; 294, identifier:ConfigurationException; 295, argument_list; 295, 296; 296, string:'Alert is set as static but no value_function config specified'; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 304; 299, attribute; 299, 300; 299, 303; 300, subscript; 300, 301; 300, 302; 301, identifier:data; 302, string:'nrql_condition'; 303, identifier:pop; 304, argument_list; 304, 305; 304, 306; 305, string:'expected_groups'; 306, None; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 314; 309, attribute; 309, 310; 309, 313; 310, subscript; 310, 311; 310, 312; 311, identifier:data; 312, string:'nrql_condition'; 313, identifier:pop; 314, argument_list; 314, 315; 314, 316; 315, string:'ignore_overlap'; 316, None; 317, elif_clause; 317, 318; 317, 325; 318, comparison_operator:==; 318, 319; 318, 324; 319, subscript; 319, 320; 319, 323; 320, subscript; 320, 321; 320, 322; 321, identifier:data; 322, string:'nrql_condition'; 323, string:'type'; 324, string:'outlier'; 325, block; 325, 326; 325, 338; 325, 350; 326, if_statement; 326, 327; 326, 332; 327, comparison_operator:not; 327, 328; 327, 329; 328, string:'expected_groups'; 329, subscript; 329, 330; 329, 331; 330, identifier:data; 331, string:'nrql_condition'; 332, block; 332, 333; 333, raise_statement; 333, 334; 334, call; 334, 335; 334, 336; 335, identifier:ConfigurationException; 336, argument_list; 336, 337; 337, string:'Alert is set as outlier but expected_groups config is not specified'; 338, if_statement; 338, 339; 338, 344; 339, comparison_operator:not; 339, 340; 339, 341; 340, string:'ignore_overlap'; 341, subscript; 341, 342; 341, 343; 342, identifier:data; 343, string:'nrql_condition'; 344, block; 344, 345; 345, raise_statement; 345, 346; 346, call; 346, 347; 346, 348; 347, identifier:ConfigurationException; 348, argument_list; 348, 349; 349, string:'Alert is set as outlier but ignore_overlap config is not specified'; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 357; 352, attribute; 352, 353; 352, 356; 353, subscript; 353, 354; 353, 355; 354, identifier:data; 355, string:'nrql_condition'; 356, identifier:pop; 357, argument_list; 357, 358; 357, 359; 358, string:'value_function'; 359, None; 360, return_statement; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:self; 364, identifier:_put; 365, argument_list; 365, 366; 365, 377; 365, 382; 366, keyword_argument; 366, 367; 366, 368; 367, identifier:url; 368, call; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, string:'{0}alerts_nrql_conditions/{1}.json'; 371, identifier:format; 372, argument_list; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:self; 375, identifier:URL; 376, identifier:alert_condition_nrql_id; 377, keyword_argument; 377, 378; 377, 379; 378, identifier:headers; 379, attribute; 379, 380; 379, 381; 380, identifier:self; 381, identifier:headers; 382, keyword_argument; 382, 383; 382, 384; 383, identifier:data; 384, identifier:data | def update(
self, alert_condition_nrql_id, policy_id, name=None, threshold_type=None, query=None,
since_value=None, terms=None, expected_groups=None, value_function=None,
runbook_url=None, ignore_overlap=None, enabled=True):
conditions_nrql_dict = self.list(policy_id)
target_condition_nrql = None
for condition in conditions_nrql_dict['nrql_conditions']:
if int(condition['id']) == alert_condition_nrql_id:
target_condition_nrql = condition
break
if target_condition_nrql is None:
raise NoEntityException(
'Target alert condition nrql is not included in that policy.'
'policy_id: {}, alert_condition_nrql_id {}'.format(
policy_id,
alert_condition_nrql_id
)
)
data = {
'nrql_condition': {
'type': threshold_type or target_condition_nrql['type'],
'enabled': target_condition_nrql['enabled'],
'name': name or target_condition_nrql['name'],
'terms': terms or target_condition_nrql['terms'],
'nrql': {
'query': query or target_condition_nrql['nrql']['query'],
'since_value': since_value or target_condition_nrql['nrql']['since_value'],
}
}
}
if enabled is not None:
data['nrql_condition']['enabled'] = str(enabled).lower()
if runbook_url is not None:
data['nrql_condition']['runbook_url'] = runbook_url
elif 'runbook_url' in target_condition_nrql:
data['nrql_condition']['runbook_url'] = target_condition_nrql['runbook_url']
if expected_groups is not None:
data['nrql_condition']['expected_groups'] = expected_groups
elif 'expected_groups' in target_condition_nrql:
data['nrql_condition']['expected_groups'] = target_condition_nrql['expected_groups']
if ignore_overlap is not None:
data['nrql_condition']['ignore_overlap'] = ignore_overlap
elif 'ignore_overlap' in target_condition_nrql:
data['nrql_condition']['ignore_overlap'] = target_condition_nrql['ignore_overlap']
if value_function is not None:
data['nrql_condition']['value_function'] = value_function
elif 'value_function' in target_condition_nrql:
data['nrql_condition']['value_function'] = target_condition_nrql['value_function']
if data['nrql_condition']['type'] == 'static':
if 'value_function' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as static but no value_function config specified'
)
data['nrql_condition'].pop('expected_groups', None)
data['nrql_condition'].pop('ignore_overlap', None)
elif data['nrql_condition']['type'] == 'outlier':
if 'expected_groups' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as outlier but expected_groups config is not specified'
)
if 'ignore_overlap' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as outlier but ignore_overlap config is not specified'
)
data['nrql_condition'].pop('value_function', None)
return self._put(
url='{0}alerts_nrql_conditions/{1}.json'.format(self.URL, alert_condition_nrql_id),
headers=self.headers,
data=data
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:create; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, identifier:policy_id; 6, identifier:name; 7, identifier:threshold_type; 8, identifier:query; 9, identifier:since_value; 10, identifier:terms; 11, default_parameter; 11, 12; 11, 13; 12, identifier:expected_groups; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:value_function; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:runbook_url; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:ignore_overlap; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:enabled; 25, True; 26, block; 26, 27; 26, 55; 26, 68; 26, 81; 26, 94; 26, 107; 26, 191; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:data; 30, dictionary; 30, 31; 31, pair; 31, 32; 31, 33; 32, string:'nrql_condition'; 33, dictionary; 33, 34; 33, 37; 33, 40; 33, 43; 33, 46; 34, pair; 34, 35; 34, 36; 35, string:'type'; 36, identifier:threshold_type; 37, pair; 37, 38; 37, 39; 38, string:'name'; 39, identifier:name; 40, pair; 40, 41; 40, 42; 41, string:'enabled'; 42, identifier:enabled; 43, pair; 43, 44; 43, 45; 44, string:'terms'; 45, identifier:terms; 46, pair; 46, 47; 46, 48; 47, string:'nrql'; 48, dictionary; 48, 49; 48, 52; 49, pair; 49, 50; 49, 51; 50, string:'query'; 51, identifier:query; 52, pair; 52, 53; 52, 54; 53, string:'since_value'; 54, identifier:since_value; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:runbook_url; 58, None; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 67; 62, subscript; 62, 63; 62, 66; 63, subscript; 63, 64; 63, 65; 64, identifier:data; 65, string:'nrql_condition'; 66, string:'runbook_url'; 67, identifier:runbook_url; 68, if_statement; 68, 69; 68, 72; 69, comparison_operator:is; 69, 70; 69, 71; 70, identifier:expected_groups; 71, None; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 80; 75, subscript; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:data; 78, string:'nrql_condition'; 79, string:'expected_groups'; 80, identifier:expected_groups; 81, if_statement; 81, 82; 81, 85; 82, comparison_operator:is; 82, 83; 82, 84; 83, identifier:ignore_overlap; 84, None; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 93; 88, subscript; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:data; 91, string:'nrql_condition'; 92, string:'ignore_overlap'; 93, identifier:ignore_overlap; 94, if_statement; 94, 95; 94, 98; 95, comparison_operator:is; 95, 96; 95, 97; 96, identifier:value_function; 97, None; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 106; 101, subscript; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:data; 104, string:'nrql_condition'; 105, string:'value_function'; 106, identifier:value_function; 107, if_statement; 107, 108; 107, 115; 107, 148; 108, comparison_operator:==; 108, 109; 108, 114; 109, subscript; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:data; 112, string:'nrql_condition'; 113, string:'type'; 114, string:'static'; 115, block; 115, 116; 115, 128; 115, 138; 116, if_statement; 116, 117; 116, 122; 117, comparison_operator:not; 117, 118; 117, 119; 118, string:'value_function'; 119, subscript; 119, 120; 119, 121; 120, identifier:data; 121, string:'nrql_condition'; 122, block; 122, 123; 123, raise_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:ConfigurationException; 126, argument_list; 126, 127; 127, string:'Alert is set as static but no value_function config specified'; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:data; 133, string:'nrql_condition'; 134, identifier:pop; 135, argument_list; 135, 136; 135, 137; 136, string:'expected_groups'; 137, None; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:data; 143, string:'nrql_condition'; 144, identifier:pop; 145, argument_list; 145, 146; 145, 147; 146, string:'ignore_overlap'; 147, None; 148, elif_clause; 148, 149; 148, 156; 149, comparison_operator:==; 149, 150; 149, 155; 150, subscript; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:data; 153, string:'nrql_condition'; 154, string:'type'; 155, string:'outlier'; 156, block; 156, 157; 156, 169; 156, 181; 157, if_statement; 157, 158; 157, 163; 158, comparison_operator:not; 158, 159; 158, 160; 159, string:'expected_groups'; 160, subscript; 160, 161; 160, 162; 161, identifier:data; 162, string:'nrql_condition'; 163, block; 163, 164; 164, raise_statement; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:ConfigurationException; 167, argument_list; 167, 168; 168, string:'Alert is set as outlier but expected_groups config is not specified'; 169, if_statement; 169, 170; 169, 175; 170, comparison_operator:not; 170, 171; 170, 172; 171, string:'ignore_overlap'; 172, subscript; 172, 173; 172, 174; 173, identifier:data; 174, string:'nrql_condition'; 175, block; 175, 176; 176, raise_statement; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:ConfigurationException; 179, argument_list; 179, 180; 180, string:'Alert is set as outlier but ignore_overlap config is not specified'; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 188; 183, attribute; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:data; 186, string:'nrql_condition'; 187, identifier:pop; 188, argument_list; 188, 189; 188, 190; 189, string:'value_function'; 190, None; 191, return_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:_post; 196, argument_list; 196, 197; 196, 208; 196, 213; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:url; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, string:'{0}alerts_nrql_conditions/policies/{1}.json'; 202, identifier:format; 203, argument_list; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:URL; 207, identifier:policy_id; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:headers; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:headers; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:data; 215, identifier:data | def create(
self, policy_id, name, threshold_type, query, since_value, terms,
expected_groups=None, value_function=None, runbook_url=None,
ignore_overlap=None, enabled=True):
data = {
'nrql_condition': {
'type': threshold_type,
'name': name,
'enabled': enabled,
'terms': terms,
'nrql': {
'query': query,
'since_value': since_value
}
}
}
if runbook_url is not None:
data['nrql_condition']['runbook_url'] = runbook_url
if expected_groups is not None:
data['nrql_condition']['expected_groups'] = expected_groups
if ignore_overlap is not None:
data['nrql_condition']['ignore_overlap'] = ignore_overlap
if value_function is not None:
data['nrql_condition']['value_function'] = value_function
if data['nrql_condition']['type'] == 'static':
if 'value_function' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as static but no value_function config specified'
)
data['nrql_condition'].pop('expected_groups', None)
data['nrql_condition'].pop('ignore_overlap', None)
elif data['nrql_condition']['type'] == 'outlier':
if 'expected_groups' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as outlier but expected_groups config is not specified'
)
if 'ignore_overlap' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as outlier but ignore_overlap config is not specified'
)
data['nrql_condition'].pop('value_function', None)
return self._post(
url='{0}alerts_nrql_conditions/policies/{1}.json'.format(self.URL, policy_id),
headers=self.headers,
data=data
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 34; 2, function_name:update; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 4, identifier:self; 5, identifier:alert_condition_id; 6, identifier:policy_id; 7, default_parameter; 7, 8; 7, 9; 8, identifier:type; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:condition_scope; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:name; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:entities; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:metric; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:runbook_url; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:terms; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:user_defined; 30, None; 31, default_parameter; 31, 32; 31, 33; 32, identifier:enabled; 33, None; 34, block; 34, 35; 34, 44; 34, 48; 34, 69; 34, 87; 34, 143; 34, 163; 34, 205; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:conditions_dict; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:list; 42, argument_list; 42, 43; 43, identifier:policy_id; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:target_condition; 47, None; 48, for_statement; 48, 49; 48, 50; 48, 53; 49, identifier:condition; 50, subscript; 50, 51; 50, 52; 51, identifier:conditions_dict; 52, string:'conditions'; 53, block; 53, 54; 54, if_statement; 54, 55; 54, 63; 55, comparison_operator:==; 55, 56; 55, 62; 56, call; 56, 57; 56, 58; 57, identifier:int; 58, argument_list; 58, 59; 59, subscript; 59, 60; 59, 61; 60, identifier:condition; 61, string:'id'; 62, identifier:alert_condition_id; 63, block; 63, 64; 63, 68; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:target_condition; 67, identifier:condition; 68, break_statement; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:is; 70, 71; 70, 72; 71, identifier:target_condition; 72, None; 73, block; 73, 74; 74, raise_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:NoEntityException; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, concatenated_string; 80, 81; 80, 82; 81, string:'Target alert condition is not included in that policy.'; 82, string:'policy_id: {}, alert_condition_id {}'; 83, identifier:format; 84, argument_list; 84, 85; 84, 86; 85, identifier:policy_id; 86, identifier:alert_condition_id; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:data; 90, dictionary; 90, 91; 91, pair; 91, 92; 91, 93; 92, string:'condition'; 93, dictionary; 93, 94; 93, 101; 93, 108; 93, 115; 93, 122; 93, 129; 93, 136; 94, pair; 94, 95; 94, 96; 95, string:'type'; 96, boolean_operator:or; 96, 97; 96, 98; 97, identifier:type; 98, subscript; 98, 99; 98, 100; 99, identifier:target_condition; 100, string:'type'; 101, pair; 101, 102; 101, 103; 102, string:'name'; 103, boolean_operator:or; 103, 104; 103, 105; 104, identifier:name; 105, subscript; 105, 106; 105, 107; 106, identifier:target_condition; 107, string:'name'; 108, pair; 108, 109; 108, 110; 109, string:'entities'; 110, boolean_operator:or; 110, 111; 110, 112; 111, identifier:entities; 112, subscript; 112, 113; 112, 114; 113, identifier:target_condition; 114, string:'entities'; 115, pair; 115, 116; 115, 117; 116, string:'condition_scope'; 117, boolean_operator:or; 117, 118; 117, 119; 118, identifier:condition_scope; 119, subscript; 119, 120; 119, 121; 120, identifier:target_condition; 121, string:'condition_scope'; 122, pair; 122, 123; 122, 124; 123, string:'terms'; 124, boolean_operator:or; 124, 125; 124, 126; 125, identifier:terms; 126, subscript; 126, 127; 126, 128; 127, identifier:target_condition; 128, string:'terms'; 129, pair; 129, 130; 129, 131; 130, string:'metric'; 131, boolean_operator:or; 131, 132; 131, 133; 132, identifier:metric; 133, subscript; 133, 134; 133, 135; 134, identifier:target_condition; 135, string:'metric'; 136, pair; 136, 137; 136, 138; 137, string:'runbook_url'; 138, boolean_operator:or; 138, 139; 138, 140; 139, identifier:runbook_url; 140, subscript; 140, 141; 140, 142; 141, identifier:target_condition; 142, string:'runbook_url'; 143, if_statement; 143, 144; 143, 147; 144, comparison_operator:is; 144, 145; 144, 146; 145, identifier:enabled; 146, None; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 155; 150, subscript; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:data; 153, string:'condition'; 154, string:'enabled'; 155, call; 155, 156; 155, 162; 156, attribute; 156, 157; 156, 161; 157, call; 157, 158; 157, 159; 158, identifier:str; 159, argument_list; 159, 160; 160, identifier:enabled; 161, identifier:lower; 162, argument_list; 163, if_statement; 163, 164; 163, 171; 164, comparison_operator:==; 164, 165; 164, 170; 165, subscript; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:data; 168, string:'condition'; 169, string:'metric'; 170, string:'user_defined'; 171, block; 171, 172; 172, if_statement; 172, 173; 172, 174; 172, 183; 172, 198; 173, identifier:user_defined; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 182; 177, subscript; 177, 178; 177, 181; 178, subscript; 178, 179; 178, 180; 179, identifier:data; 180, string:'condition'; 181, string:'user_defined'; 182, identifier:user_defined; 183, elif_clause; 183, 184; 183, 187; 184, comparison_operator:in; 184, 185; 184, 186; 185, string:'user_defined'; 186, identifier:target_condition; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 195; 190, subscript; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:data; 193, string:'condition'; 194, string:'user_defined'; 195, subscript; 195, 196; 195, 197; 196, identifier:target_condition; 197, string:'user_defined'; 198, else_clause; 198, 199; 199, block; 199, 200; 200, raise_statement; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:ConfigurationException; 203, argument_list; 203, 204; 204, string:'Metric is set as user_defined but no user_defined config specified'; 205, return_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:_put; 210, argument_list; 210, 211; 210, 222; 210, 227; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:url; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, string:'{0}alerts_conditions/{1}.json'; 216, identifier:format; 217, argument_list; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:URL; 221, identifier:alert_condition_id; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:headers; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:headers; 227, keyword_argument; 227, 228; 227, 229; 228, identifier:data; 229, identifier:data | def update(
self, alert_condition_id, policy_id,
type=None,
condition_scope=None,
name=None,
entities=None,
metric=None,
runbook_url=None,
terms=None,
user_defined=None,
enabled=None):
conditions_dict = self.list(policy_id)
target_condition = None
for condition in conditions_dict['conditions']:
if int(condition['id']) == alert_condition_id:
target_condition = condition
break
if target_condition is None:
raise NoEntityException(
'Target alert condition is not included in that policy.'
'policy_id: {}, alert_condition_id {}'.format(policy_id, alert_condition_id)
)
data = {
'condition': {
'type': type or target_condition['type'],
'name': name or target_condition['name'],
'entities': entities or target_condition['entities'],
'condition_scope': condition_scope or target_condition['condition_scope'],
'terms': terms or target_condition['terms'],
'metric': metric or target_condition['metric'],
'runbook_url': runbook_url or target_condition['runbook_url'],
}
}
if enabled is not None:
data['condition']['enabled'] = str(enabled).lower()
if data['condition']['metric'] == 'user_defined':
if user_defined:
data['condition']['user_defined'] = user_defined
elif 'user_defined' in target_condition:
data['condition']['user_defined'] = target_condition['user_defined']
else:
raise ConfigurationException(
'Metric is set as user_defined but no user_defined config specified'
)
return self._put(
url='{0}alerts_conditions/{1}.json'.format(self.URL, alert_condition_id),
headers=self.headers,
data=data
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:operatorPrecedence; 3, parameters; 3, 4; 3, 5; 4, identifier:base; 5, identifier:operators; 6, block; 6, 7; 6, 13; 6, 29; 6, 49; 6, 214; 6, 218; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:expression; 10, call; 10, 11; 10, 12; 11, identifier:Forward; 12, argument_list; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:last; 16, binary_operator:|; 16, 17; 16, 18; 17, identifier:base; 18, binary_operator:+; 18, 19; 18, 25; 19, binary_operator:+; 19, 20; 19, 24; 20, call; 20, 21; 20, 22; 21, identifier:Suppress; 22, argument_list; 22, 23; 23, string:'('; 24, identifier:expression; 25, call; 25, 26; 25, 27; 26, identifier:Suppress; 27, argument_list; 27, 28; 28, string:')'; 29, function_definition; 29, 30; 29, 31; 29, 41; 30, function_name:parse_operator; 31, parameters; 31, 32; 31, 33; 31, 34; 31, 35; 31, 38; 32, identifier:expr; 33, identifier:arity; 34, identifier:association; 35, default_parameter; 35, 36; 35, 37; 36, identifier:action; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:extra; 40, None; 41, block; 41, 42; 42, return_statement; 42, 43; 43, expression_list; 43, 44; 43, 45; 43, 46; 43, 47; 43, 48; 44, identifier:expr; 45, identifier:arity; 46, identifier:association; 47, identifier:action; 48, identifier:extra; 49, for_statement; 49, 50; 49, 51; 49, 52; 50, identifier:op; 51, identifier:operators; 52, block; 52, 53; 52, 66; 52, 80; 52, 96; 52, 102; 52, 191; 52, 203; 52, 210; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 61; 55, pattern_list; 55, 56; 55, 57; 55, 58; 55, 59; 55, 60; 56, identifier:expr; 57, identifier:arity; 58, identifier:association; 59, identifier:action; 60, identifier:extra; 61, call; 61, 62; 61, 63; 62, identifier:parse_operator; 63, argument_list; 63, 64; 64, list_splat; 64, 65; 65, identifier:op; 66, if_statement; 66, 67; 66, 74; 67, boolean_operator:or; 67, 68; 67, 71; 68, comparison_operator:<; 68, 69; 68, 70; 69, identifier:arity; 70, integer:1; 71, comparison_operator:>; 71, 72; 71, 73; 72, identifier:arity; 73, integer:2; 74, block; 74, 75; 75, raise_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:Exception; 78, argument_list; 78, 79; 79, string:"Arity must be unary (1) or binary (2)"; 80, if_statement; 80, 81; 80, 90; 81, comparison_operator:not; 81, 82; 81, 83; 82, identifier:association; 83, tuple; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:opAssoc; 86, identifier:LEFT; 87, attribute; 87, 88; 87, 89; 88, identifier:opAssoc; 89, identifier:RIGHT; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:Exception; 94, argument_list; 94, 95; 95, string:"Association must be LEFT or RIGHT"; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:this; 99, call; 99, 100; 99, 101; 100, identifier:Forward; 101, argument_list; 102, if_statement; 102, 103; 102, 108; 102, 149; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:association; 105, attribute; 105, 106; 105, 107; 106, identifier:opAssoc; 107, identifier:LEFT; 108, block; 108, 109; 108, 119; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:new_last; 112, conditional_expression:if; 112, 113; 112, 117; 112, 118; 113, parenthesized_expression; 113, 114; 114, binary_operator:|; 114, 115; 114, 116; 115, identifier:last; 116, identifier:extra; 117, identifier:extra; 118, identifier:last; 119, if_statement; 119, 120; 119, 123; 119, 133; 120, comparison_operator:==; 120, 121; 120, 122; 121, identifier:arity; 122, integer:1; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:operator_expression; 127, binary_operator:+; 127, 128; 127, 129; 128, identifier:new_last; 129, call; 129, 130; 129, 131; 130, identifier:OneOrMore; 131, argument_list; 131, 132; 132, identifier:expr; 133, elif_clause; 133, 134; 133, 137; 134, comparison_operator:==; 134, 135; 134, 136; 135, identifier:arity; 136, integer:2; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:operator_expression; 141, binary_operator:+; 141, 142; 141, 143; 142, identifier:last; 143, call; 143, 144; 143, 145; 144, identifier:OneOrMore; 145, argument_list; 145, 146; 146, binary_operator:+; 146, 147; 146, 148; 147, identifier:expr; 148, identifier:new_last; 149, elif_clause; 149, 150; 149, 155; 150, comparison_operator:is; 150, 151; 150, 152; 151, identifier:association; 152, attribute; 152, 153; 152, 154; 153, identifier:opAssoc; 154, identifier:RIGHT; 155, block; 155, 156; 155, 166; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:new_this; 159, conditional_expression:if; 159, 160; 159, 164; 159, 165; 160, parenthesized_expression; 160, 161; 161, binary_operator:|; 161, 162; 161, 163; 162, identifier:this; 163, identifier:extra; 164, identifier:extra; 165, identifier:this; 166, if_statement; 166, 167; 166, 170; 166, 177; 167, comparison_operator:==; 167, 168; 167, 169; 168, identifier:arity; 169, integer:1; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:operator_expression; 174, binary_operator:+; 174, 175; 174, 176; 175, identifier:expr; 176, identifier:new_this; 177, elif_clause; 177, 178; 177, 181; 178, comparison_operator:==; 178, 179; 178, 180; 179, identifier:arity; 180, integer:2; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:operator_expression; 185, binary_operator:+; 185, 186; 185, 187; 186, identifier:last; 187, call; 187, 188; 187, 189; 188, identifier:OneOrMore; 189, argument_list; 189, 190; 190, identifier:new_this; 191, if_statement; 191, 192; 191, 195; 192, comparison_operator:is; 192, 193; 192, 194; 193, identifier:action; 194, None; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:operator_expression; 200, identifier:setParseAction; 201, argument_list; 201, 202; 202, identifier:action; 203, expression_statement; 203, 204; 204, augmented_assignment:<<=; 204, 205; 204, 206; 205, identifier:this; 206, parenthesized_expression; 206, 207; 207, binary_operator:|; 207, 208; 207, 209; 208, identifier:operator_expression; 209, identifier:last; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:last; 213, identifier:this; 214, expression_statement; 214, 215; 215, augmented_assignment:<<=; 215, 216; 215, 217; 216, identifier:expression; 217, identifier:last; 218, return_statement; 218, 219; 219, identifier:expression | def operatorPrecedence(base, operators):
expression = Forward()
last = base | Suppress('(') + expression + Suppress(')')
def parse_operator(expr, arity, association, action=None, extra=None):
return expr, arity, association, action, extra
for op in operators:
expr, arity, association, action, extra = parse_operator(*op)
if arity < 1 or arity > 2:
raise Exception("Arity must be unary (1) or binary (2)")
if association not in (opAssoc.LEFT, opAssoc.RIGHT):
raise Exception("Association must be LEFT or RIGHT")
this = Forward()
if association is opAssoc.LEFT:
new_last = (last | extra) if extra else last
if arity == 1:
operator_expression = new_last + OneOrMore(expr)
elif arity == 2:
operator_expression = last + OneOrMore(expr + new_last)
elif association is opAssoc.RIGHT:
new_this = (this | extra) if extra else this
if arity == 1:
operator_expression = expr + new_this
elif arity == 2:
operator_expression = last + OneOrMore(new_this)
if action is not None:
operator_expression.setParseAction(action)
this <<= (operator_expression | last)
last = this
expression <<= last
return expression |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:readGraph; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:edgeList; 5, default_parameter; 5, 6; 5, 7; 6, identifier:nodeList; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:directed; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:idKey; 13, string:'ID'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:eSource; 16, string:'From'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:eDest; 19, string:'To'; 20, block; 20, 21; 20, 27; 20, 48; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:progArgs; 24, tuple; 24, 25; 24, 26; 25, integer:0; 26, string:"Starting to reading graphs"; 27, if_statement; 27, 28; 27, 31; 27, 39; 28, attribute; 28, 29; 28, 30; 29, identifier:metaknowledge; 30, identifier:VERBOSE_MODE; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:progKwargs; 35, dictionary; 35, 36; 36, pair; 36, 37; 36, 38; 37, string:'dummy'; 38, False; 39, else_clause; 39, 40; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:progKwargs; 44, dictionary; 44, 45; 45, pair; 45, 46; 45, 47; 46, string:'dummy'; 47, True; 48, with_statement; 48, 49; 48, 61; 49, with_clause; 49, 50; 50, with_item; 50, 51; 51, as_pattern; 51, 52; 51, 59; 52, call; 52, 53; 52, 54; 53, identifier:_ProgressBar; 54, argument_list; 54, 55; 54, 57; 55, list_splat; 55, 56; 56, identifier:progArgs; 57, dictionary_splat; 57, 58; 58, identifier:progKwargs; 59, as_pattern_target; 59, 60; 60, identifier:PBar; 61, block; 61, 62; 61, 83; 61, 176; 61, 186; 61, 207; 61, 216; 61, 272; 61, 299; 61, 305; 62, if_statement; 62, 63; 62, 64; 62, 73; 63, identifier:directed; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:grph; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:nx; 71, identifier:DiGraph; 72, argument_list; 73, else_clause; 73, 74; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:grph; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:nx; 81, identifier:Graph; 82, argument_list; 83, if_statement; 83, 84; 83, 85; 84, identifier:nodeList; 85, block; 85, 86; 85, 96; 85, 117; 85, 126; 85, 170; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:PBar; 90, identifier:updateVal; 91, argument_list; 91, 92; 91, 93; 92, integer:0; 93, binary_operator:+; 93, 94; 93, 95; 94, string:"Reading "; 95, identifier:nodeList; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:f; 99, call; 99, 100; 99, 101; 100, identifier:open; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:os; 106, identifier:path; 107, identifier:expanduser; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:os; 113, identifier:path; 114, identifier:abspath; 115, argument_list; 115, 116; 116, identifier:nodeList; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:nFile; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:csv; 123, identifier:DictReader; 124, argument_list; 124, 125; 125, identifier:f; 126, for_statement; 126, 127; 126, 128; 126, 129; 127, identifier:line; 128, identifier:nFile; 129, block; 129, 130; 129, 134; 129, 140; 129, 144; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:vals; 133, identifier:line; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:ndID; 137, subscript; 137, 138; 137, 139; 138, identifier:vals; 139, identifier:idKey; 140, delete_statement; 140, 141; 141, subscript; 141, 142; 141, 143; 142, identifier:vals; 143, identifier:idKey; 144, if_statement; 144, 145; 144, 151; 144, 161; 145, comparison_operator:>; 145, 146; 145, 150; 146, call; 146, 147; 146, 148; 147, identifier:len; 148, argument_list; 148, 149; 149, identifier:vals; 150, integer:0; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:grph; 156, identifier:add_node; 157, argument_list; 157, 158; 157, 159; 158, identifier:ndID; 159, dictionary_splat; 159, 160; 160, identifier:vals; 161, else_clause; 161, 162; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:grph; 167, identifier:add_node; 168, argument_list; 168, 169; 169, identifier:ndID; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:f; 174, identifier:close; 175, argument_list; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:PBar; 180, identifier:updateVal; 181, argument_list; 181, 182; 181, 183; 182, float:.25; 183, binary_operator:+; 183, 184; 183, 185; 184, string:"Reading "; 185, identifier:edgeList; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:f; 189, call; 189, 190; 189, 191; 190, identifier:open; 191, argument_list; 191, 192; 192, call; 192, 193; 192, 198; 193, attribute; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:os; 196, identifier:path; 197, identifier:expanduser; 198, argument_list; 198, 199; 199, call; 199, 200; 199, 205; 200, attribute; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:os; 203, identifier:path; 204, identifier:abspath; 205, argument_list; 205, 206; 206, identifier:edgeList; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:eFile; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:csv; 213, identifier:DictReader; 214, argument_list; 214, 215; 215, identifier:f; 216, for_statement; 216, 217; 216, 218; 216, 219; 217, identifier:line; 218, identifier:eFile; 219, block; 219, 220; 219, 224; 219, 230; 219, 236; 219, 240; 219, 244; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:vals; 223, identifier:line; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:eFrom; 227, subscript; 227, 228; 227, 229; 228, identifier:vals; 229, identifier:eSource; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:eTo; 233, subscript; 233, 234; 233, 235; 234, identifier:vals; 235, identifier:eDest; 236, delete_statement; 236, 237; 237, subscript; 237, 238; 237, 239; 238, identifier:vals; 239, identifier:eSource; 240, delete_statement; 240, 241; 241, subscript; 241, 242; 241, 243; 242, identifier:vals; 243, identifier:eDest; 244, if_statement; 244, 245; 244, 251; 244, 262; 245, comparison_operator:>; 245, 246; 245, 250; 246, call; 246, 247; 246, 248; 247, identifier:len; 248, argument_list; 248, 249; 249, identifier:vals; 250, integer:0; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:grph; 256, identifier:add_edge; 257, argument_list; 257, 258; 257, 259; 257, 260; 258, identifier:eFrom; 259, identifier:eTo; 260, dictionary_splat; 260, 261; 261, identifier:vals; 262, else_clause; 262, 263; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:grph; 268, identifier:add_edge; 269, argument_list; 269, 270; 269, 271; 270, identifier:eFrom; 271, identifier:eTo; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:PBar; 276, identifier:finish; 277, argument_list; 277, 278; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, string:"{} nodes and {} edges found"; 281, identifier:format; 282, argument_list; 282, 283; 282, 291; 283, call; 283, 284; 283, 285; 284, identifier:len; 285, argument_list; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:grph; 289, identifier:nodes; 290, argument_list; 291, call; 291, 292; 291, 293; 292, identifier:len; 293, argument_list; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:grph; 297, identifier:edges; 298, argument_list; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:f; 303, identifier:close; 304, argument_list; 305, return_statement; 305, 306; 306, identifier:grph | def readGraph(edgeList, nodeList = None, directed = False, idKey = 'ID', eSource = 'From', eDest = 'To'):
progArgs = (0, "Starting to reading graphs")
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
if directed:
grph = nx.DiGraph()
else:
grph = nx.Graph()
if nodeList:
PBar.updateVal(0, "Reading " + nodeList)
f = open(os.path.expanduser(os.path.abspath(nodeList)))
nFile = csv.DictReader(f)
for line in nFile:
vals = line
ndID = vals[idKey]
del vals[idKey]
if len(vals) > 0:
grph.add_node(ndID, **vals)
else:
grph.add_node(ndID)
f.close()
PBar.updateVal(.25, "Reading " + edgeList)
f = open(os.path.expanduser(os.path.abspath(edgeList)))
eFile = csv.DictReader(f)
for line in eFile:
vals = line
eFrom = vals[eSource]
eTo = vals[eDest]
del vals[eSource]
del vals[eDest]
if len(vals) > 0:
grph.add_edge(eFrom, eTo, **vals)
else:
grph.add_edge(eFrom, eTo)
PBar.finish("{} nodes and {} edges found".format(len(grph.nodes()), len(grph.edges())))
f.close()
return grph |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:writeGraph; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:grph; 5, identifier:name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:edgeInfo; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:typing; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:suffix; 14, string:'csv'; 15, default_parameter; 15, 16; 15, 17; 16, identifier:overwrite; 17, True; 18, default_parameter; 18, 19; 18, 20; 19, identifier:allSameAttribute; 20, False; 21, block; 21, 22; 21, 33; 21, 54; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:progArgs; 25, tuple; 25, 26; 25, 27; 26, integer:0; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, string:"Writing the graph to files starting with: {}"; 30, identifier:format; 31, argument_list; 31, 32; 32, identifier:name; 33, if_statement; 33, 34; 33, 37; 33, 45; 34, attribute; 34, 35; 34, 36; 35, identifier:metaknowledge; 36, identifier:VERBOSE_MODE; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:progKwargs; 41, dictionary; 41, 42; 42, pair; 42, 43; 42, 44; 43, string:'dummy'; 44, False; 45, else_clause; 45, 46; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:progKwargs; 50, dictionary; 50, 51; 51, pair; 51, 52; 51, 53; 52, string:'dummy'; 53, True; 54, with_statement; 54, 55; 54, 67; 55, with_clause; 55, 56; 56, with_item; 56, 57; 57, as_pattern; 57, 58; 57, 65; 58, call; 58, 59; 58, 60; 59, identifier:_ProgressBar; 60, argument_list; 60, 61; 60, 63; 61, list_splat; 61, 62; 62, identifier:progArgs; 63, dictionary_splat; 63, 64; 64, identifier:progKwargs; 65, as_pattern_target; 65, 66; 66, identifier:PBar; 67, block; 67, 68; 67, 112; 67, 137; 67, 302; 67, 340; 67, 355; 67, 367; 68, if_statement; 68, 69; 68, 70; 68, 106; 69, identifier:typing; 70, block; 70, 71; 71, if_statement; 71, 72; 71, 95; 71, 100; 72, boolean_operator:or; 72, 73; 72, 84; 73, call; 73, 74; 73, 75; 74, identifier:isinstance; 75, argument_list; 75, 76; 75, 77; 76, identifier:grph; 77, attribute; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:nx; 81, identifier:classes; 82, identifier:digraph; 83, identifier:DiGraph; 84, call; 84, 85; 84, 86; 85, identifier:isinstance; 86, argument_list; 86, 87; 86, 88; 87, identifier:grph; 88, attribute; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:nx; 92, identifier:classes; 93, identifier:multidigraph; 94, identifier:MultiDiGraph; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:grphType; 99, string:"_directed"; 100, else_clause; 100, 101; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:grphType; 105, string:"_undirected"; 106, else_clause; 106, 107; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:grphType; 111, string:''; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:nameCompts; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:os; 119, identifier:path; 120, identifier:split; 121, argument_list; 121, 122; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:os; 126, identifier:path; 127, identifier:expanduser; 128, argument_list; 128, 129; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:os; 133, identifier:path; 134, identifier:normpath; 135, argument_list; 135, 136; 136, identifier:name; 137, if_statement; 137, 138; 137, 149; 137, 170; 137, 205; 137, 252; 138, boolean_operator:and; 138, 139; 138, 144; 139, comparison_operator:==; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:nameCompts; 142, integer:0; 143, string:''; 144, comparison_operator:==; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:nameCompts; 147, integer:1; 148, string:''; 149, block; 149, 150; 149, 160; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:edgeListName; 153, binary_operator:+; 153, 154; 153, 159; 154, binary_operator:+; 154, 155; 154, 158; 155, binary_operator:+; 155, 156; 155, 157; 156, string:"edgeList"; 157, identifier:grphType; 158, string:'.'; 159, identifier:suffix; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:nodesAtrName; 163, binary_operator:+; 163, 164; 163, 169; 164, binary_operator:+; 164, 165; 164, 168; 165, binary_operator:+; 165, 166; 165, 167; 166, string:"nodeAttributes"; 167, identifier:grphType; 168, string:'.'; 169, identifier:suffix; 170, elif_clause; 170, 171; 170, 176; 171, comparison_operator:==; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:nameCompts; 174, integer:0; 175, string:''; 176, block; 176, 177; 176, 191; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:edgeListName; 180, binary_operator:+; 180, 181; 180, 190; 181, binary_operator:+; 181, 182; 181, 189; 182, binary_operator:+; 182, 183; 182, 188; 183, binary_operator:+; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:nameCompts; 186, integer:1; 187, string:"_edgeList"; 188, identifier:grphType; 189, string:'.'; 190, identifier:suffix; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:nodesAtrName; 194, binary_operator:+; 194, 195; 194, 204; 195, binary_operator:+; 195, 196; 195, 203; 196, binary_operator:+; 196, 197; 196, 202; 197, binary_operator:+; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:nameCompts; 200, integer:1; 201, string:"_nodeAttributes"; 202, identifier:grphType; 203, string:'.'; 204, identifier:suffix; 205, elif_clause; 205, 206; 205, 211; 206, comparison_operator:==; 206, 207; 206, 210; 207, subscript; 207, 208; 207, 209; 208, identifier:nameCompts; 209, integer:1; 210, string:''; 211, block; 211, 212; 211, 232; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:edgeListName; 215, call; 215, 216; 215, 221; 216, attribute; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:os; 219, identifier:path; 220, identifier:join; 221, argument_list; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:nameCompts; 224, integer:0; 225, binary_operator:+; 225, 226; 225, 231; 226, binary_operator:+; 226, 227; 226, 230; 227, binary_operator:+; 227, 228; 227, 229; 228, string:"edgeList"; 229, identifier:grphType; 230, string:'.'; 231, identifier:suffix; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:nodesAtrName; 235, call; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:os; 239, identifier:path; 240, identifier:join; 241, argument_list; 241, 242; 241, 245; 242, subscript; 242, 243; 242, 244; 243, identifier:nameCompts; 244, integer:0; 245, binary_operator:+; 245, 246; 245, 251; 246, binary_operator:+; 246, 247; 246, 250; 247, binary_operator:+; 247, 248; 247, 249; 248, string:"nodeAttributes"; 249, identifier:grphType; 250, string:'.'; 251, identifier:suffix; 252, else_clause; 252, 253; 253, block; 253, 254; 253, 278; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:edgeListName; 257, call; 257, 258; 257, 263; 258, attribute; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:os; 261, identifier:path; 262, identifier:join; 263, argument_list; 263, 264; 263, 267; 264, subscript; 264, 265; 264, 266; 265, identifier:nameCompts; 266, integer:0; 267, binary_operator:+; 267, 268; 267, 277; 268, binary_operator:+; 268, 269; 268, 276; 269, binary_operator:+; 269, 270; 269, 275; 270, binary_operator:+; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:nameCompts; 273, integer:1; 274, string:"_edgeList"; 275, identifier:grphType; 276, string:'.'; 277, identifier:suffix; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:nodesAtrName; 281, call; 281, 282; 281, 287; 282, attribute; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:os; 285, identifier:path; 286, identifier:join; 287, argument_list; 287, 288; 287, 291; 288, subscript; 288, 289; 288, 290; 289, identifier:nameCompts; 290, integer:0; 291, binary_operator:+; 291, 292; 291, 301; 292, binary_operator:+; 292, 293; 292, 300; 293, binary_operator:+; 293, 294; 293, 299; 294, binary_operator:+; 294, 295; 294, 298; 295, subscript; 295, 296; 295, 297; 296, identifier:nameCompts; 297, integer:1; 298, string:"_nodeAttributes"; 299, identifier:grphType; 300, string:'.'; 301, identifier:suffix; 302, if_statement; 302, 303; 302, 305; 303, not_operator; 303, 304; 304, identifier:overwrite; 305, block; 305, 306; 305, 323; 306, if_statement; 306, 307; 306, 315; 307, call; 307, 308; 307, 313; 308, attribute; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:os; 311, identifier:path; 312, identifier:isfile; 313, argument_list; 313, 314; 314, identifier:edgeListName; 315, block; 315, 316; 316, raise_statement; 316, 317; 317, call; 317, 318; 317, 319; 318, identifier:OSError; 319, argument_list; 319, 320; 320, binary_operator:+; 320, 321; 320, 322; 321, identifier:edgeListName; 322, string:" already exists"; 323, if_statement; 323, 324; 323, 332; 324, call; 324, 325; 324, 330; 325, attribute; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:os; 328, identifier:path; 329, identifier:isfile; 330, argument_list; 330, 331; 331, identifier:nodesAtrName; 332, block; 332, 333; 333, raise_statement; 333, 334; 334, call; 334, 335; 334, 336; 335, identifier:OSError; 336, argument_list; 336, 337; 337, binary_operator:+; 337, 338; 337, 339; 338, identifier:nodesAtrName; 339, string:" already exists"; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 343; 342, identifier:writeEdgeList; 343, argument_list; 343, 344; 343, 345; 343, 346; 343, 349; 343, 352; 344, identifier:grph; 345, identifier:edgeListName; 346, keyword_argument; 346, 347; 346, 348; 347, identifier:extraInfo; 348, identifier:edgeInfo; 349, keyword_argument; 349, 350; 349, 351; 350, identifier:allSameAttribute; 351, identifier:allSameAttribute; 352, keyword_argument; 352, 353; 352, 354; 353, identifier:_progBar; 354, identifier:PBar; 355, expression_statement; 355, 356; 356, call; 356, 357; 356, 358; 357, identifier:writeNodeAttributeFile; 358, argument_list; 358, 359; 358, 360; 358, 361; 358, 364; 359, identifier:grph; 360, identifier:nodesAtrName; 361, keyword_argument; 361, 362; 361, 363; 362, identifier:allSameAttribute; 363, identifier:allSameAttribute; 364, keyword_argument; 364, 365; 364, 366; 365, identifier:_progBar; 366, identifier:PBar; 367, expression_statement; 367, 368; 368, call; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:PBar; 371, identifier:finish; 372, argument_list; 372, 373; 373, call; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, string:"{} nodes and {} edges written to file"; 376, identifier:format; 377, argument_list; 377, 378; 377, 386; 378, call; 378, 379; 378, 380; 379, identifier:len; 380, argument_list; 380, 381; 381, call; 381, 382; 381, 385; 382, attribute; 382, 383; 382, 384; 383, identifier:grph; 384, identifier:nodes; 385, argument_list; 386, call; 386, 387; 386, 388; 387, identifier:len; 388, argument_list; 388, 389; 389, call; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:grph; 392, identifier:edges; 393, argument_list | def writeGraph(grph, name, edgeInfo = True, typing = False, suffix = 'csv', overwrite = True, allSameAttribute = False):
progArgs = (0, "Writing the graph to files starting with: {}".format(name))
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
if typing:
if isinstance(grph, nx.classes.digraph.DiGraph) or isinstance(grph, nx.classes.multidigraph.MultiDiGraph):
grphType = "_directed"
else:
grphType = "_undirected"
else:
grphType = ''
nameCompts = os.path.split(os.path.expanduser(os.path.normpath(name)))
if nameCompts[0] == '' and nameCompts[1] == '':
edgeListName = "edgeList"+ grphType + '.' + suffix
nodesAtrName = "nodeAttributes"+ grphType + '.' + suffix
elif nameCompts[0] == '':
edgeListName = nameCompts[1] + "_edgeList"+ grphType + '.' + suffix
nodesAtrName = nameCompts[1] + "_nodeAttributes"+ grphType + '.' + suffix
elif nameCompts[1] == '':
edgeListName = os.path.join(nameCompts[0], "edgeList"+ grphType + '.' + suffix)
nodesAtrName = os.path.join(nameCompts[0], "nodeAttributes"+ grphType + '.' + suffix)
else:
edgeListName = os.path.join(nameCompts[0], nameCompts[1] + "_edgeList"+ grphType + '.' + suffix)
nodesAtrName = os.path.join(nameCompts[0], nameCompts[1] + "_nodeAttributes"+ grphType + '.' + suffix)
if not overwrite:
if os.path.isfile(edgeListName):
raise OSError(edgeListName+ " already exists")
if os.path.isfile(nodesAtrName):
raise OSError(nodesAtrName + " already exists")
writeEdgeList(grph, edgeListName, extraInfo = edgeInfo, allSameAttribute = allSameAttribute, _progBar = PBar)
writeNodeAttributeFile(grph, nodesAtrName, allSameAttribute = allSameAttribute, _progBar = PBar)
PBar.finish("{} nodes and {} edges written to file".format(len(grph.nodes()), len(grph.edges()))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:mergeGraphs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:targetGraph; 5, identifier:addedGraph; 6, default_parameter; 6, 7; 6, 8; 7, identifier:incrementedNodeVal; 8, string:'count'; 9, default_parameter; 9, 10; 9, 11; 10, identifier:incrementedEdgeVal; 11, string:'weight'; 12, block; 12, 13; 12, 75; 13, for_statement; 13, 14; 13, 17; 13, 25; 14, pattern_list; 14, 15; 14, 16; 15, identifier:addedNode; 16, identifier:attribs; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:addedGraph; 20, identifier:nodes; 21, argument_list; 21, 22; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:data; 24, True; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 28; 26, 55; 27, identifier:incrementedNodeVal; 28, block; 28, 29; 29, try_statement; 29, 30; 29, 43; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, augmented_assignment:+=; 32, 33; 32, 40; 33, subscript; 33, 34; 33, 39; 34, subscript; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:targetGraph; 37, identifier:node; 38, identifier:addedNode; 39, identifier:incrementedNodeVal; 40, subscript; 40, 41; 40, 42; 41, identifier:attribs; 42, identifier:incrementedNodeVal; 43, except_clause; 43, 44; 43, 45; 44, identifier:KeyError; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:targetGraph; 50, identifier:add_node; 51, argument_list; 51, 52; 51, 53; 52, identifier:addedNode; 53, dictionary_splat; 53, 54; 54, identifier:attribs; 55, else_clause; 55, 56; 56, block; 56, 57; 57, if_statement; 57, 58; 57, 65; 58, not_operator; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:targetGraph; 62, identifier:has_node; 63, argument_list; 63, 64; 64, identifier:addedNode; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:targetGraph; 70, identifier:add_node; 71, argument_list; 71, 72; 71, 73; 72, identifier:addedNode; 73, dictionary_splat; 73, 74; 74, identifier:attribs; 75, for_statement; 75, 76; 75, 80; 75, 88; 76, pattern_list; 76, 77; 76, 78; 76, 79; 77, identifier:edgeNode1; 78, identifier:edgeNode2; 79, identifier:attribs; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:addedGraph; 83, identifier:edges; 84, argument_list; 84, 85; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:data; 87, True; 88, block; 88, 89; 89, if_statement; 89, 90; 89, 91; 89, 120; 90, identifier:incrementedEdgeVal; 91, block; 91, 92; 92, try_statement; 92, 93; 92, 107; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, augmented_assignment:+=; 95, 96; 95, 104; 96, subscript; 96, 97; 96, 103; 97, subscript; 97, 98; 97, 101; 97, 102; 98, attribute; 98, 99; 98, 100; 99, identifier:targetGraph; 100, identifier:edges; 101, identifier:edgeNode1; 102, identifier:edgeNode2; 103, identifier:incrementedEdgeVal; 104, subscript; 104, 105; 104, 106; 105, identifier:attribs; 106, identifier:incrementedEdgeVal; 107, except_clause; 107, 108; 107, 109; 108, identifier:KeyError; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:targetGraph; 114, identifier:add_edge; 115, argument_list; 115, 116; 115, 117; 115, 118; 116, identifier:edgeNode1; 117, identifier:edgeNode2; 118, dictionary_splat; 118, 119; 119, identifier:attribs; 120, else_clause; 120, 121; 121, block; 121, 122; 122, if_statement; 122, 123; 122, 133; 123, not_operator; 123, 124; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:targetGraph; 128, identifier:Graph; 129, identifier:has_edge; 130, argument_list; 130, 131; 130, 132; 131, identifier:edgeNode1; 132, identifier:edgeNode2; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:targetGraph; 138, identifier:add_edge; 139, argument_list; 139, 140; 139, 141; 139, 142; 140, identifier:edgeNode1; 141, identifier:edgeNode2; 142, dictionary_splat; 142, 143; 143, identifier:attribs | def mergeGraphs(targetGraph, addedGraph, incrementedNodeVal = 'count', incrementedEdgeVal = 'weight'):
for addedNode, attribs in addedGraph.nodes(data = True):
if incrementedNodeVal:
try:
targetGraph.node[addedNode][incrementedNodeVal] += attribs[incrementedNodeVal]
except KeyError:
targetGraph.add_node(addedNode, **attribs)
else:
if not targetGraph.has_node(addedNode):
targetGraph.add_node(addedNode, **attribs)
for edgeNode1, edgeNode2, attribs in addedGraph.edges(data = True):
if incrementedEdgeVal:
try:
targetGraph.edges[edgeNode1, edgeNode2][incrementedEdgeVal] += attribs[incrementedEdgeVal]
except KeyError:
targetGraph.add_edge(edgeNode1, edgeNode2, **attribs)
else:
if not targetGraph.Graph.has_edge(edgeNode1, edgeNode2):
targetGraph.add_edge(edgeNode1, edgeNode2, **attribs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:writeRecord; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:f; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 11; 7, 27; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:bad; 11, block; 11, 12; 12, raise_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:BadPubmedRecord; 15, argument_list; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, string:"This record cannot be converted to a file as the input was malformed.\nThe original line number (if any) is: {} and the original file is: '{}'"; 19, identifier:format; 20, argument_list; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_sourceLine; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_sourceFile; 27, else_clause; 27, 28; 28, block; 28, 29; 28, 33; 28, 143; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:authTags; 32, dictionary; 33, for_statement; 33, 34; 33, 35; 33, 36; 34, identifier:tag; 35, identifier:authorBasedTags; 36, block; 36, 37; 37, for_statement; 37, 38; 37, 39; 37, 48; 38, identifier:val; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:_fieldDict; 44, identifier:get; 45, argument_list; 45, 46; 45, 47; 46, identifier:tag; 47, list:[]; 48, block; 48, 49; 48, 58; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:split; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:val; 55, identifier:split; 56, argument_list; 56, 57; 57, string:' : '; 58, try_statement; 58, 59; 58, 101; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 69; 62, attribute; 62, 63; 62, 68; 63, subscript; 63, 64; 63, 65; 64, identifier:authTags; 65, subscript; 65, 66; 65, 67; 66, identifier:split; 67, integer:0; 68, identifier:append; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:"{0}{1}- {2}\n"; 73, identifier:format; 74, argument_list; 74, 75; 74, 76; 74, 85; 75, identifier:tag; 76, binary_operator:*; 76, 77; 76, 78; 77, string:' '; 78, parenthesized_expression; 78, 79; 79, binary_operator:-; 79, 80; 79, 81; 80, integer:4; 81, call; 81, 82; 81, 83; 82, identifier:len; 83, argument_list; 83, 84; 84, identifier:tag; 85, call; 85, 86; 85, 98; 86, attribute; 86, 87; 86, 97; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, string:' : '; 90, identifier:join; 91, argument_list; 91, 92; 92, subscript; 92, 93; 92, 94; 93, identifier:split; 94, slice; 94, 95; 94, 96; 95, integer:1; 96, colon; 97, identifier:replace; 98, argument_list; 98, 99; 98, 100; 99, string:'\n'; 100, string:'\n '; 101, except_clause; 101, 102; 101, 103; 102, identifier:KeyError; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 108; 107, identifier:authTags; 108, subscript; 108, 109; 108, 110; 109, identifier:split; 110, integer:0; 111, list:["{0}{1}- {2}\n".format(tag, ' ' * (4 - len(tag)),' : '.join(split[1:]).replace('\n', '\n '))]; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, string:"{0}{1}- {2}\n"; 115, identifier:format; 116, argument_list; 116, 117; 116, 118; 116, 127; 117, identifier:tag; 118, binary_operator:*; 118, 119; 118, 120; 119, string:' '; 120, parenthesized_expression; 120, 121; 121, binary_operator:-; 121, 122; 121, 123; 122, integer:4; 123, call; 123, 124; 123, 125; 124, identifier:len; 125, argument_list; 125, 126; 126, identifier:tag; 127, call; 127, 128; 127, 140; 128, attribute; 128, 129; 128, 139; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, string:' : '; 132, identifier:join; 133, argument_list; 133, 134; 134, subscript; 134, 135; 134, 136; 135, identifier:split; 136, slice; 136, 137; 136, 138; 137, integer:1; 138, colon; 139, identifier:replace; 140, argument_list; 140, 141; 140, 142; 141, string:'\n'; 142, string:'\n '; 143, for_statement; 143, 144; 143, 147; 143, 154; 144, pattern_list; 144, 145; 144, 146; 145, identifier:tag; 146, identifier:value; 147, call; 147, 148; 147, 153; 148, attribute; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:_fieldDict; 152, identifier:items; 153, argument_list; 154, block; 154, 155; 155, if_statement; 155, 156; 155, 159; 155, 161; 156, comparison_operator:in; 156, 157; 156, 158; 157, identifier:tag; 158, identifier:authorBasedTags; 159, block; 159, 160; 160, continue_statement; 161, else_clause; 161, 162; 162, block; 162, 163; 163, for_statement; 163, 164; 163, 165; 163, 166; 164, identifier:v; 165, identifier:value; 166, block; 166, 167; 166, 195; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:f; 171, identifier:write; 172, argument_list; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, string:"{0}{1}- {2}\n"; 176, identifier:format; 177, argument_list; 177, 178; 177, 179; 177, 188; 178, identifier:tag; 179, binary_operator:*; 179, 180; 179, 181; 180, string:' '; 181, parenthesized_expression; 181, 182; 182, binary_operator:-; 182, 183; 182, 184; 183, integer:4; 184, call; 184, 185; 184, 186; 185, identifier:len; 186, argument_list; 186, 187; 187, identifier:tag; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:v; 191, identifier:replace; 192, argument_list; 192, 193; 192, 194; 193, string:'\n'; 194, string:'\n '; 195, if_statement; 195, 196; 195, 199; 196, comparison_operator:==; 196, 197; 196, 198; 197, identifier:tag; 198, string:'AU'; 199, block; 199, 200; 200, for_statement; 200, 201; 200, 202; 200, 209; 201, identifier:authVal; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:authTags; 205, identifier:get; 206, argument_list; 206, 207; 206, 208; 207, identifier:v; 208, list:[]; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:f; 214, identifier:write; 215, argument_list; 215, 216; 216, identifier:authVal | def writeRecord(self, f):
if self.bad:
raise BadPubmedRecord("This record cannot be converted to a file as the input was malformed.\nThe original line number (if any) is: {} and the original file is: '{}'".format(self._sourceLine, self._sourceFile))
else:
authTags = {}
for tag in authorBasedTags:
for val in self._fieldDict.get(tag, []):
split = val.split(' : ')
try:
authTags[split[0]].append("{0}{1}- {2}\n".format(tag, ' ' * (4 - len(tag)),' : '.join(split[1:]).replace('\n', '\n ')))
except KeyError:
authTags[split[0]] = ["{0}{1}- {2}\n".format(tag, ' ' * (4 - len(tag)),' : '.join(split[1:]).replace('\n', '\n '))]
for tag, value in self._fieldDict.items():
if tag in authorBasedTags:
continue
else:
for v in value:
f.write("{0}{1}- {2}\n".format(tag, ' ' * (4 - len(tag)), v.replace('\n', '\n ')))
if tag == 'AU':
for authVal in authTags.get(v,[]):
f.write(authVal) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:graphDensityContourPlot; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:G; 5, default_parameter; 5, 6; 5, 7; 6, identifier:iters; 7, integer:50; 8, default_parameter; 8, 9; 8, 10; 9, identifier:layout; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:layoutScaleFactor; 13, integer:1; 14, default_parameter; 14, 15; 14, 16; 15, identifier:overlay; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:nodeSize; 19, integer:10; 20, default_parameter; 20, 21; 20, 22; 21, identifier:axisSamples; 22, integer:100; 23, default_parameter; 23, 24; 23, 25; 24, identifier:blurringFactor; 25, float:.1; 26, default_parameter; 26, 27; 26, 28; 27, identifier:contours; 28, integer:15; 29, default_parameter; 29, 30; 29, 31; 30, identifier:graphType; 31, string:'coloured'; 32, block; 32, 33; 32, 39; 32, 79; 32, 258; 32, 266; 32, 277; 32, 302; 32, 318; 32, 331; 32, 343; 32, 373; 32, 380; 32, 387; 33, import_from_statement; 33, 34; 33, 37; 34, dotted_name; 34, 35; 34, 36; 35, identifier:mpl_toolkits; 36, identifier:mplot3d; 37, dotted_name; 37, 38; 38, identifier:Axes3D; 39, if_statement; 39, 40; 39, 65; 40, boolean_operator:and; 40, 41; 40, 53; 41, not_operator; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 46; 45, identifier:G; 46, attribute; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:nx; 50, identifier:classes; 51, identifier:digraph; 52, identifier:DiGraph; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:G; 58, attribute; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:nx; 62, identifier:classes; 63, identifier:graph; 64, identifier:Graph; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:TypeError; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:"{} is not a valid input."; 73, identifier:format; 74, argument_list; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:type; 77, argument_list; 77, 78; 78, identifier:G; 79, if_statement; 79, 80; 79, 83; 79, 153; 79, 243; 80, comparison_operator:is; 80, 81; 80, 82; 81, identifier:layout; 82, None; 83, block; 83, 84; 83, 101; 83, 117; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:layout; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:nx; 90, identifier:spring_layout; 91, argument_list; 91, 92; 91, 93; 91, 98; 92, identifier:G; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:scale; 95, binary_operator:-; 95, 96; 95, 97; 96, identifier:axisSamples; 97, integer:1; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:iterations; 100, identifier:iters; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:grid; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:np; 107, identifier:zeros; 108, argument_list; 108, 109; 108, 112; 109, list:[axisSamples, axisSamples]; 109, 110; 109, 111; 110, identifier:axisSamples; 111, identifier:axisSamples; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:dtype; 114, attribute; 114, 115; 114, 116; 115, identifier:np; 116, identifier:float32; 117, for_statement; 117, 118; 117, 119; 117, 124; 118, identifier:v; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:layout; 122, identifier:values; 123, argument_list; 124, block; 124, 125; 124, 145; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 130; 127, pattern_list; 127, 128; 127, 129; 128, identifier:x; 129, identifier:y; 130, call; 130, 131; 130, 132; 131, identifier:tuple; 132, generator_expression; 132, 133; 132, 137; 133, call; 133, 134; 133, 135; 134, identifier:int; 135, argument_list; 135, 136; 136, identifier:x; 137, for_in_clause; 137, 138; 137, 139; 138, identifier:x; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:v; 142, identifier:round; 143, argument_list; 143, 144; 144, integer:0; 145, expression_statement; 145, 146; 146, augmented_assignment:+=; 146, 147; 146, 152; 147, subscript; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:grid; 150, identifier:y; 151, identifier:x; 152, integer:1; 153, elif_clause; 153, 154; 153, 159; 154, call; 154, 155; 154, 156; 155, identifier:isinstance; 156, argument_list; 156, 157; 156, 158; 157, identifier:layout; 158, identifier:dict; 159, block; 159, 160; 159, 168; 159, 184; 159, 193; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:layout; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:layout; 166, identifier:copy; 167, argument_list; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:grid; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:np; 174, identifier:zeros; 175, argument_list; 175, 176; 175, 179; 176, list:[axisSamples, axisSamples]; 176, 177; 176, 178; 177, identifier:axisSamples; 178, identifier:axisSamples; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:dtype; 181, attribute; 181, 182; 181, 183; 182, identifier:np; 183, identifier:float32; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:multFactor; 187, binary_operator:/; 187, 188; 187, 192; 188, parenthesized_expression; 188, 189; 189, binary_operator:-; 189, 190; 189, 191; 190, identifier:axisSamples; 191, integer:1; 192, identifier:layoutScaleFactor; 193, for_statement; 193, 194; 193, 195; 193, 200; 194, identifier:k; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:layout; 198, identifier:keys; 199, argument_list; 200, block; 200, 201; 200, 209; 200, 215; 200, 235; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:tmpPos; 204, binary_operator:*; 204, 205; 204, 208; 205, subscript; 205, 206; 205, 207; 206, identifier:layout; 207, identifier:k; 208, identifier:multFactor; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:layout; 213, identifier:k; 214, identifier:tmpPos; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 220; 217, pattern_list; 217, 218; 217, 219; 218, identifier:x; 219, identifier:y; 220, call; 220, 221; 220, 222; 221, identifier:tuple; 222, generator_expression; 222, 223; 222, 227; 223, call; 223, 224; 223, 225; 224, identifier:int; 225, argument_list; 225, 226; 226, identifier:x; 227, for_in_clause; 227, 228; 227, 229; 228, identifier:x; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:tmpPos; 232, identifier:round; 233, argument_list; 233, 234; 234, integer:0; 235, expression_statement; 235, 236; 236, augmented_assignment:+=; 236, 237; 236, 242; 237, subscript; 237, 238; 237, 241; 238, subscript; 238, 239; 238, 240; 239, identifier:grid; 240, identifier:y; 241, identifier:x; 242, integer:1; 243, else_clause; 243, 244; 244, block; 244, 245; 245, raise_statement; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:TypeError; 248, argument_list; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, string:"{} is not a valid input."; 252, identifier:format; 253, argument_list; 253, 254; 254, call; 254, 255; 254, 256; 255, identifier:type; 256, argument_list; 256, 257; 257, identifier:layout; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:fig; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:plt; 264, identifier:figure; 265, argument_list; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:axis; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:fig; 272, identifier:gca; 273, argument_list; 273, 274; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:projection; 276, string:'3d'; 277, if_statement; 277, 278; 277, 279; 278, identifier:overlay; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:nx; 284, identifier:draw_networkx; 285, argument_list; 285, 286; 285, 287; 285, 290; 285, 293; 285, 296; 285, 299; 286, identifier:G; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:pos; 289, identifier:layout; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:ax; 292, identifier:axis; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:node_size; 295, identifier:nodeSize; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:with_labels; 298, False; 299, keyword_argument; 299, 300; 299, 301; 300, identifier:edgelist; 301, list:[]; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:grid; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:ndi; 308, identifier:gaussian_filter; 309, argument_list; 309, 310; 309, 311; 310, identifier:grid; 311, tuple; 311, 312; 311, 315; 312, binary_operator:*; 312, 313; 312, 314; 313, identifier:blurringFactor; 314, identifier:axisSamples; 315, binary_operator:*; 315, 316; 315, 317; 316, identifier:blurringFactor; 317, identifier:axisSamples; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:X; 321, assignment; 321, 322; 321, 323; 322, identifier:Y; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:np; 326, identifier:arange; 327, argument_list; 327, 328; 327, 329; 327, 330; 328, integer:0; 329, identifier:axisSamples; 330, integer:1; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 336; 333, pattern_list; 333, 334; 333, 335; 334, identifier:X; 335, identifier:Y; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:np; 339, identifier:meshgrid; 340, argument_list; 340, 341; 340, 342; 341, identifier:X; 342, identifier:Y; 343, if_statement; 343, 344; 343, 347; 343, 359; 344, comparison_operator:==; 344, 345; 344, 346; 345, identifier:graphType; 346, string:"solid"; 347, block; 347, 348; 348, expression_statement; 348, 349; 349, assignment; 349, 350; 349, 351; 350, identifier:CS; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:axis; 354, identifier:plot_surface; 355, argument_list; 355, 356; 355, 357; 355, 358; 356, identifier:X; 357, identifier:Y; 358, identifier:grid; 359, else_clause; 359, 360; 360, block; 360, 361; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 364; 363, identifier:CS; 364, call; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:axis; 367, identifier:contourf; 368, argument_list; 368, 369; 368, 370; 368, 371; 368, 372; 369, identifier:X; 370, identifier:Y; 371, identifier:grid; 372, identifier:contours; 373, expression_statement; 373, 374; 374, call; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:axis; 377, identifier:set_xlabel; 378, argument_list; 378, 379; 379, string:'X'; 380, expression_statement; 380, 381; 381, call; 381, 382; 381, 385; 382, attribute; 382, 383; 382, 384; 383, identifier:axis; 384, identifier:set_ylabel; 385, argument_list; 385, 386; 386, string:'Y'; 387, expression_statement; 387, 388; 388, call; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:axis; 391, identifier:set_zlabel; 392, argument_list; 392, 393; 393, string:'Node Density' | def graphDensityContourPlot(G, iters = 50, layout = None, layoutScaleFactor = 1, overlay = False, nodeSize = 10, axisSamples = 100, blurringFactor = .1, contours = 15, graphType = 'coloured'):
from mpl_toolkits.mplot3d import Axes3D
if not isinstance(G, nx.classes.digraph.DiGraph) and not isinstance(G, nx.classes.graph.Graph):
raise TypeError("{} is not a valid input.".format(type(G)))
if layout is None:
layout = nx.spring_layout(G, scale = axisSamples - 1, iterations = iters)
grid = np.zeros( [axisSamples, axisSamples],dtype=np.float32)
for v in layout.values():
x, y = tuple(int(x) for x in v.round(0))
grid[y][x] += 1
elif isinstance(layout, dict):
layout = layout.copy()
grid = np.zeros([axisSamples, axisSamples],dtype=np.float32)
multFactor = (axisSamples - 1) / layoutScaleFactor
for k in layout.keys():
tmpPos = layout[k] * multFactor
layout[k] = tmpPos
x, y = tuple(int(x) for x in tmpPos.round(0))
grid[y][x] += 1
else:
raise TypeError("{} is not a valid input.".format(type(layout)))
fig = plt.figure()
axis = fig.gca(projection='3d')
if overlay:
nx.draw_networkx(G, pos = layout, ax = axis, node_size = nodeSize, with_labels = False, edgelist = [])
grid = ndi.gaussian_filter(grid, (blurringFactor * axisSamples, blurringFactor * axisSamples))
X = Y = np.arange(0, axisSamples, 1)
X, Y = np.meshgrid(X, Y)
if graphType == "solid":
CS = axis.plot_surface(X,Y, grid)
else:
CS = axis.contourf(X, Y, grid, contours)
axis.set_xlabel('X')
axis.set_ylabel('Y')
axis.set_zlabel('Node Density') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:makeNodeTuple; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 4, identifier:citation; 5, identifier:idVal; 6, identifier:nodeInfo; 7, identifier:fullInfo; 8, identifier:nodeType; 9, identifier:count; 10, identifier:coreCitesDict; 11, identifier:coreValues; 12, identifier:detailedValues; 13, identifier:addCR; 14, block; 14, 15; 14, 19; 14, 304; 14, 316; 14, 325; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:d; 18, dictionary; 19, if_statement; 19, 20; 19, 21; 20, identifier:nodeInfo; 21, block; 21, 22; 22, if_statement; 22, 23; 22, 26; 22, 249; 22, 282; 22, 296; 23, comparison_operator:==; 23, 24; 23, 25; 24, identifier:nodeType; 25, string:'full'; 26, block; 26, 27; 27, if_statement; 27, 28; 27, 29; 27, 237; 28, identifier:coreValues; 29, block; 29, 30; 30, if_statement; 30, 31; 30, 34; 30, 204; 31, comparison_operator:in; 31, 32; 31, 33; 32, identifier:citation; 33, identifier:coreCitesDict; 34, block; 34, 35; 34, 41; 34, 49; 34, 171; 34, 177; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:R; 38, subscript; 38, 39; 38, 40; 39, identifier:coreCitesDict; 40, identifier:citation; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:d; 45, string:'MK-ID'; 46, attribute; 46, 47; 46, 48; 47, identifier:R; 48, identifier:id; 49, if_statement; 49, 50; 49, 52; 49, 126; 50, not_operator; 50, 51; 51, identifier:detailedValues; 52, block; 52, 53; 52, 57; 52, 115; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:infoVals; 56, list:[]; 57, for_statement; 57, 58; 57, 59; 57, 60; 58, identifier:tag; 59, identifier:coreValues; 60, block; 60, 61; 60, 70; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:tagVal; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:R; 67, identifier:get; 68, argument_list; 68, 69; 69, identifier:tag; 70, if_statement; 70, 71; 70, 76; 70, 90; 70, 112; 71, call; 71, 72; 71, 73; 72, identifier:isinstance; 73, argument_list; 73, 74; 73, 75; 74, identifier:tagVal; 75, identifier:str; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:infoVals; 81, identifier:append; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:tagVal; 86, identifier:replace; 87, argument_list; 87, 88; 87, 89; 88, string:','; 89, string:''; 90, elif_clause; 90, 91; 90, 96; 91, call; 91, 92; 91, 93; 92, identifier:isinstance; 93, argument_list; 93, 94; 93, 95; 94, identifier:tagVal; 95, identifier:list; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:infoVals; 101, identifier:append; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:tagVal; 107, integer:0; 108, identifier:replace; 109, argument_list; 109, 110; 109, 111; 110, string:','; 111, string:''; 112, else_clause; 112, 113; 113, block; 113, 114; 114, pass_statement; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:d; 119, string:'info'; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, string:', '; 123, identifier:join; 124, argument_list; 124, 125; 125, identifier:infoVals; 126, else_clause; 126, 127; 127, block; 127, 128; 128, for_statement; 128, 129; 128, 130; 128, 131; 129, identifier:tag; 130, identifier:coreValues; 131, block; 131, 132; 131, 142; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:v; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:R; 138, identifier:get; 139, argument_list; 139, 140; 139, 141; 140, identifier:tag; 141, None; 142, if_statement; 142, 143; 142, 148; 142, 163; 143, call; 143, 144; 143, 145; 144, identifier:isinstance; 145, argument_list; 145, 146; 145, 147; 146, identifier:v; 147, identifier:list; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:d; 153, identifier:tag; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, string:'|'; 157, identifier:join; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 161; 160, identifier:sorted; 161, argument_list; 161, 162; 162, identifier:v; 163, else_clause; 163, 164; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:d; 169, identifier:tag; 170, identifier:v; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:d; 175, string:'inCore'; 176, True; 177, if_statement; 177, 178; 177, 179; 178, identifier:addCR; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:d; 184, string:'citations'; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, string:'|'; 188, identifier:join; 189, argument_list; 189, 190; 190, generator_expression; 190, 191; 190, 195; 191, call; 191, 192; 191, 193; 192, identifier:str; 193, argument_list; 193, 194; 194, identifier:c; 195, for_in_clause; 195, 196; 195, 197; 196, identifier:c; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:R; 200, identifier:get; 201, argument_list; 201, 202; 201, 203; 202, string:'citations'; 203, list:[]; 204, else_clause; 204, 205; 205, block; 205, 206; 205, 212; 205, 222; 205, 228; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 211; 208, subscript; 208, 209; 208, 210; 209, identifier:d; 210, string:'MK-ID'; 211, string:'None'; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:d; 216, string:'info'; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:citation; 220, identifier:allButDOI; 221, argument_list; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 227; 224, subscript; 224, 225; 224, 226; 225, identifier:d; 226, string:'inCore'; 227, False; 228, if_statement; 228, 229; 228, 230; 229, identifier:addCR; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:d; 235, string:'citations'; 236, string:''; 237, else_clause; 237, 238; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 244; 241, subscript; 241, 242; 241, 243; 242, identifier:d; 243, string:'info'; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:citation; 247, identifier:allButDOI; 248, argument_list; 249, elif_clause; 249, 250; 249, 253; 250, comparison_operator:==; 250, 251; 250, 252; 251, identifier:nodeType; 252, string:'journal'; 253, block; 253, 254; 254, if_statement; 254, 255; 254, 260; 254, 274; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:citation; 258, identifier:isJournal; 259, argument_list; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 266; 263, subscript; 263, 264; 263, 265; 264, identifier:d; 265, string:'info'; 266, call; 266, 267; 266, 268; 267, identifier:str; 268, argument_list; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:citation; 272, identifier:FullJournalName; 273, argument_list; 274, else_clause; 274, 275; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 281; 278, subscript; 278, 279; 278, 280; 279, identifier:d; 280, string:'info'; 281, string:"None"; 282, elif_clause; 282, 283; 282, 286; 283, comparison_operator:==; 283, 284; 283, 285; 284, identifier:nodeType; 285, string:'original'; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 292; 289, subscript; 289, 290; 289, 291; 290, identifier:d; 291, string:'info'; 292, call; 292, 293; 292, 294; 293, identifier:str; 294, argument_list; 294, 295; 295, identifier:citation; 296, else_clause; 296, 297; 297, block; 297, 298; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 303; 300, subscript; 300, 301; 300, 302; 301, identifier:d; 302, string:'info'; 303, identifier:idVal; 304, if_statement; 304, 305; 304, 306; 305, identifier:fullInfo; 306, block; 306, 307; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 312; 309, subscript; 309, 310; 309, 311; 310, identifier:d; 311, string:'fullCite'; 312, call; 312, 313; 312, 314; 313, identifier:str; 314, argument_list; 314, 315; 315, identifier:citation; 316, if_statement; 316, 317; 316, 318; 317, identifier:count; 318, block; 318, 319; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 324; 321, subscript; 321, 322; 321, 323; 322, identifier:d; 323, string:'count'; 324, integer:1; 325, return_statement; 325, 326; 326, tuple; 326, 327; 326, 328; 327, identifier:idVal; 328, identifier:d | def makeNodeTuple(citation, idVal, nodeInfo, fullInfo, nodeType, count, coreCitesDict, coreValues, detailedValues, addCR):
d = {}
if nodeInfo:
if nodeType == 'full':
if coreValues:
if citation in coreCitesDict:
R = coreCitesDict[citation]
d['MK-ID'] = R.id
if not detailedValues:
infoVals = []
for tag in coreValues:
tagVal = R.get(tag)
if isinstance(tagVal, str):
infoVals.append(tagVal.replace(',',''))
elif isinstance(tagVal, list):
infoVals.append(tagVal[0].replace(',',''))
else:
pass
d['info'] = ', '.join(infoVals)
else:
for tag in coreValues:
v = R.get(tag, None)
if isinstance(v, list):
d[tag] = '|'.join(sorted(v))
else:
d[tag] = v
d['inCore'] = True
if addCR:
d['citations'] = '|'.join((str(c) for c in R.get('citations', [])))
else:
d['MK-ID'] = 'None'
d['info'] = citation.allButDOI()
d['inCore'] = False
if addCR:
d['citations'] = ''
else:
d['info'] = citation.allButDOI()
elif nodeType == 'journal':
if citation.isJournal():
d['info'] = str(citation.FullJournalName())
else:
d['info'] = "None"
elif nodeType == 'original':
d['info'] = str(citation)
else:
d['info'] = idVal
if fullInfo:
d['fullCite'] = str(citation)
if count:
d['count'] = 1
return (idVal, d) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:expandRecs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:G; 5, identifier:RecCollect; 6, identifier:nodeType; 7, identifier:weighted; 8, block; 8, 9; 9, for_statement; 9, 10; 9, 11; 9, 12; 10, identifier:Rec; 11, identifier:RecCollect; 12, block; 12, 13; 12, 32; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:fullCiteList; 16, list_comprehension; 16, 17; 16, 22; 17, call; 17, 18; 17, 19; 18, identifier:makeID; 19, argument_list; 19, 20; 19, 21; 20, identifier:c; 21, identifier:nodeType; 22, for_in_clause; 22, 23; 22, 24; 23, identifier:c; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:Rec; 27, identifier:createCitation; 28, argument_list; 28, 29; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:multiCite; 31, True; 32, if_statement; 32, 33; 32, 39; 33, comparison_operator:>; 33, 34; 33, 38; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, identifier:fullCiteList; 38, integer:1; 39, block; 39, 40; 40, for_statement; 40, 41; 40, 44; 40, 48; 41, pattern_list; 41, 42; 41, 43; 42, identifier:i; 43, identifier:citeID1; 44, call; 44, 45; 44, 46; 45, identifier:enumerate; 46, argument_list; 46, 47; 47, identifier:fullCiteList; 48, block; 48, 49; 49, if_statement; 49, 50; 49, 53; 50, comparison_operator:in; 50, 51; 50, 52; 51, identifier:citeID1; 52, identifier:G; 53, block; 53, 54; 54, for_statement; 54, 55; 54, 56; 54, 63; 55, identifier:citeID2; 56, subscript; 56, 57; 56, 58; 57, identifier:fullCiteList; 58, slice; 58, 59; 58, 62; 59, binary_operator:+; 59, 60; 59, 61; 60, identifier:i; 61, integer:1; 62, colon; 63, block; 63, 64; 63, 136; 64, if_statement; 64, 65; 64, 68; 64, 106; 65, comparison_operator:not; 65, 66; 65, 67; 66, identifier:citeID2; 67, identifier:G; 68, block; 68, 69; 68, 82; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:G; 73, identifier:add_node; 74, argument_list; 74, 75; 74, 76; 75, identifier:citeID2; 76, dictionary_splat; 76, 77; 77, subscript; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:G; 80, identifier:node; 81, identifier:citeID1; 82, if_statement; 82, 83; 82, 84; 82, 96; 83, identifier:weighted; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:G; 89, identifier:add_edge; 90, argument_list; 90, 91; 90, 92; 90, 93; 91, identifier:citeID1; 92, identifier:citeID2; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:weight; 95, integer:1; 96, else_clause; 96, 97; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:G; 102, identifier:add_edge; 103, argument_list; 103, 104; 103, 105; 104, identifier:citeID1; 105, identifier:citeID2; 106, elif_clause; 106, 107; 106, 108; 107, identifier:weighted; 108, block; 108, 109; 109, try_statement; 109, 110; 109, 122; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, augmented_assignment:+=; 112, 113; 112, 121; 113, subscript; 113, 114; 113, 120; 114, subscript; 114, 115; 114, 118; 114, 119; 115, attribute; 115, 116; 115, 117; 116, identifier:G; 117, identifier:edges; 118, identifier:citeID1; 119, identifier:citeID2; 120, string:'weight'; 121, integer:1; 122, except_clause; 122, 123; 122, 124; 123, identifier:KeyError; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:G; 129, identifier:add_edge; 130, argument_list; 130, 131; 130, 132; 130, 133; 131, identifier:citeID1; 132, identifier:citeID2; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:weight; 135, integer:1; 136, for_statement; 136, 137; 136, 141; 136, 150; 137, pattern_list; 137, 138; 137, 139; 137, 140; 138, identifier:e1; 139, identifier:e2; 140, identifier:data; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:G; 144, identifier:edges; 145, argument_list; 145, 146; 145, 147; 146, identifier:citeID1; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:data; 149, True; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:G; 155, identifier:add_edge; 156, argument_list; 156, 157; 156, 158; 156, 159; 157, identifier:citeID2; 158, identifier:e2; 159, dictionary_splat; 159, 160; 160, identifier:data | def expandRecs(G, RecCollect, nodeType, weighted):
for Rec in RecCollect:
fullCiteList = [makeID(c, nodeType) for c in Rec.createCitation(multiCite = True)]
if len(fullCiteList) > 1:
for i, citeID1 in enumerate(fullCiteList):
if citeID1 in G:
for citeID2 in fullCiteList[i + 1:]:
if citeID2 not in G:
G.add_node(citeID2, **G.node[citeID1])
if weighted:
G.add_edge(citeID1, citeID2, weight = 1)
else:
G.add_edge(citeID1, citeID2)
elif weighted:
try:
G.edges[citeID1, citeID2]['weight'] += 1
except KeyError:
G.add_edge(citeID1, citeID2, weight = 1)
for e1, e2, data in G.edges(citeID1, data = True):
G.add_edge(citeID2, e2, **data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:writeBib; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:fname; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:maxStringLength; 10, integer:1000; 11, default_parameter; 11, 12; 11, 13; 12, identifier:wosMode; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:reducedOutput; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:niceIDs; 19, True; 20, block; 20, 21; 20, 60; 20, 67; 20, 123; 21, if_statement; 21, 22; 21, 23; 21, 37; 22, identifier:fname; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:f; 27, call; 27, 28; 27, 29; 28, identifier:open; 29, argument_list; 29, 30; 29, 31; 29, 34; 30, identifier:fname; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:mode; 33, string:'w'; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:encoding; 36, string:'utf-8'; 37, else_clause; 37, 38; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:f; 42, call; 42, 43; 42, 44; 43, identifier:open; 44, argument_list; 44, 45; 44, 54; 44, 57; 45, binary_operator:+; 45, 46; 45, 53; 46, subscript; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:name; 50, slice; 50, 51; 50, 52; 51, colon; 52, integer:200; 53, string:'.bib'; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:mode; 56, string:'w'; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:encoding; 59, string:'utf-8'; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:f; 64, identifier:write; 65, argument_list; 65, 66; 66, string:"%This file was generated by the metaknowledge Python package.\n%The contents have been automatically generated and are likely to not work with\n%LaTeX without some human intervention. This file is meant for other automatic\n%systems and not to be used directly for making citations\n"; 67, for_statement; 67, 68; 67, 69; 67, 70; 68, identifier:R; 69, identifier:self; 70, block; 70, 71; 71, try_statement; 71, 72; 71, 103; 71, 107; 72, block; 72, 73; 72, 80; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:f; 77, identifier:write; 78, argument_list; 78, 79; 79, string:'\n\n'; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:f; 84, identifier:write; 85, argument_list; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:R; 89, identifier:bibString; 90, argument_list; 90, 91; 90, 94; 90, 97; 90, 100; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:maxLength; 93, identifier:maxStringLength; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:WOSMode; 96, identifier:wosMode; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:restrictedOutput; 99, identifier:reducedOutput; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:niceID; 102, identifier:niceIDs; 103, except_clause; 103, 104; 103, 105; 104, identifier:BadWOSRecord; 105, block; 105, 106; 106, pass_statement; 107, except_clause; 107, 108; 107, 109; 108, identifier:AttributeError; 109, block; 109, 110; 110, raise_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:RecordsNotCompatible; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, string:"The Record '{}', with ID '{}' does not support writing to bibtext files."; 117, identifier:format; 118, argument_list; 118, 119; 118, 120; 119, identifier:R; 120, attribute; 120, 121; 120, 122; 121, identifier:R; 122, identifier:id; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:f; 127, identifier:close; 128, argument_list | def writeBib(self, fname = None, maxStringLength = 1000, wosMode = False, reducedOutput = False, niceIDs = True):
if fname:
f = open(fname, mode = 'w', encoding = 'utf-8')
else:
f = open(self.name[:200] + '.bib', mode = 'w', encoding = 'utf-8')
f.write("%This file was generated by the metaknowledge Python package.\n%The contents have been automatically generated and are likely to not work with\n%LaTeX without some human intervention. This file is meant for other automatic\n%systems and not to be used directly for making citations\n")
for R in self:
try:
f.write('\n\n')
f.write(R.bibString(maxLength = maxStringLength, WOSMode = wosMode, restrictedOutput = reducedOutput, niceID = niceIDs))
except BadWOSRecord:
pass
except AttributeError:
raise RecordsNotCompatible("The Record '{}', with ID '{}' does not support writing to bibtext files.".format(R, R.id))
f.close() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:makeDict; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:onlyTheseTags; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:longNames; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:raw; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:numAuthors; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:genderCounts; 19, True; 20, block; 20, 21; 20, 85; 20, 108; 20, 118; 20, 127; 20, 146; 20, 242; 21, if_statement; 21, 22; 21, 23; 21, 55; 22, identifier:onlyTheseTags; 23, block; 23, 24; 23, 51; 24, for_statement; 24, 25; 24, 26; 24, 33; 25, identifier:i; 26, call; 26, 27; 26, 28; 27, identifier:range; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, identifier:onlyTheseTags; 33, block; 33, 34; 34, if_statement; 34, 35; 34, 40; 35, comparison_operator:in; 35, 36; 35, 39; 36, subscript; 36, 37; 36, 38; 37, identifier:onlyTheseTags; 38, identifier:i; 39, identifier:fullToTagDict; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:onlyTheseTags; 45, identifier:i; 46, subscript; 46, 47; 46, 48; 47, identifier:fullToTagDict; 48, subscript; 48, 49; 48, 50; 49, identifier:onlyTheseTags; 50, identifier:i; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:retrievedFields; 54, identifier:onlyTheseTags; 55, else_clause; 55, 56; 56, block; 56, 57; 56, 61; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:retrievedFields; 60, list:[]; 61, for_statement; 61, 62; 61, 63; 61, 64; 62, identifier:R; 63, identifier:self; 64, block; 64, 65; 64, 81; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:tagsLst; 68, list_comprehension; 68, 69; 68, 70; 68, 77; 69, identifier:t; 70, for_in_clause; 70, 71; 70, 72; 71, identifier:t; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:R; 75, identifier:keys; 76, argument_list; 77, if_clause; 77, 78; 78, comparison_operator:not; 78, 79; 78, 80; 79, identifier:t; 80, identifier:retrievedFields; 81, expression_statement; 81, 82; 82, augmented_assignment:+=; 82, 83; 82, 84; 83, identifier:retrievedFields; 84, identifier:tagsLst; 85, if_statement; 85, 86; 85, 87; 86, identifier:longNames; 87, block; 87, 88; 88, try_statement; 88, 89; 88, 100; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:retrievedFields; 93, list_comprehension; 93, 94; 93, 97; 94, subscript; 94, 95; 94, 96; 95, identifier:tagToFullDict; 96, identifier:t; 97, for_in_clause; 97, 98; 97, 99; 98, identifier:t; 99, identifier:retrievedFields; 100, except_clause; 100, 101; 100, 102; 101, identifier:KeyError; 102, block; 102, 103; 103, raise_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:KeyError; 106, argument_list; 106, 107; 107, string:"One of the tags could not be converted to a long name."; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:retDict; 111, dictionary_comprehension; 111, 112; 111, 115; 112, pair; 112, 113; 112, 114; 113, identifier:k; 114, list:[]; 115, for_in_clause; 115, 116; 115, 117; 116, identifier:k; 117, identifier:retrievedFields; 118, if_statement; 118, 119; 118, 120; 119, identifier:numAuthors; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 126; 123, subscript; 123, 124; 123, 125; 124, identifier:retDict; 125, string:"num-Authors"; 126, list:[]; 127, if_statement; 127, 128; 127, 129; 128, identifier:genderCounts; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:retDict; 134, identifier:update; 135, argument_list; 135, 136; 136, dictionary; 136, 137; 136, 140; 136, 143; 137, pair; 137, 138; 137, 139; 138, string:'num-Male'; 139, list:[]; 140, pair; 140, 141; 140, 142; 141, string:'num-Female'; 142, list:[]; 143, pair; 143, 144; 143, 145; 144, string:'num-Unknown'; 145, list:[]; 146, for_statement; 146, 147; 146, 148; 146, 149; 147, identifier:R; 148, identifier:self; 149, block; 149, 150; 149, 171; 149, 215; 150, if_statement; 150, 151; 150, 152; 151, identifier:numAuthors; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 160; 155, attribute; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:retDict; 158, string:"num-Authors"; 159, identifier:append; 160, argument_list; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:len; 163, argument_list; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:R; 167, identifier:get; 168, argument_list; 168, 169; 168, 170; 169, string:'authorsShort'; 170, list:[]; 171, if_statement; 171, 172; 171, 173; 172, identifier:genderCounts; 173, block; 173, 174; 173, 188; 173, 197; 173, 206; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 180; 176, pattern_list; 176, 177; 176, 178; 176, 179; 177, identifier:m; 178, identifier:f; 179, identifier:u; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:R; 183, identifier:authGenders; 184, argument_list; 184, 185; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:_countsTuple; 187, True; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 195; 190, attribute; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:retDict; 193, string:'num-Male'; 194, identifier:append; 195, argument_list; 195, 196; 196, identifier:m; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 204; 199, attribute; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:retDict; 202, string:'num-Female'; 203, identifier:append; 204, argument_list; 204, 205; 205, identifier:f; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 213; 208, attribute; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:retDict; 211, string:'num-Unknown'; 212, identifier:append; 213, argument_list; 213, 214; 214, identifier:u; 215, for_statement; 215, 216; 215, 219; 215, 232; 216, pattern_list; 216, 217; 216, 218; 217, identifier:k; 218, identifier:v; 219, call; 219, 220; 219, 231; 220, attribute; 220, 221; 220, 230; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:R; 224, identifier:subDict; 225, argument_list; 225, 226; 225, 227; 226, identifier:retrievedFields; 227, keyword_argument; 227, 228; 227, 229; 228, identifier:raw; 229, identifier:raw; 230, identifier:items; 231, argument_list; 232, block; 232, 233; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 240; 235, attribute; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:retDict; 238, identifier:k; 239, identifier:append; 240, argument_list; 240, 241; 241, identifier:v; 242, return_statement; 242, 243; 243, identifier:retDict | def makeDict(self, onlyTheseTags = None, longNames = False, raw = False, numAuthors = True, genderCounts = True):
if onlyTheseTags:
for i in range(len(onlyTheseTags)):
if onlyTheseTags[i] in fullToTagDict:
onlyTheseTags[i] = fullToTagDict[onlyTheseTags[i]]
retrievedFields = onlyTheseTags
else:
retrievedFields = []
for R in self:
tagsLst = [t for t in R.keys() if t not in retrievedFields]
retrievedFields += tagsLst
if longNames:
try:
retrievedFields = [tagToFullDict[t] for t in retrievedFields]
except KeyError:
raise KeyError("One of the tags could not be converted to a long name.")
retDict = {k : [] for k in retrievedFields}
if numAuthors:
retDict["num-Authors"] = []
if genderCounts:
retDict.update({'num-Male' : [], 'num-Female' : [], 'num-Unknown' : []})
for R in self:
if numAuthors:
retDict["num-Authors"].append(len(R.get('authorsShort', [])))
if genderCounts:
m, f, u = R.authGenders(_countsTuple = True)
retDict['num-Male'].append(m)
retDict['num-Female'].append(f)
retDict['num-Unknown'].append(u)
for k, v in R.subDict(retrievedFields, raw = raw).items():
retDict[k].append(v)
return retDict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 44; 2, function_name:networkCoCitation; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 3, 41; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:dropAnon; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:nodeType; 10, string:"full"; 11, default_parameter; 11, 12; 11, 13; 12, identifier:nodeInfo; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:fullInfo; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:weighted; 19, True; 20, default_parameter; 20, 21; 20, 22; 21, identifier:dropNonJournals; 22, False; 23, default_parameter; 23, 24; 23, 25; 24, identifier:count; 25, True; 26, default_parameter; 26, 27; 26, 28; 27, identifier:keyWords; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:detailedCore; 31, True; 32, default_parameter; 32, 33; 32, 34; 33, identifier:detailedCoreAttributes; 34, False; 35, default_parameter; 35, 36; 35, 37; 36, identifier:coreOnly; 37, False; 38, default_parameter; 38, 39; 38, 40; 39, identifier:expandedCore; 40, False; 41, default_parameter; 41, 42; 41, 43; 42, identifier:addCR; 43, False; 44, block; 44, 45; 44, 54; 44, 69; 44, 73; 44, 109; 44, 117; 44, 121; 44, 127; 44, 148; 44, 318; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:allowedTypes; 48, list:["full", "original", "author", "journal", "year"]; 48, 49; 48, 50; 48, 51; 48, 52; 48, 53; 49, string:"full"; 50, string:"original"; 51, string:"author"; 52, string:"journal"; 53, string:"year"; 54, if_statement; 54, 55; 54, 58; 55, comparison_operator:not; 55, 56; 55, 57; 56, identifier:nodeType; 57, identifier:allowedTypes; 58, block; 58, 59; 59, raise_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:RCValueError; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, string:"{} is not an allowed nodeType."; 66, identifier:format; 67, argument_list; 67, 68; 68, identifier:nodeType; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:coreValues; 72, list:[]; 73, if_statement; 73, 74; 73, 78; 74, call; 74, 75; 74, 76; 75, identifier:bool; 76, argument_list; 76, 77; 77, identifier:detailedCore; 78, block; 78, 79; 79, try_statement; 79, 80; 79, 95; 80, block; 80, 81; 81, for_statement; 81, 82; 81, 83; 81, 84; 82, identifier:tag; 83, identifier:detailedCore; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:coreValues; 89, identifier:append; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:normalizeToTag; 93, argument_list; 93, 94; 94, identifier:tag; 95, except_clause; 95, 96; 95, 97; 96, identifier:TypeError; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:coreValues; 101, list:['id', 'authorsFull', 'year', 'title', 'journal', 'volume', 'beginningPage']; 101, 102; 101, 103; 101, 104; 101, 105; 101, 106; 101, 107; 101, 108; 102, string:'id'; 103, string:'authorsFull'; 104, string:'year'; 105, string:'title'; 106, string:'journal'; 107, string:'volume'; 108, string:'beginningPage'; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:tmpgrph; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:nx; 115, identifier:Graph; 116, argument_list; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:pcount; 120, integer:0; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:progArgs; 124, tuple; 124, 125; 124, 126; 125, integer:0; 126, string:"Starting to make a co-citation network"; 127, if_statement; 127, 128; 127, 131; 127, 139; 128, attribute; 128, 129; 128, 130; 129, identifier:metaknowledge; 130, identifier:VERBOSE_MODE; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:progKwargs; 135, dictionary; 135, 136; 136, pair; 136, 137; 136, 138; 137, string:'dummy'; 138, False; 139, else_clause; 139, 140; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:progKwargs; 144, dictionary; 144, 145; 145, pair; 145, 146; 145, 147; 146, string:'dummy'; 147, True; 148, with_statement; 148, 149; 148, 161; 149, with_clause; 149, 150; 150, with_item; 150, 151; 151, as_pattern; 151, 152; 151, 159; 152, call; 152, 153; 152, 154; 153, identifier:_ProgressBar; 154, argument_list; 154, 155; 154, 157; 155, list_splat; 155, 156; 156, identifier:progArgs; 157, dictionary_splat; 157, 158; 158, identifier:progKwargs; 159, as_pattern_target; 159, 160; 160, identifier:PBar; 161, block; 161, 162; 161, 210; 161, 281; 161, 303; 162, if_statement; 162, 163; 162, 168; 162, 200; 163, boolean_operator:or; 163, 164; 163, 167; 164, boolean_operator:or; 164, 165; 164, 166; 165, identifier:coreOnly; 166, identifier:coreValues; 167, identifier:expandedCore; 168, block; 168, 169; 168, 183; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:coreCitesDict; 172, dictionary_comprehension; 172, 173; 172, 180; 173, pair; 173, 174; 173, 179; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:R; 177, identifier:createCitation; 178, argument_list; 179, identifier:R; 180, for_in_clause; 180, 181; 180, 182; 181, identifier:R; 182, identifier:self; 183, if_statement; 183, 184; 183, 185; 183, 194; 184, identifier:coreOnly; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:coreCites; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:coreCitesDict; 192, identifier:keys; 193, argument_list; 194, else_clause; 194, 195; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:coreCites; 199, None; 200, else_clause; 200, 201; 201, block; 201, 202; 201, 206; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:coreCitesDict; 205, None; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:coreCites; 209, None; 210, for_statement; 210, 211; 210, 212; 210, 213; 211, identifier:R; 212, identifier:self; 213, block; 213, 214; 213, 239; 213, 248; 214, if_statement; 214, 215; 214, 216; 215, identifier:PBar; 216, block; 216, 217; 216, 221; 217, expression_statement; 217, 218; 218, augmented_assignment:+=; 218, 219; 218, 220; 219, identifier:pcount; 220, integer:1; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:PBar; 225, identifier:updateVal; 226, argument_list; 226, 227; 226, 233; 227, binary_operator:/; 227, 228; 227, 229; 228, identifier:pcount; 229, call; 229, 230; 229, 231; 230, identifier:len; 231, argument_list; 231, 232; 232, identifier:self; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, string:"Analyzing: {}"; 236, identifier:format; 237, argument_list; 237, 238; 238, identifier:R; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:Cites; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:R; 245, identifier:get; 246, argument_list; 246, 247; 247, string:'citations'; 248, if_statement; 248, 249; 248, 250; 249, identifier:Cites; 250, block; 250, 251; 250, 263; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:filteredCites; 254, call; 254, 255; 254, 256; 255, identifier:filterCites; 256, argument_list; 256, 257; 256, 258; 256, 259; 256, 260; 256, 261; 256, 262; 257, identifier:Cites; 258, identifier:nodeType; 259, identifier:dropAnon; 260, identifier:dropNonJournals; 261, identifier:keyWords; 262, identifier:coreCites; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 266; 265, identifier:addToNetwork; 266, argument_list; 266, 267; 266, 268; 266, 269; 266, 270; 266, 271; 266, 272; 266, 273; 266, 274; 266, 275; 266, 276; 266, 277; 266, 278; 267, identifier:tmpgrph; 268, identifier:filteredCites; 269, identifier:count; 270, identifier:weighted; 271, identifier:nodeType; 272, identifier:nodeInfo; 273, identifier:fullInfo; 274, identifier:coreCitesDict; 275, identifier:coreValues; 276, identifier:detailedCoreAttributes; 277, identifier:addCR; 278, keyword_argument; 278, 279; 278, 280; 279, identifier:headNd; 280, None; 281, if_statement; 281, 282; 281, 283; 282, identifier:expandedCore; 283, block; 283, 284; 283, 295; 284, if_statement; 284, 285; 284, 286; 285, identifier:PBar; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:PBar; 291, identifier:updateVal; 292, argument_list; 292, 293; 292, 294; 293, float:.98; 294, string:"Expanding core Records"; 295, expression_statement; 295, 296; 296, call; 296, 297; 296, 298; 297, identifier:expandRecs; 298, argument_list; 298, 299; 298, 300; 298, 301; 298, 302; 299, identifier:tmpgrph; 300, identifier:self; 301, identifier:nodeType; 302, identifier:weighted; 303, if_statement; 303, 304; 303, 305; 304, identifier:PBar; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:PBar; 310, identifier:finish; 311, argument_list; 311, 312; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, string:"Done making a co-citation network from {}"; 315, identifier:format; 316, argument_list; 316, 317; 317, identifier:self; 318, return_statement; 318, 319; 319, identifier:tmpgrph | def networkCoCitation(self, dropAnon = True, nodeType = "full", nodeInfo = True, fullInfo = False, weighted = True, dropNonJournals = False, count = True, keyWords = None, detailedCore = True, detailedCoreAttributes = False, coreOnly = False, expandedCore = False, addCR = False):
allowedTypes = ["full", "original", "author", "journal", "year"]
if nodeType not in allowedTypes:
raise RCValueError("{} is not an allowed nodeType.".format(nodeType))
coreValues = []
if bool(detailedCore):
try:
for tag in detailedCore:
coreValues.append(normalizeToTag(tag))
except TypeError:
coreValues = ['id', 'authorsFull', 'year', 'title', 'journal', 'volume', 'beginningPage']
tmpgrph = nx.Graph()
pcount = 0
progArgs = (0, "Starting to make a co-citation network")
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
if coreOnly or coreValues or expandedCore:
coreCitesDict = {R.createCitation() : R for R in self}
if coreOnly:
coreCites = coreCitesDict.keys()
else:
coreCites = None
else:
coreCitesDict = None
coreCites = None
for R in self:
if PBar:
pcount += 1
PBar.updateVal(pcount / len(self), "Analyzing: {}".format(R))
Cites = R.get('citations')
if Cites:
filteredCites = filterCites(Cites, nodeType, dropAnon, dropNonJournals, keyWords, coreCites)
addToNetwork(tmpgrph, filteredCites, count, weighted, nodeType, nodeInfo , fullInfo, coreCitesDict, coreValues, detailedCoreAttributes, addCR, headNd = None)
if expandedCore:
if PBar:
PBar.updateVal(.98, "Expanding core Records")
expandRecs(tmpgrph, self, nodeType, weighted)
if PBar:
PBar.finish("Done making a co-citation network from {}".format(self))
return tmpgrph |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:networkBibCoupling; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:weighted; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:fullInfo; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:addCR; 13, False; 14, block; 14, 15; 14, 21; 14, 42; 14, 325; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:progArgs; 18, tuple; 18, 19; 18, 20; 19, integer:0; 20, string:"Make a citation network for coupling"; 21, if_statement; 21, 22; 21, 25; 21, 33; 22, attribute; 22, 23; 22, 24; 23, identifier:metaknowledge; 24, identifier:VERBOSE_MODE; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:progKwargs; 29, dictionary; 29, 30; 30, pair; 30, 31; 30, 32; 31, string:'dummy'; 32, False; 33, else_clause; 33, 34; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:progKwargs; 38, dictionary; 38, 39; 39, pair; 39, 40; 39, 41; 40, string:'dummy'; 41, True; 42, with_statement; 42, 43; 42, 55; 43, with_clause; 43, 44; 44, with_item; 44, 45; 45, as_pattern; 45, 46; 45, 53; 46, call; 46, 47; 46, 48; 47, identifier:_ProgressBar; 48, argument_list; 48, 49; 48, 51; 49, list_splat; 49, 50; 50, identifier:progArgs; 51, dictionary_splat; 51, 52; 52, identifier:progKwargs; 53, as_pattern_target; 53, 54; 54, identifier:PBar; 55, block; 55, 56; 55, 88; 55, 92; 55, 99; 55, 107; 55, 115; 55, 121; 55, 189; 55, 193; 55, 200; 55, 313; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:citeGrph; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:networkCitation; 63, argument_list; 63, 64; 63, 67; 63, 70; 63, 73; 63, 76; 63, 79; 63, 82; 63, 85; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:weighted; 66, False; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:directed; 69, True; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:detailedCore; 72, True; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:fullInfo; 75, identifier:fullInfo; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:count; 78, False; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:nodeInfo; 81, True; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:addCR; 84, identifier:addCR; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:_quiet; 87, True; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:pcount; 91, integer:0; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:pmax; 95, call; 95, 96; 95, 97; 96, identifier:len; 97, argument_list; 97, 98; 98, identifier:citeGrph; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:PBar; 103, identifier:updateVal; 104, argument_list; 104, 105; 104, 106; 105, float:.2; 106, string:"Starting to classify nodes"; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:workingGrph; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:nx; 113, identifier:Graph; 114, argument_list; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:couplingSet; 118, call; 118, 119; 118, 120; 119, identifier:set; 120, argument_list; 121, for_statement; 121, 122; 121, 125; 121, 133; 122, pattern_list; 122, 123; 122, 124; 123, identifier:n; 124, identifier:d; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:citeGrph; 128, identifier:nodes; 129, argument_list; 129, 130; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:data; 132, True; 133, block; 133, 134; 133, 138; 133, 158; 133, 172; 134, expression_statement; 134, 135; 135, augmented_assignment:+=; 135, 136; 135, 137; 136, identifier:pcount; 137, integer:1; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:PBar; 142, identifier:updateVal; 143, argument_list; 143, 144; 143, 152; 144, binary_operator:+; 144, 145; 144, 146; 145, float:.2; 146, binary_operator:*; 146, 147; 146, 148; 147, float:.4; 148, parenthesized_expression; 148, 149; 149, binary_operator:/; 149, 150; 149, 151; 150, identifier:pcount; 151, identifier:pmax; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, string:"Classifying: {}"; 155, identifier:format; 156, argument_list; 156, 157; 157, identifier:n; 158, if_statement; 158, 159; 158, 162; 159, subscript; 159, 160; 159, 161; 160, identifier:d; 161, string:'inCore'; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:workingGrph; 167, identifier:add_node; 168, argument_list; 168, 169; 168, 170; 169, identifier:n; 170, dictionary_splat; 170, 171; 171, identifier:d; 172, if_statement; 172, 173; 172, 181; 173, comparison_operator:>; 173, 174; 173, 180; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:citeGrph; 177, identifier:in_degree; 178, argument_list; 178, 179; 179, identifier:n; 180, integer:0; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:couplingSet; 186, identifier:add; 187, argument_list; 187, 188; 188, identifier:n; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:pcount; 192, integer:0; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:pmax; 196, call; 196, 197; 196, 198; 197, identifier:len; 198, argument_list; 198, 199; 199, identifier:couplingSet; 200, for_statement; 200, 201; 200, 202; 200, 203; 201, identifier:n; 202, identifier:couplingSet; 203, block; 203, 204; 203, 224; 203, 236; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:PBar; 208, identifier:updateVal; 209, argument_list; 209, 210; 209, 218; 210, binary_operator:+; 210, 211; 210, 212; 211, float:.6; 212, binary_operator:*; 212, 213; 212, 214; 213, float:.4; 214, parenthesized_expression; 214, 215; 215, binary_operator:/; 215, 216; 215, 217; 216, identifier:pcount; 217, identifier:pmax; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, string:"Coupling: {}"; 221, identifier:format; 222, argument_list; 222, 223; 223, identifier:n; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:citesLst; 227, call; 227, 228; 227, 229; 228, identifier:list; 229, argument_list; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:citeGrph; 233, identifier:in_edges; 234, argument_list; 234, 235; 235, identifier:n; 236, for_statement; 236, 237; 236, 240; 236, 244; 237, pattern_list; 237, 238; 237, 239; 238, identifier:i; 239, identifier:edgeOuter; 240, call; 240, 241; 240, 242; 241, identifier:enumerate; 242, argument_list; 242, 243; 243, identifier:citesLst; 244, block; 244, 245; 244, 251; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:outerNode; 248, subscript; 248, 249; 248, 250; 249, identifier:edgeOuter; 250, integer:0; 251, for_statement; 251, 252; 251, 253; 251, 260; 252, identifier:edgeInner; 253, subscript; 253, 254; 253, 255; 254, identifier:citesLst; 255, slice; 255, 256; 255, 259; 256, binary_operator:+; 256, 257; 256, 258; 257, identifier:i; 258, integer:1; 259, colon; 260, block; 260, 261; 260, 267; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:innerNode; 264, subscript; 264, 265; 264, 266; 265, identifier:edgeInner; 266, integer:0; 267, if_statement; 267, 268; 267, 277; 267, 289; 267, 303; 268, boolean_operator:and; 268, 269; 268, 270; 269, identifier:weighted; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:workingGrph; 273, identifier:has_edge; 274, argument_list; 274, 275; 274, 276; 275, identifier:outerNode; 276, identifier:innerNode; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, augmented_assignment:+=; 279, 280; 279, 288; 280, subscript; 280, 281; 280, 287; 281, subscript; 281, 282; 281, 285; 281, 286; 282, attribute; 282, 283; 282, 284; 283, identifier:workingGrph; 284, identifier:edges; 285, identifier:outerNode; 286, identifier:innerNode; 287, string:'weight'; 288, integer:1; 289, elif_clause; 289, 290; 289, 291; 290, identifier:weighted; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:workingGrph; 296, identifier:add_edge; 297, argument_list; 297, 298; 297, 299; 297, 300; 298, identifier:outerNode; 299, identifier:innerNode; 300, keyword_argument; 300, 301; 300, 302; 301, identifier:weight; 302, integer:1; 303, else_clause; 303, 304; 304, block; 304, 305; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:workingGrph; 309, identifier:add_edge; 310, argument_list; 310, 311; 310, 312; 311, identifier:outerNode; 312, identifier:innerNode; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:PBar; 317, identifier:finish; 318, argument_list; 318, 319; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, string:"Done making a bib-coupling network from {}"; 322, identifier:format; 323, argument_list; 323, 324; 324, identifier:self; 325, return_statement; 325, 326; 326, identifier:workingGrph | def networkBibCoupling(self, weighted = True, fullInfo = False, addCR = False):
progArgs = (0, "Make a citation network for coupling")
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
citeGrph = self.networkCitation(weighted = False, directed = True, detailedCore = True, fullInfo = fullInfo, count = False, nodeInfo = True, addCR = addCR, _quiet = True)
pcount = 0
pmax = len(citeGrph)
PBar.updateVal(.2, "Starting to classify nodes")
workingGrph = nx.Graph()
couplingSet = set()
for n, d in citeGrph.nodes(data = True):
pcount += 1
PBar.updateVal(.2 + .4 * (pcount / pmax), "Classifying: {}".format(n))
if d['inCore']:
workingGrph.add_node(n, **d)
if citeGrph.in_degree(n) > 0:
couplingSet.add(n)
pcount = 0
pmax = len(couplingSet)
for n in couplingSet:
PBar.updateVal(.6 + .4 * (pcount / pmax), "Coupling: {}".format(n))
citesLst = list(citeGrph.in_edges(n))
for i, edgeOuter in enumerate(citesLst):
outerNode = edgeOuter[0]
for edgeInner in citesLst[i + 1:]:
innerNode = edgeInner[0]
if weighted and workingGrph.has_edge(outerNode, innerNode):
workingGrph.edges[outerNode, innerNode]['weight'] += 1
elif weighted:
workingGrph.add_edge(outerNode, innerNode, weight = 1)
else:
workingGrph.add_edge(outerNode, innerNode)
PBar.finish("Done making a bib-coupling network from {}".format(self))
return workingGrph |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:localCiteStats; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:pandasFriendly; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:keyType; 10, string:"citation"; 11, block; 11, 12; 11, 16; 11, 23; 11, 34; 11, 55; 11, 220; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:count; 15, integer:0; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:recCount; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, identifier:self; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:progArgs; 26, tuple; 26, 27; 26, 28; 27, integer:0; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, string:"Starting to get the local stats on {}s."; 31, identifier:format; 32, argument_list; 32, 33; 33, identifier:keyType; 34, if_statement; 34, 35; 34, 38; 34, 46; 35, attribute; 35, 36; 35, 37; 36, identifier:metaknowledge; 37, identifier:VERBOSE_MODE; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:progKwargs; 42, dictionary; 42, 43; 43, pair; 43, 44; 43, 45; 44, string:'dummy'; 45, False; 46, else_clause; 46, 47; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:progKwargs; 51, dictionary; 51, 52; 52, pair; 52, 53; 52, 54; 53, string:'dummy'; 54, True; 55, with_statement; 55, 56; 55, 68; 56, with_clause; 56, 57; 57, with_item; 57, 58; 58, as_pattern; 58, 59; 58, 66; 59, call; 59, 60; 59, 61; 60, identifier:_ProgressBar; 61, argument_list; 61, 62; 61, 64; 62, list_splat; 62, 63; 63, identifier:progArgs; 64, dictionary_splat; 64, 65; 65, identifier:progKwargs; 66, as_pattern_target; 66, 67; 67, identifier:PBar; 68, block; 68, 69; 68, 77; 68, 81; 68, 111; 68, 201; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:keyTypesLst; 72, list:["citation", "journal", "year", "author"]; 72, 73; 72, 74; 72, 75; 72, 76; 73, string:"citation"; 74, string:"journal"; 75, string:"year"; 76, string:"author"; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:citesDict; 80, dictionary; 81, if_statement; 81, 82; 81, 85; 82, comparison_operator:not; 82, 83; 82, 84; 83, identifier:keyType; 84, identifier:keyTypesLst; 85, block; 85, 86; 86, raise_statement; 86, 87; 87, call; 87, 88; 87, 89; 88, identifier:TypeError; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, string:"{} is not a valid key type, only '{}' or '{}' are."; 93, identifier:format; 94, argument_list; 94, 95; 94, 96; 94, 107; 95, identifier:keyType; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, string:"', '"; 99, identifier:join; 100, argument_list; 100, 101; 101, subscript; 101, 102; 101, 103; 102, identifier:keyTypesLst; 103, slice; 103, 104; 103, 105; 104, colon; 105, unary_operator:-; 105, 106; 106, integer:1; 107, subscript; 107, 108; 107, 109; 108, identifier:keyTypesLst; 109, unary_operator:-; 109, 110; 110, integer:1; 111, for_statement; 111, 112; 111, 113; 111, 114; 112, identifier:R; 113, identifier:self; 114, block; 114, 115; 114, 124; 114, 148; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:rCites; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:R; 121, identifier:get; 122, argument_list; 122, 123; 123, string:'citations'; 124, if_statement; 124, 125; 124, 126; 125, identifier:PBar; 126, block; 126, 127; 126, 131; 127, expression_statement; 127, 128; 128, augmented_assignment:+=; 128, 129; 128, 130; 129, identifier:count; 130, integer:1; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:PBar; 135, identifier:updateVal; 136, argument_list; 136, 137; 136, 140; 137, binary_operator:/; 137, 138; 137, 139; 138, identifier:count; 139, identifier:recCount; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, string:"Analysing: {}"; 143, identifier:format; 144, argument_list; 144, 145; 145, attribute; 145, 146; 145, 147; 146, identifier:R; 147, identifier:UT; 148, if_statement; 148, 149; 148, 150; 149, identifier:rCites; 150, block; 150, 151; 151, for_statement; 151, 152; 151, 153; 151, 154; 152, identifier:c; 153, identifier:rCites; 154, block; 154, 155; 154, 182; 155, if_statement; 155, 156; 155, 161; 155, 166; 156, comparison_operator:==; 156, 157; 156, 158; 157, identifier:keyType; 158, subscript; 158, 159; 158, 160; 159, identifier:keyTypesLst; 160, integer:0; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:cVal; 165, identifier:c; 166, else_clause; 166, 167; 167, block; 167, 168; 167, 176; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:cVal; 171, call; 171, 172; 171, 173; 172, identifier:getattr; 173, argument_list; 173, 174; 173, 175; 174, identifier:c; 175, identifier:keyType; 176, if_statement; 176, 177; 176, 180; 177, comparison_operator:is; 177, 178; 177, 179; 178, identifier:cVal; 179, None; 180, block; 180, 181; 181, continue_statement; 182, if_statement; 182, 183; 182, 186; 182, 193; 183, comparison_operator:in; 183, 184; 183, 185; 184, identifier:cVal; 185, identifier:citesDict; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, augmented_assignment:+=; 188, 189; 188, 192; 189, subscript; 189, 190; 189, 191; 190, identifier:citesDict; 191, identifier:cVal; 192, integer:1; 193, else_clause; 193, 194; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:citesDict; 199, identifier:cVal; 200, integer:1; 201, if_statement; 201, 202; 201, 203; 202, identifier:PBar; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:PBar; 208, identifier:finish; 209, argument_list; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, string:"Done, {} {} fields analysed"; 213, identifier:format; 214, argument_list; 214, 215; 214, 219; 215, call; 215, 216; 215, 217; 216, identifier:len; 217, argument_list; 217, 218; 218, identifier:citesDict; 219, identifier:keyType; 220, if_statement; 220, 221; 220, 222; 220, 263; 221, identifier:pandasFriendly; 222, block; 222, 223; 222, 227; 222, 231; 222, 255; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:citeLst; 226, list:[]; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:countLst; 230, list:[]; 231, for_statement; 231, 232; 231, 235; 231, 240; 232, pattern_list; 232, 233; 232, 234; 233, identifier:cite; 234, identifier:occ; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:citesDict; 238, identifier:items; 239, argument_list; 240, block; 240, 241; 240, 248; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:citeLst; 245, identifier:append; 246, argument_list; 246, 247; 247, identifier:cite; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:countLst; 252, identifier:append; 253, argument_list; 253, 254; 254, identifier:occ; 255, return_statement; 255, 256; 256, dictionary; 256, 257; 256, 260; 257, pair; 257, 258; 257, 259; 258, string:"Citations"; 259, identifier:citeLst; 260, pair; 260, 261; 260, 262; 261, string:"Counts"; 262, identifier:countLst; 263, else_clause; 263, 264; 264, block; 264, 265; 265, return_statement; 265, 266; 266, identifier:citesDict | def localCiteStats(self, pandasFriendly = False, keyType = "citation"):
count = 0
recCount = len(self)
progArgs = (0, "Starting to get the local stats on {}s.".format(keyType))
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
keyTypesLst = ["citation", "journal", "year", "author"]
citesDict = {}
if keyType not in keyTypesLst:
raise TypeError("{} is not a valid key type, only '{}' or '{}' are.".format(keyType, "', '".join(keyTypesLst[:-1]), keyTypesLst[-1]))
for R in self:
rCites = R.get('citations')
if PBar:
count += 1
PBar.updateVal(count / recCount, "Analysing: {}".format(R.UT))
if rCites:
for c in rCites:
if keyType == keyTypesLst[0]:
cVal = c
else:
cVal = getattr(c, keyType)
if cVal is None:
continue
if cVal in citesDict:
citesDict[cVal] += 1
else:
citesDict[cVal] = 1
if PBar:
PBar.finish("Done, {} {} fields analysed".format(len(citesDict), keyType))
if pandasFriendly:
citeLst = []
countLst = []
for cite, occ in citesDict.items():
citeLst.append(cite)
countLst.append(occ)
return {"Citations" : citeLst, "Counts" : countLst}
else:
return citesDict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:citeFilter; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:keyString; 7, string:''; 8, default_parameter; 8, 9; 8, 10; 9, identifier:field; 10, string:'all'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:reverse; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:caseSensitive; 16, False; 17, block; 17, 18; 17, 22; 17, 29; 17, 389; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:retRecs; 21, list:[]; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:keyString; 25, call; 25, 26; 25, 27; 26, identifier:str; 27, argument_list; 27, 28; 28, identifier:keyString; 29, for_statement; 29, 30; 29, 31; 29, 32; 30, identifier:R; 31, identifier:self; 32, block; 32, 33; 33, try_statement; 33, 34; 33, 385; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 39; 35, 92; 35, 135; 35, 174; 35, 212; 35, 251; 35, 290; 35, 329; 35, 358; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:field; 38, string:'all'; 39, block; 39, 40; 40, for_statement; 40, 41; 40, 42; 40, 48; 41, identifier:cite; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:R; 45, identifier:get; 46, argument_list; 46, 47; 47, string:'citations'; 48, block; 48, 49; 49, if_statement; 49, 50; 49, 51; 49, 67; 50, identifier:caseSensitive; 51, block; 51, 52; 52, if_statement; 52, 53; 52, 58; 53, comparison_operator:in; 53, 54; 53, 55; 54, identifier:keyString; 55, attribute; 55, 56; 55, 57; 56, identifier:cite; 57, identifier:original; 58, block; 58, 59; 58, 66; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:retRecs; 63, identifier:append; 64, argument_list; 64, 65; 65, identifier:R; 66, break_statement; 67, else_clause; 67, 68; 68, block; 68, 69; 69, if_statement; 69, 70; 69, 83; 70, comparison_operator:in; 70, 71; 70, 76; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:keyString; 74, identifier:upper; 75, argument_list; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:cite; 80, identifier:original; 81, identifier:upper; 82, argument_list; 83, block; 83, 84; 83, 91; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:retRecs; 88, identifier:append; 89, argument_list; 89, 90; 90, identifier:R; 91, break_statement; 92, elif_clause; 92, 93; 92, 96; 93, comparison_operator:==; 93, 94; 93, 95; 94, identifier:field; 95, string:'author'; 96, block; 96, 97; 97, for_statement; 97, 98; 97, 99; 97, 105; 98, identifier:cite; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:R; 102, identifier:get; 103, argument_list; 103, 104; 104, string:'citations'; 105, block; 105, 106; 106, try_statement; 106, 107; 106, 131; 107, block; 107, 108; 108, if_statement; 108, 109; 108, 122; 109, comparison_operator:in; 109, 110; 109, 115; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:keyString; 113, identifier:upper; 114, argument_list; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:cite; 119, identifier:author; 120, identifier:upper; 121, argument_list; 122, block; 122, 123; 122, 130; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:retRecs; 127, identifier:append; 128, argument_list; 128, 129; 129, identifier:R; 130, break_statement; 131, except_clause; 131, 132; 131, 133; 132, identifier:AttributeError; 133, block; 133, 134; 134, pass_statement; 135, elif_clause; 135, 136; 135, 139; 136, comparison_operator:==; 136, 137; 136, 138; 137, identifier:field; 138, string:'journal'; 139, block; 139, 140; 140, for_statement; 140, 141; 140, 142; 140, 148; 141, identifier:cite; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:R; 145, identifier:get; 146, argument_list; 146, 147; 147, string:'citations'; 148, block; 148, 149; 149, try_statement; 149, 150; 149, 170; 150, block; 150, 151; 151, if_statement; 151, 152; 151, 161; 152, comparison_operator:in; 152, 153; 152, 158; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:keyString; 156, identifier:upper; 157, argument_list; 158, attribute; 158, 159; 158, 160; 159, identifier:cite; 160, identifier:journal; 161, block; 161, 162; 161, 169; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:retRecs; 166, identifier:append; 167, argument_list; 167, 168; 168, identifier:R; 169, break_statement; 170, except_clause; 170, 171; 170, 172; 171, identifier:AttributeError; 172, block; 172, 173; 173, pass_statement; 174, elif_clause; 174, 175; 174, 178; 175, comparison_operator:==; 175, 176; 175, 177; 176, identifier:field; 177, string:'year'; 178, block; 178, 179; 179, for_statement; 179, 180; 179, 181; 179, 187; 180, identifier:cite; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:R; 184, identifier:get; 185, argument_list; 185, 186; 186, string:'citations'; 187, block; 187, 188; 188, try_statement; 188, 189; 188, 208; 189, block; 189, 190; 190, if_statement; 190, 191; 190, 199; 191, comparison_operator:==; 191, 192; 191, 196; 192, call; 192, 193; 192, 194; 193, identifier:int; 194, argument_list; 194, 195; 195, identifier:keyString; 196, attribute; 196, 197; 196, 198; 197, identifier:cite; 198, identifier:year; 199, block; 199, 200; 199, 207; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:retRecs; 204, identifier:append; 205, argument_list; 205, 206; 206, identifier:R; 207, break_statement; 208, except_clause; 208, 209; 208, 210; 209, identifier:AttributeError; 210, block; 210, 211; 211, pass_statement; 212, elif_clause; 212, 213; 212, 216; 213, comparison_operator:==; 213, 214; 213, 215; 214, identifier:field; 215, string:'V'; 216, block; 216, 217; 217, for_statement; 217, 218; 217, 219; 217, 225; 218, identifier:cite; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:R; 222, identifier:get; 223, argument_list; 223, 224; 224, string:'citations'; 225, block; 225, 226; 226, try_statement; 226, 227; 226, 247; 227, block; 227, 228; 228, if_statement; 228, 229; 228, 238; 229, comparison_operator:in; 229, 230; 229, 235; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:keyString; 233, identifier:upper; 234, argument_list; 235, attribute; 235, 236; 235, 237; 236, identifier:cite; 237, identifier:V; 238, block; 238, 239; 238, 246; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:retRecs; 243, identifier:append; 244, argument_list; 244, 245; 245, identifier:R; 246, break_statement; 247, except_clause; 247, 248; 247, 249; 248, identifier:AttributeError; 249, block; 249, 250; 250, pass_statement; 251, elif_clause; 251, 252; 251, 255; 252, comparison_operator:==; 252, 253; 252, 254; 253, identifier:field; 254, string:'P'; 255, block; 255, 256; 256, for_statement; 256, 257; 256, 258; 256, 264; 257, identifier:cite; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:R; 261, identifier:get; 262, argument_list; 262, 263; 263, string:'citations'; 264, block; 264, 265; 265, try_statement; 265, 266; 265, 286; 266, block; 266, 267; 267, if_statement; 267, 268; 267, 277; 268, comparison_operator:in; 268, 269; 268, 274; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:keyString; 272, identifier:upper; 273, argument_list; 274, attribute; 274, 275; 274, 276; 275, identifier:cite; 276, identifier:P; 277, block; 277, 278; 277, 285; 278, expression_statement; 278, 279; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:retRecs; 282, identifier:append; 283, argument_list; 283, 284; 284, identifier:R; 285, break_statement; 286, except_clause; 286, 287; 286, 288; 287, identifier:AttributeError; 288, block; 288, 289; 289, pass_statement; 290, elif_clause; 290, 291; 290, 294; 291, comparison_operator:==; 291, 292; 291, 293; 292, identifier:field; 293, string:'misc'; 294, block; 294, 295; 295, for_statement; 295, 296; 295, 297; 295, 303; 296, identifier:cite; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:R; 300, identifier:get; 301, argument_list; 301, 302; 302, string:'citations'; 303, block; 303, 304; 304, try_statement; 304, 305; 304, 325; 305, block; 305, 306; 306, if_statement; 306, 307; 306, 316; 307, comparison_operator:in; 307, 308; 307, 313; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:keyString; 311, identifier:upper; 312, argument_list; 313, attribute; 313, 314; 313, 315; 314, identifier:cite; 315, identifier:misc; 316, block; 316, 317; 316, 324; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:retRecs; 321, identifier:append; 322, argument_list; 322, 323; 323, identifier:R; 324, break_statement; 325, except_clause; 325, 326; 325, 327; 326, identifier:AttributeError; 327, block; 327, 328; 328, pass_statement; 329, elif_clause; 329, 330; 329, 333; 330, comparison_operator:==; 330, 331; 330, 332; 331, identifier:field; 332, string:'anonymous'; 333, block; 333, 334; 334, for_statement; 334, 335; 334, 336; 334, 342; 335, identifier:cite; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:R; 339, identifier:get; 340, argument_list; 340, 341; 341, string:'citations'; 342, block; 342, 343; 343, if_statement; 343, 344; 343, 349; 344, call; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:cite; 347, identifier:isAnonymous; 348, argument_list; 349, block; 349, 350; 349, 357; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:retRecs; 354, identifier:append; 355, argument_list; 355, 356; 356, identifier:R; 357, break_statement; 358, elif_clause; 358, 359; 358, 362; 359, comparison_operator:==; 359, 360; 359, 361; 360, identifier:field; 361, string:'bad'; 362, block; 362, 363; 363, for_statement; 363, 364; 363, 365; 363, 371; 364, identifier:cite; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:R; 368, identifier:get; 369, argument_list; 369, 370; 370, string:'citations'; 371, block; 371, 372; 372, if_statement; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:cite; 375, identifier:bad; 376, block; 376, 377; 376, 384; 377, expression_statement; 377, 378; 378, call; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:retRecs; 381, identifier:append; 382, argument_list; 382, 383; 383, identifier:R; 384, break_statement; 385, except_clause; 385, 386; 385, 387; 386, identifier:TypeError; 387, block; 387, 388; 388, pass_statement; 389, if_statement; 389, 390; 389, 391; 389, 427; 390, identifier:reverse; 391, block; 391, 392; 391, 396; 391, 412; 392, expression_statement; 392, 393; 393, assignment; 393, 394; 393, 395; 394, identifier:excluded; 395, list:[]; 396, for_statement; 396, 397; 396, 398; 396, 399; 397, identifier:R; 398, identifier:self; 399, block; 399, 400; 400, if_statement; 400, 401; 400, 404; 401, comparison_operator:not; 401, 402; 401, 403; 402, identifier:R; 403, identifier:retRecs; 404, block; 404, 405; 405, expression_statement; 405, 406; 406, call; 406, 407; 406, 410; 407, attribute; 407, 408; 407, 409; 408, identifier:excluded; 409, identifier:append; 410, argument_list; 410, 411; 411, identifier:R; 412, return_statement; 412, 413; 413, call; 413, 414; 413, 415; 414, identifier:RecordCollection; 415, argument_list; 415, 416; 415, 419; 415, 424; 416, keyword_argument; 416, 417; 416, 418; 417, identifier:inCollection; 418, identifier:excluded; 419, keyword_argument; 419, 420; 419, 421; 420, identifier:name; 421, attribute; 421, 422; 421, 423; 422, identifier:self; 423, identifier:name; 424, keyword_argument; 424, 425; 424, 426; 425, identifier:quietStart; 426, True; 427, else_clause; 427, 428; 428, block; 428, 429; 429, return_statement; 429, 430; 430, call; 430, 431; 430, 432; 431, identifier:RecordCollection; 432, argument_list; 432, 433; 432, 436; 432, 441; 433, keyword_argument; 433, 434; 433, 435; 434, identifier:inCollection; 435, identifier:retRecs; 436, keyword_argument; 436, 437; 436, 438; 437, identifier:name; 438, attribute; 438, 439; 438, 440; 439, identifier:self; 440, identifier:name; 441, keyword_argument; 441, 442; 441, 443; 442, identifier:quietStart; 443, True | def citeFilter(self, keyString = '', field = 'all', reverse = False, caseSensitive = False):
retRecs = []
keyString = str(keyString)
for R in self:
try:
if field == 'all':
for cite in R.get('citations'):
if caseSensitive:
if keyString in cite.original:
retRecs.append(R)
break
else:
if keyString.upper() in cite.original.upper():
retRecs.append(R)
break
elif field == 'author':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.author.upper():
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'journal':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.journal:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'year':
for cite in R.get('citations'):
try:
if int(keyString) == cite.year:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'V':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.V:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'P':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.P:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'misc':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.misc:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'anonymous':
for cite in R.get('citations'):
if cite.isAnonymous():
retRecs.append(R)
break
elif field == 'bad':
for cite in R.get('citations'):
if cite.bad:
retRecs.append(R)
break
except TypeError:
pass
if reverse:
excluded = []
for R in self:
if R not in retRecs:
excluded.append(R)
return RecordCollection(inCollection = excluded, name = self.name, quietStart = True)
else:
return RecordCollection(inCollection = retRecs, name = self.name, quietStart = True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:rankedSeries; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 4, identifier:self; 5, identifier:tag; 6, default_parameter; 6, 7; 6, 8; 7, identifier:outputFile; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:giveCounts; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:giveRanks; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:greatestFirst; 17, True; 18, default_parameter; 18, 19; 18, 20; 19, identifier:pandasMode; 20, True; 21, default_parameter; 21, 22; 21, 23; 22, identifier:limitTo; 23, None; 24, block; 24, 25; 24, 35; 24, 39; 24, 99; 24, 121; 24, 169; 25, if_statement; 25, 26; 25, 29; 26, boolean_operator:and; 26, 27; 26, 28; 27, identifier:giveRanks; 28, identifier:giveCounts; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:mkException; 33, argument_list; 33, 34; 34, string:"rankedSeries cannot return counts and ranks only one of giveRanks or giveCounts can be True."; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:seriesDict; 38, dictionary; 39, for_statement; 39, 40; 39, 41; 39, 42; 40, identifier:R; 41, identifier:self; 42, block; 42, 43; 42, 55; 42, 68; 43, try_statement; 43, 44; 43, 51; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:val; 48, subscript; 48, 49; 48, 50; 49, identifier:R; 50, identifier:tag; 51, except_clause; 51, 52; 51, 53; 52, identifier:KeyError; 53, block; 53, 54; 54, continue_statement; 55, if_statement; 55, 56; 55, 62; 56, not_operator; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:isinstance; 59, argument_list; 59, 60; 59, 61; 60, identifier:val; 61, identifier:list; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:val; 66, list:[val]; 66, 67; 67, identifier:val; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:entry; 70, identifier:val; 71, block; 71, 72; 71, 80; 72, if_statement; 72, 73; 72, 78; 73, boolean_operator:and; 73, 74; 73, 75; 74, identifier:limitTo; 75, comparison_operator:not; 75, 76; 75, 77; 76, identifier:entry; 77, identifier:limitTo; 78, block; 78, 79; 79, continue_statement; 80, if_statement; 80, 81; 80, 84; 80, 91; 81, comparison_operator:in; 81, 82; 81, 83; 82, identifier:entry; 83, identifier:seriesDict; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, augmented_assignment:+=; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:seriesDict; 89, identifier:entry; 90, integer:1; 91, else_clause; 91, 92; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:seriesDict; 97, identifier:entry; 98, integer:1; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:seriesList; 102, call; 102, 103; 102, 104; 103, identifier:sorted; 104, argument_list; 104, 105; 104, 110; 104, 118; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:seriesDict; 108, identifier:items; 109, argument_list; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:key; 112, lambda; 112, 113; 112, 115; 113, lambda_parameters; 113, 114; 114, identifier:x; 115, subscript; 115, 116; 115, 117; 116, identifier:x; 117, integer:1; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:reverse; 120, identifier:greatestFirst; 121, if_statement; 121, 122; 121, 125; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:outputFile; 124, None; 125, block; 125, 126; 126, with_statement; 126, 127; 126, 137; 127, with_clause; 127, 128; 128, with_item; 128, 129; 129, as_pattern; 129, 130; 129, 135; 130, call; 130, 131; 130, 132; 131, identifier:open; 132, argument_list; 132, 133; 132, 134; 133, identifier:outputFile; 134, string:'w'; 135, as_pattern_target; 135, 136; 136, identifier:f; 137, block; 137, 138; 137, 150; 137, 162; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:writer; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:csv; 144, identifier:writer; 145, argument_list; 145, 146; 145, 147; 146, identifier:f; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:dialect; 149, string:'excel'; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:writer; 154, identifier:writerow; 155, argument_list; 155, 156; 156, tuple; 156, 157; 156, 161; 157, call; 157, 158; 157, 159; 158, identifier:str; 159, argument_list; 159, 160; 160, identifier:tag; 161, string:'count'; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:writer; 166, identifier:writerows; 167, argument_list; 167, 168; 168, identifier:seriesList; 169, if_statement; 169, 170; 169, 174; 169, 177; 169, 308; 170, boolean_operator:and; 170, 171; 170, 172; 171, identifier:giveCounts; 172, not_operator; 172, 173; 173, identifier:pandasMode; 174, block; 174, 175; 175, return_statement; 175, 176; 176, identifier:seriesList; 177, elif_clause; 177, 178; 177, 181; 178, boolean_operator:or; 178, 179; 178, 180; 179, identifier:giveRanks; 180, identifier:pandasMode; 181, block; 181, 182; 181, 192; 181, 196; 181, 200; 181, 213; 181, 289; 181, 299; 182, if_statement; 182, 183; 182, 185; 183, not_operator; 183, 184; 184, identifier:greatestFirst; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:seriesList; 190, identifier:reverse; 191, argument_list; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:currentRank; 195, integer:1; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:retList; 199, list:[]; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:panDict; 203, dictionary; 203, 204; 203, 207; 203, 210; 204, pair; 204, 205; 204, 206; 205, string:'entry'; 206, list:[]; 207, pair; 207, 208; 207, 209; 208, string:'count'; 209, list:[]; 210, pair; 210, 211; 210, 212; 211, string:'rank'; 212, list:[]; 213, try_statement; 213, 214; 213, 223; 213, 227; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:currentCount; 218, subscript; 218, 219; 218, 222; 219, subscript; 219, 220; 219, 221; 220, identifier:seriesList; 221, integer:0; 222, integer:1; 223, except_clause; 223, 224; 223, 225; 224, identifier:IndexError; 225, block; 225, 226; 226, pass_statement; 227, else_clause; 227, 228; 228, block; 228, 229; 229, for_statement; 229, 230; 229, 233; 229, 234; 230, pattern_list; 230, 231; 230, 232; 231, identifier:valString; 232, identifier:count; 233, identifier:seriesList; 234, block; 234, 235; 234, 248; 235, if_statement; 235, 236; 235, 239; 236, comparison_operator:>; 236, 237; 236, 238; 237, identifier:currentCount; 238, identifier:count; 239, block; 239, 240; 239, 244; 240, expression_statement; 240, 241; 241, augmented_assignment:+=; 241, 242; 241, 243; 242, identifier:currentRank; 243, integer:1; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:currentCount; 247, identifier:count; 248, if_statement; 248, 249; 248, 250; 248, 278; 249, identifier:pandasMode; 250, block; 250, 251; 250, 260; 250, 269; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 258; 253, attribute; 253, 254; 253, 257; 254, subscript; 254, 255; 254, 256; 255, identifier:panDict; 256, string:'entry'; 257, identifier:append; 258, argument_list; 258, 259; 259, identifier:valString; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 267; 262, attribute; 262, 263; 262, 266; 263, subscript; 263, 264; 263, 265; 264, identifier:panDict; 265, string:'count'; 266, identifier:append; 267, argument_list; 267, 268; 268, identifier:count; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 276; 271, attribute; 271, 272; 271, 275; 272, subscript; 272, 273; 272, 274; 273, identifier:panDict; 274, string:'rank'; 275, identifier:append; 276, argument_list; 276, 277; 277, identifier:currentRank; 278, else_clause; 278, 279; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:retList; 284, identifier:append; 285, argument_list; 285, 286; 286, tuple; 286, 287; 286, 288; 287, identifier:valString; 288, identifier:currentRank; 289, if_statement; 289, 290; 289, 292; 290, not_operator; 290, 291; 291, identifier:greatestFirst; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:retList; 297, identifier:reverse; 298, argument_list; 299, if_statement; 299, 300; 299, 301; 299, 304; 300, identifier:pandasMode; 301, block; 301, 302; 302, return_statement; 302, 303; 303, identifier:panDict; 304, else_clause; 304, 305; 305, block; 305, 306; 306, return_statement; 306, 307; 307, identifier:retList; 308, else_clause; 308, 309; 309, block; 309, 310; 310, return_statement; 310, 311; 311, list_comprehension; 311, 312; 311, 313; 312, identifier:e; 313, for_in_clause; 313, 314; 313, 317; 314, pattern_list; 314, 315; 314, 316; 315, identifier:e; 316, identifier:c; 317, identifier:seriesList | def rankedSeries(self, tag, outputFile = None, giveCounts = True, giveRanks = False, greatestFirst = True, pandasMode = True, limitTo = None):
if giveRanks and giveCounts:
raise mkException("rankedSeries cannot return counts and ranks only one of giveRanks or giveCounts can be True.")
seriesDict = {}
for R in self:
try:
val = R[tag]
except KeyError:
continue
if not isinstance(val, list):
val = [val]
for entry in val:
if limitTo and entry not in limitTo:
continue
if entry in seriesDict:
seriesDict[entry] += 1
else:
seriesDict[entry] = 1
seriesList = sorted(seriesDict.items(), key = lambda x: x[1], reverse = greatestFirst)
if outputFile is not None:
with open(outputFile, 'w') as f:
writer = csv.writer(f, dialect = 'excel')
writer.writerow((str(tag), 'count'))
writer.writerows(seriesList)
if giveCounts and not pandasMode:
return seriesList
elif giveRanks or pandasMode:
if not greatestFirst:
seriesList.reverse()
currentRank = 1
retList = []
panDict = {'entry' : [], 'count' : [], 'rank' : []}
try:
currentCount = seriesList[0][1]
except IndexError:
pass
else:
for valString, count in seriesList:
if currentCount > count:
currentRank += 1
currentCount = count
if pandasMode:
panDict['entry'].append(valString)
panDict['count'].append(count)
panDict['rank'].append(currentRank)
else:
retList.append((valString, currentRank))
if not greatestFirst:
retList.reverse()
if pandasMode:
return panDict
else:
return retList
else:
return [e for e,c in seriesList] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:timeSeries; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:tag; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:outputFile; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:giveYears; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:greatestFirst; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:limitTo; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:pandasMode; 22, True; 23, block; 23, 24; 23, 28; 23, 134; 23, 138; 23, 162; 23, 180; 23, 252; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:seriesDict; 27, dictionary; 28, for_statement; 28, 29; 28, 30; 28, 31; 29, identifier:R; 30, identifier:self; 31, block; 31, 32; 31, 44; 32, try_statement; 32, 33; 32, 40; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:year; 37, subscript; 37, 38; 37, 39; 38, identifier:R; 39, string:'year'; 40, except_clause; 40, 41; 40, 42; 41, identifier:KeyError; 42, block; 42, 43; 43, continue_statement; 44, if_statement; 44, 45; 44, 48; 44, 58; 45, comparison_operator:is; 45, 46; 45, 47; 46, identifier:tag; 47, None; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:seriesDict; 53, identifier:R; 54, dictionary; 54, 55; 55, pair; 55, 56; 55, 57; 56, identifier:year; 57, integer:1; 58, else_clause; 58, 59; 59, block; 59, 60; 59, 72; 59, 85; 60, try_statement; 60, 61; 60, 68; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:val; 65, subscript; 65, 66; 65, 67; 66, identifier:R; 67, identifier:tag; 68, except_clause; 68, 69; 68, 70; 69, identifier:KeyError; 70, block; 70, 71; 71, continue_statement; 72, if_statement; 72, 73; 72, 79; 73, not_operator; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:isinstance; 76, argument_list; 76, 77; 76, 78; 77, identifier:val; 78, identifier:list; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:val; 83, list:[val]; 83, 84; 84, identifier:val; 85, for_statement; 85, 86; 85, 87; 85, 88; 86, identifier:entry; 87, identifier:val; 88, block; 88, 89; 88, 97; 89, if_statement; 89, 90; 89, 95; 90, boolean_operator:and; 90, 91; 90, 92; 91, identifier:limitTo; 92, comparison_operator:not; 92, 93; 92, 94; 93, identifier:entry; 94, identifier:limitTo; 95, block; 95, 96; 96, continue_statement; 97, if_statement; 97, 98; 97, 101; 97, 123; 98, comparison_operator:in; 98, 99; 98, 100; 99, identifier:entry; 100, identifier:seriesDict; 101, block; 101, 102; 102, try_statement; 102, 103; 102, 112; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, augmented_assignment:+=; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:seriesDict; 109, identifier:entry; 110, identifier:year; 111, integer:1; 112, except_clause; 112, 113; 112, 114; 113, identifier:KeyError; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 122; 117, subscript; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:seriesDict; 120, identifier:entry; 121, identifier:year; 122, integer:1; 123, else_clause; 123, 124; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:seriesDict; 129, identifier:entry; 130, dictionary; 130, 131; 131, pair; 131, 132; 131, 133; 132, identifier:year; 133, integer:1; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:seriesList; 137, list:[]; 138, for_statement; 138, 139; 138, 142; 138, 147; 139, pattern_list; 139, 140; 139, 141; 140, identifier:e; 141, identifier:yd; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:seriesDict; 145, identifier:items; 146, argument_list; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, augmented_assignment:+=; 149, 150; 149, 151; 150, identifier:seriesList; 151, list_comprehension; 151, 152; 151, 155; 152, tuple; 152, 153; 152, 154; 153, identifier:e; 154, identifier:y; 155, for_in_clause; 155, 156; 155, 157; 156, identifier:y; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:yd; 160, identifier:keys; 161, argument_list; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:seriesList; 165, call; 165, 166; 165, 167; 166, identifier:sorted; 167, argument_list; 167, 168; 167, 169; 167, 177; 168, identifier:seriesList; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:key; 171, lambda; 171, 172; 171, 174; 172, lambda_parameters; 172, 173; 173, identifier:x; 174, subscript; 174, 175; 174, 176; 175, identifier:x; 176, integer:1; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:reverse; 179, identifier:greatestFirst; 180, if_statement; 180, 181; 180, 184; 181, comparison_operator:is; 181, 182; 181, 183; 182, identifier:outputFile; 183, None; 184, block; 184, 185; 185, with_statement; 185, 186; 185, 196; 186, with_clause; 186, 187; 187, with_item; 187, 188; 188, as_pattern; 188, 189; 188, 194; 189, call; 189, 190; 189, 191; 190, identifier:open; 191, argument_list; 191, 192; 191, 193; 192, identifier:outputFile; 193, string:'w'; 194, as_pattern_target; 194, 195; 195, identifier:f; 196, block; 196, 197; 196, 209; 196, 221; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:writer; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:csv; 203, identifier:writer; 204, argument_list; 204, 205; 204, 206; 205, identifier:f; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:dialect; 208, string:'excel'; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:writer; 213, identifier:writerow; 214, argument_list; 214, 215; 215, tuple; 215, 216; 215, 220; 216, call; 216, 217; 216, 218; 217, identifier:str; 218, argument_list; 218, 219; 219, identifier:tag; 220, string:'years'; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:writer; 225, identifier:writerows; 226, argument_list; 226, 227; 227, generator_expression; 227, 228; 227, 243; 228, tuple; 228, 229; 228, 230; 229, identifier:k; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, string:'|'; 233, identifier:join; 234, argument_list; 234, 235; 235, generator_expression; 235, 236; 235, 240; 236, call; 236, 237; 236, 238; 237, identifier:str; 238, argument_list; 238, 239; 239, identifier:y; 240, for_in_clause; 240, 241; 240, 242; 241, identifier:y; 242, identifier:v; 243, for_in_clause; 243, 244; 243, 247; 244, pattern_list; 244, 245; 244, 246; 245, identifier:k; 246, identifier:v; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:seriesDict; 250, identifier:items; 251, argument_list; 252, if_statement; 252, 253; 252, 254; 252, 307; 252, 312; 253, identifier:pandasMode; 254, block; 254, 255; 254, 268; 254, 305; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:panDict; 258, dictionary; 258, 259; 258, 262; 258, 265; 259, pair; 259, 260; 259, 261; 260, string:'entry'; 261, list:[]; 262, pair; 262, 263; 262, 264; 263, string:'count'; 264, list:[]; 265, pair; 265, 266; 265, 267; 266, string:'year'; 267, list:[]; 268, for_statement; 268, 269; 268, 272; 268, 273; 269, pattern_list; 269, 270; 269, 271; 270, identifier:entry; 271, identifier:year; 272, identifier:seriesList; 273, block; 273, 274; 273, 283; 273, 292; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 281; 276, attribute; 276, 277; 276, 280; 277, subscript; 277, 278; 277, 279; 278, identifier:panDict; 279, string:'entry'; 280, identifier:append; 281, argument_list; 281, 282; 282, identifier:entry; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 290; 285, attribute; 285, 286; 285, 289; 286, subscript; 286, 287; 286, 288; 287, identifier:panDict; 288, string:'year'; 289, identifier:append; 290, argument_list; 290, 291; 291, identifier:year; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 299; 294, attribute; 294, 295; 294, 298; 295, subscript; 295, 296; 295, 297; 296, identifier:panDict; 297, string:'count'; 298, identifier:append; 299, argument_list; 299, 300; 300, subscript; 300, 301; 300, 304; 301, subscript; 301, 302; 301, 303; 302, identifier:seriesDict; 303, identifier:entry; 304, identifier:year; 305, return_statement; 305, 306; 306, identifier:panDict; 307, elif_clause; 307, 308; 307, 309; 308, identifier:giveYears; 309, block; 309, 310; 310, return_statement; 310, 311; 311, identifier:seriesList; 312, else_clause; 312, 313; 313, block; 313, 314; 314, return_statement; 314, 315; 315, list_comprehension; 315, 316; 315, 317; 316, identifier:e; 317, for_in_clause; 317, 318; 317, 321; 318, pattern_list; 318, 319; 318, 320; 319, identifier:e; 320, identifier:c; 321, identifier:seriesList | def timeSeries(self, tag = None, outputFile = None, giveYears = True, greatestFirst = True, limitTo = False, pandasMode = True):
seriesDict = {}
for R in self:
try:
year = R['year']
except KeyError:
continue
if tag is None:
seriesDict[R] = {year : 1}
else:
try:
val = R[tag]
except KeyError:
continue
if not isinstance(val, list):
val = [val]
for entry in val:
if limitTo and entry not in limitTo:
continue
if entry in seriesDict:
try:
seriesDict[entry][year] += 1
except KeyError:
seriesDict[entry][year] = 1
else:
seriesDict[entry] = {year : 1}
seriesList = []
for e, yd in seriesDict.items():
seriesList += [(e, y) for y in yd.keys()]
seriesList = sorted(seriesList, key = lambda x: x[1], reverse = greatestFirst)
if outputFile is not None:
with open(outputFile, 'w') as f:
writer = csv.writer(f, dialect = 'excel')
writer.writerow((str(tag), 'years'))
writer.writerows(((k,'|'.join((str(y) for y in v))) for k,v in seriesDict.items()))
if pandasMode:
panDict = {'entry' : [], 'count' : [], 'year' : []}
for entry, year in seriesList:
panDict['entry'].append(entry)
panDict['year'].append(year)
panDict['count'].append(seriesDict[entry][year])
return panDict
elif giveYears:
return seriesList
else:
return [e for e,c in seriesList] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:cooccurrenceCounts; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:keyTag; 6, list_splat_pattern; 6, 7; 7, identifier:countedTags; 8, block; 8, 9; 8, 27; 8, 40; 8, 62; 8, 66; 8, 83; 8, 104; 8, 267; 9, if_statement; 9, 10; 9, 16; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:keyTag; 15, identifier:str; 16, block; 16, 17; 17, raise_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:TagError; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, string:"'{}' is not a string it cannot be used as a tag."; 24, identifier:format; 25, argument_list; 25, 26; 26, identifier:keyTag; 27, if_statement; 27, 28; 27, 34; 28, comparison_operator:<; 28, 29; 28, 33; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, identifier:countedTags; 33, integer:1; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:TagError; 38, argument_list; 38, 39; 39, string:"You need to provide atleast one tag"; 40, for_statement; 40, 41; 40, 42; 40, 43; 41, identifier:tag; 42, identifier:countedTags; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 51; 45, not_operator; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:isinstance; 48, argument_list; 48, 49; 48, 50; 49, identifier:tag; 50, identifier:str; 51, block; 51, 52; 52, raise_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:TagError; 55, argument_list; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, string:"'{}' is not a string it cannot be used as a tag."; 59, identifier:format; 60, argument_list; 60, 61; 61, identifier:tag; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:occurenceDict; 65, dictionary; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:progArgs; 69, tuple; 69, 70; 69, 71; 70, integer:0; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, string:"Starting to count the co-occurrences of '{}' and' {}'"; 74, identifier:format; 75, argument_list; 75, 76; 75, 77; 76, identifier:keyTag; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, string:"','"; 80, identifier:join; 81, argument_list; 81, 82; 82, identifier:countedTags; 83, if_statement; 83, 84; 83, 87; 83, 95; 84, attribute; 84, 85; 84, 86; 85, identifier:metaknowledge; 86, identifier:VERBOSE_MODE; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:progKwargs; 91, dictionary; 91, 92; 92, pair; 92, 93; 92, 94; 93, string:'dummy'; 94, False; 95, else_clause; 95, 96; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:progKwargs; 100, dictionary; 100, 101; 101, pair; 101, 102; 101, 103; 102, string:'dummy'; 103, True; 104, with_statement; 104, 105; 104, 117; 105, with_clause; 105, 106; 106, with_item; 106, 107; 107, as_pattern; 107, 108; 107, 115; 108, call; 108, 109; 108, 110; 109, identifier:_ProgressBar; 110, argument_list; 110, 111; 110, 113; 111, list_splat; 111, 112; 112, identifier:progArgs; 113, dictionary_splat; 113, 114; 114, identifier:progKwargs; 115, as_pattern_target; 115, 116; 116, identifier:PBar; 117, block; 117, 118; 117, 249; 118, for_statement; 118, 119; 118, 122; 118, 126; 119, pattern_list; 119, 120; 119, 121; 120, identifier:i; 121, identifier:R; 122, call; 122, 123; 122, 124; 123, identifier:enumerate; 124, argument_list; 124, 125; 125, identifier:self; 126, block; 126, 127; 126, 145; 126, 154; 126, 160; 126, 173; 126, 188; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:PBar; 131, identifier:updateVal; 132, argument_list; 132, 133; 132, 139; 133, binary_operator:/; 133, 134; 133, 135; 134, identifier:i; 135, call; 135, 136; 135, 137; 136, identifier:len; 137, argument_list; 137, 138; 138, identifier:self; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, string:"Analyzing {}"; 142, identifier:format; 143, argument_list; 143, 144; 144, identifier:R; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:keyVal; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:R; 151, identifier:get; 152, argument_list; 152, 153; 153, identifier:keyTag; 154, if_statement; 154, 155; 154, 158; 155, comparison_operator:is; 155, 156; 155, 157; 156, identifier:keyVal; 157, None; 158, block; 158, 159; 159, continue_statement; 160, if_statement; 160, 161; 160, 167; 161, not_operator; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:isinstance; 164, argument_list; 164, 165; 164, 166; 165, identifier:keyVal; 166, identifier:list; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:keyVal; 171, list:[keyVal]; 171, 172; 172, identifier:keyVal; 173, for_statement; 173, 174; 173, 175; 173, 176; 174, identifier:key; 175, identifier:keyVal; 176, block; 176, 177; 177, if_statement; 177, 178; 177, 181; 178, comparison_operator:not; 178, 179; 178, 180; 179, identifier:key; 180, identifier:occurenceDict; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:occurenceDict; 186, identifier:key; 187, dictionary; 188, for_statement; 188, 189; 188, 190; 188, 191; 189, identifier:tag; 190, identifier:countedTags; 191, block; 191, 192; 191, 201; 191, 207; 191, 220; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:tagval; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:R; 198, identifier:get; 199, argument_list; 199, 200; 200, identifier:tag; 201, if_statement; 201, 202; 201, 205; 202, comparison_operator:is; 202, 203; 202, 204; 203, identifier:tagval; 204, None; 205, block; 205, 206; 206, continue_statement; 207, if_statement; 207, 208; 207, 214; 208, not_operator; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:isinstance; 211, argument_list; 211, 212; 211, 213; 212, identifier:tagval; 213, identifier:list; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:tagval; 218, list:[tagval]; 218, 219; 219, identifier:tagval; 220, for_statement; 220, 221; 220, 222; 220, 223; 221, identifier:val; 222, identifier:tagval; 223, block; 223, 224; 224, for_statement; 224, 225; 224, 226; 224, 227; 225, identifier:key; 226, identifier:keyVal; 227, block; 227, 228; 228, try_statement; 228, 229; 228, 238; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, augmented_assignment:+=; 231, 232; 231, 237; 232, subscript; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:occurenceDict; 235, identifier:key; 236, identifier:val; 237, integer:1; 238, except_clause; 238, 239; 238, 240; 239, identifier:KeyError; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 248; 243, subscript; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:occurenceDict; 246, identifier:key; 247, identifier:val; 248, integer:1; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:PBar; 253, identifier:finish; 254, argument_list; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, string:"Done extracting the co-occurrences of '{}' and '{}'"; 258, identifier:format; 259, argument_list; 259, 260; 259, 261; 260, identifier:keyTag; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, string:"','"; 264, identifier:join; 265, argument_list; 265, 266; 266, identifier:countedTags; 267, return_statement; 267, 268; 268, identifier:occurenceDict | def cooccurrenceCounts(self, keyTag, *countedTags):
if not isinstance(keyTag, str):
raise TagError("'{}' is not a string it cannot be used as a tag.".format(keyTag))
if len(countedTags) < 1:
TagError("You need to provide atleast one tag")
for tag in countedTags:
if not isinstance(tag, str):
raise TagError("'{}' is not a string it cannot be used as a tag.".format(tag))
occurenceDict = {}
progArgs = (0, "Starting to count the co-occurrences of '{}' and' {}'".format(keyTag, "','".join(countedTags)))
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
for i, R in enumerate(self):
PBar.updateVal(i / len(self), "Analyzing {}".format(R))
keyVal = R.get(keyTag)
if keyVal is None:
continue
if not isinstance(keyVal, list):
keyVal = [keyVal]
for key in keyVal:
if key not in occurenceDict:
occurenceDict[key] = {}
for tag in countedTags:
tagval = R.get(tag)
if tagval is None:
continue
if not isinstance(tagval, list):
tagval = [tagval]
for val in tagval:
for key in keyVal:
try:
occurenceDict[key][val] += 1
except KeyError:
occurenceDict[key][val] = 1
PBar.finish("Done extracting the co-occurrences of '{}' and '{}'".format(keyTag, "','".join(countedTags)))
return occurenceDict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:getCitations; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:field; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:values; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:pandasFriendly; 13, True; 14, block; 14, 15; 14, 19; 14, 50; 14, 107; 14, 116; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:retCites; 18, list:[]; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:values; 22, None; 23, block; 23, 24; 24, if_statement; 24, 25; 24, 44; 25, boolean_operator:or; 25, 26; 25, 34; 26, call; 26, 27; 26, 28; 27, identifier:isinstance; 28, argument_list; 28, 29; 28, 30; 29, identifier:values; 30, tuple; 30, 31; 30, 32; 30, 33; 31, identifier:str; 32, identifier:int; 33, identifier:float; 34, not_operator; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:isinstance; 37, argument_list; 37, 38; 37, 39; 38, identifier:values; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:collections; 42, identifier:abc; 43, identifier:Container; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:values; 48, list:[values]; 48, 49; 49, identifier:values; 50, if_statement; 50, 51; 50, 54; 50, 95; 51, comparison_operator:is; 51, 52; 51, 53; 52, identifier:field; 53, None; 54, block; 54, 55; 55, for_statement; 55, 56; 55, 57; 55, 64; 56, identifier:cite; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:get; 61, argument_list; 61, 62; 61, 63; 62, string:'citations'; 63, list:[]; 64, block; 64, 65; 65, try_statement; 65, 66; 65, 91; 66, block; 66, 67; 66, 75; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:targetVal; 70, call; 70, 71; 70, 72; 71, identifier:getattr; 72, argument_list; 72, 73; 72, 74; 73, identifier:cite; 74, identifier:field; 75, if_statement; 75, 76; 75, 83; 76, boolean_operator:or; 76, 77; 76, 80; 77, comparison_operator:is; 77, 78; 77, 79; 78, identifier:values; 79, None; 80, comparison_operator:in; 80, 81; 80, 82; 81, identifier:targetVal; 82, identifier:values; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:retCites; 88, identifier:append; 89, argument_list; 89, 90; 90, identifier:cite; 91, except_clause; 91, 92; 91, 93; 92, identifier:AttributeError; 93, block; 93, 94; 94, pass_statement; 95, else_clause; 95, 96; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:retCites; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:get; 104, argument_list; 104, 105; 104, 106; 105, string:'citations'; 106, list:[]; 107, if_statement; 107, 108; 107, 109; 108, identifier:pandasFriendly; 109, block; 109, 110; 110, return_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:_pandasPrep; 113, argument_list; 113, 114; 113, 115; 114, identifier:retCites; 115, False; 116, return_statement; 116, 117; 117, identifier:retCites | def getCitations(self, field = None, values = None, pandasFriendly = True):
retCites = []
if values is not None:
if isinstance(values, (str, int, float)) or not isinstance(values, collections.abc.Container):
values = [values]
if field is not None:
for cite in self.get('citations', []):
try:
targetVal = getattr(cite, field)
if values is None or targetVal in values:
retCites.append(cite)
except AttributeError:
pass
else:
retCites = self.get('citations', [])
if pandasFriendly:
return _pandasPrep(retCites, False)
return retCites |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:proQuestParser; 3, parameters; 3, 4; 4, identifier:proFile; 5, block; 5, 6; 5, 10; 5, 16; 5, 20; 5, 24; 5, 301; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:nameDict; 9, dictionary; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:recSet; 13, call; 13, 14; 13, 15; 14, identifier:set; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:error; 19, None; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:lineNum; 23, integer:0; 24, try_statement; 24, 25; 24, 273; 25, block; 25, 26; 26, with_statement; 26, 27; 26, 40; 27, with_clause; 27, 28; 28, with_item; 28, 29; 29, as_pattern; 29, 30; 29, 38; 30, call; 30, 31; 30, 32; 31, identifier:open; 32, argument_list; 32, 33; 32, 34; 32, 35; 33, identifier:proFile; 34, string:'r'; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:encoding; 37, string:'utf-8'; 38, as_pattern_target; 38, 39; 39, identifier:openfile; 40, block; 40, 41; 40, 51; 40, 67; 40, 146; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:f; 44, call; 44, 45; 44, 46; 45, identifier:enumerate; 46, argument_list; 46, 47; 46, 48; 47, identifier:openfile; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:start; 50, integer:1; 51, for_statement; 51, 52; 51, 53; 51, 57; 52, identifier:i; 53, call; 53, 54; 53, 55; 54, identifier:range; 55, argument_list; 55, 56; 56, integer:12; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 63; 60, pattern_list; 60, 61; 60, 62; 61, identifier:lineNum; 62, identifier:line; 63, call; 63, 64; 63, 65; 64, identifier:next; 65, argument_list; 65, 66; 66, identifier:f; 67, while_statement; 67, 68; 67, 69; 68, True; 69, block; 69, 70; 69, 79; 69, 88; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, pattern_list; 72, 73; 72, 74; 73, identifier:lineNum; 74, identifier:line; 75, call; 75, 76; 75, 77; 76, identifier:next; 77, argument_list; 77, 78; 78, identifier:f; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, pattern_list; 81, 82; 81, 83; 82, identifier:lineNum; 83, identifier:line; 84, call; 84, 85; 84, 86; 85, identifier:next; 86, argument_list; 86, 87; 87, identifier:f; 88, if_statement; 88, 89; 88, 92; 88, 110; 89, comparison_operator:==; 89, 90; 89, 91; 90, identifier:line; 91, string:'Bibliography\n'; 92, block; 92, 93; 92, 109; 93, for_statement; 93, 94; 93, 95; 93, 99; 94, identifier:i; 95, call; 95, 96; 95, 97; 96, identifier:range; 97, argument_list; 97, 98; 98, integer:3; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, pattern_list; 102, 103; 102, 104; 103, identifier:lineNum; 104, identifier:line; 105, call; 105, 106; 105, 107; 106, identifier:next; 107, argument_list; 107, 108; 108, identifier:f; 109, break_statement; 110, else_clause; 110, 111; 111, block; 111, 112; 111, 121; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:s; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:line; 118, identifier:split; 119, argument_list; 119, 120; 120, string:'. '; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 131; 123, subscript; 123, 124; 123, 125; 124, identifier:nameDict; 125, call; 125, 126; 125, 127; 126, identifier:int; 127, argument_list; 127, 128; 128, subscript; 128, 129; 128, 130; 129, identifier:s; 130, integer:0; 131, subscript; 131, 132; 131, 142; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, string:'. '; 135, identifier:join; 136, argument_list; 136, 137; 137, subscript; 137, 138; 137, 139; 138, identifier:s; 139, slice; 139, 140; 139, 141; 140, integer:1; 141, colon; 142, slice; 142, 143; 142, 144; 143, colon; 144, unary_operator:-; 144, 145; 145, integer:1; 146, while_statement; 146, 147; 146, 148; 147, True; 148, block; 148, 149; 148, 158; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, pattern_list; 151, 152; 151, 153; 152, identifier:lineNum; 153, identifier:line; 154, call; 154, 155; 154, 156; 155, identifier:next; 156, argument_list; 156, 157; 157, identifier:f; 158, if_statement; 158, 159; 158, 162; 158, 164; 158, 256; 159, comparison_operator:==; 159, 160; 159, 161; 160, identifier:line; 161, string:'Bibliography\n'; 162, block; 162, 163; 163, break_statement; 164, elif_clause; 164, 165; 164, 171; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:line; 168, identifier:startswith; 169, argument_list; 169, 170; 170, string:'Document '; 171, block; 171, 172; 171, 190; 171, 203; 171, 240; 171, 247; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:n; 175, call; 175, 176; 175, 177; 176, identifier:int; 177, argument_list; 177, 178; 178, subscript; 178, 179; 178, 189; 179, call; 179, 180; 179, 187; 180, attribute; 180, 181; 180, 186; 181, subscript; 181, 182; 181, 183; 182, identifier:line; 183, slice; 183, 184; 183, 185; 184, integer:9; 185, colon; 186, identifier:split; 187, argument_list; 187, 188; 188, string:' of '; 189, integer:0; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:R; 193, call; 193, 194; 193, 195; 194, identifier:ProQuestRecord; 195, argument_list; 195, 196; 195, 197; 195, 200; 196, identifier:f; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:sFile; 199, identifier:proFile; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:sLine; 202, identifier:lineNum; 203, if_statement; 203, 204; 203, 214; 204, comparison_operator:!=; 204, 205; 204, 211; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:R; 208, identifier:get; 209, argument_list; 209, 210; 210, string:'Title'; 211, subscript; 211, 212; 211, 213; 212, identifier:nameDict; 213, identifier:n; 214, block; 214, 215; 214, 238; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:error; 218, call; 218, 219; 218, 220; 219, identifier:BadProQuestFile; 220, argument_list; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, string:"The numbering of the titles at the beginning of the file does not match the records inside. Line {} has a record titled '{}' with number {}, the name should be '{}'."; 224, identifier:format; 225, argument_list; 225, 226; 225, 227; 225, 234; 225, 235; 226, identifier:lineNum; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:R; 230, identifier:get; 231, argument_list; 231, 232; 231, 233; 232, string:'Title'; 233, string:"TITLE MISSING"; 234, identifier:n; 235, subscript; 235, 236; 235, 237; 236, identifier:nameDict; 237, identifier:n; 238, raise_statement; 238, 239; 239, identifier:StopIteration; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:recSet; 244, identifier:add; 245, argument_list; 245, 246; 246, identifier:R; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 252; 249, pattern_list; 249, 250; 249, 251; 250, identifier:lineNum; 251, identifier:line; 252, call; 252, 253; 252, 254; 253, identifier:next; 254, argument_list; 254, 255; 255, identifier:f; 256, else_clause; 256, 257; 257, block; 257, 258; 257, 271; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:error; 261, call; 261, 262; 261, 263; 262, identifier:BadProQuestFile; 263, argument_list; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, string:"The file '{}' has parts of it that are unparsable starting at line: {}. It is likely that the seperators between the records are incorrect"; 267, identifier:format; 268, argument_list; 268, 269; 268, 270; 269, identifier:proFile; 270, identifier:lineNum; 271, raise_statement; 271, 272; 272, identifier:StopIteration; 273, except_clause; 273, 274; 273, 281; 274, as_pattern; 274, 275; 274, 279; 275, tuple; 275, 276; 275, 277; 275, 278; 276, identifier:UnicodeDecodeError; 277, identifier:StopIteration; 278, identifier:ValueError; 279, as_pattern_target; 279, 280; 280, identifier:e; 281, block; 281, 282; 282, if_statement; 282, 283; 282, 286; 283, comparison_operator:is; 283, 284; 283, 285; 284, identifier:error; 285, None; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:error; 290, call; 290, 291; 290, 292; 291, identifier:BadProQuestFile; 292, argument_list; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, string:"The file '{}' has parts of it that are unparsable starting at line: {}.\nThe error was: '{}'"; 296, identifier:format; 297, argument_list; 297, 298; 297, 299; 297, 300; 298, identifier:proFile; 299, identifier:lineNum; 300, identifier:e; 301, return_statement; 301, 302; 302, expression_list; 302, 303; 302, 304; 303, identifier:recSet; 304, identifier:error | def proQuestParser(proFile):
nameDict = {}
recSet = set()
error = None
lineNum = 0
try:
with open(proFile, 'r', encoding = 'utf-8') as openfile:
f = enumerate(openfile, start = 1)
for i in range(12):
lineNum, line = next(f)
while True:
lineNum, line = next(f)
lineNum, line = next(f)
if line == 'Bibliography\n':
for i in range(3):
lineNum, line = next(f)
break
else:
s = line.split('. ')
nameDict[int(s[0])] = '. '.join(s[1:])[:-1]
while True:
lineNum, line = next(f)
if line == 'Bibliography\n':
break
elif line.startswith('Document '):
n = int(line[9:].split(' of ')[0])
R = ProQuestRecord(f, sFile = proFile, sLine = lineNum)
if R.get('Title') != nameDict[n]:
error = BadProQuestFile("The numbering of the titles at the beginning of the file does not match the records inside. Line {} has a record titled '{}' with number {}, the name should be '{}'.".format(lineNum, R.get('Title', "TITLE MISSING"), n, nameDict[n]))
raise StopIteration
recSet.add(R)
lineNum, line = next(f)
else:
error = BadProQuestFile("The file '{}' has parts of it that are unparsable starting at line: {}. It is likely that the seperators between the records are incorrect".format(proFile, lineNum))
raise StopIteration
except (UnicodeDecodeError, StopIteration, ValueError) as e:
if error is None:
error = BadProQuestFile("The file '{}' has parts of it that are unparsable starting at line: {}.\nThe error was: '{}'".format(proFile, lineNum, e))
return recSet, error |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:minus; 3, parameters; 3, 4; 3, 5; 4, identifier:repo_list_a; 5, identifier:repo_list_b; 6, block; 6, 7; 6, 15; 6, 27; 6, 33; 6, 60; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:included; 10, call; 10, 11; 10, 12; 11, identifier:defaultdict; 12, argument_list; 12, 13; 13, lambda; 13, 14; 14, False; 15, for_statement; 15, 16; 15, 17; 15, 18; 16, identifier:repo; 17, identifier:repo_list_b; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 26; 21, subscript; 21, 22; 21, 23; 22, identifier:included; 23, attribute; 23, 24; 23, 25; 24, identifier:repo; 25, identifier:full_name; 26, True; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:a_minus_b; 30, call; 30, 31; 30, 32; 31, identifier:list; 32, argument_list; 33, for_statement; 33, 34; 33, 35; 33, 36; 34, identifier:repo; 35, identifier:repo_list_a; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 44; 38, not_operator; 38, 39; 39, subscript; 39, 40; 39, 41; 40, identifier:included; 41, attribute; 41, 42; 41, 43; 42, identifier:repo; 43, identifier:full_name; 44, block; 44, 45; 44, 53; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 52; 47, subscript; 47, 48; 47, 49; 48, identifier:included; 49, attribute; 49, 50; 49, 51; 50, identifier:repo; 51, identifier:full_name; 52, True; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:a_minus_b; 57, identifier:append; 58, argument_list; 58, 59; 59, identifier:repo; 60, return_statement; 60, 61; 61, identifier:a_minus_b | def minus(repo_list_a, repo_list_b):
included = defaultdict(lambda: False)
for repo in repo_list_b:
included[repo.full_name] = True
a_minus_b = list()
for repo in repo_list_a:
if not included[repo.full_name]:
included[repo.full_name] = True
a_minus_b.append(repo)
return a_minus_b |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__clean_and_tokenize; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:doc_list; 6, block; 6, 7; 6, 29; 6, 35; 6, 42; 6, 50; 6, 58; 6, 122; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:doc_list; 10, call; 10, 11; 10, 12; 11, identifier:filter; 12, argument_list; 12, 13; 12, 28; 13, lambda; 13, 14; 13, 16; 14, lambda_parameters; 14, 15; 15, identifier:x; 16, boolean_operator:and; 16, 17; 16, 20; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:x; 19, None; 20, comparison_operator:<=; 20, 21; 20, 25; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:x; 25, attribute; 25, 26; 25, 27; 26, identifier:GitSuggest; 27, identifier:MAX_DESC_LEN; 28, identifier:doc_list; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:cleaned_doc_list; 32, call; 32, 33; 32, 34; 33, identifier:list; 34, argument_list; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:tokenizer; 38, call; 38, 39; 38, 40; 39, identifier:RegexpTokenizer; 40, argument_list; 40, 41; 41, string:r"[a-zA-Z]+"; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:stopwords; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:__get_words_to_ignore; 49, argument_list; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:dict_words; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:__get_words_to_consider; 57, argument_list; 58, for_statement; 58, 59; 58, 60; 58, 61; 59, identifier:doc; 60, identifier:doc_list; 61, block; 61, 62; 61, 70; 61, 79; 61, 91; 61, 103; 61, 115; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:lower; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:doc; 68, identifier:lower; 69, argument_list; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:tokens; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:tokenizer; 76, identifier:tokenize; 77, argument_list; 77, 78; 78, identifier:lower; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:tokens; 82, list_comprehension; 82, 83; 82, 84; 82, 87; 83, identifier:tok; 84, for_in_clause; 84, 85; 84, 86; 85, identifier:tok; 86, identifier:tokens; 87, if_clause; 87, 88; 88, comparison_operator:in; 88, 89; 88, 90; 89, identifier:tok; 90, identifier:dict_words; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:tokens; 94, list_comprehension; 94, 95; 94, 96; 94, 99; 95, identifier:tok; 96, for_in_clause; 96, 97; 96, 98; 97, identifier:tok; 98, identifier:tokens; 99, if_clause; 99, 100; 100, comparison_operator:not; 100, 101; 100, 102; 101, identifier:tok; 102, identifier:stopwords; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:tokens; 106, list_comprehension; 106, 107; 106, 108; 106, 111; 107, identifier:tok; 108, for_in_clause; 108, 109; 108, 110; 109, identifier:tok; 110, identifier:tokens; 111, if_clause; 111, 112; 112, comparison_operator:is; 112, 113; 112, 114; 113, identifier:tok; 114, None; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:cleaned_doc_list; 119, identifier:append; 120, argument_list; 120, 121; 121, identifier:tokens; 122, return_statement; 122, 123; 123, identifier:cleaned_doc_list | def __clean_and_tokenize(self, doc_list):
doc_list = filter(
lambda x: x is not None and len(x) <= GitSuggest.MAX_DESC_LEN,
doc_list,
)
cleaned_doc_list = list()
tokenizer = RegexpTokenizer(r"[a-zA-Z]+")
stopwords = self.__get_words_to_ignore()
dict_words = self.__get_words_to_consider()
for doc in doc_list:
lower = doc.lower()
tokens = tokenizer.tokenize(lower)
tokens = [tok for tok in tokens if tok in dict_words]
tokens = [tok for tok in tokens if tok not in stopwords]
tokens = [tok for tok in tokens if tok is not None]
cleaned_doc_list.append(tokens)
return cleaned_doc_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:__get_search_results; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:url; 6, identifier:limit; 7, identifier:order_by; 8, identifier:sort_order; 9, identifier:filter; 10, block; 10, 11; 10, 27; 10, 59; 10, 93; 10, 99; 10, 131; 10, 142; 10, 149; 10, 164; 10, 220; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:order_by_options; 14, list:['search_rank', 'series_id', 'title', 'units', 'frequency',
'seasonal_adjustment', 'realtime_start', 'realtime_end', 'last_updated',
'observation_start', 'observation_end', 'popularity']; 14, 15; 14, 16; 14, 17; 14, 18; 14, 19; 14, 20; 14, 21; 14, 22; 14, 23; 14, 24; 14, 25; 14, 26; 15, string:'search_rank'; 16, string:'series_id'; 17, string:'title'; 18, string:'units'; 19, string:'frequency'; 20, string:'seasonal_adjustment'; 21, string:'realtime_start'; 22, string:'realtime_end'; 23, string:'last_updated'; 24, string:'observation_start'; 25, string:'observation_end'; 26, string:'popularity'; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:order_by; 30, None; 31, block; 31, 32; 32, if_statement; 32, 33; 32, 36; 32, 45; 33, comparison_operator:in; 33, 34; 33, 35; 34, identifier:order_by; 35, identifier:order_by_options; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:url; 40, binary_operator:+; 40, 41; 40, 44; 41, binary_operator:+; 41, 42; 41, 43; 42, identifier:url; 43, string:'&order_by='; 44, identifier:order_by; 45, else_clause; 45, 46; 46, block; 46, 47; 47, raise_statement; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:ValueError; 50, argument_list; 50, 51; 51, binary_operator:%; 51, 52; 51, 53; 52, string:'%s is not in the valid list of order_by options: %s'; 53, tuple; 53, 54; 53, 55; 54, identifier:order_by; 55, call; 55, 56; 55, 57; 56, identifier:str; 57, argument_list; 57, 58; 58, identifier:order_by_options; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:is; 60, 61; 60, 62; 61, identifier:filter; 62, None; 63, block; 63, 64; 64, if_statement; 64, 65; 64, 71; 64, 86; 65, comparison_operator:==; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:len; 68, argument_list; 68, 69; 69, identifier:filter; 70, integer:2; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:url; 75, binary_operator:+; 75, 76; 75, 77; 76, identifier:url; 77, binary_operator:%; 77, 78; 77, 79; 78, string:'&filter_variable=%s&filter_value=%s'; 79, tuple; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:filter; 82, integer:0; 83, subscript; 83, 84; 83, 85; 84, identifier:filter; 85, integer:1; 86, else_clause; 86, 87; 87, block; 87, 88; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:ValueError; 91, argument_list; 91, 92; 92, string:'Filter should be a 2 item tuple like (filter_variable, filter_value)'; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:sort_order_options; 96, list:['asc', 'desc']; 96, 97; 96, 98; 97, string:'asc'; 98, string:'desc'; 99, if_statement; 99, 100; 99, 103; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:sort_order; 102, None; 103, block; 103, 104; 104, if_statement; 104, 105; 104, 108; 104, 117; 105, comparison_operator:in; 105, 106; 105, 107; 106, identifier:sort_order; 107, identifier:sort_order_options; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:url; 112, binary_operator:+; 112, 113; 112, 116; 113, binary_operator:+; 113, 114; 113, 115; 114, identifier:url; 115, string:'&sort_order='; 116, identifier:sort_order; 117, else_clause; 117, 118; 118, block; 118, 119; 119, raise_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:ValueError; 122, argument_list; 122, 123; 123, binary_operator:%; 123, 124; 123, 125; 124, string:'%s is not in the valid list of sort_order options: %s'; 125, tuple; 125, 126; 125, 127; 126, identifier:sort_order; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:sort_order_options; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, pattern_list; 133, 134; 133, 135; 134, identifier:data; 135, identifier:num_results_total; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:__do_series_search; 140, argument_list; 140, 141; 141, identifier:url; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:is; 143, 144; 143, 145; 144, identifier:data; 145, None; 146, block; 146, 147; 147, return_statement; 147, 148; 148, identifier:data; 149, if_statement; 149, 150; 149, 153; 149, 158; 150, comparison_operator:==; 150, 151; 150, 152; 151, identifier:limit; 152, integer:0; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:max_results_needed; 157, identifier:num_results_total; 158, else_clause; 158, 159; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:max_results_needed; 163, identifier:limit; 164, if_statement; 164, 165; 164, 170; 165, comparison_operator:>; 165, 166; 165, 167; 166, identifier:max_results_needed; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:max_results_per_request; 170, block; 170, 171; 171, for_statement; 171, 172; 171, 173; 171, 184; 172, identifier:i; 173, call; 173, 174; 173, 175; 174, identifier:range; 175, argument_list; 175, 176; 175, 177; 176, integer:1; 177, binary_operator:+; 177, 178; 177, 183; 178, binary_operator://; 178, 179; 178, 180; 179, identifier:max_results_needed; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:max_results_per_request; 183, integer:1; 184, block; 184, 185; 184, 193; 184, 211; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:offset; 188, binary_operator:*; 188, 189; 188, 190; 189, identifier:i; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:max_results_per_request; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, pattern_list; 195, 196; 195, 197; 196, identifier:next_data; 197, identifier:_; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:__do_series_search; 202, argument_list; 202, 203; 203, binary_operator:+; 203, 204; 203, 207; 204, binary_operator:+; 204, 205; 204, 206; 205, identifier:url; 206, string:'&offset='; 207, call; 207, 208; 207, 209; 208, identifier:str; 209, argument_list; 209, 210; 210, identifier:offset; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:data; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:data; 217, identifier:append; 218, argument_list; 218, 219; 219, identifier:next_data; 220, return_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:data; 224, identifier:head; 225, argument_list; 225, 226; 226, identifier:max_results_needed | def __get_search_results(self, url, limit, order_by, sort_order, filter):
order_by_options = ['search_rank', 'series_id', 'title', 'units', 'frequency',
'seasonal_adjustment', 'realtime_start', 'realtime_end', 'last_updated',
'observation_start', 'observation_end', 'popularity']
if order_by is not None:
if order_by in order_by_options:
url = url + '&order_by=' + order_by
else:
raise ValueError('%s is not in the valid list of order_by options: %s' % (order_by, str(order_by_options)))
if filter is not None:
if len(filter) == 2:
url = url + '&filter_variable=%s&filter_value=%s' % (filter[0], filter[1])
else:
raise ValueError('Filter should be a 2 item tuple like (filter_variable, filter_value)')
sort_order_options = ['asc', 'desc']
if sort_order is not None:
if sort_order in sort_order_options:
url = url + '&sort_order=' + sort_order
else:
raise ValueError('%s is not in the valid list of sort_order options: %s' % (sort_order, str(sort_order_options)))
data, num_results_total = self.__do_series_search(url)
if data is None:
return data
if limit == 0:
max_results_needed = num_results_total
else:
max_results_needed = limit
if max_results_needed > self.max_results_per_request:
for i in range(1, max_results_needed // self.max_results_per_request + 1):
offset = i * self.max_results_per_request
next_data, _ = self.__do_series_search(url + '&offset=' + str(offset))
data = data.append(next_data)
return data.head(max_results_needed) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:text; 6, default_parameter; 6, 7; 6, 8; 7, identifier:limit; 8, integer:1000; 9, default_parameter; 9, 10; 9, 11; 10, identifier:order_by; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:sort_order; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:filter; 17, None; 18, block; 18, 19; 18, 32; 18, 45; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:url; 22, binary_operator:%; 22, 23; 22, 24; 23, string:"%s/series/search?search_text=%s&"; 24, tuple; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:root_url; 28, call; 28, 29; 28, 30; 29, identifier:quote_plus; 30, argument_list; 30, 31; 31, identifier:text; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:info; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:__get_search_results; 39, argument_list; 39, 40; 39, 41; 39, 42; 39, 43; 39, 44; 40, identifier:url; 41, identifier:limit; 42, identifier:order_by; 43, identifier:sort_order; 44, identifier:filter; 45, return_statement; 45, 46; 46, identifier:info | def search(self, text, limit=1000, order_by=None, sort_order=None, filter=None):
url = "%s/series/search?search_text=%s&" % (self.root_url,
quote_plus(text))
info = self.__get_search_results(url, limit, order_by, sort_order, filter)
return info |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:search_by_release; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:release_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:limit; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:order_by; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:sort_order; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:filter; 17, None; 18, block; 18, 19; 18, 29; 18, 42; 18, 57; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:url; 22, binary_operator:%; 22, 23; 22, 24; 23, string:"%s/release/series?release_id=%d"; 24, tuple; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:root_url; 28, identifier:release_id; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:info; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:__get_search_results; 36, argument_list; 36, 37; 36, 38; 36, 39; 36, 40; 36, 41; 37, identifier:url; 38, identifier:limit; 39, identifier:order_by; 40, identifier:sort_order; 41, identifier:filter; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:info; 45, None; 46, block; 46, 47; 47, raise_statement; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:ValueError; 50, argument_list; 50, 51; 51, binary_operator:+; 51, 52; 51, 53; 52, string:'No series exists for release id: '; 53, call; 53, 54; 53, 55; 54, identifier:str; 55, argument_list; 55, 56; 56, identifier:release_id; 57, return_statement; 57, 58; 58, identifier:info | def search_by_release(self, release_id, limit=0, order_by=None, sort_order=None, filter=None):
url = "%s/release/series?release_id=%d" % (self.root_url, release_id)
info = self.__get_search_results(url, limit, order_by, sort_order, filter)
if info is None:
raise ValueError('No series exists for release id: ' + str(release_id))
return info |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:search_by_category; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:category_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:limit; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:order_by; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:sort_order; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:filter; 17, None; 18, block; 18, 19; 18, 29; 18, 42; 18, 57; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:url; 22, binary_operator:%; 22, 23; 22, 24; 23, string:"%s/category/series?category_id=%d&"; 24, tuple; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:root_url; 28, identifier:category_id; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:info; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:__get_search_results; 36, argument_list; 36, 37; 36, 38; 36, 39; 36, 40; 36, 41; 37, identifier:url; 38, identifier:limit; 39, identifier:order_by; 40, identifier:sort_order; 41, identifier:filter; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:info; 45, None; 46, block; 46, 47; 47, raise_statement; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:ValueError; 50, argument_list; 50, 51; 51, binary_operator:+; 51, 52; 51, 53; 52, string:'No series exists for category id: '; 53, call; 53, 54; 53, 55; 54, identifier:str; 55, argument_list; 55, 56; 56, identifier:category_id; 57, return_statement; 57, 58; 58, identifier:info | def search_by_category(self, category_id, limit=0, order_by=None, sort_order=None, filter=None):
url = "%s/category/series?category_id=%d&" % (self.root_url,
category_id)
info = self.__get_search_results(url, limit, order_by, sort_order, filter)
if info is None:
raise ValueError('No series exists for category id: ' + str(category_id))
return info |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:format_name; 3, parameters; 3, 4; 4, identifier:subject; 5, block; 5, 6; 5, 31; 6, if_statement; 6, 7; 6, 14; 7, call; 7, 8; 7, 9; 8, identifier:isinstance; 9, argument_list; 9, 10; 9, 11; 10, identifier:subject; 11, attribute; 11, 12; 11, 13; 12, identifier:x509; 13, identifier:Name; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:subject; 18, list_comprehension; 18, 19; 18, 28; 19, tuple; 19, 20; 19, 25; 20, subscript; 20, 21; 20, 22; 21, identifier:OID_NAME_MAPPINGS; 22, attribute; 22, 23; 22, 24; 23, identifier:s; 24, identifier:oid; 25, attribute; 25, 26; 25, 27; 26, identifier:s; 27, identifier:value; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:s; 30, identifier:subject; 31, return_statement; 31, 32; 32, binary_operator:%; 32, 33; 32, 34; 33, string:'/%s'; 34, parenthesized_expression; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:'/'; 38, identifier:join; 39, argument_list; 39, 40; 40, list_comprehension; 40, 41; 40, 52; 41, binary_operator:%; 41, 42; 41, 43; 42, string:'%s=%s'; 43, tuple; 43, 44; 43, 48; 44, call; 44, 45; 44, 46; 45, identifier:force_text; 46, argument_list; 46, 47; 47, identifier:k; 48, call; 48, 49; 48, 50; 49, identifier:force_text; 50, argument_list; 50, 51; 51, identifier:v; 52, for_in_clause; 52, 53; 52, 56; 53, pattern_list; 53, 54; 53, 55; 54, identifier:k; 55, identifier:v; 56, identifier:subject | def format_name(subject):
if isinstance(subject, x509.Name):
subject = [(OID_NAME_MAPPINGS[s.oid], s.value) for s in subject]
return '/%s' % ('/'.join(['%s=%s' % (force_text(k), force_text(v)) for k, v in subject])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_name; 3, parameters; 3, 4; 4, identifier:name; 5, block; 5, 6; 5, 14; 5, 20; 5, 67; 5, 105; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:name; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:name; 12, identifier:strip; 13, argument_list; 14, if_statement; 14, 15; 14, 17; 15, not_operator; 15, 16; 16, identifier:name; 17, block; 17, 18; 18, return_statement; 18, 19; 19, list:[]; 20, try_statement; 20, 21; 20, 50; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:items; 25, list_comprehension; 25, 26; 25, 42; 26, tuple; 26, 27; 26, 36; 27, subscript; 27, 28; 27, 29; 28, identifier:NAME_CASE_MAPPINGS; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:t; 33, integer:0; 34, identifier:upper; 35, argument_list; 36, call; 36, 37; 36, 38; 37, identifier:force_text; 38, argument_list; 38, 39; 39, subscript; 39, 40; 39, 41; 40, identifier:t; 41, integer:2; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:t; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:NAME_RE; 47, identifier:findall; 48, argument_list; 48, 49; 49, identifier:name; 50, except_clause; 50, 51; 50, 55; 51, as_pattern; 51, 52; 51, 53; 52, identifier:KeyError; 53, as_pattern_target; 53, 54; 54, identifier:e; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:ValueError; 59, argument_list; 59, 60; 60, binary_operator:%; 60, 61; 60, 62; 61, string:'Unknown x509 name field: %s'; 62, subscript; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:e; 65, identifier:args; 66, integer:0; 67, for_statement; 67, 68; 67, 71; 67, 76; 68, pattern_list; 68, 69; 68, 70; 69, identifier:key; 70, identifier:oid; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:NAME_OID_MAPPINGS; 74, identifier:items; 75, argument_list; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 97; 78, boolean_operator:and; 78, 79; 78, 94; 79, comparison_operator:>; 79, 80; 79, 93; 80, call; 80, 81; 80, 82; 81, identifier:sum; 82, generator_expression; 82, 83; 82, 84; 82, 87; 83, integer:1; 84, for_in_clause; 84, 85; 84, 86; 85, identifier:t; 86, identifier:items; 87, if_clause; 87, 88; 88, comparison_operator:==; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:t; 91, integer:0; 92, identifier:key; 93, integer:1; 94, comparison_operator:not; 94, 95; 94, 96; 95, identifier:oid; 96, identifier:MULTIPLE_OIDS; 97, block; 97, 98; 98, raise_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:ValueError; 101, argument_list; 101, 102; 102, binary_operator:%; 102, 103; 102, 104; 103, string:'Subject contains multiple "%s" fields'; 104, identifier:key; 105, return_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:sort_name; 108, argument_list; 108, 109; 109, identifier:items | def parse_name(name):
name = name.strip()
if not name:
return []
try:
items = [(NAME_CASE_MAPPINGS[t[0].upper()], force_text(t[2])) for t in NAME_RE.findall(name)]
except KeyError as e:
raise ValueError('Unknown x509 name field: %s' % e.args[0])
for key, oid in NAME_OID_MAPPINGS.items():
if sum(1 for t in items if t[0] == key) > 1 and oid not in MULTIPLE_OIDS:
raise ValueError('Subject contains multiple "%s" fields' % key)
return sort_name(items) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_general_name; 3, parameters; 3, 4; 4, identifier:name; 5, block; 5, 6; 5, 13; 5, 17; 5, 26; 5, 49; 5, 205; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:name; 9, call; 9, 10; 9, 11; 10, identifier:force_text; 11, argument_list; 11, 12; 12, identifier:name; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:typ; 16, None; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:match; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:GENERAL_NAME_RE; 23, identifier:match; 24, argument_list; 24, 25; 25, identifier:name; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:match; 29, None; 30, block; 30, 31; 30, 41; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, pattern_list; 33, 34; 33, 35; 34, identifier:typ; 35, identifier:name; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:match; 39, identifier:groups; 40, argument_list; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:typ; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:typ; 47, identifier:lower; 48, argument_list; 49, if_statement; 49, 50; 49, 53; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:typ; 52, None; 53, block; 53, 54; 53, 76; 53, 97; 53, 119; 53, 135; 53, 151; 53, 198; 54, if_statement; 54, 55; 54, 62; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:re; 58, identifier:match; 59, argument_list; 59, 60; 59, 61; 60, string:'[a-z0-9]{2,}://'; 61, identifier:name; 62, block; 62, 63; 63, try_statement; 63, 64; 63, 72; 64, block; 64, 65; 65, return_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:x509; 69, identifier:UniformResourceIdentifier; 70, argument_list; 70, 71; 71, identifier:name; 72, except_clause; 72, 73; 72, 74; 73, identifier:Exception; 74, block; 74, 75; 75, pass_statement; 76, if_statement; 76, 77; 76, 80; 77, comparison_operator:in; 77, 78; 77, 79; 78, string:'@'; 79, identifier:name; 80, block; 80, 81; 81, try_statement; 81, 82; 81, 93; 82, block; 82, 83; 83, return_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:x509; 87, identifier:RFC822Name; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:validate_email; 91, argument_list; 91, 92; 92, identifier:name; 93, except_clause; 93, 94; 93, 95; 94, identifier:Exception; 95, block; 95, 96; 96, pass_statement; 97, if_statement; 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:name; 103, identifier:strip; 104, argument_list; 105, identifier:startswith; 106, argument_list; 106, 107; 107, string:'/'; 108, block; 108, 109; 109, return_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:x509; 113, identifier:DirectoryName; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:x509_name; 117, argument_list; 117, 118; 118, identifier:name; 119, try_statement; 119, 120; 119, 131; 120, block; 120, 121; 121, return_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:x509; 125, identifier:IPAddress; 126, argument_list; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:ip_address; 129, argument_list; 129, 130; 130, identifier:name; 131, except_clause; 131, 132; 131, 133; 132, identifier:ValueError; 133, block; 133, 134; 134, pass_statement; 135, try_statement; 135, 136; 135, 147; 136, block; 136, 137; 137, return_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:x509; 141, identifier:IPAddress; 142, argument_list; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:ip_network; 145, argument_list; 145, 146; 146, identifier:name; 147, except_clause; 147, 148; 147, 149; 148, identifier:ValueError; 149, block; 149, 150; 150, pass_statement; 151, if_statement; 151, 152; 151, 158; 151, 170; 151, 189; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:name; 155, identifier:startswith; 156, argument_list; 156, 157; 157, string:'*.'; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:idna; 163, identifier:encode; 164, argument_list; 164, 165; 165, subscript; 165, 166; 165, 167; 166, identifier:name; 167, slice; 167, 168; 167, 169; 168, integer:2; 169, colon; 170, elif_clause; 170, 171; 170, 177; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:name; 174, identifier:startswith; 175, argument_list; 175, 176; 176, string:'.'; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:idna; 182, identifier:encode; 183, argument_list; 183, 184; 184, subscript; 184, 185; 184, 186; 185, identifier:name; 186, slice; 186, 187; 186, 188; 187, integer:1; 188, colon; 189, else_clause; 189, 190; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:idna; 195, identifier:encode; 196, argument_list; 196, 197; 197, identifier:name; 198, return_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:x509; 202, identifier:DNSName; 203, argument_list; 203, 204; 204, identifier:name; 205, if_statement; 205, 206; 205, 209; 205, 217; 205, 232; 205, 274; 205, 291; 205, 412; 205, 427; 206, comparison_operator:==; 206, 207; 206, 208; 207, identifier:typ; 208, string:'uri'; 209, block; 209, 210; 210, return_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:x509; 214, identifier:UniformResourceIdentifier; 215, argument_list; 215, 216; 216, identifier:name; 217, elif_clause; 217, 218; 217, 221; 218, comparison_operator:==; 218, 219; 218, 220; 219, identifier:typ; 220, string:'email'; 221, block; 221, 222; 222, return_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:x509; 226, identifier:RFC822Name; 227, argument_list; 227, 228; 228, call; 228, 229; 228, 230; 229, identifier:validate_email; 230, argument_list; 230, 231; 231, identifier:name; 232, elif_clause; 232, 233; 232, 236; 233, comparison_operator:==; 233, 234; 233, 235; 234, identifier:typ; 235, string:'ip'; 236, block; 236, 237; 236, 253; 236, 269; 237, try_statement; 237, 238; 237, 249; 238, block; 238, 239; 239, return_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:x509; 243, identifier:IPAddress; 244, argument_list; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:ip_address; 247, argument_list; 247, 248; 248, identifier:name; 249, except_clause; 249, 250; 249, 251; 250, identifier:ValueError; 251, block; 251, 252; 252, pass_statement; 253, try_statement; 253, 254; 253, 265; 254, block; 254, 255; 255, return_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:x509; 259, identifier:IPAddress; 260, argument_list; 260, 261; 261, call; 261, 262; 261, 263; 262, identifier:ip_network; 263, argument_list; 263, 264; 264, identifier:name; 265, except_clause; 265, 266; 265, 267; 266, identifier:ValueError; 267, block; 267, 268; 268, pass_statement; 269, raise_statement; 269, 270; 270, call; 270, 271; 270, 272; 271, identifier:ValueError; 272, argument_list; 272, 273; 273, string:'Could not parse IP address.'; 274, elif_clause; 274, 275; 274, 278; 275, comparison_operator:==; 275, 276; 275, 277; 276, identifier:typ; 277, string:'rid'; 278, block; 278, 279; 279, return_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:x509; 283, identifier:RegisteredID; 284, argument_list; 284, 285; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:x509; 288, identifier:ObjectIdentifier; 289, argument_list; 289, 290; 290, identifier:name; 291, elif_clause; 291, 292; 291, 295; 292, comparison_operator:==; 292, 293; 292, 294; 293, identifier:typ; 294, string:'othername'; 295, block; 295, 296; 295, 300; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:regex; 299, string:"(.*);(.*):(.*)"; 300, if_statement; 300, 301; 300, 310; 300, 403; 301, comparison_operator:is; 301, 302; 301, 309; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:re; 305, identifier:match; 306, argument_list; 306, 307; 306, 308; 307, identifier:regex; 308, identifier:name; 309, None; 310, block; 310, 311; 310, 328; 310, 337; 310, 388; 310, 395; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 317; 313, pattern_list; 313, 314; 313, 315; 313, 316; 314, identifier:oid; 315, identifier:asn_typ; 316, identifier:val; 317, call; 317, 318; 317, 327; 318, attribute; 318, 319; 318, 326; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:re; 322, identifier:match; 323, argument_list; 323, 324; 323, 325; 324, identifier:regex; 325, identifier:name; 326, identifier:groups; 327, argument_list; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:oid; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:x509; 334, identifier:ObjectIdentifier; 335, argument_list; 335, 336; 336, identifier:oid; 337, if_statement; 337, 338; 337, 341; 337, 351; 337, 379; 338, comparison_operator:==; 338, 339; 338, 340; 339, identifier:asn_typ; 340, string:'UTF8'; 341, block; 341, 342; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 345; 344, identifier:val; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:val; 348, identifier:encode; 349, argument_list; 349, 350; 350, string:'utf-8'; 351, elif_clause; 351, 352; 351, 355; 352, comparison_operator:==; 352, 353; 352, 354; 353, identifier:asn_typ; 354, string:'OctetString'; 355, block; 355, 356; 355, 368; 356, expression_statement; 356, 357; 357, assignment; 357, 358; 357, 359; 358, identifier:val; 359, call; 359, 360; 359, 361; 360, identifier:bytes; 361, argument_list; 361, 362; 362, call; 362, 363; 362, 366; 363, attribute; 363, 364; 363, 365; 364, identifier:bytearray; 365, identifier:fromhex; 366, argument_list; 366, 367; 367, identifier:val; 368, expression_statement; 368, 369; 369, assignment; 369, 370; 369, 371; 370, identifier:val; 371, call; 371, 372; 371, 378; 372, attribute; 372, 373; 372, 377; 373, call; 373, 374; 373, 375; 374, identifier:OctetString; 375, argument_list; 375, 376; 376, identifier:val; 377, identifier:dump; 378, argument_list; 379, else_clause; 379, 380; 380, block; 380, 381; 381, raise_statement; 381, 382; 382, call; 382, 383; 382, 384; 383, identifier:ValueError; 384, argument_list; 384, 385; 385, binary_operator:%; 385, 386; 385, 387; 386, string:'Unsupported ASN type in otherName: %s'; 387, identifier:asn_typ; 388, expression_statement; 388, 389; 389, assignment; 389, 390; 389, 391; 390, identifier:val; 391, call; 391, 392; 391, 393; 392, identifier:force_bytes; 393, argument_list; 393, 394; 394, identifier:val; 395, return_statement; 395, 396; 396, call; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:x509; 399, identifier:OtherName; 400, argument_list; 400, 401; 400, 402; 401, identifier:oid; 402, identifier:val; 403, else_clause; 403, 404; 404, block; 404, 405; 405, raise_statement; 405, 406; 406, call; 406, 407; 406, 408; 407, identifier:ValueError; 408, argument_list; 408, 409; 409, binary_operator:%; 409, 410; 409, 411; 410, string:'Incorrect otherName format: %s'; 411, identifier:name; 412, elif_clause; 412, 413; 412, 416; 413, comparison_operator:==; 413, 414; 413, 415; 414, identifier:typ; 415, string:'dirname'; 416, block; 416, 417; 417, return_statement; 417, 418; 418, call; 418, 419; 418, 422; 419, attribute; 419, 420; 419, 421; 420, identifier:x509; 421, identifier:DirectoryName; 422, argument_list; 422, 423; 423, call; 423, 424; 423, 425; 424, identifier:x509_name; 425, argument_list; 425, 426; 426, identifier:name; 427, else_clause; 427, 428; 428, block; 428, 429; 428, 476; 429, if_statement; 429, 430; 429, 436; 429, 448; 429, 467; 430, call; 430, 431; 430, 434; 431, attribute; 431, 432; 431, 433; 432, identifier:name; 433, identifier:startswith; 434, argument_list; 434, 435; 435, string:'*.'; 436, block; 436, 437; 437, expression_statement; 437, 438; 438, call; 438, 439; 438, 442; 439, attribute; 439, 440; 439, 441; 440, identifier:idna; 441, identifier:encode; 442, argument_list; 442, 443; 443, subscript; 443, 444; 443, 445; 444, identifier:name; 445, slice; 445, 446; 445, 447; 446, integer:2; 447, colon; 448, elif_clause; 448, 449; 448, 455; 449, call; 449, 450; 449, 453; 450, attribute; 450, 451; 450, 452; 451, identifier:name; 452, identifier:startswith; 453, argument_list; 453, 454; 454, string:'.'; 455, block; 455, 456; 456, expression_statement; 456, 457; 457, call; 457, 458; 457, 461; 458, attribute; 458, 459; 458, 460; 459, identifier:idna; 460, identifier:encode; 461, argument_list; 461, 462; 462, subscript; 462, 463; 462, 464; 463, identifier:name; 464, slice; 464, 465; 464, 466; 465, integer:1; 466, colon; 467, else_clause; 467, 468; 468, block; 468, 469; 469, expression_statement; 469, 470; 470, call; 470, 471; 470, 474; 471, attribute; 471, 472; 471, 473; 472, identifier:idna; 473, identifier:encode; 474, argument_list; 474, 475; 475, identifier:name; 476, return_statement; 476, 477; 477, call; 477, 478; 477, 481; 478, attribute; 478, 479; 478, 480; 479, identifier:x509; 480, identifier:DNSName; 481, argument_list; 481, 482; 482, identifier:name | def parse_general_name(name):
name = force_text(name)
typ = None
match = GENERAL_NAME_RE.match(name)
if match is not None:
typ, name = match.groups()
typ = typ.lower()
if typ is None:
if re.match('[a-z0-9]{2,}://', name):
try:
return x509.UniformResourceIdentifier(name)
except Exception:
pass
if '@' in name:
try:
return x509.RFC822Name(validate_email(name))
except Exception:
pass
if name.strip().startswith('/'):
return x509.DirectoryName(x509_name(name))
try:
return x509.IPAddress(ip_address(name))
except ValueError:
pass
try:
return x509.IPAddress(ip_network(name))
except ValueError:
pass
if name.startswith('*.'):
idna.encode(name[2:])
elif name.startswith('.'):
idna.encode(name[1:])
else:
idna.encode(name)
return x509.DNSName(name)
if typ == 'uri':
return x509.UniformResourceIdentifier(name)
elif typ == 'email':
return x509.RFC822Name(validate_email(name))
elif typ == 'ip':
try:
return x509.IPAddress(ip_address(name))
except ValueError:
pass
try:
return x509.IPAddress(ip_network(name))
except ValueError:
pass
raise ValueError('Could not parse IP address.')
elif typ == 'rid':
return x509.RegisteredID(x509.ObjectIdentifier(name))
elif typ == 'othername':
regex = "(.*);(.*):(.*)"
if re.match(regex, name) is not None:
oid, asn_typ, val = re.match(regex, name).groups()
oid = x509.ObjectIdentifier(oid)
if asn_typ == 'UTF8':
val = val.encode('utf-8')
elif asn_typ == 'OctetString':
val = bytes(bytearray.fromhex(val))
val = OctetString(val).dump()
else:
raise ValueError('Unsupported ASN type in otherName: %s' % asn_typ)
val = force_bytes(val)
return x509.OtherName(oid, val)
else:
raise ValueError('Incorrect otherName format: %s' % name)
elif typ == 'dirname':
return x509.DirectoryName(x509_name(name))
else:
if name.startswith('*.'):
idna.encode(name[2:])
elif name.startswith('.'):
idna.encode(name[1:])
else:
idna.encode(name)
return x509.DNSName(name) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:render; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 20; 9, 35; 9, 59; 9, 75; 9, 88; 9, 94; 9, 132; 9, 147; 9, 181; 9, 191; 9, 200; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:pretty; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:kwargs; 16, identifier:pop; 17, argument_list; 17, 18; 17, 19; 18, string:"pretty"; 19, False; 20, if_statement; 20, 21; 20, 28; 21, boolean_operator:and; 21, 22; 21, 23; 22, identifier:pretty; 23, comparison_operator:!=; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_stable; 27, string:"pretty"; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_stable; 34, False; 35, for_statement; 35, 36; 35, 37; 35, 38; 36, identifier:arg; 37, identifier:args; 38, block; 38, 39; 38, 45; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:_stable; 44, False; 45, if_statement; 45, 46; 45, 51; 46, call; 46, 47; 46, 48; 47, identifier:isinstance; 48, argument_list; 48, 49; 48, 50; 49, identifier:arg; 50, identifier:dict; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:inject; 57, argument_list; 57, 58; 58, identifier:arg; 59, if_statement; 59, 60; 59, 61; 60, identifier:kwargs; 61, block; 61, 62; 61, 68; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_stable; 67, False; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:inject; 73, argument_list; 73, 74; 74, identifier:kwargs; 75, if_statement; 75, 76; 75, 83; 76, boolean_operator:and; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:_stable; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:_render; 83, block; 83, 84; 84, return_statement; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:_render; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:pretty_pre; 91, assignment; 91, 92; 91, 93; 92, identifier:pretty_inner; 93, string:""; 94, if_statement; 94, 95; 94, 96; 95, identifier:pretty; 96, block; 96, 97; 96, 111; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:pretty_pre; 100, conditional_expression:if; 100, 101; 100, 109; 100, 110; 101, binary_operator:+; 101, 102; 101, 103; 102, string:"\n"; 103, parenthesized_expression; 103, 104; 104, binary_operator:*; 104, 105; 104, 106; 105, string:"\t"; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:_depth; 109, identifier:pretty; 110, string:""; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:pretty_inner; 114, conditional_expression:if; 114, 115; 114, 123; 114, 131; 115, binary_operator:+; 115, 116; 115, 117; 116, string:"\n"; 117, parenthesized_expression; 117, 118; 118, binary_operator:*; 118, 119; 118, 120; 119, string:"\t"; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:_depth; 123, comparison_operator:>; 123, 124; 123, 130; 124, call; 124, 125; 124, 126; 125, identifier:len; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:childs; 130, integer:1; 131, string:""; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:inner; 135, conditional_expression:if; 135, 136; 135, 142; 135, 146; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:render_childs; 140, argument_list; 140, 141; 141, identifier:pretty; 142, not_operator; 142, 143; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:_void; 146, string:""; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:tag_data; 150, subscript; 150, 151; 150, 170; 151, tuple; 151, 152; 151, 153; 151, 158; 151, 163; 151, 164; 151, 165; 152, identifier:pretty_pre; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:_get__tag; 157, argument_list; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:render_attrs; 162, argument_list; 163, identifier:inner; 164, identifier:pretty_inner; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:_get__tag; 169, argument_list; 170, slice; 170, 171; 170, 172; 171, colon; 172, binary_operator:-; 172, 173; 172, 174; 173, integer:6; 174, subscript; 174, 175; 174, 178; 175, list:[0, 3]; 175, 176; 175, 177; 176, integer:0; 177, integer:3; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:_void; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:_render; 186, binary_operator:%; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:_template; 190, identifier:tag_data; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:_stable; 196, conditional_expression:if; 196, 197; 196, 198; 196, 199; 197, string:"pretty"; 198, identifier:pretty; 199, True; 200, return_statement; 200, 201; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:_render | def render(self, *args, **kwargs):
pretty = kwargs.pop("pretty", False)
if pretty and self._stable != "pretty":
self._stable = False
for arg in args:
self._stable = False
if isinstance(arg, dict):
self.inject(arg)
if kwargs:
self._stable = False
self.inject(kwargs)
if self._stable and self._render:
return self._render
pretty_pre = pretty_inner = ""
if pretty:
pretty_pre = "\n" + ("\t" * self._depth) if pretty else ""
pretty_inner = "\n" + ("\t" * self._depth) if len(self.childs) > 1 else ""
inner = self.render_childs(pretty) if not self._void else ""
tag_data = (
pretty_pre,
self._get__tag(),
self.render_attrs(),
inner,
pretty_inner,
self._get__tag()
)[: 6 - [0, 3][self._void]]
self._render = self._template % tag_data
self._stable = "pretty" if pretty else True
return self._render |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:_insert; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:dom_group; 6, default_parameter; 6, 7; 6, 8; 7, identifier:idx; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:prepend; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:name; 14, None; 15, block; 15, 16; 15, 27; 15, 50; 16, if_statement; 16, 17; 16, 22; 17, boolean_operator:and; 17, 18; 17, 19; 18, identifier:idx; 19, comparison_operator:<; 19, 20; 19, 21; 20, identifier:idx; 21, integer:0; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:idx; 26, integer:0; 27, if_statement; 27, 28; 27, 29; 27, 34; 28, identifier:prepend; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:idx; 33, integer:0; 34, else_clause; 34, 35; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:idx; 39, conditional_expression:if; 39, 40; 39, 41; 39, 44; 40, identifier:idx; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:idx; 43, None; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:childs; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:is; 51, 52; 51, 53; 52, identifier:dom_group; 53, None; 54, block; 54, 55; 54, 76; 55, if_statement; 55, 56; 55, 70; 56, boolean_operator:or; 56, 57; 56, 63; 57, not_operator; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:isinstance; 60, argument_list; 60, 61; 60, 62; 61, identifier:dom_group; 62, identifier:Iterable; 63, call; 63, 64; 63, 65; 64, identifier:isinstance; 65, argument_list; 65, 66; 65, 67; 66, identifier:dom_group; 67, tuple; 67, 68; 67, 69; 68, identifier:DOMElement; 69, identifier:str; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:dom_group; 74, list:[dom_group]; 74, 75; 75, identifier:dom_group; 76, for_statement; 76, 77; 76, 80; 76, 84; 77, pattern_list; 77, 78; 77, 79; 78, identifier:i_group; 79, identifier:elem; 80, call; 80, 81; 80, 82; 81, identifier:enumerate; 82, argument_list; 82, 83; 83, identifier:dom_group; 84, block; 84, 85; 85, if_statement; 85, 86; 85, 89; 86, comparison_operator:is; 86, 87; 86, 88; 87, identifier:elem; 88, None; 89, block; 89, 90; 89, 102; 89, 117; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:childs; 96, identifier:insert; 97, argument_list; 97, 98; 97, 101; 98, binary_operator:+; 98, 99; 98, 100; 99, identifier:idx; 100, identifier:i_group; 101, identifier:elem; 102, if_statement; 102, 103; 102, 110; 103, call; 103, 104; 103, 105; 104, identifier:issubclass; 105, argument_list; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:elem; 108, identifier:__class__; 109, identifier:DOMElement; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:elem; 115, identifier:parent; 116, identifier:self; 117, if_statement; 117, 118; 117, 119; 118, identifier:name; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:setattr; 123, argument_list; 123, 124; 123, 125; 123, 126; 124, identifier:self; 125, identifier:name; 126, identifier:elem | def _insert(self, dom_group, idx=None, prepend=False, name=None):
if idx and idx < 0:
idx = 0
if prepend:
idx = 0
else:
idx = idx if idx is not None else len(self.childs)
if dom_group is not None:
if not isinstance(dom_group, Iterable) or isinstance(
dom_group, (DOMElement, str)
):
dom_group = [dom_group]
for i_group, elem in enumerate(dom_group):
if elem is not None:
self.childs.insert(idx + i_group, elem)
if issubclass(elem.__class__, DOMElement):
elem.parent = self
if name:
setattr(self, name, elem) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:check_label; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:labels; 5, identifier:required; 6, identifier:value_regex; 7, identifier:target_labels; 8, block; 8, 9; 8, 29; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:present; 12, boolean_operator:and; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:target_labels; 15, None; 16, not_operator; 16, 17; 17, call; 17, 18; 17, 24; 18, attribute; 18, 19; 18, 23; 19, call; 19, 20; 19, 21; 20, identifier:set; 21, argument_list; 21, 22; 22, identifier:labels; 23, identifier:isdisjoint; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:set; 27, argument_list; 27, 28; 28, identifier:target_labels; 29, if_statement; 29, 30; 29, 31; 29, 90; 30, identifier:present; 31, block; 31, 32; 32, if_statement; 32, 33; 32, 37; 32, 40; 32, 86; 33, boolean_operator:and; 33, 34; 33, 35; 34, identifier:required; 35, not_operator; 35, 36; 36, identifier:value_regex; 37, block; 37, 38; 38, return_statement; 38, 39; 39, True; 40, elif_clause; 40, 41; 40, 42; 41, identifier:value_regex; 42, block; 42, 43; 42, 52; 42, 64; 42, 84; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:pattern; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:re; 49, identifier:compile; 50, argument_list; 50, 51; 51, identifier:value_regex; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:present_labels; 55, binary_operator:&; 55, 56; 55, 60; 56, call; 56, 57; 56, 58; 57, identifier:set; 58, argument_list; 58, 59; 59, identifier:labels; 60, call; 60, 61; 60, 62; 61, identifier:set; 62, argument_list; 62, 63; 63, identifier:target_labels; 64, for_statement; 64, 65; 64, 66; 64, 67; 65, identifier:l; 66, identifier:present_labels; 67, block; 67, 68; 68, if_statement; 68, 69; 68, 81; 69, not_operator; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:bool; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:pattern; 76, identifier:search; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 80; 79, identifier:target_labels; 80, identifier:l; 81, block; 81, 82; 82, return_statement; 82, 83; 83, False; 84, return_statement; 84, 85; 85, True; 86, else_clause; 86, 87; 87, block; 87, 88; 88, return_statement; 88, 89; 89, False; 90, else_clause; 90, 91; 91, block; 91, 92; 92, return_statement; 92, 93; 93, not_operator; 93, 94; 94, identifier:required | def check_label(labels, required, value_regex, target_labels):
present = target_labels is not None and not set(labels).isdisjoint(set(target_labels))
if present:
if required and not value_regex:
return True
elif value_regex:
pattern = re.compile(value_regex)
present_labels = set(labels) & set(target_labels)
for l in present_labels:
if not bool(pattern.search(target_labels[l])):
return False
return True
else:
return False
else:
return not required |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:receive_fmf_metadata; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:name; 5, identifier:path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:object_list; 8, False; 9, block; 9, 10; 9, 14; 9, 21; 9, 30; 9, 59; 9, 64; 9, 121; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:output; 13, dictionary; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:fmf_tree; 17, call; 17, 18; 17, 19; 18, identifier:ExtendedTree; 19, argument_list; 19, 20; 20, identifier:path; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:logger; 25, identifier:debug; 26, argument_list; 26, 27; 26, 28; 26, 29; 27, string:"get FMF metadata for test (path:%s name=%s)"; 28, identifier:path; 29, identifier:name; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:items; 33, list_comprehension; 33, 34; 33, 35; 33, 42; 34, identifier:x; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:x; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:fmf_tree; 40, identifier:climb; 41, argument_list; 42, if_clause; 42, 43; 43, boolean_operator:and; 43, 44; 43, 54; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:x; 48, identifier:name; 49, identifier:endswith; 50, argument_list; 50, 51; 51, binary_operator:+; 51, 52; 51, 53; 52, string:"/"; 53, identifier:name; 54, comparison_operator:not; 54, 55; 54, 56; 55, string:"@"; 56, attribute; 56, 57; 56, 58; 57, identifier:x; 58, identifier:name; 59, if_statement; 59, 60; 59, 61; 60, identifier:object_list; 61, block; 61, 62; 62, return_statement; 62, 63; 63, identifier:items; 64, if_statement; 64, 65; 64, 71; 64, 78; 64, 107; 65, comparison_operator:==; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:len; 68, argument_list; 68, 69; 69, identifier:items; 70, integer:1; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:output; 75, subscript; 75, 76; 75, 77; 76, identifier:items; 77, integer:0; 78, elif_clause; 78, 79; 78, 85; 79, comparison_operator:>; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:len; 82, argument_list; 82, 83; 83, identifier:items; 84, integer:1; 85, block; 85, 86; 86, raise_statement; 86, 87; 87, call; 87, 88; 87, 89; 88, identifier:Exception; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, string:"There is more FMF test metadata for item by name:{}({}) {}"; 93, identifier:format; 94, argument_list; 94, 95; 94, 96; 94, 100; 95, identifier:name; 96, call; 96, 97; 96, 98; 97, identifier:len; 98, argument_list; 98, 99; 99, identifier:items; 100, list_comprehension; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:x; 103, identifier:name; 104, for_in_clause; 104, 105; 104, 106; 105, identifier:x; 106, identifier:items; 107, elif_clause; 107, 108; 107, 110; 108, not_operator; 108, 109; 109, identifier:items; 110, block; 110, 111; 111, raise_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:Exception; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, string:"Unable to get FMF metadata for: {}"; 118, identifier:format; 119, argument_list; 119, 120; 120, identifier:name; 121, return_statement; 121, 122; 122, identifier:output | def receive_fmf_metadata(name, path, object_list=False):
output = {}
fmf_tree = ExtendedTree(path)
logger.debug("get FMF metadata for test (path:%s name=%s)", path, name)
items = [x for x in fmf_tree.climb() if x.name.endswith("/" + name) and "@" not in x.name]
if object_list:
return items
if len(items) == 1:
output = items[0]
elif len(items) > 1:
raise Exception("There is more FMF test metadata for item by name:{}({}) {}".format(
name, len(items), [x.name for x in items]))
elif not items:
raise Exception("Unable to get FMF metadata for: {}".format(name))
return output |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:prune_overridden; 3, parameters; 3, 4; 4, identifier:ansi_string; 5, block; 5, 6; 5, 27; 5, 138; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:multi_seqs; 9, call; 9, 10; 9, 11; 10, identifier:set; 11, generator_expression; 11, 12; 11, 13; 11, 21; 12, identifier:p; 13, for_in_clause; 13, 14; 13, 15; 14, identifier:p; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:RE_ANSI; 18, identifier:findall; 19, argument_list; 19, 20; 20, identifier:ansi_string; 21, if_clause; 21, 22; 22, comparison_operator:in; 22, 23; 22, 24; 23, string:';'; 24, subscript; 24, 25; 24, 26; 25, identifier:p; 26, integer:1; 27, for_statement; 27, 28; 27, 31; 27, 32; 28, pattern_list; 28, 29; 28, 30; 29, identifier:escape; 30, identifier:codes; 31, identifier:multi_seqs; 32, block; 32, 33; 32, 48; 32, 69; 32, 104; 32, 119; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:r_codes; 36, call; 36, 37; 36, 38; 37, identifier:list; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:reversed; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:codes; 45, identifier:split; 46, argument_list; 46, 47; 47, string:';'; 48, try_statement; 48, 49; 48, 65; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:r_codes; 53, subscript; 53, 54; 53, 55; 54, identifier:r_codes; 55, slice; 55, 56; 55, 57; 56, colon; 57, binary_operator:+; 57, 58; 57, 64; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:r_codes; 61, identifier:index; 62, argument_list; 62, 63; 63, string:'0'; 64, integer:1; 65, except_clause; 65, 66; 65, 67; 66, identifier:ValueError; 67, block; 67, 68; 68, pass_statement; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:group; 71, identifier:CODE_GROUPS; 72, block; 72, 73; 73, for_statement; 73, 74; 73, 75; 73, 96; 74, identifier:pos; 75, call; 75, 76; 75, 77; 76, identifier:reversed; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 93; 79, list_comprehension; 79, 80; 79, 81; 79, 89; 80, identifier:i; 81, for_in_clause; 81, 82; 81, 85; 82, pattern_list; 82, 83; 82, 84; 83, identifier:i; 84, identifier:n; 85, call; 85, 86; 85, 87; 86, identifier:enumerate; 87, argument_list; 87, 88; 88, identifier:r_codes; 89, if_clause; 89, 90; 90, comparison_operator:in; 90, 91; 90, 92; 91, identifier:n; 92, identifier:group; 93, slice; 93, 94; 93, 95; 94, integer:1; 95, colon; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:r_codes; 101, identifier:pop; 102, argument_list; 102, 103; 103, identifier:pos; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:reduced_codes; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, string:';'; 110, identifier:join; 111, argument_list; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:sorted; 114, argument_list; 114, 115; 114, 116; 115, identifier:r_codes; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:key; 118, identifier:int; 119, if_statement; 119, 120; 119, 123; 120, comparison_operator:!=; 120, 121; 120, 122; 121, identifier:codes; 122, identifier:reduced_codes; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:ansi_string; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:ansi_string; 130, identifier:replace; 131, argument_list; 131, 132; 131, 133; 132, identifier:escape; 133, binary_operator:+; 133, 134; 133, 137; 134, binary_operator:+; 134, 135; 134, 136; 135, string:'\033['; 136, identifier:reduced_codes; 137, string:'m'; 138, return_statement; 138, 139; 139, identifier:ansi_string | def prune_overridden(ansi_string):
multi_seqs = set(p for p in RE_ANSI.findall(ansi_string) if ';' in p[1])
for escape, codes in multi_seqs:
r_codes = list(reversed(codes.split(';')))
try:
r_codes = r_codes[:r_codes.index('0') + 1]
except ValueError:
pass
for group in CODE_GROUPS:
for pos in reversed([i for i, n in enumerate(r_codes) if n in group][1:]):
r_codes.pop(pos)
reduced_codes = ';'.join(sorted(r_codes, key=int))
if codes != reduced_codes:
ansi_string = ansi_string.replace(escape, '\033[' + reduced_codes + 'm')
return ansi_string |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:parse_input; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:tagged_string; 5, identifier:disable_colors; 6, identifier:keep_tags; 7, block; 7, 8; 7, 15; 7, 24; 7, 67; 7, 77; 7, 84; 7, 107; 7, 114; 7, 118; 7, 124; 7, 172; 7, 181; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:codes; 11, call; 11, 12; 11, 13; 12, identifier:ANSICodeMapping; 13, argument_list; 13, 14; 14, identifier:tagged_string; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:output_colors; 18, call; 18, 19; 18, 20; 19, identifier:getattr; 20, argument_list; 20, 21; 20, 22; 20, 23; 21, identifier:tagged_string; 22, string:'value_colors'; 23, identifier:tagged_string; 24, if_statement; 24, 25; 24, 27; 25, not_operator; 25, 26; 26, identifier:keep_tags; 27, block; 27, 28; 28, for_statement; 28, 29; 28, 32; 28, 56; 29, pattern_list; 29, 30; 29, 31; 30, identifier:tag; 31, identifier:replacement; 32, generator_expression; 32, 33; 32, 47; 33, tuple; 33, 34; 33, 39; 34, binary_operator:+; 34, 35; 34, 38; 35, binary_operator:+; 35, 36; 35, 37; 36, string:'{'; 37, identifier:k; 38, string:'}'; 39, conditional_expression:if; 39, 40; 39, 41; 39, 44; 40, string:''; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:v; 43, None; 44, binary_operator:%; 44, 45; 44, 46; 45, string:'\033[%dm'; 46, identifier:v; 47, for_in_clause; 47, 48; 47, 51; 48, pattern_list; 48, 49; 48, 50; 49, identifier:k; 50, identifier:v; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:codes; 54, identifier:items; 55, argument_list; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:output_colors; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:output_colors; 63, identifier:replace; 64, argument_list; 64, 65; 64, 66; 65, identifier:tag; 66, identifier:replacement; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:output_no_colors; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:RE_ANSI; 73, identifier:sub; 74, argument_list; 74, 75; 74, 76; 75, string:''; 76, identifier:output_colors; 77, if_statement; 77, 78; 77, 79; 78, identifier:disable_colors; 79, block; 79, 80; 80, return_statement; 80, 81; 81, expression_list; 81, 82; 81, 83; 82, identifier:output_no_colors; 83, identifier:output_no_colors; 84, while_statement; 84, 85; 84, 86; 85, True; 86, block; 86, 87; 86, 97; 86, 103; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:simplified; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:RE_COMBINE; 93, identifier:sub; 94, argument_list; 94, 95; 94, 96; 95, string:r'\033[\1;\2m'; 96, identifier:output_colors; 97, if_statement; 97, 98; 97, 101; 98, comparison_operator:==; 98, 99; 98, 100; 99, identifier:simplified; 100, identifier:output_colors; 101, block; 101, 102; 102, break_statement; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:output_colors; 106, identifier:simplified; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:output_colors; 110, call; 110, 111; 110, 112; 111, identifier:prune_overridden; 112, argument_list; 112, 113; 113, identifier:output_colors; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:previous_escape; 117, None; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:segments; 121, call; 121, 122; 121, 123; 122, identifier:list; 123, argument_list; 124, for_statement; 124, 125; 124, 126; 124, 138; 125, identifier:item; 126, generator_expression; 126, 127; 126, 128; 126, 136; 127, identifier:i; 128, for_in_clause; 128, 129; 128, 130; 129, identifier:i; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:RE_SPLIT; 133, identifier:split; 134, argument_list; 134, 135; 135, identifier:output_colors; 136, if_clause; 136, 137; 137, identifier:i; 138, block; 138, 139; 139, if_statement; 139, 140; 139, 146; 139, 163; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:RE_SPLIT; 143, identifier:match; 144, argument_list; 144, 145; 145, identifier:item; 146, block; 146, 147; 147, if_statement; 147, 148; 147, 151; 148, comparison_operator:!=; 148, 149; 148, 150; 149, identifier:item; 150, identifier:previous_escape; 151, block; 151, 152; 151, 159; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:segments; 156, identifier:append; 157, argument_list; 157, 158; 158, identifier:item; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:previous_escape; 162, identifier:item; 163, else_clause; 163, 164; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:segments; 169, identifier:append; 170, argument_list; 170, 171; 171, identifier:item; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:output_colors; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, string:''; 178, identifier:join; 179, argument_list; 179, 180; 180, identifier:segments; 181, return_statement; 181, 182; 182, expression_list; 182, 183; 182, 184; 183, identifier:output_colors; 184, identifier:output_no_colors | def parse_input(tagged_string, disable_colors, keep_tags):
codes = ANSICodeMapping(tagged_string)
output_colors = getattr(tagged_string, 'value_colors', tagged_string)
if not keep_tags:
for tag, replacement in (('{' + k + '}', '' if v is None else '\033[%dm' % v) for k, v in codes.items()):
output_colors = output_colors.replace(tag, replacement)
output_no_colors = RE_ANSI.sub('', output_colors)
if disable_colors:
return output_no_colors, output_no_colors
while True:
simplified = RE_COMBINE.sub(r'\033[\1;\2m', output_colors)
if simplified == output_colors:
break
output_colors = simplified
output_colors = prune_overridden(output_colors)
previous_escape = None
segments = list()
for item in (i for i in RE_SPLIT.split(output_colors) if i):
if RE_SPLIT.match(item):
if item != previous_escape:
segments.append(item)
previous_escape = item
else:
segments.append(item)
output_colors = ''.join(segments)
return output_colors, output_no_colors |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:memoize; 3, parameters; 3, 4; 4, identifier:method; 5, block; 5, 6; 5, 18; 5, 24; 5, 30; 5, 175; 5, 181; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:cache; 9, assignment; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:method; 12, identifier:cache; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:collections; 16, identifier:OrderedDict; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:_get; 21, attribute; 21, 22; 21, 23; 22, identifier:cache; 23, identifier:get; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:_popitem; 27, attribute; 27, 28; 27, 29; 28, identifier:cache; 29, identifier:popitem; 30, decorated_definition; 30, 31; 30, 38; 31, decorator; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:functools; 35, identifier:wraps; 36, argument_list; 36, 37; 37, identifier:method; 38, function_definition; 38, 39; 38, 40; 38, 47; 39, function_name:memoizer; 40, parameters; 40, 41; 40, 42; 40, 43; 40, 45; 41, identifier:instance; 42, identifier:x; 43, list_splat_pattern; 43, 44; 44, identifier:args; 45, dictionary_splat_pattern; 45, 46; 46, identifier:kwargs; 47, block; 47, 48; 47, 70; 47, 106; 47, 113; 47, 120; 48, if_statement; 48, 49; 48, 59; 49, boolean_operator:or; 49, 50; 49, 52; 50, not_operator; 50, 51; 51, identifier:_WITH_MEMOIZATION; 52, call; 52, 53; 52, 54; 53, identifier:isinstance; 54, argument_list; 54, 55; 54, 56; 55, identifier:x; 56, attribute; 56, 57; 56, 58; 57, identifier:u; 58, identifier:Quantity; 59, block; 59, 60; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:method; 63, argument_list; 63, 64; 63, 65; 63, 66; 63, 68; 64, identifier:instance; 65, identifier:x; 66, list_splat; 66, 67; 67, identifier:args; 68, dictionary_splat; 68, 69; 69, identifier:kwargs; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:unique_id; 73, binary_operator:+; 73, 74; 73, 92; 74, call; 74, 75; 74, 76; 75, identifier:tuple; 76, generator_expression; 76, 77; 76, 83; 77, call; 77, 78; 77, 79; 78, identifier:float; 79, argument_list; 79, 80; 80, attribute; 80, 81; 80, 82; 81, identifier:yy; 82, identifier:value; 83, for_in_clause; 83, 84; 83, 85; 84, identifier:yy; 85, call; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:instance; 89, identifier:parameters; 90, identifier:values; 91, argument_list; 92, tuple; 92, 93; 92, 96; 92, 101; 93, attribute; 93, 94; 93, 95; 94, identifier:x; 95, identifier:size; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:x; 99, identifier:min; 100, argument_list; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:x; 104, identifier:max; 105, argument_list; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:key; 109, call; 109, 110; 109, 111; 110, identifier:hash; 111, argument_list; 111, 112; 112, identifier:unique_id; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:result; 116, call; 116, 117; 116, 118; 117, identifier:_get; 118, argument_list; 118, 119; 119, identifier:key; 120, if_statement; 120, 121; 120, 124; 120, 127; 121, comparison_operator:is; 121, 122; 121, 123; 122, identifier:result; 123, None; 124, block; 124, 125; 125, return_statement; 125, 126; 126, identifier:result; 127, else_clause; 127, 128; 128, block; 128, 129; 128, 141; 128, 147; 128, 173; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:result; 132, call; 132, 133; 132, 134; 133, identifier:method; 134, argument_list; 134, 135; 134, 136; 134, 137; 134, 139; 135, identifier:instance; 136, identifier:x; 137, list_splat; 137, 138; 138, identifier:args; 139, dictionary_splat; 139, 140; 140, identifier:kwargs; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:cache; 145, identifier:key; 146, identifier:result; 147, if_statement; 147, 148; 147, 154; 148, comparison_operator:>; 148, 149; 148, 153; 149, call; 149, 150; 149, 151; 150, identifier:len; 151, argument_list; 151, 152; 152, identifier:cache; 153, identifier:_CACHE_SIZE; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, list_comprehension; 156, 157; 156, 161; 157, call; 157, 158; 157, 159; 158, identifier:_popitem; 159, argument_list; 159, 160; 160, False; 161, for_in_clause; 161, 162; 161, 163; 162, identifier:i; 163, call; 163, 164; 163, 165; 164, identifier:range; 165, argument_list; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:max; 168, argument_list; 168, 169; 168, 172; 169, binary_operator://; 169, 170; 169, 171; 170, identifier:_CACHE_SIZE; 171, integer:2; 172, integer:1; 173, return_statement; 173, 174; 174, identifier:result; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:memoizer; 179, identifier:input_object; 180, identifier:method; 181, return_statement; 181, 182; 182, identifier:memoizer | def memoize(method):
cache = method.cache = collections.OrderedDict()
_get = cache.get
_popitem = cache.popitem
@functools.wraps(method)
def memoizer(instance, x, *args, **kwargs):
if not _WITH_MEMOIZATION or isinstance(x, u.Quantity):
return method(instance, x, *args, **kwargs)
unique_id = tuple(float(yy.value) for yy in instance.parameters.values()) + (x.size, x.min(), x.max())
key = hash(unique_id)
result = _get(key)
if result is not None:
return result
else:
result = method(instance, x, *args, **kwargs)
cache[key] = result
if len(cache) > _CACHE_SIZE:
[_popitem(False) for i in range(max(_CACHE_SIZE // 2, 1))]
return result
memoizer.input_object = method
return memoizer |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_set_value; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:new_value; 6, block; 6, 7; 6, 36; 6, 65; 6, 99; 6, 123; 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:min_value; 13, None; 14, comparison_operator:<; 14, 15; 14, 16; 15, identifier:new_value; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:min_value; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:SettingOutOfBounds; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, string:"Trying to set parameter {0} = {1}, which is less than the minimum allowed {2}"; 27, identifier:format; 28, argument_list; 28, 29; 28, 32; 28, 33; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:name; 32, identifier:new_value; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:min_value; 36, if_statement; 36, 37; 36, 48; 37, boolean_operator:and; 37, 38; 37, 43; 38, comparison_operator:is; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:max_value; 42, None; 43, comparison_operator:>; 43, 44; 43, 45; 44, identifier:new_value; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:max_value; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:SettingOutOfBounds; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, string:"Trying to set parameter {0} = {1}, which is more than the maximum allowed {2}"; 56, identifier:format; 57, argument_list; 57, 58; 57, 61; 57, 62; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:name; 61, identifier:new_value; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:max_value; 65, if_statement; 65, 66; 65, 71; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:has_auxiliary_variable; 70, argument_list; 71, block; 71, 72; 72, with_statement; 72, 73; 72, 80; 73, with_clause; 73, 74; 74, with_item; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:warnings; 78, identifier:catch_warnings; 79, argument_list; 80, block; 80, 81; 80, 89; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:warnings; 85, identifier:simplefilter; 86, argument_list; 86, 87; 86, 88; 87, string:"always"; 88, identifier:RuntimeWarning; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:warnings; 93, identifier:warn; 94, argument_list; 94, 95; 94, 98; 95, concatenated_string; 95, 96; 95, 97; 96, string:"You are trying to assign to a parameter which is either linked or "; 97, string:"has auxiliary variables. The assignment has no effect."; 98, identifier:RuntimeWarning; 99, if_statement; 99, 100; 99, 105; 99, 110; 100, comparison_operator:is; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:_transformation; 104, None; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:new_internal_value; 109, identifier:new_value; 110, else_clause; 110, 111; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:new_internal_value; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:_transformation; 120, identifier:forward; 121, argument_list; 121, 122; 122, identifier:new_value; 123, if_statement; 123, 124; 123, 129; 124, comparison_operator:!=; 124, 125; 124, 126; 125, identifier:new_internal_value; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:_internal_value; 129, block; 129, 130; 129, 136; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:_internal_value; 135, identifier:new_internal_value; 136, for_statement; 136, 137; 136, 138; 136, 141; 137, identifier:callback; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:_callbacks; 141, block; 141, 142; 142, try_statement; 142, 143; 142, 149; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:callback; 147, argument_list; 147, 148; 148, identifier:self; 149, except_clause; 149, 150; 150, block; 150, 151; 151, raise_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:NotCallableOrErrorInCall; 154, argument_list; 154, 155; 155, binary_operator:%; 155, 156; 155, 157; 156, string:"Could not call callback for parameter %s"; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:name | def _set_value(self, new_value):
if self.min_value is not None and new_value < self.min_value:
raise SettingOutOfBounds(
"Trying to set parameter {0} = {1}, which is less than the minimum allowed {2}".format(
self.name, new_value, self.min_value))
if self.max_value is not None and new_value > self.max_value:
raise SettingOutOfBounds(
"Trying to set parameter {0} = {1}, which is more than the maximum allowed {2}".format(
self.name, new_value, self.max_value))
if self.has_auxiliary_variable():
with warnings.catch_warnings():
warnings.simplefilter("always", RuntimeWarning)
warnings.warn("You are trying to assign to a parameter which is either linked or "
"has auxiliary variables. The assignment has no effect.", RuntimeWarning)
if self._transformation is None:
new_internal_value = new_value
else:
new_internal_value = self._transformation.forward(new_value)
if new_internal_value != self._internal_value:
self._internal_value = new_internal_value
for callback in self._callbacks:
try:
callback(self)
except:
raise NotCallableOrErrorInCall("Could not call callback for parameter %s" % self.name) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:set_uninformative_prior; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:prior_class; 6, block; 6, 7; 6, 13; 6, 59; 6, 105; 6, 121; 6, 137; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:prior_instance; 10, call; 10, 11; 10, 12; 11, identifier:prior_class; 12, argument_list; 13, if_statement; 13, 14; 13, 19; 13, 31; 14, comparison_operator:is; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:min_value; 18, None; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:ParameterMustHaveBounds; 23, argument_list; 23, 24; 24, binary_operator:%; 24, 25; 24, 28; 25, concatenated_string; 25, 26; 25, 27; 26, string:"Parameter %s does not have a defined minimum. Set one first, then re-run "; 27, string:"set_uninformative_prior"; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:path; 31, else_clause; 31, 32; 32, block; 32, 33; 33, try_statement; 33, 34; 33, 43; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:prior_instance; 39, identifier:lower_bound; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:min_value; 43, except_clause; 43, 44; 43, 45; 44, identifier:SettingOutOfBounds; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:SettingOutOfBounds; 49, argument_list; 49, 50; 50, binary_operator:%; 50, 51; 50, 52; 51, string:"Cannot use minimum of %s for prior %s"; 52, tuple; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:min_value; 56, attribute; 56, 57; 56, 58; 57, identifier:prior_instance; 58, identifier:name; 59, if_statement; 59, 60; 59, 65; 59, 77; 60, comparison_operator:is; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:max_value; 64, None; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:ParameterMustHaveBounds; 69, argument_list; 69, 70; 70, binary_operator:%; 70, 71; 70, 74; 71, concatenated_string; 71, 72; 71, 73; 72, string:"Parameter %s does not have a defined maximum. Set one first, then re-run "; 73, string:"set_uninformative_prior"; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:path; 77, else_clause; 77, 78; 78, block; 78, 79; 79, try_statement; 79, 80; 79, 89; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:prior_instance; 85, identifier:upper_bound; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:max_value; 89, except_clause; 89, 90; 89, 91; 90, identifier:SettingOutOfBounds; 91, block; 91, 92; 92, raise_statement; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:SettingOutOfBounds; 95, argument_list; 95, 96; 96, binary_operator:%; 96, 97; 96, 98; 97, string:"Cannot use maximum of %s for prior %s"; 98, tuple; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:max_value; 102, attribute; 102, 103; 102, 104; 103, identifier:prior_instance; 104, identifier:name; 105, assert_statement; 105, 106; 105, 116; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:np; 109, identifier:isfinite; 110, argument_list; 110, 111; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:prior_instance; 114, identifier:upper_bound; 115, identifier:value; 116, binary_operator:%; 116, 117; 116, 118; 117, string:"The parameter %s must have a finite maximum"; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:name; 121, assert_statement; 121, 122; 121, 132; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:np; 125, identifier:isfinite; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:prior_instance; 130, identifier:lower_bound; 131, identifier:value; 132, binary_operator:%; 132, 133; 132, 134; 133, string:"The parameter %s must have a finite minimum"; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:name; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:_set_prior; 142, argument_list; 142, 143; 143, identifier:prior_instance | def set_uninformative_prior(self, prior_class):
prior_instance = prior_class()
if self.min_value is None:
raise ParameterMustHaveBounds("Parameter %s does not have a defined minimum. Set one first, then re-run "
"set_uninformative_prior" % self.path)
else:
try:
prior_instance.lower_bound = self.min_value
except SettingOutOfBounds:
raise SettingOutOfBounds("Cannot use minimum of %s for prior %s" % (self.min_value,
prior_instance.name))
if self.max_value is None:
raise ParameterMustHaveBounds("Parameter %s does not have a defined maximum. Set one first, then re-run "
"set_uninformative_prior" % self.path)
else:
try:
prior_instance.upper_bound = self.max_value
except SettingOutOfBounds:
raise SettingOutOfBounds("Cannot use maximum of %s for prior %s" % (self.max_value,
prior_instance.name))
assert np.isfinite(prior_instance.upper_bound.value),"The parameter %s must have a finite maximum" % self.name
assert np.isfinite(prior_instance.lower_bound.value),"The parameter %s must have a finite minimum" % self.name
self._set_prior(prior_instance) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:find_library; 3, parameters; 3, 4; 3, 5; 4, identifier:library_root; 5, default_parameter; 5, 6; 5, 7; 6, identifier:additional_places; 7, None; 8, block; 8, 9; 8, 20; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:first_guess; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:ctypes; 16, identifier:util; 17, identifier:find_library; 18, argument_list; 18, 19; 19, identifier:library_root; 20, if_statement; 20, 21; 20, 24; 20, 89; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:first_guess; 23, None; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 40; 25, 48; 25, 78; 26, comparison_operator:>=; 26, 27; 26, 39; 27, call; 27, 28; 27, 37; 28, attribute; 28, 29; 28, 36; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:sys; 33, identifier:platform; 34, identifier:lower; 35, argument_list; 36, identifier:find; 37, argument_list; 37, 38; 38, string:"linux"; 39, integer:0; 40, block; 40, 41; 41, return_statement; 41, 42; 42, expression_list; 42, 43; 42, 47; 43, call; 43, 44; 43, 45; 44, identifier:sanitize_lib_name; 45, argument_list; 45, 46; 46, identifier:first_guess; 47, None; 48, elif_clause; 48, 49; 48, 63; 49, comparison_operator:>=; 49, 50; 49, 62; 50, call; 50, 51; 50, 60; 51, attribute; 51, 52; 51, 59; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:sys; 56, identifier:platform; 57, identifier:lower; 58, argument_list; 59, identifier:find; 60, argument_list; 60, 61; 61, string:"darwin"; 62, integer:0; 63, block; 63, 64; 64, return_statement; 64, 65; 65, expression_list; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:sanitize_lib_name; 68, argument_list; 68, 69; 69, identifier:first_guess; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:os; 74, identifier:path; 75, identifier:dirname; 76, argument_list; 76, 77; 77, identifier:first_guess; 78, else_clause; 78, 79; 79, block; 79, 80; 80, raise_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:NotImplementedError; 83, argument_list; 83, 84; 84, binary_operator:%; 84, 85; 84, 86; 85, string:"Platform %s is not supported"; 86, attribute; 86, 87; 86, 88; 87, identifier:sys; 88, identifier:platform; 89, else_clause; 89, 90; 90, block; 90, 91; 90, 168; 90, 180; 90, 184; 90, 188; 90, 270; 91, if_statement; 91, 92; 91, 106; 91, 124; 91, 157; 92, comparison_operator:>=; 92, 93; 92, 105; 93, call; 93, 94; 93, 103; 94, attribute; 94, 95; 94, 102; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:sys; 99, identifier:platform; 100, identifier:lower; 101, argument_list; 102, identifier:find; 103, argument_list; 103, 104; 104, string:"linux"; 105, integer:0; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:possible_locations; 110, call; 110, 111; 110, 122; 111, attribute; 111, 112; 111, 121; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:os; 116, identifier:environ; 117, identifier:get; 118, argument_list; 118, 119; 118, 120; 119, string:"LD_LIBRARY_PATH"; 120, string:""; 121, identifier:split; 122, argument_list; 122, 123; 123, string:":"; 124, elif_clause; 124, 125; 124, 139; 125, comparison_operator:>=; 125, 126; 125, 138; 126, call; 126, 127; 126, 136; 127, attribute; 127, 128; 127, 135; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:sys; 132, identifier:platform; 133, identifier:lower; 134, argument_list; 135, identifier:find; 136, argument_list; 136, 137; 137, string:"darwin"; 138, integer:0; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:possible_locations; 143, call; 143, 144; 143, 155; 144, attribute; 144, 145; 144, 154; 145, call; 145, 146; 145, 151; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:os; 149, identifier:environ; 150, identifier:get; 151, argument_list; 151, 152; 151, 153; 152, string:"DYLD_LIBRARY_PATH"; 153, string:""; 154, identifier:split; 155, argument_list; 155, 156; 156, string:":"; 157, else_clause; 157, 158; 158, block; 158, 159; 159, raise_statement; 159, 160; 160, call; 160, 161; 160, 162; 161, identifier:NotImplementedError; 162, argument_list; 162, 163; 163, binary_operator:%; 163, 164; 163, 165; 164, string:"Platform %s is not supported"; 165, attribute; 165, 166; 165, 167; 166, identifier:sys; 167, identifier:platform; 168, if_statement; 168, 169; 168, 172; 169, comparison_operator:is; 169, 170; 169, 171; 170, identifier:additional_places; 171, None; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:possible_locations; 177, identifier:extend; 178, argument_list; 178, 179; 179, identifier:additional_places; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:library_name; 183, None; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:library_dir; 187, None; 188, for_statement; 188, 189; 188, 190; 188, 191; 189, identifier:search_path; 190, identifier:possible_locations; 191, block; 191, 192; 191, 198; 191, 217; 191, 264; 192, if_statement; 192, 193; 192, 196; 193, comparison_operator:==; 193, 194; 193, 195; 194, identifier:search_path; 195, string:""; 196, block; 196, 197; 197, continue_statement; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:results; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:glob; 204, identifier:glob; 205, argument_list; 205, 206; 206, call; 206, 207; 206, 212; 207, attribute; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:os; 210, identifier:path; 211, identifier:join; 212, argument_list; 212, 213; 212, 214; 213, identifier:search_path; 214, binary_operator:%; 214, 215; 214, 216; 215, string:"lib%s*"; 216, identifier:library_root; 217, if_statement; 217, 218; 217, 224; 217, 261; 218, comparison_operator:>=; 218, 219; 218, 223; 219, call; 219, 220; 219, 221; 220, identifier:len; 221, argument_list; 221, 222; 222, identifier:results; 223, integer:1; 224, block; 224, 225; 225, for_statement; 225, 226; 225, 227; 225, 228; 226, identifier:result; 227, identifier:results; 228, block; 228, 229; 229, if_statement; 229, 230; 229, 248; 229, 250; 230, comparison_operator:is; 230, 231; 230, 247; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:re; 234, identifier:match; 235, argument_list; 235, 236; 235, 239; 236, binary_operator:%; 236, 237; 236, 238; 237, string:"lib%s[\-_\.]"; 238, identifier:library_root; 239, call; 239, 240; 239, 245; 240, attribute; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:os; 243, identifier:path; 244, identifier:basename; 245, argument_list; 245, 246; 246, identifier:result; 247, None; 248, block; 248, 249; 249, continue_statement; 250, else_clause; 250, 251; 251, block; 251, 252; 251, 256; 251, 260; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:library_name; 255, identifier:result; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:library_dir; 259, identifier:search_path; 260, break_statement; 261, else_clause; 261, 262; 262, block; 262, 263; 263, continue_statement; 264, if_statement; 264, 265; 264, 268; 265, comparison_operator:is; 265, 266; 265, 267; 266, identifier:library_name; 267, None; 268, block; 268, 269; 269, break_statement; 270, if_statement; 270, 271; 270, 274; 270, 279; 271, comparison_operator:is; 271, 272; 271, 273; 272, identifier:library_name; 273, None; 274, block; 274, 275; 275, return_statement; 275, 276; 276, expression_list; 276, 277; 276, 278; 277, None; 278, None; 279, else_clause; 279, 280; 280, block; 280, 281; 281, return_statement; 281, 282; 282, expression_list; 282, 283; 282, 287; 283, call; 283, 284; 283, 285; 284, identifier:sanitize_lib_name; 285, argument_list; 285, 286; 286, identifier:library_name; 287, identifier:library_dir | def find_library(library_root, additional_places=None):
first_guess = ctypes.util.find_library(library_root)
if first_guess is not None:
if sys.platform.lower().find("linux") >= 0:
return sanitize_lib_name(first_guess), None
elif sys.platform.lower().find("darwin") >= 0:
return sanitize_lib_name(first_guess), os.path.dirname(first_guess)
else:
raise NotImplementedError("Platform %s is not supported" % sys.platform)
else:
if sys.platform.lower().find("linux") >= 0:
possible_locations = os.environ.get("LD_LIBRARY_PATH", "").split(":")
elif sys.platform.lower().find("darwin") >= 0:
possible_locations = os.environ.get("DYLD_LIBRARY_PATH", "").split(":")
else:
raise NotImplementedError("Platform %s is not supported" % sys.platform)
if additional_places is not None:
possible_locations.extend(additional_places)
library_name = None
library_dir = None
for search_path in possible_locations:
if search_path == "":
continue
results = glob.glob(os.path.join(search_path, "lib%s*" % library_root))
if len(results) >= 1:
for result in results:
if re.match("lib%s[\-_\.]" % library_root, os.path.basename(result)) is None:
continue
else:
library_name = result
library_dir = search_path
break
else:
continue
if library_name is not None:
break
if library_name is None:
return None, None
else:
return sanitize_lib_name(library_name), library_dir |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:LDA_discriminants; 3, parameters; 3, 4; 3, 5; 4, identifier:x; 5, identifier:labels; 6, block; 6, 7; 6, 25; 6, 35; 7, try_statement; 7, 8; 7, 18; 8, block; 8, 9; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:x; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:np; 15, identifier:array; 16, argument_list; 16, 17; 17, identifier:x; 18, except_clause; 18, 19; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:ValueError; 23, argument_list; 23, 24; 24, string:'Impossible to convert x to a numpy array.'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, pattern_list; 27, 28; 27, 29; 28, identifier:eigen_values; 29, identifier:eigen_vectors; 30, call; 30, 31; 30, 32; 31, identifier:LDA_base; 32, argument_list; 32, 33; 32, 34; 33, identifier:x; 34, identifier:labels; 35, return_statement; 35, 36; 36, subscript; 36, 37; 36, 38; 37, identifier:eigen_values; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, parenthesized_expression; 40, 41; 41, unary_operator:-; 41, 42; 42, identifier:eigen_values; 43, identifier:argsort; 44, argument_list | def LDA_discriminants(x, labels):
try:
x = np.array(x)
except:
raise ValueError('Impossible to convert x to a numpy array.')
eigen_values, eigen_vectors = LDA_base(x, labels)
return eigen_values[(-eigen_values).argsort()] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:train; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:x; 6, identifier:d; 7, default_parameter; 7, 8; 7, 9; 8, identifier:epochs; 9, integer:10; 10, default_parameter; 10, 11; 10, 12; 11, identifier:shuffle; 12, False; 13, block; 13, 14; 13, 21; 13, 35; 13, 53; 13, 95; 13, 122; 13, 157; 13, 166; 13, 202; 13, 272; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:N; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:x; 21, if_statement; 21, 22; 21, 29; 22, not_operator; 22, 23; 23, comparison_operator:==; 23, 24; 23, 28; 24, call; 24, 25; 24, 26; 25, identifier:len; 26, argument_list; 26, 27; 27, identifier:d; 28, identifier:N; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:ValueError; 33, argument_list; 33, 34; 34, string:'The length of vector d and matrix x must agree.'; 35, if_statement; 35, 36; 35, 47; 36, not_operator; 36, 37; 37, comparison_operator:==; 37, 38; 37, 44; 38, call; 38, 39; 38, 40; 39, identifier:len; 40, argument_list; 40, 41; 41, subscript; 41, 42; 41, 43; 42, identifier:x; 43, integer:0; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:n_input; 47, block; 47, 48; 48, raise_statement; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:ValueError; 51, argument_list; 51, 52; 52, string:'The number of network inputs is not correct.'; 53, if_statement; 53, 54; 53, 59; 53, 76; 54, comparison_operator:==; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:outputs; 58, integer:1; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 70; 61, not_operator; 61, 62; 62, comparison_operator:==; 62, 63; 62, 69; 63, call; 63, 64; 63, 65; 64, identifier:len; 65, argument_list; 65, 66; 66, attribute; 66, 67; 66, 68; 67, identifier:d; 68, identifier:shape; 69, integer:1; 70, block; 70, 71; 71, raise_statement; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:ValueError; 74, argument_list; 74, 75; 75, string:'For one output MLP the d must have one dimension'; 76, else_clause; 76, 77; 77, block; 77, 78; 78, if_statement; 78, 79; 78, 89; 79, not_operator; 79, 80; 80, comparison_operator:==; 80, 81; 80, 86; 81, subscript; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:d; 84, identifier:shape; 85, integer:1; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:outputs; 89, block; 89, 90; 90, raise_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:ValueError; 93, argument_list; 93, 94; 94, string:'The number of outputs must agree with number of columns in d'; 95, try_statement; 95, 96; 95, 115; 96, block; 96, 97; 96, 106; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:x; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:np; 103, identifier:array; 104, argument_list; 104, 105; 105, identifier:x; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:d; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:np; 112, identifier:array; 113, argument_list; 113, 114; 114, identifier:d; 115, except_clause; 115, 116; 116, block; 116, 117; 117, raise_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:ValueError; 120, argument_list; 120, 121; 121, string:'Impossible to convert x or d to a numpy array'; 122, if_statement; 122, 123; 122, 128; 122, 140; 123, comparison_operator:==; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:outputs; 127, integer:1; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:e; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:np; 135, identifier:zeros; 136, argument_list; 136, 137; 137, binary_operator:*; 137, 138; 137, 139; 138, identifier:epochs; 139, identifier:N; 140, else_clause; 140, 141; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:e; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:np; 148, identifier:zeros; 149, argument_list; 149, 150; 150, tuple; 150, 151; 150, 154; 151, binary_operator:*; 151, 152; 151, 153; 152, identifier:epochs; 153, identifier:N; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:outputs; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:MSE; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:np; 163, identifier:zeros; 164, argument_list; 164, 165; 165, identifier:epochs; 166, if_statement; 166, 167; 166, 168; 167, identifier:shuffle; 168, block; 168, 169; 168, 181; 168, 190; 168, 196; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:randomize; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:np; 175, identifier:arange; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:len; 179, argument_list; 179, 180; 180, identifier:x; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 188; 183, attribute; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:np; 186, identifier:random; 187, identifier:shuffle; 188, argument_list; 188, 189; 189, identifier:randomize; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:x; 193, subscript; 193, 194; 193, 195; 194, identifier:x; 195, identifier:randomize; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:d; 199, subscript; 199, 200; 199, 201; 200, identifier:d; 201, identifier:randomize; 202, for_statement; 202, 203; 202, 204; 202, 208; 203, identifier:epoch; 204, call; 204, 205; 204, 206; 205, identifier:range; 206, argument_list; 206, 207; 207, identifier:epochs; 208, block; 208, 209; 208, 243; 209, for_statement; 209, 210; 209, 211; 209, 215; 210, identifier:k; 211, call; 211, 212; 211, 213; 212, identifier:range; 213, argument_list; 213, 214; 214, identifier:N; 215, block; 215, 216; 215, 225; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:predict; 221, argument_list; 221, 222; 222, subscript; 222, 223; 222, 224; 223, identifier:x; 224, identifier:k; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 235; 227, subscript; 227, 228; 227, 229; 228, identifier:e; 229, binary_operator:+; 229, 230; 229, 234; 230, parenthesized_expression; 230, 231; 231, binary_operator:*; 231, 232; 231, 233; 232, identifier:epoch; 233, identifier:N; 234, identifier:k; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:self; 238, identifier:update; 239, argument_list; 239, 240; 240, subscript; 240, 241; 240, 242; 241, identifier:d; 242, identifier:k; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:MSE; 247, identifier:epoch; 248, binary_operator:/; 248, 249; 248, 271; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:np; 252, identifier:sum; 253, argument_list; 253, 254; 254, binary_operator:**; 254, 255; 254, 270; 255, subscript; 255, 256; 255, 257; 256, identifier:e; 257, slice; 257, 258; 257, 261; 257, 262; 258, binary_operator:*; 258, 259; 258, 260; 259, identifier:epoch; 260, identifier:N; 261, colon; 262, binary_operator:-; 262, 263; 262, 269; 263, binary_operator:*; 263, 264; 263, 268; 264, parenthesized_expression; 264, 265; 265, binary_operator:+; 265, 266; 265, 267; 266, identifier:epoch; 267, integer:1; 268, identifier:N; 269, integer:1; 270, integer:2; 271, identifier:N; 272, return_statement; 272, 273; 273, expression_list; 273, 274; 273, 275; 274, identifier:e; 275, identifier:MSE | def train(self, x, d, epochs=10, shuffle=False):
N = len(x)
if not len(d) == N:
raise ValueError('The length of vector d and matrix x must agree.')
if not len(x[0]) == self.n_input:
raise ValueError('The number of network inputs is not correct.')
if self.outputs == 1:
if not len(d.shape) == 1:
raise ValueError('For one output MLP the d must have one dimension')
else:
if not d.shape[1] == self.outputs:
raise ValueError('The number of outputs must agree with number of columns in d')
try:
x = np.array(x)
d = np.array(d)
except:
raise ValueError('Impossible to convert x or d to a numpy array')
if self.outputs == 1:
e = np.zeros(epochs*N)
else:
e = np.zeros((epochs*N, self.outputs))
MSE = np.zeros(epochs)
if shuffle:
randomize = np.arange(len(x))
np.random.shuffle(randomize)
x = x[randomize]
d = d[randomize]
for epoch in range(epochs):
for k in range(N):
self.predict(x[k])
e[(epoch*N)+k] = self.update(d[k])
MSE[epoch] = np.sum(e[epoch*N:(epoch+1)*N-1]**2) / N
return e, MSE |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:PCA_components; 3, parameters; 3, 4; 4, identifier:x; 5, block; 5, 6; 5, 24; 5, 44; 5, 58; 6, try_statement; 6, 7; 6, 17; 7, block; 7, 8; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:x; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:np; 14, identifier:array; 15, argument_list; 15, 16; 16, identifier:x; 17, except_clause; 17, 18; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:ValueError; 22, argument_list; 22, 23; 23, string:'Impossible to convert x to a numpy array.'; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, pattern_list; 26, 27; 26, 28; 27, identifier:eigen_values; 28, identifier:eigen_vectors; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:np; 33, identifier:linalg; 34, identifier:eig; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:np; 39, identifier:cov; 40, argument_list; 40, 41; 41, attribute; 41, 42; 41, 43; 42, identifier:x; 43, identifier:T; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:eigen_order; 47, subscript; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:eigen_vectors; 50, identifier:T; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, parenthesized_expression; 53, 54; 54, unary_operator:-; 54, 55; 55, identifier:eigen_values; 56, identifier:argsort; 57, argument_list; 58, return_statement; 58, 59; 59, subscript; 59, 60; 59, 61; 60, identifier:eigen_values; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, parenthesized_expression; 63, 64; 64, unary_operator:-; 64, 65; 65, identifier:eigen_values; 66, identifier:argsort; 67, argument_list | def PCA_components(x):
try:
x = np.array(x)
except:
raise ValueError('Impossible to convert x to a numpy array.')
eigen_values, eigen_vectors = np.linalg.eig(np.cov(x.T))
eigen_order = eigen_vectors.T[(-eigen_values).argsort()]
return eigen_values[(-eigen_values).argsort()] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:add_mpl_colorbar; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:dfr; 5, identifier:fig; 6, identifier:dend; 7, identifier:params; 8, default_parameter; 8, 9; 8, 10; 9, identifier:orientation; 10, string:"row"; 11, block; 11, 12; 11, 39; 11, 60; 11, 64; 11, 103; 11, 112; 11, 207; 11, 212; 12, for_statement; 12, 13; 12, 14; 12, 23; 13, identifier:name; 14, subscript; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:dfr; 17, identifier:index; 18, subscript; 18, 19; 18, 22; 19, subscript; 19, 20; 19, 21; 20, identifier:dend; 21, string:"dendrogram"; 22, string:"leaves"; 23, block; 23, 24; 24, if_statement; 24, 25; 24, 30; 25, comparison_operator:not; 25, 26; 25, 27; 26, identifier:name; 27, attribute; 27, 28; 27, 29; 28, identifier:params; 29, identifier:classes; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 38; 33, subscript; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:params; 36, identifier:classes; 37, identifier:name; 38, identifier:name; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:classdict; 42, dictionary_comprehension; 42, 43; 42, 46; 43, pair; 43, 44; 43, 45; 44, identifier:cls; 45, identifier:idx; 46, for_in_clause; 46, 47; 46, 50; 47, tuple_pattern; 47, 48; 47, 49; 48, identifier:idx; 49, identifier:cls; 50, call; 50, 51; 50, 52; 51, identifier:enumerate; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:params; 57, identifier:classes; 58, identifier:values; 59, argument_list; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:cblist; 63, list:[]; 64, for_statement; 64, 65; 64, 66; 64, 75; 65, identifier:name; 66, subscript; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:dfr; 69, identifier:index; 70, subscript; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:dend; 73, string:"dendrogram"; 74, string:"leaves"; 75, block; 75, 76; 76, try_statement; 76, 77; 76, 91; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:cblist; 82, identifier:append; 83, argument_list; 83, 84; 84, subscript; 84, 85; 84, 86; 85, identifier:classdict; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:params; 89, identifier:classes; 90, identifier:name; 91, except_clause; 91, 92; 91, 93; 92, identifier:KeyError; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:cblist; 98, identifier:append; 99, argument_list; 99, 100; 100, subscript; 100, 101; 100, 102; 101, identifier:classdict; 102, identifier:name; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:colbar; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:pd; 109, identifier:Series; 110, argument_list; 110, 111; 111, identifier:cblist; 112, if_statement; 112, 113; 112, 116; 112, 164; 113, comparison_operator:==; 113, 114; 113, 115; 114, identifier:orientation; 115, string:"row"; 116, block; 116, 117; 116, 131; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:cbaxes; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:fig; 123, identifier:add_subplot; 124, argument_list; 124, 125; 125, subscript; 125, 126; 125, 129; 125, 130; 126, subscript; 126, 127; 126, 128; 127, identifier:dend; 128, string:"gridspec"; 129, integer:0; 130, integer:1; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:cbaxes; 135, identifier:imshow; 136, argument_list; 136, 137; 136, 145; 136, 155; 136, 158; 136, 161; 137, list_comprehension; 137, 138; 137, 140; 138, list:[cbar]; 138, 139; 139, identifier:cbar; 140, for_in_clause; 140, 141; 140, 142; 141, identifier:cbar; 142, attribute; 142, 143; 142, 144; 143, identifier:colbar; 144, identifier:values; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:cmap; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:plt; 150, identifier:get_cmap; 151, argument_list; 151, 152; 152, attribute; 152, 153; 152, 154; 153, identifier:pyani_config; 154, identifier:MPL_CBAR; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:interpolation; 157, string:"nearest"; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:aspect; 160, string:"auto"; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:origin; 163, string:"lower"; 164, else_clause; 164, 165; 165, block; 165, 166; 165, 180; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:cbaxes; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:fig; 172, identifier:add_subplot; 173, argument_list; 173, 174; 174, subscript; 174, 175; 174, 178; 174, 179; 175, subscript; 175, 176; 175, 177; 176, identifier:dend; 177, string:"gridspec"; 178, integer:1; 179, integer:0; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:cbaxes; 184, identifier:imshow; 185, argument_list; 185, 186; 185, 188; 185, 198; 185, 201; 185, 204; 186, list:[colbar]; 186, 187; 187, identifier:colbar; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:cmap; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:plt; 193, identifier:get_cmap; 194, argument_list; 194, 195; 195, attribute; 195, 196; 195, 197; 196, identifier:pyani_config; 197, identifier:MPL_CBAR; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:interpolation; 200, string:"nearest"; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:aspect; 203, string:"auto"; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:origin; 206, string:"lower"; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 210; 209, identifier:clean_axis; 210, argument_list; 210, 211; 211, identifier:cbaxes; 212, return_statement; 212, 213; 213, identifier:colbar | def add_mpl_colorbar(dfr, fig, dend, params, orientation="row"):
for name in dfr.index[dend["dendrogram"]["leaves"]]:
if name not in params.classes:
params.classes[name] = name
classdict = {cls: idx for (idx, cls) in enumerate(params.classes.values())}
cblist = []
for name in dfr.index[dend["dendrogram"]["leaves"]]:
try:
cblist.append(classdict[params.classes[name]])
except KeyError:
cblist.append(classdict[name])
colbar = pd.Series(cblist)
if orientation == "row":
cbaxes = fig.add_subplot(dend["gridspec"][0, 1])
cbaxes.imshow(
[[cbar] for cbar in colbar.values],
cmap=plt.get_cmap(pyani_config.MPL_CBAR),
interpolation="nearest",
aspect="auto",
origin="lower",
)
else:
cbaxes = fig.add_subplot(dend["gridspec"][1, 0])
cbaxes.imshow(
[colbar],
cmap=plt.get_cmap(pyani_config.MPL_CBAR),
interpolation="nearest",
aspect="auto",
origin="lower",
)
clean_axis(cbaxes)
return colbar |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:calculate_anim; 3, parameters; 3, 4; 3, 5; 4, identifier:infiles; 5, identifier:org_lengths; 6, block; 6, 7; 6, 14; 6, 21; 6, 37; 6, 45; 6, 226; 6, 233; 6, 246; 6, 317; 6, 336; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:logger; 11, identifier:info; 12, argument_list; 12, 13; 13, string:"Running ANIm"; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:logger; 18, identifier:info; 19, argument_list; 19, 20; 20, string:"Generating NUCmer command-lines"; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:deltadir; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:os; 28, identifier:path; 29, identifier:join; 30, argument_list; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:args; 33, identifier:outdirname; 34, subscript; 34, 35; 34, 36; 35, identifier:ALIGNDIR; 36, string:"ANIm"; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:logger; 41, identifier:info; 42, argument_list; 42, 43; 42, 44; 43, string:"Writing nucmer output to %s"; 44, identifier:deltadir; 45, if_statement; 45, 46; 45, 50; 45, 217; 46, not_operator; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:args; 49, identifier:skip_nucmer; 50, block; 50, 51; 50, 83; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:joblist; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:anim; 57, identifier:generate_nucmer_jobs; 58, argument_list; 58, 59; 58, 60; 58, 63; 58, 68; 58, 73; 58, 78; 59, identifier:infiles; 60, attribute; 60, 61; 60, 62; 61, identifier:args; 62, identifier:outdirname; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:nucmer_exe; 65, attribute; 65, 66; 65, 67; 66, identifier:args; 67, identifier:nucmer_exe; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:filter_exe; 70, attribute; 70, 71; 70, 72; 71, identifier:args; 72, identifier:filter_exe; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:maxmatch; 75, attribute; 75, 76; 75, 77; 76, identifier:args; 77, identifier:maxmatch; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:jobprefix; 80, attribute; 80, 81; 80, 82; 81, identifier:args; 82, identifier:jobprefix; 83, if_statement; 83, 84; 83, 89; 83, 173; 84, comparison_operator:==; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:args; 87, identifier:scheduler; 88, string:"multiprocessing"; 89, block; 89, 90; 89, 97; 89, 125; 89, 142; 89, 150; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:logger; 94, identifier:info; 95, argument_list; 95, 96; 96, string:"Running jobs with multiprocessing"; 97, if_statement; 97, 98; 97, 103; 97, 113; 98, comparison_operator:is; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:args; 101, identifier:workers; 102, None; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:logger; 108, identifier:info; 109, argument_list; 109, 110; 110, binary_operator:+; 110, 111; 110, 112; 111, string:"(using maximum number of available "; 112, string:"worker threads)"; 113, else_clause; 113, 114; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:logger; 119, identifier:info; 120, argument_list; 120, 121; 120, 122; 121, string:"(using %d worker threads, if available)"; 122, attribute; 122, 123; 122, 124; 123, identifier:args; 124, identifier:workers; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:cumval; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:run_mp; 131, identifier:run_dependency_graph; 132, argument_list; 132, 133; 132, 134; 132, 139; 133, identifier:joblist; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:workers; 136, attribute; 136, 137; 136, 138; 137, identifier:args; 138, identifier:workers; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:logger; 141, identifier:logger; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:logger; 146, identifier:info; 147, argument_list; 147, 148; 147, 149; 148, string:"Cumulative return value: %d"; 149, identifier:cumval; 150, if_statement; 150, 151; 150, 154; 150, 164; 151, comparison_operator:<; 151, 152; 151, 153; 152, integer:0; 153, identifier:cumval; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:logger; 159, identifier:warning; 160, argument_list; 160, 161; 161, binary_operator:+; 161, 162; 161, 163; 162, string:"At least one NUCmer comparison failed. "; 163, string:"ANIm may fail."; 164, else_clause; 164, 165; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:logger; 170, identifier:info; 171, argument_list; 171, 172; 172, string:"All multiprocessing jobs complete."; 173, else_clause; 173, 174; 174, block; 174, 175; 174, 182; 174, 192; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:logger; 179, identifier:info; 180, argument_list; 180, 181; 181, string:"Running jobs with SGE"; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:logger; 186, identifier:info; 187, argument_list; 187, 188; 187, 189; 188, string:"Jobarray group size set to %d"; 189, attribute; 189, 190; 189, 191; 190, identifier:args; 191, identifier:sgegroupsize; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:run_sge; 196, identifier:run_dependency_graph; 197, argument_list; 197, 198; 197, 199; 197, 202; 197, 207; 197, 212; 198, identifier:joblist; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:logger; 201, identifier:logger; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:jgprefix; 204, attribute; 204, 205; 204, 206; 205, identifier:args; 206, identifier:jobprefix; 207, keyword_argument; 207, 208; 207, 209; 208, identifier:sgegroupsize; 209, attribute; 209, 210; 209, 211; 210, identifier:args; 211, identifier:sgegroupsize; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:sgeargs; 214, attribute; 214, 215; 214, 216; 215, identifier:args; 216, identifier:sgeargs; 217, else_clause; 217, 218; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:logger; 223, identifier:warning; 224, argument_list; 224, 225; 225, string:"Skipping NUCmer run (as instructed)!"; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:logger; 230, identifier:info; 231, argument_list; 231, 232; 232, string:"Processing NUCmer .delta files."; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:results; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:anim; 239, identifier:process_deltadir; 240, argument_list; 240, 241; 240, 242; 240, 243; 241, identifier:deltadir; 242, identifier:org_lengths; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:logger; 245, identifier:logger; 246, if_statement; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:results; 249, identifier:zero_error; 250, block; 250, 251; 251, if_statement; 251, 252; 251, 262; 252, boolean_operator:and; 252, 253; 252, 257; 253, not_operator; 253, 254; 254, attribute; 254, 255; 254, 256; 255, identifier:args; 256, identifier:skip_nucmer; 257, comparison_operator:==; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:args; 260, identifier:scheduler; 261, string:"multiprocessing"; 262, block; 262, 263; 263, if_statement; 263, 264; 263, 267; 263, 293; 264, comparison_operator:<; 264, 265; 264, 266; 265, integer:0; 266, identifier:cumval; 267, block; 267, 268; 267, 277; 267, 286; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:logger; 272, identifier:error; 273, argument_list; 273, 274; 274, binary_operator:+; 274, 275; 274, 276; 275, string:"This has possibly been a NUCmer run failure, "; 276, string:"please investigate"; 277, expression_statement; 277, 278; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:logger; 281, identifier:error; 282, argument_list; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:last_exception; 285, argument_list; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:sys; 290, identifier:exit; 291, argument_list; 291, 292; 292, integer:1; 293, else_clause; 293, 294; 294, block; 294, 295; 294, 306; 295, expression_statement; 295, 296; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:logger; 299, identifier:error; 300, argument_list; 300, 301; 301, binary_operator:+; 301, 302; 301, 305; 302, binary_operator:+; 302, 303; 302, 304; 303, string:"This is possibly due to a NUCmer comparison "; 304, string:"being too distant for use. Please consider "; 305, string:"using the --maxmatch option."; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:logger; 310, identifier:error; 311, argument_list; 311, 312; 312, binary_operator:+; 312, 313; 312, 316; 313, binary_operator:+; 313, 314; 313, 315; 314, string:"This is alternatively due to NUCmer run "; 315, string:"failure, analysis will continue, but please "; 316, string:"investigate."; 317, if_statement; 317, 318; 317, 322; 318, not_operator; 318, 319; 319, attribute; 319, 320; 319, 321; 320, identifier:args; 321, identifier:nocompress; 322, block; 322, 323; 322, 331; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:logger; 327, identifier:info; 328, argument_list; 328, 329; 328, 330; 329, string:"Compressing/deleting %s"; 330, identifier:deltadir; 331, expression_statement; 331, 332; 332, call; 332, 333; 332, 334; 333, identifier:compress_delete_outdir; 334, argument_list; 334, 335; 335, identifier:deltadir; 336, return_statement; 336, 337; 337, identifier:results | def calculate_anim(infiles, org_lengths):
logger.info("Running ANIm")
logger.info("Generating NUCmer command-lines")
deltadir = os.path.join(args.outdirname, ALIGNDIR["ANIm"])
logger.info("Writing nucmer output to %s", deltadir)
if not args.skip_nucmer:
joblist = anim.generate_nucmer_jobs(
infiles,
args.outdirname,
nucmer_exe=args.nucmer_exe,
filter_exe=args.filter_exe,
maxmatch=args.maxmatch,
jobprefix=args.jobprefix,
)
if args.scheduler == "multiprocessing":
logger.info("Running jobs with multiprocessing")
if args.workers is None:
logger.info("(using maximum number of available " + "worker threads)")
else:
logger.info("(using %d worker threads, if available)", args.workers)
cumval = run_mp.run_dependency_graph(
joblist, workers=args.workers, logger=logger
)
logger.info("Cumulative return value: %d", cumval)
if 0 < cumval:
logger.warning(
"At least one NUCmer comparison failed. " + "ANIm may fail."
)
else:
logger.info("All multiprocessing jobs complete.")
else:
logger.info("Running jobs with SGE")
logger.info("Jobarray group size set to %d", args.sgegroupsize)
run_sge.run_dependency_graph(
joblist,
logger=logger,
jgprefix=args.jobprefix,
sgegroupsize=args.sgegroupsize,
sgeargs=args.sgeargs,
)
else:
logger.warning("Skipping NUCmer run (as instructed)!")
logger.info("Processing NUCmer .delta files.")
results = anim.process_deltadir(deltadir, org_lengths, logger=logger)
if results.zero_error:
if not args.skip_nucmer and args.scheduler == "multiprocessing":
if 0 < cumval:
logger.error(
"This has possibly been a NUCmer run failure, "
+ "please investigate"
)
logger.error(last_exception())
sys.exit(1)
else:
logger.error(
"This is possibly due to a NUCmer comparison "
+ "being too distant for use. Please consider "
+ "using the --maxmatch option."
)
logger.error(
"This is alternatively due to NUCmer run "
+ "failure, analysis will continue, but please "
+ "investigate."
)
if not args.nocompress:
logger.info("Compressing/deleting %s", deltadir)
compress_delete_outdir(deltadir)
return results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:unified_anib; 3, parameters; 3, 4; 3, 5; 4, identifier:infiles; 5, identifier:org_lengths; 6, block; 6, 7; 6, 17; 6, 35; 6, 43; 6, 290; 6, 300; 6, 370; 6, 389; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:logger; 11, identifier:info; 12, argument_list; 12, 13; 12, 14; 13, string:"Running %s"; 14, attribute; 14, 15; 14, 16; 15, identifier:args; 16, identifier:method; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:blastdir; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:os; 24, identifier:path; 25, identifier:join; 26, argument_list; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:args; 29, identifier:outdirname; 30, subscript; 30, 31; 30, 32; 31, identifier:ALIGNDIR; 32, attribute; 32, 33; 32, 34; 33, identifier:args; 34, identifier:method; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:logger; 39, identifier:info; 40, argument_list; 40, 41; 40, 42; 41, string:"Writing BLAST output to %s"; 42, identifier:blastdir; 43, if_statement; 43, 44; 43, 48; 43, 239; 44, not_operator; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:args; 47, identifier:skip_blastn; 48, block; 48, 49; 48, 59; 48, 74; 48, 102; 48, 109; 48, 128; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:logger; 53, identifier:info; 54, argument_list; 54, 55; 54, 56; 55, string:"Fragmenting input files, and writing to %s"; 56, attribute; 56, 57; 56, 58; 57, identifier:args; 58, identifier:outdirname; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, pattern_list; 61, 62; 61, 63; 62, identifier:fragfiles; 63, identifier:fraglengths; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:anib; 67, identifier:fragment_fasta_files; 68, argument_list; 68, 69; 68, 70; 68, 71; 69, identifier:infiles; 70, identifier:blastdir; 71, attribute; 71, 72; 71, 73; 72, identifier:args; 73, identifier:fragsize; 74, with_statement; 74, 75; 74, 93; 75, with_clause; 75, 76; 76, with_item; 76, 77; 77, as_pattern; 77, 78; 77, 91; 78, call; 78, 79; 78, 80; 79, identifier:open; 80, argument_list; 80, 81; 80, 90; 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:blastdir; 89, string:"fraglengths.json"; 90, string:"w"; 91, as_pattern_target; 91, 92; 92, identifier:outfile; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:json; 98, identifier:dump; 99, argument_list; 99, 100; 99, 101; 100, identifier:fraglengths; 101, identifier:outfile; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:logger; 106, identifier:info; 107, argument_list; 107, 108; 108, string:"Creating job dependency graph"; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:jobgraph; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:anib; 115, identifier:make_job_graph; 116, argument_list; 116, 117; 116, 118; 116, 119; 117, identifier:infiles; 118, identifier:fragfiles; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:anib; 122, identifier:make_blastcmd_builder; 123, argument_list; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:args; 126, identifier:method; 127, identifier:blastdir; 128, if_statement; 128, 129; 128, 134; 128, 220; 129, comparison_operator:==; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:args; 132, identifier:scheduler; 133, string:"multiprocessing"; 134, block; 134, 135; 134, 142; 134, 149; 134, 177; 134, 194; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:logger; 139, identifier:info; 140, argument_list; 140, 141; 141, string:"Running jobs with multiprocessing"; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:logger; 146, identifier:info; 147, argument_list; 147, 148; 148, string:"Running job dependency graph"; 149, if_statement; 149, 150; 149, 155; 149, 165; 150, comparison_operator:is; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:args; 153, identifier:workers; 154, None; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:logger; 160, identifier:info; 161, argument_list; 161, 162; 162, binary_operator:+; 162, 163; 162, 164; 163, string:"(using maximum number of available "; 164, string:"worker threads)"; 165, else_clause; 165, 166; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:logger; 171, identifier:info; 172, argument_list; 172, 173; 172, 174; 173, string:"(using %d worker threads, if available)"; 174, attribute; 174, 175; 174, 176; 175, identifier:args; 176, identifier:workers; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:cumval; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:run_mp; 183, identifier:run_dependency_graph; 184, argument_list; 184, 185; 184, 186; 184, 191; 185, identifier:jobgraph; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:workers; 188, attribute; 188, 189; 188, 190; 189, identifier:args; 190, identifier:workers; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:logger; 193, identifier:logger; 194, if_statement; 194, 195; 194, 198; 194, 211; 195, comparison_operator:<; 195, 196; 195, 197; 196, integer:0; 197, identifier:cumval; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:logger; 203, identifier:warning; 204, argument_list; 204, 205; 204, 208; 205, binary_operator:+; 205, 206; 205, 207; 206, string:"At least one BLAST run failed. "; 207, string:"%s may fail."; 208, attribute; 208, 209; 208, 210; 209, identifier:args; 210, identifier:method; 211, else_clause; 211, 212; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:logger; 217, identifier:info; 218, argument_list; 218, 219; 219, string:"All multiprocessing jobs complete."; 220, else_clause; 220, 221; 221, block; 221, 222; 221, 232; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:run_sge; 226, identifier:run_dependency_graph; 227, argument_list; 227, 228; 227, 229; 228, identifier:jobgraph; 229, keyword_argument; 229, 230; 229, 231; 230, identifier:logger; 231, identifier:logger; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:logger; 236, identifier:info; 237, argument_list; 237, 238; 238, string:"Running jobs with SGE"; 239, else_clause; 239, 240; 240, block; 240, 241; 240, 283; 241, if_statement; 241, 242; 241, 247; 241, 277; 242, comparison_operator:==; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:args; 245, identifier:method; 246, string:"ANIblastall"; 247, block; 247, 248; 248, with_statement; 248, 249; 248, 267; 249, with_clause; 249, 250; 250, with_item; 250, 251; 251, as_pattern; 251, 252; 251, 265; 252, call; 252, 253; 252, 254; 253, identifier:open; 254, argument_list; 254, 255; 254, 264; 255, call; 255, 256; 255, 261; 256, attribute; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:os; 259, identifier:path; 260, identifier:join; 261, argument_list; 261, 262; 261, 263; 262, identifier:blastdir; 263, string:"fraglengths.json"; 264, string:"rU"; 265, as_pattern_target; 265, 266; 266, identifier:infile; 267, block; 267, 268; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:fraglengths; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:json; 274, identifier:load; 275, argument_list; 275, 276; 276, identifier:infile; 277, else_clause; 277, 278; 278, block; 278, 279; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:fraglengths; 282, None; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:logger; 287, identifier:warning; 288, argument_list; 288, 289; 289, string:"Skipping BLASTN runs (as instructed)!"; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:logger; 294, identifier:info; 295, argument_list; 295, 296; 295, 297; 296, string:"Processing pairwise %s BLAST output."; 297, attribute; 297, 298; 297, 299; 298, identifier:args; 299, identifier:method; 300, try_statement; 300, 301; 300, 320; 301, block; 301, 302; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:data; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:anib; 308, identifier:process_blast; 309, argument_list; 309, 310; 309, 311; 309, 312; 309, 315; 310, identifier:blastdir; 311, identifier:org_lengths; 312, keyword_argument; 312, 313; 312, 314; 313, identifier:fraglengths; 314, identifier:fraglengths; 315, keyword_argument; 315, 316; 315, 317; 316, identifier:mode; 317, attribute; 317, 318; 317, 319; 318, identifier:args; 319, identifier:method; 320, except_clause; 320, 321; 320, 322; 321, identifier:ZeroDivisionError; 322, block; 322, 323; 322, 330; 322, 361; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:logger; 327, identifier:error; 328, argument_list; 328, 329; 329, string:"One or more BLAST output files has a problem."; 330, if_statement; 330, 331; 330, 335; 331, not_operator; 331, 332; 332, attribute; 332, 333; 332, 334; 333, identifier:args; 334, identifier:skip_blastn; 335, block; 335, 336; 336, if_statement; 336, 337; 336, 340; 336, 350; 337, comparison_operator:<; 337, 338; 337, 339; 338, integer:0; 339, identifier:cumval; 340, block; 340, 341; 341, expression_statement; 341, 342; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:logger; 345, identifier:error; 346, argument_list; 346, 347; 347, binary_operator:+; 347, 348; 347, 349; 348, string:"This is possibly due to BLASTN run failure, "; 349, string:"please investigate"; 350, else_clause; 350, 351; 351, block; 351, 352; 352, expression_statement; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:logger; 356, identifier:error; 357, argument_list; 357, 358; 358, binary_operator:+; 358, 359; 358, 360; 359, string:"This is possibly due to a BLASTN comparison "; 360, string:"being too distant for use."; 361, expression_statement; 361, 362; 362, call; 362, 363; 362, 366; 363, attribute; 363, 364; 363, 365; 364, identifier:logger; 365, identifier:error; 366, argument_list; 366, 367; 367, call; 367, 368; 367, 369; 368, identifier:last_exception; 369, argument_list; 370, if_statement; 370, 371; 370, 375; 371, not_operator; 371, 372; 372, attribute; 372, 373; 372, 374; 373, identifier:args; 374, identifier:nocompress; 375, block; 375, 376; 375, 384; 376, expression_statement; 376, 377; 377, call; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:logger; 380, identifier:info; 381, argument_list; 381, 382; 381, 383; 382, string:"Compressing/deleting %s"; 383, identifier:blastdir; 384, expression_statement; 384, 385; 385, call; 385, 386; 385, 387; 386, identifier:compress_delete_outdir; 387, argument_list; 387, 388; 388, identifier:blastdir; 389, return_statement; 389, 390; 390, identifier:data | def unified_anib(infiles, org_lengths):
logger.info("Running %s", args.method)
blastdir = os.path.join(args.outdirname, ALIGNDIR[args.method])
logger.info("Writing BLAST output to %s", blastdir)
if not args.skip_blastn:
logger.info("Fragmenting input files, and writing to %s", args.outdirname)
fragfiles, fraglengths = anib.fragment_fasta_files(
infiles, blastdir, args.fragsize
)
with open(os.path.join(blastdir, "fraglengths.json"), "w") as outfile:
json.dump(fraglengths, outfile)
logger.info("Creating job dependency graph")
jobgraph = anib.make_job_graph(
infiles, fragfiles, anib.make_blastcmd_builder(args.method, blastdir)
)
if args.scheduler == "multiprocessing":
logger.info("Running jobs with multiprocessing")
logger.info("Running job dependency graph")
if args.workers is None:
logger.info("(using maximum number of available " + "worker threads)")
else:
logger.info("(using %d worker threads, if available)", args.workers)
cumval = run_mp.run_dependency_graph(
jobgraph, workers=args.workers, logger=logger
)
if 0 < cumval:
logger.warning(
"At least one BLAST run failed. " + "%s may fail.", args.method
)
else:
logger.info("All multiprocessing jobs complete.")
else:
run_sge.run_dependency_graph(jobgraph, logger=logger)
logger.info("Running jobs with SGE")
else:
if args.method == "ANIblastall":
with open(os.path.join(blastdir, "fraglengths.json"), "rU") as infile:
fraglengths = json.load(infile)
else:
fraglengths = None
logger.warning("Skipping BLASTN runs (as instructed)!")
logger.info("Processing pairwise %s BLAST output.", args.method)
try:
data = anib.process_blast(
blastdir, org_lengths, fraglengths=fraglengths, mode=args.method
)
except ZeroDivisionError:
logger.error("One or more BLAST output files has a problem.")
if not args.skip_blastn:
if 0 < cumval:
logger.error(
"This is possibly due to BLASTN run failure, "
+ "please investigate"
)
else:
logger.error(
"This is possibly due to a BLASTN comparison "
+ "being too distant for use."
)
logger.error(last_exception())
if not args.nocompress:
logger.info("Compressing/deleting %s", blastdir)
compress_delete_outdir(blastdir)
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:process_deltadir; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:delta_dir; 5, identifier:org_lengths; 6, default_parameter; 6, 7; 6, 8; 7, identifier:logger; 8, None; 9, block; 9, 10; 9, 20; 9, 35; 9, 58; 9, 267; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:deltafiles; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:pyani_files; 16, identifier:get_input_files; 17, argument_list; 17, 18; 17, 19; 18, identifier:delta_dir; 19, string:".filter"; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:results; 23, call; 23, 24; 23, 25; 24, identifier:ANIResults; 25, argument_list; 25, 26; 25, 34; 26, call; 26, 27; 26, 28; 27, identifier:list; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:org_lengths; 32, identifier:keys; 33, argument_list; 34, string:"ANIm"; 35, for_statement; 35, 36; 35, 39; 35, 47; 36, pattern_list; 36, 37; 36, 38; 37, identifier:org; 38, identifier:length; 39, call; 39, 40; 39, 41; 40, identifier:list; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:org_lengths; 45, identifier:items; 46, argument_list; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 57; 50, subscript; 50, 51; 50, 56; 51, subscript; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:results; 54, identifier:alignment_lengths; 55, identifier:org; 56, identifier:org; 57, identifier:length; 58, for_statement; 58, 59; 58, 60; 58, 61; 59, identifier:deltafile; 60, identifier:deltafiles; 61, block; 61, 62; 61, 92; 61, 121; 61, 150; 61, 159; 61, 182; 61, 193; 61, 204; 61, 230; 61, 239; 61, 248; 61, 257; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, pattern_list; 64, 65; 64, 66; 65, identifier:qname; 66, identifier:sname; 67, call; 67, 68; 67, 90; 68, attribute; 68, 69; 68, 89; 69, subscript; 69, 70; 69, 88; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:os; 74, identifier:path; 75, identifier:splitext; 76, argument_list; 76, 77; 77, subscript; 77, 78; 77, 86; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:os; 82, identifier:path; 83, identifier:split; 84, argument_list; 84, 85; 85, identifier:deltafile; 86, unary_operator:-; 86, 87; 87, integer:1; 88, integer:0; 89, identifier:split; 90, argument_list; 90, 91; 91, string:"_vs_"; 92, if_statement; 92, 93; 92, 103; 93, comparison_operator:not; 93, 94; 93, 95; 94, identifier:qname; 95, call; 95, 96; 95, 97; 96, identifier:list; 97, argument_list; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:org_lengths; 101, identifier:keys; 102, argument_list; 103, block; 103, 104; 103, 120; 104, if_statement; 104, 105; 104, 106; 105, identifier:logger; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:logger; 111, identifier:warning; 112, argument_list; 112, 113; 113, binary_operator:+; 113, 114; 113, 117; 114, binary_operator:%; 114, 115; 114, 116; 115, string:"Query name %s not in input "; 116, identifier:qname; 117, binary_operator:%; 117, 118; 117, 119; 118, string:"sequence list, skipping %s"; 119, identifier:deltafile; 120, continue_statement; 121, if_statement; 121, 122; 121, 132; 122, comparison_operator:not; 122, 123; 122, 124; 123, identifier:sname; 124, call; 124, 125; 124, 126; 125, identifier:list; 126, argument_list; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:org_lengths; 130, identifier:keys; 131, argument_list; 132, block; 132, 133; 132, 149; 133, if_statement; 133, 134; 133, 135; 134, identifier:logger; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:logger; 140, identifier:warning; 141, argument_list; 141, 142; 142, binary_operator:+; 142, 143; 142, 146; 143, binary_operator:%; 143, 144; 143, 145; 144, string:"Subject name %s not in input "; 145, identifier:sname; 146, binary_operator:%; 146, 147; 146, 148; 147, string:"sequence list, skipping %s"; 148, identifier:deltafile; 149, continue_statement; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 155; 152, pattern_list; 152, 153; 152, 154; 153, identifier:tot_length; 154, identifier:tot_sim_error; 155, call; 155, 156; 155, 157; 156, identifier:parse_delta; 157, argument_list; 157, 158; 158, identifier:deltafile; 159, if_statement; 159, 160; 159, 167; 160, boolean_operator:and; 160, 161; 160, 164; 161, comparison_operator:==; 161, 162; 161, 163; 162, identifier:tot_length; 163, integer:0; 164, comparison_operator:is; 164, 165; 164, 166; 165, identifier:logger; 166, None; 167, block; 167, 168; 168, if_statement; 168, 169; 168, 170; 169, identifier:logger; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:logger; 175, identifier:warning; 176, argument_list; 176, 177; 177, binary_operator:+; 177, 178; 177, 179; 178, string:"Total alignment length reported in "; 179, binary_operator:%; 179, 180; 179, 181; 180, string:"%s is zero!"; 181, identifier:deltafile; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:query_cover; 185, binary_operator:/; 185, 186; 185, 190; 186, call; 186, 187; 186, 188; 187, identifier:float; 188, argument_list; 188, 189; 189, identifier:tot_length; 190, subscript; 190, 191; 190, 192; 191, identifier:org_lengths; 192, identifier:qname; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:sbjct_cover; 196, binary_operator:/; 196, 197; 196, 201; 197, call; 197, 198; 197, 199; 198, identifier:float; 199, argument_list; 199, 200; 200, identifier:tot_length; 201, subscript; 201, 202; 201, 203; 202, identifier:org_lengths; 203, identifier:sname; 204, try_statement; 204, 205; 204, 217; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:perc_id; 209, binary_operator:-; 209, 210; 209, 211; 210, integer:1; 211, binary_operator:/; 211, 212; 211, 216; 212, call; 212, 213; 212, 214; 213, identifier:float; 214, argument_list; 214, 215; 215, identifier:tot_sim_error; 216, identifier:tot_length; 217, except_clause; 217, 218; 217, 219; 218, identifier:ZeroDivisionError; 219, block; 219, 220; 219, 224; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:perc_id; 223, integer:0; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:results; 228, identifier:zero_error; 229, True; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:results; 234, identifier:add_tot_length; 235, argument_list; 235, 236; 235, 237; 235, 238; 236, identifier:qname; 237, identifier:sname; 238, identifier:tot_length; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:results; 243, identifier:add_sim_errors; 244, argument_list; 244, 245; 244, 246; 244, 247; 245, identifier:qname; 246, identifier:sname; 247, identifier:tot_sim_error; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:results; 252, identifier:add_pid; 253, argument_list; 253, 254; 253, 255; 253, 256; 254, identifier:qname; 255, identifier:sname; 256, identifier:perc_id; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:results; 261, identifier:add_coverage; 262, argument_list; 262, 263; 262, 264; 262, 265; 262, 266; 263, identifier:qname; 264, identifier:sname; 265, identifier:query_cover; 266, identifier:sbjct_cover; 267, return_statement; 267, 268; 268, identifier:results | def process_deltadir(delta_dir, org_lengths, logger=None):
deltafiles = pyani_files.get_input_files(delta_dir, ".filter")
results = ANIResults(list(org_lengths.keys()), "ANIm")
for org, length in list(org_lengths.items()):
results.alignment_lengths[org][org] = length
for deltafile in deltafiles:
qname, sname = os.path.splitext(os.path.split(deltafile)[-1])[0].split("_vs_")
if qname not in list(org_lengths.keys()):
if logger:
logger.warning(
"Query name %s not in input " % qname
+ "sequence list, skipping %s" % deltafile
)
continue
if sname not in list(org_lengths.keys()):
if logger:
logger.warning(
"Subject name %s not in input " % sname
+ "sequence list, skipping %s" % deltafile
)
continue
tot_length, tot_sim_error = parse_delta(deltafile)
if tot_length == 0 and logger is not None:
if logger:
logger.warning(
"Total alignment length reported in " + "%s is zero!" % deltafile
)
query_cover = float(tot_length) / org_lengths[qname]
sbjct_cover = float(tot_length) / org_lengths[sname]
try:
perc_id = 1 - float(tot_sim_error) / tot_length
except ZeroDivisionError:
perc_id = 0
results.zero_error = True
results.add_tot_length(qname, sname, tot_length)
results.add_sim_errors(qname, sname, tot_sim_error)
results.add_pid(qname, sname, perc_id)
results.add_coverage(qname, sname, query_cover, sbjct_cover)
return results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:write_contigs; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:asm_uid; 5, identifier:contig_uids; 6, default_parameter; 6, 7; 6, 8; 7, identifier:batchsize; 8, integer:10000; 9, block; 9, 10; 9, 18; 9, 44; 9, 56; 9, 83; 9, 107; 9, 119; 9, 140; 9, 148; 9, 332; 9, 344; 9, 355; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:logger; 14, identifier:info; 15, argument_list; 15, 16; 15, 17; 16, string:"Collecting contig data for %s"; 17, identifier:asm_uid; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:asm_record; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:Entrez; 24, identifier:read; 25, argument_list; 25, 26; 25, 41; 26, call; 26, 27; 26, 28; 27, identifier:entrez_retry; 28, argument_list; 28, 29; 28, 32; 28, 35; 28, 38; 29, attribute; 29, 30; 29, 31; 30, identifier:Entrez; 31, identifier:esummary; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:db; 34, string:'assembly'; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:id; 37, identifier:asm_uid; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:rettype; 40, string:'text'; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:validate; 43, False; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:asm_organism; 47, subscript; 47, 48; 47, 55; 48, subscript; 48, 49; 48, 54; 49, subscript; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:asm_record; 52, string:'DocumentSummarySet'; 53, string:'DocumentSummary'; 54, integer:0; 55, string:'SpeciesName'; 56, try_statement; 56, 57; 56, 76; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:asm_strain; 61, subscript; 61, 62; 61, 75; 62, subscript; 62, 63; 62, 74; 63, subscript; 63, 64; 63, 73; 64, subscript; 64, 65; 64, 72; 65, subscript; 65, 66; 65, 71; 66, subscript; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:asm_record; 69, string:'DocumentSummarySet'; 70, string:'DocumentSummary'; 71, integer:0; 72, string:'Biosource'; 73, string:'InfraspeciesList'; 74, integer:0; 75, string:'Sub_value'; 76, except_clause; 76, 77; 76, 78; 77, identifier:KeyError; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:asm_strain; 82, string:""; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:outfilename; 86, binary_operator:%; 86, 87; 86, 88; 87, string:"%s.fasta"; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:os; 92, identifier:path; 93, identifier:join; 94, argument_list; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:args; 97, identifier:outdirname; 98, subscript; 98, 99; 98, 106; 99, subscript; 99, 100; 99, 105; 100, subscript; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:asm_record; 103, string:'DocumentSummarySet'; 104, string:'DocumentSummary'; 105, integer:0; 106, string:'AssemblyAccession'; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, pattern_list; 109, 110; 109, 111; 110, identifier:genus; 111, identifier:species; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:asm_organism; 115, identifier:split; 116, argument_list; 116, 117; 116, 118; 117, string:' '; 118, integer:1; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:logger; 123, identifier:info; 124, argument_list; 124, 125; 124, 126; 124, 127; 125, string:"Downloading FASTA records for assembly %s (%s)"; 126, identifier:asm_uid; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, string:' '; 130, identifier:join; 131, argument_list; 131, 132; 132, list:[genus[0] + '.', species, asm_strain]; 132, 133; 132, 138; 132, 139; 133, binary_operator:+; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:genus; 136, integer:0; 137, string:'.'; 138, identifier:species; 139, identifier:asm_strain; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 145; 142, pattern_list; 142, 143; 142, 144; 143, identifier:tries; 144, identifier:success; 145, expression_list; 145, 146; 145, 147; 146, integer:0; 147, False; 148, while_statement; 148, 149; 148, 157; 149, boolean_operator:and; 149, 150; 149, 152; 150, not_operator; 150, 151; 151, identifier:success; 152, comparison_operator:<; 152, 153; 152, 154; 153, identifier:tries; 154, attribute; 154, 155; 154, 156; 155, identifier:args; 156, identifier:retries; 157, block; 157, 158; 157, 162; 157, 171; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:records; 161, list:[]; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:query_uids; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, string:','; 168, identifier:join; 169, argument_list; 169, 170; 170, identifier:contig_uids; 171, try_statement; 171, 172; 171, 305; 172, block; 172, 173; 172, 235; 172, 239; 172, 287; 173, for_statement; 173, 174; 173, 175; 173, 184; 174, identifier:start; 175, call; 175, 176; 175, 177; 176, identifier:range; 177, argument_list; 177, 178; 177, 179; 177, 183; 178, integer:0; 179, call; 179, 180; 179, 181; 180, identifier:len; 181, argument_list; 181, 182; 182, identifier:contig_uids; 183, identifier:batchsize; 184, block; 184, 185; 184, 196; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:logger; 189, identifier:info; 190, argument_list; 190, 191; 190, 192; 190, 193; 191, string:"Batch: %d-%d"; 192, identifier:start; 193, binary_operator:+; 193, 194; 193, 195; 194, identifier:start; 195, identifier:batchsize; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:records; 200, identifier:extend; 201, argument_list; 201, 202; 202, call; 202, 203; 202, 204; 203, identifier:list; 204, argument_list; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:SeqIO; 208, identifier:parse; 209, argument_list; 209, 210; 209, 234; 210, call; 210, 211; 210, 212; 211, identifier:entrez_retry; 212, argument_list; 212, 213; 212, 216; 212, 219; 212, 222; 212, 225; 212, 228; 212, 231; 213, attribute; 213, 214; 213, 215; 214, identifier:Entrez; 215, identifier:efetch; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:db; 218, string:'nucleotide'; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:id; 221, identifier:query_uids; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:rettype; 224, string:'fasta'; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:retmode; 227, string:'text'; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:retstart; 230, identifier:start; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:retmax; 233, identifier:batchsize; 234, string:'fasta'; 235, expression_statement; 235, 236; 236, augmented_assignment:+=; 236, 237; 236, 238; 237, identifier:tries; 238, integer:1; 239, if_statement; 239, 240; 239, 249; 239, 254; 240, comparison_operator:==; 240, 241; 240, 245; 241, call; 241, 242; 241, 243; 242, identifier:len; 243, argument_list; 243, 244; 244, identifier:records; 245, call; 245, 246; 245, 247; 246, identifier:len; 247, argument_list; 247, 248; 248, identifier:contig_uids; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:success; 253, True; 254, else_clause; 254, 255; 255, block; 255, 256; 255, 271; 255, 279; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:logger; 260, identifier:warning; 261, argument_list; 261, 262; 261, 263; 261, 267; 262, string:"%d contigs expected, %d contigs returned"; 263, call; 263, 264; 263, 265; 264, identifier:len; 265, argument_list; 265, 266; 266, identifier:contig_uids; 267, call; 267, 268; 267, 269; 268, identifier:len; 269, argument_list; 269, 270; 270, identifier:records; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:logger; 275, identifier:warning; 276, argument_list; 276, 277; 276, 278; 277, string:"FASTA download for assembly %s failed"; 278, identifier:asm_uid; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:logger; 283, identifier:warning; 284, argument_list; 284, 285; 284, 286; 285, string:"try %d/20"; 286, identifier:tries; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:logger; 291, identifier:info; 292, argument_list; 292, 293; 292, 294; 293, string:"Downloaded genome size: %d"; 294, call; 294, 295; 294, 296; 295, identifier:sum; 296, argument_list; 296, 297; 297, list_comprehension; 297, 298; 297, 302; 298, call; 298, 299; 298, 300; 299, identifier:len; 300, argument_list; 300, 301; 301, identifier:r; 302, for_in_clause; 302, 303; 302, 304; 303, identifier:r; 304, identifier:records; 305, except_clause; 305, 306; 306, block; 306, 307; 306, 315; 306, 324; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:logger; 311, identifier:warning; 312, argument_list; 312, 313; 312, 314; 313, string:"FASTA download for assembly %s failed"; 314, identifier:asm_uid; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:logger; 319, identifier:warning; 320, argument_list; 320, 321; 321, call; 321, 322; 321, 323; 322, identifier:last_exception; 323, argument_list; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:logger; 328, identifier:warning; 329, argument_list; 329, 330; 329, 331; 330, string:"try %d/20"; 331, identifier:tries; 332, if_statement; 332, 333; 332, 335; 333, not_operator; 333, 334; 334, identifier:success; 335, block; 335, 336; 336, expression_statement; 336, 337; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:logger; 340, identifier:error; 341, argument_list; 341, 342; 341, 343; 342, string:"Failed to download records for %s (continuing)"; 343, identifier:asm_uid; 344, expression_statement; 344, 345; 345, assignment; 345, 346; 345, 347; 346, identifier:retval; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:SeqIO; 350, identifier:write; 351, argument_list; 351, 352; 351, 353; 351, 354; 352, identifier:records; 353, identifier:outfilename; 354, string:'fasta'; 355, expression_statement; 355, 356; 356, call; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:logger; 359, identifier:info; 360, argument_list; 360, 361; 360, 362; 360, 363; 361, string:"Wrote %d contigs to %s"; 362, identifier:retval; 363, identifier:outfilename | def write_contigs(asm_uid, contig_uids, batchsize=10000):
logger.info("Collecting contig data for %s", asm_uid)
asm_record = Entrez.read(
entrez_retry(
Entrez.esummary, db='assembly', id=asm_uid, rettype='text'),
validate=False)
asm_organism = asm_record['DocumentSummarySet']['DocumentSummary'][0][
'SpeciesName']
try:
asm_strain = asm_record['DocumentSummarySet']['DocumentSummary'][0][
'Biosource']['InfraspeciesList'][0]['Sub_value']
except KeyError:
asm_strain = ""
outfilename = "%s.fasta" % os.path.join(args.outdirname, asm_record[
'DocumentSummarySet']['DocumentSummary'][0]['AssemblyAccession'])
genus, species = asm_organism.split(' ', 1)
logger.info("Downloading FASTA records for assembly %s (%s)", asm_uid,
' '.join([genus[0] + '.', species, asm_strain]))
tries, success = 0, False
while not success and tries < args.retries:
records = []
query_uids = ','.join(contig_uids)
try:
for start in range(0, len(contig_uids), batchsize):
logger.info("Batch: %d-%d", start, start + batchsize)
records.extend(
list(
SeqIO.parse(
entrez_retry(
Entrez.efetch,
db='nucleotide',
id=query_uids,
rettype='fasta',
retmode='text',
retstart=start,
retmax=batchsize), 'fasta')))
tries += 1
if len(records) == len(contig_uids):
success = True
else:
logger.warning("%d contigs expected, %d contigs returned",
len(contig_uids), len(records))
logger.warning("FASTA download for assembly %s failed",
asm_uid)
logger.warning("try %d/20", tries)
logger.info("Downloaded genome size: %d",
sum([len(r) for r in records]))
except:
logger.warning("FASTA download for assembly %s failed", asm_uid)
logger.warning(last_exception())
logger.warning("try %d/20", tries)
if not success:
logger.error("Failed to download records for %s (continuing)", asm_uid)
retval = SeqIO.write(records, outfilename, 'fasta')
logger.info("Wrote %d contigs to %s", retval, outfilename) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:calculate_tetra_zscore; 3, parameters; 3, 4; 4, identifier:filename; 5, block; 5, 6; 5, 34; 5, 258; 5, 262; 5, 315; 5, 319; 5, 323; 5, 442; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:counts; 9, tuple; 9, 10; 9, 16; 9, 22; 9, 28; 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:int; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:collections; 19, identifier:defaultdict; 20, argument_list; 20, 21; 21, identifier:int; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:collections; 25, identifier:defaultdict; 26, argument_list; 26, 27; 27, identifier:int; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:collections; 31, identifier:defaultdict; 32, argument_list; 32, 33; 33, identifier:int; 34, for_statement; 34, 35; 34, 36; 34, 43; 35, identifier:rec; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:SeqIO; 39, identifier:parse; 40, argument_list; 40, 41; 40, 42; 41, identifier:filename; 42, string:'fasta'; 43, block; 43, 44; 44, for_statement; 44, 45; 44, 46; 44, 71; 45, identifier:seq; 46, list:[str(rec.seq).upper(),
str(rec.seq.reverse_complement()).upper()]; 46, 47; 46, 57; 47, call; 47, 48; 47, 56; 48, attribute; 48, 49; 48, 55; 49, call; 49, 50; 49, 51; 50, identifier:str; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:rec; 54, identifier:seq; 55, identifier:upper; 56, argument_list; 57, call; 57, 58; 57, 70; 58, attribute; 58, 59; 58, 69; 59, call; 59, 60; 59, 61; 60, identifier:str; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:rec; 66, identifier:seq; 67, identifier:reverse_complement; 68, argument_list; 69, identifier:upper; 70, argument_list; 71, block; 71, 72; 71, 93; 71, 172; 71, 190; 71, 206; 71, 224; 71, 242; 72, for_statement; 72, 73; 72, 74; 72, 79; 73, identifier:base; 74, tuple; 74, 75; 74, 76; 74, 77; 74, 78; 75, string:'G'; 76, string:'C'; 77, string:'T'; 78, string:'A'; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, augmented_assignment:+=; 81, 82; 81, 87; 82, subscript; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:counts; 85, integer:0; 86, identifier:base; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:seq; 90, identifier:count; 91, argument_list; 91, 92; 92, identifier:base; 93, for_statement; 93, 94; 93, 95; 93, 107; 94, identifier:i; 95, call; 95, 96; 95, 97; 96, identifier:range; 97, argument_list; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, subscript; 101, 102; 101, 103; 102, identifier:seq; 103, slice; 103, 104; 103, 105; 104, colon; 105, unary_operator:-; 105, 106; 106, integer:4; 107, block; 107, 108; 107, 139; 107, 150; 107, 161; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 114; 110, pattern_list; 110, 111; 110, 112; 110, 113; 111, identifier:din; 112, identifier:tri; 113, identifier:tetra; 114, expression_list; 114, 115; 114, 123; 114, 131; 115, subscript; 115, 116; 115, 117; 116, identifier:seq; 117, slice; 117, 118; 117, 119; 117, 120; 118, identifier:i; 119, colon; 120, binary_operator:+; 120, 121; 120, 122; 121, identifier:i; 122, integer:2; 123, subscript; 123, 124; 123, 125; 124, identifier:seq; 125, slice; 125, 126; 125, 127; 125, 128; 126, identifier:i; 127, colon; 128, binary_operator:+; 128, 129; 128, 130; 129, identifier:i; 130, integer:3; 131, subscript; 131, 132; 131, 133; 132, identifier:seq; 133, slice; 133, 134; 133, 135; 133, 136; 134, identifier:i; 135, colon; 136, binary_operator:+; 136, 137; 136, 138; 137, identifier:i; 138, integer:4; 139, expression_statement; 139, 140; 140, augmented_assignment:+=; 140, 141; 140, 149; 141, subscript; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:counts; 144, integer:1; 145, call; 145, 146; 145, 147; 146, identifier:str; 147, argument_list; 147, 148; 148, identifier:din; 149, integer:1; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 160; 152, subscript; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:counts; 155, integer:2; 156, call; 156, 157; 156, 158; 157, identifier:str; 158, argument_list; 158, 159; 159, identifier:tri; 160, integer:1; 161, expression_statement; 161, 162; 162, augmented_assignment:+=; 162, 163; 162, 171; 163, subscript; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:counts; 166, integer:3; 167, call; 167, 168; 167, 169; 168, identifier:str; 169, argument_list; 169, 170; 170, identifier:tetra; 171, integer:1; 172, expression_statement; 172, 173; 173, augmented_assignment:+=; 173, 174; 173, 189; 174, subscript; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:counts; 177, integer:2; 178, call; 178, 179; 178, 180; 179, identifier:str; 180, argument_list; 180, 181; 181, subscript; 181, 182; 181, 183; 182, identifier:seq; 183, slice; 183, 184; 183, 186; 183, 187; 184, unary_operator:-; 184, 185; 185, integer:4; 186, colon; 187, unary_operator:-; 187, 188; 188, integer:1; 189, integer:1; 190, expression_statement; 190, 191; 191, augmented_assignment:+=; 191, 192; 191, 205; 192, subscript; 192, 193; 192, 196; 193, subscript; 193, 194; 193, 195; 194, identifier:counts; 195, integer:2; 196, call; 196, 197; 196, 198; 197, identifier:str; 198, argument_list; 198, 199; 199, subscript; 199, 200; 199, 201; 200, identifier:seq; 201, slice; 201, 202; 201, 204; 202, unary_operator:-; 202, 203; 203, integer:3; 204, colon; 205, integer:1; 206, expression_statement; 206, 207; 207, augmented_assignment:+=; 207, 208; 207, 223; 208, subscript; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:counts; 211, integer:1; 212, call; 212, 213; 212, 214; 213, identifier:str; 214, argument_list; 214, 215; 215, subscript; 215, 216; 215, 217; 216, identifier:seq; 217, slice; 217, 218; 217, 220; 217, 221; 218, unary_operator:-; 218, 219; 219, integer:4; 220, colon; 221, unary_operator:-; 221, 222; 222, integer:2; 223, integer:1; 224, expression_statement; 224, 225; 225, augmented_assignment:+=; 225, 226; 225, 241; 226, subscript; 226, 227; 226, 230; 227, subscript; 227, 228; 227, 229; 228, identifier:counts; 229, integer:1; 230, call; 230, 231; 230, 232; 231, identifier:str; 232, argument_list; 232, 233; 233, subscript; 233, 234; 233, 235; 234, identifier:seq; 235, slice; 235, 236; 235, 238; 235, 239; 236, unary_operator:-; 236, 237; 237, integer:3; 238, colon; 239, unary_operator:-; 239, 240; 240, integer:1; 241, integer:1; 242, expression_statement; 242, 243; 243, augmented_assignment:+=; 243, 244; 243, 257; 244, subscript; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:counts; 247, integer:1; 248, call; 248, 249; 248, 250; 249, identifier:str; 250, argument_list; 250, 251; 251, subscript; 251, 252; 251, 253; 252, identifier:seq; 253, slice; 253, 254; 253, 256; 254, unary_operator:-; 254, 255; 255, integer:2; 256, colon; 257, integer:1; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:tetra_exp; 261, dictionary; 262, for_statement; 262, 263; 262, 264; 262, 276; 263, identifier:tet; 264, list_comprehension; 264, 265; 264, 266; 264, 271; 265, identifier:tetn; 266, for_in_clause; 266, 267; 266, 268; 267, identifier:tetn; 268, subscript; 268, 269; 268, 270; 269, identifier:counts; 270, integer:3; 271, if_clause; 271, 272; 272, call; 272, 273; 272, 274; 273, identifier:tetra_clean; 274, argument_list; 274, 275; 275, identifier:tetn; 276, block; 276, 277; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 282; 279, subscript; 279, 280; 279, 281; 280, identifier:tetra_exp; 281, identifier:tet; 282, binary_operator:/; 282, 283; 282, 304; 282, 305; 283, binary_operator:*; 283, 284; 283, 295; 284, binary_operator:*; 284, 285; 284, 286; 285, float:1.; 286, subscript; 286, 287; 286, 290; 287, subscript; 287, 288; 287, 289; 288, identifier:counts; 289, integer:2; 290, subscript; 290, 291; 290, 292; 291, identifier:tet; 292, slice; 292, 293; 292, 294; 293, colon; 294, integer:3; 295, subscript; 295, 296; 295, 299; 296, subscript; 296, 297; 296, 298; 297, identifier:counts; 298, integer:2; 299, subscript; 299, 300; 299, 301; 300, identifier:tet; 301, slice; 301, 302; 301, 303; 302, integer:1; 303, colon; 304, line_continuation:\; 305, subscript; 305, 306; 305, 309; 306, subscript; 306, 307; 306, 308; 307, identifier:counts; 308, integer:1; 309, subscript; 309, 310; 309, 311; 310, identifier:tet; 311, slice; 311, 312; 311, 313; 311, 314; 312, integer:1; 313, colon; 314, integer:3; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:tetra_sd; 318, dictionary; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 322; 321, identifier:tetra_z; 322, dictionary; 323, for_statement; 323, 324; 323, 327; 323, 335; 324, pattern_list; 324, 325; 324, 326; 325, identifier:tet; 326, identifier:exp; 327, call; 327, 328; 327, 329; 328, identifier:list; 329, argument_list; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:tetra_exp; 333, identifier:items; 334, argument_list; 335, block; 335, 336; 335, 349; 335, 391; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:den; 339, subscript; 339, 340; 339, 343; 340, subscript; 340, 341; 340, 342; 341, identifier:counts; 342, integer:1; 343, subscript; 343, 344; 343, 345; 344, identifier:tet; 345, slice; 345, 346; 345, 347; 345, 348; 346, integer:1; 347, colon; 348, integer:3; 349, expression_statement; 349, 350; 350, assignment; 350, 351; 350, 354; 351, subscript; 351, 352; 351, 353; 352, identifier:tetra_sd; 353, identifier:tet; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:math; 357, identifier:sqrt; 358, argument_list; 358, 359; 359, binary_operator:/; 359, 360; 359, 387; 360, binary_operator:*; 360, 361; 360, 375; 361, binary_operator:*; 361, 362; 361, 363; 362, identifier:exp; 363, parenthesized_expression; 363, 364; 364, binary_operator:-; 364, 365; 364, 366; 365, identifier:den; 366, subscript; 366, 367; 366, 370; 367, subscript; 367, 368; 367, 369; 368, identifier:counts; 369, integer:2; 370, subscript; 370, 371; 370, 372; 371, identifier:tet; 372, slice; 372, 373; 372, 374; 373, colon; 374, integer:3; 375, parenthesized_expression; 375, 376; 376, binary_operator:-; 376, 377; 376, 378; 377, identifier:den; 378, subscript; 378, 379; 378, 382; 379, subscript; 379, 380; 379, 381; 380, identifier:counts; 381, integer:2; 382, subscript; 382, 383; 382, 384; 383, identifier:tet; 384, slice; 384, 385; 384, 386; 385, integer:1; 386, colon; 387, parenthesized_expression; 387, 388; 388, binary_operator:*; 388, 389; 388, 390; 389, identifier:den; 390, identifier:den; 391, try_statement; 391, 392; 391, 410; 392, block; 392, 393; 393, expression_statement; 393, 394; 394, assignment; 394, 395; 394, 398; 395, subscript; 395, 396; 395, 397; 396, identifier:tetra_z; 397, identifier:tet; 398, binary_operator:/; 398, 399; 398, 407; 399, parenthesized_expression; 399, 400; 400, binary_operator:-; 400, 401; 400, 406; 401, subscript; 401, 402; 401, 405; 402, subscript; 402, 403; 402, 404; 403, identifier:counts; 404, integer:3; 405, identifier:tet; 406, identifier:exp; 407, subscript; 407, 408; 407, 409; 408, identifier:tetra_sd; 409, identifier:tet; 410, except_clause; 410, 411; 410, 412; 411, identifier:ZeroDivisionError; 412, block; 412, 413; 413, expression_statement; 413, 414; 414, assignment; 414, 415; 414, 418; 415, subscript; 415, 416; 415, 417; 416, identifier:tetra_z; 417, identifier:tet; 418, binary_operator:/; 418, 419; 418, 420; 419, integer:1; 420, parenthesized_expression; 420, 421; 421, binary_operator:*; 421, 422; 421, 432; 422, subscript; 422, 423; 422, 426; 423, subscript; 423, 424; 423, 425; 424, identifier:counts; 425, integer:1; 426, subscript; 426, 427; 426, 428; 427, identifier:tet; 428, slice; 428, 429; 428, 430; 428, 431; 429, integer:1; 430, colon; 431, integer:3; 432, subscript; 432, 433; 432, 436; 433, subscript; 433, 434; 433, 435; 434, identifier:counts; 435, integer:1; 436, subscript; 436, 437; 436, 438; 437, identifier:tet; 438, slice; 438, 439; 438, 440; 438, 441; 439, integer:1; 440, colon; 441, integer:3; 442, return_statement; 442, 443; 443, identifier:tetra_z | def calculate_tetra_zscore(filename):
counts = (collections.defaultdict(int), collections.defaultdict(int),
collections.defaultdict(int), collections.defaultdict(int))
for rec in SeqIO.parse(filename, 'fasta'):
for seq in [str(rec.seq).upper(),
str(rec.seq.reverse_complement()).upper()]:
for base in ('G', 'C', 'T', 'A'):
counts[0][base] += seq.count(base)
for i in range(len(seq[:-4])):
din, tri, tetra = seq[i:i+2], seq[i:i+3], seq[i:i+4]
counts[1][str(din)] += 1
counts[2][str(tri)] += 1
counts[3][str(tetra)] += 1
counts[2][str(seq[-4:-1])] += 1
counts[2][str(seq[-3:])] += 1
counts[1][str(seq[-4:-2])] += 1
counts[1][str(seq[-3:-1])] += 1
counts[1][str(seq[-2:])] += 1
tetra_exp = {}
for tet in [tetn for tetn in counts[3] if tetra_clean(tetn)]:
tetra_exp[tet] = 1. * counts[2][tet[:3]] * counts[2][tet[1:]] / \
counts[1][tet[1:3]]
tetra_sd = {}
tetra_z = {}
for tet, exp in list(tetra_exp.items()):
den = counts[1][tet[1:3]]
tetra_sd[tet] = math.sqrt(exp * (den - counts[2][tet[:3]]) *
(den - counts[2][tet[1:]]) / (den * den))
try:
tetra_z[tet] = (counts[3][tet] - exp)/tetra_sd[tet]
except ZeroDivisionError:
tetra_z[tet] = 1 / (counts[1][tet[1:3]] * counts[1][tet[1:3]])
return tetra_z |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:calculate_correlations; 3, parameters; 3, 4; 4, identifier:tetra_z; 5, block; 5, 6; 5, 17; 5, 39; 5, 253; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:orgs; 9, call; 9, 10; 9, 11; 10, identifier:sorted; 11, argument_list; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:tetra_z; 15, identifier:keys; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:correlations; 20, call; 20, 21; 20, 37; 21, attribute; 21, 22; 21, 36; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:pd; 25, identifier:DataFrame; 26, argument_list; 26, 27; 26, 30; 26, 33; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:index; 29, identifier:orgs; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:columns; 32, identifier:orgs; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:dtype; 35, identifier:float; 36, identifier:fillna; 37, argument_list; 37, 38; 38, float:1.0; 39, for_statement; 39, 40; 39, 43; 39, 52; 40, pattern_list; 40, 41; 40, 42; 41, identifier:idx; 42, identifier:org1; 43, call; 43, 44; 43, 45; 44, identifier:enumerate; 45, argument_list; 45, 46; 46, subscript; 46, 47; 46, 48; 47, identifier:orgs; 48, slice; 48, 49; 48, 50; 49, colon; 50, unary_operator:-; 50, 51; 51, integer:1; 52, block; 52, 53; 53, for_statement; 53, 54; 53, 55; 53, 62; 54, identifier:org2; 55, subscript; 55, 56; 55, 57; 56, identifier:orgs; 57, slice; 57, 58; 57, 61; 58, binary_operator:+; 58, 59; 58, 60; 59, identifier:idx; 60, integer:1; 61, colon; 62, block; 62, 63; 62, 85; 62, 98; 62, 120; 62, 136; 62, 162; 62, 191; 62, 219; 62, 241; 63, assert_statement; 63, 64; 64, comparison_operator:==; 64, 65; 64, 75; 65, call; 65, 66; 65, 67; 66, identifier:sorted; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:tetra_z; 72, identifier:org1; 73, identifier:keys; 74, argument_list; 75, call; 75, 76; 75, 77; 76, identifier:sorted; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:tetra_z; 82, identifier:org2; 83, identifier:keys; 84, argument_list; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:tets; 88, call; 88, 89; 88, 90; 89, identifier:sorted; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:tetra_z; 95, identifier:org1; 96, identifier:keys; 97, argument_list; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:zscores; 101, list:[[tetra_z[org1][t] for t in tets],
[tetra_z[org2][t] for t in tets]]; 101, 102; 101, 111; 102, list_comprehension; 102, 103; 102, 108; 103, subscript; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:tetra_z; 106, identifier:org1; 107, identifier:t; 108, for_in_clause; 108, 109; 108, 110; 109, identifier:t; 110, identifier:tets; 111, list_comprehension; 111, 112; 111, 117; 112, subscript; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:tetra_z; 115, identifier:org2; 116, identifier:t; 117, for_in_clause; 117, 118; 117, 119; 118, identifier:t; 119, identifier:tets; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:zmeans; 123, list_comprehension; 123, 124; 123, 133; 124, binary_operator:/; 124, 125; 124, 129; 125, call; 125, 126; 125, 127; 126, identifier:sum; 127, argument_list; 127, 128; 128, identifier:zscore; 129, call; 129, 130; 129, 131; 130, identifier:len; 131, argument_list; 131, 132; 132, identifier:zscore; 133, for_in_clause; 133, 134; 133, 135; 134, identifier:zscore; 135, identifier:zscores; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:zdiffs; 139, list:[[z - zmeans[0] for z in zscores[0]],
[z - zmeans[1] for z in zscores[1]]]; 139, 140; 139, 151; 140, list_comprehension; 140, 141; 140, 146; 141, binary_operator:-; 141, 142; 141, 143; 142, identifier:z; 143, subscript; 143, 144; 143, 145; 144, identifier:zmeans; 145, integer:0; 146, for_in_clause; 146, 147; 146, 148; 147, identifier:z; 148, subscript; 148, 149; 148, 150; 149, identifier:zscores; 150, integer:0; 151, list_comprehension; 151, 152; 151, 157; 152, binary_operator:-; 152, 153; 152, 154; 153, identifier:z; 154, subscript; 154, 155; 154, 156; 155, identifier:zmeans; 156, integer:1; 157, for_in_clause; 157, 158; 157, 159; 158, identifier:z; 159, subscript; 159, 160; 159, 161; 160, identifier:zscores; 161, integer:1; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:diffprods; 165, call; 165, 166; 165, 167; 166, identifier:sum; 167, argument_list; 167, 168; 168, list_comprehension; 168, 169; 168, 180; 169, binary_operator:*; 169, 170; 169, 175; 170, subscript; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:zdiffs; 173, integer:0; 174, identifier:i; 175, subscript; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:zdiffs; 178, integer:1; 179, identifier:i; 180, for_in_clause; 180, 181; 180, 182; 181, identifier:i; 182, call; 182, 183; 182, 184; 183, identifier:range; 184, argument_list; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:len; 187, argument_list; 187, 188; 188, subscript; 188, 189; 188, 190; 189, identifier:zdiffs; 190, integer:0; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:zdiffs2; 194, list:[sum([z * z for z in zdiffs[0]]),
sum([z * z for z in zdiffs[1]])]; 194, 195; 194, 207; 195, call; 195, 196; 195, 197; 196, identifier:sum; 197, argument_list; 197, 198; 198, list_comprehension; 198, 199; 198, 202; 199, binary_operator:*; 199, 200; 199, 201; 200, identifier:z; 201, identifier:z; 202, for_in_clause; 202, 203; 202, 204; 203, identifier:z; 204, subscript; 204, 205; 204, 206; 205, identifier:zdiffs; 206, integer:0; 207, call; 207, 208; 207, 209; 208, identifier:sum; 209, argument_list; 209, 210; 210, list_comprehension; 210, 211; 210, 214; 211, binary_operator:*; 211, 212; 211, 213; 212, identifier:z; 213, identifier:z; 214, for_in_clause; 214, 215; 214, 216; 215, identifier:z; 216, subscript; 216, 217; 216, 218; 217, identifier:zdiffs; 218, integer:1; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 226; 221, subscript; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:correlations; 224, identifier:org1; 225, identifier:org2; 226, binary_operator:/; 226, 227; 226, 228; 226, 229; 227, identifier:diffprods; 228, line_continuation:\; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:math; 232, identifier:sqrt; 233, argument_list; 233, 234; 234, binary_operator:*; 234, 235; 234, 238; 235, subscript; 235, 236; 235, 237; 236, identifier:zdiffs2; 237, integer:0; 238, subscript; 238, 239; 238, 240; 239, identifier:zdiffs2; 240, integer:1; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 248; 243, subscript; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:correlations; 246, identifier:org2; 247, identifier:org1; 248, subscript; 248, 249; 248, 252; 249, subscript; 249, 250; 249, 251; 250, identifier:correlations; 251, identifier:org1; 252, identifier:org2; 253, return_statement; 253, 254; 254, identifier:correlations | def calculate_correlations(tetra_z):
orgs = sorted(tetra_z.keys())
correlations = pd.DataFrame(index=orgs, columns=orgs,
dtype=float).fillna(1.0)
for idx, org1 in enumerate(orgs[:-1]):
for org2 in orgs[idx+1:]:
assert sorted(tetra_z[org1].keys()) == sorted(tetra_z[org2].keys())
tets = sorted(tetra_z[org1].keys())
zscores = [[tetra_z[org1][t] for t in tets],
[tetra_z[org2][t] for t in tets]]
zmeans = [sum(zscore)/len(zscore) for zscore in zscores]
zdiffs = [[z - zmeans[0] for z in zscores[0]],
[z - zmeans[1] for z in zscores[1]]]
diffprods = sum([zdiffs[0][i] * zdiffs[1][i] for i in
range(len(zdiffs[0]))])
zdiffs2 = [sum([z * z for z in zdiffs[0]]),
sum([z * z for z in zdiffs[1]])]
correlations[org1][org2] = diffprods / \
math.sqrt(zdiffs2[0] * zdiffs2[1])
correlations[org2][org1] = correlations[org1][org2]
return correlations |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:process_blast; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:blast_dir; 5, identifier:org_lengths; 6, default_parameter; 6, 7; 6, 8; 7, identifier:fraglengths; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:mode; 11, string:"ANIb"; 12, default_parameter; 12, 13; 12, 14; 13, identifier:identity; 14, float:0.3; 15, default_parameter; 15, 16; 15, 17; 16, identifier:coverage; 17, float:0.7; 18, default_parameter; 18, 19; 18, 20; 19, identifier:logger; 20, None; 21, block; 21, 22; 21, 32; 21, 47; 21, 70; 21, 239; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:blastfiles; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:pyani_files; 28, identifier:get_input_files; 29, argument_list; 29, 30; 29, 31; 30, identifier:blast_dir; 31, string:".blast_tab"; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:results; 35, call; 35, 36; 35, 37; 36, identifier:ANIResults; 37, argument_list; 37, 38; 37, 46; 38, call; 38, 39; 38, 40; 39, identifier:list; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:org_lengths; 44, identifier:keys; 45, argument_list; 46, identifier:mode; 47, for_statement; 47, 48; 47, 51; 47, 59; 48, pattern_list; 48, 49; 48, 50; 49, identifier:org; 50, identifier:length; 51, call; 51, 52; 51, 53; 52, identifier:list; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:org_lengths; 57, identifier:items; 58, argument_list; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 69; 62, subscript; 62, 63; 62, 68; 63, subscript; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:results; 66, identifier:alignment_lengths; 67, identifier:org; 68, identifier:org; 69, identifier:length; 70, for_statement; 70, 71; 70, 72; 70, 73; 71, identifier:blastfile; 72, identifier:blastfiles; 73, block; 73, 74; 73, 104; 73, 133; 73, 162; 73, 173; 73, 186; 73, 200; 73, 214; 73, 230; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, pattern_list; 76, 77; 76, 78; 77, identifier:qname; 78, identifier:sname; 79, call; 79, 80; 79, 102; 80, attribute; 80, 81; 80, 101; 81, subscript; 81, 82; 81, 100; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:os; 86, identifier:path; 87, identifier:splitext; 88, argument_list; 88, 89; 89, subscript; 89, 90; 89, 98; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:os; 94, identifier:path; 95, identifier:split; 96, argument_list; 96, 97; 97, identifier:blastfile; 98, unary_operator:-; 98, 99; 99, integer:1; 100, integer:0; 101, identifier:split; 102, argument_list; 102, 103; 103, string:"_vs_"; 104, if_statement; 104, 105; 104, 115; 105, comparison_operator:not; 105, 106; 105, 107; 106, identifier:qname; 107, call; 107, 108; 107, 109; 108, identifier:list; 109, argument_list; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:org_lengths; 113, identifier:keys; 114, argument_list; 115, block; 115, 116; 115, 132; 116, if_statement; 116, 117; 116, 118; 117, identifier:logger; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:logger; 123, identifier:warning; 124, argument_list; 124, 125; 125, binary_operator:+; 125, 126; 125, 129; 126, binary_operator:%; 126, 127; 126, 128; 127, string:"Query name %s not in input "; 128, identifier:qname; 129, binary_operator:%; 129, 130; 129, 131; 130, string:"sequence list, skipping %s"; 131, identifier:blastfile; 132, continue_statement; 133, if_statement; 133, 134; 133, 144; 134, comparison_operator:not; 134, 135; 134, 136; 135, identifier:sname; 136, call; 136, 137; 136, 138; 137, identifier:list; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:org_lengths; 142, identifier:keys; 143, argument_list; 144, block; 144, 145; 144, 161; 145, if_statement; 145, 146; 145, 147; 146, identifier:logger; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:logger; 152, identifier:warning; 153, argument_list; 153, 154; 154, binary_operator:+; 154, 155; 154, 158; 155, binary_operator:%; 155, 156; 155, 157; 156, string:"Subject name %s not in input "; 157, identifier:sname; 158, binary_operator:%; 158, 159; 158, 160; 159, string:"sequence list, skipping %s"; 160, identifier:blastfile; 161, continue_statement; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:resultvals; 165, call; 165, 166; 165, 167; 166, identifier:parse_blast_tab; 167, argument_list; 167, 168; 167, 169; 167, 170; 167, 171; 167, 172; 168, identifier:blastfile; 169, identifier:fraglengths; 170, identifier:identity; 171, identifier:coverage; 172, identifier:mode; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:query_cover; 176, binary_operator:/; 176, 177; 176, 183; 177, call; 177, 178; 177, 179; 178, identifier:float; 179, argument_list; 179, 180; 180, subscript; 180, 181; 180, 182; 181, identifier:resultvals; 182, integer:0; 183, subscript; 183, 184; 183, 185; 184, identifier:org_lengths; 185, identifier:qname; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:results; 190, identifier:add_tot_length; 191, argument_list; 191, 192; 191, 193; 191, 194; 191, 197; 192, identifier:qname; 193, identifier:sname; 194, subscript; 194, 195; 194, 196; 195, identifier:resultvals; 196, integer:0; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:sym; 199, False; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:results; 204, identifier:add_sim_errors; 205, argument_list; 205, 206; 205, 207; 205, 208; 205, 211; 206, identifier:qname; 207, identifier:sname; 208, subscript; 208, 209; 208, 210; 209, identifier:resultvals; 210, integer:1; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:sym; 213, False; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:results; 218, identifier:add_pid; 219, argument_list; 219, 220; 219, 221; 219, 222; 219, 227; 220, identifier:qname; 221, identifier:sname; 222, binary_operator:*; 222, 223; 222, 224; 223, float:0.01; 224, subscript; 224, 225; 224, 226; 225, identifier:resultvals; 226, integer:2; 227, keyword_argument; 227, 228; 227, 229; 228, identifier:sym; 229, False; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:results; 234, identifier:add_coverage; 235, argument_list; 235, 236; 235, 237; 235, 238; 236, identifier:qname; 237, identifier:sname; 238, identifier:query_cover; 239, return_statement; 239, 240; 240, identifier:results | def process_blast(
blast_dir,
org_lengths,
fraglengths=None,
mode="ANIb",
identity=0.3,
coverage=0.7,
logger=None,
):
blastfiles = pyani_files.get_input_files(blast_dir, ".blast_tab")
results = ANIResults(list(org_lengths.keys()), mode)
for org, length in list(org_lengths.items()):
results.alignment_lengths[org][org] = length
for blastfile in blastfiles:
qname, sname = os.path.splitext(os.path.split(blastfile)[-1])[0].split("_vs_")
if qname not in list(org_lengths.keys()):
if logger:
logger.warning(
"Query name %s not in input " % qname
+ "sequence list, skipping %s" % blastfile
)
continue
if sname not in list(org_lengths.keys()):
if logger:
logger.warning(
"Subject name %s not in input " % sname
+ "sequence list, skipping %s" % blastfile
)
continue
resultvals = parse_blast_tab(blastfile, fraglengths, identity, coverage, mode)
query_cover = float(resultvals[0]) / org_lengths[qname]
results.add_tot_length(qname, sname, resultvals[0], sym=False)
results.add_sim_errors(qname, sname, resultvals[1], sym=False)
results.add_pid(qname, sname, 0.01 * resultvals[2], sym=False)
results.add_coverage(qname, sname, query_cover)
return results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:run_dependency_graph; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:jobgraph; 5, default_parameter; 5, 6; 5, 7; 6, identifier:logger; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:jgprefix; 10, string:"ANIm_SGE_JG"; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sgegroupsize; 13, integer:10000; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sgeargs; 16, None; 17, block; 17, 18; 17, 25; 17, 29; 17, 94; 17, 103; 17, 124; 17, 131; 17, 138; 17, 153; 17, 162; 17, 169; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:joblist; 21, call; 21, 22; 21, 23; 22, identifier:build_joblist; 23, argument_list; 23, 24; 24, identifier:jobgraph; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:dep_count; 28, integer:0; 29, if_statement; 29, 30; 29, 31; 30, identifier:logger; 31, block; 31, 32; 31, 39; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:logger; 36, identifier:info; 37, argument_list; 37, 38; 38, string:"Jobs to run with scheduler"; 39, for_statement; 39, 40; 39, 41; 39, 42; 40, identifier:job; 41, identifier:joblist; 42, block; 42, 43; 42, 60; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:logger; 47, identifier:info; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, string:"{0}: {1}"; 52, identifier:format; 53, argument_list; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:job; 56, identifier:name; 57, attribute; 57, 58; 57, 59; 58, identifier:job; 59, identifier:command; 60, if_statement; 60, 61; 60, 67; 61, call; 61, 62; 61, 63; 62, identifier:len; 63, argument_list; 63, 64; 64, attribute; 64, 65; 64, 66; 65, identifier:job; 66, identifier:dependencies; 67, block; 67, 68; 67, 77; 68, expression_statement; 68, 69; 69, augmented_assignment:+=; 69, 70; 69, 71; 70, identifier:dep_count; 71, call; 71, 72; 71, 73; 72, identifier:len; 73, argument_list; 73, 74; 74, attribute; 74, 75; 74, 76; 75, identifier:job; 76, identifier:dependencies; 77, for_statement; 77, 78; 77, 79; 77, 82; 78, identifier:dep; 79, attribute; 79, 80; 79, 81; 80, identifier:job; 81, identifier:dependencies; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:logger; 87, identifier:info; 88, argument_list; 88, 89; 89, binary_operator:%; 89, 90; 89, 91; 90, string:"\t[^ depends on: %s]"; 91, attribute; 91, 92; 91, 93; 92, identifier:dep; 93, identifier:name; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:logger; 98, identifier:info; 99, argument_list; 99, 100; 100, binary_operator:%; 100, 101; 100, 102; 101, string:"There are %d job dependencies"; 102, identifier:dep_count; 103, if_statement; 103, 104; 103, 107; 104, comparison_operator:==; 104, 105; 104, 106; 105, identifier:dep_count; 106, integer:0; 107, block; 107, 108; 107, 115; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:logger; 112, identifier:info; 113, argument_list; 113, 114; 114, string:"Compiling jobs into JobGroups"; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:joblist; 118, call; 118, 119; 118, 120; 119, identifier:compile_jobgroups_from_joblist; 120, argument_list; 120, 121; 120, 122; 120, 123; 121, identifier:joblist; 122, identifier:jgprefix; 123, identifier:sgegroupsize; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:logger; 128, identifier:info; 129, argument_list; 129, 130; 130, string:"Running jobs with scheduler..."; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:logger; 135, identifier:info; 136, argument_list; 136, 137; 137, string:"Jobs passed to scheduler in order:"; 138, for_statement; 138, 139; 138, 140; 138, 141; 139, identifier:job; 140, identifier:joblist; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:logger; 146, identifier:info; 147, argument_list; 147, 148; 148, binary_operator:%; 148, 149; 148, 150; 149, string:"\t%s"; 150, attribute; 150, 151; 150, 152; 151, identifier:job; 152, identifier:name; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:build_and_submit_jobs; 156, argument_list; 156, 157; 156, 160; 156, 161; 157, attribute; 157, 158; 157, 159; 158, identifier:os; 159, identifier:curdir; 160, identifier:joblist; 161, identifier:sgeargs; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:logger; 166, identifier:info; 167, argument_list; 167, 168; 168, string:"Waiting for SGE-submitted jobs to finish (polling)"; 169, for_statement; 169, 170; 169, 171; 169, 172; 170, identifier:job; 171, identifier:joblist; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:job; 177, identifier:wait; 178, argument_list | def run_dependency_graph(jobgraph, logger=None, jgprefix="ANIm_SGE_JG",
sgegroupsize=10000, sgeargs=None):
joblist = build_joblist(jobgraph)
dep_count = 0
if logger:
logger.info("Jobs to run with scheduler")
for job in joblist:
logger.info("{0}: {1}".format(job.name, job.command))
if len(job.dependencies):
dep_count += len(job.dependencies)
for dep in job.dependencies:
logger.info("\t[^ depends on: %s]" % dep.name)
logger.info("There are %d job dependencies" % dep_count)
if dep_count == 0:
logger.info("Compiling jobs into JobGroups")
joblist = compile_jobgroups_from_joblist(joblist, jgprefix,
sgegroupsize)
logger.info("Running jobs with scheduler...")
logger.info("Jobs passed to scheduler in order:")
for job in joblist:
logger.info("\t%s" % job.name)
build_and_submit_jobs(os.curdir, joblist, sgeargs)
logger.info("Waiting for SGE-submitted jobs to finish (polling)")
for job in joblist:
job.wait() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:outputpairedstats; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 3, 16; 3, 17; 3, 18; 3, 19; 3, 20; 4, identifier:fname; 5, identifier:writemode; 6, identifier:name1; 7, identifier:n1; 8, identifier:m1; 9, identifier:se1; 10, identifier:min1; 11, identifier:max1; 12, identifier:name2; 13, identifier:n2; 14, identifier:m2; 15, identifier:se2; 16, identifier:min2; 17, identifier:max2; 18, identifier:statname; 19, identifier:stat; 20, identifier:prob; 21, block; 21, 22; 21, 26; 21, 43; 21, 70; 21, 81; 21, 127; 21, 323; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:suffix; 25, string:''; 26, try_statement; 26, 27; 26, 40; 27, block; 27, 28; 27, 34; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:x; 31, attribute; 31, 32; 31, 33; 32, identifier:prob; 33, identifier:shape; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:prob; 37, subscript; 37, 38; 37, 39; 38, identifier:prob; 39, integer:0; 40, except_clause; 40, 41; 41, block; 41, 42; 42, pass_statement; 43, if_statement; 43, 44; 43, 47; 43, 52; 43, 61; 44, comparison_operator:<; 44, 45; 44, 46; 45, identifier:prob; 46, float:0.001; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:suffix; 51, string:' ***'; 52, elif_clause; 52, 53; 52, 56; 53, comparison_operator:<; 53, 54; 53, 55; 54, identifier:prob; 55, float:0.01; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:suffix; 60, string:' **'; 61, elif_clause; 61, 62; 61, 65; 62, comparison_operator:<; 62, 63; 62, 64; 63, identifier:prob; 64, float:0.05; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:suffix; 69, string:' *'; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:title; 73, list:[['Name','N','Mean','SD','Min','Max']]; 73, 74; 74, list:['Name','N','Mean','SD','Min','Max']; 74, 75; 74, 76; 74, 77; 74, 78; 74, 79; 74, 80; 75, string:'Name'; 76, string:'N'; 77, string:'Mean'; 78, string:'SD'; 79, string:'Min'; 80, string:'Max'; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:lofl; 84, binary_operator:+; 84, 85; 84, 86; 85, identifier:title; 86, list:[[name1,n1,round(m1,3),round(math.sqrt(se1),3),min1,max1],
[name2,n2,round(m2,3),round(math.sqrt(se2),3),min2,max2]]; 86, 87; 86, 107; 87, list:[name1,n1,round(m1,3),round(math.sqrt(se1),3),min1,max1]; 87, 88; 87, 89; 87, 90; 87, 95; 87, 105; 87, 106; 88, identifier:name1; 89, identifier:n1; 90, call; 90, 91; 90, 92; 91, identifier:round; 92, argument_list; 92, 93; 92, 94; 93, identifier:m1; 94, integer:3; 95, call; 95, 96; 95, 97; 96, identifier:round; 97, argument_list; 97, 98; 97, 104; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:math; 101, identifier:sqrt; 102, argument_list; 102, 103; 103, identifier:se1; 104, integer:3; 105, identifier:min1; 106, identifier:max1; 107, list:[name2,n2,round(m2,3),round(math.sqrt(se2),3),min2,max2]; 107, 108; 107, 109; 107, 110; 107, 115; 107, 125; 107, 126; 108, identifier:name2; 109, identifier:n2; 110, call; 110, 111; 110, 112; 111, identifier:round; 112, argument_list; 112, 113; 112, 114; 113, identifier:m2; 114, integer:3; 115, call; 115, 116; 115, 117; 116, identifier:round; 117, argument_list; 117, 118; 117, 124; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:math; 121, identifier:sqrt; 122, argument_list; 122, 123; 123, identifier:se2; 124, integer:3; 125, identifier:min2; 126, identifier:max2; 127, if_statement; 127, 128; 127, 141; 127, 218; 128, boolean_operator:or; 128, 129; 128, 135; 129, comparison_operator:!=; 129, 130; 129, 134; 130, call; 130, 131; 130, 132; 131, identifier:type; 132, argument_list; 132, 133; 133, identifier:fname; 134, identifier:StringType; 135, comparison_operator:==; 135, 136; 135, 140; 136, call; 136, 137; 136, 138; 137, identifier:len; 138, argument_list; 138, 139; 139, identifier:fname; 140, integer:0; 141, block; 141, 142; 141, 146; 141, 151; 141, 155; 141, 162; 141, 166; 141, 197; 141, 214; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:print; 145, argument_list; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:print; 149, argument_list; 149, 150; 150, identifier:statname; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:print; 154, argument_list; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:pstat; 159, identifier:printcc; 160, argument_list; 160, 161; 161, identifier:lofl; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:print; 165, argument_list; 166, try_statement; 166, 167; 166, 194; 167, block; 167, 168; 167, 181; 168, if_statement; 168, 169; 168, 174; 169, comparison_operator:==; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:stat; 172, identifier:shape; 173, tuple; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:stat; 178, subscript; 178, 179; 178, 180; 179, identifier:stat; 180, integer:0; 181, if_statement; 181, 182; 181, 187; 182, comparison_operator:==; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:prob; 185, identifier:shape; 186, tuple; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:prob; 191, subscript; 191, 192; 191, 193; 192, identifier:prob; 193, integer:0; 194, except_clause; 194, 195; 195, block; 195, 196; 196, pass_statement; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:print; 200, argument_list; 200, 201; 200, 202; 200, 207; 200, 208; 200, 213; 201, string:'Test statistic = '; 202, call; 202, 203; 202, 204; 203, identifier:round; 204, argument_list; 204, 205; 204, 206; 205, identifier:stat; 206, integer:3; 207, string:' p = '; 208, call; 208, 209; 208, 210; 209, identifier:round; 210, argument_list; 210, 211; 210, 212; 211, identifier:prob; 212, integer:3; 213, identifier:suffix; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 217; 216, identifier:print; 217, argument_list; 218, else_clause; 218, 219; 219, block; 219, 220; 219, 228; 219, 239; 219, 245; 219, 252; 219, 260; 219, 291; 219, 317; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:file; 223, call; 223, 224; 223, 225; 224, identifier:open; 225, argument_list; 225, 226; 225, 227; 226, identifier:fname; 227, identifier:writemode; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:file; 232, identifier:write; 233, argument_list; 233, 234; 234, binary_operator:+; 234, 235; 234, 238; 235, binary_operator:+; 235, 236; 235, 237; 236, string:'\n'; 237, identifier:statname; 238, string:'\n\n'; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:file; 243, identifier:close; 244, argument_list; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:writecc; 248, argument_list; 248, 249; 248, 250; 248, 251; 249, identifier:lofl; 250, identifier:fname; 251, string:'a'; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:file; 255, call; 255, 256; 255, 257; 256, identifier:open; 257, argument_list; 257, 258; 257, 259; 258, identifier:fname; 259, string:'a'; 260, try_statement; 260, 261; 260, 288; 261, block; 261, 262; 261, 275; 262, if_statement; 262, 263; 262, 268; 263, comparison_operator:==; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:stat; 266, identifier:shape; 267, tuple; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:stat; 272, subscript; 272, 273; 272, 274; 273, identifier:stat; 274, integer:0; 275, if_statement; 275, 276; 275, 281; 276, comparison_operator:==; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:prob; 279, identifier:shape; 280, tuple; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:prob; 285, subscript; 285, 286; 285, 287; 286, identifier:prob; 287, integer:0; 288, except_clause; 288, 289; 289, block; 289, 290; 290, pass_statement; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:file; 295, identifier:write; 296, argument_list; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:pstat; 300, identifier:list2string; 301, argument_list; 301, 302; 302, list:['\nTest statistic = ',round(stat,4),' p = ',round(prob,4),suffix,'\n\n']; 302, 303; 302, 304; 302, 309; 302, 310; 302, 315; 302, 316; 303, string:'\nTest statistic = '; 304, call; 304, 305; 304, 306; 305, identifier:round; 306, argument_list; 306, 307; 306, 308; 307, identifier:stat; 308, integer:4; 309, string:' p = '; 310, call; 310, 311; 310, 312; 311, identifier:round; 312, argument_list; 312, 313; 312, 314; 313, identifier:prob; 314, integer:4; 315, identifier:suffix; 316, string:'\n\n'; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:file; 321, identifier:close; 322, argument_list; 323, return_statement; 323, 324; 324, None | def outputpairedstats(fname,writemode,name1,n1,m1,se1,min1,max1,name2,n2,m2,se2,min2,max2,statname,stat,prob):
suffix = ''
try:
x = prob.shape
prob = prob[0]
except:
pass
if prob < 0.001: suffix = ' ***'
elif prob < 0.01: suffix = ' **'
elif prob < 0.05: suffix = ' *'
title = [['Name','N','Mean','SD','Min','Max']]
lofl = title+[[name1,n1,round(m1,3),round(math.sqrt(se1),3),min1,max1],
[name2,n2,round(m2,3),round(math.sqrt(se2),3),min2,max2]]
if type(fname)!=StringType or len(fname)==0:
print()
print(statname)
print()
pstat.printcc(lofl)
print()
try:
if stat.shape == ():
stat = stat[0]
if prob.shape == ():
prob = prob[0]
except:
pass
print('Test statistic = ',round(stat,3),' p = ',round(prob,3),suffix)
print()
else:
file = open(fname,writemode)
file.write('\n'+statname+'\n\n')
file.close()
writecc(lofl,fname,'a')
file = open(fname,'a')
try:
if stat.shape == ():
stat = stat[0]
if prob.shape == ():
prob = prob[0]
except:
pass
file.write(pstat.list2string(['\nTest statistic = ',round(stat,4),' p = ',round(prob,4),suffix,'\n\n']))
file.close()
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:GeneReader; 3, parameters; 3, 4; 3, 5; 4, identifier:fh; 5, default_parameter; 5, 6; 5, 7; 6, identifier:format; 7, string:'gff'; 8, block; 8, 9; 8, 16; 8, 45; 8, 208; 8, 212; 8, 216; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:known_formats; 12, tuple; 12, 13; 12, 14; 12, 15; 13, string:'gff'; 14, string:'gtf'; 15, string:'bed'; 16, if_statement; 16, 17; 16, 20; 17, comparison_operator:not; 17, 18; 17, 19; 18, identifier:format; 19, identifier:known_formats; 20, block; 20, 21; 20, 40; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:print; 24, argument_list; 24, 25; 24, 35; 25, binary_operator:%; 25, 26; 25, 27; 26, string:'%s format not in %s'; 27, tuple; 27, 28; 27, 29; 28, identifier:format; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, string:","; 32, identifier:join; 33, argument_list; 33, 34; 34, identifier:known_formats; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:file; 37, attribute; 37, 38; 37, 39; 38, identifier:sys; 39, identifier:stderr; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:Exception; 43, argument_list; 43, 44; 44, string:'?'; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:==; 46, 47; 46, 48; 47, identifier:format; 48, string:'bed'; 49, block; 49, 50; 50, for_statement; 50, 51; 50, 52; 50, 53; 51, identifier:line; 52, identifier:fh; 53, block; 53, 54; 53, 66; 53, 72; 53, 81; 53, 87; 53, 93; 53, 102; 53, 111; 53, 120; 53, 143; 53, 168; 53, 172; 53, 201; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:f; 57, call; 57, 58; 57, 65; 58, attribute; 58, 59; 58, 64; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:line; 62, identifier:strip; 63, argument_list; 64, identifier:split; 65, argument_list; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:chrom; 69, subscript; 69, 70; 69, 71; 70, identifier:f; 71, integer:0; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:chrom_start; 75, call; 75, 76; 75, 77; 76, identifier:int; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 80; 79, identifier:f; 80, integer:1; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:name; 84, subscript; 84, 85; 84, 86; 85, identifier:f; 86, integer:4; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:strand; 90, subscript; 90, 91; 90, 92; 91, identifier:f; 92, integer:5; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:cdsStart; 96, call; 96, 97; 96, 98; 97, identifier:int; 98, argument_list; 98, 99; 99, subscript; 99, 100; 99, 101; 100, identifier:f; 101, integer:6; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:cdsEnd; 105, call; 105, 106; 105, 107; 106, identifier:int; 107, argument_list; 107, 108; 108, subscript; 108, 109; 108, 110; 109, identifier:f; 110, integer:7; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:blockCount; 114, call; 114, 115; 114, 116; 115, identifier:int; 116, argument_list; 116, 117; 117, subscript; 117, 118; 117, 119; 118, identifier:f; 119, integer:9; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:blockSizes; 123, list_comprehension; 123, 124; 123, 128; 124, call; 124, 125; 124, 126; 125, identifier:int; 126, argument_list; 126, 127; 127, identifier:i; 128, for_in_clause; 128, 129; 128, 130; 129, identifier:i; 130, call; 130, 131; 130, 141; 131, attribute; 131, 132; 131, 140; 132, call; 132, 133; 132, 138; 133, attribute; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:f; 136, integer:10; 137, identifier:strip; 138, argument_list; 138, 139; 139, string:','; 140, identifier:split; 141, argument_list; 141, 142; 142, string:','; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:blockStarts; 146, list_comprehension; 146, 147; 146, 153; 147, binary_operator:+; 147, 148; 147, 149; 148, identifier:chrom_start; 149, call; 149, 150; 149, 151; 150, identifier:int; 151, argument_list; 151, 152; 152, identifier:i; 153, for_in_clause; 153, 154; 153, 155; 154, identifier:i; 155, call; 155, 156; 155, 166; 156, attribute; 156, 157; 156, 165; 157, call; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, subscript; 159, 160; 159, 161; 160, identifier:f; 161, integer:11; 162, identifier:strip; 163, argument_list; 163, 164; 164, string:','; 165, identifier:split; 166, argument_list; 166, 167; 167, string:','; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:gene_exons; 171, list:[]; 172, for_statement; 172, 173; 172, 176; 172, 181; 173, pattern_list; 173, 174; 173, 175; 174, identifier:base; 175, identifier:offset; 176, call; 176, 177; 176, 178; 177, identifier:zip; 178, argument_list; 178, 179; 178, 180; 179, identifier:blockStarts; 180, identifier:blockSizes; 181, block; 181, 182; 181, 186; 181, 192; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:exon_start; 185, identifier:base; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:exon_end; 189, binary_operator:+; 189, 190; 189, 191; 190, identifier:base; 191, identifier:offset; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:gene_exons; 196, identifier:append; 197, argument_list; 197, 198; 198, tuple; 198, 199; 198, 200; 199, identifier:exon_start; 200, identifier:exon_end; 201, expression_statement; 201, 202; 202, yield; 202, 203; 203, expression_list; 203, 204; 203, 205; 203, 206; 203, 207; 204, identifier:chrom; 205, identifier:strand; 206, identifier:gene_exons; 207, identifier:name; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:genelist; 211, dictionary; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:grouplist; 215, list:[]; 216, if_statement; 216, 217; 216, 224; 217, boolean_operator:or; 217, 218; 217, 221; 218, comparison_operator:==; 218, 219; 218, 220; 219, identifier:format; 220, string:'gff'; 221, comparison_operator:==; 221, 222; 221, 223; 222, identifier:format; 223, string:'gtf'; 224, block; 224, 225; 224, 348; 224, 364; 225, for_statement; 225, 226; 225, 227; 225, 228; 226, identifier:line; 227, identifier:fh; 228, block; 228, 229; 228, 247; 228, 253; 228, 264; 228, 273; 228, 279; 228, 305; 228, 317; 228, 331; 228, 335; 229, if_statement; 229, 230; 229, 238; 229, 245; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:line; 233, identifier:startswith; 234, argument_list; 234, 235; 234, 236; 235, string:'
fields = line.strip().split('; 236, ERROR; 236, 237; 237, escape_sequence:\t; 238, ERROR; 238, 239; 239, comparison_operator:<; 239, 240; 239, 244; 240, call; 240, 241; 240, 242; 241, identifier:len; 242, argument_list; 242, 243; 243, identifier:fields; 244, integer:9; 245, block; 245, 246; 246, continue_statement; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:chrom; 250, subscript; 250, 251; 250, 252; 251, identifier:fields; 252, integer:0; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:ex_st; 256, binary_operator:-; 256, 257; 256, 263; 257, call; 257, 258; 257, 259; 258, identifier:int; 259, argument_list; 259, 260; 260, subscript; 260, 261; 260, 262; 261, identifier:fields; 262, integer:3; 263, integer:1; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:ex_end; 267, call; 267, 268; 267, 269; 268, identifier:int; 269, argument_list; 269, 270; 270, subscript; 270, 271; 270, 272; 271, identifier:fields; 272, integer:4; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:strand; 276, subscript; 276, 277; 276, 278; 277, identifier:fields; 278, integer:6; 279, if_statement; 279, 280; 279, 283; 279, 297; 280, comparison_operator:==; 280, 281; 280, 282; 281, identifier:format; 282, string:'gtf'; 283, block; 283, 284; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:group; 287, subscript; 287, 288; 287, 296; 288, call; 288, 289; 288, 294; 289, attribute; 289, 290; 289, 293; 290, subscript; 290, 291; 290, 292; 291, identifier:fields; 292, integer:8; 293, identifier:split; 294, argument_list; 294, 295; 295, string:';'; 296, integer:0; 297, else_clause; 297, 298; 298, block; 298, 299; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:group; 302, subscript; 302, 303; 302, 304; 303, identifier:fields; 304, integer:8; 305, if_statement; 305, 306; 305, 309; 306, comparison_operator:not; 306, 307; 306, 308; 307, identifier:group; 308, identifier:grouplist; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:grouplist; 314, identifier:append; 315, argument_list; 315, 316; 316, identifier:group; 317, if_statement; 317, 318; 317, 321; 318, comparison_operator:not; 318, 319; 318, 320; 319, identifier:group; 320, identifier:genelist; 321, block; 321, 322; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 327; 324, subscript; 324, 325; 324, 326; 325, identifier:genelist; 326, identifier:group; 327, tuple; 327, 328; 327, 329; 327, 330; 328, identifier:chrom; 329, identifier:strand; 330, list:[]; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 334; 333, identifier:exons_i; 334, integer:2; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 344; 337, attribute; 337, 338; 337, 343; 338, subscript; 338, 339; 338, 342; 339, subscript; 339, 340; 339, 341; 340, identifier:genelist; 341, identifier:group; 342, identifier:exons_i; 343, identifier:append; 344, argument_list; 344, 345; 345, tuple; 345, 346; 345, 347; 346, identifier:ex_st; 347, identifier:ex_end; 348, expression_statement; 348, 349; 349, assignment; 349, 350; 349, 351; 350, identifier:sp; 351, lambda; 351, 352; 351, 355; 352, lambda_parameters; 352, 353; 352, 354; 353, identifier:a; 354, identifier:b; 355, call; 355, 356; 355, 357; 356, identifier:cmp; 357, argument_list; 357, 358; 357, 361; 358, subscript; 358, 359; 358, 360; 359, identifier:a; 360, integer:0; 361, subscript; 361, 362; 361, 363; 362, identifier:b; 363, integer:0; 364, for_statement; 364, 365; 364, 366; 364, 367; 365, identifier:gene; 366, identifier:grouplist; 367, block; 367, 368; 367, 377; 367, 384; 368, expression_statement; 368, 369; 369, assignment; 369, 370; 369, 374; 370, pattern_list; 370, 371; 370, 372; 370, 373; 371, identifier:chrom; 372, identifier:strand; 373, identifier:gene_exons; 374, subscript; 374, 375; 374, 376; 375, identifier:genelist; 376, identifier:gene; 377, expression_statement; 377, 378; 378, assignment; 378, 379; 378, 380; 379, identifier:gene_exons; 380, call; 380, 381; 380, 382; 381, identifier:bitset_union; 382, argument_list; 382, 383; 383, identifier:gene_exons; 384, expression_statement; 384, 385; 385, yield; 385, 386; 386, expression_list; 386, 387; 386, 388; 386, 389; 386, 390; 387, identifier:chrom; 388, identifier:strand; 389, identifier:gene_exons; 390, identifier:gene | def GeneReader( fh, format='gff' ):
known_formats = ( 'gff', 'gtf', 'bed')
if format not in known_formats:
print('%s format not in %s' % (format, ",".join( known_formats )), file=sys.stderr)
raise Exception('?')
if format == 'bed':
for line in fh:
f = line.strip().split()
chrom = f[0]
chrom_start = int(f[1])
name = f[4]
strand = f[5]
cdsStart = int(f[6])
cdsEnd = int(f[7])
blockCount = int(f[9])
blockSizes = [ int(i) for i in f[10].strip(',').split(',') ]
blockStarts = [ chrom_start + int(i) for i in f[11].strip(',').split(',') ]
gene_exons = []
for base,offset in zip( blockStarts, blockSizes ):
exon_start = base
exon_end = base+offset
gene_exons.append( (exon_start, exon_end) )
yield chrom, strand, gene_exons, name
genelist = {}
grouplist = []
if format == 'gff' or format == 'gtf':
for line in fh:
if line.startswith('
fields = line.strip().split('\t')
if len( fields ) < 9: continue
chrom = fields[0]
ex_st = int( fields[3] ) - 1
ex_end = int( fields[4] )
strand = fields[6]
if format == 'gtf':
group = fields[8].split(';')[0]
else:
group = fields[8]
if group not in grouplist: grouplist.append( group )
if group not in genelist:
genelist[group] = (chrom, strand, [])
exons_i = 2
genelist[group][exons_i].append( ( ex_st, ex_end ) )
sp = lambda a,b: cmp( a[0], b[0] )
for gene in grouplist:
chrom, strand, gene_exons = genelist[ gene ]
gene_exons = bitset_union( gene_exons )
yield chrom, strand, gene_exons, gene |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:read_next_maf; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:file; 5, default_parameter; 5, 6; 5, 7; 6, identifier:species_to_lengths; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:parse_e_rows; 10, False; 11, block; 11, 12; 11, 21; 11, 31; 11, 37; 11, 45; 11, 57; 11, 70; 11, 101; 11, 105; 11, 417; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:alignment; 15, call; 15, 16; 15, 17; 16, identifier:Alignment; 17, argument_list; 17, 18; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:species_to_lengths; 20, identifier:species_to_lengths; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:line; 24, call; 24, 25; 24, 26; 25, identifier:readline; 26, argument_list; 26, 27; 26, 28; 27, identifier:file; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:skip_blank; 30, True; 31, if_statement; 31, 32; 31, 34; 32, not_operator; 32, 33; 33, identifier:line; 34, block; 34, 35; 35, return_statement; 35, 36; 36, None; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:fields; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:line; 43, identifier:split; 44, argument_list; 45, if_statement; 45, 46; 45, 51; 46, comparison_operator:!=; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:fields; 49, integer:0; 50, string:'a'; 51, block; 51, 52; 52, raise_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:Exception; 55, argument_list; 55, 56; 56, string:"Expected 'a ...' line"; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:alignment; 61, identifier:attributes; 62, call; 62, 63; 62, 64; 63, identifier:parse_attributes; 64, argument_list; 64, 65; 65, subscript; 65, 66; 65, 67; 66, identifier:fields; 67, slice; 67, 68; 67, 69; 68, integer:1; 69, colon; 70, if_statement; 70, 71; 70, 76; 70, 93; 71, comparison_operator:in; 71, 72; 71, 73; 72, string:'score'; 73, attribute; 73, 74; 73, 75; 74, identifier:alignment; 75, identifier:attributes; 76, block; 76, 77; 76, 87; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:alignment; 81, identifier:score; 82, subscript; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:alignment; 85, identifier:attributes; 86, string:'score'; 87, delete_statement; 87, 88; 88, subscript; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:alignment; 91, identifier:attributes; 92, string:'score'; 93, else_clause; 93, 94; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:alignment; 99, identifier:score; 100, integer:0; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:last_component; 104, None; 105, while_statement; 105, 106; 105, 107; 106, integer:1; 107, block; 107, 108; 107, 115; 107, 126; 107, 134; 107, 142; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:line; 111, call; 111, 112; 111, 113; 112, identifier:readline; 113, argument_list; 113, 114; 114, identifier:file; 115, if_statement; 115, 116; 115, 124; 116, boolean_operator:or; 116, 117; 116, 119; 117, not_operator; 117, 118; 118, identifier:line; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:line; 122, identifier:isspace; 123, argument_list; 124, block; 124, 125; 125, break_statement; 126, if_statement; 126, 127; 126, 132; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:line; 130, identifier:isspace; 131, argument_list; 132, block; 132, 133; 133, break_statement; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:fields; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:line; 140, identifier:split; 141, argument_list; 142, if_statement; 142, 143; 142, 148; 142, 235; 142, 347; 142, 393; 143, comparison_operator:==; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:fields; 146, integer:0; 147, string:'s'; 148, block; 148, 149; 148, 155; 148, 163; 148, 174; 148, 185; 148, 193; 148, 204; 148, 224; 148, 231; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:component; 152, call; 152, 153; 152, 154; 153, identifier:Component; 154, argument_list; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:component; 159, identifier:src; 160, subscript; 160, 161; 160, 162; 161, identifier:fields; 162, integer:1; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:component; 167, identifier:start; 168, call; 168, 169; 168, 170; 169, identifier:int; 170, argument_list; 170, 171; 171, subscript; 171, 172; 171, 173; 172, identifier:fields; 173, integer:2; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:component; 178, identifier:size; 179, call; 179, 180; 179, 181; 180, identifier:int; 181, argument_list; 181, 182; 182, subscript; 182, 183; 182, 184; 183, identifier:fields; 184, integer:3; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:component; 189, identifier:strand; 190, subscript; 190, 191; 190, 192; 191, identifier:fields; 192, integer:4; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:component; 197, identifier:src_size; 198, call; 198, 199; 198, 200; 199, identifier:int; 200, argument_list; 200, 201; 201, subscript; 201, 202; 201, 203; 202, identifier:fields; 203, integer:5; 204, if_statement; 204, 205; 204, 211; 205, comparison_operator:>; 205, 206; 205, 210; 206, call; 206, 207; 206, 208; 207, identifier:len; 208, argument_list; 208, 209; 209, identifier:fields; 210, integer:6; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:component; 216, identifier:text; 217, call; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, subscript; 219, 220; 219, 221; 220, identifier:fields; 221, integer:6; 222, identifier:strip; 223, argument_list; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:alignment; 228, identifier:add_component; 229, argument_list; 229, 230; 230, identifier:component; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:last_component; 234, identifier:component; 235, elif_clause; 235, 236; 235, 241; 236, comparison_operator:==; 236, 237; 236, 240; 237, subscript; 237, 238; 237, 239; 238, identifier:fields; 239, integer:0; 240, string:'e'; 241, block; 241, 242; 242, if_statement; 242, 243; 242, 244; 243, identifier:parse_e_rows; 244, block; 244, 245; 244, 251; 244, 257; 244, 265; 244, 276; 244, 287; 244, 295; 244, 306; 244, 312; 244, 322; 244, 330; 244, 336; 244, 343; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:component; 248, call; 248, 249; 248, 250; 249, identifier:Component; 250, argument_list; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:component; 255, identifier:empty; 256, True; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:component; 261, identifier:src; 262, subscript; 262, 263; 262, 264; 263, identifier:fields; 264, integer:1; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:component; 269, identifier:start; 270, call; 270, 271; 270, 272; 271, identifier:int; 272, argument_list; 272, 273; 273, subscript; 273, 274; 273, 275; 274, identifier:fields; 275, integer:2; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:component; 280, identifier:size; 281, call; 281, 282; 281, 283; 282, identifier:int; 283, argument_list; 283, 284; 284, subscript; 284, 285; 284, 286; 285, identifier:fields; 286, integer:3; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:component; 291, identifier:strand; 292, subscript; 292, 293; 292, 294; 293, identifier:fields; 294, integer:4; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:component; 299, identifier:src_size; 300, call; 300, 301; 300, 302; 301, identifier:int; 302, argument_list; 302, 303; 303, subscript; 303, 304; 303, 305; 304, identifier:fields; 305, integer:5; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:component; 310, identifier:text; 311, None; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:synteny; 315, call; 315, 316; 315, 321; 316, attribute; 316, 317; 316, 320; 317, subscript; 317, 318; 317, 319; 318, identifier:fields; 319, integer:6; 320, identifier:strip; 321, argument_list; 322, assert_statement; 322, 323; 322, 329; 323, comparison_operator:==; 323, 324; 323, 328; 324, call; 324, 325; 324, 326; 325, identifier:len; 326, argument_list; 326, 327; 327, identifier:synteny; 328, integer:1; 329, string:"Synteny status in 'e' rows should be denoted with a single character code"; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:component; 334, identifier:synteny_empty; 335, identifier:synteny; 336, expression_statement; 336, 337; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:alignment; 340, identifier:add_component; 341, argument_list; 341, 342; 342, identifier:component; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 346; 345, identifier:last_component; 346, identifier:component; 347, elif_clause; 347, 348; 347, 353; 348, comparison_operator:==; 348, 349; 348, 352; 349, subscript; 349, 350; 349, 351; 350, identifier:fields; 351, integer:0; 352, string:'i'; 353, block; 353, 354; 353, 363; 353, 378; 354, assert_statement; 354, 355; 354, 362; 355, comparison_operator:==; 355, 356; 355, 359; 356, subscript; 356, 357; 356, 358; 357, identifier:fields; 358, integer:1; 359, attribute; 359, 360; 359, 361; 360, identifier:last_component; 361, identifier:src; 362, string:"'i' row does not follow matching 's' row"; 363, expression_statement; 363, 364; 364, assignment; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:last_component; 367, identifier:synteny_left; 368, tuple; 368, 369; 368, 372; 369, subscript; 369, 370; 369, 371; 370, identifier:fields; 371, integer:2; 372, call; 372, 373; 372, 374; 373, identifier:int; 374, argument_list; 374, 375; 375, subscript; 375, 376; 375, 377; 376, identifier:fields; 377, integer:3; 378, expression_statement; 378, 379; 379, assignment; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:last_component; 382, identifier:synteny_right; 383, tuple; 383, 384; 383, 387; 384, subscript; 384, 385; 384, 386; 385, identifier:fields; 386, integer:4; 387, call; 387, 388; 387, 389; 388, identifier:int; 389, argument_list; 389, 390; 390, subscript; 390, 391; 390, 392; 391, identifier:fields; 392, integer:5; 393, elif_clause; 393, 394; 393, 399; 394, comparison_operator:==; 394, 395; 394, 398; 395, subscript; 395, 396; 395, 397; 396, identifier:fields; 397, integer:0; 398, string:'q'; 399, block; 399, 400; 399, 409; 400, assert_statement; 400, 401; 400, 408; 401, comparison_operator:==; 401, 402; 401, 405; 402, subscript; 402, 403; 402, 404; 403, identifier:fields; 404, integer:1; 405, attribute; 405, 406; 405, 407; 406, identifier:last_component; 407, identifier:src; 408, string:"'q' row does not follow matching 's' row"; 409, expression_statement; 409, 410; 410, assignment; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:last_component; 413, identifier:quality; 414, subscript; 414, 415; 414, 416; 415, identifier:fields; 416, integer:2; 417, return_statement; 417, 418; 418, identifier:alignment | def read_next_maf( file, species_to_lengths=None, parse_e_rows=False ):
alignment = Alignment(species_to_lengths=species_to_lengths)
line = readline( file, skip_blank=True )
if not line: return None
fields = line.split()
if fields[0] != 'a': raise Exception("Expected 'a ...' line")
alignment.attributes = parse_attributes( fields[1:] )
if 'score' in alignment.attributes:
alignment.score = alignment.attributes['score']
del alignment.attributes['score']
else:
alignment.score = 0
last_component = None
while 1:
line = readline( file )
if not line or line.isspace(): break
if line.isspace(): break
fields = line.split()
if fields[0] == 's':
component = Component()
component.src = fields[1]
component.start = int( fields[2] )
component.size = int( fields[3] )
component.strand = fields[4]
component.src_size = int( fields[5] )
if len(fields) > 6: component.text = fields[6].strip()
alignment.add_component( component )
last_component = component
elif fields[0] == 'e':
if parse_e_rows:
component = Component()
component.empty = True
component.src = fields[1]
component.start = int( fields[2] )
component.size = int( fields[3] )
component.strand = fields[4]
component.src_size = int( fields[5] )
component.text = None
synteny = fields[6].strip()
assert len( synteny ) == 1, \
"Synteny status in 'e' rows should be denoted with a single character code"
component.synteny_empty = synteny
alignment.add_component( component )
last_component = component
elif fields[0] == 'i':
assert fields[1] == last_component.src, "'i' row does not follow matching 's' row"
last_component.synteny_left = ( fields[2], int( fields[3] ) )
last_component.synteny_right = ( fields[4], int( fields[5] ) )
elif fields[0] == 'q':
assert fields[1] == last_component.src, "'q' row does not follow matching 's' row"
last_component.quality = fields[2]
return alignment |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parse_record; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:lines; 6, block; 6, 7; 6, 11; 6, 52; 6, 56; 6, 62; 6, 66; 6, 429; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:temp_lines; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:line; 13, identifier:lines; 14, block; 14, 15; 14, 30; 14, 45; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:fields; 18, call; 18, 19; 18, 27; 19, attribute; 19, 20; 19, 26; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:line; 23, identifier:rstrip; 24, argument_list; 24, 25; 25, string:"\r\n"; 26, identifier:split; 27, argument_list; 27, 28; 27, 29; 28, None; 29, integer:1; 30, if_statement; 30, 31; 30, 37; 31, comparison_operator:==; 31, 32; 31, 36; 32, call; 32, 33; 32, 34; 33, identifier:len; 34, argument_list; 34, 35; 35, identifier:fields; 36, integer:1; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:fields; 42, identifier:append; 43, argument_list; 43, 44; 44, string:""; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:temp_lines; 49, identifier:append; 50, argument_list; 50, 51; 51, identifier:fields; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:lines; 55, identifier:temp_lines; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:motif; 59, call; 59, 60; 59, 61; 60, identifier:TransfacMotif; 61, argument_list; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:current_line; 65, integer:0; 66, while_statement; 66, 67; 66, 68; 67, integer:1; 68, block; 68, 69; 68, 78; 68, 86; 68, 98; 68, 106; 68, 130; 68, 173; 68, 231; 68, 292; 69, if_statement; 69, 70; 69, 76; 70, comparison_operator:>=; 70, 71; 70, 72; 71, identifier:current_line; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, identifier:lines; 76, block; 76, 77; 77, break_statement; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 83; 80, pattern_list; 80, 81; 80, 82; 81, identifier:prefix; 82, identifier:rest; 83, subscript; 83, 84; 83, 85; 84, identifier:lines; 85, identifier:current_line; 86, if_statement; 86, 87; 86, 92; 87, comparison_operator:not; 87, 88; 87, 89; 88, identifier:prefix; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:parse_actions; 92, block; 92, 93; 92, 97; 93, expression_statement; 93, 94; 94, augmented_assignment:+=; 94, 95; 94, 96; 95, identifier:current_line; 96, integer:1; 97, continue_statement; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:action; 101, subscript; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:parse_actions; 105, identifier:prefix; 106, if_statement; 106, 107; 106, 112; 107, comparison_operator:==; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:action; 110, integer:0; 111, string:"store_single"; 112, block; 112, 113; 112, 119; 112, 126; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:key; 116, subscript; 116, 117; 116, 118; 117, identifier:action; 118, integer:1; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:setattr; 122, argument_list; 122, 123; 122, 124; 122, 125; 123, identifier:motif; 124, identifier:key; 125, identifier:rest; 126, expression_statement; 126, 127; 127, augmented_assignment:+=; 127, 128; 127, 129; 128, identifier:current_line; 129, integer:1; 130, if_statement; 130, 131; 130, 136; 131, comparison_operator:==; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:action; 134, integer:0; 135, string:"store_single_list"; 136, block; 136, 137; 136, 143; 136, 158; 136, 169; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:key; 140, subscript; 140, 141; 140, 142; 141, identifier:action; 142, integer:1; 143, if_statement; 143, 144; 143, 150; 144, not_operator; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:getattr; 147, argument_list; 147, 148; 147, 149; 148, identifier:motif; 149, identifier:key; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:setattr; 154, argument_list; 154, 155; 154, 156; 154, 157; 155, identifier:motif; 156, identifier:key; 157, list:[]; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 167; 160, attribute; 160, 161; 160, 166; 161, call; 161, 162; 161, 163; 162, identifier:getattr; 163, argument_list; 163, 164; 163, 165; 164, identifier:motif; 165, identifier:key; 166, identifier:append; 167, argument_list; 167, 168; 168, identifier:rest; 169, expression_statement; 169, 170; 170, augmented_assignment:+=; 170, 171; 170, 172; 171, identifier:current_line; 172, integer:1; 173, if_statement; 173, 174; 173, 179; 174, comparison_operator:==; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:action; 177, integer:0; 178, string:"store_single_key_value"; 179, block; 179, 180; 179, 186; 179, 202; 179, 217; 179, 227; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:key; 183, subscript; 183, 184; 183, 185; 184, identifier:action; 185, integer:1; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 191; 188, pattern_list; 188, 189; 188, 190; 189, identifier:k; 190, identifier:v; 191, call; 191, 192; 191, 199; 192, attribute; 192, 193; 192, 198; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:rest; 196, identifier:strip; 197, argument_list; 198, identifier:split; 199, argument_list; 199, 200; 199, 201; 200, string:'='; 201, integer:1; 202, if_statement; 202, 203; 202, 209; 203, not_operator; 203, 204; 204, call; 204, 205; 204, 206; 205, identifier:getattr; 206, argument_list; 206, 207; 206, 208; 207, identifier:motif; 208, identifier:key; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 213; 212, identifier:setattr; 213, argument_list; 213, 214; 213, 215; 213, 216; 214, identifier:motif; 215, identifier:key; 216, dictionary; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 226; 219, subscript; 219, 220; 219, 225; 220, call; 220, 221; 220, 222; 221, identifier:getattr; 222, argument_list; 222, 223; 222, 224; 223, identifier:motif; 224, identifier:key; 225, identifier:k; 226, identifier:v; 227, expression_statement; 227, 228; 228, augmented_assignment:+=; 228, 229; 228, 230; 229, identifier:current_line; 230, integer:1; 231, if_statement; 231, 232; 231, 237; 232, comparison_operator:==; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:action; 235, integer:0; 236, string:"store_block"; 237, block; 237, 238; 237, 244; 237, 248; 237, 279; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:key; 241, subscript; 241, 242; 241, 243; 242, identifier:action; 243, integer:1; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:value; 247, list:[]; 248, while_statement; 248, 249; 248, 263; 249, boolean_operator:and; 249, 250; 249, 256; 250, comparison_operator:<; 250, 251; 250, 252; 251, identifier:current_line; 252, call; 252, 253; 252, 254; 253, identifier:len; 254, argument_list; 254, 255; 255, identifier:lines; 256, comparison_operator:==; 256, 257; 256, 262; 257, subscript; 257, 258; 257, 261; 258, subscript; 258, 259; 258, 260; 259, identifier:lines; 260, identifier:current_line; 261, integer:0; 262, identifier:prefix; 263, block; 263, 264; 263, 275; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:value; 268, identifier:append; 269, argument_list; 269, 270; 270, subscript; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:lines; 273, identifier:current_line; 274, integer:1; 275, expression_statement; 275, 276; 276, augmented_assignment:+=; 276, 277; 276, 278; 277, identifier:current_line; 278, integer:1; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 282; 281, identifier:setattr; 282, argument_list; 282, 283; 282, 284; 282, 285; 283, identifier:motif; 284, identifier:key; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:str; 288, identifier:join; 289, argument_list; 289, 290; 289, 291; 290, string:"\n"; 291, identifier:value; 292, if_statement; 292, 293; 292, 298; 293, comparison_operator:==; 293, 294; 293, 297; 294, subscript; 294, 295; 294, 296; 295, identifier:action; 296, integer:0; 297, string:"store_matrix"; 298, block; 298, 299; 298, 307; 298, 314; 298, 318; 298, 322; 298, 326; 298, 395; 298, 410; 298, 420; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:alphabet; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:rest; 305, identifier:split; 306, argument_list; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:alphabet_size; 310, call; 310, 311; 310, 312; 311, identifier:len; 312, argument_list; 312, 313; 313, identifier:alphabet; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:rows; 317, list:[]; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:pattern; 321, string:""; 322, expression_statement; 322, 323; 323, augmented_assignment:+=; 323, 324; 323, 325; 324, identifier:current_line; 325, integer:1; 326, while_statement; 326, 327; 326, 333; 327, comparison_operator:<; 327, 328; 327, 329; 328, identifier:current_line; 329, call; 329, 330; 329, 331; 330, identifier:len; 331, argument_list; 331, 332; 332, identifier:lines; 333, block; 333, 334; 333, 342; 333, 351; 333, 359; 333, 377; 333, 391; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 339; 336, pattern_list; 336, 337; 336, 338; 337, identifier:prefix; 338, identifier:rest; 339, subscript; 339, 340; 339, 341; 340, identifier:lines; 341, identifier:current_line; 342, if_statement; 342, 343; 342, 349; 343, not_operator; 343, 344; 344, call; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:prefix; 347, identifier:isdigit; 348, argument_list; 349, block; 349, 350; 350, break_statement; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 354; 353, identifier:values; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:rest; 357, identifier:split; 358, argument_list; 359, expression_statement; 359, 360; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:rows; 363, identifier:append; 364, argument_list; 364, 365; 365, list_comprehension; 365, 366; 365, 370; 366, call; 366, 367; 366, 368; 367, identifier:float; 368, argument_list; 368, 369; 369, identifier:_; 370, for_in_clause; 370, 371; 370, 372; 371, identifier:_; 372, subscript; 372, 373; 372, 374; 373, identifier:values; 374, slice; 374, 375; 374, 376; 375, colon; 376, identifier:alphabet_size; 377, if_statement; 377, 378; 377, 384; 378, comparison_operator:>; 378, 379; 378, 383; 379, call; 379, 380; 379, 381; 380, identifier:len; 381, argument_list; 381, 382; 382, identifier:values; 383, identifier:alphabet_size; 384, block; 384, 385; 385, expression_statement; 385, 386; 386, augmented_assignment:+=; 386, 387; 386, 388; 387, identifier:pattern; 388, subscript; 388, 389; 388, 390; 389, identifier:values; 390, identifier:alphabet_size; 391, expression_statement; 391, 392; 392, augmented_assignment:+=; 392, 393; 392, 394; 393, identifier:current_line; 394, integer:1; 395, if_statement; 395, 396; 395, 405; 396, comparison_operator:!=; 396, 397; 396, 401; 397, call; 397, 398; 397, 399; 398, identifier:len; 399, argument_list; 399, 400; 400, identifier:pattern; 401, call; 401, 402; 401, 403; 402, identifier:len; 403, argument_list; 403, 404; 404, identifier:rows; 405, block; 405, 406; 406, expression_statement; 406, 407; 407, assignment; 407, 408; 407, 409; 408, identifier:pattern; 409, None; 410, expression_statement; 410, 411; 411, assignment; 411, 412; 411, 413; 412, identifier:matrix; 413, call; 413, 414; 413, 417; 414, attribute; 414, 415; 414, 416; 415, identifier:FrequencyMatrix; 416, identifier:from_rows; 417, argument_list; 417, 418; 417, 419; 418, identifier:alphabet; 419, identifier:rows; 420, expression_statement; 420, 421; 421, call; 421, 422; 421, 423; 422, identifier:setattr; 423, argument_list; 423, 424; 423, 425; 423, 428; 424, identifier:motif; 425, subscript; 425, 426; 425, 427; 426, identifier:action; 427, integer:1; 428, identifier:matrix; 429, if_statement; 429, 430; 429, 441; 430, boolean_operator:or; 430, 431; 430, 438; 431, boolean_operator:or; 431, 432; 431, 435; 432, attribute; 432, 433; 432, 434; 433, identifier:motif; 434, identifier:id; 435, attribute; 435, 436; 435, 437; 436, identifier:motif; 437, identifier:accession; 438, attribute; 438, 439; 438, 440; 439, identifier:motif; 440, identifier:name; 441, block; 441, 442; 442, return_statement; 442, 443; 443, identifier:motif | def parse_record( self, lines ):
temp_lines = []
for line in lines:
fields = line.rstrip( "\r\n" ).split( None, 1 )
if len( fields ) == 1:
fields.append( "" )
temp_lines.append( fields )
lines = temp_lines
motif = TransfacMotif()
current_line = 0
while 1:
if current_line >= len( lines ):
break
prefix, rest = lines[ current_line ]
if prefix not in self.parse_actions:
current_line += 1
continue
action = self.parse_actions[ prefix ]
if action[0] == "store_single":
key = action[1]
setattr( motif, key, rest )
current_line += 1
if action[0] == "store_single_list":
key = action[1]
if not getattr( motif, key ):
setattr( motif, key, [] )
getattr( motif, key ).append( rest )
current_line += 1
if action[0] == "store_single_key_value":
key = action[1]
k, v = rest.strip().split( '=', 1 )
if not getattr( motif, key ):
setattr( motif, key, {} )
getattr( motif, key )[k] = v
current_line += 1
if action[0] == "store_block":
key = action[1]
value = []
while current_line < len( lines ) and lines[ current_line ][0] == prefix:
value.append( lines[current_line][1] )
current_line += 1
setattr( motif, key, str.join( "\n", value ) )
if action[0] == "store_matrix":
alphabet = rest.split()
alphabet_size = len( alphabet )
rows = []
pattern = ""
current_line += 1
while current_line < len( lines ):
prefix, rest = lines[ current_line ]
if not prefix.isdigit():
break
values = rest.split()
rows.append( [ float(_) for _ in values[:alphabet_size] ] )
if len( values ) > alphabet_size:
pattern += values[alphabet_size]
current_line += 1
if len( pattern ) != len( rows ):
pattern = None
matrix = FrequencyMatrix.from_rows( alphabet, rows )
setattr( motif, action[1], matrix )
if motif.id or motif.accession or motif.name:
return motif |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:tile_interval; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:sources; 5, identifier:index; 6, identifier:ref_src; 7, identifier:start; 8, identifier:end; 9, default_parameter; 9, 10; 9, 11; 10, identifier:seq_db; 11, None; 12, block; 12, 13; 12, 54; 12, 60; 12, 71; 12, 85; 12, 93; 12, 97; 12, 163; 12, 167; 12, 184; 12, 373; 13, assert_statement; 13, 14; 13, 33; 14, comparison_operator:==; 14, 15; 14, 25; 15, subscript; 15, 16; 15, 24; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, subscript; 18, 19; 18, 20; 19, identifier:sources; 20, integer:0; 21, identifier:split; 22, argument_list; 22, 23; 23, string:'.'; 24, integer:0; 25, subscript; 25, 26; 25, 32; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:ref_src; 29, identifier:split; 30, argument_list; 30, 31; 31, string:'.'; 32, integer:0; 33, binary_operator:%; 33, 34; 33, 35; 34, string:"%s != %s"; 35, tuple; 35, 36; 35, 46; 36, subscript; 36, 37; 36, 45; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:sources; 41, integer:0; 42, identifier:split; 43, argument_list; 43, 44; 44, string:'.'; 45, integer:0; 46, subscript; 46, 47; 46, 53; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:ref_src; 50, identifier:split; 51, argument_list; 51, 52; 52, string:'.'; 53, integer:0; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:base_len; 57, binary_operator:-; 57, 58; 57, 59; 58, identifier:end; 59, identifier:start; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:blocks; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:index; 66, identifier:get; 67, argument_list; 67, 68; 67, 69; 67, 70; 68, identifier:ref_src; 69, identifier:start; 70, identifier:end; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:blocks; 75, identifier:sort; 76, argument_list; 76, 77; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:key; 79, lambda; 79, 80; 79, 82; 80, lambda_parameters; 80, 81; 81, identifier:t; 82, attribute; 82, 83; 82, 84; 83, identifier:t; 84, identifier:score; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:mask; 88, binary_operator:*; 88, 89; 88, 92; 89, list:[ -1 ]; 89, 90; 90, unary_operator:-; 90, 91; 91, integer:1; 92, identifier:base_len; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:ref_src_size; 96, None; 97, for_statement; 97, 98; 97, 101; 97, 105; 98, pattern_list; 98, 99; 98, 100; 99, identifier:i; 100, identifier:block; 101, call; 101, 102; 101, 103; 102, identifier:enumerate; 103, argument_list; 103, 104; 104, identifier:blocks; 105, block; 105, 106; 105, 115; 105, 121; 105, 127; 105, 137; 105, 147; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:ref; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:block; 112, identifier:get_component_by_src_start; 113, argument_list; 113, 114; 114, identifier:ref_src; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:ref_src_size; 118, attribute; 118, 119; 118, 120; 119, identifier:ref; 120, identifier:src_size; 121, assert_statement; 121, 122; 122, comparison_operator:==; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:ref; 125, identifier:strand; 126, string:"+"; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:slice_start; 130, call; 130, 131; 130, 132; 131, identifier:max; 132, argument_list; 132, 133; 132, 134; 133, identifier:start; 134, attribute; 134, 135; 134, 136; 135, identifier:ref; 136, identifier:start; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:slice_end; 140, call; 140, 141; 140, 142; 141, identifier:min; 142, argument_list; 142, 143; 142, 144; 143, identifier:end; 144, attribute; 144, 145; 144, 146; 145, identifier:ref; 146, identifier:end; 147, for_statement; 147, 148; 147, 149; 147, 154; 148, identifier:j; 149, call; 149, 150; 149, 151; 150, identifier:range; 151, argument_list; 151, 152; 151, 153; 152, identifier:slice_start; 153, identifier:slice_end; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 162; 157, subscript; 157, 158; 157, 159; 158, identifier:mask; 159, binary_operator:-; 159, 160; 159, 161; 160, identifier:j; 161, identifier:start; 162, identifier:i; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:tiled; 166, list:[]; 167, for_statement; 167, 168; 167, 169; 167, 176; 168, identifier:i; 169, call; 169, 170; 169, 171; 170, identifier:range; 171, argument_list; 171, 172; 172, call; 172, 173; 172, 174; 173, identifier:len; 174, argument_list; 174, 175; 175, identifier:sources; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:tiled; 181, identifier:append; 182, argument_list; 182, 183; 183, list:[]; 184, for_statement; 184, 185; 184, 189; 184, 193; 185, pattern_list; 185, 186; 185, 187; 185, 188; 186, identifier:ss; 187, identifier:ee; 188, identifier:index; 189, call; 189, 190; 189, 191; 190, identifier:intervals_from_mask; 191, argument_list; 191, 192; 192, identifier:mask; 193, block; 193, 194; 194, if_statement; 194, 195; 194, 198; 194, 271; 195, comparison_operator:<; 195, 196; 195, 197; 196, identifier:index; 197, integer:0; 198, block; 198, 199; 198, 251; 199, if_statement; 199, 200; 199, 201; 199, 235; 200, identifier:seq_db; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, subscript; 205, 206; 205, 207; 206, identifier:tiled; 207, integer:0; 208, identifier:append; 209, argument_list; 209, 210; 210, call; 210, 211; 210, 228; 211, attribute; 211, 212; 211, 227; 212, call; 212, 213; 212, 220; 213, attribute; 213, 214; 213, 219; 214, attribute; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:bx; 217, identifier:seq; 218, identifier:nib; 219, identifier:NibFile; 220, argument_list; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:open; 223, argument_list; 223, 224; 224, subscript; 224, 225; 224, 226; 225, identifier:seq_db; 226, identifier:ref_src; 227, identifier:get; 228, argument_list; 228, 229; 228, 232; 229, binary_operator:+; 229, 230; 229, 231; 230, identifier:start; 231, identifier:ss; 232, binary_operator:-; 232, 233; 232, 234; 233, identifier:ee; 234, identifier:ss; 235, else_clause; 235, 236; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 244; 239, attribute; 239, 240; 239, 243; 240, subscript; 240, 241; 240, 242; 241, identifier:tiled; 242, integer:0; 243, identifier:append; 244, argument_list; 244, 245; 245, binary_operator:*; 245, 246; 245, 247; 246, string:"N"; 247, parenthesized_expression; 247, 248; 248, binary_operator:-; 248, 249; 248, 250; 249, identifier:ee; 250, identifier:ss; 251, for_statement; 251, 252; 251, 253; 251, 258; 252, identifier:row; 253, subscript; 253, 254; 253, 255; 254, identifier:tiled; 255, slice; 255, 256; 255, 257; 256, integer:1; 257, colon; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:row; 263, identifier:append; 264, argument_list; 264, 265; 265, binary_operator:*; 265, 266; 265, 267; 266, string:"-"; 267, parenthesized_expression; 267, 268; 268, binary_operator:-; 268, 269; 268, 270; 269, identifier:ee; 270, identifier:ss; 271, else_clause; 271, 272; 272, block; 272, 273; 272, 279; 272, 285; 272, 291; 272, 300; 272, 311; 272, 320; 272, 326; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:slice_start; 276, binary_operator:+; 276, 277; 276, 278; 277, identifier:start; 278, identifier:ss; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:slice_end; 282, binary_operator:+; 282, 283; 282, 284; 283, identifier:start; 284, identifier:ee; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:block; 288, subscript; 288, 289; 288, 290; 289, identifier:blocks; 290, identifier:index; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:ref; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:block; 297, identifier:get_component_by_src_start; 298, argument_list; 298, 299; 299, identifier:ref_src; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:sliced; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:block; 306, identifier:slice_by_component; 307, argument_list; 307, 308; 307, 309; 307, 310; 308, identifier:ref; 309, identifier:slice_start; 310, identifier:slice_end; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:sliced; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:sliced; 317, identifier:limit_to_species; 318, argument_list; 318, 319; 319, identifier:sources; 320, expression_statement; 320, 321; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:sliced; 324, identifier:remove_all_gap_columns; 325, argument_list; 326, for_statement; 326, 327; 326, 330; 326, 334; 327, pattern_list; 327, 328; 327, 329; 328, identifier:i; 329, identifier:src; 330, call; 330, 331; 330, 332; 331, identifier:enumerate; 332, argument_list; 332, 333; 333, identifier:sources; 334, block; 334, 335; 334, 344; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:comp; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:sliced; 341, identifier:get_component_by_src_start; 342, argument_list; 342, 343; 343, identifier:src; 344, if_statement; 344, 345; 344, 346; 344, 358; 345, identifier:comp; 346, block; 346, 347; 347, expression_statement; 347, 348; 348, call; 348, 349; 348, 354; 349, attribute; 349, 350; 349, 353; 350, subscript; 350, 351; 350, 352; 351, identifier:tiled; 352, identifier:i; 353, identifier:append; 354, argument_list; 354, 355; 355, attribute; 355, 356; 355, 357; 356, identifier:comp; 357, identifier:text; 358, else_clause; 358, 359; 359, block; 359, 360; 360, expression_statement; 360, 361; 361, call; 361, 362; 361, 367; 362, attribute; 362, 363; 362, 366; 363, subscript; 363, 364; 363, 365; 364, identifier:tiled; 365, identifier:i; 366, identifier:append; 367, argument_list; 367, 368; 368, binary_operator:*; 368, 369; 368, 370; 369, string:"-"; 370, attribute; 370, 371; 370, 372; 371, identifier:sliced; 372, identifier:text_size; 373, return_statement; 373, 374; 374, list_comprehension; 374, 375; 374, 381; 375, call; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, string:""; 378, identifier:join; 379, argument_list; 379, 380; 380, identifier:t; 381, for_in_clause; 381, 382; 381, 383; 382, identifier:t; 383, identifier:tiled | def tile_interval( sources, index, ref_src, start, end, seq_db=None ):
assert sources[0].split('.')[0] == ref_src.split('.')[0], \
"%s != %s" % ( sources[0].split('.')[0], ref_src.split('.')[0] )
base_len = end - start
blocks = index.get( ref_src, start, end )
blocks.sort(key=lambda t: t.score)
mask = [ -1 ] * base_len
ref_src_size = None
for i, block in enumerate( blocks ):
ref = block.get_component_by_src_start( ref_src )
ref_src_size = ref.src_size
assert ref.strand == "+"
slice_start = max( start, ref.start )
slice_end = min( end, ref.end )
for j in range( slice_start, slice_end ):
mask[j-start] = i
tiled = []
for i in range( len( sources ) ):
tiled.append( [] )
for ss, ee, index in intervals_from_mask( mask ):
if index < 0:
if seq_db:
tiled[0].append( bx.seq.nib.NibFile( open( seq_db[ ref_src ] ) ).get( start+ss, ee-ss ) )
else:
tiled[0].append( "N" * (ee-ss) )
for row in tiled[1:]:
row.append( "-" * ( ee - ss ) )
else:
slice_start = start + ss
slice_end = start + ee
block = blocks[index]
ref = block.get_component_by_src_start( ref_src )
sliced = block.slice_by_component( ref, slice_start, slice_end )
sliced = sliced.limit_to_species( sources )
sliced.remove_all_gap_columns()
for i, src in enumerate( sources ):
comp = sliced.get_component_by_src_start( src )
if comp:
tiled[i].append( comp.text )
else:
tiled[i].append( "-" * sliced.text_size )
return [ "".join( t ) for t in tiled ] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:binned_bitsets_proximity; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:f; 5, default_parameter; 5, 6; 5, 7; 6, identifier:chrom_col; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:start_col; 10, integer:1; 11, default_parameter; 11, 12; 11, 13; 12, identifier:end_col; 13, integer:2; 14, default_parameter; 14, 15; 14, 16; 15, identifier:strand_col; 16, integer:5; 17, default_parameter; 17, 18; 17, 19; 18, identifier:upstream; 19, integer:0; 20, default_parameter; 20, 21; 20, 22; 21, identifier:downstream; 22, integer:0; 23, block; 23, 24; 23, 28; 23, 32; 23, 38; 23, 209; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:last_chrom; 27, None; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:last_bitset; 31, None; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:bitsets; 35, call; 35, 36; 35, 37; 36, identifier:dict; 37, argument_list; 38, for_statement; 38, 39; 38, 40; 38, 41; 39, identifier:line; 40, identifier:f; 41, block; 41, 42; 41, 77; 41, 83; 41, 112; 41, 130; 41, 161; 41, 192; 42, if_statement; 42, 43; 42, 46; 42, 65; 43, attribute; 43, 44; 43, 45; 44, identifier:line; 45, identifier:startswith; 46, ERROR; 46, 47; 46, 48; 46, 49; 46, 56; 46, 57; 47, ERROR; 48, identifier:fields; 49, ERROR; 49, 50; 49, 55; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:line; 53, identifier:split; 54, argument_list; 55, identifier:strand; 56, string:"+"; 57, comparison_operator:>=; 57, 58; 57, 62; 58, call; 58, 59; 58, 60; 59, identifier:len; 60, argument_list; 60, 61; 61, identifier:fields; 62, binary_operator:+; 62, 63; 62, 64; 63, identifier:strand_col; 64, integer:1; 65, block; 65, 66; 66, if_statement; 66, 67; 66, 72; 67, comparison_operator:==; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:fields; 70, identifier:strand_col; 71, string:"-"; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:strand; 76, string:"-"; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:chrom; 80, subscript; 80, 81; 80, 82; 81, identifier:fields; 82, identifier:chrom_col; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:!=; 84, 85; 84, 86; 85, identifier:chrom; 86, identifier:last_chrom; 87, block; 87, 88; 87, 102; 87, 106; 88, if_statement; 88, 89; 88, 92; 89, comparison_operator:not; 89, 90; 89, 91; 90, identifier:chrom; 91, identifier:bitsets; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:bitsets; 97, identifier:chrom; 98, call; 98, 99; 98, 100; 99, identifier:BinnedBitSet; 100, argument_list; 100, 101; 101, identifier:MAX; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:last_chrom; 105, identifier:chrom; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:last_bitset; 109, subscript; 109, 110; 109, 111; 110, identifier:bitsets; 111, identifier:chrom; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, pattern_list; 114, 115; 114, 116; 115, identifier:start; 116, identifier:end; 117, expression_list; 117, 118; 117, 124; 118, call; 118, 119; 118, 120; 119, identifier:int; 120, argument_list; 120, 121; 121, subscript; 121, 122; 121, 123; 122, identifier:fields; 123, identifier:start_col; 124, call; 124, 125; 124, 126; 125, identifier:int; 126, argument_list; 126, 127; 127, subscript; 127, 128; 127, 129; 128, identifier:fields; 129, identifier:end_col; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:==; 131, 132; 131, 133; 132, identifier:strand; 133, string:"+"; 134, block; 134, 135; 134, 148; 135, if_statement; 135, 136; 135, 137; 136, identifier:upstream; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:start; 141, call; 141, 142; 141, 143; 142, identifier:max; 143, argument_list; 143, 144; 143, 145; 144, integer:0; 145, binary_operator:-; 145, 146; 145, 147; 146, identifier:start; 147, identifier:upstream; 148, if_statement; 148, 149; 148, 150; 149, identifier:downstream; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:end; 154, call; 154, 155; 154, 156; 155, identifier:min; 156, argument_list; 156, 157; 156, 158; 157, identifier:MAX; 158, binary_operator:+; 158, 159; 158, 160; 159, identifier:end; 160, identifier:downstream; 161, if_statement; 161, 162; 161, 165; 162, comparison_operator:==; 162, 163; 162, 164; 163, identifier:strand; 164, string:"-"; 165, block; 165, 166; 165, 179; 166, if_statement; 166, 167; 166, 168; 167, identifier:upstream; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:end; 172, call; 172, 173; 172, 174; 173, identifier:min; 174, argument_list; 174, 175; 174, 176; 175, identifier:MAX; 176, binary_operator:+; 176, 177; 176, 178; 177, identifier:end; 178, identifier:upstream; 179, if_statement; 179, 180; 179, 181; 180, identifier:downstream; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:start; 185, call; 185, 186; 185, 187; 186, identifier:max; 187, argument_list; 187, 188; 187, 189; 188, integer:0; 189, binary_operator:-; 189, 190; 189, 191; 190, identifier:start; 191, identifier:downstream; 192, if_statement; 192, 193; 192, 198; 193, comparison_operator:>; 193, 194; 193, 197; 194, binary_operator:-; 194, 195; 194, 196; 195, identifier:end; 196, identifier:start; 197, integer:0; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:last_bitset; 203, identifier:set_range; 204, argument_list; 204, 205; 204, 206; 205, identifier:start; 206, binary_operator:-; 206, 207; 206, 208; 207, identifier:end; 208, identifier:start; 209, return_statement; 209, 210; 210, identifier:bitsets | def binned_bitsets_proximity( f, chrom_col=0, start_col=1, end_col=2, strand_col=5, upstream=0, downstream=0 ):
last_chrom = None
last_bitset = None
bitsets = dict()
for line in f:
if line.startswith("
fields = line.split()
strand = "+"
if len(fields) >= strand_col + 1:
if fields[strand_col] == "-": strand = "-"
chrom = fields[chrom_col]
if chrom != last_chrom:
if chrom not in bitsets:
bitsets[chrom] = BinnedBitSet( MAX )
last_chrom = chrom
last_bitset = bitsets[chrom]
start, end = int( fields[start_col] ), int( fields[end_col] )
if strand == "+":
if upstream: start = max( 0, start - upstream )
if downstream: end = min( MAX, end + downstream )
if strand == "-":
if upstream: end = min( MAX, end + upstream )
if downstream: start = max( 0, start - downstream )
if end-start > 0:
last_bitset.set_range( start, end-start )
return bitsets |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:to_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:Class; 5, identifier:dict; 6, identifier:file; 7, default_parameter; 7, 8; 7, 9; 8, identifier:is_little_endian; 9, True; 10, block; 10, 11; 10, 21; 10, 29; 10, 41; 10, 52; 10, 124; 10, 132; 10, 227; 10, 235; 10, 242; 10, 246; 10, 281; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:io; 14, call; 14, 15; 14, 16; 15, identifier:BinaryFileWriter; 16, argument_list; 16, 17; 16, 18; 17, identifier:file; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:is_little_endian; 20, identifier:is_little_endian; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:start_offset; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:io; 27, identifier:tell; 28, argument_list; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:io; 33, identifier:seek; 34, argument_list; 34, 35; 35, binary_operator:+; 35, 36; 35, 37; 36, identifier:start_offset; 37, parenthesized_expression; 37, 38; 38, binary_operator:*; 38, 39; 38, 40; 39, integer:8; 40, integer:256; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:subtables; 44, list_comprehension; 44, 45; 44, 46; 45, list:[]; 46, for_in_clause; 46, 47; 46, 48; 47, identifier:i; 48, call; 48, 49; 48, 50; 49, identifier:range; 50, argument_list; 50, 51; 51, integer:256; 52, for_statement; 52, 53; 52, 56; 52, 61; 53, pattern_list; 53, 54; 53, 55; 54, identifier:key; 55, identifier:value; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:dict; 59, identifier:items; 60, argument_list; 61, block; 61, 62; 61, 70; 61, 80; 61, 90; 61, 97; 61, 104; 61, 111; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:pair_offset; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:io; 68, identifier:tell; 69, argument_list; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:io; 74, identifier:write_uint32; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, identifier:key; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:io; 84, identifier:write_uint32; 85, argument_list; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:len; 88, argument_list; 88, 89; 89, identifier:value; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:io; 94, identifier:write; 95, argument_list; 95, 96; 96, identifier:key; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:io; 101, identifier:write; 102, argument_list; 102, 103; 103, identifier:value; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:hash; 107, call; 107, 108; 107, 109; 108, identifier:cdbhash; 109, argument_list; 109, 110; 110, identifier:key; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 120; 113, attribute; 113, 114; 113, 119; 114, subscript; 114, 115; 114, 116; 115, identifier:subtables; 116, binary_operator:%; 116, 117; 116, 118; 117, identifier:hash; 118, integer:256; 119, identifier:append; 120, argument_list; 120, 121; 121, tuple; 121, 122; 121, 123; 122, identifier:hash; 123, identifier:pair_offset; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:subtable_offset; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:io; 130, identifier:tell; 131, argument_list; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:subtable; 134, identifier:subtables; 135, block; 135, 136; 136, if_statement; 136, 137; 136, 143; 137, comparison_operator:>; 137, 138; 137, 142; 138, call; 138, 139; 138, 140; 139, identifier:len; 140, argument_list; 140, 141; 141, identifier:subtable; 142, integer:0; 143, block; 143, 144; 143, 153; 143, 166; 143, 207; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:ncells; 147, binary_operator:*; 147, 148; 147, 152; 148, call; 148, 149; 148, 150; 149, identifier:len; 150, argument_list; 150, 151; 151, identifier:subtable; 152, integer:2; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:cells; 156, list_comprehension; 156, 157; 156, 160; 157, tuple; 157, 158; 157, 159; 158, integer:0; 159, integer:0; 160, for_in_clause; 160, 161; 160, 162; 161, identifier:i; 162, call; 162, 163; 162, 164; 163, identifier:range; 164, argument_list; 164, 165; 165, identifier:ncells; 166, for_statement; 166, 167; 166, 170; 166, 171; 167, pattern_list; 167, 168; 167, 169; 168, identifier:hash; 169, identifier:pair_offset; 170, identifier:subtable; 171, block; 171, 172; 171, 181; 171, 199; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:index; 175, binary_operator:%; 175, 176; 175, 180; 176, parenthesized_expression; 176, 177; 177, binary_operator:>>; 177, 178; 177, 179; 178, identifier:hash; 179, integer:8; 180, identifier:ncells; 181, while_statement; 181, 182; 181, 189; 182, comparison_operator:!=; 182, 183; 182, 188; 183, subscript; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:cells; 186, identifier:index; 187, integer:1; 188, integer:0; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:index; 193, binary_operator:%; 193, 194; 193, 198; 194, parenthesized_expression; 194, 195; 195, binary_operator:+; 195, 196; 195, 197; 196, identifier:index; 197, integer:1; 198, identifier:ncells; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:cells; 203, identifier:index; 204, tuple; 204, 205; 204, 206; 205, identifier:hash; 206, identifier:pair_offset; 207, for_statement; 207, 208; 207, 211; 207, 212; 208, pattern_list; 208, 209; 208, 210; 209, identifier:hash; 210, identifier:pair_offset; 211, identifier:cells; 212, block; 212, 213; 212, 220; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:io; 217, identifier:write_uint32; 218, argument_list; 218, 219; 219, identifier:hash; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:io; 224, identifier:write_uint32; 225, argument_list; 225, 226; 226, identifier:pair_offset; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:end_offset; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:io; 233, identifier:tell; 234, argument_list; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:io; 239, identifier:seek; 240, argument_list; 240, 241; 241, identifier:start_offset; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:index; 245, identifier:subtable_offset; 246, for_statement; 246, 247; 246, 248; 246, 249; 247, identifier:subtable; 248, identifier:subtables; 249, block; 249, 250; 249, 257; 249, 269; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:io; 254, identifier:write_uint32; 255, argument_list; 255, 256; 256, identifier:index; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:io; 261, identifier:write_uint32; 262, argument_list; 262, 263; 263, call; 263, 264; 263, 265; 264, identifier:len; 265, argument_list; 265, 266; 266, binary_operator:*; 266, 267; 266, 268; 267, identifier:subtable; 268, integer:2; 269, expression_statement; 269, 270; 270, augmented_assignment:+=; 270, 271; 270, 272; 271, identifier:index; 272, binary_operator:*; 272, 273; 272, 280; 273, parenthesized_expression; 273, 274; 274, binary_operator:*; 274, 275; 274, 279; 275, call; 275, 276; 275, 277; 276, identifier:len; 277, argument_list; 277, 278; 278, identifier:subtable; 279, integer:2; 280, integer:8; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:io; 285, identifier:seek; 286, argument_list; 286, 287; 287, identifier:end_offset | def to_file( Class, dict, file, is_little_endian=True ):
io = BinaryFileWriter( file, is_little_endian=is_little_endian )
start_offset = io.tell()
io.seek( start_offset + ( 8 * 256 ) )
subtables = [ [] for i in range(256) ]
for key, value in dict.items():
pair_offset = io.tell()
io.write_uint32( len( key ) )
io.write_uint32( len( value ) )
io.write( key )
io.write( value )
hash = cdbhash( key )
subtables[ hash % 256 ].append( ( hash, pair_offset ) )
subtable_offset = io.tell()
for subtable in subtables:
if len( subtable ) > 0:
ncells = len( subtable ) * 2
cells = [ (0,0) for i in range( ncells ) ]
for hash, pair_offset in subtable:
index = ( hash >> 8 ) % ncells
while cells[index][1] != 0:
index = ( index + 1 ) % ncells
cells[index] = ( hash, pair_offset )
for hash, pair_offset in cells:
io.write_uint32( hash )
io.write_uint32( pair_offset )
end_offset = io.tell()
io.seek( start_offset )
index = subtable_offset
for subtable in subtables:
io.write_uint32( index )
io.write_uint32( len( subtable * 2 ) )
index += ( len( subtable ) * 2 ) * 8
io.seek( end_offset ) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:transform; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:elem; 5, identifier:chain_CT_CQ; 6, identifier:max_gap; 7, block; 7, 8; 7, 15; 7, 47; 7, 78; 7, 84; 7, 90; 7, 109; 7, 129; 7, 136; 7, 208; 7, 215; 7, 222; 7, 240; 7, 258; 7, 316; 7, 351; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 14; 10, tuple_pattern; 10, 11; 10, 12; 10, 13; 11, identifier:chain; 12, identifier:CT; 13, identifier:CQ; 14, identifier:chain_CT_CQ; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, pattern_list; 17, 18; 17, 19; 18, identifier:start; 19, identifier:end; 20, expression_list; 20, 21; 20, 34; 21, binary_operator:-; 21, 22; 21, 31; 22, call; 22, 23; 22, 24; 23, identifier:max; 24, argument_list; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:elem; 27, string:'start'; 28, attribute; 28, 29; 28, 30; 29, identifier:chain; 30, identifier:tStart; 31, attribute; 31, 32; 31, 33; 32, identifier:chain; 33, identifier:tStart; 34, binary_operator:-; 34, 35; 34, 44; 35, call; 35, 36; 35, 37; 36, identifier:min; 37, argument_list; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:elem; 40, string:'end'; 41, attribute; 41, 42; 41, 43; 42, identifier:chain; 43, identifier:tEnd; 44, attribute; 44, 45; 44, 46; 45, identifier:chain; 46, identifier:tStart; 47, assert_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:np; 51, identifier:all; 52, argument_list; 52, 53; 53, comparison_operator:==; 53, 54; 53, 66; 54, parenthesized_expression; 54, 55; 55, binary_operator:-; 55, 56; 55, 61; 56, subscript; 56, 57; 56, 58; 56, 60; 57, identifier:CT; 58, slice; 58, 59; 59, colon; 60, integer:1; 61, subscript; 61, 62; 61, 63; 61, 65; 62, identifier:CT; 63, slice; 63, 64; 64, colon; 65, integer:0; 66, parenthesized_expression; 66, 67; 67, binary_operator:-; 67, 68; 67, 73; 68, subscript; 68, 69; 68, 70; 68, 72; 69, identifier:CQ; 70, slice; 70, 71; 71, colon; 72, integer:1; 73, subscript; 73, 74; 73, 75; 73, 77; 74, identifier:CQ; 75, slice; 75, 76; 76, colon; 77, integer:0; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:to_chrom; 81, attribute; 81, 82; 81, 83; 82, identifier:chain; 83, identifier:qName; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:to_gab_start; 87, attribute; 87, 88; 87, 89; 88, identifier:chain; 89, identifier:qStart; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:start_idx; 93, subscript; 93, 94; 93, 108; 94, subscript; 94, 95; 94, 107; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:np; 98, identifier:where; 99, argument_list; 99, 100; 100, comparison_operator:>; 100, 101; 100, 106; 101, subscript; 101, 102; 101, 103; 101, 105; 102, identifier:CT; 103, slice; 103, 104; 104, colon; 105, integer:1; 106, identifier:start; 107, integer:0; 108, integer:0; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:end_idx; 112, subscript; 112, 113; 112, 127; 113, subscript; 113, 114; 113, 126; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:np; 117, identifier:where; 118, argument_list; 118, 119; 119, comparison_operator:<; 119, 120; 119, 125; 120, subscript; 120, 121; 120, 122; 120, 124; 121, identifier:CT; 122, slice; 122, 123; 123, colon; 124, integer:0; 125, identifier:end; 126, integer:0; 127, unary_operator:-; 127, 128; 128, integer:1; 129, if_statement; 129, 130; 129, 133; 130, comparison_operator:>; 130, 131; 130, 132; 131, identifier:start_idx; 132, identifier:end_idx; 133, block; 133, 134; 134, return_statement; 134, 135; 135, list:[]; 136, if_statement; 136, 137; 136, 146; 137, boolean_operator:and; 137, 138; 137, 141; 138, comparison_operator:>=; 138, 139; 138, 140; 139, identifier:max_gap; 140, integer:0; 141, comparison_operator:<; 141, 142; 141, 143; 142, identifier:start_idx; 143, binary_operator:-; 143, 144; 143, 145; 144, identifier:end_idx; 145, integer:1; 146, block; 146, 147; 147, if_statement; 147, 148; 147, 205; 148, boolean_operator:or; 148, 149; 148, 177; 149, comparison_operator:>; 149, 150; 149, 176; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:np; 153, identifier:max; 154, argument_list; 154, 155; 155, binary_operator:-; 155, 156; 155, 166; 156, subscript; 156, 157; 156, 158; 156, 165; 157, identifier:CT; 158, slice; 158, 159; 158, 163; 158, 164; 159, parenthesized_expression; 159, 160; 160, binary_operator:+; 160, 161; 160, 162; 161, identifier:start_idx; 162, integer:1; 163, colon; 164, identifier:end_idx; 165, integer:0; 166, subscript; 166, 167; 166, 168; 166, 175; 167, identifier:CT; 168, slice; 168, 169; 168, 170; 168, 171; 169, identifier:start_idx; 170, colon; 171, parenthesized_expression; 171, 172; 172, binary_operator:-; 172, 173; 172, 174; 173, identifier:end_idx; 174, integer:1; 175, integer:1; 176, identifier:max_gap; 177, comparison_operator:>; 177, 178; 177, 204; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:np; 181, identifier:max; 182, argument_list; 182, 183; 183, binary_operator:-; 183, 184; 183, 194; 184, subscript; 184, 185; 184, 186; 184, 193; 185, identifier:CQ; 186, slice; 186, 187; 186, 191; 186, 192; 187, parenthesized_expression; 187, 188; 188, binary_operator:+; 188, 189; 188, 190; 189, identifier:start_idx; 190, integer:1; 191, colon; 192, identifier:end_idx; 193, integer:0; 194, subscript; 194, 195; 194, 196; 194, 203; 195, identifier:CQ; 196, slice; 196, 197; 196, 198; 196, 199; 197, identifier:start_idx; 198, colon; 199, parenthesized_expression; 199, 200; 200, binary_operator:-; 200, 201; 200, 202; 201, identifier:end_idx; 202, integer:1; 203, integer:1; 204, identifier:max_gap; 205, block; 205, 206; 206, return_statement; 206, 207; 207, list:[]; 208, assert_statement; 208, 209; 209, comparison_operator:<; 209, 210; 209, 211; 210, identifier:start; 211, subscript; 211, 212; 211, 213; 211, 214; 212, identifier:CT; 213, identifier:start_idx; 214, integer:1; 215, assert_statement; 215, 216; 216, comparison_operator:<; 216, 217; 216, 221; 217, subscript; 217, 218; 217, 219; 217, 220; 218, identifier:CT; 219, identifier:end_idx; 220, integer:0; 221, identifier:end; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:to_start; 225, binary_operator:+; 225, 226; 225, 230; 226, subscript; 226, 227; 226, 228; 226, 229; 227, identifier:CQ; 228, identifier:start_idx; 229, integer:0; 230, call; 230, 231; 230, 232; 231, identifier:max; 232, argument_list; 232, 233; 232, 234; 233, integer:0; 234, binary_operator:-; 234, 235; 234, 236; 235, identifier:start; 236, subscript; 236, 237; 236, 238; 236, 239; 237, identifier:CT; 238, identifier:start_idx; 239, integer:0; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:to_end; 243, binary_operator:-; 243, 244; 243, 248; 244, subscript; 244, 245; 244, 246; 244, 247; 245, identifier:CQ; 246, identifier:end_idx; 247, integer:1; 248, call; 248, 249; 248, 250; 249, identifier:max; 250, argument_list; 250, 251; 250, 252; 251, integer:0; 252, binary_operator:-; 252, 253; 252, 257; 253, subscript; 253, 254; 253, 255; 253, 256; 254, identifier:CT; 255, identifier:end_idx; 256, integer:1; 257, identifier:end; 258, if_statement; 258, 259; 258, 262; 258, 270; 259, comparison_operator:==; 259, 260; 259, 261; 260, identifier:start_idx; 261, identifier:end_idx; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:slices; 266, list:[(to_start, to_end)]; 266, 267; 267, tuple; 267, 268; 267, 269; 268, identifier:to_start; 269, identifier:to_end; 270, else_clause; 270, 271; 271, block; 271, 272; 271, 282; 271, 304; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:slices; 275, list:[(to_start, CQ[start_idx,1])]; 275, 276; 276, tuple; 276, 277; 276, 278; 277, identifier:to_start; 278, subscript; 278, 279; 278, 280; 278, 281; 279, identifier:CQ; 280, identifier:start_idx; 281, integer:1; 282, expression_statement; 282, 283; 283, augmented_assignment:+=; 283, 284; 283, 285; 284, identifier:slices; 285, list_comprehension; 285, 286; 285, 295; 286, tuple; 286, 287; 286, 291; 287, subscript; 287, 288; 287, 289; 287, 290; 288, identifier:CQ; 289, identifier:i; 290, integer:0; 291, subscript; 291, 292; 291, 293; 291, 294; 292, identifier:CQ; 293, identifier:i; 294, integer:1; 295, for_in_clause; 295, 296; 295, 297; 296, identifier:i; 297, call; 297, 298; 297, 299; 298, identifier:range; 299, argument_list; 299, 300; 299, 303; 300, binary_operator:+; 300, 301; 300, 302; 301, identifier:start_idx; 302, integer:1; 303, identifier:end_idx; 304, expression_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:slices; 308, identifier:append; 309, argument_list; 309, 310; 310, tuple; 310, 311; 310, 315; 311, subscript; 311, 312; 311, 313; 311, 314; 312, identifier:CQ; 313, identifier:end_idx; 314, integer:0; 315, identifier:to_end; 316, if_statement; 316, 317; 316, 322; 317, comparison_operator:==; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:chain; 320, identifier:qStrand; 321, string:'-'; 322, block; 322, 323; 322, 333; 323, expression_statement; 323, 324; 324, assignment; 324, 325; 324, 326; 325, identifier:Sz; 326, binary_operator:-; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:chain; 329, identifier:qEnd; 330, attribute; 330, 331; 330, 332; 331, identifier:chain; 332, identifier:qStart; 333, expression_statement; 333, 334; 334, assignment; 334, 335; 334, 336; 335, identifier:slices; 336, list_comprehension; 336, 337; 336, 348; 337, tuple; 337, 338; 337, 343; 338, binary_operator:-; 338, 339; 338, 340; 339, identifier:Sz; 340, subscript; 340, 341; 340, 342; 341, identifier:t; 342, integer:1; 343, binary_operator:-; 343, 344; 343, 345; 344, identifier:Sz; 345, subscript; 345, 346; 345, 347; 346, identifier:t; 347, integer:0; 348, for_in_clause; 348, 349; 348, 350; 349, identifier:t; 350, identifier:slices; 351, return_statement; 351, 352; 352, list_comprehension; 352, 353; 352, 368; 353, tuple; 353, 354; 353, 355; 353, 360; 353, 365; 354, identifier:to_chrom; 355, binary_operator:+; 355, 356; 355, 357; 356, identifier:to_gab_start; 357, subscript; 357, 358; 357, 359; 358, identifier:t; 359, integer:0; 360, binary_operator:+; 360, 361; 360, 362; 361, identifier:to_gab_start; 362, subscript; 362, 363; 362, 364; 363, identifier:t; 364, integer:1; 365, subscript; 365, 366; 365, 367; 366, identifier:elem; 367, string:'id'; 368, for_in_clause; 368, 369; 368, 370; 369, identifier:t; 370, identifier:slices | def transform(elem, chain_CT_CQ, max_gap):
(chain, CT, CQ) = chain_CT_CQ
start, end = max(elem['start'], chain.tStart) - chain.tStart, min(elem['end'], chain.tEnd) - chain.tStart
assert np.all( (CT[:,1] - CT[:,0]) == (CQ[:,1] - CQ[:,0]) )
to_chrom = chain.qName
to_gab_start = chain.qStart
start_idx = np.where( CT[:,1] > start )[0][0]
end_idx = np.where( CT[:,0] < end )[0][-1]
if start_idx > end_idx:
return []
if max_gap >= 0 and start_idx < end_idx - 1:
if np.max(CT[(start_idx+1):end_idx,0] - CT[start_idx:(end_idx-1),1]) > max_gap or np.max(CQ[(start_idx+1):end_idx,0] - CQ[start_idx:(end_idx-1),1]) > max_gap:
return []
assert start < CT[start_idx, 1]
assert CT[end_idx, 0] < end
to_start = CQ[start_idx, 0] + max(0, start - CT[start_idx,0])
to_end = CQ[end_idx, 1] - max(0, CT[end_idx, 1] - end)
if start_idx == end_idx:
slices = [(to_start, to_end)]
else:
slices = [(to_start, CQ[start_idx,1])]
slices += [(CQ[i,0], CQ[i,1]) for i in range(start_idx+1, end_idx)]
slices.append( (CQ[end_idx,0], to_end) )
if chain.qStrand == '-':
Sz = chain.qEnd - chain.qStart
slices = [(Sz-t[1], Sz-t[0]) for t in slices]
return [(to_chrom, to_gab_start + t[0], to_gab_start + t[1], elem['id']) for t in slices] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:visit_Method; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:method; 6, block; 6, 7; 6, 15; 6, 59; 6, 86; 6, 109; 6, 133; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:resolved_method; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:method; 13, identifier:resolved; 14, identifier:type; 15, function_definition; 15, 16; 15, 17; 15, 20; 16, function_name:get_params; 17, parameters; 17, 18; 17, 19; 18, identifier:method; 19, identifier:extra_bindings; 20, block; 20, 21; 20, 25; 20, 57; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:result; 24, list:[]; 25, for_statement; 25, 26; 25, 27; 25, 30; 26, identifier:param; 27, attribute; 27, 28; 27, 29; 28, identifier:method; 29, identifier:params; 30, block; 30, 31; 30, 48; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:resolved_param; 34, call; 34, 35; 34, 36; 35, identifier:texpr; 36, argument_list; 36, 37; 36, 42; 36, 47; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:param; 40, identifier:resolved; 41, identifier:type; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:param; 45, identifier:resolved; 46, identifier:bindings; 47, identifier:extra_bindings; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:result; 52, identifier:append; 53, argument_list; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:resolved_param; 56, identifier:id; 57, return_statement; 57, 58; 58, identifier:result; 59, function_definition; 59, 60; 59, 61; 59, 64; 60, function_name:get_return_type; 61, parameters; 61, 62; 61, 63; 62, identifier:method; 63, identifier:extra_bindings; 64, block; 64, 65; 65, return_statement; 65, 66; 66, attribute; 66, 67; 66, 85; 67, call; 67, 68; 67, 69; 68, identifier:texpr; 69, argument_list; 69, 70; 69, 77; 69, 84; 70, attribute; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:method; 74, identifier:type; 75, identifier:resolved; 76, identifier:type; 77, attribute; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:method; 81, identifier:type; 82, identifier:resolved; 83, identifier:bindings; 84, identifier:extra_bindings; 85, identifier:id; 86, function_definition; 86, 87; 86, 88; 86, 92; 87, function_name:signature; 88, parameters; 88, 89; 88, 90; 88, 91; 89, identifier:method; 90, identifier:return_type; 91, identifier:params; 92, block; 92, 93; 93, return_statement; 93, 94; 94, binary_operator:%; 94, 95; 94, 96; 95, string:"%s %s(%s)"; 96, tuple; 96, 97; 96, 98; 96, 103; 97, identifier:return_type; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:method; 101, identifier:name; 102, identifier:text; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, string:", "; 106, identifier:join; 107, argument_list; 107, 108; 108, identifier:params; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:interfaces; 112, call; 112, 113; 112, 114; 113, identifier:list; 114, generator_expression; 114, 115; 114, 116; 114, 123; 115, identifier:t; 116, for_in_clause; 116, 117; 116, 118; 117, identifier:t; 118, attribute; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:method; 121, identifier:clazz; 122, identifier:bases; 123, if_clause; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:isinstance; 126, argument_list; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:t; 130, identifier:resolved; 131, identifier:type; 132, identifier:Interface; 133, for_statement; 133, 134; 133, 135; 133, 136; 134, identifier:interface; 135, identifier:interfaces; 136, block; 136, 137; 136, 143; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:interfaceTypeExpr; 140, attribute; 140, 141; 140, 142; 141, identifier:interface; 142, identifier:resolved; 143, for_statement; 143, 144; 143, 145; 143, 150; 144, identifier:definition; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:interfaceTypeExpr; 148, identifier:type; 149, identifier:definitions; 150, block; 150, 151; 151, if_statement; 151, 152; 151, 163; 152, comparison_operator:==; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:definition; 156, identifier:name; 157, identifier:text; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:method; 161, identifier:name; 162, identifier:text; 163, block; 163, 164; 163, 172; 163, 186; 163, 196; 163, 210; 163, 220; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:resolved_definition; 167, attribute; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:definition; 170, identifier:resolved; 171, identifier:type; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:method_params; 175, call; 175, 176; 175, 177; 176, identifier:get_params; 177, argument_list; 177, 178; 177, 179; 178, identifier:resolved_method; 179, attribute; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:method; 183, identifier:clazz; 184, identifier:resolved; 185, identifier:bindings; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:definition_params; 189, call; 189, 190; 189, 191; 190, identifier:get_params; 191, argument_list; 191, 192; 191, 193; 192, identifier:resolved_definition; 193, attribute; 193, 194; 193, 195; 194, identifier:interfaceTypeExpr; 195, identifier:bindings; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:method_return; 199, call; 199, 200; 199, 201; 200, identifier:get_return_type; 201, argument_list; 201, 202; 201, 203; 202, identifier:resolved_method; 203, attribute; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:method; 207, identifier:clazz; 208, identifier:resolved; 209, identifier:bindings; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:definition_return; 213, call; 213, 214; 213, 215; 214, identifier:get_return_type; 215, argument_list; 215, 216; 215, 217; 216, identifier:resolved_definition; 217, attribute; 217, 218; 217, 219; 218, identifier:interfaceTypeExpr; 219, identifier:bindings; 220, if_statement; 220, 221; 220, 228; 221, boolean_operator:or; 221, 222; 221, 225; 222, comparison_operator:!=; 222, 223; 222, 224; 223, identifier:method_params; 224, identifier:definition_params; 225, comparison_operator:!=; 225, 226; 225, 227; 226, identifier:method_return; 227, identifier:definition_return; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 236; 231, attribute; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:self; 234, identifier:errors; 235, identifier:append; 236, argument_list; 236, 237; 237, binary_operator:%; 237, 238; 237, 239; 238, string:"%s: method signature '%s' on %s does not match method '%s' on interface %s"; 239, tuple; 239, 240; 239, 244; 239, 250; 239, 259; 239, 265; 240, call; 240, 241; 240, 242; 241, identifier:lineinfo; 242, argument_list; 242, 243; 243, identifier:method; 244, call; 244, 245; 244, 246; 245, identifier:signature; 246, argument_list; 246, 247; 246, 248; 246, 249; 247, identifier:resolved_method; 248, identifier:method_return; 249, identifier:method_params; 250, attribute; 250, 251; 250, 258; 251, attribute; 251, 252; 251, 257; 252, attribute; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:method; 255, identifier:clazz; 256, identifier:resolved; 257, identifier:type; 258, identifier:id; 259, call; 259, 260; 259, 261; 260, identifier:signature; 261, argument_list; 261, 262; 261, 263; 261, 264; 262, identifier:resolved_definition; 263, identifier:definition_return; 264, identifier:definition_params; 265, attribute; 265, 266; 265, 271; 266, attribute; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:interface; 269, identifier:resolved; 270, identifier:type; 271, identifier:id | def visit_Method(self, method):
resolved_method = method.resolved.type
def get_params(method, extra_bindings):
result = []
for param in method.params:
resolved_param = texpr(param.resolved.type, param.resolved.bindings, extra_bindings)
result.append(resolved_param.id)
return result
def get_return_type(method, extra_bindings):
return texpr(method.type.resolved.type, method.type.resolved.bindings,
extra_bindings).id
def signature(method, return_type, params):
return "%s %s(%s)" % (return_type, method.name.text, ", ".join(params))
interfaces = list(t for t in method.clazz.bases if isinstance(t.resolved.type, Interface))
for interface in interfaces:
interfaceTypeExpr = interface.resolved
for definition in interfaceTypeExpr.type.definitions:
if definition.name.text == method.name.text:
resolved_definition = definition.resolved.type
method_params = get_params(resolved_method, method.clazz.resolved.bindings)
definition_params = get_params(resolved_definition, interfaceTypeExpr.bindings)
method_return = get_return_type(resolved_method, method.clazz.resolved.bindings)
definition_return = get_return_type(resolved_definition, interfaceTypeExpr.bindings)
if method_params != definition_params or method_return != definition_return:
self.errors.append(
"%s: method signature '%s' on %s does not match method '%s' on interface %s" % (
lineinfo(method), signature(resolved_method, method_return, method_params),
method.clazz.resolved.type.id,
signature(resolved_definition, definition_return, definition_params),
interface.resolved.type.id)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:file_search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:query; 6, default_parameter; 6, 7; 6, 8; 7, identifier:offset; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:timeout; 11, None; 12, block; 12, 13; 12, 30; 12, 74; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:params; 16, call; 16, 17; 16, 18; 17, identifier:dict; 18, argument_list; 18, 19; 18, 24; 18, 27; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:apikey; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:api_key; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:query; 26, identifier:query; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:offset; 29, identifier:offset; 30, try_statement; 30, 31; 30, 56; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:response; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:requests; 38, identifier:get; 39, argument_list; 39, 40; 39, 45; 39, 48; 39, 53; 40, binary_operator:+; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:base; 44, string:'file/search'; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:params; 47, identifier:params; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:proxies; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:proxies; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:timeout; 55, identifier:timeout; 56, except_clause; 56, 57; 56, 63; 57, as_pattern; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:requests; 60, identifier:RequestException; 61, as_pattern_target; 61, 62; 62, identifier:e; 63, block; 63, 64; 64, return_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:dict; 67, argument_list; 67, 68; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:error; 70, call; 70, 71; 70, 72; 71, identifier:str; 72, argument_list; 72, 73; 73, identifier:e; 74, return_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:_return_response_and_status_code; 77, argument_list; 77, 78; 78, identifier:response | def file_search(self, query, offset=None, timeout=None):
params = dict(apikey=self.api_key, query=query, offset=offset)
try:
response = requests.get(self.base + 'file/search', params=params, proxies=self.proxies, timeout=timeout)
except requests.RequestException as e:
return dict(error=str(e))
return _return_response_and_status_code(response) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_handle_retry; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:resp; 6, block; 6, 7; 6, 18; 6, 28; 6, 48; 6, 67; 6, 117; 6, 152; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 13; 9, pattern_list; 9, 10; 9, 11; 9, 12; 10, identifier:exc_t; 11, identifier:exc_v; 12, identifier:exc_tb; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:sys; 16, identifier:exc_info; 17, argument_list; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:exc_t; 21, None; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:TypeError; 26, argument_list; 26, 27; 27, string:'Must be called in except block.'; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:retry_on_exc; 31, call; 31, 32; 31, 33; 32, identifier:tuple; 33, argument_list; 33, 34; 34, generator_expression; 34, 35; 34, 36; 34, 41; 35, identifier:x; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:x; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_retry_on; 41, if_clause; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:inspect; 45, identifier:isclass; 46, argument_list; 46, 47; 47, identifier:x; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:retry_on_codes; 51, call; 51, 52; 51, 53; 52, identifier:tuple; 53, argument_list; 53, 54; 54, generator_expression; 54, 55; 54, 56; 54, 61; 55, identifier:x; 56, for_in_clause; 56, 57; 56, 58; 57, identifier:x; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_retry_on; 61, if_clause; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:isinstance; 64, argument_list; 64, 65; 64, 66; 65, identifier:x; 66, identifier:int; 67, if_statement; 67, 68; 67, 73; 67, 98; 68, call; 68, 69; 68, 70; 69, identifier:issubclass; 70, argument_list; 70, 71; 70, 72; 71, identifier:exc_t; 72, identifier:ZendeskError; 73, block; 73, 74; 73, 80; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:code; 77, attribute; 77, 78; 77, 79; 78, identifier:exc_v; 79, identifier:error_code; 80, if_statement; 80, 81; 80, 88; 81, boolean_operator:and; 81, 82; 81, 85; 82, comparison_operator:not; 82, 83; 82, 84; 83, identifier:exc_t; 84, identifier:retry_on_exc; 85, comparison_operator:not; 85, 86; 85, 87; 86, identifier:code; 87, identifier:retry_on_codes; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:six; 93, identifier:reraise; 94, argument_list; 94, 95; 94, 96; 94, 97; 95, identifier:exc_t; 96, identifier:exc_v; 97, identifier:exc_tb; 98, else_clause; 98, 99; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 107; 101, not_operator; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:issubclass; 104, argument_list; 104, 105; 104, 106; 105, identifier:exc_t; 106, identifier:retry_on_exc; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:six; 112, identifier:reraise; 113, argument_list; 113, 114; 113, 115; 113, 116; 114, identifier:exc_t; 115, identifier:exc_v; 116, identifier:exc_tb; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:is; 118, 119; 118, 120; 119, identifier:resp; 120, None; 121, block; 121, 122; 122, try_statement; 122, 123; 122, 146; 123, block; 123, 124; 123, 139; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:retry_after; 127, call; 127, 128; 127, 129; 128, identifier:float; 129, argument_list; 129, 130; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:resp; 134, identifier:headers; 135, identifier:get; 136, argument_list; 136, 137; 136, 138; 137, string:'Retry-After'; 138, integer:0; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:time; 143, identifier:sleep; 144, argument_list; 144, 145; 145, identifier:retry_after; 146, except_clause; 146, 147; 146, 150; 147, tuple; 147, 148; 147, 149; 148, identifier:TypeError; 149, identifier:ValueError; 150, block; 150, 151; 151, pass_statement; 152, return_statement; 152, 153; 153, True | def _handle_retry(self, resp):
exc_t, exc_v, exc_tb = sys.exc_info()
if exc_t is None:
raise TypeError('Must be called in except block.')
retry_on_exc = tuple(
(x for x in self._retry_on if inspect.isclass(x)))
retry_on_codes = tuple(
(x for x in self._retry_on if isinstance(x, int)))
if issubclass(exc_t, ZendeskError):
code = exc_v.error_code
if exc_t not in retry_on_exc and code not in retry_on_codes:
six.reraise(exc_t, exc_v, exc_tb)
else:
if not issubclass(exc_t, retry_on_exc):
six.reraise(exc_t, exc_v, exc_tb)
if resp is not None:
try:
retry_after = float(resp.headers.get('Retry-After', 0))
time.sleep(retry_after)
except (TypeError, ValueError):
pass
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_event_triggers; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 14; 5, 18; 5, 26; 5, 105; 5, 114; 5, 349; 5, 366; 5, 379; 5, 387; 5, 395; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:events; 9, dictionary; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:nvrflag; 13, False; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:event_xml; 17, list:[]; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:url; 21, binary_operator:%; 21, 22; 21, 23; 22, string:'%s/ISAPI/Event/triggers'; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:root_url; 26, try_statement; 26, 27; 26, 79; 27, block; 27, 28; 27, 42; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:response; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:hik_request; 36, identifier:get; 37, argument_list; 37, 38; 37, 39; 38, identifier:url; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:timeout; 41, identifier:CONNECT_TIMEOUT; 42, if_statement; 42, 43; 42, 52; 43, comparison_operator:==; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:response; 46, identifier:status_code; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:requests; 50, identifier:codes; 51, identifier:not_found; 52, block; 52, 53; 52, 60; 52, 68; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:_LOGGING; 57, identifier:debug; 58, argument_list; 58, 59; 59, string:'Using alternate triggers URL.'; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:url; 63, binary_operator:%; 63, 64; 63, 65; 64, string:'%s/Event/triggers'; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:root_url; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:response; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:hik_request; 76, identifier:get; 77, argument_list; 77, 78; 78, identifier:url; 79, except_clause; 79, 80; 79, 94; 80, as_pattern; 80, 81; 80, 92; 81, tuple; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:requests; 85, identifier:exceptions; 86, identifier:RequestException; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:requests; 90, identifier:exceptions; 91, identifier:ConnectionError; 92, as_pattern_target; 92, 93; 93, identifier:err; 94, block; 94, 95; 94, 103; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:_LOGGING; 99, identifier:error; 100, argument_list; 100, 101; 100, 102; 101, string:'Unable to fetch events, error: %s'; 102, identifier:err; 103, return_statement; 103, 104; 104, None; 105, if_statement; 105, 106; 105, 111; 106, comparison_operator:!=; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:response; 109, identifier:status_code; 110, integer:200; 111, block; 111, 112; 112, return_statement; 112, 113; 113, None; 114, try_statement; 114, 115; 114, 329; 115, block; 115, 116; 115, 127; 115, 185; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:content; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:ET; 122, identifier:fromstring; 123, argument_list; 123, 124; 124, attribute; 124, 125; 124, 126; 125, identifier:response; 126, identifier:text; 127, if_statement; 127, 128; 127, 141; 127, 158; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, subscript; 130, 131; 130, 132; 131, identifier:content; 132, integer:0; 133, identifier:find; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:element_query; 139, argument_list; 139, 140; 140, string:'EventTrigger'; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:event_xml; 145, call; 145, 146; 145, 151; 146, attribute; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:content; 149, integer:0; 150, identifier:findall; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:element_query; 156, argument_list; 156, 157; 157, string:'EventTrigger'; 158, elif_clause; 158, 159; 158, 170; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:content; 162, identifier:find; 163, argument_list; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:element_query; 168, argument_list; 168, 169; 169, string:'EventTrigger'; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:event_xml; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:content; 177, identifier:findall; 178, argument_list; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:element_query; 183, argument_list; 183, 184; 184, string:'EventTrigger'; 185, for_statement; 185, 186; 185, 187; 185, 188; 186, identifier:eventtrigger; 187, identifier:event_xml; 188, block; 188, 189; 188, 203; 188, 209; 188, 223; 188, 227; 188, 231; 188, 279; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:ettype; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:eventtrigger; 195, identifier:find; 196, argument_list; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:element_query; 201, argument_list; 201, 202; 202, string:'eventType'; 203, if_statement; 203, 204; 203, 207; 204, comparison_operator:is; 204, 205; 204, 206; 205, identifier:ettype; 206, None; 207, block; 207, 208; 208, break_statement; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:etnotify; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:eventtrigger; 215, identifier:find; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:element_query; 221, argument_list; 221, 222; 222, string:'EventTriggerNotificationList'; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:etchannel; 226, None; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:etchannel_num; 230, integer:0; 231, for_statement; 231, 232; 231, 233; 231, 234; 232, identifier:node_name; 233, identifier:CHANNEL_NAMES; 234, block; 234, 235; 234, 249; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:etchannel; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:eventtrigger; 241, identifier:find; 242, argument_list; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:element_query; 247, argument_list; 247, 248; 248, identifier:node_name; 249, if_statement; 249, 250; 249, 253; 250, comparison_operator:is; 250, 251; 250, 252; 251, identifier:etchannel; 252, None; 253, block; 253, 254; 254, try_statement; 254, 255; 254, 275; 255, block; 255, 256; 255, 265; 255, 274; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:etchannel_num; 259, call; 259, 260; 259, 261; 260, identifier:int; 261, argument_list; 261, 262; 262, attribute; 262, 263; 262, 264; 263, identifier:etchannel; 264, identifier:text; 265, if_statement; 265, 266; 265, 269; 266, comparison_operator:>; 266, 267; 266, 268; 267, identifier:etchannel_num; 268, integer:1; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:nvrflag; 273, True; 274, break_statement; 275, except_clause; 275, 276; 275, 277; 276, identifier:ValueError; 277, block; 277, 278; 278, pass_statement; 279, if_statement; 279, 280; 279, 281; 280, identifier:etnotify; 281, block; 281, 282; 282, for_statement; 282, 283; 282, 284; 282, 285; 283, identifier:notifytrigger; 284, identifier:etnotify; 285, block; 285, 286; 285, 300; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:ntype; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:notifytrigger; 292, identifier:find; 293, argument_list; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:self; 297, identifier:element_query; 298, argument_list; 298, 299; 299, string:'notificationMethod'; 300, if_statement; 300, 301; 300, 312; 301, boolean_operator:or; 301, 302; 301, 307; 302, comparison_operator:==; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:ntype; 305, identifier:text; 306, string:'center'; 307, comparison_operator:==; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:ntype; 310, identifier:text; 311, string:'HTTP'; 312, block; 312, 313; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 327; 315, attribute; 315, 316; 315, 325; 315, 326; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:events; 319, identifier:setdefault; 320, argument_list; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:ettype; 323, identifier:text; 324, list:[]; 325, line_continuation:\; 326, identifier:append; 327, argument_list; 327, 328; 328, identifier:etchannel_num; 329, except_clause; 329, 330; 329, 338; 330, as_pattern; 330, 331; 330, 336; 331, tuple; 331, 332; 331, 333; 332, identifier:AttributeError; 333, attribute; 333, 334; 333, 335; 334, identifier:ET; 335, identifier:ParseError; 336, as_pattern_target; 336, 337; 337, identifier:err; 338, block; 338, 339; 338, 347; 339, expression_statement; 339, 340; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:_LOGGING; 343, identifier:error; 344, argument_list; 344, 345; 344, 346; 345, string:'There was a problem finding an element: %s'; 346, identifier:err; 347, return_statement; 347, 348; 348, None; 349, if_statement; 349, 350; 349, 351; 349, 358; 350, identifier:nvrflag; 351, block; 351, 352; 352, expression_statement; 352, 353; 353, assignment; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:self; 356, identifier:device_type; 357, identifier:NVR_DEVICE; 358, else_clause; 358, 359; 359, block; 359, 360; 360, expression_statement; 360, 361; 361, assignment; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:self; 364, identifier:device_type; 365, identifier:CAM_DEVICE; 366, expression_statement; 366, 367; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:_LOGGING; 370, identifier:debug; 371, argument_list; 371, 372; 371, 373; 371, 376; 372, string:'Processed %s as %s Device.'; 373, attribute; 373, 374; 373, 375; 374, identifier:self; 375, identifier:cam_id; 376, attribute; 376, 377; 376, 378; 377, identifier:self; 378, identifier:device_type; 379, expression_statement; 379, 380; 380, call; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:_LOGGING; 383, identifier:debug; 384, argument_list; 384, 385; 384, 386; 385, string:'Found events: %s'; 386, identifier:events; 387, expression_statement; 387, 388; 388, call; 388, 389; 388, 394; 389, attribute; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:self; 392, identifier:hik_request; 393, identifier:close; 394, argument_list; 395, return_statement; 395, 396; 396, identifier:events | def get_event_triggers(self):
events = {}
nvrflag = False
event_xml = []
url = '%s/ISAPI/Event/triggers' % self.root_url
try:
response = self.hik_request.get(url, timeout=CONNECT_TIMEOUT)
if response.status_code == requests.codes.not_found:
_LOGGING.debug('Using alternate triggers URL.')
url = '%s/Event/triggers' % self.root_url
response = self.hik_request.get(url)
except (requests.exceptions.RequestException,
requests.exceptions.ConnectionError) as err:
_LOGGING.error('Unable to fetch events, error: %s', err)
return None
if response.status_code != 200:
return None
try:
content = ET.fromstring(response.text)
if content[0].find(self.element_query('EventTrigger')):
event_xml = content[0].findall(
self.element_query('EventTrigger'))
elif content.find(self.element_query('EventTrigger')):
event_xml = content.findall(
self.element_query('EventTrigger'))
for eventtrigger in event_xml:
ettype = eventtrigger.find(self.element_query('eventType'))
if ettype is None:
break
etnotify = eventtrigger.find(
self.element_query('EventTriggerNotificationList'))
etchannel = None
etchannel_num = 0
for node_name in CHANNEL_NAMES:
etchannel = eventtrigger.find(
self.element_query(node_name))
if etchannel is not None:
try:
etchannel_num = int(etchannel.text)
if etchannel_num > 1:
nvrflag = True
break
except ValueError:
pass
if etnotify:
for notifytrigger in etnotify:
ntype = notifytrigger.find(
self.element_query('notificationMethod'))
if ntype.text == 'center' or ntype.text == 'HTTP':
events.setdefault(ettype.text, []) \
.append(etchannel_num)
except (AttributeError, ET.ParseError) as err:
_LOGGING.error(
'There was a problem finding an element: %s', err)
return None
if nvrflag:
self.device_type = NVR_DEVICE
else:
self.device_type = CAM_DEVICE
_LOGGING.debug('Processed %s as %s Device.',
self.cam_id, self.device_type)
_LOGGING.debug('Found events: %s', events)
self.hik_request.close()
return events |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_device_info; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 18; 5, 22; 5, 202; 5, 222; 5, 242; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:device_info; 9, dictionary; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:url; 13, binary_operator:%; 13, 14; 13, 15; 14, string:'%s/ISAPI/System/deviceInfo'; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:root_url; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:using_digest; 21, False; 22, try_statement; 22, 23; 22, 176; 23, block; 23, 24; 23, 38; 23, 87; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:response; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:hik_request; 32, identifier:get; 33, argument_list; 33, 34; 33, 35; 34, identifier:url; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:timeout; 37, identifier:CONNECT_TIMEOUT; 38, if_statement; 38, 39; 38, 48; 39, comparison_operator:==; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:response; 42, identifier:status_code; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:requests; 46, identifier:codes; 47, identifier:unauthorized; 48, block; 48, 49; 48, 56; 48, 72; 48, 76; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:_LOGGING; 53, identifier:debug; 54, argument_list; 54, 55; 55, string:'Basic authentication failed. Using digest.'; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:hik_request; 62, identifier:auth; 63, call; 63, 64; 63, 65; 64, identifier:HTTPDigestAuth; 65, argument_list; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:usr; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:pwd; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:using_digest; 75, True; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:response; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:hik_request; 84, identifier:get; 85, argument_list; 85, 86; 86, identifier:url; 87, if_statement; 87, 88; 87, 97; 88, comparison_operator:==; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:response; 91, identifier:status_code; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:requests; 95, identifier:codes; 96, identifier:not_found; 97, block; 97, 98; 97, 105; 97, 113; 97, 124; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:_LOGGING; 102, identifier:debug; 103, argument_list; 103, 104; 104, string:'Using alternate deviceInfo URL.'; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:url; 108, binary_operator:%; 108, 109; 108, 110; 109, string:'%s/System/deviceInfo'; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:root_url; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:response; 116, call; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:hik_request; 121, identifier:get; 122, argument_list; 122, 123; 123, identifier:url; 124, if_statement; 124, 125; 124, 137; 125, boolean_operator:and; 125, 126; 125, 128; 126, not_operator; 126, 127; 127, identifier:using_digest; 128, comparison_operator:==; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:response; 131, identifier:status_code; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:requests; 135, identifier:codes; 136, identifier:unauthorized; 137, block; 137, 138; 137, 145; 137, 161; 137, 165; 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, string:'Basic authentication failed. Using digest.'; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:hik_request; 151, identifier:auth; 152, call; 152, 153; 152, 154; 153, identifier:HTTPDigestAuth; 154, argument_list; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:usr; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:pwd; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:using_digest; 164, True; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:response; 168, call; 168, 169; 168, 174; 169, attribute; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:hik_request; 173, identifier:get; 174, argument_list; 174, 175; 175, identifier:url; 176, except_clause; 176, 177; 176, 191; 177, as_pattern; 177, 178; 177, 189; 178, tuple; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:requests; 182, identifier:exceptions; 183, identifier:RequestException; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:requests; 187, identifier:exceptions; 188, identifier:ConnectionError; 189, as_pattern_target; 189, 190; 190, identifier:err; 191, block; 191, 192; 191, 200; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:_LOGGING; 196, identifier:error; 197, argument_list; 197, 198; 197, 199; 198, string:'Unable to fetch deviceInfo, error: %s'; 199, identifier:err; 200, return_statement; 200, 201; 201, None; 202, if_statement; 202, 203; 202, 212; 203, comparison_operator:==; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:response; 206, identifier:status_code; 207, attribute; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:requests; 210, identifier:codes; 211, identifier:unauthorized; 212, block; 212, 213; 212, 220; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:_LOGGING; 217, identifier:error; 218, argument_list; 218, 219; 219, string:'Authentication failed'; 220, return_statement; 220, 221; 221, None; 222, if_statement; 222, 223; 222, 232; 223, comparison_operator:!=; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:response; 226, identifier:status_code; 227, attribute; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:requests; 230, identifier:codes; 231, identifier:ok; 232, block; 232, 233; 232, 240; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:_LOGGING; 237, identifier:debug; 238, argument_list; 238, 239; 239, string:'Unable to fetch device info.'; 240, return_statement; 240, 241; 241, None; 242, try_statement; 242, 243; 242, 324; 243, block; 243, 244; 243, 255; 243, 273; 243, 287; 243, 297; 243, 322; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:tree; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:ET; 250, identifier:fromstring; 251, argument_list; 251, 252; 252, attribute; 252, 253; 252, 254; 253, identifier:response; 254, identifier:text; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:nmsp; 258, call; 258, 259; 258, 271; 259, attribute; 259, 260; 259, 270; 260, subscript; 260, 261; 260, 269; 261, call; 261, 262; 261, 267; 262, attribute; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:tree; 265, identifier:tag; 266, identifier:split; 267, argument_list; 267, 268; 268, string:'}'; 269, integer:0; 270, identifier:strip; 271, argument_list; 271, 272; 272, string:'{'; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:namespace; 278, conditional_expression:if; 278, 279; 278, 280; 278, 286; 279, identifier:nmsp; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:nmsp; 283, identifier:startswith; 284, argument_list; 284, 285; 285, string:'http'; 286, identifier:XML_NAMESPACE; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:_LOGGING; 291, identifier:debug; 292, argument_list; 292, 293; 292, 294; 293, string:'Using Namespace: %s'; 294, attribute; 294, 295; 294, 296; 295, identifier:self; 296, identifier:namespace; 297, for_statement; 297, 298; 297, 299; 297, 300; 298, identifier:item; 299, identifier:tree; 300, block; 300, 301; 300, 314; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:tag; 304, subscript; 304, 305; 304, 313; 305, call; 305, 306; 305, 311; 306, attribute; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:item; 309, identifier:tag; 310, identifier:split; 311, argument_list; 311, 312; 312, string:'}'; 313, integer:1; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 319; 316, subscript; 316, 317; 316, 318; 317, identifier:device_info; 318, identifier:tag; 319, attribute; 319, 320; 319, 321; 320, identifier:item; 321, identifier:text; 322, return_statement; 322, 323; 323, identifier:device_info; 324, except_clause; 324, 325; 324, 329; 325, as_pattern; 325, 326; 325, 327; 326, identifier:AttributeError; 327, as_pattern_target; 327, 328; 328, identifier:err; 329, block; 329, 330; 329, 340; 329, 348; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:_LOGGING; 334, identifier:error; 335, argument_list; 335, 336; 335, 337; 336, string:'Entire response: %s'; 337, attribute; 337, 338; 337, 339; 338, identifier:response; 339, identifier:text; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:_LOGGING; 344, identifier:error; 345, argument_list; 345, 346; 345, 347; 346, string:'There was a problem: %s'; 347, identifier:err; 348, return_statement; 348, 349; 349, None | def get_device_info(self):
device_info = {}
url = '%s/ISAPI/System/deviceInfo' % self.root_url
using_digest = False
try:
response = self.hik_request.get(url, timeout=CONNECT_TIMEOUT)
if response.status_code == requests.codes.unauthorized:
_LOGGING.debug('Basic authentication failed. Using digest.')
self.hik_request.auth = HTTPDigestAuth(self.usr, self.pwd)
using_digest = True
response = self.hik_request.get(url)
if response.status_code == requests.codes.not_found:
_LOGGING.debug('Using alternate deviceInfo URL.')
url = '%s/System/deviceInfo' % self.root_url
response = self.hik_request.get(url)
if not using_digest and response.status_code == requests.codes.unauthorized:
_LOGGING.debug('Basic authentication failed. Using digest.')
self.hik_request.auth = HTTPDigestAuth(self.usr, self.pwd)
using_digest = True
response = self.hik_request.get(url)
except (requests.exceptions.RequestException,
requests.exceptions.ConnectionError) as err:
_LOGGING.error('Unable to fetch deviceInfo, error: %s', err)
return None
if response.status_code == requests.codes.unauthorized:
_LOGGING.error('Authentication failed')
return None
if response.status_code != requests.codes.ok:
_LOGGING.debug('Unable to fetch device info.')
return None
try:
tree = ET.fromstring(response.text)
nmsp = tree.tag.split('}')[0].strip('{')
self.namespace = nmsp if nmsp.startswith('http') else XML_NAMESPACE
_LOGGING.debug('Using Namespace: %s', self.namespace)
for item in tree:
tag = item.tag.split('}')[1]
device_info[tag] = item.text
return device_info
except AttributeError as err:
_LOGGING.error('Entire response: %s', response.text)
_LOGGING.error('There was a problem: %s', err)
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:alert_stream; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:reset_event; 6, identifier:kill_event; 7, block; 7, 8; 7, 21; 7, 25; 7, 29; 7, 33; 7, 41; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:_LOGGING; 12, identifier:debug; 13, argument_list; 13, 14; 13, 15; 13, 18; 14, string:'Stream Thread Started: %s, %s'; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:name; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:cam_id; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:start_event; 24, False; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:parse_string; 28, string:""; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:fail_count; 32, integer:0; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:url; 36, binary_operator:%; 36, 37; 36, 38; 37, string:'%s/ISAPI/Event/notification/alertStream'; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:root_url; 41, while_statement; 41, 42; 41, 43; 42, True; 43, block; 43, 44; 44, try_statement; 44, 45; 44, 301; 45, block; 45, 46; 45, 65; 45, 98; 45, 138; 45, 255; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:stream; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:hik_request; 54, identifier:get; 55, argument_list; 55, 56; 55, 57; 55, 60; 56, identifier:url; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:stream; 59, True; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:timeout; 62, tuple; 62, 63; 62, 64; 63, identifier:CONNECT_TIMEOUT; 64, identifier:READ_TIMEOUT; 65, if_statement; 65, 66; 65, 75; 66, comparison_operator:==; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:stream; 69, identifier:status_code; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:requests; 73, identifier:codes; 74, identifier:not_found; 75, block; 75, 76; 75, 84; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:url; 79, binary_operator:%; 79, 80; 79, 81; 80, string:'%s/Event/notification/alertStream'; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:root_url; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:stream; 87, call; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:hik_request; 92, identifier:get; 93, argument_list; 93, 94; 93, 95; 94, identifier:url; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:stream; 97, True; 98, if_statement; 98, 99; 98, 108; 98, 114; 99, comparison_operator:!=; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:stream; 102, identifier:status_code; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:requests; 106, identifier:codes; 107, identifier:ok; 108, block; 108, 109; 109, raise_statement; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:ValueError; 112, argument_list; 112, 113; 113, string:'Connection unsucessful.'; 114, else_clause; 114, 115; 115, block; 115, 116; 115, 126; 115, 130; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:_LOGGING; 120, identifier:debug; 121, argument_list; 121, 122; 121, 123; 122, string:'%s Connection Successful.'; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:name; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:fail_count; 129, integer:0; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:watchdog; 136, identifier:start; 137, argument_list; 138, for_statement; 138, 139; 138, 140; 138, 145; 139, identifier:line; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:stream; 143, identifier:iter_lines; 144, argument_list; 145, block; 145, 146; 145, 235; 146, if_statement; 146, 147; 146, 148; 147, identifier:line; 148, block; 148, 149; 148, 159; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:str_line; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:line; 155, identifier:decode; 156, argument_list; 156, 157; 156, 158; 157, string:"utf-8"; 158, string:"ignore"; 159, if_statement; 159, 160; 159, 169; 159, 178; 159, 226; 160, comparison_operator:!=; 160, 161; 160, 167; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:str_line; 164, identifier:find; 165, argument_list; 165, 166; 166, string:'<EventNotificationAlert'; 167, unary_operator:-; 167, 168; 168, integer:1; 169, block; 169, 170; 169, 174; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:start_event; 173, True; 174, expression_statement; 174, 175; 175, augmented_assignment:+=; 175, 176; 175, 177; 176, identifier:parse_string; 177, identifier:str_line; 178, elif_clause; 178, 179; 178, 188; 179, comparison_operator:!=; 179, 180; 179, 186; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:str_line; 183, identifier:find; 184, argument_list; 184, 185; 185, string:'</EventNotificationAlert>'; 186, unary_operator:-; 186, 187; 187, integer:1; 188, block; 188, 189; 188, 193; 188, 197; 189, expression_statement; 189, 190; 190, augmented_assignment:+=; 190, 191; 190, 192; 191, identifier:parse_string; 192, identifier:str_line; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:start_event; 196, False; 197, if_statement; 197, 198; 197, 199; 198, identifier:parse_string; 199, block; 199, 200; 199, 209; 199, 216; 199, 222; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:tree; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:ET; 206, identifier:fromstring; 207, argument_list; 207, 208; 208, identifier:parse_string; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:process_stream; 214, argument_list; 214, 215; 215, identifier:tree; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:update_stale; 221, argument_list; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:parse_string; 225, string:""; 226, else_clause; 226, 227; 227, block; 227, 228; 228, if_statement; 228, 229; 228, 230; 229, identifier:start_event; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, augmented_assignment:+=; 232, 233; 232, 234; 233, identifier:parse_string; 234, identifier:str_line; 235, if_statement; 235, 236; 235, 241; 235, 243; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:kill_event; 239, identifier:is_set; 240, argument_list; 241, block; 241, 242; 242, break_statement; 243, elif_clause; 243, 244; 243, 249; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:reset_event; 247, identifier:is_set; 248, argument_list; 249, block; 249, 250; 250, raise_statement; 250, 251; 251, call; 251, 252; 251, 253; 252, identifier:ValueError; 253, argument_list; 253, 254; 254, string:'Watchdog failed.'; 255, if_statement; 255, 256; 255, 261; 255, 289; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:kill_event; 259, identifier:is_set; 260, argument_list; 261, block; 261, 262; 261, 272; 261, 280; 261, 288; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:_LOGGING; 266, identifier:debug; 267, argument_list; 267, 268; 267, 269; 268, string:'Stopping event stream thread for %s'; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:name; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 279; 274, attribute; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:watchdog; 278, identifier:stop; 279, argument_list; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 287; 282, attribute; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:self; 285, identifier:hik_request; 286, identifier:close; 287, argument_list; 288, return_statement; 289, elif_clause; 289, 290; 289, 295; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:reset_event; 293, identifier:is_set; 294, argument_list; 295, block; 295, 296; 296, raise_statement; 296, 297; 297, call; 297, 298; 297, 299; 298, identifier:ValueError; 299, argument_list; 299, 300; 300, string:'Watchdog failed.'; 301, except_clause; 301, 302; 301, 317; 302, as_pattern; 302, 303; 302, 315; 303, tuple; 303, 304; 303, 305; 303, 310; 304, identifier:ValueError; 305, attribute; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:requests; 308, identifier:exceptions; 309, identifier:ConnectionError; 310, attribute; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:requests; 313, identifier:exceptions; 314, identifier:ChunkedEncodingError; 315, as_pattern_target; 315, 316; 316, identifier:err; 317, block; 317, 318; 317, 322; 317, 328; 317, 346; 317, 350; 317, 358; 317, 366; 317, 373; 317, 379; 317, 388; 318, expression_statement; 318, 319; 319, augmented_assignment:+=; 319, 320; 319, 321; 320, identifier:fail_count; 321, integer:1; 322, expression_statement; 322, 323; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:reset_event; 326, identifier:clear; 327, argument_list; 328, expression_statement; 328, 329; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:_LOGGING; 332, identifier:warning; 333, argument_list; 333, 334; 333, 335; 333, 338; 333, 339; 333, 345; 334, string:'%s Connection Failed (count=%d). Waiting %ss. Err: %s'; 335, attribute; 335, 336; 335, 337; 336, identifier:self; 337, identifier:name; 338, identifier:fail_count; 339, binary_operator:+; 339, 340; 339, 344; 340, parenthesized_expression; 340, 341; 341, binary_operator:*; 341, 342; 341, 343; 342, identifier:fail_count; 343, integer:5; 344, integer:5; 345, identifier:err; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 349; 348, identifier:parse_string; 349, string:""; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 357; 352, attribute; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:watchdog; 356, identifier:stop; 357, argument_list; 358, expression_statement; 358, 359; 359, call; 359, 360; 359, 365; 360, attribute; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:self; 363, identifier:hik_request; 364, identifier:close; 365, argument_list; 366, expression_statement; 366, 367; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:time; 370, identifier:sleep; 371, argument_list; 371, 372; 372, integer:5; 373, expression_statement; 373, 374; 374, call; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:self; 377, identifier:update_stale; 378, argument_list; 379, expression_statement; 379, 380; 380, call; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:time; 383, identifier:sleep; 384, argument_list; 384, 385; 385, binary_operator:*; 385, 386; 385, 387; 386, identifier:fail_count; 387, integer:5; 388, continue_statement | def alert_stream(self, reset_event, kill_event):
_LOGGING.debug('Stream Thread Started: %s, %s', self.name, self.cam_id)
start_event = False
parse_string = ""
fail_count = 0
url = '%s/ISAPI/Event/notification/alertStream' % self.root_url
while True:
try:
stream = self.hik_request.get(url, stream=True,
timeout=(CONNECT_TIMEOUT,
READ_TIMEOUT))
if stream.status_code == requests.codes.not_found:
url = '%s/Event/notification/alertStream' % self.root_url
stream = self.hik_request.get(url, stream=True)
if stream.status_code != requests.codes.ok:
raise ValueError('Connection unsucessful.')
else:
_LOGGING.debug('%s Connection Successful.', self.name)
fail_count = 0
self.watchdog.start()
for line in stream.iter_lines():
if line:
str_line = line.decode("utf-8", "ignore")
if str_line.find('<EventNotificationAlert') != -1:
start_event = True
parse_string += str_line
elif str_line.find('</EventNotificationAlert>') != -1:
parse_string += str_line
start_event = False
if parse_string:
tree = ET.fromstring(parse_string)
self.process_stream(tree)
self.update_stale()
parse_string = ""
else:
if start_event:
parse_string += str_line
if kill_event.is_set():
break
elif reset_event.is_set():
raise ValueError('Watchdog failed.')
if kill_event.is_set():
_LOGGING.debug('Stopping event stream thread for %s',
self.name)
self.watchdog.stop()
self.hik_request.close()
return
elif reset_event.is_set():
raise ValueError('Watchdog failed.')
except (ValueError,
requests.exceptions.ConnectionError,
requests.exceptions.ChunkedEncodingError) as err:
fail_count += 1
reset_event.clear()
_LOGGING.warning('%s Connection Failed (count=%d). Waiting %ss. Err: %s',
self.name, fail_count, (fail_count * 5) + 5, err)
parse_string = ""
self.watchdog.stop()
self.hik_request.close()
time.sleep(5)
self.update_stale()
time.sleep(fail_count * 5)
continue |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:construct_request; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:ticker; 5, default_parameter; 5, 6; 5, 7; 6, identifier:fields; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:date; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:date_from; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:date_to; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:freq; 19, None; 20, block; 20, 21; 20, 55; 20, 98; 20, 163; 20, 174; 21, if_statement; 21, 22; 21, 27; 21, 32; 21, 48; 22, call; 22, 23; 22, 24; 23, identifier:isinstance; 24, argument_list; 24, 25; 24, 26; 25, identifier:ticker; 26, identifier:basestring; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:request; 31, identifier:ticker; 32, elif_clause; 32, 33; 32, 38; 33, call; 33, 34; 33, 35; 34, identifier:hasattr; 35, argument_list; 35, 36; 35, 37; 36, identifier:ticker; 37, string:'__len__'; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:request; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, string:','; 45, identifier:join; 46, argument_list; 46, 47; 47, identifier:ticker; 48, else_clause; 48, 49; 49, block; 49, 50; 50, raise_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:ValueError; 53, argument_list; 53, 54; 54, string:'ticker should be either string or list/array of strings'; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:fields; 58, None; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 66; 60, 73; 61, call; 61, 62; 61, 63; 62, identifier:isinstance; 63, argument_list; 63, 64; 63, 65; 64, identifier:fields; 65, identifier:basestring; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, augmented_assignment:+=; 68, 69; 68, 70; 69, identifier:request; 70, binary_operator:+; 70, 71; 70, 72; 71, string:'~='; 72, identifier:fields; 73, elif_clause; 73, 74; 73, 86; 74, boolean_operator:and; 74, 75; 74, 80; 75, call; 75, 76; 75, 77; 76, identifier:isinstance; 77, argument_list; 77, 78; 77, 79; 78, identifier:fields; 79, identifier:list; 80, comparison_operator:>; 80, 81; 80, 85; 81, call; 81, 82; 81, 83; 82, identifier:len; 83, argument_list; 83, 84; 84, identifier:fields; 85, integer:0; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, augmented_assignment:+=; 88, 89; 88, 90; 89, identifier:request; 90, binary_operator:+; 90, 91; 90, 92; 91, string:'~='; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, string:','; 95, identifier:join; 96, argument_list; 96, 97; 97, identifier:fields; 98, if_statement; 98, 99; 98, 102; 98, 119; 99, comparison_operator:is; 99, 100; 99, 101; 100, identifier:date; 101, None; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, augmented_assignment:+=; 104, 105; 104, 106; 105, identifier:request; 106, binary_operator:+; 106, 107; 106, 108; 107, string:'~@'; 108, call; 108, 109; 108, 117; 109, attribute; 109, 110; 109, 116; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:pd; 113, identifier:to_datetime; 114, argument_list; 114, 115; 115, identifier:date; 116, identifier:strftime; 117, argument_list; 117, 118; 118, string:'%Y-%m-%d'; 119, else_clause; 119, 120; 120, block; 120, 121; 120, 142; 121, if_statement; 121, 122; 121, 125; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:date_from; 124, None; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, augmented_assignment:+=; 127, 128; 127, 129; 128, identifier:request; 129, binary_operator:+; 129, 130; 129, 131; 130, string:'~'; 131, call; 131, 132; 131, 140; 132, attribute; 132, 133; 132, 139; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:pd; 136, identifier:to_datetime; 137, argument_list; 137, 138; 138, identifier:date_from; 139, identifier:strftime; 140, argument_list; 140, 141; 141, string:'%Y-%m-%d'; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:is; 143, 144; 143, 145; 144, identifier:date_to; 145, None; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, augmented_assignment:+=; 148, 149; 148, 150; 149, identifier:request; 150, binary_operator:+; 150, 151; 150, 152; 151, string:'~:'; 152, call; 152, 153; 152, 161; 153, attribute; 153, 154; 153, 160; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:pd; 157, identifier:to_datetime; 158, argument_list; 158, 159; 159, identifier:date_to; 160, identifier:strftime; 161, argument_list; 161, 162; 162, string:'%Y-%m-%d'; 163, if_statement; 163, 164; 163, 167; 164, comparison_operator:is; 164, 165; 164, 166; 165, identifier:freq; 166, None; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:request; 171, binary_operator:+; 171, 172; 171, 173; 172, string:'~'; 173, identifier:freq; 174, return_statement; 174, 175; 175, identifier:request | def construct_request(ticker, fields=None, date=None,
date_from=None, date_to=None, freq=None):
if isinstance(ticker, basestring):
request = ticker
elif hasattr(ticker, '__len__'):
request = ','.join(ticker)
else:
raise ValueError('ticker should be either string or list/array of strings')
if fields is not None:
if isinstance(fields, basestring):
request += '~=' + fields
elif isinstance(fields, list) and len(fields) > 0:
request += '~=' + ','.join(fields)
if date is not None:
request += '~@' + pd.to_datetime(date).strftime('%Y-%m-%d')
else:
if date_from is not None:
request += '~' + pd.to_datetime(date_from).strftime('%Y-%m-%d')
if date_to is not None:
request += '~:' + pd.to_datetime(date_to).strftime('%Y-%m-%d')
if freq is not None:
request += '~' + freq
return request |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:set; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:value; 7, default_parameter; 7, 8; 7, 9; 8, identifier:index; 9, unary_operator:-; 9, 10; 10, integer:1; 11, block; 11, 12; 11, 29; 11, 37; 11, 53; 11, 72; 11, 139; 11, 152; 11, 162; 11, 184; 12, if_statement; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:value; 17, identifier:ElementProxy; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:value; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, subscript; 24, 25; 24, 26; 25, identifier:value; 26, integer:0; 27, identifier:to_er7; 28, argument_list; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:name; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:name; 35, identifier:upper; 36, argument_list; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:reference; 40, conditional_expression:if; 40, 41; 40, 42; 40, 45; 41, None; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:name; 44, None; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:element; 50, identifier:find_child_reference; 51, argument_list; 51, 52; 52, identifier:name; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, pattern_list; 55, 56; 55, 57; 56, identifier:child_ref; 57, identifier:child_name; 58, conditional_expression:if; 58, 59; 58, 62; 58, 65; 59, tuple; 59, 60; 59, 61; 60, None; 61, None; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:reference; 64, None; 65, tuple; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:reference; 68, string:'ref'; 69, subscript; 69, 70; 69, 71; 70, identifier:reference; 71, string:'name'; 72, if_statement; 72, 73; 72, 78; 72, 96; 72, 107; 72, 131; 73, call; 73, 74; 73, 75; 74, identifier:isinstance; 75, argument_list; 75, 76; 75, 77; 76, identifier:value; 77, identifier:basestring; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:child; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:element; 87, identifier:parse_child; 88, argument_list; 88, 89; 88, 90; 88, 93; 89, identifier:value; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:child_name; 92, identifier:child_name; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:reference; 95, identifier:child_ref; 96, elif_clause; 96, 97; 96, 102; 97, call; 97, 98; 97, 99; 98, identifier:isinstance; 99, argument_list; 99, 100; 99, 101; 100, identifier:value; 101, identifier:Element; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:child; 106, identifier:value; 107, elif_clause; 107, 108; 107, 113; 108, call; 108, 109; 108, 110; 109, identifier:isinstance; 110, argument_list; 110, 111; 110, 112; 111, identifier:value; 112, identifier:BaseDataType; 113, block; 113, 114; 113, 125; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:child; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:create_element; 121, argument_list; 121, 122; 121, 123; 121, 124; 122, identifier:name; 123, False; 124, identifier:reference; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:child; 129, identifier:value; 130, identifier:value; 131, else_clause; 131, 132; 132, block; 132, 133; 133, raise_statement; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:ChildNotValid; 136, argument_list; 136, 137; 136, 138; 137, identifier:value; 138, identifier:child_name; 139, if_statement; 139, 140; 139, 145; 140, comparison_operator:!=; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:child; 143, identifier:name; 144, identifier:child_name; 145, block; 145, 146; 146, raise_statement; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:ChildNotValid; 149, argument_list; 149, 150; 149, 151; 150, identifier:value; 151, identifier:child_name; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:child_to_remove; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:child_at_index; 159, argument_list; 159, 160; 159, 161; 160, identifier:child_name; 161, identifier:index; 162, if_statement; 162, 163; 162, 166; 162, 174; 163, comparison_operator:is; 163, 164; 163, 165; 164, identifier:child_to_remove; 165, None; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:append; 172, argument_list; 172, 173; 173, identifier:child; 174, else_clause; 174, 175; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:replace_child; 181, argument_list; 181, 182; 181, 183; 182, identifier:child_to_remove; 183, identifier:child; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:element; 190, identifier:set_parent_to_traversal; 191, argument_list | def set(self, name, value, index=-1):
if isinstance(value, ElementProxy):
value = value[0].to_er7()
name = name.upper()
reference = None if name is None else self.element.find_child_reference(name)
child_ref, child_name = (None, None) if reference is None else (reference['ref'], reference['name'])
if isinstance(value, basestring):
child = self.element.parse_child(value, child_name=child_name, reference=child_ref)
elif isinstance(value, Element):
child = value
elif isinstance(value, BaseDataType):
child = self.create_element(name, False, reference)
child.value = value
else:
raise ChildNotValid(value, child_name)
if child.name != child_name:
raise ChildNotValid(value, child_name)
child_to_remove = self.child_at_index(child_name, index)
if child_to_remove is None:
self.append(child)
else:
self.replace_child(child_to_remove, child)
self.element.set_parent_to_traversal() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:init_app; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:app; 6, default_parameter; 6, 7; 6, 8; 7, identifier:config_prefix; 8, None; 9, block; 9, 10; 9, 25; 9, 35; 9, 54; 9, 61; 9, 80; 9, 93; 9, 108; 9, 122; 9, 136; 9, 241; 9, 255; 9, 296; 9, 305; 9, 346; 9, 354; 9, 364; 10, if_statement; 10, 11; 10, 16; 11, comparison_operator:not; 11, 12; 11, 13; 12, string:'redis'; 13, attribute; 13, 14; 13, 15; 14, identifier:app; 15, identifier:extensions; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 24; 19, subscript; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:app; 22, identifier:extensions; 23, string:'redis'; 24, dictionary; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:config_prefix; 30, assignment; 30, 31; 30, 32; 31, identifier:config_prefix; 32, boolean_operator:or; 32, 33; 32, 34; 33, identifier:config_prefix; 34, string:'REDIS'; 35, if_statement; 35, 36; 35, 43; 36, comparison_operator:in; 36, 37; 36, 38; 37, identifier:config_prefix; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:app; 41, identifier:extensions; 42, string:'redis'; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:ValueError; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, string:'Already registered config prefix {0!r}.'; 51, identifier:format; 52, argument_list; 52, 53; 53, identifier:config_prefix; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:converters; 57, dictionary; 57, 58; 58, pair; 58, 59; 58, 60; 59, string:'port'; 60, identifier:int; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:convert; 64, lambda; 64, 65; 64, 68; 65, lambda_parameters; 65, 66; 65, 67; 66, identifier:arg; 67, identifier:value; 68, parenthesized_expression; 68, 69; 69, conditional_expression:if; 69, 70; 69, 76; 69, 79; 70, call; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:converters; 73, identifier:arg; 74, argument_list; 74, 75; 75, identifier:value; 76, comparison_operator:in; 76, 77; 76, 78; 77, identifier:arg; 78, identifier:converters; 79, identifier:value; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:key; 83, lambda; 83, 84; 83, 86; 84, lambda_parameters; 84, 85; 85, identifier:param; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, string:'{0}_{1}'; 89, identifier:format; 90, argument_list; 90, 91; 90, 92; 91, identifier:config_prefix; 92, identifier:param; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:klass; 96, call; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:app; 100, identifier:config; 101, identifier:get; 102, argument_list; 102, 103; 102, 107; 103, call; 103, 104; 103, 105; 104, identifier:key; 105, argument_list; 105, 106; 106, string:'CLASS'; 107, identifier:RedisClass; 108, if_statement; 108, 109; 108, 114; 109, call; 109, 110; 109, 111; 110, identifier:isinstance; 111, argument_list; 111, 112; 111, 113; 112, identifier:klass; 113, identifier:string_types; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:klass; 118, call; 118, 119; 118, 120; 119, identifier:import_string; 120, argument_list; 120, 121; 121, identifier:klass; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:url; 125, call; 125, 126; 125, 131; 126, attribute; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:app; 129, identifier:config; 130, identifier:get; 131, argument_list; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:key; 134, argument_list; 134, 135; 135, string:'URL'; 136, if_statement; 136, 137; 136, 138; 137, identifier:url; 138, block; 138, 139; 138, 148; 138, 157; 138, 170; 138, 185; 138, 198; 138, 211; 138, 223; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:urlparse; 144, identifier:uses_netloc; 145, identifier:append; 146, argument_list; 146, 147; 147, string:'redis'; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:url; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:urlparse; 154, identifier:urlparse; 155, argument_list; 155, 156; 156, identifier:url; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 167; 159, subscript; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:app; 162, identifier:config; 163, call; 163, 164; 163, 165; 164, identifier:key; 165, argument_list; 165, 166; 166, string:'HOST'; 167, attribute; 167, 168; 167, 169; 168, identifier:url; 169, identifier:hostname; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 180; 172, subscript; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:app; 175, identifier:config; 176, call; 176, 177; 176, 178; 177, identifier:key; 178, argument_list; 178, 179; 179, string:'PORT'; 180, boolean_operator:or; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:url; 183, identifier:port; 184, integer:6379; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 195; 187, subscript; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:app; 190, identifier:config; 191, call; 191, 192; 191, 193; 192, identifier:key; 193, argument_list; 193, 194; 194, string:'USER'; 195, attribute; 195, 196; 195, 197; 196, identifier:url; 197, identifier:username; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 208; 200, subscript; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:app; 203, identifier:config; 204, call; 204, 205; 204, 206; 205, identifier:key; 206, argument_list; 206, 207; 207, string:'PASSWORD'; 208, attribute; 208, 209; 208, 210; 209, identifier:url; 210, identifier:password; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:db; 214, call; 214, 215; 214, 220; 215, attribute; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:url; 218, identifier:path; 219, identifier:replace; 220, argument_list; 220, 221; 220, 222; 221, string:'/'; 222, string:''; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 233; 225, subscript; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:app; 228, identifier:config; 229, call; 229, 230; 229, 231; 230, identifier:key; 231, argument_list; 231, 232; 232, string:'DB'; 233, conditional_expression:if; 233, 234; 233, 235; 233, 240; 234, identifier:db; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:db; 238, identifier:isdigit; 239, argument_list; 240, None; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:host; 244, call; 244, 245; 244, 250; 245, attribute; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:app; 248, identifier:config; 249, identifier:get; 250, argument_list; 250, 251; 251, call; 251, 252; 251, 253; 252, identifier:key; 253, argument_list; 253, 254; 254, string:'HOST'; 255, if_statement; 255, 256; 255, 272; 256, boolean_operator:and; 256, 257; 256, 258; 257, identifier:host; 258, parenthesized_expression; 258, 259; 259, boolean_operator:or; 259, 260; 259, 266; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:host; 263, identifier:startswith; 264, argument_list; 264, 265; 265, string:'file://'; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:host; 269, identifier:startswith; 270, argument_list; 270, 271; 271, string:'/'; 272, block; 272, 273; 272, 285; 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:app; 278, identifier:config; 279, identifier:pop; 280, argument_list; 280, 281; 281, call; 281, 282; 281, 283; 282, identifier:key; 283, argument_list; 283, 284; 284, string:'HOST'; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 295; 287, subscript; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:app; 290, identifier:config; 291, call; 291, 292; 291, 293; 292, identifier:key; 293, argument_list; 293, 294; 294, string:'UNIX_SOCKET_PATH'; 295, identifier:host; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:args; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:self; 302, identifier:_build_connection_args; 303, argument_list; 303, 304; 304, identifier:klass; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 308; 307, identifier:kwargs; 308, call; 308, 309; 308, 310; 309, identifier:dict; 310, argument_list; 310, 311; 311, list_comprehension; 311, 312; 311, 330; 311, 333; 312, tuple; 312, 313; 312, 314; 313, identifier:arg; 314, call; 314, 315; 314, 316; 315, identifier:convert; 316, argument_list; 316, 317; 316, 318; 317, identifier:arg; 318, subscript; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:app; 321, identifier:config; 322, call; 322, 323; 322, 324; 323, identifier:key; 324, argument_list; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:arg; 328, identifier:upper; 329, argument_list; 330, for_in_clause; 330, 331; 330, 332; 331, identifier:arg; 332, identifier:args; 333, if_clause; 333, 334; 334, comparison_operator:in; 334, 335; 334, 343; 335, call; 335, 336; 335, 337; 336, identifier:key; 337, argument_list; 337, 338; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:arg; 341, identifier:upper; 342, argument_list; 343, attribute; 343, 344; 343, 345; 344, identifier:app; 345, identifier:config; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 349; 348, identifier:connection; 349, call; 349, 350; 349, 351; 350, identifier:klass; 351, argument_list; 351, 352; 352, dictionary_splat; 352, 353; 353, identifier:kwargs; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 363; 356, subscript; 356, 357; 356, 362; 357, subscript; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:app; 360, identifier:extensions; 361, string:'redis'; 362, identifier:config_prefix; 363, identifier:connection; 364, expression_statement; 364, 365; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:self; 368, identifier:_include_public_methods; 369, argument_list; 369, 370; 370, identifier:connection | def init_app(self, app, config_prefix=None):
if 'redis' not in app.extensions:
app.extensions['redis'] = {}
self.config_prefix = config_prefix = config_prefix or 'REDIS'
if config_prefix in app.extensions['redis']:
raise ValueError('Already registered config prefix {0!r}.'.
format(config_prefix))
converters = {'port': int}
convert = lambda arg, value: (converters[arg](value)
if arg in converters
else value)
key = lambda param: '{0}_{1}'.format(config_prefix, param)
klass = app.config.get(key('CLASS'), RedisClass)
if isinstance(klass, string_types):
klass = import_string(klass)
url = app.config.get(key('URL'))
if url:
urlparse.uses_netloc.append('redis')
url = urlparse.urlparse(url)
app.config[key('HOST')] = url.hostname
app.config[key('PORT')] = url.port or 6379
app.config[key('USER')] = url.username
app.config[key('PASSWORD')] = url.password
db = url.path.replace('/', '')
app.config[key('DB')] = db if db.isdigit() else None
host = app.config.get(key('HOST'))
if host and (host.startswith('file://') or host.startswith('/')):
app.config.pop(key('HOST'))
app.config[key('UNIX_SOCKET_PATH')] = host
args = self._build_connection_args(klass)
kwargs = dict([(arg, convert(arg, app.config[key(arg.upper())]))
for arg in args
if key(arg.upper()) in app.config])
connection = klass(**kwargs)
app.extensions['redis'][config_prefix] = connection
self._include_public_methods(connection) |
0, module; 0, 1; 1, ERROR; 1, 2; 1, 348; 2, function_definition; 2, 3; 2, 4; 2, 6; 3, function_name:__setup_native_run; 4, parameters; 4, 5; 5, identifier:self; 6, block; 6, 7; 6, 14; 6, 29; 6, 59; 6, 72; 6, 84; 6, 97; 6, 121; 6, 150; 6, 163; 6, 165; 6, 217; 6, 229; 6, 235; 6, 301; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:vol_opts; 12, list:['z']; 12, 13; 13, string:'z'; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:add_env; 19, argument_list; 19, 20; 19, 21; 20, string:'SCUBAINIT_UMASK'; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, string:'{:04o}'; 24, identifier:format; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:get_umask; 28, argument_list; 29, if_statement; 29, 30; 29, 34; 30, not_operator; 30, 31; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:as_root; 34, block; 34, 35; 34, 47; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:add_env; 40, argument_list; 40, 41; 40, 42; 41, string:'SCUBAINIT_UID'; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:os; 45, identifier:getuid; 46, argument_list; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:add_env; 52, argument_list; 52, 53; 52, 54; 53, string:'SCUBAINIT_GID'; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:os; 57, identifier:getgid; 58, argument_list; 59, if_statement; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:verbose; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:add_env; 69, argument_list; 69, 70; 69, 71; 70, string:'SCUBAINIT_VERBOSE'; 71, integer:1; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:scubainit_cpath; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:copy_scubadir_file; 79, argument_list; 79, 80; 79, 81; 80, string:'scubainit'; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:scubainit_path; 84, for_statement; 84, 85; 84, 86; 84, 89; 85, identifier:name; 86, tuple; 86, 87; 86, 88; 87, string:'root'; 88, string:'user'; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:__generate_hook_script; 95, argument_list; 95, 96; 96, identifier:name; 97, if_statement; 97, 98; 97, 113; 98, boolean_operator:and; 98, 99; 98, 106; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:sys; 103, identifier:stdout; 104, identifier:isatty; 105, argument_list; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:sys; 110, identifier:stdin; 111, identifier:isatty; 112, argument_list; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:add_option; 119, argument_list; 119, 120; 120, string:'--tty'; 121, try_statement; 121, 122; 121, 136; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:context; 126, call; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:config; 131, identifier:process_command; 132, argument_list; 132, 133; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:user_command; 136, except_clause; 136, 137; 136, 141; 137, as_pattern; 137, 138; 137, 139; 138, identifier:ConfigError; 139, as_pattern_target; 139, 140; 140, identifier:cfgerr; 141, block; 141, 142; 142, raise_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:ScubaError; 145, argument_list; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:str; 148, argument_list; 148, 149; 149, identifier:cfgerr; 150, if_statement; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:image_override; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:context; 159, identifier:image; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:image_override; 163, expression_statement; 163, 164; 164, string:'''
Normally, if the user provides no command to "docker run", the image's
default CMD is run. Because we set the entrypiont, scuba must emulate the
default behavior itself.
'''; 165, if_statement; 165, 166; 165, 170; 166, not_operator; 166, 167; 167, attribute; 167, 168; 167, 169; 168, identifier:context; 169, identifier:script; 170, block; 170, 171; 170, 176; 170, 185; 170, 194; 170, 207; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 174; 173, identifier:verbose_msg; 174, argument_list; 174, 175; 175, string:'No user command; getting command from image'; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:default_cmd; 179, call; 179, 180; 179, 181; 180, identifier:get_image_command; 181, argument_list; 181, 182; 182, attribute; 182, 183; 182, 184; 183, identifier:context; 184, identifier:image; 185, if_statement; 185, 186; 185, 188; 186, not_operator; 186, 187; 187, identifier:default_cmd; 188, block; 188, 189; 189, raise_statement; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:ScubaError; 192, argument_list; 192, 193; 193, string:'No command given and no image-specified command'; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:verbose_msg; 197, argument_list; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, string:'{} Cmd: "{}"'; 201, identifier:format; 202, argument_list; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:context; 205, identifier:image; 206, identifier:default_cmd; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:context; 211, identifier:script; 212, list:[shell_quote_cmd(default_cmd)]; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:shell_quote_cmd; 215, argument_list; 215, 216; 216, identifier:default_cmd; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:add_option; 222, argument_list; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, string:'--entrypoint={}'; 226, identifier:format; 227, argument_list; 227, 228; 228, identifier:scubainit_cpath; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:docker_cmd; 234, list:[]; 235, if_statement; 235, 236; 235, 241; 235, 258; 235, 281; 236, comparison_operator:is; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:entrypoint_override; 240, None; 241, block; 241, 242; 242, if_statement; 242, 243; 242, 248; 243, comparison_operator:!=; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:entrypoint_override; 247, string:''; 248, block; 248, 249; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:docker_cmd; 254, list:[self.entrypoint_override]; 254, 255; 255, attribute; 255, 256; 255, 257; 256, identifier:self; 257, identifier:entrypoint_override; 258, elif_clause; 258, 259; 258, 264; 259, comparison_operator:is; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:context; 262, identifier:entrypoint; 263, None; 264, block; 264, 265; 265, if_statement; 265, 266; 265, 271; 266, comparison_operator:!=; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:context; 269, identifier:entrypoint; 270, string:''; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:docker_cmd; 277, list:[context.entrypoint]; 277, 278; 278, attribute; 278, 279; 278, 280; 279, identifier:context; 280, identifier:entrypoint; 281, else_clause; 281, 282; 282, block; 282, 283; 282, 292; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:ep; 286, call; 286, 287; 286, 288; 287, identifier:get_image_entrypoint; 288, argument_list; 288, 289; 289, attribute; 289, 290; 289, 291; 290, identifier:context; 291, identifier:image; 292, if_statement; 292, 293; 292, 294; 293, identifier:ep; 294, block; 294, 295; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:self; 299, identifier:docker_cmd; 300, identifier:ep; 301, with_statement; 301, 302; 301, 314; 301, 341; 302, with_clause; 302, 303; 303, with_item; 303, 304; 304, as_pattern; 304, 305; 304, 312; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:self; 308, identifier:open_scubadir_file; 309, argument_list; 309, 310; 309, 311; 310, string:'command.sh'; 311, string:'wt'; 312, as_pattern_target; 312, 313; 313, identifier:f; 314, ERROR; 314, 315; 314, 325; 314, 326; 314, 327; 315, expression_statement; 315, 316; 316, augmented_assignment:+=; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:self; 319, identifier:docker_cmd; 320, list:['/bin/sh', f.container_path]; 320, 321; 320, 322; 321, string:'/bin/sh'; 322, attribute; 322, 323; 322, 324; 323, identifier:f; 324, identifier:container_path; 325, identifier:writeln; 326, identifier:f; 327, comparison_operator:in; 327, 328; 327, 335; 327, 338; 328, call; 328, 329; 328, 330; 328, 332; 329, string:'
writeln(f, '; 330, ERROR; 330, 331; 331, identifier:writeln; 332, argument_list; 332, 333; 332, 334; 333, identifier:f; 334, string:'set -e'; 335, ERROR; 335, 336; 335, 337; 336, identifier:for; 337, identifier:cmd; 338, attribute; 338, 339; 338, 340; 339, identifier:context; 340, identifier:script; 341, block; 341, 342; 342, expression_statement; 342, 343; 343, call; 343, 344; 343, 345; 344, identifier:writeln; 345, argument_list; 345, 346; 345, 347; 346, identifier:f; 347, identifier:cmd; 348, expression_statement; 348, 349; 349, assignment; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:self; 352, identifier:context; 353, identifier:context | def __setup_native_run(self):
self.vol_opts = ['z']
self.add_env('SCUBAINIT_UMASK', '{:04o}'.format(get_umask()))
if not self.as_root:
self.add_env('SCUBAINIT_UID', os.getuid())
self.add_env('SCUBAINIT_GID', os.getgid())
if self.verbose:
self.add_env('SCUBAINIT_VERBOSE', 1)
scubainit_cpath = self.copy_scubadir_file('scubainit', self.scubainit_path)
for name in ('root', 'user', ):
self.__generate_hook_script(name)
if sys.stdout.isatty() and sys.stdin.isatty():
self.add_option('--tty')
try:
context = self.config.process_command(self.user_command)
except ConfigError as cfgerr:
raise ScubaError(str(cfgerr))
if self.image_override:
context.image = self.image_override
'''
Normally, if the user provides no command to "docker run", the image's
default CMD is run. Because we set the entrypiont, scuba must emulate the
default behavior itself.
'''
if not context.script:
verbose_msg('No user command; getting command from image')
default_cmd = get_image_command(context.image)
if not default_cmd:
raise ScubaError('No command given and no image-specified command')
verbose_msg('{} Cmd: "{}"'.format(context.image, default_cmd))
context.script = [shell_quote_cmd(default_cmd)]
self.add_option('--entrypoint={}'.format(scubainit_cpath))
self.docker_cmd = []
if self.entrypoint_override is not None:
if self.entrypoint_override != '':
self.docker_cmd = [self.entrypoint_override]
elif context.entrypoint is not None:
if context.entrypoint != '':
self.docker_cmd = [context.entrypoint]
else:
ep = get_image_entrypoint(context.image)
if ep:
self.docker_cmd = ep
with self.open_scubadir_file('command.sh', 'wt') as f:
self.docker_cmd += ['/bin/sh', f.container_path]
writeln(f, '
writeln(f, '
writeln(f, 'set -e')
for cmd in context.script:
writeln(f, cmd)
self.context = context |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 18; 2, function_name:sort; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:records; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Sequence; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:Record; 12, type; 12, 13; 13, generic_type; 13, 14; 13, 15; 14, identifier:List; 15, type_parameter; 15, 16; 16, type; 16, 17; 17, identifier:Record; 18, block; 18, 19; 18, 21; 19, expression_statement; 19, 20; 20, string:"Sort records into a canonical order, suitable for comparison."; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:sorted; 24, argument_list; 24, 25; 24, 26; 25, identifier:records; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:key; 28, identifier:_record_key | def sort(records: Sequence[Record]) -> List[Record]:
"Sort records into a canonical order, suitable for comparison."
return sorted(records, key=_record_key) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_issubclass_Mapping_covariant; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:subclass; 5, identifier:superclass; 6, identifier:bound_Generic; 7, identifier:bound_typevars; 8, identifier:bound_typevars_readonly; 9, identifier:follow_fwd_refs; 10, identifier:_recursion_check; 11, block; 11, 12; 11, 173; 12, if_statement; 12, 13; 12, 17; 13, call; 13, 14; 13, 15; 14, identifier:is_Generic; 15, argument_list; 15, 16; 16, identifier:subclass; 17, block; 17, 18; 17, 45; 17, 89; 17, 133; 17, 152; 17, 171; 18, if_statement; 18, 19; 18, 33; 19, boolean_operator:or; 19, 20; 19, 25; 20, comparison_operator:is; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:subclass; 23, identifier:__origin__; 24, None; 25, not_operator; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:issubclass; 28, argument_list; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:subclass; 31, identifier:__origin__; 32, identifier:Mapping; 33, block; 33, 34; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:_issubclass_Generic; 37, argument_list; 37, 38; 37, 39; 37, 40; 37, 41; 37, 42; 37, 43; 37, 44; 38, identifier:subclass; 39, identifier:superclass; 40, identifier:bound_Generic; 41, identifier:bound_typevars; 42, identifier:bound_typevars_readonly; 43, identifier:follow_fwd_refs; 44, identifier:_recursion_check; 45, if_statement; 45, 46; 45, 51; 45, 81; 46, comparison_operator:is; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:superclass; 49, identifier:__args__; 50, None; 51, block; 51, 52; 51, 68; 51, 75; 52, if_statement; 52, 53; 52, 57; 53, not_operator; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:pytypes; 56, identifier:check_unbound_types; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:TypeError; 61, argument_list; 61, 62; 62, binary_operator:+; 62, 63; 62, 64; 63, string:"Attempted to check unbound mapping type(superclass): "; 64, call; 64, 65; 64, 66; 65, identifier:str; 66, argument_list; 66, 67; 67, identifier:superclass; 68, if_statement; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:pytypes; 71, identifier:strict_unknown_check; 72, block; 72, 73; 73, return_statement; 73, 74; 74, False; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:super_args; 78, tuple; 78, 79; 78, 80; 79, identifier:Any; 80, identifier:Any; 81, else_clause; 81, 82; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:super_args; 86, attribute; 86, 87; 86, 88; 87, identifier:superclass; 88, identifier:__args__; 89, if_statement; 89, 90; 89, 95; 89, 125; 90, comparison_operator:is; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:subclass; 93, identifier:__args__; 94, None; 95, block; 95, 96; 95, 112; 95, 119; 96, if_statement; 96, 97; 96, 101; 97, not_operator; 97, 98; 98, attribute; 98, 99; 98, 100; 99, identifier:pytypes; 100, identifier:check_unbound_types; 101, block; 101, 102; 102, raise_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:TypeError; 105, argument_list; 105, 106; 106, binary_operator:+; 106, 107; 106, 108; 107, string:"Attempted to check unbound mapping type(subclass): "; 108, call; 108, 109; 108, 110; 109, identifier:str; 110, argument_list; 110, 111; 111, identifier:subclass; 112, if_statement; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:pytypes; 115, identifier:strict_unknown_check; 116, block; 116, 117; 117, return_statement; 117, 118; 118, False; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:sub_args; 122, tuple; 122, 123; 122, 124; 123, identifier:Any; 124, identifier:Any; 125, else_clause; 125, 126; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:sub_args; 130, attribute; 130, 131; 130, 132; 131, identifier:subclass; 132, identifier:__args__; 133, if_statement; 133, 134; 133, 149; 134, not_operator; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:_issubclass; 137, argument_list; 137, 138; 137, 141; 137, 144; 137, 145; 137, 146; 137, 147; 137, 148; 138, subscript; 138, 139; 138, 140; 139, identifier:sub_args; 140, integer:0; 141, subscript; 141, 142; 141, 143; 142, identifier:super_args; 143, integer:0; 144, identifier:bound_Generic; 145, identifier:bound_typevars; 146, identifier:bound_typevars_readonly; 147, identifier:follow_fwd_refs; 148, identifier:_recursion_check; 149, block; 149, 150; 150, return_statement; 150, 151; 151, False; 152, if_statement; 152, 153; 152, 168; 153, not_operator; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:_issubclass; 156, argument_list; 156, 157; 156, 160; 156, 163; 156, 164; 156, 165; 156, 166; 156, 167; 157, subscript; 157, 158; 157, 159; 158, identifier:sub_args; 159, integer:1; 160, subscript; 160, 161; 160, 162; 161, identifier:super_args; 162, integer:1; 163, identifier:bound_Generic; 164, identifier:bound_typevars; 165, identifier:bound_typevars_readonly; 166, identifier:follow_fwd_refs; 167, identifier:_recursion_check; 168, block; 168, 169; 169, return_statement; 169, 170; 170, False; 171, return_statement; 171, 172; 172, True; 173, return_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:issubclass; 176, argument_list; 176, 177; 176, 178; 177, identifier:subclass; 178, identifier:superclass | def _issubclass_Mapping_covariant(subclass, superclass, bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check):
if is_Generic(subclass):
if subclass.__origin__ is None or not issubclass(subclass.__origin__, Mapping):
return _issubclass_Generic(subclass, superclass, bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check)
if superclass.__args__ is None:
if not pytypes.check_unbound_types:
raise TypeError("Attempted to check unbound mapping type(superclass): "+
str(superclass))
if pytypes.strict_unknown_check:
return False
super_args = (Any, Any)
else:
super_args = superclass.__args__
if subclass.__args__ is None:
if not pytypes.check_unbound_types:
raise TypeError("Attempted to check unbound mapping type(subclass): "+
str(subclass))
if pytypes.strict_unknown_check:
return False
sub_args = (Any, Any)
else:
sub_args = subclass.__args__
if not _issubclass(sub_args[0], super_args[0],
bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check):
return False
if not _issubclass(sub_args[1], super_args[1],
bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check):
return False
return True
return issubclass(subclass, superclass) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:_isinstance; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:obj; 5, identifier:cls; 6, default_parameter; 6, 7; 6, 8; 7, identifier:bound_Generic; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:bound_typevars; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:bound_typevars_readonly; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:follow_fwd_refs; 17, True; 18, default_parameter; 18, 19; 18, 20; 19, identifier:_recursion_check; 20, None; 21, block; 21, 22; 21, 31; 21, 88; 21, 105; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:is; 23, 24; 23, 25; 24, identifier:bound_typevars; 25, None; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:bound_typevars; 30, dictionary; 31, if_statement; 31, 32; 31, 44; 32, boolean_operator:and; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:is_Generic; 35, argument_list; 35, 36; 36, identifier:cls; 37, comparison_operator:is; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:cls; 40, identifier:__origin__; 41, attribute; 41, 42; 41, 43; 42, identifier:typing; 43, identifier:Iterable; 44, block; 44, 45; 44, 54; 44, 61; 45, if_statement; 45, 46; 45, 51; 46, not_operator; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:is_iterable; 49, argument_list; 49, 50; 50, identifier:obj; 51, block; 51, 52; 52, return_statement; 52, 53; 53, False; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:itp; 57, call; 57, 58; 57, 59; 58, identifier:get_iterable_itemtype; 59, argument_list; 59, 60; 60, identifier:obj; 61, if_statement; 61, 62; 61, 65; 61, 71; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:itp; 64, None; 65, block; 65, 66; 66, return_statement; 66, 67; 67, not_operator; 67, 68; 68, attribute; 68, 69; 68, 70; 69, identifier:pytypes; 70, identifier:check_iterables; 71, else_clause; 71, 72; 72, block; 72, 73; 73, return_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:_issubclass; 76, argument_list; 76, 77; 76, 78; 76, 83; 76, 84; 76, 85; 76, 86; 76, 87; 77, identifier:itp; 78, subscript; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:cls; 81, identifier:__args__; 82, integer:0; 83, identifier:bound_Generic; 84, identifier:bound_typevars; 85, identifier:bound_typevars_readonly; 86, identifier:follow_fwd_refs; 87, identifier:_recursion_check; 88, if_statement; 88, 89; 88, 93; 89, call; 89, 90; 89, 91; 90, identifier:is_Callable; 91, argument_list; 91, 92; 92, identifier:cls; 93, block; 93, 94; 94, return_statement; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:_isinstance_Callable; 97, argument_list; 97, 98; 97, 99; 97, 100; 97, 101; 97, 102; 97, 103; 97, 104; 98, identifier:obj; 99, identifier:cls; 100, identifier:bound_Generic; 101, identifier:bound_typevars; 102, identifier:bound_typevars_readonly; 103, identifier:follow_fwd_refs; 104, identifier:_recursion_check; 105, return_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:_issubclass; 108, argument_list; 108, 109; 108, 113; 108, 114; 108, 115; 108, 116; 108, 117; 108, 118; 109, call; 109, 110; 109, 111; 110, identifier:deep_type; 111, argument_list; 111, 112; 112, identifier:obj; 113, identifier:cls; 114, identifier:bound_Generic; 115, identifier:bound_typevars; 116, identifier:bound_typevars_readonly; 117, identifier:follow_fwd_refs; 118, identifier:_recursion_check | def _isinstance(obj, cls, bound_Generic=None, bound_typevars=None,
bound_typevars_readonly=False, follow_fwd_refs=True, _recursion_check=None):
if bound_typevars is None:
bound_typevars = {}
if is_Generic(cls) and cls.__origin__ is typing.Iterable:
if not is_iterable(obj):
return False
itp = get_iterable_itemtype(obj)
if itp is None:
return not pytypes.check_iterables
else:
return _issubclass(itp, cls.__args__[0], bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check)
if is_Callable(cls):
return _isinstance_Callable(obj, cls, bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check)
return _issubclass(deep_type(obj), cls, bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:typelogged_module; 3, parameters; 3, 4; 4, identifier:md; 5, block; 5, 6; 5, 14; 5, 67; 5, 73; 5, 99; 5, 105; 5, 128; 5, 138; 5, 193; 5, 218; 6, if_statement; 6, 7; 6, 11; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:pytypes; 10, identifier:typelogging_enabled; 11, block; 11, 12; 12, return_statement; 12, 13; 13, identifier:md; 14, if_statement; 14, 15; 14, 20; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:md; 19, identifier:str; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 27; 21, 43; 22, comparison_operator:in; 22, 23; 22, 24; 23, identifier:md; 24, attribute; 24, 25; 24, 26; 25, identifier:sys; 26, identifier:modules; 27, block; 27, 28; 27, 36; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:md; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:sys; 34, identifier:modules; 35, identifier:md; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:md; 39, None; 40, block; 40, 41; 41, return_statement; 41, 42; 42, identifier:md; 43, elif_clause; 43, 44; 43, 51; 44, comparison_operator:in; 44, 45; 44, 46; 45, identifier:md; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:pytypes; 49, identifier:typechecker; 50, identifier:_pending_modules; 51, block; 51, 52; 51, 65; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 63; 54, attribute; 54, 55; 54, 62; 55, subscript; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:pytypes; 59, identifier:typechecker; 60, identifier:_pending_modules; 61, identifier:md; 62, identifier:append; 63, argument_list; 63, 64; 64, identifier:typelogged_module; 65, return_statement; 65, 66; 66, identifier:md; 67, assert_statement; 67, 68; 68, parenthesized_expression; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:ismodule; 71, argument_list; 71, 72; 72, identifier:md; 73, if_statement; 73, 74; 73, 83; 74, comparison_operator:in; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:md; 77, identifier:__name__; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:pytypes; 81, identifier:typechecker; 82, identifier:_pending_modules; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 97; 86, attribute; 86, 87; 86, 96; 87, subscript; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:pytypes; 91, identifier:typechecker; 92, identifier:_pending_modules; 93, attribute; 93, 94; 93, 95; 94, identifier:md; 95, identifier:__name__; 96, identifier:append; 97, argument_list; 97, 98; 98, identifier:typelogged_module; 99, assert_statement; 99, 100; 100, parenthesized_expression; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:ismodule; 103, argument_list; 103, 104; 104, identifier:md; 105, if_statement; 105, 106; 105, 125; 106, boolean_operator:and; 106, 107; 106, 112; 106, 113; 107, comparison_operator:in; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:md; 110, identifier:__name__; 111, identifier:_fully_typelogged_modules; 112, line_continuation:\; 113, comparison_operator:==; 113, 114; 113, 119; 114, subscript; 114, 115; 114, 116; 115, identifier:_fully_typelogged_modules; 116, attribute; 116, 117; 116, 118; 117, identifier:md; 118, identifier:__name__; 119, call; 119, 120; 119, 121; 120, identifier:len; 121, argument_list; 121, 122; 122, attribute; 122, 123; 122, 124; 123, identifier:md; 124, identifier:__dict__; 125, block; 125, 126; 126, return_statement; 126, 127; 127, identifier:md; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:keys; 131, list_comprehension; 131, 132; 131, 133; 132, identifier:key; 133, for_in_clause; 133, 134; 133, 135; 134, identifier:key; 135, attribute; 135, 136; 135, 137; 136, identifier:md; 137, identifier:__dict__; 138, for_statement; 138, 139; 138, 140; 138, 141; 139, identifier:key; 140, identifier:keys; 141, block; 141, 142; 141, 150; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:memb; 145, subscript; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:md; 148, identifier:__dict__; 149, identifier:key; 150, if_statement; 150, 151; 150, 163; 150, 174; 151, boolean_operator:and; 151, 152; 151, 156; 152, call; 152, 153; 152, 154; 153, identifier:_check_as_func; 154, argument_list; 154, 155; 155, identifier:memb; 156, comparison_operator:==; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:memb; 159, identifier:__module__; 160, attribute; 160, 161; 160, 162; 161, identifier:md; 162, identifier:__name__; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:setattr; 167, argument_list; 167, 168; 167, 169; 167, 170; 168, identifier:md; 169, identifier:key; 170, call; 170, 171; 170, 172; 171, identifier:typelogged_func; 172, argument_list; 172, 173; 173, identifier:memb; 174, elif_clause; 174, 175; 174, 187; 175, boolean_operator:and; 175, 176; 175, 180; 176, call; 176, 177; 176, 178; 177, identifier:isclass; 178, argument_list; 178, 179; 179, identifier:memb; 180, comparison_operator:==; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:memb; 183, identifier:__module__; 184, attribute; 184, 185; 184, 186; 185, identifier:md; 186, identifier:__name__; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 191; 190, identifier:typelogged_class; 191, argument_list; 191, 192; 192, identifier:memb; 193, if_statement; 193, 194; 193, 204; 194, not_operator; 194, 195; 195, comparison_operator:in; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:md; 198, identifier:__name__; 199, attribute; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:pytypes; 202, identifier:typechecker; 203, identifier:_pending_modules; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 212; 207, subscript; 207, 208; 207, 209; 208, identifier:_fully_typelogged_modules; 209, attribute; 209, 210; 209, 211; 210, identifier:md; 211, identifier:__name__; 212, call; 212, 213; 212, 214; 213, identifier:len; 214, argument_list; 214, 215; 215, attribute; 215, 216; 215, 217; 216, identifier:md; 217, identifier:__dict__; 218, return_statement; 218, 219; 219, identifier:md | def typelogged_module(md):
if not pytypes.typelogging_enabled:
return md
if isinstance(md, str):
if md in sys.modules:
md = sys.modules[md]
if md is None:
return md
elif md in pytypes.typechecker._pending_modules:
pytypes.typechecker._pending_modules[md].append(typelogged_module)
return md
assert(ismodule(md))
if md.__name__ in pytypes.typechecker._pending_modules:
pytypes.typechecker._pending_modules[md.__name__].append(typelogged_module)
assert(ismodule(md))
if md.__name__ in _fully_typelogged_modules and \
_fully_typelogged_modules[md.__name__] == len(md.__dict__):
return md
keys = [key for key in md.__dict__]
for key in keys:
memb = md.__dict__[key]
if _check_as_func(memb) and memb.__module__ == md.__name__:
setattr(md, key, typelogged_func(memb))
elif isclass(memb) and memb.__module__ == md.__name__:
typelogged_class(memb)
if not md.__name__ in pytypes.typechecker._pending_modules:
_fully_typelogged_modules[md.__name__] = len(md.__dict__)
return md |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:import_process_elements; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:document; 5, identifier:diagram_graph; 6, identifier:sequence_flows; 7, identifier:process_elements_dict; 8, identifier:plane_element; 9, block; 9, 10; 10, for_statement; 10, 11; 10, 12; 10, 23; 11, identifier:process_element; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:document; 15, identifier:getElementsByTagNameNS; 16, argument_list; 16, 17; 16, 18; 17, string:"*"; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:consts; 21, identifier:Consts; 22, identifier:process; 23, block; 23, 24; 23, 32; 23, 45; 23, 51; 23, 65; 23, 92; 23, 137; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:BpmnDiagramGraphImport; 28, identifier:import_process_element; 29, argument_list; 29, 30; 29, 31; 30, identifier:process_elements_dict; 31, identifier:process_element; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:process_id; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:process_element; 38, identifier:getAttribute; 39, argument_list; 39, 40; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:consts; 43, identifier:Consts; 44, identifier:id; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:process_attributes; 48, subscript; 48, 49; 48, 50; 49, identifier:process_elements_dict; 50, identifier:process_id; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:lane_set_list; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:process_element; 57, identifier:getElementsByTagNameNS; 58, argument_list; 58, 59; 58, 60; 59, string:"*"; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:consts; 63, identifier:Consts; 64, identifier:lane_set; 65, if_statement; 65, 66; 65, 76; 66, boolean_operator:and; 66, 67; 66, 70; 67, comparison_operator:is; 67, 68; 67, 69; 68, identifier:lane_set_list; 69, None; 70, comparison_operator:>; 70, 71; 70, 75; 71, call; 71, 72; 71, 73; 72, identifier:len; 73, argument_list; 73, 74; 74, identifier:lane_set_list; 75, integer:0; 76, block; 76, 77; 76, 83; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:lane_set; 80, subscript; 80, 81; 80, 82; 81, identifier:lane_set_list; 82, integer:0; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:BpmnDiagramGraphImport; 87, identifier:import_lane_set_element; 88, argument_list; 88, 89; 88, 90; 88, 91; 89, identifier:process_attributes; 90, identifier:lane_set; 91, identifier:plane_element; 92, for_statement; 92, 93; 92, 94; 92, 102; 93, identifier:element; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:utils; 98, identifier:BpmnImportUtils; 99, identifier:iterate_elements; 100, argument_list; 100, 101; 101, identifier:process_element; 102, block; 102, 103; 103, if_statement; 103, 104; 103, 111; 104, comparison_operator:!=; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:element; 107, identifier:nodeType; 108, attribute; 108, 109; 108, 110; 109, identifier:element; 110, identifier:TEXT_NODE; 111, block; 111, 112; 111, 125; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:tag_name; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:utils; 119, identifier:BpmnImportUtils; 120, identifier:remove_namespace_from_tag_name; 121, argument_list; 121, 122; 122, attribute; 122, 123; 122, 124; 123, identifier:element; 124, identifier:tagName; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:BpmnDiagramGraphImport; 129, identifier:__import_element_by_tag_name; 130, argument_list; 130, 131; 130, 132; 130, 133; 130, 134; 130, 135; 130, 136; 131, identifier:diagram_graph; 132, identifier:sequence_flows; 133, identifier:process_id; 134, identifier:process_attributes; 135, identifier:element; 136, identifier:tag_name; 137, for_statement; 137, 138; 137, 139; 137, 147; 138, identifier:flow; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:utils; 143, identifier:BpmnImportUtils; 144, identifier:iterate_elements; 145, argument_list; 145, 146; 146, identifier:process_element; 147, block; 147, 148; 148, if_statement; 148, 149; 148, 156; 149, comparison_operator:!=; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:flow; 152, identifier:nodeType; 153, attribute; 153, 154; 153, 155; 154, identifier:flow; 155, identifier:TEXT_NODE; 156, block; 156, 157; 156, 170; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:tag_name; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:utils; 164, identifier:BpmnImportUtils; 165, identifier:remove_namespace_from_tag_name; 166, argument_list; 166, 167; 167, attribute; 167, 168; 167, 169; 168, identifier:flow; 169, identifier:tagName; 170, if_statement; 170, 171; 170, 178; 171, comparison_operator:==; 171, 172; 171, 173; 172, identifier:tag_name; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:consts; 176, identifier:Consts; 177, identifier:sequence_flow; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:BpmnDiagramGraphImport; 183, identifier:import_sequence_flow_to_graph; 184, argument_list; 184, 185; 184, 186; 184, 187; 184, 188; 185, identifier:diagram_graph; 186, identifier:sequence_flows; 187, identifier:process_id; 188, identifier:flow | def import_process_elements(document, diagram_graph, sequence_flows, process_elements_dict, plane_element):
for process_element in document.getElementsByTagNameNS("*", consts.Consts.process):
BpmnDiagramGraphImport.import_process_element(process_elements_dict, process_element)
process_id = process_element.getAttribute(consts.Consts.id)
process_attributes = process_elements_dict[process_id]
lane_set_list = process_element.getElementsByTagNameNS("*", consts.Consts.lane_set)
if lane_set_list is not None and len(lane_set_list) > 0:
lane_set = lane_set_list[0]
BpmnDiagramGraphImport.import_lane_set_element(process_attributes, lane_set, plane_element)
for element in utils.BpmnImportUtils.iterate_elements(process_element):
if element.nodeType != element.TEXT_NODE:
tag_name = utils.BpmnImportUtils.remove_namespace_from_tag_name(element.tagName)
BpmnDiagramGraphImport.__import_element_by_tag_name(diagram_graph, sequence_flows, process_id,
process_attributes, element, tag_name)
for flow in utils.BpmnImportUtils.iterate_elements(process_element):
if flow.nodeType != flow.TEXT_NODE:
tag_name = utils.BpmnImportUtils.remove_namespace_from_tag_name(flow.tagName)
if tag_name == consts.Consts.sequence_flow:
BpmnDiagramGraphImport.import_sequence_flow_to_graph(diagram_graph, sequence_flows, process_id,
flow) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:generate_nodes_clasification; 3, parameters; 3, 4; 4, identifier:bpmn_diagram; 5, block; 5, 6; 5, 10; 5, 14; 5, 18; 5, 22; 5, 35; 5, 53; 5, 66; 5, 84; 5, 97; 5, 115; 5, 128; 5, 146; 5, 159; 5, 177; 5, 190; 5, 208; 5, 221; 5, 239; 5, 252; 5, 271; 5, 284; 5, 302; 5, 315; 5, 334; 5, 347; 5, 365; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:nodes_classification; 9, dictionary; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:classification_element; 13, string:"Element"; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:classification_start_event; 17, string:"Start Event"; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:classification_end_event; 21, string:"End Event"; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:task_list; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:bpmn_diagram; 28, identifier:get_nodes; 29, argument_list; 29, 30; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:consts; 33, identifier:Consts; 34, identifier:task; 35, for_statement; 35, 36; 35, 37; 35, 38; 36, identifier:element; 37, identifier:task_list; 38, block; 38, 39; 38, 44; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:classification_labels; 42, list:[classification_element]; 42, 43; 43, identifier:classification_element; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:BpmnImportUtils; 48, identifier:split_join_classification; 49, argument_list; 49, 50; 49, 51; 49, 52; 50, identifier:element; 51, identifier:classification_labels; 52, identifier:nodes_classification; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:subprocess_list; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:bpmn_diagram; 59, identifier:get_nodes; 60, argument_list; 60, 61; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:consts; 64, identifier:Consts; 65, identifier:subprocess; 66, for_statement; 66, 67; 66, 68; 66, 69; 67, identifier:element; 68, identifier:subprocess_list; 69, block; 69, 70; 69, 75; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:classification_labels; 73, list:[classification_element]; 73, 74; 74, identifier:classification_element; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:BpmnImportUtils; 79, identifier:split_join_classification; 80, argument_list; 80, 81; 80, 82; 80, 83; 81, identifier:element; 82, identifier:classification_labels; 83, identifier:nodes_classification; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:complex_gateway_list; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:bpmn_diagram; 90, identifier:get_nodes; 91, argument_list; 91, 92; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:consts; 95, identifier:Consts; 96, identifier:complex_gateway; 97, for_statement; 97, 98; 97, 99; 97, 100; 98, identifier:element; 99, identifier:complex_gateway_list; 100, block; 100, 101; 100, 106; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:classification_labels; 104, list:[classification_element]; 104, 105; 105, identifier:classification_element; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:BpmnImportUtils; 110, identifier:split_join_classification; 111, argument_list; 111, 112; 111, 113; 111, 114; 112, identifier:element; 113, identifier:classification_labels; 114, identifier:nodes_classification; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:event_based_gateway_list; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:bpmn_diagram; 121, identifier:get_nodes; 122, argument_list; 122, 123; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:consts; 126, identifier:Consts; 127, identifier:event_based_gateway; 128, for_statement; 128, 129; 128, 130; 128, 131; 129, identifier:element; 130, identifier:event_based_gateway_list; 131, block; 131, 132; 131, 137; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:classification_labels; 135, list:[classification_element]; 135, 136; 136, identifier:classification_element; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:BpmnImportUtils; 141, identifier:split_join_classification; 142, argument_list; 142, 143; 142, 144; 142, 145; 143, identifier:element; 144, identifier:classification_labels; 145, identifier:nodes_classification; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:inclusive_gateway_list; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:bpmn_diagram; 152, identifier:get_nodes; 153, argument_list; 153, 154; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:consts; 157, identifier:Consts; 158, identifier:inclusive_gateway; 159, for_statement; 159, 160; 159, 161; 159, 162; 160, identifier:element; 161, identifier:inclusive_gateway_list; 162, block; 162, 163; 162, 168; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:classification_labels; 166, list:[classification_element]; 166, 167; 167, identifier:classification_element; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:BpmnImportUtils; 172, identifier:split_join_classification; 173, argument_list; 173, 174; 173, 175; 173, 176; 174, identifier:element; 175, identifier:classification_labels; 176, identifier:nodes_classification; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:exclusive_gateway_list; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:bpmn_diagram; 183, identifier:get_nodes; 184, argument_list; 184, 185; 185, attribute; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:consts; 188, identifier:Consts; 189, identifier:exclusive_gateway; 190, for_statement; 190, 191; 190, 192; 190, 193; 191, identifier:element; 192, identifier:exclusive_gateway_list; 193, block; 193, 194; 193, 199; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:classification_labels; 197, list:[classification_element]; 197, 198; 198, identifier:classification_element; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:BpmnImportUtils; 203, identifier:split_join_classification; 204, argument_list; 204, 205; 204, 206; 204, 207; 205, identifier:element; 206, identifier:classification_labels; 207, identifier:nodes_classification; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:parallel_gateway_list; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:bpmn_diagram; 214, identifier:get_nodes; 215, argument_list; 215, 216; 216, attribute; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:consts; 219, identifier:Consts; 220, identifier:parallel_gateway; 221, for_statement; 221, 222; 221, 223; 221, 224; 222, identifier:element; 223, identifier:parallel_gateway_list; 224, block; 224, 225; 224, 230; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:classification_labels; 228, list:[classification_element]; 228, 229; 229, identifier:classification_element; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:BpmnImportUtils; 234, identifier:split_join_classification; 235, argument_list; 235, 236; 235, 237; 235, 238; 236, identifier:element; 237, identifier:classification_labels; 238, identifier:nodes_classification; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:start_event_list; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:bpmn_diagram; 245, identifier:get_nodes; 246, argument_list; 246, 247; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:consts; 250, identifier:Consts; 251, identifier:start_event; 252, for_statement; 252, 253; 252, 254; 252, 255; 253, identifier:element; 254, identifier:start_event_list; 255, block; 255, 256; 255, 262; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:classification_labels; 259, list:[classification_element, classification_start_event]; 259, 260; 259, 261; 260, identifier:classification_element; 261, identifier:classification_start_event; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:BpmnImportUtils; 266, identifier:split_join_classification; 267, argument_list; 267, 268; 267, 269; 267, 270; 268, identifier:element; 269, identifier:classification_labels; 270, identifier:nodes_classification; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:intermediate_catch_event_list; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:bpmn_diagram; 277, identifier:get_nodes; 278, argument_list; 278, 279; 279, attribute; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:consts; 282, identifier:Consts; 283, identifier:intermediate_catch_event; 284, for_statement; 284, 285; 284, 286; 284, 287; 285, identifier:element; 286, identifier:intermediate_catch_event_list; 287, block; 287, 288; 287, 293; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:classification_labels; 291, list:[classification_element]; 291, 292; 292, identifier:classification_element; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:BpmnImportUtils; 297, identifier:split_join_classification; 298, argument_list; 298, 299; 298, 300; 298, 301; 299, identifier:element; 300, identifier:classification_labels; 301, identifier:nodes_classification; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:end_event_list; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:bpmn_diagram; 308, identifier:get_nodes; 309, argument_list; 309, 310; 310, attribute; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:consts; 313, identifier:Consts; 314, identifier:end_event; 315, for_statement; 315, 316; 315, 317; 315, 318; 316, identifier:element; 317, identifier:end_event_list; 318, block; 318, 319; 318, 325; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 322; 321, identifier:classification_labels; 322, list:[classification_element, classification_end_event]; 322, 323; 322, 324; 323, identifier:classification_element; 324, identifier:classification_end_event; 325, expression_statement; 325, 326; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:BpmnImportUtils; 329, identifier:split_join_classification; 330, argument_list; 330, 331; 330, 332; 330, 333; 331, identifier:element; 332, identifier:classification_labels; 333, identifier:nodes_classification; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 337; 336, identifier:intermediate_throw_event_list; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:bpmn_diagram; 340, identifier:get_nodes; 341, argument_list; 341, 342; 342, attribute; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:consts; 345, identifier:Consts; 346, identifier:intermediate_throw_event; 347, for_statement; 347, 348; 347, 349; 347, 350; 348, identifier:element; 349, identifier:intermediate_throw_event_list; 350, block; 350, 351; 350, 356; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 354; 353, identifier:classification_labels; 354, list:[classification_element]; 354, 355; 355, identifier:classification_element; 356, expression_statement; 356, 357; 357, call; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:BpmnImportUtils; 360, identifier:split_join_classification; 361, argument_list; 361, 362; 361, 363; 361, 364; 362, identifier:element; 363, identifier:classification_labels; 364, identifier:nodes_classification; 365, return_statement; 365, 366; 366, identifier:nodes_classification | def generate_nodes_clasification(bpmn_diagram):
nodes_classification = {}
classification_element = "Element"
classification_start_event = "Start Event"
classification_end_event = "End Event"
task_list = bpmn_diagram.get_nodes(consts.Consts.task)
for element in task_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
subprocess_list = bpmn_diagram.get_nodes(consts.Consts.subprocess)
for element in subprocess_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
complex_gateway_list = bpmn_diagram.get_nodes(consts.Consts.complex_gateway)
for element in complex_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
event_based_gateway_list = bpmn_diagram.get_nodes(consts.Consts.event_based_gateway)
for element in event_based_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
inclusive_gateway_list = bpmn_diagram.get_nodes(consts.Consts.inclusive_gateway)
for element in inclusive_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
exclusive_gateway_list = bpmn_diagram.get_nodes(consts.Consts.exclusive_gateway)
for element in exclusive_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
parallel_gateway_list = bpmn_diagram.get_nodes(consts.Consts.parallel_gateway)
for element in parallel_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
start_event_list = bpmn_diagram.get_nodes(consts.Consts.start_event)
for element in start_event_list:
classification_labels = [classification_element, classification_start_event]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
intermediate_catch_event_list = bpmn_diagram.get_nodes(consts.Consts.intermediate_catch_event)
for element in intermediate_catch_event_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
end_event_list = bpmn_diagram.get_nodes(consts.Consts.end_event)
for element in end_event_list:
classification_labels = [classification_element, classification_end_event]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
intermediate_throw_event_list = bpmn_diagram.get_nodes(consts.Consts.intermediate_throw_event)
for element in intermediate_throw_event_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
return nodes_classification |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:hclust_linearize; 3, parameters; 3, 4; 4, identifier:U; 5, block; 5, 6; 5, 12; 5, 21; 6, import_from_statement; 6, 7; 6, 10; 7, dotted_name; 7, 8; 7, 9; 8, identifier:scipy; 9, identifier:cluster; 10, dotted_name; 10, 11; 11, identifier:hierarchy; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:Z; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:hierarchy; 18, identifier:ward; 19, argument_list; 19, 20; 20, identifier:U; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:hierarchy; 25, identifier:leaves_list; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:hierarchy; 30, identifier:optimal_leaf_ordering; 31, argument_list; 31, 32; 31, 33; 32, identifier:Z; 33, identifier:U | def hclust_linearize(U):
from scipy.cluster import hierarchy
Z = hierarchy.ward(U)
return hierarchy.leaves_list(hierarchy.optimal_leaf_ordering(Z, U)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:kruskal_align; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:U; 5, identifier:V; 6, default_parameter; 6, 7; 6, 8; 7, identifier:permute_U; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:permute_V; 11, False; 12, block; 12, 13; 12, 35; 12, 57; 12, 79; 12, 98; 12, 113; 12, 123; 12, 137; 12, 157; 12, 177; 12, 222; 12, 232; 12, 242; 12, 252; 12, 262; 12, 278; 12, 292; 12, 332; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:unrm; 16, list_comprehension; 16, 17; 16, 30; 17, binary_operator:/; 17, 18; 17, 19; 18, identifier:f; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:np; 23, identifier:linalg; 24, identifier:norm; 25, argument_list; 25, 26; 25, 27; 26, identifier:f; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:axis; 29, integer:0; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:f; 32, attribute; 32, 33; 32, 34; 33, identifier:U; 34, identifier:factors; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:vnrm; 38, list_comprehension; 38, 39; 38, 52; 39, binary_operator:/; 39, 40; 39, 41; 40, identifier:f; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:np; 45, identifier:linalg; 46, identifier:norm; 47, argument_list; 47, 48; 47, 49; 48, identifier:f; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:axis; 51, integer:0; 52, for_in_clause; 52, 53; 52, 54; 53, identifier:f; 54, attribute; 54, 55; 54, 56; 55, identifier:V; 56, identifier:factors; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:sim_matrices; 60, list_comprehension; 60, 61; 60, 70; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:np; 64, identifier:dot; 65, argument_list; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:u; 68, identifier:T; 69, identifier:v; 70, for_in_clause; 70, 71; 70, 74; 71, pattern_list; 71, 72; 71, 73; 72, identifier:u; 73, identifier:v; 74, call; 74, 75; 74, 76; 75, identifier:zip; 76, argument_list; 76, 77; 76, 78; 77, identifier:unrm; 78, identifier:vnrm; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:cost; 82, binary_operator:-; 82, 83; 82, 84; 83, integer:1; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:np; 87, identifier:mean; 88, argument_list; 88, 89; 88, 95; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:np; 92, identifier:abs; 93, argument_list; 93, 94; 94, identifier:sim_matrices; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:axis; 97, integer:0; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:indices; 101, call; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, call; 103, 104; 103, 105; 104, identifier:Munkres; 105, argument_list; 106, identifier:compute; 107, argument_list; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:cost; 111, identifier:copy; 112, argument_list; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, pattern_list; 115, 116; 115, 117; 116, identifier:prmU; 117, identifier:prmV; 118, call; 118, 119; 118, 120; 119, identifier:zip; 120, argument_list; 120, 121; 121, list_splat; 121, 122; 122, identifier:indices; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:similarity; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:np; 129, identifier:mean; 130, argument_list; 130, 131; 131, binary_operator:-; 131, 132; 131, 133; 132, integer:1; 133, subscript; 133, 134; 133, 135; 133, 136; 134, identifier:cost; 135, identifier:prmU; 136, identifier:prmV; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:unmatched_U; 140, call; 140, 141; 140, 142; 141, identifier:list; 142, argument_list; 142, 143; 143, binary_operator:-; 143, 144; 143, 153; 144, call; 144, 145; 144, 146; 145, identifier:set; 146, argument_list; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:range; 149, argument_list; 149, 150; 150, attribute; 150, 151; 150, 152; 151, identifier:U; 152, identifier:rank; 153, call; 153, 154; 153, 155; 154, identifier:set; 155, argument_list; 155, 156; 156, identifier:prmU; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:unmatched_V; 160, call; 160, 161; 160, 162; 161, identifier:list; 162, argument_list; 162, 163; 163, binary_operator:-; 163, 164; 163, 173; 164, call; 164, 165; 164, 166; 165, identifier:set; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:range; 169, argument_list; 169, 170; 170, attribute; 170, 171; 170, 172; 171, identifier:V; 172, identifier:rank; 173, call; 173, 174; 173, 175; 174, identifier:set; 175, argument_list; 175, 176; 176, identifier:prmV; 177, if_statement; 177, 178; 177, 181; 177, 194; 177, 206; 177, 218; 178, boolean_operator:and; 178, 179; 178, 180; 179, identifier:permute_U; 180, identifier:permute_V; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:idx; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:np; 188, identifier:argsort; 189, argument_list; 189, 190; 190, subscript; 190, 191; 190, 192; 190, 193; 191, identifier:cost; 192, identifier:prmU; 193, identifier:prmV; 194, elif_clause; 194, 195; 194, 196; 195, identifier:permute_V; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:idx; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:np; 203, identifier:argsort; 204, argument_list; 204, 205; 205, identifier:prmU; 206, elif_clause; 206, 207; 206, 208; 207, identifier:permute_U; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:idx; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:np; 215, identifier:argsort; 216, argument_list; 216, 217; 217, identifier:prmV; 218, else_clause; 218, 219; 219, block; 219, 220; 220, return_statement; 220, 221; 221, identifier:similarity; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:prmU; 225, list_comprehension; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:prmU; 228, identifier:i; 229, for_in_clause; 229, 230; 229, 231; 230, identifier:i; 231, identifier:idx; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:prmV; 235, list_comprehension; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:prmV; 238, identifier:i; 239, for_in_clause; 239, 240; 239, 241; 240, identifier:i; 241, identifier:idx; 242, if_statement; 242, 243; 242, 244; 243, identifier:permute_U; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:U; 249, identifier:permute; 250, argument_list; 250, 251; 251, identifier:prmU; 252, if_statement; 252, 253; 252, 254; 253, identifier:permute_V; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:V; 259, identifier:permute; 260, argument_list; 260, 261; 261, identifier:prmV; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:flips; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:np; 268, identifier:sign; 269, argument_list; 269, 270; 270, list_comprehension; 270, 271; 270, 275; 271, subscript; 271, 272; 271, 273; 271, 274; 272, identifier:F; 273, identifier:prmU; 274, identifier:prmV; 275, for_in_clause; 275, 276; 275, 277; 276, identifier:F; 277, identifier:sim_matrices; 278, expression_statement; 278, 279; 279, augmented_assignment:*=; 279, 280; 279, 283; 280, subscript; 280, 281; 280, 282; 281, identifier:flips; 282, integer:0; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:np; 286, identifier:prod; 287, argument_list; 287, 288; 287, 289; 288, identifier:flips; 289, keyword_argument; 289, 290; 289, 291; 290, identifier:axis; 291, integer:0; 292, if_statement; 292, 293; 292, 294; 292, 312; 293, identifier:permute_U; 294, block; 294, 295; 295, for_statement; 295, 296; 295, 299; 295, 303; 296, pattern_list; 296, 297; 296, 298; 297, identifier:i; 298, identifier:f; 299, call; 299, 300; 299, 301; 300, identifier:enumerate; 301, argument_list; 301, 302; 302, identifier:flips; 303, block; 303, 304; 304, expression_statement; 304, 305; 305, augmented_assignment:*=; 305, 306; 305, 311; 306, subscript; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:U; 309, identifier:factors; 310, identifier:i; 311, identifier:f; 312, elif_clause; 312, 313; 312, 314; 313, identifier:permute_V; 314, block; 314, 315; 315, for_statement; 315, 316; 315, 319; 315, 323; 316, pattern_list; 316, 317; 316, 318; 317, identifier:i; 318, identifier:f; 319, call; 319, 320; 319, 321; 320, identifier:enumerate; 321, argument_list; 321, 322; 322, identifier:flips; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, augmented_assignment:*=; 325, 326; 325, 331; 326, subscript; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:V; 329, identifier:factors; 330, identifier:i; 331, identifier:f; 332, return_statement; 332, 333; 333, identifier:similarity | def kruskal_align(U, V, permute_U=False, permute_V=False):
unrm = [f / np.linalg.norm(f, axis=0) for f in U.factors]
vnrm = [f / np.linalg.norm(f, axis=0) for f in V.factors]
sim_matrices = [np.dot(u.T, v) for u, v in zip(unrm, vnrm)]
cost = 1 - np.mean(np.abs(sim_matrices), axis=0)
indices = Munkres().compute(cost.copy())
prmU, prmV = zip(*indices)
similarity = np.mean(1 - cost[prmU, prmV])
unmatched_U = list(set(range(U.rank)) - set(prmU))
unmatched_V = list(set(range(V.rank)) - set(prmV))
if permute_U and permute_V:
idx = np.argsort(cost[prmU, prmV])
elif permute_V:
idx = np.argsort(prmU)
elif permute_U:
idx = np.argsort(prmV)
else:
return similarity
prmU = [prmU[i] for i in idx]
prmV = [prmV[i] for i in idx]
if permute_U:
U.permute(prmU)
if permute_V:
V.permute(prmV)
flips = np.sign([F[prmU, prmV] for F in sim_matrices])
flips[0] *= np.prod(flips, axis=0)
if permute_U:
for i, f in enumerate(flips):
U.factors[i] *= f
elif permute_V:
for i, f in enumerate(flips):
V.factors[i] *= f
return similarity |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:randn_ktensor; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:shape; 5, identifier:rank; 6, default_parameter; 6, 7; 6, 8; 7, identifier:norm; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:random_state; 11, None; 12, block; 12, 13; 12, 20; 12, 38; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:rns; 16, call; 16, 17; 16, 18; 17, identifier:_check_random_state; 18, argument_list; 18, 19; 19, identifier:random_state; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:factors; 23, call; 23, 24; 23, 25; 24, identifier:KTensor; 25, argument_list; 25, 26; 26, list_comprehension; 26, 27; 26, 35; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:rns; 30, identifier:standard_normal; 31, argument_list; 31, 32; 32, tuple; 32, 33; 32, 34; 33, identifier:i; 34, identifier:rank; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:i; 37, identifier:shape; 38, return_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:_rescale_tensor; 41, argument_list; 41, 42; 41, 43; 42, identifier:factors; 43, identifier:norm | def randn_ktensor(shape, rank, norm=None, random_state=None):
rns = _check_random_state(random_state)
factors = KTensor([rns.standard_normal((i, rank)) for i in shape])
return _rescale_tensor(factors, norm) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:fit; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:X; 6, identifier:ranks; 7, default_parameter; 7, 8; 7, 9; 8, identifier:replicates; 9, integer:1; 10, default_parameter; 10, 11; 10, 12; 11, identifier:verbose; 12, True; 13, block; 13, 14; 13, 29; 13, 177; 13, 218; 13, 279; 14, if_statement; 14, 15; 14, 23; 15, not_operator; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:isinstance; 18, argument_list; 18, 19; 18, 20; 19, identifier:ranks; 20, attribute; 20, 21; 20, 22; 21, identifier:collections; 22, identifier:Iterable; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:ranks; 27, tuple; 27, 28; 28, identifier:ranks; 29, for_statement; 29, 30; 29, 31; 29, 32; 30, identifier:r; 31, identifier:ranks; 32, block; 32, 33; 32, 48; 32, 78; 32, 107; 33, if_statement; 33, 34; 33, 39; 34, comparison_operator:not; 34, 35; 34, 36; 35, identifier:r; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:results; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 47; 42, subscript; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:results; 46, identifier:r; 47, list:[]; 48, if_statement; 48, 49; 48, 50; 48, 69; 49, identifier:verbose; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:itr; 54, call; 54, 55; 54, 56; 55, identifier:trange; 56, argument_list; 56, 57; 56, 58; 56, 66; 57, identifier:replicates; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:desc; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, string:'Fitting rank-{} models'; 63, identifier:format; 64, argument_list; 64, 65; 65, identifier:r; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:leave; 68, False; 69, else_clause; 69, 70; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:itr; 74, call; 74, 75; 74, 76; 75, identifier:range; 76, argument_list; 76, 77; 77, identifier:replicates; 78, for_statement; 78, 79; 78, 80; 78, 81; 79, identifier:i; 80, identifier:itr; 81, block; 81, 82; 81, 96; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:model_fit; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:_fit_method; 89, argument_list; 89, 90; 89, 91; 89, 92; 90, identifier:X; 91, identifier:r; 92, dictionary_splat; 92, 93; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:_fit_options; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 105; 98, attribute; 98, 99; 98, 104; 99, subscript; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:results; 103, identifier:r; 104, identifier:append; 105, argument_list; 105, 106; 106, identifier:model_fit; 107, if_statement; 107, 108; 107, 109; 108, identifier:verbose; 109, block; 109, 110; 109, 127; 109, 144; 109, 161; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:min_obj; 113, call; 113, 114; 113, 115; 114, identifier:min; 115, argument_list; 115, 116; 116, list_comprehension; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:res; 119, identifier:obj; 120, for_in_clause; 120, 121; 120, 122; 121, identifier:res; 122, subscript; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:results; 126, identifier:r; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:max_obj; 130, call; 130, 131; 130, 132; 131, identifier:max; 132, argument_list; 132, 133; 133, list_comprehension; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:res; 136, identifier:obj; 137, for_in_clause; 137, 138; 137, 139; 138, identifier:res; 139, subscript; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:results; 143, identifier:r; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:elapsed; 147, call; 147, 148; 147, 149; 148, identifier:sum; 149, argument_list; 149, 150; 150, list_comprehension; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:res; 153, identifier:total_time; 154, for_in_clause; 154, 155; 154, 156; 155, identifier:res; 156, subscript; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:results; 160, identifier:r; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:print; 164, argument_list; 164, 165; 165, call; 165, 166; 165, 172; 166, attribute; 166, 167; 166, 171; 167, concatenated_string; 167, 168; 167, 169; 167, 170; 168, string:'Rank-{} models: min obj, {:.2f}; '; 169, string:'max obj, {:.2f}; time to fit, '; 170, string:'{:.1f}s'; 171, identifier:format; 172, argument_list; 172, 173; 172, 174; 172, 175; 172, 176; 173, identifier:r; 174, identifier:min_obj; 175, identifier:max_obj; 176, identifier:elapsed; 177, for_statement; 177, 178; 177, 179; 177, 180; 178, identifier:r; 179, identifier:ranks; 180, block; 180, 181; 180, 200; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:idx; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:np; 187, identifier:argsort; 188, argument_list; 188, 189; 189, list_comprehension; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:result; 192, identifier:obj; 193, for_in_clause; 193, 194; 193, 195; 194, identifier:result; 195, subscript; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:results; 199, identifier:r; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 207; 202, subscript; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:results; 206, identifier:r; 207, list_comprehension; 207, 208; 207, 215; 208, subscript; 208, 209; 208, 214; 209, subscript; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:results; 213, identifier:r; 214, identifier:i; 215, for_in_clause; 215, 216; 215, 217; 216, identifier:i; 217, identifier:idx; 218, for_statement; 218, 219; 218, 220; 218, 231; 219, identifier:i; 220, call; 220, 221; 220, 222; 221, identifier:reversed; 222, argument_list; 222, 223; 223, call; 223, 224; 223, 225; 224, identifier:range; 225, argument_list; 225, 226; 225, 227; 226, integer:1; 227, call; 227, 228; 227, 229; 228, identifier:len; 229, argument_list; 229, 230; 230, identifier:ranks; 231, block; 231, 232; 231, 246; 231, 258; 231, 270; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 237; 234, pattern_list; 234, 235; 234, 236; 235, identifier:r0; 236, identifier:r1; 237, expression_list; 237, 238; 237, 243; 238, subscript; 238, 239; 238, 240; 239, identifier:ranks; 240, binary_operator:-; 240, 241; 240, 242; 241, identifier:i; 242, integer:1; 243, subscript; 243, 244; 243, 245; 244, identifier:ranks; 245, identifier:i; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:U; 249, attribute; 249, 250; 249, 257; 250, subscript; 250, 251; 250, 256; 251, subscript; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:results; 255, identifier:r0; 256, integer:0; 257, identifier:factors; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:V; 261, attribute; 261, 262; 261, 269; 262, subscript; 262, 263; 262, 268; 263, subscript; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:results; 267, identifier:r1; 268, integer:0; 269, identifier:factors; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 273; 272, identifier:kruskal_align; 273, argument_list; 273, 274; 273, 275; 273, 276; 274, identifier:U; 275, identifier:V; 276, keyword_argument; 276, 277; 276, 278; 277, identifier:permute_U; 278, True; 279, for_statement; 279, 280; 279, 281; 279, 282; 280, identifier:r; 281, identifier:ranks; 282, block; 282, 283; 282, 295; 282, 307; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:U; 286, attribute; 286, 287; 286, 294; 287, subscript; 287, 288; 287, 293; 288, subscript; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:results; 292, identifier:r; 293, integer:0; 294, identifier:factors; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 306; 297, attribute; 297, 298; 297, 305; 298, subscript; 298, 299; 298, 304; 299, subscript; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:self; 302, identifier:results; 303, identifier:r; 304, integer:0; 305, identifier:similarity; 306, float:1.0; 307, for_statement; 307, 308; 307, 309; 307, 318; 308, identifier:res; 309, subscript; 309, 310; 309, 315; 310, subscript; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:results; 314, identifier:r; 315, slice; 315, 316; 315, 317; 316, integer:1; 317, colon; 318, block; 318, 319; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:res; 323, identifier:similarity; 324, call; 324, 325; 324, 326; 325, identifier:kruskal_align; 326, argument_list; 326, 327; 326, 328; 326, 331; 327, identifier:U; 328, attribute; 328, 329; 328, 330; 329, identifier:res; 330, identifier:factors; 331, keyword_argument; 331, 332; 331, 333; 332, identifier:permute_V; 333, True | def fit(self, X, ranks, replicates=1, verbose=True):
if not isinstance(ranks, collections.Iterable):
ranks = (ranks,)
for r in ranks:
if r not in self.results:
self.results[r] = []
if verbose:
itr = trange(replicates,
desc='Fitting rank-{} models'.format(r),
leave=False)
else:
itr = range(replicates)
for i in itr:
model_fit = self._fit_method(X, r, **self._fit_options)
self.results[r].append(model_fit)
if verbose:
min_obj = min([res.obj for res in self.results[r]])
max_obj = max([res.obj for res in self.results[r]])
elapsed = sum([res.total_time for res in self.results[r]])
print('Rank-{} models: min obj, {:.2f}; '
'max obj, {:.2f}; time to fit, '
'{:.1f}s'.format(r, min_obj, max_obj, elapsed))
for r in ranks:
idx = np.argsort([result.obj for result in self.results[r]])
self.results[r] = [self.results[r][i] for i in idx]
for i in reversed(range(1, len(ranks))):
r0, r1 = ranks[i-1], ranks[i]
U = self.results[r0][0].factors
V = self.results[r1][0].factors
kruskal_align(U, V, permute_U=True)
for r in ranks:
U = self.results[r][0].factors
self.results[r][0].similarity = 1.0
for res in self.results[r][1:]:
res.similarity = kruskal_align(U, res.factors, permute_V=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_create_model_class; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:model; 6, block; 6, 7; 6, 17; 6, 42; 6, 60; 6, 72; 6, 111; 6, 155; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:cls_name; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:model; 13, identifier:replace; 14, argument_list; 14, 15; 14, 16; 15, string:'.'; 16, string:'_'; 17, if_statement; 17, 18; 17, 25; 18, comparison_operator:<; 18, 19; 18, 24; 19, subscript; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:sys; 22, identifier:version_info; 23, integer:0; 24, integer:3; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 32; 27, call; 27, 28; 27, 29; 28, identifier:isinstance; 29, argument_list; 29, 30; 29, 31; 30, identifier:cls_name; 31, identifier:unicode; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:cls_name; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:cls_name; 39, identifier:encode; 40, argument_list; 40, 41; 41, string:'utf-8'; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:attrs; 45, dictionary; 45, 46; 45, 49; 45, 54; 45, 57; 46, pair; 46, 47; 46, 48; 47, string:'_env'; 48, identifier:self; 49, pair; 49, 50; 49, 51; 50, string:'_odoo'; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_odoo; 54, pair; 54, 55; 54, 56; 55, string:'_name'; 56, identifier:model; 57, pair; 57, 58; 57, 59; 58, string:'_columns'; 59, dictionary; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:fields_get; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:_odoo; 68, identifier:execute; 69, argument_list; 69, 70; 69, 71; 70, identifier:model; 71, string:'fields_get'; 72, for_statement; 72, 73; 72, 76; 72, 81; 73, pattern_list; 73, 74; 73, 75; 74, identifier:field_name; 75, identifier:field_data; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:fields_get; 79, identifier:items; 80, argument_list; 81, block; 81, 82; 82, if_statement; 82, 83; 82, 86; 83, comparison_operator:not; 83, 84; 83, 85; 84, identifier:field_name; 85, identifier:FIELDS_RESERVED; 86, block; 86, 87; 86, 97; 86, 105; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:Field; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:fields; 93, identifier:generate_field; 94, argument_list; 94, 95; 94, 96; 95, identifier:field_name; 96, identifier:field_data; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 104; 99, subscript; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:attrs; 102, string:'_columns'; 103, identifier:field_name; 104, identifier:Field; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:attrs; 109, identifier:field_name; 110, identifier:Field; 111, if_statement; 111, 112; 111, 117; 112, comparison_operator:not; 112, 113; 112, 114; 113, string:'name'; 114, subscript; 114, 115; 114, 116; 115, identifier:attrs; 116, string:'_columns'; 117, block; 117, 118; 117, 131; 117, 141; 117, 149; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:field_data; 121, dictionary; 121, 122; 121, 125; 121, 128; 122, pair; 122, 123; 122, 124; 123, string:'type'; 124, string:'text'; 125, pair; 125, 126; 125, 127; 126, string:'string'; 127, string:'Name'; 128, pair; 128, 129; 128, 130; 129, string:'readonly'; 130, True; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:Field; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:fields; 137, identifier:generate_field; 138, argument_list; 138, 139; 138, 140; 139, string:'name'; 140, identifier:field_data; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 148; 143, subscript; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:attrs; 146, string:'_columns'; 147, string:'name'; 148, identifier:Field; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:attrs; 153, string:'name'; 154, identifier:Field; 155, return_statement; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:type; 158, argument_list; 158, 159; 158, 160; 158, 162; 159, identifier:cls_name; 160, tuple; 160, 161; 161, identifier:Model; 162, identifier:attrs | def _create_model_class(self, model):
cls_name = model.replace('.', '_')
if sys.version_info[0] < 3:
if isinstance(cls_name, unicode):
cls_name = cls_name.encode('utf-8')
attrs = {
'_env': self,
'_odoo': self._odoo,
'_name': model,
'_columns': {},
}
fields_get = self._odoo.execute(model, 'fields_get')
for field_name, field_data in fields_get.items():
if field_name not in FIELDS_RESERVED:
Field = fields.generate_field(field_name, field_data)
attrs['_columns'][field_name] = Field
attrs[field_name] = Field
if 'name' not in attrs['_columns']:
field_data = {'type': 'text', 'string': 'Name', 'readonly': True}
Field = fields.generate_field('name', field_data)
attrs['_columns']['name'] = Field
attrs['name'] = Field
return type(cls_name, (Model,), attrs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_init_values; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:context; 7, None; 8, block; 8, 9; 8, 22; 8, 26; 8, 56; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:context; 12, None; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:context; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:env; 21, identifier:context; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:basic_fields; 25, list:[]; 26, for_statement; 26, 27; 26, 28; 26, 31; 27, identifier:field_name; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_columns; 31, block; 31, 32; 31, 40; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:field; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_columns; 39, identifier:field_name; 40, if_statement; 40, 41; 40, 48; 41, not_operator; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:getattr; 44, argument_list; 44, 45; 44, 46; 44, 47; 45, identifier:field; 46, string:'relation'; 47, False; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:basic_fields; 53, identifier:append; 54, argument_list; 54, 55; 55, identifier:field_name; 56, if_statement; 56, 57; 56, 60; 56, 158; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:ids; 60, block; 60, 61; 60, 81; 60, 87; 60, 124; 60, 135; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:rows; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:__class__; 69, identifier:read; 70, argument_list; 70, 71; 70, 74; 70, 75; 70, 78; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:ids; 74, identifier:basic_fields; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:context; 77, identifier:context; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:load; 80, string:'_classic_write'; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:ids_fetched; 84, call; 84, 85; 84, 86; 85, identifier:set; 86, argument_list; 87, for_statement; 87, 88; 87, 89; 87, 90; 88, identifier:row; 89, identifier:rows; 90, block; 90, 91; 90, 100; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:ids_fetched; 95, identifier:add; 96, argument_list; 96, 97; 97, subscript; 97, 98; 97, 99; 98, identifier:row; 99, string:'id'; 100, for_statement; 100, 101; 100, 102; 100, 103; 101, identifier:field_name; 102, identifier:row; 103, block; 103, 104; 103, 110; 104, if_statement; 104, 105; 104, 108; 105, comparison_operator:==; 105, 106; 105, 107; 106, identifier:field_name; 107, string:'id'; 108, block; 108, 109; 109, continue_statement; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 121; 112, subscript; 112, 113; 112, 118; 113, subscript; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:_values; 117, identifier:field_name; 118, subscript; 118, 119; 118, 120; 119, identifier:row; 120, string:'id'; 121, subscript; 121, 122; 121, 123; 122, identifier:row; 123, identifier:field_name; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:ids_in_error; 127, binary_operator:-; 127, 128; 127, 134; 128, call; 128, 129; 128, 130; 129, identifier:set; 130, argument_list; 130, 131; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:ids; 134, identifier:ids_fetched; 135, if_statement; 135, 136; 135, 137; 136, identifier:ids_in_error; 137, block; 137, 138; 138, raise_statement; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:ValueError; 141, argument_list; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, string:"There is no '{model}' record with IDs {ids}."; 145, identifier:format; 146, argument_list; 146, 147; 146, 152; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:model; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:_name; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:ids; 154, call; 154, 155; 154, 156; 155, identifier:list; 156, argument_list; 156, 157; 157, identifier:ids_in_error; 158, else_clause; 158, 159; 159, block; 159, 160; 159, 179; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:default_get; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:__class__; 168, identifier:default_get; 169, argument_list; 169, 170; 169, 176; 170, call; 170, 171; 170, 172; 171, identifier:list; 172, argument_list; 172, 173; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:_columns; 176, keyword_argument; 176, 177; 176, 178; 177, identifier:context; 178, identifier:context; 179, for_statement; 179, 180; 179, 181; 179, 184; 180, identifier:field_name; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:_columns; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 194; 187, subscript; 187, 188; 187, 193; 188, subscript; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:_values; 192, identifier:field_name; 193, None; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:default_get; 197, identifier:get; 198, argument_list; 198, 199; 198, 200; 199, identifier:field_name; 200, False | def _init_values(self, context=None):
if context is None:
context = self.env.context
basic_fields = []
for field_name in self._columns:
field = self._columns[field_name]
if not getattr(field, 'relation', False):
basic_fields.append(field_name)
if self.ids:
rows = self.__class__.read(
self.ids, basic_fields, context=context, load='_classic_write')
ids_fetched = set()
for row in rows:
ids_fetched.add(row['id'])
for field_name in row:
if field_name == 'id':
continue
self._values[field_name][row['id']] = row[field_name]
ids_in_error = set(self.ids) - ids_fetched
if ids_in_error:
raise ValueError(
"There is no '{model}' record with IDs {ids}.".format(
model=self._name, ids=list(ids_in_error)))
else:
default_get = self.__class__.default_get(
list(self._columns), context=context)
for field_name in self._columns:
self._values[field_name][None] = default_get.get(
field_name, False) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_resource_id; 3, parameters; 3, 4; 4, identifier:rid; 5, block; 5, 6; 5, 12; 5, 21; 5, 121; 6, if_statement; 6, 7; 6, 9; 7, not_operator; 7, 8; 8, identifier:rid; 9, block; 9, 10; 10, return_statement; 10, 11; 11, dictionary; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:match; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:_ARMID_RE; 18, identifier:match; 19, argument_list; 19, 20; 20, identifier:rid; 21, if_statement; 21, 22; 21, 23; 21, 110; 22, identifier:match; 23, block; 23, 24; 23, 32; 23, 45; 23, 49; 23, 88; 23, 103; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:result; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:match; 30, identifier:groupdict; 31, argument_list; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:children; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:_CHILDREN_RE; 38, identifier:finditer; 39, argument_list; 39, 40; 40, boolean_operator:or; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:result; 43, string:'children'; 44, string:''; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:count; 48, None; 49, for_statement; 49, 50; 49, 53; 49, 57; 50, pattern_list; 50, 51; 50, 52; 51, identifier:count; 52, identifier:child; 53, call; 53, 54; 53, 55; 54, identifier:enumerate; 55, argument_list; 55, 56; 56, identifier:children; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:result; 62, identifier:update; 63, argument_list; 63, 64; 64, dictionary_comprehension; 64, 65; 64, 75; 65, pair; 65, 66; 65, 74; 66, binary_operator:+; 66, 67; 66, 68; 67, identifier:key; 68, binary_operator:%; 68, 69; 68, 70; 69, string:'_%d'; 70, parenthesized_expression; 70, 71; 71, binary_operator:+; 71, 72; 71, 73; 72, identifier:count; 73, integer:1; 74, identifier:group; 75, for_in_clause; 75, 76; 75, 79; 76, pattern_list; 76, 77; 76, 78; 77, identifier:key; 78, identifier:group; 79, call; 79, 80; 79, 87; 80, attribute; 80, 81; 80, 86; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:child; 84, identifier:groupdict; 85, argument_list; 86, identifier:items; 87, argument_list; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:result; 92, string:'last_child_num'; 93, conditional_expression:if; 93, 94; 93, 97; 93, 102; 94, binary_operator:+; 94, 95; 94, 96; 95, identifier:count; 96, integer:1; 97, call; 97, 98; 97, 99; 98, identifier:isinstance; 99, argument_list; 99, 100; 99, 101; 100, identifier:count; 101, identifier:int; 102, None; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:result; 106, call; 106, 107; 106, 108; 107, identifier:_populate_alternate_kwargs; 108, argument_list; 108, 109; 109, identifier:result; 110, else_clause; 110, 111; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:result; 115, call; 115, 116; 115, 117; 116, identifier:dict; 117, argument_list; 117, 118; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:name; 120, identifier:rid; 121, return_statement; 121, 122; 122, dictionary_comprehension; 122, 123; 122, 126; 122, 135; 123, pair; 123, 124; 123, 125; 124, identifier:key; 125, identifier:value; 126, for_in_clause; 126, 127; 126, 130; 127, pattern_list; 127, 128; 127, 129; 128, identifier:key; 129, identifier:value; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:result; 133, identifier:items; 134, argument_list; 135, if_clause; 135, 136; 136, comparison_operator:is; 136, 137; 136, 138; 137, identifier:value; 138, None | def parse_resource_id(rid):
if not rid:
return {}
match = _ARMID_RE.match(rid)
if match:
result = match.groupdict()
children = _CHILDREN_RE.finditer(result['children'] or '')
count = None
for count, child in enumerate(children):
result.update({
key + '_%d' % (count + 1): group for key, group in child.groupdict().items()})
result['last_child_num'] = count + 1 if isinstance(count, int) else None
result = _populate_alternate_kwargs(result)
else:
result = dict(name=rid)
return {key: value for key, value in result.items() if value is not None} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:lookup_instance; 3, parameters; 3, 4; 3, 8; 3, 13; 3, 18; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:name; 6, type; 6, 7; 7, identifier:str; 8, typed_default_parameter; 8, 9; 8, 10; 8, 12; 9, identifier:instance_type; 10, type; 10, 11; 11, identifier:str; 12, string:''; 13, typed_default_parameter; 13, 14; 13, 15; 13, 17; 14, identifier:image_name; 15, type; 15, 16; 16, identifier:str; 17, string:''; 18, typed_default_parameter; 18, 19; 18, 20; 18, 22; 19, identifier:states; 20, type; 20, 21; 21, identifier:tuple; 22, tuple; 22, 23; 22, 24; 22, 25; 23, string:'running'; 24, string:'stopped'; 25, string:'initializing'; 26, block; 26, 27; 26, 33; 26, 53; 26, 59; 26, 65; 26, 69; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:ec2; 30, call; 30, 31; 30, 32; 31, identifier:get_ec2_resource; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:instances; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:ec2; 40, identifier:instances; 41, identifier:filter; 42, argument_list; 42, 43; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:Filters; 45, list:[{'Name': 'instance-state-name', 'Values': states}]; 45, 46; 46, dictionary; 46, 47; 46, 50; 47, pair; 47, 48; 47, 49; 48, string:'Name'; 49, string:'instance-state-name'; 50, pair; 50, 51; 50, 52; 51, string:'Values'; 52, identifier:states; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:prefix; 56, call; 56, 57; 56, 58; 57, identifier:get_prefix; 58, argument_list; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:username; 62, call; 62, 63; 62, 64; 63, identifier:get_username; 64, argument_list; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:result; 68, list:[]; 69, for_statement; 69, 70; 69, 71; 69, 76; 70, identifier:i; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:instances; 74, identifier:all; 75, argument_list; 76, block; 76, 77; 76, 84; 76, 90; 76, 101; 76, 112; 76, 123; 76, 133; 76, 145; 76, 152; 76, 160; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:instance_name; 80, call; 80, 81; 80, 82; 81, identifier:get_name; 82, argument_list; 82, 83; 83, identifier:i; 84, if_statement; 84, 85; 84, 88; 85, comparison_operator:!=; 85, 86; 85, 87; 86, identifier:instance_name; 87, identifier:name; 88, block; 88, 89; 89, continue_statement; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, pattern_list; 92, 93; 92, 94; 93, identifier:seen_prefix; 94, identifier:seen_username; 95, call; 95, 96; 95, 97; 96, identifier:parse_key_name; 97, argument_list; 97, 98; 98, attribute; 98, 99; 98, 100; 99, identifier:i; 100, identifier:key_name; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:!=; 102, 103; 102, 104; 103, identifier:prefix; 104, identifier:seen_prefix; 105, block; 105, 106; 105, 111; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:print; 109, argument_list; 109, 110; 110, string:f"Found {name} launched under {seen_prefix}, ignoring"; 111, continue_statement; 112, if_statement; 112, 113; 112, 116; 113, comparison_operator:!=; 113, 114; 113, 115; 114, identifier:username; 115, identifier:seen_username; 116, block; 116, 117; 116, 122; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:print; 120, argument_list; 120, 121; 121, string:f"Found {name} launched by {seen_username}, ignoring"; 122, continue_statement; 123, if_statement; 123, 124; 123, 125; 124, identifier:instance_type; 125, block; 125, 126; 126, assert_statement; 126, 127; 126, 132; 127, comparison_operator:==; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:i; 130, identifier:instance_type; 131, identifier:instance_type; 132, string:f"Found existing instance for job {name} but different instance type ({i.instance_type}) than requested ({instance_type}), terminate {name} first or use new task name."; 133, if_statement; 133, 134; 133, 135; 134, identifier:image_name; 135, block; 135, 136; 136, assert_statement; 136, 137; 136, 144; 137, comparison_operator:==; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:i; 141, identifier:image; 142, identifier:name; 143, identifier:image_name; 144, string:f"Found existing instance for job {name} but launched with different image ({i.image.name}) than requested ({image_name}), terminate {name} first or use new task name."; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:result; 149, identifier:append; 150, argument_list; 150, 151; 151, identifier:i; 152, assert_statement; 152, 153; 152, 159; 153, comparison_operator:<; 153, 154; 153, 158; 154, call; 154, 155; 154, 156; 155, identifier:len; 156, argument_list; 156, 157; 157, identifier:result; 158, integer:2; 159, string:f"Found two instances with name {name}"; 160, if_statement; 160, 161; 160, 163; 160, 166; 161, not_operator; 161, 162; 162, identifier:result; 163, block; 163, 164; 164, return_statement; 164, 165; 165, None; 166, else_clause; 166, 167; 167, block; 167, 168; 168, return_statement; 168, 169; 169, subscript; 169, 170; 169, 171; 170, identifier:result; 171, integer:0 | def lookup_instance(name: str, instance_type: str = '', image_name: str = '',
states: tuple = ('running', 'stopped', 'initializing')):
ec2 = get_ec2_resource()
instances = ec2.instances.filter(
Filters=[{'Name': 'instance-state-name', 'Values': states}])
prefix = get_prefix()
username = get_username()
result = []
for i in instances.all():
instance_name = get_name(i)
if instance_name != name:
continue
seen_prefix, seen_username = parse_key_name(i.key_name)
if prefix != seen_prefix:
print(f"Found {name} launched under {seen_prefix}, ignoring")
continue
if username != seen_username:
print(f"Found {name} launched by {seen_username}, ignoring")
continue
if instance_type:
assert i.instance_type == instance_type, f"Found existing instance for job {name} but different instance type ({i.instance_type}) than requested ({instance_type}), terminate {name} first or use new task name."
if image_name:
assert i.image.name == image_name, f"Found existing instance for job {name} but launched with different image ({i.image.name}) than requested ({image_name}), terminate {name} first or use new task name."
result.append(i)
assert len(result) < 2, f"Found two instances with name {name}"
if not result:
return None
else:
return result[0] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:extract_attr_for_match; 3, parameters; 3, 4; 3, 5; 4, identifier:items; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 12; 7, 37; 7, 41; 7, 52; 7, 126; 7, 141; 7, 148; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:query_arg; 11, None; 12, for_statement; 12, 13; 12, 16; 12, 21; 13, pattern_list; 13, 14; 13, 15; 14, identifier:arg; 15, identifier:value; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:kwargs; 19, identifier:items; 20, argument_list; 21, block; 21, 22; 22, if_statement; 22, 23; 22, 27; 23, comparison_operator:==; 23, 24; 23, 25; 24, identifier:value; 25, unary_operator:-; 25, 26; 26, integer:1; 27, block; 27, 28; 27, 33; 28, assert_statement; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:query_arg; 31, None; 32, string:"Only single query arg (-1 valued) is allowed"; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:query_arg; 36, identifier:arg; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:result; 40, list:[]; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:filterset; 44, call; 44, 45; 44, 46; 45, identifier:set; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:kwargs; 50, identifier:keys; 51, argument_list; 52, for_statement; 52, 53; 52, 54; 52, 55; 53, identifier:item; 54, identifier:items; 55, block; 55, 56; 55, 60; 55, 85; 55, 114; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:match; 59, True; 60, assert_statement; 60, 61; 60, 71; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:filterset; 64, identifier:issubset; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:item; 69, identifier:keys; 70, argument_list; 71, binary_operator:%; 71, 72; 71, 73; 72, string:"Filter set contained %s which was not in record %s"; 73, tuple; 73, 74; 73, 84; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:filterset; 77, identifier:difference; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:item; 82, identifier:keys; 83, argument_list; 84, identifier:item; 85, for_statement; 85, 86; 85, 87; 85, 88; 86, identifier:arg; 87, identifier:item; 88, block; 88, 89; 88, 95; 89, if_statement; 89, 90; 89, 93; 90, comparison_operator:==; 90, 91; 90, 92; 91, identifier:arg; 92, identifier:query_arg; 93, block; 93, 94; 94, continue_statement; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:in; 96, 97; 96, 98; 97, identifier:arg; 98, identifier:kwargs; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 108; 101, comparison_operator:!=; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:item; 104, identifier:arg; 105, subscript; 105, 106; 105, 107; 106, identifier:kwargs; 107, identifier:arg; 108, block; 108, 109; 108, 113; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:match; 112, False; 113, break_statement; 114, if_statement; 114, 115; 114, 116; 115, identifier:match; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:result; 121, identifier:append; 122, argument_list; 122, 123; 123, subscript; 123, 124; 123, 125; 124, identifier:item; 125, identifier:query_arg; 126, assert_statement; 126, 127; 126, 133; 127, comparison_operator:<=; 127, 128; 127, 132; 128, call; 128, 129; 128, 130; 129, identifier:len; 130, argument_list; 130, 131; 131, identifier:result; 132, integer:1; 133, binary_operator:%; 133, 134; 133, 135; 134, string:"%d values matched %s, only allow 1"; 135, tuple; 135, 136; 135, 140; 136, call; 136, 137; 136, 138; 137, identifier:len; 138, argument_list; 138, 139; 139, identifier:result; 140, identifier:kwargs; 141, if_statement; 141, 142; 141, 143; 142, identifier:result; 143, block; 143, 144; 144, return_statement; 144, 145; 145, subscript; 145, 146; 145, 147; 146, identifier:result; 147, integer:0; 148, return_statement; 148, 149; 149, None | def extract_attr_for_match(items, **kwargs):
query_arg = None
for arg, value in kwargs.items():
if value == -1:
assert query_arg is None, "Only single query arg (-1 valued) is allowed"
query_arg = arg
result = []
filterset = set(kwargs.keys())
for item in items:
match = True
assert filterset.issubset(
item.keys()), "Filter set contained %s which was not in record %s" % (
filterset.difference(item.keys()),
item)
for arg in item:
if arg == query_arg:
continue
if arg in kwargs:
if item[arg] != kwargs[arg]:
match = False
break
if match:
result.append(item[query_arg])
assert len(result) <= 1, "%d values matched %s, only allow 1" % (
len(result), kwargs)
if result:
return result[0]
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_maybe_create_resources; 3, parameters; 3, 4; 4, typed_default_parameter; 4, 5; 4, 6; 4, 8; 5, identifier:logging_task; 6, type; 6, 7; 7, identifier:Task; 8, None; 9, block; 9, 10; 9, 37; 9, 118; 10, function_definition; 10, 11; 10, 12; 10, 15; 11, function_name:log; 12, parameters; 12, 13; 13, list_splat_pattern; 13, 14; 14, identifier:args; 15, block; 15, 16; 16, if_statement; 16, 17; 16, 18; 16, 27; 17, identifier:logging_task; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:logging_task; 23, identifier:log; 24, argument_list; 24, 25; 25, list_splat; 25, 26; 26, identifier:args; 27, else_clause; 27, 28; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:util; 33, identifier:log; 34, argument_list; 34, 35; 35, list_splat; 35, 36; 36, identifier:args; 37, function_definition; 37, 38; 37, 39; 37, 40; 38, function_name:should_create_resources; 39, parameters; 40, block; 40, 41; 40, 49; 40, 69; 40, 77; 40, 89; 40, 95; 40, 104; 40, 116; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:prefix; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:u; 47, identifier:get_prefix; 48, argument_list; 49, if_statement; 49, 50; 49, 61; 50, comparison_operator:not; 50, 51; 50, 56; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:u; 54, identifier:get_keypair_name; 55, argument_list; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:u; 59, identifier:get_keypair_dict; 60, argument_list; 61, block; 61, 62; 61, 67; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:log; 65, argument_list; 65, 66; 66, string:f"Missing {u.get_keypair_name()} keypair, creating resources"; 67, return_statement; 67, 68; 68, True; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:vpcs; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:u; 75, identifier:get_vpc_dict; 76, argument_list; 77, if_statement; 77, 78; 77, 81; 78, comparison_operator:not; 78, 79; 78, 80; 79, identifier:prefix; 80, identifier:vpcs; 81, block; 81, 82; 81, 87; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:log; 85, argument_list; 85, 86; 86, string:f"Missing {prefix} vpc, creating resources"; 87, return_statement; 87, 88; 88, True; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:vpc; 92, subscript; 92, 93; 92, 94; 93, identifier:vpcs; 94, identifier:prefix; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:gateways; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:u; 101, identifier:get_gateway_dict; 102, argument_list; 102, 103; 103, identifier:vpc; 104, if_statement; 104, 105; 104, 108; 105, comparison_operator:not; 105, 106; 105, 107; 106, identifier:prefix; 107, identifier:gateways; 108, block; 108, 109; 108, 114; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:log; 112, argument_list; 112, 113; 113, string:f"Missing {prefix} gateway, creating resources"; 114, return_statement; 114, 115; 115, True; 116, return_statement; 116, 117; 117, False; 118, try_statement; 118, 119; 118, 243; 119, block; 119, 120; 119, 197; 119, 216; 119, 237; 120, if_statement; 120, 121; 120, 129; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:os; 125, identifier:path; 126, identifier:exists; 127, argument_list; 127, 128; 128, identifier:AWS_LOCK_FN; 129, block; 129, 130; 129, 149; 129, 156; 129, 165; 129, 196; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 136; 132, pattern_list; 132, 133; 132, 134; 132, 135; 133, identifier:pid; 134, identifier:ts; 135, identifier:lock_taskname; 136, call; 136, 137; 136, 147; 137, attribute; 137, 138; 137, 146; 138, call; 138, 139; 138, 145; 139, attribute; 139, 140; 139, 144; 140, call; 140, 141; 140, 142; 141, identifier:open; 142, argument_list; 142, 143; 143, identifier:AWS_LOCK_FN; 144, identifier:read; 145, argument_list; 146, identifier:split; 147, argument_list; 147, 148; 148, string:'-'; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:ts; 152, call; 152, 153; 152, 154; 153, identifier:int; 154, argument_list; 154, 155; 155, identifier:ts; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:log; 159, argument_list; 159, 160; 160, concatenated_string; 160, 161; 160, 162; 160, 163; 160, 164; 161, string:f"waiting for aws resource creation, another resource initiation was "; 162, string:f"initiated {int(time.time()-ts)} seconds ago by "; 163, string:f"{lock_taskname}, delete lock file "; 164, string:f"{AWS_LOCK_FN} if this is an error"; 165, while_statement; 165, 166; 165, 167; 166, True; 167, block; 167, 168; 168, if_statement; 168, 169; 168, 177; 168, 193; 169, call; 169, 170; 169, 175; 170, attribute; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:os; 173, identifier:path; 174, identifier:exists; 175, argument_list; 175, 176; 176, identifier:AWS_LOCK_FN; 177, block; 177, 178; 177, 185; 177, 192; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:log; 181, argument_list; 181, 182; 182, concatenated_string; 182, 183; 182, 184; 183, string:f"waiting for lock file {AWS_LOCK_FN} to get deleted "; 184, string:f"initiated {int(time.time()-ts)} seconds ago by "; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:time; 189, identifier:sleep; 190, argument_list; 190, 191; 191, integer:2; 192, continue_statement; 193, else_clause; 193, 194; 194, block; 194, 195; 195, break_statement; 196, return_statement; 197, with_statement; 197, 198; 197, 208; 198, with_clause; 198, 199; 199, with_item; 199, 200; 200, as_pattern; 200, 201; 200, 206; 201, call; 201, 202; 201, 203; 202, identifier:open; 203, argument_list; 203, 204; 203, 205; 204, identifier:AWS_LOCK_FN; 205, string:'w'; 206, as_pattern_target; 206, 207; 207, identifier:f; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:f; 213, identifier:write; 214, argument_list; 214, 215; 215, string:f'{os.getpid()}-{int(time.time())}-{logging_task.name if logging_task else ""}'; 216, if_statement; 216, 217; 216, 221; 217, not_operator; 217, 218; 218, call; 218, 219; 218, 220; 219, identifier:should_create_resources; 220, argument_list; 221, block; 221, 222; 221, 229; 221, 236; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:util; 226, identifier:log; 227, argument_list; 227, 228; 228, string:"Resources already created, no-op"; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:os; 233, identifier:remove; 234, argument_list; 234, 235; 235, identifier:AWS_LOCK_FN; 236, return_statement; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:create_lib; 241, identifier:create_resources; 242, argument_list; 243, finally_clause; 243, 244; 244, block; 244, 245; 245, if_statement; 245, 246; 245, 254; 246, call; 246, 247; 246, 252; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:os; 250, identifier:path; 251, identifier:exists; 252, argument_list; 252, 253; 253, identifier:AWS_LOCK_FN; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:os; 259, identifier:remove; 260, argument_list; 260, 261; 261, identifier:AWS_LOCK_FN | def _maybe_create_resources(logging_task: Task = None):
def log(*args):
if logging_task:
logging_task.log(*args)
else:
util.log(*args)
def should_create_resources():
prefix = u.get_prefix()
if u.get_keypair_name() not in u.get_keypair_dict():
log(f"Missing {u.get_keypair_name()} keypair, creating resources")
return True
vpcs = u.get_vpc_dict()
if prefix not in vpcs:
log(f"Missing {prefix} vpc, creating resources")
return True
vpc = vpcs[prefix]
gateways = u.get_gateway_dict(vpc)
if prefix not in gateways:
log(f"Missing {prefix} gateway, creating resources")
return True
return False
try:
if os.path.exists(AWS_LOCK_FN):
pid, ts, lock_taskname = open(AWS_LOCK_FN).read().split('-')
ts = int(ts)
log(f"waiting for aws resource creation, another resource initiation was "
f"initiated {int(time.time()-ts)} seconds ago by "
f"{lock_taskname}, delete lock file "
f"{AWS_LOCK_FN} if this is an error")
while True:
if os.path.exists(AWS_LOCK_FN):
log(f"waiting for lock file {AWS_LOCK_FN} to get deleted "
f"initiated {int(time.time()-ts)} seconds ago by ")
time.sleep(2)
continue
else:
break
return
with open(AWS_LOCK_FN, 'w') as f:
f.write(
f'{os.getpid()}-{int(time.time())}-{logging_task.name if logging_task else ""}')
if not should_create_resources():
util.log("Resources already created, no-op")
os.remove(AWS_LOCK_FN)
return
create_lib.create_resources()
finally:
if os.path.exists(AWS_LOCK_FN):
os.remove(AWS_LOCK_FN) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_set_aws_environment; 3, parameters; 3, 4; 4, typed_default_parameter; 4, 5; 4, 6; 4, 8; 5, identifier:task; 6, type; 6, 7; 7, identifier:Task; 8, None; 9, block; 9, 10; 9, 22; 9, 34; 9, 61; 9, 86; 9, 109; 9, 144; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:current_zone; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:os; 17, identifier:environ; 18, identifier:get; 19, argument_list; 19, 20; 19, 21; 20, string:'NCLUSTER_ZONE'; 21, string:''; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:current_region; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:os; 29, identifier:environ; 30, identifier:get; 31, argument_list; 31, 32; 31, 33; 32, string:'AWS_DEFAULT_REGION'; 33, string:''; 34, function_definition; 34, 35; 34, 36; 34, 39; 35, function_name:log; 36, parameters; 36, 37; 37, list_splat_pattern; 37, 38; 38, identifier:args; 39, block; 39, 40; 40, if_statement; 40, 41; 40, 42; 40, 51; 41, identifier:task; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:task; 47, identifier:log; 48, argument_list; 48, 49; 49, list_splat; 49, 50; 50, identifier:args; 51, else_clause; 51, 52; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:util; 57, identifier:log; 58, argument_list; 58, 59; 59, list_splat; 59, 60; 60, identifier:args; 61, if_statement; 61, 62; 61, 65; 62, boolean_operator:and; 62, 63; 62, 64; 63, identifier:current_region; 64, identifier:current_zone; 65, block; 65, 66; 65, 76; 66, assert_statement; 66, 67; 66, 73; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:current_zone; 70, identifier:startswith; 71, argument_list; 71, 72; 72, identifier:current_region; 73, concatenated_string; 73, 74; 73, 75; 74, string:f'Current zone "{current_zone}" ($NCLUSTER_ZONE) is not '; 75, string:f'in current region "{current_region} ($AWS_DEFAULT_REGION)'; 76, assert_statement; 76, 77; 77, comparison_operator:==; 77, 78; 77, 85; 78, attribute; 78, 79; 78, 84; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:u; 82, identifier:get_session; 83, argument_list; 84, identifier:region_name; 85, identifier:current_region; 86, if_statement; 86, 87; 86, 91; 87, boolean_operator:and; 87, 88; 87, 89; 88, identifier:current_zone; 89, not_operator; 89, 90; 90, identifier:current_region; 91, block; 91, 92; 91, 101; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:current_region; 95, subscript; 95, 96; 95, 97; 96, identifier:current_zone; 97, slice; 97, 98; 97, 99; 98, colon; 99, unary_operator:-; 99, 100; 100, integer:1; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 108; 103, subscript; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:os; 106, identifier:environ; 107, string:'AWS_DEFAULT_REGION'; 108, identifier:current_region; 109, if_statement; 109, 110; 109, 112; 110, not_operator; 110, 111; 111, identifier:current_region; 112, block; 112, 113; 112, 123; 112, 136; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:current_region; 116, attribute; 116, 117; 116, 122; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:u; 120, identifier:get_session; 121, argument_list; 122, identifier:region_name; 123, if_statement; 123, 124; 123, 126; 124, not_operator; 124, 125; 125, identifier:current_region; 126, block; 126, 127; 126, 132; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:log; 130, argument_list; 130, 131; 131, string:f"No default region available, using {NCLUSTER_DEFAULT_REGION}"; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:current_region; 135, identifier:NCLUSTER_DEFAULT_REGION; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 143; 138, subscript; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:os; 141, identifier:environ; 142, string:'AWS_DEFAULT_REGION'; 143, identifier:current_region; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:log; 147, argument_list; 147, 148; 148, concatenated_string; 148, 149; 148, 150; 149, string:f"Using account {u.get_account_number()}, region {current_region}, "; 150, string:f"zone {current_zone}" | def _set_aws_environment(task: Task = None):
current_zone = os.environ.get('NCLUSTER_ZONE', '')
current_region = os.environ.get('AWS_DEFAULT_REGION', '')
def log(*args):
if task:
task.log(*args)
else:
util.log(*args)
if current_region and current_zone:
assert current_zone.startswith(
current_region), f'Current zone "{current_zone}" ($NCLUSTER_ZONE) is not ' \
f'in current region "{current_region} ($AWS_DEFAULT_REGION)'
assert u.get_session().region_name == current_region
if current_zone and not current_region:
current_region = current_zone[:-1]
os.environ['AWS_DEFAULT_REGION'] = current_region
if not current_region:
current_region = u.get_session().region_name
if not current_region:
log(f"No default region available, using {NCLUSTER_DEFAULT_REGION}")
current_region = NCLUSTER_DEFAULT_REGION
os.environ['AWS_DEFAULT_REGION'] = current_region
log(f"Using account {u.get_account_number()}, region {current_region}, "
f"zone {current_zone}") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.