sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:write_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:content; 6, default_parameter; 6, 7; 6, 8; 7, identifier:filepath; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:filename; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:indent; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:keys_to_write; 17, None; 18, block; 18, 19; 18, 21; 18, 30; 18, 39; 18, 80; 18, 90; 18, 104; 18, 129; 19, expression_statement; 19, 20; 20, string:'''
Write a Python dictionary as JSON to a file.
:param content: Dictionary of key-value pairs to save to a file
:param filepath: Path where the file is to be created
:param filename: Name of the file to be created
:param indent: You can use this to specify indent level for pretty printing the file
:param keys_to_write: array of keys that are to be picked from data and written to file.
Default is None, when all data is written to file.
:return: Path of file used
:raises OSError, EnvironmentError, ValueError
'''; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:path; 24, conditional_expression:if; 24, 25; 24, 26; 24, 27; 25, identifier:filepath; 26, identifier:filepath; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:filepath; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:name; 33, conditional_expression:if; 33, 34; 33, 35; 33, 36; 34, identifier:filename; 35, identifier:filename; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:filename; 39, if_statement; 39, 40; 39, 49; 40, not_operator; 40, 41; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:os; 45, identifier:path; 46, identifier:exists; 47, argument_list; 47, 48; 48, identifier:path; 49, block; 49, 50; 50, try_statement; 50, 51; 50, 59; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:os; 56, identifier:makedirs; 57, argument_list; 57, 58; 58, identifier:path; 59, except_clause; 59, 60; 59, 64; 60, as_pattern; 60, 61; 60, 62; 61, identifier:OSError; 62, as_pattern_target; 62, 63; 63, identifier:error; 64, block; 64, 65; 64, 79; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:logger; 71, identifier:error; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, string:"Error while creating directory: {}"; 76, identifier:format; 77, argument_list; 77, 78; 78, identifier:error; 79, raise_statement; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:name; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:_ends_with; 87, argument_list; 87, 88; 87, 89; 88, identifier:name; 89, string:".json"; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:path; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:_ends_with; 97, argument_list; 97, 98; 97, 99; 98, identifier:path; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:os; 102, identifier:path; 103, identifier:sep; 104, if_statement; 104, 105; 104, 106; 104, 123; 105, identifier:keys_to_write; 106, block; 106, 107; 106, 111; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:data_to_write; 110, dictionary; 111, for_statement; 111, 112; 111, 113; 111, 114; 112, identifier:key; 113, identifier:keys_to_write; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:data_to_write; 119, identifier:key; 120, subscript; 120, 121; 120, 122; 121, identifier:content; 122, identifier:key; 123, else_clause; 123, 124; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:data_to_write; 128, identifier:content; 129, try_statement; 129, 130; 129, 159; 129, 180; 130, block; 130, 131; 130, 138; 130, 149; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:indent; 134, conditional_expression:if; 134, 135; 134, 136; 134, 137; 135, identifier:indent; 136, identifier:indent; 137, integer:2; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:_write_json; 143, argument_list; 143, 144; 143, 145; 143, 146; 143, 147; 143, 148; 144, identifier:path; 145, identifier:name; 146, string:'w'; 147, identifier:data_to_write; 148, identifier:indent; 149, return_statement; 149, 150; 150, call; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:os; 154, identifier:path; 155, identifier:join; 156, argument_list; 156, 157; 156, 158; 157, identifier:path; 158, identifier:name; 159, except_clause; 159, 160; 159, 164; 160, as_pattern; 160, 161; 160, 162; 161, identifier:EnvironmentError; 162, as_pattern_target; 162, 163; 163, identifier:error; 164, block; 164, 165; 164, 179; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:logger; 171, identifier:error; 172, argument_list; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, string:"Error while opening or writing to file: {}"; 176, identifier:format; 177, argument_list; 177, 178; 178, identifier:error; 179, raise_statement; 180, except_clause; 180, 181; 180, 182; 181, identifier:ValueError; 182, block; 182, 183; 183, raise_statement | def write_file(self, content, filepath=None, filename=None, indent=None, keys_to_write=None):
'''
Write a Python dictionary as JSON to a file.
:param content: Dictionary of key-value pairs to save to a file
:param filepath: Path where the file is to be created
:param filename: Name of the file to be created
:param indent: You can use this to specify indent level for pretty printing the file
:param keys_to_write: array of keys that are to be picked from data and written to file.
Default is None, when all data is written to file.
:return: Path of file used
:raises OSError, EnvironmentError, ValueError
'''
path = filepath if filepath else self.filepath
name = filename if filename else self.filename
if not os.path.exists(path):
try:
os.makedirs(path)
except OSError as error:
self.logger.error("Error while creating directory: {}".format(error))
raise
name = self._ends_with(name, ".json")
path = self._ends_with(path, os.path.sep)
if keys_to_write:
data_to_write = {}
for key in keys_to_write:
data_to_write[key] = content[key]
else:
data_to_write = content
try:
indent = indent if indent else 2
self._write_json(path, name, 'w', data_to_write, indent)
return os.path.join(path, name)
except EnvironmentError as error:
self.logger.error("Error while opening or writing to file: {}".format(error))
raise
except ValueError:
raise |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:write_values; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:filepath; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:filename; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:indent; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:keys_to_write; 17, None; 18, block; 18, 19; 18, 28; 18, 37; 18, 47; 18, 61; 18, 112; 18, 137; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:name; 22, conditional_expression:if; 22, 23; 22, 24; 22, 25; 23, identifier:filename; 24, identifier:filename; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:filename; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:path; 31, conditional_expression:if; 31, 32; 31, 33; 31, 34; 32, identifier:filepath; 33, identifier:filepath; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:filepath; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:name; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:_ends_with; 44, argument_list; 44, 45; 44, 46; 45, identifier:name; 46, string:".json"; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:path; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_ends_with; 54, argument_list; 54, 55; 54, 56; 55, identifier:path; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:os; 59, identifier:path; 60, identifier:sep; 61, if_statement; 61, 62; 61, 73; 62, not_operator; 62, 63; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:os; 67, identifier:path; 68, identifier:isfile; 69, argument_list; 69, 70; 70, binary_operator:+; 70, 71; 70, 72; 71, identifier:path; 72, identifier:name; 73, block; 73, 74; 74, try_statement; 74, 75; 74, 87; 74, 108; 75, block; 75, 76; 76, return_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:write_file; 81, argument_list; 81, 82; 81, 83; 81, 84; 81, 85; 81, 86; 82, identifier:data; 83, identifier:path; 84, identifier:name; 85, identifier:indent; 86, identifier:keys_to_write; 87, except_clause; 87, 88; 87, 92; 88, as_pattern; 88, 89; 88, 90; 89, identifier:EnvironmentError; 90, as_pattern_target; 90, 91; 91, identifier:error; 92, block; 92, 93; 92, 107; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:logger; 99, identifier:error; 100, argument_list; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, string:"Error while opening or writing to file: {}"; 104, identifier:format; 105, argument_list; 105, 106; 106, identifier:error; 107, raise_statement; 108, except_clause; 108, 109; 108, 110; 109, identifier:ValueError; 110, block; 110, 111; 111, raise_statement; 112, if_statement; 112, 113; 112, 114; 112, 131; 113, identifier:keys_to_write; 114, block; 114, 115; 114, 119; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:data_to_write; 118, dictionary; 119, for_statement; 119, 120; 119, 121; 119, 122; 120, identifier:key; 121, identifier:keys_to_write; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:data_to_write; 127, identifier:key; 128, subscript; 128, 129; 128, 130; 129, identifier:data; 130, identifier:key; 131, else_clause; 131, 132; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:data_to_write; 136, identifier:data; 137, try_statement; 137, 138; 137, 253; 137, 274; 138, block; 138, 139; 138, 211; 138, 224; 138, 232; 138, 243; 139, with_statement; 139, 140; 139, 152; 140, with_clause; 140, 141; 141, with_item; 141, 142; 142, as_pattern; 142, 143; 142, 150; 143, call; 143, 144; 143, 145; 144, identifier:open; 145, argument_list; 145, 146; 145, 149; 146, binary_operator:+; 146, 147; 146, 148; 147, identifier:path; 148, identifier:name; 149, string:'r'; 150, as_pattern_target; 150, 151; 151, identifier:fil; 152, block; 152, 153; 152, 162; 152, 176; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:output; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:json; 159, identifier:load; 160, argument_list; 160, 161; 161, identifier:fil; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:logger; 168, identifier:info; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, string:"Read contents of {}"; 173, identifier:format; 174, argument_list; 174, 175; 175, identifier:filename; 176, for_statement; 176, 177; 176, 178; 176, 179; 177, identifier:key; 178, identifier:data_to_write; 179, block; 179, 180; 180, try_statement; 180, 181; 180, 190; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:output; 186, identifier:key; 187, subscript; 187, 188; 187, 189; 188, identifier:data_to_write; 189, identifier:key; 190, except_clause; 190, 191; 190, 195; 191, as_pattern; 191, 192; 191, 193; 192, identifier:TypeError; 193, as_pattern_target; 193, 194; 194, identifier:error; 195, block; 195, 196; 195, 210; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 203; 198, attribute; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:logger; 202, identifier:error; 203, argument_list; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, string:"File contents could not be serialized into a dict. {}"; 207, identifier:format; 208, argument_list; 208, 209; 209, identifier:error; 210, raise_statement; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:_write_json; 216, argument_list; 216, 217; 216, 218; 216, 221; 216, 222; 216, 223; 217, identifier:path; 218, binary_operator:+; 218, 219; 218, 220; 219, identifier:name; 220, string:".temp"; 221, string:"w"; 222, identifier:output; 223, identifier:indent; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:FileUtils; 228, identifier:remove_file; 229, argument_list; 229, 230; 229, 231; 230, identifier:name; 231, identifier:path; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:FileUtils; 236, identifier:rename_file; 237, argument_list; 237, 238; 237, 241; 237, 242; 238, binary_operator:+; 238, 239; 238, 240; 239, identifier:name; 240, string:'.temp'; 241, identifier:name; 242, identifier:path; 243, return_statement; 243, 244; 244, call; 244, 245; 244, 250; 245, attribute; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:os; 248, identifier:path; 249, identifier:join; 250, argument_list; 250, 251; 250, 252; 251, identifier:path; 252, identifier:name; 253, except_clause; 253, 254; 253, 258; 254, as_pattern; 254, 255; 254, 256; 255, identifier:EnvironmentError; 256, as_pattern_target; 256, 257; 257, identifier:error; 258, block; 258, 259; 258, 273; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:logger; 265, identifier:error; 266, argument_list; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, string:"Error while writing to, opening or reading the file: {}"; 270, identifier:format; 271, argument_list; 271, 272; 272, identifier:error; 273, raise_statement; 274, except_clause; 274, 275; 274, 279; 275, as_pattern; 275, 276; 275, 277; 276, identifier:ValueError; 277, as_pattern_target; 277, 278; 278, identifier:error; 279, block; 279, 280; 279, 294; 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:logger; 286, identifier:error; 287, argument_list; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, string:"File could not be decoded to JSON. It might be empty? {}"; 291, identifier:format; 292, argument_list; 292, 293; 293, identifier:error; 294, try_statement; 294, 295; 294, 317; 295, block; 295, 296; 295, 307; 296, expression_statement; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:self; 300, identifier:_write_json; 301, argument_list; 301, 302; 301, 303; 301, 304; 301, 305; 301, 306; 302, identifier:path; 303, identifier:name; 304, string:"w"; 305, identifier:data_to_write; 306, identifier:indent; 307, return_statement; 307, 308; 308, call; 308, 309; 308, 314; 309, attribute; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:os; 312, identifier:path; 313, identifier:join; 314, argument_list; 314, 315; 314, 316; 315, identifier:path; 316, identifier:name; 317, except_clause; 317, 318; 317, 319; 318, identifier:EnvironmentError; 319, block; 319, 320; 320, raise_statement | def write_values(self, data, filepath=None, filename=None, indent=None, keys_to_write=None):
name = filename if filename else self.filename
path = filepath if filepath else self.filepath
name = self._ends_with(name, ".json")
path = self._ends_with(path, os.path.sep)
if not os.path.isfile(path + name):
try:
return self.write_file(data, path, name, indent, keys_to_write)
except EnvironmentError as error:
self.logger.error("Error while opening or writing to file: {}".format(error))
raise
except ValueError:
raise
if keys_to_write:
data_to_write = {}
for key in keys_to_write:
data_to_write[key] = data[key]
else:
data_to_write = data
try:
with open(path + name, 'r') as fil:
output = json.load(fil)
self.logger.info("Read contents of {}".format(filename))
for key in data_to_write:
try:
output[key] = data_to_write[key]
except TypeError as error:
self.logger.error(
"File contents could not be serialized into a dict. {}".format(error))
raise
self._write_json(path, name + ".temp", "w", output, indent)
FileUtils.remove_file(name, path)
FileUtils.rename_file(name + '.temp', name, path)
return os.path.join(path, name)
except EnvironmentError as error:
self.logger.error(
"Error while writing to, opening or reading the file: {}".format(error))
raise
except ValueError as error:
self.logger.error(
"File could not be decoded to JSON. It might be empty? {}".format(error))
try:
self._write_json(path, name, "w", data_to_write, indent)
return os.path.join(path, name)
except EnvironmentError:
raise |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_resolve_requirements; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:requirements; 6, block; 6, 7; 6, 24; 6, 37; 6, 48; 6, 52; 6, 63; 6, 73; 6, 84; 6, 186; 6, 246; 6, 252; 7, try_statement; 7, 8; 7, 19; 8, block; 8, 9; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:dut_count; 12, subscript; 12, 13; 12, 18; 13, subscript; 13, 14; 13, 17; 14, subscript; 14, 15; 14, 16; 15, identifier:requirements; 16, string:"duts"; 17, string:"*"; 18, string:"count"; 19, except_clause; 19, 20; 19, 21; 20, identifier:KeyError; 21, block; 21, 22; 22, return_statement; 22, 23; 23, list:[]; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:default_values; 27, dictionary; 27, 28; 27, 31; 27, 34; 28, pair; 28, 29; 28, 30; 29, string:"type"; 30, string:"hardware"; 31, pair; 31, 32; 31, 33; 32, string:"allowed_platforms"; 33, list:[]; 34, pair; 34, 35; 34, 36; 35, string:"nick"; 36, None; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:default_values; 41, identifier:update; 42, argument_list; 42, 43; 43, subscript; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:requirements; 46, string:"duts"; 47, string:"*"; 48, delete_statement; 48, 49; 49, subscript; 49, 50; 49, 51; 50, identifier:default_values; 51, string:"count"; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:dut_keys; 55, call; 55, 56; 55, 57; 56, identifier:list; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:default_values; 61, identifier:keys; 62, argument_list; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:dut_keys; 67, identifier:extend; 68, argument_list; 68, 69; 69, list:["application", "location", "subtype"]; 69, 70; 69, 71; 69, 72; 70, string:"application"; 71, string:"location"; 72, string:"subtype"; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:dut_requirements; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:__generate_indexed_requirements; 80, argument_list; 80, 81; 80, 82; 80, 83; 81, identifier:dut_count; 82, identifier:default_values; 83, identifier:requirements; 84, for_statement; 84, 85; 84, 86; 84, 93; 85, identifier:key; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:requirements; 90, string:"duts"; 91, identifier:keys; 92, argument_list; 93, block; 93, 94; 93, 103; 93, 113; 94, if_statement; 94, 95; 94, 101; 95, not_operator; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:isinstance; 98, argument_list; 98, 99; 98, 100; 99, identifier:key; 100, identifier:string_types; 101, block; 101, 102; 102, continue_statement; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:match; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:re; 109, identifier:search; 110, argument_list; 110, 111; 110, 112; 111, string:r'([\d]{1,})\.\.([\d]{1,})'; 112, identifier:key; 113, if_statement; 113, 114; 113, 115; 114, identifier:match; 115, block; 115, 116; 115, 128; 115, 140; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:first_dut_idx; 119, call; 119, 120; 119, 121; 120, identifier:int; 121, argument_list; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:match; 125, identifier:group; 126, argument_list; 126, 127; 127, integer:1; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:last_dut_idx; 131, call; 131, 132; 131, 133; 132, identifier:int; 133, argument_list; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:match; 137, identifier:group; 138, argument_list; 138, 139; 139, integer:2; 140, for_statement; 140, 141; 140, 142; 140, 149; 141, identifier:i; 142, call; 142, 143; 142, 144; 143, identifier:range; 144, argument_list; 144, 145; 144, 146; 145, identifier:first_dut_idx; 146, binary_operator:+; 146, 147; 146, 148; 147, identifier:last_dut_idx; 148, integer:1; 149, block; 149, 150; 150, for_statement; 150, 151; 150, 152; 150, 153; 151, identifier:k; 152, identifier:dut_keys; 153, block; 153, 154; 154, if_statement; 154, 155; 154, 162; 155, comparison_operator:in; 155, 156; 155, 157; 156, identifier:k; 157, subscript; 157, 158; 157, 161; 158, subscript; 158, 159; 158, 160; 159, identifier:requirements; 160, string:"duts"; 161, identifier:key; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 172; 165, attribute; 165, 166; 165, 171; 166, subscript; 166, 167; 166, 168; 167, identifier:dut_requirements; 168, binary_operator:-; 168, 169; 168, 170; 169, identifier:i; 170, integer:1; 171, identifier:set; 172, argument_list; 172, 173; 172, 174; 173, identifier:k; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:copy; 177, identifier:copy; 178, argument_list; 178, 179; 179, subscript; 179, 180; 179, 185; 180, subscript; 180, 181; 180, 184; 181, subscript; 181, 182; 181, 183; 182, identifier:requirements; 183, string:"duts"; 184, identifier:key; 185, identifier:k; 186, for_statement; 186, 187; 186, 190; 186, 194; 187, pattern_list; 187, 188; 187, 189; 188, identifier:idx; 189, identifier:req; 190, call; 190, 191; 190, 192; 191, identifier:enumerate; 192, argument_list; 192, 193; 193, identifier:dut_requirements; 194, block; 194, 195; 194, 234; 195, if_statement; 195, 196; 195, 206; 196, call; 196, 197; 196, 198; 197, identifier:isinstance; 198, argument_list; 198, 199; 198, 205; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:req; 202, identifier:get; 203, argument_list; 203, 204; 204, string:"nick"; 205, identifier:string_types; 206, block; 206, 207; 206, 216; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:nick; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:req; 213, identifier:get; 214, argument_list; 214, 215; 215, string:"nick"; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:req; 220, identifier:set; 221, argument_list; 221, 222; 221, 223; 222, string:"nick"; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:ResourceConfig; 226, identifier:__replace_base_variables; 227, argument_list; 227, 228; 227, 229; 227, 233; 228, identifier:nick; 229, call; 229, 230; 229, 231; 230, identifier:len; 231, argument_list; 231, 232; 232, identifier:dut_requirements; 233, identifier:idx; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:self; 238, identifier:_solve_location; 239, argument_list; 239, 240; 239, 241; 239, 245; 240, identifier:req; 241, call; 241, 242; 241, 243; 242, identifier:len; 243, argument_list; 243, 244; 244, identifier:dut_requirements; 245, identifier:idx; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:_dut_requirements; 251, identifier:dut_requirements; 252, return_statement; 252, 253; 253, None | def _resolve_requirements(self, requirements):
try:
dut_count = requirements["duts"]["*"]["count"]
except KeyError:
return []
default_values = {
"type": "hardware",
"allowed_platforms": [],
"nick": None,
}
default_values.update(requirements["duts"]["*"])
del default_values["count"]
dut_keys = list(default_values.keys())
dut_keys.extend(["application", "location", "subtype"])
dut_requirements = self.__generate_indexed_requirements(dut_count,
default_values,
requirements)
for key in requirements["duts"].keys():
if not isinstance(key, string_types):
continue
match = re.search(r'([\d]{1,})\.\.([\d]{1,})', key)
if match:
first_dut_idx = int(match.group(1))
last_dut_idx = int(match.group(2))
for i in range(first_dut_idx, last_dut_idx+1):
for k in dut_keys:
if k in requirements["duts"][key]:
dut_requirements[i-1].set(k, copy.copy(requirements["duts"][key][k]))
for idx, req in enumerate(dut_requirements):
if isinstance(req.get("nick"), string_types):
nick = req.get("nick")
req.set("nick", ResourceConfig.__replace_base_variables(nick,
len(dut_requirements),
idx))
self._solve_location(req, len(dut_requirements), idx)
self._dut_requirements = dut_requirements
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:flash; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:binary_location; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:forceflash; 10, None; 11, block; 11, 12; 11, 30; 11, 74; 11, 96; 11, 104; 11, 113; 11, 130; 11, 271; 11, 290; 11, 298; 12, if_statement; 12, 13; 12, 15; 13, not_operator; 13, 14; 14, identifier:Flash; 15, block; 15, 16; 15, 25; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:logger; 22, identifier:error; 23, argument_list; 23, 24; 24, string:"Mbed-flasher not installed!"; 25, raise_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:ImportError; 28, argument_list; 28, 29; 29, string:"Mbed-flasher not installed!"; 30, try_statement; 30, 31; 30, 43; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:build; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:Build; 40, identifier:init; 41, argument_list; 41, 42; 42, identifier:binary_location; 43, except_clause; 43, 44; 43, 48; 44, as_pattern; 44, 45; 44, 46; 45, identifier:NotImplementedError; 46, as_pattern_target; 46, 47; 47, identifier:error; 48, block; 48, 49; 48, 60; 48, 69; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:logger; 55, identifier:error; 56, argument_list; 56, 57; 57, concatenated_string; 57, 58; 57, 59; 58, string:"Build initialization failed. "; 59, string:"Check your build location."; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:logger; 66, identifier:debug; 67, argument_list; 67, 68; 68, identifier:error; 69, raise_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:DutConnectionError; 72, argument_list; 72, 73; 73, identifier:error; 74, if_statement; 74, 75; 74, 84; 75, not_operator; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:_flash_needed; 80, argument_list; 80, 81; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:forceflash; 83, identifier:forceflash; 84, block; 84, 85; 84, 94; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:logger; 91, identifier:info; 92, argument_list; 92, 93; 93, string:"Skipping flash, not needed."; 94, return_statement; 94, 95; 95, True; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:logger; 99, call; 99, 100; 99, 101; 100, identifier:get_external_logger; 101, argument_list; 101, 102; 101, 103; 102, string:"mbed-flasher"; 103, string:"FLS"; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:flasher; 107, call; 107, 108; 107, 109; 108, identifier:Flash; 109, argument_list; 109, 110; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:logger; 112, identifier:logger; 113, if_statement; 113, 114; 113, 118; 114, not_operator; 114, 115; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:device; 118, block; 118, 119; 118, 128; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:logger; 125, identifier:error; 126, argument_list; 126, 127; 127, string:"Trying to flash device but device is not there?"; 128, return_statement; 128, 129; 129, False; 130, try_statement; 130, 131; 130, 201; 131, block; 131, 132; 131, 142; 131, 156; 131, 170; 131, 181; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:buildfile; 135, call; 135, 136; 135, 141; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:build; 140, identifier:get_file; 141, argument_list; 142, if_statement; 142, 143; 142, 145; 143, not_operator; 143, 144; 144, identifier:buildfile; 145, block; 145, 146; 146, raise_statement; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:DutConnectionError; 149, argument_list; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, string:"Binary {} not found"; 153, identifier:format; 154, argument_list; 154, 155; 155, identifier:buildfile; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:logger; 162, identifier:info; 163, argument_list; 163, 164; 163, 165; 164, string:'Flashing dev: %s'; 165, subscript; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:device; 169, string:'target_id'; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:target_id; 173, call; 173, 174; 173, 179; 174, attribute; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:device; 178, identifier:get; 179, argument_list; 179, 180; 180, string:"target_id"; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:retcode; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:flasher; 187, identifier:flash; 188, argument_list; 188, 189; 188, 192; 188, 195; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:build; 191, identifier:buildfile; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:target_id; 194, identifier:target_id; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:device_mapping_table; 197, list:[self.device]; 197, 198; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:device; 201, except_clause; 201, 202; 201, 206; 202, as_pattern; 202, 203; 202, 204; 203, identifier:FLASHER_ERRORS; 204, as_pattern_target; 204, 205; 205, identifier:error; 206, block; 206, 207; 206, 239; 206, 266; 207, if_statement; 207, 208; 207, 213; 207, 223; 208, comparison_operator:==; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:error; 211, identifier:__class__; 212, identifier:NotImplementedError; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 221; 216, attribute; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:self; 219, identifier:logger; 220, identifier:error; 221, argument_list; 221, 222; 222, string:"Flashing not supported for this platform!"; 223, elif_clause; 223, 224; 223, 229; 224, comparison_operator:==; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:error; 227, identifier:__class__; 228, identifier:SyntaxError; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 237; 232, attribute; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:logger; 236, identifier:error; 237, argument_list; 237, 238; 238, string:"target_id required by mbed-flasher!"; 239, if_statement; 239, 240; 239, 243; 240, comparison_operator:is; 240, 241; 240, 242; 241, identifier:FlashError; 242, None; 243, block; 243, 244; 244, if_statement; 244, 245; 244, 250; 245, comparison_operator:==; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:error; 248, identifier:__class__; 249, identifier:FlashError; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 258; 253, attribute; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:logger; 257, identifier:error; 258, argument_list; 258, 259; 258, 260; 258, 263; 259, string:"Flasher raised the following error: %s Error code: %i"; 260, attribute; 260, 261; 260, 262; 261, identifier:error; 262, identifier:message; 263, attribute; 263, 264; 263, 265; 264, identifier:error; 265, identifier:return_code; 266, raise_statement; 266, 267; 267, call; 267, 268; 267, 269; 268, identifier:DutConnectionError; 269, argument_list; 269, 270; 270, identifier:error; 271, if_statement; 271, 272; 271, 275; 272, comparison_operator:==; 272, 273; 272, 274; 273, identifier:retcode; 274, integer:0; 275, block; 275, 276; 275, 288; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 283; 278, attribute; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:dutinformation; 282, identifier:build_binary_sha1; 283, attribute; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:self; 286, identifier:build; 287, identifier:sha1; 288, return_statement; 288, 289; 289, True; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 297; 292, attribute; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:self; 295, identifier:dutinformation; 296, identifier:build_binary_sha1; 297, None; 298, return_statement; 298, 299; 299, False | def flash(self, binary_location=None, forceflash=None):
if not Flash:
self.logger.error("Mbed-flasher not installed!")
raise ImportError("Mbed-flasher not installed!")
try:
self.build = Build.init(binary_location)
except NotImplementedError as error:
self.logger.error("Build initialization failed. "
"Check your build location.")
self.logger.debug(error)
raise DutConnectionError(error)
if not self._flash_needed(forceflash=forceflash):
self.logger.info("Skipping flash, not needed.")
return True
logger = get_external_logger("mbed-flasher", "FLS")
flasher = Flash(logger=logger)
if not self.device:
self.logger.error("Trying to flash device but device is not there?")
return False
try:
buildfile = self.build.get_file()
if not buildfile:
raise DutConnectionError("Binary {} not found".format(buildfile))
self.logger.info('Flashing dev: %s', self.device['target_id'])
target_id = self.device.get("target_id")
retcode = flasher.flash(build=buildfile, target_id=target_id,
device_mapping_table=[self.device])
except FLASHER_ERRORS as error:
if error.__class__ == NotImplementedError:
self.logger.error("Flashing not supported for this platform!")
elif error.__class__ == SyntaxError:
self.logger.error("target_id required by mbed-flasher!")
if FlashError is not None:
if error.__class__ == FlashError:
self.logger.error("Flasher raised the following error: %s Error code: %i",
error.message, error.return_code)
raise DutConnectionError(error)
if retcode == 0:
self.dutinformation.build_binary_sha1 = self.build.sha1
return True
self.dutinformation.build_binary_sha1 = None
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:open_connection; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 18; 5, 46; 5, 64; 5, 82; 5, 197; 5, 251; 5, 264; 5, 282; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:is; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:readthread; 11, None; 12, block; 12, 13; 13, raise_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:DutConnectionError; 16, argument_list; 16, 17; 17, string:"Trying to open serial port which was already open"; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:logger; 24, identifier:info; 25, argument_list; 25, 26; 25, 40; 26, binary_operator:%; 26, 27; 26, 30; 27, concatenated_string; 27, 28; 27, 29; 28, string:"Open Connection "; 29, string:"for '%s' using '%s' baudrate: %d"; 30, tuple; 30, 31; 30, 34; 30, 37; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:dut_name; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:comport; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:serial_baudrate; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:extra; 42, dictionary; 42, 43; 43, pair; 43, 44; 43, 45; 44, string:'type'; 45, string:'<->'; 46, if_statement; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:serial_xonxoff; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:logger; 57, identifier:debug; 58, argument_list; 58, 59; 59, binary_operator:%; 59, 60; 59, 61; 60, string:"Use software flow control for dut: %s"; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:dut_name; 64, if_statement; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:serial_rtscts; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:logger; 75, identifier:debug; 76, argument_list; 76, 77; 77, binary_operator:%; 77, 78; 77, 79; 78, string:"Use hardware flow control for dut: %s"; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:dut_name; 82, try_statement; 82, 83; 82, 151; 82, 174; 83, block; 83, 84; 83, 95; 83, 105; 83, 115; 83, 125; 83, 135; 83, 143; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:port; 89, call; 89, 90; 89, 91; 90, identifier:EnhancedSerial; 91, argument_list; 91, 92; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:comport; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:port; 101, identifier:baudrate; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:serial_baudrate; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:port; 111, identifier:timeout; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:serial_timeout; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:port; 121, identifier:xonxoff; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:serial_xonxoff; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:port; 131, identifier:rtscts; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:serial_rtscts; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:port; 141, identifier:flushInput; 142, argument_list; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:port; 149, identifier:flushOutput; 150, argument_list; 151, except_clause; 151, 152; 151, 156; 152, as_pattern; 152, 153; 152, 154; 153, identifier:SerialException; 154, as_pattern_target; 154, 155; 155, identifier:err; 156, block; 156, 157; 156, 166; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:logger; 163, identifier:warning; 164, argument_list; 164, 165; 165, identifier:err; 166, raise_statement; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:DutConnectionError; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 172; 171, identifier:str; 172, argument_list; 172, 173; 173, identifier:err; 174, except_clause; 174, 175; 174, 179; 175, as_pattern; 175, 176; 175, 177; 176, identifier:ValueError; 177, as_pattern_target; 177, 178; 178, identifier:err; 179, block; 179, 180; 179, 189; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 187; 182, attribute; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:logger; 186, identifier:warning; 187, argument_list; 187, 188; 188, identifier:err; 189, raise_statement; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:ValueError; 192, argument_list; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:str; 195, argument_list; 195, 196; 196, identifier:err; 197, if_statement; 197, 198; 197, 201; 197, 234; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:ch_mode; 201, block; 201, 202; 201, 225; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:logger; 208, identifier:info; 209, argument_list; 209, 210; 209, 219; 210, binary_operator:%; 210, 211; 210, 212; 211, string:"Use chunk-mode with size %d, delay: %.3f when write data"; 212, tuple; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:ch_mode_chunk_size; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:ch_mode_ch_delay; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:extra; 221, dictionary; 221, 222; 222, pair; 222, 223; 222, 224; 223, string:'type'; 224, string:'<->'; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:time; 229, identifier:sleep; 230, argument_list; 230, 231; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:ch_mode_start_delay; 234, else_clause; 234, 235; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 243; 238, attribute; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:logger; 242, identifier:info; 243, argument_list; 243, 244; 243, 245; 244, string:"Use normal serial write mode"; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:extra; 247, dictionary; 247, 248; 248, pair; 248, 249; 248, 250; 249, string:'type'; 250, string:'<->'; 251, if_statement; 251, 252; 251, 257; 252, attribute; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:params; 256, identifier:reset; 257, block; 257, 258; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:reset; 263, argument_list; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:readthread; 269, call; 269, 270; 269, 271; 270, identifier:Thread; 271, argument_list; 271, 272; 271, 277; 272, keyword_argument; 272, 273; 272, 274; 273, identifier:name; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:name; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:target; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:run; 282, expression_statement; 282, 283; 283, call; 283, 284; 283, 289; 284, attribute; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:self; 287, identifier:readthread; 288, identifier:start; 289, argument_list | def open_connection(self):
if self.readthread is not None:
raise DutConnectionError("Trying to open serial port which was already open")
self.logger.info("Open Connection "
"for '%s' using '%s' baudrate: %d" % (self.dut_name,
self.comport,
self.serial_baudrate),
extra={'type': '<->'})
if self.serial_xonxoff:
self.logger.debug("Use software flow control for dut: %s" % self.dut_name)
if self.serial_rtscts:
self.logger.debug("Use hardware flow control for dut: %s" % self.dut_name)
try:
self.port = EnhancedSerial(self.comport)
self.port.baudrate = self.serial_baudrate
self.port.timeout = self.serial_timeout
self.port.xonxoff = self.serial_xonxoff
self.port.rtscts = self.serial_rtscts
self.port.flushInput()
self.port.flushOutput()
except SerialException as err:
self.logger.warning(err)
raise DutConnectionError(str(err))
except ValueError as err:
self.logger.warning(err)
raise ValueError(str(err))
if self.ch_mode:
self.logger.info("Use chunk-mode with size %d, delay: %.3f when write data" %
(self.ch_mode_chunk_size, self.ch_mode_ch_delay),
extra={'type': '<->'})
time.sleep(self.ch_mode_start_delay)
else:
self.logger.info("Use normal serial write mode", extra={'type': '<->'})
if self.params.reset:
self.reset()
self.readthread = Thread(name=self.name, target=self.run)
self.readthread.start() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:print_info; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 23; 5, 27; 5, 31; 5, 49; 5, 71; 5, 188; 5, 222; 5, 231; 5, 240; 5, 247; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:table; 9, call; 9, 10; 9, 11; 10, identifier:PrettyTable; 11, argument_list; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:start_string; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, string:"DutSerial {} \n"; 18, identifier:format; 19, argument_list; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:name; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:row; 26, list:[]; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:info_string; 30, string:""; 31, if_statement; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:config; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:info_string; 39, binary_operator:+; 39, 40; 39, 41; 40, identifier:info_string; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, string:"Configuration for this DUT:\n\n {} \n"; 44, identifier:format; 45, argument_list; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:config; 49, if_statement; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:comport; 53, block; 53, 54; 53, 62; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:table; 58, identifier:add_column; 59, argument_list; 59, 60; 59, 61; 60, string:"COM port"; 61, list:[]; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:row; 66, identifier:append; 67, argument_list; 67, 68; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:comport; 71, if_statement; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:port; 75, block; 75, 76; 75, 104; 75, 132; 75, 160; 76, if_statement; 76, 77; 76, 84; 77, call; 77, 78; 77, 79; 78, identifier:hasattr; 79, argument_list; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:port; 83, string:"baudrate"; 84, block; 84, 85; 84, 93; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:table; 89, identifier:add_column; 90, argument_list; 90, 91; 90, 92; 91, string:"Baudrate"; 92, list:[]; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:row; 97, identifier:append; 98, argument_list; 98, 99; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:port; 103, identifier:baudrate; 104, if_statement; 104, 105; 104, 112; 105, call; 105, 106; 105, 107; 106, identifier:hasattr; 107, argument_list; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:port; 111, string:"xonxoff"; 112, block; 112, 113; 112, 121; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:table; 117, identifier:add_column; 118, argument_list; 118, 119; 118, 120; 119, string:"XON/XOFF"; 120, list:[]; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:row; 125, identifier:append; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:port; 131, identifier:xonxoff; 132, if_statement; 132, 133; 132, 140; 133, call; 133, 134; 133, 135; 134, identifier:hasattr; 135, argument_list; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:port; 139, string:"timeout"; 140, block; 140, 141; 140, 149; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:table; 145, identifier:add_column; 146, argument_list; 146, 147; 146, 148; 147, string:"Timeout"; 148, list:[]; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:row; 153, identifier:append; 154, argument_list; 154, 155; 155, attribute; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:port; 159, identifier:timeout; 160, if_statement; 160, 161; 160, 168; 161, call; 161, 162; 161, 163; 162, identifier:hasattr; 163, argument_list; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:port; 167, string:"rtscts"; 168, block; 168, 169; 168, 177; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:table; 173, identifier:add_column; 174, argument_list; 174, 175; 174, 176; 175, string:"RTSCTS"; 176, list:[]; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:row; 181, identifier:append; 182, argument_list; 182, 183; 183, attribute; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:port; 187, identifier:rtscts; 188, if_statement; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:location; 192, block; 192, 193; 192, 201; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:table; 197, identifier:add_column; 198, argument_list; 198, 199; 198, 200; 199, string:"Location"; 200, list:[]; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:row; 205, identifier:append; 206, argument_list; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, string:"X = {}, Y = {}"; 210, identifier:format; 211, argument_list; 211, 212; 211, 217; 212, attribute; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:location; 216, identifier:x_coord; 217, attribute; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:location; 221, identifier:y_coord; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 229; 224, attribute; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:logger; 228, identifier:info; 229, argument_list; 229, 230; 230, identifier:start_string; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 238; 233, attribute; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:logger; 237, identifier:debug; 238, argument_list; 238, 239; 239, identifier:info_string; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:table; 244, identifier:add_row; 245, argument_list; 245, 246; 246, identifier:row; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 250; 249, identifier:print; 250, argument_list; 250, 251; 251, identifier:table | def print_info(self):
table = PrettyTable()
start_string = "DutSerial {} \n".format(self.name)
row = []
info_string = ""
if self.config:
info_string = info_string + "Configuration for this DUT:\n\n {} \n".format(self.config)
if self.comport:
table.add_column("COM port", [])
row.append(self.comport)
if self.port:
if hasattr(self.port, "baudrate"):
table.add_column("Baudrate", [])
row.append(self.port.baudrate)
if hasattr(self.port, "xonxoff"):
table.add_column("XON/XOFF", [])
row.append(self.port.xonxoff)
if hasattr(self.port, "timeout"):
table.add_column("Timeout", [])
row.append(self.port.timeout)
if hasattr(self.port, "rtscts"):
table.add_column("RTSCTS", [])
row.append(self.port.rtscts)
if self.location:
table.add_column("Location", [])
row.append("X = {}, Y = {}".format(self.location.x_coord, self.location.y_coord))
self.logger.info(start_string)
self.logger.debug(info_string)
table.add_row(row)
print(table) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:check; 3, parameters; 3, 4; 4, identifier:labels; 5, block; 5, 6; 5, 19; 5, 31; 5, 53; 5, 61; 5, 73; 5, 93; 5, 130; 6, if_statement; 6, 7; 6, 13; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 12; 11, identifier:labels; 12, identifier:list; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:IOError; 17, argument_list; 17, 18; 18, string:'labels are not in a list'; 19, if_statement; 19, 20; 19, 25; 20, not_operator; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:labels; 25, block; 25, 26; 26, raise_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:IOError; 29, argument_list; 29, 30; 30, string:'the labels list is empty'; 31, if_statement; 31, 32; 31, 47; 32, not_operator; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:all; 35, argument_list; 35, 36; 36, list_comprehension; 36, 37; 36, 44; 37, call; 37, 38; 37, 39; 38, identifier:isinstance; 39, argument_list; 39, 40; 39, 41; 40, identifier:l; 41, attribute; 41, 42; 41, 43; 42, identifier:np; 43, identifier:ndarray; 44, for_in_clause; 44, 45; 44, 46; 45, identifier:l; 46, identifier:labels; 47, block; 47, 48; 48, raise_statement; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:IOError; 51, argument_list; 51, 52; 52, string:'all labels must be numpy arrays'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:ndim; 56, attribute; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:labels; 59, integer:0; 60, identifier:ndim; 61, if_statement; 61, 62; 61, 67; 62, comparison_operator:not; 62, 63; 62, 64; 63, identifier:ndim; 64, list:[1, 2]; 64, 65; 64, 66; 65, integer:1; 66, integer:2; 67, block; 67, 68; 68, raise_statement; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:IOError; 71, argument_list; 71, 72; 72, string:'labels dimension must be 1 or 2'; 73, if_statement; 73, 74; 73, 87; 74, not_operator; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:all; 77, argument_list; 77, 78; 78, list_comprehension; 78, 79; 78, 84; 79, comparison_operator:==; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:l; 82, identifier:ndim; 83, identifier:ndim; 84, for_in_clause; 84, 85; 84, 86; 85, identifier:l; 86, identifier:labels; 87, block; 87, 88; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:IOError; 91, argument_list; 91, 92; 92, string:'all labels dimensions must be equal'; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:==; 94, 95; 94, 96; 95, identifier:ndim; 96, integer:2; 97, block; 97, 98; 97, 108; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:shape1; 101, subscript; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:labels; 105, integer:0; 106, identifier:shape; 107, integer:1; 108, if_statement; 108, 109; 108, 124; 109, not_operator; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:all; 112, argument_list; 112, 113; 113, list_comprehension; 113, 114; 113, 121; 114, comparison_operator:==; 114, 115; 114, 120; 115, subscript; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:l; 118, identifier:shape; 119, integer:1; 120, identifier:shape1; 121, for_in_clause; 121, 122; 121, 123; 122, identifier:l; 123, identifier:labels; 124, block; 124, 125; 125, raise_statement; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:IOError; 128, argument_list; 128, 129; 129, string:'all labels must have same shape on 2nd dim'; 130, for_statement; 130, 131; 130, 132; 130, 133; 131, identifier:label; 132, identifier:labels; 133, block; 133, 134; 133, 158; 133, 169; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:index; 137, parenthesized_expression; 137, 138; 138, conditional_expression:if; 138, 139; 138, 145; 138, 150; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:np; 142, identifier:argsort; 143, argument_list; 143, 144; 144, identifier:label; 145, comparison_operator:==; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:label; 148, identifier:ndim; 149, integer:1; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:np; 153, identifier:lexsort; 154, argument_list; 154, 155; 155, attribute; 155, 156; 155, 157; 156, identifier:label; 157, identifier:T; 158, assert_statement; 158, 159; 159, comparison_operator:==; 159, 160; 159, 164; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, identifier:index; 164, subscript; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:label; 167, identifier:shape; 168, integer:0; 169, if_statement; 169, 170; 169, 191; 170, not_operator; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:all; 173, generator_expression; 173, 174; 173, 179; 174, comparison_operator:==; 174, 175; 174, 176; 175, identifier:n; 176, subscript; 176, 177; 176, 178; 177, identifier:index; 178, identifier:n; 179, for_in_clause; 179, 180; 179, 181; 180, identifier:n; 181, call; 181, 182; 181, 183; 182, identifier:range; 183, argument_list; 183, 184; 184, binary_operator:-; 184, 185; 184, 190; 185, subscript; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:label; 188, identifier:shape; 189, integer:0; 190, integer:1; 191, block; 191, 192; 192, raise_statement; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:IOError; 195, argument_list; 195, 196; 196, string:'labels are not sorted in increasing order' | def check(labels):
if not isinstance(labels, list):
raise IOError('labels are not in a list')
if not len(labels):
raise IOError('the labels list is empty')
if not all([isinstance(l, np.ndarray) for l in labels]):
raise IOError('all labels must be numpy arrays')
ndim = labels[0].ndim
if ndim not in [1, 2]:
raise IOError('labels dimension must be 1 or 2')
if not all([l.ndim == ndim for l in labels]):
raise IOError('all labels dimensions must be equal')
if ndim == 2:
shape1 = labels[0].shape[1]
if not all([l.shape[1] == shape1 for l in labels]):
raise IOError('all labels must have same shape on 2nd dim')
for label in labels:
index = (np.argsort(label) if label.ndim == 1
else np.lexsort(label.T))
assert len(index) == label.shape[0]
if not all(n == index[n] for n in range(label.shape[0]-1)):
raise IOError('labels are not sorted in increasing order') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:write; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 4, identifier:filename; 5, identifier:groupname; 6, identifier:items; 7, identifier:times; 8, identifier:features; 9, default_parameter; 9, 10; 9, 11; 10, identifier:properties; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:dformat; 14, string:'dense'; 15, default_parameter; 15, 16; 15, 17; 16, identifier:chunk_size; 17, string:'auto'; 18, default_parameter; 18, 19; 18, 20; 19, identifier:sparsity; 20, float:0.1; 21, default_parameter; 21, 22; 21, 23; 22, identifier:mode; 23, string:'a'; 24, block; 24, 25; 24, 34; 24, 52; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:sparsity; 28, conditional_expression:if; 28, 29; 28, 30; 28, 33; 29, identifier:sparsity; 30, comparison_operator:==; 30, 31; 30, 32; 31, identifier:dformat; 32, string:'sparse'; 33, None; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:data; 37, call; 37, 38; 37, 39; 38, identifier:Data; 39, argument_list; 39, 40; 39, 41; 39, 42; 39, 43; 39, 46; 39, 49; 40, identifier:items; 41, identifier:times; 42, identifier:features; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:properties; 45, identifier:properties; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:sparsity; 48, identifier:sparsity; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:check; 51, True; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 63; 54, attribute; 54, 55; 54, 62; 55, call; 55, 56; 55, 57; 56, identifier:Writer; 57, argument_list; 57, 58; 57, 59; 58, identifier:filename; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:chunk_size; 61, identifier:chunk_size; 62, identifier:write; 63, argument_list; 63, 64; 63, 65; 63, 66; 64, identifier:data; 65, identifier:groupname; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:append; 68, True | def write(filename, groupname, items, times, features, properties=None,
dformat='dense', chunk_size='auto', sparsity=0.1, mode='a'):
sparsity = sparsity if dformat == 'sparse' else None
data = Data(items, times, features, properties=properties,
sparsity=sparsity, check=True)
Writer(filename, chunk_size=chunk_size).write(data, groupname, append=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:read; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:from_item; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:to_item; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:from_time; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:to_time; 16, None; 17, block; 17, 18; 17, 39; 17, 54; 17, 71; 17, 84; 17, 97; 17, 106; 17, 115; 17, 125; 17, 137; 17, 197; 17, 257; 17, 272; 17, 298; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:to_item; 21, None; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:to_item; 26, conditional_expression:if; 26, 27; 26, 35; 26, 38; 27, subscript; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:items; 32, identifier:data; 33, unary_operator:-; 33, 34; 34, integer:1; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:from_item; 37, None; 38, identifier:from_item; 39, if_statement; 39, 40; 39, 43; 40, comparison_operator:is; 40, 41; 40, 42; 41, identifier:from_item; 42, None; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:from_item; 47, subscript; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:items; 52, identifier:data; 53, integer:0; 54, if_statement; 54, 55; 54, 65; 55, not_operator; 55, 56; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:items; 61, identifier:is_valid_interval; 62, argument_list; 62, 63; 62, 64; 63, identifier:from_item; 64, identifier:to_item; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:IOError; 69, argument_list; 69, 70; 70, string:'cannot read items: not a valid interval'; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:from_idx; 74, call; 74, 75; 74, 82; 75, attribute; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:items; 80, identifier:data; 81, identifier:index; 82, argument_list; 82, 83; 83, identifier:from_item; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:to_idx; 87, call; 87, 88; 87, 95; 88, attribute; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:items; 93, identifier:data; 94, identifier:index; 95, argument_list; 95, 96; 96, identifier:to_item; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:from_pos; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:_get_item_position; 104, argument_list; 104, 105; 105, identifier:from_idx; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:to_pos; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:_get_item_position; 113, argument_list; 113, 114; 114, identifier:to_idx; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:lower; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:_get_from_time; 122, argument_list; 122, 123; 122, 124; 123, identifier:from_time; 124, identifier:from_pos; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:upper; 128, binary_operator:+; 128, 129; 128, 136; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:_get_to_time; 133, argument_list; 133, 134; 133, 135; 134, identifier:to_time; 135, identifier:to_pos; 136, integer:1; 137, if_statement; 137, 138; 137, 143; 137, 149; 138, comparison_operator:==; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:dformat; 142, string:'sparse'; 143, block; 143, 144; 144, raise_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:NotImplementedError; 147, argument_list; 147, 148; 148, string:'Reading sparse features not implemented'; 149, else_clause; 149, 150; 150, block; 150, 151; 150, 186; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:features; 154, parenthesized_expression; 154, 155; 155, conditional_expression:if; 155, 156; 155, 170; 155, 175; 156, attribute; 156, 157; 156, 169; 157, subscript; 157, 158; 157, 163; 157, 165; 158, subscript; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:group; 162, string:'features'; 163, slice; 163, 164; 164, colon; 165, slice; 165, 166; 165, 167; 165, 168; 166, identifier:lower; 167, colon; 168, identifier:upper; 169, identifier:T; 170, comparison_operator:==; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:version; 174, string:'0.1'; 175, subscript; 175, 176; 175, 181; 175, 185; 176, subscript; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:group; 180, string:'features'; 181, slice; 181, 182; 181, 183; 181, 184; 182, identifier:lower; 183, colon; 184, identifier:upper; 185, ellipsis:...; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:labels; 189, subscript; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:_labels_group; 193, slice; 193, 194; 193, 195; 193, 196; 194, identifier:lower; 195, colon; 196, identifier:upper; 197, if_statement; 197, 198; 197, 201; 197, 212; 198, comparison_operator:==; 198, 199; 198, 200; 199, identifier:to_idx; 200, identifier:from_idx; 201, block; 201, 202; 201, 207; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:features; 205, list:[features]; 205, 206; 206, identifier:features; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:labels; 210, list:[labels]; 210, 211; 211, identifier:labels; 212, else_clause; 212, 213; 213, block; 213, 214; 213, 231; 213, 244; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:item_ends; 217, binary_operator:+; 217, 218; 217, 230; 218, binary_operator:-; 218, 219; 218, 227; 219, subscript; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:_index; 223, slice; 223, 224; 223, 225; 223, 226; 224, identifier:from_idx; 225, colon; 226, identifier:to_idx; 227, subscript; 227, 228; 227, 229; 228, identifier:from_pos; 229, integer:0; 230, integer:1; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:features; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:np; 237, identifier:split; 238, argument_list; 238, 239; 238, 240; 238, 241; 239, identifier:features; 240, identifier:item_ends; 241, keyword_argument; 241, 242; 241, 243; 242, identifier:axis; 243, integer:0; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:labels; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:np; 250, identifier:split; 251, argument_list; 251, 252; 251, 253; 251, 254; 252, identifier:labels; 253, identifier:item_ends; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:axis; 256, integer:0; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:items; 260, subscript; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:items; 265, identifier:data; 266, slice; 266, 267; 266, 268; 266, 269; 267, identifier:from_idx; 268, colon; 269, binary_operator:+; 269, 270; 269, 271; 270, identifier:to_idx; 271, integer:1; 272, if_statement; 272, 273; 272, 278; 272, 283; 273, comparison_operator:is; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:properties; 277, None; 278, block; 278, 279; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:properties; 282, None; 283, else_clause; 283, 284; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:properties; 288, subscript; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:properties; 292, slice; 292, 293; 292, 294; 292, 295; 293, identifier:from_idx; 294, colon; 295, binary_operator:+; 295, 296; 295, 297; 296, identifier:to_idx; 297, integer:1; 298, return_statement; 298, 299; 299, call; 299, 300; 299, 301; 300, identifier:Data; 301, argument_list; 301, 302; 301, 303; 301, 304; 301, 305; 301, 308; 302, identifier:items; 303, identifier:labels; 304, identifier:features; 305, keyword_argument; 305, 306; 305, 307; 306, identifier:properties; 307, identifier:properties; 308, keyword_argument; 308, 309; 308, 310; 309, identifier:check; 310, False | def read(self, from_item=None, to_item=None,
from_time=None, to_time=None):
if to_item is None:
to_item = self.items.data[-1] if from_item is None else from_item
if from_item is None:
from_item = self.items.data[0]
if not self.items.is_valid_interval(from_item, to_item):
raise IOError('cannot read items: not a valid interval')
from_idx = self.items.data.index(from_item)
to_idx = self.items.data.index(to_item)
from_pos = self._get_item_position(from_idx)
to_pos = self._get_item_position(to_idx)
lower = self._get_from_time(from_time, from_pos)
upper = self._get_to_time(to_time, to_pos) + 1
if self.dformat == 'sparse':
raise NotImplementedError(
'Reading sparse features not implemented')
else:
features = (self.group['features'][:, lower:upper].T
if self.version == '0.1'
else self.group['features'][lower:upper, ...])
labels = self._labels_group[lower:upper]
if to_idx == from_idx:
features = [features]
labels = [labels]
else:
item_ends = self._index[from_idx:to_idx] - from_pos[0] + 1
features = np.split(features, item_ends, axis=0)
labels = np.split(labels, item_ends, axis=0)
items = self.items.data[from_idx:to_idx + 1]
if self.properties is None:
properties = None
else:
properties = self.properties[from_idx:to_idx + 1]
return Data(
items, labels, features, properties=properties, check=False) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 5, 32; 5, 48; 5, 373; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:d; 9, call; 9, 10; 9, 11; 10, identifier:dict; 11, argument_list; 11, 12; 11, 15; 11, 18; 11, 21; 11, 24; 11, 27; 12, keyword_argument; 12, 13; 12, 14; 13, identifier:ninputs; 14, None; 15, keyword_argument; 15, 16; 15, 17; 16, identifier:noutputs; 17, None; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:input_labels; 20, None; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:output_labels; 23, None; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:intype; 26, None; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:cover; 29, call; 29, 30; 29, 31; 30, identifier:set; 31, argument_list; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:lines; 35, list_comprehension; 35, 36; 35, 41; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:line; 39, identifier:strip; 40, argument_list; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:line; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:s; 46, identifier:splitlines; 47, argument_list; 48, for_statement; 48, 49; 48, 52; 48, 59; 49, pattern_list; 49, 50; 49, 51; 50, identifier:i; 51, identifier:line; 52, call; 52, 53; 52, 54; 53, identifier:enumerate; 54, argument_list; 54, 55; 54, 56; 55, identifier:lines; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:start; 58, integer:1; 59, block; 59, 60; 59, 72; 59, 81; 59, 113; 59, 122; 59, 154; 59, 163; 59, 167; 59, 176; 59, 209; 59, 218; 59, 251; 59, 260; 59, 291; 59, 300; 59, 349; 59, 358; 59, 362; 60, if_statement; 60, 61; 60, 70; 61, boolean_operator:or; 61, 62; 61, 64; 62, not_operator; 62, 63; 63, identifier:line; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:_COMMENT; 67, identifier:match; 68, argument_list; 68, 69; 69, identifier:line; 70, block; 70, 71; 71, continue_statement; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:m_in; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:_NINS; 78, identifier:match; 79, argument_list; 79, 80; 80, identifier:line; 81, if_statement; 81, 82; 81, 83; 82, identifier:m_in; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 90; 84, 106; 85, comparison_operator:is; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:d; 88, string:'ninputs'; 89, None; 90, block; 90, 91; 90, 105; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:d; 95, string:'ninputs'; 96, call; 96, 97; 96, 98; 97, identifier:int; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:m_in; 102, identifier:group; 103, argument_list; 103, 104; 104, integer:1; 105, continue_statement; 106, else_clause; 106, 107; 107, block; 107, 108; 108, raise_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:Error; 111, argument_list; 111, 112; 112, string:".i declared more than once"; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:m_out; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:_NOUTS; 119, identifier:match; 120, argument_list; 120, 121; 121, identifier:line; 122, if_statement; 122, 123; 122, 124; 123, identifier:m_out; 124, block; 124, 125; 125, if_statement; 125, 126; 125, 131; 125, 147; 126, comparison_operator:is; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:d; 129, string:'noutputs'; 130, None; 131, block; 131, 132; 131, 146; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:d; 136, string:'noutputs'; 137, call; 137, 138; 137, 139; 138, identifier:int; 139, argument_list; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:m_out; 143, identifier:group; 144, argument_list; 144, 145; 145, integer:1; 146, continue_statement; 147, else_clause; 147, 148; 148, block; 148, 149; 149, raise_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:Error; 152, argument_list; 152, 153; 153, string:".o declared more than once"; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:m_prod; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:_PROD; 160, identifier:match; 161, argument_list; 161, 162; 162, identifier:line; 163, if_statement; 163, 164; 163, 165; 164, identifier:m_prod; 165, block; 165, 166; 166, continue_statement; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:m_ilb; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:_ILB; 173, identifier:match; 174, argument_list; 174, 175; 175, identifier:line; 176, if_statement; 176, 177; 176, 178; 177, identifier:m_ilb; 178, block; 178, 179; 179, if_statement; 179, 180; 179, 185; 179, 202; 180, comparison_operator:is; 180, 181; 180, 184; 181, subscript; 181, 182; 181, 183; 182, identifier:d; 183, string:'input_labels'; 184, None; 185, block; 185, 186; 185, 201; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 191; 188, subscript; 188, 189; 188, 190; 189, identifier:d; 190, string:'input_labels'; 191, call; 191, 192; 191, 200; 192, attribute; 192, 193; 192, 199; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:m_ilb; 196, identifier:group; 197, argument_list; 197, 198; 198, integer:1; 199, identifier:split; 200, argument_list; 201, continue_statement; 202, else_clause; 202, 203; 203, block; 203, 204; 204, raise_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:Error; 207, argument_list; 207, 208; 208, string:".ilb declared more than once"; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:m_ob; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:_OB; 215, identifier:match; 216, argument_list; 216, 217; 217, identifier:line; 218, if_statement; 218, 219; 218, 220; 219, identifier:m_ob; 220, block; 220, 221; 221, if_statement; 221, 222; 221, 227; 221, 244; 222, comparison_operator:is; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:d; 225, string:'output_labels'; 226, None; 227, block; 227, 228; 227, 243; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 233; 230, subscript; 230, 231; 230, 232; 231, identifier:d; 232, string:'output_labels'; 233, call; 233, 234; 233, 242; 234, attribute; 234, 235; 234, 241; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:m_ob; 238, identifier:group; 239, argument_list; 239, 240; 240, integer:1; 241, identifier:split; 242, argument_list; 243, continue_statement; 244, else_clause; 244, 245; 245, block; 245, 246; 246, raise_statement; 246, 247; 247, call; 247, 248; 247, 249; 248, identifier:Error; 249, argument_list; 249, 250; 250, string:".ob declared more than once"; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:m_type; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:_TYPE; 257, identifier:match; 258, argument_list; 258, 259; 259, identifier:line; 260, if_statement; 260, 261; 260, 262; 261, identifier:m_type; 262, block; 262, 263; 263, if_statement; 263, 264; 263, 269; 263, 284; 264, comparison_operator:is; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:d; 267, string:'intype'; 268, None; 269, block; 269, 270; 269, 283; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 275; 272, subscript; 272, 273; 272, 274; 273, identifier:d; 274, string:'intype'; 275, subscript; 275, 276; 275, 277; 276, identifier:_TYPES; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:m_type; 280, identifier:group; 281, argument_list; 281, 282; 282, integer:1; 283, continue_statement; 284, else_clause; 284, 285; 285, block; 285, 286; 286, raise_statement; 286, 287; 287, call; 287, 288; 287, 289; 288, identifier:Error; 289, argument_list; 289, 290; 290, string:".type declared more tha once"; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:m_cube; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:_CUBE; 297, identifier:match; 298, argument_list; 298, 299; 299, identifier:line; 300, if_statement; 300, 301; 300, 302; 301, identifier:m_cube; 302, block; 302, 303; 302, 313; 302, 325; 302, 337; 302, 348; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 308; 305, pattern_list; 305, 306; 305, 307; 306, identifier:inputs; 307, identifier:outputs; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:m_cube; 311, identifier:groups; 312, argument_list; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:invec; 316, call; 316, 317; 316, 318; 317, identifier:tuple; 318, generator_expression; 318, 319; 318, 322; 319, subscript; 319, 320; 319, 321; 320, identifier:_INCODE; 321, identifier:c; 322, for_in_clause; 322, 323; 322, 324; 323, identifier:c; 324, identifier:inputs; 325, expression_statement; 325, 326; 326, assignment; 326, 327; 326, 328; 327, identifier:outvec; 328, call; 328, 329; 328, 330; 329, identifier:tuple; 330, generator_expression; 330, 331; 330, 334; 331, subscript; 331, 332; 331, 333; 332, identifier:_OUTCODE; 333, identifier:c; 334, for_in_clause; 334, 335; 334, 336; 335, identifier:c; 336, identifier:outputs; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 344; 339, attribute; 339, 340; 339, 343; 340, subscript; 340, 341; 340, 342; 341, identifier:d; 342, string:'cover'; 343, identifier:add; 344, argument_list; 344, 345; 345, tuple; 345, 346; 345, 347; 346, identifier:invec; 347, identifier:outvec; 348, continue_statement; 349, expression_statement; 349, 350; 350, assignment; 350, 351; 350, 352; 351, identifier:m_end; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:_END; 355, identifier:match; 356, argument_list; 356, 357; 357, identifier:line; 358, if_statement; 358, 359; 358, 360; 359, identifier:m_end; 360, block; 360, 361; 361, continue_statement; 362, raise_statement; 362, 363; 363, call; 363, 364; 363, 365; 364, identifier:Error; 365, argument_list; 365, 366; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, string:"syntax error on line {}: {}"; 369, identifier:format; 370, argument_list; 370, 371; 370, 372; 371, identifier:i; 372, identifier:line; 373, return_statement; 373, 374; 374, identifier:d | def parse(s):
d = dict(ninputs=None, noutputs=None,
input_labels=None, output_labels=None,
intype=None, cover=set())
lines = [line.strip() for line in s.splitlines()]
for i, line in enumerate(lines, start=1):
if not line or _COMMENT.match(line):
continue
m_in = _NINS.match(line)
if m_in:
if d['ninputs'] is None:
d['ninputs'] = int(m_in.group(1))
continue
else:
raise Error(".i declared more than once")
m_out = _NOUTS.match(line)
if m_out:
if d['noutputs'] is None:
d['noutputs'] = int(m_out.group(1))
continue
else:
raise Error(".o declared more than once")
m_prod = _PROD.match(line)
if m_prod:
continue
m_ilb = _ILB.match(line)
if m_ilb:
if d['input_labels'] is None:
d['input_labels'] = m_ilb.group(1).split()
continue
else:
raise Error(".ilb declared more than once")
m_ob = _OB.match(line)
if m_ob:
if d['output_labels'] is None:
d['output_labels'] = m_ob.group(1).split()
continue
else:
raise Error(".ob declared more than once")
m_type = _TYPE.match(line)
if m_type:
if d['intype'] is None:
d['intype'] = _TYPES[m_type.group(1)]
continue
else:
raise Error(".type declared more tha once")
m_cube = _CUBE.match(line)
if m_cube:
inputs, outputs = m_cube.groups()
invec = tuple(_INCODE[c] for c in inputs)
outvec = tuple(_OUTCODE[c] for c in outputs)
d['cover'].add((invec, outvec))
continue
m_end = _END.match(line)
if m_end:
continue
raise Error("syntax error on line {}: {}".format(i, line))
return d |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:var; 3, parameters; 3, 4; 3, 5; 4, identifier:name; 5, default_parameter; 5, 6; 5, 7; 6, identifier:index; 7, None; 8, block; 8, 9; 8, 16; 8, 51; 8, 60; 8, 90; 8, 145; 8, 194; 8, 223; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:tname; 12, call; 12, 13; 12, 14; 13, identifier:type; 14, argument_list; 14, 15; 15, identifier:name; 16, if_statement; 16, 17; 16, 20; 16, 26; 16, 35; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:tname; 19, identifier:str; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:names; 24, tuple; 24, 25; 25, identifier:name; 26, elif_clause; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:tname; 29, identifier:tuple; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:names; 34, identifier:name; 35, else_clause; 35, 36; 36, block; 36, 37; 36, 41; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:fstr; 40, string:"expected name to be a str or tuple, got {0.__name__}"; 41, raise_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:TypeError; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:fstr; 48, identifier:format; 49, argument_list; 49, 50; 50, identifier:tname; 51, if_statement; 51, 52; 51, 54; 52, not_operator; 52, 53; 53, identifier:names; 54, block; 54, 55; 55, raise_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:ValueError; 58, argument_list; 58, 59; 59, string:"expected at least one name"; 60, for_statement; 60, 61; 60, 62; 60, 63; 61, identifier:name; 62, identifier:names; 63, block; 63, 64; 63, 71; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:tname; 67, call; 67, 68; 67, 69; 68, identifier:type; 69, argument_list; 69, 70; 70, identifier:name; 71, if_statement; 71, 72; 71, 75; 72, comparison_operator:is; 72, 73; 72, 74; 73, identifier:tname; 74, identifier:str; 75, block; 75, 76; 75, 80; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:fstr; 79, string:"expected name to be a str, got {0.__name__}"; 80, raise_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:TypeError; 83, argument_list; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:fstr; 87, identifier:format; 88, argument_list; 88, 89; 89, identifier:tname; 90, if_statement; 90, 91; 90, 94; 90, 101; 91, comparison_operator:is; 91, 92; 91, 93; 92, identifier:index; 93, None; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:indices; 98, call; 98, 99; 98, 100; 99, identifier:tuple; 100, argument_list; 101, else_clause; 101, 102; 102, block; 102, 103; 102, 110; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:tindex; 106, call; 106, 107; 106, 108; 107, identifier:type; 108, argument_list; 108, 109; 109, identifier:index; 110, if_statement; 110, 111; 110, 114; 110, 120; 110, 129; 111, comparison_operator:is; 111, 112; 111, 113; 112, identifier:tindex; 113, identifier:int; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:indices; 118, tuple; 118, 119; 119, identifier:index; 120, elif_clause; 120, 121; 120, 124; 121, comparison_operator:is; 121, 122; 121, 123; 122, identifier:tindex; 123, identifier:tuple; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:indices; 128, identifier:index; 129, else_clause; 129, 130; 130, block; 130, 131; 130, 135; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:fstr; 134, string:"expected index to be an int or tuple, got {0.__name__}"; 135, raise_statement; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:TypeError; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:fstr; 142, identifier:format; 143, argument_list; 143, 144; 144, identifier:tindex; 145, for_statement; 145, 146; 145, 147; 145, 148; 146, identifier:index; 147, identifier:indices; 148, block; 148, 149; 148, 156; 148, 175; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:tindex; 152, call; 152, 153; 152, 154; 153, identifier:type; 154, argument_list; 154, 155; 155, identifier:index; 156, if_statement; 156, 157; 156, 160; 157, comparison_operator:is; 157, 158; 157, 159; 158, identifier:tindex; 159, identifier:int; 160, block; 160, 161; 160, 165; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:fstr; 164, string:"expected index to be an int, got {0.__name__}"; 165, raise_statement; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:TypeError; 168, argument_list; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:fstr; 172, identifier:format; 173, argument_list; 173, 174; 174, identifier:tindex; 175, if_statement; 175, 176; 175, 179; 176, comparison_operator:<; 176, 177; 176, 178; 177, identifier:index; 178, integer:0; 179, block; 179, 180; 179, 184; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:fstr; 183, string:"expected index to be >= 0, got {}"; 184, raise_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:ValueError; 187, argument_list; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:fstr; 191, identifier:format; 192, argument_list; 192, 193; 193, identifier:index; 194, try_statement; 194, 195; 194, 204; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:v; 199, subscript; 199, 200; 199, 201; 200, identifier:VARIABLES; 201, tuple; 201, 202; 201, 203; 202, identifier:names; 203, identifier:indices; 204, except_clause; 204, 205; 204, 206; 205, identifier:KeyError; 206, block; 206, 207; 206, 215; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:v; 210, call; 210, 211; 210, 212; 211, identifier:Variable; 212, argument_list; 212, 213; 212, 214; 213, identifier:names; 214, identifier:indices; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 222; 217, subscript; 217, 218; 217, 219; 218, identifier:VARIABLES; 219, tuple; 219, 220; 219, 221; 220, identifier:names; 221, identifier:indices; 222, identifier:v; 223, return_statement; 223, 224; 224, identifier:v | def var(name, index=None):
tname = type(name)
if tname is str:
names = (name, )
elif tname is tuple:
names = name
else:
fstr = "expected name to be a str or tuple, got {0.__name__}"
raise TypeError(fstr.format(tname))
if not names:
raise ValueError("expected at least one name")
for name in names:
tname = type(name)
if tname is not str:
fstr = "expected name to be a str, got {0.__name__}"
raise TypeError(fstr.format(tname))
if index is None:
indices = tuple()
else:
tindex = type(index)
if tindex is int:
indices = (index, )
elif tindex is tuple:
indices = index
else:
fstr = "expected index to be an int or tuple, got {0.__name__}"
raise TypeError(fstr.format(tindex))
for index in indices:
tindex = type(index)
if tindex is not int:
fstr = "expected index to be an int, got {0.__name__}"
raise TypeError(fstr.format(tindex))
if index < 0:
fstr = "expected index to be >= 0, got {}"
raise ValueError(fstr.format(index))
try:
v = VARIABLES[(names, indices)]
except KeyError:
v = Variable(names, indices)
VARIABLES[(names, indices)] = v
return v |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_itemize; 3, parameters; 3, 4; 4, identifier:objs; 5, block; 5, 6; 5, 21; 5, 35; 6, if_statement; 6, 7; 6, 15; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 12; 11, identifier:objs; 12, attribute; 12, 13; 12, 14; 13, identifier:collections; 14, identifier:Sequence; 15, block; 15, 16; 16, raise_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:TypeError; 19, argument_list; 19, 20; 20, string:"expected a sequence of Function"; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:isseq; 24, list_comprehension; 24, 25; 24, 32; 25, call; 25, 26; 25, 27; 26, identifier:isinstance; 27, argument_list; 27, 28; 27, 29; 28, identifier:obj; 29, attribute; 29, 30; 29, 31; 30, identifier:collections; 31, identifier:Sequence; 32, for_in_clause; 32, 33; 32, 34; 33, identifier:obj; 34, identifier:objs; 35, if_statement; 35, 36; 35, 41; 35, 122; 35, 215; 36, not_operator; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:any; 39, argument_list; 39, 40; 40, identifier:isseq; 41, block; 41, 42; 41, 46; 41, 108; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:ftype; 45, None; 46, for_statement; 46, 47; 46, 48; 46, 49; 47, identifier:obj; 48, identifier:objs; 49, block; 49, 50; 50, if_statement; 50, 51; 50, 54; 50, 95; 51, comparison_operator:is; 51, 52; 51, 53; 52, identifier:ftype; 53, None; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 61; 55, 66; 55, 77; 55, 88; 56, call; 56, 57; 56, 58; 57, identifier:isinstance; 58, argument_list; 58, 59; 58, 60; 59, identifier:obj; 60, identifier:BinaryDecisionDiagram; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:ftype; 65, identifier:BinaryDecisionDiagram; 66, elif_clause; 66, 67; 66, 72; 67, call; 67, 68; 67, 69; 68, identifier:isinstance; 69, argument_list; 69, 70; 69, 71; 70, identifier:obj; 71, identifier:Expression; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:ftype; 76, identifier:Expression; 77, elif_clause; 77, 78; 77, 83; 78, call; 78, 79; 78, 80; 79, identifier:isinstance; 80, argument_list; 80, 81; 80, 82; 81, identifier:obj; 82, identifier:TruthTable; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:ftype; 87, identifier:TruthTable; 88, else_clause; 88, 89; 89, block; 89, 90; 90, raise_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:TypeError; 93, argument_list; 93, 94; 94, string:"expected valid Function inputs"; 95, elif_clause; 95, 96; 95, 102; 96, not_operator; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:isinstance; 99, argument_list; 99, 100; 99, 101; 100, identifier:obj; 101, identifier:ftype; 102, block; 102, 103; 103, raise_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:ValueError; 106, argument_list; 106, 107; 107, string:"expected uniform Function types"; 108, return_statement; 108, 109; 109, expression_list; 109, 110; 109, 114; 109, 121; 110, call; 110, 111; 110, 112; 111, identifier:list; 112, argument_list; 112, 113; 113, identifier:objs; 114, tuple; 114, 115; 115, tuple; 115, 116; 115, 117; 116, integer:0; 117, call; 117, 118; 117, 119; 118, identifier:len; 119, argument_list; 119, 120; 120, identifier:objs; 121, identifier:ftype; 122, elif_clause; 122, 123; 122, 127; 123, call; 123, 124; 123, 125; 124, identifier:all; 125, argument_list; 125, 126; 126, identifier:isseq; 127, block; 127, 128; 127, 134; 127, 138; 127, 142; 127, 198; 127, 210; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:items; 131, call; 131, 132; 131, 133; 132, identifier:list; 133, argument_list; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:shape; 137, None; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:ftype; 141, None; 142, for_statement; 142, 143; 142, 144; 142, 145; 143, identifier:obj; 144, identifier:objs; 145, block; 145, 146; 145, 156; 145, 175; 145, 194; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 152; 148, pattern_list; 148, 149; 148, 150; 148, 151; 149, identifier:_items; 150, identifier:_shape; 151, identifier:_ftype; 152, call; 152, 153; 152, 154; 153, identifier:_itemize; 154, argument_list; 154, 155; 155, identifier:obj; 156, if_statement; 156, 157; 156, 160; 156, 165; 157, comparison_operator:is; 157, 158; 157, 159; 158, identifier:shape; 159, None; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:shape; 164, identifier:_shape; 165, elif_clause; 165, 166; 165, 169; 166, comparison_operator:!=; 166, 167; 166, 168; 167, identifier:shape; 168, identifier:_shape; 169, block; 169, 170; 170, raise_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:ValueError; 173, argument_list; 173, 174; 174, string:"expected uniform farray dimensions"; 175, if_statement; 175, 176; 175, 179; 175, 184; 176, comparison_operator:is; 176, 177; 176, 178; 177, identifier:ftype; 178, None; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:ftype; 183, identifier:_ftype; 184, elif_clause; 184, 185; 184, 188; 185, comparison_operator:!=; 185, 186; 185, 187; 186, identifier:ftype; 187, identifier:_ftype; 188, block; 188, 189; 189, raise_statement; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:ValueError; 192, argument_list; 192, 193; 193, string:"expected uniform Function types"; 194, expression_statement; 194, 195; 195, augmented_assignment:+=; 195, 196; 195, 197; 196, identifier:items; 197, identifier:_items; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:shape; 201, binary_operator:+; 201, 202; 201, 209; 202, tuple; 202, 203; 203, tuple; 203, 204; 203, 205; 204, integer:0; 205, call; 205, 206; 205, 207; 206, identifier:len; 207, argument_list; 207, 208; 208, identifier:objs; 209, identifier:shape; 210, return_statement; 210, 211; 211, expression_list; 211, 212; 211, 213; 211, 214; 212, identifier:items; 213, identifier:shape; 214, identifier:ftype; 215, else_clause; 215, 216; 216, block; 216, 217; 217, raise_statement; 217, 218; 218, call; 218, 219; 218, 220; 219, identifier:ValueError; 220, argument_list; 220, 221; 221, string:"expected uniform farray dimensions" | def _itemize(objs):
if not isinstance(objs, collections.Sequence):
raise TypeError("expected a sequence of Function")
isseq = [isinstance(obj, collections.Sequence) for obj in objs]
if not any(isseq):
ftype = None
for obj in objs:
if ftype is None:
if isinstance(obj, BinaryDecisionDiagram):
ftype = BinaryDecisionDiagram
elif isinstance(obj, Expression):
ftype = Expression
elif isinstance(obj, TruthTable):
ftype = TruthTable
else:
raise TypeError("expected valid Function inputs")
elif not isinstance(obj, ftype):
raise ValueError("expected uniform Function types")
return list(objs), ((0, len(objs)), ), ftype
elif all(isseq):
items = list()
shape = None
ftype = None
for obj in objs:
_items, _shape, _ftype = _itemize(obj)
if shape is None:
shape = _shape
elif shape != _shape:
raise ValueError("expected uniform farray dimensions")
if ftype is None:
ftype = _ftype
elif ftype != _ftype:
raise ValueError("expected uniform Function types")
items += _items
shape = ((0, len(objs)), ) + shape
return items, shape, ftype
else:
raise ValueError("expected uniform farray dimensions") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_filtdim; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:items; 5, identifier:shape; 6, identifier:dim; 7, identifier:nsl; 8, block; 8, 9; 8, 23; 8, 30; 8, 36; 8, 52; 8, 61; 8, 67; 8, 341; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:normshape; 12, call; 12, 13; 12, 14; 13, identifier:tuple; 14, generator_expression; 14, 15; 14, 18; 15, binary_operator:-; 15, 16; 15, 17; 16, identifier:stop; 17, identifier:start; 18, for_in_clause; 18, 19; 18, 22; 19, pattern_list; 19, 20; 19, 21; 20, identifier:start; 21, identifier:stop; 22, identifier:shape; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:nsl_type; 26, call; 26, 27; 26, 28; 27, identifier:type; 28, argument_list; 28, 29; 29, identifier:nsl; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:newitems; 33, call; 33, 34; 33, 35; 34, identifier:list; 35, argument_list; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:num; 39, call; 39, 40; 39, 41; 40, identifier:reduce; 41, argument_list; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:operator; 44, identifier:mul; 45, subscript; 45, 46; 45, 47; 46, identifier:normshape; 47, slice; 47, 48; 47, 49; 48, colon; 49, binary_operator:+; 49, 50; 49, 51; 50, identifier:dim; 51, integer:1; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:size; 55, binary_operator://; 55, 56; 55, 60; 56, call; 56, 57; 56, 58; 57, identifier:len; 58, argument_list; 58, 59; 59, identifier:items; 60, identifier:num; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:n; 64, subscript; 64, 65; 64, 66; 65, identifier:normshape; 66, identifier:dim; 67, if_statement; 67, 68; 67, 71; 67, 118; 67, 200; 68, comparison_operator:is; 68, 69; 68, 70; 69, identifier:nsl_type; 70, identifier:int; 71, block; 71, 72; 71, 102; 72, for_statement; 72, 73; 72, 74; 72, 78; 73, identifier:i; 74, call; 74, 75; 74, 76; 75, identifier:range; 76, argument_list; 76, 77; 77, identifier:num; 78, block; 78, 79; 79, if_statement; 79, 80; 79, 85; 80, comparison_operator:==; 80, 81; 80, 84; 81, binary_operator:%; 81, 82; 81, 83; 82, identifier:i; 83, identifier:n; 84, identifier:nsl; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, augmented_assignment:+=; 87, 88; 87, 89; 88, identifier:newitems; 89, subscript; 89, 90; 89, 91; 90, identifier:items; 91, slice; 91, 92; 91, 95; 91, 96; 92, binary_operator:*; 92, 93; 92, 94; 93, identifier:size; 94, identifier:i; 95, colon; 96, binary_operator:*; 96, 97; 96, 98; 97, identifier:size; 98, parenthesized_expression; 98, 99; 99, binary_operator:+; 99, 100; 99, 101; 100, identifier:i; 101, integer:1; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:newshape; 105, binary_operator:+; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 108; 107, identifier:shape; 108, slice; 108, 109; 108, 110; 109, colon; 110, identifier:dim; 111, subscript; 111, 112; 111, 113; 112, identifier:shape; 113, slice; 113, 114; 113, 117; 114, binary_operator:+; 114, 115; 114, 116; 115, identifier:dim; 116, integer:1; 117, colon; 118, elif_clause; 118, 119; 118, 122; 119, comparison_operator:is; 119, 120; 119, 121; 120, identifier:nsl_type; 121, identifier:slice; 122, block; 122, 123; 122, 159; 122, 167; 122, 181; 123, for_statement; 123, 124; 123, 125; 123, 129; 124, identifier:i; 125, call; 125, 126; 125, 127; 126, identifier:range; 127, argument_list; 127, 128; 128, identifier:num; 129, block; 129, 130; 130, if_statement; 130, 131; 130, 142; 131, comparison_operator:<=; 131, 132; 131, 135; 131, 139; 132, attribute; 132, 133; 132, 134; 133, identifier:nsl; 134, identifier:start; 135, parenthesized_expression; 135, 136; 136, binary_operator:%; 136, 137; 136, 138; 137, identifier:i; 138, identifier:n; 139, attribute; 139, 140; 139, 141; 140, identifier:nsl; 141, identifier:stop; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, augmented_assignment:+=; 144, 145; 144, 146; 145, identifier:newitems; 146, subscript; 146, 147; 146, 148; 147, identifier:items; 148, slice; 148, 149; 148, 152; 148, 153; 149, binary_operator:*; 149, 150; 149, 151; 150, identifier:size; 151, identifier:i; 152, colon; 153, binary_operator:*; 153, 154; 153, 155; 154, identifier:size; 155, parenthesized_expression; 155, 156; 156, binary_operator:+; 156, 157; 156, 158; 157, identifier:i; 158, integer:1; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:offset; 162, subscript; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:shape; 165, identifier:dim; 166, integer:0; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:redim; 170, tuple; 170, 171; 170, 176; 171, binary_operator:+; 171, 172; 171, 173; 172, identifier:offset; 173, attribute; 173, 174; 173, 175; 174, identifier:nsl; 175, identifier:start; 176, binary_operator:+; 176, 177; 176, 178; 177, identifier:offset; 178, attribute; 178, 179; 178, 180; 179, identifier:nsl; 180, identifier:stop; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:newshape; 184, binary_operator:+; 184, 185; 184, 193; 185, binary_operator:+; 185, 186; 185, 191; 186, subscript; 186, 187; 186, 188; 187, identifier:shape; 188, slice; 188, 189; 188, 190; 189, colon; 190, identifier:dim; 191, tuple; 191, 192; 192, identifier:redim; 193, subscript; 193, 194; 193, 195; 194, identifier:shape; 195, slice; 195, 196; 195, 199; 196, binary_operator:+; 196, 197; 196, 198; 197, identifier:dim; 198, integer:1; 199, colon; 200, else_clause; 200, 201; 201, block; 201, 202; 201, 233; 201, 246; 201, 273; 201, 325; 202, if_statement; 202, 203; 202, 211; 203, comparison_operator:<; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:nsl; 206, identifier:size; 207, call; 207, 208; 207, 209; 208, identifier:clog2; 209, argument_list; 209, 210; 210, identifier:n; 211, block; 211, 212; 211, 216; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:fstr; 215, string:"expected dim {} select to have >= {} bits, got {}"; 216, raise_statement; 216, 217; 217, call; 217, 218; 217, 219; 218, identifier:ValueError; 219, argument_list; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:fstr; 223, identifier:format; 224, argument_list; 224, 225; 224, 226; 224, 230; 225, identifier:dim; 226, call; 226, 227; 226, 228; 227, identifier:clog2; 228, argument_list; 228, 229; 229, identifier:n; 230, attribute; 230, 231; 230, 232; 231, identifier:nsl; 232, identifier:size; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:groups; 236, list_comprehension; 236, 237; 236, 240; 237, call; 237, 238; 237, 239; 238, identifier:list; 239, argument_list; 240, for_in_clause; 240, 241; 240, 242; 241, identifier:_; 242, call; 242, 243; 242, 244; 243, identifier:range; 244, argument_list; 244, 245; 245, identifier:n; 246, for_statement; 246, 247; 246, 248; 246, 252; 247, identifier:i; 248, call; 248, 249; 248, 250; 249, identifier:range; 250, argument_list; 250, 251; 251, identifier:num; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, augmented_assignment:+=; 254, 255; 254, 260; 255, subscript; 255, 256; 255, 257; 256, identifier:groups; 257, binary_operator:%; 257, 258; 257, 259; 258, identifier:i; 259, identifier:n; 260, subscript; 260, 261; 260, 262; 261, identifier:items; 262, slice; 262, 263; 262, 266; 262, 267; 263, binary_operator:*; 263, 264; 263, 265; 264, identifier:size; 265, identifier:i; 266, colon; 267, binary_operator:*; 267, 268; 267, 269; 268, identifier:size; 269, parenthesized_expression; 269, 270; 270, binary_operator:+; 270, 271; 270, 272; 271, identifier:i; 272, integer:1; 273, for_statement; 273, 274; 273, 275; 273, 280; 274, identifier:muxins; 275, call; 275, 276; 275, 277; 276, identifier:zip; 277, argument_list; 277, 278; 278, list_splat; 278, 279; 279, identifier:groups; 280, block; 280, 281; 280, 292; 280, 312; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:it; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:boolfunc; 287, identifier:iter_terms; 288, argument_list; 288, 289; 289, attribute; 289, 290; 289, 291; 290, identifier:nsl; 291, identifier:_items; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:xs; 295, list_comprehension; 295, 296; 295, 309; 296, call; 296, 297; 296, 298; 297, identifier:reduce; 298, argument_list; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:operator; 301, identifier:and_; 302, binary_operator:+; 302, 303; 302, 305; 303, tuple; 303, 304; 304, identifier:muxin; 305, call; 305, 306; 305, 307; 306, identifier:next; 307, argument_list; 307, 308; 308, identifier:it; 309, for_in_clause; 309, 310; 309, 311; 310, identifier:muxin; 311, identifier:muxins; 312, expression_statement; 312, 313; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:newitems; 316, identifier:append; 317, argument_list; 317, 318; 318, call; 318, 319; 318, 320; 319, identifier:reduce; 320, argument_list; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:operator; 323, identifier:or_; 324, identifier:xs; 325, expression_statement; 325, 326; 326, assignment; 326, 327; 326, 328; 327, identifier:newshape; 328, binary_operator:+; 328, 329; 328, 334; 329, subscript; 329, 330; 329, 331; 330, identifier:shape; 331, slice; 331, 332; 331, 333; 332, colon; 333, identifier:dim; 334, subscript; 334, 335; 334, 336; 335, identifier:shape; 336, slice; 336, 337; 336, 340; 337, binary_operator:+; 337, 338; 337, 339; 338, identifier:dim; 339, integer:1; 340, colon; 341, return_statement; 341, 342; 342, expression_list; 342, 343; 342, 344; 343, identifier:newitems; 344, identifier:newshape | def _filtdim(items, shape, dim, nsl):
normshape = tuple(stop - start for start, stop in shape)
nsl_type = type(nsl)
newitems = list()
num = reduce(operator.mul, normshape[:dim+1])
size = len(items) // num
n = normshape[dim]
if nsl_type is int:
for i in range(num):
if i % n == nsl:
newitems += items[size*i:size*(i+1)]
newshape = shape[:dim] + shape[dim+1:]
elif nsl_type is slice:
for i in range(num):
if nsl.start <= (i % n) < nsl.stop:
newitems += items[size*i:size*(i+1)]
offset = shape[dim][0]
redim = (offset + nsl.start, offset + nsl.stop)
newshape = shape[:dim] + (redim, ) + shape[dim+1:]
else:
if nsl.size < clog2(n):
fstr = "expected dim {} select to have >= {} bits, got {}"
raise ValueError(fstr.format(dim, clog2(n), nsl.size))
groups = [list() for _ in range(n)]
for i in range(num):
groups[i % n] += items[size*i:size*(i+1)]
for muxins in zip(*groups):
it = boolfunc.iter_terms(nsl._items)
xs = [reduce(operator.and_, (muxin, ) + next(it))
for muxin in muxins]
newitems.append(reduce(operator.or_, xs))
newshape = shape[:dim] + shape[dim+1:]
return newitems, newshape |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 1, 10; 2, function_name:parse; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:text; 6, type; 6, 7; 7, identifier:str; 8, type; 8, 9; 9, identifier:Docstring; 10, block; 10, 11; 10, 17; 10, 23; 10, 32; 10, 41; 10, 78; 10, 88; 10, 98; 10, 148; 10, 160; 10, 166; 10, 170; 10, 205; 10, 224; 10, 228; 10, 272; 10, 278; 10, 478; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:ret; 14, call; 14, 15; 14, 16; 15, identifier:Docstring; 16, argument_list; 17, if_statement; 17, 18; 17, 20; 18, not_operator; 18, 19; 19, identifier:text; 20, block; 20, 21; 21, return_statement; 21, 22; 22, identifier:ret; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:text; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:inspect; 29, identifier:cleandoc; 30, argument_list; 30, 31; 31, identifier:text; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:match; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:_titles_re; 38, identifier:search; 39, argument_list; 39, 40; 40, identifier:text; 41, if_statement; 41, 42; 41, 43; 41, 68; 42, identifier:match; 43, block; 43, 44; 43, 56; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:desc_chunk; 47, subscript; 47, 48; 47, 49; 48, identifier:text; 49, slice; 49, 50; 49, 51; 50, colon; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:match; 54, identifier:start; 55, argument_list; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:meta_chunk; 59, subscript; 59, 60; 59, 61; 60, identifier:text; 61, slice; 61, 62; 61, 67; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:match; 65, identifier:start; 66, argument_list; 67, colon; 68, else_clause; 68, 69; 69, block; 69, 70; 69, 74; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:desc_chunk; 73, identifier:text; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:meta_chunk; 77, string:""; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:parts; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:desc_chunk; 84, identifier:split; 85, argument_list; 85, 86; 85, 87; 86, string:"\n"; 87, integer:1; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:ret; 92, identifier:short_description; 93, boolean_operator:or; 93, 94; 93, 97; 94, subscript; 94, 95; 94, 96; 95, identifier:parts; 96, integer:0; 97, None; 98, if_statement; 98, 99; 98, 105; 99, comparison_operator:>; 99, 100; 99, 104; 100, call; 100, 101; 100, 102; 101, identifier:len; 102, argument_list; 102, 103; 103, identifier:parts; 104, integer:1; 105, block; 105, 106; 105, 114; 105, 125; 105, 136; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:long_desc_chunk; 109, boolean_operator:or; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:parts; 112, integer:1; 113, string:""; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:ret; 118, identifier:blank_after_short_description; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:long_desc_chunk; 122, identifier:startswith; 123, argument_list; 123, 124; 124, string:"\n"; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:ret; 129, identifier:blank_after_long_description; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:long_desc_chunk; 133, identifier:endswith; 134, argument_list; 134, 135; 135, string:"\n\n"; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:ret; 140, identifier:long_description; 141, boolean_operator:or; 141, 142; 141, 147; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:long_desc_chunk; 145, identifier:strip; 146, argument_list; 147, None; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:matches; 151, call; 151, 152; 151, 153; 152, identifier:list; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:_titles_re; 157, identifier:finditer; 158, argument_list; 158, 159; 159, identifier:meta_chunk; 160, if_statement; 160, 161; 160, 163; 161, not_operator; 161, 162; 162, identifier:matches; 163, block; 163, 164; 164, return_statement; 164, 165; 165, identifier:ret; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:splits; 169, list:[]; 170, for_statement; 170, 171; 170, 172; 170, 181; 171, identifier:j; 172, call; 172, 173; 172, 174; 173, identifier:range; 174, argument_list; 174, 175; 175, binary_operator:-; 175, 176; 175, 180; 176, call; 176, 177; 176, 178; 177, identifier:len; 178, argument_list; 178, 179; 179, identifier:matches; 180, integer:1; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:splits; 186, identifier:append; 187, argument_list; 187, 188; 188, tuple; 188, 189; 188, 196; 189, call; 189, 190; 189, 195; 190, attribute; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:matches; 193, identifier:j; 194, identifier:end; 195, argument_list; 196, call; 196, 197; 196, 204; 197, attribute; 197, 198; 197, 203; 198, subscript; 198, 199; 198, 200; 199, identifier:matches; 200, binary_operator:+; 200, 201; 200, 202; 201, identifier:j; 202, integer:1; 203, identifier:start; 204, argument_list; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:splits; 209, identifier:append; 210, argument_list; 210, 211; 211, tuple; 211, 212; 211, 220; 212, call; 212, 213; 212, 219; 213, attribute; 213, 214; 213, 218; 214, subscript; 214, 215; 214, 216; 215, identifier:matches; 216, unary_operator:-; 216, 217; 217, integer:1; 218, identifier:end; 219, argument_list; 220, call; 220, 221; 220, 222; 221, identifier:len; 222, argument_list; 222, 223; 223, identifier:meta_chunk; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:chunks; 227, dictionary; 228, for_statement; 228, 229; 228, 234; 228, 238; 229, pattern_list; 229, 230; 229, 231; 230, identifier:j; 231, tuple_pattern; 231, 232; 231, 233; 232, identifier:start; 233, identifier:end; 234, call; 234, 235; 234, 236; 235, identifier:enumerate; 236, argument_list; 236, 237; 237, identifier:splits; 238, block; 238, 239; 238, 250; 238, 256; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:title; 242, call; 242, 243; 242, 248; 243, attribute; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:matches; 246, identifier:j; 247, identifier:group; 248, argument_list; 248, 249; 249, integer:1; 250, if_statement; 250, 251; 250, 254; 251, comparison_operator:not; 251, 252; 251, 253; 252, identifier:title; 253, identifier:_valid; 254, block; 254, 255; 255, continue_statement; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 261; 258, subscript; 258, 259; 258, 260; 259, identifier:chunks; 260, identifier:title; 261, call; 261, 262; 261, 270; 262, attribute; 262, 263; 262, 269; 263, subscript; 263, 264; 263, 265; 264, identifier:meta_chunk; 265, slice; 265, 266; 265, 267; 265, 268; 266, identifier:start; 267, colon; 268, identifier:end; 269, identifier:strip; 270, argument_list; 270, 271; 271, string:"\n"; 272, if_statement; 272, 273; 272, 275; 273, not_operator; 273, 274; 274, identifier:chunks; 275, block; 275, 276; 276, return_statement; 276, 277; 277, identifier:ret; 278, for_statement; 278, 279; 278, 282; 278, 287; 279, pattern_list; 279, 280; 279, 281; 280, identifier:title; 281, identifier:chunk; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:chunks; 285, identifier:items; 286, argument_list; 287, block; 287, 288; 287, 298; 287, 307; 287, 315; 287, 347; 287, 355; 287, 373; 287, 382; 287, 386; 287, 421; 287, 440; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:indent_match; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:re; 294, identifier:search; 295, argument_list; 295, 296; 295, 297; 296, string:r"^\s+"; 297, identifier:chunk; 298, if_statement; 298, 299; 298, 301; 299, not_operator; 299, 300; 300, identifier:indent_match; 301, block; 301, 302; 302, raise_statement; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:ParseError; 305, argument_list; 305, 306; 306, string:f'Can\'t infer indent from "{chunk}"'; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:indent; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:indent_match; 313, identifier:group; 314, argument_list; 315, if_statement; 315, 316; 315, 323; 316, comparison_operator:in; 316, 317; 316, 320; 317, subscript; 317, 318; 317, 319; 318, identifier:_sections; 319, identifier:title; 320, tuple; 320, 321; 320, 322; 321, string:"returns"; 322, string:"yields"; 323, block; 323, 324; 323, 333; 323, 346; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:part; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:inspect; 330, identifier:cleandoc; 331, argument_list; 331, 332; 332, identifier:chunk; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 340; 335, attribute; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:ret; 338, identifier:meta; 339, identifier:append; 340, argument_list; 340, 341; 341, call; 341, 342; 341, 343; 342, identifier:_build_meta; 343, argument_list; 343, 344; 343, 345; 344, identifier:part; 345, identifier:title; 346, continue_statement; 347, expression_statement; 347, 348; 348, assignment; 348, 349; 348, 350; 349, identifier:_re; 350, binary_operator:+; 350, 351; 350, 354; 351, binary_operator:+; 351, 352; 351, 353; 352, string:"^"; 353, identifier:indent; 354, string:r"(?=\S)"; 355, expression_statement; 355, 356; 356, assignment; 356, 357; 356, 358; 357, identifier:c_matches; 358, call; 358, 359; 358, 360; 359, identifier:list; 360, argument_list; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:re; 364, identifier:finditer; 365, argument_list; 365, 366; 365, 367; 365, 368; 366, identifier:_re; 367, identifier:chunk; 368, keyword_argument; 368, 369; 368, 370; 369, identifier:flags; 370, attribute; 370, 371; 370, 372; 371, identifier:re; 372, identifier:M; 373, if_statement; 373, 374; 373, 376; 374, not_operator; 374, 375; 375, identifier:c_matches; 376, block; 376, 377; 377, raise_statement; 377, 378; 378, call; 378, 379; 378, 380; 379, identifier:ParseError; 380, argument_list; 380, 381; 381, string:f'No specification for "{title}": "{chunk}"'; 382, expression_statement; 382, 383; 383, assignment; 383, 384; 383, 385; 384, identifier:c_splits; 385, list:[]; 386, for_statement; 386, 387; 386, 388; 386, 397; 387, identifier:j; 388, call; 388, 389; 388, 390; 389, identifier:range; 390, argument_list; 390, 391; 391, binary_operator:-; 391, 392; 391, 396; 392, call; 392, 393; 392, 394; 393, identifier:len; 394, argument_list; 394, 395; 395, identifier:c_matches; 396, integer:1; 397, block; 397, 398; 398, expression_statement; 398, 399; 399, call; 399, 400; 399, 403; 400, attribute; 400, 401; 400, 402; 401, identifier:c_splits; 402, identifier:append; 403, argument_list; 403, 404; 404, tuple; 404, 405; 404, 412; 405, call; 405, 406; 405, 411; 406, attribute; 406, 407; 406, 410; 407, subscript; 407, 408; 407, 409; 408, identifier:c_matches; 409, identifier:j; 410, identifier:end; 411, argument_list; 412, call; 412, 413; 412, 420; 413, attribute; 413, 414; 413, 419; 414, subscript; 414, 415; 414, 416; 415, identifier:c_matches; 416, binary_operator:+; 416, 417; 416, 418; 417, identifier:j; 418, integer:1; 419, identifier:start; 420, argument_list; 421, expression_statement; 421, 422; 422, call; 422, 423; 422, 426; 423, attribute; 423, 424; 423, 425; 424, identifier:c_splits; 425, identifier:append; 426, argument_list; 426, 427; 427, tuple; 427, 428; 427, 436; 428, call; 428, 429; 428, 435; 429, attribute; 429, 430; 429, 434; 430, subscript; 430, 431; 430, 432; 431, identifier:c_matches; 432, unary_operator:-; 432, 433; 433, integer:1; 434, identifier:end; 435, argument_list; 436, call; 436, 437; 436, 438; 437, identifier:len; 438, argument_list; 438, 439; 439, identifier:chunk; 440, for_statement; 440, 441; 440, 446; 440, 450; 441, pattern_list; 441, 442; 441, 443; 442, identifier:j; 443, tuple_pattern; 443, 444; 443, 445; 444, identifier:start; 445, identifier:end; 446, call; 446, 447; 446, 448; 447, identifier:enumerate; 448, argument_list; 448, 449; 449, identifier:c_splits; 450, block; 450, 451; 450, 465; 451, expression_statement; 451, 452; 452, assignment; 452, 453; 452, 454; 453, identifier:part; 454, call; 454, 455; 454, 463; 455, attribute; 455, 456; 455, 462; 456, subscript; 456, 457; 456, 458; 457, identifier:chunk; 458, slice; 458, 459; 458, 460; 458, 461; 459, identifier:start; 460, colon; 461, identifier:end; 462, identifier:strip; 463, argument_list; 463, 464; 464, string:"\n"; 465, expression_statement; 465, 466; 466, call; 466, 467; 466, 472; 467, attribute; 467, 468; 467, 471; 468, attribute; 468, 469; 468, 470; 469, identifier:ret; 470, identifier:meta; 471, identifier:append; 472, argument_list; 472, 473; 473, call; 473, 474; 473, 475; 474, identifier:_build_meta; 475, argument_list; 475, 476; 475, 477; 476, identifier:part; 477, identifier:title; 478, return_statement; 478, 479; 479, identifier:ret | def parse(text: str) -> Docstring:
ret = Docstring()
if not text:
return ret
text = inspect.cleandoc(text)
match = _titles_re.search(text)
if match:
desc_chunk = text[: match.start()]
meta_chunk = text[match.start() :]
else:
desc_chunk = text
meta_chunk = ""
parts = desc_chunk.split("\n", 1)
ret.short_description = parts[0] or None
if len(parts) > 1:
long_desc_chunk = parts[1] or ""
ret.blank_after_short_description = long_desc_chunk.startswith("\n")
ret.blank_after_long_description = long_desc_chunk.endswith("\n\n")
ret.long_description = long_desc_chunk.strip() or None
matches = list(_titles_re.finditer(meta_chunk))
if not matches:
return ret
splits = []
for j in range(len(matches) - 1):
splits.append((matches[j].end(), matches[j + 1].start()))
splits.append((matches[-1].end(), len(meta_chunk)))
chunks = {}
for j, (start, end) in enumerate(splits):
title = matches[j].group(1)
if title not in _valid:
continue
chunks[title] = meta_chunk[start:end].strip("\n")
if not chunks:
return ret
for title, chunk in chunks.items():
indent_match = re.search(r"^\s+", chunk)
if not indent_match:
raise ParseError(f'Can\'t infer indent from "{chunk}"')
indent = indent_match.group()
if _sections[title] in ("returns", "yields"):
part = inspect.cleandoc(chunk)
ret.meta.append(_build_meta(part, title))
continue
_re = "^" + indent + r"(?=\S)"
c_matches = list(re.finditer(_re, chunk, flags=re.M))
if not c_matches:
raise ParseError(f'No specification for "{title}": "{chunk}"')
c_splits = []
for j in range(len(c_matches) - 1):
c_splits.append((c_matches[j].end(), c_matches[j + 1].start()))
c_splits.append((c_matches[-1].end(), len(chunk)))
for j, (start, end) in enumerate(c_splits):
part = chunk[start:end].strip("\n")
ret.meta.append(_build_meta(part, title))
return ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:generate; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:tool; 6, default_parameter; 6, 7; 6, 8; 7, identifier:copied; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:copy; 11, False; 12, block; 12, 13; 12, 17; 12, 38; 12, 42; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:tools; 16, list:[]; 17, if_statement; 17, 18; 17, 20; 17, 31; 18, not_operator; 18, 19; 19, identifier:tool; 20, block; 20, 21; 20, 28; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:logger; 25, identifier:info; 26, argument_list; 26, 27; 27, string:"Workspace supports one tool for all projects within."; 28, return_statement; 28, 29; 29, unary_operator:-; 29, 30; 30, integer:1; 31, else_clause; 31, 32; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:tools; 36, list:[tool]; 36, 37; 37, identifier:tool; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:result; 41, integer:0; 42, for_statement; 42, 43; 42, 44; 42, 45; 43, identifier:export_tool; 44, identifier:tools; 45, block; 45, 46; 45, 57; 45, 68; 45, 72; 45, 126; 45, 152; 45, 177; 45, 269; 45, 285; 45, 293; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:tool_export; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, call; 51, 52; 51, 53; 52, identifier:ToolsSupported; 53, argument_list; 54, identifier:get_tool; 55, argument_list; 55, 56; 56, identifier:export_tool; 57, if_statement; 57, 58; 57, 61; 58, comparison_operator:is; 58, 59; 58, 60; 59, identifier:tool_export; 60, None; 61, block; 61, 62; 61, 67; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:result; 65, unary_operator:-; 65, 66; 66, integer:1; 67, continue_statement; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:project_export_dir_overwrite; 71, False; 72, if_statement; 72, 73; 72, 84; 72, 93; 73, comparison_operator:!=; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:settings; 78, identifier:export_location_format; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:settings; 83, identifier:DEFAULT_EXPORT_LOCATION_FORMAT; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:location_format; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:settings; 92, identifier:export_location_format; 93, else_clause; 93, 94; 94, block; 94, 95; 95, if_statement; 95, 96; 95, 101; 95, 116; 96, comparison_operator:in; 96, 97; 96, 98; 97, string:'export_dir'; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:workspace_settings; 101, block; 101, 102; 101, 112; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:location_format; 105, subscript; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:workspace_settings; 110, string:'export_dir'; 111, integer:0; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:project_export_dir_overwrite; 115, True; 116, else_clause; 116, 117; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:location_format; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:settings; 125, identifier:export_location_format; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:location; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, call; 131, 132; 131, 133; 132, identifier:PartialFormatter; 133, argument_list; 134, identifier:format; 135, argument_list; 135, 136; 135, 137; 136, identifier:location_format; 137, dictionary_splat; 137, 138; 138, dictionary; 138, 139; 138, 144; 138, 147; 139, pair; 139, 140; 139, 141; 140, string:'project_name'; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:name; 144, pair; 144, 145; 144, 146; 145, string:'tool'; 146, identifier:tool; 147, pair; 147, 148; 147, 149; 148, string:'workspace_name'; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:name; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:workspace_dic; 155, dictionary; 155, 156; 155, 159; 156, pair; 156, 157; 156, 158; 157, string:'projects'; 158, list:[]; 159, pair; 159, 160; 159, 161; 160, string:'settings'; 161, dictionary; 161, 162; 161, 167; 162, pair; 162, 163; 162, 164; 163, string:'name'; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:name; 167, pair; 167, 168; 167, 169; 168, string:'path'; 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:normpath; 175, argument_list; 175, 176; 176, identifier:location; 177, for_statement; 177, 178; 177, 179; 177, 182; 178, identifier:project; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:projects; 182, block; 182, 183; 182, 193; 182, 206; 182, 214; 182, 223; 182, 233; 182, 251; 182, 260; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:generated_files; 186, dictionary; 186, 187; 186, 190; 187, pair; 187, 188; 187, 189; 188, string:'projects'; 189, list:[]; 190, pair; 190, 191; 190, 192; 191, string:'workspaces'; 192, list:[]; 193, if_statement; 193, 194; 193, 195; 194, identifier:project_export_dir_overwrite; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 205; 198, subscript; 198, 199; 198, 204; 199, subscript; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:project; 202, identifier:project; 203, string:'common'; 204, string:'export_dir'; 205, identifier:location; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:project; 210, identifier:_fill_export_dict; 211, argument_list; 211, 212; 211, 213; 212, identifier:export_tool; 213, identifier:copied; 214, if_statement; 214, 215; 214, 216; 215, identifier:copy; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:project; 221, identifier:_copy_sources_to_generated_destination; 222, argument_list; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 232; 225, subscript; 225, 226; 225, 231; 226, subscript; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:project; 229, identifier:project; 230, string:'export'; 231, string:'singular'; 232, False; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:files; 236, call; 236, 237; 236, 250; 237, attribute; 237, 238; 237, 249; 238, call; 238, 239; 238, 240; 239, identifier:tool_export; 240, argument_list; 240, 241; 240, 246; 241, subscript; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:project; 244, identifier:project; 245, string:'export'; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:settings; 249, identifier:export_project; 250, argument_list; 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:workspace_dic; 256, string:'projects'; 257, identifier:append; 258, argument_list; 258, 259; 259, identifier:files; 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:generated_files; 265, string:'projects'; 266, identifier:append; 267, argument_list; 267, 268; 268, identifier:files; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:generated_files; 273, string:'workspaces'; 274, call; 274, 275; 274, 284; 275, attribute; 275, 276; 275, 283; 276, call; 276, 277; 276, 278; 277, identifier:tool_export; 278, argument_list; 278, 279; 278, 280; 279, identifier:workspace_dic; 280, attribute; 280, 281; 280, 282; 281, identifier:self; 282, identifier:settings; 283, identifier:export_workspace; 284, argument_list; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 292; 287, subscript; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:self; 290, identifier:generated_files; 291, identifier:export_tool; 292, identifier:generated_files; 293, return_statement; 293, 294; 294, identifier:result | def generate(self, tool, copied=False, copy=False):
tools = []
if not tool:
logger.info("Workspace supports one tool for all projects within.")
return -1
else:
tools = [tool]
result = 0
for export_tool in tools:
tool_export = ToolsSupported().get_tool(export_tool)
if tool_export is None:
result = -1
continue
project_export_dir_overwrite = False
if self.settings.export_location_format != self.settings.DEFAULT_EXPORT_LOCATION_FORMAT:
location_format = self.settings.export_location_format
else:
if 'export_dir' in self.workspace_settings:
location_format = self.workspace_settings['export_dir'][0]
project_export_dir_overwrite = True
else:
location_format = self.settings.export_location_format
location = PartialFormatter().format(location_format, **{
'project_name': self.name,
'tool': tool,
'workspace_name': self.name
})
workspace_dic = {
'projects': [],
'settings': {
'name': self.name,
'path': os.path.normpath(location),
},
}
for project in self.projects:
generated_files = {
'projects' : [],
'workspaces': [],
}
if project_export_dir_overwrite:
project.project['common']['export_dir'] = location
project._fill_export_dict(export_tool, copied)
if copy:
project._copy_sources_to_generated_destination()
project.project['export']['singular'] = False
files = tool_export(project.project['export'], self.settings).export_project()
workspace_dic['projects'].append(files)
generated_files['projects'].append(files)
generated_files['workspaces'] = tool_export(workspace_dic, self.settings).export_workspace()
self.generated_files[export_tool] = generated_files
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_send_request; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:request; 6, block; 6, 7; 6, 16; 6, 31; 6, 40; 6, 46; 6, 70; 6, 79; 6, 109; 6, 116; 6, 153; 6, 159; 6, 190; 6, 244; 6, 252; 6, 260; 6, 266; 6, 302; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:headers; 10, dictionary; 10, 11; 11, pair; 11, 12; 11, 13; 12, string:"X-Experience-API-Version"; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:version; 16, if_statement; 16, 17; 16, 22; 17, comparison_operator:is; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:auth; 21, None; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:headers; 27, string:"Authorization"; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:auth; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:headers; 35, identifier:update; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:request; 39, identifier:headers; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:params; 43, attribute; 43, 44; 43, 45; 44, identifier:request; 45, identifier:query_params; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:params; 49, dictionary_comprehension; 49, 50; 49, 63; 50, pair; 50, 51; 50, 52; 51, identifier:k; 52, call; 52, 53; 52, 61; 53, attribute; 53, 54; 53, 60; 54, call; 54, 55; 54, 56; 55, identifier:unicode; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:params; 59, identifier:k; 60, identifier:encode; 61, argument_list; 61, 62; 62, string:'utf-8'; 63, for_in_clause; 63, 64; 63, 65; 64, identifier:k; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:params; 68, identifier:keys; 69, argument_list; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:params; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:urllib; 76, identifier:urlencode; 77, argument_list; 77, 78; 78, identifier:params; 79, if_statement; 79, 80; 79, 88; 79, 95; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:request; 84, identifier:resource; 85, identifier:startswith; 86, argument_list; 86, 87; 87, string:'http'; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:url; 92, attribute; 92, 93; 92, 94; 93, identifier:request; 94, identifier:resource; 95, else_clause; 95, 96; 96, block; 96, 97; 96, 103; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:url; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:endpoint; 103, expression_statement; 103, 104; 104, augmented_assignment:+=; 104, 105; 104, 106; 105, identifier:url; 106, attribute; 106, 107; 106, 108; 107, identifier:request; 108, identifier:resource; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:parsed; 112, call; 112, 113; 112, 114; 113, identifier:urlparse; 114, argument_list; 114, 115; 115, identifier:url; 116, if_statement; 116, 117; 116, 122; 116, 137; 117, comparison_operator:==; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:parsed; 120, identifier:scheme; 121, string:"https"; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:web_req; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:httplib; 129, identifier:HTTPSConnection; 130, argument_list; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:parsed; 133, identifier:hostname; 134, attribute; 134, 135; 134, 136; 135, identifier:parsed; 136, identifier:port; 137, else_clause; 137, 138; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:web_req; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:httplib; 145, identifier:HTTPConnection; 146, argument_list; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:parsed; 149, identifier:hostname; 150, attribute; 150, 151; 150, 152; 151, identifier:parsed; 152, identifier:port; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:path; 156, attribute; 156, 157; 156, 158; 157, identifier:parsed; 158, identifier:path; 159, if_statement; 159, 160; 159, 167; 160, boolean_operator:or; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:parsed; 163, identifier:query; 164, attribute; 164, 165; 164, 166; 165, identifier:parsed; 166, identifier:path; 167, block; 167, 168; 167, 172; 167, 183; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:path; 171, string:"?"; 172, if_statement; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:parsed; 175, identifier:query; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, augmented_assignment:+=; 178, 179; 178, 180; 179, identifier:path; 180, attribute; 180, 181; 180, 182; 181, identifier:parsed; 182, identifier:query; 183, if_statement; 183, 184; 183, 185; 184, identifier:params; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, augmented_assignment:+=; 187, 188; 187, 189; 188, identifier:path; 189, identifier:params; 190, if_statement; 190, 191; 190, 202; 190, 225; 191, boolean_operator:and; 191, 192; 191, 197; 192, call; 192, 193; 192, 194; 193, identifier:hasattr; 194, argument_list; 194, 195; 194, 196; 195, identifier:request; 196, string:"content"; 197, comparison_operator:is; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:request; 200, identifier:content; 201, None; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:web_req; 207, identifier:request; 208, argument_list; 208, 209; 208, 214; 208, 217; 208, 222; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:method; 211, attribute; 211, 212; 211, 213; 212, identifier:request; 213, identifier:method; 214, keyword_argument; 214, 215; 214, 216; 215, identifier:url; 216, identifier:path; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:body; 219, attribute; 219, 220; 219, 221; 220, identifier:request; 221, identifier:content; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:headers; 224, identifier:headers; 225, else_clause; 225, 226; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:web_req; 231, identifier:request; 232, argument_list; 232, 233; 232, 238; 232, 241; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:method; 235, attribute; 235, 236; 235, 237; 236, identifier:request; 237, identifier:method; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:url; 240, identifier:path; 241, keyword_argument; 241, 242; 241, 243; 242, identifier:headers; 243, identifier:headers; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:response; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:web_req; 250, identifier:getresponse; 251, argument_list; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:data; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:response; 258, identifier:read; 259, argument_list; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:web_req; 264, identifier:close; 265, argument_list; 266, if_statement; 266, 267; 266, 291; 266, 296; 267, parenthesized_expression; 267, 268; 268, boolean_operator:or; 268, 269; 268, 275; 269, comparison_operator:<=; 269, 270; 269, 271; 269, 274; 270, integer:200; 271, attribute; 271, 272; 271, 273; 272, identifier:response; 273, identifier:status; 274, integer:300; 275, parenthesized_expression; 275, 276; 276, boolean_operator:and; 276, 277; 276, 288; 277, boolean_operator:and; 277, 278; 277, 283; 278, comparison_operator:==; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:response; 281, identifier:status; 282, integer:404; 283, call; 283, 284; 283, 285; 284, identifier:hasattr; 285, argument_list; 285, 286; 285, 287; 286, identifier:request; 287, string:"ignore404"; 288, attribute; 288, 289; 288, 290; 289, identifier:request; 290, identifier:ignore404; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:success; 295, True; 296, else_clause; 296, 297; 297, block; 297, 298; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:success; 301, False; 302, return_statement; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:LRSResponse; 305, argument_list; 305, 306; 305, 309; 305, 312; 305, 315; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:success; 308, identifier:success; 309, keyword_argument; 309, 310; 309, 311; 310, identifier:request; 311, identifier:request; 312, keyword_argument; 312, 313; 312, 314; 313, identifier:response; 314, identifier:response; 315, keyword_argument; 315, 316; 315, 317; 316, identifier:data; 317, identifier:data | def _send_request(self, request):
headers = {"X-Experience-API-Version": self.version}
if self.auth is not None:
headers["Authorization"] = self.auth
headers.update(request.headers)
params = request.query_params
params = {k: unicode(params[k]).encode('utf-8') for k in params.keys()}
params = urllib.urlencode(params)
if request.resource.startswith('http'):
url = request.resource
else:
url = self.endpoint
url += request.resource
parsed = urlparse(url)
if parsed.scheme == "https":
web_req = httplib.HTTPSConnection(parsed.hostname, parsed.port)
else:
web_req = httplib.HTTPConnection(parsed.hostname, parsed.port)
path = parsed.path
if parsed.query or parsed.path:
path += "?"
if parsed.query:
path += parsed.query
if params:
path += params
if hasattr(request, "content") and request.content is not None:
web_req.request(
method=request.method,
url=path,
body=request.content,
headers=headers,
)
else:
web_req.request(
method=request.method,
url=path,
headers=headers,
)
response = web_req.getresponse()
data = response.read()
web_req.close()
if (200 <= response.status < 300
or (response.status == 404
and hasattr(request, "ignore404")
and request.ignore404)):
success = True
else:
success = False
return LRSResponse(
success=success,
request=request,
response=response,
data=data,
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:query_statements; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:query; 6, block; 6, 7; 6, 11; 6, 24; 6, 85; 6, 97; 6, 103; 6, 112; 6, 130; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:params; 10, dictionary; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:param_keys; 14, list:[
"registration",
"since",
"until",
"limit",
"ascending",
"related_activities",
"related_agents",
"format",
"attachments",
]; 14, 15; 14, 16; 14, 17; 14, 18; 14, 19; 14, 20; 14, 21; 14, 22; 14, 23; 15, string:"registration"; 16, string:"since"; 17, string:"until"; 18, string:"limit"; 19, string:"ascending"; 20, string:"related_activities"; 21, string:"related_agents"; 22, string:"format"; 23, string:"attachments"; 24, for_statement; 24, 25; 24, 28; 24, 33; 25, pattern_list; 25, 26; 25, 27; 26, identifier:k; 27, identifier:v; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:query; 31, identifier:iteritems; 32, argument_list; 33, block; 33, 34; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:v; 37, None; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 43; 39, 57; 39, 74; 40, comparison_operator:==; 40, 41; 40, 42; 41, identifier:k; 42, string:"agent"; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:params; 48, identifier:k; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:v; 52, identifier:to_json; 53, argument_list; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:version; 57, elif_clause; 57, 58; 57, 65; 58, boolean_operator:or; 58, 59; 58, 62; 59, comparison_operator:==; 59, 60; 59, 61; 60, identifier:k; 61, string:"verb"; 62, comparison_operator:==; 62, 63; 62, 64; 63, identifier:k; 64, string:"activity"; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:params; 70, identifier:k; 71, attribute; 71, 72; 71, 73; 72, identifier:v; 73, identifier:id; 74, elif_clause; 74, 75; 74, 78; 75, comparison_operator:in; 75, 76; 75, 77; 76, identifier:k; 77, identifier:param_keys; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:params; 83, identifier:k; 84, identifier:v; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:request; 88, call; 88, 89; 88, 90; 89, identifier:HTTPRequest; 90, argument_list; 90, 91; 90, 94; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:method; 93, string:"GET"; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:resource; 96, string:"statements"; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:request; 101, identifier:query_params; 102, identifier:params; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:lrs_response; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:_send_request; 110, argument_list; 110, 111; 111, identifier:request; 112, if_statement; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:lrs_response; 115, identifier:success; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:lrs_response; 121, identifier:content; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:StatementsResult; 125, identifier:from_json; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 129; 128, identifier:lrs_response; 129, identifier:data; 130, return_statement; 130, 131; 131, identifier:lrs_response | def query_statements(self, query):
params = {}
param_keys = [
"registration",
"since",
"until",
"limit",
"ascending",
"related_activities",
"related_agents",
"format",
"attachments",
]
for k, v in query.iteritems():
if v is not None:
if k == "agent":
params[k] = v.to_json(self.version)
elif k == "verb" or k == "activity":
params[k] = v.id
elif k in param_keys:
params[k] = v
request = HTTPRequest(
method="GET",
resource="statements"
)
request.query_params = params
lrs_response = self._send_request(request)
if lrs_response.success:
lrs_response.content = StatementsResult.from_json(lrs_response.data)
return lrs_response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:retrieve_state; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:activity; 6, identifier:agent; 7, identifier:state_id; 8, default_parameter; 8, 9; 8, 10; 9, identifier:registration; 10, None; 11, block; 11, 12; 11, 27; 11, 42; 11, 57; 11, 81; 11, 94; 11, 103; 11, 212; 12, if_statement; 12, 13; 12, 19; 13, not_operator; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:activity; 18, identifier:Activity; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:activity; 23, call; 23, 24; 23, 25; 24, identifier:Activity; 25, argument_list; 25, 26; 26, identifier:activity; 27, if_statement; 27, 28; 27, 34; 28, not_operator; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 33; 32, identifier:agent; 33, identifier:Agent; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:agent; 38, call; 38, 39; 38, 40; 39, identifier:Agent; 40, argument_list; 40, 41; 41, identifier:agent; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:request; 45, call; 45, 46; 45, 47; 46, identifier:HTTPRequest; 47, argument_list; 47, 48; 47, 51; 47, 54; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:method; 50, string:"GET"; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:resource; 53, string:"activities/state"; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:ignore404; 56, True; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:request; 61, identifier:query_params; 62, dictionary; 62, 63; 62, 68; 62, 78; 63, pair; 63, 64; 63, 65; 64, string:"activityId"; 65, attribute; 65, 66; 65, 67; 66, identifier:activity; 67, identifier:id; 68, pair; 68, 69; 68, 70; 69, string:"agent"; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:agent; 73, identifier:to_json; 74, argument_list; 74, 75; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:version; 78, pair; 78, 79; 78, 80; 79, string:"stateId"; 80, identifier:state_id; 81, if_statement; 81, 82; 81, 85; 82, comparison_operator:is; 82, 83; 82, 84; 83, identifier:registration; 84, None; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 93; 88, subscript; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:request; 91, identifier:query_params; 92, string:"registration"; 93, identifier:registration; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:lrs_response; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:_send_request; 101, argument_list; 101, 102; 102, identifier:request; 103, if_statement; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:lrs_response; 106, identifier:success; 107, block; 107, 108; 107, 128; 107, 139; 107, 149; 107, 168; 107, 187; 107, 206; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:doc; 111, call; 111, 112; 111, 113; 112, identifier:StateDocument; 113, argument_list; 113, 114; 113, 117; 113, 122; 113, 125; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:id; 116, identifier:state_id; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:content; 119, attribute; 119, 120; 119, 121; 120, identifier:lrs_response; 121, identifier:data; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:activity; 124, identifier:activity; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:agent; 127, identifier:agent; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:is; 129, 130; 129, 131; 130, identifier:registration; 131, None; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:doc; 137, identifier:registration; 138, identifier:registration; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:headers; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:lrs_response; 146, identifier:response; 147, identifier:getheaders; 148, argument_list; 149, if_statement; 149, 150; 149, 159; 150, boolean_operator:and; 150, 151; 150, 154; 151, comparison_operator:in; 151, 152; 151, 153; 152, string:"lastModified"; 153, identifier:headers; 154, comparison_operator:is; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:headers; 157, string:"lastModified"; 158, None; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:doc; 164, identifier:timestamp; 165, subscript; 165, 166; 165, 167; 166, identifier:headers; 167, string:"lastModified"; 168, if_statement; 168, 169; 168, 178; 169, boolean_operator:and; 169, 170; 169, 173; 170, comparison_operator:in; 170, 171; 170, 172; 171, string:"contentType"; 172, identifier:headers; 173, comparison_operator:is; 173, 174; 173, 177; 174, subscript; 174, 175; 174, 176; 175, identifier:headers; 176, string:"contentType"; 177, None; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:doc; 183, identifier:content_type; 184, subscript; 184, 185; 184, 186; 185, identifier:headers; 186, string:"contentType"; 187, if_statement; 187, 188; 187, 197; 188, boolean_operator:and; 188, 189; 188, 192; 189, comparison_operator:in; 189, 190; 189, 191; 190, string:"etag"; 191, identifier:headers; 192, comparison_operator:is; 192, 193; 192, 196; 193, subscript; 193, 194; 193, 195; 194, identifier:headers; 195, string:"etag"; 196, None; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:doc; 202, identifier:etag; 203, subscript; 203, 204; 203, 205; 204, identifier:headers; 205, string:"etag"; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:lrs_response; 210, identifier:content; 211, identifier:doc; 212, return_statement; 212, 213; 213, identifier:lrs_response | def retrieve_state(self, activity, agent, state_id, registration=None):
if not isinstance(activity, Activity):
activity = Activity(activity)
if not isinstance(agent, Agent):
agent = Agent(agent)
request = HTTPRequest(
method="GET",
resource="activities/state",
ignore404=True
)
request.query_params = {
"activityId": activity.id,
"agent": agent.to_json(self.version),
"stateId": state_id
}
if registration is not None:
request.query_params["registration"] = registration
lrs_response = self._send_request(request)
if lrs_response.success:
doc = StateDocument(
id=state_id,
content=lrs_response.data,
activity=activity,
agent=agent
)
if registration is not None:
doc.registration = registration
headers = lrs_response.response.getheaders()
if "lastModified" in headers and headers["lastModified"] is not None:
doc.timestamp = headers["lastModified"]
if "contentType" in headers and headers["contentType"] is not None:
doc.content_type = headers["contentType"]
if "etag" in headers and headers["etag"] is not None:
doc.etag = headers["etag"]
lrs_response.content = doc
return lrs_response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:as_version; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:version; 7, attribute; 7, 8; 7, 9; 8, identifier:Version; 9, identifier:latest; 10, block; 10, 11; 10, 235; 11, if_statement; 11, 12; 11, 18; 11, 197; 12, not_operator; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:self; 17, identifier:list; 18, block; 18, 19; 18, 23; 18, 188; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:result; 22, dictionary; 23, for_statement; 23, 24; 23, 27; 23, 46; 24, pattern_list; 24, 25; 24, 26; 25, identifier:k; 26, identifier:v; 27, conditional_expression:if; 27, 28; 27, 33; 27, 38; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:iteritems; 32, argument_list; 33, call; 33, 34; 33, 35; 34, identifier:isinstance; 35, argument_list; 35, 36; 35, 37; 36, identifier:self; 37, identifier:dict; 38, call; 38, 39; 38, 45; 39, attribute; 39, 40; 39, 44; 40, call; 40, 41; 40, 42; 41, identifier:vars; 42, argument_list; 42, 43; 43, identifier:self; 44, identifier:iteritems; 45, argument_list; 46, block; 46, 47; 46, 59; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:k; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_props_corrected; 55, identifier:get; 56, argument_list; 56, 57; 56, 58; 57, identifier:k; 58, identifier:k; 59, if_statement; 59, 60; 59, 65; 59, 77; 59, 126; 59, 144; 59, 162; 59, 180; 60, call; 60, 61; 60, 62; 61, identifier:isinstance; 62, argument_list; 62, 63; 62, 64; 63, identifier:v; 64, identifier:SerializableBase; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:result; 70, identifier:k; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:v; 74, identifier:as_version; 75, argument_list; 75, 76; 76, identifier:version; 77, elif_clause; 77, 78; 77, 83; 78, call; 78, 79; 78, 80; 79, identifier:isinstance; 80, argument_list; 80, 81; 80, 82; 81, identifier:v; 82, identifier:list; 83, block; 83, 84; 83, 90; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:result; 88, identifier:k; 89, list:[]; 90, for_statement; 90, 91; 90, 92; 90, 93; 91, identifier:val; 92, identifier:v; 93, block; 93, 94; 94, if_statement; 94, 95; 94, 100; 94, 115; 95, call; 95, 96; 95, 97; 96, identifier:isinstance; 97, argument_list; 97, 98; 97, 99; 98, identifier:val; 99, identifier:SerializableBase; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:result; 106, identifier:k; 107, identifier:append; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:val; 112, identifier:as_version; 113, argument_list; 113, 114; 114, identifier:version; 115, else_clause; 115, 116; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:result; 122, identifier:k; 123, identifier:append; 124, argument_list; 124, 125; 125, identifier:val; 126, elif_clause; 126, 127; 126, 134; 127, call; 127, 128; 127, 129; 128, identifier:isinstance; 129, argument_list; 129, 130; 129, 131; 130, identifier:v; 131, attribute; 131, 132; 131, 133; 132, identifier:uuid; 133, identifier:UUID; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:result; 139, identifier:k; 140, call; 140, 141; 140, 142; 141, identifier:unicode; 142, argument_list; 142, 143; 143, identifier:v; 144, elif_clause; 144, 145; 144, 152; 145, call; 145, 146; 145, 147; 146, identifier:isinstance; 147, argument_list; 147, 148; 147, 149; 148, identifier:v; 149, attribute; 149, 150; 149, 151; 150, identifier:datetime; 151, identifier:timedelta; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:result; 157, identifier:k; 158, call; 158, 159; 158, 160; 159, identifier:jsonify_timedelta; 160, argument_list; 160, 161; 161, identifier:v; 162, elif_clause; 162, 163; 162, 170; 163, call; 163, 164; 163, 165; 164, identifier:isinstance; 165, argument_list; 165, 166; 165, 167; 166, identifier:v; 167, attribute; 167, 168; 167, 169; 168, identifier:datetime; 169, identifier:datetime; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:result; 175, identifier:k; 176, call; 176, 177; 176, 178; 177, identifier:jsonify_datetime; 178, argument_list; 178, 179; 179, identifier:v; 180, else_clause; 180, 181; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:result; 186, identifier:k; 187, identifier:v; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:result; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:_filter_none; 195, argument_list; 195, 196; 196, identifier:result; 197, else_clause; 197, 198; 198, block; 198, 199; 198, 203; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:result; 202, list:[]; 203, for_statement; 203, 204; 203, 205; 203, 206; 204, identifier:v; 205, identifier:self; 206, block; 206, 207; 207, if_statement; 207, 208; 207, 213; 207, 226; 208, call; 208, 209; 208, 210; 209, identifier:isinstance; 210, argument_list; 210, 211; 210, 212; 211, identifier:v; 212, identifier:SerializableBase; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:result; 218, identifier:append; 219, argument_list; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:v; 223, identifier:as_version; 224, argument_list; 224, 225; 225, identifier:version; 226, else_clause; 226, 227; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:result; 232, identifier:append; 233, argument_list; 233, 234; 234, identifier:v; 235, return_statement; 235, 236; 236, identifier:result | def as_version(self, version=Version.latest):
if not isinstance(self, list):
result = {}
for k, v in self.iteritems() if isinstance(self, dict) else vars(self).iteritems():
k = self._props_corrected.get(k, k)
if isinstance(v, SerializableBase):
result[k] = v.as_version(version)
elif isinstance(v, list):
result[k] = []
for val in v:
if isinstance(val, SerializableBase):
result[k].append(val.as_version(version))
else:
result[k].append(val)
elif isinstance(v, uuid.UUID):
result[k] = unicode(v)
elif isinstance(v, datetime.timedelta):
result[k] = jsonify_timedelta(v)
elif isinstance(v, datetime.datetime):
result[k] = jsonify_datetime(v)
else:
result[k] = v
result = self._filter_none(result)
else:
result = []
for v in self:
if isinstance(v, SerializableBase):
result.append(v.as_version(version))
else:
result.append(v)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:xrun; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 19; 4, identifier:command; 5, identifier:options; 6, default_parameter; 6, 7; 6, 8; 7, identifier:log; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:_log_container_as_started; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:logfile; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:timeout; 17, unary_operator:-; 17, 18; 18, integer:1; 19, default_parameter; 19, 20; 19, 21; 20, identifier:kill_callback; 21, None; 22, block; 22, 23; 22, 42; 22, 70; 22, 98; 22, 108; 22, 116; 22, 124; 22, 130; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:cmd; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, string:" "; 29, identifier:join; 30, argument_list; 30, 31; 31, binary_operator:+; 31, 32; 31, 34; 32, list:[command]; 32, 33; 33, identifier:command; 34, call; 34, 35; 34, 36; 35, identifier:list; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:map; 39, argument_list; 39, 40; 39, 41; 40, identifier:str; 41, identifier:options; 42, function_definition; 42, 43; 42, 44; 42, 46; 43, function_name:_print_info; 44, parameters; 44, 45; 45, identifier:msg; 46, block; 46, 47; 46, 53; 47, if_statement; 47, 48; 47, 51; 48, comparison_operator:is; 48, 49; 48, 50; 49, identifier:msg; 50, None; 51, block; 51, 52; 52, return_statement; 53, if_statement; 53, 54; 53, 55; 53, 63; 54, identifier:log; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:log; 60, identifier:info; 61, argument_list; 61, 62; 62, identifier:msg; 63, else_clause; 63, 64; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:print; 68, argument_list; 68, 69; 69, identifier:msg; 70, function_definition; 70, 71; 70, 72; 70, 74; 71, function_name:_print_warn; 72, parameters; 72, 73; 73, identifier:msg; 74, block; 74, 75; 74, 81; 75, if_statement; 75, 76; 75, 79; 76, comparison_operator:is; 76, 77; 76, 78; 77, identifier:msg; 78, None; 79, block; 79, 80; 80, return_statement; 81, if_statement; 81, 82; 81, 83; 81, 91; 82, identifier:log; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:log; 88, identifier:warn; 89, argument_list; 89, 90; 90, identifier:msg; 91, else_clause; 91, 92; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:print; 96, argument_list; 96, 97; 97, identifier:msg; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:_print_info; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, string:u"Running: {0:s}"; 105, identifier:format; 106, argument_list; 106, 107; 107, identifier:cmd; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:sys; 113, identifier:stdout; 114, identifier:flush; 115, argument_list; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:starttime; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:time; 122, identifier:time; 123, argument_list; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:process; 127, assignment; 127, 128; 127, 129; 128, identifier:p; 129, None; 130, try_statement; 130, 131; 130, 359; 131, block; 131, 132; 131, 164; 131, 338; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:foutname; 135, call; 135, 136; 135, 141; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:os; 139, identifier:path; 140, identifier:join; 141, argument_list; 141, 142; 141, 143; 142, string:"/tmp"; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, string:"stimela_output_{0:s}_{1:f}"; 146, identifier:format; 147, argument_list; 147, 148; 147, 163; 148, call; 148, 149; 148, 162; 149, attribute; 149, 150; 149, 161; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:hashlib; 153, identifier:md5; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:cmd; 158, identifier:encode; 159, argument_list; 159, 160; 160, string:'utf-8'; 161, identifier:hexdigest; 162, argument_list; 163, identifier:starttime; 164, with_statement; 164, 165; 164, 175; 165, with_clause; 165, 166; 166, with_item; 166, 167; 167, as_pattern; 167, 168; 167, 173; 168, call; 168, 169; 168, 170; 169, identifier:open; 170, argument_list; 170, 171; 170, 172; 171, identifier:foutname; 172, string:"w+"; 173, as_pattern_target; 173, 174; 174, identifier:fout; 175, block; 175, 176; 175, 196; 175, 274; 175, 292; 175, 331; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:p; 179, assignment; 179, 180; 179, 181; 180, identifier:process; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:subprocess; 184, identifier:Popen; 185, argument_list; 185, 186; 185, 187; 185, 190; 185, 193; 186, identifier:cmd; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:stderr; 189, identifier:fout; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:stdout; 192, identifier:fout; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:shell; 195, True; 196, function_definition; 196, 197; 196, 198; 196, 200; 197, function_name:clock_killer; 198, parameters; 198, 199; 199, identifier:p; 200, block; 200, 201; 201, while_statement; 201, 202; 201, 214; 202, boolean_operator:and; 202, 203; 202, 210; 203, comparison_operator:is; 203, 204; 203, 209; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:process; 207, identifier:poll; 208, argument_list; 209, None; 210, parenthesized_expression; 210, 211; 211, comparison_operator:>=; 211, 212; 211, 213; 212, identifier:timeout; 213, integer:0; 214, block; 214, 215; 214, 223; 214, 267; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:currenttime; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:time; 221, identifier:time; 222, argument_list; 223, if_statement; 223, 224; 223, 230; 223, 246; 224, parenthesized_expression; 224, 225; 225, comparison_operator:<; 225, 226; 225, 229; 226, binary_operator:-; 226, 227; 226, 228; 227, identifier:currenttime; 228, identifier:starttime; 229, identifier:timeout; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, boolean_operator:and; 232, 233; 232, 234; 233, identifier:DEBUG; 234, call; 234, 235; 234, 236; 235, identifier:_print_warn; 236, argument_list; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, string:u"Clock Reaper: has been running for {0:f}, must finish in {1:f}"; 240, identifier:format; 241, argument_list; 241, 242; 241, 245; 242, binary_operator:-; 242, 243; 242, 244; 243, identifier:currenttime; 244, identifier:starttime; 245, identifier:timeout; 246, else_clause; 246, 247; 247, block; 247, 248; 247, 258; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 251; 250, identifier:_print_warn; 251, argument_list; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, string:u"Clock Reaper: Timeout reached for '{0:s}'... sending the KILL signal"; 255, identifier:format; 256, argument_list; 256, 257; 257, identifier:cmd; 258, expression_statement; 258, 259; 259, boolean_operator:and; 259, 260; 259, 264; 260, parenthesized_expression; 260, 261; 261, comparison_operator:is; 261, 262; 261, 263; 262, identifier:kill_callback; 263, None; 264, call; 264, 265; 264, 266; 265, identifier:kill_callback; 266, argument_list; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:time; 271, identifier:sleep; 272, argument_list; 272, 273; 273, identifier:INTERRUPT_TIME; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 291; 276, attribute; 276, 277; 276, 290; 277, call; 277, 278; 277, 279; 278, identifier:Thread; 279, argument_list; 279, 280; 279, 283; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:target; 282, identifier:clock_killer; 283, keyword_argument; 283, 284; 283, 285; 284, identifier:args; 285, call; 285, 286; 285, 287; 286, identifier:tuple; 287, argument_list; 287, 288; 288, list:[p]; 288, 289; 289, identifier:p; 290, identifier:start; 291, argument_list; 292, while_statement; 292, 293; 292, 301; 293, parenthesized_expression; 293, 294; 294, comparison_operator:is; 294, 295; 294, 300; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:process; 298, identifier:poll; 299, argument_list; 300, None; 301, block; 301, 302; 301, 310; 301, 324; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:currenttime; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:time; 308, identifier:time; 309, argument_list; 310, expression_statement; 310, 311; 311, boolean_operator:and; 311, 312; 311, 313; 312, identifier:DEBUG; 313, call; 313, 314; 313, 315; 314, identifier:_print_info; 315, argument_list; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, string:u"God mode on: has been running for {0:f}"; 319, identifier:format; 320, argument_list; 320, 321; 321, binary_operator:-; 321, 322; 321, 323; 322, identifier:currenttime; 323, identifier:starttime; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:time; 328, identifier:sleep; 329, argument_list; 329, 330; 330, identifier:INTERRUPT_TIME; 331, assert_statement; 331, 332; 331, 337; 332, call; 332, 333; 332, 334; 333, identifier:hasattr; 334, argument_list; 334, 335; 334, 336; 335, identifier:process; 336, string:"returncode"; 337, string:"No returncode after termination!"; 338, with_statement; 338, 339; 338, 349; 339, with_clause; 339, 340; 340, with_item; 340, 341; 341, as_pattern; 341, 342; 341, 347; 342, call; 342, 343; 342, 344; 343, identifier:open; 344, argument_list; 344, 345; 344, 346; 345, identifier:foutname; 346, string:"r"; 347, as_pattern_target; 347, 348; 348, identifier:fout; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 353; 352, identifier:_print_info; 353, argument_list; 353, 354; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:fout; 357, identifier:read; 358, argument_list; 359, finally_clause; 359, 360; 360, block; 360, 361; 361, if_statement; 361, 362; 361, 370; 362, boolean_operator:and; 362, 363; 362, 367; 363, parenthesized_expression; 363, 364; 364, comparison_operator:is; 364, 365; 364, 366; 365, identifier:process; 366, None; 367, attribute; 367, 368; 367, 369; 368, identifier:process; 369, identifier:returncode; 370, block; 370, 371; 371, raise_statement; 371, 372; 372, call; 372, 373; 372, 374; 373, identifier:StimelaCabRuntimeError; 374, argument_list; 374, 375; 375, binary_operator:%; 375, 376; 375, 377; 376, string:'%s: returns errr code %d'; 377, tuple; 377, 378; 377, 379; 378, identifier:command; 379, attribute; 379, 380; 379, 381; 380, identifier:process; 381, identifier:returncode | def xrun(command, options, log=None, _log_container_as_started=False, logfile=None, timeout=-1, kill_callback=None):
cmd = " ".join([command] + list(map(str, options)) )
def _print_info(msg):
if msg is None: return
if log:
log.info(msg)
else:
print(msg)
def _print_warn(msg):
if msg is None: return
if log:
log.warn(msg)
else:
print(msg)
_print_info(u"Running: {0:s}".format(cmd))
sys.stdout.flush()
starttime = time.time()
process = p = None
try:
foutname = os.path.join("/tmp", "stimela_output_{0:s}_{1:f}".format(hashlib.md5(cmd.encode('utf-8')).hexdigest(), starttime))
with open(foutname, "w+") as fout:
p = process = subprocess.Popen(cmd,
stderr=fout,
stdout=fout,
shell=True)
def clock_killer(p):
while process.poll() is None and (timeout >= 0):
currenttime = time.time()
if (currenttime - starttime < timeout):
DEBUG and _print_warn(u"Clock Reaper: has been running for {0:f}, must finish in {1:f}".format(currenttime - starttime, timeout))
else:
_print_warn(u"Clock Reaper: Timeout reached for '{0:s}'... sending the KILL signal".format(cmd))
(kill_callback is not None) and kill_callback()
time.sleep(INTERRUPT_TIME)
Thread(target=clock_killer, args=tuple([p])).start()
while (process.poll() is None):
currenttime = time.time()
DEBUG and _print_info(u"God mode on: has been running for {0:f}".format(currenttime - starttime))
time.sleep(INTERRUPT_TIME)
assert hasattr(process, "returncode"), "No returncode after termination!"
with open(foutname, "r") as fout:
_print_info(fout.read())
finally:
if (process is not None) and process.returncode:
raise StimelaCabRuntimeError('%s: returns errr code %d' % (command, process.returncode)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:to_items; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:func; 7, identifier:str; 8, block; 8, 9; 9, return_statement; 9, 10; 10, list_comprehension; 10, 11; 10, 21; 11, tuple; 11, 12; 11, 13; 12, identifier:key; 13, call; 13, 14; 13, 15; 14, identifier:func; 15, argument_list; 15, 16; 16, subscript; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:kwargs; 20, identifier:key; 21, for_in_clause; 21, 22; 21, 23; 22, identifier:key; 23, call; 23, 24; 23, 25; 24, identifier:sorted; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:kwargs; 31, identifier:keys; 32, argument_list | def to_items(self, func=str):
return [
(key, func(self.kwargs[key]))
for key in sorted(self.kwargs.keys())
] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_apply_sub_frames; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:documents; 6, identifier:subs; 7, block; 7, 8; 8, for_statement; 8, 9; 8, 12; 8, 17; 9, pattern_list; 9, 10; 9, 11; 10, identifier:path; 11, identifier:projection; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:subs; 15, identifier:items; 16, argument_list; 17, block; 17, 18; 17, 22; 17, 26; 17, 61; 17, 65; 17, 238; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:sub; 21, None; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:expect_map; 25, False; 26, if_statement; 26, 27; 26, 30; 26, 40; 26, 58; 27, comparison_operator:in; 27, 28; 27, 29; 28, string:'$sub'; 29, identifier:projection; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:sub; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:projection; 37, identifier:pop; 38, argument_list; 38, 39; 39, string:'$sub'; 40, elif_clause; 40, 41; 40, 44; 41, comparison_operator:in; 41, 42; 41, 43; 42, string:'$sub.'; 43, identifier:projection; 44, block; 44, 45; 44, 54; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:sub; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:projection; 51, identifier:pop; 52, argument_list; 52, 53; 53, string:'$sub.'; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:expect_map; 57, True; 58, else_clause; 58, 59; 59, block; 59, 60; 60, continue_statement; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:raw_subs; 64, list:[]; 65, for_statement; 65, 66; 65, 67; 65, 68; 66, identifier:document; 67, identifier:documents; 68, block; 68, 69; 68, 79; 68, 85; 68, 201; 68, 205; 68, 214; 68, 229; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:value; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:cls; 75, identifier:_path_to_value; 76, argument_list; 76, 77; 76, 78; 77, identifier:path; 78, identifier:document; 79, if_statement; 79, 80; 79, 83; 80, comparison_operator:is; 80, 81; 80, 82; 81, identifier:value; 82, None; 83, block; 83, 84; 84, continue_statement; 85, if_statement; 85, 86; 85, 91; 85, 166; 85, 194; 86, call; 86, 87; 86, 88; 87, identifier:isinstance; 88, argument_list; 88, 89; 88, 90; 89, identifier:value; 90, identifier:dict; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 94; 92, 150; 93, identifier:expect_map; 94, block; 94, 95; 94, 103; 95, expression_statement; 95, 96; 96, augmented_assignment:+=; 96, 97; 96, 98; 97, identifier:raw_subs; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:value; 101, identifier:values; 102, argument_list; 103, for_statement; 103, 104; 103, 107; 103, 112; 104, pattern_list; 104, 105; 104, 106; 105, identifier:k; 106, identifier:v; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:value; 110, identifier:items; 111, argument_list; 112, block; 112, 113; 113, if_statement; 113, 114; 113, 119; 113, 139; 114, call; 114, 115; 114, 116; 115, identifier:isinstance; 116, argument_list; 116, 117; 116, 118; 117, identifier:v; 118, identifier:list; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:value; 124, identifier:k; 125, list_comprehension; 125, 126; 125, 130; 125, 133; 126, call; 126, 127; 126, 128; 127, identifier:sub; 128, argument_list; 128, 129; 129, identifier:u; 130, for_in_clause; 130, 131; 130, 132; 131, identifier:u; 132, identifier:v; 133, if_clause; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:isinstance; 136, argument_list; 136, 137; 136, 138; 137, identifier:u; 138, identifier:dict; 139, else_clause; 139, 140; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:value; 145, identifier:k; 146, call; 146, 147; 146, 148; 147, identifier:sub; 148, argument_list; 148, 149; 149, identifier:v; 150, else_clause; 150, 151; 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:raw_subs; 156, identifier:append; 157, argument_list; 157, 158; 158, identifier:value; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:value; 162, call; 162, 163; 162, 164; 163, identifier:sub; 164, argument_list; 164, 165; 165, identifier:value; 166, elif_clause; 166, 167; 166, 172; 167, call; 167, 168; 167, 169; 168, identifier:isinstance; 169, argument_list; 169, 170; 169, 171; 170, identifier:value; 171, identifier:list; 172, block; 172, 173; 172, 177; 173, expression_statement; 173, 174; 174, augmented_assignment:+=; 174, 175; 174, 176; 175, identifier:raw_subs; 176, identifier:value; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:value; 180, list_comprehension; 180, 181; 180, 185; 180, 188; 181, call; 181, 182; 181, 183; 182, identifier:sub; 183, argument_list; 183, 184; 184, identifier:v; 185, for_in_clause; 185, 186; 185, 187; 186, identifier:v; 187, identifier:value; 188, if_clause; 188, 189; 189, call; 189, 190; 189, 191; 190, identifier:isinstance; 191, argument_list; 191, 192; 191, 193; 192, identifier:v; 193, identifier:dict; 194, else_clause; 194, 195; 195, block; 195, 196; 196, raise_statement; 196, 197; 197, call; 197, 198; 197, 199; 198, identifier:TypeError; 199, argument_list; 199, 200; 200, string:'Not a supported sub-frame type'; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:child_document; 204, identifier:document; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:keys; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:cls; 211, identifier:_path_to_keys; 212, argument_list; 212, 213; 213, identifier:path; 214, for_statement; 214, 215; 214, 216; 214, 222; 215, identifier:key; 216, subscript; 216, 217; 216, 218; 217, identifier:keys; 218, slice; 218, 219; 218, 220; 219, colon; 220, unary_operator:-; 220, 221; 221, integer:1; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:child_document; 226, subscript; 226, 227; 226, 228; 227, identifier:child_document; 228, identifier:key; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 237; 231, subscript; 231, 232; 231, 233; 232, identifier:child_document; 233, subscript; 233, 234; 233, 235; 234, identifier:keys; 235, unary_operator:-; 235, 236; 236, integer:1; 237, identifier:value; 238, if_statement; 238, 239; 238, 240; 239, identifier:projection; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:sub; 245, identifier:_apply_projection; 246, argument_list; 246, 247; 246, 248; 247, identifier:raw_subs; 248, identifier:projection | def _apply_sub_frames(cls, documents, subs):
for path, projection in subs.items():
sub = None
expect_map = False
if '$sub' in projection:
sub = projection.pop('$sub')
elif '$sub.' in projection:
sub = projection.pop('$sub.')
expect_map = True
else:
continue
raw_subs = []
for document in documents:
value = cls._path_to_value(path, document)
if value is None:
continue
if isinstance(value, dict):
if expect_map:
raw_subs += value.values()
for k, v in value.items():
if isinstance(v ,list):
value[k] = [
sub(u) for u in v if isinstance(u, dict)]
else:
value[k] = sub(v)
else:
raw_subs.append(value)
value = sub(value)
elif isinstance(value, list):
raw_subs += value
value = [sub(v) for v in value if isinstance(v, dict)]
else:
raise TypeError('Not a supported sub-frame type')
child_document = document
keys = cls._path_to_keys(path)
for key in keys[:-1]:
child_document = child_document[key]
child_document[keys[-1]] = value
if projection:
sub._apply_projection(raw_subs, projection) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_dereference; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:documents; 6, identifier:references; 7, block; 7, 8; 8, for_statement; 8, 9; 8, 12; 8, 17; 9, pattern_list; 9, 10; 9, 11; 10, identifier:path; 11, identifier:projection; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:references; 15, identifier:items; 16, argument_list; 17, block; 17, 18; 17, 24; 17, 30; 17, 90; 17, 99; 17, 120; 17, 132; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:not; 19, 20; 19, 21; 20, string:'$ref'; 21, identifier:projection; 22, block; 22, 23; 23, continue_statement; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:ids; 27, call; 27, 28; 27, 29; 28, identifier:set; 29, argument_list; 30, for_statement; 30, 31; 30, 32; 30, 33; 31, identifier:document; 32, identifier:documents; 33, block; 33, 34; 33, 44; 33, 49; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:value; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:cls; 40, identifier:_path_to_value; 41, argument_list; 41, 42; 41, 43; 42, identifier:path; 43, identifier:document; 44, if_statement; 44, 45; 44, 47; 45, not_operator; 45, 46; 46, identifier:value; 47, block; 47, 48; 48, continue_statement; 49, if_statement; 49, 50; 49, 55; 49, 63; 49, 81; 50, call; 50, 51; 50, 52; 51, identifier:isinstance; 52, argument_list; 52, 53; 52, 54; 53, identifier:value; 54, identifier:list; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:ids; 60, identifier:update; 61, argument_list; 61, 62; 62, identifier:value; 63, elif_clause; 63, 64; 63, 69; 64, call; 64, 65; 64, 66; 65, identifier:isinstance; 66, argument_list; 66, 67; 66, 68; 67, identifier:value; 68, identifier:dict; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:ids; 74, identifier:update; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:value; 79, identifier:values; 80, argument_list; 81, else_clause; 81, 82; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:ids; 87, identifier:add; 88, argument_list; 88, 89; 89, identifier:value; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:ref; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:projection; 96, identifier:pop; 97, argument_list; 97, 98; 98, string:'$ref'; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:frames; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:ref; 105, identifier:many; 106, argument_list; 106, 107; 106, 117; 107, dictionary; 107, 108; 108, pair; 108, 109; 108, 110; 109, string:'_id'; 110, dictionary; 110, 111; 111, pair; 111, 112; 111, 113; 112, string:'$in'; 113, call; 113, 114; 113, 115; 114, identifier:list; 115, argument_list; 115, 116; 116, identifier:ids; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:projection; 119, identifier:projection; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:frames; 123, dictionary_comprehension; 123, 124; 123, 129; 124, pair; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:f; 127, identifier:_id; 128, identifier:f; 129, for_in_clause; 129, 130; 129, 131; 130, identifier:f; 131, identifier:frames; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:document; 134, identifier:documents; 135, block; 135, 136; 135, 146; 135, 151; 135, 212; 135, 216; 135, 225; 135, 240; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:value; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:cls; 142, identifier:_path_to_value; 143, argument_list; 143, 144; 143, 145; 144, identifier:path; 145, identifier:document; 146, if_statement; 146, 147; 146, 149; 147, not_operator; 147, 148; 148, identifier:value; 149, block; 149, 150; 150, continue_statement; 151, if_statement; 151, 152; 151, 157; 151, 172; 151, 200; 152, call; 152, 153; 152, 154; 153, identifier:isinstance; 154, argument_list; 154, 155; 154, 156; 155, identifier:value; 156, identifier:list; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:value; 161, list_comprehension; 161, 162; 161, 165; 161, 168; 162, subscript; 162, 163; 162, 164; 163, identifier:frames; 164, identifier:id; 165, for_in_clause; 165, 166; 165, 167; 166, identifier:id; 167, identifier:value; 168, if_clause; 168, 169; 169, comparison_operator:in; 169, 170; 169, 171; 170, identifier:id; 171, identifier:frames; 172, elif_clause; 172, 173; 172, 178; 173, call; 173, 174; 173, 175; 174, identifier:isinstance; 175, argument_list; 175, 176; 175, 177; 176, identifier:value; 177, identifier:dict; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:value; 182, dictionary_comprehension; 182, 183; 182, 191; 183, pair; 183, 184; 183, 185; 184, identifier:key; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:frames; 188, identifier:get; 189, argument_list; 189, 190; 190, identifier:id; 191, for_in_clause; 191, 192; 191, 195; 192, pattern_list; 192, 193; 192, 194; 193, identifier:key; 194, identifier:id; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:value; 198, identifier:items; 199, argument_list; 200, else_clause; 200, 201; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:value; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:frames; 208, identifier:get; 209, argument_list; 209, 210; 209, 211; 210, identifier:value; 211, None; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:child_document; 215, identifier:document; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:keys; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:cls; 222, identifier:_path_to_keys; 223, argument_list; 223, 224; 224, identifier:path; 225, for_statement; 225, 226; 225, 227; 225, 233; 226, identifier:key; 227, subscript; 227, 228; 227, 229; 228, identifier:keys; 229, slice; 229, 230; 229, 231; 230, colon; 231, unary_operator:-; 231, 232; 232, integer:1; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:child_document; 237, subscript; 237, 238; 237, 239; 238, identifier:child_document; 239, identifier:key; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 248; 242, subscript; 242, 243; 242, 244; 243, identifier:child_document; 244, subscript; 244, 245; 244, 246; 245, identifier:keys; 246, unary_operator:-; 246, 247; 247, integer:1; 248, identifier:value | def _dereference(cls, documents, references):
for path, projection in references.items():
if '$ref' not in projection:
continue
ids = set()
for document in documents:
value = cls._path_to_value(path, document)
if not value:
continue
if isinstance(value, list):
ids.update(value)
elif isinstance(value, dict):
ids.update(value.values())
else:
ids.add(value)
ref = projection.pop('$ref')
frames = ref.many(
{'_id': {'$in': list(ids)}},
projection=projection
)
frames = {f._id: f for f in frames}
for document in documents:
value = cls._path_to_value(path, document)
if not value:
continue
if isinstance(value, list):
value = [frames[id] for id in value if id in frames]
elif isinstance(value, dict):
value = {key: frames.get(id) for key, id in value.items()}
else:
value = frames.get(value, None)
child_document = document
keys = cls._path_to_keys(path)
for key in keys[:-1]:
child_document = child_document[key]
child_document[keys[-1]] = value |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:p; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:i; 5, identifier:sample_size; 6, identifier:weights; 7, block; 7, 8; 7, 14; 7, 21; 7, 28; 7, 32; 7, 36; 7, 125; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:weight_i; 11, subscript; 11, 12; 11, 13; 12, identifier:weights; 13, identifier:i; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:weights_sum; 17, call; 17, 18; 17, 19; 18, identifier:sum; 19, argument_list; 19, 20; 20, identifier:weights; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:other_weights; 24, call; 24, 25; 24, 26; 25, identifier:list; 26, argument_list; 26, 27; 27, identifier:weights; 28, delete_statement; 28, 29; 29, subscript; 29, 30; 29, 31; 30, identifier:other_weights; 31, identifier:i; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:probability_of_i; 35, integer:0; 36, for_statement; 36, 37; 36, 38; 36, 43; 37, identifier:picks; 38, call; 38, 39; 38, 40; 39, identifier:range; 40, argument_list; 40, 41; 40, 42; 41, integer:0; 42, identifier:sample_size; 43, block; 43, 44; 43, 57; 43, 61; 43, 118; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:permutations; 47, call; 47, 48; 47, 49; 48, identifier:list; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:itertools; 53, identifier:permutations; 54, argument_list; 54, 55; 54, 56; 55, identifier:other_weights; 56, identifier:picks; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:permutation_probabilities; 60, list:[]; 61, for_statement; 61, 62; 61, 63; 61, 64; 62, identifier:permutation; 63, identifier:permutations; 64, block; 64, 65; 64, 69; 64, 73; 64, 90; 64, 97; 64, 111; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:pick_probabilities; 68, list:[]; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:pick_weight_sum; 72, identifier:weights_sum; 73, for_statement; 73, 74; 73, 75; 73, 76; 74, identifier:pick; 75, identifier:permutation; 76, block; 76, 77; 76, 86; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:pick_probabilities; 81, identifier:append; 82, argument_list; 82, 83; 83, binary_operator:/; 83, 84; 83, 85; 84, identifier:pick; 85, identifier:pick_weight_sum; 86, expression_statement; 86, 87; 87, augmented_assignment:-=; 87, 88; 87, 89; 88, identifier:pick_weight_sum; 89, identifier:pick; 90, expression_statement; 90, 91; 91, augmented_assignment:+=; 91, 92; 91, 93; 92, identifier:pick_probabilities; 93, list:[weight_i / pick_weight_sum]; 93, 94; 94, binary_operator:/; 94, 95; 94, 96; 95, identifier:weight_i; 96, identifier:pick_weight_sum; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:permutation_probability; 100, call; 100, 101; 100, 102; 101, identifier:reduce; 102, argument_list; 102, 103; 102, 110; 103, lambda; 103, 104; 103, 107; 104, lambda_parameters; 104, 105; 104, 106; 105, identifier:x; 106, identifier:y; 107, binary_operator:*; 107, 108; 107, 109; 108, identifier:x; 109, identifier:y; 110, identifier:pick_probabilities; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:permutation_probabilities; 115, identifier:append; 116, argument_list; 116, 117; 117, identifier:permutation_probability; 118, expression_statement; 118, 119; 119, augmented_assignment:+=; 119, 120; 119, 121; 120, identifier:probability_of_i; 121, call; 121, 122; 121, 123; 122, identifier:sum; 123, argument_list; 123, 124; 124, identifier:permutation_probabilities; 125, return_statement; 125, 126; 126, identifier:probability_of_i | def p(i, sample_size, weights):
weight_i = weights[i]
weights_sum = sum(weights)
other_weights = list(weights)
del other_weights[i]
probability_of_i = 0
for picks in range(0, sample_size):
permutations = list(itertools.permutations(other_weights, picks))
permutation_probabilities = []
for permutation in permutations:
pick_probabilities = []
pick_weight_sum = weights_sum
for pick in permutation:
pick_probabilities.append(pick / pick_weight_sum)
pick_weight_sum -= pick
pick_probabilities += [weight_i / pick_weight_sum]
permutation_probability = reduce(
lambda x, y: x * y, pick_probabilities
)
permutation_probabilities.append(permutation_probability)
probability_of_i += sum(permutation_probabilities)
return probability_of_i |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:diff_to_html; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:details; 6, block; 6, 7; 6, 11; 6, 17; 6, 63; 6, 76; 6, 139; 6, 152; 6, 256; 6, 269; 6, 332; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:changes; 10, list:[]; 11, if_statement; 11, 12; 11, 14; 12, not_operator; 12, 13; 13, identifier:details; 14, block; 14, 15; 15, return_statement; 15, 16; 16, string:''; 17, function_definition; 17, 18; 17, 19; 17, 21; 18, function_name:_frame; 19, parameters; 19, 20; 20, identifier:value; 21, block; 21, 22; 21, 58; 22, if_statement; 22, 23; 22, 32; 22, 37; 23, boolean_operator:and; 23, 24; 23, 29; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 28; 27, identifier:value; 28, identifier:dict; 29, comparison_operator:in; 29, 30; 29, 31; 30, string:'_str'; 31, identifier:value; 32, block; 32, 33; 33, return_statement; 33, 34; 34, subscript; 34, 35; 34, 36; 35, identifier:value; 36, string:'_str'; 37, elif_clause; 37, 38; 37, 43; 38, call; 38, 39; 38, 40; 39, identifier:isinstance; 40, argument_list; 40, 41; 40, 42; 41, identifier:value; 42, identifier:list; 43, block; 43, 44; 44, return_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, string:', '; 48, identifier:join; 49, argument_list; 49, 50; 50, list_comprehension; 50, 51; 50, 55; 51, call; 51, 52; 51, 53; 52, identifier:_frame; 53, argument_list; 53, 54; 54, identifier:v; 55, for_in_clause; 55, 56; 55, 57; 56, identifier:v; 57, identifier:value; 58, return_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:str; 61, argument_list; 61, 62; 62, identifier:value; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:fields; 66, call; 66, 67; 66, 68; 67, identifier:sorted; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:details; 72, identifier:get; 73, argument_list; 73, 74; 73, 75; 74, string:'additions'; 75, dictionary; 76, for_statement; 76, 77; 76, 78; 76, 79; 77, identifier:field; 78, identifier:fields; 79, block; 79, 80; 79, 91; 79, 114; 79, 132; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:new_value; 83, call; 83, 84; 83, 85; 84, identifier:_frame; 85, argument_list; 85, 86; 86, subscript; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:details; 89, string:'additions'; 90, identifier:field; 91, if_statement; 91, 92; 91, 97; 92, call; 92, 93; 92, 94; 93, identifier:isinstance; 94, argument_list; 94, 95; 94, 96; 95, identifier:new_value; 96, identifier:list; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:new_value; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, string:', '; 104, identifier:join; 105, argument_list; 105, 106; 106, list_comprehension; 106, 107; 106, 111; 107, call; 107, 108; 107, 109; 108, identifier:_frame; 109, argument_list; 109, 110; 110, identifier:v; 111, for_in_clause; 111, 112; 111, 113; 112, identifier:v; 113, identifier:new_value; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:change; 117, call; 117, 118; 117, 125; 118, attribute; 118, 119; 118, 124; 119, subscript; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:cls; 122, identifier:_templates; 123, string:'add'; 124, identifier:format; 125, argument_list; 125, 126; 125, 129; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:field; 128, identifier:field; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:new_value; 131, identifier:new_value; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:changes; 136, identifier:append; 137, argument_list; 137, 138; 138, identifier:change; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:fields; 142, call; 142, 143; 142, 144; 143, identifier:sorted; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:details; 148, identifier:get; 149, argument_list; 149, 150; 149, 151; 150, string:'updates'; 151, dictionary; 152, for_statement; 152, 153; 152, 154; 152, 155; 153, identifier:field; 154, identifier:fields; 155, block; 155, 156; 155, 169; 155, 192; 155, 205; 155, 228; 155, 249; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:original_value; 159, call; 159, 160; 159, 161; 160, identifier:_frame; 161, argument_list; 161, 162; 162, subscript; 162, 163; 162, 168; 163, subscript; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:details; 166, string:'updates'; 167, identifier:field; 168, integer:0; 169, if_statement; 169, 170; 169, 175; 170, call; 170, 171; 170, 172; 171, identifier:isinstance; 172, argument_list; 172, 173; 172, 174; 173, identifier:original_value; 174, identifier:list; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:original_value; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, string:', '; 182, identifier:join; 183, argument_list; 183, 184; 184, list_comprehension; 184, 185; 184, 189; 185, call; 185, 186; 185, 187; 186, identifier:_frame; 187, argument_list; 187, 188; 188, identifier:v; 189, for_in_clause; 189, 190; 189, 191; 190, identifier:v; 191, identifier:original_value; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:new_value; 195, call; 195, 196; 195, 197; 196, identifier:_frame; 197, argument_list; 197, 198; 198, subscript; 198, 199; 198, 204; 199, subscript; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:details; 202, string:'updates'; 203, identifier:field; 204, integer:1; 205, if_statement; 205, 206; 205, 211; 206, call; 206, 207; 206, 208; 207, identifier:isinstance; 208, argument_list; 208, 209; 208, 210; 209, identifier:new_value; 210, identifier:list; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:new_value; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, string:', '; 218, identifier:join; 219, argument_list; 219, 220; 220, list_comprehension; 220, 221; 220, 225; 221, call; 221, 222; 221, 223; 222, identifier:_frame; 223, argument_list; 223, 224; 224, identifier:v; 225, for_in_clause; 225, 226; 225, 227; 226, identifier:v; 227, identifier:new_value; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:change; 231, call; 231, 232; 231, 239; 232, attribute; 232, 233; 232, 238; 233, subscript; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:cls; 236, identifier:_templates; 237, string:'update'; 238, identifier:format; 239, argument_list; 239, 240; 239, 243; 239, 246; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:field; 242, identifier:field; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:original_value; 245, identifier:original_value; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:new_value; 248, identifier:new_value; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:changes; 253, identifier:append; 254, argument_list; 254, 255; 255, identifier:change; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:fields; 259, call; 259, 260; 259, 261; 260, identifier:sorted; 261, argument_list; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:details; 265, identifier:get; 266, argument_list; 266, 267; 266, 268; 267, string:'deletions'; 268, dictionary; 269, for_statement; 269, 270; 269, 271; 269, 272; 270, identifier:field; 271, identifier:fields; 272, block; 272, 273; 272, 284; 272, 307; 272, 325; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:original_value; 276, call; 276, 277; 276, 278; 277, identifier:_frame; 278, argument_list; 278, 279; 279, subscript; 279, 280; 279, 283; 280, subscript; 280, 281; 280, 282; 281, identifier:details; 282, string:'deletions'; 283, identifier:field; 284, if_statement; 284, 285; 284, 290; 285, call; 285, 286; 285, 287; 286, identifier:isinstance; 287, argument_list; 287, 288; 287, 289; 288, identifier:original_value; 289, identifier:list; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:original_value; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, string:', '; 297, identifier:join; 298, argument_list; 298, 299; 299, list_comprehension; 299, 300; 299, 304; 300, call; 300, 301; 300, 302; 301, identifier:_frame; 302, argument_list; 302, 303; 303, identifier:v; 304, for_in_clause; 304, 305; 304, 306; 305, identifier:v; 306, identifier:original_value; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:change; 310, call; 310, 311; 310, 318; 311, attribute; 311, 312; 311, 317; 312, subscript; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:cls; 315, identifier:_templates; 316, string:'delete'; 317, identifier:format; 318, argument_list; 318, 319; 318, 322; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:field; 321, identifier:field; 322, keyword_argument; 322, 323; 322, 324; 323, identifier:original_value; 324, identifier:original_value; 325, expression_statement; 325, 326; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:changes; 329, identifier:append; 330, argument_list; 330, 331; 331, identifier:change; 332, return_statement; 332, 333; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, string:'\n'; 336, identifier:join; 337, argument_list; 337, 338; 338, identifier:changes | def diff_to_html(cls, details):
changes = []
if not details:
return ''
def _frame(value):
if isinstance(value, dict) and '_str' in value:
return value['_str']
elif isinstance(value, list):
return ', '.join([_frame(v) for v in value])
return str(value)
fields = sorted(details.get('additions', {}))
for field in fields:
new_value = _frame(details['additions'][field])
if isinstance(new_value, list):
new_value = ', '.join([_frame(v) for v in new_value])
change = cls._templates['add'].format(
field=field,
new_value=new_value
)
changes.append(change)
fields = sorted(details.get('updates', {}))
for field in fields:
original_value = _frame(details['updates'][field][0])
if isinstance(original_value, list):
original_value = ', '.join([_frame(v) for v in original_value])
new_value = _frame(details['updates'][field][1])
if isinstance(new_value, list):
new_value = ', '.join([_frame(v) for v in new_value])
change = cls._templates['update'].format(
field=field,
original_value=original_value,
new_value=new_value
)
changes.append(change)
fields = sorted(details.get('deletions', {}))
for field in fields:
original_value = _frame(details['deletions'][field])
if isinstance(original_value, list):
original_value = ', '.join([_frame(v) for v in original_value])
change = cls._templates['delete'].format(
field=field,
original_value=original_value
)
changes.append(change)
return '\n'.join(changes) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:SortBy; 3, parameters; 3, 4; 4, list_splat_pattern; 4, 5; 5, identifier:qs; 6, block; 6, 7; 6, 11; 6, 54; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:sort; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:q; 13, identifier:qs; 14, block; 14, 15; 15, if_statement; 15, 16; 15, 24; 15, 41; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:q; 20, identifier:_path; 21, identifier:endswith; 22, argument_list; 22, 23; 23, string:'.desc'; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:sort; 29, identifier:append; 30, argument_list; 30, 31; 31, tuple; 31, 32; 31, 40; 32, subscript; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:q; 35, identifier:_path; 36, slice; 36, 37; 36, 38; 37, colon; 38, unary_operator:-; 38, 39; 39, integer:5; 40, identifier:DESCENDING; 41, else_clause; 41, 42; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:sort; 47, identifier:append; 48, argument_list; 48, 49; 49, tuple; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:q; 52, identifier:_path; 53, identifier:ASCENDING; 54, return_statement; 54, 55; 55, identifier:sort | def SortBy(*qs):
sort = []
for q in qs:
if q._path.endswith('.desc'):
sort.append((q._path[:-5], DESCENDING))
else:
sort.append((q._path, ASCENDING))
return sort |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:refresh; 3, parameters; 4, block; 4, 5; 4, 9; 4, 51; 4, 65; 4, 72; 4, 141; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:override_files; 8, list:[]; 9, for_statement; 9, 10; 9, 11; 9, 16; 10, identifier:stack; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:traceback; 14, identifier:extract_stack; 15, argument_list; 16, block; 16, 17; 16, 38; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:f; 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, 37; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:os; 31, identifier:path; 32, identifier:dirname; 33, argument_list; 33, 34; 34, subscript; 34, 35; 34, 36; 35, identifier:stack; 36, integer:0; 37, identifier:OVERRIDE_FILE; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:not; 39, 40; 39, 41; 40, identifier:f; 41, identifier:override_files; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:override_files; 47, identifier:insert; 48, argument_list; 48, 49; 48, 50; 49, integer:0; 50, identifier:f; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:in; 52, 53; 52, 54; 53, identifier:OVERRIDE_FILE; 54, identifier:override_files; 55, block; 55, 56; 56, delete_statement; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:override_files; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:override_files; 62, identifier:index; 63, argument_list; 63, 64; 64, identifier:OVERRIDE_FILE; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:override_files; 69, identifier:append; 70, argument_list; 70, 71; 71, identifier:OVERRIDE_FILE; 72, function_definition; 72, 73; 72, 74; 72, 76; 73, function_name:import_path; 74, parameters; 74, 75; 75, identifier:path; 76, block; 76, 77; 76, 103; 76, 107; 76, 119; 76, 130; 76, 139; 77, if_statement; 77, 78; 77, 86; 78, comparison_operator:<; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:sys; 81, identifier:version_info; 82, tuple; 82, 83; 82, 84; 82, 85; 83, integer:3; 84, integer:5; 85, integer:0; 86, block; 86, 87; 86, 93; 87, import_from_statement; 87, 88; 87, 91; 88, dotted_name; 88, 89; 88, 90; 89, identifier:importlib; 90, identifier:machinery; 91, dotted_name; 91, 92; 92, identifier:SourceFileLoader; 93, return_statement; 93, 94; 94, call; 94, 95; 94, 102; 95, attribute; 95, 96; 95, 101; 96, call; 96, 97; 96, 98; 97, identifier:SourceFileLoader; 98, argument_list; 98, 99; 98, 100; 99, identifier:__name__; 100, identifier:path; 101, identifier:load_module; 102, argument_list; 103, import_statement; 103, 104; 104, dotted_name; 104, 105; 104, 106; 105, identifier:importlib; 106, identifier:util; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:spec; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:importlib; 114, identifier:util; 115, identifier:spec_from_file_location; 116, argument_list; 116, 117; 116, 118; 117, identifier:__name__; 118, identifier:path; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:module; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:importlib; 126, identifier:util; 127, identifier:module_from_spec; 128, argument_list; 128, 129; 129, identifier:spec; 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:spec; 135, identifier:loader; 136, identifier:exec_module; 137, argument_list; 137, 138; 138, identifier:module; 139, return_statement; 139, 140; 140, identifier:module; 141, for_statement; 141, 142; 141, 143; 141, 144; 142, identifier:override_file; 143, identifier:override_files; 144, block; 144, 145; 144, 157; 144, 164; 145, if_statement; 145, 146; 145, 155; 146, not_operator; 146, 147; 147, call; 147, 148; 147, 153; 148, attribute; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:os; 151, identifier:path; 152, identifier:isfile; 153, argument_list; 153, 154; 154, identifier:override_file; 155, block; 155, 156; 156, continue_statement; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:mod; 160, call; 160, 161; 160, 162; 161, identifier:import_path; 162, argument_list; 162, 163; 163, identifier:override_file; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, call; 167, 168; 167, 169; 168, identifier:globals; 169, argument_list; 170, identifier:update; 171, argument_list; 171, 172; 172, dictionary_comprehension; 172, 173; 172, 180; 172, 186; 173, pair; 173, 174; 173, 175; 174, identifier:n; 175, call; 175, 176; 175, 177; 176, identifier:getattr; 177, argument_list; 177, 178; 177, 179; 178, identifier:mod; 179, identifier:n; 180, for_in_clause; 180, 181; 180, 182; 181, identifier:n; 182, call; 182, 183; 182, 184; 183, identifier:dir; 184, argument_list; 184, 185; 185, identifier:mod; 186, if_clause; 186, 187; 187, not_operator; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:n; 191, identifier:startswith; 192, argument_list; 192, 193; 193, string:"__" | def refresh():
override_files = []
for stack in traceback.extract_stack():
f = os.path.join(os.path.dirname(stack[0]), OVERRIDE_FILE)
if f not in override_files:
override_files.insert(0, f)
if OVERRIDE_FILE in override_files:
del override_files[override_files.index(OVERRIDE_FILE)]
override_files.append(OVERRIDE_FILE)
def import_path(path):
if sys.version_info < (3, 5, 0):
from importlib.machinery import SourceFileLoader
return SourceFileLoader(__name__, path).load_module()
import importlib.util
spec = importlib.util.spec_from_file_location(__name__, path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
for override_file in override_files:
if not os.path.isfile(override_file):
continue
mod = import_path(override_file)
globals().update({n: getattr(mod, n) for n in dir(mod) if not n.startswith("__")}) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:setup; 3, parameters; 3, 4; 3, 14; 3, 18; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:level; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Union; 9, type_parameter; 9, 10; 9, 12; 10, type; 10, 11; 11, identifier:str; 12, type; 12, 13; 13, identifier:int; 14, typed_parameter; 14, 15; 14, 16; 15, identifier:structured; 16, type; 16, 17; 17, identifier:bool; 18, typed_default_parameter; 18, 19; 18, 20; 18, 22; 19, identifier:config_path; 20, type; 20, 21; 21, identifier:str; 22, None; 23, block; 23, 24; 23, 26; 23, 30; 23, 46; 23, 89; 23, 112; 23, 118; 23, 125; 23, 189; 23, 197; 23, 204; 24, global_statement; 24, 25; 25, identifier:logs_are_structured; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:logs_are_structured; 29, identifier:structured; 30, if_statement; 30, 31; 30, 37; 31, not_operator; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:isinstance; 34, argument_list; 34, 35; 34, 36; 35, identifier:level; 36, identifier:int; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:level; 41, subscript; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:logging; 44, identifier:_nameToLevel; 45, identifier:level; 46, function_definition; 46, 47; 46, 48; 46, 50; 47, function_name:ensure_utf8_stream; 48, parameters; 48, 49; 49, identifier:stream; 50, block; 50, 51; 50, 87; 51, if_statement; 51, 52; 51, 66; 52, boolean_operator:and; 52, 53; 52, 61; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:stream; 58, attribute; 58, 59; 58, 60; 59, identifier:io; 60, identifier:StringIO; 61, call; 61, 62; 61, 63; 62, identifier:hasattr; 63, argument_list; 63, 64; 63, 65; 64, identifier:stream; 65, string:"buffer"; 66, block; 66, 67; 66, 81; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:stream; 70, call; 70, 71; 70, 77; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:codecs; 74, identifier:getwriter; 75, argument_list; 75, 76; 76, string:"utf-8"; 77, argument_list; 77, 78; 78, attribute; 78, 79; 78, 80; 79, identifier:stream; 80, identifier:buffer; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:stream; 85, identifier:encoding; 86, string:"utf-8"; 87, return_statement; 87, 88; 88, identifier:stream; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 98; 91, pattern_list; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:sys; 94, identifier:stdout; 95, attribute; 95, 96; 95, 97; 96, identifier:sys; 97, identifier:stderr; 98, generator_expression; 98, 99; 98, 103; 99, call; 99, 100; 99, 101; 100, identifier:ensure_utf8_stream; 101, argument_list; 101, 102; 102, identifier:s; 103, for_in_clause; 103, 104; 103, 105; 104, identifier:s; 105, tuple; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:sys; 108, identifier:stdout; 109, attribute; 109, 110; 109, 111; 110, identifier:sys; 111, identifier:stderr; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:logging; 116, identifier:basicConfig; 117, argument_list; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:logging; 122, identifier:setLogRecordFactory; 123, argument_list; 123, 124; 124, identifier:NumpyLogRecord; 125, if_statement; 125, 126; 125, 138; 126, boolean_operator:and; 126, 127; 126, 130; 127, comparison_operator:is; 127, 128; 127, 129; 128, identifier:config_path; 129, None; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:os; 134, identifier:path; 135, identifier:isfile; 136, argument_list; 136, 137; 137, identifier:config_path; 138, block; 138, 139; 138, 159; 139, with_statement; 139, 140; 139, 149; 140, with_clause; 140, 141; 141, with_item; 141, 142; 142, as_pattern; 142, 143; 142, 147; 143, call; 143, 144; 143, 145; 144, identifier:open; 145, argument_list; 145, 146; 146, identifier:config_path; 147, as_pattern_target; 147, 148; 148, identifier:fh; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:config; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:yaml; 156, identifier:safe_load; 157, argument_list; 157, 158; 158, identifier:fh; 159, for_statement; 159, 160; 159, 163; 159, 168; 160, pattern_list; 160, 161; 160, 162; 161, identifier:key; 162, identifier:val; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:config; 166, identifier:items; 167, argument_list; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 179; 171, attribute; 171, 172; 171, 178; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:logging; 175, identifier:getLogger; 176, argument_list; 176, 177; 177, identifier:key; 178, identifier:setLevel; 179, argument_list; 179, 180; 180, call; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:logging; 184, identifier:_nameToLevel; 185, identifier:get; 186, argument_list; 186, 187; 186, 188; 187, identifier:val; 188, identifier:level; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:root; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:logging; 195, identifier:getLogger; 196, argument_list; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:root; 201, identifier:setLevel; 202, argument_list; 202, 203; 203, identifier:level; 204, if_statement; 204, 205; 204, 207; 204, 241; 205, not_operator; 205, 206; 206, identifier:structured; 207, block; 207, 208; 208, if_statement; 208, 209; 208, 223; 209, boolean_operator:and; 209, 210; 209, 216; 210, not_operator; 210, 211; 211, attribute; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:sys; 214, identifier:stdin; 215, identifier:closed; 216, call; 216, 217; 216, 222; 217, attribute; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:sys; 220, identifier:stdout; 221, identifier:isatty; 222, argument_list; 223, block; 223, 224; 223, 232; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:handler; 227, subscript; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:root; 230, identifier:handlers; 231, integer:0; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:handler; 236, identifier:setFormatter; 237, argument_list; 237, 238; 238, call; 238, 239; 238, 240; 239, identifier:AwesomeFormatter; 240, argument_list; 241, else_clause; 241, 242; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 250; 245, subscript; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:root; 248, identifier:handlers; 249, integer:0; 250, call; 250, 251; 250, 252; 251, identifier:StructuredHandler; 252, argument_list; 252, 253; 253, identifier:level | def setup(level: Union[str, int], structured: bool, config_path: str = None):
global logs_are_structured
logs_are_structured = structured
if not isinstance(level, int):
level = logging._nameToLevel[level]
def ensure_utf8_stream(stream):
if not isinstance(stream, io.StringIO) and hasattr(stream, "buffer"):
stream = codecs.getwriter("utf-8")(stream.buffer)
stream.encoding = "utf-8"
return stream
sys.stdout, sys.stderr = (ensure_utf8_stream(s)
for s in (sys.stdout, sys.stderr))
logging.basicConfig()
logging.setLogRecordFactory(NumpyLogRecord)
if config_path is not None and os.path.isfile(config_path):
with open(config_path) as fh:
config = yaml.safe_load(fh)
for key, val in config.items():
logging.getLogger(key).setLevel(logging._nameToLevel.get(val, level))
root = logging.getLogger()
root.setLevel(level)
if not structured:
if not sys.stdin.closed and sys.stdout.isatty():
handler = root.handlers[0]
handler.setFormatter(AwesomeFormatter())
else:
root.handlers[0] = StructuredHandler(level) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:getMessage; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 39; 5, 148; 6, if_statement; 6, 7; 6, 16; 6, 28; 7, call; 7, 8; 7, 9; 8, identifier:isinstance; 9, argument_list; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:msg; 13, attribute; 13, 14; 13, 15; 14, identifier:numpy; 15, identifier:ndarray; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:msg; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:array2string; 24, argument_list; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:msg; 28, else_clause; 28, 29; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:msg; 33, call; 33, 34; 33, 35; 34, identifier:str; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:msg; 39, if_statement; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:args; 43, block; 43, 44; 43, 50; 43, 142; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:a2s; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:array2string; 50, if_statement; 50, 51; 50, 58; 50, 90; 50, 124; 51, call; 51, 52; 51, 53; 52, identifier:isinstance; 53, argument_list; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:args; 57, identifier:Dict; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:args; 62, dictionary_comprehension; 62, 63; 62, 79; 63, pair; 63, 64; 63, 65; 64, identifier:k; 65, parenthesized_expression; 65, 66; 66, conditional_expression:if; 66, 67; 66, 71; 66, 78; 67, call; 67, 68; 67, 69; 68, identifier:a2s; 69, argument_list; 69, 70; 70, identifier:v; 71, call; 71, 72; 71, 73; 72, identifier:isinstance; 73, argument_list; 73, 74; 73, 75; 74, identifier:v; 75, attribute; 75, 76; 75, 77; 76, identifier:numpy; 77, identifier:ndarray; 78, identifier:v; 79, for_in_clause; 79, 80; 79, 83; 80, tuple_pattern; 80, 81; 80, 82; 81, identifier:k; 82, identifier:v; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:args; 88, identifier:items; 89, argument_list; 90, elif_clause; 90, 91; 90, 98; 91, call; 91, 92; 91, 93; 92, identifier:isinstance; 93, argument_list; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:args; 97, identifier:Sequence; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:args; 102, call; 102, 103; 102, 104; 103, identifier:tuple; 104, generator_expression; 104, 105; 104, 119; 105, parenthesized_expression; 105, 106; 106, conditional_expression:if; 106, 107; 106, 111; 106, 118; 107, call; 107, 108; 107, 109; 108, identifier:a2s; 109, argument_list; 109, 110; 110, identifier:a; 111, call; 111, 112; 111, 113; 112, identifier:isinstance; 113, argument_list; 113, 114; 113, 115; 114, identifier:a; 115, attribute; 115, 116; 115, 117; 116, identifier:numpy; 117, identifier:ndarray; 118, identifier:a; 119, for_in_clause; 119, 120; 119, 121; 120, identifier:a; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:args; 124, else_clause; 124, 125; 125, block; 125, 126; 126, raise_statement; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:TypeError; 129, argument_list; 129, 130; 130, binary_operator:%; 130, 131; 130, 132; 131, string:"Unexpected input '%s' with type '%s'"; 132, tuple; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:args; 136, call; 136, 137; 136, 138; 137, identifier:type; 138, argument_list; 138, 139; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:args; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:msg; 145, binary_operator:%; 145, 146; 145, 147; 146, identifier:msg; 147, identifier:args; 148, return_statement; 148, 149; 149, identifier:msg | def getMessage(self):
if isinstance(self.msg, numpy.ndarray):
msg = self.array2string(self.msg)
else:
msg = str(self.msg)
if self.args:
a2s = self.array2string
if isinstance(self.args, Dict):
args = {k: (a2s(v) if isinstance(v, numpy.ndarray) else v)
for (k, v) in self.args.items()}
elif isinstance(self.args, Sequence):
args = tuple((a2s(a) if isinstance(a, numpy.ndarray) else a)
for a in self.args)
else:
raise TypeError("Unexpected input '%s' with type '%s'" % (self.args,
type(self.args)))
msg = msg % args
return msg |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:toposorted; 3, parameters; 3, 4; 3, 5; 4, identifier:nodes; 5, identifier:edges; 6, block; 6, 7; 6, 14; 6, 21; 6, 51; 6, 62; 6, 66; 6, 138; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:incoming; 10, call; 10, 11; 10, 12; 11, identifier:defaultdict; 12, argument_list; 12, 13; 13, identifier:set; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:outgoing; 17, call; 17, 18; 17, 19; 18, identifier:defaultdict; 19, argument_list; 19, 20; 20, identifier:set; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:edge; 23, identifier:edges; 24, block; 24, 25; 24, 38; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 34; 27, attribute; 27, 28; 27, 33; 28, subscript; 28, 29; 28, 30; 29, identifier:incoming; 30, attribute; 30, 31; 30, 32; 31, identifier:edge; 32, identifier:to_id; 33, identifier:add; 34, argument_list; 34, 35; 35, attribute; 35, 36; 35, 37; 36, identifier:edge; 37, identifier:from_id; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 47; 40, attribute; 40, 41; 40, 46; 41, subscript; 41, 42; 41, 43; 42, identifier:outgoing; 43, attribute; 43, 44; 43, 45; 44, identifier:edge; 45, identifier:from_id; 46, identifier:add; 47, argument_list; 47, 48; 48, attribute; 48, 49; 48, 50; 49, identifier:edge; 50, identifier:to_id; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:working_set; 54, call; 54, 55; 54, 56; 55, identifier:list; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:nodes; 60, identifier:values; 61, argument_list; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:results; 65, list:[]; 66, while_statement; 66, 67; 66, 68; 67, identifier:working_set; 68, block; 68, 69; 68, 73; 68, 118; 68, 134; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:remaining; 72, list:[]; 73, for_statement; 73, 74; 73, 75; 73, 76; 74, identifier:node; 75, identifier:working_set; 76, block; 76, 77; 76, 92; 76, 99; 77, if_statement; 77, 78; 77, 83; 78, subscript; 78, 79; 78, 80; 79, identifier:incoming; 80, attribute; 80, 81; 80, 82; 81, identifier:node; 82, identifier:id; 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:remaining; 88, identifier:append; 89, argument_list; 89, 90; 90, identifier:node; 91, continue_statement; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:results; 96, identifier:append; 97, argument_list; 97, 98; 98, identifier:node; 99, for_statement; 99, 100; 99, 101; 99, 106; 100, identifier:child; 101, subscript; 101, 102; 101, 103; 102, identifier:outgoing; 103, attribute; 103, 104; 103, 105; 104, identifier:node; 105, identifier:id; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 114; 109, attribute; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:incoming; 112, identifier:child; 113, identifier:remove; 114, argument_list; 114, 115; 115, attribute; 115, 116; 115, 117; 116, identifier:node; 117, identifier:id; 118, if_statement; 118, 119; 118, 128; 119, comparison_operator:==; 119, 120; 119, 124; 120, call; 120, 121; 120, 122; 121, identifier:len; 122, argument_list; 122, 123; 123, identifier:working_set; 124, call; 124, 125; 124, 126; 125, identifier:len; 126, argument_list; 126, 127; 127, identifier:remaining; 128, block; 128, 129; 129, raise_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:Exception; 132, argument_list; 132, 133; 133, string:"Cycle detected"; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:working_set; 137, identifier:remaining; 138, return_statement; 138, 139; 139, identifier:results | def toposorted(nodes, edges):
incoming = defaultdict(set)
outgoing = defaultdict(set)
for edge in edges:
incoming[edge.to_id].add(edge.from_id)
outgoing[edge.from_id].add(edge.to_id)
working_set = list(nodes.values())
results = []
while working_set:
remaining = []
for node in working_set:
if incoming[node.id]:
remaining.append(node)
continue
results.append(node)
for child in outgoing[node.id]:
incoming[child].remove(node.id)
if len(working_set) == len(remaining):
raise Exception("Cycle detected")
working_set = remaining
return results |
0, ERROR; 0, 1; 0, 2; 0, 5; 0, 7; 0, 41; 0, 51; 0, 63; 0, 74; 0, 77; 0, 303; 0, 306; 0, 324; 0, 334; 0, 335; 1, identifier:proc; 2, parameters; 2, 3; 2, 4; 3, identifier:ctx; 4, identifier:files; 5, expression_statement; 5, 6; 6, string:'''Process calculated structures'''; 7, function_definition; 7, 8; 7, 9; 7, 12; 8, function_name:calc_reader; 9, parameters; 9, 10; 9, 11; 10, identifier:fn; 11, identifier:verb; 12, block; 12, 13; 12, 32; 13, if_statement; 13, 14; 13, 15; 14, identifier:verb; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:echo; 19, argument_list; 19, 20; 19, 26; 19, 29; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, string:'Reading: {:<60s}\r'; 23, identifier:format; 24, argument_list; 24, 25; 25, identifier:fn; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:nl; 28, False; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:err; 31, True; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:ase; 37, identifier:io; 38, identifier:read; 39, argument_list; 39, 40; 40, identifier:fn; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:action; 44, subscript; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:ctx; 48, identifier:parent; 49, identifier:params; 50, string:'action'; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:systems; 54, list_comprehension; 54, 55; 54, 60; 55, call; 55, 56; 55, 57; 56, identifier:calc_reader; 57, argument_list; 57, 58; 57, 59; 58, identifier:calc; 59, identifier:verbose; 60, for_in_clause; 60, 61; 60, 62; 61, identifier:calc; 62, identifier:files; 63, if_statement; 63, 64; 63, 65; 64, identifier:verbose; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:echo; 69, argument_list; 69, 70; 69, 71; 70, string:''; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:err; 73, True; 74, comparison_operator:==; 74, 75; 74, 76; 75, identifier:action; 76, string:'cij'; 77, block; 77, 78; 77, 96; 77, 108; 77, 112; 77, 256; 77, 299; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:cij; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:elastic; 84, identifier:get_elastic_tensor; 85, argument_list; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:systems; 88, integer:0; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:systems; 91, subscript; 91, 92; 91, 93; 92, identifier:systems; 93, slice; 93, 94; 93, 95; 94, integer:1; 95, colon; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:msv; 99, call; 99, 100; 99, 107; 100, attribute; 100, 101; 100, 106; 101, subscript; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:cij; 104, integer:1; 105, integer:3; 106, identifier:max; 107, argument_list; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:eps; 111, float:1e-4; 112, if_statement; 112, 113; 112, 114; 113, identifier:verbose; 114, block; 114, 115; 114, 124; 114, 153; 114, 181; 114, 186; 114, 216; 114, 221; 114, 247; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:echo; 118, argument_list; 118, 119; 119, binary_operator:+; 119, 120; 119, 121; 120, string:'Cij solution\n'; 121, binary_operator:*; 121, 122; 121, 123; 122, integer:30; 123, string:'-'; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:echo; 127, argument_list; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, string:' Solution rank: {:2d}{}'; 131, identifier:format; 132, argument_list; 132, 133; 132, 138; 133, subscript; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:cij; 136, integer:1; 137, integer:2; 138, conditional_expression:if; 138, 139; 138, 140; 138, 152; 139, string:' (undetermined)'; 140, comparison_operator:<; 140, 141; 140, 146; 141, subscript; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:cij; 144, integer:1; 145, integer:2; 146, call; 146, 147; 146, 148; 147, identifier:len; 148, argument_list; 148, 149; 149, subscript; 149, 150; 149, 151; 150, identifier:cij; 151, integer:0; 152, string:''; 153, if_statement; 153, 154; 153, 166; 154, comparison_operator:==; 154, 155; 154, 160; 155, subscript; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:cij; 158, integer:1; 159, integer:2; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, subscript; 163, 164; 163, 165; 164, identifier:cij; 165, integer:0; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 170; 169, identifier:echo; 170, argument_list; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, string:' Square of residuals: {:7.2g}'; 174, identifier:format; 175, argument_list; 175, 176; 176, subscript; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:cij; 179, integer:1; 180, integer:1; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 184; 183, identifier:echo; 184, argument_list; 184, 185; 185, string:' Relative singular values:'; 186, for_statement; 186, 187; 186, 188; 186, 195; 187, identifier:sv; 188, binary_operator:/; 188, 189; 188, 194; 189, subscript; 189, 190; 189, 193; 190, subscript; 190, 191; 190, 192; 191, identifier:cij; 192, integer:1; 193, integer:3; 194, identifier:msv; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 199; 198, identifier:echo; 199, argument_list; 199, 200; 199, 213; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, string:'{:7.4f}{}'; 203, identifier:format; 204, argument_list; 204, 205; 204, 206; 205, identifier:sv; 206, conditional_expression:if; 206, 207; 206, 208; 206, 212; 207, string:'* '; 208, comparison_operator:<; 208, 209; 208, 211; 209, parenthesized_expression; 209, 210; 210, identifier:sv; 211, identifier:eps; 212, string:' '; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:nl; 215, False; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 219; 218, identifier:echo; 219, argument_list; 219, 220; 220, string:'\n\nElastic tensor (GPa):'; 221, for_statement; 221, 222; 221, 223; 221, 233; 222, identifier:dsc; 223, call; 223, 224; 223, 229; 224, attribute; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:elastic; 227, identifier:elastic; 228, identifier:get_cij_order; 229, argument_list; 229, 230; 230, subscript; 230, 231; 230, 232; 231, identifier:systems; 232, integer:0; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 237; 236, identifier:echo; 237, argument_list; 237, 238; 237, 244; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, string:'{: >7s} '; 241, identifier:format; 242, argument_list; 242, 243; 243, identifier:dsc; 244, keyword_argument; 244, 245; 244, 246; 245, identifier:nl; 246, False; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 250; 249, identifier:echo; 250, argument_list; 250, 251; 251, binary_operator:+; 251, 252; 251, 253; 252, string:'\n'; 253, binary_operator:*; 253, 254; 253, 255; 254, integer:30; 255, string:'-'; 256, for_statement; 256, 257; 256, 260; 256, 273; 257, pattern_list; 257, 258; 257, 259; 258, identifier:c; 259, identifier:sv; 260, call; 260, 261; 260, 262; 261, identifier:zip; 262, argument_list; 262, 263; 262, 266; 263, subscript; 263, 264; 263, 265; 264, identifier:cij; 265, integer:0; 266, binary_operator:/; 266, 267; 266, 272; 267, subscript; 267, 268; 267, 271; 268, subscript; 268, 269; 268, 270; 269, identifier:cij; 270, integer:1; 271, integer:3; 272, identifier:msv; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 277; 276, identifier:echo; 277, argument_list; 277, 278; 277, 296; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, string:'{:7.2f}{}'; 281, identifier:format; 282, argument_list; 282, 283; 282, 290; 283, binary_operator:/; 283, 284; 283, 285; 284, identifier:c; 285, attribute; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:ase; 288, identifier:units; 289, identifier:GPa; 290, conditional_expression:if; 290, 291; 290, 292; 290, 295; 291, string:'* '; 292, comparison_operator:<; 292, 293; 292, 294; 293, identifier:sv; 294, identifier:eps; 295, string:' '; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:nl; 298, False; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 302; 301, identifier:echo; 302, argument_list; 303, comparison_operator:==; 303, 304; 303, 305; 304, identifier:action; 305, string:'eos'; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:eos; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:elastic; 312, identifier:get_BM_EOS; 313, argument_list; 313, 314; 313, 317; 314, subscript; 314, 315; 314, 316; 315, identifier:systems; 316, integer:0; 317, keyword_argument; 317, 318; 317, 319; 318, identifier:systems; 319, subscript; 319, 320; 319, 321; 320, identifier:systems; 321, slice; 321, 322; 321, 323; 322, integer:1; 323, colon; 324, expression_statement; 324, 325; 325, augmented_assignment:/=; 325, 326; 325, 329; 326, subscript; 326, 327; 326, 328; 327, identifier:eos; 328, integer:1; 329, attribute; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:ase; 332, identifier:units; 333, identifier:GPa; 334, identifier:verbose; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 338; 337, identifier:echo; 338, argument_list; 338, 339; 339, binary_operator:%; 339, 340; 339, 347; 339, 349; 339, 351; 340, binary_operator:%; 340, 341; 340, 344; 340, 346; 341, binary_operator:%; 341, 342; 341, 343; 342, string:'
echo('; 343, float:7.2; 344, ERROR; 344, 345; 345, identifier:f; 346, float:7.2; 347, ERROR; 347, 348; 348, identifier:f; 349, ERROR; 349, 350; 350, float:7.2; 351, call; 351, 352; 351, 353; 352, identifier:tuple; 353, argument_list; 353, 354; 354, identifier:eos | def proc(ctx, files):
'''Process calculated structures'''
def calc_reader(fn, verb):
if verb:
echo('Reading: {:<60s}\r'.format(fn), nl=False, err=True)
return ase.io.read(fn)
action = ctx.parent.params['action']
systems = [calc_reader(calc, verbose) for calc in files]
if verbose :
echo('', err=True)
if action == 'cij':
cij = elastic.get_elastic_tensor(systems[0], systems=systems[1:])
msv = cij[1][3].max()
eps = 1e-4
if verbose:
echo('Cij solution\n'+30*'-')
echo(' Solution rank: {:2d}{}'.format(
cij[1][2],
' (undetermined)' if cij[1][2] < len(cij[0]) else ''))
if cij[1][2] == len(cij[0]):
echo(' Square of residuals: {:7.2g}'.format(cij[1][1]))
echo(' Relative singular values:')
for sv in cij[1][3]/msv:
echo('{:7.4f}{}'.format(
sv, '* ' if (sv) < eps else ' '), nl=False)
echo('\n\nElastic tensor (GPa):')
for dsc in elastic.elastic.get_cij_order(systems[0]):
echo('{: >7s} '.format(dsc), nl=False)
echo('\n'+30*'-')
for c, sv in zip(cij[0], cij[1][3]/msv):
echo('{:7.2f}{}'.format(
c/ase.units.GPa, '* ' if sv < eps else ' '), nl=False)
echo()
elif action == 'eos':
eos = elastic.get_BM_EOS(systems[0], systems=systems[1:])
eos[1] /= ase.units.GPa
if verbose:
echo('
echo(' %7.2f %7.2f %7.2f' % tuple(eos)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:sample; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:bqm; 6, default_parameter; 6, 7; 6, 8; 7, identifier:init_solution; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:tenure; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:scale_factor; 14, integer:1; 15, default_parameter; 15, 16; 15, 17; 16, identifier:timeout; 17, integer:20; 18, default_parameter; 18, 19; 18, 20; 19, identifier:num_reads; 20, integer:1; 21, block; 21, 22; 21, 113; 21, 134; 21, 156; 21, 169; 21, 184; 21, 197; 21, 207; 21, 218; 21, 222; 21, 226; 21, 312; 21, 331; 21, 343; 22, if_statement; 22, 23; 22, 26; 22, 107; 23, comparison_operator:is; 23, 24; 23, 25; 24, identifier:init_solution; 25, None; 26, block; 26, 27; 26, 42; 26, 57; 26, 79; 27, if_statement; 27, 28; 27, 36; 28, not_operator; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 33; 32, identifier:init_solution; 33, attribute; 33, 34; 33, 35; 34, identifier:dimod; 35, identifier:SampleSet; 36, block; 36, 37; 37, raise_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:TypeError; 40, argument_list; 40, 41; 41, string:"'init_solution' should be a 'dimod.SampleSet' instance"; 42, if_statement; 42, 43; 42, 51; 43, comparison_operator:<; 43, 44; 43, 50; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:init_solution; 49, identifier:record; 50, integer:1; 51, block; 51, 52; 52, raise_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:ValueError; 55, argument_list; 55, 56; 56, string:"'init_solution' should contain at least one sample"; 57, if_statement; 57, 58; 57, 73; 58, comparison_operator:!=; 58, 59; 58, 69; 59, call; 59, 60; 59, 61; 60, identifier:len; 61, argument_list; 61, 62; 62, attribute; 62, 63; 62, 68; 63, subscript; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:init_solution; 66, identifier:record; 67, integer:0; 68, identifier:sample; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, identifier:bqm; 73, block; 73, 74; 74, raise_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:ValueError; 77, argument_list; 77, 78; 78, string:"'init_solution' sample dimension different from BQM"; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:init_sample; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:_bqm_sample_to_tabu_sample; 86, argument_list; 86, 87; 86, 104; 87, attribute; 87, 88; 87, 103; 88, subscript; 88, 89; 88, 102; 89, attribute; 89, 90; 89, 101; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:init_solution; 93, identifier:change_vartype; 94, argument_list; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:dimod; 97, identifier:BINARY; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:inplace; 100, False; 101, identifier:record; 102, integer:0; 103, identifier:sample; 104, attribute; 104, 105; 104, 106; 105, identifier:bqm; 106, identifier:binary; 107, else_clause; 107, 108; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:init_sample; 112, None; 113, if_statement; 113, 114; 113, 116; 114, not_operator; 114, 115; 115, identifier:bqm; 116, block; 116, 117; 117, return_statement; 117, 118; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:dimod; 122, identifier:SampleSet; 123, identifier:from_samples; 124, argument_list; 124, 125; 124, 126; 124, 129; 125, list:[]; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:energy; 128, integer:0; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:vartype; 131, attribute; 131, 132; 131, 133; 132, identifier:bqm; 133, identifier:vartype; 134, if_statement; 134, 135; 134, 138; 135, comparison_operator:is; 135, 136; 135, 137; 136, identifier:tenure; 137, None; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:tenure; 142, call; 142, 143; 142, 144; 143, identifier:max; 144, argument_list; 144, 145; 144, 155; 145, call; 145, 146; 145, 147; 146, identifier:min; 147, argument_list; 147, 148; 147, 149; 148, integer:20; 149, binary_operator://; 149, 150; 149, 154; 150, call; 150, 151; 150, 152; 151, identifier:len; 152, argument_list; 152, 153; 153, identifier:bqm; 154, integer:4; 155, integer:0; 156, if_statement; 156, 157; 156, 163; 157, not_operator; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:isinstance; 160, argument_list; 160, 161; 160, 162; 161, identifier:tenure; 162, identifier:int; 163, block; 163, 164; 164, raise_statement; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:TypeError; 167, argument_list; 167, 168; 168, string:"'tenure' should be an integer in range [0, num_vars - 1]"; 169, if_statement; 169, 170; 169, 178; 170, not_operator; 170, 171; 171, comparison_operator:<=; 171, 172; 171, 173; 171, 174; 172, integer:0; 173, identifier:tenure; 174, call; 174, 175; 174, 176; 175, identifier:len; 176, argument_list; 176, 177; 177, identifier:bqm; 178, block; 178, 179; 179, raise_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:ValueError; 182, argument_list; 182, 183; 183, string:"'tenure' should be an integer in range [0, num_vars - 1]"; 184, if_statement; 184, 185; 184, 191; 185, not_operator; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:isinstance; 188, argument_list; 188, 189; 188, 190; 189, identifier:num_reads; 190, identifier:int; 191, block; 191, 192; 192, raise_statement; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:TypeError; 195, argument_list; 195, 196; 196, string:"'num_reads' should be a positive integer"; 197, if_statement; 197, 198; 197, 201; 198, comparison_operator:<; 198, 199; 198, 200; 199, identifier:num_reads; 200, integer:1; 201, block; 201, 202; 202, raise_statement; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:ValueError; 205, argument_list; 205, 206; 206, string:"'num_reads' should be a positive integer"; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:qubo; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:_bqm_to_tabu_qubo; 214, argument_list; 214, 215; 215, attribute; 215, 216; 215, 217; 216, identifier:bqm; 217, identifier:binary; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:samples; 221, list:[]; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:energies; 225, list:[]; 226, for_statement; 226, 227; 226, 228; 226, 232; 227, identifier:_; 228, call; 228, 229; 228, 230; 229, identifier:range; 230, argument_list; 230, 231; 231, identifier:num_reads; 232, block; 232, 233; 232, 257; 232, 268; 232, 287; 232, 298; 232, 305; 233, if_statement; 233, 234; 233, 237; 234, comparison_operator:is; 234, 235; 234, 236; 235, identifier:init_sample; 236, None; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:init_sample; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:_bqm_sample_to_tabu_sample; 245, argument_list; 245, 246; 245, 254; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:self; 249, identifier:_random_sample; 250, argument_list; 250, 251; 251, attribute; 251, 252; 251, 253; 252, identifier:bqm; 253, identifier:binary; 254, attribute; 254, 255; 254, 256; 255, identifier:bqm; 256, identifier:binary; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:r; 260, call; 260, 261; 260, 262; 261, identifier:TabuSearch; 262, argument_list; 262, 263; 262, 264; 262, 265; 262, 266; 262, 267; 263, identifier:qubo; 264, identifier:init_sample; 265, identifier:tenure; 266, identifier:scale_factor; 267, identifier:timeout; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:sample; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:_tabu_sample_to_bqm_sample; 275, argument_list; 275, 276; 275, 284; 276, call; 276, 277; 276, 278; 277, identifier:list; 278, argument_list; 278, 279; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:r; 282, identifier:bestSolution; 283, argument_list; 284, attribute; 284, 285; 284, 286; 285, identifier:bqm; 286, identifier:binary; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:energy; 290, call; 290, 291; 290, 296; 291, attribute; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:bqm; 294, identifier:binary; 295, identifier:energy; 296, argument_list; 296, 297; 297, identifier:sample; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:samples; 302, identifier:append; 303, argument_list; 303, 304; 304, identifier:sample; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:energies; 309, identifier:append; 310, argument_list; 310, 311; 311, identifier:energy; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:response; 315, call; 315, 316; 315, 321; 316, attribute; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:dimod; 319, identifier:SampleSet; 320, identifier:from_samples; 321, argument_list; 321, 322; 321, 323; 321, 326; 322, identifier:samples; 323, keyword_argument; 323, 324; 323, 325; 324, identifier:energy; 325, identifier:energies; 326, keyword_argument; 326, 327; 326, 328; 327, identifier:vartype; 328, attribute; 328, 329; 328, 330; 329, identifier:dimod; 330, identifier:BINARY; 331, expression_statement; 331, 332; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:response; 335, identifier:change_vartype; 336, argument_list; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:bqm; 339, identifier:vartype; 340, keyword_argument; 340, 341; 340, 342; 341, identifier:inplace; 342, True; 343, return_statement; 343, 344; 344, identifier:response | def sample(self, bqm, init_solution=None, tenure=None, scale_factor=1, timeout=20, num_reads=1):
if init_solution is not None:
if not isinstance(init_solution, dimod.SampleSet):
raise TypeError("'init_solution' should be a 'dimod.SampleSet' instance")
if len(init_solution.record) < 1:
raise ValueError("'init_solution' should contain at least one sample")
if len(init_solution.record[0].sample) != len(bqm):
raise ValueError("'init_solution' sample dimension different from BQM")
init_sample = self._bqm_sample_to_tabu_sample(
init_solution.change_vartype(dimod.BINARY, inplace=False).record[0].sample, bqm.binary)
else:
init_sample = None
if not bqm:
return dimod.SampleSet.from_samples([], energy=0, vartype=bqm.vartype)
if tenure is None:
tenure = max(min(20, len(bqm) // 4), 0)
if not isinstance(tenure, int):
raise TypeError("'tenure' should be an integer in range [0, num_vars - 1]")
if not 0 <= tenure < len(bqm):
raise ValueError("'tenure' should be an integer in range [0, num_vars - 1]")
if not isinstance(num_reads, int):
raise TypeError("'num_reads' should be a positive integer")
if num_reads < 1:
raise ValueError("'num_reads' should be a positive integer")
qubo = self._bqm_to_tabu_qubo(bqm.binary)
samples = []
energies = []
for _ in range(num_reads):
if init_sample is None:
init_sample = self._bqm_sample_to_tabu_sample(self._random_sample(bqm.binary), bqm.binary)
r = TabuSearch(qubo, init_sample, tenure, scale_factor, timeout)
sample = self._tabu_sample_to_bqm_sample(list(r.bestSolution()), bqm.binary)
energy = bqm.binary.energy(sample)
samples.append(sample)
energies.append(energy)
response = dimod.SampleSet.from_samples(
samples, energy=energies, vartype=dimod.BINARY)
response.change_vartype(bqm.vartype, inplace=True)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:mmi_to_raster; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:force_flag; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:algorithm; 10, identifier:USE_ASCII; 11, block; 11, 12; 11, 19; 11, 28; 11, 73; 11, 89; 11, 247; 11, 254; 11, 299; 11, 307; 11, 315; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:LOGGER; 16, identifier:debug; 17, argument_list; 17, 18; 18, string:'mmi_to_raster requested.'; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:algorithm; 22, None; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:algorithm; 27, identifier:USE_ASCII; 28, if_statement; 28, 29; 28, 32; 28, 53; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:algorithm_name; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:tif_path; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:os; 40, identifier:path; 41, identifier:join; 42, argument_list; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:output_dir; 46, binary_operator:%; 46, 47; 46, 48; 47, string:'%s-%s.tif'; 48, tuple; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:output_basename; 52, identifier:algorithm; 53, else_clause; 53, 54; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:tif_path; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:os; 62, identifier:path; 63, identifier:join; 64, argument_list; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:output_dir; 68, binary_operator:%; 68, 69; 68, 70; 69, string:'%s.tif'; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:output_basename; 73, if_statement; 73, 74; 73, 86; 74, boolean_operator:and; 74, 75; 74, 83; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:os; 79, identifier:path; 80, identifier:exists; 81, argument_list; 81, 82; 82, identifier:tif_path; 83, comparison_operator:is; 83, 84; 83, 85; 84, identifier:force_flag; 85, True; 86, block; 86, 87; 87, return_statement; 87, 88; 88, identifier:tif_path; 89, if_statement; 89, 90; 89, 93; 89, 143; 90, comparison_operator:==; 90, 91; 90, 92; 91, identifier:algorithm; 92, identifier:USE_ASCII; 93, block; 93, 94; 93, 103; 93, 127; 93, 136; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:ascii_path; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:mmi_to_ascii; 101, argument_list; 101, 102; 102, True; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:command; 106, parenthesized_expression; 106, 107; 107, binary_operator:%; 107, 108; 107, 112; 108, parenthesized_expression; 108, 109; 109, concatenated_string; 109, 110; 109, 111; 110, string:'%(gdal_translate)s -a_srs EPSG:4326 '; 111, string:'"%(ascii)s" "%(tif)s"'; 112, dictionary; 112, 113; 112, 121; 112, 124; 113, pair; 113, 114; 113, 115; 114, string:'gdal_translate'; 115, subscript; 115, 116; 115, 120; 116, call; 116, 117; 116, 118; 117, identifier:which; 118, argument_list; 118, 119; 119, string:'gdal_translate'; 120, integer:0; 121, pair; 121, 122; 121, 123; 122, string:'ascii'; 123, identifier:ascii_path; 124, pair; 124, 125; 124, 126; 125, string:'tif'; 126, identifier:tif_path; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:LOGGER; 131, identifier:info; 132, argument_list; 132, 133; 133, binary_operator:%; 133, 134; 133, 135; 134, string:'Created this gdal command:\n%s'; 135, identifier:command; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:_run_command; 141, argument_list; 141, 142; 142, identifier:command; 143, else_clause; 143, 144; 144, block; 144, 145; 144, 154; 144, 163; 144, 222; 144, 231; 144, 238; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:vrt_path; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:mmi_to_vrt; 152, argument_list; 152, 153; 153, identifier:force_flag; 154, if_statement; 154, 155; 154, 158; 155, comparison_operator:in; 155, 156; 155, 157; 156, identifier:INVDIST; 157, identifier:algorithm; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:algorithm; 162, string:'invdist:power=2.0:smoothing=1.0'; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:command; 166, parenthesized_expression; 166, 167; 167, binary_operator:%; 167, 168; 167, 174; 168, parenthesized_expression; 168, 169; 169, concatenated_string; 169, 170; 169, 171; 169, 172; 169, 173; 170, string:'%(gdal_grid)s -a %(alg)s -zfield "mmi" -txe %(xMin)s '; 171, string:'%(xMax)s -tye %(yMin)s %(yMax)s -outsize %(dimX)i '; 172, string:'%(dimY)i -of GTiff -ot Float16 -a_srs EPSG:4326 -l mmi '; 173, string:'"%(vrt)s" "%(tif)s"'; 174, dictionary; 174, 175; 174, 183; 174, 186; 174, 191; 174, 196; 174, 201; 174, 206; 174, 211; 174, 216; 174, 219; 175, pair; 175, 176; 175, 177; 176, string:'gdal_grid'; 177, subscript; 177, 178; 177, 182; 178, call; 178, 179; 178, 180; 179, identifier:which; 180, argument_list; 180, 181; 181, string:'gdal_grid'; 182, integer:0; 183, pair; 183, 184; 183, 185; 184, string:'alg'; 185, identifier:algorithm; 186, pair; 186, 187; 186, 188; 187, string:'xMin'; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:x_minimum; 191, pair; 191, 192; 191, 193; 192, string:'xMax'; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:x_maximum; 196, pair; 196, 197; 196, 198; 197, string:'yMin'; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:y_minimum; 201, pair; 201, 202; 201, 203; 202, string:'yMax'; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:y_maximum; 206, pair; 206, 207; 206, 208; 207, string:'dimX'; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:columns; 211, pair; 211, 212; 211, 213; 212, string:'dimY'; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:rows; 216, pair; 216, 217; 216, 218; 217, string:'vrt'; 218, identifier:vrt_path; 219, pair; 219, 220; 219, 221; 220, string:'tif'; 221, identifier:tif_path; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:LOGGER; 226, identifier:info; 227, argument_list; 227, 228; 228, binary_operator:%; 228, 229; 228, 230; 229, string:'Created this gdal command:\n%s'; 230, identifier:command; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:_run_command; 236, argument_list; 236, 237; 237, identifier:command; 238, if_statement; 238, 239; 238, 242; 239, comparison_operator:in; 239, 240; 239, 241; 240, identifier:INVDIST; 241, identifier:algorithm; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:algorithm; 246, string:'invdist'; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:create_keyword_file; 252, argument_list; 252, 253; 253, identifier:algorithm; 254, if_statement; 254, 255; 254, 258; 254, 279; 255, attribute; 255, 256; 255, 257; 256, identifier:self; 257, identifier:algorithm_name; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:qml_path; 262, call; 262, 263; 262, 268; 263, attribute; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:os; 266, identifier:path; 267, identifier:join; 268, argument_list; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:output_dir; 272, binary_operator:%; 272, 273; 272, 274; 273, string:'%s-%s.qml'; 274, tuple; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:output_basename; 278, identifier:algorithm; 279, else_clause; 279, 280; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:qml_path; 284, call; 284, 285; 284, 290; 285, attribute; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:os; 288, identifier:path; 289, identifier:join; 290, argument_list; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:self; 293, identifier:output_dir; 294, binary_operator:%; 294, 295; 294, 296; 295, string:'%s.qml'; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:output_basename; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:qml_source_path; 302, call; 302, 303; 302, 304; 303, identifier:resources_path; 304, argument_list; 304, 305; 304, 306; 305, string:'converter_data'; 306, string:'mmi.qml'; 307, expression_statement; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:shutil; 311, identifier:copyfile; 312, argument_list; 312, 313; 312, 314; 313, identifier:qml_source_path; 314, identifier:qml_path; 315, return_statement; 315, 316; 316, identifier:tif_path | def mmi_to_raster(self, force_flag=False, algorithm=USE_ASCII):
LOGGER.debug('mmi_to_raster requested.')
if algorithm is None:
algorithm = USE_ASCII
if self.algorithm_name:
tif_path = os.path.join(
self.output_dir, '%s-%s.tif' % (
self.output_basename, algorithm))
else:
tif_path = os.path.join(
self.output_dir, '%s.tif' % self.output_basename)
if os.path.exists(tif_path) and force_flag is not True:
return tif_path
if algorithm == USE_ASCII:
ascii_path = self.mmi_to_ascii(True)
command = (
(
'%(gdal_translate)s -a_srs EPSG:4326 '
'"%(ascii)s" "%(tif)s"'
) % {
'gdal_translate': which('gdal_translate')[0],
'ascii': ascii_path,
'tif': tif_path
}
)
LOGGER.info('Created this gdal command:\n%s' % command)
self._run_command(command)
else:
vrt_path = self.mmi_to_vrt(force_flag)
if INVDIST in algorithm:
algorithm = 'invdist:power=2.0:smoothing=1.0'
command = (
(
'%(gdal_grid)s -a %(alg)s -zfield "mmi" -txe %(xMin)s '
'%(xMax)s -tye %(yMin)s %(yMax)s -outsize %(dimX)i '
'%(dimY)i -of GTiff -ot Float16 -a_srs EPSG:4326 -l mmi '
'"%(vrt)s" "%(tif)s"'
) % {
'gdal_grid': which('gdal_grid')[0],
'alg': algorithm,
'xMin': self.x_minimum,
'xMax': self.x_maximum,
'yMin': self.y_minimum,
'yMax': self.y_maximum,
'dimX': self.columns,
'dimY': self.rows,
'vrt': vrt_path,
'tif': tif_path
}
)
LOGGER.info('Created this gdal command:\n%s' % command)
self._run_command(command)
if INVDIST in algorithm:
algorithm = 'invdist'
self.create_keyword_file(algorithm)
if self.algorithm_name:
qml_path = os.path.join(
self.output_dir, '%s-%s.qml' % (
self.output_basename, algorithm))
else:
qml_path = os.path.join(
self.output_dir, '%s.qml' % self.output_basename)
qml_source_path = resources_path('converter_data', 'mmi.qml')
shutil.copyfile(qml_source_path, qml_path)
return tif_path |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:create_keyword_file; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:algorithm; 6, block; 6, 7; 6, 13; 6, 20; 6, 35; 6, 42; 6, 57; 6, 61; 6, 90; 6, 190; 6, 211; 6, 215; 6, 240; 6, 251; 6, 302; 6, 347; 6, 375; 6, 381; 6, 389; 6, 401; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:keyword_io; 10, call; 10, 11; 10, 12; 11, identifier:KeywordIO; 12, argument_list; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:mmi_default_classes; 16, call; 16, 17; 16, 18; 17, identifier:default_classification_thresholds; 18, argument_list; 18, 19; 19, identifier:earthquake_mmi_scale; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:mmi_default_threshold; 23, dictionary; 23, 24; 24, pair; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:earthquake_mmi_scale; 27, string:'key'; 28, dictionary; 28, 29; 28, 32; 29, pair; 29, 30; 29, 31; 30, string:'active'; 31, True; 32, pair; 32, 33; 32, 34; 33, string:'classes'; 34, identifier:mmi_default_classes; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:generic_default_classes; 38, call; 38, 39; 38, 40; 39, identifier:default_classification_thresholds; 40, argument_list; 40, 41; 41, identifier:generic_hazard_classes; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:generic_default_threshold; 45, dictionary; 45, 46; 46, pair; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:generic_hazard_classes; 49, string:'key'; 50, dictionary; 50, 51; 50, 54; 51, pair; 51, 52; 51, 53; 52, string:'active'; 53, True; 54, pair; 54, 55; 54, 56; 55, string:'classes'; 56, identifier:generic_default_classes; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:threshold_keyword; 60, dictionary; 61, for_statement; 61, 62; 61, 63; 61, 64; 62, identifier:exposure; 63, identifier:exposure_all; 64, block; 64, 65; 65, if_statement; 65, 66; 65, 71; 65, 80; 66, comparison_operator:in; 66, 67; 66, 68; 67, identifier:exposure; 68, subscript; 68, 69; 68, 70; 69, identifier:earthquake_mmi_scale; 70, string:'exposures'; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 79; 74, subscript; 74, 75; 74, 76; 75, identifier:threshold_keyword; 76, subscript; 76, 77; 76, 78; 77, identifier:exposure; 78, string:'key'; 79, identifier:mmi_default_threshold; 80, else_clause; 80, 81; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 86; 85, identifier:threshold_keyword; 86, subscript; 86, 87; 86, 88; 87, identifier:exposure; 88, string:'key'; 89, identifier:generic_default_threshold; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:extra_keywords; 93, dictionary; 93, 94; 93, 101; 93, 108; 93, 115; 93, 122; 93, 129; 93, 136; 93, 148; 93, 155; 93, 162; 93, 169; 93, 176; 93, 183; 94, pair; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:extra_keyword_earthquake_latitude; 97, string:'key'; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:latitude; 101, pair; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:extra_keyword_earthquake_longitude; 104, string:'key'; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:longitude; 108, pair; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:extra_keyword_earthquake_magnitude; 111, string:'key'; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:magnitude; 115, pair; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:extra_keyword_earthquake_depth; 118, string:'key'; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:depth; 122, pair; 122, 123; 122, 126; 123, subscript; 123, 124; 123, 125; 124, identifier:extra_keyword_earthquake_description; 125, string:'key'; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:description; 129, pair; 129, 130; 129, 133; 130, subscript; 130, 131; 130, 132; 131, identifier:extra_keyword_earthquake_location; 132, string:'key'; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:location; 136, pair; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:extra_keyword_earthquake_event_time; 139, string:'key'; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:time; 145, identifier:strftime; 146, argument_list; 146, 147; 147, string:'%Y-%m-%dT%H:%M:%S'; 148, pair; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:extra_keyword_time_zone; 151, string:'key'; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:time_zone; 155, pair; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:extra_keyword_earthquake_x_minimum; 158, string:'key'; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:x_minimum; 162, pair; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:extra_keyword_earthquake_x_maximum; 165, string:'key'; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:x_maximum; 169, pair; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:extra_keyword_earthquake_y_minimum; 172, string:'key'; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:y_minimum; 176, pair; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:extra_keyword_earthquake_y_maximum; 179, string:'key'; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:y_maximum; 183, pair; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:extra_keyword_earthquake_event_id; 186, string:'key'; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:event_id; 190, for_statement; 190, 191; 190, 194; 190, 204; 191, pattern_list; 191, 192; 191, 193; 192, identifier:key; 193, identifier:value; 194, call; 194, 195; 194, 196; 195, identifier:list; 196, argument_list; 196, 197; 197, call; 197, 198; 197, 203; 198, attribute; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:extra_keywords; 202, identifier:items; 203, argument_list; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 210; 207, subscript; 207, 208; 207, 209; 208, identifier:extra_keywords; 209, identifier:key; 210, identifier:value; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:empty_keys; 214, list:[]; 215, for_statement; 215, 216; 215, 219; 215, 227; 216, pattern_list; 216, 217; 216, 218; 217, identifier:key; 218, identifier:value; 219, call; 219, 220; 219, 221; 220, identifier:list; 221, argument_list; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:extra_keywords; 225, identifier:items; 226, argument_list; 227, block; 227, 228; 228, if_statement; 228, 229; 228, 232; 229, comparison_operator:is; 229, 230; 229, 231; 230, identifier:value; 231, None; 232, block; 232, 233; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:empty_keys; 237, identifier:append; 238, argument_list; 238, 239; 239, identifier:key; 240, for_statement; 240, 241; 240, 242; 240, 243; 241, identifier:empty_key; 242, identifier:empty_keys; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:extra_keywords; 248, identifier:pop; 249, argument_list; 249, 250; 250, identifier:empty_key; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:keywords; 254, dictionary; 254, 255; 254, 260; 254, 265; 254, 268; 254, 273; 254, 278; 254, 283; 254, 288; 254, 293; 254, 296; 254, 299; 255, pair; 255, 256; 255, 257; 256, string:'hazard'; 257, subscript; 257, 258; 257, 259; 258, identifier:hazard_earthquake; 259, string:'key'; 260, pair; 260, 261; 260, 262; 261, string:'hazard_category'; 262, subscript; 262, 263; 262, 264; 263, identifier:hazard_category_single_event; 264, string:'key'; 265, pair; 265, 266; 265, 267; 266, string:'keyword_version'; 267, identifier:inasafe_keyword_version; 268, pair; 268, 269; 268, 270; 269, string:'layer_geometry'; 270, subscript; 270, 271; 270, 272; 271, identifier:layer_geometry_raster; 272, string:'key'; 273, pair; 273, 274; 273, 275; 274, string:'layer_mode'; 275, subscript; 275, 276; 275, 277; 276, identifier:layer_mode_continuous; 277, string:'key'; 278, pair; 278, 279; 278, 280; 279, string:'layer_purpose'; 280, subscript; 280, 281; 280, 282; 281, identifier:layer_purpose_hazard; 282, string:'key'; 283, pair; 283, 284; 283, 285; 284, string:'continuous_hazard_unit'; 285, subscript; 285, 286; 285, 287; 286, identifier:unit_mmi; 287, string:'key'; 288, pair; 288, 289; 288, 290; 289, string:'classification'; 290, subscript; 290, 291; 290, 292; 291, identifier:earthquake_mmi_scale; 292, string:'key'; 293, pair; 293, 294; 293, 295; 294, string:'thresholds'; 295, identifier:threshold_keyword; 296, pair; 296, 297; 296, 298; 297, string:'extra_keywords'; 298, identifier:extra_keywords; 299, pair; 299, 300; 299, 301; 300, string:'active_band'; 301, integer:1; 302, if_statement; 302, 303; 302, 306; 302, 327; 303, attribute; 303, 304; 303, 305; 304, identifier:self; 305, identifier:algorithm_name; 306, block; 306, 307; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:layer_path; 310, call; 310, 311; 310, 316; 311, attribute; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:os; 314, identifier:path; 315, identifier:join; 316, argument_list; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:self; 319, identifier:output_dir; 320, binary_operator:%; 320, 321; 320, 322; 321, string:'%s-%s.tif'; 322, tuple; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:output_basename; 326, identifier:algorithm; 327, else_clause; 327, 328; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 332; 331, identifier:layer_path; 332, call; 332, 333; 332, 338; 333, attribute; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:os; 336, identifier:path; 337, identifier:join; 338, argument_list; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:self; 341, identifier:output_dir; 342, binary_operator:%; 342, 343; 342, 344; 343, string:'%s.tif'; 344, attribute; 344, 345; 344, 346; 345, identifier:self; 346, identifier:output_basename; 347, if_statement; 347, 348; 347, 360; 347, 367; 348, comparison_operator:==; 348, 349; 348, 359; 349, call; 349, 350; 349, 351; 350, identifier:len; 351, argument_list; 351, 352; 352, call; 352, 353; 352, 358; 353, attribute; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:self; 356, identifier:title; 357, identifier:strip; 358, argument_list; 359, integer:0; 360, block; 360, 361; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 364; 363, identifier:keyword_title; 364, attribute; 364, 365; 364, 366; 365, identifier:self; 366, identifier:output_basename; 367, else_clause; 367, 368; 368, block; 368, 369; 369, expression_statement; 369, 370; 370, assignment; 370, 371; 370, 372; 371, identifier:keyword_title; 372, attribute; 372, 373; 372, 374; 373, identifier:self; 374, identifier:title; 375, expression_statement; 375, 376; 376, assignment; 376, 377; 376, 380; 377, subscript; 377, 378; 377, 379; 378, identifier:keywords; 379, string:'title'; 380, identifier:keyword_title; 381, expression_statement; 381, 382; 382, assignment; 382, 383; 382, 384; 383, identifier:hazard_layer; 384, call; 384, 385; 384, 386; 385, identifier:QgsRasterLayer; 386, argument_list; 386, 387; 386, 388; 387, identifier:layer_path; 388, identifier:keyword_title; 389, if_statement; 389, 390; 389, 396; 390, not_operator; 390, 391; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:hazard_layer; 394, identifier:isValid; 395, argument_list; 396, block; 396, 397; 397, raise_statement; 397, 398; 398, call; 398, 399; 398, 400; 399, identifier:InvalidLayerError; 400, argument_list; 401, expression_statement; 401, 402; 402, call; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, identifier:keyword_io; 405, identifier:write_keywords; 406, argument_list; 406, 407; 406, 408; 407, identifier:hazard_layer; 408, identifier:keywords | def create_keyword_file(self, algorithm):
keyword_io = KeywordIO()
mmi_default_classes = default_classification_thresholds(
earthquake_mmi_scale
)
mmi_default_threshold = {
earthquake_mmi_scale['key']: {
'active': True,
'classes': mmi_default_classes
}
}
generic_default_classes = default_classification_thresholds(
generic_hazard_classes
)
generic_default_threshold = {
generic_hazard_classes['key']: {
'active': True,
'classes': generic_default_classes
}
}
threshold_keyword = {}
for exposure in exposure_all:
if exposure in earthquake_mmi_scale['exposures']:
threshold_keyword[exposure['key']] = mmi_default_threshold
else:
threshold_keyword[
exposure['key']] = generic_default_threshold
extra_keywords = {
extra_keyword_earthquake_latitude['key']: self.latitude,
extra_keyword_earthquake_longitude['key']: self.longitude,
extra_keyword_earthquake_magnitude['key']: self.magnitude,
extra_keyword_earthquake_depth['key']: self.depth,
extra_keyword_earthquake_description['key']: self.description,
extra_keyword_earthquake_location['key']: self.location,
extra_keyword_earthquake_event_time['key']: self.time.strftime(
'%Y-%m-%dT%H:%M:%S'),
extra_keyword_time_zone['key']: self.time_zone,
extra_keyword_earthquake_x_minimum['key']: self.x_minimum,
extra_keyword_earthquake_x_maximum['key']: self.x_maximum,
extra_keyword_earthquake_y_minimum['key']: self.y_minimum,
extra_keyword_earthquake_y_maximum['key']: self.y_maximum,
extra_keyword_earthquake_event_id['key']: self.event_id
}
for key, value in list(self.extra_keywords.items()):
extra_keywords[key] = value
empty_keys = []
for key, value in list(extra_keywords.items()):
if value is None:
empty_keys.append(key)
for empty_key in empty_keys:
extra_keywords.pop(empty_key)
keywords = {
'hazard': hazard_earthquake['key'],
'hazard_category': hazard_category_single_event['key'],
'keyword_version': inasafe_keyword_version,
'layer_geometry': layer_geometry_raster['key'],
'layer_mode': layer_mode_continuous['key'],
'layer_purpose': layer_purpose_hazard['key'],
'continuous_hazard_unit': unit_mmi['key'],
'classification': earthquake_mmi_scale['key'],
'thresholds': threshold_keyword,
'extra_keywords': extra_keywords,
'active_band': 1
}
if self.algorithm_name:
layer_path = os.path.join(
self.output_dir, '%s-%s.tif' % (
self.output_basename, algorithm))
else:
layer_path = os.path.join(
self.output_dir, '%s.tif' % self.output_basename)
if len(self.title.strip()) == 0:
keyword_title = self.output_basename
else:
keyword_title = self.title
keywords['title'] = keyword_title
hazard_layer = QgsRasterLayer(layer_path, keyword_title)
if not hazard_layer.isValid():
raise InvalidLayerError()
keyword_io.write_keywords(hazard_layer, keywords) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_check_value_mapping; 3, parameters; 3, 4; 3, 5; 4, identifier:layer; 5, default_parameter; 5, 6; 5, 7; 6, identifier:exposure_key; 7, None; 8, block; 8, 9; 8, 24; 8, 33; 8, 83; 8, 89; 8, 136; 8, 143; 8, 147; 8, 167; 8, 171; 8, 189; 8, 201; 8, 230; 8, 238; 8, 246; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:index; 12, call; 12, 13; 12, 20; 13, attribute; 13, 14; 13, 19; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:layer; 17, identifier:fields; 18, argument_list; 19, identifier:lookupField; 20, argument_list; 20, 21; 21, subscript; 21, 22; 21, 23; 22, identifier:exposure_type_field; 23, string:'field_name'; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:unique_exposure; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:layer; 30, identifier:uniqueValues; 31, argument_list; 31, 32; 32, identifier:index; 33, if_statement; 33, 34; 33, 43; 33, 70; 34, comparison_operator:==; 34, 35; 34, 40; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:layer; 38, identifier:keywords; 39, string:'layer_purpose'; 40, subscript; 40, 41; 40, 42; 41, identifier:layer_purpose_hazard; 42, string:'key'; 43, block; 43, 44; 43, 60; 44, if_statement; 44, 45; 44, 47; 45, not_operator; 45, 46; 46, identifier:exposure_key; 47, block; 47, 48; 47, 55; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:message; 51, call; 51, 52; 51, 53; 52, identifier:tr; 53, argument_list; 53, 54; 54, string:'Hazard value mapping missing exposure key.'; 55, raise_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:InvalidKeywordsForProcessingAlgorithm; 58, argument_list; 58, 59; 59, identifier:message; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:value_map; 63, call; 63, 64; 63, 65; 64, identifier:active_thresholds_value_maps; 65, argument_list; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:layer; 68, identifier:keywords; 69, identifier:exposure_key; 70, else_clause; 70, 71; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:value_map; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:layer; 79, identifier:keywords; 80, identifier:get; 81, argument_list; 81, 82; 82, string:'value_map'; 83, if_statement; 83, 84; 83, 86; 84, not_operator; 84, 85; 85, identifier:value_map; 86, block; 86, 87; 87, return_statement; 87, 88; 88, identifier:layer; 89, if_statement; 89, 90; 89, 99; 89, 126; 90, comparison_operator:==; 90, 91; 90, 96; 91, subscript; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:layer; 94, identifier:keywords; 95, string:'layer_purpose'; 96, subscript; 96, 97; 96, 98; 97, identifier:layer_purpose_hazard; 98, string:'key'; 99, block; 99, 100; 99, 116; 100, if_statement; 100, 101; 100, 103; 101, not_operator; 101, 102; 102, identifier:exposure_key; 103, block; 103, 104; 103, 111; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:message; 107, call; 107, 108; 107, 109; 108, identifier:tr; 109, argument_list; 109, 110; 110, string:'Hazard classification is missing exposure key.'; 111, raise_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:InvalidKeywordsForProcessingAlgorithm; 114, argument_list; 114, 115; 115, identifier:message; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:classification; 119, call; 119, 120; 119, 121; 120, identifier:active_classification; 121, argument_list; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:layer; 124, identifier:keywords; 125, identifier:exposure_key; 126, else_clause; 126, 127; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:classification; 131, subscript; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:layer; 134, identifier:keywords; 135, string:'classification'; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:exposure_classification; 139, call; 139, 140; 139, 141; 140, identifier:definition; 141, argument_list; 141, 142; 142, identifier:classification; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:other; 146, None; 147, if_statement; 147, 148; 147, 155; 148, comparison_operator:!=; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:exposure_classification; 151, string:'key'; 152, subscript; 152, 153; 152, 154; 153, identifier:data_driven_classes; 154, string:'key'; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:other; 159, subscript; 159, 160; 159, 166; 160, subscript; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:exposure_classification; 163, string:'classes'; 164, unary_operator:-; 164, 165; 165, integer:1; 166, string:'key'; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:exposure_mapped; 170, list:[]; 171, for_statement; 171, 172; 171, 173; 171, 181; 172, identifier:group; 173, call; 173, 174; 173, 175; 174, identifier:list; 175, argument_list; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:value_map; 179, identifier:values; 180, argument_list; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:exposure_mapped; 186, identifier:extend; 187, argument_list; 187, 188; 188, identifier:group; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:diff; 192, call; 192, 193; 192, 194; 193, identifier:list; 194, argument_list; 194, 195; 195, binary_operator:-; 195, 196; 195, 197; 196, identifier:unique_exposure; 197, call; 197, 198; 197, 199; 198, identifier:set; 199, argument_list; 199, 200; 200, identifier:exposure_mapped; 201, if_statement; 201, 202; 201, 212; 201, 222; 202, comparison_operator:in; 202, 203; 202, 204; 203, identifier:other; 204, call; 204, 205; 204, 206; 205, identifier:list; 206, argument_list; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:value_map; 210, identifier:keys; 211, argument_list; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 220; 215, attribute; 215, 216; 215, 219; 216, subscript; 216, 217; 216, 218; 217, identifier:value_map; 218, identifier:other; 219, identifier:extend; 220, argument_list; 220, 221; 221, identifier:diff; 222, else_clause; 222, 223; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:value_map; 228, identifier:other; 229, identifier:diff; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 237; 232, subscript; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:layer; 235, identifier:keywords; 236, string:'value_map'; 237, identifier:value_map; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 245; 240, subscript; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:layer; 243, identifier:keywords; 244, string:'classification'; 245, identifier:classification; 246, return_statement; 246, 247; 247, identifier:layer | def _check_value_mapping(layer, exposure_key=None):
index = layer.fields().lookupField(exposure_type_field['field_name'])
unique_exposure = layer.uniqueValues(index)
if layer.keywords['layer_purpose'] == layer_purpose_hazard['key']:
if not exposure_key:
message = tr('Hazard value mapping missing exposure key.')
raise InvalidKeywordsForProcessingAlgorithm(message)
value_map = active_thresholds_value_maps(layer.keywords, exposure_key)
else:
value_map = layer.keywords.get('value_map')
if not value_map:
return layer
if layer.keywords['layer_purpose'] == layer_purpose_hazard['key']:
if not exposure_key:
message = tr('Hazard classification is missing exposure key.')
raise InvalidKeywordsForProcessingAlgorithm(message)
classification = active_classification(layer.keywords, exposure_key)
else:
classification = layer.keywords['classification']
exposure_classification = definition(classification)
other = None
if exposure_classification['key'] != data_driven_classes['key']:
other = exposure_classification['classes'][-1]['key']
exposure_mapped = []
for group in list(value_map.values()):
exposure_mapped.extend(group)
diff = list(unique_exposure - set(exposure_mapped))
if other in list(value_map.keys()):
value_map[other].extend(diff)
else:
value_map[other] = diff
layer.keywords['value_map'] = value_map
layer.keywords['classification'] = classification
return layer |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:clean_inasafe_fields; 3, parameters; 3, 4; 4, identifier:layer; 5, block; 5, 6; 5, 10; 5, 86; 5, 110; 5, 124; 5, 128; 5, 180; 5, 191; 5, 195; 5, 238; 5, 244; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:fields; 9, list:[]; 10, if_statement; 10, 11; 10, 20; 10, 37; 10, 64; 11, comparison_operator:==; 11, 12; 11, 17; 12, subscript; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:layer; 15, identifier:keywords; 16, string:'layer_purpose'; 17, subscript; 17, 18; 17, 19; 18, identifier:layer_purpose_exposure; 19, string:'key'; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:fields; 24, call; 24, 25; 24, 26; 25, identifier:get_fields; 26, argument_list; 26, 27; 26, 32; 27, subscript; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:layer; 30, identifier:keywords; 31, string:'layer_purpose'; 32, subscript; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:layer; 35, identifier:keywords; 36, string:'exposure'; 37, elif_clause; 37, 38; 37, 47; 38, comparison_operator:==; 38, 39; 38, 44; 39, subscript; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:layer; 42, identifier:keywords; 43, string:'layer_purpose'; 44, subscript; 44, 45; 44, 46; 45, identifier:layer_purpose_hazard; 46, string:'key'; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:fields; 51, call; 51, 52; 51, 53; 52, identifier:get_fields; 53, argument_list; 53, 54; 53, 59; 54, subscript; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:layer; 57, identifier:keywords; 58, string:'layer_purpose'; 59, subscript; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:layer; 62, identifier:keywords; 63, string:'hazard'; 64, elif_clause; 64, 65; 64, 74; 65, comparison_operator:==; 65, 66; 65, 71; 66, subscript; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:layer; 69, identifier:keywords; 70, string:'layer_purpose'; 71, subscript; 71, 72; 71, 73; 72, identifier:layer_purpose_aggregation; 73, string:'key'; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:fields; 78, call; 78, 79; 78, 80; 79, identifier:get_fields; 80, argument_list; 80, 81; 81, subscript; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:layer; 84, identifier:keywords; 85, string:'layer_purpose'; 86, try_statement; 86, 87; 86, 106; 87, block; 87, 88; 88, if_statement; 88, 89; 88, 98; 89, subscript; 89, 90; 89, 95; 90, subscript; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:layer; 93, identifier:keywords; 94, string:'inasafe_fields'; 95, subscript; 95, 96; 95, 97; 96, identifier:displaced_field; 97, string:'key'; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:fields; 103, identifier:append; 104, argument_list; 104, 105; 105, identifier:displaced_field; 106, except_clause; 106, 107; 106, 108; 107, identifier:KeyError; 108, block; 108, 109; 109, pass_statement; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:expected_fields; 113, dictionary_comprehension; 113, 114; 113, 121; 114, pair; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:field; 117, string:'key'; 118, subscript; 118, 119; 118, 120; 119, identifier:field; 120, string:'field_name'; 121, for_in_clause; 121, 122; 121, 123; 122, identifier:field; 123, identifier:fields; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:new_keywords; 127, dictionary; 128, for_statement; 128, 129; 128, 132; 128, 147; 129, pattern_list; 129, 130; 129, 131; 130, identifier:key; 131, identifier:val; 132, call; 132, 133; 132, 134; 133, identifier:list; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 146; 136, attribute; 136, 137; 136, 145; 137, call; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:layer; 141, identifier:keywords; 142, identifier:get; 143, argument_list; 143, 144; 144, string:'inasafe_fields'; 145, identifier:items; 146, argument_list; 147, block; 147, 148; 148, if_statement; 148, 149; 148, 152; 149, comparison_operator:in; 149, 150; 149, 151; 150, identifier:key; 151, identifier:expected_fields; 152, block; 152, 153; 152, 165; 152, 172; 153, if_statement; 153, 154; 153, 159; 154, call; 154, 155; 154, 156; 155, identifier:isinstance; 156, argument_list; 156, 157; 156, 158; 157, identifier:val; 158, identifier:str; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:val; 163, list:[val]; 163, 164; 164, identifier:val; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:sum_fields; 168, argument_list; 168, 169; 168, 170; 168, 171; 169, identifier:layer; 170, identifier:key; 171, identifier:val; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 177; 174, subscript; 174, 175; 174, 176; 175, identifier:new_keywords; 176, identifier:key; 177, subscript; 177, 178; 177, 179; 178, identifier:expected_fields; 179, identifier:key; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 189; 182, attribute; 182, 183; 182, 188; 183, subscript; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:layer; 186, identifier:keywords; 187, string:'inasafe_fields'; 188, identifier:update; 189, argument_list; 189, 190; 190, identifier:new_keywords; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:to_remove; 194, list:[]; 195, for_statement; 195, 196; 195, 197; 195, 206; 196, identifier:field; 197, call; 197, 198; 197, 205; 198, attribute; 198, 199; 198, 204; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:layer; 202, identifier:fields; 203, argument_list; 204, identifier:toList; 205, argument_list; 206, block; 206, 207; 207, if_statement; 207, 208; 207, 226; 208, comparison_operator:not; 208, 209; 208, 214; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:field; 212, identifier:name; 213, argument_list; 214, call; 214, 215; 214, 216; 215, identifier:list; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 225; 218, attribute; 218, 219; 218, 224; 219, subscript; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:layer; 222, identifier:keywords; 223, string:'inasafe_fields'; 224, identifier:values; 225, argument_list; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:to_remove; 231, identifier:append; 232, argument_list; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:field; 236, identifier:name; 237, argument_list; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 241; 240, identifier:remove_fields; 241, argument_list; 241, 242; 241, 243; 242, identifier:layer; 243, identifier:to_remove; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:LOGGER; 248, identifier:debug; 249, argument_list; 249, 250; 250, binary_operator:%; 250, 251; 250, 252; 251, string:'Fields which have been removed from %s : %s'; 252, tuple; 252, 253; 252, 258; 253, subscript; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:layer; 256, identifier:keywords; 257, string:'layer_purpose'; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, string:' '; 261, identifier:join; 262, argument_list; 262, 263; 263, identifier:to_remove | def clean_inasafe_fields(layer):
fields = []
if layer.keywords['layer_purpose'] == layer_purpose_exposure['key']:
fields = get_fields(
layer.keywords['layer_purpose'], layer.keywords['exposure'])
elif layer.keywords['layer_purpose'] == layer_purpose_hazard['key']:
fields = get_fields(
layer.keywords['layer_purpose'], layer.keywords['hazard'])
elif layer.keywords['layer_purpose'] == layer_purpose_aggregation['key']:
fields = get_fields(
layer.keywords['layer_purpose'])
try:
if layer.keywords['inasafe_fields'][displaced_field['key']]:
fields.append(displaced_field)
except KeyError:
pass
expected_fields = {field['key']: field['field_name'] for field in fields}
new_keywords = {}
for key, val in list(layer.keywords.get('inasafe_fields').items()):
if key in expected_fields:
if isinstance(val, str):
val = [val]
sum_fields(layer, key, val)
new_keywords[key] = expected_fields[key]
layer.keywords['inasafe_fields'].update(new_keywords)
to_remove = []
for field in layer.fields().toList():
if field.name() not in list(layer.keywords['inasafe_fields'].values()):
to_remove.append(field.name())
remove_fields(layer, to_remove)
LOGGER.debug(
'Fields which have been removed from %s : %s'
% (layer.keywords['layer_purpose'], ' '.join(to_remove))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_size_is_needed; 3, parameters; 3, 4; 4, identifier:layer; 5, block; 5, 6; 5, 17; 5, 23; 5, 33; 5, 40; 5, 53; 5, 61; 5, 71; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:exposure; 9, call; 9, 10; 9, 15; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:layer; 13, identifier:keywords; 14, identifier:get; 15, argument_list; 15, 16; 16, string:'exposure'; 17, if_statement; 17, 18; 17, 20; 18, not_operator; 18, 19; 19, identifier:exposure; 20, block; 20, 21; 21, return_statement; 21, 22; 22, False; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:indivisible_exposure_keys; 26, list_comprehension; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:f; 29, string:'key'; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:f; 32, identifier:indivisible_exposure; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:in; 34, 35; 34, 36; 35, identifier:exposure; 36, identifier:indivisible_exposure_keys; 37, block; 37, 38; 38, return_statement; 38, 39; 39, False; 40, if_statement; 40, 41; 40, 50; 41, comparison_operator:==; 41, 42; 41, 47; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:layer; 45, identifier:geometryType; 46, argument_list; 47, attribute; 47, 48; 47, 49; 48, identifier:QgsWkbTypes; 49, identifier:PointGeometry; 50, block; 50, 51; 51, return_statement; 51, 52; 52, False; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:fields; 56, subscript; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:layer; 59, identifier:keywords; 60, string:'inasafe_fields'; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:absolute_field_keys; 64, list_comprehension; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:f; 67, string:'key'; 68, for_in_clause; 68, 69; 68, 70; 69, identifier:f; 70, identifier:count_fields; 71, for_statement; 71, 72; 71, 73; 71, 74; 71, 82; 72, identifier:field; 73, identifier:fields; 74, block; 74, 75; 75, if_statement; 75, 76; 75, 79; 76, comparison_operator:in; 76, 77; 76, 78; 77, identifier:field; 78, identifier:absolute_field_keys; 79, block; 79, 80; 80, return_statement; 80, 81; 81, True; 82, else_clause; 82, 83; 83, block; 83, 84; 84, return_statement; 84, 85; 85, False | def _size_is_needed(layer):
exposure = layer.keywords.get('exposure')
if not exposure:
return False
indivisible_exposure_keys = [f['key'] for f in indivisible_exposure]
if exposure in indivisible_exposure_keys:
return False
if layer.geometryType() == QgsWkbTypes.PointGeometry:
return False
fields = layer.keywords['inasafe_fields']
absolute_field_keys = [f['key'] for f in count_fields]
for field in fields:
if field in absolute_field_keys:
return True
else:
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_remove_features; 3, parameters; 3, 4; 4, identifier:layer; 5, block; 5, 6; 5, 14; 5, 25; 5, 33; 5, 41; 5, 52; 5, 65; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:layer_purpose; 9, subscript; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:layer; 12, identifier:keywords; 13, string:'layer_purpose'; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:layer_subcategory; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:layer; 21, identifier:keywords; 22, identifier:get; 23, argument_list; 23, 24; 24, identifier:layer_purpose; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:compulsory_field; 28, call; 28, 29; 28, 30; 29, identifier:get_compulsory_fields; 30, argument_list; 30, 31; 30, 32; 31, identifier:layer_purpose; 32, identifier:layer_subcategory; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:inasafe_fields; 36, subscript; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:layer; 39, identifier:keywords; 40, string:'inasafe_fields'; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:field_names; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:inasafe_fields; 47, identifier:get; 48, argument_list; 48, 49; 49, subscript; 49, 50; 49, 51; 50, identifier:compulsory_field; 51, string:'key'; 52, if_statement; 52, 53; 52, 59; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:field_names; 58, identifier:list; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:field_names; 63, list:[field_names]; 63, 64; 64, identifier:field_names; 65, for_statement; 65, 66; 65, 67; 65, 68; 66, identifier:field_name; 67, identifier:field_names; 68, block; 68, 69; 68, 88; 68, 101; 68, 107; 68, 120; 68, 126; 68, 130; 68, 291; 68, 297; 69, if_statement; 69, 70; 69, 72; 70, not_operator; 70, 71; 71, identifier:field_name; 72, block; 72, 73; 72, 83; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:message; 76, binary_operator:%; 76, 77; 76, 78; 77, string:'Keyword %s is missing from %s'; 78, tuple; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:compulsory_field; 81, string:'key'; 82, identifier:layer_purpose; 83, raise_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:InvalidKeywordsForProcessingAlgorithm; 86, argument_list; 86, 87; 87, identifier:message; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:index; 91, call; 91, 92; 91, 99; 92, attribute; 92, 93; 92, 98; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:layer; 96, identifier:fields; 97, argument_list; 98, identifier:lookupField; 99, argument_list; 99, 100; 100, identifier:field_name; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:request; 104, call; 104, 105; 104, 106; 105, identifier:QgsFeatureRequest; 106, argument_list; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:request; 111, identifier:setSubsetOfAttributes; 112, argument_list; 112, 113; 112, 115; 113, list:[field_name]; 113, 114; 114, identifier:field_name; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:layer; 118, identifier:fields; 119, argument_list; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:layer; 124, identifier:startEditing; 125, argument_list; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:i; 129, integer:0; 130, for_statement; 130, 131; 130, 132; 130, 138; 131, identifier:feature; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:layer; 135, identifier:getFeatures; 136, argument_list; 136, 137; 137, identifier:request; 138, block; 138, 139; 138, 149; 138, 231; 138, 239; 138, 259; 138, 282; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:feat_attr; 142, subscript; 142, 143; 142, 148; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:feature; 146, identifier:attributes; 147, argument_list; 148, identifier:index; 149, if_statement; 149, 150; 149, 167; 150, parenthesized_expression; 150, 151; 151, boolean_operator:or; 151, 152; 151, 155; 152, comparison_operator:is; 152, 153; 152, 154; 153, identifier:feat_attr; 154, None; 155, parenthesized_expression; 155, 156; 156, boolean_operator:and; 156, 157; 156, 162; 157, call; 157, 158; 157, 159; 158, identifier:hasattr; 159, argument_list; 159, 160; 159, 161; 160, identifier:feat_attr; 161, string:'isNull'; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:feat_attr; 165, identifier:isNull; 166, argument_list; 167, block; 167, 168; 168, if_statement; 168, 169; 168, 172; 168, 188; 168, 213; 169, comparison_operator:==; 169, 170; 169, 171; 170, identifier:layer_purpose; 171, string:'hazard'; 172, block; 172, 173; 172, 184; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:layer; 177, identifier:deleteFeature; 178, argument_list; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:feature; 182, identifier:id; 183, argument_list; 184, expression_statement; 184, 185; 185, augmented_assignment:+=; 185, 186; 185, 187; 186, identifier:i; 187, integer:1; 188, elif_clause; 188, 189; 188, 192; 189, comparison_operator:==; 189, 190; 189, 191; 190, identifier:layer_purpose; 191, string:'aggregation'; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:layer; 197, identifier:changeAttributeValue; 198, argument_list; 198, 199; 198, 204; 198, 205; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:feature; 202, identifier:id; 203, argument_list; 204, identifier:index; 205, call; 205, 206; 205, 207; 206, identifier:str; 207, argument_list; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:feature; 211, identifier:id; 212, argument_list; 213, elif_clause; 213, 214; 213, 217; 214, comparison_operator:==; 214, 215; 214, 216; 215, identifier:layer_purpose; 216, string:'exposure'; 217, block; 217, 218; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:layer; 222, identifier:changeAttributeValue; 223, argument_list; 223, 224; 223, 229; 223, 230; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:feature; 227, identifier:id; 228, argument_list; 229, identifier:index; 230, string:''; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:geometry; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:feature; 237, identifier:geometry; 238, argument_list; 239, if_statement; 239, 240; 239, 242; 240, not_operator; 240, 241; 241, identifier:geometry; 242, block; 242, 243; 242, 254; 242, 258; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:layer; 247, identifier:deleteFeature; 248, argument_list; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:feature; 252, identifier:id; 253, argument_list; 254, expression_statement; 254, 255; 255, augmented_assignment:+=; 255, 256; 255, 257; 256, identifier:i; 257, integer:1; 258, continue_statement; 259, if_statement; 259, 260; 259, 265; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:geometry; 263, identifier:isEmpty; 264, argument_list; 265, block; 265, 266; 265, 277; 265, 281; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:layer; 270, identifier:deleteFeature; 271, argument_list; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:feature; 275, identifier:id; 276, argument_list; 277, expression_statement; 277, 278; 278, augmented_assignment:+=; 278, 279; 278, 280; 279, identifier:i; 280, integer:1; 281, continue_statement; 282, if_statement; 282, 283; 282, 289; 283, not_operator; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:geometry; 287, identifier:isGeosValid; 288, argument_list; 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:layer; 295, identifier:commitChanges; 296, argument_list; 297, if_statement; 297, 298; 297, 299; 297, 315; 298, identifier:i; 299, block; 299, 300; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:LOGGER; 304, identifier:critical; 305, argument_list; 305, 306; 306, binary_operator:%; 306, 307; 306, 308; 307, string:'Features which have been removed from %s : %s'; 308, tuple; 308, 309; 308, 314; 309, subscript; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:layer; 312, identifier:keywords; 313, string:'layer_purpose'; 314, identifier:i; 315, else_clause; 315, 316; 316, block; 316, 317; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:LOGGER; 321, identifier:info; 322, argument_list; 322, 323; 323, binary_operator:%; 323, 324; 323, 327; 324, concatenated_string; 324, 325; 324, 326; 325, string:'No feature has been removed from %s during the vector layer '; 326, string:'preparation'; 327, subscript; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:layer; 330, identifier:keywords; 331, string:'layer_purpose' | def _remove_features(layer):
layer_purpose = layer.keywords['layer_purpose']
layer_subcategory = layer.keywords.get(layer_purpose)
compulsory_field = get_compulsory_fields(layer_purpose, layer_subcategory)
inasafe_fields = layer.keywords['inasafe_fields']
field_names = inasafe_fields.get(compulsory_field['key'])
if not isinstance(field_names, list):
field_names = [field_names]
for field_name in field_names:
if not field_name:
message = 'Keyword %s is missing from %s' % (
compulsory_field['key'], layer_purpose)
raise InvalidKeywordsForProcessingAlgorithm(message)
index = layer.fields().lookupField(field_name)
request = QgsFeatureRequest()
request.setSubsetOfAttributes([field_name], layer.fields())
layer.startEditing()
i = 0
for feature in layer.getFeatures(request):
feat_attr = feature.attributes()[index]
if (feat_attr is None
or (hasattr(feat_attr, 'isNull')
and feat_attr.isNull())):
if layer_purpose == 'hazard':
layer.deleteFeature(feature.id())
i += 1
elif layer_purpose == 'aggregation':
layer.changeAttributeValue(
feature.id(), index, str(feature.id()))
elif layer_purpose == 'exposure':
layer.changeAttributeValue(
feature.id(), index, '')
geometry = feature.geometry()
if not geometry:
layer.deleteFeature(feature.id())
i += 1
continue
if geometry.isEmpty():
layer.deleteFeature(feature.id())
i += 1
continue
if not geometry.isGeosValid():
pass
layer.commitChanges()
if i:
LOGGER.critical(
'Features which have been removed from %s : %s'
% (layer.keywords['layer_purpose'], i))
else:
LOGGER.info(
'No feature has been removed from %s during the vector layer '
'preparation' % layer.keywords['layer_purpose']) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_profiles; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:overwrite; 7, False; 8, block; 8, 9; 8, 69; 9, function_definition; 9, 10; 9, 11; 9, 14; 10, function_name:sort_by_locale; 11, parameters; 11, 12; 11, 13; 12, identifier:unsorted_profiles; 13, identifier:locale; 14, block; 14, 15; 14, 22; 14, 32; 14, 36; 14, 40; 14, 65; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:locale; 18, None; 19, block; 19, 20; 20, return_statement; 20, 21; 21, identifier:unsorted_profiles; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:locale; 25, binary_operator:%; 25, 26; 25, 27; 26, string:'_%s'; 27, subscript; 27, 28; 27, 29; 28, identifier:locale; 29, slice; 29, 30; 29, 31; 30, colon; 31, integer:2; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:profiles_our_locale; 35, list:[]; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:profiles_remaining; 39, list:[]; 40, for_statement; 40, 41; 40, 42; 40, 43; 41, identifier:profile_name; 42, identifier:unsorted_profiles; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 48; 44, 56; 45, comparison_operator:in; 45, 46; 45, 47; 46, identifier:locale; 47, identifier:profile_name; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:profiles_our_locale; 53, identifier:append; 54, argument_list; 54, 55; 55, identifier:profile_name; 56, else_clause; 56, 57; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:profiles_remaining; 62, identifier:append; 63, argument_list; 63, 64; 64, identifier:profile_name; 65, return_statement; 65, 66; 66, binary_operator:+; 66, 67; 66, 68; 67, identifier:profiles_our_locale; 68, identifier:profiles_remaining; 69, if_statement; 69, 70; 69, 74; 69, 81; 70, not_operator; 70, 71; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:root_directory; 74, block; 74, 75; 74, 79; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:profiles; 78, list:[]; 79, return_statement; 79, 80; 80, identifier:profiles; 81, else_clause; 81, 82; 82, block; 82, 83; 82, 97; 82, 104; 82, 122; 82, 174; 82, 181; 82, 208; 82, 218; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:locale_minimum_needs_dir; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:os; 90, identifier:path; 91, identifier:join; 92, argument_list; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:root_directory; 96, string:'minimum_needs'; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:path_name; 100, call; 100, 101; 100, 102; 101, identifier:resources_path; 102, argument_list; 102, 103; 103, string:'minimum_needs'; 104, if_statement; 104, 105; 104, 114; 105, not_operator; 105, 106; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:os; 110, identifier:path; 111, identifier:exists; 112, argument_list; 112, 113; 113, identifier:locale_minimum_needs_dir; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:os; 119, identifier:makedirs; 120, argument_list; 120, 121; 121, identifier:locale_minimum_needs_dir; 122, for_statement; 122, 123; 122, 124; 122, 130; 123, identifier:file_name; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:os; 127, identifier:listdir; 128, argument_list; 128, 129; 129, identifier:path_name; 130, block; 130, 131; 130, 143; 130, 155; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:source_file; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:os; 138, identifier:path; 139, identifier:join; 140, argument_list; 140, 141; 140, 142; 141, identifier:path_name; 142, identifier:file_name; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:destination_file; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:os; 150, identifier:path; 151, identifier:join; 152, argument_list; 152, 153; 152, 154; 153, identifier:locale_minimum_needs_dir; 154, identifier:file_name; 155, if_statement; 155, 156; 155, 167; 156, boolean_operator:or; 156, 157; 156, 166; 157, not_operator; 157, 158; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:os; 162, identifier:path; 163, identifier:exists; 164, argument_list; 164, 165; 165, identifier:destination_file; 166, identifier:overwrite; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:copy; 171, argument_list; 171, 172; 171, 173; 172, identifier:source_file; 173, identifier:destination_file; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:move_old_profile; 179, argument_list; 179, 180; 180, identifier:locale_minimum_needs_dir; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:profiles; 184, list_comprehension; 184, 185; 184, 191; 184, 199; 185, subscript; 185, 186; 185, 187; 186, identifier:profile; 187, slice; 187, 188; 187, 189; 188, colon; 189, unary_operator:-; 189, 190; 190, integer:5; 191, for_in_clause; 191, 192; 191, 193; 192, identifier:profile; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:os; 196, identifier:listdir; 197, argument_list; 197, 198; 198, identifier:locale_minimum_needs_dir; 199, if_clause; 199, 200; 200, comparison_operator:==; 200, 201; 200, 207; 201, subscript; 201, 202; 201, 203; 202, identifier:profile; 203, slice; 203, 204; 203, 206; 204, unary_operator:-; 204, 205; 205, integer:5; 206, colon; 207, string:'.json'; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:profiles; 211, call; 211, 212; 211, 213; 212, identifier:sort_by_locale; 213, argument_list; 213, 214; 213, 215; 214, identifier:profiles; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:locale; 218, return_statement; 218, 219; 219, identifier:profiles | def get_profiles(self, overwrite=False):
def sort_by_locale(unsorted_profiles, locale):
if locale is None:
return unsorted_profiles
locale = '_%s' % locale[:2]
profiles_our_locale = []
profiles_remaining = []
for profile_name in unsorted_profiles:
if locale in profile_name:
profiles_our_locale.append(profile_name)
else:
profiles_remaining.append(profile_name)
return profiles_our_locale + profiles_remaining
if not self.root_directory:
profiles = []
return profiles
else:
locale_minimum_needs_dir = os.path.join(
self.root_directory, 'minimum_needs')
path_name = resources_path('minimum_needs')
if not os.path.exists(locale_minimum_needs_dir):
os.makedirs(locale_minimum_needs_dir)
for file_name in os.listdir(path_name):
source_file = os.path.join(path_name, file_name)
destination_file = os.path.join(
locale_minimum_needs_dir, file_name)
if not os.path.exists(destination_file) or overwrite:
copy(source_file, destination_file)
self.move_old_profile(locale_minimum_needs_dir)
profiles = [
profile[:-5] for profile in
os.listdir(locale_minimum_needs_dir) if
profile[-5:] == '.json']
profiles = sort_by_locale(profiles, self.locale)
return profiles |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sorted_keywords_by_order; 3, parameters; 3, 4; 3, 5; 4, identifier:keywords; 5, identifier:order; 6, block; 6, 7; 6, 29; 6, 35; 6, 62; 6, 82; 7, for_statement; 7, 8; 7, 11; 7, 19; 8, pattern_list; 8, 9; 8, 10; 9, identifier:key; 10, identifier:value; 11, call; 11, 12; 11, 13; 12, identifier:list; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:keywords; 17, identifier:items; 18, argument_list; 19, block; 19, 20; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:value; 23, None; 24, block; 24, 25; 25, delete_statement; 25, 26; 26, subscript; 26, 27; 26, 28; 27, identifier:keywords; 28, identifier:key; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:ordered_keywords; 32, call; 32, 33; 32, 34; 33, identifier:OrderedDict; 34, argument_list; 35, for_statement; 35, 36; 35, 37; 35, 38; 36, identifier:key; 37, identifier:order; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 50; 40, comparison_operator:in; 40, 41; 40, 42; 41, identifier:key; 42, call; 42, 43; 42, 44; 43, identifier:list; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:keywords; 48, identifier:keys; 49, argument_list; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:ordered_keywords; 55, identifier:key; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:keywords; 59, identifier:get; 60, argument_list; 60, 61; 61, identifier:key; 62, for_statement; 62, 63; 62, 64; 62, 65; 63, identifier:keyword; 64, identifier:keywords; 65, block; 65, 66; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:not; 67, 68; 67, 69; 68, identifier:keyword; 69, identifier:order; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:ordered_keywords; 75, identifier:keyword; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:keywords; 79, identifier:get; 80, argument_list; 80, 81; 81, identifier:keyword; 82, return_statement; 82, 83; 83, identifier:ordered_keywords | def sorted_keywords_by_order(keywords, order):
for key, value in list(keywords.items()):
if value is None:
del keywords[key]
ordered_keywords = OrderedDict()
for key in order:
if key in list(keywords.keys()):
ordered_keywords[key] = keywords.get(key)
for keyword in keywords:
if keyword not in order:
ordered_keywords[keyword] = keywords.get(keyword)
return ordered_keywords |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_layer_modes; 3, parameters; 3, 4; 4, identifier:subcategory; 5, block; 5, 6; 5, 15; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:layer_modes; 9, subscript; 9, 10; 9, 14; 10, call; 10, 11; 10, 12; 11, identifier:definition; 12, argument_list; 12, 13; 13, identifier:subcategory; 14, string:'layer_modes'; 15, return_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:sorted; 18, argument_list; 18, 19; 18, 20; 19, identifier:layer_modes; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:key; 22, lambda; 22, 23; 22, 25; 23, lambda_parameters; 23, 24; 24, identifier:k; 25, subscript; 25, 26; 25, 27; 26, identifier:k; 27, string:'key' | def get_layer_modes(subcategory):
layer_modes = definition(subcategory)['layer_modes']
return sorted(layer_modes, key=lambda k: k['key']) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:add_ordered_combo_item; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:combo; 5, identifier:text; 6, default_parameter; 6, 7; 6, 8; 7, identifier:data; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:count_selected_features; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:icon; 14, None; 15, block; 15, 16; 15, 39; 15, 47; 15, 106; 16, if_statement; 16, 17; 16, 20; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:count_selected_features; 19, None; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, augmented_assignment:+=; 22, 23; 22, 24; 23, identifier:text; 24, binary_operator:+; 24, 25; 24, 38; 25, binary_operator:+; 25, 26; 25, 27; 26, string:' ('; 27, call; 27, 28; 27, 34; 28, attribute; 28, 29; 28, 33; 29, call; 29, 30; 29, 31; 30, identifier:tr; 31, argument_list; 31, 32; 32, string:'{count} selected features'; 33, identifier:format; 34, argument_list; 34, 35; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:count; 37, identifier:count_selected_features; 38, string:')'; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:size; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:combo; 45, identifier:count; 46, argument_list; 47, for_statement; 47, 48; 47, 49; 47, 54; 48, identifier:combo_index; 49, call; 49, 50; 49, 51; 50, identifier:range; 51, argument_list; 51, 52; 51, 53; 52, integer:0; 53, identifier:size; 54, block; 54, 55; 54, 64; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:item_text; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:combo; 61, identifier:itemText; 62, argument_list; 62, 63; 63, identifier:combo_index; 64, if_statement; 64, 65; 64, 80; 65, comparison_operator:<; 65, 66; 65, 79; 66, call; 66, 67; 66, 68; 67, identifier:cmp; 68, argument_list; 68, 69; 68, 74; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:text; 72, identifier:lower; 73, argument_list; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:item_text; 77, identifier:lower; 78, argument_list; 79, integer:0; 80, block; 80, 81; 80, 105; 81, if_statement; 81, 82; 81, 83; 81, 94; 82, identifier:icon; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:combo; 88, identifier:insertItem; 89, argument_list; 89, 90; 89, 91; 89, 92; 89, 93; 90, identifier:combo_index; 91, identifier:icon; 92, identifier:text; 93, identifier:data; 94, else_clause; 94, 95; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:combo; 100, identifier:insertItem; 101, argument_list; 101, 102; 101, 103; 101, 104; 102, identifier:combo_index; 103, identifier:text; 104, identifier:data; 105, return_statement; 106, if_statement; 106, 107; 106, 108; 106, 119; 107, identifier:icon; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:combo; 113, identifier:insertItem; 114, argument_list; 114, 115; 114, 116; 114, 117; 114, 118; 115, identifier:size; 116, identifier:icon; 117, identifier:text; 118, identifier:data; 119, else_clause; 119, 120; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:combo; 125, identifier:insertItem; 126, argument_list; 126, 127; 126, 128; 126, 129; 127, identifier:size; 128, identifier:text; 129, identifier:data | def add_ordered_combo_item(
combo, text, data=None, count_selected_features=None, icon=None):
if count_selected_features is not None:
text += ' (' + tr('{count} selected features').format(
count=count_selected_features) + ')'
size = combo.count()
for combo_index in range(0, size):
item_text = combo.itemText(combo_index)
if cmp(text.lower(), item_text.lower()) < 0:
if icon:
combo.insertItem(combo_index, icon, text, data)
else:
combo.insertItem(combo_index, text, data)
return
if icon:
combo.insertItem(size, icon, text, data)
else:
combo.insertItem(size, text, data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 15; 8, attribute; 8, 9; 8, 14; 9, call; 9, 10; 9, 11; 10, identifier:super; 11, argument_list; 11, 12; 11, 13; 12, identifier:JSSObjectList; 13, identifier:self; 14, identifier:sort; 15, argument_list; 15, 16; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:key; 18, lambda; 18, 19; 18, 21; 19, lambda_parameters; 19, 20; 20, identifier:k; 21, attribute; 21, 22; 21, 23; 22, identifier:k; 23, identifier:id | def sort(self):
super(JSSObjectList, self).sort(key=lambda k: k.id) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_by_name; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 15; 8, attribute; 8, 9; 8, 14; 9, call; 9, 10; 9, 11; 10, identifier:super; 11, argument_list; 11, 12; 11, 13; 12, identifier:JSSObjectList; 13, identifier:self; 14, identifier:sort; 15, argument_list; 15, 16; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:key; 18, lambda; 18, 19; 18, 21; 19, lambda_parameters; 19, 20; 20, identifier:k; 21, attribute; 21, 22; 21, 23; 22, identifier:k; 23, identifier:name | def sort_by_name(self):
super(JSSObjectList, self).sort(key=lambda k: k.name) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:find_sorted_task_dependencies; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:task; 5, identifier:task_name; 6, identifier:task_id; 7, block; 7, 8; 7, 21; 7, 54; 7, 83; 7, 91; 7, 98; 7, 110; 7, 114; 7, 123; 7, 131; 7, 143; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:log; 12, identifier:info; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, string:"find_sorted_task_dependencies {} {}"; 17, identifier:format; 18, argument_list; 18, 19; 18, 20; 19, identifier:task_name; 20, identifier:task_id; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:cot_input_dependencies; 24, list_comprehension; 24, 25; 24, 31; 25, call; 25, 26; 25, 27; 26, identifier:_craft_dependency_tuple; 27, argument_list; 27, 28; 27, 29; 27, 30; 28, identifier:task_name; 29, identifier:task_type; 30, identifier:task_id; 31, for_in_clause; 31, 32; 31, 35; 32, pattern_list; 32, 33; 32, 34; 33, identifier:task_type; 34, identifier:task_id; 35, call; 35, 36; 35, 53; 36, attribute; 36, 37; 36, 52; 37, call; 37, 38; 37, 49; 38, attribute; 38, 39; 38, 48; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:task; 43, string:'extra'; 44, identifier:get; 45, argument_list; 45, 46; 45, 47; 46, string:'chainOfTrust'; 47, dictionary; 48, identifier:get; 49, argument_list; 49, 50; 49, 51; 50, string:'inputs'; 51, dictionary; 52, identifier:items; 53, argument_list; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:upstream_artifacts_dependencies; 57, list_comprehension; 57, 58; 57, 68; 58, call; 58, 59; 58, 60; 59, identifier:_craft_dependency_tuple; 60, argument_list; 60, 61; 60, 62; 60, 65; 61, identifier:task_name; 62, subscript; 62, 63; 62, 64; 63, identifier:artifact_dict; 64, string:'taskType'; 65, subscript; 65, 66; 65, 67; 66, identifier:artifact_dict; 67, string:'taskId'; 68, for_in_clause; 68, 69; 68, 70; 69, identifier:artifact_dict; 70, call; 70, 71; 70, 80; 71, attribute; 71, 72; 71, 79; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:task; 75, identifier:get; 76, argument_list; 76, 77; 76, 78; 77, string:'payload'; 78, dictionary; 79, identifier:get; 80, argument_list; 80, 81; 80, 82; 81, string:'upstreamArtifacts'; 82, list:[]; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:dependencies; 86, list:[*cot_input_dependencies, *upstream_artifacts_dependencies]; 86, 87; 86, 89; 87, list_splat; 87, 88; 88, identifier:cot_input_dependencies; 89, list_splat; 89, 90; 90, identifier:upstream_artifacts_dependencies; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:dependencies; 94, call; 94, 95; 94, 96; 95, identifier:_sort_dependencies_by_name_then_task_id; 96, argument_list; 96, 97; 97, identifier:dependencies; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:parent_task_id; 101, boolean_operator:or; 101, 102; 101, 106; 102, call; 102, 103; 102, 104; 103, identifier:get_parent_task_id; 104, argument_list; 104, 105; 105, identifier:task; 106, call; 106, 107; 106, 108; 107, identifier:get_decision_task_id; 108, argument_list; 108, 109; 109, identifier:task; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:parent_task_type; 113, string:'parent'; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:parent_tuple; 117, call; 117, 118; 117, 119; 118, identifier:_craft_dependency_tuple; 119, argument_list; 119, 120; 119, 121; 119, 122; 120, identifier:task_name; 121, identifier:parent_task_type; 122, identifier:parent_task_id; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:dependencies; 127, identifier:insert; 128, argument_list; 128, 129; 128, 130; 129, integer:0; 130, identifier:parent_tuple; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:log; 135, identifier:info; 136, argument_list; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, string:'found dependencies: {}'; 140, identifier:format; 141, argument_list; 141, 142; 142, identifier:dependencies; 143, return_statement; 143, 144; 144, identifier:dependencies | def find_sorted_task_dependencies(task, task_name, task_id):
log.info("find_sorted_task_dependencies {} {}".format(task_name, task_id))
cot_input_dependencies = [
_craft_dependency_tuple(task_name, task_type, task_id)
for task_type, task_id in task['extra'].get('chainOfTrust', {}).get('inputs', {}).items()
]
upstream_artifacts_dependencies = [
_craft_dependency_tuple(task_name, artifact_dict['taskType'], artifact_dict['taskId'])
for artifact_dict in task.get('payload', {}).get('upstreamArtifacts', [])
]
dependencies = [*cot_input_dependencies, *upstream_artifacts_dependencies]
dependencies = _sort_dependencies_by_name_then_task_id(dependencies)
parent_task_id = get_parent_task_id(task) or get_decision_task_id(task)
parent_task_type = 'parent'
parent_tuple = _craft_dependency_tuple(task_name, parent_task_type, parent_task_id)
dependencies.insert(0, parent_tuple)
log.info('found dependencies: {}'.format(dependencies))
return dependencies |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_all_artifacts_per_task_id; 3, parameters; 3, 4; 3, 5; 4, identifier:chain; 5, identifier:upstream_artifacts; 6, block; 6, 7; 6, 11; 6, 76; 6, 100; 6, 122; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:all_artifacts_per_task_id; 10, dictionary; 11, for_statement; 11, 12; 11, 13; 11, 16; 12, identifier:link; 13, attribute; 13, 14; 13, 15; 14, identifier:chain; 15, identifier:links; 16, block; 16, 17; 16, 39; 17, if_statement; 17, 18; 17, 23; 18, comparison_operator:in; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:link; 21, identifier:task_type; 22, identifier:PARENT_TASK_TYPES; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:add_enumerable_item_to_dict; 27, argument_list; 27, 28; 27, 31; 27, 36; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:dict_; 30, identifier:all_artifacts_per_task_id; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:key; 33, attribute; 33, 34; 33, 35; 34, identifier:link; 35, identifier:task_id; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:item; 38, string:'public/task-graph.json'; 39, if_statement; 39, 40; 39, 45; 40, comparison_operator:in; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:link; 43, identifier:task_type; 44, identifier:DECISION_TASK_TYPES; 45, block; 45, 46; 45, 61; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:add_enumerable_item_to_dict; 49, argument_list; 49, 50; 49, 53; 49, 58; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:dict_; 52, identifier:all_artifacts_per_task_id; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:key; 55, attribute; 55, 56; 55, 57; 56, identifier:link; 57, identifier:task_id; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:item; 60, string:'public/actions.json'; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:add_enumerable_item_to_dict; 64, argument_list; 64, 65; 64, 68; 64, 73; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:dict_; 67, identifier:all_artifacts_per_task_id; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:key; 70, attribute; 70, 71; 70, 72; 71, identifier:link; 72, identifier:task_id; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:item; 75, string:'public/parameters.yml'; 76, if_statement; 76, 77; 76, 78; 77, identifier:upstream_artifacts; 78, block; 78, 79; 79, for_statement; 79, 80; 79, 81; 79, 82; 80, identifier:upstream_dict; 81, identifier:upstream_artifacts; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:add_enumerable_item_to_dict; 86, argument_list; 86, 87; 86, 90; 86, 95; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:dict_; 89, identifier:all_artifacts_per_task_id; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:key; 92, subscript; 92, 93; 92, 94; 93, identifier:upstream_dict; 94, string:'taskId'; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:item; 97, subscript; 97, 98; 97, 99; 98, identifier:upstream_dict; 99, string:'paths'; 100, for_statement; 100, 101; 100, 104; 100, 109; 101, pattern_list; 101, 102; 101, 103; 102, identifier:task_id; 103, identifier:paths; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:all_artifacts_per_task_id; 107, identifier:items; 108, argument_list; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:all_artifacts_per_task_id; 114, identifier:task_id; 115, call; 115, 116; 115, 117; 116, identifier:sorted; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:set; 120, argument_list; 120, 121; 121, identifier:paths; 122, return_statement; 122, 123; 123, identifier:all_artifacts_per_task_id | def get_all_artifacts_per_task_id(chain, upstream_artifacts):
all_artifacts_per_task_id = {}
for link in chain.links:
if link.task_type in PARENT_TASK_TYPES:
add_enumerable_item_to_dict(
dict_=all_artifacts_per_task_id, key=link.task_id, item='public/task-graph.json'
)
if link.task_type in DECISION_TASK_TYPES:
add_enumerable_item_to_dict(
dict_=all_artifacts_per_task_id, key=link.task_id, item='public/actions.json'
)
add_enumerable_item_to_dict(
dict_=all_artifacts_per_task_id, key=link.task_id, item='public/parameters.yml'
)
if upstream_artifacts:
for upstream_dict in upstream_artifacts:
add_enumerable_item_to_dict(
dict_=all_artifacts_per_task_id, key=upstream_dict['taskId'], item=upstream_dict['paths']
)
for task_id, paths in all_artifacts_per_task_id.items():
all_artifacts_per_task_id[task_id] = sorted(set(paths))
return all_artifacts_per_task_id |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_upstream_artifacts_full_paths_per_task_id; 3, parameters; 3, 4; 4, identifier:context; 5, block; 5, 6; 5, 16; 5, 30; 5, 37; 5, 41; 5, 45; 5, 122; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:upstream_artifacts; 9, subscript; 9, 10; 9, 15; 10, subscript; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:context; 13, identifier:task; 14, string:'payload'; 15, string:'upstreamArtifacts'; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:task_ids_and_relative_paths; 19, list_comprehension; 19, 20; 19, 27; 20, tuple; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:artifact_definition; 23, string:'taskId'; 24, subscript; 24, 25; 24, 26; 25, identifier:artifact_definition; 26, string:'paths'; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:artifact_definition; 29, identifier:upstream_artifacts; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:optional_artifacts_per_task_id; 33, call; 33, 34; 33, 35; 34, identifier:get_optional_artifacts_per_task_id; 35, argument_list; 35, 36; 36, identifier:upstream_artifacts; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:upstream_artifacts_full_paths_per_task_id; 40, dictionary; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:failed_paths_per_task_id; 44, dictionary; 45, for_statement; 45, 46; 45, 49; 45, 50; 46, pattern_list; 46, 47; 46, 48; 47, identifier:task_id; 48, identifier:paths; 49, identifier:task_ids_and_relative_paths; 50, block; 50, 51; 51, for_statement; 51, 52; 51, 53; 51, 54; 52, identifier:path; 53, identifier:paths; 54, block; 54, 55; 55, try_statement; 55, 56; 55, 79; 56, block; 56, 57; 56, 66; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:path_to_add; 60, call; 60, 61; 60, 62; 61, identifier:get_and_check_single_upstream_artifact_full_path; 62, argument_list; 62, 63; 62, 64; 62, 65; 63, identifier:context; 64, identifier:task_id; 65, identifier:path; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:add_enumerable_item_to_dict; 69, argument_list; 69, 70; 69, 73; 69, 76; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:dict_; 72, identifier:upstream_artifacts_full_paths_per_task_id; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:key; 75, identifier:task_id; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:item; 78, identifier:path_to_add; 79, except_clause; 79, 80; 79, 81; 80, identifier:ScriptWorkerTaskException; 81, block; 81, 82; 82, if_statement; 82, 83; 82, 92; 82, 119; 83, comparison_operator:in; 83, 84; 83, 85; 84, identifier:path; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:optional_artifacts_per_task_id; 88, identifier:get; 89, argument_list; 89, 90; 89, 91; 90, identifier:task_id; 91, list:[]; 92, block; 92, 93; 92, 106; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:log; 97, identifier:warning; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, string:'Optional artifact "{}" of task "{}" not found'; 102, identifier:format; 103, argument_list; 103, 104; 103, 105; 104, identifier:path; 105, identifier:task_id; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:add_enumerable_item_to_dict; 109, argument_list; 109, 110; 109, 113; 109, 116; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:dict_; 112, identifier:failed_paths_per_task_id; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:key; 115, identifier:task_id; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:item; 118, identifier:path; 119, else_clause; 119, 120; 120, block; 120, 121; 121, raise_statement; 122, return_statement; 122, 123; 123, expression_list; 123, 124; 123, 125; 124, identifier:upstream_artifacts_full_paths_per_task_id; 125, identifier:failed_paths_per_task_id | def get_upstream_artifacts_full_paths_per_task_id(context):
upstream_artifacts = context.task['payload']['upstreamArtifacts']
task_ids_and_relative_paths = [
(artifact_definition['taskId'], artifact_definition['paths'])
for artifact_definition in upstream_artifacts
]
optional_artifacts_per_task_id = get_optional_artifacts_per_task_id(upstream_artifacts)
upstream_artifacts_full_paths_per_task_id = {}
failed_paths_per_task_id = {}
for task_id, paths in task_ids_and_relative_paths:
for path in paths:
try:
path_to_add = get_and_check_single_upstream_artifact_full_path(context, task_id, path)
add_enumerable_item_to_dict(
dict_=upstream_artifacts_full_paths_per_task_id,
key=task_id, item=path_to_add
)
except ScriptWorkerTaskException:
if path in optional_artifacts_per_task_id.get(task_id, []):
log.warning('Optional artifact "{}" of task "{}" not found'.format(path, task_id))
add_enumerable_item_to_dict(
dict_=failed_paths_per_task_id,
key=task_id, item=path
)
else:
raise
return upstream_artifacts_full_paths_per_task_id, failed_paths_per_task_id |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_PreparedData; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:order_by; 7, tuple; 8, block; 8, 9; 8, 17; 8, 26; 8, 66; 8, 175; 9, if_statement; 9, 10; 9, 12; 10, not_operator; 10, 11; 11, identifier:order_by; 12, block; 12, 13; 13, return_statement; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:__data; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:sorted_data; 20, subscript; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:__data; 24, slice; 24, 25; 25, colon; 26, if_statement; 26, 27; 26, 60; 27, boolean_operator:or; 27, 28; 27, 35; 28, call; 28, 29; 28, 30; 29, identifier:isinstance; 30, argument_list; 30, 31; 30, 32; 31, identifier:order_by; 32, attribute; 32, 33; 32, 34; 33, identifier:six; 34, identifier:string_types; 35, parenthesized_expression; 35, 36; 36, boolean_operator:and; 36, 37; 36, 49; 37, boolean_operator:and; 37, 38; 37, 43; 38, call; 38, 39; 38, 40; 39, identifier:isinstance; 40, argument_list; 40, 41; 40, 42; 41, identifier:order_by; 42, identifier:tuple; 43, comparison_operator:==; 43, 44; 43, 48; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, identifier:order_by; 48, integer:2; 49, comparison_operator:in; 49, 50; 49, 57; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:order_by; 54, integer:1; 55, identifier:lower; 56, argument_list; 57, list:["asc", "desc"]; 57, 58; 57, 59; 58, string:"asc"; 59, string:"desc"; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:order_by; 64, tuple; 64, 65; 65, identifier:order_by; 66, for_statement; 66, 67; 66, 68; 66, 72; 67, identifier:key; 68, call; 68, 69; 68, 70; 69, identifier:reversed; 70, argument_list; 70, 71; 71, identifier:order_by; 72, block; 72, 73; 73, if_statement; 73, 74; 73, 81; 73, 101; 73, 166; 74, call; 74, 75; 74, 76; 75, identifier:isinstance; 76, argument_list; 76, 77; 76, 78; 77, identifier:key; 78, attribute; 78, 79; 78, 80; 79, identifier:six; 80, identifier:string_types; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:sorted_data; 86, identifier:sort; 87, argument_list; 87, 88; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:key; 90, lambda; 90, 91; 90, 93; 91, lambda_parameters; 91, 92; 92, identifier:x; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:x; 97, integer:0; 98, identifier:get; 99, argument_list; 99, 100; 100, identifier:key; 101, elif_clause; 101, 102; 101, 129; 102, parenthesized_expression; 102, 103; 103, boolean_operator:and; 103, 104; 103, 118; 104, boolean_operator:and; 104, 105; 104, 112; 105, call; 105, 106; 105, 107; 106, identifier:isinstance; 107, argument_list; 107, 108; 107, 109; 108, identifier:key; 109, tuple; 109, 110; 109, 111; 110, identifier:list; 111, identifier:tuple; 112, comparison_operator:==; 112, 113; 112, 117; 113, call; 113, 114; 113, 115; 114, identifier:len; 115, argument_list; 115, 116; 116, identifier:key; 117, integer:2; 118, comparison_operator:in; 118, 119; 118, 126; 119, call; 119, 120; 119, 125; 120, attribute; 120, 121; 120, 124; 121, subscript; 121, 122; 121, 123; 122, identifier:key; 123, integer:1; 124, identifier:lower; 125, argument_list; 126, tuple; 126, 127; 126, 128; 127, string:"asc"; 128, string:"desc"; 129, block; 129, 130; 129, 146; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:key_func; 133, lambda; 133, 134; 133, 136; 134, lambda_parameters; 134, 135; 135, identifier:x; 136, call; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:x; 140, integer:0; 141, identifier:get; 142, argument_list; 142, 143; 143, subscript; 143, 144; 143, 145; 144, identifier:key; 145, integer:0; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:sorted_data; 150, identifier:sort; 151, argument_list; 151, 152; 151, 155; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:key; 154, identifier:key_func; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:reverse; 157, comparison_operator:!=; 157, 158; 157, 165; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:key; 162, integer:1; 163, identifier:lower; 164, argument_list; 165, string:"asc"; 166, else_clause; 166, 167; 167, block; 167, 168; 168, raise_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:DataTableException; 171, argument_list; 171, 172; 172, concatenated_string; 172, 173; 172, 174; 173, string:"Expected tuple with second value: "; 174, string:"'asc' or 'desc'"; 175, return_statement; 175, 176; 176, identifier:sorted_data | def _PreparedData(self, order_by=()):
if not order_by:
return self.__data
sorted_data = self.__data[:]
if isinstance(order_by, six.string_types) or (
isinstance(order_by, tuple) and len(order_by) == 2 and
order_by[1].lower() in ["asc", "desc"]):
order_by = (order_by,)
for key in reversed(order_by):
if isinstance(key, six.string_types):
sorted_data.sort(key=lambda x: x[0].get(key))
elif (isinstance(key, (list, tuple)) and len(key) == 2 and
key[1].lower() in ("asc", "desc")):
key_func = lambda x: x[0].get(key[0])
sorted_data.sort(key=key_func, reverse=key[1].lower() != "asc")
else:
raise DataTableException("Expected tuple with second value: "
"'asc' or 'desc'")
return sorted_data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:ToJSCode; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:columns_order; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:order_by; 11, tuple; 12, block; 12, 13; 12, 19; 12, 36; 12, 53; 12, 59; 12, 79; 12, 150; 12, 163; 12, 314; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:encoder; 16, call; 16, 17; 16, 18; 17, identifier:DataTableJSONEncoder; 18, argument_list; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:columns_order; 22, None; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:columns_order; 27, list_comprehension; 27, 28; 27, 31; 28, subscript; 28, 29; 28, 30; 29, identifier:col; 30, string:"id"; 31, for_in_clause; 31, 32; 31, 33; 32, identifier:col; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:__columns; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:col_dict; 39, call; 39, 40; 39, 41; 40, identifier:dict; 41, argument_list; 41, 42; 42, list_comprehension; 42, 43; 42, 48; 43, tuple; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:col; 46, string:"id"; 47, identifier:col; 48, for_in_clause; 48, 49; 48, 50; 49, identifier:col; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:__columns; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:jscode; 56, binary_operator:%; 56, 57; 56, 58; 57, string:"var %s = new google.visualization.DataTable();\n"; 58, identifier:name; 59, if_statement; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:custom_properties; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, augmented_assignment:+=; 65, 66; 65, 67; 66, identifier:jscode; 67, binary_operator:%; 67, 68; 67, 69; 68, string:"%s.setTableProperties(%s);\n"; 69, tuple; 69, 70; 69, 71; 70, identifier:name; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:encoder; 74, identifier:encode; 75, argument_list; 75, 76; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:custom_properties; 79, for_statement; 79, 80; 79, 83; 79, 87; 80, pattern_list; 80, 81; 80, 82; 81, identifier:i; 82, identifier:col; 83, call; 83, 84; 83, 85; 84, identifier:enumerate; 85, argument_list; 85, 86; 86, identifier:columns_order; 87, block; 87, 88; 87, 125; 88, expression_statement; 88, 89; 89, augmented_assignment:+=; 89, 90; 89, 91; 90, identifier:jscode; 91, binary_operator:%; 91, 92; 91, 93; 92, string:"%s.addColumn(%s, %s, %s);\n"; 93, tuple; 93, 94; 93, 95; 93, 105; 93, 115; 94, identifier:name; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:encoder; 98, identifier:encode; 99, argument_list; 99, 100; 100, subscript; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:col_dict; 103, identifier:col; 104, string:"type"; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:encoder; 108, identifier:encode; 109, argument_list; 109, 110; 110, subscript; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:col_dict; 113, identifier:col; 114, string:"label"; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:encoder; 118, identifier:encode; 119, argument_list; 119, 120; 120, subscript; 120, 121; 120, 124; 121, subscript; 121, 122; 121, 123; 122, identifier:col_dict; 123, identifier:col; 124, string:"id"; 125, if_statement; 125, 126; 125, 131; 126, subscript; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:col_dict; 129, identifier:col; 130, string:"custom_properties"; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, augmented_assignment:+=; 133, 134; 133, 135; 134, identifier:jscode; 135, binary_operator:%; 135, 136; 135, 137; 136, string:"%s.setColumnProperties(%d, %s);\n"; 137, tuple; 137, 138; 137, 139; 137, 140; 138, identifier:name; 139, identifier:i; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:encoder; 143, identifier:encode; 144, argument_list; 144, 145; 145, subscript; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:col_dict; 148, identifier:col; 149, string:"custom_properties"; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 153; 152, identifier:jscode; 153, binary_operator:%; 153, 154; 153, 155; 154, string:"%s.addRows(%d);\n"; 155, tuple; 155, 156; 155, 157; 156, identifier:name; 157, call; 157, 158; 157, 159; 158, identifier:len; 159, argument_list; 159, 160; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:__data; 163, for_statement; 163, 164; 163, 169; 163, 178; 164, tuple_pattern; 164, 165; 164, 166; 165, identifier:i; 166, tuple_pattern; 166, 167; 166, 168; 167, identifier:row; 168, identifier:cp; 169, call; 169, 170; 169, 171; 170, identifier:enumerate; 171, argument_list; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:_PreparedData; 176, argument_list; 176, 177; 177, identifier:order_by; 178, block; 178, 179; 178, 297; 179, for_statement; 179, 180; 179, 183; 179, 187; 180, tuple_pattern; 180, 181; 180, 182; 181, identifier:j; 182, identifier:col; 183, call; 183, 184; 183, 185; 184, identifier:enumerate; 185, argument_list; 185, 186; 186, identifier:columns_order; 187, block; 187, 188; 187, 200; 187, 216; 188, if_statement; 188, 189; 188, 198; 189, boolean_operator:or; 189, 190; 189, 193; 190, comparison_operator:not; 190, 191; 190, 192; 191, identifier:col; 192, identifier:row; 193, comparison_operator:is; 193, 194; 193, 197; 194, subscript; 194, 195; 194, 196; 195, identifier:row; 196, identifier:col; 197, None; 198, block; 198, 199; 199, continue_statement; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:value; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:CoerceValue; 207, argument_list; 207, 208; 207, 211; 208, subscript; 208, 209; 208, 210; 209, identifier:row; 210, identifier:col; 211, subscript; 211, 212; 211, 215; 212, subscript; 212, 213; 212, 214; 213, identifier:col_dict; 214, identifier:col; 215, string:"type"; 216, if_statement; 216, 217; 216, 222; 216, 279; 217, call; 217, 218; 217, 219; 218, identifier:isinstance; 219, argument_list; 219, 220; 219, 221; 220, identifier:value; 221, identifier:tuple; 222, block; 222, 223; 222, 227; 222, 250; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:cell_cp; 226, string:""; 227, if_statement; 227, 228; 227, 234; 228, comparison_operator:==; 228, 229; 228, 233; 229, call; 229, 230; 229, 231; 230, identifier:len; 231, argument_list; 231, 232; 232, identifier:value; 233, integer:3; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:cell_cp; 238, binary_operator:%; 238, 239; 238, 240; 239, string:", %s"; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:encoder; 243, identifier:encode; 244, argument_list; 244, 245; 245, subscript; 245, 246; 245, 249; 246, subscript; 246, 247; 246, 248; 247, identifier:row; 248, identifier:col; 249, integer:2; 250, expression_statement; 250, 251; 251, augmented_assignment:+=; 251, 252; 251, 253; 252, identifier:jscode; 253, parenthesized_expression; 253, 254; 254, binary_operator:%; 254, 255; 254, 256; 255, string:"%s.setCell(%d, %d, %s, %s%s);\n"; 256, tuple; 256, 257; 256, 258; 256, 259; 256, 260; 256, 269; 256, 278; 257, identifier:name; 258, identifier:i; 259, identifier:j; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:self; 263, identifier:EscapeForJSCode; 264, argument_list; 264, 265; 264, 266; 265, identifier:encoder; 266, subscript; 266, 267; 266, 268; 267, identifier:value; 268, integer:0; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:self; 272, identifier:EscapeForJSCode; 273, argument_list; 273, 274; 273, 275; 274, identifier:encoder; 275, subscript; 275, 276; 275, 277; 276, identifier:value; 277, integer:1; 278, identifier:cell_cp; 279, else_clause; 279, 280; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, augmented_assignment:+=; 282, 283; 282, 284; 283, identifier:jscode; 284, binary_operator:%; 284, 285; 284, 286; 285, string:"%s.setCell(%d, %d, %s);\n"; 286, tuple; 286, 287; 286, 288; 286, 289; 286, 290; 287, identifier:name; 288, identifier:i; 289, identifier:j; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:self; 293, identifier:EscapeForJSCode; 294, argument_list; 294, 295; 294, 296; 295, identifier:encoder; 296, identifier:value; 297, if_statement; 297, 298; 297, 299; 298, identifier:cp; 299, block; 299, 300; 300, expression_statement; 300, 301; 301, augmented_assignment:+=; 301, 302; 301, 303; 302, identifier:jscode; 303, binary_operator:%; 303, 304; 303, 305; 304, string:"%s.setRowProperties(%d, %s);\n"; 305, tuple; 305, 306; 305, 307; 305, 308; 306, identifier:name; 307, identifier:i; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:encoder; 311, identifier:encode; 312, argument_list; 312, 313; 313, identifier:cp; 314, return_statement; 314, 315; 315, identifier:jscode | def ToJSCode(self, name, columns_order=None, order_by=()):
encoder = DataTableJSONEncoder()
if columns_order is None:
columns_order = [col["id"] for col in self.__columns]
col_dict = dict([(col["id"], col) for col in self.__columns])
jscode = "var %s = new google.visualization.DataTable();\n" % name
if self.custom_properties:
jscode += "%s.setTableProperties(%s);\n" % (
name, encoder.encode(self.custom_properties))
for i, col in enumerate(columns_order):
jscode += "%s.addColumn(%s, %s, %s);\n" % (
name,
encoder.encode(col_dict[col]["type"]),
encoder.encode(col_dict[col]["label"]),
encoder.encode(col_dict[col]["id"]))
if col_dict[col]["custom_properties"]:
jscode += "%s.setColumnProperties(%d, %s);\n" % (
name, i, encoder.encode(col_dict[col]["custom_properties"]))
jscode += "%s.addRows(%d);\n" % (name, len(self.__data))
for (i, (row, cp)) in enumerate(self._PreparedData(order_by)):
for (j, col) in enumerate(columns_order):
if col not in row or row[col] is None:
continue
value = self.CoerceValue(row[col], col_dict[col]["type"])
if isinstance(value, tuple):
cell_cp = ""
if len(value) == 3:
cell_cp = ", %s" % encoder.encode(row[col][2])
jscode += ("%s.setCell(%d, %d, %s, %s%s);\n" %
(name, i, j,
self.EscapeForJSCode(encoder, value[0]),
self.EscapeForJSCode(encoder, value[1]), cell_cp))
else:
jscode += "%s.setCell(%d, %d, %s);\n" % (
name, i, j, self.EscapeForJSCode(encoder, value))
if cp:
jscode += "%s.setRowProperties(%d, %s);\n" % (
name, i, encoder.encode(cp))
return jscode |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:ToHtml; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:columns_order; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:order_by; 10, tuple; 11, block; 11, 12; 11, 16; 11, 20; 11, 24; 11, 28; 11, 32; 11, 36; 11, 53; 11, 70; 11, 74; 11, 96; 11, 107; 11, 111; 11, 224; 11, 235; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:table_template; 15, string:"<html><body><table border=\"1\">%s</table></body></html>"; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:columns_template; 19, string:"<thead><tr>%s</tr></thead>"; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:rows_template; 23, string:"<tbody>%s</tbody>"; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:row_template; 27, string:"<tr>%s</tr>"; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:header_cell_template; 31, string:"<th>%s</th>"; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:cell_template; 35, string:"<td>%s</td>"; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:columns_order; 39, None; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:columns_order; 44, list_comprehension; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:col; 47, string:"id"; 48, for_in_clause; 48, 49; 48, 50; 49, identifier:col; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:__columns; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:col_dict; 56, call; 56, 57; 56, 58; 57, identifier:dict; 58, argument_list; 58, 59; 59, list_comprehension; 59, 60; 59, 65; 60, tuple; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:col; 63, string:"id"; 64, identifier:col; 65, for_in_clause; 65, 66; 65, 67; 66, identifier:col; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:__columns; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:columns_list; 73, list:[]; 74, for_statement; 74, 75; 74, 76; 74, 77; 75, identifier:col; 76, identifier:columns_order; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:columns_list; 82, identifier:append; 83, argument_list; 83, 84; 84, binary_operator:%; 84, 85; 84, 86; 85, identifier:header_cell_template; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:html; 89, identifier:escape; 90, argument_list; 90, 91; 91, subscript; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:col_dict; 94, identifier:col; 95, string:"label"; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:columns_html; 99, binary_operator:%; 99, 100; 99, 101; 100, identifier:columns_template; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, string:""; 104, identifier:join; 105, argument_list; 105, 106; 106, identifier:columns_list; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:rows_list; 110, list:[]; 111, for_statement; 111, 112; 111, 115; 111, 121; 112, pattern_list; 112, 113; 112, 114; 113, identifier:row; 114, identifier:unused_cp; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:_PreparedData; 119, argument_list; 119, 120; 120, identifier:order_by; 121, block; 121, 122; 121, 126; 121, 210; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:cells_list; 125, list:[]; 126, for_statement; 126, 127; 126, 128; 126, 129; 127, identifier:col; 128, identifier:columns_order; 129, block; 129, 130; 129, 134; 129, 161; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:value; 133, string:""; 134, if_statement; 134, 135; 134, 144; 135, boolean_operator:and; 135, 136; 135, 139; 136, comparison_operator:in; 136, 137; 136, 138; 137, identifier:col; 138, identifier:row; 139, comparison_operator:is; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:row; 142, identifier:col; 143, None; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:value; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:CoerceValue; 152, argument_list; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:row; 155, identifier:col; 156, subscript; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:col_dict; 159, identifier:col; 160, string:"type"; 161, if_statement; 161, 162; 161, 167; 161, 189; 162, call; 162, 163; 162, 164; 163, identifier:isinstance; 164, argument_list; 164, 165; 164, 166; 165, identifier:value; 166, identifier:tuple; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:cells_list; 172, identifier:append; 173, argument_list; 173, 174; 174, binary_operator:%; 174, 175; 174, 176; 175, identifier:cell_template; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:html; 179, identifier:escape; 180, argument_list; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:ToString; 185, argument_list; 185, 186; 186, subscript; 186, 187; 186, 188; 187, identifier:value; 188, integer:1; 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:cells_list; 195, identifier:append; 196, argument_list; 196, 197; 197, binary_operator:%; 197, 198; 197, 199; 198, identifier:cell_template; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:html; 202, identifier:escape; 203, argument_list; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:ToString; 208, argument_list; 208, 209; 209, identifier:value; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:rows_list; 214, identifier:append; 215, argument_list; 215, 216; 216, binary_operator:%; 216, 217; 216, 218; 217, identifier:row_template; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, string:""; 221, identifier:join; 222, argument_list; 222, 223; 223, identifier:cells_list; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:rows_html; 227, binary_operator:%; 227, 228; 227, 229; 228, identifier:rows_template; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, string:""; 232, identifier:join; 233, argument_list; 233, 234; 234, identifier:rows_list; 235, return_statement; 235, 236; 236, binary_operator:%; 236, 237; 236, 238; 237, identifier:table_template; 238, parenthesized_expression; 238, 239; 239, binary_operator:+; 239, 240; 239, 241; 240, identifier:columns_html; 241, identifier:rows_html | def ToHtml(self, columns_order=None, order_by=()):
table_template = "<html><body><table border=\"1\">%s</table></body></html>"
columns_template = "<thead><tr>%s</tr></thead>"
rows_template = "<tbody>%s</tbody>"
row_template = "<tr>%s</tr>"
header_cell_template = "<th>%s</th>"
cell_template = "<td>%s</td>"
if columns_order is None:
columns_order = [col["id"] for col in self.__columns]
col_dict = dict([(col["id"], col) for col in self.__columns])
columns_list = []
for col in columns_order:
columns_list.append(header_cell_template %
html.escape(col_dict[col]["label"]))
columns_html = columns_template % "".join(columns_list)
rows_list = []
for row, unused_cp in self._PreparedData(order_by):
cells_list = []
for col in columns_order:
value = ""
if col in row and row[col] is not None:
value = self.CoerceValue(row[col], col_dict[col]["type"])
if isinstance(value, tuple):
cells_list.append(cell_template % html.escape(self.ToString(value[1])))
else:
cells_list.append(cell_template % html.escape(self.ToString(value)))
rows_list.append(row_template % "".join(cells_list))
rows_html = rows_template % "".join(rows_list)
return table_template % (columns_html + rows_html) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:ToCsv; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:columns_order; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:order_by; 10, tuple; 11, default_parameter; 11, 12; 11, 13; 12, identifier:separator; 13, string:","; 14, block; 14, 15; 14, 23; 14, 35; 14, 52; 14, 69; 14, 92; 14, 110; 14, 239; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:csv_buffer; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:six; 21, identifier:StringIO; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:writer; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:csv; 29, identifier:writer; 30, argument_list; 30, 31; 30, 32; 31, identifier:csv_buffer; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:delimiter; 34, identifier:separator; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:columns_order; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:columns_order; 43, list_comprehension; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:col; 46, string:"id"; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:col; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:__columns; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:col_dict; 55, call; 55, 56; 55, 57; 56, identifier:dict; 57, argument_list; 57, 58; 58, list_comprehension; 58, 59; 58, 64; 59, tuple; 59, 60; 59, 63; 60, subscript; 60, 61; 60, 62; 61, identifier:col; 62, string:"id"; 63, identifier:col; 64, for_in_clause; 64, 65; 64, 66; 65, identifier:col; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:__columns; 69, function_definition; 69, 70; 69, 71; 69, 73; 70, function_name:ensure_str; 71, parameters; 71, 72; 72, identifier:s; 73, block; 73, 74; 73, 76; 73, 85; 74, expression_statement; 74, 75; 75, string:"Compatibility function. Ensures using of str rather than unicode."; 76, if_statement; 76, 77; 76, 82; 77, call; 77, 78; 77, 79; 78, identifier:isinstance; 79, argument_list; 79, 80; 79, 81; 80, identifier:s; 81, identifier:str; 82, block; 82, 83; 83, return_statement; 83, 84; 84, identifier:s; 85, return_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:s; 89, identifier:encode; 90, argument_list; 90, 91; 91, string:"utf-8"; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:writer; 96, identifier:writerow; 97, argument_list; 97, 98; 98, list_comprehension; 98, 99; 98, 107; 99, call; 99, 100; 99, 101; 100, identifier:ensure_str; 101, argument_list; 101, 102; 102, subscript; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:col_dict; 105, identifier:col; 106, string:"label"; 107, for_in_clause; 107, 108; 107, 109; 108, identifier:col; 109, identifier:columns_order; 110, for_statement; 110, 111; 110, 114; 110, 120; 111, pattern_list; 111, 112; 111, 113; 112, identifier:row; 113, identifier:unused_cp; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:_PreparedData; 118, argument_list; 118, 119; 119, identifier:order_by; 120, block; 120, 121; 120, 125; 120, 232; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:cells_list; 124, list:[]; 125, for_statement; 125, 126; 125, 127; 125, 128; 126, identifier:col; 127, identifier:columns_order; 128, block; 128, 129; 128, 133; 128, 160; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:value; 132, string:""; 133, if_statement; 133, 134; 133, 143; 134, boolean_operator:and; 134, 135; 134, 138; 135, comparison_operator:in; 135, 136; 135, 137; 136, identifier:col; 137, identifier:row; 138, comparison_operator:is; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:row; 141, identifier:col; 142, None; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:value; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:CoerceValue; 151, argument_list; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:row; 154, identifier:col; 155, subscript; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:col_dict; 158, identifier:col; 159, string:"type"; 160, if_statement; 160, 161; 160, 166; 160, 215; 161, call; 161, 162; 161, 163; 162, identifier:isinstance; 163, argument_list; 163, 164; 163, 165; 164, identifier:value; 165, identifier:tuple; 166, block; 166, 167; 167, if_statement; 167, 168; 167, 178; 167, 196; 168, comparison_operator:in; 168, 169; 168, 174; 169, subscript; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:col_dict; 172, identifier:col; 173, string:"type"; 174, list:["date", "datetime", "timeofday"]; 174, 175; 174, 176; 174, 177; 175, string:"date"; 176, string:"datetime"; 177, string:"timeofday"; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:cells_list; 183, identifier:append; 184, argument_list; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:ensure_str; 187, argument_list; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:ToString; 192, argument_list; 192, 193; 193, subscript; 193, 194; 193, 195; 194, identifier:value; 195, integer:1; 196, else_clause; 196, 197; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:cells_list; 202, identifier:append; 203, argument_list; 203, 204; 204, call; 204, 205; 204, 206; 205, identifier:ensure_str; 206, argument_list; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:ToString; 211, argument_list; 211, 212; 212, subscript; 212, 213; 212, 214; 213, identifier:value; 214, integer:0; 215, else_clause; 215, 216; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:cells_list; 221, identifier:append; 222, argument_list; 222, 223; 223, call; 223, 224; 223, 225; 224, identifier:ensure_str; 225, argument_list; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:ToString; 230, argument_list; 230, 231; 231, identifier:value; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:writer; 236, identifier:writerow; 237, argument_list; 237, 238; 238, identifier:cells_list; 239, return_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:csv_buffer; 243, identifier:getvalue; 244, argument_list | def ToCsv(self, columns_order=None, order_by=(), separator=","):
csv_buffer = six.StringIO()
writer = csv.writer(csv_buffer, delimiter=separator)
if columns_order is None:
columns_order = [col["id"] for col in self.__columns]
col_dict = dict([(col["id"], col) for col in self.__columns])
def ensure_str(s):
"Compatibility function. Ensures using of str rather than unicode."
if isinstance(s, str):
return s
return s.encode("utf-8")
writer.writerow([ensure_str(col_dict[col]["label"])
for col in columns_order])
for row, unused_cp in self._PreparedData(order_by):
cells_list = []
for col in columns_order:
value = ""
if col in row and row[col] is not None:
value = self.CoerceValue(row[col], col_dict[col]["type"])
if isinstance(value, tuple):
if col_dict[col]["type"] in ["date", "datetime", "timeofday"]:
cells_list.append(ensure_str(self.ToString(value[1])))
else:
cells_list.append(ensure_str(self.ToString(value[0])))
else:
cells_list.append(ensure_str(self.ToString(value)))
writer.writerow(cells_list)
return csv_buffer.getvalue() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_ToJSonObj; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:columns_order; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:order_by; 10, tuple; 11, block; 11, 12; 11, 29; 11, 46; 11, 50; 11, 103; 11, 107; 11, 248; 11, 258; 11, 271; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:columns_order; 15, None; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:columns_order; 20, list_comprehension; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:col; 23, string:"id"; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:col; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:__columns; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:col_dict; 32, call; 32, 33; 32, 34; 33, identifier:dict; 34, argument_list; 34, 35; 35, list_comprehension; 35, 36; 35, 41; 36, tuple; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:col; 39, string:"id"; 40, identifier:col; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:col; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:__columns; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:col_objs; 49, list:[]; 50, for_statement; 50, 51; 50, 52; 50, 53; 51, identifier:col_id; 52, identifier:columns_order; 53, block; 53, 54; 53, 79; 53, 96; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:col_obj; 57, dictionary; 57, 58; 57, 65; 57, 72; 58, pair; 58, 59; 58, 60; 59, string:"id"; 60, subscript; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:col_dict; 63, identifier:col_id; 64, string:"id"; 65, pair; 65, 66; 65, 67; 66, string:"label"; 67, subscript; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:col_dict; 70, identifier:col_id; 71, string:"label"; 72, pair; 72, 73; 72, 74; 73, string:"type"; 74, subscript; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:col_dict; 77, identifier:col_id; 78, string:"type"; 79, if_statement; 79, 80; 79, 85; 80, subscript; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:col_dict; 83, identifier:col_id; 84, string:"custom_properties"; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:col_obj; 90, string:"p"; 91, subscript; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:col_dict; 94, identifier:col_id; 95, string:"custom_properties"; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:col_objs; 100, identifier:append; 101, argument_list; 101, 102; 102, identifier:col_obj; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:row_objs; 106, list:[]; 107, for_statement; 107, 108; 107, 111; 107, 117; 108, pattern_list; 108, 109; 108, 110; 109, identifier:row; 110, identifier:cp; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:_PreparedData; 115, argument_list; 115, 116; 116, identifier:order_by; 117, block; 117, 118; 117, 122; 117, 225; 117, 232; 117, 241; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:cell_objs; 121, list:[]; 122, for_statement; 122, 123; 122, 124; 122, 125; 123, identifier:col; 124, identifier:columns_order; 125, block; 125, 126; 125, 146; 125, 218; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:value; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:CoerceValue; 133, argument_list; 133, 134; 133, 141; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:row; 137, identifier:get; 138, argument_list; 138, 139; 138, 140; 139, identifier:col; 140, None; 141, subscript; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:col_dict; 144, identifier:col; 145, string:"type"; 146, if_statement; 146, 147; 146, 150; 146, 155; 146, 209; 147, comparison_operator:is; 147, 148; 147, 149; 148, identifier:value; 149, None; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:cell_obj; 154, None; 155, elif_clause; 155, 156; 155, 161; 156, call; 156, 157; 156, 158; 157, identifier:isinstance; 158, argument_list; 158, 159; 158, 160; 159, identifier:value; 160, identifier:tuple; 161, block; 161, 162; 161, 171; 161, 193; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:cell_obj; 165, dictionary; 165, 166; 166, pair; 166, 167; 166, 168; 167, string:"v"; 168, subscript; 168, 169; 168, 170; 169, identifier:value; 170, integer:0; 171, if_statement; 171, 172; 171, 184; 172, boolean_operator:and; 172, 173; 172, 179; 173, comparison_operator:>; 173, 174; 173, 178; 174, call; 174, 175; 174, 176; 175, identifier:len; 176, argument_list; 176, 177; 177, identifier:value; 178, integer:1; 179, comparison_operator:is; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:value; 182, integer:1; 183, None; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:cell_obj; 189, string:"f"; 190, subscript; 190, 191; 190, 192; 191, identifier:value; 192, integer:1; 193, if_statement; 193, 194; 193, 200; 194, comparison_operator:==; 194, 195; 194, 199; 195, call; 195, 196; 195, 197; 196, identifier:len; 197, argument_list; 197, 198; 198, identifier:value; 199, integer:3; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:cell_obj; 205, string:"p"; 206, subscript; 206, 207; 206, 208; 207, identifier:value; 208, integer:2; 209, else_clause; 209, 210; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:cell_obj; 214, dictionary; 214, 215; 215, pair; 215, 216; 215, 217; 216, string:"v"; 217, identifier:value; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:cell_objs; 222, identifier:append; 223, argument_list; 223, 224; 224, identifier:cell_obj; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:row_obj; 228, dictionary; 228, 229; 229, pair; 229, 230; 229, 231; 230, string:"c"; 231, identifier:cell_objs; 232, if_statement; 232, 233; 232, 234; 233, identifier:cp; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 240; 237, subscript; 237, 238; 237, 239; 238, identifier:row_obj; 239, string:"p"; 240, identifier:cp; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:row_objs; 245, identifier:append; 246, argument_list; 246, 247; 247, identifier:row_obj; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:json_obj; 251, dictionary; 251, 252; 251, 255; 252, pair; 252, 253; 252, 254; 253, string:"cols"; 254, identifier:col_objs; 255, pair; 255, 256; 255, 257; 256, string:"rows"; 257, identifier:row_objs; 258, if_statement; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:custom_properties; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:json_obj; 267, string:"p"; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:custom_properties; 271, return_statement; 271, 272; 272, identifier:json_obj | def _ToJSonObj(self, columns_order=None, order_by=()):
if columns_order is None:
columns_order = [col["id"] for col in self.__columns]
col_dict = dict([(col["id"], col) for col in self.__columns])
col_objs = []
for col_id in columns_order:
col_obj = {"id": col_dict[col_id]["id"],
"label": col_dict[col_id]["label"],
"type": col_dict[col_id]["type"]}
if col_dict[col_id]["custom_properties"]:
col_obj["p"] = col_dict[col_id]["custom_properties"]
col_objs.append(col_obj)
row_objs = []
for row, cp in self._PreparedData(order_by):
cell_objs = []
for col in columns_order:
value = self.CoerceValue(row.get(col, None), col_dict[col]["type"])
if value is None:
cell_obj = None
elif isinstance(value, tuple):
cell_obj = {"v": value[0]}
if len(value) > 1 and value[1] is not None:
cell_obj["f"] = value[1]
if len(value) == 3:
cell_obj["p"] = value[2]
else:
cell_obj = {"v": value}
cell_objs.append(cell_obj)
row_obj = {"c": cell_objs}
if cp:
row_obj["p"] = cp
row_objs.append(row_obj)
json_obj = {"cols": col_objs, "rows": row_objs}
if self.custom_properties:
json_obj["p"] = self.custom_properties
return json_obj |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:ToJSon; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:columns_order; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:order_by; 10, tuple; 11, block; 11, 12; 11, 29; 11, 44; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:encoded_response_str; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, call; 17, 18; 17, 19; 18, identifier:DataTableJSONEncoder; 19, argument_list; 20, identifier:encode; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:_ToJSonObj; 26, argument_list; 26, 27; 26, 28; 27, identifier:columns_order; 28, identifier:order_by; 29, if_statement; 29, 30; 29, 36; 30, not_operator; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:isinstance; 33, argument_list; 33, 34; 33, 35; 34, identifier:encoded_response_str; 35, identifier:str; 36, block; 36, 37; 37, return_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:encoded_response_str; 41, identifier:encode; 42, argument_list; 42, 43; 43, string:"utf-8"; 44, return_statement; 44, 45; 45, identifier:encoded_response_str | def ToJSon(self, columns_order=None, order_by=()):
encoded_response_str = DataTableJSONEncoder().encode(self._ToJSonObj(columns_order, order_by))
if not isinstance(encoded_response_str, str):
return encoded_response_str.encode("utf-8")
return encoded_response_str |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_radix_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:L; 5, default_parameter; 5, 6; 5, 7; 6, identifier:i; 7, integer:0; 8, block; 8, 9; 8, 19; 8, 23; 8, 34; 8, 69; 8, 83; 9, if_statement; 9, 10; 9, 16; 10, comparison_operator:<=; 10, 11; 10, 15; 11, call; 11, 12; 11, 13; 12, identifier:len; 13, argument_list; 13, 14; 14, identifier:L; 15, integer:1; 16, block; 16, 17; 17, return_statement; 17, 18; 18, identifier:L; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:done_bucket; 22, list:[]; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:buckets; 26, list_comprehension; 26, 27; 26, 28; 27, list:[]; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:x; 30, call; 30, 31; 30, 32; 31, identifier:range; 32, argument_list; 32, 33; 33, integer:255; 34, for_statement; 34, 35; 34, 36; 34, 37; 35, identifier:s; 36, identifier:L; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 45; 38, 53; 39, comparison_operator:>=; 39, 40; 39, 41; 40, identifier:i; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:s; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:done_bucket; 50, identifier:append; 51, argument_list; 51, 52; 52, identifier:s; 53, else_clause; 53, 54; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 67; 57, attribute; 57, 58; 57, 66; 58, subscript; 58, 59; 58, 60; 59, identifier:buckets; 60, call; 60, 61; 60, 62; 61, identifier:ord; 62, argument_list; 62, 63; 63, subscript; 63, 64; 63, 65; 64, identifier:s; 65, identifier:i; 66, identifier:append; 67, argument_list; 67, 68; 68, identifier:s; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:buckets; 72, list_comprehension; 72, 73; 72, 80; 73, call; 73, 74; 73, 75; 74, identifier:_radix_sort; 75, argument_list; 75, 76; 75, 77; 76, identifier:b; 77, binary_operator:+; 77, 78; 77, 79; 78, identifier:i; 79, integer:1; 80, for_in_clause; 80, 81; 80, 82; 81, identifier:b; 82, identifier:buckets; 83, return_statement; 83, 84; 84, binary_operator:+; 84, 85; 84, 86; 85, identifier:done_bucket; 86, list_comprehension; 86, 87; 86, 88; 86, 91; 87, identifier:b; 88, for_in_clause; 88, 89; 88, 90; 89, identifier:blist; 90, identifier:buckets; 91, for_in_clause; 91, 92; 91, 93; 92, identifier:b; 93, identifier:blist | def _radix_sort(L, i=0):
if len(L) <= 1:
return L
done_bucket = []
buckets = [ [] for x in range(255) ]
for s in L:
if i >= len(s):
done_bucket.append(s)
else:
buckets[ ord(s[i]) ].append(s)
buckets = [ _radix_sort(b, i + 1) for b in buckets ]
return done_bucket + [ b for blist in buckets for b in blist ] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:fixed_legend_filter_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:fixed_legend_filter_sort; 6, block; 6, 7; 6, 13; 6, 29; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:allowed_values; 10, list:["TOP", "BOTTOM"]; 10, 11; 10, 12; 11, string:"TOP"; 12, string:"BOTTOM"; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:not; 14, 15; 14, 16; 15, identifier:fixed_legend_filter_sort; 16, identifier:allowed_values; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:ValueError; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, string:"Invalid value for `fixed_legend_filter_sort` ({0}), must be one of {1}"; 25, identifier:format; 26, argument_list; 26, 27; 26, 28; 27, identifier:fixed_legend_filter_sort; 28, identifier:allowed_values; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_fixed_legend_filter_sort; 34, identifier:fixed_legend_filter_sort | def fixed_legend_filter_sort(self, fixed_legend_filter_sort):
allowed_values = ["TOP", "BOTTOM"]
if fixed_legend_filter_sort not in allowed_values:
raise ValueError(
"Invalid value for `fixed_legend_filter_sort` ({0}), must be one of {1}"
.format(fixed_legend_filter_sort, allowed_values)
)
self._fixed_legend_filter_sort = fixed_legend_filter_sort |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:print_table; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:title; 5, identifier:headers; 6, identifier:rows; 7, default_parameter; 7, 8; 7, 9; 8, identifier:sort_columns; 9, None; 10, block; 10, 11; 10, 64; 10, 81; 10, 95; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:sort_columns; 14, None; 15, block; 15, 16; 16, if_statement; 16, 17; 16, 22; 16, 36; 16, 59; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:sort_columns; 21, identifier:int; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:rows; 26, call; 26, 27; 26, 28; 27, identifier:sorted; 28, argument_list; 28, 29; 28, 30; 29, identifier:rows; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:key; 32, call; 32, 33; 32, 34; 33, identifier:itemgetter; 34, argument_list; 34, 35; 35, identifier:sort_columns; 36, elif_clause; 36, 37; 36, 44; 37, call; 37, 38; 37, 39; 38, identifier:isinstance; 39, argument_list; 39, 40; 39, 41; 40, identifier:sort_columns; 41, tuple; 41, 42; 41, 43; 42, identifier:list; 43, identifier:tuple; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:rows; 48, call; 48, 49; 48, 50; 49, identifier:sorted; 50, argument_list; 50, 51; 50, 52; 51, identifier:rows; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:key; 54, call; 54, 55; 54, 56; 55, identifier:itemgetter; 56, argument_list; 56, 57; 57, list_splat; 57, 58; 58, identifier:sort_columns; 59, else_clause; 59, 60; 60, block; 60, 61; 61, assert_statement; 61, 62; 61, 63; 62, False; 63, string:"Sort_columns must be int or list/tuple of int"; 64, if_statement; 64, 65; 64, 66; 64, 74; 65, identifier:title; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:print; 70, argument_list; 70, 71; 71, binary_operator:%; 71, 72; 71, 73; 72, string:'\n%s:'; 73, identifier:title; 74, else_clause; 74, 75; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:print; 79, argument_list; 79, 80; 80, string:''; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:print; 84, argument_list; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:tabulate; 88, identifier:tabulate; 89, argument_list; 89, 90; 89, 91; 89, 92; 90, identifier:rows; 91, identifier:headers; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:tablefmt; 94, string:'simple'; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:print; 98, argument_list; 98, 99; 99, string:'' | def print_table(title, headers, rows, sort_columns=None):
if sort_columns is not None:
if isinstance(sort_columns, int):
rows = sorted(rows, key=itemgetter(sort_columns))
elif isinstance(sort_columns, (list, tuple)):
rows = sorted(rows, key=itemgetter(*sort_columns))
else:
assert False, "Sort_columns must be int or list/tuple of int"
if title:
print('\n%s:' % title)
else:
print('')
print(tabulate.tabulate(rows, headers, tablefmt='simple'))
print('') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:formatted; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 96; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:ret; 9, string:"Statistics (times in seconds, lengths in Bytes):\n"; 10, if_statement; 10, 11; 10, 14; 10, 90; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:enabled; 14, block; 14, 15; 14, 39; 14, 43; 14, 58; 14, 75; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:snapshot; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 20, 26; 20, 36; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:snapshot; 25, argument_list; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:key; 28, lambda; 28, 29; 28, 31; 29, lambda_parameters; 29, 30; 30, identifier:item; 31, attribute; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:item; 34, integer:1; 35, identifier:avg_time; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:reverse; 38, True; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:include_svr; 42, False; 43, for_statement; 43, 44; 43, 47; 43, 48; 44, pattern_list; 44, 45; 44, 46; 45, identifier:name; 46, identifier:stats; 47, identifier:snapshot; 48, block; 48, 49; 49, if_statement; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:stats; 52, identifier:_server_time_stored; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:include_svr; 57, True; 58, if_statement; 58, 59; 58, 60; 58, 67; 59, identifier:include_svr; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, augmented_assignment:+=; 62, 63; 62, 64; 63, identifier:ret; 64, attribute; 64, 65; 64, 66; 65, identifier:OperationStatistic; 66, identifier:_formatted_header_w_svr; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, augmented_assignment:+=; 70, 71; 70, 72; 71, identifier:ret; 72, attribute; 72, 73; 72, 74; 73, identifier:OperationStatistic; 74, identifier:_formatted_header; 75, for_statement; 75, 76; 75, 79; 75, 80; 76, pattern_list; 76, 77; 76, 78; 77, identifier:name; 78, identifier:stats; 79, identifier:snapshot; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, augmented_assignment:+=; 82, 83; 82, 84; 83, identifier:ret; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:stats; 87, identifier:formatted; 88, argument_list; 88, 89; 89, identifier:include_svr; 90, else_clause; 90, 91; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, augmented_assignment:+=; 93, 94; 93, 95; 94, identifier:ret; 95, string:"Disabled"; 96, return_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:ret; 100, identifier:strip; 101, argument_list | def formatted(self):
ret = "Statistics (times in seconds, lengths in Bytes):\n"
if self.enabled:
snapshot = sorted(self.snapshot(),
key=lambda item: item[1].avg_time,
reverse=True)
include_svr = False
for name, stats in snapshot:
if stats._server_time_stored:
include_svr = True
if include_svr:
ret += OperationStatistic._formatted_header_w_svr
else:
ret += OperationStatistic._formatted_header
for name, stats in snapshot:
ret += stats.formatted(include_svr)
else:
ret += "Disabled"
return ret.strip() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_clusters; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:platform; 6, identifier:retry_contexts; 7, identifier:all_clusters; 8, block; 8, 9; 8, 11; 8, 15; 8, 27; 8, 120; 8, 141; 8, 156; 9, expression_statement; 9, 10; 10, string:''' return clusters sorted by load. '''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:possible_cluster_info; 14, dictionary; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:candidates; 18, call; 18, 19; 18, 20; 19, identifier:set; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:copy; 24, identifier:copy; 25, argument_list; 25, 26; 26, identifier:all_clusters; 27, while_statement; 27, 28; 27, 32; 28, boolean_operator:and; 28, 29; 28, 30; 29, identifier:candidates; 30, not_operator; 30, 31; 31, identifier:possible_cluster_info; 32, block; 32, 33; 32, 38; 32, 101; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:wait_for_any_cluster; 36, argument_list; 36, 37; 37, identifier:retry_contexts; 38, for_statement; 38, 39; 38, 40; 38, 50; 39, identifier:cluster; 40, call; 40, 41; 40, 42; 41, identifier:sorted; 42, argument_list; 42, 43; 42, 44; 43, identifier:candidates; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:key; 46, call; 46, 47; 46, 48; 47, identifier:attrgetter; 48, argument_list; 48, 49; 49, string:'priority'; 50, block; 50, 51; 50, 59; 50, 65; 50, 71; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:ctx; 54, subscript; 54, 55; 54, 56; 55, identifier:retry_contexts; 56, attribute; 56, 57; 56, 58; 57, identifier:cluster; 58, identifier:name; 59, if_statement; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:ctx; 62, identifier:in_retry_wait; 63, block; 63, 64; 64, continue_statement; 65, if_statement; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:ctx; 68, identifier:failed; 69, block; 69, 70; 70, continue_statement; 71, try_statement; 71, 72; 71, 89; 72, block; 72, 73; 72, 83; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:cluster_info; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:get_cluster_info; 80, argument_list; 80, 81; 80, 82; 81, identifier:cluster; 82, identifier:platform; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:possible_cluster_info; 87, identifier:cluster; 88, identifier:cluster_info; 89, except_clause; 89, 90; 89, 91; 90, identifier:OsbsException; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:ctx; 96, identifier:try_again_later; 97, argument_list; 97, 98; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:find_cluster_retry_delay; 101, expression_statement; 101, 102; 102, augmented_assignment:-=; 102, 103; 102, 104; 103, identifier:candidates; 104, call; 104, 105; 104, 106; 105, identifier:set; 106, argument_list; 106, 107; 107, list_comprehension; 107, 108; 107, 109; 107, 112; 108, identifier:c; 109, for_in_clause; 109, 110; 109, 111; 110, identifier:c; 111, identifier:candidates; 112, if_clause; 112, 113; 113, attribute; 113, 114; 113, 119; 114, subscript; 114, 115; 114, 116; 115, identifier:retry_contexts; 116, attribute; 116, 117; 116, 118; 117, identifier:c; 118, identifier:name; 119, identifier:failed; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:ret; 123, call; 123, 124; 123, 125; 124, identifier:sorted; 125, argument_list; 125, 126; 125, 131; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:possible_cluster_info; 129, identifier:values; 130, argument_list; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:key; 133, lambda; 133, 134; 133, 136; 134, lambda_parameters; 134, 135; 135, identifier:c; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:c; 139, identifier:cluster; 140, identifier:priority; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:ret; 144, call; 144, 145; 144, 146; 145, identifier:sorted; 146, argument_list; 146, 147; 146, 148; 147, identifier:ret; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:key; 150, lambda; 150, 151; 150, 153; 151, lambda_parameters; 151, 152; 152, identifier:c; 153, attribute; 153, 154; 153, 155; 154, identifier:c; 155, identifier:load; 156, return_statement; 156, 157; 157, identifier:ret | def get_clusters(self, platform, retry_contexts, all_clusters):
''' return clusters sorted by load. '''
possible_cluster_info = {}
candidates = set(copy.copy(all_clusters))
while candidates and not possible_cluster_info:
wait_for_any_cluster(retry_contexts)
for cluster in sorted(candidates, key=attrgetter('priority')):
ctx = retry_contexts[cluster.name]
if ctx.in_retry_wait:
continue
if ctx.failed:
continue
try:
cluster_info = self.get_cluster_info(cluster, platform)
possible_cluster_info[cluster] = cluster_info
except OsbsException:
ctx.try_again_later(self.find_cluster_retry_delay)
candidates -= set([c for c in candidates if retry_contexts[c.name].failed])
ret = sorted(possible_cluster_info.values(), key=lambda c: c.cluster.priority)
ret = sorted(ret, key=lambda c: c.load)
return ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 1, 20; 2, function_name:get_profile_names_and_default; 3, parameters; 4, type; 4, 5; 5, parenthesized_expression; 5, 6; 6, subscript; 6, 7; 6, 10; 6, 15; 7, attribute; 7, 8; 7, 9; 8, identifier:typing; 9, identifier:Tuple; 10, subscript; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:typing; 13, identifier:Sequence; 14, identifier:str; 15, subscript; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:typing; 18, identifier:Optional; 19, identifier:Profile; 20, block; 20, 21; 21, with_statement; 21, 22; 21, 32; 22, with_clause; 22, 23; 23, with_item; 23, 24; 24, as_pattern; 24, 25; 24, 30; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:ProfileStore; 28, identifier:open; 29, argument_list; 30, as_pattern_target; 30, 31; 31, identifier:config; 32, block; 32, 33; 33, return_statement; 33, 34; 34, expression_list; 34, 35; 34, 39; 35, call; 35, 36; 35, 37; 36, identifier:sorted; 37, argument_list; 37, 38; 38, identifier:config; 39, attribute; 39, 40; 39, 41; 40, identifier:config; 41, identifier:default | def get_profile_names_and_default() -> (
typing.Tuple[typing.Sequence[str], typing.Optional[Profile]]):
with ProfileStore.open() as config:
return sorted(config), config.default |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:print_all_commands; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, keyword_separator; 6, default_parameter; 6, 7; 6, 8; 7, identifier:no_pager; 8, False; 9, block; 9, 10; 9, 20; 9, 37; 9, 53; 9, 57; 9, 174; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:formatter; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:parent_parser; 18, identifier:_get_formatter; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:command_names; 23, call; 23, 24; 23, 25; 24, identifier:sorted; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 36; 27, attribute; 27, 28; 27, 35; 28, attribute; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:parent_parser; 33, identifier:subparsers; 34, identifier:choices; 35, identifier:keys; 36, argument_list; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:max_name_len; 40, binary_operator:+; 40, 41; 40, 52; 41, call; 41, 42; 41, 43; 42, identifier:max; 43, argument_list; 43, 44; 44, list_comprehension; 44, 45; 44, 49; 45, call; 45, 46; 45, 47; 46, identifier:len; 47, argument_list; 47, 48; 48, identifier:name; 49, for_in_clause; 49, 50; 49, 51; 50, identifier:name; 51, identifier:command_names; 52, integer:1; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:commands; 56, string:""; 57, for_statement; 57, 58; 57, 59; 57, 60; 58, identifier:name; 59, identifier:command_names; 60, block; 60, 61; 60, 73; 60, 82; 60, 95; 60, 165; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:command; 64, subscript; 64, 65; 64, 72; 65, attribute; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:parent_parser; 70, identifier:subparsers; 71, identifier:choices; 72, identifier:name; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:extra_padding; 76, binary_operator:-; 76, 77; 76, 78; 77, identifier:max_name_len; 78, call; 78, 79; 78, 80; 79, identifier:len; 80, argument_list; 80, 81; 81, identifier:name; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:command_line; 85, binary_operator:%; 85, 86; 85, 87; 86, string:'%s%s%s'; 87, tuple; 87, 88; 87, 89; 87, 92; 88, identifier:name; 89, binary_operator:*; 89, 90; 89, 91; 90, string:' '; 91, identifier:extra_padding; 92, attribute; 92, 93; 92, 94; 93, identifier:command; 94, identifier:description; 95, while_statement; 95, 96; 95, 104; 96, comparison_operator:>; 96, 97; 96, 101; 97, call; 97, 98; 97, 99; 98, identifier:len; 99, argument_list; 99, 100; 100, identifier:command_line; 101, attribute; 101, 102; 101, 103; 102, identifier:formatter; 103, identifier:_width; 104, block; 104, 105; 104, 117; 104, 125; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:lines; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:textwrap; 111, identifier:wrap; 112, argument_list; 112, 113; 112, 114; 113, identifier:command_line; 114, attribute; 114, 115; 114, 116; 115, identifier:formatter; 116, identifier:_width; 117, expression_statement; 117, 118; 118, augmented_assignment:+=; 118, 119; 118, 120; 119, identifier:commands; 120, binary_operator:%; 120, 121; 120, 122; 121, string:"%s\n"; 122, subscript; 122, 123; 122, 124; 123, identifier:lines; 124, integer:0; 125, if_statement; 125, 126; 125, 132; 125, 159; 126, comparison_operator:>; 126, 127; 126, 131; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, identifier:lines; 131, integer:1; 132, block; 132, 133; 132, 146; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:lines; 137, integer:1; 138, binary_operator:+; 138, 139; 138, 143; 139, parenthesized_expression; 139, 140; 140, binary_operator:*; 140, 141; 140, 142; 141, string:' '; 142, identifier:max_name_len; 143, subscript; 143, 144; 143, 145; 144, identifier:lines; 145, integer:1; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:command_line; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, string:' '; 152, identifier:join; 153, argument_list; 153, 154; 154, subscript; 154, 155; 154, 156; 155, identifier:lines; 156, slice; 156, 157; 156, 158; 157, integer:1; 158, colon; 159, else_clause; 159, 160; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:command_line; 164, None; 165, if_statement; 165, 166; 165, 167; 166, identifier:command_line; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:commands; 171, binary_operator:%; 171, 172; 171, 173; 172, string:"%s\n"; 173, identifier:command_line; 174, if_statement; 174, 175; 174, 176; 174, 187; 175, identifier:no_pager; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:print; 180, argument_list; 180, 181; 181, subscript; 181, 182; 181, 183; 182, identifier:commands; 183, slice; 183, 184; 183, 185; 184, colon; 185, unary_operator:-; 185, 186; 186, integer:1; 187, else_clause; 187, 188; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:print_with_pager; 192, argument_list; 192, 193; 193, subscript; 193, 194; 193, 195; 194, identifier:commands; 195, slice; 195, 196; 195, 197; 196, colon; 197, unary_operator:-; 197, 198; 198, integer:1 | def print_all_commands(self, *, no_pager=False):
formatter = self.parent_parser._get_formatter()
command_names = sorted(self.parent_parser.subparsers.choices.keys())
max_name_len = max([len(name) for name in command_names]) + 1
commands = ""
for name in command_names:
command = self.parent_parser.subparsers.choices[name]
extra_padding = max_name_len - len(name)
command_line = '%s%s%s' % (
name, ' ' * extra_padding, command.description)
while len(command_line) > formatter._width:
lines = textwrap.wrap(command_line, formatter._width)
commands += "%s\n" % lines[0]
if len(lines) > 1:
lines[1] = (' ' * max_name_len) + lines[1]
command_line = ' '.join(lines[1:])
else:
command_line = None
if command_line:
commands += "%s\n" % command_line
if no_pager:
print(commands[:-1])
else:
print_with_pager(commands[:-1]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:rank_dated_files; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:pattern; 5, identifier:dir; 6, default_parameter; 6, 7; 6, 8; 7, identifier:descending; 8, True; 9, block; 9, 10; 9, 25; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:files; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:glob; 16, identifier:glob; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:op; 21, identifier:join; 22, argument_list; 22, 23; 22, 24; 23, identifier:dir; 24, identifier:pattern; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:sorted; 28, argument_list; 28, 29; 28, 30; 29, identifier:files; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:reverse; 32, identifier:descending | def rank_dated_files(pattern, dir, descending=True):
files = glob.glob(op.join(dir, pattern))
return sorted(files, reverse=descending) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:best_structures; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:uniprot_id; 5, default_parameter; 5, 6; 5, 7; 6, identifier:outname; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:outdir; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:seq_ident_cutoff; 13, float:0.0; 14, default_parameter; 14, 15; 14, 16; 15, identifier:force_rerun; 16, False; 17, block; 17, 18; 17, 22; 17, 30; 17, 40; 17, 62; 17, 216; 17, 225; 17, 248; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:outfile; 21, string:''; 22, if_statement; 22, 23; 22, 25; 23, not_operator; 23, 24; 24, identifier:outdir; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:outdir; 29, string:''; 30, if_statement; 30, 31; 30, 35; 31, boolean_operator:and; 31, 32; 31, 34; 32, not_operator; 32, 33; 33, identifier:outname; 34, identifier:outdir; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:outname; 39, identifier:uniprot_id; 40, if_statement; 40, 41; 40, 42; 41, identifier:outname; 42, block; 42, 43; 42, 53; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:outname; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:op; 49, identifier:join; 50, argument_list; 50, 51; 50, 52; 51, identifier:outdir; 52, identifier:outname; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:outfile; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, string:'{}.json'; 59, identifier:format; 60, argument_list; 60, 61; 61, identifier:outname; 62, if_statement; 62, 63; 62, 77; 62, 111; 63, not_operator; 63, 64; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:ssbio; 68, identifier:utils; 69, identifier:force_rerun; 70, argument_list; 70, 71; 70, 74; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:flag; 73, identifier:force_rerun; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:outfile; 76, identifier:outfile; 77, block; 77, 78; 77, 99; 78, with_statement; 78, 79; 78, 89; 79, with_clause; 79, 80; 80, with_item; 80, 81; 81, as_pattern; 81, 82; 81, 87; 82, call; 82, 83; 82, 84; 83, identifier:open; 84, argument_list; 84, 85; 84, 86; 85, identifier:outfile; 86, string:'r'; 87, as_pattern_target; 87, 88; 88, identifier:f; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:raw_data; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:json; 96, identifier:load; 97, argument_list; 97, 98; 98, identifier:f; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:log; 103, identifier:debug; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, string:'{}: loaded existing json file'; 108, identifier:format; 109, argument_list; 109, 110; 110, identifier:uniprot_id; 111, else_clause; 111, 112; 112, block; 112, 113; 112, 133; 112, 181; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:response; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:requests; 119, identifier:get; 120, argument_list; 120, 121; 120, 127; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, string:'https://www.ebi.ac.uk/pdbe/api/mappings/best_structures/{}'; 124, identifier:format; 125, argument_list; 125, 126; 126, identifier:uniprot_id; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:data; 129, dictionary; 129, 130; 130, pair; 130, 131; 130, 132; 131, string:'key'; 132, string:'value'; 133, if_statement; 133, 134; 133, 139; 133, 159; 134, comparison_operator:==; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:response; 137, identifier:status_code; 138, integer:404; 139, block; 139, 140; 139, 152; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:log; 144, identifier:debug; 145, argument_list; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, string:'{}: 404 returned, probably no structures available.'; 149, identifier:format; 150, argument_list; 150, 151; 151, identifier:uniprot_id; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:raw_data; 155, dictionary; 155, 156; 156, pair; 156, 157; 156, 158; 157, identifier:uniprot_id; 158, dictionary; 159, else_clause; 159, 160; 160, block; 160, 161; 160, 173; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:log; 165, identifier:debug; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, string:'{}: Obtained best structures'; 170, identifier:format; 171, argument_list; 171, 172; 172, identifier:uniprot_id; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:raw_data; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:response; 179, identifier:json; 180, argument_list; 181, if_statement; 181, 182; 181, 183; 182, identifier:outfile; 183, block; 183, 184; 183, 204; 184, with_statement; 184, 185; 184, 195; 185, with_clause; 185, 186; 186, with_item; 186, 187; 187, as_pattern; 187, 188; 187, 193; 188, call; 188, 189; 188, 190; 189, identifier:open; 190, argument_list; 190, 191; 190, 192; 191, identifier:outfile; 192, string:'w'; 193, as_pattern_target; 193, 194; 194, identifier:f; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:json; 200, identifier:dump; 201, argument_list; 201, 202; 201, 203; 202, identifier:raw_data; 203, identifier:f; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:log; 208, identifier:debug; 209, argument_list; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, string:'{}: Saved json file of best structures'; 213, identifier:format; 214, argument_list; 214, 215; 215, identifier:uniprot_id; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:data; 219, subscript; 219, 220; 219, 224; 220, call; 220, 221; 220, 222; 221, identifier:dict; 222, argument_list; 222, 223; 223, identifier:raw_data; 224, identifier:uniprot_id; 225, if_statement; 225, 226; 225, 229; 226, comparison_operator:!=; 226, 227; 226, 228; 227, identifier:seq_ident_cutoff; 228, integer:0; 229, block; 229, 230; 230, for_statement; 230, 231; 230, 232; 230, 233; 231, identifier:result; 232, identifier:data; 233, block; 233, 234; 234, if_statement; 234, 235; 234, 240; 235, comparison_operator:<; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:result; 238, string:'coverage'; 239, identifier:seq_ident_cutoff; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:data; 245, identifier:remove; 246, argument_list; 246, 247; 247, identifier:result; 248, return_statement; 248, 249; 249, identifier:data | def best_structures(uniprot_id, outname=None, outdir=None, seq_ident_cutoff=0.0, force_rerun=False):
outfile = ''
if not outdir:
outdir = ''
if not outname and outdir:
outname = uniprot_id
if outname:
outname = op.join(outdir, outname)
outfile = '{}.json'.format(outname)
if not ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
with open(outfile, 'r') as f:
raw_data = json.load(f)
log.debug('{}: loaded existing json file'.format(uniprot_id))
else:
response = requests.get('https://www.ebi.ac.uk/pdbe/api/mappings/best_structures/{}'.format(uniprot_id),
data={'key': 'value'})
if response.status_code == 404:
log.debug('{}: 404 returned, probably no structures available.'.format(uniprot_id))
raw_data = {uniprot_id: {}}
else:
log.debug('{}: Obtained best structures'.format(uniprot_id))
raw_data = response.json()
if outfile:
with open(outfile, 'w') as f:
json.dump(raw_data, f)
log.debug('{}: Saved json file of best structures'.format(uniprot_id))
data = dict(raw_data)[uniprot_id]
if seq_ident_cutoff != 0:
for result in data:
if result['coverage'] < seq_ident_cutoff:
data.remove(result)
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:map_uniprot_to_pdb; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:seq_ident_cutoff; 7, float:0.0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:outdir; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:force_rerun; 13, False; 14, block; 14, 15; 14, 37; 14, 45; 14, 65; 14, 95; 14, 114; 14, 147; 14, 151; 14, 308; 15, if_statement; 15, 16; 15, 20; 16, not_operator; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:representative_sequence; 20, block; 20, 21; 20, 35; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:log; 25, identifier:error; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, string:'{}: no representative sequence set, cannot use best structures API'; 30, identifier:format; 31, argument_list; 31, 32; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:id; 35, return_statement; 35, 36; 36, None; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:uniprot_id; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:representative_sequence; 44, identifier:uniprot; 45, if_statement; 45, 46; 45, 48; 46, not_operator; 46, 47; 47, identifier:uniprot_id; 48, block; 48, 49; 48, 63; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:log; 53, identifier:error; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, string:'{}: no representative UniProt ID set, cannot use best structures API'; 58, identifier:format; 59, argument_list; 59, 60; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:id; 63, return_statement; 63, 64; 64, None; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:in; 66, 67; 66, 68; 67, string:'-'; 68, identifier:uniprot_id; 69, block; 69, 70; 69, 84; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:log; 74, identifier:debug; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, string:'{}: "-" detected in UniProt ID, isoform specific sequences are ignored with best structures API'; 79, identifier:format; 80, argument_list; 80, 81; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:id; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:uniprot_id; 87, subscript; 87, 88; 87, 94; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:uniprot_id; 91, identifier:split; 92, argument_list; 92, 93; 93, string:'-'; 94, integer:0; 95, if_statement; 95, 96; 95, 98; 96, not_operator; 96, 97; 97, identifier:outdir; 98, block; 98, 99; 98, 105; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:outdir; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:sequence_dir; 105, if_statement; 105, 106; 105, 108; 106, not_operator; 106, 107; 107, identifier:outdir; 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:'Output directory must be specified'; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:best_structures; 117, call; 117, 118; 117, 125; 118, attribute; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:ssbio; 122, identifier:databases; 123, identifier:pdb; 124, identifier:best_structures; 125, argument_list; 125, 126; 125, 127; 125, 138; 125, 141; 125, 144; 126, identifier:uniprot_id; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:outname; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, string:'{}_best_structures'; 132, identifier:format; 133, argument_list; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:custom_slugify; 136, argument_list; 136, 137; 137, identifier:uniprot_id; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:outdir; 140, identifier:outdir; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:seq_ident_cutoff; 143, identifier:seq_ident_cutoff; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:force_rerun; 146, identifier:force_rerun; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:new_pdbs; 150, list:[]; 151, if_statement; 151, 152; 151, 153; 151, 291; 152, identifier:best_structures; 153, block; 153, 154; 153, 158; 153, 272; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:rank; 157, integer:1; 158, for_statement; 158, 159; 158, 160; 158, 161; 159, identifier:best_structure; 160, identifier:best_structures; 161, block; 161, 162; 161, 175; 161, 182; 161, 191; 161, 205; 161, 212; 161, 218; 161, 227; 161, 237; 161, 248; 161, 258; 161, 268; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:currpdb; 165, call; 165, 166; 165, 167; 166, identifier:str; 167, argument_list; 167, 168; 168, call; 168, 169; 168, 174; 169, attribute; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:best_structure; 172, string:'pdb_id'; 173, identifier:lower; 174, argument_list; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:new_pdbs; 179, identifier:append; 180, argument_list; 180, 181; 181, identifier:currpdb; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:currchain; 185, call; 185, 186; 185, 187; 186, identifier:str; 187, argument_list; 187, 188; 188, subscript; 188, 189; 188, 190; 189, identifier:best_structure; 190, string:'chain_id'; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:new_pdb; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:load_pdb; 198, argument_list; 198, 199; 198, 202; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:pdb_id; 201, identifier:currpdb; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:mapped_chains; 204, identifier:currchain; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:new_pdb; 209, identifier:add_chain_ids; 210, argument_list; 210, 211; 211, identifier:currchain; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:pdb_specific_keys; 215, list:['experimental_method', 'resolution']; 215, 216; 215, 217; 216, string:'experimental_method'; 217, string:'resolution'; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:chain_specific_keys; 221, list:['coverage', 'start', 'end', 'unp_start', 'unp_end']; 221, 222; 221, 223; 221, 224; 221, 225; 221, 226; 222, string:'coverage'; 223, string:'start'; 224, string:'end'; 225, string:'unp_start'; 226, string:'unp_end'; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:new_pdb; 231, identifier:update; 232, argument_list; 232, 233; 232, 234; 233, identifier:best_structure; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:only_keys; 236, identifier:pdb_specific_keys; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:new_chain; 240, call; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:new_pdb; 244, identifier:chains; 245, identifier:get_by_id; 246, argument_list; 246, 247; 247, identifier:currchain; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:new_chain; 252, identifier:update; 253, argument_list; 253, 254; 253, 255; 254, identifier:best_structure; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:only_keys; 257, identifier:chain_specific_keys; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:new_chain; 262, identifier:update; 263, argument_list; 263, 264; 264, dictionary; 264, 265; 265, pair; 265, 266; 265, 267; 266, string:'rank'; 267, identifier:rank; 268, expression_statement; 268, 269; 269, augmented_assignment:+=; 269, 270; 269, 271; 270, identifier:rank; 271, integer:1; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:log; 276, identifier:debug; 277, argument_list; 277, 278; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, string:'{}, {}: {} PDB/chain pairs mapped'; 281, identifier:format; 282, argument_list; 282, 283; 282, 286; 282, 287; 283, attribute; 283, 284; 283, 285; 284, identifier:self; 285, identifier:id; 286, identifier:uniprot_id; 287, call; 287, 288; 287, 289; 288, identifier:len; 289, argument_list; 289, 290; 290, identifier:best_structures; 291, else_clause; 291, 292; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:log; 297, identifier:debug; 298, argument_list; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, string:'{}, {}: no PDB/chain pairs mapped'; 302, identifier:format; 303, argument_list; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:id; 307, identifier:uniprot_id; 308, return_statement; 308, 309; 309, identifier:new_pdbs | def map_uniprot_to_pdb(self, seq_ident_cutoff=0.0, outdir=None, force_rerun=False):
if not self.representative_sequence:
log.error('{}: no representative sequence set, cannot use best structures API'.format(self.id))
return None
uniprot_id = self.representative_sequence.uniprot
if not uniprot_id:
log.error('{}: no representative UniProt ID set, cannot use best structures API'.format(self.id))
return None
if '-' in uniprot_id:
log.debug('{}: "-" detected in UniProt ID, isoform specific sequences are ignored with best structures API'.format(self.id))
uniprot_id = uniprot_id.split('-')[0]
if not outdir:
outdir = self.sequence_dir
if not outdir:
raise ValueError('Output directory must be specified')
best_structures = ssbio.databases.pdb.best_structures(uniprot_id,
outname='{}_best_structures'.format(custom_slugify(uniprot_id)),
outdir=outdir,
seq_ident_cutoff=seq_ident_cutoff,
force_rerun=force_rerun)
new_pdbs = []
if best_structures:
rank = 1
for best_structure in best_structures:
currpdb = str(best_structure['pdb_id'].lower())
new_pdbs.append(currpdb)
currchain = str(best_structure['chain_id'])
new_pdb = self.load_pdb(pdb_id=currpdb, mapped_chains=currchain)
new_pdb.add_chain_ids(currchain)
pdb_specific_keys = ['experimental_method', 'resolution']
chain_specific_keys = ['coverage', 'start', 'end', 'unp_start', 'unp_end']
new_pdb.update(best_structure, only_keys=pdb_specific_keys)
new_chain = new_pdb.chains.get_by_id(currchain)
new_chain.update(best_structure, only_keys=chain_specific_keys)
new_chain.update({'rank': rank})
rank += 1
log.debug('{}, {}: {} PDB/chain pairs mapped'.format(self.id, uniprot_id, len(best_structures)))
else:
log.debug('{}, {}: no PDB/chain pairs mapped'.format(self.id, uniprot_id))
return new_pdbs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:map_uniprot_to_pdb; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:seq_ident_cutoff; 7, float:0.0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:outdir; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:force_rerun; 13, False; 14, block; 14, 15; 14, 19; 14, 61; 14, 68; 14, 85; 14, 89; 14, 193; 14, 216; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:all_representative_uniprots; 18, list:[]; 19, for_statement; 19, 20; 19, 21; 19, 24; 20, identifier:g; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:genes_with_a_representative_sequence; 24, block; 24, 25; 24, 35; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:uniprot_id; 28, attribute; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:g; 32, identifier:protein; 33, identifier:representative_sequence; 34, identifier:uniprot; 35, if_statement; 35, 36; 35, 37; 36, identifier:uniprot_id; 37, block; 37, 38; 37, 54; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:in; 39, 40; 39, 41; 40, string:'-'; 41, identifier:uniprot_id; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:uniprot_id; 46, subscript; 46, 47; 46, 53; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:uniprot_id; 50, identifier:split; 51, argument_list; 51, 52; 52, string:'-'; 53, integer:0; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:all_representative_uniprots; 58, identifier:append; 59, argument_list; 59, 60; 60, identifier:uniprot_id; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:log; 65, identifier:info; 66, argument_list; 66, 67; 67, string:'Mapping UniProt IDs --> PDB IDs...'; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:uniprots_to_pdbs; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:bs_unip; 74, identifier:mapping; 75, argument_list; 75, 76; 75, 79; 75, 82; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:fr; 78, string:'ACC'; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:to; 81, string:'PDB_ID'; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:query; 84, identifier:all_representative_uniprots; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:counter; 88, integer:0; 89, for_statement; 89, 90; 89, 91; 89, 97; 90, identifier:g; 91, call; 91, 92; 91, 93; 92, identifier:tqdm; 93, argument_list; 93, 94; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:genes_with_a_representative_sequence; 97, block; 97, 98; 97, 108; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:uniprot_id; 101, attribute; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:g; 105, identifier:protein; 106, identifier:representative_sequence; 107, identifier:uniprot; 108, if_statement; 108, 109; 108, 110; 109, identifier:uniprot_id; 110, block; 110, 111; 110, 127; 111, if_statement; 111, 112; 111, 115; 112, comparison_operator:in; 112, 113; 112, 114; 113, string:'-'; 114, identifier:uniprot_id; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:uniprot_id; 119, subscript; 119, 120; 119, 126; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:uniprot_id; 123, identifier:split; 124, argument_list; 124, 125; 125, string:'-'; 126, integer:0; 127, if_statement; 127, 128; 127, 131; 127, 176; 128, comparison_operator:in; 128, 129; 128, 130; 129, identifier:uniprot_id; 130, identifier:uniprots_to_pdbs; 131, block; 131, 132; 131, 151; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:best_structures; 135, call; 135, 136; 135, 141; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:g; 139, identifier:protein; 140, identifier:map_uniprot_to_pdb; 141, argument_list; 141, 142; 141, 145; 141, 148; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:seq_ident_cutoff; 144, identifier:seq_ident_cutoff; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:outdir; 147, identifier:outdir; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:force_rerun; 150, identifier:force_rerun; 151, if_statement; 151, 152; 151, 153; 152, identifier:best_structures; 153, block; 153, 154; 153, 158; 154, expression_statement; 154, 155; 155, augmented_assignment:+=; 155, 156; 155, 157; 156, identifier:counter; 157, integer:1; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:log; 162, identifier:debug; 163, argument_list; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, string:'{}: {} PDBs mapped'; 167, identifier:format; 168, argument_list; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:g; 171, identifier:id; 172, call; 172, 173; 172, 174; 173, identifier:len; 174, argument_list; 174, 175; 175, identifier:best_structures; 176, else_clause; 176, 177; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:log; 182, identifier:debug; 183, argument_list; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, string:'{}, {}: no PDBs available'; 187, identifier:format; 188, argument_list; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:g; 191, identifier:id; 192, identifier:uniprot_id; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:log; 197, identifier:info; 198, argument_list; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, string:'{}/{}: number of genes with at least one experimental structure'; 202, identifier:format; 203, argument_list; 203, 204; 203, 210; 204, call; 204, 205; 204, 206; 205, identifier:len; 206, argument_list; 206, 207; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:genes_with_experimental_structures; 210, call; 210, 211; 210, 212; 211, identifier:len; 212, argument_list; 212, 213; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:genes; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:log; 220, identifier:info; 221, argument_list; 221, 222; 222, string:'Completed UniProt --> best PDB mapping. See the "df_pdb_ranking" attribute for a summary dataframe.' | def map_uniprot_to_pdb(self, seq_ident_cutoff=0.0, outdir=None, force_rerun=False):
all_representative_uniprots = []
for g in self.genes_with_a_representative_sequence:
uniprot_id = g.protein.representative_sequence.uniprot
if uniprot_id:
if '-' in uniprot_id:
uniprot_id = uniprot_id.split('-')[0]
all_representative_uniprots.append(uniprot_id)
log.info('Mapping UniProt IDs --> PDB IDs...')
uniprots_to_pdbs = bs_unip.mapping(fr='ACC', to='PDB_ID', query=all_representative_uniprots)
counter = 0
for g in tqdm(self.genes_with_a_representative_sequence):
uniprot_id = g.protein.representative_sequence.uniprot
if uniprot_id:
if '-' in uniprot_id:
uniprot_id = uniprot_id.split('-')[0]
if uniprot_id in uniprots_to_pdbs:
best_structures = g.protein.map_uniprot_to_pdb(seq_ident_cutoff=seq_ident_cutoff, outdir=outdir, force_rerun=force_rerun)
if best_structures:
counter += 1
log.debug('{}: {} PDBs mapped'.format(g.id, len(best_structures)))
else:
log.debug('{}, {}: no PDBs available'.format(g.id, uniprot_id))
log.info('{}/{}: number of genes with at least one experimental structure'.format(len(self.genes_with_experimental_structures),
len(self.genes)))
log.info('Completed UniProt --> best PDB mapping. See the "df_pdb_ranking" attribute for a summary dataframe.') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:get_properties_by_type; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:type; 6, default_parameter; 6, 7; 6, 8; 7, identifier:recursive; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:parent_path; 11, string:""; 12, block; 12, 13; 12, 20; 12, 58; 12, 62; 12, 173; 13, if_statement; 13, 14; 13, 15; 14, identifier:parent_path; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, augmented_assignment:+=; 17, 18; 17, 19; 18, identifier:parent_path; 19, string:"."; 20, if_statement; 20, 21; 20, 26; 21, call; 21, 22; 21, 23; 22, identifier:isinstance; 23, argument_list; 23, 24; 23, 25; 24, identifier:type; 25, identifier:str; 26, block; 26, 27; 27, if_statement; 27, 28; 27, 31; 27, 51; 28, comparison_operator:==; 28, 29; 28, 30; 29, identifier:type; 30, string:"*"; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:type; 35, binary_operator:-; 35, 36; 35, 44; 36, call; 36, 37; 36, 38; 37, identifier:set; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:MAPPING_NAME_TYPE; 42, identifier:keys; 43, argument_list; 44, call; 44, 45; 44, 46; 45, identifier:set; 46, argument_list; 46, 47; 47, list:["nested", "multi_field", "multifield"]; 47, 48; 47, 49; 47, 50; 48, string:"nested"; 49, string:"multi_field"; 50, string:"multifield"; 51, else_clause; 51, 52; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:type; 56, list:[type]; 56, 57; 57, identifier:type; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:properties; 61, list:[]; 62, for_statement; 62, 63; 62, 64; 62, 74; 63, identifier:prop; 64, call; 64, 65; 64, 66; 65, identifier:list; 66, argument_list; 66, 67; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:properties; 72, identifier:values; 73, argument_list; 74, block; 74, 75; 74, 137; 74, 142; 75, if_statement; 75, 76; 75, 81; 75, 96; 76, comparison_operator:in; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:prop; 79, identifier:type; 80, identifier:type; 81, block; 81, 82; 81, 95; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:properties; 86, identifier:append; 87, argument_list; 87, 88; 88, tuple; 88, 89; 88, 94; 89, binary_operator:+; 89, 90; 89, 91; 90, identifier:parent_path; 91, attribute; 91, 92; 91, 93; 92, identifier:prop; 93, identifier:name; 94, identifier:prop; 95, continue_statement; 96, elif_clause; 96, 97; 96, 122; 97, boolean_operator:and; 97, 98; 97, 111; 98, boolean_operator:and; 98, 99; 98, 104; 99, comparison_operator:==; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:prop; 102, identifier:type; 103, string:"multi_field"; 104, comparison_operator:in; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:prop; 107, identifier:name; 108, attribute; 108, 109; 108, 110; 109, identifier:prop; 110, identifier:fields; 111, comparison_operator:in; 111, 112; 111, 121; 112, attribute; 112, 113; 112, 120; 113, subscript; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:prop; 116, identifier:fields; 117, attribute; 117, 118; 117, 119; 118, identifier:prop; 119, identifier:name; 120, identifier:type; 121, identifier:type; 122, block; 122, 123; 122, 136; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:properties; 127, identifier:append; 128, argument_list; 128, 129; 129, tuple; 129, 130; 129, 135; 130, binary_operator:+; 130, 131; 130, 132; 131, identifier:parent_path; 132, attribute; 132, 133; 132, 134; 133, identifier:prop; 134, identifier:name; 135, identifier:prop; 136, continue_statement; 137, if_statement; 137, 138; 137, 140; 138, not_operator; 138, 139; 139, identifier:recursive; 140, block; 140, 141; 141, continue_statement; 142, if_statement; 142, 143; 142, 150; 143, comparison_operator:in; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:prop; 146, identifier:type; 147, list:["nested", "object"]; 147, 148; 147, 149; 148, string:"nested"; 149, string:"object"; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:properties; 155, identifier:extend; 156, argument_list; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:prop; 160, identifier:get_properties_by_type; 161, argument_list; 161, 162; 161, 163; 161, 166; 162, identifier:type; 163, keyword_argument; 163, 164; 163, 165; 164, identifier:recursive; 165, identifier:recursive; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:parent_path; 168, binary_operator:+; 168, 169; 168, 170; 169, identifier:parent_path; 170, attribute; 170, 171; 170, 172; 171, identifier:prop; 172, identifier:name; 173, return_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:sorted; 176, argument_list; 176, 177; 177, identifier:properties | def get_properties_by_type(self, type, recursive=True, parent_path=""):
if parent_path:
parent_path += "."
if isinstance(type, str):
if type == "*":
type = set(MAPPING_NAME_TYPE.keys()) - set(["nested", "multi_field", "multifield"])
else:
type = [type]
properties = []
for prop in list(self.properties.values()):
if prop.type in type:
properties.append((parent_path + prop.name, prop))
continue
elif prop.type == "multi_field" and prop.name in prop.fields and prop.fields[prop.name].type in type:
properties.append((parent_path + prop.name, prop))
continue
if not recursive:
continue
if prop.type in ["nested", "object"]:
properties.extend(
prop.get_properties_by_type(type, recursive=recursive, parent_path=parent_path + prop.name))
return sorted(properties) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:insert; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:index; 6, identifier:key; 7, identifier:value; 8, block; 8, 9; 8, 42; 8, 52; 9, if_statement; 9, 10; 9, 15; 10, comparison_operator:in; 10, 11; 10, 12; 11, identifier:key; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:keyOrder; 15, block; 15, 16; 15, 27; 15, 33; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:n; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:keyOrder; 24, identifier:index; 25, argument_list; 25, 26; 26, identifier:key; 27, delete_statement; 27, 28; 28, subscript; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:keyOrder; 32, identifier:n; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:<; 34, 35; 34, 36; 35, identifier:n; 36, identifier:index; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, augmented_assignment:-=; 39, 40; 39, 41; 40, identifier:index; 41, integer:1; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:keyOrder; 48, identifier:insert; 49, argument_list; 49, 50; 49, 51; 50, identifier:index; 51, identifier:key; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 61; 54, attribute; 54, 55; 54, 60; 55, call; 55, 56; 55, 57; 56, identifier:super; 57, argument_list; 57, 58; 57, 59; 58, identifier:SortedDict; 59, identifier:self; 60, identifier:__setitem__; 61, argument_list; 61, 62; 61, 63; 62, identifier:key; 63, identifier:value | def insert(self, index, key, value):
if key in self.keyOrder:
n = self.keyOrder.index(key)
del self.keyOrder[n]
if n < index:
index -= 1
self.keyOrder.insert(index, key)
super(SortedDict, self).__setitem__(key, value) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 11; 2, function_name:sort_qualified_edges; 3, parameters; 3, 4; 4, identifier:graph; 5, type; 5, 6; 6, generic_type; 6, 7; 6, 8; 7, identifier:Iterable; 8, type_parameter; 8, 9; 9, type; 9, 10; 10, identifier:EdgeTuple; 11, block; 11, 12; 11, 56; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:qualified_edges; 15, generator_expression; 15, 16; 15, 21; 15, 38; 16, tuple; 16, 17; 16, 18; 16, 19; 16, 20; 17, identifier:u; 18, identifier:v; 19, identifier:k; 20, identifier:d; 21, for_in_clause; 21, 22; 21, 27; 22, pattern_list; 22, 23; 22, 24; 22, 25; 22, 26; 23, identifier:u; 24, identifier:v; 25, identifier:k; 26, identifier:d; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:graph; 30, identifier:edges; 31, argument_list; 31, 32; 31, 35; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:keys; 34, True; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:data; 37, True; 38, if_clause; 38, 39; 39, boolean_operator:and; 39, 40; 39, 48; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:graph; 43, identifier:has_edge_citation; 44, argument_list; 44, 45; 44, 46; 44, 47; 45, identifier:u; 46, identifier:v; 47, identifier:k; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:graph; 51, identifier:has_edge_evidence; 52, argument_list; 52, 53; 52, 54; 52, 55; 53, identifier:u; 54, identifier:v; 55, identifier:k; 56, return_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:sorted; 59, argument_list; 59, 60; 59, 61; 60, identifier:qualified_edges; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:key; 63, identifier:_sort_qualified_edges_helper | def sort_qualified_edges(graph) -> Iterable[EdgeTuple]:
qualified_edges = (
(u, v, k, d)
for u, v, k, d in graph.edges(keys=True, data=True)
if graph.has_edge_citation(u, v, k) and graph.has_edge_evidence(u, v, k)
)
return sorted(qualified_edges, key=_sort_qualified_edges_helper) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 1, 10; 2, function_name:_citation_sort_key; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:t; 6, type; 6, 7; 7, identifier:EdgeTuple; 8, type; 8, 9; 9, identifier:str; 10, block; 10, 11; 11, return_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, string:'"{}", "{}"'; 15, identifier:format; 16, argument_list; 16, 17; 16, 24; 17, subscript; 17, 18; 17, 23; 18, subscript; 18, 19; 18, 22; 19, subscript; 19, 20; 19, 21; 20, identifier:t; 21, integer:3; 22, identifier:CITATION; 23, identifier:CITATION_TYPE; 24, subscript; 24, 25; 24, 30; 25, subscript; 25, 26; 25, 29; 26, subscript; 26, 27; 26, 28; 27, identifier:t; 28, integer:3; 29, identifier:CITATION; 30, identifier:CITATION_REFERENCE | def _citation_sort_key(t: EdgeTuple) -> str:
return '"{}", "{}"'.format(t[3][CITATION][CITATION_TYPE], t[3][CITATION][CITATION_REFERENCE]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 18; 2, function_name:clean_pubmed_identifiers; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:pmids; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Iterable; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:str; 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:str; 18, block; 18, 19; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:sorted; 22, argument_list; 22, 23; 23, set_comprehension; 23, 24; 23, 32; 24, call; 24, 25; 24, 31; 25, attribute; 25, 26; 25, 30; 26, call; 26, 27; 26, 28; 27, identifier:str; 28, argument_list; 28, 29; 29, identifier:pmid; 30, identifier:strip; 31, argument_list; 32, for_in_clause; 32, 33; 32, 34; 33, identifier:pmid; 34, identifier:pmids | def clean_pubmed_identifiers(pmids: Iterable[str]) -> List[str]:
return sorted({str(pmid).strip() for pmid in pmids}) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 7; 2, function_name:hash_dump; 3, parameters; 3, 4; 4, identifier:data; 5, type; 5, 6; 6, identifier:str; 7, block; 7, 8; 8, return_statement; 8, 9; 9, call; 9, 10; 9, 31; 10, attribute; 10, 11; 10, 30; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:hashlib; 14, identifier:sha512; 15, argument_list; 15, 16; 16, call; 16, 17; 16, 28; 17, attribute; 17, 18; 17, 27; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:json; 21, identifier:dumps; 22, argument_list; 22, 23; 22, 24; 23, identifier:data; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:sort_keys; 26, True; 27, identifier:encode; 28, argument_list; 28, 29; 29, string:'utf-8'; 30, identifier:hexdigest; 31, argument_list | def hash_dump(data) -> str:
return hashlib.sha512(json.dumps(data, sort_keys=True).encode('utf-8')).hexdigest() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:yield_sorted_by_type; 3, parameters; 3, 4; 4, list_splat_pattern; 4, 5; 5, identifier:typelist; 6, block; 6, 7; 6, 40; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:decorate; 9, parameters; 9, 10; 10, identifier:fun; 11, block; 11, 12; 11, 38; 12, decorated_definition; 12, 13; 12, 18; 13, decorator; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:wraps; 16, argument_list; 16, 17; 17, identifier:fun; 18, function_definition; 18, 19; 18, 20; 18, 25; 19, function_name:decorated; 20, parameters; 20, 21; 20, 23; 21, list_splat_pattern; 21, 22; 22, identifier:args; 23, dictionary_splat_pattern; 23, 24; 24, identifier:kwds; 25, block; 25, 26; 26, return_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:iterate_by_type; 29, argument_list; 29, 30; 29, 37; 30, call; 30, 31; 30, 32; 31, identifier:fun; 32, argument_list; 32, 33; 32, 35; 33, list_splat; 33, 34; 34, identifier:args; 35, dictionary_splat; 35, 36; 36, identifier:kwds; 37, identifier:typelist; 38, return_statement; 38, 39; 39, identifier:decorated; 40, return_statement; 40, 41; 41, identifier:decorate | def yield_sorted_by_type(*typelist):
def decorate(fun):
@wraps(fun)
def decorated(*args, **kwds):
return iterate_by_type(fun(*args, **kwds), typelist)
return decorated
return decorate |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 1, 22; 2, function_name:build_route_timetable; 3, parameters; 3, 4; 3, 8; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:feed; 6, type; 6, 7; 7, string:"Feed"; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:route_id; 10, type; 10, 11; 11, identifier:str; 12, typed_parameter; 12, 13; 12, 14; 13, identifier:dates; 14, type; 14, 15; 15, generic_type; 15, 16; 15, 17; 16, identifier:List; 17, type_parameter; 17, 18; 18, type; 18, 19; 19, identifier:str; 20, type; 20, 21; 21, identifier:DataFrame; 22, block; 22, 23; 22, 32; 22, 42; 22, 56; 22, 70; 22, 79; 22, 83; 22, 163; 22, 172; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:dates; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:feed; 29, identifier:restrict_dates; 30, argument_list; 30, 31; 31, identifier:dates; 32, if_statement; 32, 33; 32, 35; 33, not_operator; 33, 34; 34, identifier:dates; 35, block; 35, 36; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:pd; 40, identifier:DataFrame; 41, argument_list; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:t; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:pd; 48, identifier:merge; 49, argument_list; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:feed; 52, identifier:trips; 53, attribute; 53, 54; 53, 55; 54, identifier:feed; 55, identifier:stop_times; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:t; 59, call; 59, 60; 59, 69; 60, attribute; 60, 61; 60, 68; 61, subscript; 61, 62; 61, 63; 62, identifier:t; 63, comparison_operator:==; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:t; 66, string:"route_id"; 67, identifier:route_id; 68, identifier:copy; 69, argument_list; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:a; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:feed; 76, identifier:compute_trip_activity; 77, argument_list; 77, 78; 78, identifier:dates; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:frames; 82, list:[]; 83, for_statement; 83, 84; 83, 85; 83, 86; 84, identifier:date; 85, identifier:dates; 86, block; 86, 87; 86, 100; 86, 117; 86, 123; 86, 138; 86, 156; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:ids; 90, subscript; 90, 91; 90, 94; 90, 99; 91, attribute; 91, 92; 91, 93; 92, identifier:a; 93, identifier:loc; 94, comparison_operator:==; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:a; 97, identifier:date; 98, integer:1; 99, string:"trip_id"; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:f; 103, call; 103, 104; 103, 116; 104, attribute; 104, 105; 104, 115; 105, subscript; 105, 106; 105, 107; 106, identifier:t; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:t; 111, string:"trip_id"; 112, identifier:isin; 113, argument_list; 113, 114; 114, identifier:ids; 115, identifier:copy; 116, argument_list; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:f; 121, string:"date"; 122, identifier:date; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:f; 127, string:"dt"; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, subscript; 130, 131; 130, 132; 131, identifier:f; 132, string:"departure_time"; 133, identifier:fillna; 134, argument_list; 134, 135; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:method; 137, string:"ffill"; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:f; 142, string:"min_dt"; 143, call; 143, 144; 143, 154; 144, attribute; 144, 145; 144, 153; 145, subscript; 145, 146; 145, 152; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:f; 149, identifier:groupby; 150, argument_list; 150, 151; 151, string:"trip_id"; 152, string:"dt"; 153, identifier:transform; 154, argument_list; 154, 155; 155, identifier:min; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:frames; 160, identifier:append; 161, argument_list; 161, 162; 162, identifier:f; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:f; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:pd; 169, identifier:concat; 170, argument_list; 170, 171; 171, identifier:frames; 172, return_statement; 172, 173; 173, call; 173, 174; 173, 185; 174, attribute; 174, 175; 174, 184; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:f; 178, identifier:sort_values; 179, argument_list; 179, 180; 180, list:["date", "min_dt", "stop_sequence"]; 180, 181; 180, 182; 180, 183; 181, string:"date"; 182, string:"min_dt"; 183, string:"stop_sequence"; 184, identifier:drop; 185, argument_list; 185, 186; 185, 189; 186, list:["min_dt", "dt"]; 186, 187; 186, 188; 187, string:"min_dt"; 188, string:"dt"; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:axis; 191, integer:1 | def build_route_timetable(
feed: "Feed", route_id: str, dates: List[str]
) -> DataFrame:
dates = feed.restrict_dates(dates)
if not dates:
return pd.DataFrame()
t = pd.merge(feed.trips, feed.stop_times)
t = t[t["route_id"] == route_id].copy()
a = feed.compute_trip_activity(dates)
frames = []
for date in dates:
ids = a.loc[a[date] == 1, "trip_id"]
f = t[t["trip_id"].isin(ids)].copy()
f["date"] = date
f["dt"] = f["departure_time"].fillna(method="ffill")
f["min_dt"] = f.groupby("trip_id")["dt"].transform(min)
frames.append(f)
f = pd.concat(frames)
return f.sort_values(["date", "min_dt", "stop_sequence"]).drop(
["min_dt", "dt"], axis=1
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 14; 2, function_name:almost_equal; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:f; 6, type; 6, 7; 7, identifier:DataFrame; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:g; 10, type; 10, 11; 11, identifier:DataFrame; 12, type; 12, 13; 13, identifier:bool; 14, block; 14, 15; 15, if_statement; 15, 16; 15, 23; 15, 31; 16, boolean_operator:or; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:f; 19, identifier:empty; 20, attribute; 20, 21; 20, 22; 21, identifier:g; 22, identifier:empty; 23, block; 23, 24; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:f; 28, identifier:equals; 29, argument_list; 29, 30; 30, identifier:g; 31, else_clause; 31, 32; 32, block; 32, 33; 32, 62; 32, 91; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:F; 36, parenthesized_expression; 36, 37; 37, call; 37, 38; 37, 58; 38, attribute; 38, 39; 38, 57; 39, call; 39, 40; 39, 50; 40, attribute; 40, 41; 40, 49; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:f; 44, identifier:sort_index; 45, argument_list; 45, 46; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:axis; 48, integer:1; 49, identifier:sort_values; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:list; 53, argument_list; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:f; 56, identifier:columns; 57, identifier:reset_index; 58, argument_list; 58, 59; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:drop; 61, True; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:G; 65, parenthesized_expression; 65, 66; 66, call; 66, 67; 66, 87; 67, attribute; 67, 68; 67, 86; 68, call; 68, 69; 68, 79; 69, attribute; 69, 70; 69, 78; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:g; 73, identifier:sort_index; 74, argument_list; 74, 75; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:axis; 77, integer:1; 78, identifier:sort_values; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:list; 82, argument_list; 82, 83; 83, attribute; 83, 84; 83, 85; 84, identifier:g; 85, identifier:columns; 86, identifier:reset_index; 87, argument_list; 87, 88; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:drop; 90, True; 91, return_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:F; 95, identifier:equals; 96, argument_list; 96, 97; 97, identifier:G | def almost_equal(f: DataFrame, g: DataFrame) -> bool:
if f.empty or g.empty:
return f.equals(g)
else:
F = (
f.sort_index(axis=1)
.sort_values(list(f.columns))
.reset_index(drop=True)
)
G = (
g.sort_index(axis=1)
.sort_values(list(g.columns))
.reset_index(drop=True)
)
return F.equals(G) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 1, 22; 2, function_name:build_stop_timetable; 3, parameters; 3, 4; 3, 8; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:feed; 6, type; 6, 7; 7, string:"Feed"; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:stop_id; 10, type; 10, 11; 11, identifier:str; 12, typed_parameter; 12, 13; 12, 14; 13, identifier:dates; 14, type; 14, 15; 15, generic_type; 15, 16; 15, 17; 16, identifier:List; 17, type_parameter; 17, 18; 18, type; 18, 19; 19, identifier:str; 20, type; 20, 21; 21, identifier:DataFrame; 22, block; 22, 23; 22, 32; 22, 42; 22, 56; 22, 70; 22, 79; 22, 83; 22, 130; 22, 139; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:dates; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:feed; 29, identifier:restrict_dates; 30, argument_list; 30, 31; 31, identifier:dates; 32, if_statement; 32, 33; 32, 35; 33, not_operator; 33, 34; 34, identifier:dates; 35, block; 35, 36; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:pd; 40, identifier:DataFrame; 41, argument_list; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:t; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:pd; 48, identifier:merge; 49, argument_list; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:feed; 52, identifier:trips; 53, attribute; 53, 54; 53, 55; 54, identifier:feed; 55, identifier:stop_times; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:t; 59, call; 59, 60; 59, 69; 60, attribute; 60, 61; 60, 68; 61, subscript; 61, 62; 61, 63; 62, identifier:t; 63, comparison_operator:==; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:t; 66, string:"stop_id"; 67, identifier:stop_id; 68, identifier:copy; 69, argument_list; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:a; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:feed; 76, identifier:compute_trip_activity; 77, argument_list; 77, 78; 78, identifier:dates; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:frames; 82, list:[]; 83, for_statement; 83, 84; 83, 85; 83, 86; 84, identifier:date; 85, identifier:dates; 86, block; 86, 87; 86, 100; 86, 117; 86, 123; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:ids; 90, subscript; 90, 91; 90, 94; 90, 99; 91, attribute; 91, 92; 91, 93; 92, identifier:a; 93, identifier:loc; 94, comparison_operator:==; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:a; 97, identifier:date; 98, integer:1; 99, string:"trip_id"; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:f; 103, call; 103, 104; 103, 116; 104, attribute; 104, 105; 104, 115; 105, subscript; 105, 106; 105, 107; 106, identifier:t; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:t; 111, string:"trip_id"; 112, identifier:isin; 113, argument_list; 113, 114; 114, identifier:ids; 115, identifier:copy; 116, argument_list; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:f; 121, string:"date"; 122, identifier:date; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:frames; 127, identifier:append; 128, argument_list; 128, 129; 129, identifier:f; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:f; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:pd; 136, identifier:concat; 137, argument_list; 137, 138; 138, identifier:frames; 139, return_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:f; 143, identifier:sort_values; 144, argument_list; 144, 145; 145, list:["date", "departure_time"]; 145, 146; 145, 147; 146, string:"date"; 147, string:"departure_time" | def build_stop_timetable(
feed: "Feed", stop_id: str, dates: List[str]
) -> DataFrame:
dates = feed.restrict_dates(dates)
if not dates:
return pd.DataFrame()
t = pd.merge(feed.trips, feed.stop_times)
t = t[t["stop_id"] == stop_id].copy()
a = feed.compute_trip_activity(dates)
frames = []
for date in dates:
ids = a.loc[a[date] == 1, "trip_id"]
f = t[t["trip_id"].isin(ids)].copy()
f["date"] = date
frames.append(f)
f = pd.concat(frames)
return f.sort_values(["date", "departure_time"]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_unit_property_names; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:unit_id; 7, None; 8, block; 8, 9; 8, 11; 8, 63; 9, expression_statement; 9, 10; 10, string:'''Get a list of property names for a given unit, or for all units if unit_id is None
Parameters
----------
unit_id: int
The unit id for which the property names will be returned
If None (default), will return property names for all units
Returns
----------
property_names
The list of property names from the specified unit(s)
'''; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:unit_id; 14, None; 15, block; 15, 16; 15, 20; 15, 48; 15, 61; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:property_names; 19, list:[]; 20, for_statement; 20, 21; 20, 22; 20, 27; 21, identifier:unit_id; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:get_unit_ids; 26, argument_list; 27, block; 27, 28; 27, 37; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:curr_property_names; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:get_unit_property_names; 35, argument_list; 35, 36; 36, identifier:unit_id; 37, for_statement; 37, 38; 37, 39; 37, 40; 38, identifier:curr_property_name; 39, identifier:curr_property_names; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:property_names; 45, identifier:append; 46, argument_list; 46, 47; 47, identifier:curr_property_name; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:property_names; 51, call; 51, 52; 51, 53; 52, identifier:sorted; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:list; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:set; 59, argument_list; 59, 60; 60, identifier:property_names; 61, return_statement; 61, 62; 62, identifier:property_names; 63, if_statement; 63, 64; 63, 73; 63, 127; 64, call; 64, 65; 64, 66; 65, identifier:isinstance; 66, argument_list; 66, 67; 66, 68; 67, identifier:unit_id; 68, tuple; 68, 69; 68, 70; 69, identifier:int; 70, attribute; 70, 71; 70, 72; 71, identifier:np; 72, identifier:integer; 73, block; 73, 74; 74, if_statement; 74, 75; 74, 82; 74, 115; 75, comparison_operator:in; 75, 76; 75, 77; 76, identifier:unit_id; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:get_unit_ids; 81, argument_list; 82, block; 82, 83; 82, 98; 82, 113; 83, if_statement; 83, 84; 83, 89; 84, comparison_operator:not; 84, 85; 84, 86; 85, identifier:unit_id; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:_unit_properties; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 97; 92, subscript; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:_unit_properties; 96, identifier:unit_id; 97, dictionary; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:property_names; 101, call; 101, 102; 101, 103; 102, identifier:sorted; 103, argument_list; 103, 104; 104, call; 104, 105; 104, 112; 105, attribute; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:_unit_properties; 110, identifier:unit_id; 111, identifier:keys; 112, argument_list; 113, return_statement; 113, 114; 114, identifier:property_names; 115, else_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, binary_operator:+; 121, 122; 121, 126; 122, call; 122, 123; 122, 124; 123, identifier:str; 124, argument_list; 124, 125; 125, identifier:unit_id; 126, string:" is not a valid unit_id"; 127, else_clause; 127, 128; 128, block; 128, 129; 129, raise_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:ValueError; 132, argument_list; 132, 133; 133, binary_operator:+; 133, 134; 133, 138; 134, call; 134, 135; 134, 136; 135, identifier:str; 136, argument_list; 136, 137; 137, identifier:unit_id; 138, string:" must be an int" | def get_unit_property_names(self, unit_id=None):
'''Get a list of property names for a given unit, or for all units if unit_id is None
Parameters
----------
unit_id: int
The unit id for which the property names will be returned
If None (default), will return property names for all units
Returns
----------
property_names
The list of property names from the specified unit(s)
'''
if unit_id is None:
property_names = []
for unit_id in self.get_unit_ids():
curr_property_names = self.get_unit_property_names(unit_id)
for curr_property_name in curr_property_names:
property_names.append(curr_property_name)
property_names = sorted(list(set(property_names)))
return property_names
if isinstance(unit_id, (int, np.integer)):
if unit_id in self.get_unit_ids():
if unit_id not in self._unit_properties:
self._unit_properties[unit_id] = {}
property_names = sorted(self._unit_properties[unit_id].keys())
return property_names
else:
raise ValueError(str(unit_id) + " is not a valid unit_id")
else:
raise ValueError(str(unit_id) + " must be an int") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:copy_unit_properties; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:sorting; 6, default_parameter; 6, 7; 6, 8; 7, identifier:unit_ids; 8, None; 9, block; 9, 10; 9, 12; 9, 25; 10, expression_statement; 10, 11; 11, string:'''Copy unit properties from another sorting extractor to the current
sorting extractor.
Parameters
----------
sorting: SortingExtractor
The sorting extractor from which the properties will be copied
unit_ids: (array_like, int)
The list (or single value) of unit_ids for which the properties will be copied.
'''; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:unit_ids; 15, None; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:unit_ids; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:sorting; 23, identifier:get_unit_ids; 24, argument_list; 25, if_statement; 25, 26; 25, 31; 25, 76; 26, call; 26, 27; 26, 28; 27, identifier:isinstance; 28, argument_list; 28, 29; 28, 30; 29, identifier:unit_ids; 30, identifier:int; 31, block; 31, 32; 31, 43; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:curr_property_names; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:sorting; 38, identifier:get_unit_property_names; 39, argument_list; 39, 40; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:unit_id; 42, identifier:unit_ids; 43, for_statement; 43, 44; 43, 45; 43, 46; 44, identifier:curr_property_name; 45, identifier:curr_property_names; 46, block; 46, 47; 46, 61; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:value; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:sorting; 53, identifier:get_unit_property; 54, argument_list; 54, 55; 54, 58; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:unit_id; 57, identifier:unit_ids; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:property_name; 60, identifier:curr_property_name; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:set_unit_property; 66, argument_list; 66, 67; 66, 70; 66, 73; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:unit_id; 69, identifier:unit_ids; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:property_name; 72, identifier:curr_property_name; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:value; 75, identifier:value; 76, else_clause; 76, 77; 77, block; 77, 78; 78, for_statement; 78, 79; 78, 80; 78, 81; 79, identifier:unit_id; 80, identifier:unit_ids; 81, block; 81, 82; 81, 93; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:curr_property_names; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:sorting; 88, identifier:get_unit_property_names; 89, argument_list; 89, 90; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:unit_id; 92, identifier:unit_id; 93, for_statement; 93, 94; 93, 95; 93, 96; 94, identifier:curr_property_name; 95, identifier:curr_property_names; 96, block; 96, 97; 96, 111; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:value; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:sorting; 103, identifier:get_unit_property; 104, argument_list; 104, 105; 104, 108; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:unit_id; 107, identifier:unit_id; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:property_name; 110, identifier:curr_property_name; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:set_unit_property; 116, argument_list; 116, 117; 116, 120; 116, 123; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:unit_id; 119, identifier:unit_id; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:property_name; 122, identifier:curr_property_name; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:value; 125, identifier:value | def copy_unit_properties(self, sorting, unit_ids=None):
'''Copy unit properties from another sorting extractor to the current
sorting extractor.
Parameters
----------
sorting: SortingExtractor
The sorting extractor from which the properties will be copied
unit_ids: (array_like, int)
The list (or single value) of unit_ids for which the properties will be copied.
'''
if unit_ids is None:
unit_ids = sorting.get_unit_ids()
if isinstance(unit_ids, int):
curr_property_names = sorting.get_unit_property_names(unit_id=unit_ids)
for curr_property_name in curr_property_names:
value = sorting.get_unit_property(unit_id=unit_ids, property_name=curr_property_name)
self.set_unit_property(unit_id=unit_ids, property_name=curr_property_name, value=value)
else:
for unit_id in unit_ids:
curr_property_names = sorting.get_unit_property_names(unit_id=unit_id)
for curr_property_name in curr_property_names:
value = sorting.get_unit_property(unit_id=unit_id, property_name=curr_property_name)
self.set_unit_property(unit_id=unit_id, property_name=curr_property_name, value=value) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:copy_unit_spike_features; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:sorting; 6, default_parameter; 6, 7; 6, 8; 7, identifier:unit_ids; 8, None; 9, block; 9, 10; 9, 12; 9, 25; 10, expression_statement; 10, 11; 11, string:'''Copy unit spike features from another sorting extractor to the current
sorting extractor.
Parameters
----------
sorting: SortingExtractor
The sorting extractor from which the spike features will be copied
unit_ids: (array_like, int)
The list (or single value) of unit_ids for which the spike features will be copied.
def get_unit_spike_features(self, unit_id, feature_name, start_frame=None, end_frame=None):
'''; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:unit_ids; 15, None; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:unit_ids; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:sorting; 23, identifier:get_unit_ids; 24, argument_list; 25, if_statement; 25, 26; 25, 31; 25, 76; 26, call; 26, 27; 26, 28; 27, identifier:isinstance; 28, argument_list; 28, 29; 28, 30; 29, identifier:unit_ids; 30, identifier:int; 31, block; 31, 32; 31, 43; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:curr_feature_names; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:sorting; 38, identifier:get_unit_spike_feature_names; 39, argument_list; 39, 40; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:unit_id; 42, identifier:unit_ids; 43, for_statement; 43, 44; 43, 45; 43, 46; 44, identifier:curr_feature_name; 45, identifier:curr_feature_names; 46, block; 46, 47; 46, 61; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:value; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:sorting; 53, identifier:get_unit_spike_features; 54, argument_list; 54, 55; 54, 58; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:unit_id; 57, identifier:unit_ids; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:feature_name; 60, identifier:curr_feature_name; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:set_unit_spike_features; 66, argument_list; 66, 67; 66, 70; 66, 73; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:unit_id; 69, identifier:unit_ids; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:feature_name; 72, identifier:curr_feature_name; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:value; 75, identifier:value; 76, else_clause; 76, 77; 77, block; 77, 78; 78, for_statement; 78, 79; 78, 80; 78, 81; 79, identifier:unit_id; 80, identifier:unit_ids; 81, block; 81, 82; 81, 93; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:curr_feature_names; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:sorting; 88, identifier:get_unit_spike_feature_names; 89, argument_list; 89, 90; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:unit_id; 92, identifier:unit_id; 93, for_statement; 93, 94; 93, 95; 93, 96; 94, identifier:curr_feature_name; 95, identifier:curr_feature_names; 96, block; 96, 97; 96, 111; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:value; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:sorting; 103, identifier:get_unit_spike_features; 104, argument_list; 104, 105; 104, 108; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:unit_id; 107, identifier:unit_id; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:feature_name; 110, identifier:curr_feature_name; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:set_unit_spike_features; 116, argument_list; 116, 117; 116, 120; 116, 123; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:unit_id; 119, identifier:unit_id; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:feature_name; 122, identifier:curr_feature_name; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:value; 125, identifier:value | def copy_unit_spike_features(self, sorting, unit_ids=None):
'''Copy unit spike features from another sorting extractor to the current
sorting extractor.
Parameters
----------
sorting: SortingExtractor
The sorting extractor from which the spike features will be copied
unit_ids: (array_like, int)
The list (or single value) of unit_ids for which the spike features will be copied.
def get_unit_spike_features(self, unit_id, feature_name, start_frame=None, end_frame=None):
'''
if unit_ids is None:
unit_ids = sorting.get_unit_ids()
if isinstance(unit_ids, int):
curr_feature_names = sorting.get_unit_spike_feature_names(unit_id=unit_ids)
for curr_feature_name in curr_feature_names:
value = sorting.get_unit_spike_features(unit_id=unit_ids, feature_name=curr_feature_name)
self.set_unit_spike_features(unit_id=unit_ids, feature_name=curr_feature_name, value=value)
else:
for unit_id in unit_ids:
curr_feature_names = sorting.get_unit_spike_feature_names(unit_id=unit_id)
for curr_feature_name in curr_feature_names:
value = sorting.get_unit_spike_features(unit_id=unit_id, feature_name=curr_feature_name)
self.set_unit_spike_features(unit_id=unit_id, feature_name=curr_feature_name, value=value) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:merge_units; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:unit_ids; 6, block; 6, 7; 6, 9; 6, 13; 6, 42; 6, 46; 7, expression_statement; 7, 8; 8, string:'''This function merges two roots from the curation tree according to the given unit_ids. It creates a new unit_id and root
that has the merged roots as children.
Parameters
----------
unit_ids: list
The unit ids to be merged
'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:root_ids; 12, list:[]; 13, for_statement; 13, 14; 13, 15; 13, 24; 14, identifier:i; 15, call; 15, 16; 15, 17; 16, identifier:range; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:len; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_roots; 24, block; 24, 25; 24, 35; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:root_id; 28, attribute; 28, 29; 28, 34; 29, subscript; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_roots; 33, identifier:i; 34, identifier:unit_id; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:root_ids; 39, identifier:append; 40, argument_list; 40, 41; 41, identifier:root_id; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:indices_to_be_deleted; 45, list:[]; 46, if_statement; 46, 47; 46, 67; 46, 364; 47, parenthesized_expression; 47, 48; 48, boolean_operator:and; 48, 49; 48, 61; 49, call; 49, 50; 49, 56; 50, attribute; 50, 51; 50, 55; 51, call; 51, 52; 51, 53; 52, identifier:set; 53, argument_list; 53, 54; 54, identifier:unit_ids; 55, identifier:issubset; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:set; 59, argument_list; 59, 60; 60, identifier:root_ids; 61, comparison_operator:>; 61, 62; 61, 66; 62, call; 62, 63; 62, 64; 63, identifier:len; 64, argument_list; 64, 65; 65, identifier:unit_ids; 66, integer:1; 67, block; 67, 68; 67, 72; 67, 92; 67, 101; 67, 116; 67, 123; 67, 127; 67, 144; 67, 155; 67, 164; 67, 171; 67, 175; 67, 271; 67, 280; 67, 289; 67, 303; 67, 305; 67, 328; 67, 337; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:all_feature_names; 71, list:[]; 72, for_statement; 72, 73; 72, 74; 72, 75; 73, identifier:unit_id; 74, identifier:unit_ids; 75, block; 75, 76; 75, 85; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:feature_names; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:get_unit_spike_feature_names; 83, argument_list; 83, 84; 84, identifier:unit_id; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:all_feature_names; 89, identifier:append; 90, argument_list; 90, 91; 91, identifier:feature_names; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:shared_feature_names; 95, call; 95, 96; 95, 97; 96, identifier:set; 97, argument_list; 97, 98; 98, subscript; 98, 99; 98, 100; 99, identifier:all_feature_names; 100, integer:0; 101, for_statement; 101, 102; 101, 103; 101, 108; 102, identifier:feature_names; 103, subscript; 103, 104; 103, 105; 104, identifier:all_feature_names; 105, slice; 105, 106; 105, 107; 106, integer:1; 107, colon; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:shared_feature_names; 113, identifier:intersection_update; 114, argument_list; 114, 115; 115, identifier:feature_names; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:shared_feature_names; 119, call; 119, 120; 119, 121; 120, identifier:list; 121, argument_list; 121, 122; 122, identifier:shared_feature_names; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:shared_features; 126, list:[]; 127, for_statement; 127, 128; 127, 129; 127, 136; 128, identifier:i; 129, call; 129, 130; 129, 131; 130, identifier:range; 131, argument_list; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:len; 134, argument_list; 134, 135; 135, identifier:shared_feature_names; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:shared_features; 141, identifier:append; 142, argument_list; 142, 143; 143, list:[]; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:new_root_id; 147, binary_operator:+; 147, 148; 147, 154; 148, call; 148, 149; 148, 150; 149, identifier:max; 150, argument_list; 150, 151; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:_all_ids; 154, integer:1; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 162; 157, attribute; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:_all_ids; 161, identifier:append; 162, argument_list; 162, 163; 163, identifier:new_root_id; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:new_root; 167, call; 167, 168; 167, 169; 168, identifier:Unit; 169, argument_list; 169, 170; 170, identifier:new_root_id; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:all_spike_trains; 174, list:[]; 175, for_statement; 175, 176; 175, 177; 175, 178; 176, identifier:unit_id; 177, identifier:unit_ids; 178, block; 178, 179; 178, 188; 178, 199; 178, 214; 178, 242; 178, 248; 178, 264; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:root_index; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:root_ids; 185, identifier:index; 186, argument_list; 186, 187; 187, identifier:unit_id; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:new_root; 192, identifier:add_child; 193, argument_list; 193, 194; 194, subscript; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:_roots; 198, identifier:root_index; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:all_spike_trains; 203, identifier:append; 204, argument_list; 204, 205; 205, call; 205, 206; 205, 213; 206, attribute; 206, 207; 206, 212; 207, subscript; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:_roots; 211, identifier:root_index; 212, identifier:get_spike_train; 213, argument_list; 214, for_statement; 214, 215; 214, 218; 214, 222; 215, pattern_list; 215, 216; 215, 217; 216, identifier:i; 217, identifier:feature_name; 218, call; 218, 219; 218, 220; 219, identifier:enumerate; 220, argument_list; 220, 221; 221, identifier:shared_feature_names; 222, block; 222, 223; 222, 233; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:features; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:get_unit_spike_features; 230, argument_list; 230, 231; 230, 232; 231, identifier:unit_id; 232, identifier:feature_name; 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:shared_features; 238, identifier:i; 239, identifier:append; 240, argument_list; 240, 241; 241, identifier:features; 242, delete_statement; 242, 243; 243, subscript; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:_unit_features; 247, identifier:unit_id; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 257; 250, attribute; 250, 251; 250, 256; 251, subscript; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:_roots; 255, identifier:root_index; 256, identifier:set_spike_train; 257, argument_list; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:np; 261, identifier:asarray; 262, argument_list; 262, 263; 263, list:[]; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:indices_to_be_deleted; 268, identifier:append; 269, argument_list; 269, 270; 270, identifier:root_index; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:all_spike_trains; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:np; 277, identifier:concatenate; 278, argument_list; 278, 279; 279, identifier:all_spike_trains; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:sort_indices; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:np; 286, identifier:argsort; 287, argument_list; 287, 288; 288, identifier:all_spike_trains; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:new_root; 293, identifier:set_spike_train; 294, argument_list; 294, 295; 295, subscript; 295, 296; 295, 302; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:np; 299, identifier:asarray; 300, argument_list; 300, 301; 301, identifier:all_spike_trains; 302, identifier:sort_indices; 303, delete_statement; 303, 304; 304, identifier:all_spike_trains; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:self; 309, identifier:_roots; 310, list_comprehension; 310, 311; 310, 316; 310, 324; 311, subscript; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:_roots; 315, identifier:i; 316, for_in_clause; 316, 317; 316, 320; 317, pattern_list; 317, 318; 317, 319; 318, identifier:i; 319, identifier:_; 320, call; 320, 321; 320, 322; 321, identifier:enumerate; 322, argument_list; 322, 323; 323, identifier:root_ids; 324, if_clause; 324, 325; 325, comparison_operator:not; 325, 326; 325, 327; 326, identifier:i; 327, identifier:indices_to_be_deleted; 328, expression_statement; 328, 329; 329, call; 329, 330; 329, 335; 330, attribute; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:_roots; 334, identifier:append; 335, argument_list; 335, 336; 336, identifier:new_root; 337, for_statement; 337, 338; 337, 341; 337, 345; 338, pattern_list; 338, 339; 338, 340; 339, identifier:i; 340, identifier:feature_name; 341, call; 341, 342; 341, 343; 342, identifier:enumerate; 343, argument_list; 343, 344; 344, identifier:shared_feature_names; 345, block; 345, 346; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:self; 350, identifier:set_unit_spike_features; 351, argument_list; 351, 352; 351, 353; 351, 354; 352, identifier:new_root_id; 353, identifier:feature_name; 354, subscript; 354, 355; 354, 363; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:np; 358, identifier:concatenate; 359, argument_list; 359, 360; 360, subscript; 360, 361; 360, 362; 361, identifier:shared_features; 362, identifier:i; 363, identifier:sort_indices; 364, else_clause; 364, 365; 365, block; 365, 366; 366, raise_statement; 366, 367; 367, call; 367, 368; 367, 369; 368, identifier:ValueError; 369, argument_list; 369, 370; 370, binary_operator:+; 370, 371; 370, 375; 371, call; 371, 372; 371, 373; 372, identifier:str; 373, argument_list; 373, 374; 374, identifier:unit_ids; 375, string:" has one or more invalid unit ids" | def merge_units(self, unit_ids):
'''This function merges two roots from the curation tree according to the given unit_ids. It creates a new unit_id and root
that has the merged roots as children.
Parameters
----------
unit_ids: list
The unit ids to be merged
'''
root_ids = []
for i in range(len(self._roots)):
root_id = self._roots[i].unit_id
root_ids.append(root_id)
indices_to_be_deleted = []
if(set(unit_ids).issubset(set(root_ids)) and len(unit_ids) > 1):
all_feature_names = []
for unit_id in unit_ids:
feature_names = self.get_unit_spike_feature_names(unit_id)
all_feature_names.append(feature_names)
shared_feature_names = set(all_feature_names[0])
for feature_names in all_feature_names[1:]:
shared_feature_names.intersection_update(feature_names)
shared_feature_names = list(shared_feature_names)
shared_features = []
for i in range(len(shared_feature_names)):
shared_features.append([])
new_root_id = max(self._all_ids)+1
self._all_ids.append(new_root_id)
new_root = Unit(new_root_id)
all_spike_trains = []
for unit_id in unit_ids:
root_index = root_ids.index(unit_id)
new_root.add_child(self._roots[root_index])
all_spike_trains.append(self._roots[root_index].get_spike_train())
for i, feature_name in enumerate(shared_feature_names):
features = self.get_unit_spike_features(unit_id, feature_name)
shared_features[i].append(features)
del self._unit_features[unit_id]
self._roots[root_index].set_spike_train(np.asarray([]))
indices_to_be_deleted.append(root_index)
all_spike_trains = np.concatenate(all_spike_trains)
sort_indices = np.argsort(all_spike_trains)
new_root.set_spike_train(np.asarray(all_spike_trains)[sort_indices])
del all_spike_trains
self._roots = [self._roots[i] for i,_ in enumerate(root_ids) if i not in indices_to_be_deleted]
self._roots.append(new_root)
for i, feature_name in enumerate(shared_feature_names):
self.set_unit_spike_features(new_root_id, feature_name, np.concatenate(shared_features[i])[sort_indices])
else:
raise ValueError(str(unit_ids) + " has one or more invalid unit ids") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:split_unit; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:unit_id; 6, identifier:indices; 7, block; 7, 8; 7, 10; 7, 14; 7, 43; 8, expression_statement; 8, 9; 9, string:'''This function splits a root from the curation tree according to the given unit_id and indices. It creates two new unit_ids
and roots that have the split root as a child. This function splits the spike train of the root by the given indices.
Parameters
----------
unit_id: int
The unit id to be split
indices: list
The indices of the unit spike train at which the spike train will be split.
'''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:root_ids; 13, list:[]; 14, for_statement; 14, 15; 14, 16; 14, 25; 15, identifier:i; 16, call; 16, 17; 16, 18; 17, identifier:range; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:_roots; 25, block; 25, 26; 25, 36; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:root_id; 29, attribute; 29, 30; 29, 35; 30, subscript; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_roots; 34, identifier:i; 35, identifier:unit_id; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:root_ids; 40, identifier:append; 41, argument_list; 41, 42; 42, identifier:root_id; 43, if_statement; 43, 44; 43, 48; 43, 306; 44, parenthesized_expression; 44, 45; 45, comparison_operator:in; 45, 46; 45, 47; 46, identifier:unit_id; 47, identifier:root_ids; 48, block; 48, 49; 48, 69; 48, 78; 48, 86; 48, 98; 48, 124; 48, 145; 48, 151; 48, 153; 48, 164; 48, 173; 48, 180; 48, 187; 48, 194; 48, 205; 48, 214; 48, 221; 48, 228; 48, 235; 48, 244; 48, 253; 48, 294; 48, 300; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:indices_1; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:np; 55, identifier:sort; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:np; 60, identifier:asarray; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:list; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:set; 67, argument_list; 67, 68; 68, identifier:indices; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:root_index; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:root_ids; 75, identifier:index; 76, argument_list; 76, 77; 77, identifier:unit_id; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:new_child; 81, subscript; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:_roots; 85, identifier:root_index; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:original_spike_train; 89, call; 89, 90; 89, 97; 90, attribute; 90, 91; 90, 96; 91, subscript; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:_roots; 95, identifier:root_index; 96, identifier:get_spike_train; 97, argument_list; 98, try_statement; 98, 99; 98, 106; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:spike_train_1; 103, subscript; 103, 104; 103, 105; 104, identifier:original_spike_train; 105, identifier:indices_1; 106, except_clause; 106, 107; 106, 108; 107, identifier:IndexError; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:print; 112, argument_list; 112, 113; 113, binary_operator:+; 113, 114; 113, 120; 114, binary_operator:+; 114, 115; 114, 119; 115, call; 115, 116; 115, 117; 116, identifier:str; 117, argument_list; 117, 118; 118, identifier:indices; 119, string:" out of bounds for the spike train of "; 120, call; 120, 121; 120, 122; 121, identifier:str; 122, argument_list; 122, 123; 123, identifier:unit_id; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:indices_2; 127, call; 127, 128; 127, 129; 128, identifier:list; 129, argument_list; 129, 130; 130, binary_operator:-; 130, 131; 130, 141; 131, call; 131, 132; 131, 133; 132, identifier:set; 133, argument_list; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:range; 136, argument_list; 136, 137; 137, call; 137, 138; 137, 139; 138, identifier:len; 139, argument_list; 139, 140; 140, identifier:original_spike_train; 141, call; 141, 142; 141, 143; 142, identifier:set; 143, argument_list; 143, 144; 144, identifier:indices_1; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:spike_train_2; 148, subscript; 148, 149; 148, 150; 149, identifier:original_spike_train; 150, identifier:indices_2; 151, delete_statement; 151, 152; 152, identifier:original_spike_train; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:new_root_1_id; 156, binary_operator:+; 156, 157; 156, 163; 157, call; 157, 158; 157, 159; 158, identifier:max; 159, argument_list; 159, 160; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:_all_ids; 163, integer:1; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:_all_ids; 170, identifier:append; 171, argument_list; 171, 172; 172, identifier:new_root_1_id; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:new_root_1; 176, call; 176, 177; 176, 178; 177, identifier:Unit; 178, argument_list; 178, 179; 179, identifier:new_root_1_id; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:new_root_1; 184, identifier:add_child; 185, argument_list; 185, 186; 186, identifier:new_child; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:new_root_1; 191, identifier:set_spike_train; 192, argument_list; 192, 193; 193, identifier:spike_train_1; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:new_root_2_id; 197, binary_operator:+; 197, 198; 197, 204; 198, call; 198, 199; 198, 200; 199, identifier:max; 200, argument_list; 200, 201; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:_all_ids; 204, integer:1; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 212; 207, attribute; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:_all_ids; 211, identifier:append; 212, argument_list; 212, 213; 213, identifier:new_root_2_id; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:new_root_2; 217, call; 217, 218; 217, 219; 218, identifier:Unit; 219, argument_list; 219, 220; 220, identifier:new_root_2_id; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:new_root_2; 225, identifier:add_child; 226, argument_list; 226, 227; 227, identifier:new_child; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:new_root_2; 232, identifier:set_spike_train; 233, argument_list; 233, 234; 234, identifier:spike_train_2; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 242; 237, attribute; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:_roots; 241, identifier:append; 242, argument_list; 242, 243; 243, identifier:new_root_1; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 251; 246, attribute; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:self; 249, identifier:_roots; 250, identifier:append; 251, argument_list; 251, 252; 252, identifier:new_root_2; 253, for_statement; 253, 254; 253, 255; 253, 261; 254, identifier:feature_name; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:get_unit_spike_feature_names; 259, argument_list; 259, 260; 260, identifier:unit_id; 261, block; 261, 262; 261, 272; 261, 283; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:full_features; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:get_unit_spike_features; 269, argument_list; 269, 270; 269, 271; 270, identifier:unit_id; 271, identifier:feature_name; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:set_unit_spike_features; 277, argument_list; 277, 278; 277, 279; 277, 280; 278, identifier:new_root_1_id; 279, identifier:feature_name; 280, subscript; 280, 281; 280, 282; 281, identifier:full_features; 282, identifier:indices_1; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:self; 287, identifier:set_unit_spike_features; 288, argument_list; 288, 289; 288, 290; 288, 291; 289, identifier:new_root_2_id; 290, identifier:feature_name; 291, subscript; 291, 292; 291, 293; 292, identifier:full_features; 293, identifier:indices_2; 294, delete_statement; 294, 295; 295, subscript; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:_unit_features; 299, identifier:unit_id; 300, delete_statement; 300, 301; 301, subscript; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:self; 304, identifier:_roots; 305, identifier:root_index; 306, else_clause; 306, 307; 307, block; 307, 308; 308, raise_statement; 308, 309; 309, call; 309, 310; 309, 311; 310, identifier:ValueError; 311, argument_list; 311, 312; 312, binary_operator:+; 312, 313; 312, 317; 313, call; 313, 314; 313, 315; 314, identifier:str; 315, argument_list; 315, 316; 316, identifier:unit_id; 317, string:" non-valid unit id" | def split_unit(self, unit_id, indices):
'''This function splits a root from the curation tree according to the given unit_id and indices. It creates two new unit_ids
and roots that have the split root as a child. This function splits the spike train of the root by the given indices.
Parameters
----------
unit_id: int
The unit id to be split
indices: list
The indices of the unit spike train at which the spike train will be split.
'''
root_ids = []
for i in range(len(self._roots)):
root_id = self._roots[i].unit_id
root_ids.append(root_id)
if(unit_id in root_ids):
indices_1 = np.sort(np.asarray(list(set(indices))))
root_index = root_ids.index(unit_id)
new_child = self._roots[root_index]
original_spike_train = self._roots[root_index].get_spike_train()
try:
spike_train_1 = original_spike_train[indices_1]
except IndexError:
print(str(indices) + " out of bounds for the spike train of " + str(unit_id))
indices_2 = list(set(range(len(original_spike_train))) - set(indices_1))
spike_train_2 = original_spike_train[indices_2]
del original_spike_train
new_root_1_id = max(self._all_ids)+1
self._all_ids.append(new_root_1_id)
new_root_1 = Unit(new_root_1_id)
new_root_1.add_child(new_child)
new_root_1.set_spike_train(spike_train_1)
new_root_2_id = max(self._all_ids)+1
self._all_ids.append(new_root_2_id)
new_root_2 = Unit(new_root_2_id)
new_root_2.add_child(new_child)
new_root_2.set_spike_train(spike_train_2)
self._roots.append(new_root_1)
self._roots.append(new_root_2)
for feature_name in self.get_unit_spike_feature_names(unit_id):
full_features = self.get_unit_spike_features(unit_id, feature_name)
self.set_unit_spike_features(new_root_1_id, feature_name, full_features[indices_1])
self.set_unit_spike_features(new_root_2_id, feature_name, full_features[indices_2])
del self._unit_features[unit_id]
del self._roots[root_index]
else:
raise ValueError(str(unit_id) + " non-valid unit id") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_find_best_fit; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:pbin; 6, block; 6, 7; 6, 35; 6, 49; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:fit; 10, generator_expression; 10, 11; 10, 24; 11, tuple; 11, 12; 11, 23; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:pbin; 15, identifier:fitness; 16, argument_list; 16, 17; 16, 20; 17, subscript; 17, 18; 17, 19; 18, identifier:r; 19, integer:0; 20, subscript; 20, 21; 20, 22; 21, identifier:r; 22, integer:1; 23, identifier:k; 24, for_in_clause; 24, 25; 24, 28; 25, pattern_list; 25, 26; 25, 27; 26, identifier:k; 27, identifier:r; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_sorted_rect; 33, identifier:items; 34, argument_list; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:fit; 38, generator_expression; 38, 39; 38, 40; 38, 43; 39, identifier:f; 40, for_in_clause; 40, 41; 40, 42; 41, identifier:f; 42, identifier:fit; 43, if_clause; 43, 44; 44, comparison_operator:is; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:f; 47, integer:0; 48, None; 49, try_statement; 49, 50; 49, 67; 50, block; 50, 51; 50, 65; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, pattern_list; 53, 54; 53, 55; 54, identifier:_; 55, identifier:rect; 56, call; 56, 57; 56, 58; 57, identifier:min; 58, argument_list; 58, 59; 58, 60; 59, identifier:fit; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:key; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:first_item; 65, return_statement; 65, 66; 66, identifier:rect; 67, except_clause; 67, 68; 67, 69; 68, identifier:ValueError; 69, block; 69, 70; 70, return_statement; 70, 71; 71, None | def _find_best_fit(self, pbin):
fit = ((pbin.fitness(r[0], r[1]), k) for k, r in self._sorted_rect.items())
fit = (f for f in fit if f[0] is not None)
try:
_, rect = min(fit, key=self.first_item)
return rect
except ValueError:
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_item_attributes_match; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:crypto_config; 5, identifier:plaintext_item; 6, identifier:encrypted_item; 7, block; 7, 8; 7, 45; 8, for_statement; 8, 9; 8, 12; 8, 17; 9, pattern_list; 9, 10; 9, 11; 10, identifier:name; 11, identifier:value; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:plaintext_item; 15, identifier:items; 16, argument_list; 17, block; 17, 18; 17, 33; 18, if_statement; 18, 19; 18, 31; 19, comparison_operator:==; 19, 20; 19, 28; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:crypto_config; 24, identifier:attribute_actions; 25, identifier:action; 26, argument_list; 26, 27; 27, identifier:name; 28, attribute; 28, 29; 28, 30; 29, identifier:CryptoAction; 30, identifier:ENCRYPT_AND_SIGN; 31, block; 31, 32; 32, continue_statement; 33, if_statement; 33, 34; 33, 42; 34, comparison_operator:!=; 34, 35; 34, 41; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:encrypted_item; 38, identifier:get; 39, argument_list; 39, 40; 40, identifier:name; 41, identifier:value; 42, block; 42, 43; 43, return_statement; 43, 44; 44, False; 45, return_statement; 45, 46; 46, True | def _item_attributes_match(crypto_config, plaintext_item, encrypted_item):
for name, value in plaintext_item.items():
if crypto_config.attribute_actions.action(name) == CryptoAction.ENCRYPT_AND_SIGN:
continue
if encrypted_item.get(name) != value:
return False
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:load_css; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 16; 5, 25; 5, 36; 5, 45; 5, 181; 5, 187; 5, 231; 5, 253; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:icons; 9, call; 9, 10; 9, 11; 10, identifier:dict; 11, argument_list; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:common_prefix; 15, None; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:parser; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:tinycss; 22, identifier:make_parser; 23, argument_list; 23, 24; 24, string:'page3'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:stylesheet; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:parser; 31, identifier:parse_stylesheet_file; 32, argument_list; 32, 33; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:css_file; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:is_icon; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:re; 42, identifier:compile; 43, argument_list; 43, 44; 44, string:"\.(.*):before,?"; 45, for_statement; 45, 46; 45, 47; 45, 50; 46, identifier:rule; 47, attribute; 47, 48; 47, 49; 48, identifier:stylesheet; 49, identifier:rules; 50, block; 50, 51; 50, 61; 50, 71; 50, 103; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:selector; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:rule; 58, identifier:selector; 59, identifier:as_css; 60, argument_list; 61, if_statement; 61, 62; 61, 69; 62, not_operator; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:is_icon; 66, identifier:match; 67, argument_list; 67, 68; 68, identifier:selector; 69, block; 69, 70; 70, continue_statement; 71, if_statement; 71, 72; 71, 75; 71, 84; 72, comparison_operator:is; 72, 73; 72, 74; 73, identifier:common_prefix; 74, None; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:common_prefix; 79, subscript; 79, 80; 79, 81; 80, identifier:selector; 81, slice; 81, 82; 81, 83; 82, integer:1; 83, colon; 84, else_clause; 84, 85; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:common_prefix; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:os; 93, identifier:path; 94, identifier:commonprefix; 95, argument_list; 95, 96; 96, tuple; 96, 97; 96, 98; 97, identifier:common_prefix; 98, subscript; 98, 99; 98, 100; 99, identifier:selector; 100, slice; 100, 101; 100, 102; 101, integer:1; 102, colon; 103, for_statement; 103, 104; 103, 105; 103, 111; 104, identifier:match; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:is_icon; 108, identifier:finditer; 109, argument_list; 109, 110; 110, identifier:selector; 111, block; 111, 112; 111, 122; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:name; 115, subscript; 115, 116; 115, 121; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:match; 119, identifier:groups; 120, argument_list; 121, integer:0; 122, for_statement; 122, 123; 122, 124; 122, 127; 123, identifier:declaration; 124, attribute; 124, 125; 124, 126; 125, identifier:rule; 126, identifier:declarations; 127, block; 127, 128; 128, if_statement; 128, 129; 128, 134; 129, comparison_operator:==; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:declaration; 132, identifier:name; 133, string:"content"; 134, block; 134, 135; 134, 145; 134, 164; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:val; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:declaration; 142, identifier:value; 143, identifier:as_css; 144, argument_list; 145, if_statement; 145, 146; 145, 153; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:re; 149, identifier:match; 150, argument_list; 150, 151; 150, 152; 151, string:"^['\"].*['\"]$"; 152, identifier:val; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:val; 157, subscript; 157, 158; 157, 159; 158, identifier:val; 159, slice; 159, 160; 159, 161; 159, 162; 160, integer:1; 161, colon; 162, unary_operator:-; 162, 163; 163, integer:1; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:icons; 168, identifier:name; 169, call; 169, 170; 169, 171; 170, identifier:unichr; 171, argument_list; 171, 172; 172, call; 172, 173; 172, 174; 173, identifier:int; 174, argument_list; 174, 175; 174, 180; 175, subscript; 175, 176; 175, 177; 176, identifier:val; 177, slice; 177, 178; 177, 179; 178, integer:1; 179, colon; 180, integer:16; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:common_prefix; 184, boolean_operator:or; 184, 185; 184, 186; 185, identifier:common_prefix; 186, string:''; 187, if_statement; 187, 188; 187, 199; 188, boolean_operator:and; 188, 189; 188, 193; 189, not_operator; 189, 190; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:keep_prefix; 193, comparison_operator:>; 193, 194; 193, 198; 194, call; 194, 195; 194, 196; 195, identifier:len; 196, argument_list; 196, 197; 197, identifier:common_prefix; 198, integer:0; 199, block; 199, 200; 199, 204; 199, 227; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:non_prefixed_icons; 203, dictionary; 204, for_statement; 204, 205; 204, 206; 204, 211; 205, identifier:name; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:icons; 209, identifier:keys; 210, argument_list; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 224; 214, subscript; 214, 215; 214, 216; 215, identifier:non_prefixed_icons; 216, subscript; 216, 217; 216, 218; 217, identifier:name; 218, slice; 218, 219; 218, 223; 219, call; 219, 220; 219, 221; 220, identifier:len; 221, argument_list; 221, 222; 222, identifier:common_prefix; 223, colon; 224, subscript; 224, 225; 224, 226; 225, identifier:icons; 226, identifier:name; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:icons; 230, identifier:non_prefixed_icons; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:sorted_icons; 234, call; 234, 235; 234, 236; 235, identifier:OrderedDict; 236, argument_list; 236, 237; 237, call; 237, 238; 237, 239; 238, identifier:sorted; 239, argument_list; 239, 240; 239, 245; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:icons; 243, identifier:items; 244, argument_list; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:key; 247, lambda; 247, 248; 247, 250; 248, lambda_parameters; 248, 249; 249, identifier:t; 250, subscript; 250, 251; 250, 252; 251, identifier:t; 252, integer:0; 253, return_statement; 253, 254; 254, expression_list; 254, 255; 254, 256; 255, identifier:sorted_icons; 256, identifier:common_prefix | def load_css(self):
icons = dict()
common_prefix = None
parser = tinycss.make_parser('page3')
stylesheet = parser.parse_stylesheet_file(self.css_file)
is_icon = re.compile("\.(.*):before,?")
for rule in stylesheet.rules:
selector = rule.selector.as_css()
if not is_icon.match(selector):
continue
if common_prefix is None:
common_prefix = selector[1:]
else:
common_prefix = os.path.commonprefix((common_prefix,
selector[1:]))
for match in is_icon.finditer(selector):
name = match.groups()[0]
for declaration in rule.declarations:
if declaration.name == "content":
val = declaration.value.as_css()
if re.match("^['\"].*['\"]$", val):
val = val[1:-1]
icons[name] = unichr(int(val[1:], 16))
common_prefix = common_prefix or ''
if not self.keep_prefix and len(common_prefix) > 0:
non_prefixed_icons = {}
for name in icons.keys():
non_prefixed_icons[name[len(common_prefix):]] = icons[name]
icons = non_prefixed_icons
sorted_icons = OrderedDict(sorted(icons.items(), key=lambda t: t[0]))
return sorted_icons, common_prefix |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:rules; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 252; 5, 325; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:list_of_rules; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 15; 11, identifier:main_row; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:dict_rules; 15, block; 15, 16; 16, if_statement; 16, 17; 16, 20; 16, 228; 17, comparison_operator:in; 17, 18; 17, 19; 18, string:'rules'; 19, identifier:main_row; 20, block; 20, 21; 21, for_statement; 21, 22; 21, 23; 21, 26; 22, identifier:rule_row; 23, subscript; 23, 24; 23, 25; 24, identifier:main_row; 25, string:'rules'; 26, block; 26, 27; 27, if_statement; 27, 28; 27, 31; 27, 184; 28, comparison_operator:in; 28, 29; 28, 30; 29, string:'grants'; 30, identifier:rule_row; 31, block; 31, 32; 32, for_statement; 32, 33; 32, 34; 32, 37; 33, identifier:grant_row; 34, subscript; 34, 35; 34, 36; 35, identifier:rule_row; 36, string:'grants'; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 42; 38, 119; 38, 176; 39, comparison_operator:in; 39, 40; 39, 41; 40, string:'group_id'; 41, identifier:grant_row; 42, block; 42, 43; 42, 49; 42, 66; 42, 112; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:group_id; 46, subscript; 46, 47; 46, 48; 47, identifier:grant_row; 48, string:'group_id'; 49, if_statement; 49, 50; 49, 53; 49, 60; 50, comparison_operator:in; 50, 51; 50, 52; 51, string:'name'; 52, identifier:grant_row; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:row_name; 57, subscript; 57, 58; 57, 59; 58, identifier:grant_row; 59, string:'name'; 60, else_clause; 60, 61; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:row_name; 65, None; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:fr; 69, call; 69, 70; 69, 71; 70, identifier:FirewallRule; 71, argument_list; 71, 72; 71, 75; 71, 78; 71, 81; 71, 86; 71, 91; 71, 96; 71, 101; 71, 104; 71, 107; 72, subscript; 72, 73; 72, 74; 73, identifier:main_row; 74, string:'id'; 75, subscript; 75, 76; 75, 77; 76, identifier:main_row; 77, string:'name'; 78, subscript; 78, 79; 78, 80; 79, identifier:main_row; 80, string:'description'; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:rules_direction; 83, subscript; 83, 84; 83, 85; 84, identifier:rule_row; 85, string:'direction'; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:rules_ip_protocol; 88, subscript; 88, 89; 88, 90; 89, identifier:rule_row; 90, string:'ip_protocol'; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:rules_from_port; 93, subscript; 93, 94; 93, 95; 94, identifier:rule_row; 95, string:'from_port'; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:rules_to_port; 98, subscript; 98, 99; 98, 100; 99, identifier:rule_row; 100, string:'to_port'; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:rules_grants_group_id; 103, identifier:group_id; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:rules_grants_name; 106, identifier:row_name; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:rules_description; 109, subscript; 109, 110; 109, 111; 110, identifier:grant_row; 111, string:'description'; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:list_of_rules; 116, identifier:append; 117, argument_list; 117, 118; 118, identifier:fr; 119, elif_clause; 119, 120; 119, 123; 120, comparison_operator:in; 120, 121; 120, 122; 121, string:'cidr_ip'; 122, identifier:grant_row; 123, block; 123, 124; 123, 169; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:fr; 127, call; 127, 128; 127, 129; 128, identifier:FirewallRule; 129, argument_list; 129, 130; 129, 133; 129, 136; 129, 139; 129, 144; 129, 149; 129, 154; 129, 159; 129, 164; 130, subscript; 130, 131; 130, 132; 131, identifier:main_row; 132, string:'id'; 133, subscript; 133, 134; 133, 135; 134, identifier:main_row; 135, string:'name'; 136, subscript; 136, 137; 136, 138; 137, identifier:main_row; 138, string:'description'; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:rules_direction; 141, subscript; 141, 142; 141, 143; 142, identifier:rule_row; 143, string:'direction'; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:rules_ip_protocol; 146, subscript; 146, 147; 146, 148; 147, identifier:rule_row; 148, string:'ip_protocol'; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:rules_from_port; 151, subscript; 151, 152; 151, 153; 152, identifier:rule_row; 153, string:'from_port'; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:rules_to_port; 156, subscript; 156, 157; 156, 158; 157, identifier:rule_row; 158, string:'to_port'; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:rules_grants_cidr_ip; 161, subscript; 161, 162; 161, 163; 162, identifier:grant_row; 163, string:'cidr_ip'; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:rules_description; 166, subscript; 166, 167; 166, 168; 167, identifier:grant_row; 168, string:'description'; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:list_of_rules; 173, identifier:append; 174, argument_list; 174, 175; 175, identifier:fr; 176, else_clause; 176, 177; 177, block; 177, 178; 178, raise_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:ValueError; 181, argument_list; 181, 182; 181, 183; 182, string:"Unsupported grant:"; 183, identifier:grant_row; 184, else_clause; 184, 185; 185, block; 185, 186; 185, 221; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:fr; 189, call; 189, 190; 189, 191; 190, identifier:FirewallRule; 191, argument_list; 191, 192; 191, 195; 191, 198; 191, 201; 191, 206; 191, 211; 191, 216; 192, subscript; 192, 193; 192, 194; 193, identifier:main_row; 194, string:'id'; 195, subscript; 195, 196; 195, 197; 196, identifier:main_row; 197, string:'name'; 198, subscript; 198, 199; 198, 200; 199, identifier:main_row; 200, string:'description'; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:rules_direction; 203, subscript; 203, 204; 203, 205; 204, identifier:rule_row; 205, string:'direction'; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:rules_ip_protocol; 208, subscript; 208, 209; 208, 210; 209, identifier:rule_row; 210, string:'ip_protocol'; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:rules_from_port; 213, subscript; 213, 214; 213, 215; 214, identifier:rule_row; 215, string:'from_port'; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:rules_to_port; 218, subscript; 218, 219; 218, 220; 219, identifier:rule_row; 220, string:'to_port'; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:list_of_rules; 225, identifier:append; 226, argument_list; 226, 227; 227, identifier:fr; 228, else_clause; 228, 229; 229, block; 229, 230; 229, 245; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:fr; 233, call; 233, 234; 233, 235; 234, identifier:FirewallRule; 235, argument_list; 235, 236; 235, 239; 235, 242; 236, subscript; 236, 237; 236, 238; 237, identifier:main_row; 238, string:'id'; 239, subscript; 239, 240; 239, 241; 240, identifier:main_row; 241, string:'name'; 242, subscript; 242, 243; 242, 244; 243, identifier:main_row; 244, string:'description'; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:list_of_rules; 249, identifier:append; 250, argument_list; 250, 251; 251, identifier:fr; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:sorted_list; 255, call; 255, 256; 255, 257; 256, identifier:sorted; 257, argument_list; 257, 258; 257, 259; 258, identifier:list_of_rules; 259, keyword_argument; 259, 260; 259, 261; 260, identifier:key; 261, lambda; 261, 262; 261, 264; 262, lambda_parameters; 262, 263; 263, identifier:fr; 264, tuple; 264, 265; 264, 271; 264, 277; 264, 283; 264, 289; 264, 295; 264, 301; 264, 307; 264, 313; 264, 319; 265, call; 265, 266; 265, 267; 266, identifier:str; 267, argument_list; 267, 268; 268, attribute; 268, 269; 268, 270; 269, identifier:fr; 270, identifier:id; 271, call; 271, 272; 271, 273; 272, identifier:str; 273, argument_list; 273, 274; 274, attribute; 274, 275; 274, 276; 275, identifier:fr; 276, identifier:name; 277, call; 277, 278; 277, 279; 278, identifier:str; 279, argument_list; 279, 280; 280, attribute; 280, 281; 280, 282; 281, identifier:fr; 282, identifier:description; 283, call; 283, 284; 283, 285; 284, identifier:str; 285, argument_list; 285, 286; 286, attribute; 286, 287; 286, 288; 287, identifier:fr; 288, identifier:rules_direction; 289, call; 289, 290; 289, 291; 290, identifier:str; 291, argument_list; 291, 292; 292, attribute; 292, 293; 292, 294; 293, identifier:fr; 294, identifier:rules_ip_protocol; 295, call; 295, 296; 295, 297; 296, identifier:str; 297, argument_list; 297, 298; 298, attribute; 298, 299; 298, 300; 299, identifier:fr; 300, identifier:rules_from_port; 301, call; 301, 302; 301, 303; 302, identifier:str; 303, argument_list; 303, 304; 304, attribute; 304, 305; 304, 306; 305, identifier:fr; 306, identifier:rules_to_port; 307, call; 307, 308; 307, 309; 308, identifier:str; 309, argument_list; 309, 310; 310, attribute; 310, 311; 310, 312; 311, identifier:fr; 312, identifier:rules_grants_group_id; 313, call; 313, 314; 313, 315; 314, identifier:str; 315, argument_list; 315, 316; 316, attribute; 316, 317; 316, 318; 317, identifier:fr; 318, identifier:rules_grants_name; 319, call; 319, 320; 319, 321; 320, identifier:str; 321, argument_list; 321, 322; 322, attribute; 322, 323; 322, 324; 323, identifier:fr; 324, identifier:rules_grants_cidr_ip; 325, return_statement; 325, 326; 326, identifier:sorted_list | def rules(self):
list_of_rules = []
for main_row in self.dict_rules:
if 'rules' in main_row:
for rule_row in main_row['rules']:
if 'grants' in rule_row:
for grant_row in rule_row['grants']:
if 'group_id' in grant_row:
group_id = grant_row['group_id']
if 'name' in grant_row:
row_name = grant_row['name']
else:
row_name = None
fr = FirewallRule(
main_row['id'],
main_row['name'],
main_row['description'],
rules_direction=rule_row['direction'],
rules_ip_protocol=rule_row['ip_protocol'],
rules_from_port=rule_row['from_port'],
rules_to_port=rule_row['to_port'],
rules_grants_group_id=group_id,
rules_grants_name=row_name,
rules_description=grant_row['description'])
list_of_rules.append(fr)
elif 'cidr_ip' in grant_row:
fr = FirewallRule(
main_row['id'],
main_row['name'],
main_row['description'],
rules_direction=rule_row['direction'],
rules_ip_protocol=rule_row['ip_protocol'],
rules_from_port=rule_row['from_port'],
rules_to_port=rule_row['to_port'],
rules_grants_cidr_ip=grant_row['cidr_ip'],
rules_description=grant_row['description'])
list_of_rules.append(fr)
else:
raise ValueError("Unsupported grant:",
grant_row)
else:
fr = FirewallRule(
main_row['id'],
main_row['name'],
main_row['description'],
rules_direction=rule_row['direction'],
rules_ip_protocol=rule_row['ip_protocol'],
rules_from_port=rule_row['from_port'],
rules_to_port=rule_row['to_port'])
list_of_rules.append(fr)
else:
fr = FirewallRule(main_row['id'],
main_row['name'],
main_row['description'])
list_of_rules.append(fr)
sorted_list = sorted(list_of_rules,
key=lambda fr: (str(fr.id),
str(fr.name),
str(fr.description),
str(fr.rules_direction),
str(fr.rules_ip_protocol),
str(fr.rules_from_port),
str(fr.rules_to_port),
str(fr.rules_grants_group_id),
str(fr.rules_grants_name),
str(fr.rules_grants_cidr_ip)))
return sorted_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_select_mgmt_networks; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:conf; 6, block; 6, 7; 6, 13; 6, 39; 6, 84; 6, 109; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:nets; 10, subscript; 10, 11; 10, 12; 11, identifier:conf; 12, string:'nets'; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:mgmts; 16, call; 16, 17; 16, 18; 17, identifier:sorted; 18, argument_list; 18, 19; 19, list_comprehension; 19, 20; 19, 21; 19, 30; 20, identifier:name; 21, for_in_clause; 21, 22; 21, 25; 22, pattern_list; 22, 23; 22, 24; 23, identifier:name; 24, identifier:net; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:nets; 28, identifier:iteritems; 29, argument_list; 30, if_clause; 30, 31; 31, comparison_operator:is; 31, 32; 31, 38; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:net; 35, identifier:get; 36, argument_list; 36, 37; 37, string:'management'; 38, True; 39, if_statement; 39, 40; 39, 46; 40, comparison_operator:==; 40, 41; 40, 45; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:mgmts; 45, integer:0; 46, block; 46, 47; 46, 61; 46, 69; 46, 77; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:mgmt_name; 50, subscript; 50, 51; 50, 60; 51, call; 51, 52; 51, 53; 52, identifier:sorted; 53, argument_list; 53, 54; 54, parenthesized_expression; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:nets; 58, identifier:keys; 59, argument_list; 60, integer:0; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:LOGGER; 65, identifier:debug; 66, argument_list; 66, 67; 66, 68; 67, string:'No management network configured, selecting network %s'; 68, identifier:mgmt_name; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 76; 71, subscript; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:nets; 74, identifier:mgmt_name; 75, string:'management'; 76, True; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:mgmts; 81, identifier:append; 82, argument_list; 82, 83; 83, identifier:mgmt_name; 84, for_statement; 84, 85; 84, 86; 84, 87; 85, identifier:mgmt_name; 86, identifier:mgmts; 87, block; 87, 88; 88, if_statement; 88, 89; 88, 100; 89, comparison_operator:is; 89, 90; 89, 99; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:nets; 94, identifier:mgmt_name; 95, identifier:get; 96, argument_list; 96, 97; 96, 98; 97, string:'dns_domain_name'; 98, None; 99, None; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 108; 103, subscript; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:nets; 106, identifier:mgmt_name; 107, string:'dns_domain_name'; 108, string:'lago.local'; 109, return_statement; 109, 110; 110, identifier:mgmts | def _select_mgmt_networks(self, conf):
nets = conf['nets']
mgmts = sorted(
[
name for name, net in nets.iteritems()
if net.get('management') is True
]
)
if len(mgmts) == 0:
mgmt_name = sorted((nets.keys()))[0]
LOGGER.debug(
'No management network configured, selecting network %s',
mgmt_name
)
nets[mgmt_name]['management'] = True
mgmts.append(mgmt_name)
for mgmt_name in mgmts:
if nets[mgmt_name].get('dns_domain_name', None) is None:
nets[mgmt_name]['dns_domain_name'] = 'lago.local'
return mgmts |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:validate_wavetable; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 45; 5, 54; 5, 107; 5, 122; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:wave; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:_wavetable; 12, if_statement; 12, 13; 12, 21; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:N; 16, identifier:any; 17, argument_list; 17, 18; 18, comparison_operator:<=; 18, 19; 18, 20; 19, identifier:wave; 20, integer:0; 21, block; 21, 22; 21, 35; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:wrong; 25, subscript; 25, 26; 25, 34; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:N; 29, identifier:where; 30, argument_list; 30, 31; 31, comparison_operator:<=; 31, 32; 31, 33; 32, identifier:wave; 33, integer:0; 34, integer:0; 35, raise_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:exceptions; 39, identifier:ZeroWavelength; 40, argument_list; 40, 41; 40, 42; 41, string:'Negative or Zero wavelength occurs in wavelength array'; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:rows; 44, identifier:wrong; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:sorted; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:N; 51, identifier:sort; 52, argument_list; 52, 53; 53, identifier:wave; 54, if_statement; 54, 55; 54, 64; 55, not_operator; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:N; 59, identifier:alltrue; 60, argument_list; 60, 61; 61, comparison_operator:==; 61, 62; 61, 63; 62, identifier:sorted; 63, identifier:wave; 64, block; 64, 65; 65, if_statement; 65, 66; 65, 80; 65, 82; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:N; 69, identifier:alltrue; 70, argument_list; 70, 71; 71, comparison_operator:==; 71, 72; 71, 79; 72, subscript; 72, 73; 72, 74; 73, identifier:sorted; 74, slice; 74, 75; 74, 76; 74, 77; 75, colon; 76, colon; 77, unary_operator:-; 77, 78; 78, integer:1; 79, identifier:wave; 80, block; 80, 81; 81, pass_statement; 82, else_clause; 82, 83; 83, block; 83, 84; 83, 97; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:wrong; 87, subscript; 87, 88; 87, 96; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:N; 91, identifier:where; 92, argument_list; 92, 93; 93, comparison_operator:!=; 93, 94; 93, 95; 94, identifier:sorted; 95, identifier:wave; 96, integer:0; 97, raise_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:exceptions; 101, identifier:UnsortedWavelength; 102, argument_list; 102, 103; 102, 104; 103, string:'Wavelength array is not monotonic'; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:rows; 106, identifier:wrong; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:dw; 110, binary_operator:-; 110, 111; 110, 116; 111, subscript; 111, 112; 111, 113; 112, identifier:sorted; 113, slice; 113, 114; 113, 115; 114, integer:1; 115, colon; 116, subscript; 116, 117; 116, 118; 117, identifier:sorted; 118, slice; 118, 119; 118, 120; 119, colon; 120, unary_operator:-; 120, 121; 121, integer:1; 122, if_statement; 122, 123; 122, 131; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:N; 126, identifier:any; 127, argument_list; 127, 128; 128, comparison_operator:==; 128, 129; 128, 130; 129, identifier:dw; 130, integer:0; 131, block; 131, 132; 131, 145; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:wrong; 135, subscript; 135, 136; 135, 144; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:N; 139, identifier:where; 140, argument_list; 140, 141; 141, comparison_operator:==; 141, 142; 141, 143; 142, identifier:dw; 143, integer:0; 144, integer:0; 145, raise_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:exceptions; 149, identifier:DuplicateWavelength; 150, argument_list; 150, 151; 150, 152; 151, string:"Wavelength array contains duplicate entries"; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:rows; 154, identifier:wrong | def validate_wavetable(self):
wave = self._wavetable
if N.any(wave <= 0):
wrong = N.where(wave <= 0)[0]
raise exceptions.ZeroWavelength(
'Negative or Zero wavelength occurs in wavelength array',
rows=wrong)
sorted = N.sort(wave)
if not N.alltrue(sorted == wave):
if N.alltrue(sorted[::-1] == wave):
pass
else:
wrong = N.where(sorted != wave)[0]
raise exceptions.UnsortedWavelength(
'Wavelength array is not monotonic', rows=wrong)
dw = sorted[1:] - sorted[:-1]
if N.any(dw == 0):
wrong = N.where(dw == 0)[0]
raise exceptions.DuplicateWavelength(
"Wavelength array contains duplicate entries", rows=wrong) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:getStateIndex; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:state; 6, block; 6, 7; 6, 16; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:statecodes; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:getStateCode; 14, argument_list; 14, 15; 15, identifier:state; 16, return_statement; 16, 17; 17, call; 17, 18; 17, 29; 18, attribute; 18, 19; 18, 28; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:np; 22, identifier:searchsorted; 23, argument_list; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:codes; 27, identifier:statecodes; 28, identifier:astype; 29, argument_list; 29, 30; 30, identifier:int | def getStateIndex(self,state):
statecodes = self.getStateCode(state)
return np.searchsorted(self.codes,statecodes).astype(int) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:guess_chimera_path; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:search_all; 6, False; 7, block; 7, 8; 7, 20; 7, 55; 7, 71; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:paths; 11, call; 11, 12; 11, 13; 12, identifier:_search_chimera; 13, argument_list; 13, 14; 13, 15; 13, 16; 13, 17; 14, identifier:CHIMERA_BINARY; 15, identifier:CHIMERA_LOCATIONS; 16, identifier:CHIMERA_PREFIX; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:search_all; 19, identifier:search_all; 20, if_statement; 20, 21; 20, 25; 21, boolean_operator:and; 21, 22; 21, 24; 22, not_operator; 22, 23; 23, identifier:paths; 24, identifier:search_all; 25, block; 25, 26; 25, 43; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:headless; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, string:'{0[0]}{1}{0[1]}'; 32, identifier:format; 33, argument_list; 33, 34; 33, 42; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:os; 38, identifier:path; 39, identifier:split; 40, argument_list; 40, 41; 41, identifier:CHIMERA_BINARY; 42, string:'-headless'; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:paths; 46, call; 46, 47; 46, 48; 47, identifier:_search_chimera; 48, argument_list; 48, 49; 48, 50; 48, 51; 48, 52; 49, identifier:headless; 50, identifier:CHIMERA_LOCATIONS; 51, identifier:CHIMERA_PREFIX; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:search_all; 54, identifier:search_all; 55, if_statement; 55, 56; 55, 58; 56, not_operator; 56, 57; 57, identifier:paths; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:sys; 63, identifier:exit; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, string:"Could not find UCSF Chimera.\n{}"; 68, identifier:format; 69, argument_list; 69, 70; 70, identifier:_INSTRUCTIONS; 71, return_statement; 71, 72; 72, identifier:paths | def guess_chimera_path(search_all=False):
paths = _search_chimera(CHIMERA_BINARY, CHIMERA_LOCATIONS, CHIMERA_PREFIX,
search_all=search_all)
if not paths and search_all:
headless = '{0[0]}{1}{0[1]}'.format(os.path.split(CHIMERA_BINARY), '-headless')
paths = _search_chimera(headless, CHIMERA_LOCATIONS, CHIMERA_PREFIX,
search_all=search_all)
if not paths:
sys.exit("Could not find UCSF Chimera.\n{}".format(_INSTRUCTIONS))
return paths |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_topo_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:forward; 7, True; 8, block; 8, 9; 8, 13; 8, 19; 8, 23; 8, 64; 8, 97; 8, 154; 8, 179; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:topo_list; 12, list:[]; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:queue; 16, call; 16, 17; 16, 18; 17, identifier:deque; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:indeg; 22, dictionary; 23, if_statement; 23, 24; 23, 25; 23, 44; 24, identifier:forward; 25, block; 25, 26; 25, 32; 25, 38; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:get_edges; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:out_edges; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:get_degree; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:inc_degree; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:get_next; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:tail; 44, else_clause; 44, 45; 45, block; 45, 46; 45, 52; 45, 58; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:get_edges; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:inc_edges; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:get_degree; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:out_degree; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:get_next; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:head; 64, for_statement; 64, 65; 64, 66; 64, 71; 65, identifier:node; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:node_list; 70, argument_list; 71, block; 71, 72; 71, 79; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:degree; 75, call; 75, 76; 75, 77; 76, identifier:get_degree; 77, argument_list; 77, 78; 78, identifier:node; 79, if_statement; 79, 80; 79, 81; 79, 88; 80, identifier:degree; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:indeg; 86, identifier:node; 87, identifier:degree; 88, else_clause; 88, 89; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:queue; 94, identifier:append; 95, argument_list; 95, 96; 96, identifier:node; 97, while_statement; 97, 98; 97, 99; 98, identifier:queue; 99, block; 99, 100; 99, 108; 99, 115; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:curr_node; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:queue; 106, identifier:popleft; 107, argument_list; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:topo_list; 112, identifier:append; 113, argument_list; 113, 114; 114, identifier:curr_node; 115, for_statement; 115, 116; 115, 117; 115, 121; 116, identifier:edge; 117, call; 117, 118; 117, 119; 118, identifier:get_edges; 119, argument_list; 119, 120; 120, identifier:curr_node; 121, block; 121, 122; 121, 129; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:tail_id; 125, call; 125, 126; 125, 127; 126, identifier:get_next; 127, argument_list; 127, 128; 128, identifier:edge; 129, if_statement; 129, 130; 129, 133; 130, comparison_operator:in; 130, 131; 130, 132; 131, identifier:tail_id; 132, identifier:indeg; 133, block; 133, 134; 133, 140; 134, expression_statement; 134, 135; 135, augmented_assignment:-=; 135, 136; 135, 139; 136, subscript; 136, 137; 136, 138; 137, identifier:indeg; 138, identifier:tail_id; 139, integer:1; 140, if_statement; 140, 141; 140, 146; 141, comparison_operator:==; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:indeg; 144, identifier:tail_id; 145, integer:0; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:queue; 151, identifier:append; 152, argument_list; 152, 153; 153, identifier:tail_id; 154, if_statement; 154, 155; 154, 168; 154, 173; 155, comparison_operator:==; 155, 156; 155, 160; 156, call; 156, 157; 156, 158; 157, identifier:len; 158, argument_list; 158, 159; 159, identifier:topo_list; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:node_list; 167, argument_list; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:valid; 172, True; 173, else_clause; 173, 174; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:valid; 178, False; 179, return_statement; 179, 180; 180, tuple; 180, 181; 180, 182; 181, identifier:valid; 182, identifier:topo_list | def _topo_sort(self, forward=True):
topo_list = []
queue = deque()
indeg = {}
if forward:
get_edges = self.out_edges
get_degree = self.inc_degree
get_next = self.tail
else:
get_edges = self.inc_edges
get_degree = self.out_degree
get_next = self.head
for node in self.node_list():
degree = get_degree(node)
if degree:
indeg[node] = degree
else:
queue.append(node)
while queue:
curr_node = queue.popleft()
topo_list.append(curr_node)
for edge in get_edges(curr_node):
tail_id = get_next(edge)
if tail_id in indeg:
indeg[tail_id] -= 1
if indeg[tail_id] == 0:
queue.append(tail_id)
if len(topo_list) == len(self.node_list()):
valid = True
else:
valid = False
return (valid, topo_list) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 34; 2, function_name:execute_sql; 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:server_context; 5, identifier:schema_name; 6, identifier:sql; 7, default_parameter; 7, 8; 7, 9; 8, identifier:container_path; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:max_rows; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:sort; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:offset; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:container_filter; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:save_in_session; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:parameters; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:required_version; 30, None; 31, default_parameter; 31, 32; 31, 33; 32, identifier:timeout; 33, identifier:_default_timeout; 34, block; 34, 35; 34, 48; 34, 58; 34, 69; 34, 80; 34, 91; 34, 102; 34, 113; 34, 136; 34, 147; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:url; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:server_context; 41, identifier:build_url; 42, argument_list; 42, 43; 42, 44; 42, 45; 43, string:'query'; 44, string:'executeSql.api'; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:container_path; 47, identifier:container_path; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:payload; 51, dictionary; 51, 52; 51, 55; 52, pair; 52, 53; 52, 54; 53, string:'schemaName'; 54, identifier:schema_name; 55, pair; 55, 56; 55, 57; 56, string:'sql'; 57, identifier:sql; 58, if_statement; 58, 59; 58, 62; 59, comparison_operator:is; 59, 60; 59, 61; 60, identifier:container_filter; 61, None; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:payload; 67, string:'containerFilter'; 68, identifier:container_filter; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:is; 70, 71; 70, 72; 71, identifier:max_rows; 72, None; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:payload; 78, string:'maxRows'; 79, identifier:max_rows; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:is; 81, 82; 81, 83; 82, identifier:offset; 83, None; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:payload; 89, string:'offset'; 90, identifier:offset; 91, if_statement; 91, 92; 91, 95; 92, comparison_operator:is; 92, 93; 92, 94; 93, identifier:sort; 94, None; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:payload; 100, string:'query.sort'; 101, identifier:sort; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:save_in_session; 105, None; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:payload; 111, string:'saveInSession'; 112, identifier:save_in_session; 113, if_statement; 113, 114; 113, 117; 114, comparison_operator:is; 114, 115; 114, 116; 115, identifier:parameters; 116, None; 117, block; 117, 118; 118, for_statement; 118, 119; 118, 122; 118, 127; 119, pattern_list; 119, 120; 119, 121; 120, identifier:key; 121, identifier:value; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:parameters; 125, identifier:items; 126, argument_list; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 135; 130, subscript; 130, 131; 130, 132; 131, identifier:payload; 132, binary_operator:+; 132, 133; 132, 134; 133, string:'query.param.'; 134, identifier:key; 135, identifier:value; 136, if_statement; 136, 137; 136, 140; 137, comparison_operator:is; 137, 138; 137, 139; 138, identifier:required_version; 139, None; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:payload; 145, string:'apiVersion'; 146, identifier:required_version; 147, return_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:server_context; 151, identifier:make_request; 152, argument_list; 152, 153; 152, 154; 152, 155; 153, identifier:url; 154, identifier:payload; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:timeout; 157, identifier:timeout | def execute_sql(server_context, schema_name, sql, container_path=None,
max_rows=None,
sort=None,
offset=None,
container_filter=None,
save_in_session=None,
parameters=None,
required_version=None,
timeout=_default_timeout):
url = server_context.build_url('query', 'executeSql.api', container_path=container_path)
payload = {
'schemaName': schema_name,
'sql': sql
}
if container_filter is not None:
payload['containerFilter'] = container_filter
if max_rows is not None:
payload['maxRows'] = max_rows
if offset is not None:
payload['offset'] = offset
if sort is not None:
payload['query.sort'] = sort
if save_in_session is not None:
payload['saveInSession'] = save_in_session
if parameters is not None:
for key, value in parameters.items():
payload['query.param.' + key] = value
if required_version is not None:
payload['apiVersion'] = required_version
return server_context.make_request(url, payload, timeout=timeout) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:find_missing_projections; 3, parameters; 3, 4; 3, 5; 4, identifier:label_list; 5, identifier:projections; 6, block; 6, 7; 6, 13; 6, 20; 6, 58; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:unmapped_combinations; 10, call; 10, 11; 10, 12; 11, identifier:set; 12, argument_list; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:in; 14, 15; 14, 16; 15, identifier:WILDCARD_COMBINATION; 16, identifier:projections; 17, block; 17, 18; 18, return_statement; 18, 19; 19, list:[]; 20, for_statement; 20, 21; 20, 22; 20, 27; 21, identifier:labeled_segment; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:label_list; 25, identifier:ranges; 26, argument_list; 27, block; 27, 28; 27, 46; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:combination; 31, call; 31, 32; 31, 33; 32, identifier:tuple; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:sorted; 36, argument_list; 36, 37; 37, list_comprehension; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:label; 40, identifier:value; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:label; 43, subscript; 43, 44; 43, 45; 44, identifier:labeled_segment; 45, integer:2; 46, if_statement; 46, 47; 46, 50; 47, comparison_operator:not; 47, 48; 47, 49; 48, identifier:combination; 49, identifier:projections; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:unmapped_combinations; 55, identifier:add; 56, argument_list; 56, 57; 57, identifier:combination; 58, return_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:sorted; 61, argument_list; 61, 62; 62, identifier:unmapped_combinations | def find_missing_projections(label_list, projections):
unmapped_combinations = set()
if WILDCARD_COMBINATION in projections:
return []
for labeled_segment in label_list.ranges():
combination = tuple(sorted([label.value for label in labeled_segment[2]]))
if combination not in projections:
unmapped_combinations.add(combination)
return sorted(unmapped_combinations) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:load_projections; 3, parameters; 3, 4; 4, identifier:projections_file; 5, block; 5, 6; 5, 10; 5, 61; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:projections; 9, dictionary; 10, for_statement; 10, 11; 10, 12; 10, 19; 11, identifier:parts; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:textfile; 15, identifier:read_separated_lines_generator; 16, argument_list; 16, 17; 16, 18; 17, identifier:projections_file; 18, string:'|'; 19, block; 19, 20; 19, 45; 19, 55; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:combination; 23, call; 23, 24; 23, 25; 24, identifier:tuple; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:sorted; 28, argument_list; 28, 29; 29, list_comprehension; 29, 30; 29, 35; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:label; 33, identifier:strip; 34, argument_list; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:label; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:parts; 41, integer:0; 42, identifier:split; 43, argument_list; 43, 44; 44, string:' '; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:new_label; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:parts; 52, integer:1; 53, identifier:strip; 54, argument_list; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:projections; 59, identifier:combination; 60, identifier:new_label; 61, return_statement; 61, 62; 62, identifier:projections | def load_projections(projections_file):
projections = {}
for parts in textfile.read_separated_lines_generator(projections_file, '|'):
combination = tuple(sorted([label.strip() for label in parts[0].split(' ')]))
new_label = parts[1].strip()
projections[combination] = new_label
return projections |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:label_values; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 19; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:all_labels; 9, call; 9, 10; 9, 11; 10, identifier:set; 11, argument_list; 11, 12; 12, list_comprehension; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:l; 15, identifier:value; 16, for_in_clause; 16, 17; 16, 18; 17, identifier:l; 18, identifier:self; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:sorted; 22, argument_list; 22, 23; 23, identifier:all_labels | def label_values(self):
all_labels = set([l.value for l in self])
return sorted(all_labels) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_utt_regions; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 14; 5, 129; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:regions; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:current_offset; 13, integer:0; 14, for_statement; 14, 15; 14, 16; 14, 22; 15, identifier:utt_idx; 16, call; 16, 17; 16, 18; 17, identifier:sorted; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:utt_ids; 22, block; 22, 23; 22, 27; 22, 31; 22, 35; 22, 72; 22, 93; 22, 111; 22, 118; 22, 125; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:offset; 26, identifier:current_offset; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:num_frames; 30, list:[]; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:refs; 34, list:[]; 35, for_statement; 35, 36; 35, 37; 35, 40; 36, identifier:cnt; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:containers; 40, block; 40, 41; 40, 57; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:num_frames; 45, identifier:append; 46, argument_list; 46, 47; 47, subscript; 47, 48; 47, 56; 48, attribute; 48, 49; 48, 55; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:cnt; 52, identifier:get; 53, argument_list; 53, 54; 54, identifier:utt_idx; 55, identifier:shape; 56, integer:0; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:refs; 61, identifier:append; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:cnt; 66, identifier:get; 67, argument_list; 67, 68; 67, 69; 68, identifier:utt_idx; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:mem_map; 71, True; 72, if_statement; 72, 73; 72, 82; 73, comparison_operator:!=; 73, 74; 73, 81; 74, call; 74, 75; 74, 76; 75, identifier:len; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:set; 79, argument_list; 79, 80; 80, identifier:num_frames; 81, integer:1; 82, block; 82, 83; 83, raise_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:ValueError; 86, argument_list; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, string:'Utterance {} has not the same number of frames in all containers!'; 90, identifier:format; 91, argument_list; 91, 92; 92, identifier:utt_idx; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:num_chunks; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:math; 99, identifier:ceil; 100, argument_list; 100, 101; 101, binary_operator:/; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:num_frames; 104, integer:0; 105, call; 105, 106; 105, 107; 106, identifier:float; 107, argument_list; 107, 108; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:frames_per_chunk; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:region; 114, tuple; 114, 115; 114, 116; 114, 117; 115, identifier:offset; 116, identifier:num_chunks; 117, identifier:refs; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:regions; 122, identifier:append; 123, argument_list; 123, 124; 124, identifier:region; 125, expression_statement; 125, 126; 126, augmented_assignment:+=; 126, 127; 126, 128; 127, identifier:current_offset; 128, identifier:num_chunks; 129, return_statement; 129, 130; 130, identifier:regions | def get_utt_regions(self):
regions = []
current_offset = 0
for utt_idx in sorted(self.utt_ids):
offset = current_offset
num_frames = []
refs = []
for cnt in self.containers:
num_frames.append(cnt.get(utt_idx).shape[0])
refs.append(cnt.get(utt_idx, mem_map=True))
if len(set(num_frames)) != 1:
raise ValueError('Utterance {} has not the same number of frames in all containers!'.format(utt_idx))
num_chunks = math.ceil(num_frames[0] / float(self.frames_per_chunk))
region = (offset, num_chunks, refs)
regions.append(region)
current_offset += num_chunks
return regions |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:write_separated_lines; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:path; 5, identifier:values; 6, default_parameter; 6, 7; 6, 8; 7, identifier:separator; 8, string:' '; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort_by_column; 11, integer:0; 12, block; 12, 13; 12, 24; 12, 183; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:f; 16, call; 16, 17; 16, 18; 17, identifier:open; 18, argument_list; 18, 19; 18, 20; 18, 21; 19, identifier:path; 20, string:'w'; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:encoding; 23, string:'utf-8'; 24, if_statement; 24, 25; 24, 31; 24, 114; 25, comparison_operator:is; 25, 26; 25, 30; 26, call; 26, 27; 26, 28; 27, identifier:type; 28, argument_list; 28, 29; 29, identifier:values; 30, identifier:dict; 31, block; 31, 32; 31, 68; 32, if_statement; 32, 33; 32, 38; 32, 58; 33, comparison_operator:in; 33, 34; 33, 35; 34, identifier:sort_by_column; 35, list:[0, 1]; 35, 36; 35, 37; 36, integer:0; 37, integer:1; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:items; 42, call; 42, 43; 42, 44; 43, identifier:sorted; 44, argument_list; 44, 45; 44, 50; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:values; 48, identifier:items; 49, argument_list; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:key; 52, lambda; 52, 53; 52, 55; 53, lambda_parameters; 53, 54; 54, identifier:t; 55, subscript; 55, 56; 55, 57; 56, identifier:t; 57, identifier:sort_by_column; 58, else_clause; 58, 59; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:items; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:values; 66, identifier:items; 67, argument_list; 68, for_statement; 68, 69; 68, 72; 68, 73; 69, pattern_list; 69, 70; 69, 71; 70, identifier:key; 71, identifier:value; 72, identifier:items; 73, block; 73, 74; 73, 100; 74, if_statement; 74, 75; 74, 83; 75, comparison_operator:in; 75, 76; 75, 80; 76, call; 76, 77; 76, 78; 77, identifier:type; 78, argument_list; 78, 79; 79, identifier:value; 80, list:[list, set]; 80, 81; 80, 82; 81, identifier:list; 82, identifier:set; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:value; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:separator; 90, identifier:join; 91, argument_list; 91, 92; 92, list_comprehension; 92, 93; 92, 97; 93, call; 93, 94; 93, 95; 94, identifier:str; 95, argument_list; 95, 96; 96, identifier:x; 97, for_in_clause; 97, 98; 97, 99; 98, identifier:x; 99, identifier:value; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:f; 104, identifier:write; 105, argument_list; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, string:'{}{}{}\n'; 109, identifier:format; 110, argument_list; 110, 111; 110, 112; 110, 113; 111, identifier:key; 112, identifier:separator; 113, identifier:value; 114, elif_clause; 114, 115; 114, 128; 115, boolean_operator:or; 115, 116; 115, 122; 116, comparison_operator:is; 116, 117; 116, 121; 117, call; 117, 118; 117, 119; 118, identifier:type; 119, argument_list; 119, 120; 120, identifier:values; 121, identifier:list; 122, comparison_operator:is; 122, 123; 122, 127; 123, call; 123, 124; 123, 125; 124, identifier:type; 125, argument_list; 125, 126; 126, identifier:values; 127, identifier:set; 128, block; 128, 129; 128, 151; 129, if_statement; 129, 130; 129, 137; 129, 145; 130, comparison_operator:<=; 130, 131; 130, 132; 130, 133; 131, integer:0; 132, identifier:sort_by_column; 133, call; 133, 134; 133, 135; 134, identifier:len; 135, argument_list; 135, 136; 136, identifier:values; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:items; 141, call; 141, 142; 141, 143; 142, identifier:sorted; 143, argument_list; 143, 144; 144, identifier:values; 145, else_clause; 145, 146; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:items; 150, identifier:values; 151, for_statement; 151, 152; 151, 153; 151, 154; 152, identifier:record; 153, identifier:items; 154, block; 154, 155; 154, 166; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:str_values; 158, list_comprehension; 158, 159; 158, 163; 159, call; 159, 160; 159, 161; 160, identifier:str; 161, argument_list; 161, 162; 162, identifier:value; 163, for_in_clause; 163, 164; 163, 165; 164, identifier:value; 165, identifier:record; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:f; 170, identifier:write; 171, argument_list; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, string:'{}\n'; 175, identifier:format; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:separator; 180, identifier:join; 181, argument_list; 181, 182; 182, identifier:str_values; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:f; 187, identifier:close; 188, argument_list | def write_separated_lines(path, values, separator=' ', sort_by_column=0):
f = open(path, 'w', encoding='utf-8')
if type(values) is dict:
if sort_by_column in [0, 1]:
items = sorted(values.items(), key=lambda t: t[sort_by_column])
else:
items = values.items()
for key, value in items:
if type(value) in [list, set]:
value = separator.join([str(x) for x in value])
f.write('{}{}{}\n'.format(key, separator, value))
elif type(values) is list or type(values) is set:
if 0 <= sort_by_column < len(values):
items = sorted(values)
else:
items = values
for record in items:
str_values = [str(value) for value in record]
f.write('{}\n'.format(separator.join(str_values)))
f.close() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_set; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 5, 19; 5, 26; 5, 43; 6, if_statement; 6, 7; 6, 13; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 12; 11, identifier:s; 12, identifier:Set; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:TypeError; 17, argument_list; 17, 18; 18, string:"sets only"; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:s; 22, call; 22, 23; 22, 24; 23, identifier:frozenset; 24, argument_list; 24, 25; 25, identifier:s; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:not; 27, 28; 27, 29; 28, identifier:s; 29, identifier:_sort_set_memo; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:_sort_set_memo; 35, identifier:s; 36, call; 36, 37; 36, 38; 37, identifier:sorted; 38, argument_list; 38, 39; 38, 40; 39, identifier:s; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:key; 42, identifier:_sort_set_key; 43, return_statement; 43, 44; 44, subscript; 44, 45; 44, 46; 45, identifier:_sort_set_memo; 46, identifier:s | def sort_set(s):
if not isinstance(s, Set):
raise TypeError("sets only")
s = frozenset(s)
if s not in _sort_set_memo:
_sort_set_memo[s] = sorted(s, key=_sort_set_key)
return _sort_set_memo[s] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_tags; 3, parameters; 3, 4; 4, identifier:tagstring; 5, block; 5, 6; 5, 12; 5, 19; 5, 23; 5, 27; 5, 31; 5, 38; 5, 163; 5, 185; 5, 195; 5, 201; 6, if_statement; 6, 7; 6, 9; 7, not_operator; 7, 8; 8, identifier:tagstring; 9, block; 9, 10; 10, return_statement; 10, 11; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:tagstring; 15, call; 15, 16; 15, 17; 16, identifier:force_text; 17, argument_list; 17, 18; 18, identifier:tagstring; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:words; 22, list:[]; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:buffer; 26, list:[]; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:to_be_split; 30, list:[]; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:i; 34, call; 34, 35; 34, 36; 35, identifier:iter; 36, argument_list; 36, 37; 37, identifier:tagstring; 38, try_statement; 38, 39; 38, 145; 39, block; 39, 40; 40, while_statement; 40, 41; 40, 42; 41, True; 42, block; 42, 43; 42, 52; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:c; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:six; 49, identifier:next; 50, argument_list; 50, 51; 51, identifier:i; 52, if_statement; 52, 53; 52, 56; 52, 136; 53, comparison_operator:==; 53, 54; 53, 55; 54, identifier:c; 55, string:'"'; 56, block; 56, 57; 56, 76; 56, 85; 56, 106; 57, if_statement; 57, 58; 57, 59; 58, identifier:buffer; 59, block; 59, 60; 59, 72; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:to_be_split; 64, identifier:append; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, string:''; 69, identifier:join; 70, argument_list; 70, 71; 71, identifier:buffer; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:buffer; 75, list:[]; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:c; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:six; 82, identifier:next; 83, argument_list; 83, 84; 84, identifier:i; 85, while_statement; 85, 86; 85, 89; 86, comparison_operator:!=; 86, 87; 86, 88; 87, identifier:c; 88, string:'"'; 89, block; 89, 90; 89, 97; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:buffer; 94, identifier:append; 95, argument_list; 95, 96; 96, identifier:c; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:c; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:six; 103, identifier:next; 104, argument_list; 104, 105; 105, identifier:i; 106, if_statement; 106, 107; 106, 108; 107, identifier:buffer; 108, block; 108, 109; 108, 122; 108, 132; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:word; 112, call; 112, 113; 112, 121; 113, attribute; 113, 114; 113, 120; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, string:''; 117, identifier:join; 118, argument_list; 118, 119; 119, identifier:buffer; 120, identifier:strip; 121, argument_list; 122, if_statement; 122, 123; 122, 124; 123, identifier:word; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:words; 129, identifier:append; 130, argument_list; 130, 131; 131, identifier:word; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:buffer; 135, list:[]; 136, else_clause; 136, 137; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:buffer; 142, identifier:append; 143, argument_list; 143, 144; 144, identifier:c; 145, except_clause; 145, 146; 145, 147; 146, identifier:StopIteration; 147, block; 147, 148; 148, if_statement; 148, 149; 148, 150; 149, identifier:buffer; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:to_be_split; 155, identifier:append; 156, argument_list; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, string:''; 160, identifier:join; 161, argument_list; 161, 162; 162, identifier:buffer; 163, if_statement; 163, 164; 163, 165; 164, identifier:to_be_split; 165, block; 165, 166; 166, for_statement; 166, 167; 166, 168; 166, 169; 167, identifier:chunk; 168, identifier:to_be_split; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:words; 174, identifier:extend; 175, argument_list; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:split_strip; 178, argument_list; 178, 179; 178, 180; 179, identifier:chunk; 180, subscript; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:settings; 183, identifier:TAGGIT_SELECTIZE; 184, string:'DELIMITER'; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:words; 188, call; 188, 189; 188, 190; 189, identifier:list; 190, argument_list; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:set; 193, argument_list; 193, 194; 194, identifier:words; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:words; 199, identifier:sort; 200, argument_list; 201, return_statement; 201, 202; 202, identifier:words | def parse_tags(tagstring):
if not tagstring:
return []
tagstring = force_text(tagstring)
words = []
buffer = []
to_be_split = []
i = iter(tagstring)
try:
while True:
c = six.next(i)
if c == '"':
if buffer:
to_be_split.append(''.join(buffer))
buffer = []
c = six.next(i)
while c != '"':
buffer.append(c)
c = six.next(i)
if buffer:
word = ''.join(buffer).strip()
if word:
words.append(word)
buffer = []
else:
buffer.append(c)
except StopIteration:
if buffer:
to_be_split.append(''.join(buffer))
if to_be_split:
for chunk in to_be_split:
words.extend(split_strip(chunk, settings.TAGGIT_SELECTIZE['DELIMITER']))
words = list(set(words))
words.sort()
return words |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_sort_by_unique_fields; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:model; 5, identifier:model_objs; 6, identifier:unique_fields; 7, block; 7, 8; 7, 26; 7, 51; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:unique_fields; 11, list_comprehension; 11, 12; 11, 13; 11, 20; 12, identifier:field; 13, for_in_clause; 13, 14; 13, 15; 14, identifier:field; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:model; 18, identifier:_meta; 19, identifier:fields; 20, if_clause; 20, 21; 21, comparison_operator:in; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:field; 24, identifier:attname; 25, identifier:unique_fields; 26, function_definition; 26, 27; 26, 28; 26, 30; 27, function_name:sort_key; 28, parameters; 28, 29; 29, identifier:model_obj; 30, block; 30, 31; 31, return_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:tuple; 34, generator_expression; 34, 35; 34, 48; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:field; 38, identifier:get_db_prep_save; 39, argument_list; 39, 40; 39, 47; 40, call; 40, 41; 40, 42; 41, identifier:getattr; 42, argument_list; 42, 43; 42, 44; 43, identifier:model_obj; 44, attribute; 44, 45; 44, 46; 45, identifier:field; 46, identifier:attname; 47, identifier:connection; 48, for_in_clause; 48, 49; 48, 50; 49, identifier:field; 50, identifier:unique_fields; 51, return_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:sorted; 54, argument_list; 54, 55; 54, 56; 55, identifier:model_objs; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:key; 58, identifier:sort_key | def _sort_by_unique_fields(model, model_objs, unique_fields):
unique_fields = [
field for field in model._meta.fields
if field.attname in unique_fields
]
def sort_key(model_obj):
return tuple(
field.get_db_prep_save(getattr(model_obj, field.attname),
connection)
for field in unique_fields
)
return sorted(model_objs, key=sort_key) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:find; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:datum; 6, block; 6, 7; 6, 22; 6, 78; 7, if_statement; 7, 8; 7, 19; 8, boolean_operator:and; 8, 9; 8, 16; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:datum; 14, identifier:value; 15, identifier:dict; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:expressions; 19, block; 19, 20; 20, return_statement; 20, 21; 21, identifier:datum; 22, if_statement; 22, 23; 22, 38; 23, boolean_operator:or; 23, 24; 23, 31; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:datum; 29, identifier:value; 30, identifier:dict; 31, call; 31, 32; 31, 33; 32, identifier:isinstance; 33, argument_list; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:datum; 36, identifier:value; 37, identifier:list; 38, block; 38, 39; 38, 56; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:key; 42, parenthesized_expression; 42, 43; 43, conditional_expression:if; 43, 44; 43, 52; 43, 55; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:functools; 47, identifier:cmp_to_key; 48, argument_list; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_compare; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:expressions; 55, None; 56, return_statement; 56, 57; 57, list:[jsonpath_rw.DatumInContext.wrap(
[value for value in sorted(datum.value, key=key)])]; 57, 58; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:jsonpath_rw; 62, identifier:DatumInContext; 63, identifier:wrap; 64, argument_list; 64, 65; 65, list_comprehension; 65, 66; 65, 67; 66, identifier:value; 67, for_in_clause; 67, 68; 67, 69; 68, identifier:value; 69, call; 69, 70; 69, 71; 70, identifier:sorted; 71, argument_list; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:datum; 74, identifier:value; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:key; 77, identifier:key; 78, return_statement; 78, 79; 79, identifier:datum | def find(self, datum):
if isinstance(datum.value, dict) and self.expressions:
return datum
if isinstance(datum.value, dict) or isinstance(datum.value, list):
key = (functools.cmp_to_key(self._compare)
if self.expressions else None)
return [jsonpath_rw.DatumInContext.wrap(
[value for value in sorted(datum.value, key=key)])]
return datum |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_subset_riverid_index_list; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:river_id_list; 6, block; 6, 7; 6, 11; 6, 15; 6, 19; 6, 68; 6, 77; 6, 86; 6, 95; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:netcdf_river_indices_list; 10, list:[]; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:valid_river_ids; 14, list:[]; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:missing_river_ids; 18, list:[]; 19, for_statement; 19, 20; 19, 21; 19, 22; 20, identifier:river_id; 21, identifier:river_id_list; 22, block; 22, 23; 23, try_statement; 23, 24; 23, 45; 24, block; 24, 25; 24, 38; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 31; 27, attribute; 27, 28; 27, 29; 27, 30; 28, identifier:netcdf_river_indices_list; 29, line_continuation:\; 30, identifier:append; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:get_river_index; 36, argument_list; 36, 37; 37, identifier:river_id; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:valid_river_ids; 42, identifier:append; 43, argument_list; 43, 44; 44, identifier:river_id; 45, except_clause; 45, 46; 45, 47; 46, identifier:IndexError; 47, block; 47, 48; 47, 61; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:log; 51, argument_list; 51, 52; 51, 60; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, concatenated_string; 54, 55; 54, 56; 55, string:"ReachID {0} not found in netCDF dataset."; 56, string:" Skipping ..."; 57, identifier:format; 58, argument_list; 58, 59; 59, identifier:river_id; 60, string:"WARNING"; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:missing_river_ids; 65, identifier:append; 66, argument_list; 66, 67; 67, identifier:river_id; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:np_valid_river_indices_list; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:np; 74, identifier:array; 75, argument_list; 75, 76; 76, identifier:netcdf_river_indices_list; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:np_valid_river_ids; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:np; 83, identifier:array; 84, argument_list; 84, 85; 85, identifier:valid_river_ids; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:sorted_indexes; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:np; 92, identifier:argsort; 93, argument_list; 93, 94; 94, identifier:np_valid_river_indices_list; 95, return_statement; 95, 96; 96, tuple; 96, 97; 96, 100; 96, 103; 97, subscript; 97, 98; 97, 99; 98, identifier:np_valid_river_indices_list; 99, identifier:sorted_indexes; 100, subscript; 100, 101; 100, 102; 101, identifier:np_valid_river_ids; 102, identifier:sorted_indexes; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:np; 106, identifier:array; 107, argument_list; 107, 108; 108, identifier:missing_river_ids | def get_subset_riverid_index_list(self, river_id_list):
netcdf_river_indices_list = []
valid_river_ids = []
missing_river_ids = []
for river_id in river_id_list:
try:
netcdf_river_indices_list \
.append(self.get_river_index(river_id))
valid_river_ids.append(river_id)
except IndexError:
log("ReachID {0} not found in netCDF dataset."
" Skipping ...".format(river_id),
"WARNING")
missing_river_ids.append(river_id)
np_valid_river_indices_list = np.array(netcdf_river_indices_list)
np_valid_river_ids = np.array(valid_river_ids)
sorted_indexes = np.argsort(np_valid_river_indices_list)
return(np_valid_river_indices_list[sorted_indexes],
np_valid_river_ids[sorted_indexes],
np.array(missing_river_ids)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_child_type_choices; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:request; 6, identifier:action; 7, block; 7, 8; 7, 23; 7, 33; 7, 37; 7, 41; 7, 118; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:choices; 11, call; 11, 12; 11, 20; 12, attribute; 12, 13; 12, 18; 12, 19; 13, call; 13, 14; 13, 15; 14, identifier:super; 15, argument_list; 15, 16; 15, 17; 16, identifier:ChildModelPluginPolymorphicParentModelAdmin; 17, identifier:self; 18, line_continuation:\; 19, identifier:get_child_type_choices; 20, argument_list; 20, 21; 20, 22; 21, identifier:request; 22, identifier:action; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:plugins; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:child_model_plugin_class; 31, identifier:get_plugins; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:labels; 36, dictionary; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:sort_priorities; 40, dictionary; 41, if_statement; 41, 42; 41, 43; 42, identifier:plugins; 43, block; 43, 44; 43, 80; 43, 94; 44, for_statement; 44, 45; 44, 46; 44, 47; 45, identifier:plugin; 46, identifier:plugins; 47, block; 47, 48; 47, 56; 47, 67; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:pk; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:plugin; 54, identifier:content_type; 55, identifier:pk; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:labels; 60, identifier:pk; 61, call; 61, 62; 61, 63; 62, identifier:capfirst; 63, argument_list; 63, 64; 64, attribute; 64, 65; 64, 66; 65, identifier:plugin; 66, identifier:verbose_name; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:sort_priorities; 71, identifier:pk; 72, call; 72, 73; 72, 74; 73, identifier:getattr; 74, argument_list; 74, 75; 74, 76; 74, 77; 75, identifier:plugin; 76, string:'sort_priority'; 77, subscript; 77, 78; 77, 79; 78, identifier:labels; 79, identifier:pk; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:choices; 83, list_comprehension; 83, 84; 83, 89; 84, tuple; 84, 85; 84, 86; 85, identifier:ctype; 86, subscript; 86, 87; 86, 88; 87, identifier:labels; 88, identifier:ctype; 89, for_in_clause; 89, 90; 89, 93; 90, pattern_list; 90, 91; 90, 92; 91, identifier:ctype; 92, identifier:_; 93, identifier:choices; 94, return_statement; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:sorted; 97, argument_list; 97, 98; 97, 99; 98, identifier:choices; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:cmp; 101, lambda; 101, 102; 101, 105; 102, lambda_parameters; 102, 103; 102, 104; 103, identifier:a; 104, identifier:b; 105, call; 105, 106; 105, 107; 106, identifier:cmp; 107, argument_list; 107, 108; 107, 113; 108, subscript; 108, 109; 108, 110; 109, identifier:sort_priorities; 110, subscript; 110, 111; 110, 112; 111, identifier:a; 112, integer:0; 113, subscript; 113, 114; 113, 115; 114, identifier:sort_priorities; 115, subscript; 115, 116; 115, 117; 116, identifier:b; 117, integer:0; 118, return_statement; 118, 119; 119, identifier:choices | def get_child_type_choices(self, request, action):
choices = super(ChildModelPluginPolymorphicParentModelAdmin, self) \
.get_child_type_choices(request, action)
plugins = self.child_model_plugin_class.get_plugins()
labels = {}
sort_priorities = {}
if plugins:
for plugin in plugins:
pk = plugin.content_type.pk
labels[pk] = capfirst(plugin.verbose_name)
sort_priorities[pk] = getattr(plugin, 'sort_priority', labels[pk])
choices = [(ctype, labels[ctype]) for ctype, _ in choices]
return sorted(choices,
cmp=lambda a, b: cmp(
sort_priorities[a[0]],
sort_priorities[b[0]]
)
)
return choices |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.