sequence
stringlengths
546
16.2k
code
stringlengths
108
19.3k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:check_base_suggested_attributes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:dataset; 6, block; 6, 7; 6, 9; 6, 19; 6, 20; 6, 29; 6, 39; 6, 48; 6, 74; 6, 75; 6, 124; 6, 137; 6, 152; 6, 165; 6, 180; 6, 189; 6, 198; 6, 207; 6, 216; 6, 226; 6, 242; 6, 252; 6, 268; 7, expression_statement; 7, 8; 8, string:''' Check the global suggested attributes for 2.0 templates. These go an extra step besides just checking that they exist. :param netCDF4.Dataset dataset: An open netCDF dataset :creator_type = "" ; //........................................ SUGGESTED - Specifies type of creator with one of the following: 'person', 'group', 'institution', or 'position'. (ACDD) :creator_institution = "" ; //................................. SUGGESTED - The institution of the creator; should uniquely identify the creator's institution. (ACDD) :publisher_type = "" ; //...................................... SUGGESTED - Specifies type of publisher with one of the following: 'person', 'group', 'institution', or 'position'. (ACDD) :publisher_institution = "" ; //............................... SUGGESTED - The institution that presented the data file or equivalent product to users; should uniquely identify the institution. (ACDD) :program = "" ; //............................................. SUGGESTED - The overarching program(s) of which the dataset is a part. (ACDD) :contributor_name = "" ; //.................................... SUGGESTED - The name of any individuals, projects, or institutions that contributed to the creation of this data. (ACDD) :contributor_role = "" ; //.................................... SUGGESTED - The role of any individuals, projects, or institutions that contributed to the creation of this data. (ACDD) :geospatial_lat_units = "degrees_north" ; //.................. SUGGESTED - Units for the latitude axis described in "geospatial_lat_min" and "geospatial_lat_max" attributes. Use UDUNITS compatible units. (ACDD) :geospatial_lon_units = "degrees_east"; //..................... SUGGESTED - Units for the longitude axis described in "geospatial_lon_min" and "geospatial_lon_max" attributes. Use UDUNITS compatible units. (ACDD) :geospatial_vertical_units = "" ; //........................... SUGGESTED - Units for the vertical axis described in "geospatial_vertical_min" and "geospatial_vertical_max" attributes. The default is EPSG:4979. (ACDD) :date_modified = "" ; //....................................... SUGGESTED - The date on which the data was last modified. Note that this applies just to the data, not the metadata. Use ISO 8601:2004 for date and time. (ACDD) :date_issued = "" ; //......................................... SUGGESTED - The date on which this data (including all modifications) was formally issued (i.e., made available to a wider audience). Note that these apply just to the data, not the metadata. Use ISO 8601:2004 for date and time. (ACDD) :date_metadata_modified = "" ; //.............................. SUGGESTED - The date on which the metadata was last modified. Use ISO 8601:2004 for date and time. (ACDD) :product_version = "" ; //..................................... SUGGESTED - Version identifier of the data file or product as assigned by the data creator. (ACDD) :keywords_vocabulary = "" ; //................................. SUGGESTED - Identifies the controlled keyword vocabulary used to specify the values within the attribute "keywords". Example: 'GCMD:GCMD Keywords' ACDD) :platform = "" ; //............................................ SUGGESTED - Name of the platform(s) that supported the sensor data used to create this data set or product. Platforms can be of any type, including satellite, ship, station, aircraft or other. (ACDD) :platform_vocabulary = "" ; //................................. SUGGESTED - Controlled vocabulary for the names used in the "platform" attribute . Example: ‘NASA/GCMD Platform Keywords Version 8.1’ (ACDD) :instrument = "" ; //.......................................... SUGGESTED - Name of the contributing instrument(s) or sensor(s) used to create this data set or product. (ACDD) :instrument_vocabulary = "" ; //............................... SUGGESTED - Controlled vocabulary for the names used in the "instrument" attribute. Example: ‘NASA/GCMD Instrument Keywords Version 8.1’ (ACDD) :cdm_data_type = "Point" ; //.................................. SUGGESTED - The data type, as derived from Unidata's Common Data Model Scientific Data types and understood by THREDDS. (ACDD) :metadata_link = "" ; //....................................... SUGGESTED - A URL that gives the location of more complete metadata. A persistent URL is recommended for this attribute. (ACDD) :references = "" ; //.......................................... SUGGESTED - Published or web-based references that describe the data or methods used to produce it. Recommend URIs (such as a URL or DOI) for papers or other references. (CF) '''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:suggested_ctx; 12, call; 12, 13; 12, 14; 13, identifier:TestCtx; 14, argument_list; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:BaseCheck; 17, identifier:LOW; 18, string:'Suggested global attributes'; 19, comment; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:platform_name; 23, call; 23, 24; 23, 25; 24, identifier:getattr; 25, argument_list; 25, 26; 25, 27; 25, 28; 26, identifier:dataset; 27, string:'platform'; 28, string:''; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:suggested_ctx; 33, identifier:assert_true; 34, argument_list; 34, 35; 34, 38; 35, comparison_operator:!=; 35, 36; 35, 37; 36, identifier:platform_name; 37, string:''; 38, string:'platform should exist and point to a term in :platform_vocabulary.'; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:cdm_data_type; 42, call; 42, 43; 42, 44; 43, identifier:getattr; 44, argument_list; 44, 45; 44, 46; 44, 47; 45, identifier:dataset; 46, string:'cdm_data_type'; 47, string:''; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:suggested_ctx; 52, identifier:assert_true; 53, argument_list; 53, 54; 53, 68; 54, comparison_operator:in; 54, 55; 54, 60; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:cdm_data_type; 58, identifier:lower; 59, argument_list; 60, list:['grid', 'image', 'point', 'radial', 'station', 'swath', 'trajectory']; 60, 61; 60, 62; 60, 63; 60, 64; 60, 65; 60, 66; 60, 67; 61, string:'grid'; 62, string:'image'; 63, string:'point'; 64, string:'radial'; 65, string:'station'; 66, string:'swath'; 67, string:'trajectory'; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, string:'cdm_data_type must be one of Grid, Image, Point, Radial, Station, Swath, Trajectory: {}'; 71, identifier:format; 72, argument_list; 72, 73; 73, identifier:cdm_data_type; 74, comment; 75, for_statement; 75, 76; 75, 77; 75, 81; 76, identifier:attr; 77, list:['date_modified', 'date_issued', 'date_metadata_modified']; 77, 78; 77, 79; 77, 80; 78, string:'date_modified'; 79, string:'date_issued'; 80, string:'date_metadata_modified'; 81, block; 81, 82; 81, 91; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:attr_value; 85, call; 85, 86; 85, 87; 86, identifier:getattr; 87, argument_list; 87, 88; 87, 89; 87, 90; 88, identifier:dataset; 89, identifier:attr; 90, string:''; 91, try_statement; 91, 92; 91, 107; 92, block; 92, 93; 92, 98; 92, 106; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:parse_datetime; 96, argument_list; 96, 97; 97, identifier:attr_value; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:suggested_ctx; 102, identifier:assert_true; 103, argument_list; 103, 104; 103, 105; 104, True; 105, string:''; 106, comment; 107, except_clause; 107, 108; 107, 109; 108, identifier:ISO8601Error; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:suggested_ctx; 114, identifier:assert_true; 115, argument_list; 115, 116; 115, 117; 116, False; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, string:'{} should exist and be ISO-8601 format (example: PT1M30S), currently: {}'; 120, identifier:format; 121, argument_list; 121, 122; 121, 123; 122, identifier:attr; 123, identifier:attr_value; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:units; 127, call; 127, 128; 127, 136; 128, attribute; 128, 129; 128, 135; 129, call; 129, 130; 129, 131; 130, identifier:getattr; 131, argument_list; 131, 132; 131, 133; 131, 134; 132, identifier:dataset; 133, string:'geospatial_lat_units'; 134, string:''; 135, identifier:lower; 136, argument_list; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:suggested_ctx; 141, identifier:assert_true; 142, argument_list; 142, 143; 142, 146; 143, comparison_operator:==; 143, 144; 143, 145; 144, identifier:units; 145, string:'degrees_north'; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, string:'geospatial_lat_units attribute should be degrees_north: {}'; 149, identifier:format; 150, argument_list; 150, 151; 151, identifier:units; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:units; 155, call; 155, 156; 155, 164; 156, attribute; 156, 157; 156, 163; 157, call; 157, 158; 157, 159; 158, identifier:getattr; 159, argument_list; 159, 160; 159, 161; 159, 162; 160, identifier:dataset; 161, string:'geospatial_lon_units'; 162, string:''; 163, identifier:lower; 164, argument_list; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:suggested_ctx; 169, identifier:assert_true; 170, argument_list; 170, 171; 170, 174; 171, comparison_operator:==; 171, 172; 171, 173; 172, identifier:units; 173, string:'degrees_east'; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, string:'geospatial_lon_units attribute should be degrees_east: {}'; 177, identifier:format; 178, argument_list; 178, 179; 179, identifier:units; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:contributor_name; 183, call; 183, 184; 183, 185; 184, identifier:getattr; 185, argument_list; 185, 186; 185, 187; 185, 188; 186, identifier:dataset; 187, string:'contributor_name'; 188, string:''; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:contributor_role; 192, call; 192, 193; 192, 194; 193, identifier:getattr; 194, argument_list; 194, 195; 194, 196; 194, 197; 195, identifier:dataset; 196, string:'contributor_role'; 197, string:''; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:names; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:contributor_role; 204, identifier:split; 205, argument_list; 205, 206; 206, string:','; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:roles; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:contributor_role; 213, identifier:split; 214, argument_list; 214, 215; 215, string:','; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:suggested_ctx; 220, identifier:assert_true; 221, argument_list; 221, 222; 221, 225; 222, comparison_operator:!=; 222, 223; 222, 224; 223, identifier:contributor_name; 224, string:''; 225, string:'contributor_name should exist and not be empty.'; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:suggested_ctx; 230, identifier:assert_true; 231, argument_list; 231, 232; 231, 241; 232, comparison_operator:==; 232, 233; 232, 237; 233, call; 233, 234; 233, 235; 234, identifier:len; 235, argument_list; 235, 236; 236, identifier:names; 237, call; 237, 238; 237, 239; 238, identifier:len; 239, argument_list; 239, 240; 240, identifier:roles; 241, string:'length of contributor names matches length of roles'; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:suggested_ctx; 246, identifier:assert_true; 247, argument_list; 247, 248; 247, 251; 248, comparison_operator:!=; 248, 249; 248, 250; 249, identifier:contributor_role; 250, string:''; 251, string:'contributor_role should exist and not be empty.'; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:suggested_ctx; 256, identifier:assert_true; 257, argument_list; 257, 258; 257, 267; 258, comparison_operator:==; 258, 259; 258, 263; 259, call; 259, 260; 259, 261; 260, identifier:len; 261, argument_list; 261, 262; 262, identifier:names; 263, call; 263, 264; 263, 265; 264, identifier:len; 265, argument_list; 265, 266; 266, identifier:roles; 267, string:'length of contributor names matches length of roles'; 268, return_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:suggested_ctx; 272, identifier:to_result; 273, argument_list
def check_base_suggested_attributes(self, dataset): ''' Check the global suggested attributes for 2.0 templates. These go an extra step besides just checking that they exist. :param netCDF4.Dataset dataset: An open netCDF dataset :creator_type = "" ; //........................................ SUGGESTED - Specifies type of creator with one of the following: 'person', 'group', 'institution', or 'position'. (ACDD) :creator_institution = "" ; //................................. SUGGESTED - The institution of the creator; should uniquely identify the creator's institution. (ACDD) :publisher_type = "" ; //...................................... SUGGESTED - Specifies type of publisher with one of the following: 'person', 'group', 'institution', or 'position'. (ACDD) :publisher_institution = "" ; //............................... SUGGESTED - The institution that presented the data file or equivalent product to users; should uniquely identify the institution. (ACDD) :program = "" ; //............................................. SUGGESTED - The overarching program(s) of which the dataset is a part. (ACDD) :contributor_name = "" ; //.................................... SUGGESTED - The name of any individuals, projects, or institutions that contributed to the creation of this data. (ACDD) :contributor_role = "" ; //.................................... SUGGESTED - The role of any individuals, projects, or institutions that contributed to the creation of this data. (ACDD) :geospatial_lat_units = "degrees_north" ; //.................. SUGGESTED - Units for the latitude axis described in "geospatial_lat_min" and "geospatial_lat_max" attributes. Use UDUNITS compatible units. (ACDD) :geospatial_lon_units = "degrees_east"; //..................... SUGGESTED - Units for the longitude axis described in "geospatial_lon_min" and "geospatial_lon_max" attributes. Use UDUNITS compatible units. (ACDD) :geospatial_vertical_units = "" ; //........................... SUGGESTED - Units for the vertical axis described in "geospatial_vertical_min" and "geospatial_vertical_max" attributes. The default is EPSG:4979. (ACDD) :date_modified = "" ; //....................................... SUGGESTED - The date on which the data was last modified. Note that this applies just to the data, not the metadata. Use ISO 8601:2004 for date and time. (ACDD) :date_issued = "" ; //......................................... SUGGESTED - The date on which this data (including all modifications) was formally issued (i.e., made available to a wider audience). Note that these apply just to the data, not the metadata. Use ISO 8601:2004 for date and time. (ACDD) :date_metadata_modified = "" ; //.............................. SUGGESTED - The date on which the metadata was last modified. Use ISO 8601:2004 for date and time. (ACDD) :product_version = "" ; //..................................... SUGGESTED - Version identifier of the data file or product as assigned by the data creator. (ACDD) :keywords_vocabulary = "" ; //................................. SUGGESTED - Identifies the controlled keyword vocabulary used to specify the values within the attribute "keywords". Example: 'GCMD:GCMD Keywords' ACDD) :platform = "" ; //............................................ SUGGESTED - Name of the platform(s) that supported the sensor data used to create this data set or product. Platforms can be of any type, including satellite, ship, station, aircraft or other. (ACDD) :platform_vocabulary = "" ; //................................. SUGGESTED - Controlled vocabulary for the names used in the "platform" attribute . Example: ‘NASA/GCMD Platform Keywords Version 8.1’ (ACDD) :instrument = "" ; //.......................................... SUGGESTED - Name of the contributing instrument(s) or sensor(s) used to create this data set or product. (ACDD) :instrument_vocabulary = "" ; //............................... SUGGESTED - Controlled vocabulary for the names used in the "instrument" attribute. Example: ‘NASA/GCMD Instrument Keywords Version 8.1’ (ACDD) :cdm_data_type = "Point" ; //.................................. SUGGESTED - The data type, as derived from Unidata's Common Data Model Scientific Data types and understood by THREDDS. (ACDD) :metadata_link = "" ; //....................................... SUGGESTED - A URL that gives the location of more complete metadata. A persistent URL is recommended for this attribute. (ACDD) :references = "" ; //.......................................... SUGGESTED - Published or web-based references that describe the data or methods used to produce it. Recommend URIs (such as a URL or DOI) for papers or other references. (CF) ''' suggested_ctx = TestCtx(BaseCheck.LOW, 'Suggested global attributes') # Do any of the variables define platform ? platform_name = getattr(dataset, 'platform', '') suggested_ctx.assert_true(platform_name != '', 'platform should exist and point to a term in :platform_vocabulary.') cdm_data_type = getattr(dataset, 'cdm_data_type', '') suggested_ctx.assert_true(cdm_data_type.lower() in ['grid', 'image', 'point', 'radial', 'station', 'swath', 'trajectory'], 'cdm_data_type must be one of Grid, Image, Point, Radial, Station, Swath, Trajectory: {}'.format(cdm_data_type)) # Parse dates, check for ISO 8601 for attr in ['date_modified', 'date_issued', 'date_metadata_modified']: attr_value = getattr(dataset, attr, '') try: parse_datetime(attr_value) suggested_ctx.assert_true(True, '') # Score it True! except ISO8601Error: suggested_ctx.assert_true(False, '{} should exist and be ISO-8601 format (example: PT1M30S), currently: {}'.format(attr, attr_value)) units = getattr(dataset, 'geospatial_lat_units', '').lower() suggested_ctx.assert_true(units == 'degrees_north', 'geospatial_lat_units attribute should be degrees_north: {}'.format(units)) units = getattr(dataset, 'geospatial_lon_units', '').lower() suggested_ctx.assert_true(units == 'degrees_east', 'geospatial_lon_units attribute should be degrees_east: {}'.format(units)) contributor_name = getattr(dataset, 'contributor_name', '') contributor_role = getattr(dataset, 'contributor_role', '') names = contributor_role.split(',') roles = contributor_role.split(',') suggested_ctx.assert_true(contributor_name != '', 'contributor_name should exist and not be empty.') suggested_ctx.assert_true(len(names) == len(roles), 'length of contributor names matches length of roles') suggested_ctx.assert_true(contributor_role != '', 'contributor_role should exist and not be empty.') suggested_ctx.assert_true(len(names) == len(roles), 'length of contributor names matches length of roles') return suggested_ctx.to_result()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:load_from_args_as_dataframe; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 8; 5, 21; 5, 58; 5, 67; 5, 71; 5, 185; 5, 281; 5, 290; 5, 313; 5, 323; 5, 346; 5, 365; 5, 366; 5, 388; 5, 410; 5, 425; 5, 454; 6, expression_statement; 6, 7; 7, string:''' Given parsed variant-loading arguments, return a pandas DataFrame. If no variant loading arguments are specified, return None. '''; 8, if_statement; 8, 9; 8, 18; 9, boolean_operator:and; 9, 10; 9, 14; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:args; 13, identifier:variants; 14, not_operator; 14, 15; 15, attribute; 15, 16; 15, 17; 16, identifier:args; 17, identifier:single_variant; 18, block; 18, 19; 19, return_statement; 19, 20; 20, None; 21, if_statement; 21, 22; 21, 25; 21, 45; 22, attribute; 22, 23; 22, 24; 23, identifier:args; 24, identifier:variant_source_name; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:variant_source_names; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:util; 32, identifier:expand; 33, argument_list; 33, 34; 33, 37; 33, 38; 33, 39; 34, attribute; 34, 35; 34, 36; 35, identifier:args; 36, identifier:variant_source_name; 37, string:'variant_source_name'; 38, string:'variant source'; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, attribute; 42, 43; 42, 44; 43, identifier:args; 44, identifier:variants; 45, else_clause; 45, 46; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:variant_source_names; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:util; 53, identifier:drop_prefix; 54, argument_list; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:args; 57, identifier:variants; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:variant_to_sources; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:collections; 64, identifier:defaultdict; 65, argument_list; 65, 66; 66, identifier:list; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:dfs; 70, list:[]; 71, for_statement; 71, 72; 71, 73; 71, 82; 72, identifier:i; 73, call; 73, 74; 73, 75; 74, identifier:range; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:len; 78, argument_list; 78, 79; 79, attribute; 79, 80; 79, 81; 80, identifier:args; 81, identifier:variants; 82, block; 82, 83; 82, 89; 82, 106; 82, 139; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:name; 86, subscript; 86, 87; 86, 88; 87, identifier:variant_source_names; 88, identifier:i; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:prefix; 92, parenthesized_expression; 92, 93; 93, conditional_expression:if; 93, 94; 93, 95; 93, 103; 94, string:'metadata:'; 95, comparison_operator:==; 95, 96; 95, 102; 96, call; 96, 97; 96, 98; 97, identifier:len; 98, argument_list; 98, 99; 99, attribute; 99, 100; 99, 101; 100, identifier:args; 101, identifier:variants; 102, integer:1; 103, binary_operator:%; 103, 104; 103, 105; 104, string:"metadata:%s:"; 105, identifier:name; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:df; 109, call; 109, 110; 109, 111; 110, identifier:load_as_dataframe; 111, argument_list; 111, 112; 111, 117; 111, 120; 111, 125; 111, 130; 111, 136; 112, subscript; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:args; 115, identifier:variants; 116, identifier:i; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:name; 119, identifier:name; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:genome; 122, attribute; 122, 123; 122, 124; 123, identifier:args; 124, identifier:genome; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:max_variants; 127, attribute; 127, 128; 127, 129; 128, identifier:args; 129, identifier:max_variants_per_source; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:only_passing; 132, not_operator; 132, 133; 133, attribute; 133, 134; 133, 135; 134, identifier:args; 135, identifier:include_failing_variants; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:metadata_column_prefix; 138, identifier:prefix; 139, if_statement; 139, 140; 139, 147; 139, 161; 140, comparison_operator:==; 140, 141; 140, 146; 141, subscript; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:df; 144, identifier:shape; 145, integer:0; 146, integer:0; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:logging; 152, identifier:warn; 153, argument_list; 153, 154; 154, binary_operator:%; 154, 155; 154, 156; 155, string:"No variants loaded from: %s"; 156, subscript; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:args; 159, identifier:variants; 160, identifier:i; 161, else_clause; 161, 162; 162, block; 162, 163; 162, 178; 163, for_statement; 163, 164; 163, 165; 163, 168; 164, identifier:variant; 165, attribute; 165, 166; 165, 167; 166, identifier:df; 167, identifier:variant; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:variant_to_sources; 174, identifier:variant; 175, identifier:append; 176, argument_list; 176, 177; 177, identifier:name; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:dfs; 182, identifier:append; 183, argument_list; 183, 184; 184, identifier:df; 185, if_statement; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:args; 188, identifier:single_variant; 189, block; 189, 190; 189, 194; 189, 198; 189, 219; 189, 271; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:variants; 193, list:[]; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:extra_args; 197, dictionary; 198, if_statement; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:args; 201, identifier:genome; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:extra_args; 206, dictionary; 206, 207; 207, pair; 207, 208; 207, 209; 208, string:'ensembl'; 209, call; 209, 210; 209, 215; 210, attribute; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:varcode; 213, identifier:reference; 214, identifier:infer_genome; 215, argument_list; 215, 216; 216, attribute; 216, 217; 216, 218; 217, identifier:args; 218, identifier:genome; 219, for_statement; 219, 220; 219, 224; 219, 227; 220, tuple_pattern; 220, 221; 220, 222; 220, 223; 221, identifier:locus_str; 222, identifier:ref; 223, identifier:alt; 224, attribute; 224, 225; 224, 226; 225, identifier:args; 226, identifier:single_variant; 227, block; 227, 228; 227, 237; 227, 255; 227, 262; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:locus; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:Locus; 234, identifier:parse; 235, argument_list; 235, 236; 236, identifier:locus_str; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:variant; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:varcode; 243, identifier:Variant; 244, argument_list; 244, 245; 244, 248; 244, 251; 244, 252; 244, 253; 245, attribute; 245, 246; 245, 247; 246, identifier:locus; 247, identifier:contig; 248, attribute; 248, 249; 248, 250; 249, identifier:locus; 250, identifier:inclusive_start; 251, identifier:ref; 252, identifier:alt; 253, dictionary_splat; 253, 254; 254, identifier:extra_args; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:variants; 259, identifier:append; 260, argument_list; 260, 261; 261, identifier:variant; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 269; 264, attribute; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:variant_to_sources; 267, identifier:variant; 268, identifier:append; 269, argument_list; 269, 270; 270, string:"commandline"; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:dfs; 275, identifier:append; 276, argument_list; 276, 277; 277, call; 277, 278; 277, 279; 278, identifier:variants_to_dataframe; 279, argument_list; 279, 280; 280, identifier:variants; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:df; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:dfs; 287, identifier:pop; 288, argument_list; 288, 289; 289, integer:0; 290, for_statement; 290, 291; 290, 292; 290, 293; 291, identifier:other_df; 292, identifier:dfs; 293, block; 293, 294; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:df; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:pandas; 300, identifier:merge; 301, argument_list; 301, 302; 301, 303; 301, 304; 301, 307; 302, identifier:df; 303, identifier:other_df; 304, keyword_argument; 304, 305; 304, 306; 305, identifier:how; 306, string:'outer'; 307, keyword_argument; 307, 308; 307, 309; 308, identifier:on; 309, binary_operator:+; 309, 310; 309, 312; 310, list:["variant"]; 310, 311; 311, string:"variant"; 312, identifier:STANDARD_DATAFRAME_COLUMNS; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:genomes; 316, call; 316, 317; 316, 322; 317, attribute; 317, 318; 317, 321; 318, subscript; 318, 319; 318, 320; 319, identifier:df; 320, string:"genome"; 321, identifier:unique; 322, argument_list; 323, if_statement; 323, 324; 323, 330; 324, comparison_operator:>; 324, 325; 324, 329; 325, call; 325, 326; 325, 327; 326, identifier:len; 327, argument_list; 327, 328; 328, identifier:genomes; 329, integer:1; 330, block; 330, 331; 331, raise_statement; 331, 332; 332, call; 332, 333; 332, 334; 333, identifier:ValueError; 334, argument_list; 334, 335; 335, binary_operator:%; 335, 336; 335, 339; 336, concatenated_string; 336, 337; 336, 338; 337, string:"Mixing references is not supported. "; 338, string:"Reference genomes: %s"; 339, parenthesized_expression; 339, 340; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, string:", "; 343, identifier:join; 344, argument_list; 344, 345; 345, identifier:genomes; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 351; 348, subscript; 348, 349; 348, 350; 349, identifier:df; 350, string:"sources"; 351, list_comprehension; 351, 352; 351, 360; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, string:" "; 355, identifier:join; 356, argument_list; 356, 357; 357, subscript; 357, 358; 357, 359; 358, identifier:variant_to_sources; 359, identifier:v; 360, for_in_clause; 360, 361; 360, 362; 361, identifier:v; 362, attribute; 362, 363; 362, 364; 363, identifier:df; 364, identifier:variant; 365, comment; 366, if_statement; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:args; 369, identifier:ref; 370, block; 370, 371; 371, expression_statement; 371, 372; 372, assignment; 372, 373; 372, 374; 373, identifier:df; 374, subscript; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:df; 377, identifier:ix; 378, call; 378, 379; 378, 384; 379, attribute; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:df; 382, identifier:ref; 383, identifier:isin; 384, argument_list; 384, 385; 385, attribute; 385, 386; 385, 387; 386, identifier:args; 387, identifier:ref; 388, if_statement; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:args; 391, identifier:alt; 392, block; 392, 393; 393, expression_statement; 393, 394; 394, assignment; 394, 395; 394, 396; 395, identifier:df; 396, subscript; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:df; 399, identifier:ix; 400, call; 400, 401; 400, 406; 401, attribute; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:df; 404, identifier:alt; 405, identifier:isin; 406, argument_list; 406, 407; 407, attribute; 407, 408; 407, 409; 408, identifier:args; 409, identifier:alt; 410, expression_statement; 410, 411; 411, assignment; 411, 412; 411, 413; 412, identifier:loci; 413, call; 413, 414; 413, 417; 414, attribute; 414, 415; 414, 416; 415, identifier:loci_util; 416, identifier:load_from_args; 417, argument_list; 417, 418; 418, call; 418, 419; 418, 422; 419, attribute; 419, 420; 419, 421; 420, identifier:util; 421, identifier:remove_prefix_from_parsed_args; 422, argument_list; 422, 423; 422, 424; 423, identifier:args; 424, string:"variant"; 425, if_statement; 425, 426; 425, 429; 426, comparison_operator:is; 426, 427; 426, 428; 427, identifier:loci; 428, None; 429, block; 429, 430; 430, expression_statement; 430, 431; 431, assignment; 431, 432; 431, 433; 432, identifier:df; 433, subscript; 433, 434; 433, 437; 434, attribute; 434, 435; 434, 436; 435, identifier:df; 436, identifier:ix; 437, list_comprehension; 437, 438; 437, 449; 438, call; 438, 439; 438, 442; 439, attribute; 439, 440; 439, 441; 440, identifier:loci; 441, identifier:intersects; 442, argument_list; 442, 443; 443, call; 443, 444; 443, 447; 444, attribute; 444, 445; 444, 446; 445, identifier:pileup_collection; 446, identifier:to_locus; 447, argument_list; 447, 448; 448, identifier:v; 449, for_in_clause; 449, 450; 449, 451; 450, identifier:v; 451, attribute; 451, 452; 451, 453; 452, identifier:df; 453, identifier:variant; 454, return_statement; 454, 455; 455, identifier:df
def load_from_args_as_dataframe(args): ''' Given parsed variant-loading arguments, return a pandas DataFrame. If no variant loading arguments are specified, return None. ''' if not args.variants and not args.single_variant: return None if args.variant_source_name: variant_source_names = util.expand( args.variant_source_name, 'variant_source_name', 'variant source', len(args.variants)) else: variant_source_names = util.drop_prefix(args.variants) variant_to_sources = collections.defaultdict(list) dfs = [] for i in range(len(args.variants)): name = variant_source_names[i] prefix = ( 'metadata:' if len(args.variants) == 1 else "metadata:%s:" % name) df = load_as_dataframe( args.variants[i], name=name, genome=args.genome, max_variants=args.max_variants_per_source, only_passing=not args.include_failing_variants, metadata_column_prefix=prefix) if df.shape[0] == 0: logging.warn("No variants loaded from: %s" % args.variants[i]) else: for variant in df.variant: variant_to_sources[variant].append(name) dfs.append(df) if args.single_variant: variants = [] extra_args = {} if args.genome: extra_args = { 'ensembl': varcode.reference.infer_genome(args.genome) } for (locus_str, ref, alt) in args.single_variant: locus = Locus.parse(locus_str) variant = varcode.Variant( locus.contig, locus.inclusive_start, ref, alt, **extra_args) variants.append(variant) variant_to_sources[variant].append("commandline") dfs.append(variants_to_dataframe(variants)) df = dfs.pop(0) for other_df in dfs: df = pandas.merge( df, other_df, how='outer', on=["variant"] + STANDARD_DATAFRAME_COLUMNS) genomes = df["genome"].unique() if len(genomes) > 1: raise ValueError( "Mixing references is not supported. " "Reference genomes: %s" % (", ".join(genomes))) df["sources"] = [" ".join(variant_to_sources[v]) for v in df.variant] # Apply filters: if args.ref: df = df.ix[df.ref.isin(args.ref)] if args.alt: df = df.ix[df.alt.isin(args.alt)] loci = loci_util.load_from_args( util.remove_prefix_from_parsed_args(args, "variant")) if loci is not None: df = df.ix[[ loci.intersects(pileup_collection.to_locus(v)) for v in df.variant ]] return df
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:protected; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:tests; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 22; 9, 34; 9, 44; 9, 54; 9, 64; 9, 74; 9, 85; 9, 89; 9, 93; 9, 390; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:_role; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:kwargs; 18, identifier:pop; 19, argument_list; 19, 20; 19, 21; 20, string:'role'; 21, None; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:_roles; 25, boolean_operator:or; 25, 26; 25, 33; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:kwargs; 29, identifier:pop; 30, argument_list; 30, 31; 30, 32; 31, string:'roles'; 32, None; 33, list:[]; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:_csrf; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:kwargs; 40, identifier:pop; 41, argument_list; 41, 42; 41, 43; 42, string:'csrf'; 43, None; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:_url_sign_in; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:kwargs; 50, identifier:pop; 51, argument_list; 51, 52; 51, 53; 52, string:'url_sign_in'; 53, None; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:_request; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:kwargs; 60, identifier:pop; 61, argument_list; 61, 62; 61, 63; 62, string:'request'; 63, None; 64, if_statement; 64, 65; 64, 66; 65, identifier:_role; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:_roles; 71, identifier:append; 72, argument_list; 72, 73; 73, identifier:_role; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:_roles; 77, list_comprehension; 77, 78; 77, 82; 78, call; 78, 79; 78, 80; 79, identifier:to_unicode; 80, argument_list; 80, 81; 81, identifier:r; 82, for_in_clause; 82, 83; 82, 84; 83, identifier:r; 84, identifier:_roles; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:_tests; 88, identifier:tests; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:_user_tests; 92, identifier:kwargs; 93, function_definition; 93, 94; 93, 95; 93, 97; 94, function_name:decorator; 95, parameters; 95, 96; 96, identifier:f; 97, block; 97, 98; 97, 388; 98, decorated_definition; 98, 99; 98, 106; 99, decorator; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:functools; 103, identifier:wraps; 104, argument_list; 104, 105; 105, identifier:f; 106, function_definition; 106, 107; 106, 108; 106, 113; 107, function_name:wrapper; 108, parameters; 108, 109; 108, 111; 109, list_splat_pattern; 109, 110; 110, identifier:args; 111, dictionary_splat_pattern; 111, 112; 112, identifier:kwargs; 113, block; 113, 114; 113, 123; 113, 137; 113, 147; 113, 155; 113, 167; 113, 228; 113, 269; 113, 324; 113, 330; 113, 331; 113, 380; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:logger; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:logging; 120, identifier:getLogger; 121, argument_list; 121, 122; 122, identifier:__name__; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:request; 126, boolean_operator:or; 126, 127; 126, 132; 127, boolean_operator:or; 127, 128; 127, 129; 128, identifier:_request; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:request; 132, boolean_operator:and; 132, 133; 132, 134; 133, identifier:args; 134, subscript; 134, 135; 134, 136; 135, identifier:args; 136, integer:0; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:url_sign_in; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:_get_url_sign_in; 144, argument_list; 144, 145; 144, 146; 145, identifier:request; 146, identifier:_url_sign_in; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:user; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:get_user; 154, argument_list; 155, if_statement; 155, 156; 155, 158; 156, not_operator; 156, 157; 157, identifier:user; 158, block; 158, 159; 159, return_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:_login_required; 164, argument_list; 164, 165; 164, 166; 165, identifier:request; 166, identifier:url_sign_in; 167, if_statement; 167, 168; 167, 175; 168, boolean_operator:and; 168, 169; 168, 174; 169, call; 169, 170; 169, 171; 170, identifier:hasattr; 171, argument_list; 171, 172; 171, 173; 172, identifier:user; 173, string:'has_role'; 174, identifier:_roles; 175, block; 175, 176; 176, if_statement; 176, 177; 176, 185; 177, not_operator; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:user; 181, identifier:has_role; 182, argument_list; 182, 183; 183, list_splat; 183, 184; 184, identifier:_roles; 185, block; 185, 186; 185, 200; 185, 220; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:logger; 190, identifier:debug; 191, argument_list; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, string:u'User `{0}`: has_role fail'; 195, identifier:format; 196, argument_list; 196, 197; 197, attribute; 197, 198; 197, 199; 198, identifier:user; 199, identifier:login; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:logger; 204, identifier:debug; 205, argument_list; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, string:u'User roles: {0}'; 209, identifier:format; 210, argument_list; 210, 211; 211, list_comprehension; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:r; 214, identifier:name; 215, for_in_clause; 215, 216; 215, 217; 216, identifier:r; 217, attribute; 217, 218; 217, 219; 218, identifier:user; 219, identifier:roles; 220, return_statement; 220, 221; 221, call; 221, 222; 221, 227; 222, attribute; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:self; 225, identifier:wsgi; 226, identifier:raise_forbidden; 227, argument_list; 228, for_statement; 228, 229; 228, 230; 228, 231; 229, identifier:test; 230, identifier:_tests; 231, block; 231, 232; 231, 243; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:test_pass; 235, call; 235, 236; 235, 237; 236, identifier:test; 237, argument_list; 237, 238; 237, 239; 237, 241; 238, identifier:user; 239, list_splat; 239, 240; 240, identifier:args; 241, dictionary_splat; 241, 242; 242, identifier:kwargs; 243, if_statement; 243, 244; 243, 246; 244, not_operator; 244, 245; 245, identifier:test_pass; 246, block; 246, 247; 246, 261; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:logger; 251, identifier:debug; 252, argument_list; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, string:u'User `{0}`: test fail'; 256, identifier:format; 257, argument_list; 257, 258; 258, attribute; 258, 259; 258, 260; 259, identifier:user; 260, identifier:login; 261, return_statement; 261, 262; 262, call; 262, 263; 262, 268; 263, attribute; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:wsgi; 267, identifier:raise_forbidden; 268, argument_list; 269, for_statement; 269, 270; 269, 273; 269, 278; 270, pattern_list; 270, 271; 270, 272; 271, identifier:name; 272, identifier:value; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:_user_tests; 276, identifier:items; 277, argument_list; 278, block; 278, 279; 278, 287; 278, 298; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:user_test; 282, call; 282, 283; 282, 284; 283, identifier:getattr; 284, argument_list; 284, 285; 284, 286; 285, identifier:user; 286, identifier:name; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:test_pass; 290, call; 290, 291; 290, 292; 291, identifier:user_test; 292, argument_list; 292, 293; 292, 294; 292, 296; 293, identifier:value; 294, list_splat; 294, 295; 295, identifier:args; 296, dictionary_splat; 296, 297; 297, identifier:kwargs; 298, if_statement; 298, 299; 298, 301; 299, not_operator; 299, 300; 300, identifier:test_pass; 301, block; 301, 302; 301, 316; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:logger; 306, identifier:debug; 307, argument_list; 307, 308; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, string:u'User `{0}`: test fail'; 311, identifier:format; 312, argument_list; 312, 313; 313, attribute; 313, 314; 313, 315; 314, identifier:user; 315, identifier:login; 316, return_statement; 316, 317; 317, call; 317, 318; 317, 323; 318, attribute; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:self; 321, identifier:wsgi; 322, identifier:raise_forbidden; 323, argument_list; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:disable_csrf; 327, comparison_operator:==; 327, 328; 327, 329; 328, identifier:_csrf; 329, False; 330, comment; 331, if_statement; 331, 332; 331, 347; 332, boolean_operator:or; 332, 333; 332, 346; 333, parenthesized_expression; 333, 334; 334, boolean_operator:and; 334, 335; 334, 344; 335, not_operator; 335, 336; 336, call; 336, 337; 336, 342; 337, attribute; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:wsgi; 341, identifier:is_idempotent; 342, argument_list; 342, 343; 343, identifier:request; 344, not_operator; 344, 345; 345, identifier:disable_csrf; 346, identifier:_csrf; 347, block; 347, 348; 348, if_statement; 348, 349; 348, 356; 349, not_operator; 349, 350; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:self; 353, identifier:csrf_token_is_valid; 354, argument_list; 354, 355; 355, identifier:request; 356, block; 356, 357; 356, 371; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:logger; 361, identifier:debug; 362, argument_list; 362, 363; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, string:u'User `{0}`: invalid CSFR token'; 366, identifier:format; 367, argument_list; 367, 368; 368, attribute; 368, 369; 368, 370; 369, identifier:user; 370, identifier:login; 371, return_statement; 371, 372; 372, call; 372, 373; 372, 378; 373, attribute; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, identifier:self; 376, identifier:wsgi; 377, identifier:raise_forbidden; 378, argument_list; 378, 379; 379, string:"CSFR token isn't valid"; 380, return_statement; 380, 381; 381, call; 381, 382; 381, 383; 382, identifier:f; 383, argument_list; 383, 384; 383, 386; 384, list_splat; 384, 385; 385, identifier:args; 386, dictionary_splat; 386, 387; 387, identifier:kwargs; 388, return_statement; 388, 389; 389, identifier:wrapper; 390, return_statement; 390, 391; 391, identifier:decorator
def protected(self, *tests, **kwargs): """Factory of decorators for limit the access to views. :tests: *function, optional One or more functions that takes the args and kwargs of the view and returns either `True` or `False`. All test must return True to show the view. Options: :role: str, optional Test for the user having a role with this name. :roles: list, optional Test for the user having **any** role in this list of names. :csrf: bool, None, optional If ``None`` (the default), the decorator will check the value of the CSFR token for POST, PUT or DELETE requests. If ``True`` it will do the same also for all requests. If ``False``, the value of the CSFR token will not be checked. :url_sign_in: str, function, optional If any required condition fail, redirect to this place. Override the default URL. This can also be a callable. :request: obj, optional Overwrite the request for testing. The rest of the ``key=value`` pairs in ``kwargs`` are interpreted as tests. The user must have a property `key` with a value equals to `value`. If the user has a method named `key`, that method is called with `value` as a single argument and must return True to show the view. """ _role = kwargs.pop('role', None) _roles = kwargs.pop('roles', None) or [] _csrf = kwargs.pop('csrf', None) _url_sign_in = kwargs.pop('url_sign_in', None) _request = kwargs.pop('request', None) if _role: _roles.append(_role) _roles = [to_unicode(r) for r in _roles] _tests = tests _user_tests = kwargs def decorator(f): @functools.wraps(f) def wrapper(*args, **kwargs): logger = logging.getLogger(__name__) request = _request or self.request or args and args[0] url_sign_in = self._get_url_sign_in(request, _url_sign_in) user = self.get_user() if not user: return self._login_required(request, url_sign_in) if hasattr(user, 'has_role') and _roles: if not user.has_role(*_roles): logger.debug(u'User `{0}`: has_role fail'.format(user.login)) logger.debug(u'User roles: {0}'.format([r.name for r in user.roles])) return self.wsgi.raise_forbidden() for test in _tests: test_pass = test(user, *args, **kwargs) if not test_pass: logger.debug(u'User `{0}`: test fail'.format(user.login)) return self.wsgi.raise_forbidden() for name, value in _user_tests.items(): user_test = getattr(user, name) test_pass = user_test(value, *args, **kwargs) if not test_pass: logger.debug(u'User `{0}`: test fail'.format(user.login)) return self.wsgi.raise_forbidden() disable_csrf = _csrf == False # noqa if (not self.wsgi.is_idempotent(request) and not disable_csrf) or _csrf: if not self.csrf_token_is_valid(request): logger.debug(u'User `{0}`: invalid CSFR token'.format(user.login)) return self.wsgi.raise_forbidden("CSFR token isn't valid") return f(*args, **kwargs) return wrapper return decorator
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_verify_multi; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:token; 6, identifier:verifying_keys; 7, default_parameter; 7, 8; 7, 9; 8, identifier:num_required; 9, None; 10, block; 10, 11; 10, 13; 10, 24; 10, 36; 10, 47; 10, 64; 10, 78; 10, 79; 10, 103; 10, 119; 10, 120; 10, 124; 10, 185; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 20; 15, pattern_list; 15, 16; 15, 17; 15, 18; 15, 19; 16, identifier:headers; 17, identifier:payload; 18, identifier:raw_signatures; 19, identifier:signing_inputs; 20, call; 20, 21; 20, 22; 21, identifier:_unpack_token_json; 22, argument_list; 22, 23; 23, identifier:token; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:num_required; 27, None; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:num_required; 32, call; 32, 33; 32, 34; 33, identifier:len; 34, argument_list; 34, 35; 35, identifier:raw_signatures; 36, if_statement; 36, 37; 36, 43; 36, 44; 37, comparison_operator:>; 37, 38; 37, 39; 38, identifier:num_required; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, identifier:verifying_keys; 43, comment; 44, block; 44, 45; 45, return_statement; 45, 46; 46, False; 47, if_statement; 47, 48; 47, 57; 47, 58; 48, comparison_operator:!=; 48, 49; 48, 53; 49, call; 49, 50; 49, 51; 50, identifier:len; 51, argument_list; 51, 52; 52, identifier:headers; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:raw_signatures; 57, comment; 58, block; 58, 59; 59, raise_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:DecodeError; 62, argument_list; 62, 63; 63, string:'Header/signature mismatch'; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:verifying_keys; 67, list_comprehension; 67, 68; 67, 75; 68, call; 68, 69; 68, 70; 69, identifier:load_verifying_key; 70, argument_list; 70, 71; 70, 72; 71, identifier:vk; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:crypto_backend; 75, for_in_clause; 75, 76; 75, 77; 76, identifier:vk; 77, identifier:verifying_keys; 78, comment; 79, for_statement; 79, 80; 79, 81; 79, 82; 80, identifier:vk; 81, identifier:verifying_keys; 82, block; 82, 83; 83, if_statement; 83, 84; 83, 97; 84, comparison_operator:!=; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:vk; 88, identifier:curve; 89, identifier:name; 90, attribute; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:verifying_keys; 94, integer:0; 95, identifier:curve; 96, identifier:name; 97, block; 97, 98; 98, raise_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:DecodeError; 101, argument_list; 101, 102; 102, string:"TODO: only support using keys from one curve per JWT"; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:der_signatures; 106, list_comprehension; 106, 107; 106, 116; 107, call; 107, 108; 107, 109; 108, identifier:raw_to_der_signature; 109, argument_list; 109, 110; 109, 111; 110, identifier:rs; 111, attribute; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:verifying_keys; 114, integer:0; 115, identifier:curve; 116, for_in_clause; 116, 117; 116, 118; 117, identifier:rs; 118, identifier:raw_signatures; 119, comment; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:num_verified; 123, integer:0; 124, for_statement; 124, 125; 124, 128; 124, 133; 125, tuple_pattern; 125, 126; 125, 127; 126, identifier:signing_input; 127, identifier:der_sig; 128, call; 128, 129; 128, 130; 129, identifier:zip; 130, argument_list; 130, 131; 130, 132; 131, identifier:signing_inputs; 132, identifier:der_signatures; 133, block; 133, 134; 133, 179; 134, for_statement; 134, 135; 134, 136; 134, 137; 135, identifier:vk; 136, identifier:verifying_keys; 137, block; 137, 138; 137, 148; 137, 155; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:verifier; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:_get_verifier; 145, argument_list; 145, 146; 145, 147; 146, identifier:vk; 147, identifier:der_sig; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:verifier; 152, identifier:update; 153, argument_list; 153, 154; 154, identifier:signing_input; 155, try_statement; 155, 156; 155, 175; 156, block; 156, 157; 156, 163; 156, 167; 156, 174; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:verifier; 161, identifier:verify; 162, argument_list; 163, expression_statement; 163, 164; 164, augmented_assignment:+=; 164, 165; 164, 166; 165, identifier:num_verified; 166, integer:1; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:verifying_keys; 171, identifier:remove; 172, argument_list; 172, 173; 173, identifier:vk; 174, break_statement; 175, except_clause; 175, 176; 175, 177; 176, identifier:InvalidSignature; 177, block; 177, 178; 178, pass_statement; 179, if_statement; 179, 180; 179, 183; 180, comparison_operator:>=; 180, 181; 180, 182; 181, identifier:num_verified; 182, identifier:num_required; 183, block; 183, 184; 184, break_statement; 185, return_statement; 185, 186; 186, parenthesized_expression; 186, 187; 187, comparison_operator:>=; 187, 188; 187, 189; 188, identifier:num_verified; 189, identifier:num_required
def _verify_multi(self, token, verifying_keys, num_required=None): """ Verify a JSON-formatted JWT signed by multiple keys is authentic. Optionally set a threshold of required valid signatures with num_required. Return True if valid Return False if not TODO: support multiple types of keys """ headers, payload, raw_signatures, signing_inputs = _unpack_token_json(token) if num_required is None: num_required = len(raw_signatures) if num_required > len(verifying_keys): # not possible return False if len(headers) != len(raw_signatures): # invalid raise DecodeError('Header/signature mismatch') verifying_keys = [load_verifying_key(vk, self.crypto_backend) for vk in verifying_keys] # sanity check: only support one type of key :( for vk in verifying_keys: if vk.curve.name != verifying_keys[0].curve.name: raise DecodeError("TODO: only support using keys from one curve per JWT") der_signatures = [raw_to_der_signature(rs, verifying_keys[0].curve) for rs in raw_signatures] # verify until threshold is met num_verified = 0 for (signing_input, der_sig) in zip(signing_inputs, der_signatures): for vk in verifying_keys: verifier = self._get_verifier(vk, der_sig) verifier.update(signing_input) try: verifier.verify() num_verified += 1 verifying_keys.remove(vk) break except InvalidSignature: pass if num_verified >= num_required: break return (num_verified >= num_required)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:parse_pic_field; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:l; 5, identifier:c; 6, identifier:last_section_node; 7, identifier:last_vars; 8, identifier:line; 9, block; 9, 10; 9, 12; 9, 16; 9, 25; 9, 29; 9, 52; 9, 98; 9, 108; 9, 121; 9, 134; 9, 165; 9, 213; 9, 226; 9, 274; 9, 281; 9, 282; 9, 283; 9, 284; 9, 304; 9, 319; 9, 326; 9, 332; 9, 333; 9, 347; 9, 363; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:parent_node; 15, None; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:raw_tokens; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:line; 22, identifier:split; 23, argument_list; 23, 24; 24, string:" "; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:tokens; 28, list:[]; 29, for_statement; 29, 30; 29, 31; 29, 32; 30, identifier:t; 31, identifier:raw_tokens; 32, block; 32, 33; 33, if_statement; 33, 34; 33, 44; 34, boolean_operator:and; 34, 35; 34, 41; 35, not_operator; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:t; 39, identifier:isspace; 40, argument_list; 41, comparison_operator:!=; 41, 42; 41, 43; 42, identifier:t; 43, string:""; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:tokens; 49, identifier:append; 50, argument_list; 50, 51; 51, identifier:t; 52, try_statement; 52, 53; 52, 87; 52, 92; 53, block; 53, 54; 53, 81; 54, if_statement; 54, 55; 54, 64; 54, 69; 55, comparison_operator:==; 55, 56; 55, 63; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:tokens; 60, integer:0; 61, identifier:upper; 62, argument_list; 63, string:"FD"; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:lvl; 68, integer:1; 69, else_clause; 69, 70; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:lvl; 74, call; 74, 75; 74, 76; 75, identifier:int; 76, argument_list; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:tokens; 79, integer:0; 80, integer:16; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:name; 84, subscript; 84, 85; 84, 86; 85, identifier:tokens; 86, integer:1; 87, except_clause; 87, 88; 87, 89; 88, identifier:ValueError; 89, block; 89, 90; 90, return_statement; 90, 91; 91, None; 92, except_clause; 92, 93; 92, 94; 92, 95; 93, identifier:IndexError; 94, comment; 95, block; 95, 96; 96, return_statement; 96, 97; 97, None; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:name; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:name; 104, identifier:replace; 105, argument_list; 105, 106; 105, 107; 106, string:"."; 107, string:""; 108, if_statement; 108, 109; 108, 118; 109, boolean_operator:or; 109, 110; 109, 113; 110, comparison_operator:in; 110, 111; 110, 112; 111, identifier:name; 112, identifier:ALL_KEYWORDS; 113, comparison_operator:in; 113, 114; 113, 115; 114, identifier:name; 115, list:['-', '/']; 115, 116; 115, 117; 116, string:'-'; 117, string:'/'; 118, block; 118, 119; 119, return_statement; 119, 120; 120, None; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:m; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:re; 127, identifier:findall; 128, argument_list; 128, 129; 128, 130; 128, 131; 129, string:r'pic.*\.'; 130, identifier:line; 131, attribute; 131, 132; 131, 133; 132, identifier:re; 133, identifier:IGNORECASE; 134, if_statement; 134, 135; 134, 136; 134, 159; 135, identifier:m; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:description; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, string:' '; 143, identifier:join; 144, argument_list; 144, 145; 145, list_comprehension; 145, 146; 145, 147; 145, 157; 146, identifier:t; 147, for_in_clause; 147, 148; 147, 149; 148, identifier:t; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:m; 153, integer:0; 154, identifier:split; 155, argument_list; 155, 156; 156, string:' '; 157, if_clause; 157, 158; 158, identifier:t; 159, else_clause; 159, 160; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:description; 164, identifier:line; 165, try_statement; 165, 166; 165, 180; 165, 193; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:index; 170, call; 170, 171; 170, 178; 171, attribute; 171, 172; 171, 177; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:description; 175, identifier:lower; 176, argument_list; 177, identifier:index; 178, argument_list; 178, 179; 179, string:'value'; 180, except_clause; 180, 181; 180, 182; 181, identifier:ValueError; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:description; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:description; 189, identifier:replace; 190, argument_list; 190, 191; 190, 192; 191, string:'.'; 192, string:''; 193, else_clause; 193, 194; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:description; 198, subscript; 198, 199; 198, 210; 199, call; 199, 200; 199, 207; 200, attribute; 200, 201; 200, 206; 201, subscript; 201, 202; 201, 203; 202, identifier:description; 203, slice; 203, 204; 203, 205; 204, identifier:index; 205, colon; 206, identifier:replace; 207, argument_list; 207, 208; 207, 209; 208, string:'value'; 209, string:''; 210, slice; 210, 211; 210, 212; 211, colon; 212, integer:80; 213, if_statement; 213, 214; 213, 221; 214, comparison_operator:==; 214, 215; 214, 216; 215, identifier:lvl; 216, call; 216, 217; 216, 218; 217, identifier:int; 218, argument_list; 218, 219; 218, 220; 219, string:'78'; 220, integer:16; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:lvl; 225, integer:1; 226, if_statement; 226, 227; 226, 230; 226, 241; 227, comparison_operator:==; 227, 228; 227, 229; 228, identifier:lvl; 229, integer:1; 230, block; 230, 231; 230, 235; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:parent_node; 234, identifier:last_section_node; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:last_vars; 239, identifier:clear; 240, argument_list; 241, else_clause; 241, 242; 241, 243; 242, comment; 243, block; 243, 244; 243, 258; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:levels; 247, call; 247, 248; 247, 249; 248, identifier:sorted; 249, argument_list; 249, 250; 249, 255; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:last_vars; 253, identifier:keys; 254, argument_list; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:reverse; 257, True; 258, for_statement; 258, 259; 258, 260; 258, 261; 259, identifier:lv; 260, identifier:levels; 261, block; 261, 262; 262, if_statement; 262, 263; 262, 266; 263, comparison_operator:<; 263, 264; 263, 265; 264, identifier:lv; 265, identifier:lvl; 266, block; 266, 267; 266, 273; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:parent_node; 270, subscript; 270, 271; 270, 272; 271, identifier:last_vars; 272, identifier:lv; 273, break_statement; 274, if_statement; 274, 275; 274, 277; 274, 278; 275, not_operator; 275, 276; 276, identifier:parent_node; 277, comment; 278, block; 278, 279; 279, return_statement; 279, 280; 280, None; 281, comment; 282, comment; 283, comment; 284, if_statement; 284, 285; 284, 299; 285, boolean_operator:or; 285, 286; 285, 288; 286, not_operator; 286, 287; 287, identifier:name; 288, comparison_operator:==; 288, 289; 288, 298; 289, call; 289, 290; 289, 297; 290, attribute; 290, 291; 290, 296; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:name; 294, identifier:upper; 295, argument_list; 296, identifier:strip; 297, argument_list; 298, string:'PIC'; 299, block; 299, 300; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:name; 303, string:'FILLER'; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:node; 307, call; 307, 308; 307, 309; 308, identifier:Name; 309, argument_list; 309, 310; 309, 315; 309, 316; 309, 317; 309, 318; 310, attribute; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:Name; 313, identifier:Type; 314, identifier:Variable; 315, identifier:l; 316, identifier:c; 317, identifier:name; 318, identifier:description; 319, expression_statement; 319, 320; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:parent_node; 323, identifier:add_child; 324, argument_list; 324, 325; 325, identifier:node; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 331; 328, subscript; 328, 329; 328, 330; 329, identifier:last_vars; 330, identifier:lvl; 331, identifier:node; 332, comment; 333, expression_statement; 333, 334; 334, assignment; 334, 335; 334, 336; 335, identifier:levels; 336, call; 336, 337; 336, 338; 337, identifier:sorted; 338, argument_list; 338, 339; 338, 344; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:last_vars; 342, identifier:keys; 343, argument_list; 344, keyword_argument; 344, 345; 344, 346; 345, identifier:reverse; 346, True; 347, for_statement; 347, 348; 347, 349; 347, 350; 348, identifier:l; 349, identifier:levels; 350, block; 350, 351; 351, if_statement; 351, 352; 351, 355; 352, comparison_operator:>; 352, 353; 352, 354; 353, identifier:l; 354, identifier:lvl; 355, block; 355, 356; 356, expression_statement; 356, 357; 357, call; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:last_vars; 360, identifier:pop; 361, argument_list; 361, 362; 362, identifier:l; 363, return_statement; 363, 364; 364, identifier:node
def parse_pic_field(l, c, last_section_node, last_vars, line): """ Parse a pic field line. Return A VariableNode or None in case of malformed code. :param l: The line number (starting from 0) :param c: The column number (starting from 0) :param last_section_node: The last section node found :param last_vars: The last vars dict :param line: The line string (without indentation) :return: The extracted variable node """ parent_node = None raw_tokens = line.split(" ") tokens = [] for t in raw_tokens: if not t.isspace() and t != "": tokens.append(t) try: if tokens[0].upper() == "FD": lvl = 1 else: lvl = int(tokens[0], 16) name = tokens[1] except ValueError: return None except IndexError: # line not complete return None name = name.replace(".", "") if name in ALL_KEYWORDS or name in ['-', '/']: return None m = re.findall(r'pic.*\.', line, re.IGNORECASE) if m: description = ' '.join([t for t in m[0].split(' ') if t]) else: description = line try: index = description.lower().index('value') except ValueError: description = description.replace('.', '') else: description = description[index:].replace('value', '')[:80] if lvl == int('78', 16): lvl = 1 if lvl == 1: parent_node = last_section_node last_vars.clear() else: # find parent level levels = sorted(last_vars.keys(), reverse=True) for lv in levels: if lv < lvl: parent_node = last_vars[lv] break if not parent_node: # malformed code return None # todo: enabled this with an option in pyqode 3.0 # if lvl == int('88', 16): # return None if not name or name.upper().strip() == 'PIC': name = 'FILLER' node = Name(Name.Type.Variable, l, c, name, description) parent_node.add_child(node) last_vars[lvl] = node # remove closed variables levels = sorted(last_vars.keys(), reverse=True) for l in levels: if l > lvl: last_vars.pop(l) return node
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:getgrouploansurl; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:idgroup; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 16; 9, 71; 9, 77; 9, 111; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:getparams; 15, list:[]; 16, if_statement; 16, 17; 16, 18; 17, identifier:kwargs; 18, block; 18, 19; 18, 51; 19, try_statement; 19, 20; 19, 44; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 27; 21, 35; 22, comparison_operator:==; 22, 23; 22, 26; 23, subscript; 23, 24; 23, 25; 24, identifier:kwargs; 25, string:"fullDetails"; 26, True; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:getparams; 32, identifier:append; 33, argument_list; 33, 34; 34, string:"fullDetails=true"; 35, else_clause; 35, 36; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:getparams; 41, identifier:append; 42, argument_list; 42, 43; 43, string:"fullDetails=false"; 44, except_clause; 44, 45; 44, 49; 45, as_pattern; 45, 46; 45, 47; 46, identifier:Exception; 47, as_pattern_target; 47, 48; 48, identifier:ex; 49, block; 49, 50; 50, pass_statement; 51, try_statement; 51, 52; 51, 64; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:getparams; 57, identifier:append; 58, argument_list; 58, 59; 59, binary_operator:%; 59, 60; 59, 61; 60, string:"accountState=%s"; 61, subscript; 61, 62; 61, 63; 62, identifier:kwargs; 63, string:"accountState"; 64, except_clause; 64, 65; 64, 69; 65, as_pattern; 65, 66; 65, 67; 66, identifier:Exception; 67, as_pattern_target; 67, 68; 68, identifier:ex; 69, block; 69, 70; 70, pass_statement; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:groupidparam; 74, binary_operator:+; 74, 75; 74, 76; 75, string:"/"; 76, identifier:idgroup; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:url; 80, binary_operator:+; 80, 81; 80, 94; 81, binary_operator:+; 81, 82; 81, 93; 82, binary_operator:+; 82, 83; 82, 92; 83, binary_operator:+; 83, 84; 83, 91; 84, call; 84, 85; 84, 86; 85, identifier:getmambuurl; 86, argument_list; 86, 87; 86, 89; 87, list_splat; 87, 88; 88, identifier:args; 89, dictionary_splat; 89, 90; 90, identifier:kwargs; 91, string:"groups"; 92, identifier:groupidparam; 93, string:"/loans"; 94, parenthesized_expression; 94, 95; 95, conditional_expression:if; 95, 96; 95, 97; 95, 103; 96, string:""; 97, comparison_operator:==; 97, 98; 97, 102; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, identifier:getparams; 102, integer:0; 103, binary_operator:+; 103, 104; 103, 105; 104, string:"?"; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, string:"&"; 108, identifier:join; 109, argument_list; 109, 110; 110, identifier:getparams; 111, return_statement; 111, 112; 112, identifier:url
def getgrouploansurl(idgroup, *args, **kwargs): """Request Group loans URL. How to use it? By default MambuLoan uses getloansurl as the urlfunc. Override that behaviour by sending getgrouploansurl (this function) as the urlfunc to the constructor of MambuLoans (note the final 's') and voila! you get the Loans just for a certain group. If idgroup is set, you'll get a response adequate for a MambuLoans object. If not set, you'll get a Jar Jar Binks object, or something quite strange and useless as JarJar. A MambuError must likely since I haven't needed it for anything but for loans of one and just one group. See mambugroup module and pydoc for further information. Currently implemented filter parameters: * accountState See Mambu official developer documentation for further details, and info on parameters that may be implemented here in the future. """ getparams = [] if kwargs: try: if kwargs["fullDetails"] == True: getparams.append("fullDetails=true") else: getparams.append("fullDetails=false") except Exception as ex: pass try: getparams.append("accountState=%s" % kwargs["accountState"]) except Exception as ex: pass groupidparam = "/" + idgroup url = getmambuurl(*args,**kwargs) + "groups" + groupidparam + "/loans" + ( "" if len(getparams) == 0 else "?" + "&".join(getparams) ) return url
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:getclientloansurl; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:idclient; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 16; 9, 71; 9, 77; 9, 111; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:getparams; 15, list:[]; 16, if_statement; 16, 17; 16, 18; 17, identifier:kwargs; 18, block; 18, 19; 18, 51; 19, try_statement; 19, 20; 19, 44; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 27; 21, 35; 22, comparison_operator:==; 22, 23; 22, 26; 23, subscript; 23, 24; 23, 25; 24, identifier:kwargs; 25, string:"fullDetails"; 26, True; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:getparams; 32, identifier:append; 33, argument_list; 33, 34; 34, string:"fullDetails=true"; 35, else_clause; 35, 36; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:getparams; 41, identifier:append; 42, argument_list; 42, 43; 43, string:"fullDetails=false"; 44, except_clause; 44, 45; 44, 49; 45, as_pattern; 45, 46; 45, 47; 46, identifier:Exception; 47, as_pattern_target; 47, 48; 48, identifier:ex; 49, block; 49, 50; 50, pass_statement; 51, try_statement; 51, 52; 51, 64; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:getparams; 57, identifier:append; 58, argument_list; 58, 59; 59, binary_operator:%; 59, 60; 59, 61; 60, string:"accountState=%s"; 61, subscript; 61, 62; 61, 63; 62, identifier:kwargs; 63, string:"accountState"; 64, except_clause; 64, 65; 64, 69; 65, as_pattern; 65, 66; 65, 67; 66, identifier:Exception; 67, as_pattern_target; 67, 68; 68, identifier:ex; 69, block; 69, 70; 70, pass_statement; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:clientidparam; 74, binary_operator:+; 74, 75; 74, 76; 75, string:"/"; 76, identifier:idclient; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:url; 80, binary_operator:+; 80, 81; 80, 94; 81, binary_operator:+; 81, 82; 81, 93; 82, binary_operator:+; 82, 83; 82, 92; 83, binary_operator:+; 83, 84; 83, 91; 84, call; 84, 85; 84, 86; 85, identifier:getmambuurl; 86, argument_list; 86, 87; 86, 89; 87, list_splat; 87, 88; 88, identifier:args; 89, dictionary_splat; 89, 90; 90, identifier:kwargs; 91, string:"clients"; 92, identifier:clientidparam; 93, string:"/loans"; 94, parenthesized_expression; 94, 95; 95, conditional_expression:if; 95, 96; 95, 97; 95, 103; 96, string:""; 97, comparison_operator:==; 97, 98; 97, 102; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, identifier:getparams; 102, integer:0; 103, binary_operator:+; 103, 104; 103, 105; 104, string:"?"; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, string:"&"; 108, identifier:join; 109, argument_list; 109, 110; 110, identifier:getparams; 111, return_statement; 111, 112; 112, identifier:url
def getclientloansurl(idclient, *args, **kwargs): """Request Client loans URL. How to use it? By default MambuLoan uses getloansurl as the urlfunc. Override that behaviour by sending getclientloansurl (this function) as the urlfunc to the constructor of MambuLoans (note the final 's') and voila! you get the Loans just for a certain client. If idclient is set, you'll get a response adequate for a MambuLoans object. If not set, you'll get a Jar Jar Binks object, or something quite strange and useless as JarJar. A MambuError must likely since I haven't needed it for anything but for loans of one and just one client. See mambuloan module and pydoc for further information. Currently implemented filter parameters: * accountState See Mambu official developer documentation for further details, and info on parameters that may be implemented here in the future. """ getparams = [] if kwargs: try: if kwargs["fullDetails"] == True: getparams.append("fullDetails=true") else: getparams.append("fullDetails=false") except Exception as ex: pass try: getparams.append("accountState=%s" % kwargs["accountState"]) except Exception as ex: pass clientidparam = "/" + idclient url = getmambuurl(*args,**kwargs) + "clients" + clientidparam + "/loans" + ( "" if len(getparams) == 0 else "?" + "&".join(getparams) ) return url
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:backup_db; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 9; 4, identifier:callback; 5, identifier:bool_func; 6, identifier:output_fname; 7, list_splat_pattern; 7, 8; 8, identifier:args; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 14; 11, 19; 11, 34; 11, 50; 11, 68; 11, 103; 11, 113; 11, 123; 11, 130; 11, 228; 11, 266; 11, 272; 11, 315; 11, 367; 11, 372; 11, 387; 11, 407; 11, 421; 11, 459; 11, 475; 11, 496; 11, 512; 12, expression_statement; 12, 13; 13, comment; 14, import_from_statement; 14, 15; 14, 17; 15, dotted_name; 15, 16; 16, identifier:datetime; 17, dotted_name; 17, 18; 18, identifier:datetime; 19, try_statement; 19, 20; 19, 27; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:verbose; 24, subscript; 24, 25; 24, 26; 25, identifier:kwargs; 26, string:'verbose'; 27, except_clause; 27, 28; 27, 29; 28, identifier:KeyError; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:verbose; 33, False; 34, try_statement; 34, 35; 34, 42; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:retries; 39, subscript; 39, 40; 39, 41; 40, identifier:kwargs; 41, string:'retries'; 42, except_clause; 42, 43; 42, 44; 43, identifier:KeyError; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:retries; 48, unary_operator:-; 48, 49; 49, integer:1; 50, try_statement; 50, 51; 50, 61; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:force_download_latest; 55, call; 55, 56; 55, 57; 56, identifier:bool; 57, argument_list; 57, 58; 58, subscript; 58, 59; 58, 60; 59, identifier:kwargs; 60, string:'force_download_latest'; 61, except_clause; 61, 62; 61, 63; 62, identifier:KeyError; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:force_download_latest; 67, False; 68, if_statement; 68, 69; 68, 70; 69, identifier:verbose; 70, block; 70, 71; 70, 79; 70, 97; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:log; 74, call; 74, 75; 74, 76; 75, identifier:open; 76, argument_list; 76, 77; 76, 78; 77, string:'/tmp/log_mambu_backup'; 78, string:'a'; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:log; 83, identifier:write; 84, argument_list; 84, 85; 85, binary_operator:+; 85, 86; 85, 96; 86, call; 86, 87; 86, 94; 87, attribute; 87, 88; 87, 93; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:datetime; 91, identifier:now; 92, argument_list; 93, identifier:strftime; 94, argument_list; 94, 95; 95, string:'%Y-%m-%d %H:%M:%S'; 96, string:" - Mambu DB Backup\n"; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:log; 101, identifier:flush; 102, argument_list; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:user; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:kwargs; 109, identifier:pop; 110, argument_list; 110, 111; 110, 112; 111, string:'user'; 112, identifier:apiuser; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:pwd; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:kwargs; 119, identifier:pop; 120, argument_list; 120, 121; 120, 122; 121, string:'pwd'; 122, identifier:apipwd; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:data; 126, dictionary; 126, 127; 127, pair; 127, 128; 127, 129; 128, string:'callback'; 129, identifier:callback; 130, try_statement; 130, 131; 130, 190; 131, block; 131, 132; 131, 147; 131, 167; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:posturl; 135, call; 135, 136; 135, 137; 136, identifier:iriToUri; 137, argument_list; 137, 138; 138, binary_operator:+; 138, 139; 138, 146; 139, call; 139, 140; 139, 141; 140, identifier:getmambuurl; 141, argument_list; 141, 142; 141, 144; 142, list_splat; 142, 143; 143, identifier:args; 144, dictionary_splat; 144, 145; 145, identifier:kwargs; 146, string:"database/backup"; 147, if_statement; 147, 148; 147, 149; 148, identifier:verbose; 149, block; 149, 150; 149, 161; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:log; 154, identifier:write; 155, argument_list; 155, 156; 156, binary_operator:+; 156, 157; 156, 160; 157, binary_operator:+; 157, 158; 157, 159; 158, string:"open url: "; 159, identifier:posturl; 160, string:"\n"; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:log; 165, identifier:flush; 166, argument_list; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:resp; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:requests; 173, identifier:post; 174, argument_list; 174, 175; 174, 176; 174, 179; 174, 185; 175, identifier:posturl; 176, keyword_argument; 176, 177; 176, 178; 177, identifier:data; 178, identifier:data; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:headers; 181, dictionary; 181, 182; 182, pair; 182, 183; 182, 184; 183, string:'content-type'; 184, string:'application/json'; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:auth; 187, tuple; 187, 188; 187, 189; 188, identifier:apiuser; 189, identifier:apipwd; 190, except_clause; 190, 191; 190, 195; 191, as_pattern; 191, 192; 191, 193; 192, identifier:Exception; 193, as_pattern_target; 193, 194; 194, identifier:ex; 195, block; 195, 196; 195, 205; 195, 223; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:mess; 199, binary_operator:%; 199, 200; 199, 201; 200, string:"Error requesting backup: %s"; 201, call; 201, 202; 201, 203; 202, identifier:repr; 203, argument_list; 203, 204; 204, identifier:ex; 205, if_statement; 205, 206; 205, 207; 206, identifier:verbose; 207, block; 207, 208; 207, 217; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:log; 212, identifier:write; 213, argument_list; 213, 214; 214, binary_operator:+; 214, 215; 214, 216; 215, identifier:mess; 216, string:"\n"; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:log; 221, identifier:close; 222, argument_list; 223, raise_statement; 223, 224; 224, call; 224, 225; 224, 226; 225, identifier:MambuError; 226, argument_list; 226, 227; 227, identifier:mess; 228, if_statement; 228, 229; 228, 234; 229, comparison_operator:!=; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:resp; 232, identifier:status_code; 233, integer:200; 234, block; 234, 235; 234, 243; 234, 261; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:mess; 238, binary_operator:%; 238, 239; 238, 240; 239, string:"Error posting request for backup: %s"; 240, attribute; 240, 241; 240, 242; 241, identifier:resp; 242, identifier:content; 243, if_statement; 243, 244; 243, 245; 244, identifier:verbose; 245, block; 245, 246; 245, 255; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:log; 250, identifier:write; 251, argument_list; 251, 252; 252, binary_operator:+; 252, 253; 252, 254; 253, identifier:mess; 254, string:"\n"; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:log; 259, identifier:close; 260, argument_list; 261, raise_statement; 261, 262; 262, call; 262, 263; 262, 264; 263, identifier:MambuCommError; 264, argument_list; 264, 265; 265, identifier:mess; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 271; 268, subscript; 268, 269; 268, 270; 269, identifier:data; 270, string:'latest'; 271, True; 272, while_statement; 272, 273; 272, 279; 273, boolean_operator:and; 273, 274; 273, 275; 274, identifier:retries; 275, not_operator; 275, 276; 276, call; 276, 277; 276, 278; 277, identifier:bool_func; 278, argument_list; 279, block; 279, 280; 279, 296; 279, 301; 279, 305; 280, if_statement; 280, 281; 280, 282; 281, identifier:verbose; 282, block; 282, 283; 282, 290; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:log; 287, identifier:write; 288, argument_list; 288, 289; 289, string:"waiting...\n"; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:log; 294, identifier:flush; 295, argument_list; 296, expression_statement; 296, 297; 297, call; 297, 298; 297, 299; 298, identifier:sleep; 299, argument_list; 299, 300; 300, integer:10; 301, expression_statement; 301, 302; 302, augmented_assignment:-=; 302, 303; 302, 304; 303, identifier:retries; 304, integer:1; 305, if_statement; 305, 306; 305, 309; 306, comparison_operator:<; 306, 307; 306, 308; 307, identifier:retries; 308, integer:0; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:retries; 313, unary_operator:-; 313, 314; 314, integer:1; 315, if_statement; 315, 316; 315, 318; 316, not_operator; 316, 317; 317, identifier:retries; 318, block; 318, 319; 318, 323; 318, 341; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 322; 321, identifier:mess; 322, string:"Tired of waiting, giving up..."; 323, if_statement; 323, 324; 323, 325; 324, identifier:verbose; 325, block; 325, 326; 325, 335; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:log; 330, identifier:write; 331, argument_list; 331, 332; 332, binary_operator:+; 332, 333; 332, 334; 333, identifier:mess; 334, string:"\n"; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:log; 339, identifier:flush; 340, argument_list; 341, if_statement; 341, 342; 341, 344; 341, 359; 342, not_operator; 342, 343; 343, identifier:force_download_latest; 344, block; 344, 345; 344, 354; 345, if_statement; 345, 346; 345, 347; 346, identifier:verbose; 347, block; 347, 348; 348, expression_statement; 348, 349; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:log; 352, identifier:close; 353, argument_list; 354, raise_statement; 354, 355; 355, call; 355, 356; 355, 357; 356, identifier:MambuError; 357, argument_list; 357, 358; 358, identifier:mess; 359, else_clause; 359, 360; 360, block; 360, 361; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 366; 363, subscript; 363, 364; 363, 365; 364, identifier:data; 365, string:'latest'; 366, False; 367, expression_statement; 367, 368; 368, call; 368, 369; 368, 370; 369, identifier:sleep; 370, argument_list; 370, 371; 371, integer:30; 372, expression_statement; 372, 373; 373, assignment; 373, 374; 373, 375; 374, identifier:geturl; 375, call; 375, 376; 375, 377; 376, identifier:iriToUri; 377, argument_list; 377, 378; 378, binary_operator:+; 378, 379; 378, 386; 379, call; 379, 380; 379, 381; 380, identifier:getmambuurl; 381, argument_list; 381, 382; 381, 384; 382, list_splat; 382, 383; 383, identifier:args; 384, dictionary_splat; 384, 385; 385, identifier:kwargs; 386, string:"database/backup/LATEST"; 387, if_statement; 387, 388; 387, 389; 388, identifier:verbose; 389, block; 389, 390; 389, 401; 390, expression_statement; 390, 391; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:log; 394, identifier:write; 395, argument_list; 395, 396; 396, binary_operator:+; 396, 397; 396, 400; 397, binary_operator:+; 397, 398; 397, 399; 398, string:"open url: "; 399, identifier:geturl; 400, string:"\n"; 401, expression_statement; 401, 402; 402, call; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, identifier:log; 405, identifier:flush; 406, argument_list; 407, expression_statement; 407, 408; 408, assignment; 408, 409; 408, 410; 409, identifier:resp; 410, call; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:requests; 413, identifier:get; 414, argument_list; 414, 415; 414, 416; 415, identifier:geturl; 416, keyword_argument; 416, 417; 416, 418; 417, identifier:auth; 418, tuple; 418, 419; 418, 420; 419, identifier:apiuser; 420, identifier:apipwd; 421, if_statement; 421, 422; 421, 427; 422, comparison_operator:!=; 422, 423; 422, 426; 423, attribute; 423, 424; 423, 425; 424, identifier:resp; 425, identifier:status_code; 426, integer:200; 427, block; 427, 428; 427, 436; 427, 454; 428, expression_statement; 428, 429; 429, assignment; 429, 430; 429, 431; 430, identifier:mess; 431, binary_operator:%; 431, 432; 431, 433; 432, string:"Error getting database backup: %s"; 433, attribute; 433, 434; 433, 435; 434, identifier:resp; 435, identifier:content; 436, if_statement; 436, 437; 436, 438; 437, identifier:verbose; 438, block; 438, 439; 438, 448; 439, expression_statement; 439, 440; 440, call; 440, 441; 440, 444; 441, attribute; 441, 442; 441, 443; 442, identifier:log; 443, identifier:write; 444, argument_list; 444, 445; 445, binary_operator:+; 445, 446; 445, 447; 446, identifier:mess; 447, string:"\n"; 448, expression_statement; 448, 449; 449, call; 449, 450; 449, 453; 450, attribute; 450, 451; 450, 452; 451, identifier:log; 452, identifier:close; 453, argument_list; 454, raise_statement; 454, 455; 455, call; 455, 456; 455, 457; 456, identifier:MambuCommError; 457, argument_list; 457, 458; 458, identifier:mess; 459, if_statement; 459, 460; 459, 461; 460, identifier:verbose; 461, block; 461, 462; 461, 469; 462, expression_statement; 462, 463; 463, call; 463, 464; 463, 467; 464, attribute; 464, 465; 464, 466; 465, identifier:log; 466, identifier:write; 467, argument_list; 467, 468; 468, string:"saving...\n"; 469, expression_statement; 469, 470; 470, call; 470, 471; 470, 474; 471, attribute; 471, 472; 471, 473; 472, identifier:log; 473, identifier:flush; 474, argument_list; 475, with_statement; 475, 476; 475, 486; 476, with_clause; 476, 477; 477, with_item; 477, 478; 478, as_pattern; 478, 479; 478, 484; 479, call; 479, 480; 479, 481; 480, identifier:open; 481, argument_list; 481, 482; 481, 483; 482, identifier:output_fname; 483, string:"w"; 484, as_pattern_target; 484, 485; 485, identifier:fw; 486, block; 486, 487; 487, expression_statement; 487, 488; 488, call; 488, 489; 488, 492; 489, attribute; 489, 490; 489, 491; 490, identifier:fw; 491, identifier:write; 492, argument_list; 492, 493; 493, attribute; 493, 494; 493, 495; 494, identifier:resp; 495, identifier:content; 496, if_statement; 496, 497; 496, 498; 497, identifier:verbose; 498, block; 498, 499; 498, 506; 499, expression_statement; 499, 500; 500, call; 500, 501; 500, 504; 501, attribute; 501, 502; 501, 503; 502, identifier:log; 503, identifier:write; 504, argument_list; 504, 505; 505, string:"DONE!\n"; 506, expression_statement; 506, 507; 507, call; 507, 508; 507, 511; 508, attribute; 508, 509; 508, 510; 509, identifier:log; 510, identifier:close; 511, argument_list; 512, return_statement; 512, 513; 513, identifier:data
def backup_db(callback, bool_func, output_fname, *args, **kwargs): """Backup Mambu Database via REST API. Makes two calls to Mambu API: - a POST to request a backup to be made - a GET, once the backup is ready, to download the latest backup * callback is a string to a callback URL Mambu will internally call when the backup is ready to download. You should have a webservice there to warn you when the backup is ready. * bool_func is a function you use against your own code to test if the said backup is ready. This function backup_db manages both the logic of the request of a backup and the downloading of it too, so bool_func allows you to have some way on your side to know when this function will download the backup. The thing is you have to build a webservice (for the callback) making some kind of flag turn that your bool_func will read and know when to say True, telling backup_db to begin the download of the backup. * output_fname the name of the file that will hold the downloaded backup. PLEASE MIND that Mambu sends a ZIP file here. * user, pwd and url allow you to change the Mambu permissions for the getmambuurl internally called here. * verbose is a boolean flag for verbosity. * retries number of retries for bool_func or -1 for keep waiting. * force_download_latest boolean, True to force download even if no callback is called. False to throw error if callback isn't received after retries. * returns a dictionary with info about the download -latest boolean flag, if the db downloaded was the latest or not """ from datetime import datetime try: verbose = kwargs['verbose'] except KeyError: verbose = False try: retries = kwargs['retries'] except KeyError: retries = -1 try: force_download_latest = bool(kwargs['force_download_latest']) except KeyError: force_download_latest = False if verbose: log = open('/tmp/log_mambu_backup','a') log.write(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " - Mambu DB Backup\n") log.flush() user = kwargs.pop('user', apiuser) pwd = kwargs.pop('pwd', apipwd) data = {'callback' : callback} try: posturl = iriToUri(getmambuurl(*args, **kwargs) + "database/backup") if verbose: log.write("open url: "+posturl+"\n") log.flush() resp = requests.post(posturl, data=data, headers={'content-type': 'application/json'}, auth=(apiuser, apipwd)) except Exception as ex: mess = "Error requesting backup: %s" % repr(ex) if verbose: log.write(mess + "\n") log.close() raise MambuError(mess) if resp.status_code != 200: mess = "Error posting request for backup: %s" % resp.content if verbose: log.write(mess + "\n") log.close() raise MambuCommError(mess) data['latest'] = True while retries and not bool_func(): if verbose: log.write("waiting...\n") log.flush() sleep(10) retries -= 1 if retries < 0: retries = -1 if not retries: mess = "Tired of waiting, giving up..." if verbose: log.write(mess + "\n") log.flush() if not force_download_latest: if verbose: log.close() raise MambuError(mess) else: data['latest'] = False sleep(30) geturl = iriToUri(getmambuurl(*args, **kwargs) + "database/backup/LATEST") if verbose: log.write("open url: "+geturl+"\n") log.flush() resp = requests.get(geturl, auth=(apiuser, apipwd)) if resp.status_code != 200: mess = "Error getting database backup: %s" % resp.content if verbose: log.write(mess + "\n") log.close() raise MambuCommError(mess) if verbose: log.write("saving...\n") log.flush() with open(output_fname, "w") as fw: fw.write(resp.content) if verbose: log.write("DONE!\n") log.close() return data
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:send; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:stack; 7, type; 7, 8; 8, identifier:Layers; 9, block; 9, 10; 9, 12; 9, 27; 9, 98; 9, 137; 9, 190; 9, 226; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 19; 13, not_operator; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:stack; 18, identifier:Stack; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:stack; 23, call; 23, 24; 23, 25; 24, identifier:Stack; 25, argument_list; 25, 26; 26, identifier:stack; 27, if_statement; 27, 28; 27, 40; 28, boolean_operator:and; 28, 29; 28, 34; 29, comparison_operator:in; 29, 30; 29, 31; 30, string:'callback_query'; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_update; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:stack; 37, identifier:has_layer; 38, argument_list; 38, 39; 39, identifier:Update; 40, block; 40, 41; 40, 50; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:layer; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:stack; 47, identifier:get_layer; 48, argument_list; 48, 49; 49, identifier:Update; 50, try_statement; 50, 51; 50, 62; 50, 78; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:msg; 55, subscript; 55, 56; 55, 61; 56, subscript; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_update; 60, string:'callback_query'; 61, string:'message'; 62, except_clause; 62, 63; 62, 64; 63, identifier:KeyError; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 66, 71; 67, attribute; 67, 68; 67, 69; 68, identifier:layer; 69, identifier:inline_message_id; 70, line_continuation:\; 71, subscript; 71, 72; 71, 77; 72, subscript; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:_update; 76, string:'callback_query'; 77, string:'inline_message_id'; 78, else_clause; 78, 79; 79, block; 79, 80; 79, 90; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:layer; 84, identifier:chat_id; 85, subscript; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:msg; 88, string:'chat'; 89, string:'id'; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:layer; 94, identifier:message_id; 95, subscript; 95, 96; 95, 97; 96, identifier:msg; 97, string:'message_id'; 98, if_statement; 98, 99; 98, 105; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:stack; 102, identifier:has_layer; 103, argument_list; 103, 104; 104, identifier:AnswerCallbackQuery; 105, block; 105, 106; 105, 117; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:_acq; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:stack; 114, identifier:get_layer; 115, argument_list; 115, 116; 116, identifier:AnswerCallbackQuery; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:stack; 120, call; 120, 121; 120, 122; 121, identifier:Stack; 122, argument_list; 122, 123; 123, list_comprehension; 123, 124; 123, 125; 123, 130; 124, identifier:l; 125, for_in_clause; 125, 126; 125, 127; 126, identifier:l; 127, attribute; 127, 128; 127, 129; 128, identifier:stack; 129, identifier:layers; 130, if_clause; 130, 131; 131, not_operator; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:isinstance; 134, argument_list; 134, 135; 134, 136; 135, identifier:l; 136, identifier:AnswerCallbackQuery; 137, if_statement; 137, 138; 137, 144; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:stack; 141, identifier:has_layer; 142, argument_list; 142, 143; 143, identifier:Reply; 144, block; 144, 145; 144, 154; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:layer; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:stack; 151, identifier:get_layer; 152, argument_list; 152, 153; 153, identifier:Reply; 154, if_statement; 154, 155; 154, 160; 154, 171; 155, comparison_operator:in; 155, 156; 155, 157; 156, string:'message'; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:_update; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:layer; 165, identifier:message; 166, subscript; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:_update; 170, string:'message'; 171, elif_clause; 171, 172; 171, 177; 172, comparison_operator:in; 172, 173; 172, 174; 173, string:'callback_query'; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:_update; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:layer; 182, identifier:message; 183, subscript; 183, 184; 183, 189; 184, subscript; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:_update; 188, string:'callback_query'; 189, string:'message'; 190, if_statement; 190, 191; 190, 204; 191, boolean_operator:and; 191, 192; 191, 197; 191, 198; 192, comparison_operator:in; 192, 193; 192, 194; 193, string:'inline_query'; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:_update; 197, line_continuation:\; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:stack; 201, identifier:has_layer; 202, argument_list; 202, 203; 203, identifier:AnswerInlineQuery; 204, block; 204, 205; 204, 214; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:a; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:stack; 211, identifier:get_layer; 212, argument_list; 212, 213; 213, identifier:AnswerInlineQuery; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:a; 218, identifier:inline_query_id; 219, subscript; 219, 220; 219, 225; 220, subscript; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:_update; 224, string:'inline_query'; 225, string:'id'; 226, if_statement; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:stack; 229, identifier:layers; 230, block; 230, 231; 231, return_statement; 231, 232; 232, call; 232, 233; 232, 240; 233, attribute; 233, 234; 233, 239; 234, call; 234, 235; 234, 236; 235, identifier:super; 236, argument_list; 236, 237; 236, 238; 237, identifier:TelegramResponder; 238, identifier:self; 239, identifier:send; 240, argument_list; 240, 241; 241, identifier:stack
def send(self, stack: Layers): """ Intercept any potential "AnswerCallbackQuery" before adding the stack to the output buffer. """ if not isinstance(stack, Stack): stack = Stack(stack) if 'callback_query' in self._update and stack.has_layer(Update): layer = stack.get_layer(Update) try: msg = self._update['callback_query']['message'] except KeyError: layer.inline_message_id = \ self._update['callback_query']['inline_message_id'] else: layer.chat_id = msg['chat']['id'] layer.message_id = msg['message_id'] if stack.has_layer(AnswerCallbackQuery): self._acq = stack.get_layer(AnswerCallbackQuery) stack = Stack([ l for l in stack.layers if not isinstance(l, AnswerCallbackQuery) ]) if stack.has_layer(Reply): layer = stack.get_layer(Reply) if 'message' in self._update: layer.message = self._update['message'] elif 'callback_query' in self._update: layer.message = self._update['callback_query']['message'] if 'inline_query' in self._update \ and stack.has_layer(AnswerInlineQuery): a = stack.get_layer(AnswerInlineQuery) a.inline_query_id = self._update['inline_query']['id'] if stack.layers: return super(TelegramResponder, self).send(stack)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:_send_text; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 13; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:request; 7, type; 7, 8; 8, identifier:Request; 9, typed_parameter; 9, 10; 9, 11; 10, identifier:stack; 11, type; 11, 12; 12, identifier:Stack; 13, typed_default_parameter; 13, 14; 13, 15; 13, 21; 14, identifier:parse_mode; 15, type; 15, 16; 16, generic_type; 16, 17; 16, 18; 17, identifier:Optional; 18, type_parameter; 18, 19; 19, type; 19, 20; 20, identifier:Text; 21, None; 22, block; 22, 23; 22, 25; 22, 29; 22, 39; 22, 79; 22, 102; 22, 115; 22, 126; 22, 134; 22, 166; 23, expression_statement; 23, 24; 24, comment; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:parts; 28, list:[]; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:chat_id; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:request; 36, identifier:message; 37, identifier:get_chat_id; 38, argument_list; 39, for_statement; 39, 40; 39, 41; 39, 44; 40, identifier:layer; 41, attribute; 41, 42; 41, 43; 42, identifier:stack; 43, identifier:layers; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 60; 46, call; 46, 47; 46, 48; 47, identifier:isinstance; 48, argument_list; 48, 49; 48, 50; 49, identifier:layer; 50, tuple; 50, 51; 50, 54; 50, 57; 51, attribute; 51, 52; 51, 53; 52, identifier:lyr; 53, identifier:Text; 54, attribute; 54, 55; 54, 56; 55, identifier:lyr; 56, identifier:RawText; 57, attribute; 57, 58; 57, 59; 58, identifier:lyr; 59, identifier:Markdown; 60, block; 60, 61; 60, 72; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:text; 64, await; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:render; 67, argument_list; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:layer; 70, identifier:text; 71, identifier:request; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:parts; 76, identifier:append; 77, argument_list; 77, 78; 78, identifier:text; 79, for_statement; 79, 80; 79, 81; 79, 87; 80, identifier:part; 81, subscript; 81, 82; 81, 83; 82, identifier:parts; 83, slice; 83, 84; 83, 85; 84, colon; 85, unary_operator:-; 85, 86; 86, integer:1; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, await; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:call; 94, argument_list; 94, 95; 94, 96; 94, 99; 95, string:'sendMessage'; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:text; 98, identifier:part; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:chat_id; 101, identifier:chat_id; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:msg; 105, dictionary; 105, 106; 105, 112; 106, pair; 106, 107; 106, 108; 107, string:'text'; 108, subscript; 108, 109; 108, 110; 109, identifier:parts; 110, unary_operator:-; 110, 111; 111, integer:1; 112, pair; 112, 113; 112, 114; 113, string:'chat_id'; 114, identifier:chat_id; 115, if_statement; 115, 116; 115, 119; 116, comparison_operator:is; 116, 117; 116, 118; 117, identifier:parse_mode; 118, None; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:msg; 124, string:'parse_mode'; 125, identifier:parse_mode; 126, expression_statement; 126, 127; 127, await; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:set_reply_markup; 130, argument_list; 130, 131; 130, 132; 130, 133; 131, identifier:msg; 132, identifier:request; 133, identifier:stack; 134, if_statement; 134, 135; 134, 141; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:stack; 138, identifier:has_layer; 139, argument_list; 139, 140; 140, identifier:Reply; 141, block; 141, 142; 141, 151; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:reply; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:stack; 148, identifier:get_layer; 149, argument_list; 149, 150; 150, identifier:Reply; 151, if_statement; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:reply; 154, identifier:message; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, subscript; 158, 159; 158, 160; 159, identifier:msg; 160, string:'reply_to_message_id'; 161, subscript; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:reply; 164, identifier:message; 165, string:'message_id'; 166, if_statement; 166, 167; 166, 173; 166, 222; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:stack; 170, identifier:has_layer; 171, argument_list; 171, 172; 172, identifier:Update; 173, block; 173, 174; 173, 183; 173, 210; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:update; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:stack; 180, identifier:get_layer; 181, argument_list; 181, 182; 182, identifier:Update; 183, if_statement; 183, 184; 183, 187; 183, 200; 184, attribute; 184, 185; 184, 186; 185, identifier:update; 186, identifier:inline_message_id; 187, block; 187, 188; 187, 196; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, subscript; 190, 191; 190, 192; 191, identifier:msg; 192, string:'inline_message_id'; 193, attribute; 193, 194; 193, 195; 194, identifier:update; 195, identifier:inline_message_id; 196, delete_statement; 196, 197; 197, subscript; 197, 198; 197, 199; 198, identifier:msg; 199, string:'chat_id'; 200, else_clause; 200, 201; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 207; 204, subscript; 204, 205; 204, 206; 205, identifier:msg; 206, string:'message_id'; 207, attribute; 207, 208; 207, 209; 208, identifier:update; 209, identifier:message_id; 210, expression_statement; 210, 211; 211, await; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:call; 216, argument_list; 216, 217; 216, 218; 216, 220; 217, string:'editMessageText'; 218, set; 218, 219; 219, string:'Bad Request: message is not modified'; 220, dictionary_splat; 220, 221; 221, identifier:msg; 222, else_clause; 222, 223; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, await; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:call; 230, argument_list; 230, 231; 230, 232; 231, string:'sendMessage'; 232, dictionary_splat; 232, 233; 233, identifier:msg
async def _send_text(self, request: Request, stack: Stack, parse_mode: Optional[Text] = None): """ Base function for sending text """ parts = [] chat_id = request.message.get_chat_id() for layer in stack.layers: if isinstance(layer, (lyr.Text, lyr.RawText, lyr.Markdown)): text = await render(layer.text, request) parts.append(text) for part in parts[:-1]: await self.call( 'sendMessage', text=part, chat_id=chat_id, ) msg = { 'text': parts[-1], 'chat_id': chat_id, } if parse_mode is not None: msg['parse_mode'] = parse_mode await set_reply_markup(msg, request, stack) if stack.has_layer(Reply): reply = stack.get_layer(Reply) if reply.message: msg['reply_to_message_id'] = reply.message['message_id'] if stack.has_layer(Update): update = stack.get_layer(Update) if update.inline_message_id: msg['inline_message_id'] = update.inline_message_id del msg['chat_id'] else: msg['message_id'] = update.message_id await self.call( 'editMessageText', {'Bad Request: message is not modified'}, **msg ) else: await self.call('sendMessage', **msg)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:setRepayments; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 37; 9, 92; 9, 106; 9, 112; 10, expression_statement; 10, 11; 11, comment; 12, function_definition; 12, 13; 12, 14; 12, 16; 13, function_name:duedate; 14, parameters; 14, 15; 15, identifier:repayment; 16, block; 16, 17; 16, 19; 17, expression_statement; 17, 18; 18, comment; 19, try_statement; 19, 20; 19, 25; 20, block; 20, 21; 21, return_statement; 21, 22; 22, subscript; 22, 23; 22, 24; 23, identifier:repayment; 24, string:'dueDate'; 25, except_clause; 25, 26; 25, 30; 26, as_pattern; 26, 27; 26, 28; 27, identifier:KeyError; 28, as_pattern_target; 28, 29; 29, identifier:kerr; 30, block; 30, 31; 31, return_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:datetime; 35, identifier:now; 36, argument_list; 37, try_statement; 37, 38; 37, 56; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:reps; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:mamburepaymentsclass; 46, argument_list; 46, 47; 46, 52; 46, 54; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:entid; 49, subscript; 49, 50; 49, 51; 50, identifier:self; 51, string:'id'; 52, list_splat; 52, 53; 53, identifier:args; 54, dictionary_splat; 54, 55; 55, identifier:kwargs; 56, except_clause; 56, 57; 56, 61; 57, as_pattern; 57, 58; 57, 59; 58, identifier:AttributeError; 59, as_pattern_target; 59, 60; 60, identifier:ae; 61, block; 61, 62; 61, 69; 61, 75; 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:mamburepayment; 67, dotted_name; 67, 68; 68, identifier:MambuRepayments; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:mamburepaymentsclass; 74, identifier:MambuRepayments; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:reps; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:mamburepaymentsclass; 82, argument_list; 82, 83; 82, 88; 82, 90; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:entid; 85, subscript; 85, 86; 85, 87; 86, identifier:self; 87, string:'id'; 88, list_splat; 88, 89; 89, identifier:args; 90, dictionary_splat; 90, 91; 91, identifier:kwargs; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:reps; 96, identifier:attrs; 97, call; 97, 98; 97, 99; 98, identifier:sorted; 99, argument_list; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:reps; 102, identifier:attrs; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:key; 105, identifier:duedate; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:self; 110, string:'repayments'; 111, identifier:reps; 112, return_statement; 112, 113; 113, integer:1
def setRepayments(self, *args, **kwargs): """Adds the repayments for this loan to a 'repayments' field. Repayments are MambuRepayment objects. Repayments get sorted by due date. Returns the number of requests done to Mambu. .. todo:: since pagination logic was added, is not always true that just 1 request was done. It may be more! But since request counter singleton holds true information about how many requests were done to Mambu, in fact this return value may be obsolete """ def duedate(repayment): """Util function used for sorting repayments according to due Date""" try: return repayment['dueDate'] except KeyError as kerr: return datetime.now() try: reps = self.mamburepaymentsclass(entid=self['id'], *args, **kwargs) except AttributeError as ae: from .mamburepayment import MambuRepayments self.mamburepaymentsclass = MambuRepayments reps = self.mamburepaymentsclass(entid=self['id'], *args, **kwargs) reps.attrs = sorted(reps.attrs, key=duedate) self['repayments'] = reps return 1
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:setTransactions; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 33; 9, 88; 9, 102; 9, 108; 10, expression_statement; 10, 11; 11, comment; 12, function_definition; 12, 13; 12, 14; 12, 16; 13, function_name:transactionid; 14, parameters; 14, 15; 15, identifier:transaction; 16, block; 16, 17; 16, 19; 17, expression_statement; 17, 18; 18, comment; 19, try_statement; 19, 20; 19, 25; 20, block; 20, 21; 21, return_statement; 21, 22; 22, subscript; 22, 23; 22, 24; 23, identifier:transaction; 24, string:'transactionId'; 25, except_clause; 25, 26; 25, 30; 26, as_pattern; 26, 27; 26, 28; 27, identifier:KeyError; 28, as_pattern_target; 28, 29; 29, identifier:kerr; 30, block; 30, 31; 31, return_statement; 31, 32; 32, None; 33, try_statement; 33, 34; 33, 52; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:trans; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:mambutransactionsclass; 42, argument_list; 42, 43; 42, 48; 42, 50; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:entid; 45, subscript; 45, 46; 45, 47; 46, identifier:self; 47, string:'id'; 48, list_splat; 48, 49; 49, identifier:args; 50, dictionary_splat; 50, 51; 51, identifier:kwargs; 52, except_clause; 52, 53; 52, 57; 53, as_pattern; 53, 54; 53, 55; 54, identifier:AttributeError; 55, as_pattern_target; 55, 56; 56, identifier:ae; 57, block; 57, 58; 57, 65; 57, 71; 58, import_from_statement; 58, 59; 58, 63; 59, relative_import; 59, 60; 59, 61; 60, import_prefix; 61, dotted_name; 61, 62; 62, identifier:mambutransaction; 63, dotted_name; 63, 64; 64, identifier:MambuTransactions; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:mambutransactionsclass; 70, identifier:MambuTransactions; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:trans; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:mambutransactionsclass; 78, argument_list; 78, 79; 78, 84; 78, 86; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:entid; 81, subscript; 81, 82; 81, 83; 82, identifier:self; 83, string:'id'; 84, list_splat; 84, 85; 85, identifier:args; 86, dictionary_splat; 86, 87; 87, identifier:kwargs; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:trans; 92, identifier:attrs; 93, call; 93, 94; 93, 95; 94, identifier:sorted; 95, argument_list; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:trans; 98, identifier:attrs; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:key; 101, identifier:transactionid; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:self; 106, string:'transactions'; 107, identifier:trans; 108, return_statement; 108, 109; 109, integer:1
def setTransactions(self, *args, **kwargs): """Adds the transactions for this loan to a 'transactions' field. Transactions are MambuTransaction objects. Transactions get sorted by transaction id. Returns the number of requests done to Mambu. .. todo:: since pagination logic was added, is not always true that just 1 request was done. It may be more! But since request counter singleton holds true information about how many requests were done to Mambu, in fact this return value may be obsolete """ def transactionid(transaction): """Util function used for sorting transactions according to id""" try: return transaction['transactionId'] except KeyError as kerr: return None try: trans = self.mambutransactionsclass(entid=self['id'], *args, **kwargs) except AttributeError as ae: from .mambutransaction import MambuTransactions self.mambutransactionsclass = MambuTransactions trans = self.mambutransactionsclass(entid=self['id'], *args, **kwargs) trans.attrs = sorted(trans.attrs, key=transactionid) self['transactions'] = trans return 1
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_filter; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:environ; 6, identifier:params; 7, block; 7, 8; 7, 10; 7, 11; 7, 71; 7, 72; 7, 73; 7, 77; 7, 100; 7, 101; 7, 102; 7, 110; 7, 111; 7, 112; 7, 113; 7, 133; 7, 134; 7, 143; 7, 144; 7, 151; 7, 158; 7, 159; 7, 167; 7, 168; 7, 169; 7, 170; 7, 171; 7, 181; 7, 182; 7, 193; 7, 209; 7, 224; 7, 225; 7, 239; 7, 254; 7, 255; 7, 256; 7, 396; 7, 397; 7, 411; 7, 412; 7, 413; 7, 414; 7, 445; 7, 446; 7, 447; 7, 456; 7, 474; 7, 475; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, if_statement; 11, 12; 11, 15; 11, 16; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:queries; 15, comment; 16, block; 16, 17; 16, 24; 16, 25; 16, 26; 16, 50; 16, 51; 16, 60; 17, if_statement; 17, 18; 17, 21; 18, comparison_operator:not; 18, 19; 18, 20; 19, string:'QUERY_STRING'; 20, identifier:environ; 21, block; 21, 22; 22, return_statement; 22, 23; 23, False; 24, comment; 25, comment; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:available; 29, call; 29, 30; 29, 31; 30, identifier:set; 31, generator_expression; 31, 32; 31, 40; 32, subscript; 32, 33; 32, 39; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:qstr; 36, identifier:partition; 37, argument_list; 37, 38; 38, string:'='; 39, integer:0; 40, for_in_clause; 40, 41; 40, 42; 41, identifier:qstr; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:environ; 46, string:'QUERY_STRING'; 47, identifier:split; 48, argument_list; 48, 49; 49, string:'&'; 50, comment; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:required; 54, call; 54, 55; 54, 56; 55, identifier:set; 56, argument_list; 56, 57; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:queries; 60, if_statement; 60, 61; 60, 68; 61, not_operator; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:required; 65, identifier:issubset; 66, argument_list; 66, 67; 67, identifier:available; 68, block; 68, 69; 69, return_statement; 69, 70; 70, False; 71, comment; 72, comment; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:unused; 76, dictionary; 77, for_statement; 77, 78; 77, 81; 77, 86; 78, pattern_list; 78, 79; 78, 80; 79, identifier:key; 80, identifier:value; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:params; 84, identifier:items; 85, argument_list; 86, block; 86, 87; 87, if_statement; 87, 88; 87, 93; 88, comparison_operator:not; 88, 89; 88, 90; 89, identifier:key; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:use; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:unused; 98, identifier:key; 99, identifier:value; 100, comment; 101, comment; 102, for_statement; 102, 103; 102, 104; 102, 105; 103, identifier:key; 104, identifier:unused; 105, block; 105, 106; 106, delete_statement; 106, 107; 107, subscript; 107, 108; 107, 109; 108, identifier:params; 109, identifier:key; 110, comment; 111, comment; 112, comment; 113, try_statement; 113, 114; 113, 128; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:additional; 118, boolean_operator:or; 118, 119; 118, 127; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:filter; 123, argument_list; 123, 124; 123, 125; 123, 126; 124, identifier:environ; 125, identifier:params; 126, identifier:unused; 127, dictionary; 128, except_clause; 128, 129; 128, 130; 129, identifier:DeferLimit; 130, block; 130, 131; 131, return_statement; 131, 132; 132, False; 133, comment; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:key; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:key; 141, argument_list; 141, 142; 142, identifier:params; 143, comment; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:params; 148, identifier:update; 149, argument_list; 149, 150; 150, identifier:unused; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:params; 155, identifier:update; 156, argument_list; 156, 157; 157, identifier:additional; 158, comment; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:now; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:time; 165, identifier:time; 166, argument_list; 167, comment; 168, comment; 169, comment; 170, comment; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:db; 177, identifier:expire; 178, argument_list; 178, 179; 178, 180; 179, identifier:key; 180, integer:60; 181, comment; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:update_uuid; 185, call; 185, 186; 185, 187; 186, identifier:str; 187, argument_list; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:uuid; 191, identifier:uuid4; 192, argument_list; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:update; 196, dictionary; 196, 197; 196, 200; 197, pair; 197, 198; 197, 199; 198, string:'uuid'; 199, identifier:update_uuid; 200, pair; 200, 201; 200, 202; 201, string:'update'; 202, dictionary; 202, 203; 202, 206; 203, pair; 203, 204; 203, 205; 204, string:'params'; 205, identifier:params; 206, pair; 206, 207; 206, 208; 207, string:'time'; 208, identifier:now; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 216; 211, attribute; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:db; 215, identifier:rpush; 216, argument_list; 216, 217; 216, 218; 217, identifier:key; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:msgpack; 221, identifier:dumps; 222, argument_list; 222, 223; 223, identifier:update; 224, comment; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:records; 228, call; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:db; 233, identifier:lrange; 234, argument_list; 234, 235; 234, 236; 234, 237; 235, identifier:key; 236, integer:0; 237, unary_operator:-; 237, 238; 238, integer:1; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:loader; 242, call; 242, 243; 242, 244; 243, identifier:BucketLoader; 244, argument_list; 244, 245; 244, 248; 244, 251; 244, 252; 244, 253; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:bucket_class; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:db; 251, identifier:self; 252, identifier:key; 253, identifier:records; 254, comment; 255, comment; 256, if_statement; 256, 257; 256, 260; 257, comparison_operator:in; 257, 258; 257, 259; 258, string:'turnstile.conf'; 259, identifier:environ; 260, block; 260, 261; 260, 269; 260, 289; 260, 309; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:config; 264, subscript; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:environ; 267, string:'turnstile.conf'; 268, string:'compactor'; 269, try_statement; 269, 270; 269, 280; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:max_updates; 274, call; 274, 275; 274, 276; 275, identifier:int; 276, argument_list; 276, 277; 277, subscript; 277, 278; 277, 279; 278, identifier:config; 279, string:'max_updates'; 280, except_clause; 280, 281; 280, 284; 281, tuple; 281, 282; 281, 283; 282, identifier:KeyError; 283, identifier:ValueError; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:max_updates; 288, None; 289, try_statement; 289, 290; 289, 300; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:max_age; 294, call; 294, 295; 294, 296; 295, identifier:int; 296, argument_list; 296, 297; 297, subscript; 297, 298; 297, 299; 298, identifier:config; 299, string:'max_age'; 300, except_clause; 300, 301; 300, 304; 301, tuple; 301, 302; 301, 303; 302, identifier:KeyError; 303, identifier:ValueError; 304, block; 304, 305; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 308; 307, identifier:max_age; 308, integer:600; 309, if_statement; 309, 310; 309, 320; 309, 321; 309, 322; 309, 323; 309, 324; 309, 325; 309, 326; 309, 327; 309, 328; 309, 329; 309, 330; 309, 331; 310, boolean_operator:and; 310, 311; 310, 312; 311, identifier:max_updates; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:loader; 315, identifier:need_summary; 316, argument_list; 316, 317; 316, 318; 316, 319; 317, identifier:now; 318, identifier:max_updates; 319, identifier:max_age; 320, comment; 321, comment; 322, comment; 323, comment; 324, comment; 325, comment; 326, comment; 327, comment; 328, comment; 329, comment; 330, comment; 331, block; 331, 332; 331, 351; 331, 366; 331, 367; 331, 377; 332, expression_statement; 332, 333; 333, assignment; 333, 334; 333, 335; 334, identifier:summarize; 335, call; 335, 336; 335, 337; 336, identifier:dict; 337, argument_list; 337, 338; 337, 341; 338, keyword_argument; 338, 339; 338, 340; 339, identifier:summarize; 340, identifier:now; 341, keyword_argument; 341, 342; 341, 343; 342, identifier:uuid; 343, call; 343, 344; 343, 345; 344, identifier:str; 345, argument_list; 345, 346; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:uuid; 349, identifier:uuid4; 350, argument_list; 351, expression_statement; 351, 352; 352, call; 352, 353; 352, 358; 353, attribute; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:self; 356, identifier:db; 357, identifier:rpush; 358, argument_list; 358, 359; 358, 360; 359, identifier:key; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:msgpack; 363, identifier:dumps; 364, argument_list; 364, 365; 365, identifier:summarize; 366, comment; 367, expression_statement; 367, 368; 368, assignment; 368, 369; 368, 370; 369, identifier:compactor_key; 370, call; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:config; 373, identifier:get; 374, argument_list; 374, 375; 374, 376; 375, string:'compactor_key'; 376, string:'compactor'; 377, expression_statement; 377, 378; 378, call; 378, 379; 378, 384; 379, attribute; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:self; 382, identifier:db; 383, identifier:zadd; 384, argument_list; 384, 385; 384, 386; 384, 395; 385, identifier:compactor_key; 386, call; 386, 387; 386, 388; 387, identifier:int; 388, argument_list; 388, 389; 389, call; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:math; 392, identifier:ceil; 393, argument_list; 393, 394; 394, identifier:now; 395, identifier:key; 396, comment; 397, expression_statement; 397, 398; 398, call; 398, 399; 398, 404; 399, attribute; 399, 400; 399, 403; 400, attribute; 400, 401; 400, 402; 401, identifier:self; 402, identifier:db; 403, identifier:expireat; 404, argument_list; 404, 405; 404, 406; 405, identifier:key; 406, attribute; 406, 407; 406, 410; 407, attribute; 407, 408; 407, 409; 408, identifier:loader; 409, identifier:bucket; 410, identifier:expire; 411, comment; 412, comment; 413, comment; 414, if_statement; 414, 415; 414, 420; 415, comparison_operator:is; 415, 416; 415, 419; 416, attribute; 416, 417; 416, 418; 417, identifier:loader; 418, identifier:delay; 419, None; 420, block; 420, 421; 420, 429; 421, expression_statement; 421, 422; 422, call; 422, 423; 422, 426; 423, attribute; 423, 424; 423, 425; 424, identifier:environ; 425, identifier:setdefault; 426, argument_list; 426, 427; 426, 428; 427, string:'turnstile.delay'; 428, list:[]; 429, expression_statement; 429, 430; 430, call; 430, 431; 430, 436; 431, attribute; 431, 432; 431, 435; 432, subscript; 432, 433; 432, 434; 433, identifier:environ; 434, string:'turnstile.delay'; 435, identifier:append; 436, argument_list; 436, 437; 437, tuple; 437, 438; 437, 441; 437, 442; 438, attribute; 438, 439; 438, 440; 439, identifier:loader; 440, identifier:delay; 441, identifier:self; 442, attribute; 442, 443; 442, 444; 443, identifier:loader; 444, identifier:bucket; 445, comment; 446, comment; 447, expression_statement; 447, 448; 448, assignment; 448, 449; 448, 450; 449, identifier:set_name; 450, call; 450, 451; 450, 454; 451, attribute; 451, 452; 451, 453; 452, identifier:environ; 453, identifier:get; 454, argument_list; 454, 455; 455, string:'turnstile.bucket_set'; 456, if_statement; 456, 457; 456, 458; 457, identifier:set_name; 458, block; 458, 459; 459, expression_statement; 459, 460; 460, call; 460, 461; 460, 466; 461, attribute; 461, 462; 461, 465; 462, attribute; 462, 463; 462, 464; 463, identifier:self; 464, identifier:db; 465, identifier:zadd; 466, argument_list; 466, 467; 466, 468; 466, 473; 467, identifier:set_name; 468, attribute; 468, 469; 468, 472; 469, attribute; 469, 470; 469, 471; 470, identifier:loader; 471, identifier:bucket; 472, identifier:expire; 473, identifier:key; 474, comment; 475, return_statement; 475, 476; 476, not_operator; 476, 477; 477, attribute; 477, 478; 477, 479; 478, identifier:self; 479, identifier:continue_scan
def _filter(self, environ, params): """ Performs final filtering of the request to determine if this limit applies. Returns False if the limit does not apply or if the call should not be limited, or True to apply the limit. """ # Search for required query arguments if self.queries: # No query string available if 'QUERY_STRING' not in environ: return False # Extract the list of provided query arguments from the # QUERY_STRING available = set(qstr.partition('=')[0] for qstr in environ['QUERY_STRING'].split('&')) # Check if we have the required query arguments required = set(self.queries) if not required.issubset(available): return False # Use only the parameters listed in use; we'll add the others # back later unused = {} for key, value in params.items(): if key not in self.use: unused[key] = value # Do this in a separate step so we avoid changing a # dictionary during traversal for key in unused: del params[key] # First, we need to set up any additional params required to # get the bucket. If the DeferLimit exception is thrown, no # further processing is performed. try: additional = self.filter(environ, params, unused) or {} except DeferLimit: return False # Compute the bucket key key = self.key(params) # Update the parameters... params.update(unused) params.update(additional) # Get the current time now = time.time() # Allow up to a minute to mutate the bucket record. If no # bucket exists currently, this is essentially a no-op, and # the bucket won't expire anyway, once the update record is # pushed. self.db.expire(key, 60) # Push an update record update_uuid = str(uuid.uuid4()) update = { 'uuid': update_uuid, 'update': { 'params': params, 'time': now, }, } self.db.rpush(key, msgpack.dumps(update)) # Now suck in the bucket records = self.db.lrange(key, 0, -1) loader = BucketLoader(self.bucket_class, self.db, self, key, records) # Determine if we should initialize the compactor algorithm on # this bucket if 'turnstile.conf' in environ: config = environ['turnstile.conf']['compactor'] try: max_updates = int(config['max_updates']) except (KeyError, ValueError): max_updates = None try: max_age = int(config['max_age']) except (KeyError, ValueError): max_age = 600 if max_updates and loader.need_summary(now, max_updates, max_age): # Add a summary record; we want to do this before # instructing the compactor to compact. If we did the # compactor instruction first, and a crash occurred # before adding the summarize record, the lack of # quiesence could cause two compactor threads to run # on the same bucket, leading to a race condition that # could corrupt the bucket. With this ordering, if a # crash occurs before the compactor instruction, the # maximum aging applied to summarize records will # cause this logic to eventually be retriggered, which # should allow the compactor instruction to be issued. summarize = dict(summarize=now, uuid=str(uuid.uuid4())) self.db.rpush(key, msgpack.dumps(summarize)) # Instruct the compactor to compact this record compactor_key = config.get('compactor_key', 'compactor') self.db.zadd(compactor_key, int(math.ceil(now)), key) # Set the expire on the bucket self.db.expireat(key, loader.bucket.expire) # If we found a delay, store the particulars in the # environment; this will later be sorted and an error message # corresponding to the longest delay returned. if loader.delay is not None: environ.setdefault('turnstile.delay', []) environ['turnstile.delay'].append((loader.delay, self, loader.bucket)) # Finally, if desired, add the bucket key to a desired # database set set_name = environ.get('turnstile.bucket_set') if set_name: self.db.zadd(set_name, loader.bucket.expire, key) # Should we continue the route scan? return not self.continue_scan
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 41; 2, function_name:show; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 4, identifier:items; 5, default_parameter; 5, 6; 5, 7; 6, identifier:command; 7, string:'dmenu'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:bottom; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:fast; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:case_insensitive; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:lines; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:monitor; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:prompt; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:font; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:background; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:foreground; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:background_selected; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:foreground_selected; 40, None; 41, block; 41, 42; 41, 44; 41, 45; 41, 50; 41, 60; 41, 70; 41, 80; 41, 97; 41, 114; 41, 128; 41, 142; 41, 156; 41, 170; 41, 184; 41, 198; 41, 241; 41, 242; 41, 271; 41, 294; 41, 304; 41, 312; 41, 331; 41, 332; 42, expression_statement; 42, 43; 43, string:'''Present a dmenu to the user. Args: items (Iterable[str]): defines the menu items being presented to the user. items should not contain the newline character. command (Optional[str]): defines the path to the dmenu executable. Defaults to 'dmenu'. bottom (Optional[bool]): dmenu appears at the bottom of the screen. fast (Optional[bool]): dmenu grabs the keyboard before reading stdin. This is faster, but will lock up X until stdin reaches end-of-file. case_insensitive (Optional[bool]): dmenu matches menu items case insensitively. lines (Optional[int]): dmenu lists items vertically, with the given number of lines. monitor (Optional[int]): dmenu is displayed on the monitor number supplied. Monitor numbers are starting from 0. prompt (Optional[str]): defines the prompt to be displayed to the left of the input field. font (Optional[str]): defines the font or font set used. eg. "fixed" or "Monospace-12:normal" (an xft font) background (Optional[str]): defines the normal background color. #RGB, #RRGGBB, and X color names are supported. foreground (Optional[str]): defines the normal foreground color. background_selected (Optional[str]): defines the selected background color. foreground_selected (Optional[str]): defines the selected foreground color. Raises: DmenuCommandError DmenuUsageError Returns: The user's selected menu item, their own typed item, or None if they hit escape. Examples: >>> import dmenu >>> dmenu.show(['a', 'b', 'c']) 'a' # user selected a >>> dmenu.show(['a', 'b', 'c'], prompt='pick a letter') 'b' # user selected b >>> dmenu.show(['a', 'b', 'c']) None # user hit escape >>> dmenu.show(['a', 'b', 'c']) 'd' # user typed their own selection, d >>> dmenu.show(['a', 'b', 'c'], command='not_a_valid_dmenu') Traceback (most recent call last): ... dmenu.dmenu.DmenuCommandError: The provided dmenu command could not be used (['not_a_valid_dmenu']): [Errno 2] No such file or directory: 'not_a_valid_dmenu' >>> dmenu.show(['a', 'b', 'c'], monitor=2) Traceback (most recent call last): ... dmenu.dmenu.DmenuUsageError: This version of dmenu does not support your usage (['dmenu', '-m', '2']): usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-nb color] [-nf color] [-sb color] [-sf color] [-v] Consider configuring show using partial application: >>> import functools >>> show = functools.partial(dmenu.show, bottom=True) >>> show(['we', 'show', 'up', 'below']) >>> show(['us', 'too']) '''; 44, comment; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:args; 48, list:[command]; 48, 49; 49, identifier:command; 50, if_statement; 50, 51; 50, 52; 51, identifier:bottom; 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:'-b'; 60, if_statement; 60, 61; 60, 62; 61, identifier:fast; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:args; 67, identifier:append; 68, argument_list; 68, 69; 69, string:'-f'; 70, if_statement; 70, 71; 70, 72; 71, identifier:case_insensitive; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:args; 77, identifier:append; 78, argument_list; 78, 79; 79, string:'-i'; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:is; 81, 82; 81, 83; 82, identifier:lines; 83, None; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:args; 89, identifier:extend; 90, argument_list; 90, 91; 91, tuple; 91, 92; 91, 93; 92, string:'-l'; 93, call; 93, 94; 93, 95; 94, identifier:str; 95, argument_list; 95, 96; 96, identifier:lines; 97, if_statement; 97, 98; 97, 101; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:monitor; 100, None; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:args; 106, identifier:extend; 107, argument_list; 107, 108; 108, tuple; 108, 109; 108, 110; 109, string:'-m'; 110, call; 110, 111; 110, 112; 111, identifier:str; 112, argument_list; 112, 113; 113, identifier:monitor; 114, if_statement; 114, 115; 114, 118; 115, comparison_operator:is; 115, 116; 115, 117; 116, identifier:prompt; 117, None; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:args; 123, identifier:extend; 124, argument_list; 124, 125; 125, tuple; 125, 126; 125, 127; 126, string:'-p'; 127, identifier:prompt; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:is; 129, 130; 129, 131; 130, identifier:font; 131, None; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:args; 137, identifier:extend; 138, argument_list; 138, 139; 139, tuple; 139, 140; 139, 141; 140, string:'-fn'; 141, identifier:font; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:is; 143, 144; 143, 145; 144, identifier:background; 145, None; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:args; 151, identifier:extend; 152, argument_list; 152, 153; 153, tuple; 153, 154; 153, 155; 154, string:'-nb'; 155, identifier:background; 156, if_statement; 156, 157; 156, 160; 157, comparison_operator:is; 157, 158; 157, 159; 158, identifier:foreground; 159, None; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:args; 165, identifier:extend; 166, argument_list; 166, 167; 167, tuple; 167, 168; 167, 169; 168, string:'-nf'; 169, identifier:foreground; 170, if_statement; 170, 171; 170, 174; 171, comparison_operator:is; 171, 172; 171, 173; 172, identifier:background_selected; 173, None; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:args; 179, identifier:extend; 180, argument_list; 180, 181; 181, tuple; 181, 182; 181, 183; 182, string:'-sb'; 183, identifier:background_selected; 184, if_statement; 184, 185; 184, 188; 185, comparison_operator:is; 185, 186; 185, 187; 186, identifier:foreground_selected; 187, None; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:args; 193, identifier:extend; 194, argument_list; 194, 195; 195, tuple; 195, 196; 195, 197; 196, string:'-sf'; 197, identifier:foreground_selected; 198, try_statement; 198, 199; 198, 200; 198, 228; 199, comment; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:proc; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:subprocess; 207, identifier:Popen; 208, argument_list; 208, 209; 208, 210; 208, 213; 208, 218; 208, 223; 209, identifier:args; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:universal_newlines; 212, True; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:stdin; 215, attribute; 215, 216; 215, 217; 216, identifier:subprocess; 217, identifier:PIPE; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:stdout; 220, attribute; 220, 221; 220, 222; 221, identifier:subprocess; 222, identifier:PIPE; 223, keyword_argument; 223, 224; 223, 225; 224, identifier:stderr; 225, attribute; 225, 226; 225, 227; 226, identifier:subprocess; 227, identifier:PIPE; 228, except_clause; 228, 229; 228, 233; 228, 234; 229, as_pattern; 229, 230; 229, 231; 230, identifier:OSError; 231, as_pattern_target; 231, 232; 232, identifier:err; 233, comment; 234, block; 234, 235; 235, raise_statement; 235, 236; 236, call; 236, 237; 236, 238; 237, identifier:DmenuCommandError; 238, argument_list; 238, 239; 238, 240; 239, identifier:args; 240, identifier:err; 241, comment; 242, with_statement; 242, 243; 242, 248; 243, with_clause; 243, 244; 244, with_item; 244, 245; 245, attribute; 245, 246; 245, 247; 246, identifier:proc; 247, identifier:stdin; 248, block; 248, 249; 249, for_statement; 249, 250; 249, 251; 249, 252; 250, identifier:item; 251, identifier:items; 252, block; 252, 253; 252, 262; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:proc; 258, identifier:stdin; 259, identifier:write; 260, argument_list; 260, 261; 261, identifier:item; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 269; 264, attribute; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:proc; 267, identifier:stdin; 268, identifier:write; 269, argument_list; 269, 270; 270, string:'\n'; 271, if_statement; 271, 272; 271, 279; 271, 280; 272, comparison_operator:==; 272, 273; 272, 278; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:proc; 276, identifier:wait; 277, argument_list; 278, integer:0; 279, comment; 280, block; 280, 281; 281, return_statement; 281, 282; 282, call; 282, 283; 282, 292; 283, attribute; 283, 284; 283, 291; 284, call; 284, 285; 284, 290; 285, attribute; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:proc; 288, identifier:stdout; 289, identifier:read; 290, argument_list; 291, identifier:rstrip; 292, argument_list; 292, 293; 293, string:'\n'; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:stderr; 297, call; 297, 298; 297, 303; 298, attribute; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:proc; 301, identifier:stderr; 302, identifier:read; 303, argument_list; 304, if_statement; 304, 305; 304, 308; 304, 309; 305, comparison_operator:==; 305, 306; 305, 307; 306, identifier:stderr; 307, string:''; 308, comment; 309, block; 309, 310; 310, return_statement; 310, 311; 311, None; 312, if_statement; 312, 313; 312, 323; 312, 324; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:re; 316, identifier:match; 317, argument_list; 317, 318; 317, 319; 317, 320; 318, string:'usage'; 319, identifier:stderr; 320, attribute; 320, 321; 320, 322; 321, identifier:re; 322, identifier:I; 323, comment; 324, block; 324, 325; 325, raise_statement; 325, 326; 326, call; 326, 327; 326, 328; 327, identifier:DmenuUsageError; 328, argument_list; 328, 329; 328, 330; 329, identifier:args; 330, identifier:stderr; 331, comment; 332, raise_statement; 332, 333; 333, call; 333, 334; 333, 335; 334, identifier:DmenuCommandError; 335, argument_list; 335, 336; 335, 337; 336, identifier:args; 337, identifier:stderr
def show( items, command='dmenu', bottom=None, fast=None, case_insensitive=None, lines=None, monitor=None, prompt=None, font=None, background=None, foreground=None, background_selected=None, foreground_selected=None): '''Present a dmenu to the user. Args: items (Iterable[str]): defines the menu items being presented to the user. items should not contain the newline character. command (Optional[str]): defines the path to the dmenu executable. Defaults to 'dmenu'. bottom (Optional[bool]): dmenu appears at the bottom of the screen. fast (Optional[bool]): dmenu grabs the keyboard before reading stdin. This is faster, but will lock up X until stdin reaches end-of-file. case_insensitive (Optional[bool]): dmenu matches menu items case insensitively. lines (Optional[int]): dmenu lists items vertically, with the given number of lines. monitor (Optional[int]): dmenu is displayed on the monitor number supplied. Monitor numbers are starting from 0. prompt (Optional[str]): defines the prompt to be displayed to the left of the input field. font (Optional[str]): defines the font or font set used. eg. "fixed" or "Monospace-12:normal" (an xft font) background (Optional[str]): defines the normal background color. #RGB, #RRGGBB, and X color names are supported. foreground (Optional[str]): defines the normal foreground color. background_selected (Optional[str]): defines the selected background color. foreground_selected (Optional[str]): defines the selected foreground color. Raises: DmenuCommandError DmenuUsageError Returns: The user's selected menu item, their own typed item, or None if they hit escape. Examples: >>> import dmenu >>> dmenu.show(['a', 'b', 'c']) 'a' # user selected a >>> dmenu.show(['a', 'b', 'c'], prompt='pick a letter') 'b' # user selected b >>> dmenu.show(['a', 'b', 'c']) None # user hit escape >>> dmenu.show(['a', 'b', 'c']) 'd' # user typed their own selection, d >>> dmenu.show(['a', 'b', 'c'], command='not_a_valid_dmenu') Traceback (most recent call last): ... dmenu.dmenu.DmenuCommandError: The provided dmenu command could not be used (['not_a_valid_dmenu']): [Errno 2] No such file or directory: 'not_a_valid_dmenu' >>> dmenu.show(['a', 'b', 'c'], monitor=2) Traceback (most recent call last): ... dmenu.dmenu.DmenuUsageError: This version of dmenu does not support your usage (['dmenu', '-m', '2']): usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-nb color] [-nf color] [-sb color] [-sf color] [-v] Consider configuring show using partial application: >>> import functools >>> show = functools.partial(dmenu.show, bottom=True) >>> show(['we', 'show', 'up', 'below']) >>> show(['us', 'too']) ''' # construct args args = [command] if bottom: args.append('-b') if fast: args.append('-f') if case_insensitive: args.append('-i') if lines is not None: args.extend(('-l', str(lines))) if monitor is not None: args.extend(('-m', str(monitor))) if prompt is not None: args.extend(('-p', prompt)) if font is not None: args.extend(('-fn', font)) if background is not None: args.extend(('-nb', background)) if foreground is not None: args.extend(('-nf', foreground)) if background_selected is not None: args.extend(('-sb', background_selected)) if foreground_selected is not None: args.extend(('-sf', foreground_selected)) try: # start the dmenu process proc = subprocess.Popen( args, universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError as err: # something went wrong with starting the process raise DmenuCommandError(args, err) # write items over to dmenu with proc.stdin: for item in items: proc.stdin.write(item) proc.stdin.write('\n') if proc.wait() == 0: # user made a selection return proc.stdout.read().rstrip('\n') stderr = proc.stderr.read() if stderr == '': # user hit escape return None if re.match('usage', stderr, re.I): # usage error raise DmenuUsageError(args, stderr) # other error from dmenu raise DmenuCommandError(args, stderr)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:clean_names; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:lines; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ensure_unique_names; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:strip_prefix; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:make_database_safe; 13, False; 14, block; 14, 15; 14, 17; 14, 21; 14, 169; 15, expression_statement; 15, 16; 16, comment; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:names; 20, dictionary; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:row; 23, identifier:lines; 24, block; 24, 25; 24, 77; 24, 152; 25, if_statement; 25, 26; 25, 27; 26, identifier:strip_prefix; 27, block; 27, 28; 27, 49; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:row; 32, string:'name'; 33, subscript; 33, 34; 33, 37; 34, subscript; 34, 35; 34, 36; 35, identifier:row; 36, string:'name'; 37, slice; 37, 38; 37, 48; 38, binary_operator:+; 38, 39; 38, 47; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:row; 43, string:'name'; 44, identifier:find; 45, argument_list; 45, 46; 46, string:'-'; 47, integer:1; 48, colon; 49, if_statement; 49, 50; 49, 55; 50, comparison_operator:is; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:row; 53, string:'indexed_by'; 54, None; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:row; 60, string:'indexed_by'; 61, subscript; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:row; 64, string:'indexed_by'; 65, slice; 65, 66; 65, 76; 66, binary_operator:+; 66, 67; 66, 75; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:row; 71, string:'indexed_by'; 72, identifier:find; 73, argument_list; 73, 74; 74, string:'-'; 75, integer:1; 76, colon; 77, if_statement; 77, 78; 77, 79; 78, identifier:ensure_unique_names; 79, block; 79, 80; 79, 84; 79, 110; 79, 132; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:i; 83, integer:1; 84, while_statement; 84, 85; 84, 105; 85, comparison_operator:in; 85, 86; 85, 104; 86, parenthesized_expression; 86, 87; 87, conditional_expression:if; 87, 88; 87, 91; 87, 94; 88, subscript; 88, 89; 88, 90; 89, identifier:row; 90, string:'name'; 91, comparison_operator:==; 91, 92; 91, 93; 92, identifier:i; 93, integer:1; 94, binary_operator:+; 94, 95; 94, 100; 95, binary_operator:+; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:row; 98, string:'name'; 99, string:"-"; 100, call; 100, 101; 100, 102; 101, identifier:str; 102, argument_list; 102, 103; 103, identifier:i; 104, identifier:names; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, augmented_assignment:+=; 107, 108; 107, 109; 108, identifier:i; 109, integer:1; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 131; 112, subscript; 112, 113; 112, 114; 113, identifier:names; 114, conditional_expression:if; 114, 115; 114, 118; 114, 121; 115, subscript; 115, 116; 115, 117; 116, identifier:row; 117, string:'name'; 118, comparison_operator:==; 118, 119; 118, 120; 119, identifier:i; 120, integer:1; 121, binary_operator:+; 121, 122; 121, 127; 122, binary_operator:+; 122, 123; 122, 126; 123, subscript; 123, 124; 123, 125; 124, identifier:row; 125, string:'name'; 126, string:"-"; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:i; 131, integer:1; 132, if_statement; 132, 133; 132, 136; 133, comparison_operator:>; 133, 134; 133, 135; 134, identifier:i; 135, integer:1; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:row; 141, string:'name'; 142, binary_operator:+; 142, 143; 142, 148; 143, binary_operator:+; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:row; 146, string:'name'; 147, string:"-"; 148, call; 148, 149; 148, 150; 149, identifier:str; 150, argument_list; 150, 151; 151, identifier:i; 152, if_statement; 152, 153; 152, 154; 153, identifier:make_database_safe; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:row; 159, string:'name'; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, subscript; 162, 163; 162, 164; 163, identifier:row; 164, string:'name'; 165, identifier:replace; 166, argument_list; 166, 167; 166, 168; 167, string:"-"; 168, string:"_"; 169, return_statement; 169, 170; 170, identifier:lines
def clean_names(lines, ensure_unique_names=False, strip_prefix=False, make_database_safe=False): """ Clean the names. Options to: - strip prefixes on names - enforce unique names - make database safe names by converting - to _ """ names = {} for row in lines: if strip_prefix: row['name'] = row['name'][row['name'].find('-') + 1:] if row['indexed_by'] is not None: row['indexed_by'] = row['indexed_by'][row['indexed_by'].find( '-') + 1:] if ensure_unique_names: i = 1 while (row['name'] if i == 1 else row['name'] + "-" + str(i)) in names: i += 1 names[row['name'] if i == 1 else row['name'] + "-" + str(i)] = 1 if i > 1: row['name'] = row['name'] + "-" + str(i) if make_database_safe: row['name'] = row['name'].replace("-", "_") return lines
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:do_help; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:arg; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 11; 9, 12; 9, 88; 10, identifier:arg; 11, comment; 12, block; 12, 13; 12, 84; 13, try_statement; 13, 14; 13, 25; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:func; 18, call; 18, 19; 18, 20; 19, identifier:getattr; 20, argument_list; 20, 21; 20, 22; 21, identifier:self; 22, binary_operator:+; 22, 23; 22, 24; 23, string:'help_'; 24, identifier:arg; 25, except_clause; 25, 26; 25, 27; 26, identifier:AttributeError; 27, block; 27, 28; 27, 64; 27, 83; 28, try_statement; 28, 29; 28, 60; 29, block; 29, 30; 29, 42; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:doc; 33, attribute; 33, 34; 33, 41; 34, call; 34, 35; 34, 36; 35, identifier:getattr; 36, argument_list; 36, 37; 36, 38; 37, identifier:self; 38, binary_operator:+; 38, 39; 38, 40; 39, string:'do_'; 40, identifier:arg; 41, identifier:__doc__; 42, if_statement; 42, 43; 42, 44; 43, identifier:doc; 44, block; 44, 45; 44, 59; 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:stdout; 51, identifier:write; 52, argument_list; 52, 53; 53, binary_operator:%; 53, 54; 53, 55; 54, string:"%s\n"; 55, call; 55, 56; 55, 57; 56, identifier:str; 57, argument_list; 57, 58; 58, identifier:doc; 59, return_statement; 60, except_clause; 60, 61; 60, 62; 61, identifier:AttributeError; 62, block; 62, 63; 63, pass_statement; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:stdout; 70, identifier:write; 71, argument_list; 71, 72; 72, binary_operator:%; 72, 73; 72, 74; 73, string:"%s\n"; 74, call; 74, 75; 74, 76; 75, identifier:str; 76, argument_list; 76, 77; 77, binary_operator:%; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:nohelp; 81, tuple; 81, 82; 82, identifier:arg; 83, return_statement; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:func; 87, argument_list; 88, else_clause; 88, 89; 89, block; 89, 90; 89, 98; 89, 102; 89, 106; 89, 110; 89, 133; 89, 139; 89, 140; 89, 144; 89, 216; 89, 232; 89, 244; 89, 263; 89, 275; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:names; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:get_names; 97, argument_list; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:cmds_doc; 101, list:[]; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:cmds_undoc; 105, list:[]; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:help_page; 109, dictionary; 110, for_statement; 110, 111; 110, 112; 110, 113; 111, identifier:name; 112, identifier:names; 113, block; 113, 114; 114, if_statement; 114, 115; 114, 122; 115, comparison_operator:==; 115, 116; 115, 121; 116, subscript; 116, 117; 116, 118; 117, identifier:name; 118, slice; 118, 119; 118, 120; 119, colon; 120, integer:5; 121, string:'help_'; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 132; 125, subscript; 125, 126; 125, 127; 126, identifier:help_page; 127, subscript; 127, 128; 127, 129; 128, identifier:name; 129, slice; 129, 130; 129, 131; 130, integer:5; 131, colon; 132, integer:1; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:names; 137, identifier:sort; 138, argument_list; 139, comment; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:prevname; 143, string:''; 144, for_statement; 144, 145; 144, 146; 144, 147; 145, identifier:name; 146, identifier:names; 147, block; 147, 148; 148, if_statement; 148, 149; 148, 156; 149, comparison_operator:==; 149, 150; 149, 155; 150, subscript; 150, 151; 150, 152; 151, identifier:name; 152, slice; 152, 153; 152, 154; 153, colon; 154, integer:3; 155, string:'do_'; 156, block; 156, 157; 156, 163; 156, 167; 156, 175; 157, if_statement; 157, 158; 157, 161; 158, comparison_operator:==; 158, 159; 158, 160; 159, identifier:name; 160, identifier:prevname; 161, block; 161, 162; 162, continue_statement; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:prevname; 166, identifier:name; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:cmd; 170, subscript; 170, 171; 170, 172; 171, identifier:name; 172, slice; 172, 173; 172, 174; 173, integer:3; 174, colon; 175, if_statement; 175, 176; 175, 179; 175, 191; 175, 207; 176, comparison_operator:in; 176, 177; 176, 178; 177, identifier:cmd; 178, identifier:help_page; 179, block; 179, 180; 179, 187; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:cmds_doc; 184, identifier:append; 185, argument_list; 185, 186; 186, identifier:cmd; 187, delete_statement; 187, 188; 188, subscript; 188, 189; 188, 190; 189, identifier:help_page; 190, identifier:cmd; 191, elif_clause; 191, 192; 191, 199; 192, attribute; 192, 193; 192, 198; 193, call; 193, 194; 193, 195; 194, identifier:getattr; 195, argument_list; 195, 196; 195, 197; 196, identifier:self; 197, identifier:name; 198, identifier:__doc__; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:cmds_doc; 204, identifier:append; 205, argument_list; 205, 206; 206, identifier:cmd; 207, else_clause; 207, 208; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:cmds_undoc; 213, identifier:append; 214, argument_list; 214, 215; 215, identifier:cmd; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:stdout; 222, identifier:write; 223, argument_list; 223, 224; 224, binary_operator:%; 224, 225; 224, 226; 225, string:"%s\n"; 226, call; 226, 227; 226, 228; 227, identifier:str; 228, argument_list; 228, 229; 229, attribute; 229, 230; 229, 231; 230, identifier:self; 231, identifier:doc_leader; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:print_topics; 237, argument_list; 237, 238; 237, 241; 237, 242; 237, 243; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:doc_header; 241, identifier:cmds_doc; 242, integer:15; 243, integer:80; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:print_topics; 249, argument_list; 249, 250; 249, 253; 249, 261; 249, 262; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:misc_header; 253, call; 253, 254; 253, 255; 254, identifier:list; 255, argument_list; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:help_page; 259, identifier:keys; 260, argument_list; 261, integer:15; 262, integer:80; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:print_topics; 268, argument_list; 268, 269; 268, 272; 268, 273; 268, 274; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:undoc_header; 272, identifier:cmds_undoc; 273, integer:15; 274, integer:80; 275, for_statement; 275, 276; 275, 277; 275, 280; 276, identifier:topic; 277, attribute; 277, 278; 277, 279; 278, identifier:self; 279, identifier:command_topics; 280, block; 280, 281; 280, 289; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:topic_cmds; 284, subscript; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:self; 287, identifier:command_topics; 288, identifier:topic; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:self; 293, identifier:print_topics; 294, argument_list; 294, 295; 294, 303; 294, 304; 294, 305; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:string; 298, identifier:capwords; 299, argument_list; 299, 300; 300, binary_operator:+; 300, 301; 300, 302; 301, identifier:topic; 302, string:" commands"; 303, identifier:topic_cmds; 304, integer:15; 305, integer:80
def do_help(self, arg): """List available commands with "help" or detailed help with "help cmd".""" if arg: # XXX check arg syntax try: func = getattr(self, 'help_' + arg) except AttributeError: try: doc = getattr(self, 'do_' + arg).__doc__ if doc: self.stdout.write("%s\n" % str(doc)) return except AttributeError: pass self.stdout.write("%s\n" % str(self.nohelp % (arg,))) return func() else: names = self.get_names() cmds_doc = [] cmds_undoc = [] help_page = {} for name in names: if name[:5] == 'help_': help_page[name[5:]] = 1 names.sort() # There can be duplicates if routines overridden prevname = '' for name in names: if name[:3] == 'do_': if name == prevname: continue prevname = name cmd = name[3:] if cmd in help_page: cmds_doc.append(cmd) del help_page[cmd] elif getattr(self, name).__doc__: cmds_doc.append(cmd) else: cmds_undoc.append(cmd) self.stdout.write("%s\n" % str(self.doc_leader)) self.print_topics(self.doc_header, cmds_doc, 15, 80) self.print_topics(self.misc_header, list(help_page.keys()), 15, 80) self.print_topics(self.undoc_header, cmds_undoc, 15, 80) for topic in self.command_topics: topic_cmds = self.command_topics[topic] self.print_topics(string.capwords(topic + " commands"), topic_cmds, 15, 80)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:make_echoicefield; 3, parameters; 3, 4; 3, 5; 3, 7; 3, 10; 4, identifier:echoices; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, default_parameter; 7, 8; 7, 9; 8, identifier:klass_name; 9, None; 10, dictionary_splat_pattern; 10, 11; 11, identifier:kwargs; 12, block; 12, 13; 12, 15; 12, 21; 12, 29; 12, 82; 12, 114; 12, 144; 12, 153; 12, 165; 13, expression_statement; 13, 14; 14, comment; 15, assert_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:issubclass; 18, argument_list; 18, 19; 18, 20; 19, identifier:echoices; 20, identifier:EChoice; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:value_type; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:echoices; 27, identifier:__getvaluetype__; 28, argument_list; 29, if_statement; 29, 30; 29, 33; 29, 40; 29, 51; 29, 62; 29, 73; 30, comparison_operator:is; 30, 31; 30, 32; 31, identifier:value_type; 32, identifier:str; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:cls_; 37, attribute; 37, 38; 37, 39; 38, identifier:models; 39, identifier:CharField; 40, elif_clause; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:value_type; 43, identifier:int; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:cls_; 48, attribute; 48, 49; 48, 50; 49, identifier:models; 50, identifier:IntegerField; 51, elif_clause; 51, 52; 51, 55; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:value_type; 54, identifier:float; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:cls_; 59, attribute; 59, 60; 59, 61; 60, identifier:models; 61, identifier:FloatField; 62, elif_clause; 62, 63; 62, 66; 63, comparison_operator:is; 63, 64; 63, 65; 64, identifier:value_type; 65, identifier:bool; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:cls_; 70, attribute; 70, 71; 70, 72; 71, identifier:models; 72, identifier:BooleanField; 73, else_clause; 73, 74; 74, block; 74, 75; 75, raise_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:NotImplementedError; 78, argument_list; 78, 79; 79, concatenated_string; 79, 80; 79, 81; 80, string:"Please open an issue if you wish your value type to be supported: "; 81, string:"https://github.com/mbourqui/django-echoices/issues/new"; 82, if_statement; 82, 83; 82, 96; 83, boolean_operator:and; 83, 84; 83, 85; 84, identifier:klass_name; 85, comparison_operator:<; 85, 86; 85, 92; 86, call; 86, 87; 86, 88; 87, identifier:StrictVersion; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:django_version; 91, argument_list; 92, call; 92, 93; 92, 94; 93, identifier:StrictVersion; 94, argument_list; 94, 95; 95, string:'1.9.0'; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:warnings; 101, identifier:warn; 102, argument_list; 102, 103; 102, 113; 103, call; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, concatenated_string; 105, 106; 105, 107; 106, string:"Django < 1.9 throws an 'ImportError' if the class name is not defined in the module. "; 107, string:"The provided klass_name will be replaced by {}"; 108, identifier:format; 109, argument_list; 109, 110; 110, attribute; 110, 111; 110, 112; 111, identifier:EChoiceField; 112, identifier:__name__; 113, identifier:RuntimeWarning; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:klass_name; 117, conditional_expression:if; 117, 118; 117, 121; 117, 132; 117, 133; 118, attribute; 118, 119; 118, 120; 119, identifier:EChoiceField; 120, identifier:__name__; 121, comparison_operator:<; 121, 122; 121, 128; 122, call; 122, 123; 122, 124; 123, identifier:StrictVersion; 124, argument_list; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:django_version; 127, argument_list; 128, call; 128, 129; 128, 130; 129, identifier:StrictVersion; 130, argument_list; 130, 131; 131, string:'1.9.0'; 132, line_continuation:\; 133, conditional_expression:if; 133, 134; 133, 135; 133, 136; 134, identifier:klass_name; 135, identifier:klass_name; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, string:"{}Field"; 139, identifier:format; 140, argument_list; 140, 141; 141, attribute; 141, 142; 141, 143; 142, identifier:echoices; 143, identifier:__name__; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:d; 147, call; 147, 148; 147, 149; 148, identifier:dict; 149, argument_list; 149, 150; 150, attribute; 150, 151; 150, 152; 151, identifier:cls_; 152, identifier:__dict__; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:d; 157, identifier:update; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 161; 160, identifier:dict; 161, argument_list; 161, 162; 162, attribute; 162, 163; 162, 164; 163, identifier:EChoiceField; 164, identifier:__dict__; 165, return_statement; 165, 166; 166, call; 166, 167; 166, 174; 167, call; 167, 168; 167, 169; 168, identifier:type; 169, argument_list; 169, 170; 169, 171; 169, 173; 170, identifier:klass_name; 171, tuple; 171, 172; 172, identifier:cls_; 173, identifier:d; 174, argument_list; 174, 175; 174, 176; 174, 178; 175, identifier:echoices; 176, list_splat; 176, 177; 177, identifier:args; 178, dictionary_splat; 178, 179; 179, identifier:kwargs
def make_echoicefield(echoices, *args, klass_name=None, **kwargs): """ Construct a subclass of a derived `models.Field` specific to the type of the `EChoice` values. Parameters ---------- echoices : subclass of EChoice args Passed to the derived `models.Field` klass_name : str Give a specific name to the returned class. By default for Django < 1.9, the name will be 'EChoiceField'. By default for Django >= 1.9, the name will be the name of the enum appended with 'Field'. kwargs Passed to the derived `models.Field` Returns ------- EChoiceField For Django>=1.9, the exact name of the returned Field is based on the name of the `echoices` with a suffixed 'Field'. For older Django, the returned name of the class is `EChoiceField`. """ assert issubclass(echoices, EChoice) value_type = echoices.__getvaluetype__() if value_type is str: cls_ = models.CharField elif value_type is int: cls_ = models.IntegerField elif value_type is float: cls_ = models.FloatField elif value_type is bool: cls_ = models.BooleanField else: raise NotImplementedError("Please open an issue if you wish your value type to be supported: " "https://github.com/mbourqui/django-echoices/issues/new") if klass_name and StrictVersion(django_version()) < StrictVersion('1.9.0'): warnings.warn("Django < 1.9 throws an 'ImportError' if the class name is not defined in the module. " "The provided klass_name will be replaced by {}".format(EChoiceField.__name__), RuntimeWarning) klass_name = EChoiceField.__name__ if StrictVersion(django_version()) < StrictVersion('1.9.0') else \ klass_name if klass_name else "{}Field".format(echoices.__name__) d = dict(cls_.__dict__) d.update(dict(EChoiceField.__dict__)) return type(klass_name, (cls_,), d)(echoices, *args, **kwargs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:make_dummy; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 17; 3, 20; 3, 23; 3, 26; 3, 28; 4, identifier:instance; 5, default_parameter; 5, 6; 5, 7; 6, identifier:relations; 7, dictionary; 8, default_parameter; 8, 9; 8, 10; 9, identifier:datetime_default; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:dt; 13, identifier:strptime; 14, argument_list; 14, 15; 14, 16; 15, string:'1901-01-01'; 16, string:'%Y-%m-%d'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:varchar_default; 19, string:""; 20, default_parameter; 20, 21; 20, 22; 21, identifier:integer_default; 22, integer:0; 23, default_parameter; 23, 24; 23, 25; 24, identifier:numeric_default; 25, float:0.0; 26, list_splat_pattern; 26, 27; 27, identifier:args; 28, dictionary_splat_pattern; 28, 29; 29, identifier:kwargs; 30, block; 30, 31; 30, 33; 30, 34; 30, 53; 30, 54; 30, 61; 30, 104; 30, 136; 31, expression_statement; 31, 32; 32, comment; 33, comment; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:init_data; 37, dictionary; 37, 38; 37, 41; 37, 44; 37, 47; 37, 50; 38, pair; 38, 39; 38, 40; 39, string:'DATETIME'; 40, identifier:datetime_default; 41, pair; 41, 42; 41, 43; 42, string:'VARCHAR'; 43, identifier:varchar_default; 44, pair; 44, 45; 44, 46; 45, string:'INTEGER'; 46, identifier:integer_default; 47, pair; 47, 48; 47, 49; 48, string:'NUMERIC(50, 10)'; 49, identifier:numeric_default; 50, pair; 50, 51; 50, 52; 51, string:'TEXT'; 52, identifier:varchar_default; 53, comment; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:table; 57, call; 57, 58; 57, 59; 58, identifier:type; 59, argument_list; 59, 60; 60, identifier:instance; 61, for_statement; 61, 62; 61, 63; 61, 68; 61, 69; 62, identifier:col; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:table; 66, identifier:__table__; 67, identifier:columns; 68, comment; 69, block; 69, 70; 70, try_statement; 70, 71; 70, 85; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:setattr; 75, argument_list; 75, 76; 75, 77; 75, 80; 76, identifier:instance; 77, attribute; 77, 78; 77, 79; 78, identifier:col; 79, identifier:name; 80, subscript; 80, 81; 80, 82; 81, identifier:kwargs; 82, attribute; 82, 83; 82, 84; 83, identifier:col; 84, identifier:name; 85, except_clause; 85, 86; 85, 87; 86, identifier:KeyError; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:setattr; 91, argument_list; 91, 92; 91, 93; 91, 96; 92, identifier:instance; 93, attribute; 93, 94; 93, 95; 94, identifier:col; 95, identifier:name; 96, subscript; 96, 97; 96, 98; 97, identifier:init_data; 98, call; 98, 99; 98, 100; 99, identifier:str; 100, argument_list; 100, 101; 101, attribute; 101, 102; 101, 103; 102, identifier:col; 103, identifier:type; 104, for_statement; 104, 105; 104, 108; 104, 113; 104, 114; 105, pattern_list; 105, 106; 105, 107; 106, identifier:k; 107, identifier:v; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:relations; 111, identifier:iteritems; 112, argument_list; 113, comment; 114, block; 114, 115; 114, 124; 114, 125; 114, 126; 114, 127; 114, 128; 114, 129; 114, 130; 114, 131; 114, 132; 114, 133; 114, 134; 114, 135; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:setattr; 118, argument_list; 118, 119; 118, 120; 118, 121; 119, identifier:instance; 120, identifier:k; 121, subscript; 121, 122; 121, 123; 122, identifier:v; 123, integer:0; 124, comment; 125, comment; 126, comment; 127, comment; 128, comment; 129, comment; 130, comment; 131, comment; 132, comment; 133, comment; 134, comment; 135, comment; 136, return_statement; 136, 137; 137, identifier:instance
def make_dummy(instance, relations = {}, datetime_default = dt.strptime('1901-01-01','%Y-%m-%d'), varchar_default = "", integer_default = 0, numeric_default = 0.0, *args, **kwargs ): """Make an instance to look like an empty dummy. Every field of the table is set with zeroes/empty strings. Date fields are set to 01/01/1901. * relations is a dictionary to set properties for relationships on the instance. The keys of the relations dictionary are the name of the fields to be set at the instance. The values of the relations dictionary must be 2 dimension tuples: - first element will be the element to be related. - second element will be the name of the backref set on the previous first element of the tuple, as a list containing the instance. If you wish that no backref to be set you may use any invalid value for a property name, anything other than a string, for example a number. Preferably, use None. * datetime_default is the datetime object to use for init datetime fields. Defaults to 01-01-1901 * varchar_default is the string object to use for init varchar fields. Defaults to "" * integer_default is the int object to use for init integer fields. Defaults to 0 * numeric_default is the float object to use for init numeric fields. Defaults to 0.0 * kwargs may have the name of a certain field you wish to initialize with a value other than the given by the init_data dicionary. If you give an unexistent name on the columns of the table, they are safely ignored. .. todo:: further field types may be set at the init_data dictionary. """ # init_data knows how to put an init value depending on data type init_data = { 'DATETIME' : datetime_default, 'VARCHAR' : varchar_default, 'INTEGER' : integer_default, 'NUMERIC(50, 10)' : numeric_default, 'TEXT' : varchar_default, } # the type of the instance is the SQLAlchemy Table table = type(instance) for col in table.__table__.columns: # declarative base tables have a columns property useful for reflection try: setattr(instance, col.name, kwargs[col.name]) except KeyError: setattr(instance, col.name, init_data[str(col.type)]) for k,v in relations.iteritems(): # set the relationship property with the first element of the tuple setattr(instance, k, v[0]) # try: # # set the relationship backref on the first element of the tuple # # with a property named according to the second element of the # # tuple, pointing to a list with the instance itself (assumes a # # one-to-many relationship) # # in case you don't want a backref, just send a None as v[1] # try: # getattr(v[0], v[1]).append(instance) # except: # setattr(v[0], v[1], [ instance ]) # except: # pass return instance
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:read_headers; 3, parameters; 3, 4; 3, 5; 4, identifier:rfile; 5, default_parameter; 5, 6; 5, 7; 6, identifier:hdict; 7, None; 8, block; 8, 9; 8, 11; 8, 20; 8, 161; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:hdict; 14, None; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:hdict; 19, dictionary; 20, while_statement; 20, 21; 20, 22; 21, True; 22, block; 22, 23; 22, 31; 22, 41; 22, 48; 22, 62; 22, 127; 22, 155; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:line; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:rfile; 29, identifier:readline; 30, argument_list; 31, if_statement; 31, 32; 31, 34; 31, 35; 32, not_operator; 32, 33; 33, identifier:line; 34, comment; 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:"Illegal end of headers."; 41, if_statement; 41, 42; 41, 45; 41, 46; 42, comparison_operator:==; 42, 43; 42, 44; 43, identifier:line; 44, identifier:CRLF; 45, comment; 46, block; 46, 47; 47, break_statement; 48, if_statement; 48, 49; 48, 56; 49, not_operator; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:line; 53, identifier:endswith; 54, argument_list; 54, 55; 55, identifier:CRLF; 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:"HTTP requires CRLF terminators"; 62, if_statement; 62, 63; 62, 68; 62, 69; 62, 78; 63, comparison_operator:in; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:line; 66, integer:0; 67, string:' \t'; 68, comment; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:v; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:line; 76, identifier:strip; 77, argument_list; 78, else_clause; 78, 79; 79, block; 79, 80; 79, 102; 79, 103; 79, 115; 79, 123; 80, try_statement; 80, 81; 80, 94; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, pattern_list; 84, 85; 84, 86; 85, identifier:k; 86, identifier:v; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:line; 90, identifier:split; 91, argument_list; 91, 92; 91, 93; 92, string:":"; 93, integer:1; 94, except_clause; 94, 95; 94, 96; 95, identifier:ValueError; 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:"Illegal header line."; 102, comment; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:k; 106, call; 106, 107; 106, 114; 107, attribute; 107, 108; 107, 113; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:k; 111, identifier:strip; 112, argument_list; 113, identifier:title; 114, argument_list; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:v; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:v; 121, identifier:strip; 122, argument_list; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:hname; 126, identifier:k; 127, if_statement; 127, 128; 127, 131; 128, comparison_operator:in; 128, 129; 128, 130; 129, identifier:k; 130, identifier:comma_separated_headers; 131, block; 131, 132; 131, 141; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:existing; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:hdict; 138, identifier:get; 139, argument_list; 139, 140; 140, identifier:hname; 141, if_statement; 141, 142; 141, 143; 142, identifier:existing; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:v; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, string:", "; 150, identifier:join; 151, argument_list; 151, 152; 152, tuple; 152, 153; 152, 154; 153, identifier:existing; 154, identifier:v; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:hdict; 159, identifier:hname; 160, identifier:v; 161, return_statement; 161, 162; 162, identifier:hdict
def read_headers(rfile, hdict=None): """Read headers from the given stream into the given header dict. If hdict is None, a new header dict is created. Returns the populated header dict. Headers which are repeated are folded together using a comma if their specification so dictates. This function raises ValueError when the read bytes violate the HTTP spec. You should probably return "400 Bad Request" if this happens. """ if hdict is None: hdict = {} while True: line = rfile.readline() if not line: # No more data--illegal end of headers raise ValueError("Illegal end of headers.") if line == CRLF: # Normal end of headers break if not line.endswith(CRLF): raise ValueError("HTTP requires CRLF terminators") if line[0] in ' \t': # It's a continuation line. v = line.strip() else: try: k, v = line.split(":", 1) except ValueError: raise ValueError("Illegal header line.") # TODO: what about TE and WWW-Authenticate? k = k.strip().title() v = v.strip() hname = k if k in comma_separated_headers: existing = hdict.get(hname) if existing: v = ", ".join((existing, v)) hdict[hname] = v return hdict
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:send_headers; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 24; 5, 37; 5, 113; 5, 162; 5, 212; 5, 232; 5, 252; 5, 269; 5, 290; 5, 297; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:hkeys; 11, list_comprehension; 11, 12; 11, 17; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:key; 15, identifier:lower; 16, argument_list; 17, for_in_clause; 17, 18; 17, 21; 18, pattern_list; 18, 19; 18, 20; 19, identifier:key; 20, identifier:value; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:outheaders; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:status; 27, call; 27, 28; 27, 29; 28, identifier:int; 29, argument_list; 29, 30; 30, subscript; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:status; 34, slice; 34, 35; 34, 36; 35, colon; 36, integer:3; 37, if_statement; 37, 38; 37, 41; 37, 42; 37, 49; 38, comparison_operator:==; 38, 39; 38, 40; 39, identifier:status; 40, integer:413; 41, comment; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:close_connection; 48, True; 49, elif_clause; 49, 50; 49, 53; 49, 54; 49, 55; 49, 56; 50, comparison_operator:not; 50, 51; 50, 52; 51, string:"content-length"; 52, identifier:hkeys; 53, comment; 54, comment; 55, comment; 56, block; 56, 57; 57, if_statement; 57, 58; 57, 68; 57, 70; 58, boolean_operator:or; 58, 59; 58, 62; 59, comparison_operator:<; 59, 60; 59, 61; 60, identifier:status; 61, integer:200; 62, comparison_operator:in; 62, 63; 62, 64; 63, identifier:status; 64, tuple; 64, 65; 64, 66; 64, 67; 65, integer:204; 66, integer:205; 67, integer:304; 68, block; 68, 69; 69, pass_statement; 70, else_clause; 70, 71; 71, block; 71, 72; 72, if_statement; 72, 73; 72, 85; 72, 86; 72, 104; 73, parenthesized_expression; 73, 74; 74, boolean_operator:and; 74, 75; 74, 80; 75, comparison_operator:==; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:response_protocol; 79, string:'HTTP/1.1'; 80, comparison_operator:!=; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:method; 84, string:'HEAD'; 85, comment; 86, block; 86, 87; 86, 93; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:chunked_write; 92, True; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:outheaders; 99, identifier:append; 100, argument_list; 100, 101; 101, tuple; 101, 102; 101, 103; 102, string:"Transfer-Encoding"; 103, string:"chunked"; 104, else_clause; 104, 105; 104, 106; 105, comment; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:close_connection; 112, True; 113, if_statement; 113, 114; 113, 117; 114, comparison_operator:not; 114, 115; 114, 116; 115, string:"connection"; 116, identifier:hkeys; 117, block; 117, 118; 118, if_statement; 118, 119; 118, 124; 118, 125; 118, 142; 119, comparison_operator:==; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:response_protocol; 123, string:'HTTP/1.1'; 124, comment; 125, block; 125, 126; 126, if_statement; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:close_connection; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 138; 133, attribute; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:outheaders; 137, identifier:append; 138, argument_list; 138, 139; 139, tuple; 139, 140; 139, 141; 140, string:"Connection"; 141, string:"close"; 142, else_clause; 142, 143; 142, 144; 143, comment; 144, block; 144, 145; 145, if_statement; 145, 146; 145, 150; 146, not_operator; 146, 147; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:close_connection; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:outheaders; 157, identifier:append; 158, argument_list; 158, 159; 159, tuple; 159, 160; 159, 161; 160, string:"Connection"; 161, string:"Keep-Alive"; 162, if_statement; 162, 163; 162, 174; 162, 175; 162, 176; 162, 177; 162, 178; 162, 179; 162, 180; 162, 181; 162, 182; 162, 183; 162, 184; 162, 185; 162, 186; 163, boolean_operator:and; 163, 164; 163, 169; 164, parenthesized_expression; 164, 165; 165, not_operator; 165, 166; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:close_connection; 169, parenthesized_expression; 169, 170; 170, not_operator; 170, 171; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:chunked_read; 174, comment; 175, comment; 176, comment; 177, comment; 178, comment; 179, comment; 180, comment; 181, comment; 182, comment; 183, comment; 184, comment; 185, comment; 186, block; 186, 187; 186, 198; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:remaining; 190, call; 190, 191; 190, 192; 191, identifier:getattr; 192, argument_list; 192, 193; 192, 196; 192, 197; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:rfile; 196, string:'remaining'; 197, integer:0; 198, if_statement; 198, 199; 198, 202; 199, comparison_operator:>; 199, 200; 199, 201; 200, identifier:remaining; 201, integer:0; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 210; 205, attribute; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:rfile; 209, identifier:read; 210, argument_list; 210, 211; 211, identifier:remaining; 212, if_statement; 212, 213; 212, 216; 213, comparison_operator:not; 213, 214; 213, 215; 214, string:"date"; 215, identifier:hkeys; 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:outheaders; 223, identifier:append; 224, argument_list; 224, 225; 225, tuple; 225, 226; 225, 227; 226, string:"Date"; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:rfc822; 230, identifier:formatdate; 231, argument_list; 232, if_statement; 232, 233; 232, 236; 233, comparison_operator:not; 233, 234; 233, 235; 234, string:"server"; 235, identifier:hkeys; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 244; 239, attribute; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:outheaders; 243, identifier:append; 244, argument_list; 244, 245; 245, tuple; 245, 246; 245, 247; 246, string:"Server"; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:server; 251, identifier:server_name; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:buf; 255, list:[self.server.protocol + " " + self.status + CRLF]; 255, 256; 256, binary_operator:+; 256, 257; 256, 268; 257, binary_operator:+; 257, 258; 257, 265; 258, binary_operator:+; 258, 259; 258, 264; 259, attribute; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:server; 263, identifier:protocol; 264, string:" "; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:status; 268, identifier:CRLF; 269, for_statement; 269, 270; 269, 273; 269, 276; 270, pattern_list; 270, 271; 270, 272; 271, identifier:k; 272, identifier:v; 273, attribute; 273, 274; 273, 275; 274, identifier:self; 275, identifier:outheaders; 276, block; 276, 277; 277, expression_statement; 277, 278; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:buf; 281, identifier:append; 282, argument_list; 282, 283; 283, binary_operator:+; 283, 284; 283, 289; 284, binary_operator:+; 284, 285; 284, 288; 285, binary_operator:+; 285, 286; 285, 287; 286, identifier:k; 287, string:": "; 288, identifier:v; 289, identifier:CRLF; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:buf; 294, identifier:append; 295, argument_list; 295, 296; 296, identifier:CRLF; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 306; 299, attribute; 299, 300; 299, 305; 300, attribute; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:self; 303, identifier:conn; 304, identifier:wfile; 305, identifier:sendall; 306, argument_list; 306, 307; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, string:""; 310, identifier:join; 311, argument_list; 311, 312; 312, identifier:buf
def send_headers(self): """Assert, process, and send the HTTP response message-headers. You must set self.status, and self.outheaders before calling this. """ hkeys = [key.lower() for key, value in self.outheaders] status = int(self.status[:3]) if status == 413: # Request Entity Too Large. Close conn to avoid garbage. self.close_connection = True elif "content-length" not in hkeys: # "All 1xx (informational), 204 (no content), # and 304 (not modified) responses MUST NOT # include a message-body." So no point chunking. if status < 200 or status in (204, 205, 304): pass else: if (self.response_protocol == 'HTTP/1.1' and self.method != 'HEAD'): # Use the chunked transfer-coding self.chunked_write = True self.outheaders.append(("Transfer-Encoding", "chunked")) else: # Closing the conn is the only way to determine len. self.close_connection = True if "connection" not in hkeys: if self.response_protocol == 'HTTP/1.1': # Both server and client are HTTP/1.1 or better if self.close_connection: self.outheaders.append(("Connection", "close")) else: # Server and/or client are HTTP/1.0 if not self.close_connection: self.outheaders.append(("Connection", "Keep-Alive")) if (not self.close_connection) and (not self.chunked_read): # Read any remaining request body data on the socket. # "If an origin server receives a request that does not include an # Expect request-header field with the "100-continue" expectation, # the request includes a request body, and the server responds # with a final status code before reading the entire request body # from the transport connection, then the server SHOULD NOT close # the transport connection until it has read the entire request, # or until the client closes the connection. Otherwise, the client # might not reliably receive the response message. However, this # requirement is not be construed as preventing a server from # defending itself against denial-of-service attacks, or from # badly broken client implementations." remaining = getattr(self.rfile, 'remaining', 0) if remaining > 0: self.rfile.read(remaining) if "date" not in hkeys: self.outheaders.append(("Date", rfc822.formatdate())) if "server" not in hkeys: self.outheaders.append(("Server", self.server.server_name)) buf = [self.server.protocol + " " + self.status + CRLF] for k, v in self.outheaders: buf.append(k + ": " + v + CRLF) buf.append(CRLF) self.conn.wfile.sendall("".join(buf))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:setActivities; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 35; 9, 90; 9, 104; 9, 110; 10, expression_statement; 10, 11; 11, comment; 12, function_definition; 12, 13; 12, 14; 12, 16; 13, function_name:activityDate; 14, parameters; 14, 15; 15, identifier:activity; 16, block; 16, 17; 16, 19; 17, expression_statement; 17, 18; 18, comment; 19, try_statement; 19, 20; 19, 27; 20, block; 20, 21; 21, return_statement; 21, 22; 22, subscript; 22, 23; 22, 26; 23, subscript; 23, 24; 23, 25; 24, identifier:activity; 25, string:'activity'; 26, string:'timestamp'; 27, except_clause; 27, 28; 27, 32; 28, as_pattern; 28, 29; 28, 30; 29, identifier:KeyError; 30, as_pattern_target; 30, 31; 31, identifier:kerr; 32, block; 32, 33; 33, return_statement; 33, 34; 34, None; 35, try_statement; 35, 36; 35, 54; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:activities; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:mambuactivitiesclass; 44, argument_list; 44, 45; 44, 50; 44, 52; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:groupId; 47, subscript; 47, 48; 47, 49; 48, identifier:self; 49, string:'encodedKey'; 50, list_splat; 50, 51; 51, identifier:args; 52, dictionary_splat; 52, 53; 53, identifier:kwargs; 54, except_clause; 54, 55; 54, 59; 55, as_pattern; 55, 56; 55, 57; 56, identifier:AttributeError; 57, as_pattern_target; 57, 58; 58, identifier:ae; 59, block; 59, 60; 59, 67; 59, 73; 60, import_from_statement; 60, 61; 60, 65; 61, relative_import; 61, 62; 61, 63; 62, import_prefix; 63, dotted_name; 63, 64; 64, identifier:mambuactivity; 65, dotted_name; 65, 66; 66, identifier:MambuActivities; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:mambuactivitiesclass; 72, identifier:MambuActivities; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:activities; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:mambuactivitiesclass; 80, argument_list; 80, 81; 80, 86; 80, 88; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:groupId; 83, subscript; 83, 84; 83, 85; 84, identifier:self; 85, string:'encodedKey'; 86, list_splat; 86, 87; 87, identifier:args; 88, dictionary_splat; 88, 89; 89, identifier:kwargs; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:activities; 94, identifier:attrs; 95, call; 95, 96; 95, 97; 96, identifier:sorted; 97, argument_list; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:activities; 100, identifier:attrs; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:key; 103, identifier:activityDate; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:self; 108, string:'activities'; 109, identifier:activities; 110, return_statement; 110, 111; 111, integer:1
def setActivities(self, *args, **kwargs): """Adds the activities for this group to a 'activities' field. Activities are MambuActivity objects. Activities get sorted by activity timestamp. Returns the number of requests done to Mambu. """ def activityDate(activity): """Util function used for sorting activities according to timestamp""" try: return activity['activity']['timestamp'] except KeyError as kerr: return None try: activities = self.mambuactivitiesclass(groupId=self['encodedKey'], *args, **kwargs) except AttributeError as ae: from .mambuactivity import MambuActivities self.mambuactivitiesclass = MambuActivities activities = self.mambuactivitiesclass(groupId=self['encodedKey'], *args, **kwargs) activities.attrs = sorted(activities.attrs, key=activityDate) self['activities'] = activities return 1
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:connect; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 17; 9, 29; 9, 53; 9, 57; 9, 64; 9, 65; 9, 71; 9, 75; 9, 79; 9, 470; 9, 498; 10, expression_statement; 10, 11; 11, comment; 12, import_from_statement; 12, 13; 12, 15; 13, dotted_name; 13, 14; 14, identifier:copy; 15, dotted_name; 15, 16; 16, identifier:deepcopy; 17, if_statement; 17, 18; 17, 19; 18, identifier:args; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:__args; 25, call; 25, 26; 25, 27; 26, identifier:deepcopy; 27, argument_list; 27, 28; 28, identifier:args; 29, if_statement; 29, 30; 29, 31; 30, identifier:kwargs; 31, block; 31, 32; 32, for_statement; 32, 33; 32, 36; 32, 41; 33, pattern_list; 33, 34; 33, 35; 34, identifier:k; 35, identifier:v; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:kwargs; 39, identifier:items; 40, argument_list; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 49; 44, subscript; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:__kwargs; 48, identifier:k; 49, call; 49, 50; 49, 51; 50, identifier:deepcopy; 51, argument_list; 51, 52; 52, identifier:v; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:jsresp; 56, dictionary; 57, if_statement; 57, 58; 57, 62; 58, not_operator; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:__urlfunc; 62, block; 62, 63; 63, return_statement; 64, comment; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:offset; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:__offset; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:window; 74, True; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:jsresp; 78, dictionary; 79, while_statement; 79, 80; 79, 81; 80, identifier:window; 81, block; 81, 82; 81, 106; 81, 107; 81, 111; 81, 433; 81, 434; 81, 440; 82, if_statement; 82, 83; 82, 93; 82, 98; 83, boolean_operator:or; 83, 84; 83, 88; 84, not_operator; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:__limit; 88, comparison_operator:>; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:__limit; 92, identifier:OUT_OF_BOUNDS_PAGINATION_LIMIT_VALUE; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:limit; 97, identifier:OUT_OF_BOUNDS_PAGINATION_LIMIT_VALUE; 98, else_clause; 98, 99; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:limit; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:__limit; 106, comment; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:retries; 110, integer:0; 111, while_statement; 111, 112; 111, 117; 111, 426; 112, comparison_operator:<; 112, 113; 112, 114; 113, identifier:retries; 114, attribute; 114, 115; 114, 116; 115, identifier:MambuStruct; 116, identifier:RETRIES; 117, block; 117, 118; 118, try_statement; 118, 119; 118, 120; 118, 399; 118, 407; 118, 418; 119, comment; 120, block; 120, 121; 120, 133; 120, 145; 120, 295; 120, 296; 120, 309; 120, 397; 120, 398; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:user; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:__kwargs; 129, identifier:get; 130, argument_list; 130, 131; 130, 132; 131, string:'user'; 132, identifier:apiuser; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:pwd; 136, call; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:__kwargs; 141, identifier:get; 142, argument_list; 142, 143; 142, 144; 143, string:'pwd'; 144, identifier:apipwd; 145, if_statement; 145, 146; 145, 149; 145, 250; 145, 251; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:__data; 149, block; 149, 150; 149, 157; 149, 171; 149, 199; 149, 200; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:headers; 153, dictionary; 153, 154; 154, pair; 154, 155; 154, 156; 155, string:'content-type'; 156, string:'application/json'; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:data; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:json; 163, identifier:dumps; 164, argument_list; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:encoded_dict; 167, argument_list; 167, 168; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:__data; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:url; 174, call; 174, 175; 174, 176; 175, identifier:iriToUri; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:__urlfunc; 181, argument_list; 181, 182; 181, 185; 181, 188; 181, 191; 181, 195; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:entid; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:limit; 187, identifier:limit; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:offset; 190, identifier:offset; 191, list_splat; 191, 192; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:__args; 195, dictionary_splat; 195, 196; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:__kwargs; 199, comment; 200, if_statement; 200, 201; 200, 206; 200, 227; 200, 228; 201, comparison_operator:==; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:__method; 205, string:"PATCH"; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:resp; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:requests; 213, identifier:patch; 214, argument_list; 214, 215; 214, 216; 214, 219; 214, 222; 215, identifier:url; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:data; 218, identifier:data; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:headers; 221, identifier:headers; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:auth; 224, tuple; 224, 225; 224, 226; 225, identifier:user; 226, identifier:pwd; 227, comment; 228, else_clause; 228, 229; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:resp; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:requests; 236, identifier:post; 237, argument_list; 237, 238; 237, 239; 237, 242; 237, 245; 238, identifier:url; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:data; 241, identifier:data; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:headers; 244, identifier:headers; 245, keyword_argument; 245, 246; 245, 247; 246, identifier:auth; 247, tuple; 247, 248; 247, 249; 248, identifier:user; 249, identifier:pwd; 250, comment; 251, else_clause; 251, 252; 252, block; 252, 253; 252, 281; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:url; 256, call; 256, 257; 256, 258; 257, identifier:iriToUri; 258, argument_list; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:__urlfunc; 263, argument_list; 263, 264; 263, 267; 263, 270; 263, 273; 263, 277; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:entid; 267, keyword_argument; 267, 268; 267, 269; 268, identifier:limit; 269, identifier:limit; 270, keyword_argument; 270, 271; 270, 272; 271, identifier:offset; 272, identifier:offset; 273, list_splat; 273, 274; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:__args; 277, dictionary_splat; 277, 278; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:__kwargs; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:resp; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:requests; 287, identifier:get; 288, argument_list; 288, 289; 288, 290; 289, identifier:url; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:auth; 292, tuple; 292, 293; 292, 294; 293, identifier:user; 294, identifier:pwd; 295, comment; 296, expression_statement; 296, 297; 297, call; 297, 298; 297, 303; 298, attribute; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:self; 301, identifier:rc; 302, identifier:add; 303, argument_list; 303, 304; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:datetime; 307, identifier:now; 308, argument_list; 309, try_statement; 309, 310; 309, 371; 309, 380; 310, block; 310, 311; 310, 322; 310, 323; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:jsonresp; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:json; 317, identifier:loads; 318, argument_list; 318, 319; 319, attribute; 319, 320; 319, 321; 320, identifier:resp; 321, identifier:content; 322, comment; 323, if_statement; 323, 324; 323, 330; 323, 360; 323, 361; 324, comparison_operator:==; 324, 325; 324, 329; 325, call; 325, 326; 325, 327; 326, identifier:type; 327, argument_list; 327, 328; 328, identifier:jsonresp; 329, identifier:list; 330, block; 330, 331; 330, 348; 331, try_statement; 331, 332; 331, 340; 332, block; 332, 333; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:jsresp; 337, identifier:extend; 338, argument_list; 338, 339; 339, identifier:jsonresp; 340, except_clause; 340, 341; 340, 342; 340, 343; 341, identifier:AttributeError; 342, comment; 343, block; 343, 344; 344, expression_statement; 344, 345; 345, assignment; 345, 346; 345, 347; 346, identifier:jsresp; 347, identifier:jsonresp; 348, if_statement; 348, 349; 348, 355; 349, comparison_operator:<; 349, 350; 349, 354; 350, call; 350, 351; 350, 352; 351, identifier:len; 352, argument_list; 352, 353; 353, identifier:jsonresp; 354, identifier:limit; 355, block; 355, 356; 356, expression_statement; 356, 357; 357, assignment; 357, 358; 357, 359; 358, identifier:window; 359, False; 360, comment; 361, else_clause; 361, 362; 362, block; 362, 363; 362, 367; 363, expression_statement; 363, 364; 364, assignment; 364, 365; 364, 366; 365, identifier:jsresp; 366, identifier:jsonresp; 367, expression_statement; 367, 368; 368, assignment; 368, 369; 368, 370; 369, identifier:window; 370, False; 371, except_clause; 371, 372; 371, 376; 371, 377; 372, as_pattern; 372, 373; 372, 374; 373, identifier:ValueError; 374, as_pattern_target; 374, 375; 375, identifier:ex; 376, comment; 377, block; 377, 378; 378, raise_statement; 378, 379; 379, identifier:ex; 380, except_clause; 380, 381; 380, 385; 380, 386; 381, as_pattern; 381, 382; 381, 383; 382, identifier:Exception; 383, as_pattern_target; 383, 384; 384, identifier:ex; 385, comment; 386, block; 386, 387; 387, raise_statement; 387, 388; 388, call; 388, 389; 388, 390; 389, identifier:MambuError; 390, argument_list; 390, 391; 391, binary_operator:%; 391, 392; 391, 393; 392, string:"JSON Error: %s"; 393, call; 393, 394; 393, 395; 394, identifier:repr; 395, argument_list; 395, 396; 396, identifier:ex; 397, comment; 398, break_statement; 399, except_clause; 399, 400; 399, 404; 400, as_pattern; 400, 401; 400, 402; 401, identifier:MambuError; 402, as_pattern_target; 402, 403; 403, identifier:merr; 404, block; 404, 405; 405, raise_statement; 405, 406; 406, identifier:merr; 407, except_clause; 407, 408; 407, 413; 408, attribute; 408, 409; 408, 412; 409, attribute; 409, 410; 409, 411; 410, identifier:requests; 411, identifier:exceptions; 412, identifier:RequestException; 413, block; 413, 414; 414, expression_statement; 414, 415; 415, augmented_assignment:+=; 415, 416; 415, 417; 416, identifier:retries; 417, integer:1; 418, except_clause; 418, 419; 418, 423; 419, as_pattern; 419, 420; 419, 421; 420, identifier:Exception; 421, as_pattern_target; 421, 422; 422, identifier:ex; 423, block; 423, 424; 424, raise_statement; 424, 425; 425, identifier:ex; 426, else_clause; 426, 427; 427, block; 427, 428; 428, raise_statement; 428, 429; 429, call; 429, 430; 429, 431; 430, identifier:MambuCommError; 431, argument_list; 431, 432; 432, string:"ERROR I can't communicate with Mambu"; 433, comment; 434, expression_statement; 434, 435; 435, assignment; 435, 436; 435, 437; 436, identifier:offset; 437, binary_operator:+; 437, 438; 437, 439; 438, identifier:offset; 439, identifier:limit; 440, if_statement; 440, 441; 440, 444; 441, attribute; 441, 442; 441, 443; 442, identifier:self; 443, identifier:__limit; 444, block; 444, 445; 444, 451; 445, expression_statement; 445, 446; 446, augmented_assignment:-=; 446, 447; 446, 450; 447, attribute; 447, 448; 447, 449; 448, identifier:self; 449, identifier:__limit; 450, identifier:limit; 451, if_statement; 451, 452; 451, 457; 452, comparison_operator:<=; 452, 453; 452, 456; 453, attribute; 453, 454; 453, 455; 454, identifier:self; 455, identifier:__limit; 456, integer:0; 457, block; 457, 458; 457, 462; 458, expression_statement; 458, 459; 459, assignment; 459, 460; 459, 461; 460, identifier:window; 461, False; 462, expression_statement; 462, 463; 463, assignment; 463, 464; 463, 467; 464, attribute; 464, 465; 464, 466; 465, identifier:self; 466, identifier:__limit; 467, attribute; 467, 468; 467, 469; 468, identifier:self; 469, identifier:__inilimit; 470, try_statement; 470, 471; 470, 494; 471, block; 471, 472; 472, if_statement; 472, 473; 472, 486; 473, boolean_operator:and; 473, 474; 473, 481; 474, boolean_operator:and; 474, 475; 474, 478; 475, comparison_operator:in; 475, 476; 475, 477; 476, string:u'returnCode'; 477, identifier:jsresp; 478, comparison_operator:in; 478, 479; 478, 480; 479, string:u'returnStatus'; 480, identifier:jsresp; 481, comparison_operator:!=; 481, 482; 481, 485; 482, subscript; 482, 483; 482, 484; 483, identifier:jsresp; 484, string:u'returnCode'; 485, integer:0; 486, block; 486, 487; 487, raise_statement; 487, 488; 488, call; 488, 489; 488, 490; 489, identifier:MambuError; 490, argument_list; 490, 491; 491, subscript; 491, 492; 491, 493; 492, identifier:jsresp; 493, string:u'returnStatus'; 494, except_clause; 494, 495; 494, 496; 495, identifier:AttributeError; 496, block; 496, 497; 497, pass_statement; 498, if_statement; 498, 499; 498, 504; 499, comparison_operator:!=; 499, 500; 499, 503; 500, attribute; 500, 501; 500, 502; 501, identifier:self; 502, identifier:__method; 503, string:"PATCH"; 504, block; 504, 505; 505, expression_statement; 505, 506; 506, call; 506, 507; 506, 510; 507, attribute; 507, 508; 507, 509; 508, identifier:self; 509, identifier:init; 510, argument_list; 510, 511; 510, 514; 510, 518; 511, keyword_argument; 511, 512; 511, 513; 512, identifier:attrs; 513, identifier:jsresp; 514, list_splat; 514, 515; 515, attribute; 515, 516; 515, 517; 516, identifier:self; 517, identifier:__args; 518, dictionary_splat; 518, 519; 519, attribute; 519, 520; 519, 521; 520, identifier:self; 521, identifier:__kwargs
def connect(self, *args, **kwargs): """Connect to Mambu, make the request to the REST API. If there's no urlfunc to use, nothing is done here. When done, initializes the attrs attribute of the Mambu object by calling the init method. Please refer to that code and pydoc for further information. Uses urllib module to connect. Since all Mambu REST API responses are json, uses json module to translate the response to a valid python object (dictionary or list). When Mambu returns a response with returnCode and returnStatus fields, it means something went wrong with the request, and a MambuError is thrown detailing the error given by Mambu itself. If you need to make a POST request, send a data argument to the new Mambu object. Provides to prevent errors due to using special chars on the request URL. See mambuutil.iriToUri() method pydoc for further info. Provides to prevent errors due to using special chars on the parameters of a POST request. See mambuutil.encoded_dict() method pydoc for further info. For every request done, the request counter Singleton is increased. Includes retry logic, to provide for a max number of connection failures with Mambu. If maximum retries are reached, MambuCommError is thrown. Includes pagination code. Mambu supports a max of 500 elements per response. Such an ugly detail is wrapped here so further pagination logic is not needed above here. You need a million elements? you got them by making several 500 elements requests later joined together in a sigle list. Just send a limit=0 (default) and that's it. .. todo:: improve raised exception messages. Sometimes MambuCommErrors are thrown due to reasons not always clear when catched down the road, but that perhaps may be noticed in here and aren't fully reported to the user. Specially serious on retries-MambuCommError situations (the except Exception that increases the retries counter is not saving the exception message, just retrying). .. todo:: what about using decorators for the retry and for the window logic? (https://www.oreilly.com/ideas/5-reasons-you-need-to-learn-to-write-python-decorators # Reusing impossible-to-reuse code) """ from copy import deepcopy if args: self.__args = deepcopy(args) if kwargs: for k,v in kwargs.items(): self.__kwargs[k] = deepcopy(v) jsresp = {} if not self.__urlfunc: return # Pagination window, Mambu restricts at most 500 elements in response offset = self.__offset window = True jsresp = {} while window: if not self.__limit or self.__limit > OUT_OF_BOUNDS_PAGINATION_LIMIT_VALUE: limit = OUT_OF_BOUNDS_PAGINATION_LIMIT_VALUE else: limit = self.__limit # Retry mechanism, for awful connections retries = 0 while retries < MambuStruct.RETRIES: try: # Basic authentication user = self.__kwargs.get('user', apiuser) pwd = self.__kwargs.get('pwd', apipwd) if self.__data: headers = {'content-type': 'application/json'} data = json.dumps(encoded_dict(self.__data)) url = iriToUri(self.__urlfunc(self.entid, limit=limit, offset=offset, *self.__args, **self.__kwargs)) # PATCH if self.__method=="PATCH": resp = requests.patch(url, data=data, headers=headers, auth=(user, pwd)) # POST else: resp = requests.post(url, data=data, headers=headers, auth=(user, pwd)) # GET else: url = iriToUri(self.__urlfunc(self.entid, limit=limit, offset=offset, *self.__args, **self.__kwargs)) resp = requests.get(url, auth=(user, pwd)) # Always count a new request when done! self.rc.add(datetime.now()) try: jsonresp = json.loads(resp.content) # Returns list: extend list for offset if type(jsonresp) == list: try: jsresp.extend(jsonresp) except AttributeError: # First window, forget that jsresp was a dict, turn it in to a list jsresp=jsonresp if len(jsonresp) < limit: window = False # Returns dict: in theory Mambu REST API doesn't takes limit/offset in to account else: jsresp = jsonresp window = False except ValueError as ex: # json.loads invalid data argument raise ex except Exception as ex: # any other json error raise MambuError("JSON Error: %s" % repr(ex)) # if we reach here, we're done and safe break except MambuError as merr: raise merr except requests.exceptions.RequestException: retries += 1 except Exception as ex: raise ex else: raise MambuCommError("ERROR I can't communicate with Mambu") # next window, moving offset... offset = offset + limit if self.__limit: self.__limit -= limit if self.__limit <= 0: window = False self.__limit = self.__inilimit try: if u'returnCode' in jsresp and u'returnStatus' in jsresp and jsresp[u'returnCode'] != 0: raise MambuError(jsresp[u'returnStatus']) except AttributeError: pass if self.__method != "PATCH": self.init(attrs=jsresp, *self.__args, **self.__kwargs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 37; 2, function_name:GetDirections; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 4, identifier:self; 5, identifier:origin; 6, identifier:destination; 7, default_parameter; 7, 8; 7, 9; 8, identifier:sensor; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:mode; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:waypoints; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:alternatives; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:avoid; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:language; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:units; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:region; 30, None; 31, default_parameter; 31, 32; 31, 33; 32, identifier:departure_time; 33, None; 34, default_parameter; 34, 35; 34, 36; 35, identifier:arrival_time; 36, None; 37, block; 37, 38; 37, 40; 37, 60; 37, 69; 37, 78; 37, 87; 37, 96; 37, 105; 37, 114; 37, 123; 37, 132; 37, 141; 37, 167; 38, expression_statement; 38, 39; 39, string:'''Get Directions Service Pls refer to the Google Maps Web API for the details of the remained parameters '''; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:params; 43, dictionary; 43, 44; 43, 47; 43, 50; 44, pair; 44, 45; 44, 46; 45, string:'origin'; 46, identifier:origin; 47, pair; 47, 48; 47, 49; 48, string:'destination'; 49, identifier:destination; 50, pair; 50, 51; 50, 52; 51, string:'sensor'; 52, call; 52, 53; 52, 59; 53, attribute; 53, 54; 53, 58; 54, call; 54, 55; 54, 56; 55, identifier:str; 56, argument_list; 56, 57; 57, identifier:sensor; 58, identifier:lower; 59, argument_list; 60, if_statement; 60, 61; 60, 62; 61, identifier:mode; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:params; 67, string:'mode'; 68, identifier:mode; 69, if_statement; 69, 70; 69, 71; 70, identifier:waypoints; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:params; 76, string:'waypoints'; 77, identifier:waypoints; 78, if_statement; 78, 79; 78, 80; 79, identifier:alternatives; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:params; 85, string:'alternatives'; 86, identifier:alternatives; 87, if_statement; 87, 88; 87, 89; 88, identifier:avoid; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:params; 94, string:'avoid'; 95, identifier:avoid; 96, if_statement; 96, 97; 96, 98; 97, identifier:language; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:params; 103, string:'language'; 104, identifier:language; 105, if_statement; 105, 106; 105, 107; 106, identifier:units; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:params; 112, string:'units'; 113, identifier:units; 114, if_statement; 114, 115; 114, 116; 115, identifier:region; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:params; 121, string:'region'; 122, identifier:region; 123, if_statement; 123, 124; 123, 125; 124, identifier:departure_time; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:params; 130, string:'departure_time'; 131, identifier:departure_time; 132, if_statement; 132, 133; 132, 134; 133, identifier:arrival_time; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, subscript; 137, 138; 137, 139; 138, identifier:params; 139, string:'arrival_time'; 140, identifier:arrival_time; 141, if_statement; 141, 142; 141, 146; 141, 156; 142, not_operator; 142, 143; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:premier; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:url; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:get_url; 154, argument_list; 154, 155; 155, identifier:params; 156, else_clause; 156, 157; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:url; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:get_signed_url; 165, argument_list; 165, 166; 166, identifier:params; 167, return_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:GetService_url; 172, argument_list; 172, 173; 173, identifier:url
def GetDirections(self, origin, destination, sensor = False, mode = None, waypoints = None, alternatives = None, avoid = None, language = None, units = None, region = None, departure_time = None, arrival_time = None): '''Get Directions Service Pls refer to the Google Maps Web API for the details of the remained parameters ''' params = { 'origin': origin, 'destination': destination, 'sensor': str(sensor).lower() } if mode: params['mode'] = mode if waypoints: params['waypoints'] = waypoints if alternatives: params['alternatives'] = alternatives if avoid: params['avoid'] = avoid if language: params['language'] = language if units: params['units'] = units if region: params['region'] = region if departure_time: params['departure_time'] = departure_time if arrival_time: params['arrival_time'] = arrival_time if not self.premier: url = self.get_url(params) else: url = self.get_signed_url(params) return self.GetService_url(url)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:compactor; 3, parameters; 3, 4; 4, identifier:conf; 5, block; 5, 6; 5, 8; 5, 9; 5, 18; 5, 19; 5, 27; 5, 28; 5, 34; 5, 35; 5, 57; 5, 58; 5, 68; 5, 75; 5, 76; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:db; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:conf; 15, identifier:get_database; 16, argument_list; 16, 17; 17, string:'compactor'; 18, comment; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:limit_map; 22, call; 22, 23; 22, 24; 23, identifier:LimitContainer; 24, argument_list; 24, 25; 24, 26; 25, identifier:conf; 26, identifier:db; 27, comment; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:config; 31, subscript; 31, 32; 31, 33; 32, identifier:conf; 33, string:'compactor'; 34, comment; 35, if_statement; 35, 36; 35, 44; 35, 45; 35, 46; 36, comparison_operator:<=; 36, 37; 36, 43; 37, call; 37, 38; 37, 39; 38, identifier:get_int; 39, argument_list; 39, 40; 39, 41; 39, 42; 40, identifier:config; 41, string:'max_updates'; 42, integer:0; 43, integer:0; 44, comment; 45, comment; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:LOG; 51, identifier:warning; 52, argument_list; 52, 53; 53, concatenated_string; 53, 54; 53, 55; 53, 56; 54, string:"Compaction is not enabled. Enable it by "; 55, string:"setting a positive integer value for "; 56, string:"'compactor.max_updates' in the configuration."; 57, comment; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:key_getter; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:GetBucketKey; 64, identifier:factory; 65, argument_list; 65, 66; 65, 67; 66, identifier:config; 67, identifier:db; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:LOG; 72, identifier:info; 73, argument_list; 73, 74; 74, string:"Compactor initialized"; 75, comment; 76, while_statement; 76, 77; 76, 78; 76, 79; 77, True; 78, comment; 79, block; 79, 80; 79, 112; 79, 113; 79, 121; 79, 122; 79, 148; 79, 157; 79, 158; 79, 159; 80, try_statement; 80, 81; 80, 95; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:buck_key; 85, call; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:limits; 89, identifier:BucketKey; 90, identifier:decode; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:key_getter; 94, argument_list; 95, except_clause; 95, 96; 95, 100; 95, 101; 96, as_pattern; 96, 97; 96, 98; 97, identifier:ValueError; 98, as_pattern_target; 98, 99; 99, identifier:exc; 100, comment; 101, block; 101, 102; 101, 111; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:LOG; 106, identifier:warning; 107, argument_list; 107, 108; 108, binary_operator:%; 108, 109; 108, 110; 109, string:"Error interpreting bucket key: %s"; 110, identifier:exc; 111, continue_statement; 112, comment; 113, if_statement; 113, 114; 113, 119; 114, comparison_operator:<; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:buck_key; 117, identifier:version; 118, integer:2; 119, block; 119, 120; 120, continue_statement; 121, comment; 122, try_statement; 122, 123; 122, 132; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:limit; 127, subscript; 127, 128; 127, 129; 128, identifier:limit_map; 129, attribute; 129, 130; 129, 131; 130, identifier:buck_key; 131, identifier:uuid; 132, except_clause; 132, 133; 132, 134; 132, 135; 133, identifier:KeyError; 134, comment; 135, block; 135, 136; 135, 147; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:LOG; 140, identifier:warning; 141, argument_list; 141, 142; 142, binary_operator:%; 142, 143; 142, 144; 143, string:"Unable to compact bucket for limit %s"; 144, attribute; 144, 145; 144, 146; 145, identifier:buck_key; 146, identifier:uuid; 147, continue_statement; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:LOG; 152, identifier:debug; 153, argument_list; 153, 154; 154, binary_operator:%; 154, 155; 154, 156; 155, string:"Compacting bucket %s"; 156, identifier:buck_key; 157, comment; 158, comment; 159, try_statement; 159, 160; 159, 168; 159, 180; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:compact_bucket; 164, argument_list; 164, 165; 164, 166; 164, 167; 165, identifier:db; 166, identifier:buck_key; 167, identifier:limit; 168, except_clause; 168, 169; 168, 170; 169, identifier:Exception; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:LOG; 175, identifier:exception; 176, argument_list; 176, 177; 177, binary_operator:%; 177, 178; 177, 179; 178, string:"Failed to compact bucket %s"; 179, identifier:buck_key; 180, else_clause; 180, 181; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:LOG; 186, identifier:debug; 187, argument_list; 187, 188; 188, binary_operator:%; 188, 189; 188, 190; 189, string:"Finished compacting bucket %s"; 190, identifier:buck_key
def compactor(conf): """ The compactor daemon. This fuction watches the sorted set containing bucket keys that need to be compacted, performing the necessary compaction. :param conf: A turnstile.config.Config instance containing the configuration for the compactor daemon. Note that a ControlDaemon is also started, so appropriate configuration for that must also be present, as must appropriate Redis connection information. """ # Get the database handle db = conf.get_database('compactor') # Get the limits container limit_map = LimitContainer(conf, db) # Get the compactor configuration config = conf['compactor'] # Make sure compaction is enabled if get_int(config, 'max_updates', 0) <= 0: # We'll just warn about it, since they could be running # the compactor with a different configuration file LOG.warning("Compaction is not enabled. Enable it by " "setting a positive integer value for " "'compactor.max_updates' in the configuration.") # Select the bucket key getter key_getter = GetBucketKey.factory(config, db) LOG.info("Compactor initialized") # Now enter our loop while True: # Get a bucket key to compact try: buck_key = limits.BucketKey.decode(key_getter()) except ValueError as exc: # Warn about invalid bucket keys LOG.warning("Error interpreting bucket key: %s" % exc) continue # Ignore version 1 keys--they can't be compacted if buck_key.version < 2: continue # Get the corresponding limit class try: limit = limit_map[buck_key.uuid] except KeyError: # Warn about missing limits LOG.warning("Unable to compact bucket for limit %s" % buck_key.uuid) continue LOG.debug("Compacting bucket %s" % buck_key) # OK, we now have the limit (which we really only need for # the bucket class); let's compact the bucket try: compact_bucket(db, buck_key, limit) except Exception: LOG.exception("Failed to compact bucket %s" % buck_key) else: LOG.debug("Finished compacting bucket %s" % buck_key)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:now; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, with_statement; 9, 10; 9, 15; 10, with_clause; 10, 11; 11, with_item; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:lock; 15, block; 15, 16; 15, 41; 15, 42; 15, 48; 15, 49; 15, 55; 15, 64; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:items; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:db; 24, identifier:zrangebyscore; 25, argument_list; 25, 26; 25, 29; 25, 30; 25, 35; 25, 38; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:key; 29, integer:0; 30, binary_operator:-; 30, 31; 30, 32; 31, identifier:now; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:min_age; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:start; 37, integer:0; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:num; 40, integer:1; 41, comment; 42, if_statement; 42, 43; 42, 45; 43, not_operator; 43, 44; 44, identifier:items; 45, block; 45, 46; 46, return_statement; 46, 47; 47, None; 48, comment; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:item; 52, subscript; 52, 53; 52, 54; 53, identifier:items; 54, integer:0; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:db; 61, identifier:zrem; 62, argument_list; 62, 63; 63, identifier:item; 64, return_statement; 64, 65; 65, identifier:item
def get(self, now): """ Get a bucket key to compact. If none are available, returns None. This uses a configured lock to ensure that the bucket key is popped off the sorted set in an atomic fashion. :param now: The current time, as a float. Used to ensure the bucket key has been aged sufficiently to be quiescent. :returns: A bucket key ready for compaction, or None if no bucket keys are available or none have aged sufficiently. """ with self.lock: items = self.db.zrangebyscore(self.key, 0, now - self.min_age, start=0, num=1) # Did we get any items? if not items: return None # Drop the item we got item = items[0] self.db.zrem(item) return item
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:now; 6, block; 6, 7; 6, 9; 6, 31; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:items; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:script; 16, argument_list; 16, 17; 16, 23; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:keys; 19, list:[self.key]; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:key; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:args; 25, list:[now - self.min_age]; 25, 26; 26, binary_operator:-; 26, 27; 26, 28; 27, identifier:now; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:min_age; 31, return_statement; 31, 32; 32, conditional_expression:if; 32, 33; 32, 36; 32, 37; 33, subscript; 33, 34; 33, 35; 34, identifier:items; 35, integer:0; 36, identifier:items; 37, None
def get(self, now): """ Get a bucket key to compact. If none are available, returns None. This uses a Lua script to ensure that the bucket key is popped off the sorted set in an atomic fashion. :param now: The current time, as a float. Used to ensure the bucket key has been aged sufficiently to be quiescent. :returns: A bucket key ready for compaction, or None if no bucket keys are available or none have aged sufficiently. """ items = self.script(keys=[self.key], args=[now - self.min_age]) return items[0] if items else None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:main_cli; 3, parameters; 4, block; 4, 5; 4, 7; 4, 8; 4, 14; 4, 20; 4, 26; 4, 32; 4, 38; 4, 44; 4, 48; 4, 103; 5, expression_statement; 5, 6; 6, comment; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:args; 11, call; 11, 12; 11, 13; 12, identifier:_cli_argument_parser; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:delta_secs; 17, attribute; 17, 18; 17, 19; 18, identifier:args; 19, identifier:delay; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:i2cbus; 23, attribute; 23, 24; 23, 25; 24, identifier:args; 25, identifier:bus; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:i2c_address; 29, attribute; 29, 30; 29, 31; 30, identifier:args; 31, identifier:address; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:sensor_key; 35, attribute; 35, 36; 35, 37; 36, identifier:args; 37, identifier:sensor; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:sensor_params; 41, attribute; 41, 42; 41, 43; 42, identifier:args; 43, identifier:params; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:params; 47, dictionary; 48, if_statement; 48, 49; 48, 50; 49, identifier:sensor_params; 50, block; 50, 51; 50, 89; 51, function_definition; 51, 52; 51, 53; 51, 55; 52, function_name:_parse_param; 53, parameters; 53, 54; 54, identifier:str_param; 55, block; 55, 56; 55, 67; 55, 80; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, pattern_list; 58, 59; 58, 60; 59, identifier:key; 60, identifier:value; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:str_param; 64, identifier:split; 65, argument_list; 65, 66; 66, string:'='; 67, try_statement; 67, 68; 67, 76; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:value; 72, call; 72, 73; 72, 74; 73, identifier:int; 74, argument_list; 74, 75; 75, identifier:value; 76, except_clause; 76, 77; 76, 78; 77, identifier:ValueError; 78, block; 78, 79; 79, pass_statement; 80, return_statement; 80, 81; 81, dictionary; 81, 82; 82, pair; 82, 83; 82, 88; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:key; 86, identifier:strip; 87, argument_list; 88, identifier:value; 89, expression_statement; 89, 90; 90, list_comprehension; 90, 91; 90, 100; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:params; 94, identifier:update; 95, argument_list; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:_parse_param; 98, argument_list; 98, 99; 99, identifier:sp; 100, for_in_clause; 100, 101; 100, 102; 101, identifier:sp; 102, identifier:sensor_params; 103, if_statement; 103, 104; 103, 105; 103, 252; 104, identifier:sensor_key; 105, block; 105, 106; 105, 111; 105, 112; 105, 148; 105, 149; 105, 177; 105, 197; 105, 198; 105, 208; 105, 209; 106, import_from_statement; 106, 107; 106, 109; 107, dotted_name; 107, 108; 108, identifier:time; 109, dotted_name; 109, 110; 110, identifier:sleep; 111, comment; 112, try_statement; 112, 113; 112, 114; 112, 127; 113, comment; 114, block; 114, 115; 114, 118; 115, import_statement; 115, 116; 116, dotted_name; 116, 117; 117, identifier:smbus; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:bus_handler; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:smbus; 124, identifier:SMBus; 125, argument_list; 125, 126; 126, identifier:i2cbus; 127, except_clause; 127, 128; 127, 132; 128, as_pattern; 128, 129; 128, 130; 129, identifier:ImportError; 130, as_pattern_target; 130, 131; 131, identifier:exc; 132, block; 132, 133; 132, 140; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:print; 136, argument_list; 136, 137; 136, 138; 136, 139; 137, identifier:exc; 138, string:"\n"; 139, string:"Please install smbus-cffi before."; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:sys; 144, identifier:exit; 145, argument_list; 145, 146; 146, unary_operator:-; 146, 147; 147, integer:1; 148, comment; 149, try_statement; 149, 150; 149, 159; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, pattern_list; 153, 154; 153, 155; 154, identifier:sensor_handler; 155, identifier:i2c_default_address; 156, subscript; 156, 157; 156, 158; 157, identifier:SENSORS; 158, identifier:sensor_key; 159, except_clause; 159, 160; 159, 161; 160, identifier:KeyError; 161, block; 161, 162; 161, 169; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:print; 165, argument_list; 165, 166; 166, binary_operator:%; 166, 167; 166, 168; 167, string:"'%s' is not recognized as an implemented i2c sensor."; 168, identifier:sensor_key; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:sys; 173, identifier:exit; 174, argument_list; 174, 175; 175, unary_operator:-; 175, 176; 176, integer:1; 177, if_statement; 177, 178; 177, 179; 177, 191; 178, identifier:i2c_address; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:i2c_address; 183, call; 183, 184; 183, 185; 184, identifier:hex; 185, argument_list; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:int; 188, argument_list; 188, 189; 188, 190; 189, identifier:i2c_address; 190, integer:0; 191, else_clause; 191, 192; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:i2c_address; 196, identifier:i2c_default_address; 197, comment; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:sensor; 201, call; 201, 202; 201, 203; 202, identifier:sensor_handler; 203, argument_list; 203, 204; 203, 205; 203, 206; 204, identifier:bus_handler; 205, identifier:i2c_address; 206, dictionary_splat; 206, 207; 207, identifier:params; 208, comment; 209, try_statement; 209, 210; 209, 244; 210, block; 210, 211; 211, while_statement; 211, 212; 211, 213; 212, True; 213, block; 213, 214; 213, 220; 213, 232; 213, 239; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:sensor; 218, identifier:update; 219, argument_list; 220, if_statement; 220, 221; 220, 225; 221, not_operator; 221, 222; 222, attribute; 222, 223; 222, 224; 223, identifier:sensor; 224, identifier:sample_ok; 225, block; 225, 226; 225, 231; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 229; 228, identifier:print; 229, argument_list; 229, 230; 230, string:"An error has occured."; 231, break_statement; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 235; 234, identifier:print; 235, argument_list; 235, 236; 236, attribute; 236, 237; 236, 238; 237, identifier:sensor; 238, identifier:current_state_str; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 242; 241, identifier:sleep; 242, argument_list; 242, 243; 243, identifier:delta_secs; 244, except_clause; 244, 245; 244, 246; 245, identifier:KeyboardInterrupt; 246, block; 246, 247; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 250; 249, identifier:print; 250, argument_list; 250, 251; 251, string:"Bye!"; 252, else_clause; 252, 253; 252, 254; 253, comment; 254, block; 254, 255; 254, 260; 254, 269; 254, 316; 254, 317; 254, 354; 255, import_from_statement; 255, 256; 255, 258; 256, dotted_name; 256, 257; 257, identifier:subprocess; 258, dotted_name; 258, 259; 259, identifier:check_output; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:cmd; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, string:'/usr/sbin/i2cdetect -y {}'; 266, identifier:format; 267, argument_list; 267, 268; 268, identifier:i2cbus; 269, try_statement; 269, 270; 269, 300; 270, block; 270, 271; 270, 282; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:output; 274, call; 274, 275; 274, 276; 275, identifier:check_output; 276, argument_list; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:cmd; 280, identifier:split; 281, argument_list; 282, expression_statement; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:print; 285, argument_list; 285, 286; 286, call; 286, 287; 286, 292; 287, attribute; 287, 288; 287, 291; 288, concatenated_string; 288, 289; 288, 290; 289, string:"Running i2cdetect utility in i2c bus {}:\n"; 290, string:"The command '{}' has returned:\n{}"; 291, identifier:format; 292, argument_list; 292, 293; 292, 294; 292, 295; 293, identifier:i2cbus; 294, identifier:cmd; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:output; 298, identifier:decode; 299, argument_list; 300, except_clause; 300, 301; 300, 302; 301, identifier:FileNotFoundError; 302, block; 302, 303; 302, 308; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:print; 306, argument_list; 306, 307; 307, string:"Please install i2cdetect before."; 308, expression_statement; 308, 309; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:sys; 312, identifier:exit; 313, argument_list; 313, 314; 314, unary_operator:-; 314, 315; 315, integer:1; 316, comment; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:addresses; 320, list_comprehension; 320, 321; 320, 324; 320, 339; 320, 350; 321, binary_operator:+; 321, 322; 321, 323; 322, string:'0x'; 323, identifier:l; 324, for_in_clause; 324, 325; 324, 326; 325, identifier:line; 326, subscript; 326, 327; 326, 336; 327, call; 327, 328; 327, 335; 328, attribute; 328, 329; 328, 334; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:output; 332, identifier:decode; 333, argument_list; 334, identifier:splitlines; 335, argument_list; 336, slice; 336, 337; 336, 338; 337, integer:1; 338, colon; 339, for_in_clause; 339, 340; 339, 341; 340, identifier:l; 341, subscript; 341, 342; 341, 347; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:line; 345, identifier:split; 346, argument_list; 347, slice; 347, 348; 347, 349; 348, integer:1; 349, colon; 350, if_clause; 350, 351; 351, comparison_operator:!=; 351, 352; 351, 353; 352, identifier:l; 353, string:'--'; 354, if_statement; 354, 355; 354, 356; 354, 376; 355, identifier:addresses; 356, block; 356, 357; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 360; 359, identifier:print; 360, argument_list; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, string:"{} sensors detected in {}"; 364, identifier:format; 365, argument_list; 365, 366; 365, 370; 366, call; 366, 367; 366, 368; 367, identifier:len; 368, argument_list; 368, 369; 369, identifier:addresses; 370, call; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, string:', '; 373, identifier:join; 374, argument_list; 374, 375; 375, identifier:addresses; 376, else_clause; 376, 377; 377, block; 377, 378; 378, expression_statement; 378, 379; 379, call; 379, 380; 379, 381; 380, identifier:print; 381, argument_list; 381, 382; 382, string:"No i2c sensors detected."
def main_cli(): """CLI minimal interface.""" # Get params args = _cli_argument_parser() delta_secs = args.delay i2cbus = args.bus i2c_address = args.address sensor_key = args.sensor sensor_params = args.params params = {} if sensor_params: def _parse_param(str_param): key, value = str_param.split('=') try: value = int(value) except ValueError: pass return {key.strip(): value} [params.update(_parse_param(sp)) for sp in sensor_params] if sensor_key: from time import sleep # Bus init try: # noinspection PyUnresolvedReferences import smbus bus_handler = smbus.SMBus(i2cbus) except ImportError as exc: print(exc, "\n", "Please install smbus-cffi before.") sys.exit(-1) # Sensor selection try: sensor_handler, i2c_default_address = SENSORS[sensor_key] except KeyError: print("'%s' is not recognized as an implemented i2c sensor." % sensor_key) sys.exit(-1) if i2c_address: i2c_address = hex(int(i2c_address, 0)) else: i2c_address = i2c_default_address # Sensor init sensor = sensor_handler(bus_handler, i2c_address, **params) # Infinite loop try: while True: sensor.update() if not sensor.sample_ok: print("An error has occured.") break print(sensor.current_state_str) sleep(delta_secs) except KeyboardInterrupt: print("Bye!") else: # Run detection mode from subprocess import check_output cmd = '/usr/sbin/i2cdetect -y {}'.format(i2cbus) try: output = check_output(cmd.split()) print("Running i2cdetect utility in i2c bus {}:\n" "The command '{}' has returned:\n{}" .format(i2cbus, cmd, output.decode())) except FileNotFoundError: print("Please install i2cdetect before.") sys.exit(-1) # Parse output addresses = ['0x' + l for line in output.decode().splitlines()[1:] for l in line.split()[1:] if l != '--'] if addresses: print("{} sensors detected in {}" .format(len(addresses), ', '.join(addresses))) else: print("No i2c sensors detected.")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:variant_support; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:variants; 5, identifier:allele_support_df; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ignore_missing; 8, False; 9, block; 9, 10; 9, 12; 9, 26; 9, 41; 9, 42; 9, 60; 9, 73; 9, 82; 9, 120; 9, 121; 9, 128; 9, 143; 9, 340; 9, 366; 10, expression_statement; 10, 11; 11, string:''' Collect the read evidence support for the given variants. Parameters ---------- variants : iterable of varcode.Variant allele_support_df : dataframe Allele support dataframe, as output by the varlens-allele-support tool. It should have columns: source, contig, interbase_start, interbase_end, allele. The remaining columns are interpreted as read counts of various subsets of reads (e.g. all reads, non-duplicate reads, etc.) ignore_missing : boolean If True, then varaints with no allele counts will be interpreted as having 0 depth. If False, then an exception will be raised if any variants have no allele counts. Returns ---------- A pandas.Panel4D frame with these axes: labels (axis=0) : the type of read being counted, i.e. the read count fields in allele_support_df. items (axis=1) : the type of measurement (num_alt, num_ref, num_other, total_depth, alt_fraction, any_alt_fraction) major axis (axis=2) : the variants minor axis (axis=3) : the sources '''; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:missing; 15, list_comprehension; 15, 16; 15, 17; 15, 20; 16, identifier:c; 17, for_in_clause; 17, 18; 17, 19; 18, identifier:c; 19, identifier:EXPECTED_COLUMNS; 20, if_clause; 20, 21; 21, comparison_operator:not; 21, 22; 21, 23; 22, identifier:c; 23, attribute; 23, 24; 23, 25; 24, identifier:allele_support_df; 25, identifier:columns; 26, if_statement; 26, 27; 26, 28; 27, identifier:missing; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:ValueError; 32, argument_list; 32, 33; 33, binary_operator:%; 33, 34; 33, 35; 34, string:"Missing columns: %s"; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:" "; 38, identifier:join; 39, argument_list; 39, 40; 40, identifier:missing; 41, comment; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 49; 44, subscript; 44, 45; 44, 46; 45, identifier:allele_support_df; 46, list:["interbase_start", "interbase_end"]; 46, 47; 46, 48; 47, string:"interbase_start"; 48, string:"interbase_end"; 49, parenthesized_expression; 49, 50; 50, call; 50, 51; 50, 58; 51, attribute; 51, 52; 51, 57; 52, subscript; 52, 53; 52, 54; 53, identifier:allele_support_df; 54, list:["interbase_start", "interbase_end"]; 54, 55; 54, 56; 55, string:"interbase_start"; 56, string:"interbase_end"; 57, identifier:astype; 58, argument_list; 58, 59; 59, identifier:int; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:sources; 63, call; 63, 64; 63, 65; 64, identifier:sorted; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:allele_support_df; 70, string:"source"; 71, identifier:unique; 72, argument_list; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:allele_support_dict; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:collections; 79, identifier:defaultdict; 80, argument_list; 80, 81; 81, identifier:dict; 82, for_statement; 82, 83; 82, 86; 82, 91; 83, tuple_pattern; 83, 84; 83, 85; 84, identifier:i; 85, identifier:row; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:allele_support_df; 89, identifier:iterrows; 90, argument_list; 91, block; 91, 92; 91, 108; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:key; 95, tuple; 95, 96; 95, 99; 95, 102; 95, 105; 96, subscript; 96, 97; 96, 98; 97, identifier:row; 98, string:'source'; 99, attribute; 99, 100; 99, 101; 100, identifier:row; 101, identifier:contig; 102, attribute; 102, 103; 102, 104; 103, identifier:row; 104, identifier:interbase_start; 105, attribute; 105, 106; 105, 107; 106, identifier:row; 107, identifier:interbase_end; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 117; 110, subscript; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:allele_support_dict; 113, identifier:key; 114, attribute; 114, 115; 114, 116; 115, identifier:row; 116, identifier:allele; 117, subscript; 117, 118; 117, 119; 118, identifier:row; 119, string:"count"; 120, comment; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:allele_support_dict; 124, call; 124, 125; 124, 126; 125, identifier:dict; 126, argument_list; 126, 127; 127, identifier:allele_support_dict; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:dataframe_dicts; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:collections; 134, identifier:defaultdict; 135, argument_list; 135, 136; 136, lambda; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:collections; 140, identifier:defaultdict; 141, argument_list; 141, 142; 142, identifier:list; 143, for_statement; 143, 144; 143, 145; 143, 146; 144, identifier:variant; 145, identifier:variants; 146, block; 146, 147; 147, for_statement; 147, 148; 147, 149; 147, 150; 148, identifier:source; 149, identifier:sources; 150, block; 150, 151; 150, 167; 150, 211; 150, 223; 150, 235; 150, 246; 150, 254; 150, 265; 150, 276; 150, 287; 150, 298; 150, 318; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:key; 154, tuple; 154, 155; 154, 156; 154, 159; 154, 164; 155, identifier:source; 156, attribute; 156, 157; 156, 158; 157, identifier:variant; 158, identifier:contig; 159, binary_operator:-; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:variant; 162, identifier:start; 163, integer:1; 164, attribute; 164, 165; 164, 166; 165, identifier:variant; 166, identifier:end; 167, try_statement; 167, 168; 167, 175; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:alleles; 172, subscript; 172, 173; 172, 174; 173, identifier:allele_support_dict; 174, identifier:key; 175, except_clause; 175, 176; 175, 177; 176, identifier:KeyError; 177, block; 177, 178; 177, 190; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:message; 181, parenthesized_expression; 181, 182; 182, binary_operator:%; 182, 183; 182, 184; 183, string:"No allele counts in source %s for variant %s"; 184, tuple; 184, 185; 184, 186; 185, identifier:source; 186, call; 186, 187; 186, 188; 187, identifier:str; 188, argument_list; 188, 189; 189, identifier:variant; 190, if_statement; 190, 191; 190, 192; 190, 204; 191, identifier:ignore_missing; 192, block; 192, 193; 192, 200; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:logging; 197, identifier:warning; 198, argument_list; 198, 199; 199, identifier:message; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:alleles; 203, dictionary; 204, else_clause; 204, 205; 205, block; 205, 206; 206, raise_statement; 206, 207; 207, call; 207, 208; 207, 209; 208, identifier:ValueError; 209, argument_list; 209, 210; 210, identifier:message; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:alt; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:alleles; 217, identifier:get; 218, argument_list; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:variant; 221, identifier:alt; 222, integer:0; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:ref; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:alleles; 229, identifier:get; 230, argument_list; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:variant; 233, identifier:ref; 234, integer:0; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:total; 238, call; 238, 239; 238, 240; 239, identifier:sum; 240, argument_list; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:alleles; 244, identifier:values; 245, argument_list; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:other; 249, binary_operator:-; 249, 250; 249, 253; 250, binary_operator:-; 250, 251; 250, 252; 251, identifier:total; 252, identifier:alt; 253, identifier:ref; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 263; 256, attribute; 256, 257; 256, 262; 257, subscript; 257, 258; 257, 261; 258, subscript; 258, 259; 258, 260; 259, identifier:dataframe_dicts; 260, string:"num_alt"; 261, identifier:source; 262, identifier:append; 263, argument_list; 263, 264; 264, identifier:alt; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 274; 267, attribute; 267, 268; 267, 273; 268, subscript; 268, 269; 268, 272; 269, subscript; 269, 270; 269, 271; 270, identifier:dataframe_dicts; 271, string:"num_ref"; 272, identifier:source; 273, identifier:append; 274, argument_list; 274, 275; 275, identifier:ref; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 285; 278, attribute; 278, 279; 278, 284; 279, subscript; 279, 280; 279, 283; 280, subscript; 280, 281; 280, 282; 281, identifier:dataframe_dicts; 282, string:"num_other"; 283, identifier:source; 284, identifier:append; 285, argument_list; 285, 286; 286, identifier:other; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 296; 289, attribute; 289, 290; 289, 295; 290, subscript; 290, 291; 290, 294; 291, subscript; 291, 292; 291, 293; 292, identifier:dataframe_dicts; 293, string:"total_depth"; 294, identifier:source; 295, identifier:append; 296, argument_list; 296, 297; 297, identifier:total; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 307; 300, attribute; 300, 301; 300, 306; 301, subscript; 301, 302; 301, 305; 302, subscript; 302, 303; 302, 304; 303, identifier:dataframe_dicts; 304, string:"alt_fraction"; 305, identifier:source; 306, identifier:append; 307, argument_list; 307, 308; 308, binary_operator:/; 308, 309; 308, 313; 309, call; 309, 310; 309, 311; 310, identifier:float; 311, argument_list; 311, 312; 312, identifier:alt; 313, call; 313, 314; 313, 315; 314, identifier:max; 315, argument_list; 315, 316; 315, 317; 316, integer:1; 317, identifier:total; 318, expression_statement; 318, 319; 319, call; 319, 320; 319, 327; 320, attribute; 320, 321; 320, 326; 321, subscript; 321, 322; 321, 325; 322, subscript; 322, 323; 322, 324; 323, identifier:dataframe_dicts; 324, string:"any_alt_fraction"; 325, identifier:source; 326, identifier:append; 327, argument_list; 327, 328; 328, binary_operator:/; 328, 329; 328, 335; 329, call; 329, 330; 329, 331; 330, identifier:float; 331, argument_list; 331, 332; 332, binary_operator:+; 332, 333; 332, 334; 333, identifier:alt; 334, identifier:other; 335, call; 335, 336; 335, 337; 336, identifier:max; 337, argument_list; 337, 338; 337, 339; 338, integer:1; 339, identifier:total; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:dataframes; 343, call; 343, 344; 343, 345; 344, identifier:dict; 345, generator_expression; 345, 346; 345, 357; 346, tuple; 346, 347; 346, 348; 347, identifier:label; 348, call; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:pandas; 351, identifier:DataFrame; 352, argument_list; 352, 353; 352, 354; 353, identifier:value; 354, keyword_argument; 354, 355; 354, 356; 355, identifier:index; 356, identifier:variants; 357, for_in_clause; 357, 358; 357, 361; 358, tuple_pattern; 358, 359; 358, 360; 359, identifier:label; 360, identifier:value; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:dataframe_dicts; 364, identifier:items; 365, argument_list; 366, return_statement; 366, 367; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:pandas; 370, identifier:Panel; 371, argument_list; 371, 372; 372, identifier:dataframes
def variant_support(variants, allele_support_df, ignore_missing=False): ''' Collect the read evidence support for the given variants. Parameters ---------- variants : iterable of varcode.Variant allele_support_df : dataframe Allele support dataframe, as output by the varlens-allele-support tool. It should have columns: source, contig, interbase_start, interbase_end, allele. The remaining columns are interpreted as read counts of various subsets of reads (e.g. all reads, non-duplicate reads, etc.) ignore_missing : boolean If True, then varaints with no allele counts will be interpreted as having 0 depth. If False, then an exception will be raised if any variants have no allele counts. Returns ---------- A pandas.Panel4D frame with these axes: labels (axis=0) : the type of read being counted, i.e. the read count fields in allele_support_df. items (axis=1) : the type of measurement (num_alt, num_ref, num_other, total_depth, alt_fraction, any_alt_fraction) major axis (axis=2) : the variants minor axis (axis=3) : the sources ''' missing = [ c for c in EXPECTED_COLUMNS if c not in allele_support_df.columns ] if missing: raise ValueError("Missing columns: %s" % " ".join(missing)) # Ensure our start and end fields are ints. allele_support_df[["interbase_start", "interbase_end"]] = ( allele_support_df[["interbase_start", "interbase_end"]].astype(int)) sources = sorted(allele_support_df["source"].unique()) allele_support_dict = collections.defaultdict(dict) for (i, row) in allele_support_df.iterrows(): key = ( row['source'], row.contig, row.interbase_start, row.interbase_end) allele_support_dict[key][row.allele] = row["count"] # We want an exception on bad lookups, so convert to a regular dict. allele_support_dict = dict(allele_support_dict) dataframe_dicts = collections.defaultdict( lambda: collections.defaultdict(list)) for variant in variants: for source in sources: key = (source, variant.contig, variant.start - 1, variant.end) try: alleles = allele_support_dict[key] except KeyError: message = ( "No allele counts in source %s for variant %s" % ( source, str(variant))) if ignore_missing: logging.warning(message) alleles = {} else: raise ValueError(message) alt = alleles.get(variant.alt, 0) ref = alleles.get(variant.ref, 0) total = sum(alleles.values()) other = total - alt - ref dataframe_dicts["num_alt"][source].append(alt) dataframe_dicts["num_ref"][source].append(ref) dataframe_dicts["num_other"][source].append(other) dataframe_dicts["total_depth"][source].append(total) dataframe_dicts["alt_fraction"][source].append( float(alt) / max(1, total)) dataframe_dicts["any_alt_fraction"][source].append( float(alt + other) / max(1, total)) dataframes = dict( (label, pandas.DataFrame(value, index=variants)) for (label, value) in dataframe_dicts.items()) return pandas.Panel(dataframes)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 1, 25; 2, function_name:_wavReadData; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 13; 3, 17; 4, identifier:fid; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:size; 7, type; 7, 8; 8, identifier:int; 9, typed_parameter; 9, 10; 9, 11; 10, identifier:channels; 11, type; 11, 12; 12, identifier:int; 13, typed_parameter; 13, 14; 13, 15; 14, identifier:encoding; 15, type; 15, 16; 16, identifier:str; 17, typed_parameter; 17, 18; 17, 19; 18, identifier:bigendian; 19, type; 19, 20; 20, identifier:bool; 21, type; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:np; 24, identifier:ndarray; 25, block; 25, 26; 25, 28; 25, 39; 25, 258; 26, expression_statement; 26, 27; 27, comment; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:bits; 31, call; 31, 32; 31, 33; 32, identifier:int; 33, argument_list; 33, 34; 34, subscript; 34, 35; 34, 36; 35, identifier:encoding; 36, slice; 36, 37; 36, 38; 37, integer:3; 38, colon; 39, if_statement; 39, 40; 39, 43; 39, 77; 40, comparison_operator:==; 40, 41; 40, 42; 41, identifier:bits; 42, integer:8; 43, block; 43, 44; 43, 61; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:data; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:np; 50, identifier:fromfile; 51, argument_list; 51, 52; 51, 53; 51, 58; 52, identifier:fid; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:dtype; 55, attribute; 55, 56; 55, 57; 56, identifier:np; 57, identifier:ubyte; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:count; 60, identifier:size; 61, if_statement; 61, 62; 61, 65; 62, comparison_operator:>; 62, 63; 62, 64; 63, identifier:channels; 64, integer:1; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:data; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:data; 72, identifier:reshape; 73, argument_list; 73, 74; 73, 76; 74, unary_operator:-; 74, 75; 75, integer:1; 76, identifier:channels; 77, else_clause; 77, 78; 78, block; 78, 79; 78, 85; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:bytes; 82, binary_operator://; 82, 83; 82, 84; 83, identifier:bits; 84, integer:8; 85, if_statement; 85, 86; 85, 92; 85, 143; 85, 212; 86, comparison_operator:in; 86, 87; 86, 88; 87, identifier:encoding; 88, tuple; 88, 89; 88, 90; 88, 91; 89, string:'pcm16'; 90, string:'pcm32'; 91, string:'pcm64'; 92, block; 92, 93; 92, 110; 92, 127; 93, if_statement; 93, 94; 93, 95; 93, 102; 94, identifier:bigendian; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:dtype; 99, binary_operator:%; 99, 100; 99, 101; 100, string:'>i%d'; 101, identifier:bytes; 102, else_clause; 102, 103; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:dtype; 107, binary_operator:%; 107, 108; 107, 109; 108, string:'<i%d'; 109, identifier:bytes; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:data; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:np; 116, identifier:fromfile; 117, argument_list; 117, 118; 117, 119; 117, 122; 118, identifier:fid; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:dtype; 121, identifier:dtype; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:count; 124, binary_operator://; 124, 125; 124, 126; 125, identifier:size; 126, identifier:bytes; 127, if_statement; 127, 128; 127, 131; 128, comparison_operator:>; 128, 129; 128, 130; 129, identifier:channels; 130, integer:1; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:data; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:data; 138, identifier:reshape; 139, argument_list; 139, 140; 139, 142; 140, unary_operator:-; 140, 141; 141, integer:1; 142, identifier:channels; 143, elif_clause; 143, 144; 143, 151; 144, comparison_operator:==; 144, 145; 144, 150; 145, subscript; 145, 146; 145, 147; 146, identifier:encoding; 147, slice; 147, 148; 147, 149; 148, colon; 149, integer:3; 150, string:'flt'; 151, block; 151, 152; 151, 157; 151, 179; 151, 196; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 155; 154, identifier:print; 155, argument_list; 155, 156; 156, string:"flt32!"; 157, if_statement; 157, 158; 157, 161; 157, 175; 158, comparison_operator:==; 158, 159; 158, 160; 159, identifier:bits; 160, integer:32; 161, block; 161, 162; 162, if_statement; 162, 163; 162, 164; 162, 169; 163, identifier:bigendian; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:dtype; 168, string:'>f4'; 169, else_clause; 169, 170; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:dtype; 174, string:'<f4'; 175, else_clause; 175, 176; 176, block; 176, 177; 177, raise_statement; 177, 178; 178, identifier:NotImplementedError; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:data; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:np; 185, identifier:fromfile; 186, argument_list; 186, 187; 186, 188; 186, 191; 187, identifier:fid; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:dtype; 190, identifier:dtype; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:count; 193, binary_operator://; 193, 194; 193, 195; 194, identifier:size; 195, identifier:bytes; 196, if_statement; 196, 197; 196, 200; 197, comparison_operator:>; 197, 198; 197, 199; 198, identifier:channels; 199, integer:1; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:data; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:data; 207, identifier:reshape; 208, argument_list; 208, 209; 208, 211; 209, unary_operator:-; 209, 210; 210, integer:1; 211, identifier:channels; 212, elif_clause; 212, 213; 212, 216; 212, 217; 212, 218; 213, comparison_operator:==; 213, 214; 213, 215; 214, identifier:encoding; 215, string:'pcm24'; 216, comment; 217, comment; 218, block; 218, 219; 218, 242; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:data; 222, call; 222, 223; 222, 224; 223, identifier:_numpy24to32bit; 224, argument_list; 224, 225; 224, 239; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:np; 228, identifier:fromfile; 229, argument_list; 229, 230; 229, 231; 229, 236; 230, identifier:fid; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:dtype; 233, attribute; 233, 234; 233, 235; 234, identifier:np; 235, identifier:ubyte; 236, keyword_argument; 236, 237; 236, 238; 237, identifier:count; 238, identifier:size; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:bigendian; 241, False; 242, if_statement; 242, 243; 242, 246; 243, comparison_operator:>; 243, 244; 243, 245; 244, identifier:channels; 245, integer:1; 246, block; 246, 247; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:data; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:data; 253, identifier:reshape; 254, argument_list; 254, 255; 254, 257; 255, unary_operator:-; 255, 256; 256, integer:1; 257, identifier:channels; 258, return_statement; 258, 259; 259, identifier:data
def _wavReadData(fid, size:int, channels:int, encoding:str, bigendian:bool) -> np.ndarray: """ adapted from scipy.io.wavfile._read_data_chunk assume we are at the data (after having read the size) """ bits = int(encoding[3:]) if bits == 8: data = np.fromfile(fid, dtype=np.ubyte, count=size) if channels > 1: data = data.reshape(-1, channels) else: bytes = bits // 8 if encoding in ('pcm16', 'pcm32', 'pcm64'): if bigendian: dtype = '>i%d' % bytes else: dtype = '<i%d' % bytes data = np.fromfile(fid, dtype=dtype, count=size // bytes) if channels > 1: data = data.reshape(-1, channels) elif encoding[:3] == 'flt': print("flt32!") if bits == 32: if bigendian: dtype = '>f4' else: dtype = '<f4' else: raise NotImplementedError data = np.fromfile(fid, dtype=dtype, count=size // bytes) if channels > 1: data = data.reshape(-1, channels) elif encoding == 'pcm24': # this conversion approach is really bad for long files # TODO: do the same but in chunks data = _numpy24to32bit(np.fromfile(fid, dtype=np.ubyte, count=size), bigendian=False) if channels > 1: data = data.reshape(-1, channels) return data
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:refreshButton; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 22; 5, 27; 5, 35; 5, 36; 5, 63; 5, 67; 5, 68; 5, 199; 5, 266; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:collapsed; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:isCollapsed; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:btn; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_collapseButton; 22, if_statement; 22, 23; 22, 25; 23, not_operator; 23, 24; 24, identifier:btn; 25, block; 25, 26; 26, return_statement; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:btn; 31, identifier:setMaximumSize; 32, argument_list; 32, 33; 32, 34; 33, identifier:MAX_SIZE; 34, identifier:MAX_SIZE; 35, comment; 36, if_statement; 36, 37; 36, 46; 36, 54; 37, comparison_operator:==; 37, 38; 37, 43; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:orientation; 42, argument_list; 43, attribute; 43, 44; 43, 45; 44, identifier:Qt; 45, identifier:Vertical; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:btn; 51, identifier:setMaximumHeight; 52, argument_list; 52, 53; 53, integer:12; 54, else_clause; 54, 55; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:btn; 60, identifier:setMaximumWidth; 61, argument_list; 61, 62; 62, integer:12; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:icon; 66, string:''; 67, comment; 68, if_statement; 68, 69; 68, 78; 68, 138; 69, comparison_operator:==; 69, 70; 69, 75; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:orientation; 74, argument_list; 75, attribute; 75, 76; 75, 77; 76, identifier:Qt; 77, identifier:Vertical; 78, block; 78, 79; 79, if_statement; 79, 80; 79, 81; 79, 107; 80, identifier:collapsed; 81, block; 81, 82; 81, 91; 81, 98; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:setFixedWidth; 87, argument_list; 87, 88; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:_collapsedSize; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:btn; 95, identifier:setMaximumHeight; 96, argument_list; 96, 97; 97, identifier:MAX_SIZE; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:btn; 102, identifier:setArrowType; 103, argument_list; 103, 104; 104, attribute; 104, 105; 104, 106; 105, identifier:Qt; 106, identifier:RightArrow; 107, else_clause; 107, 108; 108, block; 108, 109; 108, 116; 108, 122; 108, 129; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:setMaximumWidth; 114, argument_list; 114, 115; 115, identifier:MAX_SIZE; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:_precollapseSize; 121, None; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:btn; 126, identifier:setMaximumHeight; 127, argument_list; 127, 128; 128, integer:12; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:btn; 133, identifier:setArrowType; 134, argument_list; 134, 135; 135, attribute; 135, 136; 135, 137; 136, identifier:Qt; 137, identifier:LeftArrow; 138, else_clause; 138, 139; 139, block; 139, 140; 140, if_statement; 140, 141; 140, 142; 140, 168; 141, identifier:collapsed; 142, block; 142, 143; 142, 152; 142, 159; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:setFixedHeight; 148, argument_list; 148, 149; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:_collapsedSize; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:btn; 156, identifier:setMaximumWidth; 157, argument_list; 157, 158; 158, identifier:MAX_SIZE; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:btn; 163, identifier:setArrowType; 164, argument_list; 164, 165; 165, attribute; 165, 166; 165, 167; 166, identifier:Qt; 167, identifier:DownArrow; 168, else_clause; 168, 169; 169, block; 169, 170; 169, 177; 169, 183; 169, 190; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:setMaximumHeight; 175, argument_list; 175, 176; 176, integer:1000; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:_precollapseSize; 182, None; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:btn; 187, identifier:setMaximumWidth; 188, argument_list; 188, 189; 189, integer:12; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:btn; 194, identifier:setArrowType; 195, argument_list; 195, 196; 196, attribute; 196, 197; 196, 198; 197, identifier:Qt; 198, identifier:UpArrow; 199, for_statement; 199, 200; 199, 201; 199, 214; 200, identifier:index; 201, call; 201, 202; 201, 203; 202, identifier:range; 203, argument_list; 203, 204; 203, 205; 204, integer:1; 205, call; 205, 206; 205, 213; 206, attribute; 206, 207; 206, 212; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:layout; 211, argument_list; 212, identifier:count; 213, argument_list; 214, block; 214, 215; 214, 228; 214, 237; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:item; 218, call; 218, 219; 218, 226; 219, attribute; 219, 220; 219, 225; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:layout; 224, argument_list; 225, identifier:itemAt; 226, argument_list; 226, 227; 227, identifier:index; 228, if_statement; 228, 229; 228, 235; 229, not_operator; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:item; 233, identifier:widget; 234, argument_list; 235, block; 235, 236; 236, continue_statement; 237, if_statement; 237, 238; 237, 239; 237, 252; 238, identifier:collapsed; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 249; 242, attribute; 242, 243; 242, 248; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:item; 246, identifier:widget; 247, argument_list; 248, identifier:setMaximumSize; 249, argument_list; 249, 250; 249, 251; 250, integer:0; 251, integer:0; 252, else_clause; 252, 253; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 263; 256, attribute; 256, 257; 256, 262; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:item; 260, identifier:widget; 261, argument_list; 262, identifier:setMaximumSize; 263, argument_list; 263, 264; 263, 265; 264, identifier:MAX_SIZE; 265, identifier:MAX_SIZE; 266, if_statement; 266, 267; 266, 273; 266, 280; 267, not_operator; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:isCollapsable; 272, argument_list; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:btn; 278, identifier:hide; 279, argument_list; 280, else_clause; 280, 281; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:btn; 286, identifier:show; 287, argument_list
def refreshButton(self): """ Refreshes the button for this toolbar. """ collapsed = self.isCollapsed() btn = self._collapseButton if not btn: return btn.setMaximumSize(MAX_SIZE, MAX_SIZE) # set up a vertical scrollbar if self.orientation() == Qt.Vertical: btn.setMaximumHeight(12) else: btn.setMaximumWidth(12) icon = '' # collapse/expand a vertical toolbar if self.orientation() == Qt.Vertical: if collapsed: self.setFixedWidth(self._collapsedSize) btn.setMaximumHeight(MAX_SIZE) btn.setArrowType(Qt.RightArrow) else: self.setMaximumWidth(MAX_SIZE) self._precollapseSize = None btn.setMaximumHeight(12) btn.setArrowType(Qt.LeftArrow) else: if collapsed: self.setFixedHeight(self._collapsedSize) btn.setMaximumWidth(MAX_SIZE) btn.setArrowType(Qt.DownArrow) else: self.setMaximumHeight(1000) self._precollapseSize = None btn.setMaximumWidth(12) btn.setArrowType(Qt.UpArrow) for index in range(1, self.layout().count()): item = self.layout().itemAt(index) if not item.widget(): continue if collapsed: item.widget().setMaximumSize(0, 0) else: item.widget().setMaximumSize(MAX_SIZE, MAX_SIZE) if not self.isCollapsable(): btn.hide() else: btn.show()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:applyCommand; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 17; 5, 26; 5, 45; 5, 53; 5, 65; 5, 75; 5, 76; 5, 459; 5, 466; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:cursor; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:textCursor; 16, argument_list; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:cursor; 21, identifier:movePosition; 22, argument_list; 22, 23; 23, attribute; 23, 24; 23, 25; 24, identifier:cursor; 25, identifier:EndOfLine; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:line; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:projex; 33, identifier:text; 34, identifier:nativestring; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 44; 37, attribute; 37, 38; 37, 43; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:cursor; 41, identifier:block; 42, argument_list; 43, identifier:text; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:at_end; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:cursor; 51, identifier:atEnd; 52, argument_list; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:modifiers; 56, call; 56, 57; 56, 64; 57, attribute; 57, 58; 57, 63; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:QApplication; 61, identifier:instance; 62, argument_list; 63, identifier:keyboardModifiers; 64, argument_list; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:mod_mode; 68, boolean_operator:or; 68, 69; 68, 70; 69, identifier:at_end; 70, comparison_operator:==; 70, 71; 70, 72; 71, identifier:modifiers; 72, attribute; 72, 73; 72, 74; 73, identifier:Qt; 74, identifier:ShiftModifier; 75, comment; 76, if_statement; 76, 77; 76, 85; 76, 148; 76, 220; 76, 221; 76, 449; 77, boolean_operator:and; 77, 78; 77, 79; 78, identifier:mod_mode; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:line; 82, identifier:endswith; 83, argument_list; 83, 84; 84, string:':'; 85, block; 85, 86; 85, 95; 85, 106; 85, 117; 85, 135; 85, 146; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:cursor; 90, identifier:movePosition; 91, argument_list; 91, 92; 92, attribute; 92, 93; 92, 94; 93, identifier:cursor; 94, identifier:EndOfLine; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:line; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:re; 101, identifier:sub; 102, argument_list; 102, 103; 102, 104; 102, 105; 103, string:'^>>> '; 104, string:''; 105, identifier:line; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:line; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:re; 112, identifier:sub; 113, argument_list; 113, 114; 113, 115; 113, 116; 114, string:'^\.\.\. '; 115, string:''; 116, identifier:line; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:count; 120, binary_operator:+; 120, 121; 120, 134; 121, binary_operator:-; 121, 122; 121, 126; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:line; 126, call; 126, 127; 126, 128; 127, identifier:len; 128, argument_list; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:line; 132, identifier:lstrip; 133, argument_list; 134, integer:4; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:insertPlainText; 140, argument_list; 140, 141; 141, binary_operator:+; 141, 142; 141, 143; 142, string:'\n... '; 143, binary_operator:*; 143, 144; 143, 145; 144, identifier:count; 145, string:' '; 146, return_statement; 146, 147; 147, False; 148, elif_clause; 148, 149; 148, 170; 149, boolean_operator:and; 149, 150; 149, 158; 149, 159; 150, boolean_operator:and; 150, 151; 150, 152; 151, identifier:mod_mode; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:line; 155, identifier:startswith; 156, argument_list; 156, 157; 157, string:'...'; 158, line_continuation:\; 159, parenthesized_expression; 159, 160; 160, boolean_operator:or; 160, 161; 160, 168; 161, comparison_operator:!=; 161, 162; 161, 167; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:line; 165, identifier:strip; 166, argument_list; 167, string:'...'; 168, not_operator; 168, 169; 169, identifier:at_end; 170, block; 170, 171; 170, 180; 170, 191; 170, 207; 170, 218; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:cursor; 175, identifier:movePosition; 176, argument_list; 176, 177; 177, attribute; 177, 178; 177, 179; 178, identifier:cursor; 179, identifier:EndOfLine; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:line; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:re; 186, identifier:sub; 187, argument_list; 187, 188; 187, 189; 187, 190; 188, string:'^\.\.\. '; 189, string:''; 190, identifier:line; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:count; 194, binary_operator:-; 194, 195; 194, 199; 195, call; 195, 196; 195, 197; 196, identifier:len; 197, argument_list; 197, 198; 198, identifier:line; 199, call; 199, 200; 199, 201; 200, identifier:len; 201, argument_list; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:line; 205, identifier:lstrip; 206, argument_list; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:insertPlainText; 212, argument_list; 212, 213; 213, binary_operator:+; 213, 214; 213, 215; 214, string:'\n... '; 215, binary_operator:*; 215, 216; 215, 217; 216, identifier:count; 217, string:' '; 218, return_statement; 218, 219; 219, False; 220, comment; 221, elif_clause; 221, 222; 221, 235; 221, 236; 222, boolean_operator:or; 222, 223; 222, 229; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:line; 226, identifier:startswith; 227, argument_list; 227, 228; 228, string:'>>>'; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:line; 232, identifier:startswith; 233, argument_list; 233, 234; 234, string:'...'; 235, comment; 236, block; 236, 237; 236, 256; 236, 292; 236, 293; 236, 302; 236, 321; 236, 325; 236, 329; 236, 401; 236, 410; 236, 411; 236, 412; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:line; 240, call; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:projex; 244, identifier:text; 245, identifier:nativestring; 246, argument_list; 246, 247; 247, call; 247, 248; 247, 255; 248, attribute; 248, 249; 248, 254; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:cursor; 252, identifier:block; 253, argument_list; 254, identifier:text; 255, argument_list; 256, while_statement; 256, 257; 256, 263; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:line; 260, identifier:startswith; 261, argument_list; 261, 262; 262, string:'...'; 263, block; 263, 264; 263, 273; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:cursor; 268, identifier:movePosition; 269, argument_list; 269, 270; 270, attribute; 270, 271; 270, 272; 271, identifier:cursor; 272, identifier:PreviousBlock; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:line; 276, call; 276, 277; 276, 282; 277, attribute; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:projex; 280, identifier:text; 281, identifier:nativestring; 282, argument_list; 282, 283; 283, call; 283, 284; 283, 291; 284, attribute; 284, 285; 284, 290; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:cursor; 288, identifier:block; 289, argument_list; 290, identifier:text; 291, argument_list; 292, comment; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:cursor; 297, identifier:movePosition; 298, argument_list; 298, 299; 299, attribute; 299, 300; 299, 301; 300, identifier:cursor; 301, identifier:EndOfLine; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:line; 305, call; 305, 306; 305, 311; 306, attribute; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:projex; 309, identifier:text; 310, identifier:nativestring; 311, argument_list; 311, 312; 312, call; 312, 313; 312, 320; 313, attribute; 313, 314; 313, 319; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:cursor; 317, identifier:block; 318, argument_list; 319, identifier:text; 320, argument_list; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:ended; 324, False; 325, expression_statement; 325, 326; 326, assignment; 326, 327; 326, 328; 327, identifier:lines; 328, list:[]; 329, while_statement; 329, 330; 329, 331; 329, 332; 330, True; 331, comment; 332, block; 332, 333; 332, 340; 332, 352; 332, 353; 332, 362; 332, 371; 332, 390; 332, 391; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:lines; 337, identifier:append; 338, argument_list; 338, 339; 339, identifier:line; 340, if_statement; 340, 341; 340, 346; 341, call; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:cursor; 344, identifier:atEnd; 345, argument_list; 346, block; 346, 347; 346, 351; 347, expression_statement; 347, 348; 348, assignment; 348, 349; 348, 350; 349, identifier:ended; 350, True; 351, break_statement; 352, comment; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:cursor; 357, identifier:movePosition; 358, argument_list; 358, 359; 359, attribute; 359, 360; 359, 361; 360, identifier:cursor; 361, identifier:NextBlock; 362, expression_statement; 362, 363; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:cursor; 366, identifier:movePosition; 367, argument_list; 367, 368; 368, attribute; 368, 369; 368, 370; 369, identifier:cursor; 370, identifier:EndOfLine; 371, expression_statement; 371, 372; 372, assignment; 372, 373; 372, 374; 373, identifier:line; 374, call; 374, 375; 374, 380; 375, attribute; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:projex; 378, identifier:text; 379, identifier:nativestring; 380, argument_list; 380, 381; 381, call; 381, 382; 381, 389; 382, attribute; 382, 383; 382, 388; 383, call; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:cursor; 386, identifier:block; 387, argument_list; 388, identifier:text; 389, argument_list; 390, comment; 391, if_statement; 391, 392; 391, 399; 392, not_operator; 392, 393; 393, call; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:line; 396, identifier:startswith; 397, argument_list; 397, 398; 398, string:'...'; 399, block; 399, 400; 400, break_statement; 401, expression_statement; 401, 402; 402, assignment; 402, 403; 402, 404; 403, identifier:command; 404, call; 404, 405; 404, 408; 405, attribute; 405, 406; 405, 407; 406, string:'\n'; 407, identifier:join; 408, argument_list; 408, 409; 409, identifier:lines; 410, comment; 411, comment; 412, if_statement; 412, 413; 412, 418; 413, not_operator; 413, 414; 414, parenthesized_expression; 414, 415; 415, boolean_operator:and; 415, 416; 415, 417; 416, identifier:ended; 417, identifier:command; 418, block; 418, 419; 418, 425; 418, 438; 418, 447; 419, expression_statement; 419, 420; 420, call; 420, 421; 420, 424; 421, attribute; 421, 422; 421, 423; 422, identifier:self; 423, identifier:waitForInput; 424, argument_list; 425, expression_statement; 425, 426; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:self; 429, identifier:insertPlainText; 430, argument_list; 430, 431; 431, call; 431, 432; 431, 435; 432, attribute; 432, 433; 432, 434; 433, identifier:command; 434, identifier:replace; 435, argument_list; 435, 436; 435, 437; 436, string:'>>> '; 437, string:''; 438, expression_statement; 438, 439; 439, call; 439, 440; 439, 443; 440, attribute; 440, 441; 440, 442; 441, identifier:cursor; 442, identifier:movePosition; 443, argument_list; 443, 444; 444, attribute; 444, 445; 444, 446; 445, identifier:cursor; 446, identifier:End; 447, return_statement; 447, 448; 448, False; 449, else_clause; 449, 450; 450, block; 450, 451; 450, 457; 451, expression_statement; 451, 452; 452, call; 452, 453; 452, 456; 453, attribute; 453, 454; 453, 455; 454, identifier:self; 455, identifier:waitForInput; 456, argument_list; 457, return_statement; 457, 458; 458, False; 459, expression_statement; 459, 460; 460, call; 460, 461; 460, 464; 461, attribute; 461, 462; 461, 463; 462, identifier:self; 463, identifier:executeCommand; 464, argument_list; 464, 465; 465, identifier:command; 466, return_statement; 466, 467; 467, True
def applyCommand(self): """ Applies the current line of code as an interactive python command. """ # generate the command information cursor = self.textCursor() cursor.movePosition(cursor.EndOfLine) line = projex.text.nativestring(cursor.block().text()) at_end = cursor.atEnd() modifiers = QApplication.instance().keyboardModifiers() mod_mode = at_end or modifiers == Qt.ShiftModifier # test the line for information if mod_mode and line.endswith(':'): cursor.movePosition(cursor.EndOfLine) line = re.sub('^>>> ', '', line) line = re.sub('^\.\.\. ', '', line) count = len(line) - len(line.lstrip()) + 4 self.insertPlainText('\n... ' + count * ' ') return False elif mod_mode and line.startswith('...') and \ (line.strip() != '...' or not at_end): cursor.movePosition(cursor.EndOfLine) line = re.sub('^\.\.\. ', '', line) count = len(line) - len(line.lstrip()) self.insertPlainText('\n... ' + count * ' ') return False # if we're not at the end of the console, then add it to the end elif line.startswith('>>>') or line.startswith('...'): # move to the top of the command structure line = projex.text.nativestring(cursor.block().text()) while line.startswith('...'): cursor.movePosition(cursor.PreviousBlock) line = projex.text.nativestring(cursor.block().text()) # calculate the command cursor.movePosition(cursor.EndOfLine) line = projex.text.nativestring(cursor.block().text()) ended = False lines = [] while True: # add the new block lines.append(line) if cursor.atEnd(): ended = True break # move to the next line cursor.movePosition(cursor.NextBlock) cursor.movePosition(cursor.EndOfLine) line = projex.text.nativestring(cursor.block().text()) # check for a new command or the end of the command if not line.startswith('...'): break command = '\n'.join(lines) # if we did not end up at the end of the command block, then # copy it for modification if not (ended and command): self.waitForInput() self.insertPlainText(command.replace('>>> ', '')) cursor.movePosition(cursor.End) return False else: self.waitForInput() return False self.executeCommand(command) return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:pager; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:lines; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, try_statement; 9, 10; 9, 250; 10, block; 10, 11; 10, 15; 10, 37; 10, 52; 10, 56; 10, 236; 10, 237; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:line_count; 14, integer:0; 15, if_statement; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_output_filename; 19, block; 19, 20; 19, 25; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:print; 23, argument_list; 23, 24; 24, string:f"Output is also going to '{self.output_file}'"; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_output_file; 30, call; 30, 31; 30, 32; 31, identifier:open; 32, argument_list; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_output_filename; 36, string:"a+"; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 42; 39, pattern_list; 39, 40; 39, 41; 40, identifier:terminal_columns; 41, identifier:terminal_lines; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:shutil; 45, identifier:get_terminal_size; 46, argument_list; 46, 47; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:fallback; 49, tuple; 49, 50; 49, 51; 50, integer:80; 51, integer:24; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:lines_left; 55, identifier:terminal_lines; 56, for_statement; 56, 57; 56, 60; 56, 65; 57, pattern_list; 57, 58; 57, 59; 58, identifier:i; 59, identifier:l; 60, call; 60, 61; 60, 62; 61, identifier:enumerate; 62, argument_list; 62, 63; 62, 64; 63, identifier:lines; 64, integer:1; 65, block; 65, 66; 65, 70; 65, 85; 65, 97; 65, 109; 65, 128; 65, 139; 65, 140; 65, 145; 65, 167; 65, 168; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:line_residue; 69, integer:0; 70, if_statement; 70, 71; 70, 74; 70, 79; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:line_numbers; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:output_line; 78, string:f"{i:<4} {l}"; 79, else_clause; 79, 80; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:output_line; 84, identifier:l; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:line_overflow; 88, call; 88, 89; 88, 90; 89, identifier:int; 90, argument_list; 90, 91; 91, binary_operator:/; 91, 92; 91, 96; 92, call; 92, 93; 92, 94; 93, identifier:len; 94, argument_list; 94, 95; 95, identifier:output_line; 96, identifier:terminal_columns; 97, if_statement; 97, 98; 97, 99; 98, identifier:line_overflow; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:line_residue; 103, binary_operator:%; 103, 104; 103, 108; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, identifier:output_line; 108, identifier:terminal_columns; 109, if_statement; 109, 110; 109, 113; 109, 120; 110, comparison_operator:>=; 110, 111; 110, 112; 111, identifier:line_overflow; 112, integer:1; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:lines_left; 117, binary_operator:-; 117, 118; 117, 119; 118, identifier:lines_left; 119, identifier:line_overflow; 120, else_clause; 120, 121; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:lines_left; 125, binary_operator:-; 125, 126; 125, 127; 126, identifier:lines_left; 127, integer:1; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:>; 129, 130; 129, 131; 130, identifier:line_residue; 131, integer:1; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:lines_left; 136, binary_operator:-; 136, 137; 136, 138; 137, identifier:lines_left; 138, integer:1; 139, comment; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:print; 143, argument_list; 143, 144; 144, identifier:output_line; 145, if_statement; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:_output_file; 149, block; 149, 150; 149, 159; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:_output_file; 156, identifier:write; 157, argument_list; 157, 158; 158, string:f"{l}\n"; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:_output_file; 165, identifier:flush; 166, argument_list; 167, comment; 168, if_statement; 168, 169; 168, 179; 168, 180; 169, comparison_operator:<=; 169, 170; 169, 178; 170, parenthesized_expression; 170, 171; 171, binary_operator:-; 171, 172; 171, 177; 172, binary_operator:-; 172, 173; 172, 174; 173, identifier:lines_left; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:overlap; 177, integer:1; 178, integer:0; 179, comment; 180, block; 180, 181; 181, if_statement; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:paginate; 185, block; 185, 186; 185, 194; 185, 200; 185, 217; 185, 232; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 189; 188, identifier:print; 189, argument_list; 189, 190; 189, 191; 190, string:"Hit Return to continue (q or quit to exit)"; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:end; 193, string:""; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:user_input; 197, call; 197, 198; 197, 199; 198, identifier:input; 199, argument_list; 200, if_statement; 200, 201; 200, 215; 201, comparison_operator:in; 201, 202; 201, 211; 202, call; 202, 203; 202, 210; 203, attribute; 203, 204; 203, 209; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:user_input; 207, identifier:lower; 208, argument_list; 209, identifier:strip; 210, argument_list; 211, list:["q", "quit", "exit"]; 211, 212; 211, 213; 211, 214; 212, string:"q"; 213, string:"quit"; 214, string:"exit"; 215, block; 215, 216; 216, break_statement; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 222; 219, pattern_list; 219, 220; 219, 221; 220, identifier:terminal_columns; 221, identifier:terminal_lines; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:shutil; 225, identifier:get_terminal_size; 226, argument_list; 226, 227; 227, keyword_argument; 227, 228; 227, 229; 228, identifier:fallback; 229, tuple; 229, 230; 229, 231; 230, integer:80; 231, integer:24; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:lines_left; 235, identifier:terminal_lines; 236, comment; 237, if_statement; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:_output_file; 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:_output_file; 248, identifier:close; 249, argument_list; 250, except_clause; 250, 251; 250, 252; 251, identifier:KeyboardInterrupt; 252, block; 252, 253; 252, 258; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 256; 255, identifier:print; 256, argument_list; 256, 257; 257, string:"ctrl-C..."; 258, if_statement; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:_output_file; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 270; 265, attribute; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:_output_file; 269, identifier:close; 270, argument_list
def pager(self, lines): """ Outputs lines to a terminal. It uses `shutil.get_terminal_size` to determine the height of the terminal. It expects an iterator that returns a line at a time and those lines should be terminated by a valid newline sequence. Behaviour is controlled by a number of external class properties. `paginate` : Is on by default and triggers pagination. Without `paginate` all output is written straight to the screen. `output_file` : By assigning a name to this property we can ensure that all output is sent to the corresponding file. Prompts are not output. `pretty_print` : If this is set (default is on) then all output is pretty printed with `pprint`. If it is off then the output is just written to the screen. `overlap` : The number of lines to overlap between one page and the next. :param lines: :return: paginated output """ try: line_count = 0 if self._output_filename: print(f"Output is also going to '{self.output_file}'") self._output_file = open(self._output_filename, "a+") terminal_columns, terminal_lines = shutil.get_terminal_size(fallback=(80, 24)) lines_left = terminal_lines for i, l in enumerate(lines, 1): line_residue = 0 if self.line_numbers: output_line = f"{i:<4} {l}" else: output_line = l line_overflow = int(len(output_line) / terminal_columns) if line_overflow: line_residue = len(output_line) % terminal_columns if line_overflow >= 1: lines_left = lines_left - line_overflow else: lines_left = lines_left - 1 if line_residue > 1: lines_left = lines_left - 1 # line_count = line_count + 1 print(output_line) if self._output_file: self._output_file.write(f"{l}\n") self._output_file.flush() #print(lines_left) if (lines_left - self.overlap - 1) <= 0: # -1 to leave room for prompt if self.paginate: print("Hit Return to continue (q or quit to exit)", end="") user_input = input() if user_input.lower().strip() in ["q", "quit", "exit"]: break terminal_columns, terminal_lines = shutil.get_terminal_size(fallback=(80, 24)) lines_left = terminal_lines # end for if self._output_file: self._output_file.close() except KeyboardInterrupt: print("ctrl-C...") if self._output_file: self._output_file.close()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:merge; 3, parameters; 3, 4; 4, identifier:constraints; 5, block; 5, 6; 5, 8; 5, 9; 5, 16; 5, 33; 5, 34; 5, 57; 5, 58; 5, 81; 5, 82; 5, 104; 5, 105; 5, 127; 5, 128; 5, 132; 5, 212; 5, 213; 5, 217; 5, 297; 5, 298; 5, 383; 5, 397; 5, 411; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:operators; 12, call; 12, 13; 12, 14; 13, identifier:defaultdict; 14, argument_list; 14, 15; 15, identifier:set; 16, for_statement; 16, 17; 16, 18; 16, 19; 17, identifier:constraint; 18, identifier:constraints; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 29; 22, attribute; 22, 23; 22, 28; 23, subscript; 23, 24; 23, 25; 24, identifier:operators; 25, attribute; 25, 26; 25, 27; 26, identifier:constraint; 27, identifier:operator; 28, identifier:add; 29, argument_list; 29, 30; 30, attribute; 30, 31; 30, 32; 31, identifier:constraint; 32, identifier:version; 33, comment; 34, if_statement; 34, 35; 34, 38; 34, 51; 35, comparison_operator:in; 35, 36; 35, 37; 36, identifier:gt; 37, identifier:operators; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:gt_ver; 42, subscript; 42, 43; 42, 49; 43, call; 43, 44; 43, 45; 44, identifier:sorted; 45, argument_list; 45, 46; 46, subscript; 46, 47; 46, 48; 47, identifier:operators; 48, identifier:gt; 49, unary_operator:-; 49, 50; 50, integer:1; 51, else_clause; 51, 52; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:gt_ver; 56, None; 57, comment; 58, if_statement; 58, 59; 58, 62; 58, 75; 59, comparison_operator:in; 59, 60; 59, 61; 60, identifier:ge; 61, identifier:operators; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:ge_ver; 66, subscript; 66, 67; 66, 73; 67, call; 67, 68; 67, 69; 68, identifier:sorted; 69, argument_list; 69, 70; 70, subscript; 70, 71; 70, 72; 71, identifier:operators; 72, identifier:ge; 73, unary_operator:-; 73, 74; 74, integer:1; 75, else_clause; 75, 76; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:ge_ver; 80, None; 81, comment; 82, if_statement; 82, 83; 82, 86; 82, 98; 83, comparison_operator:in; 83, 84; 83, 85; 84, identifier:lt; 85, identifier:operators; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:lt_ver; 90, subscript; 90, 91; 90, 97; 91, call; 91, 92; 91, 93; 92, identifier:sorted; 93, argument_list; 93, 94; 94, subscript; 94, 95; 94, 96; 95, identifier:operators; 96, identifier:lt; 97, integer:0; 98, else_clause; 98, 99; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:lt_ver; 103, None; 104, comment; 105, if_statement; 105, 106; 105, 109; 105, 121; 106, comparison_operator:in; 106, 107; 106, 108; 107, identifier:le; 108, identifier:operators; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:le_ver; 113, subscript; 113, 114; 113, 120; 114, call; 114, 115; 114, 116; 115, identifier:sorted; 116, argument_list; 116, 117; 117, subscript; 117, 118; 117, 119; 118, identifier:operators; 119, identifier:le; 120, integer:0; 121, else_clause; 121, 122; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:le_ver; 126, None; 127, comment; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:l_constraint; 131, None; 132, if_statement; 132, 133; 132, 134; 132, 201; 133, identifier:le_ver; 134, block; 134, 135; 135, if_statement; 135, 136; 135, 137; 135, 191; 136, identifier:lt_ver; 137, block; 137, 138; 137, 146; 137, 154; 137, 180; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:le_constraint; 141, call; 141, 142; 141, 143; 142, identifier:Constraint; 143, argument_list; 143, 144; 143, 145; 144, identifier:le; 145, identifier:le_ver; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:lt_constraint; 149, call; 149, 150; 149, 151; 150, identifier:Constraint; 151, argument_list; 151, 152; 151, 153; 152, identifier:lt; 153, identifier:lt_ver; 154, if_statement; 154, 155; 154, 158; 154, 159; 154, 168; 155, comparison_operator:<; 155, 156; 155, 157; 156, identifier:le_ver; 157, identifier:lt_ver; 158, comment; 159, block; 159, 160; 159, 164; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:l_constraint; 163, identifier:le_constraint; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:l_less_restrictive_c; 167, identifier:lt_constraint; 168, else_clause; 168, 169; 168, 170; 168, 171; 169, comment; 170, comment; 171, block; 171, 172; 171, 176; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:l_constraint; 175, identifier:lt_constraint; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:l_less_restrictive_c; 179, identifier:le_constraint; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:LOGGER; 184, identifier:debug; 185, argument_list; 185, 186; 185, 189; 185, 190; 186, concatenated_string; 186, 187; 186, 188; 187, string:'Removed constraint %s because it is less '; 188, string:'restrictive than %s'; 189, identifier:l_less_restrictive_c; 190, identifier:l_constraint; 191, else_clause; 191, 192; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:l_constraint; 196, call; 196, 197; 196, 198; 197, identifier:Constraint; 198, argument_list; 198, 199; 198, 200; 199, identifier:le; 200, identifier:le_ver; 201, elif_clause; 201, 202; 201, 203; 202, identifier:lt_ver; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:l_constraint; 207, call; 207, 208; 207, 209; 208, identifier:Constraint; 209, argument_list; 209, 210; 209, 211; 210, identifier:lt; 211, identifier:lt_ver; 212, comment; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:g_constraint; 216, None; 217, if_statement; 217, 218; 217, 219; 217, 286; 218, identifier:ge_ver; 219, block; 219, 220; 220, if_statement; 220, 221; 220, 222; 220, 276; 221, identifier:gt_ver; 222, block; 222, 223; 222, 231; 222, 239; 222, 265; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:gt_constraint; 226, call; 226, 227; 226, 228; 227, identifier:Constraint; 228, argument_list; 228, 229; 228, 230; 229, identifier:gt; 230, identifier:gt_ver; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:ge_constraint; 234, call; 234, 235; 234, 236; 235, identifier:Constraint; 236, argument_list; 236, 237; 236, 238; 237, identifier:ge; 238, identifier:ge_ver; 239, if_statement; 239, 240; 239, 243; 239, 244; 239, 245; 239, 254; 240, comparison_operator:<=; 240, 241; 240, 242; 241, identifier:ge_ver; 242, identifier:gt_ver; 243, comment; 244, comment; 245, block; 245, 246; 245, 250; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:g_constraint; 249, identifier:gt_constraint; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:g_less_restrictive_c; 253, identifier:ge_constraint; 254, else_clause; 254, 255; 254, 256; 255, comment; 256, block; 256, 257; 256, 261; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:g_constraint; 260, identifier:ge_constraint; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:g_less_restrictive_c; 264, identifier:gt_constraint; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:LOGGER; 269, identifier:debug; 270, argument_list; 270, 271; 270, 274; 270, 275; 271, concatenated_string; 271, 272; 271, 273; 272, string:'Removed constraint %s because it is less '; 273, string:'restrictive than %s'; 274, identifier:g_less_restrictive_c; 275, identifier:g_constraint; 276, else_clause; 276, 277; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:g_constraint; 281, call; 281, 282; 281, 283; 282, identifier:Constraint; 283, argument_list; 283, 284; 283, 285; 284, identifier:ge; 285, identifier:ge_ver; 286, elif_clause; 286, 287; 286, 288; 287, identifier:gt_ver; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:g_constraint; 292, call; 292, 293; 292, 294; 293, identifier:Constraint; 294, argument_list; 294, 295; 294, 296; 295, identifier:gt; 296, identifier:gt_ver; 297, comment; 298, if_statement; 298, 299; 298, 302; 299, boolean_operator:and; 299, 300; 299, 301; 300, identifier:g_constraint; 301, identifier:l_constraint; 302, block; 302, 303; 303, if_statement; 303, 304; 303, 311; 303, 367; 304, comparison_operator:==; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:g_constraint; 307, identifier:version; 308, attribute; 308, 309; 308, 310; 309, identifier:l_constraint; 310, identifier:version; 311, block; 311, 312; 312, if_statement; 312, 313; 312, 324; 312, 325; 312, 326; 312, 358; 313, boolean_operator:and; 313, 314; 313, 319; 314, comparison_operator:==; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:g_constraint; 317, identifier:operator; 318, identifier:ge; 319, comparison_operator:==; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:l_constraint; 322, identifier:operator; 323, identifier:le; 324, comment; 325, comment; 326, block; 326, 327; 326, 338; 326, 350; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 334; 329, attribute; 329, 330; 329, 333; 330, subscript; 330, 331; 330, 332; 331, identifier:operators; 332, identifier:eq; 333, identifier:add; 334, argument_list; 334, 335; 335, attribute; 335, 336; 335, 337; 336, identifier:g_constraint; 337, identifier:version; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:LOGGER; 342, identifier:debug; 343, argument_list; 343, 344; 343, 345; 343, 346; 343, 347; 344, string:'Merged constraints: %s and %s into ==%s'; 345, identifier:l_constraint; 346, identifier:g_constraint; 347, attribute; 347, 348; 347, 349; 348, identifier:g_constraint; 349, identifier:version; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 355; 352, pattern_list; 352, 353; 352, 354; 353, identifier:l_constraint; 354, identifier:g_constraint; 355, expression_list; 355, 356; 355, 357; 356, None; 357, None; 358, else_clause; 358, 359; 359, block; 359, 360; 360, raise_statement; 360, 361; 361, call; 361, 362; 361, 363; 362, identifier:ExclusiveConstraints; 363, argument_list; 363, 364; 363, 365; 364, identifier:g_constraint; 365, list:[l_constraint]; 365, 366; 366, identifier:l_constraint; 367, elif_clause; 367, 368; 367, 375; 368, comparison_operator:>; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:g_constraint; 371, identifier:version; 372, attribute; 372, 373; 372, 374; 373, identifier:l_constraint; 374, identifier:version; 375, block; 375, 376; 376, raise_statement; 376, 377; 377, call; 377, 378; 377, 379; 378, identifier:ExclusiveConstraints; 379, argument_list; 379, 380; 379, 381; 380, identifier:g_constraint; 381, list:[l_constraint]; 381, 382; 382, identifier:l_constraint; 383, expression_statement; 383, 384; 384, assignment; 384, 385; 384, 386; 385, identifier:ne_constraints; 386, list_comprehension; 386, 387; 386, 392; 387, call; 387, 388; 387, 389; 388, identifier:Constraint; 389, argument_list; 389, 390; 389, 391; 390, identifier:ne; 391, identifier:v; 392, for_in_clause; 392, 393; 392, 394; 393, identifier:v; 394, subscript; 394, 395; 394, 396; 395, identifier:operators; 396, identifier:ne; 397, expression_statement; 397, 398; 398, assignment; 398, 399; 398, 400; 399, identifier:eq_constraints; 400, list_comprehension; 400, 401; 400, 406; 401, call; 401, 402; 401, 403; 402, identifier:Constraint; 403, argument_list; 403, 404; 403, 405; 404, identifier:eq; 405, identifier:v; 406, for_in_clause; 406, 407; 406, 408; 407, identifier:v; 408, subscript; 408, 409; 408, 410; 409, identifier:operators; 410, identifier:eq; 411, if_statement; 411, 412; 411, 413; 411, 467; 412, identifier:eq_constraints; 413, block; 413, 414; 413, 422; 413, 423; 413, 464; 414, expression_statement; 414, 415; 415, assignment; 415, 416; 415, 417; 416, identifier:eq_constraint; 417, call; 417, 418; 417, 421; 418, attribute; 418, 419; 418, 420; 419, identifier:eq_constraints; 420, identifier:pop; 421, argument_list; 422, comment; 423, if_statement; 423, 424; 423, 431; 424, boolean_operator:or; 424, 425; 424, 430; 425, boolean_operator:or; 425, 426; 425, 429; 426, boolean_operator:or; 426, 427; 426, 428; 427, identifier:g_constraint; 428, identifier:l_constraint; 429, identifier:ne_constraints; 430, identifier:eq_constraints; 431, block; 431, 432; 431, 444; 431, 451; 431, 458; 432, expression_statement; 432, 433; 433, assignment; 433, 434; 433, 435; 434, identifier:conflict_list; 435, list_comprehension; 435, 436; 435, 437; 435, 442; 436, identifier:c; 437, for_in_clause; 437, 438; 437, 439; 438, identifier:c; 439, tuple; 439, 440; 439, 441; 440, identifier:g_constraint; 441, identifier:l_constraint; 442, if_clause; 442, 443; 443, identifier:c; 444, expression_statement; 444, 445; 445, call; 445, 446; 445, 449; 446, attribute; 446, 447; 446, 448; 447, identifier:conflict_list; 448, identifier:extend; 449, argument_list; 449, 450; 450, identifier:ne_constraints; 451, expression_statement; 451, 452; 452, call; 452, 453; 452, 456; 453, attribute; 453, 454; 453, 455; 454, identifier:conflict_list; 455, identifier:extend; 456, argument_list; 456, 457; 457, identifier:eq_constraints; 458, raise_statement; 458, 459; 459, call; 459, 460; 459, 461; 460, identifier:ExclusiveConstraints; 461, argument_list; 461, 462; 461, 463; 462, identifier:eq_constraint; 463, identifier:conflict_list; 464, return_statement; 464, 465; 465, list:[eq_constraint]; 465, 466; 466, identifier:eq_constraint; 467, else_clause; 467, 468; 468, block; 468, 469; 468, 477; 469, expression_statement; 469, 470; 470, assignment; 470, 471; 470, 472; 471, identifier:constraints; 472, binary_operator:+; 472, 473; 472, 474; 473, identifier:ne_constraints; 474, list:[g_constraint, l_constraint]; 474, 475; 474, 476; 475, identifier:g_constraint; 476, identifier:l_constraint; 477, return_statement; 477, 478; 478, list_comprehension; 478, 479; 478, 480; 478, 483; 479, identifier:c; 480, for_in_clause; 480, 481; 480, 482; 481, identifier:c; 482, identifier:constraints; 483, if_clause; 483, 484; 484, identifier:c
def merge(constraints): """Merge ``constraints``. It removes dupplicate, pruned and merged constraints. :param constraints: Current constraints. :type constraints: Iterable of :class:`.Constraint` objects. :rtype: :func:`list` of :class:`.Constraint` objects. :raises: :exc:`.ExclusiveConstraints` """ # Dictionary :class:`Operator`: set of :class:`Version`. operators = defaultdict(set) for constraint in constraints: operators[constraint.operator].add(constraint.version) # Get most recent version required by > constraints. if gt in operators: gt_ver = sorted(operators[gt])[-1] else: gt_ver = None # Get most recent version required by >= constraints. if ge in operators: ge_ver = sorted(operators[ge])[-1] else: ge_ver = None # Get least recent version required by < constraints. if lt in operators: lt_ver = sorted(operators[lt])[0] else: lt_ver = None # Get least recent version required by <= constraints. if le in operators: le_ver = sorted(operators[le])[0] else: le_ver = None # Most restrictive LT/LE constraint. l_constraint = None if le_ver: if lt_ver: le_constraint = Constraint(le, le_ver) lt_constraint = Constraint(lt, lt_ver) if le_ver < lt_ver: # <= 1, < 2 l_constraint = le_constraint l_less_restrictive_c = lt_constraint else: # <= 2, < 1 # <= 2, < 2 l_constraint = lt_constraint l_less_restrictive_c = le_constraint LOGGER.debug('Removed constraint %s because it is less ' 'restrictive than %s', l_less_restrictive_c, l_constraint) else: l_constraint = Constraint(le, le_ver) elif lt_ver: l_constraint = Constraint(lt, lt_ver) # Most restrictive GT/GE constraint. g_constraint = None if ge_ver: if gt_ver: gt_constraint = Constraint(gt, gt_ver) ge_constraint = Constraint(ge, ge_ver) if ge_ver <= gt_ver: # >= 1, > 2 # >= 2, > 2 g_constraint = gt_constraint g_less_restrictive_c = ge_constraint else: # >= 2, > 1 g_constraint = ge_constraint g_less_restrictive_c = gt_constraint LOGGER.debug('Removed constraint %s because it is less ' 'restrictive than %s', g_less_restrictive_c, g_constraint) else: g_constraint = Constraint(ge, ge_ver) elif gt_ver: g_constraint = Constraint(gt, gt_ver) # Check if g_constraint and l_constraint are conflicting if g_constraint and l_constraint: if g_constraint.version == l_constraint.version: if g_constraint.operator == ge and l_constraint.operator == le: # Merge >= and <= constraints on same version to a == # constraint operators[eq].add(g_constraint.version) LOGGER.debug('Merged constraints: %s and %s into ==%s', l_constraint, g_constraint, g_constraint.version) l_constraint, g_constraint = None, None else: raise ExclusiveConstraints(g_constraint, [l_constraint]) elif g_constraint.version > l_constraint.version: raise ExclusiveConstraints(g_constraint, [l_constraint]) ne_constraints = [Constraint(ne, v) for v in operators[ne]] eq_constraints = [Constraint(eq, v) for v in operators[eq]] if eq_constraints: eq_constraint = eq_constraints.pop() # An eq constraint conflicts with other constraints if g_constraint or l_constraint or ne_constraints or eq_constraints: conflict_list = [c for c in (g_constraint, l_constraint) if c] conflict_list.extend(ne_constraints) conflict_list.extend(eq_constraints) raise ExclusiveConstraints(eq_constraint, conflict_list) return [eq_constraint] else: constraints = ne_constraints + [g_constraint, l_constraint] return [c for c in constraints if c]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_baxter; 3, parameters; 3, 4; 4, identifier:reading; 5, block; 5, 6; 5, 8; 5, 12; 5, 16; 5, 20; 5, 24; 5, 25; 5, 29; 5, 33; 5, 37; 5, 41; 5, 45; 5, 52; 5, 144; 5, 145; 5, 168; 5, 169; 5, 182; 5, 183; 5, 200; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:initial; 11, string:''; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:medial; 15, string:''; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:final; 19, string:''; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:tone; 23, string:''; 24, comment; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:inienv; 28, True; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:medienv; 32, False; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:finenv; 36, False; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:tonenv; 40, False; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:inichars; 44, string:"pbmrtdnkgnsyhzl'x"; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:chars; 48, call; 48, 49; 48, 50; 49, identifier:list; 50, argument_list; 50, 51; 51, identifier:reading; 52, for_statement; 52, 53; 52, 54; 52, 55; 52, 56; 53, identifier:char; 54, identifier:chars; 55, comment; 56, block; 56, 57; 56, 115; 56, 116; 56, 123; 56, 130; 56, 137; 57, if_statement; 57, 58; 57, 64; 57, 77; 58, boolean_operator:and; 58, 59; 58, 62; 59, comparison_operator:in; 59, 60; 59, 61; 60, identifier:char; 61, string:'jw'; 62, not_operator; 62, 63; 63, identifier:finenv; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 72; 67, pattern_list; 67, 68; 67, 69; 67, 70; 67, 71; 68, identifier:inienv; 69, identifier:medienv; 70, identifier:finenv; 71, identifier:tonenv; 72, expression_list; 72, 73; 72, 74; 72, 75; 72, 76; 73, False; 74, True; 75, False; 76, False; 77, elif_clause; 77, 78; 77, 83; 78, boolean_operator:or; 78, 79; 78, 82; 79, comparison_operator:not; 79, 80; 79, 81; 80, identifier:char; 81, identifier:inichars; 82, identifier:finenv; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 88; 84, 101; 85, comparison_operator:in; 85, 86; 85, 87; 86, identifier:char; 87, string:'XH'; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 96; 91, pattern_list; 91, 92; 91, 93; 91, 94; 91, 95; 92, identifier:inienv; 93, identifier:medienv; 94, identifier:finenv; 95, identifier:tonenv; 96, expression_list; 96, 97; 96, 98; 96, 99; 96, 100; 97, False; 98, False; 99, False; 100, True; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 110; 105, pattern_list; 105, 106; 105, 107; 105, 108; 105, 109; 106, identifier:inienv; 107, identifier:medienv; 108, identifier:finenv; 109, identifier:tonenv; 110, expression_list; 110, 111; 110, 112; 110, 113; 110, 114; 111, False; 112, False; 113, True; 114, False; 115, comment; 116, if_statement; 116, 117; 116, 118; 117, identifier:inienv; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, augmented_assignment:+=; 120, 121; 120, 122; 121, identifier:initial; 122, identifier:char; 123, if_statement; 123, 124; 123, 125; 124, identifier:medienv; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, augmented_assignment:+=; 127, 128; 127, 129; 128, identifier:medial; 129, identifier:char; 130, if_statement; 130, 131; 130, 132; 131, identifier:finenv; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, augmented_assignment:+=; 134, 135; 134, 136; 135, identifier:final; 136, identifier:char; 137, if_statement; 137, 138; 137, 139; 138, identifier:tonenv; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, augmented_assignment:+=; 141, 142; 141, 143; 142, identifier:tone; 143, identifier:char; 144, comment; 145, if_statement; 145, 146; 145, 155; 145, 160; 146, boolean_operator:and; 146, 147; 146, 149; 147, not_operator; 147, 148; 148, identifier:tone; 149, comparison_operator:in; 149, 150; 149, 154; 150, subscript; 150, 151; 150, 152; 151, identifier:final; 152, unary_operator:-; 152, 153; 153, integer:1; 154, string:'ptk'; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:tone; 159, string:'R'; 160, elif_clause; 160, 161; 160, 163; 161, not_operator; 161, 162; 162, identifier:tone; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:tone; 167, string:'P'; 168, comment; 169, if_statement; 169, 170; 169, 177; 170, boolean_operator:and; 170, 171; 170, 174; 171, comparison_operator:not; 171, 172; 171, 173; 172, string:'j'; 173, identifier:medial; 174, comparison_operator:in; 174, 175; 174, 176; 175, string:'y'; 176, identifier:initial; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, augmented_assignment:+=; 179, 180; 179, 181; 180, identifier:medial; 181, string:'j'; 182, comment; 183, if_statement; 183, 184; 183, 193; 184, boolean_operator:and; 184, 185; 184, 190; 185, comparison_operator:in; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:final; 188, integer:0; 189, string:'u'; 190, comparison_operator:not; 190, 191; 190, 192; 191, string:'w'; 192, identifier:medial; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:medial; 197, binary_operator:+; 197, 198; 197, 199; 198, string:'w'; 199, identifier:medial; 200, return_statement; 200, 201; 201, expression_list; 201, 202; 201, 203; 201, 204; 201, 205; 202, identifier:initial; 203, identifier:medial; 204, identifier:final; 205, identifier:tone
def parse_baxter(reading): """ Parse a Baxter string and render it with all its contents, namely initial, medial, final, and tone. """ initial = '' medial = '' final = '' tone = '' # determine environments inienv = True medienv = False finenv = False tonenv = False inichars = "pbmrtdnkgnsyhzl'x" chars = list(reading) for char in chars: # switch environments if char in 'jw' and not finenv: inienv,medienv,finenv,tonenv = False,True,False,False elif char not in inichars or finenv: if char in 'XH': inienv,medienv,finenv,tonenv = False,False,False,True else: inienv,medienv,finenv,tonenv = False,False,True,False # fill in slots if inienv: initial += char if medienv: medial += char if finenv: final += char if tonenv: tone += char # post-parse tone if not tone and final[-1] in 'ptk': tone = 'R' elif not tone: tone = 'P' # post-parse medial if 'j' not in medial and 'y' in initial: medial += 'j' # post-parse labial if final[0] in 'u' and 'w' not in medial: medial = 'w' + medial return initial,medial,final,tone
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:create; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:query; 6, keyword_separator; 7, default_parameter; 7, 8; 7, 9; 8, identifier:dc; 9, None; 10, block; 10, 11; 10, 13; 10, 34; 10, 55; 11, expression_statement; 11, 12; 12, comment; 13, if_statement; 13, 14; 13, 17; 13, 18; 14, comparison_operator:in; 14, 15; 14, 16; 15, string:"Token"; 16, identifier:query; 17, comment; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:query; 23, string:"Token"; 24, call; 24, 25; 24, 26; 25, identifier:extract_attr; 26, argument_list; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:query; 29, string:"Token"; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:keys; 32, list:["ID"]; 32, 33; 33, string:"ID"; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:response; 37, await; 37, 38; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_api; 43, identifier:post; 44, argument_list; 44, 45; 44, 46; 44, 52; 45, string:"/v1/query"; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:params; 48, dictionary; 48, 49; 49, pair; 49, 50; 49, 51; 50, string:"dc"; 51, identifier:dc; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:data; 54, identifier:query; 55, return_statement; 55, 56; 56, attribute; 56, 57; 56, 58; 57, identifier:response; 58, identifier:body
async def create(self, query, *, dc=None): """Creates a new prepared query Parameters: Query (Object): Query definition dc (str): Specify datacenter that will be used. Defaults to the agent's local datacenter. Returns: Object: New query ID The create operation expects a body that defines the prepared query, like this example:: { "Name": "my-query", "Session": "adf4238a-882b-9ddc-4a9d-5b6758e4159e", "Token": "", "Near": "node1", "Service": { "Service": "redis", "Failover": { "NearestN": 3, "Datacenters": ["dc1", "dc2"] }, "OnlyPassing": False, "Tags": ["master", "!experimental"] }, "DNS": { "TTL": timedelta(seconds=10) } } Only the **Service** field inside the **Service** structure is mandatory, all other fields will take their default values if they are not included. **Name** is an optional friendly name that can be used to execute a query instead of using its ID. **Session** provides a way to automatically remove a prepared query when the given session is invalidated. This is optional, and if not given the prepared query must be manually removed when no longer needed. **Token**, if specified, is a captured ACL Token that is reused as the ACL Token every time the query is executed. This allows queries to be executed by clients with lesser or even no ACL Token, so this should be used with care. The token itself can only be seen by clients with a management token. If the **Token** field is left blank or omitted, the client's ACL Token will be used to determine if they have access to the service being queried. If the client does not supply an ACL Token, the anonymous token will be used. **Near** allows specifying a particular node to sort near based on distance sorting using Network Coordinates. The nearest instance to the specified node will be returned first, and subsequent nodes in the response will be sorted in ascending order of estimated round-trip times. If the node given does not exist, the nodes in the response will be shuffled. Using the magic **_agent** value is supported, and will automatically return results nearest the agent servicing the request. If unspecified, the response will be shuffled by default. The set of fields inside the **Service** structure define the query's behavior. **Service** is the name of the service to query. This is required. **Failover** contains two fields, both of which are optional, and determine what happens if no healthy nodes are available in the local datacenter when the query is executed. It allows the use of nodes in other datacenters with very little configuration. If **NearestN** is set to a value greater than zero, then the query will be forwarded to up to **NearestN** other datacenters based on their estimated network round trip time using Network Coordinates from the WAN gossip pool. The median round trip time from the server handling the query to the servers in the remote datacenter is used to determine the priority. The default value is zero. All Consul servers must be running version 0.6.0 or above in order for this feature to work correctly. If any servers are not running the required version of Consul they will be considered last since they won't have any available network coordinate information. **Datacenters** contains a fixed list of remote datacenters to forward the query to if there are no healthy nodes in the local datacenter. Datacenters are queried in the order given in the list. If this option is combined with **NearestN**, then the **NearestN** queries will be performed first, followed by the list given by **Datacenters**. A given datacenter will only be queried one time during a failover, even if it is selected by both **NearestN** and is listed in **Datacenters**. The default value is an empty list. **OnlyPassing** controls the behavior of the query's health check filtering. If this is set to false, the results will include nodes with checks in the passing as well as the warning states. If this is set to true, only nodes with checks in the passing state will be returned. The default value is False. **Tags** provides a list of service tags to filter the query results. For a service to pass the tag filter it must have all of the required tags, and none of the excluded tags (prefixed with ``!``). The default value is an empty list, which does no tag filtering. **TTL** in the **DNS** structure is a duration string that can use "s" as a suffix for seconds. It controls how the TTL is set when query results are served over DNS. If this isn't specified, then the Consul agent configuration for the given service will be used (see DNS Caching). If this is specified, it will take precedence over any Consul agent-specific configuration. If no TTL is specified here or at the Consul agent level, then the TTL will default to 0. It returns the ID of the created query:: { "ID": "8f246b77-f3e1-ff88-5b48-8ec93abf3e05" } """ if "Token" in query: # in case of a full token object... query["Token"] = extract_attr(query["Token"], keys=["ID"]) response = await self._api.post("/v1/query", params={"dc": dc}, data=query) return response.body
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:execute; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:self; 5, identifier:query; 6, keyword_separator; 7, default_parameter; 7, 8; 7, 9; 8, identifier:dc; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:near; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:limit; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:consistency; 18, None; 19, block; 19, 20; 19, 22; 19, 33; 19, 62; 20, expression_statement; 20, 21; 21, comment; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:query_id; 25, call; 25, 26; 25, 27; 26, identifier:extract_attr; 27, argument_list; 27, 28; 27, 29; 28, identifier:query; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:keys; 31, list:["ID"]; 31, 32; 32, string:"ID"; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:response; 36, await; 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:_api; 42, identifier:get; 43, argument_list; 43, 44; 43, 47; 43, 59; 44, binary_operator:%; 44, 45; 44, 46; 45, string:"/v1/query/%s/execute"; 46, identifier:query_id; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:params; 49, dictionary; 49, 50; 49, 53; 49, 56; 50, pair; 50, 51; 50, 52; 51, string:"dc"; 52, identifier:dc; 53, pair; 53, 54; 53, 55; 54, string:"near"; 55, identifier:near; 56, pair; 56, 57; 56, 58; 57, string:"limit"; 58, identifier:limit; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:consistency; 61, identifier:consistency; 62, return_statement; 62, 63; 63, attribute; 63, 64; 63, 65; 64, identifier:response; 65, identifier:body
async def execute(self, query, *, dc=None, near=None, limit=None, consistency=None): """Executes a prepared query Parameters: query (ObjectID): Query ID dc (str): Specify datacenter that will be used. Defaults to the agent's local datacenter. near (str): Sort the resulting list in ascending order based on the estimated round trip time from that node limit (int): Limit the list's size to the given number of nodes consistency (Consistency): Force consistency Returns: Object: Raises: NotFound: the query does not exist Returns a body like this:: { "Service": "redis", "Nodes": [ { "Node": { "Node": "foobar", "Address": "10.1.10.12", "TaggedAddresses": { "lan": "10.1.10.12", "wan": "10.1.10.12" } }, "Service": { "ID": "redis", "Service": "redis", "Tags": None, "Port": 8000 }, "Checks": [ { "Node": "foobar", "CheckID": "service:redis", "Name": "Service 'redis' check", "Status": "passing", "Notes": "", "Output": "", "ServiceID": "redis", "ServiceName": "redis" }, { "Node": "foobar", "CheckID": "serfHealth", "Name": "Serf Health Status", "Status": "passing", "Notes": "", "Output": "", "ServiceID": "", "ServiceName": "" } ], "DNS": { "TTL": timedelta(seconds=10) }, "Datacenter": "dc3", "Failovers": 2 } ] } The **Nodes** section contains the list of healthy nodes providing the given service, as specified by the constraints of the prepared query. **Service** has the service name that the query was selecting. This is useful for context in case an empty list of nodes is returned. **DNS** has information used when serving the results over DNS. This is just a copy of the structure given when the prepared query was created. **Datacenter** has the datacenter that ultimately provided the list of nodes and **Failovers** has the number of remote datacenters that were queried while executing the query. This provides some insight into where the data came from. This will be zero during non-failover operations where there were healthy nodes found in the local datacenter. """ query_id = extract_attr(query, keys=["ID"]) response = await self._api.get( "/v1/query/%s/execute" % query_id, params={"dc": dc, "near": near, "limit": limit}, consistency=consistency) return response.body
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:zip_process; 3, parameters; 3, 4; 4, dictionary_splat_pattern; 4, 5; 5, identifier:kwargs; 6, block; 6, 7; 6, 9; 6, 13; 6, 17; 6, 21; 6, 25; 6, 71; 6, 96; 6, 255; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:str_localPath; 12, string:""; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:str_zipFileName; 16, string:""; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:str_action; 20, string:"zip"; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:str_arcroot; 24, string:""; 25, for_statement; 25, 26; 25, 29; 25, 34; 26, pattern_list; 26, 27; 26, 28; 27, identifier:k; 28, identifier:v; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:kwargs; 32, identifier:items; 33, argument_list; 34, block; 34, 35; 34, 44; 34, 53; 34, 62; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:k; 38, string:'path'; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:str_localPath; 43, identifier:v; 44, if_statement; 44, 45; 44, 48; 45, comparison_operator:==; 45, 46; 45, 47; 46, identifier:k; 47, string:'action'; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:str_action; 52, identifier:v; 53, if_statement; 53, 54; 53, 57; 54, comparison_operator:==; 54, 55; 54, 56; 55, identifier:k; 56, string:'payloadFile'; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:str_zipFileName; 61, identifier:v; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:==; 63, 64; 63, 65; 64, identifier:k; 65, string:'arcroot'; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:str_arcroot; 70, identifier:v; 71, if_statement; 71, 72; 71, 75; 71, 90; 72, comparison_operator:==; 72, 73; 72, 74; 73, identifier:str_action; 74, string:'zip'; 75, block; 75, 76; 75, 80; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:str_mode; 79, string:'w'; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:str_zipFileName; 83, binary_operator:%; 83, 84; 83, 85; 84, string:'%s.zip'; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:uuid; 88, identifier:uuid4; 89, argument_list; 90, else_clause; 90, 91; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:str_mode; 95, string:'r'; 96, try_statement; 96, 97; 96, 243; 97, block; 97, 98; 97, 111; 97, 215; 97, 227; 97, 233; 97, 239; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:ziphandler; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:zipfile; 104, identifier:ZipFile; 105, argument_list; 105, 106; 105, 107; 105, 108; 106, identifier:str_zipFileName; 107, identifier:str_mode; 108, attribute; 108, 109; 108, 110; 109, identifier:zipfile; 110, identifier:ZIP_DEFLATED; 111, if_statement; 111, 112; 111, 115; 112, comparison_operator:==; 112, 113; 112, 114; 113, identifier:str_mode; 114, string:'w'; 115, block; 115, 116; 116, if_statement; 116, 117; 116, 125; 116, 135; 117, call; 117, 118; 117, 123; 118, attribute; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:os; 121, identifier:path; 122, identifier:isdir; 123, argument_list; 123, 124; 124, identifier:str_localPath; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:zipdir; 129, argument_list; 129, 130; 129, 131; 129, 132; 130, identifier:str_localPath; 131, identifier:ziphandler; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:arcroot; 134, identifier:str_arcroot; 135, else_clause; 135, 136; 136, block; 136, 137; 136, 170; 137, if_statement; 137, 138; 137, 142; 137, 164; 138, call; 138, 139; 138, 140; 139, identifier:len; 140, argument_list; 140, 141; 141, identifier:str_arcroot; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:str_arcname; 146, binary_operator:+; 146, 147; 146, 156; 147, subscript; 147, 148; 147, 154; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:str_arcroot; 151, identifier:split; 152, argument_list; 152, 153; 153, string:'/'; 154, unary_operator:-; 154, 155; 155, integer:1; 156, subscript; 156, 157; 156, 163; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:str_localPath; 160, identifier:split; 161, argument_list; 161, 162; 162, identifier:str_arcroot; 163, integer:1; 164, else_clause; 164, 165; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:str_arcname; 169, identifier:str_localPath; 170, try_statement; 170, 171; 170, 182; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:ziphandler; 176, identifier:write; 177, argument_list; 177, 178; 177, 179; 178, identifier:str_localPath; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:arcname; 181, identifier:str_arcname; 182, except_clause; 182, 183; 183, block; 183, 184; 183, 190; 183, 197; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:ziphandler; 188, identifier:close; 189, argument_list; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:os; 194, identifier:remove; 195, argument_list; 195, 196; 196, identifier:str_zipFileName; 197, return_statement; 197, 198; 198, dictionary; 198, 199; 198, 212; 199, pair; 199, 200; 199, 201; 200, string:'msg'; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:json; 204, identifier:dumps; 205, argument_list; 205, 206; 206, dictionary; 206, 207; 207, pair; 207, 208; 207, 209; 208, string:"msg"; 209, binary_operator:%; 209, 210; 209, 211; 210, string:"No file or directory found for '%s'"; 211, identifier:str_localPath; 212, pair; 212, 213; 212, 214; 213, string:'status'; 214, False; 215, if_statement; 215, 216; 215, 219; 216, comparison_operator:==; 216, 217; 216, 218; 217, identifier:str_mode; 218, string:'r'; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:ziphandler; 224, identifier:extractall; 225, argument_list; 225, 226; 226, identifier:str_localPath; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:ziphandler; 231, identifier:close; 232, argument_list; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:str_msg; 236, binary_operator:%; 236, 237; 236, 238; 237, string:'%s operation successful'; 238, identifier:str_action; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:b_status; 242, True; 243, except_clause; 243, 244; 244, block; 244, 245; 244, 251; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:str_msg; 248, binary_operator:%; 248, 249; 248, 250; 249, string:'%s operation failed'; 250, identifier:str_action; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:b_status; 254, False; 255, return_statement; 255, 256; 256, dictionary; 256, 257; 256, 260; 256, 263; 256, 266; 256, 269; 256, 272; 256, 287; 257, pair; 257, 258; 257, 259; 258, string:'msg'; 259, identifier:str_msg; 260, pair; 260, 261; 260, 262; 261, string:'fileProcessed'; 262, identifier:str_zipFileName; 263, pair; 263, 264; 263, 265; 264, string:'status'; 265, identifier:b_status; 266, pair; 266, 267; 266, 268; 267, string:'path'; 268, identifier:str_localPath; 269, pair; 269, 270; 269, 271; 270, string:'zipmode'; 271, identifier:str_mode; 272, pair; 272, 273; 272, 274; 273, string:'filesize'; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, string:"{:,}"; 277, identifier:format; 278, argument_list; 278, 279; 279, attribute; 279, 280; 279, 286; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:os; 283, identifier:stat; 284, argument_list; 284, 285; 285, identifier:str_zipFileName; 286, identifier:st_size; 287, pair; 287, 288; 287, 289; 288, string:'timestamp'; 289, binary_operator:%; 289, 290; 289, 291; 290, string:'%s'; 291, call; 291, 292; 291, 297; 292, attribute; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:datetime; 295, identifier:datetime; 296, identifier:now; 297, argument_list
def zip_process(**kwargs): """ Process zip operations. :param kwargs: :return: """ str_localPath = "" str_zipFileName = "" str_action = "zip" str_arcroot = "" for k,v in kwargs.items(): if k == 'path': str_localPath = v if k == 'action': str_action = v if k == 'payloadFile': str_zipFileName = v if k == 'arcroot': str_arcroot = v if str_action == 'zip': str_mode = 'w' str_zipFileName = '%s.zip' % uuid.uuid4() else: str_mode = 'r' try: ziphandler = zipfile.ZipFile(str_zipFileName, str_mode, zipfile.ZIP_DEFLATED) if str_mode == 'w': if os.path.isdir(str_localPath): zipdir(str_localPath, ziphandler, arcroot = str_arcroot) else: if len(str_arcroot): str_arcname = str_arcroot.split('/')[-1] + str_localPath.split(str_arcroot)[1] else: str_arcname = str_localPath try: ziphandler.write(str_localPath, arcname = str_arcname) except: ziphandler.close() os.remove(str_zipFileName) return { 'msg': json.dumps({"msg": "No file or directory found for '%s'" % str_localPath}), 'status': False } if str_mode == 'r': ziphandler.extractall(str_localPath) ziphandler.close() str_msg = '%s operation successful' % str_action b_status = True except: str_msg = '%s operation failed' % str_action b_status = False return { 'msg': str_msg, 'fileProcessed': str_zipFileName, 'status': b_status, 'path': str_localPath, 'zipmode': str_mode, 'filesize': "{:,}".format(os.stat(str_zipFileName).st_size), 'timestamp': '%s' % datetime.datetime.now() }
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:base64_process; 3, parameters; 3, 4; 4, dictionary_splat_pattern; 4, 5; 5, identifier:kwargs; 6, block; 6, 7; 6, 9; 6, 13; 6, 17; 6, 21; 6, 25; 6, 72; 6, 156; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:str_fileToSave; 12, string:""; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:str_fileToRead; 16, string:""; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:str_action; 20, string:"encode"; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:data; 24, None; 25, for_statement; 25, 26; 25, 29; 25, 34; 26, pattern_list; 26, 27; 26, 28; 27, identifier:k; 28, identifier:v; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:kwargs; 32, identifier:items; 33, argument_list; 34, block; 34, 35; 34, 44; 34, 53; 34, 62; 34, 71; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:k; 38, string:'action'; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:str_action; 43, identifier:v; 44, if_statement; 44, 45; 44, 48; 45, comparison_operator:==; 45, 46; 45, 47; 46, identifier:k; 47, string:'payloadBytes'; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:data; 52, identifier:v; 53, if_statement; 53, 54; 53, 57; 54, comparison_operator:==; 54, 55; 54, 56; 55, identifier:k; 56, string:'payloadFile'; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:str_fileToRead; 61, identifier:v; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:==; 63, 64; 63, 65; 64, identifier:k; 65, string:'saveToFile'; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:str_fileToSave; 70, identifier:v; 71, comment; 72, if_statement; 72, 73; 72, 76; 72, 77; 73, comparison_operator:==; 73, 74; 73, 75; 74, identifier:str_action; 75, string:"encode"; 76, comment; 77, block; 77, 78; 77, 110; 77, 119; 77, 144; 78, if_statement; 78, 79; 78, 83; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, identifier:str_fileToRead; 83, block; 83, 84; 84, with_statement; 84, 85; 84, 95; 85, with_clause; 85, 86; 86, with_item; 86, 87; 87, as_pattern; 87, 88; 87, 93; 88, call; 88, 89; 88, 90; 89, identifier:open; 90, argument_list; 90, 91; 90, 92; 91, identifier:str_fileToRead; 92, string:'rb'; 93, as_pattern_target; 93, 94; 94, identifier:f; 95, block; 95, 96; 95, 104; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:data; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:f; 102, identifier:read; 103, argument_list; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:f; 108, identifier:close; 109, argument_list; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:data_b64; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:base64; 116, identifier:b64encode; 117, argument_list; 117, 118; 118, identifier:data; 119, with_statement; 119, 120; 119, 130; 120, with_clause; 120, 121; 121, with_item; 121, 122; 122, as_pattern; 122, 123; 122, 128; 123, call; 123, 124; 123, 125; 124, identifier:open; 125, argument_list; 125, 126; 125, 127; 126, identifier:str_fileToSave; 127, string:'wb'; 128, as_pattern_target; 128, 129; 129, identifier:f; 130, block; 130, 131; 130, 138; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:f; 135, identifier:write; 136, argument_list; 136, 137; 137, identifier:data_b64; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:f; 142, identifier:close; 143, argument_list; 144, return_statement; 144, 145; 145, dictionary; 145, 146; 145, 149; 145, 152; 145, 155; 146, pair; 146, 147; 146, 148; 147, string:'msg'; 148, string:'Encode successful'; 149, pair; 149, 150; 149, 151; 150, string:'fileProcessed'; 151, identifier:str_fileToSave; 152, pair; 152, 153; 152, 154; 153, string:'status'; 154, True; 155, comment; 156, if_statement; 156, 157; 156, 160; 156, 161; 156, 162; 156, 163; 156, 164; 156, 165; 157, comparison_operator:==; 157, 158; 157, 159; 158, identifier:str_action; 159, string:"decode"; 160, comment; 161, comment; 162, comment; 163, comment; 164, comment; 165, block; 165, 166; 165, 177; 165, 202; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:bytes_decoded; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:base64; 172, identifier:b64decode; 173, argument_list; 173, 174; 174, binary_operator:+; 174, 175; 174, 176; 175, identifier:data; 176, string:"==="; 177, with_statement; 177, 178; 177, 188; 178, with_clause; 178, 179; 179, with_item; 179, 180; 180, as_pattern; 180, 181; 180, 186; 181, call; 181, 182; 181, 183; 182, identifier:open; 183, argument_list; 183, 184; 183, 185; 184, identifier:str_fileToSave; 185, string:'wb'; 186, as_pattern_target; 186, 187; 187, identifier:f; 188, block; 188, 189; 188, 196; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:f; 193, identifier:write; 194, argument_list; 194, 195; 195, identifier:bytes_decoded; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:f; 200, identifier:close; 201, argument_list; 202, return_statement; 202, 203; 203, dictionary; 203, 204; 203, 207; 203, 210; 203, 213; 204, pair; 204, 205; 204, 206; 205, string:'msg'; 206, string:'Decode successful'; 207, pair; 207, 208; 207, 209; 208, string:'fileProcessed'; 209, identifier:str_fileToSave; 210, pair; 210, 211; 210, 212; 211, string:'status'; 212, True; 213, comment
def base64_process(**kwargs): """ Process base64 file io """ str_fileToSave = "" str_fileToRead = "" str_action = "encode" data = None for k,v in kwargs.items(): if k == 'action': str_action = v if k == 'payloadBytes': data = v if k == 'payloadFile': str_fileToRead = v if k == 'saveToFile': str_fileToSave = v # if k == 'sourcePath': str_sourcePath = v if str_action == "encode": # Encode the contents of the file at targetPath as ASCII for transmission if len(str_fileToRead): with open(str_fileToRead, 'rb') as f: data = f.read() f.close() data_b64 = base64.b64encode(data) with open(str_fileToSave, 'wb') as f: f.write(data_b64) f.close() return { 'msg': 'Encode successful', 'fileProcessed': str_fileToSave, 'status': True # 'encodedBytes': data_b64 } if str_action == "decode": # if len(data) % 4: # not a multiple of 4, add padding: # data += '=' * (4 - len(data) % 4) # adding 3 padding = will never succumb to the TypeError and will always produce the same result. # https://gist.github.com/perrygeo/ee7c65bb1541ff6ac770 bytes_decoded = base64.b64decode(data + "===") with open(str_fileToSave, 'wb') as f: f.write(bytes_decoded) f.close() return { 'msg': 'Decode successful', 'fileProcessed': str_fileToSave, 'status': True # 'decodedBytes': bytes_decoded }
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:path_localLocationCheck; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:d_msg; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 15; 8, 21; 8, 37; 8, 48; 8, 59; 8, 65; 8, 78; 8, 82; 8, 86; 8, 97; 8, 108; 8, 119; 8, 280; 8, 304; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:b_pull; 14, False; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:d_meta; 18, subscript; 18, 19; 18, 20; 19, identifier:d_msg; 20, string:'meta'; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:in; 22, 23; 22, 24; 23, string:'do'; 24, identifier:d_meta; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 32; 27, comparison_operator:==; 27, 28; 27, 31; 28, subscript; 28, 29; 28, 30; 29, identifier:d_meta; 30, string:'do'; 31, string:'pull'; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:b_pull; 36, True; 37, if_statement; 37, 38; 37, 41; 38, comparison_operator:in; 38, 39; 38, 40; 39, string:'local'; 40, identifier:d_meta; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:d_local; 45, subscript; 45, 46; 45, 47; 46, identifier:d_meta; 47, string:'local'; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:in; 49, 50; 49, 51; 50, string:'to'; 51, identifier:d_meta; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:d_local; 56, subscript; 56, 57; 56, 58; 57, identifier:d_meta; 58, string:'to'; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:str_localPathFull; 62, subscript; 62, 63; 62, 64; 63, identifier:d_local; 64, string:'path'; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, pattern_list; 67, 68; 67, 69; 68, identifier:str_localPath; 69, identifier:str_unpack; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:os; 74, identifier:path; 75, identifier:split; 76, argument_list; 76, 77; 77, identifier:str_localPathFull; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:str_msg; 81, string:''; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:str_checkedDir; 85, identifier:str_localPathFull; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:b_isFile; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:os; 93, identifier:path; 94, identifier:isfile; 95, argument_list; 95, 96; 96, identifier:str_localPathFull; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:b_isDir; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:os; 104, identifier:path; 105, identifier:isdir; 106, argument_list; 106, 107; 107, identifier:str_localPathFull; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:b_exists; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:os; 115, identifier:path; 116, identifier:exists; 117, argument_list; 117, 118; 118, identifier:str_localPathFull; 119, if_statement; 119, 120; 119, 127; 119, 128; 119, 129; 119, 130; 119, 131; 119, 132; 119, 133; 120, boolean_operator:or; 120, 121; 120, 126; 121, comparison_operator:in; 121, 122; 121, 123; 122, string:'pull'; 123, subscript; 123, 124; 123, 125; 124, identifier:d_msg; 125, string:'action'; 126, identifier:b_pull; 127, comment; 128, comment; 129, comment; 130, comment; 131, comment; 132, comment; 133, block; 133, 134; 133, 138; 133, 149; 133, 160; 133, 171; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:str_checkedDir; 137, identifier:str_localPath; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:b_isFile; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:os; 145, identifier:path; 146, identifier:isfile; 147, argument_list; 147, 148; 148, identifier:str_localPath; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:b_isDir; 152, call; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:os; 156, identifier:path; 157, identifier:isdir; 158, argument_list; 158, 159; 159, identifier:str_localPath; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:b_exists; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:os; 167, identifier:path; 168, identifier:exists; 169, argument_list; 169, 170; 170, identifier:str_localPath; 171, if_statement; 171, 172; 171, 179; 171, 243; 172, comparison_operator:in; 172, 173; 172, 174; 173, string:'createDir'; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:d_local; 177, identifier:keys; 178, argument_list; 179, block; 179, 180; 180, if_statement; 180, 181; 180, 184; 181, subscript; 181, 182; 181, 183; 182, identifier:d_local; 183, string:'createDir'; 184, block; 184, 185; 184, 217; 184, 228; 184, 235; 184, 239; 185, if_statement; 185, 186; 185, 194; 186, call; 186, 187; 186, 192; 187, attribute; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:os; 190, identifier:path; 191, identifier:isdir; 192, argument_list; 192, 193; 193, identifier:str_localPathFull; 194, block; 194, 195; 194, 206; 194, 213; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:dp; 201, identifier:qprint; 202, argument_list; 202, 203; 203, binary_operator:%; 203, 204; 203, 205; 204, string:'Removing local path %s...'; 205, identifier:str_localPathFull; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:shutil; 210, identifier:rmtree; 211, argument_list; 211, 212; 212, identifier:str_localPathFull; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:str_msg; 216, string:'Removed existing local path... '; 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:dp; 223, identifier:qprint; 224, argument_list; 224, 225; 225, binary_operator:%; 225, 226; 225, 227; 226, string:'Creating empty local path %s...'; 227, identifier:str_localPathFull; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:os; 232, identifier:makedirs; 233, argument_list; 233, 234; 234, identifier:str_localPathFull; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:b_exists; 238, True; 239, expression_statement; 239, 240; 240, augmented_assignment:+=; 240, 241; 240, 242; 241, identifier:str_msg; 242, string:'Created new local path'; 243, else_clause; 243, 244; 244, block; 244, 245; 244, 249; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:str_msg; 248, string:'local path already exists!'; 249, if_statement; 249, 250; 249, 257; 249, 271; 250, comparison_operator:in; 250, 251; 250, 252; 251, string:'writeInExisting'; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:d_local; 255, identifier:keys; 256, argument_list; 257, block; 257, 258; 258, if_statement; 258, 259; 258, 263; 259, not_operator; 259, 260; 260, subscript; 260, 261; 260, 262; 261, identifier:d_local; 262, string:'writeInExisting'; 263, block; 263, 264; 264, if_statement; 264, 265; 264, 266; 265, identifier:b_isDir; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:b_exists; 270, False; 271, else_clause; 271, 272; 272, block; 272, 273; 273, if_statement; 273, 274; 273, 275; 274, identifier:b_isDir; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:b_exists; 279, False; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:d_ret; 283, dictionary; 283, 284; 283, 289; 283, 292; 283, 295; 283, 298; 283, 301; 284, pair; 284, 285; 284, 286; 285, string:'action'; 286, subscript; 286, 287; 286, 288; 287, identifier:d_msg; 288, string:'action'; 289, pair; 289, 290; 289, 291; 290, string:'dir'; 291, identifier:str_checkedDir; 292, pair; 292, 293; 292, 294; 293, string:'status'; 294, identifier:b_exists; 295, pair; 295, 296; 295, 297; 296, string:'isfile'; 297, identifier:b_isFile; 298, pair; 298, 299; 298, 300; 299, string:'isdir'; 300, identifier:b_isDir; 301, pair; 301, 302; 301, 303; 302, string:'msg'; 303, identifier:str_msg; 304, return_statement; 304, 305; 305, dictionary; 305, 306; 305, 309; 305, 314; 306, pair; 306, 307; 306, 308; 307, string:'check'; 308, identifier:d_ret; 309, pair; 309, 310; 309, 311; 310, string:'status'; 311, subscript; 311, 312; 311, 313; 312, identifier:d_ret; 313, string:'status'; 314, pair; 314, 315; 314, 316; 315, string:'timestamp'; 316, binary_operator:%; 316, 317; 316, 318; 317, string:'%s'; 318, call; 318, 319; 318, 324; 319, attribute; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:datetime; 322, identifier:datetime; 323, identifier:now; 324, argument_list
def path_localLocationCheck(self, d_msg, **kwargs): """ Check if a path exists on the local filesystem :param self: :param kwargs: :return: """ b_pull = False d_meta = d_msg['meta'] if 'do' in d_meta: if d_meta['do'] == 'pull': b_pull = True if 'local' in d_meta: d_local = d_meta['local'] if 'to' in d_meta: d_local = d_meta['to'] str_localPathFull = d_local['path'] str_localPath, str_unpack = os.path.split(str_localPathFull) str_msg = '' str_checkedDir = str_localPathFull b_isFile = os.path.isfile(str_localPathFull) b_isDir = os.path.isdir(str_localPathFull) b_exists = os.path.exists(str_localPathFull) if 'pull' in d_msg['action'] or b_pull: # If we are "pulling" data to local, then we assume the local # directory does not exist. If it does, and if 'createDir' is 'true', # we remove the localPath and re-create it, thus assuring it will # only contain the info pulled from the remote source. # If 'writeInExisting' is 'true', then execution continues, but # may fail if the pulled target exists in the localPath. str_checkedDir = str_localPath b_isFile = os.path.isfile(str_localPath) b_isDir = os.path.isdir(str_localPath) b_exists = os.path.exists(str_localPath) if 'createDir' in d_local.keys(): if d_local['createDir']: if os.path.isdir(str_localPathFull): self.dp.qprint('Removing local path %s...' % str_localPathFull) shutil.rmtree(str_localPathFull) str_msg = 'Removed existing local path... ' self.dp.qprint('Creating empty local path %s...' % str_localPathFull) os.makedirs(str_localPathFull) b_exists = True str_msg += 'Created new local path' else: str_msg = 'local path already exists!' if 'writeInExisting' in d_local.keys(): if not d_local['writeInExisting']: if b_isDir: b_exists = False else: if b_isDir: b_exists = False d_ret = { 'action': d_msg['action'], 'dir': str_checkedDir, 'status': b_exists, 'isfile': b_isFile, 'isdir': b_isDir, 'msg': str_msg } return {'check': d_ret, 'status': d_ret['status'], 'timestamp': '%s' % datetime.datetime.now()}
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:rebuild; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 27; 5, 89; 5, 117; 5, 124; 5, 132; 5, 140; 5, 158; 5, 164; 5, 346; 5, 353; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:table; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:tableType; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:form; 19, call; 19, 20; 19, 21; 20, identifier:nativestring; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:filterFormat; 26, argument_list; 27, if_statement; 27, 28; 27, 32; 27, 84; 28, boolean_operator:and; 28, 29; 28, 31; 29, not_operator; 29, 30; 30, identifier:table; 31, identifier:form; 32, block; 32, 33; 32, 83; 33, if_statement; 33, 34; 33, 45; 33, 61; 34, comparison_operator:==; 34, 35; 34, 44; 35, call; 35, 36; 35, 43; 36, attribute; 36, 37; 36, 42; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:layout; 41, argument_list; 42, identifier:count; 43, argument_list; 44, integer:0; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 55; 48, attribute; 48, 49; 48, 54; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:layout; 53, argument_list; 54, identifier:addWidget; 55, argument_list; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:QLabel; 58, argument_list; 58, 59; 58, 60; 59, identifier:form; 60, identifier:self; 61, else_clause; 61, 62; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 81; 65, attribute; 65, 66; 65, 80; 66, call; 66, 67; 66, 79; 67, attribute; 67, 68; 67, 78; 68, call; 68, 69; 68, 76; 69, attribute; 69, 70; 69, 75; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:layout; 74, argument_list; 75, identifier:itemAt; 76, argument_list; 76, 77; 77, integer:0; 78, identifier:widget; 79, argument_list; 80, identifier:setText; 81, argument_list; 81, 82; 82, identifier:form; 83, return_statement; 84, elif_clause; 84, 85; 84, 87; 85, not_operator; 85, 86; 86, identifier:form; 87, block; 87, 88; 88, return_statement; 89, for_statement; 89, 90; 89, 91; 89, 97; 90, identifier:child; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:findChildren; 95, argument_list; 95, 96; 96, identifier:QWidget; 97, block; 97, 98; 97, 104; 97, 111; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:child; 102, identifier:close; 103, argument_list; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:child; 108, identifier:setParent; 109, argument_list; 109, 110; 110, None; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:child; 115, identifier:deleteLater; 116, argument_list; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:setUpdatesEnabled; 122, argument_list; 122, 123; 123, False; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:schema; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:table; 130, identifier:schema; 131, argument_list; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:vlayout; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:layout; 139, argument_list; 140, for_statement; 140, 141; 140, 142; 140, 150; 141, identifier:i; 142, call; 142, 143; 142, 144; 143, identifier:range; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:vlayout; 148, identifier:count; 149, argument_list; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:vlayout; 155, identifier:takeAt; 156, argument_list; 156, 157; 157, integer:0; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:_plugins; 163, list:[]; 164, for_statement; 164, 165; 164, 166; 164, 172; 165, identifier:line; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:form; 169, identifier:split; 170, argument_list; 170, 171; 171, string:'\n'; 172, block; 172, 173; 172, 179; 172, 189; 172, 196; 172, 332; 172, 339; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:row; 176, call; 176, 177; 176, 178; 177, identifier:QHBoxLayout; 178, argument_list; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:row; 183, identifier:setContentsMargins; 184, argument_list; 184, 185; 184, 186; 184, 187; 184, 188; 185, integer:0; 186, integer:0; 187, integer:0; 188, integer:0; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:row; 193, identifier:setSpacing; 194, argument_list; 194, 195; 195, integer:0; 196, for_statement; 196, 197; 196, 200; 196, 206; 196, 207; 197, pattern_list; 197, 198; 197, 199; 198, identifier:label; 199, identifier:lookup; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:FORMAT_SPLITTER; 203, identifier:findall; 204, argument_list; 204, 205; 205, identifier:line; 206, comment; 207, block; 207, 208; 207, 216; 207, 223; 207, 224; 207, 233; 207, 248; 207, 259; 207, 264; 207, 277; 207, 282; 207, 296; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:lbl; 211, call; 211, 212; 211, 213; 212, identifier:QLabel; 213, argument_list; 213, 214; 213, 215; 214, identifier:label; 215, identifier:self; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:row; 220, identifier:addWidget; 221, argument_list; 221, 222; 222, identifier:lbl; 223, comment; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:opts; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:lookup; 230, identifier:split; 231, argument_list; 231, 232; 232, string:':'; 233, if_statement; 233, 234; 233, 240; 234, comparison_operator:==; 234, 235; 234, 239; 235, call; 235, 236; 235, 237; 236, identifier:len; 237, argument_list; 237, 238; 238, identifier:opts; 239, integer:1; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:opts; 245, identifier:append; 246, argument_list; 246, 247; 247, string:'is'; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:column; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:schema; 254, identifier:column; 255, argument_list; 255, 256; 256, subscript; 256, 257; 256, 258; 257, identifier:opts; 258, integer:0; 259, if_statement; 259, 260; 259, 262; 260, not_operator; 260, 261; 261, identifier:column; 262, block; 262, 263; 263, continue_statement; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:plugin; 267, call; 267, 268; 267, 275; 268, attribute; 268, 269; 268, 274; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:self; 272, identifier:pluginFactory; 273, argument_list; 274, identifier:plugin; 275, argument_list; 275, 276; 276, identifier:column; 277, if_statement; 277, 278; 277, 280; 278, not_operator; 278, 279; 279, identifier:plugin; 280, block; 280, 281; 281, continue_statement; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:editor; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:plugin; 288, identifier:createEditor; 289, argument_list; 289, 290; 289, 291; 289, 292; 289, 295; 290, identifier:self; 291, identifier:column; 292, subscript; 292, 293; 292, 294; 293, identifier:opts; 294, integer:1; 295, None; 296, if_statement; 296, 297; 296, 298; 297, identifier:editor; 298, block; 298, 299; 298, 308; 298, 315; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:editor; 303, identifier:setObjectName; 304, argument_list; 304, 305; 305, subscript; 305, 306; 305, 307; 306, identifier:opts; 307, integer:0; 308, expression_statement; 308, 309; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:row; 312, identifier:addWidget; 313, argument_list; 313, 314; 314, identifier:editor; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 322; 317, attribute; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:self; 320, identifier:_plugins; 321, identifier:append; 322, argument_list; 322, 323; 323, tuple; 323, 324; 323, 327; 323, 330; 323, 331; 324, subscript; 324, 325; 324, 326; 325, identifier:opts; 326, integer:0; 327, subscript; 327, 328; 327, 329; 328, identifier:opts; 329, integer:1; 330, identifier:plugin; 331, identifier:editor; 332, expression_statement; 332, 333; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:row; 336, identifier:addStretch; 337, argument_list; 337, 338; 338, integer:1; 339, expression_statement; 339, 340; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:vlayout; 343, identifier:addLayout; 344, argument_list; 344, 345; 345, identifier:row; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:self; 350, identifier:setUpdatesEnabled; 351, argument_list; 351, 352; 352, True; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:self; 357, identifier:adjustSize; 358, argument_list
def rebuild(self): """ Rebuilds the data associated with this filter widget. """ table = self.tableType() form = nativestring(self.filterFormat()) if not table and form: if self.layout().count() == 0: self.layout().addWidget(QLabel(form, self)) else: self.layout().itemAt(0).widget().setText(form) return elif not form: return for child in self.findChildren(QWidget): child.close() child.setParent(None) child.deleteLater() self.setUpdatesEnabled(False) schema = table.schema() vlayout = self.layout() for i in range(vlayout.count()): vlayout.takeAt(0) self._plugins = [] for line in form.split('\n'): row = QHBoxLayout() row.setContentsMargins(0, 0, 0, 0) row.setSpacing(0) for label, lookup in FORMAT_SPLITTER.findall(line): # create the label lbl = QLabel(label, self) row.addWidget(lbl) # create the query plugin opts = lookup.split(':') if len(opts) == 1: opts.append('is') column = schema.column(opts[0]) if not column: continue plugin = self.pluginFactory().plugin(column) if not plugin: continue editor = plugin.createEditor(self, column, opts[1], None) if editor: editor.setObjectName(opts[0]) row.addWidget(editor) self._plugins.append((opts[0], opts[1], plugin, editor)) row.addStretch(1) vlayout.addLayout(row) self.setUpdatesEnabled(True) self.adjustSize()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:filters; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:filter_directory; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:update; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:fmt; 12, string:'table'; 13, dictionary_splat_pattern; 13, 14; 14, identifier:kwargs; 15, block; 15, 16; 15, 18; 15, 31; 15, 32; 15, 44; 15, 48; 15, 71; 15, 279; 15, 280; 15, 284; 15, 315; 15, 316; 16, expression_statement; 16, 17; 17, comment; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:filter_directory; 21, None; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:filter_directory; 26, call; 26, 27; 26, 28; 27, identifier:resource_filename; 28, argument_list; 28, 29; 28, 30; 29, string:'svo_filters'; 30, string:'data/filters/'; 31, comment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:p_path; 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:join; 41, argument_list; 41, 42; 41, 43; 42, identifier:filter_directory; 43, string:'filter_list.p'; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:updated; 47, False; 48, if_statement; 48, 49; 48, 58; 49, not_operator; 49, 50; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:os; 54, identifier:path; 55, identifier:isfile; 56, argument_list; 56, 57; 57, identifier:p_path; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:os; 63, identifier:system; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, string:'touch {}'; 68, identifier:format; 69, argument_list; 69, 70; 70, identifier:p_path; 71, if_statement; 71, 72; 71, 73; 72, identifier:update; 73, block; 73, 74; 73, 79; 73, 80; 73, 89; 73, 105; 73, 120; 73, 124; 73, 253; 73, 254; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:print; 77, argument_list; 77, 78; 78, string:'Loading filters into table...'; 79, comment; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:files; 83, call; 83, 84; 83, 85; 84, identifier:glob; 85, argument_list; 85, 86; 86, binary_operator:+; 86, 87; 86, 88; 87, identifier:filter_directory; 88, string:'*'; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:files; 92, list_comprehension; 92, 93; 92, 94; 92, 97; 93, identifier:f; 94, for_in_clause; 94, 95; 94, 96; 95, identifier:f; 96, identifier:files; 97, if_clause; 97, 98; 98, not_operator; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:f; 102, identifier:endswith; 103, argument_list; 103, 104; 104, string:'.p'; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:bands; 108, list_comprehension; 108, 109; 108, 117; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:os; 113, identifier:path; 114, identifier:basename; 115, argument_list; 115, 116; 116, identifier:b; 117, for_in_clause; 117, 118; 117, 119; 118, identifier:b; 119, identifier:files; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:tables; 123, list:[]; 124, for_statement; 124, 125; 124, 126; 124, 127; 124, 128; 125, identifier:band; 126, identifier:bands; 127, comment; 128, block; 128, 129; 128, 139; 128, 148; 128, 154; 128, 155; 128, 164; 128, 202; 128, 218; 128, 241; 128, 248; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:band; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:band; 135, identifier:replace; 136, argument_list; 136, 137; 136, 138; 137, string:'.txt'; 138, string:''; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:filt; 142, call; 142, 143; 142, 144; 143, identifier:Filter; 144, argument_list; 144, 145; 144, 146; 145, identifier:band; 146, dictionary_splat; 146, 147; 147, identifier:kwargs; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:filt; 152, identifier:Band; 153, identifier:band; 154, comment; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:info; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:filt; 161, identifier:info; 162, argument_list; 162, 163; 163, True; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:vals; 167, list_comprehension; 167, 168; 167, 197; 168, conditional_expression:if; 168, 169; 168, 173; 168, 196; 169, call; 169, 170; 169, 171; 170, identifier:float; 171, argument_list; 171, 172; 172, identifier:i; 173, call; 173, 174; 173, 195; 174, attribute; 174, 175; 174, 194; 175, call; 175, 176; 175, 191; 176, attribute; 176, 177; 176, 190; 177, call; 177, 178; 177, 187; 178, attribute; 178, 179; 178, 186; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:i; 182, identifier:replace; 183, argument_list; 183, 184; 183, 185; 184, string:'.'; 185, string:''; 186, identifier:replace; 187, argument_list; 187, 188; 187, 189; 188, string:'-'; 189, string:''; 190, identifier:replace; 191, argument_list; 191, 192; 191, 193; 192, string:'+'; 193, string:''; 194, identifier:isnumeric; 195, argument_list; 196, identifier:i; 197, for_in_clause; 197, 198; 197, 199; 198, identifier:i; 199, subscript; 199, 200; 199, 201; 200, identifier:info; 201, string:'Values'; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:dtypes; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:np; 208, identifier:array; 209, argument_list; 209, 210; 210, list_comprehension; 210, 211; 210, 215; 211, call; 211, 212; 211, 213; 212, identifier:type; 213, argument_list; 213, 214; 214, identifier:i; 215, for_in_clause; 215, 216; 215, 217; 216, identifier:i; 217, identifier:vals; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:table; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:at; 224, identifier:Table; 225, argument_list; 225, 226; 225, 233; 225, 238; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:np; 229, identifier:array; 230, argument_list; 230, 231; 231, list:[vals]; 231, 232; 232, identifier:vals; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:names; 235, subscript; 235, 236; 235, 237; 236, identifier:info; 237, string:'Attributes'; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:dtype; 240, identifier:dtypes; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:tables; 245, identifier:append; 246, argument_list; 246, 247; 247, identifier:table; 248, delete_statement; 248, 249; 249, expression_list; 249, 250; 249, 251; 249, 252; 250, identifier:filt; 251, identifier:info; 252, identifier:table; 253, comment; 254, with_statement; 254, 255; 254, 265; 255, with_clause; 255, 256; 256, with_item; 256, 257; 257, as_pattern; 257, 258; 257, 263; 258, call; 258, 259; 258, 260; 259, identifier:open; 260, argument_list; 260, 261; 260, 262; 261, identifier:p_path; 262, string:'wb'; 263, as_pattern_target; 263, 264; 264, identifier:file; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:pickle; 270, identifier:dump; 271, argument_list; 271, 272; 271, 278; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:at; 275, identifier:vstack; 276, argument_list; 276, 277; 277, identifier:tables; 278, identifier:file; 279, comment; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:data; 283, dictionary; 284, if_statement; 284, 285; 284, 293; 285, call; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:os; 289, identifier:path; 290, identifier:isfile; 291, argument_list; 291, 292; 292, identifier:p_path; 293, block; 293, 294; 294, with_statement; 294, 295; 294, 305; 295, with_clause; 295, 296; 296, with_item; 296, 297; 297, as_pattern; 297, 298; 297, 303; 298, call; 298, 299; 298, 300; 299, identifier:open; 300, argument_list; 300, 301; 300, 302; 301, identifier:p_path; 302, string:'rb'; 303, as_pattern_target; 303, 304; 304, identifier:file; 305, block; 305, 306; 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:pickle; 312, identifier:load; 313, argument_list; 313, 314; 314, identifier:file; 315, comment; 316, if_statement; 316, 317; 316, 318; 316, 377; 316, 378; 317, identifier:data; 318, block; 318, 319; 318, 375; 319, if_statement; 319, 320; 319, 323; 319, 365; 320, comparison_operator:==; 320, 321; 320, 322; 321, identifier:fmt; 322, string:'dict'; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:data; 327, dictionary_comprehension; 327, 328; 327, 362; 328, pair; 328, 329; 328, 332; 329, subscript; 329, 330; 329, 331; 330, identifier:r; 331, integer:0; 332, dictionary_comprehension; 332, 333; 332, 351; 333, pair; 333, 334; 333, 335; 334, identifier:k; 335, conditional_expression:if; 335, 336; 335, 341; 335, 348; 336, attribute; 336, 337; 336, 340; 337, subscript; 337, 338; 337, 339; 338, identifier:r; 339, identifier:k; 340, identifier:value; 341, call; 341, 342; 341, 343; 342, identifier:hasattr; 343, argument_list; 343, 344; 343, 347; 344, subscript; 344, 345; 344, 346; 345, identifier:r; 346, identifier:k; 347, string:'unit'; 348, subscript; 348, 349; 348, 350; 349, identifier:r; 350, identifier:k; 351, for_in_clause; 351, 352; 351, 353; 352, identifier:k; 353, subscript; 353, 354; 353, 359; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:data; 357, identifier:keys; 358, argument_list; 359, slice; 359, 360; 359, 361; 360, integer:1; 361, colon; 362, for_in_clause; 362, 363; 362, 364; 363, identifier:r; 364, identifier:data; 365, else_clause; 365, 366; 365, 367; 366, comment; 367, block; 367, 368; 368, expression_statement; 368, 369; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:data; 372, identifier:add_index; 373, argument_list; 373, 374; 374, string:'Band'; 375, return_statement; 375, 376; 376, identifier:data; 377, comment; 378, else_clause; 378, 379; 379, block; 379, 380; 380, if_statement; 380, 381; 380, 383; 380, 395; 381, not_operator; 381, 382; 382, identifier:updated; 383, block; 383, 384; 383, 388; 384, expression_statement; 384, 385; 385, assignment; 385, 386; 385, 387; 386, identifier:updated; 387, True; 388, expression_statement; 388, 389; 389, call; 389, 390; 389, 391; 390, identifier:filters; 391, argument_list; 391, 392; 392, keyword_argument; 392, 393; 392, 394; 393, identifier:update; 394, True; 395, else_clause; 395, 396; 396, block; 396, 397; 397, expression_statement; 397, 398; 398, call; 398, 399; 398, 400; 399, identifier:print; 400, argument_list; 400, 401; 400, 402; 401, string:'No filters found in'; 402, identifier:filter_directory
def filters(filter_directory=None, update=False, fmt='table', **kwargs): """ Get a list of the available filters Parameters ---------- filter_directory: str The directory containing the filter relative spectral response curves update: bool Check the filter directory for new filters and generate pickle of table fmt: str The format for the returned table Returns ------- list The list of band names """ if filter_directory is None: filter_directory = resource_filename('svo_filters', 'data/filters/') # Get the pickle path and make sure file exists p_path = os.path.join(filter_directory, 'filter_list.p') updated = False if not os.path.isfile(p_path): os.system('touch {}'.format(p_path)) if update: print('Loading filters into table...') # Get all the filters (except the pickle) files = glob(filter_directory+'*') files = [f for f in files if not f.endswith('.p')] bands = [os.path.basename(b) for b in files] tables = [] for band in bands: # Load the filter band = band.replace('.txt', '') filt = Filter(band, **kwargs) filt.Band = band # Put metadata into table with correct dtypes info = filt.info(True) vals = [float(i) if i.replace('.', '').replace('-', '') .replace('+', '').isnumeric() else i for i in info['Values']] dtypes = np.array([type(i) for i in vals]) table = at.Table(np.array([vals]), names=info['Attributes'], dtype=dtypes) tables.append(table) del filt, info, table # Write to the pickle with open(p_path, 'wb') as file: pickle.dump(at.vstack(tables), file) # Load the saved pickle data = {} if os.path.isfile(p_path): with open(p_path, 'rb') as file: data = pickle.load(file) # Return the data if data: if fmt == 'dict': data = {r[0]: {k: r[k].value if hasattr(r[k], 'unit') else r[k] for k in data.keys()[1:]} for r in data} else: # Add Band as index data.add_index('Band') return data # Or try to generate it once else: if not updated: updated = True filters(update=True) else: print('No filters found in', filter_directory)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:parse_unit; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:prop; 5, identifier:dictionary; 6, default_parameter; 6, 7; 6, 8; 7, identifier:dt; 8, None; 9, block; 9, 10; 9, 12; 9, 13; 9, 36; 9, 37; 9, 53; 9, 81; 9, 82; 9, 128; 9, 129; 9, 140; 10, expression_statement; 10, 11; 11, string:'''Do a fuzzy match for `prop` in the dictionary, taking into account unit suffix.'''; 12, comment; 13, try_statement; 13, 14; 13, 29; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:dt; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:timezone; 21, identifier:parse_datetime; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:dictionary; 26, identifier:get; 27, argument_list; 27, 28; 28, string:'date_time'; 29, except_clause; 29, 30; 29, 31; 30, identifier:TypeError; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:dt; 35, None; 36, comment; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:matches; 40, list_comprehension; 40, 41; 40, 42; 40, 49; 41, identifier:k; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:k; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:dictionary; 47, identifier:keys; 48, argument_list; 49, if_clause; 49, 50; 50, comparison_operator:in; 50, 51; 50, 52; 51, identifier:prop; 52, identifier:k; 53, try_statement; 53, 54; 53, 75; 54, block; 54, 55; 54, 63; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:value; 58, subscript; 58, 59; 58, 60; 59, identifier:dictionary; 60, subscript; 60, 61; 60, 62; 61, identifier:matches; 62, integer:0; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:unit; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:re; 69, identifier:search; 70, argument_list; 70, 71; 70, 72; 71, string:r' \(([^)]+)\)'; 72, subscript; 72, 73; 72, 74; 73, identifier:matches; 74, integer:0; 75, except_clause; 75, 76; 75, 77; 75, 78; 76, identifier:IndexError; 77, comment; 78, block; 78, 79; 79, return_statement; 79, 80; 80, None; 81, comment; 82, if_statement; 82, 83; 82, 86; 82, 87; 83, comparison_operator:in; 83, 84; 83, 85; 84, string:';'; 85, identifier:value; 86, comment; 87, block; 87, 88; 87, 105; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:values; 91, list_comprehension; 91, 92; 91, 93; 91, 101; 92, identifier:val; 93, for_in_clause; 93, 94; 93, 95; 94, identifier:val; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:value; 98, identifier:split; 99, argument_list; 99, 100; 100, string:';'; 101, if_clause; 101, 102; 102, comparison_operator:!=; 102, 103; 102, 104; 103, identifier:val; 104, string:''; 105, if_statement; 105, 106; 105, 107; 105, 124; 106, identifier:unit; 107, block; 107, 108; 108, return_statement; 108, 109; 109, list_comprehension; 109, 110; 109, 121; 110, call; 110, 111; 110, 112; 111, identifier:Observation; 112, argument_list; 112, 113; 112, 114; 112, 120; 113, identifier:v; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:unit; 117, identifier:group; 118, argument_list; 118, 119; 119, integer:1; 120, identifier:dt; 121, for_in_clause; 121, 122; 121, 123; 122, identifier:v; 123, identifier:values; 124, else_clause; 124, 125; 125, block; 125, 126; 126, return_statement; 126, 127; 127, identifier:values; 128, comment; 129, if_statement; 129, 130; 129, 135; 130, boolean_operator:or; 130, 131; 130, 133; 131, not_operator; 131, 132; 132, identifier:value; 133, not_operator; 133, 134; 134, identifier:unit; 135, block; 135, 136; 136, return_statement; 136, 137; 137, boolean_operator:or; 137, 138; 137, 139; 138, identifier:value; 139, None; 140, return_statement; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:Observation; 143, argument_list; 143, 144; 143, 145; 143, 151; 144, identifier:value; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:unit; 148, identifier:group; 149, argument_list; 149, 150; 150, integer:1; 151, identifier:dt
def parse_unit(prop, dictionary, dt=None): '''Do a fuzzy match for `prop` in the dictionary, taking into account unit suffix.''' # add the observation's time try: dt = timezone.parse_datetime(dictionary.get('date_time')) except TypeError: dt = None # 'prop' is a stub of the property's attribute key, so search for matches matches = [k for k in dictionary.keys() if prop in k] try: value = dictionary[matches[0]] unit = re.search(r' \(([^)]+)\)', matches[0]) except IndexError: # No matches: fail out return None # Sometimes we get a list of values (e.g. waves) if ';' in value: # Ignore empty values values = [val for val in value.split(';') if val != ''] if unit: return [Observation(v, unit.group(1), dt) for v in values] else: return values # Sometimes there's no value! Sometimes there's no unit! if not value or not unit: return value or None return Observation(value, unit.group(1), dt)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:rebuild; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 22; 5, 23; 5, 45; 5, 46; 5, 54; 5, 321; 5, 328; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:setUpdatesEnabled; 13, argument_list; 13, 14; 14, False; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:blockSignals; 20, argument_list; 20, 21; 21, True; 22, comment; 23, for_statement; 23, 24; 23, 25; 23, 31; 24, identifier:child; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:findChildren; 29, argument_list; 29, 30; 30, identifier:QObject; 31, block; 31, 32; 31, 39; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:child; 36, identifier:setParent; 37, argument_list; 37, 38; 38, None; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:child; 43, identifier:deleteLater; 44, argument_list; 45, comment; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:schema; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:schema; 53, argument_list; 54, if_statement; 54, 55; 54, 57; 54, 312; 55, parenthesized_expression; 55, 56; 56, identifier:schema; 57, block; 57, 58; 57, 65; 57, 73; 57, 74; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:setEnabled; 63, argument_list; 63, 64; 64, True; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:uifile; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:uiFile; 72, argument_list; 73, comment; 74, if_statement; 74, 75; 74, 77; 74, 142; 74, 143; 75, parenthesized_expression; 75, 76; 76, identifier:uifile; 77, block; 77, 78; 77, 87; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:projexui; 82, identifier:loadUi; 83, argument_list; 83, 84; 83, 85; 83, 86; 84, string:''; 85, identifier:self; 86, identifier:uifile; 87, for_statement; 87, 88; 87, 89; 87, 95; 88, identifier:widget; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:findChildren; 93, argument_list; 93, 94; 94, identifier:XOrbColumnEdit; 95, block; 95, 96; 95, 104; 95, 113; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:columnName; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:widget; 102, identifier:columnName; 103, argument_list; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:column; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:schema; 110, identifier:column; 111, argument_list; 111, 112; 112, identifier:columnName; 113, if_statement; 113, 114; 113, 116; 113, 124; 114, parenthesized_expression; 114, 115; 115, identifier:column; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:widget; 121, identifier:setColumn; 122, argument_list; 122, 123; 123, identifier:column; 124, else_clause; 124, 125; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:logger; 130, identifier:debug; 131, argument_list; 131, 132; 132, binary_operator:%; 132, 133; 132, 134; 132, 135; 133, string:'%s is not a valid column of %s'; 134, line_continuation:\; 135, tuple; 135, 136; 135, 137; 136, identifier:columnName; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:schema; 140, identifier:name; 141, argument_list; 142, comment; 143, else_clause; 143, 144; 144, block; 144, 145; 144, 151; 144, 161; 144, 169; 144, 185; 144, 193; 144, 286; 144, 293; 144, 299; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:layout; 148, call; 148, 149; 148, 150; 149, identifier:QFormLayout; 150, argument_list; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:layout; 155, identifier:setContentsMargins; 156, argument_list; 156, 157; 156, 158; 156, 159; 156, 160; 157, integer:0; 158, integer:0; 159, integer:0; 160, integer:0; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:columns; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:schema; 167, identifier:columns; 168, argument_list; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:columns; 173, identifier:sort; 174, argument_list; 174, 175; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:key; 177, lambda; 177, 178; 177, 180; 178, lambda_parameters; 178, 179; 179, identifier:x; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:x; 183, identifier:displayName; 184, argument_list; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:record; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:record; 192, argument_list; 193, for_statement; 193, 194; 193, 195; 193, 196; 193, 197; 194, identifier:column; 195, identifier:columns; 196, comment; 197, block; 197, 198; 197, 212; 197, 220; 197, 228; 197, 236; 197, 237; 197, 244; 197, 253; 197, 260; 197, 267; 197, 274; 198, if_statement; 198, 199; 198, 210; 199, parenthesized_expression; 199, 200; 200, call; 200, 201; 200, 208; 201, attribute; 201, 202; 201, 207; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:column; 205, identifier:name; 206, argument_list; 207, identifier:startswith; 208, argument_list; 208, 209; 209, string:'_'; 210, block; 210, 211; 211, continue_statement; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:label; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:column; 218, identifier:displayName; 219, argument_list; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:coltype; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:column; 226, identifier:columnType; 227, argument_list; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:name; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:column; 234, identifier:name; 235, argument_list; 236, comment; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:widget; 240, call; 240, 241; 240, 242; 241, identifier:XOrbColumnEdit; 242, argument_list; 242, 243; 243, identifier:self; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:widget; 248, identifier:setObjectName; 249, argument_list; 249, 250; 250, binary_operator:+; 250, 251; 250, 252; 251, string:'ui_'; 252, identifier:name; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:widget; 257, identifier:setColumnName; 258, argument_list; 258, 259; 259, identifier:name; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:widget; 264, identifier:setColumnType; 265, argument_list; 265, 266; 266, identifier:coltype; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:widget; 271, identifier:setColumn; 272, argument_list; 272, 273; 273, identifier:column; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:layout; 278, identifier:addRow; 279, argument_list; 279, 280; 279, 285; 280, call; 280, 281; 280, 282; 281, identifier:QLabel; 282, argument_list; 282, 283; 282, 284; 283, identifier:label; 284, identifier:self; 285, identifier:widget; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:self; 290, identifier:setLayout; 291, argument_list; 291, 292; 292, identifier:layout; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:self; 297, identifier:adjustSize; 298, argument_list; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:self; 303, identifier:setWindowTitle; 304, argument_list; 304, 305; 305, binary_operator:%; 305, 306; 305, 307; 306, string:'Edit %s'; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:schema; 310, identifier:name; 311, argument_list; 312, else_clause; 312, 313; 313, block; 313, 314; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:self; 318, identifier:setEnabled; 319, argument_list; 319, 320; 320, False; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:setUpdatesEnabled; 326, argument_list; 326, 327; 327, True; 328, expression_statement; 328, 329; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:self; 332, identifier:blockSignals; 333, argument_list; 333, 334; 334, False
def rebuild( self ): """ Rebuilds the interface for this widget based on the current model. """ self.setUpdatesEnabled(False) self.blockSignals(True) # clear out all the subwidgets for this widget for child in self.findChildren(QObject): child.setParent(None) child.deleteLater() # load up all the interface for this widget schema = self.schema() if ( schema ): self.setEnabled(True) uifile = self.uiFile() # load a user defined file if ( uifile ): projexui.loadUi('', self, uifile) for widget in self.findChildren(XOrbColumnEdit): columnName = widget.columnName() column = schema.column(columnName) if ( column ): widget.setColumn(column) else: logger.debug('%s is not a valid column of %s' % \ (columnName, schema.name())) # dynamically load files else: layout = QFormLayout() layout.setContentsMargins(0, 0, 0, 0) columns = schema.columns() columns.sort(key = lambda x: x.displayName()) record = self.record() for column in columns: # ignore protected columns if ( column.name().startswith('_') ): continue label = column.displayName() coltype = column.columnType() name = column.name() # create the column edit widget widget = XOrbColumnEdit(self) widget.setObjectName('ui_' + name) widget.setColumnName(name) widget.setColumnType(coltype) widget.setColumn(column) layout.addRow(QLabel(label, self), widget) self.setLayout(layout) self.adjustSize() self.setWindowTitle('Edit %s' % schema.name()) else: self.setEnabled(False) self.setUpdatesEnabled(True) self.blockSignals(False)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:save; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 30; 5, 38; 5, 50; 5, 51; 5, 55; 5, 64; 5, 255; 5, 256; 5, 274; 5, 280; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:schema; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:schema; 15, argument_list; 16, if_statement; 16, 17; 16, 20; 17, parenthesized_expression; 17, 18; 18, not_operator; 18, 19; 19, identifier:schema; 20, block; 20, 21; 20, 29; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:saved; 27, identifier:emit; 28, argument_list; 29, return_statement; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:record; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:record; 37, argument_list; 38, if_statement; 38, 39; 38, 41; 39, not_operator; 39, 40; 40, identifier:record; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:record; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_model; 49, argument_list; 50, comment; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:save_data; 54, list:[]; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:column_edits; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:findChildren; 62, argument_list; 62, 63; 63, identifier:XOrbColumnEdit; 64, for_statement; 64, 65; 64, 66; 64, 67; 65, identifier:widget; 66, identifier:column_edits; 67, block; 67, 68; 67, 76; 67, 85; 67, 107; 67, 115; 67, 122; 67, 123; 67, 246; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:columnName; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:widget; 74, identifier:columnName; 75, argument_list; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:column; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:schema; 82, identifier:column; 83, argument_list; 83, 84; 84, identifier:columnName; 85, if_statement; 85, 86; 85, 89; 86, parenthesized_expression; 86, 87; 87, not_operator; 87, 88; 88, identifier:column; 89, block; 89, 90; 89, 106; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:logger; 94, identifier:warning; 95, argument_list; 95, 96; 96, binary_operator:%; 96, 97; 96, 98; 96, 99; 97, string:'%s is not a valid column of %s.'; 98, line_continuation:\; 99, tuple; 99, 100; 99, 101; 100, identifier:columnName; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:schema; 104, identifier:name; 105, argument_list; 106, continue_statement; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:value; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:widget; 113, identifier:value; 114, argument_list; 115, if_statement; 115, 116; 115, 120; 116, parenthesized_expression; 116, 117; 117, comparison_operator:==; 117, 118; 117, 119; 118, identifier:value; 119, identifier:IGNORED; 120, block; 120, 121; 121, continue_statement; 122, comment; 123, if_statement; 123, 124; 123, 133; 123, 154; 123, 155; 124, parenthesized_expression; 124, 125; 125, boolean_operator:and; 125, 126; 125, 131; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:column; 129, identifier:required; 130, argument_list; 131, not_operator; 131, 132; 132, identifier:value; 133, block; 133, 134; 133, 142; 133, 153; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:name; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:column; 140, identifier:displayName; 141, argument_list; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:QMessageBox; 146, identifier:information; 147, argument_list; 147, 148; 147, 149; 147, 150; 148, identifier:self; 149, string:'Missing Required Field'; 150, binary_operator:%; 150, 151; 150, 152; 151, string:'%s is a required field.'; 152, identifier:name; 153, return_statement; 154, comment; 155, elif_clause; 155, 156; 155, 162; 155, 163; 156, parenthesized_expression; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:column; 160, identifier:unique; 161, argument_list; 162, comment; 163, block; 163, 164; 163, 177; 163, 196; 163, 210; 163, 226; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:query; 167, comparison_operator:==; 167, 168; 167, 176; 168, call; 168, 169; 168, 170; 169, identifier:Q; 170, argument_list; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:column; 174, identifier:name; 175, argument_list; 176, identifier:value; 177, if_statement; 177, 178; 177, 184; 178, parenthesized_expression; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:record; 182, identifier:isRecord; 183, argument_list; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, augmented_assignment:&=; 186, 187; 186, 188; 187, identifier:query; 188, comparison_operator:!=; 188, 189; 188, 195; 189, call; 189, 190; 189, 191; 190, identifier:Q; 191, argument_list; 191, 192; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:_model; 195, identifier:record; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:columns; 199, call; 199, 200; 199, 209; 200, attribute; 200, 201; 200, 208; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:_model; 206, identifier:schema; 207, argument_list; 208, identifier:primaryColumns; 209, argument_list; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:result; 213, call; 213, 214; 213, 219; 214, attribute; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:_model; 218, identifier:select; 219, argument_list; 219, 220; 219, 223; 220, keyword_argument; 220, 221; 220, 222; 221, identifier:columns; 222, identifier:columns; 223, keyword_argument; 223, 224; 223, 225; 224, identifier:where; 225, identifier:query; 226, if_statement; 226, 227; 226, 233; 227, parenthesized_expression; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:result; 231, identifier:total; 232, argument_list; 233, block; 233, 234; 233, 245; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:QMessageBox; 238, identifier:information; 239, argument_list; 239, 240; 239, 241; 239, 242; 240, identifier:self; 241, string:'Duplicate Entry'; 242, binary_operator:%; 242, 243; 242, 244; 243, string:'%s already exists.'; 244, identifier:value; 245, return_statement; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:save_data; 250, identifier:append; 251, argument_list; 251, 252; 252, tuple; 252, 253; 252, 254; 253, identifier:column; 254, identifier:value; 255, comment; 256, for_statement; 256, 257; 256, 260; 256, 261; 257, pattern_list; 257, 258; 257, 259; 258, identifier:column; 259, identifier:value; 260, identifier:save_data; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:record; 266, identifier:setRecordValue; 267, argument_list; 267, 268; 267, 273; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:column; 271, identifier:name; 272, argument_list; 273, identifier:value; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:_record; 279, identifier:record; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 287; 282, attribute; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:self; 285, identifier:saved; 286, identifier:emit; 287, argument_list
def save( self ): """ Saves the values from the editor to the system. """ schema = self.schema() if ( not schema ): self.saved.emit() return record = self.record() if not record: record = self._model() # validate the information save_data = [] column_edits = self.findChildren(XOrbColumnEdit) for widget in column_edits: columnName = widget.columnName() column = schema.column(columnName) if ( not column ): logger.warning('%s is not a valid column of %s.' % \ (columnName, schema.name())) continue value = widget.value() if ( value == IGNORED ): continue # check for required columns if ( column.required() and not value ): name = column.displayName() QMessageBox.information(self, 'Missing Required Field', '%s is a required field.' % name) return # check for unique columns elif ( column.unique() ): # check for uniqueness query = Q(column.name()) == value if ( record.isRecord() ): query &= Q(self._model) != record columns = self._model.schema().primaryColumns() result = self._model.select(columns = columns, where = query) if ( result.total() ): QMessageBox.information(self, 'Duplicate Entry', '%s already exists.' % value) return save_data.append((column, value)) # record the properties for the record for column, value in save_data: record.setRecordValue(column.name(), value) self._record = record self.saved.emit()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:register; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:service; 6, block; 6, 7; 6, 9; 6, 24; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:response; 12, await; 12, 13; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_api; 18, identifier:put; 19, argument_list; 19, 20; 19, 21; 20, string:"/v1/agent/service/register"; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:data; 23, identifier:service; 24, return_statement; 24, 25; 25, comparison_operator:==; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:response; 28, identifier:status; 29, integer:200
async def register(self, service): """Registers a new local service. Returns: bool: ``True`` on success The register endpoint is used to add a new service, with an optional health check, to the local agent. The request body must look like:: { "ID": "redis1", "Name": "redis", "Tags": [ "master", "v1" ], "Address": "127.0.0.1", "Port": 8000, "EnableTagOverride": False, "Check": { "DeregisterCriticalServiceAfter": timedelta(seconds=90), "Script": "/usr/local/bin/check_redis.py", "HTTP": "http://localhost:5000/health", "Interval": timedelta(seconds=10), "TTL": timedelta(seconds=15) } } The **Name** field is mandatory. If an **ID** is not provided, it is set to **Name**. You cannot have duplicate **ID** entries per agent, so it may be necessary to provide an **ID** in the case of a collision. **Tags**, **Address**, **Port**, **Check** and **EnableTagOverride** are optional. If **Address** is not provided or left empty, then the agent's address will be used as the address for the service during DNS queries. When querying for services using HTTP endpoints such as service health or service catalog and encountering an empty **Address** field for a service, use the **Address** field of the agent node associated with that instance of the service, which is returned alongside the service information. If **Check** is provided, only one of **Script**, **HTTP**, **TCP** or **TTL** should be specified. **Script** and **HTTP** also require **Interval**. The created check will be named "service:<ServiceId>". Checks that are associated with a service may also contain an optional **DeregisterCriticalServiceAfter** field, which is a timeout in the same format as **Interval** and **TTL**. If a check is in the critical state for more than this configured value, then its associated service (and all of its associated checks) will automatically be deregistered. The minimum timeout is 1 minute, and the process that reaps critical services runs every 30 seconds, so it may take slightly longer than the configured timeout to trigger the deregistration. This should generally be configured with a timeout that's much, much longer than any expected recoverable outage for the given service. **EnableTagOverride** can optionally be specified to disable the anti-entropy feature for this service's tags. If **EnableTagOverride** is set to ``True`` then external agents can update this service in the catalog and modify the tags. Subsequent local sync operations by this agent will ignore the updated tags. For instance, if an external agent modified both the tags and the port for this service and **EnableTagOverride** was set to true then after the next sync cycle the service's port would revert to the original value but the tags would maintain the updated value. As a counter example, if an external agent modified both the tags and port for this service and **EnableTagOverride** was set to false then after the next sync cycle the service's port and the tags would revert to the original value and all modifications would be lost. It's important to note that this applies only to the locally registered service. If you have multiple nodes all registering the same service their **EnableTagOverride** configuration and all other service configuration items are independent of one another. Updating the tags for the service registered on one node is independent of the same service (by name) registered on another node. If **EnableTagOverride** is not specified the default value is ``False``. """ response = await self._api.put("/v1/agent/service/register", data=service) return response.status == 200
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:save; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 31; 5, 56; 5, 64; 5, 65; 5, 73; 5, 113; 5, 114; 5, 218; 5, 219; 5, 230; 5, 246; 5, 254; 5, 264; 5, 279; 5, 311; 5, 351; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:record; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:record; 15, argument_list; 16, if_statement; 16, 17; 16, 19; 17, not_operator; 17, 18; 18, identifier:record; 19, block; 19, 20; 19, 29; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:logger; 24, identifier:warning; 25, argument_list; 25, 26; 26, binary_operator:%; 26, 27; 26, 28; 27, string:'No record has been defined for %s.'; 28, identifier:self; 29, return_statement; 29, 30; 30, False; 31, if_statement; 31, 32; 31, 38; 32, not_operator; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:signalsBlocked; 37, argument_list; 38, block; 38, 39; 38, 48; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:aboutToSaveRecord; 45, identifier:emit; 46, argument_list; 46, 47; 47, identifier:record; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:aboutToSave; 54, identifier:emit; 55, argument_list; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:values; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:saveValues; 63, argument_list; 64, comment; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:check; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:values; 71, identifier:copy; 72, argument_list; 73, for_statement; 73, 74; 73, 77; 73, 82; 74, pattern_list; 74, 75; 74, 76; 75, identifier:column_name; 76, identifier:value; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:check; 80, identifier:items; 81, argument_list; 82, block; 82, 83; 82, 103; 83, try_statement; 83, 84; 83, 96; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:equals; 88, comparison_operator:==; 88, 89; 88, 90; 89, identifier:value; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:record; 93, identifier:recordValue; 94, argument_list; 94, 95; 95, identifier:column_name; 96, except_clause; 96, 97; 96, 98; 97, identifier:UnicodeWarning; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:equals; 102, False; 103, if_statement; 103, 104; 103, 105; 104, identifier:equals; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:check; 110, identifier:pop; 111, argument_list; 111, 112; 112, identifier:column_name; 113, comment; 114, if_statement; 114, 115; 114, 123; 115, boolean_operator:and; 115, 116; 115, 118; 116, not_operator; 116, 117; 117, identifier:check; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:record; 121, identifier:isRecord; 122, argument_list; 123, block; 123, 124; 123, 163; 123, 216; 124, if_statement; 124, 125; 124, 131; 124, 155; 125, not_operator; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:signalsBlocked; 130, argument_list; 131, block; 131, 132; 131, 141; 131, 149; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 139; 134, attribute; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:recordSaved; 138, identifier:emit; 139, argument_list; 139, 140; 140, identifier:record; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:saved; 147, identifier:emit; 148, argument_list; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:_saveSignalBlocked; 154, False; 155, else_clause; 155, 156; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:_saveSignalBlocked; 162, True; 163, if_statement; 163, 164; 163, 169; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:autoCommitOnSave; 168, argument_list; 169, block; 169, 170; 169, 180; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 175; 172, pattern_list; 172, 173; 172, 174; 173, identifier:status; 174, identifier:result; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:record; 178, identifier:commit; 179, argument_list; 180, if_statement; 180, 181; 180, 184; 181, comparison_operator:==; 181, 182; 181, 183; 182, identifier:status; 183, string:'errored'; 184, block; 184, 185; 184, 205; 184, 214; 185, if_statement; 185, 186; 185, 189; 185, 199; 186, comparison_operator:in; 186, 187; 186, 188; 187, string:'db_error'; 188, identifier:result; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:msg; 193, call; 193, 194; 193, 195; 194, identifier:nativestring; 195, argument_list; 195, 196; 196, subscript; 196, 197; 196, 198; 197, identifier:result; 198, string:'db_error'; 199, else_clause; 199, 200; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:msg; 204, string:'An unknown database error has occurred.'; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:QMessageBox; 209, identifier:information; 210, argument_list; 210, 211; 210, 212; 210, 213; 211, identifier:self; 212, string:'Commit Error'; 213, identifier:msg; 214, return_statement; 214, 215; 215, False; 216, return_statement; 216, 217; 217, True; 218, comment; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 224; 221, pattern_list; 221, 222; 221, 223; 222, identifier:success; 223, identifier:msg; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:record; 227, identifier:validateValues; 228, argument_list; 228, 229; 229, identifier:check; 230, if_statement; 230, 231; 230, 234; 231, parenthesized_expression; 231, 232; 232, not_operator; 232, 233; 233, identifier:success; 234, block; 234, 235; 234, 244; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:QMessageBox; 239, identifier:information; 240, argument_list; 240, 241; 240, 242; 240, 243; 241, None; 242, string:'Could Not Save'; 243, identifier:msg; 244, return_statement; 244, 245; 245, False; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:record; 250, identifier:setRecordValues; 251, argument_list; 251, 252; 252, dictionary_splat; 252, 253; 253, identifier:values; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 259; 256, pattern_list; 256, 257; 256, 258; 257, identifier:success; 258, identifier:msg; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:record; 262, identifier:validateRecord; 263, argument_list; 264, if_statement; 264, 265; 264, 267; 265, not_operator; 265, 266; 266, identifier:success; 267, block; 267, 268; 267, 277; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:QMessageBox; 272, identifier:information; 273, argument_list; 273, 274; 273, 275; 273, 276; 274, None; 275, string:'Could Not Save'; 276, identifier:msg; 277, return_statement; 277, 278; 278, False; 279, if_statement; 279, 280; 279, 286; 280, parenthesized_expression; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:autoCommitOnSave; 285, argument_list; 286, block; 286, 287; 286, 295; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:result; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:record; 293, identifier:commit; 294, argument_list; 295, if_statement; 295, 296; 295, 299; 296, comparison_operator:in; 296, 297; 296, 298; 297, string:'errored'; 298, identifier:result; 299, block; 299, 300; 299, 309; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:QMessageBox; 304, identifier:information; 305, argument_list; 305, 306; 305, 307; 305, 308; 306, None; 307, string:'Could Not Save'; 308, identifier:msg; 309, return_statement; 309, 310; 310, False; 311, if_statement; 311, 312; 311, 319; 311, 343; 312, parenthesized_expression; 312, 313; 313, not_operator; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:self; 317, identifier:signalsBlocked; 318, argument_list; 319, block; 319, 320; 319, 329; 319, 337; 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:self; 325, identifier:recordSaved; 326, identifier:emit; 327, argument_list; 327, 328; 328, identifier:record; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 336; 331, attribute; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:self; 334, identifier:saved; 335, identifier:emit; 336, argument_list; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:self; 341, identifier:_saveSignalBlocked; 342, False; 343, else_clause; 343, 344; 344, block; 344, 345; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:self; 349, identifier:_saveSignalBlocked; 350, True; 351, return_statement; 351, 352; 352, True
def save(self): """ Saves the changes from the ui to this widgets record instance. """ record = self.record() if not record: logger.warning('No record has been defined for %s.' % self) return False if not self.signalsBlocked(): self.aboutToSaveRecord.emit(record) self.aboutToSave.emit() values = self.saveValues() # ignore columns that are the same (fixes bugs in encrypted columns) check = values.copy() for column_name, value in check.items(): try: equals = value == record.recordValue(column_name) except UnicodeWarning: equals = False if equals: check.pop(column_name) # check to see if nothing has changed if not check and record.isRecord(): if not self.signalsBlocked(): self.recordSaved.emit(record) self.saved.emit() self._saveSignalBlocked = False else: self._saveSignalBlocked = True if self.autoCommitOnSave(): status, result = record.commit() if status == 'errored': if 'db_error' in result: msg = nativestring(result['db_error']) else: msg = 'An unknown database error has occurred.' QMessageBox.information(self, 'Commit Error', msg) return False return True # validate the modified values success, msg = record.validateValues(check) if ( not success ): QMessageBox.information(None, 'Could Not Save', msg) return False record.setRecordValues(**values) success, msg = record.validateRecord() if not success: QMessageBox.information(None, 'Could Not Save', msg) return False if ( self.autoCommitOnSave() ): result = record.commit() if 'errored' in result: QMessageBox.information(None, 'Could Not Save', msg) return False if ( not self.signalsBlocked() ): self.recordSaved.emit(record) self.saved.emit() self._saveSignalBlocked = False else: self._saveSignalBlocked = True return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:prepare; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 18; 5, 33; 5, 34; 5, 43; 5, 76; 5, 77; 5, 148; 5, 149; 5, 167; 5, 287; 5, 296; 5, 331; 5, 335; 5, 345; 5, 355; 5, 365; 5, 375; 5, 395; 5, 403; 5, 410; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:pixmap; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:property; 16, argument_list; 16, 17; 17, string:'pixmap'; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:pixmap; 21, None; 22, block; 22, 23; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 32; 25, attribute; 25, 26; 25, 31; 26, call; 26, 27; 26, 28; 27, identifier:super; 28, argument_list; 28, 29; 28, 30; 29, identifier:XWalkthroughSnapshot; 30, identifier:self; 31, identifier:prepare; 32, argument_list; 33, comment; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:widget; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:property; 41, argument_list; 41, 42; 42, string:'widget'; 43, if_statement; 43, 44; 43, 52; 44, comparison_operator:in; 44, 45; 44, 49; 45, call; 45, 46; 45, 47; 46, identifier:type; 47, argument_list; 47, 48; 48, identifier:widget; 49, tuple; 49, 50; 49, 51; 50, identifier:unicode; 51, identifier:str; 52, block; 52, 53; 52, 62; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:widget; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:findReference; 60, argument_list; 60, 61; 61, identifier:widget; 62, if_statement; 62, 63; 62, 65; 63, not_operator; 63, 64; 64, identifier:widget; 65, block; 65, 66; 66, return_statement; 66, 67; 67, call; 67, 68; 67, 75; 68, attribute; 68, 69; 68, 74; 69, call; 69, 70; 69, 71; 70, identifier:super; 71, argument_list; 71, 72; 71, 73; 72, identifier:XWalkthroughSnapshot; 73, identifier:self; 74, identifier:prepare; 75, argument_list; 76, comment; 77, if_statement; 77, 78; 77, 90; 78, boolean_operator:and; 78, 79; 78, 85; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:property; 83, argument_list; 83, 84; 84, string:'overlay'; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:widget; 88, identifier:parent; 89, argument_list; 90, block; 90, 91; 90, 99; 90, 140; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:ref; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:referenceWidget; 98, argument_list; 99, if_statement; 99, 100; 99, 103; 99, 114; 100, comparison_operator:==; 100, 101; 100, 102; 101, identifier:ref; 102, identifier:widget; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:pos; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:QtCore; 110, identifier:QPoint; 111, argument_list; 111, 112; 111, 113; 112, integer:0; 113, integer:0; 114, else_clause; 114, 115; 115, block; 115, 116; 115, 131; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:glbl_pos; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:widget; 122, identifier:mapToGlobal; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:QtCore; 127, identifier:QPoint; 128, argument_list; 128, 129; 128, 130; 129, integer:0; 130, integer:0; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:pos; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:ref; 137, identifier:mapFromGlobal; 138, argument_list; 138, 139; 139, identifier:glbl_pos; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:setProperty; 145, argument_list; 145, 146; 145, 147; 146, string:'pos'; 147, identifier:pos; 148, comment; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:crop; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:property; 156, argument_list; 156, 157; 156, 158; 157, string:'crop'; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:QtCore; 161, identifier:QRect; 162, argument_list; 162, 163; 162, 164; 162, 165; 162, 166; 163, integer:0; 164, integer:0; 165, integer:0; 166, integer:0; 167, if_statement; 167, 168; 167, 169; 167, 274; 168, identifier:crop; 169, block; 169, 170; 169, 178; 169, 196; 169, 214; 169, 238; 169, 262; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:rect; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:widget; 176, identifier:rect; 177, argument_list; 178, if_statement; 178, 179; 178, 184; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:crop; 182, identifier:width; 183, argument_list; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:rect; 189, identifier:setWidth; 190, argument_list; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:crop; 194, identifier:width; 195, argument_list; 196, if_statement; 196, 197; 196, 202; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:crop; 200, identifier:height; 201, argument_list; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:rect; 207, identifier:setHeight; 208, argument_list; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:crop; 212, identifier:height; 213, argument_list; 214, if_statement; 214, 215; 214, 220; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:crop; 218, identifier:x; 219, argument_list; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:rect; 225, identifier:setX; 226, argument_list; 226, 227; 227, binary_operator:-; 227, 228; 227, 233; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:rect; 231, identifier:width; 232, argument_list; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:crop; 236, identifier:x; 237, argument_list; 238, if_statement; 238, 239; 238, 244; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:crop; 242, identifier:y; 243, argument_list; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:rect; 249, identifier:setY; 250, argument_list; 250, 251; 251, binary_operator:-; 251, 252; 251, 257; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:rect; 255, identifier:height; 256, argument_list; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:crop; 260, identifier:y; 261, argument_list; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:pixmap; 265, call; 265, 266; 265, 271; 266, attribute; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:QtGui; 269, identifier:QPixmap; 270, identifier:grabWidget; 271, argument_list; 271, 272; 271, 273; 272, identifier:widget; 273, identifier:rect; 274, else_clause; 274, 275; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:pixmap; 279, call; 279, 280; 279, 285; 280, attribute; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:QtGui; 283, identifier:QPixmap; 284, identifier:grabWidget; 285, argument_list; 285, 286; 286, identifier:widget; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:scaled; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:self; 293, identifier:property; 294, argument_list; 294, 295; 295, string:'scaled'; 296, if_statement; 296, 297; 296, 298; 297, identifier:scaled; 298, block; 298, 299; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:pixmap; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:pixmap; 305, identifier:scaled; 306, argument_list; 306, 307; 306, 314; 306, 321; 306, 326; 307, binary_operator:*; 307, 308; 307, 313; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:pixmap; 311, identifier:width; 312, argument_list; 313, identifier:scaled; 314, binary_operator:*; 314, 315; 314, 320; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:pixmap; 318, identifier:height; 319, argument_list; 320, identifier:scaled; 321, attribute; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:QtCore; 324, identifier:Qt; 325, identifier:KeepAspectRatio; 326, attribute; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:QtCore; 329, identifier:Qt; 330, identifier:SmoothTransformation; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 334; 333, identifier:kwds; 334, dictionary; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 340; 337, subscript; 337, 338; 337, 339; 338, identifier:kwds; 339, string:'whatsThis'; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:widget; 343, identifier:whatsThis; 344, argument_list; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 350; 347, subscript; 347, 348; 347, 349; 348, identifier:kwds; 349, string:'toolTip'; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:widget; 353, identifier:toolTip; 354, argument_list; 355, expression_statement; 355, 356; 356, assignment; 356, 357; 356, 360; 357, subscript; 357, 358; 357, 359; 358, identifier:kwds; 359, string:'windowTitle'; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:widget; 363, identifier:windowTitle; 364, argument_list; 365, expression_statement; 365, 366; 366, assignment; 366, 367; 366, 370; 367, subscript; 367, 368; 367, 369; 368, identifier:kwds; 369, string:'objectName'; 370, call; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:widget; 373, identifier:objectName; 374, argument_list; 375, expression_statement; 375, 376; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:self; 379, identifier:setProperty; 380, argument_list; 380, 381; 380, 382; 381, string:'caption'; 382, call; 382, 383; 382, 392; 383, attribute; 383, 384; 383, 391; 384, call; 384, 385; 384, 388; 385, attribute; 385, 386; 385, 387; 386, identifier:self; 387, identifier:property; 388, argument_list; 388, 389; 388, 390; 389, string:'caption'; 390, string:''; 391, identifier:format; 392, argument_list; 392, 393; 393, dictionary_splat; 393, 394; 394, identifier:kwds; 395, expression_statement; 395, 396; 396, call; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:self; 399, identifier:setProperty; 400, argument_list; 400, 401; 400, 402; 401, string:'pixmap'; 402, identifier:pixmap; 403, expression_statement; 403, 404; 404, call; 404, 405; 404, 408; 405, attribute; 405, 406; 405, 407; 406, identifier:self; 407, identifier:addPixmap; 408, argument_list; 408, 409; 409, identifier:pixmap; 410, return_statement; 410, 411; 411, call; 411, 412; 411, 419; 412, attribute; 412, 413; 412, 418; 413, call; 413, 414; 413, 415; 414, identifier:super; 415, argument_list; 415, 416; 415, 417; 416, identifier:XWalkthroughSnapshot; 417, identifier:self; 418, identifier:prepare; 419, argument_list
def prepare(self): """ Prepares the information for this graphic. """ # determine if we already have a snapshot setup pixmap = self.property('pixmap') if pixmap is not None: return super(XWalkthroughSnapshot, self).prepare() # otherwise, setup the snapshot widget = self.property('widget') if type(widget) in (unicode, str): widget = self.findReference(widget) if not widget: return super(XWalkthroughSnapshot, self).prepare() # test if this is an overlay option if self.property('overlay') and widget.parent(): ref = self.referenceWidget() if ref == widget: pos = QtCore.QPoint(0, 0) else: glbl_pos = widget.mapToGlobal(QtCore.QPoint(0, 0)) pos = ref.mapFromGlobal(glbl_pos) self.setProperty('pos', pos) # crop out the options crop = self.property('crop', QtCore.QRect(0, 0, 0, 0)) if crop: rect = widget.rect() if crop.width(): rect.setWidth(crop.width()) if crop.height(): rect.setHeight(crop.height()) if crop.x(): rect.setX(rect.width() - crop.x()) if crop.y(): rect.setY(rect.height() - crop.y()) pixmap = QtGui.QPixmap.grabWidget(widget, rect) else: pixmap = QtGui.QPixmap.grabWidget(widget) scaled = self.property('scaled') if scaled: pixmap = pixmap.scaled(pixmap.width() * scaled, pixmap.height() * scaled, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) kwds = {} kwds['whatsThis'] = widget.whatsThis() kwds['toolTip'] = widget.toolTip() kwds['windowTitle'] = widget.windowTitle() kwds['objectName'] = widget.objectName() self.setProperty('caption', self.property('caption', '').format(**kwds)) self.setProperty('pixmap', pixmap) self.addPixmap(pixmap) return super(XWalkthroughSnapshot, self).prepare()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:depends; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:func; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:after; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:before; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:priority; 15, None; 16, block; 16, 17; 16, 19; 16, 45; 16, 59; 16, 60; 16, 61; 16, 62; 16, 81; 16, 102; 16, 178; 16, 183; 16, 189; 16, 200; 16, 222; 17, expression_statement; 17, 18; 18, comment; 19, if_statement; 19, 20; 19, 39; 20, not_operator; 20, 21; 21, parenthesized_expression; 21, 22; 22, boolean_operator:or; 22, 23; 22, 33; 23, boolean_operator:or; 23, 24; 23, 27; 24, comparison_operator:is; 24, 25; 24, 26; 25, identifier:func; 26, None; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:inspect; 30, identifier:ismethod; 31, argument_list; 31, 32; 32, identifier:func; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:inspect; 36, identifier:isfunction; 37, argument_list; 37, 38; 38, identifier:func; 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:"depends decorator can only be used on functions or methods"; 45, if_statement; 45, 46; 45, 53; 46, not_operator; 46, 47; 47, parenthesized_expression; 47, 48; 48, boolean_operator:or; 48, 49; 48, 52; 49, boolean_operator:or; 49, 50; 49, 51; 50, identifier:after; 51, identifier:before; 52, identifier:priority; 53, block; 53, 54; 54, raise_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:ValueError; 57, argument_list; 57, 58; 58, string:"depends decorator needs at least one argument"; 59, comment; 60, comment; 61, comment; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:is; 63, 64; 63, 65; 64, identifier:func; 65, None; 66, block; 66, 67; 67, return_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:partial; 70, argument_list; 70, 71; 70, 72; 70, 75; 70, 78; 71, identifier:depends; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:after; 74, identifier:after; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:before; 77, identifier:before; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:priority; 80, identifier:priority; 81, function_definition; 81, 82; 81, 83; 81, 86; 82, function_name:self_check; 83, parameters; 83, 84; 83, 85; 84, identifier:a; 85, identifier:b; 86, block; 86, 87; 87, if_statement; 87, 88; 87, 91; 88, comparison_operator:==; 88, 89; 88, 90; 89, identifier:a; 90, identifier:b; 91, block; 91, 92; 92, raise_statement; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:ValueError; 95, argument_list; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, string:"Test '{}' cannot depend on itself"; 99, identifier:format; 100, argument_list; 100, 101; 101, identifier:a; 102, function_definition; 102, 103; 102, 104; 102, 109; 103, function_name:handle_dep; 104, parameters; 104, 105; 104, 106; 105, identifier:conditions; 106, default_parameter; 106, 107; 106, 108; 107, identifier:_before; 108, True; 109, block; 109, 110; 110, if_statement; 110, 111; 110, 112; 111, identifier:conditions; 112, block; 112, 113; 112, 126; 113, if_statement; 113, 114; 113, 120; 114, comparison_operator:is; 114, 115; 114, 119; 115, call; 115, 116; 115, 117; 116, identifier:type; 117, argument_list; 117, 118; 118, identifier:conditions; 119, identifier:list; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:conditions; 124, list:[conditions]; 124, 125; 125, identifier:conditions; 126, for_statement; 126, 127; 126, 128; 126, 129; 127, identifier:cond; 128, identifier:conditions; 129, block; 129, 130; 129, 143; 129, 151; 130, if_statement; 130, 131; 130, 136; 131, call; 131, 132; 131, 133; 132, identifier:hasattr; 133, argument_list; 133, 134; 133, 135; 134, identifier:cond; 135, string:'__call__'; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:cond; 140, attribute; 140, 141; 140, 142; 141, identifier:cond; 142, identifier:__name__; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:self_check; 146, argument_list; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:func; 149, identifier:__name__; 150, identifier:cond; 151, if_statement; 151, 152; 151, 153; 151, 165; 152, identifier:_before; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 161; 156, attribute; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:soft_dependencies; 159, identifier:cond; 160, identifier:add; 161, argument_list; 161, 162; 162, attribute; 162, 163; 162, 164; 163, identifier:func; 164, identifier:__name__; 165, else_clause; 165, 166; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 176; 169, attribute; 169, 170; 169, 175; 170, subscript; 170, 171; 170, 172; 171, identifier:dependencies; 172, attribute; 172, 173; 172, 174; 173, identifier:func; 174, identifier:__name__; 175, identifier:add; 176, argument_list; 176, 177; 177, identifier:cond; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:handle_dep; 181, argument_list; 181, 182; 182, identifier:before; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:handle_dep; 186, argument_list; 186, 187; 186, 188; 187, identifier:after; 188, False; 189, if_statement; 189, 190; 189, 191; 190, identifier:priority; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 199; 194, subscript; 194, 195; 194, 196; 195, identifier:priorities; 196, attribute; 196, 197; 196, 198; 197, identifier:func; 198, identifier:__name__; 199, identifier:priority; 200, decorated_definition; 200, 201; 200, 206; 201, decorator; 201, 202; 202, call; 202, 203; 202, 204; 203, identifier:wraps; 204, argument_list; 204, 205; 205, identifier:func; 206, function_definition; 206, 207; 206, 208; 206, 213; 207, function_name:inner; 208, parameters; 208, 209; 208, 211; 209, list_splat_pattern; 209, 210; 210, identifier:args; 211, dictionary_splat_pattern; 211, 212; 212, identifier:kwargs; 213, block; 213, 214; 214, return_statement; 214, 215; 215, call; 215, 216; 215, 217; 216, identifier:func; 217, argument_list; 217, 218; 217, 220; 218, list_splat; 218, 219; 219, identifier:args; 220, dictionary_splat; 220, 221; 221, identifier:kwargs; 222, return_statement; 222, 223; 223, identifier:inner
def depends(func=None, after=None, before=None, priority=None): """Decorator to specify test dependencies :param after: The test needs to run after this/these tests. String or list of strings. :param before: The test needs to run before this/these tests. String or list of strings. """ if not (func is None or inspect.ismethod(func) or inspect.isfunction(func)): raise ValueError("depends decorator can only be used on functions or methods") if not (after or before or priority): raise ValueError("depends decorator needs at least one argument") # This avoids some nesting in the decorator # If called without func the decorator was called with optional args # so we'll return a function with those args filled in. if func is None: return partial(depends, after=after, before=before, priority=priority) def self_check(a, b): if a == b: raise ValueError("Test '{}' cannot depend on itself".format(a)) def handle_dep(conditions, _before=True): if conditions: if type(conditions) is not list: conditions = [conditions] for cond in conditions: if hasattr(cond, '__call__'): cond = cond.__name__ self_check(func.__name__, cond) if _before: soft_dependencies[cond].add(func.__name__) else: dependencies[func.__name__].add(cond) handle_dep(before) handle_dep(after, False) if priority: priorities[func.__name__] = priority @wraps(func) def inner(*args, **kwargs): return func(*args, **kwargs) return inner
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_translate_language_name; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:language_name; 6, block; 6, 7; 6, 9; 6, 17; 6, 21; 6, 22; 6, 23; 6, 48; 6, 49; 6, 50; 6, 79; 6, 104; 6, 105; 6, 106; 6, 120; 6, 136; 6, 137; 6, 138; 6, 155; 6, 162; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:languages; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:languages; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:language_id; 20, None; 21, comment; 22, comment; 23, for_statement; 23, 24; 23, 27; 23, 32; 24, pattern_list; 24, 25; 24, 26; 25, identifier:ideone_index; 26, identifier:ideone_language; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:languages; 30, identifier:items; 31, argument_list; 32, block; 32, 33; 33, if_statement; 33, 34; 33, 45; 34, comparison_operator:==; 34, 35; 34, 40; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:ideone_language; 38, identifier:lower; 39, argument_list; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:language_name; 43, identifier:lower; 44, argument_list; 45, block; 45, 46; 46, return_statement; 46, 47; 47, identifier:ideone_index; 48, comment; 49, comment; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:simple_languages; 53, call; 53, 54; 53, 55; 54, identifier:dict; 55, generator_expression; 55, 56; 55, 70; 56, tuple; 56, 57; 56, 58; 57, identifier:k; 58, call; 58, 59; 58, 69; 59, attribute; 59, 60; 59, 68; 60, subscript; 60, 61; 60, 67; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:v; 64, identifier:split; 65, argument_list; 65, 66; 66, string:'('; 67, integer:0; 68, identifier:strip; 69, argument_list; 70, for_in_clause; 70, 71; 70, 74; 71, tuple_pattern; 71, 72; 71, 73; 72, identifier:k; 73, identifier:v; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:languages; 77, identifier:items; 78, argument_list; 79, for_statement; 79, 80; 79, 83; 79, 88; 80, pattern_list; 80, 81; 80, 82; 81, identifier:ideone_index; 82, identifier:simple_name; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:simple_languages; 86, identifier:items; 87, argument_list; 88, block; 88, 89; 89, if_statement; 89, 90; 89, 101; 90, comparison_operator:==; 90, 91; 90, 96; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:simple_name; 94, identifier:lower; 95, argument_list; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:language_name; 99, identifier:lower; 100, argument_list; 101, block; 101, 102; 102, return_statement; 102, 103; 103, identifier:ideone_index; 104, comment; 105, comment; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:language_choices; 109, binary_operator:+; 109, 110; 109, 115; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:languages; 113, identifier:values; 114, argument_list; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:simple_languages; 118, identifier:values; 119, argument_list; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:similar_choices; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:difflib; 126, identifier:get_close_matches; 127, argument_list; 127, 128; 127, 129; 127, 130; 127, 133; 128, identifier:language_name; 129, identifier:language_choices; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:n; 132, integer:3; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:cutoff; 135, float:0.3; 136, comment; 137, comment; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:similar_choices_string; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, string:", "; 144, identifier:join; 145, argument_list; 145, 146; 146, list_comprehension; 146, 147; 146, 152; 147, binary_operator:+; 147, 148; 147, 151; 148, binary_operator:+; 148, 149; 148, 150; 149, string:"'"; 150, identifier:s; 151, string:"'"; 152, for_in_clause; 152, 153; 152, 154; 153, identifier:s; 154, identifier:similar_choices; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:error_string; 158, parenthesized_expression; 158, 159; 159, concatenated_string; 159, 160; 159, 161; 160, string:"Couldn't match '%s' to an Ideone accepted language.\n"; 161, string:"Did you mean one of the following: %s"; 162, raise_statement; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:IdeoneError; 165, argument_list; 165, 166; 166, binary_operator:%; 166, 167; 166, 168; 167, identifier:error_string; 168, tuple; 168, 169; 168, 170; 169, identifier:language_name; 170, identifier:similar_choices_string
def _translate_language_name(self, language_name): """ Translate a human readable langauge name into its Ideone integer representation. Keyword Arguments ----------------- * langauge_name: a string of the language (e.g. "c++") Returns ------- An integer representation of the language. Notes ----- We use a local cache of languages if available, else we grab the list of languages from Ideone. We test for a string match by comparing prefixes because Ideone includes the language compiler name and version number. Both strings are converted to lower case before the comparison. Examples -------- >>> ideone_object = Ideone('username', 'password') >>> ideone_object._translate_language_name('ada') 7 """ languages = self.languages() language_id = None # Check for exact match first including the whole version # string for ideone_index, ideone_language in languages.items(): if ideone_language.lower() == language_name.lower(): return ideone_index # Check for a match of just the language name without any # version information simple_languages = dict((k,v.split('(')[0].strip()) for (k,v) in languages.items()) for ideone_index, simple_name in simple_languages.items(): if simple_name.lower() == language_name.lower(): return ideone_index # Give up, but first find a similar name, suggest it and error # out language_choices = languages.values() + simple_languages.values() similar_choices = difflib.get_close_matches(language_name, language_choices, n=3, cutoff=0.3) # Add quotes and delimit with strings for easier to read # output similar_choices_string = ", ".join(["'" + s + "'" for s in similar_choices]) error_string = ("Couldn't match '%s' to an Ideone accepted language.\n" "Did you mean one of the following: %s") raise IdeoneError(error_string % (language_name, similar_choices_string))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:headerSortAscending; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:setSortingEnabled; 13, argument_list; 13, 14; 14, True; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:sortByColumn; 20, argument_list; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_headerIndex; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:QtCore; 27, identifier:Qt; 28, identifier:AscendingOrder
def headerSortAscending( self ): """ Sorts the column at the current header index by ascending order. """ self.setSortingEnabled(True) self.sortByColumn(self._headerIndex, QtCore.Qt.AscendingOrder)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:headerSortDescending; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:setSortingEnabled; 13, argument_list; 13, 14; 14, True; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:sortByColumn; 20, argument_list; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_headerIndex; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:QtCore; 27, identifier:Qt; 28, identifier:DescendingOrder
def headerSortDescending( self ): """ Sorts the column at the current header index by descending order. """ self.setSortingEnabled(True) self.sortByColumn(self._headerIndex, QtCore.Qt.DescendingOrder)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:from_api; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:api; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 21; 8, 97; 8, 121; 8, 154; 8, 179; 8, 186; 8, 264; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 16; 12, not_operator; 12, 13; 13, attribute; 13, 14; 13, 15; 14, identifier:cls; 15, identifier:_api_attrs; 16, block; 16, 17; 17, raise_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:NotImplementedError; 20, argument_list; 21, function_definition; 21, 22; 21, 23; 21, 25; 21, 26; 22, function_name:resolve_attribute_type; 23, parameters; 23, 24; 24, identifier:attr_type; 25, comment; 26, block; 26, 27; 26, 40; 26, 41; 26, 50; 26, 51; 26, 64; 26, 65; 26, 74; 26, 75; 26, 95; 27, while_statement; 27, 28; 27, 33; 28, call; 28, 29; 28, 30; 29, identifier:isinstance; 30, argument_list; 30, 31; 30, 32; 31, identifier:attr_type; 32, identifier:list; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:attr_type; 37, subscript; 37, 38; 37, 39; 38, identifier:attr_type; 39, integer:0; 40, comment; 41, if_statement; 41, 42; 41, 45; 42, comparison_operator:==; 42, 43; 42, 44; 43, identifier:attr_type; 44, string:'self'; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:attr_type; 49, identifier:cls; 50, comment; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:==; 52, 53; 52, 54; 53, identifier:attr_type; 54, string:'date'; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:attr_type; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:datetime; 62, identifier:datetime; 63, identifier:fromtimestamp; 64, comment; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:attr_type; 68, identifier:str; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:attr_type; 73, identifier:unicode; 74, comment; 75, if_statement; 75, 76; 75, 81; 76, call; 76, 77; 76, 78; 77, identifier:hasattr; 78, argument_list; 78, 79; 78, 80; 79, identifier:attr_type; 80, string:'from_api'; 81, block; 81, 82; 82, return_statement; 82, 83; 83, lambda; 83, 84; 83, 87; 84, lambda_parameters; 84, 85; 85, dictionary_splat_pattern; 85, 86; 86, identifier:kw; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:attr_type; 90, identifier:from_api; 91, argument_list; 91, 92; 91, 93; 92, identifier:api; 93, dictionary_splat; 93, 94; 94, identifier:kw; 95, return_statement; 95, 96; 96, identifier:attr_type; 97, function_definition; 97, 98; 97, 99; 97, 102; 98, function_name:instantiate_attr; 99, parameters; 99, 100; 99, 101; 100, identifier:attr_value; 101, identifier:attr_type; 102, block; 102, 103; 102, 116; 103, if_statement; 103, 104; 103, 109; 104, call; 104, 105; 104, 106; 105, identifier:isinstance; 106, argument_list; 106, 107; 106, 108; 107, identifier:attr_value; 108, identifier:dict; 109, block; 109, 110; 110, return_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:attr_type; 113, argument_list; 113, 114; 114, dictionary_splat; 114, 115; 115, identifier:attr_value; 116, return_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:attr_type; 119, argument_list; 119, 120; 120, identifier:attr_value; 121, function_definition; 121, 122; 121, 123; 121, 126; 122, function_name:instantiate_array; 123, parameters; 123, 124; 123, 125; 124, identifier:attr_values; 125, identifier:attr_type; 126, block; 126, 127; 126, 131; 126, 144; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:func; 130, identifier:instantiate_attr; 131, if_statement; 131, 132; 131, 139; 132, call; 132, 133; 132, 134; 133, identifier:isinstance; 134, argument_list; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:attr_values; 137, integer:0; 138, identifier:list; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:func; 143, identifier:instantiate_array; 144, return_statement; 144, 145; 145, list_comprehension; 145, 146; 145, 151; 146, call; 146, 147; 146, 148; 147, identifier:func; 148, argument_list; 148, 149; 148, 150; 149, identifier:val; 150, identifier:attr_type; 151, for_in_clause; 151, 152; 151, 153; 152, identifier:val; 153, identifier:attr_values; 154, function_definition; 154, 155; 154, 156; 154, 159; 155, function_name:instantiate; 156, parameters; 156, 157; 156, 158; 157, identifier:attr_value; 158, identifier:attr_type; 159, block; 159, 160; 159, 173; 160, if_statement; 160, 161; 160, 166; 161, call; 161, 162; 161, 163; 162, identifier:isinstance; 163, argument_list; 163, 164; 163, 165; 164, identifier:attr_value; 165, identifier:list; 166, block; 166, 167; 167, return_statement; 167, 168; 168, call; 168, 169; 168, 170; 169, identifier:instantiate_array; 170, argument_list; 170, 171; 170, 172; 171, identifier:attr_value; 172, identifier:attr_type; 173, return_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:instantiate_attr; 176, argument_list; 176, 177; 176, 178; 177, identifier:attr_value; 178, identifier:attr_type; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:instance; 182, call; 182, 183; 182, 184; 183, identifier:cls; 184, argument_list; 184, 185; 185, identifier:api; 186, for_statement; 186, 187; 186, 191; 186, 194; 186, 195; 187, pattern_list; 187, 188; 187, 189; 187, 190; 188, identifier:attr_name; 189, identifier:attr_type; 190, identifier:attr_default; 191, attribute; 191, 192; 191, 193; 192, identifier:cls; 193, identifier:_api_attrs; 194, comment; 195, block; 195, 196; 195, 206; 195, 207; 195, 225; 195, 232; 195, 233; 195, 246; 195, 247; 195, 256; 195, 257; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:attr_value; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:kwargs; 202, identifier:get; 203, argument_list; 203, 204; 203, 205; 204, identifier:attr_name; 205, identifier:attr_default; 206, comment; 207, if_statement; 207, 208; 207, 211; 208, comparison_operator:is; 208, 209; 208, 210; 209, identifier:attr_value; 210, identifier:TypeError; 211, block; 211, 212; 212, raise_statement; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:TypeError; 215, argument_list; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, string:'{} requires argument {}'; 219, identifier:format; 220, argument_list; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:cls; 223, identifier:__name__; 224, identifier:attr_name; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:attr_type; 228, call; 228, 229; 228, 230; 229, identifier:resolve_attribute_type; 230, argument_list; 230, 231; 231, identifier:attr_type; 232, comment; 233, if_statement; 233, 234; 233, 237; 234, comparison_operator:!=; 234, 235; 234, 236; 235, identifier:attr_value; 236, identifier:attr_default; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:attr_value; 241, call; 241, 242; 241, 243; 242, identifier:instantiate; 243, argument_list; 243, 244; 243, 245; 244, identifier:attr_value; 245, identifier:attr_type; 246, comment; 247, if_statement; 247, 248; 247, 251; 248, comparison_operator:==; 248, 249; 248, 250; 249, identifier:attr_name; 250, string:'from'; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:attr_name; 255, string:'froom'; 256, comment; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 260; 259, identifier:setattr; 260, argument_list; 260, 261; 260, 262; 260, 263; 261, identifier:instance; 262, identifier:attr_name; 263, identifier:attr_value; 264, return_statement; 264, 265; 265, identifier:instance
def from_api(cls, api, **kwargs): """ Parses a payload from the API, guided by `_api_attrs` """ if not cls._api_attrs: raise NotImplementedError() def resolve_attribute_type(attr_type): # resolve arrays of types down to base type while isinstance(attr_type, list): attr_type = attr_type[0] # attribute type 'self' resolves to current class if attr_type == 'self': attr_type = cls # attribute type 'date' is a unix timestamp if attr_type == 'date': attr_type = datetime.datetime.fromtimestamp # string attributes should use unicode literals if attr_type is str: attr_type = unicode # if attribute type is an APIObject, use the from_api factory method and pass the `api` argument if hasattr(attr_type, 'from_api'): return lambda **kw: attr_type.from_api(api, **kw) return attr_type def instantiate_attr(attr_value, attr_type): if isinstance(attr_value, dict): return attr_type(**attr_value) return attr_type(attr_value) def instantiate_array(attr_values, attr_type): func = instantiate_attr if isinstance(attr_values[0], list): func = instantiate_array return [func(val, attr_type) for val in attr_values] def instantiate(attr_value, attr_type): if isinstance(attr_value, list): return instantiate_array(attr_value, attr_type) return instantiate_attr(attr_value, attr_type) instance = cls(api) for attr_name, attr_type, attr_default in cls._api_attrs: # grab the current attribute value attr_value = kwargs.get(attr_name, attr_default) # default of TypeError means a required attribute, raise Exception if attr_value is TypeError: raise TypeError('{} requires argument {}'.format(cls.__name__, attr_name)) attr_type = resolve_attribute_type(attr_type) # if value has been provided from API, instantiate it using `attr_type` if attr_value != attr_default: attr_value = instantiate(attr_value, attr_type) # rename the 'from' variable, reserved word if attr_name == 'from': attr_name = 'froom' # and finally set the attribute value on the instance setattr(instance, attr_name, attr_value) return instance
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:updateEditor; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 17; 5, 25; 5, 35; 5, 39; 5, 43; 5, 56; 5, 57; 5, 105; 5, 114; 5, 115; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:rule; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:currentRule; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:operator; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:currentOperator; 24, argument_list; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:widget; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:uiWidgetAREA; 33, identifier:widget; 34, argument_list; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:editorType; 38, None; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:text; 42, string:''; 43, if_statement; 43, 44; 43, 46; 44, parenthesized_expression; 44, 45; 45, identifier:rule; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:editorType; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:rule; 53, identifier:editorType; 54, argument_list; 54, 55; 55, identifier:operator; 56, comment; 57, if_statement; 57, 58; 57, 69; 57, 71; 58, parenthesized_expression; 58, 59; 59, boolean_operator:and; 59, 60; 59, 63; 60, boolean_operator:and; 60, 61; 60, 62; 61, identifier:widget; 62, identifier:editorType; 63, comparison_operator:==; 63, 64; 63, 68; 64, call; 64, 65; 64, 66; 65, identifier:type; 66, argument_list; 66, 67; 67, identifier:widget; 68, identifier:editorType; 69, block; 69, 70; 70, return_statement; 71, elif_clause; 71, 72; 71, 74; 72, parenthesized_expression; 72, 73; 73, identifier:widget; 74, block; 74, 75; 74, 92; 74, 99; 75, if_statement; 75, 76; 75, 83; 76, parenthesized_expression; 76, 77; 77, comparison_operator:!=; 77, 78; 77, 82; 78, call; 78, 79; 78, 80; 79, identifier:type; 80, argument_list; 80, 81; 81, identifier:widget; 82, identifier:QWidget; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:text; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:widget; 90, identifier:text; 91, argument_list; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:widget; 96, identifier:setParent; 97, argument_list; 97, 98; 98, None; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:widget; 103, identifier:deleteLater; 104, argument_list; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:uiWidgetAREA; 111, identifier:setWidget; 112, argument_list; 112, 113; 113, None; 114, comment; 115, if_statement; 115, 116; 115, 118; 116, parenthesized_expression; 116, 117; 117, identifier:editorType; 118, block; 118, 119; 118, 126; 118, 182; 118, 191; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:widget; 122, call; 122, 123; 122, 124; 123, identifier:editorType; 124, argument_list; 124, 125; 125, identifier:self; 126, if_statement; 126, 127; 126, 133; 127, parenthesized_expression; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:isinstance; 130, argument_list; 130, 131; 130, 132; 131, identifier:widget; 132, identifier:QLineEdit; 133, block; 133, 134; 133, 142; 133, 167; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:terms; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:rule; 140, identifier:completionTerms; 141, argument_list; 142, if_statement; 142, 143; 142, 146; 143, parenthesized_expression; 143, 144; 144, not_operator; 144, 145; 145, identifier:terms; 146, block; 146, 147; 146, 155; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:qwidget; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:queryBuilderWidget; 154, argument_list; 155, if_statement; 155, 156; 155, 158; 156, parenthesized_expression; 156, 157; 157, identifier:qwidget; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:terms; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:qwidget; 165, identifier:completionTerms; 166, argument_list; 167, if_statement; 167, 168; 167, 170; 168, parenthesized_expression; 168, 169; 169, identifier:terms; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:widget; 175, identifier:setCompleter; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 179; 178, identifier:XQueryCompleter; 179, argument_list; 179, 180; 179, 181; 180, identifier:terms; 181, identifier:widget; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:uiWidgetAREA; 188, identifier:setWidget; 189, argument_list; 189, 190; 190, identifier:widget; 191, if_statement; 191, 192; 191, 199; 192, parenthesized_expression; 192, 193; 193, comparison_operator:!=; 193, 194; 193, 198; 194, call; 194, 195; 194, 196; 195, identifier:type; 196, argument_list; 196, 197; 197, identifier:widget; 198, identifier:QWidget; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:widget; 204, identifier:setText; 205, argument_list; 205, 206; 206, identifier:text
def updateEditor( self ): """ Updates the editor based on the current selection. """ # assignt the rule operators to the choice list rule = self.currentRule() operator = self.currentOperator() widget = self.uiWidgetAREA.widget() editorType = None text = '' if ( rule ): editorType = rule.editorType(operator) # no change in types if ( widget and editorType and type(widget) == editorType ): return elif ( widget ): if ( type(widget) != QWidget ): text = widget.text() widget.setParent(None) widget.deleteLater() self.uiWidgetAREA.setWidget(None) # create the new editor if ( editorType ): widget = editorType(self) if ( isinstance(widget, QLineEdit) ): terms = rule.completionTerms() if ( not terms ): qwidget = self.queryBuilderWidget() if ( qwidget ): terms = qwidget.completionTerms() if ( terms ): widget.setCompleter(XQueryCompleter(terms, widget)) self.uiWidgetAREA.setWidget(widget) if ( type(widget) != QWidget ): widget.setText(text)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:StreamMetrics; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:request_iterator; 6, identifier:context; 7, block; 7, 8; 7, 10; 7, 17; 7, 18; 7, 26; 7, 30; 7, 34; 7, 49; 7, 80; 7, 111; 7, 122; 7, 133; 7, 134; 7, 151; 7, 157; 7, 163; 7, 164; 7, 168; 7, 172; 7, 178; 7, 409; 7, 410; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:LOG; 14, identifier:debug; 15, argument_list; 15, 16; 16, string:"StreamMetrics called"; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:collect_args; 21, parenthesized_expression; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:next; 24, argument_list; 24, 25; 25, identifier:request_iterator; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:max_metrics_buffer; 29, integer:0; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:max_collect_duration; 33, integer:0; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:cfg; 37, call; 37, 38; 37, 39; 38, identifier:Metric; 39, argument_list; 39, 40; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:pb; 42, subscript; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:collect_args; 46, identifier:Metrics_Arg; 47, identifier:metrics; 48, integer:0; 49, try_statement; 49, 50; 49, 62; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:max_metrics_buffer; 54, call; 54, 55; 54, 56; 55, identifier:int; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:cfg; 60, identifier:config; 61, string:"max-metrics-buffer"; 62, except_clause; 62, 63; 62, 67; 63, as_pattern; 63, 64; 63, 65; 64, identifier:Exception; 65, as_pattern_target; 65, 66; 66, identifier:ex; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:LOG; 72, identifier:debug; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, string:"Unable to get schedule parameters: {}"; 77, identifier:format; 78, argument_list; 78, 79; 79, identifier:ex; 80, try_statement; 80, 81; 80, 93; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:max_collect_duration; 85, call; 85, 86; 85, 87; 86, identifier:int; 87, argument_list; 87, 88; 88, subscript; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:cfg; 91, identifier:config; 92, string:"max-collect-duration"; 93, except_clause; 93, 94; 93, 98; 94, as_pattern; 94, 95; 94, 96; 95, identifier:Exception; 96, as_pattern_target; 96, 97; 97, identifier:ex; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:LOG; 103, identifier:debug; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, string:"Unable to get schedule parameters: {}"; 108, identifier:format; 109, argument_list; 109, 110; 110, identifier:ex; 111, if_statement; 111, 112; 111, 115; 112, comparison_operator:>; 112, 113; 112, 114; 113, identifier:max_metrics_buffer; 114, integer:0; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:max_metrics_buffer; 121, identifier:max_metrics_buffer; 122, if_statement; 122, 123; 122, 126; 123, comparison_operator:>; 123, 124; 123, 125; 124, identifier:max_collect_duration; 125, integer:0; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:max_collect_duration; 132, identifier:max_collect_duration; 133, comment; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:thread; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:threading; 140, identifier:Thread; 141, argument_list; 141, 142; 141, 147; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:target; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:_stream_wrapper; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:args; 149, tuple; 149, 150; 150, identifier:collect_args; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:thread; 155, identifier:daemon; 156, True; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:thread; 161, identifier:start; 162, argument_list; 163, comment; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:metrics; 167, list:[]; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:metrics_to_stream; 171, list:[]; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:stream_timeout; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:max_collect_duration; 178, while_statement; 178, 179; 178, 184; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:context; 182, identifier:is_active; 183, argument_list; 184, block; 184, 185; 185, try_statement; 185, 186; 185, 187; 185, 229; 185, 282; 186, comment; 187, block; 187, 188; 187, 196; 187, 212; 187, 225; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:t_start; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:time; 194, identifier:time; 195, argument_list; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:metrics; 199, call; 199, 200; 199, 205; 200, attribute; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:metrics_queue; 204, identifier:get; 205, argument_list; 205, 206; 205, 209; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:block; 208, True; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:timeout; 211, identifier:stream_timeout; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:elapsed; 215, call; 215, 216; 215, 217; 216, identifier:round; 217, argument_list; 217, 218; 218, binary_operator:-; 218, 219; 218, 224; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:time; 222, identifier:time; 223, argument_list; 224, identifier:t_start; 225, expression_statement; 225, 226; 226, augmented_assignment:-=; 226, 227; 226, 228; 227, identifier:stream_timeout; 228, identifier:elapsed; 229, except_clause; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:queue; 232, identifier:Empty; 233, block; 233, 234; 233, 249; 233, 269; 233, 273; 233, 279; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:LOG; 238, identifier:debug; 239, argument_list; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, string:"Max collect duration exceeded. Streaming {} metrics"; 243, identifier:format; 244, argument_list; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:len; 247, argument_list; 247, 248; 248, identifier:metrics_to_stream; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:metrics_col; 252, call; 252, 253; 252, 254; 253, identifier:CollectReply; 254, argument_list; 254, 255; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:Metrics_Reply; 257, call; 257, 258; 257, 259; 258, identifier:MetricsReply; 259, argument_list; 259, 260; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:metrics; 262, list_comprehension; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:m; 265, identifier:pb; 266, for_in_clause; 266, 267; 266, 268; 267, identifier:m; 268, identifier:metrics_to_stream; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:metrics_to_stream; 272, list:[]; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:stream_timeout; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:max_collect_duration; 279, expression_statement; 279, 280; 280, yield; 280, 281; 281, identifier:metrics_col; 282, else_clause; 282, 283; 283, block; 283, 284; 283, 353; 283, 354; 284, for_statement; 284, 285; 284, 286; 284, 287; 285, identifier:metric; 286, identifier:metrics; 287, block; 287, 288; 287, 295; 288, expression_statement; 288, 289; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:metrics_to_stream; 292, identifier:append; 293, argument_list; 293, 294; 294, identifier:metric; 295, if_statement; 295, 296; 295, 304; 296, comparison_operator:==; 296, 297; 296, 301; 297, call; 297, 298; 297, 299; 298, identifier:len; 299, argument_list; 299, 300; 300, identifier:metrics_to_stream; 301, attribute; 301, 302; 301, 303; 302, identifier:self; 303, identifier:max_metrics_buffer; 304, block; 304, 305; 304, 320; 304, 340; 304, 344; 304, 350; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:LOG; 309, identifier:debug; 310, argument_list; 310, 311; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, string:"Max metrics buffer reached. Streaming {} metrics"; 314, identifier:format; 315, argument_list; 315, 316; 316, call; 316, 317; 316, 318; 317, identifier:len; 318, argument_list; 318, 319; 319, identifier:metrics_to_stream; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:metrics_col; 323, call; 323, 324; 323, 325; 324, identifier:CollectReply; 325, argument_list; 325, 326; 326, keyword_argument; 326, 327; 326, 328; 327, identifier:Metrics_Reply; 328, call; 328, 329; 328, 330; 329, identifier:MetricsReply; 330, argument_list; 330, 331; 331, keyword_argument; 331, 332; 331, 333; 332, identifier:metrics; 333, list_comprehension; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:m; 336, identifier:pb; 337, for_in_clause; 337, 338; 337, 339; 338, identifier:m; 339, identifier:metrics_to_stream; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:metrics_to_stream; 343, list:[]; 344, expression_statement; 344, 345; 345, assignment; 345, 346; 345, 347; 346, identifier:stream_timeout; 347, attribute; 347, 348; 347, 349; 348, identifier:self; 349, identifier:max_collect_duration; 350, expression_statement; 350, 351; 351, yield; 351, 352; 352, identifier:metrics_col; 353, comment; 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:max_metrics_buffer; 359, integer:0; 360, block; 360, 361; 360, 376; 360, 396; 360, 400; 360, 406; 361, expression_statement; 361, 362; 362, call; 362, 363; 362, 366; 363, attribute; 363, 364; 363, 365; 364, identifier:LOG; 365, identifier:debug; 366, argument_list; 366, 367; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, string:"Max metrics buffer set to 0. Streaming {} metrics"; 370, identifier:format; 371, argument_list; 371, 372; 372, call; 372, 373; 372, 374; 373, identifier:len; 374, argument_list; 374, 375; 375, identifier:metrics_to_stream; 376, expression_statement; 376, 377; 377, assignment; 377, 378; 377, 379; 378, identifier:metrics_col; 379, call; 379, 380; 379, 381; 380, identifier:CollectReply; 381, argument_list; 381, 382; 382, keyword_argument; 382, 383; 382, 384; 383, identifier:Metrics_Reply; 384, call; 384, 385; 384, 386; 385, identifier:MetricsReply; 386, argument_list; 386, 387; 387, keyword_argument; 387, 388; 387, 389; 388, identifier:metrics; 389, list_comprehension; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:m; 392, identifier:pb; 393, for_in_clause; 393, 394; 393, 395; 394, identifier:m; 395, identifier:metrics_to_stream; 396, expression_statement; 396, 397; 397, assignment; 397, 398; 397, 399; 398, identifier:metrics_to_stream; 399, list:[]; 400, expression_statement; 400, 401; 401, assignment; 401, 402; 401, 403; 402, identifier:stream_timeout; 403, attribute; 403, 404; 403, 405; 404, identifier:self; 405, identifier:max_collect_duration; 406, expression_statement; 406, 407; 407, yield; 407, 408; 408, identifier:metrics_col; 409, comment; 410, expression_statement; 410, 411; 411, call; 411, 412; 411, 417; 412, attribute; 412, 413; 412, 416; 413, attribute; 413, 414; 413, 415; 414, identifier:self; 415, identifier:done_queue; 416, identifier:put; 417, argument_list; 417, 418; 418, True
def StreamMetrics(self, request_iterator, context): """Dispatches metrics streamed by collector""" LOG.debug("StreamMetrics called") # set up arguments collect_args = (next(request_iterator)) max_metrics_buffer = 0 max_collect_duration = 0 cfg = Metric(pb=collect_args.Metrics_Arg.metrics[0]) try: max_metrics_buffer = int(cfg.config["max-metrics-buffer"]) except Exception as ex: LOG.debug("Unable to get schedule parameters: {}".format(ex)) try: max_collect_duration = int(cfg.config["max-collect-duration"]) except Exception as ex: LOG.debug("Unable to get schedule parameters: {}".format(ex)) if max_metrics_buffer > 0: self.max_metrics_buffer = max_metrics_buffer if max_collect_duration > 0: self.max_collect_duration = max_collect_duration # start collection thread thread = threading.Thread(target=self._stream_wrapper, args=(collect_args,),) thread.daemon = True thread.start() # stream metrics metrics = [] metrics_to_stream = [] stream_timeout = self.max_collect_duration while context.is_active(): try: # wait for metrics until timeout is reached t_start = time.time() metrics = self.metrics_queue.get(block=True, timeout=stream_timeout) elapsed = round(time.time() - t_start) stream_timeout -= elapsed except queue.Empty: LOG.debug("Max collect duration exceeded. Streaming {} metrics".format(len(metrics_to_stream))) metrics_col = CollectReply(Metrics_Reply=MetricsReply(metrics=[m.pb for m in metrics_to_stream])) metrics_to_stream = [] stream_timeout = self.max_collect_duration yield metrics_col else: for metric in metrics: metrics_to_stream.append(metric) if len(metrics_to_stream) == self.max_metrics_buffer: LOG.debug("Max metrics buffer reached. Streaming {} metrics".format(len(metrics_to_stream))) metrics_col = CollectReply( Metrics_Reply=MetricsReply(metrics=[m.pb for m in metrics_to_stream])) metrics_to_stream = [] stream_timeout = self.max_collect_duration yield metrics_col # stream metrics if max_metrics_buffer is 0 or enough metrics has been collected if self.max_metrics_buffer == 0: LOG.debug("Max metrics buffer set to 0. Streaming {} metrics".format(len(metrics_to_stream))) metrics_col = CollectReply(Metrics_Reply=MetricsReply(metrics=[m.pb for m in metrics_to_stream])) metrics_to_stream = [] stream_timeout = self.max_collect_duration yield metrics_col # sent notification if stream has been stopped self.done_queue.put(True)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:prepare_node; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 8; 5, 16; 5, 27; 5, 28; 5, 52; 5, 56; 5, 69; 5, 93; 5, 108; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 11; 9, not_operator; 9, 10; 10, identifier:data; 11, block; 11, 12; 12, return_statement; 12, 13; 13, expression_list; 13, 14; 13, 15; 14, None; 15, dictionary; 16, if_statement; 16, 17; 16, 22; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:data; 21, identifier:str; 22, block; 22, 23; 23, return_statement; 23, 24; 24, expression_list; 24, 25; 24, 26; 25, identifier:data; 26, dictionary; 27, comment; 28, if_statement; 28, 29; 28, 41; 29, call; 29, 30; 29, 31; 30, identifier:all; 31, generator_expression; 31, 32; 31, 35; 32, comparison_operator:in; 32, 33; 32, 34; 33, identifier:field; 34, identifier:data; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:field; 37, tuple; 37, 38; 37, 39; 37, 40; 38, string:"Node"; 39, string:"Service"; 40, string:"Checks"; 41, block; 41, 42; 42, return_statement; 42, 43; 43, expression_list; 43, 44; 43, 49; 44, subscript; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:data; 47, string:"Node"; 48, string:"Node"; 49, subscript; 49, 50; 49, 51; 50, identifier:data; 51, string:"Node"; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:result; 55, dictionary; 56, if_statement; 56, 57; 56, 60; 57, comparison_operator:in; 57, 58; 57, 59; 58, string:"ID"; 59, identifier:data; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, subscript; 63, 64; 63, 65; 64, identifier:result; 65, string:"Node"; 66, subscript; 66, 67; 66, 68; 67, identifier:data; 68, string:"ID"; 69, for_statement; 69, 70; 69, 71; 69, 79; 70, identifier:k; 71, tuple; 71, 72; 71, 73; 71, 74; 71, 75; 71, 76; 71, 77; 71, 78; 72, string:"Datacenter"; 73, string:"Node"; 74, string:"Address"; 75, string:"TaggedAddresses"; 76, string:"Service"; 77, string:"Check"; 78, string:"Checks"; 79, block; 79, 80; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:in; 81, 82; 81, 83; 82, identifier:k; 83, identifier:data; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:result; 89, identifier:k; 90, subscript; 90, 91; 90, 92; 91, identifier:data; 92, identifier:k; 93, if_statement; 93, 94; 93, 101; 94, comparison_operator:==; 94, 95; 94, 99; 95, call; 95, 96; 95, 97; 96, identifier:list; 97, argument_list; 97, 98; 98, identifier:result; 99, list:["Node"]; 99, 100; 100, string:"Node"; 101, block; 101, 102; 102, return_statement; 102, 103; 103, expression_list; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:result; 106, string:"Node"; 107, dictionary; 108, return_statement; 108, 109; 109, expression_list; 109, 110; 109, 116; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:result; 113, identifier:get; 114, argument_list; 114, 115; 115, string:"Node"; 116, identifier:result
def prepare_node(data): """Prepare node for catalog endpoint Parameters: data (Union[str, dict]): Node ID or node definition Returns: Tuple[str, dict]: where first is ID and second is node definition Extract from /v1/health/service/<service>:: { "Node": { "Node": "foobar", "Address": "10.1.10.12", "TaggedAddresses": { "lan": "10.1.10.12", "wan": "10.1.10.12" } }, "Service": {...}, "Checks": [...] } """ if not data: return None, {} if isinstance(data, str): return data, {} # from /v1/health/service/<service> if all(field in data for field in ("Node", "Service", "Checks")): return data["Node"]["Node"], data["Node"] result = {} if "ID" in data: result["Node"] = data["ID"] for k in ("Datacenter", "Node", "Address", "TaggedAddresses", "Service", "Check", "Checks"): if k in data: result[k] = data[k] if list(result) == ["Node"]: return result["Node"], {} return result.get("Node"), result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:prepare_service; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 8; 5, 16; 5, 27; 5, 28; 5, 52; 5, 53; 5, 54; 5, 55; 5, 56; 5, 109; 5, 124; 5, 128; 5, 141; 5, 163; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 11; 9, not_operator; 9, 10; 10, identifier:data; 11, block; 11, 12; 12, return_statement; 12, 13; 13, expression_list; 13, 14; 13, 15; 14, None; 15, dictionary; 16, if_statement; 16, 17; 16, 22; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:data; 21, identifier:str; 22, block; 22, 23; 23, return_statement; 23, 24; 24, expression_list; 24, 25; 24, 26; 25, identifier:data; 26, dictionary; 27, comment; 28, if_statement; 28, 29; 28, 41; 29, call; 29, 30; 29, 31; 30, identifier:all; 31, generator_expression; 31, 32; 31, 35; 32, comparison_operator:in; 32, 33; 32, 34; 33, identifier:field; 34, identifier:data; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:field; 37, tuple; 37, 38; 37, 39; 37, 40; 38, string:"Node"; 39, string:"Service"; 40, string:"Checks"; 41, block; 41, 42; 42, return_statement; 42, 43; 43, expression_list; 43, 44; 43, 49; 44, subscript; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:data; 47, string:"Service"; 48, string:"ID"; 49, subscript; 49, 50; 49, 51; 50, identifier:data; 51, string:"Service"; 52, comment; 53, comment; 54, comment; 55, comment; 56, if_statement; 56, 57; 56, 68; 57, call; 57, 58; 57, 59; 58, identifier:all; 59, generator_expression; 59, 60; 59, 63; 60, comparison_operator:in; 60, 61; 60, 62; 61, identifier:field; 62, identifier:data; 63, for_in_clause; 63, 64; 63, 65; 64, identifier:field; 65, tuple; 65, 66; 65, 67; 66, string:"ServiceName"; 67, string:"ServiceID"; 68, block; 68, 69; 69, return_statement; 69, 70; 70, expression_list; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:data; 73, string:"ServiceID"; 74, dictionary; 74, 75; 74, 80; 74, 85; 74, 93; 74, 101; 75, pair; 75, 76; 75, 77; 76, string:"ID"; 77, subscript; 77, 78; 77, 79; 78, identifier:data; 79, string:"ServiceID"; 80, pair; 80, 81; 80, 82; 81, string:"Service"; 82, subscript; 82, 83; 82, 84; 83, identifier:data; 84, string:"ServiceName"; 85, pair; 85, 86; 85, 87; 86, string:"Tags"; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:data; 90, identifier:get; 91, argument_list; 91, 92; 92, string:"ServiceTags"; 93, pair; 93, 94; 93, 95; 94, string:"Address"; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:data; 98, identifier:get; 99, argument_list; 99, 100; 100, string:"ServiceAddress"; 101, pair; 101, 102; 101, 103; 102, string:"Port"; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:data; 106, identifier:get; 107, argument_list; 107, 108; 108, string:"ServicePort"; 109, if_statement; 109, 110; 109, 117; 110, comparison_operator:==; 110, 111; 110, 115; 111, call; 111, 112; 111, 113; 112, identifier:list; 113, argument_list; 113, 114; 114, identifier:data; 115, list:["ID"]; 115, 116; 116, string:"ID"; 117, block; 117, 118; 118, return_statement; 118, 119; 119, expression_list; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:data; 122, string:"ID"; 123, dictionary; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:result; 127, dictionary; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:in; 129, 130; 129, 131; 130, string:"Name"; 131, identifier:data; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:result; 137, string:"Service"; 138, subscript; 138, 139; 138, 140; 139, identifier:data; 140, string:"Name"; 141, for_statement; 141, 142; 141, 143; 141, 149; 142, identifier:k; 143, tuple; 143, 144; 143, 145; 143, 146; 143, 147; 143, 148; 144, string:"Service"; 145, string:"ID"; 146, string:"Tags"; 147, string:"Address"; 148, string:"Port"; 149, block; 149, 150; 150, if_statement; 150, 151; 150, 154; 151, comparison_operator:in; 151, 152; 151, 153; 152, identifier:k; 153, identifier:data; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:result; 159, identifier:k; 160, subscript; 160, 161; 160, 162; 161, identifier:data; 162, identifier:k; 163, return_statement; 163, 164; 164, expression_list; 164, 165; 164, 171; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:result; 168, identifier:get; 169, argument_list; 169, 170; 170, string:"ID"; 171, identifier:result
def prepare_service(data): """Prepare service for catalog endpoint Parameters: data (Union[str, dict]): Service ID or service definition Returns: Tuple[str, dict]: str is ID and dict is service Transform ``/v1/health/state/<state>``:: { "Node": "foobar", "CheckID": "service:redis", "Name": "Service 'redis' check", "Status": "passing", "Notes": "", "Output": "", "ServiceID": "redis1", "ServiceName": "redis" } to:: { "ID": "redis1", "Service": "redis" } Extract from /v1/health/service/<service>:: { "Node": {...}, "Service": { "ID": "redis1", "Service": "redis", "Tags": None, "Address": "10.1.10.12", "Port": 8000 }, "Checks": [...] } """ if not data: return None, {} if isinstance(data, str): return data, {} # from /v1/health/service/<service> if all(field in data for field in ("Node", "Service", "Checks")): return data["Service"]["ID"], data["Service"] # from /v1/health/checks/<service> # from /v1/health/node/<node> # from /v1/health/state/<state> # from /v1/catalog/service/<service> if all(field in data for field in ("ServiceName", "ServiceID")): return data["ServiceID"], { "ID": data["ServiceID"], "Service": data["ServiceName"], "Tags": data.get("ServiceTags"), "Address": data.get("ServiceAddress"), "Port": data.get("ServicePort"), } if list(data) == ["ID"]: return data["ID"], {} result = {} if "Name" in data: result["Service"] = data["Name"] for k in ("Service", "ID", "Tags", "Address", "Port"): if k in data: result[k] = data[k] return result.get("ID"), result
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:add_measurement; 3, parameters; 3, 4; 4, identifier:measurement; 5, block; 5, 6; 5, 8; 5, 10; 5, 25; 5, 39; 5, 52; 5, 63; 5, 78; 5, 86; 5, 97; 5, 98; 5, 119; 5, 120; 5, 126; 6, expression_statement; 6, 7; 7, comment; 8, global_statement; 8, 9; 9, identifier:_buffer_size; 10, if_statement; 10, 11; 10, 13; 11, not_operator; 11, 12; 12, identifier:_enabled; 13, block; 13, 14; 13, 24; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:LOGGER; 18, identifier:debug; 19, argument_list; 19, 20; 19, 21; 20, string:'Discarding measurement for %s while not enabled'; 21, attribute; 21, 22; 21, 23; 22, identifier:measurement; 23, identifier:database; 24, return_statement; 25, if_statement; 25, 26; 25, 27; 26, identifier:_stopping; 27, block; 27, 28; 27, 38; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:LOGGER; 32, identifier:warning; 33, argument_list; 33, 34; 33, 35; 34, string:'Discarding measurement for %s while stopping'; 35, attribute; 35, 36; 35, 37; 36, identifier:measurement; 37, identifier:database; 38, return_statement; 39, if_statement; 39, 40; 39, 43; 40, comparison_operator:>; 40, 41; 40, 42; 41, identifier:_buffer_size; 42, identifier:_max_buffer_size; 43, block; 43, 44; 43, 51; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:LOGGER; 48, identifier:warning; 49, argument_list; 49, 50; 50, string:'Discarding measurement due to buffer size limit'; 51, return_statement; 52, if_statement; 52, 53; 52, 57; 53, not_operator; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:measurement; 56, identifier:fields; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:ValueError; 61, argument_list; 61, 62; 62, string:'Measurement does not contain a field'; 63, if_statement; 63, 64; 63, 69; 64, comparison_operator:not; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:measurement; 67, identifier:database; 68, identifier:_measurements; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 77; 72, subscript; 72, 73; 72, 74; 73, identifier:_measurements; 74, attribute; 74, 75; 74, 76; 75, identifier:measurement; 76, identifier:database; 77, list:[]; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:value; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:measurement; 84, identifier:marshall; 85, argument_list; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 95; 88, attribute; 88, 89; 88, 94; 89, subscript; 89, 90; 89, 91; 90, identifier:_measurements; 91, attribute; 91, 92; 91, 93; 92, identifier:measurement; 93, identifier:database; 94, identifier:append; 95, argument_list; 95, 96; 96, identifier:value; 97, comment; 98, if_statement; 98, 99; 98, 101; 99, not_operator; 99, 100; 100, identifier:_timeout; 101, block; 101, 102; 102, if_statement; 102, 103; 102, 114; 103, boolean_operator:or; 103, 104; 103, 112; 104, parenthesized_expression; 104, 105; 105, boolean_operator:and; 105, 106; 105, 107; 106, identifier:_batch_future; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:_batch_future; 110, identifier:done; 111, argument_list; 112, not_operator; 112, 113; 113, identifier:_batch_future; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:_start_timeout; 118, argument_list; 119, comment; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:_buffer_size; 123, call; 123, 124; 123, 125; 124, identifier:_pending_measurements; 125, argument_list; 126, if_statement; 126, 127; 126, 130; 127, comparison_operator:>=; 127, 128; 127, 129; 128, identifier:_buffer_size; 129, identifier:_trigger_size; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:_trigger_batch_write; 134, argument_list
def add_measurement(measurement): """Add measurement data to the submission buffer for eventual writing to InfluxDB. Example: .. code:: python import sprockets_influxdb as influxdb measurement = influxdb.Measurement('example', 'measurement-name') measurement.set_tag('foo', 'bar') measurement.set_field('baz', 1.05) influxdb.add_measurement(measurement) :param :class:`~sprockets_influxdb.Measurement` measurement: The measurement to add to the buffer for submission to InfluxDB. """ global _buffer_size if not _enabled: LOGGER.debug('Discarding measurement for %s while not enabled', measurement.database) return if _stopping: LOGGER.warning('Discarding measurement for %s while stopping', measurement.database) return if _buffer_size > _max_buffer_size: LOGGER.warning('Discarding measurement due to buffer size limit') return if not measurement.fields: raise ValueError('Measurement does not contain a field') if measurement.database not in _measurements: _measurements[measurement.database] = [] value = measurement.marshall() _measurements[measurement.database].append(value) # Ensure that len(measurements) < _trigger_size are written if not _timeout: if (_batch_future and _batch_future.done()) or not _batch_future: _start_timeout() # Check to see if the batch should be triggered _buffer_size = _pending_measurements() if _buffer_size >= _trigger_size: _trigger_batch_write()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:refresh; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:reloadData; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:force; 10, False; 11, block; 11, 12; 11, 14; 11, 34; 11, 42; 11, 51; 11, 52; 11, 60; 11, 70; 11, 83; 11, 84; 11, 92; 11, 107; 11, 122; 11, 123; 11, 174; 11, 175; 11, 200; 11, 201; 11, 217; 11, 218; 11, 247; 11, 260; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 24; 15, not_operator; 15, 16; 16, parenthesized_expression; 16, 17; 17, boolean_operator:or; 17, 18; 17, 23; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:isVisible; 22, argument_list; 23, identifier:force; 24, block; 24, 25; 24, 33; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_refreshTimer; 31, identifier:start; 32, argument_list; 33, return_statement; 34, if_statement; 34, 35; 34, 40; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:isLoading; 39, argument_list; 40, block; 40, 41; 41, return_statement; 42, if_statement; 42, 43; 42, 44; 43, identifier:reloadData; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:refreshQueryRecords; 50, argument_list; 51, comment; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:_refreshTimer; 58, identifier:stop; 59, argument_list; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 69; 62, attribute; 62, 63; 62, 68; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:worker; 67, argument_list; 68, identifier:cancel; 69, argument_list; 70, if_statement; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_popup; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:_popup; 81, identifier:close; 82, argument_list; 83, comment; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:currset; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:currentRecordSet; 91, argument_list; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 101; 94, attribute; 94, 95; 94, 100; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:worker; 99, argument_list; 100, identifier:setBatched; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:isPaged; 106, argument_list; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 116; 109, attribute; 109, 110; 109, 115; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:worker; 114, argument_list; 115, identifier:setBatchSize; 116, argument_list; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:pageSize; 121, argument_list; 122, comment; 123, if_statement; 123, 124; 123, 127; 123, 139; 123, 140; 123, 164; 123, 165; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:_searchTerms; 127, block; 127, 128; 127, 135; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:currset; 132, identifier:setGroupBy; 133, argument_list; 133, 134; 134, None; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:pageSize; 138, integer:0; 139, comment; 140, elif_clause; 140, 141; 140, 152; 141, boolean_operator:and; 141, 142; 141, 147; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:groupBy; 146, argument_list; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:isGroupingActive; 151, argument_list; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:currset; 157, identifier:setGroupBy; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:groupBy; 163, argument_list; 164, comment; 165, else_clause; 165, 166; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:currset; 171, identifier:setGroupBy; 172, argument_list; 172, 173; 173, None; 174, comment; 175, if_statement; 175, 176; 175, 181; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:order; 180, argument_list; 181, block; 181, 182; 181, 189; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:currset; 186, identifier:setOrdered; 187, argument_list; 187, 188; 188, True; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:currset; 193, identifier:setOrder; 194, argument_list; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:order; 199, argument_list; 200, comment; 201, if_statement; 201, 202; 201, 207; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:useLoader; 206, argument_list; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:loader; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:XLoaderWidget; 214, identifier:start; 215, argument_list; 215, 216; 216, identifier:self; 217, comment; 218, if_statement; 218, 219; 218, 224; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:specifiedColumnsOnly; 223, argument_list; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:currset; 229, identifier:setColumns; 230, argument_list; 230, 231; 231, call; 231, 232; 231, 233; 232, identifier:map; 233, argument_list; 233, 234; 233, 242; 234, lambda; 234, 235; 234, 237; 235, lambda_parameters; 235, 236; 236, identifier:x; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:x; 240, identifier:name; 241, argument_list; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:specifiedColumns; 246, argument_list; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:_loadedColumns; 252, call; 252, 253; 252, 254; 253, identifier:set; 254, argument_list; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:visibleColumns; 259, argument_list; 260, if_statement; 260, 261; 260, 272; 260, 295; 261, boolean_operator:and; 261, 262; 261, 267; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:isThreadEnabled; 266, argument_list; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:currset; 270, identifier:isThreadEnabled; 271, argument_list; 272, block; 272, 273; 272, 286; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 282; 275, attribute; 275, 276; 275, 281; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:self; 279, identifier:worker; 280, argument_list; 281, identifier:setPreloadColumns; 282, argument_list; 282, 283; 283, attribute; 283, 284; 283, 285; 284, identifier:self; 285, identifier:_preloadColumns; 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:loadRequested; 292, identifier:emit; 293, argument_list; 293, 294; 294, identifier:currset; 295, else_clause; 295, 296; 296, block; 296, 297; 296, 306; 296, 317; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:QApplication; 301, identifier:setOverrideCursor; 302, argument_list; 302, 303; 303, attribute; 303, 304; 303, 305; 304, identifier:Qt; 305, identifier:WaitCursor; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 315; 308, attribute; 308, 309; 308, 314; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:self; 312, identifier:worker; 313, argument_list; 314, identifier:loadRecords; 315, argument_list; 315, 316; 316, identifier:currset; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:QApplication; 321, identifier:restoreOverrideCursor; 322, argument_list
def refresh(self, reloadData=False, force=False): """ Refreshes the record list for the tree. """ if not (self.isVisible() or force): self._refreshTimer.start() return if self.isLoading(): return if reloadData: self.refreshQueryRecords() # cancel current work self._refreshTimer.stop() self.worker().cancel() if self._popup: self._popup.close() # grab the record set currset = self.currentRecordSet() self.worker().setBatched(self.isPaged()) self.worker().setBatchSize(self.pageSize()) # group the information if self._searchTerms: currset.setGroupBy(None) pageSize = 0 # work with groups elif self.groupBy() and self.isGroupingActive(): currset.setGroupBy(self.groupBy()) # work with batching else: currset.setGroupBy(None) # order the information if self.order(): currset.setOrdered(True) currset.setOrder(self.order()) # for larger queries, run it through the thread if self.useLoader(): loader = XLoaderWidget.start(self) # specify the columns to load if self.specifiedColumnsOnly(): currset.setColumns(map(lambda x: x.name(), self.specifiedColumns())) self._loadedColumns = set(self.visibleColumns()) if self.isThreadEnabled() and currset.isThreadEnabled(): self.worker().setPreloadColumns(self._preloadColumns) self.loadRequested.emit(currset) else: QApplication.setOverrideCursor(Qt.WaitCursor) self.worker().loadRecords(currset) QApplication.restoreOverrideCursor()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 1, 30; 2, function_name:tornado_run; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:app; 5, default_parameter; 5, 6; 5, 7; 6, identifier:port; 7, integer:5000; 8, default_parameter; 8, 9; 8, 10; 9, identifier:address; 10, string:""; 11, default_parameter; 11, 12; 11, 13; 12, identifier:use_gevent; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:start; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:monkey_patch; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:Container; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:Server; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:threadpool; 28, None; 29, comment; 30, block; 30, 31; 30, 33; 30, 48; 30, 63; 30, 72; 30, 76; 30, 139; 30, 208; 30, 218; 30, 226; 30, 233; 31, expression_statement; 31, 32; 32, comment; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:Container; 36, None; 37, block; 37, 38; 37, 44; 38, import_from_statement; 38, 39; 38, 42; 39, dotted_name; 39, 40; 39, 41; 40, identifier:tornado; 41, identifier:wsgi; 42, dotted_name; 42, 43; 43, identifier:WSGIContainer; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:Container; 47, identifier:WSGIContainer; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:is; 49, 50; 49, 51; 50, identifier:Server; 51, None; 52, block; 52, 53; 52, 59; 53, import_from_statement; 53, 54; 53, 57; 54, dotted_name; 54, 55; 54, 56; 55, identifier:tornado; 56, identifier:httpserver; 57, dotted_name; 57, 58; 58, identifier:HTTPServer; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:Server; 62, identifier:HTTPServer; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:monkey_patch; 66, None; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:monkey_patch; 71, identifier:use_gevent; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:CustomWSGIContainer; 75, identifier:Container; 76, if_statement; 76, 77; 76, 78; 77, identifier:use_gevent; 78, block; 78, 79; 78, 93; 78, 96; 78, 135; 79, if_statement; 79, 80; 79, 81; 80, identifier:monkey_patch; 81, block; 81, 82; 81, 87; 82, import_from_statement; 82, 83; 82, 85; 83, dotted_name; 83, 84; 84, identifier:gevent; 85, dotted_name; 85, 86; 86, identifier:monkey; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:monkey; 91, identifier:patch_all; 92, argument_list; 93, import_statement; 93, 94; 94, dotted_name; 94, 95; 95, identifier:gevent; 96, class_definition; 96, 97; 96, 98; 96, 100; 97, identifier:GeventWSGIContainer; 98, argument_list; 98, 99; 99, identifier:Container; 100, block; 100, 101; 101, function_definition; 101, 102; 101, 103; 101, 109; 102, function_name:__call__; 103, parameters; 103, 104; 103, 105; 103, 107; 104, identifier:self; 105, list_splat_pattern; 105, 106; 106, identifier:args; 107, dictionary_splat_pattern; 107, 108; 108, identifier:kwargs; 109, block; 109, 110; 109, 128; 110, function_definition; 110, 111; 110, 112; 110, 113; 111, function_name:async_task; 112, parameters; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 123; 116, attribute; 116, 117; 116, 122; 117, call; 117, 118; 117, 119; 118, identifier:super; 119, argument_list; 119, 120; 119, 121; 120, identifier:GeventWSGIContainer; 121, identifier:self; 122, identifier:__call__; 123, argument_list; 123, 124; 123, 126; 124, list_splat; 124, 125; 125, identifier:args; 126, dictionary_splat; 126, 127; 127, identifier:kwargs; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:gevent; 132, identifier:spawn; 133, argument_list; 133, 134; 134, identifier:async_task; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:CustomWSGIContainer; 138, identifier:GeventWSGIContainer; 139, if_statement; 139, 140; 139, 143; 140, comparison_operator:is; 140, 141; 140, 142; 141, identifier:threadpool; 142, None; 143, block; 143, 144; 143, 150; 143, 165; 143, 204; 144, import_from_statement; 144, 145; 144, 148; 145, dotted_name; 145, 146; 145, 147; 146, identifier:multiprocessing; 147, identifier:pool; 148, dotted_name; 148, 149; 149, identifier:ThreadPool; 150, if_statement; 150, 151; 150, 157; 151, not_operator; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:isinstance; 154, argument_list; 154, 155; 154, 156; 155, identifier:threadpool; 156, identifier:ThreadPool; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:threadpool; 161, call; 161, 162; 161, 163; 162, identifier:ThreadPool; 163, argument_list; 163, 164; 164, identifier:threadpool; 165, class_definition; 165, 166; 165, 167; 165, 169; 166, identifier:ThreadPoolWSGIContainer; 167, argument_list; 167, 168; 168, identifier:Container; 169, block; 169, 170; 170, function_definition; 170, 171; 170, 172; 170, 178; 171, function_name:__call__; 172, parameters; 172, 173; 172, 174; 172, 176; 173, identifier:self; 174, list_splat_pattern; 174, 175; 175, identifier:args; 176, dictionary_splat_pattern; 176, 177; 177, identifier:kwargs; 178, block; 178, 179; 178, 197; 179, function_definition; 179, 180; 179, 181; 179, 182; 180, function_name:async_task; 181, parameters; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 192; 185, attribute; 185, 186; 185, 191; 186, call; 186, 187; 186, 188; 187, identifier:super; 188, argument_list; 188, 189; 188, 190; 189, identifier:ThreadPoolWSGIContainer; 190, identifier:self; 191, identifier:__call__; 192, argument_list; 192, 193; 192, 195; 193, list_splat; 193, 194; 194, identifier:args; 195, dictionary_splat; 195, 196; 196, identifier:kwargs; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:threadpool; 201, identifier:apply_async; 202, argument_list; 202, 203; 203, identifier:async_task; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:CustomWSGIContainer; 207, identifier:ThreadPoolWSGIContainer; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:http_server; 211, call; 211, 212; 211, 213; 212, identifier:Server; 213, argument_list; 213, 214; 214, call; 214, 215; 214, 216; 215, identifier:CustomWSGIContainer; 216, argument_list; 216, 217; 217, identifier:app; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:http_server; 222, identifier:listen; 223, argument_list; 223, 224; 223, 225; 224, identifier:port; 225, identifier:address; 226, if_statement; 226, 227; 226, 228; 227, identifier:start; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 232; 231, identifier:tornado_start; 232, argument_list; 233, return_statement; 233, 234; 234, identifier:http_server
def tornado_run(app, port=5000, address="", use_gevent=False, start=True, monkey_patch=None, Container=None, Server=None, threadpool=None): # pragma: no cover """Run your app in one tornado event loop process :param app: wsgi application, Microservice instance :param port: port for listen, int, default: 5000 :param address: address for listen, str, default: "" :param use_gevent: if True, app.wsgi will be run in gevent.spawn :param start: if True, will be call utils.tornado_start() :param Container: your class, bases on tornado.wsgi.WSGIContainer, default: tornado.wsgi.WSGIContainer :param monkey_patch: boolean, use gevent.monkey.patch_all() for patching standard modules, default: use_gevent :param Server: your class, bases on tornado.httpserver.HTTPServer, default: tornado.httpserver.HTTPServer :return: tornado server """ if Container is None: from tornado.wsgi import WSGIContainer Container = WSGIContainer if Server is None: from tornado.httpserver import HTTPServer Server = HTTPServer if monkey_patch is None: monkey_patch = use_gevent CustomWSGIContainer = Container if use_gevent: if monkey_patch: from gevent import monkey monkey.patch_all() import gevent class GeventWSGIContainer(Container): def __call__(self, *args, **kwargs): def async_task(): super(GeventWSGIContainer, self).__call__(*args, **kwargs) gevent.spawn(async_task) CustomWSGIContainer = GeventWSGIContainer if threadpool is not None: from multiprocessing.pool import ThreadPool if not isinstance(threadpool, ThreadPool): threadpool = ThreadPool(threadpool) class ThreadPoolWSGIContainer(Container): def __call__(self, *args, **kwargs): def async_task(): super(ThreadPoolWSGIContainer, self).__call__(*args, **kwargs) threadpool.apply_async(async_task) CustomWSGIContainer = ThreadPoolWSGIContainer http_server = Server(CustomWSGIContainer(app)) http_server.listen(port, address) if start: tornado_start() return http_server
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 1, 24; 2, function_name:tornado_combiner; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:configs; 5, default_parameter; 5, 6; 5, 7; 6, identifier:use_gevent; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:start; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:monkey_patch; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:Container; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:Server; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:threadpool; 22, None; 23, comment; 24, block; 24, 25; 24, 27; 24, 31; 24, 40; 24, 57; 24, 83; 24, 151; 24, 158; 25, expression_statement; 25, 26; 26, comment; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:servers; 30, list:[]; 31, if_statement; 31, 32; 31, 35; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:monkey_patch; 34, None; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:monkey_patch; 39, identifier:use_gevent; 40, if_statement; 40, 41; 40, 42; 41, identifier:use_gevent; 42, block; 42, 43; 43, if_statement; 43, 44; 43, 45; 44, identifier:monkey_patch; 45, block; 45, 46; 45, 51; 46, import_from_statement; 46, 47; 46, 49; 47, dotted_name; 47, 48; 48, identifier:gevent; 49, dotted_name; 49, 50; 50, identifier:monkey; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:monkey; 55, identifier:patch_all; 56, argument_list; 57, if_statement; 57, 58; 57, 61; 58, comparison_operator:is; 58, 59; 58, 60; 59, identifier:threadpool; 60, None; 61, block; 61, 62; 61, 68; 62, import_from_statement; 62, 63; 62, 66; 63, dotted_name; 63, 64; 63, 65; 64, identifier:multiprocessing; 65, identifier:pool; 66, dotted_name; 66, 67; 67, identifier:ThreadPool; 68, if_statement; 68, 69; 68, 75; 69, not_operator; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:isinstance; 72, argument_list; 72, 73; 72, 74; 73, identifier:threadpool; 74, identifier:ThreadPool; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:threadpool; 79, call; 79, 80; 79, 81; 80, identifier:ThreadPool; 81, argument_list; 81, 82; 82, identifier:threadpool; 83, for_statement; 83, 84; 83, 85; 83, 86; 84, identifier:config; 85, identifier:configs; 86, block; 86, 87; 86, 93; 86, 103; 86, 113; 86, 144; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:app; 90, subscript; 90, 91; 90, 92; 91, identifier:config; 92, string:'app'; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:port; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:config; 99, identifier:get; 100, argument_list; 100, 101; 100, 102; 101, string:'port'; 102, integer:5000; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:address; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:config; 109, identifier:get; 110, argument_list; 110, 111; 110, 112; 111, string:'address'; 112, string:''; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:server; 116, call; 116, 117; 116, 118; 117, identifier:tornado_run; 118, argument_list; 118, 119; 118, 120; 118, 123; 118, 126; 118, 129; 118, 132; 118, 135; 118, 138; 118, 141; 119, identifier:app; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:use_gevent; 122, identifier:use_gevent; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:port; 125, identifier:port; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:monkey_patch; 128, False; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:address; 131, identifier:address; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:start; 134, False; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:Container; 137, identifier:Container; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:Server; 140, identifier:Server; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:threadpool; 143, identifier:threadpool; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:servers; 148, identifier:append; 149, argument_list; 149, 150; 150, identifier:server; 151, if_statement; 151, 152; 151, 153; 152, identifier:start; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:tornado_start; 157, argument_list; 158, return_statement; 158, 159; 159, identifier:servers
def tornado_combiner(configs, use_gevent=False, start=True, monkey_patch=None, Container=None, Server=None, threadpool=None): # pragma: no cover """Combine servers in one tornado event loop process :param configs: [ { 'app': Microservice Application or another wsgi application, required 'port': int, default: 5000 'address': str, default: "" }, { ... } ] :param use_gevent: if True, app.wsgi will be run in gevent.spawn :param start: if True, will be call utils.tornado_start() :param Container: your class, bases on tornado.wsgi.WSGIContainer, default: tornado.wsgi.WSGIContainer :param Server: your class, bases on tornado.httpserver.HTTPServer, default: tornado.httpserver.HTTPServer :param monkey_patch: boolean, use gevent.monkey.patch_all() for patching standard modules, default: use_gevent :return: list of tornado servers """ servers = [] if monkey_patch is None: monkey_patch = use_gevent if use_gevent: if monkey_patch: from gevent import monkey monkey.patch_all() if threadpool is not None: from multiprocessing.pool import ThreadPool if not isinstance(threadpool, ThreadPool): threadpool = ThreadPool(threadpool) for config in configs: app = config['app'] port = config.get('port', 5000) address = config.get('address', '') server = tornado_run(app, use_gevent=use_gevent, port=port, monkey_patch=False, address=address, start=False, Container=Container, Server=Server, threadpool=threadpool) servers.append(server) if start: tornado_start() return servers
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:rebuild; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 26; 5, 33; 5, 43; 5, 49; 5, 57; 5, 95; 5, 96; 5, 104; 5, 112; 5, 119; 5, 126; 5, 133; 5, 142; 5, 153; 5, 164; 5, 168; 5, 177; 5, 185; 5, 186; 5, 225; 5, 226; 5, 233; 5, 457; 5, 496; 5, 503; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:navitem; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:currentItem; 15, argument_list; 16, if_statement; 16, 17; 16, 19; 17, parenthesized_expression; 17, 18; 18, identifier:navitem; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:navitem; 24, identifier:initialize; 25, argument_list; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:setUpdatesEnabled; 31, argument_list; 31, 32; 32, False; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 42; 35, attribute; 35, 36; 35, 41; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:scrollWidget; 40, argument_list; 41, identifier:show; 42, argument_list; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:_originalText; 48, string:''; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:partsw; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:partsWidget; 56, argument_list; 57, for_statement; 57, 58; 57, 59; 57, 66; 58, identifier:button; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:_buttonGroup; 64, identifier:buttons; 65, argument_list; 66, block; 66, 67; 66, 76; 66, 82; 66, 89; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:_buttonGroup; 73, identifier:removeButton; 74, argument_list; 74, 75; 75, identifier:button; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:button; 80, identifier:close; 81, argument_list; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:button; 86, identifier:setParent; 87, argument_list; 87, 88; 88, None; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:button; 93, identifier:deleteLater; 94, argument_list; 95, comment; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:layout; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:partsw; 102, identifier:layout; 103, argument_list; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:parts; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:parts; 111, argument_list; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:button; 115, call; 115, 116; 115, 117; 116, identifier:QToolButton; 117, argument_list; 117, 118; 118, identifier:partsw; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:button; 123, identifier:setAutoRaise; 124, argument_list; 124, 125; 125, True; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:button; 130, identifier:setMaximumWidth; 131, argument_list; 131, 132; 132, integer:12; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:button; 137, identifier:setArrowType; 138, argument_list; 138, 139; 139, attribute; 139, 140; 139, 141; 140, identifier:Qt; 141, identifier:RightArrow; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:button; 146, identifier:setProperty; 147, argument_list; 147, 148; 147, 149; 148, string:'path'; 149, call; 149, 150; 149, 151; 150, identifier:wrapVariant; 151, argument_list; 151, 152; 152, string:''; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:button; 157, identifier:setProperty; 158, argument_list; 158, 159; 158, 160; 159, string:'is_completer'; 160, call; 160, 161; 160, 162; 161, identifier:wrapVariant; 162, argument_list; 162, 163; 163, True; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:last_button; 167, identifier:button; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 175; 170, attribute; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:_buttonGroup; 174, identifier:addButton; 175, argument_list; 175, 176; 176, identifier:button; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:layout; 181, identifier:insertWidget; 182, argument_list; 182, 183; 182, 184; 183, integer:0; 184, identifier:button; 185, comment; 186, if_statement; 186, 187; 186, 191; 186, 219; 187, parenthesized_expression; 187, 188; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:_navigationModel; 191, block; 191, 192; 191, 207; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:last_item; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:_navigationModel; 200, identifier:itemByPath; 201, argument_list; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:text; 206, argument_list; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:show_last; 210, boolean_operator:and; 210, 211; 210, 212; 211, identifier:last_item; 212, comparison_operator:>; 212, 213; 212, 218; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:last_item; 216, identifier:rowCount; 217, argument_list; 218, integer:0; 219, else_clause; 219, 220; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:show_last; 224, False; 225, comment; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:count; 229, call; 229, 230; 229, 231; 230, identifier:len; 231, argument_list; 231, 232; 232, identifier:parts; 233, for_statement; 233, 234; 233, 237; 233, 241; 234, pattern_list; 234, 235; 234, 236; 235, identifier:i; 236, identifier:part; 237, call; 237, 238; 237, 239; 238, identifier:enumerate; 239, argument_list; 239, 240; 240, identifier:parts; 241, block; 241, 242; 241, 261; 241, 268; 241, 275; 241, 282; 241, 323; 241, 334; 241, 345; 241, 354; 241, 367; 241, 368; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:path; 245, call; 245, 246; 245, 253; 246, attribute; 246, 247; 246, 252; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:separator; 251, argument_list; 252, identifier:join; 253, argument_list; 253, 254; 254, subscript; 254, 255; 254, 256; 255, identifier:parts; 256, slice; 256, 257; 256, 258; 257, colon; 258, binary_operator:+; 258, 259; 258, 260; 259, identifier:i; 260, integer:1; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:button; 264, call; 264, 265; 264, 266; 265, identifier:QToolButton; 266, argument_list; 266, 267; 267, identifier:partsw; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:button; 272, identifier:setAutoRaise; 273, argument_list; 273, 274; 274, True; 275, expression_statement; 275, 276; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:button; 279, identifier:setText; 280, argument_list; 280, 281; 281, identifier:part; 282, if_statement; 282, 283; 282, 287; 283, parenthesized_expression; 283, 284; 284, attribute; 284, 285; 284, 286; 285, identifier:self; 286, identifier:_navigationModel; 287, block; 287, 288; 287, 299; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:item; 291, call; 291, 292; 291, 297; 292, attribute; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:self; 295, identifier:_navigationModel; 296, identifier:itemByPath; 297, argument_list; 297, 298; 298, identifier:path; 299, if_statement; 299, 300; 299, 302; 300, parenthesized_expression; 300, 301; 301, identifier:item; 302, block; 302, 303; 302, 314; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:button; 307, identifier:setIcon; 308, argument_list; 308, 309; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:item; 312, identifier:icon; 313, argument_list; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:button; 318, identifier:setToolButtonStyle; 319, argument_list; 319, 320; 320, attribute; 320, 321; 320, 322; 321, identifier:Qt; 322, identifier:ToolButtonTextBesideIcon; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:button; 327, identifier:setProperty; 328, argument_list; 328, 329; 328, 330; 329, string:'path'; 330, call; 330, 331; 330, 332; 331, identifier:wrapVariant; 332, argument_list; 332, 333; 333, identifier:path; 334, expression_statement; 334, 335; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:button; 338, identifier:setProperty; 339, argument_list; 339, 340; 339, 341; 340, string:'is_completer'; 341, call; 341, 342; 341, 343; 342, identifier:wrapVariant; 343, argument_list; 343, 344; 344, False; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 352; 347, attribute; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:self; 350, identifier:_buttonGroup; 351, identifier:addButton; 352, argument_list; 352, 353; 353, identifier:button; 354, expression_statement; 354, 355; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:layout; 358, identifier:insertWidget; 359, argument_list; 359, 360; 359, 366; 360, binary_operator:+; 360, 361; 360, 365; 361, parenthesized_expression; 361, 362; 362, binary_operator:*; 362, 363; 362, 364; 363, identifier:i; 364, integer:2; 365, integer:1; 366, identifier:button; 367, comment; 368, if_statement; 368, 369; 368, 378; 369, parenthesized_expression; 369, 370; 370, boolean_operator:or; 370, 371; 370, 372; 371, identifier:show_last; 372, comparison_operator:<; 372, 373; 372, 374; 373, identifier:i; 374, parenthesized_expression; 374, 375; 375, binary_operator:-; 375, 376; 375, 377; 376, identifier:count; 377, integer:1; 378, block; 378, 379; 378, 386; 378, 393; 378, 400; 378, 409; 378, 420; 378, 431; 378, 440; 378, 453; 379, expression_statement; 379, 380; 380, assignment; 380, 381; 380, 382; 381, identifier:button; 382, call; 382, 383; 382, 384; 383, identifier:QToolButton; 384, argument_list; 384, 385; 385, identifier:partsw; 386, expression_statement; 386, 387; 387, call; 387, 388; 387, 391; 388, attribute; 388, 389; 388, 390; 389, identifier:button; 390, identifier:setAutoRaise; 391, argument_list; 391, 392; 392, True; 393, expression_statement; 393, 394; 394, call; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:button; 397, identifier:setMaximumWidth; 398, argument_list; 398, 399; 399, integer:12; 400, expression_statement; 400, 401; 401, call; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:button; 404, identifier:setArrowType; 405, argument_list; 405, 406; 406, attribute; 406, 407; 406, 408; 407, identifier:Qt; 408, identifier:RightArrow; 409, expression_statement; 409, 410; 410, call; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:button; 413, identifier:setProperty; 414, argument_list; 414, 415; 414, 416; 415, string:'path'; 416, call; 416, 417; 416, 418; 417, identifier:wrapVariant; 418, argument_list; 418, 419; 419, identifier:path; 420, expression_statement; 420, 421; 421, call; 421, 422; 421, 425; 422, attribute; 422, 423; 422, 424; 423, identifier:button; 424, identifier:setProperty; 425, argument_list; 425, 426; 425, 427; 426, string:'is_completer'; 427, call; 427, 428; 427, 429; 428, identifier:wrapVariant; 429, argument_list; 429, 430; 430, True; 431, expression_statement; 431, 432; 432, call; 432, 433; 432, 438; 433, attribute; 433, 434; 433, 437; 434, attribute; 434, 435; 434, 436; 435, identifier:self; 436, identifier:_buttonGroup; 437, identifier:addButton; 438, argument_list; 438, 439; 439, identifier:button; 440, expression_statement; 440, 441; 441, call; 441, 442; 441, 445; 442, attribute; 442, 443; 442, 444; 443, identifier:layout; 444, identifier:insertWidget; 445, argument_list; 445, 446; 445, 452; 446, binary_operator:+; 446, 447; 446, 451; 447, parenthesized_expression; 447, 448; 448, binary_operator:*; 448, 449; 448, 450; 449, identifier:i; 450, integer:2; 451, integer:2; 452, identifier:button; 453, expression_statement; 453, 454; 454, assignment; 454, 455; 454, 456; 455, identifier:last_button; 456, identifier:button; 457, if_statement; 457, 458; 457, 474; 458, parenthesized_expression; 458, 459; 459, comparison_operator:<; 459, 460; 459, 469; 460, call; 460, 461; 460, 468; 461, attribute; 461, 462; 461, 467; 462, call; 462, 463; 462, 466; 463, attribute; 463, 464; 463, 465; 464, identifier:self; 465, identifier:scrollWidget; 466, argument_list; 467, identifier:width; 468, argument_list; 469, call; 469, 470; 469, 473; 470, attribute; 470, 471; 470, 472; 471, identifier:partsw; 472, identifier:width; 473, argument_list; 474, block; 474, 475; 475, expression_statement; 475, 476; 476, call; 476, 477; 476, 480; 477, attribute; 477, 478; 477, 479; 478, identifier:self; 479, identifier:scrollParts; 480, argument_list; 480, 481; 481, binary_operator:-; 481, 482; 481, 487; 482, call; 482, 483; 482, 486; 483, attribute; 483, 484; 483, 485; 484, identifier:partsw; 485, identifier:width; 486, argument_list; 487, call; 487, 488; 487, 495; 488, attribute; 488, 489; 488, 494; 489, call; 489, 490; 489, 493; 490, attribute; 490, 491; 490, 492; 491, identifier:self; 492, identifier:scrollWidget; 493, argument_list; 494, identifier:width; 495, argument_list; 496, expression_statement; 496, 497; 497, call; 497, 498; 497, 501; 498, attribute; 498, 499; 498, 500; 499, identifier:self; 500, identifier:setUpdatesEnabled; 501, argument_list; 501, 502; 502, True; 503, expression_statement; 503, 504; 504, call; 504, 505; 504, 510; 505, attribute; 505, 506; 505, 509; 506, attribute; 506, 507; 506, 508; 507, identifier:self; 508, identifier:navigationChanged; 509, identifier:emit; 510, argument_list
def rebuild( self ): """ Rebuilds the parts widget with the latest text. """ navitem = self.currentItem() if ( navitem ): navitem.initialize() self.setUpdatesEnabled(False) self.scrollWidget().show() self._originalText = '' partsw = self.partsWidget() for button in self._buttonGroup.buttons(): self._buttonGroup.removeButton(button) button.close() button.setParent(None) button.deleteLater() # create the root button layout = partsw.layout() parts = self.parts() button = QToolButton(partsw) button.setAutoRaise(True) button.setMaximumWidth(12) button.setArrowType(Qt.RightArrow) button.setProperty('path', wrapVariant('')) button.setProperty('is_completer', wrapVariant(True)) last_button = button self._buttonGroup.addButton(button) layout.insertWidget(0, button) # check to see if we have a navigation model setup if ( self._navigationModel ): last_item = self._navigationModel.itemByPath(self.text()) show_last = last_item and last_item.rowCount() > 0 else: show_last = False # load the navigation system count = len(parts) for i, part in enumerate(parts): path = self.separator().join(parts[:i+1]) button = QToolButton(partsw) button.setAutoRaise(True) button.setText(part) if ( self._navigationModel ): item = self._navigationModel.itemByPath(path) if ( item ): button.setIcon(item.icon()) button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) button.setProperty('path', wrapVariant(path)) button.setProperty('is_completer', wrapVariant(False)) self._buttonGroup.addButton(button) layout.insertWidget((i * 2) + 1, button) # determine if we should show the final button if ( show_last or i < (count - 1) ): button = QToolButton(partsw) button.setAutoRaise(True) button.setMaximumWidth(12) button.setArrowType(Qt.RightArrow) button.setProperty('path', wrapVariant(path)) button.setProperty('is_completer', wrapVariant(True)) self._buttonGroup.addButton(button) layout.insertWidget((i * 2) + 2, button) last_button = button if ( self.scrollWidget().width() < partsw.width() ): self.scrollParts(partsw.width() - self.scrollWidget().width()) self.setUpdatesEnabled(True) self.navigationChanged.emit()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:syncView; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:recursive; 7, False; 8, block; 8, 9; 8, 11; 8, 12; 8, 20; 8, 28; 8, 33; 8, 41; 8, 49; 8, 57; 8, 71; 8, 83; 8, 84; 8, 89; 8, 106; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:gantt; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:ganttWidget; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:tree; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:treeWidget; 27, argument_list; 28, if_statement; 28, 29; 28, 31; 29, not_operator; 29, 30; 30, identifier:gantt; 31, block; 31, 32; 32, return_statement; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:vwidget; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:gantt; 39, identifier:viewWidget; 40, argument_list; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:scene; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:vwidget; 47, identifier:scene; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:cell_w; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:gantt; 55, identifier:cellWidth; 56, argument_list; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:tree_offset_y; 60, binary_operator:+; 60, 61; 60, 70; 61, call; 61, 62; 61, 69; 62, attribute; 62, 63; 62, 68; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:tree; 66, identifier:header; 67, argument_list; 68, identifier:height; 69, argument_list; 70, integer:1; 71, expression_statement; 71, 72; 72, augmented_assignment:+=; 72, 73; 72, 74; 73, identifier:tree_offset_y; 74, call; 74, 75; 74, 82; 75, attribute; 75, 76; 75, 81; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:tree; 79, identifier:verticalScrollBar; 80, argument_list; 81, identifier:value; 82, argument_list; 83, comment; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:items; 87, list:[self]; 87, 88; 88, identifier:self; 89, if_statement; 89, 90; 89, 91; 90, identifier:recursive; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, augmented_assignment:+=; 93, 94; 93, 95; 94, identifier:items; 95, call; 95, 96; 95, 97; 96, identifier:list; 97, argument_list; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:children; 102, argument_list; 102, 103; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:recursive; 105, True; 106, for_statement; 106, 107; 106, 108; 106, 109; 106, 110; 107, identifier:item; 108, identifier:items; 109, comment; 110, block; 110, 111; 110, 119; 110, 134; 110, 135; 110, 152; 110, 158; 110, 167; 110, 177; 110, 185; 110, 186; 110, 202; 110, 437; 110, 445; 110, 452; 110, 460; 110, 470; 110, 477; 110, 478; 110, 484; 110, 490; 110, 507; 110, 514; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:vitem; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:item; 117, identifier:viewItem; 118, argument_list; 119, if_statement; 119, 120; 119, 126; 120, not_operator; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:vitem; 124, identifier:scene; 125, argument_list; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:scene; 131, identifier:addItem; 132, argument_list; 132, 133; 133, identifier:vitem; 134, comment; 135, if_statement; 135, 136; 135, 144; 136, boolean_operator:or; 136, 137; 136, 142; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:item; 140, identifier:isHidden; 141, argument_list; 142, not_operator; 142, 143; 143, identifier:tree; 144, block; 144, 145; 144, 151; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:vitem; 149, identifier:hide; 150, argument_list; 151, continue_statement; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:vitem; 156, identifier:show; 157, argument_list; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:tree_rect; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:tree; 164, identifier:visualItemRect; 165, argument_list; 165, 166; 166, identifier:item; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:tree_y; 170, binary_operator:+; 170, 171; 170, 176; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:tree_rect; 174, identifier:y; 175, argument_list; 176, identifier:tree_offset_y; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:tree_h; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:tree_rect; 183, identifier:height; 184, argument_list; 185, comment; 186, if_statement; 186, 187; 186, 194; 187, comparison_operator:==; 187, 188; 187, 193; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:tree_rect; 191, identifier:height; 192, argument_list; 193, integer:0; 194, block; 194, 195; 194, 201; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:vitem; 199, identifier:hide; 200, argument_list; 201, continue_statement; 202, if_statement; 202, 203; 202, 225; 202, 266; 203, comparison_operator:in; 203, 204; 203, 209; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:gantt; 207, identifier:timescale; 208, argument_list; 209, tuple; 209, 210; 209, 215; 209, 220; 210, attribute; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:gantt; 213, identifier:Timescale; 214, identifier:Minute; 215, attribute; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:gantt; 218, identifier:Timescale; 219, identifier:Hour; 220, attribute; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:gantt; 223, identifier:Timescale; 224, identifier:Day; 225, block; 225, 226; 225, 234; 225, 242; 225, 251; 225, 260; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:dstart; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:item; 232, identifier:dateTimeStart; 233, argument_list; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:dend; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:item; 240, identifier:dateTimeEnd; 241, argument_list; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:view_x; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:scene; 248, identifier:datetimeXPos; 249, argument_list; 249, 250; 250, identifier:dstart; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:view_r; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:scene; 257, identifier:datetimeXPos; 258, argument_list; 258, 259; 259, identifier:dend; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:view_w; 263, binary_operator:-; 263, 264; 263, 265; 264, identifier:view_r; 265, identifier:view_x; 266, else_clause; 266, 267; 267, block; 267, 268; 267, 281; 267, 291; 267, 292; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:view_x; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:scene; 274, identifier:dateXPos; 275, argument_list; 275, 276; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:item; 279, identifier:dateStart; 280, argument_list; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:view_w; 284, binary_operator:*; 284, 285; 284, 290; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:item; 288, identifier:duration; 289, argument_list; 290, identifier:cell_w; 291, comment; 292, if_statement; 292, 293; 292, 299; 293, not_operator; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:item; 297, identifier:isAllDay; 298, argument_list; 299, block; 299, 300; 299, 308; 299, 309; 299, 310; 299, 318; 299, 331; 299, 342; 299, 351; 299, 363; 299, 364; 299, 372; 299, 385; 299, 396; 299, 407; 299, 408; 299, 421; 299, 425; 299, 426; 299, 430; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:full_day; 303, binary_operator:*; 303, 304; 303, 307; 304, binary_operator:*; 304, 305; 304, 306; 305, integer:24; 306, integer:60; 307, integer:60; 308, comment; 309, comment; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:start; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:item; 316, identifier:timeStart; 317, argument_list; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:start_day; 321, parenthesized_expression; 321, 322; 322, binary_operator:*; 322, 323; 322, 330; 323, binary_operator:*; 323, 324; 323, 329; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:start; 327, identifier:hour; 328, argument_list; 329, integer:60; 330, integer:60; 331, expression_statement; 331, 332; 332, augmented_assignment:+=; 332, 333; 332, 334; 333, identifier:start_day; 334, parenthesized_expression; 334, 335; 335, binary_operator:*; 335, 336; 335, 341; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:start; 339, identifier:minute; 340, argument_list; 341, integer:60; 342, expression_statement; 342, 343; 343, augmented_assignment:+=; 343, 344; 343, 345; 344, identifier:start_day; 345, parenthesized_expression; 345, 346; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:start; 349, identifier:second; 350, argument_list; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 354; 353, identifier:offset_start; 354, binary_operator:*; 354, 355; 354, 362; 355, parenthesized_expression; 355, 356; 356, binary_operator:/; 356, 357; 356, 358; 357, identifier:start_day; 358, call; 358, 359; 358, 360; 359, identifier:float; 360, argument_list; 360, 361; 361, identifier:full_day; 362, identifier:cell_w; 363, comment; 364, expression_statement; 364, 365; 365, assignment; 365, 366; 365, 367; 366, identifier:end; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:item; 370, identifier:timeEnd; 371, argument_list; 372, expression_statement; 372, 373; 373, assignment; 373, 374; 373, 375; 374, identifier:end_day; 375, parenthesized_expression; 375, 376; 376, binary_operator:*; 376, 377; 376, 384; 377, binary_operator:*; 377, 378; 377, 383; 378, call; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:end; 381, identifier:hour; 382, argument_list; 383, integer:60; 384, integer:60; 385, expression_statement; 385, 386; 386, augmented_assignment:+=; 386, 387; 386, 388; 387, identifier:end_day; 388, parenthesized_expression; 388, 389; 389, binary_operator:*; 389, 390; 389, 395; 390, call; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:start; 393, identifier:minute; 394, argument_list; 395, integer:60; 396, expression_statement; 396, 397; 397, augmented_assignment:+=; 397, 398; 397, 399; 398, identifier:end_day; 399, parenthesized_expression; 399, 400; 400, binary_operator:+; 400, 401; 400, 406; 401, call; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:start; 404, identifier:second; 405, argument_list; 406, integer:1; 407, comment; 408, expression_statement; 408, 409; 409, assignment; 409, 410; 409, 411; 410, identifier:offset_end; 411, parenthesized_expression; 411, 412; 412, binary_operator:/; 412, 413; 412, 417; 413, parenthesized_expression; 413, 414; 414, binary_operator:-; 414, 415; 414, 416; 415, identifier:full_day; 416, identifier:end_day; 417, call; 417, 418; 417, 419; 418, identifier:float; 419, argument_list; 419, 420; 420, identifier:full_day; 421, expression_statement; 421, 422; 422, augmented_assignment:*=; 422, 423; 422, 424; 423, identifier:offset_end; 424, identifier:cell_w; 425, comment; 426, expression_statement; 426, 427; 427, augmented_assignment:+=; 427, 428; 427, 429; 428, identifier:view_x; 429, identifier:offset_start; 430, expression_statement; 430, 431; 431, augmented_assignment:-=; 431, 432; 431, 433; 432, identifier:view_w; 433, parenthesized_expression; 433, 434; 434, binary_operator:+; 434, 435; 434, 436; 435, identifier:offset_start; 436, identifier:offset_end; 437, expression_statement; 437, 438; 438, assignment; 438, 439; 438, 440; 439, identifier:view_w; 440, call; 440, 441; 440, 442; 441, identifier:max; 442, argument_list; 442, 443; 442, 444; 443, identifier:view_w; 444, integer:5; 445, expression_statement; 445, 446; 446, call; 446, 447; 446, 450; 447, attribute; 447, 448; 447, 449; 448, identifier:vitem; 449, identifier:setSyncing; 450, argument_list; 450, 451; 451, True; 452, expression_statement; 452, 453; 453, call; 453, 454; 453, 457; 454, attribute; 454, 455; 454, 456; 455, identifier:vitem; 456, identifier:setPos; 457, argument_list; 457, 458; 457, 459; 458, identifier:view_x; 459, identifier:tree_y; 460, expression_statement; 460, 461; 461, call; 461, 462; 461, 465; 462, attribute; 462, 463; 462, 464; 463, identifier:vitem; 464, identifier:setRect; 465, argument_list; 465, 466; 465, 467; 465, 468; 465, 469; 466, integer:0; 467, integer:0; 468, identifier:view_w; 469, identifier:tree_h; 470, expression_statement; 470, 471; 471, call; 471, 472; 471, 475; 472, attribute; 472, 473; 472, 474; 473, identifier:vitem; 474, identifier:setSyncing; 475, argument_list; 475, 476; 476, False; 477, comment; 478, expression_statement; 478, 479; 479, assignment; 479, 480; 479, 481; 480, identifier:flags; 481, attribute; 481, 482; 481, 483; 482, identifier:vitem; 483, identifier:ItemIsSelectable; 484, expression_statement; 484, 485; 485, augmented_assignment:|=; 485, 486; 485, 487; 486, identifier:flags; 487, attribute; 487, 488; 487, 489; 488, identifier:vitem; 489, identifier:ItemIsFocusable; 490, if_statement; 490, 491; 490, 500; 491, binary_operator:&; 491, 492; 491, 497; 492, call; 492, 493; 492, 496; 493, attribute; 493, 494; 493, 495; 494, identifier:item; 495, identifier:flags; 496, argument_list; 497, attribute; 497, 498; 497, 499; 498, identifier:Qt; 499, identifier:ItemIsEditable; 500, block; 500, 501; 501, expression_statement; 501, 502; 502, augmented_assignment:|=; 502, 503; 502, 504; 503, identifier:flags; 504, attribute; 504, 505; 504, 506; 505, identifier:vitem; 506, identifier:ItemIsMovable; 507, expression_statement; 507, 508; 508, call; 508, 509; 508, 512; 509, attribute; 509, 510; 509, 511; 510, identifier:vitem; 511, identifier:setFlags; 512, argument_list; 512, 513; 513, identifier:flags; 514, expression_statement; 514, 515; 515, call; 515, 516; 515, 519; 516, attribute; 516, 517; 516, 518; 517, identifier:item; 518, identifier:syncDependencies; 519, argument_list
def syncView(self, recursive=False): """ Syncs the information from this item to the view. """ # update the view widget gantt = self.ganttWidget() tree = self.treeWidget() if not gantt: return vwidget = gantt.viewWidget() scene = vwidget.scene() cell_w = gantt.cellWidth() tree_offset_y = tree.header().height() + 1 tree_offset_y += tree.verticalScrollBar().value() # collect the items to work on items = [self] if recursive: items += list(self.children(recursive=True)) for item in items: # grab the view item from the gantt item vitem = item.viewItem() if not vitem.scene(): scene.addItem(vitem) # make sure the item should be visible if item.isHidden() or not tree: vitem.hide() continue vitem.show() tree_rect = tree.visualItemRect(item) tree_y = tree_rect.y() + tree_offset_y tree_h = tree_rect.height() # check to see if this item is hidden if tree_rect.height() == 0: vitem.hide() continue if gantt.timescale() in (gantt.Timescale.Minute, gantt.Timescale.Hour, gantt.Timescale.Day): dstart = item.dateTimeStart() dend = item.dateTimeEnd() view_x = scene.datetimeXPos(dstart) view_r = scene.datetimeXPos(dend) view_w = view_r - view_x else: view_x = scene.dateXPos(item.dateStart()) view_w = item.duration() * cell_w # determine the % off from the length based on this items time if not item.isAllDay(): full_day = 24 * 60 * 60 # full days worth of seconds # determine the start offset start = item.timeStart() start_day = (start.hour() * 60 * 60) start_day += (start.minute() * 60) start_day += (start.second()) offset_start = (start_day / float(full_day)) * cell_w # determine the end offset end = item.timeEnd() end_day = (end.hour() * 60 * 60) end_day += (start.minute() * 60) end_day += (start.second() + 1) # forces at least 1 sec offset_end = ((full_day - end_day) / float(full_day)) offset_end *= cell_w # update the xpos and widths view_x += offset_start view_w -= (offset_start + offset_end) view_w = max(view_w, 5) vitem.setSyncing(True) vitem.setPos(view_x, tree_y) vitem.setRect(0, 0, view_w, tree_h) vitem.setSyncing(False) # setup standard properties flags = vitem.ItemIsSelectable flags |= vitem.ItemIsFocusable if item.flags() & Qt.ItemIsEditable: flags |= vitem.ItemIsMovable vitem.setFlags(flags) item.syncDependencies()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:nodes; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, keyword_separator; 6, default_parameter; 6, 7; 6, 8; 7, identifier:dc; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:near; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:watch; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:consistency; 17, None; 18, block; 18, 19; 18, 21; 18, 31; 18, 52; 19, expression_statement; 19, 20; 20, comment; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:params; 24, dictionary; 24, 25; 24, 28; 25, pair; 25, 26; 25, 27; 26, string:"dc"; 27, identifier:dc; 28, pair; 28, 29; 28, 30; 29, string:"near"; 30, identifier:near; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:response; 34, await; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_api; 40, identifier:get; 41, argument_list; 41, 42; 41, 43; 41, 46; 41, 49; 42, string:"/v1/catalog/nodes"; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:params; 45, identifier:params; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:watch; 48, identifier:watch; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:consistency; 51, identifier:consistency; 52, return_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:consul; 55, argument_list; 55, 56; 56, identifier:response
async def nodes(self, *, dc=None, near=None, watch=None, consistency=None): """Lists nodes in a given DC Parameters: dc (str): Specify datacenter that will be used. Defaults to the agent's local datacenter. near (str): Sort the node list in ascending order based on the estimated round trip time from that node. watch (Blocking): Do a blocking query consistency (Consistency): Force consistency Returns: CollectionMeta: where value is a list It returns a body like this:: [ { "Node": "baz", "Address": "10.1.10.11", "TaggedAddresses": { "lan": "10.1.10.11", "wan": "10.1.10.11" } }, { "Node": "foobar", "Address": "10.1.10.12", "TaggedAddresses": { "lan": "10.1.10.11", "wan": "10.1.10.12" } } ] """ params = {"dc": dc, "near": near} response = await self._api.get("/v1/catalog/nodes", params=params, watch=watch, consistency=consistency) return consul(response)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:keyphrases_graph; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 4, identifier:keyphrases; 5, identifier:texts; 6, default_parameter; 6, 7; 6, 8; 7, identifier:referral_confidence; 8, float:0.6; 9, default_parameter; 9, 10; 9, 11; 10, identifier:relevance_threshold; 11, float:0.25; 12, default_parameter; 12, 13; 12, 14; 13, identifier:support_threshold; 14, integer:1; 15, default_parameter; 15, 16; 15, 17; 16, identifier:similarity_measure; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:synonimizer; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:language; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:consts; 26, identifier:Language; 27, identifier:ENGLISH; 28, block; 28, 29; 28, 31; 28, 41; 28, 42; 28, 53; 28, 54; 28, 79; 28, 80; 28, 122; 28, 123; 28, 146; 28, 147; 28, 148; 28, 245; 29, expression_statement; 29, 30; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:similarity_measure; 34, boolean_operator:or; 34, 35; 34, 36; 35, identifier:similarity_measure; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:relevance; 39, identifier:ASTRelevanceMeasure; 40, argument_list; 41, comment; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:table; 45, call; 45, 46; 45, 47; 46, identifier:keyphrases_table; 47, argument_list; 47, 48; 47, 49; 47, 50; 47, 51; 47, 52; 48, identifier:keyphrases; 49, identifier:texts; 50, identifier:similarity_measure; 51, identifier:synonimizer; 52, identifier:language; 53, comment; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:keyphrase_texts; 57, dictionary_comprehension; 57, 58; 57, 76; 58, pair; 58, 59; 58, 60; 59, identifier:keyphrase; 60, call; 60, 61; 60, 62; 61, identifier:set; 62, argument_list; 62, 63; 63, list_comprehension; 63, 64; 63, 65; 63, 68; 64, identifier:text; 65, for_in_clause; 65, 66; 65, 67; 66, identifier:text; 67, identifier:texts; 68, if_clause; 68, 69; 69, comparison_operator:>=; 69, 70; 69, 75; 70, subscript; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:table; 73, identifier:keyphrase; 74, identifier:text; 75, identifier:relevance_threshold; 76, for_in_clause; 76, 77; 76, 78; 77, identifier:keyphrase; 78, identifier:keyphrases; 79, comment; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:graph; 83, dictionary; 83, 84; 83, 110; 83, 113; 83, 116; 83, 119; 84, pair; 84, 85; 84, 86; 85, string:"nodes"; 86, list_comprehension; 86, 87; 86, 102; 87, dictionary; 87, 88; 87, 91; 87, 94; 88, pair; 88, 89; 88, 90; 89, string:"id"; 90, identifier:i; 91, pair; 91, 92; 91, 93; 92, string:"label"; 93, identifier:keyphrase; 94, pair; 94, 95; 94, 96; 95, string:"support"; 96, call; 96, 97; 96, 98; 97, identifier:len; 98, argument_list; 98, 99; 99, subscript; 99, 100; 99, 101; 100, identifier:keyphrase_texts; 101, identifier:keyphrase; 102, for_in_clause; 102, 103; 102, 106; 103, pattern_list; 103, 104; 103, 105; 104, identifier:i; 105, identifier:keyphrase; 106, call; 106, 107; 106, 108; 107, identifier:enumerate; 108, argument_list; 108, 109; 109, identifier:keyphrases; 110, pair; 110, 111; 110, 112; 111, string:"edges"; 112, list:[]; 113, pair; 113, 114; 113, 115; 114, string:"referral_confidence"; 115, identifier:referral_confidence; 116, pair; 116, 117; 116, 118; 117, string:"relevance_threshold"; 118, identifier:relevance_threshold; 119, pair; 119, 120; 119, 121; 120, string:"support_threshold"; 121, identifier:support_threshold; 122, comment; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:graph; 127, string:"nodes"; 128, list_comprehension; 128, 129; 128, 130; 128, 135; 129, identifier:n; 130, for_in_clause; 130, 131; 130, 132; 131, identifier:n; 132, subscript; 132, 133; 132, 134; 133, identifier:graph; 134, string:"nodes"; 135, if_clause; 135, 136; 136, comparison_operator:>=; 136, 137; 136, 145; 137, call; 137, 138; 137, 139; 138, identifier:len; 139, argument_list; 139, 140; 140, subscript; 140, 141; 140, 142; 141, identifier:keyphrase_texts; 142, subscript; 142, 143; 142, 144; 143, identifier:n; 144, string:"label"; 145, identifier:support_threshold; 146, comment; 147, comment; 148, for_statement; 148, 149; 148, 152; 148, 167; 149, pattern_list; 149, 150; 149, 151; 150, identifier:i1; 151, identifier:i2; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:itertools; 155, identifier:permutations; 156, argument_list; 156, 157; 156, 166; 157, call; 157, 158; 157, 159; 158, identifier:range; 159, argument_list; 159, 160; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, subscript; 163, 164; 163, 165; 164, identifier:graph; 165, string:"nodes"; 166, integer:2; 167, block; 167, 168; 167, 176; 167, 184; 167, 218; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:node1; 171, subscript; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:graph; 174, string:"nodes"; 175, identifier:i1; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:node2; 179, subscript; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:graph; 182, string:"nodes"; 183, identifier:i2; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:confidence; 187, parenthesized_expression; 187, 188; 188, binary_operator:/; 188, 189; 188, 206; 189, call; 189, 190; 189, 191; 190, identifier:float; 191, argument_list; 191, 192; 192, call; 192, 193; 192, 194; 193, identifier:len; 194, argument_list; 194, 195; 195, binary_operator:&; 195, 196; 195, 201; 196, subscript; 196, 197; 196, 198; 197, identifier:keyphrase_texts; 198, subscript; 198, 199; 198, 200; 199, identifier:node1; 200, string:"label"; 201, subscript; 201, 202; 201, 203; 202, identifier:keyphrase_texts; 203, subscript; 203, 204; 203, 205; 204, identifier:node2; 205, string:"label"; 206, call; 206, 207; 206, 208; 207, identifier:max; 208, argument_list; 208, 209; 208, 217; 209, call; 209, 210; 209, 211; 210, identifier:len; 211, argument_list; 211, 212; 212, subscript; 212, 213; 212, 214; 213, identifier:keyphrase_texts; 214, subscript; 214, 215; 214, 216; 215, identifier:node1; 216, string:"label"; 217, integer:1; 218, if_statement; 218, 219; 218, 222; 219, comparison_operator:>=; 219, 220; 219, 221; 220, identifier:confidence; 221, identifier:referral_confidence; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 230; 225, attribute; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:graph; 228, string:"edges"; 229, identifier:append; 230, argument_list; 230, 231; 231, dictionary; 231, 232; 231, 237; 231, 242; 232, pair; 232, 233; 232, 234; 233, string:"source"; 234, subscript; 234, 235; 234, 236; 235, identifier:node1; 236, string:"id"; 237, pair; 237, 238; 237, 239; 238, string:"target"; 239, subscript; 239, 240; 239, 241; 240, identifier:node2; 241, string:"id"; 242, pair; 242, 243; 242, 244; 243, string:"confidence"; 244, identifier:confidence; 245, return_statement; 245, 246; 246, identifier:graph
def keyphrases_graph(keyphrases, texts, referral_confidence=0.6, relevance_threshold=0.25, support_threshold=1, similarity_measure=None, synonimizer=None, language=consts.Language.ENGLISH): """ Constructs the keyphrases relation graph based on the given texts corpus. The graph construction algorithm is based on the analysis of co-occurrences of key phrases in the text corpus. A key phrase is considered to imply another one if that second phrase occurs frequently enough in the same texts as the first one (that frequency is controlled by the referral_confidence). A keyphrase counts as occuring in a text if its matching score for that text ecxeeds some threshold (Mirkin, Chernyak, & Chugunova, 2012). :param keyphrases: list of unicode strings :param texts: dictionary of form {text_name: text} :param referral_confidence: significance level of the graph in [0; 1], 0.6 by default :param relevance_threshold: threshold for the matching score in [0; 1] where a keyphrase starts to be considered as occuring in the corresponding text; the defaul value is 0.25 :param support_threshold: threshold for the support of a node (the number of documents containing the corresponding keyphrase) such that it can be included into the graph :param similarity_measure: Similarity measure to use :param synonimizer: SynonymExtractor object to be used :param language: Language of the text collection / keyphrases :returns: graph dictionary in a the following format: { "nodes": [ { "id": <id>, "label": "keyphrase", "support": <# of documents containing the keyphrase> }, ... ] "edges": [ { "source": "node_id", "target": "node_id", "confidence": <confidence_level> }, ... ] } """ similarity_measure = similarity_measure or relevance.ASTRelevanceMeasure() # Keyphrases table table = keyphrases_table(keyphrases, texts, similarity_measure, synonimizer, language) # Dictionary { "keyphrase" => set(names of texts containing "keyphrase") } keyphrase_texts = {keyphrase: set([text for text in texts if table[keyphrase][text] >= relevance_threshold]) for keyphrase in keyphrases} # Initializing the graph object with nodes graph = { "nodes": [ { "id": i, "label": keyphrase, "support": len(keyphrase_texts[keyphrase]) } for i, keyphrase in enumerate(keyphrases) ], "edges": [], "referral_confidence": referral_confidence, "relevance_threshold": relevance_threshold, "support_threshold": support_threshold } # Removing nodes with small support after we've numbered all nodes graph["nodes"] = [n for n in graph["nodes"] if len(keyphrase_texts[n["label"]]) >= support_threshold] # Creating edges # NOTE(msdubov): permutations(), unlike combinations(), treats (1,2) and (2,1) as different for i1, i2 in itertools.permutations(range(len(graph["nodes"])), 2): node1 = graph["nodes"][i1] node2 = graph["nodes"][i2] confidence = (float(len(keyphrase_texts[node1["label"]] & keyphrase_texts[node2["label"]])) / max(len(keyphrase_texts[node1["label"]]), 1)) if confidence >= referral_confidence: graph["edges"].append({ "source": node1["id"], "target": node2["id"], "confidence": confidence }) return graph
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_hm_verify_message_crc_uk; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:self; 5, identifier:thermostat_id; 6, identifier:protocol; 7, identifier:source; 8, identifier:expectedFunction; 9, identifier:expectedLength; 10, identifier:datal; 11, block; 11, 12; 11, 14; 11, 15; 11, 19; 12, expression_statement; 12, 13; 13, comment; 14, comment; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:badresponse; 18, integer:0; 19, if_statement; 19, 20; 19, 25; 19, 458; 20, comparison_operator:==; 20, 21; 20, 22; 21, identifier:protocol; 22, attribute; 22, 23; 22, 24; 23, identifier:constants; 24, identifier:HMV3_ID; 25, block; 25, 26; 25, 39; 25, 52; 25, 58; 25, 59; 25, 68; 25, 106; 25, 112; 25, 118; 25, 124; 25, 133; 25, 139; 25, 145; 25, 182; 25, 214; 25, 251; 25, 283; 25, 324; 25, 356; 25, 396; 25, 435; 25, 436; 25, 437; 25, 438; 25, 439; 25, 440; 25, 441; 25, 442; 25, 443; 25, 444; 25, 445; 25, 446; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:checksum; 29, subscript; 29, 30; 29, 31; 30, identifier:datal; 31, slice; 31, 32; 31, 38; 32, binary_operator:-; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:len; 35, argument_list; 35, 36; 36, identifier:datal; 37, integer:2; 38, colon; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:rxmsg; 42, subscript; 42, 43; 42, 44; 43, identifier:datal; 44, slice; 44, 45; 44, 46; 45, colon; 46, binary_operator:-; 46, 47; 46, 51; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, identifier:datal; 51, integer:2; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:crc; 55, call; 55, 56; 55, 57; 56, identifier:CRC16; 57, argument_list; 58, comment; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:expectedchecksum; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:crc; 65, identifier:run; 66, argument_list; 66, 67; 67, identifier:rxmsg; 68, if_statement; 68, 69; 68, 72; 68, 80; 69, comparison_operator:==; 69, 70; 69, 71; 70, identifier:expectedchecksum; 71, identifier:checksum; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:logging; 77, identifier:info; 78, argument_list; 78, 79; 79, string:"CRC is correct"; 80, else_clause; 80, 81; 81, block; 81, 82; 81, 89; 81, 93; 81, 102; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:logging; 86, identifier:error; 87, argument_list; 87, 88; 88, string:"CRC is INCORRECT"; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:serror; 92, string:"Incorrect CRC"; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:sys; 98, identifier:stderr; 99, identifier:write; 100, argument_list; 100, 101; 101, identifier:serror; 102, expression_statement; 102, 103; 103, augmented_assignment:+=; 103, 104; 103, 105; 104, identifier:badresponse; 105, integer:1; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:dest_addr; 109, subscript; 109, 110; 109, 111; 110, identifier:datal; 111, integer:0; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:frame_len_l; 115, subscript; 115, 116; 115, 117; 116, identifier:datal; 117, integer:1; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:frame_len_h; 121, subscript; 121, 122; 121, 123; 122, identifier:datal; 123, integer:2; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:frame_len; 127, binary_operator:|; 127, 128; 127, 132; 128, parenthesized_expression; 128, 129; 129, binary_operator:<<; 129, 130; 129, 131; 130, identifier:frame_len_h; 131, integer:8; 132, identifier:frame_len_l; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:source_addr; 136, subscript; 136, 137; 136, 138; 137, identifier:datal; 138, integer:3; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:func_code; 142, subscript; 142, 143; 142, 144; 143, identifier:datal; 144, integer:4; 145, if_statement; 145, 146; 145, 154; 146, parenthesized_expression; 146, 147; 147, boolean_operator:and; 147, 148; 147, 151; 148, comparison_operator:!=; 148, 149; 148, 150; 149, identifier:dest_addr; 150, integer:129; 151, comparison_operator:!=; 151, 152; 151, 153; 152, identifier:dest_addr; 153, integer:160; 154, block; 154, 155; 154, 162; 154, 169; 154, 178; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:logging; 159, identifier:info; 160, argument_list; 160, 161; 161, string:"dest_addr is ILLEGAL"; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:serror; 165, binary_operator:%; 165, 166; 165, 167; 166, string:"Illegal Dest Addr: %s\n"; 167, parenthesized_expression; 167, 168; 168, identifier:dest_addr; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:sys; 174, identifier:stderr; 175, identifier:write; 176, argument_list; 176, 177; 177, identifier:serror; 178, expression_statement; 178, 179; 179, augmented_assignment:+=; 179, 180; 179, 181; 180, identifier:badresponse; 181, integer:1; 182, if_statement; 182, 183; 182, 186; 183, comparison_operator:!=; 183, 184; 183, 185; 184, identifier:dest_addr; 185, identifier:thermostat_id; 186, block; 186, 187; 186, 194; 186, 201; 186, 210; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:logging; 191, identifier:info; 192, argument_list; 192, 193; 193, string:"dest_addr is INCORRECT"; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:serror; 197, binary_operator:%; 197, 198; 197, 199; 198, string:"Incorrect Dest Addr: %s\n"; 199, parenthesized_expression; 199, 200; 200, identifier:dest_addr; 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:sys; 206, identifier:stderr; 207, identifier:write; 208, argument_list; 208, 209; 209, identifier:serror; 210, expression_statement; 210, 211; 211, augmented_assignment:+=; 211, 212; 211, 213; 212, identifier:badresponse; 213, integer:1; 214, if_statement; 214, 215; 214, 223; 215, parenthesized_expression; 215, 216; 216, boolean_operator:or; 216, 217; 216, 220; 217, comparison_operator:<; 217, 218; 217, 219; 218, identifier:source_addr; 219, integer:1; 220, comparison_operator:>; 220, 221; 220, 222; 221, identifier:source_addr; 222, integer:32; 223, block; 223, 224; 223, 231; 223, 238; 223, 247; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:logging; 228, identifier:info; 229, argument_list; 229, 230; 230, string:"source_addr is ILLEGAL"; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:serror; 234, binary_operator:%; 234, 235; 234, 236; 235, string:"Illegal Src Addr: %s\n"; 236, parenthesized_expression; 236, 237; 237, identifier:source_addr; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 245; 240, attribute; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:sys; 243, identifier:stderr; 244, identifier:write; 245, argument_list; 245, 246; 246, identifier:serror; 247, expression_statement; 247, 248; 248, augmented_assignment:+=; 248, 249; 248, 250; 249, identifier:badresponse; 250, integer:1; 251, if_statement; 251, 252; 251, 255; 252, comparison_operator:!=; 252, 253; 252, 254; 253, identifier:source_addr; 254, identifier:source; 255, block; 255, 256; 255, 263; 255, 270; 255, 279; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:logging; 260, identifier:info; 261, argument_list; 261, 262; 262, string:"source addr is INCORRECT"; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:serror; 266, binary_operator:%; 266, 267; 266, 268; 267, string:"Incorrect Src Addr: %s\n"; 268, parenthesized_expression; 268, 269; 269, identifier:source_addr; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 277; 272, attribute; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:sys; 275, identifier:stderr; 276, identifier:write; 277, argument_list; 277, 278; 278, identifier:serror; 279, expression_statement; 279, 280; 280, augmented_assignment:+=; 280, 281; 280, 282; 281, identifier:badresponse; 282, integer:1; 283, if_statement; 283, 284; 283, 296; 284, parenthesized_expression; 284, 285; 285, boolean_operator:and; 285, 286; 285, 291; 286, comparison_operator:!=; 286, 287; 286, 288; 287, identifier:func_code; 288, attribute; 288, 289; 288, 290; 289, identifier:constants; 290, identifier:FUNC_WRITE; 291, comparison_operator:!=; 291, 292; 291, 293; 292, identifier:func_code; 293, attribute; 293, 294; 293, 295; 294, identifier:constants; 295, identifier:FUNC_READ; 296, block; 296, 297; 296, 304; 296, 311; 296, 320; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:logging; 301, identifier:info; 302, argument_list; 302, 303; 303, string:"Func Code is UNKNWON"; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:serror; 307, binary_operator:%; 307, 308; 307, 309; 308, string:"Unknown Func Code: %s\n"; 309, parenthesized_expression; 309, 310; 310, identifier:func_code; 311, expression_statement; 311, 312; 312, call; 312, 313; 312, 318; 313, attribute; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:sys; 316, identifier:stderr; 317, identifier:write; 318, argument_list; 318, 319; 319, identifier:serror; 320, expression_statement; 320, 321; 321, augmented_assignment:+=; 321, 322; 321, 323; 322, identifier:badresponse; 323, integer:1; 324, if_statement; 324, 325; 324, 328; 325, comparison_operator:!=; 325, 326; 325, 327; 326, identifier:func_code; 327, identifier:expectedFunction; 328, block; 328, 329; 328, 336; 328, 343; 328, 352; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:logging; 333, identifier:info; 334, argument_list; 334, 335; 335, string:"Func Code is UNEXPECTED"; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:serror; 339, binary_operator:%; 339, 340; 339, 341; 340, string:"Unexpected Func Code: %s\n"; 341, parenthesized_expression; 341, 342; 342, identifier:func_code; 343, expression_statement; 343, 344; 344, call; 344, 345; 344, 350; 345, attribute; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:sys; 348, identifier:stderr; 349, identifier:write; 350, argument_list; 350, 351; 351, identifier:serror; 352, expression_statement; 352, 353; 353, augmented_assignment:+=; 353, 354; 353, 355; 354, identifier:badresponse; 355, integer:1; 356, if_statement; 356, 357; 356, 367; 356, 368; 357, parenthesized_expression; 357, 358; 358, boolean_operator:and; 358, 359; 358, 364; 359, comparison_operator:==; 359, 360; 359, 361; 360, identifier:func_code; 361, attribute; 361, 362; 361, 363; 362, identifier:constants; 363, identifier:FUNC_WRITE; 364, comparison_operator:!=; 364, 365; 364, 366; 365, identifier:frame_len; 366, integer:7; 367, comment; 368, block; 368, 369; 368, 376; 368, 383; 368, 392; 369, expression_statement; 369, 370; 370, call; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:logging; 373, identifier:info; 374, argument_list; 374, 375; 375, string:"response length is INCORRECT"; 376, expression_statement; 376, 377; 377, assignment; 377, 378; 377, 379; 378, identifier:serror; 379, binary_operator:%; 379, 380; 379, 381; 380, string:"Incorrect length: %s\n"; 381, parenthesized_expression; 381, 382; 382, identifier:frame_len; 383, expression_statement; 383, 384; 384, call; 384, 385; 384, 390; 385, attribute; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:sys; 388, identifier:stderr; 389, identifier:write; 390, argument_list; 390, 391; 391, identifier:serror; 392, expression_statement; 392, 393; 393, augmented_assignment:+=; 393, 394; 393, 395; 394, identifier:badresponse; 395, integer:1; 396, if_statement; 396, 397; 396, 403; 397, comparison_operator:!=; 397, 398; 397, 402; 398, call; 398, 399; 398, 400; 399, identifier:len; 400, argument_list; 400, 401; 401, identifier:datal; 402, identifier:frame_len; 403, block; 403, 404; 403, 411; 403, 422; 403, 431; 404, expression_statement; 404, 405; 405, call; 405, 406; 405, 409; 406, attribute; 406, 407; 406, 408; 407, identifier:logging; 408, identifier:info; 409, argument_list; 409, 410; 410, string:"response length MISMATCHES header"; 411, expression_statement; 411, 412; 412, assignment; 412, 413; 412, 414; 413, identifier:serror; 414, binary_operator:%; 414, 415; 414, 416; 415, string:"Mismatch length: %s %s\n"; 416, tuple; 416, 417; 416, 421; 417, call; 417, 418; 417, 419; 418, identifier:len; 419, argument_list; 419, 420; 420, identifier:datal; 421, identifier:frame_len; 422, expression_statement; 422, 423; 423, call; 423, 424; 423, 429; 424, attribute; 424, 425; 424, 428; 425, attribute; 425, 426; 425, 427; 426, identifier:sys; 427, identifier:stderr; 428, identifier:write; 429, argument_list; 429, 430; 430, identifier:serror; 431, expression_statement; 431, 432; 432, augmented_assignment:+=; 432, 433; 432, 434; 433, identifier:badresponse; 434, integer:1; 435, comment; 436, comment; 437, comment; 438, comment; 439, comment; 440, comment; 441, comment; 442, comment; 443, comment; 444, comment; 445, comment; 446, if_statement; 446, 447; 446, 451; 446, 454; 447, parenthesized_expression; 447, 448; 448, comparison_operator:==; 448, 449; 448, 450; 449, identifier:badresponse; 450, integer:0; 451, block; 451, 452; 452, return_statement; 452, 453; 453, True; 454, else_clause; 454, 455; 455, block; 455, 456; 456, return_statement; 456, 457; 457, False; 458, else_clause; 458, 459; 459, block; 459, 460; 460, assert_statement; 460, 461; 460, 462; 461, integer:0; 462, binary_operator:%; 462, 463; 462, 464; 463, string:"Un-supported protocol found %s"; 464, identifier:protocol
def _hm_verify_message_crc_uk( self, thermostat_id, protocol, source, expectedFunction, expectedLength, datal ): """Verifies message appears legal""" # expectedLength only used for read msgs as always 7 for write badresponse = 0 if protocol == constants.HMV3_ID: checksum = datal[len(datal) - 2:] rxmsg = datal[:len(datal) - 2] crc = CRC16() # Initialises the CRC expectedchecksum = crc.run(rxmsg) if expectedchecksum == checksum: logging.info("CRC is correct") else: logging.error("CRC is INCORRECT") serror = "Incorrect CRC" sys.stderr.write(serror) badresponse += 1 dest_addr = datal[0] frame_len_l = datal[1] frame_len_h = datal[2] frame_len = (frame_len_h << 8) | frame_len_l source_addr = datal[3] func_code = datal[4] if (dest_addr != 129 and dest_addr != 160): logging.info("dest_addr is ILLEGAL") serror = "Illegal Dest Addr: %s\n" % (dest_addr) sys.stderr.write(serror) badresponse += 1 if dest_addr != thermostat_id: logging.info("dest_addr is INCORRECT") serror = "Incorrect Dest Addr: %s\n" % (dest_addr) sys.stderr.write(serror) badresponse += 1 if (source_addr < 1 or source_addr > 32): logging.info("source_addr is ILLEGAL") serror = "Illegal Src Addr: %s\n" % (source_addr) sys.stderr.write(serror) badresponse += 1 if source_addr != source: logging.info("source addr is INCORRECT") serror = "Incorrect Src Addr: %s\n" % (source_addr) sys.stderr.write(serror) badresponse += 1 if ( func_code != constants.FUNC_WRITE and func_code != constants.FUNC_READ ): logging.info("Func Code is UNKNWON") serror = "Unknown Func Code: %s\n" % (func_code) sys.stderr.write(serror) badresponse += 1 if func_code != expectedFunction: logging.info("Func Code is UNEXPECTED") serror = "Unexpected Func Code: %s\n" % (func_code) sys.stderr.write(serror) badresponse += 1 if ( func_code == constants.FUNC_WRITE and frame_len != 7 ): # Reply to Write is always 7 long logging.info("response length is INCORRECT") serror = "Incorrect length: %s\n" % (frame_len) sys.stderr.write(serror) badresponse += 1 if len(datal) != frame_len: logging.info("response length MISMATCHES header") serror = "Mismatch length: %s %s\n" % (len(datal), frame_len) sys.stderr.write(serror) badresponse += 1 # if (func_code == constants.FUNC_READ and # expectedLength !=len(datal) ): # # Read response length is wrong # logging.info("response length # not EXPECTED value") # logging.info("Got %s when expecting %s", # len(datal), expectedLength) # logging.info("Data is:\n %s", datal) # s = "Incorrect length: %s\n" % (frame_len) # sys.stderr.write(s) # badresponse += 1 if (badresponse == 0): return True else: return False else: assert 0, "Un-supported protocol found %s" % protocol
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:checks; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:self; 5, identifier:service; 6, keyword_separator; 7, default_parameter; 7, 8; 7, 9; 8, identifier:dc; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:near; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:watch; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:consistency; 18, None; 19, block; 19, 20; 19, 22; 19, 34; 19, 44; 19, 66; 20, expression_statement; 20, 21; 21, comment; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:service_id; 25, call; 25, 26; 25, 27; 26, identifier:extract_attr; 27, argument_list; 27, 28; 27, 29; 28, identifier:service; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:keys; 31, list:["ServiceID", "ID"]; 31, 32; 31, 33; 32, string:"ServiceID"; 33, string:"ID"; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:params; 37, dictionary; 37, 38; 37, 41; 38, pair; 38, 39; 38, 40; 39, string:"dc"; 40, identifier:dc; 41, pair; 41, 42; 41, 43; 42, string:"near"; 43, identifier:near; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:response; 47, await; 47, 48; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_api; 53, identifier:get; 54, argument_list; 54, 55; 54, 56; 54, 57; 54, 60; 54, 63; 55, string:"/v1/health/checks"; 56, identifier:service_id; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:params; 59, identifier:params; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:watch; 62, identifier:watch; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:consistency; 65, identifier:consistency; 66, return_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:consul; 69, argument_list; 69, 70; 70, identifier:response
async def checks(self, service, *, dc=None, near=None, watch=None, consistency=None): """Returns the checks of a service Parameters: dc (str): Specify datacenter that will be used. Defaults to the agent's local datacenter. near (str): With a node name will sort the node list in ascending order based on the estimated round trip time from that node watch (Blocking): Do a blocking query consistency (Consistency): Force consistency Returns: CollectionMeta: where value is a list of checks """ service_id = extract_attr(service, keys=["ServiceID", "ID"]) params = {"dc": dc, "near": near} response = await self._api.get("/v1/health/checks", service_id, params=params, watch=watch, consistency=consistency) return consul(response)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:cap; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 13; 9, 22; 9, 40; 9, 57; 9, 66; 9, 134; 9, 135; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, if_statement; 13, 14; 13, 19; 14, comparison_operator:in; 14, 15; 14, 16; 15, string:'READTHEDOCS'; 16, attribute; 16, 17; 16, 18; 17, identifier:os; 18, identifier:environ; 19, block; 19, 20; 20, return_statement; 20, 21; 21, string:''; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:!=; 23, 24; 23, 25; 24, identifier:kwargs; 25, dictionary; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:TypeError; 30, argument_list; 30, 31; 31, binary_operator:%; 31, 32; 31, 33; 32, string:"get(): No such argument %r"; 33, subscript; 33, 34; 33, 39; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:kwargs; 37, identifier:popitem; 38, argument_list; 39, integer:0; 40, if_statement; 40, 41; 40, 44; 40, 45; 41, comparison_operator:==; 41, 42; 41, 43; 42, identifier:_cache; 43, dictionary; 44, comment; 45, block; 45, 46; 46, try_statement; 46, 47; 46, 54; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:curses; 52, identifier:setupterm; 53, argument_list; 54, except_clause; 54, 55; 55, block; 55, 56; 56, pass_statement; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:s; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:_cache; 63, identifier:get; 64, argument_list; 64, 65; 65, identifier:cap; 66, if_statement; 66, 67; 66, 69; 67, not_operator; 67, 68; 68, identifier:s; 69, block; 69, 70; 69, 79; 69, 128; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:s; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:curses; 76, identifier:tigetstr; 77, argument_list; 77, 78; 78, identifier:cap; 79, if_statement; 79, 80; 79, 83; 80, comparison_operator:==; 80, 81; 80, 82; 81, identifier:s; 82, None; 83, block; 83, 84; 83, 93; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:s; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:curses; 90, identifier:tigetnum; 91, argument_list; 91, 92; 92, identifier:cap; 93, if_statement; 93, 94; 93, 98; 94, comparison_operator:==; 94, 95; 94, 96; 95, identifier:s; 96, unary_operator:-; 96, 97; 97, integer:2; 98, block; 98, 99; 98, 108; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:s; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:curses; 105, identifier:tigetflag; 106, argument_list; 106, 107; 107, identifier:cap; 108, if_statement; 108, 109; 108, 113; 108, 114; 108, 119; 109, comparison_operator:==; 109, 110; 109, 111; 110, identifier:s; 111, unary_operator:-; 111, 112; 112, integer:1; 113, comment; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:s; 118, string:''; 119, else_clause; 119, 120; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:s; 124, call; 124, 125; 124, 126; 125, identifier:bool; 126, argument_list; 126, 127; 127, identifier:s; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 133; 130, subscript; 130, 131; 130, 132; 131, identifier:_cache; 132, identifier:cap; 133, identifier:s; 134, comment; 135, if_statement; 135, 136; 135, 139; 135, 158; 136, boolean_operator:and; 136, 137; 136, 138; 137, identifier:args; 138, identifier:s; 139, block; 139, 140; 139, 151; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:r; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:curses; 146, identifier:tparm; 147, argument_list; 147, 148; 147, 149; 148, identifier:s; 149, list_splat; 149, 150; 150, identifier:args; 151, return_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:r; 155, identifier:decode; 156, argument_list; 156, 157; 157, string:'utf-8'; 158, else_clause; 158, 159; 159, block; 159, 160; 160, if_statement; 160, 161; 160, 166; 160, 174; 161, call; 161, 162; 161, 163; 162, identifier:isinstance; 163, argument_list; 163, 164; 163, 165; 164, identifier:s; 165, identifier:bytes; 166, block; 166, 167; 167, return_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:s; 171, identifier:decode; 172, argument_list; 172, 173; 173, string:'utf-8'; 174, else_clause; 174, 175; 175, block; 175, 176; 176, return_statement; 176, 177; 177, identifier:s
def get(cap, *args, **kwargs): """ Get a terminal capability exposes through the `curses` module. """ # Hack for readthedocs.org if 'READTHEDOCS' in os.environ: return '' if kwargs != {}: raise TypeError("get(): No such argument %r" % kwargs.popitem()[0]) if _cache == {}: # Fix for BPython try: curses.setupterm() except: pass s = _cache.get(cap) if not s: s = curses.tigetstr(cap) if s == None: s = curses.tigetnum(cap) if s == -2: s = curses.tigetflag(cap) if s == -1: # default to empty string so tparm doesn't fail s = '' else: s = bool(s) _cache[cap] = s # if 's' is not set 'curses.tparm' will throw an error if given arguments if args and s: r = curses.tparm(s, *args) return r.decode('utf-8') else: if isinstance(s, bytes): return s.decode('utf-8') else: return s
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:draw; 3, parameters; 3, 4; 3, 5; 4, identifier:canvas; 5, identifier:mol; 6, block; 6, 7; 6, 9; 6, 16; 6, 24; 6, 33; 6, 73; 6, 74; 6, 237; 6, 238; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:mol; 13, identifier:require; 14, argument_list; 14, 15; 15, string:"ScaleAndCenter"; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:mlb; 19, subscript; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:mol; 22, identifier:size2d; 23, integer:2; 24, if_statement; 24, 25; 24, 31; 25, not_operator; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:mol; 29, identifier:atom_count; 30, argument_list; 31, block; 31, 32; 32, return_statement; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:bond_type_fn; 36, dictionary; 36, 37; 36, 52; 36, 67; 37, pair; 37, 38; 37, 39; 38, integer:1; 39, dictionary; 39, 40; 39, 43; 39, 46; 39, 49; 40, pair; 40, 41; 40, 42; 41, integer:0; 42, identifier:single_bond; 43, pair; 43, 44; 43, 45; 44, integer:1; 45, identifier:wedged_single; 46, pair; 46, 47; 46, 48; 47, integer:2; 48, identifier:dashed_wedged_single; 49, pair; 49, 50; 49, 51; 50, integer:3; 51, identifier:wave_single; 52, pair; 52, 53; 52, 54; 53, integer:2; 54, dictionary; 54, 55; 54, 58; 54, 61; 54, 64; 55, pair; 55, 56; 55, 57; 56, integer:0; 57, identifier:cw_double; 58, pair; 58, 59; 58, 60; 59, integer:1; 60, identifier:counter_cw_double; 61, pair; 61, 62; 61, 63; 62, integer:2; 63, identifier:double_bond; 64, pair; 64, 65; 64, 66; 65, integer:3; 66, identifier:cross_double; 67, pair; 67, 68; 67, 69; 68, integer:3; 69, dictionary; 69, 70; 70, pair; 70, 71; 70, 72; 71, integer:0; 72, identifier:triple_bond; 73, comment; 74, for_statement; 74, 75; 74, 79; 74, 84; 75, pattern_list; 75, 76; 75, 77; 75, 78; 76, identifier:u; 77, identifier:v; 78, identifier:bond; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:mol; 82, identifier:bonds_iter; 83, argument_list; 84, block; 84, 85; 84, 92; 84, 120; 84, 131; 84, 142; 84, 149; 84, 173; 84, 197; 84, 208; 84, 219; 85, if_statement; 85, 86; 85, 90; 86, not_operator; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:bond; 89, identifier:visible; 90, block; 90, 91; 91, continue_statement; 92, if_statement; 92, 93; 92, 101; 92, 110; 93, comparison_operator:==; 93, 94; 93, 98; 94, parenthesized_expression; 94, 95; 95, comparison_operator:<; 95, 96; 95, 97; 96, identifier:u; 97, identifier:v; 98, attribute; 98, 99; 98, 100; 99, identifier:bond; 100, identifier:is_lower_first; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, pattern_list; 104, 105; 104, 106; 105, identifier:f; 106, identifier:s; 107, tuple; 107, 108; 107, 109; 108, identifier:u; 109, identifier:v; 110, else_clause; 110, 111; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, pattern_list; 114, 115; 114, 116; 115, identifier:s; 116, identifier:f; 117, tuple; 117, 118; 117, 119; 118, identifier:u; 119, identifier:v; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:p1; 123, attribute; 123, 124; 123, 130; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:mol; 127, identifier:atom; 128, argument_list; 128, 129; 129, identifier:f; 130, identifier:coords; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:p2; 134, attribute; 134, 135; 134, 141; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:mol; 138, identifier:atom; 139, argument_list; 139, 140; 140, identifier:s; 141, identifier:coords; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:==; 143, 144; 143, 145; 144, identifier:p1; 145, identifier:p2; 146, block; 146, 147; 146, 148; 147, continue_statement; 148, comment; 149, if_statement; 149, 150; 149, 158; 150, attribute; 150, 151; 150, 157; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:mol; 154, identifier:atom; 155, argument_list; 155, 156; 156, identifier:f; 157, identifier:visible; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:p1; 162, subscript; 162, 163; 162, 172; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:gm; 166, identifier:t_seg; 167, argument_list; 167, 168; 167, 169; 167, 170; 167, 171; 168, identifier:p1; 169, identifier:p2; 170, identifier:F_AOVL; 171, integer:2; 172, integer:0; 173, if_statement; 173, 174; 173, 182; 174, attribute; 174, 175; 174, 181; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:mol; 178, identifier:atom; 179, argument_list; 179, 180; 180, identifier:s; 181, identifier:visible; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:p2; 186, subscript; 186, 187; 186, 196; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:gm; 190, identifier:t_seg; 191, argument_list; 191, 192; 191, 193; 191, 194; 191, 195; 192, identifier:p1; 193, identifier:p2; 194, identifier:F_AOVL; 195, integer:1; 196, integer:1; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:color1; 200, attribute; 200, 201; 200, 207; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:mol; 204, identifier:atom; 205, argument_list; 205, 206; 206, identifier:f; 207, identifier:color; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:color2; 211, attribute; 211, 212; 211, 218; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:mol; 215, identifier:atom; 216, argument_list; 216, 217; 217, identifier:s; 218, identifier:color; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 230; 221, subscript; 221, 222; 221, 227; 222, subscript; 222, 223; 222, 224; 223, identifier:bond_type_fn; 224, attribute; 224, 225; 224, 226; 225, identifier:bond; 226, identifier:order; 227, attribute; 227, 228; 227, 229; 228, identifier:bond; 229, identifier:type; 230, argument_list; 230, 231; 230, 232; 230, 233; 230, 234; 230, 235; 230, 236; 231, identifier:canvas; 232, identifier:p1; 233, identifier:p2; 234, identifier:color1; 235, identifier:color2; 236, identifier:mlb; 237, comment; 238, for_statement; 238, 239; 238, 242; 238, 247; 239, pattern_list; 239, 240; 239, 241; 240, identifier:n; 241, identifier:atom; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:mol; 245, identifier:atoms_iter; 246, argument_list; 247, block; 247, 248; 247, 255; 247, 261; 247, 267; 247, 268; 247, 399; 247, 400; 247, 408; 248, if_statement; 248, 249; 248, 253; 249, not_operator; 249, 250; 250, attribute; 250, 251; 250, 252; 251, identifier:atom; 252, identifier:visible; 253, block; 253, 254; 254, continue_statement; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:p; 258, attribute; 258, 259; 258, 260; 259, identifier:atom; 260, identifier:coords; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:color; 264, attribute; 264, 265; 264, 266; 265, identifier:atom; 266, identifier:color; 267, comment; 268, if_statement; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:atom; 271, identifier:H_count; 272, block; 272, 273; 272, 277; 272, 289; 272, 339; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:cosnbrs; 276, list:[]; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:hrzn; 280, tuple; 280, 281; 280, 286; 281, binary_operator:+; 281, 282; 281, 285; 282, subscript; 282, 283; 282, 284; 283, identifier:p; 284, integer:0; 285, integer:1; 286, subscript; 286, 287; 286, 288; 287, identifier:p; 288, integer:1; 289, for_statement; 289, 290; 289, 291; 289, 299; 290, identifier:nbr; 291, call; 291, 292; 291, 297; 292, attribute; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:mol; 295, identifier:graph; 296, identifier:neighbors; 297, argument_list; 297, 298; 298, identifier:n; 299, block; 299, 300; 299, 311; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:pnbr; 303, attribute; 303, 304; 303, 310; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:mol; 307, identifier:atom; 308, argument_list; 308, 309; 309, identifier:nbr; 310, identifier:coords; 311, try_statement; 311, 312; 311, 335; 312, block; 312, 313; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:cosnbrs; 317, identifier:append; 318, argument_list; 318, 319; 319, binary_operator:/; 319, 320; 319, 328; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:gm; 323, identifier:dot_product; 324, argument_list; 324, 325; 324, 326; 324, 327; 325, identifier:hrzn; 326, identifier:pnbr; 327, identifier:p; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:gm; 331, identifier:distance; 332, argument_list; 332, 333; 332, 334; 333, identifier:p; 334, identifier:pnbr; 335, except_clause; 335, 336; 335, 337; 336, identifier:ZeroDivisionError; 337, block; 337, 338; 338, pass_statement; 339, if_statement; 339, 340; 339, 349; 339, 350; 339, 371; 340, boolean_operator:or; 340, 341; 340, 343; 341, not_operator; 341, 342; 342, identifier:cosnbrs; 343, comparison_operator:>; 343, 344; 343, 348; 344, call; 344, 345; 344, 346; 345, identifier:min; 346, argument_list; 346, 347; 347, identifier:cosnbrs; 348, integer:0; 349, comment; 350, block; 350, 351; 350, 360; 350, 370; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 354; 353, identifier:text; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:atom; 357, identifier:formula_html; 358, argument_list; 358, 359; 359, True; 360, expression_statement; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:canvas; 364, identifier:draw_text; 365, argument_list; 365, 366; 365, 367; 365, 368; 365, 369; 366, identifier:p; 367, identifier:text; 368, identifier:color; 369, string:"right"; 370, continue_statement; 371, elif_clause; 371, 372; 371, 378; 371, 379; 372, comparison_operator:<; 372, 373; 372, 377; 373, call; 373, 374; 373, 375; 374, identifier:max; 375, argument_list; 375, 376; 376, identifier:cosnbrs; 377, integer:0; 378, comment; 379, block; 379, 380; 379, 388; 379, 398; 380, expression_statement; 380, 381; 381, assignment; 381, 382; 381, 383; 382, identifier:text; 383, call; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:atom; 386, identifier:formula_html; 387, argument_list; 388, expression_statement; 388, 389; 389, call; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:canvas; 392, identifier:draw_text; 393, argument_list; 393, 394; 393, 395; 393, 396; 393, 397; 394, identifier:p; 395, identifier:text; 396, identifier:color; 397, string:"left"; 398, continue_statement; 399, comment; 400, expression_statement; 400, 401; 401, assignment; 401, 402; 401, 403; 402, identifier:text; 403, call; 403, 404; 403, 407; 404, attribute; 404, 405; 404, 406; 405, identifier:atom; 406, identifier:formula_html; 407, argument_list; 408, expression_statement; 408, 409; 409, call; 409, 410; 409, 413; 410, attribute; 410, 411; 410, 412; 411, identifier:canvas; 412, identifier:draw_text; 413, argument_list; 413, 414; 413, 415; 413, 416; 413, 417; 414, identifier:p; 415, identifier:text; 416, identifier:color; 417, string:"center"
def draw(canvas, mol): """Draw molecule structure image. Args: canvas: draw.drawable.Drawable mol: model.graphmol.Compound """ mol.require("ScaleAndCenter") mlb = mol.size2d[2] if not mol.atom_count(): return bond_type_fn = { 1: { 0: single_bond, 1: wedged_single, 2: dashed_wedged_single, 3: wave_single, }, 2: { 0: cw_double, 1: counter_cw_double, 2: double_bond, 3: cross_double }, 3: { 0: triple_bond } } # Draw bonds for u, v, bond in mol.bonds_iter(): if not bond.visible: continue if (u < v) == bond.is_lower_first: f, s = (u, v) else: s, f = (u, v) p1 = mol.atom(f).coords p2 = mol.atom(s).coords if p1 == p2: continue # avoid zero division if mol.atom(f).visible: p1 = gm.t_seg(p1, p2, F_AOVL, 2)[0] if mol.atom(s).visible: p2 = gm.t_seg(p1, p2, F_AOVL, 1)[1] color1 = mol.atom(f).color color2 = mol.atom(s).color bond_type_fn[bond.order][bond.type]( canvas, p1, p2, color1, color2, mlb) # Draw atoms for n, atom in mol.atoms_iter(): if not atom.visible: continue p = atom.coords color = atom.color # Determine text direction if atom.H_count: cosnbrs = [] hrzn = (p[0] + 1, p[1]) for nbr in mol.graph.neighbors(n): pnbr = mol.atom(nbr).coords try: cosnbrs.append(gm.dot_product(hrzn, pnbr, p) / gm.distance(p, pnbr)) except ZeroDivisionError: pass if not cosnbrs or min(cosnbrs) > 0: # [atom]< or isolated node(ex. H2O, HCl) text = atom.formula_html(True) canvas.draw_text(p, text, color, "right") continue elif max(cosnbrs) < 0: # >[atom] text = atom.formula_html() canvas.draw_text(p, text, color, "left") continue # -[atom]- or no hydrogens text = atom.formula_html() canvas.draw_text(p, text, color, "center")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:salm2map; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:salm; 5, identifier:s; 6, identifier:lmax; 7, identifier:Ntheta; 8, identifier:Nphi; 9, block; 9, 10; 9, 12; 9, 34; 9, 61; 9, 66; 9, 80; 9, 108; 9, 133; 9, 233; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 20; 13, boolean_operator:or; 13, 14; 13, 17; 14, comparison_operator:<; 14, 15; 14, 16; 15, identifier:Ntheta; 16, integer:2; 17, comparison_operator:<; 17, 18; 17, 19; 18, identifier:Nphi; 19, integer:1; 20, block; 20, 21; 21, raise_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:ValueError; 24, argument_list; 24, 25; 25, binary_operator:+; 25, 26; 25, 33; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, string:"Input values of Ntheta={0} and Nphi={1} "; 29, identifier:format; 30, argument_list; 30, 31; 30, 32; 31, identifier:Ntheta; 32, identifier:Nphi; 33, string:"are not allowed; they must be greater than 1 and 0, respectively."; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:<; 35, 36; 35, 37; 36, identifier:lmax; 37, integer:1; 38, block; 38, 39; 39, raise_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:ValueError; 42, argument_list; 42, 43; 43, binary_operator:+; 43, 44; 43, 52; 44, binary_operator:+; 44, 45; 44, 51; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, string:"Input value of lmax={0} "; 48, identifier:format; 49, argument_list; 49, 50; 50, identifier:lmax; 51, string:"is not allowed; it must be greater than 0 and should be greater "; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, string:"than |s|={0}."; 55, identifier:format; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:abs; 59, argument_list; 59, 60; 60, identifier:s; 61, import_statement; 61, 62; 62, aliased_import; 62, 63; 62, 65; 63, dotted_name; 63, 64; 64, identifier:numpy; 65, identifier:np; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:salm; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:np; 72, identifier:ascontiguousarray; 73, argument_list; 73, 74; 73, 75; 74, identifier:salm; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:dtype; 77, attribute; 77, 78; 77, 79; 78, identifier:np; 79, identifier:complex128; 80, if_statement; 80, 81; 80, 92; 81, comparison_operator:<; 81, 82; 81, 88; 82, subscript; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:salm; 85, identifier:shape; 86, unary_operator:-; 86, 87; 87, integer:1; 88, call; 88, 89; 88, 90; 89, identifier:N_lm; 90, argument_list; 90, 91; 91, identifier:lmax; 92, block; 92, 93; 93, raise_statement; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:ValueError; 96, argument_list; 96, 97; 97, binary_operator:+; 97, 98; 97, 107; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, string:"The input `salm` array of shape {0} is too small for the stated `lmax` of {1}. "; 101, identifier:format; 102, argument_list; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:salm; 105, identifier:shape; 106, identifier:lmax; 107, string:"Perhaps you forgot to include the (zero) modes with ell<|s|."; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:map; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:np; 114, identifier:empty; 115, argument_list; 115, 116; 115, 128; 116, binary_operator:+; 116, 117; 116, 125; 117, subscript; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:salm; 120, identifier:shape; 121, slice; 121, 122; 121, 123; 122, colon; 123, unary_operator:-; 123, 124; 124, integer:1; 125, tuple; 125, 126; 125, 127; 126, identifier:Ntheta; 127, identifier:Nphi; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:dtype; 130, attribute; 130, 131; 130, 132; 131, identifier:np; 132, identifier:complex128; 133, if_statement; 133, 134; 133, 139; 133, 221; 134, comparison_operator:>; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:salm; 137, identifier:ndim; 138, integer:1; 139, block; 139, 140; 139, 154; 139, 211; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:s; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:np; 146, identifier:ascontiguousarray; 147, argument_list; 147, 148; 147, 149; 148, identifier:s; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:dtype; 151, attribute; 151, 152; 151, 153; 152, identifier:np; 153, identifier:intc; 154, if_statement; 154, 155; 154, 187; 155, boolean_operator:or; 155, 156; 155, 165; 156, comparison_operator:!=; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:s; 159, identifier:ndim; 160, binary_operator:-; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:salm; 163, identifier:ndim; 164, integer:1; 165, comparison_operator:!=; 165, 166; 165, 174; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:np; 169, identifier:product; 170, argument_list; 170, 171; 171, attribute; 171, 172; 171, 173; 172, identifier:s; 173, identifier:shape; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:np; 177, identifier:product; 178, argument_list; 178, 179; 179, subscript; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:salm; 182, identifier:shape; 183, slice; 183, 184; 183, 185; 184, colon; 185, unary_operator:-; 185, 186; 186, integer:1; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:s; 191, binary_operator:*; 191, 192; 191, 193; 192, identifier:s; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:np; 196, identifier:ones; 197, argument_list; 197, 198; 197, 206; 198, subscript; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:salm; 201, identifier:shape; 202, slice; 202, 203; 202, 204; 203, colon; 204, unary_operator:-; 204, 205; 205, integer:1; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:dtype; 208, attribute; 208, 209; 208, 210; 209, identifier:np; 210, identifier:intc; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:_multi_salm2map; 214, argument_list; 214, 215; 214, 216; 214, 217; 214, 218; 214, 219; 214, 220; 215, identifier:salm; 216, identifier:map; 217, identifier:s; 218, identifier:lmax; 219, identifier:Ntheta; 220, identifier:Nphi; 221, else_clause; 221, 222; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 226; 225, identifier:_salm2map; 226, argument_list; 226, 227; 226, 228; 226, 229; 226, 230; 226, 231; 226, 232; 227, identifier:salm; 228, identifier:map; 229, identifier:s; 230, identifier:lmax; 231, identifier:Ntheta; 232, identifier:Nphi; 233, return_statement; 233, 234; 234, identifier:map
def salm2map(salm, s, lmax, Ntheta, Nphi): """Convert mode weights of spin-weighted function to values on a grid Parameters ---------- salm : array_like, complex, shape (..., (lmax+1)**2) Input array representing mode weights of the spin-weighted function. This array may be multi-dimensional, where initial dimensions may represent different times, for example, or separate functions on the sphere. The final dimension should give the values of the mode weights, in the order described below in the 'Notes' section. s : int or array, int, shape (...) Spin weight of the function. If `salm` is multidimensional and this is an array, its dimensions must match the first dimensions of `salm`, and the different values are the spin weights of the different functions represented by those dimensions. Otherwise, if `salm` is multidimensional and `s` is a single integer, all functions are assumed to have the same spin weight. lmax : int The largest `ell` value present in the input array. Ntheta : int Number of points in the output grid along the polar angle. Nphi : int Number of points in the output grid along the azimuthal angle. Returns ------- map : ndarray, complex, shape (..., Ntheta, Nphi) Values of the spin-weighted function on grid points of the sphere. This array is shaped like the input `salm` array, but has one extra dimension. The final two dimensions describe the values of the function on the sphere. See also -------- spinsfast.map2salm : Roughly the inverse of this function. Notes ----- The input `salm` data should be given in increasing order of `ell` value, always starting with (ell, m) = (0, 0) even if `s` is nonzero, proceeding to (1, -1), (1, 0), (1, 1), etc. Explicitly, the ordering should match this: [f_lm(ell, m) for ell in range(lmax+1) for m in range(-ell, ell+1)] The input is converted to a contiguous complex numpy array if necessary. The output data are presented on this grid of spherical coordinates: np.array([[f(theta, phi) for phi in np.linspace(0.0, 2*np.pi, num=2*lmax+1, endpoint=False)] for theta in np.linspace(0.0, np.pi, num=2*lmax+1, endpoint=True)]) Note that `map2salm` and `salm2map` are not true inverses of each other for several reasons. First, modes with `ell < |s|` should always be zero; they are simply assumed to be zero on input to `salm2map`. It is also possible to define a `map` function that violates this assumption -- for example, having a nonzero average value over the sphere, if the function has nonzero spin `s`, this is impossible. Also, it is possible to define a map of a function with so much angular dependence that it cannot be captured with the given `lmax` value. For example, a discontinuous function will never be perfectly resolved. Example ------- >>> s = -2 >>> lmax = 8 >>> Ntheta = Nphi = 2*lmax + 1 >>> modes = np.zeros(spinsfast.N_lm(lmax), dtype=np.complex128) >>> modes[spinsfast.lm_ind(2, 2, 8)] = 1.0 >>> values = spinsfast.salm2map(modes, s, lmax, Ntheta, Nphi) """ if Ntheta < 2 or Nphi < 1: raise ValueError("Input values of Ntheta={0} and Nphi={1} ".format(Ntheta, Nphi) + "are not allowed; they must be greater than 1 and 0, respectively.") if lmax < 1: raise ValueError("Input value of lmax={0} ".format(lmax) + "is not allowed; it must be greater than 0 and should be greater " + "than |s|={0}.".format(abs(s))) import numpy as np salm = np.ascontiguousarray(salm, dtype=np.complex128) if salm.shape[-1] < N_lm(lmax): raise ValueError("The input `salm` array of shape {0} is too small for the stated `lmax` of {1}. ".format(salm.shape, lmax) + "Perhaps you forgot to include the (zero) modes with ell<|s|.") map = np.empty(salm.shape[:-1]+(Ntheta, Nphi), dtype=np.complex128) if salm.ndim>1: s = np.ascontiguousarray(s, dtype=np.intc) if s.ndim != salm.ndim-1 or np.product(s.shape) != np.product(salm.shape[:-1]): s = s*np.ones(salm.shape[:-1], dtype=np.intc) _multi_salm2map(salm, map, s, lmax, Ntheta, Nphi) else: _salm2map(salm, map, s, lmax, Ntheta, Nphi) return map
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:map2salm; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:map; 5, identifier:s; 6, identifier:lmax; 7, block; 7, 8; 7, 10; 7, 15; 7, 29; 7, 56; 7, 152; 8, expression_statement; 8, 9; 9, comment; 10, import_statement; 10, 11; 11, aliased_import; 11, 12; 11, 14; 12, dotted_name; 12, 13; 13, identifier:numpy; 14, identifier:np; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:map; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:np; 21, identifier:ascontiguousarray; 22, argument_list; 22, 23; 22, 24; 23, identifier:map; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:dtype; 26, attribute; 26, 27; 26, 28; 27, identifier:np; 28, identifier:complex128; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:salm; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:np; 35, identifier:empty; 36, argument_list; 36, 37; 36, 51; 37, binary_operator:+; 37, 38; 37, 46; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:map; 41, identifier:shape; 42, slice; 42, 43; 42, 44; 43, colon; 44, unary_operator:-; 44, 45; 45, integer:2; 46, tuple; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:N_lm; 49, argument_list; 49, 50; 50, identifier:lmax; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:dtype; 53, attribute; 53, 54; 53, 55; 54, identifier:np; 55, identifier:complex128; 56, if_statement; 56, 57; 56, 62; 56, 142; 57, comparison_operator:>; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:map; 60, identifier:ndim; 61, integer:2; 62, block; 62, 63; 62, 77; 62, 134; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:s; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:np; 69, identifier:ascontiguousarray; 70, argument_list; 70, 71; 70, 72; 71, identifier:s; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:dtype; 74, attribute; 74, 75; 74, 76; 75, identifier:np; 76, identifier:intc; 77, if_statement; 77, 78; 77, 110; 78, boolean_operator:or; 78, 79; 78, 88; 79, comparison_operator:!=; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:s; 82, identifier:ndim; 83, binary_operator:-; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:map; 86, identifier:ndim; 87, integer:2; 88, comparison_operator:!=; 88, 89; 88, 97; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:np; 92, identifier:product; 93, argument_list; 93, 94; 94, attribute; 94, 95; 94, 96; 95, identifier:s; 96, identifier:shape; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:np; 100, identifier:product; 101, argument_list; 101, 102; 102, subscript; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:map; 105, identifier:shape; 106, slice; 106, 107; 106, 108; 107, colon; 108, unary_operator:-; 108, 109; 109, integer:2; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:s; 114, binary_operator:*; 114, 115; 114, 116; 115, identifier:s; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:np; 119, identifier:ones; 120, argument_list; 120, 121; 120, 129; 121, subscript; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:map; 124, identifier:shape; 125, slice; 125, 126; 125, 127; 126, colon; 127, unary_operator:-; 127, 128; 128, integer:2; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:dtype; 131, attribute; 131, 132; 131, 133; 132, identifier:np; 133, identifier:intc; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:_multi_map2salm; 137, argument_list; 137, 138; 137, 139; 137, 140; 137, 141; 138, identifier:map; 139, identifier:salm; 140, identifier:s; 141, identifier:lmax; 142, else_clause; 142, 143; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:_map2salm; 147, argument_list; 147, 148; 147, 149; 147, 150; 147, 151; 148, identifier:map; 149, identifier:salm; 150, identifier:s; 151, identifier:lmax; 152, return_statement; 152, 153; 153, identifier:salm
def map2salm(map, s, lmax): """Convert values of spin-weighted function on a grid to mode weights Parameters ---------- map : array_like, complex, shape (..., Ntheta, Nphi) Values of the spin-weighted function on grid points of the sphere. This array may have more than two dimensions, where initial dimensions may represent different times, for example, or separate functions on the sphere. The final two dimensions should give the values of the function, in the order described below in the 'Notes' section. s : int or array, int, shape (...) Spin weight of the function. If `amp` is multidimensional and this is an array, its dimensions must match the first dimensions of `map`, and the different values are the spin weights of the different functions represented by those dimensions. Otherwise, if `map` is multidimensional and `s` is a single integer, all functions are assumed to have the same spin weight. lmax : int The largest `ell` value present in the input array. Returns ------- salm : ndarray, complex, shape (..., (lmax+1)**2) Mode weights of the spin-weighted function. This array is shaped like the input `map` array, but has one less dimension. The final dimension describes the values of the mode weights on the corresponding sphere, as described below in the 'Notes' section. See also -------- spinsfast.map2salm : Roughly the inverse of this function. Notes ----- The input data represent the values on this grid of spherical coordinates: np.array([[map(theta, phi) for phi in np.linspace(0.0, 2*np.pi, num=2*lmax+1, endpoint=False)] for theta in np.linspace(0.0, np.pi, num=2*lmax+1, endpoint=True)]) The input is converted to a contiguous complex numpy array if necessary. The output `salm` data are given in increasing order of `ell` value, always starting with (ell, m) = (0, 0) even if `s` is nonzero, proceeding to (1, -1), (1, 0), (1, 1), etc. Explicitly, the ordering matches this: [map_lm(ell, m) for ell in range(lmax+1) for m in range(-ell, ell+1)] Note that `map2salm` and `salm2map` are not true inverses of each other for several reasons. First, modes with `ell < |s|` should always be zero; they are simply assumed to be zero on input to `salm2map`. It is possible to define a `map` function that violates this assumption -- for example, having a nonzero average value over the sphere, if the function has nonzero spin `s`, this is impossible. Also, it is possible to define a map of a function with so much angular dependence that it cannot be captured with the given `lmax` value. For example, a discontinuous function will never be perfectly resolved. Example ------- >>> s = -2 >>> lmax = 8 >>> theta_phi = np.array([[[theta, phi] for phi in np.linspace(0.0, 2*np.pi, num=2*lmax+1, endpoint=False)] for theta in np.linspace(0.0, np.pi, num=2*lmax+1, endpoint=True)]) >>> map = np.array([[np.sqrt(3/(8*np.pi)) * np.sin(tp[0]) for tp in _] for _ in theta_phi]) >>> salm = spinsfast.map2salm(map, s, lmax) """ import numpy as np map = np.ascontiguousarray(map, dtype=np.complex128) salm = np.empty(map.shape[:-2]+(N_lm(lmax),), dtype=np.complex128) if map.ndim>2: s = np.ascontiguousarray(s, dtype=np.intc) if s.ndim != map.ndim-2 or np.product(s.shape) != np.product(map.shape[:-2]): s = s*np.ones(map.shape[:-2], dtype=np.intc) _multi_map2salm(map, salm, s, lmax) else: _map2salm(map, salm, s, lmax) return salm
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:get; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:url; 6, default_parameter; 6, 7; 6, 8; 7, identifier:store_on_error; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:xpath; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:rate_limit; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:log_hits; 17, True; 18, default_parameter; 18, 19; 18, 20; 19, identifier:log_misses; 20, True; 21, block; 21, 22; 21, 24; 21, 346; 22, expression_statement; 22, 23; 23, comment; 24, try_statement; 24, 25; 24, 26; 24, 79; 25, comment; 26, block; 26, 27; 26, 41; 26, 55; 26, 56; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:cached; 30, call; 30, 31; 30, 40; 31, attribute; 31, 32; 31, 39; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_query; 36, argument_list; 36, 37; 36, 38; 37, identifier:url; 38, identifier:xpath; 39, identifier:one; 40, argument_list; 41, if_statement; 41, 42; 41, 43; 42, identifier:log_hits; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:config; 49, identifier:logger; 50, identifier:info; 51, argument_list; 51, 52; 52, binary_operator:+; 52, 53; 52, 54; 53, string:"Request cache hit: "; 54, identifier:url; 55, comment; 56, if_statement; 56, 57; 56, 66; 57, comparison_operator:!=; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:cached; 60, identifier:status_code; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:requests; 64, identifier:codes; 65, identifier:ok; 66, block; 66, 67; 67, raise_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:RuntimeError; 70, argument_list; 70, 71; 71, binary_operator:+; 71, 72; 71, 73; 72, string:"Cached request returned an error, code "; 73, call; 73, 74; 73, 75; 74, identifier:str; 75, argument_list; 75, 76; 76, attribute; 76, 77; 76, 78; 77, identifier:cached; 78, identifier:status_code; 79, except_clause; 79, 80; 79, 81; 80, identifier:NoResultFound; 81, block; 81, 82; 81, 96; 81, 97; 81, 263; 81, 264; 81, 294; 81, 295; 81, 323; 82, if_statement; 82, 83; 82, 84; 83, identifier:log_misses; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:config; 90, identifier:logger; 91, identifier:info; 92, argument_list; 92, 93; 93, binary_operator:+; 93, 94; 93, 95; 94, string:"Request cache miss: "; 95, identifier:url; 96, comment; 97, try_statement; 97, 98; 97, 99; 97, 243; 98, comment; 99, block; 99, 100; 99, 144; 99, 156; 99, 165; 99, 171; 99, 172; 99, 178; 99, 184; 100, if_statement; 100, 101; 100, 110; 101, boolean_operator:and; 101, 102; 101, 105; 102, comparison_operator:is; 102, 103; 102, 104; 103, identifier:rate_limit; 104, None; 105, comparison_operator:is; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:last_query; 109, None; 110, block; 110, 111; 110, 132; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:to_sleep; 114, binary_operator:-; 114, 115; 114, 116; 115, identifier:rate_limit; 116, call; 116, 117; 116, 131; 117, attribute; 117, 118; 117, 130; 118, parenthesized_expression; 118, 119; 119, binary_operator:-; 119, 120; 119, 127; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:datetime; 124, identifier:datetime; 125, identifier:now; 126, argument_list; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:last_query; 130, identifier:total_seconds; 131, argument_list; 132, if_statement; 132, 133; 132, 136; 133, comparison_operator:>; 133, 134; 133, 135; 134, identifier:to_sleep; 135, integer:0; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:time; 141, identifier:sleep; 142, argument_list; 142, 143; 143, identifier:to_sleep; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:last_query; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:datetime; 153, identifier:datetime; 154, identifier:now; 155, argument_list; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:response; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:requests; 162, identifier:get; 163, argument_list; 163, 164; 164, identifier:url; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:status_code; 168, attribute; 168, 169; 168, 170; 169, identifier:response; 170, identifier:status_code; 171, comment; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:content; 175, attribute; 175, 176; 175, 177; 176, identifier:response; 177, identifier:text; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:response; 182, identifier:close; 183, argument_list; 184, if_statement; 184, 185; 184, 188; 185, comparison_operator:is; 185, 186; 185, 187; 186, identifier:xpath; 187, None; 188, block; 188, 189; 188, 198; 188, 207; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:doc; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:html; 195, identifier:fromstring; 196, argument_list; 196, 197; 197, identifier:content; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:nodes; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:doc; 204, identifier:xpath; 205, argument_list; 205, 206; 206, identifier:xpath; 207, if_statement; 207, 208; 207, 214; 207, 215; 207, 226; 208, comparison_operator:==; 208, 209; 208, 213; 209, call; 209, 210; 209, 211; 210, identifier:len; 211, argument_list; 211, 212; 212, identifier:nodes; 213, integer:0; 214, comment; 215, block; 215, 216; 215, 222; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:content; 219, binary_operator:+; 219, 220; 219, 221; 220, string:"xpath not found: "; 221, identifier:xpath; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:status_code; 225, identifier:ERROR_XPATH_NOT_FOUND; 226, else_clause; 226, 227; 226, 228; 227, comment; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:content; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:html; 235, identifier:tostring; 236, argument_list; 236, 237; 236, 240; 237, subscript; 237, 238; 237, 239; 238, identifier:nodes; 239, integer:0; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:encoding; 242, string:'unicode'; 243, except_clause; 243, 244; 243, 250; 243, 251; 244, as_pattern; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:requests; 247, identifier:ConnectionError; 248, as_pattern_target; 248, 249; 249, identifier:e; 250, comment; 251, block; 251, 252; 251, 256; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:status_code; 255, identifier:ERROR_CONNECTION_ERROR; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:content; 259, call; 259, 260; 259, 261; 260, identifier:str; 261, argument_list; 261, 262; 262, identifier:e; 263, comment; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:cached; 267, call; 267, 268; 267, 269; 268, identifier:CachedRequest; 269, argument_list; 269, 270; 269, 276; 269, 279; 269, 282; 269, 285; 270, keyword_argument; 270, 271; 270, 272; 271, identifier:url; 272, call; 272, 273; 272, 274; 273, identifier:str; 274, argument_list; 274, 275; 275, identifier:url; 276, keyword_argument; 276, 277; 276, 278; 277, identifier:content; 278, identifier:content; 279, keyword_argument; 279, 280; 279, 281; 280, identifier:status_code; 281, identifier:status_code; 282, keyword_argument; 282, 283; 282, 284; 283, identifier:xpath; 284, identifier:xpath; 285, keyword_argument; 285, 286; 285, 287; 286, identifier:queried_on; 287, call; 287, 288; 287, 293; 288, attribute; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:datetime; 291, identifier:datetime; 292, identifier:now; 293, argument_list; 294, comment; 295, if_statement; 295, 296; 295, 305; 296, boolean_operator:or; 296, 297; 296, 304; 297, comparison_operator:==; 297, 298; 297, 299; 298, identifier:status_code; 299, attribute; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:requests; 302, identifier:codes; 303, identifier:ok; 304, identifier:store_on_error; 305, block; 305, 306; 305, 315; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 313; 308, attribute; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:self; 311, identifier:session; 312, identifier:add; 313, argument_list; 313, 314; 314, identifier:cached; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 322; 317, attribute; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:self; 320, identifier:session; 321, identifier:commit; 322, argument_list; 323, if_statement; 323, 324; 323, 331; 324, comparison_operator:!=; 324, 325; 324, 326; 325, identifier:status_code; 326, attribute; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:requests; 329, identifier:codes; 330, identifier:ok; 331, block; 331, 332; 332, raise_statement; 332, 333; 333, call; 333, 334; 333, 335; 334, identifier:RuntimeError; 335, argument_list; 335, 336; 336, binary_operator:+; 336, 337; 336, 345; 337, binary_operator:+; 337, 338; 337, 344; 338, binary_operator:+; 338, 339; 338, 340; 339, string:"Error processing the request, "; 340, call; 340, 341; 340, 342; 341, identifier:str; 342, argument_list; 342, 343; 343, identifier:status_code; 344, string:": "; 345, identifier:content; 346, return_statement; 346, 347; 347, attribute; 347, 348; 347, 349; 348, identifier:cached; 349, identifier:content
def get(self, url, store_on_error=False, xpath=None, rate_limit=None, log_hits=True, log_misses=True): """Get a URL via the cache. If the URL exists in the cache, return the cached value. Otherwise perform the request, store the resulting content in the cache and return it. Throws a :class:`RuntimeError` if the request results in an error. Args: url (str): URL to request store_on_error (bool): If True, store request results in cache even if request results in an an error. Otherwise (default) do not store results when an error occurs. Cached content equals exception message. xpath (str): If given (default is None), parses the response content to html, searches the first node matching the given xpath and returns only that node (as UTF8-encoded html). Also, only stores this node's html in the cache. Raises a ``RuntimeError`` if the xpath cannot be found in the response. rate_limit (float): If not None (default), wait at least this many seconds between the previous request and the current one (this does not apply to cache hits). log_hits (bool): If True, log cache hits log_misses (bool): If True, log cache misses Returns: str: request content """ try: # get cached request - if none is found, this throws a NoResultFound exception cached = self._query(url, xpath).one() if log_hits: config.logger.info("Request cache hit: " + url) # if the cached value is from a request that resulted in an error, throw an exception if cached.status_code != requests.codes.ok: raise RuntimeError("Cached request returned an error, code " + str(cached.status_code)) except NoResultFound: if log_misses: config.logger.info("Request cache miss: " + url) # perform the request try: # rate limit if rate_limit is not None and self.last_query is not None: to_sleep = rate_limit - (datetime.datetime.now() - self.last_query).total_seconds() if to_sleep > 0: time.sleep(to_sleep) self.last_query = datetime.datetime.now() response = requests.get(url) status_code = response.status_code # get 'text', not 'content', because then we are sure to get unicode content = response.text response.close() if xpath is not None: doc = html.fromstring(content) nodes = doc.xpath(xpath) if len(nodes) == 0: # xpath not found; set content and status code, exception is raised below content = "xpath not found: " + xpath status_code = ERROR_XPATH_NOT_FOUND else: # extract desired node only content = html.tostring(nodes[0], encoding='unicode') except requests.ConnectionError as e: # on a connection error, write exception information to a response object status_code = ERROR_CONNECTION_ERROR content = str(e) # a new request cache object cached = CachedRequest(url=str(url), content=content, status_code=status_code, xpath=xpath, queried_on=datetime.datetime.now()) # if desired, store the response even if an error occurred if status_code == requests.codes.ok or store_on_error: self.session.add(cached) self.session.commit() if status_code != requests.codes.ok: raise RuntimeError("Error processing the request, " + str(status_code) + ": " + content) return cached.content
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:event; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:event_data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:priority; 8, string:"normal"; 9, default_parameter; 9, 10; 9, 11; 10, identifier:event_method; 11, string:"EVENT"; 12, block; 12, 13; 12, 15; 12, 27; 12, 28; 12, 36; 12, 63; 12, 78; 12, 79; 12, 108; 12, 109; 12, 149; 12, 173; 12, 192; 12, 193; 12, 194; 12, 205; 12, 206; 12, 227; 12, 242; 13, expression_statement; 13, 14; 14, comment; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:logger; 19, identifier:debug; 20, argument_list; 20, 21; 21, binary_operator:+; 21, 22; 21, 23; 22, string:"event: "; 23, call; 23, 24; 23, 25; 24, identifier:str; 25, argument_list; 25, 26; 26, identifier:event_data; 27, comment; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:euuid; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:uuid; 34, identifier:uuid1; 35, argument_list; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:logger; 40, identifier:debug; 41, argument_list; 41, 42; 42, binary_operator:%; 42, 43; 42, 46; 43, concatenated_string; 43, 44; 43, 45; 44, string:"<%s> <euuid:%s> Sending event data to server: "; 45, string:"%s"; 46, tuple; 46, 47; 46, 53; 46, 57; 47, call; 47, 48; 47, 49; 48, identifier:str; 49, argument_list; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:cuuid; 53, call; 53, 54; 53, 55; 54, identifier:str; 55, argument_list; 55, 56; 56, identifier:euuid; 57, call; 57, 58; 57, 59; 58, identifier:str; 59, argument_list; 59, 60; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:server; 63, if_statement; 63, 64; 63, 70; 64, not_operator; 64, 65; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:listener; 69, identifier:listening; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:logger; 75, identifier:warning; 76, argument_list; 76, 77; 77, string:"Neteria client is not listening."; 78, comment; 79, if_statement; 79, 80; 79, 84; 80, not_operator; 80, 81; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:registered; 84, block; 84, 85; 84, 106; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:logger; 89, identifier:warning; 90, argument_list; 90, 91; 91, binary_operator:%; 91, 92; 91, 95; 92, concatenated_string; 92, 93; 92, 94; 93, string:"<%s> <euuid:%s> Client is currently not registered. "; 94, string:"Event not sent."; 95, tuple; 95, 96; 95, 102; 96, call; 96, 97; 96, 98; 97, identifier:str; 98, argument_list; 98, 99; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:cuuid; 102, call; 102, 103; 102, 104; 103, identifier:str; 104, argument_list; 104, 105; 105, identifier:euuid; 106, return_statement; 106, 107; 107, False; 108, comment; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:packet; 112, dictionary; 112, 113; 112, 116; 112, 124; 112, 130; 112, 133; 112, 143; 112, 146; 113, pair; 113, 114; 113, 115; 114, string:"method"; 115, identifier:event_method; 116, pair; 116, 117; 116, 118; 117, string:"cuuid"; 118, call; 118, 119; 118, 120; 119, identifier:str; 120, argument_list; 120, 121; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:cuuid; 124, pair; 124, 125; 124, 126; 125, string:"euuid"; 126, call; 126, 127; 126, 128; 127, identifier:str; 128, argument_list; 128, 129; 129, identifier:euuid; 130, pair; 130, 131; 130, 132; 131, string:"event_data"; 132, identifier:event_data; 133, pair; 133, 134; 133, 135; 134, string:"timestamp"; 135, call; 135, 136; 135, 137; 136, identifier:str; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:datetime; 141, identifier:now; 142, argument_list; 143, pair; 143, 144; 143, 145; 144, string:"retry"; 145, integer:0; 146, pair; 146, 147; 146, 148; 147, string:"priority"; 148, identifier:priority; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:listener; 155, identifier:send_datagram; 156, argument_list; 156, 157; 156, 170; 157, call; 157, 158; 157, 159; 158, identifier:serialize_data; 159, argument_list; 159, 160; 159, 161; 159, 164; 159, 167; 160, identifier:packet; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:compression; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:encryption; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:server_key; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:server; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:logger; 177, identifier:debug; 178, argument_list; 178, 179; 179, binary_operator:%; 179, 180; 179, 181; 180, string:"<%s> Sending EVENT Packet: %s"; 181, tuple; 181, 182; 181, 188; 182, call; 182, 183; 182, 184; 183, identifier:str; 184, argument_list; 184, 185; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:cuuid; 188, call; 188, 189; 188, 190; 189, identifier:pformat; 190, argument_list; 190, 191; 191, identifier:packet; 192, comment; 193, comment; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 204; 196, subscript; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:event_uuids; 200, call; 200, 201; 200, 202; 201, identifier:str; 202, argument_list; 202, 203; 203, identifier:euuid; 204, identifier:packet; 205, comment; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:logger; 210, identifier:debug; 211, argument_list; 211, 212; 212, binary_operator:%; 212, 213; 212, 214; 213, string:"<%s> Scheduling retry in %s seconds"; 214, tuple; 214, 215; 214, 221; 215, call; 215, 216; 215, 217; 216, identifier:str; 217, argument_list; 217, 218; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:cuuid; 221, call; 221, 222; 221, 223; 222, identifier:str; 223, argument_list; 223, 224; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:timeout; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:listener; 233, identifier:call_later; 234, argument_list; 234, 235; 234, 238; 234, 241; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:timeout; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:retransmit; 241, identifier:packet; 242, return_statement; 242, 243; 243, identifier:euuid
def event(self, event_data, priority="normal", event_method="EVENT"): """This function will send event packets to the server. This is the main method you would use to send data from your application to the server. Whenever an event is sent to the server, a universally unique event id (euuid) is created for each event and stored in the "event_uuids" dictionary. This dictionary contains a list of all events that are currently waiting for a response from the server. The event will only be removed from this dictionary if the server responds with LEGAL or ILLEGAL or if the request times out. Args: event_data (dict): The event data to send to the server. This data will be passed through the server's middleware to determine if the event is legal or not, and then processed by the server it is legal priority (string): The event's priority informs the server of whether or not the client is going to wait for a confirmation message from the server indicating whether its event was LEGAL or ILLEGAL. Setting this to "normal" informs the server that the client will wait for a response from the server before processing the event. Setting this to "high" informs the server that the client will NOT wait for a response. Defaults to "normal". event_method (string): The type of event to send to the server. Valid methods are "EVENT", "AUTH". Defaults to "EVENT". Returns: A universally unique identifier (uuid) of the event. Examples: >>> event_data >>> priority """ logger.debug("event: " + str(event_data)) # Generate an event UUID for this event euuid = uuid.uuid1() logger.debug("<%s> <euuid:%s> Sending event data to server: " "%s" % (str(self.cuuid), str(euuid), str(self.server))) if not self.listener.listening: logger.warning("Neteria client is not listening.") # If we're not even registered, don't even bother. if not self.registered: logger.warning("<%s> <euuid:%s> Client is currently not registered. " "Event not sent." % (str(self.cuuid), str(euuid))) return False # Send the event data to the server packet = {"method": event_method, "cuuid": str(self.cuuid), "euuid": str(euuid), "event_data": event_data, "timestamp": str(datetime.now()), "retry": 0, "priority": priority} self.listener.send_datagram( serialize_data(packet, self.compression, self.encryption, self.server_key), self.server) logger.debug("<%s> Sending EVENT Packet: %s" % (str(self.cuuid), pformat(packet))) # Set the sent event to our event buffer to see if we need to roll back # or anything self.event_uuids[str(euuid)] = packet # Now we need to reschedule a timeout/retransmit check logger.debug("<%s> Scheduling retry in %s seconds" % (str(self.cuuid), str(self.timeout))) self.listener.call_later(self.timeout, self.retransmit, packet) return euuid
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:run; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 13; 5, 14; 5, 34; 5, 56; 5, 57; 5, 72; 5, 82; 5, 83; 5, 89; 5, 90; 5, 96; 5, 97; 5, 228; 5, 229; 5, 233; 5, 234; 5, 247; 5, 248; 5, 249; 5, 375; 5, 376; 5, 385; 5, 393; 6, expression_statement; 6, 7; 7, comment; 8, import_statement; 8, 9; 9, aliased_import; 9, 10; 9, 12; 10, dotted_name; 10, 11; 11, identifier:numpy; 12, identifier:np; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:query; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:session; 22, identifier:query; 23, argument_list; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:models; 27, identifier:NUTS2Region; 28, identifier:key; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:models; 32, identifier:NUTS2Region; 33, identifier:id; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:region_ids; 37, call; 37, 38; 37, 55; 38, attribute; 38, 39; 38, 54; 39, subscript; 39, 40; 39, 53; 40, call; 40, 41; 40, 51; 41, attribute; 41, 42; 41, 50; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:client; 47, identifier:df_query; 48, argument_list; 48, 49; 49, identifier:query; 50, identifier:set_index; 51, argument_list; 51, 52; 52, string:'key'; 53, string:'id'; 54, identifier:to_dict; 55, argument_list; 56, comment; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:data; 60, call; 60, 61; 60, 71; 61, attribute; 61, 62; 61, 70; 62, call; 62, 63; 62, 64; 63, identifier:next; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:requires; 69, argument_list; 70, identifier:load; 71, argument_list; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:nuts; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, call; 77, 78; 77, 79; 78, identifier:NUTS2GeoJSONInputFile; 79, argument_list; 80, identifier:load; 81, argument_list; 82, comment; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:indicator_ids; 86, call; 86, 87; 86, 88; 87, identifier:dict; 88, argument_list; 89, comment; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:t_data; 93, call; 93, 94; 93, 95; 94, identifier:dict; 95, argument_list; 96, comment; 97, for_statement; 97, 98; 97, 101; 97, 106; 97, 107; 98, pattern_list; 98, 99; 98, 100; 99, identifier:season; 100, identifier:suffix; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:CLIMATE_SEASON_SUFFIXES; 104, identifier:items; 105, argument_list; 106, comment; 107, block; 107, 108; 107, 123; 107, 132; 107, 133; 107, 141; 107, 149; 107, 150; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:indicator; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:models; 114, identifier:ClimateIndicator; 115, argument_list; 115, 116; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:description; 118, binary_operator:+; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:description; 122, identifier:suffix; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:session; 129, identifier:add; 130, argument_list; 130, 131; 131, identifier:indicator; 132, comment; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:session; 139, identifier:commit; 140, argument_list; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:indicator_ids; 145, identifier:season; 146, attribute; 146, 147; 146, 148; 147, identifier:indicator; 148, identifier:id; 149, comment; 150, if_statement; 150, 151; 150, 154; 150, 182; 151, comparison_operator:==; 151, 152; 151, 153; 152, identifier:season; 153, string:'summer'; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:t_data; 159, identifier:season; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:np; 164, identifier:ma; 165, identifier:average; 166, argument_list; 166, 167; 166, 179; 167, subscript; 167, 168; 167, 171; 167, 175; 167, 177; 168, subscript; 168, 169; 168, 170; 169, identifier:data; 170, string:'data'; 171, slice; 171, 172; 171, 173; 171, 174; 172, integer:3; 173, colon; 174, integer:9; 175, slice; 175, 176; 176, colon; 177, slice; 177, 178; 178, colon; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:axis; 181, integer:0; 182, else_clause; 182, 183; 182, 184; 183, comment; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:t_data; 189, identifier:season; 190, call; 190, 191; 190, 196; 191, attribute; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:np; 194, identifier:ma; 195, identifier:average; 196, argument_list; 196, 197; 196, 225; 197, binary_operator:*; 197, 198; 197, 199; 198, float:0.5; 199, parenthesized_expression; 199, 200; 200, binary_operator:+; 200, 201; 200, 213; 201, subscript; 201, 202; 201, 205; 201, 209; 201, 211; 202, subscript; 202, 203; 202, 204; 203, identifier:data; 204, string:'data'; 205, slice; 205, 206; 205, 207; 205, 208; 206, integer:0; 207, colon; 208, integer:3; 209, slice; 209, 210; 210, colon; 211, slice; 211, 212; 212, colon; 213, subscript; 213, 214; 213, 217; 213, 221; 213, 223; 214, subscript; 214, 215; 214, 216; 215, identifier:data; 216, string:'data'; 217, slice; 217, 218; 217, 219; 217, 220; 218, integer:9; 219, colon; 220, integer:12; 221, slice; 221, 222; 222, colon; 223, slice; 223, 224; 224, colon; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:axis; 227, integer:0; 228, comment; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:objects; 232, list:[]; 233, comment; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:current_value_id; 237, call; 237, 238; 237, 243; 238, attribute; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:models; 241, identifier:ClimateValue; 242, identifier:get_max_id; 243, argument_list; 243, 244; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:session; 247, comment; 248, comment; 249, for_statement; 249, 250; 249, 251; 249, 252; 249, 253; 250, identifier:feature; 251, identifier:nuts; 252, comment; 253, block; 253, 254; 253, 280; 253, 281; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:mask; 257, call; 257, 258; 257, 259; 258, identifier:geojson_polygon_to_mask; 259, argument_list; 259, 260; 259, 263; 259, 270; 259, 275; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:feature; 262, identifier:feature; 263, keyword_argument; 263, 264; 263, 265; 264, identifier:shape; 265, attribute; 265, 266; 265, 269; 266, subscript; 266, 267; 266, 268; 267, identifier:t_data; 268, string:'summer'; 269, identifier:shape; 270, keyword_argument; 270, 271; 270, 272; 271, identifier:lat_idx; 272, subscript; 272, 273; 272, 274; 273, identifier:data; 274, string:'lat_idx'; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:lon_idx; 277, subscript; 277, 278; 277, 279; 278, identifier:data; 279, string:'lon_idx'; 280, comment; 281, for_statement; 281, 282; 281, 283; 281, 291; 281, 292; 282, identifier:season; 283, call; 283, 284; 283, 285; 284, identifier:list; 285, argument_list; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:CLIMATE_SEASON_SUFFIXES; 289, identifier:keys; 290, argument_list; 291, comment; 292, block; 292, 293; 292, 309; 292, 310; 292, 324; 292, 336; 292, 337; 292, 341; 292, 366; 292, 367; 292, 368; 292, 369; 292, 370; 292, 371; 292, 372; 292, 373; 292, 374; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:value; 296, call; 296, 297; 296, 302; 297, attribute; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:np; 300, identifier:ma; 301, identifier:average; 302, argument_list; 302, 303; 302, 306; 303, subscript; 303, 304; 303, 305; 304, identifier:t_data; 305, identifier:season; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:weights; 308, identifier:mask; 309, comment; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:region_id; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:region_ids; 316, identifier:get; 317, argument_list; 317, 318; 317, 323; 318, subscript; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:feature; 321, identifier:properties; 322, string:'NUTS_ID'; 323, None; 324, if_statement; 324, 325; 324, 328; 325, comparison_operator:is; 325, 326; 325, 327; 326, identifier:region_id; 327, None; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 332; 331, identifier:region_id; 332, call; 332, 333; 332, 334; 333, identifier:int; 334, argument_list; 334, 335; 335, identifier:region_id; 336, comment; 337, expression_statement; 337, 338; 338, augmented_assignment:+=; 338, 339; 338, 340; 339, identifier:current_value_id; 340, integer:1; 341, expression_statement; 341, 342; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:objects; 345, identifier:append; 346, argument_list; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:models; 350, identifier:ClimateValue; 351, argument_list; 351, 352; 351, 355; 351, 358; 351, 361; 352, keyword_argument; 352, 353; 352, 354; 353, identifier:id; 354, identifier:current_value_id; 355, keyword_argument; 355, 356; 355, 357; 356, identifier:value; 357, identifier:value; 358, keyword_argument; 358, 359; 358, 360; 359, identifier:region_id; 360, identifier:region_id; 361, keyword_argument; 361, 362; 361, 363; 362, identifier:indicator_id; 363, subscript; 363, 364; 363, 365; 364, identifier:indicator_ids; 365, identifier:season; 366, comment; 367, comment; 368, comment; 369, comment; 370, comment; 371, comment; 372, comment; 373, comment; 374, comment; 375, comment; 376, expression_statement; 376, 377; 377, call; 377, 378; 377, 383; 378, attribute; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:self; 381, identifier:session; 382, identifier:bulk_save_objects; 383, argument_list; 383, 384; 384, identifier:objects; 385, expression_statement; 385, 386; 386, call; 386, 387; 386, 392; 387, attribute; 387, 388; 387, 391; 388, attribute; 388, 389; 388, 390; 389, identifier:self; 390, identifier:session; 391, identifier:commit; 392, argument_list; 393, expression_statement; 393, 394; 394, call; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:self; 397, identifier:done; 398, argument_list
def run(self): """Load climate data and convert to indicator objects """ import numpy as np # get all NUTS region IDs, for linking values to region objects query = self.session.query(models.NUTS2Region.key, models.NUTS2Region.id) region_ids = self.client.df_query(query).set_index('key')['id'].to_dict() # load climate data and NUTS2 polygons data = next(self.requires()).load() nuts = NUTS2GeoJSONInputFile().load() # generated indicator IDs, keyed by season indicator_ids = dict() # climate data by season t_data = dict() # create new indicator objects for summer and winter, create averaged climate data for season, suffix in CLIMATE_SEASON_SUFFIXES.items(): # noinspection PyUnresolvedReferences indicator = models.ClimateIndicator(description=self.description + suffix) self.session.add(indicator) # commit, to get indicator ID filled self.session.commit() indicator_ids[season] = indicator.id # select winter or summer data by month index, average over time range if season == 'summer': t_data[season] = np.ma.average(data['data'][3:9, :, :], axis=0) else: # noinspection PyTypeChecker t_data[season] = np.ma.average(0.5 * (data['data'][0:3, :, :] + data['data'][9:12, :, :]), axis=0) # container for output objects, for bulk saving objects = [] # start value for manual object id generation current_value_id = models.ClimateValue.get_max_id(self.session) # for each region, get a mask, average climate variable over the mask and store the indicator value; # loop over features first, then over seasons, because mask generation is expensive for feature in nuts: # draw region mask (doesn't matter for which season we take the map shape) mask = geojson_polygon_to_mask(feature=feature, shape=t_data['summer'].shape, lat_idx=data['lat_idx'], lon_idx=data['lon_idx']) # create indicator values for summer and winter for season in list(CLIMATE_SEASON_SUFFIXES.keys()): # weighted average from region mask value = np.ma.average(t_data[season], weights=mask) # region ID must be cast to int (DBs don't like numpy dtypes from pandas) region_id = region_ids.get(feature.properties['NUTS_ID'], None) if region_id is not None: region_id = int(region_id) # append an indicator value, manually generate object IDs for bulk saving current_value_id += 1 objects.append(models.ClimateValue(id=current_value_id, value=value, region_id=region_id, indicator_id=indicator_ids[season])) # # print some debugging output # print self.variable_name + ' ' + season, feature.properties['NUTS_ID'], value # # generate some plots for debugging # from matplotlib import pyplot as plt # plt.subplot(211) # plt.imshow(0.02 * t_data + mask * t_data, interpolation='none') # plt.subplot(212) # plt.imshow(t_data, interpolation='none') # plt.savefig('/tmp/' + feature.properties['NUTS_ID'] + '.png') # bulk-save all objects self.session.bulk_save_objects(objects) self.session.commit() self.done()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:dapply; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:fn; 6, default_parameter; 6, 7; 6, 8; 7, identifier:pairwise; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:symmetric; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:diagonal; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:block; 17, None; 18, dictionary_splat_pattern; 18, 19; 19, identifier:kwargs; 20, block; 20, 21; 20, 23; 20, 50; 20, 59; 20, 75; 20, 79; 20, 222; 21, expression_statement; 21, 22; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:search_keys; 26, list_comprehension; 26, 27; 26, 28; 26, 37; 27, identifier:k; 28, for_in_clause; 28, 29; 28, 32; 29, pattern_list; 29, 30; 29, 31; 30, identifier:k; 31, identifier:v; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:kwargs; 35, identifier:items; 36, argument_list; 37, if_clause; 37, 38; 38, boolean_operator:and; 38, 39; 38, 44; 39, call; 39, 40; 39, 41; 40, identifier:isinstance; 41, argument_list; 41, 42; 41, 43; 42, identifier:v; 43, identifier:list; 44, comparison_operator:>; 44, 45; 44, 49; 45, call; 45, 46; 45, 47; 46, identifier:len; 47, argument_list; 47, 48; 48, identifier:v; 49, integer:1; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:functions; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:util; 56, identifier:make_list; 57, argument_list; 57, 58; 58, identifier:fn; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:search; 62, call; 62, 63; 62, 64; 63, identifier:list; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:product; 67, argument_list; 67, 68; 67, 69; 68, identifier:functions; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:util; 72, identifier:dict_product; 73, argument_list; 73, 74; 74, identifier:kwargs; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:results; 78, list:[]; 79, for_statement; 79, 80; 79, 83; 79, 84; 80, pattern_list; 80, 81; 80, 82; 81, identifier:fn; 82, identifier:kw; 83, identifier:search; 84, block; 84, 85; 84, 133; 84, 148; 84, 162; 84, 215; 85, if_statement; 85, 86; 85, 88; 85, 112; 86, not_operator; 86, 87; 87, identifier:pairwise; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:r; 92, call; 92, 93; 92, 102; 93, attribute; 93, 94; 93, 101; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:index; 99, identifier:to_series; 100, argument_list; 101, identifier:apply; 102, argument_list; 102, 103; 103, lambda; 103, 104; 103, 106; 104, lambda_parameters; 104, 105; 105, identifier:step; 106, call; 106, 107; 106, 108; 107, identifier:fn; 108, argument_list; 108, 109; 108, 110; 109, identifier:step; 110, dictionary_splat; 110, 111; 111, identifier:kw; 112, else_clause; 112, 113; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:r; 117, call; 117, 118; 117, 119; 118, identifier:apply_pairwise; 119, argument_list; 119, 120; 119, 121; 119, 122; 119, 125; 119, 128; 119, 131; 120, identifier:self; 121, identifier:fn; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:symmetric; 124, identifier:symmetric; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:diagonal; 127, identifier:diagonal; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:block; 130, identifier:block; 131, dictionary_splat; 131, 132; 132, identifier:kw; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:name; 136, conditional_expression:if; 136, 137; 136, 138; 136, 144; 137, list:[]; 138, comparison_operator:==; 138, 139; 138, 143; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, identifier:functions; 143, integer:1; 144, list:[fn.__name__]; 144, 145; 145, attribute; 145, 146; 145, 147; 146, identifier:fn; 147, identifier:__name__; 148, expression_statement; 148, 149; 149, augmented_assignment:+=; 149, 150; 149, 151; 150, identifier:name; 151, call; 151, 152; 151, 161; 152, attribute; 152, 153; 152, 160; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:util; 156, identifier:dict_subset; 157, argument_list; 157, 158; 157, 159; 158, identifier:kw; 159, identifier:search_keys; 160, identifier:values; 161, argument_list; 162, if_statement; 162, 163; 162, 170; 162, 204; 163, call; 163, 164; 163, 165; 164, identifier:isinstance; 165, argument_list; 165, 166; 165, 167; 166, identifier:r; 167, attribute; 167, 168; 167, 169; 168, identifier:pd; 169, identifier:DataFrame; 170, block; 170, 171; 170, 198; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:columns; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:pd; 178, identifier:MultiIndex; 179, identifier:from_tuples; 180, argument_list; 180, 181; 181, list_comprehension; 181, 182; 181, 193; 182, call; 182, 183; 182, 184; 183, identifier:tuple; 184, argument_list; 184, 185; 185, binary_operator:+; 185, 186; 185, 187; 186, identifier:name; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:util; 190, identifier:make_list; 191, argument_list; 191, 192; 192, identifier:c; 193, for_in_clause; 193, 194; 193, 195; 194, identifier:c; 195, attribute; 195, 196; 195, 197; 196, identifier:r; 197, identifier:columns; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:r; 202, identifier:columns; 203, identifier:columns; 204, else_clause; 204, 205; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:r; 210, identifier:name; 211, call; 211, 212; 211, 213; 212, identifier:tuple; 213, argument_list; 213, 214; 214, identifier:name; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:results; 219, identifier:append; 220, argument_list; 220, 221; 221, identifier:r; 222, if_statement; 222, 223; 222, 229; 222, 293; 223, comparison_operator:>; 223, 224; 223, 228; 224, call; 224, 225; 224, 226; 225, identifier:len; 226, argument_list; 226, 227; 227, identifier:results; 228, integer:1; 229, block; 229, 230; 229, 242; 229, 243; 229, 256; 229, 260; 229, 280; 229, 288; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:result; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:pd; 236, identifier:concat; 237, argument_list; 237, 238; 237, 239; 238, identifier:results; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:axis; 241, integer:1; 242, comment; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:column_names; 246, conditional_expression:if; 246, 247; 246, 248; 246, 254; 247, list:[]; 248, comparison_operator:==; 248, 249; 248, 253; 249, call; 249, 250; 249, 251; 250, identifier:len; 251, argument_list; 251, 252; 252, identifier:functions; 253, integer:1; 254, list:[None]; 254, 255; 255, None; 256, expression_statement; 256, 257; 257, augmented_assignment:+=; 257, 258; 257, 259; 258, identifier:column_names; 259, identifier:search_keys; 260, expression_statement; 260, 261; 261, augmented_assignment:+=; 261, 262; 261, 263; 262, identifier:column_names; 263, binary_operator:*; 263, 264; 263, 266; 264, list:[None]; 264, 265; 265, None; 266, parenthesized_expression; 266, 267; 267, binary_operator:-; 267, 268; 267, 276; 268, call; 268, 269; 268, 270; 269, identifier:len; 270, argument_list; 270, 271; 271, attribute; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:result; 274, identifier:columns; 275, identifier:names; 276, call; 276, 277; 276, 278; 277, identifier:len; 278, argument_list; 278, 279; 279, identifier:column_names; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 287; 282, attribute; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:result; 285, identifier:columns; 286, identifier:names; 287, identifier:column_names; 288, return_statement; 288, 289; 289, call; 289, 290; 289, 291; 290, identifier:StepFrame; 291, argument_list; 291, 292; 292, identifier:result; 293, else_clause; 293, 294; 294, block; 294, 295; 294, 301; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 298; 297, identifier:result; 298, subscript; 298, 299; 298, 300; 299, identifier:results; 300, integer:0; 301, if_statement; 301, 302; 301, 309; 301, 315; 302, call; 302, 303; 302, 304; 303, identifier:isinstance; 304, argument_list; 304, 305; 304, 306; 305, identifier:result; 306, attribute; 306, 307; 306, 308; 307, identifier:pd; 308, identifier:DataFrame; 309, block; 309, 310; 310, return_statement; 310, 311; 311, call; 311, 312; 311, 313; 312, identifier:StepFrame; 313, argument_list; 313, 314; 314, identifier:result; 315, else_clause; 315, 316; 316, block; 316, 317; 316, 327; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:result; 321, identifier:name; 322, attribute; 322, 323; 322, 326; 323, subscript; 323, 324; 323, 325; 324, identifier:functions; 325, integer:0; 326, identifier:__name__; 327, return_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:StepSeries; 330, argument_list; 330, 331; 331, identifier:result
def dapply(self, fn, pairwise=False, symmetric=True, diagonal=False, block=None, **kwargs): """ Apply function to each step object in the index Args: fn: function to apply. If a list then each function is applied pairwise: whether to apply the function to pairs of steps symmetric, diagonal, block: passed to apply_pairwise when pairwise=True kwargs: a keyword arguments to pass to each function. Arguments with list value are grid searched using util.dict_product. Returns: a StepFrame or StepSeries """ search_keys = [k for k, v in kwargs.items() if isinstance(v, list) and len(v) > 1] functions = util.make_list(fn) search = list(product(functions, util.dict_product(kwargs))) results = [] for fn, kw in search: if not pairwise: r = self.index.to_series().apply(lambda step: fn(step, **kw)) else: r = apply_pairwise(self, fn, symmetric=symmetric, diagonal=diagonal, block=block, **kw) name = [] if len(functions) == 1 else [fn.__name__] name += util.dict_subset(kw, search_keys).values() if isinstance(r, pd.DataFrame): columns = pd.MultiIndex.from_tuples( [tuple(name + util.make_list(c)) for c in r.columns]) r.columns = columns else: r.name = tuple(name) results.append(r) if len(results) > 1: result = pd.concat(results, axis=1) # get subset of parameters that were searched over column_names = [] if len(functions) == 1 else [None] column_names += search_keys column_names += [None]*(len(result.columns.names)-len(column_names)) result.columns.names = column_names return StepFrame(result) else: result = results[0] if isinstance(result, pd.DataFrame): return StepFrame(result) else: result.name = functions[0].__name__ return StepSeries(result)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_identifySuperGraph; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 30; 5, 38; 5, 47; 5, 75; 5, 81; 5, 90; 5, 99; 5, 351; 5, 361; 5, 371; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:debug; 12, block; 12, 13; 12, 22; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:sys; 18, identifier:stdout; 19, identifier:write; 20, argument_list; 20, 21; 21, string:"Condensing Graph: "; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:start; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:time; 28, identifier:clock; 29, argument_list; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:G; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:nx; 36, identifier:DiGraph; 37, argument_list; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:G; 42, identifier:add_edges_from; 43, argument_list; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:edges; 47, if_statement; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:short_circuit; 51, block; 51, 52; 51, 62; 51, 72; 51, 73; 51, 74; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:superNodes; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:G; 60, identifier:nodes; 61, argument_list; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:superArcs; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:G; 70, identifier:edges; 71, argument_list; 72, comment; 73, comment; 74, return_statement; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:augmentedEdges; 80, dictionary; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:N; 84, call; 84, 85; 84, 86; 85, identifier:len; 86, argument_list; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:Y; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:processed; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:np; 96, identifier:zeros; 97, argument_list; 97, 98; 98, identifier:N; 99, for_statement; 99, 100; 99, 101; 99, 105; 99, 106; 99, 107; 100, identifier:node; 101, call; 101, 102; 101, 103; 102, identifier:range; 103, argument_list; 103, 104; 104, identifier:N; 105, comment; 106, comment; 107, block; 107, 108; 107, 114; 107, 115; 107, 116; 107, 117; 107, 118; 107, 119; 107, 120; 108, if_statement; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:processed; 111, identifier:node; 112, block; 112, 113; 113, continue_statement; 114, comment; 115, comment; 116, comment; 117, comment; 118, comment; 119, comment; 120, if_statement; 120, 121; 120, 138; 120, 139; 120, 140; 121, boolean_operator:and; 121, 122; 121, 130; 122, comparison_operator:==; 122, 123; 122, 129; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:G; 126, identifier:in_degree; 127, argument_list; 127, 128; 128, identifier:node; 129, integer:1; 130, comparison_operator:==; 130, 131; 130, 137; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:G; 134, identifier:out_degree; 135, argument_list; 135, 136; 136, identifier:node; 137, integer:1; 138, comment; 139, comment; 140, block; 140, 141; 140, 145; 140, 146; 140, 162; 140, 224; 140, 230; 140, 237; 140, 238; 140, 254; 140, 316; 140, 324; 140, 331; 140, 341; 140, 342; 140, 343; 140, 344; 140, 345; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:removedNodes; 144, list:[]; 145, comment; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:lower_link; 149, subscript; 149, 150; 149, 161; 150, subscript; 150, 151; 150, 160; 151, call; 151, 152; 151, 153; 152, identifier:list; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:G; 157, identifier:in_edges; 158, argument_list; 158, 159; 159, identifier:node; 160, integer:0; 161, integer:0; 162, while_statement; 162, 163; 162, 181; 163, parenthesized_expression; 163, 164; 164, boolean_operator:and; 164, 165; 164, 173; 165, comparison_operator:==; 165, 166; 165, 172; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:G; 169, identifier:in_degree; 170, argument_list; 170, 171; 171, identifier:lower_link; 172, integer:1; 173, comparison_operator:==; 173, 174; 173, 180; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:G; 177, identifier:out_degree; 178, argument_list; 178, 179; 179, identifier:lower_link; 180, integer:1; 181, block; 181, 182; 181, 198; 181, 206; 181, 213; 181, 220; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:new_lower_link; 185, subscript; 185, 186; 185, 197; 186, subscript; 186, 187; 186, 196; 187, call; 187, 188; 187, 189; 188, identifier:list; 189, argument_list; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:G; 193, identifier:in_edges; 194, argument_list; 194, 195; 195, identifier:lower_link; 196, integer:0; 197, integer:0; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:G; 202, identifier:add_edge; 203, argument_list; 203, 204; 203, 205; 204, identifier:new_lower_link; 205, identifier:node; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:G; 210, identifier:remove_node; 211, argument_list; 211, 212; 212, identifier:lower_link; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:removedNodes; 217, identifier:append; 218, argument_list; 218, 219; 219, identifier:lower_link; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:lower_link; 223, identifier:new_lower_link; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:removedNodes; 228, identifier:reverse; 229, argument_list; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:removedNodes; 234, identifier:append; 235, argument_list; 235, 236; 236, identifier:node; 237, comment; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:upper_link; 241, subscript; 241, 242; 241, 253; 242, subscript; 242, 243; 242, 252; 243, call; 243, 244; 243, 245; 244, identifier:list; 245, argument_list; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:G; 249, identifier:out_edges; 250, argument_list; 250, 251; 251, identifier:node; 252, integer:0; 253, integer:1; 254, while_statement; 254, 255; 254, 273; 255, parenthesized_expression; 255, 256; 256, boolean_operator:and; 256, 257; 256, 265; 257, comparison_operator:==; 257, 258; 257, 264; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:G; 261, identifier:in_degree; 262, argument_list; 262, 263; 263, identifier:upper_link; 264, integer:1; 265, comparison_operator:==; 265, 266; 265, 272; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:G; 269, identifier:out_degree; 270, argument_list; 270, 271; 271, identifier:upper_link; 272, integer:1; 273, block; 273, 274; 273, 290; 273, 298; 273, 305; 273, 312; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:new_upper_link; 277, subscript; 277, 278; 277, 289; 278, subscript; 278, 279; 278, 288; 279, call; 279, 280; 279, 281; 280, identifier:list; 281, argument_list; 281, 282; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:G; 285, identifier:out_edges; 286, argument_list; 286, 287; 287, identifier:upper_link; 288, integer:0; 289, integer:1; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:G; 294, identifier:add_edge; 295, argument_list; 295, 296; 295, 297; 296, identifier:node; 297, identifier:new_upper_link; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:G; 302, identifier:remove_node; 303, argument_list; 303, 304; 304, identifier:upper_link; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:removedNodes; 309, identifier:append; 310, argument_list; 310, 311; 311, identifier:upper_link; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:upper_link; 315, identifier:new_upper_link; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:G; 320, identifier:add_edge; 321, argument_list; 321, 322; 321, 323; 322, identifier:lower_link; 323, identifier:upper_link; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:G; 328, identifier:remove_node; 329, argument_list; 329, 330; 330, identifier:node; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 340; 333, subscript; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:self; 336, identifier:augmentedEdges; 337, tuple; 337, 338; 337, 339; 338, identifier:lower_link; 339, identifier:upper_link; 340, identifier:removedNodes; 341, comment; 342, comment; 343, comment; 344, comment; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 350; 347, subscript; 347, 348; 347, 349; 348, identifier:processed; 349, identifier:removedNodes; 350, integer:1; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:superNodes; 356, call; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:G; 359, identifier:nodes; 360, argument_list; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 366; 363, attribute; 363, 364; 363, 365; 364, identifier:self; 365, identifier:superArcs; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:G; 369, identifier:edges; 370, argument_list; 371, if_statement; 371, 372; 371, 375; 372, attribute; 372, 373; 372, 374; 373, identifier:self; 374, identifier:debug; 375, block; 375, 376; 375, 384; 376, expression_statement; 376, 377; 377, assignment; 377, 378; 377, 379; 378, identifier:end; 379, call; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:time; 382, identifier:clock; 383, argument_list; 384, expression_statement; 384, 385; 385, call; 385, 386; 385, 391; 386, attribute; 386, 387; 386, 390; 387, attribute; 387, 388; 387, 389; 388, identifier:sys; 389, identifier:stdout; 390, identifier:write; 391, argument_list; 391, 392; 392, binary_operator:%; 392, 393; 392, 394; 393, string:"%f s\n"; 394, parenthesized_expression; 394, 395; 395, binary_operator:-; 395, 396; 395, 397; 396, identifier:end; 397, identifier:start
def _identifySuperGraph(self): """ A helper function for determining the condensed representation of the tree. That is, one that does not hold all of the internal nodes of the graph. The results will be stored in ContourTree.superNodes and ContourTree.superArcs. These two can be used to potentially speed up queries by limiting the searching on the graph to only nodes on these super arcs. """ if self.debug: sys.stdout.write("Condensing Graph: ") start = time.clock() G = nx.DiGraph() G.add_edges_from(self.edges) if self.short_circuit: self.superNodes = G.nodes() self.superArcs = G.edges() # There should be a way to populate this from the data we # have... return self.augmentedEdges = {} N = len(self.Y) processed = np.zeros(N) for node in range(N): # We can short circuit this here, since some of the nodes # will be handled within the while loops below. if processed[node]: continue # Loop through each internal node (see if below for # determining what is internal), trace up and down to a # node's first non-internal node in either direction # removing all of the internal nodes and pushing them into a # list. This list (removedNodes) will be put into a # dictionary keyed on the endpoints of the final super arc. if G.in_degree(node) == 1 and G.out_degree(node) == 1: # The sorted list of nodes that will be condensed by # this super arc removedNodes = [] # Trace down to a non-internal node lower_link = list(G.in_edges(node))[0][0] while ( G.in_degree(lower_link) == 1 and G.out_degree(lower_link) == 1 ): new_lower_link = list(G.in_edges(lower_link))[0][0] G.add_edge(new_lower_link, node) G.remove_node(lower_link) removedNodes.append(lower_link) lower_link = new_lower_link removedNodes.reverse() removedNodes.append(node) # Trace up to a non-internal node upper_link = list(G.out_edges(node))[0][1] while ( G.in_degree(upper_link) == 1 and G.out_degree(upper_link) == 1 ): new_upper_link = list(G.out_edges(upper_link))[0][1] G.add_edge(node, new_upper_link) G.remove_node(upper_link) removedNodes.append(upper_link) upper_link = new_upper_link G.add_edge(lower_link, upper_link) G.remove_node(node) self.augmentedEdges[(lower_link, upper_link)] = removedNodes # This is to help speed up the process by skipping nodes # we have already condensed, and to prevent us from not # being able to find nodes that have already been # removed. processed[removedNodes] = 1 self.superNodes = G.nodes() self.superArcs = G.edges() if self.debug: end = time.clock() sys.stdout.write("%f s\n" % (end - start))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_construct_nx_tree; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:thisTree; 6, default_parameter; 6, 7; 6, 8; 7, identifier:thatTree; 8, None; 9, block; 9, 10; 9, 12; 9, 34; 9, 42; 9, 51; 9, 55; 9, 70; 9, 71; 9, 180; 9, 207; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:debug; 16, block; 16, 17; 16, 26; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:sys; 22, identifier:stdout; 23, identifier:write; 24, argument_list; 24, 25; 25, string:"Networkx Tree construction: "; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:start; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:time; 32, identifier:clock; 33, argument_list; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:nxTree; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:nx; 40, identifier:DiGraph; 41, argument_list; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:nxTree; 46, identifier:add_edges_from; 47, argument_list; 47, 48; 48, attribute; 48, 49; 48, 50; 49, identifier:thisTree; 50, identifier:edges; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:nodesOfThatTree; 54, list:[]; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:thatTree; 58, None; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:nodesOfThatTree; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:thatTree; 67, identifier:nodes; 68, identifier:keys; 69, argument_list; 70, comment; 71, for_statement; 71, 72; 71, 77; 71, 84; 72, pattern_list; 72, 73; 72, 76; 73, tuple_pattern; 73, 74; 73, 75; 74, identifier:superNode; 75, identifier:_; 76, identifier:nodes; 77, call; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:thisTree; 81, identifier:augmentedEdges; 82, identifier:items; 83, argument_list; 84, block; 84, 85; 84, 97; 84, 120; 84, 128; 84, 132; 84, 140; 84, 165; 84, 166; 84, 167; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:superNodeEdge; 88, call; 88, 89; 88, 90; 89, identifier:list; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:nxTree; 94, identifier:out_edges; 95, argument_list; 95, 96; 96, identifier:superNode; 97, if_statement; 97, 98; 97, 104; 98, comparison_operator:>; 98, 99; 98, 103; 99, call; 99, 100; 99, 101; 100, identifier:len; 101, argument_list; 101, 102; 102, identifier:superNodeEdge; 103, integer:1; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:warnings; 109, identifier:warn; 110, argument_list; 110, 111; 111, call; 111, 112; 111, 118; 112, attribute; 112, 113; 112, 117; 113, concatenated_string; 113, 114; 113, 115; 113, 116; 114, string:"The supernode {} should have only a single "; 115, string:"emanating edge. Merge tree is invalidly "; 116, string:"structured"; 117, identifier:format; 118, argument_list; 118, 119; 119, identifier:superNode; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:endNode; 123, subscript; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:superNodeEdge; 126, integer:0; 127, integer:1; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:startNode; 131, identifier:superNode; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:nxTree; 136, identifier:remove_edge; 137, argument_list; 137, 138; 137, 139; 138, identifier:startNode; 139, identifier:endNode; 140, for_statement; 140, 141; 140, 142; 140, 143; 141, identifier:node; 142, identifier:nodes; 143, block; 143, 144; 144, if_statement; 144, 145; 144, 152; 145, boolean_operator:or; 145, 146; 145, 149; 146, comparison_operator:is; 146, 147; 146, 148; 147, identifier:thatTree; 148, None; 149, comparison_operator:in; 149, 150; 149, 151; 150, identifier:node; 151, identifier:nodesOfThatTree; 152, block; 152, 153; 152, 161; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:nxTree; 157, identifier:add_edge; 158, argument_list; 158, 159; 158, 160; 159, identifier:startNode; 160, identifier:node; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:startNode; 164, identifier:node; 165, comment; 166, comment; 167, if_statement; 167, 168; 167, 171; 168, comparison_operator:!=; 168, 169; 168, 170; 169, identifier:startNode; 170, identifier:endNode; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:nxTree; 176, identifier:add_edge; 177, argument_list; 177, 178; 177, 179; 178, identifier:startNode; 179, identifier:endNode; 180, if_statement; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:debug; 184, block; 184, 185; 184, 193; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:end; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:time; 191, identifier:clock; 192, argument_list; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:sys; 198, identifier:stdout; 199, identifier:write; 200, argument_list; 200, 201; 201, binary_operator:%; 201, 202; 201, 203; 202, string:"%f s\n"; 203, parenthesized_expression; 203, 204; 204, binary_operator:-; 204, 205; 204, 206; 205, identifier:end; 206, identifier:start; 207, return_statement; 207, 208; 208, identifier:nxTree
def _construct_nx_tree(self, thisTree, thatTree=None): """ A function for creating networkx instances that can be used more efficiently for graph manipulation than the MergeTree class. @ In, thisTree, a MergeTree instance for which we will construct a networkx graph @ In, thatTree, a MergeTree instance optionally used to speed up the processing by bypassing the fully augmented search and only focusing on the partially augmented split and join trees @ Out, nxTree, a networkx.Graph instance matching the details of the input tree. """ if self.debug: sys.stdout.write("Networkx Tree construction: ") start = time.clock() nxTree = nx.DiGraph() nxTree.add_edges_from(thisTree.edges) nodesOfThatTree = [] if thatTree is not None: nodesOfThatTree = thatTree.nodes.keys() # Fully or partially augment the join tree for (superNode, _), nodes in thisTree.augmentedEdges.items(): superNodeEdge = list(nxTree.out_edges(superNode)) if len(superNodeEdge) > 1: warnings.warn( "The supernode {} should have only a single " "emanating edge. Merge tree is invalidly " "structured".format(superNode) ) endNode = superNodeEdge[0][1] startNode = superNode nxTree.remove_edge(startNode, endNode) for node in nodes: if thatTree is None or node in nodesOfThatTree: nxTree.add_edge(startNode, node) startNode = node # Make sure this is not the root node trying to connect to # itself if startNode != endNode: nxTree.add_edge(startNode, endNode) if self.debug: end = time.clock() sys.stdout.write("%f s\n" % (end - start)) return nxTree
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_process_tree; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:thisTree; 6, identifier:thatTree; 7, block; 7, 8; 7, 10; 7, 32; 7, 33; 7, 34; 7, 87; 7, 402; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:debug; 14, block; 14, 15; 14, 24; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:sys; 20, identifier:stdout; 21, identifier:write; 22, argument_list; 22, 23; 23, string:"Processing Tree: "; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:start; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:time; 30, identifier:clock; 31, argument_list; 32, comment; 33, comment; 34, if_statement; 34, 35; 34, 45; 34, 79; 35, comparison_operator:>; 35, 36; 35, 44; 36, call; 36, 37; 36, 38; 37, identifier:len; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:thisTree; 42, identifier:nodes; 43, argument_list; 44, integer:1; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:leaves; 49, call; 49, 50; 49, 51; 50, identifier:set; 51, argument_list; 51, 52; 52, list_comprehension; 52, 53; 52, 54; 52, 61; 53, identifier:v; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:v; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:thisTree; 59, identifier:nodes; 60, argument_list; 61, if_clause; 61, 62; 62, boolean_operator:and; 62, 63; 62, 71; 63, comparison_operator:==; 63, 64; 63, 70; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:thisTree; 67, identifier:in_degree; 68, argument_list; 68, 69; 69, identifier:v; 70, integer:0; 71, comparison_operator:<; 71, 72; 71, 78; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:thatTree; 75, identifier:in_degree; 76, argument_list; 76, 77; 77, identifier:v; 78, integer:2; 79, else_clause; 79, 80; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:leaves; 84, call; 84, 85; 84, 86; 85, identifier:set; 86, argument_list; 87, while_statement; 87, 88; 87, 94; 88, comparison_operator:>; 88, 89; 88, 93; 89, call; 89, 90; 89, 91; 90, identifier:len; 91, argument_list; 91, 92; 92, identifier:leaves; 93, integer:0; 94, block; 94, 95; 94, 103; 94, 104; 94, 105; 94, 106; 94, 107; 94, 108; 94, 120; 94, 142; 94, 150; 94, 158; 94, 159; 94, 160; 94, 161; 94, 162; 94, 163; 94, 164; 94, 201; 94, 202; 94, 203; 94, 210; 94, 211; 94, 342; 94, 395; 94, 396; 94, 397; 94, 398; 94, 399; 94, 400; 94, 401; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:v; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:leaves; 101, identifier:pop; 102, argument_list; 103, comment; 104, comment; 105, comment; 106, comment; 107, comment; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:edges; 111, call; 111, 112; 111, 113; 112, identifier:list; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:thisTree; 117, identifier:out_edges; 118, argument_list; 118, 119; 119, identifier:v; 120, if_statement; 120, 121; 120, 127; 121, comparison_operator:!=; 121, 122; 121, 126; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:edges; 126, integer:1; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:warnings; 132, identifier:warn; 133, argument_list; 133, 134; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, concatenated_string; 136, 137; 136, 138; 137, string:"The node {} should have a single emanating "; 138, string:"edge.\n"; 139, identifier:format; 140, argument_list; 140, 141; 141, identifier:v; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:e1; 145, subscript; 145, 146; 145, 149; 146, subscript; 146, 147; 146, 148; 147, identifier:edges; 148, integer:0; 149, integer:0; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:e2; 153, subscript; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:edges; 156, integer:0; 157, integer:1; 158, comment; 159, comment; 160, comment; 161, comment; 162, comment; 163, comment; 164, if_statement; 164, 165; 164, 176; 164, 188; 165, comparison_operator:<; 165, 166; 165, 171; 166, subscript; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:Y; 170, identifier:e1; 171, subscript; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:Y; 175, identifier:e2; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:edges; 183, identifier:append; 184, argument_list; 184, 185; 185, tuple; 185, 186; 185, 187; 186, identifier:e1; 187, identifier:e2; 188, else_clause; 188, 189; 189, block; 189, 190; 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:edges; 196, identifier:append; 197, argument_list; 197, 198; 198, tuple; 198, 199; 198, 200; 199, identifier:e2; 200, identifier:e1; 201, comment; 202, comment; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:thisTree; 207, identifier:remove_node; 208, argument_list; 208, 209; 209, identifier:v; 210, comment; 211, if_statement; 211, 212; 211, 220; 211, 231; 211, 232; 211, 233; 211, 234; 212, comparison_operator:==; 212, 213; 212, 219; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:thatTree; 216, identifier:out_degree; 217, argument_list; 217, 218; 218, identifier:v; 219, integer:0; 220, block; 220, 221; 220, 228; 220, 229; 220, 230; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:thatTree; 225, identifier:remove_node; 226, argument_list; 226, 227; 227, identifier:v; 228, comment; 229, comment; 230, comment; 231, comment; 232, comment; 233, comment; 234, else_clause; 234, 235; 234, 236; 234, 237; 235, comment; 236, comment; 237, block; 237, 238; 237, 276; 237, 314; 237, 331; 237, 338; 237, 339; 237, 340; 237, 341; 238, if_statement; 238, 239; 238, 250; 238, 267; 239, comparison_operator:>; 239, 240; 239, 249; 240, call; 240, 241; 240, 242; 241, identifier:len; 242, argument_list; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:thatTree; 246, identifier:in_edges; 247, argument_list; 247, 248; 248, identifier:v; 249, integer:0; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:startNode; 254, subscript; 254, 255; 254, 266; 255, subscript; 255, 256; 255, 265; 256, call; 256, 257; 256, 258; 257, identifier:list; 258, argument_list; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:thatTree; 262, identifier:in_edges; 263, argument_list; 263, 264; 264, identifier:v; 265, integer:0; 266, integer:0; 267, else_clause; 267, 268; 267, 269; 267, 270; 267, 271; 268, comment; 269, comment; 270, comment; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:startNode; 275, None; 276, if_statement; 276, 277; 276, 288; 276, 305; 277, comparison_operator:>; 277, 278; 277, 287; 278, call; 278, 279; 278, 280; 279, identifier:len; 280, argument_list; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:thatTree; 284, identifier:out_edges; 285, argument_list; 285, 286; 286, identifier:v; 287, integer:0; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:endNode; 292, subscript; 292, 293; 292, 304; 293, subscript; 293, 294; 293, 303; 294, call; 294, 295; 294, 296; 295, identifier:list; 296, argument_list; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:thatTree; 300, identifier:out_edges; 301, argument_list; 301, 302; 302, identifier:v; 303, integer:0; 304, integer:1; 305, else_clause; 305, 306; 305, 307; 305, 308; 305, 309; 306, comment; 307, comment; 308, comment; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:endNode; 313, None; 314, if_statement; 314, 315; 314, 322; 315, boolean_operator:and; 315, 316; 315, 319; 316, comparison_operator:is; 316, 317; 316, 318; 317, identifier:startNode; 318, None; 319, comparison_operator:is; 319, 320; 319, 321; 320, identifier:endNode; 321, None; 322, block; 322, 323; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:thatTree; 327, identifier:add_edge; 328, argument_list; 328, 329; 328, 330; 329, identifier:startNode; 330, identifier:endNode; 331, expression_statement; 331, 332; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:thatTree; 335, identifier:remove_node; 336, argument_list; 336, 337; 337, identifier:v; 338, comment; 339, comment; 340, comment; 341, comment; 342, if_statement; 342, 343; 342, 353; 342, 387; 343, comparison_operator:>; 343, 344; 343, 352; 344, call; 344, 345; 344, 346; 345, identifier:len; 346, argument_list; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:thisTree; 350, identifier:nodes; 351, argument_list; 352, integer:1; 353, block; 353, 354; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 357; 356, identifier:leaves; 357, call; 357, 358; 357, 359; 358, identifier:set; 359, argument_list; 359, 360; 360, list_comprehension; 360, 361; 360, 362; 360, 369; 361, identifier:v; 362, for_in_clause; 362, 363; 362, 364; 363, identifier:v; 364, call; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:thisTree; 367, identifier:nodes; 368, argument_list; 369, if_clause; 369, 370; 370, boolean_operator:and; 370, 371; 370, 379; 371, comparison_operator:==; 371, 372; 371, 378; 372, call; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:thisTree; 375, identifier:in_degree; 376, argument_list; 376, 377; 377, identifier:v; 378, integer:0; 379, comparison_operator:<; 379, 380; 379, 386; 380, call; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:thatTree; 383, identifier:in_degree; 384, argument_list; 384, 385; 385, identifier:v; 386, integer:2; 387, else_clause; 387, 388; 388, block; 388, 389; 389, expression_statement; 389, 390; 390, assignment; 390, 391; 390, 392; 391, identifier:leaves; 392, call; 392, 393; 392, 394; 393, identifier:set; 394, argument_list; 395, comment; 396, comment; 397, comment; 398, comment; 399, comment; 400, comment; 401, comment; 402, if_statement; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, identifier:self; 405, identifier:debug; 406, block; 406, 407; 406, 415; 407, expression_statement; 407, 408; 408, assignment; 408, 409; 408, 410; 409, identifier:end; 410, call; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:time; 413, identifier:clock; 414, argument_list; 415, expression_statement; 415, 416; 416, call; 416, 417; 416, 422; 417, attribute; 417, 418; 417, 421; 418, attribute; 418, 419; 418, 420; 419, identifier:sys; 420, identifier:stdout; 421, identifier:write; 422, argument_list; 422, 423; 423, binary_operator:%; 423, 424; 423, 425; 424, string:"%f s\n"; 425, parenthesized_expression; 425, 426; 426, binary_operator:-; 426, 427; 426, 428; 427, identifier:end; 428, identifier:start
def _process_tree(self, thisTree, thatTree): """ A function that will process either a split or join tree with reference to the other tree and store it as part of this CT instance. @ In, thisTree, a networkx.Graph instance representing a merge tree for which we will process all of its leaf nodes into this CT object @ In, thatTree, a networkx.Graph instance representing the opposing merge tree which will need to be updated as nodes from thisTree are processed @ Out, None """ if self.debug: sys.stdout.write("Processing Tree: ") start = time.clock() # Get all of the leaf nodes that are not branches in the other # tree if len(thisTree.nodes()) > 1: leaves = set( [ v for v in thisTree.nodes() if thisTree.in_degree(v) == 0 and thatTree.in_degree(v) < 2 ] ) else: leaves = set() while len(leaves) > 0: v = leaves.pop() # if self.debug: # sys.stdout.write('\tProcessing {} -> {}\n' # .format(v, thisTree.edges(v)[0][1])) # Take the leaf and edge out of the input tree and place it # on the CT edges = list(thisTree.out_edges(v)) if len(edges) != 1: warnings.warn( "The node {} should have a single emanating " "edge.\n".format(v) ) e1 = edges[0][0] e2 = edges[0][1] # This may be a bit beside the point, but if we want all of # our edges pointing 'up,' we can verify that the edges we # add have the lower vertex pointing to the upper vertex. # This is useful only for nicely plotting with some graph # tools (graphviz/networkx), and I guess for consistency # sake. if self.Y[e1] < self.Y[e2]: self.edges.append((e1, e2)) else: self.edges.append((e2, e1)) # Removing the node will remove its constituent edges from # thisTree thisTree.remove_node(v) # This is the root node of the other tree if thatTree.out_degree(v) == 0: thatTree.remove_node(v) # if self.debug: # sys.stdout.write('\t\tRemoving root {} from other tree\n' # .format(v)) # This is a "regular" node in the other tree, suppress it # there, but be sure to glue the upper and lower portions # together else: # The other ends of the node being removed are added to # "that" tree if len(thatTree.in_edges(v)) > 0: startNode = list(thatTree.in_edges(v))[0][0] else: # This means we are at the root of the other tree, # we can safely remove this node without connecting # its predecessor with its descendant startNode = None if len(thatTree.out_edges(v)) > 0: endNode = list(thatTree.out_edges(v))[0][1] else: # This means we are at a leaf of the other tree, # we can safely remove this node without connecting # its predecessor with its descendant endNode = None if startNode is not None and endNode is not None: thatTree.add_edge(startNode, endNode) thatTree.remove_node(v) # if self.debug: # sys.stdout.write('\t\tSuppressing {} in other tree and ' # 'gluing {} to {}\n' # .format(v, startNode, endNode)) if len(thisTree.nodes()) > 1: leaves = set( [ v for v in thisTree.nodes() if thisTree.in_degree(v) == 0 and thatTree.in_degree(v) < 2 ] ) else: leaves = set() # if self.debug: # myMessage = '\t\tValid leaves: ' # sep = '' # for leaf in leaves: # myMessage += sep + str(leaf) # sep = ',' # sys.stdout.write(myMessage+'\n') if self.debug: end = time.clock() sys.stdout.write("%f s\n" % (end - start))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_project_content_commit_date; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:root_dir; 6, string:'.'; 7, default_parameter; 7, 8; 7, 9; 8, identifier:exclusions; 9, None; 10, block; 10, 11; 10, 13; 10, 22; 10, 23; 10, 34; 10, 38; 10, 52; 10, 53; 10, 65; 10, 66; 10, 97; 10, 114; 10, 128; 10, 132; 10, 170; 10, 179; 10, 186; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:logger; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:logging; 19, identifier:getLogger; 20, argument_list; 20, 21; 21, identifier:__name__; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:extensions; 26, tuple; 26, 27; 26, 28; 26, 29; 26, 30; 26, 31; 26, 32; 26, 33; 27, string:'rst'; 28, string:'ipynb'; 29, string:'png'; 30, string:'jpeg'; 31, string:'jpg'; 32, string:'svg'; 33, string:'gif'; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:content_paths; 37, list:[]; 38, for_statement; 38, 39; 38, 40; 38, 41; 39, identifier:extname; 40, identifier:extensions; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, augmented_assignment:+=; 43, 44; 43, 45; 44, identifier:content_paths; 45, call; 45, 46; 45, 47; 46, identifier:get_filepaths_with_extension; 47, argument_list; 47, 48; 47, 49; 48, identifier:extname; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:root_dir; 51, identifier:root_dir; 52, comment; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:exclude; 56, call; 56, 57; 56, 58; 57, identifier:Matcher; 58, argument_list; 58, 59; 59, conditional_expression:if; 59, 60; 59, 61; 59, 62; 60, identifier:exclusions; 61, identifier:exclusions; 62, list:['readme.rst', 'license.rst']; 62, 63; 62, 64; 63, string:'readme.rst'; 64, string:'license.rst'; 65, comment; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:content_paths; 69, list_comprehension; 69, 70; 69, 71; 69, 74; 70, identifier:p; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:p; 73, identifier:content_paths; 74, if_clause; 74, 75; 75, not_operator; 75, 76; 76, parenthesized_expression; 76, 77; 77, boolean_operator:or; 77, 78; 77, 82; 78, call; 78, 79; 78, 80; 79, identifier:exclude; 80, argument_list; 80, 81; 81, identifier:p; 82, call; 82, 83; 82, 84; 83, identifier:exclude; 84, argument_list; 84, 85; 85, subscript; 85, 86; 85, 96; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:p; 89, identifier:split; 90, argument_list; 90, 91; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:os; 94, identifier:path; 95, identifier:sep; 96, integer:0; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:logger; 101, identifier:debug; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, string:'Found content paths: {}'; 106, identifier:format; 107, argument_list; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, string:', '; 111, identifier:join; 112, argument_list; 112, 113; 113, identifier:content_paths; 114, if_statement; 114, 115; 114, 117; 115, not_operator; 115, 116; 116, identifier:content_paths; 117, block; 117, 118; 118, raise_statement; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:RuntimeError; 121, argument_list; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, string:'No content files found in {}'; 125, identifier:format; 126, argument_list; 126, 127; 127, identifier:root_dir; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:commit_datetimes; 131, list:[]; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:filepath; 134, identifier:content_paths; 135, block; 135, 136; 136, try_statement; 136, 137; 136, 155; 137, block; 137, 138; 137, 148; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:datetime; 141, call; 141, 142; 141, 143; 142, identifier:read_git_commit_timestamp_for_file; 143, argument_list; 143, 144; 143, 145; 144, identifier:filepath; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:repo_path; 147, identifier:root_dir; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:commit_datetimes; 152, identifier:append; 153, argument_list; 153, 154; 154, identifier:datetime; 155, except_clause; 155, 156; 155, 157; 156, identifier:IOError; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:logger; 162, identifier:warning; 163, argument_list; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, string:'Could not get commit for {}, skipping'; 167, identifier:format; 168, argument_list; 168, 169; 169, identifier:filepath; 170, if_statement; 170, 171; 170, 173; 171, not_operator; 171, 172; 172, identifier:commit_datetimes; 173, block; 173, 174; 174, raise_statement; 174, 175; 175, call; 175, 176; 175, 177; 176, identifier:RuntimeError; 177, argument_list; 177, 178; 178, string:'No content commits could be found'; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:latest_datetime; 182, call; 182, 183; 182, 184; 183, identifier:max; 184, argument_list; 184, 185; 185, identifier:commit_datetimes; 186, return_statement; 186, 187; 187, identifier:latest_datetime
def get_project_content_commit_date(root_dir='.', exclusions=None): """Get the datetime for the most recent commit to a project that affected Sphinx content. *Content* is considered any file with one of these extensions: - ``rst`` (README.rst and LICENSE.rst are excluded) - ``ipynb`` - ``png`` - ``jpeg`` - ``jpg`` - ``svg`` - ``gif`` This function allows project infrastructure and configuration files to be updated without changing the timestamp. Parameters ---------- root_dir : `str`, optional Root directory. This is the current working directory by default. exclusions : `list` of `str`, optional List of file paths or directory paths to ignore. Returns ------- commit_date : `datetime.datetime` Datetime of the most recent content commit. Raises ------ RuntimeError Raised if no content files are found. """ logger = logging.getLogger(__name__) # Supported 'content' extensions extensions = ('rst', 'ipynb', 'png', 'jpeg', 'jpg', 'svg', 'gif') content_paths = [] for extname in extensions: content_paths += get_filepaths_with_extension( extname, root_dir=root_dir) # Known files that should be excluded; lower case for comparison exclude = Matcher(exclusions if exclusions else ['readme.rst', 'license.rst']) # filter out excluded files content_paths = [p for p in content_paths if not (exclude(p) or exclude(p.split(os.path.sep)[0]))] logger.debug('Found content paths: {}'.format(', '.join(content_paths))) if not content_paths: raise RuntimeError('No content files found in {}'.format(root_dir)) commit_datetimes = [] for filepath in content_paths: try: datetime = read_git_commit_timestamp_for_file( filepath, repo_path=root_dir) commit_datetimes.append(datetime) except IOError: logger.warning( 'Could not get commit for {}, skipping'.format(filepath)) if not commit_datetimes: raise RuntimeError('No content commits could be found') latest_datetime = max(commit_datetimes) return latest_datetime
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_table; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:name; 6, block; 6, 7; 6, 9; 6, 93; 6, 94; 6, 154; 6, 155; 6, 177; 6, 178; 6, 203; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:name; 12, None; 13, block; 13, 14; 13, 19; 13, 27; 13, 56; 13, 88; 14, assert_statement; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:active_table; 18, string:"Can't get table without name unless an active table is set"; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:name; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:active_table; 26, identifier:name; 27, if_statement; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:active_worksheet; 31, block; 31, 32; 31, 43; 31, 50; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:table; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:active_worksheet; 40, identifier:get_table; 41, argument_list; 41, 42; 42, identifier:name; 43, assert_statement; 43, 44; 43, 49; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:table; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:active_table; 49, string:"Active table is not from the active sheet"; 50, return_statement; 50, 51; 51, expression_list; 51, 52; 51, 53; 52, identifier:table; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:active_worksheet; 56, for_statement; 56, 57; 56, 58; 56, 61; 57, identifier:ws; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:worksheets; 61, block; 61, 62; 62, try_statement; 62, 63; 62, 84; 63, block; 63, 64; 63, 73; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:table; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:ws; 70, identifier:get_table; 71, argument_list; 71, 72; 72, identifier:name; 73, if_statement; 73, 74; 73, 79; 74, comparison_operator:is; 74, 75; 74, 76; 75, identifier:table; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:active_table; 79, block; 79, 80; 80, return_statement; 80, 81; 81, expression_list; 81, 82; 81, 83; 82, identifier:table; 83, identifier:ws; 84, except_clause; 84, 85; 84, 86; 85, identifier:KeyError; 86, block; 86, 87; 87, pass_statement; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:RuntimeError; 91, argument_list; 91, 92; 92, string:"Active table not found in any sheet"; 93, comment; 94, if_statement; 94, 95; 94, 98; 95, comparison_operator:in; 95, 96; 95, 97; 96, string:"!"; 97, identifier:name; 98, block; 98, 99; 98, 123; 98, 149; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, pattern_list; 101, 102; 101, 103; 102, identifier:ws_name; 103, identifier:table_name; 104, call; 104, 105; 104, 106; 105, identifier:map; 106, argument_list; 106, 107; 106, 116; 107, lambda; 107, 108; 107, 110; 108, lambda_parameters; 108, 109; 109, identifier:x; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:x; 113, identifier:strip; 114, argument_list; 114, 115; 115, string:"'"; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:name; 119, identifier:split; 120, argument_list; 120, 121; 120, 122; 121, string:"!"; 122, integer:1; 123, for_statement; 123, 124; 123, 125; 123, 128; 124, identifier:ws; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:worksheets; 128, block; 128, 129; 129, if_statement; 129, 130; 129, 135; 130, comparison_operator:==; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:ws; 133, identifier:name; 134, identifier:ws_name; 135, block; 135, 136; 135, 145; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:table; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:ws; 142, identifier:get_table; 143, argument_list; 143, 144; 144, identifier:table_name; 145, return_statement; 145, 146; 146, expression_list; 146, 147; 146, 148; 147, identifier:table; 148, identifier:ws; 149, raise_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:KeyError; 152, argument_list; 152, 153; 153, identifier:name; 154, comment; 155, if_statement; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:active_worksheet; 159, block; 159, 160; 159, 171; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:table; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:active_worksheet; 168, identifier:get_table; 169, argument_list; 169, 170; 170, identifier:name; 171, return_statement; 171, 172; 172, expression_list; 172, 173; 172, 174; 173, identifier:table; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:active_worksheet; 177, comment; 178, for_statement; 178, 179; 178, 180; 178, 183; 179, identifier:ws; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:worksheets; 183, block; 183, 184; 184, try_statement; 184, 185; 184, 199; 185, block; 185, 186; 185, 195; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:table; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:ws; 192, identifier:get_table; 193, argument_list; 193, 194; 194, identifier:name; 195, return_statement; 195, 196; 196, expression_list; 196, 197; 196, 198; 197, identifier:table; 198, identifier:ws; 199, except_clause; 199, 200; 199, 201; 200, identifier:KeyError; 201, block; 201, 202; 202, pass_statement; 203, raise_statement; 203, 204; 204, call; 204, 205; 204, 206; 205, identifier:KeyError; 206, argument_list; 206, 207; 207, identifier:name
def get_table(self, name): """ Return a table, worksheet pair for the named table """ if name is None: assert self.active_table, "Can't get table without name unless an active table is set" name = self.active_table.name if self.active_worksheet: table = self.active_worksheet.get_table(name) assert table is self.active_table, "Active table is not from the active sheet" return table, self.active_worksheet for ws in self.worksheets: try: table = ws.get_table(name) if table is self.active_table: return table, ws except KeyError: pass raise RuntimeError("Active table not found in any sheet") # if the tablename explicitly uses the sheetname find the right sheet if "!" in name: ws_name, table_name = map(lambda x: x.strip("'"), name.split("!", 1)) for ws in self.worksheets: if ws.name == ws_name: table = ws.get_table(table_name) return table, ws raise KeyError(name) # otherwise look in the current table if self.active_worksheet: table = self.active_worksheet.get_table(name) return table, self.active_worksheet # or fallback to the first matching name in any table for ws in self.worksheets: try: table = ws.get_table(name) return table, ws except KeyError: pass raise KeyError(name)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:assign_valence; 3, parameters; 3, 4; 4, identifier:mol; 5, block; 5, 6; 5, 8; 5, 141; 5, 181; 5, 276; 6, expression_statement; 6, 7; 7, comment; 8, for_statement; 8, 9; 8, 13; 8, 18; 9, pattern_list; 9, 10; 9, 11; 9, 12; 10, identifier:u; 11, identifier:v; 12, identifier:bond; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:mol; 16, identifier:bonds_iter; 17, argument_list; 18, block; 18, 19; 19, if_statement; 19, 20; 19, 25; 19, 114; 20, comparison_operator:==; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:bond; 23, identifier:order; 24, integer:2; 25, block; 25, 26; 25, 37; 25, 48; 25, 81; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 36; 28, attribute; 28, 29; 28, 35; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:mol; 32, identifier:atom; 33, argument_list; 33, 34; 34, identifier:u; 35, identifier:pi; 36, integer:1; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 47; 39, attribute; 39, 40; 39, 46; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:mol; 43, identifier:atom; 44, argument_list; 44, 45; 45, identifier:v; 46, identifier:pi; 47, integer:1; 48, if_statement; 48, 49; 48, 69; 49, boolean_operator:and; 49, 50; 49, 60; 50, comparison_operator:==; 50, 51; 50, 59; 51, attribute; 51, 52; 51, 58; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:mol; 55, identifier:atom; 56, argument_list; 56, 57; 57, identifier:u; 58, identifier:symbol; 59, string:"O"; 60, not_operator; 60, 61; 61, attribute; 61, 62; 61, 68; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:mol; 65, identifier:atom; 66, argument_list; 66, 67; 67, identifier:u; 68, identifier:charge; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 80; 72, attribute; 72, 73; 72, 79; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:mol; 76, identifier:atom; 77, argument_list; 77, 78; 78, identifier:v; 79, identifier:carbonyl_C; 80, integer:1; 81, if_statement; 81, 82; 81, 102; 82, boolean_operator:and; 82, 83; 82, 93; 83, comparison_operator:==; 83, 84; 83, 92; 84, attribute; 84, 85; 84, 91; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:mol; 88, identifier:atom; 89, argument_list; 89, 90; 90, identifier:v; 91, identifier:symbol; 92, string:"O"; 93, not_operator; 93, 94; 94, attribute; 94, 95; 94, 101; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:mol; 98, identifier:atom; 99, argument_list; 99, 100; 100, identifier:v; 101, identifier:charge; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 113; 105, attribute; 105, 106; 105, 112; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:mol; 109, identifier:atom; 110, argument_list; 110, 111; 111, identifier:u; 112, identifier:carbonyl_C; 113, integer:1; 114, elif_clause; 114, 115; 114, 120; 115, comparison_operator:==; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:bond; 118, identifier:order; 119, integer:3; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 131; 123, attribute; 123, 124; 123, 130; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:mol; 127, identifier:atom; 128, argument_list; 128, 129; 129, identifier:u; 130, identifier:pi; 131, assignment; 131, 132; 131, 140; 132, attribute; 132, 133; 132, 139; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:mol; 136, identifier:atom; 137, argument_list; 137, 138; 138, identifier:v; 139, identifier:pi; 140, integer:2; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:max_nbr; 144, dictionary; 144, 145; 144, 148; 144, 151; 144, 154; 144, 157; 144, 160; 144, 163; 144, 166; 144, 169; 144, 172; 144, 175; 144, 178; 145, pair; 145, 146; 145, 147; 146, string:"C"; 147, integer:4; 148, pair; 148, 149; 148, 150; 149, string:"Si"; 150, integer:4; 151, pair; 151, 152; 151, 153; 152, string:"N"; 153, integer:3; 154, pair; 154, 155; 154, 156; 155, string:"P"; 156, integer:3; 157, pair; 157, 158; 157, 159; 158, string:"As"; 159, integer:3; 160, pair; 160, 161; 160, 162; 161, string:"O"; 162, integer:2; 163, pair; 163, 164; 163, 165; 164, string:"S"; 165, integer:2; 166, pair; 166, 167; 166, 168; 167, string:"Se"; 168, integer:2; 169, pair; 169, 170; 169, 171; 170, string:"F"; 171, integer:1; 172, pair; 172, 173; 172, 174; 173, string:"Cl"; 174, integer:1; 175, pair; 175, 176; 175, 177; 176, string:"Br"; 177, integer:1; 178, pair; 178, 179; 178, 180; 179, string:"I"; 180, integer:1; 181, for_statement; 181, 182; 181, 185; 181, 190; 182, pattern_list; 182, 183; 182, 184; 183, identifier:i; 184, identifier:nbrs; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:mol; 188, identifier:neighbors_iter; 189, argument_list; 190, block; 190, 191; 190, 200; 190, 231; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:atom; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:mol; 197, identifier:atom; 198, argument_list; 198, 199; 199, identifier:i; 200, if_statement; 200, 201; 200, 223; 201, boolean_operator:and; 201, 202; 201, 208; 202, comparison_operator:==; 202, 203; 202, 207; 203, call; 203, 204; 203, 205; 204, identifier:len; 205, argument_list; 205, 206; 206, identifier:nbrs; 207, integer:2; 208, call; 208, 209; 208, 210; 209, identifier:all; 210, generator_expression; 210, 211; 210, 216; 211, comparison_operator:==; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:bond; 214, identifier:order; 215, integer:2; 216, for_in_clause; 216, 217; 216, 218; 217, identifier:bond; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:nbrs; 221, identifier:values; 222, argument_list; 223, block; 223, 224; 223, 230; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:atom; 228, identifier:pi; 229, integer:2; 230, comment; 231, if_statement; 231, 232; 231, 237; 232, comparison_operator:in; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:atom; 235, identifier:symbol; 236, identifier:max_nbr; 237, block; 237, 238; 237, 259; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:h_cnt; 241, binary_operator:+; 241, 242; 241, 256; 242, binary_operator:-; 242, 243; 242, 253; 243, binary_operator:-; 243, 244; 243, 249; 244, subscript; 244, 245; 244, 246; 245, identifier:max_nbr; 246, attribute; 246, 247; 246, 248; 247, identifier:atom; 248, identifier:symbol; 249, call; 249, 250; 249, 251; 250, identifier:len; 251, argument_list; 251, 252; 252, identifier:nbrs; 253, attribute; 253, 254; 253, 255; 254, identifier:atom; 255, identifier:pi; 256, attribute; 256, 257; 256, 258; 257, identifier:atom; 258, identifier:charge; 259, if_statement; 259, 260; 259, 263; 260, comparison_operator:>; 260, 261; 260, 262; 261, identifier:h_cnt; 262, integer:0; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 274; 266, attribute; 266, 267; 266, 273; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:mol; 270, identifier:atom; 271, argument_list; 271, 272; 272, identifier:i; 273, identifier:add_hydrogen; 274, argument_list; 274, 275; 275, identifier:h_cnt; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 283; 278, attribute; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:mol; 281, identifier:descriptors; 282, identifier:add; 283, argument_list; 283, 284; 284, string:"Valence"
def assign_valence(mol): """Assign pi electron and hydrogens""" for u, v, bond in mol.bonds_iter(): if bond.order == 2: mol.atom(u).pi = 1 mol.atom(v).pi = 1 if mol.atom(u).symbol == "O" and not mol.atom(u).charge: mol.atom(v).carbonyl_C = 1 if mol.atom(v).symbol == "O" and not mol.atom(v).charge: mol.atom(u).carbonyl_C = 1 elif bond.order == 3: mol.atom(u).pi = mol.atom(v).pi = 2 max_nbr = {"C": 4, "Si": 4, "N": 3, "P": 3, "As": 3, "O": 2, "S": 2, "Se": 2, "F": 1, "Cl": 1, "Br": 1, "I": 1} for i, nbrs in mol.neighbors_iter(): atom = mol.atom(i) if len(nbrs) == 2 and all(bond.order == 2 for bond in nbrs.values()): atom.pi = 2 # sp (allene, ketene) if atom.symbol in max_nbr: h_cnt = max_nbr[atom.symbol] - len(nbrs) - atom.pi + atom.charge if h_cnt > 0: mol.atom(i).add_hydrogen(h_cnt) mol.descriptors.add("Valence")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:assign_charge; 3, parameters; 3, 4; 3, 5; 4, identifier:mol; 5, default_parameter; 5, 6; 5, 7; 6, identifier:force_recalc; 7, False; 8, block; 8, 9; 8, 11; 8, 12; 8, 19; 8, 405; 8, 411; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:mol; 16, identifier:require; 17, argument_list; 17, 18; 18, string:"Aromatic"; 19, for_statement; 19, 20; 19, 23; 19, 28; 20, pattern_list; 20, 21; 20, 22; 21, identifier:i; 22, identifier:nbrs; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:mol; 26, identifier:neighbors_iter; 27, argument_list; 28, block; 28, 29; 28, 38; 28, 45; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:atom; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:mol; 35, identifier:atom; 36, argument_list; 36, 37; 37, identifier:i; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:nbrcnt; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:nbrs; 45, if_statement; 45, 46; 45, 51; 45, 212; 45, 358; 46, comparison_operator:==; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:atom; 49, identifier:symbol; 50, string:"N"; 51, block; 51, 52; 52, if_statement; 52, 53; 52, 57; 52, 58; 52, 70; 53, not_operator; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:atom; 56, identifier:pi; 57, comment; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 69; 61, attribute; 61, 62; 61, 68; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:mol; 65, identifier:atom; 66, argument_list; 66, 67; 67, identifier:i; 68, identifier:charge_phys; 69, integer:1; 70, elif_clause; 70, 71; 70, 80; 70, 81; 71, boolean_operator:and; 71, 72; 71, 75; 72, comparison_operator:==; 72, 73; 72, 74; 73, identifier:nbrcnt; 74, integer:1; 75, comparison_operator:==; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:atom; 78, identifier:pi; 79, integer:2; 80, comment; 81, block; 81, 82; 81, 95; 81, 99; 81, 103; 81, 182; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:ni; 85, subscript; 85, 86; 85, 94; 86, call; 86, 87; 86, 88; 87, identifier:list; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:nbrs; 92, identifier:keys; 93, argument_list; 94, integer:0; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:conj; 98, False; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:sp2n; 102, None; 103, for_statement; 103, 104; 103, 107; 103, 117; 104, pattern_list; 104, 105; 104, 106; 105, identifier:nni; 106, identifier:nnb; 107, call; 107, 108; 107, 116; 108, attribute; 108, 109; 108, 115; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:mol; 112, identifier:neighbors; 113, argument_list; 113, 114; 114, identifier:ni; 115, identifier:items; 116, argument_list; 117, block; 117, 118; 118, if_statement; 118, 119; 118, 146; 118, 162; 119, boolean_operator:and; 119, 120; 119, 136; 119, 137; 120, boolean_operator:and; 120, 121; 120, 131; 121, comparison_operator:==; 121, 122; 121, 130; 122, attribute; 122, 123; 122, 129; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:mol; 126, identifier:atom; 127, argument_list; 127, 128; 128, identifier:nni; 129, identifier:symbol; 130, string:"N"; 131, comparison_operator:==; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:nnb; 134, identifier:order; 135, integer:2; 136, line_continuation:\; 137, not_operator; 137, 138; 138, attribute; 138, 139; 138, 145; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:mol; 142, identifier:atom; 143, argument_list; 143, 144; 144, identifier:nni; 145, identifier:aromatic; 146, block; 146, 147; 146, 158; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 157; 149, attribute; 149, 150; 149, 156; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:mol; 153, identifier:atom; 154, argument_list; 154, 155; 155, identifier:nni; 156, identifier:charge_conj; 157, integer:1; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:conj; 161, True; 162, elif_clause; 162, 163; 162, 177; 163, boolean_operator:and; 163, 164; 163, 174; 164, comparison_operator:==; 164, 165; 164, 173; 165, attribute; 165, 166; 165, 172; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:mol; 169, identifier:atom; 170, argument_list; 170, 171; 171, identifier:nni; 172, identifier:symbol; 173, string:"N"; 174, comparison_operator:!=; 174, 175; 174, 176; 175, identifier:nni; 176, identifier:i; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:sp2n; 181, identifier:nni; 182, if_statement; 182, 183; 182, 184; 183, identifier:conj; 184, block; 184, 185; 184, 196; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 195; 187, attribute; 187, 188; 187, 194; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:mol; 191, identifier:atom; 192, argument_list; 192, 193; 193, identifier:i; 194, identifier:charge_phys; 195, integer:1; 196, if_statement; 196, 197; 196, 200; 197, comparison_operator:is; 197, 198; 197, 199; 198, identifier:sp2n; 199, None; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 211; 203, attribute; 203, 204; 203, 210; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:mol; 207, identifier:atom; 208, argument_list; 208, 209; 209, identifier:sp2n; 210, identifier:charge_conj; 211, integer:1; 212, elif_clause; 212, 213; 212, 228; 212, 229; 213, boolean_operator:and; 213, 214; 213, 223; 214, boolean_operator:and; 214, 215; 214, 220; 215, comparison_operator:==; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:atom; 218, identifier:symbol; 219, string:"O"; 220, comparison_operator:==; 220, 221; 220, 222; 221, identifier:nbrcnt; 222, integer:1; 223, comparison_operator:==; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:atom; 226, identifier:pi; 227, integer:2; 228, comment; 229, block; 229, 230; 229, 243; 229, 247; 229, 281; 229, 343; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:ni; 233, subscript; 233, 234; 233, 242; 234, call; 234, 235; 234, 236; 235, identifier:list; 236, argument_list; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:nbrs; 240, identifier:keys; 241, argument_list; 242, integer:0; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:conj; 246, False; 247, if_statement; 247, 248; 247, 258; 248, comparison_operator:==; 248, 249; 248, 257; 249, attribute; 249, 250; 249, 256; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:mol; 253, identifier:atom; 254, argument_list; 254, 255; 255, identifier:ni; 256, identifier:symbol; 257, string:"N"; 258, block; 258, 259; 258, 270; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 269; 261, attribute; 261, 262; 261, 268; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:mol; 265, identifier:atom; 266, argument_list; 266, 267; 267, identifier:i; 268, identifier:n_oxide; 269, True; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 280; 272, attribute; 272, 273; 272, 279; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:mol; 276, identifier:atom; 277, argument_list; 277, 278; 278, identifier:ni; 279, identifier:n_oxide; 280, True; 281, for_statement; 281, 282; 281, 285; 281, 295; 282, pattern_list; 282, 283; 282, 284; 283, identifier:nni; 284, identifier:nnb; 285, call; 285, 286; 285, 294; 286, attribute; 286, 287; 286, 293; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:mol; 290, identifier:neighbors; 291, argument_list; 291, 292; 292, identifier:ni; 293, identifier:items; 294, argument_list; 295, block; 295, 296; 296, if_statement; 296, 297; 296, 326; 297, boolean_operator:and; 297, 298; 297, 317; 298, boolean_operator:and; 298, 299; 298, 311; 298, 312; 299, comparison_operator:in; 299, 300; 299, 308; 300, attribute; 300, 301; 300, 307; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:mol; 304, identifier:atom; 305, argument_list; 305, 306; 306, identifier:nni; 307, identifier:symbol; 308, tuple; 308, 309; 308, 310; 309, string:"O"; 310, string:"S"; 311, line_continuation:\; 312, comparison_operator:==; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:nnb; 315, identifier:order; 316, integer:2; 317, not_operator; 317, 318; 318, attribute; 318, 319; 318, 325; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:mol; 322, identifier:atom; 323, argument_list; 323, 324; 324, identifier:ni; 325, identifier:n_oxide; 326, block; 326, 327; 326, 339; 327, expression_statement; 327, 328; 328, assignment; 328, 329; 328, 337; 329, attribute; 329, 330; 329, 336; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:mol; 333, identifier:atom; 334, argument_list; 334, 335; 335, identifier:nni; 336, identifier:charge_conj; 337, unary_operator:-; 337, 338; 338, integer:1; 339, expression_statement; 339, 340; 340, assignment; 340, 341; 340, 342; 341, identifier:conj; 342, True; 343, if_statement; 343, 344; 343, 345; 344, identifier:conj; 345, block; 345, 346; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 356; 348, attribute; 348, 349; 348, 355; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:mol; 352, identifier:atom; 353, argument_list; 353, 354; 354, identifier:i; 355, identifier:charge_phys; 356, unary_operator:-; 356, 357; 357, integer:1; 358, elif_clause; 358, 359; 358, 368; 358, 369; 359, boolean_operator:and; 359, 360; 359, 365; 360, comparison_operator:==; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:atom; 363, identifier:symbol; 364, string:"S"; 365, comparison_operator:==; 365, 366; 365, 367; 366, identifier:nbrcnt; 367, integer:1; 368, comment; 369, block; 369, 370; 369, 383; 370, expression_statement; 370, 371; 371, assignment; 371, 372; 371, 373; 372, identifier:ni; 373, subscript; 373, 374; 373, 382; 374, call; 374, 375; 374, 376; 375, identifier:list; 376, argument_list; 376, 377; 377, call; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:nbrs; 380, identifier:keys; 381, argument_list; 382, integer:0; 383, if_statement; 383, 384; 383, 392; 384, attribute; 384, 385; 384, 391; 385, call; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:mol; 388, identifier:atom; 389, argument_list; 389, 390; 390, identifier:ni; 391, identifier:aromatic; 392, block; 392, 393; 393, expression_statement; 393, 394; 394, assignment; 394, 395; 394, 403; 395, attribute; 395, 396; 395, 402; 396, call; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:mol; 399, identifier:atom; 400, argument_list; 400, 401; 401, identifier:i; 402, identifier:charge_phys; 403, unary_operator:-; 403, 404; 404, integer:1; 405, expression_statement; 405, 406; 406, assignment; 406, 407; 406, 410; 407, attribute; 407, 408; 407, 409; 408, identifier:mol; 409, identifier:charge_assigned; 410, True; 411, expression_statement; 411, 412; 412, call; 412, 413; 412, 418; 413, attribute; 413, 414; 413, 417; 414, attribute; 414, 415; 414, 416; 415, identifier:mol; 416, identifier:descriptors; 417, identifier:add; 418, argument_list; 418, 419; 419, string:"Phys_charge"
def assign_charge(mol, force_recalc=False): """Assign charges in physiological condition""" # TODO: not implemented yet mol.require("Aromatic") for i, nbrs in mol.neighbors_iter(): atom = mol.atom(i) nbrcnt = len(nbrs) if atom.symbol == "N": if not atom.pi: # non-conjugated amines are anion mol.atom(i).charge_phys = 1 elif nbrcnt == 1 and atom.pi == 2: # amidine, guanidine are conjugated cation ni = list(nbrs.keys())[0] conj = False sp2n = None for nni, nnb in mol.neighbors(ni).items(): if mol.atom(nni).symbol == "N" and nnb.order == 2 \ and not mol.atom(nni).aromatic: mol.atom(nni).charge_conj = 1 conj = True elif mol.atom(nni).symbol == "N" and nni != i: sp2n = nni if conj: mol.atom(i).charge_phys = 1 if sp2n is not None: mol.atom(sp2n).charge_conj = 1 elif atom.symbol == "O" and nbrcnt == 1 and atom.pi == 2: # oxoacid are conjugated anion ni = list(nbrs.keys())[0] conj = False if mol.atom(ni).symbol == "N": mol.atom(i).n_oxide = True mol.atom(ni).n_oxide = True for nni, nnb in mol.neighbors(ni).items(): if mol.atom(nni).symbol in ("O", "S") \ and nnb.order == 2 and not mol.atom(ni).n_oxide: mol.atom(nni).charge_conj = -1 conj = True if conj: mol.atom(i).charge_phys = -1 elif atom.symbol == "S" and nbrcnt == 1: # thiophenols are anion ni = list(nbrs.keys())[0] if mol.atom(ni).aromatic: mol.atom(i).charge_phys = -1 mol.charge_assigned = True mol.descriptors.add("Phys_charge")
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_alphabetical_members; 3, parameters; 3, 4; 3, 5; 4, identifier:obj; 5, identifier:predicate; 6, block; 6, 7; 6, 9; 6, 22; 6, 33; 6, 39; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:fields; 12, call; 12, 13; 12, 14; 13, identifier:dict; 14, argument_list; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:inspect; 18, identifier:getmembers; 19, argument_list; 19, 20; 19, 21; 20, identifier:obj; 21, identifier:predicate; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:keys; 25, call; 25, 26; 25, 27; 26, identifier:list; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:fields; 31, identifier:keys; 32, argument_list; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:keys; 37, identifier:sort; 38, argument_list; 39, return_statement; 39, 40; 40, dictionary_comprehension; 40, 41; 40, 46; 41, pair; 41, 42; 41, 43; 42, identifier:k; 43, subscript; 43, 44; 43, 45; 44, identifier:fields; 45, identifier:k; 46, for_in_clause; 46, 47; 46, 48; 47, identifier:k; 48, identifier:keys
def _get_alphabetical_members(obj, predicate): """Get members of an object, sorted alphabetically. Parameters ---------- obj An object. predicate : callable Callable that takes an attribute and returns a bool of whether the attribute should be returned or not. Returns ------- members : `dict` Dictionary of - Keys: attribute name - Values: attribute The dictionary is ordered according to the attribute name. Notes ----- This uses the insertion-order-preserved nature of `dict` in Python 3.6+. See also -------- `inspect.getmembers` """ fields = dict(inspect.getmembers(obj, predicate)) keys = list(fields.keys()) keys.sort() return {k: fields[k] for k in keys}
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:run; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 17; 5, 18; 5, 30; 5, 31; 5, 37; 5, 38; 5, 42; 5, 43; 5, 44; 5, 374; 5, 379; 5, 395; 5, 396; 5, 402; 5, 408; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:request_cache; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:cache; 15, identifier:get_request_cache; 16, argument_list; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:session; 21, call; 21, 22; 21, 29; 22, attribute; 22, 23; 22, 28; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:client; 26, identifier:get_client; 27, argument_list; 28, identifier:create_session; 29, argument_list; 30, comment; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:mark_incomplete; 36, argument_list; 37, comment; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:universes; 41, list:[]; 42, comment; 43, comment; 44, with_statement; 44, 45; 44, 50; 44, 51; 45, with_clause; 45, 46; 46, with_item; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:session; 49, identifier:no_autoflush; 50, comment; 51, block; 51, 52; 51, 67; 51, 68; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:movies; 55, call; 55, 56; 55, 66; 56, attribute; 56, 57; 56, 65; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:session; 60, identifier:query; 61, argument_list; 61, 62; 62, attribute; 62, 63; 62, 64; 63, identifier:models; 64, identifier:Movie; 65, identifier:all; 66, argument_list; 67, comment; 68, for_statement; 68, 69; 68, 70; 68, 71; 68, 72; 69, identifier:movie; 70, identifier:movies; 71, comment; 72, block; 72, 73; 72, 92; 72, 101; 72, 102; 72, 113; 72, 121; 72, 122; 72, 123; 72, 127; 72, 128; 72, 129; 72, 137; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:article; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:request_cache; 79, identifier:get; 80, argument_list; 80, 81; 80, 86; 80, 89; 81, binary_operator:+; 81, 82; 81, 83; 82, string:"http://marvel.wikia.com"; 83, attribute; 83, 84; 83, 85; 84, identifier:movie; 85, identifier:url; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:xpath; 88, string:"//article[@id='WikiaMainContent']"; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:rate_limit; 91, float:0.5; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:doc; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:html; 98, identifier:fromstring; 99, argument_list; 99, 100; 100, identifier:article; 101, comment; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:node; 105, subscript; 105, 106; 105, 112; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:doc; 109, identifier:xpath; 110, argument_list; 110, 111; 111, string:"//span[@id='Appearances']"; 112, integer:0; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:node; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:node; 119, identifier:getparent; 120, argument_list; 121, comment; 122, comment; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:appearance_type; 126, string:"Featured Characters"; 127, comment; 128, comment; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:node; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:node; 135, identifier:getnext; 136, argument_list; 137, while_statement; 137, 138; 137, 147; 138, boolean_operator:and; 138, 139; 138, 142; 139, comparison_operator:is; 139, 140; 139, 141; 140, identifier:node; 141, None; 142, comparison_operator:!=; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:node; 145, identifier:tag; 146, string:'h2'; 147, block; 147, 148; 147, 366; 148, if_statement; 148, 149; 148, 171; 148, 172; 148, 173; 148, 332; 149, boolean_operator:and; 149, 150; 149, 155; 150, comparison_operator:==; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:node; 153, identifier:tag; 154, string:'ul'; 155, parenthesized_expression; 155, 156; 156, boolean_operator:or; 156, 157; 156, 164; 157, comparison_operator:in; 157, 158; 157, 159; 158, string:'characters'; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:appearance_type; 162, identifier:lower; 163, argument_list; 164, comparison_operator:in; 164, 165; 164, 166; 165, string:'villains'; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:appearance_type; 169, identifier:lower; 170, argument_list; 171, comment; 172, comment; 173, block; 173, 174; 174, for_statement; 174, 175; 174, 176; 174, 182; 174, 183; 174, 184; 175, identifier:li; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:node; 179, identifier:iter; 180, argument_list; 180, 181; 181, string:'li'; 182, comment; 183, comment; 184, block; 184, 185; 185, for_statement; 185, 186; 185, 187; 185, 188; 186, identifier:a; 187, identifier:li; 188, block; 188, 189; 188, 197; 188, 198; 188, 199; 188, 224; 188, 239; 188, 259; 188, 260; 188, 330; 188, 331; 189, if_statement; 189, 190; 189, 195; 190, comparison_operator:!=; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:a; 193, identifier:tag; 194, string:'a'; 195, block; 195, 196; 196, continue_statement; 197, comment; 198, comment; 199, if_statement; 199, 200; 199, 222; 200, boolean_operator:or; 200, 201; 200, 210; 201, comparison_operator:in; 201, 202; 201, 203; 202, string:"image"; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:a; 206, identifier:get; 207, argument_list; 207, 208; 207, 209; 208, string:"class"; 209, string:""; 210, not_operator; 210, 211; 211, call; 211, 212; 211, 220; 212, attribute; 212, 213; 212, 219; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:a; 216, identifier:get; 217, argument_list; 217, 218; 218, string:"href"; 219, identifier:startswith; 220, argument_list; 220, 221; 221, string:"/wiki/"; 222, block; 222, 223; 223, continue_statement; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:match; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:re; 230, identifier:search; 231, argument_list; 231, 232; 231, 233; 232, string:r'\(.*?\)'; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:a; 236, identifier:get; 237, argument_list; 237, 238; 238, string:'href'; 239, if_statement; 239, 240; 239, 241; 240, identifier:match; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:universes; 246, identifier:append; 247, argument_list; 247, 248; 248, subscript; 248, 249; 248, 254; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:match; 252, identifier:group; 253, argument_list; 254, slice; 254, 255; 254, 256; 254, 257; 255, integer:1; 256, colon; 257, unary_operator:-; 257, 258; 258, integer:1; 259, comment; 260, try_statement; 260, 261; 260, 325; 261, block; 261, 262; 261, 295; 261, 296; 261, 317; 261, 324; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:character; 265, call; 265, 266; 265, 294; 266, attribute; 266, 267; 266, 292; 266, 293; 267, call; 267, 268; 267, 279; 268, attribute; 268, 269; 268, 277; 268, 278; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:session; 272, identifier:query; 273, argument_list; 273, 274; 274, attribute; 274, 275; 274, 276; 275, identifier:models; 276, identifier:Character; 277, line_continuation:\; 278, identifier:filter; 279, argument_list; 279, 280; 280, comparison_operator:==; 280, 281; 280, 286; 281, attribute; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:models; 284, identifier:Character; 285, identifier:url; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:a; 289, identifier:get; 290, argument_list; 290, 291; 291, string:"href"; 292, line_continuation:\; 293, identifier:one; 294, argument_list; 295, comment; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:appearance; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:models; 302, identifier:MovieAppearance; 303, argument_list; 303, 304; 303, 309; 303, 314; 304, keyword_argument; 304, 305; 304, 306; 305, identifier:movie_id; 306, attribute; 306, 307; 306, 308; 307, identifier:movie; 308, identifier:id; 309, keyword_argument; 309, 310; 309, 311; 310, identifier:character_id; 311, attribute; 311, 312; 311, 313; 312, identifier:character; 313, identifier:id; 314, keyword_argument; 314, 315; 314, 316; 315, identifier:appearance_type; 316, identifier:appearance_type; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:session; 321, identifier:add; 322, argument_list; 322, 323; 323, identifier:appearance; 324, comment; 325, except_clause; 325, 326; 325, 327; 325, 328; 326, identifier:NoResultFound; 327, comment; 328, block; 328, 329; 329, pass_statement; 330, comment; 331, break_statement; 332, elif_clause; 332, 333; 332, 338; 332, 339; 333, comparison_operator:==; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:node; 336, identifier:tag; 337, string:'p'; 338, comment; 339, block; 339, 340; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:appearance_type; 343, call; 343, 344; 343, 365; 344, attribute; 344, 345; 344, 364; 345, call; 345, 346; 345, 362; 346, attribute; 346, 347; 346, 361; 347, call; 347, 348; 347, 360; 348, attribute; 348, 349; 348, 359; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, string:" "; 352, identifier:join; 353, argument_list; 353, 354; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:node; 357, identifier:itertext; 358, argument_list; 359, identifier:strip; 360, argument_list; 361, identifier:strip; 362, argument_list; 362, 363; 363, string:':'; 364, identifier:strip; 365, argument_list; 366, expression_statement; 366, 367; 367, assignment; 367, 368; 367, 369; 368, identifier:node; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:node; 372, identifier:getnext; 373, argument_list; 374, expression_statement; 374, 375; 375, call; 375, 376; 375, 377; 376, identifier:print; 377, argument_list; 377, 378; 378, string:"\nNumber of character appearances per universe: "; 379, expression_statement; 379, 380; 380, call; 380, 381; 380, 382; 381, identifier:print; 382, argument_list; 382, 383; 383, call; 383, 384; 383, 394; 384, attribute; 384, 385; 384, 393; 385, call; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:pd; 388, identifier:Series; 389, argument_list; 389, 390; 390, keyword_argument; 390, 391; 390, 392; 391, identifier:data; 392, identifier:universes; 393, identifier:value_counts; 394, argument_list; 395, comment; 396, expression_statement; 396, 397; 397, call; 397, 398; 397, 401; 398, attribute; 398, 399; 398, 400; 399, identifier:session; 400, identifier:commit; 401, argument_list; 402, expression_statement; 402, 403; 403, call; 403, 404; 403, 407; 404, attribute; 404, 405; 404, 406; 405, identifier:session; 406, identifier:close; 407, argument_list; 408, expression_statement; 408, 409; 409, call; 409, 410; 409, 413; 410, attribute; 410, 411; 410, 412; 411, identifier:self; 412, identifier:mark_complete; 413, argument_list
def run(self): """Run loading of movie appearances. The wiki page structure for this part cannot be easily handled by simple xpath queries. We need to iterate over the respective portion of the page and parse appearances. """ # make all requests via a cache instance request_cache = cache.get_request_cache() # DB session to operate in session = client.get_client().create_session() # clear completion flag for this task self.mark_incomplete() # list of universes seen in character appearances universes = [] # don't auto-flush the session for queries, this causes issues with the 'id' field of newly # created MovieAppearance instances with session.no_autoflush: # get all movies movies = session.query(models.Movie).all() # iterate over all movies and build appearance objects for movie in movies: # retrieve movie article, keep main article content only, parse article = request_cache.get("http://marvel.wikia.com" + movie.url, xpath="//article[@id='WikiaMainContent']", rate_limit=0.5) doc = html.fromstring(article) # find heading for appearances, this is a span inside an h2; go to the h2 node = doc.xpath("//span[@id='Appearances']")[0] node = node.getparent() # Appearance type is given by <p><b>... some text ...</b></p> tags. Sometimes the first # group of appearances carries no such label, assume it's the featured characters. appearance_type = "Featured Characters" # walk along the tree; character lists are in <ul>s, labels in <p>s; # the next h2 ends the character listing node = node.getnext() while node is not None and node.tag != 'h2': if node.tag == 'ul' and ('characters' in appearance_type.lower() or 'villains' in appearance_type.lower()): # starts a new list of stuff; only enter here if the previous label was for characters; # use iter() to iterate over all 'li' items (also those of nested lists) for li in node.iter('li'): # inside the list element, find all 'a's; iterate over child nodes, don't use iter(), # since we want don't want to find 'a's of sub-elements in a nested list here for a in li: if a.tag != 'a': continue # there are 'a's in the list that wrap imags, don't use these; also don't use # links that lead to somewhere else than the wiki if "image" in a.get("class", "") or not a.get("href").startswith("/wiki/"): continue match = re.search(r'\(.*?\)', a.get('href')) if match: universes.append(match.group()[1:-1]) # accept the first matching href, build a new appearance object, then skip to next li try: character = session.query(models.Character) \ .filter(models.Character.url == a.get("href")) \ .one() # -- start documentation include: many-to-many-generation appearance = models.MovieAppearance(movie_id=movie.id, character_id=character.id, appearance_type=appearance_type) session.add(appearance) # -- end documentation include: many-to-many-generation except NoResultFound: # none found, ignore pass # break looping over 'a's once we have found one, go to next 'li' break elif node.tag == 'p': # new character class (or label for locations, items, ...) appearance_type = " ".join(node.itertext()).strip().strip(':').strip() node = node.getnext() print("\nNumber of character appearances per universe: ") print(pd.Series(data=universes).value_counts()) # done, save all data, finalize task session.commit() session.close() self.mark_complete()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_argsort; 3, parameters; 3, 4; 3, 5; 4, identifier:y_score; 5, default_parameter; 5, 6; 5, 7; 6, identifier:k; 7, None; 8, block; 8, 9; 8, 11; 8, 19; 8, 29; 8, 43; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:ranks; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:y_score; 17, identifier:argsort; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:argsort; 22, subscript; 22, 23; 22, 24; 23, identifier:ranks; 24, slice; 24, 25; 24, 26; 24, 27; 25, colon; 26, colon; 27, unary_operator:-; 27, 28; 28, integer:1; 29, if_statement; 29, 30; 29, 33; 30, comparison_operator:is; 30, 31; 30, 32; 31, identifier:k; 32, None; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:argsort; 37, subscript; 37, 38; 37, 39; 38, identifier:argsort; 39, slice; 39, 40; 39, 41; 39, 42; 40, integer:0; 41, colon; 42, identifier:k; 43, return_statement; 43, 44; 44, identifier:argsort
def _argsort(y_score, k=None): """ Returns the indexes in descending order of the top k score or all scores if k is None """ ranks = y_score.argsort() argsort = ranks[::-1] if k is not None: argsort = argsort[0:k] return argsort
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:formula; 3, parameters; 3, 4; 4, identifier:mol; 5, block; 5, 6; 5, 8; 5, 15; 5, 22; 5, 28; 5, 202; 5, 227; 5, 231; 5, 263; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:mol; 12, identifier:require; 13, argument_list; 13, 14; 14, string:"Valence"; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:mol; 19, identifier:require; 20, argument_list; 20, 21; 21, string:"Topology"; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:total_cntr; 25, call; 25, 26; 25, 27; 26, identifier:Counter; 27, argument_list; 28, for_statement; 28, 29; 28, 30; 28, 43; 29, identifier:m; 30, call; 30, 31; 30, 32; 31, identifier:sorted; 32, argument_list; 32, 33; 32, 37; 32, 40; 33, call; 33, 34; 33, 35; 34, identifier:mols_iter; 35, argument_list; 35, 36; 36, identifier:mol; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:key; 39, identifier:len; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:reverse; 42, True; 43, block; 43, 44; 43, 50; 43, 67; 43, 71; 43, 81; 43, 106; 43, 116; 43, 141; 43, 163; 43, 191; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:cntr; 47, call; 47, 48; 47, 49; 48, identifier:Counter; 49, argument_list; 50, for_statement; 50, 51; 50, 52; 50, 53; 51, identifier:i; 52, identifier:m; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, augmented_assignment:+=; 55, 56; 55, 57; 56, identifier:cntr; 57, call; 57, 58; 57, 66; 58, attribute; 58, 59; 58, 65; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:mol; 62, identifier:atom; 63, argument_list; 63, 64; 64, identifier:i; 65, identifier:composition; 66, argument_list; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:text; 70, list:[]; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:Cs; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:cntr; 77, identifier:pop; 78, argument_list; 78, 79; 78, 80; 79, string:"C"; 80, integer:0; 81, if_statement; 81, 82; 81, 83; 82, identifier:Cs; 83, block; 83, 84; 83, 91; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:text; 88, identifier:append; 89, argument_list; 89, 90; 90, string:"C"; 91, if_statement; 91, 92; 91, 95; 92, comparison_operator:>; 92, 93; 92, 94; 93, identifier:Cs; 94, integer:1; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:text; 100, identifier:append; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:str; 104, argument_list; 104, 105; 105, identifier:Cs; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:Hs; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:cntr; 112, identifier:pop; 113, argument_list; 113, 114; 113, 115; 114, string:"H"; 115, integer:0; 116, if_statement; 116, 117; 116, 118; 117, identifier:Hs; 118, block; 118, 119; 118, 126; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:text; 123, identifier:append; 124, argument_list; 124, 125; 125, string:"H"; 126, if_statement; 126, 127; 126, 130; 127, comparison_operator:>; 127, 128; 127, 129; 128, identifier:Hs; 129, integer:1; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:text; 135, identifier:append; 136, argument_list; 136, 137; 137, call; 137, 138; 137, 139; 138, identifier:str; 139, argument_list; 139, 140; 140, identifier:Hs; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:heteros; 144, call; 144, 145; 144, 146; 145, identifier:sorted; 146, argument_list; 146, 147; 146, 152; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:cntr; 150, identifier:items; 151, argument_list; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:key; 154, lambda; 154, 155; 154, 157; 155, lambda_parameters; 155, 156; 156, identifier:x; 157, call; 157, 158; 157, 159; 158, identifier:atom_number; 159, argument_list; 159, 160; 160, subscript; 160, 161; 160, 162; 161, identifier:x; 162, integer:0; 163, for_statement; 163, 164; 163, 167; 163, 168; 164, pattern_list; 164, 165; 164, 166; 165, identifier:k; 166, identifier:v; 167, identifier:heteros; 168, block; 168, 169; 168, 176; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:text; 173, identifier:append; 174, argument_list; 174, 175; 175, identifier:k; 176, if_statement; 176, 177; 176, 180; 177, comparison_operator:>; 177, 178; 177, 179; 178, identifier:v; 179, integer:1; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:text; 185, identifier:append; 186, argument_list; 186, 187; 187, call; 187, 188; 187, 189; 188, identifier:str; 189, argument_list; 189, 190; 190, identifier:v; 191, expression_statement; 191, 192; 192, augmented_assignment:+=; 192, 193; 192, 201; 193, subscript; 193, 194; 193, 195; 194, identifier:total_cntr; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, string:""; 198, identifier:join; 199, argument_list; 199, 200; 200, identifier:text; 201, integer:1; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:total; 205, call; 205, 206; 205, 207; 206, identifier:sorted; 207, argument_list; 207, 208; 207, 213; 207, 224; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:total_cntr; 211, identifier:items; 212, argument_list; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:key; 215, lambda; 215, 216; 215, 218; 216, lambda_parameters; 216, 217; 217, identifier:x; 218, call; 218, 219; 218, 220; 219, identifier:len; 220, argument_list; 220, 221; 221, subscript; 221, 222; 221, 223; 222, identifier:x; 223, integer:0; 224, keyword_argument; 224, 225; 224, 226; 225, identifier:reverse; 226, True; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:total_text; 230, list:[]; 231, for_statement; 231, 232; 231, 235; 231, 236; 232, pattern_list; 232, 233; 232, 234; 233, identifier:k; 234, identifier:v; 235, identifier:total; 236, block; 236, 237; 237, if_statement; 237, 238; 237, 241; 237, 254; 238, comparison_operator:>; 238, 239; 238, 240; 239, identifier:v; 240, integer:1; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:total_text; 246, identifier:append; 247, argument_list; 247, 248; 248, binary_operator:+; 248, 249; 248, 253; 249, call; 249, 250; 249, 251; 250, identifier:str; 251, argument_list; 251, 252; 252, identifier:v; 253, identifier:k; 254, else_clause; 254, 255; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:total_text; 260, identifier:append; 261, argument_list; 261, 262; 262, identifier:k; 263, return_statement; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, string:"."; 267, identifier:join; 268, argument_list; 268, 269; 269, identifier:total_text
def formula(mol): """Chemical formula. Atoms should be arranged in order of C, H and other atoms. Molecules should be arranged in order of length of formula text. """ mol.require("Valence") mol.require("Topology") total_cntr = Counter() for m in sorted(mols_iter(mol), key=len, reverse=True): cntr = Counter() for i in m: cntr += mol.atom(i).composition() text = [] Cs = cntr.pop("C", 0) if Cs: text.append("C") if Cs > 1: text.append(str(Cs)) Hs = cntr.pop("H", 0) if Hs: text.append("H") if Hs > 1: text.append(str(Hs)) heteros = sorted(cntr.items(), key=lambda x: atom_number(x[0])) for k, v in heteros: text.append(k) if v > 1: text.append(str(v)) total_cntr["".join(text)] += 1 total = sorted(total_cntr.items(), key=lambda x: len(x[0]), reverse=True) total_text = [] for k, v in total: if v > 1: total_text.append(str(v) + k) else: total_text.append(k) return ".".join(total_text)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_start_action_for_section; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:section; 6, block; 6, 7; 6, 9; 6, 15; 6, 26; 6, 27; 6, 37; 6, 55; 6, 59; 6, 60; 6, 64; 6, 75; 6, 103; 6, 118; 6, 132; 6, 141; 6, 150; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:==; 10, 11; 10, 12; 11, identifier:section; 12, string:"configuration"; 13, block; 13, 14; 14, return_statement; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:Global; 20, identifier:LOGGER; 21, identifier:debug; 22, argument_list; 22, 23; 23, binary_operator:+; 23, 24; 23, 25; 24, string:"starting actions for section "; 25, identifier:section; 26, comment; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:action_configuration; 30, subscript; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:Global; 34, identifier:CONFIG_MANAGER; 35, identifier:sections; 36, identifier:section; 37, if_statement; 37, 38; 37, 44; 38, comparison_operator:==; 38, 39; 38, 43; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, identifier:action_configuration; 43, integer:0; 44, block; 44, 45; 44, 54; 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:Global; 50, identifier:LOGGER; 51, identifier:warn; 52, argument_list; 52, 53; 53, string:f"section {section} has no configuration, skipping"; 54, return_statement; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:action_type; 58, None; 59, comment; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:new_managed_input; 63, list:[]; 64, if_statement; 64, 65; 64, 68; 65, comparison_operator:in; 65, 66; 65, 67; 66, string:"type"; 67, identifier:action_configuration; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:action_type; 72, subscript; 72, 73; 72, 74; 73, identifier:action_configuration; 74, string:"type"; 75, if_statement; 75, 76; 75, 79; 76, comparison_operator:in; 76, 77; 76, 78; 77, string:"input"; 78, identifier:action_configuration; 79, block; 79, 80; 79, 86; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:action_input; 83, subscript; 83, 84; 83, 85; 84, identifier:action_configuration; 85, string:"input"; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:new_managed_input; 89, generator_expression; 89, 90; 89, 95; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:item; 93, identifier:strip; 94, argument_list; 95, for_in_clause; 95, 96; 95, 97; 96, identifier:item; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:action_input; 100, identifier:split; 101, argument_list; 101, 102; 102, string:","; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:my_action; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:Action; 109, identifier:create_action_for_code; 110, argument_list; 110, 111; 110, 112; 110, 113; 110, 114; 111, identifier:action_type; 112, identifier:section; 113, identifier:action_configuration; 114, call; 114, 115; 114, 116; 115, identifier:list; 116, argument_list; 116, 117; 117, identifier:new_managed_input; 118, if_statement; 118, 119; 118, 121; 119, not_operator; 119, 120; 120, identifier:my_action; 121, block; 121, 122; 121, 131; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:Global; 127, identifier:LOGGER; 128, identifier:warn; 129, argument_list; 129, 130; 130, string:f"can't find a type for action {section}, the action will be skipped"; 131, return_statement; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 139; 134, attribute; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:actions; 138, identifier:append; 139, argument_list; 139, 140; 140, identifier:my_action; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:Global; 146, identifier:LOGGER; 147, identifier:debug; 148, argument_list; 148, 149; 149, string:"updating the subscriptions table"; 150, for_statement; 150, 151; 150, 152; 150, 155; 151, identifier:my_input; 152, attribute; 152, 153; 152, 154; 153, identifier:my_action; 154, identifier:monitored_input; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 169; 158, attribute; 158, 159; 158, 168; 159, call; 159, 160; 159, 165; 160, attribute; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:subscriptions; 164, identifier:setdefault; 165, argument_list; 165, 166; 165, 167; 166, identifier:my_input; 167, list:[]; 168, identifier:append; 169, argument_list; 169, 170; 170, identifier:my_action
def _start_action_for_section(self, section): """ Start all the actions for a particular section """ if section == "configuration": return Global.LOGGER.debug("starting actions for section " + section) # read the configuration of the action action_configuration = Global.CONFIG_MANAGER.sections[ section] if len(action_configuration) == 0: Global.LOGGER.warn(f"section {section} has no configuration, skipping") return action_type = None # action_input = None new_managed_input = [] if "type" in action_configuration: action_type = action_configuration["type"] if "input" in action_configuration: action_input = action_configuration["input"] new_managed_input = (item.strip() for item in action_input.split(",")) my_action = Action.create_action_for_code(action_type, section, action_configuration, list(new_managed_input)) if not my_action: Global.LOGGER.warn(f"can't find a type for action {section}, the action will be skipped") return self.actions.append(my_action) Global.LOGGER.debug("updating the subscriptions table") for my_input in my_action.monitored_input: self.subscriptions.setdefault( my_input, []).append(my_action)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:check_completion; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:task; 5, default_parameter; 5, 6; 5, 7; 6, identifier:mark_incomplete; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:clear; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:return_stats; 13, False; 14, block; 14, 15; 14, 17; 14, 18; 14, 24; 14, 50; 14, 51; 14, 52; 14, 177; 14, 191; 15, expression_statement; 15, 16; 16, comment; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:to_clear; 21, call; 21, 22; 21, 23; 22, identifier:dict; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, pattern_list; 26, 27; 26, 28; 27, identifier:is_complete; 28, identifier:stats; 29, call; 29, 30; 29, 31; 30, identifier:_check_completion; 31, argument_list; 31, 32; 31, 33; 31, 36; 31, 39; 31, 42; 31, 47; 32, identifier:task; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:mark_incomplete; 35, identifier:mark_incomplete; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:clear; 38, identifier:clear; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:stats; 41, dictionary; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:visited; 44, call; 44, 45; 44, 46; 45, identifier:dict; 46, argument_list; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:to_clear; 49, identifier:to_clear; 50, comment; 51, comment; 52, while_statement; 52, 53; 52, 54; 52, 55; 52, 56; 53, identifier:to_clear; 54, comment; 55, comment; 56, block; 56, 57; 56, 61; 56, 168; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:found_clearable_task; 60, False; 61, for_statement; 61, 62; 61, 63; 61, 71; 62, identifier:task_id; 63, call; 63, 64; 63, 65; 64, identifier:list; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:to_clear; 69, identifier:keys; 70, argument_list; 71, block; 71, 72; 71, 78; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:v; 75, subscript; 75, 76; 75, 77; 76, identifier:to_clear; 77, identifier:task_id; 78, if_statement; 78, 79; 78, 83; 78, 84; 79, not_operator; 79, 80; 80, subscript; 80, 81; 80, 82; 81, identifier:v; 82, string:'required_by'; 83, comment; 84, block; 84, 85; 84, 89; 84, 95; 84, 144; 84, 145; 84, 146; 84, 147; 84, 151; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:found_clearable_task; 88, True; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:task; 92, subscript; 92, 93; 92, 94; 93, identifier:v; 94, string:'task'; 95, if_statement; 95, 96; 95, 101; 95, 131; 96, call; 96, 97; 96, 98; 97, identifier:isinstance; 98, argument_list; 98, 99; 98, 100; 99, identifier:task; 100, identifier:ORMTask; 101, block; 101, 102; 101, 108; 101, 114; 101, 120; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:task; 106, identifier:mark_incomplete; 107, argument_list; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:task; 112, identifier:clear; 113, argument_list; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:_increment_stats; 117, argument_list; 117, 118; 117, 119; 118, identifier:stats; 119, string:'Cleared'; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:config; 125, identifier:logger; 126, identifier:info; 127, argument_list; 127, 128; 128, binary_operator:+; 128, 129; 128, 130; 129, string:"Cleared task: "; 130, identifier:task_id; 131, else_clause; 131, 132; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:config; 138, identifier:logger; 139, identifier:info; 140, argument_list; 140, 141; 141, binary_operator:+; 141, 142; 141, 143; 142, string:'Cannot clear task, not an ORMTask: '; 143, identifier:task_id; 144, comment; 145, comment; 146, comment; 147, delete_statement; 147, 148; 148, subscript; 148, 149; 148, 150; 149, identifier:to_clear; 150, identifier:task_id; 151, for_statement; 151, 152; 151, 153; 151, 158; 152, identifier:w; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:to_clear; 156, identifier:values; 157, argument_list; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, subscript; 162, 163; 162, 164; 163, identifier:w; 164, string:'required_by'; 165, identifier:discard; 166, argument_list; 166, 167; 167, identifier:task_id; 168, if_statement; 168, 169; 168, 171; 169, not_operator; 169, 170; 170, identifier:found_clearable_task; 171, block; 171, 172; 172, raise_statement; 172, 173; 173, call; 173, 174; 173, 175; 174, identifier:RuntimeError; 175, argument_list; 175, 176; 176, string:"Error in recursive task clearing, no clearable task found"; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:config; 182, identifier:logger; 183, identifier:info; 184, argument_list; 184, 185; 185, binary_operator:+; 185, 186; 185, 187; 186, string:"Task completion checking, summary:\n"; 187, call; 187, 188; 187, 189; 188, identifier:str; 189, argument_list; 189, 190; 190, identifier:stats; 191, if_statement; 191, 192; 191, 193; 191, 198; 192, identifier:return_stats; 193, block; 193, 194; 194, return_statement; 194, 195; 195, expression_list; 195, 196; 195, 197; 196, identifier:is_complete; 197, identifier:stats; 198, else_clause; 198, 199; 199, block; 199, 200; 200, return_statement; 200, 201; 201, identifier:is_complete
def check_completion(task, mark_incomplete=False, clear=False, return_stats=False): """Recursively check if a task and all its requirements are complete Args: task (derived from luigi.Task): Task to check completion for; check everything 'downstream' from that task. mark_incomplete (bool): If ``True`` set any task as incomplete for which a requirement is found to be incomplete (checked recursively). This works only for tasks derived from :class:`ORMTask`. clear (bool): If ``True``, call the :func:`clear()` method of any task for which a requirement is found to be incomplete (checked recursively). This implies ``mark_incomplete = True``. This works only for tasks derived from :class:`ORMTask`. return_stats (bool): If ``True``, return task checking statistics in addition to completion status Returns: bool: ``True`` if the task, all its requirements and (recursively) all their requirements are complete, ``False`` otherwise. """ # run recursive task checking, get stats to_clear = dict() is_complete, stats = _check_completion(task, mark_incomplete=mark_incomplete, clear=clear, stats={}, visited=dict(), to_clear=to_clear) # task clearing needs to happen top-down: because of foreign key constraints, a task can # only be cleared once all tasks that require it have been cleared while to_clear: # find all tasks that we can currently clear - tasks not required by other tasks; # iterate over list of keys to be able to modify dict while iterating found_clearable_task = False for task_id in list(to_clear.keys()): v = to_clear[task_id] if not v['required_by']: # this is a task that can be cleared - no other task requires it found_clearable_task = True task = v['task'] if isinstance(task, ORMTask): task.mark_incomplete() task.clear() _increment_stats(stats, 'Cleared') config.logger.info("Cleared task: " + task_id) else: config.logger.info('Cannot clear task, not an ORMTask: ' + task_id) # remove the task from the list of tasks that need clearing, remove references # in the required_by lists of all other tasks; this is not an efficient implementation, # O(n^2), could be made O(n) using lookup tables of the task graph del to_clear[task_id] for w in to_clear.values(): w['required_by'].discard(task_id) if not found_clearable_task: raise RuntimeError("Error in recursive task clearing, no clearable task found") config.logger.info("Task completion checking, summary:\n" + str(stats)) if return_stats: return is_complete, stats else: return is_complete
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_connection_string; 3, parameters; 3, 4; 3, 5; 4, identifier:params; 5, default_parameter; 5, 6; 5, 7; 6, identifier:hide_password; 7, True; 8, block; 8, 9; 8, 11; 8, 19; 8, 29; 8, 39; 8, 49; 8, 59; 8, 69; 8, 79; 8, 80; 8, 109; 8, 110; 8, 171; 8, 172; 8, 178; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:connection_string; 14, binary_operator:+; 14, 15; 14, 18; 15, subscript; 15, 16; 15, 17; 16, identifier:params; 17, string:'driver'; 18, string:'://'; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:user; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:params; 25, identifier:get; 26, argument_list; 26, 27; 26, 28; 27, string:'user'; 28, None; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:password; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:params; 35, identifier:get; 36, argument_list; 36, 37; 36, 38; 37, string:'password'; 38, None; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:host; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:params; 45, identifier:get; 46, argument_list; 46, 47; 46, 48; 47, string:'host'; 48, None; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:port; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:params; 55, identifier:get; 56, argument_list; 56, 57; 56, 58; 57, string:'port'; 58, None; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:database; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:params; 65, identifier:get; 66, argument_list; 66, 67; 66, 68; 67, string:'database'; 68, None; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:is; 70, 71; 70, 72; 71, identifier:database; 72, None; 73, block; 73, 74; 74, raise_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:ValueError; 77, argument_list; 77, 78; 78, string:"Field 'database' of connection parameters cannot be None."; 79, comment; 80, if_statement; 80, 81; 80, 88; 80, 89; 81, boolean_operator:and; 81, 82; 81, 85; 82, comparison_operator:is; 82, 83; 82, 84; 83, identifier:password; 84, None; 85, comparison_operator:is; 85, 86; 85, 87; 86, identifier:user; 87, None; 88, comment; 89, block; 89, 90; 89, 99; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:password; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:Client; 96, identifier:_get_password; 97, argument_list; 97, 98; 98, identifier:params; 99, if_statement; 99, 100; 99, 103; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:password; 102, None; 103, block; 103, 104; 104, raise_statement; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:RuntimeError; 107, argument_list; 107, 108; 108, string:"Password not defined and not available in keyring."; 109, comment; 110, if_statement; 110, 111; 110, 114; 110, 115; 111, comparison_operator:is; 111, 112; 111, 113; 112, identifier:host; 113, None; 114, comment; 115, block; 115, 116; 115, 153; 115, 157; 116, if_statement; 116, 117; 116, 120; 117, comparison_operator:is; 117, 118; 117, 119; 118, identifier:user; 119, None; 120, block; 120, 121; 120, 125; 120, 126; 120, 149; 121, expression_statement; 121, 122; 122, augmented_assignment:+=; 122, 123; 122, 124; 123, identifier:connection_string; 124, identifier:user; 125, comment; 126, if_statement; 126, 127; 126, 133; 127, comparison_operator:>; 127, 128; 127, 132; 128, call; 128, 129; 128, 130; 129, identifier:len; 130, argument_list; 130, 131; 131, identifier:password; 132, integer:0; 133, block; 133, 134; 134, if_statement; 134, 135; 134, 136; 134, 141; 135, identifier:hide_password; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, augmented_assignment:+=; 138, 139; 138, 140; 139, identifier:connection_string; 140, string:":[password hidden]"; 141, else_clause; 141, 142; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, augmented_assignment:+=; 144, 145; 144, 146; 145, identifier:connection_string; 146, binary_operator:+; 146, 147; 146, 148; 147, string:":"; 148, identifier:password; 149, expression_statement; 149, 150; 150, augmented_assignment:+=; 150, 151; 150, 152; 151, identifier:connection_string; 152, string:"@"; 153, expression_statement; 153, 154; 154, augmented_assignment:+=; 154, 155; 154, 156; 155, identifier:connection_string; 156, identifier:host; 157, if_statement; 157, 158; 157, 161; 158, comparison_operator:is; 158, 159; 158, 160; 159, identifier:port; 160, None; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, augmented_assignment:+=; 163, 164; 163, 165; 164, identifier:connection_string; 165, binary_operator:+; 165, 166; 165, 167; 166, string:':'; 167, call; 167, 168; 167, 169; 168, identifier:str; 169, argument_list; 169, 170; 170, identifier:port; 171, comment; 172, expression_statement; 172, 173; 173, augmented_assignment:+=; 173, 174; 173, 175; 174, identifier:connection_string; 175, binary_operator:+; 175, 176; 175, 177; 176, string:'/'; 177, identifier:database; 178, return_statement; 178, 179; 179, identifier:connection_string
def get_connection_string(params, hide_password=True): """Get a database connection string Args: params (dict): database configuration, as defined in :mod:`ozelot.config` hide_password (bool): if True, the password is hidden in the returned string (use this for logging purposes). Returns: str: connection string """ connection_string = params['driver'] + '://' user = params.get('user', None) password = params.get('password', None) host = params.get('host', None) port = params.get('port', None) database = params.get('database', None) if database is None: raise ValueError("Field 'database' of connection parameters cannot be None.") # if password is not set, try to get it from keyring if password is None and user is not None: # noinspection PyTypeChecker password = Client._get_password(params) if password is None: raise RuntimeError("Password not defined and not available in keyring.") # don't add host/port/user/password if no host given if host is not None: # don't add user/password if user not given if user is not None: connection_string += user # omit zero-length passwords if len(password) > 0: if hide_password: connection_string += ":[password hidden]" else: connection_string += ":" + password connection_string += "@" connection_string += host if port is not None: connection_string += ':' + str(port) # noinspection PyTypeChecker connection_string += '/' + database return connection_string
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:movie_network; 3, parameters; 4, block; 4, 5; 4, 7; 4, 8; 4, 17; 4, 18; 4, 24; 4, 25; 4, 33; 4, 41; 4, 42; 4, 43; 4, 44; 4, 45; 4, 78; 4, 87; 4, 88; 4, 106; 4, 115; 4, 116; 4, 167; 4, 176; 4, 177; 4, 178; 4, 179; 4, 201; 4, 202; 4, 208; 4, 214; 4, 215; 4, 227; 4, 228; 4, 296; 4, 297; 4, 350; 4, 351; 4, 387; 4, 401; 4, 402; 4, 403; 4, 404; 4, 414; 4, 424; 4, 443; 4, 444; 4, 451; 5, expression_statement; 5, 6; 6, comment; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:template; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:jenv; 14, identifier:get_template; 15, argument_list; 15, 16; 16, string:"movie_network.html"; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:context; 21, call; 21, 22; 21, 23; 22, identifier:dict; 23, argument_list; 24, comment; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:cl; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:client; 31, identifier:get_client; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:session; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:cl; 39, identifier:create_session; 40, argument_list; 41, comment; 42, comment; 43, comment; 44, comment; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:query; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:session; 51, identifier:query; 52, argument_list; 52, 53; 52, 58; 52, 63; 52, 68; 52, 73; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:models; 56, identifier:Movie; 57, identifier:id; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:models; 61, identifier:Movie; 62, identifier:name; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:models; 66, identifier:Movie; 67, identifier:url; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:models; 71, identifier:Movie; 72, identifier:budget_inflation_adjusted; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:models; 76, identifier:Movie; 77, identifier:imdb_rating; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:movies; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:cl; 84, identifier:df_query; 85, argument_list; 85, 86; 86, identifier:query; 87, comment; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:query; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:session; 94, identifier:query; 95, argument_list; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:models; 99, identifier:MovieAppearance; 100, identifier:movie_id; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:models; 104, identifier:MovieAppearance; 105, identifier:character_id; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:appearances; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:cl; 112, identifier:df_query; 113, argument_list; 113, 114; 114, identifier:query; 115, comment; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:query; 119, call; 119, 120; 119, 143; 120, attribute; 120, 121; 120, 141; 120, 142; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:session; 124, identifier:query; 125, argument_list; 125, 126; 125, 131; 125, 136; 126, attribute; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:models; 129, identifier:Character; 130, identifier:id; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:models; 134, identifier:Character; 135, identifier:url; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:models; 139, identifier:Character; 140, identifier:name; 141, line_continuation:\; 142, identifier:filter; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 152; 145, attribute; 145, 146; 145, 151; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:models; 149, identifier:Character; 150, identifier:id; 151, identifier:in_; 152, argument_list; 152, 153; 153, list_comprehension; 153, 154; 153, 158; 154, call; 154, 155; 154, 156; 155, identifier:int; 156, argument_list; 156, 157; 157, identifier:i; 158, for_in_clause; 158, 159; 158, 160; 159, identifier:i; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, subscript; 162, 163; 162, 164; 163, identifier:appearances; 164, string:'character_id'; 165, identifier:unique; 166, argument_list; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:characters; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:cl; 173, identifier:df_query; 174, argument_list; 174, 175; 175, identifier:query; 176, comment; 177, comment; 178, comment; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:graph; 182, call; 182, 183; 182, 184; 183, identifier:dict; 184, argument_list; 184, 185; 184, 188; 184, 191; 184, 192; 184, 195; 184, 198; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:nodes; 187, list:[]; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:graph; 190, list:[]; 191, comment; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:links; 194, list:[]; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:directed; 197, False; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:multigraph; 200, True; 201, comment; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:movie_node_id; 205, call; 205, 206; 205, 207; 206, identifier:dict; 207, argument_list; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:character_node_id; 211, call; 211, 212; 211, 213; 212, identifier:dict; 213, argument_list; 214, comment; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:movie_size_factor; 218, binary_operator:/; 218, 219; 218, 220; 219, float:100.; 220, call; 220, 221; 220, 226; 221, attribute; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:movies; 224, string:'budget_inflation_adjusted'; 225, identifier:max; 226, argument_list; 227, comment; 228, for_statement; 228, 229; 228, 232; 228, 237; 229, pattern_list; 229, 230; 229, 231; 230, identifier:_; 231, identifier:data; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:movies; 235, identifier:iterrows; 236, argument_list; 237, block; 237, 238; 237, 251; 237, 252; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 245; 240, subscript; 240, 241; 240, 242; 241, identifier:movie_node_id; 242, subscript; 242, 243; 242, 244; 243, identifier:data; 244, string:'id'; 245, call; 245, 246; 245, 247; 246, identifier:len; 247, argument_list; 247, 248; 248, subscript; 248, 249; 248, 250; 249, identifier:graph; 250, string:'nodes'; 251, comment; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 259; 254, attribute; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:graph; 257, string:'nodes'; 258, identifier:append; 259, argument_list; 259, 260; 260, call; 260, 261; 260, 262; 261, identifier:dict; 262, argument_list; 262, 263; 262, 268; 262, 279; 262, 286; 262, 289; 263, keyword_argument; 263, 264; 263, 265; 264, identifier:id; 265, subscript; 265, 266; 265, 267; 266, identifier:data; 267, string:'name'; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:size; 270, call; 270, 271; 270, 272; 271, identifier:max; 272, argument_list; 272, 273; 272, 274; 273, float:5.; 274, binary_operator:*; 274, 275; 274, 278; 275, subscript; 275, 276; 275, 277; 276, identifier:data; 277, string:'budget_inflation_adjusted'; 278, identifier:movie_size_factor; 279, keyword_argument; 279, 280; 279, 281; 280, identifier:score; 281, binary_operator:/; 281, 282; 281, 285; 282, subscript; 282, 283; 282, 284; 283, identifier:data; 284, string:'imdb_rating'; 285, float:10.; 286, keyword_argument; 286, 287; 286, 288; 287, identifier:type; 288, string:'square'; 289, keyword_argument; 289, 290; 289, 291; 290, identifier:url; 291, binary_operator:+; 291, 292; 291, 293; 292, string:"http://marvel.wikia.com"; 293, subscript; 293, 294; 293, 295; 294, identifier:data; 295, string:'url'; 296, comment; 297, for_statement; 297, 298; 297, 301; 297, 306; 298, pattern_list; 298, 299; 298, 300; 299, identifier:_; 300, identifier:data; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:characters; 304, identifier:iterrows; 305, argument_list; 306, block; 306, 307; 306, 320; 306, 321; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 314; 309, subscript; 309, 310; 309, 311; 310, identifier:character_node_id; 311, subscript; 311, 312; 311, 313; 312, identifier:data; 313, string:'id'; 314, call; 314, 315; 314, 316; 315, identifier:len; 316, argument_list; 316, 317; 317, subscript; 317, 318; 317, 319; 318, identifier:graph; 319, string:'nodes'; 320, comment; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 328; 323, attribute; 323, 324; 323, 327; 324, subscript; 324, 325; 324, 326; 325, identifier:graph; 326, string:'nodes'; 327, identifier:append; 328, argument_list; 328, 329; 329, call; 329, 330; 329, 331; 330, identifier:dict; 331, argument_list; 331, 332; 331, 337; 331, 340; 331, 343; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:id; 334, subscript; 334, 335; 334, 336; 335, identifier:data; 336, string:'name'; 337, keyword_argument; 337, 338; 337, 339; 338, identifier:size; 339, integer:10; 340, keyword_argument; 340, 341; 340, 342; 341, identifier:type; 342, string:'circle'; 343, keyword_argument; 343, 344; 343, 345; 344, identifier:url; 345, binary_operator:+; 345, 346; 345, 347; 346, string:"http://marvel.wikia.com"; 347, subscript; 347, 348; 347, 349; 348, identifier:data; 349, string:'url'; 350, comment; 351, for_statement; 351, 352; 351, 355; 351, 360; 351, 361; 352, pattern_list; 352, 353; 352, 354; 353, identifier:_; 354, identifier:data; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:appearances; 358, identifier:iterrows; 359, argument_list; 360, comment; 361, block; 361, 362; 362, expression_statement; 362, 363; 363, call; 363, 364; 363, 369; 364, attribute; 364, 365; 364, 368; 365, subscript; 365, 366; 365, 367; 366, identifier:graph; 367, string:'links'; 368, identifier:append; 369, argument_list; 369, 370; 370, call; 370, 371; 370, 372; 371, identifier:dict; 372, argument_list; 372, 373; 372, 380; 373, keyword_argument; 373, 374; 373, 375; 374, identifier:source; 375, subscript; 375, 376; 375, 377; 376, identifier:movie_node_id; 377, subscript; 377, 378; 377, 379; 378, identifier:data; 379, string:'movie_id'; 380, keyword_argument; 380, 381; 380, 382; 381, identifier:target; 382, subscript; 382, 383; 382, 384; 383, identifier:character_node_id; 384, subscript; 384, 385; 384, 386; 385, identifier:data; 386, string:'character_id'; 387, expression_statement; 387, 388; 388, assignment; 388, 389; 388, 392; 389, subscript; 389, 390; 389, 391; 390, identifier:context; 391, string:'graph'; 392, call; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:json; 395, identifier:dumps; 396, argument_list; 396, 397; 396, 398; 397, identifier:graph; 398, keyword_argument; 398, 399; 398, 400; 399, identifier:indent; 400, integer:4; 401, comment; 402, comment; 403, comment; 404, expression_statement; 404, 405; 405, assignment; 405, 406; 405, 407; 406, identifier:out_file; 407, call; 407, 408; 407, 411; 408, attribute; 408, 409; 408, 410; 409, identifier:path; 410, identifier:join; 411, argument_list; 411, 412; 411, 413; 412, identifier:out_dir; 413, string:"movie_network.html"; 414, expression_statement; 414, 415; 415, assignment; 415, 416; 415, 417; 416, identifier:html_content; 417, call; 417, 418; 417, 421; 418, attribute; 418, 419; 418, 420; 419, identifier:template; 420, identifier:render; 421, argument_list; 421, 422; 422, dictionary_splat; 422, 423; 423, identifier:context; 424, with_statement; 424, 425; 424, 435; 425, with_clause; 425, 426; 426, with_item; 426, 427; 427, as_pattern; 427, 428; 427, 433; 428, call; 428, 429; 428, 430; 429, identifier:open; 430, argument_list; 430, 431; 430, 432; 431, identifier:out_file; 432, string:'w'; 433, as_pattern_target; 433, 434; 434, identifier:f; 435, block; 435, 436; 436, expression_statement; 436, 437; 437, call; 437, 438; 437, 441; 438, attribute; 438, 439; 438, 440; 439, identifier:f; 440, identifier:write; 441, argument_list; 441, 442; 442, identifier:html_content; 443, comment; 444, expression_statement; 444, 445; 445, call; 445, 446; 445, 449; 446, attribute; 446, 447; 446, 448; 447, identifier:plt; 448, identifier:close; 449, argument_list; 449, 450; 450, string:'all'; 451, expression_statement; 451, 452; 452, call; 452, 453; 452, 456; 453, attribute; 453, 454; 453, 455; 454, identifier:session; 455, identifier:close; 456, argument_list
def movie_network(): """Generate interactive network graph of movie appearances Output is an html page, rendered to 'movie_network.html' in the output directory. """ # page template template = jenv.get_template("movie_network.html") # container for template context context = dict() # a database client/session to run queries in cl = client.get_client() session = cl.create_session() # # query data # # get all Movies query = session.query(models.Movie.id, models.Movie.name, models.Movie.url, models.Movie.budget_inflation_adjusted, models.Movie.imdb_rating) movies = cl.df_query(query) # get all Movie Appearances query = session.query(models.MovieAppearance.movie_id, models.MovieAppearance.character_id) appearances = cl.df_query(query) # get all Characters that have movie appearances query = session.query(models.Character.id, models.Character.url, models.Character.name) \ .filter(models.Character.id.in_([int(i) for i in appearances['character_id'].unique()])) characters = cl.df_query(query) # # transform to network graph # graph = dict(nodes=[], graph=[], # this stays empty links=[], directed=False, multigraph=True) # containers for lookups from movie/character IDs to node IDs movie_node_id = dict() character_node_id = dict() # normalization for movie node size: 100 = max budget movie_size_factor = 100. / movies['budget_inflation_adjusted'].max() # nodes for movies for _, data in movies.iterrows(): movie_node_id[data['id']] = len(graph['nodes']) # noinspection PyTypeChecker graph['nodes'].append(dict(id=data['name'], size=max(5., data['budget_inflation_adjusted'] * movie_size_factor), score=data['imdb_rating'] / 10., type='square', url="http://marvel.wikia.com" + data['url'])) # nodes for characters for _, data in characters.iterrows(): character_node_id[data['id']] = len(graph['nodes']) # noinspection PyTypeChecker graph['nodes'].append(dict(id=data['name'], size=10, type='circle', url="http://marvel.wikia.com" + data['url'])) # links: movie appearances for _, data in appearances.iterrows(): # noinspection PyTypeChecker graph['links'].append(dict(source=movie_node_id[data['movie_id']], target=character_node_id[data['character_id']])) context['graph'] = json.dumps(graph, indent=4) # # render template # out_file = path.join(out_dir, "movie_network.html") html_content = template.render(**context) with open(out_file, 'w') as f: f.write(html_content) # done, clean up plt.close('all') session.close()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:better_exchook; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:etype; 5, identifier:value; 6, identifier:tb; 7, default_parameter; 7, 8; 7, 9; 8, identifier:debugshell; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:autodebugshell; 12, True; 13, default_parameter; 13, 14; 13, 15; 14, identifier:file; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:with_color; 18, None; 19, block; 19, 20; 19, 22; 19, 33; 19, 49; 19, 58; 19, 74; 19, 82; 19, 124; 19, 127; 19, 128; 19, 155; 19, 156; 19, 214; 19, 215; 19, 271; 19, 294; 19, 315; 20, expression_statement; 20, 21; 21, comment; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:is; 23, 24; 23, 25; 24, identifier:file; 25, None; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:file; 30, attribute; 30, 31; 30, 32; 31, identifier:sys; 32, identifier:stderr; 33, function_definition; 33, 34; 33, 35; 33, 37; 34, function_name:output; 35, parameters; 35, 36; 36, identifier:ln; 37, block; 37, 38; 37, 40; 38, expression_statement; 38, 39; 39, comment; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:file; 44, identifier:write; 45, argument_list; 45, 46; 46, binary_operator:+; 46, 47; 46, 48; 47, identifier:ln; 48, string:"\n"; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:color; 52, call; 52, 53; 52, 54; 53, identifier:Color; 54, argument_list; 54, 55; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:enable; 57, identifier:with_color; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:output; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:color; 64, argument_list; 64, 65; 64, 66; 64, 71; 65, string:"EXCEPTION"; 66, subscript; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:color; 69, identifier:fg_colors; 70, integer:1; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:bold; 73, True; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, pattern_list; 76, 77; 76, 78; 77, identifier:all_locals; 78, identifier:all_globals; 79, expression_list; 79, 80; 79, 81; 80, dictionary; 81, dictionary; 82, if_statement; 82, 83; 82, 86; 82, 109; 83, comparison_operator:is; 83, 84; 83, 85; 84, identifier:tb; 85, None; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:print_tb; 90, argument_list; 90, 91; 90, 92; 90, 95; 90, 98; 90, 101; 90, 104; 91, identifier:tb; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:allLocals; 94, identifier:all_locals; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:allGlobals; 97, identifier:all_globals; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:file; 100, identifier:file; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:withTitle; 103, True; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:with_color; 106, attribute; 106, 107; 106, 108; 107, identifier:color; 108, identifier:enable; 109, else_clause; 109, 110; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:output; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 117; 116, identifier:color; 117, argument_list; 117, 118; 117, 119; 118, string:"better_exchook: traceback unknown"; 119, subscript; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:color; 122, identifier:fg_colors; 123, integer:1; 124, import_statement; 124, 125; 125, dotted_name; 125, 126; 126, identifier:types; 127, comment; 128, function_definition; 128, 129; 128, 130; 128, 132; 129, function_name:_some_str; 130, parameters; 130, 131; 131, identifier:value; 132, block; 132, 133; 132, 135; 132, 136; 133, expression_statement; 133, 134; 134, comment; 135, comment; 136, try_statement; 136, 137; 136, 143; 137, block; 137, 138; 138, return_statement; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:str; 141, argument_list; 141, 142; 142, identifier:value; 143, except_clause; 143, 144; 143, 145; 144, identifier:Exception; 145, block; 145, 146; 146, return_statement; 146, 147; 147, binary_operator:%; 147, 148; 147, 149; 148, string:'<unprintable %s object>'; 149, attribute; 149, 150; 149, 154; 150, call; 150, 151; 150, 152; 151, identifier:type; 152, argument_list; 152, 153; 153, identifier:value; 154, identifier:__name__; 155, comment; 156, function_definition; 156, 157; 156, 158; 156, 161; 157, function_name:_format_final_exc_line; 158, parameters; 158, 159; 158, 160; 159, identifier:etype; 160, identifier:value; 161, block; 161, 162; 161, 169; 161, 212; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:value_str; 165, call; 165, 166; 165, 167; 166, identifier:_some_str; 167, argument_list; 167, 168; 168, identifier:value; 169, if_statement; 169, 170; 169, 176; 169, 191; 170, boolean_operator:or; 170, 171; 170, 174; 171, comparison_operator:is; 171, 172; 171, 173; 172, identifier:value; 173, None; 174, not_operator; 174, 175; 175, identifier:value_str; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:line; 180, call; 180, 181; 180, 182; 181, identifier:color; 182, argument_list; 182, 183; 182, 186; 183, binary_operator:%; 183, 184; 183, 185; 184, string:"%s"; 185, identifier:etype; 186, subscript; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:color; 189, identifier:fg_colors; 190, integer:1; 191, else_clause; 191, 192; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:line; 196, binary_operator:+; 196, 197; 196, 208; 197, call; 197, 198; 197, 199; 198, identifier:color; 199, argument_list; 199, 200; 199, 203; 200, binary_operator:%; 200, 201; 200, 202; 201, string:"%s"; 202, identifier:etype; 203, subscript; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:color; 206, identifier:fg_colors; 207, integer:1; 208, binary_operator:%; 208, 209; 208, 210; 209, string:": %s"; 210, tuple; 210, 211; 211, identifier:value_str; 212, return_statement; 212, 213; 213, identifier:line; 214, comment; 215, if_statement; 215, 216; 215, 248; 215, 258; 216, parenthesized_expression; 216, 217; 217, boolean_operator:or; 217, 218; 217, 242; 218, boolean_operator:or; 218, 219; 218, 239; 219, boolean_operator:or; 219, 220; 219, 225; 220, call; 220, 221; 220, 222; 221, identifier:isinstance; 222, argument_list; 222, 223; 222, 224; 223, identifier:etype; 224, identifier:BaseException; 225, parenthesized_expression; 225, 226; 226, boolean_operator:and; 226, 227; 226, 232; 227, call; 227, 228; 227, 229; 228, identifier:hasattr; 229, argument_list; 229, 230; 229, 231; 230, identifier:types; 231, string:"InstanceType"; 232, call; 232, 233; 232, 234; 233, identifier:isinstance; 234, argument_list; 234, 235; 234, 236; 235, identifier:etype; 236, attribute; 236, 237; 236, 238; 237, identifier:types; 238, identifier:InstanceType; 239, comparison_operator:is; 239, 240; 239, 241; 240, identifier:etype; 241, None; 242, comparison_operator:is; 242, 243; 242, 247; 243, call; 243, 244; 243, 245; 244, identifier:type; 245, argument_list; 245, 246; 246, identifier:etype; 247, identifier:str; 248, block; 248, 249; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 252; 251, identifier:output; 252, argument_list; 252, 253; 253, call; 253, 254; 253, 255; 254, identifier:_format_final_exc_line; 255, argument_list; 255, 256; 255, 257; 256, identifier:etype; 257, identifier:value; 258, else_clause; 258, 259; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 263; 262, identifier:output; 263, argument_list; 263, 264; 264, call; 264, 265; 264, 266; 265, identifier:_format_final_exc_line; 266, argument_list; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:etype; 269, identifier:__name__; 270, identifier:value; 271, if_statement; 271, 272; 271, 273; 271, 274; 272, identifier:autodebugshell; 273, comment; 274, block; 274, 275; 275, try_statement; 275, 276; 275, 290; 276, block; 276, 277; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:debugshell; 280, comparison_operator:!=; 280, 281; 280, 289; 281, call; 281, 282; 281, 283; 282, identifier:int; 283, argument_list; 283, 284; 284, subscript; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:os; 287, identifier:environ; 288, string:"DEBUG"; 289, integer:0; 290, except_clause; 290, 291; 290, 292; 291, identifier:Exception; 292, block; 292, 293; 293, pass_statement; 294, if_statement; 294, 295; 294, 296; 295, identifier:debugshell; 296, block; 296, 297; 296, 302; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 300; 299, identifier:output; 300, argument_list; 300, 301; 301, string:"---------- DEBUG SHELL -----------"; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:debug_shell; 305, argument_list; 305, 306; 305, 309; 305, 312; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:user_ns; 308, identifier:all_locals; 309, keyword_argument; 309, 310; 309, 311; 310, identifier:user_global_ns; 311, identifier:all_globals; 312, keyword_argument; 312, 313; 312, 314; 313, identifier:traceback; 314, identifier:tb; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:file; 319, identifier:flush; 320, argument_list
def better_exchook(etype, value, tb, debugshell=False, autodebugshell=True, file=None, with_color=None): """ Replacement for sys.excepthook. :param etype: exception type :param value: exception value :param tb: traceback :param bool debugshell: spawn a debug shell at the context of the exception :param bool autodebugshell: if env DEBUG is an integer != 0, it will spawn a debug shell :param io.TextIOBase|io.StringIO file: output stream where we will print the traceback and exception information. stderr by default. :param bool|None with_color: whether to use ANSI escape codes for colored output """ if file is None: file = sys.stderr def output(ln): """ :param str ln: :return: nothing, prints to ``file`` """ file.write(ln + "\n") color = Color(enable=with_color) output(color("EXCEPTION", color.fg_colors[1], bold=True)) all_locals, all_globals = {}, {} if tb is not None: print_tb(tb, allLocals=all_locals, allGlobals=all_globals, file=file, withTitle=True, with_color=color.enable) else: output(color("better_exchook: traceback unknown", color.fg_colors[1])) import types # noinspection PyShadowingNames def _some_str(value): """ :param object value: :rtype: str """ # noinspection PyBroadException try: return str(value) except Exception: return '<unprintable %s object>' % type(value).__name__ # noinspection PyShadowingNames def _format_final_exc_line(etype, value): value_str = _some_str(value) if value is None or not value_str: line = color("%s" % etype, color.fg_colors[1]) else: line = color("%s" % etype, color.fg_colors[1]) + ": %s" % (value_str,) return line # noinspection PyUnresolvedReferences if (isinstance(etype, BaseException) or (hasattr(types, "InstanceType") and isinstance(etype, types.InstanceType)) or etype is None or type(etype) is str): output(_format_final_exc_line(etype, value)) else: output(_format_final_exc_line(etype.__name__, value)) if autodebugshell: # noinspection PyBroadException try: debugshell = int(os.environ["DEBUG"]) != 0 except Exception: pass if debugshell: output("---------- DEBUG SHELL -----------") debug_shell(user_ns=all_locals, user_global_ns=all_globals, traceback=tb) file.flush()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:dump_all_thread_tracebacks; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:exclude_thread_ids; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:file; 9, None; 10, block; 10, 11; 10, 13; 10, 22; 10, 32; 10, 35; 11, expression_statement; 11, 12; 12, comment; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:exclude_thread_ids; 16, None; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:exclude_thread_ids; 21, list:[]; 22, if_statement; 22, 23; 22, 25; 23, not_operator; 23, 24; 24, identifier:file; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:file; 29, attribute; 29, 30; 29, 31; 30, identifier:sys; 31, identifier:stdout; 32, import_statement; 32, 33; 33, dotted_name; 33, 34; 34, identifier:threading; 35, if_statement; 35, 36; 35, 41; 35, 205; 36, call; 36, 37; 36, 38; 37, identifier:hasattr; 38, argument_list; 38, 39; 38, 40; 39, identifier:sys; 40, string:"_current_frames"; 41, block; 41, 42; 41, 50; 41, 66; 41, 67; 41, 197; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:print; 45, argument_list; 45, 46; 45, 47; 46, string:""; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:file; 49, identifier:file; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:threads; 53, dictionary_comprehension; 53, 54; 53, 59; 54, pair; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:t; 57, identifier:ident; 58, identifier:t; 59, for_in_clause; 59, 60; 59, 61; 60, identifier:t; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:threading; 64, identifier:enumerate; 65, argument_list; 66, comment; 67, for_statement; 67, 68; 67, 71; 67, 80; 68, pattern_list; 68, 69; 68, 70; 69, identifier:tid; 70, identifier:stack; 71, call; 71, 72; 71, 79; 72, attribute; 72, 73; 72, 78; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:sys; 76, identifier:_current_frames; 77, argument_list; 78, identifier:items; 79, argument_list; 80, block; 80, 81; 80, 87; 80, 88; 80, 89; 80, 90; 80, 96; 80, 100; 80, 109; 80, 166; 80, 181; 80, 189; 81, if_statement; 81, 82; 81, 85; 82, comparison_operator:in; 82, 83; 82, 84; 83, identifier:tid; 84, identifier:exclude_thread_ids; 85, block; 85, 86; 86, continue_statement; 87, comment; 88, comment; 89, comment; 90, if_statement; 90, 91; 90, 94; 91, comparison_operator:not; 91, 92; 91, 93; 92, identifier:tid; 93, identifier:threads; 94, block; 94, 95; 95, continue_statement; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:tags; 99, list:[]; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:thread; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:threads; 106, identifier:get; 107, argument_list; 107, 108; 108, identifier:tid; 109, if_statement; 109, 110; 109, 111; 109, 157; 110, identifier:thread; 111, block; 111, 112; 111, 120; 111, 134; 111, 135; 111, 149; 112, assert_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:isinstance; 115, argument_list; 115, 116; 115, 117; 116, identifier:thread; 117, attribute; 117, 118; 117, 119; 118, identifier:threading; 119, identifier:Thread; 120, if_statement; 120, 121; 120, 128; 121, comparison_operator:is; 121, 122; 121, 123; 122, identifier:thread; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:threading; 126, identifier:currentThread; 127, argument_list; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, augmented_assignment:+=; 130, 131; 130, 132; 131, identifier:tags; 132, list:["current"]; 132, 133; 133, string:"current"; 134, comment; 135, if_statement; 135, 136; 135, 143; 136, call; 136, 137; 136, 138; 137, identifier:isinstance; 138, argument_list; 138, 139; 138, 140; 139, identifier:thread; 140, attribute; 140, 141; 140, 142; 141, identifier:threading; 142, identifier:_MainThread; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, augmented_assignment:+=; 145, 146; 145, 147; 146, identifier:tags; 147, list:["main"]; 147, 148; 148, string:"main"; 149, expression_statement; 149, 150; 150, augmented_assignment:+=; 150, 151; 150, 152; 151, identifier:tags; 152, list:[str(thread)]; 152, 153; 153, call; 153, 154; 153, 155; 154, identifier:str; 155, argument_list; 155, 156; 156, identifier:thread; 157, else_clause; 157, 158; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, augmented_assignment:+=; 160, 161; 160, 162; 161, identifier:tags; 162, list:["unknown with id %i" % tid]; 162, 163; 163, binary_operator:%; 163, 164; 163, 165; 164, string:"unknown with id %i"; 165, identifier:tid; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:print; 169, argument_list; 169, 170; 169, 178; 170, binary_operator:%; 170, 171; 170, 172; 171, string:"Thread %s:"; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, string:", "; 175, identifier:join; 176, argument_list; 176, 177; 177, identifier:tags; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:file; 180, identifier:file; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 184; 183, identifier:print_tb; 184, argument_list; 184, 185; 184, 186; 185, identifier:stack; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:file; 188, identifier:file; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:print; 192, argument_list; 192, 193; 192, 194; 193, string:""; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:file; 196, identifier:file; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:print; 200, argument_list; 200, 201; 200, 202; 201, string:"That were all threads."; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:file; 204, identifier:file; 205, else_clause; 205, 206; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 210; 209, identifier:print; 210, argument_list; 210, 211; 210, 212; 211, string:"Does not have sys._current_frames, cannot get thread tracebacks."; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:file; 214, identifier:file
def dump_all_thread_tracebacks(exclude_thread_ids=None, file=None): """ Prints the traceback of all threads. :param set[int]|list[int]|None exclude_thread_ids: threads to exclude :param io.TextIOBase|io.StringIO file: output stream """ if exclude_thread_ids is None: exclude_thread_ids = [] if not file: file = sys.stdout import threading if hasattr(sys, "_current_frames"): print("", file=file) threads = {t.ident: t for t in threading.enumerate()} # noinspection PyProtectedMember for tid, stack in sys._current_frames().items(): if tid in exclude_thread_ids: continue # This is a bug in earlier Python versions. # http://bugs.python.org/issue17094 # Note that this leaves out all threads not created via the threading module. if tid not in threads: continue tags = [] thread = threads.get(tid) if thread: assert isinstance(thread, threading.Thread) if thread is threading.currentThread(): tags += ["current"] # noinspection PyProtectedMember,PyUnresolvedReferences if isinstance(thread, threading._MainThread): tags += ["main"] tags += [str(thread)] else: tags += ["unknown with id %i" % tid] print("Thread %s:" % ", ".join(tags), file=file) print_tb(stack, file=file) print("", file=file) print("That were all threads.", file=file) else: print("Does not have sys._current_frames, cannot get thread tracebacks.", file=file)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:_main; 3, parameters; 4, block; 4, 5; 4, 7; 4, 162; 4, 163; 4, 164; 4, 216; 4, 243; 4, 280; 4, 281; 4, 294; 4, 295; 4, 308; 4, 309; 4, 330; 4, 350; 4, 351; 4, 355; 4, 356; 4, 357; 5, expression_statement; 5, 6; 6, comment; 7, if_statement; 7, 8; 7, 18; 7, 66; 7, 94; 7, 135; 8, comparison_operator:==; 8, 9; 8, 16; 9, subscript; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:sys; 12, identifier:argv; 13, slice; 13, 14; 13, 15; 14, integer:1; 15, colon; 16, list:["test"]; 16, 17; 17, string:"test"; 18, block; 18, 19; 18, 55; 18, 60; 19, for_statement; 19, 20; 19, 23; 19, 33; 20, pattern_list; 20, 21; 20, 22; 21, identifier:k; 22, identifier:v; 23, call; 23, 24; 23, 25; 24, identifier:sorted; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, call; 28, 29; 28, 30; 29, identifier:globals; 30, argument_list; 31, identifier:items; 32, argument_list; 33, block; 33, 34; 33, 44; 33, 51; 34, if_statement; 34, 35; 34, 42; 35, not_operator; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:k; 39, identifier:startswith; 40, argument_list; 40, 41; 41, string:"test_"; 42, block; 42, 43; 43, continue_statement; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:print; 47, argument_list; 47, 48; 48, binary_operator:%; 48, 49; 48, 50; 49, string:"running: %s()"; 50, identifier:k; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:v; 54, argument_list; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:print; 58, argument_list; 58, 59; 59, string:"ok."; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:sys; 64, identifier:exit; 65, argument_list; 66, elif_clause; 66, 67; 66, 77; 67, comparison_operator:==; 67, 68; 67, 75; 68, subscript; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:sys; 71, identifier:argv; 72, slice; 72, 73; 72, 74; 73, integer:1; 74, colon; 75, list:["debug_shell"]; 75, 76; 76, string:"debug_shell"; 77, block; 77, 78; 77, 88; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 81; 80, identifier:debug_shell; 81, argument_list; 81, 82; 81, 85; 82, call; 82, 83; 82, 84; 83, identifier:locals; 84, argument_list; 85, call; 85, 86; 85, 87; 86, identifier:globals; 87, argument_list; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:sys; 92, identifier:exit; 93, argument_list; 94, elif_clause; 94, 95; 94, 105; 95, comparison_operator:==; 95, 96; 95, 103; 96, subscript; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:sys; 99, identifier:argv; 100, slice; 100, 101; 100, 102; 101, integer:1; 102, colon; 103, list:["debug_shell_exception"]; 103, 104; 104, string:"debug_shell_exception"; 105, block; 105, 106; 105, 129; 106, try_statement; 106, 107; 106, 113; 107, block; 107, 108; 108, raise_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:Exception; 111, argument_list; 111, 112; 112, string:"demo exception"; 113, except_clause; 113, 114; 113, 115; 114, identifier:Exception; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:better_exchook; 119, argument_list; 119, 120; 119, 126; 120, list_splat; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:sys; 124, identifier:exc_info; 125, argument_list; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:debugshell; 128, True; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:sys; 133, identifier:exit; 134, argument_list; 135, elif_clause; 135, 136; 135, 143; 136, subscript; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:sys; 139, identifier:argv; 140, slice; 140, 141; 140, 142; 141, integer:1; 142, colon; 143, block; 143, 144; 143, 155; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:print; 147, argument_list; 147, 148; 148, binary_operator:%; 148, 149; 148, 150; 149, string:"Usage: %s (test|...)"; 150, subscript; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:sys; 153, identifier:argv; 154, integer:0; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:sys; 159, identifier:exit; 160, argument_list; 160, 161; 161, integer:1; 162, comment; 163, comment; 164, try_statement; 164, 165; 164, 203; 165, block; 165, 166; 165, 176; 165, 177; 165, 199; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:x; 169, dictionary; 169, 170; 169, 173; 170, pair; 170, 171; 170, 172; 171, integer:1; 172, integer:2; 173, pair; 173, 174; 173, 175; 174, string:"a"; 175, string:"b"; 176, comment; 177, function_definition; 177, 178; 177, 179; 177, 180; 178, function_name:f; 179, parameters; 180, block; 180, 181; 180, 185; 180, 186; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:y; 184, string:"foo"; 185, comment; 186, expression_statement; 186, 187; 186, 188; 186, 189; 186, 194; 186, 197; 186, 198; 187, identifier:x; 188, integer:42; 189, attribute; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:sys; 192, identifier:stdin; 193, identifier:__class__; 194, attribute; 194, 195; 194, 196; 195, identifier:sys; 196, identifier:exc_info; 197, identifier:y; 198, identifier:z; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:f; 202, argument_list; 203, except_clause; 203, 204; 203, 205; 204, identifier:Exception; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 209; 208, identifier:better_exchook; 209, argument_list; 209, 210; 210, list_splat; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:sys; 214, identifier:exc_info; 215, argument_list; 216, try_statement; 216, 217; 216, 218; 216, 230; 217, comment; 218, block; 218, 219; 218, 229; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 226; 221, parenthesized_expression; 221, 222; 222, lambda; 222, 223; 222, 225; 223, lambda_parameters; 223, 224; 224, identifier:_x; 225, None; 226, argument_list; 226, 227; 226, 228; 227, identifier:__name__; 228, integer:42; 229, comment; 230, except_clause; 230, 231; 230, 232; 231, identifier:Exception; 232, block; 232, 233; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 236; 235, identifier:better_exchook; 236, argument_list; 236, 237; 237, list_splat; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:sys; 241, identifier:exc_info; 242, argument_list; 243, try_statement; 243, 244; 243, 267; 244, block; 244, 245; 244, 258; 244, 264; 245, class_definition; 245, 246; 245, 247; 246, identifier:Obj; 247, block; 247, 248; 248, function_definition; 248, 249; 248, 250; 248, 252; 249, function_name:__repr__; 250, parameters; 250, 251; 251, identifier:self; 252, block; 252, 253; 253, return_statement; 253, 254; 254, parenthesized_expression; 254, 255; 255, binary_operator:+; 255, 256; 255, 257; 256, string:"<Obj multi-\n"; 257, string:" line repr>"; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:obj; 261, call; 261, 262; 261, 263; 262, identifier:Obj; 263, argument_list; 264, assert_statement; 264, 265; 265, not_operator; 265, 266; 266, identifier:obj; 267, except_clause; 267, 268; 267, 269; 268, identifier:Exception; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 273; 272, identifier:better_exchook; 273, argument_list; 273, 274; 274, list_splat; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:sys; 278, identifier:exc_info; 279, argument_list; 280, comment; 281, function_definition; 281, 282; 281, 283; 281, 285; 282, function_name:f1; 283, parameters; 283, 284; 284, identifier:a; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, call; 287, 288; 287, 289; 288, identifier:f2; 289, argument_list; 289, 290; 289, 293; 290, binary_operator:+; 290, 291; 290, 292; 291, identifier:a; 292, integer:1; 293, integer:2; 294, comment; 295, function_definition; 295, 296; 295, 297; 295, 300; 296, function_name:f2; 297, parameters; 297, 298; 297, 299; 298, identifier:a; 299, identifier:b; 300, block; 300, 301; 301, expression_statement; 301, 302; 302, call; 302, 303; 302, 304; 303, identifier:f3; 304, argument_list; 304, 305; 305, binary_operator:+; 305, 306; 305, 307; 306, identifier:a; 307, identifier:b; 308, comment; 309, function_definition; 309, 310; 309, 311; 309, 313; 310, function_name:f3; 311, parameters; 311, 312; 312, identifier:a; 313, block; 313, 314; 313, 323; 313, 324; 313, 329; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:b; 317, binary_operator:+; 317, 318; 317, 322; 318, parenthesized_expression; 318, 319; 319, binary_operator:*; 319, 320; 319, 321; 320, string:"abc"; 321, integer:100; 322, string:"-interesting"; 323, comment; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 327; 326, identifier:a; 327, argument_list; 327, 328; 328, identifier:b; 329, comment; 330, try_statement; 330, 331; 330, 337; 331, block; 331, 332; 332, expression_statement; 332, 333; 333, call; 333, 334; 333, 335; 334, identifier:f1; 335, argument_list; 335, 336; 336, integer:13; 337, except_clause; 337, 338; 337, 339; 338, identifier:Exception; 339, block; 339, 340; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 343; 342, identifier:better_exchook; 343, argument_list; 343, 344; 344, list_splat; 344, 345; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:sys; 348, identifier:exc_info; 349, argument_list; 350, comment; 351, expression_statement; 351, 352; 352, call; 352, 353; 352, 354; 353, identifier:install; 354, argument_list; 355, comment; 356, comment; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 360; 359, identifier:finalfail; 360, argument_list; 360, 361; 361, identifier:sys
def _main(): """ Some demo. """ if sys.argv[1:] == ["test"]: for k, v in sorted(globals().items()): if not k.startswith("test_"): continue print("running: %s()" % k) v() print("ok.") sys.exit() elif sys.argv[1:] == ["debug_shell"]: debug_shell(locals(), globals()) sys.exit() elif sys.argv[1:] == ["debug_shell_exception"]: try: raise Exception("demo exception") except Exception: better_exchook(*sys.exc_info(), debugshell=True) sys.exit() elif sys.argv[1:]: print("Usage: %s (test|...)" % sys.argv[0]) sys.exit(1) # some examples # this code produces this output: https://gist.github.com/922622 try: x = {1: 2, "a": "b"} # noinspection PyMissingOrEmptyDocstring def f(): y = "foo" # noinspection PyUnresolvedReferences,PyStatementEffect x, 42, sys.stdin.__class__, sys.exc_info, y, z f() except Exception: better_exchook(*sys.exc_info()) try: # noinspection PyArgumentList (lambda _x: None)(__name__, 42) # multiline except Exception: better_exchook(*sys.exc_info()) try: class Obj: def __repr__(self): return ( "<Obj multi-\n" + " line repr>") obj = Obj() assert not obj except Exception: better_exchook(*sys.exc_info()) # noinspection PyMissingOrEmptyDocstring def f1(a): f2(a + 1, 2) # noinspection PyMissingOrEmptyDocstring def f2(a, b): f3(a + b) # noinspection PyMissingOrEmptyDocstring def f3(a): b = ("abc" * 100) + "-interesting" # some long demo str a(b) # error, not callable try: f1(13) except Exception: better_exchook(*sys.exc_info()) # use this to overwrite the global exception handler install() # and fail # noinspection PyUnresolvedReferences finalfail(sys)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:mol_supplier; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:lines; 5, identifier:no_halt; 6, identifier:assign_descriptors; 7, block; 7, 8; 7, 10; 7, 113; 8, expression_statement; 8, 9; 9, comment; 10, function_definition; 10, 11; 10, 12; 10, 14; 11, function_name:sdf_block; 12, parameters; 12, 13; 13, identifier:lns; 14, block; 14, 15; 14, 19; 14, 23; 14, 27; 14, 105; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:mol; 18, list:[]; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:opt; 22, list:[]; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:is_mol; 26, True; 27, for_statement; 27, 28; 27, 29; 27, 30; 28, identifier:line; 29, identifier:lns; 30, block; 30, 31; 31, if_statement; 31, 32; 31, 38; 31, 66; 31, 78; 31, 92; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:line; 35, identifier:startswith; 36, argument_list; 36, 37; 37, string:"$$$$"; 38, block; 38, 39; 38, 50; 38, 54; 38, 60; 39, expression_statement; 39, 40; 40, yield; 40, 41; 41, expression_list; 41, 42; 41, 46; 42, subscript; 42, 43; 42, 44; 43, identifier:mol; 44, slice; 44, 45; 45, colon; 46, subscript; 46, 47; 46, 48; 47, identifier:opt; 48, slice; 48, 49; 49, colon; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:is_mol; 53, True; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:mol; 58, identifier:clear; 59, argument_list; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:opt; 64, identifier:clear; 65, argument_list; 66, elif_clause; 66, 67; 66, 73; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:line; 70, identifier:startswith; 71, argument_list; 71, 72; 72, string:"M END"; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:is_mol; 77, False; 78, elif_clause; 78, 79; 78, 80; 79, identifier:is_mol; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:mol; 85, identifier:append; 86, argument_list; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:line; 90, identifier:rstrip; 91, argument_list; 92, else_clause; 92, 93; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:opt; 98, identifier:append; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:line; 103, identifier:rstrip; 104, argument_list; 105, if_statement; 105, 106; 105, 107; 106, identifier:mol; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, yield; 109, 110; 110, expression_list; 110, 111; 110, 112; 111, identifier:mol; 112, identifier:opt; 113, for_statement; 113, 114; 113, 119; 113, 126; 114, pattern_list; 114, 115; 114, 116; 115, identifier:i; 116, tuple_pattern; 116, 117; 116, 118; 117, identifier:mol; 118, identifier:opt; 119, call; 119, 120; 119, 121; 120, identifier:enumerate; 121, argument_list; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:sdf_block; 124, argument_list; 124, 125; 125, identifier:lines; 126, block; 126, 127; 126, 278; 126, 287; 127, try_statement; 127, 128; 127, 146; 127, 189; 127, 223; 128, block; 128, 129; 128, 136; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:c; 132, call; 132, 133; 132, 134; 133, identifier:molecule; 134, argument_list; 134, 135; 135, identifier:mol; 136, if_statement; 136, 137; 136, 138; 137, identifier:assign_descriptors; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:molutil; 143, identifier:assign_descriptors; 144, argument_list; 144, 145; 145, identifier:c; 146, except_clause; 146, 147; 146, 151; 147, as_pattern; 147, 148; 147, 149; 148, identifier:ValueError; 149, as_pattern_target; 149, 150; 150, identifier:err; 151, block; 151, 152; 152, if_statement; 152, 153; 152, 154; 152, 177; 153, identifier:no_halt; 154, block; 154, 155; 154, 168; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:print; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, string:"Unsupported symbol: {} (#{} in v2000reader)"; 162, identifier:format; 163, argument_list; 163, 164; 163, 165; 164, identifier:err; 165, binary_operator:+; 165, 166; 165, 167; 166, identifier:i; 167, integer:1; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:c; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:molutil; 174, identifier:null_molecule; 175, argument_list; 175, 176; 176, identifier:assign_descriptors; 177, else_clause; 177, 178; 178, block; 178, 179; 179, raise_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:ValueError; 182, argument_list; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, string:"Unsupported symbol: {}"; 186, identifier:format; 187, argument_list; 187, 188; 188, identifier:err; 189, except_clause; 189, 190; 189, 194; 190, as_pattern; 190, 191; 190, 192; 191, identifier:RuntimeError; 192, as_pattern_target; 192, 193; 193, identifier:err; 194, block; 194, 195; 195, if_statement; 195, 196; 195, 197; 195, 211; 196, identifier:no_halt; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 201; 200, identifier:print; 201, argument_list; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, string:"Failed to minimize ring: {} (#{} in v2000reader)"; 205, identifier:format; 206, argument_list; 206, 207; 206, 208; 207, identifier:err; 208, binary_operator:+; 208, 209; 208, 210; 209, identifier:i; 210, integer:1; 211, else_clause; 211, 212; 212, block; 212, 213; 213, raise_statement; 213, 214; 214, call; 214, 215; 214, 216; 215, identifier:RuntimeError; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, string:"Failed to minimize ring: {}"; 220, identifier:format; 221, argument_list; 221, 222; 222, identifier:err; 223, except_clause; 223, 224; 224, block; 224, 225; 225, if_statement; 225, 226; 225, 227; 225, 262; 226, identifier:no_halt; 227, block; 227, 228; 227, 240; 227, 249; 227, 258; 227, 261; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:print; 231, argument_list; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, string:"Unexpected error (#{} in v2000reader)"; 235, identifier:format; 236, argument_list; 236, 237; 237, binary_operator:+; 237, 238; 237, 239; 238, identifier:i; 239, integer:1; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:c; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:molutil; 246, identifier:null_molecule; 247, argument_list; 247, 248; 248, identifier:assign_descriptors; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:c; 253, identifier:data; 254, call; 254, 255; 254, 256; 255, identifier:optional_data; 256, argument_list; 256, 257; 257, identifier:opt; 258, expression_statement; 258, 259; 259, yield; 259, 260; 260, identifier:c; 261, continue_statement; 262, else_clause; 262, 263; 263, block; 263, 264; 263, 273; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:print; 267, argument_list; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:traceback; 271, identifier:format_exc; 272, argument_list; 273, raise_statement; 273, 274; 274, call; 274, 275; 274, 276; 275, identifier:Exception; 276, argument_list; 276, 277; 277, string:"Unsupported Error"; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:c; 282, identifier:data; 283, call; 283, 284; 283, 285; 284, identifier:optional_data; 285, argument_list; 285, 286; 286, identifier:opt; 287, expression_statement; 287, 288; 288, yield; 288, 289; 289, identifier:c
def mol_supplier(lines, no_halt, assign_descriptors): """Yields molecules generated from CTAB text Args: lines (iterable): CTAB text lines no_halt (boolean): True: shows warning messages for invalid format and go on. False: throws an exception for it and stop parsing. assign_descriptors (boolean): if True, default descriptors are automatically assigned. """ def sdf_block(lns): mol = [] opt = [] is_mol = True for line in lns: if line.startswith("$$$$"): yield mol[:], opt[:] is_mol = True mol.clear() opt.clear() elif line.startswith("M END"): is_mol = False elif is_mol: mol.append(line.rstrip()) else: opt.append(line.rstrip()) if mol: yield mol, opt for i, (mol, opt) in enumerate(sdf_block(lines)): try: c = molecule(mol) if assign_descriptors: molutil.assign_descriptors(c) except ValueError as err: if no_halt: print("Unsupported symbol: {} (#{} in v2000reader)".format( err, i + 1)) c = molutil.null_molecule(assign_descriptors) else: raise ValueError("Unsupported symbol: {}".format(err)) except RuntimeError as err: if no_halt: print( "Failed to minimize ring: {} (#{} in v2000reader)".format( err, i + 1) ) else: raise RuntimeError("Failed to minimize ring: {}".format(err)) except: if no_halt: print("Unexpected error (#{} in v2000reader)".format(i + 1)) c = molutil.null_molecule(assign_descriptors) c.data = optional_data(opt) yield c continue else: print(traceback.format_exc()) raise Exception("Unsupported Error") c.data = optional_data(opt) yield c
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:render_diagram; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:root_task; 5, identifier:out_base; 6, default_parameter; 6, 7; 6, 8; 7, identifier:max_param_len; 8, integer:20; 9, default_parameter; 9, 10; 9, 11; 10, identifier:horizontal; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:colored; 14, False; 15, block; 15, 16; 15, 18; 15, 21; 15, 24; 15, 27; 15, 32; 15, 41; 15, 42; 15, 47; 15, 57; 15, 58; 15, 59; 15, 94; 15, 95; 15, 101; 15, 102; 15, 108; 15, 109; 15, 326; 15, 327; 15, 332; 15, 333; 15, 340; 15, 341; 15, 372; 15, 373; 15, 386; 15, 411; 15, 412; 15, 413; 16, expression_statement; 16, 17; 17, comment; 18, import_statement; 18, 19; 19, dotted_name; 19, 20; 20, identifier:re; 21, import_statement; 21, 22; 22, dotted_name; 22, 23; 23, identifier:codecs; 24, import_statement; 24, 25; 25, dotted_name; 25, 26; 26, identifier:subprocess; 27, import_from_statement; 27, 28; 27, 30; 28, dotted_name; 28, 29; 29, identifier:ozelot; 30, dotted_name; 30, 31; 31, identifier:config; 32, import_from_statement; 32, 33; 32, 37; 32, 39; 33, dotted_name; 33, 34; 33, 35; 33, 36; 34, identifier:ozelot; 35, identifier:etl; 36, identifier:tasks; 37, dotted_name; 37, 38; 38, identifier:get_task_name; 39, dotted_name; 39, 40; 40, identifier:get_task_param_string; 41, comment; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:lines; 45, list:[u"digraph G {"]; 45, 46; 46, string:u"digraph G {"; 47, if_statement; 47, 48; 47, 49; 48, identifier:horizontal; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:lines; 54, identifier:append; 55, argument_list; 55, 56; 56, string:u"rankdir=LR;"; 57, comment; 58, comment; 59, function_definition; 59, 60; 59, 61; 59, 63; 60, function_name:get_id; 61, parameters; 61, 62; 62, identifier:task; 63, block; 63, 64; 63, 78; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:s; 67, binary_operator:+; 67, 68; 67, 74; 68, binary_operator:+; 68, 69; 68, 73; 69, call; 69, 70; 69, 71; 70, identifier:get_task_name; 71, argument_list; 71, 72; 72, identifier:task; 73, string:"_"; 74, call; 74, 75; 74, 76; 75, identifier:get_task_param_string; 76, argument_list; 76, 77; 77, identifier:task; 78, return_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:re; 82, identifier:sub; 83, argument_list; 83, 84; 83, 85; 83, 86; 84, string:r'\W+'; 85, string:''; 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:' '; 92, string:'_'; 93, identifier:s; 94, comment; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:existing_nodes; 98, call; 98, 99; 98, 100; 99, identifier:set; 100, argument_list; 101, comment; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:existing_edges; 105, call; 105, 106; 105, 107; 106, identifier:set; 107, argument_list; 108, comment; 109, function_definition; 109, 110; 109, 111; 109, 116; 110, function_name:_build; 111, parameters; 111, 112; 111, 113; 112, identifier:task; 113, default_parameter; 113, 114; 113, 115; 114, identifier:parent_id; 115, None; 116, block; 116, 117; 116, 124; 116, 125; 116, 297; 116, 298; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:tid; 120, call; 120, 121; 120, 122; 121, identifier:get_id; 122, argument_list; 122, 123; 123, identifier:task; 124, comment; 125, if_statement; 125, 126; 125, 129; 125, 130; 126, comparison_operator:not; 126, 127; 126, 128; 127, identifier:tid; 128, identifier:existing_nodes; 129, comment; 130, block; 130, 131; 130, 139; 130, 143; 130, 187; 130, 208; 130, 217; 130, 242; 130, 243; 130, 273; 130, 280; 130, 281; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:params; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:task; 137, identifier:to_str_params; 138, argument_list; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:param_list; 142, string:""; 143, for_statement; 143, 144; 143, 147; 143, 152; 143, 153; 144, pattern_list; 144, 145; 144, 146; 145, identifier:k; 146, identifier:v; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:params; 150, identifier:items; 151, argument_list; 152, comment; 153, block; 153, 154; 153, 172; 154, if_statement; 154, 155; 154, 161; 155, comparison_operator:>; 155, 156; 155, 160; 156, call; 156, 157; 156, 158; 157, identifier:len; 158, argument_list; 158, 159; 159, identifier:v; 160, identifier:max_param_len; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:v; 165, binary_operator:+; 165, 166; 165, 171; 166, subscript; 166, 167; 166, 168; 167, identifier:v; 168, slice; 168, 169; 168, 170; 169, colon; 170, identifier:max_param_len; 171, string:"..."; 172, expression_statement; 172, 173; 173, augmented_assignment:+=; 173, 174; 173, 175; 174, identifier:param_list; 175, call; 175, 176; 175, 184; 176, attribute; 176, 177; 176, 183; 177, concatenated_string; 177, 178; 177, 179; 177, 180; 177, 181; 177, 182; 178, string:"<TR><TD ALIGN=\"LEFT\">"; 179, string:"<FONT POINT-SIZE=\"10\">{:s}</FONT>"; 180, string:"</TD><TD ALIGN=\"LEFT\">"; 181, string:"<FONT POINT-SIZE=\"10\">{:s}</FONT>"; 182, string:"</TD></TR>"; 183, identifier:format; 184, argument_list; 184, 185; 184, 186; 185, identifier:k; 186, identifier:v; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:label; 190, binary_operator:+; 190, 191; 190, 207; 191, binary_operator:+; 191, 192; 191, 206; 192, call; 192, 193; 192, 201; 193, attribute; 193, 194; 193, 200; 194, concatenated_string; 194, 195; 194, 196; 194, 197; 194, 198; 194, 199; 195, string:"<TABLE BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"1\">"; 196, string:"<TR><TD COLSPAN=\"2\" ALIGN=\"CENTER\">"; 197, string:"<FONT POINT-SIZE=\"12\">{:s}</FONT>"; 198, string:"</TD></TR>"; 199, string:""; 200, identifier:format; 201, argument_list; 201, 202; 202, call; 202, 203; 202, 204; 203, identifier:get_task_name; 204, argument_list; 204, 205; 205, identifier:task; 206, identifier:param_list; 207, string:"</TABLE>"; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:style; 211, call; 211, 212; 211, 213; 212, identifier:getattr; 213, argument_list; 213, 214; 213, 215; 213, 216; 214, identifier:task; 215, string:'diagram_style'; 216, list:[]; 217, if_statement; 217, 218; 217, 219; 217, 236; 218, identifier:colored; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:color; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, string:', color="{:s}"'; 226, identifier:format; 227, argument_list; 227, 228; 228, conditional_expression:if; 228, 229; 228, 230; 228, 235; 229, string:"green"; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:task; 233, identifier:complete; 234, argument_list; 235, string:"red"; 236, else_clause; 236, 237; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:color; 241, string:''; 242, comment; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:lines; 247, identifier:append; 248, argument_list; 248, 249; 249, call; 249, 250; 249, 255; 250, attribute; 250, 251; 250, 254; 251, concatenated_string; 251, 252; 251, 253; 252, string:u"{name:s} [label=< {label:s} >, shape=\"rect\" {color:s}, style=\"{style:s}\"];\n"; 253, string:u""; 254, identifier:format; 255, argument_list; 255, 256; 255, 259; 255, 262; 255, 265; 256, keyword_argument; 256, 257; 256, 258; 257, identifier:name; 258, identifier:tid; 259, keyword_argument; 259, 260; 259, 261; 260, identifier:label; 261, identifier:label; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:color; 264, identifier:color; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:style; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, string:','; 270, identifier:join; 271, argument_list; 271, 272; 272, identifier:style; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:existing_nodes; 277, identifier:add; 278, argument_list; 278, 279; 279, identifier:tid; 280, comment; 281, for_statement; 281, 282; 281, 283; 281, 288; 282, identifier:req; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:task; 286, identifier:requires; 287, argument_list; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 292; 291, identifier:_build; 292, argument_list; 292, 293; 292, 294; 293, identifier:req; 294, keyword_argument; 294, 295; 294, 296; 295, identifier:parent_id; 296, identifier:tid; 297, comment; 298, if_statement; 298, 299; 298, 308; 299, boolean_operator:and; 299, 300; 299, 303; 300, comparison_operator:is; 300, 301; 300, 302; 301, identifier:parent_id; 302, None; 303, comparison_operator:not; 303, 304; 303, 307; 304, tuple; 304, 305; 304, 306; 305, identifier:tid; 306, identifier:parent_id; 307, identifier:existing_edges; 308, block; 308, 309; 309, expression_statement; 309, 310; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:lines; 313, identifier:append; 314, argument_list; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, string:u"{source:s} -> {target:s};\n"; 318, identifier:format; 319, argument_list; 319, 320; 319, 323; 320, keyword_argument; 320, 321; 320, 322; 321, identifier:source; 322, identifier:tid; 323, keyword_argument; 323, 324; 323, 325; 324, identifier:target; 325, identifier:parent_id; 326, comment; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:_build; 330, argument_list; 330, 331; 331, identifier:root_task; 332, comment; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:lines; 337, identifier:append; 338, argument_list; 338, 339; 339, string:u"}"; 340, comment; 341, with_statement; 341, 342; 341, 359; 342, with_clause; 342, 343; 343, with_item; 343, 344; 344, as_pattern; 344, 345; 344, 357; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:codecs; 348, identifier:open; 349, argument_list; 349, 350; 349, 353; 349, 354; 350, binary_operator:+; 350, 351; 350, 352; 351, identifier:out_base; 352, string:'.dot'; 353, string:'w'; 354, keyword_argument; 354, 355; 354, 356; 355, identifier:encoding; 356, string:'utf-8'; 357, as_pattern_target; 357, 358; 358, identifier:f; 359, block; 359, 360; 360, expression_statement; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:f; 364, identifier:write; 365, argument_list; 365, 366; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, string:u"\n"; 369, identifier:join; 370, argument_list; 370, 371; 371, identifier:lines; 372, comment; 373, if_statement; 373, 374; 373, 380; 374, not_operator; 374, 375; 375, call; 375, 376; 375, 377; 376, identifier:hasattr; 377, argument_list; 377, 378; 377, 379; 378, identifier:config; 379, string:'DOT_EXECUTABLE'; 380, block; 380, 381; 381, raise_statement; 381, 382; 382, call; 382, 383; 382, 384; 383, identifier:RuntimeError; 384, argument_list; 384, 385; 385, string:"Please configure the 'DOT_EXECUTABLE' variable in your 'project_config.py'"; 386, if_statement; 386, 387; 386, 398; 387, not_operator; 387, 388; 388, call; 388, 389; 388, 394; 389, attribute; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:os; 392, identifier:path; 393, identifier:exists; 394, argument_list; 394, 395; 395, attribute; 395, 396; 395, 397; 396, identifier:config; 397, identifier:DOT_EXECUTABLE; 398, block; 398, 399; 399, raise_statement; 399, 400; 400, call; 400, 401; 400, 402; 401, identifier:IOError; 402, argument_list; 402, 403; 403, binary_operator:+; 403, 404; 403, 405; 404, string:"Could not find file pointed to by 'DOT_EXECUTABLE': "; 405, call; 405, 406; 405, 407; 406, identifier:str; 407, argument_list; 407, 408; 408, attribute; 408, 409; 408, 410; 409, identifier:config; 410, identifier:DOT_EXECUTABLE; 411, comment; 412, comment; 413, expression_statement; 413, 414; 414, call; 414, 415; 414, 418; 415, attribute; 415, 416; 415, 417; 416, identifier:subprocess; 417, identifier:check_call; 418, argument_list; 418, 419; 419, list:[ config.DOT_EXECUTABLE, '-T', 'png', '-o', out_base + '.png', out_base + '.dot' ]; 419, 420; 419, 423; 419, 424; 419, 425; 419, 426; 419, 429; 420, attribute; 420, 421; 420, 422; 421, identifier:config; 422, identifier:DOT_EXECUTABLE; 423, string:'-T'; 424, string:'png'; 425, string:'-o'; 426, binary_operator:+; 426, 427; 426, 428; 427, identifier:out_base; 428, string:'.png'; 429, binary_operator:+; 429, 430; 429, 431; 430, identifier:out_base; 431, string:'.dot'
def render_diagram(root_task, out_base, max_param_len=20, horizontal=False, colored=False): """Render a diagram of the ETL pipeline All upstream tasks (i.e. requirements) of :attr:`root_task` are rendered. Nodes are, by default, styled as simple rects. This style is augmented by any :attr:`diagram_style` attributes of the tasks. .. note:: This function requires the 'dot' executable from the GraphViz package to be installed and its location configured in your `project_config.py` variable :attr:`DOT_EXECUTABLE`. Args: root_task (luigi.Task): Task instance that defines the 'upstream root' of the pipeline out_base (str): base output file name (file endings will be appended) max_param_len (int): Maximum shown length of task parameter values horizontal (bool): If True, layout graph left-to-right instead of top-to-bottom colored (bool): If True, show task completion status by color of nodes """ import re import codecs import subprocess from ozelot import config from ozelot.etl.tasks import get_task_name, get_task_param_string # the graph - lines in dot file lines = [u"digraph G {"] if horizontal: lines.append(u"rankdir=LR;") # helper function: make unique task id from task name and parameters: # task name + parameter string, with spaces replaced with _ and all non-alphanumerical characters stripped def get_id(task): s = get_task_name(task) + "_" + get_task_param_string(task) return re.sub(r'\W+', '', re.sub(' ', '_', s)) # node names of tasks that have already been added to the graph existing_nodes = set() # edge sets (tuples of two node names) that have already been added existing_edges = set() # recursion function for generating the pipeline graph def _build(task, parent_id=None): tid = get_id(task) # add node if it's not already there if tid not in existing_nodes: # build task label: task name plus dictionary of parameters as table params = task.to_str_params() param_list = "" for k, v in params.items(): # truncate param value if necessary, and add "..." if len(v) > max_param_len: v = v[:max_param_len] + "..." param_list += "<TR><TD ALIGN=\"LEFT\">" \ "<FONT POINT-SIZE=\"10\">{:s}</FONT>" \ "</TD><TD ALIGN=\"LEFT\">" \ "<FONT POINT-SIZE=\"10\">{:s}</FONT>" \ "</TD></TR>".format(k, v) label = "<TABLE BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"1\">" \ "<TR><TD COLSPAN=\"2\" ALIGN=\"CENTER\">" \ "<FONT POINT-SIZE=\"12\">{:s}</FONT>" \ "</TD></TR>" \ "".format(get_task_name(task)) + param_list + "</TABLE>" style = getattr(task, 'diagram_style', []) if colored: color = ', color="{:s}"'.format("green" if task.complete() else "red") else: color = '' # add a node for the task lines.append(u"{name:s} [label=< {label:s} >, shape=\"rect\" {color:s}, style=\"{style:s}\"];\n" u"".format(name=tid, label=label, color=color, style=','.join(style))) existing_nodes.add(tid) # recurse over requirements for req in task.requires(): _build(req, parent_id=tid) # add edge from current node to (upstream) parent, if it doesn't already exist if parent_id is not None and (tid, parent_id) not in existing_edges: lines.append(u"{source:s} -> {target:s};\n".format(source=tid, target=parent_id)) # generate pipeline graph _build(root_task) # close the graph definition lines.append(u"}") # write description in DOT format with codecs.open(out_base + '.dot', 'w', encoding='utf-8') as f: f.write(u"\n".join(lines)) # check existence of DOT_EXECUTABLE variable and file if not hasattr(config, 'DOT_EXECUTABLE'): raise RuntimeError("Please configure the 'DOT_EXECUTABLE' variable in your 'project_config.py'") if not os.path.exists(config.DOT_EXECUTABLE): raise IOError("Could not find file pointed to by 'DOT_EXECUTABLE': " + str(config.DOT_EXECUTABLE)) # render to image using DOT # noinspection PyUnresolvedReferences subprocess.check_call([ config.DOT_EXECUTABLE, '-T', 'png', '-o', out_base + '.png', out_base + '.dot' ])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:binarize; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:df; 5, identifier:category_classes; 6, default_parameter; 6, 7; 6, 8; 7, identifier:all_classes; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:drop; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:astype; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:inplace; 17, True; 18, default_parameter; 18, 19; 18, 20; 19, identifier:min_freq; 20, None; 21, block; 21, 22; 21, 24; 21, 65; 21, 80; 21, 166; 21, 184; 22, expression_statement; 22, 23; 23, comment; 24, if_statement; 24, 25; 24, 31; 24, 55; 25, comparison_operator:is; 25, 26; 25, 30; 26, call; 26, 27; 26, 28; 27, identifier:type; 28, argument_list; 28, 29; 29, identifier:category_classes; 30, identifier:dict; 31, block; 31, 32; 31, 39; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:columns; 35, call; 35, 36; 35, 37; 36, identifier:set; 37, argument_list; 37, 38; 38, identifier:category_classes; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:category_classes; 42, dictionary_comprehension; 42, 43; 42, 52; 43, pair; 43, 44; 43, 45; 44, identifier:column; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:df; 49, identifier:column; 50, identifier:unique; 51, argument_list; 52, for_in_clause; 52, 53; 52, 54; 53, identifier:column; 54, identifier:columns; 55, else_clause; 55, 56; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:columns; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:category_classes; 63, identifier:keys; 64, argument_list; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:df_new; 68, conditional_expression:if; 68, 69; 68, 70; 68, 71; 69, identifier:df; 70, identifier:inplace; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:df; 74, identifier:drop; 75, argument_list; 75, 76; 75, 77; 76, identifier:columns; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:axis; 79, integer:1; 80, for_statement; 80, 81; 80, 82; 80, 83; 81, identifier:category; 82, identifier:columns; 83, block; 83, 84; 83, 90; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:classes; 87, subscript; 87, 88; 87, 89; 88, identifier:category_classes; 89, identifier:category; 90, for_statement; 90, 91; 90, 92; 90, 108; 91, identifier:i; 92, call; 92, 93; 92, 94; 93, identifier:range; 94, argument_list; 94, 95; 95, conditional_expression:if; 95, 96; 95, 102; 95, 104; 96, binary_operator:-; 96, 97; 96, 101; 97, call; 97, 98; 97, 99; 98, identifier:len; 99, argument_list; 99, 100; 100, identifier:classes; 101, integer:1; 102, not_operator; 102, 103; 103, identifier:all_classes; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, identifier:classes; 108, block; 108, 109; 108, 119; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:c; 112, comparison_operator:==; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:df; 115, identifier:category; 116, subscript; 116, 117; 116, 118; 117, identifier:classes; 118, identifier:i; 119, if_statement; 119, 120; 119, 130; 120, boolean_operator:or; 120, 121; 120, 123; 121, not_operator; 121, 122; 122, identifier:min_freq; 123, comparison_operator:>=; 123, 124; 123, 129; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:c; 127, identifier:sum; 128, argument_list; 129, identifier:min_freq; 130, block; 130, 131; 130, 145; 131, if_statement; 131, 132; 131, 135; 132, comparison_operator:is; 132, 133; 132, 134; 133, identifier:astype; 134, None; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:c; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:c; 142, identifier:astype; 143, argument_list; 143, 144; 144, identifier:astype; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 165; 147, subscript; 147, 148; 147, 149; 148, identifier:df_new; 149, binary_operator:%; 149, 150; 149, 151; 150, string:'%s_%s'; 151, tuple; 151, 152; 151, 153; 152, identifier:category; 153, call; 153, 154; 153, 162; 154, attribute; 154, 155; 154, 161; 155, call; 155, 156; 155, 157; 156, identifier:str; 157, argument_list; 157, 158; 158, subscript; 158, 159; 158, 160; 159, identifier:classes; 160, identifier:i; 161, identifier:replace; 162, argument_list; 162, 163; 162, 164; 163, string:' '; 164, string:'_'; 165, identifier:c; 166, if_statement; 166, 167; 166, 170; 167, boolean_operator:and; 167, 168; 167, 169; 168, identifier:drop; 169, identifier:inplace; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:df_new; 175, identifier:drop; 176, argument_list; 176, 177; 176, 178; 176, 181; 177, identifier:columns; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:axis; 180, integer:1; 181, keyword_argument; 181, 182; 181, 183; 182, identifier:inplace; 183, True; 184, return_statement; 184, 185; 185, identifier:df_new
def binarize(df, category_classes, all_classes=True, drop=True, astype=None, inplace=True, min_freq=None): """ Binarize specified categoricals. Works inplace! Args: - df: the DataFrame whose columns to binarize - category_classes: either a dict of (column : [class1, class2, ...]) pairs or a collection of column names, in which case classes are given using df[column].unique() - all_classes: when False, the last class is skipped - drop: when True, the original categorical columns are dropped - astype: a type for the resulting binaries, e.g. np.float32. When None, use the defualt (bool). - inplace: whether to modify the DataFrame inplace Returns: the DataFrame with binarized columns """ if type(category_classes) is not dict: columns = set(category_classes) category_classes = {column: df[column].unique() for column in columns} else: columns = category_classes.keys() df_new = df if inplace else df.drop(columns, axis=1) for category in columns: classes = category_classes[category] for i in range(len(classes)-1 if not all_classes else len(classes)): c = df[category] == classes[i] if not min_freq or c.sum() >= min_freq: if astype is not None: c = c.astype(astype) df_new['%s_%s' % (category, str(classes[i]).replace(' ', '_'))] = c if drop and inplace: df_new.drop(columns, axis=1, inplace=True) return df_new
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:find_package_docs; 3, parameters; 3, 4; 3, 5; 4, identifier:package_dir; 5, default_parameter; 5, 6; 5, 7; 6, identifier:skippedNames; 7, None; 8, block; 8, 9; 8, 11; 8, 20; 8, 29; 8, 41; 8, 53; 8, 74; 8, 94; 8, 98; 8, 102; 8, 106; 8, 194; 8, 265; 8, 357; 8, 368; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:logger; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:logging; 17, identifier:getLogger; 18, argument_list; 18, 19; 19, identifier:__name__; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:skippedNames; 23, None; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:skippedNames; 28, list:[]; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:doc_dir; 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:join; 38, argument_list; 38, 39; 38, 40; 39, identifier:package_dir; 40, string:'doc'; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:modules_yaml_path; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:os; 48, identifier:path; 49, identifier:join; 50, argument_list; 50, 51; 50, 52; 51, identifier:doc_dir; 52, string:'manifest.yaml'; 53, if_statement; 53, 54; 53, 63; 54, not_operator; 54, 55; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:os; 59, identifier:path; 60, identifier:exists; 61, argument_list; 61, 62; 62, identifier:modules_yaml_path; 63, block; 63, 64; 64, raise_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:NoPackageDocs; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, string:'Manifest YAML not found: {0}'; 71, identifier:format; 72, argument_list; 72, 73; 73, identifier:modules_yaml_path; 74, with_statement; 74, 75; 74, 84; 75, with_clause; 75, 76; 76, with_item; 76, 77; 77, as_pattern; 77, 78; 77, 82; 78, call; 78, 79; 78, 80; 79, identifier:open; 80, argument_list; 80, 81; 81, identifier:modules_yaml_path; 82, as_pattern_target; 82, 83; 83, identifier:f; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:manifest_data; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:yaml; 91, identifier:safe_load; 92, argument_list; 92, 93; 93, identifier:f; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:module_dirs; 97, dictionary; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:package_dirs; 101, dictionary; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:static_dirs; 105, dictionary; 106, if_statement; 106, 107; 106, 110; 107, comparison_operator:in; 107, 108; 107, 109; 108, string:'modules'; 109, identifier:manifest_data; 110, block; 110, 111; 111, for_statement; 111, 112; 111, 113; 111, 116; 112, identifier:module_name; 113, subscript; 113, 114; 113, 115; 114, identifier:manifest_data; 115, string:'modules'; 116, block; 116, 117; 116, 135; 116, 147; 116, 148; 116, 176; 116, 182; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:in; 118, 119; 118, 120; 119, identifier:module_name; 120, identifier:skippedNames; 121, block; 121, 122; 121, 134; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:logger; 126, identifier:debug; 127, argument_list; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, string:'Skipping module {0}'; 131, identifier:format; 132, argument_list; 132, 133; 133, identifier:module_name; 134, continue_statement; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:module_dir; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:os; 142, identifier:path; 143, identifier:join; 144, argument_list; 144, 145; 144, 146; 145, identifier:doc_dir; 146, identifier:module_name; 147, comment; 148, if_statement; 148, 149; 148, 158; 149, not_operator; 149, 150; 150, call; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:os; 154, identifier:path; 155, identifier:isdir; 156, argument_list; 156, 157; 157, identifier:module_dir; 158, block; 158, 159; 158, 168; 158, 175; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:message; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, string:'module doc dir not found: {0}'; 165, identifier:format; 166, argument_list; 166, 167; 167, identifier:module_dir; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:logger; 172, identifier:warning; 173, argument_list; 173, 174; 174, identifier:message; 175, continue_statement; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, subscript; 178, 179; 178, 180; 179, identifier:module_dirs; 180, identifier:module_name; 181, identifier:module_dir; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:logger; 186, identifier:debug; 187, argument_list; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, string:'Found module doc dir {0}'; 191, identifier:format; 192, argument_list; 192, 193; 193, identifier:module_dir; 194, if_statement; 194, 195; 194, 198; 195, comparison_operator:in; 195, 196; 195, 197; 196, string:'package'; 197, identifier:manifest_data; 198, block; 198, 199; 198, 205; 198, 217; 198, 218; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:package_name; 202, subscript; 202, 203; 202, 204; 203, identifier:manifest_data; 204, string:'package'; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:full_package_dir; 208, call; 208, 209; 208, 214; 209, attribute; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:os; 212, identifier:path; 213, identifier:join; 214, argument_list; 214, 215; 214, 216; 215, identifier:doc_dir; 216, identifier:package_name; 217, comment; 218, if_statement; 218, 219; 218, 232; 218, 251; 219, boolean_operator:and; 219, 220; 219, 228; 219, 229; 220, call; 220, 221; 220, 226; 221, attribute; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:os; 224, identifier:path; 225, identifier:isdir; 226, argument_list; 226, 227; 227, identifier:full_package_dir; 228, line_continuation:\; 229, comparison_operator:not; 229, 230; 229, 231; 230, identifier:package_name; 231, identifier:skippedNames; 232, block; 232, 233; 232, 239; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 238; 235, subscript; 235, 236; 235, 237; 236, identifier:package_dirs; 237, identifier:package_name; 238, identifier:full_package_dir; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:logger; 243, identifier:debug; 244, argument_list; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, string:'Found package doc dir {0}'; 248, identifier:format; 249, argument_list; 249, 250; 250, identifier:full_package_dir; 251, else_clause; 251, 252; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:logger; 257, identifier:warning; 258, argument_list; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, string:'package doc dir excluded or not found: {0}'; 262, identifier:format; 263, argument_list; 263, 264; 264, identifier:full_package_dir; 265, if_statement; 265, 266; 265, 269; 266, comparison_operator:in; 266, 267; 266, 268; 267, string:'statics'; 268, identifier:manifest_data; 269, block; 269, 270; 270, for_statement; 270, 271; 270, 272; 270, 275; 271, identifier:static_dirname; 272, subscript; 272, 273; 272, 274; 273, identifier:manifest_data; 274, string:'statics'; 275, block; 275, 276; 275, 288; 275, 289; 275, 317; 275, 318; 275, 319; 275, 339; 275, 345; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:full_static_dir; 279, call; 279, 280; 279, 285; 280, attribute; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:os; 283, identifier:path; 284, identifier:join; 285, argument_list; 285, 286; 285, 287; 286, identifier:doc_dir; 287, identifier:static_dirname; 288, comment; 289, if_statement; 289, 290; 289, 299; 290, not_operator; 290, 291; 291, call; 291, 292; 291, 297; 292, attribute; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:os; 295, identifier:path; 296, identifier:isdir; 297, argument_list; 297, 298; 298, identifier:full_static_dir; 299, block; 299, 300; 299, 309; 299, 316; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:message; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, string:'_static doc dir not found: {0}'; 306, identifier:format; 307, argument_list; 307, 308; 308, identifier:full_static_dir; 309, expression_statement; 309, 310; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:logger; 313, identifier:warning; 314, argument_list; 314, 315; 315, identifier:message; 316, continue_statement; 317, comment; 318, comment; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 322; 321, identifier:relative_static_dir; 322, call; 322, 323; 322, 328; 323, attribute; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:os; 326, identifier:path; 327, identifier:relpath; 328, argument_list; 328, 329; 328, 330; 329, identifier:full_static_dir; 330, call; 330, 331; 330, 336; 331, attribute; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:os; 334, identifier:path; 335, identifier:join; 336, argument_list; 336, 337; 336, 338; 337, identifier:doc_dir; 338, string:'_static'; 339, expression_statement; 339, 340; 340, assignment; 340, 341; 340, 344; 341, subscript; 341, 342; 341, 343; 342, identifier:static_dirs; 343, identifier:relative_static_dir; 344, identifier:full_static_dir; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:logger; 349, identifier:debug; 350, argument_list; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, string:'Found _static doc dir: {0}'; 354, identifier:format; 355, argument_list; 355, 356; 356, identifier:full_static_dir; 357, expression_statement; 357, 358; 358, assignment; 358, 359; 358, 360; 359, identifier:Dirs; 360, call; 360, 361; 360, 362; 361, identifier:namedtuple; 362, argument_list; 362, 363; 362, 364; 363, string:'Dirs'; 364, list:['module_dirs', 'package_dirs', 'static_dirs']; 364, 365; 364, 366; 364, 367; 365, string:'module_dirs'; 366, string:'package_dirs'; 367, string:'static_dirs'; 368, return_statement; 368, 369; 369, call; 369, 370; 369, 371; 370, identifier:Dirs; 371, argument_list; 371, 372; 371, 375; 371, 378; 372, keyword_argument; 372, 373; 372, 374; 373, identifier:module_dirs; 374, identifier:module_dirs; 375, keyword_argument; 375, 376; 375, 377; 376, identifier:package_dirs; 377, identifier:package_dirs; 378, keyword_argument; 378, 379; 378, 380; 379, identifier:static_dirs; 380, identifier:static_dirs
def find_package_docs(package_dir, skippedNames=None): """Find documentation directories in a package using ``manifest.yaml``. Parameters ---------- package_dir : `str` Directory of an EUPS package. skippedNames : `list` of `str`, optional List of package or module names to skip when creating links. Returns ------- doc_dirs : namedtuple Attributes of the namedtuple are: - ``package_dirs`` (`dict`). Keys are package names (for example, ``'afw'``). Values are absolute directory paths to the package's documentation directory inside the package's ``doc`` directory. If there is no package-level documentation the dictionary will be empty. - ``modules_dirs`` (`dict`). Keys are module names (for example, ``'lsst.afw.table'``). Values are absolute directory paths to the module's directory inside the package's ``doc`` directory. If a package has no modules the returned dictionary will be empty. - ``static_doc_dirs`` (`dict`). Keys are directory names relative to the ``_static`` directory. Values are absolute directory paths to the static documentation directory in the package. If there isn't a declared ``_static`` directory, this dictionary is empty. Raises ------ NoPackageDocs Raised when the ``manifest.yaml`` file cannot be found in a package. Notes ----- Stack packages have documentation in subdirectories of their `doc` directory. The ``manifest.yaml`` file declares what these directories are so that they can be symlinked into the root project. There are three types of documentation directories: 1. Package doc directories contain documentation for the EUPS package aspect. This is optional. 2. Module doc directories contain documentation for a Python package aspect. These are optional. 3. Static doc directories are root directories inside the package's ``doc/_static/`` directory. These are optional. These are declared in a package's ``doc/manifest.yaml`` file. For example: .. code-block:: yaml package: "afw" modules: - "lsst.afw.image" - "lsst.afw.geom" statics: - "_static/afw" This YAML declares *module* documentation directories: - ``afw/doc/lsst.afw.image/`` - ``afw/doc/lsst.afw.geom/`` It also declares a *package* documentation directory: - ``afw/doc/afw`` And a static documentaton directory: - ``afw/doc/_static/afw`` """ logger = logging.getLogger(__name__) if skippedNames is None: skippedNames = [] doc_dir = os.path.join(package_dir, 'doc') modules_yaml_path = os.path.join(doc_dir, 'manifest.yaml') if not os.path.exists(modules_yaml_path): raise NoPackageDocs( 'Manifest YAML not found: {0}'.format(modules_yaml_path)) with open(modules_yaml_path) as f: manifest_data = yaml.safe_load(f) module_dirs = {} package_dirs = {} static_dirs = {} if 'modules' in manifest_data: for module_name in manifest_data['modules']: if module_name in skippedNames: logger.debug('Skipping module {0}'.format(module_name)) continue module_dir = os.path.join(doc_dir, module_name) # validate that the module's documentation directory does exist if not os.path.isdir(module_dir): message = 'module doc dir not found: {0}'.format(module_dir) logger.warning(message) continue module_dirs[module_name] = module_dir logger.debug('Found module doc dir {0}'.format(module_dir)) if 'package' in manifest_data: package_name = manifest_data['package'] full_package_dir = os.path.join(doc_dir, package_name) # validate the directory exists if os.path.isdir(full_package_dir) \ and package_name not in skippedNames: package_dirs[package_name] = full_package_dir logger.debug('Found package doc dir {0}'.format(full_package_dir)) else: logger.warning('package doc dir excluded or not found: {0}'.format( full_package_dir)) if 'statics' in manifest_data: for static_dirname in manifest_data['statics']: full_static_dir = os.path.join(doc_dir, static_dirname) # validate the directory exists if not os.path.isdir(full_static_dir): message = '_static doc dir not found: {0}'.format( full_static_dir) logger.warning(message) continue # Make a relative path to `_static` that's used as the # link source in the root docproject's _static/ directory relative_static_dir = os.path.relpath( full_static_dir, os.path.join(doc_dir, '_static')) static_dirs[relative_static_dir] = full_static_dir logger.debug('Found _static doc dir: {0}'.format(full_static_dir)) Dirs = namedtuple('Dirs', ['module_dirs', 'package_dirs', 'static_dirs']) return Dirs(module_dirs=module_dirs, package_dirs=package_dirs, static_dirs=static_dirs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_max_id; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:session; 6, block; 6, 7; 6, 9; 6, 10; 6, 14; 6, 60; 6, 61; 6, 75; 6, 76; 6, 96; 6, 97; 6, 106; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:id_base; 13, None; 14, for_statement; 14, 15; 14, 16; 14, 25; 15, identifier:c; 16, binary_operator:+; 16, 17; 16, 19; 17, list:[cls]; 17, 18; 18, identifier:cls; 19, call; 19, 20; 19, 21; 20, identifier:list; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:cls; 24, identifier:__bases__; 25, block; 25, 26; 26, for_statement; 26, 27; 26, 28; 26, 31; 27, identifier:base_class; 28, attribute; 28, 29; 28, 30; 29, identifier:c; 30, identifier:__bases__; 31, block; 31, 32; 32, if_statement; 32, 33; 32, 38; 33, comparison_operator:==; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:base_class; 36, identifier:__name__; 37, string:'Base'; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 43; 39, 44; 39, 49; 40, comparison_operator:is; 40, 41; 40, 42; 41, identifier:id_base; 42, None; 43, comment; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:id_base; 48, identifier:c; 49, else_clause; 49, 50; 50, block; 50, 51; 51, raise_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:RuntimeError; 54, argument_list; 54, 55; 55, binary_operator:+; 55, 56; 55, 57; 56, string:"Multiple base object classes for class "; 57, attribute; 57, 58; 57, 59; 58, identifier:cls; 59, identifier:__name__; 60, comment; 61, if_statement; 61, 62; 61, 65; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:id_base; 64, None; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:RuntimeError; 69, argument_list; 69, 70; 70, binary_operator:+; 70, 71; 70, 72; 71, string:"Error searching for base class of "; 72, attribute; 72, 73; 72, 74; 73, identifier:cls; 74, identifier:__name__; 75, comment; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:max_id; 79, call; 79, 80; 79, 95; 80, attribute; 80, 81; 80, 94; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:session; 84, identifier:query; 85, argument_list; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:func; 89, identifier:max; 90, argument_list; 90, 91; 91, attribute; 91, 92; 91, 93; 92, identifier:id_base; 93, identifier:id; 94, identifier:scalar; 95, argument_list; 96, comment; 97, if_statement; 97, 98; 97, 101; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:max_id; 100, None; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:max_id; 105, integer:0; 106, return_statement; 106, 107; 107, identifier:max_id
def get_max_id(cls, session): """Get the current max value of the ``id`` column. When creating and storing ORM objects in bulk, :mod:`sqlalchemy` does not automatically generate an incrementing primary key ``id``. To do this manually, one needs to know the current max ``id``. For ORM object classes that are derived from other ORM object classes, the max ``id`` of the lowest base class is returned. This is designed to be used with inheritance by joining, in which derived and base class objects have identical ``id`` values. Args: session: database session to operate in """ # sqlalchemy allows only one level of inheritance, so just check this class and all its bases id_base = None for c in [cls] + list(cls.__bases__): for base_class in c.__bases__: if base_class.__name__ == 'Base': if id_base is None: # we found our base class for determining the ID id_base = c else: raise RuntimeError("Multiple base object classes for class " + cls.__name__) # this should never happen if id_base is None: raise RuntimeError("Error searching for base class of " + cls.__name__) # get its max ID max_id = session.query(func.max(id_base.id)).scalar() # if no object is present, None is returned if max_id is None: max_id = 0 return max_id
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_insert_automodapi_configs; 3, parameters; 3, 4; 4, identifier:c; 5, block; 5, 6; 5, 8; 5, 9; 5, 10; 5, 16; 5, 22; 5, 28; 5, 34; 5, 35; 5, 41; 5, 42; 5, 43; 5, 44; 5, 50; 5, 51; 5, 52; 5, 53; 5, 54; 5, 55; 5, 56; 5, 57; 5, 58; 5, 59; 5, 60; 5, 68; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 15; 12, subscript; 12, 13; 12, 14; 13, identifier:c; 14, string:'numpydoc_show_class_members'; 15, False; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 21; 18, subscript; 18, 19; 18, 20; 19, identifier:c; 20, string:'autosummary_generate'; 21, True; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, subscript; 24, 25; 24, 26; 25, identifier:c; 26, string:'automodapi_toctreedirnm'; 27, string:'py-api'; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:c; 32, string:'automodsumm_inherited_members'; 33, True; 34, comment; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:c; 39, string:'autodoc_inherit_docstrings'; 40, True; 41, comment; 42, comment; 43, comment; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:c; 48, string:'autoclass_content'; 49, string:"class"; 50, comment; 51, comment; 52, comment; 53, comment; 54, comment; 55, comment; 56, comment; 57, comment; 58, comment; 59, comment; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:c; 64, string:'autodoc_default_flags'; 65, list:['show-inheritance', 'special-members']; 65, 66; 65, 67; 66, string:'show-inheritance'; 67, string:'special-members'; 68, return_statement; 68, 69; 69, identifier:c
def _insert_automodapi_configs(c): """Add configurations related to automodapi, autodoc, and numpydoc to the state. """ # Don't show summaries of the members in each class along with the # class' docstring c['numpydoc_show_class_members'] = False c['autosummary_generate'] = True c['automodapi_toctreedirnm'] = 'py-api' c['automodsumm_inherited_members'] = True # Docstrings for classes and methods are inherited from parents. c['autodoc_inherit_docstrings'] = True # Class documentation should only contain the class docstring and # ignore the __init__ docstring, account to LSST coding standards. # c['autoclass_content'] = "both" c['autoclass_content'] = "class" # Default flags for automodapi directives. Special members are dunder # methods. # NOTE: We want to used `inherited-members`, but it seems to be causing # documentation duplication in the automodapi listings. We're leaving # this out for now. See https://jira.lsstcorp.org/browse/DM-14782 for # additional notes. # NOTE: Without inherited members set, special-members doesn't need seem # to have an effect (even for special members where the docstrings are # directly written in the class, not inherited. # c['autodoc_default_flags'] = ['inherited-members'] c['autodoc_default_flags'] = ['show-inheritance', 'special-members'] return c
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:build_pipelines_lsst_io_configs; 3, parameters; 3, 4; 3, 5; 3, 6; 4, keyword_separator; 5, identifier:project_name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:copyright; 8, None; 9, block; 9, 10; 9, 12; 9, 13; 9, 20; 9, 24; 9, 34; 9, 35; 9, 48; 9, 49; 9, 56; 9, 57; 9, 64; 9, 65; 9, 66; 9, 67; 9, 74; 9, 75; 9, 82; 9, 83; 9, 90; 9, 91; 9, 98; 9, 99; 9, 100; 9, 110; 9, 121; 9, 122; 9, 123; 9, 138; 9, 139; 9, 145; 9, 146; 9, 147; 9, 170; 9, 171; 9, 178; 9, 179; 9, 186; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:sys; 17, identifier:setrecursionlimit; 18, argument_list; 18, 19; 19, integer:2000; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:c; 23, dictionary; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:c; 27, call; 27, 28; 27, 29; 28, identifier:_insert_common_sphinx_configs; 29, argument_list; 29, 30; 29, 31; 30, identifier:c; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:project_name; 33, identifier:project_name; 34, comment; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:c; 38, call; 38, 39; 38, 40; 39, identifier:_insert_html_configs; 40, argument_list; 40, 41; 40, 42; 40, 45; 41, identifier:c; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:project_name; 44, identifier:project_name; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:short_project_name; 47, identifier:project_name; 48, comment; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:c; 52, call; 52, 53; 52, 54; 53, identifier:_insert_extensions; 54, argument_list; 54, 55; 55, identifier:c; 56, comment; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:c; 60, call; 60, 61; 60, 62; 61, identifier:_insert_intersphinx_mapping; 62, argument_list; 62, 63; 63, identifier:c; 64, comment; 65, comment; 66, comment; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:c; 70, call; 70, 71; 70, 72; 71, identifier:_insert_automodapi_configs; 72, argument_list; 72, 73; 73, identifier:c; 74, comment; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:c; 78, call; 78, 79; 78, 80; 79, identifier:_insert_matplotlib_configs; 80, argument_list; 80, 81; 81, identifier:c; 82, comment; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:c; 86, call; 86, 87; 86, 88; 87, identifier:_insert_graphviz_configs; 88, argument_list; 88, 89; 89, identifier:c; 90, comment; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:c; 94, call; 94, 95; 94, 96; 95, identifier:_insert_eups_version; 96, argument_list; 96, 97; 97, identifier:c; 98, comment; 99, comment; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:date; 103, call; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:datetime; 107, identifier:datetime; 108, identifier:now; 109, argument_list; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:c; 114, string:'today'; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:date; 118, identifier:strftime; 119, argument_list; 119, 120; 120, string:'%Y-%m-%d'; 121, comment; 122, comment; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:c; 127, string:'copyright'; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, string:'2015-{year} LSST contributors'; 131, identifier:format; 132, argument_list; 132, 133; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:year; 135, attribute; 135, 136; 135, 137; 136, identifier:date; 137, identifier:year; 138, comment; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:c; 143, string:'todo_include_todos'; 144, False; 145, comment; 146, comment; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:c; 151, string:'exclude_patterns'; 152, list:[ 'README.rst', # Build products '_build', # Source for release notes (contents are included in built pages) 'releases/note-source/*.rst', 'releases/tickets-source/*.rst', # EUPS configuration directory 'ups', # Recommended directory for pip installing doc eng Python packages '.pyvenv', # GitHub templates '.github', # This 'home' directory is created by the docubase image for the # sqre/infra/documenteer ci.lsst.codes Jenkins job. Ideally this # shouldn't be in the directory at all, but we certainly need to # ignore it while its here. 'home', ]; 152, 153; 152, 154; 152, 155; 152, 156; 152, 157; 152, 158; 152, 159; 152, 160; 152, 161; 152, 162; 152, 163; 152, 164; 152, 165; 152, 166; 152, 167; 152, 168; 152, 169; 153, string:'README.rst'; 154, comment; 155, string:'_build'; 156, comment; 157, string:'releases/note-source/*.rst'; 158, string:'releases/tickets-source/*.rst'; 159, comment; 160, string:'ups'; 161, comment; 162, string:'.pyvenv'; 163, comment; 164, string:'.github'; 165, comment; 166, comment; 167, comment; 168, comment; 169, string:'home'; 170, comment; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:c; 174, call; 174, 175; 174, 176; 175, identifier:_insert_rst_epilog; 176, argument_list; 176, 177; 177, identifier:c; 178, comment; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:c; 182, call; 182, 183; 182, 184; 183, identifier:_insert_jinja_configuration; 184, argument_list; 184, 185; 185, identifier:c; 186, return_statement; 186, 187; 187, identifier:c
def build_pipelines_lsst_io_configs(*, project_name, copyright=None): """Build a `dict` of Sphinx configurations that populate the ``conf.py`` of the main pipelines_lsst_io Sphinx project for LSST Science Pipelines documentation. The ``conf.py`` file can ingest these configurations via:: from documenteer.sphinxconfig.stackconf import \ build_pipelines_lsst_io_configs _g = globals() _g.update(build_pipelines_lsst_io_configs( project_name='LSST Science Pipelines') You can subsequently customize the Sphinx configuration by directly assigning global variables, as usual in a Sphinx ``config.py``, e.g.:: copyright = '2016 Association of Universities for ' 'Research in Astronomy, Inc.' Parameters ---------- project_name : `str` Name of the project copyright : `str`, optional Copyright statement. Do not include the 'Copyright (c)' string; it'll be added automatically. Returns ------- c : dict Dictionary of configurations that should be added to the ``conf.py`` global namespace via:: _g = global() _g.update(c) """ # Work around Sphinx bug related to large and highly-nested source files sys.setrecursionlimit(2000) c = {} c = _insert_common_sphinx_configs( c, project_name=project_name) # HTML theme c = _insert_html_configs( c, project_name=project_name, short_project_name=project_name) # Sphinx extension modules c = _insert_extensions(c) # Intersphinx configuration c = _insert_intersphinx_mapping(c) # Breathe extension configuration # FIXME configure this for multiple sites # Automodapi and numpydoc configurations c = _insert_automodapi_configs(c) # Matplotlib configurations c = _insert_matplotlib_configs(c) # Graphviz configurations c = _insert_graphviz_configs(c) # Add versioning information c = _insert_eups_version(c) # Always use "now" as the date for the main site's docs because we can't # look at the Git history of each stack package. date = datetime.datetime.now() c['today'] = date.strftime('%Y-%m-%d') # Use this copyright for now. Ultimately we want to gather COPYRIGHT files # and build an integrated copyright that way. c['copyright'] = '2015-{year} LSST contributors'.format( year=date.year) # Hide todo directives in the "published" documentation on the main site. c['todo_include_todos'] = False # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. c['exclude_patterns'] = [ 'README.rst', # Build products '_build', # Source for release notes (contents are included in built pages) 'releases/note-source/*.rst', 'releases/tickets-source/*.rst', # EUPS configuration directory 'ups', # Recommended directory for pip installing doc eng Python packages '.pyvenv', # GitHub templates '.github', # This 'home' directory is created by the docubase image for the # sqre/infra/documenteer ci.lsst.codes Jenkins job. Ideally this # shouldn't be in the directory at all, but we certainly need to # ignore it while its here. 'home', ] # Insert rst_epilog configuration c = _insert_rst_epilog(c) # Set up the context for the sphinx-jinja extension c = _insert_jinja_configuration(c) return c
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:event; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:self; 5, identifier:cuuid; 6, identifier:host; 7, identifier:euuid; 8, identifier:event_data; 9, identifier:timestamp; 10, identifier:priority; 11, block; 11, 12; 11, 14; 11, 15; 11, 19; 11, 20; 11, 21; 11, 58; 11, 59; 11, 65; 11, 71; 11, 72; 11, 73; 11, 74; 11, 115; 11, 116; 11, 117; 11, 139; 11, 140; 11, 141; 11, 142; 11, 150; 11, 169; 11, 180; 11, 195; 11, 196; 11, 197; 11, 198; 11, 312; 11, 313; 11, 314; 11, 338; 12, expression_statement; 12, 13; 13, comment; 14, comment; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:response; 18, None; 19, comment; 20, comment; 21, if_statement; 21, 22; 21, 27; 21, 45; 22, comparison_operator:in; 22, 23; 22, 24; 23, identifier:host; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:encrypted_hosts; 27, block; 27, 28; 27, 35; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:logger; 32, identifier:debug; 33, argument_list; 33, 34; 34, string:"Encrypted!"; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:client_key; 38, subscript; 38, 39; 38, 44; 39, subscript; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:registry; 43, identifier:cuuid; 44, string:"encryption"; 45, else_clause; 45, 46; 46, block; 46, 47; 46, 54; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:logger; 51, identifier:debug; 52, argument_list; 52, 53; 53, string:"Not encrypted :<"; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:client_key; 57, None; 58, comment; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:port; 62, subscript; 62, 63; 62, 64; 63, identifier:host; 64, integer:1; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:host; 68, subscript; 68, 69; 68, 70; 69, identifier:host; 70, integer:0; 71, comment; 72, comment; 73, comment; 74, if_statement; 74, 75; 74, 83; 75, not_operator; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:is_registered; 80, argument_list; 80, 81; 80, 82; 81, identifier:cuuid; 82, identifier:host; 83, block; 83, 84; 83, 93; 83, 113; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:logger; 88, identifier:warning; 89, argument_list; 89, 90; 90, binary_operator:%; 90, 91; 90, 92; 91, string:"<%s> Sending BYE EVENT: Client not registered."; 92, identifier:cuuid; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:response; 96, call; 96, 97; 96, 98; 97, identifier:serialize_data; 98, argument_list; 98, 99; 98, 106; 98, 109; 98, 112; 99, dictionary; 99, 100; 99, 103; 100, pair; 100, 101; 100, 102; 101, string:"method"; 102, string:"BYE EVENT"; 103, pair; 103, 104; 103, 105; 104, string:"data"; 105, string:"Not registered"; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:compression; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:encryption; 112, identifier:client_key; 113, return_statement; 113, 114; 114, identifier:response; 115, comment; 116, comment; 117, if_statement; 117, 118; 117, 123; 118, comparison_operator:in; 118, 119; 118, 120; 119, identifier:euuid; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:event_uuids; 123, block; 123, 124; 123, 135; 123, 136; 123, 137; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:logger; 128, identifier:warning; 129, argument_list; 129, 130; 130, binary_operator:%; 130, 131; 130, 132; 131, string:"<%s> Event ID is already being processed: %s"; 132, tuple; 132, 133; 132, 134; 133, identifier:cuuid; 134, identifier:euuid; 135, comment; 136, comment; 137, return_statement; 137, 138; 138, identifier:response; 139, comment; 140, comment; 141, comment; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:event_uuids; 148, identifier:euuid; 149, integer:0; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:logger; 154, identifier:debug; 155, argument_list; 155, 156; 156, binary_operator:%; 156, 157; 156, 160; 157, concatenated_string; 157, 158; 157, 159; 158, string:"<%s> <euuid:%s> Currently processing events: "; 159, string:"%s"; 160, tuple; 160, 161; 160, 162; 160, 163; 161, identifier:cuuid; 162, identifier:euuid; 163, call; 163, 164; 163, 165; 164, identifier:str; 165, argument_list; 165, 166; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:event_uuids; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:logger; 173, identifier:debug; 174, argument_list; 174, 175; 175, binary_operator:%; 175, 176; 175, 177; 176, string:"<%s> <euuid:%s> New event being processed"; 177, tuple; 177, 178; 177, 179; 178, identifier:cuuid; 179, identifier:euuid; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:logger; 184, identifier:debug; 185, argument_list; 185, 186; 186, binary_operator:%; 186, 187; 186, 188; 187, string:"<%s> <euuid:%s> Event Data: %s"; 188, tuple; 188, 189; 188, 190; 188, 191; 189, identifier:cuuid; 190, identifier:euuid; 191, call; 191, 192; 191, 193; 192, identifier:pformat; 193, argument_list; 193, 194; 194, identifier:event_data; 195, comment; 196, comment; 197, comment; 198, if_statement; 198, 199; 198, 209; 198, 274; 199, call; 199, 200; 199, 205; 200, attribute; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:middleware; 204, identifier:event_legal; 205, argument_list; 205, 206; 205, 207; 205, 208; 206, identifier:cuuid; 207, identifier:euuid; 208, identifier:event_data; 209, block; 209, 210; 209, 223; 209, 246; 209, 247; 209, 268; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:logger; 214, identifier:debug; 215, argument_list; 215, 216; 216, binary_operator:%; 216, 217; 216, 220; 217, concatenated_string; 217, 218; 217, 219; 218, string:"<%s> <euuid:%s> Event LEGAL. Sending judgement "; 219, string:"to client."; 220, tuple; 220, 221; 220, 222; 221, identifier:cuuid; 222, identifier:euuid; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:response; 226, call; 226, 227; 226, 228; 227, identifier:serialize_data; 228, argument_list; 228, 229; 228, 239; 228, 242; 228, 245; 229, dictionary; 229, 230; 229, 233; 229, 236; 230, pair; 230, 231; 230, 232; 231, string:"method"; 232, string:"LEGAL"; 233, pair; 233, 234; 233, 235; 234, string:"euuid"; 235, identifier:euuid; 236, pair; 236, 237; 236, 238; 237, string:"priority"; 238, identifier:priority; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:compression; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:encryption; 245, identifier:client_key; 246, comment; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:thread; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:threading; 253, identifier:Thread; 254, argument_list; 254, 255; 254, 262; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:target; 257, attribute; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:middleware; 261, identifier:event_execute; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:args; 264, tuple; 264, 265; 264, 266; 264, 267; 265, identifier:cuuid; 266, identifier:euuid; 267, identifier:event_data; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:thread; 272, identifier:start; 273, argument_list; 274, else_clause; 274, 275; 275, block; 275, 276; 275, 289; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:logger; 280, identifier:debug; 281, argument_list; 281, 282; 282, binary_operator:%; 282, 283; 282, 286; 283, concatenated_string; 283, 284; 283, 285; 284, string:"<%s> <euuid:%s> Event ILLEGAL. Sending judgement "; 285, string:"to client."; 286, tuple; 286, 287; 286, 288; 287, identifier:cuuid; 288, identifier:euuid; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:response; 292, call; 292, 293; 292, 294; 293, identifier:serialize_data; 294, argument_list; 294, 295; 294, 305; 294, 308; 294, 311; 295, dictionary; 295, 296; 295, 299; 295, 302; 296, pair; 296, 297; 296, 298; 297, string:"method"; 298, string:"ILLEGAL"; 299, pair; 299, 300; 299, 301; 300, string:"euuid"; 301, identifier:euuid; 302, pair; 302, 303; 302, 304; 303, string:"priority"; 304, identifier:priority; 305, attribute; 305, 306; 305, 307; 306, identifier:self; 307, identifier:compression; 308, attribute; 308, 309; 308, 310; 309, identifier:self; 310, identifier:encryption; 311, identifier:client_key; 312, comment; 313, comment; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 321; 316, attribute; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:self; 319, identifier:listener; 320, identifier:call_later; 321, argument_list; 321, 322; 321, 325; 321, 328; 322, attribute; 322, 323; 322, 324; 323, identifier:self; 324, identifier:timeout; 325, attribute; 325, 326; 325, 327; 326, identifier:self; 327, identifier:retransmit; 328, dictionary; 328, 329; 328, 332; 328, 335; 329, pair; 329, 330; 329, 331; 330, string:"euuid"; 331, identifier:euuid; 332, pair; 332, 333; 332, 334; 333, string:"response"; 334, identifier:response; 335, pair; 335, 336; 335, 337; 336, string:"cuuid"; 337, identifier:cuuid; 338, return_statement; 338, 339; 339, identifier:response
def event(self, cuuid, host, euuid, event_data, timestamp, priority): """This function will process event packets and send them to legal checks. Args: cuuid (string): The client uuid that the event came from. host (tuple): The (address, port) tuple of the client. euuid (string): The event uuid of the specific event. event_data (any): The event data that we will be sending to the middleware to be judged and executed. timestamp (string): The client provided timestamp of when the event was created. priority (string): The priority of the event. This is normally set to either "normal" or "high". If an event was sent with a high priority, then the client will not wait for a response from the server before executing the event locally. Returns: A LEGAL/ILLEGAL response to be sent to the client. """ # Set the initial response to none response = None # If the host we're sending to is using encryption, get their key to # encrypt. if host in self.encrypted_hosts: logger.debug("Encrypted!") client_key = self.registry[cuuid]["encryption"] else: logger.debug("Not encrypted :<") client_key = None # Get the port and host port = host[1] host = host[0] # First, we need to check if the request is coming from a registered # client. If it's not coming from a registered client, we tell them to # fuck off and register first. if not self.is_registered(cuuid, host): logger.warning("<%s> Sending BYE EVENT: Client not registered." % cuuid) response = serialize_data({"method": "BYE EVENT", "data": "Not registered"}, self.compression, self.encryption, client_key) return response # Check our stored event uuid's to see if we're already processing # this event. if euuid in self.event_uuids: logger.warning("<%s> Event ID is already being processed: %s" % (cuuid, euuid)) # If we're already working on this event, return none so we do not # reply to the client return response # If we're not already processing this event, store the event uuid # until we receive a confirmation from the client that it received our # judgement. self.event_uuids[euuid] = 0 logger.debug("<%s> <euuid:%s> Currently processing events: " "%s" % (cuuid, euuid, str(self.event_uuids))) logger.debug("<%s> <euuid:%s> New event being processed" % (cuuid, euuid)) logger.debug("<%s> <euuid:%s> Event Data: %s" % (cuuid, euuid, pformat(event_data))) # Send the event to the game middleware to determine if the event is # legal or not and to process the event in the Game Server if it is # legal. if self.middleware.event_legal(cuuid, euuid, event_data): logger.debug("<%s> <euuid:%s> Event LEGAL. Sending judgement " "to client." % (cuuid, euuid)) response = serialize_data({"method": "LEGAL", "euuid": euuid, "priority": priority}, self.compression, self.encryption, client_key) # Execute the event thread = threading.Thread(target=self.middleware.event_execute, args=(cuuid, euuid, event_data) ) thread.start() else: logger.debug("<%s> <euuid:%s> Event ILLEGAL. Sending judgement " "to client." % (cuuid, euuid)) response = serialize_data({"method": "ILLEGAL", "euuid": euuid, "priority": priority}, self.compression, self.encryption, client_key) # Schedule a task to run in x seconds to check to see if we've timed # out in receiving a response from the client. self.listener.call_later(self.timeout, self.retransmit, {"euuid": euuid, "response": response, "cuuid": cuuid}) return response