sequence
stringlengths
492
15.9k
code
stringlengths
75
8.58k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:commit_check; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:commands; 7, string:""; 8, default_parameter; 8, 9; 8, 10; 9, identifier:req_format; 10, string:"text"; 11, block; 11, 12; 11, 21; 11, 25; 11, 39; 11, 45; 11, 59; 11, 79; 11, 85; 11, 97; 11, 101; 11, 176; 12, if_statement; 12, 13; 12, 15; 13, not_operator; 13, 14; 14, identifier:commands; 15, block; 15, 16; 16, raise_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:InvalidCommandError; 19, argument_list; 19, 20; 20, string:'No commands specified'; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:clean_cmds; 24, list:[]; 25, for_statement; 25, 26; 25, 27; 25, 31; 26, identifier:cmd; 27, call; 27, 28; 27, 29; 28, identifier:clean_lines; 29, argument_list; 29, 30; 30, identifier:commands; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:clean_cmds; 36, identifier:append; 37, argument_list; 37, 38; 38, identifier:cmd; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:lock; 44, argument_list; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_session; 51, identifier:load_configuration; 52, argument_list; 52, 53; 52, 56; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:action; 55, string:'set'; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:config; 58, identifier:clean_cmds; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:results; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:ET; 65, identifier:fromstring; 66, argument_list; 66, 67; 67, attribute; 67, 68; 67, 78; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:_session; 73, identifier:validate; 74, argument_list; 74, 75; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:source; 77, string:'candidate'; 78, identifier:tostring; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:unlock; 84, argument_list; 85, if_statement; 85, 86; 85, 89; 86, comparison_operator:==; 86, 87; 86, 88; 87, identifier:req_format; 88, string:"xml"; 89, block; 89, 90; 90, return_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:ET; 94, identifier:tostring; 95, argument_list; 95, 96; 96, identifier:results; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:out; 100, string:""; 101, for_statement; 101, 102; 101, 103; 101, 108; 102, identifier:i; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:results; 106, identifier:iter; 107, argument_list; 108, block; 108, 109; 109, if_statement; 109, 110; 109, 115; 109, 120; 109, 152; 110, comparison_operator:==; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:i; 113, identifier:tag; 114, string:'commit-check-success'; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, augmented_assignment:+=; 117, 118; 117, 119; 118, identifier:out; 119, string:'configuration check succeeds\n'; 120, elif_clause; 120, 121; 120, 126; 121, comparison_operator:is; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:i; 124, identifier:text; 125, None; 126, block; 126, 127; 127, if_statement; 127, 128; 127, 139; 128, comparison_operator:!=; 128, 129; 128, 138; 129, binary_operator:+; 129, 130; 129, 137; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:i; 134, identifier:text; 135, identifier:strip; 136, argument_list; 137, string:'\n'; 138, string:'\n'; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, augmented_assignment:+=; 141, 142; 141, 143; 142, identifier:out; 143, binary_operator:+; 143, 144; 143, 151; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:i; 148, identifier:text; 149, identifier:strip; 150, argument_list; 151, string:'\n'; 152, elif_clause; 152, 153; 152, 158; 153, comparison_operator:is; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:i; 156, identifier:text; 157, None; 158, block; 158, 159; 159, if_statement; 159, 160; 159, 167; 160, comparison_operator:!=; 160, 161; 160, 166; 161, binary_operator:+; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:i; 164, identifier:tag; 165, string:'\n'; 166, string:'\n'; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:out; 171, binary_operator:+; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:i; 174, identifier:tag; 175, string:'\n'; 176, return_statement; 176, 177; 177, identifier:out
def commit_check(self, commands="", req_format="text"): if not commands: raise InvalidCommandError('No commands specified') clean_cmds = [] for cmd in clean_lines(commands): clean_cmds.append(cmd) self.lock() self._session.load_configuration(action='set', config=clean_cmds) results = ET.fromstring(self._session.validate( source='candidate').tostring) self.unlock() if req_format == "xml": return ET.tostring(results) out = "" for i in results.iter(): if i.tag == 'commit-check-success': out += 'configuration check succeeds\n' elif i.text is not None: if i.text.strip() + '\n' != '\n': out += i.text.strip() + '\n' elif i.text is None: if i.tag + '\n' != '\n': out += i.tag + '\n' return out
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:connect; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 91; 5, 382; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:==; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:conn_type; 11, string:'paramiko'; 12, block; 12, 13; 12, 23; 12, 36; 12, 45; 12, 58; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_session; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:paramiko; 21, identifier:SSHClient; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:logger; 26, call; 26, 27; 26, 34; 27, attribute; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:logging; 31, identifier:Logger; 32, identifier:manager; 33, identifier:getLogger; 34, argument_list; 34, 35; 35, string:'paramiko.transport'; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:logger; 40, identifier:setLevel; 41, argument_list; 41, 42; 42, attribute; 42, 43; 42, 44; 43, identifier:logging; 44, identifier:CRITICAL; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_session; 51, identifier:set_missing_host_key_policy; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:paramiko; 56, identifier:AutoAddPolicy; 57, argument_list; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:_session; 64, identifier:connect; 65, argument_list; 65, 66; 65, 71; 65, 76; 65, 81; 65, 86; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:hostname; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:host; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:username; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:username; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:password; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:password; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:port; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:port; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:timeout; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:connect_timeout; 91, if_statement; 91, 92; 91, 97; 91, 191; 91, 242; 91, 333; 92, comparison_operator:==; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:conn_type; 96, string:'scp'; 97, block; 97, 98; 97, 108; 97, 121; 97, 130; 97, 143; 97, 176; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:_scp_session; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:paramiko; 106, identifier:SSHClient; 107, argument_list; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:logger; 111, call; 111, 112; 111, 119; 112, attribute; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:logging; 116, identifier:Logger; 117, identifier:manager; 118, identifier:getLogger; 119, argument_list; 119, 120; 120, string:'paramiko.transport'; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:logger; 125, identifier:setLevel; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 129; 128, identifier:logging; 129, identifier:CRITICAL; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:_scp_session; 136, identifier:set_missing_host_key_policy; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:paramiko; 141, identifier:AutoAddPolicy; 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:_scp_session; 149, identifier:connect; 150, argument_list; 150, 151; 150, 156; 150, 161; 150, 166; 150, 171; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:hostname; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:host; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:username; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:username; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:password; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:password; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:port; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:port; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:timeout; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:connect_timeout; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:_scp; 181, call; 181, 182; 181, 183; 182, identifier:SCPClient; 183, argument_list; 183, 184; 184, call; 184, 185; 184, 190; 185, attribute; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:_scp_session; 189, identifier:get_transport; 190, argument_list; 191, elif_clause; 191, 192; 191, 197; 192, comparison_operator:==; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:conn_type; 196, string:"ncclient"; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:_session; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:manager; 206, identifier:connect; 207, argument_list; 207, 208; 207, 213; 207, 218; 207, 223; 207, 228; 207, 233; 207, 239; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:host; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:host; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:port; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:port; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:username; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:username; 223, keyword_argument; 223, 224; 223, 225; 224, identifier:password; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:password; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:timeout; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:connect_timeout; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:device_params; 235, dictionary; 235, 236; 236, pair; 236, 237; 236, 238; 237, string:'name'; 238, string:'junos'; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:hostkey_verify; 241, False; 242, elif_clause; 242, 243; 242, 248; 243, comparison_operator:==; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:conn_type; 247, string:'shell'; 248, block; 248, 249; 248, 273; 248, 316; 249, if_statement; 249, 250; 249, 254; 250, not_operator; 250, 251; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:_session; 254, block; 254, 255; 254, 261; 254, 267; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:self; 259, identifier:conn_type; 260, string:'paramiko'; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:connect; 266, argument_list; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:conn_type; 272, string:'shell'; 273, if_statement; 273, 274; 273, 278; 274, not_operator; 274, 275; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:_shell; 278, block; 278, 279; 278, 291; 278, 298; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:self; 283, identifier:_shell; 284, call; 284, 285; 284, 290; 285, attribute; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:_session; 289, identifier:invoke_shell; 290, argument_list; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:time; 295, identifier:sleep; 296, argument_list; 296, 297; 297, integer:2; 298, if_statement; 298, 299; 298, 309; 299, boolean_operator:and; 299, 300; 299, 305; 300, comparison_operator:!=; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:self; 303, identifier:username; 304, string:'root'; 305, not_operator; 305, 306; 306, attribute; 306, 307; 306, 308; 307, identifier:self; 308, identifier:_in_cli; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:_in_cli; 315, True; 316, if_statement; 316, 317; 316, 323; 317, not_operator; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:self; 321, identifier:cli_to_shell; 322, argument_list; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 331; 326, attribute; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:self; 329, identifier:_shell; 330, identifier:recv; 331, argument_list; 331, 332; 332, integer:9999; 333, elif_clause; 333, 334; 333, 339; 334, comparison_operator:==; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:self; 337, identifier:conn_type; 338, string:'root'; 339, block; 339, 340; 339, 365; 340, if_statement; 340, 341; 340, 345; 341, not_operator; 341, 342; 342, attribute; 342, 343; 342, 344; 343, identifier:self; 344, identifier:_shell; 345, block; 345, 346; 345, 358; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:self; 350, identifier:_shell; 351, call; 351, 352; 351, 357; 352, attribute; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:_session; 356, identifier:invoke_shell; 357, argument_list; 358, expression_statement; 358, 359; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:time; 362, identifier:sleep; 363, argument_list; 363, 364; 364, integer:2; 365, if_statement; 365, 366; 365, 372; 366, not_operator; 366, 367; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:self; 370, identifier:shell_to_cli; 371, argument_list; 372, block; 372, 373; 373, expression_statement; 373, 374; 374, call; 374, 375; 374, 380; 375, attribute; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:self; 378, identifier:_shell; 379, identifier:recv; 380, argument_list; 380, 381; 381, integer:9999; 382, expression_statement; 382, 383; 383, call; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:self; 386, identifier:_update_timeout; 387, argument_list; 387, 388; 388, attribute; 388, 389; 388, 390; 389, identifier:self; 390, identifier:session_timeout
def connect(self): if self.conn_type == 'paramiko': self._session = paramiko.SSHClient() logger = logging.Logger.manager.getLogger('paramiko.transport') logger.setLevel(logging.CRITICAL) self._session.set_missing_host_key_policy( paramiko.AutoAddPolicy()) self._session.connect(hostname=self.host, username=self.username, password=self.password, port=self.port, timeout=self.connect_timeout) if self.conn_type == 'scp': self._scp_session = paramiko.SSHClient() logger = logging.Logger.manager.getLogger('paramiko.transport') logger.setLevel(logging.CRITICAL) self._scp_session.set_missing_host_key_policy( paramiko.AutoAddPolicy()) self._scp_session.connect(hostname=self.host, username=self.username, password=self.password, port=self.port, timeout=self.connect_timeout) self._scp = SCPClient(self._scp_session.get_transport()) elif self.conn_type == "ncclient": self._session = manager.connect( host=self.host, port=self.port, username=self.username, password=self.password, timeout=self.connect_timeout, device_params={'name': 'junos'}, hostkey_verify=False ) elif self.conn_type == 'shell': if not self._session: self.conn_type = 'paramiko' self.connect() self.conn_type = 'shell' if not self._shell: self._shell = self._session.invoke_shell() time.sleep(2) if self.username != 'root' and not self._in_cli: self._in_cli = True if not self.cli_to_shell(): self._shell.recv(9999) elif self.conn_type == 'root': if not self._shell: self._shell = self._session.invoke_shell() time.sleep(2) if not self.shell_to_cli(): self._shell.recv(9999) self._update_timeout(self.session_timeout)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:script; 3, parameters; 3, 4; 3, 5; 4, identifier:inbox; 5, identifier:cfg; 6, block; 6, 7; 6, 13; 6, 45; 6, 49; 6, 60; 6, 66; 6, 101; 6, 126; 6, 132; 6, 136; 6, 289; 6, 311; 6, 334; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:script_name; 10, subscript; 10, 11; 10, 12; 11, identifier:cfg; 12, string:"id"; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:script_id; 16, subscript; 16, 17; 16, 41; 17, call; 17, 18; 17, 19; 18, identifier:str; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:abs; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:hash; 25, argument_list; 25, 26; 26, binary_operator:+; 26, 27; 26, 31; 27, tuple; 27, 28; 28, subscript; 28, 29; 28, 30; 29, identifier:cfg; 30, string:"id"; 31, call; 31, 32; 31, 33; 32, identifier:tuple; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, subscript; 36, 37; 36, 38; 37, identifier:inbox; 38, integer:0; 39, identifier:values; 40, argument_list; 41, slice; 41, 42; 41, 43; 41, 44; 42, integer:0; 43, colon; 44, integer:8; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:args; 48, dictionary; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:args; 53, string:"params"; 54, call; 54, 55; 54, 56; 55, identifier:dict; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:cfg; 59, string:"params"; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:args; 64, string:"in"; 65, dictionary; 66, for_statement; 66, 67; 66, 68; 66, 71; 67, identifier:in_port; 68, subscript; 68, 69; 68, 70; 69, identifier:cfg; 70, string:"in"; 71, block; 71, 72; 72, for_statement; 72, 73; 72, 74; 72, 75; 73, identifier:inin_ports; 74, identifier:inbox; 75, block; 75, 76; 75, 86; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:in_path; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:inin_ports; 82, identifier:get; 83, argument_list; 83, 84; 83, 85; 84, identifier:in_port; 85, None; 86, if_statement; 86, 87; 86, 91; 87, parenthesized_expression; 87, 88; 88, comparison_operator:is; 88, 89; 88, 90; 89, identifier:in_path; 90, None; 91, block; 91, 92; 91, 100; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 99; 94, subscript; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:args; 97, string:"in"; 98, identifier:in_port; 99, identifier:in_path; 100, break_statement; 101, if_statement; 101, 102; 101, 115; 102, comparison_operator:<; 102, 103; 102, 109; 103, call; 103, 104; 103, 105; 104, identifier:len; 105, argument_list; 105, 106; 106, subscript; 106, 107; 106, 108; 107, identifier:args; 108, string:"in"; 109, call; 109, 110; 109, 111; 110, identifier:len; 111, argument_list; 111, 112; 112, subscript; 112, 113; 112, 114; 113, identifier:cfg; 114, string:"in"; 115, block; 115, 116; 116, raise_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:Exception; 119, argument_list; 119, 120; 120, binary_operator:%; 120, 121; 120, 122; 121, string:"not all in_ports connected, got: %s"; 122, tuple; 122, 123; 123, subscript; 123, 124; 123, 125; 124, identifier:args; 125, string:"in"; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:args; 130, string:"out"; 131, dictionary; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:out; 135, dictionary; 136, for_statement; 136, 137; 136, 142; 136, 148; 137, pattern_list; 137, 138; 137, 139; 138, identifier:i; 139, tuple_pattern; 139, 140; 139, 141; 140, identifier:out_port; 141, identifier:out_ext; 142, call; 142, 143; 142, 144; 143, identifier:enumerate; 144, argument_list; 144, 145; 145, subscript; 145, 146; 145, 147; 146, identifier:cfg; 147, string:"out"; 148, block; 148, 149; 148, 242; 148, 275; 148, 283; 149, if_statement; 149, 150; 149, 165; 149, 201; 150, comparison_operator:==; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:cfg; 153, string:"in"; 154, call; 154, 155; 154, 156; 155, identifier:tuple; 156, generator_expression; 156, 157; 156, 158; 157, identifier:out_port_; 158, for_in_clause; 158, 159; 158, 162; 159, pattern_list; 159, 160; 159, 161; 160, identifier:out_port_; 161, identifier:_; 162, subscript; 162, 163; 162, 164; 163, identifier:cfg; 164, string:"out"; 165, block; 165, 166; 165, 195; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:pfx; 169, binary_operator:+; 169, 170; 169, 194; 170, subscript; 170, 171; 170, 193; 171, call; 171, 172; 171, 191; 172, attribute; 172, 173; 172, 190; 173, subscript; 173, 174; 173, 188; 174, call; 174, 175; 174, 186; 175, attribute; 175, 176; 175, 185; 176, subscript; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:args; 179, string:"in"; 180, subscript; 180, 181; 180, 184; 181, subscript; 181, 182; 181, 183; 182, identifier:cfg; 183, string:"in"; 184, identifier:i; 185, identifier:split; 186, argument_list; 186, 187; 187, string:"/"; 188, unary_operator:-; 188, 189; 189, integer:1; 190, identifier:split; 191, argument_list; 191, 192; 192, string:"."; 193, integer:0; 194, string:"_"; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:base; 198, subscript; 198, 199; 198, 200; 199, identifier:cfg; 200, string:"id"; 201, else_clause; 201, 202; 202, block; 202, 203; 202, 232; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:pfx; 206, binary_operator:+; 206, 207; 206, 231; 207, subscript; 207, 208; 207, 230; 208, call; 208, 209; 208, 228; 209, attribute; 209, 210; 209, 227; 210, subscript; 210, 211; 210, 225; 211, call; 211, 212; 211, 223; 212, attribute; 212, 213; 212, 222; 213, subscript; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:args; 216, string:"in"; 217, subscript; 217, 218; 217, 221; 218, subscript; 218, 219; 218, 220; 219, identifier:cfg; 220, string:"in"; 221, integer:0; 222, identifier:split; 223, argument_list; 223, 224; 224, string:"/"; 225, unary_operator:-; 225, 226; 226, integer:1; 227, identifier:split; 228, argument_list; 228, 229; 229, string:"."; 230, integer:0; 231, string:"_"; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:base; 235, binary_operator:+; 235, 236; 235, 241; 236, binary_operator:+; 236, 237; 236, 240; 237, subscript; 237, 238; 237, 239; 238, identifier:cfg; 239, string:"id"; 240, string:"-"; 241, identifier:out_port; 242, if_statement; 242, 243; 242, 244; 242, 261; 243, identifier:out_ext; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:out_path; 248, binary_operator:+; 248, 249; 248, 260; 249, binary_operator:+; 249, 250; 249, 259; 250, binary_operator:+; 250, 251; 250, 258; 251, binary_operator:+; 251, 252; 251, 257; 252, binary_operator:+; 252, 253; 252, 256; 253, subscript; 253, 254; 253, 255; 254, identifier:cfg; 255, string:"dir"; 256, string:"/"; 257, identifier:pfx; 258, identifier:base; 259, string:"."; 260, identifier:out_ext; 261, else_clause; 261, 262; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:out_path; 266, binary_operator:+; 266, 267; 266, 274; 267, binary_operator:+; 267, 268; 267, 273; 268, binary_operator:+; 268, 269; 268, 272; 269, subscript; 269, 270; 269, 271; 270, identifier:cfg; 271, string:"dir"; 272, string:"/"; 273, identifier:pfx; 274, identifier:base; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 282; 277, subscript; 277, 278; 277, 281; 278, subscript; 278, 279; 278, 280; 279, identifier:args; 280, string:"out"; 281, identifier:out_port; 282, identifier:out_path; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 288; 285, subscript; 285, 286; 285, 287; 286, identifier:out; 287, identifier:out_port; 288, identifier:out_path; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:ret; 292, call; 292, 293; 292, 294; 293, identifier:_eval_script; 294, argument_list; 294, 295; 294, 298; 294, 301; 294, 304; 294, 307; 294, 310; 295, subscript; 295, 296; 295, 297; 296, identifier:cfg; 297, string:"evaluator"; 298, subscript; 298, 299; 298, 300; 299, identifier:cfg; 300, string:"preamble"; 301, subscript; 301, 302; 301, 303; 302, identifier:cfg; 303, string:"dir"; 304, subscript; 304, 305; 304, 306; 305, identifier:cfg; 306, string:"executable"; 307, subscript; 307, 308; 307, 309; 308, identifier:cfg; 309, string:"script"; 310, identifier:args; 311, if_statement; 311, 312; 311, 317; 312, comparison_operator:!=; 312, 313; 312, 316; 313, subscript; 313, 314; 313, 315; 314, identifier:ret; 315, integer:0; 316, integer:0; 317, block; 317, 318; 318, raise_statement; 318, 319; 319, call; 319, 320; 319, 321; 320, identifier:Exception; 321, argument_list; 321, 322; 321, 325; 321, 328; 321, 331; 322, subscript; 322, 323; 322, 324; 323, identifier:ret; 324, integer:0; 325, subscript; 325, 326; 325, 327; 326, identifier:cfg; 327, string:"script"; 328, subscript; 328, 329; 328, 330; 329, identifier:ret; 330, integer:1; 331, subscript; 331, 332; 331, 333; 332, identifier:ret; 333, integer:2; 334, return_statement; 334, 335; 335, identifier:out
def script(inbox, cfg): script_name = cfg["id"] script_id = str(abs(hash((cfg["id"],) + tuple(inbox[0].values()))))[0:8] args = {} args["params"] = dict(cfg["params"]) args["in"] = {} for in_port in cfg["in"]: for inin_ports in inbox: in_path = inin_ports.get(in_port, None) if (in_path is not None): args["in"][in_port] = in_path break if len(args["in"]) < len(cfg["in"]): raise Exception("not all in_ports connected, got: %s" % (args["in"],)) args["out"] = {} out = {} for i, (out_port, out_ext) in enumerate(cfg["out"]): if cfg["in"] == tuple(out_port_ for out_port_, _ in cfg["out"]): pfx = args["in"][cfg["in"][i]].split("/")[-1].split(".")[0] + "_" base = cfg["id"] else: pfx = args["in"][cfg["in"][0]].split("/")[-1].split(".")[0] + "_" base = cfg["id"] + "-" + out_port if out_ext: out_path = cfg["dir"] + "/" + pfx + base + "." + out_ext else: out_path = cfg["dir"] + "/" + pfx + base args["out"][out_port] = out_path out[out_port] = out_path ret = _eval_script(cfg["evaluator"], cfg["preamble"], cfg["dir"], cfg["executable"], cfg["script"], args) if ret[0] != 0: raise Exception(ret[0], cfg["script"], ret[1], ret[2]) return out
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_create_update_tracking_related_event; 3, parameters; 3, 4; 4, identifier:instance; 5, block; 5, 6; 5, 10; 5, 100; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:events; 9, dictionary; 10, for_statement; 10, 11; 10, 14; 10, 21; 11, pattern_list; 11, 12; 11, 13; 12, identifier:field; 13, identifier:related_fields; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:instance; 18, identifier:_tracked_related_fields; 19, identifier:items; 20, argument_list; 21, block; 21, 22; 22, if_statement; 22, 23; 22, 36; 23, not_operator; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 35; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:instance; 31, identifier:_meta; 32, identifier:get_field; 33, argument_list; 33, 34; 34, identifier:field; 35, identifier:ManyToManyField; 36, block; 36, 37; 36, 74; 37, if_statement; 37, 38; 37, 50; 37, 64; 38, call; 38, 39; 38, 40; 39, identifier:isinstance; 40, argument_list; 40, 41; 40, 49; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:instance; 45, identifier:_meta; 46, identifier:get_field; 47, argument_list; 47, 48; 48, identifier:field; 49, identifier:ForeignKey; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:value; 54, call; 54, 55; 54, 56; 55, identifier:getattr; 56, argument_list; 56, 57; 56, 58; 57, identifier:instance; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, string:'{0}_id'; 61, identifier:format; 62, argument_list; 62, 63; 63, identifier:field; 64, else_clause; 64, 65; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:value; 69, call; 69, 70; 69, 71; 70, identifier:getattr; 71, argument_list; 71, 72; 71, 73; 72, identifier:instance; 73, identifier:field; 74, if_statement; 74, 75; 74, 82; 75, comparison_operator:!=; 75, 76; 75, 81; 76, subscript; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:instance; 79, identifier:_original_fields; 80, identifier:field; 81, identifier:value; 82, block; 82, 83; 83, for_statement; 83, 84; 83, 85; 83, 86; 84, identifier:related_field; 85, identifier:related_fields; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 98; 89, attribute; 89, 90; 89, 97; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:events; 93, identifier:setdefault; 94, argument_list; 94, 95; 94, 96; 95, identifier:related_field; 96, list:[]; 97, identifier:append; 98, argument_list; 98, 99; 99, identifier:field; 100, for_statement; 100, 101; 100, 104; 100, 109; 101, pattern_list; 101, 102; 101, 103; 102, identifier:related_field; 103, identifier:fields; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:events; 107, identifier:items; 108, argument_list; 109, block; 109, 110; 109, 126; 109, 148; 110, try_statement; 110, 111; 110, 122; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:related_instances; 115, call; 115, 116; 115, 117; 116, identifier:getattr; 117, argument_list; 117, 118; 117, 119; 118, identifier:instance; 119, subscript; 119, 120; 119, 121; 120, identifier:related_field; 121, integer:1; 122, except_clause; 122, 123; 122, 124; 123, identifier:ObjectDoesNotExist; 124, block; 124, 125; 125, continue_statement; 126, if_statement; 126, 127; 126, 132; 126, 141; 127, call; 127, 128; 127, 129; 128, identifier:hasattr; 129, argument_list; 129, 130; 129, 131; 130, identifier:related_instances; 131, string:'all'; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:related_instances; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:related_instances; 139, identifier:all; 140, argument_list; 141, else_clause; 141, 142; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:related_instances; 146, list:[related_instances]; 146, 147; 147, identifier:related_instances; 148, for_statement; 148, 149; 148, 150; 148, 151; 149, identifier:related_instance; 150, identifier:related_instances; 151, block; 151, 152; 151, 160; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:event; 155, call; 155, 156; 155, 157; 156, identifier:_create_event; 157, argument_list; 157, 158; 157, 159; 158, identifier:related_instance; 159, identifier:UPDATE; 160, for_statement; 160, 161; 160, 162; 160, 163; 161, identifier:field; 162, identifier:fields; 163, block; 163, 164; 163, 176; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:fieldname; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, string:'{0}__{1}'; 170, identifier:format; 171, argument_list; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:related_field; 174, integer:0; 175, identifier:field; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:_create_tracked_field; 179, argument_list; 179, 180; 179, 181; 179, 182; 179, 183; 180, identifier:event; 181, identifier:instance; 182, identifier:field; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:fieldname; 185, identifier:fieldname
def _create_update_tracking_related_event(instance): events = {} for field, related_fields in instance._tracked_related_fields.items(): if not isinstance(instance._meta.get_field(field), ManyToManyField): if isinstance(instance._meta.get_field(field), ForeignKey): value = getattr(instance, '{0}_id'.format(field)) else: value = getattr(instance, field) if instance._original_fields[field] != value: for related_field in related_fields: events.setdefault(related_field, []).append(field) for related_field, fields in events.items(): try: related_instances = getattr(instance, related_field[1]) except ObjectDoesNotExist: continue if hasattr(related_instances, 'all'): related_instances = related_instances.all() else: related_instances = [related_instances] for related_instance in related_instances: event = _create_event(related_instance, UPDATE) for field in fields: fieldname = '{0}__{1}'.format(related_field[0], field) _create_tracked_field( event, instance, field, fieldname=fieldname )
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:filter; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:type; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:limit; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:page; 19, None; 20, block; 20, 21; 20, 35; 20, 53; 20, 73; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:schema; 24, call; 24, 25; 24, 26; 25, identifier:PackageSchema; 26, argument_list; 26, 27; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:exclude; 29, tuple; 29, 30; 29, 31; 29, 32; 29, 33; 29, 34; 30, string:'testlist'; 31, string:'extra_cli_args'; 32, string:'agent_id'; 33, string:'options'; 34, string:'note'; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:resp; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:service; 43, identifier:list; 44, argument_list; 44, 45; 44, 48; 44, 49; 44, 50; 44, 51; 44, 52; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:base; 48, identifier:filter; 49, identifier:type; 50, identifier:sort; 51, identifier:limit; 52, identifier:page; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, pattern_list; 55, 56; 55, 57; 56, identifier:ps; 57, identifier:l; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:service; 63, identifier:decode; 64, argument_list; 64, 65; 64, 66; 64, 67; 64, 70; 65, identifier:schema; 66, identifier:resp; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:many; 69, True; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:links; 72, True; 73, return_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:Page; 76, argument_list; 76, 77; 76, 78; 77, identifier:ps; 78, identifier:l
def list(self, filter=None, type=None, sort=None, limit=None, page=None): schema = PackageSchema(exclude=('testlist', 'extra_cli_args', 'agent_id', 'options', 'note')) resp = self.service.list(self.base, filter, type, sort, limit, page) ps, l = self.service.decode(schema, resp, many=True, links=True) return Page(ps, l)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:clean_lines; 3, parameters; 3, 4; 4, identifier:commands; 5, block; 5, 6; 5, 84; 6, if_statement; 6, 7; 6, 12; 6, 69; 6, 77; 7, call; 7, 8; 7, 9; 8, identifier:isinstance; 9, argument_list; 9, 10; 9, 11; 10, identifier:commands; 11, identifier:basestring; 12, block; 12, 13; 13, if_statement; 13, 14; 13, 20; 13, 29; 13, 51; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:path; 17, identifier:isfile; 18, argument_list; 18, 19; 19, identifier:commands; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:commands; 24, call; 24, 25; 24, 26; 25, identifier:open; 26, argument_list; 26, 27; 26, 28; 27, identifier:commands; 28, string:'rb'; 29, elif_clause; 29, 30; 29, 41; 30, comparison_operator:>; 30, 31; 30, 40; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:commands; 37, identifier:split; 38, argument_list; 38, 39; 39, string:','; 40, integer:1; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:commands; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:commands; 48, identifier:split; 49, argument_list; 49, 50; 50, string:','; 51, else_clause; 51, 52; 52, block; 52, 53; 53, try_statement; 53, 54; 53, 64; 53, 65; 54, ERROR; 54, 55; 54, 62; 54, 63; 55, subscript; 55, 56; 55, 61; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:commands; 59, identifier:strip; 60, argument_list; 61, integer:0; 62, string:" yield commands.strip() + '\n; 63, identifier:return; 64, block:; 65, except_clause; 65, 66; 65, 67; 66, identifier:IndexError; 67, block; 67, 68; 68, pass_statement; 69, elif_clause; 69, 70; 69, 75; 70, call; 70, 71; 70, 72; 71, identifier:isinstance; 72, argument_list; 72, 73; 72, 74; 73, identifier:commands; 74, identifier:list; 75, block; 75, 76; 76, pass_statement; 77, else_clause; 77, 78; 78, block; 78, 79; 79, raise_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:TypeError; 82, argument_list; 82, 83; 83, string:'clean_lines() accepts a \'str\' or \'list\''; 84, for_statement; 84, 85; 84, 86; 84, 87; 84, 105; 85, identifier:cmd; 86, identifier:commands; 87, ERROR; 87, 88; 87, 104; 88, ERROR; 88, 89; 89, block; 89, 90; 89, 103; 90, if_statement; 90, 91; 90, 102; 91, comparison_operator:!=; 91, 92; 91, 99; 91, 101; 92, subscript; 92, 93; 92, 98; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:cmd; 96, identifier:strip; 97, argument_list; 98, integer:0; 99, ERROR; 99, 100; 100, string:" yield cmd.strip() + '\n; 101, identifier:IndexError; 102, block:; 103, pass_statement; 104, block:; 105, block:
def clean_lines(commands): if isinstance(commands, basestring): if path.isfile(commands): commands = open(commands, 'rb') elif len(commands.split(',')) > 1: commands = commands.split(',') else: try: if commands.strip()[0] != " yield commands.strip() + '\n' return except IndexError: pass elif isinstance(commands, list): pass else: raise TypeError('clean_lines() accepts a \'str\' or \'list\'') for cmd in commands: try: if cmd.strip()[0] != " yield cmd.strip() + '\n' except IndexError: pass
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:xpath; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:source_xml; 5, identifier:xpath_expr; 6, default_parameter; 6, 7; 6, 8; 7, identifier:req_format; 8, string:'string'; 9, block; 9, 10; 9, 14; 9, 33; 9, 80; 9, 90; 9, 99; 9, 106; 9, 126; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:tree; 13, identifier:source_xml; 14, if_statement; 14, 15; 14, 23; 15, not_operator; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:isinstance; 18, argument_list; 18, 19; 18, 20; 19, identifier:source_xml; 20, attribute; 20, 21; 20, 22; 21, identifier:ET; 22, identifier:Element; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:tree; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:objectify; 30, identifier:fromstring; 31, argument_list; 31, 32; 32, identifier:source_xml; 33, for_statement; 33, 34; 33, 35; 33, 40; 34, identifier:elem; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:tree; 38, identifier:getiterator; 39, argument_list; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 49; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:elem; 47, identifier:tag; 48, identifier:basestring; 49, block; 49, 50; 49, 61; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:i; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:elem; 57, identifier:tag; 58, identifier:find; 59, argument_list; 59, 60; 60, string:'}'; 61, if_statement; 61, 62; 61, 65; 62, comparison_operator:>=; 62, 63; 62, 64; 63, identifier:i; 64, integer:0; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:elem; 70, identifier:tag; 71, subscript; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:elem; 74, identifier:tag; 75, slice; 75, 76; 75, 79; 76, binary_operator:+; 76, 77; 76, 78; 77, identifier:i; 78, integer:1; 79, colon; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:objectify; 84, identifier:deannotate; 85, argument_list; 85, 86; 85, 87; 86, identifier:tree; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:cleanup_namespaces; 89, True; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:filtered_list; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:tree; 96, identifier:xpath; 97, argument_list; 97, 98; 98, identifier:xpath_expr; 99, if_statement; 99, 100; 99, 103; 100, comparison_operator:==; 100, 101; 100, 102; 101, identifier:req_format; 102, string:'xml'; 103, block; 103, 104; 104, return_statement; 104, 105; 105, identifier:filtered_list; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:matches; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, string:''; 112, identifier:join; 113, generator_expression; 113, 114; 113, 123; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:etree; 117, identifier:tostring; 118, argument_list; 118, 119; 118, 120; 119, identifier:element; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:pretty_print; 122, True; 123, for_in_clause; 123, 124; 123, 125; 124, identifier:element; 125, identifier:filtered_list; 126, return_statement; 126, 127; 127, conditional_expression:if; 127, 128; 127, 129; 127, 130; 128, identifier:matches; 129, identifier:matches; 130, string:""
def xpath(source_xml, xpath_expr, req_format='string'): tree = source_xml if not isinstance(source_xml, ET.Element): tree = objectify.fromstring(source_xml) for elem in tree.getiterator(): if isinstance(elem.tag, basestring): i = elem.tag.find('}') if i >= 0: elem.tag = elem.tag[i+1:] objectify.deannotate(tree, cleanup_namespaces=True) filtered_list = tree.xpath(xpath_expr) if req_format == 'xml': return filtered_list matches = ''.join(etree.tostring( element, pretty_print=True) for element in filtered_list) return matches if matches else ""
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:model_to_dict; 3, parameters; 3, 4; 3, 5; 4, identifier:instance; 5, dictionary_splat_pattern; 5, 6; 6, identifier:options; 7, block; 7, 8; 7, 10; 7, 17; 7, 21; 7, 53; 7, 242; 7, 257; 8, expression_statement; 8, 9; 9, string:"Takes a model instance and converts it into a dict."; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:options; 13, call; 13, 14; 13, 15; 14, identifier:_defaults; 15, argument_list; 15, 16; 16, identifier:options; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:attrs; 20, dictionary; 21, if_statement; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:options; 24, string:'prehook'; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 36; 27, call; 27, 28; 27, 29; 28, identifier:isinstance; 29, argument_list; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:options; 32, string:'prehook'; 33, attribute; 33, 34; 33, 35; 34, identifier:collections; 35, identifier:Callable; 36, block; 36, 37; 36, 46; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:instance; 40, call; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:options; 43, string:'prehook'; 44, argument_list; 44, 45; 45, identifier:instance; 46, if_statement; 46, 47; 46, 50; 47, comparison_operator:is; 47, 48; 47, 49; 48, identifier:instance; 49, None; 50, block; 50, 51; 51, return_statement; 51, 52; 52, identifier:attrs; 53, for_statement; 53, 54; 53, 55; 53, 58; 54, identifier:alias; 55, subscript; 55, 56; 55, 57; 56, identifier:options; 57, string:'fields'; 58, block; 58, 59; 58, 71; 58, 79; 58, 91; 58, 104; 58, 236; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:accessor; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:options; 66, string:'aliases'; 67, identifier:get; 68, argument_list; 68, 69; 68, 70; 69, identifier:alias; 70, identifier:alias; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:key; 74, binary_operator:+; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:options; 77, string:'prefix'; 78, identifier:alias; 79, if_statement; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:options; 82, string:'camelcase'; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:key; 87, call; 87, 88; 87, 89; 88, identifier:convert_to_camel; 89, argument_list; 89, 90; 90, identifier:key; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:value; 94, call; 94, 95; 94, 96; 95, identifier:get_field_value; 96, argument_list; 96, 97; 96, 98; 96, 99; 97, identifier:instance; 98, identifier:accessor; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:allow_missing; 101, subscript; 101, 102; 101, 103; 102, identifier:options; 103, string:'allow_missing'; 104, if_statement; 104, 105; 104, 114; 105, call; 105, 106; 105, 107; 106, identifier:isinstance; 107, argument_list; 107, 108; 107, 109; 108, identifier:value; 109, tuple; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:models; 112, identifier:Model; 113, identifier:QuerySet; 114, block; 114, 115; 114, 130; 114, 150; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:_options; 118, call; 118, 119; 118, 120; 119, identifier:_defaults; 120, argument_list; 120, 121; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, subscript; 123, 124; 123, 125; 124, identifier:options; 125, string:'related'; 126, identifier:get; 127, argument_list; 127, 128; 127, 129; 128, identifier:accessor; 129, dictionary; 130, if_statement; 130, 131; 130, 136; 131, comparison_operator:in; 131, 132; 131, 133; 132, string:'%(accessor)s'; 133, subscript; 133, 134; 133, 135; 134, identifier:_options; 135, string:'prefix'; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:_options; 141, string:'prefix'; 142, binary_operator:%; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:_options; 145, string:'prefix'; 146, dictionary; 146, 147; 147, pair; 147, 148; 147, 149; 148, string:'accessor'; 149, identifier:alias; 150, if_statement; 150, 151; 150, 158; 150, 225; 151, call; 151, 152; 151, 153; 152, identifier:isinstance; 153, argument_list; 153, 154; 153, 155; 154, identifier:value; 155, attribute; 155, 156; 155, 157; 156, identifier:models; 157, identifier:Model; 158, block; 158, 159; 159, if_statement; 159, 160; 159, 178; 159, 197; 160, boolean_operator:and; 160, 161; 160, 173; 160, 174; 161, boolean_operator:and; 161, 162; 161, 170; 162, comparison_operator:==; 162, 163; 162, 169; 163, call; 163, 164; 163, 165; 164, identifier:len; 165, argument_list; 165, 166; 166, subscript; 166, 167; 166, 168; 167, identifier:_options; 168, string:'fields'; 169, integer:1; 170, subscript; 170, 171; 170, 172; 171, identifier:_options; 172, string:'flat'; 173, line_continuation:\; 174, not_operator; 174, 175; 175, subscript; 175, 176; 175, 177; 176, identifier:_options; 177, string:'merge'; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:value; 182, subscript; 182, 183; 182, 196; 183, call; 183, 184; 183, 185; 184, identifier:list; 185, argument_list; 185, 186; 186, call; 186, 187; 186, 195; 187, attribute; 187, 188; 187, 194; 188, call; 188, 189; 188, 190; 189, identifier:serialize; 190, argument_list; 190, 191; 190, 192; 191, identifier:value; 192, dictionary_splat; 192, 193; 193, identifier:_options; 194, identifier:values; 195, argument_list; 196, integer:0; 197, else_clause; 197, 198; 198, block; 198, 199; 198, 208; 198, 221; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:_attrs; 202, call; 202, 203; 202, 204; 203, identifier:serialize; 204, argument_list; 204, 205; 204, 206; 205, identifier:value; 206, dictionary_splat; 206, 207; 207, identifier:_options; 208, if_statement; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:_options; 211, string:'merge'; 212, block; 212, 213; 212, 220; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:attrs; 217, identifier:update; 218, argument_list; 218, 219; 219, identifier:_attrs; 220, continue_statement; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:value; 224, identifier:_attrs; 225, else_clause; 225, 226; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:value; 230, call; 230, 231; 230, 232; 231, identifier:serialize; 232, argument_list; 232, 233; 232, 234; 233, identifier:value; 234, dictionary_splat; 234, 235; 235, identifier:_options; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 241; 238, subscript; 238, 239; 238, 240; 239, identifier:attrs; 240, identifier:key; 241, identifier:value; 242, if_statement; 242, 243; 242, 246; 243, subscript; 243, 244; 243, 245; 244, identifier:options; 245, string:'posthook'; 246, block; 246, 247; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:attrs; 250, call; 250, 251; 250, 254; 251, subscript; 251, 252; 251, 253; 252, identifier:options; 253, string:'posthook'; 254, argument_list; 254, 255; 254, 256; 255, identifier:instance; 256, identifier:attrs; 257, return_statement; 257, 258; 258, identifier:attrs
def model_to_dict(instance, **options): "Takes a model instance and converts it into a dict." options = _defaults(options) attrs = {} if options['prehook']: if isinstance(options['prehook'], collections.Callable): instance = options['prehook'](instance) if instance is None: return attrs for alias in options['fields']: accessor = options['aliases'].get(alias, alias) key = options['prefix'] + alias if options['camelcase']: key = convert_to_camel(key) value = get_field_value(instance, accessor, allow_missing=options['allow_missing']) if isinstance(value, (models.Model, QuerySet)): _options = _defaults(options['related'].get(accessor, {})) if '%(accessor)s' in _options['prefix']: _options['prefix'] = _options['prefix'] % {'accessor': alias} if isinstance(value, models.Model): if len(_options['fields']) == 1 and _options['flat'] \ and not _options['merge']: value = list(serialize(value, **_options).values())[0] else: _attrs = serialize(value, **_options) if _options['merge']: attrs.update(_attrs) continue value = _attrs else: value = serialize(value, **_options) attrs[key] = value if options['posthook']: attrs = options['posthook'](instance, attrs) return attrs
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:filter; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:type; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:sort; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:limit; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:page; 20, None; 21, block; 21, 22; 21, 32; 21, 53; 21, 73; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:schema; 25, call; 25, 26; 25, 27; 26, identifier:AttachmentSchema; 27, argument_list; 27, 28; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:exclude; 30, parenthesized_expression; 30, 31; 31, string:'path'; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:resp; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:service; 40, identifier:list; 41, argument_list; 41, 42; 41, 48; 41, 49; 41, 50; 41, 51; 41, 52; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:_base; 46, argument_list; 46, 47; 47, identifier:id; 48, identifier:filter; 49, identifier:type; 50, identifier:sort; 51, identifier:limit; 52, identifier:page; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, pattern_list; 55, 56; 55, 57; 56, identifier:at; 57, identifier:l; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:service; 63, identifier:decode; 64, argument_list; 64, 65; 64, 66; 64, 67; 64, 70; 65, identifier:schema; 66, identifier:resp; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:many; 69, True; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:links; 72, True; 73, return_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:Page; 76, argument_list; 76, 77; 76, 78; 77, identifier:at; 78, identifier:l
def list(self, id, filter=None, type=None, sort=None, limit=None, page=None): schema = AttachmentSchema(exclude=('path')) resp = self.service.list(self._base(id), filter, type, sort, limit, page) at, l = self.service.decode(schema, resp, many=True, links=True) return Page(at, l)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:load_item; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:inbox; 5, default_parameter; 5, 6; 5, 7; 6, identifier:type; 7, string:"string"; 8, default_parameter; 8, 9; 8, 10; 9, identifier:remove; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:buffer; 13, None; 14, block; 14, 15; 14, 25; 14, 31; 14, 46; 14, 105; 14, 121; 14, 135; 14, 139; 14, 260; 14, 429; 14, 468; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 21; 17, pattern_list; 17, 18; 17, 19; 17, 20; 18, identifier:is_file; 19, identifier:is_fifo; 20, identifier:is_socket; 21, expression_list; 21, 22; 21, 23; 21, 24; 22, False; 23, False; 24, False; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:file; 28, subscript; 28, 29; 28, 30; 29, identifier:inbox; 30, integer:0; 31, try_statement; 31, 32; 31, 39; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:file_type; 36, subscript; 36, 37; 36, 38; 37, identifier:file; 38, integer:0; 39, except_clause; 39, 40; 40, block; 40, 41; 41, raise_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:ValueError; 44, argument_list; 44, 45; 45, string:"invalid inbox item"; 46, if_statement; 46, 47; 46, 50; 46, 64; 46, 87; 46, 96; 47, comparison_operator:==; 47, 48; 47, 49; 48, identifier:file_type; 49, string:"file"; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:is_file; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:os; 58, identifier:path; 59, identifier:exists; 60, argument_list; 60, 61; 61, subscript; 61, 62; 61, 63; 62, identifier:file; 63, integer:1; 64, elif_clause; 64, 65; 64, 68; 65, comparison_operator:==; 65, 66; 65, 67; 66, identifier:file_type; 67, string:"fifo"; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:is_fifo; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:stat; 75, identifier:S_ISFIFO; 76, argument_list; 76, 77; 77, attribute; 77, 78; 77, 86; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:os; 81, identifier:stat; 82, argument_list; 82, 83; 83, subscript; 83, 84; 83, 85; 84, identifier:file; 85, integer:1; 86, identifier:st_mode; 87, elif_clause; 87, 88; 87, 91; 88, comparison_operator:==; 88, 89; 88, 90; 89, identifier:file_type; 90, string:"socket"; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:is_socket; 95, True; 96, else_clause; 96, 97; 97, block; 97, 98; 98, raise_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:ValueError; 101, argument_list; 101, 102; 102, binary_operator:%; 102, 103; 102, 104; 103, string:"type: %s not undertood"; 104, identifier:file_type; 105, if_statement; 105, 106; 105, 115; 106, boolean_operator:and; 106, 107; 106, 111; 107, parenthesized_expression; 107, 108; 108, boolean_operator:or; 108, 109; 108, 110; 109, identifier:is_fifo; 110, identifier:is_socket; 111, parenthesized_expression; 111, 112; 112, comparison_operator:==; 112, 113; 112, 114; 113, identifier:type; 114, string:'mmap'; 115, block; 115, 116; 116, raise_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:ValueError; 119, argument_list; 119, 120; 120, string:"mmap is not supported for FIFOs and sockets"; 121, if_statement; 121, 122; 121, 129; 122, boolean_operator:and; 122, 123; 122, 127; 123, parenthesized_expression; 123, 124; 124, boolean_operator:or; 124, 125; 124, 126; 125, identifier:is_fifo; 126, identifier:is_socket; 127, not_operator; 127, 128; 128, identifier:remove; 129, block; 129, 130; 130, raise_statement; 130, 131; 131, call; 131, 132; 131, 133; 132, identifier:ValueError; 133, argument_list; 133, 134; 134, string:"FIFOs and sockets have to be removed"; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:start; 138, integer:0; 139, if_statement; 139, 140; 139, 143; 139, 182; 139, 247; 140, boolean_operator:or; 140, 141; 140, 142; 141, identifier:is_fifo; 142, identifier:is_file; 143, block; 143, 144; 143, 159; 143, 173; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:stop; 147, binary_operator:-; 147, 148; 147, 158; 148, attribute; 148, 149; 148, 157; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:os; 152, identifier:stat; 153, argument_list; 153, 154; 154, subscript; 154, 155; 154, 156; 155, identifier:file; 156, integer:1; 157, identifier:st_size; 158, integer:1; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:fd; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:os; 165, identifier:open; 166, argument_list; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:file; 169, integer:1; 170, attribute; 170, 171; 170, 172; 171, identifier:os; 172, identifier:O_RDONLY; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:BUFFER; 176, parenthesized_expression; 176, 177; 177, boolean_operator:or; 177, 178; 177, 179; 178, identifier:buffer; 179, subscript; 179, 180; 179, 181; 180, identifier:PAPY_DEFAULTS; 181, string:'PIPE_BUF'; 182, elif_clause; 182, 183; 182, 184; 183, identifier:is_socket; 184, block; 184, 185; 184, 202; 184, 216; 184, 225; 184, 230; 184, 238; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, pattern_list; 187, 188; 187, 189; 188, identifier:host; 189, identifier:port; 190, expression_list; 190, 191; 190, 199; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:socket; 194, identifier:gethostbyname; 195, argument_list; 195, 196; 196, subscript; 196, 197; 196, 198; 197, identifier:file; 198, integer:1; 199, subscript; 199, 200; 199, 201; 200, identifier:file; 201, integer:2; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:sock; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:socket; 208, identifier:socket; 209, argument_list; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:socket; 212, identifier:AF_INET; 213, attribute; 213, 214; 213, 215; 214, identifier:socket; 215, identifier:SOCK_STREAM; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:sock; 220, identifier:connect; 221, argument_list; 221, 222; 222, tuple; 222, 223; 222, 224; 223, identifier:host; 224, identifier:port; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:stop; 228, unary_operator:-; 228, 229; 229, integer:1; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:fd; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:sock; 236, identifier:fileno; 237, argument_list; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:BUFFER; 241, parenthesized_expression; 241, 242; 242, boolean_operator:or; 242, 243; 242, 244; 243, identifier:buffer; 244, subscript; 244, 245; 244, 246; 245, identifier:PAPY_DEFAULTS; 246, string:'TCP_RCVBUF'; 247, else_clause; 247, 248; 248, block; 248, 249; 249, raise_statement; 249, 250; 250, call; 250, 251; 250, 252; 251, identifier:ValueError; 252, argument_list; 252, 253; 253, binary_operator:%; 253, 254; 253, 255; 254, string:"got unknown inbox: %s"; 255, parenthesized_expression; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:repr; 258, argument_list; 258, 259; 259, identifier:inbox; 260, if_statement; 260, 261; 260, 264; 260, 346; 260, 420; 261, comparison_operator:==; 261, 262; 261, 263; 262, identifier:type; 263, string:'mmap'; 264, block; 264, 265; 264, 287; 264, 293; 264, 301; 264, 339; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:offset; 268, binary_operator:-; 268, 269; 268, 270; 269, identifier:start; 270, parenthesized_expression; 270, 271; 271, binary_operator:%; 271, 272; 271, 273; 272, identifier:start; 273, parenthesized_expression; 273, 274; 274, boolean_operator:or; 274, 275; 274, 281; 274, 282; 275, call; 275, 276; 275, 277; 276, identifier:getattr; 277, argument_list; 277, 278; 277, 279; 277, 280; 278, identifier:mmap; 279, string:'ALLOCATIONGRANULARITY'; 280, None; 281, line_continuation:\; 282, call; 282, 283; 282, 284; 283, identifier:getattr; 284, argument_list; 284, 285; 284, 286; 285, identifier:mmap; 286, string:'PAGESIZE'; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:start; 290, binary_operator:-; 290, 291; 290, 292; 291, identifier:start; 292, identifier:offset; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:stop; 296, binary_operator:+; 296, 297; 296, 300; 297, binary_operator:-; 297, 298; 297, 299; 298, identifier:stop; 299, identifier:offset; 300, integer:1; 301, try_statement; 301, 302; 301, 321; 302, block; 302, 303; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 306; 305, identifier:data; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:mmap; 309, identifier:mmap; 310, argument_list; 310, 311; 310, 312; 310, 313; 310, 318; 311, identifier:fd; 312, identifier:stop; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:access; 315, attribute; 315, 316; 315, 317; 316, identifier:mmap; 317, identifier:ACCESS_READ; 318, keyword_argument; 318, 319; 318, 320; 319, identifier:offset; 320, identifier:offset; 321, except_clause; 321, 322; 321, 323; 322, identifier:TypeError; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:data; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:mmap; 330, identifier:mmap; 331, argument_list; 331, 332; 331, 333; 331, 334; 332, identifier:fd; 333, identifier:stop; 334, keyword_argument; 334, 335; 334, 336; 335, identifier:access; 336, attribute; 336, 337; 336, 338; 337, identifier:mmap; 338, identifier:ACCESS_READ; 339, expression_statement; 339, 340; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:data; 343, identifier:seek; 344, argument_list; 344, 345; 345, identifier:start; 346, elif_clause; 346, 347; 346, 350; 347, comparison_operator:==; 347, 348; 347, 349; 348, identifier:type; 349, string:'string'; 350, block; 350, 351; 350, 355; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 354; 353, identifier:data; 354, list:[]; 355, if_statement; 355, 356; 355, 360; 355, 395; 356, comparison_operator:==; 356, 357; 356, 358; 357, identifier:stop; 358, unary_operator:-; 358, 359; 359, integer:1; 360, block; 360, 361; 360, 386; 361, while_statement; 361, 362; 361, 363; 362, True; 363, block; 363, 364; 363, 374; 363, 379; 364, expression_statement; 364, 365; 365, assignment; 365, 366; 365, 367; 366, identifier:buffer_; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:os; 370, identifier:read; 371, argument_list; 371, 372; 371, 373; 372, identifier:fd; 373, identifier:BUFFER; 374, if_statement; 374, 375; 374, 377; 375, not_operator; 375, 376; 376, identifier:buffer_; 377, block; 377, 378; 378, break_statement; 379, expression_statement; 379, 380; 380, call; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:data; 383, identifier:append; 384, argument_list; 384, 385; 385, identifier:buffer_; 386, expression_statement; 386, 387; 387, assignment; 387, 388; 387, 389; 388, identifier:data; 389, call; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, string:""; 392, identifier:join; 393, argument_list; 393, 394; 394, identifier:data; 395, else_clause; 395, 396; 396, block; 396, 397; 396, 406; 397, expression_statement; 397, 398; 398, call; 398, 399; 398, 402; 399, attribute; 399, 400; 399, 401; 400, identifier:os; 401, identifier:lseek; 402, argument_list; 402, 403; 402, 404; 402, 405; 403, identifier:fd; 404, identifier:start; 405, integer:0; 406, expression_statement; 406, 407; 407, assignment; 407, 408; 407, 409; 408, identifier:data; 409, call; 409, 410; 409, 413; 410, attribute; 410, 411; 410, 412; 411, identifier:os; 412, identifier:read; 413, argument_list; 413, 414; 413, 415; 414, identifier:fd; 415, binary_operator:+; 415, 416; 415, 419; 416, binary_operator:-; 416, 417; 416, 418; 417, identifier:stop; 418, identifier:start; 419, integer:1; 420, else_clause; 420, 421; 421, block; 421, 422; 422, raise_statement; 422, 423; 423, call; 423, 424; 423, 425; 424, identifier:ValueError; 425, argument_list; 425, 426; 426, binary_operator:%; 426, 427; 426, 428; 427, string:'type: %s not understood.'; 428, identifier:type; 429, if_statement; 429, 430; 429, 431; 429, 459; 430, identifier:remove; 431, block; 431, 432; 432, if_statement; 432, 433; 432, 434; 432, 441; 433, identifier:is_socket; 434, block; 434, 435; 435, expression_statement; 435, 436; 436, call; 436, 437; 436, 440; 437, attribute; 437, 438; 437, 439; 438, identifier:sock; 439, identifier:close; 440, argument_list; 441, else_clause; 441, 442; 442, block; 442, 443; 442, 450; 443, expression_statement; 443, 444; 444, call; 444, 445; 444, 448; 445, attribute; 445, 446; 445, 447; 446, identifier:os; 447, identifier:close; 448, argument_list; 448, 449; 449, identifier:fd; 450, expression_statement; 450, 451; 451, call; 451, 452; 451, 455; 452, attribute; 452, 453; 452, 454; 453, identifier:os; 454, identifier:unlink; 455, argument_list; 455, 456; 456, subscript; 456, 457; 456, 458; 457, identifier:file; 458, integer:1; 459, else_clause; 459, 460; 460, block; 460, 461; 461, expression_statement; 461, 462; 462, call; 462, 463; 462, 466; 463, attribute; 463, 464; 463, 465; 464, identifier:os; 465, identifier:close; 466, argument_list; 466, 467; 467, identifier:fd; 468, return_statement; 468, 469; 469, identifier:data
def load_item(inbox, type="string", remove=True, buffer=None): is_file, is_fifo, is_socket = False, False, False file = inbox[0] try: file_type = file[0] except: raise ValueError("invalid inbox item") if file_type == "file": is_file = os.path.exists(file[1]) elif file_type == "fifo": is_fifo = stat.S_ISFIFO(os.stat(file[1]).st_mode) elif file_type == "socket": is_socket = True else: raise ValueError("type: %s not undertood" % file_type) if (is_fifo or is_socket) and (type == 'mmap'): raise ValueError("mmap is not supported for FIFOs and sockets") if (is_fifo or is_socket) and not remove: raise ValueError("FIFOs and sockets have to be removed") start = 0 if is_fifo or is_file: stop = os.stat(file[1]).st_size - 1 fd = os.open(file[1], os.O_RDONLY) BUFFER = (buffer or PAPY_DEFAULTS['PIPE_BUF']) elif is_socket: host, port = socket.gethostbyname(file[1]), file[2] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, port)) stop = -1 fd = sock.fileno() BUFFER = (buffer or PAPY_DEFAULTS['TCP_RCVBUF']) else: raise ValueError("got unknown inbox: %s" % (repr(inbox))) if type == 'mmap': offset = start - (start % (getattr(mmap, 'ALLOCATIONGRANULARITY', None)\ or getattr(mmap, 'PAGESIZE'))) start = start - offset stop = stop - offset + 1 try: data = mmap.mmap(fd, stop, access=mmap.ACCESS_READ, offset=offset) except TypeError: data = mmap.mmap(fd, stop, access=mmap.ACCESS_READ) data.seek(start) elif type == 'string': data = [] if stop == -1: while True: buffer_ = os.read(fd, BUFFER) if not buffer_: break data.append(buffer_) data = "".join(data) else: os.lseek(fd, start, 0) data = os.read(fd, stop - start + 1) else: raise ValueError('type: %s not understood.' % type) if remove: if is_socket: sock.close() else: os.close(fd) os.unlink(file[1]) else: os.close(fd) return data
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:write_validate; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:ctx; 5, identifier:param; 6, identifier:value; 7, block; 7, 8; 8, if_statement; 8, 9; 8, 14; 8, 82; 9, comparison_operator:!=; 9, 10; 9, 11; 10, identifier:value; 11, tuple; 11, 12; 11, 13; 12, string:"default"; 13, string:"default"; 14, block; 14, 15; 14, 43; 14, 68; 15, try_statement; 15, 16; 15, 29; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, pattern_list; 19, 20; 19, 21; 20, identifier:mode; 21, identifier:dest_file; 22, tuple; 22, 23; 22, 26; 23, subscript; 23, 24; 23, 25; 24, identifier:value; 25, integer:0; 26, subscript; 26, 27; 26, 28; 27, identifier:value; 28, integer:1; 29, except_clause; 29, 30; 29, 31; 30, identifier:IndexError; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:click; 36, identifier:BadParameter; 37, argument_list; 37, 38; 38, concatenated_string; 38, 39; 38, 40; 38, 41; 38, 42; 39, string:'Expecting two arguments, one for how to '; 40, string:'output (s, single, m, multiple), and '; 41, string:'the second is a filepath where to put'; 42, string:' the output.'; 43, if_statement; 43, 44; 43, 55; 44, comparison_operator:not; 44, 45; 44, 50; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:mode; 48, identifier:lower; 49, argument_list; 50, list:['s', 'single', 'm', 'multiple']; 50, 51; 50, 52; 50, 53; 50, 54; 51, string:'s'; 52, string:'single'; 53, string:'m'; 54, string:'multiple'; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:click; 60, identifier:BadParameter; 61, argument_list; 61, 62; 62, concatenated_string; 62, 63; 62, 64; 62, 65; 62, 66; 62, 67; 63, string:'The first argument of the -w/--write '; 64, string:'option must specifies whether to write'; 65, string:' to one file per device, or all device'; 66, string:' output to a single file. Valid options'; 67, string:' are "s", "single", "m", and "multiple"'; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 75; 70, subscript; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:ctx; 73, identifier:obj; 74, string:'out'; 75, tuple; 75, 76; 75, 81; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:mode; 79, identifier:lower; 80, argument_list; 81, identifier:dest_file; 82, else_clause; 82, 83; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:ctx; 89, identifier:obj; 90, string:'out'; 91, None
def write_validate(ctx, param, value): if value != ("default", "default"): try: mode, dest_file = (value[0], value[1]) except IndexError: raise click.BadParameter('Expecting two arguments, one for how to ' 'output (s, single, m, multiple), and ' 'the second is a filepath where to put' ' the output.') if mode.lower() not in ['s', 'single', 'm', 'multiple']: raise click.BadParameter('The first argument of the -w/--write ' 'option must specifies whether to write' ' to one file per device, or all device' ' output to a single file. Valid options' ' are "s", "single", "m", and "multiple"') ctx.obj['out'] = (mode.lower(), dest_file) else: ctx.obj['out'] = None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:write_out; 3, parameters; 3, 4; 4, identifier:input; 5, block; 5, 6; 5, 12; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, pattern_list; 8, 9; 8, 10; 9, identifier:to_file; 10, identifier:output; 11, identifier:input; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:!=; 13, 14; 13, 15; 14, identifier:to_file; 15, string:"quiet"; 16, block; 16, 17; 17, try_statement; 17, 18; 17, 25; 17, 35; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, pattern_list; 21, 22; 21, 23; 22, identifier:mode; 23, identifier:dest_file; 24, identifier:to_file; 25, except_clause; 25, 26; 25, 27; 26, identifier:TypeError; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:click; 32, identifier:echo; 33, argument_list; 33, 34; 34, identifier:output; 35, else_clause; 35, 36; 36, block; 36, 37; 36, 59; 36, 94; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:ip; 40, call; 40, 41; 40, 58; 41, attribute; 41, 42; 41, 57; 42, subscript; 42, 43; 42, 56; 43, call; 43, 44; 43, 54; 44, attribute; 44, 45; 44, 53; 45, subscript; 45, 46; 45, 52; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:output; 49, identifier:split; 50, argument_list; 50, 51; 51, string:'device: '; 52, integer:1; 53, identifier:split; 54, argument_list; 54, 55; 55, string:'\n'; 56, integer:0; 57, identifier:strip; 58, argument_list; 59, if_statement; 59, 60; 59, 65; 60, comparison_operator:in; 60, 61; 60, 62; 61, identifier:mode; 62, list:['m', 'multiple']; 62, 63; 62, 64; 63, string:'m'; 64, string:'multiple'; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:dest_file; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:path; 72, identifier:join; 73, argument_list; 73, 74; 73, 82; 74, subscript; 74, 75; 74, 81; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:path; 78, identifier:split; 79, argument_list; 79, 80; 80, identifier:dest_file; 81, integer:0; 82, binary_operator:+; 82, 83; 82, 86; 83, binary_operator:+; 83, 84; 83, 85; 84, identifier:ip; 85, string:"_"; 86, subscript; 86, 87; 86, 93; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:path; 90, identifier:split; 91, argument_list; 91, 92; 92, identifier:dest_file; 93, integer:1; 94, try_statement; 94, 95; 94, 104; 94, 139; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:out_file; 99, call; 99, 100; 99, 101; 100, identifier:open; 101, argument_list; 101, 102; 101, 103; 102, identifier:dest_file; 103, string:'a+b'; 104, except_clause; 104, 105; 104, 109; 105, as_pattern; 105, 106; 105, 107; 106, identifier:IOError; 107, as_pattern_target; 107, 108; 108, identifier:e; 109, block; 109, 110; 109, 125; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:print; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:color; 116, argument_list; 116, 117; 116, 124; 117, binary_operator:%; 117, 118; 117, 121; 118, concatenated_string; 118, 119; 118, 120; 119, string:"Could not open output file '%s' for writing. "; 120, string:"Output would have been:\n%s"; 121, tuple; 121, 122; 121, 123; 122, identifier:dest_file; 123, identifier:output; 124, string:'red'; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:print; 128, argument_list; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:color; 131, argument_list; 131, 132; 131, 138; 132, binary_operator:+; 132, 133; 132, 134; 133, string:'Here is the error for opening the output file:'; 134, call; 134, 135; 134, 136; 135, identifier:str; 136, argument_list; 136, 137; 137, identifier:e; 138, string:'red'; 139, else_clause; 139, 140; 140, block; 140, 141; 140, 154; 140, 166; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:click; 145, identifier:echo; 146, argument_list; 146, 147; 146, 148; 146, 151; 147, identifier:output; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:nl; 150, False; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:file; 153, identifier:out_file; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:print; 157, argument_list; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:color; 160, argument_list; 160, 161; 161, binary_operator:%; 161, 162; 161, 163; 162, string:'%s output appended to: %s'; 163, tuple; 163, 164; 163, 165; 164, identifier:ip; 165, identifier:dest_file; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:out_file; 170, identifier:close; 171, argument_list
def write_out(input): to_file, output = input if to_file != "quiet": try: mode, dest_file = to_file except TypeError: click.echo(output) else: ip = output.split('device: ')[1].split('\n')[0].strip() if mode in ['m', 'multiple']: dest_file = path.join(path.split(dest_file)[0], ip + "_" + path.split(dest_file)[1]) try: out_file = open(dest_file, 'a+b') except IOError as e: print(color("Could not open output file '%s' for writing. " "Output would have been:\n%s" % (dest_file, output), 'red')) print(color('Here is the error for opening the output file:' + str(e), 'red')) else: click.echo(output, nl=False, file=out_file) print(color('%s output appended to: %s' % (ip, dest_file))) out_file.close()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:endpoint; 3, parameters; 3, 4; 4, identifier:request; 5, block; 5, 6; 5, 15; 5, 52; 5, 79; 5, 110; 5, 134; 5, 157; 5, 168; 5, 177; 5, 202; 5, 229; 5, 246; 5, 288; 5, 316; 6, if_statement; 6, 7; 6, 12; 7, comparison_operator:!=; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:request; 10, identifier:method; 11, string:'POST'; 12, block; 12, 13; 13, raise_statement; 13, 14; 14, identifier:Http404; 15, if_statement; 15, 16; 15, 21; 16, call; 16, 17; 16, 18; 17, identifier:hasattr; 18, argument_list; 18, 19; 18, 20; 19, identifier:settings; 20, string:'BOUNCY_TOPIC_ARN'; 21, block; 21, 22; 21, 34; 22, if_statement; 22, 23; 22, 28; 23, comparison_operator:not; 23, 24; 23, 25; 24, string:'HTTP_X_AMZ_SNS_TOPIC_ARN'; 25, attribute; 25, 26; 25, 27; 26, identifier:request; 27, identifier:META; 28, block; 28, 29; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:HttpResponseBadRequest; 32, argument_list; 32, 33; 33, string:'No TopicArn Header'; 34, if_statement; 34, 35; 34, 46; 35, parenthesized_expression; 35, 36; 36, not_operator; 36, 37; 37, comparison_operator:in; 37, 38; 37, 43; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:request; 41, identifier:META; 42, string:'HTTP_X_AMZ_SNS_TOPIC_ARN'; 43, attribute; 43, 44; 43, 45; 44, identifier:settings; 45, identifier:BOUNCY_TOPIC_ARN; 46, block; 46, 47; 47, return_statement; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:HttpResponseBadRequest; 50, argument_list; 50, 51; 51, string:'Bad Topic'; 52, if_statement; 52, 53; 52, 60; 52, 67; 53, call; 53, 54; 53, 55; 54, identifier:isinstance; 55, argument_list; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:request; 58, identifier:body; 59, identifier:str; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:request_body; 64, attribute; 64, 65; 64, 66; 65, identifier:request; 66, identifier:body; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:request_body; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:request; 76, identifier:body; 77, identifier:decode; 78, argument_list; 79, try_statement; 79, 80; 79, 90; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:data; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:json; 87, identifier:loads; 88, argument_list; 88, 89; 89, identifier:request_body; 90, except_clause; 90, 91; 90, 92; 91, identifier:ValueError; 92, block; 92, 93; 92, 105; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:logger; 97, identifier:warning; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, string:'Notification Not Valid JSON: {}'; 102, identifier:format; 103, argument_list; 103, 104; 104, identifier:request_body; 105, return_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:HttpResponseBadRequest; 108, argument_list; 108, 109; 109, string:'Not Valid JSON'; 110, if_statement; 110, 111; 110, 121; 111, not_operator; 111, 112; 112, comparison_operator:<=; 112, 113; 112, 117; 113, call; 113, 114; 113, 115; 114, identifier:set; 115, argument_list; 115, 116; 116, identifier:VITAL_NOTIFICATION_FIELDS; 117, call; 117, 118; 117, 119; 118, identifier:set; 119, argument_list; 119, 120; 120, identifier:data; 121, block; 121, 122; 121, 129; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:logger; 126, identifier:warning; 127, argument_list; 127, 128; 128, string:'Request Missing Necessary Keys'; 129, return_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:HttpResponseBadRequest; 132, argument_list; 132, 133; 133, string:'Request Missing Necessary Keys'; 134, if_statement; 134, 135; 134, 141; 135, not_operator; 135, 136; 136, comparison_operator:in; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:data; 139, string:'Type'; 140, identifier:ALLOWED_TYPES; 141, block; 141, 142; 141, 152; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:logger; 146, identifier:info; 147, argument_list; 147, 148; 147, 149; 148, string:'Notification Type Not Known %s'; 149, subscript; 149, 150; 149, 151; 150, identifier:data; 151, string:'Type'; 152, return_statement; 152, 153; 153, call; 153, 154; 153, 155; 154, identifier:HttpResponseBadRequest; 155, argument_list; 155, 156; 156, string:'Unknown Notification Type'; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:domain; 160, attribute; 160, 161; 160, 167; 161, call; 161, 162; 161, 163; 162, identifier:urlparse; 163, argument_list; 163, 164; 164, subscript; 164, 165; 164, 166; 165, identifier:data; 166, string:'SigningCertURL'; 167, identifier:netloc; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:pattern; 171, call; 171, 172; 171, 173; 172, identifier:getattr; 173, argument_list; 173, 174; 173, 175; 173, 176; 174, identifier:settings; 175, string:'BOUNCY_CERT_DOMAIN_REGEX'; 176, string:r"sns.[a-z0-9\-]+.amazonaws.com$"; 177, if_statement; 177, 178; 177, 186; 178, not_operator; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:re; 182, identifier:search; 183, argument_list; 183, 184; 183, 185; 184, identifier:pattern; 185, identifier:domain; 186, block; 186, 187; 186, 197; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:logger; 191, identifier:warning; 192, argument_list; 192, 193; 192, 194; 193, string:'Improper Certificate Location %s'; 194, subscript; 194, 195; 194, 196; 195, identifier:data; 196, string:'SigningCertURL'; 197, return_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:HttpResponseBadRequest; 200, argument_list; 200, 201; 201, string:'Improper Certificate Location'; 202, if_statement; 202, 203; 202, 216; 203, parenthesized_expression; 203, 204; 204, boolean_operator:and; 204, 205; 204, 211; 205, call; 205, 206; 205, 207; 206, identifier:getattr; 207, argument_list; 207, 208; 207, 209; 207, 210; 208, identifier:settings; 209, string:'BOUNCY_VERIFY_CERTIFICATE'; 210, True; 211, not_operator; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:verify_notification; 214, argument_list; 214, 215; 215, identifier:data; 216, block; 216, 217; 216, 224; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:logger; 221, identifier:error; 222, argument_list; 222, 223; 223, string:'Verification Failure %s'; 224, return_statement; 224, 225; 225, call; 225, 226; 225, 227; 226, identifier:HttpResponseBadRequest; 227, argument_list; 227, 228; 228, string:'Improper Signature'; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 236; 231, attribute; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:signals; 234, identifier:notification; 235, identifier:send; 236, argument_list; 236, 237; 236, 240; 236, 243; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:sender; 239, string:'bouncy_endpoint'; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:notification; 242, identifier:data; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:request; 245, identifier:request; 246, if_statement; 246, 247; 246, 252; 246, 269; 247, comparison_operator:==; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:data; 250, string:'Type'; 251, string:'SubscriptionConfirmation'; 252, block; 252, 253; 252, 264; 253, if_statement; 253, 254; 253, 261; 254, not_operator; 254, 255; 255, call; 255, 256; 255, 257; 256, identifier:getattr; 257, argument_list; 257, 258; 257, 259; 257, 260; 258, identifier:settings; 259, string:'BOUNCY_AUTO_SUBSCRIBE'; 260, True; 261, block; 261, 262; 262, raise_statement; 262, 263; 263, identifier:Http404; 264, return_statement; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:approve_subscription; 267, argument_list; 267, 268; 268, identifier:data; 269, elif_clause; 269, 270; 269, 275; 270, comparison_operator:==; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:data; 273, string:'Type'; 274, string:'UnsubscribeConfirmation'; 275, block; 275, 276; 275, 283; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:logger; 280, identifier:info; 281, argument_list; 281, 282; 282, string:'UnsubscribeConfirmation Not Handled'; 283, return_statement; 283, 284; 284, call; 284, 285; 284, 286; 285, identifier:HttpResponse; 286, argument_list; 286, 287; 287, string:'UnsubscribeConfirmation Not Handled'; 288, try_statement; 288, 289; 288, 301; 289, block; 289, 290; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:message; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:json; 296, identifier:loads; 297, argument_list; 297, 298; 298, subscript; 298, 299; 298, 300; 299, identifier:data; 300, string:'Message'; 301, except_clause; 301, 302; 301, 303; 302, identifier:ValueError; 303, block; 303, 304; 303, 311; 304, expression_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:logger; 308, identifier:info; 309, argument_list; 309, 310; 310, string:'Non-Valid JSON Message Received'; 311, return_statement; 311, 312; 312, call; 312, 313; 312, 314; 313, identifier:HttpResponse; 314, argument_list; 314, 315; 315, string:'Message is not valid JSON'; 316, return_statement; 316, 317; 317, call; 317, 318; 317, 319; 318, identifier:process_message; 319, argument_list; 319, 320; 319, 321; 320, identifier:message; 321, identifier:data
def endpoint(request): if request.method != 'POST': raise Http404 if hasattr(settings, 'BOUNCY_TOPIC_ARN'): if 'HTTP_X_AMZ_SNS_TOPIC_ARN' not in request.META: return HttpResponseBadRequest('No TopicArn Header') if (not request.META['HTTP_X_AMZ_SNS_TOPIC_ARN'] in settings.BOUNCY_TOPIC_ARN): return HttpResponseBadRequest('Bad Topic') if isinstance(request.body, str): request_body = request.body else: request_body = request.body.decode() try: data = json.loads(request_body) except ValueError: logger.warning('Notification Not Valid JSON: {}'.format(request_body)) return HttpResponseBadRequest('Not Valid JSON') if not set(VITAL_NOTIFICATION_FIELDS) <= set(data): logger.warning('Request Missing Necessary Keys') return HttpResponseBadRequest('Request Missing Necessary Keys') if not data['Type'] in ALLOWED_TYPES: logger.info('Notification Type Not Known %s', data['Type']) return HttpResponseBadRequest('Unknown Notification Type') domain = urlparse(data['SigningCertURL']).netloc pattern = getattr( settings, 'BOUNCY_CERT_DOMAIN_REGEX', r"sns.[a-z0-9\-]+.amazonaws.com$" ) if not re.search(pattern, domain): logger.warning( 'Improper Certificate Location %s', data['SigningCertURL']) return HttpResponseBadRequest('Improper Certificate Location') if (getattr(settings, 'BOUNCY_VERIFY_CERTIFICATE', True) and not verify_notification(data)): logger.error('Verification Failure %s', ) return HttpResponseBadRequest('Improper Signature') signals.notification.send( sender='bouncy_endpoint', notification=data, request=request) if data['Type'] == 'SubscriptionConfirmation': if not getattr(settings, 'BOUNCY_AUTO_SUBSCRIBE', True): raise Http404 return approve_subscription(data) elif data['Type'] == 'UnsubscribeConfirmation': logger.info('UnsubscribeConfirmation Not Handled') return HttpResponse('UnsubscribeConfirmation Not Handled') try: message = json.loads(data['Message']) except ValueError: logger.info('Non-Valid JSON Message Received') return HttpResponse('Message is not valid JSON') return process_message(message, data)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_process_value; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:value; 6, identifier:type; 7, block; 7, 8; 7, 30; 8, if_statement; 8, 9; 8, 20; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:isinstance; 12, argument_list; 12, 13; 12, 14; 13, identifier:value; 14, binary_operator:+; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:six; 17, identifier:string_types; 18, tuple; 18, 19; 19, identifier:list; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:value; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:json; 27, identifier:dumps; 28, argument_list; 28, 29; 29, identifier:value; 30, return_statement; 30, 31; 31, identifier:value
def _process_value(self, value, type): if not isinstance(value, six.string_types + (list,)): value = json.dumps(value) return value
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:representatives; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:count; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sorting; 10, False; 11, block; 11, 12; 11, 16; 11, 33; 11, 48; 11, 58; 11, 69; 11, 88; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:payload; 15, dictionary; 16, if_statement; 16, 17; 16, 20; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:count; 19, None; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 26; 23, subscript; 23, 24; 23, 25; 24, identifier:payload; 25, string:'count'; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_process_value; 30, argument_list; 30, 31; 30, 32; 31, identifier:count; 32, string:'int'; 33, if_statement; 33, 34; 33, 35; 34, identifier:sorting; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:payload; 40, string:'sorting'; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:_process_value; 45, argument_list; 45, 46; 45, 47; 46, identifier:sorting; 47, string:'strbool'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:resp; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:call; 55, argument_list; 55, 56; 55, 57; 56, string:'representatives'; 57, identifier:payload; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:representatives; 61, boolean_operator:or; 61, 62; 61, 68; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:resp; 65, identifier:get; 66, argument_list; 66, 67; 67, string:'representatives'; 68, dictionary; 69, for_statement; 69, 70; 69, 73; 69, 78; 70, pattern_list; 70, 71; 70, 72; 71, identifier:k; 72, identifier:v; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:representatives; 76, identifier:items; 77, argument_list; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:representatives; 83, identifier:k; 84, call; 84, 85; 84, 86; 85, identifier:int; 86, argument_list; 86, 87; 87, identifier:v; 88, return_statement; 88, 89; 89, identifier:representatives
def representatives(self, count=None, sorting=False): payload = {} if count is not None: payload['count'] = self._process_value(count, 'int') if sorting: payload['sorting'] = self._process_value(sorting, 'strbool') resp = self.call('representatives', payload) representatives = resp.get('representatives') or {} for k, v in representatives.items(): representatives[k] = int(v) return representatives
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:iterative_overlap_assembly; 3, parameters; 3, 4; 3, 5; 4, identifier:variant_sequences; 5, default_parameter; 5, 6; 5, 7; 6, identifier:min_overlap_size; 7, identifier:MIN_VARIANT_SEQUENCE_ASSEMBLY_OVERLAP_SIZE; 8, block; 8, 9; 8, 19; 8, 26; 8, 33; 8, 40; 8, 49; 8, 57; 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:variant_sequences; 15, integer:1; 16, block; 16, 17; 17, return_statement; 17, 18; 18, identifier:variant_sequences; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:n_before_collapse; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, identifier:variant_sequences; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:variant_sequences; 29, call; 29, 30; 29, 31; 30, identifier:collapse_substrings; 31, argument_list; 31, 32; 32, identifier:variant_sequences; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:n_after_collapse; 36, call; 36, 37; 36, 38; 37, identifier:len; 38, argument_list; 38, 39; 39, identifier:variant_sequences; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:logger; 44, identifier:info; 45, argument_list; 45, 46; 45, 47; 45, 48; 46, string:"Collapsed %d -> %d sequences"; 47, identifier:n_before_collapse; 48, identifier:n_after_collapse; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:merged_variant_sequences; 52, call; 52, 53; 52, 54; 53, identifier:greedy_merge; 54, argument_list; 54, 55; 54, 56; 55, identifier:variant_sequences; 56, identifier:min_overlap_size; 57, return_statement; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:list; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:sorted; 63, argument_list; 63, 64; 63, 65; 64, identifier:merged_variant_sequences; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:key; 67, lambda; 67, 68; 67, 70; 68, lambda_parameters; 68, 69; 69, identifier:seq; 70, unary_operator:-; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:len; 73, argument_list; 73, 74; 74, attribute; 74, 75; 74, 76; 75, identifier:seq; 76, identifier:reads
def iterative_overlap_assembly( variant_sequences, min_overlap_size=MIN_VARIANT_SEQUENCE_ASSEMBLY_OVERLAP_SIZE): if len(variant_sequences) <= 1: return variant_sequences n_before_collapse = len(variant_sequences) variant_sequences = collapse_substrings(variant_sequences) n_after_collapse = len(variant_sequences) logger.info( "Collapsed %d -> %d sequences", n_before_collapse, n_after_collapse) merged_variant_sequences = greedy_merge(variant_sequences, min_overlap_size) return list(sorted( merged_variant_sequences, key=lambda seq: -len(seq.reads)))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:ortho_basis; 3, parameters; 3, 4; 3, 5; 4, identifier:normal; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ref_vec; 7, None; 8, block; 8, 9; 8, 14; 8, 21; 8, 28; 8, 35; 8, 42; 8, 46; 8, 62; 8, 77; 8, 88; 8, 205; 8, 215; 8, 226; 8, 236; 8, 247; 9, import_statement; 9, 10; 10, aliased_import; 10, 11; 10, 13; 11, dotted_name; 11, 12; 12, identifier:numpy; 13, identifier:np; 14, import_from_statement; 14, 15; 14, 17; 15, dotted_name; 15, 16; 16, identifier:scipy; 17, aliased_import; 17, 18; 17, 20; 18, dotted_name; 18, 19; 19, identifier:linalg; 20, identifier:spla; 21, import_from_statement; 21, 22; 21, 24; 22, dotted_name; 22, 23; 23, identifier:scipy; 24, aliased_import; 24, 25; 24, 27; 25, dotted_name; 25, 26; 26, identifier:random; 27, identifier:sprnd; 28, import_from_statement; 28, 29; 28, 33; 29, relative_import; 29, 30; 29, 31; 30, import_prefix; 31, dotted_name; 31, 32; 32, identifier:const; 33, dotted_name; 33, 34; 34, identifier:PRM; 35, import_from_statement; 35, 36; 35, 40; 36, relative_import; 36, 37; 36, 38; 37, import_prefix; 38, dotted_name; 38, 39; 39, identifier:error; 40, dotted_name; 40, 41; 41, identifier:VectorError; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:RAND_MAG; 45, float:0.25; 46, if_statement; 46, 47; 46, 56; 47, not_operator; 47, 48; 48, comparison_operator:==; 48, 49; 48, 55; 49, call; 49, 50; 49, 51; 50, identifier:len; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:normal; 54, identifier:shape; 55, integer:1; 56, block; 56, 57; 57, raise_statement; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:ValueError; 60, argument_list; 60, 61; 61, string:"'normal' is not a vector"; 62, if_statement; 62, 63; 62, 71; 63, not_operator; 63, 64; 64, comparison_operator:==; 64, 65; 64, 70; 65, subscript; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:normal; 68, identifier:shape; 69, integer:0; 70, integer:3; 71, block; 71, 72; 72, raise_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:ValueError; 75, argument_list; 75, 76; 76, string:"Length of 'normal' is not three"; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:nv; 80, binary_operator:/; 80, 81; 80, 82; 81, identifier:normal; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:spla; 85, identifier:norm; 86, argument_list; 86, 87; 87, identifier:normal; 88, if_statement; 88, 89; 88, 92; 88, 145; 89, comparison_operator:is; 89, 90; 89, 91; 90, identifier:ref_vec; 91, None; 92, block; 92, 93; 92, 97; 92, 126; 92, 134; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:rv; 96, identifier:nv; 97, while_statement; 97, 98; 97, 103; 98, call; 98, 99; 98, 100; 99, identifier:parallel_check; 100, argument_list; 100, 101; 100, 102; 101, identifier:nv; 102, identifier:rv; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:rv; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:np; 110, identifier:float64; 111, argument_list; 111, 112; 112, binary_operator:+; 112, 113; 112, 116; 113, binary_operator:-; 113, 114; 113, 115; 114, float:1.0; 115, identifier:RAND_MAG; 116, binary_operator:*; 116, 117; 116, 120; 117, binary_operator:*; 117, 118; 117, 119; 118, integer:2; 119, identifier:RAND_MAG; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:sprnd; 123, identifier:rand; 124, argument_list; 124, 125; 125, integer:3; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:rv; 129, call; 129, 130; 129, 131; 130, identifier:rej; 131, argument_list; 131, 132; 131, 133; 132, identifier:rv; 133, identifier:nv; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:rv; 137, binary_operator:/; 137, 138; 137, 139; 138, identifier:rv; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:spla; 142, identifier:norm; 143, argument_list; 143, 144; 144, identifier:rv; 145, else_clause; 145, 146; 146, block; 146, 147; 146, 163; 146, 178; 146, 189; 147, if_statement; 147, 148; 147, 157; 148, not_operator; 148, 149; 149, comparison_operator:==; 149, 150; 149, 156; 150, call; 150, 151; 150, 152; 151, identifier:len; 152, argument_list; 152, 153; 153, attribute; 153, 154; 153, 155; 154, identifier:ref_vec; 155, identifier:shape; 156, integer:1; 157, block; 157, 158; 158, raise_statement; 158, 159; 159, call; 159, 160; 159, 161; 160, identifier:ValueError; 161, argument_list; 161, 162; 162, string:"ref_vec is not a vector"; 163, if_statement; 163, 164; 163, 172; 164, not_operator; 164, 165; 165, comparison_operator:==; 165, 166; 165, 171; 166, subscript; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:ref_vec; 169, identifier:shape; 170, integer:0; 171, integer:3; 172, block; 172, 173; 173, raise_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:ValueError; 176, argument_list; 176, 177; 177, string:"ref_vec length is not three"; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:rv; 181, binary_operator:/; 181, 182; 181, 183; 182, identifier:ref_vec; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:spla; 186, identifier:norm; 187, argument_list; 187, 188; 188, identifier:ref_vec; 189, if_statement; 189, 190; 189, 195; 190, call; 190, 191; 190, 192; 191, identifier:parallel_check; 192, argument_list; 192, 193; 192, 194; 193, identifier:nv; 194, identifier:rv; 195, block; 195, 196; 196, raise_statement; 196, 197; 197, call; 197, 198; 197, 199; 198, identifier:VectorError; 199, argument_list; 199, 200; 199, 203; 199, 204; 200, attribute; 200, 201; 200, 202; 201, identifier:VectorError; 202, identifier:NONPRL; 203, string:"'normal' and 'ref_vec' are too nearly parallel."; 204, string:""; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:on2; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:np; 211, identifier:cross; 212, argument_list; 212, 213; 212, 214; 213, identifier:nv; 214, identifier:rv; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:on2; 218, binary_operator:/; 218, 219; 218, 220; 219, identifier:on2; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:spla; 223, identifier:norm; 224, argument_list; 224, 225; 225, identifier:on2; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:on1; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:np; 232, identifier:cross; 233, argument_list; 233, 234; 233, 235; 234, identifier:on2; 235, identifier:nv; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:on1; 239, binary_operator:/; 239, 240; 239, 241; 240, identifier:on1; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:spla; 244, identifier:norm; 245, argument_list; 245, 246; 246, identifier:on1; 247, return_statement; 247, 248; 248, expression_list; 248, 249; 248, 250; 249, identifier:on1; 250, identifier:on2
def ortho_basis(normal, ref_vec=None): import numpy as np from scipy import linalg as spla from scipy import random as sprnd from ..const import PRM from ..error import VectorError RAND_MAG = 0.25 if not len(normal.shape) == 1: raise ValueError("'normal' is not a vector") if not normal.shape[0] == 3: raise ValueError("Length of 'normal' is not three") nv = normal / spla.norm(normal) if ref_vec is None: rv = nv while parallel_check(nv, rv): rv = np.float64(1.0 - RAND_MAG + 2 * RAND_MAG * sprnd.rand(3)) rv = rej(rv, nv) rv = rv / spla.norm(rv) else: if not len(ref_vec.shape) == 1: raise ValueError("ref_vec is not a vector") if not ref_vec.shape[0] == 3: raise ValueError("ref_vec length is not three") rv = ref_vec / spla.norm(ref_vec) if parallel_check(nv, rv): raise VectorError(VectorError.NONPRL, "'normal' and 'ref_vec' are too nearly parallel.", "") on2 = np.cross(nv, rv) on2 = on2 / spla.norm(on2) on1 = np.cross(on2, nv) on1 = on1 / spla.norm(on1) return on1, on2
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:orthonorm_check; 3, parameters; 3, 4; 3, 5; 3, 10; 4, identifier:a; 5, default_parameter; 5, 6; 5, 7; 6, identifier:tol; 7, attribute; 7, 8; 7, 9; 8, identifier:_DEF; 9, identifier:ORTHONORM_TOL; 10, default_parameter; 10, 11; 10, 12; 11, identifier:report; 12, False; 13, block; 13, 14; 13, 19; 13, 26; 13, 30; 13, 34; 13, 38; 13, 80; 13, 94; 13, 179; 14, import_statement; 14, 15; 15, aliased_import; 15, 16; 15, 18; 16, dotted_name; 16, 17; 17, identifier:numpy; 18, identifier:np; 19, import_from_statement; 19, 20; 19, 24; 20, relative_import; 20, 21; 20, 22; 21, import_prefix; 22, dotted_name; 22, 23; 23, identifier:base; 24, dotted_name; 24, 25; 25, identifier:delta_fxn; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:orth; 29, True; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:n_fail; 33, list:[]; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:o_fail; 37, list:[]; 38, if_statement; 38, 39; 38, 47; 38, 64; 39, comparison_operator:==; 39, 40; 39, 46; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:a; 45, identifier:shape; 46, integer:1; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:a_mx; 51, attribute; 51, 52; 51, 63; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:np; 55, identifier:matrix; 56, argument_list; 56, 57; 56, 58; 57, identifier:a; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:dtype; 60, attribute; 60, 61; 60, 62; 61, identifier:np; 62, identifier:float_; 63, identifier:T; 64, else_clause; 64, 65; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:a_mx; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:np; 72, identifier:matrix; 73, argument_list; 73, 74; 73, 75; 74, identifier:a; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:dtype; 77, attribute; 77, 78; 77, 79; 78, identifier:np; 79, identifier:float_; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:a_split; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:np; 86, identifier:hsplit; 87, argument_list; 87, 88; 87, 89; 88, identifier:a_mx; 89, subscript; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:a_mx; 92, identifier:shape; 93, integer:1; 94, for_statement; 94, 95; 94, 96; 94, 104; 95, identifier:iter1; 96, call; 96, 97; 96, 98; 97, identifier:range; 98, argument_list; 98, 99; 99, subscript; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:a_mx; 102, identifier:shape; 103, integer:1; 104, block; 104, 105; 105, for_statement; 105, 106; 105, 107; 105, 116; 106, identifier:iter2; 107, call; 107, 108; 107, 109; 108, identifier:range; 109, argument_list; 109, 110; 109, 111; 110, identifier:iter1; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:a_mx; 114, identifier:shape; 115, integer:1; 116, block; 116, 117; 117, if_statement; 117, 118; 117, 148; 118, not_operator; 118, 119; 119, comparison_operator:<=; 119, 120; 119, 147; 120, call; 120, 121; 120, 122; 121, identifier:abs; 122, argument_list; 122, 123; 123, binary_operator:-; 123, 124; 123, 137; 124, subscript; 124, 125; 124, 135; 124, 136; 125, parenthesized_expression; 125, 126; 126, binary_operator:*; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:a_split; 130, identifier:iter1; 131, identifier:T; 132, subscript; 132, 133; 132, 134; 133, identifier:a_split; 134, identifier:iter2; 135, integer:0; 136, integer:0; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:np; 140, identifier:float_; 141, argument_list; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:delta_fxn; 144, argument_list; 144, 145; 144, 146; 145, identifier:iter1; 146, identifier:iter2; 147, identifier:tol; 148, block; 148, 149; 148, 153; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:orth; 152, False; 153, if_statement; 153, 154; 153, 155; 154, identifier:report; 155, block; 155, 156; 156, if_statement; 156, 157; 156, 160; 156, 168; 157, comparison_operator:==; 157, 158; 157, 159; 158, identifier:iter1; 159, identifier:iter2; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:n_fail; 165, identifier:append; 166, argument_list; 166, 167; 167, identifier:iter1; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:o_fail; 174, identifier:append; 175, argument_list; 175, 176; 176, tuple; 176, 177; 176, 178; 177, identifier:iter1; 178, identifier:iter2; 179, if_statement; 179, 180; 179, 181; 179, 187; 180, identifier:report; 181, block; 181, 182; 182, return_statement; 182, 183; 183, expression_list; 183, 184; 183, 185; 183, 186; 184, identifier:orth; 185, identifier:n_fail; 186, identifier:o_fail; 187, else_clause; 187, 188; 188, block; 188, 189; 189, return_statement; 189, 190; 190, expression_list; 190, 191; 190, 192; 190, 193; 191, identifier:orth; 192, None; 193, None
def orthonorm_check(a, tol=_DEF.ORTHONORM_TOL, report=False): import numpy as np from .base import delta_fxn orth = True n_fail = [] o_fail = [] if len(a.shape) == 1: a_mx = np.matrix(a, dtype=np.float_).T else: a_mx = np.matrix(a, dtype=np.float_) a_split = np.hsplit(a_mx, a_mx.shape[1]) for iter1 in range(a_mx.shape[1]): for iter2 in range(iter1,a_mx.shape[1]): if not abs((a_split[iter1].T * a_split[iter2])[0,0] - np.float_(delta_fxn(iter1, iter2))) <= tol: orth = False if report: if iter1 == iter2: n_fail.append(iter1) else: o_fail.append((iter1, iter2)) if report: return orth, n_fail, o_fail else: return orth, None, None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parallel_check; 3, parameters; 3, 4; 3, 5; 4, identifier:vec1; 5, identifier:vec2; 6, block; 6, 7; 6, 14; 6, 19; 6, 23; 6, 51; 6, 70; 6, 78; 6, 102; 7, import_from_statement; 7, 8; 7, 12; 8, relative_import; 8, 9; 8, 10; 9, import_prefix; 10, dotted_name; 10, 11; 11, identifier:const; 12, dotted_name; 12, 13; 13, identifier:PRM; 14, import_statement; 14, 15; 15, aliased_import; 15, 16; 15, 18; 16, dotted_name; 16, 17; 17, identifier:numpy; 18, identifier:np; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:par; 22, False; 23, for_statement; 23, 24; 23, 27; 23, 33; 24, pattern_list; 24, 25; 24, 26; 25, identifier:n; 26, identifier:v; 27, call; 27, 28; 27, 29; 28, identifier:enumerate; 29, argument_list; 29, 30; 30, list:[vec1, vec2]; 30, 31; 30, 32; 31, identifier:vec1; 32, identifier:vec2; 33, block; 33, 34; 34, if_statement; 34, 35; 34, 44; 34, 50; 35, not_operator; 35, 36; 36, comparison_operator:==; 36, 37; 36, 43; 37, call; 37, 38; 37, 39; 38, identifier:len; 39, argument_list; 39, 40; 40, attribute; 40, 41; 40, 42; 41, identifier:v; 42, identifier:shape; 43, integer:1; 44, ERROR; 44, 45; 44, 46; 44, 48; 44, 49; 45, identifier:ValueError; 46, ERROR; 46, 47; 47, identifier:Bad; 48, identifier:shape; 49, identifier:vector; 50, block:; 51, if_statement; 51, 52; 51, 64; 52, not_operator; 52, 53; 53, comparison_operator:==; 53, 54; 53, 59; 54, subscript; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:vec1; 57, identifier:shape; 58, integer:0; 59, subscript; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:vec2; 62, identifier:shape; 63, integer:0; 64, block; 64, 65; 65, raise_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:ValueError; 68, argument_list; 68, 69; 69, string:"Vector length mismatch"; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:angle; 73, call; 73, 74; 73, 75; 74, identifier:vec_angle; 75, argument_list; 75, 76; 75, 77; 76, identifier:vec1; 77, identifier:vec2; 78, if_statement; 78, 79; 78, 97; 79, comparison_operator:<; 79, 80; 79, 94; 80, call; 80, 81; 80, 82; 81, identifier:min; 82, argument_list; 82, 83; 83, list:[abs(angle), abs(angle - 180.)]; 83, 84; 83, 88; 84, call; 84, 85; 84, 86; 85, identifier:abs; 86, argument_list; 86, 87; 87, identifier:angle; 88, call; 88, 89; 88, 90; 89, identifier:abs; 90, argument_list; 90, 91; 91, binary_operator:-; 91, 92; 91, 93; 92, identifier:angle; 93, float:180.; 94, attribute; 94, 95; 94, 96; 95, identifier:PRM; 96, identifier:NON_PARALLEL_TOL; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:par; 101, True; 102, return_statement; 102, 103; 103, identifier:par
def parallel_check(vec1, vec2): from ..const import PRM import numpy as np par = False for n,v in enumerate([vec1, vec2]): if not len(v.shape) == 1: raise ValueError("Bad shape for vector if not vec1.shape[0] == vec2.shape[0]: raise ValueError("Vector length mismatch") angle = vec_angle(vec1, vec2) if min([abs(angle), abs(angle - 180.)]) < PRM.NON_PARALLEL_TOL: par = True return par
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:vec_angle; 3, parameters; 3, 4; 3, 5; 4, identifier:vec1; 5, identifier:vec2; 6, block; 6, 7; 6, 12; 6, 19; 6, 26; 6, 41; 6, 56; 6, 74; 6, 91; 6, 108; 6, 132; 6, 167; 7, import_statement; 7, 8; 8, aliased_import; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier:numpy; 11, identifier:np; 12, import_from_statement; 12, 13; 12, 15; 13, dotted_name; 13, 14; 14, identifier:scipy; 15, aliased_import; 15, 16; 15, 18; 16, dotted_name; 16, 17; 17, identifier:linalg; 18, identifier:spla; 19, import_from_statement; 19, 20; 19, 24; 20, relative_import; 20, 21; 20, 22; 21, import_prefix; 22, dotted_name; 22, 23; 23, identifier:const; 24, dotted_name; 24, 25; 25, identifier:PRM; 26, if_statement; 26, 27; 26, 35; 27, comparison_operator:!=; 27, 28; 27, 34; 28, call; 28, 29; 28, 30; 29, identifier:len; 30, argument_list; 30, 31; 31, attribute; 31, 32; 31, 33; 32, identifier:vec1; 33, identifier:shape; 34, integer:1; 35, block; 35, 36; 36, raise_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:ValueError; 39, argument_list; 39, 40; 40, string:"'vec1' is not a vector"; 41, if_statement; 41, 42; 41, 50; 42, comparison_operator:!=; 42, 43; 42, 49; 43, call; 43, 44; 43, 45; 44, identifier:len; 45, argument_list; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:vec2; 48, identifier:shape; 49, integer:1; 50, block; 50, 51; 51, raise_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:ValueError; 54, argument_list; 54, 55; 55, string:"'vec2' is not a vector"; 56, if_statement; 56, 57; 56, 68; 57, comparison_operator:!=; 57, 58; 57, 63; 58, subscript; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:vec1; 61, identifier:shape; 62, integer:0; 63, subscript; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:vec2; 66, identifier:shape; 67, integer:0; 68, block; 68, 69; 69, raise_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:ValueError; 72, argument_list; 72, 73; 73, string:"Vector lengths are not equal"; 74, if_statement; 74, 75; 74, 85; 75, comparison_operator:<; 75, 76; 75, 82; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:spla; 79, identifier:norm; 80, argument_list; 80, 81; 81, identifier:vec1; 82, attribute; 82, 83; 82, 84; 83, identifier:PRM; 84, identifier:ZERO_VEC_TOL; 85, block; 85, 86; 86, raise_statement; 86, 87; 87, call; 87, 88; 87, 89; 88, identifier:ValueError; 89, argument_list; 89, 90; 90, string:"'vec1' norm is too small"; 91, if_statement; 91, 92; 91, 102; 92, comparison_operator:<; 92, 93; 92, 99; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:spla; 96, identifier:norm; 97, argument_list; 97, 98; 98, identifier:vec2; 99, attribute; 99, 100; 99, 101; 100, identifier:PRM; 101, identifier:ZERO_VEC_TOL; 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:"'vec2' norm is too small"; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:dotp; 111, binary_operator:/; 111, 112; 111, 126; 112, binary_operator:/; 112, 113; 112, 120; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:np; 116, identifier:dot; 117, argument_list; 117, 118; 117, 119; 118, identifier:vec1; 119, identifier:vec2; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:spla; 123, identifier:norm; 124, argument_list; 124, 125; 125, identifier:vec1; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:spla; 129, identifier:norm; 130, argument_list; 130, 131; 131, identifier:vec2; 132, if_statement; 132, 133; 132, 136; 132, 141; 132, 151; 133, comparison_operator:>; 133, 134; 133, 135; 134, identifier:dotp; 135, integer:1; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:angle; 140, float:0.; 141, elif_clause; 141, 142; 141, 146; 142, comparison_operator:<; 142, 143; 142, 144; 143, identifier:dotp; 144, unary_operator:-; 144, 145; 145, integer:1; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:angle; 150, float:180.; 151, else_clause; 151, 152; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:angle; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:np; 159, identifier:degrees; 160, argument_list; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:np; 164, identifier:arccos; 165, argument_list; 165, 166; 166, identifier:dotp; 167, return_statement; 167, 168; 168, identifier:angle
def vec_angle(vec1, vec2): import numpy as np from scipy import linalg as spla from ..const import PRM if len(vec1.shape) != 1: raise ValueError("'vec1' is not a vector") if len(vec2.shape) != 1: raise ValueError("'vec2' is not a vector") if vec1.shape[0] != vec2.shape[0]: raise ValueError("Vector lengths are not equal") if spla.norm(vec1) < PRM.ZERO_VEC_TOL: raise ValueError("'vec1' norm is too small") if spla.norm(vec2) < PRM.ZERO_VEC_TOL: raise ValueError("'vec2' norm is too small") dotp = np.dot(vec1, vec2) / spla.norm(vec1) / spla.norm(vec2) if dotp > 1: angle = 0. elif dotp < -1: angle = 180. else: angle = np.degrees(np.arccos(dotp)) return angle
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:ctr_mass; 3, parameters; 3, 4; 3, 5; 4, identifier:geom; 5, identifier:masses; 6, block; 6, 7; 6, 12; 6, 21; 6, 36; 6, 51; 6, 68; 6, 100; 6, 124; 6, 168; 7, import_statement; 7, 8; 8, aliased_import; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier:numpy; 11, identifier:np; 12, import_from_statement; 12, 13; 12, 17; 13, relative_import; 13, 14; 13, 15; 14, import_prefix; 15, dotted_name; 15, 16; 16, identifier:base; 17, aliased_import; 17, 18; 17, 20; 18, dotted_name; 18, 19; 19, identifier:safe_cast; 20, identifier:scast; 21, if_statement; 21, 22; 21, 30; 22, comparison_operator:!=; 22, 23; 22, 29; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, attribute; 26, 27; 26, 28; 27, identifier:geom; 28, identifier:shape; 29, integer:1; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:ValueError; 34, argument_list; 34, 35; 35, string:"Geometry is not a vector"; 36, if_statement; 36, 37; 36, 45; 37, comparison_operator:!=; 37, 38; 37, 44; 38, call; 38, 39; 38, 40; 39, identifier:len; 40, argument_list; 40, 41; 41, attribute; 41, 42; 41, 43; 42, identifier:masses; 43, identifier:shape; 44, integer:1; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:ValueError; 49, argument_list; 49, 50; 50, string:"Masses cannot be parsed as a vector"; 51, if_statement; 51, 52; 51, 62; 52, not_operator; 52, 53; 53, comparison_operator:==; 53, 54; 53, 61; 54, binary_operator:%; 54, 55; 54, 60; 55, subscript; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:geom; 58, identifier:shape; 59, integer:0; 60, integer:3; 61, integer:0; 62, block; 62, 63; 63, raise_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:ValueError; 66, argument_list; 66, 67; 67, string:"Geometry is not length-3N"; 68, if_statement; 68, 69; 68, 94; 69, boolean_operator:and; 69, 70; 69, 83; 70, comparison_operator:!=; 70, 71; 70, 76; 71, subscript; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:geom; 74, identifier:shape; 75, integer:0; 76, binary_operator:*; 76, 77; 76, 78; 77, integer:3; 78, subscript; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:masses; 81, identifier:shape; 82, integer:0; 83, comparison_operator:!=; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:geom; 87, identifier:shape; 88, integer:0; 89, subscript; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:masses; 92, identifier:shape; 93, integer:0; 94, block; 94, 95; 95, raise_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:ValueError; 98, argument_list; 98, 99; 99, string:"Inconsistent geometry and masses vector lengths"; 100, if_statement; 100, 101; 100, 114; 101, comparison_operator:==; 101, 102; 101, 107; 102, subscript; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:geom; 105, identifier:shape; 106, integer:0; 107, binary_operator:*; 107, 108; 107, 109; 108, integer:3; 109, subscript; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:masses; 112, identifier:shape; 113, integer:0; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:masses; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:masses; 121, identifier:repeat; 122, argument_list; 122, 123; 123, integer:3; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:ctr; 127, binary_operator:/; 127, 128; 127, 160; 128, call; 128, 129; 128, 159; 129, attribute; 129, 130; 129, 158; 130, call; 130, 131; 130, 154; 131, attribute; 131, 132; 131, 152; 131, 153; 132, call; 132, 133; 132, 142; 133, attribute; 133, 134; 133, 141; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:np; 137, identifier:multiply; 138, argument_list; 138, 139; 138, 140; 139, identifier:geom; 140, identifier:masses; 141, identifier:reshape; 142, argument_list; 142, 143; 143, tuple; 143, 144; 143, 151; 144, binary_operator://; 144, 145; 144, 150; 145, subscript; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:geom; 148, identifier:shape; 149, integer:0; 150, integer:3; 151, integer:3; 152, line_continuation:\; 153, identifier:sum; 154, argument_list; 154, 155; 155, keyword_argument; 155, 156; 155, 157; 156, identifier:axis; 157, integer:0; 158, identifier:squeeze; 159, argument_list; 160, parenthesized_expression; 160, 161; 161, binary_operator:/; 161, 162; 161, 167; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:masses; 165, identifier:sum; 166, argument_list; 167, integer:3; 168, return_statement; 168, 169; 169, identifier:ctr
def ctr_mass(geom, masses): import numpy as np from .base import safe_cast as scast if len(geom.shape) != 1: raise ValueError("Geometry is not a vector") if len(masses.shape) != 1: raise ValueError("Masses cannot be parsed as a vector") if not geom.shape[0] % 3 == 0: raise ValueError("Geometry is not length-3N") if geom.shape[0] != 3*masses.shape[0] and geom.shape[0] != masses.shape[0]: raise ValueError("Inconsistent geometry and masses vector lengths") if geom.shape[0] == 3*masses.shape[0]: masses = masses.repeat(3) ctr = np.multiply(geom, masses).reshape((geom.shape[0]//3, 3)) \ .sum(axis=0).squeeze() / (masses.sum() / 3) return ctr
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:inertia_tensor; 3, parameters; 3, 4; 3, 5; 4, identifier:geom; 5, identifier:masses; 6, block; 6, 7; 6, 12; 6, 20; 6, 44; 6, 55; 6, 247; 7, import_statement; 7, 8; 8, aliased_import; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier:numpy; 11, identifier:np; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:geom; 15, call; 15, 16; 15, 17; 16, identifier:ctr_geom; 17, argument_list; 17, 18; 17, 19; 18, identifier:geom; 19, identifier:masses; 20, if_statement; 20, 21; 20, 34; 21, comparison_operator:==; 21, 22; 21, 27; 22, subscript; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:geom; 25, identifier:shape; 26, integer:0; 27, binary_operator:*; 27, 28; 27, 29; 28, integer:3; 29, subscript; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:masses; 32, identifier:shape; 33, integer:0; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:masses; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:masses; 41, identifier:repeat; 42, argument_list; 42, 43; 43, integer:3; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:tensor; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:np; 50, identifier:zeros; 51, argument_list; 51, 52; 52, tuple; 52, 53; 52, 54; 53, integer:3; 54, integer:3; 55, for_statement; 55, 56; 55, 57; 55, 61; 56, identifier:i; 57, call; 57, 58; 57, 59; 58, identifier:range; 59, argument_list; 59, 60; 60, integer:3; 61, block; 61, 62; 62, for_statement; 62, 63; 62, 64; 62, 69; 63, identifier:j; 64, call; 64, 65; 64, 66; 65, identifier:range; 66, argument_list; 66, 67; 66, 68; 67, identifier:i; 68, integer:3; 69, block; 69, 70; 70, if_statement; 70, 71; 70, 74; 70, 150; 71, comparison_operator:==; 71, 72; 71, 73; 72, identifier:i; 73, identifier:j; 74, block; 74, 75; 74, 124; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:ind; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:np; 81, identifier:concatenate; 82, argument_list; 82, 83; 83, list_comprehension; 83, 84; 83, 112; 84, binary_operator:+; 84, 85; 84, 111; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:np; 88, identifier:array; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:list; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:map; 95, argument_list; 95, 96; 95, 102; 96, lambda; 96, 97; 96, 99; 97, lambda_parameters; 97, 98; 98, identifier:v; 99, binary_operator:%; 99, 100; 99, 101; 100, identifier:v; 101, integer:3; 102, call; 102, 103; 102, 104; 103, identifier:range; 104, argument_list; 104, 105; 104, 108; 105, binary_operator:+; 105, 106; 105, 107; 106, identifier:i; 107, integer:1; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:i; 110, integer:3; 111, identifier:o; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:o; 114, call; 114, 115; 114, 116; 115, identifier:range; 116, argument_list; 116, 117; 116, 118; 116, 123; 117, integer:0; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:geom; 121, identifier:shape; 122, integer:0; 123, integer:3; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 130; 126, subscript; 126, 127; 126, 128; 126, 129; 127, identifier:tensor; 128, identifier:i; 129, identifier:i; 130, call; 130, 131; 130, 149; 131, attribute; 131, 132; 131, 148; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:np; 135, identifier:multiply; 136, argument_list; 136, 137; 136, 145; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:np; 140, identifier:square; 141, argument_list; 141, 142; 142, subscript; 142, 143; 142, 144; 143, identifier:geom; 144, identifier:ind; 145, subscript; 145, 146; 145, 147; 146, identifier:masses; 147, identifier:ind; 148, identifier:sum; 149, argument_list; 150, else_clause; 150, 151; 151, block; 151, 152; 151, 172; 151, 192; 151, 237; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:ind_i; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:np; 158, identifier:array; 159, argument_list; 159, 160; 160, call; 160, 161; 160, 162; 161, identifier:range; 162, argument_list; 162, 163; 162, 164; 162, 171; 163, identifier:i; 164, binary_operator:+; 164, 165; 164, 170; 165, subscript; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:geom; 168, identifier:shape; 169, integer:0; 170, identifier:i; 171, integer:3; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:ind_j; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:np; 178, identifier:array; 179, argument_list; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:range; 182, argument_list; 182, 183; 182, 184; 182, 191; 183, identifier:j; 184, binary_operator:+; 184, 185; 184, 190; 185, subscript; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:geom; 188, identifier:shape; 189, integer:0; 190, identifier:j; 191, integer:3; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 198; 194, subscript; 194, 195; 194, 196; 194, 197; 195, identifier:tensor; 196, identifier:i; 197, identifier:j; 198, binary_operator:*; 198, 199; 198, 235; 199, call; 199, 200; 199, 234; 200, attribute; 200, 201; 200, 233; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:np; 204, identifier:multiply; 205, argument_list; 205, 206; 205, 222; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:np; 209, identifier:sqrt; 210, argument_list; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:np; 214, identifier:multiply; 215, argument_list; 215, 216; 215, 219; 216, subscript; 216, 217; 216, 218; 217, identifier:masses; 218, identifier:ind_i; 219, subscript; 219, 220; 219, 221; 220, identifier:masses; 221, identifier:ind_j; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:np; 225, identifier:multiply; 226, argument_list; 226, 227; 226, 230; 227, subscript; 227, 228; 227, 229; 228, identifier:geom; 229, identifier:ind_i; 230, subscript; 230, 231; 230, 232; 231, identifier:geom; 232, identifier:ind_j; 233, identifier:sum; 234, argument_list; 235, unary_operator:-; 235, 236; 236, integer:1; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 243; 239, subscript; 239, 240; 239, 241; 239, 242; 240, identifier:tensor; 241, identifier:j; 242, identifier:i; 243, subscript; 243, 244; 243, 245; 243, 246; 244, identifier:tensor; 245, identifier:i; 246, identifier:j; 247, return_statement; 247, 248; 248, identifier:tensor
def inertia_tensor(geom, masses): import numpy as np geom = ctr_geom(geom, masses) if geom.shape[0] == 3*masses.shape[0]: masses = masses.repeat(3) tensor = np.zeros((3,3)) for i in range(3): for j in range(i,3): if i == j: ind = np.concatenate([np.array(list(map(lambda v: v % 3, range(i+1, i+3)))) + o for o in range(0,geom.shape[0],3)]) tensor[i,i] = np.multiply(np.square(geom[ind]), masses[ind]).sum() else: ind_i = np.array(range(i,geom.shape[0]+i,3)) ind_j = np.array(range(j,geom.shape[0]+j,3)) tensor[i,j] = np.multiply( np.sqrt(np.multiply(masses[ind_i], masses[ind_j])) , np.multiply(geom[ind_i], geom[ind_j]) ).sum() * -1 tensor[j,i] = tensor[i,j] return tensor
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:rot_consts; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 11; 4, identifier:geom; 5, identifier:masses; 6, default_parameter; 6, 7; 6, 8; 7, identifier:units; 8, attribute; 8, 9; 8, 10; 9, identifier:_EURC; 10, identifier:INV_INERTIA; 11, default_parameter; 11, 12; 11, 13; 12, identifier:on_tol; 13, attribute; 13, 14; 13, 15; 14, identifier:_DEF; 15, identifier:ORTHONORM_TOL; 16, block; 16, 17; 16, 22; 16, 39; 16, 55; 16, 67; 16, 101; 16, 336; 17, import_statement; 17, 18; 18, aliased_import; 18, 19; 18, 21; 19, dotted_name; 19, 20; 20, identifier:numpy; 21, identifier:np; 22, import_from_statement; 22, 23; 22, 27; 22, 31; 22, 35; 22, 37; 23, relative_import; 23, 24; 23, 25; 24, import_prefix; 25, dotted_name; 25, 26; 26, identifier:const; 27, aliased_import; 27, 28; 27, 30; 28, dotted_name; 28, 29; 29, identifier:EnumTopType; 30, identifier:ETT; 31, aliased_import; 31, 32; 31, 34; 32, dotted_name; 32, 33; 33, identifier:EnumUnitsRotConst; 34, identifier:EURC; 35, dotted_name; 35, 36; 36, identifier:PRM; 37, dotted_name; 37, 38; 38, identifier:PHYS; 39, if_statement; 39, 40; 39, 44; 40, not_operator; 40, 41; 41, comparison_operator:in; 41, 42; 41, 43; 42, identifier:units; 43, identifier:EURC; 44, block; 44, 45; 45, raise_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:ValueError; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, string:"'{0}' is not a valid units value"; 52, identifier:format; 53, argument_list; 53, 54; 54, identifier:units; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 61; 57, pattern_list; 57, 58; 57, 59; 57, 60; 58, identifier:mom; 59, identifier:ax; 60, identifier:top; 61, call; 61, 62; 61, 63; 62, identifier:principals; 63, argument_list; 63, 64; 63, 65; 63, 66; 64, identifier:geom; 65, identifier:masses; 66, identifier:on_tol; 67, if_statement; 67, 68; 67, 73; 67, 86; 68, comparison_operator:==; 68, 69; 68, 70; 69, identifier:top; 70, attribute; 70, 71; 70, 72; 71, identifier:ETT; 72, identifier:ATOM; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:mom; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:np; 80, identifier:repeat; 81, argument_list; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:PRM; 84, identifier:ZERO_MOMENT_TOL; 85, integer:3; 86, elif_clause; 86, 87; 86, 92; 87, comparison_operator:==; 87, 88; 87, 89; 88, identifier:top; 89, attribute; 89, 90; 89, 91; 90, identifier:ETT; 91, identifier:LINEAR; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:mom; 97, integer:0; 98, attribute; 98, 99; 98, 100; 99, identifier:PRM; 100, identifier:ZERO_MOMENT_TOL; 101, if_statement; 101, 102; 101, 107; 101, 117; 101, 139; 101, 165; 101, 191; 101, 222; 101, 255; 101, 289; 101, 329; 102, comparison_operator:==; 102, 103; 102, 104; 103, identifier:units; 104, attribute; 104, 105; 104, 106; 105, identifier:EURC; 106, identifier:INV_INERTIA; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:rc; 111, binary_operator:/; 111, 112; 111, 113; 112, float:1.0; 113, parenthesized_expression; 113, 114; 114, binary_operator:*; 114, 115; 114, 116; 115, float:2.0; 116, identifier:mom; 117, elif_clause; 117, 118; 117, 123; 118, comparison_operator:==; 118, 119; 118, 120; 119, identifier:units; 120, attribute; 120, 121; 120, 122; 121, identifier:EURC; 122, identifier:ANGFREQ_ATOMIC; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:rc; 127, binary_operator:/; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:PHYS; 130, identifier:PLANCK_BAR; 131, parenthesized_expression; 131, 132; 132, binary_operator:*; 132, 133; 132, 136; 133, binary_operator:*; 133, 134; 133, 135; 134, float:2.0; 135, identifier:mom; 136, attribute; 136, 137; 136, 138; 137, identifier:PHYS; 138, identifier:ME_PER_AMU; 139, elif_clause; 139, 140; 139, 145; 140, comparison_operator:==; 140, 141; 140, 142; 141, identifier:units; 142, attribute; 142, 143; 142, 144; 143, identifier:EURC; 144, identifier:ANGFREQ_SECS; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:rc; 149, binary_operator:/; 149, 150; 149, 162; 150, binary_operator:/; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:PHYS; 153, identifier:PLANCK_BAR; 154, parenthesized_expression; 154, 155; 155, binary_operator:*; 155, 156; 155, 159; 156, binary_operator:*; 156, 157; 156, 158; 157, float:2.0; 158, identifier:mom; 159, attribute; 159, 160; 159, 161; 160, identifier:PHYS; 161, identifier:ME_PER_AMU; 162, attribute; 162, 163; 162, 164; 163, identifier:PHYS; 164, identifier:SEC_PER_TA; 165, elif_clause; 165, 166; 165, 171; 166, comparison_operator:==; 166, 167; 166, 168; 167, identifier:units; 168, attribute; 168, 169; 168, 170; 169, identifier:EURC; 170, identifier:CYCFREQ_ATOMIC; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:rc; 175, binary_operator:/; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:PHYS; 178, identifier:PLANCK_BAR; 179, parenthesized_expression; 179, 180; 180, binary_operator:*; 180, 181; 180, 188; 181, binary_operator:*; 181, 182; 181, 187; 182, binary_operator:*; 182, 183; 182, 184; 183, float:4.0; 184, attribute; 184, 185; 184, 186; 185, identifier:np; 186, identifier:pi; 187, identifier:mom; 188, attribute; 188, 189; 188, 190; 189, identifier:PHYS; 190, identifier:ME_PER_AMU; 191, elif_clause; 191, 192; 191, 197; 192, comparison_operator:==; 192, 193; 192, 194; 193, identifier:units; 194, attribute; 194, 195; 194, 196; 195, identifier:EURC; 196, identifier:CYCFREQ_HZ; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:rc; 201, binary_operator:/; 201, 202; 201, 218; 201, 219; 202, binary_operator:/; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:PHYS; 205, identifier:PLANCK_BAR; 206, parenthesized_expression; 206, 207; 207, binary_operator:*; 207, 208; 207, 215; 208, binary_operator:*; 208, 209; 208, 214; 209, binary_operator:*; 209, 210; 209, 211; 210, float:4.0; 211, attribute; 211, 212; 211, 213; 212, identifier:np; 213, identifier:pi; 214, identifier:mom; 215, attribute; 215, 216; 215, 217; 216, identifier:PHYS; 217, identifier:ME_PER_AMU; 218, line_continuation:\; 219, attribute; 219, 220; 219, 221; 220, identifier:PHYS; 221, identifier:SEC_PER_TA; 222, elif_clause; 222, 223; 222, 228; 223, comparison_operator:==; 223, 224; 223, 225; 224, identifier:units; 225, attribute; 225, 226; 225, 227; 226, identifier:EURC; 227, identifier:CYCFREQ_MHZ; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:rc; 232, binary_operator:/; 232, 233; 232, 254; 233, binary_operator:/; 233, 234; 233, 250; 233, 251; 234, binary_operator:/; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:PHYS; 237, identifier:PLANCK_BAR; 238, parenthesized_expression; 238, 239; 239, binary_operator:*; 239, 240; 239, 247; 240, binary_operator:*; 240, 241; 240, 246; 241, binary_operator:*; 241, 242; 241, 243; 242, float:4.0; 243, attribute; 243, 244; 243, 245; 244, identifier:np; 245, identifier:pi; 246, identifier:mom; 247, attribute; 247, 248; 247, 249; 248, identifier:PHYS; 249, identifier:ME_PER_AMU; 250, line_continuation:\; 251, attribute; 251, 252; 251, 253; 252, identifier:PHYS; 253, identifier:SEC_PER_TA; 254, float:1.0e6; 255, elif_clause; 255, 256; 255, 261; 256, comparison_operator:==; 256, 257; 256, 258; 257, identifier:units; 258, attribute; 258, 259; 258, 260; 259, identifier:EURC; 260, identifier:WAVENUM_ATOMIC; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:rc; 265, binary_operator:/; 265, 266; 265, 276; 265, 277; 266, binary_operator:/; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:PHYS; 269, identifier:PLANCK; 270, parenthesized_expression; 270, 271; 271, binary_operator:*; 271, 272; 271, 273; 272, identifier:mom; 273, attribute; 273, 274; 273, 275; 274, identifier:PHYS; 275, identifier:ME_PER_AMU; 276, line_continuation:\; 277, parenthesized_expression; 277, 278; 278, binary_operator:*; 278, 279; 278, 286; 279, binary_operator:*; 279, 280; 279, 281; 280, float:8.0; 281, binary_operator:**; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:np; 284, identifier:pi; 285, float:2.0; 286, attribute; 286, 287; 286, 288; 287, identifier:PHYS; 288, identifier:LIGHT_SPEED; 289, elif_clause; 289, 290; 289, 295; 290, comparison_operator:==; 290, 291; 290, 292; 291, identifier:units; 292, attribute; 292, 293; 292, 294; 293, identifier:EURC; 294, identifier:WAVENUM_CM; 295, block; 295, 296; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:rc; 299, binary_operator:*; 299, 300; 299, 328; 300, binary_operator:/; 300, 301; 300, 311; 300, 312; 301, binary_operator:/; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:PHYS; 304, identifier:PLANCK; 305, parenthesized_expression; 305, 306; 306, binary_operator:*; 306, 307; 306, 308; 307, identifier:mom; 308, attribute; 308, 309; 308, 310; 309, identifier:PHYS; 310, identifier:ME_PER_AMU; 311, line_continuation:\; 312, parenthesized_expression; 312, 313; 313, binary_operator:*; 313, 314; 313, 325; 314, binary_operator:*; 314, 315; 314, 322; 315, binary_operator:*; 315, 316; 315, 317; 316, float:8.0; 317, binary_operator:**; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:np; 320, identifier:pi; 321, float:2.0; 322, attribute; 322, 323; 322, 324; 323, identifier:PHYS; 324, identifier:LIGHT_SPEED; 325, attribute; 325, 326; 325, 327; 326, identifier:PHYS; 327, identifier:ANG_PER_BOHR; 328, float:1.0e8; 329, else_clause; 329, 330; 330, block; 330, 331; 331, raise_statement; 331, 332; 332, call; 332, 333; 332, 334; 333, identifier:NotImplementedError; 334, argument_list; 334, 335; 335, string:"Units conversion not yet implemented."; 336, return_statement; 336, 337; 337, identifier:rc
def rot_consts(geom, masses, units=_EURC.INV_INERTIA, on_tol=_DEF.ORTHONORM_TOL): import numpy as np from ..const import EnumTopType as ETT, EnumUnitsRotConst as EURC, PRM, PHYS if not units in EURC: raise ValueError("'{0}' is not a valid units value".format(units)) mom, ax, top = principals(geom, masses, on_tol) if top == ETT.ATOM: mom = np.repeat(PRM.ZERO_MOMENT_TOL, 3) elif top == ETT.LINEAR: mom[0] = PRM.ZERO_MOMENT_TOL if units == EURC.INV_INERTIA: rc = 1.0 / (2.0 * mom) elif units == EURC.ANGFREQ_ATOMIC: rc = PHYS.PLANCK_BAR / (2.0 * mom * PHYS.ME_PER_AMU) elif units == EURC.ANGFREQ_SECS: rc = PHYS.PLANCK_BAR / (2.0 * mom * PHYS.ME_PER_AMU) / PHYS.SEC_PER_TA elif units == EURC.CYCFREQ_ATOMIC: rc = PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) elif units == EURC.CYCFREQ_HZ: rc = PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) / \ PHYS.SEC_PER_TA elif units == EURC.CYCFREQ_MHZ: rc = PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) / \ PHYS.SEC_PER_TA / 1.0e6 elif units == EURC.WAVENUM_ATOMIC: rc = PHYS.PLANCK / (mom * PHYS.ME_PER_AMU) / \ (8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED) elif units == EURC.WAVENUM_CM: rc = PHYS.PLANCK / (mom * PHYS.ME_PER_AMU) / \ (8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED * PHYS.ANG_PER_BOHR) * 1.0e8 else: raise NotImplementedError("Units conversion not yet implemented.") return rc
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_fadn_orth; 3, parameters; 3, 4; 3, 5; 4, identifier:vec; 5, identifier:geom; 6, block; 6, 7; 6, 12; 6, 19; 6, 26; 6, 33; 6, 42; 6, 69; 6, 83; 6, 100; 6, 111; 7, import_statement; 7, 8; 8, aliased_import; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier:numpy; 11, identifier:np; 12, import_from_statement; 12, 13; 12, 15; 13, dotted_name; 13, 14; 14, identifier:scipy; 15, aliased_import; 15, 16; 15, 18; 16, dotted_name; 16, 17; 17, identifier:linalg; 18, identifier:spla; 19, import_from_statement; 19, 20; 19, 24; 20, relative_import; 20, 21; 20, 22; 21, import_prefix; 22, dotted_name; 22, 23; 23, identifier:const; 24, dotted_name; 24, 25; 25, identifier:PRM; 26, import_from_statement; 26, 27; 26, 31; 27, relative_import; 27, 28; 27, 29; 28, import_prefix; 29, dotted_name; 29, 30; 30, identifier:error; 31, dotted_name; 31, 32; 32, identifier:InertiaError; 33, import_from_statement; 33, 34; 33, 38; 34, relative_import; 34, 35; 34, 36; 35, import_prefix; 36, dotted_name; 36, 37; 37, identifier:vector; 38, aliased_import; 38, 39; 38, 41; 39, dotted_name; 39, 40; 40, identifier:orthonorm_check; 41, identifier:onchk; 42, if_statement; 42, 43; 42, 63; 43, not_operator; 43, 44; 44, parenthesized_expression; 44, 45; 45, boolean_operator:and; 45, 46; 45, 54; 46, comparison_operator:==; 46, 47; 46, 53; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:geom; 52, identifier:shape; 53, integer:1; 54, comparison_operator:==; 54, 55; 54, 62; 55, binary_operator:%; 55, 56; 55, 61; 56, subscript; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:geom; 59, identifier:shape; 60, integer:0; 61, integer:3; 62, integer:0; 63, block; 63, 64; 64, raise_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:ValueError; 67, argument_list; 67, 68; 68, string:"Geometry is not length 3N"; 69, if_statement; 69, 70; 69, 77; 70, not_operator; 70, 71; 71, comparison_operator:==; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:vec; 74, identifier:shape; 75, tuple; 75, 76; 76, integer:3; 77, block; 77, 78; 78, raise_statement; 78, 79; 79, call; 79, 80; 79, 81; 80, identifier:ValueError; 81, argument_list; 81, 82; 82, string:"Reference vector is not length 3"; 83, if_statement; 83, 84; 83, 94; 84, comparison_operator:<; 84, 85; 84, 91; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:spla; 88, identifier:norm; 89, argument_list; 89, 90; 90, identifier:vec; 91, attribute; 91, 92; 91, 93; 92, identifier:PRM; 93, identifier:ZERO_VEC_TOL; 94, block; 94, 95; 95, raise_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:ValueError; 98, argument_list; 98, 99; 99, string:"Reference vector norm is too small"; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:vec; 103, binary_operator:/; 103, 104; 103, 105; 104, identifier:vec; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:spla; 108, identifier:norm; 109, argument_list; 109, 110; 110, identifier:vec; 111, for_statement; 111, 112; 111, 113; 111, 127; 111, 182; 112, identifier:disp; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:geom; 116, identifier:reshape; 117, argument_list; 117, 118; 118, tuple; 118, 119; 118, 126; 119, binary_operator://; 119, 120; 119, 125; 120, subscript; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:geom; 123, identifier:shape; 124, integer:0; 125, integer:3; 126, integer:3; 127, block; 127, 128; 128, if_statement; 128, 129; 128, 168; 129, boolean_operator:and; 129, 130; 129, 140; 130, comparison_operator:>=; 130, 131; 130, 137; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:spla; 134, identifier:norm; 135, argument_list; 135, 136; 136, identifier:disp; 137, attribute; 137, 138; 137, 139; 138, identifier:PRM; 139, identifier:ZERO_VEC_TOL; 140, not_operator; 140, 141; 141, subscript; 141, 142; 141, 167; 142, call; 142, 143; 142, 144; 143, identifier:onchk; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:np; 148, identifier:column_stack; 149, argument_list; 149, 150; 150, tuple; 150, 151; 150, 159; 151, binary_operator:/; 151, 152; 151, 153; 152, identifier:disp; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:spla; 156, identifier:norm; 157, argument_list; 157, 158; 158, identifier:disp; 159, binary_operator:/; 159, 160; 159, 161; 160, identifier:vec; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:spla; 164, identifier:norm; 165, argument_list; 165, 166; 166, identifier:vec; 167, integer:0; 168, block; 168, 169; 168, 180; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:out_vec; 172, binary_operator:/; 172, 173; 172, 174; 173, identifier:disp; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:spla; 177, identifier:norm; 178, argument_list; 178, 179; 179, identifier:disp; 180, return_statement; 180, 181; 181, identifier:out_vec; 182, else_clause; 182, 183; 183, block; 183, 184; 184, raise_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:InertiaError; 187, argument_list; 187, 188; 187, 191; 187, 192; 188, attribute; 188, 189; 188, 190; 189, identifier:InertiaError; 190, identifier:BAD_GEOM; 191, string:"No suitable atomic displacement found"; 192, string:""
def _fadn_orth(vec, geom): import numpy as np from scipy import linalg as spla from ..const import PRM from ..error import InertiaError from .vector import orthonorm_check as onchk if not (len(geom.shape) == 1 and geom.shape[0] % 3 == 0): raise ValueError("Geometry is not length 3N") if not vec.shape == (3,): raise ValueError("Reference vector is not length 3") if spla.norm(vec) < PRM.ZERO_VEC_TOL: raise ValueError("Reference vector norm is too small") vec = vec / spla.norm(vec) for disp in geom.reshape((geom.shape[0]//3, 3)): if spla.norm(disp) >= PRM.ZERO_VEC_TOL and not onchk( np.column_stack((disp / spla.norm(disp), vec / spla.norm(vec))))[0]: out_vec = disp / spla.norm(disp) return out_vec else: raise InertiaError(InertiaError.BAD_GEOM, "No suitable atomic displacement found", "")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_fadn_par; 3, parameters; 3, 4; 3, 5; 4, identifier:vec; 5, identifier:geom; 6, block; 6, 7; 6, 12; 6, 19; 6, 26; 6, 33; 6, 42; 6, 69; 6, 83; 6, 100; 6, 111; 6, 176; 7, import_statement; 7, 8; 8, aliased_import; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier:numpy; 11, identifier:np; 12, import_from_statement; 12, 13; 12, 15; 13, dotted_name; 13, 14; 14, identifier:scipy; 15, aliased_import; 15, 16; 15, 18; 16, dotted_name; 16, 17; 17, identifier:linalg; 18, identifier:spla; 19, import_from_statement; 19, 20; 19, 24; 20, relative_import; 20, 21; 20, 22; 21, import_prefix; 22, dotted_name; 22, 23; 23, identifier:const; 24, dotted_name; 24, 25; 25, identifier:PRM; 26, import_from_statement; 26, 27; 26, 31; 27, relative_import; 27, 28; 27, 29; 28, import_prefix; 29, dotted_name; 29, 30; 30, identifier:error; 31, dotted_name; 31, 32; 32, identifier:InertiaError; 33, import_from_statement; 33, 34; 33, 38; 34, relative_import; 34, 35; 34, 36; 35, import_prefix; 36, dotted_name; 36, 37; 37, identifier:vector; 38, aliased_import; 38, 39; 38, 41; 39, dotted_name; 39, 40; 40, identifier:parallel_check; 41, identifier:parchk; 42, if_statement; 42, 43; 42, 63; 43, not_operator; 43, 44; 44, parenthesized_expression; 44, 45; 45, boolean_operator:and; 45, 46; 45, 54; 46, comparison_operator:==; 46, 47; 46, 53; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:geom; 52, identifier:shape; 53, integer:1; 54, comparison_operator:==; 54, 55; 54, 62; 55, binary_operator:%; 55, 56; 55, 61; 56, subscript; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:geom; 59, identifier:shape; 60, integer:0; 61, integer:3; 62, integer:0; 63, block; 63, 64; 64, raise_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:ValueError; 67, argument_list; 67, 68; 68, string:"Geometry is not length 3N"; 69, if_statement; 69, 70; 69, 77; 70, not_operator; 70, 71; 71, comparison_operator:==; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:vec; 74, identifier:shape; 75, tuple; 75, 76; 76, integer:3; 77, block; 77, 78; 78, raise_statement; 78, 79; 79, call; 79, 80; 79, 81; 80, identifier:ValueError; 81, argument_list; 81, 82; 82, string:"Reference vector is not length 3"; 83, if_statement; 83, 84; 83, 94; 84, comparison_operator:<; 84, 85; 84, 91; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:spla; 88, identifier:norm; 89, argument_list; 89, 90; 90, identifier:vec; 91, attribute; 91, 92; 91, 93; 92, identifier:PRM; 93, identifier:ZERO_VEC_TOL; 94, block; 94, 95; 95, raise_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:ValueError; 98, argument_list; 98, 99; 99, string:"Reference vector norm is too small"; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:vec; 103, binary_operator:/; 103, 104; 103, 105; 104, identifier:vec; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:spla; 108, identifier:norm; 109, argument_list; 109, 110; 110, identifier:vec; 111, for_statement; 111, 112; 111, 113; 111, 127; 111, 165; 112, identifier:disp; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:geom; 116, identifier:reshape; 117, argument_list; 117, 118; 118, tuple; 118, 119; 118, 126; 119, binary_operator://; 119, 120; 119, 125; 120, subscript; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:geom; 123, identifier:shape; 124, integer:0; 125, integer:3; 126, integer:3; 127, block; 127, 128; 128, if_statement; 128, 129; 128, 152; 129, boolean_operator:and; 129, 130; 129, 140; 129, 141; 130, comparison_operator:>=; 130, 131; 130, 137; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:spla; 134, identifier:norm; 135, argument_list; 135, 136; 136, identifier:disp; 137, attribute; 137, 138; 137, 139; 138, identifier:PRM; 139, identifier:ZERO_VEC_TOL; 140, line_continuation:\; 141, not_operator; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:parchk; 144, argument_list; 144, 145; 144, 151; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:disp; 148, identifier:reshape; 149, argument_list; 149, 150; 150, integer:3; 151, identifier:vec; 152, block; 152, 153; 152, 164; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:out_vec; 156, binary_operator:/; 156, 157; 156, 158; 157, identifier:disp; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:spla; 161, identifier:norm; 162, argument_list; 162, 163; 163, identifier:disp; 164, break_statement; 165, else_clause; 165, 166; 166, block; 166, 167; 167, raise_statement; 167, 168; 168, call; 168, 169; 168, 170; 169, identifier:InertiaError; 170, argument_list; 170, 171; 170, 174; 170, 175; 171, attribute; 171, 172; 171, 173; 172, identifier:InertiaError; 173, identifier:BAD_GEOM; 174, string:"Linear molecule, no non-parallel displacement"; 175, string:""; 176, return_statement; 176, 177; 177, identifier:out_vec
def _fadn_par(vec, geom): import numpy as np from scipy import linalg as spla from ..const import PRM from ..error import InertiaError from .vector import parallel_check as parchk if not (len(geom.shape) == 1 and geom.shape[0] % 3 == 0): raise ValueError("Geometry is not length 3N") if not vec.shape == (3,): raise ValueError("Reference vector is not length 3") if spla.norm(vec) < PRM.ZERO_VEC_TOL: raise ValueError("Reference vector norm is too small") vec = vec / spla.norm(vec) for disp in geom.reshape((geom.shape[0]//3, 3)): if spla.norm(disp) >= PRM.ZERO_VEC_TOL and \ not parchk(disp.reshape(3), vec): out_vec = disp / spla.norm(disp) break else: raise InertiaError(InertiaError.BAD_GEOM, "Linear molecule, no non-parallel displacement", "") return out_vec
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:reference_contexts_for_variants; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:variants; 5, identifier:context_size; 6, default_parameter; 6, 7; 6, 8; 7, identifier:transcript_id_whitelist; 8, None; 9, block; 9, 10; 9, 16; 9, 37; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:result; 13, call; 13, 14; 13, 15; 14, identifier:OrderedDict; 15, argument_list; 16, for_statement; 16, 17; 16, 18; 16, 19; 17, identifier:variant; 18, identifier:variants; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:result; 24, identifier:variant; 25, call; 25, 26; 25, 27; 26, identifier:reference_contexts_for_variant; 27, argument_list; 27, 28; 27, 31; 27, 34; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:variant; 30, identifier:variant; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:context_size; 33, identifier:context_size; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:transcript_id_whitelist; 36, identifier:transcript_id_whitelist; 37, return_statement; 37, 38; 38, identifier:result
def reference_contexts_for_variants( variants, context_size, transcript_id_whitelist=None): result = OrderedDict() for variant in variants: result[variant] = reference_contexts_for_variant( variant=variant, context_size=context_size, transcript_id_whitelist=transcript_id_whitelist) return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:pack_tups; 3, parameters; 3, 4; 4, list_splat_pattern; 4, 5; 5, identifier:args; 6, block; 6, 7; 6, 12; 6, 16; 6, 21; 6, 26; 6, 39; 6, 54; 6, 73; 6, 91; 6, 98; 6, 121; 6, 129; 6, 162; 6, 175; 7, import_statement; 7, 8; 8, aliased_import; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier:numpy; 11, identifier:np; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:_DEBUG; 15, False; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:NOT_ITER; 19, unary_operator:-; 19, 20; 20, integer:1; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:UNINIT_VAL; 24, unary_operator:-; 24, 25; 25, integer:1; 26, if_statement; 26, 27; 26, 28; 27, identifier:_DEBUG; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:print; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, string:"args = {0}"; 36, identifier:format; 37, argument_list; 37, 38; 38, identifier:args; 39, class_definition; 39, 40; 39, 41; 39, 43; 40, identifier:StrNoIter; 41, argument_list; 41, 42; 42, identifier:str; 43, block; 43, 44; 44, function_definition; 44, 45; 44, 46; 44, 48; 45, function_name:__iter__; 46, parameters; 46, 47; 47, identifier:self; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:NotImplementedError; 52, argument_list; 52, 53; 53, string:"Non-iterable string"; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:mod_args; 57, list_comprehension; 57, 58; 57, 70; 58, parenthesized_expression; 58, 59; 59, conditional_expression:if; 59, 60; 59, 64; 59, 69; 60, call; 60, 61; 60, 62; 61, identifier:StrNoIter; 62, argument_list; 62, 63; 63, identifier:a; 64, call; 64, 65; 64, 66; 65, identifier:isinstance; 66, argument_list; 66, 67; 66, 68; 67, identifier:a; 68, identifier:str; 69, identifier:a; 70, for_in_clause; 70, 71; 70, 72; 71, identifier:a; 72, identifier:args; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:iterlens; 76, list_comprehension; 76, 77; 76, 88; 77, parenthesized_expression; 77, 78; 78, conditional_expression:if; 78, 79; 78, 83; 78, 87; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, identifier:a; 83, call; 83, 84; 83, 85; 84, identifier:iterable; 85, argument_list; 85, 86; 86, identifier:a; 87, identifier:NOT_ITER; 88, for_in_clause; 88, 89; 88, 90; 89, identifier:a; 90, identifier:mod_args; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:maxiter; 94, call; 94, 95; 94, 96; 95, identifier:max; 96, argument_list; 96, 97; 97, identifier:iterlens; 98, if_statement; 98, 99; 98, 115; 99, not_operator; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:all; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:map; 105, argument_list; 105, 106; 105, 114; 106, lambda; 106, 107; 106, 109; 107, lambda_parameters; 107, 108; 108, identifier:v; 109, comparison_operator:in; 109, 110; 109, 111; 110, identifier:v; 111, tuple; 111, 112; 111, 113; 112, identifier:NOT_ITER; 113, identifier:maxiter; 114, identifier:iterlens; 115, block; 115, 116; 116, raise_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:ValueError; 119, argument_list; 119, 120; 120, string:"All iterable items must be of equal length"; 121, if_statement; 121, 122; 121, 125; 122, comparison_operator:==; 122, 123; 122, 124; 123, identifier:maxiter; 124, identifier:NOT_ITER; 125, block; 125, 126; 126, return_statement; 126, 127; 127, list:[args]; 127, 128; 128, identifier:args; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:tups; 132, call; 132, 133; 132, 134; 133, identifier:list; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:zip; 137, argument_list; 137, 138; 138, list_splat; 138, 139; 139, list_comprehension; 139, 140; 139, 153; 140, parenthesized_expression; 140, 141; 141, conditional_expression:if; 141, 142; 141, 149; 141, 152; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:np; 145, identifier:repeat; 146, argument_list; 146, 147; 146, 148; 147, identifier:a; 148, identifier:maxiter; 149, comparison_operator:==; 149, 150; 149, 151; 150, identifier:l; 151, identifier:NOT_ITER; 152, identifier:a; 153, for_in_clause; 153, 154; 153, 157; 154, tuple_pattern; 154, 155; 154, 156; 155, identifier:a; 156, identifier:l; 157, call; 157, 158; 157, 159; 158, identifier:zip; 159, argument_list; 159, 160; 159, 161; 160, identifier:mod_args; 161, identifier:iterlens; 162, if_statement; 162, 163; 162, 164; 163, identifier:_DEBUG; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:print; 168, argument_list; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, string:"tups = {0}"; 172, identifier:format; 173, argument_list; 173, 174; 174, identifier:tups; 175, return_statement; 175, 176; 176, identifier:tups
def pack_tups(*args): import numpy as np _DEBUG = False NOT_ITER = -1 UNINIT_VAL = -1 if _DEBUG: print("args = {0}".format(args)) class StrNoIter(str): def __iter__(self): raise NotImplementedError("Non-iterable string") mod_args = [(StrNoIter(a) if isinstance(a, str) else a) for a in args] iterlens = [(len(a) if iterable(a) else NOT_ITER) for a in mod_args] maxiter = max(iterlens) if not all(map(lambda v: v in (NOT_ITER, maxiter), iterlens)): raise ValueError("All iterable items must be of equal length") if maxiter == NOT_ITER: return [args] tups = list(zip(*[(np.repeat(a, maxiter) if l == NOT_ITER else a) for (a,l) in zip(mod_args, iterlens)])) if _DEBUG: print("tups = {0}".format(tups)) return tups
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:check_geom; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:c1; 5, identifier:a1; 6, identifier:c2; 7, identifier:a2; 8, default_parameter; 8, 9; 8, 10; 9, identifier:tol; 10, attribute; 10, 11; 10, 12; 11, identifier:_DEF; 12, identifier:XYZ_COORD_MATCH_TOL; 13, block; 13, 14; 13, 21; 13, 26; 13, 35; 13, 39; 13, 56; 13, 73; 13, 90; 13, 107; 13, 128; 13, 149; 13, 178; 13, 199; 13, 226; 13, 257; 13, 288; 13, 298; 13, 325; 14, import_from_statement; 14, 15; 14, 19; 15, relative_import; 15, 16; 15, 17; 16, import_prefix; 17, dotted_name; 17, 18; 18, identifier:const; 19, dotted_name; 19, 20; 20, identifier:atom_num; 21, import_statement; 21, 22; 22, aliased_import; 22, 23; 22, 25; 23, dotted_name; 23, 24; 24, identifier:numpy; 25, identifier:np; 26, import_from_statement; 26, 27; 26, 31; 27, relative_import; 27, 28; 27, 29; 28, import_prefix; 29, dotted_name; 29, 30; 30, identifier:const; 31, aliased_import; 31, 32; 31, 34; 32, dotted_name; 32, 33; 33, identifier:EnumCheckGeomMismatch; 34, identifier:ECGM; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:match; 38, True; 39, if_statement; 39, 40; 39, 49; 40, not_operator; 40, 41; 41, comparison_operator:==; 41, 42; 41, 48; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:c1; 47, identifier:shape; 48, integer:1; 49, block; 49, 50; 50, raise_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:ValueError; 53, argument_list; 53, 54; 54, parenthesized_expression; 54, 55; 55, string:"'c1' is not a vector."; 56, if_statement; 56, 57; 56, 66; 57, not_operator; 57, 58; 58, comparison_operator:==; 58, 59; 58, 65; 59, call; 59, 60; 59, 61; 60, identifier:len; 61, argument_list; 61, 62; 62, attribute; 62, 63; 62, 64; 63, identifier:c2; 64, identifier:shape; 65, integer:1; 66, block; 66, 67; 67, raise_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:ValueError; 70, argument_list; 70, 71; 71, parenthesized_expression; 71, 72; 72, string:"'c2' is not a vector."; 73, if_statement; 73, 74; 73, 83; 74, not_operator; 74, 75; 75, comparison_operator:==; 75, 76; 75, 82; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, attribute; 79, 80; 79, 81; 80, identifier:a1; 81, identifier:shape; 82, integer:1; 83, block; 83, 84; 84, raise_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:ValueError; 87, argument_list; 87, 88; 88, parenthesized_expression; 88, 89; 89, string:"'a1' is not a simple list."; 90, if_statement; 90, 91; 90, 100; 91, not_operator; 91, 92; 92, comparison_operator:==; 92, 93; 92, 99; 93, call; 93, 94; 93, 95; 94, identifier:len; 95, argument_list; 95, 96; 96, attribute; 96, 97; 96, 98; 97, identifier:a2; 98, identifier:shape; 99, integer:1; 100, block; 100, 101; 101, raise_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:ValueError; 104, argument_list; 104, 105; 105, parenthesized_expression; 105, 106; 106, string:"'a2' is not a simple list."; 107, if_statement; 107, 108; 107, 122; 108, not_operator; 108, 109; 109, comparison_operator:==; 109, 110; 109, 115; 110, subscript; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:c1; 113, identifier:shape; 114, integer:0; 115, binary_operator:*; 115, 116; 115, 117; 116, integer:3; 117, subscript; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:a1; 120, identifier:shape; 121, integer:0; 122, block; 122, 123; 123, raise_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:ValueError; 126, argument_list; 126, 127; 127, string:"len(c1) != 3*len(a1)"; 128, if_statement; 128, 129; 128, 143; 129, not_operator; 129, 130; 130, comparison_operator:==; 130, 131; 130, 136; 131, subscript; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:c2; 134, identifier:shape; 135, integer:0; 136, binary_operator:*; 136, 137; 136, 138; 137, integer:3; 138, subscript; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:a2; 141, identifier:shape; 142, integer:0; 143, block; 143, 144; 144, raise_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:ValueError; 147, argument_list; 147, 148; 148, string:"len(c2) != 3*len(a2)"; 149, if_statement; 149, 150; 149, 162; 150, not_operator; 150, 151; 151, comparison_operator:==; 151, 152; 151, 157; 152, subscript; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:c1; 155, identifier:shape; 156, integer:0; 157, subscript; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:c2; 160, identifier:shape; 161, integer:0; 162, block; 162, 163; 162, 167; 162, 173; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:match; 166, False; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:fail_type; 170, attribute; 170, 171; 170, 172; 171, identifier:ECGM; 172, identifier:DIMENSION; 173, return_statement; 173, 174; 174, expression_list; 174, 175; 174, 176; 174, 177; 175, identifier:match; 176, identifier:fail_type; 177, None; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:fail_loc; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:np; 184, identifier:less_equal; 185, argument_list; 185, 186; 185, 198; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:np; 189, identifier:abs; 190, argument_list; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:np; 194, identifier:subtract; 195, argument_list; 195, 196; 195, 197; 196, identifier:c1; 197, identifier:c2; 198, identifier:tol; 199, if_statement; 199, 200; 199, 210; 200, comparison_operator:!=; 200, 201; 200, 205; 201, call; 201, 202; 201, 203; 202, identifier:sum; 203, argument_list; 203, 204; 204, identifier:fail_loc; 205, subscript; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:c2; 208, identifier:shape; 209, integer:0; 210, block; 210, 211; 210, 215; 210, 221; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:match; 214, False; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:fail_type; 218, attribute; 218, 219; 218, 220; 219, identifier:ECGM; 220, identifier:COORDS; 221, return_statement; 221, 222; 222, expression_list; 222, 223; 222, 224; 222, 225; 223, identifier:match; 224, identifier:fail_type; 225, identifier:fail_loc; 226, if_statement; 226, 227; 226, 241; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:np; 230, identifier:issubdtype; 231, argument_list; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:a1; 234, identifier:dtype; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:np; 238, identifier:dtype; 239, argument_list; 239, 240; 240, string:'str'; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:a1; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:np; 248, identifier:array; 249, argument_list; 249, 250; 250, list_comprehension; 250, 251; 250, 254; 251, subscript; 251, 252; 251, 253; 252, identifier:atom_num; 253, identifier:e; 254, for_in_clause; 254, 255; 254, 256; 255, identifier:e; 256, identifier:a1; 257, if_statement; 257, 258; 257, 272; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:np; 261, identifier:issubdtype; 262, argument_list; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:a2; 265, identifier:dtype; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:np; 269, identifier:dtype; 270, argument_list; 270, 271; 271, string:'str'; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:a2; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:np; 279, identifier:array; 280, argument_list; 280, 281; 281, list_comprehension; 281, 282; 281, 285; 282, subscript; 282, 283; 282, 284; 283, identifier:atom_num; 284, identifier:e; 285, for_in_clause; 285, 286; 285, 287; 286, identifier:e; 287, identifier:a2; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:fail_loc; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:np; 294, identifier:equal; 295, argument_list; 295, 296; 295, 297; 296, identifier:a1; 297, identifier:a2; 298, if_statement; 298, 299; 298, 309; 299, comparison_operator:!=; 299, 300; 299, 304; 300, call; 300, 301; 300, 302; 301, identifier:sum; 302, argument_list; 302, 303; 303, identifier:fail_loc; 304, subscript; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:a2; 307, identifier:shape; 308, integer:0; 309, block; 309, 310; 309, 314; 309, 320; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:match; 313, False; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:fail_type; 317, attribute; 317, 318; 317, 319; 318, identifier:ECGM; 319, identifier:ATOMS; 320, return_statement; 320, 321; 321, expression_list; 321, 322; 321, 323; 321, 324; 322, identifier:match; 323, identifier:fail_type; 324, identifier:fail_loc; 325, return_statement; 325, 326; 326, expression_list; 326, 327; 326, 328; 326, 329; 327, identifier:match; 328, None; 329, None
def check_geom(c1, a1, c2, a2, tol=_DEF.XYZ_COORD_MATCH_TOL): from ..const import atom_num import numpy as np from ..const import EnumCheckGeomMismatch as ECGM match = True if not len(c1.shape) == 1: raise ValueError(("'c1' is not a vector.")) if not len(c2.shape) == 1: raise ValueError(("'c2' is not a vector.")) if not len(a1.shape) == 1: raise ValueError(("'a1' is not a simple list.")) if not len(a2.shape) == 1: raise ValueError(("'a2' is not a simple list.")) if not c1.shape[0] == 3 * a1.shape[0]: raise ValueError("len(c1) != 3*len(a1)") if not c2.shape[0] == 3 * a2.shape[0]: raise ValueError("len(c2) != 3*len(a2)") if not c1.shape[0] == c2.shape[0]: match = False fail_type = ECGM.DIMENSION return match, fail_type, None fail_loc = np.less_equal(np.abs(np.subtract(c1,c2)), tol) if sum(fail_loc) != c2.shape[0]: match = False fail_type = ECGM.COORDS return match, fail_type, fail_loc if np.issubdtype(a1.dtype, np.dtype('str')): a1 = np.array([atom_num[e] for e in a1]) if np.issubdtype(a2.dtype, np.dtype('str')): a2 = np.array([atom_num[e] for e in a2]) fail_loc = np.equal(a1, a2) if sum(fail_loc) != a2.shape[0]: match = False fail_type = ECGM.ATOMS return match, fail_type, fail_loc return match, None, None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:assert_npfloatarray; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:obj; 5, identifier:varname; 6, identifier:desc; 7, identifier:exc; 8, identifier:tc; 9, identifier:errsrc; 10, block; 10, 11; 10, 16; 10, 53; 10, 96; 11, import_statement; 11, 12; 12, aliased_import; 12, 13; 12, 15; 13, dotted_name; 13, 14; 14, identifier:numpy; 15, identifier:np; 16, if_statement; 16, 17; 16, 20; 16, 25; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:varname; 19, None; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:var; 24, identifier:obj; 25, else_clause; 25, 26; 26, block; 26, 27; 27, try_statement; 27, 28; 27, 37; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:var; 32, call; 32, 33; 32, 34; 33, identifier:getattr; 34, argument_list; 34, 35; 34, 36; 35, identifier:obj; 36, identifier:varname; 37, except_clause; 37, 38; 37, 39; 38, identifier:AttributeError; 39, block; 39, 40; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:exc; 43, argument_list; 43, 44; 43, 45; 43, 52; 44, identifier:tc; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, string:"Attribute '{0}' not defined in '{1}'"; 48, identifier:format; 49, argument_list; 49, 50; 49, 51; 50, identifier:varname; 51, identifier:obj; 52, identifier:errsrc; 53, try_statement; 53, 54; 53, 61; 53, 76; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:dt; 58, attribute; 58, 59; 58, 60; 59, identifier:var; 60, identifier:dtype; 61, except_clause; 61, 62; 61, 63; 62, identifier:AttributeError; 63, block; 63, 64; 64, raise_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:exc; 67, argument_list; 67, 68; 67, 69; 67, 75; 68, identifier:tc; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:"'{0}' is not an np.array (lacks a 'dtype' member)"; 72, identifier:format; 73, argument_list; 73, 74; 74, identifier:desc; 75, identifier:errsrc; 76, else_clause; 76, 77; 77, block; 77, 78; 78, if_statement; 78, 79; 78, 83; 79, not_operator; 79, 80; 80, attribute; 80, 81; 80, 82; 81, identifier:var; 82, identifier:shape; 83, block; 83, 84; 84, raise_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:exc; 87, argument_list; 87, 88; 87, 89; 87, 95; 88, identifier:tc; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, string:"'{0}' is not an np.array ('len(shape)' < 1)"; 92, identifier:format; 93, argument_list; 93, 94; 94, identifier:desc; 95, identifier:errsrc; 96, if_statement; 96, 97; 96, 107; 97, not_operator; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:np; 101, identifier:issubdtype; 102, argument_list; 102, 103; 102, 104; 103, identifier:dt; 104, attribute; 104, 105; 104, 106; 105, identifier:np; 106, identifier:float; 107, block; 107, 108; 108, raise_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:exc; 111, argument_list; 111, 112; 111, 113; 111, 119; 112, identifier:tc; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, string:"'{0}' is not an np.array of np.float"; 116, identifier:format; 117, argument_list; 117, 118; 118, identifier:desc; 119, identifier:errsrc
def assert_npfloatarray(obj, varname, desc, exc, tc, errsrc): import numpy as np if varname is None: var = obj else: try: var = getattr(obj, varname) except AttributeError: raise exc(tc, "Attribute '{0}' not defined in '{1}'" .format(varname, obj), errsrc) try: dt = var.dtype except AttributeError: raise exc(tc, "'{0}' is not an np.array (lacks a 'dtype' member)" .format(desc), errsrc) else: if not var.shape: raise exc(tc, "'{0}' is not an np.array ('len(shape)' < 1)" .format(desc), errsrc) if not np.issubdtype(dt, np.float): raise exc(tc, "'{0}' is not an np.array of np.float".format(desc), errsrc)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_advance_pattern_generators; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:p; 6, block; 6, 7; 6, 11; 6, 80; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:valid_generators; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 16; 12, identifier:g; 13, attribute; 13, 14; 13, 15; 14, identifier:p; 15, identifier:generators; 16, block; 16, 17; 17, for_statement; 17, 18; 17, 19; 17, 25; 17, 67; 18, identifier:trial; 19, call; 19, 20; 19, 21; 20, identifier:range; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:max_trials; 25, block; 25, 26; 25, 53; 25, 60; 26, if_statement; 26, 27; 26, 44; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:np; 30, identifier:alltrue; 31, argument_list; 31, 32; 32, list_comprehension; 32, 33; 32, 41; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:__distance_valid; 37, argument_list; 37, 38; 37, 39; 37, 40; 38, identifier:g; 39, identifier:v; 40, identifier:p; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:v; 43, identifier:valid_generators; 44, block; 44, 45; 44, 52; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:valid_generators; 49, identifier:append; 50, argument_list; 50, 51; 51, identifier:g; 52, break_statement; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:g; 57, identifier:force_new_dynamic_value; 58, argument_list; 58, 59; 59, string:'x'; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:g; 64, identifier:force_new_dynamic_value; 65, argument_list; 65, 66; 66, string:'y'; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:warning; 74, argument_list; 74, 75; 75, binary_operator:%; 75, 76; 75, 77; 76, string:"Unable to place pattern %s subject to given constraints"; 77, attribute; 77, 78; 77, 79; 78, identifier:g; 79, identifier:name; 80, return_statement; 80, 81; 81, identifier:valid_generators
def _advance_pattern_generators(self,p): valid_generators = [] for g in p.generators: for trial in range(self.max_trials): if np.alltrue([self.__distance_valid(g,v,p) for v in valid_generators]): valid_generators.append(g) break g.force_new_dynamic_value('x') g.force_new_dynamic_value('y') else: self.warning("Unable to place pattern %s subject to given constraints" % g.name) return valid_generators
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:register; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 10; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:settings_class; 7, identifier:NoSwitcher; 8, list_splat_pattern; 8, 9; 9, identifier:simple_checks; 10, dictionary_splat_pattern; 10, 11; 11, identifier:conditions; 12, block; 12, 13; 12, 38; 12, 48; 12, 68; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:settings_class; 16, identifier:NoSwitcher; 17, block; 17, 18; 17, 36; 18, function_definition; 18, 19; 18, 20; 18, 22; 19, function_name:decorator; 20, parameters; 20, 21; 21, identifier:cls; 22, block; 22, 23; 22, 34; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:register; 28, argument_list; 28, 29; 28, 30; 28, 32; 29, identifier:cls; 30, list_splat; 30, 31; 31, identifier:simple_checks; 32, dictionary_splat; 32, 33; 33, identifier:conditions; 34, return_statement; 34, 35; 35, identifier:cls; 36, return_statement; 36, 37; 37, identifier:decorator; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:available_checks; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:checks; 46, identifier:keys; 47, argument_list; 48, for_statement; 48, 49; 48, 50; 48, 55; 49, identifier:condition; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:conditions; 53, identifier:keys; 54, argument_list; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 60; 57, comparison_operator:not; 57, 58; 57, 59; 58, identifier:condition; 59, identifier:available_checks; 60, block; 60, 61; 61, raise_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:InvalidCondition; 64, argument_list; 64, 65; 65, binary_operator:%; 65, 66; 65, 67; 66, string:'There is no check for the condition "%s"'; 67, identifier:condition; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_registry; 74, identifier:append; 75, argument_list; 75, 76; 76, tuple; 76, 77; 76, 78; 76, 79; 77, identifier:settings_class; 78, identifier:simple_checks; 79, identifier:conditions
def register(self, settings_class=NoSwitcher, *simple_checks, **conditions): if settings_class is NoSwitcher: def decorator(cls): self.register(cls, *simple_checks, **conditions) return cls return decorator available_checks = self.checks.keys() for condition in conditions.keys(): if condition not in available_checks: raise InvalidCondition( 'There is no check for the condition "%s"' % condition) self._registry.append((settings_class, simple_checks, conditions))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_load_data; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:atom_syms; 6, identifier:coords; 7, default_parameter; 7, 8; 7, 9; 8, identifier:bohrs; 9, True; 10, block; 10, 11; 10, 16; 10, 25; 10, 32; 10, 49; 10, 65; 10, 81; 10, 102; 10, 167; 10, 185; 10, 195; 10, 201; 10, 209; 10, 223; 10, 231; 10, 249; 11, import_statement; 11, 12; 12, aliased_import; 12, 13; 12, 15; 13, dotted_name; 13, 14; 14, identifier:numpy; 15, identifier:np; 16, import_from_statement; 16, 17; 16, 21; 16, 23; 17, relative_import; 17, 18; 17, 19; 18, import_prefix; 19, dotted_name; 19, 20; 20, identifier:const; 21, dotted_name; 21, 22; 22, identifier:atom_num; 23, dotted_name; 23, 24; 24, identifier:PHYS; 25, import_from_statement; 25, 26; 25, 30; 26, relative_import; 26, 27; 26, 28; 27, import_prefix; 28, dotted_name; 28, 29; 29, identifier:error; 30, dotted_name; 30, 31; 31, identifier:XYZError; 32, if_statement; 32, 33; 32, 39; 33, comparison_operator:in; 33, 34; 33, 35; 34, string:'geoms'; 35, call; 35, 36; 35, 37; 36, identifier:dir; 37, argument_list; 37, 38; 38, identifier:self; 39, block; 39, 40; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:XYZError; 43, argument_list; 43, 44; 43, 47; 43, 48; 44, attribute; 44, 45; 44, 46; 45, identifier:XYZError; 46, identifier:OVERWRITE; 47, string:"Cannot overwrite contents of existing OpanXYZ"; 48, string:""; 49, if_statement; 49, 50; 49, 59; 50, not_operator; 50, 51; 51, comparison_operator:==; 51, 52; 51, 58; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:coords; 57, identifier:shape; 58, integer:1; 59, block; 59, 60; 60, raise_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:ValueError; 63, argument_list; 63, 64; 64, string:"Coordinates are not a vector"; 65, if_statement; 65, 66; 65, 75; 66, not_operator; 66, 67; 67, comparison_operator:==; 67, 68; 67, 74; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, attribute; 71, 72; 71, 73; 72, identifier:atom_syms; 73, identifier:shape; 74, integer:1; 75, block; 75, 76; 76, raise_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:ValueError; 79, argument_list; 79, 80; 80, string:"Atom symbols are not a simple list"; 81, if_statement; 81, 82; 81, 96; 82, not_operator; 82, 83; 83, comparison_operator:==; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:coords; 87, identifier:shape; 88, integer:0; 89, binary_operator:*; 89, 90; 89, 91; 90, integer:3; 91, subscript; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:atom_syms; 94, identifier:shape; 95, integer:0; 96, block; 96, 97; 97, raise_statement; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:ValueError; 100, argument_list; 100, 101; 101, string:"len(coords) != 3 * len(atom_syms)"; 102, if_statement; 102, 103; 102, 127; 103, not_operator; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:all; 106, generator_expression; 106, 107; 106, 117; 107, parenthesized_expression; 107, 108; 108, comparison_operator:in; 108, 109; 108, 116; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:atom_syms; 113, identifier:i; 114, identifier:upper; 115, argument_list; 116, identifier:atom_num; 117, for_in_clause; 117, 118; 117, 119; 118, identifier:i; 119, call; 119, 120; 119, 121; 120, identifier:range; 121, argument_list; 121, 122; 122, subscript; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:atom_syms; 125, identifier:shape; 126, integer:0; 127, block; 127, 128; 128, raise_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:ValueError; 131, argument_list; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, string:"Invalid atoms specified: {0}"; 135, identifier:format; 136, argument_list; 136, 137; 137, list_comprehension; 137, 138; 137, 143; 138, tuple; 138, 139; 138, 140; 139, identifier:j; 140, subscript; 140, 141; 140, 142; 141, identifier:atom_syms; 142, identifier:j; 143, for_in_clause; 143, 144; 143, 145; 144, identifier:j; 145, generator_expression; 145, 146; 145, 147; 145, 164; 146, identifier:i; 147, for_in_clause; 147, 148; 147, 151; 148, tuple_pattern; 148, 149; 148, 150; 149, identifier:i; 150, identifier:valid; 151, call; 151, 152; 151, 153; 152, identifier:enumerate; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:map; 156, argument_list; 156, 157; 156, 163; 157, lambda; 157, 158; 157, 160; 158, lambda_parameters; 158, 159; 159, identifier:k; 160, comparison_operator:in; 160, 161; 160, 162; 161, identifier:k; 162, identifier:atom_num; 163, identifier:atom_syms; 164, if_clause; 164, 165; 165, not_operator; 165, 166; 166, identifier:valid; 167, if_statement; 167, 168; 167, 179; 168, not_operator; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:all; 171, argument_list; 171, 172; 172, call; 172, 173; 172, 174; 173, identifier:map; 174, argument_list; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:np; 177, identifier:isreal; 178, identifier:coords; 179, block; 179, 180; 180, raise_statement; 180, 181; 181, call; 181, 182; 181, 183; 182, identifier:ValueError; 183, argument_list; 183, 184; 184, string:"All coordinates must be real numeric"; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:num_atoms; 190, subscript; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:atom_syms; 193, identifier:shape; 194, integer:0; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:num_geoms; 200, integer:1; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:in_str; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:LOAD_DATA_FLAG; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:descs; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:np; 217, identifier:array; 218, argument_list; 218, 219; 219, list:[self.LOAD_DATA_FLAG]; 219, 220; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:LOAD_DATA_FLAG; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:XYZ_path; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:LOAD_DATA_FLAG; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:atom_syms; 236, call; 236, 237; 236, 238; 237, identifier:list; 238, argument_list; 238, 239; 239, call; 239, 240; 239, 241; 240, identifier:map; 241, argument_list; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:str; 244, identifier:upper; 245, call; 245, 246; 245, 247; 246, identifier:list; 247, argument_list; 247, 248; 248, identifier:atom_syms; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:geoms; 254, list:[coords / (1.0 if bohrs else PHYS.ANG_PER_BOHR)]; 254, 255; 255, binary_operator:/; 255, 256; 255, 257; 256, identifier:coords; 257, parenthesized_expression; 257, 258; 258, conditional_expression:if; 258, 259; 258, 260; 258, 261; 259, float:1.0; 260, identifier:bohrs; 261, attribute; 261, 262; 261, 263; 262, identifier:PHYS; 263, identifier:ANG_PER_BOHR
def _load_data(self, atom_syms, coords, bohrs=True): import numpy as np from .const import atom_num, PHYS from .error import XYZError if 'geoms' in dir(self): raise XYZError(XYZError.OVERWRITE, "Cannot overwrite contents of existing OpanXYZ", "") if not len(coords.shape) == 1: raise ValueError("Coordinates are not a vector") if not len(atom_syms.shape) == 1: raise ValueError("Atom symbols are not a simple list") if not coords.shape[0] == 3 * atom_syms.shape[0]: raise ValueError("len(coords) != 3 * len(atom_syms)") if not all( (atom_syms[i].upper() in atom_num) for i in range(atom_syms.shape[0]) ): raise ValueError("Invalid atoms specified: {0}".format( [(j, atom_syms[j]) for j in (i for (i, valid) in enumerate(map(lambda k: k in atom_num, atom_syms)) if not valid ) ] )) if not all(map(np.isreal, coords)): raise ValueError("All coordinates must be real numeric") self.num_atoms = atom_syms.shape[0] self.num_geoms = 1 self.in_str = self.LOAD_DATA_FLAG self.descs = np.array([self.LOAD_DATA_FLAG]) self.XYZ_path = self.LOAD_DATA_FLAG self.atom_syms = list(map(str.upper, list(atom_syms))) self.geoms = [coords / (1.0 if bohrs else PHYS.ANG_PER_BOHR)]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:dist_single; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:g_num; 6, identifier:at_1; 7, identifier:at_2; 8, block; 8, 9; 8, 14; 8, 21; 8, 30; 8, 53; 8, 76; 8, 91; 8, 106; 8, 139; 9, import_statement; 9, 10; 10, aliased_import; 10, 11; 10, 13; 11, dotted_name; 11, 12; 12, identifier:numpy; 13, identifier:np; 14, import_from_statement; 14, 15; 14, 17; 15, dotted_name; 15, 16; 16, identifier:scipy; 17, aliased_import; 17, 18; 17, 20; 18, dotted_name; 18, 19; 19, identifier:linalg; 20, identifier:spla; 21, import_from_statement; 21, 22; 21, 26; 22, relative_import; 22, 23; 22, 24; 23, import_prefix; 24, dotted_name; 24, 25; 25, identifier:utils; 26, aliased_import; 26, 27; 26, 29; 27, dotted_name; 27, 28; 28, identifier:safe_cast; 29, identifier:scast; 30, if_statement; 30, 31; 30, 42; 31, not_operator; 31, 32; 32, parenthesized_expression; 32, 33; 33, comparison_operator:<=; 33, 34; 33, 38; 33, 39; 34, unary_operator:-; 34, 35; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:num_atoms; 38, identifier:at_1; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:num_atoms; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:IndexError; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, string:"Invalid index for 'at_1' ({0})"; 50, identifier:format; 51, argument_list; 51, 52; 52, identifier:at_1; 53, if_statement; 53, 54; 53, 65; 54, not_operator; 54, 55; 55, parenthesized_expression; 55, 56; 56, comparison_operator:<=; 56, 57; 56, 61; 56, 62; 57, unary_operator:-; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:num_atoms; 61, identifier:at_2; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:num_atoms; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:IndexError; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:"Invalid index for 'at_2' ({0})"; 73, identifier:format; 74, argument_list; 74, 75; 75, identifier:at_2; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:at_1; 79, call; 79, 80; 79, 81; 80, identifier:scast; 81, argument_list; 81, 82; 81, 88; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:np; 85, identifier:floor; 86, argument_list; 86, 87; 87, identifier:at_1; 88, attribute; 88, 89; 88, 90; 89, identifier:np; 90, identifier:int_; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:at_2; 94, call; 94, 95; 94, 96; 95, identifier:scast; 96, argument_list; 96, 97; 96, 103; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:np; 100, identifier:floor; 101, argument_list; 101, 102; 102, identifier:at_2; 103, attribute; 103, 104; 103, 105; 104, identifier:np; 105, identifier:int_; 106, if_statement; 106, 107; 106, 110; 106, 115; 107, comparison_operator:==; 107, 108; 107, 109; 108, identifier:at_1; 109, identifier:at_2; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:dist; 114, float:0.0; 115, else_clause; 115, 116; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:dist; 120, call; 120, 121; 120, 122; 121, identifier:scast; 122, argument_list; 122, 123; 122, 136; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:spla; 126, identifier:norm; 127, argument_list; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:displ_single; 132, argument_list; 132, 133; 132, 134; 132, 135; 133, identifier:g_num; 134, identifier:at_1; 135, identifier:at_2; 136, attribute; 136, 137; 136, 138; 137, identifier:np; 138, identifier:float_; 139, return_statement; 139, 140; 140, identifier:dist
def dist_single(self, g_num, at_1, at_2): import numpy as np from scipy import linalg as spla from .utils import safe_cast as scast if not (-self.num_atoms <= at_1 < self.num_atoms): raise IndexError("Invalid index for 'at_1' ({0})".format(at_1)) if not (-self.num_atoms <= at_2 < self.num_atoms): raise IndexError("Invalid index for 'at_2' ({0})".format(at_2)) at_1 = scast(np.floor(at_1), np.int_) at_2 = scast(np.floor(at_2), np.int_) if at_1 == at_2: dist = 0.0 else: dist = scast( spla.norm(self.displ_single(g_num, at_1, at_2)), np.float_) return dist
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:dist_iter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:g_nums; 6, identifier:ats_1; 7, identifier:ats_2; 8, default_parameter; 8, 9; 8, 10; 9, identifier:invalid_error; 10, False; 11, block; 11, 12; 11, 17; 11, 24; 11, 57; 11, 68; 11, 76; 11, 84; 12, import_statement; 12, 13; 13, aliased_import; 13, 14; 13, 16; 14, dotted_name; 14, 15; 15, identifier:numpy; 16, identifier:np; 17, import_from_statement; 17, 18; 17, 22; 18, relative_import; 18, 19; 18, 20; 19, import_prefix; 20, dotted_name; 20, 21; 21, identifier:utils; 22, dotted_name; 22, 23; 23, identifier:pack_tups; 24, if_statement; 24, 25; 24, 26; 25, identifier:_DEBUG; 26, block; 26, 27; 26, 37; 26, 47; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:print; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, string:"g_nums = {0}"; 34, identifier:format; 35, argument_list; 35, 36; 36, identifier:g_nums; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:print; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, string:"ats_1 = {0}"; 44, identifier:format; 45, argument_list; 45, 46; 46, identifier:ats_1; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:print; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, string:"ats_2 = {0}"; 54, identifier:format; 55, argument_list; 55, 56; 56, identifier:ats_2; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:arglist; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:_none_subst; 64, argument_list; 64, 65; 64, 66; 64, 67; 65, identifier:g_nums; 66, identifier:ats_1; 67, identifier:ats_2; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:tups; 71, call; 71, 72; 71, 73; 72, identifier:pack_tups; 73, argument_list; 73, 74; 74, list_splat; 74, 75; 75, identifier:arglist; 76, if_statement; 76, 77; 76, 78; 77, identifier:_DEBUG; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:print; 82, argument_list; 82, 83; 83, identifier:tups; 84, for_statement; 84, 85; 84, 86; 84, 87; 85, identifier:tup; 86, identifier:tups; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, yield; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:_iter_return; 94, argument_list; 94, 95; 94, 96; 94, 99; 95, identifier:tup; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:dist_single; 99, identifier:invalid_error
def dist_iter(self, g_nums, ats_1, ats_2, invalid_error=False): import numpy as np from .utils import pack_tups if _DEBUG: print("g_nums = {0}".format(g_nums)) print("ats_1 = {0}".format(ats_1)) print("ats_2 = {0}".format(ats_2)) arglist = self._none_subst(g_nums, ats_1, ats_2) tups = pack_tups(*arglist) if _DEBUG: print(tups) for tup in tups: yield self._iter_return(tup, self.dist_single, invalid_error)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:angle_single; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:g_num; 6, identifier:at_1; 7, identifier:at_2; 8, identifier:at_3; 9, block; 9, 10; 9, 15; 9, 24; 9, 32; 9, 55; 9, 78; 9, 101; 9, 116; 9, 131; 9, 146; 9, 166; 9, 186; 9, 203; 9, 214; 9, 225; 9, 233; 10, import_statement; 10, 11; 11, aliased_import; 11, 12; 11, 14; 12, dotted_name; 12, 13; 13, identifier:numpy; 14, identifier:np; 15, import_from_statement; 15, 16; 15, 20; 16, relative_import; 16, 17; 16, 18; 17, import_prefix; 18, dotted_name; 18, 19; 19, identifier:utils; 20, aliased_import; 20, 21; 20, 23; 21, dotted_name; 21, 22; 22, identifier:safe_cast; 23, identifier:scast; 24, import_from_statement; 24, 25; 24, 30; 25, relative_import; 25, 26; 25, 27; 26, import_prefix; 27, dotted_name; 27, 28; 27, 29; 28, identifier:utils; 29, identifier:vector; 30, dotted_name; 30, 31; 31, identifier:vec_angle; 32, if_statement; 32, 33; 32, 44; 33, not_operator; 33, 34; 34, parenthesized_expression; 34, 35; 35, comparison_operator:<=; 35, 36; 35, 40; 35, 41; 36, unary_operator:-; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:num_atoms; 40, identifier:at_1; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:num_atoms; 44, block; 44, 45; 45, raise_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:IndexError; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, string:"Invalid index for 'at_1' ({0})"; 52, identifier:format; 53, argument_list; 53, 54; 54, identifier:at_1; 55, if_statement; 55, 56; 55, 67; 56, not_operator; 56, 57; 57, parenthesized_expression; 57, 58; 58, comparison_operator:<=; 58, 59; 58, 63; 58, 64; 59, unary_operator:-; 59, 60; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:num_atoms; 63, identifier:at_2; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:num_atoms; 67, block; 67, 68; 68, raise_statement; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:IndexError; 71, argument_list; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, string:"Invalid index for 'at_2' ({0})"; 75, identifier:format; 76, argument_list; 76, 77; 77, identifier:at_2; 78, if_statement; 78, 79; 78, 90; 79, not_operator; 79, 80; 80, parenthesized_expression; 80, 81; 81, comparison_operator:<=; 81, 82; 81, 86; 81, 87; 82, unary_operator:-; 82, 83; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:num_atoms; 86, identifier:at_3; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:num_atoms; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:IndexError; 94, argument_list; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, string:"Invalid index for 'at_3' ({0})"; 98, identifier:format; 99, argument_list; 99, 100; 100, identifier:at_3; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:at_1; 104, call; 104, 105; 104, 106; 105, identifier:scast; 106, argument_list; 106, 107; 106, 113; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:np; 110, identifier:floor; 111, argument_list; 111, 112; 112, identifier:at_1; 113, attribute; 113, 114; 113, 115; 114, identifier:np; 115, identifier:int_; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:at_2; 119, call; 119, 120; 119, 121; 120, identifier:scast; 121, argument_list; 121, 122; 121, 128; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:np; 125, identifier:floor; 126, argument_list; 126, 127; 127, identifier:at_2; 128, attribute; 128, 129; 128, 130; 129, identifier:np; 130, identifier:int_; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:at_3; 134, call; 134, 135; 134, 136; 135, identifier:scast; 136, argument_list; 136, 137; 136, 143; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:np; 140, identifier:floor; 141, argument_list; 141, 142; 142, identifier:at_3; 143, attribute; 143, 144; 143, 145; 144, identifier:np; 145, identifier:int_; 146, if_statement; 146, 147; 146, 160; 147, comparison_operator:==; 147, 148; 147, 154; 148, parenthesized_expression; 148, 149; 149, binary_operator:%; 149, 150; 149, 151; 150, identifier:at_2; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:num_atoms; 154, parenthesized_expression; 154, 155; 155, binary_operator:%; 155, 156; 155, 157; 156, identifier:at_1; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:num_atoms; 160, block; 160, 161; 161, raise_statement; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:ValueError; 164, argument_list; 164, 165; 165, string:"'at_1' and 'at_2' must be different"; 166, if_statement; 166, 167; 166, 180; 167, comparison_operator:==; 167, 168; 167, 174; 168, parenthesized_expression; 168, 169; 169, binary_operator:%; 169, 170; 169, 171; 170, identifier:at_2; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:num_atoms; 174, parenthesized_expression; 174, 175; 175, binary_operator:%; 175, 176; 175, 177; 176, identifier:at_3; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:num_atoms; 180, block; 180, 181; 181, raise_statement; 181, 182; 182, call; 182, 183; 182, 184; 183, identifier:ValueError; 184, argument_list; 184, 185; 185, string:"'at_2' and 'at_3' must be different"; 186, if_statement; 186, 187; 186, 200; 187, comparison_operator:==; 187, 188; 187, 194; 188, parenthesized_expression; 188, 189; 189, binary_operator:%; 189, 190; 189, 191; 190, identifier:at_1; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:num_atoms; 194, parenthesized_expression; 194, 195; 195, binary_operator:%; 195, 196; 195, 197; 196, identifier:at_3; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:num_atoms; 200, block; 200, 201; 201, return_statement; 201, 202; 202, float:0.0; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:vec_2_1; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:displ_single; 210, argument_list; 210, 211; 210, 212; 210, 213; 211, identifier:g_num; 212, identifier:at_2; 213, identifier:at_1; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:vec_2_3; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:displ_single; 221, argument_list; 221, 222; 221, 223; 221, 224; 222, identifier:g_num; 223, identifier:at_2; 224, identifier:at_3; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:angle; 228, call; 228, 229; 228, 230; 229, identifier:vec_angle; 230, argument_list; 230, 231; 230, 232; 231, identifier:vec_2_1; 232, identifier:vec_2_3; 233, return_statement; 233, 234; 234, identifier:angle
def angle_single(self, g_num, at_1, at_2, at_3): import numpy as np from .utils import safe_cast as scast from .utils.vector import vec_angle if not(-self.num_atoms <= at_1 < self.num_atoms): raise IndexError("Invalid index for 'at_1' ({0})".format(at_1)) if not(-self.num_atoms <= at_2 < self.num_atoms): raise IndexError("Invalid index for 'at_2' ({0})".format(at_2)) if not(-self.num_atoms <= at_3 < self.num_atoms): raise IndexError("Invalid index for 'at_3' ({0})".format(at_3)) at_1 = scast(np.floor(at_1), np.int_) at_2 = scast(np.floor(at_2), np.int_) at_3 = scast(np.floor(at_3), np.int_) if (at_2 % self.num_atoms) == (at_1 % self.num_atoms): raise ValueError("'at_1' and 'at_2' must be different") if (at_2 % self.num_atoms) == (at_3 % self.num_atoms): raise ValueError("'at_2' and 'at_3' must be different") if (at_1 % self.num_atoms) == (at_3 % self.num_atoms): return 0.0 vec_2_1 = self.displ_single(g_num, at_2, at_1) vec_2_3 = self.displ_single(g_num, at_2, at_3) angle = vec_angle(vec_2_1, vec_2_3) return angle
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:angle_iter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:g_nums; 6, identifier:ats_1; 7, identifier:ats_2; 8, identifier:ats_3; 9, default_parameter; 9, 10; 9, 11; 10, identifier:invalid_error; 11, False; 12, block; 12, 13; 12, 20; 12, 63; 12, 75; 12, 83; 12, 91; 13, import_from_statement; 13, 14; 13, 18; 14, relative_import; 14, 15; 14, 16; 15, import_prefix; 16, dotted_name; 16, 17; 17, identifier:utils; 18, dotted_name; 18, 19; 19, identifier:pack_tups; 20, if_statement; 20, 21; 20, 22; 21, identifier:_DEBUG; 22, block; 22, 23; 22, 33; 22, 43; 22, 53; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:print; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, string:"g_nums = {0}"; 30, identifier:format; 31, argument_list; 31, 32; 32, identifier:g_nums; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:print; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, string:"ats_1 = {0}"; 40, identifier:format; 41, argument_list; 41, 42; 42, identifier:ats_1; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:print; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, string:"ats_2 = {0}"; 50, identifier:format; 51, argument_list; 51, 52; 52, identifier:ats_2; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:print; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, string:"ats_3 = {0}"; 60, identifier:format; 61, argument_list; 61, 62; 62, identifier:ats_3; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:arglist; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_none_subst; 70, argument_list; 70, 71; 70, 72; 70, 73; 70, 74; 71, identifier:g_nums; 72, identifier:ats_1; 73, identifier:ats_2; 74, identifier:ats_3; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:tups; 78, call; 78, 79; 78, 80; 79, identifier:pack_tups; 80, argument_list; 80, 81; 81, list_splat; 81, 82; 82, identifier:arglist; 83, if_statement; 83, 84; 83, 85; 84, identifier:_DEBUG; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 89; 88, identifier:print; 89, argument_list; 89, 90; 90, identifier:tups; 91, for_statement; 91, 92; 91, 93; 91, 94; 92, identifier:tup; 93, identifier:tups; 94, block; 94, 95; 94, 103; 95, if_statement; 95, 96; 95, 97; 96, identifier:_DEBUG; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:print; 101, argument_list; 101, 102; 102, identifier:tup; 103, expression_statement; 103, 104; 104, yield; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:_iter_return; 109, argument_list; 109, 110; 109, 111; 109, 114; 110, identifier:tup; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:angle_single; 114, identifier:invalid_error
def angle_iter(self, g_nums, ats_1, ats_2, ats_3, invalid_error=False): from .utils import pack_tups if _DEBUG: print("g_nums = {0}".format(g_nums)) print("ats_1 = {0}".format(ats_1)) print("ats_2 = {0}".format(ats_2)) print("ats_3 = {0}".format(ats_3)) arglist = self._none_subst(g_nums, ats_1, ats_2, ats_3) tups = pack_tups(*arglist) if _DEBUG: print(tups) for tup in tups: if _DEBUG: print(tup) yield self._iter_return(tup, self.angle_single, invalid_error)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:dihed_iter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:g_nums; 6, identifier:ats_1; 7, identifier:ats_2; 8, identifier:ats_3; 9, identifier:ats_4; 10, line_continuation:\; 11, default_parameter; 11, 12; 11, 13; 12, identifier:invalid_error; 13, False; 14, block; 14, 15; 14, 22; 14, 75; 14, 88; 14, 96; 14, 104; 15, import_from_statement; 15, 16; 15, 20; 16, relative_import; 16, 17; 16, 18; 17, import_prefix; 18, dotted_name; 18, 19; 19, identifier:utils; 20, dotted_name; 20, 21; 21, identifier:pack_tups; 22, if_statement; 22, 23; 22, 24; 23, identifier:_DEBUG; 24, block; 24, 25; 24, 35; 24, 45; 24, 55; 24, 65; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:print; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, string:"g_nums = {0}"; 32, identifier:format; 33, argument_list; 33, 34; 34, identifier:g_nums; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:print; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, string:"ats_1 = {0}"; 42, identifier:format; 43, argument_list; 43, 44; 44, identifier:ats_1; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:print; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, string:"ats_2 = {0}"; 52, identifier:format; 53, argument_list; 53, 54; 54, identifier:ats_2; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:print; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, string:"ats_3 = {0}"; 62, identifier:format; 63, argument_list; 63, 64; 64, identifier:ats_3; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:print; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:"ats_4 = {0}"; 72, identifier:format; 73, argument_list; 73, 74; 74, identifier:ats_4; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:arglist; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:_none_subst; 82, argument_list; 82, 83; 82, 84; 82, 85; 82, 86; 82, 87; 83, identifier:g_nums; 84, identifier:ats_1; 85, identifier:ats_2; 86, identifier:ats_3; 87, identifier:ats_4; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:tups; 91, call; 91, 92; 91, 93; 92, identifier:pack_tups; 93, argument_list; 93, 94; 94, list_splat; 94, 95; 95, identifier:arglist; 96, if_statement; 96, 97; 96, 98; 97, identifier:_DEBUG; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:print; 102, argument_list; 102, 103; 103, identifier:tups; 104, for_statement; 104, 105; 104, 106; 104, 107; 105, identifier:tup; 106, identifier:tups; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, yield; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:_iter_return; 114, argument_list; 114, 115; 114, 116; 114, 119; 115, identifier:tup; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:dihed_single; 119, identifier:invalid_error
def dihed_iter(self, g_nums, ats_1, ats_2, ats_3, ats_4, \ invalid_error=False): from .utils import pack_tups if _DEBUG: print("g_nums = {0}".format(g_nums)) print("ats_1 = {0}".format(ats_1)) print("ats_2 = {0}".format(ats_2)) print("ats_3 = {0}".format(ats_3)) print("ats_4 = {0}".format(ats_4)) arglist = self._none_subst(g_nums, ats_1, ats_2, ats_3, ats_4) tups = pack_tups(*arglist) if _DEBUG: print(tups) for tup in tups: yield self._iter_return(tup, self.dihed_single, invalid_error)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:displ_single; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:g_num; 6, identifier:at_1; 7, identifier:at_2; 8, block; 8, 9; 8, 14; 8, 23; 8, 46; 8, 69; 8, 84; 8, 99; 8, 124; 8, 133; 8, 163; 9, import_statement; 9, 10; 10, aliased_import; 10, 11; 10, 13; 11, dotted_name; 11, 12; 12, identifier:numpy; 13, identifier:np; 14, import_from_statement; 14, 15; 14, 19; 15, relative_import; 15, 16; 15, 17; 16, import_prefix; 17, dotted_name; 17, 18; 18, identifier:utils; 19, aliased_import; 19, 20; 19, 22; 20, dotted_name; 20, 21; 21, identifier:safe_cast; 22, identifier:scast; 23, if_statement; 23, 24; 23, 35; 24, not_operator; 24, 25; 25, parenthesized_expression; 25, 26; 26, comparison_operator:<=; 26, 27; 26, 31; 26, 32; 27, unary_operator:-; 27, 28; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:num_atoms; 31, identifier:at_1; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:num_atoms; 35, block; 35, 36; 36, raise_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:IndexError; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, string:"Invalid index for 'at_1' ({0})"; 43, identifier:format; 44, argument_list; 44, 45; 45, identifier:at_1; 46, if_statement; 46, 47; 46, 58; 47, not_operator; 47, 48; 48, parenthesized_expression; 48, 49; 49, comparison_operator:<=; 49, 50; 49, 54; 49, 55; 50, unary_operator:-; 50, 51; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:num_atoms; 54, identifier:at_2; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:num_atoms; 58, block; 58, 59; 59, raise_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:IndexError; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, string:"Invalid index for 'at_2' ({0})"; 66, identifier:format; 67, argument_list; 67, 68; 68, identifier:at_2; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:at_1; 72, call; 72, 73; 72, 74; 73, identifier:scast; 74, argument_list; 74, 75; 74, 81; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:np; 78, identifier:floor; 79, argument_list; 79, 80; 80, identifier:at_1; 81, attribute; 81, 82; 81, 83; 82, identifier:np; 83, identifier:int_; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:at_2; 87, call; 87, 88; 87, 89; 88, identifier:scast; 89, argument_list; 89, 90; 89, 96; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:floor; 94, argument_list; 94, 95; 95, identifier:at_2; 96, attribute; 96, 97; 96, 98; 97, identifier:np; 98, identifier:int_; 99, if_statement; 99, 100; 99, 113; 100, comparison_operator:==; 100, 101; 100, 107; 101, parenthesized_expression; 101, 102; 102, binary_operator:%; 102, 103; 102, 104; 103, identifier:at_1; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:num_atoms; 107, parenthesized_expression; 107, 108; 108, binary_operator:%; 108, 109; 108, 110; 109, identifier:at_2; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:num_atoms; 113, block; 113, 114; 114, return_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:np; 118, identifier:array; 119, argument_list; 119, 120; 120, list:[0.0, 0.0, 0.0]; 120, 121; 120, 122; 120, 123; 121, float:0.0; 122, float:0.0; 123, float:0.0; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:g; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:geom_single; 131, argument_list; 131, 132; 132, identifier:g_num; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:displ; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:np; 139, identifier:array; 140, argument_list; 140, 141; 141, list_comprehension; 141, 142; 141, 157; 142, binary_operator:-; 142, 143; 142, 150; 143, subscript; 143, 144; 143, 145; 144, identifier:g; 145, binary_operator:+; 145, 146; 145, 147; 146, identifier:i; 147, binary_operator:*; 147, 148; 147, 149; 148, integer:3; 149, identifier:at_2; 150, subscript; 150, 151; 150, 152; 151, identifier:g; 152, binary_operator:+; 152, 153; 152, 154; 153, identifier:i; 154, binary_operator:*; 154, 155; 154, 156; 155, integer:3; 156, identifier:at_1; 157, for_in_clause; 157, 158; 157, 159; 158, identifier:i; 159, call; 159, 160; 159, 161; 160, identifier:range; 161, argument_list; 161, 162; 162, integer:3; 163, return_statement; 163, 164; 164, identifier:displ
def displ_single(self, g_num, at_1, at_2): import numpy as np from .utils import safe_cast as scast if not (-self.num_atoms <= at_1 < self.num_atoms): raise IndexError("Invalid index for 'at_1' ({0})".format(at_1)) if not (-self.num_atoms <= at_2 < self.num_atoms): raise IndexError("Invalid index for 'at_2' ({0})".format(at_2)) at_1 = scast(np.floor(at_1), np.int_) at_2 = scast(np.floor(at_2), np.int_) if (at_1 % self.num_atoms) == (at_2 % self.num_atoms): return np.array([0.0, 0.0, 0.0]) g = self.geom_single(g_num) displ = np.array([ g[i + 3*at_2] - g[i + 3*at_1] for i in range(3) ]) return displ
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:displ_iter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:g_nums; 6, identifier:ats_1; 7, identifier:ats_2; 8, default_parameter; 8, 9; 8, 10; 9, identifier:invalid_error; 10, False; 11, block; 11, 12; 11, 19; 11, 52; 11, 63; 11, 71; 11, 79; 12, import_from_statement; 12, 13; 12, 17; 13, relative_import; 13, 14; 13, 15; 14, import_prefix; 15, dotted_name; 15, 16; 16, identifier:utils; 17, dotted_name; 17, 18; 18, identifier:pack_tups; 19, if_statement; 19, 20; 19, 21; 20, identifier:_DEBUG; 21, block; 21, 22; 21, 32; 21, 42; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:print; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, string:"g_nums = {0}"; 29, identifier:format; 30, argument_list; 30, 31; 31, identifier:g_nums; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:print; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, string:"ats_1 = {0}"; 39, identifier:format; 40, argument_list; 40, 41; 41, identifier:ats_1; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:print; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, string:"ats_2 = {0}"; 49, identifier:format; 50, argument_list; 50, 51; 51, identifier:ats_2; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:arglist; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:_none_subst; 59, argument_list; 59, 60; 59, 61; 59, 62; 60, identifier:g_nums; 61, identifier:ats_1; 62, identifier:ats_2; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:tups; 66, call; 66, 67; 66, 68; 67, identifier:pack_tups; 68, argument_list; 68, 69; 69, list_splat; 69, 70; 70, identifier:arglist; 71, if_statement; 71, 72; 71, 73; 72, identifier:_DEBUG; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:print; 77, argument_list; 77, 78; 78, identifier:tups; 79, for_statement; 79, 80; 79, 81; 79, 82; 80, identifier:tup; 81, identifier:tups; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, yield; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:_iter_return; 89, argument_list; 89, 90; 89, 91; 89, 94; 90, identifier:tup; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:displ_single; 94, identifier:invalid_error
def displ_iter(self, g_nums, ats_1, ats_2, invalid_error=False): from .utils import pack_tups if _DEBUG: print("g_nums = {0}".format(g_nums)) print("ats_1 = {0}".format(ats_1)) print("ats_2 = {0}".format(ats_2)) arglist = self._none_subst(g_nums, ats_1, ats_2) tups = pack_tups(*arglist) if _DEBUG: print(tups) for tup in tups: yield self._iter_return(tup, self.displ_single, invalid_error)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_none_subst; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, block; 7, 8; 7, 13; 7, 21; 7, 25; 7, 46; 7, 163; 8, import_statement; 8, 9; 9, aliased_import; 9, 10; 9, 12; 10, dotted_name; 10, 11; 11, identifier:numpy; 12, identifier:np; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:arglist; 16, list_comprehension; 16, 17; 16, 18; 17, identifier:a; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:a; 20, identifier:args; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:none_found; 24, False; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:none_vals; 28, call; 28, 29; 28, 30; 29, identifier:list; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:map; 33, argument_list; 33, 34; 33, 45; 34, lambda; 34, 35; 34, 37; 35, lambda_parameters; 35, 36; 36, identifier:e; 37, call; 37, 38; 37, 39; 38, identifier:isinstance; 39, argument_list; 39, 40; 39, 41; 40, identifier:e; 41, call; 41, 42; 41, 43; 42, identifier:type; 43, argument_list; 43, 44; 44, None; 45, identifier:arglist; 46, if_statement; 46, 47; 46, 55; 46, 76; 47, comparison_operator:>; 47, 48; 47, 54; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:np; 51, identifier:count_nonzero; 52, argument_list; 52, 53; 53, identifier:none_vals; 54, integer:1; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:ValueError; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, string:"Multiple 'None' values [indices {0}] not supported"; 63, identifier:format; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:tuple; 67, argument_list; 67, 68; 68, subscript; 68, 69; 68, 75; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:np; 72, identifier:nonzero; 73, argument_list; 73, 74; 74, identifier:none_vals; 75, integer:0; 76, elif_clause; 76, 77; 76, 85; 77, comparison_operator:==; 77, 78; 77, 84; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:np; 81, identifier:count_nonzero; 82, argument_list; 82, 83; 83, identifier:none_vals; 84, integer:1; 85, block; 85, 86; 85, 127; 85, 131; 85, 144; 86, if_statement; 86, 87; 86, 121; 87, not_operator; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:all; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:np; 94, identifier:equal; 95, argument_list; 95, 96; 95, 106; 96, call; 96, 97; 96, 98; 97, identifier:list; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:map; 101, argument_list; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:np; 104, identifier:iterable; 105, identifier:arglist; 106, call; 106, 107; 106, 108; 107, identifier:list; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:map; 111, argument_list; 111, 112; 111, 120; 112, lambda; 112, 113; 112, 115; 113, lambda_parameters; 113, 114; 114, identifier:e; 115, call; 115, 116; 115, 117; 116, identifier:isinstance; 117, argument_list; 117, 118; 117, 119; 118, identifier:e; 119, identifier:str; 120, identifier:arglist; 121, block; 121, 122; 122, raise_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:ValueError; 125, argument_list; 125, 126; 126, string:"'None' as parameter invalid with non-str iterables"; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:none_found; 130, True; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:none_loc; 134, subscript; 134, 135; 134, 143; 135, subscript; 135, 136; 135, 142; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:np; 139, identifier:nonzero; 140, argument_list; 140, 141; 141, identifier:none_vals; 142, integer:0; 143, integer:0; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 145, 150; 146, subscript; 146, 147; 146, 148; 147, identifier:arglist; 148, identifier:none_loc; 149, line_continuation:\; 150, call; 150, 151; 150, 152; 151, identifier:range; 152, argument_list; 152, 153; 153, conditional_expression:if; 153, 154; 153, 157; 153, 160; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:num_geoms; 157, comparison_operator:==; 157, 158; 157, 159; 158, identifier:none_loc; 159, integer:0; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:num_atoms; 163, return_statement; 163, 164; 164, identifier:arglist
def _none_subst(self, *args): import numpy as np arglist = [a for a in args] none_found = False none_vals = list(map(lambda e: isinstance(e, type(None)), arglist)) if np.count_nonzero(none_vals) > 1: raise ValueError( "Multiple 'None' values [indices {0}] not supported" .format(tuple(np.nonzero(none_vals)[0]))) elif np.count_nonzero(none_vals) == 1: if not all(np.equal(list(map(np.iterable, arglist)), list(map(lambda e: isinstance(e, str), arglist)))): raise ValueError( "'None' as parameter invalid with non-str iterables") none_found = True none_loc = np.nonzero(none_vals)[0][0] arglist[none_loc] = \ range(self.num_geoms if none_loc == 0 else self.num_atoms) return arglist
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:new_from_files; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 3, 13; 3, 18; 3, 19; 3, 22; 4, identifier:self; 5, identifier:basepath; 6, identifier:basename; 7, identifier:repo; 8, line_continuation:\; 9, default_parameter; 9, 10; 9, 11; 10, identifier:bohrs; 11, False; 12, line_continuation:\; 13, default_parameter; 13, 14; 13, 15; 14, identifier:software; 15, attribute; 15, 16; 15, 17; 16, identifier:_E_SW; 17, identifier:ORCA; 18, line_continuation:\; 19, default_parameter; 19, 20; 19, 21; 20, identifier:repo_clobber; 21, False; 22, dictionary_splat_pattern; 22, 23; 23, identifier:kwargs; 24, block; 24, 25; 24, 28; 24, 35; 24, 44; 24, 53; 24, 62; 24, 71; 24, 84; 24, 93; 24, 100; 24, 109; 24, 126; 24, 143; 24, 160; 24, 177; 24, 199; 24, 227; 24, 255; 24, 270; 24, 300; 24, 315; 24, 342; 25, import_statement; 25, 26; 26, dotted_name; 26, 27; 27, identifier:os; 28, import_from_statement; 28, 29; 28, 31; 29, dotted_name; 29, 30; 30, identifier:os; 31, aliased_import; 31, 32; 31, 34; 32, dotted_name; 32, 33; 33, identifier:path; 34, identifier:osp; 35, import_from_statement; 35, 36; 35, 40; 36, relative_import; 36, 37; 36, 38; 37, import_prefix; 38, dotted_name; 38, 39; 39, identifier:xyz; 40, aliased_import; 40, 41; 40, 43; 41, dotted_name; 41, 42; 42, identifier:OpanXYZ; 43, identifier:OX; 44, import_from_statement; 44, 45; 44, 49; 45, relative_import; 45, 46; 45, 47; 46, import_prefix; 47, dotted_name; 47, 48; 48, identifier:grad; 49, aliased_import; 49, 50; 49, 52; 50, dotted_name; 50, 51; 51, identifier:OrcaEngrad; 52, identifier:OE; 53, import_from_statement; 53, 54; 53, 58; 54, relative_import; 54, 55; 54, 56; 55, import_prefix; 56, dotted_name; 56, 57; 57, identifier:hess; 58, aliased_import; 58, 59; 58, 61; 59, dotted_name; 59, 60; 60, identifier:OrcaHess; 61, identifier:OH; 62, import_from_statement; 62, 63; 62, 67; 63, relative_import; 63, 64; 63, 65; 64, import_prefix; 65, dotted_name; 65, 66; 66, identifier:repo; 67, aliased_import; 67, 68; 67, 70; 68, dotted_name; 68, 69; 69, identifier:OpanAnharmRepo; 70, identifier:OR; 71, import_from_statement; 71, 72; 71, 76; 71, 80; 72, relative_import; 72, 73; 72, 74; 73, import_prefix; 74, dotted_name; 74, 75; 75, identifier:const; 76, aliased_import; 76, 77; 76, 79; 77, dotted_name; 77, 78; 78, identifier:EnumDispDirection; 79, identifier:E_DDir; 80, aliased_import; 80, 81; 80, 83; 81, dotted_name; 81, 82; 82, identifier:EnumFileType; 83, identifier:E_FT; 84, import_from_statement; 84, 85; 84, 89; 85, relative_import; 85, 86; 85, 87; 86, import_prefix; 87, dotted_name; 87, 88; 88, identifier:const; 89, aliased_import; 89, 90; 89, 92; 90, dotted_name; 90, 91; 91, identifier:EnumSoftware; 92, identifier:E_SW; 93, import_from_statement; 93, 94; 93, 98; 94, relative_import; 94, 95; 94, 96; 95, import_prefix; 96, dotted_name; 96, 97; 97, identifier:const; 98, dotted_name; 98, 99; 99, identifier:DEF; 100, import_from_statement; 100, 101; 100, 105; 101, relative_import; 101, 102; 101, 103; 102, import_prefix; 103, dotted_name; 103, 104; 104, identifier:error; 105, aliased_import; 105, 106; 105, 108; 106, dotted_name; 106, 107; 107, identifier:AnharmError; 108, identifier:ANHErr; 109, if_statement; 109, 110; 109, 116; 110, not_operator; 110, 111; 111, comparison_operator:==; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:w_xyz; 115, None; 116, block; 116, 117; 117, raise_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:ANHErr; 120, argument_list; 120, 121; 120, 124; 120, 125; 121, attribute; 121, 122; 121, 123; 122, identifier:ANHErr; 123, identifier:STATUS; 124, string:"XYZ object is already bound"; 125, string:""; 126, if_statement; 126, 127; 126, 133; 127, not_operator; 127, 128; 128, comparison_operator:==; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:w_grad; 132, None; 133, block; 133, 134; 134, raise_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:ANHErr; 137, argument_list; 137, 138; 137, 141; 137, 142; 138, attribute; 138, 139; 138, 140; 139, identifier:ANHErr; 140, identifier:STATUS; 141, string:"GRAD object is already bound"; 142, string:""; 143, if_statement; 143, 144; 143, 150; 144, not_operator; 144, 145; 145, comparison_operator:==; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:w_hess; 149, None; 150, block; 150, 151; 151, raise_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:ANHErr; 154, argument_list; 154, 155; 154, 158; 154, 159; 155, attribute; 155, 156; 155, 157; 156, identifier:ANHErr; 157, identifier:STATUS; 158, string:"HESS object is already bound"; 159, string:""; 160, if_statement; 160, 161; 160, 167; 161, not_operator; 161, 162; 162, comparison_operator:==; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:repo; 166, None; 167, block; 167, 168; 168, raise_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:ANHErr; 171, argument_list; 171, 172; 171, 175; 171, 176; 172, attribute; 172, 173; 172, 174; 173, identifier:ANHErr; 174, identifier:STATUS; 175, string:"Repository object is already bound"; 176, string:""; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:w_xyz; 182, call; 182, 183; 182, 184; 183, identifier:OX; 184, argument_list; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:osp; 188, identifier:join; 189, argument_list; 189, 190; 189, 191; 189, 192; 190, identifier:basepath; 191, line_continuation:\; 192, binary_operator:+; 192, 193; 192, 198; 193, binary_operator:+; 193, 194; 193, 195; 194, identifier:basename; 195, attribute; 195, 196; 195, 197; 196, identifier:osp; 197, identifier:extsep; 198, identifier:xyz_ext; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:w_grad; 204, call; 204, 205; 204, 206; 205, identifier:OE; 206, argument_list; 206, 207; 206, 221; 206, 222; 206, 223; 206, 226; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:osp; 210, identifier:join; 211, argument_list; 211, 212; 211, 213; 211, 214; 212, identifier:basepath; 213, line_continuation:\; 214, binary_operator:+; 214, 215; 214, 220; 215, binary_operator:+; 215, 216; 215, 217; 216, identifier:basename; 217, attribute; 217, 218; 217, 219; 218, identifier:osp; 219, identifier:extsep; 220, identifier:engrad_ext; 221, line_continuation:\; 222, integer:0; 223, attribute; 223, 224; 223, 225; 224, identifier:E_DDir; 225, identifier:NO_DISP; 226, float:0.0; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:self; 231, identifier:w_hess; 232, call; 232, 233; 232, 234; 233, identifier:OH; 234, argument_list; 234, 235; 234, 249; 234, 250; 234, 251; 234, 254; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:osp; 238, identifier:join; 239, argument_list; 239, 240; 239, 241; 239, 242; 240, identifier:basepath; 241, line_continuation:\; 242, binary_operator:+; 242, 243; 242, 248; 243, binary_operator:+; 243, 244; 243, 245; 244, identifier:basename; 245, attribute; 245, 246; 245, 247; 246, identifier:osp; 247, identifier:extsep; 248, identifier:hess_ext; 249, line_continuation:\; 250, integer:0; 251, attribute; 251, 252; 251, 253; 252, identifier:E_DDir; 253, identifier:NO_DISP; 254, float:0.0; 255, if_statement; 255, 256; 255, 262; 256, not_operator; 256, 257; 257, call; 257, 258; 257, 259; 258, identifier:isinstance; 259, argument_list; 259, 260; 259, 261; 260, identifier:repo; 261, identifier:str; 262, block; 262, 263; 263, raise_statement; 263, 264; 264, call; 264, 265; 264, 266; 265, identifier:TypeError; 266, argument_list; 266, 267; 267, binary_operator:+; 267, 268; 267, 269; 268, string:"Must create new repository when loading "; 269, string:"a new dataset."; 270, if_statement; 270, 271; 270, 289; 271, boolean_operator:and; 271, 272; 271, 282; 272, comparison_operator:>; 272, 273; 272, 281; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:osp; 276, identifier:split; 277, argument_list; 277, 278; 278, subscript; 278, 279; 278, 280; 279, identifier:repo; 280, integer:0; 281, integer:0; 282, not_operator; 282, 283; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:osp; 286, identifier:isabs; 287, argument_list; 287, 288; 288, identifier:repo; 289, block; 289, 290; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:repo; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:osp; 296, identifier:join; 297, argument_list; 297, 298; 297, 299; 298, identifier:basepath; 299, identifier:repo; 300, if_statement; 300, 301; 300, 307; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:osp; 304, identifier:isdir; 305, argument_list; 305, 306; 306, identifier:repo; 307, block; 307, 308; 308, raise_statement; 308, 309; 309, call; 309, 310; 309, 311; 310, identifier:IOError; 311, argument_list; 311, 312; 312, binary_operator:+; 312, 313; 312, 314; 313, string:"Cannot bind repository -- specified "; 314, string:"location is a directory"; 315, if_statement; 315, 316; 315, 322; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:osp; 319, identifier:isfile; 320, argument_list; 320, 321; 321, identifier:repo; 322, block; 322, 323; 323, if_statement; 323, 324; 323, 325; 323, 333; 324, identifier:repo_clobber; 325, block; 325, 326; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:os; 330, identifier:remove; 331, argument_list; 331, 332; 332, identifier:repo; 333, else_clause; 333, 334; 334, block; 334, 335; 335, raise_statement; 335, 336; 336, call; 336, 337; 336, 338; 337, identifier:IOError; 338, argument_list; 338, 339; 339, binary_operator:+; 339, 340; 339, 341; 340, string:"Target repository file exists and "; 341, string:"clobber is disabled."; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:self; 346, identifier:repo; 347, call; 347, 348; 347, 349; 348, identifier:OR; 349, argument_list; 349, 350; 350, identifier:repo
def new_from_files(self, basepath, basename, repo, \ bohrs=False, \ software=_E_SW.ORCA, \ repo_clobber=False, **kwargs): import os from os import path as osp from ..xyz import OpanXYZ as OX from ..grad import OrcaEngrad as OE from ..hess import OrcaHess as OH from .repo import OpanAnharmRepo as OR from ..const import EnumDispDirection as E_DDir, EnumFileType as E_FT from ..const import EnumSoftware as E_SW from ..const import DEF from ..error import AnharmError as ANHErr if not self.w_xyz == None: raise ANHErr(ANHErr.STATUS, "XYZ object is already bound", "") if not self.w_grad == None: raise ANHErr(ANHErr.STATUS, "GRAD object is already bound", "") if not self.w_hess == None: raise ANHErr(ANHErr.STATUS, "HESS object is already bound", "") if not self.repo == None: raise ANHErr(ANHErr.STATUS, "Repository object is already bound", "") self.w_xyz = OX( osp.join(basepath, \ basename + osp.extsep + xyz_ext) ) self.w_grad = OE( osp.join(basepath, \ basename + osp.extsep + engrad_ext), \ 0, E_DDir.NO_DISP, 0.0 ) self.w_hess = OH( osp.join(basepath, \ basename + osp.extsep + hess_ext), \ 0, E_DDir.NO_DISP, 0.0 ) if not isinstance(repo, str): raise TypeError("Must create new repository when loading " + "a new dataset.") if osp.split(repo[0]) > 0 and not osp.isabs(repo): repo = osp.join(basepath, repo) if osp.isdir(repo): raise IOError("Cannot bind repository -- specified " + "location is a directory") if osp.isfile(repo): if repo_clobber: os.remove(repo) else: raise IOError("Target repository file exists and " + "clobber is disabled.") self.repo = OR(repo)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:from_locus_read; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:locus_read; 6, identifier:n_ref; 7, block; 7, 8; 7, 14; 7, 20; 7, 26; 7, 32; 7, 38; 7, 53; 7, 59; 7, 74; 7, 155; 7, 166; 7, 176; 7, 184; 7, 194; 7, 204; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:sequence; 11, attribute; 11, 12; 11, 13; 12, identifier:locus_read; 13, identifier:sequence; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:reference_positions; 17, attribute; 17, 18; 17, 19; 18, identifier:locus_read; 19, identifier:reference_positions; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:read_pos_before; 23, attribute; 23, 24; 23, 25; 24, identifier:locus_read; 25, identifier:base0_read_position_before_variant; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:read_pos_after; 29, attribute; 29, 30; 29, 31; 30, identifier:locus_read; 31, identifier:base0_read_position_after_variant; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:ref_pos_before; 35, subscript; 35, 36; 35, 37; 36, identifier:reference_positions; 37, identifier:read_pos_before; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:ref_pos_before; 41, None; 42, block; 42, 43; 42, 51; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:logger; 47, identifier:warn; 48, argument_list; 48, 49; 48, 50; 49, string:"Missing reference pos for nucleotide before variant on read: %s"; 50, identifier:locus_read; 51, return_statement; 51, 52; 52, None; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:ref_pos_after; 56, subscript; 56, 57; 56, 58; 57, identifier:reference_positions; 58, identifier:read_pos_after; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:is; 60, 61; 60, 62; 61, identifier:ref_pos_after; 62, None; 63, block; 63, 64; 63, 72; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:logger; 68, identifier:warn; 69, argument_list; 69, 70; 69, 71; 70, string:"Missing reference pos for nucleotide after variant on read: %s"; 71, identifier:locus_read; 72, return_statement; 72, 73; 73, None; 74, if_statement; 74, 75; 74, 78; 74, 129; 75, comparison_operator:==; 75, 76; 75, 77; 76, identifier:n_ref; 77, integer:0; 78, block; 78, 79; 78, 98; 78, 109; 79, if_statement; 79, 80; 79, 85; 80, comparison_operator:!=; 80, 81; 80, 84; 81, binary_operator:-; 81, 82; 81, 83; 82, identifier:ref_pos_after; 83, identifier:ref_pos_before; 84, integer:1; 85, block; 85, 86; 85, 96; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:logger; 90, identifier:debug; 91, argument_list; 91, 92; 91, 93; 91, 94; 91, 95; 92, string:"Positions before (%d) and after (%d) variant should be adjacent on read %s"; 93, identifier:ref_pos_before; 94, identifier:ref_pos_after; 95, identifier:locus_read; 96, return_statement; 96, 97; 97, None; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:ref_positions_for_inserted; 101, subscript; 101, 102; 101, 103; 102, identifier:reference_positions; 103, slice; 103, 104; 103, 107; 103, 108; 104, binary_operator:+; 104, 105; 104, 106; 105, identifier:read_pos_before; 106, integer:1; 107, colon; 108, identifier:read_pos_after; 109, if_statement; 109, 110; 109, 119; 110, call; 110, 111; 110, 112; 111, identifier:any; 112, generator_expression; 112, 113; 112, 116; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:insert_pos; 115, None; 116, for_in_clause; 116, 117; 116, 118; 117, identifier:insert_pos; 118, identifier:ref_positions_for_inserted; 119, block; 119, 120; 119, 127; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:logger; 124, identifier:debug; 125, argument_list; 125, 126; 126, string:"Skipping read, inserted nucleotides shouldn't map to reference"; 127, return_statement; 127, 128; 128, None; 129, else_clause; 129, 130; 130, block; 130, 131; 131, if_statement; 131, 132; 131, 139; 132, comparison_operator:!=; 132, 133; 132, 136; 133, binary_operator:-; 133, 134; 133, 135; 134, identifier:ref_pos_after; 135, identifier:ref_pos_before; 136, binary_operator:+; 136, 137; 136, 138; 137, identifier:n_ref; 138, integer:1; 139, block; 139, 140; 139, 153; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:logger; 144, identifier:debug; 145, argument_list; 145, 146; 145, 150; 145, 151; 145, 152; 146, parenthesized_expression; 146, 147; 147, concatenated_string; 147, 148; 147, 149; 148, string:"Positions before (%d) and after (%d) variant should be "; 149, string:"adjacent on read %s"; 150, identifier:ref_pos_before; 151, identifier:ref_pos_after; 152, identifier:locus_read; 153, return_statement; 153, 154; 154, None; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:nucleotides_at_variant_locus; 158, subscript; 158, 159; 158, 160; 159, identifier:sequence; 160, slice; 160, 161; 160, 164; 160, 165; 161, binary_operator:+; 161, 162; 161, 163; 162, identifier:read_pos_before; 163, integer:1; 164, colon; 165, identifier:read_pos_after; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:prefix; 169, subscript; 169, 170; 169, 171; 170, identifier:sequence; 171, slice; 171, 172; 171, 173; 172, colon; 173, binary_operator:+; 173, 174; 173, 175; 174, identifier:read_pos_before; 175, integer:1; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:suffix; 179, subscript; 179, 180; 179, 181; 180, identifier:sequence; 181, slice; 181, 182; 181, 183; 182, identifier:read_pos_after; 183, colon; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 189; 186, pattern_list; 186, 187; 186, 188; 187, identifier:prefix; 188, identifier:suffix; 189, call; 189, 190; 189, 191; 190, identifier:convert_from_bytes_if_necessary; 191, argument_list; 191, 192; 191, 193; 192, identifier:prefix; 193, identifier:suffix; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, pattern_list; 196, 197; 196, 198; 197, identifier:prefix; 198, identifier:suffix; 199, call; 199, 200; 199, 201; 200, identifier:trim_N_nucleotides; 201, argument_list; 201, 202; 201, 203; 202, identifier:prefix; 203, identifier:suffix; 204, return_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:cls; 207, argument_list; 207, 208; 207, 209; 207, 210; 207, 211; 208, identifier:prefix; 209, identifier:nucleotides_at_variant_locus; 210, identifier:suffix; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:name; 213, attribute; 213, 214; 213, 215; 214, identifier:locus_read; 215, identifier:name
def from_locus_read(cls, locus_read, n_ref): sequence = locus_read.sequence reference_positions = locus_read.reference_positions read_pos_before = locus_read.base0_read_position_before_variant read_pos_after = locus_read.base0_read_position_after_variant ref_pos_before = reference_positions[read_pos_before] if ref_pos_before is None: logger.warn( "Missing reference pos for nucleotide before variant on read: %s", locus_read) return None ref_pos_after = reference_positions[read_pos_after] if ref_pos_after is None: logger.warn( "Missing reference pos for nucleotide after variant on read: %s", locus_read) return None if n_ref == 0: if ref_pos_after - ref_pos_before != 1: logger.debug( "Positions before (%d) and after (%d) variant should be adjacent on read %s", ref_pos_before, ref_pos_after, locus_read) return None ref_positions_for_inserted = reference_positions[ read_pos_before + 1:read_pos_after] if any(insert_pos is not None for insert_pos in ref_positions_for_inserted): logger.debug( "Skipping read, inserted nucleotides shouldn't map to reference") return None else: if ref_pos_after - ref_pos_before != n_ref + 1: logger.debug( ("Positions before (%d) and after (%d) variant should be " "adjacent on read %s"), ref_pos_before, ref_pos_after, locus_read) return None nucleotides_at_variant_locus = sequence[read_pos_before + 1:read_pos_after] prefix = sequence[:read_pos_before + 1] suffix = sequence[read_pos_after:] prefix, suffix = convert_from_bytes_if_necessary(prefix, suffix) prefix, suffix = trim_N_nucleotides(prefix, suffix) return cls( prefix, nucleotides_at_variant_locus, suffix, name=locus_read.name)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:mtx_refl; 3, parameters; 3, 4; 3, 5; 4, identifier:nv; 5, default_parameter; 5, 6; 5, 7; 6, identifier:reps; 7, integer:1; 8, block; 8, 9; 8, 14; 8, 21; 8, 28; 8, 45; 8, 63; 8, 77; 8, 95; 8, 106; 8, 124; 8, 182; 8, 199; 9, import_statement; 9, 10; 10, aliased_import; 10, 11; 10, 13; 11, dotted_name; 11, 12; 12, identifier:numpy; 13, identifier:np; 14, import_from_statement; 14, 15; 14, 17; 15, dotted_name; 15, 16; 16, identifier:scipy; 17, aliased_import; 17, 18; 17, 20; 18, dotted_name; 18, 19; 19, identifier:linalg; 20, identifier:spla; 21, import_from_statement; 21, 22; 21, 26; 22, relative_import; 22, 23; 22, 24; 23, import_prefix; 24, dotted_name; 24, 25; 25, identifier:const; 26, dotted_name; 26, 27; 27, identifier:PRM; 28, if_statement; 28, 29; 28, 39; 29, comparison_operator:<; 29, 30; 29, 36; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:spla; 33, identifier:norm; 34, argument_list; 34, 35; 35, identifier:nv; 36, attribute; 36, 37; 36, 38; 37, identifier:PRM; 38, identifier:ZERO_VEC_TOL; 39, block; 39, 40; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:ValueError; 43, argument_list; 43, 44; 44, string:"Norm of 'nv' is too small."; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:nv; 48, call; 48, 49; 48, 50; 49, identifier:make_nd_vec; 50, argument_list; 50, 51; 50, 52; 50, 55; 50, 60; 51, identifier:nv; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:nd; 54, integer:3; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:t; 57, attribute; 57, 58; 57, 59; 58, identifier:np; 59, identifier:float64; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:norm; 62, True; 63, if_statement; 63, 64; 63, 71; 64, not_operator; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:np; 68, identifier:isscalar; 69, argument_list; 69, 70; 70, identifier:reps; 71, block; 71, 72; 72, raise_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:ValueError; 75, argument_list; 75, 76; 76, string:"'reps' must be scalar."; 77, if_statement; 77, 78; 77, 89; 78, not_operator; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:np; 82, identifier:issubdtype; 83, argument_list; 83, 84; 83, 88; 84, call; 84, 85; 84, 86; 85, identifier:type; 86, argument_list; 86, 87; 87, identifier:reps; 88, identifier:int; 89, block; 89, 90; 90, raise_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:ValueError; 93, argument_list; 93, 94; 94, string:"'reps' must be an integer."; 95, if_statement; 95, 96; 95, 100; 96, not_operator; 96, 97; 97, comparison_operator:>; 97, 98; 97, 99; 98, identifier:reps; 99, integer:0; 100, block; 100, 101; 101, raise_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:ValueError; 104, argument_list; 104, 105; 105, string:"'reps' must be a positive integer."; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:base_mtx; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:np; 112, identifier:zeros; 113, argument_list; 113, 114; 113, 119; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:shape; 116, tuple; 116, 117; 116, 118; 117, integer:3; 118, integer:3; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:dtype; 121, attribute; 121, 122; 121, 123; 122, identifier:np; 123, identifier:float64; 124, for_statement; 124, 125; 124, 126; 124, 130; 125, identifier:i; 126, call; 126, 127; 126, 128; 127, identifier:range; 128, argument_list; 128, 129; 129, integer:3; 130, block; 130, 131; 131, for_statement; 131, 132; 131, 133; 131, 138; 132, identifier:j; 133, call; 133, 134; 133, 135; 134, identifier:range; 135, argument_list; 135, 136; 135, 137; 136, identifier:i; 137, integer:3; 138, block; 138, 139; 139, if_statement; 139, 140; 139, 143; 139, 159; 140, comparison_operator:==; 140, 141; 140, 142; 141, identifier:i; 142, identifier:j; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 150; 146, subscript; 146, 147; 146, 148; 146, 149; 147, identifier:base_mtx; 148, identifier:i; 149, identifier:j; 150, binary_operator:-; 150, 151; 150, 152; 151, integer:1; 152, binary_operator:*; 152, 153; 152, 154; 153, integer:2; 154, binary_operator:**; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:nv; 157, identifier:i; 158, integer:2; 159, else_clause; 159, 160; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 167; 163, subscript; 163, 164; 163, 165; 163, 166; 164, identifier:base_mtx; 165, identifier:i; 166, identifier:j; 167, assignment; 167, 168; 167, 172; 168, subscript; 168, 169; 168, 170; 168, 171; 169, identifier:base_mtx; 170, identifier:j; 171, identifier:i; 172, binary_operator:*; 172, 173; 172, 179; 173, binary_operator:*; 173, 174; 173, 176; 174, unary_operator:-; 174, 175; 175, integer:2; 176, subscript; 176, 177; 176, 178; 177, identifier:nv; 178, identifier:i; 179, subscript; 179, 180; 179, 181; 180, identifier:nv; 181, identifier:j; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:refl_mtx; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:spla; 188, identifier:block_diag; 189, argument_list; 189, 190; 190, list_splat; 190, 191; 191, list_comprehension; 191, 192; 191, 193; 192, identifier:base_mtx; 193, for_in_clause; 193, 194; 193, 195; 194, identifier:i; 195, call; 195, 196; 195, 197; 196, identifier:range; 197, argument_list; 197, 198; 198, identifier:reps; 199, return_statement; 199, 200; 200, identifier:refl_mtx
def mtx_refl(nv, reps=1): import numpy as np from scipy import linalg as spla from ..const import PRM if spla.norm(nv) < PRM.ZERO_VEC_TOL: raise ValueError("Norm of 'nv' is too small.") nv = make_nd_vec(nv, nd=3, t=np.float64, norm=True) if not np.isscalar(reps): raise ValueError("'reps' must be scalar.") if not np.issubdtype(type(reps), int): raise ValueError("'reps' must be an integer.") if not reps > 0: raise ValueError("'reps' must be a positive integer.") base_mtx = np.zeros(shape=(3,3), dtype=np.float64) for i in range(3): for j in range(i,3): if i==j: base_mtx[i,j] = 1 - 2*nv[i]**2 else: base_mtx[i,j] = base_mtx[j,i] = -2*nv[i]*nv[j] refl_mtx= spla.block_diag(*[base_mtx for i in range(reps)]) return refl_mtx
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:mtx_rot; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:ax; 5, identifier:theta; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reps; 8, integer:1; 9, block; 9, 10; 9, 15; 9, 22; 9, 29; 9, 46; 9, 64; 9, 78; 9, 96; 9, 107; 9, 121; 9, 162; 9, 186; 9, 231; 9, 248; 10, import_statement; 10, 11; 11, aliased_import; 11, 12; 11, 14; 12, dotted_name; 12, 13; 13, identifier:numpy; 14, identifier:np; 15, import_from_statement; 15, 16; 15, 18; 16, dotted_name; 16, 17; 17, identifier:scipy; 18, aliased_import; 18, 19; 18, 21; 19, dotted_name; 19, 20; 20, identifier:linalg; 21, identifier:spla; 22, import_from_statement; 22, 23; 22, 27; 23, relative_import; 23, 24; 23, 25; 24, import_prefix; 25, dotted_name; 25, 26; 26, identifier:const; 27, dotted_name; 27, 28; 28, identifier:PRM; 29, if_statement; 29, 30; 29, 40; 30, comparison_operator:<; 30, 31; 30, 37; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:spla; 34, identifier:norm; 35, argument_list; 35, 36; 36, identifier:ax; 37, attribute; 37, 38; 37, 39; 38, identifier:PRM; 39, identifier:ZERO_VEC_TOL; 40, block; 40, 41; 41, raise_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:ValueError; 44, argument_list; 44, 45; 45, string:"Norm of 'ax' is too small."; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:ax; 49, call; 49, 50; 49, 51; 50, identifier:make_nd_vec; 51, argument_list; 51, 52; 51, 53; 51, 56; 51, 61; 52, identifier:ax; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:nd; 55, integer:3; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:t; 58, attribute; 58, 59; 58, 60; 59, identifier:np; 60, identifier:float64; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:norm; 63, True; 64, if_statement; 64, 65; 64, 72; 65, not_operator; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:np; 69, identifier:isscalar; 70, argument_list; 70, 71; 71, identifier:reps; 72, block; 72, 73; 73, raise_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:ValueError; 76, argument_list; 76, 77; 77, string:"'reps' must be scalar."; 78, if_statement; 78, 79; 78, 90; 79, not_operator; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:np; 83, identifier:issubdtype; 84, argument_list; 84, 85; 84, 89; 85, call; 85, 86; 85, 87; 86, identifier:type; 87, argument_list; 87, 88; 88, identifier:reps; 89, identifier:int; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:ValueError; 94, argument_list; 94, 95; 95, string:"'reps' must be an integer."; 96, if_statement; 96, 97; 96, 101; 97, not_operator; 97, 98; 98, comparison_operator:>; 98, 99; 98, 100; 99, identifier:reps; 100, integer:0; 101, block; 101, 102; 102, raise_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:ValueError; 105, argument_list; 105, 106; 106, string:"'reps' must be a positive integer."; 107, if_statement; 107, 108; 107, 115; 108, not_operator; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:np; 112, identifier:isscalar; 113, argument_list; 113, 114; 114, identifier:theta; 115, block; 115, 116; 116, raise_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:ValueError; 119, argument_list; 119, 120; 120, string:"'theta' must be scalar."; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:mod_lc; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:np; 127, identifier:array; 128, argument_list; 128, 129; 128, 157; 129, list:[ [0, -ax[2], ax[1]], [ax[2], 0, -ax[0]], [-ax[1], ax[0], 0] ]; 129, 130; 129, 139; 129, 148; 130, list:[0, -ax[2], ax[1]]; 130, 131; 130, 132; 130, 136; 131, integer:0; 132, unary_operator:-; 132, 133; 133, subscript; 133, 134; 133, 135; 134, identifier:ax; 135, integer:2; 136, subscript; 136, 137; 136, 138; 137, identifier:ax; 138, integer:1; 139, list:[ax[2], 0, -ax[0]]; 139, 140; 139, 143; 139, 144; 140, subscript; 140, 141; 140, 142; 141, identifier:ax; 142, integer:2; 143, integer:0; 144, unary_operator:-; 144, 145; 145, subscript; 145, 146; 145, 147; 146, identifier:ax; 147, integer:0; 148, list:[-ax[1], ax[0], 0]; 148, 149; 148, 153; 148, 156; 149, unary_operator:-; 149, 150; 150, subscript; 150, 151; 150, 152; 151, identifier:ax; 152, integer:1; 153, subscript; 153, 154; 153, 155; 154, identifier:ax; 155, integer:0; 156, integer:0; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:dtype; 159, attribute; 159, 160; 159, 161; 160, identifier:np; 161, identifier:float64; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:ax_oprod; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:np; 168, identifier:dot; 169, argument_list; 169, 170; 169, 178; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:ax; 173, identifier:reshape; 174, argument_list; 174, 175; 175, tuple; 175, 176; 175, 177; 176, integer:3; 177, integer:1; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:ax; 181, identifier:reshape; 182, argument_list; 182, 183; 183, tuple; 183, 184; 183, 185; 184, integer:1; 185, integer:3; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:base_mtx; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:np; 192, identifier:add; 193, argument_list; 193, 194; 193, 223; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:np; 197, identifier:add; 198, argument_list; 198, 199; 198, 210; 199, binary_operator:*; 199, 200; 199, 209; 200, parenthesized_expression; 200, 201; 201, binary_operator:-; 201, 202; 201, 203; 202, float:1.0; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:np; 206, identifier:cos; 207, argument_list; 207, 208; 208, identifier:theta; 209, identifier:ax_oprod; 210, binary_operator:*; 210, 211; 210, 217; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:np; 214, identifier:cos; 215, argument_list; 215, 216; 216, identifier:theta; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:np; 220, identifier:eye; 221, argument_list; 221, 222; 222, integer:3; 223, binary_operator:*; 223, 224; 223, 230; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:np; 227, identifier:sin; 228, argument_list; 228, 229; 229, identifier:theta; 230, identifier:mod_lc; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:rot_mtx; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:spla; 237, identifier:block_diag; 238, argument_list; 238, 239; 239, list_splat; 239, 240; 240, list_comprehension; 240, 241; 240, 242; 241, identifier:base_mtx; 242, for_in_clause; 242, 243; 242, 244; 243, identifier:i; 244, call; 244, 245; 244, 246; 245, identifier:range; 246, argument_list; 246, 247; 247, identifier:reps; 248, return_statement; 248, 249; 249, identifier:rot_mtx
def mtx_rot(ax, theta, reps=1): import numpy as np from scipy import linalg as spla from ..const import PRM if spla.norm(ax) < PRM.ZERO_VEC_TOL: raise ValueError("Norm of 'ax' is too small.") ax = make_nd_vec(ax, nd=3, t=np.float64, norm=True) if not np.isscalar(reps): raise ValueError("'reps' must be scalar.") if not np.issubdtype(type(reps), int): raise ValueError("'reps' must be an integer.") if not reps > 0: raise ValueError("'reps' must be a positive integer.") if not np.isscalar(theta): raise ValueError("'theta' must be scalar.") mod_lc = np.array([ [0, -ax[2], ax[1]], [ax[2], 0, -ax[0]], [-ax[1], ax[0], 0] ], dtype=np.float64) ax_oprod = np.dot(ax.reshape((3,1)), ax.reshape((1,3))) base_mtx = np.add( np.add( (1.0 - np.cos(theta)) * ax_oprod, np.cos(theta) * np.eye(3) ), np.sin(theta) * mod_lc ) rot_mtx= spla.block_diag(*[base_mtx for i in range(reps)]) return rot_mtx
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:ffd; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:items; 5, identifier:targets; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 22; 8, 40; 8, 53; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:sizes; 12, call; 12, 13; 12, 14; 13, identifier:zip; 14, argument_list; 14, 15; 14, 16; 15, identifier:items; 16, call; 16, 17; 16, 18; 17, identifier:weight; 18, argument_list; 18, 19; 18, 20; 19, identifier:items; 20, dictionary_splat; 20, 21; 21, identifier:kwargs; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:sizes; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 27, 29; 27, 37; 28, identifier:sizes; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:key; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:operator; 34, identifier:itemgetter; 35, argument_list; 35, 36; 36, integer:1; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:reverse; 39, True; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:items; 43, call; 43, 44; 43, 45; 44, identifier:map; 45, argument_list; 45, 46; 45, 52; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:operator; 49, identifier:itemgetter; 50, argument_list; 50, 51; 51, integer:0; 52, identifier:sizes; 53, return_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:ff; 56, argument_list; 56, 57; 56, 58; 57, identifier:items; 58, identifier:targets
def ffd(items, targets, **kwargs): sizes = zip(items, weight(items, **kwargs)) sizes = sorted(sizes, key=operator.itemgetter(1), reverse=True) items = map(operator.itemgetter(0), sizes) return ff(items, targets)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:match_variant_sequence_to_reference_context; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:variant_sequence; 5, identifier:reference_context; 6, identifier:min_transcript_prefix_length; 7, identifier:max_transcript_mismatches; 8, default_parameter; 8, 9; 8, 10; 9, identifier:include_mismatches_after_variant; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:max_trimming_attempts; 13, integer:2; 14, block; 14, 15; 14, 19; 14, 197; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:variant_sequence_in_reading_frame; 18, None; 19, for_statement; 19, 20; 19, 21; 19, 27; 20, identifier:i; 21, call; 21, 22; 21, 23; 22, identifier:range; 23, argument_list; 23, 24; 24, binary_operator:+; 24, 25; 24, 26; 25, identifier:max_trimming_attempts; 26, integer:1; 27, block; 27, 28; 27, 63; 27, 80; 27, 95; 27, 102; 27, 109; 27, 116; 27, 131; 27, 135; 27, 142; 27, 149; 27, 168; 27, 176; 27, 186; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:variant_sequence_too_short; 31, parenthesized_expression; 31, 32; 32, boolean_operator:or; 32, 33; 32, 48; 33, parenthesized_expression; 33, 34; 34, boolean_operator:and; 34, 35; 34, 40; 35, comparison_operator:==; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:reference_context; 38, identifier:strand; 39, string:"+"; 40, comparison_operator:<; 40, 41; 40, 47; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:variant_sequence; 46, identifier:prefix; 47, identifier:min_transcript_prefix_length; 48, parenthesized_expression; 48, 49; 49, boolean_operator:and; 49, 50; 49, 55; 50, comparison_operator:==; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:reference_context; 53, identifier:strand; 54, string:"-"; 55, comparison_operator:<; 55, 56; 55, 62; 56, call; 56, 57; 56, 58; 57, identifier:len; 58, argument_list; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:variant_sequence; 61, identifier:suffix; 62, identifier:min_transcript_prefix_length; 63, if_statement; 63, 64; 63, 65; 64, identifier:variant_sequence_too_short; 65, block; 65, 66; 65, 78; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:logger; 70, identifier:info; 71, argument_list; 71, 72; 71, 73; 71, 74; 71, 75; 72, string:"Variant sequence %s shorter than min allowed %d (iter=%d)"; 73, identifier:variant_sequence; 74, identifier:min_transcript_prefix_length; 75, binary_operator:+; 75, 76; 75, 77; 76, identifier:i; 77, integer:1; 78, return_statement; 78, 79; 79, None; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 81, 84; 82, identifier:variant_sequence_in_reading_frame; 83, line_continuation:\; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:VariantSequenceInReadingFrame; 87, identifier:from_variant_sequence_and_reference_context; 88, argument_list; 88, 89; 88, 92; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:variant_sequence; 91, identifier:variant_sequence; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:reference_context; 94, identifier:reference_context; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:is; 96, 97; 96, 98; 97, identifier:variant_sequence_in_reading_frame; 98, None; 99, block; 99, 100; 100, return_statement; 100, 101; 101, None; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:n_mismatch_before_variant; 105, parenthesized_expression; 105, 106; 106, attribute; 106, 107; 106, 108; 107, identifier:variant_sequence_in_reading_frame; 108, identifier:number_mismatches_before_variant; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:n_mismatch_after_variant; 112, parenthesized_expression; 112, 113; 113, attribute; 113, 114; 113, 115; 114, identifier:variant_sequence_in_reading_frame; 115, identifier:number_mismatches_after_variant; 116, ERROR; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:logger; 120, identifier:info; 121, argument_list; 121, 122; 121, 124; 121, 127; 121, 130; 122, ERROR; 122, 123; 123, identifier:Iter; 124, binary_operator:+; 124, 125; 124, 126; 125, identifier:i; 126, integer:1; 127, binary_operator:+; 127, 128; 127, 129; 128, identifier:max_trimming_attempts; 129, integer:1; 130, identifier:variant_sequence_in_reading_frame; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:total_mismatches; 134, identifier:n_mismatch_before_variant; 135, if_statement; 135, 136; 135, 137; 136, identifier:include_mismatches_after_variant; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, augmented_assignment:+=; 139, 140; 139, 141; 140, identifier:total_mismatches; 141, identifier:n_mismatch_after_variant; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:<=; 143, 144; 143, 145; 144, identifier:total_mismatches; 145, identifier:max_transcript_mismatches; 146, block; 146, 147; 147, return_statement; 147, 148; 148, identifier:variant_sequence_in_reading_frame; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:logger; 153, identifier:info; 154, argument_list; 154, 155; 154, 159; 154, 160; 154, 161; 154, 162; 154, 165; 155, parenthesized_expression; 155, 156; 156, concatenated_string; 156, 157; 156, 158; 157, string:"Too many mismatches (%d) between variant sequence %s and "; 158, string:"reference context %s (attempt=%d/%d)"; 159, identifier:n_mismatch_before_variant; 160, identifier:variant_sequence; 161, identifier:reference_context; 162, binary_operator:+; 162, 163; 162, 164; 163, identifier:i; 164, integer:1; 165, binary_operator:+; 165, 166; 165, 167; 166, identifier:max_trimming_attempts; 167, integer:1; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:current_min_coverage; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:variant_sequence; 174, identifier:min_coverage; 175, argument_list; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:logger; 180, identifier:info; 181, argument_list; 181, 182; 181, 183; 182, string:"Trimming to subsequence covered by at least %d reads"; 183, binary_operator:+; 183, 184; 183, 185; 184, identifier:current_min_coverage; 185, integer:1; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:variant_sequence; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:variant_sequence; 192, identifier:trim_by_coverage; 193, argument_list; 193, 194; 194, binary_operator:+; 194, 195; 194, 196; 195, identifier:current_min_coverage; 196, integer:1; 197, return_statement; 197, 198; 198, None
def match_variant_sequence_to_reference_context( variant_sequence, reference_context, min_transcript_prefix_length, max_transcript_mismatches, include_mismatches_after_variant=False, max_trimming_attempts=2): variant_sequence_in_reading_frame = None for i in range(max_trimming_attempts + 1): variant_sequence_too_short = ( (reference_context.strand == "+" and len(variant_sequence.prefix) < min_transcript_prefix_length) or (reference_context.strand == "-" and len(variant_sequence.suffix) < min_transcript_prefix_length) ) if variant_sequence_too_short: logger.info( "Variant sequence %s shorter than min allowed %d (iter=%d)", variant_sequence, min_transcript_prefix_length, i + 1) return None variant_sequence_in_reading_frame = \ VariantSequenceInReadingFrame.from_variant_sequence_and_reference_context( variant_sequence=variant_sequence, reference_context=reference_context) if variant_sequence_in_reading_frame is None: return None n_mismatch_before_variant = ( variant_sequence_in_reading_frame.number_mismatches_before_variant) n_mismatch_after_variant = ( variant_sequence_in_reading_frame.number_mismatches_after_variant) logger.info("Iter i + 1, max_trimming_attempts + 1, variant_sequence_in_reading_frame)) total_mismatches = n_mismatch_before_variant if include_mismatches_after_variant: total_mismatches += n_mismatch_after_variant if total_mismatches <= max_transcript_mismatches: return variant_sequence_in_reading_frame logger.info( ("Too many mismatches (%d) between variant sequence %s and " "reference context %s (attempt=%d/%d)"), n_mismatch_before_variant, variant_sequence, reference_context, i + 1, max_trimming_attempts + 1) current_min_coverage = variant_sequence.min_coverage() logger.info( "Trimming to subsequence covered by at least %d reads", current_min_coverage + 1) variant_sequence = variant_sequence.trim_by_coverage( current_min_coverage + 1) return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:predicted_effects_for_variant; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:variant; 5, default_parameter; 5, 6; 5, 7; 6, identifier:transcript_id_whitelist; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:only_coding_changes; 10, True; 11, block; 11, 12; 11, 16; 11, 79; 11, 86; 11, 93; 11, 104; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:effects; 15, list:[]; 16, for_statement; 16, 17; 16, 18; 16, 21; 17, identifier:transcript; 18, attribute; 18, 19; 18, 20; 19, identifier:variant; 20, identifier:transcripts; 21, block; 21, 22; 21, 42; 21, 67; 22, if_statement; 22, 23; 22, 29; 23, boolean_operator:and; 23, 24; 23, 25; 24, identifier:only_coding_changes; 25, not_operator; 25, 26; 26, attribute; 26, 27; 26, 28; 27, identifier:transcript; 28, identifier:complete; 29, block; 29, 30; 29, 41; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:logger; 34, identifier:info; 35, argument_list; 35, 36; 35, 37; 35, 40; 36, string:"Skipping transcript %s for variant %s because it's incomplete"; 37, attribute; 37, 38; 37, 39; 38, identifier:transcript; 39, identifier:name; 40, identifier:variant; 41, continue_statement; 42, if_statement; 42, 43; 42, 50; 43, boolean_operator:and; 43, 44; 43, 45; 44, identifier:transcript_id_whitelist; 45, comparison_operator:not; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:transcript; 48, identifier:id; 49, identifier:transcript_id_whitelist; 50, block; 50, 51; 50, 66; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:logger; 55, identifier:info; 56, argument_list; 56, 57; 56, 58; 56, 61; 56, 62; 57, string:"Skipping transcript %s for variant %s because it's not one of %d allowed"; 58, attribute; 58, 59; 58, 60; 59, identifier:transcript; 60, identifier:name; 61, identifier:variant; 62, call; 62, 63; 62, 64; 63, identifier:len; 64, argument_list; 64, 65; 65, identifier:transcript_id_whitelist; 66, continue_statement; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:effects; 71, identifier:append; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:variant; 76, identifier:effect_on_transcript; 77, argument_list; 77, 78; 78, identifier:transcript; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:effects; 82, call; 82, 83; 82, 84; 83, identifier:EffectCollection; 84, argument_list; 84, 85; 85, identifier:effects; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:n_total_effects; 89, call; 89, 90; 89, 91; 90, identifier:len; 91, argument_list; 91, 92; 92, identifier:effects; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:logger; 97, identifier:info; 98, argument_list; 98, 99; 99, binary_operator:%; 99, 100; 99, 101; 100, string:"Predicted total %d effects for variant %s"; 101, tuple; 101, 102; 101, 103; 102, identifier:n_total_effects; 103, identifier:variant; 104, if_statement; 104, 105; 104, 107; 104, 110; 105, not_operator; 105, 106; 106, identifier:only_coding_changes; 107, block; 107, 108; 108, return_statement; 108, 109; 109, identifier:effects; 110, else_clause; 110, 111; 111, block; 111, 112; 111, 120; 111, 134; 111, 148; 111, 161; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:nonsynonymous_coding_effects; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:effects; 118, identifier:drop_silent_and_noncoding; 119, argument_list; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:logger; 124, identifier:info; 125, argument_list; 125, 126; 125, 127; 125, 131; 125, 132; 125, 133; 126, string:"Keeping %d/%d effects which affect protein coding sequence for %s: %s"; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, identifier:nonsynonymous_coding_effects; 131, identifier:n_total_effects; 132, identifier:variant; 133, identifier:nonsynonymous_coding_effects; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:usable_effects; 137, list_comprehension; 137, 138; 137, 139; 137, 142; 138, identifier:effect; 139, for_in_clause; 139, 140; 139, 141; 140, identifier:effect; 141, identifier:nonsynonymous_coding_effects; 142, if_clause; 142, 143; 143, comparison_operator:is; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:effect; 146, identifier:mutant_protein_sequence; 147, None; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:logger; 152, identifier:info; 153, argument_list; 153, 154; 153, 155; 153, 159; 153, 160; 154, string:"Keeping %d effects with predictable AA sequences for %s: %s"; 155, call; 155, 156; 155, 157; 156, identifier:len; 157, argument_list; 157, 158; 158, identifier:usable_effects; 159, identifier:variant; 160, identifier:usable_effects; 161, return_statement; 161, 162; 162, identifier:usable_effects
def predicted_effects_for_variant( variant, transcript_id_whitelist=None, only_coding_changes=True): effects = [] for transcript in variant.transcripts: if only_coding_changes and not transcript.complete: logger.info( "Skipping transcript %s for variant %s because it's incomplete", transcript.name, variant) continue if transcript_id_whitelist and transcript.id not in transcript_id_whitelist: logger.info( "Skipping transcript %s for variant %s because it's not one of %d allowed", transcript.name, variant, len(transcript_id_whitelist)) continue effects.append(variant.effect_on_transcript(transcript)) effects = EffectCollection(effects) n_total_effects = len(effects) logger.info("Predicted total %d effects for variant %s" % ( n_total_effects, variant)) if not only_coding_changes: return effects else: nonsynonymous_coding_effects = effects.drop_silent_and_noncoding() logger.info( "Keeping %d/%d effects which affect protein coding sequence for %s: %s", len(nonsynonymous_coding_effects), n_total_effects, variant, nonsynonymous_coding_effects) usable_effects = [ effect for effect in nonsynonymous_coding_effects if effect.mutant_protein_sequence is not None ] logger.info( "Keeping %d effects with predictable AA sequences for %s: %s", len(usable_effects), variant, usable_effects) return usable_effects
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_protein_sequences; 3, parameters; 3, 4; 4, identifier:protein_sequences; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:list; 9, argument_list; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:sorted; 12, argument_list; 12, 13; 12, 14; 12, 19; 13, identifier:protein_sequences; 14, keyword_argument; 14, 15; 14, 16; 15, identifier:key; 16, attribute; 16, 17; 16, 18; 17, identifier:ProteinSequence; 18, identifier:ascending_sort_key; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:reverse; 21, True
def sort_protein_sequences(protein_sequences): return list( sorted( protein_sequences, key=ProteinSequence.ascending_sort_key, reverse=True))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:reads_generator_to_protein_sequences_generator; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:variant_and_overlapping_reads_generator; 5, default_parameter; 5, 6; 5, 7; 6, identifier:transcript_id_whitelist; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:protein_sequence_length; 10, identifier:PROTEIN_SEQUENCE_LENGTH; 11, default_parameter; 11, 12; 11, 13; 12, identifier:min_alt_rna_reads; 13, identifier:MIN_ALT_RNA_READS; 14, default_parameter; 14, 15; 14, 16; 15, identifier:min_variant_sequence_coverage; 16, identifier:MIN_VARIANT_SEQUENCE_COVERAGE; 17, default_parameter; 17, 18; 17, 19; 18, identifier:min_transcript_prefix_length; 19, identifier:MIN_TRANSCRIPT_PREFIX_LENGTH; 20, default_parameter; 20, 21; 20, 22; 21, identifier:max_transcript_mismatches; 22, identifier:MAX_REFERENCE_TRANSCRIPT_MISMATCHES; 23, default_parameter; 23, 24; 23, 25; 24, identifier:include_mismatches_after_variant; 25, identifier:INCLUDE_MISMATCHES_AFTER_VARIANT; 26, default_parameter; 26, 27; 26, 28; 27, identifier:max_protein_sequences_per_variant; 28, identifier:MAX_PROTEIN_SEQUENCES_PER_VARIANT; 29, default_parameter; 29, 30; 29, 31; 30, identifier:variant_sequence_assembly; 31, identifier:VARIANT_SEQUENCE_ASSEMBLY; 32, block; 32, 33; 33, for_statement; 33, 34; 33, 37; 33, 38; 34, tuple_pattern; 34, 35; 34, 36; 35, identifier:variant; 36, identifier:overlapping_reads; 37, identifier:variant_and_overlapping_reads_generator; 38, block; 38, 39; 38, 55; 38, 65; 38, 72; 38, 79; 38, 89; 38, 99; 38, 135; 38, 139; 38, 241; 38, 248; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:overlapping_transcript_ids; 42, list_comprehension; 42, 43; 42, 46; 42, 51; 43, attribute; 43, 44; 43, 45; 44, identifier:t; 45, identifier:id; 46, for_in_clause; 46, 47; 46, 48; 47, identifier:t; 48, attribute; 48, 49; 48, 50; 49, identifier:variant; 50, identifier:transcripts; 51, if_clause; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:t; 54, identifier:is_protein_coding; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 61; 57, pattern_list; 57, 58; 57, 59; 57, 60; 58, identifier:_; 59, identifier:ref; 60, identifier:alt; 61, call; 61, 62; 61, 63; 62, identifier:trim_variant; 63, argument_list; 63, 64; 64, identifier:variant; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:overlapping_reads; 68, call; 68, 69; 68, 70; 69, identifier:list; 70, argument_list; 70, 71; 71, identifier:overlapping_reads; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:reads_grouped_by_allele; 75, call; 75, 76; 75, 77; 76, identifier:group_reads_by_allele; 77, argument_list; 77, 78; 78, identifier:overlapping_reads; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:ref_reads; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:reads_grouped_by_allele; 85, identifier:get; 86, argument_list; 86, 87; 86, 88; 87, identifier:ref; 88, list:[]; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:alt_reads; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:reads_grouped_by_allele; 95, identifier:get; 96, argument_list; 96, 97; 96, 98; 97, identifier:alt; 98, list:[]; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:translations; 102, call; 102, 103; 102, 104; 103, identifier:translate_variant_reads; 104, argument_list; 104, 105; 104, 108; 104, 111; 104, 114; 104, 117; 104, 120; 104, 123; 104, 126; 104, 129; 104, 132; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:variant; 107, identifier:variant; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:variant_reads; 110, identifier:alt_reads; 111, keyword_argument; 111, 112; 111, 113; 112, identifier:transcript_id_whitelist; 113, identifier:transcript_id_whitelist; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:protein_sequence_length; 116, identifier:protein_sequence_length; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:min_alt_rna_reads; 119, identifier:min_alt_rna_reads; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:min_variant_sequence_coverage; 122, identifier:min_variant_sequence_coverage; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:min_transcript_prefix_length; 125, identifier:min_transcript_prefix_length; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:max_transcript_mismatches; 128, identifier:max_transcript_mismatches; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:include_mismatches_after_variant; 131, identifier:include_mismatches_after_variant; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:variant_sequence_assembly; 134, identifier:variant_sequence_assembly; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:protein_sequences; 138, list:[]; 139, for_statement; 139, 140; 139, 143; 139, 156; 140, tuple_pattern; 140, 141; 140, 142; 141, identifier:key; 142, identifier:equivalent_translations; 143, call; 143, 144; 143, 155; 144, attribute; 144, 145; 144, 154; 145, call; 145, 146; 145, 147; 146, identifier:groupby; 147, argument_list; 147, 148; 147, 149; 148, identifier:translations; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:key_fn; 151, attribute; 151, 152; 151, 153; 152, identifier:Translation; 153, identifier:as_translation_key; 154, identifier:items; 155, argument_list; 156, block; 156, 157; 156, 170; 156, 183; 156, 221; 156, 234; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 163; 158, 164; 159, pattern_list; 159, 160; 159, 161; 159, 162; 160, identifier:alt_reads_supporting_protein_sequence; 161, identifier:group_transcript_ids; 162, identifier:group_gene_names; 163, line_continuation:\; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:ProteinSequence; 167, identifier:_summarize_translations; 168, argument_list; 168, 169; 169, identifier:equivalent_translations; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:logger; 174, identifier:info; 175, argument_list; 175, 176; 175, 177; 175, 178; 175, 182; 176, string:"%s: %s alt reads supporting protein sequence (gene names = %s)"; 177, identifier:key; 178, call; 178, 179; 178, 180; 179, identifier:len; 180, argument_list; 180, 181; 181, identifier:alt_reads_supporting_protein_sequence; 182, identifier:group_gene_names; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:protein_sequence; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:ProteinSequence; 189, identifier:from_translation_key; 190, argument_list; 190, 191; 190, 194; 190, 197; 190, 200; 190, 203; 190, 206; 190, 209; 190, 212; 190, 215; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:translation_key; 193, identifier:key; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:translations; 196, identifier:equivalent_translations; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:overlapping_reads; 199, identifier:overlapping_reads; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:alt_reads; 202, identifier:alt_reads; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:ref_reads; 205, identifier:ref_reads; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:alt_reads_supporting_protein_sequence; 208, identifier:alt_reads_supporting_protein_sequence; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:transcripts_supporting_protein_sequence; 211, identifier:group_transcript_ids; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:transcripts_overlapping_variant; 214, identifier:overlapping_transcript_ids; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:gene; 217, call; 217, 218; 217, 219; 218, identifier:list; 219, argument_list; 219, 220; 220, identifier:group_gene_names; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:logger; 225, identifier:info; 226, argument_list; 226, 227; 227, binary_operator:%; 227, 228; 227, 229; 228, string:"%s: protein sequence = %s"; 229, tuple; 229, 230; 229, 231; 230, identifier:key; 231, attribute; 231, 232; 231, 233; 232, identifier:protein_sequence; 233, identifier:amino_acids; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:protein_sequences; 238, identifier:append; 239, argument_list; 239, 240; 240, identifier:protein_sequence; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:protein_sequences; 244, call; 244, 245; 244, 246; 245, identifier:sort_protein_sequences; 246, argument_list; 246, 247; 247, identifier:protein_sequences; 248, expression_statement; 248, 249; 249, yield; 249, 250; 250, expression_list; 250, 251; 250, 252; 251, identifier:variant; 252, subscript; 252, 253; 252, 254; 253, identifier:protein_sequences; 254, slice; 254, 255; 254, 256; 255, colon; 256, identifier:max_protein_sequences_per_variant
def reads_generator_to_protein_sequences_generator( variant_and_overlapping_reads_generator, transcript_id_whitelist=None, protein_sequence_length=PROTEIN_SEQUENCE_LENGTH, min_alt_rna_reads=MIN_ALT_RNA_READS, min_variant_sequence_coverage=MIN_VARIANT_SEQUENCE_COVERAGE, min_transcript_prefix_length=MIN_TRANSCRIPT_PREFIX_LENGTH, max_transcript_mismatches=MAX_REFERENCE_TRANSCRIPT_MISMATCHES, include_mismatches_after_variant=INCLUDE_MISMATCHES_AFTER_VARIANT, max_protein_sequences_per_variant=MAX_PROTEIN_SEQUENCES_PER_VARIANT, variant_sequence_assembly=VARIANT_SEQUENCE_ASSEMBLY): for (variant, overlapping_reads) in variant_and_overlapping_reads_generator: overlapping_transcript_ids = [ t.id for t in variant.transcripts if t.is_protein_coding ] _, ref, alt = trim_variant(variant) overlapping_reads = list(overlapping_reads) reads_grouped_by_allele = group_reads_by_allele(overlapping_reads) ref_reads = reads_grouped_by_allele.get(ref, []) alt_reads = reads_grouped_by_allele.get(alt, []) translations = translate_variant_reads( variant=variant, variant_reads=alt_reads, transcript_id_whitelist=transcript_id_whitelist, protein_sequence_length=protein_sequence_length, min_alt_rna_reads=min_alt_rna_reads, min_variant_sequence_coverage=min_variant_sequence_coverage, min_transcript_prefix_length=min_transcript_prefix_length, max_transcript_mismatches=max_transcript_mismatches, include_mismatches_after_variant=include_mismatches_after_variant, variant_sequence_assembly=variant_sequence_assembly) protein_sequences = [] for (key, equivalent_translations) in groupby( translations, key_fn=Translation.as_translation_key).items(): alt_reads_supporting_protein_sequence, group_transcript_ids, group_gene_names = \ ProteinSequence._summarize_translations(equivalent_translations) logger.info( "%s: %s alt reads supporting protein sequence (gene names = %s)", key, len(alt_reads_supporting_protein_sequence), group_gene_names) protein_sequence = ProteinSequence.from_translation_key( translation_key=key, translations=equivalent_translations, overlapping_reads=overlapping_reads, alt_reads=alt_reads, ref_reads=ref_reads, alt_reads_supporting_protein_sequence=alt_reads_supporting_protein_sequence, transcripts_supporting_protein_sequence=group_transcript_ids, transcripts_overlapping_variant=overlapping_transcript_ids, gene=list(group_gene_names)) logger.info("%s: protein sequence = %s" % (key, protein_sequence.amino_acids)) protein_sequences.append(protein_sequence) protein_sequences = sort_protein_sequences(protein_sequences) yield variant, protein_sequences[:max_protein_sequences_per_variant]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:from_variant_and_transcript; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:cls; 5, identifier:variant; 6, identifier:transcript; 7, identifier:context_size; 8, block; 8, 9; 8, 28; 8, 47; 8, 66; 8, 83; 8, 101; 9, if_statement; 9, 10; 9, 14; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:transcript; 13, identifier:contains_start_codon; 14, block; 14, 15; 14, 26; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:logger; 19, identifier:info; 20, argument_list; 20, 21; 20, 22; 20, 25; 21, string:"Expected transcript %s for variant %s to have start codon"; 22, attribute; 22, 23; 22, 24; 23, identifier:transcript; 24, identifier:name; 25, identifier:variant; 26, return_statement; 26, 27; 27, None; 28, if_statement; 28, 29; 28, 33; 29, not_operator; 29, 30; 30, attribute; 30, 31; 30, 32; 31, identifier:transcript; 32, identifier:contains_stop_codon; 33, block; 33, 34; 33, 45; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:logger; 38, identifier:info; 39, argument_list; 39, 40; 39, 41; 39, 44; 40, string:"Expected transcript %s for variant %s to have stop codon"; 41, attribute; 41, 42; 41, 43; 42, identifier:transcript; 43, identifier:name; 44, identifier:variant; 45, return_statement; 45, 46; 46, None; 47, if_statement; 47, 48; 47, 52; 48, not_operator; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:transcript; 51, identifier:protein_sequence; 52, block; 52, 53; 52, 64; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:logger; 57, identifier:info; 58, argument_list; 58, 59; 58, 60; 58, 63; 59, string:"Expected transript %s for variant %s to have protein sequence"; 60, attribute; 60, 61; 60, 62; 61, identifier:transcript; 62, identifier:name; 63, identifier:variant; 64, return_statement; 64, 65; 65, None; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:sequence_key; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:ReferenceSequenceKey; 72, identifier:from_variant_and_transcript; 73, argument_list; 73, 74; 73, 77; 73, 80; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:variant; 76, identifier:variant; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:transcript; 79, identifier:transcript; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:context_size; 82, identifier:context_size; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:is; 84, 85; 84, 86; 85, identifier:sequence_key; 86, None; 87, block; 87, 88; 87, 99; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:logger; 92, identifier:info; 93, argument_list; 93, 94; 93, 95; 93, 96; 94, string:"No sequence key for variant %s on transcript %s"; 95, identifier:variant; 96, attribute; 96, 97; 96, 98; 97, identifier:transcript; 98, identifier:name; 99, return_statement; 99, 100; 100, None; 101, return_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:cls; 105, identifier:from_variant_and_transcript_and_sequence_key; 106, argument_list; 106, 107; 106, 110; 106, 113; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:variant; 109, identifier:variant; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:transcript; 112, identifier:transcript; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:sequence_key; 115, identifier:sequence_key
def from_variant_and_transcript( cls, variant, transcript, context_size): if not transcript.contains_start_codon: logger.info( "Expected transcript %s for variant %s to have start codon", transcript.name, variant) return None if not transcript.contains_stop_codon: logger.info( "Expected transcript %s for variant %s to have stop codon", transcript.name, variant) return None if not transcript.protein_sequence: logger.info( "Expected transript %s for variant %s to have protein sequence", transcript.name, variant) return None sequence_key = ReferenceSequenceKey.from_variant_and_transcript( variant=variant, transcript=transcript, context_size=context_size) if sequence_key is None: logger.info( "No sequence key for variant %s on transcript %s", variant, transcript.name) return None return cls.from_variant_and_transcript_and_sequence_key( variant=variant, transcript=transcript, sequence_key=sequence_key)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:info; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:package; 5, identifier:long_description; 6, identifier:classifiers; 7, identifier:license; 8, block; 8, 9; 8, 17; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:client; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:requests; 15, identifier:Session; 16, argument_list; 17, for_statement; 17, 18; 17, 19; 17, 20; 18, identifier:name_or_url; 19, identifier:package; 20, block; 20, 21; 20, 29; 20, 54; 20, 90; 20, 95; 20, 107; 20, 111; 20, 125; 20, 139; 20, 143; 20, 148; 20, 152; 20, 164; 20, 180; 20, 196; 20, 208; 20, 217; 20, 233; 20, 249; 20, 253; 20, 267; 20, 286; 20, 305; 20, 334; 20, 385; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:package; 24, call; 24, 25; 24, 26; 25, identifier:get_package; 26, argument_list; 26, 27; 26, 28; 27, identifier:name_or_url; 28, identifier:client; 29, if_statement; 29, 30; 29, 32; 30, not_operator; 30, 31; 31, identifier:package; 32, block; 32, 33; 32, 53; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:secho; 36, argument_list; 36, 37; 36, 45; 36, 48; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, string:u'Invalid name or URL: "{name}"'; 40, identifier:format; 41, argument_list; 41, 42; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:name; 44, identifier:name_or_url; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:fg; 47, string:'red'; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:file; 50, attribute; 50, 51; 50, 52; 51, identifier:sys; 52, identifier:stderr; 53, continue_statement; 54, try_statement; 54, 55; 54, 64; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:info; 59, subscript; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:package; 62, identifier:data; 63, string:'info'; 64, except_clause; 64, 65; 64, 66; 65, identifier:NotFoundError; 66, block; 66, 67; 66, 89; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:secho; 70, argument_list; 70, 71; 70, 81; 70, 84; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, concatenated_string; 73, 74; 73, 75; 74, string:u'No versions found for "{0}". '; 75, string:u'Skipping. . .'; 76, identifier:format; 77, argument_list; 77, 78; 78, attribute; 78, 79; 78, 80; 79, identifier:package; 80, identifier:name; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:fg; 83, string:'red'; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:file; 86, attribute; 86, 87; 86, 88; 87, identifier:sys; 88, identifier:stderr; 89, continue_statement; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:echo_header; 93, argument_list; 93, 94; 94, identifier:name_or_url; 95, if_statement; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:package; 98, identifier:summary; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:echo; 103, argument_list; 103, 104; 104, attribute; 104, 105; 104, 106; 105, identifier:package; 106, identifier:summary; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:echo; 110, argument_list; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:echo; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, string:'Latest release: {version:12}'; 118, identifier:format; 119, argument_list; 119, 120; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:version; 122, subscript; 122, 123; 122, 124; 123, identifier:info; 124, string:'version'; 125, if_statement; 125, 126; 125, 127; 126, identifier:long_description; 127, block; 127, 128; 127, 132; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:echo; 131, argument_list; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:echo; 135, argument_list; 135, 136; 136, attribute; 136, 137; 136, 138; 137, identifier:package; 138, identifier:description; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:echo; 142, argument_list; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:echo_download_summary; 146, argument_list; 146, 147; 147, identifier:package; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 151; 150, identifier:echo; 151, argument_list; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, pattern_list; 154, 155; 154, 156; 155, identifier:author; 156, identifier:author_email; 157, expression_list; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:package; 160, identifier:author; 161, attribute; 161, 162; 161, 163; 162, identifier:package; 163, identifier:author_email; 164, if_statement; 164, 165; 164, 166; 165, identifier:author; 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:u'Author: {author:12}'; 174, identifier:format; 175, argument_list; 175, 176; 176, dictionary_splat; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:locals; 179, argument_list; 180, if_statement; 180, 181; 180, 182; 181, identifier:author_email; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:echo; 186, argument_list; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, string:u'Author email: {author_email:12}'; 190, identifier:format; 191, argument_list; 191, 192; 192, dictionary_splat; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:locals; 195, argument_list; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 201; 198, pattern_list; 198, 199; 198, 200; 199, identifier:maintainer; 200, identifier:maintainer_email; 201, tuple; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:package; 204, identifier:maintainer; 205, attribute; 205, 206; 205, 207; 206, identifier:package; 207, identifier:maintainer_email; 208, if_statement; 208, 209; 208, 212; 209, boolean_operator:or; 209, 210; 209, 211; 210, identifier:maintainer; 211, identifier:maintainer_email; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 216; 215, identifier:echo; 216, argument_list; 217, if_statement; 217, 218; 217, 219; 218, identifier:maintainer; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:echo; 223, argument_list; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, string:u'Maintainer: {maintainer:12}'; 227, identifier:format; 228, argument_list; 228, 229; 229, dictionary_splat; 229, 230; 230, call; 230, 231; 230, 232; 231, identifier:locals; 232, argument_list; 233, if_statement; 233, 234; 233, 235; 234, identifier:maintainer_email; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 239; 238, identifier:echo; 239, argument_list; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, string:u'Maintainer email: {maintainer_email:12}'; 243, identifier:format; 244, argument_list; 244, 245; 245, dictionary_splat; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:locals; 248, argument_list; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 252; 251, identifier:echo; 252, argument_list; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 256; 255, identifier:echo; 256, argument_list; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, string:u'PyPI URL: {pypi_url:12}'; 260, identifier:format; 261, argument_list; 261, 262; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:pypi_url; 264, attribute; 264, 265; 264, 266; 265, identifier:package; 266, identifier:package_url; 267, if_statement; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:package; 270, identifier:home_page; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 275; 274, identifier:echo; 275, argument_list; 275, 276; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, string:u'Home Page: {home_page:12}'; 279, identifier:format; 280, argument_list; 280, 281; 281, keyword_argument; 281, 282; 281, 283; 282, identifier:home_page; 283, attribute; 283, 284; 283, 285; 284, identifier:package; 285, identifier:home_page; 286, if_statement; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:package; 289, identifier:docs_url; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:echo; 294, argument_list; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, string:u'Documentation: {docs_url:12}'; 298, identifier:format; 299, argument_list; 299, 300; 300, keyword_argument; 300, 301; 300, 302; 301, identifier:docs_url; 302, attribute; 302, 303; 302, 304; 303, identifier:package; 304, identifier:docs_url; 305, if_statement; 305, 306; 305, 307; 306, identifier:classifiers; 307, block; 307, 308; 307, 312; 307, 317; 308, expression_statement; 308, 309; 309, call; 309, 310; 309, 311; 310, identifier:echo; 311, argument_list; 312, expression_statement; 312, 313; 313, call; 313, 314; 313, 315; 314, identifier:echo; 315, argument_list; 315, 316; 316, string:u'Classifiers: '; 317, for_statement; 317, 318; 317, 319; 317, 326; 318, identifier:each; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:info; 322, identifier:get; 323, argument_list; 323, 324; 323, 325; 324, string:'classifiers'; 325, list:[]; 326, block; 326, 327; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:echo; 330, argument_list; 330, 331; 331, binary_operator:+; 331, 332; 331, 333; 332, string:'\t'; 333, identifier:each; 334, if_statement; 334, 335; 334, 340; 335, boolean_operator:and; 335, 336; 335, 337; 336, identifier:license; 337, attribute; 337, 338; 337, 339; 338, identifier:package; 339, identifier:license; 340, block; 340, 341; 340, 345; 340, 353; 340, 378; 341, expression_statement; 341, 342; 342, call; 342, 343; 342, 344; 343, identifier:echo; 344, argument_list; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 348; 347, identifier:echo; 348, argument_list; 348, 349; 348, 350; 349, string:u'License: '; 350, keyword_argument; 350, 351; 350, 352; 351, identifier:nl; 352, False; 353, if_statement; 353, 354; 353, 373; 354, boolean_operator:or; 354, 355; 354, 365; 355, comparison_operator:>=; 355, 356; 355, 364; 356, call; 356, 357; 356, 362; 357, attribute; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:package; 360, identifier:license; 361, identifier:find; 362, argument_list; 362, 363; 363, string:'\n'; 364, integer:0; 365, comparison_operator:>; 365, 366; 365, 372; 366, call; 366, 367; 366, 368; 367, identifier:len; 368, argument_list; 368, 369; 369, attribute; 369, 370; 369, 371; 370, identifier:package; 371, identifier:license; 372, integer:80; 373, block; 373, 374; 374, expression_statement; 374, 375; 375, call; 375, 376; 375, 377; 376, identifier:echo; 377, argument_list; 378, expression_statement; 378, 379; 379, call; 379, 380; 379, 381; 380, identifier:echo; 381, argument_list; 381, 382; 382, attribute; 382, 383; 382, 384; 383, identifier:package; 384, identifier:license; 385, expression_statement; 385, 386; 386, call; 386, 387; 386, 388; 387, identifier:echo; 388, argument_list
def info(package, long_description, classifiers, license): client = requests.Session() for name_or_url in package: package = get_package(name_or_url, client) if not package: secho(u'Invalid name or URL: "{name}"'.format(name=name_or_url), fg='red', file=sys.stderr) continue try: info = package.data['info'] except NotFoundError: secho(u'No versions found for "{0}". ' u'Skipping. . .'.format(package.name), fg='red', file=sys.stderr) continue echo_header(name_or_url) if package.summary: echo(package.summary) echo() echo('Latest release: {version:12}'.format(version=info['version'])) if long_description: echo() echo(package.description) echo() echo_download_summary(package) echo() author, author_email = package.author, package.author_email if author: echo(u'Author: {author:12}'.format(**locals())) if author_email: echo(u'Author email: {author_email:12}'.format(**locals())) maintainer, maintainer_email = (package.maintainer, package.maintainer_email) if maintainer or maintainer_email: echo() if maintainer: echo(u'Maintainer: {maintainer:12}'.format(**locals())) if maintainer_email: echo(u'Maintainer email: {maintainer_email:12}'.format(**locals())) echo() echo(u'PyPI URL: {pypi_url:12}'.format(pypi_url=package.package_url)) if package.home_page: echo(u'Home Page: {home_page:12}'.format( home_page=package.home_page)) if package.docs_url: echo(u'Documentation: {docs_url:12}'.format( docs_url=package.docs_url)) if classifiers: echo() echo(u'Classifiers: ') for each in info.get('classifiers', []): echo('\t' + each) if license and package.license: echo() echo(u'License: ', nl=False) if package.license.find('\n') >= 0 or len(package.license) > 80: echo() echo(package.license) echo()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:install_packages; 3, parameters; 3, 4; 3, 5; 4, identifier:packages; 5, default_parameter; 5, 6; 5, 7; 6, identifier:what_for; 7, string:'for a complete setup to work properly'; 8, block; 8, 9; 8, 11; 8, 15; 8, 22; 8, 31; 8, 193; 9, expression_statement; 9, 10; 10, string:'''Try to install .deb packages given by list. Return True, if packages could be installed or are installed already, or if they cannot be installed but the user gives feedback to continue. Else return False. '''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:res; 14, True; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:non_installed_packages; 18, call; 18, 19; 18, 20; 19, identifier:_non_installed; 20, argument_list; 20, 21; 21, identifier:packages; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:packages_str; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, string:' '; 28, identifier:join; 29, argument_list; 29, 30; 30, identifier:non_installed_packages; 31, if_statement; 31, 32; 31, 33; 32, identifier:non_installed_packages; 33, block; 33, 34; 33, 47; 33, 51; 33, 55; 33, 59; 33, 161; 33, 172; 34, with_statement; 34, 35; 34, 40; 35, with_clause; 35, 36; 36, with_item; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:quiet; 39, argument_list; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:dpkg; 44, call; 44, 45; 44, 46; 45, identifier:_has_dpkg; 46, argument_list; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:hint; 50, string:' (You may have to install them manually)'; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:do_install; 54, False; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:go_on; 58, True; 59, if_statement; 59, 60; 59, 61; 59, 119; 60, identifier:dpkg; 61, block; 61, 62; 62, if_statement; 62, 63; 62, 67; 62, 72; 63, call; 63, 64; 63, 65; 64, identifier:_is_sudoer; 65, argument_list; 65, 66; 66, string:'Want to install dpkg packages'; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:do_install; 71, True; 72, else_clause; 72, 73; 73, block; 73, 74; 73, 78; 73, 101; 73, 105; 74, expression_statement; 74, 75; 75, comparison_operator:is; 75, 76; 75, 77; 76, identifier:do_install; 77, False; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:info; 81, call; 81, 82; 81, 83; 82, identifier:yellow; 83, argument_list; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, string:' '; 87, identifier:join; 88, argument_list; 88, 89; 89, list:[ 'This deb packages are missing to be installed', flo("{what_for}: "), ', '.join(non_installed_packages), ]; 89, 90; 89, 91; 89, 95; 90, string:'This deb packages are missing to be installed'; 91, call; 91, 92; 91, 93; 92, identifier:flo; 93, argument_list; 93, 94; 94, string:"{what_for}: "; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, string:', '; 98, identifier:join; 99, argument_list; 99, 100; 100, identifier:non_installed_packages; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:question; 104, string:' Continue anyway?'; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:go_on; 108, call; 108, 109; 108, 110; 109, identifier:query_yes_no; 110, argument_list; 110, 111; 110, 116; 111, binary_operator:+; 111, 112; 111, 115; 112, binary_operator:+; 112, 113; 112, 114; 113, identifier:info; 114, identifier:hint; 115, identifier:question; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:default; 118, string:'no'; 119, else_clause; 119, 120; 120, block; 120, 121; 120, 125; 120, 147; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:do_install; 124, False; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:info; 128, call; 128, 129; 128, 130; 129, identifier:yellow; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, string:' '; 134, identifier:join; 135, argument_list; 135, 136; 136, list:[ flo('Required {what_for}: '), ', '.join(non_installed_packages), ]; 136, 137; 136, 141; 137, call; 137, 138; 137, 139; 138, identifier:flo; 139, argument_list; 139, 140; 140, string:'Required {what_for}: '; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, string:', '; 144, identifier:join; 145, argument_list; 145, 146; 146, identifier:non_installed_packages; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:go_on; 150, call; 150, 151; 150, 152; 151, identifier:query_yes_no; 152, argument_list; 152, 153; 152, 158; 153, binary_operator:+; 153, 154; 153, 157; 154, binary_operator:+; 154, 155; 154, 156; 155, identifier:info; 156, identifier:hint; 157, string:' Continue?'; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:default; 160, string:'yes'; 161, if_statement; 161, 162; 161, 164; 162, not_operator; 162, 163; 163, identifier:go_on; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:sys; 169, identifier:exit; 170, argument_list; 170, 171; 171, string:'Abort'; 172, if_statement; 172, 173; 172, 174; 173, identifier:do_install; 174, block; 174, 175; 174, 182; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:command; 178, call; 178, 179; 178, 180; 179, identifier:flo; 180, argument_list; 180, 181; 181, string:'sudo apt-get install {packages_str}'; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:res; 185, comparison_operator:==; 185, 186; 185, 192; 186, attribute; 186, 187; 186, 191; 187, call; 187, 188; 187, 189; 188, identifier:run; 189, argument_list; 189, 190; 190, identifier:command; 191, identifier:return_code; 192, integer:0; 193, return_statement; 193, 194; 194, identifier:res
def install_packages(packages, what_for='for a complete setup to work properly'): '''Try to install .deb packages given by list. Return True, if packages could be installed or are installed already, or if they cannot be installed but the user gives feedback to continue. Else return False. ''' res = True non_installed_packages = _non_installed(packages) packages_str = ' '.join(non_installed_packages) if non_installed_packages: with quiet(): dpkg = _has_dpkg() hint = ' (You may have to install them manually)' do_install = False go_on = True if dpkg: if _is_sudoer('Want to install dpkg packages'): do_install = True else: do_install is False info = yellow(' '.join([ 'This deb packages are missing to be installed', flo("{what_for}: "), ', '.join(non_installed_packages), ])) question = ' Continue anyway?' go_on = query_yes_no(info + hint + question, default='no') else: do_install = False info = yellow(' '.join([ flo('Required {what_for}: '), ', '.join(non_installed_packages), ])) go_on = query_yes_no(info + hint + ' Continue?', default='yes') if not go_on: sys.exit('Abort') if do_install: command = flo('sudo apt-get install {packages_str}') res = run(command).return_code == 0 return res
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:scan; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:host; 5, default_parameter; 5, 6; 5, 7; 6, identifier:port; 7, integer:80; 8, default_parameter; 8, 9; 8, 10; 9, identifier:url; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:https; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:timeout; 16, integer:1; 17, default_parameter; 17, 18; 17, 19; 18, identifier:max_size; 19, integer:65535; 20, block; 20, 21; 20, 27; 20, 33; 20, 40; 20, 60; 20, 73; 20, 89; 20, 131; 20, 143; 20, 157; 20, 164; 20, 175; 20, 187; 20, 238; 20, 365; 20, 371; 20, 383; 20, 414; 20, 425; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:starts; 24, call; 24, 25; 24, 26; 25, identifier:OrderedDict; 26, argument_list; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:ends; 30, call; 30, 31; 30, 32; 31, identifier:OrderedDict; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:port; 36, call; 36, 37; 36, 38; 37, identifier:int; 38, argument_list; 38, 39; 39, identifier:port; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:result; 43, call; 43, 44; 43, 45; 44, identifier:dict; 45, argument_list; 45, 46; 45, 49; 45, 52; 45, 55; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:host; 48, identifier:host; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:port; 51, identifier:port; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:state; 54, string:'closed'; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:durations; 57, call; 57, 58; 57, 59; 58, identifier:OrderedDict; 59, argument_list; 60, if_statement; 60, 61; 60, 62; 61, identifier:url; 62, block; 62, 63; 62, 67; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:timeout; 66, integer:1; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:result; 71, string:'code'; 72, None; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:starts; 77, string:'all'; 78, assignment; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:starts; 81, string:'dns'; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:datetime; 86, identifier:datetime; 87, identifier:now; 88, argument_list; 89, try_statement; 89, 90; 89, 118; 90, block; 90, 91; 90, 100; 90, 106; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:hostip; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:socket; 97, identifier:gethostbyname; 98, argument_list; 98, 99; 99, identifier:host; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:result; 104, string:'ip'; 105, identifier:hostip; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:ends; 110, string:'dns'; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:datetime; 115, identifier:datetime; 116, identifier:now; 117, argument_list; 118, except_clause; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:socket; 121, identifier:gaierror; 122, block; 122, 123; 123, raise_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:ScanFailed; 126, argument_list; 126, 127; 126, 128; 127, string:'DNS Lookup failed'; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:result; 130, identifier:result; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:starts; 135, string:'connect'; 136, call; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:datetime; 140, identifier:datetime; 141, identifier:now; 142, argument_list; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:network_socket; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:socket; 149, identifier:socket; 150, argument_list; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:socket; 153, identifier:AF_INET; 154, attribute; 154, 155; 154, 156; 155, identifier:socket; 156, identifier:SOCK_STREAM; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:network_socket; 161, identifier:settimeout; 162, argument_list; 162, 163; 163, identifier:timeout; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:result_connection; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:network_socket; 170, identifier:connect_ex; 171, argument_list; 171, 172; 172, tuple; 172, 173; 172, 174; 173, identifier:hostip; 174, identifier:port; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:ends; 179, string:'connect'; 180, call; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:datetime; 184, identifier:datetime; 185, identifier:now; 186, argument_list; 187, if_statement; 187, 188; 187, 189; 188, identifier:https; 189, block; 189, 190; 189, 202; 189, 226; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:starts; 194, string:'ssl'; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:datetime; 199, identifier:datetime; 200, identifier:now; 201, argument_list; 202, try_statement; 202, 203; 202, 213; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:network_socket; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:ssl; 210, identifier:wrap_socket; 211, argument_list; 211, 212; 212, identifier:network_socket; 213, except_clause; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:socket; 216, identifier:timeout; 217, block; 217, 218; 218, raise_statement; 218, 219; 219, call; 219, 220; 219, 221; 220, identifier:ScanFailed; 221, argument_list; 221, 222; 221, 223; 222, string:'SSL socket timeout'; 223, keyword_argument; 223, 224; 223, 225; 224, identifier:result; 225, identifier:result; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:ends; 230, string:'ssl'; 231, call; 231, 232; 231, 237; 232, attribute; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:datetime; 235, identifier:datetime; 236, identifier:now; 237, argument_list; 238, if_statement; 238, 239; 238, 244; 239, boolean_operator:and; 239, 240; 239, 243; 240, comparison_operator:==; 240, 241; 240, 242; 241, identifier:result_connection; 242, integer:0; 243, identifier:url; 244, block; 244, 245; 244, 257; 244, 275; 244, 297; 244, 306; 244, 318; 244, 325; 244, 353; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 250; 247, subscript; 247, 248; 247, 249; 248, identifier:starts; 249, string:'request'; 250, call; 250, 251; 250, 256; 251, attribute; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:datetime; 254, identifier:datetime; 255, identifier:now; 256, argument_list; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:network_socket; 261, identifier:send; 262, argument_list; 262, 263; 263, call; 263, 264; 263, 273; 264, attribute; 264, 265; 264, 272; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, string:"GET {0} HTTP/1.0\r\nHost: {1}\r\n\r\n"; 268, identifier:format; 269, argument_list; 269, 270; 269, 271; 270, identifier:url; 271, identifier:host; 272, identifier:encode; 273, argument_list; 273, 274; 274, string:'ascii'; 275, if_statement; 275, 276; 275, 277; 275, 287; 276, identifier:max_size; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:data; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:network_socket; 284, identifier:recv; 285, argument_list; 285, 286; 286, identifier:max_size; 287, else_clause; 287, 288; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:data; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:network_socket; 295, identifier:recv; 296, argument_list; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 302; 299, subscript; 299, 300; 299, 301; 300, identifier:result; 301, string:'length'; 302, call; 302, 303; 302, 304; 303, identifier:len; 304, argument_list; 304, 305; 305, identifier:data; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:data; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:data; 312, identifier:decode; 313, argument_list; 313, 314; 313, 315; 314, string:'ascii'; 315, keyword_argument; 315, 316; 315, 317; 316, identifier:errors; 317, string:'ignore'; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 323; 320, subscript; 320, 321; 320, 322; 321, identifier:result; 322, string:'response'; 323, parenthesized_expression; 323, 324; 324, identifier:data; 325, try_statement; 325, 326; 325, 349; 326, block; 326, 327; 327, expression_statement; 327, 328; 328, assignment; 328, 329; 328, 332; 329, subscript; 329, 330; 329, 331; 330, identifier:result; 331, string:'code'; 332, call; 332, 333; 332, 334; 333, identifier:int; 334, argument_list; 334, 335; 335, subscript; 335, 336; 335, 348; 336, call; 336, 337; 336, 347; 337, attribute; 337, 338; 337, 346; 338, subscript; 338, 339; 338, 345; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:data; 342, identifier:split; 343, argument_list; 343, 344; 344, string:'\n'; 345, integer:0; 346, identifier:split; 347, argument_list; 348, integer:1; 349, except_clause; 349, 350; 349, 351; 350, identifier:IndexError; 351, block; 351, 352; 352, pass_statement; 353, expression_statement; 353, 354; 354, assignment; 354, 355; 354, 358; 355, subscript; 355, 356; 355, 357; 356, identifier:ends; 357, string:'request'; 358, call; 358, 359; 358, 364; 359, attribute; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:datetime; 362, identifier:datetime; 363, identifier:now; 364, argument_list; 365, expression_statement; 365, 366; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:network_socket; 369, identifier:close; 370, argument_list; 371, expression_statement; 371, 372; 372, assignment; 372, 373; 372, 376; 373, subscript; 373, 374; 373, 375; 374, identifier:ends; 375, string:'all'; 376, call; 376, 377; 376, 382; 377, attribute; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:datetime; 380, identifier:datetime; 381, identifier:now; 382, argument_list; 383, for_statement; 383, 384; 383, 385; 383, 390; 384, identifier:duration; 385, call; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:starts; 388, identifier:keys; 389, argument_list; 390, block; 390, 391; 391, if_statement; 391, 392; 391, 399; 392, comparison_operator:in; 392, 393; 392, 394; 393, identifier:duration; 394, call; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:ends; 397, identifier:keys; 398, argument_list; 399, block; 399, 400; 400, expression_statement; 400, 401; 401, assignment; 401, 402; 401, 407; 402, subscript; 402, 403; 402, 406; 403, subscript; 403, 404; 403, 405; 404, identifier:result; 405, string:'durations'; 406, identifier:duration; 407, binary_operator:-; 407, 408; 407, 411; 408, subscript; 408, 409; 408, 410; 409, identifier:ends; 410, identifier:duration; 411, subscript; 411, 412; 411, 413; 412, identifier:starts; 413, identifier:duration; 414, if_statement; 414, 415; 414, 418; 415, comparison_operator:==; 415, 416; 415, 417; 416, identifier:result_connection; 417, integer:0; 418, block; 418, 419; 419, expression_statement; 419, 420; 420, assignment; 420, 421; 420, 424; 421, subscript; 421, 422; 421, 423; 422, identifier:result; 423, string:'state'; 424, string:'open'; 425, return_statement; 425, 426; 426, identifier:result
def scan(host, port=80, url=None, https=False, timeout=1, max_size=65535): starts = OrderedDict() ends = OrderedDict() port = int(port) result = dict( host=host, port=port, state='closed', durations=OrderedDict() ) if url: timeout = 1 result['code'] = None starts['all'] = starts['dns'] = datetime.datetime.now() try: hostip = socket.gethostbyname(host) result['ip'] = hostip ends['dns'] = datetime.datetime.now() except socket.gaierror: raise ScanFailed('DNS Lookup failed', result=result) starts['connect'] = datetime.datetime.now() network_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) network_socket.settimeout(timeout) result_connection = network_socket.connect_ex((hostip, port)) ends['connect'] = datetime.datetime.now() if https: starts['ssl'] = datetime.datetime.now() try: network_socket = ssl.wrap_socket(network_socket) except socket.timeout: raise ScanFailed('SSL socket timeout', result=result) ends['ssl'] = datetime.datetime.now() if result_connection == 0 and url: starts['request'] = datetime.datetime.now() network_socket.send( "GET {0} HTTP/1.0\r\nHost: {1}\r\n\r\n".format( url, host ).encode('ascii')) if max_size: data = network_socket.recv(max_size) else: data = network_socket.recv() result['length'] = len(data) data = data.decode('ascii', errors='ignore') result['response'] = (data) try: result['code'] = int(data.split('\n')[0].split()[1]) except IndexError: pass ends['request'] = datetime.datetime.now() network_socket.close() ends['all'] = datetime.datetime.now() for duration in starts.keys(): if duration in ends.keys(): result['durations'][duration] = ends[duration] - starts[duration] if result_connection == 0: result['state'] = 'open' return result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 45; 2, function_name:redirect; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 3, 39; 3, 42; 4, identifier:pattern; 5, identifier:to; 6, default_parameter; 6, 7; 6, 8; 7, identifier:permanent; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:locale_prefix; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:anchor; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:name; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:query; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:vary; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:cache_timeout; 26, integer:12; 27, default_parameter; 27, 28; 27, 29; 28, identifier:decorators; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:re_flags; 32, None; 33, default_parameter; 33, 34; 33, 35; 34, identifier:to_args; 35, None; 36, default_parameter; 36, 37; 36, 38; 37, identifier:to_kwargs; 38, None; 39, default_parameter; 39, 40; 39, 41; 40, identifier:prepend_locale; 41, True; 42, default_parameter; 42, 43; 42, 44; 43, identifier:merge_query; 44, False; 45, block; 45, 46; 45, 59; 45, 77; 45, 91; 45, 95; 45, 110; 45, 136; 45, 161; 45, 429; 45, 457; 46, if_statement; 46, 47; 46, 48; 46, 53; 47, identifier:permanent; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:redirect_class; 52, identifier:HttpResponsePermanentRedirect; 53, else_clause; 53, 54; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:redirect_class; 58, identifier:HttpResponseRedirect; 59, if_statement; 59, 60; 59, 61; 60, identifier:locale_prefix; 61, block; 61, 62; 61, 71; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:pattern; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:pattern; 68, identifier:lstrip; 69, argument_list; 69, 70; 70, string:'^/'; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:pattern; 74, binary_operator:+; 74, 75; 74, 76; 75, identifier:LOCALE_RE; 76, identifier:pattern; 77, if_statement; 77, 78; 77, 79; 78, identifier:re_flags; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:pattern; 83, binary_operator:+; 83, 84; 83, 90; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, string:'(?{})'; 87, identifier:format; 88, argument_list; 88, 89; 89, identifier:re_flags; 90, identifier:pattern; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:view_decorators; 94, list:[]; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:is; 96, 97; 96, 98; 97, identifier:cache_timeout; 98, None; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:view_decorators; 104, identifier:append; 105, argument_list; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:cache_control_expires; 108, argument_list; 108, 109; 109, identifier:cache_timeout; 110, if_statement; 110, 111; 110, 112; 111, identifier:vary; 112, block; 112, 113; 112, 125; 113, if_statement; 113, 114; 113, 119; 114, call; 114, 115; 114, 116; 115, identifier:isinstance; 116, argument_list; 116, 117; 116, 118; 117, identifier:vary; 118, identifier:basestring; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:vary; 123, list:[vary]; 123, 124; 124, identifier:vary; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:view_decorators; 129, identifier:append; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 133; 132, identifier:vary_on_headers; 133, argument_list; 133, 134; 134, list_splat; 134, 135; 135, identifier:vary; 136, if_statement; 136, 137; 136, 138; 137, identifier:decorators; 138, block; 138, 139; 139, if_statement; 139, 140; 139, 144; 139, 152; 140, call; 140, 141; 140, 142; 141, identifier:callable; 142, argument_list; 142, 143; 143, identifier:decorators; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:view_decorators; 149, identifier:append; 150, argument_list; 150, 151; 151, identifier:decorators; 152, else_clause; 152, 153; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:view_decorators; 158, identifier:extend; 159, argument_list; 159, 160; 160, identifier:decorators; 161, function_definition; 161, 162; 161, 163; 161, 169; 162, function_name:_view; 163, parameters; 163, 164; 163, 165; 163, 167; 164, identifier:request; 165, list_splat_pattern; 165, 166; 166, identifier:args; 167, dictionary_splat_pattern; 167, 168; 168, identifier:kwargs; 169, block; 169, 170; 169, 188; 169, 198; 169, 221; 169, 264; 169, 292; 169, 315; 169, 386; 169, 400; 169, 424; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:kwargs; 173, dictionary_comprehension; 173, 174; 173, 179; 174, pair; 174, 175; 174, 176; 175, identifier:k; 176, boolean_operator:or; 176, 177; 176, 178; 177, identifier:v; 178, string:''; 179, for_in_clause; 179, 180; 179, 183; 180, pattern_list; 180, 181; 180, 182; 181, identifier:k; 182, identifier:v; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:kwargs; 186, identifier:items; 187, argument_list; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:args; 191, list_comprehension; 191, 192; 191, 195; 192, boolean_operator:or; 192, 193; 192, 194; 193, identifier:x; 194, string:''; 195, for_in_clause; 195, 196; 195, 197; 196, identifier:x; 197, identifier:args; 198, if_statement; 198, 199; 198, 203; 198, 215; 199, call; 199, 200; 199, 201; 200, identifier:callable; 201, argument_list; 201, 202; 202, identifier:to; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:to_value; 207, call; 207, 208; 207, 209; 208, identifier:to; 209, argument_list; 209, 210; 209, 211; 209, 213; 210, identifier:request; 211, list_splat; 211, 212; 212, identifier:args; 213, dictionary_splat; 213, 214; 214, identifier:kwargs; 215, else_clause; 215, 216; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:to_value; 220, identifier:to; 221, if_statement; 221, 222; 221, 235; 221, 240; 222, boolean_operator:or; 222, 223; 222, 229; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:to_value; 226, identifier:startswith; 227, argument_list; 227, 228; 228, string:'/'; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:HTTP_RE; 232, identifier:match; 233, argument_list; 233, 234; 234, identifier:to_value; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:redirect_url; 239, identifier:to_value; 240, else_clause; 240, 241; 241, block; 241, 242; 242, try_statement; 242, 243; 242, 257; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:redirect_url; 247, call; 247, 248; 247, 249; 248, identifier:reverse; 249, argument_list; 249, 250; 249, 251; 249, 254; 250, identifier:to_value; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:args; 253, identifier:to_args; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:kwargs; 256, identifier:to_kwargs; 257, except_clause; 257, 258; 257, 259; 258, identifier:NoReverseMatch; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:redirect_url; 263, identifier:to_value; 264, if_statement; 264, 265; 264, 280; 265, boolean_operator:and; 265, 266; 265, 274; 266, boolean_operator:and; 266, 267; 266, 268; 267, identifier:prepend_locale; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:redirect_url; 271, identifier:startswith; 272, argument_list; 272, 273; 273, string:'/'; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:kwargs; 277, identifier:get; 278, argument_list; 278, 279; 279, string:'locale'; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:redirect_url; 284, binary_operator:+; 284, 285; 284, 286; 285, string:'/{locale}'; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:redirect_url; 289, identifier:lstrip; 290, argument_list; 290, 291; 291, string:'/'; 292, if_statement; 292, 293; 292, 296; 293, boolean_operator:or; 293, 294; 293, 295; 294, identifier:args; 295, identifier:kwargs; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 300; 299, identifier:redirect_url; 300, call; 300, 301; 300, 302; 301, identifier:strip_tags; 302, argument_list; 302, 303; 303, call; 303, 304; 303, 310; 304, attribute; 304, 305; 304, 309; 305, call; 305, 306; 305, 307; 306, identifier:force_text; 307, argument_list; 307, 308; 308, identifier:redirect_url; 309, identifier:format; 310, argument_list; 310, 311; 310, 313; 311, list_splat; 311, 312; 312, identifier:args; 313, dictionary_splat; 313, 314; 314, identifier:kwargs; 315, if_statement; 315, 316; 315, 317; 315, 364; 315, 380; 316, identifier:query; 317, block; 317, 318; 318, if_statement; 318, 319; 318, 320; 318, 352; 319, identifier:merge_query; 320, block; 320, 321; 320, 335; 320, 342; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:req_query; 324, call; 324, 325; 324, 326; 325, identifier:parse_qs; 326, argument_list; 326, 327; 327, call; 327, 328; 327, 333; 328, attribute; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:request; 331, identifier:META; 332, identifier:get; 333, argument_list; 333, 334; 334, string:'QUERY_STRING'; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:req_query; 339, identifier:update; 340, argument_list; 340, 341; 341, identifier:query; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 345; 344, identifier:querystring; 345, call; 345, 346; 345, 347; 346, identifier:urlencode; 347, argument_list; 347, 348; 347, 349; 348, identifier:req_query; 349, keyword_argument; 349, 350; 349, 351; 350, identifier:doseq; 351, True; 352, else_clause; 352, 353; 353, block; 353, 354; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 357; 356, identifier:querystring; 357, call; 357, 358; 357, 359; 358, identifier:urlencode; 359, argument_list; 359, 360; 359, 361; 360, identifier:query; 361, keyword_argument; 361, 362; 361, 363; 362, identifier:doseq; 363, True; 364, elif_clause; 364, 365; 364, 368; 365, comparison_operator:is; 365, 366; 365, 367; 366, identifier:query; 367, None; 368, block; 368, 369; 369, expression_statement; 369, 370; 370, assignment; 370, 371; 370, 372; 371, identifier:querystring; 372, call; 372, 373; 372, 378; 373, attribute; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, identifier:request; 376, identifier:META; 377, identifier:get; 378, argument_list; 378, 379; 379, string:'QUERY_STRING'; 380, else_clause; 380, 381; 381, block; 381, 382; 382, expression_statement; 382, 383; 383, assignment; 383, 384; 383, 385; 384, identifier:querystring; 385, string:''; 386, if_statement; 386, 387; 386, 388; 387, identifier:querystring; 388, block; 388, 389; 389, expression_statement; 389, 390; 390, assignment; 390, 391; 390, 392; 391, identifier:redirect_url; 392, call; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, string:'?'; 395, identifier:join; 396, argument_list; 396, 397; 397, list:[redirect_url, querystring]; 397, 398; 397, 399; 398, identifier:redirect_url; 399, identifier:querystring; 400, if_statement; 400, 401; 400, 402; 401, identifier:anchor; 402, block; 402, 403; 403, expression_statement; 403, 404; 404, assignment; 404, 405; 404, 406; 404, 414; 405, identifier:redirect_url; 406, ERROR; 406, 407; 406, 408; 407, identifier:if; 408, call; 408, 409; 408, 412; 409, attribute; 409, 410; 409, 411; 410, identifier:PROTOCOL_RELATIVE_RE; 411, identifier:match; 412, argument_list; 412, 413; 413, identifier:redirect_url; 414, assignment; 414, 415; 414, 416; 415, identifier:redirect_url; 416, binary_operator:+; 416, 417; 416, 418; 417, string:'/'; 418, call; 418, 419; 418, 422; 419, attribute; 419, 420; 419, 421; 420, identifier:redirect_url; 421, identifier:lstrip; 422, argument_list; 422, 423; 423, string:'/'; 424, return_statement; 424, 425; 425, call; 425, 426; 425, 427; 426, identifier:redirect_class; 427, argument_list; 427, 428; 428, identifier:redirect_url; 429, try_statement; 429, 430; 429, 445; 430, block; 430, 431; 431, for_statement; 431, 432; 431, 433; 431, 437; 432, identifier:decorator; 433, call; 433, 434; 433, 435; 434, identifier:reversed; 435, argument_list; 435, 436; 436, identifier:view_decorators; 437, block; 437, 438; 438, expression_statement; 438, 439; 439, assignment; 439, 440; 439, 441; 440, identifier:_view; 441, call; 441, 442; 441, 443; 442, identifier:decorator; 443, argument_list; 443, 444; 444, identifier:_view; 445, except_clause; 445, 446; 445, 447; 446, identifier:TypeError; 447, block; 447, 448; 448, expression_statement; 448, 449; 449, call; 449, 450; 449, 453; 450, attribute; 450, 451; 450, 452; 451, identifier:log; 452, identifier:exception; 453, argument_list; 453, 454; 454, concatenated_string; 454, 455; 454, 456; 455, string:'decorators not iterable or does not contain '; 456, string:'callable items'; 457, return_statement; 457, 458; 458, call; 458, 459; 458, 460; 459, identifier:url; 460, argument_list; 460, 461; 460, 462; 460, 463; 461, identifier:pattern; 462, identifier:_view; 463, keyword_argument; 463, 464; 463, 465; 464, identifier:name; 465, identifier:name
def redirect(pattern, to, permanent=True, locale_prefix=True, anchor=None, name=None, query=None, vary=None, cache_timeout=12, decorators=None, re_flags=None, to_args=None, to_kwargs=None, prepend_locale=True, merge_query=False): if permanent: redirect_class = HttpResponsePermanentRedirect else: redirect_class = HttpResponseRedirect if locale_prefix: pattern = pattern.lstrip('^/') pattern = LOCALE_RE + pattern if re_flags: pattern = '(?{})'.format(re_flags) + pattern view_decorators = [] if cache_timeout is not None: view_decorators.append(cache_control_expires(cache_timeout)) if vary: if isinstance(vary, basestring): vary = [vary] view_decorators.append(vary_on_headers(*vary)) if decorators: if callable(decorators): view_decorators.append(decorators) else: view_decorators.extend(decorators) def _view(request, *args, **kwargs): kwargs = {k: v or '' for k, v in kwargs.items()} args = [x or '' for x in args] if callable(to): to_value = to(request, *args, **kwargs) else: to_value = to if to_value.startswith('/') or HTTP_RE.match(to_value): redirect_url = to_value else: try: redirect_url = reverse(to_value, args=to_args, kwargs=to_kwargs) except NoReverseMatch: redirect_url = to_value if prepend_locale and redirect_url.startswith('/') and kwargs.get('locale'): redirect_url = '/{locale}' + redirect_url.lstrip('/') if args or kwargs: redirect_url = strip_tags(force_text(redirect_url).format(*args, **kwargs)) if query: if merge_query: req_query = parse_qs(request.META.get('QUERY_STRING')) req_query.update(query) querystring = urlencode(req_query, doseq=True) else: querystring = urlencode(query, doseq=True) elif query is None: querystring = request.META.get('QUERY_STRING') else: querystring = '' if querystring: redirect_url = '?'.join([redirect_url, querystring]) if anchor: redirect_url = ' if PROTOCOL_RELATIVE_RE.match(redirect_url): redirect_url = '/' + redirect_url.lstrip('/') return redirect_class(redirect_url) try: for decorator in reversed(view_decorators): _view = decorator(_view) except TypeError: log.exception('decorators not iterable or does not contain ' 'callable items') return url(pattern, _view, name=name)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:FD; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 16; 5, 40; 5, 69; 5, 105; 5, 140; 5, 255; 5, 277; 6, if_statement; 6, 7; 6, 10; 7, attribute; 7, 8; 7, 9; 8, identifier:self; 9, identifier:Verbose; 10, block; 10, 11; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:print; 14, argument_list; 14, 15; 15, string:"Finite Difference Solution Technique"; 16, try_statement; 16, 17; 16, 22; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:qs; 22, except_clause; 22, 23; 23, block; 23, 24; 23, 36; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:qs; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:q0; 34, identifier:copy; 35, argument_list; 36, delete_statement; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:q0; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:x; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:np; 48, identifier:arange; 49, argument_list; 49, 50; 49, 55; 49, 66; 50, binary_operator:/; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:dx; 54, float:2.; 55, binary_operator:*; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:dx; 59, subscript; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:qs; 64, identifier:shape; 65, integer:0; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:dx; 69, if_statement; 69, 70; 69, 75; 70, comparison_operator:==; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:dimension; 74, integer:2; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:y; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:np; 84, identifier:arange; 85, argument_list; 85, 86; 85, 91; 85, 102; 86, binary_operator:/; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:dy; 90, float:2.; 91, binary_operator:*; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:dy; 95, subscript; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:qs; 100, identifier:shape; 101, integer:1; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:dy; 105, try_statement; 105, 106; 105, 111; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:Solver; 111, except_clause; 111, 112; 112, block; 112, 113; 113, if_statement; 113, 114; 113, 117; 113, 131; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:filename; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:Solver; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:configGet; 127, argument_list; 127, 128; 127, 129; 127, 130; 128, string:"string"; 129, string:"numerical"; 130, string:"Solver"; 131, else_clause; 131, 132; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:sys; 137, identifier:exit; 138, argument_list; 138, 139; 139, string:"No solver defined!"; 140, if_statement; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:filename; 144, block; 144, 145; 144, 158; 144, 231; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:iterative_ConvergenceTolerance; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:configGet; 154, argument_list; 154, 155; 154, 156; 154, 157; 155, string:"float"; 156, string:"numerical"; 157, string:"ConvergenceTolerance"; 158, try_statement; 158, 159; 158, 209; 159, block; 159, 160; 159, 176; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:Te; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:configGet; 169, argument_list; 169, 170; 169, 171; 169, 172; 169, 173; 170, string:"float"; 171, string:"input"; 172, string:"ElasticThickness"; 173, keyword_argument; 173, 174; 173, 175; 174, identifier:optional; 175, False; 176, if_statement; 176, 177; 176, 182; 176, 203; 177, comparison_operator:is; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:Te; 181, None; 182, block; 182, 183; 182, 197; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:Tepath; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:configGet; 190, argument_list; 190, 191; 190, 192; 190, 193; 190, 194; 191, string:"string"; 192, string:"input"; 193, string:"ElasticThickness"; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:optional; 196, False; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:Te; 202, identifier:Tepath; 203, else_clause; 203, 204; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:Tepath; 208, None; 209, except_clause; 209, 210; 210, block; 210, 211; 210, 225; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:Tepath; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:configGet; 218, argument_list; 218, 219; 218, 220; 218, 221; 218, 222; 219, string:"string"; 220, string:"input"; 221, string:"ElasticThickness"; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:optional; 224, False; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:Te; 230, identifier:Tepath; 231, if_statement; 231, 232; 231, 237; 232, comparison_operator:is; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:Te; 236, None; 237, block; 237, 238; 238, if_statement; 238, 239; 238, 244; 238, 246; 239, comparison_operator:is; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:coeff_matrix; 243, None; 244, block; 244, 245; 245, pass_statement; 246, else_clause; 246, 247; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:sys; 252, identifier:exit; 253, argument_list; 253, 254; 254, string:"No input elastic thickness or coefficient matrix supplied."; 255, if_statement; 255, 256; 255, 264; 255, 271; 256, comparison_operator:==; 256, 257; 256, 263; 257, call; 257, 258; 257, 259; 258, identifier:type; 259, argument_list; 259, 260; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:Te; 263, identifier:str; 264, block; 264, 265; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:Tepath; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:Te; 271, else_clause; 271, 272; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:Tepath; 276, None; 277, if_statement; 277, 278; 277, 279; 278, identifier:Tepath; 279, block; 279, 280; 279, 296; 279, 348; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:Te; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:loadFile; 289, argument_list; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:self; 292, identifier:Te; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:close_on_fail; 295, False; 296, if_statement; 296, 297; 296, 302; 297, comparison_operator:is; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:self; 300, identifier:Te; 301, None; 302, block; 302, 303; 302, 308; 302, 313; 302, 318; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:print; 306, argument_list; 306, 307; 307, string:"Requested Te file is provided but cannot be located."; 308, expression_statement; 308, 309; 309, call; 309, 310; 309, 311; 310, identifier:print; 311, argument_list; 311, 312; 312, string:"No scalar elastic thickness is provided in configuration file"; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 316; 315, identifier:print; 316, argument_list; 316, 317; 317, string:"(Typo in path to input Te grid?)"; 318, if_statement; 318, 319; 318, 324; 318, 335; 319, comparison_operator:is; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:self; 322, identifier:coeff_matrix; 323, None; 324, block; 324, 325; 324, 330; 325, expression_statement; 325, 326; 326, call; 326, 327; 326, 328; 327, identifier:print; 328, argument_list; 328, 329; 329, string:"But a coefficient matrix has been found."; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 333; 332, identifier:print; 333, argument_list; 333, 334; 334, string:"Calculations will be carried forward using it."; 335, else_clause; 335, 336; 336, block; 336, 337; 336, 342; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 340; 339, identifier:print; 340, argument_list; 340, 341; 341, string:"Exiting."; 342, expression_statement; 342, 343; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:sys; 346, identifier:exit; 347, argument_list; 348, if_statement; 348, 349; 348, 356; 349, call; 349, 350; 349, 355; 350, attribute; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:self; 353, identifier:Te; 354, identifier:any; 355, argument_list; 356, block; 356, 357; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:self; 361, identifier:TeArraySizeCheck; 362, argument_list
def FD(self): if self.Verbose: print("Finite Difference Solution Technique") try: self.qs except: self.qs = self.q0.copy() del self.q0 self.x = np.arange(self.dx/2., self.dx * self.qs.shape[0], self.dx) if self.dimension == 2: self.y = np.arange(self.dy/2., self.dy * self.qs.shape[1], self.dy) try: self.Solver except: if self.filename: self.Solver = self.configGet("string", "numerical", "Solver") else: sys.exit("No solver defined!") if self.filename: self.iterative_ConvergenceTolerance = self.configGet("float", "numerical", "ConvergenceTolerance") try: self.Te = self.configGet("float", "input", "ElasticThickness", optional=False) if self.Te is None: Tepath = self.configGet("string", "input", "ElasticThickness", optional=False) self.Te = Tepath else: Tepath = None except: Tepath = self.configGet("string", "input", "ElasticThickness", optional=False) self.Te = Tepath if self.Te is None: if self.coeff_matrix is not None: pass else: sys.exit("No input elastic thickness or coefficient matrix supplied.") if type(self.Te) == str: Tepath = self.Te else: Tepath = None if Tepath: self.Te = self.loadFile(self.Te, close_on_fail = False) if self.Te is None: print("Requested Te file is provided but cannot be located.") print("No scalar elastic thickness is provided in configuration file") print("(Typo in path to input Te grid?)") if self.coeff_matrix is not None: print("But a coefficient matrix has been found.") print("Calculations will be carried forward using it.") else: print("Exiting.") sys.exit() if self.Te.any(): self.TeArraySizeCheck()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:SAS_NG; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 69; 5, 224; 5, 232; 5, 247; 5, 251; 5, 298; 5, 321; 5, 452; 6, if_statement; 6, 7; 6, 10; 7, attribute; 7, 8; 7, 9; 8, identifier:self; 9, identifier:filename; 10, block; 10, 11; 10, 24; 10, 40; 10, 56; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:Te; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:configGet; 20, argument_list; 20, 21; 20, 22; 20, 23; 21, string:"float"; 22, string:"input"; 23, string:"ElasticThickness"; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:latlon; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:configGet; 33, argument_list; 33, 34; 33, 35; 33, 36; 33, 37; 34, string:"string"; 35, string:"numerical2D"; 36, string:"latlon"; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:optional; 39, True; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:PlanetaryRadius; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:configGet; 49, argument_list; 49, 50; 49, 51; 49, 52; 49, 53; 50, string:"float"; 51, string:"numerical2D"; 52, string:"PlanetaryRadius"; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:optional; 55, True; 56, if_statement; 56, 57; 56, 62; 57, comparison_operator:==; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:dimension; 61, integer:2; 62, block; 62, 63; 63, import_from_statement; 63, 64; 63, 67; 64, dotted_name; 64, 65; 64, 66; 65, identifier:scipy; 66, identifier:special; 67, dotted_name; 67, 68; 68, identifier:kei; 69, if_statement; 69, 70; 69, 75; 69, 141; 70, comparison_operator:==; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:dimension; 74, integer:1; 75, block; 75, 76; 76, try_statement; 76, 77; 76, 86; 77, block; 77, 78; 77, 82; 78, expression_statement; 78, 79; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:x; 82, expression_statement; 82, 83; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:q; 86, except_clause; 86, 87; 87, block; 87, 88; 88, if_statement; 88, 89; 88, 98; 88, 123; 89, comparison_operator:==; 89, 90; 89, 97; 90, subscript; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:q0; 95, identifier:shape; 96, integer:1; 97, integer:2; 98, block; 98, 99; 98, 111; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:x; 104, subscript; 104, 105; 104, 108; 104, 110; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:q0; 108, slice; 108, 109; 109, colon; 110, integer:0; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:q; 116, subscript; 116, 117; 116, 120; 116, 122; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:q0; 120, slice; 120, 121; 121, colon; 122, integer:1; 123, else_clause; 123, 124; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:sys; 129, identifier:exit; 130, argument_list; 130, 131; 131, binary_operator:+; 131, 132; 131, 133; 132, string:"For 1D (ungridded) SAS_NG configuration file, need [x,w] array. Your dimensions are: "; 133, call; 133, 134; 133, 135; 134, identifier:str; 135, argument_list; 135, 136; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:q0; 140, identifier:shape; 141, else_clause; 141, 142; 142, block; 142, 143; 143, try_statement; 143, 144; 143, 157; 144, block; 144, 145; 144, 149; 144, 153; 145, expression_statement; 145, 146; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:x; 149, expression_statement; 149, 150; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:u; 153, expression_statement; 153, 154; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:q; 157, except_clause; 157, 158; 158, block; 158, 159; 159, if_statement; 159, 160; 159, 169; 159, 206; 160, comparison_operator:==; 160, 161; 160, 168; 161, subscript; 161, 162; 161, 167; 162, attribute; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:q0; 166, identifier:shape; 167, integer:1; 168, integer:3; 169, block; 169, 170; 169, 182; 169, 194; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:x; 175, subscript; 175, 176; 175, 179; 175, 181; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:q0; 179, slice; 179, 180; 180, colon; 181, integer:0; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:y; 187, subscript; 187, 188; 187, 191; 187, 193; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:q0; 191, slice; 191, 192; 192, colon; 193, integer:1; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:q; 199, subscript; 199, 200; 199, 203; 199, 205; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:q0; 203, slice; 203, 204; 204, colon; 205, integer:2; 206, else_clause; 206, 207; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:sys; 212, identifier:exit; 213, argument_list; 213, 214; 214, binary_operator:+; 214, 215; 214, 216; 215, string:"For 2D (ungridded) SAS_NG configuration file, need [x,y,w] array. Your dimensions are: "; 216, call; 216, 217; 216, 218; 217, identifier:str; 218, argument_list; 218, 219; 219, attribute; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:q0; 223, identifier:shape; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:x; 229, attribute; 229, 230; 229, 231; 230, identifier:self; 231, identifier:x; 232, if_statement; 232, 233; 232, 238; 233, comparison_operator:==; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:dimension; 237, integer:2; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:y; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:y; 247, delete_statement; 247, 248; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:q0; 251, try_statement; 251, 252; 251, 257; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:xw; 257, except_clause; 257, 258; 258, block; 258, 259; 259, try_statement; 259, 260; 259, 290; 260, block; 260, 261; 260, 277; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:xw; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:configGet; 270, argument_list; 270, 271; 270, 272; 270, 273; 270, 274; 271, string:'string'; 272, string:"input"; 273, string:"xw"; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:optional; 276, True; 277, if_statement; 277, 278; 277, 283; 278, comparison_operator:==; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:xw; 282, string:''; 283, block; 283, 284; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:xw; 289, None; 290, except_clause; 290, 291; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:self; 296, identifier:xw; 297, None; 298, if_statement; 298, 299; 298, 307; 299, comparison_operator:==; 299, 300; 299, 306; 300, call; 300, 301; 300, 302; 301, identifier:type; 302, argument_list; 302, 303; 303, attribute; 303, 304; 303, 305; 304, identifier:self; 305, identifier:xw; 306, identifier:str; 307, block; 307, 308; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:self; 312, identifier:xw; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:self; 316, identifier:loadFile; 317, argument_list; 317, 318; 318, attribute; 318, 319; 318, 320; 319, identifier:self; 320, identifier:xw; 321, if_statement; 321, 322; 321, 327; 322, comparison_operator:==; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:dimension; 326, integer:2; 327, block; 327, 328; 327, 375; 327, 410; 328, try_statement; 328, 329; 328, 334; 329, block; 329, 330; 330, expression_statement; 330, 331; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:yw; 334, except_clause; 334, 335; 335, block; 335, 336; 336, try_statement; 336, 337; 336, 367; 337, block; 337, 338; 337, 354; 338, expression_statement; 338, 339; 339, assignment; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:self; 342, identifier:yw; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:self; 346, identifier:configGet; 347, argument_list; 347, 348; 347, 349; 347, 350; 347, 351; 348, string:'string'; 349, string:"input"; 350, string:"yw"; 351, keyword_argument; 351, 352; 351, 353; 352, identifier:optional; 353, True; 354, if_statement; 354, 355; 354, 360; 355, comparison_operator:==; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:yw; 359, string:''; 360, block; 360, 361; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 366; 363, attribute; 363, 364; 363, 365; 364, identifier:self; 365, identifier:yw; 366, None; 367, except_clause; 367, 368; 368, block; 368, 369; 369, expression_statement; 369, 370; 370, assignment; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:self; 373, identifier:yw; 374, None; 375, if_statement; 375, 376; 375, 402; 376, boolean_operator:or; 376, 377; 376, 389; 376, 390; 377, parenthesized_expression; 377, 378; 378, boolean_operator:and; 378, 379; 378, 384; 379, comparison_operator:is; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:self; 382, identifier:xw; 383, None; 384, comparison_operator:is; 384, 385; 384, 388; 385, attribute; 385, 386; 385, 387; 386, identifier:self; 387, identifier:yw; 388, None; 389, line_continuation:\; 390, parenthesized_expression; 390, 391; 391, boolean_operator:and; 391, 392; 391, 397; 392, comparison_operator:is; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:self; 395, identifier:xw; 396, None; 397, comparison_operator:is; 397, 398; 397, 401; 398, attribute; 398, 399; 398, 400; 399, identifier:self; 400, identifier:yw; 401, None; 402, block; 402, 403; 403, expression_statement; 403, 404; 404, call; 404, 405; 404, 408; 405, attribute; 405, 406; 405, 407; 406, identifier:sys; 407, identifier:exit; 408, argument_list; 408, 409; 409, string:"SAS_NG output at specified points requires both xw and yw to be defined"; 410, if_statement; 410, 411; 410, 419; 410, 433; 411, comparison_operator:==; 411, 412; 411, 418; 412, call; 412, 413; 412, 414; 413, identifier:type; 414, argument_list; 414, 415; 415, attribute; 415, 416; 415, 417; 416, identifier:self; 417, identifier:yw; 418, identifier:str; 419, block; 419, 420; 420, expression_statement; 420, 421; 421, assignment; 421, 422; 421, 425; 422, attribute; 422, 423; 422, 424; 423, identifier:self; 424, identifier:yw; 425, call; 425, 426; 425, 429; 426, attribute; 426, 427; 426, 428; 427, identifier:self; 428, identifier:loadFile; 429, argument_list; 429, 430; 430, attribute; 430, 431; 430, 432; 431, identifier:self; 432, identifier:yw; 433, elif_clause; 433, 434; 433, 439; 434, comparison_operator:is; 434, 435; 434, 438; 435, attribute; 435, 436; 435, 437; 436, identifier:self; 437, identifier:yw; 438, None; 439, block; 439, 440; 440, expression_statement; 440, 441; 441, assignment; 441, 442; 441, 445; 442, attribute; 442, 443; 442, 444; 443, identifier:self; 444, identifier:yw; 445, call; 445, 446; 445, 451; 446, attribute; 446, 447; 446, 450; 447, attribute; 447, 448; 447, 449; 448, identifier:self; 449, identifier:y; 450, identifier:copy; 451, argument_list; 452, if_statement; 452, 453; 452, 458; 453, comparison_operator:is; 453, 454; 453, 457; 454, attribute; 454, 455; 454, 456; 455, identifier:self; 456, identifier:xw; 457, None; 458, block; 458, 459; 459, expression_statement; 459, 460; 460, assignment; 460, 461; 460, 464; 461, attribute; 461, 462; 461, 463; 462, identifier:self; 463, identifier:xw; 464, call; 464, 465; 464, 470; 465, attribute; 465, 466; 465, 469; 466, attribute; 466, 467; 466, 468; 467, identifier:self; 468, identifier:x; 469, identifier:copy; 470, argument_list
def SAS_NG(self): if self.filename: self.Te = self.configGet("float", "input", "ElasticThickness") self.latlon = self.configGet("string", "numerical2D", "latlon", optional=True) self.PlanetaryRadius = self.configGet("float", "numerical2D", "PlanetaryRadius", optional=True) if self.dimension == 2: from scipy.special import kei if self.dimension == 1: try: self.x self.q except: if self.q0.shape[1] == 2: self.x = self.q0[:,0] self.q = self.q0[:,1] else: sys.exit("For 1D (ungridded) SAS_NG configuration file, need [x,w] array. Your dimensions are: "+str(self.q0.shape)) else: try: self.x self.u self.q except: if self.q0.shape[1] == 3: self.x = self.q0[:,0] self.y = self.q0[:,1] self.q = self.q0[:,2] else: sys.exit("For 2D (ungridded) SAS_NG configuration file, need [x,y,w] array. Your dimensions are: "+str(self.q0.shape)) self.x = self.x if self.dimension == 2: self.y = self.y del self.q0 try: self.xw except: try: self.xw = self.configGet('string', "input", "xw", optional=True) if self.xw == '': self.xw = None except: self.xw = None if type(self.xw) == str: self.xw = self.loadFile(self.xw) if self.dimension == 2: try: self.yw except: try: self.yw = self.configGet('string', "input", "yw", optional=True ) if self.yw == '': self.yw = None except: self.yw = None if (self.xw is not None and self.yw is None) \ or (self.xw is None and self.yw is not None): sys.exit("SAS_NG output at specified points requires both xw and yw to be defined") if type(self.yw) == str: self.yw = self.loadFile(self.yw) elif self.yw is None: self.yw = self.y.copy() if self.xw is None: self.xw = self.x.copy()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_c3_mro; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, default_parameter; 5, 6; 5, 7; 6, identifier:abcs; 7, None; 8, block; 8, 9; 8, 48; 8, 58; 8, 71; 8, 75; 8, 88; 8, 121; 8, 132; 8, 146; 8, 160; 8, 174; 9, for_statement; 9, 10; 9, 13; 9, 22; 9, 42; 10, pattern_list; 10, 11; 10, 12; 11, identifier:i; 12, identifier:base; 13, call; 13, 14; 13, 15; 14, identifier:enumerate; 15, argument_list; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:reversed; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:cls; 21, identifier:__bases__; 22, block; 22, 23; 23, if_statement; 23, 24; 23, 29; 24, call; 24, 25; 24, 26; 25, identifier:hasattr; 26, argument_list; 26, 27; 26, 28; 27, identifier:base; 28, string:'__abstractmethods__'; 29, block; 29, 30; 29, 41; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:boundary; 33, binary_operator:-; 33, 34; 33, 40; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:cls; 39, identifier:__bases__; 40, identifier:i; 41, break_statement; 42, else_clause; 42, 43; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:boundary; 47, integer:0; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:abcs; 51, conditional_expression:if; 51, 52; 51, 56; 51, 57; 52, call; 52, 53; 52, 54; 53, identifier:list; 54, argument_list; 54, 55; 55, identifier:abcs; 56, identifier:abcs; 57, list:[]; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:explicit_bases; 61, call; 61, 62; 61, 63; 62, identifier:list; 63, argument_list; 63, 64; 64, subscript; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:cls; 67, identifier:__bases__; 68, slice; 68, 69; 68, 70; 69, colon; 70, identifier:boundary; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:abstract_bases; 74, list:[]; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:other_bases; 78, call; 78, 79; 78, 80; 79, identifier:list; 80, argument_list; 80, 81; 81, subscript; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:cls; 84, identifier:__bases__; 85, slice; 85, 86; 85, 87; 86, identifier:boundary; 87, colon; 88, for_statement; 88, 89; 88, 90; 88, 91; 89, identifier:base; 90, identifier:abcs; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 113; 93, boolean_operator:and; 93, 94; 93, 99; 94, call; 94, 95; 94, 96; 95, identifier:issubclass; 96, argument_list; 96, 97; 96, 98; 97, identifier:cls; 98, identifier:base; 99, not_operator; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:any; 102, generator_expression; 102, 103; 102, 108; 103, call; 103, 104; 103, 105; 104, identifier:issubclass; 105, argument_list; 105, 106; 105, 107; 106, identifier:b; 107, identifier:base; 108, for_in_clause; 108, 109; 108, 110; 109, identifier:b; 110, attribute; 110, 111; 110, 112; 111, identifier:cls; 112, identifier:__bases__; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:abstract_bases; 118, identifier:append; 119, argument_list; 119, 120; 120, identifier:base; 121, for_statement; 121, 122; 121, 123; 121, 124; 122, identifier:base; 123, identifier:abstract_bases; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:abcs; 129, identifier:remove; 130, argument_list; 130, 131; 131, identifier:base; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:explicit_c3_mros; 135, list_comprehension; 135, 136; 135, 143; 136, call; 136, 137; 136, 138; 137, identifier:_c3_mro; 138, argument_list; 138, 139; 138, 140; 139, identifier:base; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:abcs; 142, identifier:abcs; 143, for_in_clause; 143, 144; 143, 145; 144, identifier:base; 145, identifier:explicit_bases; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:abstract_c3_mros; 149, list_comprehension; 149, 150; 149, 157; 150, call; 150, 151; 150, 152; 151, identifier:_c3_mro; 152, argument_list; 152, 153; 152, 154; 153, identifier:base; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:abcs; 156, identifier:abcs; 157, for_in_clause; 157, 158; 157, 159; 158, identifier:base; 159, identifier:abstract_bases; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:other_c3_mros; 163, list_comprehension; 163, 164; 163, 171; 164, call; 164, 165; 164, 166; 165, identifier:_c3_mro; 166, argument_list; 166, 167; 166, 168; 167, identifier:base; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:abcs; 170, identifier:abcs; 171, for_in_clause; 171, 172; 171, 173; 172, identifier:base; 173, identifier:other_bases; 174, return_statement; 174, 175; 175, call; 175, 176; 175, 177; 176, identifier:_c3_merge; 177, argument_list; 177, 178; 178, binary_operator:+; 178, 179; 178, 194; 179, binary_operator:+; 179, 180; 179, 192; 180, binary_operator:+; 180, 181; 180, 190; 181, binary_operator:+; 181, 182; 181, 189; 182, binary_operator:+; 182, 183; 182, 188; 183, binary_operator:+; 183, 184; 183, 187; 184, list:[[cls]]; 184, 185; 185, list:[cls]; 185, 186; 186, identifier:cls; 187, identifier:explicit_c3_mros; 188, identifier:abstract_c3_mros; 189, identifier:other_c3_mros; 190, list:[explicit_bases]; 190, 191; 191, identifier:explicit_bases; 192, list:[abstract_bases]; 192, 193; 193, identifier:abstract_bases; 194, list:[ other_bases]; 194, 195; 195, identifier:other_bases
def _c3_mro(cls, abcs=None): for i, base in enumerate(reversed(cls.__bases__)): if hasattr(base, '__abstractmethods__'): boundary = len(cls.__bases__) - i break else: boundary = 0 abcs = list(abcs) if abcs else [] explicit_bases = list(cls.__bases__[:boundary]) abstract_bases = [] other_bases = list(cls.__bases__[boundary:]) for base in abcs: if issubclass(cls, base) and not any(issubclass(b, base) for b in cls.__bases__): abstract_bases.append(base) for base in abstract_bases: abcs.remove(base) explicit_c3_mros = [_c3_mro(base, abcs=abcs) for base in explicit_bases] abstract_c3_mros = [_c3_mro(base, abcs=abcs) for base in abstract_bases] other_c3_mros = [_c3_mro(base, abcs=abcs) for base in other_bases] return _c3_merge( [[cls]] + explicit_c3_mros + abstract_c3_mros + other_c3_mros + [explicit_bases] + [abstract_bases] + [ other_bases])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:singledispatch; 3, parameters; 3, 4; 4, identifier:function; 5, block; 5, 6; 5, 10; 5, 16; 5, 21; 5, 27; 5, 102; 5, 159; 5, 182; 5, 188; 5, 194; 5, 200; 5, 209; 5, 217; 5, 223; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:registry; 9, dictionary; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:dispatch_cache; 13, call; 13, 14; 13, 15; 14, identifier:WeakKeyDictionary; 15, argument_list; 16, function_definition; 16, 17; 16, 18; 16, 19; 17, function_name:ns; 18, parameters; 19, block; 19, 20; 20, pass_statement; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:ns; 25, identifier:cache_token; 26, None; 27, function_definition; 27, 28; 27, 29; 27, 31; 28, function_name:dispatch; 29, parameters; 29, 30; 30, identifier:cls; 31, block; 31, 32; 31, 64; 31, 100; 32, if_statement; 32, 33; 32, 38; 33, comparison_operator:is; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:ns; 36, identifier:cache_token; 37, None; 38, block; 38, 39; 38, 45; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:current_token; 42, call; 42, 43; 42, 44; 43, identifier:get_cache_token; 44, argument_list; 45, if_statement; 45, 46; 45, 51; 46, comparison_operator:!=; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:ns; 49, identifier:cache_token; 50, identifier:current_token; 51, block; 51, 52; 51, 58; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:dispatch_cache; 56, identifier:clear; 57, argument_list; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:ns; 62, identifier:cache_token; 63, identifier:current_token; 64, try_statement; 64, 65; 64, 72; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:impl; 69, subscript; 69, 70; 69, 71; 70, identifier:dispatch_cache; 71, identifier:cls; 72, except_clause; 72, 73; 72, 74; 73, identifier:KeyError; 74, block; 74, 75; 74, 94; 75, try_statement; 75, 76; 75, 83; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:impl; 80, subscript; 80, 81; 80, 82; 81, identifier:registry; 82, identifier:cls; 83, except_clause; 83, 84; 83, 85; 84, identifier:KeyError; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:impl; 89, call; 89, 90; 89, 91; 90, identifier:_find_impl; 91, argument_list; 91, 92; 91, 93; 92, identifier:cls; 93, identifier:registry; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:dispatch_cache; 98, identifier:cls; 99, identifier:impl; 100, return_statement; 100, 101; 101, identifier:impl; 102, function_definition; 102, 103; 102, 104; 102, 109; 103, function_name:register; 104, parameters; 104, 105; 104, 106; 105, identifier:cls; 106, default_parameter; 106, 107; 106, 108; 107, identifier:func; 108, None; 109, block; 109, 110; 109, 124; 109, 130; 109, 151; 109, 157; 110, if_statement; 110, 111; 110, 114; 111, comparison_operator:is; 111, 112; 111, 113; 112, identifier:func; 113, None; 114, block; 114, 115; 115, return_statement; 115, 116; 116, lambda; 116, 117; 116, 119; 117, lambda_parameters; 117, 118; 118, identifier:f; 119, call; 119, 120; 119, 121; 120, identifier:register; 121, argument_list; 121, 122; 121, 123; 122, identifier:cls; 123, identifier:f; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:registry; 128, identifier:cls; 129, identifier:func; 130, if_statement; 130, 131; 130, 142; 131, boolean_operator:and; 131, 132; 131, 137; 132, comparison_operator:is; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:ns; 135, identifier:cache_token; 136, None; 137, call; 137, 138; 137, 139; 138, identifier:hasattr; 139, argument_list; 139, 140; 139, 141; 140, identifier:cls; 141, string:'__abstractmethods__'; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:ns; 147, identifier:cache_token; 148, call; 148, 149; 148, 150; 149, identifier:get_cache_token; 150, argument_list; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:dispatch_cache; 155, identifier:clear; 156, argument_list; 157, return_statement; 157, 158; 158, identifier:func; 159, function_definition; 159, 160; 159, 161; 159, 166; 160, function_name:wrapper; 161, parameters; 161, 162; 161, 164; 162, list_splat_pattern; 162, 163; 163, identifier:args; 164, dictionary_splat_pattern; 164, 165; 165, identifier:kw; 166, block; 166, 167; 167, return_statement; 167, 168; 168, call; 168, 169; 168, 177; 169, call; 169, 170; 169, 171; 170, identifier:dispatch; 171, argument_list; 171, 172; 172, attribute; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:args; 175, integer:0; 176, identifier:__class__; 177, argument_list; 177, 178; 177, 180; 178, list_splat; 178, 179; 179, identifier:args; 180, dictionary_splat; 180, 181; 181, identifier:kw; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:registry; 186, identifier:object; 187, identifier:function; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:wrapper; 192, identifier:register; 193, identifier:register; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:wrapper; 198, identifier:dispatch; 199, identifier:dispatch; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:wrapper; 204, identifier:registry; 205, call; 205, 206; 205, 207; 206, identifier:MappingProxyType; 207, argument_list; 207, 208; 208, identifier:registry; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:wrapper; 213, identifier:_clear_cache; 214, attribute; 214, 215; 214, 216; 215, identifier:dispatch_cache; 216, identifier:clear; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 220; 219, identifier:update_wrapper; 220, argument_list; 220, 221; 220, 222; 221, identifier:wrapper; 222, identifier:function; 223, return_statement; 223, 224; 224, identifier:wrapper
def singledispatch(function): registry = {} dispatch_cache = WeakKeyDictionary() def ns(): pass ns.cache_token = None def dispatch(cls): if ns.cache_token is not None: current_token = get_cache_token() if ns.cache_token != current_token: dispatch_cache.clear() ns.cache_token = current_token try: impl = dispatch_cache[cls] except KeyError: try: impl = registry[cls] except KeyError: impl = _find_impl(cls, registry) dispatch_cache[cls] = impl return impl def register(cls, func=None): if func is None: return lambda f: register(cls, f) registry[cls] = func if ns.cache_token is None and hasattr(cls, '__abstractmethods__'): ns.cache_token = get_cache_token() dispatch_cache.clear() return func def wrapper(*args, **kw): return dispatch(args[0].__class__)(*args, **kw) registry[object] = function wrapper.register = register wrapper.dispatch = dispatch wrapper.registry = MappingProxyType(registry) wrapper._clear_cache = dispatch_cache.clear update_wrapper(wrapper, function) return wrapper
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 40; 2, function_name:createResource; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 3, 37; 4, identifier:self; 5, identifier:resource_type; 6, identifier:title; 7, default_parameter; 7, 8; 7, 9; 8, identifier:resource_file; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:resource_filename; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:abstract; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:keywords; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:edit_users; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:view_users; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:edit_groups; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:view_groups; 30, None; 31, default_parameter; 31, 32; 31, 33; 32, identifier:metadata; 33, None; 34, default_parameter; 34, 35; 34, 36; 35, identifier:extra_metadata; 36, None; 37, default_parameter; 37, 38; 37, 39; 38, identifier:progress_callback; 39, None; 40, block; 40, 41; 40, 54; 40, 58; 40, 87; 40, 97; 40, 106; 40, 135; 40, 144; 40, 153; 40, 162; 40, 171; 40, 180; 40, 189; 40, 203; 40, 210; 40, 219; 40, 227; 40, 248; 40, 265; 40, 299; 40, 307; 40, 313; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:url; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, string:"{url_base}/resource/"; 47, identifier:format; 48, argument_list; 48, 49; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:url_base; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:url_base; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:close_fd; 57, False; 58, if_statement; 58, 59; 58, 64; 59, comparison_operator:not; 59, 60; 59, 61; 60, identifier:resource_type; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:resource_types; 64, block; 64, 65; 65, raise_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:HydroShareArgumentException; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:"Resource type {0} is not among known resources: {1}"; 72, identifier:format; 73, argument_list; 73, 74; 73, 75; 74, identifier:resource_type; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, string:", "; 78, identifier:join; 79, argument_list; 79, 80; 80, list_comprehension; 80, 81; 80, 82; 81, identifier:r; 82, for_in_clause; 82, 83; 82, 84; 83, identifier:r; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:resource_types; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:params; 90, dictionary; 90, 91; 90, 94; 91, pair; 91, 92; 91, 93; 92, string:'resource_type'; 93, identifier:resource_type; 94, pair; 94, 95; 94, 96; 95, string:'title'; 96, identifier:title; 97, if_statement; 97, 98; 97, 99; 98, identifier:abstract; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:params; 104, string:'abstract'; 105, identifier:abstract; 106, if_statement; 106, 107; 106, 108; 107, identifier:keywords; 108, block; 108, 109; 109, for_statement; 109, 110; 109, 113; 109, 117; 110, tuple_pattern; 110, 111; 110, 112; 111, identifier:i; 112, identifier:kw; 113, call; 113, 114; 113, 115; 114, identifier:enumerate; 115, argument_list; 115, 116; 116, identifier:keywords; 117, block; 117, 118; 117, 129; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:key; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, string:"keywords[{index}]"; 124, identifier:format; 125, argument_list; 125, 126; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:index; 128, identifier:i; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:params; 133, identifier:key; 134, identifier:kw; 135, if_statement; 135, 136; 135, 137; 136, identifier:edit_users; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:params; 142, string:'edit_users'; 143, identifier:edit_users; 144, if_statement; 144, 145; 144, 146; 145, identifier:view_users; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:params; 151, string:'view_users'; 152, identifier:view_users; 153, if_statement; 153, 154; 153, 155; 154, identifier:edit_groups; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, subscript; 158, 159; 158, 160; 159, identifier:params; 160, string:'edit_groups'; 161, identifier:edit_groups; 162, if_statement; 162, 163; 162, 164; 163, identifier:view_groups; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:params; 169, string:'view_groups'; 170, identifier:view_groups; 171, if_statement; 171, 172; 171, 173; 172, identifier:metadata; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:params; 178, string:'metadata'; 179, identifier:metadata; 180, if_statement; 180, 181; 180, 182; 181, identifier:extra_metadata; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:params; 187, string:'extra_metadata'; 188, identifier:extra_metadata; 189, if_statement; 189, 190; 189, 191; 190, identifier:resource_file; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:close_fd; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:_prepareFileForUpload; 199, argument_list; 199, 200; 199, 201; 199, 202; 200, identifier:params; 201, identifier:resource_file; 202, identifier:resource_filename; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:encoder; 206, call; 206, 207; 206, 208; 207, identifier:MultipartEncoder; 208, argument_list; 208, 209; 209, identifier:params; 210, if_statement; 210, 211; 210, 214; 211, comparison_operator:is; 211, 212; 211, 213; 212, identifier:progress_callback; 213, None; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:progress_callback; 218, identifier:default_progress_callback; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:monitor; 222, call; 222, 223; 222, 224; 223, identifier:MultipartEncoderMonitor; 224, argument_list; 224, 225; 224, 226; 225, identifier:encoder; 226, identifier:progress_callback; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:r; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:_request; 234, argument_list; 234, 235; 234, 236; 234, 237; 234, 240; 235, string:'POST'; 236, identifier:url; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:data; 239, identifier:monitor; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:headers; 242, dictionary; 242, 243; 243, pair; 243, 244; 243, 245; 244, string:'Content-Type'; 245, attribute; 245, 246; 245, 247; 246, identifier:monitor; 247, identifier:content_type; 248, if_statement; 248, 249; 248, 250; 249, identifier:close_fd; 250, block; 250, 251; 250, 259; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:fd; 254, subscript; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:params; 257, string:'file'; 258, integer:1; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:fd; 263, identifier:close; 264, argument_list; 265, if_statement; 265, 266; 265, 271; 266, comparison_operator:!=; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:r; 269, identifier:status_code; 270, integer:201; 271, block; 271, 272; 272, if_statement; 272, 273; 272, 278; 272, 286; 273, comparison_operator:==; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:r; 276, identifier:status_code; 277, integer:403; 278, block; 278, 279; 279, raise_statement; 279, 280; 280, call; 280, 281; 280, 282; 281, identifier:HydroShareNotAuthorized; 282, argument_list; 282, 283; 283, tuple; 283, 284; 283, 285; 284, string:'POST'; 285, identifier:url; 286, else_clause; 286, 287; 287, block; 287, 288; 288, raise_statement; 288, 289; 289, call; 289, 290; 289, 291; 290, identifier:HydroShareHTTPException; 291, argument_list; 291, 292; 292, tuple; 292, 293; 292, 294; 292, 295; 292, 298; 293, identifier:url; 294, string:'POST'; 295, attribute; 295, 296; 295, 297; 296, identifier:r; 297, identifier:status_code; 298, identifier:params; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:response; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:r; 305, identifier:json; 306, argument_list; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:new_resource_id; 310, subscript; 310, 311; 310, 312; 311, identifier:response; 312, string:'resource_id'; 313, return_statement; 313, 314; 314, identifier:new_resource_id
def createResource(self, resource_type, title, resource_file=None, resource_filename=None, abstract=None, keywords=None, edit_users=None, view_users=None, edit_groups=None, view_groups=None, metadata=None, extra_metadata=None, progress_callback=None): url = "{url_base}/resource/".format(url_base=self.url_base) close_fd = False if resource_type not in self.resource_types: raise HydroShareArgumentException("Resource type {0} is not among known resources: {1}".format(resource_type, ", ".join([r for r in self.resource_types]))) params = {'resource_type': resource_type, 'title': title} if abstract: params['abstract'] = abstract if keywords: for (i, kw) in enumerate(keywords): key = "keywords[{index}]".format(index=i) params[key] = kw if edit_users: params['edit_users'] = edit_users if view_users: params['view_users'] = view_users if edit_groups: params['edit_groups'] = edit_groups if view_groups: params['view_groups'] = view_groups if metadata: params['metadata'] = metadata if extra_metadata: params['extra_metadata'] = extra_metadata if resource_file: close_fd = self._prepareFileForUpload(params, resource_file, resource_filename) encoder = MultipartEncoder(params) if progress_callback is None: progress_callback = default_progress_callback monitor = MultipartEncoderMonitor(encoder, progress_callback) r = self._request('POST', url, data=monitor, headers={'Content-Type': monitor.content_type}) if close_fd: fd = params['file'][1] fd.close() if r.status_code != 201: if r.status_code == 403: raise HydroShareNotAuthorized(('POST', url)) else: raise HydroShareHTTPException((url, 'POST', r.status_code, params)) response = r.json() new_resource_id = response['resource_id'] return new_resource_id
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:getResourceFile; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:pid; 6, identifier:filename; 7, default_parameter; 7, 8; 7, 9; 8, identifier:destination; 9, None; 10, block; 10, 11; 10, 30; 10, 76; 10, 89; 10, 136; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:url; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, string:"{url_base}/resource/{pid}/files/{filename}"; 17, identifier:format; 18, argument_list; 18, 19; 18, 24; 18, 27; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:url_base; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:url_base; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:pid; 26, identifier:pid; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:filename; 29, identifier:filename; 30, if_statement; 30, 31; 30, 32; 31, identifier:destination; 32, block; 32, 33; 32, 54; 33, if_statement; 33, 34; 33, 43; 34, not_operator; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:os; 39, identifier:path; 40, identifier:isdir; 41, argument_list; 41, 42; 42, identifier:destination; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:HydroShareArgumentException; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, string:"{0} is not a directory."; 51, identifier:format; 52, argument_list; 52, 53; 53, identifier:destination; 54, if_statement; 54, 55; 54, 65; 55, not_operator; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:os; 59, identifier:access; 60, argument_list; 60, 61; 60, 62; 61, identifier:destination; 62, attribute; 62, 63; 62, 64; 63, identifier:os; 64, identifier:W_OK; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:HydroShareArgumentException; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, string:"You do not have write permissions to directory '{0}'."; 73, identifier:format; 74, argument_list; 74, 75; 75, identifier:destination; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:r; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:_request; 83, argument_list; 83, 84; 83, 85; 83, 86; 84, string:'GET'; 85, identifier:url; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:stream; 88, True; 89, if_statement; 89, 90; 89, 95; 90, comparison_operator:!=; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:r; 93, identifier:status_code; 94, integer:200; 95, block; 95, 96; 96, if_statement; 96, 97; 96, 102; 96, 110; 96, 124; 97, comparison_operator:==; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:r; 100, identifier:status_code; 101, integer:403; 102, block; 102, 103; 103, raise_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:HydroShareNotAuthorized; 106, argument_list; 106, 107; 107, tuple; 107, 108; 107, 109; 108, string:'GET'; 109, identifier:url; 110, elif_clause; 110, 111; 110, 116; 111, comparison_operator:==; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:r; 114, identifier:status_code; 115, integer:404; 116, block; 116, 117; 117, raise_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:HydroShareNotFound; 120, argument_list; 120, 121; 121, tuple; 121, 122; 121, 123; 122, identifier:pid; 123, identifier:filename; 124, else_clause; 124, 125; 125, block; 125, 126; 126, raise_statement; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:HydroShareHTTPException; 129, argument_list; 129, 130; 130, tuple; 130, 131; 130, 132; 130, 133; 131, identifier:url; 132, string:'GET'; 133, attribute; 133, 134; 133, 135; 134, identifier:r; 135, identifier:status_code; 136, if_statement; 136, 137; 136, 140; 136, 148; 137, comparison_operator:is; 137, 138; 137, 139; 138, identifier:destination; 139, None; 140, block; 140, 141; 141, return_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:r; 145, identifier:iter_content; 146, argument_list; 146, 147; 147, identifier:STREAM_CHUNK_SIZE; 148, else_clause; 148, 149; 149, block; 149, 150; 149, 162; 149, 190; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:filepath; 153, call; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:os; 157, identifier:path; 158, identifier:join; 159, argument_list; 159, 160; 159, 161; 160, identifier:destination; 161, identifier:filename; 162, with_statement; 162, 163; 162, 173; 163, with_clause; 163, 164; 164, with_item; 164, 165; 165, as_pattern; 165, 166; 165, 171; 166, call; 166, 167; 166, 168; 167, identifier:open; 168, argument_list; 168, 169; 168, 170; 169, identifier:filepath; 170, string:'wb'; 171, as_pattern_target; 171, 172; 172, identifier:fd; 173, block; 173, 174; 174, for_statement; 174, 175; 174, 176; 174, 182; 175, identifier:chunk; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:r; 179, identifier:iter_content; 180, argument_list; 180, 181; 181, identifier:STREAM_CHUNK_SIZE; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:fd; 187, identifier:write; 188, argument_list; 188, 189; 189, identifier:chunk; 190, return_statement; 190, 191; 191, identifier:filepath
def getResourceFile(self, pid, filename, destination=None): url = "{url_base}/resource/{pid}/files/{filename}".format(url_base=self.url_base, pid=pid, filename=filename) if destination: if not os.path.isdir(destination): raise HydroShareArgumentException("{0} is not a directory.".format(destination)) if not os.access(destination, os.W_OK): raise HydroShareArgumentException("You do not have write permissions to directory '{0}'.".format(destination)) r = self._request('GET', url, stream=True) if r.status_code != 200: if r.status_code == 403: raise HydroShareNotAuthorized(('GET', url)) elif r.status_code == 404: raise HydroShareNotFound((pid, filename)) else: raise HydroShareHTTPException((url, 'GET', r.status_code)) if destination is None: return r.iter_content(STREAM_CHUNK_SIZE) else: filepath = os.path.join(destination, filename) with open(filepath, 'wb') as fd: for chunk in r.iter_content(STREAM_CHUNK_SIZE): fd.write(chunk) return filepath
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:upsert; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 16; 5, 29; 5, 449; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:required_parameters; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_stackParameters; 15, list:[]; 16, try_statement; 16, 17; 16, 24; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_initialize_upsert; 23, argument_list; 24, except_clause; 24, 25; 24, 26; 25, identifier:Exception; 26, block; 26, 27; 27, return_statement; 27, 28; 28, False; 29, try_statement; 29, 30; 29, 414; 30, block; 30, 31; 30, 41; 30, 63; 30, 75; 30, 87; 30, 91; 30, 155; 30, 170; 30, 221; 30, 243; 30, 261; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:available_parameters; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_parameters; 39, identifier:keys; 40, argument_list; 41, for_statement; 41, 42; 41, 43; 41, 52; 42, identifier:parameter_name; 43, call; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:_template; 48, identifier:get; 49, argument_list; 49, 50; 49, 51; 50, string:'Parameters'; 51, dictionary; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:required_parameters; 57, identifier:append; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:str; 61, argument_list; 61, 62; 62, identifier:parameter_name; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:logging; 67, identifier:info; 68, argument_list; 68, 69; 69, binary_operator:+; 69, 70; 69, 71; 70, string:' required parameters: '; 71, call; 71, 72; 71, 73; 72, identifier:str; 73, argument_list; 73, 74; 74, identifier:required_parameters; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:logging; 79, identifier:info; 80, argument_list; 80, 81; 81, binary_operator:+; 81, 82; 81, 83; 82, string:'available parameters: '; 83, call; 83, 84; 83, 85; 84, identifier:str; 85, argument_list; 85, 86; 86, identifier:available_parameters; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:parameters; 90, list:[]; 91, for_statement; 91, 92; 91, 93; 91, 94; 92, identifier:required_parameter; 93, identifier:required_parameters; 94, block; 94, 95; 94, 99; 94, 108; 94, 115; 94, 148; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:parameter; 98, dictionary; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:parameter; 103, string:'ParameterKey'; 104, call; 104, 105; 104, 106; 105, identifier:str; 106, argument_list; 106, 107; 107, identifier:required_parameter; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:required_parameter; 111, call; 111, 112; 111, 113; 112, identifier:str; 113, argument_list; 113, 114; 114, identifier:required_parameter; 115, if_statement; 115, 116; 115, 121; 115, 132; 116, comparison_operator:in; 116, 117; 116, 118; 117, identifier:required_parameter; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:_parameters; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:parameter; 126, string:'ParameterValue'; 127, subscript; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:_parameters; 131, identifier:required_parameter; 132, else_clause; 132, 133; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, subscript; 136, 137; 136, 138; 137, identifier:parameter; 138, string:'ParameterValue'; 139, subscript; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:_parameters; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:required_parameter; 146, identifier:lower; 147, argument_list; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:parameters; 152, identifier:append; 153, argument_list; 153, 154; 154, identifier:parameter; 155, if_statement; 155, 156; 155, 162; 156, not_operator; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:_analyze_stuff; 161, argument_list; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:sys; 167, identifier:exit; 168, argument_list; 168, 169; 169, integer:1; 170, if_statement; 170, 171; 170, 180; 171, call; 171, 172; 171, 177; 172, attribute; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:_config; 176, identifier:get; 177, argument_list; 177, 178; 177, 179; 178, string:'dryrun'; 179, False; 180, block; 180, 181; 180, 188; 180, 197; 180, 207; 180, 214; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:logging; 185, identifier:info; 186, argument_list; 186, 187; 187, string:'Generating change set'; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:set_id; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:_generate_change_set; 195, argument_list; 195, 196; 196, identifier:parameters; 197, if_statement; 197, 198; 197, 199; 198, identifier:set_id; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:_describe_change_set; 205, argument_list; 205, 206; 206, identifier:set_id; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:logging; 211, identifier:info; 212, argument_list; 212, 213; 213, string:'This was a dryrun'; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:sys; 218, identifier:exit; 219, argument_list; 219, 220; 220, integer:0; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 228; 223, attribute; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:_tags; 227, identifier:append; 228, argument_list; 228, 229; 229, dictionary; 229, 230; 229, 233; 230, pair; 230, 231; 230, 232; 231, string:"Key"; 232, string:"CODE_VERSION_SD"; 233, pair; 233, 234; 233, 235; 234, string:"Value"; 235, call; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:_config; 240, identifier:get; 241, argument_list; 241, 242; 242, string:'codeVersion'; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 250; 245, attribute; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:_tags; 249, identifier:append; 250, argument_list; 250, 251; 251, dictionary; 251, 252; 251, 255; 252, pair; 252, 253; 252, 254; 253, string:"Key"; 254, string:"ANSWER"; 255, pair; 255, 256; 255, 257; 256, string:"Value"; 257, call; 257, 258; 257, 259; 258, identifier:str; 259, argument_list; 259, 260; 260, integer:42; 261, if_statement; 261, 262; 261, 265; 261, 339; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:_updateStack; 265, block; 265, 266; 265, 321; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:stack; 269, call; 269, 270; 269, 275; 270, attribute; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:self; 273, identifier:_cloudFormation; 274, identifier:update_stack; 275, argument_list; 275, 276; 275, 293; 275, 298; 275, 301; 275, 306; 275, 311; 276, keyword_argument; 276, 277; 276, 278; 277, identifier:StackName; 278, call; 278, 279; 278, 290; 279, attribute; 279, 280; 279, 289; 280, call; 280, 281; 280, 286; 281, attribute; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:_config; 285, identifier:get; 286, argument_list; 286, 287; 286, 288; 287, string:'environment'; 288, dictionary; 289, identifier:get; 290, argument_list; 290, 291; 290, 292; 291, string:'stack_name'; 292, None; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:TemplateURL; 295, attribute; 295, 296; 295, 297; 296, identifier:self; 297, identifier:_templateUrl; 298, keyword_argument; 298, 299; 298, 300; 299, identifier:Parameters; 300, identifier:parameters; 301, keyword_argument; 301, 302; 301, 303; 302, identifier:Capabilities; 303, list:['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']; 303, 304; 303, 305; 304, string:'CAPABILITY_IAM'; 305, string:'CAPABILITY_NAMED_IAM'; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:Tags; 308, attribute; 308, 309; 308, 310; 309, identifier:self; 310, identifier:_tags; 311, keyword_argument; 311, 312; 311, 313; 312, identifier:ClientRequestToken; 313, call; 313, 314; 313, 315; 314, identifier:str; 315, argument_list; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:uuid; 319, identifier:uuid4; 320, argument_list; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:logging; 325, identifier:info; 326, argument_list; 326, 327; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, string:'existing stack ID: {}'; 330, identifier:format; 331, argument_list; 331, 332; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:stack; 335, identifier:get; 336, argument_list; 336, 337; 336, 338; 337, string:'StackId'; 338, string:'unknown'; 339, else_clause; 339, 340; 340, block; 340, 341; 340, 396; 341, expression_statement; 341, 342; 342, assignment; 342, 343; 342, 344; 343, identifier:stack; 344, call; 344, 345; 344, 350; 345, attribute; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:self; 348, identifier:_cloudFormation; 349, identifier:create_stack; 350, argument_list; 350, 351; 350, 368; 350, 373; 350, 376; 350, 381; 350, 386; 351, keyword_argument; 351, 352; 351, 353; 352, identifier:StackName; 353, call; 353, 354; 353, 365; 354, attribute; 354, 355; 354, 364; 355, call; 355, 356; 355, 361; 356, attribute; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:self; 359, identifier:_config; 360, identifier:get; 361, argument_list; 361, 362; 361, 363; 362, string:'environment'; 363, dictionary; 364, identifier:get; 365, argument_list; 365, 366; 365, 367; 366, string:'stack_name'; 367, None; 368, keyword_argument; 368, 369; 368, 370; 369, identifier:TemplateURL; 370, attribute; 370, 371; 370, 372; 371, identifier:self; 372, identifier:_templateUrl; 373, keyword_argument; 373, 374; 373, 375; 374, identifier:Parameters; 375, identifier:parameters; 376, keyword_argument; 376, 377; 376, 378; 377, identifier:Capabilities; 378, list:['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']; 378, 379; 378, 380; 379, string:'CAPABILITY_IAM'; 380, string:'CAPABILITY_NAMED_IAM'; 381, keyword_argument; 381, 382; 381, 383; 382, identifier:Tags; 383, attribute; 383, 384; 383, 385; 384, identifier:self; 385, identifier:_tags; 386, keyword_argument; 386, 387; 386, 388; 387, identifier:ClientRequestToken; 388, call; 388, 389; 388, 390; 389, identifier:str; 390, argument_list; 390, 391; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:uuid; 394, identifier:uuid4; 395, argument_list; 396, expression_statement; 396, 397; 397, call; 397, 398; 397, 401; 398, attribute; 398, 399; 398, 400; 399, identifier:logging; 400, identifier:info; 401, argument_list; 401, 402; 402, call; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, string:'new stack ID: {}'; 405, identifier:format; 406, argument_list; 406, 407; 407, call; 407, 408; 407, 411; 408, attribute; 408, 409; 408, 410; 409, identifier:stack; 410, identifier:get; 411, argument_list; 411, 412; 411, 413; 412, string:'StackId'; 413, string:'unknown'; 414, except_clause; 414, 415; 414, 419; 415, as_pattern; 415, 416; 415, 417; 416, identifier:Exception; 417, as_pattern_target; 417, 418; 418, identifier:x; 419, block; 419, 420; 419, 447; 420, if_statement; 420, 421; 420, 424; 420, 435; 421, attribute; 421, 422; 421, 423; 422, identifier:self; 423, identifier:_verbose; 424, block; 424, 425; 425, expression_statement; 425, 426; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:logging; 429, identifier:error; 430, argument_list; 430, 431; 430, 432; 431, identifier:x; 432, keyword_argument; 432, 433; 432, 434; 433, identifier:exc_info; 434, True; 435, else_clause; 435, 436; 436, block; 436, 437; 437, expression_statement; 437, 438; 438, call; 438, 439; 438, 442; 439, attribute; 439, 440; 439, 441; 440, identifier:logging; 441, identifier:error; 442, argument_list; 442, 443; 442, 444; 443, identifier:x; 444, keyword_argument; 444, 445; 444, 446; 445, identifier:exc_info; 446, False; 447, return_statement; 447, 448; 448, False; 449, return_statement; 449, 450; 450, True
def upsert(self): required_parameters = [] self._stackParameters = [] try: self._initialize_upsert() except Exception: return False try: available_parameters = self._parameters.keys() for parameter_name in self._template.get('Parameters', {}): required_parameters.append(str(parameter_name)) logging.info(' required parameters: ' + str(required_parameters)) logging.info('available parameters: ' + str(available_parameters)) parameters = [] for required_parameter in required_parameters: parameter = {} parameter['ParameterKey'] = str(required_parameter) required_parameter = str(required_parameter) if required_parameter in self._parameters: parameter['ParameterValue'] = self._parameters[required_parameter] else: parameter['ParameterValue'] = self._parameters[required_parameter.lower()] parameters.append(parameter) if not self._analyze_stuff(): sys.exit(1) if self._config.get('dryrun', False): logging.info('Generating change set') set_id = self._generate_change_set(parameters) if set_id: self._describe_change_set(set_id) logging.info('This was a dryrun') sys.exit(0) self._tags.append({"Key": "CODE_VERSION_SD", "Value": self._config.get('codeVersion')}) self._tags.append({"Key": "ANSWER", "Value": str(42)}) if self._updateStack: stack = self._cloudFormation.update_stack( StackName=self._config.get('environment', {}).get('stack_name', None), TemplateURL=self._templateUrl, Parameters=parameters, Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'], Tags=self._tags, ClientRequestToken=str(uuid.uuid4()) ) logging.info('existing stack ID: {}'.format(stack.get('StackId', 'unknown'))) else: stack = self._cloudFormation.create_stack( StackName=self._config.get('environment', {}).get('stack_name', None), TemplateURL=self._templateUrl, Parameters=parameters, Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'], Tags=self._tags, ClientRequestToken=str(uuid.uuid4()) ) logging.info('new stack ID: {}'.format(stack.get('StackId', 'unknown'))) except Exception as x: if self._verbose: logging.error(x, exc_info=True) else: logging.error(x, exc_info=False) return False return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:dump; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:obj; 5, default_parameter; 5, 6; 5, 7; 6, identifier:fp; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:indent; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort_keys; 13, False; 14, dictionary_splat_pattern; 14, 15; 15, identifier:kw; 16, block; 16, 17; 17, if_statement; 17, 18; 17, 19; 17, 50; 18, identifier:fp; 19, block; 19, 20; 19, 39; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:iterable; 23, call; 23, 24; 23, 37; 24, attribute; 24, 25; 24, 36; 25, call; 25, 26; 25, 27; 26, identifier:YAMLEncoder; 27, argument_list; 27, 28; 27, 31; 27, 34; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:indent; 30, identifier:indent; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:sort_keys; 33, identifier:sort_keys; 34, dictionary_splat; 34, 35; 35, identifier:kw; 36, identifier:iterencode; 37, argument_list; 37, 38; 38, identifier:obj; 39, for_statement; 39, 40; 39, 41; 39, 42; 40, identifier:chunk; 41, identifier:iterable; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:fp; 47, identifier:write; 48, argument_list; 48, 49; 49, identifier:chunk; 50, else_clause; 50, 51; 51, block; 51, 52; 52, return_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:dumps; 55, argument_list; 55, 56; 55, 57; 55, 60; 55, 63; 56, identifier:obj; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:indent; 59, identifier:indent; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:sort_keys; 62, identifier:sort_keys; 63, dictionary_splat; 63, 64; 64, identifier:kw
def dump(obj, fp=None, indent=None, sort_keys=False, **kw): if fp: iterable = YAMLEncoder(indent=indent, sort_keys=sort_keys, **kw).iterencode(obj) for chunk in iterable: fp.write(chunk) else: return dumps(obj, indent=indent, sort_keys=sort_keys, **kw)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_reference; 3, parameters; 3, 4; 4, identifier:root; 5, block; 5, 6; 5, 10; 5, 19; 5, 29; 5, 39; 5, 49; 5, 316; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:reference; 9, dictionary; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:elem; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:root; 16, identifier:find; 17, argument_list; 17, 18; 18, string:'bibliographyLink'; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:elem; 22, None; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:MissingElementError; 27, argument_list; 27, 28; 28, string:'bibliographyLink'; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:ref_doi; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:elem; 35, identifier:get; 36, argument_list; 36, 37; 36, 38; 37, string:'doi'; 38, None; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:ref_key; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:elem; 45, identifier:get; 46, argument_list; 46, 47; 46, 48; 47, string:'preferredKey'; 48, None; 49, if_statement; 49, 50; 49, 53; 49, 274; 49, 308; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:ref_doi; 52, None; 53, block; 53, 54; 54, try_statement; 54, 55; 54, 69; 54, 118; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:ref; 59, subscript; 59, 60; 59, 68; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:crossref_api; 63, identifier:works; 64, argument_list; 64, 65; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:ids; 67, identifier:ref_doi; 68, string:'message'; 69, except_clause; 69, 70; 69, 76; 70, tuple; 70, 71; 70, 72; 70, 75; 71, identifier:HTTPError; 72, attribute; 72, 73; 72, 74; 73, identifier:habanero; 74, identifier:RequestError; 75, identifier:ConnectionError; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 81; 77, 87; 78, comparison_operator:is; 78, 79; 78, 80; 79, identifier:ref_key; 80, None; 81, block; 81, 82; 82, raise_statement; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:KeywordError; 85, argument_list; 85, 86; 86, string:'DOI not found and preferredKey attribute not set'; 87, else_clause; 87, 88; 88, block; 88, 89; 88, 96; 88, 102; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:warn; 92, argument_list; 92, 93; 93, concatenated_string; 93, 94; 93, 95; 94, string:'Missing doi attribute in bibliographyLink or lookup failed. '; 95, string:'Setting "detail" key as a fallback; please update to the appropriate fields.'; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:reference; 100, string:'detail'; 101, identifier:ref_key; 102, if_statement; 102, 103; 102, 111; 103, comparison_operator:!=; 103, 104; 103, 110; 104, subscript; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:reference; 107, string:'detail'; 108, unary_operator:-; 108, 109; 109, integer:1; 110, string:'.'; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, augmented_assignment:+=; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:reference; 116, string:'detail'; 117, string:'.'; 118, else_clause; 118, 119; 119, block; 119, 120; 119, 130; 119, 140; 119, 153; 119, 169; 119, 184; 119, 198; 119, 209; 119, 215; 120, if_statement; 120, 121; 120, 124; 121, comparison_operator:is; 121, 122; 121, 123; 122, identifier:ref_key; 123, None; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:warn; 128, argument_list; 128, 129; 129, string:'Using DOI to obtain reference information, rather than preferredKey.'; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:reference; 134, string:'doi'; 135, subscript; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:elem; 138, identifier:attrib; 139, string:'doi'; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:reference; 144, string:'journal'; 145, subscript; 145, 146; 145, 152; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:ref; 149, identifier:get; 150, argument_list; 150, 151; 151, string:'container-title'; 152, integer:0; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:ref_year; 156, boolean_operator:or; 156, 157; 156, 163; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:ref; 160, identifier:get; 161, argument_list; 161, 162; 162, string:'published-print'; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:ref; 166, identifier:get; 167, argument_list; 167, 168; 168, string:'published-online'; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:reference; 173, string:'year'; 174, call; 174, 175; 174, 176; 175, identifier:int; 176, argument_list; 176, 177; 177, subscript; 177, 178; 177, 183; 178, subscript; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:ref_year; 181, string:'date-parts'; 182, integer:0; 183, integer:0; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:reference; 188, string:'volume'; 189, call; 189, 190; 189, 191; 190, identifier:int; 191, argument_list; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:ref; 195, identifier:get; 196, argument_list; 196, 197; 197, string:'volume'; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:reference; 202, string:'pages'; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:ref; 206, identifier:get; 207, argument_list; 207, 208; 208, string:'page'; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:reference; 213, string:'authors'; 214, list:[]; 215, for_statement; 215, 216; 215, 217; 215, 220; 216, identifier:author; 217, subscript; 217, 218; 217, 219; 218, identifier:ref; 219, string:'author'; 220, block; 220, 221; 220, 225; 220, 242; 220, 251; 220, 265; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:auth; 224, dictionary; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 230; 227, subscript; 227, 228; 227, 229; 228, identifier:auth; 229, string:'name'; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, string:' '; 233, identifier:join; 234, argument_list; 234, 235; 235, list:[author['given'], author['family']]; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:author; 238, string:'given'; 239, subscript; 239, 240; 239, 241; 240, identifier:author; 241, string:'family'; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:orcid; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:author; 248, identifier:get; 249, argument_list; 249, 250; 250, string:'ORCID'; 251, if_statement; 251, 252; 251, 253; 252, identifier:orcid; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 259; 256, subscript; 256, 257; 256, 258; 257, identifier:auth; 258, string:'ORCID'; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:orcid; 262, identifier:lstrip; 263, argument_list; 263, 264; 264, string:'http://orcid.org/'; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 272; 267, attribute; 267, 268; 267, 271; 268, subscript; 268, 269; 268, 270; 269, identifier:reference; 270, string:'authors'; 271, identifier:append; 272, argument_list; 272, 273; 273, identifier:auth; 274, elif_clause; 274, 275; 274, 278; 275, comparison_operator:is; 275, 276; 275, 277; 276, identifier:ref_key; 277, None; 278, block; 278, 279; 278, 286; 278, 292; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 282; 281, identifier:warn; 282, argument_list; 282, 283; 283, concatenated_string; 283, 284; 283, 285; 284, string:'Missing doi attribute in bibliographyLink. '; 285, string:'Setting "detail" key as a fallback; please update to the appropriate fields.'; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 291; 288, subscript; 288, 289; 288, 290; 289, identifier:reference; 290, string:'detail'; 291, identifier:ref_key; 292, if_statement; 292, 293; 292, 301; 293, comparison_operator:!=; 293, 294; 293, 300; 294, subscript; 294, 295; 294, 298; 295, subscript; 295, 296; 295, 297; 296, identifier:reference; 297, string:'detail'; 298, unary_operator:-; 298, 299; 299, integer:1; 300, string:'.'; 301, block; 301, 302; 302, expression_statement; 302, 303; 303, augmented_assignment:+=; 303, 304; 303, 307; 304, subscript; 304, 305; 304, 306; 305, identifier:reference; 306, string:'detail'; 307, string:'.'; 308, else_clause; 308, 309; 309, block; 309, 310; 310, raise_statement; 310, 311; 311, call; 311, 312; 311, 313; 312, identifier:MissingAttributeError; 313, argument_list; 313, 314; 313, 315; 314, string:'preferredKey'; 315, string:'bibliographyLink'; 316, return_statement; 316, 317; 317, identifier:reference
def get_reference(root): reference = {} elem = root.find('bibliographyLink') if elem is None: raise MissingElementError('bibliographyLink') ref_doi = elem.get('doi', None) ref_key = elem.get('preferredKey', None) if ref_doi is not None: try: ref = crossref_api.works(ids=ref_doi)['message'] except (HTTPError, habanero.RequestError, ConnectionError): if ref_key is None: raise KeywordError('DOI not found and preferredKey attribute not set') else: warn('Missing doi attribute in bibliographyLink or lookup failed. ' 'Setting "detail" key as a fallback; please update to the appropriate fields.' ) reference['detail'] = ref_key if reference['detail'][-1] != '.': reference['detail'] += '.' else: if ref_key is not None: warn('Using DOI to obtain reference information, rather than preferredKey.') reference['doi'] = elem.attrib['doi'] reference['journal'] = ref.get('container-title')[0] ref_year = ref.get('published-print') or ref.get('published-online') reference['year'] = int(ref_year['date-parts'][0][0]) reference['volume'] = int(ref.get('volume')) reference['pages'] = ref.get('page') reference['authors'] = [] for author in ref['author']: auth = {} auth['name'] = ' '.join([author['given'], author['family']]) orcid = author.get('ORCID') if orcid: auth['ORCID'] = orcid.lstrip('http://orcid.org/') reference['authors'].append(auth) elif ref_key is not None: warn('Missing doi attribute in bibliographyLink. ' 'Setting "detail" key as a fallback; please update to the appropriate fields.' ) reference['detail'] = ref_key if reference['detail'][-1] != '.': reference['detail'] += '.' else: raise MissingAttributeError('preferredKey', 'bibliographyLink') return reference
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:ReSpecTh_to_ChemKED; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 12; 4, identifier:filename_xml; 5, default_parameter; 5, 6; 5, 7; 6, identifier:file_author; 7, string:''; 8, default_parameter; 8, 9; 8, 10; 9, identifier:file_author_orcid; 10, string:''; 11, keyword_separator; 12, default_parameter; 12, 13; 12, 14; 13, identifier:validate; 14, False; 15, block; 15, 16; 15, 25; 15, 33; 15, 40; 15, 49; 15, 77; 15, 87; 15, 96; 15, 107; 15, 116; 15, 140; 15, 156; 15, 186; 15, 202; 15, 213; 15, 241; 15, 273; 15, 285; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:tree; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:etree; 22, identifier:parse; 23, argument_list; 23, 24; 24, identifier:filename_xml; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:root; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:tree; 31, identifier:getroot; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:properties; 36, call; 36, 37; 36, 38; 37, identifier:get_file_metadata; 38, argument_list; 38, 39; 39, identifier:root; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:properties; 44, string:'reference'; 45, call; 45, 46; 45, 47; 46, identifier:get_reference; 47, argument_list; 47, 48; 48, identifier:root; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 56; 51, subscript; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:properties; 54, string:'reference'; 55, string:'detail'; 56, parenthesized_expression; 56, 57; 57, binary_operator:+; 57, 58; 57, 69; 58, binary_operator:+; 58, 59; 58, 68; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:properties; 63, string:'reference'; 64, identifier:get; 65, argument_list; 65, 66; 65, 67; 66, string:'detail'; 67, string:''; 68, string:'Converted from ReSpecTh XML file '; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:os; 73, identifier:path; 74, identifier:basename; 75, argument_list; 75, 76; 76, identifier:filename_xml; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:properties; 81, identifier:update; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:get_experiment_kind; 85, argument_list; 85, 86; 86, identifier:root; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:properties; 91, string:'common-properties'; 92, call; 92, 93; 92, 94; 93, identifier:get_common_properties; 94, argument_list; 94, 95; 95, identifier:root; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 103; 98, subscript; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:properties; 101, string:'common-properties'; 102, string:'ignition-type'; 103, call; 103, 104; 103, 105; 104, identifier:get_ignition_type; 105, argument_list; 105, 106; 106, identifier:root; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:properties; 111, string:'datapoints'; 112, call; 112, 113; 112, 114; 113, identifier:get_datapoints; 114, argument_list; 114, 115; 115, identifier:root; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:has_pres_rise; 119, parenthesized_expression; 119, 120; 120, boolean_operator:or; 120, 121; 120, 126; 121, comparison_operator:in; 121, 122; 121, 123; 122, string:'pressure-rise'; 123, subscript; 123, 124; 123, 125; 124, identifier:properties; 125, string:'common-properties'; 126, call; 126, 127; 126, 128; 127, identifier:any; 128, argument_list; 128, 129; 129, list_comprehension; 129, 130; 129, 131; 129, 136; 130, True; 131, for_in_clause; 131, 132; 131, 133; 132, identifier:dp; 133, subscript; 133, 134; 133, 135; 134, identifier:properties; 135, string:'datapoints'; 136, if_clause; 136, 137; 137, comparison_operator:in; 137, 138; 137, 139; 138, string:'pressure-rise'; 139, identifier:dp; 140, if_statement; 140, 141; 140, 150; 141, boolean_operator:and; 141, 142; 141, 143; 142, identifier:has_pres_rise; 143, comparison_operator:==; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:properties; 147, string:'apparatus'; 148, string:'kind'; 149, string:'rapid compression machine'; 150, block; 150, 151; 151, raise_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:KeywordError; 154, argument_list; 154, 155; 155, string:'Pressure rise cannot be defined for RCM.'; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:has_vol_hist; 159, call; 159, 160; 159, 161; 160, identifier:any; 161, argument_list; 161, 162; 162, list_comprehension; 162, 163; 162, 171; 162, 176; 163, comparison_operator:==; 163, 164; 163, 170; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:t; 167, identifier:get; 168, argument_list; 168, 169; 169, string:'type'; 170, string:'volume'; 171, for_in_clause; 171, 172; 171, 173; 172, identifier:dp; 173, subscript; 173, 174; 173, 175; 174, identifier:properties; 175, string:'datapoints'; 176, for_in_clause; 176, 177; 176, 178; 177, identifier:t; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:dp; 181, identifier:get; 182, argument_list; 182, 183; 182, 184; 183, string:'time-histories'; 184, list:[{}]; 184, 185; 185, dictionary; 186, if_statement; 186, 187; 186, 196; 187, boolean_operator:and; 187, 188; 187, 189; 188, identifier:has_vol_hist; 189, comparison_operator:==; 189, 190; 189, 195; 190, subscript; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:properties; 193, string:'apparatus'; 194, string:'kind'; 195, string:'shock tube'; 196, block; 196, 197; 197, raise_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:KeywordError; 200, argument_list; 200, 201; 201, string:'Volume history cannot be defined for shock tube.'; 202, if_statement; 202, 203; 202, 207; 203, boolean_operator:and; 203, 204; 203, 205; 204, identifier:file_author_orcid; 205, not_operator; 205, 206; 206, identifier:file_author; 207, block; 207, 208; 208, raise_statement; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:KeywordError; 211, argument_list; 211, 212; 212, string:'If file_author_orcid is specified, file_author must be as well'; 213, if_statement; 213, 214; 213, 215; 214, identifier:file_author; 215, block; 215, 216; 215, 223; 215, 232; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:temp_author; 219, dictionary; 219, 220; 220, pair; 220, 221; 220, 222; 221, string:'name'; 222, identifier:file_author; 223, if_statement; 223, 224; 223, 225; 224, identifier:file_author_orcid; 225, block; 225, 226; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:temp_author; 230, string:'ORCID'; 231, identifier:file_author_orcid; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 239; 234, attribute; 234, 235; 234, 238; 235, subscript; 235, 236; 235, 237; 236, identifier:properties; 237, string:'file-authors'; 238, identifier:append; 239, argument_list; 239, 240; 240, identifier:temp_author; 241, for_statement; 241, 242; 241, 243; 241, 252; 242, identifier:idx; 243, call; 243, 244; 243, 245; 244, identifier:range; 245, argument_list; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:len; 248, argument_list; 248, 249; 249, subscript; 249, 250; 249, 251; 250, identifier:properties; 251, string:'datapoints'; 252, block; 252, 253; 253, for_statement; 253, 254; 253, 255; 253, 258; 254, identifier:prop; 255, subscript; 255, 256; 255, 257; 256, identifier:properties; 257, string:'common-properties'; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 268; 261, subscript; 261, 262; 261, 267; 262, subscript; 262, 263; 262, 266; 263, subscript; 263, 264; 263, 265; 264, identifier:properties; 265, string:'datapoints'; 266, identifier:idx; 267, identifier:prop; 268, subscript; 268, 269; 268, 272; 269, subscript; 269, 270; 269, 271; 270, identifier:properties; 271, string:'common-properties'; 272, identifier:prop; 273, if_statement; 273, 274; 273, 275; 274, identifier:validate; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:chemked; 280, identifier:ChemKED; 281, argument_list; 281, 282; 282, keyword_argument; 282, 283; 282, 284; 283, identifier:dict_input; 284, identifier:properties; 285, return_statement; 285, 286; 286, identifier:properties
def ReSpecTh_to_ChemKED(filename_xml, file_author='', file_author_orcid='', *, validate=False): tree = etree.parse(filename_xml) root = tree.getroot() properties = get_file_metadata(root) properties['reference'] = get_reference(root) properties['reference']['detail'] = (properties['reference'].get('detail', '') + 'Converted from ReSpecTh XML file ' + os.path.basename(filename_xml) ) properties.update(get_experiment_kind(root)) properties['common-properties'] = get_common_properties(root) properties['common-properties']['ignition-type'] = get_ignition_type(root) properties['datapoints'] = get_datapoints(root) has_pres_rise = ('pressure-rise' in properties['common-properties'] or any([True for dp in properties['datapoints'] if 'pressure-rise' in dp]) ) if has_pres_rise and properties['apparatus']['kind'] == 'rapid compression machine': raise KeywordError('Pressure rise cannot be defined for RCM.') has_vol_hist = any( [t.get('type') == 'volume' for dp in properties['datapoints'] for t in dp.get('time-histories', [{}])] ) if has_vol_hist and properties['apparatus']['kind'] == 'shock tube': raise KeywordError('Volume history cannot be defined for shock tube.') if file_author_orcid and not file_author: raise KeywordError('If file_author_orcid is specified, file_author must be as well') if file_author: temp_author = {'name': file_author} if file_author_orcid: temp_author['ORCID'] = file_author_orcid properties['file-authors'].append(temp_author) for idx in range(len(properties['datapoints'])): for prop in properties['common-properties']: properties['datapoints'][idx][prop] = properties['common-properties'][prop] if validate: chemked.ChemKED(dict_input=properties) return properties
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_cantera_composition_string; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:species_conversion; 7, None; 8, block; 8, 9; 8, 47; 8, 233; 9, if_statement; 9, 10; 9, 17; 9, 22; 9, 33; 10, comparison_operator:in; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:composition_type; 14, list:['mole fraction', 'mass fraction']; 14, 15; 14, 16; 15, string:'mole fraction'; 16, string:'mass fraction'; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:factor; 21, float:1.0; 22, elif_clause; 22, 23; 22, 28; 23, comparison_operator:==; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:composition_type; 27, string:'mole percent'; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:factor; 32, float:100.0; 33, else_clause; 33, 34; 34, block; 34, 35; 35, raise_statement; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:ValueError; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, string:'Unknown composition type: {}'; 42, identifier:format; 43, argument_list; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:composition_type; 47, if_statement; 47, 48; 47, 51; 47, 80; 48, comparison_operator:is; 48, 49; 48, 50; 49, identifier:species_conversion; 50, None; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:comps; 55, list_comprehension; 55, 56; 55, 71; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, string:'{!s}:{:.4e}'; 59, identifier:format; 60, argument_list; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:c; 63, identifier:species_name; 64, binary_operator:/; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:c; 68, identifier:amount; 69, identifier:magnitude; 70, identifier:factor; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:c; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:composition; 78, identifier:values; 79, argument_list; 80, else_clause; 80, 81; 81, block; 81, 82; 81, 86; 81, 215; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:comps; 85, list:[]; 86, for_statement; 86, 87; 86, 88; 86, 95; 87, identifier:c; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:composition; 93, identifier:values; 94, argument_list; 95, block; 95, 96; 95, 106; 95, 122; 95, 132; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:amount; 99, binary_operator:/; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:c; 103, identifier:amount; 104, identifier:magnitude; 105, identifier:factor; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:idents; 109, list_comprehension; 109, 110; 109, 116; 110, call; 110, 111; 110, 112; 111, identifier:getattr; 112, argument_list; 112, 113; 112, 114; 112, 115; 113, identifier:c; 114, identifier:s; 115, False; 116, for_in_clause; 116, 117; 116, 118; 117, identifier:s; 118, list:['species_name', 'InChI', 'SMILES']; 118, 119; 118, 120; 118, 121; 119, string:'species_name'; 120, string:'InChI'; 121, string:'SMILES'; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:present; 125, list_comprehension; 125, 126; 125, 129; 126, comparison_operator:in; 126, 127; 126, 128; 127, identifier:i; 128, identifier:species_conversion; 129, for_in_clause; 129, 130; 129, 131; 130, identifier:i; 131, identifier:idents; 132, if_statement; 132, 133; 132, 138; 132, 154; 133, not_operator; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:any; 136, argument_list; 136, 137; 137, identifier:present; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:comps; 143, identifier:append; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, string:'{!s}:{:.4e}'; 148, identifier:format; 149, argument_list; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:c; 152, identifier:species_name; 153, identifier:amount; 154, else_clause; 154, 155; 155, block; 155, 156; 155, 182; 155, 193; 155, 202; 156, if_statement; 156, 157; 156, 169; 157, comparison_operator:>; 157, 158; 157, 168; 158, call; 158, 159; 158, 160; 159, identifier:len; 160, argument_list; 160, 161; 161, list_comprehension; 161, 162; 161, 163; 161, 166; 162, identifier:i; 163, for_in_clause; 163, 164; 163, 165; 164, identifier:i; 165, identifier:present; 166, if_clause; 166, 167; 167, identifier:i; 168, integer:1; 169, block; 169, 170; 170, raise_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:ValueError; 173, argument_list; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, string:'More than one conversion present for species {}'; 177, identifier:format; 178, argument_list; 178, 179; 179, attribute; 179, 180; 179, 181; 180, identifier:c; 181, identifier:species_name; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:ident; 185, subscript; 185, 186; 185, 187; 186, identifier:idents; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:present; 190, identifier:index; 191, argument_list; 191, 192; 192, True; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:species_replacement_name; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:species_conversion; 199, identifier:pop; 200, argument_list; 200, 201; 201, identifier:ident; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:comps; 206, identifier:append; 207, argument_list; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, string:'{!s}:{:.4e}'; 211, identifier:format; 212, argument_list; 212, 213; 212, 214; 213, identifier:species_replacement_name; 214, identifier:amount; 215, if_statement; 215, 216; 215, 222; 216, comparison_operator:>; 216, 217; 216, 221; 217, call; 217, 218; 217, 219; 218, identifier:len; 219, argument_list; 219, 220; 220, identifier:species_conversion; 221, integer:0; 222, block; 222, 223; 223, raise_statement; 223, 224; 224, call; 224, 225; 224, 226; 225, identifier:ValueError; 226, argument_list; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, string:'Unknown species in conversion: {}'; 230, identifier:format; 231, argument_list; 231, 232; 232, identifier:species_conversion; 233, return_statement; 233, 234; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, string:', '; 237, identifier:join; 238, argument_list; 238, 239; 239, identifier:comps
def get_cantera_composition_string(self, species_conversion=None): if self.composition_type in ['mole fraction', 'mass fraction']: factor = 1.0 elif self.composition_type == 'mole percent': factor = 100.0 else: raise ValueError('Unknown composition type: {}'.format(self.composition_type)) if species_conversion is None: comps = ['{!s}:{:.4e}'.format(c.species_name, c.amount.magnitude/factor) for c in self.composition.values()] else: comps = [] for c in self.composition.values(): amount = c.amount.magnitude/factor idents = [getattr(c, s, False) for s in ['species_name', 'InChI', 'SMILES']] present = [i in species_conversion for i in idents] if not any(present): comps.append('{!s}:{:.4e}'.format(c.species_name, amount)) else: if len([i for i in present if i]) > 1: raise ValueError('More than one conversion present for species {}'.format( c.species_name)) ident = idents[present.index(True)] species_replacement_name = species_conversion.pop(ident) comps.append('{!s}:{:.4e}'.format(species_replacement_name, amount)) if len(species_conversion) > 0: raise ValueError('Unknown species in conversion: {}'.format(species_conversion)) return ', '.join(comps)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:compare_name; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:given_name; 5, identifier:family_name; 6, identifier:question_name; 7, block; 7, 8; 7, 16; 7, 24; 7, 32; 7, 65; 7, 75; 7, 85; 7, 95; 7, 112; 7, 132; 7, 149; 7, 156; 7, 178; 7, 268; 7, 307; 7, 346; 7, 397; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:given_name; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:given_name; 14, identifier:lower; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:family_name; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:family_name; 22, identifier:lower; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:question_name; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:question_name; 30, identifier:lower; 31, argument_list; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:in; 33, 34; 33, 35; 34, string:','; 35, identifier:question_name; 36, block; 36, 37; 36, 46; 36, 52; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:name_split; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:question_name; 43, identifier:split; 44, argument_list; 44, 45; 45, string:','; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:name_split; 50, identifier:reverse; 51, argument_list; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:question_name; 55, call; 55, 56; 55, 64; 56, attribute; 56, 57; 56, 63; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, string:' '; 60, identifier:join; 61, argument_list; 61, 62; 62, identifier:name_split; 63, identifier:strip; 64, argument_list; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:question_name; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:question_name; 71, identifier:replace; 72, argument_list; 72, 73; 72, 74; 73, string:'.'; 74, string:''; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:given_name; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:given_name; 81, identifier:replace; 82, argument_list; 82, 83; 82, 84; 83, string:'.'; 84, string:''; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:family_name; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:family_name; 91, identifier:replace; 92, argument_list; 92, 93; 92, 94; 93, string:'.'; 94, string:''; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:given_name; 98, call; 98, 99; 98, 100; 99, identifier:list; 100, argument_list; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:filter; 103, argument_list; 103, 104; 103, 105; 104, None; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:re; 108, identifier:split; 109, argument_list; 109, 110; 109, 111; 110, string:r"[, \-.]+"; 111, identifier:given_name; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:num_family_names; 115, call; 115, 116; 115, 117; 116, identifier:len; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:list; 120, argument_list; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:filter; 123, argument_list; 123, 124; 123, 125; 124, None; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:re; 128, identifier:split; 129, argument_list; 129, 130; 129, 131; 130, string:"[, .]+"; 131, identifier:family_name; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:name_split; 135, call; 135, 136; 135, 137; 136, identifier:list; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:filter; 140, argument_list; 140, 141; 140, 142; 141, None; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:re; 145, identifier:split; 146, argument_list; 146, 147; 146, 148; 147, string:r"[, \-.]+"; 148, identifier:question_name; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:first_name; 152, list:[name_split[0]]; 152, 153; 153, subscript; 153, 154; 153, 155; 154, identifier:name_split; 155, integer:0; 156, if_statement; 156, 157; 156, 163; 157, comparison_operator:>; 157, 158; 157, 162; 158, call; 158, 159; 158, 160; 159, identifier:len; 160, argument_list; 160, 161; 161, identifier:name_split; 162, integer:2; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, augmented_assignment:+=; 165, 166; 165, 167; 166, identifier:first_name; 167, list_comprehension; 167, 168; 167, 169; 168, identifier:n; 169, for_in_clause; 169, 170; 169, 171; 170, identifier:n; 171, subscript; 171, 172; 171, 173; 172, identifier:name_split; 173, slice; 173, 174; 173, 175; 173, 176; 174, integer:1; 175, colon; 176, unary_operator:-; 176, 177; 177, identifier:num_family_names; 178, if_statement; 178, 179; 178, 195; 178, 227; 179, boolean_operator:and; 179, 180; 179, 186; 180, comparison_operator:>; 180, 181; 180, 185; 181, call; 181, 182; 181, 183; 182, identifier:len; 183, argument_list; 183, 184; 184, identifier:first_name; 185, integer:1; 186, comparison_operator:==; 186, 187; 186, 191; 187, call; 187, 188; 187, 189; 188, identifier:len; 189, argument_list; 189, 190; 190, identifier:given_name; 191, call; 191, 192; 191, 193; 192, identifier:len; 193, argument_list; 193, 194; 194, identifier:first_name; 195, block; 195, 196; 196, for_statement; 196, 197; 196, 198; 196, 206; 197, identifier:i; 198, call; 198, 199; 198, 200; 199, identifier:range; 200, argument_list; 200, 201; 200, 202; 201, integer:1; 202, call; 202, 203; 202, 204; 203, identifier:len; 204, argument_list; 204, 205; 205, identifier:first_name; 206, block; 206, 207; 206, 217; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:first_name; 211, identifier:i; 212, subscript; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:first_name; 215, identifier:i; 216, integer:0; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 222; 219, subscript; 219, 220; 219, 221; 220, identifier:given_name; 221, identifier:i; 222, subscript; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:given_name; 225, identifier:i; 226, integer:0; 227, elif_clause; 227, 228; 227, 237; 228, comparison_operator:!=; 228, 229; 228, 233; 229, call; 229, 230; 229, 231; 230, identifier:len; 231, argument_list; 231, 232; 232, identifier:given_name; 233, call; 233, 234; 233, 235; 234, identifier:len; 235, argument_list; 235, 236; 236, identifier:first_name; 237, block; 237, 238; 237, 252; 237, 260; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:min_names; 241, call; 241, 242; 241, 243; 242, identifier:min; 243, argument_list; 243, 244; 243, 248; 244, call; 244, 245; 244, 246; 245, identifier:len; 246, argument_list; 246, 247; 247, identifier:given_name; 248, call; 248, 249; 248, 250; 249, identifier:len; 250, argument_list; 250, 251; 251, identifier:first_name; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:first_name; 255, subscript; 255, 256; 255, 257; 256, identifier:first_name; 257, slice; 257, 258; 257, 259; 258, colon; 259, identifier:min_names; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:given_name; 263, subscript; 263, 264; 263, 265; 264, identifier:given_name; 265, slice; 265, 266; 265, 267; 266, colon; 267, identifier:min_names; 268, if_statement; 268, 269; 268, 286; 269, boolean_operator:or; 269, 270; 269, 278; 270, comparison_operator:==; 270, 271; 270, 277; 271, call; 271, 272; 271, 273; 272, identifier:len; 273, argument_list; 273, 274; 274, subscript; 274, 275; 274, 276; 275, identifier:first_name; 276, integer:0; 277, integer:1; 278, comparison_operator:==; 278, 279; 278, 285; 279, call; 279, 280; 279, 281; 280, identifier:len; 281, argument_list; 281, 282; 282, subscript; 282, 283; 282, 284; 283, identifier:given_name; 284, integer:0; 285, integer:1; 286, block; 286, 287; 286, 297; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 292; 289, subscript; 289, 290; 289, 291; 290, identifier:given_name; 291, integer:0; 292, subscript; 292, 293; 292, 296; 293, subscript; 293, 294; 293, 295; 294, identifier:given_name; 295, integer:0; 296, integer:0; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 302; 299, subscript; 299, 300; 299, 301; 300, identifier:first_name; 301, integer:0; 302, subscript; 302, 303; 302, 306; 303, subscript; 303, 304; 303, 305; 304, identifier:first_name; 305, integer:0; 306, integer:0; 307, if_statement; 307, 308; 307, 325; 308, boolean_operator:or; 308, 309; 308, 317; 309, comparison_operator:>; 309, 310; 309, 316; 310, call; 310, 311; 310, 312; 311, identifier:len; 312, argument_list; 312, 313; 313, subscript; 313, 314; 313, 315; 314, identifier:first_name; 315, integer:0; 316, integer:1; 317, comparison_operator:>; 317, 318; 317, 324; 318, call; 318, 319; 318, 320; 319, identifier:len; 320, argument_list; 320, 321; 321, subscript; 321, 322; 321, 323; 322, identifier:given_name; 323, integer:0; 324, integer:1; 325, block; 325, 326; 325, 336; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 331; 328, subscript; 328, 329; 328, 330; 329, identifier:given_name; 330, integer:0; 331, subscript; 331, 332; 331, 335; 332, subscript; 332, 333; 332, 334; 333, identifier:given_name; 334, integer:0; 335, integer:0; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 341; 338, subscript; 338, 339; 338, 340; 339, identifier:first_name; 340, integer:0; 341, subscript; 341, 342; 341, 345; 342, subscript; 342, 343; 342, 344; 343, identifier:name_split; 344, integer:0; 345, integer:0; 346, if_statement; 346, 347; 346, 354; 346, 381; 347, boolean_operator:and; 347, 348; 347, 351; 348, comparison_operator:==; 348, 349; 348, 350; 349, identifier:num_family_names; 350, integer:1; 351, comparison_operator:in; 351, 352; 351, 353; 352, string:'-'; 353, identifier:family_name; 354, block; 354, 355; 354, 364; 355, expression_statement; 355, 356; 356, assignment; 356, 357; 356, 358; 357, identifier:num_hyphen; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:family_name; 361, identifier:count; 362, argument_list; 362, 363; 363, string:'-'; 364, expression_statement; 364, 365; 365, assignment; 365, 366; 365, 367; 366, identifier:family_name_compare; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, string:'-'; 370, identifier:join; 371, argument_list; 371, 372; 372, subscript; 372, 373; 372, 374; 373, identifier:name_split; 374, slice; 374, 375; 374, 380; 375, unary_operator:-; 375, 376; 376, parenthesized_expression; 376, 377; 377, binary_operator:+; 377, 378; 377, 379; 378, identifier:num_hyphen; 379, integer:1; 380, colon; 381, else_clause; 381, 382; 382, block; 382, 383; 383, expression_statement; 383, 384; 384, assignment; 384, 385; 384, 386; 385, identifier:family_name_compare; 386, call; 386, 387; 386, 390; 387, attribute; 387, 388; 387, 389; 388, string:' '; 389, identifier:join; 390, argument_list; 390, 391; 391, subscript; 391, 392; 391, 393; 392, identifier:name_split; 393, slice; 393, 394; 393, 396; 394, unary_operator:-; 394, 395; 395, identifier:num_family_names; 396, colon; 397, return_statement; 397, 398; 398, boolean_operator:and; 398, 399; 398, 402; 399, comparison_operator:==; 399, 400; 399, 401; 400, identifier:given_name; 401, identifier:first_name; 402, comparison_operator:==; 402, 403; 402, 404; 403, identifier:family_name; 404, identifier:family_name_compare
def compare_name(given_name, family_name, question_name): given_name = given_name.lower() family_name = family_name.lower() question_name = question_name.lower() if ',' in question_name: name_split = question_name.split(',') name_split.reverse() question_name = ' '.join(name_split).strip() question_name = question_name.replace('.', '') given_name = given_name.replace('.', '') family_name = family_name.replace('.', '') given_name = list(filter(None, re.split(r"[, \-.]+", given_name))) num_family_names = len(list(filter(None, re.split("[, .]+", family_name)))) name_split = list(filter(None, re.split(r"[, \-.]+", question_name))) first_name = [name_split[0]] if len(name_split) > 2: first_name += [n for n in name_split[1:-num_family_names]] if len(first_name) > 1 and len(given_name) == len(first_name): for i in range(1, len(first_name)): first_name[i] = first_name[i][0] given_name[i] = given_name[i][0] elif len(given_name) != len(first_name): min_names = min(len(given_name), len(first_name)) first_name = first_name[:min_names] given_name = given_name[:min_names] if len(first_name[0]) == 1 or len(given_name[0]) == 1: given_name[0] = given_name[0][0] first_name[0] = first_name[0][0] if len(first_name[0]) > 1 or len(given_name[0]) > 1: given_name[0] = given_name[0][0] first_name[0] = name_split[0][0] if num_family_names == 1 and '-' in family_name: num_hyphen = family_name.count('-') family_name_compare = '-'.join(name_split[-(num_hyphen + 1):]) else: family_name_compare = ' '.join(name_split[-num_family_names:]) return given_name == first_name and family_name == family_name_compare
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorted_options; 3, parameters; 3, 4; 4, identifier:sort_options; 5, block; 5, 6; 6, return_statement; 6, 7; 7, list_comprehension; 7, 8; 7, 34; 8, dictionary; 8, 9; 8, 14; 9, pair; 9, 10; 9, 11; 10, string:'title'; 11, subscript; 11, 12; 11, 13; 12, identifier:v; 13, string:'title'; 14, pair; 14, 15; 14, 16; 15, string:'value'; 16, parenthesized_expression; 16, 17; 17, conditional_expression:if; 17, 18; 17, 24; 17, 33; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, string:'-{0}'; 21, identifier:format; 22, argument_list; 22, 23; 23, identifier:k; 24, comparison_operator:==; 24, 25; 24, 32; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:v; 28, identifier:get; 29, argument_list; 29, 30; 29, 31; 30, string:'default_order'; 31, string:'asc'; 32, string:'desc'; 33, identifier:k; 34, for_in_clause; 34, 35; 34, 38; 35, pattern_list; 35, 36; 35, 37; 36, identifier:k; 37, identifier:v; 38, call; 38, 39; 38, 40; 39, identifier:sorted; 40, argument_list; 40, 41; 40, 46; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:sort_options; 44, identifier:items; 45, argument_list; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:key; 48, lambda; 48, 49; 48, 51; 49, lambda_parameters; 49, 50; 50, identifier:x; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:x; 55, integer:1; 56, identifier:get; 57, argument_list; 57, 58; 57, 59; 58, string:'order'; 59, integer:0
def sorted_options(sort_options): return [ { 'title': v['title'], 'value': ('-{0}'.format(k) if v.get('default_order', 'asc') == 'desc' else k), } for k, v in sorted(sort_options.items(), key=lambda x: x[1].get('order', 0)) ]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:insert_files; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 4, identifier:self; 5, identifier:rootpath; 6, default_parameter; 6, 7; 6, 8; 7, identifier:directoryInFilter; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:directoryExFilter; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:compileInFilter; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:compileExFilter; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:contentInFilter; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:contentExFilter; 23, None; 24, block; 24, 25; 24, 36; 24, 47; 24, 58; 24, 69; 24, 80; 24, 91; 24, 132; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:directoryInFilter; 28, conditional_expression:if; 28, 29; 28, 32; 28, 35; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:DirectoryInFilter; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:directoryInFilter; 34, None; 35, identifier:directoryInFilter; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:directoryExFilter; 39, conditional_expression:if; 39, 40; 39, 43; 39, 46; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:DirectoryExFilter; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:directoryExFilter; 45, None; 46, identifier:directoryExFilter; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:compileInFilter; 50, conditional_expression:if; 50, 51; 50, 54; 50, 57; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:CompileInFilter; 54, comparison_operator:is; 54, 55; 54, 56; 55, identifier:compileInFilter; 56, None; 57, identifier:compileInFilter; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:compileExFilter; 61, conditional_expression:if; 61, 62; 61, 65; 61, 68; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:CompileExFilter; 65, comparison_operator:is; 65, 66; 65, 67; 66, identifier:compileExFilter; 67, None; 68, identifier:compileExFilter; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:contentInFilter; 72, conditional_expression:if; 72, 73; 72, 76; 72, 79; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:ContentInFilter; 76, comparison_operator:is; 76, 77; 76, 78; 77, identifier:contentInFilter; 78, None; 79, identifier:contentInFilter; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:contentExFilter; 83, conditional_expression:if; 83, 84; 83, 87; 83, 90; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:ContentExFilter; 87, comparison_operator:is; 87, 88; 87, 89; 88, identifier:contentExFilter; 89, None; 90, identifier:contentExFilter; 91, function_definition; 91, 92; 91, 93; 91, 97; 92, function_name:filter; 93, parameters; 93, 94; 93, 95; 93, 96; 94, identifier:text; 95, identifier:filters; 96, identifier:explicit; 97, block; 97, 98; 97, 115; 98, if_statement; 98, 99; 98, 100; 99, identifier:explicit; 100, block; 100, 101; 101, return_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:any; 104, generator_expression; 104, 105; 104, 112; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:fnmatch; 108, identifier:fnmatch; 109, argument_list; 109, 110; 109, 111; 110, identifier:text; 111, identifier:f; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:f; 114, identifier:filters; 115, return_statement; 115, 116; 116, boolean_operator:or; 116, 117; 116, 119; 117, not_operator; 117, 118; 118, identifier:filters; 119, call; 119, 120; 119, 121; 120, identifier:any; 121, generator_expression; 121, 122; 121, 129; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:fnmatch; 125, identifier:fnmatch; 126, argument_list; 126, 127; 126, 128; 127, identifier:text; 128, identifier:f; 129, for_in_clause; 129, 130; 129, 131; 130, identifier:f; 131, identifier:filters; 132, for_statement; 132, 133; 132, 137; 132, 143; 133, pattern_list; 133, 134; 133, 135; 133, 136; 134, identifier:root; 135, identifier:dirnames; 136, identifier:filenames; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:os; 140, identifier:walk; 141, argument_list; 141, 142; 142, identifier:rootpath; 143, block; 143, 144; 143, 162; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:searchdir; 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:normpath; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 160; 155, attribute; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:os; 158, identifier:path; 159, identifier:normcase; 160, argument_list; 160, 161; 161, identifier:root; 162, if_statement; 162, 163; 162, 169; 162, 177; 163, call; 163, 164; 163, 165; 164, identifier:filter; 165, argument_list; 165, 166; 165, 167; 165, 168; 166, identifier:searchdir; 167, identifier:directoryExFilter; 168, True; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 176; 172, subscript; 172, 173; 172, 174; 173, identifier:dirnames; 174, slice; 174, 175; 175, colon; 176, list:[]; 177, elif_clause; 177, 178; 177, 184; 178, call; 178, 179; 178, 180; 179, identifier:filter; 180, argument_list; 180, 181; 180, 182; 180, 183; 181, identifier:searchdir; 182, identifier:directoryInFilter; 183, False; 184, block; 184, 185; 185, for_statement; 185, 186; 185, 187; 185, 200; 186, identifier:filepath; 187, list_comprehension; 187, 188; 187, 197; 188, call; 188, 189; 188, 194; 189, attribute; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:os; 192, identifier:path; 193, identifier:join; 194, argument_list; 194, 195; 194, 196; 195, identifier:root; 196, identifier:filename; 197, for_in_clause; 197, 198; 197, 199; 198, identifier:filename; 199, identifier:filenames; 200, block; 200, 201; 201, if_statement; 201, 202; 201, 216; 201, 226; 202, boolean_operator:and; 202, 203; 202, 209; 203, call; 203, 204; 203, 205; 204, identifier:filter; 205, argument_list; 205, 206; 205, 207; 205, 208; 206, identifier:filepath; 207, identifier:compileInFilter; 208, False; 209, not_operator; 209, 210; 210, call; 210, 211; 210, 212; 211, identifier:filter; 212, argument_list; 212, 213; 212, 214; 212, 215; 213, identifier:filepath; 214, identifier:compileExFilter; 215, True; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 224; 219, attribute; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:CompileFiles; 223, identifier:append; 224, argument_list; 224, 225; 225, identifier:filepath; 226, elif_clause; 226, 227; 226, 241; 227, boolean_operator:and; 227, 228; 227, 234; 228, call; 228, 229; 228, 230; 229, identifier:filter; 230, argument_list; 230, 231; 230, 232; 230, 233; 231, identifier:filepath; 232, identifier:contentInFilter; 233, False; 234, not_operator; 234, 235; 235, call; 235, 236; 235, 237; 236, identifier:filter; 237, argument_list; 237, 238; 237, 239; 237, 240; 238, identifier:filepath; 239, identifier:contentExFilter; 240, True; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:ContentFiles; 248, identifier:append; 249, argument_list; 249, 250; 250, identifier:filepath
def insert_files(self, rootpath, directoryInFilter=None, directoryExFilter=None, compileInFilter=None, compileExFilter=None, contentInFilter=None, contentExFilter=None): directoryInFilter = self.DirectoryInFilter if directoryInFilter is None else directoryInFilter directoryExFilter = self.DirectoryExFilter if directoryExFilter is None else directoryExFilter compileInFilter = self.CompileInFilter if compileInFilter is None else compileInFilter compileExFilter = self.CompileExFilter if compileExFilter is None else compileExFilter contentInFilter = self.ContentInFilter if contentInFilter is None else contentInFilter contentExFilter = self.ContentExFilter if contentExFilter is None else contentExFilter def filter(text, filters, explicit): if explicit: return any(fnmatch.fnmatch(text, f) for f in filters) return not filters or any(fnmatch.fnmatch(text, f) for f in filters) for root, dirnames, filenames in os.walk(rootpath): searchdir = os.path.normpath(os.path.normcase(root)) if filter(searchdir, directoryExFilter, True): dirnames[:] = [] elif filter(searchdir, directoryInFilter, False): for filepath in [os.path.join(root, filename) for filename in filenames]: if filter(filepath, compileInFilter, False) and not filter(filepath, compileExFilter, True): self.CompileFiles.append(filepath) elif filter(filepath, contentInFilter, False) and not filter(filepath, contentExFilter, True): self.ContentFiles.append(filepath)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:make_variant; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:cls; 5, identifier:converters; 6, default_parameter; 6, 7; 6, 8; 7, identifier:re_opts; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:compiled; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:strict; 14, True; 15, block; 15, 16; 15, 19; 15, 31; 15, 42; 15, 57; 15, 65; 15, 72; 15, 85; 15, 111; 15, 117; 15, 126; 15, 132; 16, assert_statement; 16, 17; 16, 18; 17, identifier:converters; 18, string:"REQUIRE: Non-empty list."; 19, if_statement; 19, 20; 19, 26; 20, comparison_operator:==; 20, 21; 20, 25; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, identifier:converters; 25, integer:1; 26, block; 26, 27; 27, return_statement; 27, 28; 28, subscript; 28, 29; 28, 30; 29, identifier:converters; 30, integer:0; 31, if_statement; 31, 32; 31, 35; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:re_opts; 34, None; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:re_opts; 39, attribute; 39, 40; 39, 41; 40, identifier:cls; 41, identifier:default_re_opts; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:pattern; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, string:r")|("; 48, identifier:join; 49, argument_list; 49, 50; 50, list_comprehension; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:tc; 53, identifier:pattern; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:tc; 56, identifier:converters; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:pattern; 60, binary_operator:+; 60, 61; 60, 64; 61, binary_operator:+; 61, 62; 61, 63; 62, string:r"("; 63, identifier:pattern; 64, string:")"; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:group_count; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:converters; 72, for_statement; 72, 73; 72, 74; 72, 75; 73, identifier:converter; 74, identifier:converters; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, augmented_assignment:+=; 77, 78; 77, 79; 78, identifier:group_count; 79, call; 79, 80; 79, 81; 80, identifier:pattern_group_count; 81, argument_list; 81, 82; 82, attribute; 82, 83; 82, 84; 83, identifier:converter; 84, identifier:pattern; 85, if_statement; 85, 86; 85, 87; 85, 99; 86, identifier:compiled; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:convert_variant; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:cls; 94, identifier:__create_convert_variant_compiled; 95, argument_list; 95, 96; 95, 97; 95, 98; 96, identifier:converters; 97, identifier:re_opts; 98, identifier:strict; 99, else_clause; 99, 100; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:convert_variant; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:cls; 107, identifier:__create_convert_variant; 108, argument_list; 108, 109; 108, 110; 109, identifier:re_opts; 110, identifier:strict; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:convert_variant; 115, identifier:pattern; 116, identifier:pattern; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:convert_variant; 121, identifier:converters; 122, call; 122, 123; 122, 124; 123, identifier:tuple; 124, argument_list; 124, 125; 125, identifier:converters; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:convert_variant; 130, identifier:regex_group_count; 131, identifier:group_count; 132, return_statement; 132, 133; 133, identifier:convert_variant
def make_variant(cls, converters, re_opts=None, compiled=False, strict=True): assert converters, "REQUIRE: Non-empty list." if len(converters) == 1: return converters[0] if re_opts is None: re_opts = cls.default_re_opts pattern = r")|(".join([tc.pattern for tc in converters]) pattern = r"("+ pattern + ")" group_count = len(converters) for converter in converters: group_count += pattern_group_count(converter.pattern) if compiled: convert_variant = cls.__create_convert_variant_compiled(converters, re_opts, strict) else: convert_variant = cls.__create_convert_variant(re_opts, strict) convert_variant.pattern = pattern convert_variant.converters = tuple(converters) convert_variant.regex_group_count = group_count return convert_variant
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:info; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, string:''' Returns information on all the registered checkers. Sorted by namespace and then name :returns a list of CheckerInfo '''; 8, return_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:sorted; 11, argument_list; 11, 12; 11, 19; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_checkers; 17, identifier:values; 18, argument_list; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:key; 21, lambda; 21, 22; 21, 24; 22, lambda_parameters; 22, 23; 23, identifier:x; 24, tuple; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:x; 27, identifier:ns; 28, attribute; 28, 29; 28, 30; 29, identifier:x; 30, identifier:name
def info(self): ''' Returns information on all the registered checkers. Sorted by namespace and then name :returns a list of CheckerInfo ''' return sorted(self._checkers.values(), key=lambda x: (x.ns, x.name))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:extract_from_text; 3, parameters; 3, 4; 4, identifier:text; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:tools; 10, identifier:remove_duplicates; 11, argument_list; 11, 12; 12, list_comprehension; 12, 13; 12, 16; 12, 24; 13, subscript; 13, 14; 13, 15; 14, identifier:i; 15, integer:0; 16, for_in_clause; 16, 17; 16, 18; 17, identifier:i; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:REGEX; 21, identifier:findall; 22, argument_list; 22, 23; 23, identifier:text; 24, if_clause; 24, 25; 25, comparison_operator:!=; 25, 26; 25, 27; 26, identifier:i; 27, string:''
def extract_from_text(text): return tools.remove_duplicates([i[0] for i in REGEX.findall(text) if i != ''])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:add_caveat; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:cav; 6, default_parameter; 6, 7; 6, 8; 7, identifier:key; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:loc; 11, None; 12, block; 12, 13; 12, 15; 12, 41; 12, 51; 12, 60; 12, 120; 12, 129; 12, 154; 12, 169; 12, 201; 13, expression_statement; 13, 14; 14, string:'''Add a caveat to the macaroon. It encrypts it using the given key pair and by looking up the location using the given locator. As a special case, if the caveat's Location field has the prefix "local " the caveat is added as a client self-discharge caveat using the public key base64-encoded in the rest of the location. In this case, the Condition field must be empty. The resulting third-party caveat will encode the condition "true" encrypted with that public key. @param cav the checkers.Caveat to be added. @param key the public key to encrypt third party caveat. @param loc locator to find information on third parties when adding third party caveats. It is expected to have a third_party_info method that will be called with a location string and should return a ThirdPartyInfo instance holding the requested information. '''; 15, if_statement; 15, 16; 15, 21; 16, comparison_operator:is; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:cav; 19, identifier:location; 20, None; 21, block; 21, 22; 21, 40; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_macaroon; 28, identifier:add_first_party_caveat; 29, argument_list; 29, 30; 30, attribute; 30, 31; 30, 39; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:namespace; 36, identifier:resolve_caveat; 37, argument_list; 37, 38; 38, identifier:cav; 39, identifier:condition; 40, return_statement; 41, if_statement; 41, 42; 41, 45; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:key; 44, None; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:ValueError; 49, argument_list; 49, 50; 50, string:'no private key to encrypt third party caveat'; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:local_info; 54, call; 54, 55; 54, 56; 55, identifier:_parse_local_location; 56, argument_list; 56, 57; 57, attribute; 57, 58; 57, 59; 58, identifier:cav; 59, identifier:location; 60, if_statement; 60, 61; 60, 64; 60, 97; 61, comparison_operator:is; 61, 62; 61, 63; 62, identifier:local_info; 63, None; 64, block; 64, 65; 64, 69; 64, 83; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:info; 68, identifier:local_info; 69, if_statement; 69, 70; 69, 75; 70, comparison_operator:is; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:cav; 73, identifier:condition; 74, string:''; 75, block; 75, 76; 76, raise_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:ValueError; 79, argument_list; 79, 80; 80, concatenated_string; 80, 81; 80, 82; 81, string:'cannot specify caveat condition in '; 82, string:'local third-party caveat'; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:cav; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:checkers; 89, identifier:Caveat; 90, argument_list; 90, 91; 90, 94; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:location; 93, string:'local'; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:condition; 96, string:'true'; 97, else_clause; 97, 98; 98, block; 98, 99; 98, 109; 99, if_statement; 99, 100; 99, 103; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:loc; 102, None; 103, block; 103, 104; 104, raise_statement; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:ValueError; 107, argument_list; 107, 108; 108, string:'no locator when adding third party caveat'; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:info; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:loc; 115, identifier:third_party_info; 116, argument_list; 116, 117; 117, attribute; 117, 118; 117, 119; 118, identifier:cav; 119, identifier:location; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:root_key; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:os; 126, identifier:urandom; 127, argument_list; 127, 128; 128, integer:24; 129, if_statement; 129, 130; 129, 137; 130, comparison_operator:<; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:_version; 134, attribute; 134, 135; 134, 136; 135, identifier:info; 136, identifier:version; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:info; 141, call; 141, 142; 141, 143; 142, identifier:ThirdPartyInfo; 143, argument_list; 143, 144; 143, 149; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:version; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:_version; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:public_key; 151, attribute; 151, 152; 151, 153; 152, identifier:info; 153, identifier:public_key; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:caveat_info; 157, call; 157, 158; 157, 159; 158, identifier:encode_caveat; 159, argument_list; 159, 160; 159, 163; 159, 164; 159, 165; 159, 166; 160, attribute; 160, 161; 160, 162; 161, identifier:cav; 162, identifier:condition; 163, identifier:root_key; 164, identifier:info; 165, identifier:key; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:_namespace; 169, if_statement; 169, 170; 169, 175; 169, 180; 170, comparison_operator:<; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:info; 173, identifier:version; 174, identifier:VERSION_3; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:id; 179, identifier:caveat_info; 180, else_clause; 180, 181; 181, block; 181, 182; 181, 193; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:id; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:_new_caveat_id; 189, argument_list; 189, 190; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:_caveat_id_prefix; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 200; 195, subscript; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:_caveat_data; 199, identifier:id; 200, identifier:caveat_info; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:_macaroon; 207, identifier:add_third_party_caveat; 208, argument_list; 208, 209; 208, 212; 208, 213; 209, attribute; 209, 210; 209, 211; 210, identifier:cav; 211, identifier:location; 212, identifier:root_key; 213, identifier:id
def add_caveat(self, cav, key=None, loc=None): '''Add a caveat to the macaroon. It encrypts it using the given key pair and by looking up the location using the given locator. As a special case, if the caveat's Location field has the prefix "local " the caveat is added as a client self-discharge caveat using the public key base64-encoded in the rest of the location. In this case, the Condition field must be empty. The resulting third-party caveat will encode the condition "true" encrypted with that public key. @param cav the checkers.Caveat to be added. @param key the public key to encrypt third party caveat. @param loc locator to find information on third parties when adding third party caveats. It is expected to have a third_party_info method that will be called with a location string and should return a ThirdPartyInfo instance holding the requested information. ''' if cav.location is None: self._macaroon.add_first_party_caveat( self.namespace.resolve_caveat(cav).condition) return if key is None: raise ValueError( 'no private key to encrypt third party caveat') local_info = _parse_local_location(cav.location) if local_info is not None: info = local_info if cav.condition is not '': raise ValueError( 'cannot specify caveat condition in ' 'local third-party caveat') cav = checkers.Caveat(location='local', condition='true') else: if loc is None: raise ValueError( 'no locator when adding third party caveat') info = loc.third_party_info(cav.location) root_key = os.urandom(24) if self._version < info.version: info = ThirdPartyInfo( version=self._version, public_key=info.public_key, ) caveat_info = encode_caveat( cav.condition, root_key, info, key, self._namespace) if info.version < VERSION_3: id = caveat_info else: id = self._new_caveat_id(self._caveat_id_prefix) self._caveat_data[id] = caveat_info self._macaroon.add_third_party_caveat(cav.location, root_key, id)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_new_caveat_id; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:base; 6, block; 6, 7; 6, 9; 6, 15; 6, 39; 6, 48; 6, 56; 7, expression_statement; 7, 8; 8, string:'''Return a third party caveat id This does not duplicate any third party caveat ids already inside macaroon. If base is non-empty, it is used as the id prefix. @param base bytes @return bytes '''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:id; 12, call; 12, 13; 12, 14; 13, identifier:bytearray; 14, argument_list; 15, if_statement; 15, 16; 15, 22; 15, 30; 16, comparison_operator:>; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:base; 21, integer:0; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:id; 27, identifier:extend; 28, argument_list; 28, 29; 29, identifier:base; 30, else_clause; 30, 31; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:id; 36, identifier:append; 37, argument_list; 37, 38; 38, identifier:VERSION_3; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:i; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:_caveat_data; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:caveats; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_macaroon; 55, identifier:caveats; 56, while_statement; 56, 57; 56, 58; 57, True; 58, block; 58, 59; 58, 66; 58, 72; 58, 76; 58, 99; 58, 108; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:temp; 62, subscript; 62, 63; 62, 64; 63, identifier:id; 64, slice; 64, 65; 65, colon; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:encode_uvarint; 69, argument_list; 69, 70; 69, 71; 70, identifier:i; 71, identifier:temp; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:found; 75, False; 76, for_statement; 76, 77; 76, 78; 76, 79; 77, identifier:cav; 78, identifier:caveats; 79, block; 79, 80; 80, if_statement; 80, 81; 80, 93; 81, parenthesized_expression; 81, 82; 82, boolean_operator:and; 82, 83; 82, 88; 83, comparison_operator:is; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:cav; 86, identifier:verification_key_id; 87, None; 88, comparison_operator:==; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:cav; 91, identifier:caveat_id; 92, identifier:temp; 93, block; 93, 94; 93, 98; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:found; 97, True; 98, break_statement; 99, if_statement; 99, 100; 99, 102; 100, not_operator; 100, 101; 101, identifier:found; 102, block; 102, 103; 103, return_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:bytes; 106, argument_list; 106, 107; 107, identifier:temp; 108, expression_statement; 108, 109; 109, augmented_assignment:+=; 109, 110; 109, 111; 110, identifier:i; 111, integer:1
def _new_caveat_id(self, base): '''Return a third party caveat id This does not duplicate any third party caveat ids already inside macaroon. If base is non-empty, it is used as the id prefix. @param base bytes @return bytes ''' id = bytearray() if len(base) > 0: id.extend(base) else: id.append(VERSION_3) i = len(self._caveat_data) caveats = self._macaroon.caveats while True: temp = id[:] encode_uvarint(i, temp) found = False for cav in caveats: if (cav.verification_key_id is not None and cav.caveat_id == temp): found = True break if not found: return bytes(temp) i += 1
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:extract_macaroons; 3, parameters; 3, 4; 4, identifier:headers_or_request; 5, block; 5, 6; 5, 8; 5, 37; 5, 41; 5, 95; 5, 102; 5, 144; 5, 151; 5, 170; 6, expression_statement; 6, 7; 7, string:''' Returns an array of any macaroons found in the given slice of cookies. If the argument implements a get_header method, that will be used instead of the get method to retrieve headers. @param headers_or_request: dict of headers or a urllib.request.Request-like object. @return: A list of list of mpy macaroons '''; 8, function_definition; 8, 9; 8, 10; 8, 15; 9, function_name:get_header; 10, parameters; 10, 11; 10, 12; 11, identifier:key; 12, default_parameter; 12, 13; 12, 14; 13, identifier:default; 14, None; 15, block; 15, 16; 16, try_statement; 16, 17; 16, 26; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:headers_or_request; 22, identifier:get_header; 23, argument_list; 23, 24; 23, 25; 24, identifier:key; 25, identifier:default; 26, except_clause; 26, 27; 26, 28; 27, identifier:AttributeError; 28, block; 28, 29; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:headers_or_request; 33, identifier:get; 34, argument_list; 34, 35; 34, 36; 35, identifier:key; 36, identifier:default; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:mss; 40, list:[]; 41, function_definition; 41, 42; 41, 43; 41, 45; 42, function_name:add_macaroon; 43, parameters; 43, 44; 44, identifier:data; 45, block; 45, 46; 45, 75; 45, 88; 46, try_statement; 46, 47; 46, 71; 47, block; 47, 48; 47, 57; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:data; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:utils; 54, identifier:b64decode; 55, argument_list; 55, 56; 56, identifier:data; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:data_as_objs; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:json; 63, identifier:loads; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:data; 68, identifier:decode; 69, argument_list; 69, 70; 70, string:'utf-8'; 71, except_clause; 71, 72; 71, 73; 72, identifier:ValueError; 73, block; 73, 74; 74, return_statement; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:ms; 78, list_comprehension; 78, 79; 78, 85; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:utils; 82, identifier:macaroon_from_dict; 83, argument_list; 83, 84; 84, identifier:x; 85, for_in_clause; 85, 86; 85, 87; 86, identifier:x; 87, identifier:data_as_objs; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:mss; 92, identifier:append; 93, argument_list; 93, 94; 94, identifier:ms; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:cookie_header; 98, call; 98, 99; 98, 100; 99, identifier:get_header; 100, argument_list; 100, 101; 101, string:'Cookie'; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:cookie_header; 105, None; 106, block; 106, 107; 106, 113; 106, 123; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:cs; 110, call; 110, 111; 110, 112; 111, identifier:SimpleCookie; 112, argument_list; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:cs; 117, identifier:load; 118, argument_list; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:str; 121, argument_list; 121, 122; 122, identifier:cookie_header; 123, for_statement; 123, 124; 123, 125; 123, 126; 124, identifier:c; 125, identifier:cs; 126, block; 126, 127; 127, if_statement; 127, 128; 127, 134; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:c; 131, identifier:startswith; 132, argument_list; 132, 133; 133, string:'macaroon-'; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:add_macaroon; 138, argument_list; 138, 139; 139, attribute; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:cs; 142, identifier:c; 143, identifier:value; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:macaroon_header; 147, call; 147, 148; 147, 149; 148, identifier:get_header; 149, argument_list; 149, 150; 150, string:'Macaroons'; 151, if_statement; 151, 152; 151, 155; 152, comparison_operator:is; 152, 153; 152, 154; 153, identifier:macaroon_header; 154, None; 155, block; 155, 156; 156, for_statement; 156, 157; 156, 158; 156, 164; 157, identifier:h; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:macaroon_header; 161, identifier:split; 162, argument_list; 162, 163; 163, string:','; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:add_macaroon; 168, argument_list; 168, 169; 169, identifier:h; 170, return_statement; 170, 171; 171, identifier:mss
def extract_macaroons(headers_or_request): ''' Returns an array of any macaroons found in the given slice of cookies. If the argument implements a get_header method, that will be used instead of the get method to retrieve headers. @param headers_or_request: dict of headers or a urllib.request.Request-like object. @return: A list of list of mpy macaroons ''' def get_header(key, default=None): try: return headers_or_request.get_header(key, default) except AttributeError: return headers_or_request.get(key, default) mss = [] def add_macaroon(data): try: data = utils.b64decode(data) data_as_objs = json.loads(data.decode('utf-8')) except ValueError: return ms = [utils.macaroon_from_dict(x) for x in data_as_objs] mss.append(ms) cookie_header = get_header('Cookie') if cookie_header is not None: cs = SimpleCookie() cs.load(str(cookie_header)) for c in cs: if c.startswith('macaroon-'): add_macaroon(cs[c].value) macaroon_header = get_header('Macaroons') if macaroon_header is not None: for h in macaroon_header.split(','): add_macaroon(h) return mss
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:http_error_handler; 3, parameters; 3, 4; 4, identifier:f; 5, block; 5, 6; 5, 50; 5, 87; 5, 302; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:hrefs_to_resources; 8, parameters; 8, 9; 9, identifier:hrefs; 10, block; 10, 11; 11, for_statement; 11, 12; 11, 13; 11, 24; 12, identifier:href; 13, call; 13, 14; 13, 23; 14, attribute; 14, 15; 14, 22; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:hrefs; 18, identifier:replace; 19, argument_list; 19, 20; 19, 21; 20, string:','; 21, string:''; 22, identifier:split; 23, argument_list; 24, block; 24, 25; 24, 41; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, pattern_list; 27, 28; 27, 29; 28, identifier:type; 29, identifier:uuid; 30, subscript; 30, 31; 30, 37; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:href; 34, identifier:split; 35, argument_list; 35, 36; 36, string:'/'; 37, slice; 37, 38; 37, 40; 38, unary_operator:-; 38, 39; 39, integer:2; 40, colon; 41, expression_statement; 41, 42; 42, yield; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:Resource; 45, argument_list; 45, 46; 45, 47; 46, identifier:type; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:uuid; 49, identifier:uuid; 50, function_definition; 50, 51; 50, 52; 50, 54; 51, function_name:hrefs_list_to_resources; 52, parameters; 52, 53; 53, identifier:hrefs_list; 54, block; 54, 55; 55, for_statement; 55, 56; 55, 57; 55, 61; 56, identifier:href; 57, call; 57, 58; 57, 59; 58, identifier:eval; 59, argument_list; 59, 60; 60, identifier:hrefs_list; 61, block; 61, 62; 61, 78; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, pattern_list; 64, 65; 64, 66; 65, identifier:type; 66, identifier:uuid; 67, subscript; 67, 68; 67, 74; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:href; 71, identifier:split; 72, argument_list; 72, 73; 73, string:'/'; 74, slice; 74, 75; 74, 77; 75, unary_operator:-; 75, 76; 76, integer:2; 77, colon; 78, expression_statement; 78, 79; 79, yield; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:Resource; 82, argument_list; 82, 83; 82, 84; 83, identifier:type; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:uuid; 86, identifier:uuid; 87, decorated_definition; 87, 88; 87, 93; 88, decorator; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:wraps; 91, argument_list; 91, 92; 92, identifier:f; 93, function_definition; 93, 94; 93, 95; 93, 101; 94, function_name:wrapper; 95, parameters; 95, 96; 95, 97; 95, 99; 96, identifier:self; 97, list_splat_pattern; 97, 98; 98, identifier:args; 99, dictionary_splat_pattern; 99, 100; 100, identifier:kwargs; 101, block; 101, 102; 102, try_statement; 102, 103; 102, 113; 103, block; 103, 104; 104, return_statement; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:f; 107, argument_list; 107, 108; 107, 109; 107, 111; 108, identifier:self; 109, list_splat; 109, 110; 110, identifier:args; 111, dictionary_splat; 111, 112; 112, identifier:kwargs; 113, except_clause; 113, 114; 113, 118; 114, as_pattern; 114, 115; 114, 116; 115, identifier:HttpError; 116, as_pattern_target; 116, 117; 117, identifier:e; 118, block; 118, 119; 118, 301; 119, if_statement; 119, 120; 119, 125; 119, 162; 120, comparison_operator:==; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:e; 123, identifier:http_status; 124, integer:404; 125, block; 125, 126; 125, 134; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:emit; 131, argument_list; 131, 132; 131, 133; 132, string:'deleted'; 133, identifier:self; 134, if_statement; 134, 135; 134, 140; 134, 148; 135, call; 135, 136; 135, 137; 136, identifier:isinstance; 137, argument_list; 137, 138; 137, 139; 138, identifier:self; 139, identifier:Resource; 140, block; 140, 141; 141, raise_statement; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:ResourceNotFound; 144, argument_list; 144, 145; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:resource; 147, identifier:self; 148, elif_clause; 148, 149; 148, 154; 149, call; 149, 150; 149, 151; 150, identifier:isinstance; 151, argument_list; 151, 152; 151, 153; 152, identifier:self; 153, identifier:Collection; 154, block; 154, 155; 155, raise_statement; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:CollectionNotFound; 158, argument_list; 158, 159; 159, keyword_argument; 159, 160; 159, 161; 160, identifier:collection; 161, identifier:self; 162, elif_clause; 162, 163; 162, 168; 163, comparison_operator:==; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:e; 166, identifier:http_status; 167, integer:409; 168, block; 168, 169; 168, 181; 168, 202; 168, 214; 168, 235; 168, 247; 168, 268; 168, 280; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:matches; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:re; 175, identifier:match; 176, argument_list; 176, 177; 176, 178; 177, string:r'^Delete when children still present: (\[[^]]*\])'; 178, attribute; 178, 179; 178, 180; 179, identifier:e; 180, identifier:message; 181, if_statement; 181, 182; 181, 183; 182, identifier:matches; 183, block; 183, 184; 184, raise_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:ChildrenExists; 187, argument_list; 187, 188; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:resources; 190, call; 190, 191; 190, 192; 191, identifier:list; 192, argument_list; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:hrefs_list_to_resources; 195, argument_list; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:matches; 199, identifier:group; 200, argument_list; 200, 201; 201, integer:1; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:matches; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:re; 208, identifier:match; 209, argument_list; 209, 210; 209, 211; 210, string:r'^Delete when resource still referred: (\[[^]]*\])'; 211, attribute; 211, 212; 211, 213; 212, identifier:e; 213, identifier:message; 214, if_statement; 214, 215; 214, 216; 215, identifier:matches; 216, block; 216, 217; 217, raise_statement; 217, 218; 218, call; 218, 219; 218, 220; 219, identifier:BackRefsExists; 220, argument_list; 220, 221; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:resources; 223, call; 223, 224; 223, 225; 224, identifier:list; 225, argument_list; 225, 226; 226, call; 226, 227; 226, 228; 227, identifier:hrefs_list_to_resources; 228, argument_list; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:matches; 232, identifier:group; 233, argument_list; 233, 234; 234, integer:1; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:matches; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:re; 241, identifier:match; 242, argument_list; 242, 243; 242, 244; 243, string:r'^Children (.*) still exist$'; 244, attribute; 244, 245; 244, 246; 245, identifier:e; 246, identifier:message; 247, if_statement; 247, 248; 247, 249; 248, identifier:matches; 249, block; 249, 250; 250, raise_statement; 250, 251; 251, call; 251, 252; 251, 253; 252, identifier:ChildrenExists; 253, argument_list; 253, 254; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:resources; 256, call; 256, 257; 256, 258; 257, identifier:list; 258, argument_list; 258, 259; 259, call; 259, 260; 259, 261; 260, identifier:hrefs_to_resources; 261, argument_list; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:matches; 265, identifier:group; 266, argument_list; 266, 267; 267, integer:1; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:matches; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:re; 274, identifier:match; 275, argument_list; 275, 276; 275, 277; 276, string:r'^Back-References from (.*) still exist$'; 277, attribute; 277, 278; 277, 279; 278, identifier:e; 279, identifier:message; 280, if_statement; 280, 281; 280, 282; 281, identifier:matches; 282, block; 282, 283; 283, raise_statement; 283, 284; 284, call; 284, 285; 284, 286; 285, identifier:BackRefsExists; 286, argument_list; 286, 287; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:resources; 289, call; 289, 290; 289, 291; 290, identifier:list; 291, argument_list; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:hrefs_to_resources; 294, argument_list; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:matches; 298, identifier:group; 299, argument_list; 299, 300; 300, integer:1; 301, raise_statement; 302, return_statement; 302, 303; 303, identifier:wrapper
def http_error_handler(f): def hrefs_to_resources(hrefs): for href in hrefs.replace(',', '').split(): type, uuid = href.split('/')[-2:] yield Resource(type, uuid=uuid) def hrefs_list_to_resources(hrefs_list): for href in eval(hrefs_list): type, uuid = href.split('/')[-2:] yield Resource(type, uuid=uuid) @wraps(f) def wrapper(self, *args, **kwargs): try: return f(self, *args, **kwargs) except HttpError as e: if e.http_status == 404: self.emit('deleted', self) if isinstance(self, Resource): raise ResourceNotFound(resource=self) elif isinstance(self, Collection): raise CollectionNotFound(collection=self) elif e.http_status == 409: matches = re.match(r'^Delete when children still present: (\[[^]]*\])', e.message) if matches: raise ChildrenExists( resources=list(hrefs_list_to_resources(matches.group(1)))) matches = re.match(r'^Delete when resource still referred: (\[[^]]*\])', e.message) if matches: raise BackRefsExists( resources=list(hrefs_list_to_resources(matches.group(1)))) matches = re.match(r'^Children (.*) still exist$', e.message) if matches: raise ChildrenExists( resources=list(hrefs_to_resources(matches.group(1)))) matches = re.match(r'^Back-References from (.*) still exist$', e.message) if matches: raise BackRefsExists( resources=list(hrefs_to_resources(matches.group(1)))) raise return wrapper
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_handle_windows; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:event; 6, block; 6, 7; 6, 20; 6, 70; 6, 81; 6, 85; 6, 149; 6, 171; 6, 186; 6, 325; 6, 457; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:vkey; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_keyname; 14, argument_list; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:event; 18, identifier:GetKey; 19, argument_list; 20, if_statement; 20, 21; 20, 32; 21, comparison_operator:in; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:event; 24, identifier:Message; 25, binary_operator:+; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:KEYS_UP; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:KEYS_DOWN; 32, block; 32, 33; 33, if_statement; 33, 34; 33, 39; 34, comparison_operator:in; 34, 35; 34, 36; 35, identifier:vkey; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:MODIFIERNAMES; 39, block; 39, 40; 39, 54; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 47; 42, subscript; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:_realmodifiers; 46, identifier:vkey; 47, comparison_operator:in; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:event; 50, identifier:Message; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:KEYS_DOWN; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 65; 56, subscript; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_modifiers; 60, subscript; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:MODIFIERNAMES; 64, identifier:vkey; 65, subscript; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:_realmodifiers; 69, identifier:vkey; 70, if_statement; 70, 71; 70, 78; 71, comparison_operator:not; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:event; 74, identifier:Message; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:KEYS_DOWN; 78, block; 78, 79; 79, return_statement; 79, 80; 80, True; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:is_altgr; 84, False; 85, if_statement; 85, 86; 85, 97; 85, 106; 85, 123; 86, comparison_operator:in; 86, 87; 86, 94; 87, tuple; 87, 88; 87, 89; 88, identifier:vkey; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:event; 92, identifier:IsExtended; 93, argument_list; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:NUMPAD_SPECIALS; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:key; 101, assignment; 101, 102; 101, 103; 102, identifier:vkey; 103, binary_operator:+; 103, 104; 103, 105; 104, string:"Numpad-"; 105, identifier:vkey; 106, elif_clause; 106, 107; 106, 118; 107, boolean_operator:or; 107, 108; 107, 112; 108, not_operator; 108, 109; 109, attribute; 109, 110; 109, 111; 110, identifier:event; 111, identifier:Ascii; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:vkey; 115, identifier:startswith; 116, argument_list; 116, 117; 117, string:"Numpad"; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:key; 122, identifier:vkey; 123, else_clause; 123, 124; 124, block; 124, 125; 124, 135; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:is_altgr; 128, comparison_operator:in; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:event; 131, identifier:Ascii; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:ALT_GRS; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:key; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:_keyname; 142, argument_list; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:unichr; 145, argument_list; 145, 146; 146, attribute; 146, 147; 146, 148; 147, identifier:event; 148, identifier:Ascii; 149, if_statement; 149, 150; 149, 151; 150, identifier:DEBUG; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 155; 154, identifier:print; 155, argument_list; 155, 156; 156, binary_operator:%; 156, 157; 156, 158; 157, string:"Adding key %s (real %s)"; 158, tuple; 158, 159; 158, 165; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:key; 162, identifier:encode; 163, argument_list; 163, 164; 164, string:"utf-8"; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:vkey; 168, identifier:encode; 169, argument_list; 169, 170; 170, string:"utf-8"; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:_output; 176, argument_list; 176, 177; 176, 180; 176, 183; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:type; 179, string:"keys"; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:key; 182, identifier:key; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:realkey; 185, identifier:vkey; 186, if_statement; 186, 187; 186, 195; 187, boolean_operator:and; 187, 188; 187, 193; 188, comparison_operator:not; 188, 189; 188, 190; 189, identifier:vkey; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:MODIFIERNAMES; 193, not_operator; 193, 194; 194, identifier:is_altgr; 195, block; 195, 196; 195, 218; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:modifier; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, string:"-"; 202, identifier:join; 203, generator_expression; 203, 204; 203, 205; 203, 212; 204, identifier:k; 205, for_in_clause; 205, 206; 205, 207; 206, identifier:k; 207, list:["Ctrl", "Alt", "Shift", "Win"]; 207, 208; 207, 209; 207, 210; 207, 211; 208, string:"Ctrl"; 209, string:"Alt"; 210, string:"Shift"; 211, string:"Win"; 212, if_clause; 212, 213; 213, subscript; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:_modifiers; 217, identifier:k; 218, if_statement; 218, 219; 218, 224; 219, boolean_operator:and; 219, 220; 219, 221; 220, identifier:modifier; 221, comparison_operator:!=; 221, 222; 221, 223; 222, identifier:modifier; 223, string:"Shift"; 224, block; 224, 225; 224, 250; 224, 272; 224, 280; 224, 288; 224, 310; 225, if_statement; 225, 226; 225, 235; 226, boolean_operator:and; 226, 227; 226, 232; 227, subscript; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:_modifiers; 231, string:"Ctrl"; 232, attribute; 232, 233; 232, 234; 233, identifier:event; 234, identifier:Ascii; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:key; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:_keyname; 243, argument_list; 243, 244; 244, call; 244, 245; 244, 246; 245, identifier:unichr; 246, argument_list; 246, 247; 247, attribute; 247, 248; 247, 249; 248, identifier:event; 249, identifier:KeyID; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:realmodifier; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, string:"-"; 256, identifier:join; 257, generator_expression; 257, 258; 257, 259; 257, 270; 258, identifier:k; 259, for_in_clause; 259, 260; 259, 263; 260, pattern_list; 260, 261; 260, 262; 261, identifier:k; 262, identifier:v; 263, call; 263, 264; 263, 269; 264, attribute; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:_realmodifiers; 268, identifier:items; 269, argument_list; 270, if_clause; 270, 271; 271, identifier:v; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:realkey; 275, binary_operator:%; 275, 276; 275, 277; 276, string:"%s-%s"; 277, tuple; 277, 278; 277, 279; 278, identifier:realmodifier; 279, identifier:key; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:key; 283, binary_operator:%; 283, 284; 283, 285; 284, string:"%s-%s"; 285, tuple; 285, 286; 285, 287; 286, identifier:modifier; 287, identifier:key; 288, if_statement; 288, 289; 288, 290; 289, identifier:DEBUG; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:print; 294, argument_list; 294, 295; 295, binary_operator:%; 295, 296; 295, 297; 296, string:"Adding combo %s (real %s)"; 297, tuple; 297, 298; 297, 304; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:key; 301, identifier:encode; 302, argument_list; 302, 303; 303, string:"utf-8"; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:realkey; 307, identifier:encode; 308, argument_list; 308, 309; 309, string:"utf-8"; 310, expression_statement; 310, 311; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:_output; 315, argument_list; 315, 316; 315, 319; 315, 322; 316, keyword_argument; 316, 317; 316, 318; 317, identifier:type; 318, string:"combos"; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:key; 321, identifier:key; 322, keyword_argument; 322, 323; 322, 324; 323, identifier:realkey; 324, identifier:realkey; 325, if_statement; 325, 326; 325, 327; 326, identifier:DEBUG; 327, block; 327, 328; 327, 335; 327, 349; 327, 363; 327, 377; 327, 391; 327, 405; 327, 417; 327, 429; 327, 441; 327, 453; 328, expression_statement; 328, 329; 329, call; 329, 330; 329, 331; 330, identifier:print; 331, argument_list; 331, 332; 332, binary_operator:%; 332, 333; 332, 334; 333, string:"CHARACTER: %r"; 334, identifier:key; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 338; 337, identifier:print; 338, argument_list; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, string:'GetKey: {0}'; 342, identifier:format; 343, argument_list; 343, 344; 344, call; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:event; 347, identifier:GetKey; 348, argument_list; 349, expression_statement; 349, 350; 350, call; 350, 351; 350, 352; 351, identifier:print; 352, argument_list; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, string:'IsAlt: {0}'; 356, identifier:format; 357, argument_list; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:event; 361, identifier:IsAlt; 362, argument_list; 363, expression_statement; 363, 364; 364, call; 364, 365; 364, 366; 365, identifier:print; 366, argument_list; 366, 367; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, string:'IsExtended: {0}'; 370, identifier:format; 371, argument_list; 371, 372; 372, call; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:event; 375, identifier:IsExtended; 376, argument_list; 377, expression_statement; 377, 378; 378, call; 378, 379; 378, 380; 379, identifier:print; 380, argument_list; 380, 381; 381, call; 381, 382; 381, 385; 382, attribute; 382, 383; 382, 384; 383, string:'IsInjected: {0}'; 384, identifier:format; 385, argument_list; 385, 386; 386, call; 386, 387; 386, 390; 387, attribute; 387, 388; 387, 389; 388, identifier:event; 389, identifier:IsInjected; 390, argument_list; 391, expression_statement; 391, 392; 392, call; 392, 393; 392, 394; 393, identifier:print; 394, argument_list; 394, 395; 395, call; 395, 396; 395, 399; 396, attribute; 396, 397; 396, 398; 397, string:'IsTransition: {0}'; 398, identifier:format; 399, argument_list; 399, 400; 400, call; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:event; 403, identifier:IsTransition; 404, argument_list; 405, expression_statement; 405, 406; 406, call; 406, 407; 406, 408; 407, identifier:print; 408, argument_list; 408, 409; 409, call; 409, 410; 409, 413; 410, attribute; 410, 411; 410, 412; 411, string:'ASCII: {0}'; 412, identifier:format; 413, argument_list; 413, 414; 414, attribute; 414, 415; 414, 416; 415, identifier:event; 416, identifier:Ascii; 417, expression_statement; 417, 418; 418, call; 418, 419; 418, 420; 419, identifier:print; 420, argument_list; 420, 421; 421, call; 421, 422; 421, 425; 422, attribute; 422, 423; 422, 424; 423, string:'KeyID: {0}'; 424, identifier:format; 425, argument_list; 425, 426; 426, attribute; 426, 427; 426, 428; 427, identifier:event; 428, identifier:KeyID; 429, expression_statement; 429, 430; 430, call; 430, 431; 430, 432; 431, identifier:print; 432, argument_list; 432, 433; 433, call; 433, 434; 433, 437; 434, attribute; 434, 435; 434, 436; 435, string:'ScanCode: {0}'; 436, identifier:format; 437, argument_list; 437, 438; 438, attribute; 438, 439; 438, 440; 439, identifier:event; 440, identifier:ScanCode; 441, expression_statement; 441, 442; 442, call; 442, 443; 442, 444; 443, identifier:print; 444, argument_list; 444, 445; 445, call; 445, 446; 445, 449; 446, attribute; 446, 447; 446, 448; 447, string:'Message: {0}'; 448, identifier:format; 449, argument_list; 449, 450; 450, attribute; 450, 451; 450, 452; 451, identifier:event; 452, identifier:Message; 453, expression_statement; 453, 454; 454, call; 454, 455; 454, 456; 455, identifier:print; 456, argument_list; 457, return_statement; 457, 458; 458, True
def _handle_windows(self, event): vkey = self._keyname(event.GetKey()) if event.Message in self.KEYS_UP + self.KEYS_DOWN: if vkey in self.MODIFIERNAMES: self._realmodifiers[vkey] = event.Message in self.KEYS_DOWN self._modifiers[self.MODIFIERNAMES[vkey]] = self._realmodifiers[vkey] if event.Message not in self.KEYS_DOWN: return True is_altgr = False if (vkey, event.IsExtended()) in self.NUMPAD_SPECIALS: key = vkey = "Numpad-" + vkey elif not event.Ascii or vkey.startswith("Numpad"): key = vkey else: is_altgr = event.Ascii in self.ALT_GRS key = self._keyname(unichr(event.Ascii)) if DEBUG: print("Adding key %s (real %s)" % (key.encode("utf-8"), vkey.encode("utf-8"))) self._output(type="keys", key=key, realkey=vkey) if vkey not in self.MODIFIERNAMES and not is_altgr: modifier = "-".join(k for k in ["Ctrl", "Alt", "Shift", "Win"] if self._modifiers[k]) if modifier and modifier != "Shift": if self._modifiers["Ctrl"] and event.Ascii: key = self._keyname(unichr(event.KeyID)) realmodifier = "-".join(k for k, v in self._realmodifiers.items() if v) realkey = "%s-%s" % (realmodifier, key) key = "%s-%s" % (modifier, key) if DEBUG: print("Adding combo %s (real %s)" % (key.encode("utf-8"), realkey.encode("utf-8"))) self._output(type="combos", key=key, realkey=realkey) if DEBUG: print("CHARACTER: %r" % key) print('GetKey: {0}'.format(event.GetKey())) print('IsAlt: {0}'.format(event.IsAlt())) print('IsExtended: {0}'.format(event.IsExtended())) print('IsInjected: {0}'.format(event.IsInjected())) print('IsTransition: {0}'.format(event.IsTransition())) print('ASCII: {0}'.format(event.Ascii)) print('KeyID: {0}'.format(event.KeyID)) print('ScanCode: {0}'.format(event.ScanCode)) print('Message: {0}'.format(event.Message)) print() return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_handle_linux; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:keycode; 6, identifier:character; 7, identifier:press; 8, block; 8, 9; 8, 15; 8, 25; 8, 52; 8, 70; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:character; 12, None; 13, block; 13, 14; 14, return_statement; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:key; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_keyname; 22, argument_list; 22, 23; 22, 24; 23, identifier:character; 24, identifier:keycode; 25, if_statement; 25, 26; 25, 31; 26, comparison_operator:in; 26, 27; 26, 28; 27, identifier:key; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:MODIFIERNAMES; 31, block; 31, 32; 31, 44; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 43; 34, subscript; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_modifiers; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:MODIFIERNAMES; 42, identifier:key; 43, identifier:press; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 51; 46, subscript; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_realmodifiers; 50, identifier:key; 51, identifier:press; 52, if_statement; 52, 53; 52, 54; 53, identifier:press; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_output; 60, argument_list; 60, 61; 60, 64; 60, 67; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:type; 63, string:"keys"; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:key; 66, identifier:key; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:realkey; 69, identifier:key; 70, if_statement; 70, 71; 70, 78; 71, boolean_operator:and; 71, 72; 71, 73; 72, identifier:press; 73, comparison_operator:not; 73, 74; 73, 75; 74, identifier:key; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:MODIFIERNAMES; 78, block; 78, 79; 78, 101; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:modifier; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, string:"-"; 85, identifier:join; 86, generator_expression; 86, 87; 86, 88; 86, 95; 87, identifier:k; 88, for_in_clause; 88, 89; 88, 90; 89, identifier:k; 90, list:["Ctrl", "Alt", "Shift", "Win"]; 90, 91; 90, 92; 90, 93; 90, 94; 91, string:"Ctrl"; 92, string:"Alt"; 93, string:"Shift"; 94, string:"Win"; 95, if_clause; 95, 96; 96, subscript; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_modifiers; 100, identifier:k; 101, if_statement; 101, 102; 101, 107; 102, boolean_operator:and; 102, 103; 102, 104; 103, identifier:modifier; 104, comparison_operator:!=; 104, 105; 104, 106; 105, identifier:modifier; 106, string:"Shift"; 107, block; 107, 108; 107, 130; 107, 138; 107, 146; 107, 168; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:realmodifier; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, string:"-"; 114, identifier:join; 115, generator_expression; 115, 116; 115, 117; 115, 128; 116, identifier:k; 117, for_in_clause; 117, 118; 117, 121; 118, pattern_list; 118, 119; 118, 120; 119, identifier:k; 120, identifier:v; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:_realmodifiers; 126, identifier:items; 127, argument_list; 128, if_clause; 128, 129; 129, identifier:v; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:realkey; 133, binary_operator:%; 133, 134; 133, 135; 134, string:"%s-%s"; 135, tuple; 135, 136; 135, 137; 136, identifier:realmodifier; 137, identifier:key; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:key; 141, binary_operator:%; 141, 142; 141, 143; 142, string:"%s-%s"; 143, tuple; 143, 144; 143, 145; 144, identifier:modifier; 145, identifier:key; 146, if_statement; 146, 147; 146, 148; 147, identifier:DEBUG; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:print; 152, argument_list; 152, 153; 153, binary_operator:%; 153, 154; 153, 155; 154, string:"Adding combo %s (real %s)"; 155, tuple; 155, 156; 155, 162; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:key; 159, identifier:encode; 160, argument_list; 160, 161; 161, string:"utf-8"; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:realkey; 165, identifier:encode; 166, argument_list; 166, 167; 167, string:"utf-8"; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:_output; 173, argument_list; 173, 174; 173, 177; 173, 180; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:type; 176, string:"combos"; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:key; 179, identifier:key; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:realkey; 182, identifier:realkey
def _handle_linux(self, keycode, character, press): if character is None: return key = self._keyname(character, keycode) if key in self.MODIFIERNAMES: self._modifiers[self.MODIFIERNAMES[key]] = press self._realmodifiers[key] = press if press: self._output(type="keys", key=key, realkey=key) if press and key not in self.MODIFIERNAMES: modifier = "-".join(k for k in ["Ctrl", "Alt", "Shift", "Win"] if self._modifiers[k]) if modifier and modifier != "Shift": realmodifier = "-".join(k for k, v in self._realmodifiers.items() if v) realkey = "%s-%s" % (realmodifier, key) key = "%s-%s" % (modifier, key) if DEBUG: print("Adding combo %s (real %s)" % (key.encode("utf-8"), realkey.encode("utf-8"))) self._output(type="combos", key=key, realkey=realkey)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_store_documentation; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:path; 6, identifier:html; 7, identifier:overwrite; 8, identifier:quiet; 9, block; 9, 10; 9, 15; 9, 26; 9, 44; 9, 66; 9, 91; 9, 116; 9, 149; 9, 153; 9, 212; 9, 217; 9, 230; 9, 237; 9, 241; 9, 262; 9, 274; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:echo; 13, argument_list; 13, 14; 14, string:"Storing groundwork application documents\n"; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:echo; 18, argument_list; 18, 19; 19, binary_operator:%; 19, 20; 19, 21; 20, string:"Application: %s"; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:app; 25, identifier:name; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:echo; 29, argument_list; 29, 30; 30, binary_operator:%; 30, 31; 30, 32; 31, string:"Number of documents: %s\n"; 32, call; 32, 33; 32, 34; 33, identifier:len; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 43; 36, attribute; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:app; 41, identifier:documents; 42, identifier:get; 43, argument_list; 44, if_statement; 44, 45; 44, 54; 45, not_operator; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:os; 50, identifier:path; 51, identifier:isabs; 52, argument_list; 52, 53; 53, identifier:path; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier: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:abspath; 64, argument_list; 64, 65; 65, identifier:path; 66, if_statement; 66, 67; 66, 76; 67, not_operator; 67, 68; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:os; 72, identifier:path; 73, identifier:isdir; 74, argument_list; 74, 75; 75, identifier:path; 76, block; 76, 77; 76, 84; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:echo; 80, argument_list; 80, 81; 81, binary_operator:%; 81, 82; 81, 83; 82, string:"Path %s is not a directory!"; 83, identifier:path; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:sys; 88, identifier:exit; 89, argument_list; 89, 90; 90, integer:1; 91, if_statement; 91, 92; 91, 101; 92, not_operator; 92, 93; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:os; 97, identifier:path; 98, identifier:exists; 99, argument_list; 99, 100; 100, identifier:path; 101, block; 101, 102; 101, 109; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:echo; 105, argument_list; 105, 106; 106, binary_operator:%; 106, 107; 106, 108; 107, string:"Path %s does not exist"; 108, identifier:path; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:sys; 113, identifier:exit; 114, argument_list; 114, 115; 115, integer:1; 116, for_statement; 116, 117; 116, 121; 116, 127; 117, pattern_list; 117, 118; 117, 119; 117, 120; 118, identifier:dirpath; 119, identifier:dirnames; 120, identifier:files; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:os; 124, identifier:walk; 125, argument_list; 125, 126; 126, identifier:path; 127, block; 127, 128; 128, if_statement; 128, 129; 128, 130; 129, identifier:files; 130, block; 130, 131; 130, 138; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:echo; 134, argument_list; 134, 135; 135, binary_operator:%; 135, 136; 135, 137; 136, string:"Path %s is not empty!\n"; 137, identifier:path; 138, if_statement; 138, 139; 138, 141; 139, not_operator; 139, 140; 140, identifier:overwrite; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:sys; 146, identifier:exit; 147, argument_list; 147, 148; 148, integer:1; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:documents; 152, list:[]; 153, for_statement; 153, 154; 153, 157; 153, 170; 154, pattern_list; 154, 155; 154, 156; 155, identifier:key; 156, identifier:document; 157, call; 157, 158; 157, 169; 158, attribute; 158, 159; 158, 168; 159, call; 159, 160; 159, 167; 160, attribute; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:app; 165, identifier:documents; 166, identifier:get; 167, argument_list; 168, identifier:items; 169, argument_list; 170, block; 170, 171; 170, 178; 170, 190; 170, 199; 170, 203; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:file_extension; 174, conditional_expression:if; 174, 175; 174, 176; 174, 177; 175, string:".html"; 176, identifier:html; 177, string:".rst"; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:file_name_parts; 181, call; 181, 182; 181, 189; 182, attribute; 182, 183; 182, 188; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:key; 186, identifier:lower; 187, argument_list; 188, identifier:split; 189, argument_list; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:file_name; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, string:""; 196, identifier:join; 197, argument_list; 197, 198; 198, identifier:file_name_parts; 199, expression_statement; 199, 200; 200, augmented_assignment:+=; 200, 201; 200, 202; 201, identifier:file_name; 202, identifier:file_extension; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:documents; 207, identifier:append; 208, argument_list; 208, 209; 209, tuple; 209, 210; 209, 211; 210, identifier:file_name; 211, identifier:document; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:echo; 215, argument_list; 215, 216; 216, string:"Going to write to following files:"; 217, for_statement; 217, 218; 217, 219; 217, 220; 218, identifier:document; 219, identifier:documents; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:echo; 224, argument_list; 224, 225; 225, binary_operator:%; 225, 226; 225, 227; 226, string:" %s"; 227, subscript; 227, 228; 227, 229; 228, identifier:document; 229, integer:0; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 233; 232, identifier:echo; 233, argument_list; 233, 234; 234, binary_operator:%; 234, 235; 234, 236; 235, string:"\nTarget directory: %s"; 236, identifier:path; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:answer; 240, None; 241, while_statement; 241, 242; 241, 250; 242, boolean_operator:and; 242, 243; 242, 248; 243, comparison_operator:not; 243, 244; 243, 245; 244, identifier:answer; 245, list:["N", "Y"]; 245, 246; 245, 247; 246, string:"N"; 247, string:"Y"; 248, not_operator; 248, 249; 249, identifier:quiet; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:answer; 254, call; 254, 255; 254, 261; 255, attribute; 255, 256; 255, 260; 256, call; 256, 257; 256, 258; 257, identifier:prompt; 258, argument_list; 258, 259; 259, string:"Shall we go on? [Y]es, [N]o: "; 260, identifier:upper; 261, argument_list; 262, if_statement; 262, 263; 262, 266; 263, comparison_operator:==; 263, 264; 263, 265; 264, identifier:answer; 265, string:"N"; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:sys; 271, identifier:exit; 272, argument_list; 272, 273; 273, integer:0; 274, for_statement; 274, 275; 274, 276; 274, 277; 275, identifier:document; 276, identifier:documents; 277, block; 277, 278; 278, try_statement; 278, 279; 278, 361; 278, 378; 279, block; 279, 280; 280, with_statement; 280, 281; 280, 301; 281, with_clause; 281, 282; 282, with_item; 282, 283; 283, as_pattern; 283, 284; 283, 299; 284, call; 284, 285; 284, 286; 285, identifier:open; 286, argument_list; 286, 287; 286, 298; 287, call; 287, 288; 287, 293; 288, attribute; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:os; 291, identifier:path; 292, identifier:join; 293, argument_list; 293, 294; 293, 295; 294, identifier:path; 295, subscript; 295, 296; 295, 297; 296, identifier:document; 297, integer:0; 298, string:"w"; 299, as_pattern_target; 299, 300; 300, identifier:doc_file; 301, block; 301, 302; 301, 333; 301, 354; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:doc_rendered; 305, call; 305, 306; 305, 320; 306, attribute; 306, 307; 306, 319; 307, call; 307, 308; 307, 313; 308, attribute; 308, 309; 308, 312; 309, call; 309, 310; 309, 311; 310, identifier:Environment; 311, argument_list; 312, identifier:from_string; 313, argument_list; 313, 314; 314, attribute; 314, 315; 314, 318; 315, subscript; 315, 316; 315, 317; 316, identifier:document; 317, integer:1; 318, identifier:content; 319, identifier:render; 320, argument_list; 320, 321; 320, 326; 321, keyword_argument; 321, 322; 321, 323; 322, identifier:app; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:app; 326, keyword_argument; 326, 327; 326, 328; 327, identifier:plugin; 328, attribute; 328, 329; 328, 332; 329, subscript; 329, 330; 329, 331; 330, identifier:document; 331, integer:1; 332, identifier:plugin; 333, if_statement; 333, 334; 333, 335; 333, 348; 334, identifier:html; 335, block; 335, 336; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:output; 339, subscript; 339, 340; 339, 347; 340, call; 340, 341; 340, 342; 341, identifier:publish_parts; 342, argument_list; 342, 343; 342, 344; 343, identifier:doc_rendered; 344, keyword_argument; 344, 345; 344, 346; 345, identifier:writer_name; 346, string:"html"; 347, string:'whole'; 348, else_clause; 348, 349; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 353; 352, identifier:output; 353, identifier:doc_rendered; 354, expression_statement; 354, 355; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:doc_file; 358, identifier:write; 359, argument_list; 359, 360; 360, identifier:output; 361, except_clause; 361, 362; 361, 366; 362, as_pattern; 362, 363; 362, 364; 363, identifier:Exception; 364, as_pattern_target; 364, 365; 365, identifier:e; 366, block; 366, 367; 367, expression_statement; 367, 368; 368, call; 368, 369; 368, 370; 369, identifier:echo; 370, argument_list; 370, 371; 371, binary_operator:%; 371, 372; 371, 373; 372, string:"%s error occurred: %s"; 373, tuple; 373, 374; 373, 377; 374, subscript; 374, 375; 374, 376; 375, identifier:document; 376, integer:0; 377, identifier:e; 378, else_clause; 378, 379; 379, block; 379, 380; 380, expression_statement; 380, 381; 381, call; 381, 382; 381, 383; 382, identifier:echo; 383, argument_list; 383, 384; 384, binary_operator:%; 384, 385; 384, 386; 385, string:"%s stored."; 386, subscript; 386, 387; 386, 388; 387, identifier:document; 388, integer:0
def _store_documentation(self, path, html, overwrite, quiet): echo("Storing groundwork application documents\n") echo("Application: %s" % self.app.name) echo("Number of documents: %s\n" % len(self.app.documents.get())) if not os.path.isabs(path): path = os.path.abspath(path) if not os.path.isdir(path): echo("Path %s is not a directory!" % path) sys.exit(1) if not os.path.exists(path): echo("Path %s does not exist" % path) sys.exit(1) for dirpath, dirnames, files in os.walk(path): if files: echo("Path %s is not empty!\n" % path) if not overwrite: sys.exit(1) documents = [] for key, document in self.app.documents.get().items(): file_extension = ".html" if html else ".rst" file_name_parts = key.lower().split() file_name = "".join(file_name_parts) file_name += file_extension documents.append((file_name, document)) echo("Going to write to following files:") for document in documents: echo(" %s" % document[0]) echo("\nTarget directory: %s" % path) answer = None while answer not in ["N", "Y"] and not quiet: answer = prompt("Shall we go on? [Y]es, [N]o: ").upper() if answer == "N": sys.exit(0) for document in documents: try: with open(os.path.join(path, document[0]), "w") as doc_file: doc_rendered = Environment().from_string(document[1].content).render(app=self.app, plugin=document[1].plugin) if html: output = publish_parts(doc_rendered, writer_name="html")['whole'] else: output = doc_rendered doc_file.write(output) except Exception as e: echo("%s error occurred: %s" % (document[0], e)) else: echo("%s stored." % document[0])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_show_documentation; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 42; 5, 57; 5, 70; 5, 87; 5, 91; 5, 95; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:documents; 9, list:[]; 10, for_statement; 10, 11; 10, 14; 10, 27; 11, pattern_list; 11, 12; 11, 13; 12, identifier:key; 13, identifier:document; 14, call; 14, 15; 14, 26; 15, attribute; 15, 16; 15, 25; 16, call; 16, 17; 16, 24; 17, attribute; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:app; 22, identifier:documents; 23, identifier:get; 24, argument_list; 25, identifier:items; 26, argument_list; 27, block; 27, 28; 28, if_statement; 28, 29; 28, 32; 29, comparison_operator:!=; 29, 30; 29, 31; 30, identifier:key; 31, string:"main"; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:documents; 37, identifier:append; 38, argument_list; 38, 39; 39, tuple; 39, 40; 39, 41; 40, identifier:key; 41, identifier:document; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:documents; 45, call; 45, 46; 45, 47; 46, identifier:sorted; 47, argument_list; 47, 48; 47, 49; 48, identifier:documents; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:key; 51, lambda; 51, 52; 51, 54; 52, lambda_parameters; 52, 53; 53, identifier:x; 54, subscript; 54, 55; 54, 56; 55, identifier:x; 56, integer:0; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:main; 60, call; 60, 61; 60, 68; 61, attribute; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:app; 66, identifier:documents; 67, identifier:get; 68, argument_list; 68, 69; 69, string:"main"; 70, if_statement; 70, 71; 70, 74; 71, comparison_operator:is; 71, 72; 71, 73; 72, identifier:main; 73, None; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:documents; 79, identifier:insert; 80, argument_list; 80, 81; 80, 82; 81, integer:0; 82, tuple; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:main; 85, identifier:name; 86, identifier:main; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:user_answer; 90, string:""; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:index; 94, integer:0; 95, while_statement; 95, 96; 95, 99; 96, comparison_operator:!=; 96, 97; 96, 98; 97, identifier:user_answer; 98, string:"X"; 99, block; 99, 100; 99, 109; 99, 128; 99, 136; 99, 150; 99, 178; 99, 192; 99, 202; 99, 207; 99, 217; 99, 221; 99, 235; 99, 244; 99, 248; 99, 253; 99, 282; 99, 296; 100, if_statement; 100, 101; 100, 104; 101, comparison_operator:<; 101, 102; 101, 103; 102, identifier:index; 103, integer:0; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:index; 108, integer:0; 109, if_statement; 109, 110; 109, 118; 110, comparison_operator:>; 110, 111; 110, 112; 111, identifier:index; 112, binary_operator:-; 112, 113; 112, 117; 113, call; 113, 114; 113, 115; 114, identifier:len; 115, argument_list; 115, 116; 116, identifier:documents; 117, integer:1; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:index; 122, binary_operator:-; 122, 123; 122, 127; 123, call; 123, 124; 123, 125; 124, identifier:len; 125, argument_list; 125, 126; 126, identifier:documents; 127, integer:1; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:document; 131, subscript; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:documents; 134, identifier:index; 135, integer:1; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:os; 140, identifier:system; 141, argument_list; 141, 142; 142, conditional_expression:if; 142, 143; 142, 144; 142, 149; 143, string:'cls'; 144, comparison_operator:==; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:os; 147, identifier:name; 148, string:'nt'; 149, string:'clear'; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 153; 152, identifier:echo; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 167; 155, attribute; 155, 156; 155, 166; 156, call; 156, 157; 156, 162; 157, attribute; 157, 158; 157, 161; 158, call; 158, 159; 158, 160; 159, identifier:Environment; 160, argument_list; 161, identifier:from_string; 162, argument_list; 162, 163; 163, attribute; 163, 164; 163, 165; 164, identifier:document; 165, identifier:content; 166, identifier:render; 167, argument_list; 167, 168; 167, 173; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:app; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:app; 173, keyword_argument; 173, 174; 173, 175; 174, identifier:plugin; 175, attribute; 175, 176; 175, 177; 176, identifier:document; 177, identifier:plugin; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:source; 181, binary_operator:%; 181, 182; 181, 183; 182, string:"This document is registered by '%s' under the name '%s'"; 183, tuple; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:document; 187, identifier:plugin; 188, identifier:name; 189, attribute; 189, 190; 189, 191; 190, identifier:document; 191, identifier:name; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:echo; 195, argument_list; 195, 196; 196, binary_operator:*; 196, 197; 196, 198; 197, string:"-"; 198, call; 198, 199; 198, 200; 199, identifier:len; 200, argument_list; 200, 201; 201, identifier:source; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:echo; 205, argument_list; 205, 206; 206, identifier:source; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 210; 209, identifier:echo; 210, argument_list; 210, 211; 211, binary_operator:*; 211, 212; 211, 213; 212, string:"-"; 213, call; 213, 214; 213, 215; 214, identifier:len; 215, argument_list; 215, 216; 216, identifier:source; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:commands; 220, string:"Actions: "; 221, if_statement; 221, 222; 221, 230; 222, comparison_operator:<; 222, 223; 222, 224; 223, identifier:index; 224, binary_operator:-; 224, 225; 224, 229; 225, call; 225, 226; 225, 227; 226, identifier:len; 227, argument_list; 227, 228; 228, identifier:documents; 229, integer:1; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, augmented_assignment:+=; 232, 233; 232, 234; 233, identifier:commands; 234, string:"[N]ext, "; 235, if_statement; 235, 236; 235, 239; 236, comparison_operator:>; 236, 237; 236, 238; 237, identifier:index; 238, integer:0; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, augmented_assignment:+=; 241, 242; 241, 243; 242, identifier:commands; 243, string:"[P]revious, "; 244, expression_statement; 244, 245; 245, augmented_assignment:+=; 245, 246; 245, 247; 246, identifier:commands; 247, string:"E[x]it"; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 251; 250, identifier:echo; 251, argument_list; 251, 252; 252, identifier:commands; 253, if_statement; 253, 254; 253, 262; 253, 267; 253, 276; 254, comparison_operator:<; 254, 255; 254, 256; 255, identifier:index; 256, binary_operator:-; 256, 257; 256, 261; 257, call; 257, 258; 257, 259; 258, identifier:len; 259, argument_list; 259, 260; 260, identifier:documents; 261, integer:1; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:default; 266, string:"N"; 267, elif_clause; 267, 268; 267, 271; 268, comparison_operator:>; 268, 269; 268, 270; 269, identifier:index; 270, integer:0; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:default; 275, string:"P"; 276, else_clause; 276, 277; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:default; 281, string:"X"; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:user_answer; 285, call; 285, 286; 285, 295; 286, attribute; 286, 287; 286, 294; 287, call; 287, 288; 287, 289; 288, identifier:prompt; 289, argument_list; 289, 290; 289, 291; 290, string:"Select your action"; 291, keyword_argument; 291, 292; 291, 293; 292, identifier:default; 293, identifier:default; 294, identifier:upper; 295, argument_list; 296, if_statement; 296, 297; 296, 300; 296, 305; 297, comparison_operator:==; 297, 298; 297, 299; 298, identifier:user_answer; 299, string:"N"; 300, block; 300, 301; 301, expression_statement; 301, 302; 302, augmented_assignment:+=; 302, 303; 302, 304; 303, identifier:index; 304, integer:1; 305, elif_clause; 305, 306; 305, 309; 306, comparison_operator:==; 306, 307; 306, 308; 307, identifier:user_answer; 308, string:"P"; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, augmented_assignment:-=; 311, 312; 311, 313; 312, identifier:index; 313, integer:1
def _show_documentation(self): documents = [] for key, document in self.app.documents.get().items(): if key != "main": documents.append((key, document)) documents = sorted(documents, key=lambda x: x[0]) main = self.app.documents.get("main") if main is not None: documents.insert(0, (main.name, main)) user_answer = "" index = 0 while user_answer != "X": if index < 0: index = 0 if index > len(documents) - 1: index = len(documents) - 1 document = documents[index][1] os.system('cls' if os.name == 'nt' else 'clear') echo(Environment().from_string(document.content).render(app=self.app, plugin=document.plugin)) source = "This document is registered by '%s' under the name '%s'" % (document.plugin.name, document.name) echo("-" * len(source)) echo(source) echo("-" * len(source)) commands = "Actions: " if index < len(documents) - 1: commands += "[N]ext, " if index > 0: commands += "[P]revious, " commands += "E[x]it" echo(commands) if index < len(documents) - 1: default = "N" elif index > 0: default = "P" else: default = "X" user_answer = prompt("Select your action", default=default).upper() if user_answer == "N": index += 1 elif user_answer == "P": index -= 1
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:infer_declared_from_conditions; 3, parameters; 3, 4; 3, 5; 4, identifier:conds; 5, default_parameter; 5, 6; 5, 7; 6, identifier:namespace; 7, None; 8, block; 8, 9; 8, 11; 8, 15; 8, 26; 8, 35; 8, 44; 8, 50; 8, 54; 8, 149; 8, 160; 9, expression_statement; 9, 10; 10, string:''' like infer_declared except that it is passed a set of first party caveat conditions as a list of string rather than a set of macaroons. '''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:conflicts; 14, list:[]; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:namespace; 18, None; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:namespace; 23, call; 23, 24; 23, 25; 24, identifier:Namespace; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:prefix; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:namespace; 32, identifier:resolve; 33, argument_list; 33, 34; 34, identifier:STD_NAMESPACE; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:prefix; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:prefix; 43, string:''; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:declared_cond; 47, binary_operator:+; 47, 48; 47, 49; 48, identifier:prefix; 49, identifier:COND_DECLARED; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:info; 53, dictionary; 54, for_statement; 54, 55; 54, 56; 54, 57; 55, identifier:cond; 56, identifier:conds; 57, block; 57, 58; 57, 80; 57, 86; 57, 96; 57, 105; 57, 117; 57, 126; 57, 143; 58, try_statement; 58, 59; 58, 69; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, pattern_list; 62, 63; 62, 64; 63, identifier:name; 64, identifier:rest; 65, call; 65, 66; 65, 67; 66, identifier:parse_caveat; 67, argument_list; 67, 68; 68, identifier:cond; 69, except_clause; 69, 70; 69, 71; 70, identifier:ValueError; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, pattern_list; 74, 75; 74, 76; 75, identifier:name; 76, identifier:rest; 77, expression_list; 77, 78; 77, 79; 78, string:''; 79, string:''; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:!=; 81, 82; 81, 83; 82, identifier:name; 83, identifier:declared_cond; 84, block; 84, 85; 85, continue_statement; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:parts; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:rest; 92, identifier:split; 93, argument_list; 93, 94; 93, 95; 94, string:' '; 95, integer:1; 96, if_statement; 96, 97; 96, 103; 97, comparison_operator:!=; 97, 98; 97, 102; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, identifier:parts; 102, integer:2; 103, block; 103, 104; 104, continue_statement; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, pattern_list; 107, 108; 107, 109; 108, identifier:key; 109, identifier:val; 110, expression_list; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:parts; 113, integer:0; 114, subscript; 114, 115; 114, 116; 115, identifier:parts; 116, integer:1; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:old_val; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:info; 123, identifier:get; 124, argument_list; 124, 125; 125, identifier:key; 126, if_statement; 126, 127; 126, 134; 127, boolean_operator:and; 127, 128; 127, 131; 128, comparison_operator:is; 128, 129; 128, 130; 129, identifier:old_val; 130, None; 131, comparison_operator:!=; 131, 132; 131, 133; 132, identifier:old_val; 133, identifier:val; 134, block; 134, 135; 134, 142; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:conflicts; 139, identifier:append; 140, argument_list; 140, 141; 141, identifier:key; 142, continue_statement; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:info; 147, identifier:key; 148, identifier:val; 149, for_statement; 149, 150; 149, 151; 149, 155; 150, identifier:key; 151, call; 151, 152; 151, 153; 152, identifier:set; 153, argument_list; 153, 154; 154, identifier:conflicts; 155, block; 155, 156; 156, delete_statement; 156, 157; 157, subscript; 157, 158; 157, 159; 158, identifier:info; 159, identifier:key; 160, return_statement; 160, 161; 161, identifier:info
def infer_declared_from_conditions(conds, namespace=None): ''' like infer_declared except that it is passed a set of first party caveat conditions as a list of string rather than a set of macaroons. ''' conflicts = [] if namespace is None: namespace = Namespace() prefix = namespace.resolve(STD_NAMESPACE) if prefix is None: prefix = '' declared_cond = prefix + COND_DECLARED info = {} for cond in conds: try: name, rest = parse_caveat(cond) except ValueError: name, rest = '', '' if name != declared_cond: continue parts = rest.split(' ', 1) if len(parts) != 2: continue key, val = parts[0], parts[1] old_val = info.get(key) if old_val is not None and old_val != val: conflicts.append(key) continue info[key] = val for key in set(conflicts): del info[key] return info
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_cited_dois; 3, parameters; 3, 4; 4, identifier:file; 5, block; 5, 6; 5, 27; 5, 31; 5, 35; 5, 119; 5, 200; 6, if_statement; 6, 7; 6, 13; 6, 21; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 12; 11, identifier:file; 12, identifier:list; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:plaintext_citations; 17, call; 17, 18; 17, 19; 18, identifier:get_plaintext_citations; 19, argument_list; 19, 20; 20, identifier:file; 21, else_clause; 21, 22; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:plaintext_citations; 26, identifier:file; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:dois; 30, dictionary; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:crossref_queue; 34, list:[]; 35, for_statement; 35, 36; 35, 37; 35, 41; 36, identifier:citation; 37, subscript; 37, 38; 37, 39; 38, identifier:plaintext_citations; 39, slice; 39, 40; 40, colon; 41, block; 41, 42; 41, 51; 41, 72; 41, 81; 41, 107; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:matched_dois; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:doi; 48, identifier:extract_from_text; 49, argument_list; 49, 50; 50, identifier:citation; 51, if_statement; 51, 52; 51, 58; 52, comparison_operator:>; 52, 53; 52, 57; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:matched_dois; 57, integer:0; 58, block; 58, 59; 58, 71; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:dois; 63, identifier:citation; 64, call; 64, 65; 64, 66; 65, identifier:next; 66, argument_list; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:iter; 69, argument_list; 69, 70; 70, identifier:matched_dois; 71, continue_statement; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:matched_arxiv; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:arxiv; 78, identifier:extract_from_text; 79, argument_list; 79, 80; 80, identifier:citation; 81, if_statement; 81, 82; 81, 88; 82, comparison_operator:>; 82, 83; 82, 87; 83, call; 83, 84; 83, 85; 84, identifier:len; 85, argument_list; 85, 86; 86, identifier:matched_arxiv; 87, integer:0; 88, block; 88, 89; 88, 106; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:dois; 93, identifier:citation; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:arxiv; 97, identifier:to_doi; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:next; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:iter; 104, argument_list; 104, 105; 105, identifier:matched_arxiv; 106, continue_statement; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:crossref_queue; 111, identifier:append; 112, argument_list; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:tools; 116, identifier:remove_urls; 117, argument_list; 117, 118; 118, identifier:citation; 119, for_statement; 119, 120; 119, 121; 119, 128; 120, identifier:batch; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:tools; 124, identifier:batch; 125, argument_list; 125, 126; 125, 127; 126, identifier:crossref_queue; 127, identifier:CROSSREF_MAX_BATCH_SIZE; 128, block; 128, 129; 128, 137; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:batch; 132, list_comprehension; 132, 133; 132, 134; 133, identifier:i; 134, for_in_clause; 134, 135; 134, 136; 135, identifier:i; 136, identifier:batch; 137, try_statement; 137, 138; 137, 184; 138, block; 138, 139; 138, 151; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:request; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:requests; 145, identifier:post; 146, argument_list; 146, 147; 146, 148; 147, identifier:CROSSREF_LINKS_API_URL; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:json; 150, identifier:batch; 151, for_statement; 151, 152; 151, 153; 151, 160; 152, identifier:result; 153, subscript; 153, 154; 153, 159; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:request; 157, identifier:json; 158, argument_list; 159, string:"results"; 160, block; 160, 161; 161, try_statement; 161, 162; 161, 173; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 170; 165, subscript; 165, 166; 165, 167; 166, identifier:dois; 167, subscript; 167, 168; 167, 169; 168, identifier:result; 169, string:"text"; 170, subscript; 170, 171; 170, 172; 171, identifier:result; 172, string:"doi"; 173, except_clause; 173, 174; 173, 175; 174, identifier:KeyError; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 183; 178, subscript; 178, 179; 178, 180; 179, identifier:dois; 180, subscript; 180, 181; 180, 182; 181, identifier:result; 182, string:"text"; 183, None; 184, except_clause; 184, 185; 184, 189; 185, tuple; 185, 186; 185, 187; 185, 188; 186, identifier:RequestException; 187, identifier:ValueError; 188, identifier:KeyError; 189, block; 189, 190; 190, for_statement; 190, 191; 190, 192; 190, 193; 191, identifier:i; 192, identifier:batch; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, subscript; 196, 197; 196, 198; 197, identifier:dois; 198, identifier:i; 199, None; 200, return_statement; 200, 201; 201, identifier:dois
def get_cited_dois(file): if not isinstance(file, list): plaintext_citations = get_plaintext_citations(file) else: plaintext_citations = file dois = {} crossref_queue = [] for citation in plaintext_citations[:]: matched_dois = doi.extract_from_text(citation) if len(matched_dois) > 0: dois[citation] = next(iter(matched_dois)) continue matched_arxiv = arxiv.extract_from_text(citation) if len(matched_arxiv) > 0: dois[citation] = arxiv.to_doi(next(iter(matched_arxiv))) continue crossref_queue.append(tools.remove_urls(citation)) for batch in tools.batch(crossref_queue, CROSSREF_MAX_BATCH_SIZE): batch = [i for i in batch] try: request = requests.post(CROSSREF_LINKS_API_URL, json=batch) for result in request.json()["results"]: try: dois[result["text"]] = result["doi"] except KeyError: dois[result["text"]] = None except (RequestException, ValueError, KeyError): for i in batch: dois[i] = None return dois
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:used_args; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 87; 5, 96; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:values; 9, list:[]; 10, for_statement; 10, 11; 10, 14; 10, 24; 11, pattern_list; 11, 12; 11, 13; 12, identifier:idx; 13, identifier:c; 14, call; 14, 15; 14, 16; 15, identifier:enumerate; 16, argument_list; 16, 17; 17, subscript; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:words; 21, slice; 21, 22; 21, 23; 22, integer:1; 23, colon; 24, block; 24, 25; 24, 34; 24, 48; 24, 57; 25, if_statement; 25, 26; 25, 32; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:c; 29, identifier:startswith; 30, argument_list; 30, 31; 31, string:'-'; 32, block; 32, 33; 33, continue_statement; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:option_str; 37, subscript; 37, 38; 37, 45; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:words; 42, slice; 42, 43; 42, 44; 43, integer:1; 44, colon; 45, binary_operator:-; 45, 46; 45, 47; 46, identifier:idx; 47, integer:1; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:option; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:get_option; 55, argument_list; 55, 56; 56, identifier:option_str; 57, if_statement; 57, 58; 57, 66; 58, boolean_operator:or; 58, 59; 58, 62; 59, comparison_operator:is; 59, 60; 59, 61; 60, identifier:option; 61, None; 62, not_operator; 62, 63; 63, attribute; 63, 64; 63, 65; 64, identifier:option; 65, identifier:need_value; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:values; 71, identifier:append; 72, argument_list; 72, 73; 73, tuple; 73, 74; 73, 75; 74, identifier:c; 75, comparison_operator:==; 75, 76; 75, 77; 76, identifier:c; 77, call; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:document; 82, identifier:get_word_before_cursor; 83, argument_list; 83, 84; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:WORD; 86, True; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:logger; 91, identifier:debug; 92, argument_list; 92, 93; 93, binary_operator:%; 93, 94; 93, 95; 94, string:"Found args values %s"; 95, identifier:values; 96, for_statement; 96, 97; 96, 98; 96, 107; 97, identifier:arg; 98, call; 98, 99; 98, 106; 99, attribute; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:cmd; 104, identifier:args; 105, identifier:values; 106, argument_list; 107, block; 107, 108; 107, 114; 108, if_statement; 108, 109; 108, 111; 109, not_operator; 109, 110; 110, identifier:values; 111, block; 111, 112; 112, raise_statement; 112, 113; 113, identifier:StopIteration; 114, if_statement; 114, 115; 114, 118; 114, 126; 115, attribute; 115, 116; 115, 117; 116, identifier:arg; 117, identifier:is_multiple; 118, block; 118, 119; 118, 123; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:values; 122, list:[]; 123, expression_statement; 123, 124; 124, yield; 124, 125; 125, identifier:arg; 126, elif_clause; 126, 127; 126, 135; 127, comparison_operator:is; 127, 128; 127, 134; 128, call; 128, 129; 128, 130; 129, identifier:type; 130, argument_list; 130, 131; 131, attribute; 131, 132; 131, 133; 132, identifier:arg; 133, identifier:nargs; 134, identifier:int; 135, block; 135, 136; 136, for_statement; 136, 137; 136, 138; 136, 144; 137, identifier:_; 138, call; 138, 139; 138, 140; 139, identifier:range; 140, argument_list; 140, 141; 141, attribute; 141, 142; 141, 143; 142, identifier:arg; 143, identifier:nargs; 144, block; 144, 145; 144, 154; 144, 164; 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:values; 151, identifier:pop; 152, argument_list; 152, 153; 153, integer:0; 154, if_statement; 154, 155; 154, 160; 155, comparison_operator:is; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:value; 158, integer:1; 159, False; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, yield; 162, 163; 163, identifier:arg; 164, if_statement; 164, 165; 164, 167; 165, not_operator; 165, 166; 166, identifier:values; 167, block; 167, 168; 168, raise_statement; 168, 169; 169, identifier:StopIteration
def used_args(self): values = [] for idx, c in enumerate(self.words[1:]): if c.startswith('-'): continue option_str = self.words[1:][idx - 1] option = self.get_option(option_str) if option is None or not option.need_value: values.append((c, c == self.document.get_word_before_cursor(WORD=True))) logger.debug("Found args values %s" % values) for arg in self.cmd.args.values(): if not values: raise StopIteration if arg.is_multiple: values = [] yield arg elif type(arg.nargs) is int: for _ in range(arg.nargs): value = values.pop(0) if value[1] is False: yield arg if not values: raise StopIteration
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_preprocess; 3, parameters; 3, 4; 4, identifier:inp; 5, block; 5, 6; 5, 17; 5, 28; 5, 39; 5, 50; 5, 61; 5, 72; 5, 83; 5, 94; 5, 105; 5, 116; 5, 127; 5, 138; 5, 149; 5, 333; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:inp; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:re; 12, identifier:sub; 13, argument_list; 13, 14; 13, 15; 13, 16; 14, string:r'(\b)a(\b)'; 15, string:r'\g<1>one\g<2>'; 16, identifier:inp; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:inp; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:re; 23, identifier:sub; 24, argument_list; 24, 25; 24, 26; 24, 27; 25, string:r'to the (.*) power'; 26, string:r'to \g<1>'; 27, identifier:inp; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:inp; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:re; 34, identifier:sub; 35, argument_list; 35, 36; 35, 37; 35, 38; 36, string:r'to the (.*?)(\b)'; 37, string:r'to \g<1>\g<2>'; 38, identifier:inp; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:inp; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:re; 45, identifier:sub; 46, argument_list; 46, 47; 46, 48; 46, 49; 47, string:r'log of'; 48, string:r'log'; 49, identifier:inp; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:inp; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:re; 56, identifier:sub; 57, argument_list; 57, 58; 57, 59; 57, 60; 58, string:r'(square )?root( of)?'; 59, string:r'sqrt'; 60, identifier:inp; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:inp; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:re; 67, identifier:sub; 68, argument_list; 68, 69; 68, 70; 68, 71; 69, string:r'squared'; 70, string:r'to two'; 71, identifier:inp; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:inp; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:re; 78, identifier:sub; 79, argument_list; 79, 80; 79, 81; 79, 82; 80, string:r'cubed'; 81, string:r'to three'; 82, identifier:inp; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:inp; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:re; 89, identifier:sub; 90, argument_list; 90, 91; 90, 92; 90, 93; 91, string:r'divided?( by)?'; 92, string:r'divide'; 93, identifier:inp; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:inp; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:re; 100, identifier:sub; 101, argument_list; 101, 102; 101, 103; 101, 104; 102, string:r'(\b)over(\b)'; 103, string:r'\g<1>divide\g<2>'; 104, identifier:inp; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:inp; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:re; 111, identifier:sub; 112, argument_list; 112, 113; 112, 114; 112, 115; 113, string:r'(\b)EE(\b)'; 114, string:r'\g<1>e\g<2>'; 115, identifier:inp; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:inp; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:re; 122, identifier:sub; 123, argument_list; 123, 124; 123, 125; 123, 126; 124, string:r'(\b)E(\b)'; 125, string:r'\g<1>e\g<2>'; 126, identifier:inp; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:inp; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:re; 133, identifier:sub; 134, argument_list; 134, 135; 134, 136; 134, 137; 135, string:r'(\b)pie(\b)'; 136, string:r'\g<1>pi\g<2>'; 137, identifier:inp; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:inp; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:re; 144, identifier:sub; 145, argument_list; 145, 146; 145, 147; 145, 148; 146, string:r'(\b)PI(\b)'; 147, string:r'\g<1>pi\g<2>'; 148, identifier:inp; 149, function_definition; 149, 150; 149, 151; 149, 153; 150, function_name:findImplicitMultiplications; 151, parameters; 151, 152; 152, identifier:inp; 153, block; 153, 154; 153, 232; 153, 325; 154, function_definition; 154, 155; 154, 156; 154, 158; 155, function_name:findConstantMultiplications; 156, parameters; 156, 157; 157, identifier:inp; 158, block; 158, 159; 158, 168; 158, 172; 158, 178; 158, 230; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:split; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:inp; 165, identifier:split; 166, argument_list; 166, 167; 167, string:' '; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:revision; 171, string:""; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:converter; 175, call; 175, 176; 175, 177; 176, identifier:NumberService; 177, argument_list; 178, for_statement; 178, 179; 178, 182; 178, 186; 179, pattern_list; 179, 180; 179, 181; 180, identifier:i; 181, identifier:w; 182, call; 182, 183; 182, 184; 183, identifier:enumerate; 184, argument_list; 184, 185; 185, identifier:split; 186, block; 186, 187; 186, 214; 187, if_statement; 187, 188; 187, 197; 188, boolean_operator:and; 188, 189; 188, 192; 189, comparison_operator:>; 189, 190; 189, 191; 190, identifier:i; 191, integer:0; 192, comparison_operator:in; 192, 193; 192, 194; 193, identifier:w; 194, attribute; 194, 195; 194, 196; 195, identifier:MathService; 196, identifier:__constants__; 197, block; 197, 198; 198, if_statement; 198, 199; 198, 209; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:converter; 202, identifier:isValid; 203, argument_list; 203, 204; 204, subscript; 204, 205; 204, 206; 205, identifier:split; 206, binary_operator:-; 206, 207; 206, 208; 207, identifier:i; 208, integer:1; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, augmented_assignment:+=; 211, 212; 211, 213; 212, identifier:revision; 213, string:" times"; 214, if_statement; 214, 215; 214, 217; 214, 222; 215, not_operator; 215, 216; 216, identifier:revision; 217, block; 217, 218; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:revision; 221, identifier:w; 222, else_clause; 222, 223; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, augmented_assignment:+=; 225, 226; 225, 227; 226, identifier:revision; 227, binary_operator:+; 227, 228; 227, 229; 228, string:" "; 229, identifier:w; 230, return_statement; 230, 231; 231, identifier:revision; 232, function_definition; 232, 233; 232, 234; 232, 236; 233, function_name:findUnaryMultiplications; 234, parameters; 234, 235; 235, identifier:inp; 236, block; 236, 237; 236, 246; 236, 250; 236, 323; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:split; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:inp; 243, identifier:split; 244, argument_list; 244, 245; 245, string:' '; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:revision; 249, string:""; 250, for_statement; 250, 251; 250, 254; 250, 258; 251, pattern_list; 251, 252; 251, 253; 252, identifier:i; 253, identifier:w; 254, call; 254, 255; 254, 256; 255, identifier:enumerate; 256, argument_list; 256, 257; 257, identifier:split; 258, block; 258, 259; 258, 307; 259, if_statement; 259, 260; 259, 269; 260, boolean_operator:and; 260, 261; 260, 264; 261, comparison_operator:>; 261, 262; 261, 263; 262, identifier:i; 263, integer:0; 264, comparison_operator:in; 264, 265; 264, 266; 265, identifier:w; 266, attribute; 266, 267; 266, 268; 267, identifier:MathService; 268, identifier:__unaryOperators__; 269, block; 269, 270; 269, 278; 269, 286; 269, 294; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:last_op; 273, subscript; 273, 274; 273, 275; 274, identifier:split; 275, binary_operator:-; 275, 276; 275, 277; 276, identifier:i; 277, integer:1; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:binary; 281, comparison_operator:in; 281, 282; 281, 283; 282, identifier:last_op; 283, attribute; 283, 284; 283, 285; 284, identifier:MathService; 285, identifier:__binaryOperators__; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:unary; 289, comparison_operator:in; 289, 290; 289, 291; 290, identifier:last_op; 291, attribute; 291, 292; 291, 293; 292, identifier:MathService; 293, identifier:__unaryOperators__; 294, if_statement; 294, 295; 294, 302; 295, boolean_operator:and; 295, 296; 295, 297; 296, identifier:last_op; 297, not_operator; 297, 298; 298, parenthesized_expression; 298, 299; 299, boolean_operator:or; 299, 300; 299, 301; 300, identifier:binary; 301, identifier:unary; 302, block; 302, 303; 303, expression_statement; 303, 304; 304, augmented_assignment:+=; 304, 305; 304, 306; 305, identifier:revision; 306, string:" times"; 307, if_statement; 307, 308; 307, 310; 307, 315; 308, not_operator; 308, 309; 309, identifier:revision; 310, block; 310, 311; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:revision; 314, identifier:w; 315, else_clause; 315, 316; 316, block; 316, 317; 317, expression_statement; 317, 318; 318, augmented_assignment:+=; 318, 319; 318, 320; 319, identifier:revision; 320, binary_operator:+; 320, 321; 320, 322; 321, string:" "; 322, identifier:w; 323, return_statement; 323, 324; 324, identifier:revision; 325, return_statement; 325, 326; 326, call; 326, 327; 326, 328; 327, identifier:findUnaryMultiplications; 328, argument_list; 328, 329; 329, call; 329, 330; 329, 331; 330, identifier:findConstantMultiplications; 331, argument_list; 331, 332; 332, identifier:inp; 333, return_statement; 333, 334; 334, call; 334, 335; 334, 336; 335, identifier:findImplicitMultiplications; 336, argument_list; 336, 337; 337, identifier:inp
def _preprocess(inp): inp = re.sub(r'(\b)a(\b)', r'\g<1>one\g<2>', inp) inp = re.sub(r'to the (.*) power', r'to \g<1>', inp) inp = re.sub(r'to the (.*?)(\b)', r'to \g<1>\g<2>', inp) inp = re.sub(r'log of', r'log', inp) inp = re.sub(r'(square )?root( of)?', r'sqrt', inp) inp = re.sub(r'squared', r'to two', inp) inp = re.sub(r'cubed', r'to three', inp) inp = re.sub(r'divided?( by)?', r'divide', inp) inp = re.sub(r'(\b)over(\b)', r'\g<1>divide\g<2>', inp) inp = re.sub(r'(\b)EE(\b)', r'\g<1>e\g<2>', inp) inp = re.sub(r'(\b)E(\b)', r'\g<1>e\g<2>', inp) inp = re.sub(r'(\b)pie(\b)', r'\g<1>pi\g<2>', inp) inp = re.sub(r'(\b)PI(\b)', r'\g<1>pi\g<2>', inp) def findImplicitMultiplications(inp): def findConstantMultiplications(inp): split = inp.split(' ') revision = "" converter = NumberService() for i, w in enumerate(split): if i > 0 and w in MathService.__constants__: if converter.isValid(split[i - 1]): revision += " times" if not revision: revision = w else: revision += " " + w return revision def findUnaryMultiplications(inp): split = inp.split(' ') revision = "" for i, w in enumerate(split): if i > 0 and w in MathService.__unaryOperators__: last_op = split[i - 1] binary = last_op in MathService.__binaryOperators__ unary = last_op in MathService.__unaryOperators__ if last_op and not (binary or unary): revision += " times" if not revision: revision = w else: revision += " " + w return revision return findUnaryMultiplications(findConstantMultiplications(inp)) return findImplicitMultiplications(inp)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parseEquation; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:inp; 6, block; 6, 7; 6, 16; 6, 25; 6, 106; 6, 233; 6, 242; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:inp; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:MathService; 13, identifier:_preprocess; 14, argument_list; 14, 15; 15, identifier:inp; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:split; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:inp; 22, identifier:split; 23, argument_list; 23, 24; 24, string:' '; 25, for_statement; 25, 26; 25, 29; 25, 33; 26, pattern_list; 26, 27; 26, 28; 27, identifier:i; 28, identifier:w; 29, call; 29, 30; 29, 31; 30, identifier:enumerate; 31, argument_list; 31, 32; 32, identifier:split; 33, block; 33, 34; 34, if_statement; 34, 35; 34, 40; 35, comparison_operator:in; 35, 36; 35, 37; 36, identifier:w; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:__unaryOperators__; 40, block; 40, 41; 40, 49; 40, 62; 40, 77; 40, 92; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:op; 44, subscript; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:__unaryOperators__; 48, identifier:w; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:eq1; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, string:' '; 55, identifier:join; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:split; 59, slice; 59, 60; 59, 61; 60, colon; 61, identifier:i; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:eq2; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, string:' '; 68, identifier:join; 69, argument_list; 69, 70; 70, subscript; 70, 71; 70, 72; 71, identifier:split; 72, slice; 72, 73; 72, 76; 73, binary_operator:+; 73, 74; 73, 75; 74, identifier:i; 75, integer:1; 76, colon; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:result; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:MathService; 83, identifier:_applyUnary; 84, argument_list; 84, 85; 84, 91; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:parseEquation; 89, argument_list; 89, 90; 90, identifier:eq2; 91, identifier:op; 92, return_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:parseEquation; 97, argument_list; 97, 98; 98, binary_operator:+; 98, 99; 98, 102; 99, binary_operator:+; 99, 100; 99, 101; 100, identifier:eq1; 101, string:" "; 102, call; 102, 103; 102, 104; 103, identifier:str; 104, argument_list; 104, 105; 105, identifier:result; 106, function_definition; 106, 107; 106, 108; 106, 110; 107, function_name:extractNumbersAndSymbols; 108, parameters; 108, 109; 109, identifier:inp; 110, block; 110, 111; 110, 115; 110, 119; 110, 123; 110, 177; 110, 187; 110, 218; 110, 229; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:numbers; 114, list:[]; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:symbols; 118, list:[]; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:next_number; 122, string:""; 123, for_statement; 123, 124; 123, 125; 123, 131; 124, identifier:w; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:inp; 128, identifier:split; 129, argument_list; 129, 130; 130, string:' '; 131, block; 131, 132; 132, if_statement; 132, 133; 132, 138; 132, 164; 133, comparison_operator:in; 133, 134; 133, 135; 134, identifier:w; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:__binaryOperators__; 138, block; 138, 139; 138, 150; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:symbols; 143, identifier:append; 144, argument_list; 144, 145; 145, subscript; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:__binaryOperators__; 149, identifier:w; 150, if_statement; 150, 151; 150, 152; 151, identifier:next_number; 152, block; 152, 153; 152, 160; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:numbers; 157, identifier:append; 158, argument_list; 158, 159; 159, identifier:next_number; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:next_number; 163, string:""; 164, else_clause; 164, 165; 165, block; 165, 166; 165, 173; 166, if_statement; 166, 167; 166, 168; 167, identifier:next_number; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, augmented_assignment:+=; 170, 171; 170, 172; 171, identifier:next_number; 172, string:" "; 173, expression_statement; 173, 174; 174, augmented_assignment:+=; 174, 175; 174, 176; 175, identifier:next_number; 176, identifier:w; 177, if_statement; 177, 178; 177, 179; 178, identifier:next_number; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:numbers; 184, identifier:append; 185, argument_list; 185, 186; 186, identifier:next_number; 187, function_definition; 187, 188; 187, 189; 187, 191; 188, function_name:convert; 189, parameters; 189, 190; 190, identifier:n; 191, block; 191, 192; 191, 205; 191, 211; 192, if_statement; 192, 193; 192, 198; 193, comparison_operator:in; 193, 194; 193, 195; 194, identifier:n; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:__constants__; 198, block; 198, 199; 199, return_statement; 199, 200; 200, subscript; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:__constants__; 204, identifier:n; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:converter; 208, call; 208, 209; 208, 210; 209, identifier:NumberService; 210, argument_list; 211, return_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:converter; 215, identifier:parse; 216, argument_list; 216, 217; 217, identifier:n; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:numbers; 221, list_comprehension; 221, 222; 221, 226; 222, call; 222, 223; 222, 224; 223, identifier:convert; 224, argument_list; 224, 225; 225, identifier:n; 226, for_in_clause; 226, 227; 226, 228; 227, identifier:n; 228, identifier:numbers; 229, return_statement; 229, 230; 230, expression_list; 230, 231; 230, 232; 231, identifier:numbers; 232, identifier:symbols; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 238; 235, pattern_list; 235, 236; 235, 237; 236, identifier:numbers; 237, identifier:symbols; 238, call; 238, 239; 238, 240; 239, identifier:extractNumbersAndSymbols; 240, argument_list; 240, 241; 241, identifier:inp; 242, return_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:MathService; 246, identifier:_calculate; 247, argument_list; 247, 248; 247, 249; 248, identifier:numbers; 249, identifier:symbols
def parseEquation(self, inp): inp = MathService._preprocess(inp) split = inp.split(' ') for i, w in enumerate(split): if w in self.__unaryOperators__: op = self.__unaryOperators__[w] eq1 = ' '.join(split[:i]) eq2 = ' '.join(split[i + 1:]) result = MathService._applyUnary(self.parseEquation(eq2), op) return self.parseEquation(eq1 + " " + str(result)) def extractNumbersAndSymbols(inp): numbers = [] symbols = [] next_number = "" for w in inp.split(' '): if w in self.__binaryOperators__: symbols.append(self.__binaryOperators__[w]) if next_number: numbers.append(next_number) next_number = "" else: if next_number: next_number += " " next_number += w if next_number: numbers.append(next_number) def convert(n): if n in self.__constants__: return self.__constants__[n] converter = NumberService() return converter.parse(n) numbers = [convert(n) for n in numbers] return numbers, symbols numbers, symbols = extractNumbersAndSymbols(inp) return MathService._calculate(numbers, symbols)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:activate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:plugins; 7, list:[]; 8, block; 8, 9; 8, 18; 8, 36; 8, 52; 8, 56; 8, 286; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_log; 15, identifier:debug; 16, argument_list; 16, 17; 17, string:"Plugins Activation started"; 18, if_statement; 18, 19; 18, 25; 19, not_operator; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:isinstance; 22, argument_list; 22, 23; 22, 24; 23, identifier:plugins; 24, identifier:list; 25, block; 25, 26; 26, raise_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:AttributeError; 29, argument_list; 29, 30; 30, binary_operator:%; 30, 31; 30, 32; 31, string:"plugins must be a list, not %s"; 32, call; 32, 33; 32, 34; 33, identifier:type; 34, argument_list; 34, 35; 35, identifier:plugins; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_log; 42, identifier:debug; 43, argument_list; 43, 44; 44, binary_operator:%; 44, 45; 44, 46; 45, string:"Plugins to activate: %s"; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, string:", "; 49, identifier:join; 50, argument_list; 50, 51; 51, identifier:plugins; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:plugins_activated; 55, list:[]; 56, for_statement; 56, 57; 56, 58; 56, 59; 57, identifier:plugin_name; 58, identifier:plugins; 59, block; 59, 60; 59, 78; 59, 179; 60, if_statement; 60, 61; 60, 67; 61, not_operator; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:isinstance; 64, argument_list; 64, 65; 64, 66; 65, identifier:plugin_name; 66, identifier:str; 67, block; 67, 68; 68, raise_statement; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:AttributeError; 71, argument_list; 71, 72; 72, binary_operator:%; 72, 73; 72, 74; 73, string:"plugin name must be a str, not %s"; 74, call; 74, 75; 74, 76; 75, identifier:type; 76, argument_list; 76, 77; 77, identifier:plugin_name; 78, if_statement; 78, 79; 78, 100; 79, boolean_operator:and; 79, 80; 79, 89; 80, comparison_operator:not; 80, 81; 80, 82; 81, identifier:plugin_name; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:_plugins; 87, identifier:keys; 88, argument_list; 89, comparison_operator:in; 89, 90; 89, 91; 90, identifier:plugin_name; 91, call; 91, 92; 91, 99; 92, attribute; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:classes; 97, identifier:_classes; 98, identifier:keys; 99, argument_list; 100, block; 100, 101; 100, 110; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:_log; 107, identifier:debug; 108, argument_list; 108, 109; 109, string:"Initialisation needed before activation."; 110, try_statement; 110, 111; 110, 120; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:initialise_by_names; 117, argument_list; 117, 118; 118, list:[plugin_name]; 118, 119; 119, identifier:plugin_name; 120, except_clause; 120, 121; 120, 125; 121, as_pattern; 121, 122; 121, 123; 122, identifier:Exception; 123, as_pattern_target; 123, 124; 124, identifier:e; 125, block; 125, 126; 125, 139; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 133; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:_log; 132, identifier:error; 133, argument_list; 133, 134; 134, binary_operator:%; 134, 135; 134, 136; 135, string:"Couldn't initialise plugin %s. Reason %s"; 136, tuple; 136, 137; 136, 138; 137, identifier:plugin_name; 138, identifier:e; 139, if_statement; 139, 140; 139, 145; 139, 176; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:_app; 144, identifier:strict; 145, block; 145, 146; 145, 152; 145, 167; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:error; 149, binary_operator:%; 149, 150; 149, 151; 150, string:"Couldn't initialise plugin %s"; 151, identifier:plugin_name; 152, if_statement; 152, 153; 152, 160; 153, comparison_operator:<; 153, 154; 153, 159; 154, subscript; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:sys; 157, identifier:version_info; 158, integer:0; 159, integer:3; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, augmented_assignment:+=; 162, 163; 162, 164; 163, identifier:error; 164, binary_operator:%; 164, 165; 164, 166; 165, string:"Reason: %s"; 166, identifier:e; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 170; 169, identifier:raise_from; 170, argument_list; 170, 171; 170, 175; 171, call; 171, 172; 171, 173; 172, identifier:Exception; 173, argument_list; 173, 174; 174, identifier:error; 175, identifier:e; 176, else_clause; 176, 177; 177, block; 177, 178; 178, continue_statement; 179, if_statement; 179, 180; 179, 189; 180, comparison_operator:in; 180, 181; 180, 182; 181, identifier:plugin_name; 182, call; 182, 183; 182, 188; 183, attribute; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:_plugins; 187, identifier:keys; 188, argument_list; 189, block; 189, 190; 189, 201; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 197; 192, attribute; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:_log; 196, identifier:debug; 197, argument_list; 197, 198; 198, binary_operator:%; 198, 199; 198, 200; 199, string:"Activating plugin %s"; 200, identifier:plugin_name; 201, if_statement; 201, 202; 201, 210; 201, 262; 202, not_operator; 202, 203; 203, attribute; 203, 204; 203, 209; 204, subscript; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:_plugins; 208, identifier:plugin_name; 209, identifier:active; 210, block; 210, 211; 211, try_statement; 211, 212; 211, 223; 211, 242; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 222; 215, attribute; 215, 216; 215, 221; 216, subscript; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:self; 219, identifier:_plugins; 220, identifier:plugin_name; 221, identifier:activate; 222, argument_list; 223, except_clause; 223, 224; 223, 228; 224, as_pattern; 224, 225; 224, 226; 225, identifier:Exception; 226, as_pattern_target; 226, 227; 227, identifier:e; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 232; 231, identifier:raise_from; 232, argument_list; 232, 233; 232, 241; 233, call; 233, 234; 233, 235; 234, identifier:PluginNotActivatableException; 235, argument_list; 235, 236; 236, binary_operator:%; 236, 237; 236, 238; 237, string:"Plugin %s could not be activated: %s"; 238, tuple; 238, 239; 238, 240; 239, identifier:plugin_name; 240, identifier:e; 241, identifier:e; 242, else_clause; 242, 243; 243, block; 243, 244; 243, 255; 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:_log; 250, identifier:debug; 251, argument_list; 251, 252; 252, binary_operator:%; 252, 253; 252, 254; 253, string:"Plugin %s activated"; 254, identifier:plugin_name; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:plugins_activated; 259, identifier:append; 260, argument_list; 260, 261; 261, identifier:plugin_name; 262, else_clause; 262, 263; 263, block; 263, 264; 263, 275; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 271; 266, attribute; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:_log; 270, identifier:warning; 271, argument_list; 271, 272; 272, binary_operator:%; 272, 273; 272, 274; 273, string:"Plugin %s got already activated."; 274, identifier:plugin_name; 275, if_statement; 275, 276; 275, 281; 276, attribute; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:self; 279, identifier:_app; 280, identifier:strict; 281, block; 281, 282; 282, raise_statement; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:PluginNotInitialisableException; 285, argument_list; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 293; 288, attribute; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:_log; 292, identifier:info; 293, argument_list; 293, 294; 294, binary_operator:%; 294, 295; 294, 296; 295, string:"Plugins activated: %s"; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, string:", "; 299, identifier:join; 300, argument_list; 300, 301; 301, identifier:plugins_activated
def activate(self, plugins=[]): self._log.debug("Plugins Activation started") if not isinstance(plugins, list): raise AttributeError("plugins must be a list, not %s" % type(plugins)) self._log.debug("Plugins to activate: %s" % ", ".join(plugins)) plugins_activated = [] for plugin_name in plugins: if not isinstance(plugin_name, str): raise AttributeError("plugin name must be a str, not %s" % type(plugin_name)) if plugin_name not in self._plugins.keys() and plugin_name in self.classes._classes.keys(): self._log.debug("Initialisation needed before activation.") try: self.initialise_by_names([plugin_name]) except Exception as e: self._log.error("Couldn't initialise plugin %s. Reason %s" % (plugin_name, e)) if self._app.strict: error = "Couldn't initialise plugin %s" % plugin_name if sys.version_info[0] < 3: error += "Reason: %s" % e raise_from(Exception(error), e) else: continue if plugin_name in self._plugins.keys(): self._log.debug("Activating plugin %s" % plugin_name) if not self._plugins[plugin_name].active: try: self._plugins[plugin_name].activate() except Exception as e: raise_from( PluginNotActivatableException("Plugin %s could not be activated: %s" % (plugin_name, e)), e) else: self._log.debug("Plugin %s activated" % plugin_name) plugins_activated.append(plugin_name) else: self._log.warning("Plugin %s got already activated." % plugin_name) if self._app.strict: raise PluginNotInitialisableException() self._log.info("Plugins activated: %s" % ", ".join(plugins_activated))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:dispersion_ranking_NN; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:nnm; 6, default_parameter; 6, 7; 6, 8; 7, identifier:num_norm_avg; 8, integer:50; 9, block; 9, 10; 9, 17; 9, 27; 9, 41; 9, 52; 9, 70; 9, 84; 9, 102; 9, 110; 9, 128; 9, 138; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:knn_avg; 15, argument_list; 15, 16; 16, identifier:nnm; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:D_avg; 20, subscript; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:adata; 25, identifier:layers; 26, string:'X_knn_avg'; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 32; 29, pattern_list; 29, 30; 29, 31; 30, identifier:mu; 31, identifier:var; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:sf; 35, identifier:mean_variance_axis; 36, argument_list; 36, 37; 36, 38; 37, identifier:D_avg; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:axis; 40, integer:0; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:dispersions; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:np; 47, identifier:zeros; 48, argument_list; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:var; 51, identifier:size; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 59; 54, subscript; 54, 55; 54, 56; 55, identifier:dispersions; 56, comparison_operator:>; 56, 57; 56, 58; 57, identifier:mu; 58, integer:0; 59, binary_operator:/; 59, 60; 59, 65; 60, subscript; 60, 61; 60, 62; 61, identifier:var; 62, comparison_operator:>; 62, 63; 62, 64; 63, identifier:mu; 64, integer:0; 65, subscript; 65, 66; 65, 67; 66, identifier:mu; 67, comparison_operator:>; 67, 68; 67, 69; 68, identifier:mu; 69, integer:0; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 79; 72, subscript; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:adata; 77, identifier:var; 78, string:'spatial_dispersions'; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:dispersions; 82, identifier:copy; 83, argument_list; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:ma; 87, call; 87, 88; 87, 101; 88, attribute; 88, 89; 88, 100; 89, subscript; 89, 90; 89, 96; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:sort; 94, argument_list; 94, 95; 95, identifier:dispersions; 96, slice; 96, 97; 96, 99; 97, unary_operator:-; 97, 98; 98, identifier:num_norm_avg; 99, colon; 100, identifier:mean; 101, argument_list; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 109; 104, subscript; 104, 105; 104, 106; 105, identifier:dispersions; 106, comparison_operator:>=; 106, 107; 106, 108; 107, identifier:dispersions; 108, identifier:ma; 109, identifier:ma; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:weights; 113, call; 113, 114; 113, 127; 114, attribute; 114, 115; 114, 126; 115, parenthesized_expression; 115, 116; 116, binary_operator:**; 116, 117; 116, 125; 117, parenthesized_expression; 117, 118; 118, binary_operator:/; 118, 119; 118, 120; 119, identifier:dispersions; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:dispersions; 123, identifier:max; 124, argument_list; 125, float:0.5; 126, identifier:flatten; 127, argument_list; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 137; 130, subscript; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:adata; 135, identifier:var; 136, string:'weights'; 137, identifier:weights; 138, return_statement; 138, 139; 139, identifier:weights
def dispersion_ranking_NN(self, nnm, num_norm_avg=50): self.knn_avg(nnm) D_avg = self.adata.layers['X_knn_avg'] mu, var = sf.mean_variance_axis(D_avg, axis=0) dispersions = np.zeros(var.size) dispersions[mu > 0] = var[mu > 0] / mu[mu > 0] self.adata.var['spatial_dispersions'] = dispersions.copy() ma = np.sort(dispersions)[-num_norm_avg:].mean() dispersions[dispersions >= ma] = ma weights = ((dispersions / dispersions.max())**0.5).flatten() self.adata.var['weights'] = weights return weights
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 31; 2, function_name:scatter; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:projection; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:c; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:cmap; 13, string:'rainbow'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:linewidth; 16, float:0.0; 17, default_parameter; 17, 18; 17, 19; 18, identifier:edgecolor; 19, string:'k'; 20, default_parameter; 20, 21; 20, 22; 21, identifier:axes; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:colorbar; 25, True; 26, default_parameter; 26, 27; 26, 28; 27, identifier:s; 28, integer:10; 29, dictionary_splat_pattern; 29, 30; 30, identifier:kwargs; 31, block; 31, 32; 32, if_statement; 32, 33; 32, 36; 32, 42; 33, parenthesized_expression; 33, 34; 34, not_operator; 34, 35; 35, identifier:PLOTTING; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:print; 40, argument_list; 40, 41; 41, string:"matplotlib not installed!"; 42, else_clause; 42, 43; 43, block; 43, 44; 43, 124; 43, 144; 44, if_statement; 44, 45; 44, 51; 44, 74; 44, 118; 45, parenthesized_expression; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:isinstance; 48, argument_list; 48, 49; 48, 50; 49, identifier:projection; 50, identifier:str; 51, block; 51, 52; 52, try_statement; 52, 53; 52, 64; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:dt; 57, subscript; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:adata; 62, identifier:obsm; 63, identifier:projection; 64, except_clause; 64, 65; 64, 66; 65, identifier:KeyError; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:print; 70, argument_list; 70, 71; 71, concatenated_string; 71, 72; 71, 73; 72, string:'Please create a projection first using run_umap or'; 73, string:'run_tsne'; 74, elif_clause; 74, 75; 74, 79; 75, parenthesized_expression; 75, 76; 76, comparison_operator:is; 76, 77; 76, 78; 77, identifier:projection; 78, None; 79, block; 79, 80; 80, try_statement; 80, 81; 80, 92; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:dt; 85, subscript; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:adata; 90, identifier:obsm; 91, string:'X_umap'; 92, except_clause; 92, 93; 92, 94; 93, identifier:KeyError; 94, block; 94, 95; 95, try_statement; 95, 96; 95, 107; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:dt; 100, subscript; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:adata; 105, identifier:obsm; 106, string:'X_tsne'; 107, except_clause; 107, 108; 107, 109; 108, identifier:KeyError; 109, block; 109, 110; 109, 117; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:print; 113, argument_list; 113, 114; 114, concatenated_string; 114, 115; 114, 116; 115, string:"Please create either a t-SNE or UMAP projection"; 116, string:"first."; 117, return_statement; 118, else_clause; 118, 119; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:dt; 123, identifier:projection; 124, if_statement; 124, 125; 124, 129; 125, parenthesized_expression; 125, 126; 126, comparison_operator:is; 126, 127; 126, 128; 127, identifier:axes; 128, None; 129, block; 129, 130; 129, 136; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:plt; 134, identifier:figure; 135, argument_list; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:axes; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:plt; 142, identifier:gca; 143, argument_list; 144, if_statement; 144, 145; 144, 149; 144, 177; 145, parenthesized_expression; 145, 146; 146, comparison_operator:is; 146, 147; 146, 148; 147, identifier:c; 148, None; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:plt; 154, identifier:scatter; 155, argument_list; 155, 156; 155, 161; 155, 166; 155, 169; 155, 172; 155, 175; 156, subscript; 156, 157; 156, 158; 156, 160; 157, identifier:dt; 158, slice; 158, 159; 159, colon; 160, integer:0; 161, subscript; 161, 162; 161, 163; 161, 165; 162, identifier:dt; 163, slice; 163, 164; 164, colon; 165, integer:1; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:s; 168, identifier:s; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:linewidth; 171, identifier:linewidth; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:edgecolor; 174, identifier:edgecolor; 175, dictionary_splat; 175, 176; 176, identifier:kwargs; 177, else_clause; 177, 178; 178, block; 178, 179; 178, 207; 179, if_statement; 179, 180; 179, 185; 180, call; 180, 181; 180, 182; 181, identifier:isinstance; 182, argument_list; 182, 183; 182, 184; 183, identifier:c; 184, identifier:str; 185, block; 185, 186; 186, try_statement; 186, 187; 186, 202; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:c; 191, call; 191, 192; 191, 201; 192, attribute; 192, 193; 192, 200; 193, subscript; 193, 194; 193, 199; 194, attribute; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:adata; 198, identifier:obs; 199, identifier:c; 200, identifier:get_values; 201, argument_list; 202, except_clause; 202, 203; 202, 204; 203, identifier:KeyError; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, integer:0; 207, if_statement; 207, 208; 207, 242; 207, 331; 208, parenthesized_expression; 208, 209; 209, boolean_operator:and; 209, 210; 209, 228; 210, parenthesized_expression; 210, 211; 211, boolean_operator:or; 211, 212; 211, 219; 212, call; 212, 213; 212, 214; 213, identifier:isinstance; 214, argument_list; 214, 215; 214, 218; 215, subscript; 215, 216; 215, 217; 216, identifier:c; 217, integer:0; 218, identifier:str; 219, call; 219, 220; 219, 221; 220, identifier:isinstance; 221, argument_list; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:c; 224, integer:0; 225, attribute; 225, 226; 225, 227; 226, identifier:np; 227, identifier:str_; 228, parenthesized_expression; 228, 229; 229, boolean_operator:or; 229, 230; 229, 237; 230, call; 230, 231; 230, 232; 231, identifier:isinstance; 232, argument_list; 232, 233; 232, 234; 233, identifier:c; 234, attribute; 234, 235; 234, 236; 235, identifier:np; 236, identifier:ndarray; 237, call; 237, 238; 237, 239; 238, identifier:isinstance; 239, argument_list; 239, 240; 239, 241; 240, identifier:c; 241, identifier:list; 242, block; 242, 243; 242, 252; 242, 266; 242, 301; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:i; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:ut; 249, identifier:convert_annotations; 250, argument_list; 250, 251; 251, identifier:c; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 257; 254, pattern_list; 254, 255; 254, 256; 255, identifier:ui; 256, identifier:ai; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:np; 260, identifier:unique; 261, argument_list; 261, 262; 261, 263; 262, identifier:i; 263, keyword_argument; 263, 264; 263, 265; 264, identifier:return_index; 265, True; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:cax; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:axes; 272, identifier:scatter; 273, argument_list; 273, 274; 273, 279; 273, 284; 273, 287; 273, 290; 273, 293; 273, 296; 273, 299; 274, subscript; 274, 275; 274, 276; 274, 278; 275, identifier:dt; 276, slice; 276, 277; 277, colon; 278, integer:0; 279, subscript; 279, 280; 279, 281; 279, 283; 280, identifier:dt; 281, slice; 281, 282; 282, colon; 283, integer:1; 284, keyword_argument; 284, 285; 284, 286; 285, identifier:c; 286, identifier:i; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:cmap; 289, identifier:cmap; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:s; 292, identifier:s; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:linewidth; 295, identifier:linewidth; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:edgecolor; 298, identifier:edgecolor; 299, dictionary_splat; 299, 300; 300, identifier:kwargs; 301, if_statement; 301, 302; 301, 304; 302, parenthesized_expression; 302, 303; 303, identifier:colorbar; 304, block; 304, 305; 304, 320; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 308; 307, identifier:cbar; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:plt; 311, identifier:colorbar; 312, argument_list; 312, 313; 312, 314; 312, 317; 313, identifier:cax; 314, keyword_argument; 314, 315; 314, 316; 315, identifier:ax; 316, identifier:axes; 317, keyword_argument; 317, 318; 317, 319; 318, identifier:ticks; 319, identifier:ui; 320, expression_statement; 320, 321; 321, call; 321, 322; 321, 327; 322, attribute; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:cbar; 325, identifier:ax; 326, identifier:set_yticklabels; 327, argument_list; 327, 328; 328, subscript; 328, 329; 328, 330; 329, identifier:c; 330, identifier:ai; 331, else_clause; 331, 332; 332, block; 332, 333; 332, 354; 332, 358; 332, 393; 333, if_statement; 333, 334; 333, 349; 334, not_operator; 334, 335; 335, parenthesized_expression; 335, 336; 336, boolean_operator:or; 336, 337; 336, 344; 337, call; 337, 338; 337, 339; 338, identifier:isinstance; 339, argument_list; 339, 340; 339, 341; 340, identifier:c; 341, attribute; 341, 342; 341, 343; 342, identifier:np; 343, identifier:ndarray; 344, call; 344, 345; 344, 346; 345, identifier:isinstance; 346, argument_list; 346, 347; 346, 348; 347, identifier:c; 348, identifier:list; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 353; 352, identifier:colorbar; 353, False; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 357; 356, identifier:i; 357, identifier:c; 358, expression_statement; 358, 359; 359, assignment; 359, 360; 359, 361; 360, identifier:cax; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:axes; 364, identifier:scatter; 365, argument_list; 365, 366; 365, 371; 365, 376; 365, 379; 365, 382; 365, 385; 365, 388; 365, 391; 366, subscript; 366, 367; 366, 368; 366, 370; 367, identifier:dt; 368, slice; 368, 369; 369, colon; 370, integer:0; 371, subscript; 371, 372; 371, 373; 371, 375; 372, identifier:dt; 373, slice; 373, 374; 374, colon; 375, integer:1; 376, keyword_argument; 376, 377; 376, 378; 377, identifier:c; 378, identifier:i; 379, keyword_argument; 379, 380; 379, 381; 380, identifier:cmap; 381, identifier:cmap; 382, keyword_argument; 382, 383; 382, 384; 383, identifier:s; 384, identifier:s; 385, keyword_argument; 385, 386; 385, 387; 386, identifier:linewidth; 387, identifier:linewidth; 388, keyword_argument; 388, 389; 388, 390; 389, identifier:edgecolor; 390, identifier:edgecolor; 391, dictionary_splat; 391, 392; 392, identifier:kwargs; 393, if_statement; 393, 394; 393, 396; 394, parenthesized_expression; 394, 395; 395, identifier:colorbar; 396, block; 396, 397; 397, expression_statement; 397, 398; 398, call; 398, 399; 398, 402; 399, attribute; 399, 400; 399, 401; 400, identifier:plt; 401, identifier:colorbar; 402, argument_list; 402, 403; 402, 404; 403, identifier:cax; 404, keyword_argument; 404, 405; 404, 406; 405, identifier:ax; 406, identifier:axes
def scatter(self, projection=None, c=None, cmap='rainbow', linewidth=0.0, edgecolor='k', axes=None, colorbar=True, s=10, **kwargs): if (not PLOTTING): print("matplotlib not installed!") else: if(isinstance(projection, str)): try: dt = self.adata.obsm[projection] except KeyError: print('Please create a projection first using run_umap or' 'run_tsne') elif(projection is None): try: dt = self.adata.obsm['X_umap'] except KeyError: try: dt = self.adata.obsm['X_tsne'] except KeyError: print("Please create either a t-SNE or UMAP projection" "first.") return else: dt = projection if(axes is None): plt.figure() axes = plt.gca() if(c is None): plt.scatter(dt[:, 0], dt[:, 1], s=s, linewidth=linewidth, edgecolor=edgecolor, **kwargs) else: if isinstance(c, str): try: c = self.adata.obs[c].get_values() except KeyError: 0 if((isinstance(c[0], str) or isinstance(c[0], np.str_)) and (isinstance(c, np.ndarray) or isinstance(c, list))): i = ut.convert_annotations(c) ui, ai = np.unique(i, return_index=True) cax = axes.scatter(dt[:,0], dt[:,1], c=i, cmap=cmap, s=s, linewidth=linewidth, edgecolor=edgecolor, **kwargs) if(colorbar): cbar = plt.colorbar(cax, ax=axes, ticks=ui) cbar.ax.set_yticklabels(c[ai]) else: if not (isinstance(c, np.ndarray) or isinstance(c, list)): colorbar = False i = c cax = axes.scatter(dt[:,0], dt[:,1], c=i, cmap=cmap, s=s, linewidth=linewidth, edgecolor=edgecolor, **kwargs) if(colorbar): plt.colorbar(cax, ax=axes)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parseFloat; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:words; 6, block; 6, 7; 6, 86; 6, 236; 6, 243; 6, 248; 6, 255; 6, 260; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:pointFloat; 9, parameters; 9, 10; 10, identifier:words; 11, block; 11, 12; 11, 22; 11, 84; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:m; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:re; 18, identifier:search; 19, argument_list; 19, 20; 19, 21; 20, string:r'(.*) point (.*)'; 21, identifier:words; 22, if_statement; 22, 23; 22, 24; 23, identifier:m; 24, block; 24, 25; 24, 34; 24, 43; 24, 47; 24, 51; 24, 75; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:whole; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:m; 31, identifier:group; 32, argument_list; 32, 33; 33, integer:1; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:frac; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:m; 40, identifier:group; 41, argument_list; 41, 42; 42, integer:2; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:total; 46, float:0.0; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:coeff; 50, float:0.10; 51, for_statement; 51, 52; 51, 53; 51, 59; 52, identifier:digit; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:frac; 56, identifier:split; 57, argument_list; 57, 58; 58, string:' '; 59, block; 59, 60; 59, 71; 60, expression_statement; 60, 61; 61, augmented_assignment:+=; 61, 62; 61, 63; 62, identifier:total; 63, binary_operator:*; 63, 64; 63, 65; 64, identifier:coeff; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:parse; 69, argument_list; 69, 70; 70, identifier:digit; 71, expression_statement; 71, 72; 72, augmented_assignment:/=; 72, 73; 72, 74; 73, identifier:coeff; 74, float:10.0; 75, return_statement; 75, 76; 76, binary_operator:+; 76, 77; 76, 83; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:parseInt; 81, argument_list; 81, 82; 82, identifier:whole; 83, identifier:total; 84, return_statement; 84, 85; 85, None; 86, function_definition; 86, 87; 86, 88; 86, 90; 87, function_name:fractionFloat; 88, parameters; 88, 89; 89, identifier:words; 90, block; 90, 91; 90, 101; 90, 234; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:m; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:re; 97, identifier:search; 98, argument_list; 98, 99; 98, 100; 99, string:r'(.*) and (.*)'; 100, identifier:words; 101, if_statement; 101, 102; 101, 103; 102, identifier:m; 103, block; 103, 104; 103, 118; 103, 127; 103, 138; 103, 149; 103, 158; 103, 166; 103, 174; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:whole; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:parseInt; 111, argument_list; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:m; 115, identifier:group; 116, argument_list; 116, 117; 117, integer:1; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:frac; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:m; 124, identifier:group; 125, argument_list; 125, 126; 126, integer:2; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:frac; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:re; 133, identifier:sub; 134, argument_list; 134, 135; 134, 136; 134, 137; 135, string:r'(\w+)s(\b)'; 136, string:'\g<1>\g<2>'; 137, identifier:frac; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:frac; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:re; 144, identifier:sub; 145, argument_list; 145, 146; 145, 147; 145, 148; 146, string:r'(\b)a(\b)'; 147, string:'\g<1>one\g<2>'; 148, identifier:frac; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:split; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:frac; 155, identifier:split; 156, argument_list; 156, 157; 157, string:' '; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:num; 161, subscript; 161, 162; 161, 163; 162, identifier:split; 163, slice; 163, 164; 163, 165; 164, colon; 165, integer:1; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:denom; 169, subscript; 169, 170; 169, 171; 170, identifier:split; 171, slice; 171, 172; 171, 173; 172, integer:1; 173, colon; 174, while_statement; 174, 175; 174, 176; 175, identifier:denom; 176, block; 176, 177; 177, try_statement; 177, 178; 177, 216; 178, block; 178, 179; 178, 193; 178, 207; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:num_value; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:parse; 186, argument_list; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, string:' '; 190, identifier:join; 191, argument_list; 191, 192; 192, identifier:num; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:denom_value; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:parse; 200, argument_list; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, string:' '; 204, identifier:join; 205, argument_list; 205, 206; 206, identifier:denom; 207, return_statement; 207, 208; 208, binary_operator:+; 208, 209; 208, 210; 209, identifier:whole; 210, binary_operator:/; 210, 211; 210, 215; 211, call; 211, 212; 211, 213; 212, identifier:float; 213, argument_list; 213, 214; 214, identifier:num_value; 215, identifier:denom_value; 216, except_clause; 216, 217; 217, block; 217, 218; 217, 226; 218, expression_statement; 218, 219; 219, augmented_assignment:+=; 219, 220; 219, 221; 220, identifier:num; 221, subscript; 221, 222; 221, 223; 222, identifier:denom; 223, slice; 223, 224; 223, 225; 224, colon; 225, integer:1; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:denom; 229, subscript; 229, 230; 229, 231; 230, identifier:denom; 231, slice; 231, 232; 231, 233; 232, integer:1; 233, colon; 234, return_statement; 234, 235; 235, None; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:result; 239, call; 239, 240; 239, 241; 240, identifier:pointFloat; 241, argument_list; 241, 242; 242, identifier:words; 243, if_statement; 243, 244; 243, 245; 244, identifier:result; 245, block; 245, 246; 246, return_statement; 246, 247; 247, identifier:result; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:result; 251, call; 251, 252; 251, 253; 252, identifier:fractionFloat; 253, argument_list; 253, 254; 254, identifier:words; 255, if_statement; 255, 256; 255, 257; 256, identifier:result; 257, block; 257, 258; 258, return_statement; 258, 259; 259, identifier:result; 260, return_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:parseInt; 265, argument_list; 265, 266; 266, identifier:words
def parseFloat(self, words): def pointFloat(words): m = re.search(r'(.*) point (.*)', words) if m: whole = m.group(1) frac = m.group(2) total = 0.0 coeff = 0.10 for digit in frac.split(' '): total += coeff * self.parse(digit) coeff /= 10.0 return self.parseInt(whole) + total return None def fractionFloat(words): m = re.search(r'(.*) and (.*)', words) if m: whole = self.parseInt(m.group(1)) frac = m.group(2) frac = re.sub(r'(\w+)s(\b)', '\g<1>\g<2>', frac) frac = re.sub(r'(\b)a(\b)', '\g<1>one\g<2>', frac) split = frac.split(' ') num = split[:1] denom = split[1:] while denom: try: num_value = self.parse(' '.join(num)) denom_value = self.parse(' '.join(denom)) return whole + float(num_value) / denom_value except: num += denom[:1] denom = denom[1:] return None result = pointFloat(words) if result: return result result = fractionFloat(words) if result: return result return self.parseInt(words)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:run; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:cmd; 6, default_parameter; 6, 7; 6, 8; 7, identifier:stdin; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:marshal_output; 11, True; 12, dictionary_splat_pattern; 12, 13; 13, identifier:kwargs; 14, block; 14, 15; 14, 19; 14, 34; 14, 50; 14, 60; 14, 74; 14, 78; 14, 87; 14, 91; 14, 114; 14, 143; 14, 160; 14, 312; 14, 323; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:records; 18, list:[]; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:args; 22, list:[self._executable, "-u", self._user, "-p", self._port]; 22, 23; 22, 26; 22, 27; 22, 30; 22, 31; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:_executable; 26, string:"-u"; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_user; 30, string:"-p"; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_port; 34, if_statement; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_client; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, augmented_assignment:+=; 40, 41; 40, 42; 41, identifier:args; 42, list:["-c", str(self._client)]; 42, 43; 42, 44; 43, string:"-c"; 44, call; 44, 45; 44, 46; 45, identifier:str; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_client; 50, if_statement; 50, 51; 50, 52; 51, identifier:marshal_output; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:args; 57, identifier:append; 58, argument_list; 58, 59; 59, string:'-G'; 60, if_statement; 60, 61; 60, 68; 61, call; 61, 62; 61, 63; 62, identifier:isinstance; 63, argument_list; 63, 64; 63, 65; 64, identifier:cmd; 65, attribute; 65, 66; 65, 67; 66, identifier:six; 67, identifier:string_types; 68, block; 68, 69; 69, raise_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:ValueError; 72, argument_list; 72, 73; 73, string:'String commands are not supported, please use a list'; 74, expression_statement; 74, 75; 75, augmented_assignment:+=; 75, 76; 75, 77; 76, identifier:args; 77, identifier:cmd; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:command; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, string:' '; 84, identifier:join; 85, argument_list; 85, 86; 86, identifier:args; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:startupinfo; 90, None; 91, if_statement; 91, 92; 91, 97; 92, comparison_operator:==; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:os; 95, identifier:name; 96, string:'nt'; 97, block; 97, 98; 97, 106; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:startupinfo; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:subprocess; 104, identifier:STARTUPINFO; 105, argument_list; 106, expression_statement; 106, 107; 107, augmented_assignment:|=; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:startupinfo; 110, identifier:dwFlags; 111, attribute; 111, 112; 111, 113; 112, identifier:subprocess; 113, identifier:STARTF_USESHOWWINDOW; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:proc; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:subprocess; 120, identifier:Popen; 121, argument_list; 121, 122; 121, 123; 121, 128; 121, 133; 121, 138; 121, 141; 122, identifier:args; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:stdin; 125, attribute; 125, 126; 125, 127; 126, identifier:subprocess; 127, identifier:PIPE; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:stdout; 130, attribute; 130, 131; 130, 132; 131, identifier:subprocess; 132, identifier:PIPE; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:stderr; 135, attribute; 135, 136; 135, 137; 136, identifier:subprocess; 137, identifier:PIPE; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:startupinfo; 140, identifier:startupinfo; 141, dictionary_splat; 141, 142; 142, identifier:kwargs; 143, if_statement; 143, 144; 143, 145; 144, identifier:stdin; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 153; 148, attribute; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:proc; 151, identifier:stdin; 152, identifier:write; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:six; 157, identifier:b; 158, argument_list; 158, 159; 159, identifier:stdin; 160, if_statement; 160, 161; 160, 162; 160, 300; 161, identifier:marshal_output; 162, block; 162, 163; 162, 290; 163, try_statement; 163, 164; 163, 286; 164, block; 164, 165; 165, while_statement; 165, 166; 165, 167; 166, True; 167, block; 167, 168; 167, 179; 167, 225; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:record; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:marshal; 174, identifier:load; 175, argument_list; 175, 176; 176, attribute; 176, 177; 176, 178; 177, identifier:proc; 178, identifier:stdout; 179, if_statement; 179, 180; 179, 197; 180, boolean_operator:and; 180, 181; 180, 190; 181, comparison_operator:==; 181, 182; 181, 189; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:record; 185, identifier:get; 186, argument_list; 186, 187; 186, 188; 187, string:b'code'; 188, string:''; 189, string:b'error'; 190, comparison_operator:>=; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:record; 193, string:b'severity'; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:_level; 197, block; 197, 198; 197, 206; 197, 214; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 205; 200, attribute; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:proc; 203, identifier:stdin; 204, identifier:close; 205, argument_list; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 213; 208, attribute; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:proc; 211, identifier:stdout; 212, identifier:close; 213, argument_list; 214, raise_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:errors; 218, identifier:CommandError; 219, argument_list; 219, 220; 219, 223; 219, 224; 220, subscript; 220, 221; 220, 222; 221, identifier:record; 222, string:b'data'; 223, identifier:record; 224, identifier:command; 225, if_statement; 225, 226; 225, 231; 226, call; 226, 227; 226, 228; 227, identifier:isinstance; 228, argument_list; 228, 229; 228, 230; 229, identifier:record; 230, identifier:dict; 231, block; 231, 232; 232, if_statement; 232, 233; 232, 236; 232, 244; 233, attribute; 233, 234; 233, 235; 234, identifier:six; 235, identifier:PY2; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:records; 241, identifier:append; 242, argument_list; 242, 243; 243, identifier:record; 244, else_clause; 244, 245; 245, block; 245, 246; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:records; 250, identifier:append; 251, argument_list; 251, 252; 252, dictionary_comprehension; 252, 253; 252, 277; 253, pair; 253, 254; 253, 259; 254, call; 254, 255; 254, 256; 255, identifier:str; 256, argument_list; 256, 257; 256, 258; 257, identifier:k; 258, string:'utf8'; 259, conditional_expression:if; 259, 260; 259, 264; 259, 269; 260, call; 260, 261; 260, 262; 261, identifier:str; 262, argument_list; 262, 263; 263, identifier:v; 264, call; 264, 265; 264, 266; 265, identifier:isinstance; 266, argument_list; 266, 267; 266, 268; 267, identifier:v; 268, identifier:int; 269, call; 269, 270; 269, 271; 270, identifier:str; 271, argument_list; 271, 272; 271, 273; 271, 274; 272, identifier:v; 273, string:'utf8'; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:errors; 276, string:'ignore'; 277, for_in_clause; 277, 278; 277, 281; 278, pattern_list; 278, 279; 278, 280; 279, identifier:k; 280, identifier:v; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:record; 284, identifier:items; 285, argument_list; 286, except_clause; 286, 287; 286, 288; 287, identifier:EOFError; 288, block; 288, 289; 289, pass_statement; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 295; 292, pattern_list; 292, 293; 292, 294; 293, identifier:stdout; 294, identifier:stderr; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:proc; 298, identifier:communicate; 299, argument_list; 300, else_clause; 300, 301; 301, block; 301, 302; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 307; 304, pattern_list; 304, 305; 304, 306; 305, identifier:records; 306, identifier:stderr; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:proc; 310, identifier:communicate; 311, argument_list; 312, if_statement; 312, 313; 312, 314; 313, identifier:stderr; 314, block; 314, 315; 315, raise_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:errors; 319, identifier:CommandError; 320, argument_list; 320, 321; 320, 322; 321, identifier:stderr; 322, identifier:command; 323, return_statement; 323, 324; 324, identifier:records
def run(self, cmd, stdin=None, marshal_output=True, **kwargs): records = [] args = [self._executable, "-u", self._user, "-p", self._port] if self._client: args += ["-c", str(self._client)] if marshal_output: args.append('-G') if isinstance(cmd, six.string_types): raise ValueError('String commands are not supported, please use a list') args += cmd command = ' '.join(args) startupinfo = None if os.name == 'nt': startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW proc = subprocess.Popen( args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo, **kwargs ) if stdin: proc.stdin.write(six.b(stdin)) if marshal_output: try: while True: record = marshal.load(proc.stdout) if record.get(b'code', '') == b'error' and record[b'severity'] >= self._level: proc.stdin.close() proc.stdout.close() raise errors.CommandError(record[b'data'], record, command) if isinstance(record, dict): if six.PY2: records.append(record) else: records.append({str(k, 'utf8'): str(v) if isinstance(v, int) else str(v, 'utf8', errors='ignore') for k, v in record.items()}) except EOFError: pass stdout, stderr = proc.communicate() else: records, stderr = proc.communicate() if stderr: raise errors.CommandError(stderr, command) return records
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:canonical_ops; 3, parameters; 3, 4; 4, identifier:ops; 5, block; 5, 6; 5, 8; 5, 30; 6, expression_statement; 6, 7; 7, string:''' Returns the given operations array sorted with duplicates removed. @param ops checker.Ops @return: checker.Ops '''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:new_ops; 11, call; 11, 12; 11, 13; 12, identifier:sorted; 13, argument_list; 13, 14; 13, 18; 14, call; 14, 15; 14, 16; 15, identifier:set; 16, argument_list; 16, 17; 17, identifier:ops; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:key; 20, lambda; 20, 21; 20, 23; 21, lambda_parameters; 21, 22; 22, identifier:x; 23, tuple; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:x; 26, identifier:entity; 27, attribute; 27, 28; 27, 29; 28, identifier:x; 29, identifier:action; 30, return_statement; 30, 31; 31, identifier:new_ops
def canonical_ops(ops): ''' Returns the given operations array sorted with duplicates removed. @param ops checker.Ops @return: checker.Ops ''' new_ops = sorted(set(ops), key=lambda x: (x.entity, x.action)) return new_ops
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:extract_from_text; 3, parameters; 3, 4; 4, identifier:text; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:tools; 10, identifier:remove_duplicates; 11, argument_list; 11, 12; 12, list_comprehension; 12, 13; 12, 28; 12, 36; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:re; 16, identifier:sub; 17, argument_list; 17, 18; 17, 19; 17, 20; 17, 23; 18, string:"arxiv:"; 19, string:""; 20, subscript; 20, 21; 20, 22; 21, identifier:i; 22, integer:0; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:flags; 25, attribute; 25, 26; 25, 27; 26, identifier:re; 27, identifier:IGNORECASE; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:i; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:REGEX; 33, identifier:findall; 34, argument_list; 34, 35; 35, identifier:text; 36, if_clause; 36, 37; 37, comparison_operator:!=; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:i; 40, integer:0; 41, string:''
def extract_from_text(text): return tools.remove_duplicates([re.sub("arxiv:", "", i[0], flags=re.IGNORECASE) for i in REGEX.findall(text) if i[0] != ''])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:extractTimes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:inp; 6, block; 6, 7; 6, 308; 6, 317; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:handleMatch; 9, parameters; 9, 10; 10, identifier:time; 11, block; 11, 12; 11, 16; 11, 264; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:relative; 15, False; 16, if_statement; 16, 17; 16, 19; 16, 22; 16, 40; 16, 58; 16, 76; 16, 203; 17, not_operator; 17, 18; 18, identifier:time; 19, block; 19, 20; 20, return_statement; 20, 21; 21, None; 22, elif_clause; 22, 23; 22, 31; 23, comparison_operator:==; 23, 24; 23, 30; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:time; 27, identifier:group; 28, argument_list; 28, 29; 29, integer:1; 30, string:'morning'; 31, block; 31, 32; 31, 36; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:h; 35, integer:8; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:m; 39, integer:0; 40, elif_clause; 40, 41; 40, 49; 41, comparison_operator:==; 41, 42; 41, 48; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:time; 45, identifier:group; 46, argument_list; 46, 47; 47, integer:1; 48, string:'afternoon'; 49, block; 49, 50; 49, 54; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:h; 53, integer:12; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:m; 57, integer:0; 58, elif_clause; 58, 59; 58, 67; 59, comparison_operator:==; 59, 60; 59, 66; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:time; 63, identifier:group; 64, argument_list; 64, 65; 65, integer:1; 66, string:'evening'; 67, block; 67, 68; 67, 72; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:h; 71, integer:19; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:m; 75, integer:0; 76, elif_clause; 76, 77; 76, 90; 77, boolean_operator:and; 77, 78; 77, 84; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:time; 81, identifier:group; 82, argument_list; 82, 83; 83, integer:4; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:time; 87, identifier:group; 88, argument_list; 88, 89; 89, integer:5; 90, block; 90, 91; 90, 99; 90, 105; 90, 125; 90, 145; 90, 199; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, pattern_list; 93, 94; 93, 95; 94, identifier:h; 95, identifier:m; 96, expression_list; 96, 97; 96, 98; 97, integer:0; 98, integer:0; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:converter; 102, call; 102, 103; 102, 104; 103, identifier:NumberService; 104, argument_list; 105, try_statement; 105, 106; 105, 121; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:diff; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:converter; 113, identifier:parse; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:time; 118, identifier:group; 119, argument_list; 119, 120; 120, integer:4; 121, except_clause; 121, 122; 122, block; 122, 123; 123, return_statement; 123, 124; 124, None; 125, if_statement; 125, 126; 125, 134; 125, 139; 126, comparison_operator:==; 126, 127; 126, 133; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:time; 130, identifier:group; 131, argument_list; 131, 132; 132, integer:5; 133, string:'hours'; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, augmented_assignment:+=; 136, 137; 136, 138; 137, identifier:h; 138, identifier:diff; 139, else_clause; 139, 140; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, augmented_assignment:+=; 142, 143; 142, 144; 143, identifier:m; 144, identifier:diff; 145, if_statement; 145, 146; 145, 152; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:time; 149, identifier:group; 150, argument_list; 150, 151; 151, integer:6; 152, block; 152, 153; 152, 159; 152, 179; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:converter; 156, call; 156, 157; 156, 158; 157, identifier:NumberService; 158, argument_list; 159, try_statement; 159, 160; 159, 175; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:diff; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:converter; 167, identifier:parse; 168, argument_list; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:time; 172, identifier:group; 173, argument_list; 173, 174; 174, integer:7; 175, except_clause; 175, 176; 176, block; 176, 177; 177, return_statement; 177, 178; 178, None; 179, if_statement; 179, 180; 179, 188; 179, 193; 180, comparison_operator:==; 180, 181; 180, 187; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:time; 184, identifier:group; 185, argument_list; 185, 186; 186, integer:8; 187, string:'hours'; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, augmented_assignment:+=; 190, 191; 190, 192; 191, identifier:h; 192, identifier:diff; 193, else_clause; 193, 194; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, augmented_assignment:+=; 196, 197; 196, 198; 197, identifier:m; 198, identifier:diff; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:relative; 202, True; 203, else_clause; 203, 204; 204, block; 204, 205; 204, 214; 204, 244; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:t; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:time; 211, identifier:group; 212, argument_list; 212, 213; 213, integer:2; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 219; 216, pattern_list; 216, 217; 216, 218; 217, identifier:h; 218, identifier:m; 219, expression_list; 219, 220; 219, 233; 220, binary_operator:%; 220, 221; 220, 232; 221, call; 221, 222; 221, 223; 222, identifier:int; 223, argument_list; 223, 224; 224, subscript; 224, 225; 224, 231; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:t; 228, identifier:split; 229, argument_list; 229, 230; 230, string:':'; 231, integer:0; 232, integer:12; 233, call; 233, 234; 233, 235; 234, identifier:int; 235, argument_list; 235, 236; 236, subscript; 236, 237; 236, 243; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:t; 240, identifier:split; 241, argument_list; 241, 242; 242, string:':'; 243, integer:1; 244, try_statement; 244, 245; 244, 260; 245, block; 245, 246; 246, if_statement; 246, 247; 246, 255; 247, comparison_operator:==; 247, 248; 247, 254; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:time; 251, identifier:group; 252, argument_list; 252, 253; 253, integer:3; 254, string:'pm'; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, augmented_assignment:+=; 257, 258; 257, 259; 258, identifier:h; 259, integer:12; 260, except_clause; 260, 261; 260, 262; 261, identifier:IndexError; 262, block; 262, 263; 263, pass_statement; 264, if_statement; 264, 265; 264, 266; 264, 283; 265, identifier:relative; 266, block; 266, 267; 267, return_statement; 267, 268; 268, binary_operator:+; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:now; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:datetime; 275, identifier:timedelta; 276, argument_list; 276, 277; 276, 280; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:hours; 279, identifier:h; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:minutes; 282, identifier:m; 283, else_clause; 283, 284; 284, block; 284, 285; 285, return_statement; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:datetime; 289, identifier:datetime; 290, argument_list; 290, 291; 290, 296; 290, 301; 290, 306; 290, 307; 291, attribute; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:now; 295, identifier:year; 296, attribute; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:self; 299, identifier:now; 300, identifier:month; 301, attribute; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:self; 304, identifier:now; 305, identifier:day; 306, identifier:h; 307, identifier:m; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:inp; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:_preprocess; 315, argument_list; 315, 316; 316, identifier:inp; 317, return_statement; 317, 318; 318, list_comprehension; 318, 319; 318, 323; 319, call; 319, 320; 319, 321; 320, identifier:handleMatch; 321, argument_list; 321, 322; 322, identifier:time; 323, for_in_clause; 323, 324; 323, 325; 324, identifier:time; 325, call; 325, 326; 325, 331; 326, attribute; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:self; 329, identifier:_timeRegex; 330, identifier:finditer; 331, argument_list; 331, 332; 332, identifier:inp
def extractTimes(self, inp): def handleMatch(time): relative = False if not time: return None elif time.group(1) == 'morning': h = 8 m = 0 elif time.group(1) == 'afternoon': h = 12 m = 0 elif time.group(1) == 'evening': h = 19 m = 0 elif time.group(4) and time.group(5): h, m = 0, 0 converter = NumberService() try: diff = converter.parse(time.group(4)) except: return None if time.group(5) == 'hours': h += diff else: m += diff if time.group(6): converter = NumberService() try: diff = converter.parse(time.group(7)) except: return None if time.group(8) == 'hours': h += diff else: m += diff relative = True else: t = time.group(2) h, m = int(t.split(':')[0]) % 12, int(t.split(':')[1]) try: if time.group(3) == 'pm': h += 12 except IndexError: pass if relative: return self.now + datetime.timedelta(hours=h, minutes=m) else: return datetime.datetime( self.now.year, self.now.month, self.now.day, h, m ) inp = self._preprocess(inp) return [handleMatch(time) for time in self._timeRegex.finditer(inp)]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:serialize_text; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 26; 5, 44; 5, 48; 5, 65; 6, expression_statement; 6, 7; 7, string:'''Returns a serialized form of the Namepace. All the elements in the namespace are sorted by URI, joined to the associated prefix with a colon and separated with spaces. :return: bytes '''; 8, if_statement; 8, 9; 8, 23; 9, boolean_operator:or; 9, 10; 9, 15; 10, comparison_operator:is; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_uri_to_prefix; 14, None; 15, comparison_operator:==; 15, 16; 15, 22; 16, call; 16, 17; 16, 18; 17, identifier:len; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_uri_to_prefix; 22, integer:0; 23, block; 23, 24; 24, return_statement; 24, 25; 25, string:b''; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:od; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:collections; 32, identifier:OrderedDict; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:sorted; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_uri_to_prefix; 42, identifier:items; 43, argument_list; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:data; 47, list:[]; 48, for_statement; 48, 49; 48, 50; 48, 51; 49, identifier:uri; 50, identifier:od; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:data; 56, identifier:append; 57, argument_list; 57, 58; 58, binary_operator:+; 58, 59; 58, 62; 59, binary_operator:+; 59, 60; 59, 61; 60, identifier:uri; 61, string:':'; 62, subscript; 62, 63; 62, 64; 63, identifier:od; 64, identifier:uri; 65, return_statement; 65, 66; 66, call; 66, 67; 66, 75; 67, attribute; 67, 68; 67, 74; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, string:' '; 71, identifier:join; 72, argument_list; 72, 73; 73, identifier:data; 74, identifier:encode; 75, argument_list; 75, 76; 76, string:'utf-8'
def serialize_text(self): '''Returns a serialized form of the Namepace. All the elements in the namespace are sorted by URI, joined to the associated prefix with a colon and separated with spaces. :return: bytes ''' if self._uri_to_prefix is None or len(self._uri_to_prefix) == 0: return b'' od = collections.OrderedDict(sorted(self._uri_to_prefix.items())) data = [] for uri in od: data.append(uri + ':' + od[uri]) return ' '.join(data).encode('utf-8')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:with_zero_or_one; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:converter; 6, default_parameter; 6, 7; 6, 8; 7, identifier:pattern; 8, None; 9, block; 9, 10; 9, 16; 9, 31; 9, 40; 9, 49; 9, 79; 9, 85; 9, 91; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:cardinality; 13, attribute; 13, 14; 13, 15; 14, identifier:Cardinality; 15, identifier:zero_or_one; 16, if_statement; 16, 17; 16, 19; 17, not_operator; 17, 18; 18, identifier:pattern; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:pattern; 23, call; 23, 24; 23, 25; 24, identifier:getattr; 25, argument_list; 25, 26; 25, 27; 25, 28; 26, identifier:converter; 27, string:"pattern"; 28, attribute; 28, 29; 28, 30; 29, identifier:cls; 30, identifier:default_pattern; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:optional_pattern; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:cardinality; 37, identifier:make_pattern; 38, argument_list; 38, 39; 39, identifier:pattern; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:group_count; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:cardinality; 46, identifier:compute_group_count; 47, argument_list; 47, 48; 48, identifier:pattern; 49, function_definition; 49, 50; 49, 51; 49, 56; 50, function_name:convert_optional; 51, parameters; 51, 52; 51, 53; 52, identifier:text; 53, default_parameter; 53, 54; 53, 55; 54, identifier:m; 55, None; 56, block; 56, 57; 56, 68; 56, 74; 57, if_statement; 57, 58; 57, 59; 58, identifier:text; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:text; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:text; 66, identifier:strip; 67, argument_list; 68, if_statement; 68, 69; 68, 71; 69, not_operator; 69, 70; 70, identifier:text; 71, block; 71, 72; 72, return_statement; 72, 73; 73, None; 74, return_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:converter; 77, argument_list; 77, 78; 78, identifier:text; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:convert_optional; 83, identifier:pattern; 84, identifier:optional_pattern; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:convert_optional; 89, identifier:regex_group_count; 90, identifier:group_count; 91, return_statement; 91, 92; 92, identifier:convert_optional
def with_zero_or_one(cls, converter, pattern=None): cardinality = Cardinality.zero_or_one if not pattern: pattern = getattr(converter, "pattern", cls.default_pattern) optional_pattern = cardinality.make_pattern(pattern) group_count = cardinality.compute_group_count(pattern) def convert_optional(text, m=None): if text: text = text.strip() if not text: return None return converter(text) convert_optional.pattern = optional_pattern convert_optional.regex_group_count = group_count return convert_optional
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:stats_keyboard; 3, parameters; 3, 4; 3, 5; 4, identifier:events; 5, identifier:table; 6, block; 6, 7; 6, 19; 6, 27; 6, 35; 6, 48; 6, 63; 6, 72; 6, 200; 6, 229; 6, 387; 7, if_statement; 7, 8; 7, 14; 8, comparison_operator:<; 8, 9; 8, 13; 9, call; 9, 10; 9, 11; 10, identifier:len; 11, argument_list; 11, 12; 12, identifier:events; 13, integer:2; 14, block; 14, 15; 15, return_statement; 15, 16; 16, expression_list; 16, 17; 16, 18; 17, list:[]; 18, list:[]; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, pattern_list; 21, 22; 21, 23; 22, identifier:deltas; 23, identifier:prev_dt; 24, expression_list; 24, 25; 24, 26; 25, list:[]; 26, None; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 32; 29, pattern_list; 29, 30; 29, 31; 30, identifier:sessions; 31, identifier:session; 32, expression_list; 32, 33; 32, 34; 33, list:[]; 34, None; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:UNBROKEN_DELTA; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:datetime; 41, identifier:timedelta; 42, argument_list; 42, 43; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:seconds; 45, attribute; 45, 46; 45, 47; 46, identifier:conf; 47, identifier:KeyboardSessionMaxDelta; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:blank; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:collections; 54, identifier:defaultdict; 55, argument_list; 55, 56; 56, lambda; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:collections; 60, identifier:defaultdict; 61, argument_list; 61, 62; 62, identifier:int; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:collated; 66, list:[blank.copy()]; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:blank; 70, identifier:copy; 71, argument_list; 72, for_statement; 72, 73; 72, 74; 72, 75; 73, identifier:e; 74, identifier:events; 75, block; 75, 76; 75, 170; 75, 181; 75, 194; 76, if_statement; 76, 77; 76, 78; 77, identifier:prev_dt; 78, block; 78, 79; 78, 122; 78, 130; 78, 137; 79, if_statement; 79, 80; 79, 110; 80, parenthesized_expression; 80, 81; 81, boolean_operator:or; 81, 82; 81, 101; 82, boolean_operator:or; 82, 83; 82, 92; 83, comparison_operator:!=; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:prev_dt; 86, identifier:second; 87, attribute; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:e; 90, string:"dt"; 91, identifier:second; 92, comparison_operator:!=; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:prev_dt; 95, identifier:minute; 96, attribute; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:e; 99, string:"dt"; 100, identifier:minute; 101, comparison_operator:!=; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:prev_dt; 104, identifier:hour; 105, attribute; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:e; 108, string:"dt"; 109, identifier:hour; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:collated; 115, identifier:append; 116, argument_list; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:blank; 120, identifier:copy; 121, argument_list; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:delta; 125, binary_operator:-; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:e; 128, string:"dt"; 129, identifier:prev_dt; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:deltas; 134, identifier:append; 135, argument_list; 135, 136; 136, identifier:delta; 137, if_statement; 137, 138; 137, 141; 137, 146; 138, comparison_operator:>; 138, 139; 138, 140; 139, identifier:delta; 140, identifier:UNBROKEN_DELTA; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:session; 145, None; 146, else_clause; 146, 147; 147, block; 147, 148; 147, 163; 148, if_statement; 148, 149; 148, 151; 149, not_operator; 149, 150; 150, identifier:session; 151, block; 151, 152; 151, 156; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:session; 155, list:[]; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:sessions; 160, identifier:append; 161, argument_list; 161, 162; 162, identifier:session; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:session; 167, identifier:append; 168, argument_list; 168, 169; 169, identifier:delta; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 178; 172, subscript; 172, 173; 172, 177; 173, subscript; 173, 174; 173, 175; 174, identifier:collated; 175, unary_operator:-; 175, 176; 176, integer:1; 177, string:"dt"; 178, subscript; 178, 179; 178, 180; 179, identifier:e; 180, string:"dt"; 181, expression_statement; 181, 182; 182, augmented_assignment:+=; 182, 183; 182, 193; 183, subscript; 183, 184; 183, 190; 184, subscript; 184, 185; 184, 189; 185, subscript; 185, 186; 185, 187; 186, identifier:collated; 187, unary_operator:-; 187, 188; 188, integer:1; 189, string:"keys"; 190, subscript; 190, 191; 190, 192; 191, identifier:e; 192, string:"realkey"; 193, integer:1; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:prev_dt; 197, subscript; 197, 198; 197, 199; 198, identifier:e; 199, string:"dt"; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:longest_session; 203, call; 203, 204; 203, 205; 204, identifier:max; 205, argument_list; 205, 206; 205, 215; 206, binary_operator:+; 206, 207; 206, 208; 207, identifier:sessions; 208, list:[[datetime.timedelta()]]; 208, 209; 209, list:[datetime.timedelta()]; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:datetime; 213, identifier:timedelta; 214, argument_list; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:key; 217, lambda; 217, 218; 217, 220; 218, lambda_parameters; 218, 219; 219, identifier:x; 220, call; 220, 221; 220, 222; 221, identifier:sum; 222, argument_list; 222, 223; 222, 224; 223, identifier:x; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:datetime; 227, identifier:timedelta; 228, argument_list; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:stats; 232, conditional_expression:if; 232, 233; 232, 250; 232, 253; 233, list:[ ("Average interval between combos", sum(deltas, datetime.timedelta()) / len(deltas)), ]; 233, 234; 234, tuple; 234, 235; 234, 236; 235, string:"Average interval between combos"; 236, binary_operator:/; 236, 237; 236, 246; 237, call; 237, 238; 237, 239; 238, identifier:sum; 239, argument_list; 239, 240; 239, 241; 240, identifier:deltas; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:datetime; 244, identifier:timedelta; 245, argument_list; 246, call; 246, 247; 246, 248; 247, identifier:len; 248, argument_list; 248, 249; 249, identifier:deltas; 250, comparison_operator:==; 250, 251; 250, 252; 251, string:"combos"; 252, identifier:table; 253, list:[ ("Keys per hour", int(3600 * len(events) / timedelta_seconds(events[-1]["dt"] - events[0]["dt"]))), ("Average interval between keys", sum(deltas, datetime.timedelta()) / len(deltas)), ("Typing sessions (key interval < %ss)" % UNBROKEN_DELTA.seconds, len(sessions)), ("Average keys in session", sum(len(x) + 1 for x in sessions) / len(sessions)), ("Average session duration", sum((sum(x, datetime.timedelta()) for x in sessions), datetime.timedelta()) / len(sessions)), ("Longest session duration", sum(longest_session, datetime.timedelta())), ("Keys in longest session", len(longest_session) + 1), ("Most keys in session", max(len(x) + 1 for x in sessions)), ]; 253, 254; 253, 281; 253, 297; 253, 307; 253, 326; 253, 354; 253, 365; 253, 373; 254, tuple; 254, 255; 254, 256; 255, string:"Keys per hour"; 256, call; 256, 257; 256, 258; 257, identifier:int; 258, argument_list; 258, 259; 259, binary_operator:/; 259, 260; 259, 266; 260, binary_operator:*; 260, 261; 260, 262; 261, integer:3600; 262, call; 262, 263; 262, 264; 263, identifier:len; 264, argument_list; 264, 265; 265, identifier:events; 266, call; 266, 267; 266, 268; 267, identifier:timedelta_seconds; 268, argument_list; 268, 269; 269, binary_operator:-; 269, 270; 269, 276; 270, subscript; 270, 271; 270, 275; 271, subscript; 271, 272; 271, 273; 272, identifier:events; 273, unary_operator:-; 273, 274; 274, integer:1; 275, string:"dt"; 276, subscript; 276, 277; 276, 280; 277, subscript; 277, 278; 277, 279; 278, identifier:events; 279, integer:0; 280, string:"dt"; 281, tuple; 281, 282; 281, 283; 282, string:"Average interval between keys"; 283, binary_operator:/; 283, 284; 283, 293; 284, call; 284, 285; 284, 286; 285, identifier:sum; 286, argument_list; 286, 287; 286, 288; 287, identifier:deltas; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:datetime; 291, identifier:timedelta; 292, argument_list; 293, call; 293, 294; 293, 295; 294, identifier:len; 295, argument_list; 295, 296; 296, identifier:deltas; 297, tuple; 297, 298; 297, 303; 298, binary_operator:%; 298, 299; 298, 300; 299, string:"Typing sessions (key interval < %ss)"; 300, attribute; 300, 301; 300, 302; 301, identifier:UNBROKEN_DELTA; 302, identifier:seconds; 303, call; 303, 304; 303, 305; 304, identifier:len; 305, argument_list; 305, 306; 306, identifier:sessions; 307, tuple; 307, 308; 307, 309; 308, string:"Average keys in session"; 309, binary_operator:/; 309, 310; 309, 322; 310, call; 310, 311; 310, 312; 311, identifier:sum; 312, generator_expression; 312, 313; 312, 319; 313, binary_operator:+; 313, 314; 313, 318; 314, call; 314, 315; 314, 316; 315, identifier:len; 316, argument_list; 316, 317; 317, identifier:x; 318, integer:1; 319, for_in_clause; 319, 320; 319, 321; 320, identifier:x; 321, identifier:sessions; 322, call; 322, 323; 322, 324; 323, identifier:len; 324, argument_list; 324, 325; 325, identifier:sessions; 326, tuple; 326, 327; 326, 328; 327, string:"Average session duration"; 328, binary_operator:/; 328, 329; 328, 350; 329, call; 329, 330; 329, 331; 330, identifier:sum; 331, argument_list; 331, 332; 331, 345; 332, generator_expression; 332, 333; 332, 342; 333, call; 333, 334; 333, 335; 334, identifier:sum; 335, argument_list; 335, 336; 335, 337; 336, identifier:x; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:datetime; 340, identifier:timedelta; 341, argument_list; 342, for_in_clause; 342, 343; 342, 344; 343, identifier:x; 344, identifier:sessions; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:datetime; 348, identifier:timedelta; 349, argument_list; 350, call; 350, 351; 350, 352; 351, identifier:len; 352, argument_list; 352, 353; 353, identifier:sessions; 354, tuple; 354, 355; 354, 356; 355, string:"Longest session duration"; 356, call; 356, 357; 356, 358; 357, identifier:sum; 358, argument_list; 358, 359; 358, 360; 359, identifier:longest_session; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:datetime; 363, identifier:timedelta; 364, argument_list; 365, tuple; 365, 366; 365, 367; 366, string:"Keys in longest session"; 367, binary_operator:+; 367, 368; 367, 372; 368, call; 368, 369; 368, 370; 369, identifier:len; 370, argument_list; 370, 371; 371, identifier:longest_session; 372, integer:1; 373, tuple; 373, 374; 373, 375; 374, string:"Most keys in session"; 375, call; 375, 376; 375, 377; 376, identifier:max; 377, generator_expression; 377, 378; 377, 384; 378, binary_operator:+; 378, 379; 378, 383; 379, call; 379, 380; 379, 381; 380, identifier:len; 381, argument_list; 381, 382; 382, identifier:x; 383, integer:1; 384, for_in_clause; 384, 385; 384, 386; 385, identifier:x; 386, identifier:sessions; 387, return_statement; 387, 388; 388, expression_list; 388, 389; 388, 390; 389, identifier:stats; 390, identifier:collated
def stats_keyboard(events, table): if len(events) < 2: return [], [] deltas, prev_dt = [], None sessions, session = [], None UNBROKEN_DELTA = datetime.timedelta(seconds=conf.KeyboardSessionMaxDelta) blank = collections.defaultdict(lambda: collections.defaultdict(int)) collated = [blank.copy()] for e in events: if prev_dt: if (prev_dt.second != e["dt"].second or prev_dt.minute != e["dt"].minute or prev_dt.hour != e["dt"].hour): collated.append(blank.copy()) delta = e["dt"] - prev_dt deltas.append(delta) if delta > UNBROKEN_DELTA: session = None else: if not session: session = [] sessions.append(session) session.append(delta) collated[-1]["dt"] = e["dt"] collated[-1]["keys"][e["realkey"]] += 1 prev_dt = e["dt"] longest_session = max(sessions + [[datetime.timedelta()]], key=lambda x: sum(x, datetime.timedelta())) stats = [ ("Average interval between combos", sum(deltas, datetime.timedelta()) / len(deltas)), ] if "combos" == table else [ ("Keys per hour", int(3600 * len(events) / timedelta_seconds(events[-1]["dt"] - events[0]["dt"]))), ("Average interval between keys", sum(deltas, datetime.timedelta()) / len(deltas)), ("Typing sessions (key interval < %ss)" % UNBROKEN_DELTA.seconds, len(sessions)), ("Average keys in session", sum(len(x) + 1 for x in sessions) / len(sessions)), ("Average session duration", sum((sum(x, datetime.timedelta()) for x in sessions), datetime.timedelta()) / len(sessions)), ("Longest session duration", sum(longest_session, datetime.timedelta())), ("Keys in longest session", len(longest_session) + 1), ("Most keys in session", max(len(x) + 1 for x in sessions)), ] return stats, collated
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:to_perseus; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:df; 5, identifier:path_or_file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:main_columns; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:separator; 11, identifier:separator; 12, default_parameter; 12, 13; 12, 14; 13, identifier:convert_bool_to_category; 14, True; 15, default_parameter; 15, 16; 15, 17; 16, identifier:numerical_annotation_rows; 17, call; 17, 18; 17, 19; 18, identifier:set; 19, argument_list; 19, 20; 20, list:[]; 21, block; 21, 22; 21, 30; 21, 46; 21, 57; 21, 61; 21, 73; 21, 100; 21, 181; 21, 234; 21, 248; 21, 280; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:_df; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:df; 28, identifier:copy; 29, argument_list; 30, if_statement; 30, 31; 30, 37; 31, not_operator; 31, 32; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:_df; 35, identifier:columns; 36, identifier:name; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:_df; 43, identifier:columns; 44, identifier:name; 45, string:'Column Name'; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:column_names; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:_df; 53, identifier:columns; 54, identifier:get_level_values; 55, argument_list; 55, 56; 56, string:'Column Name'; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:annotations; 60, dictionary; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:main_columns; 64, conditional_expression:if; 64, 65; 64, 69; 64, 72; 65, call; 65, 66; 65, 67; 66, identifier:_infer_main_columns; 67, argument_list; 67, 68; 68, identifier:_df; 69, comparison_operator:is; 69, 70; 69, 71; 70, identifier:main_columns; 71, None; 72, identifier:main_columns; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:annotations; 77, string:'Type'; 78, list_comprehension; 78, 79; 78, 90; 79, conditional_expression:if; 79, 80; 79, 81; 79, 86; 80, string:'E'; 81, comparison_operator:in; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:column_names; 84, identifier:i; 85, identifier:main_columns; 86, call; 86, 87; 86, 88; 87, identifier:dtype_to_perseus; 88, argument_list; 88, 89; 89, identifier:dtype; 90, for_in_clause; 90, 91; 90, 94; 91, pattern_list; 91, 92; 91, 93; 92, identifier:i; 93, identifier:dtype; 94, call; 94, 95; 94, 96; 95, identifier:enumerate; 96, argument_list; 96, 97; 97, attribute; 97, 98; 97, 99; 98, identifier:_df; 99, identifier:dtypes; 100, for_statement; 100, 101; 100, 104; 100, 110; 101, pattern_list; 101, 102; 101, 103; 102, identifier:i; 103, identifier:column; 104, call; 104, 105; 104, 106; 105, identifier:enumerate; 106, argument_list; 106, 107; 107, attribute; 107, 108; 107, 109; 108, identifier:_df; 109, identifier:columns; 110, block; 110, 111; 110, 125; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:valid_values; 114, list_comprehension; 114, 115; 114, 116; 114, 121; 115, identifier:value; 116, for_in_clause; 116, 117; 116, 118; 117, identifier:value; 118, subscript; 118, 119; 118, 120; 119, identifier:_df; 120, identifier:column; 121, if_clause; 121, 122; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:value; 124, None; 125, if_statement; 125, 126; 125, 145; 126, boolean_operator:and; 126, 127; 126, 133; 127, comparison_operator:>; 127, 128; 127, 132; 128, call; 128, 129; 128, 130; 129, identifier:len; 130, argument_list; 130, 131; 131, identifier:valid_values; 132, integer:0; 133, call; 133, 134; 133, 135; 134, identifier:all; 135, generator_expression; 135, 136; 135, 142; 136, comparison_operator:is; 136, 137; 136, 141; 137, call; 137, 138; 137, 139; 138, identifier:type; 139, argument_list; 139, 140; 140, identifier:value; 141, identifier:list; 142, for_in_clause; 142, 143; 142, 144; 143, identifier:value; 144, identifier:valid_values; 145, block; 145, 146; 145, 154; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 153; 148, subscript; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:annotations; 151, string:'Type'; 152, identifier:i; 153, string:'M'; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:_df; 158, identifier:column; 159, call; 159, 160; 159, 165; 160, attribute; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:_df; 163, identifier:column; 164, identifier:apply; 165, argument_list; 165, 166; 166, lambda; 166, 167; 166, 169; 167, lambda_parameters; 167, 168; 168, identifier:xs; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, string:';'; 172, identifier:join; 173, generator_expression; 173, 174; 173, 178; 174, call; 174, 175; 174, 176; 175, identifier:str; 176, argument_list; 176, 177; 177, identifier:x; 178, for_in_clause; 178, 179; 178, 180; 179, identifier:x; 180, identifier:xs; 181, if_statement; 181, 182; 181, 183; 182, identifier:convert_bool_to_category; 183, block; 183, 184; 184, for_statement; 184, 185; 184, 188; 184, 194; 185, pattern_list; 185, 186; 185, 187; 186, identifier:i; 187, identifier:column; 188, call; 188, 189; 188, 190; 189, identifier:enumerate; 190, argument_list; 190, 191; 191, attribute; 191, 192; 191, 193; 192, identifier:_df; 193, identifier:columns; 194, block; 194, 195; 195, if_statement; 195, 196; 195, 208; 196, comparison_operator:is; 196, 197; 196, 202; 197, subscript; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:_df; 200, identifier:dtypes; 201, identifier:i; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:np; 205, identifier:dtype; 206, argument_list; 206, 207; 207, string:'bool'; 208, block; 208, 209; 208, 217; 208, 225; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:values; 212, attribute; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:_df; 215, identifier:column; 216, identifier:values; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 224; 219, subscript; 219, 220; 219, 223; 220, subscript; 220, 221; 220, 222; 221, identifier:_df; 222, identifier:column; 223, identifier:values; 224, string:'+'; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 233; 227, subscript; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:_df; 230, identifier:column; 231, unary_operator:~; 231, 232; 232, identifier:values; 233, string:''; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:annotation_row_names; 237, binary_operator:-; 237, 238; 237, 246; 238, call; 238, 239; 238, 240; 239, identifier:set; 240, argument_list; 240, 241; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:_df; 244, identifier:columns; 245, identifier:names; 246, set; 246, 247; 247, string:'Column Name'; 248, for_statement; 248, 249; 248, 250; 248, 251; 249, identifier:name; 250, identifier:annotation_row_names; 251, block; 251, 252; 251, 261; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:annotation_type; 255, conditional_expression:if; 255, 256; 255, 257; 255, 260; 256, string:'N'; 257, comparison_operator:in; 257, 258; 257, 259; 258, identifier:name; 259, identifier:numerical_annotation_rows; 260, string:'C'; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 272; 263, subscript; 263, 264; 263, 265; 264, identifier:annotations; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, string:'{}:{}'; 268, identifier:format; 269, argument_list; 269, 270; 269, 271; 270, identifier:annotation_type; 271, identifier:name; 272, call; 272, 273; 272, 278; 273, attribute; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:_df; 276, identifier:columns; 277, identifier:get_level_values; 278, argument_list; 278, 279; 279, identifier:name; 280, with_statement; 280, 281; 280, 291; 281, with_clause; 281, 282; 282, with_item; 282, 283; 283, as_pattern; 283, 284; 283, 289; 284, call; 284, 285; 284, 286; 285, identifier:PathOrFile; 286, argument_list; 286, 287; 286, 288; 287, identifier:path_or_file; 288, string:'w'; 289, as_pattern_target; 289, 290; 290, identifier:f; 291, block; 291, 292; 291, 306; 291, 320; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:f; 296, identifier:write; 297, argument_list; 297, 298; 298, binary_operator:+; 298, 299; 298, 305; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:separator; 302, identifier:join; 303, argument_list; 303, 304; 304, identifier:column_names; 305, string:'\n'; 306, for_statement; 306, 307; 306, 310; 306, 315; 306, 319; 307, pattern_list; 307, 308; 307, 309; 308, identifier:name; 309, identifier:values; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:annotations; 313, identifier:items; 314, argument_list; 315, ERROR; 315, 316; 316, attribute; 316, 317; 316, 318; 317, identifier:f; 318, identifier:write; 319, block:; 320, expression_statement; 320, 321; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:_df; 324, identifier:to_csv; 325, argument_list; 325, 326; 325, 327; 325, 330; 325, 333; 326, identifier:f; 327, keyword_argument; 327, 328; 327, 329; 328, identifier:header; 329, None; 330, keyword_argument; 330, 331; 330, 332; 331, identifier:index; 332, False; 333, keyword_argument; 333, 334; 333, 335; 334, identifier:sep; 335, identifier:separator
def to_perseus(df, path_or_file, main_columns=None, separator=separator, convert_bool_to_category=True, numerical_annotation_rows = set([])): _df = df.copy() if not _df.columns.name: _df.columns.name = 'Column Name' column_names = _df.columns.get_level_values('Column Name') annotations = {} main_columns = _infer_main_columns(_df) if main_columns is None else main_columns annotations['Type'] = ['E' if column_names[i] in main_columns else dtype_to_perseus(dtype) for i, dtype in enumerate(_df.dtypes)] for i, column in enumerate(_df.columns): valid_values = [value for value in _df[column] if value is not None] if len(valid_values) > 0 and all(type(value) is list for value in valid_values): annotations['Type'][i] = 'M' _df[column] = _df[column].apply(lambda xs: ';'.join(str(x) for x in xs)) if convert_bool_to_category: for i, column in enumerate(_df.columns): if _df.dtypes[i] is np.dtype('bool'): values = _df[column].values _df[column][values] = '+' _df[column][~values] = '' annotation_row_names = set(_df.columns.names) - {'Column Name'} for name in annotation_row_names: annotation_type = 'N' if name in numerical_annotation_rows else 'C' annotations['{}:{}'.format(annotation_type, name)] = _df.columns.get_level_values(name) with PathOrFile(path_or_file, 'w') as f: f.write(separator.join(column_names) + '\n') for name, values in annotations.items(): f.write(' _df.to_csv(f, header=None, index=False, sep=separator)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:do_your_job; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 16; 5, 65; 5, 71; 5, 80; 5, 153; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, pattern_list; 8, 9; 8, 10; 9, identifier:y; 10, identifier:x; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:get_intended_direction; 15, argument_list; 16, if_statement; 16, 17; 16, 32; 17, boolean_operator:and; 17, 18; 17, 25; 18, comparison_operator:==; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:target_x; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:current_x; 25, comparison_operator:==; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:target_y; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:current_y; 32, block; 32, 33; 32, 64; 33, if_statement; 33, 34; 33, 42; 34, comparison_operator:==; 34, 35; 34, 41; 35, call; 35, 36; 35, 37; 36, identifier:len; 37, argument_list; 37, 38; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:results; 41, integer:0; 42, block; 42, 43; 42, 52; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:results; 49, identifier:append; 50, argument_list; 50, 51; 51, string:"TARGET ACQUIRED"; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:lg_mv; 57, argument_list; 57, 58; 57, 59; 58, integer:2; 59, binary_operator:+; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:name; 63, string:": TARGET ACQUIRED"; 64, return_statement; 65, expression_statement; 65, 66; 66, augmented_assignment:+=; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:num_steps; 70, integer:1; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:accessible; 74, list:['\\', '-', '|', '/', '.']; 74, 75; 74, 76; 74, 77; 74, 78; 74, 79; 75, string:'\\'; 76, string:'-'; 77, string:'|'; 78, string:'/'; 79, string:'.'; 80, if_statement; 80, 81; 80, 96; 81, boolean_operator:and; 81, 82; 81, 89; 82, boolean_operator:and; 82, 83; 82, 86; 83, comparison_operator:!=; 83, 84; 83, 85; 84, identifier:y; 85, integer:0; 86, comparison_operator:!=; 86, 87; 86, 88; 87, identifier:x; 88, integer:0; 89, comparison_operator:==; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:backtrack; 93, list:[0,0]; 93, 94; 93, 95; 94, integer:0; 95, integer:0; 96, block; 96, 97; 97, if_statement; 97, 98; 97, 107; 98, comparison_operator:>; 98, 99; 98, 106; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:random; 102, identifier:randint; 103, argument_list; 103, 104; 103, 105; 104, integer:1; 105, integer:10; 106, integer:6; 107, block; 107, 108; 108, if_statement; 108, 109; 108, 126; 109, comparison_operator:in; 109, 110; 109, 125; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:grd; 115, identifier:get_tile; 116, argument_list; 116, 117; 116, 122; 117, binary_operator:+; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:current_y; 121, identifier:y; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:current_x; 125, identifier:accessible; 126, block; 126, 127; 126, 133; 126, 152; 127, expression_statement; 127, 128; 128, augmented_assignment:+=; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:current_y; 132, identifier:y; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:lg_mv; 138, argument_list; 138, 139; 138, 140; 139, integer:3; 140, binary_operator:+; 140, 141; 140, 146; 141, binary_operator:+; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:name; 145, string:": randomly moving Y axis "; 146, call; 146, 147; 146, 148; 147, identifier:str; 148, argument_list; 148, 149; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:num_steps; 152, return_statement; 153, if_statement; 153, 154; 153, 157; 154, comparison_operator:==; 154, 155; 154, 156; 155, identifier:x; 156, integer:1; 157, block; 157, 158; 157, 200; 157, 241; 157, 283; 158, if_statement; 158, 159; 158, 176; 159, comparison_operator:in; 159, 160; 159, 175; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:grd; 165, identifier:get_tile; 166, argument_list; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:current_y; 170, binary_operator:+; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:current_x; 174, integer:1; 175, identifier:accessible; 176, block; 176, 177; 176, 183; 177, expression_statement; 177, 178; 178, augmented_assignment:+=; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:current_x; 182, integer:1; 183, ERROR; 183, 184; 183, 187; 183, 188; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:lg_mv; 187, integer:3; 188, comparison_operator:==; 188, 189; 188, 198; 189, binary_operator:+; 189, 190; 189, 193; 189, 197; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:name; 193, ERROR; 193, 194; 193, 195; 193, 196; 194, identifier:move; 195, identifier:return; 196, identifier:elif; 197, identifier:x; 198, unary_operator:-; 198, 199; 199, integer:1; 200, if_statement; 200, 201; 200, 218; 201, comparison_operator:in; 201, 202; 201, 217; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:grd; 207, identifier:get_tile; 208, argument_list; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:current_y; 212, binary_operator:-; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:current_x; 216, integer:1; 217, identifier:accessible; 218, block; 218, 219; 218, 225; 219, expression_statement; 219, 220; 220, augmented_assignment:-=; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:current_x; 224, integer:1; 225, ERROR; 225, 226; 225, 229; 225, 230; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:lg_mv; 229, integer:3; 230, comparison_operator:==; 230, 231; 230, 240; 231, binary_operator:+; 231, 232; 231, 235; 231, 239; 232, attribute; 232, 233; 232, 234; 233, identifier:self; 234, identifier:name; 235, ERROR; 235, 236; 235, 237; 235, 238; 236, identifier:move; 237, identifier:return; 238, identifier:elif; 239, identifier:y; 240, integer:1; 241, if_statement; 241, 242; 241, 259; 242, comparison_operator:in; 242, 243; 242, 258; 243, call; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:grd; 248, identifier:get_tile; 249, argument_list; 249, 250; 249, 255; 250, binary_operator:+; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:current_y; 254, integer:1; 255, attribute; 255, 256; 255, 257; 256, identifier:self; 257, identifier:current_x; 258, identifier:accessible; 259, block; 259, 260; 259, 266; 260, expression_statement; 260, 261; 261, augmented_assignment:+=; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:current_y; 265, integer:1; 266, ERROR; 266, 267; 266, 270; 266, 271; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:lg_mv; 270, integer:3; 271, comparison_operator:==; 271, 272; 271, 281; 272, binary_operator:+; 272, 273; 272, 276; 272, 280; 273, attribute; 273, 274; 273, 275; 274, identifier:self; 275, identifier:name; 276, ERROR; 276, 277; 276, 278; 276, 279; 277, identifier:move; 278, identifier:return; 279, identifier:elif; 280, identifier:y; 281, unary_operator:-; 281, 282; 282, integer:1; 283, if_statement; 283, 284; 283, 301; 284, comparison_operator:in; 284, 285; 284, 300; 285, call; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:grd; 290, identifier:get_tile; 291, argument_list; 291, 292; 291, 297; 292, binary_operator:-; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:self; 295, identifier:current_y; 296, integer:1; 297, attribute; 297, 298; 297, 299; 298, identifier:self; 299, identifier:current_x; 300, identifier:accessible; 301, block; 301, 302; 301, 308; 302, expression_statement; 302, 303; 303, augmented_assignment:-=; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:current_y; 307, integer:1; 308, ERROR; 308, 309; 308, 312; 308, 313; 309, attribute; 309, 310; 309, 311; 310, identifier:self; 311, identifier:lg_mv; 312, integer:3; 313, binary_operator:+; 313, 314; 313, 317; 313, 319; 314, attribute; 314, 315; 314, 316; 315, identifier:self; 316, identifier:name; 317, ERROR; 317, 318; 318, identifier:move; 319, call; 319, 320; 319, 342; 320, attribute; 320, 321; 320, 341; 321, attribute; 321, 322; 321, 338; 321, 340; 322, call; 322, 323; 322, 330; 323, attribute; 323, 324; 323, 329; 324, attribute; 324, 325; 324, 326; 324, 328; 325, identifier:return; 326, ERROR; 326, 327; 327, identifier:self; 328, identifier:grd; 329, identifier:set_tile; 330, argument_list; 330, 331; 330, 334; 330, 337; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:start_y; 334, attribute; 334, 335; 334, 336; 335, identifier:self; 336, identifier:start_x; 337, string:'A'; 338, ERROR; 338, 339; 339, identifier:self; 340, identifier:grd; 341, identifier:save; 342, argument_list; 342, 343; 343, call; 343, 344; 343, 349; 344, attribute; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:os; 347, identifier:path; 348, identifier:join; 349, argument_list; 349, 350; 349, 355; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:os; 353, identifier:getcwd; 354, argument_list; 355, string:'agent.txt'
def do_your_job(self): y,x = self.get_intended_direction() if self.target_x == self.current_x and self.target_y == self.current_y: if len(self.results) == 0: self.results.append("TARGET ACQUIRED") self.lg_mv(2, self.name + ": TARGET ACQUIRED" ) return self.num_steps += 1 accessible = ['\\', '-', '|', '/', '.'] if y != 0 and x != 0 and self.backtrack == [0,0]: if random.randint(1,10) > 6: if self.grd.get_tile(self.current_y + y, self.current_x) in accessible: self.current_y += y self.lg_mv(3, self.name + ": randomly moving Y axis " + str(self.num_steps) ) return if x == 1: if self.grd.get_tile(self.current_y, self.current_x + 1) in accessible: self.current_x += 1 self.lg_mv(3, self.name + ": move return elif x == -1: if self.grd.get_tile(self.current_y, self.current_x - 1) in accessible: self.current_x -= 1 self.lg_mv(3, self.name + ": move return elif y == 1: if self.grd.get_tile(self.current_y + 1, self.current_x) in accessible: self.current_y += 1 self.lg_mv(3, self.name + ": move return elif y == -1: if self.grd.get_tile(self.current_y - 1, self.current_x) in accessible: self.current_y -= 1 self.lg_mv(3, self.name + ": move return self.grd.set_tile(self.start_y, self.start_x, 'A') self.grd.save(os.path.join(os.getcwd(), 'agent.txt'))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:save_filelist; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:opFile; 6, identifier:opFormat; 7, default_parameter; 7, 8; 7, 9; 8, identifier:delim; 9, string:','; 10, default_parameter; 10, 11; 10, 12; 11, identifier:qu; 12, string:'"'; 13, block; 13, 14; 13, 25; 13, 48; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:op_folder; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:os; 21, identifier:path; 22, identifier:dirname; 23, argument_list; 23, 24; 24, identifier:opFile; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:op_folder; 28, None; 29, block; 29, 30; 30, if_statement; 30, 31; 30, 40; 31, not_operator; 31, 32; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:os; 36, identifier:path; 37, identifier:exists; 38, argument_list; 38, 39; 39, identifier:op_folder; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:os; 45, identifier:makedirs; 46, argument_list; 46, 47; 47, identifier:op_folder; 48, with_statement; 48, 49; 48, 59; 49, with_clause; 49, 50; 50, with_item; 50, 51; 51, as_pattern; 51, 52; 51, 57; 52, call; 52, 53; 52, 54; 53, identifier:open; 54, argument_list; 54, 55; 54, 56; 55, identifier:opFile; 56, string:'w'; 57, as_pattern_target; 57, 58; 58, identifier:fout; 59, block; 59, 60; 59, 69; 59, 82; 59, 89; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:fout; 64, identifier:write; 65, argument_list; 65, 66; 66, binary_operator:+; 66, 67; 66, 68; 67, string:"fullFilename"; 68, identifier:delim; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:colHeading; 71, identifier:opFormat; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:fout; 77, identifier:write; 78, argument_list; 78, 79; 79, binary_operator:+; 79, 80; 79, 81; 80, identifier:colHeading; 81, identifier:delim; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:fout; 86, identifier:write; 87, argument_list; 87, 88; 88, string:'\n'; 89, for_statement; 89, 90; 89, 91; 89, 94; 90, identifier:f; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:filelist; 94, block; 94, 95; 94, 105; 94, 215; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:line; 98, binary_operator:+; 98, 99; 98, 104; 99, binary_operator:+; 99, 100; 99, 103; 100, binary_operator:+; 100, 101; 100, 102; 101, identifier:qu; 102, identifier:f; 103, identifier:qu; 104, identifier:delim; 105, try_statement; 105, 106; 105, 208; 106, block; 106, 107; 107, for_statement; 107, 108; 107, 109; 107, 110; 108, identifier:fld; 109, identifier:opFormat; 110, block; 110, 111; 110, 135; 110, 157; 110, 184; 111, if_statement; 111, 112; 111, 115; 112, comparison_operator:==; 112, 113; 112, 114; 113, identifier:fld; 114, string:"name"; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:line; 119, binary_operator:+; 119, 120; 119, 134; 120, binary_operator:+; 120, 121; 120, 133; 121, binary_operator:+; 121, 122; 121, 125; 122, binary_operator:+; 122, 123; 122, 124; 123, identifier:line; 124, identifier:qu; 125, call; 125, 126; 125, 131; 126, attribute; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:os; 129, identifier:path; 130, identifier:basename; 131, argument_list; 131, 132; 132, identifier:f; 133, identifier:qu; 134, identifier:delim; 135, if_statement; 135, 136; 135, 139; 136, comparison_operator:==; 136, 137; 136, 138; 137, identifier:fld; 138, string:"date"; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:line; 143, binary_operator:+; 143, 144; 143, 156; 144, binary_operator:+; 144, 145; 144, 155; 145, binary_operator:+; 145, 146; 145, 149; 146, binary_operator:+; 146, 147; 146, 148; 147, identifier:line; 148, identifier:qu; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:GetDateAsString; 153, argument_list; 153, 154; 154, identifier:f; 155, identifier:qu; 156, identifier:delim; 157, if_statement; 157, 158; 157, 161; 158, comparison_operator:==; 158, 159; 158, 160; 159, identifier:fld; 160, string:"size"; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:line; 165, binary_operator:+; 165, 166; 165, 183; 166, binary_operator:+; 166, 167; 166, 182; 167, binary_operator:+; 167, 168; 167, 171; 168, binary_operator:+; 168, 169; 168, 170; 169, identifier:line; 170, identifier:qu; 171, call; 171, 172; 171, 173; 172, identifier:str; 173, argument_list; 173, 174; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:os; 178, identifier:path; 179, identifier:getsize; 180, argument_list; 180, 181; 181, identifier:f; 182, identifier:qu; 183, identifier:delim; 184, if_statement; 184, 185; 184, 188; 185, comparison_operator:==; 185, 186; 185, 187; 186, identifier:fld; 187, string:"path"; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:line; 192, binary_operator:+; 192, 193; 192, 207; 193, binary_operator:+; 193, 194; 193, 206; 194, binary_operator:+; 194, 195; 194, 198; 195, binary_operator:+; 195, 196; 195, 197; 196, identifier:line; 197, identifier:qu; 198, call; 198, 199; 198, 204; 199, attribute; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:os; 202, identifier:path; 203, identifier:dirname; 204, argument_list; 204, 205; 205, identifier:f; 206, identifier:qu; 207, identifier:delim; 208, except_clause; 208, 209; 208, 210; 209, identifier:IOError; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, augmented_assignment:+=; 212, 213; 212, 214; 213, identifier:line; 214, string:'\n'; 215, try_statement; 215, 216; 215, 245; 216, block; 216, 217; 216, 238; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:fout; 221, identifier:write; 222, argument_list; 222, 223; 223, call; 223, 224; 223, 225; 224, identifier:str; 225, argument_list; 225, 226; 226, call; 226, 227; 226, 236; 227, attribute; 227, 228; 227, 235; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:line; 231, identifier:encode; 232, argument_list; 232, 233; 232, 234; 233, string:'ascii'; 234, string:'ignore'; 235, identifier:decode; 236, argument_list; 236, 237; 237, string:'utf-8'; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:fout; 242, identifier:write; 243, argument_list; 243, 244; 244, string:'\n'; 245, except_clause; 245, 246; 245, 247; 246, identifier:IOError; 247, block; 247, 248; 248, pass_statement
def save_filelist(self, opFile, opFormat, delim=',', qu='"'): op_folder = os.path.dirname(opFile) if op_folder is not None: if not os.path.exists(op_folder): os.makedirs(op_folder) with open(opFile,'w') as fout: fout.write("fullFilename" + delim) for colHeading in opFormat: fout.write(colHeading + delim) fout.write('\n') for f in self.filelist: line = qu + f + qu + delim try: for fld in opFormat: if fld == "name": line = line + qu + os.path.basename(f) + qu + delim if fld == "date": line = line + qu + self.GetDateAsString(f) + qu + delim if fld == "size": line = line + qu + str(os.path.getsize(f)) + qu + delim if fld == "path": line = line + qu + os.path.dirname(f) + qu + delim except IOError: line += '\n' try: fout.write (str(line.encode('ascii', 'ignore').decode('utf-8'))) fout.write ('\n') except IOError: pass
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:type; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:variant_probe_coverages; 6, default_parameter; 6, 7; 6, 8; 7, identifier:variant; 8, None; 9, block; 9, 10; 9, 23; 9, 27; 9, 44; 9, 61; 9, 78; 10, if_statement; 10, 11; 10, 17; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:isinstance; 14, argument_list; 14, 15; 14, 16; 15, identifier:variant_probe_coverages; 16, identifier:list; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:variant_probe_coverages; 21, list:[variant_probe_coverages]; 21, 22; 22, identifier:variant_probe_coverages; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:calls; 26, list:[]; 27, for_statement; 27, 28; 27, 29; 27, 30; 28, identifier:variant_probe_coverage; 29, identifier:variant_probe_coverages; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:calls; 35, identifier:append; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_type_variant_probe_coverages; 41, argument_list; 41, 42; 41, 43; 42, identifier:variant_probe_coverage; 43, identifier:variant; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:hom_alt_calls; 47, list_comprehension; 47, 48; 47, 49; 47, 52; 48, identifier:c; 49, for_in_clause; 49, 50; 49, 51; 50, identifier:c; 51, identifier:calls; 52, if_clause; 52, 53; 53, comparison_operator:>; 53, 54; 53, 60; 54, call; 54, 55; 54, 56; 55, identifier:sum; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:c; 59, string:"genotype"; 60, integer:1; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:het_calls; 64, list_comprehension; 64, 65; 64, 66; 64, 69; 65, identifier:c; 66, for_in_clause; 66, 67; 66, 68; 67, identifier:c; 68, identifier:calls; 69, if_clause; 69, 70; 70, comparison_operator:==; 70, 71; 70, 77; 71, call; 71, 72; 71, 73; 72, identifier:sum; 73, argument_list; 73, 74; 74, subscript; 74, 75; 74, 76; 75, identifier:c; 76, string:"genotype"; 77, integer:1; 78, if_statement; 78, 79; 78, 80; 78, 104; 78, 130; 79, identifier:hom_alt_calls; 80, block; 80, 81; 80, 100; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:hom_alt_calls; 85, identifier:sort; 86, argument_list; 86, 87; 86, 97; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:key; 89, lambda; 89, 90; 89, 92; 90, lambda_parameters; 90, 91; 91, identifier:x; 92, subscript; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:x; 95, string:"info"; 96, string:"conf"; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:reverse; 99, True; 100, return_statement; 100, 101; 101, subscript; 101, 102; 101, 103; 102, identifier:hom_alt_calls; 103, integer:0; 104, elif_clause; 104, 105; 104, 106; 105, identifier:het_calls; 106, block; 106, 107; 106, 126; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:het_calls; 111, identifier:sort; 112, argument_list; 112, 113; 112, 123; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:key; 115, lambda; 115, 116; 115, 118; 116, lambda_parameters; 116, 117; 117, identifier:x; 118, subscript; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:x; 121, string:"info"; 122, string:"conf"; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:reverse; 125, True; 126, return_statement; 126, 127; 127, subscript; 127, 128; 127, 129; 128, identifier:het_calls; 129, integer:0; 130, else_clause; 130, 131; 131, block; 131, 132; 131, 151; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:calls; 136, identifier:sort; 137, argument_list; 137, 138; 137, 148; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:key; 140, lambda; 140, 141; 140, 143; 141, lambda_parameters; 141, 142; 142, identifier:x; 143, subscript; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:x; 146, string:"info"; 147, string:"conf"; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:reverse; 150, True; 151, return_statement; 151, 152; 152, subscript; 152, 153; 152, 154; 153, identifier:calls; 154, integer:0
def type(self, variant_probe_coverages, variant=None): if not isinstance(variant_probe_coverages, list): variant_probe_coverages = [variant_probe_coverages] calls = [] for variant_probe_coverage in variant_probe_coverages: calls.append( self._type_variant_probe_coverages( variant_probe_coverage, variant)) hom_alt_calls = [c for c in calls if sum(c["genotype"]) > 1] het_calls = [c for c in calls if sum(c["genotype"]) == 1] if hom_alt_calls: hom_alt_calls.sort(key=lambda x: x["info"]["conf"], reverse=True) return hom_alt_calls[0] elif het_calls: het_calls.sort(key=lambda x: x["info"]["conf"], reverse=True) return het_calls[0] else: calls.sort(key=lambda x: x["info"]["conf"], reverse=True) return calls[0]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:process; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:versions; 6, block; 6, 7; 7, for_statement; 7, 8; 7, 9; 7, 17; 8, identifier:tool_name; 9, call; 9, 10; 9, 11; 10, identifier:sorted; 11, argument_list; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:versions; 15, identifier:keys; 16, argument_list; 17, block; 17, 18; 17, 24; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:version; 21, subscript; 21, 22; 21, 23; 22, identifier:versions; 23, identifier:tool_name; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_log; 29, argument_list; 29, 30; 30, binary_operator:%; 30, 31; 30, 32; 31, string:"Using tool '%s', %s"; 32, tuple; 32, 33; 32, 34; 33, identifier:tool_name; 34, identifier:version
def process(self, versions): for tool_name in sorted(versions.keys()): version = versions[tool_name] self._log("Using tool '%s', %s" % (tool_name, version))